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

     1  /*
     2  Copyright SecureKey Technologies Inc. All Rights Reserved.
     3  SPDX-License-Identifier: Apache-2.0
     4  */
     5  
     6  package proof
     7  
     8  import (
     9  	"github.com/hyperledger/aries-framework-go/component/models/ld/processor"
    10  	ldproof "github.com/hyperledger/aries-framework-go/component/models/ld/proof"
    11  )
    12  
    13  // signatureSuite encapsulates signature suite methods required for normalizing document.
    14  type signatureSuite interface {
    15  
    16  	// GetCanonicalDocument will return normalized/canonical version of the document
    17  	GetCanonicalDocument(doc map[string]interface{}, opts ...processor.Opts) ([]byte, error)
    18  
    19  	// GetDigest returns document digest
    20  	GetDigest(doc []byte) []byte
    21  
    22  	// CompactProof indicates weather to compact the proof doc before canonization
    23  	CompactProof() bool
    24  }
    25  
    26  // SignatureRepresentation defines a representation of signature value.
    27  type SignatureRepresentation = ldproof.SignatureRepresentation
    28  
    29  const (
    30  	// SignatureProofValue uses "proofValue" field in a Proof to put/read a digital signature.
    31  	SignatureProofValue = ldproof.SignatureProofValue
    32  
    33  	// SignatureJWS uses "jws" field in a Proof as an element for representation of detached JSON Web Signatures.
    34  	SignatureJWS = ldproof.SignatureJWS
    35  )
    36  
    37  // Proof is cryptographic proof of the integrity of the DID Document.
    38  type Proof = ldproof.Proof
    39  
    40  // NewProof creates new proof.
    41  func NewProof(emap map[string]interface{}) (*Proof, error) {
    42  	return ldproof.NewProof(emap)
    43  }
    44  
    45  // DecodeProofValue decodes proofValue basing on proof type.
    46  func DecodeProofValue(s, proofType string) ([]byte, error) {
    47  	return ldproof.DecodeProofValue(s, proofType)
    48  }
    49  
    50  // EncodeProofValue decodes proofValue basing on proof type.
    51  func EncodeProofValue(proofValue []byte, proofType string) string {
    52  	return ldproof.EncodeProofValue(proofValue, proofType)
    53  }
    54  
    55  // CreateVerifyData creates data that is used to generate or verify a digital signature.
    56  // It depends on the signature value holder type.
    57  // In case of "proofValue", the standard Create Verify Hash algorithm is used.
    58  // In case of "jws", verify data is built as JSON Web Signature (JWS) with detached payload.
    59  func CreateVerifyData(suite signatureSuite, jsonldDoc map[string]interface{}, proof *Proof,
    60  	opts ...processor.Opts) ([]byte, error) {
    61  	return ldproof.CreateVerifyData(suite, jsonldDoc, proof, opts...)
    62  }
    63  
    64  // CreateVerifyHash returns data that is used to generate or verify a digital signature
    65  // Algorithm steps are described here https://w3c-dvcg.github.io/ld-signatures/#create-verify-hash-algorithm
    66  func CreateVerifyHash(suite signatureSuite, jsonldDoc, proofOptions map[string]interface{},
    67  	opts ...processor.Opts) ([]byte, error) {
    68  	return ldproof.CreateVerifyHash(suite, jsonldDoc, proofOptions, opts...)
    69  }
    70  
    71  // CreateDetachedJWTHeader creates detached JWT header.
    72  func CreateDetachedJWTHeader(alg string) string {
    73  	return ldproof.CreateDetachedJWTHeader(alg)
    74  }
    75  
    76  // GetJWTSignature returns signature part of JWT.
    77  func GetJWTSignature(jwt string) ([]byte, error) {
    78  	return ldproof.GetJWTSignature(jwt)
    79  }
    80  
    81  // GetProofs gets proof(s) from LD Object.
    82  func GetProofs(jsonLdObject map[string]interface{}) ([]*Proof, error) {
    83  	return ldproof.GetProofs(jsonLdObject)
    84  }
    85  
    86  // AddProof adds a proof to LD Object.
    87  func AddProof(jsonLdObject map[string]interface{}, proof *Proof) error {
    88  	return ldproof.AddProof(jsonLdObject, proof)
    89  }
    90  
    91  // GetCopyWithoutProof gets copy of JSON LD Object without proofs (signatures).
    92  func GetCopyWithoutProof(jsonLdObject map[string]interface{}) map[string]interface{} {
    93  	return ldproof.GetCopyWithoutProof(jsonLdObject)
    94  }
    95  
    96  // ErrProofNotFound is returned when proof is not found.
    97  var ErrProofNotFound = ldproof.ErrProofNotFound