thunder-bridge 1.4.1 → 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 +356 -536
- 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/rail-CqUfuYXJ.d.cts
DELETED
|
@@ -1,615 +0,0 @@
|
|
|
1
|
-
type Resolved = {
|
|
2
|
-
address: string;
|
|
3
|
-
bolt11: string;
|
|
4
|
-
verifyUrl: string;
|
|
5
|
-
paymentHash: string;
|
|
6
|
-
expiresAt: number;
|
|
7
|
-
};
|
|
8
|
-
/**
|
|
9
|
-
* Bech32-encode a pay endpoint as the `LNURL1` string LUD-01 defines, uppercase
|
|
10
|
-
* because that is the form it asks a QR to carry. An onion endpoint is http
|
|
11
|
-
* rather than https, which LUD-17 spells out, so both are taken here
|
|
12
|
-
*/
|
|
13
|
-
declare function toLnurl(endpoint: string): string;
|
|
14
|
-
|
|
15
|
-
/** Where a payment stands, `paid` is the only status that carries a preimage */
|
|
16
|
-
type PaymentStatus = "pending" | "paid" | "expired";
|
|
17
|
-
/** Whether the gateway resolved the address and got the invoice, or was handed one to watch */
|
|
18
|
-
type PaymentKind = "minted" | "watched";
|
|
19
|
-
/** A payment as the gateway reports it, every field is checkable against the recipient */
|
|
20
|
-
interface Payment {
|
|
21
|
-
id: string;
|
|
22
|
-
lnAddress: string;
|
|
23
|
-
amountMsat: number;
|
|
24
|
-
status: PaymentStatus;
|
|
25
|
-
paymentHash: string;
|
|
26
|
-
bolt11: string;
|
|
27
|
-
preimage: string | null;
|
|
28
|
-
expiresAt: number;
|
|
29
|
-
createdAt: number;
|
|
30
|
-
verifyUrl: string;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* `lnAddresses` is a priority list, the gateway takes the first one that can
|
|
34
|
-
* issue a provable invoice for `amountMsat` and the rest are the fallback
|
|
35
|
-
*/
|
|
36
|
-
interface CreatePaymentParams {
|
|
37
|
-
lnAddresses: string[];
|
|
38
|
-
amountMsat: number;
|
|
39
|
-
webhookUrl?: string;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* `lnAddresses` is the same priority list `createPayment` takes, and quoting it
|
|
43
|
-
* mints nothing and charges the recipient's wallet nothing
|
|
44
|
-
*/
|
|
45
|
-
interface CreateQuoteParams {
|
|
46
|
-
lnAddresses: string[];
|
|
47
|
-
amountMsat: number;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Which address would serve an amount, and what the ones ahead of it refused.
|
|
51
|
-
* `feeMsat` is always zero, the payer pays the recipient's own invoice and the
|
|
52
|
-
* gateway is never in the money's path
|
|
53
|
-
*/
|
|
54
|
-
interface Quote {
|
|
55
|
-
lnAddress: string;
|
|
56
|
-
amountMsat: number;
|
|
57
|
-
feeMsat: number;
|
|
58
|
-
minMsat: number;
|
|
59
|
-
maxMsat: number;
|
|
60
|
-
metadata: string;
|
|
61
|
-
refusals: WalletFailure[];
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* What the gateway reports about a payment it is watching, for a trigger stream
|
|
65
|
-
* or for one you minted yourself. `lnAddress` and `amountMsat` are null when the
|
|
66
|
-
* gateway was never told them, which is the point of `watchPayment`: what the
|
|
67
|
-
* watcher needs but the gateway should not know travels in `sealed` instead
|
|
68
|
-
*/
|
|
69
|
-
interface TriggerEvent {
|
|
70
|
-
id: string;
|
|
71
|
-
kind: PaymentKind;
|
|
72
|
-
paymentHash: string;
|
|
73
|
-
verifyUrl: string;
|
|
74
|
-
status: PaymentStatus;
|
|
75
|
-
preimage: string | null;
|
|
76
|
-
expiresAt: number;
|
|
77
|
-
createdAt: number;
|
|
78
|
-
sealed: string | null;
|
|
79
|
-
lnAddress: string | null;
|
|
80
|
-
amountMsat: number | null;
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* An invoice you obtained yourself, handed over to be watched. The gateway is
|
|
84
|
-
* given no address and no amount, so it cannot refuse one recipient rather than
|
|
85
|
-
* all of them
|
|
86
|
-
*/
|
|
87
|
-
interface WatchPaymentParams {
|
|
88
|
-
paymentHash: string;
|
|
89
|
-
verifyUrl: string;
|
|
90
|
-
expiresAt: number;
|
|
91
|
-
trigger?: string;
|
|
92
|
-
/**
|
|
93
|
-
* How many of this trigger's settlements the gateway keeps replayable past the
|
|
94
|
-
* hour it would otherwise forget them in, up to the ceiling its operator set.
|
|
95
|
-
* Needs `trigger`, defaults to none
|
|
96
|
-
*/
|
|
97
|
-
replay?: number;
|
|
98
|
-
sealed?: string;
|
|
99
|
-
webhookUrl?: string;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* A one minute pass onto one trigger's stream. It opens that trigger and nothing
|
|
103
|
-
* else, which is what makes it the thing to hand a browser when the trigger
|
|
104
|
-
* secret is not. `expiresAt` is unix seconds, like every other time here
|
|
105
|
-
*/
|
|
106
|
-
interface SocketTicket {
|
|
107
|
-
ticket: string;
|
|
108
|
-
expiresAt: number;
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Which trigger the ticket opens, and how many of its settlements the socket
|
|
112
|
-
* replays on connect, up to the ceiling the gateway's operator set
|
|
113
|
-
*/
|
|
114
|
-
interface SocketTicketParams {
|
|
115
|
-
trigger: string;
|
|
116
|
-
replay?: number;
|
|
117
|
-
}
|
|
118
|
-
/** Why one wallet in the list could not be used */
|
|
119
|
-
type WalletReason = "address-unusable" | "unreachable" | "amount-not-accepted" | "cannot-prove-delivery" | "invoice-refused";
|
|
120
|
-
interface WalletFailure {
|
|
121
|
-
address: string;
|
|
122
|
-
reason: WalletReason;
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* What a delivery carries. Everything needed to act on a settlement and to check
|
|
126
|
-
* it, and nothing else, so a retry is the same size every time
|
|
127
|
-
*/
|
|
128
|
-
interface Settlement {
|
|
129
|
-
id: string;
|
|
130
|
-
status: PaymentStatus;
|
|
131
|
-
paymentHash: string;
|
|
132
|
-
preimage: string | null;
|
|
133
|
-
settledAt: number;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
interface ThunderBridgeOptions {
|
|
137
|
-
/**
|
|
138
|
-
* Prove every payment against the recipient's own server before handing it
|
|
139
|
-
* back, and refuse a reported settlement whose preimage does not hash to the
|
|
140
|
-
* payment hash, defaults to true
|
|
141
|
-
*/
|
|
142
|
-
verify?: boolean;
|
|
143
|
-
/**
|
|
144
|
-
* Sent as `Authorization: Bearer`, which a gateway started with
|
|
145
|
-
* `GATEWAY_TOKEN` requires on every call, the socket handshake included. No
|
|
146
|
-
* browser WebSocket can carry a header, so setting this also puts every socket
|
|
147
|
-
* through a ticket
|
|
148
|
-
*/
|
|
149
|
-
token?: string;
|
|
150
|
-
/**
|
|
151
|
-
* The same long lived server side secret your rail derives its preimages from.
|
|
152
|
-
* Given here, every call carries a signature the gateway reads as your identity,
|
|
153
|
-
* so a payment you create is handed back to you and to nobody else. Withheld,
|
|
154
|
-
* you are anonymous and any holder of an id can read what it names
|
|
155
|
-
*/
|
|
156
|
-
secret?: string;
|
|
157
|
-
}
|
|
158
|
-
interface WaitOptions {
|
|
159
|
-
/** Give up when this aborts, `AbortSignal.timeout(ms)` covers the usual case */
|
|
160
|
-
signal?: AbortSignal;
|
|
161
|
-
/**
|
|
162
|
-
* Mint a short-lived ticket and put that in the socket URL instead of the
|
|
163
|
-
* payment id. Implied by `token`. The id stays readable inside the ticket,
|
|
164
|
-
* what changes is that a URL out of a log stops opening anything after a
|
|
165
|
-
* minute
|
|
166
|
-
*/
|
|
167
|
-
tickets?: boolean;
|
|
168
|
-
}
|
|
169
|
-
interface CreateOptions {
|
|
170
|
-
/**
|
|
171
|
-
* Makes the POST safe to retry. A repeat of a finished request replays its
|
|
172
|
-
* payment instead of asking a wallet for a second invoice, a repeat that
|
|
173
|
-
* arrives while the first is still resolving throws
|
|
174
|
-
* `IdempotencyConflictError`, and the key is held for 24 hours
|
|
175
|
-
*/
|
|
176
|
-
idempotencyKey?: string;
|
|
177
|
-
/**
|
|
178
|
-
* Groups this payment with every other one carrying the same secret, so
|
|
179
|
-
* `followTrigger` can watch the place rather than the payment. Registering
|
|
180
|
-
* sends only its sha256, which is also all the gateway stores, so a stolen
|
|
181
|
-
* ledger cannot subscribe. Following sends the secret itself, because the
|
|
182
|
-
* gateway hashes what it is given to find the stream, so the operator of a
|
|
183
|
-
* gateway you do not own learns it the first time you connect. Keep it apart
|
|
184
|
-
* from any URL a payer sees
|
|
185
|
-
*/
|
|
186
|
-
trigger?: string;
|
|
187
|
-
/**
|
|
188
|
-
* How many of the trigger's settlements the gateway keeps replayable past the
|
|
189
|
-
* hour it would otherwise forget them in, up to the ceiling its operator set.
|
|
190
|
-
* Needs `trigger`, defaults to none
|
|
191
|
-
*/
|
|
192
|
-
replay?: number;
|
|
193
|
-
}
|
|
194
|
-
interface FollowOptions {
|
|
195
|
-
/** Called for the recent settlements replayed on connect, then for each new one */
|
|
196
|
-
onPayment: (settled: TriggerEvent) => void;
|
|
197
|
-
/**
|
|
198
|
-
* How many settlements to ask for on connect, defaults to the gateway's ten.
|
|
199
|
-
* It hands back what it still holds, which is the last hour unless the
|
|
200
|
-
* payments were minted with `replay`
|
|
201
|
-
*/
|
|
202
|
-
replay?: number;
|
|
203
|
-
/** Called when a connection drops or a frame is refused, the follow keeps going */
|
|
204
|
-
onError?: (error: unknown) => void;
|
|
205
|
-
/** Reconnect after a drop, defaults to true */
|
|
206
|
-
reconnect?: boolean;
|
|
207
|
-
/**
|
|
208
|
-
* The first wait after a drop, doubling up to 30 seconds and jittered so a
|
|
209
|
-
* fleet does not come back in lockstep, defaults to 3000. A connection that
|
|
210
|
-
* opens puts it back to the first wait
|
|
211
|
-
*/
|
|
212
|
-
reconnectDelayMs?: number;
|
|
213
|
-
/**
|
|
214
|
-
* Mint a short-lived ticket and put that in the socket URL instead of the
|
|
215
|
-
* secret, one per connection. Keeps the secret out of access logs, at the cost
|
|
216
|
-
* of a POST before each connect. Implied by `token`. Leave it off for a
|
|
217
|
-
* microcontroller, where one hardcoded URL and a dumb reconnect loop is the
|
|
218
|
-
* whole point
|
|
219
|
-
*/
|
|
220
|
-
tickets?: boolean;
|
|
221
|
-
}
|
|
222
|
-
/** Talks to a Thunder Bridge gateway and trusts it for nothing it can check itself */
|
|
223
|
-
declare class ThunderBridge {
|
|
224
|
-
private readonly baseUrl;
|
|
225
|
-
private readonly verify;
|
|
226
|
-
private readonly token;
|
|
227
|
-
private readonly secret;
|
|
228
|
-
private strangers;
|
|
229
|
-
private speaks;
|
|
230
|
-
constructor(baseUrl: string, options?: ThunderBridgeOptions);
|
|
231
|
-
/**
|
|
232
|
-
* Whether a token was given, which is what makes an instance yours: a gateway
|
|
233
|
-
* started with `GATEWAY_TOKEN` answers nobody else, so anything you hand it
|
|
234
|
-
* stays between you and it
|
|
235
|
-
*/
|
|
236
|
-
get isPrivate(): boolean;
|
|
237
|
-
/**
|
|
238
|
-
* Whether the gateway turns away a caller carrying no token, asked by making
|
|
239
|
-
* one unauthenticated read it would have to refuse. `isPrivate` answers only
|
|
240
|
-
* whether you configured a token, which is your side of the arrangement and
|
|
241
|
-
* says nothing about the gateway's, so a made-up token against a public
|
|
242
|
-
* instance reads as private and is not. Asked once and remembered, because an
|
|
243
|
-
* instance does not change its mind. Anything other than a refusal counts as
|
|
244
|
-
* open, so an unreachable gateway fails closed
|
|
245
|
-
*/
|
|
246
|
-
refusesStrangers(): Promise<boolean>;
|
|
247
|
-
/**
|
|
248
|
-
* Ask the gateway for an invoice payable to the first address on your list
|
|
249
|
-
* that can issue a provable one, throws `NoWalletAvailableError` when none can
|
|
250
|
-
* and `GatewayCheatError` when what comes back is not what you asked for
|
|
251
|
-
*/
|
|
252
|
-
createPayment(params: CreatePaymentParams, options?: CreateOptions): Promise<Payment>;
|
|
253
|
-
/**
|
|
254
|
-
* Ask which address would serve an amount without minting anything, throws
|
|
255
|
-
* `NoWalletAvailableError` when none would. A quote is a probe and not a
|
|
256
|
-
* promise: the address it names can still be refused at create time, because
|
|
257
|
-
* whether a wallet returns a provable invoice cannot be known without asking
|
|
258
|
-
* it for one, and asking mints it
|
|
259
|
-
*/
|
|
260
|
-
createQuote(params: CreateQuoteParams): Promise<Quote>;
|
|
261
|
-
/** Read a payment back, null when the gateway has never heard of it */
|
|
262
|
-
/**
|
|
263
|
-
* The key this gateway signs webhooks with when you registered none of your own,
|
|
264
|
-
* ready to hand to `parseWebhookRequest` as `{ publicKey }`. Fetch it once and
|
|
265
|
-
* keep it: it is the same for every instance in the cluster
|
|
266
|
-
*/
|
|
267
|
-
webhookKey(): Promise<string>;
|
|
268
|
-
getPayment(id: string): Promise<Payment | null>;
|
|
269
|
-
/**
|
|
270
|
-
* Read back a payment the gateway is only watching, null when it has never
|
|
271
|
-
* heard of it. A watched payment carries no address, amount or invoice, so
|
|
272
|
-
* `getPayment` refuses it and this reads the shape both rails share
|
|
273
|
-
*/
|
|
274
|
-
getWatched(id: string): Promise<TriggerEvent | null>;
|
|
275
|
-
/**
|
|
276
|
-
* List what this gateway is watching, newest first. Only a gateway started
|
|
277
|
-
* with `GATEWAY_TOKEN` serves this, because on a shared one it would hand
|
|
278
|
-
* every caller everyone else's payments, so a public gateway answers 404.
|
|
279
|
-
*
|
|
280
|
-
* `scanned` says how many settled records were looked at to build the page.
|
|
281
|
-
* Anything older than that window is not in the answer, and the list does not
|
|
282
|
-
* pretend otherwise
|
|
283
|
-
*/
|
|
284
|
-
listPayments(limit?: number): Promise<{
|
|
285
|
-
payments: TriggerEvent[];
|
|
286
|
-
scanned: number;
|
|
287
|
-
}>;
|
|
288
|
-
/**
|
|
289
|
-
* Follow a payment over WebSocket until it is paid or expired, reconnecting
|
|
290
|
-
* through a drop. A payment that never answers gives up after a few tries, and
|
|
291
|
-
* one that has answered is followed until its own expiry, so the wait always
|
|
292
|
-
* ends by itself
|
|
293
|
-
*/
|
|
294
|
-
waitForPayment(id: string, options?: WaitOptions): Promise<Payment>;
|
|
295
|
-
/**
|
|
296
|
-
* Follow a payment the gateway is only watching, one it did not mint, until it
|
|
297
|
-
* is paid or expired.
|
|
298
|
-
*
|
|
299
|
-
* A watched payment carries no address, no amount and no invoice, because the
|
|
300
|
-
* gateway was told none of them, so it reads back as the shape a trigger
|
|
301
|
-
* streams rather than as a `Payment`. That is every bank transfer, and every
|
|
302
|
-
* Lightning invoice registered with `watchPayment` instead of `createPayment`.
|
|
303
|
-
*/
|
|
304
|
-
waitForWatched(id: string, options?: WaitOptions): Promise<TriggerEvent>;
|
|
305
|
-
private followed;
|
|
306
|
-
/**
|
|
307
|
-
* Wait on several payments and keep the first one that is really paid, then stop
|
|
308
|
-
* waiting on the losers, which closes their sockets.
|
|
309
|
-
*
|
|
310
|
-
* This is how one order offers two rails. A Lightning invoice and a bank
|
|
311
|
-
* transfer for the same thing are two payments here, and the payer picks one, so
|
|
312
|
-
* what you want is the one that arrives and nothing further from the other.
|
|
313
|
-
*
|
|
314
|
-
* A leg that expires is a loser, not a winner, which is the whole reason this is
|
|
315
|
-
* not a race: `waitForPayment` ends on `paid` and on `expired` alike, and a
|
|
316
|
-
* Lightning invoice expires in an hour while a bank transfer takes days. `null`
|
|
317
|
-
* means every leg ended without being paid.
|
|
318
|
-
*
|
|
319
|
-
* Stopping the wait is not revoking the invoice. Nobody can revoke one, because
|
|
320
|
-
* the recipient's own wallet minted it, so a payer who pays the loser afterwards
|
|
321
|
-
* really does pay twice and that shows up on `followTrigger` as a second
|
|
322
|
-
* settlement to refund.
|
|
323
|
-
*/
|
|
324
|
-
firstToSettle(ids: string[], options?: WaitOptions): Promise<TriggerEvent | null>;
|
|
325
|
-
/**
|
|
326
|
-
* Hand over an invoice you obtained yourself so the gateway watches it without
|
|
327
|
-
* being told the address or the amount. It can then only refuse everyone
|
|
328
|
-
* rather than one recipient, which is what makes leaving it cheap. Anything
|
|
329
|
-
* the watcher needs goes in `sealed`, which the gateway cannot read
|
|
330
|
-
*/
|
|
331
|
-
watchPayment(params: WatchPaymentParams): Promise<TriggerEvent>;
|
|
332
|
-
/**
|
|
333
|
-
* What this payment is called, which you can work out before any gateway has
|
|
334
|
-
* heard of it. Every gateway you hand the same invoice to answers with the same
|
|
335
|
-
* name, so watching at several of them adds up to one payment rather than
|
|
336
|
-
* several, and no gateway's key is in the answer. Null when no secret was given,
|
|
337
|
-
* because then the gateway names the payment and only it can
|
|
338
|
-
*/
|
|
339
|
-
nameFor(paymentHash: string): Promise<string | null>;
|
|
340
|
-
/**
|
|
341
|
-
* Follow every payment made to one trigger, replayed from the recent ones on
|
|
342
|
-
* connect and then live, reconnecting on its own until the returned function
|
|
343
|
-
* is called. A trigger has no terminal state, so this never resolves
|
|
344
|
-
*/
|
|
345
|
-
followTrigger(secret: string, options: FollowOptions): () => void;
|
|
346
|
-
/**
|
|
347
|
-
* A one minute pass onto one trigger's stream, for something that must hold
|
|
348
|
-
* neither the token nor the trigger secret. Mint it in a handler and answer
|
|
349
|
-
* with the ticket alone, because that is all a browser needs to connect and
|
|
350
|
-
* all it can do anything with. `watchTicketEndpoint` is this method already
|
|
351
|
-
* wrapped in a route
|
|
352
|
-
*/
|
|
353
|
-
createSocketTicket(params: SocketTicketParams): Promise<SocketTicket>;
|
|
354
|
-
private needsTicket;
|
|
355
|
-
private wsTicket;
|
|
356
|
-
private mintedTicket;
|
|
357
|
-
private sending;
|
|
358
|
-
private reading;
|
|
359
|
-
private speaking;
|
|
360
|
-
private proven;
|
|
361
|
-
private checked;
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
/** A wallet reachable over NIP-47, as its `nostr+walletconnect://` URI describes it */
|
|
365
|
-
interface NwcConnection {
|
|
366
|
-
/** The wallet service's public key, which is what its answers have to be signed by */
|
|
367
|
-
walletPubkey: string;
|
|
368
|
-
/** Where to reach it, tried in order until one answers */
|
|
369
|
-
relays: string[];
|
|
370
|
-
/** Our own private key on this connection, and the only thing that authorises it */
|
|
371
|
-
secret: string;
|
|
372
|
-
}
|
|
373
|
-
/** A minted invoice and everything needed to watch it */
|
|
374
|
-
interface NwcInvoice {
|
|
375
|
-
bolt11: string;
|
|
376
|
-
paymentHash: string;
|
|
377
|
-
expiresAt: number;
|
|
378
|
-
}
|
|
379
|
-
interface NwcVerifyConfig {
|
|
380
|
-
/** The wallet this endpoint speaks for. It never leaves this process */
|
|
381
|
-
connection: NwcConnection;
|
|
382
|
-
/** The secret the payment hash was sealed with, and nothing else uses it */
|
|
383
|
-
secret: string;
|
|
384
|
-
/** How often the gateway should ask, in seconds, sent as `Cache-Control: max-age`, `5` by default */
|
|
385
|
-
pollEverySecs?: number;
|
|
386
|
-
/** How long one `lookup_invoice` may take before the wallet counts as unreachable, `10_000` by default */
|
|
387
|
-
askTimeoutMs?: number;
|
|
388
|
-
}
|
|
389
|
-
/**
|
|
390
|
-
* Read a `nostr+walletconnect://` URI. Refuses a relay that is not `wss`, for the
|
|
391
|
-
* reason the gateway refuses a verify URL that is not https
|
|
392
|
-
*/
|
|
393
|
-
declare function nwcConnection(uri: string): NwcConnection;
|
|
394
|
-
/** Mint an invoice on the connected wallet, decoded so the caller need not trust its word */
|
|
395
|
-
declare function nwcInvoice(connection: NwcConnection, amountMsat: number, description: string, timeoutMs?: number): Promise<NwcInvoice>;
|
|
396
|
-
/**
|
|
397
|
-
* Mint a hold invoice on a hash the wallet does not hold the preimage for, which
|
|
398
|
-
* is what lets an operator be paid only by paying somebody else first. The hash
|
|
399
|
-
* has to come from the recipient's own invoice, and the invoice that comes back
|
|
400
|
-
* is decoded rather than believed
|
|
401
|
-
*/
|
|
402
|
-
declare function nwcHoldInvoice(connection: NwcConnection, held: {
|
|
403
|
-
paymentHash: string;
|
|
404
|
-
amountMsat: number;
|
|
405
|
-
description: string;
|
|
406
|
-
expirySecs: number;
|
|
407
|
-
minCltvExpiryDelta?: number;
|
|
408
|
-
}, timeoutMs?: number): Promise<NwcInvoice>;
|
|
409
|
-
/**
|
|
410
|
-
* The preimage the wallet released for this hash, null while it has released
|
|
411
|
-
* none. A preimage that does not hash to what was asked for is a lie rather than
|
|
412
|
-
* an answer, so it throws instead of being passed on
|
|
413
|
-
*/
|
|
414
|
-
declare function nwcSettlement(connection: NwcConnection, paymentHash: string, timeoutMs?: number): Promise<string | null>;
|
|
415
|
-
/**
|
|
416
|
-
* Pay an invoice and keep the preimage the network handed back. Whoever pays
|
|
417
|
-
* learns it, which is what makes delivery provable to a recipient publishing no
|
|
418
|
-
* LUD-21 of their own. A preimage that does not hash to the invoice's own hash is
|
|
419
|
-
* a lie rather than a receipt, so it throws instead of being passed on
|
|
420
|
-
*/
|
|
421
|
-
declare function nwcPay(connection: NwcConnection, bolt11: string, timeoutMs?: number): Promise<string>;
|
|
422
|
-
/**
|
|
423
|
-
* A verify endpoint of your own that asks your wallet over NIP-47, so the gateway
|
|
424
|
-
* polls you and never learns the connection, the relay, or which wallet it is.
|
|
425
|
-
*
|
|
426
|
-
* `nwcVerifyUrl` seals the payment hash into the query with your secret, which is
|
|
427
|
-
* what stops a stranger driving your wallet through this handler. It answers the
|
|
428
|
-
* LUD-21 shape the gateway already speaks, so nothing on that side changes.
|
|
429
|
-
*
|
|
430
|
-
* A wallet it cannot reach answers `502` rather than "not settled", because those
|
|
431
|
-
* are different claims and only one of them is true.
|
|
432
|
-
*/
|
|
433
|
-
declare function nwcVerifyEndpoint(config: NwcVerifyConfig): (request: Request) => Promise<Response>;
|
|
434
|
-
/**
|
|
435
|
-
* The URL to hand the gateway, with the payment hash sealed inside it. Point it at
|
|
436
|
-
* wherever `nwcVerifyEndpoint` is mounted
|
|
437
|
-
*/
|
|
438
|
-
declare function nwcVerifyUrl(endpoint: string, paymentHash: string, secret: string): Promise<string>;
|
|
439
|
-
/**
|
|
440
|
-
* One NIP-47 call, for a method this SDK does not wrap. The wallet's own info
|
|
441
|
-
* event lists what it will answer, and anything it refuses comes back as a
|
|
442
|
-
* `WalletRefused` carrying the code it named
|
|
443
|
-
*/
|
|
444
|
-
declare function askWallet(connection: NwcConnection, method: string, params: Record<string, unknown>, timeoutMs?: number): Promise<Record<string, unknown>>;
|
|
445
|
-
|
|
446
|
-
/** What a shop knows about a sale before any rail exists */
|
|
447
|
-
interface Order {
|
|
448
|
-
/** The bank matches it on the statement, and Lightning keys idempotency on it */
|
|
449
|
-
reference: string;
|
|
450
|
-
/** The price in the smallest unit of `currency`, so 48055 is 480.55 CZK */
|
|
451
|
-
amountMinor: number;
|
|
452
|
-
/** ISO 4217. The bank rail moves this, Lightning reads it only through your own `amountMsat` */
|
|
453
|
-
currency: string;
|
|
454
|
-
}
|
|
455
|
-
/** One way to pay one order, already registered with the gateway */
|
|
456
|
-
interface Leg {
|
|
457
|
-
/** The watched payment's id, which is what `firstToSettle`, `getWatched` and `waitForWatched` take */
|
|
458
|
-
id: string;
|
|
459
|
-
/** Which rail made it, so a shop can label a leg without knowing how it was built */
|
|
460
|
-
rail: string;
|
|
461
|
-
/** What the payer reads, a BOLT11 invoice or a Short Payment Descriptor */
|
|
462
|
-
scan: string;
|
|
463
|
-
/** The same thing as a QR has to encode it, which is not always `scan` itself */
|
|
464
|
-
qr: string;
|
|
465
|
-
expiresAt: number;
|
|
466
|
-
}
|
|
467
|
-
/**
|
|
468
|
-
* A payment method. Everything that differs between rails is bound once when the
|
|
469
|
-
* rail is built, so the only thing passed per sale is which sale it is
|
|
470
|
-
*/
|
|
471
|
-
type Rail = (order: Order) => Promise<Leg>;
|
|
472
|
-
interface BankRailConfig {
|
|
473
|
-
/** The gateway that will watch these transfers. It has to be one of your own */
|
|
474
|
-
gateway: ThunderBridge;
|
|
475
|
-
/** Long lived and server side. Every preimage is derived from it, so losing it loses every proof */
|
|
476
|
-
secret: string;
|
|
477
|
-
/** The account the money goes to, as an IBAN */
|
|
478
|
-
iban: string;
|
|
479
|
-
/** Where `bankVerifyEndpoint` is mounted, a public https URL with no query of its own */
|
|
480
|
-
verifyUrl: string;
|
|
481
|
-
/**
|
|
482
|
-
* When this order stops being payable, in unix seconds. Re-offering one order
|
|
483
|
-
* has to return the same second every time, because the gateway compares the
|
|
484
|
-
* expiry to decide whether a repeated watch is the same watch
|
|
485
|
-
*/
|
|
486
|
-
expiresAt: (order: Order) => number;
|
|
487
|
-
/** Groups every leg on the same secret, so one `followTrigger` socket hears them all */
|
|
488
|
-
trigger?: string;
|
|
489
|
-
/** How many settlements of that trigger the gateway keeps replayable past the hour, needs `trigger` */
|
|
490
|
-
replay?: number;
|
|
491
|
-
/** Handed back untouched on that stream. Stable across re-offers, for the reason `expiresAt` is */
|
|
492
|
-
sealed?: (order: Order) => string | Promise<string>;
|
|
493
|
-
/** Up to ten digits, for accounting systems that still want one */
|
|
494
|
-
variableSymbol?: (order: Order) => string | undefined;
|
|
495
|
-
webhookUrl?: string;
|
|
496
|
-
/** Register on a gateway you do not own anyway, on the terms `bankTransfer` sets out */
|
|
497
|
-
allowPublicGateway?: boolean;
|
|
498
|
-
/** What `Leg.rail` reads, for a shop running more than one account */
|
|
499
|
-
name?: string;
|
|
500
|
-
}
|
|
501
|
-
interface LightningRailConfig {
|
|
502
|
-
/** The gateway that mints the invoice */
|
|
503
|
-
gateway: ThunderBridge;
|
|
504
|
-
/** Priority list, the gateway takes the first that can issue a provable invoice */
|
|
505
|
-
lnAddresses: string[];
|
|
506
|
-
/** What this order costs in millisatoshi. A shop pricing in fiat writes `msatFor` and its own ticker */
|
|
507
|
-
amountMsat: (order: Order) => number | Promise<number>;
|
|
508
|
-
/** Groups every leg on the same secret, so one `followTrigger` socket hears them all */
|
|
509
|
-
trigger?: string;
|
|
510
|
-
/** How many settlements of that trigger the gateway keeps replayable past the hour, needs `trigger` */
|
|
511
|
-
replay?: number;
|
|
512
|
-
/**
|
|
513
|
-
* Makes the mint safe to retry. Unset nothing is sent, because a key stable
|
|
514
|
-
* across re-offers is one the gateway can join against the bank leg's reference
|
|
515
|
-
*/
|
|
516
|
-
idempotencyKey?: (order: Order) => string | undefined;
|
|
517
|
-
webhookUrl?: string;
|
|
518
|
-
/** What `Leg.rail` reads, for a shop running more than one wallet */
|
|
519
|
-
name?: string;
|
|
520
|
-
}
|
|
521
|
-
interface BlindLightningRailConfig {
|
|
522
|
-
/** The gateway that watches an invoice it was never allowed to mint */
|
|
523
|
-
gateway: ThunderBridge;
|
|
524
|
-
/** Priority list, resolved here rather than by the gateway */
|
|
525
|
-
lnAddresses: string[];
|
|
526
|
-
/** What this order costs in millisatoshi */
|
|
527
|
-
amountMsat: (order: Order) => number | Promise<number>;
|
|
528
|
-
/** Groups every leg on the same secret, so one `followTrigger` socket hears them all */
|
|
529
|
-
trigger?: string;
|
|
530
|
-
/** How many settlements of that trigger the gateway keeps replayable past the hour, needs `trigger` */
|
|
531
|
-
replay?: number;
|
|
532
|
-
/** Only a watched leg has anywhere to carry this */
|
|
533
|
-
sealed?: (order: Order) => string | Promise<string>;
|
|
534
|
-
webhookUrl?: string;
|
|
535
|
-
/**
|
|
536
|
-
* Where your own `lightningVerifyEndpoint` is mounted, and the secret it
|
|
537
|
-
* unseals with. Set both and the gateway is handed your URL rather than the
|
|
538
|
-
* wallet's, so it polls you, never a third party, and learns nothing about
|
|
539
|
-
* which provider the recipient uses. Leave them out and it polls the wallet
|
|
540
|
-
*/
|
|
541
|
-
relayVerifyThrough?: {
|
|
542
|
-
endpoint: string;
|
|
543
|
-
secret: string;
|
|
544
|
-
};
|
|
545
|
-
/** What `Leg.rail` reads, for a shop running more than one wallet */
|
|
546
|
-
name?: string;
|
|
547
|
-
}
|
|
548
|
-
interface NwcRailConfig {
|
|
549
|
-
/** The gateway that watches an invoice your own wallet minted */
|
|
550
|
-
gateway: ThunderBridge;
|
|
551
|
-
/** Your wallet over NIP-47, from `nwcConnection`. It never reaches the gateway */
|
|
552
|
-
connection: NwcConnection;
|
|
553
|
-
/** What this order costs in millisatoshi */
|
|
554
|
-
amountMsat: (order: Order) => number | Promise<number>;
|
|
555
|
-
/**
|
|
556
|
-
* Where your own `nwcVerifyEndpoint` is mounted, and the secret it unseals
|
|
557
|
-
* with. The gateway is handed this URL rather than a wallet's, so it polls you
|
|
558
|
-
* and learns neither the connection nor which wallet is behind it
|
|
559
|
-
*/
|
|
560
|
-
verifyThrough: {
|
|
561
|
-
endpoint: string;
|
|
562
|
-
secret: string;
|
|
563
|
-
};
|
|
564
|
-
/** What the payer reads on the invoice, and what your wallet files it under */
|
|
565
|
-
description?: (order: Order) => string;
|
|
566
|
-
/** Groups every leg on the same secret, so one `followTrigger` socket hears them all */
|
|
567
|
-
trigger?: string;
|
|
568
|
-
/** How many settlements of that trigger the gateway keeps replayable past the hour, needs `trigger` */
|
|
569
|
-
replay?: number;
|
|
570
|
-
/** Only a watched leg has anywhere to carry this */
|
|
571
|
-
sealed?: (order: Order) => string | Promise<string>;
|
|
572
|
-
webhookUrl?: string;
|
|
573
|
-
/** What `Leg.rail` reads, for a shop running more than one wallet */
|
|
574
|
-
name?: string;
|
|
575
|
-
}
|
|
576
|
-
/**
|
|
577
|
-
* Sell for a bank transfer. The money moves straight to your account and the
|
|
578
|
-
* gateway is told a hash, a URL and an expiry, never the amount or the reference.
|
|
579
|
-
*
|
|
580
|
-
* Which bank is read back is `bankVerifyEndpoint`'s business, not this one's, so
|
|
581
|
-
* a rail built here serves Fio and anything else behind a `Statement`.
|
|
582
|
-
*/
|
|
583
|
-
declare function bankRail(config: BankRailConfig): Rail;
|
|
584
|
-
/**
|
|
585
|
-
* Sell for Lightning, with the gateway minting the invoice. It is told the
|
|
586
|
-
* address list and the amount, which is the round trip `blindLightningRail`
|
|
587
|
-
* spends to avoid.
|
|
588
|
-
*/
|
|
589
|
-
declare function lightningRail(config: LightningRailConfig): Rail;
|
|
590
|
-
/**
|
|
591
|
-
* Sell for Lightning, resolving the address here and handing the gateway only a
|
|
592
|
-
* hash and a URL to poll. It costs one more round trip and the gateway learns
|
|
593
|
-
* neither who is being paid nor how much, so the only refusal left to it is
|
|
594
|
-
* refusing everyone.
|
|
595
|
-
*/
|
|
596
|
-
declare function blindLightningRail(config: BlindLightningRailConfig): Rail;
|
|
597
|
-
/**
|
|
598
|
-
* Sell for Lightning against a wallet of your own over NIP-47, for a wallet that
|
|
599
|
-
* has no LUD-21 address to be watched at. Your node mints the invoice and releases
|
|
600
|
-
* the preimage, so the proof comes from one hop nearer than any hosted address can
|
|
601
|
-
* manage, and the gateway sees a hash and a URL of yours.
|
|
602
|
-
*/
|
|
603
|
-
declare function nwcRail(config: NwcRailConfig): Rail;
|
|
604
|
-
/**
|
|
605
|
-
* A provable invoice from the first address on the list that will issue one, which
|
|
606
|
-
* is what a client mints for itself rather than asking a gateway to. Everything the
|
|
607
|
-
* gateway needs to watch it comes back with everything you need to prove it came
|
|
608
|
-
* from the address you asked for, so you can hand over the first and keep the second.
|
|
609
|
-
*
|
|
610
|
-
* Server side: it resolves hostnames and refuses a private one, which no browser can
|
|
611
|
-
* do. Throws `NoWalletAvailableError` when no address on the list would serve
|
|
612
|
-
*/
|
|
613
|
-
declare function invoiceFrom(lnAddresses: string[], amountMsat: number): Promise<Resolved>;
|
|
614
|
-
|
|
615
|
-
export { nwcPay as A, type BankRailConfig as B, type CreatePaymentParams as C, nwcRail as D, nwcSettlement as E, type FollowOptions as F, nwcVerifyEndpoint as G, nwcVerifyUrl as H, type Leg as L, type NwcConnection as N, type Order as O, type Payment as P, type Quote as Q, type Rail as R, type Settlement as S, ThunderBridge as T, type WalletFailure as W, type ThunderBridgeOptions as a, type WatchPaymentParams as b, type TriggerEvent as c, type WaitOptions as d, type CreateOptions as e, type CreateQuoteParams as f, type LightningRailConfig as g, type PaymentKind as h, type PaymentStatus as i, type SocketTicket as j, type SocketTicketParams as k, type WalletReason as l, bankRail as m, lightningRail as n, type BlindLightningRailConfig as o, type NwcInvoice as p, type NwcRailConfig as q, type NwcVerifyConfig as r, type Resolved as s, toLnurl as t, askWallet as u, blindLightningRail as v, invoiceFrom as w, nwcConnection as x, nwcHoldInvoice as y, nwcInvoice as z };
|