From 2b276b1924c18b14373927be3a70674af95f267d Mon Sep 17 00:00:00 2001 From: Corey Martin Date: Mon, 25 Sep 2023 18:00:16 -0700 Subject: [PATCH] Add a couple wasm bindgens and fix warnings --- src/lib.rs | 10 ++++++++++ src/remote_signing.rs | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 88d0068..c276c25 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,15 +2,25 @@ pub mod crypto; pub mod remote_signing; pub mod signer; +#[cfg(not(target_arch = "wasm32"))] use crypto::decrypt_ecies; +#[cfg(not(target_arch = "wasm32"))] use crypto::encrypt_ecies; +#[cfg(not(target_arch = "wasm32"))] use crypto::generate_keypair; +#[cfg(not(target_arch = "wasm32"))] use crypto::sign_ecdsa; +#[cfg(not(target_arch = "wasm32"))] use crypto::verify_ecdsa; +#[cfg(not(target_arch = "wasm32"))] use crypto::CryptoError; +#[cfg(not(target_arch = "wasm32"))] use lightspark_remote_signing::validation::Validation; +#[cfg(not(target_arch = "wasm32"))] use remote_signing::handle_remote_signing_webhook_event; +#[cfg(not(target_arch = "wasm32"))] use remote_signing::RemoteSigningError; +#[cfg(not(target_arch = "wasm32"))] use remote_signing::RemoteSigningResponse; #[cfg(not(target_arch = "wasm32"))] diff --git a/src/remote_signing.rs b/src/remote_signing.rs index 0bc843a..6710d51 100644 --- a/src/remote_signing.rs +++ b/src/remote_signing.rs @@ -6,12 +6,15 @@ use lightspark_remote_signing::{ signer::{LightsparkSigner, Network, Seed}, validation::Validation, }; +use wasm_bindgen::prelude::*; +use wasm_bindgen::{JsError, JsValue}; pub struct RemoteSigningResponse { pub query: String, pub variables: String, } +#[wasm_bindgen] #[derive(Clone, Copy, Debug)] pub enum RemoteSigningError { WebhookParsingError, @@ -31,6 +34,14 @@ impl fmt::Display for RemoteSigningError { } } +impl std::error::Error for RemoteSigningError {} + +impl From for JsValue { + fn from(val: RemoteSigningError) -> Self { + JsError::from(val).into() + } +} + pub fn handle_remote_signing_webhook_event( webhook_data: Vec, webhook_signature: String,