aboutsummaryrefslogtreecommitdiffstats
path: root/docs/demo
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
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')
-rw-r--r--docs/demo/bls-demo.js12
-rw-r--r--docs/demo/bls.html1
-rw-r--r--docs/demo/bls.js54
-rw-r--r--docs/demo/bls_c.wasmbin524171 -> 524157 bytes
4 files changed, 30 insertions, 37 deletions
diff --git a/docs/demo/bls-demo.js b/docs/demo/bls-demo.js
index 8214668..926bf11 100644
--- a/docs/demo/bls-demo.js
+++ b/docs/demo/bls-demo.js
@@ -3,12 +3,12 @@ function setValue(name, val) { document.getElementsByName(name)[0].value = val }
function getText(name) { return document.getElementsByName(name)[0].innerText }
function setText(name, val) { document.getElementsByName(name)[0].innerText = val }
-(function() {
- bls.init(function() {
- setText('status', 'ok')
- setText('curveOrder', bls.capi.blsGetCurveOrder())
- })
-})()
+bls.init()
+ .then(() => {
+ console.log('XXX')
+ setText('status', 'ok')
+ setText('curveOrder', bls.capi.blsGetCurveOrder())
+ })
let prevSelectedCurve = -1
function onChangeSelectCurve() {
diff --git a/docs/demo/bls.html b/docs/demo/bls.html
index 14e09dd..c148f07 100644
--- a/docs/demo/bls.html
+++ b/docs/demo/bls.html
@@ -4,7 +4,6 @@
<meta charset="UTF-8">
<title>BLS signature sample</title>
<link rel="stylesheet" href="style.css" type="text/css">
-<script type='text/javascript' src="./exported-bls.js"></script>
<script type='text/javascript' src="./bls_c.js"></script>
<script type='text/javascript' src="./bls.js"></script>
<script type='text/javascript' src="./bls-demo.js"></script>
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) {
diff --git a/docs/demo/bls_c.wasm b/docs/demo/bls_c.wasm
index 91a2694..e58164d 100644
--- a/docs/demo/bls_c.wasm
+++ b/docs/demo/bls_c.wasm
Binary files differ