-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1773 from oasisprotocol/kostko/feature/rofl
Add support for ROFL
- Loading branch information
Showing
106 changed files
with
5,351 additions
and
589 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package rofl | ||
|
||
import ( | ||
"encoding" | ||
"encoding/binary" | ||
|
||
"github.com/oasisprotocol/oasis-core/go/common/crypto/address" | ||
"github.com/oasisprotocol/oasis-core/go/common/encoding/bech32" | ||
|
||
"github.com/oasisprotocol/oasis-sdk/client-sdk/go/types" | ||
) | ||
|
||
var ( | ||
// AppIDV0CRIContext is the unique context for v0 creator/round/index application identifiers. | ||
AppIDV0CRIContext = address.NewContext("oasis-sdk/rofl: cri app id", 0) | ||
// AppIDV0GlobalNameContext is the unique context for v0 global name application identifiers. | ||
AppIDV0GlobalNameContext = address.NewContext("oasis-sdk/rofl: global name app id", 0) | ||
// AppIDBech32HRP is the unique human readable part of Bech32 encoded application identifiers. | ||
AppIDBech32HRP = address.NewBech32HRP("rofl") | ||
|
||
_ encoding.BinaryMarshaler = AppID{} | ||
_ encoding.BinaryUnmarshaler = (*AppID)(nil) | ||
_ encoding.TextMarshaler = AppID{} | ||
_ encoding.TextUnmarshaler = (*AppID)(nil) | ||
) | ||
|
||
// AppID is the ROFL application identifier. | ||
type AppID address.Address | ||
|
||
// MarshalBinary encodes an application identifier into binary form. | ||
func (a AppID) MarshalBinary() ([]byte, error) { | ||
return (address.Address)(a).MarshalBinary() | ||
} | ||
|
||
// UnmarshalBinary decodes a binary marshaled application identifier. | ||
func (a *AppID) UnmarshalBinary(data []byte) error { | ||
return (*address.Address)(a).UnmarshalBinary(data) | ||
} | ||
|
||
// MarshalText encodes an application identifier into text form. | ||
func (a AppID) MarshalText() ([]byte, error) { | ||
return (address.Address)(a).MarshalBech32(AppIDBech32HRP) | ||
} | ||
|
||
// UnmarshalText decodes a text marshaled application identifier. | ||
func (a *AppID) UnmarshalText(text []byte) error { | ||
return (*address.Address)(a).UnmarshalBech32(AppIDBech32HRP, text) | ||
} | ||
|
||
// Equal compares vs another application identifier for equality. | ||
func (a AppID) Equal(cmp AppID) bool { | ||
return (address.Address)(a).Equal((address.Address)(cmp)) | ||
} | ||
|
||
// String returns the string representation of an application identifier. | ||
func (a AppID) String() string { | ||
bech32Addr, err := bech32.Encode(AppIDBech32HRP.String(), a[:]) | ||
if err != nil { | ||
return "[malformed]" | ||
} | ||
return bech32Addr | ||
} | ||
|
||
// NewAppIDCreatorRoundIndex creates a new application identifier from the given creator/round/index | ||
// tuple. | ||
func NewAppIDCreatorRoundIndex(creator types.Address, round uint64, index uint32) AppID { | ||
data := make([]byte, address.Size+8+4) | ||
|
||
rawCreator, _ := creator.MarshalBinary() | ||
copy(data[:address.Size], rawCreator) | ||
|
||
binary.BigEndian.PutUint64(data[address.Size:], round) | ||
binary.BigEndian.PutUint32(data[address.Size+8:], index) | ||
|
||
return NewAppIDRaw(AppIDV0CRIContext, data) | ||
} | ||
|
||
// NewAppIDGlobalName creates a new application identifier from the given global name. | ||
func NewAppIDGlobalName(name string) AppID { | ||
return NewAppIDRaw(AppIDV0GlobalNameContext, []byte(name)) | ||
} | ||
|
||
// NewAppIDRaw creates a new application identifier from passed context and data. | ||
func NewAppIDRaw(ctx address.Context, data []byte) AppID { | ||
return (AppID)(address.NewAddress(ctx, data)) | ||
} | ||
|
||
// NewAppIDFromBech32 creates a new application identifier from the given bech-32 encoded string. | ||
// | ||
// Panics in case of errors -- use UnmarshalText if you want to handle errors. | ||
func NewAppIDFromBech32(data string) (a AppID) { | ||
err := a.UnmarshalText([]byte(data)) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package rofl | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
sdkTesting "github.com/oasisprotocol/oasis-sdk/client-sdk/go/testing" | ||
) | ||
|
||
func TestIdentifierV0(t *testing.T) { | ||
require := require.New(t) | ||
|
||
appID := NewAppIDCreatorRoundIndex(sdkTesting.Alice.Address, 42, 0) | ||
require.Equal("rofl1qr98wz5t6q4x8ng6a5l5v7rqlx90j3kcnun5dwht", appID.String()) | ||
|
||
appID = NewAppIDCreatorRoundIndex(sdkTesting.Bob.Address, 42, 0) | ||
require.Equal("rofl1qrd45eaj4tf6l7mjw5prcukz75wdmwg6kggt6pnp", appID.String()) | ||
|
||
appID = NewAppIDCreatorRoundIndex(sdkTesting.Bob.Address, 1, 0) | ||
require.Equal("rofl1qzmuyfwygnmfralgtwrqx8kcm587kwex9y8hf9hf", appID.String()) | ||
|
||
appID = NewAppIDCreatorRoundIndex(sdkTesting.Bob.Address, 42, 1) | ||
require.Equal("rofl1qzmh56f52yd0tcqh757fahzc7ec49s8kaguyylvu", appID.String()) | ||
|
||
appID = NewAppIDGlobalName("test global app") | ||
require.Equal("rofl1qrev5wq76npkmcv5wxkdxxcu4dhmu704yyl30h43", appID.String()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package rofl | ||
|
||
import ( | ||
beacon "github.com/oasisprotocol/oasis-core/go/beacon/api" | ||
"github.com/oasisprotocol/oasis-core/go/common/crypto/signature" | ||
"github.com/oasisprotocol/oasis-core/go/common/sgx" | ||
"github.com/oasisprotocol/oasis-core/go/common/sgx/quote" | ||
) | ||
|
||
// AppAuthPolicy is the per-application ROFL policy. | ||
type AppAuthPolicy struct { | ||
// Quotes is a quote policy. | ||
Quotes quote.Policy `json:"quotes"` | ||
// Enclaves is the set of allowed enclave identities. | ||
Enclaves []sgx.EnclaveIdentity `json:"enclaves"` | ||
// Endorsements is the set of allowed endorsements. | ||
Endorsements []AllowedEndorsement `json:"endorsements"` | ||
// Fees is the gas fee payment policy. | ||
Fees FeePolicy `json:"fees"` | ||
// MaxExpiration is the maximum number of future epochs for which one can register. | ||
MaxExpiration beacon.EpochTime `json:"max_expiration"` | ||
} | ||
|
||
// AllowedEndorsement is an allowed endorsement policy. | ||
type AllowedEndorsement struct { | ||
// Any specifies that any node can endorse the enclave. | ||
Any *struct{} `json:"any,omitempty"` | ||
// ComputeRole specifies that a compute node can endorse the enclave. | ||
ComputeRole *struct{} `json:"role_compute,omitempty"` | ||
// ObserverRole specifies that an observer node can endorse the enclave. | ||
ObserverRole *struct{} `json:"role_observer,omitempty"` | ||
// Entity specifies that a registered node from a specific entity can endorse the enclave. | ||
Entity *signature.PublicKey `json:"entity,omitempty"` | ||
// Node specifies that a specific node can endorse the enclave. | ||
Node *signature.PublicKey `json:"node,omitempty"` | ||
} | ||
|
||
// FeePolicy is a gas fee payment policy. | ||
type FeePolicy uint8 | ||
|
||
const ( | ||
// FeePolicyAppPays is a fee policy where the application enclave pays the gas fees. | ||
FeePolicyAppPays FeePolicy = 1 | ||
// FeePolicyEndorsingNodePays is a fee policy where the endorsing node pays the gas fees. | ||
FeePolicyEndorsingNodePays FeePolicy = 2 | ||
) |
Oops, something went wrong.