diff options
author | MITSUNARI Shigeo <herumi@nifty.com> | 2017-10-09 17:02:27 +0800 |
---|---|---|
committer | MITSUNARI Shigeo <herumi@nifty.com> | 2017-10-09 17:02:27 +0800 |
commit | 2b376693509b9a24aa0fa1ef18a8f46d44b02f66 (patch) | |
tree | 7993402b9885d6a504a0899e11b9a4f384888da5 /docs/demo/bls.js | |
parent | c49bd0cb2bcec4c75cc1a50de775635e8d33ee66 (diff) | |
download | dexon-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
Diffstat (limited to 'docs/demo/bls.js')
-rw-r--r-- | docs/demo/bls.js | 55 |
1 files changed, 55 insertions, 0 deletions
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 + } } |