-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
56 lines (51 loc) · 4.53 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=, initial-scale=1.0" />
<title>Document</title>
<script type="importmap">
{
"imports": {
"@iden3/js-crypto": "./node_modules/@iden3/js-crypto/dist/browser/esm/index.js",
"@iden3/js-iden3-core": "./node_modules/@iden3/js-iden3-core/dist/browser/esm/index.js",
"@iden3/js-merkletree": "./node_modules/@iden3/js-merkletree/dist/browser/esm/index.js",
"snarkjs": "./node_modules/snarkjs/build/browser.esm.js",
"ffjavascript": "./node_modules/ffjavascript/build/browser.esm.js"
}
}
</script>
<script src="./dist/browser/umd/index.js"></script>
</head>
<body>
<script type="module">
const esm = await import('./dist/browser/esm/index.js');
await testParseAndVerid(esm);
await testParseAndVerid(JWZ);
async function testParseAndVerid(module) {
const { Token, base64 } = module;
const verificationKey = await fetch('./test/data/authV2/verification_key.json').then(
(res) => res.arrayBuffer()
);
const token = await Token.parse(
`eyJhbGciOiJncm90aDE2IiwiY2lyY3VpdElkIjoiYXV0aFYyIiwiY3JpdCI6WyJjaXJjdWl0SWQiXSwidHlwIjoiSldaIn0.bXltZXNzYWdl.eyJwcm9vZiI6eyJwaV9hIjpbIjU4OTA4MTc2NDc0NDY4MzQ2MDU3NjU3NzA0NTExMDIyMDg4NjMyMDkxNDgwMTE5NDgzNjA0MDQ3NDU0ODA2NzE1NDM2MjU5MTkwNDIiLCI2OTY1MzI0OTI3MDYzMDQxOTU2NTIwODg5ODU1MDcxNjU1OTg5Mzg4NzQyODM1ODgzOTI1NjU4MDI1NDE0MjM4OTQ2OTkxNjE1ODMwIiwiMSJdLCJwaV9iIjpbWyIxNjgwMjkyNTc5OTM3NjI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CI6Imdyb3RoMTYiLCJjdXJ2ZSI6ImJuMTI4In0sInB1Yl9zaWduYWxzIjpbIjIzMTQ4OTM2NDY2MzM0MzUwNzQ0NTQ4NzkwMDEyMjk0NDg5MzY1MjA3NDQwNzU0NTA5OTg4OTg2Njg0Nzk3NzA4MzcwMDUxMDczIiwiNjExMDUxNzc2ODI0OTU1OTIzODE5MzQ3NzQzNTQ1NDc5MjAyNDczMjE3Mzg2NTQ4ODkwMDI3MDg0OTYyNDMyODY1MDc2NTY5MTQ5NCIsIjEyNDM5MDQ3MTE0Mjk5NjE4NTg3NzQyMjA2NDc2MTA3MjQyNzM3OTg5MTg0NTc5OTE0ODYwMzE1NjcyNDQxMDA3NjcyNTkyMzk3NDciXX0'
)
);
const zkProof = JSON.parse(new TextDecoder().decode(proofByte));
console.assert(
JSON.stringify(zkProof.pub_signals) === JSON.stringify(token.zkProof.pub_signals)
);
console.assert(JSON.stringify(zkProof.proof) === JSON.stringify(token.zkProof.proof));
console.assert('authV2' === token.circuitId);
console.assert('groth16' === token.alg);
console.log('JWZ test passed');
}
</script>
</body>
</html>