@getalby/lightning-tools 8.0.0 → 8.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/dist/cjs/402/l402.cjs +102 -0
- package/dist/cjs/402/l402.cjs.map +1 -1
- package/dist/cjs/402/x402.cjs +539 -509
- package/dist/cjs/402/x402.cjs.map +1 -1
- package/dist/cjs/402.cjs +157 -16
- package/dist/cjs/402.cjs.map +1 -1
- package/dist/cjs/bolt11.cjs +526 -518
- package/dist/cjs/bolt11.cjs.map +1 -1
- package/dist/cjs/index.cjs +624 -482
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/lnurl.cjs +14 -7
- package/dist/cjs/lnurl.cjs.map +1 -1
- package/dist/esm/402/l402.js +98 -1
- package/dist/esm/402/l402.js.map +1 -1
- package/dist/esm/402/x402.js +539 -510
- package/dist/esm/402/x402.js.map +1 -1
- package/dist/esm/402.js +152 -17
- package/dist/esm/402.js.map +1 -1
- package/dist/esm/bolt11.js +526 -519
- package/dist/esm/bolt11.js.map +1 -1
- package/dist/esm/index.js +618 -483
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lnurl.js +14 -7
- package/dist/esm/lnurl.js.map +1 -1
- package/dist/lightning-tools.umd.js +3 -3
- package/dist/lightning-tools.umd.js.map +1 -1
- package/dist/types/402/l402.d.ts +39 -1
- package/dist/types/402/x402.d.ts +20 -1
- package/dist/types/402.d.ts +58 -2
- package/dist/types/bolt11.d.ts +2 -1
- package/dist/types/index.d.ts +59 -2
- package/package.json +1 -1
package/dist/types/402/l402.d.ts
CHANGED
|
@@ -10,4 +10,42 @@ declare const fetchWithL402: (url: string, fetchArgs: RequestInit, options: {
|
|
|
10
10
|
wallet: Wallet;
|
|
11
11
|
}) => Promise<Response>;
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
interface WwwAuthenticatePayload {
|
|
14
|
+
token: string;
|
|
15
|
+
invoice: string;
|
|
16
|
+
[key: string]: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Client: parse "www-authenticate" header from server response
|
|
20
|
+
* @param input
|
|
21
|
+
* @returns details from the header value (token or macaroon, invoice)
|
|
22
|
+
*/
|
|
23
|
+
declare const parseL402: (input: string) => WwwAuthenticatePayload;
|
|
24
|
+
|
|
25
|
+
type MacaroonPayload<T> = T & {
|
|
26
|
+
paymentHash: string;
|
|
27
|
+
};
|
|
28
|
+
declare function issueL402Macaroon<T extends Record<string, unknown>>(secret: string, paymentHash: string, params?: T): Promise<string>;
|
|
29
|
+
declare function verifyL402Macaroon<T = unknown>(secret: string, token: string): Promise<MacaroonPayload<T>>;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Server: create a WWW-Authenticate header for a given macaroon and invoice
|
|
33
|
+
* @param args the macaroon/token and invoice generated for the client's request
|
|
34
|
+
* @returns the header value
|
|
35
|
+
*/
|
|
36
|
+
declare const makeL402AuthenticateHeader: (args: {
|
|
37
|
+
token?: string;
|
|
38
|
+
invoice: string;
|
|
39
|
+
}) => string;
|
|
40
|
+
/**
|
|
41
|
+
* Server: parse "authorization" header sent from client
|
|
42
|
+
* @param input value from authorization header
|
|
43
|
+
* @returns the macaroon and preimage
|
|
44
|
+
*/
|
|
45
|
+
declare function parseL402Authorization(input: string): {
|
|
46
|
+
token: string;
|
|
47
|
+
preimage: string;
|
|
48
|
+
} | null;
|
|
49
|
+
|
|
50
|
+
export { fetchWithL402, issueL402Macaroon, makeL402AuthenticateHeader, parseL402, parseL402Authorization, verifyL402Macaroon };
|
|
51
|
+
export type { MacaroonPayload };
|
package/dist/types/402/x402.d.ts
CHANGED
|
@@ -6,8 +6,27 @@ interface Wallet {
|
|
|
6
6
|
}>;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
+
interface X402Requirements {
|
|
10
|
+
scheme: string;
|
|
11
|
+
network: string;
|
|
12
|
+
extra: {
|
|
13
|
+
invoice: string;
|
|
14
|
+
paymentMethod?: string;
|
|
15
|
+
[key: string]: unknown;
|
|
16
|
+
};
|
|
17
|
+
[key: string]: unknown;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Probe a PAYMENT-REQUIRED header for a lightning-payable offer without
|
|
22
|
+
* throwing. Returns the matching requirements, or null if the header has no
|
|
23
|
+
* lightning entry (e.g. USDC-only endpoints) or is malformed. Used by the
|
|
24
|
+
* top-level fetch402 dispatcher to decide whether to attempt payment or hand
|
|
25
|
+
* the 402 back to the caller.
|
|
26
|
+
*/
|
|
27
|
+
declare const findX402LightningRequirements: (x402Header: string) => X402Requirements | null;
|
|
9
28
|
declare const fetchWithX402: (url: string, fetchArgs: RequestInit, options: {
|
|
10
29
|
wallet: Wallet;
|
|
11
30
|
}) => Promise<Response>;
|
|
12
31
|
|
|
13
|
-
export { fetchWithX402 };
|
|
32
|
+
export { fetchWithX402, findX402LightningRequirements };
|
package/dist/types/402.d.ts
CHANGED
|
@@ -16,6 +16,62 @@ declare const fetchWithL402: (url: string, fetchArgs: RequestInit, options: {
|
|
|
16
16
|
wallet: Wallet;
|
|
17
17
|
}) => Promise<Response>;
|
|
18
18
|
|
|
19
|
+
interface WwwAuthenticatePayload {
|
|
20
|
+
token: string;
|
|
21
|
+
invoice: string;
|
|
22
|
+
[key: string]: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Client: parse "www-authenticate" header from server response
|
|
26
|
+
* @param input
|
|
27
|
+
* @returns details from the header value (token or macaroon, invoice)
|
|
28
|
+
*/
|
|
29
|
+
declare const parseL402: (input: string) => WwwAuthenticatePayload;
|
|
30
|
+
|
|
31
|
+
type MacaroonPayload<T> = T & {
|
|
32
|
+
paymentHash: string;
|
|
33
|
+
};
|
|
34
|
+
declare function issueL402Macaroon<T extends Record<string, unknown>>(secret: string, paymentHash: string, params?: T): Promise<string>;
|
|
35
|
+
declare function verifyL402Macaroon<T = unknown>(secret: string, token: string): Promise<MacaroonPayload<T>>;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Server: create a WWW-Authenticate header for a given macaroon and invoice
|
|
39
|
+
* @param args the macaroon/token and invoice generated for the client's request
|
|
40
|
+
* @returns the header value
|
|
41
|
+
*/
|
|
42
|
+
declare const makeL402AuthenticateHeader: (args: {
|
|
43
|
+
token?: string;
|
|
44
|
+
invoice: string;
|
|
45
|
+
}) => string;
|
|
46
|
+
/**
|
|
47
|
+
* Server: parse "authorization" header sent from client
|
|
48
|
+
* @param input value from authorization header
|
|
49
|
+
* @returns the macaroon and preimage
|
|
50
|
+
*/
|
|
51
|
+
declare function parseL402Authorization(input: string): {
|
|
52
|
+
token: string;
|
|
53
|
+
preimage: string;
|
|
54
|
+
} | null;
|
|
55
|
+
|
|
56
|
+
interface X402Requirements {
|
|
57
|
+
scheme: string;
|
|
58
|
+
network: string;
|
|
59
|
+
extra: {
|
|
60
|
+
invoice: string;
|
|
61
|
+
paymentMethod?: string;
|
|
62
|
+
[key: string]: unknown;
|
|
63
|
+
};
|
|
64
|
+
[key: string]: unknown;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Probe a PAYMENT-REQUIRED header for a lightning-payable offer without
|
|
69
|
+
* throwing. Returns the matching requirements, or null if the header has no
|
|
70
|
+
* lightning entry (e.g. USDC-only endpoints) or is malformed. Used by the
|
|
71
|
+
* top-level fetch402 dispatcher to decide whether to attempt payment or hand
|
|
72
|
+
* the 402 back to the caller.
|
|
73
|
+
*/
|
|
74
|
+
declare const findX402LightningRequirements: (x402Header: string) => X402Requirements | null;
|
|
19
75
|
declare const fetchWithX402: (url: string, fetchArgs: RequestInit, options: {
|
|
20
76
|
wallet: Wallet;
|
|
21
77
|
}) => Promise<Response>;
|
|
@@ -37,5 +93,5 @@ declare const fetchWithMpp: (url: string, fetchArgs: RequestInit, options: {
|
|
|
37
93
|
wallet: Wallet;
|
|
38
94
|
}) => Promise<Response>;
|
|
39
95
|
|
|
40
|
-
export { createGuardedWallet, fetch402, fetchWithL402, fetchWithMpp, fetchWithX402 };
|
|
41
|
-
export type { Wallet };
|
|
96
|
+
export { createGuardedWallet, fetch402, fetchWithL402, fetchWithMpp, fetchWithX402, findX402LightningRequirements, issueL402Macaroon, makeL402AuthenticateHeader, parseL402, parseL402Authorization, verifyL402Macaroon };
|
|
97
|
+
export type { MacaroonPayload, Wallet };
|
package/dist/types/bolt11.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ type DecodedInvoice = {
|
|
|
24
24
|
description: string | undefined;
|
|
25
25
|
};
|
|
26
26
|
declare const decodeInvoice: (paymentRequest: string) => DecodedInvoice | null;
|
|
27
|
+
declare function validatePreimage(preimage: string, paymentHash: string): boolean;
|
|
27
28
|
|
|
28
29
|
declare class Invoice {
|
|
29
30
|
paymentRequest: string;
|
|
@@ -46,5 +47,5 @@ declare class Invoice {
|
|
|
46
47
|
hasExpired(): boolean;
|
|
47
48
|
}
|
|
48
49
|
|
|
49
|
-
export { Invoice, decodeInvoice, fromHexString };
|
|
50
|
+
export { Invoice, decodeInvoice, fromHexString, validatePreimage };
|
|
50
51
|
export type { InvoiceArgs, SuccessAction };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -27,6 +27,7 @@ type DecodedInvoice = {
|
|
|
27
27
|
description: string | undefined;
|
|
28
28
|
};
|
|
29
29
|
declare const decodeInvoice: (paymentRequest: string) => DecodedInvoice | null;
|
|
30
|
+
declare function validatePreimage(preimage: string, paymentHash: string): boolean;
|
|
30
31
|
|
|
31
32
|
declare class Invoice {
|
|
32
33
|
paymentRequest: string;
|
|
@@ -257,6 +258,62 @@ declare const fetchWithL402: (url: string, fetchArgs: RequestInit, options: {
|
|
|
257
258
|
wallet: Wallet;
|
|
258
259
|
}) => Promise<Response>;
|
|
259
260
|
|
|
261
|
+
interface WwwAuthenticatePayload {
|
|
262
|
+
token: string;
|
|
263
|
+
invoice: string;
|
|
264
|
+
[key: string]: string;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Client: parse "www-authenticate" header from server response
|
|
268
|
+
* @param input
|
|
269
|
+
* @returns details from the header value (token or macaroon, invoice)
|
|
270
|
+
*/
|
|
271
|
+
declare const parseL402: (input: string) => WwwAuthenticatePayload;
|
|
272
|
+
|
|
273
|
+
type MacaroonPayload<T> = T & {
|
|
274
|
+
paymentHash: string;
|
|
275
|
+
};
|
|
276
|
+
declare function issueL402Macaroon<T extends Record<string, unknown>>(secret: string, paymentHash: string, params?: T): Promise<string>;
|
|
277
|
+
declare function verifyL402Macaroon<T = unknown>(secret: string, token: string): Promise<MacaroonPayload<T>>;
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Server: create a WWW-Authenticate header for a given macaroon and invoice
|
|
281
|
+
* @param args the macaroon/token and invoice generated for the client's request
|
|
282
|
+
* @returns the header value
|
|
283
|
+
*/
|
|
284
|
+
declare const makeL402AuthenticateHeader: (args: {
|
|
285
|
+
token?: string;
|
|
286
|
+
invoice: string;
|
|
287
|
+
}) => string;
|
|
288
|
+
/**
|
|
289
|
+
* Server: parse "authorization" header sent from client
|
|
290
|
+
* @param input value from authorization header
|
|
291
|
+
* @returns the macaroon and preimage
|
|
292
|
+
*/
|
|
293
|
+
declare function parseL402Authorization(input: string): {
|
|
294
|
+
token: string;
|
|
295
|
+
preimage: string;
|
|
296
|
+
} | null;
|
|
297
|
+
|
|
298
|
+
interface X402Requirements {
|
|
299
|
+
scheme: string;
|
|
300
|
+
network: string;
|
|
301
|
+
extra: {
|
|
302
|
+
invoice: string;
|
|
303
|
+
paymentMethod?: string;
|
|
304
|
+
[key: string]: unknown;
|
|
305
|
+
};
|
|
306
|
+
[key: string]: unknown;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Probe a PAYMENT-REQUIRED header for a lightning-payable offer without
|
|
311
|
+
* throwing. Returns the matching requirements, or null if the header has no
|
|
312
|
+
* lightning entry (e.g. USDC-only endpoints) or is malformed. Used by the
|
|
313
|
+
* top-level fetch402 dispatcher to decide whether to attempt payment or hand
|
|
314
|
+
* the 402 back to the caller.
|
|
315
|
+
*/
|
|
316
|
+
declare const findX402LightningRequirements: (x402Header: string) => X402Requirements | null;
|
|
260
317
|
declare const fetchWithX402: (url: string, fetchArgs: RequestInit, options: {
|
|
261
318
|
wallet: Wallet;
|
|
262
319
|
}) => Promise<Response>;
|
|
@@ -300,5 +357,5 @@ declare const getFormattedFiatValue: ({ satoshi, currency, locale, }: {
|
|
|
300
357
|
locale: string;
|
|
301
358
|
}) => Promise<string>;
|
|
302
359
|
|
|
303
|
-
export { DEFAULT_PROXY, Invoice, LN_ADDRESS_REGEX, LightningAddress, createGuardedWallet, decodeInvoice, fetch402, fetchWithL402, fetchWithMpp, fetchWithX402, fromHexString, generateZapEvent, getEventHash, getFiatBtcRate, getFiatCurrencies, getFiatValue, getFormattedFiatValue, getSatoshiValue, isUrl, isValidAmount, parseKeysendResponse, parseLnUrlPayResponse, parseNostrResponse, sendBoostagram, serializeEvent, validateEvent };
|
|
304
|
-
export type { Boost, BoostArguments, BoostOptions, Event, FiatCurrency, InvoiceArgs, KeySendRawData, KeysendResponse, LUD18PayerData, LUD18ServicePayerData, LnUrlPayResponse, LnUrlRawData, NostrProvider, NostrResponse, RequestInvoiceArgs, SuccessAction, Wallet, WeblnBoostParams, ZapArgs, ZapOptions };
|
|
360
|
+
export { DEFAULT_PROXY, Invoice, LN_ADDRESS_REGEX, LightningAddress, createGuardedWallet, decodeInvoice, fetch402, fetchWithL402, fetchWithMpp, fetchWithX402, findX402LightningRequirements, fromHexString, generateZapEvent, getEventHash, getFiatBtcRate, getFiatCurrencies, getFiatValue, getFormattedFiatValue, getSatoshiValue, isUrl, isValidAmount, issueL402Macaroon, makeL402AuthenticateHeader, parseKeysendResponse, parseL402, parseL402Authorization, parseLnUrlPayResponse, parseNostrResponse, sendBoostagram, serializeEvent, validateEvent, validatePreimage, verifyL402Macaroon };
|
|
361
|
+
export type { Boost, BoostArguments, BoostOptions, Event, FiatCurrency, InvoiceArgs, KeySendRawData, KeysendResponse, LUD18PayerData, LUD18ServicePayerData, LnUrlPayResponse, LnUrlRawData, MacaroonPayload, NostrProvider, NostrResponse, RequestInvoiceArgs, SuccessAction, Wallet, WeblnBoostParams, ZapArgs, ZapOptions };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getalby/lightning-tools",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.1.1",
|
|
4
4
|
"description": "Collection of helpful building blocks and tools to develop Bitcoin Lightning web apps",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": "https://github.com/getAlby/js-lightning-tools.git",
|