forked from TBD54566975/vc-workshop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex-completed.js
53 lines (42 loc) · 1.67 KB
/
index-completed.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
import { VerifiableCredential, PresentationExchange } from "@web5/credentials";
import { DidDht } from "@web5/dids";
import { loadDID, storeDID } from "./utils.js";
import pd from "./presentation-definition.json" assert { type: "json" };
// STEP 0: Set filepath to use or store DID
const filename = "./did.json";
let attendeeDid;
//STEP 1: Creates and stores new DID if one doesn't exist
const existingDID = await loadDID(filename);
if(!existingDID) {
// creates a DID
attendeeDid = await DidDht.create({
options:{ publish: true }
});
console.log("DID:", attendeeDid.uri);
console.log("DID Document:", attendeeDid.document);
console.log("DIDDht:", attendeeDid);
await storeDID(filename, attendeeDid);
} else {
attendeeDid = await DidDht.import({ portableDid: existingDID });
console.log('attendeeDid', attendeeDid);
}
// STEP 2: Create a verifiable credential
const vc = await VerifiableCredential.create({
type: 'WorkshopAttendeeCredential',
issuer: attendeeDid.uri,
subject: attendeeDid.uri,
expirationDate: '2024-12-31T23:59:59Z',
data: {
"name": "Jane Doe",
"location": "Amsterdam",
"conference": "DevWorld 2024",
"eventDate": "2024-03-01T00:00:00Z",
"issuerName": "Jane Doe",
}
});
console.log("VC:", vc);
// STEP 3: Sign VC and get JWT
const signedVC = await vc.sign({ did: attendeeDid });
console.log("Signed VC:", signedVC);
// TODO: STEP 4: Examine VC: https://jwt.io/
// TODO: STEP 5: Present VC: https://web5-vc.netlify.app/