Documentation ¶
Index ¶
- Constants
- Variables
- func ContextContainsString(context Context, contextString string) bool
- func ContextPeekString(context Context) (string, bool)
- func LookupDIDCommRecipientKeys(didDoc *Doc) ([]string, bool)
- type Context
- type DID
- type DIDURL
- type Doc
- func (doc *Doc) JSONBytes() ([]byte, error)
- func (doc *Doc) MarshalJSON() ([]byte, error)
- func (doc *Doc) SerializeInterop() ([]byte, error)
- func (doc *Doc) ToLegacyRawDoc() (interface{}, error)
- func (doc *Doc) UnmarshalJSON(data []byte) error
- func (doc *Doc) VerificationMethods(customVerificationRelationships ...VerificationRelationship) map[VerificationRelationship][]Verification
- func (doc *Doc) VerifyProof(suites []verifier.SignatureSuite, jsonldOpts ...jsonld.ProcessorOpts) error
- type DocOption
- func WithAssertion(assertion []Verification) DocOption
- func WithAuthentication(auth []Verification) DocOption
- func WithCreatedTime(t time.Time) DocOption
- func WithKeyAgreement(keyAgreement []Verification) DocOption
- func WithService(svc []Service) DocOption
- func WithUpdatedTime(t time.Time) DocOption
- func WithVerificationMethod(pubKey []VerificationMethod) DocOption
- type DocResolution
- type DocumentMetadata
- type MethodMetadata
- type Proof
- type ProtocolOperation
- type Service
- type Verification
- type VerificationMethod
- func LookupPublicKey(id string, didDoc *Doc) (*VerificationMethod, bool)
- func NewVerificationMethodFromBytes(id, keyType, controller string, value []byte) *VerificationMethod
- func NewVerificationMethodFromBytesWithMultibase(id, keyType, controller string, value []byte, encoding multibase.Encoding) *VerificationMethod
- func NewVerificationMethodFromJWK(id, keyType, controller string, j *jwk.JWK) (*VerificationMethod, error)
- type VerificationRelationship
Constants ¶
const ( // ContextV1 of the DID document is the current V1 context name. ContextV1 = "https://www.w3.org/ns/did/v1" // ContextV1Old of the DID document representing the old/legacy V1 context name. ContextV1Old = "https://w3id.org/did/v1" )
Variables ¶
var ErrDIDDocumentNotExist = errors.New("did document not exists")
ErrDIDDocumentNotExist error did doc not exist.
var ErrKeyNotFound = errors.New("key not found")
ErrKeyNotFound is returned when key is not found.
var ErrProofNotFound = errors.New("proof not found")
ErrProofNotFound is returned when proof is not found.
Functions ¶
func ContextContainsString ¶
ContextContainsString returns true if the given Context contains the given context string. Strings nested inside maps are not checked.
func ContextPeekString ¶
ContextPeekString returns the first string element in `context`, which identifies the DID JSON-LD schema in use. This is generally useful to branch based on the version of the DID schema.
func LookupDIDCommRecipientKeys ¶
LookupDIDCommRecipientKeys gets the DIDComm recipient keys from the did doc which match the given parameters. DIDComm recipient keys are encoded as did:key identifiers. See: - https://github.com/hyperledger/aries-rfcs/blob/master/features/0067-didcomm-diddoc-conventions/README.md - https://github.com/hyperledger/aries-rfcs/blob/master/features/0360-use-did-key/README.md
Types ¶
type Context ¶
type Context interface{}
Context represents JSON-LD representation-specific DID-core @context, which must be either a string, or a list containing maps and/or strings.
func ContextCleanup ¶
ContextCleanup performs non-intrusive cleanup of the given context by converting `[]string(nil)` and `[]interface{}(nil)` to the empty string, and converting `[]interface{}` to `[]string` if it contains only string values. This will NOT change string arrays into single strings, even when they contain only a single string.
func ContextCopy ¶
ContextCopy create a deep copy of the given context. This is used to prevent unintentional mutations of `Context` instances which are passed to functions that modify and return updated values, e.g., `parseContext()`.
type DID ¶
type DID struct { Scheme string // Scheme is always "did" Method string // Method is the specific DID methods MethodSpecificID string // MethodSpecificID is the unique ID computed or assigned by the DID method }
DID is parsed according to the generic syntax: https://w3c.github.io/did-core/#generic-did-syntax
func Parse ¶
Parse parses the string according to the generic DID syntax. See https://w3c.github.io/did-core/#generic-did-syntax.
type DIDURL ¶
DIDURL holds a DID URL.
func ParseDIDURL ¶
ParseDIDURL parses a DID URL string into a DIDURL object.
type Doc ¶
type Doc struct { Context Context ID string AlsoKnownAs []string VerificationMethod []VerificationMethod Service []Service Authentication []Verification AssertionMethod []Verification CapabilityDelegation []Verification CapabilityInvocation []Verification KeyAgreement []Verification Created *time.Time Updated *time.Time Proof []Proof // contains filtered or unexported fields }
Doc DID Document definition.
func ParseDocument ¶
ParseDocument creates an instance of DIDDocument by reading a JSON document from bytes.
func (*Doc) MarshalJSON ¶
MarshalJSON marshals the DID Document.
func (*Doc) SerializeInterop ¶
SerializeInterop serializes the DID doc, using normal serialization unless the `interop` build flag is set.
func (*Doc) ToLegacyRawDoc ¶
ToLegacyRawDoc converts document to raw doc.
func (*Doc) UnmarshalJSON ¶
UnmarshalJSON unmarshals a DID Document.
func (*Doc) VerificationMethods ¶
func (doc *Doc) VerificationMethods(customVerificationRelationships ...VerificationRelationship) map[VerificationRelationship][]Verification
VerificationMethods returns verification methods of DID Doc of certain relationship. If customVerificationRelationships is empty, all verification methods are returned. Public keys which are not referred by any verification method are put into special VerificationRelationshipGeneral relationship category. nolint:gocyclo
func (*Doc) VerifyProof ¶
func (doc *Doc) VerifyProof(suites []verifier.SignatureSuite, jsonldOpts ...jsonld.ProcessorOpts) error
VerifyProof verifies document proofs.
type DocOption ¶
type DocOption func(opts *Doc)
DocOption provides options to build DID Doc.
func WithAssertion ¶
func WithAssertion(assertion []Verification) DocOption
WithAssertion sets the verification methods for assertion: https://w3c.github.io/did-core/#assertion.
func WithAuthentication ¶
func WithAuthentication(auth []Verification) DocOption
WithAuthentication sets the verification methods for authentication: https://w3c.github.io/did-core/#authentication.
func WithCreatedTime ¶
WithCreatedTime DID doc created time.
func WithKeyAgreement ¶
func WithKeyAgreement(keyAgreement []Verification) DocOption
WithKeyAgreement sets the verification methods for KeyAgreement: https://w3c.github.io/did-core/#key-agreement.
func WithUpdatedTime ¶
WithUpdatedTime DID doc updated time.
func WithVerificationMethod ¶
func WithVerificationMethod(pubKey []VerificationMethod) DocOption
WithVerificationMethod DID doc VerificationMethod.
type DocResolution ¶
type DocResolution struct { Context Context DIDDocument *Doc DocumentMetadata *DocumentMetadata }
DocResolution did resolution.
func ParseDocumentResolution ¶
func ParseDocumentResolution(data []byte) (*DocResolution, error)
ParseDocumentResolution parse document resolution.
func (*DocResolution) JSONBytes ¶
func (docResolution *DocResolution) JSONBytes() ([]byte, error)
JSONBytes converts document to json bytes.
type DocumentMetadata ¶
type DocumentMetadata struct { // VersionID is version ID key. VersionID string `json:"versionId,omitempty"` // Deactivated is deactivated flag key. Deactivated bool `json:"deactivated,omitempty"` // CanonicalID is canonical ID key. CanonicalID string `json:"canonicalId,omitempty"` // EquivalentID is equivalent ID array. EquivalentID []string `json:"equivalentId,omitempty"` // Method is used for method metadata within did document metadata. Method *MethodMetadata `json:"method,omitempty"` }
DocumentMetadata document metadata.
type MethodMetadata ¶
type MethodMetadata struct { // UpdateCommitment is update commitment key. UpdateCommitment string `json:"updateCommitment,omitempty"` // RecoveryCommitment is recovery commitment key. RecoveryCommitment string `json:"recoveryCommitment,omitempty"` // Published is published key. Published bool `json:"published,omitempty"` // AnchorOrigin is anchor origin. AnchorOrigin string `json:"anchorOrigin,omitempty"` // UnpublishedOperations unpublished operations UnpublishedOperations []*ProtocolOperation `json:"unpublishedOperations,omitempty"` // PublishedOperations published operations PublishedOperations []*ProtocolOperation `json:"publishedOperations,omitempty"` }
MethodMetadata method metadata.
type Proof ¶
type Proof struct { Type string Created *time.Time Creator string ProofValue []byte Domain string Nonce []byte ProofPurpose string // contains filtered or unexported fields }
Proof is cryptographic proof of the integrity of the DID Document.
type ProtocolOperation ¶
type ProtocolOperation struct { // Operation is operation request. Operation string `json:"operation,omitempty"` // ProtocolVersion is protocol version. ProtocolVersion int `json:"protocolVersion,omitempty"` // TransactionNumber is transaction number. TransactionNumber int `json:"transactionNumber,omitempty"` // TransactionTime is transaction time. TransactionTime int64 `json:"transactionTime,omitempty"` // Type is type of operation. Type string `json:"type,omitempty"` // AnchorOrigin is anchor origin. AnchorOrigin string `json:"anchorOrigin,omitempty"` // CanonicalReference is canonical reference CanonicalReference string `json:"canonicalReference,omitempty"` // EquivalentReferences is equivalent references EquivalentReferences []string `json:"equivalentReferences,omitempty"` }
ProtocolOperation info.
type Service ¶
type Service struct { ID string `json:"id"` Type interface{} `json:"type"` Priority interface{} `json:"priority,omitempty"` RecipientKeys []string `json:"recipientKeys,omitempty"` RoutingKeys []string `json:"routingKeys,omitempty"` ServiceEndpoint model.Endpoint `json:"serviceEndpoint"` Accept []string `json:"accept,omitempty"` Properties map[string]interface{} `json:"properties,omitempty"` // contains filtered or unexported fields }
Service DID doc service.
type Verification ¶
type Verification struct { VerificationMethod VerificationMethod Relationship VerificationRelationship Embedded bool }
Verification authentication verification.
func NewEmbeddedVerification ¶
func NewEmbeddedVerification(vm *VerificationMethod, r VerificationRelationship) *Verification
NewEmbeddedVerification creates a new verification method with embedded verification method.
func NewReferencedVerification ¶
func NewReferencedVerification(vm *VerificationMethod, r VerificationRelationship) *Verification
NewReferencedVerification creates a new verification method with referenced verification method.
type VerificationMethod ¶
type VerificationMethod struct { ID string Type string Controller string Value []byte // contains filtered or unexported fields }
VerificationMethod DID doc verification method. The value of the verification method is defined either as raw public key bytes (Value field) or as JSON Web Key. In the first case the Type field can hold additional information to understand the nature of the raw public key.
func LookupPublicKey ¶
func LookupPublicKey(id string, didDoc *Doc) (*VerificationMethod, bool)
LookupPublicKey returns the public key with the given id from the given DID Doc.
func NewVerificationMethodFromBytes ¶
func NewVerificationMethodFromBytes(id, keyType, controller string, value []byte) *VerificationMethod
NewVerificationMethodFromBytes creates a new VerificationMethod based on raw public key bytes.
func NewVerificationMethodFromBytesWithMultibase ¶
func NewVerificationMethodFromBytesWithMultibase(id, keyType, controller string, value []byte, encoding multibase.Encoding) *VerificationMethod
NewVerificationMethodFromBytesWithMultibase creates a new VerificationMethod based on raw public key bytes with multibase.
func NewVerificationMethodFromJWK ¶
func NewVerificationMethodFromJWK(id, keyType, controller string, j *jwk.JWK) (*VerificationMethod, error)
NewVerificationMethodFromJWK creates a new VerificationMethod based on JSON Web Key.
func (*VerificationMethod) JSONWebKey ¶
func (pk *VerificationMethod) JSONWebKey() *jwk.JWK
JSONWebKey returns JSON Web key if defined.
type VerificationRelationship ¶
type VerificationRelationship int
VerificationRelationship defines a verification relationship between DID subject and a verification method.
const ( // VerificationRelationshipGeneral is a special case of verification relationship: when a verification method // defined in Verification is not used by any Verification. VerificationRelationshipGeneral VerificationRelationship = iota // Authentication defines verification relationship. Authentication // AssertionMethod defines verification relationship. AssertionMethod // CapabilityDelegation defines verification relationship. CapabilityDelegation // CapabilityInvocation defines verification relationship. CapabilityInvocation // KeyAgreement defines verification relationship. KeyAgreement )