forked from iden3/js-crypto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
49 lines (36 loc) · 1.33 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
<!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>
</head>
<body>
Test browser
</body>
<script>
// Function to convert hex to base64
function base64FromHex(hex) {
hex = hex.replace(/^0x/, '');
hex = hex.length % 2 != 0 ? '0' + hex : hex;
const buffer = new Uint8Array(hex.match(/.{1,2}/g).map((byte) => parseInt(byte, 16)));
return btoa(String.fromCharCode(...buffer));
}
const { poseidon, PrivateKey, Signature, utils, ffUtils, Hex } = IdenJsCrypto;
const msgBuf = Hex.decodeString('000102030405060708090000');
const msg = ffUtils.leBuff2int(msgBuf);
const skBuff = Hex.decodeString('0001020304050607080900010203040506070809000102030405060708090001');
const privateKey = new PrivateKey(skBuff);
const pubKey = privateKey.public();
const pPubKey = pubKey.compress();
console.log(pPubKey);
const signature = privateKey.signPoseidon(msg);
const pSignature = signature.compress();
const uSignature = Signature.newFromCompressed(pSignature);
console.assert(pubKey.verifyPoseidon(msg, uSignature));
</script>
</html>