thunder-bridge 1.4.2 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,126 @@
1
+ import { W as WalletFailure } from './types-BNPmVnA7.js';
2
+
3
+ /**
4
+ * Why an amount was refused. A code rather than a message, because a caller can
5
+ * only recover from a failure it can name and a message is free to be reworded
6
+ */
7
+ type AmountFault = "not-whole-satoshi" | "not-whole-millisatoshi" | "not-a-decimal" | "too-precise" | "unknown-currency";
8
+ /**
9
+ * Thrown when a price cannot be held exactly. Every constructor of an amount
10
+ * throws this rather than returning something approximate, because a payment
11
+ * library that rounds silently moves the wrong money
12
+ */
13
+ declare class AmountError extends Error {
14
+ /**
15
+ * Whether a failure is one of these, without asking whether it is this exact
16
+ * class. Every entry point carries its own copy of the class, so a price
17
+ * refused inside `thunder-bridge/price` is not `instanceof` the `AmountError`
18
+ * imported from `thunder-bridge`. The name and the code are the same in every
19
+ * copy, so this holds where `instanceof` does not
20
+ */
21
+ static is(failure: unknown): failure is AmountError;
22
+ readonly code: AmountFault;
23
+ constructor(code: AmountFault, detail: string);
24
+ }
25
+ /**
26
+ * The way a gateway was caught out, every code is a check that held against the
27
+ * recipient's own server and failed against what the gateway returned
28
+ */
29
+ type GatewayCheatCode = "address_not_requested" | "hash_mismatch" | "amount_mismatch" | "description_hash_mismatch" | "verify_url_foreign" | "invoice_not_issued" | "preimage_mismatch" | "id_not_mine";
30
+ /**
31
+ * Thrown when the gateway demonstrably misbehaved, the invoice it returned is
32
+ * not the one the address you asked for issued, or a settlement it reported
33
+ * carries a preimage that does not hash to the payment hash
34
+ */
35
+ declare class GatewayCheatError extends Error {
36
+ readonly code: GatewayCheatCode;
37
+ readonly paymentId: string;
38
+ constructor(code: GatewayCheatCode, paymentId: string);
39
+ }
40
+ /**
41
+ * The way a wrapping operator was caught out. Every code is the wrapped invoice
42
+ * failing to bind to the recipient's own, which is the only thing that makes
43
+ * paying the wrap the same act as paying the recipient
44
+ */
45
+ type WrapRefusalCode = "undecodable" | "hash_mismatch" | "amount_below_recipient" | "fee_above_allowance" | "recipient_expires_first";
46
+ /**
47
+ * Thrown when a wrapped invoice does not bind to the recipient's. Paying it
48
+ * would be paying the operator on its word rather than on the shared payment
49
+ * hash, which is the whole of what makes wrapping safe
50
+ */
51
+ declare class WrapRefusedError extends Error {
52
+ readonly code: WrapRefusalCode;
53
+ constructor(code: WrapRefusalCode, detail: string);
54
+ }
55
+ /**
56
+ * Thrown when the recipient's own server could not be reached to check the
57
+ * invoice against, a CORS-blocked browser or a provider that is down, this is
58
+ * not proof the gateway cheated and it is not proof it did not
59
+ */
60
+ declare class UnverifiedRecipientError extends Error {
61
+ readonly lnAddress: string;
62
+ readonly paymentId: string;
63
+ constructor(lnAddress: string, paymentId: string, cause: unknown);
64
+ }
65
+ /** An RFC 9457 problem document the gateway answered with */
66
+ declare class ProblemError extends Error {
67
+ static readonly NO_WALLET_AVAILABLE = "urn:problem-type:thunder-bridge:no-wallet-available";
68
+ static readonly REQUEST_IN_FLIGHT = "urn:problem-type:thunder-bridge:request-in-flight";
69
+ static readonly IDEMPOTENCY_KEY_REUSED = "urn:problem-type:thunder-bridge:idempotency-key-reused";
70
+ static readonly PAYMENT_ALREADY_WATCHED = "urn:problem-type:thunder-bridge:payment-already-watched";
71
+ static readonly INVALID_REQUEST = "urn:problem-type:thunder-bridge:invalid-request";
72
+ static readonly CALLER_UNKNOWN = "urn:problem-type:thunder-bridge:caller-unknown";
73
+ static readonly VERIFY_HOST_REFUSED = "urn:problem-type:thunder-bridge:verify-host-refused";
74
+ static readonly VERIFY_UNCONFIRMED = "urn:problem-type:thunder-bridge:verify-unconfirmed";
75
+ static readonly VERIFY_UNCONSENTED = "urn:problem-type:thunder-bridge:verify-unconsented";
76
+ static readonly WEBHOOK_UNCONFIRMED = "urn:problem-type:thunder-bridge:webhook-unconfirmed";
77
+ static readonly TOO_MANY_PENDING = "urn:problem-type:thunder-bridge:too-many-pending";
78
+ /**
79
+ * Whether a problem carries this type. Branch on the type, never on the prose,
80
+ * and reach for `instanceof` first: every type this SDK gives a class to has one
81
+ */
82
+ static is(problem: {
83
+ type?: string;
84
+ }, type: string): boolean;
85
+ readonly type: string;
86
+ readonly title: string;
87
+ readonly status: number;
88
+ readonly detail: string | null;
89
+ constructor(problem: {
90
+ type?: string;
91
+ title?: string;
92
+ status?: number;
93
+ detail?: string;
94
+ });
95
+ }
96
+ /**
97
+ * Why an `Idempotency-Key` was refused, `request-in-flight` is the benign one and
98
+ * `key-reused` means the same key was sent for a different request
99
+ */
100
+ type IdempotencyConflict = "request-in-flight" | "key-reused";
101
+ /**
102
+ * Thrown when an `Idempotency-Key` is held by another request. On
103
+ * `request-in-flight` the first attempt is still resolving, so wait and read the
104
+ * payment back rather than retrying. `key-reused` is a bug in the caller: the key
105
+ * is bound to the addresses, amount and webhook that claimed it
106
+ */
107
+ declare class IdempotencyConflictError extends ProblemError {
108
+ readonly conflict: IdempotencyConflict;
109
+ constructor(problem: {
110
+ type?: string;
111
+ title?: string;
112
+ status?: number;
113
+ detail?: string;
114
+ }, conflict: IdempotencyConflict);
115
+ }
116
+ /** Thrown when no wallet on your list could issue a provable invoice, `wallets` says why each refused */
117
+ declare class NoWalletAvailableError extends ProblemError {
118
+ readonly wallets: WalletFailure[];
119
+ constructor(problem: {
120
+ title?: string;
121
+ status?: number;
122
+ detail?: string;
123
+ }, wallets: WalletFailure[]);
124
+ }
125
+
126
+ export { AmountError as A, type GatewayCheatCode as G, type IdempotencyConflict as I, NoWalletAvailableError as N, ProblemError as P, UnverifiedRecipientError as U, type WrapRefusalCode as W, type AmountFault as a, GatewayCheatError as b, IdempotencyConflictError as c, WrapRefusedError as d };
@@ -0,0 +1,126 @@
1
+ import { W as WalletFailure } from './types-BNPmVnA7.cjs';
2
+
3
+ /**
4
+ * Why an amount was refused. A code rather than a message, because a caller can
5
+ * only recover from a failure it can name and a message is free to be reworded
6
+ */
7
+ type AmountFault = "not-whole-satoshi" | "not-whole-millisatoshi" | "not-a-decimal" | "too-precise" | "unknown-currency";
8
+ /**
9
+ * Thrown when a price cannot be held exactly. Every constructor of an amount
10
+ * throws this rather than returning something approximate, because a payment
11
+ * library that rounds silently moves the wrong money
12
+ */
13
+ declare class AmountError extends Error {
14
+ /**
15
+ * Whether a failure is one of these, without asking whether it is this exact
16
+ * class. Every entry point carries its own copy of the class, so a price
17
+ * refused inside `thunder-bridge/price` is not `instanceof` the `AmountError`
18
+ * imported from `thunder-bridge`. The name and the code are the same in every
19
+ * copy, so this holds where `instanceof` does not
20
+ */
21
+ static is(failure: unknown): failure is AmountError;
22
+ readonly code: AmountFault;
23
+ constructor(code: AmountFault, detail: string);
24
+ }
25
+ /**
26
+ * The way a gateway was caught out, every code is a check that held against the
27
+ * recipient's own server and failed against what the gateway returned
28
+ */
29
+ type GatewayCheatCode = "address_not_requested" | "hash_mismatch" | "amount_mismatch" | "description_hash_mismatch" | "verify_url_foreign" | "invoice_not_issued" | "preimage_mismatch" | "id_not_mine";
30
+ /**
31
+ * Thrown when the gateway demonstrably misbehaved, the invoice it returned is
32
+ * not the one the address you asked for issued, or a settlement it reported
33
+ * carries a preimage that does not hash to the payment hash
34
+ */
35
+ declare class GatewayCheatError extends Error {
36
+ readonly code: GatewayCheatCode;
37
+ readonly paymentId: string;
38
+ constructor(code: GatewayCheatCode, paymentId: string);
39
+ }
40
+ /**
41
+ * The way a wrapping operator was caught out. Every code is the wrapped invoice
42
+ * failing to bind to the recipient's own, which is the only thing that makes
43
+ * paying the wrap the same act as paying the recipient
44
+ */
45
+ type WrapRefusalCode = "undecodable" | "hash_mismatch" | "amount_below_recipient" | "fee_above_allowance" | "recipient_expires_first";
46
+ /**
47
+ * Thrown when a wrapped invoice does not bind to the recipient's. Paying it
48
+ * would be paying the operator on its word rather than on the shared payment
49
+ * hash, which is the whole of what makes wrapping safe
50
+ */
51
+ declare class WrapRefusedError extends Error {
52
+ readonly code: WrapRefusalCode;
53
+ constructor(code: WrapRefusalCode, detail: string);
54
+ }
55
+ /**
56
+ * Thrown when the recipient's own server could not be reached to check the
57
+ * invoice against, a CORS-blocked browser or a provider that is down, this is
58
+ * not proof the gateway cheated and it is not proof it did not
59
+ */
60
+ declare class UnverifiedRecipientError extends Error {
61
+ readonly lnAddress: string;
62
+ readonly paymentId: string;
63
+ constructor(lnAddress: string, paymentId: string, cause: unknown);
64
+ }
65
+ /** An RFC 9457 problem document the gateway answered with */
66
+ declare class ProblemError extends Error {
67
+ static readonly NO_WALLET_AVAILABLE = "urn:problem-type:thunder-bridge:no-wallet-available";
68
+ static readonly REQUEST_IN_FLIGHT = "urn:problem-type:thunder-bridge:request-in-flight";
69
+ static readonly IDEMPOTENCY_KEY_REUSED = "urn:problem-type:thunder-bridge:idempotency-key-reused";
70
+ static readonly PAYMENT_ALREADY_WATCHED = "urn:problem-type:thunder-bridge:payment-already-watched";
71
+ static readonly INVALID_REQUEST = "urn:problem-type:thunder-bridge:invalid-request";
72
+ static readonly CALLER_UNKNOWN = "urn:problem-type:thunder-bridge:caller-unknown";
73
+ static readonly VERIFY_HOST_REFUSED = "urn:problem-type:thunder-bridge:verify-host-refused";
74
+ static readonly VERIFY_UNCONFIRMED = "urn:problem-type:thunder-bridge:verify-unconfirmed";
75
+ static readonly VERIFY_UNCONSENTED = "urn:problem-type:thunder-bridge:verify-unconsented";
76
+ static readonly WEBHOOK_UNCONFIRMED = "urn:problem-type:thunder-bridge:webhook-unconfirmed";
77
+ static readonly TOO_MANY_PENDING = "urn:problem-type:thunder-bridge:too-many-pending";
78
+ /**
79
+ * Whether a problem carries this type. Branch on the type, never on the prose,
80
+ * and reach for `instanceof` first: every type this SDK gives a class to has one
81
+ */
82
+ static is(problem: {
83
+ type?: string;
84
+ }, type: string): boolean;
85
+ readonly type: string;
86
+ readonly title: string;
87
+ readonly status: number;
88
+ readonly detail: string | null;
89
+ constructor(problem: {
90
+ type?: string;
91
+ title?: string;
92
+ status?: number;
93
+ detail?: string;
94
+ });
95
+ }
96
+ /**
97
+ * Why an `Idempotency-Key` was refused, `request-in-flight` is the benign one and
98
+ * `key-reused` means the same key was sent for a different request
99
+ */
100
+ type IdempotencyConflict = "request-in-flight" | "key-reused";
101
+ /**
102
+ * Thrown when an `Idempotency-Key` is held by another request. On
103
+ * `request-in-flight` the first attempt is still resolving, so wait and read the
104
+ * payment back rather than retrying. `key-reused` is a bug in the caller: the key
105
+ * is bound to the addresses, amount and webhook that claimed it
106
+ */
107
+ declare class IdempotencyConflictError extends ProblemError {
108
+ readonly conflict: IdempotencyConflict;
109
+ constructor(problem: {
110
+ type?: string;
111
+ title?: string;
112
+ status?: number;
113
+ detail?: string;
114
+ }, conflict: IdempotencyConflict);
115
+ }
116
+ /** Thrown when no wallet on your list could issue a provable invoice, `wallets` says why each refused */
117
+ declare class NoWalletAvailableError extends ProblemError {
118
+ readonly wallets: WalletFailure[];
119
+ constructor(problem: {
120
+ title?: string;
121
+ status?: number;
122
+ detail?: string;
123
+ }, wallets: WalletFailure[]);
124
+ }
125
+
126
+ export { AmountError as A, type GatewayCheatCode as G, type IdempotencyConflict as I, NoWalletAvailableError as N, ProblemError as P, UnverifiedRecipientError as U, type WrapRefusalCode as W, type AmountFault as a, GatewayCheatError as b, IdempotencyConflictError as c, WrapRefusedError as d };