forked from supranational/blst
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunnable.html
54 lines (43 loc) · 1.5 KB
/
runnable.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
<!DOCTYPE html>
<html>
<head><meta charset="UTF-8"><title>runnable.html</title></head>
<body>
<script type="text/javascript" src="blst.js"></script>
<div id="output"></div>
<script type="text/javascript">
var output = {
div: document.getElementById("output"),
log: function(str) {
this.div.appendChild(document.createTextNode(str));
this.div.appendChild(document.createElement("br"));
}
}
output.log("testing...");
blst['onRuntimeInitialized'] = function() {
var msg = "assertion"; // this what we're signing
var DST = "MY-DST"; // domain separation tag
var SK = new blst.SecretKey();
SK.keygen("*".repeat(32));
////////////////////////////////////////////////////////////////////////
// generate public key and signature
var pk = new blst.P1(SK);
var pk_for_wire = pk.serialize();
var sig = new blst.P2();
var sig_for_wire = sig.hash_to(msg, DST, pk_for_wire)
.sign_with(SK)
.serialize();
////////////////////////////////////////////////////////////////////////
// at this point 'pk_for_wire', 'sig_for_wire' and 'msg' are
// "sent over network," so now on "receiver" side
sig = new blst.P2_Affine(sig_for_wire);
pk = new blst.P1_Affine(pk_for_wire);
if (!pk.in_group()) throw "disaster"; // vet the public key
var ctx = new blst.Pairing(true, DST);
ctx.aggregate(pk, sig, msg, pk_for_wire);
ctx.commit();
if (!ctx.finalverify()) throw "disaster";
output.log("OK");
}
</script>
</body>
</html>