bmt.js (928B)
1 const fs = require('fs'); 2 3 const memory = new WebAssembly.Memory({initial: 3}); 4 const table = new WebAssembly.Table({initial: 10, element: 'anyfunc'}); 5 const importsObj = { 6 env: { 7 memory: memory, 8 dlog: function(prefix, l, value) { 9 const v = new Uint8Array(memory.buffer, prefix, l); 10 const s = new TextDecoder().decode(v); 11 console.log('log: ' + s, value); 12 }, 13 } 14 } 15 16 async function init() { 17 const code = fs.readFileSync('./lib/swarm.wasm'); 18 const m = new WebAssembly.Module(code); 19 const i = new WebAssembly.Instance(m, importsObj); 20 21 let r; 22 let data = new Uint8Array(memory.buffer, 65535*2+1024, 3); 23 data.set([0x66, 0x6f, 0x6f], 0); 24 r = i.exports.bmt_hash_heap(65535*2+1024, 3, BigInt(3)); 25 26 let outBuf = new Uint8Array(memory.buffer, r, 32); 27 let inBuf = new Uint8Array(memory.buffer, r + 32, 3); 28 29 i.exports.bmt_hash_free(r); 30 31 process.stdout.write(Buffer.from(outBuf).toString("hex") + "\n"); 32 } 33 34 init();