aboutsummaryrefslogtreecommitdiffstats
path: root/docs/demo/bls.js
diff options
context:
space:
mode:
authorMITSUNARI Shigeo <herumi@nifty.com>2017-11-08 14:08:53 +0800
committerMITSUNARI Shigeo <herumi@nifty.com>2017-11-08 14:08:56 +0800
commitdccacf2a926150237466a5fe994f2efd9b2681f8 (patch)
tree34e03312ace15bb52dc24d3ef7afec4ffc700e5b /docs/demo/bls.js
parent4dcdbacbc21c17b993034b6aab3ac71b4e94b84b (diff)
downloaddexon-bls-dccacf2a926150237466a5fe994f2efd9b2681f8.tar
dexon-bls-dccacf2a926150237466a5fe994f2efd9b2681f8.tar.gz
dexon-bls-dccacf2a926150237466a5fe994f2efd9b2681f8.tar.bz2
dexon-bls-dccacf2a926150237466a5fe994f2efd9b2681f8.tar.lz
dexon-bls-dccacf2a926150237466a5fe994f2efd9b2681f8.tar.xz
dexon-bls-dccacf2a926150237466a5fe994f2efd9b2681f8.tar.zst
dexon-bls-dccacf2a926150237466a5fe994f2efd9b2681f8.zip
[js] change bls.init api
Diffstat (limited to 'docs/demo/bls.js')
-rw-r--r--docs/demo/bls.js54
1 files changed, 24 insertions, 30 deletions
diff --git a/docs/demo/bls.js b/docs/demo/bls.js
index 884956e..10d7f44 100644
--- a/docs/demo/bls.js
+++ b/docs/demo/bls.js
@@ -28,46 +28,40 @@
const BLS_PUBLICKEY_SIZE = BLS_ID_SIZE * 3 * 2
const BLS_SIGNATURE_SIZE = BLS_ID_SIZE * 3
- let g_callback = null
- let g_curveType = 0
-
let capi = {}
exports.capi = capi
let mod = exports.mod
- exports.init = function(callback = null, curveType = MCLBN_CURVE_FP254BNB) {
+ exports.init = (curveType = MCLBN_CURVE_FP254BNB) => {
console.log('init')
- g_callback = callback
- g_curveType = curveType
- if (isNodeJs) {
- } else {
+ if (!isNodeJs) {
fetch('bls_c.wasm')
.then(response => response.arrayBuffer())
.then(buffer => new Uint8Array(buffer))
.then(binary => { Module(mod) })
}
- }
-
- mod.onRuntimeInitialized = function() {
- console.log('onRuntimeInitialized')
- const f = function(exportedFuncs) {
- exportedFuncs.forEach(func => {
- capi[func.exportName] = mod.cwrap(func.name, func.returns, func.args)
- })
- define_extra_functions(mod)
- let r = capi.blsInit(g_curveType)
- console.log('finished ' + r)
- if (g_callback) g_callback()
- }
- if (isNodeJs) {
- const fs = require('fs')
- const jsonStr = fs.readFileSync('./exported-bls.json')
- f(JSON.parse(jsonStr))
- } else {
- fetch('exported-bls.json')
- .then(response => response.json())
- .then(exportedFuncs => f(exportedFuncs))
- }
+ return new Promise((resolve) => {
+ mod.onRuntimeInitialized = () => {
+ const f = (exportedFuncs) => {
+ exportedFuncs.forEach(func => {
+ capi[func.exportName] = mod.cwrap(func.name, func.returns, func.args)
+ })
+ define_extra_functions(mod)
+ let r = capi.blsInit(curveType)
+ console.log('finished ' + r)
+ resolve()
+ }
+ if (isNodeJs) {
+ const fs = require('fs')
+ const jsonStr = fs.readFileSync('./exported-bls.json')
+ f(JSON.parse(jsonStr))
+ } else {
+ fetch('exported-bls.json')
+ .then(response => response.json())
+ .then(exportedFuncs => f(exportedFuncs))
+ }
+ }
+ })
}
const ptrToStr = function(pos, n) {