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