nostr-core 0.6.0 → 0.8.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 CHANGED
@@ -1,9 +1,20 @@
1
- # nostr-core
1
+ # nostr-core - Dead-simple & vendor-neutral
2
2
 
3
- Dead-simple, vendor-neutral [Nostr Wallet Connect (NWC)](https://github.com/nostr-protocol/nips/blob/master/47.md) client for JavaScript and TypeScript.
3
+ **nostr-core** is a comprehensive JavaScript/TypeScript toolkit for building engaging [Nostr](https://nostr.com) applications. With support for 36+ NIPs out of the box, it covers everything from core protocol primitives to advanced social, payments, and identity features — giving you a single, well-typed foundation to build on.
4
4
 
5
- [Demo](https://nostr-core-demo.netlify.app/)
5
+ **Why nostr-core?**
6
6
 
7
+ * 📡 Protocol Complete - 36+ NIPs implemented and ready to use, from basics to cutting-edge
8
+ * ⚡ NWC & Lightning - First-class Nostr Wallet Connect support for seamless payment flows
9
+ * 🔐 Identity & Auth - Key management, NIP-07 browser signing, and bunker/remote signer support
10
+ * 🎯 Relay Management - Smart relay abstraction with connection pooling and event routing
11
+ * 🛠️ TypeScript Native - Fully typed, modern APIs designed for developer confidence
12
+ * 🧩 Composable - Headless and framework-agnostic; drop it into any stack
13
+ * 📦 Modular - Use only what you need, scale as your app grows
14
+
15
+ **Built for builders who want to ship**, not fight the protocol. [Demo](https://nostr-core-demo.netlify.app/)
16
+
17
+ [Nostr Wallet Connect (NWC)](https://github.com/nostr-protocol/nips/blob/master/47.md)
7
18
  ```ts
8
19
  import { NWC } from 'nostr-core'
9
20
 
@@ -0,0 +1,122 @@
1
+ import { type NostrEvent, type EventTemplate } from './event.js';
2
+ /** BUD-03: User server list (replaceable) */
3
+ export declare const SERVER_LIST_KIND = 10063;
4
+ /** BUD-11: Authorization token */
5
+ export declare const AUTH_KIND = 24242;
6
+ /** Blob metadata returned by Blossom servers. */
7
+ export type BlobDescriptor = {
8
+ url: string;
9
+ sha256: string;
10
+ size: number;
11
+ type?: string;
12
+ uploaded?: number;
13
+ };
14
+ /** Authorization action types for kind 24242. */
15
+ export type BlossomAuthAction = 'get' | 'upload' | 'list' | 'delete' | 'media';
16
+ export declare class BlossomError extends Error {
17
+ code: string;
18
+ status?: number;
19
+ constructor(message: string, code?: string, status?: number);
20
+ }
21
+ /**
22
+ * Create a kind 10063 server list event template (unsigned).
23
+ *
24
+ * Declares which Blossom servers a user prefers for media storage.
25
+ */
26
+ export declare function createServerListEventTemplate(servers: string[]): EventTemplate;
27
+ /**
28
+ * Create and sign a kind 10063 server list event.
29
+ */
30
+ export declare function createServerListEvent(servers: string[], secretKey: Uint8Array): NostrEvent;
31
+ /**
32
+ * Parse a kind 10063 server list event.
33
+ */
34
+ export declare function parseServerList(event: NostrEvent): string[];
35
+ /**
36
+ * Create a kind 24242 Blossom authorization event template (unsigned).
37
+ *
38
+ * @param opts.action - Operation type: get, upload, list, delete, media
39
+ * @param opts.content - Human-readable description (e.g. "Upload Blob")
40
+ * @param opts.expiration - Unix timestamp when the token expires
41
+ * @param opts.hashes - SHA-256 hashes to scope the token to (x tags)
42
+ * @param opts.size - Blob size in bytes
43
+ * @param opts.servers - Server URLs to restrict the token to
44
+ */
45
+ export declare function createAuthEventTemplate(opts: {
46
+ action: BlossomAuthAction;
47
+ content: string;
48
+ expiration: number;
49
+ hashes?: string[];
50
+ size?: number;
51
+ servers?: string[];
52
+ }): EventTemplate;
53
+ /**
54
+ * Create and sign a kind 24242 Blossom authorization event.
55
+ */
56
+ export declare function createAuthEvent(opts: Parameters<typeof createAuthEventTemplate>[0], secretKey: Uint8Array): NostrEvent;
57
+ /**
58
+ * Encode a signed kind 24242 event as a Blossom Authorization header value.
59
+ *
60
+ * Format: `Nostr <base64url-no-pad-encoded-event>`
61
+ */
62
+ export declare function getAuthorizationHeader(event: NostrEvent): string;
63
+ /**
64
+ * Upload a blob to a Blossom server (BUD-02).
65
+ *
66
+ * @param serverUrl - Blossom server base URL
67
+ * @param data - Binary data to upload
68
+ * @param authEvent - Signed kind 24242 auth event with action "upload"
69
+ * @param contentType - MIME type (default: application/octet-stream)
70
+ * @returns Blob descriptor from the server
71
+ */
72
+ export declare function uploadBlob(serverUrl: string, data: Uint8Array, authEvent: NostrEvent, contentType?: string): Promise<BlobDescriptor>;
73
+ /**
74
+ * Retrieve a blob from a Blossom server (BUD-01).
75
+ *
76
+ * @param serverUrl - Blossom server base URL
77
+ * @param sha256Hash - SHA-256 hash of the blob (hex)
78
+ * @param ext - Optional file extension (e.g. ".png")
79
+ * @returns The raw blob data
80
+ */
81
+ export declare function getBlob(serverUrl: string, sha256Hash: string, ext?: string): Promise<ArrayBuffer>;
82
+ /**
83
+ * Check if a blob exists on a Blossom server (BUD-01).
84
+ */
85
+ export declare function checkBlob(serverUrl: string, sha256Hash: string): Promise<boolean>;
86
+ /**
87
+ * Delete a blob from a Blossom server (BUD-02).
88
+ *
89
+ * @param serverUrl - Blossom server base URL
90
+ * @param sha256Hash - SHA-256 hash of the blob to delete (hex)
91
+ * @param authEvent - Signed kind 24242 auth event with action "delete"
92
+ */
93
+ export declare function deleteBlob(serverUrl: string, sha256Hash: string, authEvent: NostrEvent): Promise<void>;
94
+ /**
95
+ * List blobs uploaded by a pubkey (BUD-02).
96
+ *
97
+ * @param serverUrl - Blossom server base URL
98
+ * @param pubkey - Hex public key
99
+ * @param opts.cursor - SHA-256 hash of last blob for pagination
100
+ * @param opts.limit - Maximum number of results
101
+ * @returns Array of blob descriptors sorted by upload date descending
102
+ */
103
+ export declare function listBlobs(serverUrl: string, pubkey: string, opts?: {
104
+ cursor?: string;
105
+ limit?: number;
106
+ }): Promise<BlobDescriptor[]>;
107
+ /**
108
+ * Mirror a blob from a remote URL to a Blossom server (BUD-04).
109
+ *
110
+ * @param serverUrl - Destination Blossom server base URL
111
+ * @param sourceUrl - Public URL of the blob to mirror
112
+ * @param authEvent - Signed kind 24242 auth event with action "upload"
113
+ * @returns Blob descriptor from the destination server
114
+ */
115
+ export declare function mirrorBlob(serverUrl: string, sourceUrl: string, authEvent: NostrEvent): Promise<BlobDescriptor>;
116
+ /**
117
+ * Compute the SHA-256 hash of a blob (hex).
118
+ *
119
+ * This is the content-addressable identifier used by Blossom servers.
120
+ */
121
+ export declare function getBlobHash(data: Uint8Array): string;
122
+ //# sourceMappingURL=blossom.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"blossom.d.ts","sourceRoot":"","sources":["../src/blossom.ts"],"names":[],"mappings":"AAEA,OAAO,EAAiB,KAAK,UAAU,EAAE,KAAK,aAAa,EAAE,MAAM,YAAY,CAAA;AAI/E,6CAA6C;AAC7C,eAAO,MAAM,gBAAgB,QAAQ,CAAA;AAErC,kCAAkC;AAClC,eAAO,MAAM,SAAS,QAAQ,CAAA;AAI9B,iDAAiD;AACjD,MAAM,MAAM,cAAc,GAAG;IAC3B,GAAG,EAAE,MAAM,CAAA;IACX,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,iDAAiD;AACjD,MAAM,MAAM,iBAAiB,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAA;AAE9E,qBAAa,YAAa,SAAQ,KAAK;IACrC,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,CAAC,EAAE,MAAM,CAAA;gBACH,OAAO,EAAE,MAAM,EAAE,IAAI,SAAkB,EAAE,MAAM,CAAC,EAAE,MAAM;CAMrE;AAID;;;;GAIG;AACH,wBAAgB,6BAA6B,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,aAAa,CAO9E;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,MAAM,EAAE,EACjB,SAAS,EAAE,UAAU,GACpB,UAAU,CAEZ;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM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AAC,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,GACzC,OAAO,CAAC,cAAc,EAAE,CAAC,CAgB3B;AAED;;;;;;;GAOG;AACH,wBAAsB,UAAU,CAC9B,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,UAAU,GACpB,OAAO,CAAC,cAAc,CAAC,CAczB;AAID;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,CAEpD"}
@@ -0,0 +1,237 @@
1
+ import { sha256 } from '@noble/hashes/sha2';
2
+ import { bytesToHex } from '@noble/hashes/utils';
3
+ import { finalizeEvent } from './event.js';
4
+ // ── Event Kinds ────────────────────────────────────────────────────────
5
+ /** BUD-03: User server list (replaceable) */
6
+ export const SERVER_LIST_KIND = 10063;
7
+ /** BUD-11: Authorization token */
8
+ export const AUTH_KIND = 24242;
9
+ export class BlossomError extends Error {
10
+ code;
11
+ status;
12
+ constructor(message, code = 'BLOSSOM_ERROR', status) {
13
+ super(message);
14
+ this.name = 'BlossomError';
15
+ this.code = code;
16
+ this.status = status;
17
+ }
18
+ }
19
+ // ── Server List (kind 10063 / BUD-03) ──────────────────────────────────
20
+ /**
21
+ * Create a kind 10063 server list event template (unsigned).
22
+ *
23
+ * Declares which Blossom servers a user prefers for media storage.
24
+ */
25
+ export function createServerListEventTemplate(servers) {
26
+ return {
27
+ kind: SERVER_LIST_KIND,
28
+ created_at: Math.floor(Date.now() / 1000),
29
+ tags: servers.map(s => ['server', s]),
30
+ content: '',
31
+ };
32
+ }
33
+ /**
34
+ * Create and sign a kind 10063 server list event.
35
+ */
36
+ export function createServerListEvent(servers, secretKey) {
37
+ return finalizeEvent(createServerListEventTemplate(servers), secretKey);
38
+ }
39
+ /**
40
+ * Parse a kind 10063 server list event.
41
+ */
42
+ export function parseServerList(event) {
43
+ if (event.kind !== SERVER_LIST_KIND) {
44
+ throw new Error(`Expected kind ${SERVER_LIST_KIND}, got ${event.kind}`);
45
+ }
46
+ return event.tags
47
+ .filter(t => t[0] === 'server' && t[1])
48
+ .map(t => t[1]);
49
+ }
50
+ // ── Authorization Event (kind 24242 / BUD-11) ─────────────────────────
51
+ /**
52
+ * Create a kind 24242 Blossom authorization event template (unsigned).
53
+ *
54
+ * @param opts.action - Operation type: get, upload, list, delete, media
55
+ * @param opts.content - Human-readable description (e.g. "Upload Blob")
56
+ * @param opts.expiration - Unix timestamp when the token expires
57
+ * @param opts.hashes - SHA-256 hashes to scope the token to (x tags)
58
+ * @param opts.size - Blob size in bytes
59
+ * @param opts.servers - Server URLs to restrict the token to
60
+ */
61
+ export function createAuthEventTemplate(opts) {
62
+ const tags = [
63
+ ['t', opts.action],
64
+ ['expiration', String(opts.expiration)],
65
+ ];
66
+ if (opts.hashes) {
67
+ for (const hash of opts.hashes)
68
+ tags.push(['x', hash]);
69
+ }
70
+ if (opts.size !== undefined) {
71
+ tags.push(['size', String(opts.size)]);
72
+ }
73
+ if (opts.servers) {
74
+ for (const server of opts.servers) {
75
+ try {
76
+ tags.push(['server', new URL(server).hostname.toLowerCase()]);
77
+ }
78
+ catch {
79
+ tags.push(['server', server.toLowerCase()]);
80
+ }
81
+ }
82
+ }
83
+ return {
84
+ kind: AUTH_KIND,
85
+ created_at: Math.floor(Date.now() / 1000),
86
+ tags,
87
+ content: opts.content,
88
+ };
89
+ }
90
+ /**
91
+ * Create and sign a kind 24242 Blossom authorization event.
92
+ */
93
+ export function createAuthEvent(opts, secretKey) {
94
+ return finalizeEvent(createAuthEventTemplate(opts), secretKey);
95
+ }
96
+ // ── Authorization Header ───────────────────────────────────────────────
97
+ /**
98
+ * Encode a signed kind 24242 event as a Blossom Authorization header value.
99
+ *
100
+ * Format: `Nostr <base64url-no-pad-encoded-event>`
101
+ */
102
+ export function getAuthorizationHeader(event) {
103
+ const json = JSON.stringify(event);
104
+ const b64 = btoa(json).replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
105
+ return `Nostr ${b64}`;
106
+ }
107
+ // ── HTTP Operations ────────────────────────────────────────────────────
108
+ function baseUrl(url) {
109
+ return url.replace(/\/$/, '');
110
+ }
111
+ /**
112
+ * Upload a blob to a Blossom server (BUD-02).
113
+ *
114
+ * @param serverUrl - Blossom server base URL
115
+ * @param data - Binary data to upload
116
+ * @param authEvent - Signed kind 24242 auth event with action "upload"
117
+ * @param contentType - MIME type (default: application/octet-stream)
118
+ * @returns Blob descriptor from the server
119
+ */
120
+ export async function uploadBlob(serverUrl, data, authEvent, contentType) {
121
+ const hash = bytesToHex(sha256(data));
122
+ const res = await fetch(`${baseUrl(serverUrl)}/upload`, {
123
+ method: 'PUT',
124
+ headers: {
125
+ 'Authorization': getAuthorizationHeader(authEvent),
126
+ 'Content-Type': contentType || 'application/octet-stream',
127
+ 'X-SHA-256': hash,
128
+ },
129
+ body: data,
130
+ });
131
+ if (!res.ok) {
132
+ const reason = res.headers.get('X-Reason') || (await res.text().catch(() => ''));
133
+ throw new BlossomError(reason || res.statusText, 'UPLOAD_ERROR', res.status);
134
+ }
135
+ return (await res.json());
136
+ }
137
+ /**
138
+ * Retrieve a blob from a Blossom server (BUD-01).
139
+ *
140
+ * @param serverUrl - Blossom server base URL
141
+ * @param sha256Hash - SHA-256 hash of the blob (hex)
142
+ * @param ext - Optional file extension (e.g. ".png")
143
+ * @returns The raw blob data
144
+ */
145
+ export async function getBlob(serverUrl, sha256Hash, ext) {
146
+ const path = ext ? `${sha256Hash}${ext}` : sha256Hash;
147
+ const res = await fetch(`${baseUrl(serverUrl)}/${path}`);
148
+ if (!res.ok) {
149
+ throw new BlossomError(res.headers.get('X-Reason') || res.statusText, 'NOT_FOUND', res.status);
150
+ }
151
+ return res.arrayBuffer();
152
+ }
153
+ /**
154
+ * Check if a blob exists on a Blossom server (BUD-01).
155
+ */
156
+ export async function checkBlob(serverUrl, sha256Hash) {
157
+ try {
158
+ const res = await fetch(`${baseUrl(serverUrl)}/${sha256Hash}`, { method: 'HEAD' });
159
+ return res.ok;
160
+ }
161
+ catch {
162
+ return false;
163
+ }
164
+ }
165
+ /**
166
+ * Delete a blob from a Blossom server (BUD-02).
167
+ *
168
+ * @param serverUrl - Blossom server base URL
169
+ * @param sha256Hash - SHA-256 hash of the blob to delete (hex)
170
+ * @param authEvent - Signed kind 24242 auth event with action "delete"
171
+ */
172
+ export async function deleteBlob(serverUrl, sha256Hash, authEvent) {
173
+ const res = await fetch(`${baseUrl(serverUrl)}/${sha256Hash}`, {
174
+ method: 'DELETE',
175
+ headers: { 'Authorization': getAuthorizationHeader(authEvent) },
176
+ });
177
+ if (!res.ok) {
178
+ const reason = res.headers.get('X-Reason') || (await res.text().catch(() => ''));
179
+ throw new BlossomError(reason || res.statusText, 'DELETE_ERROR', res.status);
180
+ }
181
+ }
182
+ /**
183
+ * List blobs uploaded by a pubkey (BUD-02).
184
+ *
185
+ * @param serverUrl - Blossom server base URL
186
+ * @param pubkey - Hex public key
187
+ * @param opts.cursor - SHA-256 hash of last blob for pagination
188
+ * @param opts.limit - Maximum number of results
189
+ * @returns Array of blob descriptors sorted by upload date descending
190
+ */
191
+ export async function listBlobs(serverUrl, pubkey, opts) {
192
+ const params = new URLSearchParams();
193
+ if (opts?.cursor)
194
+ params.set('cursor', opts.cursor);
195
+ if (opts?.limit)
196
+ params.set('limit', String(opts.limit));
197
+ const qs = params.toString();
198
+ const url = `${baseUrl(serverUrl)}/list/${pubkey}${qs ? `?${qs}` : ''}`;
199
+ const res = await fetch(url);
200
+ if (!res.ok) {
201
+ throw new BlossomError(res.headers.get('X-Reason') || res.statusText, 'LIST_ERROR', res.status);
202
+ }
203
+ return (await res.json());
204
+ }
205
+ /**
206
+ * Mirror a blob from a remote URL to a Blossom server (BUD-04).
207
+ *
208
+ * @param serverUrl - Destination Blossom server base URL
209
+ * @param sourceUrl - Public URL of the blob to mirror
210
+ * @param authEvent - Signed kind 24242 auth event with action "upload"
211
+ * @returns Blob descriptor from the destination server
212
+ */
213
+ export async function mirrorBlob(serverUrl, sourceUrl, authEvent) {
214
+ const res = await fetch(`${baseUrl(serverUrl)}/mirror`, {
215
+ method: 'PUT',
216
+ headers: {
217
+ 'Authorization': getAuthorizationHeader(authEvent),
218
+ 'Content-Type': 'application/json',
219
+ },
220
+ body: JSON.stringify({ url: sourceUrl }),
221
+ });
222
+ if (!res.ok) {
223
+ const reason = res.headers.get('X-Reason') || (await res.text().catch(() => ''));
224
+ throw new BlossomError(reason || res.statusText, 'MIRROR_ERROR', res.status);
225
+ }
226
+ return (await res.json());
227
+ }
228
+ // ── Utilities ──────────────────────────────────────────────────────────
229
+ /**
230
+ * Compute the SHA-256 hash of a blob (hex).
231
+ *
232
+ * This is the content-addressable identifier used by Blossom servers.
233
+ */
234
+ export function getBlobHash(data) {
235
+ return bytesToHex(sha256(data));
236
+ }
237
+ //# sourceMappingURL=blossom.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"blossom.js","sourceRoot":"","sources":["../src/blossom.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAChD,OAAO,EAAE,aAAa,EAAuC,MAAM,YAAY,CAAA;AAE/E,0EAA0E;AAE1E,6CAA6C;AAC7C,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,CAAA;AAErC,kCAAkC;AAClC,MAAM,CAAC,MAAM,SAAS,GAAG,KAAK,CAAA;AAgB9B,MAAM,OAAO,YAAa,SAAQ,KAAK;IACrC,IAAI,CAAQ;IACZ,MAAM,CAAS;IACf,YAAY,OAAe,EAAE,IAAI,GAAG,eAAe,EAAE,MAAe;QAClE,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,cAAc,CAAA;QAC1B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;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,SAAiB,EACjB,SAAiB,EACjB,SAAqB;IAErB,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC,SAAS,EAAE;QACtD,MAAM,EAAE,KAAK;QACb,OAAO,EAAE;YACP,eAAe,EAAE,sBAAsB,CAAC,SAAS,CAAC;YAClD,cAAc,EAAE,kBAAkB;SACnC;QACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC;KACzC,CAAC,CAAA;IACF,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;QACZ,MAAM,MAAM,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,CAAA;QAChF,MAAM,IAAI,YAAY,CAAC,MAAM,IAAI,GAAG,CAAC,UAAU,EAAE,cAAc,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IAC9E,CAAC;IACD,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAmB,CAAA;AAC7C,CAAC;AAED,0EAA0E;AAE1E;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,IAAgB;IAC1C,OAAO,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAA;AACjC,CAAC"}
@@ -0,0 +1,78 @@
1
+ export declare class Bolt11Error extends Error {
2
+ code: string;
3
+ constructor(message: string, code?: string);
4
+ }
5
+ export type Bolt11Network = 'mainnet' | 'testnet' | 'signet' | 'regtest';
6
+ export type Bolt11RouteHint = {
7
+ pubkey: string;
8
+ shortChannelId: string;
9
+ feeBaseMsat: number;
10
+ feeProportionalMillionths: number;
11
+ cltvExpiryDelta: number;
12
+ };
13
+ export type Bolt11FallbackAddress = {
14
+ version: number;
15
+ hex: string;
16
+ };
17
+ export type Bolt11Invoice = {
18
+ /** The canonical lowercase invoice string */
19
+ paymentRequest: string;
20
+ /** HRP prefix (e.g. "lnbc", "lntb") */
21
+ prefix: string;
22
+ /** Bitcoin network */
23
+ network: Bolt11Network;
24
+ /** Amount in millisatoshis (undefined for zero-amount invoices) */
25
+ amountMsat?: number;
26
+ /** Amount in satoshis (undefined for zero-amount invoices) */
27
+ amountSat?: number;
28
+ /** Unix timestamp when invoice was created */
29
+ timestamp: number;
30
+ /** Expiry time in seconds (default 3600) */
31
+ expiry: number;
32
+ /** Absolute expiry timestamp (timestamp + expiry) */
33
+ expiresAt: number;
34
+ /** Whether the invoice has expired at decode time */
35
+ isExpired: boolean;
36
+ /** Payment hash (256-bit, hex) */
37
+ paymentHash: string;
38
+ /** Payment secret (256-bit, hex) */
39
+ paymentSecret?: string;
40
+ /** Short description (UTF-8) */
41
+ description?: string;
42
+ /** SHA-256 hash of a longer description (hex) */
43
+ descriptionHash?: string;
44
+ /** Payee node public key (33-byte compressed, hex) */
45
+ payeeNodeKey?: string;
46
+ /** Minimum final CLTV expiry delta in blocks (default 18) */
47
+ minFinalCltvExpiry: number;
48
+ /** Feature bits */
49
+ featureBits?: Uint8Array;
50
+ /** Payment metadata (hex) */
51
+ metadata?: string;
52
+ /** Route hints for private channels (each entry is one r-tag's hops) */
53
+ routeHints: Bolt11RouteHint[][];
54
+ /** Fallback on-chain addresses */
55
+ fallbackAddresses: Bolt11FallbackAddress[];
56
+ /** Signature R||S (64 bytes, hex) */
57
+ signature: string;
58
+ /** Signature recovery flag (0-3) */
59
+ recoveryFlag: number;
60
+ /** Unrecognized tagged fields */
61
+ unknownTags: {
62
+ tag: number;
63
+ words: number[];
64
+ }[];
65
+ };
66
+ /**
67
+ * Decode a BOLT-11 Lightning invoice.
68
+ *
69
+ * Extracts amount, payment hash, description, expiry, route hints,
70
+ * payee node key, and all other tagged fields from a bech32-encoded
71
+ * Lightning invoice.
72
+ *
73
+ * @param invoice - A BOLT-11 invoice string (e.g. "lnbc10u1p...")
74
+ * @returns Decoded invoice with all fields
75
+ * @throws {Bolt11Error} If the invoice is malformed or missing required fields
76
+ */
77
+ export declare function decode(invoice: string): Bolt11Invoice;
78
+ //# sourceMappingURL=bolt11.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bolt11.d.ts","sourceRoot":"","sources":["../src/bolt11.ts"],"names":[],"mappings":"AAQA,qBAAa,WAAY,SAAQ,KAAK;IACpC,IAAI,EAAE,MAAM,CAAA;gBACA,OAAO,EAAE,MAAM,EAAE,IAAI,SAAiB;CAKnD;AAID,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS,CAAA;AAExE,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,EAAE,MAAM,CAAA;IACd,cAAc,EAAE,MAAM,CAAA;IACtB,WAAW,EAAE,MAAM,CAAA;IACnB,yBAAyB,EAAE,MAAM,CAAA;IACjC,eAAe,EAAE,MAAM,CAAA;CACxB,CAAA;AAED,MAAM,MAAM,qBAAqB,GAAG;IAClC,OAAO,EAAE,MAAM,CAAA;IACf,GAAG,EAAE,MAAM,CAAA;CACZ,CAAA;AAED,MAAM,MAAM,aAAa,GAAG;IAC1B,6CAA6C;IAC7C,cAAc,EAAE,MAAM,CAAA;IACtB,uCAAuC;IACvC,MAAM,EAAE,MAAM,CAAA;IACd,sBAAsB;IACtB,OAAO,EAAE,aAAa,CAAA;IACtB,mEAAmE;IACnE,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,8DAA8D;IAC9D,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,8CAA8C;IAC9C,SAAS,EAAE,MAAM,CAAA;IACjB,4CAA4C;IAC5C,MAAM,EAAE,MAAM,CAAA;IACd,qDAAqD;IACrD,SAAS,EAAE,MAAM,CAAA;IACjB,qDAAqD;IACrD,SAAS,EAAE,OAAO,CAAA;IAClB,kCAAkC;IAClC,WAAW,EAAE,MAAM,CAAA;IACnB,oCAAoC;IACpC,aAAa,CAAC,EAAE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