controller

package
v0.6.3-beta.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 27, 2023 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var PrimaryAccountName string = "primary"

Functions

func LoadKeySharePubKeyFromConfigBytes

func LoadKeySharePubKeyFromConfigBytes(bytes []byte) (*crypto.PubKey, error)

LoadKeySharePubKeyFromConfigBytes loads KeyShare from a cmp.Config buffer.

func NewController

func NewController(ctx context.Context, options ...Option) (Controller, Account, error)

func ValidateWebauthnCredential

func ValidateWebauthnCredential(credential *crypto.WebauthnCredential) (*crypto.WebauthnCredential, error)

Types

type Account

type Account interface {
	// Address returns the address of the account based on the coin type
	Address() string

	// CoinType returns the coin type of the account
	CoinType() crypto.CoinType

	// DID returns the DID of the account
	Did() string

	// Get the controller's DID document
	DidDocument(controller string) *types.DidDocument

	// GetAuthInfo creates an AuthInfo for a transaction
	GetAuthInfo(gas sdk.Coins) (*txtypes.AuthInfo, error)

	// ListKeyshares returns a list of keyshares for the account
	ListKeyshares() ([]KeyShare, error)

	// MapKeyshares performs a function on each keyshare of the account
	MapKeyshares(f func(KeyShare) error) error

	// Name returns the name of the account
	Name() string

	// PartyIDs returns the party IDs of the account
	PartyIDs() []crypto.PartyID

	// Nonce returns the nonce of the account
	Nonce() uint64

	// IncrementNonce increments the nonce of the account
	IncrementNonce()

	// PubKey returns secp256k1 public key
	PubKey() *crypto.PubKey

	// Signs a message
	Sign(bz []byte) ([]byte, error)

	// ToProto returns the proto representation of the account
	ToProto() *v1.Account

	// ToStore returns the store representation of the account
	ToStore() (string, []string)

	// Type returns the type of the account
	Type() string

	// Verifies a signature
	Verify(bz []byte, sig []byte) (bool, error)

	// Lock locks the account
	Lock(c *crypto.WebauthnCredential, rootDir string) error

	// Unlock unlocks the account
	Unlock(c *crypto.WebauthnCredential, rootDir string) error
}

Account is an interface for an account in the wallet

func NewAccount

func NewAccount(kss []KeyShare, ct crypto.CoinType) Account

NewAccount creates a new account

type Controller

type Controller interface {
	// Address returns the controller's address
	Address() string

	// Get the controller's DID
	Did() string

	// Get the controller's DID document
	PrimaryIdentity() *types.DidDocument

	// Blockchain returns the controller's blockchain identities
	BlockchainIdentities() []*types.DidDocument

	// Authorize the client to access the controller's account
	Authorize(cred *crypto.WebauthnCredential) error

	// CreateAccount creates a new account for the controller
	CreateAccount(name string, coinType crypto.CoinType) (Account, error)

	// GetAccount returns the controller's account
	GetAccount(name string, coinType crypto.CoinType) (Account, error)

	// ListAccounts returns the controller's accounts
	ListAccounts(ct crypto.CoinType) ([]Account, error)

	// ListLocalAccounts returns the controller's local accounts (WARNING: this is not secure)
	ListLocalAccounts() []Account

	// Sign signs a message with the controller's account
	Sign(name string, coinType crypto.CoinType, msg []byte) ([]byte, error)

	// Verify verifies a signature with the controller's account
	Verify(name string, coinType crypto.CoinType, msg []byte, sig []byte) (bool, error)
}

func AuthorizeController

func AuthorizeController(ctx context.Context, didDoc *types.DidDocument) (Controller, error)

AuthorizeController loads a controller from the given DID document using the underlying IPFS store

type FilterOptions

type FilterOptions struct {
	CoinType    crypto.CoinType
	AccountName *string
	Index       *int
}

! ||--------------------------------------------------------------------------------|| ! || Map & Slice Filtering || ! ||--------------------------------------------------------------------------------||

type Foobar

type Foobar struct {
	Foo string
	Bar string
}

type KeyShare

type KeyShare interface {
	// AccountName returns the account name based on the keyshare file name
	AccountName() string

	// Bytes returns the bytes of the keyshare file - the marshalled cmp.Config
	Bytes() []byte

	// CoinType returns the coin type based on the keyshare file name
	CoinType() crypto.CoinType

	// Config returns the cmp.Config.
	Config() *cmp.Config

	// Did returns the cid of the keyshare
	Did() string

	// KeyShareName returns the keyshare name based on the keyshare file name
	KeyShareName() string

	// PartyID returns the party id based on the keyshare file name
	PartyID() crypto.PartyID

	// PubKey returns the public key of the keyshare
	PubKey() *crypto.PubKey

	// Encrypt checks if the file at current path is encrypted and if not, encrypts it.
	Encrypt(credential *crypto.WebauthnCredential) error

	// Encrypt checks if the file at current path is encrypted and if not, encrypts it.
	Decrypt(credential *crypto.WebauthnCredential) error

	// IsEncrypted checks if the file at current path is encrypted.
	IsEncrypted() bool
}

KeyShare is a type that interacts with a cmp.Config file located on disk.

func LoadKeyshareFromStore

func LoadKeyshareFromStore(key string, value interface{}) (KeyShare, error)

LoadKeyshareFromStore loads a keyshare from a store. The value can be a base64 encoded string or a []byte.

func NewKeyshare

func NewKeyshare(id string, bytes []byte, coinType crypto.CoinType, accName string) (KeyShare, error)

Keyshare name format is a DID did:{coin_type}:{account_address}#ks-{account_name}-{keyshare_name} did:{coin_type}:{account_address}#ks-{account_name}-{keyshare_name}

type KeyShareParseResult

type KeyShareParseResult struct {
	DID            string
	CoinType       crypto.CoinType
	AccountAddress string
	AccountName    string
	KeyShareName   string
}

func ParseKeyShareDid

func ParseKeyShareDid(name string) (*KeyShareParseResult, error)

ParseKeyShareDid parses a keyshare DID into its components. The DID format is: did:{coin_type}:{account_address}#ks-{account_name}-{keyshare_name}

type Option

type Option func(*Options)

func WithConfigHandlers

func WithConfigHandlers(handlers ...mpc.OnConfigGenerated) Option

func WithInitialAccounts

func WithInitialAccounts(accounts ...string) Option

func WithWebauthnCredential

func WithWebauthnCredential(cred *crypto.WebauthnCredential) Option

type Options

type Options struct {
	// The controller's DID document
	GenerateInitialAccounts []string

	// The controller's on config generated handler
	OnConfigGenerated []mpc.OnConfigGenerated

	// Credential to authorize the controller
	WebauthnCredential *crypto.WebauthnCredential
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL