aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMITSUNARI Shigeo <herumi@nifty.com>2017-10-10 04:59:39 +0800
committerMITSUNARI Shigeo <herumi@nifty.com>2017-10-10 04:59:39 +0800
commitb0328ca6ad728dceb37f3244d1301899fba2ac0b (patch)
tree46a05c502bb167b6c895da041a348aa310447049
parent44b36a63763fc96c6fe5d6d5f10b4ecac24826b0 (diff)
downloaddexon-bls-b0328ca6ad728dceb37f3244d1301899fba2ac0b.tar
dexon-bls-b0328ca6ad728dceb37f3244d1301899fba2ac0b.tar.gz
dexon-bls-b0328ca6ad728dceb37f3244d1301899fba2ac0b.tar.bz2
dexon-bls-b0328ca6ad728dceb37f3244d1301899fba2ac0b.tar.lz
dexon-bls-b0328ca6ad728dceb37f3244d1301899fba2ac0b.tar.xz
dexon-bls-b0328ca6ad728dceb37f3244d1301899fba2ac0b.tar.zst
dexon-bls-b0328ca6ad728dceb37f3244d1301899fba2ac0b.zip
[js] change BlsId.setStr/getStr
-rw-r--r--docs/demo/bls-demo.js6
-rw-r--r--docs/demo/bls.html4
-rw-r--r--docs/demo/bls.js48
3 files changed, 35 insertions, 23 deletions
diff --git a/docs/demo/bls-demo.js b/docs/demo/bls-demo.js
index a00228d..c748fde 100644
--- a/docs/demo/bls-demo.js
+++ b/docs/demo/bls-demo.js
@@ -356,7 +356,7 @@ function onClickTestMisc()
let idDec = getValue('idDec')
console.log('idDec=' + idDec)
var id = new BlsId()
- id.setDecStr(idDec)
- setText('idHex', id.getHexStr())
- setText('idDec2', id.getDecStr())
+ id.setStr(idDec)
+ setText('idDec2', id.getStr())
+ setText('idHex', id.getStr(16))
}
diff --git a/docs/demo/bls.html b/docs/demo/bls.html
index fb36e6b..a539729 100644
--- a/docs/demo/bls.html
+++ b/docs/demo/bls.html
@@ -82,10 +82,10 @@ e(aP, bQ) == e(P, Q)^ab is <span name="verify_pairing"></span>
<hr>
<button type="text" id="testMisc" onclick="onClickTestMisc()">test misc</button>
<div>
-id(dec) = <input type="text" name="idDec" value="3"><br>
+id(dec) = <input type="text" name="idDec" value="256"><br>
</div>
-id(hex) = <span name="idHex"></span><br>
id(dec) again = <span name="idDec2"></span><br>
+id(hex) = <span name="idHex"></span><br>
<div>
</div>
</body>
diff --git a/docs/demo/bls.js b/docs/demo/bls.js
index 2a6db45..67c8b49 100644
--- a/docs/demo/bls.js
+++ b/docs/demo/bls.js
@@ -144,7 +144,6 @@ function define_bls_extra_functions(mod) {
const G2_SIZE = FR_SIZE * 3 * 2
const GT_SIZE = FR_SIZE * 12
- const ID_SIZE = FR_SIZE
const SECRETKEY_SIZE = FR_SIZE
const PUBLICKEY_SIZE = G2_SIZE
const SIGNATURE_SIZE = G1_SIZE
@@ -225,9 +224,9 @@ function define_bls_extra_functions(mod) {
blsSecretKeyShare = wrap_keyShare(_blsSecretKeyShare, SECRETKEY_SIZE)
blsPublicKeyShare = wrap_keyShare(_blsPublicKeyShare, PUBLICKEY_SIZE)
- blsSecretKeyRecover = wrap_recover(_blsSecretKeyRecover, SECRETKEY_SIZE, ID_SIZE)
- blsPublicKeyRecover = wrap_recover(_blsPublicKeyRecover, PUBLICKEY_SIZE, ID_SIZE)
- blsSignatureRecover = wrap_recover(_blsSignatureRecover, SIGNATURE_SIZE, ID_SIZE)
+ blsSecretKeyRecover = wrap_recover(_blsSecretKeyRecover, SECRETKEY_SIZE, BLS_ID_SIZE)
+ blsPublicKeyRecover = wrap_recover(_blsPublicKeyRecover, PUBLICKEY_SIZE, BLS_ID_SIZE)
+ blsSignatureRecover = wrap_recover(_blsSignatureRecover, SIGNATURE_SIZE, BLS_ID_SIZE)
var mallocAndCopyFromUint32Array = function(a) {
let pos = mod._malloc(a.length * 4)
@@ -243,31 +242,44 @@ function define_bls_extra_functions(mod) {
}
mod._free(pos)
}
- var callSetter1 = function(func, a, s) {
+ var callSetter1 = function(func, v, p1) {
let pos = blsId_malloc()
- func(pos, s)
- copyToUint32ArrayAndFree(a, pos)
+ func(pos, p1)
+ copyToUint32ArrayAndFree(v, pos)
}
- var callGetter0 = function(func, a) {
- let pos = mallocAndCopyFromUint32Array(a)
+ var callGetter0 = function(func, v) {
+ let pos = mallocAndCopyFromUint32Array(v)
let s = func(pos)
bls_free(pos)
return s
}
- BlsId.prototype.setDecStr = function(s) {
- callSetter1(blsIdSetDecStr, this.v_, s)
+ BlsId.prototype.setInt = function(x) {
+ callSetter1(blsIdSetInt, this.v_, x)
}
- BlsId.prototype.setHexStr = function(s) {
- callSetter1(blsIdSetHexStr, this.v_, s)
+ BlsId.prototype.setStr = function(s, base = 10) {
+ switch (base) {
+ case 10:
+ callSetter1(blsIdSetDecStr, this.v_, s)
+ return
+ case 16:
+ callSetter1(blsIdSetHexStr, this.v_, s)
+ return
+ default:
+ throw('BlsId.setStr:bad base:' + base)
+ }
}
BlsId.prototype.deserialize = function(s) {
callSetter1(blsIdDeserialize, this.v_, s)
}
- BlsId.prototype.getDecStr = function() {
- return callGetter0(blsIdGetDecStr, this.v_)
- }
- BlsId.prototype.getHexStr = function() {
- return callGetter0(blsIdGetHexStr, this.v_)
+ BlsId.prototype.getStr = function(base = 10) {
+ switch (base) {
+ case 10:
+ return callGetter0(blsIdGetDecStr, this.v_)
+ case 16:
+ return callGetter0(blsIdGetHexStr, this.v_)
+ default:
+ throw('BlsId.getStr:bad base:' + base)
+ }
}
BlsId.prototype.serialize = function() {
return callGetter0(blsIdSerialize, this.v_)