did

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BearerDID

type BearerDID struct {
	DID
	crypto.KeyManager
	Document didcore.Document
}

BearerDID is a composite type that combines a DID with a KeyManager containing keys associated to the DID. Together, these two components form a BearerDID that can be used to sign and verify data.

func FromPortableDID

func FromPortableDID(portableDID PortableDID) (BearerDID, error)

FromPortableDID inflates a BearerDID from a portable format.

func (*BearerDID) GetSigner

func (d *BearerDID) GetSigner(selector didcore.VMSelector) (Signer, didcore.VerificationMethod, error)

GetSigner returns a sign method that can be used to sign a payload using a key associated to the DID. This function also returns the verification method needed to verify the signature.

Providing the verification method allows the caller to provide the signature's recipient with a reference to the verification method needed to verify the payload. This is often done by including the verification method id either alongside the signature or as part of the header in the case of JSON Web Signatures.

The verifier can dereference the verification method id to obtain the public key needed to verify the signature.

This function takes a Verification Method selector that can be used to select a specific verification method from the DID Document if desired. If no selector is provided, the payload will be signed with the key associated to the first verification method in the DID Document.

The selector can either be a Verification Method ID or a Purpose. If a Purpose is provided, the first verification method in the DID Document that has the provided purpose will be used to sign the payload.

The returned signer is a function that takes a byte payload and returns a byte signature.

func (*BearerDID) ToPortableDID

func (d *BearerDID) ToPortableDID() (PortableDID, error)

ToPortableDID exports a BearerDID to a portable format

type DID

type DID struct {
	// URI represents the complete Decentralized Identifier (DID) URI.
	// Spec: https://www.w3.org/TR/did-core/#did-syntax
	URI string

	// Method specifies the DID method in the URI, which indicates the underlying
	// method-specific identifier scheme (e.g., jwk, dht, key, etc.).
	// Spec: https://www.w3.org/TR/did-core/#method-schemes
	Method string

	// ID is the method-specific identifier in the DID URI.
	// Spec: https://www.w3.org/TR/did-core/#method-specific-id
	ID string

	// Params is a map containing optional parameters present in the DID URI.
	// These parameters are method-specific.
	// Spec: https://www.w3.org/TR/did-core/#did-parameters
	Params map[string]string

	// Path is an optional path component in the DID URI.
	// Spec: https://www.w3.org/TR/did-core/#path
	Path string

	// Query is an optional query component in the DID URI, used to express a request
	// for a specific representation or resource related to the DID.
	// Spec: https://www.w3.org/TR/did-core/#query
	Query string

	// Fragment is an optional fragment component in the DID URI, used to reference
	// a specific part of a DID document.
	// Spec: https://www.w3.org/TR/did-core/#fragment
	Fragment string
}

DID provides a way to parse and handle Decentralized Identifier (DID) URIs according to the W3C DID Core specification (https://www.w3.org/TR/did-core/).

func MustParse

func MustParse(input string) DID

MustParse parses a DID URI with Parse, and panics on error

func Parse

func Parse(input string) (DID, error)

Parse parses a DID URI in accordance to the ABNF rules specified in the specification here: https://www.w3.org/TR/did-core/#did-syntax. Returns a DIDURI instance if parsing is successful. Otherwise, returns an error.

func (DID) MarshalText

func (d DID) MarshalText() (text []byte, err error)

MarshalText will convert the given DID's URL into a byte array

func (*DID) Scan

func (d *DID) Scan(src any) error

Scan implements the Scanner interface

func (DID) String

func (d DID) String() string

func (DID) URL

func (d DID) URL() string

URL represents the DID URI + A network location identifier for a specific resource Spec: https://www.w3.org/TR/did-core/#did-url-syntax

func (*DID) UnmarshalText

func (d *DID) UnmarshalText(text []byte) error

UnmarshalText will deserialize the given byte array into an instance of DID

func (DID) Value

func (d DID) Value() (driver.Value, error)

Value implements the driver Valuer interface

type PortableDID

type PortableDID struct {
	// URI is the DID string as per https://www.w3.org/TR/did-core/#did-syntax
	URI string `json:"uri"`
	// PrivateKeys is an array of private keys associated to the BearerDID's verification methods
	// Note: PrivateKeys will be empty if the BearerDID was created using a KeyManager that does not
	// support exporting private keys (e.g. HSM based KeyManagers)
	PrivateKeys []jwk.JWK `json:"privateKeys"`
	// Document is the DID Document associated to the BearerDID
	Document didcore.Document `json:"document"`
	// Metadata is a map that can be used to store additional method specific data
	// that is necessary to inflate a BearerDID from a PortableDID
	Metadata map[string]interface{} `json:"metadata"`
}

PortableDID is a serializable BearerDID. VerificationMethod contains the private key of each verification method that the BearerDID's key manager contains

type Signer

type Signer func(payload []byte) ([]byte, error)

Signer is a function that can be used to sign a payload with a key associated to a BearerDID.

Jump to

Keyboard shortcuts

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