Skip to content
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

[Task] Wasm Bindings Improvements #669

Open
8 of 20 tasks
HenriqueNogara opened this issue Feb 22, 2022 · 3 comments
Open
8 of 20 tasks

[Task] Wasm Bindings Improvements #669

HenriqueNogara opened this issue Feb 22, 2022 · 3 comments
Labels
Enhancement New feature or improvement to an existing feature Wasm Related to Wasm bindings. Becomes part of the Wasm changelog

Comments

@HenriqueNogara
Copy link
Contributor

HenriqueNogara commented Feb 22, 2022

Description

Remove exposure of Ed25519.sign, remove Storage Send/Sync ties to the wasm feature, and make keyDel in typescript compatible with the Rust code. Refactor the Storage trait to return better errors, and simplify its API.

Motivation

  1. Users should be able to sign data without relying on our code.
  2. We might need the Storage trait not to be Send/Sync for other bindings (e.g Python) as well, so we should not tie its bounds to the wasm feature.
  3. Js implementation of MemStore keyDel slightly differs from the Rust code regarding idempotency.
  4. identity_account::types::signature::Signature::pkey is not used in the Rust code.
  5. Storage::set_password is no longer needed.
  6. Improve error feedback. See: Add Wasm Account Storage interface #597 (comment)

To-do list

Change checklist

Add an x to the boxes that are relevant to your changes, and delete any items that are not.

  • The feature or fix is implemented in Rust and across all bindings whereas possible.
  • The feature or fix has sufficient testing coverage
  • All tests and examples build and run locally as expected
  • Every piece of code has been document according to the documentation guidelines.
  • If conceptual documentation (mdbook) and examples highlighting the feature exist, they are properly updated.
  • If the feature is not currently documented, a documentation task Issue has been opened to address this.
@HenriqueNogara HenriqueNogara added Enhancement New feature or improvement to an existing feature Wasm Related to Wasm bindings. Becomes part of the Wasm changelog labels Feb 22, 2022
@cycraig
Copy link
Contributor

cycraig commented Feb 22, 2022

Users are already able to sign data without relying on our code.

E.g. using TweetNaCl

const key = new KeyPair(KeyType.Ed25519);
const seed = bs58.decode(key.private);
let naclKeyPair = nacl.sign.keyPair.fromSeed(seed);
let challengeBytes = Uint8Array.from([1,2,3,4]);
let signature = nacl.sign(challengeBytes, naclKeyPair.secretKey);
console.log(`Signature: ${bs58.encode(signature)}`);

I do think we should switch to using UInt8Array to represent the private/public keys though, from Base58-BTC encoded strings. This is because it's the type existing libraries like TweetNaCl expect as input and to avoid requiring developers bring in Base58 dependencies to decode the strings we return. Alternative would be to expose the dencode_b58, decode_multibase functions too, which might be useful for Storage implementers regardless.

Advantages of exposing Ed25519::sign:

  • It can be compatible with our exposed structs, like KeyPair, WasmPrivateKey or generalised to UInt8Array/String.
  • It's shipped in the Wasm bytecode anyway, we may as well expose it along with other functions.
  • It can avoid external dependencies for developers.

Disadvantages:

  • API bloat: increasing the API surface also increases the maintenance cost.
  • Slight code bloat.

We have had requests to include other features in identity.rs such as BIP-39 mnemonics, so I think some developers might appreciate being able to use same the functions we do internally out of convenience.
See also this comment: https://github.com/iotaledger/identity.rs/pull/597/files#r811781156

We might need the Storage trait not to be Send/Sync for other bindings (e.g Python) as well, so we should not tie its bounds to the wasm feature.

I agree. Some conditional compilation required now just for wasm might be beneficial for other use-cases too, so we can use other features (named more specifically like storage-sync for example) on top of target-based compilation.
Edit: as long as enabling --all-features does not break compilation.

Verify the need to return an error on KeyDel

I think all Storage functions need to be async and fallible to account for unknowable remote implementations where every little network request could fail. Not the point the issue raised, it's about idempotency and consistency between Rust and bindings behaviour.

@cycraig
Copy link
Contributor

cycraig commented Mar 2, 2022

This comment on #660 may have been missed regarding the Stronghold bindings package namespace: https://github.com/iotaledger/identity.rs/pull/660/files#r816770207

Edit: resolved.

@cycraig
Copy link
Contributor

cycraig commented Mar 9, 2022

As per internal discussions, the following tasks were marked as either important or easy to do prior to 0.5.0.

Each needs its own issue or PR now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or improvement to an existing feature Wasm Related to Wasm bindings. Becomes part of the Wasm changelog
Projects
Status: Product Backlog
Development

No branches or pull requests

4 participants