diff --git a/Cargo.toml b/Cargo.toml index ca0112e..3ae91d5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,7 @@ cainome = { git = "https://github.com/piniom/cainome", tag="v0.2.4-expand", feat "abigen-rs", "expand-expr" ] } cairo-lang-starknet = "2.4.0" +ecdsa = "0.16.9" futures = "0.3" lazy_static = "1" p256 = "0.13" @@ -30,7 +31,7 @@ u256-literal = "1" url = "2" wasm-bindgen = "0.2" wasm-bindgen-futures = "0.4.42" -wasm-webauthn = { git = "https://github.com/broody/wasm-webauthn" } +wasm-webauthn = { git = "https://github.com/broody/wasm-webauthn", rev = "f54bdbc3b4c5da2679e6f74278295b3924b56db5" } webauthn-rs-proto = "0.4" account-sdk = { path = "crates/account_sdk" } tokio = { version = "1", features = ["macros", "time"] } diff --git a/crates/account_sdk/Cargo.toml b/crates/account_sdk/Cargo.toml index 618f9af..efea5e5 100644 --- a/crates/account_sdk/Cargo.toml +++ b/crates/account_sdk/Cargo.toml @@ -14,6 +14,7 @@ async-trait.workspace = true base64.workspace = true cainome.workspace = true cairo-lang-starknet.workspace = true +ecdsa.workspace = true futures.workspace = true lazy_static.workspace = true p256.workspace = true @@ -31,6 +32,7 @@ url.workspace = true wasm-bindgen-futures.workspace = true wasm-bindgen.workspace = true wasm-webauthn.workspace = true +web-sys = "0.3.69" [target.'cfg(not(target_arch = "wasm32"))'.dependencies] tokio.workspace = true @@ -38,4 +40,3 @@ tokio.workspace = true [target.'cfg(target_arch = "wasm32")'.dependencies] wasm-bindgen-test = "0.3.34" js-sys = "0.3.69" -web-sys = "0.3.69" diff --git a/crates/account_sdk/src/webauthn_signer/signers/device.rs b/crates/account_sdk/src/webauthn_signer/signers/device.rs index 21cdd0d..061412c 100644 --- a/crates/account_sdk/src/webauthn_signer/signers/device.rs +++ b/crates/account_sdk/src/webauthn_signer/signers/device.rs @@ -1,5 +1,6 @@ use async_trait::async_trait; use futures::channel::oneshot; +use p256::NistP256; use std::result::Result; use wasm_bindgen_futures::spawn_local; use wasm_webauthn::*; @@ -130,15 +131,23 @@ impl DeviceSigner { impl Signer for DeviceSigner { async fn sign(&self, challenge: &[u8]) -> Result { let GetAssertionResponse { - signature, + signature: encoded_sig, + rp_id_hash, client_data_json, flags, counter, } = self.get_assertion(challenge).await?; + let ecdsa_sig = ecdsa::Signature::::from_der(&encoded_sig).unwrap(); + let r = ecdsa_sig.r().to_bytes(); + let s = ecdsa_sig.s().to_bytes(); + + let mut signature = r.as_slice().to_vec(); + signature.extend_from_slice(s.as_slice()); + Ok(AuthenticatorAssertionResponse { authenticator_data: AuthenticatorData { - rp_id_hash: [0; 32], + rp_id_hash, flags, sign_count: counter, },