lnurlcash-kit 0.1.2 → 0.2.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/dist/index.d.ts CHANGED
@@ -1,34 +1,19 @@
1
- declare const isBech32Lnurl: (data: string) => boolean;
2
- declare const toBech32Lnurl: (url: string) => string;
3
- declare const fromBech32Lnurl: (data: string) => string | null;
4
- declare const isAllowedServiceUrl: (value: string) => boolean;
5
- declare const fromLud17: (url: string) => string;
6
- declare const toLud17w: (url: string) => string;
7
- declare const isLightningAddress: (value: string) => boolean;
8
- declare const resolveMintInput: (value: string) => string | null;
9
- declare const mintAddressUrl: (payUrl: string) => string | null;
10
- declare const lightningAddressUsername: (payUrl: string) => string | null;
11
- declare const resolveLnurlInput: (value: string) => string | null;
12
- declare const serverOf: (url: string) => string;
13
-
14
- declare const noteK1: (url: string) => string | null;
15
- declare const requireNoteK1: (url: string) => string;
16
- declare const noteDeclaredAmount: (url: string) => number | null;
17
- declare const noteSignature: (url: string) => string | null;
18
- declare const resolveNoteInput: (value: string) => string | null;
19
- declare const isValidNoteInput: (value: string) => boolean;
20
- declare const buildNoteUrl: (withdrawLink: string, k1: string, amountMsat?: number) => string;
21
- declare const withNewK1: (url: string, k1: string, amountMsat: number, signature?: string) => string;
22
- declare const withoutK1: (url: string, amountMsat: number, signature?: string) => string;
23
-
24
1
  declare const hashK1: (k1: string) => string;
25
2
  type RandomSecret = () => string;
26
3
  declare const defaultRandomSecret: RandomSecret;
27
4
  declare const isPreimage: (value: string) => boolean;
5
+ declare const deriveNoteRoot: (seed: Uint8Array) => Uint8Array;
6
+ declare const deriveNoteSecret: (root: Uint8Array, host: string, index: number) => string;
7
+ declare const derivedSecretSource: (root: Uint8Array, host: string, start?: number) => RandomSecret & {
8
+ index: () => number;
9
+ };
28
10
 
29
- declare const noteSignatureMessage: (k1: string, amountMsat: number) => string;
30
- declare const noteSignatureDigest: (k1: string, amountMsat: number) => Uint8Array;
31
- declare const verifyNoteSignature: (k1: string, amountMsat: number, signatureHex: string, mintPubkeyHex: string) => boolean;
11
+ type LnurlcashOptions = {
12
+ fetch?: typeof globalThis.fetch;
13
+ timeoutMs?: number;
14
+ offline?: boolean;
15
+ randomSecret?: RandomSecret;
16
+ };
32
17
 
33
18
  type MintFee = {
34
19
  baseFeeMsat: number;
@@ -46,45 +31,6 @@ declare const grossUpForMintFee: (netMsat: number, fee: MintFee) => number;
46
31
  declare const formatFeePercent: (ppm: number) => string;
47
32
  declare const describeMintFee: (fee: MintFee) => string;
48
33
 
49
- declare const isBolt11Invoice: (value: string) => boolean;
50
- declare const sameInvoice: (a: string, b: string) => boolean;
51
- declare const decodeBolt11AmountMsat: (pr: string) => number | null;
52
-
53
- declare class LnurlcashError extends Error {
54
- constructor(message: string);
55
- }
56
- declare class RequestRefusedError extends LnurlcashError {
57
- }
58
- declare class ProtocolError extends LnurlcashError {
59
- }
60
- declare class ServiceRejectedError extends LnurlcashError {
61
- readonly reason: string;
62
- constructor(reason: string);
63
- }
64
- declare class PendingNoteError extends ServiceRejectedError {
65
- constructor(reason?: string);
66
- }
67
- declare class NoteSpentError extends ServiceRejectedError {
68
- constructor(reason: string);
69
- }
70
- declare class NoteUnknownError extends ServiceRejectedError {
71
- constructor(reason: string);
72
- }
73
- declare class AmbiguousMintError extends LnurlcashError {
74
- }
75
- declare class AmbiguousMutationError extends AmbiguousMintError {
76
- readonly newSecrets: string[];
77
- constructor(message: string, newSecrets: string[]);
78
- }
79
- declare const classifyNoteError: (reason: string) => ServiceRejectedError;
80
-
81
- type LnurlcashOptions = {
82
- fetch?: typeof globalThis.fetch;
83
- timeoutMs?: number;
84
- offline?: boolean;
85
- randomSecret?: RandomSecret;
86
- };
87
-
88
34
  type WithdrawRequestInfo = {
89
35
  tag: 'withdrawRequest';
90
36
  callback: string;
@@ -96,12 +42,18 @@ type WithdrawRequestInfo = {
96
42
  };
97
43
  declare const fetchNoteInfo: (url: string, options?: LnurlcashOptions) => Promise<WithdrawRequestInfo>;
98
44
  declare const probeBurnedNote: (url: string, options?: LnurlcashOptions) => Promise<"live" | "gone" | "unknown">;
45
+ type MintContact = {
46
+ nostr?: string;
47
+ email?: string;
48
+ url?: string;
49
+ };
99
50
  type MintAddressInfo = {
100
51
  tag: 'withdrawRequest';
101
52
  callback: string;
102
53
  minWithdrawable: number;
103
54
  maxWithdrawable: number;
104
55
  defaultDescription?: string;
56
+ mintPubkey?: string;
105
57
  nodePubkey?: string;
106
58
  payLink: string;
107
59
  nodeAlias?: string;
@@ -110,6 +62,15 @@ type MintAddressInfo = {
110
62
  nodeCapacityMsat?: number;
111
63
  nodeNumChannels?: number;
112
64
  nodeNumPeers?: number;
65
+ name?: string;
66
+ description?: string;
67
+ contact?: MintContact;
68
+ tosUrl?: string;
69
+ motd?: string;
70
+ fees?: MintFee;
71
+ version?: string;
72
+ previousPubkeys?: string[];
73
+ mintToHash?: boolean;
113
74
  };
114
75
  declare const fetchMintAddress: (url: string, options?: LnurlcashOptions) => Promise<MintAddressInfo>;
115
76
  type WithdrawSuccessResponse = {
@@ -163,20 +124,156 @@ type PayRequestInfo = {
163
124
  withdrawLink?: string;
164
125
  mintPubkey?: string;
165
126
  mintFee?: MintFee;
127
+ mintToHash?: boolean;
166
128
  };
167
129
  declare const fetchPayRequest: (url: string, options?: LnurlcashOptions) => Promise<PayRequestInfo>;
168
130
  type InvoiceResult = {
169
131
  pr: string;
170
132
  verify?: string;
171
133
  disposable: boolean;
134
+ mintToHash: boolean;
135
+ };
136
+ type InvoiceRequestOptions = LnurlcashOptions & {
137
+ h?: string;
172
138
  };
173
- declare const requestInvoice: (payCallback: string, amountMsat: number, options?: LnurlcashOptions) => Promise<InvoiceResult>;
139
+ declare const requestInvoice: (payCallback: string, amountMsat: number, options?: InvoiceRequestOptions) => Promise<InvoiceResult>;
174
140
  type VerifyResult = {
175
141
  settled: boolean;
176
142
  preimage: string | null;
177
143
  pr: string;
178
144
  };
179
145
  declare const fetchInvoiceVerification: (verifyUrl: string, options?: LnurlcashOptions) => Promise<VerifyResult>;
146
+ type MintClaim = {
147
+ state: 'minted' | 'unminted' | 'pending' | 'spent';
148
+ k1: string;
149
+ amountMsat: number | null;
150
+ callback: string | null;
151
+ };
152
+ declare const claimMintedNote: (withdrawLink: string, k1: string, options?: LnurlcashOptions) => Promise<MintClaim>;
153
+
154
+ type SettleForValueOptions = {
155
+ mints: string[];
156
+ minMsat: number;
157
+ requireSignature?: boolean;
158
+ };
159
+ type SettledForValue = {
160
+ note: SettledNote;
161
+ newUrl: string;
162
+ };
163
+ declare const settleNoteForValue: (noteUrl: string, { mints, minMsat, requireSignature }: SettleForValueOptions, options?: LnurlcashOptions) => Promise<SettledForValue>;
164
+
165
+ type RestoredNote = {
166
+ index: number;
167
+ k1: string;
168
+ amountMsat: number | null;
169
+ state: 'live' | 'pending';
170
+ };
171
+ type RestoreResult = {
172
+ found: RestoredNote[];
173
+ next: number;
174
+ };
175
+ type RestoreOptions = {
176
+ gap?: number;
177
+ start?: number;
178
+ };
179
+ declare const restoreNotes: (baseUrl: string, root: Uint8Array, host: string, { gap, start }?: RestoreOptions, options?: LnurlcashOptions) => Promise<RestoreResult>;
180
+
181
+ declare const isBech32Lnurl: (data: string) => boolean;
182
+ declare const toBech32Lnurl: (url: string) => string;
183
+ declare const fromBech32Lnurl: (data: string) => string | null;
184
+ declare const isAllowedServiceUrl: (value: string) => boolean;
185
+ declare const fromLud17: (url: string) => string;
186
+ declare const toLud17w: (url: string) => string;
187
+ declare const isLightningAddress: (value: string) => boolean;
188
+ declare const resolveMintInput: (value: string) => string | null;
189
+ declare const mintAddressUrl: (payUrl: string) => string | null;
190
+ declare const lightningAddressUsername: (payUrl: string) => string | null;
191
+ declare const resolveLnurlInput: (value: string) => string | null;
192
+ declare const serverOf: (url: string) => string;
193
+
194
+ declare const noteK1: (url: string) => string | null;
195
+ declare const requireNoteK1: (url: string) => string;
196
+ declare const noteDeclaredAmount: (url: string) => number | null;
197
+ declare const noteSignature: (url: string) => string | null;
198
+ declare const resolveNoteInput: (value: string) => string | null;
199
+ declare const isValidNoteInput: (value: string) => boolean;
200
+ declare const buildNoteUrl: (withdrawLink: string, k1: string, amountMsat?: number) => string;
201
+ declare const withNewK1: (url: string, k1: string, amountMsat: number, signature?: string) => string;
202
+ declare const withoutK1: (url: string, amountMsat: number, signature?: string) => string;
203
+
204
+ declare const PAYMENT_REQUEST_PREFIX = "lnurlcashreq1";
205
+ type PaymentRequestMethodDetails = {
206
+ mints: string[];
207
+ mintPubkeys?: string[];
208
+ };
209
+ type PaymentRequest = {
210
+ v: 1;
211
+ id: string;
212
+ amount: string;
213
+ currency: 'sat';
214
+ methodDetails: PaymentRequestMethodDetails;
215
+ to?: string;
216
+ memo?: string;
217
+ expires?: number;
218
+ };
219
+ declare const paymentRequestAmountMsat: (request: PaymentRequest) => number;
220
+ declare const encodePaymentRequest: (request: PaymentRequest) => string;
221
+ type DecodeOptions = {
222
+ now?: number;
223
+ };
224
+ declare const decodePaymentRequest: (value: string, { now }?: DecodeOptions) => PaymentRequest;
225
+ declare const isPaymentRequest: (value: string) => boolean;
226
+
227
+ declare const noteSignatureMessage: (k1: string, amountMsat: number) => string;
228
+ declare const noteSignatureDigest: (k1: string, amountMsat: number) => Uint8Array;
229
+ type SignatureCheck = {
230
+ valid: true;
231
+ pubkey: string;
232
+ } | {
233
+ valid: false;
234
+ pubkey: null;
235
+ };
236
+ declare const verifyNoteSignatureAgainst: (k1: string, amountMsat: number, signatureHex: string, mintPubkeys: string | string[]) => SignatureCheck;
237
+ declare const verifyNoteSignature: (k1: string, amountMsat: number, signatureHex: string, mintPubkeys: string | string[]) => boolean;
238
+
239
+ declare const isBolt11Invoice: (value: string) => boolean;
240
+ declare const sameInvoice: (a: string, b: string) => boolean;
241
+ declare const decodeBolt11AmountMsat: (pr: string) => number | null;
242
+
243
+ declare class LnurlcashError extends Error {
244
+ constructor(message: string);
245
+ }
246
+ declare class RequestRefusedError extends LnurlcashError {
247
+ }
248
+ declare class ProtocolError extends LnurlcashError {
249
+ }
250
+ declare class ServiceRejectedError extends LnurlcashError {
251
+ readonly reason: string;
252
+ newSecrets?: string[];
253
+ constructor(reason: string);
254
+ }
255
+ declare class PendingNoteError extends ServiceRejectedError {
256
+ constructor(reason?: string);
257
+ }
258
+ declare class NoteSpentError extends ServiceRejectedError {
259
+ constructor(reason: string);
260
+ }
261
+ declare class NoteUnknownError extends ServiceRejectedError {
262
+ constructor(reason: string);
263
+ }
264
+ declare class AmbiguousMintError extends LnurlcashError {
265
+ }
266
+ declare class AmbiguousMutationError extends AmbiguousMintError {
267
+ readonly newSecrets: string[];
268
+ constructor(message: string, newSecrets: string[]);
269
+ }
270
+ declare class InsufficientValueError extends ServiceRejectedError {
271
+ readonly amountMsat: number;
272
+ readonly minMsat: number;
273
+ constructor(amountMsat: number, minMsat: number);
274
+ }
275
+ declare const newSecretsOf: (err: unknown) => string[];
276
+ declare const classifyNoteError: (reason: string) => ServiceRejectedError;
180
277
 
181
278
  declare const createClient: (options?: LnurlcashOptions) => {
182
279
  fetchNoteInfo: (url: string) => Promise<WithdrawRequestInfo>;
@@ -191,9 +288,12 @@ declare const createClient: (options?: LnurlcashOptions) => {
191
288
  mergeNotesWithHash: (callback: string, k1s: string[], h: string) => Promise<HashedMutationResult>;
192
289
  settleNote: (baseUrl: string, k1: string, expectedAmountMsat: number, signature?: string) => Promise<SettledNote>;
193
290
  fetchPayRequest: (url: string) => Promise<PayRequestInfo>;
194
- requestInvoice: (payCallback: string, amountMsat: number) => Promise<InvoiceResult>;
291
+ requestInvoice: (payCallback: string, amountMsat: number, h?: string) => Promise<InvoiceResult>;
195
292
  fetchInvoiceVerification: (verifyUrl: string) => Promise<VerifyResult>;
293
+ claimMintedNote: (withdrawLink: string, k1: string) => Promise<MintClaim>;
294
+ restoreNotes: (baseUrl: string, root: Uint8Array, host: string, restoreOptions?: RestoreOptions) => Promise<RestoreResult>;
295
+ settleNoteForValue: (noteUrl: string, terms: SettleForValueOptions) => Promise<SettledForValue>;
196
296
  };
197
297
  type LnurlcashClient = ReturnType<typeof createClient>;
198
298
 
199
- export { AmbiguousMintError, AmbiguousMutationError, type HashedMutationResult, type HashedSplitResult, type InvoiceResult, type LnurlcashClient, LnurlcashError, type LnurlcashOptions, type MeltResult, type MintAddressInfo, type MintFee, type MintFeeBand, NoteSpentError, NoteUnknownError, type PayRequestInfo, PendingNoteError, ProtocolError, type RandomSecret, RequestRefusedError, type RotateResult, ServiceRejectedError, type SettledNote, type SplitResult, type VerifyResult, type WithdrawRequestInfo, type WithdrawSuccessResponse, applyMintFee, buildNoteUrl, classifyNoteError, createClient, decodeBolt11AmountMsat, defaultRandomSecret, describeMintFee, fetchInvoiceVerification, fetchMintAddress, fetchNoteInfo, fetchPayRequest, formatFeePercent, fromBech32Lnurl, fromLud17, grossUpForMintFee, hashK1, isAllowedServiceUrl, isBech32Lnurl, isBolt11Invoice, isLightningAddress, isPreimage, isValidNoteInput, lightningAddressUsername, meltNote, mergeNotes, mergeNotesWithHash, mintAddressUrl, mintFeeBand, noteDeclaredAmount, noteK1, noteSignature, noteSignatureDigest, noteSignatureMessage, parseMintFee, probeBurnedNote, requestInvoice, requireNoteK1, resolveLnurlInput, resolveMintInput, resolveNoteInput, rotateNote, rotateNoteWithHash, sameInvoice, serverOf, settleNote, splitNote, splitNoteWithHash, toBech32Lnurl, toLud17w, verifyNoteSignature, withNewK1, withinMintFeeBand, withoutK1 };
299
+ export { AmbiguousMintError, AmbiguousMutationError, type DecodeOptions, type HashedMutationResult, type HashedSplitResult, InsufficientValueError, type InvoiceRequestOptions, type InvoiceResult, type LnurlcashClient, LnurlcashError, type LnurlcashOptions, type MeltResult, type MintAddressInfo, type MintClaim, type MintContact, type MintFee, type MintFeeBand, NoteSpentError, NoteUnknownError, PAYMENT_REQUEST_PREFIX, type PayRequestInfo, type PaymentRequest, type PaymentRequestMethodDetails, PendingNoteError, ProtocolError, type RandomSecret, RequestRefusedError, type RestoreOptions, type RestoreResult, type RestoredNote, type RotateResult, ServiceRejectedError, type SettleForValueOptions, type SettledForValue, type SettledNote, type SignatureCheck, type SplitResult, type VerifyResult, type WithdrawRequestInfo, type WithdrawSuccessResponse, applyMintFee, buildNoteUrl, claimMintedNote, classifyNoteError, createClient, decodeBolt11AmountMsat, decodePaymentRequest, defaultRandomSecret, deriveNoteRoot, deriveNoteSecret, derivedSecretSource, describeMintFee, encodePaymentRequest, fetchInvoiceVerification, fetchMintAddress, fetchNoteInfo, fetchPayRequest, formatFeePercent, fromBech32Lnurl, fromLud17, grossUpForMintFee, hashK1, isAllowedServiceUrl, isBech32Lnurl, isBolt11Invoice, isLightningAddress, isPaymentRequest, isPreimage, isValidNoteInput, lightningAddressUsername, meltNote, mergeNotes, mergeNotesWithHash, mintAddressUrl, mintFeeBand, newSecretsOf, noteDeclaredAmount, noteK1, noteSignature, noteSignatureDigest, noteSignatureMessage, parseMintFee, paymentRequestAmountMsat, probeBurnedNote, requestInvoice, requireNoteK1, resolveLnurlInput, resolveMintInput, resolveNoteInput, restoreNotes, rotateNote, rotateNoteWithHash, sameInvoice, serverOf, settleNote, settleNoteForValue, splitNote, splitNoteWithHash, toBech32Lnurl, toLud17w, verifyNoteSignature, verifyNoteSignatureAgainst, withNewK1, withinMintFeeBand, withoutK1 };