Skip to content

Commit 6cf1d4d

Browse files
committed
test?
1 parent 5296b3b commit 6cf1d4d

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

index.js

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,29 @@
1-
const bn128 = require('./lib/index.asm.js')
2-
3-
const ec_add = bn128.cwrap('ec_add', 'string', ['string'])
4-
const ec_mul = bn128.cwrap('ec_mul', 'string', ['string'])
5-
const ec_pairing = bn128.cwrap('ec_pairing', 'string', ['string'])
1+
if (global.WebAssembly !== undefined) {
2+
const fs = require('fs')
3+
const imports = {
4+
// imports: {
5+
env: {
6+
emscripten_exit_with_live_runtime: function() {}
7+
}
8+
// }
9+
}
10+
const bn128 = WebAssembly.instantiate(fs.readFileSync('./lib/rustbn.wasm'), imports).then(function (bn128) {
11+
console.log(bn128.module)
12+
const ec_add = bn128.instance.exports.ec_add
13+
const ec_mul = bn128.instance.exports.ec_mul
14+
const ec_pairing = bn128.instance.exports.ec_pairing
15+
let memory = bn128.instance.exports.memory
16+
console.log(memory)
17+
let ret = ec_add("00112200")
18+
console.log(memory)
19+
console.log(ret)
20+
})
21+
} else {
22+
const bn128 = require('./lib/index.asm.js')
23+
const ec_add = bn128.cwrap('ec_add', 'string', ['string'])
24+
const ec_mul = bn128.cwrap('ec_mul', 'string', ['string'])
25+
const ec_pairing = bn128.cwrap('ec_pairing', 'string', ['string'])
26+
}
627

728
function bn128add (input) {
829
return Buffer.from(ec_add(input.toString('hex')), 'hex')

0 commit comments

Comments
 (0)