-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
59 lines (47 loc) · 1.52 KB
/
index.js
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
const {
CredentialIssuer,
Connector,
TrackBackAgent,
CredentialVerifier,
} = require('@trackback/agent')
async function demo() {
const connector = new Connector()
const agent = new TrackBackAgent(connector)
const account = await connector.getDefaultAccount()
const context = {
agent,
account: account,
}
const issuer = await CredentialIssuer.build()
console.log(issuer)
const metada = { 'content-type': 'application/json' }
const resMetada = { 'content-type': 'application/json' }
const result = await issuer.save(context, metada, resMetada)
console.log(result)
const credential = {
'@context': ['https://www.w3.org/2018/credentials/v1'],
type: ['VerifiableCredential'],
issuanceDate: '2010-01-01T19:23:24Z',
credentialSubject: { name: 'Test', surname: 'Test Test' },
issuer: issuer.id,
}
console.log(credential)
const jwt = await issuer.createVerifiableCredentials(credential)
console.log(jwt)
// Issuer creates a verifiable credential presentation
const jwtPresentation = await issuer.createVerifiablePresentation(
[jwt],
issuer.keypair
)
console.log(jwtPresentation)
const accountB = await connector.getDefaultAccount('Bob')
const contextB = {
agent,
account: accountB,
}
const verifier = new CredentialVerifier()
console.log(verifier)
const r = await verifier.verifyPresentation(jwtPresentation, contextB)
console.log(r)
}
demo()