identity

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// ErrMalformedAddress standard error for malformed address
	ErrMalformedAddress = errors.Error("malformed address provided")

	// BootstrappedDIDFactory stores the id of the factory
	BootstrappedDIDFactory string = "BootstrappedDIDFactory"

	// BootstrappedDIDService stores the id of the service
	BootstrappedDIDService string = "BootstrappedDIDService"

	// KeyTypeECDSA has the value one in the ERC725 identity contract
	KeyTypeECDSA = 1
)
View Source
const DIDLength = common.AddressLength

DIDLength contains the length of a DID

View Source
const (
	// ErrInvalidDIDLength must be used with invalid bytelength when attempting to convert to a DID
	ErrInvalidDIDLength = errors.Error("invalid DID length")
)

Variables

This section is empty.

Functions

func DIDsToBytes

func DIDsToBytes(dids ...*DID) [][]byte

DIDsToBytes converts DIDs to bytes.

func DIDsToStrings

func DIDsToStrings(dids ...*DID) []string

DIDsToStrings converts DIDs to hex strings.

func ValidateDIDBytes

func ValidateDIDBytes(givenDID []byte, did DID) error

ValidateDIDBytes validates a centrifuge ID given as bytes

Types

type Config

type Config interface {
	GetEthereumGasLimit(op config.ContractOp) uint64
}

Config defines methods required for the package identity.

type DID

type DID [DIDLength]byte

DID stores the identity address of the user

func BytesToDIDs

func BytesToDIDs(bytes ...[]byte) ([]*DID, error)

BytesToDIDs converts bytes to DIDs

func DIDsPointers

func DIDsPointers(dids ...DID) []*DID

DIDsPointers returns the pointers to DIDs

func FromPointerDIDs

func FromPointerDIDs(pdids ...*DID) []DID

FromPointerDIDs return pointer DIDs to value DIDs

func NewDID

func NewDID(address common.Address) DID

NewDID returns a DID based on a common.Address

func NewDIDFromBytes

func NewDIDFromBytes(bAddr []byte) (DID, error)

NewDIDFromBytes returns a DID based on a bytes input

func NewDIDFromString

func NewDIDFromString(address string) (DID, error)

NewDIDFromString returns a DID based on a hex string

func NewDIDsFromStrings

func NewDIDsFromStrings(ids []string) ([]DID, error)

NewDIDsFromStrings converts hex ids to DIDs

func RemoveDuplicateDIDs

func RemoveDuplicateDIDs(dids []DID) []DID

RemoveDuplicateDIDs removes duplicate DIDs

func StringsToDIDs

func StringsToDIDs(strs ...string) ([]*DID, error)

StringsToDIDs converts hex strings to DIDs.

func (DID) BigInt

func (d DID) BigInt() *big.Int

BigInt returns DID in bigInt

func (DID) Equal

func (d DID) Equal(other DID) bool

Equal checks if d == other

func (DID) MarshalJSON

func (d DID) MarshalJSON() ([]byte, error)

MarshalJSON marshals DID to json bytes.

func (DID) String

func (d DID) String() string

String returns the DID as HEX String

func (DID) ToAddress

func (d DID) ToAddress() common.Address

ToAddress returns the DID as common.Address

func (*DID) UnmarshalJSON

func (d *DID) UnmarshalJSON(data []byte) error

UnmarshalJSON loads json bytes to DID

type Factory

type Factory interface {
	CreateIdentity(ctx context.Context) (id *DID, err error)
	IdentityExists(did *DID) (exists bool, err error)
	CalculateIdentityAddress(ctx context.Context) (*common.Address, error)
}

Factory is the interface for factory related interactions

type IDKey

type IDKey struct {
	PublicKey  []byte
	PrivateKey []byte
}

IDKey represents a key pair

type IDKeys

type IDKeys struct {
	ID   []byte
	Keys map[int]IDKey
}

IDKeys holds key of an identity

type IDTX

type IDTX interface {
	String() string
	Bytes() []byte
}

IDTX abstracts transactions.JobID for identity package

type Key added in v1.0.0

type Key interface {
	GetKey() [32]byte
	GetPurpose() *big.Int
	GetRevokedAt() uint32
	GetType() *big.Int
}

Key defines a single ERC725 identity key

func NewKey

func NewKey(pk [32]byte, purpose *big.Int, keyType *big.Int, revokedAt uint32) Key

NewKey returns a new key struct

type KeyResponse

type KeyResponse struct {
	Key       [32]byte
	Purposes  []*big.Int
	RevokedAt uint32
}

KeyResponse contains the needed fields of the GetKey response

type Purpose

type Purpose struct {
	Name     string
	HexValue string
	Value    big.Int
}

Purpose contains the different representation of purpose along the code

var (
	// KeyPurposeManagement purpose stores the management key to interact with the ERC725 identity contract
	KeyPurposeManagement Purpose
	// KeyPurposeAction purpose stores the action key to interact with the ERC725 identity contract
	KeyPurposeAction Purpose
	// KeyPurposeP2PDiscovery purpose stores the action key to interact with the ERC725 identity contract
	KeyPurposeP2PDiscovery Purpose
	// KeyPurposeSigning purpose stores the action key to interact with the ERC725 identity contract
	KeyPurposeSigning Purpose
)

func GetPurposeByName

func GetPurposeByName(name string) Purpose

GetPurposeByName retrieves the Purpose by name

type Service added in v1.0.0

type Service interface {
	// AddKey adds a key to identity contract
	AddKey(ctx context.Context, key Key) error

	// AddKeysForAccount adds key from configuration
	AddKeysForAccount(acc config.Account) error

	// GetKey return a key from the identity contract
	GetKey(did DID, key [32]byte) (*KeyResponse, error)

	// RawExecute calls the execute method on the identity contract
	RawExecute(ctx context.Context, to common.Address, data []byte, gasLimit uint64) (txID IDTX, done chan error, err error)

	// Execute creates the abi encoding and calls the execute method on the identity contract
	Execute(ctx context.Context, to common.Address, contractAbi, methodName string, args ...interface{}) (txID IDTX, done chan error, err error)

	// AddMultiPurposeKey adds a key with multiple purposes
	AddMultiPurposeKey(context context.Context, key [32]byte, purposes []*big.Int, keyType *big.Int) error

	// RevokeKey revokes an existing key in the smart contract
	RevokeKey(ctx context.Context, key [32]byte) error

	// GetClientP2PURL returns the p2p url associated with the did
	GetClientP2PURL(did DID) (string, error)

	//Exists checks if an identity contract exists
	Exists(ctx context.Context, did DID) error

	// ValidateKey checks if a given key is valid for the given centrifugeID.
	ValidateKey(ctx context.Context, did DID, key []byte, purpose *big.Int, at *time.Time) error

	// ValidateSignature checks if signature is valid for given identity
	ValidateSignature(did DID, pubKey []byte, signature []byte, message []byte, timestamp time.Time) error

	// CurrentP2PKey retrieves the last P2P key stored in the identity
	CurrentP2PKey(did DID) (ret string, err error)

	// GetClientsP2PURLs returns p2p urls associated with each centIDs
	// will error out at first failure
	GetClientsP2PURLs(dids []*DID) ([]string, error)

	// GetKeysByPurpose returns keys grouped by purpose from the identity contract.
	GetKeysByPurpose(did DID, purpose *big.Int) ([]Key, error)
}

Service interface contains the methods to interact with the identity contract

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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