-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathdid_ldp_test.go
77 lines (60 loc) · 1.9 KB
/
did_ldp_test.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package verifiable
import (
_ "embed"
"testing"
"github.com/stretchr/testify/require"
"github.com/trustbloc/did-go/doc/did"
jsonldsig "github.com/trustbloc/did-go/doc/ld/processor"
"github.com/trustbloc/kms-go/spi/kms"
"github.com/trustbloc/vc-go/proof/testsupport"
)
//go:embed testdata/valid_doc.jsonld
var validDoc []byte //nolint:gochecknoglobals
func Test_AddDIDLinkedDataProof_VerifyDIDProof(t *testing.T) {
r := require.New(t)
didDoc, err := did.ParseDocument(validDoc)
r.NoError(err)
proofCreator, proofChecker := testsupport.NewKMSSigVerPair(t, kms.ED25519Type,
"did:example:76e12ec712ebc6f1c221ebfeb1f#key1")
ldpContext := &LinkedDataProofContext{
SignatureType: "Ed25519Signature2018",
KeyType: kms.ED25519Type,
SignatureRepresentation: SignatureProofValue,
ProofCreator: proofCreator,
VerificationMethod: "did:example:76e12ec712ebc6f1c221ebfeb1f#key1",
}
dl := createTestDocumentLoader(t)
t.Run("Success LDP", func(t *testing.T) {
signedDoc, err := AddDIDLinkedDataProof(
didDoc, ldpContext, jsonldsig.WithDocumentLoader(dl))
r.NoError(err)
err = VerifyDIDProof(
signedDoc,
WithDIDProofChecker(proofChecker),
WithDIDJSONLDDocumentLoader(dl),
)
r.NoError(err)
r.Len(signedDoc.Proof, 1)
r.Empty(signedDoc.Proof[0].JWS)
r.NotEmpty(signedDoc.Proof[0].ProofValue)
})
t.Run("Success JWK", func(t *testing.T) {
ldpContext.SignatureRepresentation = SignatureJWS
signedDoc, err := AddDIDLinkedDataProof(
didDoc, ldpContext, jsonldsig.WithDocumentLoader(dl))
r.NoError(err)
err = VerifyDIDProof(
signedDoc,
WithDIDProofChecker(proofChecker),
WithDIDJSONLDDocumentLoader(dl),
)
r.NoError(err)
r.Len(signedDoc.Proof, 1)
r.NotEmpty(signedDoc.Proof[0].JWS)
r.Empty(signedDoc.Proof[0].ProofValue)
})
}