From bba3189a2fa3ce53928c224efbaac28684e5607a Mon Sep 17 00:00:00 2001 From: thesimplekid Date: Mon, 1 Jan 2024 19:10:21 +0000 Subject: [PATCH] refactor: remove bindings --- Cargo.toml | 7 +- bindings/README.md | 8 - bindings/cashu-ffi/.gitignore | 38 -- bindings/cashu-ffi/Cargo.toml | 20 -- bindings/cashu-ffi/bindings-python/.gitignore | 16 - .../cashu-ffi/bindings-python/MANIFEST.in | 2 - bindings/cashu-ffi/bindings-python/README.md | 46 --- .../bindings-python/examples/amount.py | 5 - .../bindings-python/examples/token.py | 29 -- .../cashu-ffi/bindings-python/pyproject.toml | 7 - .../bindings-python/requirements.txt | 4 - bindings/cashu-ffi/bindings-python/setup.py | 26 -- .../bindings-python/src/cashu/__init__.py | 2 - bindings/cashu-ffi/build.rs | 3 - bindings/cashu-ffi/justfile | 17 - bindings/cashu-ffi/src/cashu.udl | 276 -------------- bindings/cashu-ffi/src/error.rs | 66 ---- bindings/cashu-ffi/src/lib.rs | 38 -- bindings/cashu-ffi/src/nuts/mod.rs | 9 - .../src/nuts/nut00/blinded_message.rs | 54 --- .../src/nuts/nut00/blinded_signature.rs | 55 --- .../cashu-ffi/src/nuts/nut00/mint_proofs.rs | 56 --- bindings/cashu-ffi/src/nuts/nut00/mod.rs | 6 - .../src/nuts/nut00/premint_secrets.rs | 78 ---- bindings/cashu-ffi/src/nuts/nut00/proof.rs | 136 ------- bindings/cashu-ffi/src/nuts/nut00/token.rs | 106 ------ bindings/cashu-ffi/src/nuts/nut01/key_pair.rs | 26 -- bindings/cashu-ffi/src/nuts/nut01/keys.rs | 110 ------ bindings/cashu-ffi/src/nuts/nut01/mod.rs | 4 - .../cashu-ffi/src/nuts/nut01/public_key.rs | 40 --- .../cashu-ffi/src/nuts/nut01/secret_key.rs | 34 -- bindings/cashu-ffi/src/nuts/nut02/key_set.rs | 113 ------ .../cashu-ffi/src/nuts/nut02/mint_keyset.rs | 35 -- bindings/cashu-ffi/src/nuts/nut02/mod.rs | 5 - bindings/cashu-ffi/src/nuts/nut03/mod.rs | 82 ----- bindings/cashu-ffi/src/nuts/nut04/mod.rs | 168 --------- bindings/cashu-ffi/src/nuts/nut05/mod.rs | 143 -------- bindings/cashu-ffi/src/nuts/nut06.rs | 134 ------- bindings/cashu-ffi/src/nuts/nut07/mod.rs | 65 ---- bindings/cashu-ffi/src/nuts/nut08/mod.rs | 112 ------ bindings/cashu-ffi/src/types/amount.rs | 54 --- .../cashu-ffi/src/types/bolt11_invoice.rs | 43 --- bindings/cashu-ffi/src/types/keyset_info.rs | 36 -- bindings/cashu-ffi/src/types/melt_quote.rs | 49 --- bindings/cashu-ffi/src/types/mint_quote.rs | 47 --- .../cashu-ffi/src/types/mint_quote_info.rs | 47 --- bindings/cashu-ffi/src/types/mod.rs | 13 - bindings/cashu-ffi/src/types/secret.rs | 44 --- bindings/cashu-ffi/uniffi.toml | 10 - bindings/cashu-js/.cargo/config.toml | 2 - bindings/cashu-js/.gitignore | 7 - bindings/cashu-js/.npmignore | 12 - bindings/cashu-js/Cargo.toml | 28 -- bindings/cashu-js/LICENSE | 29 -- bindings/cashu-js/LICENSES/NOSTR-MIT | 21 -- bindings/cashu-js/examples/amount.js | 12 - bindings/cashu-js/justfile | 5 - bindings/cashu-js/package.json | 44 --- bindings/cashu-js/scripts/LICENSE | 21 -- bindings/cashu-js/scripts/build.sh | 35 -- bindings/cashu-js/scripts/epilogue.d.ts | 10 - bindings/cashu-js/scripts/epilogue.js | 76 ---- bindings/cashu-js/src/error.rs | 12 - bindings/cashu-js/src/lib.rs | 12 - bindings/cashu-js/src/nuts/mod.rs | 20 -- .../src/nuts/nut00/blinded_message.rs | 53 --- .../src/nuts/nut00/blinded_messages.rs | 62 ---- .../src/nuts/nut00/blinded_signature.rs | 35 -- bindings/cashu-js/src/nuts/nut00/mod.rs | 11 - bindings/cashu-js/src/nuts/nut00/proof.rs | 65 ---- bindings/cashu-js/src/nuts/nut00/token.rs | 69 ---- bindings/cashu-js/src/nuts/nut01/key_pair.rs | 47 --- bindings/cashu-js/src/nuts/nut01/keys.rs | 51 --- bindings/cashu-js/src/nuts/nut01/mod.rs | 9 - .../cashu-js/src/nuts/nut01/public_key.rs | 41 --- .../cashu-js/src/nuts/nut01/secret_key.rs | 31 -- bindings/cashu-js/src/nuts/nut02/keyset.rs | 152 -------- .../cashu-js/src/nuts/nut02/mint_keyset.rs | 45 --- bindings/cashu-js/src/nuts/nut02/mod.rs | 5 - bindings/cashu-js/src/nuts/nut03.rs | 104 ------ bindings/cashu-js/src/nuts/nut04.rs | 82 ----- bindings/cashu-js/src/nuts/nut05.rs | 1 - bindings/cashu-js/src/nuts/nut06.rs | 106 ------ bindings/cashu-js/src/nuts/nut07.rs | 94 ----- bindings/cashu-js/src/nuts/nut08.rs | 131 ------- bindings/cashu-js/src/nuts/nut09.rs | 142 -------- bindings/cashu-js/src/types/amount.rs | 48 --- bindings/cashu-js/src/types/bolt11_invoice.rs | 50 --- bindings/cashu-js/src/types/mod.rs | 9 - bindings/cashu-js/src/types/proofs_status.rs | 48 --- bindings/cashu-js/src/types/secret.rs | 44 --- bindings/cashu-js/tsconfig.json | 9 - bindings/cashu-sdk-ffi/Cargo.toml | 30 -- bindings/cashu-sdk-ffi/LICENSE | 29 -- .../LICENSES/NOSTR_SDK_LICENSE_MIT | 21 -- .../cashu-sdk-ffi/bindings-python/.gitignore | 16 - .../cashu-sdk-ffi/bindings-python/LICENSE | 29 -- .../bindings-python/LICENSES/NOSTR_SDK_MIT | 21 -- .../cashu-sdk-ffi/bindings-python/MANIFEST.in | 3 - .../cashu-sdk-ffi/bindings-python/README.md | 50 --- .../bindings-python/examples/mint.py | 5 - .../bindings-python/examples/wallet.py | 13 - .../bindings-python/pyproject.toml | 7 - .../bindings-python/requirements.txt | 5 - .../cashu-sdk-ffi/bindings-python/setup.py | 26 -- .../bindings-python/src/cashu-sdk/__init__.py | 2 - bindings/cashu-sdk-ffi/build.rs | 3 - bindings/cashu-sdk-ffi/justfile | 16 - bindings/cashu-sdk-ffi/src/cashu_sdk.udl | 339 ------------------ bindings/cashu-sdk-ffi/src/error.rs | 40 --- bindings/cashu-sdk-ffi/src/lib.rs | 26 -- bindings/cashu-sdk-ffi/src/mint.rs | 142 -------- .../cashu-sdk-ffi/src/types/keyset_info.rs | 49 --- bindings/cashu-sdk-ffi/src/types/melted.rs | 49 --- bindings/cashu-sdk-ffi/src/types/mod.rs | 9 - .../cashu-sdk-ffi/src/types/proofs_status.rs | 55 --- .../cashu-sdk-ffi/src/types/send_proofs.rs | 57 --- bindings/cashu-sdk-ffi/src/wallet.rs | 180 ---------- bindings/cashu-sdk-ffi/uniffi.toml | 11 - bindings/cashu-sdk-js/.cargo/config.toml | 2 - bindings/cashu-sdk-js/.gitignore | 7 - bindings/cashu-sdk-js/Cargo.toml | 36 -- bindings/cashu-sdk-js/LICENSE | 29 -- bindings/cashu-sdk-js/LICENSES/NOSTR-MIT | 21 -- bindings/cashu-sdk-js/README.md | 0 bindings/cashu-sdk-js/examples/amount.js | 12 - bindings/cashu-sdk-js/examples/wallet.js | 19 - bindings/cashu-sdk-js/justfile | 5 - bindings/cashu-sdk-js/package.json | 44 --- bindings/cashu-sdk-js/scripts/LICENSE | 21 -- bindings/cashu-sdk-js/scripts/build.sh | 35 -- bindings/cashu-sdk-js/scripts/epilogue.d.ts | 10 - bindings/cashu-sdk-js/scripts/epilogue.js | 76 ---- bindings/cashu-sdk-js/src/error.rs | 12 - bindings/cashu-sdk-js/src/lib.rs | 7 - bindings/cashu-sdk-js/src/mint.rs | 136 ------- bindings/cashu-sdk-js/src/types/melted.rs | 57 --- bindings/cashu-sdk-js/src/types/mod.rs | 5 - .../cashu-sdk-js/src/types/send_proofs.rs | 51 --- bindings/cashu-sdk-js/src/wallet.rs | 188 ---------- bindings/uniffi-bindgen/Cargo.toml | 12 - bindings/uniffi-bindgen/src/main.rs | 3 - crates/cashu-sdk/src/wallet.rs | 3 +- 143 files changed, 3 insertions(+), 6435 deletions(-) delete mode 100644 bindings/README.md delete mode 100644 bindings/cashu-ffi/.gitignore delete mode 100644 bindings/cashu-ffi/Cargo.toml delete mode 100644 bindings/cashu-ffi/bindings-python/.gitignore delete mode 100644 bindings/cashu-ffi/bindings-python/MANIFEST.in delete mode 100644 bindings/cashu-ffi/bindings-python/README.md delete mode 100644 bindings/cashu-ffi/bindings-python/examples/amount.py delete mode 100644 bindings/cashu-ffi/bindings-python/examples/token.py delete mode 100644 bindings/cashu-ffi/bindings-python/pyproject.toml delete mode 100644 bindings/cashu-ffi/bindings-python/requirements.txt delete mode 100644 bindings/cashu-ffi/bindings-python/setup.py delete mode 100644 bindings/cashu-ffi/bindings-python/src/cashu/__init__.py delete mode 100644 bindings/cashu-ffi/build.rs delete mode 100644 bindings/cashu-ffi/justfile delete mode 100644 bindings/cashu-ffi/src/cashu.udl delete mode 100644 bindings/cashu-ffi/src/error.rs delete mode 100644 bindings/cashu-ffi/src/lib.rs delete mode 100644 bindings/cashu-ffi/src/nuts/mod.rs delete mode 100644 bindings/cashu-ffi/src/nuts/nut00/blinded_message.rs delete mode 100644 bindings/cashu-ffi/src/nuts/nut00/blinded_signature.rs delete mode 100644 bindings/cashu-ffi/src/nuts/nut00/mint_proofs.rs delete mode 100644 bindings/cashu-ffi/src/nuts/nut00/mod.rs delete mode 100644 bindings/cashu-ffi/src/nuts/nut00/premint_secrets.rs delete mode 100644 bindings/cashu-ffi/src/nuts/nut00/proof.rs delete mode 100644 bindings/cashu-ffi/src/nuts/nut00/token.rs delete mode 100644 bindings/cashu-ffi/src/nuts/nut01/key_pair.rs delete mode 100644 bindings/cashu-ffi/src/nuts/nut01/keys.rs delete mode 100644 bindings/cashu-ffi/src/nuts/nut01/mod.rs delete mode 100644 bindings/cashu-ffi/src/nuts/nut01/public_key.rs delete mode 100644 bindings/cashu-ffi/src/nuts/nut01/secret_key.rs delete mode 100644 bindings/cashu-ffi/src/nuts/nut02/key_set.rs delete mode 100644 bindings/cashu-ffi/src/nuts/nut02/mint_keyset.rs delete mode 100644 bindings/cashu-ffi/src/nuts/nut02/mod.rs delete mode 100644 bindings/cashu-ffi/src/nuts/nut03/mod.rs delete mode 100644 bindings/cashu-ffi/src/nuts/nut04/mod.rs delete mode 100644 bindings/cashu-ffi/src/nuts/nut05/mod.rs delete mode 100644 bindings/cashu-ffi/src/nuts/nut06.rs delete mode 100644 bindings/cashu-ffi/src/nuts/nut07/mod.rs delete mode 100644 bindings/cashu-ffi/src/nuts/nut08/mod.rs delete mode 100644 bindings/cashu-ffi/src/types/amount.rs delete mode 100644 bindings/cashu-ffi/src/types/bolt11_invoice.rs delete mode 100644 bindings/cashu-ffi/src/types/keyset_info.rs delete mode 100644 bindings/cashu-ffi/src/types/melt_quote.rs delete mode 100644 bindings/cashu-ffi/src/types/mint_quote.rs delete mode 100644 bindings/cashu-ffi/src/types/mint_quote_info.rs delete mode 100644 bindings/cashu-ffi/src/types/mod.rs delete mode 100644 bindings/cashu-ffi/src/types/secret.rs delete mode 100644 bindings/cashu-ffi/uniffi.toml delete mode 100644 bindings/cashu-js/.cargo/config.toml delete mode 100644 bindings/cashu-js/.gitignore delete mode 100644 bindings/cashu-js/.npmignore delete mode 100644 bindings/cashu-js/Cargo.toml delete mode 100644 bindings/cashu-js/LICENSE delete mode 100644 bindings/cashu-js/LICENSES/NOSTR-MIT delete mode 100644 bindings/cashu-js/examples/amount.js delete mode 100644 bindings/cashu-js/justfile delete mode 100644 bindings/cashu-js/package.json delete mode 100644 bindings/cashu-js/scripts/LICENSE delete mode 100755 bindings/cashu-js/scripts/build.sh delete mode 100644 bindings/cashu-js/scripts/epilogue.d.ts delete mode 100644 bindings/cashu-js/scripts/epilogue.js delete mode 100644 bindings/cashu-js/src/error.rs delete mode 100644 bindings/cashu-js/src/lib.rs delete mode 100644 bindings/cashu-js/src/nuts/mod.rs delete mode 100644 bindings/cashu-js/src/nuts/nut00/blinded_message.rs delete mode 100644 bindings/cashu-js/src/nuts/nut00/blinded_messages.rs delete mode 100644 bindings/cashu-js/src/nuts/nut00/blinded_signature.rs delete mode 100644 bindings/cashu-js/src/nuts/nut00/mod.rs delete mode 100644 bindings/cashu-js/src/nuts/nut00/proof.rs delete mode 100644 bindings/cashu-js/src/nuts/nut00/token.rs delete mode 100644 bindings/cashu-js/src/nuts/nut01/key_pair.rs delete mode 100644 bindings/cashu-js/src/nuts/nut01/keys.rs delete mode 100644 bindings/cashu-js/src/nuts/nut01/mod.rs delete mode 100644 bindings/cashu-js/src/nuts/nut01/public_key.rs delete mode 100644 bindings/cashu-js/src/nuts/nut01/secret_key.rs delete mode 100644 bindings/cashu-js/src/nuts/nut02/keyset.rs delete mode 100644 bindings/cashu-js/src/nuts/nut02/mint_keyset.rs delete mode 100644 bindings/cashu-js/src/nuts/nut02/mod.rs delete mode 100644 bindings/cashu-js/src/nuts/nut03.rs delete mode 100644 bindings/cashu-js/src/nuts/nut04.rs delete mode 100644 bindings/cashu-js/src/nuts/nut05.rs delete mode 100644 bindings/cashu-js/src/nuts/nut06.rs delete mode 100644 bindings/cashu-js/src/nuts/nut07.rs delete mode 100644 bindings/cashu-js/src/nuts/nut08.rs delete mode 100644 bindings/cashu-js/src/nuts/nut09.rs delete mode 100644 bindings/cashu-js/src/types/amount.rs delete mode 100644 bindings/cashu-js/src/types/bolt11_invoice.rs delete mode 100644 bindings/cashu-js/src/types/mod.rs delete mode 100644 bindings/cashu-js/src/types/proofs_status.rs delete mode 100644 bindings/cashu-js/src/types/secret.rs delete mode 100644 bindings/cashu-js/tsconfig.json delete mode 100644 bindings/cashu-sdk-ffi/Cargo.toml delete mode 100644 bindings/cashu-sdk-ffi/LICENSE delete mode 100644 bindings/cashu-sdk-ffi/LICENSES/NOSTR_SDK_LICENSE_MIT delete mode 100644 bindings/cashu-sdk-ffi/bindings-python/.gitignore delete mode 100644 bindings/cashu-sdk-ffi/bindings-python/LICENSE delete mode 100644 bindings/cashu-sdk-ffi/bindings-python/LICENSES/NOSTR_SDK_MIT delete mode 100644 bindings/cashu-sdk-ffi/bindings-python/MANIFEST.in delete mode 100644 bindings/cashu-sdk-ffi/bindings-python/README.md delete mode 100644 bindings/cashu-sdk-ffi/bindings-python/examples/mint.py delete mode 100644 bindings/cashu-sdk-ffi/bindings-python/examples/wallet.py delete mode 100644 bindings/cashu-sdk-ffi/bindings-python/pyproject.toml delete mode 100644 bindings/cashu-sdk-ffi/bindings-python/requirements.txt delete mode 100644 bindings/cashu-sdk-ffi/bindings-python/setup.py delete mode 100644 bindings/cashu-sdk-ffi/bindings-python/src/cashu-sdk/__init__.py delete mode 100644 bindings/cashu-sdk-ffi/build.rs delete mode 100644 bindings/cashu-sdk-ffi/justfile delete mode 100644 bindings/cashu-sdk-ffi/src/cashu_sdk.udl delete mode 100644 bindings/cashu-sdk-ffi/src/error.rs delete mode 100644 bindings/cashu-sdk-ffi/src/lib.rs delete mode 100644 bindings/cashu-sdk-ffi/src/mint.rs delete mode 100644 bindings/cashu-sdk-ffi/src/types/keyset_info.rs delete mode 100644 bindings/cashu-sdk-ffi/src/types/melted.rs delete mode 100644 bindings/cashu-sdk-ffi/src/types/mod.rs delete mode 100644 bindings/cashu-sdk-ffi/src/types/proofs_status.rs delete mode 100644 bindings/cashu-sdk-ffi/src/types/send_proofs.rs delete mode 100644 bindings/cashu-sdk-ffi/src/wallet.rs delete mode 100644 bindings/cashu-sdk-ffi/uniffi.toml delete mode 100644 bindings/cashu-sdk-js/.cargo/config.toml delete mode 100644 bindings/cashu-sdk-js/.gitignore delete mode 100644 bindings/cashu-sdk-js/Cargo.toml delete mode 100644 bindings/cashu-sdk-js/LICENSE delete mode 100644 bindings/cashu-sdk-js/LICENSES/NOSTR-MIT delete mode 100644 bindings/cashu-sdk-js/README.md delete mode 100644 bindings/cashu-sdk-js/examples/amount.js delete mode 100644 bindings/cashu-sdk-js/examples/wallet.js delete mode 100644 bindings/cashu-sdk-js/justfile delete mode 100644 bindings/cashu-sdk-js/package.json delete mode 100644 bindings/cashu-sdk-js/scripts/LICENSE delete mode 100755 bindings/cashu-sdk-js/scripts/build.sh delete mode 100644 bindings/cashu-sdk-js/scripts/epilogue.d.ts delete mode 100644 bindings/cashu-sdk-js/scripts/epilogue.js delete mode 100644 bindings/cashu-sdk-js/src/error.rs delete mode 100644 bindings/cashu-sdk-js/src/lib.rs delete mode 100644 bindings/cashu-sdk-js/src/mint.rs delete mode 100644 bindings/cashu-sdk-js/src/types/melted.rs delete mode 100644 bindings/cashu-sdk-js/src/types/mod.rs delete mode 100644 bindings/cashu-sdk-js/src/types/send_proofs.rs delete mode 100644 bindings/cashu-sdk-js/src/wallet.rs delete mode 100644 bindings/uniffi-bindgen/Cargo.toml delete mode 100644 bindings/uniffi-bindgen/src/main.rs diff --git a/Cargo.toml b/Cargo.toml index b471553a..f8d5579c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,11 +3,6 @@ members = [ "crates/cashu", "crates/cashu-sdk", - "bindings/uniffi-bindgen", - "bindings/cashu-ffi", - "bindings/cashu-sdk-ffi", - "bindings/cashu-js", - "bindings/cashu-sdk-js" ] resolver = "2" @@ -22,7 +17,7 @@ authors = ["thesimplekid"] edition = "2021" description = "cashu-crab" readme = "README.md" -repository = "https://github.com/thesimplekid/cashu-rs-mint" +repository = "https://github.com/thesimplekid/cashu-crab" license-file = "LICENSE" keywords = ["bitcoin", "e-cash", "cashu"] diff --git a/bindings/README.md b/bindings/README.md deleted file mode 100644 index febbfc87..00000000 --- a/bindings/README.md +++ /dev/null @@ -1,8 +0,0 @@ -# Cashu bindings - -- UniFFI (Kotlin (soon), Swift (soon), Python): - * [cashu-ffi](./cashu-ffi/): UniFFI bindings of the [cashu] crate - * [cashu-sdk-ffi](./cashu-sdk-ffi/): UniFFI bindings of the [cashu-sdk] crate - -[cashu]: ../crates/cashu/ -[cashu-sdk]: ../crates/cashu-sdk/ diff --git a/bindings/cashu-ffi/.gitignore b/bindings/cashu-ffi/.gitignore deleted file mode 100644 index ea360cca..00000000 --- a/bindings/cashu-ffi/.gitignore +++ /dev/null @@ -1,38 +0,0 @@ -target -build -.gradle -wallet_db -bdk_ffi_test -local.properties -*.log -*.dylib -*.so -.DS_Store -testdb -xcuserdata -.lsp -.clj-kondo -.idea/ -.editorconfig -bdk.kt - -# Swift related -/.build -/.swiftpm -/Packages -/*.xcodeproj -xcuserdata/ -DerivedData/ -.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata -bdkFFI.xcframework.zip -bdkFFI -libbdkffi.a -bdkFFI.h -BitcoinDevKit.swift -bdk.swift -.build - -# Python related -__pycache__ - -/ffi diff --git a/bindings/cashu-ffi/Cargo.toml b/bindings/cashu-ffi/Cargo.toml deleted file mode 100644 index 025642e8..00000000 --- a/bindings/cashu-ffi/Cargo.toml +++ /dev/null @@ -1,20 +0,0 @@ -[package] -name = "cashu-ffi" -version = "0.1.0" -edition = "2021" -publish = false -rust-version.workspace = true - - -[lib] -name = "cashu_ffi" -crate-type = ["lib", "cdylib", "staticlib"] -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -cashu = { path = "../../crates/cashu", features = ["wallet", "mint", "all-nuts"] } -url = { workspace = true } -uniffi = { workspace = true } - -[build-dependencies] -uniffi = { workspace = true, features = ["build"] } diff --git a/bindings/cashu-ffi/bindings-python/.gitignore b/bindings/cashu-ffi/bindings-python/.gitignore deleted file mode 100644 index 4309a480..00000000 --- a/bindings/cashu-ffi/bindings-python/.gitignore +++ /dev/null @@ -1,16 +0,0 @@ -.tox/ -dist/ -cashu_protocol.egg-info/ -__pycache__/ -libcashu_ffi.dylib -.idea/ -.DS_Store - -*.swp - -src/cashu/cashu.py -src/cashu/*.so -*.whl -build/ - -testing-setup-py-simple-example.py diff --git a/bindings/cashu-ffi/bindings-python/MANIFEST.in b/bindings/cashu-ffi/bindings-python/MANIFEST.in deleted file mode 100644 index f1c8162f..00000000 --- a/bindings/cashu-ffi/bindings-python/MANIFEST.in +++ /dev/null @@ -1,2 +0,0 @@ -include ./src/cashu/libcashu_ffi.dylib -include ./src/cashu/libcashu_ffi.so diff --git a/bindings/cashu-ffi/bindings-python/README.md b/bindings/cashu-ffi/bindings-python/README.md deleted file mode 100644 index 9aeffd19..00000000 --- a/bindings/cashu-ffi/bindings-python/README.md +++ /dev/null @@ -1,46 +0,0 @@ -Cashu Python bindings - - -**ALPHA** This library is in early development, the api will change. - -## Supported Nuts: - -Check: [https://github.com/thesimplekid/cashu-crab#implemented-nuts](https://github.com/thesimplekid/cashu-crab#implemented-nuts) - -## Build the package - -```shell -just python -``` - -## Getting Started - -For now this is not published as a package as it is still in early development. So you will have to build it as above. In the future this will be pulished and pip can be used to install. - -```python -from cashu_protocol import Token, Proof, PublicKey, Amount - -proof_one = Proof(Amount.from_sat(2), "EhpennC9qB3iFlW8FZ_pZw", PublicKey.from_hex("02c020067db727d586bc3183aecf97fcb800c3f4cc4759f69c626c9db5d8f5b5d4"), "DSAl9nvvyfva") - -proof_two = Proof(Amount.from_sat(8), "TmS6Cv0YT5PU_5ATVKnukw", PublicKey.from_hex("02ac910bef28cbe5d7325415d5c263026f15f9b967a079ca9779ab6e5c2db133a7"), "DSAl9nvvyfva") - -new_token = Token("https://8333.space:3338", [proof_one, proof_two], "Thank you.") - -print(new_token.as_string()) - -``` - - -## License - -Code is under the [BSD 3-Clause License](LICENSE) - -## Contribution - -All contributions welcome. - -Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, shall be licensed as above, without any additional terms or conditions. - -## Contact - -I can be contacted for comments or questions on nostr at _@thesimplekid.com (npub1qjgcmlpkeyl8mdkvp4s0xls4ytcux6my606tgfx9xttut907h0zs76lgjw) or via email tsk@thesimplekid.com. diff --git a/bindings/cashu-ffi/bindings-python/examples/amount.py b/bindings/cashu-ffi/bindings-python/examples/amount.py deleted file mode 100644 index ab9add40..00000000 --- a/bindings/cashu-ffi/bindings-python/examples/amount.py +++ /dev/null @@ -1,5 +0,0 @@ -from cashu_protocol import Amount - -amount = Amount().from_sat(10) - -print(amount.to_sat()) diff --git a/bindings/cashu-ffi/bindings-python/examples/token.py b/bindings/cashu-ffi/bindings-python/examples/token.py deleted file mode 100644 index 56bffe35..00000000 --- a/bindings/cashu-ffi/bindings-python/examples/token.py +++ /dev/null @@ -1,29 +0,0 @@ -from cashu_protocol import Token, Proof, PublicKey, Amount - -token_str = "cashuAeyJ0b2tlbiI6W3sibWludCI6Imh0dHBzOi8vODMzMy5zcGFjZTozMzM4IiwicHJvb2ZzIjpbeyJpZCI6IkRTQWw5bnZ2eWZ2YSIsImFtb3VudCI6Miwic2VjcmV0IjoiRWhwZW5uQzlxQjNpRmxXOEZaX3BadyIsIkMiOiIwMmMwMjAwNjdkYjcyN2Q1ODZiYzMxODNhZWNmOTdmY2I4MDBjM2Y0Y2M0NzU5ZjY5YzYyNmM5ZGI1ZDhmNWI1ZDQifSx7ImlkIjoiRFNBbDludnZ5ZnZhIiwiYW1vdW50Ijo4LCJzZWNyZXQiOiJUbVM2Q3YwWVQ1UFVfNUFUVktudWt3IiwiQyI6IjAyYWM5MTBiZWYyOGNiZTVkNzMyNTQxNWQ1YzI2MzAyNmYxNWY5Yjk2N2EwNzljYTk3NzlhYjZlNWMyZGIxMzNhNyJ9XX1dLCJtZW1vIjoiVGhhbmsgeW91LiJ9" - -token = Token.from_string(token_str) - - -print(token.memo()) -for p in token.token(): - print(p.url()) - for proof in p.proofs(): - print(proof.id()) - print(proof.amount().to_sat()) - print(proof.secret()) - print(proof.c().to_hex()) - - -proof_one = Proof(Amount.from_sat(2), "EhpennC9qB3iFlW8FZ_pZw", PublicKey.from_hex("02c020067db727d586bc3183aecf97fcb800c3f4cc4759f69c626c9db5d8f5b5d4"), "DSAl9nvvyfva") - -proof_two = Proof(Amount.from_sat(8), "TmS6Cv0YT5PU_5ATVKnukw", PublicKey.from_hex("02ac910bef28cbe5d7325415d5c263026f15f9b967a079ca9779ab6e5c2db133a7"), "DSAl9nvvyfva") - -new_token = Token("https://8333.space:3338", [proof_one, proof_two], "Thank you.") - -print(new_token.as_string()) - -# This is failing because of the url serialization. -# https://github.com/thesimplekid/cashu-crab/issues/13 -# It is still a valid token, just does not match the reference -print(new_token.as_string == token_str) diff --git a/bindings/cashu-ffi/bindings-python/pyproject.toml b/bindings/cashu-ffi/bindings-python/pyproject.toml deleted file mode 100644 index 0e557d58..00000000 --- a/bindings/cashu-ffi/bindings-python/pyproject.toml +++ /dev/null @@ -1,7 +0,0 @@ -[build-system] -requires = ["setuptools", "wheel"] - -[tool.pytest.ini_options] -pythonpath = [ - "." -] diff --git a/bindings/cashu-ffi/bindings-python/requirements.txt b/bindings/cashu-ffi/bindings-python/requirements.txt deleted file mode 100644 index 959ed447..00000000 --- a/bindings/cashu-ffi/bindings-python/requirements.txt +++ /dev/null @@ -1,4 +0,0 @@ -semantic-version==2.9.0 -typing_extensions==4.0.1 -setuptools==67.4.0 -wheel==0.38.4 diff --git a/bindings/cashu-ffi/bindings-python/setup.py b/bindings/cashu-ffi/bindings-python/setup.py deleted file mode 100644 index b2df8a47..00000000 --- a/bindings/cashu-ffi/bindings-python/setup.py +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env python - -from setuptools import setup - -from pathlib import Path -this_directory = Path(__file__).parent -long_description = (this_directory / "README.md").read_text() - -setup( - name='cashu-protocol', - version='0.0.1', - description="Rust implementation of cashu.", - long_description=long_description, - long_description_content_type='text/markdown', - include_package_data = True, - zip_safe=False, - packages=['cashu_protocol'], - package_dir={'cashu_protocol': './src/cashu'}, - package_data={'cashu_protocol': ['*.so', 'lib*']}, - url="https://github.com/thesimplekid/cashu-crab", - author="thesimplekid ", - license="BSD-3-Clause", - # This is required to ensure the library name includes the python version, abi, and platform tags - # See issue #350 for more information - has_ext_modules=lambda: True, -) diff --git a/bindings/cashu-ffi/bindings-python/src/cashu/__init__.py b/bindings/cashu-ffi/bindings-python/src/cashu/__init__.py deleted file mode 100644 index 1fcdf0a1..00000000 --- a/bindings/cashu-ffi/bindings-python/src/cashu/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -from cashu_protocol.cashu import * - diff --git a/bindings/cashu-ffi/build.rs b/bindings/cashu-ffi/build.rs deleted file mode 100644 index b6c51045..00000000 --- a/bindings/cashu-ffi/build.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - uniffi::generate_scaffolding("./src/cashu.udl").expect("Building the UDL file failed"); -} diff --git a/bindings/cashu-ffi/justfile b/bindings/cashu-ffi/justfile deleted file mode 100644 index f441304d..00000000 --- a/bindings/cashu-ffi/justfile +++ /dev/null @@ -1,17 +0,0 @@ - -init: - rustup target add aarch64-apple-ios x86_64-apple-ios aarch64-apple-ios-sim - rustup target add aarch64-apple-darwin x86_64-apple-darwin - rustup target add aarch64-linux-android armv7-linux-androideabi i686-linux-android x86_64-linux-android - cargo install cbindgen - cargo install cargo-ndk - -python: - rm -rf dist - pip install -r bindings-python/requirements.txt - cargo build --release - cargo run -p uniffi-bindgen generate src/cashu.udl --language python --no-format -o bindings-python/src/cashu/ - cp ../../target/release/libcashu_ffi.so bindings-python/src/cashu/ - cp ../../target/release/libcashu_ffi.dylib bindings-python/src/cashu/ | true - cd bindings-python && pip wheel --no-deps -w dist . - pip install ./bindings-python/dist/cashu_protocol*.whl --force-reinstall diff --git a/bindings/cashu-ffi/src/cashu.udl b/bindings/cashu-ffi/src/cashu.udl deleted file mode 100644 index ac8ddea2..00000000 --- a/bindings/cashu-ffi/src/cashu.udl +++ /dev/null @@ -1,276 +0,0 @@ -namespace cashu {}; - -[Error] -interface CashuError { - Generic(string err); -}; - -// Types - -[Enum] -interface CurrencyUnit { - Sat(); - Usd(); - Custom(string unit); -}; - -interface Bolt11Invoice { - [Throws=CashuError] - constructor(string bolt11); - string as_string(); - Amount? amount(); -}; - -interface Amount { - constructor(u64 amount); - sequence split(); -}; - -interface Secret { - constructor(); - sequence as_bytes(); -}; - -interface MintQuote { - constructor(string id, Amount amount, string unit, Bolt11Invoice request, boolean paid, u64 boolean); -}; - -interface MeltQuote { - constructor(string id, Amount amount, string unit, Bolt11Invoice request, Amount fee_reserve, boolean paid, u64 boolean); -}; - -// NUT00 - -interface PublicKey { - [Throws=CashuError, Name=from_hex] - constructor(string hex); - [Throws=CashuError] - string to_hex(); -}; - - -interface SecretKey { - [Throws=CashuError] - string to_hex(); -}; - -interface BlindedMessage { - constructor(Id keyset_id, Amount amount, PublicKey b); - Amount amount(); - Id keyset_id(); - PublicKey b(); -}; - -interface Proof { - constructor(Amount amount, Secret secret, PublicKey c, Id id); - Amount amount(); - Secret secret(); - PublicKey c(); - Id keyset_id(); -}; - -interface BlindedSignature { - constructor(Id keyset_id, Amount amount, PublicKey c); - Id keyset_id(); - Amount amount(); - PublicKey c(); -}; - -interface MintProof { - constructor(Amount? amount, Secret secret, PublicKey? c, Id? id); - Amount? amount(); - Secret secret(); - PublicKey? c(); - Id? keyset_id(); - -}; - -interface MintProofs { - [Throws=CashuError] - constructor(string mint, sequence proofs); - string url(); - sequence proofs(); -}; - -interface Token { - [Throws=CashuError] - constructor(string mint, sequence token, string? memo, string? unit); - sequence token(); - string? memo(); - string? unit(); - string to_string(); - [Throws=CashuError, Name=from_string] - constructor(string token); - -}; - -interface PreMintSecrets { - [Throws=CashuError, Name=random] - constructor(Id keyset_id, Amount amount); - [Throws=CashuError, Name=blank] - constructor(Id keyset_id, Amount amount); - sequence blinded_messages(); - sequence secrets(); - sequence rs(); - sequence amounts(); -}; - - -// NUT-02 - -interface Id { - [Throws=CashuError] - constructor(string id); -}; - -interface KeyPair { - [Name=from_secret_key] - constructor(SecretKey secret_key); - SecretKey secret_key(); - PublicKey public_key(); -}; - -interface Keys { - constructor(record keys); - record keys(); - record as_hashmap(); - PublicKey? amount_key(Amount amount); -}; - -interface KeySet { - constructor(Id id, string unit, Keys keys); - Id id(); - Keys keys(); -}; - -interface MintKeySet { - [Name=generate] - constructor(string secret, string unit, string derivation_path, u8 max_order); -}; - -interface KeysResponse { - constructor(sequence keysets); -}; - -interface KeySetResponse { - constructor(sequence keysets); - sequence keysets(); -}; - -// NUT-03 - -interface SwapRequest { - constructor(sequence proofs, sequence outputs); - sequence proofs(); - sequence outputs(); - Amount proofs_amount(); - Amount output_amount(); -}; - -interface SwapResponse { - constructor(sequence promises); - sequence signatures(); -}; - -// NUT-04 - -interface MintQuoteBolt11Request { - constructor(Amount amount, string unit); - Amount amount(); -}; - -interface MintQuoteBolt11Response { - constructor(string quote, string request, boolean paid, u64 expiry); - string quote(); - string request(); - boolean paid(); - u64 expiry(); -}; - - -interface MintBolt11Request { - constructor(string quote, sequence outputs); - string quote(); - sequence outputs(); -}; - -interface MintBolt11Response { - constructor(sequence signatures); - sequence signatures(); -}; - -// NUT-05 - -interface MeltQuoteBolt11Response { - [Throws=CashuError] - constructor(string quote, u64 amount, u64 fee_reserve, boolean paid, u64 expiry); - string quote(); - u64 amount(); - u64 fee_reserve(); - boolean paid(); - u64 expiry(); -}; - -interface MeltQuoteBolt11Request { - [Throws=CashuError] - constructor(string request, string unit); - string request(); -}; - -interface MeltBolt11Request { - [Throws=CashuError] - constructor(string quote, sequence inputs, sequence? outputs); - sequence inputs(); - string quote(); -}; - -interface MeltBolt11Response { - constructor(boolean paid, string? payment_preimage, sequence? change); - string? payment_preimage(); - boolean paid(); -}; - -// NUT-06 - -interface MintInfo { - constructor(string? name, PublicKey? pubkey, MintVersion? version, string? description, string? description_long, sequence>? contact, string nuts, string? motd); - string? name(); - PublicKey? pubkey(); - MintVersion? version(); - string? description(); - string? description_long(); - sequence>? contact(); - string? motd(); -}; - -// NUT-07 - -interface CheckSpendableRequest { - constructor(sequence proofs); - sequence proofs(); -}; - -interface CheckSpendableResponse { - constructor(sequence spendable, sequence pending); - sequence spendable(); - sequence pending(); -}; - -interface MintVersion { - constructor(string name, string version); - string name(); - string version(); -}; - -interface KeySetInfo { - constructor(Id id, string unit); - -}; - -enum InvoiceStatus { - "Unpaid", - "Paid", - "Expired", - "InFlight" -}; - diff --git a/bindings/cashu-ffi/src/error.rs b/bindings/cashu-ffi/src/error.rs deleted file mode 100644 index a28441c6..00000000 --- a/bindings/cashu-ffi/src/error.rs +++ /dev/null @@ -1,66 +0,0 @@ -use std::fmt; - -use cashu::lightning_invoice::ParseOrSemanticError; - -pub type Result = std::result::Result; - -#[derive(Debug)] -pub enum CashuError { - Generic { err: String }, -} - -impl fmt::Display for CashuError { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - Self::Generic { err } => write!(f, "{err}"), - } - } -} - -impl From for CashuError { - fn from(err: cashu::error::Error) -> Self { - Self::Generic { - err: err.to_string(), - } - } -} - -impl From for CashuError { - fn from(err: url::ParseError) -> Self { - Self::Generic { - err: err.to_string(), - } - } -} - -impl From for CashuError { - fn from(err: cashu::error::wallet::Error) -> Self { - Self::Generic { - err: err.to_string(), - } - } -} - -impl From for CashuError { - fn from(err: ParseOrSemanticError) -> Self { - Self::Generic { - err: err.to_string(), - } - } -} - -impl From for CashuError { - fn from(err: cashu::nuts::nut02::Error) -> Self { - Self::Generic { - err: err.to_string(), - } - } -} - -impl From for CashuError { - fn from(err: cashu::url::Error) -> Self { - Self::Generic { - err: err.to_string(), - } - } -} diff --git a/bindings/cashu-ffi/src/lib.rs b/bindings/cashu-ffi/src/lib.rs deleted file mode 100644 index e0be90db..00000000 --- a/bindings/cashu-ffi/src/lib.rs +++ /dev/null @@ -1,38 +0,0 @@ -mod error; -mod nuts; -mod types; - -mod ffi { - pub use cashu::types::InvoiceStatus; - - pub use crate::error::CashuError; - pub use crate::nuts::nut00::blinded_message::BlindedMessage; - pub use crate::nuts::nut00::blinded_signature::BlindedSignature; - pub use crate::nuts::nut00::mint_proofs::MintProofs; - pub use crate::nuts::nut00::premint_secrets::PreMintSecrets; - pub use crate::nuts::nut00::proof::mint::Proof as MintProof; - pub use crate::nuts::nut00::proof::Proof; - pub use crate::nuts::nut00::token::{CurrencyUnit, Token}; - pub use crate::nuts::nut01::key_pair::KeyPair; - pub use crate::nuts::nut01::keys::{Keys, KeysResponse}; - pub use crate::nuts::nut01::public_key::PublicKey; - pub use crate::nuts::nut01::secret_key::SecretKey; - pub use crate::nuts::nut02::{Id, KeySet, KeySetResponse, MintKeySet}; - pub use crate::nuts::nut03::{SwapRequest, SwapResponse}; - pub use crate::nuts::nut04::{ - MintBolt11Request, MintBolt11Response, MintQuoteBolt11Request, MintQuoteBolt11Response, - }; - pub use crate::nuts::nut05::{ - MeltBolt11Request as Nut05MeltBolt11Request, MeltBolt11Response as Nut05MeltBolt11Response, - MeltQuoteBolt11Request, MeltQuoteBolt11Response, - }; - pub use crate::nuts::nut06::{MintInfo, MintVersion}; - pub use crate::nuts::nut07::{CheckSpendableRequest, CheckSpendableResponse}; - pub use crate::nuts::nut08::{MeltBolt11Request, MeltBolt11Response}; - pub use crate::types::{Amount, Bolt11Invoice, KeySetInfo, MeltQuote, MintQuote, Secret}; - - // UDL - uniffi::include_scaffolding!("cashu"); -} - -pub use ffi::*; diff --git a/bindings/cashu-ffi/src/nuts/mod.rs b/bindings/cashu-ffi/src/nuts/mod.rs deleted file mode 100644 index add1d404..00000000 --- a/bindings/cashu-ffi/src/nuts/mod.rs +++ /dev/null @@ -1,9 +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 nut08; diff --git a/bindings/cashu-ffi/src/nuts/nut00/blinded_message.rs b/bindings/cashu-ffi/src/nuts/nut00/blinded_message.rs deleted file mode 100644 index fe8466b7..00000000 --- a/bindings/cashu-ffi/src/nuts/nut00/blinded_message.rs +++ /dev/null @@ -1,54 +0,0 @@ -use std::ops::Deref; -use std::sync::Arc; - -use cashu::nuts::BlindedMessage as BlindedMessageSdk; - -use crate::nuts::nut01::public_key::PublicKey; -use crate::{Amount, Id}; - -pub struct BlindedMessage { - inner: BlindedMessageSdk, -} - -impl Deref for BlindedMessage { - type Target = BlindedMessageSdk; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl BlindedMessage { - pub fn new(keyset_id: Arc, amount: Arc, b: Arc) -> Self { - Self { - inner: BlindedMessageSdk { - keyset_id: *keyset_id.as_ref().deref(), - amount: *amount.as_ref().deref(), - b: b.as_ref().into(), - }, - } - } - - pub fn amount(&self) -> Arc { - Arc::new(self.inner.amount.into()) - } - - pub fn keyset_id(&self) -> Arc { - Arc::new(self.inner.keyset_id.into()) - } - - pub fn b(&self) -> Arc { - Arc::new(self.inner.b.clone().into()) - } -} - -impl From<&BlindedMessage> for BlindedMessageSdk { - fn from(blinded_message: &BlindedMessage) -> BlindedMessageSdk { - blinded_message.inner.clone() - } -} - -impl From for BlindedMessage { - fn from(inner: BlindedMessageSdk) -> BlindedMessage { - BlindedMessage { inner } - } -} diff --git a/bindings/cashu-ffi/src/nuts/nut00/blinded_signature.rs b/bindings/cashu-ffi/src/nuts/nut00/blinded_signature.rs deleted file mode 100644 index 5ec154ec..00000000 --- a/bindings/cashu-ffi/src/nuts/nut00/blinded_signature.rs +++ /dev/null @@ -1,55 +0,0 @@ -use std::ops::Deref; -use std::sync::Arc; - -use cashu::nuts::nut00::BlindedSignature as BlindedSignatureSdk; - -use crate::{Amount, Id, PublicKey}; - -pub struct BlindedSignature { - inner: BlindedSignatureSdk, -} - -impl Deref for BlindedSignature { - type Target = BlindedSignatureSdk; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl BlindedSignature { - pub fn new(keyset_id: Arc, amount: Arc, c: Arc) -> Self { - Self { - inner: BlindedSignatureSdk { - keyset_id: *keyset_id.as_ref().deref(), - amount: *amount.as_ref().deref(), - c: c.as_ref().into(), - }, - } - } - - pub fn keyset_id(&self) -> Arc { - Arc::new(self.inner.keyset_id.into()) - } - - pub fn amount(&self) -> Arc { - Arc::new(self.inner.amount.into()) - } - - pub fn c(&self) -> Arc { - Arc::new(self.inner.c.clone().into()) - } -} - -impl From<&BlindedSignature> for BlindedSignatureSdk { - fn from(blinded_signature: &BlindedSignature) -> BlindedSignatureSdk { - blinded_signature.inner.clone() - } -} - -impl From for BlindedSignature { - fn from(blinded_signature: BlindedSignatureSdk) -> BlindedSignature { - BlindedSignature { - inner: blinded_signature, - } - } -} diff --git a/bindings/cashu-ffi/src/nuts/nut00/mint_proofs.rs b/bindings/cashu-ffi/src/nuts/nut00/mint_proofs.rs deleted file mode 100644 index 53c75b60..00000000 --- a/bindings/cashu-ffi/src/nuts/nut00/mint_proofs.rs +++ /dev/null @@ -1,56 +0,0 @@ -use std::ops::Deref; -use std::str::FromStr; -use std::sync::Arc; - -use cashu::nuts::nut00::MintProofs as MintProofsSdk; -use cashu::url::UncheckedUrl; - -use crate::error::Result; -use crate::Proof; - -pub struct MintProofs { - inner: MintProofsSdk, -} - -impl Deref for MintProofs { - type Target = MintProofsSdk; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl MintProofs { - pub fn new(mint: String, proofs: Vec>) -> Result { - let mint = UncheckedUrl::from_str(&mint)?; - let proofs = proofs.iter().map(|p| p.as_ref().deref().clone()).collect(); - - Ok(Self { - inner: MintProofsSdk { mint, proofs }, - }) - } - - pub fn url(&self) -> String { - self.inner.mint.to_string() - } - - pub fn proofs(&self) -> Vec> { - self.inner - .proofs - .clone() - .into_iter() - .map(|p| Arc::new(p.into())) - .collect() - } -} - -impl From<&MintProofs> for MintProofsSdk { - fn from(mint_proofs: &MintProofs) -> MintProofsSdk { - mint_proofs.inner.clone() - } -} - -impl From for MintProofs { - fn from(inner: MintProofsSdk) -> MintProofs { - MintProofs { inner } - } -} diff --git a/bindings/cashu-ffi/src/nuts/nut00/mod.rs b/bindings/cashu-ffi/src/nuts/nut00/mod.rs deleted file mode 100644 index fb559e3c..00000000 --- a/bindings/cashu-ffi/src/nuts/nut00/mod.rs +++ /dev/null @@ -1,6 +0,0 @@ -pub mod blinded_message; -pub mod blinded_signature; -pub mod mint_proofs; -pub mod premint_secrets; -pub mod proof; -pub mod token; diff --git a/bindings/cashu-ffi/src/nuts/nut00/premint_secrets.rs b/bindings/cashu-ffi/src/nuts/nut00/premint_secrets.rs deleted file mode 100644 index 5bdd4903..00000000 --- a/bindings/cashu-ffi/src/nuts/nut00/premint_secrets.rs +++ /dev/null @@ -1,78 +0,0 @@ -use std::ops::Deref; -use std::sync::Arc; - -use cashu::nuts::nut00::wallet::PreMintSecrets as PreMintSecretsSdk; - -use crate::error::Result; -use crate::{Amount, BlindedMessage, Id, Secret, SecretKey}; - -pub struct PreMintSecrets { - inner: PreMintSecretsSdk, -} - -impl Deref for PreMintSecrets { - type Target = PreMintSecretsSdk; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl PreMintSecrets { - pub fn random(keyset_id: Arc, amount: Arc) -> Result { - Ok(Self { - inner: PreMintSecretsSdk::random( - *keyset_id.as_ref().deref(), - *amount.as_ref().deref(), - )?, - }) - } - - pub fn blank(keyset_id: Arc, fee_reserve: Arc) -> Result { - Ok(Self { - inner: PreMintSecretsSdk::blank( - *keyset_id.as_ref().deref(), - *fee_reserve.as_ref().deref(), - )?, - }) - } - - pub fn blinded_messages(&self) -> Vec> { - self.inner - .iter() - .map(|premint| Arc::new(premint.blinded_message.clone().into())) - .collect() - } - - pub fn secrets(&self) -> Vec> { - self.inner - .iter() - .map(|premint| Arc::new(premint.secret.clone().into())) - .collect() - } - - pub fn rs(&self) -> Vec> { - self.inner - .iter() - .map(|premint| Arc::new(premint.r.clone().into())) - .collect() - } - - pub fn amounts(&self) -> Vec> { - self.inner - .iter() - .map(|premint| Arc::new(premint.amount.into())) - .collect() - } -} - -impl From for PreMintSecrets { - fn from(inner: cashu::nuts::nut00::wallet::PreMintSecrets) -> PreMintSecrets { - PreMintSecrets { inner } - } -} - -impl From for cashu::nuts::nut00::wallet::PreMintSecrets { - fn from(blinded_messages: PreMintSecrets) -> cashu::nuts::nut00::wallet::PreMintSecrets { - blinded_messages.inner - } -} diff --git a/bindings/cashu-ffi/src/nuts/nut00/proof.rs b/bindings/cashu-ffi/src/nuts/nut00/proof.rs deleted file mode 100644 index 9cbb0a3a..00000000 --- a/bindings/cashu-ffi/src/nuts/nut00/proof.rs +++ /dev/null @@ -1,136 +0,0 @@ -use std::ops::Deref; -use std::sync::Arc; - -use cashu::nuts::nut00::Proof as ProofSdk; - -use crate::types::Secret; -use crate::{Amount, Id, PublicKey}; - -pub struct Proof { - inner: ProofSdk, -} - -impl Deref for Proof { - type Target = ProofSdk; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl Proof { - pub fn new( - amount: Arc, - secret: Arc, - c: Arc, - keyset_id: Arc, - ) -> Self { - Self { - inner: ProofSdk { - amount: *amount.as_ref().deref(), - secret: secret.as_ref().deref().clone(), - c: c.as_ref().deref().clone(), - keyset_id: *keyset_id.as_ref().deref(), - }, - } - } - - pub fn amount(&self) -> Arc { - Arc::new(self.inner.amount.into()) - } - - pub fn secret(&self) -> Arc { - Arc::new(self.inner.secret.clone().into()) - } - - pub fn c(&self) -> Arc { - Arc::new(self.inner.c.clone().into()) - } - - pub fn keyset_id(&self) -> Arc { - Arc::new(self.keyset_id.into()) - } -} - -impl From<&Proof> for ProofSdk { - fn from(proof: &Proof) -> ProofSdk { - ProofSdk { - amount: *proof.amount().as_ref().deref(), - secret: proof.secret().as_ref().deref().clone(), - c: proof.c().deref().into(), - keyset_id: proof.keyset_id, - } - } -} - -impl From for Proof { - fn from(inner: ProofSdk) -> Proof { - Proof { inner } - } -} - -pub mod mint { - use std::ops::Deref; - use std::sync::Arc; - - use cashu::nuts::nut00::mint::Proof as ProofSdk; - - use crate::types::Secret; - use crate::{Amount, Id, PublicKey}; - - pub struct Proof { - inner: ProofSdk, - } - - impl Deref for Proof { - type Target = ProofSdk; - fn deref(&self) -> &Self::Target { - &self.inner - } - } - - impl Proof { - pub fn new( - amount: Option>, - secret: Arc, - c: Option>, - keyset_id: Option>, - ) -> Self { - Self { - inner: ProofSdk { - amount: amount.map(|a| *a.as_ref().deref()), - secret: secret.as_ref().deref().clone(), - c: c.map(|c| c.as_ref().into()), - keyset_id: keyset_id.map(|id| *id.as_ref().deref()), - }, - } - } - - pub fn amount(&self) -> Option> { - self.inner.amount.map(|a| Arc::new(a.into())) - } - - pub fn secret(&self) -> Arc { - Arc::new(self.inner.secret.clone().into()) - } - - pub fn c(&self) -> Option> { - self.inner.c.clone().map(|c| Arc::new(c.into())) - } - - pub fn keyset_id(&self) -> Option> { - self.inner.keyset_id.map(|id| Arc::new(id.into())) - } - } - - impl From for Proof { - fn from(proof: ProofSdk) -> Proof { - Proof { inner: proof } - } - } - - impl From<&Proof> for ProofSdk { - fn from(proof: &Proof) -> ProofSdk { - proof.inner.clone() - } - } -} diff --git a/bindings/cashu-ffi/src/nuts/nut00/token.rs b/bindings/cashu-ffi/src/nuts/nut00/token.rs deleted file mode 100644 index d66ba562..00000000 --- a/bindings/cashu-ffi/src/nuts/nut00/token.rs +++ /dev/null @@ -1,106 +0,0 @@ -use std::fmt; -use std::str::FromStr; -use std::sync::Arc; - -use cashu::nuts::nut00::wallet::Token as TokenSdk; -use cashu::nuts::CurrencyUnit as CurrencyUnitSdk; -use cashu::url::UncheckedUrl; - -use crate::error::Result; -use crate::{MintProofs, Proof}; - -pub enum CurrencyUnit { - Sat(), - Usd(), - Custom { unit: String }, -} - -impl From<&CurrencyUnit> for CurrencyUnitSdk { - fn from(unit: &CurrencyUnit) -> CurrencyUnitSdk { - match unit { - CurrencyUnit::Sat() => CurrencyUnitSdk::Sat, - CurrencyUnit::Usd() => CurrencyUnitSdk::Usd, - CurrencyUnit::Custom { unit } => CurrencyUnitSdk::Custom(unit.clone()), - } - } -} - -impl From for CurrencyUnitSdk { - fn from(unit: CurrencyUnit) -> CurrencyUnitSdk { - match unit { - CurrencyUnit::Sat() => CurrencyUnitSdk::Sat, - CurrencyUnit::Usd() => CurrencyUnitSdk::Usd, - CurrencyUnit::Custom { unit } => CurrencyUnitSdk::Custom(unit.clone()), - } - } -} - -impl From for CurrencyUnit { - fn from(unit: CurrencyUnitSdk) -> CurrencyUnit { - match unit { - CurrencyUnitSdk::Sat => CurrencyUnit::Sat(), - CurrencyUnitSdk::Usd => CurrencyUnit::Usd(), - CurrencyUnitSdk::Custom(unit) => CurrencyUnit::Custom { unit: unit.clone() }, - } - } -} - -pub struct Token { - inner: TokenSdk, -} - -impl Token { - pub fn new( - mint: String, - proofs: Vec>, - memo: Option, - unit: Option, - ) -> Result { - let mint = UncheckedUrl::from_str(&mint)?; - let proofs = proofs.into_iter().map(|p| p.as_ref().into()).collect(); - - let unit = unit.map(|u| CurrencyUnitSdk::from_str(&u).unwrap_or_default()); - - Ok(Self { - inner: TokenSdk::new(mint, proofs, memo, unit)?, - }) - } - - pub fn token(&self) -> Vec> { - self.inner - .token - .clone() - .into_iter() - .map(|p| Arc::new(p.into())) - .collect() - } - - pub fn memo(&self) -> Option { - self.inner.memo.clone() - } - - pub fn unit(&self) -> Option { - self.inner - .unit - .clone() - .map(|u| Into::::into(u).to_string()) - } - - pub fn from_string(token: String) -> Result { - Ok(Self { - inner: TokenSdk::from_str(&token)?, - }) - } -} - -impl fmt::Display for Token { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{}", self.inner) - } -} - -impl From for Token { - fn from(inner: cashu::nuts::nut00::wallet::Token) -> Token { - Token { inner } - } -} diff --git a/bindings/cashu-ffi/src/nuts/nut01/key_pair.rs b/bindings/cashu-ffi/src/nuts/nut01/key_pair.rs deleted file mode 100644 index 80330a3b..00000000 --- a/bindings/cashu-ffi/src/nuts/nut01/key_pair.rs +++ /dev/null @@ -1,26 +0,0 @@ -use std::ops::Deref; -use std::sync::Arc; - -use cashu::nuts::nut01::mint::KeyPair as KeyPairSdk; - -use crate::{PublicKey, SecretKey}; - -pub struct KeyPair { - inner: KeyPairSdk, -} - -impl KeyPair { - pub fn from_secret_key(secret_key: Arc) -> Self { - Self { - inner: KeyPairSdk::from_secret_key(secret_key.as_ref().deref().clone()), - } - } - - pub fn secret_key(&self) -> Arc { - Arc::new(self.inner.secret_key.clone().into()) - } - - pub fn public_key(&self) -> Arc { - Arc::new(self.inner.public_key.clone().into()) - } -} diff --git a/bindings/cashu-ffi/src/nuts/nut01/keys.rs b/bindings/cashu-ffi/src/nuts/nut01/keys.rs deleted file mode 100644 index 1fb4d14a..00000000 --- a/bindings/cashu-ffi/src/nuts/nut01/keys.rs +++ /dev/null @@ -1,110 +0,0 @@ -use std::collections::HashMap; -use std::ops::Deref; -use std::sync::Arc; - -use cashu::nuts::nut01::{Keys as KeysSdk, KeysResponse as KeysResponseSdk}; -use cashu::Amount as AmountSdk; - -use crate::{Amount, KeySet, PublicKey}; - -pub struct Keys { - inner: KeysSdk, -} - -impl Deref for Keys { - type Target = KeysSdk; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for KeysSdk { - fn from(keys: Keys) -> KeysSdk { - keys.inner - } -} - -impl From for Keys { - fn from(keys: KeysSdk) -> Keys { - let keys = keys - .keys() - .into_iter() - .map(|(amount, pk)| (u64::from(amount).to_string(), Arc::new(pk.into()))) - .collect(); - - Keys::new(keys) - } -} - -impl Keys { - pub fn new(keys: HashMap>) -> Self { - let keys = keys - .into_iter() - .map(|(amount, pk)| { - ( - AmountSdk::from(amount.parse::().unwrap()), - pk.as_ref().into(), - ) - }) - .collect(); - - Self { - inner: KeysSdk::new(keys), - } - } - - pub fn keys(&self) -> HashMap> { - self.inner - .keys() - .into_iter() - .map(|(amount, pk)| (u64::from(amount).to_string(), Arc::new(pk.into()))) - .collect() - } - - pub fn amount_key(&self, amount: Arc) -> Option> { - self.inner - .amount_key(*amount.as_ref().deref()) - .map(|pk| Arc::new(pk.into())) - } - - pub fn as_hashmap(&self) -> HashMap { - self.inner - .as_hashmap() - .into_iter() - .map(|(amount, pk)| (u64::from(amount).to_string(), pk)) - .collect() - } -} - -pub struct KeysResponse { - inner: KeysResponseSdk, -} - -impl Deref for KeysResponse { - type Target = KeysResponseSdk; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for KeysResponseSdk { - fn from(keys: KeysResponse) -> KeysResponseSdk { - keys.inner - } -} - -impl From for KeysResponse { - fn from(keys: KeysResponseSdk) -> KeysResponse { - KeysResponse { inner: keys } - } -} - -impl KeysResponse { - pub fn new(keysets: Vec>) -> Self { - Self { - inner: KeysResponseSdk { - keysets: keysets.iter().map(|k| k.as_ref().deref().clone()).collect(), - }, - } - } -} diff --git a/bindings/cashu-ffi/src/nuts/nut01/mod.rs b/bindings/cashu-ffi/src/nuts/nut01/mod.rs deleted file mode 100644 index 4a7d3d2d..00000000 --- a/bindings/cashu-ffi/src/nuts/nut01/mod.rs +++ /dev/null @@ -1,4 +0,0 @@ -pub mod key_pair; -pub mod keys; -pub mod public_key; -pub mod secret_key; diff --git a/bindings/cashu-ffi/src/nuts/nut01/public_key.rs b/bindings/cashu-ffi/src/nuts/nut01/public_key.rs deleted file mode 100644 index 01cdd3c3..00000000 --- a/bindings/cashu-ffi/src/nuts/nut01/public_key.rs +++ /dev/null @@ -1,40 +0,0 @@ -use std::ops::Deref; - -use cashu::nuts::nut01::PublicKey as PublicKeySdk; - -use crate::error::Result; - -pub struct PublicKey { - inner: PublicKeySdk, -} - -impl From for PublicKey { - fn from(inner: PublicKeySdk) -> Self { - Self { inner } - } -} - -impl From<&PublicKey> for PublicKeySdk { - fn from(pk: &PublicKey) -> PublicKeySdk { - pk.inner.clone() - } -} - -impl Deref for PublicKey { - type Target = PublicKeySdk; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl PublicKey { - pub fn from_hex(hex: String) -> Result { - Ok(Self { - inner: PublicKeySdk::from_hex(hex)?, - }) - } - - pub fn to_hex(&self) -> Result { - Ok(self.inner.to_hex()) - } -} diff --git a/bindings/cashu-ffi/src/nuts/nut01/secret_key.rs b/bindings/cashu-ffi/src/nuts/nut01/secret_key.rs deleted file mode 100644 index f85b4b53..00000000 --- a/bindings/cashu-ffi/src/nuts/nut01/secret_key.rs +++ /dev/null @@ -1,34 +0,0 @@ -use std::ops::Deref; - -use cashu::nuts::nut01::SecretKey as SecretKeySdk; - -use crate::error::Result; - -pub struct SecretKey { - inner: SecretKeySdk, -} - -impl Deref for SecretKey { - type Target = SecretKeySdk; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for SecretKey { - fn from(inner: SecretKeySdk) -> Self { - Self { inner } - } -} - -impl From for SecretKeySdk { - fn from(sk: SecretKey) -> SecretKeySdk { - sk.inner - } -} - -impl SecretKey { - pub fn to_hex(&self) -> Result { - Ok(self.inner.to_hex()) - } -} diff --git a/bindings/cashu-ffi/src/nuts/nut02/key_set.rs b/bindings/cashu-ffi/src/nuts/nut02/key_set.rs deleted file mode 100644 index 5b84cfb7..00000000 --- a/bindings/cashu-ffi/src/nuts/nut02/key_set.rs +++ /dev/null @@ -1,113 +0,0 @@ -use std::ops::Deref; -use std::str::FromStr; -use std::sync::Arc; - -use cashu::nuts::{ - CurrencyUnit, Id as IdSdk, KeySet as KeySetSdk, KeysetResponse as KeysetResponseSdk, -}; - -use crate::error::Result; -use crate::nuts::nut01::keys::Keys; -use crate::KeySetInfo; - -pub struct Id { - inner: IdSdk, -} - -impl Deref for Id { - type Target = IdSdk; - fn deref(&self) -> &Self::Target { - &self.inner - } -} -impl Id { - pub fn new(id: String) -> Result { - Ok(Self { - inner: IdSdk::from_str(&id)?, - }) - } -} - -impl From for Id { - fn from(inner: IdSdk) -> Id { - Id { inner } - } -} - -impl From for IdSdk { - fn from(id: Id) -> IdSdk { - id.inner - } -} - -pub struct KeySet { - inner: KeySetSdk, -} - -impl Deref for KeySet { - type Target = KeySetSdk; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl KeySet { - pub fn new(id: Arc, unit: String, keys: Arc) -> Self { - Self { - inner: KeySetSdk { - id: *id.as_ref().deref(), - unit: CurrencyUnit::from_str(&unit).unwrap(), - keys: keys.as_ref().deref().clone(), - }, - } - } - - pub fn id(&self) -> Arc { - Arc::new(self.inner.id.into()) - } - - pub fn unit(&self) -> String { - self.inner.unit.clone().to_string() - } - - pub fn keys(&self) -> Arc { - Arc::new(self.inner.keys.clone().into()) - } -} - -impl From for KeySet { - fn from(inner: cashu::nuts::nut02::KeySet) -> KeySet { - KeySet { inner } - } -} - -pub struct KeySetResponse { - inner: KeysetResponseSdk, -} - -impl KeySetResponse { - pub fn new(keyset_ids: Vec>) -> Self { - let keysets = keyset_ids - .into_iter() - .map(|ki| ki.as_ref().deref().clone()) - .collect(); - Self { - inner: KeysetResponseSdk { keysets }, - } - } - - pub fn keysets(&self) -> Vec> { - self.inner - .clone() - .keysets - .into_iter() - .map(|keyset_info| Arc::new(keyset_info.into())) - .collect() - } -} - -impl From for KeySetResponse { - fn from(inner: KeysetResponseSdk) -> KeySetResponse { - KeySetResponse { inner } - } -} diff --git a/bindings/cashu-ffi/src/nuts/nut02/mint_keyset.rs b/bindings/cashu-ffi/src/nuts/nut02/mint_keyset.rs deleted file mode 100644 index c83d5317..00000000 --- a/bindings/cashu-ffi/src/nuts/nut02/mint_keyset.rs +++ /dev/null @@ -1,35 +0,0 @@ -use std::ops::Deref; -use std::str::FromStr; - -use cashu::nuts::nut02::mint::KeySet as KeySetSdk; -use cashu::nuts::CurrencyUnit; - -pub struct MintKeySet { - inner: KeySetSdk, -} - -impl Deref for MintKeySet { - type Target = KeySetSdk; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl MintKeySet { - pub fn generate(secret: String, unit: String, derivation_path: String, max_order: u8) -> Self { - Self { - inner: KeySetSdk::generate( - secret.as_bytes(), - CurrencyUnit::from_str(&unit).unwrap(), - &derivation_path, - max_order, - ), - } - } -} - -impl From for MintKeySet { - fn from(inner: cashu::nuts::nut02::mint::KeySet) -> MintKeySet { - MintKeySet { inner } - } -} diff --git a/bindings/cashu-ffi/src/nuts/nut02/mod.rs b/bindings/cashu-ffi/src/nuts/nut02/mod.rs deleted file mode 100644 index 7836f6e2..00000000 --- a/bindings/cashu-ffi/src/nuts/nut02/mod.rs +++ /dev/null @@ -1,5 +0,0 @@ -pub mod key_set; -pub mod mint_keyset; - -pub use key_set::{Id, KeySet, KeySetResponse}; -pub use mint_keyset::MintKeySet; diff --git a/bindings/cashu-ffi/src/nuts/nut03/mod.rs b/bindings/cashu-ffi/src/nuts/nut03/mod.rs deleted file mode 100644 index 87287e0d..00000000 --- a/bindings/cashu-ffi/src/nuts/nut03/mod.rs +++ /dev/null @@ -1,82 +0,0 @@ -use std::ops::Deref; -use std::sync::Arc; - -use cashu::nuts::{SwapRequest as SwapRequestSdk, SwapResponse as SwapResponseSdk}; - -use crate::{Amount, BlindedMessage, BlindedSignature, Proof}; - -pub struct SwapRequest { - inner: SwapRequestSdk, -} - -impl Deref for SwapRequest { - type Target = SwapRequestSdk; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl SwapRequest { - pub fn new(proofs: Vec>, outputs: Vec>) -> Self { - let proofs = proofs.into_iter().map(|p| p.as_ref().into()).collect(); - let outputs = outputs.into_iter().map(|o| o.as_ref().into()).collect(); - - Self { - inner: SwapRequestSdk::new(proofs, outputs), - } - } - - pub fn proofs(&self) -> Vec> { - self.inner - .inputs - .clone() - .into_iter() - .map(|p| Arc::new(p.into())) - .collect() - } - - pub fn outputs(&self) -> Vec> { - self.inner - .outputs - .clone() - .into_iter() - .map(|o| Arc::new(o.into())) - .collect() - } - - pub fn proofs_amount(&self) -> Arc { - Arc::new(self.inner.input_amount().into()) - } - - pub fn output_amount(&self) -> Arc { - Arc::new(self.inner.output_amount().into()) - } -} - -pub struct SwapResponse { - inner: SwapResponseSdk, -} - -impl SwapResponse { - pub fn new(signatures: Vec>) -> Self { - let signatures = signatures.into_iter().map(|p| p.as_ref().into()).collect(); - Self { - inner: SwapResponseSdk::new(signatures), - } - } - - pub fn signatures(&self) -> Vec> { - self.inner - .signatures - .clone() - .into_iter() - .map(|p| Arc::new(p.into())) - .collect() - } -} - -impl From for SwapResponse { - fn from(inner: SwapResponseSdk) -> SwapResponse { - SwapResponse { inner } - } -} diff --git a/bindings/cashu-ffi/src/nuts/nut04/mod.rs b/bindings/cashu-ffi/src/nuts/nut04/mod.rs deleted file mode 100644 index 48cccd32..00000000 --- a/bindings/cashu-ffi/src/nuts/nut04/mod.rs +++ /dev/null @@ -1,168 +0,0 @@ -use std::ops::Deref; -use std::str::FromStr; -use std::sync::Arc; - -use cashu::nuts::{ - CurrencyUnit, MintBolt11Request as MintBolt11RequestSdk, - MintBolt11Response as MintBolt11ResponseSdk, - MintQuoteBolt11Request as MintQuoteBolt11RequestSdk, - MintQuoteBolt11Response as MintQuoteBolt11ResponseSdk, -}; - -use crate::{Amount, BlindedMessage, BlindedSignature}; - -pub struct MintQuoteBolt11Request { - inner: MintQuoteBolt11RequestSdk, -} - -impl Deref for MintQuoteBolt11Request { - type Target = MintQuoteBolt11RequestSdk; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl MintQuoteBolt11Request { - pub fn new(amount: Arc, unit: String) -> Self { - Self { - inner: MintQuoteBolt11RequestSdk { - amount: *amount.as_ref().deref(), - unit: CurrencyUnit::from_str(&unit).unwrap(), - }, - } - } - - pub fn amount(&self) -> Arc { - Arc::new(self.inner.amount.into()) - } - - pub fn unit(&self) -> Arc { - Arc::new(self.inner.clone().unit) - } -} - -impl From for MintQuoteBolt11Request { - fn from(inner: MintQuoteBolt11RequestSdk) -> MintQuoteBolt11Request { - MintQuoteBolt11Request { inner } - } -} - -pub struct MintQuoteBolt11Response { - inner: MintQuoteBolt11ResponseSdk, -} - -impl Deref for MintQuoteBolt11Response { - type Target = MintQuoteBolt11ResponseSdk; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl MintQuoteBolt11Response { - pub fn new(quote: String, request: String, paid: bool, expiry: u64) -> Self { - Self { - inner: MintQuoteBolt11ResponseSdk { - quote, - request, - paid, - expiry, - }, - } - } - - pub fn quote(&self) -> String { - self.quote.clone() - } - - pub fn request(&self) -> String { - self.request.clone() - } - - pub fn paid(&self) -> bool { - self.paid - } - - pub fn expiry(&self) -> u64 { - self.expiry - } -} - -impl From for MintQuoteBolt11Response { - fn from(inner: MintQuoteBolt11ResponseSdk) -> MintQuoteBolt11Response { - MintQuoteBolt11Response { inner } - } -} - -pub struct MintBolt11Request { - inner: MintBolt11RequestSdk, -} - -impl Deref for MintBolt11Request { - type Target = MintBolt11RequestSdk; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl MintBolt11Request { - pub fn new(quote: String, outputs: Vec>) -> Self { - Self { - inner: MintBolt11RequestSdk { - quote, - outputs: outputs.iter().map(|o| o.as_ref().deref().clone()).collect(), - }, - } - } - - pub fn quote(&self) -> String { - self.quote.clone() - } - - pub fn outputs(&self) -> Vec> { - self.inner - .outputs - .clone() - .into_iter() - .map(|o| Arc::new(o.into())) - .collect() - } -} - -pub struct MintBolt11Response { - inner: MintBolt11ResponseSdk, -} - -impl Deref for MintBolt11Response { - type Target = MintBolt11ResponseSdk; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl MintBolt11Response { - pub fn new(signatures: Vec>) -> Self { - Self { - inner: MintBolt11ResponseSdk { - signatures: signatures - .into_iter() - .map(|s| s.as_ref().deref().clone()) - .collect(), - }, - } - } - - pub fn signatures(&self) -> Vec> { - self.inner - .signatures - .clone() - .into_iter() - .map(|o| Arc::new(o.into())) - .collect() - } -} - -impl From for MintBolt11Response { - fn from(inner: MintBolt11ResponseSdk) -> MintBolt11Response { - MintBolt11Response { inner } - } -} diff --git a/bindings/cashu-ffi/src/nuts/nut05/mod.rs b/bindings/cashu-ffi/src/nuts/nut05/mod.rs deleted file mode 100644 index abd2ca92..00000000 --- a/bindings/cashu-ffi/src/nuts/nut05/mod.rs +++ /dev/null @@ -1,143 +0,0 @@ -use std::ops::Deref; -use std::str::FromStr; -use std::sync::Arc; - -use cashu::nuts::{ - CurrencyUnit, MeltBolt11Request as MeltBolt11RequestSdk, - MeltBolt11Response as MeltBolt11ResponseSdk, - MeltQuoteBolt11Request as MeltQuoteBolt11RequestSdk, - MeltQuoteBolt11Response as MeltQuoteBolt11ResponseSdk, -}; -use cashu::Bolt11Invoice; - -use crate::error::Result; -use crate::{BlindedMessage, BlindedSignature, Proof}; - -pub struct MeltQuoteBolt11Response { - inner: MeltQuoteBolt11ResponseSdk, -} - -impl MeltQuoteBolt11Response { - pub fn new( - quote: String, - amount: u64, - fee_reserve: u64, - paid: bool, - expiry: u64, - ) -> Result { - Ok(Self { - inner: MeltQuoteBolt11ResponseSdk { - quote, - amount, - fee_reserve, - paid, - expiry, - }, - }) - } - - pub fn quote(&self) -> String { - self.inner.quote.clone() - } - - pub fn amount(&self) -> u64 { - self.inner.amount - } - - pub fn fee_reserve(&self) -> u64 { - self.inner.fee_reserve - } - - pub fn paid(&self) -> bool { - self.inner.paid - } - - pub fn expiry(&self) -> u64 { - self.inner.expiry - } -} - -pub struct MeltQuoteBolt11Request { - inner: MeltQuoteBolt11RequestSdk, -} - -impl MeltQuoteBolt11Request { - pub fn new(request: String, unit: String) -> Result { - Ok(Self { - inner: MeltQuoteBolt11RequestSdk { - request: Bolt11Invoice::from_str(&request)?, - unit: CurrencyUnit::from_str(&unit)?, - }, - }) - } - - pub fn request(&self) -> String { - self.inner.request.to_string() - } - - pub fn unit(&self) -> String { - self.inner.unit.to_string() - } -} - -pub struct MeltBolt11Request { - inner: MeltBolt11RequestSdk, -} - -impl MeltBolt11Request { - pub fn new( - quote: String, - inputs: Vec>, - outputs: Option>>, - ) -> Result { - Ok(Self { - inner: MeltBolt11RequestSdk { - quote, - inputs: inputs.into_iter().map(|p| p.as_ref().into()).collect(), - outputs: outputs - .map(|o| o.into_iter().map(|p| p.as_ref().deref().clone()).collect()), - }, - }) - } - - pub fn inputs(&self) -> Vec> { - self.inner - .inputs - .clone() - .into_iter() - .map(|p| Arc::new(p.into())) - .collect() - } - - pub fn quote(&self) -> String { - self.inner.quote.clone() - } -} - -pub struct MeltBolt11Response { - inner: MeltBolt11ResponseSdk, -} - -impl MeltBolt11Response { - pub fn new( - paid: bool, - payment_preimage: Option, - change: Option>>, - ) -> Self { - Self { - inner: MeltBolt11ResponseSdk { - paid, - payment_preimage, - change: change.map(|c| c.into_iter().map(|b| b.as_ref().deref().clone()).collect()), - }, - } - } - - pub fn paid(&self) -> bool { - self.inner.paid - } - - pub fn payment_preimage(&self) -> Option { - self.inner.payment_preimage.clone() - } -} diff --git a/bindings/cashu-ffi/src/nuts/nut06.rs b/bindings/cashu-ffi/src/nuts/nut06.rs deleted file mode 100644 index f723bd4f..00000000 --- a/bindings/cashu-ffi/src/nuts/nut06.rs +++ /dev/null @@ -1,134 +0,0 @@ -use std::ops::Deref; -use std::sync::Arc; - -use cashu::nuts::{MintInfo as MintInfoSdk, MintVersion as MintVersionSdk, Nuts as NutsSdk}; - -use crate::PublicKey; - -pub struct MintVersion { - inner: MintVersionSdk, -} - -impl MintVersion { - pub fn new(name: String, version: String) -> Self { - Self { - inner: MintVersionSdk { name, version }, - } - } - - pub fn name(&self) -> String { - self.inner.name.clone() - } - - pub fn version(&self) -> String { - self.inner.version.clone() - } -} - -impl From<&MintVersion> for MintVersionSdk { - fn from(mint_version: &MintVersion) -> MintVersionSdk { - mint_version.inner.clone() - } -} - -impl From for MintVersion { - fn from(inner: MintVersionSdk) -> MintVersion { - MintVersion { inner } - } -} - -impl Deref for MintVersion { - type Target = MintVersionSdk; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -pub struct MintInfo { - inner: MintInfoSdk, -} - -impl MintInfo { - #[allow(clippy::too_many_arguments)] - pub fn new( - name: Option, - pubkey: Option>, - version: Option>, - description: Option, - description_long: Option, - contact: Option>>, - // TODO: Should be a nuts type - _nuts: String, - motd: Option, - ) -> Self { - let pubkey = pubkey.map(|p| p.as_ref().deref().clone()); - - Self { - inner: MintInfoSdk { - name, - pubkey, - version: version.map(|v| v.deref().into()), - description, - description_long, - contact, - nuts: NutsSdk::default(), - motd, - }, - } - } - - pub fn name(&self) -> Option { - self.inner.name.clone() - } - - pub fn pubkey(&self) -> Option> { - self.inner.pubkey.clone().map(|p| Arc::new(p.into())) - } - - pub fn version(&self) -> Option> { - self.inner.version.clone().map(|v| Arc::new(v.into())) - } - - pub fn description(&self) -> Option { - self.inner.description.clone() - } - - pub fn description_long(&self) -> Option { - self.inner.description_long.clone() - } - - pub fn contact(&self) -> Option>> { - self.inner.contact.clone() - } - - pub fn nuts(&self) -> Arc { - Arc::new(self.inner.nuts.clone().into()) - } - - pub fn motd(&self) -> Option { - self.inner.motd.clone() - } -} - -impl From for MintInfo { - fn from(inner: MintInfoSdk) -> MintInfo { - MintInfo { inner } - } -} - -pub struct Nuts { - inner: NutsSdk, -} - -impl Deref for Nuts { - type Target = NutsSdk; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for Nuts { - fn from(inner: NutsSdk) -> Nuts { - Nuts { inner } - } -} diff --git a/bindings/cashu-ffi/src/nuts/nut07/mod.rs b/bindings/cashu-ffi/src/nuts/nut07/mod.rs deleted file mode 100644 index b4ad68c1..00000000 --- a/bindings/cashu-ffi/src/nuts/nut07/mod.rs +++ /dev/null @@ -1,65 +0,0 @@ -use std::ops::Deref; -use std::sync::Arc; - -use cashu::nuts::nut07::{ - CheckSpendableRequest as CheckSpendableRequestSdk, - CheckSpendableResponse as CheckSpendableResponseSdk, -}; - -use crate::nuts::nut00::proof::mint::Proof; - -pub struct CheckSpendableRequest { - inner: CheckSpendableRequestSdk, -} - -impl Deref for CheckSpendableRequest { - type Target = CheckSpendableRequestSdk; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl CheckSpendableRequest { - pub fn new(proofs: Vec>) -> Self { - Self { - inner: CheckSpendableRequestSdk { - proofs: proofs.into_iter().map(|p| p.as_ref().into()).collect(), - }, - } - } - - pub fn proofs(&self) -> Vec> { - self.inner - .proofs - .clone() - .into_iter() - .map(|p| Arc::new(p.into())) - .collect() - } -} - -pub struct CheckSpendableResponse { - inner: CheckSpendableResponseSdk, -} - -impl CheckSpendableResponse { - pub fn new(spendable: Vec, pending: Vec) -> Self { - Self { - inner: CheckSpendableResponseSdk { spendable, pending }, - } - } - - pub fn spendable(&self) -> Vec { - self.inner.spendable.clone() - } - - pub fn pending(&self) -> Vec { - self.inner.pending.clone() - } -} - -impl From for CheckSpendableResponse { - fn from(inner: cashu::nuts::nut07::CheckSpendableResponse) -> CheckSpendableResponse { - CheckSpendableResponse { inner } - } -} diff --git a/bindings/cashu-ffi/src/nuts/nut08/mod.rs b/bindings/cashu-ffi/src/nuts/nut08/mod.rs deleted file mode 100644 index 4b6537ff..00000000 --- a/bindings/cashu-ffi/src/nuts/nut08/mod.rs +++ /dev/null @@ -1,112 +0,0 @@ -use std::ops::Deref; -use std::sync::Arc; - -use cashu::nuts::nut08::{ - MeltBolt11Request as MeltBolt11RequestSdk, MeltBolt11Response as MeltBolt11ResponseSdk, -}; - -use crate::error::Result; -use crate::{BlindedMessage, BlindedSignature, Proof}; - -pub struct MeltBolt11Request { - inner: MeltBolt11RequestSdk, -} - -impl Deref for MeltBolt11Request { - type Target = MeltBolt11RequestSdk; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl MeltBolt11Request { - pub fn new( - quote: String, - proofs: Vec>, - outputs: Option>>, - ) -> Result { - Ok(Self { - inner: MeltBolt11RequestSdk { - quote, - inputs: proofs.iter().map(|p| p.as_ref().into()).collect(), - outputs: outputs - .map(|outputs| outputs.into_iter().map(|o| o.as_ref().into()).collect()), - }, - }) - } - - pub fn inputs(&self) -> Vec> { - self.inner - .inputs - .clone() - .into_iter() - .map(|o| Arc::new(o.into())) - .collect() - } - - pub fn quote(&self) -> String { - self.inner.quote.clone() - } - - pub fn outputs(&self) -> Option>> { - self.inner - .outputs - .clone() - .map(|outputs| outputs.into_iter().map(|o| Arc::new(o.into())).collect()) - } -} - -pub struct MeltBolt11Response { - inner: MeltBolt11ResponseSdk, -} - -impl Deref for MeltBolt11Response { - type Target = MeltBolt11ResponseSdk; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for MeltBolt11Response { - fn from(inner: cashu::nuts::nut08::MeltBolt11Response) -> MeltBolt11Response { - MeltBolt11Response { inner } - } -} - -impl From for cashu::nuts::nut08::MeltBolt11Response { - fn from(res: MeltBolt11Response) -> cashu::nuts::nut08::MeltBolt11Response { - res.inner - } -} - -impl MeltBolt11Response { - pub fn new( - paid: bool, - payment_preimage: Option, - change: Option>>, - ) -> Self { - Self { - inner: MeltBolt11ResponseSdk { - paid, - payment_preimage, - change: change - .map(|change| change.into_iter().map(|bs| bs.as_ref().into()).collect()), - }, - } - } - - pub fn paid(&self) -> bool { - self.inner.paid - } - - pub fn payment_preimage(&self) -> Option { - self.inner.payment_preimage.clone() - } - - pub fn change(&self) -> Option>> { - self.inner - .change - .clone() - .map(|change| change.into_iter().map(|bs| Arc::new(bs.into())).collect()) - } -} diff --git a/bindings/cashu-ffi/src/types/amount.rs b/bindings/cashu-ffi/src/types/amount.rs deleted file mode 100644 index b4c136ec..00000000 --- a/bindings/cashu-ffi/src/types/amount.rs +++ /dev/null @@ -1,54 +0,0 @@ -use std::ops::Deref; -use std::sync::Arc; - -use cashu::Amount as AmountSdk; - -pub struct Amount { - inner: AmountSdk, -} - -impl Deref for Amount { - type Target = AmountSdk; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl Amount { - pub fn new(amount: u64) -> Self { - Self { - inner: AmountSdk::from(amount), - } - } - - pub const ZERO: Amount = Amount { - inner: AmountSdk::ZERO, - }; - - /// Split into parts that are powers of two - pub fn split(&self) -> Vec> { - self.inner - .split() - .into_iter() - .map(|a| Arc::new(a.into())) - .collect() - } -} - -impl From for Amount { - fn from(amount: AmountSdk) -> Amount { - Amount { inner: amount } - } -} - -impl From<&Amount> for AmountSdk { - fn from(amount: &Amount) -> AmountSdk { - amount.inner - } -} - -impl From for Amount { - fn from(amount: u64) -> Amount { - AmountSdk::from(amount).into() - } -} diff --git a/bindings/cashu-ffi/src/types/bolt11_invoice.rs b/bindings/cashu-ffi/src/types/bolt11_invoice.rs deleted file mode 100644 index 88840f53..00000000 --- a/bindings/cashu-ffi/src/types/bolt11_invoice.rs +++ /dev/null @@ -1,43 +0,0 @@ -use std::ops::Deref; -use std::str::FromStr; -use std::sync::Arc; - -use cashu::Bolt11Invoice as Bolt11InvoiceSdk; - -use crate::error::Result; -use crate::Amount; - -pub struct Bolt11Invoice { - inner: Bolt11InvoiceSdk, -} - -impl Deref for Bolt11Invoice { - type Target = Bolt11InvoiceSdk; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for Bolt11Invoice { - fn from(inner: Bolt11InvoiceSdk) -> Bolt11Invoice { - Bolt11Invoice { inner } - } -} - -impl Bolt11Invoice { - pub fn new(bolt11: String) -> Result { - Ok(Self { - inner: Bolt11InvoiceSdk::from_str(&bolt11)?, - }) - } - - pub fn as_string(&self) -> String { - self.inner.to_string() - } - - pub fn amount(&self) -> Option> { - self.inner - .amount_milli_satoshis() - .map(|a| Arc::new(Amount::from(a / 1000))) - } -} diff --git a/bindings/cashu-ffi/src/types/keyset_info.rs b/bindings/cashu-ffi/src/types/keyset_info.rs deleted file mode 100644 index 04e0b080..00000000 --- a/bindings/cashu-ffi/src/types/keyset_info.rs +++ /dev/null @@ -1,36 +0,0 @@ -use std::ops::Deref; -use std::str::FromStr; -use std::sync::Arc; - -use cashu::nuts::{CurrencyUnit, KeySetInfo as KeySetInfoSdk}; - -use crate::Id; - -pub struct KeySetInfo { - inner: KeySetInfoSdk, -} - -impl Deref for KeySetInfo { - type Target = KeySetInfoSdk; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for KeySetInfo { - fn from(inner: KeySetInfoSdk) -> KeySetInfo { - KeySetInfo { inner } - } -} - -impl KeySetInfo { - pub fn new(id: Arc, unit: String, active: bool) -> Self { - Self { - inner: KeySetInfoSdk { - id: *id.as_ref().deref(), - unit: CurrencyUnit::from_str(&unit).unwrap(), - active, - }, - } - } -} diff --git a/bindings/cashu-ffi/src/types/melt_quote.rs b/bindings/cashu-ffi/src/types/melt_quote.rs deleted file mode 100644 index b7092321..00000000 --- a/bindings/cashu-ffi/src/types/melt_quote.rs +++ /dev/null @@ -1,49 +0,0 @@ -use std::ops::Deref; -use std::str::FromStr; -use std::sync::Arc; - -use cashu::nuts::CurrencyUnit; -use cashu::types::MeltQuote as MeltQuoteSdk; - -use crate::{Amount, Bolt11Invoice}; - -pub struct MeltQuote { - inner: MeltQuoteSdk, -} - -impl Deref for MeltQuote { - type Target = MeltQuoteSdk; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for MeltQuote { - fn from(inner: MeltQuoteSdk) -> MeltQuote { - MeltQuote { inner } - } -} - -impl MeltQuote { - pub fn new( - id: String, - amount: Arc, - unit: String, - request: Arc, - fee_reserve: Arc, - paid: bool, - expiry: u64, - ) -> Self { - Self { - inner: MeltQuoteSdk { - id, - amount: *amount.as_ref().deref(), - unit: CurrencyUnit::from_str(&unit).unwrap(), - request: request.as_ref().deref().clone(), - fee_reserve: *fee_reserve.as_ref().deref(), - paid, - expiry, - }, - } - } -} diff --git a/bindings/cashu-ffi/src/types/mint_quote.rs b/bindings/cashu-ffi/src/types/mint_quote.rs deleted file mode 100644 index 7a2a7590..00000000 --- a/bindings/cashu-ffi/src/types/mint_quote.rs +++ /dev/null @@ -1,47 +0,0 @@ -use std::ops::Deref; -use std::str::FromStr; -use std::sync::Arc; - -use cashu::nuts::CurrencyUnit; -use cashu::types::MintQuote as MintQuoteSdk; - -use crate::{Amount, Bolt11Invoice}; - -pub struct MintQuote { - inner: MintQuoteSdk, -} - -impl Deref for MintQuote { - type Target = MintQuoteSdk; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for MintQuote { - fn from(inner: MintQuoteSdk) -> MintQuote { - MintQuote { inner } - } -} - -impl MintQuote { - pub fn new( - id: String, - amount: Arc, - unit: String, - request: Arc, - paid: bool, - expiry: u64, - ) -> Self { - Self { - inner: MintQuoteSdk { - id, - amount: *amount.as_ref().deref(), - unit: CurrencyUnit::from_str(&unit).unwrap(), - request: request.as_ref().deref().clone(), - paid, - expiry, - }, - } - } -} diff --git a/bindings/cashu-ffi/src/types/mint_quote_info.rs b/bindings/cashu-ffi/src/types/mint_quote_info.rs deleted file mode 100644 index 4d59b2e9..00000000 --- a/bindings/cashu-ffi/src/types/mint_quote_info.rs +++ /dev/null @@ -1,47 +0,0 @@ -use std::ops::Deref; -use std::str::FromStr; -use std::sync::Arc; - -use cashu::nuts::CurrencyUnit; -use cashu::types::MintQuote as MintQuoteSdk; - -use crate::{Amount, Bolt11Invoice}; - -pub struct MintQuote { - inner: MintQuoteSdk, -} - -impl Deref for MintQuote { - type Target = MintQuoteSdk; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for MintQuote { - fn from(inner: MintQuoteSdk) -> MintQuote { - MintQuote { inner } - } -} - -impl MintQuote { - pub fn new( - id: String, - amount: Arc, - unit: String, - request: Arc, - paid: bool, - expiry: u64, - ) -> Self { - Self { - inner: MintQuoteSdk { - id, - amount: amount.as_ref().deref().clone(), - unit: CurrencyUnit::from_str(&unit).unwrap(), - request: request.as_ref().deref().clone(), - paid, - expiry, - }, - } - } -} diff --git a/bindings/cashu-ffi/src/types/mod.rs b/bindings/cashu-ffi/src/types/mod.rs deleted file mode 100644 index 3240231d..00000000 --- a/bindings/cashu-ffi/src/types/mod.rs +++ /dev/null @@ -1,13 +0,0 @@ -pub mod amount; -pub mod bolt11_invoice; -pub mod keyset_info; -pub mod melt_quote; -pub mod mint_quote; -pub mod secret; - -pub use amount::Amount; -pub use bolt11_invoice::Bolt11Invoice; -pub use keyset_info::KeySetInfo; -pub use melt_quote::MeltQuote; -pub use mint_quote::MintQuote; -pub use secret::Secret; diff --git a/bindings/cashu-ffi/src/types/secret.rs b/bindings/cashu-ffi/src/types/secret.rs deleted file mode 100644 index e7e9e0f7..00000000 --- a/bindings/cashu-ffi/src/types/secret.rs +++ /dev/null @@ -1,44 +0,0 @@ -use std::ops::Deref; - -use cashu::secret::Secret as SecretSdk; - -pub struct Secret { - inner: SecretSdk, -} - -impl Deref for Secret { - type Target = SecretSdk; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl Default for Secret { - fn default() -> Self { - Self::new() - } -} - -impl Secret { - pub fn new() -> Self { - Self { - inner: SecretSdk::new(), - } - } - - pub fn as_bytes(&self) -> Vec { - self.inner.as_bytes().to_vec() - } -} - -impl From for Secret { - fn from(inner: SecretSdk) -> Secret { - Secret { inner } - } -} - -impl From for SecretSdk { - fn from(secret: Secret) -> SecretSdk { - secret.inner - } -} diff --git a/bindings/cashu-ffi/uniffi.toml b/bindings/cashu-ffi/uniffi.toml deleted file mode 100644 index 474c178c..00000000 --- a/bindings/cashu-ffi/uniffi.toml +++ /dev/null @@ -1,10 +0,0 @@ -[bindings.kotlin] -package_name = "cashu" -cdylib_name = "cashu_ffi" - -[bindings.swift] -ffi_module_filename = "cashuFFI" -cdylib_name = "cashu_ffi" - -[bindings.python] -cdylib_name = "cashu_ffi" diff --git a/bindings/cashu-js/.cargo/config.toml b/bindings/cashu-js/.cargo/config.toml deleted file mode 100644 index f4e8c002..00000000 --- a/bindings/cashu-js/.cargo/config.toml +++ /dev/null @@ -1,2 +0,0 @@ -[build] -target = "wasm32-unknown-unknown" diff --git a/bindings/cashu-js/.gitignore b/bindings/cashu-js/.gitignore deleted file mode 100644 index bed4e246..00000000 --- a/bindings/cashu-js/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -/target -**/*.rs.bk -Cargo.lock -bin/ -pkg/ -wasm-pack.log -*.tgz diff --git a/bindings/cashu-js/.npmignore b/bindings/cashu-js/.npmignore deleted file mode 100644 index 1147df4e..00000000 --- a/bindings/cashu-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/cashu-js/Cargo.toml b/bindings/cashu-js/Cargo.toml deleted file mode 100644 index 2bf8e021..00000000 --- a/bindings/cashu-js/Cargo.toml +++ /dev/null @@ -1,28 +0,0 @@ -[package] -name = "cashu-js" -version = "0.1.0" -edition = "2021" -description = "Cashu rust implementation, for JavaScript" -authors = ["thesimplekid "] -publish = false -repository.workspace = true -license.workspace = true - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html -[lib] -crate-type = ["lib", "cdylib"] - -[dependencies] -cashu = { path = "../../crates/cashu", features = ["nut08"] } -js-sys = "0.3.64" -serde-wasm-bindgen = "0.6.0" -serde_json.workspace = true -serde.workspace = true -wasm-bindgen = { version = "0.2.87", features = ["serde-serialize"] } -wasm-bindgen-futures = "0.4.37" -console_error_panic_hook = "0.1" - - - -[package.metadata.wasm-pack.profile.release] -wasm-opt = true diff --git a/bindings/cashu-js/LICENSE b/bindings/cashu-js/LICENSE deleted file mode 100644 index 083823dd..00000000 --- a/bindings/cashu-js/LICENSE +++ /dev/null @@ -1,29 +0,0 @@ -BSD 3-Clause License - -Copyright (c) 2023, thesimplekid -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -3. Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/bindings/cashu-js/LICENSES/NOSTR-MIT b/bindings/cashu-js/LICENSES/NOSTR-MIT deleted file mode 100644 index 2ff56442..00000000 --- a/bindings/cashu-js/LICENSES/NOSTR-MIT +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2022-2023 Yuki Kishimoto - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/bindings/cashu-js/examples/amount.js b/bindings/cashu-js/examples/amount.js deleted file mode 100644 index e381dbd4..00000000 --- a/bindings/cashu-js/examples/amount.js +++ /dev/null @@ -1,12 +0,0 @@ -const {Amount, loadWasmAsync, loadWasmSync } = require(".."); - - -function main() { - loadWasmSync(); - - let amount = Amount.fromSat(BigInt(10)); - - console.log(amount.toSat()) -} - -main(); diff --git a/bindings/cashu-js/justfile b/bindings/cashu-js/justfile deleted file mode 100644 index d1235b12..00000000 --- a/bindings/cashu-js/justfile +++ /dev/null @@ -1,5 +0,0 @@ -build: - wasm-pack build - -pack: - npm run package diff --git a/bindings/cashu-js/package.json b/bindings/cashu-js/package.json deleted file mode 100644 index 9b70632b..00000000 --- a/bindings/cashu-js/package.json +++ /dev/null @@ -1,44 +0,0 @@ -{ - "name": "@rust-cashu/cashu", - "version": "0.0.1", - "description": "Cashu protocol implementation, for JavaScript", - "keywords": [ - "cashu", - "protocol", - "rust", - "bindings" - ], - "license": "BSD-3-Clause", - "homepage": "https://github.com/thesimplekid/cashu-crab", - "repository": { - "type": "git", - "url": "git+https://github.com/thesimplekid/cashu-crab" - }, - "bugs": { - "url": "https://github.com/thesimplekid/cashu-crab/issues" - }, - "author": { - "name": "thesimplekid", - "email": "tsk@thesimplekid.com", - "url": "https://github.com/thesimplekid" - }, - "main": "pkg/cashu_js.js", - "types": "pkg/cashu_js.d.ts", - "files": [ - "pkg/cashu_js_bg.wasm.js", - "pkg/cashu_js_bg.wasm.d.ts", - "pkg/cashu_js.js", - "pkg/cashu_js.d.ts" - ], - "devDependencies": { - "wasm-pack": "^0.10.2" - }, - "engines": { - "node": ">= 10" - }, - "scripts": { - "build": "WASM_PACK_ARGS=--release ./scripts/build.sh", - "build:dev": "WASM_PACK_ARGS=--dev ./scripts/build.sh", - "package": "npm run build && npm pack" - } -} diff --git a/bindings/cashu-js/scripts/LICENSE b/bindings/cashu-js/scripts/LICENSE deleted file mode 100644 index 2ff56442..00000000 --- a/bindings/cashu-js/scripts/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2022-2023 Yuki Kishimoto - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/bindings/cashu-js/scripts/build.sh b/bindings/cashu-js/scripts/build.sh deleted file mode 100755 index 2b747eb8..00000000 --- a/bindings/cashu-js/scripts/build.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash -# -# Build the JavaScript modules -# -# This script is really a workaround for https://github.com/rustwasm/wasm-pack/issues/1074. -# -# Currently, the only reliable way to load WebAssembly in all the JS -# environments we want to target (web-via-webpack, web-via-browserify, jest) -# seems to be to pack the WASM into base64, and then unpack it and instantiate -# it at runtime. -# -# Hopefully one day, https://github.com/rustwasm/wasm-pack/issues/1074 will be -# fixed and this will be unnecessary. - -set -e - -cd "$(dirname "$0")"/.. - -WASM_BINDGEN_WEAKREF=1 wasm-pack build --target nodejs --scope rust-cashu --out-dir pkg "${WASM_PACK_ARGS[@]}" - -# Convert the Wasm into a JS file that exports the base64'ed Wasm. -echo "module.exports = \`$(base64 pkg/cashu_js_bg.wasm)\`;" > pkg/cashu_js_bg.wasm.js - -# In the JavaScript: -# 1. Strip out the lines that load the WASM, and our new epilogue. -# 2. Remove the imports of `TextDecoder` and `TextEncoder`. We rely on the global defaults. -{ - sed -e '/Text..coder.*= require(.util.)/d' \ - -e '/^const path = /,$d' pkg/cashu_js.js - cat scripts/epilogue.js -} > pkg/cashu_js.js.new -mv pkg/cashu_js.js.new pkg/cashu_js.js - -# also extend the typescript -cat scripts/epilogue.d.ts >> pkg/cashu_js.d.ts diff --git a/bindings/cashu-js/scripts/epilogue.d.ts b/bindings/cashu-js/scripts/epilogue.d.ts deleted file mode 100644 index 2a3f7fe1..00000000 --- a/bindings/cashu-js/scripts/epilogue.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -/** - * Load the WebAssembly module in the background, if it has not already been loaded. - * - * Returns a promise which will resolve once the other methods are ready. - * - * @returns {Promise} - */ - export function loadWasmAsync(): Promise; - - export function loadWasmSync(): void; diff --git a/bindings/cashu-js/scripts/epilogue.js b/bindings/cashu-js/scripts/epilogue.js deleted file mode 100644 index 4028b9cd..00000000 --- a/bindings/cashu-js/scripts/epilogue.js +++ /dev/null @@ -1,76 +0,0 @@ -let inited = false; -module.exports.loadWasmSync = function () { - if (inited) { - return; - } - if (initPromise) { - throw new Error("Asynchronous initialisation already in progress: cannot initialise synchronously"); - } - const bytes = unbase64(require("./cashu_js_bg.wasm.js")); - const mod = new WebAssembly.Module(bytes); - const instance = new WebAssembly.Instance(mod, imports); - wasm = instance.exports; - wasm.__wbindgen_start(); - inited = true; -}; - -let initPromise = null; - -/** - * Load the WebAssembly module in the background, if it has not already been loaded. - * - * Returns a promise which will resolve once the other methods are ready. - * - * @returns {Promise} - */ -module.exports.loadWasmAsync = function () { - if (inited) { - return Promise.resolve(); - } - if (!initPromise) { - initPromise = Promise.resolve() - .then(() => require("./cashu_js_bg.wasm.js")) - .then((b64) => WebAssembly.instantiate(unbase64(b64), imports)) - .then((result) => { - wasm = result.instance.exports; - wasm.__wbindgen_start(); - inited = true; - }); - } - return initPromise; -}; - -const b64lookup = new Uint8Array([ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 62, 0, 62, 0, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, - 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 0, 0, 0, 0, 63, 0, 26, 27, 28, 29, 30, 31, 32, - 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -]); - -// base64 decoder, based on the code at https://developer.mozilla.org/en-US/docs/Glossary/Base64#solution_2_%E2%80%93_rewriting_atob_and_btoa_using_typedarrays_and_utf-8 -function unbase64(sBase64) { - const sB64Enc = sBase64.replace(/[^A-Za-z0-9+/]/g, ""); - const nInLen = sB64Enc.length; - const nOutLen = (nInLen * 3 + 1) >> 2; - const taBytes = new Uint8Array(nOutLen); - - let nMod3; - let nMod4; - let nUint24 = 0; - let nOutIdx = 0; - for (let nInIdx = 0; nInIdx < nInLen; nInIdx++) { - nMod4 = nInIdx & 3; - nUint24 |= b64lookup[sB64Enc.charCodeAt(nInIdx)] << (6 * (3 - nMod4)); - if (nMod4 === 3 || nInLen - nInIdx === 1) { - nMod3 = 0; - while (nMod3 < 3 && nOutIdx < nOutLen) { - taBytes[nOutIdx] = (nUint24 >>> ((16 >>> nMod3) & 24)) & 255; - nMod3++; - nOutIdx++; - } - nUint24 = 0; - } - } - - return taBytes; -} diff --git a/bindings/cashu-js/src/error.rs b/bindings/cashu-js/src/error.rs deleted file mode 100644 index 019f9a3a..00000000 --- a/bindings/cashu-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::error::Error, -{ - JsValue::from_str(&error.to_string()) -} diff --git a/bindings/cashu-js/src/lib.rs b/bindings/cashu-js/src/lib.rs deleted file mode 100644 index 255dd9e9..00000000 --- a/bindings/cashu-js/src/lib.rs +++ /dev/null @@ -1,12 +0,0 @@ -use wasm_bindgen::prelude::*; - -pub mod error; -pub mod nuts; -mod types; - -pub use self::types::{JsAmount, JsBolt11Invoice, JsProofsStatus, JsSecret}; - -#[wasm_bindgen(start)] -pub fn start() { - console_error_panic_hook::set_once(); -} diff --git a/bindings/cashu-js/src/nuts/mod.rs b/bindings/cashu-js/src/nuts/mod.rs deleted file mode 100644 index c7d2134b..00000000 --- a/bindings/cashu-js/src/nuts/mod.rs +++ /dev/null @@ -1,20 +0,0 @@ -pub mod nut00; -pub mod nut01; -pub mod nut02; -pub mod nut03; -pub mod nut04; -pub mod nut05; -#[cfg(feature = "nut07")] -pub mod nut07; -pub mod nut08; -#[cfg(feature = "nut09")] -pub mod nut09; - -pub use nut00::{JsBlindedMessage, JsBlindedMessages, JsBlindedSignature, JsProof, JsToken}; -pub use nut01::{JsKeyPair, JsKeys, JsPublicKey, JsSecretKey}; -pub use nut02::{JsId, JsKeySet, JsKeySetsResponse, JsKeysResponse, JsMintKeySet}; -pub use nut03::{JsSwapRequest, JsSwapResponse}; -pub use nut04::{JsMintBolt11Request, JsMintBolt11Response}; -#[cfg(feature = "nut07")] -pub use nut07::{JsCheckSpendableRequest, JsCheckSpendableResponse}; -pub use nut08::{JsMeltBolt11Request, JsMeltBolt11Response}; diff --git a/bindings/cashu-js/src/nuts/nut00/blinded_message.rs b/bindings/cashu-js/src/nuts/nut00/blinded_message.rs deleted file mode 100644 index 551e6d19..00000000 --- a/bindings/cashu-js/src/nuts/nut00/blinded_message.rs +++ /dev/null @@ -1,53 +0,0 @@ -use std::ops::Deref; - -use cashu::nuts::nut00::BlindedMessage; -use wasm_bindgen::prelude::*; - -use crate::nuts::nut01::JsPublicKey; -use crate::nuts::nut02::JsId; -use crate::types::amount::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, b: JsPublicKey) -> Self { - Self { - inner: BlindedMessage { - keyset_id: *keyset_id.deref(), - amount: *amount.deref(), - b: b.deref().clone(), - }, - } - } - - /// Amount - #[wasm_bindgen(getter)] - pub fn amount(&self) -> JsAmount { - self.inner.amount.into() - } - - /// B - #[wasm_bindgen(getter)] - pub fn b(&self) -> JsPublicKey { - self.inner.b.clone().into() - } -} diff --git a/bindings/cashu-js/src/nuts/nut00/blinded_messages.rs b/bindings/cashu-js/src/nuts/nut00/blinded_messages.rs deleted file mode 100644 index b0b6874f..00000000 --- a/bindings/cashu-js/src/nuts/nut00/blinded_messages.rs +++ /dev/null @@ -1,62 +0,0 @@ -use std::ops::Deref; - -use cashu::nuts::nut00::wallet::PreMintSecrets; -use wasm_bindgen::prelude::*; - -use crate::error::{into_err, Result}; -use crate::nuts::nut02::JsId; -use crate::types::JsAmount; - -#[wasm_bindgen(js_name = BlindedMessages)] -pub struct JsBlindedMessages { - inner: PreMintSecrets, -} - -impl Deref for JsBlindedMessages { - type Target = PreMintSecrets; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -#[wasm_bindgen(js_class = BlindedMessages)] -impl JsBlindedMessages { - #[wasm_bindgen(js_name = random)] - pub fn random(keyset_id: JsId, amount: JsAmount) -> Result { - Ok(JsBlindedMessages { - inner: PreMintSecrets::random(*keyset_id.deref(), *amount.deref()).map_err(into_err)?, - }) - } - - #[wasm_bindgen(js_name = blank)] - pub fn blank(keyset_id: JsId, fee_reserve: JsAmount) -> Result { - Ok(JsBlindedMessages { - inner: PreMintSecrets::blank(*keyset_id.deref(), *fee_reserve.deref()) - .map_err(into_err)?, - }) - } - - /// Blinded Messages - #[wasm_bindgen(getter)] - pub fn blinded_messages(&self) -> Result { - serde_wasm_bindgen::to_value(&self.inner.blinded_messages()).map_err(into_err) - } - - /// Secrets - #[wasm_bindgen(getter)] - pub fn secrets(&self) -> Result { - serde_wasm_bindgen::to_value(&self.inner.secrets()).map_err(into_err) - } - - /// rs - #[wasm_bindgen(getter)] - pub fn rs(&self) -> Result { - serde_wasm_bindgen::to_value(&self.inner.rs()).map_err(into_err) - } - - /// Amounts - #[wasm_bindgen(getter)] - pub fn amounts(&self) -> Result { - serde_wasm_bindgen::to_value(&self.inner.amounts()).map_err(into_err) - } -} diff --git a/bindings/cashu-js/src/nuts/nut00/blinded_signature.rs b/bindings/cashu-js/src/nuts/nut00/blinded_signature.rs deleted file mode 100644 index 133401fe..00000000 --- a/bindings/cashu-js/src/nuts/nut00/blinded_signature.rs +++ /dev/null @@ -1,35 +0,0 @@ -use std::ops::Deref; - -use cashu::nuts::nut00::BlindedSignature; -use wasm_bindgen::prelude::*; - -use crate::nuts::nut01::JsPublicKey; -use crate::nuts::nut02::JsId; -use crate::types::JsAmount; - -#[wasm_bindgen(js_name = BlindedSignature)] -pub struct JsBlindedSignature { - inner: BlindedSignature, -} - -impl Deref for JsBlindedSignature { - type Target = BlindedSignature; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -#[wasm_bindgen(js_class = BlindedSignature)] -impl JsBlindedSignature { - #[allow(clippy::new_without_default)] - #[wasm_bindgen(constructor)] - pub fn new(keyset_id: JsId, amount: JsAmount, c: JsPublicKey) -> Self { - Self { - inner: BlindedSignature { - keyset_id: *keyset_id.deref(), - amount: *amount.deref(), - c: c.deref().clone(), - }, - } - } -} diff --git a/bindings/cashu-js/src/nuts/nut00/mod.rs b/bindings/cashu-js/src/nuts/nut00/mod.rs deleted file mode 100644 index f5246ba9..00000000 --- a/bindings/cashu-js/src/nuts/nut00/mod.rs +++ /dev/null @@ -1,11 +0,0 @@ -mod blinded_message; -mod blinded_messages; -mod blinded_signature; -mod proof; -mod token; - -pub use blinded_message::JsBlindedMessage; -pub use blinded_messages::JsBlindedMessages; -pub use blinded_signature::JsBlindedSignature; -pub use proof::JsProof; -pub use token::JsToken; diff --git a/bindings/cashu-js/src/nuts/nut00/proof.rs b/bindings/cashu-js/src/nuts/nut00/proof.rs deleted file mode 100644 index c6e92309..00000000 --- a/bindings/cashu-js/src/nuts/nut00/proof.rs +++ /dev/null @@ -1,65 +0,0 @@ -use std::ops::Deref; - -use cashu::nuts::nut00::Proof; -use wasm_bindgen::prelude::*; - -use crate::nuts::nut01::JsPublicKey; -use crate::nuts::nut02::JsId; -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) -> JsProof { - Self { - inner: Proof { - amount: *amount.deref(), - secret: secret.deref().clone(), - c: c.deref().clone(), - keyset_id: *keyset_id.deref(), - }, - } - } - - /// 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.clone().into() - } - - /// Keyset Id - #[wasm_bindgen(getter)] - pub fn keyset_id(&self) -> JsId { - self.inner.keyset_id.into() - } -} diff --git a/bindings/cashu-js/src/nuts/nut00/token.rs b/bindings/cashu-js/src/nuts/nut00/token.rs deleted file mode 100644 index 0de0a44a..00000000 --- a/bindings/cashu-js/src/nuts/nut00/token.rs +++ /dev/null @@ -1,69 +0,0 @@ -use std::ops::Deref; -use std::str::FromStr; - -use cashu::nuts::nut00::wallet::Token; -use cashu::nuts::CurrencyUnit; -use cashu::url::UncheckedUrl; -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( - mint: String, - proofs: JsValue, - memo: Option, - unit: Option, - ) -> Result { - let mint = UncheckedUrl::from_str(&mint).map_err(into_err)?; - let proofs = serde_wasm_bindgen::from_value(proofs).map_err(into_err)?; - let unit = unit.map(|u| { - CurrencyUnit::from_str(&u) - .map_err(into_err) - .unwrap_or_default() - }); - Ok(Self { - inner: Token::new(mint, proofs, memo, unit).map_err(into_err)?, - }) - } - - /// Memo - #[wasm_bindgen(getter)] - pub fn memo(&self) -> Option { - self.inner.memo.clone() - } - - /// From String - #[wasm_bindgen(js_name = fromString)] - pub fn from_string(token: String) -> Result { - Ok(JsToken { - inner: Token::from_str(&token).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/cashu-js/src/nuts/nut01/key_pair.rs b/bindings/cashu-js/src/nuts/nut01/key_pair.rs deleted file mode 100644 index 76c9ff94..00000000 --- a/bindings/cashu-js/src/nuts/nut01/key_pair.rs +++ /dev/null @@ -1,47 +0,0 @@ -use std::ops::Deref; - -use cashu::nuts::nut01::mint::KeyPair; -use wasm_bindgen::prelude::*; - -use super::{JsPublicKey, JsSecretKey}; - -#[wasm_bindgen(js_name = KeyPair)] -pub struct JsKeyPair { - inner: KeyPair, -} - -impl Deref for JsKeyPair { - type Target = KeyPair; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsKeyPair { - fn from(inner: KeyPair) -> JsKeyPair { - JsKeyPair { inner } - } -} - -#[wasm_bindgen(js_class = KeyPair)] -impl JsKeyPair { - /// From Hex - #[wasm_bindgen(js_name = fromSecretKey)] - pub fn from_secret_key(secret_key: JsSecretKey) -> JsKeyPair { - Self { - inner: KeyPair::from_secret_key(secret_key.deref().clone()), - } - } - - /// Secret Key - #[wasm_bindgen(getter)] - pub fn secret_key(&self) -> JsSecretKey { - self.inner.secret_key.clone().into() - } - - /// Public Key - #[wasm_bindgen(getter)] - pub fn public_key(&self) -> JsPublicKey { - self.inner.public_key.clone().into() - } -} diff --git a/bindings/cashu-js/src/nuts/nut01/keys.rs b/bindings/cashu-js/src/nuts/nut01/keys.rs deleted file mode 100644 index 6533d9ac..00000000 --- a/bindings/cashu-js/src/nuts/nut01/keys.rs +++ /dev/null @@ -1,51 +0,0 @@ -use std::ops::Deref; - -use cashu::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/cashu-js/src/nuts/nut01/mod.rs b/bindings/cashu-js/src/nuts/nut01/mod.rs deleted file mode 100644 index facd8f32..00000000 --- a/bindings/cashu-js/src/nuts/nut01/mod.rs +++ /dev/null @@ -1,9 +0,0 @@ -mod key_pair; -mod keys; -mod public_key; -mod secret_key; - -pub use key_pair::JsKeyPair; -pub use keys::JsKeys; -pub use public_key::JsPublicKey; -pub use secret_key::JsSecretKey; diff --git a/bindings/cashu-js/src/nuts/nut01/public_key.rs b/bindings/cashu-js/src/nuts/nut01/public_key.rs deleted file mode 100644 index 3a41e808..00000000 --- a/bindings/cashu-js/src/nuts/nut01/public_key.rs +++ /dev/null @@ -1,41 +0,0 @@ -use std::ops::Deref; - -use cashu::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/cashu-js/src/nuts/nut01/secret_key.rs b/bindings/cashu-js/src/nuts/nut01/secret_key.rs deleted file mode 100644 index 49276fc1..00000000 --- a/bindings/cashu-js/src/nuts/nut01/secret_key.rs +++ /dev/null @@ -1,31 +0,0 @@ -use std::ops::Deref; - -use cashu::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_hex() - } -} diff --git a/bindings/cashu-js/src/nuts/nut02/keyset.rs b/bindings/cashu-js/src/nuts/nut02/keyset.rs deleted file mode 100644 index 77fbe78f..00000000 --- a/bindings/cashu-js/src/nuts/nut02/keyset.rs +++ /dev/null @@ -1,152 +0,0 @@ -use std::ops::Deref; -use std::str::FromStr; - -use cashu::nuts::{CurrencyUnit, Id, KeySet, KeysResponse, KeysetResponse}; -use wasm_bindgen::prelude::*; - -use crate::error::{into_err, Result}; -use crate::nuts::nut01::JsKeys; - -#[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() - } -} - -#[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/cashu-js/src/nuts/nut02/mint_keyset.rs b/bindings/cashu-js/src/nuts/nut02/mint_keyset.rs deleted file mode 100644 index 19823dfd..00000000 --- a/bindings/cashu-js/src/nuts/nut02/mint_keyset.rs +++ /dev/null @@ -1,45 +0,0 @@ -use std::ops::Deref; -use std::str::FromStr; - -use cashu::nuts::nut02::mint::KeySet; -use cashu::nuts::CurrencyUnit; -use wasm_bindgen::prelude::*; - -#[wasm_bindgen(js_name = MintKeySet)] -pub struct JsMintKeySet { - inner: KeySet, -} - -impl Deref for JsMintKeySet { - type Target = KeySet; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsMintKeySet { - fn from(inner: KeySet) -> JsMintKeySet { - JsMintKeySet { inner } - } -} - -#[wasm_bindgen(js_class = MintKeyPair)] -impl JsMintKeySet { - /// Generate - #[wasm_bindgen(constructor)] - pub fn generate( - secret: String, - unit: String, - derivation_path: String, - max_order: u8, - ) -> JsMintKeySet { - Self { - inner: KeySet::generate( - secret.as_bytes(), - CurrencyUnit::from_str(&unit).unwrap(), - &derivation_path, - max_order, - ), - } - } -} diff --git a/bindings/cashu-js/src/nuts/nut02/mod.rs b/bindings/cashu-js/src/nuts/nut02/mod.rs deleted file mode 100644 index f18b73b8..00000000 --- a/bindings/cashu-js/src/nuts/nut02/mod.rs +++ /dev/null @@ -1,5 +0,0 @@ -mod keyset; -mod mint_keyset; - -pub use keyset::{JsId, JsKeySet, JsKeySetsResponse, JsKeysResponse}; -pub use mint_keyset::JsMintKeySet; diff --git a/bindings/cashu-js/src/nuts/nut03.rs b/bindings/cashu-js/src/nuts/nut03.rs deleted file mode 100644 index 85cd840a..00000000 --- a/bindings/cashu-js/src/nuts/nut03.rs +++ /dev/null @@ -1,104 +0,0 @@ -use std::ops::Deref; - -use cashu::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().into() - } - - /// Output Amount - #[wasm_bindgen(js_name = outputAmount)] - pub fn output_amount(&self) -> JsAmount { - self.inner.output_amount().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().into() - } -} diff --git a/bindings/cashu-js/src/nuts/nut04.rs b/bindings/cashu-js/src/nuts/nut04.rs deleted file mode 100644 index 0b1a082f..00000000 --- a/bindings/cashu-js/src/nuts/nut04.rs +++ /dev/null @@ -1,82 +0,0 @@ -use std::ops::Deref; - -use cashu::nuts::nut04::{MintBolt11Request, MintBolt11Response}; -use wasm_bindgen::prelude::*; - -use crate::error::{into_err, Result}; -use crate::types::JsAmount; - -#[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 totoal_amount(&self) -> JsAmount { - self.inner.total_amount().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) - } -} diff --git a/bindings/cashu-js/src/nuts/nut05.rs b/bindings/cashu-js/src/nuts/nut05.rs deleted file mode 100644 index 8b137891..00000000 --- a/bindings/cashu-js/src/nuts/nut05.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/bindings/cashu-js/src/nuts/nut06.rs b/bindings/cashu-js/src/nuts/nut06.rs deleted file mode 100644 index 728d9a0b..00000000 --- a/bindings/cashu-js/src/nuts/nut06.rs +++ /dev/null @@ -1,106 +0,0 @@ -use std::ops::Deref; - -use cashu::nuts::{SplitRequest, SplitResponse}; -use wasm_bindgen::prelude::*; - -use crate::error::{into_err, Result}; -use crate::types::JsAmount; - -#[wasm_bindgen(js_name = SplitRequest)] -pub struct JsSplitRequest { - inner: SplitRequest, -} - -impl Deref for JsSplitRequest { - type Target = SplitRequest; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsSplitRequest { - fn from(inner: SplitRequest) -> JsSplitRequest { - JsSplitRequest { inner } - } -} - -#[wasm_bindgen(js_class = SplitRequest)] -impl JsSplitRequest { - #[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(JsSplitRequest { - inner: SplitRequest { 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().into() - } - - /// Output Amount - #[wasm_bindgen(js_name = outputAmount)] - pub fn output_amount(&self) -> JsAmount { - self.inner.output_amount().into() - } -} - -#[wasm_bindgen(js_name = SplitResponse)] -pub struct JsSplitResponse { - inner: SplitResponse, -} - -impl Deref for JsSplitResponse { - type Target = SplitResponse; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsSplitResponse { - fn from(inner: SplitResponse) -> JsSplitResponse { - JsSplitResponse { inner } - } -} - -#[wasm_bindgen(js_class = SplitResponse)] -impl JsSplitResponse { - #[wasm_bindgen(constructor)] - pub fn new(promises: JsValue) -> Result { - let promises = serde_wasm_bindgen::from_value(promises).map_err(into_err)?; - - Ok(JsSplitResponse { - inner: SplitResponse { - promises: Some(promises), - }, - }) - } - - /// Get Promises - #[wasm_bindgen(getter)] - pub fn promises(&self) -> Result { - serde_wasm_bindgen::to_value(&self.inner.promises).map_err(into_err) - } - - /// Promises Amount - #[wasm_bindgen(js_name = promisesAmount)] - pub fn promises_amount(&self) -> Option { - self.inner.promises_amount().map(|a| a.into()) - } -} diff --git a/bindings/cashu-js/src/nuts/nut07.rs b/bindings/cashu-js/src/nuts/nut07.rs deleted file mode 100644 index 390bcf1b..00000000 --- a/bindings/cashu-js/src/nuts/nut07.rs +++ /dev/null @@ -1,94 +0,0 @@ -use std::ops::Deref; - -use cashu::nuts::nut07::{CheckSpendableRequest, CheckSpendableResponse}; -use wasm_bindgen::prelude::*; - -use crate::error::{into_err, Result}; - -#[wasm_bindgen(js_name = CheckSpendableRequest)] -pub struct JsCheckSpendableRequest { - inner: CheckSpendableRequest, -} - -impl Deref for JsCheckSpendableRequest { - type Target = CheckSpendableRequest; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsCheckSpendableRequest { - fn from(inner: CheckSpendableRequest) -> JsCheckSpendableRequest { - JsCheckSpendableRequest { inner } - } -} - -#[wasm_bindgen(js_class = CheckSpendable)] -impl JsCheckSpendableRequest { - #[wasm_bindgen(constructor)] - pub fn new(proofs: JsValue) -> Result { - let proofs = serde_wasm_bindgen::from_value(proofs).map_err(into_err)?; - - Ok(JsCheckSpendableRequest { - inner: CheckSpendableRequest { proofs }, - }) - } - - /// Get Proofs - #[wasm_bindgen(getter)] - pub fn proofs(&self) -> Result { - serde_wasm_bindgen::to_value(&self.inner.proofs).map_err(into_err) - } -} - -#[wasm_bindgen(js_name = CheckSpendableResponse)] -pub struct JsCheckSpendableResponse { - inner: CheckSpendableResponse, -} - -impl Deref for JsCheckSpendableResponse { - type Target = CheckSpendableResponse; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsCheckSpendableResponse { - fn from(inner: CheckSpendableResponse) -> JsCheckSpendableResponse { - JsCheckSpendableResponse { inner } - } -} - -#[wasm_bindgen(js_class = CheckSpendableResponse)] -impl JsCheckSpendableResponse { - #[wasm_bindgen(constructor)] - pub fn new(spendable: JsValue, pending: JsValue) -> Result { - let spendable = serde_wasm_bindgen::from_value(spendable).map_err(into_err)?; - - let pending = serde_wasm_bindgen::from_value(pending).map_err(into_err)?; - - Ok(JsCheckSpendableResponse { - inner: CheckSpendableResponse { spendable, pending }, - }) - } - - /// Get Pending - #[wasm_bindgen(getter)] - pub fn pending(&self) -> Box<[JsValue]> { - self.inner - .pending - .iter() - .map(|p| JsValue::from_bool(*p)) - .collect() - } - - /// Get Spendable - #[wasm_bindgen(getter)] - pub fn spendable(&self) -> Box<[JsValue]> { - self.inner - .spendable - .iter() - .map(|s| JsValue::from_bool(*s)) - .collect() - } -} diff --git a/bindings/cashu-js/src/nuts/nut08.rs b/bindings/cashu-js/src/nuts/nut08.rs deleted file mode 100644 index 13ae123e..00000000 --- a/bindings/cashu-js/src/nuts/nut08.rs +++ /dev/null @@ -1,131 +0,0 @@ -use std::ops::Deref; - -use cashu::nuts::nut00::{BlindedMessage, BlindedSignature, Proof}; -use cashu::nuts::nut08::{MeltBolt11Request, MeltBolt11Response}; -use wasm_bindgen::prelude::*; - -use crate::error::{into_err, Result}; -use crate::types::JsAmount; - -#[wasm_bindgen(js_name = MeltRequest)] -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_class = MeltBolt11Request)] -impl JsMeltBolt11Request { - #[wasm_bindgen(constructor)] - pub fn new(quote: String, inputs: JsValue, outputs: JsValue) -> Result { - let inputs: Vec = serde_wasm_bindgen::from_value(inputs).map_err(into_err)?; - let outputs: Option> = if !outputs.is_null() { - Some(serde_wasm_bindgen::from_value(outputs).map_err(into_err)?) - } else { - None - }; - - Ok(JsMeltBolt11Request { - inner: MeltBolt11Request { - quote, - inputs, - outputs, - }, - }) - } - - /// Get Proofs - #[wasm_bindgen(getter)] - pub fn inputs(&self) -> Result { - serde_wasm_bindgen::to_value(&self.inner.inputs).map_err(into_err) - } - - /// Get Invoice - #[wasm_bindgen(getter)] - pub fn quote(&self) -> String { - self.inner.quote.clone() - } - - /// Get 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 = MeltResponse)] -pub struct JsMeltBolt11Response { - inner: MeltBolt11Response, -} - -impl Deref for JsMeltBolt11Response { - type Target = MeltBolt11Response; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsMeltBolt11Response { - fn from(inner: MeltBolt11Response) -> JsMeltBolt11Response { - JsMeltBolt11Response { inner } - } -} - -#[wasm_bindgen(js_class = MeltBolt11Response)] -impl JsMeltBolt11Response { - #[wasm_bindgen(constructor)] - pub fn new( - paid: bool, - payment_preimage: Option, - change: JsValue, - ) -> Result { - let change: Option> = if change.is_null() { - Some(serde_wasm_bindgen::from_value(change).map_err(into_err)?) - } else { - None - }; - - Ok(JsMeltBolt11Response { - inner: MeltBolt11Response { - payment_preimage, - paid, - change, - }, - }) - } - - /// Get Paid - #[wasm_bindgen(getter)] - pub fn paid(&self) -> bool { - self.inner.paid - } - - /// Get Preimage - #[wasm_bindgen(getter)] - pub fn payment_preimage(&self) -> Option { - self.inner.payment_preimage.clone() - } - - /// Get Change - #[wasm_bindgen(getter)] - pub fn change(&self) -> Result { - serde_wasm_bindgen::to_value(&self.inner.change).map_err(into_err) - } - - /// Change Amount - #[wasm_bindgen(js_name = "changeAmount")] - pub fn change_amount(&self) -> Option { - self.inner.change_amount().map(|a| a.into()) - } -} diff --git a/bindings/cashu-js/src/nuts/nut09.rs b/bindings/cashu-js/src/nuts/nut09.rs deleted file mode 100644 index e5cedfef..00000000 --- a/bindings/cashu-js/src/nuts/nut09.rs +++ /dev/null @@ -1,142 +0,0 @@ -use std::ops::Deref; - -use cashu::nuts::nut09::{MintInfo, MintVersion}; -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: JsValue, - nuts: JsValue, - motd: Option, - ) -> Result { - Ok(JsMintInfo { - inner: MintInfo { - name, - pubkey: pubkey.map(|p| p.deref().clone()), - version: version.map(|v| v.deref().clone()), - description, - description_long, - contact: serde_wasm_bindgen::from_value(contact).map_err(into_err)?, - nuts: serde_wasm_bindgen::from_value(nuts).map_err(into_err)?, - motd, - }, - }) - } - - /// 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.clone().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 - #[wasm_bindgen(getter)] - pub fn contact(&self) -> Result { - serde_wasm_bindgen::to_value(&self.inner.contact).map_err(into_err) - } - - /// Get supported nuts - #[wasm_bindgen(getter)] - pub fn nuts(&self) -> Result { - serde_wasm_bindgen::to_value(&self.inner.nuts).map_err(into_err) - } - - /// Get motd - #[wasm_bindgen(getter)] - pub fn motd(&self) -> Option { - self.inner.motd.clone() - } -} diff --git a/bindings/cashu-js/src/types/amount.rs b/bindings/cashu-js/src/types/amount.rs deleted file mode 100644 index 48456a93..00000000 --- a/bindings/cashu-js/src/types/amount.rs +++ /dev/null @@ -1,48 +0,0 @@ -use std::ops::Deref; - -use cashu::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: u32) -> Self { - Self { - inner: Amount::from(sats as u64), - } - } - - /// 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) - } -} diff --git a/bindings/cashu-js/src/types/bolt11_invoice.rs b/bindings/cashu-js/src/types/bolt11_invoice.rs deleted file mode 100644 index e1ebdc6d..00000000 --- a/bindings/cashu-js/src/types/bolt11_invoice.rs +++ /dev/null @@ -1,50 +0,0 @@ -use std::ops::Deref; -use std::str::FromStr; - -use cashu::Bolt11Invoice; -use wasm_bindgen::prelude::*; - -use crate::error::{into_err, Result}; -use crate::types::JsAmount; - -#[wasm_bindgen(js_name = Bolt11Invoice)] -pub struct JsBolt11Invoice { - inner: Bolt11Invoice, -} - -impl Deref for JsBolt11Invoice { - type Target = Bolt11Invoice; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsBolt11Invoice { - fn from(inner: Bolt11Invoice) -> JsBolt11Invoice { - JsBolt11Invoice { inner } - } -} - -#[wasm_bindgen(js_class = Bolt11Invoice)] -impl JsBolt11Invoice { - #[wasm_bindgen(constructor)] - pub fn new(invoice: String) -> Result { - Ok(JsBolt11Invoice { - inner: Bolt11Invoice::from_str(&invoice).map_err(into_err)?, - }) - } - - /// Amount - #[wasm_bindgen(getter)] - pub fn amount(&self) -> Option { - self.inner - .amount_milli_satoshis() - .map(|a| JsAmount::from(a / 1000)) - } - - /// Invoice as string - #[wasm_bindgen(js_name = asString)] - pub fn as_string(&self) -> String { - self.inner.to_string() - } -} diff --git a/bindings/cashu-js/src/types/mod.rs b/bindings/cashu-js/src/types/mod.rs deleted file mode 100644 index d456f501..00000000 --- a/bindings/cashu-js/src/types/mod.rs +++ /dev/null @@ -1,9 +0,0 @@ -pub mod amount; -pub mod bolt11_invoice; -pub mod proofs_status; -pub mod secret; - -pub use amount::JsAmount; -pub use bolt11_invoice::JsBolt11Invoice; -pub use proofs_status::JsProofsStatus; -pub use secret::JsSecret; diff --git a/bindings/cashu-js/src/types/proofs_status.rs b/bindings/cashu-js/src/types/proofs_status.rs deleted file mode 100644 index bce6c89f..00000000 --- a/bindings/cashu-js/src/types/proofs_status.rs +++ /dev/null @@ -1,48 +0,0 @@ -use std::ops::Deref; - -use cashu::types::ProofsStatus; -use wasm_bindgen::prelude::*; - -use crate::error::{into_err, Result}; - -#[wasm_bindgen(js_name = ProofsStatus)] -pub struct JsProofsStatus { - inner: ProofsStatus, -} - -impl Deref for JsProofsStatus { - type Target = ProofsStatus; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsProofsStatus { - fn from(inner: ProofsStatus) -> JsProofsStatus { - JsProofsStatus { inner } - } -} - -#[wasm_bindgen(js_class = ProofsStatus)] -impl JsProofsStatus { - #[wasm_bindgen(constructor)] - pub fn new(spent_proofs: JsValue, spendable_proofs: JsValue) -> Result { - let spent = serde_wasm_bindgen::from_value(spent_proofs).map_err(into_err)?; - let spendable = serde_wasm_bindgen::from_value(spendable_proofs).map_err(into_err)?; - Ok(JsProofsStatus { - inner: ProofsStatus { spent, spendable }, - }) - } - - /// Get Spendable Proofs - #[wasm_bindgen(getter)] - pub fn spendable(&self) -> Result { - serde_wasm_bindgen::to_value(&self.inner.spendable).map_err(into_err) - } - - /// Get Spent Proofs - #[wasm_bindgen(getter)] - pub fn spent_proofs(&self) -> Result { - serde_wasm_bindgen::to_value(&self.inner.spent).map_err(into_err) - } -} diff --git a/bindings/cashu-js/src/types/secret.rs b/bindings/cashu-js/src/types/secret.rs deleted file mode 100644 index 78081636..00000000 --- a/bindings/cashu-js/src/types/secret.rs +++ /dev/null @@ -1,44 +0,0 @@ -use std::ops::Deref; - -use cashu::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::new(), - } - } - - /// As Bytes - #[wasm_bindgen(js_name = asBytes)] - pub fn as_bytes(&self) -> Vec { - self.inner.as_bytes().to_vec() - } -} diff --git a/bindings/cashu-js/tsconfig.json b/bindings/cashu-js/tsconfig.json deleted file mode 100644 index 6ccdd0cf..00000000 --- a/bindings/cashu-js/tsconfig.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "compilerOptions": { - "strict": true - }, - "typedocOptions": { - "entryPoints": ["pkg/cashu_js.d.ts"], - "readme": "README.md" - } -} diff --git a/bindings/cashu-sdk-ffi/Cargo.toml b/bindings/cashu-sdk-ffi/Cargo.toml deleted file mode 100644 index f065321e..00000000 --- a/bindings/cashu-sdk-ffi/Cargo.toml +++ /dev/null @@ -1,30 +0,0 @@ -[package] -name = "cashu-sdk-ffi" -version = "0.1.0" -edition = "2021" -publish = false -rust-version.workspace = true - -[lib] -name = "cashu_sdk_ffi" -crate-type = ["cdylib", "staticlib"] - - -[dependencies] -cashu-ffi = { path = "../cashu-ffi" } -cashu-sdk = { path = "../../crates/cashu-sdk", default-features = false, features = ["wallet", "mint", "all-nuts"] } -tracing = { workspace = true } -tracing-subscriber = { workspace = true } -uniffi = { workspace = true } -futures = { version= "0.3.29", feature = "executor" } -once_cell = { version = "1.17" } - -[target.'cfg(not(target_arch = "wasm32"))'.dependencies] -tokio = { workspace = true, features = ["rt-multi-thread", "time", "macros", "sync"] } - -[target.'cfg(target_arch = "wasm32")'.dependencies] -tokio = { workspace = true, features = ["rt", "macros", "sync", "time"] } - -[build-dependencies] -uniffi = { workspace = true, features = ["build"] } - diff --git a/bindings/cashu-sdk-ffi/LICENSE b/bindings/cashu-sdk-ffi/LICENSE deleted file mode 100644 index 083823dd..00000000 --- a/bindings/cashu-sdk-ffi/LICENSE +++ /dev/null @@ -1,29 +0,0 @@ -BSD 3-Clause License - -Copyright (c) 2023, thesimplekid -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -3. Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/bindings/cashu-sdk-ffi/LICENSES/NOSTR_SDK_LICENSE_MIT b/bindings/cashu-sdk-ffi/LICENSES/NOSTR_SDK_LICENSE_MIT deleted file mode 100644 index 2ff56442..00000000 --- a/bindings/cashu-sdk-ffi/LICENSES/NOSTR_SDK_LICENSE_MIT +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2022-2023 Yuki Kishimoto - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/bindings/cashu-sdk-ffi/bindings-python/.gitignore b/bindings/cashu-sdk-ffi/bindings-python/.gitignore deleted file mode 100644 index 729b25c7..00000000 --- a/bindings/cashu-sdk-ffi/bindings-python/.gitignore +++ /dev/null @@ -1,16 +0,0 @@ -.tox/ -dist/ -cashu_sdk.egg-info/ -__pycache__/ -libnostr_sdk_ffi.dylib -.idea/ -.DS_Store - -*.swp - -src/cashu-sdk/cashu_sdk.py -src/cashu-sdk/*.so -*.whl -build/ - - diff --git a/bindings/cashu-sdk-ffi/bindings-python/LICENSE b/bindings/cashu-sdk-ffi/bindings-python/LICENSE deleted file mode 100644 index 083823dd..00000000 --- a/bindings/cashu-sdk-ffi/bindings-python/LICENSE +++ /dev/null @@ -1,29 +0,0 @@ -BSD 3-Clause License - -Copyright (c) 2023, thesimplekid -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -3. Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/bindings/cashu-sdk-ffi/bindings-python/LICENSES/NOSTR_SDK_MIT b/bindings/cashu-sdk-ffi/bindings-python/LICENSES/NOSTR_SDK_MIT deleted file mode 100644 index 2ff56442..00000000 --- a/bindings/cashu-sdk-ffi/bindings-python/LICENSES/NOSTR_SDK_MIT +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2022-2023 Yuki Kishimoto - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/bindings/cashu-sdk-ffi/bindings-python/MANIFEST.in b/bindings/cashu-sdk-ffi/bindings-python/MANIFEST.in deleted file mode 100644 index ebf6ce8c..00000000 --- a/bindings/cashu-sdk-ffi/bindings-python/MANIFEST.in +++ /dev/null @@ -1,3 +0,0 @@ -include ./src/cashu-sdk/libcashu_sdk_ffi.dylib -include ./src/cashu-sdk/libcashu_sdk_ffi.so - diff --git a/bindings/cashu-sdk-ffi/bindings-python/README.md b/bindings/cashu-sdk-ffi/bindings-python/README.md deleted file mode 100644 index 08de3ed8..00000000 --- a/bindings/cashu-sdk-ffi/bindings-python/README.md +++ /dev/null @@ -1,50 +0,0 @@ -Cashu Sdk Python bindings - - -**ALPHA** This library is in early development, the api will change. - -## Supported Nuts: - -Check: [https://github.com/thesimplekid/cashu-crab#implemented-nuts](https://github.com/thesimplekid/cashu-crab#implemented-nuts) - -## Build the package - -```shell -just python -``` - -## Getting Started - -For now this is not published as a package as it is still in early development. So you will have to build it as above. In the future this will be pulished and pip can be used to install. - -```python -from cashu_sdk import Wallet, Client, Amount - -client = Client("https://mutinynet-cashu.thesimplekid.space") - -mint_keys = client.get_keys() - -wallet = Wallet(client, mint_keys) - -mint_request = wallet.request_mint(Amount.from_sat(10)) - -print(mint_request.invoice()) - -print(mint_request.hash()) - -``` - - -## License - -Code is under the [BSD 3-Clause License](LICENSE) - -## Contribution - -All contributions welcome. - -Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, shall be licensed as above, without any additional terms or conditions. - -## Contact - -I can be contacted for comments or questions on nostr at _@thesimplekid.com (npub1qjgcmlpkeyl8mdkvp4s0xls4ytcux6my606tgfx9xttut907h0zs76lgjw) or via email tsk@thesimplekid.com. diff --git a/bindings/cashu-sdk-ffi/bindings-python/examples/mint.py b/bindings/cashu-sdk-ffi/bindings-python/examples/mint.py deleted file mode 100644 index 11b3678f..00000000 --- a/bindings/cashu-sdk-ffi/bindings-python/examples/mint.py +++ /dev/null @@ -1,5 +0,0 @@ -from cashu_sdk import Mint; - -mint = Mint("supersecret", "0/0/0/0", {}, [], 32) - -print(mint.active_keyset_pubkeys().keys().as_hashmap()) diff --git a/bindings/cashu-sdk-ffi/bindings-python/examples/wallet.py b/bindings/cashu-sdk-ffi/bindings-python/examples/wallet.py deleted file mode 100644 index c8d56781..00000000 --- a/bindings/cashu-sdk-ffi/bindings-python/examples/wallet.py +++ /dev/null @@ -1,13 +0,0 @@ -from cashu_sdk import Wallet, Client, Amount - -client = Client("https://mutinynet-cashu.thesimplekid.space") - -mint_keys = client.get_keys() - -wallet = Wallet(client, mint_keys) - -mint_request = wallet.request_mint(Amount.from_sat(10)) - -print(mint_request.invoice()) - -print(mint_request.hash()) diff --git a/bindings/cashu-sdk-ffi/bindings-python/pyproject.toml b/bindings/cashu-sdk-ffi/bindings-python/pyproject.toml deleted file mode 100644 index 0e557d58..00000000 --- a/bindings/cashu-sdk-ffi/bindings-python/pyproject.toml +++ /dev/null @@ -1,7 +0,0 @@ -[build-system] -requires = ["setuptools", "wheel"] - -[tool.pytest.ini_options] -pythonpath = [ - "." -] diff --git a/bindings/cashu-sdk-ffi/bindings-python/requirements.txt b/bindings/cashu-sdk-ffi/bindings-python/requirements.txt deleted file mode 100644 index 099ef548..00000000 --- a/bindings/cashu-sdk-ffi/bindings-python/requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -semantic-version==2.9.0 -typing_extensions==4.0.1 -setuptools==67.4.0 -wheel==0.38.4 - diff --git a/bindings/cashu-sdk-ffi/bindings-python/setup.py b/bindings/cashu-sdk-ffi/bindings-python/setup.py deleted file mode 100644 index 720de203..00000000 --- a/bindings/cashu-sdk-ffi/bindings-python/setup.py +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env python - -from setuptools import setup - -from pathlib import Path -this_directory = Path(__file__).parent -long_description = (this_directory / "README.md").read_text() - -setup( - name='cashu-sdk', - version='0.0.1', - description="High level client library.", - long_description=long_description, - long_description_content_type='text/markdown', - include_package_data=True, - zip_safe=False, - packages=['cashu_sdk'], - package_dir={'cashu_sdk': './src/cashu-sdk'}, - url="https://github.com/thesimplekid/cashu-crab", - author="thesimplekid ", - license="BSD-3-Clause", - # This is required to ensure the library name includes the python version, abi, and platform tags - # See issue #350 for more information - has_ext_modules=lambda: True, -) - diff --git a/bindings/cashu-sdk-ffi/bindings-python/src/cashu-sdk/__init__.py b/bindings/cashu-sdk-ffi/bindings-python/src/cashu-sdk/__init__.py deleted file mode 100644 index 506a65dd..00000000 --- a/bindings/cashu-sdk-ffi/bindings-python/src/cashu-sdk/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -from cashu_sdk.cashu_sdk import * - diff --git a/bindings/cashu-sdk-ffi/build.rs b/bindings/cashu-sdk-ffi/build.rs deleted file mode 100644 index 0db24ea7..00000000 --- a/bindings/cashu-sdk-ffi/build.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - uniffi::generate_scaffolding("./src/cashu_sdk.udl").expect("Building the UDL file failed"); -} diff --git a/bindings/cashu-sdk-ffi/justfile b/bindings/cashu-sdk-ffi/justfile deleted file mode 100644 index 3c360bfc..00000000 --- a/bindings/cashu-sdk-ffi/justfile +++ /dev/null @@ -1,16 +0,0 @@ -init: - rustup target add aarch64-apple-ios x86_64-apple-ios aarch64-apple-ios-sim - rustup target add aarch64-apple-darwin x86_64-apple-darwin - rustup target add aarch64-linux-android armv7-linux-androideabi i686-linux-android x86_64-linux-android - cargo install cbindgen - cargo install cargo-ndk - -python: - rm -rf dist - pip install -r bindings-python/requirements.txt - cargo build --release - cargo run -p uniffi-bindgen generate src/cashu_sdk.udl --language python --no-format -o bindings-python/src/cashu-sdk/ - cp ../../target/release/libcashu_sdk_ffi.so bindings-python/src/cashu-sdk/ - cp ../../target/release/libcashu_sdk_ffi.dylib bindings-python/src/cashu-sdk/ | true - cd bindings-python && pip wheel --no-deps -w dist . - pip install ./bindings-python/dist/cashu_sdk*.whl --force-reinstall diff --git a/bindings/cashu-sdk-ffi/src/cashu_sdk.udl b/bindings/cashu-sdk-ffi/src/cashu_sdk.udl deleted file mode 100644 index af5185da..00000000 --- a/bindings/cashu-sdk-ffi/src/cashu_sdk.udl +++ /dev/null @@ -1,339 +0,0 @@ -namespace cashu_sdk {}; - -// Cashu - -[Error] -interface CashuError { - Generic(string err); -}; - - -// Types - -[Enum] -interface CurrencyUnit { - Sat(); - Usd(); - Custom(string unit); -}; - -interface Bolt11Invoice { - [Throws=CashuError] - constructor(string bolt11); - string as_string(); - Amount? amount(); -}; - -interface Amount { - constructor(u64 amount); - sequence split(); -}; - -interface Secret { - constructor(); - sequence as_bytes(); -}; - -interface MintQuote { - constructor(string id, Amount amount, string unit, Bolt11Invoice request, boolean paid, u64 boolean); -}; - - -interface MeltQuote { - constructor(string id, Amount amount, string unit, Bolt11Invoice request, Amount fee_reserve, boolean paid, u64 boolean); -}; - -// NUT00 - -interface PublicKey { - [Throws=CashuError, Name=from_hex] - constructor(string hex); - [Throws=CashuError] - string to_hex(); -}; - - -interface SecretKey { - [Throws=CashuError] - string to_hex(); -}; - -interface BlindedMessage { - constructor(Id keyset_id, Amount amount, PublicKey b); - Amount amount(); - Id keyset_id(); - PublicKey b(); -}; - -interface Proof { - constructor(Amount amount, Secret secret, PublicKey c, Id id); - Amount amount(); - Secret secret(); - PublicKey c(); - Id keyset_id(); -}; - -interface BlindedSignature { - constructor(Id keyset_id, Amount amount, PublicKey c); - Id keyset_id(); - Amount amount(); - PublicKey c(); -}; - -interface MintProof { - constructor(Amount? amount, Secret secret, PublicKey? c, Id? id); - Amount? amount(); - Secret secret(); - PublicKey? c(); - Id? keyset_id(); - -}; - -interface MintProofs { - [Throws=CashuError] - constructor(string mint, sequence proofs); - string url(); - sequence proofs(); -}; - -interface Token { - [Throws=CashuError] - constructor(string mint, sequence token, string? memo, string? unit); - sequence token(); - string? memo(); - string? unit(); - string to_string(); - [Throws=CashuError, Name=from_string] - constructor(string token); - -}; - -interface PreMintSecrets { - [Throws=CashuError, Name=random] - constructor(Id keyset_id, Amount amount); - [Throws=CashuError, Name=blank] - constructor(Id keyset_id, Amount amount); - sequence blinded_messages(); - sequence secrets(); - sequence rs(); - sequence amounts(); -}; - - -// NUT-02 - -interface Id { - [Throws=CashuError] - constructor(string id); -}; - -interface KeyPair { - [Name=from_secret_key] - constructor(SecretKey secret_key); - SecretKey secret_key(); - PublicKey public_key(); -}; - -interface Keys { - constructor(record keys); - record keys(); - record as_hashmap(); - PublicKey? amount_key(Amount amount); -}; - -interface KeySet { - constructor(Id id, string unit, Keys keys); - Id id(); - Keys keys(); -}; - -interface MintKeySet { - [Name=generate] - constructor(string secret, string unit, string derivation_path, u8 max_order); -}; - -interface KeysResponse { - constructor(sequence keysets); -}; - -interface KeySetResponse { - constructor(sequence keysets); - sequence keysets(); -}; - -// NUT-03 - -interface SwapRequest { - constructor(sequence proofs, sequence outputs); - sequence proofs(); - sequence outputs(); - Amount proofs_amount(); - Amount output_amount(); -}; - -interface SwapResponse { - constructor(sequence promises); - sequence signatures(); -}; - -// NUT-04 - -interface MintQuoteBolt11Request { - constructor(Amount amount, string unit); - Amount amount(); -}; - -interface MintQuoteBolt11Response { - constructor(string quote, string request, boolean paid, u64 expiry); - string quote(); - string request(); - boolean paid(); - u64 expiry(); -}; - - -interface MintBolt11Request { - constructor(string quote, sequence outputs); - string quote(); - sequence outputs(); -}; - -interface MintBolt11Response { - constructor(sequence signatures); - sequence signatures(); -}; - -// NUT-05 - -interface MeltQuoteBolt11Response { - [Throws=CashuError] - constructor(string quote, u64 amount, u64 fee_reserve, boolean paid, u64 expiry); - string quote(); - u64 amount(); - u64 fee_reserve(); - boolean paid(); - u64 expiry(); -}; - -interface MeltQuoteBolt11Request { - [Throws=CashuError] - constructor(string request, string unit); - string request(); -}; - -interface MeltBolt11Request { - [Throws=CashuError] - constructor(string quote, sequence inputs, sequence? outputs); - sequence inputs(); - string quote(); -}; - -interface MeltBolt11Response { - constructor(boolean paid, string? payment_preimage, sequence? change); - string? payment_preimage(); - boolean paid(); -}; - -// NUT-06 - -interface MintInfo { - constructor(string? name, PublicKey? pubkey, MintVersion? version, string? description, string? description_long, sequence>? contact, string nuts, string? motd); - string? name(); - PublicKey? pubkey(); - MintVersion? version(); - string? description(); - string? description_long(); - sequence>? contact(); - string? motd(); -}; - -// NUT-07 - -interface CheckSpendableRequest { - constructor(sequence proofs); - sequence proofs(); -}; - -interface CheckSpendableResponse { - constructor(sequence spendable, sequence pending); - sequence spendable(); - sequence pending(); -}; - -interface MintVersion { - constructor(string name, string version); - string name(); - string version(); -}; - -interface KeySetInfo { - constructor(Id id, string unit); -}; - -enum InvoiceStatus { - "Unpaid", - "Paid", - "Expired", - "InFlight" -}; - - -// Cashu Sdk - -interface MintKeySetInfo { - constructor(Id id, boolean active, string unit, u64 valid_from, u64? valid_to, string derivation_path, u8 max_order); -}; - - -[Error] -interface CashuSdkError { - Generic(string err); -}; - -interface SendProofs { - constructor(sequence change_proofs, sequence send_proofs); - sequence send_proofs(); - sequence change_proofs(); -}; - -interface Melted { - constructor(boolean paid, string? preimage, sequence? change); - string? preimage(); - boolean paid(); - sequence? change(); -}; - -interface Wallet { - constructor(string mint_url, Keys mint_keys, sequence mint_quotes, sequence melt_quotes); - // [Throws=CashuSdkError] - // ProofsStatus check_proofs_spent(sequence proofs); - [Throws=CashuSdkError] - Token mint_token(Amount amount, CurrencyUnit? unit, string? memo); - [Throws=CashuSdkError] - MintQuote mint_quote(Amount amount, CurrencyUnit unit); - [Throws=CashuSdkError] - sequence mint(string quote); - [Throws=CashuSdkError] - sequence receive(string encoded_token); - [Throws=CashuSdkError] - sequence process_swap_response(PreMintSecrets blinded_messages, sequence promises); - [Throws=CashuSdkError] - SendProofs send(Amount amount, sequence proofs); - [Throws=CashuSdkError] - MeltQuote melt_quote(CurrencyUnit unit, Bolt11Invoice request); - [Throws=CashuSdkError] - Melted melt(string quote_id, sequence proofs); - [Throws=CashuSdkError] - string proofs_to_token(sequence proof, CurrencyUnit? unit, string? memo); -}; - - -interface Mint { - [Throws=CashuSdkError] - constructor(string secret, sequence keysets_info, sequence spent_secrets, Amount min_fee_reserve, f32 percent_fee_reserve); - KeysResponse? keyset_pubkeys(Id keyset_id); - KeySetResponse keysets(); - KeySet? keyset(Id id); - [Throws=CashuSdkError] - SwapResponse process_swap_request(SwapRequest swap_request); -}; diff --git a/bindings/cashu-sdk-ffi/src/error.rs b/bindings/cashu-sdk-ffi/src/error.rs deleted file mode 100644 index d148c8ee..00000000 --- a/bindings/cashu-sdk-ffi/src/error.rs +++ /dev/null @@ -1,40 +0,0 @@ -use std::fmt; - -pub type Result = std::result::Result; - -#[derive(Debug)] -pub enum CashuSdkError { - Generic { err: String }, -} - -impl fmt::Display for CashuSdkError { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - Self::Generic { err } => write!(f, "{err}"), - } - } -} - -impl From for CashuSdkError { - fn from(err: cashu_sdk::client::Error) -> CashuSdkError { - Self::Generic { - err: err.to_string(), - } - } -} - -impl From for CashuSdkError { - fn from(err: cashu_sdk::wallet::Error) -> CashuSdkError { - Self::Generic { - err: err.to_string(), - } - } -} - -impl From for CashuSdkError { - fn from(err: cashu_sdk::mint::Error) -> CashuSdkError { - Self::Generic { - err: err.to_string(), - } - } -} diff --git a/bindings/cashu-sdk-ffi/src/lib.rs b/bindings/cashu-sdk-ffi/src/lib.rs deleted file mode 100644 index 08946483..00000000 --- a/bindings/cashu-sdk-ffi/src/lib.rs +++ /dev/null @@ -1,26 +0,0 @@ -mod error; -mod mint; -mod types; -mod wallet; - -mod ffi { - pub use cashu_ffi::{ - Amount, BlindedMessage, BlindedSignature, Bolt11Invoice, CashuError, CheckSpendableRequest, - CheckSpendableResponse, CurrencyUnit, Id, InvoiceStatus, KeyPair, KeySet, KeySetInfo, - KeySetResponse, Keys, KeysResponse, MeltBolt11Request, MeltBolt11Response, MeltQuote, - MeltQuoteBolt11Request, MeltQuoteBolt11Response, MintBolt11Request, MintBolt11Response, - MintInfo, MintKeySet, MintProof, MintProofs, MintQuote, MintQuoteBolt11Request, - MintQuoteBolt11Response, MintVersion, Nut05MeltBolt11Request, Nut05MeltBolt11Response, - PreMintSecrets, Proof, PublicKey, Secret, SecretKey, SwapRequest, SwapResponse, Token, - }; - - pub use crate::error::CashuSdkError; - pub use crate::mint::Mint; - pub use crate::types::{Melted, MintKeySetInfo, ProofsStatus, SendProofs}; - pub use crate::wallet::Wallet; - - // UDL - uniffi::include_scaffolding!("cashu_sdk"); -} - -pub use ffi::*; diff --git a/bindings/cashu-sdk-ffi/src/mint.rs b/bindings/cashu-sdk-ffi/src/mint.rs deleted file mode 100644 index bb36f4c1..00000000 --- a/bindings/cashu-sdk-ffi/src/mint.rs +++ /dev/null @@ -1,142 +0,0 @@ -use std::ops::Deref; -use std::str::FromStr; -use std::sync::{Arc, RwLock}; - -use cashu_ffi::{ - Amount, CheckSpendableRequest, CheckSpendableResponse, Id, KeySet, KeySetResponse, - KeysResponse, MeltBolt11Request, MeltBolt11Response, MintBolt11Request, MintBolt11Response, - Secret, SwapRequest, SwapResponse, -}; -use cashu_sdk::mint::Mint as MintSdk; -use cashu_sdk::Mnemonic; - -use crate::error::Result; -use crate::types::MintKeySetInfo; -use crate::CashuSdkError; - -pub struct Mint { - inner: RwLock, -} - -impl Mint { - pub fn new( - secret: String, - keysets_info: Vec>, - spent_secrets: Vec>, - min_fee_reserve: Arc, - percent_fee_reserve: f32, - ) -> Result { - let spent_secrets = spent_secrets - .into_iter() - .map(|s| s.as_ref().deref().clone()) - .collect(); - - let keysets = keysets_info - .into_iter() - .map(|ik| ik.as_ref().deref().clone()) - .collect(); - - let menemonic = Mnemonic::from_str(&secret).map_err(|_| CashuSdkError::Generic { - err: "Invalid Mnemonic".to_string(), - })?; - - Ok(Self { - inner: MintSdk::new( - menemonic, - keysets, - spent_secrets, - // TODO: quotes - vec![], - *min_fee_reserve.as_ref().deref(), - percent_fee_reserve, - ) - .into(), - }) - } - - pub fn keyset_pubkeys(&self, keyset_id: Arc) -> Option> { - self.inner - .read() - .unwrap() - .keyset_pubkeys(&keyset_id) - .map(|keyset| Arc::new(keyset.into())) - } - - pub fn keysets(&self) -> Arc { - Arc::new(self.inner.read().unwrap().keysets().into()) - } - - pub fn keyset(&self, id: Arc) -> Option> { - self.inner - .read() - .unwrap() - .keyset(&id) - .map(|k| Arc::new(k.into())) - } - - pub fn process_mint_request( - &self, - mint_request: Arc, - ) -> Result> { - Ok(Arc::new( - self.inner - .write() - .unwrap() - .process_mint_request(mint_request.as_ref().deref().clone())? - .into(), - )) - } - - pub fn process_swap_request( - &self, - split_request: Arc, - ) -> Result> { - Ok(Arc::new( - self.inner - .write() - .unwrap() - .process_swap_request(split_request.as_ref().deref().clone())? - .into(), - )) - } - - pub fn check_spendable( - &self, - check_spendable: Arc, - ) -> Result> { - Ok(Arc::new( - self.inner - .read() - .unwrap() - .check_spendable(check_spendable.as_ref().deref())? - .into(), - )) - } - - pub fn verify_melt_request(&self, melt_request: Arc) -> Result<()> { - Ok(self - .inner - .write() - .unwrap() - .verify_melt_request(melt_request.as_ref().deref())?) - } - - pub fn process_melt_request( - &self, - melt_request: Arc, - preimage: String, - total_spent: Arc, - ) -> Result> { - Ok(Arc::new( - self.inner - .write() - .unwrap() - .process_melt_request( - melt_request.as_ref().deref(), - &preimage, - *total_spent.as_ref().deref(), - )? - .into(), - )) - } -} diff --git a/bindings/cashu-sdk-ffi/src/types/keyset_info.rs b/bindings/cashu-sdk-ffi/src/types/keyset_info.rs deleted file mode 100644 index 27546273..00000000 --- a/bindings/cashu-sdk-ffi/src/types/keyset_info.rs +++ /dev/null @@ -1,49 +0,0 @@ -use std::ops::Deref; -use std::str::FromStr; -use std::sync::Arc; - -use cashu_sdk::mint::MintKeySetInfo as MintKeySetInfoSdk; -use cashu_sdk::nuts::CurrencyUnit; - -use crate::Id; - -pub struct MintKeySetInfo { - inner: MintKeySetInfoSdk, -} - -impl Deref for MintKeySetInfo { - type Target = MintKeySetInfoSdk; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for MintKeySetInfo { - fn from(inner: MintKeySetInfoSdk) -> MintKeySetInfo { - MintKeySetInfo { inner } - } -} - -impl MintKeySetInfo { - pub fn new( - id: Arc, - active: bool, - unit: String, - valid_from: u64, - valid_to: Option, - derivation_path: String, - max_order: u8, - ) -> Self { - Self { - inner: MintKeySetInfoSdk { - id: *id.as_ref().deref(), - active, - unit: CurrencyUnit::from_str(&unit).unwrap(), - valid_from, - valid_to, - derivation_path, - max_order, - }, - } - } -} diff --git a/bindings/cashu-sdk-ffi/src/types/melted.rs b/bindings/cashu-sdk-ffi/src/types/melted.rs deleted file mode 100644 index 38949d2e..00000000 --- a/bindings/cashu-sdk-ffi/src/types/melted.rs +++ /dev/null @@ -1,49 +0,0 @@ -use std::ops::Deref; -use std::sync::Arc; - -use cashu_ffi::Proof; -use cashu_sdk::types::Melted as MeltedSdk; - -pub struct Melted { - inner: MeltedSdk, -} - -impl Deref for Melted { - type Target = MeltedSdk; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for Melted { - fn from(inner: cashu_sdk::types::Melted) -> Melted { - Melted { inner } - } -} - -impl Melted { - pub fn new(paid: bool, preimage: Option, change: Option>>) -> Self { - Self { - inner: MeltedSdk { - paid, - preimage, - change: change.map(|c| c.iter().map(|p| p.as_ref().deref().clone()).collect()), - }, - } - } - - pub fn preimage(&self) -> Option { - self.inner.preimage.clone() - } - - pub fn paid(&self) -> bool { - self.inner.paid - } - - pub fn change(&self) -> Option>> { - self.inner - .change - .clone() - .map(|c| c.into_iter().map(|p| Arc::new(p.into())).collect()) - } -} diff --git a/bindings/cashu-sdk-ffi/src/types/mod.rs b/bindings/cashu-sdk-ffi/src/types/mod.rs deleted file mode 100644 index 969dd4b8..00000000 --- a/bindings/cashu-sdk-ffi/src/types/mod.rs +++ /dev/null @@ -1,9 +0,0 @@ -pub mod keyset_info; -pub mod melted; -pub mod proofs_status; -pub mod send_proofs; - -pub use keyset_info::MintKeySetInfo; -pub use melted::Melted; -pub use proofs_status::ProofsStatus; -pub use send_proofs::SendProofs; diff --git a/bindings/cashu-sdk-ffi/src/types/proofs_status.rs b/bindings/cashu-sdk-ffi/src/types/proofs_status.rs deleted file mode 100644 index ff54439c..00000000 --- a/bindings/cashu-sdk-ffi/src/types/proofs_status.rs +++ /dev/null @@ -1,55 +0,0 @@ -use std::ops::Deref; -use std::sync::Arc; - -use cashu_sdk::types::ProofsStatus as ProofsStatusSdk; - -use crate::Proof; - -pub struct ProofsStatus { - inner: ProofsStatusSdk, -} - -impl Deref for ProofsStatus { - type Target = ProofsStatusSdk; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for ProofsStatus { - fn from(inner: ProofsStatusSdk) -> ProofsStatus { - ProofsStatus { inner } - } -} - -impl ProofsStatus { - pub fn new(spendable: Vec>, spent: Vec>) -> Self { - Self { - inner: ProofsStatusSdk { - spendable: spendable - .iter() - .map(|p| p.as_ref().deref().clone()) - .collect(), - spent: spent.iter().map(|p| p.as_ref().deref().clone()).collect(), - }, - } - } - - pub fn spendable(&self) -> Vec> { - self.inner - .spendable - .clone() - .into_iter() - .map(|p| Arc::new(p.into())) - .collect() - } - - pub fn spent(&self) -> Vec> { - self.inner - .spent - .clone() - .into_iter() - .map(|p| Arc::new(p.into())) - .collect() - } -} diff --git a/bindings/cashu-sdk-ffi/src/types/send_proofs.rs b/bindings/cashu-sdk-ffi/src/types/send_proofs.rs deleted file mode 100644 index 02e6b24b..00000000 --- a/bindings/cashu-sdk-ffi/src/types/send_proofs.rs +++ /dev/null @@ -1,57 +0,0 @@ -use std::ops::Deref; -use std::sync::Arc; - -use cashu_ffi::Proof; -use cashu_sdk::types::SendProofs as SendProofsSdk; - -pub struct SendProofs { - inner: SendProofsSdk, -} - -impl Deref for SendProofs { - type Target = SendProofsSdk; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for SendProofs { - fn from(inner: SendProofsSdk) -> SendProofs { - SendProofs { inner } - } -} - -impl SendProofs { - pub fn new(change_proofs: Vec>, send_proofs: Vec>) -> Self { - Self { - inner: SendProofsSdk { - change_proofs: change_proofs - .iter() - .map(|p| p.as_ref().deref().clone()) - .collect(), - send_proofs: send_proofs - .iter() - .map(|p| p.as_ref().deref().clone()) - .collect(), - }, - } - } - - pub fn send_proofs(&self) -> Vec> { - self.inner - .send_proofs - .clone() - .into_iter() - .map(|p| Arc::new(p.into())) - .collect() - } - - pub fn change_proofs(&self) -> Vec> { - self.inner - .change_proofs - .clone() - .into_iter() - .map(|p| Arc::new(p.into())) - .collect() - } -} diff --git a/bindings/cashu-sdk-ffi/src/wallet.rs b/bindings/cashu-sdk-ffi/src/wallet.rs deleted file mode 100644 index cbcf95cb..00000000 --- a/bindings/cashu-sdk-ffi/src/wallet.rs +++ /dev/null @@ -1,180 +0,0 @@ -use std::ops::Deref; -use std::sync::Arc; - -use cashu_ffi::{ - BlindedSignature, Bolt11Invoice, CurrencyUnit, MeltQuote, MintQuote, PreMintSecrets, Proof, - Token, -}; -use cashu_sdk::client::minreq_client::HttpClient; -use cashu_sdk::types::ProofsStatus; -use cashu_sdk::url::UncheckedUrl; -use cashu_sdk::wallet::Wallet as WalletSdk; -use once_cell::sync::Lazy; -use tokio::runtime::Runtime; -use tokio::sync::Mutex; - -use crate::error::Result; -use crate::types::{Melted, SendProofs}; -use crate::{Amount, Keys}; - -static RUNTIME: Lazy = Lazy::new(|| Runtime::new().expect("Can't start Tokio runtime")); - -pub struct Wallet { - inner: Mutex>, -} - -impl Wallet { - pub fn new( - mint_url: String, - mint_keys: Arc, - mint_quotes: Vec>, - melt_quotes: Vec>, - ) -> Self { - let client = HttpClient {}; - Self { - inner: WalletSdk::new( - client, - UncheckedUrl::new(mint_url), - mint_quotes - .into_iter() - .map(|q| q.as_ref().deref().clone()) - .collect(), - melt_quotes - .into_iter() - .map(|q| q.as_ref().deref().clone()) - .collect(), - mint_keys.as_ref().deref().clone(), - ) - .into(), - } - } - - pub fn check_proofs_spent(&self, proofs: Vec>) -> Result> { - let proofs = RUNTIME.block_on(async { - self.inner - .lock() - .await - .check_proofs_spent(proofs.iter().map(|p| p.as_ref().deref().clone()).collect()) - .await - })?; - - Ok(Arc::new(proofs)) - } - - pub fn mint_token( - &self, - amount: Arc, - unit: Option, - memo: Option, - ) -> Result> { - let token = RUNTIME.block_on(async { - self.inner - .lock() - .await - .mint_token(*amount.as_ref().deref(), memo, unit.map(|u| u.into())) - .await - })?; - - Ok(Arc::new(token.into())) - } - - pub fn mint_quote(&self, amount: Arc, unit: CurrencyUnit) -> Result> { - let quote = RUNTIME.block_on(async { - self.inner - .lock() - .await - .mint_quote(*amount.as_ref().deref(), unit.into()) - .await - })?; - - Ok(Arc::new(quote.into())) - } - - pub fn mint(&self, quote: String) -> Result>> { - let proofs = RUNTIME.block_on(async { self.inner.lock().await.mint("e).await })?; - - Ok(proofs.into_iter().map(|p| Arc::new(p.into())).collect()) - } - - pub fn receive(&self, encoded_token: String) -> Result>> { - let proofs = - RUNTIME.block_on(async { self.inner.lock().await.receive(&encoded_token).await })?; - - Ok(proofs.into_iter().map(|p| Arc::new(p.into())).collect()) - } - - pub fn process_swap_response( - &self, - blinded_messages: Arc, - promises: Vec>, - ) -> Result>> { - let proofs = RUNTIME.block_on(async { - self.inner.lock().await.process_split_response( - blinded_messages.as_ref().deref().clone(), - promises.iter().map(|p| p.as_ref().into()).collect(), - ) - })?; - Ok(proofs.into_iter().map(|p| Arc::new(p.into())).collect()) - } - - pub fn send(&self, amount: Arc, proofs: Vec>) -> Result> { - let send_proofs = RUNTIME.block_on(async { - self.inner - .lock() - .await - .send( - *amount.as_ref().deref(), - proofs.iter().map(|p| p.as_ref().deref().clone()).collect(), - ) - .await - })?; - - Ok(Arc::new(send_proofs.into())) - } - - pub fn melt_quote( - &self, - unit: CurrencyUnit, - request: Arc, - ) -> Result> { - let melt_quote = RUNTIME.block_on(async { - self.inner - .lock() - .await - .melt_quote(unit.into(), request.as_ref().deref().clone()) - .await - })?; - - Ok(Arc::new(melt_quote.into())) - } - - pub fn melt(&self, quote_id: String, proofs: Vec>) -> Result> { - let melted = RUNTIME.block_on(async { - self.inner - .lock() - .await - .melt( - "e_id, - proofs.iter().map(|p| p.as_ref().deref().clone()).collect(), - ) - .await - })?; - - Ok(Arc::new(melted.into())) - } - - pub fn proofs_to_token( - &self, - proofs: Vec>, - unit: Option, - memo: Option, - ) -> Result { - Ok(RUNTIME.block_on(async { - self.inner.lock().await.proofs_to_token( - proofs.iter().map(|p| p.as_ref().deref().clone()).collect(), - memo, - unit.map(|u| u.into()), - ) - })?) - } -} diff --git a/bindings/cashu-sdk-ffi/uniffi.toml b/bindings/cashu-sdk-ffi/uniffi.toml deleted file mode 100644 index 26944880..00000000 --- a/bindings/cashu-sdk-ffi/uniffi.toml +++ /dev/null @@ -1,11 +0,0 @@ -[bindings.kotlin] -package_name = "cashu_sdk" -cdylib_name = "cashu_sdk_ffi" - -[bindings.swift] -ffi_module_filename = "cashu_sdkFFI" -cdylib_name = "cashu_sdk_ffi" - -[bindings.python] -cdylib_name = "cashu_sdk_ffi" - diff --git a/bindings/cashu-sdk-js/.cargo/config.toml b/bindings/cashu-sdk-js/.cargo/config.toml deleted file mode 100644 index f4e8c002..00000000 --- a/bindings/cashu-sdk-js/.cargo/config.toml +++ /dev/null @@ -1,2 +0,0 @@ -[build] -target = "wasm32-unknown-unknown" diff --git a/bindings/cashu-sdk-js/.gitignore b/bindings/cashu-sdk-js/.gitignore deleted file mode 100644 index bed4e246..00000000 --- a/bindings/cashu-sdk-js/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -/target -**/*.rs.bk -Cargo.lock -bin/ -pkg/ -wasm-pack.log -*.tgz diff --git a/bindings/cashu-sdk-js/Cargo.toml b/bindings/cashu-sdk-js/Cargo.toml deleted file mode 100644 index 4f75d8da..00000000 --- a/bindings/cashu-sdk-js/Cargo.toml +++ /dev/null @@ -1,36 +0,0 @@ -[package] -name = "cashu-sdk-js" -version = "0.1.0" -authors = ["thesimplekid "] -edition = "2021" -publish = false -repository.workspace = true -license.workspace = true - -[lib] -crate-type = ["cdylib", "rlib"] - -[features] -default = ["console_error_panic_hook"] - -[dependencies] -cashu-sdk = { path = "../../crates/cashu-sdk", features = ["all-nuts", "gloo"] } -cashu-js = { path = "../cashu-js" } -wasm-bindgen = "0.2.84" -js-sys = "0.3.64" -serde-wasm-bindgen = "0.6.0" -serde_json.workspace = true -serde.workspace = true -wasm-bindgen-futures = "0.4.37" - -# The `console_error_panic_hook` crate provides better debugging of panics by -# logging them with `console.error`. This is great for development, but requires -# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for -# code size when deploying. -console_error_panic_hook = { version = "0.1.7", optional = true } - -[dev-dependencies] -wasm-bindgen-test = "0.3.34" - -[package.metadata.wasm-pack.profile.release] -wasm-opt = true diff --git a/bindings/cashu-sdk-js/LICENSE b/bindings/cashu-sdk-js/LICENSE deleted file mode 100644 index 083823dd..00000000 --- a/bindings/cashu-sdk-js/LICENSE +++ /dev/null @@ -1,29 +0,0 @@ -BSD 3-Clause License - -Copyright (c) 2023, thesimplekid -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -3. Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/bindings/cashu-sdk-js/LICENSES/NOSTR-MIT b/bindings/cashu-sdk-js/LICENSES/NOSTR-MIT deleted file mode 100644 index 2ff56442..00000000 --- a/bindings/cashu-sdk-js/LICENSES/NOSTR-MIT +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2022-2023 Yuki Kishimoto - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/bindings/cashu-sdk-js/README.md b/bindings/cashu-sdk-js/README.md deleted file mode 100644 index e69de29b..00000000 diff --git a/bindings/cashu-sdk-js/examples/amount.js b/bindings/cashu-sdk-js/examples/amount.js deleted file mode 100644 index e381dbd4..00000000 --- a/bindings/cashu-sdk-js/examples/amount.js +++ /dev/null @@ -1,12 +0,0 @@ -const {Amount, loadWasmAsync, loadWasmSync } = require(".."); - - -function main() { - loadWasmSync(); - - let amount = Amount.fromSat(BigInt(10)); - - console.log(amount.toSat()) -} - -main(); diff --git a/bindings/cashu-sdk-js/examples/wallet.js b/bindings/cashu-sdk-js/examples/wallet.js deleted file mode 100644 index 95830c79..00000000 --- a/bindings/cashu-sdk-js/examples/wallet.js +++ /dev/null @@ -1,19 +0,0 @@ -const {Amount, loadWasmAsync, Wallet, Client } = require(".."); - - -async function main() { - await loadWasmAsync(); - - let client = new Client("https://mutinynet-cashu.thesimpekid.space"); - - let keys = await client.getKeys(); - - let wallet = new Wallet(client, keys); - - let amount = Amount.fromSat(BigInt(10)); - let pr = await wallet.requestMint(amount); - - console.log(pr); -} - -main(); diff --git a/bindings/cashu-sdk-js/justfile b/bindings/cashu-sdk-js/justfile deleted file mode 100644 index d1235b12..00000000 --- a/bindings/cashu-sdk-js/justfile +++ /dev/null @@ -1,5 +0,0 @@ -build: - wasm-pack build - -pack: - npm run package diff --git a/bindings/cashu-sdk-js/package.json b/bindings/cashu-sdk-js/package.json deleted file mode 100644 index a371d7f9..00000000 --- a/bindings/cashu-sdk-js/package.json +++ /dev/null @@ -1,44 +0,0 @@ -{ - "name": "@rust-cashu/cashu-sdk", - "version": "0.0.1", - "description": "Cashu protocol implementation, for JavaScript", - "keywords": [ - "cashu", - "protocol", - "rust", - "bindings" - ], - "license": "BSD-3-Clause", - "homepage": "https://github.com/thesimplekid/cashu-crab", - "repository": { - "type": "git", - "url": "git+https://github.com/thesimplekid/cashu-crab" - }, - "bugs": { - "url": "https://github.com/thesimplekid/cashu-crab/issues" - }, - "author": { - "name": "thesimplekid", - "email": "tsk@thesimplekid.com", - "url": "https://github.com/thesimplekid" - }, - "main": "pkg/cashu_sdk_js.js", - "types": "pkg/cashu_sdk_js.d.ts", - "files": [ - "pkg/cashu_sdk_js_bg.wasm.js", - "pkg/cashu_sdk_js_bg.wasm.d.ts", - "pkg/cashu_sdk_js.js", - "pkg/cashu_sdk_js.d.ts" - ], - "devDependencies": { - "wasm-pack": "^0.10.2" - }, - "engines": { - "node": ">= 10" - }, - "scripts": { - "build": "WASM_PACK_ARGS=--release ./scripts/build.sh", - "build:dev": "WASM_PACK_ARGS=--dev ./scripts/build.sh", - "package": "npm run build && npm pack" - } -} diff --git a/bindings/cashu-sdk-js/scripts/LICENSE b/bindings/cashu-sdk-js/scripts/LICENSE deleted file mode 100644 index 2ff56442..00000000 --- a/bindings/cashu-sdk-js/scripts/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2022-2023 Yuki Kishimoto - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/bindings/cashu-sdk-js/scripts/build.sh b/bindings/cashu-sdk-js/scripts/build.sh deleted file mode 100755 index 01ec1540..00000000 --- a/bindings/cashu-sdk-js/scripts/build.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash -# -# Build the JavaScript modules -# -# This script is really a workaround for https://github.com/rustwasm/wasm-pack/issues/1074. -# -# Currently, the only reliable way to load WebAssembly in all the JS -# environments we want to target (web-via-webpack, web-via-browserify, jest) -# seems to be to pack the WASM into base64, and then unpack it and instantiate -# it at runtime. -# -# Hopefully one day, https://github.com/rustwasm/wasm-pack/issues/1074 will be -# fixed and this will be unnecessary. - -set -e - -cd "$(dirname "$0")"/.. - -WASM_BINDGEN_WEAKREF=1 wasm-pack build --target nodejs --scope rust-cashu --out-dir pkg "${WASM_PACK_ARGS[@]}" - -# Convert the Wasm into a JS file that exports the base64'ed Wasm. -echo "module.exports = \`$(base64 pkg/cashu_sdk_js_bg.wasm)\`;" > pkg/cashu_sdk_js_bg.wasm.js - -# In the JavaScript: -# 1. Strip out the lines that load the WASM, and our new epilogue. -# 2. Remove the imports of `TextDecoder` and `TextEncoder`. We rely on the global defaults. -{ - sed -e '/Text..coder.*= require(.util.)/d' \ - -e '/^const path = /,$d' pkg/cashu_sdk_js.js - cat scripts/epilogue.js -} > pkg/cashu_sdk_js.js.new -mv pkg/cashu_sdk_js.js.new pkg/cashu_sdk_js.js - -# also extend the typescript -cat scripts/epilogue.d.ts >> pkg/cashu_sdk_js.d.ts diff --git a/bindings/cashu-sdk-js/scripts/epilogue.d.ts b/bindings/cashu-sdk-js/scripts/epilogue.d.ts deleted file mode 100644 index 2a3f7fe1..00000000 --- a/bindings/cashu-sdk-js/scripts/epilogue.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -/** - * Load the WebAssembly module in the background, if it has not already been loaded. - * - * Returns a promise which will resolve once the other methods are ready. - * - * @returns {Promise} - */ - export function loadWasmAsync(): Promise; - - export function loadWasmSync(): void; diff --git a/bindings/cashu-sdk-js/scripts/epilogue.js b/bindings/cashu-sdk-js/scripts/epilogue.js deleted file mode 100644 index 967076d5..00000000 --- a/bindings/cashu-sdk-js/scripts/epilogue.js +++ /dev/null @@ -1,76 +0,0 @@ -let inited = false; -module.exports.loadWasmSync = function () { - if (inited) { - return; - } - if (initPromise) { - throw new Error("Asynchronous initialisation already in progress: cannot initialise synchronously"); - } - const bytes = unbase64(require("./cashu_sdk_js_bg.wasm.js")); - const mod = new WebAssembly.Module(bytes); - const instance = new WebAssembly.Instance(mod, imports); - wasm = instance.exports; - wasm.__wbindgen_start(); - inited = true; -}; - -let initPromise = null; - -/** - * Load the WebAssembly module in the background, if it has not already been loaded. - * - * Returns a promise which will resolve once the other methods are ready. - * - * @returns {Promise} - */ -module.exports.loadWasmAsync = function () { - if (inited) { - return Promise.resolve(); - } - if (!initPromise) { - initPromise = Promise.resolve() - .then(() => require("./cashu_sdk_js_bg.wasm.js")) - .then((b64) => WebAssembly.instantiate(unbase64(b64), imports)) - .then((result) => { - wasm = result.instance.exports; - wasm.__wbindgen_start(); - inited = true; - }); - } - return initPromise; -}; - -const b64lookup = new Uint8Array([ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 62, 0, 62, 0, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, - 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 0, 0, 0, 0, 63, 0, 26, 27, 28, 29, 30, 31, 32, - 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -]); - -// base64 decoder, based on the code at https://developer.mozilla.org/en-US/docs/Glossary/Base64#solution_2_%E2%80%93_rewriting_atob_and_btoa_using_typedarrays_and_utf-8 -function unbase64(sBase64) { - const sB64Enc = sBase64.replace(/[^A-Za-z0-9+/]/g, ""); - const nInLen = sB64Enc.length; - const nOutLen = (nInLen * 3 + 1) >> 2; - const taBytes = new Uint8Array(nOutLen); - - let nMod3; - let nMod4; - let nUint24 = 0; - let nOutIdx = 0; - for (let nInIdx = 0; nInIdx < nInLen; nInIdx++) { - nMod4 = nInIdx & 3; - nUint24 |= b64lookup[sB64Enc.charCodeAt(nInIdx)] << (6 * (3 - nMod4)); - if (nMod4 === 3 || nInLen - nInIdx === 1) { - nMod3 = 0; - while (nMod3 < 3 && nOutIdx < nOutLen) { - taBytes[nOutIdx] = (nUint24 >>> ((16 >>> nMod3) & 24)) & 255; - nMod3++; - nOutIdx++; - } - nUint24 = 0; - } - } - - return taBytes; -} diff --git a/bindings/cashu-sdk-js/src/error.rs b/bindings/cashu-sdk-js/src/error.rs deleted file mode 100644 index 019f9a3a..00000000 --- a/bindings/cashu-sdk-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::error::Error, -{ - JsValue::from_str(&error.to_string()) -} diff --git a/bindings/cashu-sdk-js/src/lib.rs b/bindings/cashu-sdk-js/src/lib.rs deleted file mode 100644 index f1f132c8..00000000 --- a/bindings/cashu-sdk-js/src/lib.rs +++ /dev/null @@ -1,7 +0,0 @@ -mod error; -mod mint; -mod types; -mod wallet; - -pub use mint::JsMint; -pub use wallet::JsWallet; diff --git a/bindings/cashu-sdk-js/src/mint.rs b/bindings/cashu-sdk-js/src/mint.rs deleted file mode 100644 index 9b3145c0..00000000 --- a/bindings/cashu-sdk-js/src/mint.rs +++ /dev/null @@ -1,136 +0,0 @@ -use std::ops::Deref; -use std::str::FromStr; - -#[cfg(feature = "nut07")] -use cashu_js::nuts::{JsCheckSpendableRequest, JsCheckSpendableResponse}; -use cashu_js::nuts::{ - JsId, JsKeySet, JsKeySetsResponse, JsKeysResponse, JsMeltBolt11Request, JsMeltBolt11Response, - JsSwapRequest, JsSwapResponse, -}; -use cashu_js::JsAmount; -use cashu_sdk::mint::Mint; -use cashu_sdk::nuts::{KeySet, KeysResponse}; -use cashu_sdk::Mnemonic; -use wasm_bindgen::prelude::*; - -use crate::error::{into_err, Result}; - -#[wasm_bindgen(js_name = Mint)] -pub struct JsMint { - inner: Mint, -} - -impl Deref for JsMint { - type Target = Mint; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsMint { - fn from(inner: Mint) -> JsMint { - JsMint { inner } - } -} - -#[wasm_bindgen(js_class = Mint)] -impl JsMint { - #[wasm_bindgen(constructor)] - pub fn new( - secret: String, - keyset_info: JsValue, - spent_secrets: JsValue, - quotes: JsValue, - min_fee_reserve: JsAmount, - percent_fee_reserve: f32, - ) -> Result { - let keyset_info = serde_wasm_bindgen::from_value(keyset_info).map_err(into_err)?; - let spent_secrets = serde_wasm_bindgen::from_value(spent_secrets).map_err(into_err)?; - - let quotes = serde_wasm_bindgen::from_value(quotes).map_err(into_err)?; - Ok(JsMint { - inner: Mint::new( - Mnemonic::from_str(&secret).unwrap(), - keyset_info, - spent_secrets, - quotes, - *min_fee_reserve.deref(), - percent_fee_reserve, - ), - }) - } - - /// Get Active Keyset Pubkeys - #[wasm_bindgen(getter)] - pub fn keyset_pubkeys(&self, keyset_id: JsId) -> Result { - let keyset: KeySet = self - .inner - .keyset(&keyset_id) - .ok_or(JsError::new("Unknown Keyset"))? - .clone(); - - Ok(KeysResponse { - keysets: vec![keyset], - } - .into()) - } - - /// Get Keysets - #[wasm_bindgen(js_name = keySets)] - pub fn keysets(&self) -> JsKeySetsResponse { - self.inner.keysets().into() - } - - /// Keyset - #[wasm_bindgen(js_name = KeySet)] - pub fn keyset(&self, id: JsId) -> Option { - self.inner.keyset(id.deref()).map(|ks| ks.into()) - } - - /// Process Split Request - #[wasm_bindgen(js_name = ProcessSwapRequest)] - pub fn process_swap_request(&mut self, swap_request: JsSwapRequest) -> Result { - Ok(self - .inner - .process_swap_request(swap_request.deref().clone()) - .map_err(into_err)? - .into()) - } - - /// Check Spendable - #[cfg(feature = "nut07")] - #[wasm_bindgen(js_name = CheckSpendable)] - pub fn check_spendable( - &mut self, - check_request: JsCheckSpendableRequest, - ) -> Result { - Ok(self - .inner - .check_spendable(&check_request.deref().clone()) - .map_err(into_err)? - .into()) - } - - /// Check Verify Melt - #[wasm_bindgen(js_name = VerifyMelt)] - pub fn verify_melt(&mut self, melt_request: JsMeltBolt11Request) -> Result<()> { - self.inner - .verify_melt_request(melt_request.deref()) - .map_err(into_err) - } - - /// Process Melt Request - #[wasm_bindgen(js_name = ProcessMeltRequest)] - pub fn process_melt_request( - &mut self, - melt_request: JsMeltBolt11Request, - preimage: String, - total_spent: JsAmount, - ) -> Result { - Ok(self - .inner - .process_melt_request(melt_request.deref(), &preimage, *total_spent.deref()) - .map_err(into_err)? - .into()) - } -} diff --git a/bindings/cashu-sdk-js/src/types/melted.rs b/bindings/cashu-sdk-js/src/types/melted.rs deleted file mode 100644 index 0f62e4bd..00000000 --- a/bindings/cashu-sdk-js/src/types/melted.rs +++ /dev/null @@ -1,57 +0,0 @@ -use std::ops::Deref; - -use cashu_sdk::types::Melted; -use wasm_bindgen::prelude::*; - -use crate::error::{into_err, 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(constructor)] - pub fn new(paid: bool, preimage: Option, change: JsValue) -> Result { - let change = serde_wasm_bindgen::from_value(change).map_err(into_err)?; - Ok(JsMelted { - inner: Melted { - paid, - preimage, - change, - }, - }) - } - - /// Get Preimage - #[wasm_bindgen(getter)] - pub fn preimage(&self) -> Option { - self.inner.preimage.clone() - } - - /// Get Paid - #[wasm_bindgen(getter)] - pub fn paid(&self) -> bool { - self.inner.paid - } - - /// Get Change - #[wasm_bindgen(getter)] - pub fn change(&self) -> Result { - serde_wasm_bindgen::to_value(&self.change).map_err(into_err) - } -} diff --git a/bindings/cashu-sdk-js/src/types/mod.rs b/bindings/cashu-sdk-js/src/types/mod.rs deleted file mode 100644 index 4d12b0d5..00000000 --- a/bindings/cashu-sdk-js/src/types/mod.rs +++ /dev/null @@ -1,5 +0,0 @@ -mod melted; -mod send_proofs; - -pub use melted::JsMelted; -pub use send_proofs::JsSendProofs; diff --git a/bindings/cashu-sdk-js/src/types/send_proofs.rs b/bindings/cashu-sdk-js/src/types/send_proofs.rs deleted file mode 100644 index 76a75acc..00000000 --- a/bindings/cashu-sdk-js/src/types/send_proofs.rs +++ /dev/null @@ -1,51 +0,0 @@ -use std::ops::Deref; - -use cashu_sdk::types::SendProofs; -use wasm_bindgen::prelude::*; - -use crate::error::{into_err, Result}; - -#[wasm_bindgen(js_name = SendProofs)] -pub struct JsSendProofs { - inner: SendProofs, -} - -impl Deref for JsSendProofs { - type Target = SendProofs; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - -impl From for JsSendProofs { - fn from(inner: SendProofs) -> JsSendProofs { - JsSendProofs { inner } - } -} - -#[wasm_bindgen(js_class = SendProofs)] -impl JsSendProofs { - #[wasm_bindgen(constructor)] - pub fn new(change_proofs: JsValue, send_proofs: JsValue) -> Result { - let change_proofs = serde_wasm_bindgen::from_value(change_proofs).map_err(into_err)?; - let send_proofs = serde_wasm_bindgen::from_value(send_proofs).map_err(into_err)?; - Ok(JsSendProofs { - inner: SendProofs { - change_proofs, - send_proofs, - }, - }) - } - - /// Get Change Proofs - #[wasm_bindgen(getter)] - pub fn change_proofs(&self) -> Result { - serde_wasm_bindgen::to_value(&self.inner.change_proofs).map_err(into_err) - } - - /// Get Send Proofs - #[wasm_bindgen(getter)] - pub fn send_proofs(&self) -> Result { - serde_wasm_bindgen::to_value(&self.inner.send_proofs).map_err(into_err) - } -} diff --git a/bindings/cashu-sdk-js/src/wallet.rs b/bindings/cashu-sdk-js/src/wallet.rs deleted file mode 100644 index df802aaa..00000000 --- a/bindings/cashu-sdk-js/src/wallet.rs +++ /dev/null @@ -1,188 +0,0 @@ -use std::collections::HashMap; -use std::ops::Deref; -use std::str::FromStr; - -use cashu_js::nuts::nut00::{JsBlindedMessages, JsToken}; -use cashu_js::nuts::nut01::JsKeys; -use cashu_js::JsAmount; -#[cfg(feature = "nut07")] -use cashu_js::JsProofsStatus; -use cashu_sdk::client::gloo_client::HttpClient; -use cashu_sdk::nuts::{CurrencyUnit, Id}; -use cashu_sdk::url::UncheckedUrl; -use cashu_sdk::wallet::Wallet; -use wasm_bindgen::prelude::*; - -use crate::error::{into_err, Result}; -use crate::types::{JsMelted, JsSendProofs}; - -#[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 { - // TODO: Quotes - #[wasm_bindgen(constructor)] - pub fn new(mint_urls: Vec, mint_keys: Vec) -> JsWallet { - let client = HttpClient {}; - - let mints = mint_urls - .iter() - .map(|u| (UncheckedUrl::from_str(u).unwrap(), None)) - .collect(); - - let keys = mint_keys - .iter() - .map(|k| (Id::from(k.deref()), k.deref().clone())) - .collect(); - - JsWallet { - inner: Wallet::new(client, mints, HashMap::new(), vec![], vec![], None, keys), - } - } - - /// Check Proofs spent - #[cfg(feature = "nut07")] - #[wasm_bindgen(js_name = checkProofsSpent)] - pub async fn check_proofs_spent(&self, proofs: JsValue) -> Result { - let proofs = serde_wasm_bindgen::from_value(proofs).map_err(into_err)?; - - Ok(self - .inner - .check_proofs_spent(&proofs) - .await - .map_err(into_err)? - .into()) - } - - /// Mint Token - #[wasm_bindgen(js_name = mintToken)] - pub async fn mint_token( - &mut self, - mint_url: String, - amount: JsAmount, - memo: Option, - unit: Option, - ) -> Result { - let mint_url = UncheckedUrl::from_str(&mint_url).map_err(into_err)?; - let unit = unit.map(|u| CurrencyUnit::from_str(&u).unwrap_or_default()); - - Ok(self - .inner - .mint_token(mint_url, *amount.deref(), memo, unit) - .await - .map_err(into_err)? - .into()) - } - - /// Mint - #[wasm_bindgen(js_name = mint)] - pub async fn mint(&mut self, mint_url: String, quote: String) -> Result { - let mint_url = UncheckedUrl::from_str(&mint_url).map_err(into_err)?; - serde_wasm_bindgen::to_value(&self.inner.mint(mint_url, "e).await.map_err(into_err)?) - .map_err(into_err) - } - - /// Receive - #[wasm_bindgen(js_name = receive)] - pub async fn receive(&mut self, token: String) -> Result { - serde_wasm_bindgen::to_value(&self.inner.receive(&token).await.map_err(into_err)?) - .map_err(into_err) - } - - /// Process Split - #[wasm_bindgen(js_name = processSplitResponse)] - pub fn process_split_response( - &self, - blinded_messages: JsBlindedMessages, - promises: JsValue, - ) -> Result { - let promises = serde_wasm_bindgen::from_value(promises).map_err(into_err)?; - - serde_wasm_bindgen::to_value( - &self - .inner - .process_split_response(blinded_messages.deref().clone(), promises) - .map_err(into_err)?, - ) - .map_err(into_err) - } - - /// Send - #[wasm_bindgen(js_name = send)] - pub async fn send( - &mut self, - mint_url: String, - amount: JsAmount, - unit: String, - proofs: JsValue, - ) -> Result { - let mint_url = UncheckedUrl::from_str(&mint_url).map_err(into_err)?; - let unit = CurrencyUnit::from_str(&unit).map_err(into_err)?; - let proofs = serde_wasm_bindgen::from_value(proofs).map_err(into_err)?; - - Ok(self - .inner - .send(&mint_url, &unit, *amount.deref(), proofs) - .await - .map_err(into_err)? - .into()) - } - - /// Melt - #[wasm_bindgen(js_name = melt)] - pub async fn melt( - &mut self, - mint_url: String, - quote: String, - proofs: JsValue, - ) -> Result { - let mint_url = UncheckedUrl::from_str(&mint_url).map_err(into_err)?; - let proofs = serde_wasm_bindgen::from_value(proofs).map_err(into_err)?; - - Ok(self - .inner - .melt(&mint_url, "e, proofs) - .await - .map_err(into_err)? - .into()) - } - - /// Proofs to token - #[wasm_bindgen(js_name = proofsToToken)] - pub fn proofs_to_token( - &self, - mint_url: String, - proofs: JsValue, - unit: Option, - memo: Option, - ) -> Result { - let mint_url = UncheckedUrl::from_str(&mint_url).map_err(into_err)?; - let proofs = serde_wasm_bindgen::from_value(proofs).map_err(into_err)?; - - let unit = unit.map(|u| { - CurrencyUnit::from_str(&u) - .map_err(into_err) - .unwrap_or_default() - }); - - self.inner - .proofs_to_token(mint_url, proofs, memo, unit) - .map_err(into_err) - } -} diff --git a/bindings/uniffi-bindgen/Cargo.toml b/bindings/uniffi-bindgen/Cargo.toml deleted file mode 100644 index eed466f6..00000000 --- a/bindings/uniffi-bindgen/Cargo.toml +++ /dev/null @@ -1,12 +0,0 @@ -[package] -name = "uniffi-bindgen" -version = "0.1.0" -edition = "2021" -publish = false -rust-version.workspace = true - -[dependencies] -uniffi = { workspace = true, features = ["cli"] } - -[build-dependencies] -uniffi = { workspace = true, features = ["build"] } diff --git a/bindings/uniffi-bindgen/src/main.rs b/bindings/uniffi-bindgen/src/main.rs deleted file mode 100644 index f6cff6cf..00000000 --- a/bindings/uniffi-bindgen/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - uniffi::uniffi_bindgen_main() -} diff --git a/crates/cashu-sdk/src/wallet.rs b/crates/cashu-sdk/src/wallet.rs index c18c24c2..06432e9d 100644 --- a/crates/cashu-sdk/src/wallet.rs +++ b/crates/cashu-sdk/src/wallet.rs @@ -154,6 +154,7 @@ impl Wallet { Ok(token?) } */ + /// Mint Quote pub async fn mint_quote( &mut self, @@ -322,7 +323,7 @@ impl Wallet { pre_swap.pre_mint_secrets.secrets(), &keys.unwrap(), )?; - let mint_proofs = proofs.entry(token.mint).or_insert(Vec::new()); + let mint_proofs = proofs.entry(token.mint).or_default(); mint_proofs.extend(p); }