forked from hyperledger-archives/aries-framework-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
suite.go
57 lines (45 loc) · 1.91 KB
/
suite.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
// Package ecdsasecp256k1signature2019 implements the EcdsaSecp256k1Signature2019 signature suite
// for the Linked Data Signatures specification (https://w3c-dvcg.github.io/lds-ecdsa-secp256k1-2019/).
// It uses the RDF Dataset Normalization Algorithm to transform the input document into its canonical form.
// It uses SHA-256 [RFC6234] as the message digest algorithm.
// Supported signature algorithms depend on the signer/verifier provided as options to the New().
package ecdsasecp256k1signature2019
import (
"crypto/sha256"
"github.com/Universal-Health-Chain/aries-framework-go/pkg/doc/signature/jsonld"
"github.com/Universal-Health-Chain/aries-framework-go/pkg/doc/signature/suite"
)
// Suite implements EcdsaSecp256k1Signature2019 signature suite.
type Suite struct {
suite.SignatureSuite
jsonldProcessor *jsonld.Processor
}
const (
signatureType = "EcdsaSecp256k1Signature2019"
jwkType = "EcdsaSecp256k1VerificationKey2019"
rdfDataSetAlg = "URDNA2015"
)
// New an instance of Linked Data Signatures for JWS suite.
func New(opts ...suite.Opt) *Suite {
s := &Suite{jsonldProcessor: jsonld.NewProcessor(rdfDataSetAlg)}
suite.InitSuiteOptions(&s.SignatureSuite, opts...)
return s
}
// GetCanonicalDocument will return normalized/canonical version of the document.
// EcdsaSecp256k1Signature2019 signature suite uses RDF Dataset Normalization as canonicalization algorithm.
func (s *Suite) GetCanonicalDocument(doc map[string]interface{}, opts ...jsonld.ProcessorOpts) ([]byte, error) {
return s.jsonldProcessor.GetCanonicalDocument(doc, opts...)
}
// GetDigest returns document digest.
func (s *Suite) GetDigest(doc []byte) []byte {
digest := sha256.Sum256(doc)
return digest[:]
}
// Accept will accept only EcdsaSecp256k1Signature2019 signature type.
func (s *Suite) Accept(t string) bool {
return t == signatureType
}