Skip to content

Commit

Permalink
Bump lightspark-remote-signing version
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenlu committed Nov 1, 2023
1 parent 3d8ed37 commit f721554
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion src/lightspark_crypto.udl
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8> webhook_data,
string webhook_signature,
string webhook_secret,
Expand Down
39 changes: 26 additions & 13 deletions src/remote_signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -78,7 +78,7 @@ pub fn handle_remote_signing_webhook_event(
webhook_secret: String,
master_seed_bytes: Vec<u8>,
validation: Box<dyn Validation>,
) -> Result<RemoteSigningResponse, RemoteSigningError> {
) -> Result<Option<RemoteSigningResponse>, RemoteSigningError> {
let webhook_event =
WebhookEvent::verify_and_parse(&webhook_data, &webhook_signature, &webhook_secret)
.map_err(|e| match e {
Expand All @@ -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;
Expand Down Expand Up @@ -147,7 +149,7 @@ pub fn wasm_handle_remote_signing_webhook_event(
webhook_secret: String,
master_seed_bytes: Vec<u8>,
validation: &WasmValidation,
) -> Result<RemoteSigningResponseWasm, RemoteSigningError> {
) -> Result<Option<RemoteSigningResponseWasm>, RemoteSigningError> {
let validation = (*validation).clone();
let validator = WasmValidator::new(WasmValidation { obj: validation });
handle_remote_signing_webhook_event(
Expand All @@ -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"),
}),
})
}

Expand All @@ -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());
}
}
}

0 comments on commit f721554

Please sign in to comment.