aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMITSUNARI Shigeo <herumi@nifty.com>2017-10-09 17:02:27 +0800
committerMITSUNARI Shigeo <herumi@nifty.com>2017-10-09 17:02:27 +0800
commit2b376693509b9a24aa0fa1ef18a8f46d44b02f66 (patch)
tree7993402b9885d6a504a0899e11b9a4f384888da5
parentc49bd0cb2bcec4c75cc1a50de775635e8d33ee66 (diff)
downloaddexon-bls-2b376693509b9a24aa0fa1ef18a8f46d44b02f66.tar
dexon-bls-2b376693509b9a24aa0fa1ef18a8f46d44b02f66.tar.gz
dexon-bls-2b376693509b9a24aa0fa1ef18a8f46d44b02f66.tar.bz2
dexon-bls-2b376693509b9a24aa0fa1ef18a8f46d44b02f66.tar.lz
dexon-bls-2b376693509b9a24aa0fa1ef18a8f46d44b02f66.tar.xz
dexon-bls-2b376693509b9a24aa0fa1ef18a8f46d44b02f66.tar.zst
dexon-bls-2b376693509b9a24aa0fa1ef18a8f46d44b02f66.zip
[js] add BlsId class
-rw-r--r--docs/demo/bls-demo.js9
-rw-r--r--docs/demo/bls.html9
-rw-r--r--docs/demo/bls.js55
3 files changed, 73 insertions, 0 deletions
diff --git a/docs/demo/bls-demo.js b/docs/demo/bls-demo.js
index 21ea201..a00228d 100644
--- a/docs/demo/bls-demo.js
+++ b/docs/demo/bls-demo.js
@@ -351,3 +351,12 @@ function onClickTestShare()
}
}
+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())
+}
diff --git a/docs/demo/bls.html b/docs/demo/bls.html
index 48d9b3c..fb36e6b 100644
--- a/docs/demo/bls.html
+++ b/docs/demo/bls.html
@@ -79,5 +79,14 @@ e(P, Q)^ab = <span name="ePQab">0</span><br>
<div>
e(aP, bQ) == e(P, Q)^ab is <span name="verify_pairing"></span>
</div>
+<hr>
+<button type="text" id="testMisc" onclick="onClickTestMisc()">test misc</button>
+<div>
+id(dec) = <input type="text" name="idDec" value="3"><br>
+</div>
+id(hex) = <span name="idHex"></span><br>
+id(dec) again = <span name="idDec2"></span><br>
+<div>
+</div>
</body>
</html>
diff --git a/docs/demo/bls.js b/docs/demo/bls.js
index f4cbb9f..639f207 100644
--- a/docs/demo/bls.js
+++ b/docs/demo/bls.js
@@ -21,6 +21,12 @@ const MCLBN_CURVE_FP382_2 = 2
const MCLBN_FP_UNIT_SIZE = 6
+const BLS_ID_SIZE = MCLBN_FP_UNIT_SIZE * 8
+
+BlsId = function() {
+ this.v_ = new Uint32Array(BLS_ID_SIZE / 4)
+}
+
function define_bls_extra_functions(mod) {
wrap_outputString = function(func, doesReturnString = true) {
return function(x, ioMode = 0) {
@@ -214,5 +220,54 @@ function define_bls_extra_functions(mod) {
blsSecretKeyRecover = wrap_recover(_blsSecretKeyRecover, SECRETKEY_SIZE, ID_SIZE)
blsPublicKeyRecover = wrap_recover(_blsPublicKeyRecover, PUBLICKEY_SIZE, ID_SIZE)
blsSignatureRecover = wrap_recover(_blsSignatureRecover, SIGNATURE_SIZE, ID_SIZE)
+
+ var mallocAndCopyFromUint32Array = function(a) {
+ let p = mod._malloc(a.length * 4)
+ mod.writeArrayToMemory(a, p / 4)
+// for (let i = 0; i < a.length; i++) {
+// mod.HEAP32[p / 4 + i] = a[i]
+// }
+ return p
+ }
+ var copyToUint32ArrayAndFree = function(a, p) {
+ for (let i = 0; i < a.length; i++) {
+ a[i] = mod.HEAP32[p / 4 + i]
+ }
+ mod._free(p)
+ }
+ BlsId.prototype.setDecStr = function(s) {
+ let p = blsId_malloc()
+ blsIdSetDecStr(p, s)
+ copyToUint32ArrayAndFree(this.v_, p)
+ }
+ BlsId.prototype.setHexStr = function(s) {
+ let p = blsId_malloc()
+ blsIdSetHexStr(p, s)
+ copyToUint32ArrayAndFree(this.v_, p)
+ }
+ BlsId.prototype.deserialize = function(a) {
+ let p = mallocAndCopyFromUint32Array(this.v_)
+ blsIdDeserialize(p, a)
+ bls_free(p)
+ return s
+ }
+ BlsId.prototype.getDecStr = function() {
+ let p = mallocAndCopyFromUint32Array(this.v_)
+ let s = blsIdGetDecStr(p)
+ bls_free(p)
+ return s
+ }
+ BlsId.prototype.getHexStr = function() {
+ let p = mallocAndCopyFromUint32Array(this.v_)
+ let s = blsIdGetHexStr(p)
+ bls_free(p)
+ return s
+ }
+ BlsId.prototype.serialize = function() {
+ let p = mallocAndCopyFromUint32Array(this.v_)
+ let s = blsIdSerialize(p)
+ bls_free(p)
+ return s
+ }
}