aboutsummaryrefslogtreecommitdiffstats
path: root/docs/demo/bls.js
diff options
context:
space:
mode:
Diffstat (limited to 'docs/demo/bls.js')
-rw-r--r--docs/demo/bls.js51
1 files changed, 34 insertions, 17 deletions
diff --git a/docs/demo/bls.js b/docs/demo/bls.js
index 9b2433c..20ea3a0 100644
--- a/docs/demo/bls.js
+++ b/docs/demo/bls.js
@@ -241,69 +241,86 @@ function define_bls_extra_functions(mod) {
blsPublicKeyRecover = wrap_recover(_blsPublicKeyRecover, BLS_PUBLICKEY_SIZE, BLS_ID_SIZE)
blsSignatureRecover = wrap_recover(_blsSignatureRecover, BLS_SIGNATURE_SIZE, BLS_ID_SIZE)
- var copyToUint32Array = function(a, pos) {
+ let crypto = window.crypto || window.msCrypto
+
+ let copyToUint32Array = function(a, pos) {
for (let i = 0; i < a.length; i++) {
a[i] = mod.HEAP32[pos / 4 + i]
}
}
- var callSetter1 = function(func, a, p1) {
+ let callSetter = function(func, a, p1, p2) {
let pos = mod._malloc(a.length * 4)
- mod.HEAP32.set(a, pos / 4)
- func(pos, p1)
+ func(pos, p1, p2) // p1, p2 may be undefined
copyToUint32Array(a, pos)
mod._free(pos)
}
- var callGetter0 = function(func, a) {
+ let callGetter = function(func, a, p1, p2) {
let pos = mod._malloc(a.length * 4)
mod.HEAP32.set(a, pos / 4)
- let s = func(pos)
+ let s = func(pos, p1, p2)
mod._free(pos)
return s
}
+ let callModifier = function(func, a, p1, p2) {
+ let pos = mod._malloc(a.length * 4)
+ mod.HEAP32.set(a, pos / 4)
+ func(pos, p1, p2) // p1, p2 may be undefined
+ copyToUint32Array(a, pos)
+ mod._free(pos)
+ }
/// BlsId
BlsId.prototype.setInt = function(x) {
- callSetter1(blsIdSetInt, this.a_, x)
+ callSetter(blsIdSetInt, this.a_, x)
}
BlsId.prototype.setStr = function(s, base = 10) {
switch (base) {
case 10:
- callSetter1(blsIdSetDecStr, this.a_, s)
+ callSetter(blsIdSetDecStr, this.a_, s)
return
case 16:
- callSetter1(blsIdSetHexStr, this.a_, s)
+ callSetter(blsIdSetHexStr, this.a_, s)
return
default:
throw('BlsId.setStr:bad base:' + base)
}
}
BlsId.prototype.deserialize = function(s) {
- callSetter1(blsIdDeserialize, this.a_, s)
+ callSetter(blsIdDeserialize, this.a_, s)
}
BlsId.prototype.getStr = function(base = 10) {
switch (base) {
case 10:
- return callGetter0(blsIdGetDecStr, this.a_)
+ return callGetter(blsIdGetDecStr, this.a_)
case 16:
- return callGetter0(blsIdGetHexStr, this.a_)
+ return callGetter(blsIdGetHexStr, this.a_)
default:
throw('BlsId.getStr:bad base:' + base)
}
}
BlsId.prototype.serialize = function() {
- return callGetter0(blsIdSerialize, this.a_)
+ return callGetter(blsIdSerialize, this.a_)
}
/// BlsSecretKey
BlsSecretKey.prototype.setInt = function(x) {
- callSetter1(blsIdSetInt, this.a_, x) // same as Id
+ callSetter(blsIdSetInt, this.a_, x) // same as Id
}
BlsSecretKey.prototype.deserialize = function(s) {
- callSetter1(blsSecretKeyDeserialize, this.a_, s)
+ callSetter(blsSecretKeyDeserialize, this.a_, s)
}
BlsSecretKey.prototype.setLittleEndian = function(s) {
- callSetter1(blsSecretKeySetLittleEndian, this.a_, s)
+ callSetter(blsSecretKeySetLittleEndian, this.a_, s)
}
BlsSecretKey.prototype.serialize = function() {
- return callGetter0(blsSecretKeySerialize, this.a_)
+ return callGetter(blsSecretKeySerialize, this.a_)
+ }
+ BlsSecretKey.prototype.setHashOf = function(s) {
+ callSetter(blsHashToSecretKey, this.a_, s)
+ }
+ BlsSecretKey.prototype.setByCSPRNG = function() {
+ let a = new Uint8Array(BLS_SECRETKEY_SIZE)
+ crypto.getRandomValues(a)
+ this.setLittleEndian(a)
+// callSetter(blsSecretKeySetByCSPRNG, this.a_)
}
}