did

package
v0.0.0-...-f93f300 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2023 License: Apache-2.0 Imports: 17 Imported by: 8

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 FullyQualifiedVerificationMethodID

func FullyQualifiedVerificationMethodID(did, verificationMethodID string) string

FullyQualifiedVerificationMethodID returns a fully qualified URL for a verification method.

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 KeyTypeToMultiCodec

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

func KeyTypeToMultikeyLDType

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

KeyTypeToMultikeyLDType converts crypto.KeyType to cryptosuite.LDKeyType for non JWKs

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

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

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

func NewDIDDocumentBuilder

func NewDIDDocumentBuilder() DocumentBuilder

NewDIDDocumentBuilder Creates a new DID Document Builder

func (*DocumentBuilder) AddAssertionMethod

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

AddAssertionMethod Note: Not thread safe

func (*DocumentBuilder) AddAuthenticationMethod

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

AddAuthenticationMethod Note: Not thread safe

func (*DocumentBuilder) AddCapabilityDelegation

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

AddCapabilityDelegation Note: Not thread safe

func (*DocumentBuilder) AddCapabilityInvocation

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

AddCapabilityInvocation Note: Not thread safe

func (*DocumentBuilder) AddContext

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

func (*DocumentBuilder) AddKeyAgreement

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

AddKeyAgreement Note: Not thread safe

func (*DocumentBuilder) AddService

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

AddService Note: Not thread safe

func (*DocumentBuilder) AddVerificationMethod

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

AddVerificationMethod Note: Not thread safe

func (*DocumentBuilder) Build

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

Build builds the DID Document

func (*DocumentBuilder) IsEmpty

func (builder *DocumentBuilder) IsEmpty() bool

func (*DocumentBuilder) SetAlsoKnownAs

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

func (*DocumentBuilder) SetController

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

func (*DocumentBuilder) SetID

func (builder *DocumentBuilder) SetID(id string) 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 PublicKeyPurpose

type PublicKeyPurpose string
const (
	Authentication       PublicKeyPurpose = "authentication"
	AssertionMethod      PublicKeyPurpose = "assertionMethod"
	CapabilityInvocation PublicKeyPurpose = "capabilityInvocation"
	CapabilityDelegation PublicKeyPurpose = "capabilityDelegation"
	KeyAgreement         PublicKeyPurpose = "keyAgreement"
)

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, controller string, pubKeyBytes []byte, cryptoKeyType crypto.KeyType) (*VerificationMethod, error)

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

func ConstructMultibaseVerificationMethod

func ConstructMultibaseVerificationMethod(id, controller string, pubKey []byte, keyType cryptosuite.LDKeyType) (*VerificationMethod, error)

ConstructMultibaseVerificationMethod builds a DID verification method with a known LD key type as a multibase encoded key

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