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

Wasm API to entropy-protocol uses camelCase function names #566

Merged
merged 3 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ At the moment this project **does not** adhere to
- In [#536](https://github.com/entropyxyz/entropy-core/pull/536/), the registered struct no longer holds a program but rather a hash of a program that is set in the set_program function
- When executing the signing protocol on the client-side, a `sig-uid` no longer needs to be given as
an argument ([#549](https://github.com/entropyxyz/entropy-core/pull/549))
- Wasm API to entropy-protocol uses camelCase function names ([#566](https://github.com/entropyxyz/entropy-core/pull/566))

### Added
- Test CLI which calls the same code as in integration tests ([#417](https://github.com/entropyxyz/entropy-core/pull/417))
Expand Down
16 changes: 8 additions & 8 deletions crates/protocol/js-README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ the Entropy signing and DKG protocols on the client side.

Exposed to JS:

- `run_dkg_protocol`
- `run_signing_protocol`
- `runDkgProtocol`
- `runSigningProtocol`
- `ValidatorInfo`
- `KeyShare`

Expand Down Expand Up @@ -36,24 +36,24 @@ other details (IP address and x25519 public encryption key) by using
the staking pallet's `threshold_servers` query with the account ID.

We create an array of `ValidatorInfo` objects containing these details,
and pass this to the `run_dkg_protocol` function, together with the
and pass this to the `runDkgProtocol` function, together with the
user's secret sr25519 signing key.

`run_dkg_protocol` returns a promise which if successful will resolve to a
`runDkgProtocol` returns a promise which if successful will resolve to a
`KeyShare`. `KeyShare` has methods for serialization and de-serialization,
to/from both JSON and binary (using [bincode](https://docs.rs/bincode)).

## Signing in private access mode

The `run_signing_protocol` function also takes an array of `ValidatorInfo`
The `runSigningProtocol` function also takes an array of `ValidatorInfo`
objects. These should be selected using the message hash, exactly the
same as the those used in a `UserSignatureRequest`.

`run_signing_protocol` needs to be run concurrently whilst
`runSigningProtocol` needs to be run concurrently whilst
making the `user/sign_tx` http requests, for example by using
`Promise.all`. `run_signing_protocol` also takes the user's `KeyShare`
`Promise.all`. `runSigningProtocol` also takes the user's `KeyShare`
as an argument, as well as the message hash, and the user's private
sr25519 signing key.

`run_signing_protocol` returns a promise which if successful will resolve
`runSigningProtocol` returns a promise which if successful will resolve
to an ECDSA signature with recovery bit, encoded as a base64 string.
4 changes: 2 additions & 2 deletions crates/protocol/nodejs-test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ try {

switch(process.argv[2].toLowerCase()) {
case 'register':
protocol.run_dkg_protocol(input.validators_info, input.user_sig_req_secret_key).then((keyShare) => {
protocol.runDkgProtocol(input.validators_info, input.user_sig_req_secret_key).then((keyShare) => {
console.log(keyShare.toString())
}).catch((err) => {
console.error('ERR', err)
})
break
case 'sign':
let keyShare = protocol.KeyShare.fromString(input.key_share)
protocol.run_signing_protocol(keyShare, input.message_hash, input.validators_info, input.user_sig_req_secret_key)
protocol.runSigningProtocol(keyShare, input.message_hash, input.validators_info, input.user_sig_req_secret_key)
.then((output) => {
console.log(output)
}).catch((err) => {
Expand Down
8 changes: 4 additions & 4 deletions crates/protocol/src/user/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use super::{user_participates_in_dkg_protocol, user_participates_in_signing_prot
use crate::KeyParams;

/// Run the DKG protocol on the client side and return a keyshare
#[cfg_attr(feature = "wasm", wasm_bindgen)]
#[cfg_attr(feature = "wasm", wasm_bindgen(js_name = runDkgProtocol))]
pub async fn run_dkg_protocol(
validators_info_js: ValidatorInfoArray,
user_signing_secret_key: Vec<u8>,
Expand All @@ -27,7 +27,7 @@ pub async fn run_dkg_protocol(

/// Run the signing protocol on the client side
/// Returns a recoverable signature as a base64 encoded string
#[cfg_attr(feature = "wasm", wasm_bindgen)]
#[cfg_attr(feature = "wasm", wasm_bindgen(js_name = runSigningProtocol))]
pub async fn run_signing_protocol(
key_share: KeyShare,
message_hash: Vec<u8>,
Expand Down Expand Up @@ -62,7 +62,7 @@ extern "C" {
/// Details of a validator intended for use on JS
/// This differs from [crate::ValidatorInfo] only in that the fields must be private
#[derive(TryFromJsValue)]
#[wasm_bindgen]
#[wasm_bindgen(inspectable)]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This just makes the type look more meaningful when displayed in JS - see https://rustwasm.github.io/docs/wasm-bindgen/reference/attributes/on-rust-exports/inspectable.html

#[derive(Clone)]
pub struct ValidatorInfo {
x25519_public_key: [u8; 32],
Expand Down Expand Up @@ -136,7 +136,7 @@ fn parse_validator_info(

/// Synedrion key share wrapped for wasm
#[derive(TryFromJsValue)]
#[wasm_bindgen]
#[wasm_bindgen(inspectable)]
#[derive(Clone)]
pub struct KeyShare(synedrion::KeyShare<KeyParams>);

Expand Down