models

package
v0.6.8 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2023 License: GPL-3.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateDefaultInboxMap

func CreateDefaultInboxMap(id string) (map[string]interface{}, error)

func FormatBlockchainAddressAsDID

func FormatBlockchainAddressAsDID(addr string) string

FormatBlockchainAddressAsDID formats a blockchain address as a DID.

func GetPubKeyFromCmpConfigBytes

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

GetPubKeyFromCmpConfigBytes loads KeyShare from a cmp.Config buffer.

func ParseCredentialDID

func ParseCredentialDID(did string) (*crypto.WebauthnCredential, error)

Parse a DID into a WebauthnCredential struct

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

	// CreateInboxMail creates a new inbox mail
	CreateInboxMessage(to string, body string) (*InboxMessage, error)

	// DeriveAccount returns a new account with the same keyshares but a new coin type
	DeriveAccount(ct crypto.CoinType, idx int, name string) (Account, error)

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

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

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

	// ListKeyShares returns the list of keyshares of the account as a list of string dids
	ListKeyShares() []string

	// MapKeyShare maps a function to all the keyshares of the account
	MapKeyShare(f func(ks KeyShare) KeyShare)

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

	// 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

	// 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 Credential) error

	// Unlock unlocks the account
	Unlock(c Credential) 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 Credential

type Credential interface {
	// Controller returns the credential's controller
	Controller() string

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

	// Convert the credential to a DID VerificationMethod
	ToVerificationMethod() *types.VerificationMethod

	// Encrypt is used to encrypt a message for the credential
	Encrypt(msg []byte) ([]byte, error)

	// Decrypt is used to decrypt a message for the credential
	Decrypt(msg []byte) ([]byte, error)

	// Marshal is used to marshal the credential to JSON
	Marshal() ([]byte, error)
}

func LoadCredential

func LoadCredential(vm *types.VerificationMethod) (Credential, error)

func LoadJSONCredential

func LoadJSONCredential(bz []byte) (Credential, error)

func NewCredential

func NewCredential(cred *crypto.WebauthnCredential, controller string) Credential

func ValidateWebauthnCredential

func ValidateWebauthnCredential(credential *crypto.WebauthnCredential, controller string) (Credential, error)

type Inbox

type Inbox struct {
	// The inbox id
	Id string `json:"_id,omitempty"`

	// The inbox messages
	Messages []*InboxMessage `json:"messages,omitempty"`
}

func NewInboxFromMap

func NewInboxFromMap(inboxMap map[string]interface{}) (*Inbox, error)

func (*Inbox) AddMessageToMap

func (inbox *Inbox) AddMessageToMap(msg *InboxMessage) (map[string]interface{}, error)

func (*Inbox) ToMap

func (inbox *Inbox) ToMap() (map[string]interface{}, error)

type InboxMessage

type InboxMessage struct {
	// The message id
	Id string `json:"id,omitempty"`

	// The message type
	Type string `json:"type,omitempty"`

	// The message content
	Content string `json:"content,omitempty"`

	// The message sender
	Sender string `json:"sender,omitempty"`

	// The message receiver
	Receiver string `json:"receiver,omitempty"`

	// CoinType Name is for the blockchain network name
	CoinType string `json:"coinType,omitempty"`
}

func (*InboxMessage) InboxMessageToMap

func (im *InboxMessage) InboxMessageToMap() (map[string]interface{}, error)

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

	// DeriveBip44 returns a new keyshare with the same key but a new coin type
	DeriveBip44(ct crypto.CoinType, idx int, name string) (KeyShare, error)

	// Did returns the cid of the keyshare
	Did() 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

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

	// Encrypt encrypts the keyshare file.
	Encrypt(credential Credential) error

	// Decrypt decrypts the keyshare file.
	Decrypt(credential Credential) error
}

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

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 {
	CoinType       crypto.CoinType
	AccountAddress string
	AccountName    string
	KeyShareName   string
}

func ParseAccountDID

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

ParseAccountDID parses an account DID into its components.

func ParseKeyShareDID

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

ParseKeyShareDID parses a keyshare DID into its components.

Jump to

Keyboard shortcuts

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