Skip to content
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
26 changes: 7 additions & 19 deletions crates/auths-crypto/src/webcrypto_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,12 @@ impl CryptoProvider for WebCryptoProvider {
let usages = js_sys::Array::of1(&wasm_bindgen::JsValue::from_str("verify"));

let import_promise = subtle
.import_key_with_str(
"raw",
&key_data,
"Ed25519",
false,
&usages,
)
.map_err(|e| {
CryptoError::OperationFailed(format!("importKey failed: {e:?}"))
})?;
.import_key_with_str("raw", &key_data, "Ed25519", false, &usages)
.map_err(|e| CryptoError::OperationFailed(format!("importKey failed: {e:?}")))?;

let crypto_key: web_sys::CryptoKey = JsFuture::from(import_promise)
.await
.map_err(|e| {
CryptoError::OperationFailed(format!("importKey rejected: {e:?}"))
})?
.map_err(|e| CryptoError::OperationFailed(format!("importKey rejected: {e:?}")))?
.unchecked_into();

let verify_promise = subtle
Expand All @@ -82,13 +72,11 @@ impl CryptoProvider for WebCryptoProvider {
signature,
message,
)
.map_err(|e| {
CryptoError::OperationFailed(format!("verify call failed: {e:?}"))
})?;
.map_err(|e| CryptoError::OperationFailed(format!("verify call failed: {e:?}")))?;

let result = JsFuture::from(verify_promise).await.map_err(|e| {
CryptoError::OperationFailed(format!("verify rejected: {e:?}"))
})?;
let result = JsFuture::from(verify_promise)
.await
.map_err(|e| CryptoError::OperationFailed(format!("verify rejected: {e:?}")))?;

if result.as_bool().unwrap_or(false) {
Ok(())
Expand Down
19 changes: 8 additions & 11 deletions crates/auths-crypto/tests/wasm_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,23 @@ wasm_bindgen_test_configure!(run_in_browser);

// RFC 8032 Section 7.1, Test Vector 2 (single-byte message 0x72)
const RFC8032_PUBKEY: [u8; 32] = [
0x3d, 0x40, 0x17, 0xc3, 0xe8, 0x43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0xd9, 0xe4, 0x4b, 0x5b, 0xe7, 0xcc, 0x20, 0x5f, 0xd3, 0xc1, 0xb5, 0x7d, 0x52, 0xd3, 0xc1,
];

// A different valid public key (RFC 8032, Test Vector 1)
const RFC8032_OTHER_PUBKEY: [u8; 32] = [
0xd7, 0x5a, 0x98, 0x01, 0x82, 0xb1, 0x0a, 0xb7, 0xd5, 0x4b, 0xfe, 0xd3, 0xc9, 0x64, 0x07,
0x3a, 0x0e, 0xe1, 0x72, 0xf3, 0xda, 0xa3, 0xf4, 0xa1, 0x84, 0x46, 0xb0, 0xb8, 0xd1, 0x83,
0xf8, 0xe3,
0xd7, 0x5a, 0x98, 0x01, 0x82, 0xb1, 0x0a, 0xb7, 0xd5, 0x4b, 0xfe, 0xd3, 0xc9, 0x64, 0x07, 0x3a,
0x0e, 0xe1, 0x72, 0xf3, 0xda, 0xa3, 0xf4, 0xa1, 0x84, 0x46, 0xb0, 0xb8, 0xd1, 0x83, 0xf8, 0xe3,
];

#[wasm_bindgen_test]
Expand Down
Loading
Loading