@getalby/lightning-tools 5.2.0 → 6.0.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 +17 -19
- package/dist/cjs/bolt11.cjs +1250 -0
- package/dist/cjs/bolt11.cjs.map +1 -0
- package/dist/cjs/fiat.cjs +36 -0
- package/dist/cjs/fiat.cjs.map +1 -0
- package/dist/cjs/index.cjs +1797 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/l402.cjs +89 -0
- package/dist/cjs/l402.cjs.map +1 -0
- package/dist/cjs/lnurl.cjs +1674 -0
- package/dist/cjs/lnurl.cjs.map +1 -0
- package/dist/cjs/podcasting2.cjs +32 -0
- package/dist/cjs/podcasting2.cjs.map +1 -0
- package/dist/esm/bolt11.js +1246 -0
- package/dist/esm/bolt11.js.map +1 -0
- package/dist/esm/fiat.js +31 -0
- package/dist/esm/fiat.js.map +1 -0
- package/dist/esm/index.js +1772 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/l402.js +84 -0
- package/dist/esm/l402.js.map +1 -0
- package/dist/esm/lnurl.js +1661 -0
- package/dist/esm/lnurl.js.map +1 -0
- package/dist/esm/podcasting2.js +30 -0
- package/dist/esm/podcasting2.js.map +1 -0
- package/dist/lightning-tools.umd.js +5 -0
- package/dist/lightning-tools.umd.js.map +1 -0
- package/dist/types/bolt11.d.ts +46 -0
- package/dist/types/fiat.d.ts +16 -0
- package/dist/types/index.d.ts +277 -0
- package/dist/types/l402.d.ts +27 -0
- package/dist/types/lnurl.d.ts +211 -0
- package/dist/{podcasting2/types.d.ts → types/podcasting2.d.ts} +11 -4
- package/package.json +54 -20
- package/dist/bolt11/Invoice.d.ts +0 -19
- package/dist/bolt11/index.d.ts +0 -3
- package/dist/bolt11/types.d.ts +0 -14
- package/dist/bolt11/utils.d.ts +0 -10
- package/dist/fiat/fiat.d.ts +0 -14
- package/dist/fiat/index.d.ts +0 -1
- package/dist/index.cjs +0 -1
- package/dist/index.d.ts +0 -7
- package/dist/index.modern.js +0 -1
- package/dist/index.module.js +0 -1
- package/dist/index.umd.js +0 -1
- package/dist/l402/index.d.ts +0 -2
- package/dist/l402/l402.d.ts +0 -6
- package/dist/l402/utils.d.ts +0 -12
- package/dist/lnurl/LightningAddress.d.ts +0 -43
- package/dist/lnurl/index.d.ts +0 -3
- package/dist/lnurl/types.d.ts +0 -104
- package/dist/lnurl/utils.d.ts +0 -14
- package/dist/podcasting2/boostagrams.d.ts +0 -2
- package/dist/podcasting2/index.d.ts +0 -2
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { WebLNProvider, SendPaymentResponse } from '@webbtc/webln-types';
|
|
2
|
+
|
|
3
|
+
type LnUrlRawData = {
|
|
4
|
+
tag: string;
|
|
5
|
+
callback: string;
|
|
6
|
+
minSendable: number;
|
|
7
|
+
maxSendable: number;
|
|
8
|
+
metadata: string;
|
|
9
|
+
payerData?: LUD18ServicePayerData;
|
|
10
|
+
commentAllowed?: number;
|
|
11
|
+
allowsNostr?: boolean;
|
|
12
|
+
};
|
|
13
|
+
type LnUrlPayResponse = {
|
|
14
|
+
callback: string;
|
|
15
|
+
fixed: boolean;
|
|
16
|
+
min: number;
|
|
17
|
+
max: number;
|
|
18
|
+
domain?: string;
|
|
19
|
+
metadata: Array<Array<string>>;
|
|
20
|
+
metadataHash: string;
|
|
21
|
+
identifier: string;
|
|
22
|
+
email: string;
|
|
23
|
+
description: string;
|
|
24
|
+
image: string;
|
|
25
|
+
commentAllowed?: number;
|
|
26
|
+
rawData: LnUrlRawData;
|
|
27
|
+
allowsNostr: boolean;
|
|
28
|
+
payerData?: LUD18ServicePayerData;
|
|
29
|
+
};
|
|
30
|
+
type LUD18ServicePayerData = Partial<{
|
|
31
|
+
name: {
|
|
32
|
+
mandatory: boolean;
|
|
33
|
+
};
|
|
34
|
+
pubkey: {
|
|
35
|
+
mandatory: boolean;
|
|
36
|
+
};
|
|
37
|
+
identifier: {
|
|
38
|
+
mandatory: boolean;
|
|
39
|
+
};
|
|
40
|
+
email: {
|
|
41
|
+
mandatory: boolean;
|
|
42
|
+
};
|
|
43
|
+
auth: {
|
|
44
|
+
mandatory: boolean;
|
|
45
|
+
k1: string;
|
|
46
|
+
};
|
|
47
|
+
}> & Record<string, unknown>;
|
|
48
|
+
type LUD18PayerData = Partial<{
|
|
49
|
+
name?: string;
|
|
50
|
+
pubkey?: string;
|
|
51
|
+
identifier?: string;
|
|
52
|
+
email?: string;
|
|
53
|
+
auth?: {
|
|
54
|
+
key: string;
|
|
55
|
+
sig: string;
|
|
56
|
+
};
|
|
57
|
+
}> & Record<string, unknown>;
|
|
58
|
+
type NostrResponse = {
|
|
59
|
+
names: Record<string, string>;
|
|
60
|
+
relays: Record<string, string[]>;
|
|
61
|
+
};
|
|
62
|
+
type Event = {
|
|
63
|
+
id?: string;
|
|
64
|
+
kind: number;
|
|
65
|
+
pubkey?: string;
|
|
66
|
+
content: string;
|
|
67
|
+
tags: string[][];
|
|
68
|
+
created_at: number;
|
|
69
|
+
sig?: string;
|
|
70
|
+
};
|
|
71
|
+
type ZapArgs = {
|
|
72
|
+
satoshi: number;
|
|
73
|
+
comment?: string;
|
|
74
|
+
relays: string[];
|
|
75
|
+
p?: string;
|
|
76
|
+
e?: string;
|
|
77
|
+
};
|
|
78
|
+
type NostrProvider = {
|
|
79
|
+
getPublicKey(): Promise<string>;
|
|
80
|
+
signEvent(event: Event & {
|
|
81
|
+
pubkey: string;
|
|
82
|
+
id: string;
|
|
83
|
+
}): Promise<Event>;
|
|
84
|
+
};
|
|
85
|
+
type ZapOptions = {
|
|
86
|
+
nostr?: NostrProvider;
|
|
87
|
+
};
|
|
88
|
+
type RequestInvoiceArgs = {
|
|
89
|
+
satoshi: number;
|
|
90
|
+
comment?: string;
|
|
91
|
+
payerdata?: LUD18PayerData;
|
|
92
|
+
};
|
|
93
|
+
type KeysendResponse = {
|
|
94
|
+
customKey: string;
|
|
95
|
+
customValue: string;
|
|
96
|
+
destination: string;
|
|
97
|
+
};
|
|
98
|
+
type KeySendRawData = {
|
|
99
|
+
tag: string;
|
|
100
|
+
status: string;
|
|
101
|
+
customData?: {
|
|
102
|
+
customKey?: string;
|
|
103
|
+
customValue?: string;
|
|
104
|
+
}[];
|
|
105
|
+
pubkey: string;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
declare const parseKeysendResponse: (data: KeySendRawData) => KeysendResponse;
|
|
109
|
+
declare function generateZapEvent({ satoshi, comment, p, e, relays }: ZapArgs, options?: ZapOptions): Promise<Event>;
|
|
110
|
+
declare function validateEvent(event: Event): boolean;
|
|
111
|
+
declare function serializeEvent(evt: Event): string;
|
|
112
|
+
declare function getEventHash(event: Event): string;
|
|
113
|
+
declare function parseNostrResponse(nostrData: NostrResponse, username: string | undefined): readonly [NostrResponse, string | undefined, string[] | undefined];
|
|
114
|
+
declare const isUrl: (url: string | null) => url is string;
|
|
115
|
+
declare const isValidAmount: ({ amount, min, max, }: {
|
|
116
|
+
amount: number;
|
|
117
|
+
min: number;
|
|
118
|
+
max: number;
|
|
119
|
+
}) => boolean;
|
|
120
|
+
declare const parseLnUrlPayResponse: (data: LnUrlRawData) => Promise<LnUrlPayResponse>;
|
|
121
|
+
|
|
122
|
+
type InvoiceArgs = {
|
|
123
|
+
pr: string;
|
|
124
|
+
verify?: string;
|
|
125
|
+
preimage?: string;
|
|
126
|
+
successAction?: SuccessAction;
|
|
127
|
+
};
|
|
128
|
+
type SuccessAction = {
|
|
129
|
+
tag: "message";
|
|
130
|
+
message: string;
|
|
131
|
+
} | {
|
|
132
|
+
tag: "url";
|
|
133
|
+
description: string;
|
|
134
|
+
url: string;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
declare class Invoice {
|
|
138
|
+
paymentRequest: string;
|
|
139
|
+
paymentHash: string;
|
|
140
|
+
preimage: string | null;
|
|
141
|
+
verify: string | null;
|
|
142
|
+
satoshi: number;
|
|
143
|
+
expiry: number | undefined;
|
|
144
|
+
timestamp: number;
|
|
145
|
+
createdDate: Date;
|
|
146
|
+
expiryDate: Date | undefined;
|
|
147
|
+
description: string | null;
|
|
148
|
+
successAction: SuccessAction | null;
|
|
149
|
+
constructor(args: InvoiceArgs);
|
|
150
|
+
isPaid(): Promise<boolean>;
|
|
151
|
+
validatePreimage(preimage: string): boolean;
|
|
152
|
+
verifyPayment(): Promise<boolean>;
|
|
153
|
+
hasExpired(): boolean;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
type Boost = {
|
|
157
|
+
action: string;
|
|
158
|
+
value_msat: number;
|
|
159
|
+
value_msat_total: number;
|
|
160
|
+
app_name: string;
|
|
161
|
+
app_version: string;
|
|
162
|
+
feedId: string;
|
|
163
|
+
podcast: string;
|
|
164
|
+
episode: string;
|
|
165
|
+
ts: number;
|
|
166
|
+
name: string;
|
|
167
|
+
sender_name: string;
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
declare const LN_ADDRESS_REGEX: RegExp;
|
|
171
|
+
declare const DEFAULT_PROXY = "https://api.getalby.com/lnurl";
|
|
172
|
+
type LightningAddressOptions = {
|
|
173
|
+
proxy?: string | false;
|
|
174
|
+
webln?: WebLNProvider;
|
|
175
|
+
};
|
|
176
|
+
declare class LightningAddress {
|
|
177
|
+
address: string;
|
|
178
|
+
options: LightningAddressOptions;
|
|
179
|
+
username: string | undefined;
|
|
180
|
+
domain: string | undefined;
|
|
181
|
+
pubkey: string | undefined;
|
|
182
|
+
lnurlpData: LnUrlPayResponse | undefined;
|
|
183
|
+
keysendData: KeysendResponse | undefined;
|
|
184
|
+
nostrData: NostrResponse | undefined;
|
|
185
|
+
nostrPubkey: string | undefined;
|
|
186
|
+
nostrRelays: string[] | undefined;
|
|
187
|
+
webln: WebLNProvider | undefined;
|
|
188
|
+
constructor(address: string, options?: LightningAddressOptions);
|
|
189
|
+
parse(): void;
|
|
190
|
+
getWebLN(): any;
|
|
191
|
+
fetch(): Promise<void>;
|
|
192
|
+
fetchWithProxy(): Promise<void>;
|
|
193
|
+
fetchWithoutProxy(): Promise<void>;
|
|
194
|
+
fetchLnurlData(): Promise<void>;
|
|
195
|
+
fetchKeysendData(): Promise<void>;
|
|
196
|
+
fetchNostrData(): Promise<void>;
|
|
197
|
+
lnurlpUrl(): string;
|
|
198
|
+
keysendUrl(): string;
|
|
199
|
+
nostrUrl(): string;
|
|
200
|
+
generateInvoice(params: Record<string, string>): Promise<Invoice>;
|
|
201
|
+
requestInvoice(args: RequestInvoiceArgs): Promise<Invoice>;
|
|
202
|
+
boost(boost: Boost, amount?: number): Promise<SendPaymentResponse>;
|
|
203
|
+
zapInvoice({ satoshi, comment, relays, e }: ZapArgs, options?: ZapOptions): Promise<Invoice>;
|
|
204
|
+
zap(args: ZapArgs, options?: ZapOptions): Promise<SendPaymentResponse>;
|
|
205
|
+
private parseLnUrlPayResponse;
|
|
206
|
+
private parseKeysendResponse;
|
|
207
|
+
private parseNostrResponse;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export { DEFAULT_PROXY, LN_ADDRESS_REGEX, LightningAddress, generateZapEvent, getEventHash, isUrl, isValidAmount, parseKeysendResponse, parseLnUrlPayResponse, parseNostrResponse, serializeEvent, validateEvent };
|
|
211
|
+
export type { Event, KeySendRawData, KeysendResponse, LUD18PayerData, LUD18ServicePayerData, LnUrlPayResponse, LnUrlRawData, NostrProvider, NostrResponse, RequestInvoiceArgs, ZapArgs, ZapOptions };
|
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
import * as _webbtc_webln_types from '@webbtc/webln-types';
|
|
2
|
+
|
|
3
|
+
type BoostOptions = {
|
|
2
4
|
webln?: unknown;
|
|
3
5
|
};
|
|
4
|
-
|
|
6
|
+
type BoostArguments = {
|
|
5
7
|
destination: string;
|
|
6
8
|
customKey?: string;
|
|
7
9
|
customValue?: string;
|
|
8
10
|
amount?: number;
|
|
9
11
|
boost: Boost;
|
|
10
12
|
};
|
|
11
|
-
|
|
13
|
+
type WeblnBoostParams = {
|
|
12
14
|
destination: string;
|
|
13
15
|
amount: number;
|
|
14
16
|
customRecords: Record<string, string>;
|
|
15
17
|
};
|
|
16
|
-
|
|
18
|
+
type Boost = {
|
|
17
19
|
action: string;
|
|
18
20
|
value_msat: number;
|
|
19
21
|
value_msat_total: number;
|
|
@@ -26,3 +28,8 @@ export type Boost = {
|
|
|
26
28
|
name: string;
|
|
27
29
|
sender_name: string;
|
|
28
30
|
};
|
|
31
|
+
|
|
32
|
+
declare const sendBoostagram: (args: BoostArguments, options?: BoostOptions) => Promise<_webbtc_webln_types.SendPaymentResponse>;
|
|
33
|
+
|
|
34
|
+
export { sendBoostagram };
|
|
35
|
+
export type { Boost, BoostArguments, BoostOptions, WeblnBoostParams };
|
package/package.json
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getalby/lightning-tools",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0",
|
|
4
4
|
"description": "Collection of helpful building blocks and tools to develop Bitcoin Lightning web apps",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"source": "src/index.ts",
|
|
7
|
-
"main": "./dist/index.cjs",
|
|
8
|
-
"module": "./dist/index.module.js",
|
|
9
|
-
"unpkg": "./dist/index.umd.js",
|
|
10
|
-
"types": "./dist/index.d.ts",
|
|
11
6
|
"repository": "https://github.com/getAlby/js-lightning-tools.git",
|
|
12
7
|
"bugs": "https://github.com/getAlby/js-lightning-tools/issues",
|
|
13
8
|
"funding": {
|
|
@@ -15,17 +10,50 @@
|
|
|
15
10
|
"url": "lightning:hello@getalby.com"
|
|
16
11
|
},
|
|
17
12
|
"files": [
|
|
18
|
-
"dist
|
|
13
|
+
"dist"
|
|
19
14
|
],
|
|
20
15
|
"keywords": [
|
|
21
16
|
"lightning",
|
|
22
17
|
"bitcoin",
|
|
23
18
|
"alby"
|
|
24
19
|
],
|
|
20
|
+
"sideEffects": false,
|
|
21
|
+
"source": "src/index.ts",
|
|
22
|
+
"module": "./dist/esm/index.js",
|
|
23
|
+
"main": "./dist/cjs/index.cjs",
|
|
24
|
+
"types": "./dist/types/index.d.ts",
|
|
25
|
+
"unpkg": "./dist/types/lightning-tools.umd.js",
|
|
25
26
|
"exports": {
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
".": {
|
|
28
|
+
"import": "./dist/esm/index.js",
|
|
29
|
+
"require": "./dist/cjs/index.cjs",
|
|
30
|
+
"types": "./dist/types/index.d.ts"
|
|
31
|
+
},
|
|
32
|
+
"./bolt11": {
|
|
33
|
+
"import": "./dist/esm/bolt11.js",
|
|
34
|
+
"require": "./dist/cjs/bolt11.cjs",
|
|
35
|
+
"types": "./dist/types/bolt11.d.ts"
|
|
36
|
+
},
|
|
37
|
+
"./fiat": {
|
|
38
|
+
"import": "./dist/esm/fiat.js",
|
|
39
|
+
"require": "./dist/cjs/fiat.cjs",
|
|
40
|
+
"types": "./dist/types/fiat.d.ts"
|
|
41
|
+
},
|
|
42
|
+
"./l402": {
|
|
43
|
+
"import": "./dist/esm/l402.js",
|
|
44
|
+
"require": "./dist/cjs/l402.cjs",
|
|
45
|
+
"types": "./dist/types/l402.d.ts"
|
|
46
|
+
},
|
|
47
|
+
"./lnurl": {
|
|
48
|
+
"import": "./dist/esm/lnurl.js",
|
|
49
|
+
"require": "./dist/cjs/lnurl.cjs",
|
|
50
|
+
"types": "./dist/types/lnurl.d.ts"
|
|
51
|
+
},
|
|
52
|
+
"./podcasting": {
|
|
53
|
+
"import": "./dist/esm/podcasting2.js",
|
|
54
|
+
"require": "./dist/cjs/podcasting2.cjs",
|
|
55
|
+
"types": "./dist/types/podcasting2.d.ts"
|
|
56
|
+
}
|
|
29
57
|
},
|
|
30
58
|
"scripts": {
|
|
31
59
|
"prebuild": "yarn run clean",
|
|
@@ -38,7 +66,7 @@
|
|
|
38
66
|
"format:fix": "prettier --loglevel silent --write '**/*.(md|json)' 'src/**/*.(js|ts)' 'examples/**/*.js'",
|
|
39
67
|
"test": "jest",
|
|
40
68
|
"clean": "rm -rf dist",
|
|
41
|
-
"build": "
|
|
69
|
+
"build": "rollup -c",
|
|
42
70
|
"dev": "microbundle watch",
|
|
43
71
|
"prepare": "husky"
|
|
44
72
|
},
|
|
@@ -46,24 +74,30 @@
|
|
|
46
74
|
"devDependencies": {
|
|
47
75
|
"@commitlint/cli": "^19.8.1",
|
|
48
76
|
"@commitlint/config-conventional": "^19.8.1",
|
|
49
|
-
"@
|
|
50
|
-
"@
|
|
77
|
+
"@rollup/plugin-commonjs": "^28.0.6",
|
|
78
|
+
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
79
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
80
|
+
"@rollup/plugin-typescript": "^12.1.4",
|
|
81
|
+
"@types/jest": "^30.0.0",
|
|
82
|
+
"@types/node": "^24.2.0",
|
|
51
83
|
"@typescript-eslint/eslint-plugin": "^6.21.0",
|
|
52
84
|
"@typescript-eslint/parser": "^6.21.0",
|
|
53
85
|
"@webbtc/webln-types": "^3.0.0",
|
|
54
86
|
"eslint": "^8.47.0",
|
|
55
87
|
"eslint-config-prettier": "^10.1.5",
|
|
56
88
|
"husky": "^9.1.7",
|
|
57
|
-
"jest": "^
|
|
89
|
+
"jest": "^30.0.5",
|
|
58
90
|
"jest-fetch-mock": "^3.0.3",
|
|
59
91
|
"light-bolt11-decoder": "^3.2.0",
|
|
60
|
-
"lint-staged": "^16.
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
92
|
+
"lint-staged": "^16.1.4",
|
|
93
|
+
"nostr-tools": "^2.16.1",
|
|
94
|
+
"prettier": "^3.6.2",
|
|
95
|
+
"rollup": "^4.46.2",
|
|
96
|
+
"rollup-plugin-dts": "^6.2.1",
|
|
97
|
+
"ts-jest": "^29.4.1",
|
|
65
98
|
"ts-node": "^10.9.2",
|
|
66
|
-
"
|
|
99
|
+
"tslib": "^2.8.1",
|
|
100
|
+
"typescript": "^5.9.2"
|
|
67
101
|
},
|
|
68
102
|
"engines": {
|
|
69
103
|
"node": ">=14"
|
package/dist/bolt11/Invoice.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { InvoiceArgs, SuccessAction } from "./types";
|
|
2
|
-
export declare class Invoice {
|
|
3
|
-
paymentRequest: string;
|
|
4
|
-
paymentHash: string;
|
|
5
|
-
preimage: string | null;
|
|
6
|
-
verify: string | null;
|
|
7
|
-
satoshi: number;
|
|
8
|
-
expiry: number | undefined;
|
|
9
|
-
timestamp: number;
|
|
10
|
-
createdDate: Date;
|
|
11
|
-
expiryDate: Date | undefined;
|
|
12
|
-
description: string | null;
|
|
13
|
-
successAction: SuccessAction | null;
|
|
14
|
-
constructor(args: InvoiceArgs);
|
|
15
|
-
isPaid(): Promise<boolean>;
|
|
16
|
-
validatePreimage(preimage: string): boolean;
|
|
17
|
-
verifyPayment(): Promise<boolean>;
|
|
18
|
-
hasExpired(): boolean;
|
|
19
|
-
}
|
package/dist/bolt11/index.d.ts
DELETED
package/dist/bolt11/types.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export type InvoiceArgs = {
|
|
2
|
-
pr: string;
|
|
3
|
-
verify?: string;
|
|
4
|
-
preimage?: string;
|
|
5
|
-
successAction?: SuccessAction;
|
|
6
|
-
};
|
|
7
|
-
export type SuccessAction = {
|
|
8
|
-
tag: "message";
|
|
9
|
-
message: string;
|
|
10
|
-
} | {
|
|
11
|
-
tag: "url";
|
|
12
|
-
description: string;
|
|
13
|
-
url: string;
|
|
14
|
-
};
|
package/dist/bolt11/utils.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export declare const fromHexString: (hexString: string) => Uint8Array<ArrayBuffer>;
|
|
2
|
-
type DecodedInvoice = {
|
|
3
|
-
paymentHash: string;
|
|
4
|
-
satoshi: number;
|
|
5
|
-
timestamp: number;
|
|
6
|
-
expiry: number | undefined;
|
|
7
|
-
description: string | undefined;
|
|
8
|
-
};
|
|
9
|
-
export declare const decodeInvoice: (paymentRequest: string) => DecodedInvoice | null;
|
|
10
|
-
export {};
|
package/dist/fiat/fiat.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export declare const getFiatBtcRate: (currency: string) => Promise<number>;
|
|
2
|
-
export declare const getFiatValue: ({ satoshi, currency, }: {
|
|
3
|
-
satoshi: number | string;
|
|
4
|
-
currency: string;
|
|
5
|
-
}) => Promise<number>;
|
|
6
|
-
export declare const getSatoshiValue: ({ amount, currency, }: {
|
|
7
|
-
amount: number | string;
|
|
8
|
-
currency: string;
|
|
9
|
-
}) => Promise<number>;
|
|
10
|
-
export declare const getFormattedFiatValue: ({ satoshi, currency, locale, }: {
|
|
11
|
-
satoshi: number | string;
|
|
12
|
-
currency: string;
|
|
13
|
-
locale: string;
|
|
14
|
-
}) => Promise<string>;
|
package/dist/fiat/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./fiat";
|
package/dist/index.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var e,t,r=(e=function(e,t){function r(e){if(!Number.isSafeInteger(e))throw new Error(`Wrong integer: ${e}`)}function n(...e){const t=(e,t)=>r=>e(t(r));return{encode:Array.from(e).reverse().reduce((e,r)=>e?t(e,r.encode):r.encode,void 0),decode:e.reduce((e,r)=>e?t(e,r.decode):r.decode,void 0)}}function o(e){return{encode:t=>{if(!Array.isArray(t)||t.length&&"number"!=typeof t[0])throw new Error("alphabet.encode input should be an array of numbers");return t.map(t=>{if(r(t),t<0||t>=e.length)throw new Error(`Digit index outside alphabet: ${t} (alphabet: ${e.length})`);return e[t]})},decode:t=>{if(!Array.isArray(t)||t.length&&"string"!=typeof t[0])throw new Error("alphabet.decode input should be array of strings");return t.map(t=>{if("string"!=typeof t)throw new Error(`alphabet.decode: not string element=${t}`);const r=e.indexOf(t);if(-1===r)throw new Error(`Unknown letter: "${t}". Allowed: ${e}`);return r})}}}function s(e=""){if("string"!=typeof e)throw new Error("join separator should be string");return{encode:t=>{if(!Array.isArray(t)||t.length&&"string"!=typeof t[0])throw new Error("join.encode input should be array of strings");for(let e of t)if("string"!=typeof e)throw new Error(`join.encode: non-string input=${e}`);return t.join(e)},decode:t=>{if("string"!=typeof t)throw new Error("join.decode input should be string");return t.split(e)}}}function i(e,t="="){if(r(e),"string"!=typeof t)throw new Error("padding chr should be string");return{encode(r){if(!Array.isArray(r)||r.length&&"string"!=typeof r[0])throw new Error("padding.encode input should be array of strings");for(let e of r)if("string"!=typeof e)throw new Error(`padding.encode: non-string input=${e}`);for(;r.length*e%8;)r.push(t);return r},decode(r){if(!Array.isArray(r)||r.length&&"string"!=typeof r[0])throw new Error("padding.encode input should be array of strings");for(let e of r)if("string"!=typeof e)throw new Error(`padding.decode: non-string input=${e}`);let n=r.length;if(n*e%8)throw new Error("Invalid padding: string should have whole number of bytes");for(;n>0&&r[n-1]===t;n--)if(!((n-1)*e%8))throw new Error("Invalid padding: string has too much padding");return r.slice(0,n)}}}function a(e){if("function"!=typeof e)throw new Error("normalize fn should be function");return{encode:e=>e,decode:t=>e(t)}}function c(e,t,n){if(t<2)throw new Error(`convertRadix: wrong from=${t}, base cannot be less than 2`);if(n<2)throw new Error(`convertRadix: wrong to=${n}, base cannot be less than 2`);if(!Array.isArray(e))throw new Error("convertRadix: data should be array");if(!e.length)return[];let o=0;const s=[],i=Array.from(e);for(i.forEach(e=>{if(r(e),e<0||e>=t)throw new Error(`Wrong integer: ${e}`)});;){let e=0,r=!0;for(let s=o;s<i.length;s++){const a=i[s],c=t*e+a;if(!Number.isSafeInteger(c)||t*e/t!==e||c-a!=t*e)throw new Error("convertRadix: carry overflow");if(e=c%n,i[s]=Math.floor(c/n),!Number.isSafeInteger(i[s])||i[s]*n+e!==c)throw new Error("convertRadix: carry overflow");r&&(i[s]?r=!1:o=s)}if(s.push(e),r)break}for(let t=0;t<e.length-1&&0===e[t];t++)s.push(0);return s.reverse()}Object.defineProperty(t,"__esModule",{value:!0}),t.bytes=t.stringToBytes=t.str=t.bytesToString=t.hex=t.utf8=t.bech32m=t.bech32=t.base58check=t.base58xmr=t.base58xrp=t.base58flickr=t.base58=t.base64url=t.base64=t.base32crockford=t.base32hex=t.base32=t.base16=t.utils=t.assertNumber=void 0,t.assertNumber=r;const u=(e,t)=>t?u(t,e%t):e,h=(e,t)=>e+(t-u(e,t));function l(e,t,n,o){if(!Array.isArray(e))throw new Error("convertRadix2: data should be array");if(t<=0||t>32)throw new Error(`convertRadix2: wrong from=${t}`);if(n<=0||n>32)throw new Error(`convertRadix2: wrong to=${n}`);if(h(t,n)>32)throw new Error(`convertRadix2: carry overflow from=${t} to=${n} carryBits=${h(t,n)}`);let s=0,i=0;const a=2**n-1,c=[];for(const o of e){if(r(o),o>=2**t)throw new Error(`convertRadix2: invalid data word=${o} from=${t}`);if(s=s<<t|o,i+t>32)throw new Error(`convertRadix2: carry overflow pos=${i} from=${t}`);for(i+=t;i>=n;i-=n)c.push((s>>i-n&a)>>>0);s&=2**i-1}if(s=s<<n-i&a,!o&&i>=t)throw new Error("Excess padding");if(!o&&s)throw new Error(`Non-zero padding: ${s}`);return o&&i>0&&c.push(s>>>0),c}function f(e){return r(e),{encode:t=>{if(!(t instanceof Uint8Array))throw new Error("radix.encode input should be Uint8Array");return c(Array.from(t),256,e)},decode:t=>{if(!Array.isArray(t)||t.length&&"number"!=typeof t[0])throw new Error("radix.decode input should be array of strings");return Uint8Array.from(c(t,e,256))}}}function d(e,t=!1){if(r(e),e<=0||e>32)throw new Error("radix2: bits should be in (0..32]");if(h(8,e)>32||h(e,8)>32)throw new Error("radix2: carry overflow");return{encode:r=>{if(!(r instanceof Uint8Array))throw new Error("radix2.encode input should be Uint8Array");return l(Array.from(r),8,e,!t)},decode:r=>{if(!Array.isArray(r)||r.length&&"number"!=typeof r[0])throw new Error("radix2.decode input should be array of strings");return Uint8Array.from(l(r,e,8,t))}}}function p(e){if("function"!=typeof e)throw new Error("unsafeWrapper fn should be function");return function(...t){try{return e.apply(null,t)}catch(e){}}}function m(e,t){if(r(e),"function"!=typeof t)throw new Error("checksum fn should be function");return{encode(r){if(!(r instanceof Uint8Array))throw new Error("checksum.encode: input should be Uint8Array");const n=t(r).slice(0,e),o=new Uint8Array(r.length+e);return o.set(r),o.set(n,r.length),o},decode(r){if(!(r instanceof Uint8Array))throw new Error("checksum.decode: input should be Uint8Array");const n=r.slice(0,-e),o=t(n).slice(0,e),s=r.slice(-e);for(let t=0;t<e;t++)if(o[t]!==s[t])throw new Error("Invalid checksum");return n}}}t.utils={alphabet:o,chain:n,checksum:m,radix:f,radix2:d,join:s,padding:i},t.base16=n(d(4),o("0123456789ABCDEF"),s("")),t.base32=n(d(5),o("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),i(5),s("")),t.base32hex=n(d(5),o("0123456789ABCDEFGHIJKLMNOPQRSTUV"),i(5),s("")),t.base32crockford=n(d(5),o("0123456789ABCDEFGHJKMNPQRSTVWXYZ"),s(""),a(e=>e.toUpperCase().replace(/O/g,"0").replace(/[IL]/g,"1"))),t.base64=n(d(6),o("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),i(6),s("")),t.base64url=n(d(6),o("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),i(6),s(""));const y=e=>n(f(58),o(e),s(""));t.base58=y("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"),t.base58flickr=y("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"),t.base58xrp=y("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz");const w=[0,2,3,5,6,7,9,10,11];t.base58xmr={encode(e){let r="";for(let n=0;n<e.length;n+=8){const o=e.subarray(n,n+8);r+=t.base58.encode(o).padStart(w[o.length],"1")}return r},decode(e){let r=[];for(let n=0;n<e.length;n+=11){const o=e.slice(n,n+11),s=w.indexOf(o.length),i=t.base58.decode(o);for(let e=0;e<i.length-s;e++)if(0!==i[e])throw new Error("base58xmr: wrong padding");r=r.concat(Array.from(i.slice(i.length-s)))}return Uint8Array.from(r)}},t.base58check=e=>n(m(4,t=>e(e(t))),t.base58);const g=n(o("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),s("")),v=[996825010,642813549,513874426,1027748829,705979059];function b(e){const t=e>>25;let r=(33554431&e)<<5;for(let e=0;e<v.length;e++)1==(t>>e&1)&&(r^=v[e]);return r}function x(e,t,r=1){const n=e.length;let o=1;for(let t=0;t<n;t++){const r=e.charCodeAt(t);if(r<33||r>126)throw new Error(`Invalid prefix (${e})`);o=b(o)^r>>5}o=b(o);for(let t=0;t<n;t++)o=b(o)^31&e.charCodeAt(t);for(let e of t)o=b(o)^e;for(let e=0;e<6;e++)o=b(o);return o^=r,g.encode(l([o%2**30],30,5,!1))}function E(e){const t="bech32"===e?1:734539939,r=d(5),n=r.decode,o=r.encode,s=p(n);function i(e,r=90){if("string"!=typeof e)throw new Error("bech32.decode input should be string, not "+typeof e);if(e.length<8||!1!==r&&e.length>r)throw new TypeError(`Wrong string length: ${e.length} (${e}). Expected (8..${r})`);const n=e.toLowerCase();if(e!==n&&e!==e.toUpperCase())throw new Error("String must be lowercase or uppercase");const o=(e=n).lastIndexOf("1");if(0===o||-1===o)throw new Error('Letter "1" must be present between prefix and data only');const s=e.slice(0,o),i=e.slice(o+1);if(i.length<6)throw new Error("Data must be at least 6 characters long");const a=g.decode(i).slice(0,-6),c=x(s,a,t);if(!i.endsWith(c))throw new Error(`Invalid checksum in ${e}: expected "${c}"`);return{prefix:s,words:a}}return{encode:function(e,r,n=90){if("string"!=typeof e)throw new Error("bech32.encode prefix should be string, not "+typeof e);if(!Array.isArray(r)||r.length&&"number"!=typeof r[0])throw new Error("bech32.encode words should be array of numbers, not "+typeof r);const o=e.length+7+r.length;if(!1!==n&&o>n)throw new TypeError(`Length ${o} exceeds limit ${n}`);return`${e=e.toLowerCase()}1${g.encode(r)}${x(e,r,t)}`},decode:i,decodeToBytes:function(e){const{prefix:t,words:r}=i(e,!1);return{prefix:t,words:r,bytes:n(r)}},decodeUnsafe:p(i),fromWords:n,fromWordsUnsafe:s,toWords:o}}t.bech32=E("bech32"),t.bech32m=E("bech32m"),t.utf8={encode:e=>(new TextDecoder).decode(e),decode:e=>(new TextEncoder).encode(e)},t.hex=n(d(4),o("0123456789abcdef"),s(""),a(e=>{if("string"!=typeof e||e.length%2)throw new TypeError(`hex.decode: expected string, got ${typeof e} with length ${e.length}`);return e.toLowerCase()}));const P={utf8:t.utf8,hex:t.hex,base16:t.base16,base32:t.base32,base64:t.base64,base64url:t.base64url,base58:t.base58,base58xmr:t.base58xmr},A=`Invalid encoding type. Available types: ${Object.keys(P).join(", ")}`;t.bytesToString=(e,t)=>{if("string"!=typeof e||!P.hasOwnProperty(e))throw new TypeError(A);if(!(t instanceof Uint8Array))throw new TypeError("bytesToString() expects Uint8Array");return P[e].encode(t)},t.str=t.bytesToString,t.stringToBytes=(e,t)=>{if(!P.hasOwnProperty(e))throw new TypeError(A);if("string"!=typeof t)throw new TypeError("stringToBytes() expects string");return P[e].decode(t)},t.bytes=t.stringToBytes},e(t={exports:{}},t.exports),t.exports);const{bech32:n,hex:o,utf8:s}=r,i={bech32:"bc",pubKeyHash:0,scriptHash:5,validWitnessVersions:[0]},a={bech32:"tb",pubKeyHash:111,scriptHash:196,validWitnessVersions:[0]},c={bech32:"tbs",pubKeyHash:111,scriptHash:196,validWitnessVersions:[0]},u={bech32:"bcrt",pubKeyHash:111,scriptHash:196,validWitnessVersions:[0]},h={bech32:"sb",pubKeyHash:63,scriptHash:123,validWitnessVersions:[0]},l=["option_data_loss_protect","initial_routing_sync","option_upfront_shutdown_script","gossip_queries","var_onion_optin","gossip_queries_ex","option_static_remotekey","payment_secret","basic_mpp","option_support_large_channel"],f={m:BigInt(1e3),u:BigInt(1e6),n:BigInt(1e9),p:BigInt(1e12)},d=BigInt("2100000000000000000"),p=BigInt(1e11),m={payment_hash:1,payment_secret:16,description:13,payee:19,description_hash:23,expiry:6,min_final_cltv_expiry:24,fallback_address:9,route_hint:3,feature_bits:5,metadata:27},y={};for(let e=0,t=Object.keys(m);e<t.length;e++){const r=t[e],n=m[t[e]].toString();y[n]=r}const w={1:e=>o.encode(n.fromWordsUnsafe(e)),16:e=>o.encode(n.fromWordsUnsafe(e)),13:e=>s.encode(n.fromWordsUnsafe(e)),19:e=>o.encode(n.fromWordsUnsafe(e)),23:e=>o.encode(n.fromWordsUnsafe(e)),27:e=>o.encode(n.fromWordsUnsafe(e)),6:v,24:v,3:function(e){const t=[];let r,s,i,a,c,u=n.fromWordsUnsafe(e);for(;u.length>0;)r=o.encode(u.slice(0,33)),s=o.encode(u.slice(33,41)),i=parseInt(o.encode(u.slice(41,45)),16),a=parseInt(o.encode(u.slice(45,49)),16),c=parseInt(o.encode(u.slice(49,51)),16),u=u.slice(51),t.push({pubkey:r,short_channel_id:s,fee_base_msat:i,fee_proportional_millionths:a,cltv_expiry_delta:c});return t},5:function(e){const t=e.slice().reverse().map(e=>[!!(1&e),!!(2&e),!!(4&e),!!(8&e),!!(16&e)]).reduce((e,t)=>e.concat(t),[]);for(;t.length<2*l.length;)t.push(!1);const r={};l.forEach((e,n)=>{let o;o=t[2*n]?"required":t[2*n+1]?"supported":"unsupported",r[e]=o});const n=t.slice(2*l.length);return r.extra_bits={start_bit:2*l.length,bits:n,has_required:n.reduce((e,t,r)=>r%2!=0?e||!1:e||t,!1)},r}};function g(e){return t=>({tagCode:parseInt(e),words:n.encode("unknown",t,Number.MAX_SAFE_INTEGER)})}function v(e){return e.reverse().reduce((e,t,r)=>e+t*Math.pow(32,r),0)}var b=function(e){return Uint8Array.from(e.match(/.{1,2}/g).map(function(e){return parseInt(e,16)}))},x=function(e){if(!e)return null;try{var t=function(e,t){if("string"!=typeof e)throw new Error("Lightning Payment Request must be string");if("ln"!==e.slice(0,2).toLowerCase())throw new Error("Not a proper lightning payment request");const r=[],s=n.decode(e,Number.MAX_SAFE_INTEGER);e=e.toLowerCase();const l=s.prefix;let b=s.words,x=e.slice(l.length+1),E=b.slice(-104);b=b.slice(0,-104);let P=l.match(/^ln(\S+?)(\d*)([a-zA-Z]?)$/);if(P&&!P[2]&&(P=l.match(/^ln(\S+)$/)),!P)throw new Error("Not a proper lightning payment request");r.push({name:"lightning_network",letters:"ln"});const A=P[1];let k;switch(A){case i.bech32:k=i;break;case a.bech32:k=a;break;case c.bech32:k=c;break;case u.bech32:k=u;break;case h.bech32:k=h}if(!k||k.bech32!==A)throw new Error("Unknown coin bech32 prefix");r.push({name:"coin_network",letters:A,value:k});const _=P[2];let U;_?(U=function(e,t){let r,n;if(e.slice(-1).match(/^[munp]$/))r=e.slice(-1),n=e.slice(0,-1);else{if(e.slice(-1).match(/^[^munp0-9]$/))throw new Error("Not a valid multiplier for the amount");n=e}if(!n.match(/^\d+$/))throw new Error("Not a valid human readable amount");const o=BigInt(n),s=r?o*p/f[r]:o*p;if("p"===r&&o%BigInt(10)!==BigInt(0)||s>d)throw new Error("Amount is outside of valid range");return s.toString()}(_+P[3]),r.push({name:"amount",letters:P[2]+P[3],value:U})):U=null,r.push({name:"separator",letters:"1"});const L=v(b.slice(0,7));let N,D,I,S;for(b=b.slice(7),r.push({name:"timestamp",letters:x.slice(0,7),value:L}),x=x.slice(7);b.length>0;){const e=b[0].toString();N=y[e]||"unknown_tag",D=w[e]||g(e),b=b.slice(1),I=v(b.slice(0,2)),b=b.slice(2),S=b.slice(0,I),b=b.slice(I),r.push({name:N,tag:x[0],letters:x.slice(0,3+I),value:D(S)}),x=x.slice(3+I)}r.push({name:"signature",letters:x.slice(0,104),value:o.encode(n.fromWordsUnsafe(E))}),x=x.slice(104),r.push({name:"checksum",letters:x});let R={paymentRequest:e,sections:r,get expiry(){let e=r.find(e=>"expiry"===e.name);if(e)return j("timestamp")+e.value},get route_hints(){return r.filter(e=>"route_hint"===e.name).map(e=>e.value)}};for(let e in m)"route_hint"!==e&&Object.defineProperty(R,e,{get:()=>j(e)});return R;function j(e){let t=r.find(t=>t.name===e);return t?t.value:void 0}}(e);if(!t||!t.sections)return null;var r=t.sections.find(function(e){return"payment_hash"===e.name});if("payment_hash"!==(null==r?void 0:r.name)||!r.value)return null;var s=r.value,l=0,b=t.sections.find(function(e){return"amount"===e.name});"amount"===(null==b?void 0:b.name)&&b.value&&(l=parseInt(b.value)/1e3);var x=t.sections.find(function(e){return"timestamp"===e.name});if("timestamp"!==(null==x?void 0:x.name)||!x.value)return null;var E,P=x.value,A=t.sections.find(function(e){return"expiry"===e.name});"expiry"===(null==A?void 0:A.name)&&(E=A.value);var k=t.sections.find(function(e){return"description"===e.name});return{paymentHash:s,satoshi:l,timestamp:P,expiry:E,description:"description"===(null==k?void 0:k.name)?null==k?void 0:k.value:void 0}}catch(e){return null}};function E(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}const P=e=>e instanceof Uint8Array,A=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),k=(e,t)=>e<<32-t|e>>>t;if(68!==new Uint8Array(new Uint32Array([287454020]).buffer)[0])throw new Error("Non little-endian hardware is not supported");const _=/* @__PURE__ */Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function U(e){if(!P(e))throw new Error("Uint8Array expected");let t="";for(let r=0;r<e.length;r++)t+=_[e[r]];return t}function L(e){if("string"==typeof e&&(e=function(e){if("string"!=typeof e)throw new Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array((new TextEncoder).encode(e))}(e)),!P(e))throw new Error("expected Uint8Array, got "+typeof e);return e}class N{clone(){return this._cloneInto()}}function D(e){const t=t=>e().update(L(t)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}class I extends N{constructor(e,t,r,n){super(),this.blockLen=e,this.outputLen=t,this.padOffset=r,this.isLE=n,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=A(this.buffer)}update(e){E(this);const{view:t,buffer:r,blockLen:n}=this,o=(e=L(e)).length;for(let s=0;s<o;){const i=Math.min(n-this.pos,o-s);if(i!==n)r.set(e.subarray(s,s+i),this.pos),this.pos+=i,s+=i,this.pos===n&&(this.process(t,0),this.pos=0);else{const t=A(e);for(;n<=o-s;s+=n)this.process(t,s)}}return this.length+=e.length,this.roundClean(),this}digestInto(e){E(this),function(e,t){!function(e,...t){if(!(e instanceof Uint8Array))throw new Error("Expected Uint8Array");if(t.length>0&&!t.includes(e.length))throw new Error(`Expected Uint8Array of length ${t}, not of length=${e.length}`)}(e);const r=t.outputLen;if(e.length<r)throw new Error(`digestInto() expects output buffer of length at least ${r}`)}(e,this),this.finished=!0;const{buffer:t,view:r,blockLen:n,isLE:o}=this;let{pos:s}=this;t[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>n-s&&(this.process(r,0),s=0);for(let e=s;e<n;e++)t[e]=0;!function(e,t,r,n){if("function"==typeof e.setBigUint64)return e.setBigUint64(t,r,n);const o=BigInt(32),s=BigInt(4294967295),i=Number(r>>o&s),a=Number(r&s),c=n?0:4;e.setUint32(t+(n?4:0),i,n),e.setUint32(t+c,a,n)}(r,n-8,BigInt(8*this.length),o),this.process(r,0);const i=A(e),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const c=a/4,u=this.get();if(c>u.length)throw new Error("_sha2: outputLen bigger than state");for(let e=0;e<c;e++)i.setUint32(4*e,u[e],o)}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const r=e.slice(0,t);return this.destroy(),r}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:t,buffer:r,length:n,finished:o,destroyed:s,pos:i}=this;return e.length=n,e.pos=i,e.finished=o,e.destroyed=s,n%t&&e.buffer.set(r),e}}const S=(e,t,r)=>e&t^e&r^t&r,R=/* @__PURE__ */new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),j=/* @__PURE__ */new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),$=/* @__PURE__ */new Uint32Array(64);class T extends I{constructor(){super(64,32,8,!1),this.A=0|j[0],this.B=0|j[1],this.C=0|j[2],this.D=0|j[3],this.E=0|j[4],this.F=0|j[5],this.G=0|j[6],this.H=0|j[7]}get(){const{A:e,B:t,C:r,D:n,E:o,F:s,G:i,H:a}=this;return[e,t,r,n,o,s,i,a]}set(e,t,r,n,o,s,i,a){this.A=0|e,this.B=0|t,this.C=0|r,this.D=0|n,this.E=0|o,this.F=0|s,this.G=0|i,this.H=0|a}process(e,t){for(let r=0;r<16;r++,t+=4)$[r]=e.getUint32(t,!1);for(let e=16;e<64;e++){const t=$[e-15],r=$[e-2],n=k(t,7)^k(t,18)^t>>>3,o=k(r,17)^k(r,19)^r>>>10;$[e]=o+$[e-7]+n+$[e-16]|0}let{A:r,B:n,C:o,D:s,E:i,F:a,G:c,H:u}=this;for(let e=0;e<64;e++){const t=u+(k(i,6)^k(i,11)^k(i,25))+((h=i)&a^~h&c)+R[e]+$[e]|0,l=(k(r,2)^k(r,13)^k(r,22))+S(r,n,o)|0;u=c,c=a,a=i,i=s+t|0,s=o,o=n,n=r,r=t+l|0}var h;r=r+this.A|0,n=n+this.B|0,o=o+this.C|0,s=s+this.D|0,i=i+this.E|0,a=a+this.F|0,c=c+this.G|0,u=u+this.H|0,this.set(r,n,o,s,i,a,c,u)}roundClean(){$.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}const W=/* @__PURE__ */D(()=>new T);var B=/*#__PURE__*/function(){function e(e){var t,r,n,o;if(this.paymentRequest=void 0,this.paymentHash=void 0,this.preimage=void 0,this.verify=void 0,this.satoshi=void 0,this.expiry=void 0,this.timestamp=void 0,this.createdDate=void 0,this.expiryDate=void 0,this.description=void 0,this.successAction=void 0,this.paymentRequest=e.pr,!this.paymentRequest)throw new Error("Invalid payment request");var s=x(this.paymentRequest);if(!s)throw new Error("Failed to decode payment request");this.paymentHash=s.paymentHash,this.satoshi=s.satoshi,this.timestamp=s.timestamp,this.expiry=s.expiry,this.createdDate=new Date(1e3*this.timestamp),this.expiryDate=this.expiry?new Date(1e3*(this.timestamp+this.expiry)):void 0,this.description=null!=(t=s.description)?t:null,this.verify=null!=(r=e.verify)?r:null,this.preimage=null!=(n=e.preimage)?n:null,this.successAction=null!=(o=e.successAction)?o:null}var t=e.prototype;return t.isPaid=function(){try{var e=this;if(e.preimage)return Promise.resolve(e.validatePreimage(e.preimage));if(e.verify)return Promise.resolve(e.verifyPayment());throw new Error("Could not verify payment")}catch(e){return Promise.reject(e)}},t.validatePreimage=function(e){if(!e||!this.paymentHash)return!1;try{var t=U(W(b(e)));return this.paymentHash===t}catch(e){return!1}},t.verifyPayment=function(){try{var e=this;return Promise.resolve(function(t,r){try{var n=function(){if(!e.verify)throw new Error("LNURL verify not available");return Promise.resolve(fetch(e.verify)).then(function(t){if(!t.ok)throw new Error("Verification request failed: "+t.status+" "+t.statusText);return Promise.resolve(t.json()).then(function(t){return t.preimage&&(e.preimage=t.preimage),t.settled})})}()}catch(e){return r(e)}return n&&n.then?n.then(void 0,r):n}(0,function(e){return console.error("Failed to check LNURL-verify",e),!1}))}catch(e){return Promise.reject(e)}},t.hasExpired=function(){var e=this.expiryDate;return!!e&&e.getTime()<Date.now()},e}(),H=function(e,t){var r=e.satoshi,n=e.comment,o=e.p,s=e.e,i=e.relays;void 0===t&&(t={});try{var a=t.nostr||globalThis.nostr;if(!a)throw new Error("nostr option or window.nostr is not available");var c=[["relays"].concat(i),["amount",r.toString()]];return o&&c.push(["p",o]),s&&c.push(["e",s]),Promise.resolve(a.getPublicKey()).then(function(e){var t={pubkey:e,created_at:Math.floor(Date.now()/1e3),kind:9734,tags:c,content:null!=n?n:""};return t.id=C(t),Promise.resolve(a.signEvent(t))})}catch(s){return Promise.reject(s)}},O=function(e){if("keysend"!==e.tag)throw new Error("Invalid keysend params");if("OK"!==e.status)throw new Error("Keysend status not OK");if(!e.pubkey)throw new Error("Pubkey does not exist");var t,r;return e.customData&&e.customData[0]&&(t=e.customData[0].customKey,r=e.customData[0].customValue),{destination:e.pubkey,customKey:t,customValue:r}};function F(e){if("string"!=typeof e.content)return!1;if("number"!=typeof e.created_at)return!1;if(!Array.isArray(e.tags))return!1;for(var t=0;t<e.tags.length;t++){var r=e.tags[t];if(!Array.isArray(r))return!1;for(var n=0;n<r.length;n++)if("object"==typeof r[n])return!1}return!0}function K(e){if(!F(e))throw new Error("can't serialize event with wrong or missing properties");return JSON.stringify([0,e.pubkey,e.created_at,e.kind,e.tags,e.content])}function C(e){return U(W(K(e)))}function V(e,t){var r,n,o,s;return t&&e&&(n=(r=null==(o=e.names)?void 0:o[t])?null==(s=e.relays)?void 0:s[r]:void 0),[e,r,n]}var q=/((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=+$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=+$,\w]+@)[A-Za-z0-9.-]+)((?:\/[+~%/.\w-_]*)?\??(?:[-+=&;%@.\w_]*)#?(?:[\w]*))?)/,z=function(e){return!!e&&q.test(e)},M=function(e){var t=e.amount;return t>0&&t>=e.min&&t<=e.max},G=function(e){try{if("payRequest"!==e.tag)throw new Error("Invalid pay service params");var t=(e.callback+"").trim();if(!z(t))throw new Error("Callback must be a valid url");var r,n,o=Math.ceil(Number(e.minSendable||0)),s=Math.floor(Number(e.maxSendable));if(!o||!s||o>s)throw new Error("Invalid pay service params");try{r=JSON.parse(e.metadata+""),n=U(W(e.metadata+""))}catch(e){r=[],n=U(W("[]"))}for(var i="",a="",c="",u="",h=0;h<r.length;h++){var l=r[h],f=l[0],d=l[1];switch(f){case"text/plain":c=d;break;case"text/identifier":u=d;break;case"text/email":i=d;break;case"image/png;base64":case"image/jpeg;base64":a="data:"+f+","+d}}var p,m=e.payerData;try{p=new URL(t).hostname}catch(e){}return Promise.resolve({callback:t,fixed:o===s,min:o,max:s,domain:p,metadata:r,metadataHash:n,identifier:u,email:i,description:c,image:a,payerData:m,commentAllowed:Number(e.commentAllowed)||0,rawData:e,allowsNostr:e.allowsNostr||!1})}catch(e){return Promise.reject(e)}};function J(){return J=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},J.apply(this,arguments)}var Z=function(e,t){try{var r=e.boost;t||(t={});var n=t.webln||globalThis.webln;if(!n)throw new Error("WebLN not available");if(!n.keysend)throw new Error("Keysend not available in current WebLN provider");var o=e.amount||Math.floor(r.value_msat/1e3),s={destination:e.destination,amount:o,customRecords:{7629169:JSON.stringify(r)}};return e.customKey&&e.customValue&&(s.customRecords[e.customKey]=e.customValue),Promise.resolve(n.enable()).then(function(){return Promise.resolve(n.keysend(s))})}catch(e){return Promise.reject(e)}},X=/^((?:[^<>()[\]\\.,;:\s@"]+(?:\.[^<>()[\]\\.,;:\s@"]+)*)|(?:".+"))@((?:\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(?:(?:[a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,Y=/*#__PURE__*/function(){function e(e,t){this.address=void 0,this.options=void 0,this.username=void 0,this.domain=void 0,this.pubkey=void 0,this.lnurlpData=void 0,this.keysendData=void 0,this.nostrData=void 0,this.nostrPubkey=void 0,this.nostrRelays=void 0,this.webln=void 0,this.address=e,this.options={proxy:"https://api.getalby.com/lnurl"},this.options=Object.assign(this.options,t),this.parse(),this.webln=this.options.webln}var t=e.prototype;return t.parse=function(){var e=X.exec(this.address.toLowerCase());e&&(this.username=e[1],this.domain=e[2])},t.getWebLN=function(){return this.webln||globalThis.webln},t.fetch=function(){try{var e=this;return Promise.resolve(e.options.proxy?e.fetchWithProxy():e.fetchWithoutProxy())}catch(e){return Promise.reject(e)}},t.fetchWithProxy=function(){try{var e=this;return Promise.resolve(fetch(e.options.proxy+"/lightning-address-details?"+new URLSearchParams({ln:e.address}).toString())).then(function(t){if(!t.ok)throw new Error("Failed to fetch lnurl info: "+t.status+" "+t.statusText);return Promise.resolve(t.json()).then(function(t){return Promise.resolve(e.parseLnUrlPayResponse(t.lnurlp)).then(function(){e.parseKeysendResponse(t.keysend),e.parseNostrResponse(t.nostr)})})})}catch(e){return Promise.reject(e)}},t.fetchWithoutProxy=function(){try{var e=this;return e.domain&&e.username?Promise.resolve(Promise.all([e.fetchLnurlData(),e.fetchKeysendData(),e.fetchNostrData()])).then(function(){}):Promise.resolve()}catch(e){return Promise.reject(e)}},t.fetchLnurlData=function(){try{var e=this;return Promise.resolve(fetch(e.lnurlpUrl())).then(function(t){var r=function(){if(t.ok)return Promise.resolve(t.json()).then(function(t){return Promise.resolve(e.parseLnUrlPayResponse(t)).then(function(){})})}();if(r&&r.then)return r.then(function(){})})}catch(e){return Promise.reject(e)}},t.fetchKeysendData=function(){try{var e=this;return Promise.resolve(fetch(e.keysendUrl())).then(function(t){var r=function(){if(t.ok)return Promise.resolve(t.json()).then(function(t){e.parseKeysendResponse(t)})}();if(r&&r.then)return r.then(function(){})})}catch(e){return Promise.reject(e)}},t.fetchNostrData=function(){try{var e=this;return Promise.resolve(fetch(e.nostrUrl())).then(function(t){var r=function(){if(t.ok)return Promise.resolve(t.json()).then(function(t){e.parseNostrResponse(t)})}();if(r&&r.then)return r.then(function(){})})}catch(e){return Promise.reject(e)}},t.lnurlpUrl=function(){return"https://"+this.domain+"/.well-known/lnurlp/"+this.username},t.keysendUrl=function(){return"https://"+this.domain+"/.well-known/keysend/"+this.username},t.nostrUrl=function(){return"https://"+this.domain+"/.well-known/nostr.json?name="+this.username},t.generateInvoice=function(e){try{var t,r=function(e){var r=t&&t.pr&&t.pr.toString();if(!r)throw new Error("Invalid pay service invoice");var n={pr:r};if(t&&t.verify&&(n.verify=t.verify.toString()),t&&t.successAction&&"object"==typeof t.successAction){var o=t.successAction,s=o.tag,i=o.description,a=o.url;"message"===s?n.successAction={tag:s,message:o.message}:"url"===s&&(n.successAction={tag:s,description:i,url:a})}return new B(n)},n=this,o=function(){if(n.options.proxy)return Promise.resolve(fetch(n.options.proxy+"/generate-invoice?"+new URLSearchParams(J({ln:n.address},e)).toString())).then(function(e){if(!e.ok)throw new Error("Failed to generate invoice: "+e.status+" "+e.statusText);return Promise.resolve(e.json()).then(function(e){t=e.invoice})});if(!n.lnurlpData)throw new Error("No lnurlpData available. Please call fetch() first.");if(!n.lnurlpData.callback||!z(n.lnurlpData.callback))throw new Error("Valid callback does not exist in lnurlpData");var r=new URL(n.lnurlpData.callback);return r.search=new URLSearchParams(e).toString(),Promise.resolve(fetch(r.toString())).then(function(e){if(!e.ok)throw new Error("Failed to generate invoice: "+e.status+" "+e.statusText);return Promise.resolve(e.json()).then(function(e){t=e})})}();return Promise.resolve(o&&o.then?o.then(r):r())}catch(e){return Promise.reject(e)}},t.requestInvoice=function(e){try{var t=this;if(!t.lnurlpData)throw new Error("No lnurlpData available. Please call fetch() first.");var r=1e3*e.satoshi,n=t.lnurlpData,o=n.commentAllowed;if(!M({amount:r,min:n.min,max:n.max}))throw new Error("Invalid amount");if(e.comment&&o&&o>0&&e.comment.length>o)throw new Error("The comment length must be "+o+" characters or fewer");var s={amount:r.toString()};return e.comment&&(s.comment=e.comment),e.payerdata&&(s.payerdata=JSON.stringify(e.payerdata)),Promise.resolve(t.generateInvoice(s))}catch(e){return Promise.reject(e)}},t.boost=function(e,t){void 0===t&&(t=0);try{var r=this;if(!r.keysendData)throw new Error("No keysendData available. Please call fetch() first.");var n=r.keysendData,o=n.destination,s=n.customKey,i=n.customValue,a=r.getWebLN();if(!a)throw new Error("WebLN not available");return Promise.resolve(Z({destination:o,customKey:s,customValue:i,amount:t,boost:e},{webln:a}))}catch(e){return Promise.reject(e)}},t.zapInvoice=function(e,t){var r=e.satoshi,n=e.comment,o=e.relays,s=e.e;void 0===t&&(t={});try{var i=this;if(!i.lnurlpData)throw new Error("No lnurlpData available. Please call fetch() first.");if(!i.nostrPubkey)throw new Error("Nostr Pubkey is missing");var a=i.nostrPubkey,c=1e3*r,u=i.lnurlpData,h=u.allowsNostr;if(!M({amount:c,min:u.min,max:u.max}))throw new Error("Invalid amount");if(!h)throw new Error("Your provider does not support zaps");return Promise.resolve(H({satoshi:c,comment:n,p:a,e:s,relays:o},t)).then(function(e){var t={amount:c.toString(),nostr:JSON.stringify(e)};return Promise.resolve(i.generateInvoice(t))})}catch(s){return Promise.reject(s)}},t.zap=function(e,t){void 0===t&&(t={});try{var r=this.zapInvoice(e,t),n=this.getWebLN();if(!n)throw new Error("WebLN not available");return Promise.resolve(n.enable()).then(function(){var e=n.sendPayment;return Promise.resolve(r).then(function(t){return e.call(n,t.paymentRequest)})})}catch(e){return Promise.reject(e)}},t.parseLnUrlPayResponse=function(e){try{var t=this,r=function(){if(e)return Promise.resolve(G(e)).then(function(e){t.lnurlpData=e})}();return Promise.resolve(r&&r.then?r.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},t.parseKeysendResponse=function(e){e&&(this.keysendData=O(e))},t.parseNostrResponse=function(e){if(e){var t=V(e,this.username);this.nostrData=t[0],this.nostrPubkey=t[1],this.nostrRelays=t[2]}},e}(),Q=/*#__PURE__*/function(){function e(e){this.storage=void 0,this.storage=e||{}}var t=e.prototype;return t.getItem=function(e){return this.storage[e]},t.setItem=function(e,t){this.storage[e]=t},e}(),ee=/*#__PURE__*/function(){function e(e){}var t=e.prototype;return t.getItem=function(e){return null},t.setItem=function(e,t){},e}(),te=function(e){for(var t,r=e.replace("L402","").replace("LSAT","").trim(),n={},o=/(\w+)=("([^"]*)"|'([^']*)'|([^,]*))/g;null!==(t=o.exec(r));)n[t[1]]=t[3]||t[4]||t[5];return n},re=new Q,ne=function(e,t,r){try{var n,o=function(r){return n?r:(t.headers["Accept-Authenticate"]=s,Promise.resolve(fetch(e,t)).then(function(r){var n=r.headers.get("www-authenticate");if(!n)return r;var o=te(n),c=o.token||o.macaroon,u=o.invoice;return Promise.resolve(i.enable()).then(function(){return Promise.resolve(i.sendPayment(u)).then(function(r){return a.setItem(e,JSON.stringify({token:c,preimage:r.preimage})),t.headers.Authorization=s+" "+c+":"+r.preimage,Promise.resolve(fetch(e,t))})})}))};r||(r={});var s=r.headerKey||"L402",i=r.webln||globalThis.webln;if(!i)throw new Error("WebLN is missing");var a=r.store||re;t||(t={}),t.cache="no-store",t.mode="cors",t.headers||(t.headers={});var c=a.getItem(e),u=function(){if(c){var r=JSON.parse(c);return t.headers.Authorization=s+" "+r.token+":"+r.preimage,Promise.resolve(fetch(e,t)).then(function(e){return n=1,e})}}();return Promise.resolve(u&&u.then?u.then(o):o(u))}catch(e){return Promise.reject(e)}},oe={__proto__:null,fetchWithL402:ne,MemoryStorage:Q,NoStorage:ee,parseL402:te},se=function(e){try{var t="https://getalby.com/api/rates/"+e.toLowerCase()+".json";return Promise.resolve(fetch(t)).then(function(e){if(!e.ok)throw new Error("Failed to fetch rate: "+e.status+" "+e.statusText);return Promise.resolve(e.json()).then(function(e){return e.rate_float/1e8})})}catch(e){return Promise.reject(e)}},ie=function(e){var t=e.satoshi;return Promise.resolve(se(e.currency)).then(function(e){return Number(t)*e})},ae=function(e){var t=e.amount;return Promise.resolve(se(e.currency)).then(function(e){return Math.floor(Number(t)/e)})},ce=function(e){var t=e.currency,r=e.locale;return r||(r="en"),Promise.resolve(ie({satoshi:e.satoshi,currency:t})).then(function(e){return e.toLocaleString(r,{style:"currency",currency:t})})},ue={__proto__:null,getFiatBtcRate:se,getFiatValue:ie,getSatoshiValue:ae,getFormattedFiatValue:ce};exports.DEFAULT_PROXY="https://api.getalby.com/lnurl",exports.Invoice=B,exports.LightningAddress=Y,exports.MemoryStorage=Q,exports.NoStorage=ee,exports.decodeInvoice=x,exports.fetchWithL402=ne,exports.fiat=ue,exports.fromHexString=b,exports.generateZapEvent=H,exports.getEventHash=C,exports.getFiatBtcRate=se,exports.getFiatValue=ie,exports.getFormattedFiatValue=ce,exports.getSatoshiValue=ae,exports.isUrl=z,exports.isValidAmount=M,exports.l402=oe,exports.parseKeysendResponse=O,exports.parseL402=te,exports.parseLnUrlPayResponse=G,exports.parseNostrResponse=V,exports.sendBoostagram=Z,exports.serializeEvent=K,exports.validateEvent=F;
|
package/dist/index.d.ts
DELETED
package/dist/index.modern.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var e,t,r=(e=function(e,t){function r(e){if(!Number.isSafeInteger(e))throw new Error(`Wrong integer: ${e}`)}function n(...e){const t=(e,t)=>r=>e(t(r));return{encode:Array.from(e).reverse().reduce((e,r)=>e?t(e,r.encode):r.encode,void 0),decode:e.reduce((e,r)=>e?t(e,r.decode):r.decode,void 0)}}function o(e){return{encode:t=>{if(!Array.isArray(t)||t.length&&"number"!=typeof t[0])throw new Error("alphabet.encode input should be an array of numbers");return t.map(t=>{if(r(t),t<0||t>=e.length)throw new Error(`Digit index outside alphabet: ${t} (alphabet: ${e.length})`);return e[t]})},decode:t=>{if(!Array.isArray(t)||t.length&&"string"!=typeof t[0])throw new Error("alphabet.decode input should be array of strings");return t.map(t=>{if("string"!=typeof t)throw new Error(`alphabet.decode: not string element=${t}`);const r=e.indexOf(t);if(-1===r)throw new Error(`Unknown letter: "${t}". Allowed: ${e}`);return r})}}}function s(e=""){if("string"!=typeof e)throw new Error("join separator should be string");return{encode:t=>{if(!Array.isArray(t)||t.length&&"string"!=typeof t[0])throw new Error("join.encode input should be array of strings");for(let e of t)if("string"!=typeof e)throw new Error(`join.encode: non-string input=${e}`);return t.join(e)},decode:t=>{if("string"!=typeof t)throw new Error("join.decode input should be string");return t.split(e)}}}function i(e,t="="){if(r(e),"string"!=typeof t)throw new Error("padding chr should be string");return{encode(r){if(!Array.isArray(r)||r.length&&"string"!=typeof r[0])throw new Error("padding.encode input should be array of strings");for(let e of r)if("string"!=typeof e)throw new Error(`padding.encode: non-string input=${e}`);for(;r.length*e%8;)r.push(t);return r},decode(r){if(!Array.isArray(r)||r.length&&"string"!=typeof r[0])throw new Error("padding.encode input should be array of strings");for(let e of r)if("string"!=typeof e)throw new Error(`padding.decode: non-string input=${e}`);let n=r.length;if(n*e%8)throw new Error("Invalid padding: string should have whole number of bytes");for(;n>0&&r[n-1]===t;n--)if(!((n-1)*e%8))throw new Error("Invalid padding: string has too much padding");return r.slice(0,n)}}}function a(e){if("function"!=typeof e)throw new Error("normalize fn should be function");return{encode:e=>e,decode:t=>e(t)}}function c(e,t,n){if(t<2)throw new Error(`convertRadix: wrong from=${t}, base cannot be less than 2`);if(n<2)throw new Error(`convertRadix: wrong to=${n}, base cannot be less than 2`);if(!Array.isArray(e))throw new Error("convertRadix: data should be array");if(!e.length)return[];let o=0;const s=[],i=Array.from(e);for(i.forEach(e=>{if(r(e),e<0||e>=t)throw new Error(`Wrong integer: ${e}`)});;){let e=0,r=!0;for(let s=o;s<i.length;s++){const a=i[s],c=t*e+a;if(!Number.isSafeInteger(c)||t*e/t!==e||c-a!=t*e)throw new Error("convertRadix: carry overflow");if(e=c%n,i[s]=Math.floor(c/n),!Number.isSafeInteger(i[s])||i[s]*n+e!==c)throw new Error("convertRadix: carry overflow");r&&(i[s]?r=!1:o=s)}if(s.push(e),r)break}for(let t=0;t<e.length-1&&0===e[t];t++)s.push(0);return s.reverse()}Object.defineProperty(t,"__esModule",{value:!0}),t.bytes=t.stringToBytes=t.str=t.bytesToString=t.hex=t.utf8=t.bech32m=t.bech32=t.base58check=t.base58xmr=t.base58xrp=t.base58flickr=t.base58=t.base64url=t.base64=t.base32crockford=t.base32hex=t.base32=t.base16=t.utils=t.assertNumber=void 0,t.assertNumber=r;const h=(e,t)=>t?h(t,e%t):e,l=(e,t)=>e+(t-h(e,t));function u(e,t,n,o){if(!Array.isArray(e))throw new Error("convertRadix2: data should be array");if(t<=0||t>32)throw new Error(`convertRadix2: wrong from=${t}`);if(n<=0||n>32)throw new Error(`convertRadix2: wrong to=${n}`);if(l(t,n)>32)throw new Error(`convertRadix2: carry overflow from=${t} to=${n} carryBits=${l(t,n)}`);let s=0,i=0;const a=2**n-1,c=[];for(const o of e){if(r(o),o>=2**t)throw new Error(`convertRadix2: invalid data word=${o} from=${t}`);if(s=s<<t|o,i+t>32)throw new Error(`convertRadix2: carry overflow pos=${i} from=${t}`);for(i+=t;i>=n;i-=n)c.push((s>>i-n&a)>>>0);s&=2**i-1}if(s=s<<n-i&a,!o&&i>=t)throw new Error("Excess padding");if(!o&&s)throw new Error(`Non-zero padding: ${s}`);return o&&i>0&&c.push(s>>>0),c}function f(e){return r(e),{encode:t=>{if(!(t instanceof Uint8Array))throw new Error("radix.encode input should be Uint8Array");return c(Array.from(t),256,e)},decode:t=>{if(!Array.isArray(t)||t.length&&"number"!=typeof t[0])throw new Error("radix.decode input should be array of strings");return Uint8Array.from(c(t,e,256))}}}function d(e,t=!1){if(r(e),e<=0||e>32)throw new Error("radix2: bits should be in (0..32]");if(l(8,e)>32||l(e,8)>32)throw new Error("radix2: carry overflow");return{encode:r=>{if(!(r instanceof Uint8Array))throw new Error("radix2.encode input should be Uint8Array");return u(Array.from(r),8,e,!t)},decode:r=>{if(!Array.isArray(r)||r.length&&"number"!=typeof r[0])throw new Error("radix2.decode input should be array of strings");return Uint8Array.from(u(r,e,8,t))}}}function p(e){if("function"!=typeof e)throw new Error("unsafeWrapper fn should be function");return function(...t){try{return e.apply(null,t)}catch(e){}}}function w(e,t){if(r(e),"function"!=typeof t)throw new Error("checksum fn should be function");return{encode(r){if(!(r instanceof Uint8Array))throw new Error("checksum.encode: input should be Uint8Array");const n=t(r).slice(0,e),o=new Uint8Array(r.length+e);return o.set(r),o.set(n,r.length),o},decode(r){if(!(r instanceof Uint8Array))throw new Error("checksum.decode: input should be Uint8Array");const n=r.slice(0,-e),o=t(n).slice(0,e),s=r.slice(-e);for(let t=0;t<e;t++)if(o[t]!==s[t])throw new Error("Invalid checksum");return n}}}t.utils={alphabet:o,chain:n,checksum:w,radix:f,radix2:d,join:s,padding:i},t.base16=n(d(4),o("0123456789ABCDEF"),s("")),t.base32=n(d(5),o("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),i(5),s("")),t.base32hex=n(d(5),o("0123456789ABCDEFGHIJKLMNOPQRSTUV"),i(5),s("")),t.base32crockford=n(d(5),o("0123456789ABCDEFGHJKMNPQRSTVWXYZ"),s(""),a(e=>e.toUpperCase().replace(/O/g,"0").replace(/[IL]/g,"1"))),t.base64=n(d(6),o("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),i(6),s("")),t.base64url=n(d(6),o("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),i(6),s(""));const y=e=>n(f(58),o(e),s(""));t.base58=y("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"),t.base58flickr=y("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"),t.base58xrp=y("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz");const m=[0,2,3,5,6,7,9,10,11];t.base58xmr={encode(e){let r="";for(let n=0;n<e.length;n+=8){const o=e.subarray(n,n+8);r+=t.base58.encode(o).padStart(m[o.length],"1")}return r},decode(e){let r=[];for(let n=0;n<e.length;n+=11){const o=e.slice(n,n+11),s=m.indexOf(o.length),i=t.base58.decode(o);for(let e=0;e<i.length-s;e++)if(0!==i[e])throw new Error("base58xmr: wrong padding");r=r.concat(Array.from(i.slice(i.length-s)))}return Uint8Array.from(r)}},t.base58check=e=>n(w(4,t=>e(e(t))),t.base58);const g=n(o("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),s("")),b=[996825010,642813549,513874426,1027748829,705979059];function v(e){const t=e>>25;let r=(33554431&e)<<5;for(let e=0;e<b.length;e++)1==(t>>e&1)&&(r^=b[e]);return r}function E(e,t,r=1){const n=e.length;let o=1;for(let t=0;t<n;t++){const r=e.charCodeAt(t);if(r<33||r>126)throw new Error(`Invalid prefix (${e})`);o=v(o)^r>>5}o=v(o);for(let t=0;t<n;t++)o=v(o)^31&e.charCodeAt(t);for(let e of t)o=v(o)^e;for(let e=0;e<6;e++)o=v(o);return o^=r,g.encode(u([o%2**30],30,5,!1))}function x(e){const t="bech32"===e?1:734539939,r=d(5),n=r.decode,o=r.encode,s=p(n);function i(e,r=90){if("string"!=typeof e)throw new Error("bech32.decode input should be string, not "+typeof e);if(e.length<8||!1!==r&&e.length>r)throw new TypeError(`Wrong string length: ${e.length} (${e}). Expected (8..${r})`);const n=e.toLowerCase();if(e!==n&&e!==e.toUpperCase())throw new Error("String must be lowercase or uppercase");const o=(e=n).lastIndexOf("1");if(0===o||-1===o)throw new Error('Letter "1" must be present between prefix and data only');const s=e.slice(0,o),i=e.slice(o+1);if(i.length<6)throw new Error("Data must be at least 6 characters long");const a=g.decode(i).slice(0,-6),c=E(s,a,t);if(!i.endsWith(c))throw new Error(`Invalid checksum in ${e}: expected "${c}"`);return{prefix:s,words:a}}return{encode:function(e,r,n=90){if("string"!=typeof e)throw new Error("bech32.encode prefix should be string, not "+typeof e);if(!Array.isArray(r)||r.length&&"number"!=typeof r[0])throw new Error("bech32.encode words should be array of numbers, not "+typeof r);const o=e.length+7+r.length;if(!1!==n&&o>n)throw new TypeError(`Length ${o} exceeds limit ${n}`);return`${e=e.toLowerCase()}1${g.encode(r)}${E(e,r,t)}`},decode:i,decodeToBytes:function(e){const{prefix:t,words:r}=i(e,!1);return{prefix:t,words:r,bytes:n(r)}},decodeUnsafe:p(i),fromWords:n,fromWordsUnsafe:s,toWords:o}}t.bech32=x("bech32"),t.bech32m=x("bech32m"),t.utf8={encode:e=>(new TextDecoder).decode(e),decode:e=>(new TextEncoder).encode(e)},t.hex=n(d(4),o("0123456789abcdef"),s(""),a(e=>{if("string"!=typeof e||e.length%2)throw new TypeError(`hex.decode: expected string, got ${typeof e} with length ${e.length}`);return e.toLowerCase()}));const A={utf8:t.utf8,hex:t.hex,base16:t.base16,base32:t.base32,base64:t.base64,base64url:t.base64url,base58:t.base58,base58xmr:t.base58xmr},k=`Invalid encoding type. Available types: ${Object.keys(A).join(", ")}`;t.bytesToString=(e,t)=>{if("string"!=typeof e||!A.hasOwnProperty(e))throw new TypeError(k);if(!(t instanceof Uint8Array))throw new TypeError("bytesToString() expects Uint8Array");return A[e].encode(t)},t.str=t.bytesToString,t.stringToBytes=(e,t)=>{if(!A.hasOwnProperty(e))throw new TypeError(k);if("string"!=typeof t)throw new TypeError("stringToBytes() expects string");return A[e].decode(t)},t.bytes=t.stringToBytes},e(t={exports:{}},t.exports),t.exports);const{bech32:n,hex:o,utf8:s}=r,i={bech32:"bc",pubKeyHash:0,scriptHash:5,validWitnessVersions:[0]},a={bech32:"tb",pubKeyHash:111,scriptHash:196,validWitnessVersions:[0]},c={bech32:"tbs",pubKeyHash:111,scriptHash:196,validWitnessVersions:[0]},h={bech32:"bcrt",pubKeyHash:111,scriptHash:196,validWitnessVersions:[0]},l={bech32:"sb",pubKeyHash:63,scriptHash:123,validWitnessVersions:[0]},u=["option_data_loss_protect","initial_routing_sync","option_upfront_shutdown_script","gossip_queries","var_onion_optin","gossip_queries_ex","option_static_remotekey","payment_secret","basic_mpp","option_support_large_channel"],f={m:BigInt(1e3),u:BigInt(1e6),n:BigInt(1e9),p:BigInt(1e12)},d=BigInt("2100000000000000000"),p=BigInt(1e11),w={payment_hash:1,payment_secret:16,description:13,payee:19,description_hash:23,expiry:6,min_final_cltv_expiry:24,fallback_address:9,route_hint:3,feature_bits:5,metadata:27},y={};for(let e=0,t=Object.keys(w);e<t.length;e++){const r=t[e],n=w[t[e]].toString();y[n]=r}const m={1:e=>o.encode(n.fromWordsUnsafe(e)),16:e=>o.encode(n.fromWordsUnsafe(e)),13:e=>s.encode(n.fromWordsUnsafe(e)),19:e=>o.encode(n.fromWordsUnsafe(e)),23:e=>o.encode(n.fromWordsUnsafe(e)),27:e=>o.encode(n.fromWordsUnsafe(e)),6:b,24:b,3:function(e){const t=[];let r,s,i,a,c,h=n.fromWordsUnsafe(e);for(;h.length>0;)r=o.encode(h.slice(0,33)),s=o.encode(h.slice(33,41)),i=parseInt(o.encode(h.slice(41,45)),16),a=parseInt(o.encode(h.slice(45,49)),16),c=parseInt(o.encode(h.slice(49,51)),16),h=h.slice(51),t.push({pubkey:r,short_channel_id:s,fee_base_msat:i,fee_proportional_millionths:a,cltv_expiry_delta:c});return t},5:function(e){const t=e.slice().reverse().map(e=>[!!(1&e),!!(2&e),!!(4&e),!!(8&e),!!(16&e)]).reduce((e,t)=>e.concat(t),[]);for(;t.length<2*u.length;)t.push(!1);const r={};u.forEach((e,n)=>{let o;o=t[2*n]?"required":t[2*n+1]?"supported":"unsupported",r[e]=o});const n=t.slice(2*u.length);return r.extra_bits={start_bit:2*u.length,bits:n,has_required:n.reduce((e,t,r)=>r%2!=0?e||!1:e||t,!1)},r}};function g(e){return t=>({tagCode:parseInt(e),words:n.encode("unknown",t,Number.MAX_SAFE_INTEGER)})}function b(e){return e.reverse().reduce((e,t,r)=>e+t*Math.pow(32,r),0)}const v=e=>Uint8Array.from(e.match(/.{1,2}/g).map(e=>parseInt(e,16))),E=e=>{if(!e)return null;try{const t=function(e,t){if("string"!=typeof e)throw new Error("Lightning Payment Request must be string");if("ln"!==e.slice(0,2).toLowerCase())throw new Error("Not a proper lightning payment request");const r=[],s=n.decode(e,Number.MAX_SAFE_INTEGER);e=e.toLowerCase();const u=s.prefix;let v=s.words,E=e.slice(u.length+1),x=v.slice(-104);v=v.slice(0,-104);let A=u.match(/^ln(\S+?)(\d*)([a-zA-Z]?)$/);if(A&&!A[2]&&(A=u.match(/^ln(\S+)$/)),!A)throw new Error("Not a proper lightning payment request");r.push({name:"lightning_network",letters:"ln"});const k=A[1];let $;switch(k){case i.bech32:$=i;break;case a.bech32:$=a;break;case c.bech32:$=c;break;case h.bech32:$=h;break;case l.bech32:$=l}if(!$||$.bech32!==k)throw new Error("Unknown coin bech32 prefix");r.push({name:"coin_network",letters:k,value:$});const _=A[2];let U;_?(U=function(e,t){let r,n;if(e.slice(-1).match(/^[munp]$/))r=e.slice(-1),n=e.slice(0,-1);else{if(e.slice(-1).match(/^[^munp0-9]$/))throw new Error("Not a valid multiplier for the amount");n=e}if(!n.match(/^\d+$/))throw new Error("Not a valid human readable amount");const o=BigInt(n),s=r?o*p/f[r]:o*p;if("p"===r&&o%BigInt(10)!==BigInt(0)||s>d)throw new Error("Amount is outside of valid range");return s.toString()}(_+A[3]),r.push({name:"amount",letters:A[2]+A[3],value:U})):U=null,r.push({name:"separator",letters:"1"});const L=b(v.slice(0,7));let D,N,I,S;for(v=v.slice(7),r.push({name:"timestamp",letters:E.slice(0,7),value:L}),E=E.slice(7);v.length>0;){const e=v[0].toString();D=y[e]||"unknown_tag",N=m[e]||g(e),v=v.slice(1),I=b(v.slice(0,2)),v=v.slice(2),S=v.slice(0,I),v=v.slice(I),r.push({name:D,tag:E[0],letters:E.slice(0,3+I),value:N(S)}),E=E.slice(3+I)}r.push({name:"signature",letters:E.slice(0,104),value:o.encode(n.fromWordsUnsafe(x))}),E=E.slice(104),r.push({name:"checksum",letters:E});let R={paymentRequest:e,sections:r,get expiry(){let e=r.find(e=>"expiry"===e.name);if(e)return P("timestamp")+e.value},get route_hints(){return r.filter(e=>"route_hint"===e.name).map(e=>e.value)}};for(let e in w)"route_hint"!==e&&Object.defineProperty(R,e,{get:()=>P(e)});return R;function P(e){let t=r.find(t=>t.name===e);return t?t.value:void 0}}(e);if(!t||!t.sections)return null;const r=t.sections.find(e=>"payment_hash"===e.name);if("payment_hash"!==(null==r?void 0:r.name)||!r.value)return null;const s=r.value;let u=0;const v=t.sections.find(e=>"amount"===e.name);"amount"===(null==v?void 0:v.name)&&v.value&&(u=parseInt(v.value)/1e3);const E=t.sections.find(e=>"timestamp"===e.name);if("timestamp"!==(null==E?void 0:E.name)||!E.value)return null;const x=E.value;let A;const k=t.sections.find(e=>"expiry"===e.name);"expiry"===(null==k?void 0:k.name)&&(A=k.value);const $=t.sections.find(e=>"description"===e.name);return{paymentHash:s,satoshi:u,timestamp:x,expiry:A,description:"description"===(null==$?void 0:$.name)?null==$?void 0:$.value:void 0}}catch(e){return null}};function x(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}const A=e=>e instanceof Uint8Array,k=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),$=(e,t)=>e<<32-t|e>>>t;if(68!==new Uint8Array(new Uint32Array([287454020]).buffer)[0])throw new Error("Non little-endian hardware is not supported");const _=/* @__PURE__ */Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function U(e){if(!A(e))throw new Error("Uint8Array expected");let t="";for(let r=0;r<e.length;r++)t+=_[e[r]];return t}function L(e){if("string"==typeof e&&(e=function(e){if("string"!=typeof e)throw new Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array((new TextEncoder).encode(e))}(e)),!A(e))throw new Error("expected Uint8Array, got "+typeof e);return e}class D{clone(){return this._cloneInto()}}function N(e){const t=t=>e().update(L(t)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}class I extends D{constructor(e,t,r,n){super(),this.blockLen=e,this.outputLen=t,this.padOffset=r,this.isLE=n,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=k(this.buffer)}update(e){x(this);const{view:t,buffer:r,blockLen:n}=this,o=(e=L(e)).length;for(let s=0;s<o;){const i=Math.min(n-this.pos,o-s);if(i!==n)r.set(e.subarray(s,s+i),this.pos),this.pos+=i,s+=i,this.pos===n&&(this.process(t,0),this.pos=0);else{const t=k(e);for(;n<=o-s;s+=n)this.process(t,s)}}return this.length+=e.length,this.roundClean(),this}digestInto(e){x(this),function(e,t){!function(e,...t){if(!(e instanceof Uint8Array))throw new Error("Expected Uint8Array");if(t.length>0&&!t.includes(e.length))throw new Error(`Expected Uint8Array of length ${t}, not of length=${e.length}`)}(e);const r=t.outputLen;if(e.length<r)throw new Error(`digestInto() expects output buffer of length at least ${r}`)}(e,this),this.finished=!0;const{buffer:t,view:r,blockLen:n,isLE:o}=this;let{pos:s}=this;t[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>n-s&&(this.process(r,0),s=0);for(let e=s;e<n;e++)t[e]=0;!function(e,t,r,n){if("function"==typeof e.setBigUint64)return e.setBigUint64(t,r,n);const o=BigInt(32),s=BigInt(4294967295),i=Number(r>>o&s),a=Number(r&s),c=n?0:4;e.setUint32(t+(n?4:0),i,n),e.setUint32(t+c,a,n)}(r,n-8,BigInt(8*this.length),o),this.process(r,0);const i=k(e),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const c=a/4,h=this.get();if(c>h.length)throw new Error("_sha2: outputLen bigger than state");for(let e=0;e<c;e++)i.setUint32(4*e,h[e],o)}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const r=e.slice(0,t);return this.destroy(),r}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:t,buffer:r,length:n,finished:o,destroyed:s,pos:i}=this;return e.length=n,e.pos=i,e.finished=o,e.destroyed=s,n%t&&e.buffer.set(r),e}}const S=(e,t,r)=>e&t^e&r^t&r,R=/* @__PURE__ */new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),P=/* @__PURE__ */new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),T=/* @__PURE__ */new Uint32Array(64);class W extends I{constructor(){super(64,32,8,!1),this.A=0|P[0],this.B=0|P[1],this.C=0|P[2],this.D=0|P[3],this.E=0|P[4],this.F=0|P[5],this.G=0|P[6],this.H=0|P[7]}get(){const{A:e,B:t,C:r,D:n,E:o,F:s,G:i,H:a}=this;return[e,t,r,n,o,s,i,a]}set(e,t,r,n,o,s,i,a){this.A=0|e,this.B=0|t,this.C=0|r,this.D=0|n,this.E=0|o,this.F=0|s,this.G=0|i,this.H=0|a}process(e,t){for(let r=0;r<16;r++,t+=4)T[r]=e.getUint32(t,!1);for(let e=16;e<64;e++){const t=T[e-15],r=T[e-2],n=$(t,7)^$(t,18)^t>>>3,o=$(r,17)^$(r,19)^r>>>10;T[e]=o+T[e-7]+n+T[e-16]|0}let{A:r,B:n,C:o,D:s,E:i,F:a,G:c,H:h}=this;for(let e=0;e<64;e++){const t=h+($(i,6)^$(i,11)^$(i,25))+((l=i)&a^~l&c)+R[e]+T[e]|0,u=($(r,2)^$(r,13)^$(r,22))+S(r,n,o)|0;h=c,c=a,a=i,i=s+t|0,s=o,o=n,n=r,r=t+u|0}var l;r=r+this.A|0,n=n+this.B|0,o=o+this.C|0,s=s+this.D|0,i=i+this.E|0,a=a+this.F|0,c=c+this.G|0,h=h+this.H|0,this.set(r,n,o,s,i,a,c,h)}roundClean(){T.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}const B=/* @__PURE__ */N(()=>new W);class j{constructor(e){var t,r,n,o;if(this.paymentRequest=void 0,this.paymentHash=void 0,this.preimage=void 0,this.verify=void 0,this.satoshi=void 0,this.expiry=void 0,this.timestamp=void 0,this.createdDate=void 0,this.expiryDate=void 0,this.description=void 0,this.successAction=void 0,this.paymentRequest=e.pr,!this.paymentRequest)throw new Error("Invalid payment request");const s=E(this.paymentRequest);if(!s)throw new Error("Failed to decode payment request");this.paymentHash=s.paymentHash,this.satoshi=s.satoshi,this.timestamp=s.timestamp,this.expiry=s.expiry,this.createdDate=new Date(1e3*this.timestamp),this.expiryDate=this.expiry?new Date(1e3*(this.timestamp+this.expiry)):void 0,this.description=null!=(t=s.description)?t:null,this.verify=null!=(r=e.verify)?r:null,this.preimage=null!=(n=e.preimage)?n:null,this.successAction=null!=(o=e.successAction)?o:null}async isPaid(){if(this.preimage)return this.validatePreimage(this.preimage);if(this.verify)return await this.verifyPayment();throw new Error("Could not verify payment")}validatePreimage(e){if(!e||!this.paymentHash)return!1;try{const t=U(B(v(e)));return this.paymentHash===t}catch(e){return!1}}async verifyPayment(){try{if(!this.verify)throw new Error("LNURL verify not available");const e=await fetch(this.verify);if(!e.ok)throw new Error(`Verification request failed: ${e.status} ${e.statusText}`);const t=await e.json();return t.preimage&&(this.preimage=t.preimage),t.settled}catch(e){return console.error("Failed to check LNURL-verify",e),!1}}hasExpired(){const{expiryDate:e}=this;return!!e&&e.getTime()<Date.now()}}const H=e=>{if("keysend"!==e.tag)throw new Error("Invalid keysend params");if("OK"!==e.status)throw new Error("Keysend status not OK");if(!e.pubkey)throw new Error("Pubkey does not exist");let t,r;return e.customData&&e.customData[0]&&(t=e.customData[0].customKey,r=e.customData[0].customValue),{destination:e.pubkey,customKey:t,customValue:r}};async function O({satoshi:e,comment:t,p:r,e:n,relays:o},s={}){const i=s.nostr||globalThis.nostr;if(!i)throw new Error("nostr option or window.nostr is not available");const a=[["relays",...o],["amount",e.toString()]];r&&a.push(["p",r]),n&&a.push(["e",n]);const c={pubkey:await i.getPublicKey(),created_at:Math.floor(Date.now()/1e3),kind:9734,tags:a,content:null!=t?t:""};return c.id=F(c),await i.signEvent(c)}function C(e){if("string"!=typeof e.content)return!1;if("number"!=typeof e.created_at)return!1;if(!Array.isArray(e.tags))return!1;for(let t=0;t<e.tags.length;t++){const r=e.tags[t];if(!Array.isArray(r))return!1;for(let e=0;e<r.length;e++)if("object"==typeof r[e])return!1}return!0}function K(e){if(!C(e))throw new Error("can't serialize event with wrong or missing properties");return JSON.stringify([0,e.pubkey,e.created_at,e.kind,e.tags,e.content])}function F(e){return U(B(K(e)))}function V(e,t){let r,n;var o,s;return t&&e&&(r=null==(o=e.names)?void 0:o[t],n=r?null==(s=e.relays)?void 0:s[r]:void 0),[e,r,n]}const q=/((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=+$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=+$,\w]+@)[A-Za-z0-9.-]+)((?:\/[+~%/.\w-_]*)?\??(?:[-+=&;%@.\w_]*)#?(?:[\w]*))?)/,z=e=>!!e&&q.test(e),M=({amount:e,min:t,max:r})=>e>0&&e>=t&&e<=r,G=async e=>{if("payRequest"!==e.tag)throw new Error("Invalid pay service params");const t=(e.callback+"").trim();if(!z(t))throw new Error("Callback must be a valid url");const r=Math.ceil(Number(e.minSendable||0)),n=Math.floor(Number(e.maxSendable));if(!r||!n||r>n)throw new Error("Invalid pay service params");let o,s;try{o=JSON.parse(e.metadata+""),s=U(B(e.metadata+""))}catch(e){o=[],s=U(B("[]"))}let i="",a="",c="",h="";for(let e=0;e<o.length;e++){const[t,r]=o[e];switch(t){case"text/plain":c=r;break;case"text/identifier":h=r;break;case"text/email":i=r;break;case"image/png;base64":case"image/jpeg;base64":a="data:"+t+","+r}}const l=e.payerData;let u;try{u=new URL(t).hostname}catch(e){}return{callback:t,fixed:r===n,min:r,max:n,domain:u,metadata:o,metadataHash:s,identifier:h,email:i,description:c,image:a,payerData:l,commentAllowed:Number(e.commentAllowed)||0,rawData:e,allowsNostr:e.allowsNostr||!1}};function J(){return J=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},J.apply(this,arguments)}const Z=async(e,t)=>{const{boost:r}=e;t||(t={});const n=t.webln||globalThis.webln;if(!n)throw new Error("WebLN not available");if(!n.keysend)throw new Error("Keysend not available in current WebLN provider");const o=e.amount||Math.floor(r.value_msat/1e3),s={destination:e.destination,amount:o,customRecords:{7629169:JSON.stringify(r)}};return e.customKey&&e.customValue&&(s.customRecords[e.customKey]=e.customValue),await n.enable(),await n.keysend(s)},X=/^((?:[^<>()[\]\\.,;:\s@"]+(?:\.[^<>()[\]\\.,;:\s@"]+)*)|(?:".+"))@((?:\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(?:(?:[a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,Q="https://api.getalby.com/lnurl";class Y{constructor(e,t){this.address=void 0,this.options=void 0,this.username=void 0,this.domain=void 0,this.pubkey=void 0,this.lnurlpData=void 0,this.keysendData=void 0,this.nostrData=void 0,this.nostrPubkey=void 0,this.nostrRelays=void 0,this.webln=void 0,this.address=e,this.options={proxy:"https://api.getalby.com/lnurl"},this.options=Object.assign(this.options,t),this.parse(),this.webln=this.options.webln}parse(){const e=X.exec(this.address.toLowerCase());e&&(this.username=e[1],this.domain=e[2])}getWebLN(){return this.webln||globalThis.webln}async fetch(){return this.options.proxy?this.fetchWithProxy():this.fetchWithoutProxy()}async fetchWithProxy(){const e=await fetch(`${this.options.proxy}/lightning-address-details?${new URLSearchParams({ln:this.address}).toString()}`);if(!e.ok)throw new Error(`Failed to fetch lnurl info: ${e.status} ${e.statusText}`);const t=await e.json();await this.parseLnUrlPayResponse(t.lnurlp),this.parseKeysendResponse(t.keysend),this.parseNostrResponse(t.nostr)}async fetchWithoutProxy(){this.domain&&this.username&&await Promise.all([this.fetchLnurlData(),this.fetchKeysendData(),this.fetchNostrData()])}async fetchLnurlData(){const e=await fetch(this.lnurlpUrl());if(e.ok){const t=await e.json();await this.parseLnUrlPayResponse(t)}}async fetchKeysendData(){const e=await fetch(this.keysendUrl());if(e.ok){const t=await e.json();this.parseKeysendResponse(t)}}async fetchNostrData(){const e=await fetch(this.nostrUrl());if(e.ok){const t=await e.json();this.parseNostrResponse(t)}}lnurlpUrl(){return`https://${this.domain}/.well-known/lnurlp/${this.username}`}keysendUrl(){return`https://${this.domain}/.well-known/keysend/${this.username}`}nostrUrl(){return`https://${this.domain}/.well-known/nostr.json?name=${this.username}`}async generateInvoice(e){let t;if(this.options.proxy){const r=await fetch(`${this.options.proxy}/generate-invoice?${new URLSearchParams(J({ln:this.address},e)).toString()}`);if(!r.ok)throw new Error(`Failed to generate invoice: ${r.status} ${r.statusText}`);t=(await r.json()).invoice}else{if(!this.lnurlpData)throw new Error("No lnurlpData available. Please call fetch() first.");if(!this.lnurlpData.callback||!z(this.lnurlpData.callback))throw new Error("Valid callback does not exist in lnurlpData");const r=new URL(this.lnurlpData.callback);r.search=new URLSearchParams(e).toString();const n=await fetch(r.toString());if(!n.ok)throw new Error(`Failed to generate invoice: ${n.status} ${n.statusText}`);t=await n.json()}const r=t&&t.pr&&t.pr.toString();if(!r)throw new Error("Invalid pay service invoice");const n={pr:r};if(t&&t.verify&&(n.verify=t.verify.toString()),t&&t.successAction&&"object"==typeof t.successAction){const{tag:e,message:r,description:o,url:s}=t.successAction;"message"===e?n.successAction={tag:e,message:r}:"url"===e&&(n.successAction={tag:e,description:o,url:s})}return new j(n)}async requestInvoice(e){if(!this.lnurlpData)throw new Error("No lnurlpData available. Please call fetch() first.");const t=1e3*e.satoshi,{commentAllowed:r,min:n,max:o}=this.lnurlpData;if(!M({amount:t,min:n,max:o}))throw new Error("Invalid amount");if(e.comment&&r&&r>0&&e.comment.length>r)throw new Error(`The comment length must be ${r} characters or fewer`);const s={amount:t.toString()};return e.comment&&(s.comment=e.comment),e.payerdata&&(s.payerdata=JSON.stringify(e.payerdata)),this.generateInvoice(s)}async boost(e,t=0){if(!this.keysendData)throw new Error("No keysendData available. Please call fetch() first.");const{destination:r,customKey:n,customValue:o}=this.keysendData,s=this.getWebLN();if(!s)throw new Error("WebLN not available");return Z({destination:r,customKey:n,customValue:o,amount:t,boost:e},{webln:s})}async zapInvoice({satoshi:e,comment:t,relays:r,e:n},o={}){if(!this.lnurlpData)throw new Error("No lnurlpData available. Please call fetch() first.");if(!this.nostrPubkey)throw new Error("Nostr Pubkey is missing");const s=this.nostrPubkey,i=1e3*e,{allowsNostr:a,min:c,max:h}=this.lnurlpData;if(!M({amount:i,min:c,max:h}))throw new Error("Invalid amount");if(!a)throw new Error("Your provider does not support zaps");const l=await O({satoshi:i,comment:t,p:s,e:n,relays:r},o),u={amount:i.toString(),nostr:JSON.stringify(l)};return await this.generateInvoice(u)}async zap(e,t={}){const r=this.zapInvoice(e,t),n=this.getWebLN();if(!n)throw new Error("WebLN not available");return await n.enable(),n.sendPayment((await r).paymentRequest)}async parseLnUrlPayResponse(e){e&&(this.lnurlpData=await G(e))}parseKeysendResponse(e){e&&(this.keysendData=H(e))}parseNostrResponse(e){e&&([this.nostrData,this.nostrPubkey,this.nostrRelays]=V(e,this.username))}}class ee{constructor(e){this.storage=void 0,this.storage=e||{}}getItem(e){return this.storage[e]}setItem(e,t){this.storage[e]=t}}class te{constructor(e){}getItem(e){return null}setItem(e,t){}}const re=e=>{const t=e.replace("L402","").replace("LSAT","").trim(),r={},n=/(\w+)=("([^"]*)"|'([^']*)'|([^,]*))/g;let o;for(;null!==(o=n.exec(t));)r[o[1]]=o[3]||o[4]||o[5];return r},ne=new ee,oe=async(e,t,r)=>{r||(r={});const n=r.headerKey||"L402",o=r.webln||globalThis.webln;if(!o)throw new Error("WebLN is missing");const s=r.store||ne;t||(t={}),t.cache="no-store",t.mode="cors",t.headers||(t.headers={});const i=s.getItem(e);if(i){const r=JSON.parse(i);return t.headers.Authorization=`${n} ${r.token}:${r.preimage}`,await fetch(e,t)}t.headers["Accept-Authenticate"]=n;const a=await fetch(e,t),c=a.headers.get("www-authenticate");if(!c)return a;const h=re(c),l=h.token||h.macaroon,u=h.invoice;await o.enable();const f=await o.sendPayment(u);return s.setItem(e,JSON.stringify({token:l,preimage:f.preimage})),t.headers.Authorization=`${n} ${l}:${f.preimage}`,await fetch(e,t)};var se={__proto__:null,fetchWithL402:oe,MemoryStorage:ee,NoStorage:te,parseL402:re};const ie=async e=>{const t="https://getalby.com/api/rates/"+e.toLowerCase()+".json",r=await fetch(t);if(!r.ok)throw new Error(`Failed to fetch rate: ${r.status} ${r.statusText}`);return(await r.json()).rate_float/1e8},ae=async({satoshi:e,currency:t})=>{const r=await ie(t);return Number(e)*r},ce=async({amount:e,currency:t})=>{const r=await ie(t);return Math.floor(Number(e)/r)},he=async({satoshi:e,currency:t,locale:r})=>(r||(r="en"),(await ae({satoshi:e,currency:t})).toLocaleString(r,{style:"currency",currency:t}));var le={__proto__:null,getFiatBtcRate:ie,getFiatValue:ae,getSatoshiValue:ce,getFormattedFiatValue:he};export{Q as DEFAULT_PROXY,j as Invoice,Y as LightningAddress,ee as MemoryStorage,te as NoStorage,E as decodeInvoice,oe as fetchWithL402,le as fiat,v as fromHexString,O as generateZapEvent,F as getEventHash,ie as getFiatBtcRate,ae as getFiatValue,he as getFormattedFiatValue,ce as getSatoshiValue,z as isUrl,M as isValidAmount,se as l402,H as parseKeysendResponse,re as parseL402,G as parseLnUrlPayResponse,V as parseNostrResponse,Z as sendBoostagram,K as serializeEvent,C as validateEvent};
|