spruceid / didkit

A cross-platform toolkit for decentralized identity.
https://www.spruceid.dev/didkit/didkit
Apache License 2.0
274 stars 76 forks source link

Using library inside WASM #356

Closed mdochdev closed 1 year ago

mdochdev commented 1 year ago

Hi Team,

Currently attempting to use didkit with-in wasm (Dioxus to be exact). It builds a using wasm-unknown-unknown target. Previously when using crypto libraries I was able to set the getrandom feature to "js" which would allow the library to work within that target.

I am not sure why but when I attempt the same thing with didkit:

didkit = {version = "0.5"}
getrandom = { version = "0.2", features = ["js"] }

I still get unsupported target but during runtime (as it is calling os.rs). I notice that there is a lib/web which provides support with nodejs via WASM. So I know it is possible to do I am just not clear why I can not do it using this simple technique as described in the getrandom documentation.

Error for completeness: panicked at 'Error: getrandom: this target is not supported', ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rand_core-0.5.1/src/os.rs:63:13

Are you able to help provide some light on the subject, or is there a didkit-wasm crate I can use directly?

Thanks

sbihel commented 1 year ago

I believe you are missing rand = { version = "0.7", features = ["wasm-bindgen"] }?

Otherwise for didkit-wasm there's only one additional tweak, which is for chrono https://github.com/spruceid/didkit/blob/main/lib/web/Cargo.toml#L15.

Potentially, we could set these features automatically based on target, but considering these crates don't do it automatically there must be a good reason why

mdochdev commented 1 year ago

I was trying to use rand 0.8 which didn't support the wasm-bindgen feature. Moving it back to 0.7 with the feature has worked, thank you.

Is there a plan to bring the libraries to new versions at any point?

sbihel commented 1 year ago

Not at the moment but it's not a lot of work in case it causes issues with other crates