thunder-bridge 1.0.0 → 1.3.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 +96 -4
- package/dist/index.cjs +1650 -1302
- package/dist/index.d.cts +214 -170
- package/dist/index.d.ts +214 -170
- package/dist/index.js +1646 -1301
- package/dist/{rail-CL9QkiHo.d.cts → rail-DZzlN-bi.d.cts} +166 -1
- package/dist/{rail-CL9QkiHo.d.ts → rail-DZzlN-bi.d.ts} +166 -1
- package/dist/server.cjs +976 -382
- package/dist/server.d.cts +47 -41
- package/dist/server.d.ts +47 -41
- package/dist/server.js +966 -382
- package/openapi.yaml +1 -1
- package/package.json +33 -13
|
@@ -1,3 +1,17 @@
|
|
|
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
|
+
|
|
1
15
|
/** Where a payment stands, `paid` is the only status that carries a preimage */
|
|
2
16
|
type PaymentStatus = "pending" | "paid" | "expired";
|
|
3
17
|
/** Whether the gateway resolved the address and got the invoice, or was handed one to watch */
|
|
@@ -75,6 +89,12 @@ interface WatchPaymentParams {
|
|
|
75
89
|
verifyUrl: string;
|
|
76
90
|
expiresAt: number;
|
|
77
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;
|
|
78
98
|
sealed?: string;
|
|
79
99
|
webhookUrl?: string;
|
|
80
100
|
}
|
|
@@ -147,10 +167,22 @@ interface CreateOptions {
|
|
|
147
167
|
* from any URL a payer sees
|
|
148
168
|
*/
|
|
149
169
|
trigger?: string;
|
|
170
|
+
/**
|
|
171
|
+
* How many of the trigger's settlements the gateway keeps replayable past the
|
|
172
|
+
* hour it would otherwise forget them in, up to the ceiling its operator set.
|
|
173
|
+
* Needs `trigger`, defaults to none
|
|
174
|
+
*/
|
|
175
|
+
replay?: number;
|
|
150
176
|
}
|
|
151
177
|
interface FollowOptions {
|
|
152
178
|
/** Called for the recent settlements replayed on connect, then for each new one */
|
|
153
179
|
onPayment: (settled: TriggerEvent) => void;
|
|
180
|
+
/**
|
|
181
|
+
* How many settlements to ask for on connect, defaults to the gateway's ten.
|
|
182
|
+
* It hands back what it still holds, which is the last hour unless the
|
|
183
|
+
* payments were minted with `replay`
|
|
184
|
+
*/
|
|
185
|
+
replay?: number;
|
|
154
186
|
/** Called when a connection drops or a frame is refused, the follow keeps going */
|
|
155
187
|
onError?: (error: unknown) => void;
|
|
156
188
|
/** Reconnect after a drop, defaults to true */
|
|
@@ -303,6 +335,88 @@ declare class ThunderBridge {
|
|
|
303
335
|
private checked;
|
|
304
336
|
}
|
|
305
337
|
|
|
338
|
+
/** A wallet reachable over NIP-47, as its `nostr+walletconnect://` URI describes it */
|
|
339
|
+
interface NwcConnection {
|
|
340
|
+
/** The wallet service's public key, which is what its answers have to be signed by */
|
|
341
|
+
walletPubkey: string;
|
|
342
|
+
/** Where to reach it, tried in order until one answers */
|
|
343
|
+
relays: string[];
|
|
344
|
+
/** Our own private key on this connection, and the only thing that authorises it */
|
|
345
|
+
secret: string;
|
|
346
|
+
}
|
|
347
|
+
/** A minted invoice and everything needed to watch it */
|
|
348
|
+
interface NwcInvoice {
|
|
349
|
+
bolt11: string;
|
|
350
|
+
paymentHash: string;
|
|
351
|
+
expiresAt: number;
|
|
352
|
+
}
|
|
353
|
+
interface NwcVerifyConfig {
|
|
354
|
+
/** The wallet this endpoint speaks for. It never leaves this process */
|
|
355
|
+
connection: NwcConnection;
|
|
356
|
+
/** The secret the payment hash was sealed with, and nothing else uses it */
|
|
357
|
+
secret: string;
|
|
358
|
+
/** How often the gateway should ask, in seconds, sent as `Cache-Control: max-age`, `5` by default */
|
|
359
|
+
pollEverySecs?: number;
|
|
360
|
+
/** How long one `lookup_invoice` may take before the wallet counts as unreachable, `10_000` by default */
|
|
361
|
+
askTimeoutMs?: number;
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Read a `nostr+walletconnect://` URI. Refuses a relay that is not `wss`, for the
|
|
365
|
+
* reason the gateway refuses a verify URL that is not https
|
|
366
|
+
*/
|
|
367
|
+
declare function nwcConnection(uri: string): NwcConnection;
|
|
368
|
+
/** Mint an invoice on the connected wallet, decoded so the caller need not trust its word */
|
|
369
|
+
declare function nwcInvoice(connection: NwcConnection, amountMsat: number, description: string, timeoutMs?: number): Promise<NwcInvoice>;
|
|
370
|
+
/**
|
|
371
|
+
* Mint a hold invoice on a hash the wallet does not hold the preimage for, which
|
|
372
|
+
* is what lets an operator be paid only by paying somebody else first. The hash
|
|
373
|
+
* has to come from the recipient's own invoice, and the invoice that comes back
|
|
374
|
+
* is decoded rather than believed
|
|
375
|
+
*/
|
|
376
|
+
declare function nwcHoldInvoice(connection: NwcConnection, held: {
|
|
377
|
+
paymentHash: string;
|
|
378
|
+
amountMsat: number;
|
|
379
|
+
description: string;
|
|
380
|
+
expirySecs: number;
|
|
381
|
+
minCltvExpiryDelta?: number;
|
|
382
|
+
}, timeoutMs?: number): Promise<NwcInvoice>;
|
|
383
|
+
/**
|
|
384
|
+
* The preimage the wallet released for this hash, null while it has released
|
|
385
|
+
* none. A preimage that does not hash to what was asked for is a lie rather than
|
|
386
|
+
* an answer, so it throws instead of being passed on
|
|
387
|
+
*/
|
|
388
|
+
declare function nwcSettlement(connection: NwcConnection, paymentHash: string, timeoutMs?: number): Promise<string | null>;
|
|
389
|
+
/**
|
|
390
|
+
* Pay an invoice and keep the preimage the network handed back. Whoever pays
|
|
391
|
+
* learns it, which is what makes delivery provable to a recipient publishing no
|
|
392
|
+
* LUD-21 of their own. A preimage that does not hash to the invoice's own hash is
|
|
393
|
+
* a lie rather than a receipt, so it throws instead of being passed on
|
|
394
|
+
*/
|
|
395
|
+
declare function nwcPay(connection: NwcConnection, bolt11: string, timeoutMs?: number): Promise<string>;
|
|
396
|
+
/**
|
|
397
|
+
* A verify endpoint of your own that asks your wallet over NIP-47, so the gateway
|
|
398
|
+
* polls you and never learns the connection, the relay, or which wallet it is.
|
|
399
|
+
*
|
|
400
|
+
* `nwcVerifyUrl` seals the payment hash into the query with your secret, which is
|
|
401
|
+
* what stops a stranger driving your wallet through this handler. It answers the
|
|
402
|
+
* LUD-21 shape the gateway already speaks, so nothing on that side changes.
|
|
403
|
+
*
|
|
404
|
+
* A wallet it cannot reach answers `502` rather than "not settled", because those
|
|
405
|
+
* are different claims and only one of them is true.
|
|
406
|
+
*/
|
|
407
|
+
declare function nwcVerifyEndpoint(config: NwcVerifyConfig): (request: Request) => Promise<Response>;
|
|
408
|
+
/**
|
|
409
|
+
* The URL to hand the gateway, with the payment hash sealed inside it. Point it at
|
|
410
|
+
* wherever `nwcVerifyEndpoint` is mounted
|
|
411
|
+
*/
|
|
412
|
+
declare function nwcVerifyUrl(endpoint: string, paymentHash: string, secret: string): Promise<string>;
|
|
413
|
+
/**
|
|
414
|
+
* One NIP-47 call, for a method this SDK does not wrap. The wallet's own info
|
|
415
|
+
* event lists what it will answer, and anything it refuses comes back as a
|
|
416
|
+
* `WalletRefused` carrying the code it named
|
|
417
|
+
*/
|
|
418
|
+
declare function askWallet(connection: NwcConnection, method: string, params: Record<string, unknown>, timeoutMs?: number): Promise<Record<string, unknown>>;
|
|
419
|
+
|
|
306
420
|
/** What a shop knows about a sale before any rail exists */
|
|
307
421
|
interface Order {
|
|
308
422
|
/** The bank matches it on the statement, and Lightning keys idempotency on it */
|
|
@@ -346,6 +460,8 @@ interface BankRailConfig {
|
|
|
346
460
|
expiresAt: (order: Order) => number;
|
|
347
461
|
/** Groups every leg on the same secret, so one `followTrigger` socket hears them all */
|
|
348
462
|
trigger?: string;
|
|
463
|
+
/** How many settlements of that trigger the gateway keeps replayable past the hour, needs `trigger` */
|
|
464
|
+
replay?: number;
|
|
349
465
|
/** Handed back untouched on that stream. Stable across re-offers, for the reason `expiresAt` is */
|
|
350
466
|
sealed?: (order: Order) => string | Promise<string>;
|
|
351
467
|
/** Up to ten digits, for accounting systems that still want one */
|
|
@@ -365,6 +481,8 @@ interface LightningRailConfig {
|
|
|
365
481
|
amountMsat: (order: Order) => number | Promise<number>;
|
|
366
482
|
/** Groups every leg on the same secret, so one `followTrigger` socket hears them all */
|
|
367
483
|
trigger?: string;
|
|
484
|
+
/** How many settlements of that trigger the gateway keeps replayable past the hour, needs `trigger` */
|
|
485
|
+
replay?: number;
|
|
368
486
|
/**
|
|
369
487
|
* Makes the mint safe to retry. Unset nothing is sent, because a key stable
|
|
370
488
|
* across re-offers is one the gateway can join against the bank leg's reference
|
|
@@ -383,6 +501,8 @@ interface BlindLightningRailConfig {
|
|
|
383
501
|
amountMsat: (order: Order) => number | Promise<number>;
|
|
384
502
|
/** Groups every leg on the same secret, so one `followTrigger` socket hears them all */
|
|
385
503
|
trigger?: string;
|
|
504
|
+
/** How many settlements of that trigger the gateway keeps replayable past the hour, needs `trigger` */
|
|
505
|
+
replay?: number;
|
|
386
506
|
/** Only a watched leg has anywhere to carry this */
|
|
387
507
|
sealed?: (order: Order) => string | Promise<string>;
|
|
388
508
|
webhookUrl?: string;
|
|
@@ -399,6 +519,34 @@ interface BlindLightningRailConfig {
|
|
|
399
519
|
/** What `Leg.rail` reads, for a shop running more than one wallet */
|
|
400
520
|
name?: string;
|
|
401
521
|
}
|
|
522
|
+
interface NwcRailConfig {
|
|
523
|
+
/** The gateway that watches an invoice your own wallet minted */
|
|
524
|
+
gateway: ThunderBridge;
|
|
525
|
+
/** Your wallet over NIP-47, from `nwcConnection`. It never reaches the gateway */
|
|
526
|
+
connection: NwcConnection;
|
|
527
|
+
/** What this order costs in millisatoshi */
|
|
528
|
+
amountMsat: (order: Order) => number | Promise<number>;
|
|
529
|
+
/**
|
|
530
|
+
* Where your own `nwcVerifyEndpoint` is mounted, and the secret it unseals
|
|
531
|
+
* with. The gateway is handed this URL rather than a wallet's, so it polls you
|
|
532
|
+
* and learns neither the connection nor which wallet is behind it
|
|
533
|
+
*/
|
|
534
|
+
verifyThrough: {
|
|
535
|
+
endpoint: string;
|
|
536
|
+
secret: string;
|
|
537
|
+
};
|
|
538
|
+
/** What the payer reads on the invoice, and what your wallet files it under */
|
|
539
|
+
description?: (order: Order) => string;
|
|
540
|
+
/** Groups every leg on the same secret, so one `followTrigger` socket hears them all */
|
|
541
|
+
trigger?: string;
|
|
542
|
+
/** How many settlements of that trigger the gateway keeps replayable past the hour, needs `trigger` */
|
|
543
|
+
replay?: number;
|
|
544
|
+
/** Only a watched leg has anywhere to carry this */
|
|
545
|
+
sealed?: (order: Order) => string | Promise<string>;
|
|
546
|
+
webhookUrl?: string;
|
|
547
|
+
/** What `Leg.rail` reads, for a shop running more than one wallet */
|
|
548
|
+
name?: string;
|
|
549
|
+
}
|
|
402
550
|
/**
|
|
403
551
|
* Sell for a bank transfer. The money moves straight to your account and the
|
|
404
552
|
* gateway is told a hash, a URL and an expiry, never the amount or the reference.
|
|
@@ -420,5 +568,22 @@ declare function lightningRail(config: LightningRailConfig): Rail;
|
|
|
420
568
|
* refusing everyone.
|
|
421
569
|
*/
|
|
422
570
|
declare function blindLightningRail(config: BlindLightningRailConfig): Rail;
|
|
571
|
+
/**
|
|
572
|
+
* Sell for Lightning against a wallet of your own over NIP-47, for a wallet that
|
|
573
|
+
* has no LUD-21 address to be watched at. Your node mints the invoice and releases
|
|
574
|
+
* the preimage, so the proof comes from one hop nearer than any hosted address can
|
|
575
|
+
* manage, and the gateway sees a hash and a URL of yours.
|
|
576
|
+
*/
|
|
577
|
+
declare function nwcRail(config: NwcRailConfig): Rail;
|
|
578
|
+
/**
|
|
579
|
+
* A provable invoice from the first address on the list that will issue one, which
|
|
580
|
+
* is what a client mints for itself rather than asking a gateway to. Everything the
|
|
581
|
+
* gateway needs to watch it comes back with everything you need to prove it came
|
|
582
|
+
* from the address you asked for, so you can hand over the first and keep the second.
|
|
583
|
+
*
|
|
584
|
+
* Server side: it resolves hostnames and refuses a private one, which no browser can
|
|
585
|
+
* do. Throws `NoWalletAvailableError` when no address on the list would serve
|
|
586
|
+
*/
|
|
587
|
+
declare function invoiceFrom(lnAddresses: string[], amountMsat: number): Promise<Resolved>;
|
|
423
588
|
|
|
424
|
-
export { type BankRailConfig as B, type CreatePaymentParams as C, type FollowOptions as F, type Leg as L, type Order as O, type Payment as P, type Quote as Q, type Rail as R, type Settlement as S, ThunderBridge as T, type
|
|
589
|
+
export { nwcSettlement as A, type BankRailConfig as B, type CreatePaymentParams as C, nwcVerifyEndpoint as D, nwcVerifyUrl as E, type FollowOptions as F, 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 WalletReason as j, bankRail as k, lightningRail as l, type BlindLightningRailConfig as m, type NwcInvoice as n, type NwcRailConfig as o, type NwcVerifyConfig as p, type Resolved as q, askWallet as r, blindLightningRail as s, toLnurl as t, invoiceFrom as u, nwcConnection as v, nwcHoldInvoice as w, nwcInvoice as x, nwcPay as y, nwcRail as z };
|
|
@@ -1,3 +1,17 @@
|
|
|
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
|
+
|
|
1
15
|
/** Where a payment stands, `paid` is the only status that carries a preimage */
|
|
2
16
|
type PaymentStatus = "pending" | "paid" | "expired";
|
|
3
17
|
/** Whether the gateway resolved the address and got the invoice, or was handed one to watch */
|
|
@@ -75,6 +89,12 @@ interface WatchPaymentParams {
|
|
|
75
89
|
verifyUrl: string;
|
|
76
90
|
expiresAt: number;
|
|
77
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;
|
|
78
98
|
sealed?: string;
|
|
79
99
|
webhookUrl?: string;
|
|
80
100
|
}
|
|
@@ -147,10 +167,22 @@ interface CreateOptions {
|
|
|
147
167
|
* from any URL a payer sees
|
|
148
168
|
*/
|
|
149
169
|
trigger?: string;
|
|
170
|
+
/**
|
|
171
|
+
* How many of the trigger's settlements the gateway keeps replayable past the
|
|
172
|
+
* hour it would otherwise forget them in, up to the ceiling its operator set.
|
|
173
|
+
* Needs `trigger`, defaults to none
|
|
174
|
+
*/
|
|
175
|
+
replay?: number;
|
|
150
176
|
}
|
|
151
177
|
interface FollowOptions {
|
|
152
178
|
/** Called for the recent settlements replayed on connect, then for each new one */
|
|
153
179
|
onPayment: (settled: TriggerEvent) => void;
|
|
180
|
+
/**
|
|
181
|
+
* How many settlements to ask for on connect, defaults to the gateway's ten.
|
|
182
|
+
* It hands back what it still holds, which is the last hour unless the
|
|
183
|
+
* payments were minted with `replay`
|
|
184
|
+
*/
|
|
185
|
+
replay?: number;
|
|
154
186
|
/** Called when a connection drops or a frame is refused, the follow keeps going */
|
|
155
187
|
onError?: (error: unknown) => void;
|
|
156
188
|
/** Reconnect after a drop, defaults to true */
|
|
@@ -303,6 +335,88 @@ declare class ThunderBridge {
|
|
|
303
335
|
private checked;
|
|
304
336
|
}
|
|
305
337
|
|
|
338
|
+
/** A wallet reachable over NIP-47, as its `nostr+walletconnect://` URI describes it */
|
|
339
|
+
interface NwcConnection {
|
|
340
|
+
/** The wallet service's public key, which is what its answers have to be signed by */
|
|
341
|
+
walletPubkey: string;
|
|
342
|
+
/** Where to reach it, tried in order until one answers */
|
|
343
|
+
relays: string[];
|
|
344
|
+
/** Our own private key on this connection, and the only thing that authorises it */
|
|
345
|
+
secret: string;
|
|
346
|
+
}
|
|
347
|
+
/** A minted invoice and everything needed to watch it */
|
|
348
|
+
interface NwcInvoice {
|
|
349
|
+
bolt11: string;
|
|
350
|
+
paymentHash: string;
|
|
351
|
+
expiresAt: number;
|
|
352
|
+
}
|
|
353
|
+
interface NwcVerifyConfig {
|
|
354
|
+
/** The wallet this endpoint speaks for. It never leaves this process */
|
|
355
|
+
connection: NwcConnection;
|
|
356
|
+
/** The secret the payment hash was sealed with, and nothing else uses it */
|
|
357
|
+
secret: string;
|
|
358
|
+
/** How often the gateway should ask, in seconds, sent as `Cache-Control: max-age`, `5` by default */
|
|
359
|
+
pollEverySecs?: number;
|
|
360
|
+
/** How long one `lookup_invoice` may take before the wallet counts as unreachable, `10_000` by default */
|
|
361
|
+
askTimeoutMs?: number;
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Read a `nostr+walletconnect://` URI. Refuses a relay that is not `wss`, for the
|
|
365
|
+
* reason the gateway refuses a verify URL that is not https
|
|
366
|
+
*/
|
|
367
|
+
declare function nwcConnection(uri: string): NwcConnection;
|
|
368
|
+
/** Mint an invoice on the connected wallet, decoded so the caller need not trust its word */
|
|
369
|
+
declare function nwcInvoice(connection: NwcConnection, amountMsat: number, description: string, timeoutMs?: number): Promise<NwcInvoice>;
|
|
370
|
+
/**
|
|
371
|
+
* Mint a hold invoice on a hash the wallet does not hold the preimage for, which
|
|
372
|
+
* is what lets an operator be paid only by paying somebody else first. The hash
|
|
373
|
+
* has to come from the recipient's own invoice, and the invoice that comes back
|
|
374
|
+
* is decoded rather than believed
|
|
375
|
+
*/
|
|
376
|
+
declare function nwcHoldInvoice(connection: NwcConnection, held: {
|
|
377
|
+
paymentHash: string;
|
|
378
|
+
amountMsat: number;
|
|
379
|
+
description: string;
|
|
380
|
+
expirySecs: number;
|
|
381
|
+
minCltvExpiryDelta?: number;
|
|
382
|
+
}, timeoutMs?: number): Promise<NwcInvoice>;
|
|
383
|
+
/**
|
|
384
|
+
* The preimage the wallet released for this hash, null while it has released
|
|
385
|
+
* none. A preimage that does not hash to what was asked for is a lie rather than
|
|
386
|
+
* an answer, so it throws instead of being passed on
|
|
387
|
+
*/
|
|
388
|
+
declare function nwcSettlement(connection: NwcConnection, paymentHash: string, timeoutMs?: number): Promise<string | null>;
|
|
389
|
+
/**
|
|
390
|
+
* Pay an invoice and keep the preimage the network handed back. Whoever pays
|
|
391
|
+
* learns it, which is what makes delivery provable to a recipient publishing no
|
|
392
|
+
* LUD-21 of their own. A preimage that does not hash to the invoice's own hash is
|
|
393
|
+
* a lie rather than a receipt, so it throws instead of being passed on
|
|
394
|
+
*/
|
|
395
|
+
declare function nwcPay(connection: NwcConnection, bolt11: string, timeoutMs?: number): Promise<string>;
|
|
396
|
+
/**
|
|
397
|
+
* A verify endpoint of your own that asks your wallet over NIP-47, so the gateway
|
|
398
|
+
* polls you and never learns the connection, the relay, or which wallet it is.
|
|
399
|
+
*
|
|
400
|
+
* `nwcVerifyUrl` seals the payment hash into the query with your secret, which is
|
|
401
|
+
* what stops a stranger driving your wallet through this handler. It answers the
|
|
402
|
+
* LUD-21 shape the gateway already speaks, so nothing on that side changes.
|
|
403
|
+
*
|
|
404
|
+
* A wallet it cannot reach answers `502` rather than "not settled", because those
|
|
405
|
+
* are different claims and only one of them is true.
|
|
406
|
+
*/
|
|
407
|
+
declare function nwcVerifyEndpoint(config: NwcVerifyConfig): (request: Request) => Promise<Response>;
|
|
408
|
+
/**
|
|
409
|
+
* The URL to hand the gateway, with the payment hash sealed inside it. Point it at
|
|
410
|
+
* wherever `nwcVerifyEndpoint` is mounted
|
|
411
|
+
*/
|
|
412
|
+
declare function nwcVerifyUrl(endpoint: string, paymentHash: string, secret: string): Promise<string>;
|
|
413
|
+
/**
|
|
414
|
+
* One NIP-47 call, for a method this SDK does not wrap. The wallet's own info
|
|
415
|
+
* event lists what it will answer, and anything it refuses comes back as a
|
|
416
|
+
* `WalletRefused` carrying the code it named
|
|
417
|
+
*/
|
|
418
|
+
declare function askWallet(connection: NwcConnection, method: string, params: Record<string, unknown>, timeoutMs?: number): Promise<Record<string, unknown>>;
|
|
419
|
+
|
|
306
420
|
/** What a shop knows about a sale before any rail exists */
|
|
307
421
|
interface Order {
|
|
308
422
|
/** The bank matches it on the statement, and Lightning keys idempotency on it */
|
|
@@ -346,6 +460,8 @@ interface BankRailConfig {
|
|
|
346
460
|
expiresAt: (order: Order) => number;
|
|
347
461
|
/** Groups every leg on the same secret, so one `followTrigger` socket hears them all */
|
|
348
462
|
trigger?: string;
|
|
463
|
+
/** How many settlements of that trigger the gateway keeps replayable past the hour, needs `trigger` */
|
|
464
|
+
replay?: number;
|
|
349
465
|
/** Handed back untouched on that stream. Stable across re-offers, for the reason `expiresAt` is */
|
|
350
466
|
sealed?: (order: Order) => string | Promise<string>;
|
|
351
467
|
/** Up to ten digits, for accounting systems that still want one */
|
|
@@ -365,6 +481,8 @@ interface LightningRailConfig {
|
|
|
365
481
|
amountMsat: (order: Order) => number | Promise<number>;
|
|
366
482
|
/** Groups every leg on the same secret, so one `followTrigger` socket hears them all */
|
|
367
483
|
trigger?: string;
|
|
484
|
+
/** How many settlements of that trigger the gateway keeps replayable past the hour, needs `trigger` */
|
|
485
|
+
replay?: number;
|
|
368
486
|
/**
|
|
369
487
|
* Makes the mint safe to retry. Unset nothing is sent, because a key stable
|
|
370
488
|
* across re-offers is one the gateway can join against the bank leg's reference
|
|
@@ -383,6 +501,8 @@ interface BlindLightningRailConfig {
|
|
|
383
501
|
amountMsat: (order: Order) => number | Promise<number>;
|
|
384
502
|
/** Groups every leg on the same secret, so one `followTrigger` socket hears them all */
|
|
385
503
|
trigger?: string;
|
|
504
|
+
/** How many settlements of that trigger the gateway keeps replayable past the hour, needs `trigger` */
|
|
505
|
+
replay?: number;
|
|
386
506
|
/** Only a watched leg has anywhere to carry this */
|
|
387
507
|
sealed?: (order: Order) => string | Promise<string>;
|
|
388
508
|
webhookUrl?: string;
|
|
@@ -399,6 +519,34 @@ interface BlindLightningRailConfig {
|
|
|
399
519
|
/** What `Leg.rail` reads, for a shop running more than one wallet */
|
|
400
520
|
name?: string;
|
|
401
521
|
}
|
|
522
|
+
interface NwcRailConfig {
|
|
523
|
+
/** The gateway that watches an invoice your own wallet minted */
|
|
524
|
+
gateway: ThunderBridge;
|
|
525
|
+
/** Your wallet over NIP-47, from `nwcConnection`. It never reaches the gateway */
|
|
526
|
+
connection: NwcConnection;
|
|
527
|
+
/** What this order costs in millisatoshi */
|
|
528
|
+
amountMsat: (order: Order) => number | Promise<number>;
|
|
529
|
+
/**
|
|
530
|
+
* Where your own `nwcVerifyEndpoint` is mounted, and the secret it unseals
|
|
531
|
+
* with. The gateway is handed this URL rather than a wallet's, so it polls you
|
|
532
|
+
* and learns neither the connection nor which wallet is behind it
|
|
533
|
+
*/
|
|
534
|
+
verifyThrough: {
|
|
535
|
+
endpoint: string;
|
|
536
|
+
secret: string;
|
|
537
|
+
};
|
|
538
|
+
/** What the payer reads on the invoice, and what your wallet files it under */
|
|
539
|
+
description?: (order: Order) => string;
|
|
540
|
+
/** Groups every leg on the same secret, so one `followTrigger` socket hears them all */
|
|
541
|
+
trigger?: string;
|
|
542
|
+
/** How many settlements of that trigger the gateway keeps replayable past the hour, needs `trigger` */
|
|
543
|
+
replay?: number;
|
|
544
|
+
/** Only a watched leg has anywhere to carry this */
|
|
545
|
+
sealed?: (order: Order) => string | Promise<string>;
|
|
546
|
+
webhookUrl?: string;
|
|
547
|
+
/** What `Leg.rail` reads, for a shop running more than one wallet */
|
|
548
|
+
name?: string;
|
|
549
|
+
}
|
|
402
550
|
/**
|
|
403
551
|
* Sell for a bank transfer. The money moves straight to your account and the
|
|
404
552
|
* gateway is told a hash, a URL and an expiry, never the amount or the reference.
|
|
@@ -420,5 +568,22 @@ declare function lightningRail(config: LightningRailConfig): Rail;
|
|
|
420
568
|
* refusing everyone.
|
|
421
569
|
*/
|
|
422
570
|
declare function blindLightningRail(config: BlindLightningRailConfig): Rail;
|
|
571
|
+
/**
|
|
572
|
+
* Sell for Lightning against a wallet of your own over NIP-47, for a wallet that
|
|
573
|
+
* has no LUD-21 address to be watched at. Your node mints the invoice and releases
|
|
574
|
+
* the preimage, so the proof comes from one hop nearer than any hosted address can
|
|
575
|
+
* manage, and the gateway sees a hash and a URL of yours.
|
|
576
|
+
*/
|
|
577
|
+
declare function nwcRail(config: NwcRailConfig): Rail;
|
|
578
|
+
/**
|
|
579
|
+
* A provable invoice from the first address on the list that will issue one, which
|
|
580
|
+
* is what a client mints for itself rather than asking a gateway to. Everything the
|
|
581
|
+
* gateway needs to watch it comes back with everything you need to prove it came
|
|
582
|
+
* from the address you asked for, so you can hand over the first and keep the second.
|
|
583
|
+
*
|
|
584
|
+
* Server side: it resolves hostnames and refuses a private one, which no browser can
|
|
585
|
+
* do. Throws `NoWalletAvailableError` when no address on the list would serve
|
|
586
|
+
*/
|
|
587
|
+
declare function invoiceFrom(lnAddresses: string[], amountMsat: number): Promise<Resolved>;
|
|
423
588
|
|
|
424
|
-
export { type BankRailConfig as B, type CreatePaymentParams as C, type FollowOptions as F, type Leg as L, type Order as O, type Payment as P, type Quote as Q, type Rail as R, type Settlement as S, ThunderBridge as T, type
|
|
589
|
+
export { nwcSettlement as A, type BankRailConfig as B, type CreatePaymentParams as C, nwcVerifyEndpoint as D, nwcVerifyUrl as E, type FollowOptions as F, 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 WalletReason as j, bankRail as k, lightningRail as l, type BlindLightningRailConfig as m, type NwcInvoice as n, type NwcRailConfig as o, type NwcVerifyConfig as p, type Resolved as q, askWallet as r, blindLightningRail as s, toLnurl as t, invoiceFrom as u, nwcConnection as v, nwcHoldInvoice as w, nwcInvoice as x, nwcPay as y, nwcRail as z };
|