chore: remove bindings from cdk repo

This commit is contained in:
thesimplekid
2024-11-19 14:57:53 +00:00
parent 8a3cec6e51
commit c8f82b29d0
45 changed files with 1 additions and 2462 deletions

View File

@@ -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

View File

@@ -1,6 +1,5 @@
[workspace]
members = [
"bindings/cdk-js",
"crates/*",
]
resolver = "2"

View File

@@ -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

View File

@@ -1,4 +0,0 @@
# CDK Bindings
Javascript:
[cdk-js](./cdk-js/) javascript bindings for [cdk](../crates/cdk/)

View File

@@ -1,12 +0,0 @@
.cargo/
target/
src/
scripts/
examples/
pkg/package.json
pkg/*.md
pkg/*.wasm
.gitignore
Cargo.toml
Cargo.lock
*.tgz

View File

@@ -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"] }

View File

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

View File

@@ -1,3 +0,0 @@
pack:
rm -rf ./pkg
wasm-pack build --target web

View File

@@ -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",
}
}

View File

@@ -1,12 +0,0 @@
use wasm_bindgen::JsValue;
pub type Result<T, E = JsValue> = std::result::Result<T, E>;
/// Helper to replace the `E` to `Error` to `napi::Error` conversion.
#[inline]
pub fn into_err<E>(error: E) -> JsValue
where
E: std::fmt::Display,
{
JsValue::from_str(&error.to_string())
}

View File

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

View File

@@ -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;

View File

@@ -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<JsBlindSignatureDleq>,
) -> Self {
Self {
inner: BlindSignature {
keyset_id: *keyset_id.deref(),
amount: *amount.deref(),
c: *c.deref(),
dleq: dleq.map(|b| b.deref().clone()),
},
}
}
}

View File

@@ -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<BlindedMessage> 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<JsWitness>,
) -> 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<JsWitness> {
self.inner.witness.clone().map(|w| w.into())
}
}

View File

@@ -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<CurrencyUnit> 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<JsCurrencyUnit> 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,
}
}
}

View File

@@ -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;

View File

@@ -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<PreMint> 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<PreMintSecrets> for JsPreMintSecrets {
fn from(inner: PreMintSecrets) -> JsPreMintSecrets {
JsPreMintSecrets { inner }
}
}

View File

@@ -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<Proof> 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<JsWitness>,
dleq: Option<JsProofDleq>,
) -> 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()
}
}

View File

@@ -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<Token> 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<JsToken> {
Ok(Self {
inner: Token::from_str(&token).map_err(into_err)?,
})
}
}

View File

@@ -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<Witness> for JsWitness {
fn from(inner: Witness) -> JsWitness {
JsWitness { inner }
}
}
#[wasm_bindgen(js_class = Witness)]
impl JsWitness {
#[wasm_bindgen(constructor)]
pub fn new(preimage: Option<String>, signatures: Option<Vec<String>>) -> Result<JsWitness> {
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<Vec<String>> {
self.inner.signatures()
}
#[wasm_bindgen(getter)]
pub fn preimage(&self) -> Option<String> {
self.inner.preimage()
}
}

View File

@@ -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<Keys> 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<JsKeys> {
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<JsValue> {
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<JsPublicKey> {
self.inner.amount_key(*amount.deref()).map(|k| k.into())
}
}

View File

@@ -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;

View File

@@ -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<PublicKey> 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<JsPublicKey> {
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()
}
}

View File

@@ -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<SecretKey> 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()
}
}

View File

@@ -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<Id> 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<JsId> {
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()
}
}

View File

@@ -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<KeySet> 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<KeysetResponse> 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<JsKeySetsResponse> {
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<JsValue> {
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<KeysResponse> 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<JsKeysResponse> {
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<JsValue> {
serde_wasm_bindgen::to_value(&self.inner.keysets).map_err(into_err)
}
}

View File

@@ -1,4 +0,0 @@
pub mod id;
pub mod keyset;
pub use id::JsId;

View File

@@ -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<SwapRequest> 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<JsSwapRequest> {
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<JsValue> {
serde_wasm_bindgen::to_value(&self.inner.inputs).map_err(into_err)
}
/// Get Outputs
#[wasm_bindgen(getter)]
pub fn outputs(&self) -> Result<JsValue> {
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<SwapResponse> 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<JsSwapResponse> {
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<JsValue> {
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()
}
}

View File

@@ -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<MintQuoteBolt11Request> 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<MintQuoteBolt11Response> 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<u64> {
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<MintBolt11Request> 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<JsMintBolt11Request> {
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<JsValue> {
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<MintBolt11Response> 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<JsMintBolt11Response> {
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<JsValue> {
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<MintMethodSettings> 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<Settings> for JsSettings {
fn from(inner: Settings) -> JsSettings {
JsSettings { inner }
}
}

View File

@@ -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<MeltQuoteBolt11Request> 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<MeltQuoteBolt11Response> 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<MeltBolt11Request> 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<MeltMethodSettings> 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<NUT05Settings> for JsSettings {
fn from(inner: NUT05Settings) -> JsSettings {
JsSettings { inner }
}
}

View File

@@ -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<MintVersion> 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<JsMintVersion> {
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<MintInfo> 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<String>,
pubkey: Option<JsPublicKey>,
version: Option<JsMintVersion>,
description: Option<String>,
description_long: Option<String>,
contact: Option<Vec<JsContactInfo>>,
nuts: JsValue,
icon_url: Option<String>,
urls: Option<Vec<String>>,
motd: Option<String>,
time: Option<u64>,
) -> Result<JsMintInfo> {
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<String> {
self.inner.name.clone()
}
/// Get Pubkey
#[wasm_bindgen(getter)]
pub fn pubkey(&self) -> Option<JsPublicKey> {
self.inner.pubkey.map(|p| p.into())
}
/// Get Version
#[wasm_bindgen(getter)]
pub fn version(&self) -> Option<JsMintVersion> {
self.inner.version.clone().map(|v| v.into())
}
/// Get description
#[wasm_bindgen(getter)]
pub fn description(&self) -> Option<String> {
self.inner.description.clone()
}
/// Get description long
#[wasm_bindgen(getter)]
pub fn description_long(&self) -> Option<String> {
self.inner.description_long.clone()
}
/// Get contact info
#[wasm_bindgen(getter)]
pub fn contact(&self) -> Option<Vec<JsContactInfo>> {
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<JsValue> {
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<String> {
self.inner.icon_url.clone()
}
/// Get motd
#[wasm_bindgen(getter)]
pub fn motd(&self) -> Option<String> {
self.inner.motd.clone()
}
/// Get time
#[wasm_bindgen(getter)]
pub fn time(&self) -> Option<u64> {
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<ContactInfo> 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<JsContactInfo> {
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()
}
}

View File

@@ -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<State> 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<JsState> 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<CheckStateRequest> 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<ProofState> 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<CheckStateResponse> for JsCheckStateResponse {
fn from(inner: CheckStateResponse) -> JsCheckStateResponse {
JsCheckStateResponse { inner }
}
}

View File

@@ -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<RestoreRequest> 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<RestoreResponse> for JsRestoreResponse {
fn from(inner: RestoreResponse) -> JsRestoreResponse {
JsRestoreResponse { inner }
}
}

View File

@@ -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<Kind> for JsKind {
fn from(inner: Kind) -> JsKind {
match inner {
Kind::P2PK => JsKind::P2PK,
Kind::HTLC => JsKind::HTLC,
}
}
}
impl From<JsKind> 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<SecretData> 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<Nut10Secret> for JsNut10Secret {
fn from(inner: Nut10Secret) -> JsNut10Secret {
JsNut10Secret { inner }
}
}

View File

@@ -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<P2PKWitness> 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<JsConditions>,
) -> Result<JsP2PKSpendingConditions> {
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<Conditions> for JsConditions {
fn from(inner: Conditions) -> JsConditions {
JsConditions { inner }
}
}
#[wasm_bindgen(js_class = Conditions)]
impl JsConditions {
#[wasm_bindgen(constructor)]
pub fn new(
locktime: Option<u64>,
pubkeys: JsValue,
refund_key: JsValue,
num_sigs: Option<u64>,
sig_flag: String,
) -> Result<JsConditions> {
let pubkeys: Result<Vec<PublicKey>, _> = serde_wasm_bindgen::from_value(pubkeys);
let refund_key: Result<Vec<PublicKey>, _> = 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<u64> {
self.inner.locktime
}
#[wasm_bindgen(getter)]
pub fn pubkeys(&self) -> Result<JsValue> {
Ok(serde_wasm_bindgen::to_value(&self.inner.pubkeys)?)
}
#[wasm_bindgen(getter)]
pub fn refund_keys(&self) -> Result<JsValue> {
Ok(serde_wasm_bindgen::to_value(&self.inner.refund_keys)?)
}
#[wasm_bindgen(getter)]
pub fn num_sigs(&self) -> Option<u64> {
self.inner.num_sigs
}
#[wasm_bindgen(getter)]
pub fn sig_flag(&self) -> String {
self.inner.sig_flag.to_string()
}
}

View File

@@ -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<BlindSignatureDleq> 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<ProofDleq> for JsProofDleq {
fn from(inner: ProofDleq) -> JsProofDleq {
JsProofDleq { inner }
}
}

View File

@@ -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<HTLCWitness> 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<JsConditions>,
) -> Result<JsHTLCSpendingConditions> {
Ok(Self {
inner: SpendingConditions::new_htlc(preimage, conditions.map(|c| c.deref().clone()))
.map_err(into_err)?,
})
}
}

View File

@@ -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<Amount> for JsAmount {
fn from(inner: Amount) -> JsAmount {
JsAmount { inner }
}
}
impl From<u64> 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<JsValue> {
serde_wasm_bindgen::to_value(&self.inner.split()).map_err(into_err)
}
#[wasm_bindgen(getter)]
pub fn value(&self) -> u64 {
self.inner.into()
}
}

View File

@@ -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<MeltQuote> 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
}
}

View File

@@ -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<Melted> 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<String> {
self.inner.preimage.clone()
}
#[wasm_bindgen(getter)]
pub fn change(&self) -> Result<JsValue> {
Ok(serde_wasm_bindgen::to_value(&self.inner.change)?)
}
}

View File

@@ -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<MintQuote> 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
}
}

View File

@@ -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;

View File

@@ -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<Secret> 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<u8> {
self.inner.as_bytes().to_vec()
}
}

View File

@@ -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<Wallet> 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<u8>) -> Result<JsWallet> {
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<JsValue> {
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<JsValue> {
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<JsAmount> {
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<Option<JsMintInfo>> {
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<String>,
) -> Result<JsMintQuote> {
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<JsMintQuoteBolt11Response> {
let quote = self
.inner
.mint_quote_state(&quote_id)
.await
.map_err(into_err)?;
Ok(quote.into())
}
#[wasm_bindgen(js_name = checkAllMintQuotes)]
pub async fn check_all_mint_quotes(&self) -> Result<JsAmount> {
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<JsP2PKSpendingConditions>,
htlc_condition: Option<JsHTLCSpendingConditions>,
split_target_amount: Option<JsAmount>,
) -> Result<JsAmount> {
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(&quote_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<JsAmount>,
) -> Result<JsMeltQuote> {
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<JsMeltQuoteBolt11Response> {
let quote = self
.inner
.melt_quote_status(&quote_id)
.await
.map_err(into_err)?;
Ok(quote.into())
}
#[wasm_bindgen(js_name = melt)]
pub async fn melt(&mut self, quote_id: String) -> Result<JsMelted> {
let melted = self.inner.melt(&quote_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<JsSecretKey>,
preimages: Vec<String>,
) -> Result<JsAmount> {
let signing_keys: Vec<SecretKey> = 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<String>,
amount: u64,
p2pk_condition: Option<JsP2PKSpendingConditions>,
htlc_condition: Option<JsHTLCSpendingConditions>,
split_target_amount: Option<JsAmount>,
) -> Result<String> {
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<JsProof>,
p2pk_condition: Option<JsP2PKSpendingConditions>,
htlc_condition: Option<JsHTLCSpendingConditions>,
split_target_amount: Option<JsAmount>,
) -> Result<JsValue> {
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)?)
}
}

View File

@@ -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