vulpemventures / secp256k1-zkp

JavaScript bindings of libsecp256k1-zkp with support for pedersen commitments and range proofs.
MIT License
15 stars 10 forks source link

Compile to wasm and export to JS wrapper #12

Closed tiero closed 3 years ago

tiero commented 3 years ago

This is a substantial refactor in the secp256k1-zkp JS bindings module.

You can find comparisons for node and browser environments in the following comments in this PR thread. I don't see wht holding back on this refactor, we should move to WASM as soon as possible.

Breaking changes

As documented in test and README we must do as the following:

const secp256k1 = require('secp256k1-zkp');

// secp256k1 returns a Promise that must be resolved before using the exported methods
const { rangeproof, surjectionproof } = await secp256k1(); 

rangeproof.rewind(...)
surjectionproof.verify(...)

This adds a little overhead from 30 to 80 milliseconds in browsers (depending if Chorme or Firefox, Chrome's V8 runtime is always faster), negligible ~0-1 ms in node

Improvements for the future

tiero commented 3 years ago

I can go to bed now :) That's only node, hope the gains will be the same for the browser tho

ASM.js (current master)

image

WASM

image

tiero commented 3 years ago

ASM.js

To run test checkout my branch which adapts current master to run the test/ecdh.browser.js

Chrome

image

Firefox

image

WASM

Chrome

image

Firefox

image

tiero commented 3 years ago

I would wait to merge this. Since liquidjs-lib (both provable and vulpem fork) depends on master, this would break them.

So I would first make a patch for liquidjs using my branch and merge when ready to do at the same time

louisinger commented 3 years ago

Update: index.d.ts now defines interfaces instead of modules and export as default a function returning a Promise.