thunder-bridge 1.4.2 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/nwc.d.cts ADDED
@@ -0,0 +1,122 @@
1
+ import { A as Amount, T as Ticker } from './types-DYZ9EkmJ.cjs';
2
+ import { R as RailConfig, O as Order, T as ThunderBridge, f as Rail } from './bank-CEIuNhV_.cjs';
3
+ import './qr-CF-YeXU1.cjs';
4
+
5
+ /** A wallet reachable over NIP-47, as its `nostr+walletconnect://` URI describes it */
6
+ interface NwcConnection {
7
+ /** The wallet service's public key, which is what its answers have to be signed by */
8
+ walletPubkey: string;
9
+ /** Where to reach it, tried in order until one answers */
10
+ relays: string[];
11
+ /** Our own private key on this connection, and the only thing that authorises it */
12
+ secret: string;
13
+ }
14
+ /** A minted invoice and everything needed to watch it */
15
+ interface NwcInvoice {
16
+ bolt11: string;
17
+ paymentHash: string;
18
+ expiresAt: number;
19
+ }
20
+ /** The endpoint the gateway polls for an NWC payment, answering off your own wallet */
21
+ interface NwcVerifyConfig {
22
+ /** The wallet this endpoint speaks for. It never leaves this process */
23
+ connection: NwcConnection;
24
+ /** The secret the payment hash was sealed with, and nothing else uses it */
25
+ secret: string;
26
+ /** How often the gateway should ask, in seconds, sent as `Cache-Control: max-age`, `5` by default */
27
+ pollEverySecs?: number;
28
+ /** How long one `lookup_invoice` may take before the wallet counts as unreachable, `10_000` by default */
29
+ askTimeoutMs?: number;
30
+ }
31
+ /**
32
+ * Read a `nostr+walletconnect://` URI. Refuses a relay that is not `wss`, for the
33
+ * reason the gateway refuses a verify URL that is not https
34
+ */
35
+ declare function nwcConnection(uri: string): NwcConnection;
36
+ /** Mint an invoice on the connected wallet, decoded so the caller need not trust its word */
37
+ declare function nwcInvoice(connection: NwcConnection, amountMsat: number, description: string, timeoutMs?: number): Promise<NwcInvoice>;
38
+ /**
39
+ * Mint a hold invoice on a hash the wallet does not hold the preimage for, which
40
+ * is what lets an operator be paid only by paying somebody else first. The hash
41
+ * has to come from the recipient's own invoice, and the invoice that comes back
42
+ * is decoded rather than believed
43
+ */
44
+ declare function nwcHoldInvoice(connection: NwcConnection, held: {
45
+ paymentHash: string;
46
+ amountMsat: number;
47
+ description: string;
48
+ expirySecs: number;
49
+ minCltvExpiryDelta?: number;
50
+ }, timeoutMs?: number): Promise<NwcInvoice>;
51
+ /**
52
+ * The preimage the wallet released for this hash, null while it has released
53
+ * none. A preimage that does not hash to what was asked for is a lie rather than
54
+ * an answer, so it throws instead of being passed on
55
+ */
56
+ declare function nwcSettlement(connection: NwcConnection, paymentHash: string, timeoutMs?: number): Promise<string | null>;
57
+ /**
58
+ * Pay an invoice and keep the preimage the network handed back. Whoever pays
59
+ * learns it, which is what makes delivery provable to a recipient publishing no
60
+ * LUD-21 of their own. A preimage that does not hash to the invoice's own hash is
61
+ * a lie rather than a receipt, so it throws instead of being passed on
62
+ */
63
+ declare function nwcPay(connection: NwcConnection, bolt11: string, timeoutMs?: number): Promise<string>;
64
+ /**
65
+ * A verify endpoint of your own that asks your wallet over NIP-47, so the gateway
66
+ * polls you and never learns the connection, the relay, or which wallet it is.
67
+ *
68
+ * `nwcVerifyUrl` seals the payment hash into the query with your secret, which is
69
+ * what stops a stranger driving your wallet through this handler. It answers the
70
+ * LUD-21 shape the gateway already speaks, so nothing on that side changes.
71
+ *
72
+ * A wallet it cannot reach answers `502` rather than "not settled", because those
73
+ * are different claims and only one of them is true.
74
+ */
75
+ declare function nwcVerifyEndpoint(config: NwcVerifyConfig): (request: Request) => Promise<Response>;
76
+ /**
77
+ * The URL to hand the gateway, with the payment hash sealed inside it. Point it at
78
+ * wherever `nwcVerifyEndpoint` is mounted
79
+ */
80
+ declare function nwcVerifyUrl(endpoint: string, paymentHash: string, secret: string): Promise<string>;
81
+ /**
82
+ * One NIP-47 call, for a method this SDK does not wrap. The wallet's own info
83
+ * event lists what it will answer, and anything it refuses comes back as a
84
+ * `WalletRefused` whose `reason` says which kind of refusal it was
85
+ */
86
+ declare function askWallet(connection: NwcConnection, method: string, params: Record<string, unknown>, timeoutMs?: number): Promise<Record<string, unknown>>;
87
+ /** A Lightning rail minting on a wallet of your own over NIP-47, bound once per shop */
88
+ interface NwcRailConfig extends RailConfig {
89
+ /** The wallet that mints, which never leaves this process */
90
+ connection: NwcConnection;
91
+ /**
92
+ * What to charge for one order, the order's own price converted at `rate` by
93
+ * default. Give it a function and the price is whatever you say
94
+ */
95
+ amount?: (order: Order) => Amount;
96
+ /** Where the default conversion gets its rate, the median of four venues by default */
97
+ rate?: Ticker;
98
+ /** Where `nwcVerifyEndpoint` is mounted, and the secret the hash is sealed with */
99
+ verifyThrough: {
100
+ endpoint: string;
101
+ secret: string;
102
+ };
103
+ /** What the payer's wallet shows, the order's reference by default */
104
+ description?: (order: Order) => string;
105
+ /** Sealed before the gateway sees it, the way the blind Lightning rail does */
106
+ sealed?: {
107
+ secret: string;
108
+ data: (order: Order) => unknown;
109
+ };
110
+ }
111
+ /**
112
+ * Sell for Lightning against a wallet of your own over NIP-47, for a wallet that
113
+ * has no LUD-21 address to be watched at. Your node mints the invoice and releases
114
+ * the preimage, so the proof comes from one hop nearer than any hosted address can
115
+ * manage, and the gateway sees a hash and a URL of yours.
116
+ *
117
+ * This rail lives here rather than on `gateway.rails` because NIP-47 needs the
118
+ * nostr crypto in this module, and a browser showing a QR should not download it
119
+ */
120
+ declare function nwcRail(gateway: ThunderBridge, config: NwcRailConfig): Rail;
121
+
122
+ export { type NwcConnection, type NwcInvoice, type NwcRailConfig, type NwcVerifyConfig, askWallet, nwcConnection, nwcHoldInvoice, nwcInvoice, nwcPay, nwcRail, nwcSettlement, nwcVerifyEndpoint, nwcVerifyUrl };
package/dist/nwc.d.ts ADDED
@@ -0,0 +1,122 @@
1
+ import { A as Amount, T as Ticker } from './types-DYZ9EkmJ.js';
2
+ import { R as RailConfig, O as Order, T as ThunderBridge, f as Rail } from './bank-M8flcMks.js';
3
+ import './qr-CF-YeXU1.js';
4
+
5
+ /** A wallet reachable over NIP-47, as its `nostr+walletconnect://` URI describes it */
6
+ interface NwcConnection {
7
+ /** The wallet service's public key, which is what its answers have to be signed by */
8
+ walletPubkey: string;
9
+ /** Where to reach it, tried in order until one answers */
10
+ relays: string[];
11
+ /** Our own private key on this connection, and the only thing that authorises it */
12
+ secret: string;
13
+ }
14
+ /** A minted invoice and everything needed to watch it */
15
+ interface NwcInvoice {
16
+ bolt11: string;
17
+ paymentHash: string;
18
+ expiresAt: number;
19
+ }
20
+ /** The endpoint the gateway polls for an NWC payment, answering off your own wallet */
21
+ interface NwcVerifyConfig {
22
+ /** The wallet this endpoint speaks for. It never leaves this process */
23
+ connection: NwcConnection;
24
+ /** The secret the payment hash was sealed with, and nothing else uses it */
25
+ secret: string;
26
+ /** How often the gateway should ask, in seconds, sent as `Cache-Control: max-age`, `5` by default */
27
+ pollEverySecs?: number;
28
+ /** How long one `lookup_invoice` may take before the wallet counts as unreachable, `10_000` by default */
29
+ askTimeoutMs?: number;
30
+ }
31
+ /**
32
+ * Read a `nostr+walletconnect://` URI. Refuses a relay that is not `wss`, for the
33
+ * reason the gateway refuses a verify URL that is not https
34
+ */
35
+ declare function nwcConnection(uri: string): NwcConnection;
36
+ /** Mint an invoice on the connected wallet, decoded so the caller need not trust its word */
37
+ declare function nwcInvoice(connection: NwcConnection, amountMsat: number, description: string, timeoutMs?: number): Promise<NwcInvoice>;
38
+ /**
39
+ * Mint a hold invoice on a hash the wallet does not hold the preimage for, which
40
+ * is what lets an operator be paid only by paying somebody else first. The hash
41
+ * has to come from the recipient's own invoice, and the invoice that comes back
42
+ * is decoded rather than believed
43
+ */
44
+ declare function nwcHoldInvoice(connection: NwcConnection, held: {
45
+ paymentHash: string;
46
+ amountMsat: number;
47
+ description: string;
48
+ expirySecs: number;
49
+ minCltvExpiryDelta?: number;
50
+ }, timeoutMs?: number): Promise<NwcInvoice>;
51
+ /**
52
+ * The preimage the wallet released for this hash, null while it has released
53
+ * none. A preimage that does not hash to what was asked for is a lie rather than
54
+ * an answer, so it throws instead of being passed on
55
+ */
56
+ declare function nwcSettlement(connection: NwcConnection, paymentHash: string, timeoutMs?: number): Promise<string | null>;
57
+ /**
58
+ * Pay an invoice and keep the preimage the network handed back. Whoever pays
59
+ * learns it, which is what makes delivery provable to a recipient publishing no
60
+ * LUD-21 of their own. A preimage that does not hash to the invoice's own hash is
61
+ * a lie rather than a receipt, so it throws instead of being passed on
62
+ */
63
+ declare function nwcPay(connection: NwcConnection, bolt11: string, timeoutMs?: number): Promise<string>;
64
+ /**
65
+ * A verify endpoint of your own that asks your wallet over NIP-47, so the gateway
66
+ * polls you and never learns the connection, the relay, or which wallet it is.
67
+ *
68
+ * `nwcVerifyUrl` seals the payment hash into the query with your secret, which is
69
+ * what stops a stranger driving your wallet through this handler. It answers the
70
+ * LUD-21 shape the gateway already speaks, so nothing on that side changes.
71
+ *
72
+ * A wallet it cannot reach answers `502` rather than "not settled", because those
73
+ * are different claims and only one of them is true.
74
+ */
75
+ declare function nwcVerifyEndpoint(config: NwcVerifyConfig): (request: Request) => Promise<Response>;
76
+ /**
77
+ * The URL to hand the gateway, with the payment hash sealed inside it. Point it at
78
+ * wherever `nwcVerifyEndpoint` is mounted
79
+ */
80
+ declare function nwcVerifyUrl(endpoint: string, paymentHash: string, secret: string): Promise<string>;
81
+ /**
82
+ * One NIP-47 call, for a method this SDK does not wrap. The wallet's own info
83
+ * event lists what it will answer, and anything it refuses comes back as a
84
+ * `WalletRefused` whose `reason` says which kind of refusal it was
85
+ */
86
+ declare function askWallet(connection: NwcConnection, method: string, params: Record<string, unknown>, timeoutMs?: number): Promise<Record<string, unknown>>;
87
+ /** A Lightning rail minting on a wallet of your own over NIP-47, bound once per shop */
88
+ interface NwcRailConfig extends RailConfig {
89
+ /** The wallet that mints, which never leaves this process */
90
+ connection: NwcConnection;
91
+ /**
92
+ * What to charge for one order, the order's own price converted at `rate` by
93
+ * default. Give it a function and the price is whatever you say
94
+ */
95
+ amount?: (order: Order) => Amount;
96
+ /** Where the default conversion gets its rate, the median of four venues by default */
97
+ rate?: Ticker;
98
+ /** Where `nwcVerifyEndpoint` is mounted, and the secret the hash is sealed with */
99
+ verifyThrough: {
100
+ endpoint: string;
101
+ secret: string;
102
+ };
103
+ /** What the payer's wallet shows, the order's reference by default */
104
+ description?: (order: Order) => string;
105
+ /** Sealed before the gateway sees it, the way the blind Lightning rail does */
106
+ sealed?: {
107
+ secret: string;
108
+ data: (order: Order) => unknown;
109
+ };
110
+ }
111
+ /**
112
+ * Sell for Lightning against a wallet of your own over NIP-47, for a wallet that
113
+ * has no LUD-21 address to be watched at. Your node mints the invoice and releases
114
+ * the preimage, so the proof comes from one hop nearer than any hosted address can
115
+ * manage, and the gateway sees a hash and a URL of yours.
116
+ *
117
+ * This rail lives here rather than on `gateway.rails` because NIP-47 needs the
118
+ * nostr crypto in this module, and a browser showing a QR should not download it
119
+ */
120
+ declare function nwcRail(gateway: ThunderBridge, config: NwcRailConfig): Rail;
121
+
122
+ export { type NwcConnection, type NwcInvoice, type NwcRailConfig, type NwcVerifyConfig, askWallet, nwcConnection, nwcHoldInvoice, nwcInvoice, nwcPay, nwcRail, nwcSettlement, nwcVerifyEndpoint, nwcVerifyUrl };