thunder-bridge 1.5.0 → 2.2.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 +49 -24
- package/dist/{client-Cc5gtjGV.d.ts → bank-B5MxT_6u.d.ts} +367 -42
- package/dist/{client-CzGZcByI.d.cts → bank-Bg6RjuO-.d.cts} +367 -42
- package/dist/bank.cjs +196 -0
- package/dist/bank.d.cts +4 -2
- package/dist/bank.d.ts +4 -2
- package/dist/bank.js +195 -0
- package/dist/{errors-Dmh-Uoh8.d.cts → errors-DJmsalYZ.d.cts} +3 -3
- package/dist/{errors-0vbVoISA.d.ts → errors-VX0R18oE.d.ts} +3 -3
- package/dist/index.cjs +1313 -395
- package/dist/index.d.cts +19 -10
- package/dist/index.d.ts +19 -10
- package/dist/index.js +1312 -395
- package/dist/nwc.cjs +183 -42
- package/dist/nwc.d.cts +10 -111
- package/dist/nwc.d.ts +10 -111
- package/dist/nwc.js +180 -39
- package/dist/price.d.cts +2 -2
- package/dist/price.d.ts +2 -2
- package/dist/qr.cjs +20 -23
- package/dist/qr.js +20 -23
- package/dist/{types-BNPmVnA7.d.cts → types-DYZ9EkmJ.d.cts} +11 -2
- package/dist/{types-BNPmVnA7.d.ts → types-DYZ9EkmJ.d.ts} +11 -2
- package/openapi.yaml +30 -40
- package/package.json +1 -1
- package/dist/bank-B3mHISn1.d.cts +0 -92
- package/dist/bank-B3mHISn1.d.ts +0 -92
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { R as Resolved, Q as QrOptions } from './qr-CF-YeXU1.cjs';
|
|
2
|
-
import { A as Amount, T as Ticker, C as Charge,
|
|
3
|
-
import { a as BankTransferParams, B as BankTransfer, b as BankVerifyConfig } from './bank-B3mHISn1.cjs';
|
|
2
|
+
import { A as Amount, T as Ticker, C as Charge, f as MintedPayment, h as PaymentStatus, i as Priced, g as Msat, S as Settlement, P as Payment, Q as Quote, e as Held, H as Handover, j as SocketTicket } from './types-DYZ9EkmJ.cjs';
|
|
4
3
|
|
|
5
4
|
type Sent = {
|
|
6
5
|
method?: string;
|
|
7
6
|
headers?: Record<string, string>;
|
|
8
7
|
body?: string;
|
|
9
8
|
deadline?: AbortSignal;
|
|
9
|
+
staysOnOrigin?: boolean;
|
|
10
10
|
};
|
|
11
11
|
type Verified = {
|
|
12
12
|
address: string;
|
|
@@ -15,6 +15,120 @@ type Verified = {
|
|
|
15
15
|
/** Carries one request to an address ask() already verified, so nothing resolves the name again */
|
|
16
16
|
type Send = (url: string, sent: Sent, signal: AbortSignal, at: readonly Verified[]) => Promise<Response>;
|
|
17
17
|
|
|
18
|
+
/** A wallet reachable over NIP-47, as its `nostr+walletconnect://` URI describes it */
|
|
19
|
+
interface NwcConnection {
|
|
20
|
+
/** The wallet service's public key, which is what its answers have to be signed by */
|
|
21
|
+
walletPubkey: string;
|
|
22
|
+
/** Where to reach it, tried in order until one answers */
|
|
23
|
+
relays: string[];
|
|
24
|
+
/** Our own private key on this connection, and the only thing that authorises it */
|
|
25
|
+
secret: string;
|
|
26
|
+
}
|
|
27
|
+
/** A minted invoice and everything needed to watch it */
|
|
28
|
+
interface NwcInvoice {
|
|
29
|
+
bolt11: string;
|
|
30
|
+
paymentHash: string;
|
|
31
|
+
expiresAt: number;
|
|
32
|
+
}
|
|
33
|
+
/** The endpoint the gateway polls for an NWC payment, answering off your own wallet */
|
|
34
|
+
interface NwcVerifyConfig {
|
|
35
|
+
/** The wallet this endpoint speaks for. It never leaves this process */
|
|
36
|
+
connection: NwcConnection;
|
|
37
|
+
/** The secret the payment hash was sealed with, and nothing else uses it */
|
|
38
|
+
secret: string;
|
|
39
|
+
/** How often the gateway should ask, in seconds, sent as `Cache-Control: max-age`, `5` by default */
|
|
40
|
+
pollEverySecs?: number;
|
|
41
|
+
/** How long one `lookup_invoice` may take before the wallet counts as unreachable, `10_000` by default */
|
|
42
|
+
askTimeoutMs?: number;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Read a `nostr+walletconnect://` URI. Refuses a relay that is not `wss`, for the
|
|
46
|
+
* reason the gateway refuses a verify URL that is not https
|
|
47
|
+
*/
|
|
48
|
+
declare function nwcConnection(uri: string): NwcConnection;
|
|
49
|
+
/** Mint an invoice on the connected wallet, decoded so the caller need not trust its word */
|
|
50
|
+
declare function nwcInvoice(connection: NwcConnection, amountMsat: number, description: string, timeoutMs?: number): Promise<NwcInvoice>;
|
|
51
|
+
/**
|
|
52
|
+
* Mint a hold invoice on a hash the wallet does not hold the preimage for, which
|
|
53
|
+
* is what lets an operator be paid only by paying somebody else first. The hash
|
|
54
|
+
* has to come from the recipient's own invoice, and the invoice that comes back
|
|
55
|
+
* is decoded rather than believed
|
|
56
|
+
*/
|
|
57
|
+
declare function nwcHoldInvoice(connection: NwcConnection, held: {
|
|
58
|
+
paymentHash: string;
|
|
59
|
+
amountMsat: number;
|
|
60
|
+
description: string;
|
|
61
|
+
expirySecs: number;
|
|
62
|
+
minCltvExpiryDelta?: number;
|
|
63
|
+
}, timeoutMs?: number): Promise<NwcInvoice>;
|
|
64
|
+
/**
|
|
65
|
+
* The preimage the wallet released for this hash, null while it has released
|
|
66
|
+
* none. A preimage that does not hash to what was asked for is a lie rather than
|
|
67
|
+
* an answer, so it throws instead of being passed on
|
|
68
|
+
*/
|
|
69
|
+
declare function nwcSettlement(connection: NwcConnection, paymentHash: string, timeoutMs?: number): Promise<string | null>;
|
|
70
|
+
/**
|
|
71
|
+
* Pay an invoice and keep the preimage the network handed back. Whoever pays
|
|
72
|
+
* learns it, which is what makes delivery provable to a recipient publishing no
|
|
73
|
+
* LUD-21 of their own. A preimage that does not hash to the invoice's own hash is
|
|
74
|
+
* a lie rather than a receipt, so it throws instead of being passed on
|
|
75
|
+
*/
|
|
76
|
+
declare function nwcPay(connection: NwcConnection, bolt11: string, timeoutMs?: number): Promise<string>;
|
|
77
|
+
/**
|
|
78
|
+
* A verify endpoint of your own that asks your wallet over NIP-47, so the gateway
|
|
79
|
+
* polls you and never learns the connection, the relay, or which wallet it is.
|
|
80
|
+
*
|
|
81
|
+
* `nwcVerifyUrl` seals the payment hash into the query with your secret, which is
|
|
82
|
+
* what stops a stranger driving your wallet through this handler. It answers the
|
|
83
|
+
* LUD-21 shape the gateway already speaks, so nothing on that side changes.
|
|
84
|
+
*
|
|
85
|
+
* A wallet it cannot reach answers `502` rather than "not settled", because those
|
|
86
|
+
* are different claims and only one of them is true.
|
|
87
|
+
*/
|
|
88
|
+
declare function nwcVerifyEndpoint(config: NwcVerifyConfig): (request: Request) => Promise<Response>;
|
|
89
|
+
/**
|
|
90
|
+
* The URL to hand the gateway, with the payment hash sealed inside it. Point it at
|
|
91
|
+
* wherever `nwcVerifyEndpoint` is mounted
|
|
92
|
+
*/
|
|
93
|
+
declare function nwcVerifyUrl(endpoint: string, paymentHash: string, secret: string): Promise<string>;
|
|
94
|
+
/**
|
|
95
|
+
* One NIP-47 call, for a method this SDK does not wrap. The wallet's own info
|
|
96
|
+
* event lists what it will answer, and anything it refuses comes back as a
|
|
97
|
+
* `WalletRefused` whose `reason` says which kind of refusal it was
|
|
98
|
+
*/
|
|
99
|
+
declare function askWallet(connection: NwcConnection, method: string, params: Record<string, unknown>, timeoutMs?: number): Promise<Record<string, unknown>>;
|
|
100
|
+
/** A Lightning rail minting on a wallet of your own over NIP-47, bound once per shop */
|
|
101
|
+
interface NwcRailConfig extends RailConfig {
|
|
102
|
+
/** The wallet that mints, which never leaves this process */
|
|
103
|
+
connection: NwcConnection;
|
|
104
|
+
/**
|
|
105
|
+
* What to charge for one order, the order's own price converted at `rate` by
|
|
106
|
+
* default. Give it a function and the price is whatever you say
|
|
107
|
+
*/
|
|
108
|
+
amount?: (order: Order) => Amount;
|
|
109
|
+
/** Where the default conversion gets its rate, the median of four venues by default */
|
|
110
|
+
rate?: Ticker;
|
|
111
|
+
/** Where `nwcVerifyEndpoint` is mounted, and the secret the hash is sealed with */
|
|
112
|
+
verifyThrough: {
|
|
113
|
+
endpoint: string;
|
|
114
|
+
secret: string;
|
|
115
|
+
};
|
|
116
|
+
/** What the payer's wallet shows, the order's reference by default */
|
|
117
|
+
description?: (order: Order) => string;
|
|
118
|
+
/** Sealed before the gateway sees it, the way the blind Lightning rail does */
|
|
119
|
+
sealed?: {
|
|
120
|
+
secret: string;
|
|
121
|
+
data: (order: Order) => unknown;
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Sell for Lightning against a wallet of your own over NIP-47, for a wallet that
|
|
126
|
+
* has no LUD-21 address to be watched at. Your node mints the invoice and releases
|
|
127
|
+
* the preimage, so the proof comes from one hop nearer than any hosted address can
|
|
128
|
+
* manage, and the gateway sees a hash and a URL of yours
|
|
129
|
+
*/
|
|
130
|
+
declare function nwcRail(gateway: ThunderBridge, config: NwcRailConfig): Rail;
|
|
131
|
+
|
|
18
132
|
/** What a shop knows about a sale before any rail exists */
|
|
19
133
|
interface Order {
|
|
20
134
|
/** The bank matches it on the statement, and Lightning keys idempotency on it */
|
|
@@ -26,8 +140,9 @@ interface Order {
|
|
|
26
140
|
}
|
|
27
141
|
/** One way to pay one order, already registered with the gateway */
|
|
28
142
|
interface Leg {
|
|
29
|
-
/** The watched payment's id, which is what `firstSettled`, `payment` and `settled` take */
|
|
143
|
+
/** The watched payment's id, which with `paymentHash` is what `firstSettled`, `payment` and `settled` take */
|
|
30
144
|
id: string;
|
|
145
|
+
paymentHash: string;
|
|
31
146
|
/** Which rail made it, so a shop can label a leg without knowing how it was built */
|
|
32
147
|
rail: string;
|
|
33
148
|
/** What the payer reads, a BOLT11 invoice or a Short Payment Descriptor */
|
|
@@ -69,10 +184,13 @@ interface LightningRailConfig extends RailConfig {
|
|
|
69
184
|
/** The same rail with the invoice resolved here, so the gateway is told neither address nor amount */
|
|
70
185
|
interface BlindLightningRailConfig extends LightningRailConfig {
|
|
71
186
|
/**
|
|
72
|
-
* What the watcher needs and the gateway must not read, sealed
|
|
73
|
-
* before it goes anywhere near the gateway
|
|
187
|
+
* What the watcher needs and the gateway must not read, sealed under `secret`
|
|
188
|
+
* for the invoice's payment hash before it goes anywhere near the gateway
|
|
74
189
|
*/
|
|
75
|
-
sealed?:
|
|
190
|
+
sealed?: {
|
|
191
|
+
secret: string;
|
|
192
|
+
data: (order: Order) => unknown;
|
|
193
|
+
};
|
|
76
194
|
/**
|
|
77
195
|
* Where your own `serve.verify` endpoint is mounted, and its secret. Without
|
|
78
196
|
* it the gateway is handed the wallet's own URL, which a gateway enforcing its
|
|
@@ -96,12 +214,15 @@ interface BankRailConfig extends RailConfig {
|
|
|
96
214
|
/** When this leg stops being payable, in unix seconds */
|
|
97
215
|
expiresAt: (order: Order) => number;
|
|
98
216
|
/** Sealed before the gateway sees it, the way the blind Lightning rail does */
|
|
99
|
-
sealed?:
|
|
217
|
+
sealed?: {
|
|
218
|
+
secret: string;
|
|
219
|
+
data: (order: Order) => unknown;
|
|
220
|
+
};
|
|
100
221
|
/** The Czech variable symbol, taken off the reference's digits by default */
|
|
101
222
|
variableSymbol?: (order: Order) => string | undefined;
|
|
102
223
|
/**
|
|
103
|
-
* Register on a gateway you do not own anyway. The verify URL names
|
|
104
|
-
*
|
|
224
|
+
* Register on a gateway you do not own anyway. The sealed verify URL names
|
|
225
|
+
* nothing about the order, but its operator still learns every watch you place
|
|
105
226
|
*/
|
|
106
227
|
allowPublicGateway?: boolean;
|
|
107
228
|
}
|
|
@@ -132,6 +253,13 @@ declare class Rails {
|
|
|
132
253
|
blindLightning(config: BlindLightningRailConfig): Rail;
|
|
133
254
|
/** A bank transfer, proved the way a Lightning payment is */
|
|
134
255
|
bank(config: BankRailConfig): Rail;
|
|
256
|
+
/**
|
|
257
|
+
* Lightning against a wallet of your own over NIP-47, for a wallet that has no
|
|
258
|
+
* LUD-21 address to be watched at. Your node mints the invoice and releases the
|
|
259
|
+
* preimage, so the proof comes from one hop nearer than any hosted address can
|
|
260
|
+
* manage, and the gateway sees a hash and a URL of yours
|
|
261
|
+
*/
|
|
262
|
+
nwc(config: NwcRailConfig): Rail;
|
|
135
263
|
/**
|
|
136
264
|
* One bank transfer without building a rail first, for a shop that asks for
|
|
137
265
|
* them one at a time rather than beside another payment method
|
|
@@ -180,7 +308,7 @@ interface PaymentRequest {
|
|
|
180
308
|
* unpaid or the wait is aborted. It follows a WebSocket and reconnects through
|
|
181
309
|
* a drop, so this is one await rather than a poll.
|
|
182
310
|
*
|
|
183
|
-
* `gateway.settled(
|
|
311
|
+
* `gateway.settled(payment)` is the wider question and ends on an expiry too. This
|
|
184
312
|
* one is about the payment that was asked for, and one that expired was never paid
|
|
185
313
|
*/
|
|
186
314
|
paid(options?: WaitOptions): Promise<MintedPayment>;
|
|
@@ -335,7 +463,7 @@ interface WrapAllowance {
|
|
|
335
463
|
* Throws `GatewayCheatError` when a check fails and `UnverifiedRecipientError`
|
|
336
464
|
* when the recipient could not be reached to run one
|
|
337
465
|
*/
|
|
338
|
-
declare function proveOrigin(payment: MintedPayment, asked: Priced): Promise<void>;
|
|
466
|
+
declare function proveOrigin(payment: MintedPayment, asked: Priced, askedAt?: number): Promise<void>;
|
|
339
467
|
/**
|
|
340
468
|
* Prove the money arrived by asking the recipient's own server, not the gateway,
|
|
341
469
|
* returns the preimage when the recipient says it settled and null when it says
|
|
@@ -351,26 +479,39 @@ interface Provable {
|
|
|
351
479
|
bolt11?: string | null;
|
|
352
480
|
}
|
|
353
481
|
/**
|
|
354
|
-
* A report `
|
|
355
|
-
* status is settled. Nothing downstream of the check needs a null guard
|
|
482
|
+
* A report `agreesWithItself` has already accepted, so the preimage is there and
|
|
483
|
+
* the status is settled. Nothing downstream of the check needs a null guard
|
|
356
484
|
*/
|
|
357
|
-
type
|
|
485
|
+
type SelfConsistent<T extends Provable> = T & {
|
|
358
486
|
status: "paid";
|
|
359
487
|
preimage: string;
|
|
360
488
|
};
|
|
361
489
|
/**
|
|
362
|
-
*
|
|
490
|
+
* What `SelfConsistent` was called before 2.2.0
|
|
491
|
+
*
|
|
492
|
+
* @deprecated Use `SelfConsistent`, which says the report was checked against itself and nothing else
|
|
493
|
+
*/
|
|
494
|
+
type Proven<T extends Provable> = SelfConsistent<T>;
|
|
495
|
+
/**
|
|
496
|
+
* Whether a report agrees with itself: it says paid, and it carries a preimage
|
|
363
497
|
* that hashes to the payment hash it itself names. Where an invoice comes with it,
|
|
364
498
|
* the invoice's own hash has to agree too.
|
|
365
499
|
*
|
|
366
500
|
* A payment, a settlement delivered to a webhook and a frame off a trigger all
|
|
367
|
-
* answer this, because all three carry those fields
|
|
368
|
-
* one matters.
|
|
501
|
+
* answer this, because all three carry those fields.
|
|
369
502
|
*
|
|
370
|
-
* It asks nobody anything
|
|
371
|
-
*
|
|
503
|
+
* It asks nobody anything and holds the report against nothing you hold, so a
|
|
504
|
+
* gateway that invents a preimage and names its hash passes it. Checking against
|
|
505
|
+
* the hash you hold is what `payment` and `settled` do, and only
|
|
506
|
+
* `proveSettlement` asks the recipient
|
|
372
507
|
*/
|
|
373
|
-
declare function
|
|
508
|
+
declare function agreesWithItself<T extends Provable>(report: T): report is SelfConsistent<T>;
|
|
509
|
+
/**
|
|
510
|
+
* What `agreesWithItself` was called before 2.2.0
|
|
511
|
+
*
|
|
512
|
+
* @deprecated Use `agreesWithItself`, because it proves nothing beyond the report itself
|
|
513
|
+
*/
|
|
514
|
+
declare const carriesProof: typeof agreesWithItself;
|
|
374
515
|
/**
|
|
375
516
|
* The most an operator may add over the recipient's own amount, in millisatoshi.
|
|
376
517
|
* The proportion is what routing and the liquidity behind it costs, and the base
|
|
@@ -395,9 +536,15 @@ declare function wrapFeeCeiling(amountMsat: number, allowance?: WrapAllowance):
|
|
|
395
536
|
*/
|
|
396
537
|
declare function proveWrapped(wrapped: string, recipient: string, allowance?: WrapAllowance): void;
|
|
397
538
|
|
|
398
|
-
/**
|
|
539
|
+
/**
|
|
540
|
+
* How far the gateway's clock may drift from yours before a webhook is refused,
|
|
541
|
+
* and the URL you registered when a proxy in front of you hands requests on under
|
|
542
|
+
* another one. A delivery is signed for the URL it was sent to, so one made for
|
|
543
|
+
* somebody else's endpoint is refused here
|
|
544
|
+
*/
|
|
399
545
|
type WebhookOptions = {
|
|
400
546
|
toleranceSecs?: number;
|
|
547
|
+
url?: string;
|
|
401
548
|
};
|
|
402
549
|
/**
|
|
403
550
|
* What checks a delivery: the hex the gateway publishes at `/webhook-key`. There
|
|
@@ -427,11 +574,11 @@ interface WebhookHandlers {
|
|
|
427
574
|
* A settlement that proves itself: it says paid and its preimage hashes to the
|
|
428
575
|
* payment hash it names. This is the only callback a shop needs
|
|
429
576
|
*/
|
|
430
|
-
onSettled?: (settlement:
|
|
577
|
+
onSettled?: (settlement: SelfConsistent<Settlement>) => void | Promise<void>;
|
|
431
578
|
/**
|
|
432
|
-
* A delivery that carries no proof, so an expiry
|
|
433
|
-
*
|
|
434
|
-
*
|
|
579
|
+
* A delivery that carries no proof, so an expiry. Left unset, the handler
|
|
580
|
+
* answers `202` and does nothing, because acting on an unproven claim is the
|
|
581
|
+
* one thing this refuses to do
|
|
435
582
|
*/
|
|
436
583
|
onUnproven?: (settlement: Settlement) => void | Promise<void>;
|
|
437
584
|
/** A whole payment rather than a settlement, which is what an older gateway posts */
|
|
@@ -443,14 +590,21 @@ interface WebhookHandlers {
|
|
|
443
590
|
credential?: WebhookCredential;
|
|
444
591
|
/** How far the gateway's clock may drift from yours, five minutes by default */
|
|
445
592
|
toleranceSecs?: number;
|
|
593
|
+
/**
|
|
594
|
+
* The URL you registered, when a proxy in front of you hands the request on
|
|
595
|
+
* under another host or scheme. Left unset, the request's own URL is what the
|
|
596
|
+
* delivery has to have been signed for
|
|
597
|
+
*/
|
|
598
|
+
url?: string;
|
|
446
599
|
}
|
|
447
600
|
/**
|
|
448
601
|
* Everything one gateway lets you mount, in one place so a caller never has to
|
|
449
602
|
* know which handler needs the gateway and which does not. Most of these took it
|
|
450
603
|
* as a config field before, and reaching them through the gateway deleted it.
|
|
451
604
|
*
|
|
452
|
-
* `
|
|
453
|
-
* because a reader looking for a handler should find every handler
|
|
605
|
+
* `lightningVerify`, `bankVerify` and `nwcVerify` need nothing from the gateway and
|
|
606
|
+
* are here anyway, because a reader looking for a handler should find every handler
|
|
607
|
+
* in one list
|
|
454
608
|
*/
|
|
455
609
|
declare class Serve {
|
|
456
610
|
private readonly gateway;
|
|
@@ -471,13 +625,24 @@ declare class Serve {
|
|
|
471
625
|
* A verify endpoint of your own that asks the recipient's wallet for you, so
|
|
472
626
|
* the gateway polls you and never the wallet
|
|
473
627
|
*/
|
|
628
|
+
lightningVerify(config: LightningVerifyConfig): Handler;
|
|
629
|
+
/**
|
|
630
|
+
* What `lightningVerify` was called before 2.2.0
|
|
631
|
+
*
|
|
632
|
+
* @deprecated Use `lightningVerify`, beside `bankVerify` and `nwcVerify`
|
|
633
|
+
*/
|
|
474
634
|
verify(config: LightningVerifyConfig): Handler;
|
|
475
635
|
/** The verify endpoint a bank rail is polled at, answering off your own statement */
|
|
476
636
|
bankVerify(config: BankVerifyConfig): Handler;
|
|
637
|
+
/**
|
|
638
|
+
* The verify endpoint an NWC rail is polled at, asking your own wallet over
|
|
639
|
+
* NIP-47, so the gateway never learns the connection, the relay or the wallet
|
|
640
|
+
*/
|
|
641
|
+
nwcVerify(config: NwcVerifyConfig): Handler;
|
|
477
642
|
/**
|
|
478
643
|
* The whole webhook route: it answers the gateway's challenge, checks the
|
|
479
644
|
* signature against the key the gateway publishes, refuses a settlement that
|
|
480
|
-
* proves nothing, and calls you for the one that does.
|
|
645
|
+
* proves nothing, and calls you once for the one that does.
|
|
481
646
|
*
|
|
482
647
|
* `export const POST = gateway.serve.webhook({ onSettled: fulfil })` is the
|
|
483
648
|
* entire integration
|
|
@@ -492,14 +657,8 @@ declare class Serve {
|
|
|
492
657
|
private credential;
|
|
493
658
|
}
|
|
494
659
|
|
|
495
|
-
/** How this instance talks to one gateway
|
|
660
|
+
/** How this instance talks to one gateway */
|
|
496
661
|
interface ThunderBridgeOptions {
|
|
497
|
-
/**
|
|
498
|
-
* Prove every payment against the recipient's own server before handing it
|
|
499
|
-
* back, and refuse a reported settlement whose preimage does not hash to the
|
|
500
|
-
* payment hash, defaults to true
|
|
501
|
-
*/
|
|
502
|
-
verify?: boolean;
|
|
503
662
|
/**
|
|
504
663
|
* Sent as `Authorization: Bearer`, which a gateway started with
|
|
505
664
|
* `GATEWAY_TOKEN` requires on every call, the socket handshake included. No
|
|
@@ -521,7 +680,7 @@ interface WaitOptions {
|
|
|
521
680
|
signal?: AbortSignal;
|
|
522
681
|
/**
|
|
523
682
|
* Mint a short-lived ticket and put that in the socket URL instead of the
|
|
524
|
-
* payment id. Implied by `token`. The id stays readable inside the ticket,
|
|
683
|
+
* payment id. Implied by `token` and by `secret`. The id stays readable inside the ticket,
|
|
525
684
|
* what changes is that a URL out of a log stops opening anything after a
|
|
526
685
|
* minute
|
|
527
686
|
*/
|
|
@@ -584,17 +743,32 @@ interface FollowOptions {
|
|
|
584
743
|
/**
|
|
585
744
|
* Mint a short-lived ticket and put that in the socket URL instead of the
|
|
586
745
|
* secret, one per connection. Keeps the secret out of access logs, at the cost
|
|
587
|
-
* of a POST before each connect. Implied by `token`. Leave it off for a
|
|
746
|
+
* of a POST before each connect. Implied by `token` and by `secret`. Leave it off for a
|
|
588
747
|
* microcontroller, where one hardcoded URL and a dumb reconnect loop is the
|
|
589
748
|
* whole point
|
|
590
749
|
*/
|
|
591
750
|
tickets?: boolean;
|
|
592
751
|
}
|
|
752
|
+
/** How this caller holds a socket open and what it answers on it */
|
|
753
|
+
interface AttendOptions {
|
|
754
|
+
/**
|
|
755
|
+
* What this caller answers when the gateway asks about one of its payments.
|
|
756
|
+
* The preimage when the money is there, null while it is not, and the gateway
|
|
757
|
+
* checks the preimage against the hash either way
|
|
758
|
+
*/
|
|
759
|
+
answer: (paymentHash: string) => Promise<string | null> | string | null;
|
|
760
|
+
/** Called when a connection drops or a frame is refused, the socket keeps going */
|
|
761
|
+
onError?: (error: unknown) => void;
|
|
762
|
+
/** Reconnect after a drop, defaults to true */
|
|
763
|
+
reconnect?: boolean;
|
|
764
|
+
/** The first wait after a drop, doubling and jittered, defaults to 3000 */
|
|
765
|
+
reconnectDelayMs?: number;
|
|
766
|
+
}
|
|
593
767
|
/** Talks to a Thunder Bridge gateway and trusts it for nothing it can check itself */
|
|
594
768
|
declare class ThunderBridge {
|
|
595
769
|
private readonly baseUrl;
|
|
596
|
-
private readonly verify;
|
|
597
770
|
private readonly token;
|
|
771
|
+
private readonly handedOut;
|
|
598
772
|
private readonly secret;
|
|
599
773
|
private strangers;
|
|
600
774
|
private speaks;
|
|
@@ -651,7 +825,7 @@ declare class ThunderBridge {
|
|
|
651
825
|
* for both sorts: `kind` says whether the gateway minted it or was handed it,
|
|
652
826
|
* and the address, amount and invoice are null on one it was never told
|
|
653
827
|
*/
|
|
654
|
-
payment(
|
|
828
|
+
payment(held: Held): Promise<Payment | null>;
|
|
655
829
|
/**
|
|
656
830
|
* List what this gateway is watching, newest first. Only a gateway started
|
|
657
831
|
* with `GATEWAY_TOKEN` serves this, because on a shared one it would hand
|
|
@@ -671,7 +845,7 @@ declare class ThunderBridge {
|
|
|
671
845
|
* one that has answered is followed until its own expiry, so the wait always
|
|
672
846
|
* ends by itself
|
|
673
847
|
*/
|
|
674
|
-
settled(
|
|
848
|
+
settled(held: Held, options?: WaitOptions): Promise<Payment>;
|
|
675
849
|
private followed;
|
|
676
850
|
/**
|
|
677
851
|
* Wait on several payments and keep the first one that is really paid, then stop
|
|
@@ -690,8 +864,12 @@ declare class ThunderBridge {
|
|
|
690
864
|
* the recipient's own wallet minted it, so a payer who pays the loser afterwards
|
|
691
865
|
* really does pay twice and that shows up on `follow` as a second settlement to
|
|
692
866
|
* refund.
|
|
867
|
+
*
|
|
868
|
+
* A leg the gateway is caught lying about before any leg is paid ends the wait
|
|
869
|
+
* with its `GatewayCheatError`, even when another leg is paid after it, so a
|
|
870
|
+
* detected cheat is never traded for a later win.
|
|
693
871
|
*/
|
|
694
|
-
firstSettled(
|
|
872
|
+
firstSettled(held: Held[], options?: WaitOptions): Promise<Payment | null>;
|
|
695
873
|
/**
|
|
696
874
|
* Hand over an invoice you obtained yourself so the gateway watches it without
|
|
697
875
|
* being told the address or the amount. It can then only refuse everyone
|
|
@@ -707,6 +885,12 @@ declare class ThunderBridge {
|
|
|
707
885
|
* because then the gateway names the payment and only it can
|
|
708
886
|
*/
|
|
709
887
|
nameFor(paymentHash: string): Promise<string | null>;
|
|
888
|
+
/**
|
|
889
|
+
* Hold a socket open and answer what the gateway asks about this caller's own
|
|
890
|
+
* payments, so a watch addressed to this caller settles without anybody
|
|
891
|
+
* hosting a URL. Reconnects on its own until the returned function is called
|
|
892
|
+
*/
|
|
893
|
+
attend(options: AttendOptions): () => void;
|
|
710
894
|
/**
|
|
711
895
|
* Follow every payment made to one trigger, replayed from the recent ones on
|
|
712
896
|
* connect and then live, reconnecting on its own until the returned function
|
|
@@ -727,7 +911,148 @@ declare class ThunderBridge {
|
|
|
727
911
|
private sending;
|
|
728
912
|
private reading;
|
|
729
913
|
private speaking;
|
|
914
|
+
private handOut;
|
|
730
915
|
private proven;
|
|
731
916
|
}
|
|
732
917
|
|
|
733
|
-
|
|
918
|
+
/** One incoming payment as the bank booked it, in the smallest unit of its currency */
|
|
919
|
+
interface Credit {
|
|
920
|
+
amountMinor: number;
|
|
921
|
+
currency: string;
|
|
922
|
+
/** Whatever the payer wrote, wherever this bank puts it. Matching is a whole word, so noise around it is fine */
|
|
923
|
+
reference: string;
|
|
924
|
+
/**
|
|
925
|
+
* Unix seconds. A bank that books a day rather than an instant, as Fio does,
|
|
926
|
+
* gives the day's midnight in its own zone, so rendering this in UTC can show
|
|
927
|
+
* the day before. Nothing here matches on it, it is yours to read
|
|
928
|
+
*/
|
|
929
|
+
bookedAt: number;
|
|
930
|
+
}
|
|
931
|
+
/**
|
|
932
|
+
* Recent credits on one account, oldest or newest first, it makes no difference.
|
|
933
|
+
* This is the whole plugin seam: a bank is a function of this shape, and
|
|
934
|
+
* `fioStatement` is one implementation of it
|
|
935
|
+
*/
|
|
936
|
+
type Statement = (sinceUnix: number) => Promise<Credit[]>;
|
|
937
|
+
/** One transfer to ask for: what is owed, where it lands, and where its arrival is read back from */
|
|
938
|
+
interface BankTransferParams {
|
|
939
|
+
/**
|
|
940
|
+
* Long lived and server side, at least 32 characters. The preimage is derived
|
|
941
|
+
* from it and the verify query is sealed with it, so losing it loses every proof
|
|
942
|
+
*/
|
|
943
|
+
secret: string;
|
|
944
|
+
/** What the payer must leave on the transfer, an order id or a nonce. It is matched, not stored */
|
|
945
|
+
reference: string;
|
|
946
|
+
/** The price in the smallest unit, so 48055 is 480.55 CZK */
|
|
947
|
+
amountMinor: number;
|
|
948
|
+
/** The account the money goes to, as an IBAN */
|
|
949
|
+
iban: string;
|
|
950
|
+
/**
|
|
951
|
+
* Where `bankVerifyEndpoint` is mounted, a public https URL with no query of
|
|
952
|
+
* its own. Not needed when `answerBy` is "agent", because then nothing is polled
|
|
953
|
+
*/
|
|
954
|
+
verifyUrl?: string;
|
|
955
|
+
/**
|
|
956
|
+
* How the gateway gets its answer. "poll" hands it a URL it fetches, which
|
|
957
|
+
* needs a public host. "agent" hands it this caller's name instead, and the
|
|
958
|
+
* socket `bankAgent` holds open answers for it, which needs no host at all
|
|
959
|
+
*/
|
|
960
|
+
answerBy?: "poll" | "agent";
|
|
961
|
+
/** When the offer dies, in unix seconds. Money in a bank moves on banking days, so give it days */
|
|
962
|
+
expiresAt: number;
|
|
963
|
+
/** Defaults to CZK */
|
|
964
|
+
currency?: string;
|
|
965
|
+
/** Up to ten digits, for accounting systems that still want one */
|
|
966
|
+
variableSymbol?: string;
|
|
967
|
+
/**
|
|
968
|
+
* Groups this transfer with everything else paid to the same secret, so one
|
|
969
|
+
* `followTrigger` socket hears about it. Give the Lightning leg of the same
|
|
970
|
+
* order the same secret and both rails arrive on one stream
|
|
971
|
+
*/
|
|
972
|
+
trigger?: string;
|
|
973
|
+
/** How many settlements of that trigger the gateway keeps replayable past the hour, needs `trigger` */
|
|
974
|
+
replay?: number;
|
|
975
|
+
/**
|
|
976
|
+
* Handed back on that stream, so a watcher learns which order settled without
|
|
977
|
+
* asking anyone. It is sealed under `secret` for this transfer's payment hash,
|
|
978
|
+
* so the gateway can neither read it nor move it onto another payment
|
|
979
|
+
*/
|
|
980
|
+
sealed?: {
|
|
981
|
+
secret: string;
|
|
982
|
+
data: unknown;
|
|
983
|
+
};
|
|
984
|
+
/**
|
|
985
|
+
* Where the gateway posts once the money lands, a public https URL. Without one
|
|
986
|
+
* a transfer is only ever learned by following the trigger or asking
|
|
987
|
+
*/
|
|
988
|
+
webhookUrl?: string;
|
|
989
|
+
/**
|
|
990
|
+
* Register on a gateway you do not own anyway. The sealed verify URL tells its
|
|
991
|
+
* operator nothing about the order, but the URL itself still answers whether
|
|
992
|
+
* that order was paid. Say true only when that much is not worth hiding
|
|
993
|
+
*/
|
|
994
|
+
allowPublicGateway?: boolean;
|
|
995
|
+
}
|
|
996
|
+
/** A transfer the gateway is now watching, and the descriptor the payer scans */
|
|
997
|
+
interface BankTransfer {
|
|
998
|
+
/** The watched payment's id at the gateway, which is how you read this order back */
|
|
999
|
+
id: string;
|
|
1000
|
+
/** What the gateway was given, and what the preimage has to hash to */
|
|
1001
|
+
paymentHash: string;
|
|
1002
|
+
/** The same URL you mounted, carrying what to look for and a signature over it */
|
|
1003
|
+
verifyUrl: string;
|
|
1004
|
+
/** The payer scans this, it is a Short Payment Descriptor, the Czech QR platba format */
|
|
1005
|
+
spd: string;
|
|
1006
|
+
}
|
|
1007
|
+
/** The endpoint the gateway polls for a bank transfer, answering off your own statement */
|
|
1008
|
+
interface BankVerifyConfig {
|
|
1009
|
+
/** The same secret `bankTransfer` was given */
|
|
1010
|
+
secret: string;
|
|
1011
|
+
/** The IBAN this endpoint answers for, refusing a question sealed for another account */
|
|
1012
|
+
iban: string;
|
|
1013
|
+
/** The account to read */
|
|
1014
|
+
statement: Statement;
|
|
1015
|
+
/** How far back a credit still counts, seven days by default */
|
|
1016
|
+
lookBackSecs?: number;
|
|
1017
|
+
/**
|
|
1018
|
+
* How often you want the gateway to ask, in seconds. It goes out as
|
|
1019
|
+
* `Cache-Control: max-age`, so the pace is yours to set rather than the
|
|
1020
|
+
* gateway's, and a bank that updates once a minute should say so instead of
|
|
1021
|
+
* being polled every few seconds. Thirty by default, clamped to an hour
|
|
1022
|
+
*/
|
|
1023
|
+
pollEverySecs?: number;
|
|
1024
|
+
}
|
|
1025
|
+
/** One order this caller is waiting on, and the account it is waiting on it in */
|
|
1026
|
+
interface BankOrder {
|
|
1027
|
+
iban: string;
|
|
1028
|
+
reference: string;
|
|
1029
|
+
amountMinor: number;
|
|
1030
|
+
currency?: string;
|
|
1031
|
+
expiresAt: number;
|
|
1032
|
+
statement: Statement;
|
|
1033
|
+
}
|
|
1034
|
+
/** What a caller needs to answer for its own transfers over a socket */
|
|
1035
|
+
interface BankAgentConfig {
|
|
1036
|
+
/** The gateway holding the watches this caller raised */
|
|
1037
|
+
gateway: ThunderBridge;
|
|
1038
|
+
/** The same secret `bankTransfer` was given, never leaving this device */
|
|
1039
|
+
secret: string;
|
|
1040
|
+
/** What the payment the gateway is asking about was asking for, or null when it is none of ours */
|
|
1041
|
+
orders: (paymentHash: string) => Promise<BankOrder | null> | BankOrder | null;
|
|
1042
|
+
/** How far back a credit still counts, seven days by default */
|
|
1043
|
+
lookBackSecs?: number;
|
|
1044
|
+
/** Called when a connection drops or a frame is refused, the socket keeps going */
|
|
1045
|
+
onError?: (error: unknown) => void;
|
|
1046
|
+
}
|
|
1047
|
+
/**
|
|
1048
|
+
* Answer the gateway over a socket this device opens, so a transfer addressed to
|
|
1049
|
+
* this caller settles from a till behind NAT, a browser tab or a phone. The
|
|
1050
|
+
* preimage is derived here from the secret, so the gateway is told only that one
|
|
1051
|
+
* exists and can check it against the hash it already holds.
|
|
1052
|
+
*
|
|
1053
|
+
* Call the returned function to stop attending. Whatever is still open is asked
|
|
1054
|
+
* again on the gateway's own schedule, so leaving and coming back loses nothing
|
|
1055
|
+
*/
|
|
1056
|
+
declare function bankAgent(config: BankAgentConfig): () => void;
|
|
1057
|
+
|
|
1058
|
+
export { type WebhookOptions as $, type AttendOptions as A, type BankAgentConfig as B, type Credit as C, type Proven as D, type RailConfig as E, type FollowOptions as F, Rails as G, type Handler as H, type Range as I, type Relayed as J, type SelfConsistent as K, type Leg as L, type Minted as M, type NwcConnection as N, type Order as O, type PaymentRequest as P, type Send as Q, type Rail as R, type Statement as S, ThunderBridge as T, Serve as U, type TicketOptions as V, type WaitOptions as W, type TriggerConfig as X, type WatchTicketConfig as Y, type WebhookCredential as Z, type WebhookHandlers as _, type BankOrder as a, type WrapAllowance as a0, agreesWithItself as a1, answerVerifyChallenge as a2, carriesProof as a3, invoiceFrom as a4, proveOrigin as a5, proveSettlement as a6, proveWrapped as a7, relayedVerifyUrl as a8, wrapFeeCeiling as a9, type BankTransfer as b, type BankTransferParams as c, type BankVerifyConfig as d, bankAgent as e, nwcVerifyEndpoint as f, type NwcInvoice as g, type NwcRailConfig as h, type NwcVerifyConfig as i, askWallet as j, nwcConnection as k, nwcHoldInvoice as l, nwcInvoice as m, nwcRail as n, nwcPay as o, nwcSettlement as p, nwcVerifyUrl as q, type ThunderBridgeOptions as r, type BankRailConfig as s, type BlindLightningRailConfig as t, type CreateOptions as u, type LightningRailConfig as v, type LightningVerifyConfig as w, type PaymentRequestInit as x, type PaymentRequestOptions as y, type Provable as z };
|