-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor crypto
and other WASM-based modules
#341
Refactor crypto
and other WASM-based modules
#341
Conversation
|
@cairomassimo Would it be easier if we made a feature branch for this work? this would make it easier to review the work over time as comments will be cleared once you push newer commits. If we used a feature branch then we could review in a more manageable fashion. WDYT? |
To do:
|
ng/wasm/Cargo.toml
Outdated
serde_json = "1.0" | ||
serde_bare = "0.5" | ||
serde-wasm-bindgen = "0.5" | ||
bls12_381_plus = { version = "=0.8.9" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed since you're including blsful. Use blsful::inner_types and it gets you the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree.
I added this to fix the crate to an older version, which would fix a compile error. IIRC, I got the error when using the blsful
crate from Git, but it doesn't occur at all using versions published to crates.io. Removing.
ng/wasm/src/bls.rs
Outdated
|
||
struct Bls<C>(C); | ||
|
||
// We have to create this trait because G1/G2 implementations do not use a common trait for all the methods we need. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They actually do. See https://github.com/mikelodder7/blsful/blob/main/src/traits/serdes.rs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if we can go Uint8Array
-> Vec<u8>
-> {struct}
via serde and these traits. A TryFrom<Vec<u8>>
would fit better, or we could change the overall approach to rely on serde for JS communication everywhere.
Happy to discuss this today!
|
||
#[derive(Tsify, Deserialize)] | ||
#[tsify(from_wasm_abi)] | ||
pub enum EcdsaVariant { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing P384
ng/wasm/src/ecdsa.rs
Outdated
Ok(k) | ||
} | ||
|
||
fn derive_key_inner( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use these traits instead https://github.com/LIT-Protocol/hd-keys-curves/blob/main/src/lib.rs#L23
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happily! See #341 (comment)
ng/wasm/src/ecdsa.rs
Outdated
Ok(k) | ||
} | ||
|
||
fn sum_of_products_pippenger( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we copying code here? All this is done for you in https://github.com/LIT-Protocol/hd-keys-curves/blob/main/src/lib.rs#L23
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code was moved*, not copied, from https://github.com/LIT-Protocol/lit-ecdsa-wasm-combine/blob/main/src/combiners/hd_ecdsa/mod.rs#L53, I didn't know it was also available in another crate.
[*] the idea is having only one crate that exposes the crypto functionality to JS via WASM, and have it be part of the SDK. Ideally, this crate would not actually implement any cryptography itself, but only delegate to other crates making sure the API is JS-friendly and type-safe.
So indeed this piece of code lives much better in a different crate, I'll happily work on delegating this to hd-keys-curves
!
|
||
#[derive(Tsify, Deserialize)] | ||
#[tsify(from_wasm_abi)] | ||
pub enum FrostVariant { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again why are we copying code from lit-frost? The point of a crate is that its reusable.
54f422d
to
c5a9385
Compare
The `blstrs_plus` implementation of BLS curves would crash with a `panic_misaligned_pointer_dereference`. That implementation was wrongly selected over `bls12_381_plus` after adding dependency `hd-keys-curves`, which implied `blsful/default` -> `blsful/blst` -> `blsful/blstrs_plus`.
Description
Re-implement the functionality of
@lit-protocol/crypto
package as follows (WIP!):nx
workspace (currently in theng/
dir), with a simpler/standard build system,@lit-protocol/crypto
to the new implementation,@lit-protocol/crypto
to the new implementation.Design choices
esbuild
as bundleresbuild-jest-transform
@lit-protocol/ng
, to be renamed)Notes
The build does not generate
.d.ts
TypeScript declaration files yet.Not adding this for now, since it could come for free if recent PR nrwl/nx#21084 is merged (or nrwl/nx#20688 fixed anyway).