thunder-bridge 1.4.2 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +145 -133
- package/dist/bank-CEIuNhV_.d.cts +896 -0
- package/dist/bank-M8flcMks.d.ts +896 -0
- package/dist/bank.cjs +338 -0
- package/dist/bank.d.cts +46 -0
- package/dist/bank.d.ts +46 -0
- package/dist/bank.js +310 -0
- package/dist/errors-DriqW-lp.d.cts +126 -0
- package/dist/errors-ZEUT-MhO.d.ts +126 -0
- package/dist/index.cjs +2108 -1235
- package/dist/index.d.cts +13 -505
- package/dist/index.d.ts +13 -505
- package/dist/index.js +2088 -1193
- package/dist/{server.cjs → nwc.cjs} +376 -720
- package/dist/nwc.d.cts +122 -0
- package/dist/nwc.d.ts +122 -0
- package/dist/{server.js → nwc.js} +368 -695
- 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 +259 -0
- package/dist/qr.d.cts +1 -0
- package/dist/qr.d.ts +1 -0
- package/dist/qr.js +224 -0
- package/dist/types-DYZ9EkmJ.d.cts +261 -0
- package/dist/types-DYZ9EkmJ.d.ts +261 -0
- package/openapi.yaml +29 -39
- 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/index.d.ts
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export { R as Resolved } from './qr-CF-YeXU1.js';
|
|
2
|
+
import { T as ThunderBridge, g as ThunderBridgeOptions, W as WaitOptions } from './bank-M8flcMks.js';
|
|
3
|
+
export { A as AttendOptions, h as BankRailConfig, d as BankVerifyConfig, i as BlindLightningRailConfig, j as CreateOptions, F as FollowOptions, H as Handler, L as Leg, k as LightningRailConfig, l as LightningVerifyConfig, M as Minted, O as Order, P as PaymentRequest, m as PaymentRequestInit, n as PaymentRequestOptions, o as Provable, p as Proven, f as Rail, R as RailConfig, q as Rails, r as Range, s as Relayed, t as Send, u as Serve, v as TicketOptions, w as TriggerConfig, x as WatchTicketConfig, y as WebhookCredential, z as WebhookHandlers, D as WebhookOptions, E as WrapAllowance, G as answerVerifyChallenge, I as carriesProof, J as invoiceFrom, K as proveOrigin, N as proveSettlement, Q as proveWrapped, U as relayedVerifyUrl, V as wrapFeeCeiling } from './bank-M8flcMks.js';
|
|
4
|
+
import { H as Handover, P as Payment, e as Held } from './types-DYZ9EkmJ.js';
|
|
5
|
+
export { A as Amount, C as Charge, F as FiatOptions, f as MintedPayment, g as Msat, h as PaymentStatus, i as Priced, Q as Quote, S as Settlement, j as SocketTicket, W as WalletFailure, l as WalletReason, n as WatchedPayment, o as fiat, p as msat, s as sats } from './types-DYZ9EkmJ.js';
|
|
6
|
+
export { A as AmountError, a as AmountFault, G as GatewayCheatCode, b as GatewayCheatError, I as IdempotencyConflict, c as IdempotencyConflictError, N as NoWalletAvailableError, P as ProblemError, U as UnverifiedRecipientError, W as WrapRefusalCode, d as WrapRefusedError } from './errors-ZEUT-MhO.js';
|
|
3
7
|
|
|
4
8
|
/** What a BOLT11 invoice says about itself, every field null when it does not carry one */
|
|
5
9
|
interface Invoice {
|
|
6
10
|
paymentHash: string | null;
|
|
7
11
|
descriptionHash: string | null;
|
|
8
12
|
amountMsat: number | null;
|
|
13
|
+
issuedAt: number | null;
|
|
9
14
|
expiresAt: number | null;
|
|
10
15
|
}
|
|
11
16
|
/**
|
|
@@ -21,283 +26,15 @@ declare function preimageMatchesHash(preimage: string, paymentHash: string): boo
|
|
|
21
26
|
* stores the result and hands it back untouched, so anything readable you put
|
|
22
27
|
* in `sealed` is something you told it, which is what blind mode exists to avoid
|
|
23
28
|
*/
|
|
24
|
-
declare function seal(secret: string, plaintext: string): Promise<string>;
|
|
29
|
+
declare function seal(secret: string, plaintext: string, paymentHash?: string): Promise<string>;
|
|
25
30
|
/**
|
|
26
31
|
* Read a sealed blob back, null when it was sealed with another secret, edited
|
|
27
32
|
* on the way, or is not one of ours. A secret too short to be a key throws,
|
|
28
33
|
* because that is your bug rather than someone else's input
|
|
29
34
|
*/
|
|
30
|
-
declare function unseal(secret: string, sealed: string): Promise<string | null>;
|
|
31
|
-
|
|
32
|
-
/** One incoming payment as the bank booked it, in the smallest unit of its currency */
|
|
33
|
-
interface Credit {
|
|
34
|
-
amountMinor: number;
|
|
35
|
-
currency: string;
|
|
36
|
-
/** Whatever the payer wrote, wherever this bank puts it. Matching is a substring, so noise around it is fine */
|
|
37
|
-
reference: string;
|
|
38
|
-
/**
|
|
39
|
-
* Unix seconds. A bank that books a day rather than an instant, as Fio does,
|
|
40
|
-
* gives the day's midnight in its own zone, so rendering this in UTC can show
|
|
41
|
-
* the day before. Nothing here matches on it, it is yours to read
|
|
42
|
-
*/
|
|
43
|
-
bookedAt: number;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Recent credits on one account, oldest or newest first, it makes no difference.
|
|
47
|
-
* This is the whole plugin seam: a bank is a function of this shape, and
|
|
48
|
-
* `fioStatement` is one implementation of it
|
|
49
|
-
*/
|
|
50
|
-
type Statement = (sinceUnix: number) => Promise<Credit[]>;
|
|
51
|
-
interface BankTransferParams {
|
|
52
|
-
/**
|
|
53
|
-
* The gateway that will watch this transfer. It has to be one of your own,
|
|
54
|
-
* meaning one you gave a token, unless `allowPublicGateway` says otherwise
|
|
55
|
-
*/
|
|
56
|
-
gateway: ThunderBridge;
|
|
57
|
-
/** Long lived and server side. The preimage is derived from it, so losing it loses every proof */
|
|
58
|
-
secret: string;
|
|
59
|
-
/** What the payer must leave on the transfer, an order id or a nonce. It is matched, not stored */
|
|
60
|
-
reference: string;
|
|
61
|
-
/** The price in the smallest unit, so 48055 is 480.55 CZK */
|
|
62
|
-
amountMinor: number;
|
|
63
|
-
/** The account the money goes to, as an IBAN */
|
|
64
|
-
iban: string;
|
|
65
|
-
/** Where `bankVerifyEndpoint` is mounted, a public https URL with no query of its own */
|
|
66
|
-
verifyUrl: string;
|
|
67
|
-
/** When the offer dies, in unix seconds. Money in a bank moves on banking days, so give it days */
|
|
68
|
-
expiresAt: number;
|
|
69
|
-
/** Defaults to CZK */
|
|
70
|
-
currency?: string;
|
|
71
|
-
/** Up to ten digits, for accounting systems that still want one */
|
|
72
|
-
variableSymbol?: string;
|
|
73
|
-
/**
|
|
74
|
-
* Groups this transfer with everything else paid to the same secret, so one
|
|
75
|
-
* `followTrigger` socket hears about it. Give the Lightning leg of the same
|
|
76
|
-
* order the same secret and both rails arrive on one stream
|
|
77
|
-
*/
|
|
78
|
-
trigger?: string;
|
|
79
|
-
/** How many settlements of that trigger the gateway keeps replayable past the hour, needs `trigger` */
|
|
80
|
-
replay?: number;
|
|
81
|
-
/**
|
|
82
|
-
* Handed back untouched on that stream, so a watcher learns which order settled
|
|
83
|
-
* without asking anyone. `seal` it and the gateway cannot read it either
|
|
84
|
-
*/
|
|
85
|
-
sealed?: string;
|
|
86
|
-
/**
|
|
87
|
-
* Where the gateway posts once the money lands, a public https URL. Without one
|
|
88
|
-
* a transfer is only ever learned by following the trigger or asking
|
|
89
|
-
*/
|
|
90
|
-
webhookUrl?: string;
|
|
91
|
-
/**
|
|
92
|
-
* Register on a gateway you do not own anyway. The verify URL names the amount
|
|
93
|
-
* and the reference, so its operator ends up reading your order book, and the
|
|
94
|
-
* URL itself answers whether that order was paid. Say true only when the order
|
|
95
|
-
* book is not worth hiding
|
|
96
|
-
*/
|
|
97
|
-
allowPublicGateway?: boolean;
|
|
98
|
-
}
|
|
99
|
-
interface BankTransfer {
|
|
100
|
-
/** The watched payment's id at the gateway, which is how you read this order back */
|
|
101
|
-
id: string;
|
|
102
|
-
/** What the gateway was given, and what the preimage has to hash to */
|
|
103
|
-
paymentHash: string;
|
|
104
|
-
/** The same URL you mounted, carrying what to look for and a signature over it */
|
|
105
|
-
verifyUrl: string;
|
|
106
|
-
/** The payer scans this, it is a Short Payment Descriptor, the Czech QR platba format */
|
|
107
|
-
spd: string;
|
|
108
|
-
}
|
|
109
|
-
interface BankVerifyConfig {
|
|
110
|
-
/** The same secret `bankTransfer` was given */
|
|
111
|
-
secret: string;
|
|
112
|
-
/** The account to read */
|
|
113
|
-
statement: Statement;
|
|
114
|
-
/** How far back a credit still counts, seven days by default */
|
|
115
|
-
lookBackSecs?: number;
|
|
116
|
-
/**
|
|
117
|
-
* How often you want the gateway to ask, in seconds. It goes out as
|
|
118
|
-
* `Cache-Control: max-age`, so the pace is yours to set rather than the
|
|
119
|
-
* gateway's, and a bank that updates once a minute should say so instead of
|
|
120
|
-
* being polled every few seconds. Thirty by default, clamped to an hour
|
|
121
|
-
*/
|
|
122
|
-
pollEverySecs?: number;
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Ask for a bank transfer and put it under the gateway's watch, so it settles
|
|
126
|
-
* the way a Lightning payment does.
|
|
127
|
-
*
|
|
128
|
-
* A BOLT11 payment proves settlement with a preimage whose sha256 the payer's
|
|
129
|
-
* invoice pins. A bank transfer has no such thing, so this mints one: the
|
|
130
|
-
* preimage is an HMAC of what is being asked for, and its hash is what the
|
|
131
|
-
* gateway is given. The money still moves straight to your account, and the
|
|
132
|
-
* gateway still learns only a hash and a URL to poll.
|
|
133
|
-
*
|
|
134
|
-
* What the preimage proves is therefore what LUD-21 proves and no more: that
|
|
135
|
-
* the server holding the secret saw the money arrive. It is the recipient's
|
|
136
|
-
* own word, made unforgeable by anyone else.
|
|
137
|
-
*
|
|
138
|
-
* The gateway has to be one of your own. Unlike a blind Lightning watch, which
|
|
139
|
-
* hands over a hash and an opaque wallet URL, this hands over a URL naming the
|
|
140
|
-
* amount and the reference, so whoever runs the gateway can read your order book
|
|
141
|
-
* from the watches alone.
|
|
142
|
-
*/
|
|
143
|
-
declare function bankTransfer(params: BankTransferParams): Promise<BankTransfer>;
|
|
144
|
-
/**
|
|
145
|
-
* The verify endpoint the gateway polls, as a Fetch handler, so it runs wherever
|
|
146
|
-
* `lnurlPayEndpoint` does.
|
|
147
|
-
*
|
|
148
|
-
* It answers the LUD-21 shape: `settled` false until a matching credit is on the
|
|
149
|
-
* statement, then `settled` true with the preimage. Nothing is stored, because
|
|
150
|
-
* the preimage is derived again from the secret every time it is asked for.
|
|
151
|
-
*
|
|
152
|
-
* The query has to carry the signature `bankTransfer` put there. Without that
|
|
153
|
-
* check this would answer "did anyone send you 480.55 with this note" to whoever
|
|
154
|
-
* asked, which is your bank statement handed out one question at a time.
|
|
155
|
-
*/
|
|
156
|
-
declare function bankVerifyEndpoint(config: BankVerifyConfig): (request: Request) => Promise<Response>;
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* How many digits ISO 4217 gives the currency's minor unit, so 2 for a crown and a
|
|
160
|
-
* euro, 0 for a yen and 3 for a dinar.
|
|
161
|
-
*
|
|
162
|
-
* There is no sane default here, which is why an unlisted code throws rather than
|
|
163
|
-
* being treated as two. Assuming two turns 1000 yen into 10 and a dinar into a
|
|
164
|
-
* tenth of itself, and a payment library that guesses at this is a payment library
|
|
165
|
-
* that moves the wrong amount.
|
|
166
|
-
*/
|
|
167
|
-
declare function minorUnitsOf(currency: string): number;
|
|
168
|
-
/** The scale that minor unit implies, so 100 for a crown, 1 for a yen, 1000 for a dinar */
|
|
169
|
-
declare function minorScaleOf(currency: string): number;
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* The way a gateway was caught out, every code is a check that held against the
|
|
173
|
-
* recipient's own server and failed against what the gateway returned
|
|
174
|
-
*/
|
|
175
|
-
type GatewayCheatCode = "address_not_requested" | "hash_mismatch" | "amount_mismatch" | "description_hash_mismatch" | "verify_url_foreign" | "invoice_not_issued" | "preimage_mismatch" | "id_not_mine";
|
|
176
|
-
/**
|
|
177
|
-
* Thrown when the gateway demonstrably misbehaved, the invoice it returned is
|
|
178
|
-
* not the one the address you asked for issued, or a settlement it reported
|
|
179
|
-
* carries a preimage that does not hash to the payment hash
|
|
180
|
-
*/
|
|
181
|
-
declare class GatewayCheatError extends Error {
|
|
182
|
-
readonly code: GatewayCheatCode;
|
|
183
|
-
readonly paymentId: string;
|
|
184
|
-
constructor(code: GatewayCheatCode, paymentId: string);
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* The way a wrapping operator was caught out. Every code is the wrapped invoice
|
|
188
|
-
* failing to bind to the recipient's own, which is the only thing that makes
|
|
189
|
-
* paying the wrap the same act as paying the recipient
|
|
190
|
-
*/
|
|
191
|
-
type WrapRefusalCode = "undecodable" | "hash_mismatch" | "amount_below_recipient" | "fee_above_allowance" | "recipient_expires_first";
|
|
192
|
-
/**
|
|
193
|
-
* Thrown when a wrapped invoice does not bind to the recipient's. Paying it
|
|
194
|
-
* would be paying the operator on its word rather than on the shared payment
|
|
195
|
-
* hash, which is the whole of what makes wrapping safe
|
|
196
|
-
*/
|
|
197
|
-
declare class WrapRefusedError extends Error {
|
|
198
|
-
readonly code: WrapRefusalCode;
|
|
199
|
-
constructor(code: WrapRefusalCode, detail: string);
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* Thrown when the recipient's own server could not be reached to check the
|
|
203
|
-
* invoice against, a CORS-blocked browser or a provider that is down, this is
|
|
204
|
-
* not proof the gateway cheated and it is not proof it did not
|
|
205
|
-
*/
|
|
206
|
-
declare class UnverifiedRecipientError extends Error {
|
|
207
|
-
readonly lnAddress: string;
|
|
208
|
-
readonly paymentId: string;
|
|
209
|
-
constructor(lnAddress: string, paymentId: string, cause: unknown);
|
|
210
|
-
}
|
|
211
|
-
/** An RFC 9457 problem document the gateway answered with */
|
|
212
|
-
declare class ProblemError extends Error {
|
|
213
|
-
readonly type: string;
|
|
214
|
-
readonly title: string;
|
|
215
|
-
readonly status: number;
|
|
216
|
-
readonly detail: string | null;
|
|
217
|
-
constructor(problem: {
|
|
218
|
-
type?: string;
|
|
219
|
-
title?: string;
|
|
220
|
-
status?: number;
|
|
221
|
-
detail?: string;
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
/** Whether a problem document carries this type */
|
|
225
|
-
declare function isProblemType(problem: {
|
|
226
|
-
type?: string;
|
|
227
|
-
}, type: string): boolean;
|
|
228
|
-
declare const NO_WALLET_AVAILABLE = "urn:problem-type:thunder-bridge:no-wallet-available";
|
|
229
|
-
declare const REQUEST_IN_FLIGHT = "urn:problem-type:thunder-bridge:request-in-flight";
|
|
230
|
-
declare const IDEMPOTENCY_KEY_REUSED = "urn:problem-type:thunder-bridge:idempotency-key-reused";
|
|
231
|
-
declare const PAYMENT_ALREADY_WATCHED = "urn:problem-type:thunder-bridge:payment-already-watched";
|
|
232
|
-
/**
|
|
233
|
-
* Why an `Idempotency-Key` was refused, `request-in-flight` is the benign one and
|
|
234
|
-
* `key-reused` means the same key was sent for a different request
|
|
235
|
-
*/
|
|
236
|
-
type IdempotencyConflict = "request-in-flight" | "key-reused";
|
|
237
|
-
/**
|
|
238
|
-
* Thrown when an `Idempotency-Key` is held by another request. On
|
|
239
|
-
* `request-in-flight` the first attempt is still resolving, so wait and read the
|
|
240
|
-
* payment back rather than retrying. `key-reused` is a bug in the caller: the key
|
|
241
|
-
* is bound to the addresses, amount and webhook that claimed it
|
|
242
|
-
*/
|
|
243
|
-
declare class IdempotencyConflictError extends ProblemError {
|
|
244
|
-
readonly conflict: IdempotencyConflict;
|
|
245
|
-
constructor(problem: {
|
|
246
|
-
type?: string;
|
|
247
|
-
title?: string;
|
|
248
|
-
status?: number;
|
|
249
|
-
detail?: string;
|
|
250
|
-
}, conflict: IdempotencyConflict);
|
|
251
|
-
}
|
|
252
|
-
/** Thrown when no wallet on your list could issue a provable invoice, `wallets` says why each refused */
|
|
253
|
-
declare class NoWalletAvailableError extends ProblemError {
|
|
254
|
-
readonly wallets: WalletFailure[];
|
|
255
|
-
constructor(problem: {
|
|
256
|
-
title?: string;
|
|
257
|
-
status?: number;
|
|
258
|
-
detail?: string;
|
|
259
|
-
}, wallets: WalletFailure[]);
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
interface FioConfig {
|
|
263
|
-
/**
|
|
264
|
-
* A token with "Sledování účtu" rights, which is read only and cannot move
|
|
265
|
-
* money. One token is one account, which is why this takes no account number.
|
|
266
|
-
*
|
|
267
|
-
* Give it several and they are used in turn. Fio's window is per token rather
|
|
268
|
-
* than per account, so five tokens on one account is a read every six seconds,
|
|
269
|
-
* and generating another token for the same account is what Fio's own
|
|
270
|
-
* documentation suggests when one is not enough
|
|
271
|
-
*/
|
|
272
|
-
token: string | string[];
|
|
273
|
-
/**
|
|
274
|
-
* Fio's window for one token, 30 seconds. No token is ever asked twice inside
|
|
275
|
-
* it, and the gap between reads is this divided by however many tokens were
|
|
276
|
-
* given, so the answers stay evenly spaced rather than arriving in bursts.
|
|
277
|
-
* Inside that gap the last answer is handed back. Only helps a process that
|
|
278
|
-
* stays up
|
|
279
|
-
*/
|
|
280
|
-
minIntervalSecs?: number;
|
|
281
|
-
/** Override to point at a mock */
|
|
282
|
-
baseUrl?: string;
|
|
283
|
-
}
|
|
284
|
-
/**
|
|
285
|
-
* Read one Fio account as a `Statement`, so a bank transfer proves itself the
|
|
286
|
-
* way a Lightning payment does.
|
|
287
|
-
*
|
|
288
|
-
* The token is the read only kind, generated in internetbanking under Nastavení
|
|
289
|
-
* and API, and it is the whole configuration: a token belongs to one account, so
|
|
290
|
-
* there is no account number to get wrong. It cannot pay anyone, and the worst a
|
|
291
|
-
* leaked one costs you is that someone else can read the statement.
|
|
292
|
-
*
|
|
293
|
-
* Every field on a Fio transaction is optional and arrives as `null` when it is
|
|
294
|
-
* absent, the amount carries its direction in its sign rather than in a flag,
|
|
295
|
-
* and the date is a day and a UTC offset, `2026-07-15+0200`. This reads all
|
|
296
|
-
* three the way the bank answers them and treats a missing field as absent
|
|
297
|
-
* rather than guessing.
|
|
298
|
-
*/
|
|
299
|
-
declare function fioStatement(config: FioConfig): Statement;
|
|
35
|
+
declare function unseal(secret: string, sealed: string, paymentHash?: string): Promise<string | null>;
|
|
300
36
|
|
|
37
|
+
/** The client's own options, plus what to do about a gateway that will not take the watch */
|
|
301
38
|
interface GatewaysOptions extends ThunderBridgeOptions {
|
|
302
39
|
/**
|
|
303
40
|
* Called for each gateway that would not take the watch, with the url and what
|
|
@@ -328,243 +65,14 @@ declare class Gateways {
|
|
|
328
65
|
* carrying the first refusal, because one gateway that agreed is enough to be
|
|
329
66
|
* watched
|
|
330
67
|
*/
|
|
331
|
-
|
|
68
|
+
watch(handover: Handover): Promise<Payment>;
|
|
332
69
|
/**
|
|
333
70
|
* Wait for whichever gateway speaks first. A settlement from any of them is the
|
|
334
71
|
* settlement, and each has already proved the preimage against the hash before
|
|
335
72
|
* saying so. When they all end without a payment, the first ending is the answer,
|
|
336
73
|
* and when they all fail, the first failure is thrown
|
|
337
74
|
*/
|
|
338
|
-
|
|
75
|
+
settled(held: Held, options?: WaitOptions): Promise<Payment>;
|
|
339
76
|
}
|
|
340
77
|
|
|
341
|
-
|
|
342
|
-
* How many minor units of `currency` one bitcoin costs at one venue, so 134883815
|
|
343
|
-
* is 1,348,838.15 CZK. Throws when that venue does not quote that currency, which
|
|
344
|
-
* is a normal answer rather than a fault: Kraken and Bitstamp have no CZK pair
|
|
345
|
-
*
|
|
346
|
-
* This is the plugin seam for prices. Another venue is another function of this
|
|
347
|
-
* shape
|
|
348
|
-
*/
|
|
349
|
-
type Ticker = (currency: string) => Promise<number>;
|
|
350
|
-
interface MedianOptions {
|
|
351
|
-
/**
|
|
352
|
-
* How many venues have to answer before a price is usable. Two is the floor
|
|
353
|
-
* worth having, because one venue is a number nobody checked
|
|
354
|
-
*/
|
|
355
|
-
minVenues?: number;
|
|
356
|
-
/**
|
|
357
|
-
* Refuse the lot when the cheapest and dearest answers are further apart than
|
|
358
|
-
* this many basis points. Venues normally sit inside 50, so a wider spread means
|
|
359
|
-
* one of them is broken or stale rather than that the market moved
|
|
360
|
-
*/
|
|
361
|
-
maxSpreadBps?: number;
|
|
362
|
-
/** Hold the last answer this long per currency, so an order page is not four requests */
|
|
363
|
-
holdForSecs?: number;
|
|
364
|
-
}
|
|
365
|
-
/** Coinbase, CASP authorised in Luxembourg. Quotes CZK, EUR and most fiat */
|
|
366
|
-
declare function coinbase(baseUrl?: string): Ticker;
|
|
367
|
-
/** Kraken, CASP authorised by the Central Bank of Ireland. Quotes EUR and USD, no CZK */
|
|
368
|
-
declare function kraken(baseUrl?: string): Ticker;
|
|
369
|
-
/**
|
|
370
|
-
* Bitstamp, CASP authorised by the CSSF in Luxembourg. Quotes EUR and USD, no CZK.
|
|
371
|
-
*
|
|
372
|
-
* An unknown pair is answered with a `200` and the whole ticker list, whose first
|
|
373
|
-
* entry is BTC/USD, so asking it for CZK and reading the number would quote a
|
|
374
|
-
* bitcoin at 64,000 crowns. Anything but a single object is therefore refused
|
|
375
|
-
*/
|
|
376
|
-
declare function bitstamp(baseUrl?: string): Ticker;
|
|
377
|
-
/** Coinmate, on the ESMA CASP register, Czech and the one with a real BTC/CZK book */
|
|
378
|
-
declare function coinmate(baseUrl?: string): Ticker;
|
|
379
|
-
/**
|
|
380
|
-
* Ask several venues and take the middle answer, refusing the lot when they
|
|
381
|
-
* disagree too much.
|
|
382
|
-
*
|
|
383
|
-
* The default is the four MiCA authorised venues below, and every one of them is
|
|
384
|
-
* replaceable: pass your own list, or one venue, or a function that reads a price
|
|
385
|
-
* you already have. A venue that does not quote the currency is skipped rather
|
|
386
|
-
* than fatal, which for CZK leaves Coinbase and Coinmate.
|
|
387
|
-
*
|
|
388
|
-
* The middle is taken rather than the mean so one stuck venue moves the answer by
|
|
389
|
-
* nothing instead of by half its error, and the spread check is what catches the
|
|
390
|
-
* stuck venue that stays inside the pack.
|
|
391
|
-
*/
|
|
392
|
-
declare function medianOf(tickers?: Ticker[], options?: MedianOptions): Ticker;
|
|
393
|
-
/**
|
|
394
|
-
* What to ask for over Lightning for a price named in fiat, in millisatoshi.
|
|
395
|
-
*
|
|
396
|
-
* `priceMinorPerBtc` is what a `Ticker` returns. The arithmetic is exact, in
|
|
397
|
-
* BigInt, because a million crown order times a hundred billion millisatoshi
|
|
398
|
-
* leaves what a double can count, and it rounds up, because the extra
|
|
399
|
-
* millisatoshi is worth nothing and belongs to the recipient rather than to a
|
|
400
|
-
* rounding rule.
|
|
401
|
-
*
|
|
402
|
-
* `spreadBps` is yours to set, in basis points, and defaults to none. A Lightning
|
|
403
|
-
* invoice lives an hour and a bank transfer takes days, so a shop pricing in fiat is
|
|
404
|
-
* carrying that volatility whether or not it charges for it
|
|
405
|
-
*/
|
|
406
|
-
declare function msatFor(amountMinor: number, priceMinorPerBtc: number, options?: {
|
|
407
|
-
spreadBps?: number;
|
|
408
|
-
}): number;
|
|
409
|
-
|
|
410
|
-
interface QrOptions {
|
|
411
|
-
/** SVG width and height in pixels, defaults to 256 */
|
|
412
|
-
size?: number;
|
|
413
|
-
/** Dark module color, defaults to `#000` */
|
|
414
|
-
color?: string;
|
|
415
|
-
}
|
|
416
|
-
/** Render a BOLT11 invoice or a lightning address as an SVG QR code */
|
|
417
|
-
declare function invoiceToSvg(destination: string, options?: QrOptions): string;
|
|
418
|
-
/** SVG data URL for an `<img>` `src` */
|
|
419
|
-
declare function invoiceToDataUrl(destination: string, options?: QrOptions): string;
|
|
420
|
-
/**
|
|
421
|
-
* Render your own LNURL-pay endpoint, the URL `lnurlPayEndpoint` is mounted on,
|
|
422
|
-
* as the QR a payer scans. Nothing is minted and nothing expires, so this is the
|
|
423
|
-
* code a tip jar prints once and an overlay shows all stream
|
|
424
|
-
*/
|
|
425
|
-
declare function lnurlToSvg(endpoint: string, options?: QrOptions): string;
|
|
426
|
-
/** SVG data URL of the endpoint's QR, for an `<img>` `src` */
|
|
427
|
-
declare function lnurlToDataUrl(endpoint: string, options?: QrOptions): string;
|
|
428
|
-
/**
|
|
429
|
-
* Render the `spd` from `bankTransfer` as the QR a Czech banking app scans. The
|
|
430
|
-
* payload is a Short Payment Descriptor, so it carries the account, the amount
|
|
431
|
-
* and the reference the payer must leave on the transfer
|
|
432
|
-
*/
|
|
433
|
-
declare function spdToSvg(spd: string, options?: QrOptions): string;
|
|
434
|
-
/** SVG data URL of the bank transfer's QR, for an `<img>` `src` */
|
|
435
|
-
declare function spdToDataUrl(spd: string, options?: QrOptions): string;
|
|
436
|
-
/**
|
|
437
|
-
* Render any rail's `Leg.qr` as an SVG QR code. Each rail states its own payload,
|
|
438
|
-
* a BOLT11 invoice under the `LIGHTNING` scheme or a Short Payment Descriptor as
|
|
439
|
-
* it stands, so this draws a leg without being told which rail made it
|
|
440
|
-
*/
|
|
441
|
-
declare function qrToSvg(payload: string, options?: QrOptions): string;
|
|
442
|
-
/** SVG data URL of a leg's QR, for an `<img>` `src` */
|
|
443
|
-
declare function qrToDataUrl(payload: string, options?: QrOptions): string;
|
|
444
|
-
|
|
445
|
-
/**
|
|
446
|
-
* What a wrapping operator may charge over the recipient's own amount. This is a
|
|
447
|
-
* ceiling the client sets rather than a price the operator names, so it sits
|
|
448
|
-
* above what any operator lists and refuses only the ones reaching past it
|
|
449
|
-
*/
|
|
450
|
-
interface WrapAllowance {
|
|
451
|
-
/** As a fraction of the recipient's amount, `0.01` by default */
|
|
452
|
-
proportion?: number;
|
|
453
|
-
/** The floor in millisatoshi whatever the fraction works out to, `1000` by default */
|
|
454
|
-
baseMsat?: number;
|
|
455
|
-
}
|
|
456
|
-
/**
|
|
457
|
-
* Prove the invoice really is the one the recipient issued for what you asked,
|
|
458
|
-
* before the payer ever sees it, both fetches go straight to the recipient's own
|
|
459
|
-
* server and none of them goes back to the gateway
|
|
460
|
-
*
|
|
461
|
-
* Throws `GatewayCheatError` when a check fails and `UnverifiedRecipientError`
|
|
462
|
-
* when the recipient could not be reached to run one
|
|
463
|
-
*/
|
|
464
|
-
declare function proveOrigin(payment: Payment, request: CreatePaymentParams): Promise<void>;
|
|
465
|
-
/**
|
|
466
|
-
* Prove the money arrived by asking the recipient's own server, not the gateway,
|
|
467
|
-
* returns the preimage when the recipient says it settled and null when it says
|
|
468
|
-
* it has not, and runs the full origin proof first because a verify url the
|
|
469
|
-
* gateway made up would otherwise answer for itself
|
|
470
|
-
*/
|
|
471
|
-
declare function proveSettlement(payment: Payment, request: CreatePaymentParams): Promise<string | null>;
|
|
472
|
-
/**
|
|
473
|
-
* True when the gateway's own report of a settlement is at least self-consistent,
|
|
474
|
-
* the preimage hashes to the payment hash the invoice itself carries, this is a
|
|
475
|
-
* sanity check and not a proof, only `proveSettlement` asks the recipient
|
|
476
|
-
*/
|
|
477
|
-
declare function isProvablyPaid(payment: Payment): boolean;
|
|
478
|
-
/**
|
|
479
|
-
* The most an operator may add over the recipient's own amount, in millisatoshi.
|
|
480
|
-
* The proportion is what routing and the liquidity behind it costs, and the base
|
|
481
|
-
* is the floor it never drops below, because a fraction of a small payment
|
|
482
|
-
* rounds to nothing the operator can work for
|
|
483
|
-
*/
|
|
484
|
-
declare function wrapFeeCeiling(amountMsat: number, allowance?: WrapAllowance): number;
|
|
485
|
-
/**
|
|
486
|
-
* Prove a wrapping operator's invoice is the recipient's own payment in
|
|
487
|
-
* disguise, so paying it can only settle by the operator paying the recipient.
|
|
488
|
-
*
|
|
489
|
-
* It compares two invoices and asks nobody anything, so it runs in a browser and
|
|
490
|
-
* costs no round trip. Prove the recipient's own invoice with `proveOrigin`
|
|
491
|
-
* first, because this says nothing about where that one came from.
|
|
492
|
-
*
|
|
493
|
-
* There is no settlement check here and there does not need to be. Both invoices
|
|
494
|
-
* carry one payment hash, so the preimage that settles the wrap is the preimage
|
|
495
|
-
* the recipient released, and `proveSettlement` already reads it from the
|
|
496
|
-
* recipient's own server.
|
|
497
|
-
*
|
|
498
|
-
* Throws `WrapRefusedError` naming which binding failed
|
|
499
|
-
*/
|
|
500
|
-
declare function proveWrapped(wrapped: string, recipient: string, allowance?: WrapAllowance): void;
|
|
501
|
-
|
|
502
|
-
/** How far the gateway's clock may drift from yours before a webhook is refused */
|
|
503
|
-
type WebhookOptions = {
|
|
504
|
-
toleranceSecs?: number;
|
|
505
|
-
};
|
|
506
|
-
/**
|
|
507
|
-
* What checks a delivery: the hex the gateway publishes at `/webhook-key`. There
|
|
508
|
-
* is no shared secret to register, so a gateway holds nothing of yours. Rotating
|
|
509
|
-
* its cluster key rotates this too, so a signature that stops verifying is a
|
|
510
|
-
* reason to read the key again before it is a reason to distrust the gateway
|
|
511
|
-
*/
|
|
512
|
-
type WebhookCredential = {
|
|
513
|
-
publicKey: string;
|
|
514
|
-
};
|
|
515
|
-
/** Verify the `X-Signature` header against the raw body and the `X-Timestamp` that came with it */
|
|
516
|
-
declare function verifyWebhookSignature(body: string | Uint8Array, signature: string, credential: WebhookCredential, timestamp: string, options?: WebhookOptions): Promise<boolean>;
|
|
517
|
-
/** Verify and parse in one step, returns null on a bad signature or a body that is not a payment */
|
|
518
|
-
declare function parseWebhook(body: string | Uint8Array, signature: string, credential: WebhookCredential, timestamp: string, options?: WebhookOptions): Promise<Payment | null>;
|
|
519
|
-
/**
|
|
520
|
-
* Verify and parse from a Fetch API `Request` as used by Hono, Next, SvelteKit,
|
|
521
|
-
* Cloudflare Workers and Deno, WebCrypto only so it runs anywhere fetch does
|
|
522
|
-
*/
|
|
523
|
-
declare function parseWebhookRequest(request: Request, credential: WebhookCredential, options?: WebhookOptions): Promise<Payment | null>;
|
|
524
|
-
/**
|
|
525
|
-
* The same, for a payment the gateway only watched. A bank transfer and a blind
|
|
526
|
-
* Lightning leg carry no address, amount or invoice, so they arrive in the shape
|
|
527
|
-
* `followTrigger` and `getWatched` hand back rather than the minted one
|
|
528
|
-
*/
|
|
529
|
-
declare function parseWatchedWebhook(body: string | Uint8Array, signature: string, credential: WebhookCredential, timestamp: string, options?: WebhookOptions): Promise<TriggerEvent | null>;
|
|
530
|
-
/** `parseWatchedWebhook` from a Fetch API `Request`, the way `parseWebhookRequest` is */
|
|
531
|
-
declare function parseWatchedWebhookRequest(request: Request, credential: WebhookCredential, options?: WebhookOptions): Promise<TriggerEvent | null>;
|
|
532
|
-
/**
|
|
533
|
-
* Verify a delivery and read the settlement out of it. Null on a bad signature or
|
|
534
|
-
* on a body that is not a settlement, so a handler that gets null did not just
|
|
535
|
-
* miss a payment, it was handed something it had no reason to believe
|
|
536
|
-
*/
|
|
537
|
-
declare function parseSettlement(body: string | Uint8Array, signature: string, credential: WebhookCredential, timestamp: string, options?: WebhookOptions): Promise<Settlement | null>;
|
|
538
|
-
/** {@link parseSettlement} from a Fetch API `Request` */
|
|
539
|
-
declare function parseSettlementRequest(request: Request, credential: WebhookCredential, options?: WebhookOptions): Promise<Settlement | null>;
|
|
540
|
-
/**
|
|
541
|
-
* Whether a delivery proves what it claims, which is the only question that
|
|
542
|
-
* matters about one: it says paid and it carries a preimage that hashes to the
|
|
543
|
-
* payment hash the delivery itself names
|
|
544
|
-
*/
|
|
545
|
-
declare function isProvablySettled(settled: Settlement): boolean;
|
|
546
|
-
/**
|
|
547
|
-
* Answer the one challenge the gateway sends before it will watch a payment your
|
|
548
|
-
* webhook is registered on. Returns the body to send back with a 200, or null when
|
|
549
|
-
* this delivery is not a challenge, so a handler tries this first and then parses
|
|
550
|
-
*/
|
|
551
|
-
declare function answerWebhookChallenge(body: string | Uint8Array, signature: string, credential: WebhookCredential, timestamp: string, options?: WebhookOptions): Promise<string | null>;
|
|
552
|
-
/**
|
|
553
|
-
* `answerWebhookChallenge` from a Fetch API `Request`, leaving the body unread so
|
|
554
|
-
* the same handler can go on to `parseWebhookRequest` when this was no challenge
|
|
555
|
-
*/
|
|
556
|
-
declare function answerWebhookChallengeRequest(request: Request, credential: WebhookCredential, options?: WebhookOptions): Promise<Response | null>;
|
|
557
|
-
/**
|
|
558
|
-
* Answer the challenge the gateway sends a verify URL before it will poll it,
|
|
559
|
-
* which is how a caller shows the endpoint agreed to the traffic rather than
|
|
560
|
-
* merely being named. Returns null for anything that is not a challenge, so a
|
|
561
|
-
* verify endpoint hands the request on to its own reading of a payment.
|
|
562
|
-
*
|
|
563
|
-
* The nonce is echoed to whoever asked, which grants them nothing, so there is
|
|
564
|
-
* no signature to check here and no secret to hold
|
|
565
|
-
*/
|
|
566
|
-
declare function answerVerifyChallenge(body: string): string | null;
|
|
567
|
-
/** {@link answerVerifyChallenge} against a `Request`, leaving its body unread */
|
|
568
|
-
declare function answerVerifyChallengeRequest(request: Request): Promise<Response | null>;
|
|
569
|
-
|
|
570
|
-
export { type BankTransfer, type BankTransferParams, type BankVerifyConfig, CreatePaymentParams, type Credit, type FioConfig, type GatewayCheatCode, GatewayCheatError, Gateways, type GatewaysOptions, IDEMPOTENCY_KEY_REUSED, type IdempotencyConflict, IdempotencyConflictError, type Invoice, type MedianOptions, NO_WALLET_AVAILABLE, NoWalletAvailableError, PAYMENT_ALREADY_WATCHED, Payment, ProblemError, type QrOptions, REQUEST_IN_FLIGHT, Settlement, type Statement, ThunderBridge, ThunderBridgeOptions, type Ticker, TriggerEvent, UnverifiedRecipientError, WaitOptions, WalletFailure, WatchPaymentParams, type WebhookCredential, type WebhookOptions, type WrapAllowance, type WrapRefusalCode, WrapRefusedError, answerVerifyChallenge, answerVerifyChallengeRequest, answerWebhookChallenge, answerWebhookChallengeRequest, bankTransfer, bankVerifyEndpoint, bitstamp, coinbase, coinmate, decodeInvoice, fioStatement, invoiceToDataUrl, invoiceToSvg, isProblemType, isProvablyPaid, isProvablySettled, kraken, lnurlToDataUrl, lnurlToSvg, medianOf, minorScaleOf, minorUnitsOf, msatFor, parseSettlement, parseSettlementRequest, parseWatchedWebhook, parseWatchedWebhookRequest, parseWebhook, parseWebhookRequest, preimageMatchesHash, proveOrigin, proveSettlement, proveWrapped, qrToDataUrl, qrToSvg, seal, spdToDataUrl, spdToSvg, unseal, verifyWebhookSignature, wrapFeeCeiling };
|
|
78
|
+
export { Gateways, type GatewaysOptions, Handover, Held, type Invoice, Payment, ThunderBridge, ThunderBridgeOptions, WaitOptions, decodeInvoice, preimageMatchesHash, seal, unseal };
|