|
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 | +} |
6 | 27 |
|
7 | 28 | function bn128add (input) {
|
8 | 29 | return Buffer.from(ec_add(input.toString('hex')), 'hex')
|
|
0 commit comments