@fedimint/core-web 0.0.10 → 0.1.0-alex-cache-wasm-build
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/dts/FedimintWallet.d.ts +56 -1
- package/dist/dts/FedimintWallet.d.ts.map +1 -1
- package/dist/dts/services/BalanceService.d.ts +2 -21
- package/dist/dts/services/BalanceService.d.ts.map +1 -1
- package/dist/dts/services/FederationService.d.ts +1 -1
- package/dist/dts/services/FederationService.d.ts.map +1 -1
- package/dist/dts/services/LightningService.d.ts +11 -2
- package/dist/dts/services/LightningService.d.ts.map +1 -1
- package/dist/dts/services/MintService.d.ts +13 -6
- package/dist/dts/services/MintService.d.ts.map +1 -1
- package/dist/dts/services/RecoveryService.d.ts +1 -1
- package/dist/dts/services/RecoveryService.d.ts.map +1 -1
- package/dist/dts/services/WalletService.d.ts +8 -0
- package/dist/dts/services/WalletService.d.ts.map +1 -0
- package/dist/dts/services/index.d.ts +1 -0
- package/dist/dts/services/index.d.ts.map +1 -1
- package/dist/dts/types/utils.d.ts +8 -1
- package/dist/dts/types/utils.d.ts.map +1 -1
- package/dist/dts/types/wallet.d.ts +20 -9
- package/dist/dts/types/wallet.d.ts.map +1 -1
- package/dist/dts/types/worker.d.ts +1 -1
- package/dist/dts/types/worker.d.ts.map +1 -1
- package/dist/dts/worker/WorkerClient.d.ts +1 -1
- package/dist/dts/worker/WorkerClient.d.ts.map +1 -1
- package/dist/index.d.ts +114 -38
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/worker.js +1 -1
- package/dist/worker.js.map +1 -1
- package/package.json +8 -8
- package/src/FedimintWallet.test.ts +13 -0
- package/src/FedimintWallet.ts +69 -0
- package/src/services/BalanceService.ts +5 -26
- package/src/services/FederationService.ts +9 -7
- package/src/services/LightningService.ts +81 -65
- package/src/services/MintService.test.ts +41 -0
- package/src/services/MintService.ts +41 -25
- package/src/services/RecoveryService.ts +9 -7
- package/src/services/WalletService.test.ts +24 -0
- package/src/services/WalletService.ts +10 -0
- package/src/services/index.ts +1 -0
- package/src/test/TestingService.ts +5 -4
- package/src/test/fixtures.ts +6 -0
- package/src/types/utils.ts +5 -1
- package/src/types/wallet.ts +39 -9
- package/src/types/worker.ts +3 -0
- package/src/worker/WorkerClient.ts +8 -9
- package/src/worker/worker.js +62 -0
package/dist/index.d.ts
CHANGED
|
@@ -12,10 +12,18 @@ type JSONValue = string | number | boolean | null | {
|
|
|
12
12
|
[key: string]: JSONValue;
|
|
13
13
|
} | JSONValue[];
|
|
14
14
|
type JSONObject = Record<string, JSONValue>;
|
|
15
|
+
type Result<T, U = string> = {
|
|
16
|
+
success: true;
|
|
17
|
+
data?: T;
|
|
18
|
+
} | {
|
|
19
|
+
success: false;
|
|
20
|
+
error: U;
|
|
21
|
+
};
|
|
15
22
|
//# sourceMappingURL=utils.d.ts.map
|
|
16
23
|
|
|
17
|
-
declare const MODULE_KINDS: readonly ["", "ln", "mint"];
|
|
24
|
+
declare const MODULE_KINDS: readonly ["", "ln", "mint", "wallet"];
|
|
18
25
|
type ModuleKind = (typeof MODULE_KINDS)[number];
|
|
26
|
+
type FederationConfig = JSONObject;
|
|
19
27
|
type GatewayInfo = {
|
|
20
28
|
gateway_id: string;
|
|
21
29
|
api: string;
|
|
@@ -93,18 +101,28 @@ type StreamEnd = {
|
|
|
93
101
|
};
|
|
94
102
|
type StreamResult<T extends JSONValue> = StreamSuccess<T> | StreamError | StreamEnd;
|
|
95
103
|
type CancelFunction = () => void;
|
|
96
|
-
type ReissueExternalNotesState = 'Created' | 'Issuing' | 'Done'
|
|
97
|
-
|
|
98
|
-
|
|
104
|
+
type ReissueExternalNotesState = 'Created' | 'Issuing' | 'Done';
|
|
105
|
+
type MintSpendNotesResponse = Array<string>;
|
|
106
|
+
type SpendNotesState = 'Created' | 'UserCanceledProcessing' | 'UserCanceledSuccess' | 'UserCanceledFailure' | 'Success' | 'Refunded';
|
|
107
|
+
type TxOutputSummary = {
|
|
108
|
+
outpoint: {
|
|
109
|
+
txid: string;
|
|
110
|
+
vout: number;
|
|
99
111
|
};
|
|
112
|
+
amount: number;
|
|
100
113
|
};
|
|
101
|
-
type
|
|
102
|
-
|
|
103
|
-
|
|
114
|
+
type WalletSummary = {
|
|
115
|
+
spendable_utxos: TxOutputSummary[];
|
|
116
|
+
unsigned_peg_out_txos: TxOutputSummary[];
|
|
117
|
+
unsigned_change_utxos: TxOutputSummary[];
|
|
118
|
+
unconfirmed_peg_out_txos: TxOutputSummary[];
|
|
119
|
+
unconfirmed_change_utxos: TxOutputSummary[];
|
|
104
120
|
};
|
|
121
|
+
/** Keys are powers of 2 */
|
|
122
|
+
type NoteCountByDenomination = Record<number, number>;
|
|
105
123
|
//# sourceMappingURL=wallet.d.ts.map
|
|
106
124
|
|
|
107
|
-
declare const WorkerMessageTypes: readonly ["init", "initialized", "rpc", "log", "open", "join", "error", "unsubscribe", "cleanup"];
|
|
125
|
+
declare const WorkerMessageTypes: readonly ["init", "initialized", "rpc", "log", "open", "join", "error", "unsubscribe", "cleanup", "parseInviteCode", "parseBolt11Invoice", "previewFederation"];
|
|
108
126
|
type WorkerMessageType = (typeof WorkerMessageTypes)[number];
|
|
109
127
|
|
|
110
128
|
declare class WorkerClient {
|
|
@@ -144,7 +162,7 @@ declare class WorkerClient {
|
|
|
144
162
|
*/
|
|
145
163
|
rpcStream<Response extends JSONValue = JSONValue, Body extends JSONValue = JSONValue>(module: ModuleKind, method: string, body: Body, onSuccess: (res: Response) => void, onError: (res: StreamError['error']) => void, onEnd?: () => void): CancelFunction;
|
|
146
164
|
private _rpcStreamInner;
|
|
147
|
-
rpcSingle<Response extends JSONValue = JSONValue>(module: ModuleKind, method: string, body: JSONValue): Promise<Response>;
|
|
165
|
+
rpcSingle<Response extends JSONValue = JSONValue, Error extends string = string>(module: ModuleKind, method: string, body: JSONValue): Promise<Response>;
|
|
148
166
|
cleanup(): Promise<void>;
|
|
149
167
|
_getRequestCounter(): number;
|
|
150
168
|
_getRequestCallbackMap(): Map<number, (value: any) => void>;
|
|
@@ -153,15 +171,22 @@ declare class WorkerClient {
|
|
|
153
171
|
declare class MintService {
|
|
154
172
|
private client;
|
|
155
173
|
constructor(client: WorkerClient);
|
|
156
|
-
redeemEcash
|
|
174
|
+
/** https://web.fedimint.org/core/FedimintWallet/MintService/redeemEcash */
|
|
175
|
+
redeemEcash(notes: string): Promise<string>;
|
|
157
176
|
reissueExternalNotes(oobNotes: string, extraMeta?: JSONObject): Promise<string>;
|
|
158
|
-
subscribeReissueExternalNotes(operationId: string, onSuccess?: (state:
|
|
177
|
+
subscribeReissueExternalNotes(operationId: string, onSuccess?: (state: ReissueExternalNotesState) => void, onError?: (error: string) => void): CancelFunction;
|
|
178
|
+
/** https://web.fedimint.org/core/FedimintWallet/MintService/spendNotes */
|
|
159
179
|
spendNotes(amountMsats: number, tryCancelAfter?: number | Duration, // defaults to 1 day
|
|
160
|
-
includeInvite?: boolean, extraMeta?: JSONValue): Promise<
|
|
161
|
-
|
|
180
|
+
includeInvite?: boolean, extraMeta?: JSONValue): Promise<{
|
|
181
|
+
notes: string;
|
|
182
|
+
operation_id: string;
|
|
183
|
+
}>;
|
|
184
|
+
/** https://web.fedimint.org/core/FedimintWallet/MintService/parseEcash */
|
|
185
|
+
parseNotes(oobNotes: string): Promise<number>;
|
|
162
186
|
tryCancelSpendNotes(operationId: string): Promise<void>;
|
|
163
|
-
subscribeSpendNotes(operationId: string, onSuccess?: (state:
|
|
187
|
+
subscribeSpendNotes(operationId: string, onSuccess?: (state: SpendNotesState) => void, onError?: (error: string) => void): CancelFunction;
|
|
164
188
|
awaitSpendOobRefund(operationId: string): Promise<JSONValue>;
|
|
189
|
+
getNotesByDenomination(): Promise<NoteCountByDenomination>;
|
|
165
190
|
}
|
|
166
191
|
|
|
167
192
|
/**
|
|
@@ -172,43 +197,28 @@ declare class MintService {
|
|
|
172
197
|
declare class BalanceService {
|
|
173
198
|
private client;
|
|
174
199
|
constructor(client: WorkerClient);
|
|
175
|
-
/**
|
|
176
|
-
* Get the balance of the current wallet in milli-satoshis (MSats)
|
|
177
|
-
*
|
|
178
|
-
* @example
|
|
179
|
-
* ```ts
|
|
180
|
-
* const balance = await wallet.balance.getBalance()
|
|
181
|
-
* ```
|
|
182
|
-
*/
|
|
200
|
+
/** https://web.fedimint.org/core/FedimintWallet/BalanceService/getBalance */
|
|
183
201
|
getBalance(): Promise<number>;
|
|
184
|
-
/**
|
|
185
|
-
* Subscribe to the balance of the current wallet in milli-satoshis (MSats)
|
|
186
|
-
*
|
|
187
|
-
* @example
|
|
188
|
-
* ```ts
|
|
189
|
-
* const unsubscribe = wallet.balance.subscribeBalance((balance) => {
|
|
190
|
-
* console.log(balance)
|
|
191
|
-
* })
|
|
192
|
-
*
|
|
193
|
-
* // ...Cleanup Later
|
|
194
|
-
* unsubscribe()
|
|
195
|
-
* ```
|
|
196
|
-
*/
|
|
202
|
+
/** https://web.fedimint.org/core/FedimintWallet/BalanceService/subscribeBalance */
|
|
197
203
|
subscribeBalance(onSuccess?: (balanceMsats: number) => void, onError?: (error: string) => void): CancelFunction;
|
|
198
204
|
}
|
|
199
205
|
|
|
200
206
|
declare class LightningService {
|
|
201
207
|
private client;
|
|
202
208
|
constructor(client: WorkerClient);
|
|
209
|
+
/** https://web.fedimint.org/core/FedimintWallet/LightningService/createInvoice#lightning-createinvoice */
|
|
203
210
|
createInvoice(amountMsats: number, description: string, expiryTime?: number, // in seconds
|
|
204
211
|
gatewayInfo?: GatewayInfo, extraMeta?: JSONObject): Promise<CreateBolt11Response>;
|
|
205
212
|
createInvoiceTweaked(amountMsats: number, description: string, tweakKey: string, index: number, expiryTime?: number, // in seconds
|
|
206
213
|
gatewayInfo?: GatewayInfo, extraMeta?: JSONObject): Promise<CreateBolt11Response>;
|
|
207
214
|
scanReceivesForTweaks(tweakKey: string, indices: number[], extraMeta?: JSONObject): Promise<string[]>;
|
|
208
215
|
private _getDefaultGatewayInfo;
|
|
216
|
+
/** https://web.fedimint.org/core/FedimintWallet/LightningService/payInvoice#lightning-payinvoice-invoice-string */
|
|
209
217
|
payInvoice(invoice: string, gatewayInfo?: GatewayInfo, extraMeta?: JSONObject): Promise<OutgoingLightningPayment>;
|
|
218
|
+
/** https://web.fedimint.org/core/FedimintWallet/LightningService/payInvoice#lightning-payinvoicesync-invoice-string */
|
|
210
219
|
payInvoiceSync(invoice: string, timeoutMs?: number, gatewayInfo?: GatewayInfo, extraMeta?: JSONObject): Promise<{
|
|
211
220
|
success: false;
|
|
221
|
+
error?: string;
|
|
212
222
|
} | {
|
|
213
223
|
success: true;
|
|
214
224
|
data: {
|
|
@@ -217,16 +227,21 @@ declare class LightningService {
|
|
|
217
227
|
};
|
|
218
228
|
}>;
|
|
219
229
|
subscribeLnClaim(operationId: string, onSuccess?: (state: LnReceiveState) => void, onError?: (error: string) => void): CancelFunction;
|
|
230
|
+
/** https://web.fedimint.org/core/FedimintWallet/LightningService/payInvoice#lightning-payinvoice-invoice-string */
|
|
220
231
|
subscribeLnPay(operationId: string, onSuccess?: (state: LnPayState) => void, onError?: (error: string) => void): CancelFunction;
|
|
232
|
+
/** https://web.fedimint.org/core/FedimintWallet/LightningService/payInvoice#lightning-payinvoice-invoice-string */
|
|
221
233
|
waitForPay(operationId: string): Promise<{
|
|
222
234
|
success: false;
|
|
235
|
+
error?: string;
|
|
223
236
|
} | {
|
|
224
237
|
success: true;
|
|
225
238
|
data: {
|
|
226
239
|
preimage: string;
|
|
227
240
|
};
|
|
228
241
|
}>;
|
|
242
|
+
/** https://web.fedimint.org/core/FedimintWallet/LightningService/createInvoice#lightning-createinvoice */
|
|
229
243
|
subscribeLnReceive(operationId: string, onSuccess?: (state: LnReceiveState) => void, onError?: (error: string) => void): CancelFunction;
|
|
244
|
+
/** https://web.fedimint.org/core/FedimintWallet/LightningService/createInvoice#lightning-createinvoice */
|
|
230
245
|
waitForReceive(operationId: string, timeoutMs?: number): Promise<LnReceiveState>;
|
|
231
246
|
getGateway(gatewayId?: string | null, forceInternal?: boolean): Promise<LightningGateway | null>;
|
|
232
247
|
listGateways(): Promise<LightningGateway[]>;
|
|
@@ -241,7 +256,7 @@ declare class RecoveryService {
|
|
|
241
256
|
subscribeToRecoveryProgress(onSuccess: (progress: {
|
|
242
257
|
module_id: number;
|
|
243
258
|
progress: JSONValue;
|
|
244
|
-
}) => void, onError: (error: string) => void):
|
|
259
|
+
}) => void, onError: (error: string) => void): CancelFunction;
|
|
245
260
|
}
|
|
246
261
|
|
|
247
262
|
declare class FederationService {
|
|
@@ -249,10 +264,16 @@ declare class FederationService {
|
|
|
249
264
|
constructor(client: WorkerClient);
|
|
250
265
|
getConfig(): Promise<JSONValue>;
|
|
251
266
|
getFederationId(): Promise<string>;
|
|
252
|
-
getInviteCode(peer
|
|
267
|
+
getInviteCode(peer?: number): Promise<string | null>;
|
|
253
268
|
listOperations(): Promise<JSONValue[]>;
|
|
254
269
|
}
|
|
255
270
|
|
|
271
|
+
declare class WalletService {
|
|
272
|
+
private client;
|
|
273
|
+
constructor(client: WorkerClient);
|
|
274
|
+
getWalletSummary(): Promise<WalletSummary>;
|
|
275
|
+
}
|
|
276
|
+
|
|
256
277
|
declare const logLevels: readonly ["debug", "info", "warn", "error", "none"];
|
|
257
278
|
type LogLevel = (typeof logLevels)[number];
|
|
258
279
|
|
|
@@ -263,6 +284,7 @@ declare class FedimintWallet {
|
|
|
263
284
|
lightning: LightningService;
|
|
264
285
|
federation: FederationService;
|
|
265
286
|
recovery: RecoveryService;
|
|
287
|
+
wallet: WalletService;
|
|
266
288
|
private _openPromise;
|
|
267
289
|
private _resolveOpen;
|
|
268
290
|
private _isOpen;
|
|
@@ -306,11 +328,65 @@ declare class FedimintWallet {
|
|
|
306
328
|
*/
|
|
307
329
|
cleanup(): Promise<void>;
|
|
308
330
|
isOpen(): boolean;
|
|
331
|
+
previewFederation(inviteCode: string): Promise<{
|
|
332
|
+
config: FederationConfig;
|
|
333
|
+
federation_id: string;
|
|
334
|
+
}>;
|
|
309
335
|
/**
|
|
310
336
|
* Sets the log level for the library.
|
|
311
337
|
* @param level The desired log level ('DEBUG', 'INFO', 'WARN', 'ERROR', 'NONE').
|
|
312
338
|
*/
|
|
313
339
|
setLogLevel(level: LogLevel): void;
|
|
340
|
+
/**
|
|
341
|
+
* Parses a federation invite code and retrieves its details.
|
|
342
|
+
*
|
|
343
|
+
* This method sends the provided invite code to the WorkerClient for parsing.
|
|
344
|
+
* The response includes the federation_id and url.
|
|
345
|
+
*
|
|
346
|
+
* @param {string} inviteCode - The invite code to be parsed.
|
|
347
|
+
* @returns {Promise<{ federation_id: string, url: string}>}
|
|
348
|
+
* A promise that resolves to an object containing:
|
|
349
|
+
* - `federation_id`: The id of the feder.
|
|
350
|
+
* - `url`: One of the apipoints to connect to the federation
|
|
351
|
+
*
|
|
352
|
+
* @throws {Error} If the WorkerClient encounters an issue during the parsing process.
|
|
353
|
+
*
|
|
354
|
+
* @example
|
|
355
|
+
* const inviteCode = "example-invite-code";
|
|
356
|
+
* const parsedCode = await wallet.parseInviteCode(inviteCode);
|
|
357
|
+
* console.log(parsedCode.federation_id, parsedCode.url);
|
|
358
|
+
*/
|
|
359
|
+
parseInviteCode(inviteCode: string): Promise<{
|
|
360
|
+
type: string;
|
|
361
|
+
data: JSONValue;
|
|
362
|
+
requestId: number;
|
|
363
|
+
}>;
|
|
364
|
+
/**
|
|
365
|
+
* Parses a BOLT11 Lightning invoice and retrieves its details.
|
|
366
|
+
*
|
|
367
|
+
* This method sends the provided invoice string to the WorkerClient for parsing.
|
|
368
|
+
* The response includes details such as the amount, expiry, and memo.
|
|
369
|
+
*
|
|
370
|
+
* @param {string} invoiceStr - The BOLT11 invoice string to be parsed.
|
|
371
|
+
* @returns {Promise<{ amount: string, expiry: number, memo: string }>}
|
|
372
|
+
* A promise that resolves to an object containing:
|
|
373
|
+
* - `amount`: The amount specified in the invoice.
|
|
374
|
+
* - `expiry`: The expiry time of the invoice in seconds.
|
|
375
|
+
* - `memo`: A description or memo attached to the invoice.
|
|
376
|
+
*
|
|
377
|
+
* @throws {Error} If the WorkerClient encounters an issue during the parsing process.
|
|
378
|
+
*
|
|
379
|
+
* @example
|
|
380
|
+
* const invoiceStr = "lnbc1...";
|
|
381
|
+
* const parsedInvoice = await wallet.parseBolt11Invoice(invoiceStr);
|
|
382
|
+
* console.log(parsedInvoice.amount, parsedInvoice.expiry, parsedInvoice.memo);
|
|
383
|
+
*/
|
|
384
|
+
parseBolt11Invoice(invoiceStr: string): Promise<{
|
|
385
|
+
type: string;
|
|
386
|
+
data: JSONValue;
|
|
387
|
+
requestId: number;
|
|
388
|
+
}>;
|
|
314
389
|
}
|
|
315
390
|
|
|
316
|
-
export {
|
|
391
|
+
export { FedimintWallet };
|
|
392
|
+
export type { Alias, CancelFunction, CreateBolt11Response, Duration, FederationConfig, FeeToAmount, GatewayInfo, JSONObject, JSONValue, LightningGateway, LnPayState, LnReceiveState, MSats, MintSpendNotesResponse, ModuleKind, NoteCountByDenomination, OutgoingLightningPayment, PayType, ReissueExternalNotesState, Resolve, Result, RouteHint, Sats, SpendNotesState, StreamError, StreamResult, StreamSuccess, TxOutputSummary, WalletSummary, WorkerMessageType };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=["debug","info","warn","error","none"];const t=new class{constructor(e="none"){this.level=e}setLevel(e){this.level=e}coerceLevel(t){return e.includes(t.toLocaleUpperCase())?t.toLocaleUpperCase():"info"}log(e,t,...i){const n=this.coerceLevel(e);if(!this.shouldLog(n))return;(0,console[n])(`[${n.toUpperCase()}] ${t}`,...i)}debug(e,...t){this.log("debug",e,...t)}info(e,...t){this.log("info",e,...t)}warn(e,...t){this.log("warn",e,...t)}error(e,...t){this.log("error",e,...t)}shouldLog(e){const t=["debug","info","warn","error","none"],i=t.indexOf(e);return t.indexOf(this.level)<=i&&"none"!==this.level&&"none"!==e}};class i{constructor(){this.requestCounter=0,this.requestCallbacks=new Map,this.initPromise=void 0,this.worker=new Worker(new URL("./worker.js",import.meta.url),{type:"module"}),this.worker.onmessage=this.handleWorkerMessage.bind(this),this.worker.onerror=this.handleWorkerError.bind(this),t.info("WorkerClient instantiated"),t.debug("WorkerClient",this.worker)}initialize(){return this.initPromise||(this.initPromise=this.sendSingleMessage("init")),this.initPromise}handleWorkerLogs(e){const{type:i,level:n,message:s,...r}=e.data;t.log(n,s,...r)}handleWorkerError(e){t.error("Worker error",e)}handleWorkerMessage(e){const{type:i,requestId:n,...s}=e.data;"log"===i&&this.handleWorkerLogs(e.data);const r=this.requestCallbacks.get(n);t.debug("WorkerClient - handleWorkerMessage",e.data),r?r(s):t.warn("WorkerClient - handleWorkerMessage - received message with no callback",n,e.data)}sendSingleMessage(e,i){return new Promise(((n,s)=>{const r=++this.requestCounter;t.debug("WorkerClient - sendSingleMessage",r,e,i),this.requestCallbacks.set(r,(e=>{this.requestCallbacks.delete(r),t.debug("WorkerClient - sendSingleMessage - response",r,e),e.data?n(e.data):e.error?s(e.error):t.warn("WorkerClient - sendSingleMessage - malformed response",r,e)})),this.worker.postMessage({type:e,payload:i,requestId:r})}))}rpcStream(e,i,n,s,r,a=()=>{}){const o=++this.requestCounter;t.debug("WorkerClient - rpcStream",o,e,i,n);let c=()=>{},l=!1;const u=new Promise((e=>{c=()=>{l?e():setTimeout((()=>c()),0)}}));return this._rpcStreamInner(o,e,i,n,s,r,a,u).then((()=>{l=!0})),c}async _rpcStreamInner(e,t,i,n,s,r,a=()=>{},o){this.requestCallbacks.set(e,(t=>{void 0!==t.error?r(t.error):void 0!==t.data?s(t.data):void 0!==t.end&&(this.requestCallbacks.delete(e),a())})),this.worker.postMessage({type:"rpc",payload:{module:t,method:i,body:n},requestId:e}),o.then((()=>{this.worker?.postMessage({type:"unsubscribe",requestId:e}),this.requestCallbacks.delete(e)}))}rpcSingle(e,i,n){return t.debug("WorkerClient - rpcSingle",e,i,n),new Promise(((t,s)=>{this.rpcStream(e,i,n,t,s)}))}async cleanup(){await this.sendSingleMessage("cleanup"),this.requestCounter=0,this.initPromise=void 0,this.requestCallbacks.clear()}_getRequestCounter(){return this.requestCounter}_getRequestCallbackMap(){return this.requestCallbacks}}class n{constructor(e){this.client=e}async redeemEcash(e){await this.client.rpcSingle("mint","reissue_external_notes",{oob_notes:e,extra_meta:null})}async reissueExternalNotes(e,t={}){return await this.client.rpcSingle("mint","reissue_external_notes",{oob_notes:e,extra_meta:t})}subscribeReissueExternalNotes(e,t=()=>{},i=()=>{}){return this.client.rpcStream("mint","subscribe_reissue_external_notes",{operation_id:e},t,i)}async spendNotes(e,t=86400,i=!1,n={}){const s="number"==typeof t?{nanos:0,secs:t}:t,r=await this.client.rpcSingle("mint","spend_notes",{
|
|
1
|
+
const e=["debug","info","warn","error","none"];const t=new class{constructor(e="none"){this.level=e}setLevel(e){this.level=e}coerceLevel(t){return e.includes(t.toLocaleUpperCase())?t.toLocaleUpperCase():"info"}log(e,t,...i){const n=this.coerceLevel(e);if(!this.shouldLog(n))return;(0,console[n])(`[${n.toUpperCase()}] ${t}`,...i)}debug(e,...t){this.log("debug",e,...t)}info(e,...t){this.log("info",e,...t)}warn(e,...t){this.log("warn",e,...t)}error(e,...t){this.log("error",e,...t)}shouldLog(e){const t=["debug","info","warn","error","none"],i=t.indexOf(e);return t.indexOf(this.level)<=i&&"none"!==this.level&&"none"!==e}};class i{constructor(){this.requestCounter=0,this.requestCallbacks=new Map,this.initPromise=void 0,this.worker=new Worker(new URL("./worker.js",import.meta.url),{type:"module"}),this.worker.onmessage=this.handleWorkerMessage.bind(this),this.worker.onerror=this.handleWorkerError.bind(this),t.info("WorkerClient instantiated"),t.debug("WorkerClient",this.worker)}initialize(){return this.initPromise||(this.initPromise=this.sendSingleMessage("init")),this.initPromise}handleWorkerLogs(e){const{type:i,level:n,message:s,...r}=e.data;t.log(n,s,...r)}handleWorkerError(e){t.error("Worker error",e)}handleWorkerMessage(e){const{type:i,requestId:n,...s}=e.data;"log"===i&&this.handleWorkerLogs(e.data);const r=this.requestCallbacks.get(n);t.debug("WorkerClient - handleWorkerMessage",e.data),r?r(s):t.warn("WorkerClient - handleWorkerMessage - received message with no callback",n,e.data)}sendSingleMessage(e,i){return new Promise(((n,s)=>{const r=++this.requestCounter;t.debug("WorkerClient - sendSingleMessage",r,e,i),this.requestCallbacks.set(r,(e=>{this.requestCallbacks.delete(r),t.debug("WorkerClient - sendSingleMessage - response",r,e),e.data?n(e.data):e.error?s(e.error):t.warn("WorkerClient - sendSingleMessage - malformed response",r,e)})),this.worker.postMessage({type:e,payload:i,requestId:r})}))}rpcStream(e,i,n,s,r,a=()=>{}){const o=++this.requestCounter;t.debug("WorkerClient - rpcStream",o,e,i,n);let c=()=>{},l=!1;const u=new Promise((e=>{c=()=>{l?e():setTimeout((()=>c()),0)}}));return this._rpcStreamInner(o,e,i,n,s,r,a,u).then((()=>{l=!0})),c}async _rpcStreamInner(e,t,i,n,s,r,a=()=>{},o){this.requestCallbacks.set(e,(t=>{void 0!==t.error?r(t.error):void 0!==t.data?s(t.data):void 0!==t.end&&(this.requestCallbacks.delete(e),a())})),this.worker.postMessage({type:"rpc",payload:{module:t,method:i,body:n},requestId:e}),o.then((()=>{this.worker?.postMessage({type:"unsubscribe",requestId:e}),this.requestCallbacks.delete(e)}))}rpcSingle(e,i,n){return t.debug("WorkerClient - rpcSingle",e,i,n),new Promise(((t,s)=>{this.rpcStream(e,i,n,t,s)}))}async cleanup(){await this.sendSingleMessage("cleanup"),this.requestCounter=0,this.initPromise=void 0,this.requestCallbacks.clear()}_getRequestCounter(){return this.requestCounter}_getRequestCallbackMap(){return this.requestCallbacks}}class n{constructor(e){this.client=e}async redeemEcash(e){return await this.client.rpcSingle("mint","reissue_external_notes",{oob_notes:e,extra_meta:null})}async reissueExternalNotes(e,t={}){return await this.client.rpcSingle("mint","reissue_external_notes",{oob_notes:e,extra_meta:t})}subscribeReissueExternalNotes(e,t=()=>{},i=()=>{}){return this.client.rpcStream("mint","subscribe_reissue_external_notes",{operation_id:e},t,i)}async spendNotes(e,t=86400,i=!1,n={}){const s="number"==typeof t?{nanos:0,secs:t}:t,r=await this.client.rpcSingle("mint","spend_notes",{amount:e,try_cancel_after:s,include_invite:i,extra_meta:n});return{notes:r[1],operation_id:r[0]}}async parseNotes(e){return await this.client.rpcSingle("mint","validate_notes",{oob_notes:e})}async tryCancelSpendNotes(e){await this.client.rpcSingle("mint","try_cancel_spend_notes",{operation_id:e})}subscribeSpendNotes(e,t=()=>{},i=()=>{}){return this.client.rpcStream("mint","subscribe_spend_notes",{operation_id:e},(e=>t(e)),i)}async awaitSpendOobRefund(e){return await this.client.rpcSingle("mint","await_spend_oob_refund",{operation_id:e})}async getNotesByDenomination(){return await this.client.rpcSingle("mint","note_counts_by_denomination",{})}}class s{constructor(e){this.client=e}async getBalance(){return await this.client.rpcSingle("","get_balance",{})}subscribeBalance(e=()=>{},t=()=>{}){return this.client.rpcStream("","subscribe_balance_changes",{},(t=>e(parseInt(t))),t)}}class r{constructor(e){this.client=e}async createInvoice(e,t,i,n,s){const r=n??await this._getDefaultGatewayInfo();return await this.client.rpcSingle("ln","create_bolt11_invoice",{amount:e,description:t,expiry_time:i??null,extra_meta:s??{},gateway:r})}async createInvoiceTweaked(e,t,i,n,s,r,a){const o=r??await this._getDefaultGatewayInfo();return await this.client.rpcSingle("ln","create_bolt11_invoice_for_user_tweaked",{amount:e,description:t,expiry_time:s??null,user_key:i,index:n,extra_meta:a??{},gateway:o})}async scanReceivesForTweaks(e,t,i){return await this.client.rpcSingle("ln","scan_receive_for_user_tweaked",{user_key:e,indices:t,extra_meta:i??{}})}async _getDefaultGatewayInfo(){await this.updateGatewayCache();const e=await this.listGateways();return e[0]?.info}async payInvoice(e,t,i){const n=t??await this._getDefaultGatewayInfo();return await this.client.rpcSingle("ln","pay_bolt11_invoice",{maybe_gateway:n,invoice:e,extra_meta:i??{}})}async payInvoiceSync(e,t=1e4,i,n){return new Promise((async(s,r)=>{const{contract_id:a,fee:o}=await this.payInvoice(e,i,n),c=this.subscribeLnPay(a,(e=>{"string"!=typeof e&&"success"in e?(clearTimeout(l),c(),s({success:!0,data:{feeMsats:o,preimage:e.success.preimage}})):"string"!=typeof e&&"unexpected_error"in e&&r(new Error(e.unexpected_error.error_message))})),l=setTimeout((()=>{c(),s({success:!1,error:"Payment timeout"})}),t)}))}subscribeLnClaim(e,t=()=>{},i=()=>{}){return this.client.rpcStream("ln","subscribe_ln_claim",{operation_id:e},t,i)}subscribeLnPay(e,t=()=>{},i=()=>{}){return this.client.rpcStream("ln","subscribe_ln_pay",{operation_id:e},t,i)}async waitForPay(e){return new Promise(((t,i)=>{let n;const s=setTimeout((()=>{t({success:!1,error:"Waiting for receive timeout"})}),15e3);n=this.subscribeLnPay(e,(e=>{"string"!=typeof e&&"success"in e&&(clearTimeout(s),n(),t({success:!0,data:{preimage:e.success.preimage}}))}),(e=>{clearTimeout(s),n(),i(e)}))}))}subscribeLnReceive(e,t=()=>{},i=()=>{}){return this.client.rpcStream("ln","subscribe_ln_receive",{operation_id:e},t,i)}async waitForReceive(e,t=15e3){return new Promise(((i,n)=>{let s;const r=setTimeout((()=>{n(new Error("Timeout waiting for receive"))}),t);s=this.subscribeLnReceive(e,(e=>{"claimed"===e&&(clearTimeout(r),s(),i(e))}),(e=>{clearTimeout(r),s(),n(e)}))}))}async getGateway(e=null,t=!1){return await this.client.rpcSingle("ln","get_gateway",{gateway_id:e,force_internal:t})}async listGateways(){return await this.client.rpcSingle("ln","list_gateways",{})}async updateGatewayCache(){return await this.client.rpcSingle("ln","update_gateway_cache",{})}}class a{constructor(e){this.client=e}async hasPendingRecoveries(){return await this.client.rpcSingle("","has_pending_recoveries",{})}async waitForAllRecoveries(){await this.client.rpcSingle("","wait_for_all_recoveries",{})}subscribeToRecoveryProgress(e,t){return this.client.rpcStream("","subscribe_to_recovery_progress",{},e,t)}}class o{constructor(e){this.client=e}async getConfig(){return await this.client.rpcSingle("","get_config",{})}async getFederationId(){return await this.client.rpcSingle("","get_federation_id",{})}async getInviteCode(e=0){return await this.client.rpcSingle("","get_invite_code",{peer:e})}async listOperations(){return await this.client.rpcSingle("","list_operations",{})}}class c{constructor(e){this.client=e}async getWalletSummary(){return await this.client.rpcSingle("wallet","get_wallet_summary",{})}}const l="fm-default";class u{constructor(e=!1){this._openPromise=void 0,this._resolveOpen=()=>{},this._isOpen=!1,this._openPromise=new Promise((e=>{this._resolveOpen=e})),this._client=new i,this.mint=new n(this._client),this.lightning=new r(this._client),this.balance=new s(this._client),this.federation=new o(this._client),this.recovery=new a(this._client),this.wallet=new c(this._client),t.info("FedimintWallet instantiated"),e||this.initialize()}async initialize(){t.info("Initializing WorkerClient"),await this._client.initialize(),t.info("WorkerClient initialized")}async waitForOpen(){return this._isOpen?Promise.resolve():this._openPromise}async open(e=l){if(await this._client.initialize(),this._isOpen)throw new Error("The FedimintWallet is already open.");const{success:t}=await this._client.sendSingleMessage("open",{clientName:e});return t&&(this._isOpen=!!t,this._resolveOpen()),t}async joinFederation(e,i=l){if(await this._client.initialize(),this._isOpen)throw new Error("The FedimintWallet is already open. You can only call `joinFederation` on closed clients.");try{const t=await this._client.sendSingleMessage("join",{inviteCode:e,clientName:i});return t.success&&(this._isOpen=!0,this._resolveOpen()),t.success}catch(e){return t.error("Error joining federation",e),!1}}async cleanup(){this._openPromise=void 0,this._isOpen=!1,await this._client.cleanup()}isOpen(){return this._isOpen}async previewFederation(e){return this._client.sendSingleMessage("previewFederation",{inviteCode:e})}setLogLevel(e){t.setLevel(e),t.info(`Log level set to ${e}.`)}async parseInviteCode(e){return await this._client.sendSingleMessage("parseInviteCode",{inviteCode:e})}async parseBolt11Invoice(e){return await this._client.sendSingleMessage("parseBolt11Invoice",{invoiceStr:e})}}export{u as FedimintWallet};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/utils/logger.ts","../src/worker/WorkerClient.ts","../src/services/MintService.ts","../src/services/BalanceService.ts","../src/services/LightningService.ts","../src/services/RecoveryService.ts","../src/services/FederationService.ts","../src/FedimintWallet.ts"],"sourcesContent":[null,null,null,null,null,null,null,null],"names":["logLevels","logger","constructor","level","this","setLevel","coerceLevel","includes","toLocaleUpperCase","log","message","args","logLevel","shouldLog","consoleFn","console","toUpperCase","debug","info","warn","error","messageLevel","levels","messageLevelIndex","indexOf","WorkerClient","requestCounter","requestCallbacks","Map","initPromise","undefined","worker","Worker","URL","url","type","onmessage","handleWorkerMessage","bind","onerror","handleWorkerError","initialize","sendSingleMessage","handleWorkerLogs","event","data","requestId","streamCallback","get","payload","Promise","resolve","reject","set","response","delete","postMessage","rpcStream","module","method","body","onSuccess","onError","onEnd","unsubscribe","isSubscribed","unsubscribePromise","setTimeout","_rpcStreamInner","then","end","rpcSingle","cleanup","clear","_getRequestCounter","_getRequestCallbackMap","MintService","client","redeemEcash","notes","oob_notes","extra_meta","reissueExternalNotes","oobNotes","extraMeta","subscribeReissueExternalNotes","operationId","operation_id","spendNotes","amountMsats","tryCancelAfter","includeInvite","duration","nanos","secs","res","min_amount","try_cancel_after","include_invite","parseNotes","tryCancelSpendNotes","subscribeSpendNotes","awaitSpendOobRefund","BalanceService","getBalance","subscribeBalance","parseInt","LightningService","createInvoice","description","expiryTime","gatewayInfo","gateway","_getDefaultGatewayInfo","amount","expiry_time","createInvoiceTweaked","tweakKey","index","user_key","scanReceivesForTweaks","indices","updateGatewayCache","gateways","listGateways","payInvoice","invoice","maybe_gateway","payInvoiceSync","timeoutMs","async","contract_id","fee","subscribeLnPay","clearTimeout","timeoutId","success","feeMsats","preimage","Error","subscribeLnClaim","waitForPay","subscribeLnReceive","waitForReceive","getGateway","gatewayId","forceInternal","gateway_id","force_internal","RecoveryService","hasPendingRecoveries","waitForAllRecoveries","subscribeToRecoveryProgress","FederationService","getConfig","getFederationId","getInviteCode","peer","listOperations","DEFAULT_CLIENT_NAME","FedimintWallet","lazy","_openPromise","_resolveOpen","_isOpen","_client","mint","lightning","balance","federation","recovery","waitForOpen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ACF,CAMD,aAAMxG,GACJpE,KAAK8J,kBAAepI,EACpB1B,KAAKgK,SAAU,QACThK,KAAKiK,QAAQ7F,SACpB,CAED,MAAAyG,GACE,OAAO7K,KAAKgK,OACb,CAMD,WAAAc,CAAY/K,GACVF,EAAOI,SAASF,GAChBF,EAAOiB,KAAK,oBAAoBf,KACjC"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/utils/logger.ts","../src/worker/WorkerClient.ts","../src/services/MintService.ts","../src/services/BalanceService.ts","../src/services/LightningService.ts","../src/services/RecoveryService.ts","../src/services/FederationService.ts","../src/services/WalletService.ts","../src/FedimintWallet.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,null],"names":["logLevels","logger","constructor","level","this","setLevel","coerceLevel","includes","toLocaleUpperCase","log","message","args","logLevel","shouldLog","consoleFn","console","toUpperCase","debug","info","warn","error","messageLevel","levels","messageLevelIndex","indexOf","WorkerClient","requestCounter","requestCallbacks","Map","initPromise","undefined","worker","Worker","URL","url","type","onmessage","handleWorkerMessage","bind","onerror","handleWorkerError","initialize","sendSingleMessage","handleWorkerLogs","event","data","requestId","streamCallback","get","payload","Promise","resolve","reject","set","response","delete","postMessage","rpcStream","module","method","body","onSuccess","onError","onEnd","unsubscribe","isSubscribed","unsubscribePromise","setTimeout","_rpcStreamInner","then","end","rpcSingle","cleanup","clear","_getRequestCounter","_getRequestCallbackMap","MintService","client","redeemEcash","notes","oob_notes","extra_meta","reissueExternalNotes","oobNotes","extraMeta","subscribeReissueExternalNotes","operationId","operation_id","spendNotes","amountMsats","tryCancelAfter","includeInvite","duration","nanos","secs","res","amount","try_cancel_after","include_invite","parseNotes","tryCancelSpendNotes","subscribeSpendNotes","awaitSpendOobRefund","getNotesByDenomination","BalanceService","getBalance","subscribeBalance","parseInt","LightningService","createInvoice","description","expiryTime","gatewayInfo","gateway","_getDefaultGatewayInfo","expiry_time","createInvoiceTweaked","tweakKey","index","user_key","scanReceivesForTweaks","indices","updateGatewayCache","gateways","listGateways","payInvoice","invoice","maybe_gateway","payInvoiceSync","timeoutMs","async","contract_id","fee","subscribeLnPay","clearTimeout","timeoutId","success","feeMsats","preimage","Error","unexpected_error","error_message","subscribeLnClaim","waitForPay","subscribeLnReceive","waitForReceive","getGateway","gatewayId","forceInternal","gateway_id","force_internal","RecoveryService","hasPendingRecoveries","waitForAllRecoveries","subscribeToRecoveryProgress","FederationService","getConfig","getFederationId","getInviteCode","peer","listOperations","WalletService","getWalletSummary","DEFAULT_CLIENT_NAME","FedimintWallet","lazy","_openPromise","_resolveOpen","_isOpen","_client","mint","lightning","balance","federation","recovery","wallet","waitForOpen","open","clientName","joinFederation","inviteCode","e","isOpen","previewFederation","setLogLevel","parseInviteCode","parseBolt11Invoice","invoiceStr"],"mappings":"AAAA,MAAMA,EAAY,CAAC,QAAS,OAAQ,OAAQ,QAAS,QA4D9C,MAAMC,EAAS,UAtDpB,WAAAC,CAAYC,EAAkB,QAC5BC,KAAKD,MAAQA,EAGf,QAAAE,CAASF,GACPC,KAAKD,MAAQA,EAGf,WAAAG,CAAYH,GACV,OAAIH,EAAUO,SAASJ,EAAMK,qBACpBL,EAAMK,oBAER,OAGT,GAAAC,CAAIN,EAAeO,KAAoBC,GACrC,MAAMC,EAAWR,KAAKE,YAAYH,GAClC,IAAKC,KAAKS,UAAUD,GAClB,QAGFE,EADkBC,QAAQH,IAChB,IAAIA,EAASI,kBAAkBN,OAAcC,GAGzD,KAAAM,CAAMP,KAAoBC,GACxBP,KAAKK,IAAI,QAASC,KAAYC,GAGhC,IAAAO,CAAKR,KAAoBC,GACvBP,KAAKK,IAAI,OAAQC,KAAYC,GAG/B,IAAAQ,CAAKT,KAAoBC,GACvBP,KAAKK,IAAI,OAAQC,KAAYC,GAG/B,KAAAS,CAAMV,KAAoBC,GACxBP,KAAKK,IAAI,QAASC,KAAYC,GAGxB,SAAAE,CACNQ,GAEA,MAAMC,EAAqB,CAAC,QAAS,OAAQ,OAAQ,QAAS,QACxDC,EAAoBD,EAAOE,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YhC,EACjBpI,KAAKmK,gBAEA/B,EAGT,oBAAM2C,CACJC,EACAF,EAAqBf,GAIrB,SAFM/J,KAAKqK,QAAQhI,aAEfrC,KAAKoK,QACP,MAAM,IAAI7B,MACR,6FAEJ,IACE,MAAMrF,QAAiBlD,KAAKqK,QAAQ/H,kBAEjC,OAAQ,CAAE0I,aAAYF,eAMzB,OALI5H,EAASkF,UACXpI,KAAKoK,SAAU,EACfpK,KAAKmK,gBAGAjH,EAASkF,QAChB,MAAO6C,GAEP,OADApL,EAAOmB,MAAM,2BAA4BiK,IAClC,GAQX,aAAM7G,GACJpE,KAAKkK,kBAAexI,EACpB1B,KAAKoK,SAAU,QACTpK,KAAKqK,QAAQjG,UAGrB,MAAA8G,GACE,OAAOlL,KAAKoK,QAGd,uBAAMe,CAAkBH,GAKtB,OAJiBhL,KAAKqK,QAAQ/H,kBAG3B,oBAAqB,CAAE0I,eAQ5B,WAAAI,CAAYrL,GACVF,EAAOI,SAASF,GAChBF,EAAOiB,KAAK,oBAAoBf,MAsBlC,qBAAMsL,CAAgBL,GAMpB,aALuBhL,KAAKqK,QAAQ/H,kBAIjC,kBAAmB,CAAE0I,eAwB1B,wBAAMM,CAAmBC,GAMvB,aALuBvL,KAAKqK,QAAQ/H,kBAIjC,qBAAsB,CAAEiJ"}
|
package/dist/worker.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
globalThis.__vitest_browser_runner__={wrapDynamicImport:e=>e()};let e=null,s=null;const t=new Map;console.log("Worker - init"),self.onmessage=async
|
|
1
|
+
globalThis.__vitest_browser_runner__={wrapDynamicImport:e=>e()};let e=null,s=null;const t=new Map;console.log("Worker - init"),self.onmessage=async r=>{const{type:o,payload:a,requestId:i}=r.data;try{if("init"===o)e=(await import("@fedimint/fedimint-client-wasm-bundler")).WasmClient,self.postMessage({type:"initialized",data:{},requestId:i});else if("open"===o){const{clientName:t}=a;s=await e.open(t)||null,self.postMessage({type:"open",data:{success:!!s},requestId:i})}else if("join"===o){const{inviteCode:t,clientName:r}=a;try{s=await e.join_federation(r,t),self.postMessage({type:"join",data:{success:!!s},requestId:i})}catch(e){self.postMessage({type:"error",error:e.message,requestId:i})}}else if("previewFederation"===o){const{inviteCode:t}=a;try{s=await e.preview_federation(t);const r=JSON.parse(s);self.postMessage({type:"previewFederation",data:{success:!!s,config:r.config,federation_id:r.federation_id},requestId:i})}catch(e){self.postMessage({type:"error",error:e.message,requestId:i})}}else if("rpc"===o){const{module:e,method:r,body:o}=a;if(console.log("RPC received",e,r,o),!s)return void self.postMessage({type:"error",error:"WasmClient not initialized",requestId:i});const n=await s.rpc(e,r,JSON.stringify(o),(e=>{console.log("RPC response",i,e);const s=JSON.parse(e);if(self.postMessage({type:"rpcResponse",requestId:i,...s}),void 0!==s.end){const e=t.get(i);e?.free()}}));t.set(i,n)}else if("unsubscribe"===o){const e=t.get(i);e&&(e.cancel(),e.free(),t.delete(i))}else if("cleanup"===o)console.log("cleanup message received"),s?.free(),self.postMessage({type:"cleanup",data:{},requestId:i}),close();else if("parseInviteCode"===o){const{inviteCode:s}=a;try{const t=e.parse_invite_code(s),r=JSON.parse(t);self.postMessage({type:"parseInviteCode",data:r,requestId:i})}catch(e){self.postMessage({type:"error",error:`Failed to parse invite code: ${e.message}`,requestId:i})}}else if("parseBolt11Invoice"===o){const{invoiceStr:s}=a;try{const t=e.parse_bolt11_invoice(s),r=JSON.parse(t);self.postMessage({type:"parseBolt11Invoice",data:r,requestId:i})}catch(e){self.postMessage({type:"error",error:`Failed to parse invoice: ${e.message}`,requestId:i})}}else self.postMessage({type:"error",error:"Unknown message type",requestId:i})}catch(e){console.error("ERROR",e),self.postMessage({type:"error",error:e,requestId:i})}};
|
|
2
2
|
//# sourceMappingURL=worker.js.map
|
package/dist/worker.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker.js","sources":["../src/worker/worker.js"],"sourcesContent":["// Web Worker for fedimint-client-wasm to run in the browser\n\n// HACK: Fixes vitest browser runner\n// TODO: remove once https://github.com/vitest-dev/vitest/pull/6569 lands in a release\nglobalThis.__vitest_browser_runner__ = { wrapDynamicImport: (foo) => foo() }\n\n// dynamically imported Constructor for WasmClient\nlet WasmClient = null\n// client instance\nlet client = null\n\nconst streamCancelMap = new Map()\n\nconst handleFree = (requestId) => {\n streamCancelMap.delete(requestId)\n}\n\nconsole.log('Worker - init')\n\nself.onmessage = async (event) => {\n const { type, payload, requestId } = event.data\n\n try {\n if (type === 'init') {\n WasmClient = (await import('@fedimint/fedimint-client-wasm-bundler'))\n .WasmClient\n self.postMessage({ type: 'initialized', data: {}, requestId })\n } else if (type === 'open') {\n const { clientName } = payload\n client = (await WasmClient.open(clientName)) || null\n self.postMessage({\n type: 'open',\n data: { success: !!client },\n requestId,\n })\n } else if (type === 'join') {\n const { inviteCode, clientName: joinClientName } = payload\n try {\n client = await WasmClient.join_federation(joinClientName, inviteCode)\n self.postMessage({\n type: 'join',\n data: { success: !!client },\n requestId,\n })\n } catch (e) {\n self.postMessage({ type: 'error', error: e.message, requestId })\n }\n } else if (type === 'rpc') {\n const { module, method, body } = payload\n console.log('RPC received', module, method, body)\n if (!client) {\n self.postMessage({\n type: 'error',\n error: 'WasmClient not initialized',\n requestId,\n })\n return\n }\n const rpcHandle = await client.rpc(\n module,\n method,\n JSON.stringify(body),\n (res) => {\n console.log('RPC response', requestId, res)\n const data = JSON.parse(res)\n self.postMessage({ type: 'rpcResponse', requestId, ...data })\n\n if (data.end !== undefined) {\n // Handle stream ending\n const handle = streamCancelMap.get(requestId)\n handle?.free()\n }\n },\n )\n streamCancelMap.set(requestId, rpcHandle)\n } else if (type === 'unsubscribe') {\n const rpcHandle = streamCancelMap.get(requestId)\n if (rpcHandle) {\n rpcHandle.cancel()\n rpcHandle.free()\n streamCancelMap.delete(requestId)\n }\n } else if (type === 'cleanup') {\n console.log('cleanup message received')\n client?.free()\n self.postMessage({\n type: 'cleanup',\n data: {},\n requestId,\n })\n close()\n } else {\n self.postMessage({\n type: 'error',\n error: 'Unknown message type',\n requestId,\n })\n }\n } catch (e) {\n console.error('ERROR', e)\n self.postMessage({ type: 'error', error: e, requestId })\n }\n}\n\n// self.postMessage({ type: 'init', data: {} })\n"],"names":["globalThis","__vitest_browser_runner__","wrapDynamicImport","foo","WasmClient","client","streamCancelMap","Map","console","log","self","onmessage","async","event","type","payload","requestId","data","import","postMessage","clientName","open","success","inviteCode","joinClientName","join_federation","e","error","message","module","method","body","rpcHandle","rpc","
|
|
1
|
+
{"version":3,"file":"worker.js","sources":["../src/worker/worker.js"],"sourcesContent":["// Web Worker for fedimint-client-wasm to run in the browser\n\n// HACK: Fixes vitest browser runner\n// TODO: remove once https://github.com/vitest-dev/vitest/pull/6569 lands in a release\nglobalThis.__vitest_browser_runner__ = { wrapDynamicImport: (foo) => foo() }\n\n// dynamically imported Constructor for WasmClient\nlet WasmClient = null\n// client instance\nlet client = null\n\nconst streamCancelMap = new Map()\n\nconst handleFree = (requestId) => {\n streamCancelMap.delete(requestId)\n}\n\nconsole.log('Worker - init')\n\n/**\n * Type definitions for the worker messages\n *\n * @typedef {import('../types/worker').WorkerMessageType} WorkerMessageType\n * @typedef {{\n * type: WorkerMessageType\n * payload: any\n * requestId: number\n * }} WorkerMessage\n * @param {{data: WorkerMessage}} event\n */\nself.onmessage = async (event) => {\n const { type, payload, requestId } = event.data\n\n try {\n if (type === 'init') {\n WasmClient = (await import('@fedimint/fedimint-client-wasm-bundler'))\n .WasmClient\n self.postMessage({ type: 'initialized', data: {}, requestId })\n } else if (type === 'open') {\n const { clientName } = payload\n client = (await WasmClient.open(clientName)) || null\n self.postMessage({\n type: 'open',\n data: { success: !!client },\n requestId,\n })\n } else if (type === 'join') {\n const { inviteCode, clientName: joinClientName } = payload\n try {\n client = await WasmClient.join_federation(joinClientName, inviteCode)\n self.postMessage({\n type: 'join',\n data: { success: !!client },\n requestId,\n })\n } catch (e) {\n self.postMessage({ type: 'error', error: e.message, requestId })\n }\n } else if (type === 'previewFederation') {\n const { inviteCode } = payload\n try {\n client = await WasmClient.preview_federation(inviteCode)\n const parsed = JSON.parse(client)\n self.postMessage({\n type: 'previewFederation',\n data: {\n success: !!client,\n config: parsed.config,\n federation_id: parsed.federation_id,\n },\n requestId,\n })\n } catch (e) {\n self.postMessage({ type: 'error', error: e.message, requestId })\n }\n } else if (type === 'rpc') {\n const { module, method, body } = payload\n console.log('RPC received', module, method, body)\n if (!client) {\n self.postMessage({\n type: 'error',\n error: 'WasmClient not initialized',\n requestId,\n })\n return\n }\n const rpcHandle = await client.rpc(\n module,\n method,\n JSON.stringify(body),\n (res) => {\n console.log('RPC response', requestId, res)\n const data = JSON.parse(res)\n self.postMessage({ type: 'rpcResponse', requestId, ...data })\n\n if (data.end !== undefined) {\n // Handle stream ending\n const handle = streamCancelMap.get(requestId)\n handle?.free()\n }\n },\n )\n streamCancelMap.set(requestId, rpcHandle)\n } else if (type === 'unsubscribe') {\n const rpcHandle = streamCancelMap.get(requestId)\n if (rpcHandle) {\n rpcHandle.cancel()\n rpcHandle.free()\n streamCancelMap.delete(requestId)\n }\n } else if (type === 'cleanup') {\n console.log('cleanup message received')\n client?.free()\n self.postMessage({\n type: 'cleanup',\n data: {},\n requestId,\n })\n close()\n } else if (type === 'parseInviteCode') {\n const { inviteCode } = payload\n try {\n const res = WasmClient.parse_invite_code(inviteCode)\n const parsedRes = JSON.parse(res)\n self.postMessage({\n type: 'parseInviteCode',\n data: parsedRes,\n requestId,\n })\n } catch (error) {\n self.postMessage({\n type: 'error',\n error: `Failed to parse invite code: ${error.message}`,\n requestId,\n })\n }\n } else if (type === 'parseBolt11Invoice') {\n const { invoiceStr } = payload\n try {\n const res = WasmClient.parse_bolt11_invoice(invoiceStr)\n const parsedRes = JSON.parse(res)\n self.postMessage({\n type: 'parseBolt11Invoice',\n data: parsedRes,\n requestId,\n })\n } catch (error) {\n self.postMessage({\n type: 'error',\n error: `Failed to parse invoice: ${error.message}`,\n requestId,\n })\n }\n } else {\n self.postMessage({\n type: 'error',\n error: 'Unknown message type',\n requestId,\n })\n }\n } catch (e) {\n console.error('ERROR', e)\n self.postMessage({ type: 'error', error: e, requestId })\n }\n}\n\n// self.postMessage({ type: 'init', data: {} })\n"],"names":["globalThis","__vitest_browser_runner__","wrapDynamicImport","foo","WasmClient","client","streamCancelMap","Map","console","log","self","onmessage","async","event","type","payload","requestId","data","import","postMessage","clientName","open","success","inviteCode","joinClientName","join_federation","e","error","message","preview_federation","parsed","JSON","parse","config","federation_id","module","method","body","rpcHandle","rpc","stringify","res","undefined","end","handle","get","free","set","cancel","delete","close","parse_invite_code","parsedRes","invoiceStr","parse_bolt11_invoice"],"mappings":"AAIAA,WAAWC,0BAA4B,CAAEC,kBAAoBC,GAAQA,KAGrE,IAAIC,EAAa,KAEbC,EAAS,KAEb,MAAMC,EAAkB,IAAIC,IAM5BC,QAAQC,IAAI,iBAaZC,KAAKC,UAAYC,MAAOC,IACtB,MAAMC,KAAEA,EAAIC,QAAEA,EAAOC,UAAEA,GAAcH,EAAMI,KAE3C,IACE,GAAa,SAATH,EACFV,SAAoBc,OAAO,2CACxBd,WACHM,KAAKS,YAAY,CAAEL,KAAM,cAAeG,KAAM,CAAE,EAAED,mBAC7C,GAAa,SAATF,EAAiB,CAC1B,MAAMM,WAAEA,GAAeL,EACvBV,QAAgBD,EAAWiB,KAAKD,IAAgB,KAChDV,KAAKS,YAAY,CACfL,KAAM,OACNG,KAAM,CAAEK,UAAWjB,GACnBW,aAER,MAAW,GAAa,SAATF,EAAiB,CAC1B,MAAMS,WAAEA,EAAYH,WAAYI,GAAmBT,EACnD,IACEV,QAAeD,EAAWqB,gBAAgBD,EAAgBD,GAC1Db,KAAKS,YAAY,CACfL,KAAM,OACNG,KAAM,CAAEK,UAAWjB,GACnBW,aAEH,CAAC,MAAOU,GACPhB,KAAKS,YAAY,CAAEL,KAAM,QAASa,MAAOD,EAAEE,QAASZ,aAC5D,CACA,MAAW,GAAa,sBAATF,EAA8B,CACvC,MAAMS,WAAEA,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Y,CACfL,KAAM,kBACNG,KAAMmC,EACNpC,aAEH,CAAC,MAAOW,GACPjB,KAAKS,YAAY,CACfL,KAAM,QACNa,MAAO,gCAAgCA,EAAMC,UAC7CZ,aAEV,CACA,MAAW,GAAa,uBAATF,EAA+B,CACxC,MAAMuC,WAAEA,GAAetC,EACvB,IACE,MAAM0B,EAAMrC,EAAWkD,qBAAqBD,GACtCD,EAAYrB,KAAKC,MAAMS,GAC7B/B,KAAKS,YAAY,CACfL,KAAM,qBACNG,KAAMmC,EACNpC,aAEH,CAAC,MAAOW,GACPjB,KAAKS,YAAY,CACfL,KAAM,QACNa,MAAO,4BAA4BA,EAAMC,UACzCZ,aAEV,CACA,MACMN,KAAKS,YAAY,CACfL,KAAM,QACNa,MAAO,uBACPX,aAGL,CAAC,MAAOU,GACPlB,QAAQmB,MAAM,QAASD,GACvBhB,KAAKS,YAAY,CAAEL,KAAM,QAASa,MAAOD,EAAGV,aAChD"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fedimint/core-web",
|
|
3
3
|
"description": "Library for building web apps with a fedimint client",
|
|
4
|
-
"version": "0.0
|
|
4
|
+
"version": "0.1.0-alex-cache-wasm-build",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/fedimint/fedimint-web-sdk.git",
|
|
@@ -19,19 +19,19 @@
|
|
|
19
19
|
"main": "./dist/index.js",
|
|
20
20
|
"types": "./dist/index.d.ts",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@fedimint/fedimint-client-wasm-bundler": "0.0
|
|
22
|
+
"@fedimint/fedimint-client-wasm-bundler": "0.1.0-alex-cache-wasm-build"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@rollup/plugin-terser": "^0.4.4",
|
|
26
26
|
"@rollup/plugin-typescript": "^11.1.6",
|
|
27
|
-
"@types/node": "^20.
|
|
27
|
+
"@types/node": "^20.17.49",
|
|
28
28
|
"@types/secp256k1": "^4.0.6",
|
|
29
|
-
"rollup": "^4.
|
|
30
|
-
"rollup-plugin-dts": "^6.
|
|
29
|
+
"rollup": "^4.41.0",
|
|
30
|
+
"rollup-plugin-dts": "^6.2.1",
|
|
31
31
|
"rollup-plugin-typescript2": "^0.36.0",
|
|
32
|
-
"secp256k1": "^5.0.
|
|
33
|
-
"tslib": "^2.
|
|
34
|
-
"typescript": "^5.
|
|
32
|
+
"secp256k1": "^5.0.1",
|
|
33
|
+
"tslib": "^2.8.1",
|
|
34
|
+
"typescript": "^5.8.3"
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
37
37
|
"build": "rollup --config",
|
|
@@ -58,3 +58,16 @@ walletTest('empty getBalance', async ({ wallet }) => {
|
|
|
58
58
|
await expect(wallet.waitForOpen()).resolves.toBeUndefined()
|
|
59
59
|
await expect(wallet.balance.getBalance()).resolves.toEqual(0)
|
|
60
60
|
})
|
|
61
|
+
|
|
62
|
+
walletTest('previewFederation', async ({ unopenedWallet }) => {
|
|
63
|
+
const preview = await unopenedWallet.previewFederation(
|
|
64
|
+
unopenedWallet.testing.TESTING_INVITE,
|
|
65
|
+
)
|
|
66
|
+
expect(preview).toBeDefined()
|
|
67
|
+
expect(preview.config).toBeDefined()
|
|
68
|
+
expect(preview.federation_id).toBeDefined()
|
|
69
|
+
expect(preview).toMatchObject({
|
|
70
|
+
config: expect.any(Object),
|
|
71
|
+
federation_id: expect.any(String),
|
|
72
|
+
})
|
|
73
|
+
})
|
package/src/FedimintWallet.ts
CHANGED
|
@@ -5,8 +5,10 @@ import {
|
|
|
5
5
|
LightningService,
|
|
6
6
|
FederationService,
|
|
7
7
|
RecoveryService,
|
|
8
|
+
WalletService,
|
|
8
9
|
} from './services'
|
|
9
10
|
import { logger, type LogLevel } from './utils/logger'
|
|
11
|
+
import { FederationConfig, JSONValue } from './types'
|
|
10
12
|
|
|
11
13
|
const DEFAULT_CLIENT_NAME = 'fm-default' as const
|
|
12
14
|
|
|
@@ -18,6 +20,7 @@ export class FedimintWallet {
|
|
|
18
20
|
public lightning: LightningService
|
|
19
21
|
public federation: FederationService
|
|
20
22
|
public recovery: RecoveryService
|
|
23
|
+
public wallet: WalletService
|
|
21
24
|
|
|
22
25
|
private _openPromise: Promise<void> | undefined = undefined
|
|
23
26
|
private _resolveOpen: () => void = () => {}
|
|
@@ -62,6 +65,7 @@ export class FedimintWallet {
|
|
|
62
65
|
this.balance = new BalanceService(this._client)
|
|
63
66
|
this.federation = new FederationService(this._client)
|
|
64
67
|
this.recovery = new RecoveryService(this._client)
|
|
68
|
+
this.wallet = new WalletService(this._client)
|
|
65
69
|
|
|
66
70
|
logger.info('FedimintWallet instantiated')
|
|
67
71
|
|
|
@@ -135,6 +139,14 @@ export class FedimintWallet {
|
|
|
135
139
|
return this._isOpen
|
|
136
140
|
}
|
|
137
141
|
|
|
142
|
+
async previewFederation(inviteCode: string) {
|
|
143
|
+
const response = this._client.sendSingleMessage<{
|
|
144
|
+
config: FederationConfig
|
|
145
|
+
federation_id: string
|
|
146
|
+
}>('previewFederation', { inviteCode })
|
|
147
|
+
return response
|
|
148
|
+
}
|
|
149
|
+
|
|
138
150
|
/**
|
|
139
151
|
* Sets the log level for the library.
|
|
140
152
|
* @param level The desired log level ('DEBUG', 'INFO', 'WARN', 'ERROR', 'NONE').
|
|
@@ -143,4 +155,61 @@ export class FedimintWallet {
|
|
|
143
155
|
logger.setLevel(level)
|
|
144
156
|
logger.info(`Log level set to ${level}.`)
|
|
145
157
|
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Parses a federation invite code and retrieves its details.
|
|
161
|
+
*
|
|
162
|
+
* This method sends the provided invite code to the WorkerClient for parsing.
|
|
163
|
+
* The response includes the federation_id and url.
|
|
164
|
+
*
|
|
165
|
+
* @param {string} inviteCode - The invite code to be parsed.
|
|
166
|
+
* @returns {Promise<{ federation_id: string, url: string}>}
|
|
167
|
+
* A promise that resolves to an object containing:
|
|
168
|
+
* - `federation_id`: The id of the feder.
|
|
169
|
+
* - `url`: One of the apipoints to connect to the federation
|
|
170
|
+
*
|
|
171
|
+
* @throws {Error} If the WorkerClient encounters an issue during the parsing process.
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* const inviteCode = "example-invite-code";
|
|
175
|
+
* const parsedCode = await wallet.parseInviteCode(inviteCode);
|
|
176
|
+
* console.log(parsedCode.federation_id, parsedCode.url);
|
|
177
|
+
*/
|
|
178
|
+
async parseInviteCode(inviteCode: string) {
|
|
179
|
+
const response = await this._client.sendSingleMessage<{
|
|
180
|
+
type: string
|
|
181
|
+
data: JSONValue
|
|
182
|
+
requestId: number
|
|
183
|
+
}>('parseInviteCode', { inviteCode })
|
|
184
|
+
return response
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Parses a BOLT11 Lightning invoice and retrieves its details.
|
|
189
|
+
*
|
|
190
|
+
* This method sends the provided invoice string to the WorkerClient for parsing.
|
|
191
|
+
* The response includes details such as the amount, expiry, and memo.
|
|
192
|
+
*
|
|
193
|
+
* @param {string} invoiceStr - The BOLT11 invoice string to be parsed.
|
|
194
|
+
* @returns {Promise<{ amount: string, expiry: number, memo: string }>}
|
|
195
|
+
* A promise that resolves to an object containing:
|
|
196
|
+
* - `amount`: The amount specified in the invoice.
|
|
197
|
+
* - `expiry`: The expiry time of the invoice in seconds.
|
|
198
|
+
* - `memo`: A description or memo attached to the invoice.
|
|
199
|
+
*
|
|
200
|
+
* @throws {Error} If the WorkerClient encounters an issue during the parsing process.
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* const invoiceStr = "lnbc1...";
|
|
204
|
+
* const parsedInvoice = await wallet.parseBolt11Invoice(invoiceStr);
|
|
205
|
+
* console.log(parsedInvoice.amount, parsedInvoice.expiry, parsedInvoice.memo);
|
|
206
|
+
*/
|
|
207
|
+
async parseBolt11Invoice(invoiceStr: string) {
|
|
208
|
+
const response = await this._client.sendSingleMessage<{
|
|
209
|
+
type: string
|
|
210
|
+
data: JSONValue
|
|
211
|
+
requestId: number
|
|
212
|
+
}>('parseBolt11Invoice', { invoiceStr })
|
|
213
|
+
return response
|
|
214
|
+
}
|
|
146
215
|
}
|
|
@@ -8,43 +8,22 @@ import { WorkerClient } from '../worker'
|
|
|
8
8
|
export class BalanceService {
|
|
9
9
|
constructor(private client: WorkerClient) {}
|
|
10
10
|
|
|
11
|
-
/**
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
* @example
|
|
15
|
-
* ```ts
|
|
16
|
-
* const balance = await wallet.balance.getBalance()
|
|
17
|
-
* ```
|
|
18
|
-
*/
|
|
19
|
-
async getBalance(): Promise<number> {
|
|
20
|
-
return await this.client.rpcSingle('', 'get_balance', {})
|
|
11
|
+
/** https://web.fedimint.org/core/FedimintWallet/BalanceService/getBalance */
|
|
12
|
+
async getBalance() {
|
|
13
|
+
return await this.client.rpcSingle<number>('', 'get_balance', {})
|
|
21
14
|
}
|
|
22
15
|
|
|
23
|
-
/**
|
|
24
|
-
* Subscribe to the balance of the current wallet in milli-satoshis (MSats)
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* ```ts
|
|
28
|
-
* const unsubscribe = wallet.balance.subscribeBalance((balance) => {
|
|
29
|
-
* console.log(balance)
|
|
30
|
-
* })
|
|
31
|
-
*
|
|
32
|
-
* // ...Cleanup Later
|
|
33
|
-
* unsubscribe()
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
16
|
+
/** https://web.fedimint.org/core/FedimintWallet/BalanceService/subscribeBalance */
|
|
36
17
|
subscribeBalance(
|
|
37
18
|
onSuccess: (balanceMsats: number) => void = () => {},
|
|
38
19
|
onError: (error: string) => void = () => {},
|
|
39
20
|
) {
|
|
40
|
-
|
|
21
|
+
return this.client.rpcStream<string>(
|
|
41
22
|
'',
|
|
42
23
|
'subscribe_balance_changes',
|
|
43
24
|
{},
|
|
44
25
|
(res) => onSuccess(parseInt(res)),
|
|
45
26
|
onError,
|
|
46
27
|
)
|
|
47
|
-
|
|
48
|
-
return unsubscribe
|
|
49
28
|
}
|
|
50
29
|
}
|