-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
95 lines (85 loc) · 3.06 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="./dist/browser/umd/index.js"></script>
<title>Test</title>
<script type="importmap">
{
"imports": {
"@iden3/js-crypto": "../node_modules/@iden3/js-crypto/dist/browser/esm/index.js",
"@iden3/js-merkletree": "../node_modules/@iden3/js-merkletree/dist/browser/esm/index.js"
}
}
</script>
</head>
<body>
Test browser
</body>
<script type="module">
const multigraphDoc = `{
"@context":[
"https://www.w3.org/2018/credentials/v1",
"https://raw.githubusercontent.com/iden3/claim-schema-vocab/main/schemas/json-ld/kyc-v3.json-ld"
],
"@type":"VerifiablePresentation",
"holder": ["http://example.com/holder1", "http://example.com/holder2"],
"verifiableCredential": {
"@id": "http://example.com/vc2",
"@type":"KYCAgeCredential",
"birthday":19960425
}
}`;
const ipfsDocument = `{
"@context": [
"https://www.w3.org/2018/credentials/v1",
"ipfs://QmdP4MZkESEabRVB322r2xWm7TCi7LueMNWMJawYmSy7hp",
"ipfs://Qmbp4kwoHULnmK71abrxdksjPH5sAjxSAXU5PEp2XRMFNw/dir2/bbs-v2.jsonld"
],
"id": "https://issuer.oidp.uscis.gov/credentials/83627465",
"type": ["VerifiableCredential", "PermanentResidentCard"],
"issuer": "did:example:489398593",
"identifier": 83627465,
"name": "Permanent Resident Card",
"description": "Government of Example Permanent Resident Card.",
"issuanceDate": "2019-12-03T12:19:52Z",
"expirationDate": "2029-12-03T12:19:52Z",
"credentialSubject": {
"id": "did:example:b34ca6cd37bbf23",
"type": ["PermanentResident", "Person"],
"givenName": "JOHN",
"familyName": "SMITH",
"gender": "Male",
"image": "data:image/png;base64,iVBORw0KGgokJggg==",
"residentSince": "2015-01-01",
"lprCategory": "C09",
"lprNumber": "999-999-999",
"commuterClassification": "C1",
"birthCountry": "Bahamas",
"birthDate": "1958-07-17"
}
}`;
import * as esMerklizer from './dist/browser/esm/index.js';
const run = async (module) => {
const { Merklizer, Path } = module;
const mz = await Merklizer.merklizeJSONLD(multigraphDoc);
const path = await Path.fromDocument(null, multigraphDoc, 'verifiableCredential.birthday');
const val = await mz.rawValue(path);
console.assert(val === 19960425);
};
const runIPFS = async (module) => {
const { Merklizer, Path } = module;
const opts = { ipfsGatewayURL: 'http://ipfs.io' };
const mz = await Merklizer.merklizeJSONLD(ipfsDocument, opts);
const path = await Path.fromDocument(null, ipfsDocument, 'credentialSubject.givenName', opts);
const val = await mz.rawValue(path);
console.assert(val === 'JOHN');
};
runIPFS(Iden3Merklizer).catch(console.error);
runIPFS(esMerklizer).catch(console.error);
run(Iden3Merklizer).catch(console.error);
run(esMerklizer).catch(console.error);
</script>
</html>