diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d79aebe9..ecc520bd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -207,7 +207,6 @@ jobs: -p cdk, -p cdk --no-default-features, -p cdk --no-default-features --features wallet, - -p cdk-js, ] steps: - name: checkout diff --git a/Cargo.toml b/Cargo.toml index 9f6a4890..55c4c76c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,5 @@ [workspace] members = [ - "bindings/cdk-js", "crates/*", ] resolver = "2" diff --git a/README.md b/README.md index 5ff08b49..60dc9f1b 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ The project is split up into several crates in the `crates/` directory: ## Bindings -Experimental bindings can be found in the [bindings](./bindings/) folder. +Experimental JS bindings can be found in the [bindings repository](https://github.com/thesimplekid/cdk-js). ## License diff --git a/bindings/README.md b/bindings/README.md deleted file mode 100644 index d17392ef..00000000 --- a/bindings/README.md +++ /dev/null @@ -1,4 +0,0 @@ -# CDK Bindings - -Javascript: - [cdk-js](./cdk-js/) javascript bindings for [cdk](../crates/cdk/) diff --git a/bindings/cdk-js/.npmignore b/bindings/cdk-js/.npmignore deleted file mode 100644 index 1147df4e..00000000 --- a/bindings/cdk-js/.npmignore +++ /dev/null @@ -1,12 +0,0 @@ -.cargo/ -target/ -src/ -scripts/ -examples/ -pkg/package.json -pkg/*.md -pkg/*.wasm -.gitignore -Cargo.toml -Cargo.lock -*.tgz diff --git a/bindings/cdk-js/Cargo.toml b/bindings/cdk-js/Cargo.toml deleted file mode 100644 index 83626cbc..00000000 --- a/bindings/cdk-js/Cargo.toml +++ /dev/null @@ -1,25 +0,0 @@ -[package] -name = "cdk-js" -version = "0.4.0" -edition = "2021" -license = "MIT" -homepage = "https://github.com/cashubtc/cdk" -repository = "https://github.com/cashubtc/cdk.git" -rust-version = "1.63.0" # MSRV -description = "Cashu Development Kit JS Bindings" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html -[lib] -crate-type = ["lib", "cdylib"] - -[dependencies] -cdk = { path = "../../crates/cdk", features = ["wallet"] } -cdk-rexie = { path = "../../crates/cdk-rexie", features = ["wallet"] } -console_error_panic_hook = "0.1" -js-sys = "0.3" -serde_json = "1" -serde-wasm-bindgen = "0.6.5" -serde = { version = "1", default-features = false, features = ["derive"] } -wasm-bindgen = { version = "0.2.92", features = ["serde-serialize"] } -wasm-bindgen-futures = "0.4.41" -web-sys = { version = "0.3.69", default-features = false, features = ["console"] } diff --git a/bindings/cdk-js/examples/mint_token.js b/bindings/cdk-js/examples/mint_token.js deleted file mode 100644 index 78deb7bd..00000000 --- a/bindings/cdk-js/examples/mint_token.js +++ /dev/null @@ -1,61 +0,0 @@ -const { - loadWasmAsync, - Wallet, - CurrencyUnit -} = require("../"); - -async function main() { - await loadWasmAsync(); - let seed = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; - let mint_url = "https://testnut.cashu.space"; - let currency = CurrencyUnit.Sat; - - wallet = await new Wallet(seed, []); - - await wallet.addMint(mint_url); - await wallet.refreshMint(mint_url); - - - - let amount = 10; - - let quote = await wallet?.mintQuote($mint_url, BigInt(amount), currency); - let quote_id = quote?.id; - - let invoice = quote?.request; - if (invoice != undefined) { - data = invoice; - } - - let paid = false; - while (paid == false) { - let check_mint = await wallet?.mintQuoteStatus(mint_url, quote_id); - if (check_mint?.paid == true) { - paid = true; - } else { - await new Promise((r) => setTimeout(r, 2000)); - } - - await wallet?.mint( - mint_url, - quote_id, - undefined, - undefined, - undefined, - ); - - let token = await wallet?.send( - mint_url, - currency, - undefined, - BigInt(amount) undefined, - undefined, - ); - - console.log(token); - - - } -} - -main(); diff --git a/bindings/cdk-js/justfile b/bindings/cdk-js/justfile deleted file mode 100644 index b3e6e575..00000000 --- a/bindings/cdk-js/justfile +++ /dev/null @@ -1,3 +0,0 @@ -pack: - rm -rf ./pkg - wasm-pack build --target web diff --git a/bindings/cdk-js/package.json b/bindings/cdk-js/package.json deleted file mode 100644 index 270644be..00000000 --- a/bindings/cdk-js/package.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "name": "@cashudevkit/cdk", - "version": "0.0.0", - "description": "Cashu Dev Kit", - "keywords": [ - "cashu" - "rust", - "bindings", - "javascript" - ], - "license": "MIT", - "homepage": "https://github.com/cashubtc/cdk", - "repository": { - "type": "git", - "url": "git+https://github.com/cashubtc/cdk.git" - }, - "bugs": { - "url": "https://github.com/cashubtc/cdk/issues" - }, - "author": { - "name": "thesimplekid", - "email": "tsk@thesimplekid.com", - "url": "https://github.com/thesimplekid" - }, - "main": "pkg/cdk_js.js", - "types": "pkg/cdk_js.d.ts", - "files": [ - "pkg/cdk_js_bg.wasm.js", - "pkg/cdk_js_bg.wasm.d.ts", - "pkg/cdk_js.js", - "pkg/cdk_js.d.ts" - ], - "devDependencies": { - "wasm-pack": "^0.10.2" - }, - "engines": { - "node": ">= 10" - }, - "scripts": { - "build": "wasm-pack build --target web", - } -} diff --git a/bindings/cdk-js/src/error.rs b/bindings/cdk-js/src/error.rs deleted file mode 100644 index d4e1cb0d..00000000 --- a/bindings/cdk-js/src/error.rs +++ /dev/null @@ -1,12 +0,0 @@ -use wasm_bindgen::JsValue; - -pub type Result = std::result::Result; - -/// Helper to replace the `E` to `Error` to `napi::Error` conversion. -#[inline] -pub fn into_err(error: E) -> JsValue -where - E: std::fmt::Display, -{ - JsValue::from_str(&error.to_string()) -} diff --git a/bindings/cdk-js/src/lib.rs b/bindings/cdk-js/src/lib.rs deleted file mode 100644 index 60c66d60..00000000 --- a/bindings/cdk-js/src/lib.rs +++ /dev/null @@ -1,12 +0,0 @@ -use wasm_bindgen::prelude::*; - -pub mod error; -pub mod nuts; -pub mod types; -#[cfg(target_arch = "wasm32")] -pub mod wallet; - -#[wasm_bindgen(start)] -pub fn start() { - console_error_panic_hook::set_once(); -} diff --git a/bindings/cdk-js/src/nuts/mod.rs b/bindings/cdk-js/src/nuts/mod.rs deleted file mode 100644 index 0e3e30f2..00000000 --- a/bindings/cdk-js/src/nuts/mod.rs +++ /dev/null @@ -1,24 +0,0 @@ -pub mod nut00; -pub mod nut01; -pub mod nut02; -pub mod nut03; -pub mod nut04; -pub mod nut05; -pub mod nut06; -pub mod nut07; -pub mod nut09; -pub mod nut10; -pub mod nut11; -pub mod nut12; -pub mod nut14; - -pub use nut00::*; -pub use nut01::{JsKeys, JsPublicKey, JsSecretKey}; -pub use nut02::JsId; -pub use nut03::{JsSwapRequest, JsSwapResponse}; -pub use nut06::{JsMintInfo, JsMintVersion}; -pub use nut07::*; -pub use nut09::{JsRestoreRequest, JsRestoreResponse}; -pub use nut11::*; -pub use nut12::{JsBlindSignatureDleq, JsProofDleq}; -pub use nut14::JsHTLCWitness; diff --git a/bindings/cdk-js/src/nuts/nut00/blind_signature.rs b/bindings/cdk-js/src/nuts/nut00/blind_signature.rs deleted file mode 100644 index 31981a53..00000000 --- a/bindings/cdk-js/src/nuts/nut00/blind_signature.rs +++ /dev/null @@ -1,42 +0,0 @@ -use std::ops::Deref; - -use cdk::nuts::BlindSignature; -use wasm_bindgen::prelude::*; - -use crate::nuts::nut01::JsPublicKey; -use crate::nuts::nut02::JsId; -use crate::nuts::JsBlindSignatureDleq; -use crate::types::JsAmount; - -#[wasm_bindgen(js_name = BlindSignature)] -pub struct JsBlindSignature { - inner: BlindSignature, -} - -impl Deref for JsBlindSignature { - type Target = BlindSignature; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -#[wasm_bindgen(js_class = BlindSignature)] -impl JsBlindSignature { - #[allow(clippy::new_without_default)] - #[wasm_bindgen(constructor)] - pub fn new( - keyset_id: JsId, - amount: JsAmount, - c: JsPublicKey, - dleq: Option, - ) -> Self { - Self { - inner: BlindSignature { - keyset_id: *keyset_id.deref(), - amount: *amount.deref(), - c: *c.deref(), - dleq: dleq.map(|b| b.deref().clone()), - }, - } - } -} diff --git a/bindings/cdk-js/src/nuts/nut00/blinded_message.rs b/bindings/cdk-js/src/nuts/nut00/blinded_message.rs deleted file mode 100644 index 92eff5f3..00000000 --- a/bindings/cdk-js/src/nuts/nut00/blinded_message.rs +++ /dev/null @@ -1,71 +0,0 @@ -use std::ops::Deref; - -use cdk::nuts::BlindedMessage; -use wasm_bindgen::prelude::*; - -use super::JsWitness; -use crate::nuts::{JsId, JsPublicKey}; -use crate::types::JsAmount; - -#[wasm_bindgen(js_name = BlindedMessage)] -pub struct JsBlindedMessage { - inner: BlindedMessage, -} - -impl Deref for JsBlindedMessage { - type Target = BlindedMessage; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsBlindedMessage { - fn from(inner: BlindedMessage) -> JsBlindedMessage { - JsBlindedMessage { inner } - } -} - -#[wasm_bindgen(js_class = BlindedMessage)] -impl JsBlindedMessage { - #[allow(clippy::new_without_default)] - #[wasm_bindgen(constructor)] - pub fn new( - keyset_id: JsId, - amount: JsAmount, - blinded_secret: JsPublicKey, - witness: Option, - ) -> Self { - Self { - inner: BlindedMessage { - keyset_id: *keyset_id.deref(), - amount: *amount.deref(), - blinded_secret: *blinded_secret.deref(), - witness: witness.map(|w| w.deref().clone()), - }, - } - } - - /// Keyset Id - #[wasm_bindgen(getter)] - pub fn keyset_id(&self) -> JsId { - self.keyset_id.into() - } - - /// Amount - #[wasm_bindgen(getter)] - pub fn amount(&self) -> JsAmount { - self.inner.amount.into() - } - - /// Blinded Secret - #[wasm_bindgen(getter)] - pub fn blinded_secret(&self) -> JsPublicKey { - self.inner.blinded_secret.into() - } - - /// Witness - #[wasm_bindgen(getter)] - pub fn witness(&self) -> Option { - self.inner.witness.clone().map(|w| w.into()) - } -} diff --git a/bindings/cdk-js/src/nuts/nut00/currency_unit.rs b/bindings/cdk-js/src/nuts/nut00/currency_unit.rs deleted file mode 100644 index 02251de3..00000000 --- a/bindings/cdk-js/src/nuts/nut00/currency_unit.rs +++ /dev/null @@ -1,35 +0,0 @@ -use cdk::nuts::CurrencyUnit; -use wasm_bindgen::prelude::*; - -// use crate::nuts::{JsHTLCWitness, JsP2PKWitness}; - -#[wasm_bindgen(js_name = CurrencyUnit)] -pub enum JsCurrencyUnit { - Sat, - Msat, - Usd, - Eur, -} - -impl From for JsCurrencyUnit { - fn from(inner: CurrencyUnit) -> JsCurrencyUnit { - match inner { - CurrencyUnit::Sat => JsCurrencyUnit::Sat, - CurrencyUnit::Msat => JsCurrencyUnit::Msat, - CurrencyUnit::Usd => JsCurrencyUnit::Usd, - CurrencyUnit::Eur => JsCurrencyUnit::Eur, - _ => panic!("Unsupported unit"), - } - } -} - -impl From for CurrencyUnit { - fn from(inner: JsCurrencyUnit) -> CurrencyUnit { - match inner { - JsCurrencyUnit::Sat => CurrencyUnit::Sat, - JsCurrencyUnit::Msat => CurrencyUnit::Msat, - JsCurrencyUnit::Usd => CurrencyUnit::Usd, - JsCurrencyUnit::Eur => CurrencyUnit::Eur, - } - } -} diff --git a/bindings/cdk-js/src/nuts/nut00/mod.rs b/bindings/cdk-js/src/nuts/nut00/mod.rs deleted file mode 100644 index 17f8d66a..00000000 --- a/bindings/cdk-js/src/nuts/nut00/mod.rs +++ /dev/null @@ -1,14 +0,0 @@ -pub mod blind_signature; -pub mod blinded_message; -pub mod currency_unit; -pub mod premint; -pub mod proof; -pub mod token; -pub mod witness; - -pub use blinded_message::JsBlindedMessage; -pub use currency_unit::JsCurrencyUnit; -pub use premint::{JsPreMint, JsPreMintSecrets}; -pub use proof::JsProof; -pub use token::JsToken; -pub use witness::JsWitness; diff --git a/bindings/cdk-js/src/nuts/nut00/premint.rs b/bindings/cdk-js/src/nuts/nut00/premint.rs deleted file mode 100644 index 9e8f7a82..00000000 --- a/bindings/cdk-js/src/nuts/nut00/premint.rs +++ /dev/null @@ -1,40 +0,0 @@ -use std::ops::Deref; - -use cdk::nuts::{PreMint, PreMintSecrets}; -use wasm_bindgen::prelude::*; - -#[wasm_bindgen(js_name = PreMint)] -pub struct JsPreMint { - inner: PreMint, -} - -impl Deref for JsPreMint { - type Target = PreMint; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsPreMint { - fn from(inner: PreMint) -> JsPreMint { - JsPreMint { inner } - } -} - -#[wasm_bindgen(js_name = PreMintSecrets)] -pub struct JsPreMintSecrets { - inner: PreMintSecrets, -} - -impl Deref for JsPreMintSecrets { - type Target = PreMintSecrets; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsPreMintSecrets { - fn from(inner: PreMintSecrets) -> JsPreMintSecrets { - JsPreMintSecrets { inner } - } -} diff --git a/bindings/cdk-js/src/nuts/nut00/proof.rs b/bindings/cdk-js/src/nuts/nut00/proof.rs deleted file mode 100644 index ac474e48..00000000 --- a/bindings/cdk-js/src/nuts/nut00/proof.rs +++ /dev/null @@ -1,76 +0,0 @@ -use std::ops::Deref; - -use cdk::nuts::Proof; -use wasm_bindgen::prelude::*; - -use super::JsWitness; -use crate::nuts::nut01::JsPublicKey; -use crate::nuts::nut02::JsId; -use crate::nuts::nut12::JsProofDleq; -use crate::types::{JsAmount, JsSecret}; - -#[wasm_bindgen(js_name = Proof)] -pub struct JsProof { - inner: Proof, -} - -impl Deref for JsProof { - type Target = Proof; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsProof { - fn from(inner: Proof) -> JsProof { - JsProof { inner } - } -} - -#[wasm_bindgen(js_class = Proof)] -impl JsProof { - #[wasm_bindgen(constructor)] - pub fn new( - amount: JsAmount, - secret: JsSecret, - c: JsPublicKey, - keyset_id: JsId, - witness: Option, - dleq: Option, - ) -> Self { - Self { - inner: Proof { - amount: *amount.deref(), - secret: secret.deref().clone(), - c: *c.deref(), - keyset_id: *keyset_id.deref(), - witness: witness.map(|w| w.deref().clone()), - dleq: dleq.map(|d| d.deref().clone()), - }, - } - } - - /// Amount - #[wasm_bindgen(getter)] - pub fn amount(&self) -> JsAmount { - self.inner.amount.into() - } - - /// Secret - #[wasm_bindgen(getter)] - pub fn secret(&self) -> JsSecret { - self.inner.secret.clone().into() - } - - /// C - #[wasm_bindgen(getter)] - pub fn c(&self) -> JsPublicKey { - self.inner.c.into() - } - - /// Keyset Id - #[wasm_bindgen(getter)] - pub fn keyset_id(&self) -> JsId { - self.inner.keyset_id.into() - } -} diff --git a/bindings/cdk-js/src/nuts/nut00/token.rs b/bindings/cdk-js/src/nuts/nut00/token.rs deleted file mode 100644 index 051954b8..00000000 --- a/bindings/cdk-js/src/nuts/nut00/token.rs +++ /dev/null @@ -1,35 +0,0 @@ -use std::ops::Deref; -use std::str::FromStr; - -use cdk::nuts::Token; -use wasm_bindgen::prelude::*; - -use crate::error::{into_err, Result}; - -#[wasm_bindgen(js_name = Token)] -pub struct JsToken { - inner: Token, -} - -impl Deref for JsToken { - type Target = Token; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsToken { - fn from(inner: Token) -> JsToken { - JsToken { inner } - } -} - -#[wasm_bindgen(js_class = Token)] -impl JsToken { - #[wasm_bindgen(constructor)] - pub fn new(token: String) -> Result { - Ok(Self { - inner: Token::from_str(&token).map_err(into_err)?, - }) - } -} diff --git a/bindings/cdk-js/src/nuts/nut00/witness.rs b/bindings/cdk-js/src/nuts/nut00/witness.rs deleted file mode 100644 index 8c16481f..00000000 --- a/bindings/cdk-js/src/nuts/nut00/witness.rs +++ /dev/null @@ -1,52 +0,0 @@ -use std::ops::Deref; - -use cdk::nuts::{HTLCWitness, P2PKWitness, Witness}; -use wasm_bindgen::prelude::*; - -use crate::error::Result; - -#[wasm_bindgen(js_name = Witness)] -pub struct JsWitness { - inner: Witness, -} - -impl Deref for JsWitness { - type Target = Witness; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsWitness { - fn from(inner: Witness) -> JsWitness { - JsWitness { inner } - } -} - -#[wasm_bindgen(js_class = Witness)] -impl JsWitness { - #[wasm_bindgen(constructor)] - pub fn new(preimage: Option, signatures: Option>) -> Result { - match preimage { - Some(preimage) => Ok(Witness::HTLCWitness(HTLCWitness { - preimage, - signatures, - }) - .into()), - None => Ok(Witness::P2PKWitness(P2PKWitness { - signatures: signatures.unwrap(), - }) - .into()), - } - } - - #[wasm_bindgen(getter)] - pub fn signatures(&self) -> Option> { - self.inner.signatures() - } - - #[wasm_bindgen(getter)] - pub fn preimage(&self) -> Option { - self.inner.preimage() - } -} diff --git a/bindings/cdk-js/src/nuts/nut01/keys.rs b/bindings/cdk-js/src/nuts/nut01/keys.rs deleted file mode 100644 index e44db08f..00000000 --- a/bindings/cdk-js/src/nuts/nut01/keys.rs +++ /dev/null @@ -1,51 +0,0 @@ -use std::ops::Deref; - -use cdk::nuts::nut01::Keys; -use wasm_bindgen::prelude::*; - -use super::JsPublicKey; -use crate::error::{into_err, Result}; -use crate::types::JsAmount; - -#[wasm_bindgen(js_name = Keys)] -pub struct JsKeys { - inner: Keys, -} - -impl Deref for JsKeys { - type Target = Keys; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsKeys { - fn from(inner: Keys) -> JsKeys { - JsKeys { inner } - } -} - -#[wasm_bindgen(js_class = Keys)] -impl JsKeys { - /// From Hex - #[wasm_bindgen(constructor)] - pub fn new(keys: JsValue) -> Result { - let keys = serde_wasm_bindgen::from_value(keys).map_err(into_err)?; - - Ok(JsKeys { - inner: Keys::new(keys), - }) - } - - /// Keys - #[wasm_bindgen(js_name = keys)] - pub fn keys(&self) -> Result { - serde_wasm_bindgen::to_value(&self.inner.keys()).map_err(into_err) - } - - /// Amount Key - #[wasm_bindgen(js_name = amountKey)] - pub fn amount_key(&self, amount: JsAmount) -> Option { - self.inner.amount_key(*amount.deref()).map(|k| k.into()) - } -} diff --git a/bindings/cdk-js/src/nuts/nut01/mod.rs b/bindings/cdk-js/src/nuts/nut01/mod.rs deleted file mode 100644 index 888a7f89..00000000 --- a/bindings/cdk-js/src/nuts/nut01/mod.rs +++ /dev/null @@ -1,7 +0,0 @@ -pub mod keys; -pub mod public_key; -pub mod secret_key; - -pub use keys::JsKeys; -pub use public_key::JsPublicKey; -pub use secret_key::JsSecretKey; diff --git a/bindings/cdk-js/src/nuts/nut01/public_key.rs b/bindings/cdk-js/src/nuts/nut01/public_key.rs deleted file mode 100644 index 7fb3440a..00000000 --- a/bindings/cdk-js/src/nuts/nut01/public_key.rs +++ /dev/null @@ -1,41 +0,0 @@ -use std::ops::Deref; - -use cdk::nuts::nut01::PublicKey; -use wasm_bindgen::prelude::*; - -use crate::error::{into_err, Result}; - -#[wasm_bindgen(js_name = PublicKey)] -pub struct JsPublicKey { - inner: PublicKey, -} - -impl Deref for JsPublicKey { - type Target = PublicKey; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsPublicKey { - fn from(inner: PublicKey) -> JsPublicKey { - JsPublicKey { inner } - } -} - -#[wasm_bindgen(js_class = PublicKey)] -impl JsPublicKey { - /// From Hex - #[wasm_bindgen(js_name = fromHex)] - pub fn from_hex(hex: String) -> Result { - Ok(Self { - inner: PublicKey::from_hex(hex).map_err(into_err)?, - }) - } - - /// To Hex - #[wasm_bindgen(js_name = toHex)] - pub fn to_hex(&self) -> String { - self.inner.to_hex() - } -} diff --git a/bindings/cdk-js/src/nuts/nut01/secret_key.rs b/bindings/cdk-js/src/nuts/nut01/secret_key.rs deleted file mode 100644 index 6bd7180c..00000000 --- a/bindings/cdk-js/src/nuts/nut01/secret_key.rs +++ /dev/null @@ -1,31 +0,0 @@ -use std::ops::Deref; - -use cdk::nuts::nut01::SecretKey; -use wasm_bindgen::prelude::*; - -#[wasm_bindgen(js_name = SecretKey)] -pub struct JsSecretKey { - inner: SecretKey, -} - -impl Deref for JsSecretKey { - type Target = SecretKey; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsSecretKey { - fn from(inner: SecretKey) -> JsSecretKey { - JsSecretKey { inner } - } -} - -#[wasm_bindgen(js_class = SecretKey)] -impl JsSecretKey { - /// To Hex - #[wasm_bindgen(js_name = toHex)] - pub fn to_hex(&self) -> String { - self.inner.to_secret_hex() - } -} diff --git a/bindings/cdk-js/src/nuts/nut02/id.rs b/bindings/cdk-js/src/nuts/nut02/id.rs deleted file mode 100644 index d0044ae2..00000000 --- a/bindings/cdk-js/src/nuts/nut02/id.rs +++ /dev/null @@ -1,42 +0,0 @@ -use std::ops::Deref; -use std::str::FromStr; - -use cdk::nuts::Id; -use wasm_bindgen::prelude::*; - -use crate::error::{into_err, Result}; - -#[wasm_bindgen(js_name = Id)] -pub struct JsId { - inner: Id, -} - -impl Deref for JsId { - type Target = Id; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsId { - fn from(inner: Id) -> JsId { - JsId { inner } - } -} - -#[wasm_bindgen(js_class = Id)] -impl JsId { - /// Try From Base 64 String - #[wasm_bindgen(js_name = tryFromBase64)] - pub fn try_from_base64(id: String) -> Result { - Ok(JsId { - inner: Id::from_str(&id).map_err(into_err)?, - }) - } - - /// As String - #[wasm_bindgen(js_name = asString)] - pub fn as_string(&self) -> String { - self.inner.to_string() - } -} diff --git a/bindings/cdk-js/src/nuts/nut02/keyset.rs b/bindings/cdk-js/src/nuts/nut02/keyset.rs deleted file mode 100644 index e5f7550d..00000000 --- a/bindings/cdk-js/src/nuts/nut02/keyset.rs +++ /dev/null @@ -1,118 +0,0 @@ -use std::ops::Deref; -use std::str::FromStr; - -use cdk::nuts::{CurrencyUnit, KeySet, KeysResponse, KeysetResponse}; -use wasm_bindgen::prelude::*; - -use super::JsId; -use crate::error::{into_err, Result}; -use crate::nuts::JsKeys; - -#[wasm_bindgen(js_name = KeySet)] -pub struct JsKeySet { - inner: KeySet, -} - -impl Deref for JsKeySet { - type Target = KeySet; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsKeySet { - fn from(inner: KeySet) -> JsKeySet { - JsKeySet { inner } - } -} - -#[wasm_bindgen(js_class = KeyPair)] -impl JsKeySet { - /// From Hex - #[wasm_bindgen(constructor)] - pub fn new(id: JsId, unit: String, keys: JsKeys) -> JsKeySet { - Self { - inner: KeySet { - id: *id.deref(), - unit: CurrencyUnit::from_str(&unit).unwrap(), - keys: keys.deref().clone(), - }, - } - } - - #[wasm_bindgen(getter)] - pub fn id(&self) -> JsId { - self.inner.id.into() - } - - #[wasm_bindgen(getter)] - pub fn keys(&self) -> JsKeys { - self.inner.keys.clone().into() - } -} - -#[wasm_bindgen(js_name = KeySetsResponse)] -pub struct JsKeySetsResponse { - inner: KeysetResponse, -} - -impl Deref for JsKeySetsResponse { - type Target = KeysetResponse; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsKeySetsResponse { - fn from(inner: KeysetResponse) -> JsKeySetsResponse { - JsKeySetsResponse { inner } - } -} - -#[wasm_bindgen(js_class = KeySetsResponse)] -impl JsKeySetsResponse { - #[wasm_bindgen(constructor)] - pub fn new(keysets: JsValue) -> Result { - let response = serde_wasm_bindgen::from_value(keysets).map_err(into_err)?; - Ok(Self { inner: response }) - } - - /// Get KeySets - #[wasm_bindgen(getter)] - pub fn keys(&self) -> Result { - serde_wasm_bindgen::to_value(&self.inner.keysets).map_err(into_err) - } -} - -#[wasm_bindgen(js_name = KeysResponse)] -pub struct JsKeysResponse { - inner: KeysResponse, -} - -impl Deref for JsKeysResponse { - type Target = KeysResponse; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsKeysResponse { - fn from(inner: KeysResponse) -> JsKeysResponse { - JsKeysResponse { inner } - } -} - -#[wasm_bindgen(js_class = KeysResponse)] -impl JsKeysResponse { - #[wasm_bindgen(constructor)] - pub fn new(keysets: JsValue) -> Result { - let response = serde_wasm_bindgen::from_value(keysets).map_err(into_err)?; - Ok(Self { inner: response }) - } - - /// Get Keys - #[wasm_bindgen(getter)] - pub fn keysets(&self) -> Result { - serde_wasm_bindgen::to_value(&self.inner.keysets).map_err(into_err) - } -} diff --git a/bindings/cdk-js/src/nuts/nut02/mod.rs b/bindings/cdk-js/src/nuts/nut02/mod.rs deleted file mode 100644 index e88193dc..00000000 --- a/bindings/cdk-js/src/nuts/nut02/mod.rs +++ /dev/null @@ -1,4 +0,0 @@ -pub mod id; -pub mod keyset; - -pub use id::JsId; diff --git a/bindings/cdk-js/src/nuts/nut03.rs b/bindings/cdk-js/src/nuts/nut03.rs deleted file mode 100644 index 166bb72a..00000000 --- a/bindings/cdk-js/src/nuts/nut03.rs +++ /dev/null @@ -1,107 +0,0 @@ -use std::ops::Deref; - -use cdk::nuts::{SwapRequest, SwapResponse}; -use wasm_bindgen::prelude::*; - -use crate::error::{into_err, Result}; -use crate::types::JsAmount; - -#[wasm_bindgen(js_name = SwapRequest)] -pub struct JsSwapRequest { - inner: SwapRequest, -} - -impl Deref for JsSwapRequest { - type Target = SwapRequest; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsSwapRequest { - fn from(inner: SwapRequest) -> JsSwapRequest { - JsSwapRequest { inner } - } -} - -#[wasm_bindgen(js_class = SwapRequest)] -impl JsSwapRequest { - #[wasm_bindgen(constructor)] - pub fn new(inputs: JsValue, outputs: JsValue) -> Result { - let inputs = serde_wasm_bindgen::from_value(inputs).map_err(into_err)?; - let outputs = serde_wasm_bindgen::from_value(outputs).map_err(into_err)?; - - Ok(JsSwapRequest { - inner: SwapRequest { inputs, outputs }, - }) - } - - /// Get Proofs - #[wasm_bindgen(getter)] - pub fn proofs(&self) -> Result { - serde_wasm_bindgen::to_value(&self.inner.inputs).map_err(into_err) - } - - /// Get Outputs - #[wasm_bindgen(getter)] - pub fn outputs(&self) -> Result { - serde_wasm_bindgen::to_value(&self.inner.outputs).map_err(into_err) - } - - /// Proofs Amount - #[wasm_bindgen(js_name = proofsAmount)] - pub fn proofs_amount(&self) -> JsAmount { - self.inner.input_amount().expect("Amount overflow").into() - } - - /// Output Amount - #[wasm_bindgen(js_name = outputAmount)] - pub fn output_amount(&self) -> JsAmount { - self.inner.output_amount().expect("Amount overflow").into() - } -} - -#[wasm_bindgen(js_name = SplitResponse)] -pub struct JsSwapResponse { - inner: SwapResponse, -} - -impl Deref for JsSwapResponse { - type Target = SwapResponse; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsSwapResponse { - fn from(inner: SwapResponse) -> JsSwapResponse { - JsSwapResponse { inner } - } -} - -#[wasm_bindgen(js_class = SplitResponse)] -impl JsSwapResponse { - #[wasm_bindgen(constructor)] - pub fn new(signatures: JsValue) -> Result { - let signatures = serde_wasm_bindgen::from_value(signatures).map_err(into_err)?; - - Ok(JsSwapResponse { - inner: SwapResponse { signatures }, - }) - } - - /// Get Promises - #[wasm_bindgen(getter)] - pub fn signatures(&self) -> Result { - serde_wasm_bindgen::to_value(&self.inner.signatures).map_err(into_err) - } - - /// Promises Amount - #[wasm_bindgen(js_name = promisesAmount)] - pub fn promises_amount(&self) -> JsAmount { - self.inner - .promises_amount() - .expect("Amount overflow") - .into() - } -} diff --git a/bindings/cdk-js/src/nuts/nut04.rs b/bindings/cdk-js/src/nuts/nut04.rs deleted file mode 100644 index 6cbdb33c..00000000 --- a/bindings/cdk-js/src/nuts/nut04.rs +++ /dev/null @@ -1,178 +0,0 @@ -use std::ops::Deref; - -use cdk::nuts::nut04::{MintBolt11Request, MintBolt11Response, MintMethodSettings, Settings}; -use cdk::nuts::{MintQuoteBolt11Request, MintQuoteBolt11Response}; -use wasm_bindgen::prelude::*; - -use crate::error::{into_err, Result}; -use crate::types::JsAmount; - -#[wasm_bindgen(js_name = MintQuoteBolt11Request)] -pub struct JsMintQuoteBolt11Request { - inner: MintQuoteBolt11Request, -} - -impl Deref for JsMintQuoteBolt11Request { - type Target = MintQuoteBolt11Request; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsMintQuoteBolt11Request { - fn from(inner: MintQuoteBolt11Request) -> JsMintQuoteBolt11Request { - JsMintQuoteBolt11Request { inner } - } -} - -#[wasm_bindgen(js_name = MintQuoteBolt11Response)] -pub struct JsMintQuoteBolt11Response { - inner: MintQuoteBolt11Response, -} - -impl Deref for JsMintQuoteBolt11Response { - type Target = MintQuoteBolt11Response; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsMintQuoteBolt11Response { - fn from(inner: MintQuoteBolt11Response) -> JsMintQuoteBolt11Response { - JsMintQuoteBolt11Response { inner } - } -} - -#[wasm_bindgen(js_class = MintQuoteBolt11Response)] -impl JsMintQuoteBolt11Response { - #[wasm_bindgen(getter)] - pub fn state(&self) -> String { - self.inner.state.to_string() - } - - #[wasm_bindgen(getter)] - pub fn quote(&self) -> String { - self.inner.quote.clone() - } - - #[wasm_bindgen(getter)] - pub fn request(&self) -> String { - self.inner.request.clone() - } - - #[wasm_bindgen(getter)] - pub fn expiry(&self) -> Option { - self.inner.expiry - } -} - -#[wasm_bindgen(js_name = MintBolt11Request)] -pub struct JsMintBolt11Request { - inner: MintBolt11Request, -} - -impl Deref for JsMintBolt11Request { - type Target = MintBolt11Request; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsMintBolt11Request { - fn from(inner: MintBolt11Request) -> JsMintBolt11Request { - JsMintBolt11Request { inner } - } -} - -#[wasm_bindgen(js_class = MintBolt11Request)] -impl JsMintBolt11Request { - /// Try From Base 64 String - #[wasm_bindgen(constructor)] - pub fn new(quote: String, outputs: JsValue) -> Result { - let outputs = serde_wasm_bindgen::from_value(outputs).map_err(into_err)?; - Ok(JsMintBolt11Request { - inner: MintBolt11Request { quote, outputs }, - }) - } - - #[wasm_bindgen(getter)] - pub fn outputs(&self) -> Result { - serde_wasm_bindgen::to_value(&self.inner.outputs).map_err(into_err) - } - - #[wasm_bindgen(js_name = totalAmount)] - pub fn total_amount(&self) -> JsAmount { - self.inner.total_amount().expect("Amount overflow").into() - } -} - -#[wasm_bindgen(js_name = PostMintResponse)] -pub struct JsMintBolt11Response { - inner: MintBolt11Response, -} - -impl Deref for JsMintBolt11Response { - type Target = MintBolt11Response; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsMintBolt11Response { - fn from(inner: MintBolt11Response) -> JsMintBolt11Response { - JsMintBolt11Response { inner } - } -} - -#[wasm_bindgen(js_class = PostMintResponse)] -impl JsMintBolt11Response { - /// Try From Base 64 String - #[wasm_bindgen(constructor)] - pub fn new(signatures: JsValue) -> Result { - let signatures = serde_wasm_bindgen::from_value(signatures).map_err(into_err)?; - Ok(JsMintBolt11Response { - inner: MintBolt11Response { signatures }, - }) - } - - #[wasm_bindgen(getter)] - pub fn signatures(&self) -> Result { - serde_wasm_bindgen::to_value(&self.inner.signatures).map_err(into_err) - } -} - -#[wasm_bindgen(js_name = MintMethodSettings)] -pub struct JsMintMethodSettings { - inner: MintMethodSettings, -} - -impl Deref for JsMintMethodSettings { - type Target = MintMethodSettings; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsMintMethodSettings { - fn from(inner: MintMethodSettings) -> JsMintMethodSettings { - JsMintMethodSettings { inner } - } -} - -#[wasm_bindgen(js_name = Settings)] -pub struct JsSettings { - inner: Settings, -} - -impl Deref for JsSettings { - type Target = Settings; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsSettings { - fn from(inner: Settings) -> JsSettings { - JsSettings { inner } - } -} diff --git a/bindings/cdk-js/src/nuts/nut05.rs b/bindings/cdk-js/src/nuts/nut05.rs deleted file mode 100644 index 4767d4a7..00000000 --- a/bindings/cdk-js/src/nuts/nut05.rs +++ /dev/null @@ -1,97 +0,0 @@ -use std::ops::Deref; - -use cdk::nuts::{ - MeltBolt11Request, MeltMethodSettings, MeltQuoteBolt11Request, MeltQuoteBolt11Response, - NUT05Settings, -}; -use wasm_bindgen::prelude::*; - -#[wasm_bindgen(js_name = MeltQuoteBolt11Request)] -pub struct JsMeltQuoteBolt11Request { - inner: MeltQuoteBolt11Request, -} - -impl Deref for JsMeltQuoteBolt11Request { - type Target = MeltQuoteBolt11Request; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsMeltQuoteBolt11Request { - fn from(inner: MeltQuoteBolt11Request) -> JsMeltQuoteBolt11Request { - JsMeltQuoteBolt11Request { inner } - } -} - -#[wasm_bindgen(js_name = MeltQuoteBolt11Response)] -pub struct JsMeltQuoteBolt11Response { - inner: MeltQuoteBolt11Response, -} - -impl Deref for JsMeltQuoteBolt11Response { - type Target = MeltQuoteBolt11Response; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsMeltQuoteBolt11Response { - fn from(inner: MeltQuoteBolt11Response) -> JsMeltQuoteBolt11Response { - JsMeltQuoteBolt11Response { inner } - } -} - -#[wasm_bindgen(js_name = MeltBolt11Request)] -pub struct JsMeltBolt11Request { - inner: MeltBolt11Request, -} - -impl Deref for JsMeltBolt11Request { - type Target = MeltBolt11Request; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsMeltBolt11Request { - fn from(inner: MeltBolt11Request) -> JsMeltBolt11Request { - JsMeltBolt11Request { inner } - } -} - -#[wasm_bindgen(js_name = MeltMethodSettings)] -pub struct JsMeltMethodSettings { - inner: MeltMethodSettings, -} - -impl Deref for JsMeltMethodSettings { - type Target = MeltMethodSettings; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsMeltMethodSettings { - fn from(inner: MeltMethodSettings) -> JsMeltMethodSettings { - JsMeltMethodSettings { inner } - } -} - -#[wasm_bindgen(js_name = Nut05Settings)] -pub struct JsSettings { - inner: NUT05Settings, -} - -impl Deref for JsSettings { - type Target = NUT05Settings; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsSettings { - fn from(inner: NUT05Settings) -> JsSettings { - JsSettings { inner } - } -} diff --git a/bindings/cdk-js/src/nuts/nut06.rs b/bindings/cdk-js/src/nuts/nut06.rs deleted file mode 100644 index 0f5c8888..00000000 --- a/bindings/cdk-js/src/nuts/nut06.rs +++ /dev/null @@ -1,204 +0,0 @@ -use std::ops::Deref; - -use cdk::nuts::nut06::{MintInfo, MintVersion}; -use cdk::nuts::ContactInfo; -use wasm_bindgen::prelude::*; - -use super::nut01::JsPublicKey; -use crate::error::{into_err, Result}; - -#[wasm_bindgen(js_name = MintVersion)] -pub struct JsMintVersion { - inner: MintVersion, -} - -impl Deref for JsMintVersion { - type Target = MintVersion; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsMintVersion { - fn from(inner: MintVersion) -> JsMintVersion { - JsMintVersion { inner } - } -} - -#[wasm_bindgen(js_class = MintVersion)] -impl JsMintVersion { - #[wasm_bindgen(constructor)] - pub fn new(name: String, version: String) -> Result { - Ok(JsMintVersion { - inner: MintVersion { name, version }, - }) - } - - /// Get Name - #[wasm_bindgen(getter)] - pub fn name(&self) -> String { - self.inner.name.clone() - } - - /// Get Version - #[wasm_bindgen(getter)] - pub fn version(&self) -> String { - self.inner.version.clone() - } -} - -#[wasm_bindgen(js_name = MintInfo)] -pub struct JsMintInfo { - inner: MintInfo, -} - -impl Deref for JsMintInfo { - type Target = MintInfo; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsMintInfo { - fn from(inner: MintInfo) -> JsMintInfo { - JsMintInfo { inner } - } -} - -#[wasm_bindgen(js_class = MintInfo)] -impl JsMintInfo { - #[wasm_bindgen(constructor)] - #[allow(clippy::too_many_arguments)] - pub fn new( - name: Option, - pubkey: Option, - version: Option, - description: Option, - description_long: Option, - contact: Option>, - nuts: JsValue, - icon_url: Option, - urls: Option>, - motd: Option, - time: Option, - ) -> Result { - Ok(JsMintInfo { - inner: MintInfo { - name, - pubkey: pubkey.map(|p| *p.deref()), - version: version.map(|v| v.deref().clone()), - description, - description_long, - contact: contact - .map(|contacts| contacts.iter().map(|c| c.deref().clone()).collect()), - nuts: serde_wasm_bindgen::from_value(nuts).map_err(into_err)?, - icon_url, - urls, - motd, - time, - }, - }) - } - - /// Get Name - #[wasm_bindgen(getter)] - pub fn name(&self) -> Option { - self.inner.name.clone() - } - - /// Get Pubkey - #[wasm_bindgen(getter)] - pub fn pubkey(&self) -> Option { - self.inner.pubkey.map(|p| p.into()) - } - - /// Get Version - #[wasm_bindgen(getter)] - pub fn version(&self) -> Option { - self.inner.version.clone().map(|v| v.into()) - } - - /// Get description - #[wasm_bindgen(getter)] - pub fn description(&self) -> Option { - self.inner.description.clone() - } - - /// Get description long - #[wasm_bindgen(getter)] - pub fn description_long(&self) -> Option { - self.inner.description_long.clone() - } - - /// Get contact info - #[wasm_bindgen(getter)] - pub fn contact(&self) -> Option> { - self.inner - .contact - .clone() - .map(|c| c.into_iter().map(|c| c.into()).collect()) - } - - /// Get supported nuts - #[wasm_bindgen(getter)] - pub fn nuts(&self) -> Result { - serde_wasm_bindgen::to_value(&self.inner.nuts).map_err(into_err) - } - - /// Get mint icon url - #[wasm_bindgen(getter)] - pub fn icon_url(&self) -> Option { - self.inner.icon_url.clone() - } - - /// Get motd - #[wasm_bindgen(getter)] - pub fn motd(&self) -> Option { - self.inner.motd.clone() - } - - /// Get time - #[wasm_bindgen(getter)] - pub fn time(&self) -> Option { - self.inner.time - } -} - -#[wasm_bindgen(js_name = ContactInfo)] -pub struct JsContactInfo { - inner: ContactInfo, -} - -impl Deref for JsContactInfo { - type Target = ContactInfo; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsContactInfo { - fn from(inner: ContactInfo) -> JsContactInfo { - JsContactInfo { inner } - } -} - -#[wasm_bindgen(js_class = ContactInfo)] -impl JsContactInfo { - #[wasm_bindgen(constructor)] - pub fn new(method: String, info: String) -> Result { - Ok(JsContactInfo { - inner: ContactInfo { method, info }, - }) - } - /// Method - #[wasm_bindgen(getter)] - pub fn method(&self) -> String { - self.inner.method.clone() - } - - /// Info - #[wasm_bindgen(getter)] - pub fn info(&self) -> String { - self.inner.info.clone() - } -} diff --git a/bindings/cdk-js/src/nuts/nut07.rs b/bindings/cdk-js/src/nuts/nut07.rs deleted file mode 100644 index a5129f2d..00000000 --- a/bindings/cdk-js/src/nuts/nut07.rs +++ /dev/null @@ -1,88 +0,0 @@ -use std::ops::Deref; - -use cdk::nuts::{CheckStateRequest, CheckStateResponse, ProofState, State}; -use wasm_bindgen::prelude::*; - -#[wasm_bindgen(js_name = State)] -pub enum JsState { - Spent, - Unspent, - Pending, - Reserved, -} - -impl From for JsState { - fn from(inner: State) -> JsState { - match inner { - State::Spent => JsState::Spent, - State::Unspent => JsState::Unspent, - State::Pending => JsState::Pending, - State::Reserved => JsState::Reserved, - } - } -} - -impl From for State { - fn from(inner: JsState) -> State { - match inner { - JsState::Spent => State::Spent, - JsState::Unspent => State::Unspent, - JsState::Pending => State::Pending, - JsState::Reserved => State::Reserved, - } - } -} - -#[wasm_bindgen(js_name = CheckStateRequest)] -pub struct JsCheckStateRequest { - inner: CheckStateRequest, -} - -impl Deref for JsCheckStateRequest { - type Target = CheckStateRequest; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsCheckStateRequest { - fn from(inner: CheckStateRequest) -> JsCheckStateRequest { - JsCheckStateRequest { inner } - } -} - -#[wasm_bindgen(js_name = ProofState)] -pub struct JsProofState { - inner: ProofState, -} - -impl Deref for JsProofState { - type Target = ProofState; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsProofState { - fn from(inner: ProofState) -> JsProofState { - JsProofState { inner } - } -} - -#[wasm_bindgen(js_name = CheckStateResponse)] -pub struct JsCheckStateResponse { - inner: CheckStateResponse, -} - -impl Deref for JsCheckStateResponse { - type Target = CheckStateResponse; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsCheckStateResponse { - fn from(inner: CheckStateResponse) -> JsCheckStateResponse { - JsCheckStateResponse { inner } - } -} diff --git a/bindings/cdk-js/src/nuts/nut09.rs b/bindings/cdk-js/src/nuts/nut09.rs deleted file mode 100644 index ead4690b..00000000 --- a/bindings/cdk-js/src/nuts/nut09.rs +++ /dev/null @@ -1,40 +0,0 @@ -use std::ops::Deref; - -use cdk::nuts::{RestoreRequest, RestoreResponse}; -use wasm_bindgen::prelude::*; - -#[wasm_bindgen(js_name = RestoreRequest)] -pub struct JsRestoreRequest { - inner: RestoreRequest, -} - -impl Deref for JsRestoreRequest { - type Target = RestoreRequest; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsRestoreRequest { - fn from(inner: RestoreRequest) -> JsRestoreRequest { - JsRestoreRequest { inner } - } -} - -#[wasm_bindgen(js_name = RestoreResponse)] -pub struct JsRestoreResponse { - inner: RestoreResponse, -} - -impl Deref for JsRestoreResponse { - type Target = RestoreResponse; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsRestoreResponse { - fn from(inner: RestoreResponse) -> JsRestoreResponse { - JsRestoreResponse { inner } - } -} diff --git a/bindings/cdk-js/src/nuts/nut10.rs b/bindings/cdk-js/src/nuts/nut10.rs deleted file mode 100644 index 06f99aba..00000000 --- a/bindings/cdk-js/src/nuts/nut10.rs +++ /dev/null @@ -1,64 +0,0 @@ -use std::ops::Deref; - -use cdk::nuts::{Kind, Nut10Secret, SecretData}; -use wasm_bindgen::prelude::*; - -#[wasm_bindgen(js_name = Kind)] -pub enum JsKind { - P2PK, - HTLC, -} - -impl From for JsKind { - fn from(inner: Kind) -> JsKind { - match inner { - Kind::P2PK => JsKind::P2PK, - Kind::HTLC => JsKind::HTLC, - } - } -} - -impl From for Kind { - fn from(inner: JsKind) -> Kind { - match inner { - JsKind::P2PK => Kind::P2PK, - JsKind::HTLC => Kind::HTLC, - } - } -} - -#[wasm_bindgen(js_name = SecretData)] -pub struct JsSecretData { - inner: SecretData, -} - -impl Deref for JsSecretData { - type Target = SecretData; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsSecretData { - fn from(inner: SecretData) -> JsSecretData { - JsSecretData { inner } - } -} - -#[wasm_bindgen(js_name = Nut10Secret)] -pub struct JsNut10Secret { - inner: Nut10Secret, -} - -impl Deref for JsNut10Secret { - type Target = Nut10Secret; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsNut10Secret { - fn from(inner: Nut10Secret) -> JsNut10Secret { - JsNut10Secret { inner } - } -} diff --git a/bindings/cdk-js/src/nuts/nut11.rs b/bindings/cdk-js/src/nuts/nut11.rs deleted file mode 100644 index ca2cd3df..00000000 --- a/bindings/cdk-js/src/nuts/nut11.rs +++ /dev/null @@ -1,120 +0,0 @@ -use std::ops::Deref; -use std::str::FromStr; - -use cdk::nuts::{Conditions, P2PKWitness, PublicKey, SigFlag, SpendingConditions}; -use wasm_bindgen::prelude::*; - -use crate::error::{into_err, Result}; - -#[wasm_bindgen(js_name = P2PKWitness)] -pub struct JsP2PKWitness { - inner: P2PKWitness, -} - -impl Deref for JsP2PKWitness { - type Target = P2PKWitness; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsP2PKWitness { - fn from(inner: P2PKWitness) -> JsP2PKWitness { - JsP2PKWitness { inner } - } -} - -#[wasm_bindgen(js_name = P2PKSpendingConditions)] -pub struct JsP2PKSpendingConditions { - inner: SpendingConditions, -} - -impl Deref for JsP2PKSpendingConditions { - type Target = SpendingConditions; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -#[wasm_bindgen(js_class = P2PKSpendingConditions)] -impl JsP2PKSpendingConditions { - #[wasm_bindgen(constructor)] - pub fn new( - pubkey: String, - conditions: Option, - ) -> Result { - let pubkey = PublicKey::from_str(&pubkey).map_err(into_err)?; - Ok(Self { - inner: SpendingConditions::new_p2pk(pubkey, conditions.map(|c| c.deref().clone())), - }) - } -} - -#[wasm_bindgen(js_name = Conditions)] -pub struct JsConditions { - inner: Conditions, -} - -impl Deref for JsConditions { - type Target = Conditions; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsConditions { - fn from(inner: Conditions) -> JsConditions { - JsConditions { inner } - } -} - -#[wasm_bindgen(js_class = Conditions)] -impl JsConditions { - #[wasm_bindgen(constructor)] - pub fn new( - locktime: Option, - pubkeys: JsValue, - refund_key: JsValue, - num_sigs: Option, - sig_flag: String, - ) -> Result { - let pubkeys: Result, _> = serde_wasm_bindgen::from_value(pubkeys); - let refund_key: Result, _> = serde_wasm_bindgen::from_value(refund_key); - - Ok(Self { - inner: Conditions::new( - locktime, - pubkeys.ok(), - refund_key.ok(), - num_sigs, - Some(SigFlag::from_str(&sig_flag).unwrap_or_default()), - ) - .map_err(into_err)?, - }) - } - - #[wasm_bindgen(getter)] - pub fn locktime(&self) -> Option { - self.inner.locktime - } - - #[wasm_bindgen(getter)] - pub fn pubkeys(&self) -> Result { - Ok(serde_wasm_bindgen::to_value(&self.inner.pubkeys)?) - } - - #[wasm_bindgen(getter)] - pub fn refund_keys(&self) -> Result { - Ok(serde_wasm_bindgen::to_value(&self.inner.refund_keys)?) - } - - #[wasm_bindgen(getter)] - pub fn num_sigs(&self) -> Option { - self.inner.num_sigs - } - - #[wasm_bindgen(getter)] - pub fn sig_flag(&self) -> String { - self.inner.sig_flag.to_string() - } -} diff --git a/bindings/cdk-js/src/nuts/nut12.rs b/bindings/cdk-js/src/nuts/nut12.rs deleted file mode 100644 index 22961437..00000000 --- a/bindings/cdk-js/src/nuts/nut12.rs +++ /dev/null @@ -1,99 +0,0 @@ -use std::ops::Deref; - -use cdk::nuts::{BlindSignatureDleq, ProofDleq}; -use wasm_bindgen::prelude::*; - -use crate::nuts::JsSecretKey; - -#[wasm_bindgen(js_name = BlindSignatureDleq)] -pub struct JsBlindSignatureDleq { - inner: BlindSignatureDleq, -} - -#[wasm_bindgen(js_class = BlindedSignatureDleq)] -impl JsBlindSignatureDleq { - #[wasm_bindgen(constructor)] - pub fn new(e: JsSecretKey, s: JsSecretKey) -> Self { - Self { - inner: BlindSignatureDleq { - e: e.deref().clone(), - s: s.deref().clone(), - }, - } - } - - /// e - #[wasm_bindgen(getter)] - pub fn e(&self) -> JsSecretKey { - self.inner.e.clone().into() - } - - /// s - #[wasm_bindgen(getter)] - pub fn s(&self) -> JsSecretKey { - self.inner.s.clone().into() - } -} - -impl Deref for JsBlindSignatureDleq { - type Target = BlindSignatureDleq; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsBlindSignatureDleq { - fn from(inner: BlindSignatureDleq) -> JsBlindSignatureDleq { - JsBlindSignatureDleq { inner } - } -} - -#[wasm_bindgen(js_name = ProofDleq)] -pub struct JsProofDleq { - inner: ProofDleq, -} - -#[wasm_bindgen(js_class = ProofDleq)] -impl JsProofDleq { - #[wasm_bindgen(constructor)] - pub fn new(e: JsSecretKey, s: JsSecretKey, r: JsSecretKey) -> Self { - Self { - inner: ProofDleq { - e: e.deref().clone(), - s: s.deref().clone(), - r: r.deref().clone(), - }, - } - } - - /// e - #[wasm_bindgen(getter)] - pub fn e(&self) -> JsSecretKey { - self.inner.e.clone().into() - } - - /// s - #[wasm_bindgen(getter)] - pub fn s(&self) -> JsSecretKey { - self.inner.s.clone().into() - } - - /// r - #[wasm_bindgen(getter)] - pub fn r(&self) -> JsSecretKey { - self.inner.r.clone().into() - } -} - -impl Deref for JsProofDleq { - type Target = ProofDleq; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsProofDleq { - fn from(inner: ProofDleq) -> JsProofDleq { - JsProofDleq { inner } - } -} diff --git a/bindings/cdk-js/src/nuts/nut14.rs b/bindings/cdk-js/src/nuts/nut14.rs deleted file mode 100644 index 7ff17b47..00000000 --- a/bindings/cdk-js/src/nuts/nut14.rs +++ /dev/null @@ -1,51 +0,0 @@ -use std::ops::Deref; - -use cdk::nuts::{HTLCWitness, SpendingConditions}; -use wasm_bindgen::prelude::*; - -use super::JsConditions; -use crate::error::{into_err, Result}; - -#[wasm_bindgen(js_name = HTLCWitness)] -pub struct JsHTLCWitness { - inner: HTLCWitness, -} - -impl Deref for JsHTLCWitness { - type Target = HTLCWitness; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsHTLCWitness { - fn from(inner: HTLCWitness) -> JsHTLCWitness { - JsHTLCWitness { inner } - } -} - -#[wasm_bindgen(js_name = HTLCSpendingConditions)] -pub struct JsHTLCSpendingConditions { - inner: SpendingConditions, -} - -impl Deref for JsHTLCSpendingConditions { - type Target = SpendingConditions; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -#[wasm_bindgen(js_class = HTLCSpendingConditions)] -impl JsHTLCSpendingConditions { - #[wasm_bindgen(constructor)] - pub fn new( - preimage: String, - conditions: Option, - ) -> Result { - Ok(Self { - inner: SpendingConditions::new_htlc(preimage, conditions.map(|c| c.deref().clone())) - .map_err(into_err)?, - }) - } -} diff --git a/bindings/cdk-js/src/types/amount.rs b/bindings/cdk-js/src/types/amount.rs deleted file mode 100644 index 3a7e17d0..00000000 --- a/bindings/cdk-js/src/types/amount.rs +++ /dev/null @@ -1,53 +0,0 @@ -use std::ops::Deref; - -use cdk::Amount; -use wasm_bindgen::prelude::*; - -use crate::error::{into_err, Result}; - -#[wasm_bindgen(js_name = Amount)] -pub struct JsAmount { - inner: Amount, -} - -impl Deref for JsAmount { - type Target = Amount; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsAmount { - fn from(inner: Amount) -> JsAmount { - JsAmount { inner } - } -} - -impl From for JsAmount { - fn from(amount: u64) -> JsAmount { - JsAmount { - inner: Amount::from(amount), - } - } -} - -#[wasm_bindgen(js_class = Amount)] -impl JsAmount { - #[wasm_bindgen(constructor)] - pub fn new(sats: u64) -> Self { - Self { - inner: Amount::from(sats), - } - } - - /// Split amount returns sat vec of sats - #[wasm_bindgen(js_name = split)] - pub fn split(&self) -> Result { - serde_wasm_bindgen::to_value(&self.inner.split()).map_err(into_err) - } - - #[wasm_bindgen(getter)] - pub fn value(&self) -> u64 { - self.inner.into() - } -} diff --git a/bindings/cdk-js/src/types/melt_quote.rs b/bindings/cdk-js/src/types/melt_quote.rs deleted file mode 100644 index c00ac8b7..00000000 --- a/bindings/cdk-js/src/types/melt_quote.rs +++ /dev/null @@ -1,63 +0,0 @@ -use std::ops::Deref; - -use cdk::wallet::types::MeltQuote; -use wasm_bindgen::prelude::*; - -use crate::nuts::JsCurrencyUnit; -use crate::types::JsAmount; - -#[wasm_bindgen(js_name = MeltQuote)] -pub struct JsMeltQuote { - inner: MeltQuote, -} - -impl Deref for JsMeltQuote { - type Target = MeltQuote; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsMeltQuote { - fn from(inner: MeltQuote) -> JsMeltQuote { - JsMeltQuote { inner } - } -} - -#[wasm_bindgen(js_class = MeltQuote)] -impl JsMeltQuote { - #[wasm_bindgen(getter)] - pub fn id(&self) -> String { - self.inner.id.clone() - } - - #[wasm_bindgen(getter)] - pub fn unit(&self) -> JsCurrencyUnit { - self.inner.unit.clone().into() - } - - #[wasm_bindgen(getter)] - pub fn amount(&self) -> JsAmount { - self.inner.amount.into() - } - - #[wasm_bindgen(getter)] - pub fn request(&self) -> String { - self.inner.request.clone() - } - - #[wasm_bindgen(getter)] - pub fn fee_reserve(&self) -> JsAmount { - self.inner.fee_reserve.into() - } - - #[wasm_bindgen(getter)] - pub fn state(&self) -> String { - self.inner.state.to_string() - } - - #[wasm_bindgen(getter)] - pub fn expiry(&self) -> u64 { - self.inner.expiry - } -} diff --git a/bindings/cdk-js/src/types/melted.rs b/bindings/cdk-js/src/types/melted.rs deleted file mode 100644 index 2cbccb57..00000000 --- a/bindings/cdk-js/src/types/melted.rs +++ /dev/null @@ -1,42 +0,0 @@ -use std::ops::Deref; - -use cdk::types::Melted; -use wasm_bindgen::prelude::*; - -use crate::error::Result; - -#[wasm_bindgen(js_name = Melted)] -pub struct JsMelted { - inner: Melted, -} - -impl Deref for JsMelted { - type Target = Melted; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsMelted { - fn from(inner: Melted) -> JsMelted { - JsMelted { inner } - } -} - -#[wasm_bindgen(js_class = Melted)] -impl JsMelted { - #[wasm_bindgen(getter)] - pub fn paid(&self) -> String { - self.inner.state.to_string() - } - - #[wasm_bindgen(getter)] - pub fn preimage(&self) -> Option { - self.inner.preimage.clone() - } - - #[wasm_bindgen(getter)] - pub fn change(&self) -> Result { - Ok(serde_wasm_bindgen::to_value(&self.inner.change)?) - } -} diff --git a/bindings/cdk-js/src/types/mint_quote.rs b/bindings/cdk-js/src/types/mint_quote.rs deleted file mode 100644 index ebc7f0d7..00000000 --- a/bindings/cdk-js/src/types/mint_quote.rs +++ /dev/null @@ -1,58 +0,0 @@ -use std::ops::Deref; - -use cdk::wallet::MintQuote; -use wasm_bindgen::prelude::*; - -use crate::nuts::JsCurrencyUnit; -use crate::types::JsAmount; - -#[wasm_bindgen(js_name = MintQuote)] -pub struct JsMintQuote { - inner: MintQuote, -} - -impl Deref for JsMintQuote { - type Target = MintQuote; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsMintQuote { - fn from(inner: MintQuote) -> JsMintQuote { - JsMintQuote { inner } - } -} - -#[wasm_bindgen(js_class = MintQuote)] -impl JsMintQuote { - #[wasm_bindgen(getter)] - pub fn id(&self) -> String { - self.inner.id.clone() - } - - #[wasm_bindgen(getter)] - pub fn unit(&self) -> JsCurrencyUnit { - self.inner.unit.clone().into() - } - - #[wasm_bindgen(getter)] - pub fn amount(&self) -> JsAmount { - self.inner.amount.into() - } - - #[wasm_bindgen(getter)] - pub fn request(&self) -> String { - self.inner.request.clone() - } - - #[wasm_bindgen(getter)] - pub fn state(&self) -> String { - self.inner.state.to_string() - } - - #[wasm_bindgen(getter)] - pub fn expiry(&self) -> u64 { - self.inner.expiry - } -} diff --git a/bindings/cdk-js/src/types/mod.rs b/bindings/cdk-js/src/types/mod.rs deleted file mode 100644 index e27ce7ea..00000000 --- a/bindings/cdk-js/src/types/mod.rs +++ /dev/null @@ -1,11 +0,0 @@ -pub mod amount; -pub mod melt_quote; -pub mod melted; -pub mod mint_quote; -pub mod secret; - -pub use amount::JsAmount; -pub use melt_quote::JsMeltQuote; -pub use melted::JsMelted; -pub use mint_quote::JsMintQuote; -pub use secret::JsSecret; diff --git a/bindings/cdk-js/src/types/secret.rs b/bindings/cdk-js/src/types/secret.rs deleted file mode 100644 index 683a6578..00000000 --- a/bindings/cdk-js/src/types/secret.rs +++ /dev/null @@ -1,44 +0,0 @@ -use std::ops::Deref; - -use cdk::secret::Secret; -use wasm_bindgen::prelude::*; - -#[wasm_bindgen(js_name = Secret)] -pub struct JsSecret { - inner: Secret, -} - -impl Default for JsSecret { - fn default() -> Self { - Self::new() - } -} - -impl Deref for JsSecret { - type Target = Secret; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsSecret { - fn from(inner: Secret) -> JsSecret { - JsSecret { inner } - } -} - -#[wasm_bindgen(js_class = Secret)] -impl JsSecret { - #[wasm_bindgen(constructor)] - pub fn new() -> JsSecret { - Self { - inner: Secret::generate(), - } - } - - /// As Bytes - #[wasm_bindgen(js_name = asBytes)] - pub fn as_bytes(&self) -> Vec { - self.inner.as_bytes().to_vec() - } -} diff --git a/bindings/cdk-js/src/wallet.rs b/bindings/cdk-js/src/wallet.rs deleted file mode 100644 index 8f4cf405..00000000 --- a/bindings/cdk-js/src/wallet.rs +++ /dev/null @@ -1,285 +0,0 @@ -//! Wallet Js Bindings - -use std::ops::Deref; -use std::sync::Arc; - -use cdk::amount::SplitTarget; -use cdk::nuts::{Proofs, SecretKey}; -use cdk::wallet::{SendKind, Wallet}; -use cdk::Amount; -use cdk_rexie::WalletRexieDatabase; -use wasm_bindgen::prelude::*; - -use crate::error::{into_err, Result}; -use crate::nuts::nut01::JsSecretKey; -use crate::nuts::nut04::JsMintQuoteBolt11Response; -use crate::nuts::nut05::JsMeltQuoteBolt11Response; -use crate::nuts::nut11::JsP2PKSpendingConditions; -use crate::nuts::nut14::JsHTLCSpendingConditions; -use crate::nuts::{JsCurrencyUnit, JsMintInfo, JsProof}; -use crate::types::melt_quote::JsMeltQuote; -use crate::types::{JsAmount, JsMelted, JsMintQuote}; - -#[wasm_bindgen(js_name = Wallet)] -pub struct JsWallet { - inner: Wallet, -} - -impl Deref for JsWallet { - type Target = Wallet; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsWallet { - fn from(inner: Wallet) -> JsWallet { - JsWallet { inner } - } -} - -#[wasm_bindgen(js_class = Wallet)] -impl JsWallet { - #[wasm_bindgen(constructor)] - pub async fn new(mints_url: String, unit: JsCurrencyUnit, seed: Vec) -> Result { - let db = WalletRexieDatabase::new().await.unwrap(); - - Ok( - Wallet::new(&mints_url, unit.into(), Arc::new(db), &seed, None) - .map_err(into_err)? - .into(), - ) - } - - #[wasm_bindgen(js_name = totalBalance)] - pub async fn total_balance(&self) -> Result { - Ok(serde_wasm_bindgen::to_value( - &self.inner.total_balance().await.map_err(into_err)?, - )?) - } - - #[wasm_bindgen(js_name = totalPendingBalance)] - pub async fn total_pending_balance(&self) -> Result { - Ok(serde_wasm_bindgen::to_value( - &self.inner.total_pending_balance().await.map_err(into_err)?, - )?) - } - - #[wasm_bindgen(js_name = checkAllPendingProofs)] - pub async fn check_all_pending_proofs(&self) -> Result { - Ok(self - .inner - .check_all_pending_proofs() - .await - .map_err(into_err)? - .into()) - } - - #[wasm_bindgen(js_name = getMintInfo)] - pub async fn get_mint_info(&self) -> Result> { - Ok(self - .inner - .get_mint_info() - .await - .map_err(into_err)? - .map(|i| i.into())) - } - - #[wasm_bindgen(js_name = mintQuote)] - pub async fn mint_quote( - &mut self, - amount: u64, - description: Option, - ) -> Result { - let quote = self - .inner - .mint_quote(amount.into(), description) - .await - .map_err(into_err)?; - - Ok(quote.into()) - } - - #[wasm_bindgen(js_name = mintQuoteStatus)] - pub async fn mint_quote_status(&self, quote_id: String) -> Result { - let quote = self - .inner - .mint_quote_state("e_id) - .await - .map_err(into_err)?; - - Ok(quote.into()) - } - - #[wasm_bindgen(js_name = checkAllMintQuotes)] - pub async fn check_all_mint_quotes(&self) -> Result { - let amount = self.inner.check_all_mint_quotes().await.map_err(into_err)?; - - Ok(amount.into()) - } - - #[wasm_bindgen(js_name = mint)] - pub async fn mint( - &mut self, - quote_id: String, - p2pk_condition: Option, - htlc_condition: Option, - split_target_amount: Option, - ) -> Result { - let target = split_target_amount - .map(|a| SplitTarget::Value(*a.deref())) - .unwrap_or_default(); - let conditions = match (p2pk_condition, htlc_condition) { - (Some(_), Some(_)) => { - return Err(JsValue::from_str( - "Cannot define both p2pk and htlc conditions", - )); - } - (None, Some(htlc_condition)) => Some(htlc_condition.deref().clone()), - (Some(p2pk_condition), None) => Some(p2pk_condition.deref().clone()), - (None, None) => None, - }; - - Ok(self - .inner - .mint("e_id, target, conditions) - .await - .map_err(into_err)? - .into()) - } - - #[wasm_bindgen(js_name = meltQuote)] - pub async fn melt_quote( - &mut self, - request: String, - mpp_amount: Option, - ) -> Result { - let melt_quote = self - .inner - .melt_quote(request, mpp_amount.map(|a| *a.deref())) - .await - .map_err(into_err)?; - - Ok(melt_quote.into()) - } - - #[wasm_bindgen(js_name = meltQuoteStatus)] - pub async fn melt_quote_status(&self, quote_id: String) -> Result { - let quote = self - .inner - .melt_quote_status("e_id) - .await - .map_err(into_err)?; - - Ok(quote.into()) - } - - #[wasm_bindgen(js_name = melt)] - pub async fn melt(&mut self, quote_id: String) -> Result { - let melted = self.inner.melt("e_id).await.map_err(into_err)?; - - Ok(melted.into()) - } - - #[wasm_bindgen(js_name = receive)] - pub async fn receive( - &mut self, - encoded_token: String, - signing_keys: Vec, - preimages: Vec, - ) -> Result { - let signing_keys: Vec = signing_keys.iter().map(|s| s.deref().clone()).collect(); - - Ok(self - .inner - .receive( - &encoded_token, - SplitTarget::default(), - &signing_keys, - &preimages, - ) - .await - .map_err(into_err)? - .into()) - } - - #[allow(clippy::too_many_arguments)] - #[wasm_bindgen(js_name = send)] - pub async fn send( - &mut self, - memo: Option, - amount: u64, - p2pk_condition: Option, - htlc_condition: Option, - split_target_amount: Option, - ) -> Result { - let conditions = match (p2pk_condition, htlc_condition) { - (Some(_), Some(_)) => { - return Err(JsValue::from_str( - "Cannot define both p2pk and htlc conditions", - )); - } - (None, Some(htlc_condition)) => Some(htlc_condition.deref().clone()), - (Some(p2pk_condition), None) => Some(p2pk_condition.deref().clone()), - (None, None) => None, - }; - - let target = split_target_amount - .map(|a| SplitTarget::Value(*a.deref())) - .unwrap_or_default(); - Ok(self - .inner - .send( - Amount::from(amount), - memo, - conditions, - &target, - &SendKind::default(), - false, - ) - .await - .map_err(into_err)? - .to_string()) - } - - #[allow(clippy::too_many_arguments)] - #[wasm_bindgen(js_name = swap)] - pub async fn swap( - &mut self, - amount: u64, - input_proofs: Vec, - p2pk_condition: Option, - htlc_condition: Option, - split_target_amount: Option, - ) -> Result { - let conditions = match (p2pk_condition, htlc_condition) { - (Some(_), Some(_)) => { - return Err(JsValue::from_str( - "Cannot define both p2pk and htlc conditions", - )); - } - (None, Some(htlc_condition)) => Some(htlc_condition.deref().clone()), - (Some(p2pk_condition), None) => Some(p2pk_condition.deref().clone()), - (None, None) => None, - }; - - let proofs: Proofs = input_proofs.iter().map(|p| p.deref()).cloned().collect(); - - let target = split_target_amount - .map(|a| SplitTarget::Value(*a.deref())) - .unwrap_or_default(); - let post_swap_proofs = self - .inner - .swap( - Some(Amount::from(amount)), - target, - proofs, - conditions, - false, - ) - .await - .map_err(into_err)?; - - Ok(serde_wasm_bindgen::to_value(&post_swap_proofs)?) - } -} diff --git a/misc/justfile.custom.just b/misc/justfile.custom.just index 31adf183..f8f35f31 100644 --- a/misc/justfile.custom.just +++ b/misc/justfile.custom.just @@ -11,7 +11,6 @@ check-wasm *ARGS="--target wasm32-unknown-unknown": "-p cdk --no-default-features" "-p cdk --no-default-features --features wallet" "-p cdk --no-default-features --features mint" - "-p cdk-js" ) for arg in "${buildargs[@]}"; do