Skip to content

Commit 7e3b3fb

Browse files
asmogothesimplekid
authored andcommitted
feat(nwc): add NIP-47 wallet service support
Introduce a transport-agnostic cdk-nwc crate that connects to Nostr relays, advertises supported NWC commands, validates authorized requests, deduplicates event ids, and publishes encrypted responses. Add a CDK wallet handler for get_info, get_balance, make_invoice, pay_invoice, lookup_invoice, and list_transactions, including msat/unit conversion, quote lookup, and per-payment limits. Expose the service through UniFFI and add an example plus an end-to-end relay-backed NWC flow test.
1 parent 563c6da commit 7e3b3fb

23 files changed

Lines changed: 2819 additions & 6 deletions

File tree

Cargo.lock

Lines changed: 31 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.lock.msrv

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ cdk-mintd = { path = "./crates/cdk-mintd", version = "=0.17.0", default-features
7272
cdk-prometheus = { path = "./crates/cdk-prometheus", version = "=0.17.0", default-features = false }
7373
cdk-supabase = { path = "./crates/cdk-supabase", version = "=0.17.0", default-features = false }
7474
cdk-npubcash = { path = "./crates/cdk-npubcash", default-features = false, version = "=0.17.0" }
75+
cdk-nwc = { path = "./crates/cdk-nwc", version = "=0.17.0" }
7576
cdk-bdk = { path = "./crates/cdk-bdk", version = "=0.17.0", default-features = false }
7677
clap = { version = "4.5.31", features = ["derive"] }
7778
ciborium = { version = "0.2.2", default-features = false, features = ["std"] }
@@ -127,6 +128,7 @@ prometheus = { version = "0.13.4", features = ["process"], default-features = fa
127128
nostr-sdk = { version = "0.44.1", default-features = false, features = [
128129
"nip04",
129130
"nip44",
131+
"nip47",
130132
"nip59"
131133
]}
132134
bitcoin-payment-instructions = { version = "0.7.0", default-features = false }

bindings/dart/rust/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ name = "uniffi-bindgen"
1717
path = "uniffi-bindgen.rs"
1818

1919
[dependencies]
20-
cdk-ffi = { workspace = true, features = ["npubcash", "bip353"] }
20+
cdk-ffi = { workspace = true, features = ["npubcash", "nwc", "bip353"] }
2121
uniffi = { workspace = true, features = ["cli"] }
2222
uniffi-dart = { git = "https://github.com/Uniffi-Dart/uniffi-dart", tag = "v0.1.0+v0.30.0" }
2323
camino = "1.2"

bindings/go/rust/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ crate-type = ["cdylib"]
1313
name = "cdk_ffi_go"
1414

1515
[dependencies]
16-
cdk-ffi = { workspace = true, features = ["npubcash", "bip353"] }
16+
cdk-ffi = { workspace = true, features = ["npubcash", "nwc", "bip353"] }
1717
uniffi = { workspace = true, features = ["cli"] }
1818

1919
[build-dependencies]

bindings/kotlin/rust/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ name = "uniffi-bindgen"
1717
path = "uniffi-bindgen.rs"
1818

1919
[dependencies]
20-
cdk-ffi = { workspace = true, default-features = false, features = ["npubcash", "bip353"] }
20+
cdk-ffi = { workspace = true, default-features = false, features = ["npubcash", "nwc", "bip353"] }
2121
uniffi = { workspace = true, features = ["cli"] }
2222

2323
[build-dependencies]

bindings/swift/rust/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ name = "uniffi-bindgen-swift"
1818
path = "uniffi-bindgen-swift.rs"
1919

2020
[dependencies]
21-
cdk-ffi = { workspace = true, default-features = false, features = ["npubcash", "bip353"] }
21+
cdk-ffi = { workspace = true, default-features = false, features = ["npubcash", "nwc", "bip353"] }
2222
uniffi = { workspace = true, features = ["cli"] }
2323

2424

crates/cdk-ffi/Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ cdk-sqlite = { workspace = true }
2121
cdk-postgres = { workspace = true, optional = true }
2222
cdk-supabase = { workspace = true, optional = true, features = ["wallet"] }
2323
cdk-npubcash = { workspace = true, optional = true }
24+
cdk-nwc = { workspace = true, optional = true }
2425
nostr-sdk = { workspace = true, optional = true }
26+
tokio-util = { workspace = true, optional = true }
2527
futures = { workspace = true }
2628
once_cell = { workspace = true }
2729
rand = { workspace = true }
@@ -43,14 +45,16 @@ log = "0.4"
4345

4446

4547
[features]
46-
default = ["npubcash", "bip353"]
48+
default = ["npubcash", "nwc", "bip353"]
4749
bip353 = ["cdk/bip353"]
4850
# Enable Postgres-backed wallet database support in FFI
4951
postgres = ["cdk-postgres"]
5052
# Enable Supabase-backed wallet database support in FFI
5153
supabase = ["cdk-supabase"]
5254
# Enable NpubCash client bindings
5355
npubcash = ["cdk/npubcash", "cdk-npubcash", "nostr-sdk"]
56+
# Enable Nostr Wallet Connect (NIP-47) wallet service bindings
57+
nwc = ["cdk/nwc", "cdk-nwc", "nostr-sdk", "dep:tokio-util"]
5458

5559
[dev-dependencies]
5660

crates/cdk-ffi/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ pub mod error;
1212
pub mod logging;
1313
#[cfg(feature = "npubcash")]
1414
pub mod npubcash;
15+
#[cfg(feature = "nwc")]
16+
pub mod nwc;
1517
#[cfg(feature = "postgres")]
1618
pub mod postgres;
1719
mod runtime;
@@ -29,6 +31,8 @@ pub use error::*;
2931
pub use logging::*;
3032
#[cfg(feature = "npubcash")]
3133
pub use npubcash::*;
34+
#[cfg(feature = "nwc")]
35+
pub use nwc::*;
3236
pub use types::*;
3337
pub use wallet::*;
3438
pub use wallet_repository::*;

0 commit comments

Comments
 (0)