herumi / bls-wasm

BLS signature for Node.js by WebAssembly
47 stars 26 forks source link

Wasm read but not used #2

Closed janus closed 5 years ago

janus commented 5 years ago

I have searched through bls.js to see how wasm file is used. But it is not clear to me. And I found this function call strange , Module(). Where is this function calling from?

`` fetch(./${name}.wasm`) // eslint-disable-line .then(response => response.arrayBuffer()) .then(buffer => new Uint8Array(buffer)) .then(() => { exports.mod = Module() // eslint-disable-line exports.mod.cryptoGetRandomValues = _cryptoGetRandomValues exports.mod.onRuntimeInitialized = () => { setup(exports, curveType) resolve() } })

herumi commented 5 years ago

The code is for !isNodeJs, i.e., browsers. Module() is defined in bls_c.js, and a function defined in it calls wasm file.

janus commented 5 years ago

Please can you give me the importObject to use in the below:

I managed to craft this .. it compiles but has no value,


      env: {
      '__table_base': 0,
      '__memory_base': 0,
      'memory': new WebAssembly.Memory({initial: 256, maximum: 256}),
      'table': new WebAssembly.Table({initial: 232, element: 'anyfunc', maximum: 232}),
      'a': 66928,
      'b': function(){},
      'c': function(val){return val},
      'd': function(requestedSize){return false},
      'e': function(){},
      'f': function(){},
      abort: function(){},
      }
    }

fetch(`http://localhost:8080/dist/${name}.wasm`) // eslint-disable-line
            .then(response => response.arrayBuffer()) //response.arrayBeuffer())
            .then(buffer =>  WebAssembly.compile(buffer))
            .then((module) => new WebAssembly.Instance(module, importObject))
            .then((instance) => {
herumi commented 5 years ago

bls_c.js is generated by Emscripten so please see the documents.

janus commented 5 years ago

@herumi Thanks .. but when I tried wasm2wat to the wasm file provided I found that it lacked bls functions. I would have compiled to wasm by myself but I dont know where this file is ,../mcl/src/fp.cpp. Easy it possible to get that file? And could you compile to only wasm ... that is something like this emcc -o blc_s.wasm src/bls_c384.cpp ../mcl/src/fp.cpp $(EMCC_OPT).

herumi commented 5 years ago

Please try the following command.

mkdir work
cd work
git clone git@github.com:herumi/mcl
git clone git@github.com:herumi/bls
cd bls
make bls-wasm
janus commented 5 years ago

Thanks ... I have been able to compile to wasm only ... I will test ... and give you feed back.