From 2b376693509b9a24aa0fa1ef18a8f46d44b02f66 Mon Sep 17 00:00:00 2001 From: MITSUNARI Shigeo Date: Mon, 9 Oct 2017 18:02:27 +0900 Subject: [js] add BlsId class --- docs/demo/bls-demo.js | 9 +++++++++ docs/demo/bls.html | 9 +++++++++ docs/demo/bls.js | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+) (limited to 'docs') 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 = 0
e(aP, bQ) == e(P, Q)^ab is
+
+ +
+id(dec) =
+
+id(hex) =
+id(dec) again =
+
+
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 + } } -- cgit v1.2.3