Skip to content

Commit 7af734d

Browse files
committed
(feat: web-client) Add SigningInputs model (0xMiden#1160)
1 parent 0223723 commit 7af734d

File tree

17 files changed

+263
-22
lines changed

17 files changed

+263
-22
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
* Added bindings for retrieving storage `AccountDelta` in the web client ([#1098](https://github.com/0xMiden/miden-client/pull/1098)).
4242
* Added `multicall` support for the CLI ([#1141](https://github.com/0xMiden/miden-client/pull/1141))
4343
* Added `TransactionSummary`, `AccountDelta`, and `BasicFungibleFaucet` types to Web Client ([#1115](https://github.com/0xMiden/miden-client/pull/1115))
44+
* Added `SigningInputs` to Web Client ([#1160](https://github.com/0xMiden/miden-client/pull/1160))
4445

4546
## 0.10.1 (2025-07-26)
4647

crates/rust-client/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ pub mod asset {
179179
pub mod auth {
180180
pub use miden_lib::AuthScheme;
181181
pub use miden_objects::account::AuthSecretKey;
182-
pub use miden_tx::auth::{BasicAuthenticator, TransactionAuthenticator};
182+
pub use miden_tx::auth::{BasicAuthenticator, SigningInputs, TransactionAuthenticator};
183183
}
184184

185185
/// Provides types for working with blocks within the Miden network.

crates/web-client/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ miden-client = { default-features = false, features = [
3232
# Miden dependencies
3333
miden-lib = { workspace = true }
3434
miden-objects = { workspace = true }
35-
3635
# External dependencies
3736
rand = { workspace = true }
3837
serde-wasm-bindgen = { version = "0.6" }

crates/web-client/js/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ const {
5252
Rpo256,
5353
SecretKey,
5454
Signature,
55+
SigningInputs,
5556
SlotAndKeys,
5657
SlotAndKeysArray,
5758
StorageMap,
@@ -121,6 +122,7 @@ export {
121122
Rpo256,
122123
SecretKey,
123124
Signature,
125+
SigningInputs,
124126
SlotAndKeys,
125127
SlotAndKeysArray,
126128
StorageMap,

crates/web-client/js/types/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export {
5151
Rpo256,
5252
SecretKey,
5353
SerializedAccountHeader,
54+
SigningInputs,
5455
SlotAndKeys,
5556
SlotAndKeysArray,
5657
StorageMap,

crates/web-client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@demox-labs/miden-sdk",
3-
"version": "0.11.0-next.23",
3+
"version": "0.11.0-next.24",
44
"description": "Miden Wasm SDK",
55
"collaborators": [
66
"Miden",

crates/web-client/src/models/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ pub mod public_key;
8080
pub mod rpo256;
8181
pub mod secret_key;
8282
pub mod signature;
83+
pub mod signing_inputs;
8384
pub mod storage_map;
8485
pub mod storage_slot;
8586
pub mod sync_summary;

crates/web-client/src/models/public_key.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use wasm_bindgen::prelude::*;
44
use wasm_bindgen_futures::js_sys::Uint8Array;
55

66
use crate::models::signature::Signature;
7+
use crate::models::signing_inputs::SigningInputs;
78
use crate::models::word::Word;
89
use crate::utils::{deserialize_from_uint8array, serialize_to_uint8array};
910

@@ -25,8 +26,15 @@ impl PublicKey {
2526
}
2627

2728
pub fn verify(&self, message: &Word, signature: &Signature) -> bool {
29+
return self.verify_data(&SigningInputs::new_blind(message), signature);
30+
}
31+
32+
#[wasm_bindgen(js_name = "verifyData")]
33+
pub fn verify_data(&self, signing_inputs: &SigningInputs, signature: &Signature) -> bool {
34+
let native_public_key: NativePublicKey = self.into();
2835
let native_signature = signature.into();
29-
self.0.verify(message.into(), &native_signature)
36+
let native_word = signing_inputs.to_commitment().into();
37+
native_public_key.verify(native_word, &native_signature)
3038
}
3139
}
3240

crates/web-client/src/models/secret_key.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use miden_objects::Word as NativeWord;
21
use miden_objects::crypto::dsa::rpo_falcon512::SecretKey as NativeSecretKey;
32
use rand::SeedableRng;
43
use rand::rngs::StdRng;
@@ -7,6 +6,7 @@ use wasm_bindgen_futures::js_sys::Uint8Array;
76

87
use crate::models::public_key::PublicKey;
98
use crate::models::signature::Signature;
9+
use crate::models::signing_inputs::SigningInputs;
1010
use crate::models::word::Word;
1111
use crate::utils::{deserialize_from_uint8array, serialize_to_uint8array};
1212

@@ -35,11 +35,17 @@ impl SecretKey {
3535
self.0.public_key().into()
3636
}
3737

38-
pub fn sign(&self, message: &Word) -> Result<Signature, JsValue> {
39-
let native_message: NativeWord = message.into();
38+
// TODO: update to sign instead of sign_with_rng once miden-objects uses miden-crypto 0.16
39+
pub fn sign(&self, message: &Word) -> Signature {
40+
return self.sign_data(&SigningInputs::new_blind(message));
41+
}
42+
43+
// TODO: update to sign instead of sign_with_rng once miden-objects uses miden-crypto 0.16
44+
#[wasm_bindgen(js_name = "signData")]
45+
pub fn sign_data(&self, signing_inputs: &SigningInputs) -> Signature {
4046
let mut rng = StdRng::from_os_rng();
41-
let signature = self.0.sign_with_rng(native_message, &mut rng);
42-
Ok(signature.into())
47+
let native_word = signing_inputs.to_commitment().into();
48+
self.0.sign_with_rng(native_word, &mut rng).into()
4349
}
4450

4551
pub fn serialize(&self) -> Uint8Array {
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
use miden_client::auth::SigningInputs as NativeSigningInputs;
2+
use wasm_bindgen::prelude::*;
3+
4+
use crate::models::felt::Felt;
5+
use crate::models::transaction_summary::TransactionSummary;
6+
use crate::models::word::Word;
7+
8+
#[wasm_bindgen]
9+
pub struct SigningInputs {
10+
inner: NativeSigningInputs,
11+
}
12+
13+
#[wasm_bindgen]
14+
impl SigningInputs {
15+
#[wasm_bindgen(js_name = "newTransactionSummary")]
16+
pub fn new_transaction_summary(summary: TransactionSummary) -> Self {
17+
Self {
18+
inner: NativeSigningInputs::TransactionSummary(Box::new(summary.into())),
19+
}
20+
}
21+
22+
#[wasm_bindgen(js_name = "newArbitrary")]
23+
pub fn new_arbitrary(felts: Vec<Felt>) -> Self {
24+
Self {
25+
inner: NativeSigningInputs::Arbitrary(felts.into_iter().map(Into::into).collect()),
26+
}
27+
}
28+
29+
#[wasm_bindgen(js_name = "newBlind")]
30+
pub fn new_blind(word: &Word) -> Self {
31+
Self {
32+
inner: NativeSigningInputs::Blind(word.into()),
33+
}
34+
}
35+
36+
#[wasm_bindgen(getter, js_name = "variantType")]
37+
pub fn variant_type(&self) -> String {
38+
match &self.inner {
39+
NativeSigningInputs::TransactionSummary(_) => "TransactionSummary".to_string(),
40+
NativeSigningInputs::Arbitrary(_) => "Arbitrary".to_string(),
41+
NativeSigningInputs::Blind(_) => "Blind".to_string(),
42+
}
43+
}
44+
45+
#[wasm_bindgen(js_name = "toCommitment")]
46+
pub fn to_commitment(&self) -> Word {
47+
self.inner.to_commitment().into()
48+
}
49+
50+
#[wasm_bindgen(js_name = "toElements")]
51+
pub fn to_elements(&self) -> Vec<Felt> {
52+
self.inner.to_elements().into_iter().map(Into::into).collect()
53+
}
54+
}

0 commit comments

Comments
 (0)