-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
68 lines (59 loc) · 1.46 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
60
61
62
63
64
65
66
67
68
import { Web5 } from '@web5/api';
import { VerifiableCredential } from '@web5/credentials';
/**
* The connect() function creates an instance of Web5 and
* also creates a decentralized identifier or obtains connection to an existing one.
*/
const { web5, did: aliceDid } = await Web5.connect();
// console.log(aliceDid);
/**
* Access Bearer DID
*/
const { did: aliceBearerDid } = await web5.agent.identity.get({
didUri: aliceDid,
});
// console.log(aliceBearerDid);
/**
* Creating a verifiable credential (VC)
*/
const type = 'Web5QuickstartCompletionCredential';
const web5QuickStartCredentialData = {
name: 'Alice smith',
completionDate: new Date().getTime(),
expertiseLevel: 'Beginner',
};
const vc = await VerifiableCredential.create({
type,
issuer: aliceDid,
subject: aliceDid,
data: web5QuickStartCredentialData,
});
// console.log(vc);
/**
* Sign VC
*/
const signedVC = await vc.sign({ did: aliceBearerDid });
// console.log(signedVC);
/**
* store vc in DWN (Decentralised Web Nodes)
*/
const request = {
data: signedVC,
message: {
schema: type,
dataFormat: 'application/vc+jwt',
published: true,
},
};
const { record } = await web5.dwn.records.create(request);
// console.log('write result: ', record);
/**
* Read vc from dwn
*/
const vcJwt = await record.data.text();
// console.log(vcJwt);
/**
* Parsing/decoding application/vc+jwt data
*/
const parsedVcJwt = VerifiableCredential.parseJwt({ vcJwt });
console.log(parsedVcJwt);