forked from hyperledger-archives/aries-framework-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpresentation_ldp_test.go
98 lines (75 loc) · 2.75 KB
/
presentation_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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package verifiable
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/require"
"github.com/hyperledger/aries-framework-go/pkg/doc/signature/jsonld"
"github.com/hyperledger/aries-framework-go/pkg/doc/signature/suite"
"github.com/hyperledger/aries-framework-go/pkg/doc/signature/suite/ed25519signature2018"
"github.com/hyperledger/aries-framework-go/pkg/kms"
)
func TestParsePresentationFromLinkedDataProof(t *testing.T) {
r := require.New(t)
signer, err := newCryptoSigner(kms.ED25519Type)
r.NoError(err)
ss := ed25519signature2018.New(suite.WithSigner(signer),
suite.WithVerifier(ed25519signature2018.NewPublicKeyVerifier())) // todo use crypto verifier
ldpContext := &LinkedDataProofContext{
SignatureType: "Ed25519Signature2018",
SignatureRepresentation: SignatureJWS,
Suite: ss,
VerificationMethod: "did:example:123456#key1",
}
vc, err := newTestPresentation(t, []byte(validPresentation))
r.NoError(err)
err = vc.AddLinkedDataProof(ldpContext, jsonld.WithDocumentLoader(createTestDocumentLoader(t)))
r.NoError(err)
vcBytes, err := json.Marshal(vc)
r.NoError(err)
vcWithLdp, err := newTestPresentation(t, vcBytes,
WithPresEmbeddedSignatureSuites(ss),
WithPresPublicKeyFetcher(SingleKey(signer.PublicKeyBytes(), kms.ED25519)))
r.NoError(err)
r.NoError(err)
r.Equal(vc, vcWithLdp)
// signature suite is not passed, cannot make a proof check
vcWithLdp, err = newTestPresentation(t, vcBytes)
r.Error(err)
require.Nil(t, vcWithLdp)
}
func TestPresentation_AddLinkedDataProof(t *testing.T) {
r := require.New(t)
signer, err := newCryptoSigner(kms.ED25519Type)
r.NoError(err)
ldpContext := &LinkedDataProofContext{
SignatureType: "Ed25519Signature2018",
SignatureRepresentation: SignatureProofValue,
Suite: ed25519signature2018.New(suite.WithSigner(signer)),
}
t.Run("Add a valid Linked Data proof to VC", func(t *testing.T) {
vp, err := newTestPresentation(t, []byte(validPresentation))
r.NoError(err)
err = vp.AddLinkedDataProof(ldpContext, jsonld.WithDocumentLoader(createTestDocumentLoader(t)))
r.NoError(err)
err = vp.AddLinkedDataProof(ldpContext, jsonld.WithDocumentLoader(createTestDocumentLoader(t)))
r.NoError(err)
vpJSON, err := vp.MarshalJSON()
r.NoError(err)
vpMap, err := toMap(vpJSON)
r.NoError(err)
r.Contains(vpMap, "proof")
vpProof := vpMap["proof"]
vpProofs, ok := vpProof.([]interface{})
r.True(ok)
r.Len(vpProofs, 2)
newVPProof, ok := vpProofs[1].(map[string]interface{})
r.True(ok)
r.Contains(newVPProof, "created")
r.Contains(newVPProof, "proofValue")
r.Equal("Ed25519Signature2018", newVPProof["type"])
})
}