types

package
v1.3.3 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DIDMethod     = "panacea"
	Base58Charset = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
)
View Source
const (
	CodeDIDExists                 sdk.CodeType = 101
	CodeInvalidDID                sdk.CodeType = 102
	CodeInvalidDIDDocument        sdk.CodeType = 103
	CodeDIDNotFound               sdk.CodeType = 104
	CodeInvalidSignature          sdk.CodeType = 105
	CodeInvalidVeriMethodID       sdk.CodeType = 106
	CodeVeriMethodIDNotFound      sdk.CodeType = 107
	CodeSigVerificationFailed     sdk.CodeType = 108
	CodeInvalidSecp256k1PublicKey sdk.CodeType = 109
	CodeInvalidNetworkID          sdk.CodeType = 110
	CodeInvalidDIDDocumentWithSeq sdk.CodeType = 111
	CodeDIDDeactivated            sdk.CodeType = 112
	CodeInvalidKeyController      sdk.CodeType = 113
)
View Source
const (
	// module name
	ModuleName = "did"

	// StoreKey to be used when creating the KVStore
	StoreKey = ModuleName

	// RouterKey to be used in router
	RouterKey = ModuleName

	// QuerierRoute is the query router key
	QuerierRoute = ModuleName
)
View Source
const DefaultCodespace sdk.CodespaceType = ModuleName
View Source
const InitialSequence = Sequence(0)
View Source
const (
	QueryDID = "did"
)

Variables

View Source
var ModuleCdc *codec.Codec

ModuleCdc generic sealed codec to be used throughout module

Functions

func ErrDIDDeactivated

func ErrDIDDeactivated(did DID) sdk.Error

func ErrDIDExists

func ErrDIDExists(did DID) sdk.Error

func ErrDIDNotFound

func ErrDIDNotFound(did DID) sdk.Error

func ErrInvalidDID

func ErrInvalidDID(did string) sdk.Error

func ErrInvalidDIDDocument

func ErrInvalidDIDDocument(doc DIDDocument) sdk.Error

func ErrInvalidDIDDocumentWithSeq

func ErrInvalidDIDDocumentWithSeq(doc DIDDocumentWithSeq) sdk.Error

func ErrInvalidKeyController

func ErrInvalidKeyController(did DID) sdk.Error

func ErrInvalidNetworkID

func ErrInvalidNetworkID(id string) sdk.Error

func ErrInvalidSecp256k1PublicKey

func ErrInvalidSecp256k1PublicKey(err error) sdk.Error

func ErrInvalidSignature

func ErrInvalidSignature(sig []byte) sdk.Error

func ErrInvalidVeriMethodID

func ErrInvalidVeriMethodID(id string) sdk.Error

func ErrSigVerificationFailed

func ErrSigVerificationFailed() sdk.Error

func ErrVeriMethodIDNotFound

func ErrVeriMethodIDNotFound(id VeriMethodID) sdk.Error

func NewPrivKeyFromBytes

func NewPrivKeyFromBytes(bz []byte) (secp256k1.PrivKeySecp256k1, error)

NewPrivKeyFromBytes converts a byte slice into a Secp256k1 private key. It returns an error when the length of the input is invalid.

func NewPubKeyFromBase58

func NewPubKeyFromBase58(b58 string) (secp256k1.PubKeySecp256k1, error)

NewPubKeyFromBase58 decodes a base58-encoded Secp256k1 public key. It returns an error when the length of the input is invalid.

func RegisterCodec

func RegisterCodec(cdc *codec.Codec)

RegisterCodec registers concrete types on Amino codec

func Sign

func Sign(data Signable, seq Sequence, privKey crypto.PrivKey) ([]byte, error)

func ValidateGenesis

func ValidateGenesis(data GenesisState) error

Types

type Authentication

type Authentication struct {
	VeriMethodID VeriMethodID
	// DedicatedMethod is not nil if it is only authorized for authentication
	// https://www.w3.org/TR/did-core/#example-18-authentication-property-containing-three-verification-methods
	DedicatedMethod *VeriMethod
}

func (Authentication) MarshalJSON

func (a Authentication) MarshalJSON() ([]byte, error)

func (*Authentication) UnmarshalJSON

func (a *Authentication) UnmarshalJSON(bz []byte) error

func (Authentication) Valid

func (a Authentication) Valid(did DID) bool

type Context

type Context string
const (
	ContextDIDV1      Context = "https://www.w3.org/ns/did/v1"
	ContextSecurityV1 Context = "https://w3id.org/security/v1"
)

func (Context) Valid

func (ctx Context) Valid() bool

type Contexts

type Contexts []Context

func (Contexts) MarshalJSON

func (ctxs Contexts) MarshalJSON() ([]byte, error)

func (*Contexts) UnmarshalJSON

func (ctxs *Contexts) UnmarshalJSON(bz []byte) error

func (Contexts) Valid

func (ctxs Contexts) Valid() bool

type DID

type DID string

func NewDID

func NewDID(pubKey crypto.PubKey, keyType KeyType) DID

func ParseDID

func ParseDID(str string) (DID, error)

func (DID) Empty

func (did DID) Empty() bool

func (DID) GetSignBytes

func (did DID) GetSignBytes() []byte

GetSignBytes returns a byte array which is used to generate a signature for verifying DID ownership.

func (DID) Valid

func (did DID) Valid() bool

type DIDDocument

type DIDDocument struct {
	Contexts        Contexts         `json:"@context"`
	ID              DID              `json:"id"`
	VeriMethods     []VeriMethod     `json:"verificationMethod"`
	Authentications []Authentication `json:"authentication"`
}

func NewDIDDocument

func NewDIDDocument(id DID, veriMethod VeriMethod) DIDDocument

func (DIDDocument) Empty

func (doc DIDDocument) Empty() bool

func (DIDDocument) GetSignBytes

func (doc DIDDocument) GetSignBytes() []byte

GetSignBytes returns a byte array which is used to generate a signature for verifying DID ownership.

func (DIDDocument) String

func (doc DIDDocument) String() string

func (DIDDocument) Valid

func (doc DIDDocument) Valid() bool

func (DIDDocument) VeriMethodByID

func (doc DIDDocument) VeriMethodByID(id VeriMethodID) (VeriMethod, bool)

VeriMethodByID finds a VeriMethod by ID. If the corresponding VeriMethod doesn't exist, it returns a false.

type DIDDocumentWithSeq

type DIDDocumentWithSeq struct {
	Document DIDDocument `json:"document"`
	Seq      Sequence    `json:"sequence"`
}

DIDDocumentWithSeq is for storing a Sequence along with a DIDDocument. The Sequence is used to make DID operations not replay-able. It's used to generate signatures of DID operations.

func NewDIDDocumentWithSeq

func NewDIDDocumentWithSeq(doc DIDDocument, seq Sequence) DIDDocumentWithSeq

func (DIDDocumentWithSeq) Deactivate

func (d DIDDocumentWithSeq) Deactivate(newSeq Sequence) DIDDocumentWithSeq

Deactivate creates a new DIDDocumentWithSeq with an empty DIDDocument (tombstone). Note that it requires a new sequence.

func (DIDDocumentWithSeq) Deactivated

func (d DIDDocumentWithSeq) Deactivated() bool

Deactivated returns true if the DIDDocument has been activated.

func (DIDDocumentWithSeq) Empty

func (d DIDDocumentWithSeq) Empty() bool

Empty returns true if all members in DIDDocumentWithSeq are empty. The empty struct means that the entity doesn't exist.

func (DIDDocumentWithSeq) Valid

func (d DIDDocumentWithSeq) Valid() bool

type GenesisDIDDocumentKey

type GenesisDIDDocumentKey struct {
	DID DID `json:"did"`
}

func (GenesisDIDDocumentKey) Marshal

func (k GenesisDIDDocumentKey) Marshal() string

func (*GenesisDIDDocumentKey) Unmarshal

func (k *GenesisDIDDocumentKey) Unmarshal(key string) error

type GenesisState

type GenesisState struct {
	Documents map[string]DIDDocumentWithSeq `json:"documents"`
}

func DefaultGenesisState

func DefaultGenesisState() GenesisState

type KeyType

type KeyType string
const (
	ES256K KeyType = "Secp256k1VerificationKey2018"
)

func (KeyType) Valid

func (t KeyType) Valid() bool

type MsgCreateDID

type MsgCreateDID struct {
	DID          DID            `json:"did"`
	Document     DIDDocument    `json:"document"`
	VeriMethodID VeriMethodID   `json:"verification_method_id"`
	Signature    []byte         `json:"signature"`
	FromAddress  sdk.AccAddress `json:"from_address"`
}

MsgCreateDID defines a CreateDID message.

func NewMsgCreateDID

func NewMsgCreateDID(did DID, doc DIDDocument, veriMethodID VeriMethodID, sig []byte, fromAddr sdk.AccAddress) MsgCreateDID

NewMsgCreateDID is a constructor of MsgCreateDID.

func (MsgCreateDID) GetSignBytes

func (msg MsgCreateDID) GetSignBytes() []byte

GetSignBytes returns the canonical byte representation of the message. Used to generate a signature.

func (MsgCreateDID) GetSigners

func (msg MsgCreateDID) GetSigners() []sdk.AccAddress

GetSigners return the addresses of signers that must sign.

func (MsgCreateDID) Route

func (msg MsgCreateDID) Route() string

Route returns the name of the module.

func (MsgCreateDID) Type

func (msg MsgCreateDID) Type() string

Type returns the name of the action.

func (MsgCreateDID) ValidateBasic

func (msg MsgCreateDID) ValidateBasic() sdk.Error

ValidateBasic runs stateless checks on the message.

type MsgDeactivateDID

type MsgDeactivateDID struct {
	DID          DID            `json:"did"`
	VeriMethodID VeriMethodID   `json:"verification_method_id"`
	Signature    []byte         `json:"signature"`
	FromAddress  sdk.AccAddress `json:"from_address"`
}

MsgDeactivateDID defines a UpdateDID message.

func NewMsgDeactivateDID

func NewMsgDeactivateDID(did DID, veriMethodID VeriMethodID, sig []byte, fromAddr sdk.AccAddress) MsgDeactivateDID

NewMsgDeactivateDID is a constructor of MsgDeactivateDID.

func (MsgDeactivateDID) GetSignBytes

func (msg MsgDeactivateDID) GetSignBytes() []byte

GetSignBytes returns the canonical byte representation of the message. Used to generate a signature.

func (MsgDeactivateDID) GetSigners

func (msg MsgDeactivateDID) GetSigners() []sdk.AccAddress

GetSigners return the addresses of signers that must sign.

func (MsgDeactivateDID) Route

func (msg MsgDeactivateDID) Route() string

Route returns the name of the module.

func (MsgDeactivateDID) Type

func (msg MsgDeactivateDID) Type() string

Type returns the name of the action.

func (MsgDeactivateDID) ValidateBasic

func (msg MsgDeactivateDID) ValidateBasic() sdk.Error

VaValidateBasic runs stateless checks on the message.

type MsgUpdateDID

type MsgUpdateDID struct {
	DID          DID            `json:"did"`
	Document     DIDDocument    `json:"document"`
	VeriMethodID VeriMethodID   `json:"verification_method_id"`
	Signature    []byte         `json:"signature"`
	FromAddress  sdk.AccAddress `json:"from_address"`
}

MsgUpdateDID defines a UpdateDID message.

func NewMsgUpdateDID

func NewMsgUpdateDID(did DID, doc DIDDocument, veriMethodID VeriMethodID, sig []byte, fromAddr sdk.AccAddress) MsgUpdateDID

NewMsgUpdateDID is a constructor of MsgUpdateDID.

func (MsgUpdateDID) GetSignBytes

func (msg MsgUpdateDID) GetSignBytes() []byte

GetSignBytes returns the canonical byte representation of the message. Used to generate a signature.

func (MsgUpdateDID) GetSigners

func (msg MsgUpdateDID) GetSigners() []sdk.AccAddress

GetSigners return the addresses of signers that must sign.

func (MsgUpdateDID) Route

func (msg MsgUpdateDID) Route() string

Route returns the name of the module.

func (MsgUpdateDID) Type

func (msg MsgUpdateDID) Type() string

Type returns the name of the action.

func (MsgUpdateDID) ValidateBasic

func (msg MsgUpdateDID) ValidateBasic() sdk.Error

ValidateBasic runs stateless checks on the message.

type QueryDIDParams

type QueryDIDParams struct {
	DID DID
}

func NewQueryDIDParams

func NewQueryDIDParams(DID DID) *QueryDIDParams

type Sequence

type Sequence uint64

Sequence is a preventative measure to distinguish replayed transactions (replay attack).

func Verify

func Verify(sig []byte, data Signable, seq Sequence, pubKey crypto.PubKey) (Sequence, bool)

type Signable

type Signable interface {
	// Get the canonical byte representation of the data.
	GetSignBytes() []byte
}

Signable is an interface for data which can be converted to a sign-able byte slice (deterministic).

type VeriMethod

type VeriMethod struct {
	ID           VeriMethodID `json:"id"`
	Type         KeyType      `json:"type"`
	Controller   DID          `json:"controller"`
	PubKeyBase58 string       `json:"publicKeyBase58"`
}

TODO: support various types: https://www.w3.org/TR/did-core/#key-types-and-formats

func NewVeriMethod

func NewVeriMethod(id VeriMethodID, keyType KeyType, controller DID, key crypto.PubKey) VeriMethod

func (VeriMethod) Valid

func (pk VeriMethod) Valid(did DID) bool

type VeriMethodID

type VeriMethodID string

func NewVeriMethodID

func NewVeriMethodID(did DID, name string) VeriMethodID

func ParseVeriMethodID

func ParseVeriMethodID(id string, did DID) (VeriMethodID, error)

func (VeriMethodID) Valid

func (id VeriMethodID) Valid(did DID) bool

Jump to

Keyboard shortcuts

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