From f72155449e215bef30b19e542fd5dc4c023996aa Mon Sep 17 00:00:00 2001 From: Zhen Lu Date: Wed, 1 Nov 2023 15:25:58 -0700 Subject: [PATCH] Bump lightspark-remote-signing version --- Cargo.toml | 2 +- src/lightspark_crypto.udl | 2 +- src/remote_signing.rs | 39 ++++++++++++++++++++++++++------------- 3 files changed, 28 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 949c7b8..a5675a5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,7 @@ console_error_panic_hook = { version = "0.1.6", optional = true } bitcoin = "0.30.1" bip39 = { "version" = "2.0.0", features = ["rand"]} ecies = { "version" = "0.2.6", default-features = false, features = ["pure"]} -lightspark-remote-signing = "0.2.0" +lightspark-remote-signing = "0.3.0" serde_json = "1.0.107" serde = "1.0.188" diff --git a/src/lightspark_crypto.udl b/src/lightspark_crypto.udl index 4b66737..906da28 100644 --- a/src/lightspark_crypto.udl +++ b/src/lightspark_crypto.udl @@ -15,7 +15,7 @@ namespace lightspark_crypto { KeyPair generate_keypair(); [Throws=RemoteSigningError] - RemoteSigningResponse handle_remote_signing_webhook_event( + RemoteSigningResponse? handle_remote_signing_webhook_event( sequence webhook_data, string webhook_signature, string webhook_secret, diff --git a/src/remote_signing.rs b/src/remote_signing.rs index 885f54c..c6cde4e 100644 --- a/src/remote_signing.rs +++ b/src/remote_signing.rs @@ -2,9 +2,9 @@ use std::fmt; use lightspark_remote_signing::{ handler::Handler, + lightspark::{error::Error, webhooks::WebhookEvent}, signer::{LightsparkSigner, Network, Seed}, validation::Validation, - lightspark::{error::Error, webhooks::WebhookEvent}, }; use wasm_bindgen::prelude::*; use wasm_bindgen::{JsError, JsValue}; @@ -78,7 +78,7 @@ pub fn handle_remote_signing_webhook_event( webhook_secret: String, master_seed_bytes: Vec, validation: Box, -) -> Result { +) -> Result, RemoteSigningError> { let webhook_event = WebhookEvent::verify_and_parse(&webhook_data, &webhook_signature, &webhook_secret) .map_err(|e| match e { @@ -105,14 +105,16 @@ pub fn handle_remote_signing_webhook_event( handler .handle_remote_signing_webhook_msg(&webhook_event) .map_err(|_| RemoteSigningError::RemoteSigningHandlerError) - .map(|response| RemoteSigningResponse { - query: response.query, - variables: serde_json::to_string(&response.variables) - .expect("serde value to json should not fail"), + .map(|response| match response { + None => None, + Some(response) => Some(RemoteSigningResponse { + query: response.query, + variables: serde_json::to_string(&response.variables) + .expect("serde value to json should not fail"), + }), }) } - #[wasm_bindgen] extern "C" { pub type WasmValidation; @@ -147,7 +149,7 @@ pub fn wasm_handle_remote_signing_webhook_event( webhook_secret: String, master_seed_bytes: Vec, validation: &WasmValidation, -) -> Result { +) -> Result, RemoteSigningError> { let validation = (*validation).clone(); let validator = WasmValidator::new(WasmValidation { obj: validation }); handle_remote_signing_webhook_event( @@ -156,9 +158,14 @@ pub fn wasm_handle_remote_signing_webhook_event( webhook_secret, master_seed_bytes, Box::new(validator), - ).map(|response| RemoteSigningResponseWasm { - query: response.query, - variables: response.variables, + ) + .map(|response| match response { + None => None, + Some(response) => Some(RemoteSigningResponseWasm { + query: response.query, + variables: serde_json::to_string(&response.variables) + .expect("serde value to json should not fail"), + }), }) } @@ -176,7 +183,13 @@ mod test { let seed = "1a6deac8f74fb2e332677e3f4833b5e962f80d153fb368b8ee322a9caca4113d56cccd88f1c6a74e152669d8cd373fee2f27e3645d80de27640177a8c71395f8"; let master_seed_bytes = hex::decode(seed).unwrap(); let validator = Box::new(PositiveValidator); - let response = handle_remote_signing_webhook_event(webhook_data_string.as_bytes().to_vec(), sig.to_owned(), sec.to_owned(), master_seed_bytes, validator); + let response = handle_remote_signing_webhook_event( + webhook_data_string.as_bytes().to_vec(), + sig.to_owned(), + sec.to_owned(), + master_seed_bytes, + validator, + ); assert!(response.is_ok()); } -} \ No newline at end of file +}