github.com/hyperledger/aries-framework-go@v0.3.2/pkg/doc/did/did.go (about)

     1  /*
     2  Copyright SecureKey Technologies Inc. All Rights Reserved.
     3  SPDX-License-Identifier: Apache-2.0
     4  */
     5  
     6  package did
     7  
     8  import (
     9  	"time"
    10  
    11  	"github.com/multiformats/go-multibase"
    12  
    13  	"github.com/hyperledger/aries-framework-go/component/kmscrypto/doc/jose/jwk"
    14  	didmodel "github.com/hyperledger/aries-framework-go/component/models/did"
    15  )
    16  
    17  const (
    18  	// ContextV1 of the DID document is the current V1 context name.
    19  	ContextV1 = didmodel.ContextV1
    20  	// ContextV1Old of the DID document representing the old/legacy V1 context name.
    21  	ContextV1Old = didmodel.ContextV1Old
    22  )
    23  
    24  // ErrDIDDocumentNotExist error did doc not exist.
    25  var ErrDIDDocumentNotExist = didmodel.ErrDIDDocumentNotExist
    26  
    27  // DID is parsed according to the generic syntax: https://w3c.github.io/did-core/#generic-did-syntax
    28  type DID = didmodel.DID
    29  
    30  // Parse parses the string according to the generic DID syntax.
    31  // See https://w3c.github.io/did-core/#generic-did-syntax.
    32  func Parse(did string) (*DID, error) {
    33  	return didmodel.Parse(did)
    34  }
    35  
    36  // DIDURL holds a DID URL.
    37  type DIDURL = didmodel.DIDURL // nolint:golint
    38  
    39  // ParseDIDURL parses a DID URL string into a DIDURL object.
    40  func ParseDIDURL(didURL string) (*DIDURL, error) {
    41  	return didmodel.ParseDIDURL(didURL)
    42  }
    43  
    44  // Context represents JSON-LD representation-specific DID-core @context, which
    45  // must be either a string, or a list containing maps and/or strings.
    46  type Context = didmodel.Context
    47  
    48  // DocResolution did resolution.
    49  type DocResolution = didmodel.DocResolution
    50  
    51  // MethodMetadata method metadata.
    52  type MethodMetadata = didmodel.MethodMetadata
    53  
    54  // ProtocolOperation info.
    55  type ProtocolOperation = didmodel.ProtocolOperation
    56  
    57  // DocumentMetadata document metadata.
    58  type DocumentMetadata = didmodel.DocumentMetadata
    59  
    60  // ParseDocumentResolution parse document resolution.
    61  func ParseDocumentResolution(data []byte) (*DocResolution, error) {
    62  	return didmodel.ParseDocumentResolution(data)
    63  }
    64  
    65  // Doc DID Document definition.
    66  type Doc = didmodel.Doc
    67  
    68  // VerificationMethod DID doc verification method.
    69  // The value of the verification method is defined either as raw public key bytes (Value field) or as JSON Web Key.
    70  // In the first case the Type field can hold additional information to understand the nature of the raw public key.
    71  type VerificationMethod = didmodel.VerificationMethod
    72  
    73  // NewVerificationMethodFromBytesWithMultibase creates a new VerificationMethod based on
    74  // raw public key bytes with multibase.
    75  func NewVerificationMethodFromBytesWithMultibase(id, keyType, controller string, value []byte,
    76  	encoding multibase.Encoding) *VerificationMethod {
    77  	return didmodel.NewVerificationMethodFromBytesWithMultibase(id, keyType, controller, value, encoding)
    78  }
    79  
    80  // NewVerificationMethodFromBytes creates a new VerificationMethod based on raw public key bytes.
    81  func NewVerificationMethodFromBytes(id, keyType, controller string, value []byte) *VerificationMethod {
    82  	return didmodel.NewVerificationMethodFromBytes(id, keyType, controller, value)
    83  }
    84  
    85  // NewVerificationMethodFromJWK creates a new VerificationMethod based on JSON Web Key.
    86  func NewVerificationMethodFromJWK(id, keyType, controller string, j *jwk.JWK) (*VerificationMethod, error) {
    87  	return didmodel.NewVerificationMethodFromJWK(id, keyType, controller, j)
    88  }
    89  
    90  // Service DID doc service.
    91  type Service = didmodel.Service
    92  
    93  // VerificationRelationship defines a verification relationship between DID subject and a verification method.
    94  type VerificationRelationship = didmodel.VerificationRelationship
    95  
    96  const (
    97  	// VerificationRelationshipGeneral is a special case of verification relationship: when a verification method
    98  	// defined in Verification is not used by any Verification.
    99  	VerificationRelationshipGeneral = didmodel.VerificationRelationshipGeneral
   100  
   101  	// Authentication defines verification relationship.
   102  	Authentication = didmodel.Authentication
   103  
   104  	// AssertionMethod defines verification relationship.
   105  	AssertionMethod = didmodel.AssertionMethod
   106  
   107  	// CapabilityDelegation defines verification relationship.
   108  	CapabilityDelegation = didmodel.CapabilityDelegation
   109  
   110  	// CapabilityInvocation defines verification relationship.
   111  	CapabilityInvocation = didmodel.CapabilityInvocation
   112  
   113  	// KeyAgreement defines verification relationship.
   114  	KeyAgreement = didmodel.KeyAgreement
   115  )
   116  
   117  // Verification authentication verification.
   118  type Verification = didmodel.Verification
   119  
   120  // NewEmbeddedVerification creates a new verification method with embedded verification method.
   121  func NewEmbeddedVerification(vm *VerificationMethod, r VerificationRelationship) *Verification {
   122  	return didmodel.NewEmbeddedVerification(vm, r)
   123  }
   124  
   125  // NewReferencedVerification creates a new verification method with referenced verification method.
   126  func NewReferencedVerification(vm *VerificationMethod, r VerificationRelationship) *Verification {
   127  	return didmodel.NewReferencedVerification(vm, r)
   128  }
   129  
   130  // Proof is cryptographic proof of the integrity of the DID Document.
   131  type Proof = didmodel.Proof
   132  
   133  // ParseDocument creates an instance of DIDDocument by reading a JSON document from bytes.
   134  func ParseDocument(data []byte) (*Doc, error) { // nolint:funlen,gocyclo
   135  	return didmodel.ParseDocument(data)
   136  }
   137  
   138  // ErrProofNotFound is returned when proof is not found.
   139  var ErrProofNotFound = didmodel.ErrProofNotFound
   140  
   141  // ErrKeyNotFound is returned when key is not found.
   142  var ErrKeyNotFound = didmodel.ErrKeyNotFound
   143  
   144  // DocOption provides options to build DID Doc.
   145  type DocOption = didmodel.DocOption
   146  
   147  // WithVerificationMethod DID doc VerificationMethod.
   148  func WithVerificationMethod(pubKey []VerificationMethod) DocOption {
   149  	return didmodel.WithVerificationMethod(pubKey)
   150  }
   151  
   152  // WithAuthentication sets the verification methods for authentication: https://w3c.github.io/did-core/#authentication.
   153  func WithAuthentication(auth []Verification) DocOption {
   154  	return didmodel.WithAuthentication(auth)
   155  }
   156  
   157  // WithAssertion sets the verification methods for assertion: https://w3c.github.io/did-core/#assertion.
   158  func WithAssertion(assertion []Verification) DocOption {
   159  	return didmodel.WithAssertion(assertion)
   160  }
   161  
   162  // WithKeyAgreement sets the verification methods for KeyAgreement: https://w3c.github.io/did-core/#key-agreement.
   163  func WithKeyAgreement(keyAgreement []Verification) DocOption {
   164  	return didmodel.WithKeyAgreement(keyAgreement)
   165  }
   166  
   167  // WithService DID doc services.
   168  func WithService(svc []Service) DocOption {
   169  	return didmodel.WithService(svc)
   170  }
   171  
   172  // WithCreatedTime DID doc created time.
   173  func WithCreatedTime(t time.Time) DocOption {
   174  	return didmodel.WithCreatedTime(t)
   175  }
   176  
   177  // WithUpdatedTime DID doc updated time.
   178  func WithUpdatedTime(t time.Time) DocOption {
   179  	return didmodel.WithUpdatedTime(t)
   180  }
   181  
   182  // BuildDoc creates the DID Doc from options.
   183  func BuildDoc(opts ...DocOption) *Doc {
   184  	return didmodel.BuildDoc(opts...)
   185  }
   186  
   187  // LookupService returns the service from the given DIDDoc matching the given service type.
   188  func LookupService(didDoc *Doc, serviceType string) (*Service, bool) {
   189  	return didmodel.LookupService(didDoc, serviceType)
   190  }
   191  
   192  // LookupDIDCommRecipientKeys gets the DIDComm recipient keys from the did doc which match the given parameters.
   193  // DIDComm recipient keys are encoded as did:key identifiers.
   194  // See:
   195  // - https://github.com/hyperledger/aries-rfcs/blob/master/features/0067-didcomm-diddoc-conventions/README.md
   196  // - https://github.com/hyperledger/aries-rfcs/blob/master/features/0360-use-did-key/README.md
   197  func LookupDIDCommRecipientKeys(didDoc *Doc) ([]string, bool) {
   198  	return didmodel.LookupDIDCommRecipientKeys(didDoc)
   199  }
   200  
   201  // LookupPublicKey returns the public key with the given id from the given DID Doc.
   202  func LookupPublicKey(id string, didDoc *Doc) (*VerificationMethod, bool) {
   203  	return didmodel.LookupPublicKey(id, didDoc)
   204  }