diff --git a/CHANGELOG.md b/CHANGELOG.md index d5dbb603d..b80330ce3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -88,7 +88,7 @@ * connect: add `NostrConnect::non_secure_set_user_public_key` ([Yuki Kishimoto]) * ffi: add `make_private_msg` func ([Yuki Kishimoto]) * ffi: add `CustomNostrSigner` trait ([Yuki Kishimoto]) -* book: add some examples ([RydalWater]) +* book: add some examples ([RydalWater] and [Yuki Kishimoto]) ### Fixed diff --git a/bindings/nostr-sdk-ffi/python/examples/nwc.py b/bindings/nostr-sdk-ffi/python/examples/nwc.py deleted file mode 100644 index 9816d0990..000000000 --- a/bindings/nostr-sdk-ffi/python/examples/nwc.py +++ /dev/null @@ -1,24 +0,0 @@ -import asyncio - -from nostr_sdk import init_logger, LogLevel, NostrWalletConnectUri, Nwc - - -async def main(): - # Init logger - init_logger(LogLevel.INFO) - - # Parse NWC uri - uri = NostrWalletConnectUri.parse("nostr+walletconnect://..") - - # Initialize NWC client - nwc = Nwc(uri) - - info = await nwc.get_info() - print(info) - - balance = await nwc.get_balance() - print(f"Balance: {balance} SAT") - - -if __name__ == '__main__': - asyncio.run(main()) diff --git a/bindings/nostr-sdk-js/examples/nwc.js b/bindings/nostr-sdk-js/examples/nwc.js deleted file mode 100644 index 318f28bfc..000000000 --- a/bindings/nostr-sdk-js/examples/nwc.js +++ /dev/null @@ -1,26 +0,0 @@ -const { NWC, NostrWalletConnectURI, loadWasmAsync, initLogger, LogLevel } = require("../"); - -async function main() { - await loadWasmAsync(); - - initLogger(LogLevel.info()); - - // Parse NWC uri - let uri = NostrWalletConnectURI.parse("nostr+walletconnect://.."); - - // Initialize NWC client - let nwc = new NWC(uri); - - // Get info - let info = await nwc.getInfo(); - console.log("Supported methods: ", info.methods); - - // Get balance - let balance = await nwc.getBalance(); - console.log("Balance: " + balance + " SAT"); - - // Drop client - nwc.free(); -} - -main(); \ No newline at end of file diff --git a/book/snippets/js/src/nip47.ts b/book/snippets/js/src/nip47.ts new file mode 100644 index 000000000..014b110f4 --- /dev/null +++ b/book/snippets/js/src/nip47.ts @@ -0,0 +1,31 @@ +// ANCHOR: full +import { NWC, NostrWalletConnectURI, MakeInvoiceRequestParams } from "@rust-nostr/nostr-sdk"; + +export async function main() { + // Parse NWC uri + let uri = NostrWalletConnectURI.parse("nostr+walletconnect://.."); + + // Initialize NWC client + let nwc = new NWC(uri); + + // Get info + let info = await nwc.getInfo(); + console.log("Supported methods: ", info.methods); + + // Get balance + let balance = await nwc.getBalance(); + console.log("Balance: " + balance + " SAT"); + + // Pay an invoice + await nwc.payInvoice("lnbc..") + + // Make an invoice + let params = new MakeInvoiceRequestParams(); + params.amount = BigInt(100); + const result = await nwc.makeInvoice(params) + console.log("Invoice: " + result.invoice); + + // Drop client + nwc.free(); +} +// ANCHOR_END: full diff --git a/book/snippets/python/src/nip47.py b/book/snippets/python/src/nip47.py new file mode 100644 index 000000000..66a683314 --- /dev/null +++ b/book/snippets/python/src/nip47.py @@ -0,0 +1,28 @@ +# ANCHOR: full +from nostr_sdk import NostrWalletConnectUri, Nwc, MakeInvoiceRequestParams + + +async def main(): + # Parse NWC uri + uri = NostrWalletConnectUri.parse("nostr+walletconnect://..") + + # Initialize NWC client + nwc = Nwc(uri) + + # Get info + info = await nwc.get_info() + print(info) + + # Get balance + balance = await nwc.get_balance() + print(f"Balance: {balance} SAT") + + # Pay an invoice + await nwc.pay_invoice("lnbc..") + + # Make an invoice + params = MakeInvoiceRequestParams(amount=100, description=None, description_hash=None, expiry=None) + result = await nwc.make_invoice(params) + print(f"Invoice: {result.invoice}") + +# ANCHOR_END: full diff --git a/book/src/SUMMARY.md b/book/src/SUMMARY.md index 79ff029cc..66531a737 100644 --- a/book/src/SUMMARY.md +++ b/book/src/SUMMARY.md @@ -35,6 +35,7 @@ * [NIP-19: bech32-encoded entities](sdk/nips/19.md) * [NIP-21: nostr URI scheme](sdk/nips/21.md) * [NIP-44: Encrypted Payloads](sdk/nips/44.md) + * [NIP-47: Nostr Wallet Connect](sdk/nips/47.md) * [NIP-59: Gift Wrap](sdk/nips/59.md) * [NIP-65: Relay List Metadata](sdk/nips/65.md) diff --git a/book/src/sdk/nips/47.md b/book/src/sdk/nips/47.md new file mode 100644 index 000000000..9c89180d2 --- /dev/null +++ b/book/src/sdk/nips/47.md @@ -0,0 +1,52 @@ +## NIP-47: Nostr Wallet Connect + +### Full example + + + +
Rust
+
+ +TODO + +
+ +
Python
+
+ +```python,ignore +{{#include ../../../snippets/python/src/nip47.py:full}} +``` + +
+ +
JavaScript
+
+ +```typescript,ignore +{{#include ../../../snippets/js/src/nip47.ts:full}} +``` + +
+ +
Kotlin
+
+ +TODO + +
+ +
Swift
+
+ +TODO + +
+ +
Flutter
+
+ +TODO + +
+
diff --git a/book/src/sdk/nwc.md b/book/src/sdk/nwc.md deleted file mode 100644 index d45fcb17e..000000000 --- a/book/src/sdk/nwc.md +++ /dev/null @@ -1 +0,0 @@ -## Nostr Wallet Connect