Documentation
¶
Index ¶
- Constants
- Variables
- func ValidateMethod(d DID, expected string) error
- type Context
- type DID
- func (d DID) Defined() bool
- func (d DID) Identifier() string
- func (d DID) MarshalCBOR(w io.Writer) error
- func (d DID) MarshalDagJSON(w io.Writer) error
- func (d DID) MarshalJSON() ([]byte, error)
- func (d DID) Method() string
- func (d DID) String() string
- func (d *DID) UnmarshalCBOR(r io.Reader) error
- func (d *DID) UnmarshalDagJSON(r io.Reader) error
- func (d *DID) UnmarshalJSON(b []byte) error
- type DateTimeStamp
- type Document
- type GenericMap
- type OneOrMany
- type Resolver
- type ResolverFunc
- type ResolverMap
- type Service
- type URL
- type UnsupportedMethodError
- type VerificationMaterial
- type VerificationMethod
- func (v VerificationMethod) Equal(other VerificationMethod) bool
- func (v VerificationMethod) ExpiredAt(t time.Time) bool
- func (v VerificationMethod) MarshalJSON() ([]byte, error)
- func (v VerificationMethod) RevokedAt(t time.Time) bool
- func (v VerificationMethod) String() string
- func (v *VerificationMethod) UnmarshalJSON(b []byte) error
- func (v VerificationMethod) ValidAt(t time.Time) bool
- type VerificationMethods
- type VerificationRelationship
- func (vr *VerificationRelationship) Add(method VerificationMethod) error
- func (vr *VerificationRelationship) All() []VerificationMethod
- func (vr *VerificationRelationship) Get(i int) URL
- func (vr *VerificationRelationship) IsZero() bool
- func (vr *VerificationRelationship) Len() int
- func (vr *VerificationRelationship) MarshalJSON() ([]byte, error)
- func (vr *VerificationRelationship) UnmarshalJSON(data []byte) error
Constants ¶
const ( MultikeyPublicKeyMultibaseProp = "publicKeyMultibase" MultikeySecretKeyMultibaseProp = "secretKeyMultibase" )
const ( JsonWebKeyPublicKeyJwkProp = "publicKeyJwk" JsonWebKeySecretKeyJwkProp = "secretKeyJwk" )
const CoreContext = "https://www.w3.org/ns/did/v1.1"
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).
const DIDCore = 0x0d1d
const Ed25519 = 0xed
const JsonWebKeyVerificationMethodType = "JsonWebKey"
https://www.w3.org/TR/cid-1.0/#JsonWebKey
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.
const MultikeyVerificationMethodType = "Multikey"
https://www.w3.org/TR/cid-1.0/#Multikey
const Prefix = "did:"
const RSA = 0x1205
const Secp256k1 = 0xe7
Variables ¶
var MethodOffset = varint.UvarintSize(uint64(DIDCore))
var Undef = DID{}
Undef can be used to represent a nil or undefined DID, using DID{} directly is also acceptable.
Functions ¶
func ValidateMethod ¶
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 (*Context) UnmarshalJSON ¶
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 (DID) Identifier ¶
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) MarshalJSON ¶
func (DID) Method ¶
Method returns the DID method name (e.g. "key", "web") parsed from the scheme. Returns "" for an undefined DID.
func (*DID) UnmarshalJSON ¶
type DateTimeStamp ¶
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 (Document) Fragment ¶
Fragment returns a URL for the given fragment within this document, e.g. for a verification method.
func (*Document) UnmarshalJSON ¶
type GenericMap ¶
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 (*OneOrMany[T]) UnmarshalJSON ¶
type ResolverFunc ¶
ResolverFunc is a simple function Resolver.
type ResolverMap ¶
type URL ¶
URL is a wrapper around url.URL that implements json.Marshaler and json.Unmarshaler.
func (URL) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (*URL) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.
type UnsupportedMethodError ¶
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 (v VerificationMethod) Equal(other VerificationMethod) bool
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
type VerificationMethods ¶
type VerificationMethods map[string]VerificationMethod
func (*VerificationMethods) Add ¶
func (vms *VerificationMethods) Add(vm VerificationMethod) error
func (*VerificationMethods) All ¶
func (v *VerificationMethods) All() []VerificationMethod
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 (vr *VerificationRelationship) Add(method VerificationMethod) error
func (*VerificationRelationship) All ¶
func (vr *VerificationRelationship) All() []VerificationMethod
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