-
Notifications
You must be signed in to change notification settings - Fork 0
/
index-completed.js
49 lines (38 loc) · 1.58 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
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 attendee;
//STEP 1: Check if user already has a DID, if not create a new DID and store it in a file.
const existingDID = await loadDID(filename);
if(!existingDID) {
// creates a DID using the DHT method and publishes the DID document to the DHT
attendee = await DidDht.create();
console.log("DID:", attendee.uri);
console.log("DID Document:", attendee.document);
console.log("DIDDht:", attendee);
await storeDID(filename, attendee);
} else {
attendee = await DidDht.import({ portableDid: existingDID });
console.log('attendee', attendee);
}
// STEP 2: Create a verifiable credential
const vc = await VerifiableCredential.create({
type: 'WorkshopAttendeeCredential',
issuer: attendee.uri,
subject: attendee.uri,
expirationDate: '2024-12-31T23:59:59Z',
data: {
"name": "Jane Doe",
"location": "Amsterdam",
"conference": "JSWorld 2024",
"eventDate": "2024-03-01T00:00:00Z",
"issuerName": "Jane Doe",
}
});
console.log("VC:", vc);
// STEP 3: Sign VC and get JWT.
const vc_jwt_attendee = await vc.sign({ did: attendee });
console.log("VC JWT:", vc_jwt_attendee);