Skip to content

Commit

Permalink
Decode signature from assertion response
Browse files Browse the repository at this point in the history
  • Loading branch information
broody committed Apr 4, 2024
1 parent fd2336f commit 8618af7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"] }
3 changes: 2 additions & 1 deletion crates/account_sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -31,11 +32,11 @@ 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

[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen-test = "0.3.34"
js-sys = "0.3.69"
web-sys = "0.3.69"
13 changes: 11 additions & 2 deletions crates/account_sdk/src/webauthn_signer/signers/device.rs
Original file line number Diff line number Diff line change
@@ -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::*;
Expand Down Expand Up @@ -130,15 +131,23 @@ impl DeviceSigner {
impl Signer for DeviceSigner {
async fn sign(&self, challenge: &[u8]) -> Result<AuthenticatorAssertionResponse, SignError> {
let GetAssertionResponse {
signature,
signature: encoded_sig,
rp_id_hash,

Check warning on line 135 in crates/account_sdk/src/webauthn_signer/signers/device.rs

View check run for this annotation

Codecov / codecov/patch

crates/account_sdk/src/webauthn_signer/signers/device.rs#L134-L135

Added lines #L134 - L135 were not covered by tests
client_data_json,
flags,
counter,
} = self.get_assertion(challenge).await?;

Check warning on line 139 in crates/account_sdk/src/webauthn_signer/signers/device.rs

View workflow job for this annotation

GitHub Actions / fmt

Diff in /home/runner/work/cairo-webauthn/cairo-webauthn/crates/account_sdk/src/webauthn_signer/signers/device.rs

let ecdsa_sig = ecdsa::Signature::<NistP256>::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());

Check warning on line 147 in crates/account_sdk/src/webauthn_signer/signers/device.rs

View check run for this annotation

Codecov / codecov/patch

crates/account_sdk/src/webauthn_signer/signers/device.rs#L141-L147

Added lines #L141 - L147 were not covered by tests
Ok(AuthenticatorAssertionResponse {
authenticator_data: AuthenticatorData {
rp_id_hash: [0; 32],
rp_id_hash,

Check warning on line 150 in crates/account_sdk/src/webauthn_signer/signers/device.rs

View check run for this annotation

Codecov / codecov/patch

crates/account_sdk/src/webauthn_signer/signers/device.rs#L150

Added line #L150 was not covered by tests
flags,
sign_count: counter,
},
Expand Down

0 comments on commit 8618af7

Please sign in to comment.