did

package
v0.0.4-alpha Latest Latest
Warning

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

Go to latest
Published: May 10, 2023 License: Apache-2.0 Imports: 15 Imported by: 25

Documentation

Index

Constants

View Source
const (
	DIDDocumentLDContext string = "https://w3id.org/did/v1"
	DIDDocumentType      string = "Document"
	BuilderEmptyError    string = "builder cannot be empty"
)
View Source
const (
	KnownDIDContext string = "https://www.w3.org/ns/did/v1"

	// Base58BTCMultiBase Base58BTC https://github.com/multiformats/go-multibase/blob/master/multibase.go
	Base58BTCMultiBase = multibase.Base58BTC
)
View Source
const (
	Ed25519MultiCodec   = multicodec.Ed25519Pub
	X25519MultiCodec    = multicodec.X25519Pub
	SECP256k1MultiCodec = multicodec.Secp256k1Pub
	P256MultiCodec      = multicodec.P256Pub
	P384MultiCodec      = multicodec.P384Pub
	P521MultiCodec      = multicodec.P521Pub
	RSAMultiCodec       = multicodec.RsaPub
	SHA256MultiCodec    = multicodec.Sha2_256
)

Variables

This section is empty.

Functions

func DecodeMultibaseEncodedKey

func DecodeMultibaseEncodedKey(d string) ([]byte, cryptosuite.LDKeyType, crypto.KeyType, error)

DecodeMultibaseEncodedKey turns a multibase encoded key to a key and its key type

func DecodeMultibasePublicKeyWithType

func DecodeMultibasePublicKeyWithType(data []byte) ([]byte, cryptosuite.LDKeyType, error)

DecodeMultibasePublicKeyWithType decodes public key with an LD Key Type

func GetKeyFromVerificationMethod

func GetKeyFromVerificationMethod(did Document, kid string) (gocrypto.PublicKey, error)

GetKeyFromVerificationMethod resolves a DID and provides a kid and public key needed for data verification it is possible that a DID has multiple verification methods, in which case a kid must be provided, otherwise resolution will fail. A KID can be fully qualified (e.g. did:example:123#key-1) or just the fragment (e.g. key-1, #key-1) Some DIDs, like did:key, use the entire DID as the KID, so we need to handle all three cases.

func KeyTypeToLDKeyType

func KeyTypeToLDKeyType(kt crypto.KeyType) (cryptosuite.LDKeyType, error)

KeyTypeToLDKeyType converts crypto.KeyType to cryptosuite.LDKeyType

func KeyTypeToMultiCodec

func KeyTypeToMultiCodec(kt crypto.KeyType) (multicodec.Code, error)

func MultiBaseToPubKeyBytes

func MultiBaseToPubKeyBytes(mb string) ([]byte, error)

MultiBaseToPubKeyBytes converts a multibase encoded public key to public key bytes for known multibase encodings

func MultiCodecToKeyType

func MultiCodecToKeyType(codec multicodec.Code) (crypto.KeyType, error)

func MultiCodecToLDKeyType

func MultiCodecToLDKeyType(codec multicodec.Code) (cryptosuite.LDKeyType, error)

MultiCodecToLDKeyType goes from a multicodec to LD key type

Types

type DID

type DID interface {
	// IsValid checks if the DID is compliant with its methods definition
	IsValid() bool
	// String Returns the string representation of the DID identifier (e.g. did:example:abcd)
	String() string
	// Suffix provides the value of the DID without the method prefix
	Suffix() (string, error)
	// Method provides the method for the DID
	Method() Method
}

DID encapsulates functionality common to all DIDs

type DIDDocumentBuilder

type DIDDocumentBuilder struct {
	*Document
	// contains filtered or unexported fields
}

DIDDocumentBuilder contexts and types are kept to avoid having cast to/from any values

func NewDIDDocumentBuilder

func NewDIDDocumentBuilder() DIDDocumentBuilder

NewDIDDocumentBuilder Creates a new DID Document Builder

func (*DIDDocumentBuilder) AddAssertionMethod

func (builder *DIDDocumentBuilder) AddAssertionMethod(m VerificationMethodSet) error

AddAssertionMethod Note: Not thread safe

func (*DIDDocumentBuilder) AddAuthenticationMethod

func (builder *DIDDocumentBuilder) AddAuthenticationMethod(m VerificationMethodSet) error

AddAuthenticationMethod Note: Not thread safe

func (*DIDDocumentBuilder) AddCapabilityDelegation

func (builder *DIDDocumentBuilder) AddCapabilityDelegation(m VerificationMethodSet) error

AddCapabilityDelegation Note: Not thread safe

func (*DIDDocumentBuilder) AddCapabilityInvocation

func (builder *DIDDocumentBuilder) AddCapabilityInvocation(m VerificationMethodSet) error

AddCapabilityInvocation Note: Not thread safe

func (*DIDDocumentBuilder) AddContext

func (builder *DIDDocumentBuilder) AddContext(context any) error

func (*DIDDocumentBuilder) AddKeyAgreement

func (builder *DIDDocumentBuilder) AddKeyAgreement(m VerificationMethodSet) error

AddKeyAgreement Note: Not thread safe

func (*DIDDocumentBuilder) AddService

func (builder *DIDDocumentBuilder) AddService(s Service) error

AddService Note: Not thread safe

func (*DIDDocumentBuilder) AddVerificationMethod

func (builder *DIDDocumentBuilder) AddVerificationMethod(m VerificationMethod) error

AddVerificationMethod Note: Not thread safe

func (*DIDDocumentBuilder) Build

func (builder *DIDDocumentBuilder) Build() (*Document, error)

Build builds the DID Document

func (*DIDDocumentBuilder) IsEmpty

func (builder *DIDDocumentBuilder) IsEmpty() bool

func (*DIDDocumentBuilder) SetAlsoKnownAs

func (builder *DIDDocumentBuilder) SetAlsoKnownAs(name string) error

func (*DIDDocumentBuilder) SetController

func (builder *DIDDocumentBuilder) SetController(controller string) error

func (*DIDDocumentBuilder) SetID

func (builder *DIDDocumentBuilder) SetID(id string) error

type Document

type Document struct {
	Context any `json:"@context,omitempty"`
	// As per https://www.w3.org/TR/did-core/#did-subject intermediate representations of DID Documents do not
	// require an ID property. The provided test vectors demonstrate IRs. As such, the property is optional.
	ID                   string                  `json:"id,omitempty"`
	Controller           string                  `json:"controller,omitempty"`
	AlsoKnownAs          string                  `json:"alsoKnownAs,omitempty"`
	VerificationMethod   []VerificationMethod    `json:"verificationMethod,omitempty" validate:"dive"`
	Authentication       []VerificationMethodSet `json:"authentication,omitempty" validate:"dive"`
	AssertionMethod      []VerificationMethodSet `json:"assertionMethod,omitempty" validate:"dive"`
	KeyAgreement         []VerificationMethodSet `json:"keyAgreement,omitempty" validate:"dive"`
	CapabilityInvocation []VerificationMethodSet `json:"capabilityInvocation,omitempty" validate:"dive"`
	CapabilityDelegation []VerificationMethodSet `json:"capabilityDelegation,omitempty" validate:"dive"`
	Services             []Service               `json:"service,omitempty" validate:"dive"`
}

Document is a representation of the did core specification https://www.w3.org/TR/did-core TODO(gabe) enforce validation of DID syntax https://www.w3.org/TR/did-core/#did-syntax

func (*Document) IsEmpty

func (d *Document) IsEmpty() bool

func (*Document) IsValid

func (d *Document) IsValid() error

type Method

type Method string
const (
	KeyMethod  Method = "key"
	PeerMethod Method = "peer"
	PKHMethod  Method = "pkh"
	WebMethod  Method = "web"
	IONMethod  Method = "ion"
	JWKMethod  Method = "jwk"
)

func (Method) String

func (m Method) String() string

type Service

type Service struct {
	ID   string `json:"id" validate:"required"`
	Type string `json:"type" validate:"required"`
	// A string, map, or set composed of one or more strings and/or maps
	// All string values must be valid URIs
	ServiceEndpoint any      `json:"serviceEndpoint" validate:"required"`
	RoutingKeys     []string `json:"routingKeys,omitempty"`
	Accept          []string `json:"accept,omitempty"`
}

Service is a property compliant with the did-core spec https://www.w3.org/TR/did-core/#services

func (*Service) IsValid

func (s *Service) IsValid() bool

type VerificationMethod

type VerificationMethod struct {
	ID              string                `json:"id" validate:"required"`
	Type            cryptosuite.LDKeyType `json:"type" validate:"required"`
	Controller      string                `json:"controller" validate:"required"`
	PublicKeyBase58 string                `json:"publicKeyBase58,omitempty"`
	// must conform to https://datatracker.ietf.org/doc/html/rfc7517
	PublicKeyJWK *jwx.PublicKeyJWK `json:"publicKeyJwk,omitempty" validate:"omitempty,dive"`
	// https://datatracker.ietf.org/doc/html/draft-multiformats-multibase-03
	PublicKeyMultibase string `json:"publicKeyMultibase,omitempty"`
	// for PKH DIDs - https://github.com/w3c-ccg/did-pkh/blob/90b28ad3c18d63822a8aab3c752302aa64fc9382/did-pkh-method-draft.md
	BlockchainAccountID string `json:"blockchainAccountId,omitempty"`
}

func ConstructJWKVerificationMethod

func ConstructJWKVerificationMethod(id, keyReference string, pubKey []byte, keyType cryptosuite.LDKeyType,
	cryptoKeyType crypto.KeyType) (*VerificationMethod, error)

ConstructJWKVerificationMethod builds a DID verification method with a known LD key type as a JWK

type VerificationMethodSet

type VerificationMethodSet any

VerificationMethodSet is a union type supporting the `authentication`, `assertionMethod`, `keyAgreement`, `capabilityInvocation`, and `capabilityDelegation` types. A set of one or more verification methods. Each verification method MAY be embedded or referenced. TODO(gabe) consider changing this to a custom unmarshaler https://stackoverflow.com/a/28016508

Directories

Path Synopsis
Package ion provides all the functionality you need to interact with an ION service and manage your ION DID.
Package ion provides all the functionality you need to interact with an ION service and manage your ION DID.
Package peer DID Peer ------------------------------------------------ https://identity.foundation/peer-did-method-spec/
Package peer DID Peer ------------------------------------------------ https://identity.foundation/peer-did-method-spec/

Jump to

Keyboard shortcuts

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