Skip to content

Commit

Permalink
Take &[u8] from JavaScript for clientDataJSON
Browse files Browse the repository at this point in the history
The browser APIs provide it as `Uint8Array`.
  • Loading branch information
hrxi authored and jsdanielh committed Mar 8, 2024
1 parent 13b2b2e commit 3f3145d
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions web-client/src/primitives/signature_proof.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::str;

use js_sys::Array;
use nimiq_serde::Serialize;
use wasm_bindgen::prelude::*;
Expand Down Expand Up @@ -64,11 +66,14 @@ impl SignatureProof {
public_key: &PublicKeyUnion,
signature: &SignatureUnion,
authenticator_data: &[u8],
client_data_json: &str,
client_data_json: &[u8],
) -> Result<SignatureProof, JsError> {
let public_key = SignatureProof::unpack_public_key(public_key)?;
let signature = SignatureProof::unpack_signature(signature)?;

let client_data_json = str::from_utf8(client_data_json)
.map_err(|e| JsError::new(&format!("Invalid clientDataJSON: {e}")))?;

Ok(SignatureProof::from(
nimiq_transaction::SignatureProof::try_from_webauthn(
public_key,
Expand Down Expand Up @@ -106,6 +111,9 @@ impl SignatureProof {
Vec<u8>,
>(&public_keys, &signer_key.serialize_to_vec());

let client_data_json = str::from_utf8(client_data_json)
.map_err(|e| JsError::new(&format!("Invalid clientDataJSON: {e}")))?;

Ok(SignatureProof::from(
nimiq_transaction::SignatureProof::try_from_webauthn(
signer_key,
Expand Down Expand Up @@ -265,7 +273,7 @@ mod tests {
"49960de5880e8c687434170f6476605b8fe4aeb9a28632c7995cf3ba831d97630100000007",
)
.unwrap();
let client_data_json = r#"{"type":"webauthn.get","challenge":"u7CRZnGHrWoR9ix5llhl2VopsexuW36FKszgHBx4FfM","origin":"http://localhost:5173","crossOrigin":false}"#;
let client_data_json = br#"{"type":"webauthn.get","challenge":"u7CRZnGHrWoR9ix5llhl2VopsexuW36FKszgHBx4FfM","origin":"http://localhost:5173","crossOrigin":false}"#;
let proof = SignatureProof::webauthn_single_sig(
&JsValue::from(public_key).into(),
&JsValue::from(signature).into(),
Expand Down Expand Up @@ -295,7 +303,7 @@ mod tests {
"7a03a16dfe0c4358b79eebe4f25cba56ec7aa7c8331f46a96988006db440e690050000003c",
)
.unwrap();
let client_data_json = r#"{"type":"webauthn.get","challenge":"OCAjaXEXs-P4zqEk-61MhWPOq9a8VpDL2qf3ZwnAI9I","origin":"https:\/\/webauthn.pos.nimiqwatch.com","androidPackageName":"com.android.chrome"}"#;
let client_data_json = br#"{"type":"webauthn.get","challenge":"OCAjaXEXs-P4zqEk-61MhWPOq9a8VpDL2qf3ZwnAI9I","origin":"https:\/\/webauthn.pos.nimiqwatch.com","androidPackageName":"com.android.chrome"}"#;
let proof = SignatureProof::webauthn_single_sig(
&JsValue::from(public_key).into(),
&JsValue::from(signature).into(),
Expand Down

0 comments on commit 3f3145d

Please sign in to comment.