did

package
v0.0.0-...-ef993e1 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: Apache-2.0, MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MultikeyPublicKeyMultibaseProp = "publicKeyMultibase"
	MultikeySecretKeyMultibaseProp = "secretKeyMultibase"
)
View Source
const (
	JsonWebKeyPublicKeyJwkProp = "publicKeyJwk"
	JsonWebKeySecretKeyJwkProp = "secretKeyJwk"
)
View Source
const CoreContext = "https://www.w3.org/ns/did/v1.1"
View Source
const CoreContextV1 = "https://www.w3.org/ns/did/v1"

CoreContextV1 is the DID Core v1.0 context. It is accepted on input for interoperability with directories that have not adopted v1.1 (e.g. the PLC directory), but documents we produce always use CoreContext (v1.1).

View Source
const DIDCore = 0x0d1d
View Source
const Ed25519 = 0xed
View Source
const JsonWebKeyVerificationMethodType = "JsonWebKey"

https://www.w3.org/TR/cid-1.0/#JsonWebKey

View Source
const KeyPrefix = Prefix + "key:"

TODO: This should really go in `did/key`, but we use it in `did.Parse` to validate `did:key` DIDs during parsing. We could drop that, but it's a nice check to have.

View Source
const MultikeyVerificationMethodType = "Multikey"

https://www.w3.org/TR/cid-1.0/#Multikey

View Source
const Prefix = "did:"
View Source
const RSA = 0x1205
View Source
const Secp256k1 = 0xe7

Variables

View Source
var Undef = DID{}

Undef can be used to represent a nil or undefined DID, using DID{} directly is also acceptable.

Functions

func ValidateMethod

func ValidateMethod(d DID, expected string) error

Types

type Context

type Context []string

Context handles both string and []string formats for @context field as allowed by the DID Core specification

func (Context) MarshalJSON

func (fc Context) MarshalJSON() ([]byte, error)

func (*Context) UnmarshalJSON

func (fc *Context) UnmarshalJSON(data []byte) error

type DID

type DID struct {
	// contains filtered or unexported fields
}

DID is a decentralized identity, it has the format:

"did:%s:%s"

The underlying type is string, so DIDs are safe to compare with == and to use as keys in maps.

Note: this is not `type DID string` because cbor-gen does not recognise MarshalCBOR or UnmarshalCBOR when type is not struct.

func MustParse

func MustParse(str string) DID

func New

func New(method, identifier string) DID

func Parse

func Parse(str string) (DID, error)

func (DID) Defined

func (d DID) Defined() bool

func (DID) Identifier

func (d DID) Identifier() string

Identifier returns the method-specific identifier — everything after "did:<method>:". Per the DID spec, this segment may itself contain colons (e.g. "did:mailto:web.mail:alice" yields "web.mail:alice"). Returns "" for an undefined DID.

func (DID) MarshalCBOR

func (d DID) MarshalCBOR(w io.Writer) error

func (DID) MarshalDagJSON

func (d DID) MarshalDagJSON(w io.Writer) error

func (DID) MarshalJSON

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

func (DID) Method

func (d DID) Method() string

Method returns the DID method name (e.g. "key", "web") parsed from the scheme. Returns "" for an undefined DID.

func (DID) String

func (d DID) String() string

String formats the decentralized identity document (DID) as a string.

func (*DID) UnmarshalCBOR

func (d *DID) UnmarshalCBOR(r io.Reader) error

func (*DID) UnmarshalDagJSON

func (d *DID) UnmarshalDagJSON(r io.Reader) error

func (*DID) UnmarshalJSON

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

type DateTimeStamp

type DateTimeStamp time.Time

func (DateTimeStamp) MarshalJSON

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

func (DateTimeStamp) Time

func (d DateTimeStamp) Time() time.Time

func (*DateTimeStamp) UnmarshalJSON

func (d *DateTimeStamp) UnmarshalJSON(b []byte) error

type Document

type Document struct {
	Context              Context                   `json:"@context"`
	ID                   DID                       `json:"id"`
	Controller           OneOrMany[DID]            `json:"controller,omitempty"`
	AlsoKnownAs          []URL                     `json:"alsoKnownAs,omitempty"`
	Service              []Service                 `json:"service,omitempty"`
	VerificationMethods  *VerificationMethods      `json:"verificationMethod,omitempty"`
	Authentication       *VerificationRelationship `json:"authentication,omitzero"`
	AssertionMethod      *VerificationRelationship `json:"assertionMethod,omitzero"`
	KeyAgreement         *VerificationRelationship `json:"keyAgreement,omitzero"`
	CapabilityInvocation *VerificationRelationship `json:"capabilityInvocation,omitzero"`
	CapabilityDelegation *VerificationRelationship `json:"capabilityDelegation,omitzero"`
}

https://www.w3.org/TR/did-1.1/#core-properties

func NewDocument

func NewDocument(id DID) Document

func (Document) Fragment

func (d Document) Fragment(fragment string) URL

Fragment returns a URL for the given fragment within this document, e.g. for a verification method.

func (*Document) UnmarshalJSON

func (d *Document) UnmarshalJSON(b []byte) error

type GenericMap

type GenericMap = map[string]any

GenericMap is a value that is either specified to be a map with no particular set of keys, or whose spec is not currently implemented here.

type OneOrMany

type OneOrMany[T any] []T

func (OneOrMany[T]) MarshalJSON

func (om OneOrMany[T]) MarshalJSON() ([]byte, error)

func (*OneOrMany[T]) UnmarshalJSON

func (om *OneOrMany[T]) UnmarshalJSON(data []byte) error

type Resolver

type Resolver interface {
	Resolve(ctx context.Context, d DID) (Document, error)
}

Resolver resolves a DID to a DID Document.

type ResolverFunc

type ResolverFunc func(ctx context.Context, d DID) (Document, error)

ResolverFunc is a simple function Resolver.

func (ResolverFunc) Resolve

func (f ResolverFunc) Resolve(ctx context.Context, d DID) (Document, error)

type ResolverMap

type ResolverMap map[string]Resolver

func (ResolverMap) Resolve

func (rm ResolverMap) Resolve(ctx context.Context, d DID) (Document, error)

type Service

type Service = GenericMap

Services are not yet implemented.

type URL

type URL struct {
	*url.URL
}

URL is a wrapper around url.URL that implements json.Marshaler and json.Unmarshaler.

func ParseURL

func ParseURL(s string) (URL, error)

func (URL) MarshalJSON

func (u URL) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*URL) UnmarshalJSON

func (u *URL) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type UnsupportedMethodError

type UnsupportedMethodError struct {
	DID    DID
	Reason string
}

func (UnsupportedMethodError) Error

func (e UnsupportedMethodError) Error() string

type VerificationMaterial

type VerificationMaterial = GenericMap

VerificationMaterial is the type-specific material fields of a VerificationMethod, keyed by field name. https://www.w3.org/TR/cid-1.0/#verification-material

type VerificationMethod

type VerificationMethod struct {
	ID         URL            `json:"id"`
	Controller DID            `json:"controller"`
	Expires    *DateTimeStamp `json:"expires,omitempty"`
	Revoked    *DateTimeStamp `json:"revoked,omitempty"`
	Type       string
	Material   GenericMap
}

https://www.w3.org/TR/cid-1.0/#verification-methods

func (VerificationMethod) Equal

func (VerificationMethod) ExpiredAt

func (v VerificationMethod) ExpiredAt(t time.Time) bool

ExpiredAt reports whether the verification method is expired at time t.

func (VerificationMethod) MarshalJSON

func (v VerificationMethod) MarshalJSON() ([]byte, error)

func (VerificationMethod) RevokedAt

func (v VerificationMethod) RevokedAt(t time.Time) bool

RevokedAt reports whether the verification method is revoked at time t.

func (VerificationMethod) String

func (v VerificationMethod) String() string

func (*VerificationMethod) UnmarshalJSON

func (v *VerificationMethod) UnmarshalJSON(b []byte) error

func (VerificationMethod) ValidAt

func (v VerificationMethod) ValidAt(t time.Time) bool

ValidAt reports whether the verification method is valid at time t.

type VerificationMethods

type VerificationMethods map[string]VerificationMethod

func (*VerificationMethods) Add

func (*VerificationMethods) All

func (VerificationMethods) MarshalJSON

func (vms VerificationMethods) MarshalJSON() ([]byte, error)

func (*VerificationMethods) UnmarshalJSON

func (v *VerificationMethods) UnmarshalJSON(b []byte) error

type VerificationRelationship

type VerificationRelationship struct {
	// contains filtered or unexported fields
}

func (*VerificationRelationship) Add

func (*VerificationRelationship) All

func (*VerificationRelationship) Get

func (vr *VerificationRelationship) Get(i int) URL

func (*VerificationRelationship) IsZero

func (vr *VerificationRelationship) IsZero() bool

func (*VerificationRelationship) Len

func (vr *VerificationRelationship) Len() int

func (*VerificationRelationship) MarshalJSON

func (vr *VerificationRelationship) MarshalJSON() ([]byte, error)

func (*VerificationRelationship) UnmarshalJSON

func (vr *VerificationRelationship) UnmarshalJSON(data []byte) error

Directories

Path Synopsis
plc
gen command

Jump to

Keyboard shortcuts

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