@fedimint/core-web 0.0.3 → 0.0.4

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.
Files changed (45) hide show
  1. package/dist/FedimintWallet.d.ts +34 -62
  2. package/dist/FedimintWallet.d.ts.map +1 -1
  3. package/dist/index.js +1 -1
  4. package/dist/index.js.map +1 -1
  5. package/dist/services/BalanceService.d.ts +8 -0
  6. package/dist/services/BalanceService.d.ts.map +1 -0
  7. package/dist/services/FederationService.d.ts +12 -0
  8. package/dist/services/FederationService.d.ts.map +1 -0
  9. package/dist/services/LightningService.d.ts +17 -0
  10. package/dist/services/LightningService.d.ts.map +1 -0
  11. package/dist/services/MintService.d.ts +15 -0
  12. package/dist/services/MintService.d.ts.map +1 -0
  13. package/dist/services/RecoveryService.d.ts +13 -0
  14. package/dist/services/RecoveryService.d.ts.map +1 -0
  15. package/dist/services/index.d.ts +6 -0
  16. package/dist/services/index.d.ts.map +1 -0
  17. package/dist/worker/WorkerClient.d.ts +41 -0
  18. package/dist/worker/WorkerClient.d.ts.map +1 -0
  19. package/dist/worker/index.d.ts +2 -0
  20. package/dist/worker/index.d.ts.map +1 -0
  21. package/dist/worker.js +1 -1
  22. package/dist/worker.js.map +1 -1
  23. package/node_modules/{fedimint-client-wasm → @fedimint/fedimint-client-wasm}/package.json +3 -6
  24. package/package.json +9 -7
  25. package/src/FedimintWallet.test.ts +74 -0
  26. package/src/FedimintWallet.ts +77 -465
  27. package/src/services/BalanceService.ts +24 -0
  28. package/src/services/FederationService.ts +32 -0
  29. package/src/services/LightningService.ts +128 -0
  30. package/src/services/MintService.ts +93 -0
  31. package/src/services/RecoveryService.ts +26 -0
  32. package/src/services/index.ts +5 -0
  33. package/src/worker/WorkerClient.ts +190 -0
  34. package/src/worker/index.ts +1 -0
  35. package/src/{worker.js → worker/worker.js} +14 -9
  36. package/wasm/fedimint_client_wasm.d.ts +0 -49
  37. package/wasm/fedimint_client_wasm.js +0 -4
  38. package/wasm/fedimint_client_wasm_bg.js +0 -1411
  39. package/wasm/fedimint_client_wasm_bg.wasm +0 -0
  40. package/wasm/fedimint_client_wasm_bg.wasm.d.ts +0 -110
  41. package/wasm/package.json +0 -26
  42. /package/node_modules/{fedimint-client-wasm → @fedimint/fedimint-client-wasm}/fedimint_client_wasm.d.ts +0 -0
  43. /package/node_modules/{fedimint-client-wasm → @fedimint/fedimint-client-wasm}/fedimint_client_wasm.js +0 -0
  44. /package/node_modules/{fedimint-client-wasm → @fedimint/fedimint-client-wasm}/fedimint_client_wasm_bg.js +0 -0
  45. /package/node_modules/{fedimint-client-wasm → @fedimint/fedimint-client-wasm}/fedimint_client_wasm_bg.wasm +0 -0
@@ -1,82 +1,54 @@
1
- import { JSONValue, JSONObject, LightningGateway, OutgoingLightningPayment, LnPayState, LnReceiveState, CreateBolt11Response, GatewayInfo, CancelFunction } from './types/wallet';
1
+ import { BalanceService, MintService, LightningService, FederationService, RecoveryService } from './services';
2
2
  export declare class FedimintWallet {
3
- private worker;
4
- private initPromise;
3
+ private client;
4
+ balance: BalanceService;
5
+ mint: MintService;
6
+ lightning: LightningService;
7
+ federation: FederationService;
8
+ recovery: RecoveryService;
5
9
  private openPromise;
6
10
  private resolveOpen;
7
11
  private _isOpen;
8
- private requestCounter;
9
- private requestCallbacks;
10
- constructor(lazy?: boolean, open?: boolean);
11
- waitForOpen(): Promise<void>;
12
- private getNextRequestId;
13
- private sendSingleMessage;
14
- initialize(): Promise<void>;
15
- private handleWorkerMessage;
16
- open(clientName?: string): Promise<any>;
17
- joinFederation(inviteCode: string, clientName?: string): Promise<void>;
18
12
  /**
19
- * @summary Initiates an RPC stream with the specified module and method.
13
+ * Creates a new instance of FedimintWallet.
20
14
  *
21
15
  * @description
22
- * This function sets up an RPC stream by sending a request to a worker and
23
- * handling responses asynchronously. It ensures that unsubscription is handled
24
- * correctly, even if the unsubscribe function is called before the subscription
25
- * is fully established, by deferring the unsubscription attempt using `setTimeout`.
16
+ * This constructor initializes a FedimintWallet instance, which manages communication
17
+ * with a Web Worker. The Web Worker is responsible for running WebAssembly code that
18
+ * handles the core Fedimint Client operations.
19
+ *
20
+ * (default) When not in lazy mode, the constructor immediately initializes the
21
+ * Web Worker and begins loading the WebAssembly module in the background. This
22
+ * allows for faster subsequent operations but may increase initial load time.
26
23
  *
27
- * The function operates in a non-blocking manner, leveraging Promises to manage
28
- * asynchronous operations and callbacks to handle responses.
24
+ * In lazy mode, the Web Worker and WebAssembly initialization are deferred until
25
+ * the first operation that requires them, reducing initial overhead at the cost
26
+ * of a slight delay on the first operation.
29
27
  *
28
+ * @param {boolean} lazy - If true, delays Web Worker and WebAssembly initialization
29
+ * until needed. Default is false.
30
30
  *
31
- * @template Response - The expected type of the successful response.
32
- * @template Body - The type of the request body.
33
- * @param module - The module kind to interact with.
34
- * @param method - The method name to invoke on the module.
35
- * @param body - The request payload.
36
- * @param onSuccess - Callback invoked with the response data on success.
37
- * @param onError - Callback invoked with error information if an error occurs.
38
- * @param onEnd - Optional callback invoked when the stream ends.
39
- * @returns A function that can be called to cancel the subscription.
31
+ * @example
32
+ * // Create a wallet with immediate initialization
33
+ * const wallet = new FedimintWallet();
34
+ * wallet.open();
40
35
  *
36
+ * // Create a wallet with lazy initialization
37
+ * const lazyWallet = new FedimintWallet(true);
38
+ * // Some time later...
39
+ * lazyWallet.initialize();
40
+ * lazyWallet.open();
41
41
  */
42
- private _rpcStream;
43
- private _rpcStreamInner;
44
- private _rpcSingle;
45
- getBalance(): Promise<number>;
46
- redeemEcash(notes: string): Promise<void>;
47
- reissueExternalNotes(oobNotes: string, extraMeta: JSONObject): Promise<string>;
48
- subscribeReissueExternalNotes(operationId: string, onSuccess?: (state: JSONValue) => void, onError?: (error: string) => void): CancelFunction;
49
- spendNotes(minAmount: number, tryCancelAfter: number, includeInvite: boolean, extraMeta: JSONValue): Promise<JSONValue>;
50
- validateNotes(oobNotes: string): Promise<number>;
51
- tryCancelSpendNotes(operationId: string): Promise<void>;
52
- subscribeSpendNotes(operationId: string, onSuccess?: (state: JSONValue) => void, onError?: (error: string) => void): CancelFunction;
53
- awaitSpendOobRefund(operationId: string): Promise<JSONValue>;
42
+ constructor(lazy?: boolean);
43
+ initialize(): Promise<void>;
44
+ waitForOpen(): Promise<void | null>;
45
+ open(clientName?: string): Promise<any>;
46
+ joinFederation(inviteCode: string, clientName?: string): Promise<void>;
54
47
  /**
55
48
  * This should ONLY be called when UNLOADING the wallet client.
56
49
  * After this call, the FedimintWallet instance should be discarded.
57
50
  */
58
51
  cleanup(): Promise<void>;
59
52
  isOpen(): boolean;
60
- getConfig(): Promise<JSONValue>;
61
- getFederationId(): Promise<string>;
62
- getInviteCode(peer: number): Promise<string | null>;
63
- listOperations(): Promise<JSONValue[]>;
64
- hasPendingRecoveries(): Promise<boolean>;
65
- waitForAllRecoveries(): Promise<void>;
66
- subscribeBalance(onSuccess?: (balance: number) => void, onError?: (error: string) => void): CancelFunction;
67
- subscribeToRecoveryProgress(onSuccess?: (progress: {
68
- module_id: number;
69
- progress: JSONValue;
70
- }) => void, onError?: (error: string) => void): CancelFunction;
71
- createBolt11InvoiceWithGateway(amount: number, description: string, expiryTime: (number | null) | undefined, extraMeta: JSONObject | undefined, gatewayInfo: GatewayInfo): Promise<JSONValue>;
72
- createBolt11Invoice(amount: number, description: string, expiryTime?: number | null, extraMeta?: JSONObject): Promise<CreateBolt11Response>;
73
- payBolt11InvoiceWithGateway(invoice: string, gatewayInfo: GatewayInfo, extraMeta?: JSONObject): Promise<JSONValue>;
74
- _getDefaultGatewayInfo(): Promise<LightningGateway>;
75
- payBolt11Invoice(invoice: string, extraMeta?: JSONObject): Promise<OutgoingLightningPayment>;
76
- subscribeLnPay(operationId: string, onSuccess?: (state: LnPayState) => void, onError?: (error: string) => void): CancelFunction;
77
- subscribeLnReceive(operationId: string, onSuccess?: (state: LnReceiveState) => void, onError?: (error: string) => void): CancelFunction;
78
- getGateway(gatewayId?: string | null, forceInternal?: boolean): Promise<LightningGateway | null>;
79
- listGateways(): Promise<LightningGateway[]>;
80
- updateGatewayCache(): Promise<void>;
81
53
  }
82
54
  //# sourceMappingURL=FedimintWallet.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"FedimintWallet.d.ts","sourceRoot":"","sources":["../src/FedimintWallet.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,UAAU,EACV,gBAAgB,EAChB,wBAAwB,EACxB,UAAU,EACV,cAAc,EAGd,oBAAoB,EAEpB,WAAW,EACX,cAAc,EACf,MAAM,gBAAgB,CAAA;AAIvB,qBAAa,cAAc;IACzB,OAAO,CAAC,MAAM,CAAsB;IACpC,OAAO,CAAC,WAAW,CAA6B;IAChD,OAAO,CAAC,WAAW,CAAe;IAClC,OAAO,CAAC,WAAW,CAAuB;IAC1C,OAAO,CAAC,OAAO,CAAiB;IAChC,OAAO,CAAC,cAAc,CAAY;IAClC,OAAO,CAAC,gBAAgB,CAA+C;gBAE3D,IAAI,GAAE,OAAe,EAAE,IAAI,GAAE,OAAc;IAQjD,WAAW;IAKjB,OAAO,CAAC,gBAAgB;IAMxB,OAAO,CAAC,iBAAiB;IAiBzB,UAAU;IAQV,OAAO,CAAC,mBAAmB;IASrB,IAAI,CAAC,UAAU,GAAE,MAA4B;IAe7C,cAAc,CAClB,UAAU,EAAE,MAAM,EAClB,UAAU,GAAE,MAA4B;IAe1C;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,OAAO,CAAC,UAAU;YA8CJ,eAAe;YA4Cf,UAAU;IAUlB,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;IAM7B,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOzC,oBAAoB,CACxB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,UAAU,GACpB,OAAO,CAAC,MAAM,CAAC;IAOlB,6BAA6B,CAC3B,WAAW,EAAE,MAAM,EACnB,SAAS,GAAE,CAAC,KAAK,EAAE,SAAS,KAAK,IAAe,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AAO,CAAC,MAAM,CAAc;IAErB,OAAO,EAAE,cAAc,CAAA;IACvB,IAAI,EAAE,WAAW,CAAA;IACjB,SAAS,EAAE,gBAAgB,CAAA;IAC3B,UAAU,EAAE,iBAAiB,CAAA;IAC7B,QAAQ,EAAE,eAAe,CAAA;IAEhC,OAAO,CAAC,WAAW,CAA6B;IAChD,OAAO,CAAC,WAAW,CAAuB;IAC1C,OAAO,CAAC,OAAO,CAAiB;IAEhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;gBACS,IAAI,GAAE,OAAe;IAgB3B,UAAU;IAIV,WAAW;IAKX,IAAI,CAAC,UAAU,GAAE,MAA4B;IAc7C,cAAc,CAClB,UAAU,EAAE,MAAM,EAClB,UAAU,GAAE,MAA4B;IAkB1C;;;OAGG;IACG,OAAO;IAMb,MAAM;CAGP"}
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- const e="fm-default";class t{constructor(e=!1,t=!0){this.worker=null,this.initPromise=null,this.resolveOpen=()=>{},this._isOpen=!1,this.requestCounter=0,this.requestCallbacks=new Map,this.openPromise=new Promise((e=>{this.resolveOpen=e})),e||this.initialize()}async waitForOpen(){if(!this._isOpen)return this.openPromise}getNextRequestId(){return++this.requestCounter}sendSingleMessage(e,t){return new Promise(((i,a)=>{const s=this.getNextRequestId();this.requestCallbacks.set(s,(e=>{this.requestCallbacks.delete(s),e.data?i(e.data):e.error&&a(e.error)}));try{this.worker.postMessage({type:e,payload:t,requestId:s})}catch(e){a(e)}}))}initialize(){return this.initPromise||(this.worker=new Worker(new URL("./worker.js",import.meta.url)),this.worker.onmessage=this.handleWorkerMessage.bind(this),this.initPromise=this.sendSingleMessage("init")),this.initPromise}handleWorkerMessage(e){const{type:t,requestId:i,...a}=e.data,s=this.requestCallbacks.get(i);s&&s(a)}async open(t=e){if(await this.initialize(),this._isOpen)throw new Error("The FedimintWallet is already open. You can only call `FedimintWallet.open on closed clients.`");const{success:i}=await this.sendSingleMessage("open",{clientName:t});return i&&(this._isOpen=!!i,this.resolveOpen()),i}async joinFederation(t,i=e){if(await this.initialize(),this._isOpen)throw new Error("Failed to Join Federation. You have already joined a federation, and you can only join one federation per wallet.");(await this.sendSingleMessage("join",{inviteCode:t,clientName:i})).success&&(this._isOpen=!0)}_rpcStream(e,t,i,a,s,n=()=>{}){const r=this.getNextRequestId();let o=()=>{},c=!1;const l=new Promise((e=>{o=()=>{c?e():setTimeout((()=>o()),0)}}));return this._rpcStreamInner(r,e,t,i,a,s,n,l).then((()=>{c=!0})),o}async _rpcStreamInner(e,t,i,a,s,n,r=()=>{},o){if(await this.openPromise,!this.worker||!this._isOpen)throw new Error("FedimintWallet is not open");this.requestCallbacks.set(e,(t=>{void 0!==t.error?n(t.error):void 0!==t.data?s(t.data):void 0!==t.end&&(this.requestCallbacks.delete(e),r())})),this.worker.postMessage({type:"rpc",payload:{module:t,method:i,body:a},requestId:e}),o.then((()=>{console.trace("UNSUBSCRIBING",e),this.worker?.postMessage({type:"unsubscribe",requestId:e}),this.requestCallbacks.delete(e)}))}async _rpcSingle(e,t,i){return new Promise(((a,s)=>{this._rpcStream(e,t,i,a,s)}))}async getBalance(){return await this._rpcSingle("","get_balance",{})}async redeemEcash(e){await this._rpcSingle("mint","reissue_external_notes",{oob_notes:e,extra_meta:null})}async reissueExternalNotes(e,t){return await this._rpcSingle("mint","reissue_external_notes",{oob_notes:e,extra_meta:t})}subscribeReissueExternalNotes(e,t=()=>{},i=()=>{}){return this._rpcStream("mint","subscribe_reissue_external_notes",{operation_id:e},(e=>t(e)),i)}async spendNotes(e,t,i,a){return await this._rpcSingle("mint","spend_notes",{min_amount:e,try_cancel_after:t,include_invite:i,extra_meta:a})}async validateNotes(e){return await this._rpcSingle("mint","validate_notes",{oob_notes:e})}async tryCancelSpendNotes(e){await this._rpcSingle("mint","try_cancel_spend_notes",{operation_id:e})}subscribeSpendNotes(e,t=()=>{},i=()=>{}){return this._rpcStream("mint","subscribe_spend_notes",{operation_id:e},(e=>t(e)),i)}async awaitSpendOobRefund(e){return await this._rpcSingle("mint","await_spend_oob_refund",{operation_id:e})}async cleanup(){this.worker?.terminate(),this.worker=null,this.openPromise=Promise.resolve(),this.requestCallbacks.clear()}isOpen(){return null!==this.worker&&this._isOpen}async getConfig(){return await this._rpcSingle("","get_config",{})}async getFederationId(){return await this._rpcSingle("","get_federation_id",{})}async getInviteCode(e){return await this._rpcSingle("","get_invite_code",{peer:e})}async listOperations(){return await this._rpcSingle("","list_operations",{})}async hasPendingRecoveries(){return await this._rpcSingle("","has_pending_recoveries",{})}async waitForAllRecoveries(){await this._rpcSingle("","wait_for_all_recoveries",{})}subscribeBalance(e=()=>{},t=()=>{}){return this._rpcStream("","subscribe_balance_changes",{},(t=>e(parseInt(t))),t)}subscribeToRecoveryProgress(e=()=>{},t=()=>{}){return this._rpcStream("","subscribe_to_recovery_progress",{},e,t)}async createBolt11InvoiceWithGateway(e,t,i=null,a={},s){return await this._rpcSingle("ln","create_bolt11_invoice",{amount:e,description:t,expiry_time:i,extra_meta:a,gateway:s})}async createBolt11Invoice(e,t,i=null,a={}){await this.updateGatewayCache();const s=await this._getDefaultGatewayInfo();return await this._rpcSingle("ln","create_bolt11_invoice",{amount:e,description:t,expiry_time:i,extra_meta:a,gateway:s.info})}async payBolt11InvoiceWithGateway(e,t,i={}){return await this._rpcSingle("ln","pay_bolt11_invoice",{maybe_gateway:t,invoice:e,extra_meta:i})}async _getDefaultGatewayInfo(){return(await this.listGateways())[0]}async payBolt11Invoice(e,t={}){await this.updateGatewayCache();const i=await this._getDefaultGatewayInfo();return await this._rpcSingle("ln","pay_bolt11_invoice",{maybe_gateway:i.info,invoice:e,extra_meta:t})}subscribeLnPay(e,t=()=>{},i=()=>{}){return this._rpcStream("ln","subscribe_ln_pay",{operation_id:e},t,i)}subscribeLnReceive(e,t=()=>{},i=()=>{}){return this._rpcStream("ln","subscribe_ln_receive",{operation_id:e},t,i)}async getGateway(e=null,t=!1){return await this._rpcSingle("ln","get_gateway",{gateway_id:e,force_internal:t})}async listGateways(){return await this._rpcSingle("ln","list_gateways",{})}async updateGatewayCache(){console.trace("Updating gateway cache"),await this._rpcSingle("ln","update_gateway_cache",{})}}export{t as FedimintWallet};
1
+ class e{constructor(){this.requestCounter=0,this.requestCallbacks=new Map,this.initPromise=null,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)}initialize(){return this.initPromise||(this.initPromise=this.sendSingleMessage("init")),this.initPromise}handleWorkerError(e){console.error("Worker error",JSON.stringify(e))}handleWorkerMessage(e){const{type:t,requestId:i,...n}=e.data,s=this.requestCallbacks.get(i);s&&s(n)}sendSingleMessage(e,t){return new Promise(((i,n)=>{const s=++this.requestCounter;this.requestCallbacks.set(s,(e=>{this.requestCallbacks.delete(s),e.data?i(e.data):e.error&&n(e.error)})),this.worker.postMessage({type:e,payload:t,requestId:s})}))}rpcStream(e,t,i,n,s,r=()=>{}){const a=++this.requestCounter;let c=()=>{},o=!1;const l=new Promise((e=>{c=()=>{o?e():setTimeout((()=>c()),0)}}));return this._rpcStreamInner(a,e,t,i,n,s,r,l).then((()=>{o=!0})),c}async _rpcStreamInner(e,t,i,n,s,r,a=()=>{},c){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}),c.then((()=>{this.worker?.postMessage({type:"unsubscribe",requestId:e}),this.requestCallbacks.delete(e)}))}rpcSingle(e,t,i){return new Promise(((n,s)=>{this.rpcStream(e,t,i,n,s)}))}cleanup(){this.worker.terminate(),this.initPromise=null,this.requestCallbacks.clear()}}class t{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,i,n){return await this.client.rpcSingle("mint","spend_notes",{min_amount:e,try_cancel_after:t,include_invite:i,extra_meta:n})}async validateNotes(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})}}class i{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 n{constructor(e){this.client=e}async createBolt11InvoiceWithGateway(e,t,i=null,n={},s){return await this.client.rpcSingle("ln","create_bolt11_invoice",{amount:e,description:t,expiry_time:i,extra_meta:n,gateway:s})}async createBolt11Invoice(e,t,i=null,n={}){await this.updateGatewayCache();const s=await this._getDefaultGatewayInfo();return await this.client.rpcSingle("ln","create_bolt11_invoice",{amount:e,description:t,expiry_time:i,extra_meta:n,gateway:s.info})}async payBolt11InvoiceWithGateway(e,t,i={}){return await this.client.rpcSingle("ln","pay_bolt11_invoice",{maybe_gateway:t,invoice:e,extra_meta:i})}async _getDefaultGatewayInfo(){return(await this.listGateways())[0]}async payBolt11Invoice(e,t={}){await this.updateGatewayCache();const i=await this._getDefaultGatewayInfo();return await this.client.rpcSingle("ln","pay_bolt11_invoice",{maybe_gateway:i.info,invoice:e,extra_meta:t})}subscribeLnPay(e,t=()=>{},i=()=>{}){return this.client.rpcStream("ln","subscribe_ln_pay",{operation_id:e},t,i)}subscribeLnReceive(e,t=()=>{},i=()=>{}){return this.client.rpcStream("ln","subscribe_ln_receive",{operation_id:e},t,i)}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 s{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 r{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){return await this.client.rpcSingle("","get_invite_code",{peer:e})}async joinFederation(e,t){if(!(await this.client.sendSingleMessage("join",{inviteCode:e,clientName:t})).success)throw new Error("Failed to join federation")}async listOperations(){return await this.client.rpcSingle("","list_operations",{})}}const a="fm-default";class c{constructor(a=!1){this.openPromise=null,this.resolveOpen=()=>{},this._isOpen=!1,this.openPromise=new Promise((e=>{this.resolveOpen=e})),this.client=new e,this.mint=new t(this.client),this.lightning=new n(this.client),this.balance=new i(this.client),this.federation=new r(this.client),this.recovery=new s(this.client),a||this.initialize()}async initialize(){await this.client.initialize()}async waitForOpen(){return this._isOpen?Promise.resolve():this.openPromise}async open(e=a){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,t=a){if(await this.client.initialize(),this._isOpen)throw new Error("The FedimintWallet is already open. You can only call `joinFederation` on closed clients.");(await this.client.sendSingleMessage("join",{inviteCode:e,clientName:t})).success&&(this._isOpen=!0,this.resolveOpen())}async cleanup(){this.openPromise=null,this._isOpen=!1,this.client.cleanup()}isOpen(){return this._isOpen}}export{c as FedimintWallet};
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/FedimintWallet.ts"],"sourcesContent":[null],"names":["DEFAULT_CLIENT_NAME","FedimintWallet","constructor","lazy","open","this","worker","initPromise","resolveOpen","_isOpen","requestCounter","requestCallbacks","Map","openPromise","Promise","resolve","initialize","waitForOpen","getNextRequestId","sendSingleMessage","type","payload","reject","requestId","set","data","delete","error","postMessage","e","Worker","URL","url","onmessage","handleWorkerMessage","bind","event","streamCallback","get","clientName","Error","success","joinFederation","inviteCode","_rpcStream","module","method","body","onSuccess","onError","onEnd","unsubscribe","isSubscribed","unsubscribePromise","setTimeout","_rpcStreamInner","then","response","undefined","end","console","trace","_rpcSingle","getBalance","redeemEcash","notes","oob_notes","extra_meta","reissueExternalNotes","oobNotes","extraMeta","subscribeReissueExternalNotes","operationId","operation_id","res","spendNotes","minAmount","tryCancelAfter","includeInvite","min_amount","try_cancel_after","include_invite","validateNotes","tryCancelSpendNotes","subscribeSpendNotes","awaitSpendOobRefund","cleanup","terminate","clear","isOpen","getConfig","getFederationId","getInviteCode","peer","listOperations","hasPendingRecoveries","waitForAllRecoveries","subscribeBalance","parseInt","subscribeToRecoveryProgress","createBolt11InvoiceWithGateway","amount","description","expiryTime","gatewayInfo","expiry_time","gateway","createBolt11Invoice","updateGatewayCache","_getDefaultGatewayInfo","info","payBolt11InvoiceWithGateway","invoice","maybe_gateway","listGateways","payBolt11Invoice","subscribeLnPay","subscribeLnReceive","getGateway","gatewayId","forceInternal","gateway_id","force_internal"],"mappings":"AAeA,MAAMA,EAAsB,mBAEfC,EASX,WAAAC,CAAYC,GAAgB,EAAOC,GAAgB,GAR3CC,KAAMC,OAAkB,KACxBD,KAAWE,YAAyB,KAEpCF,KAAAG,YAA0B,OAC1BH,KAAOI,SAAY,EACnBJ,KAAcK,eAAW,EACzBL,KAAAM,iBAAsD,IAAIC,IAGhEP,KAAKQ,YAAc,IAAIC,SAASC,IAC9BV,KAAKG,YAAc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C,EAAmC,QAUnC,OARoB5C,KAAKuC,WACvB,KACA,mBACA,CAAE6B,aAAcD,GAChBxB,EACAC,EAIH,CAED,kBAAAoE,CACE7C,EACAxB,EAA6C,OAC7CC,EAAmC,QAUnC,OARoB5C,KAAKuC,WACvB,KACA,uBACA,CAAE6B,aAAcD,GAChBxB,EACAC,EAIH,CAED,gBAAMqE,CACJC,EAA2B,KAC3BC,GAAyB,GAEzB,aAAanH,KAAKyD,WAAW,KAAM,cAAe,CAChD2D,WAAYF,EACZG,eAAgBF,GAEnB,CAED,kBAAMN,GACJ,aAAa7G,KAAKyD,WAAW,KAAM,gBAAiB,CAAE,EACvD,CAED,wBAAM8C,GACJhD,QAAQC,MAAM,gCACRxD,KAAKyD,WAAW,KAAM,uBAAwB,CAAE,EACvD"}
1
+ {"version":3,"file":"index.js","sources":["../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],"names":["WorkerClient","constructor","this","requestCounter","requestCallbacks","Map","initPromise","worker","Worker","URL","url","type","onmessage","handleWorkerMessage","bind","onerror","handleWorkerError","initialize","sendSingleMessage","event","console","error","JSON","stringify","requestId","data","streamCallback","get","payload","Promise","resolve","reject","set","response","delete","postMessage","rpcStream","module","method","body","onSuccess","onError","onEnd","unsubscribe","isSubscribed","unsubscribePromise","setTimeout","_rpcStreamInner","then","undefined","end","rpcSingle","cleanup","terminate","clear","MintService","client","redeemEcash","notes","oob_notes","extra_meta","reissueExternalNotes","oobNotes","extraMeta","subscribeReissueExternalNotes","operationId","operation_id","spendNotes","minAmount","tryCancelAfter","includeInvite","min_amount","try_cancel_after","include_invite","validateNotes","tryCancelSpendNotes","subscribeSpendNotes","res","awaitSpendOobRefund","BalanceService","getBalance","subscribeBalance","parseInt","LightningService","createBolt11InvoiceWithGateway","amount","description","expiryTime","gatewayInfo","expiry_time","gateway","createBolt11Invoice","updateGatewayCache","_getDefaultGatewayInfo","info","payBolt11InvoiceWithGateway","invoice","maybe_gateway","listGateways","payBolt11Invoice","subscribeLnPay","subscribeLnReceive","getGateway","gatewayId","forceInternal","gateway_id","force_internal","RecoveryService","hasPendingRecoveries","waitForAllRecoveries","subscribeToRecoveryProgress","FederationService","getConfig","getFederationId","getInviteCode","peer","joinFederation","inviteCode","clientName","success","Error","listOperations","DEFAULT_CLIENT_NAME","FedimintWallet","lazy","openPromise","resolveOpen","_isOpen","mint","lightning","balance","federation","recovery","waitForOpen","open","isOpen"],"mappings":"MAUaA,EAMX,WAAAC,GAJQC,KAAcC,eAAG,EACjBD,KAAAE,iBAAmB,IAAIC,IACvBH,KAAWI,YAAyB,KAI1CJ,KAAKK,OAAS,IAAIC,OAAO,IAAIC,IAAI,0BAA2BC,KAAM,CAChEC,KAAM,WAERT,KAAKK,OAAOK,UAAYV,KAAKW,oBAAoBC,KAAKZ,MACtDA,KAAKK,OAAOQ,QAAUb,KAAKc,kBAAkBF,KAAKZ,KACnD,CAGD,UAAAe,GACE,OAAIf,KAAKI,cACTJ,KAAKI,YAAcJ,KAAKgB,kBAAkB,SADbhB,KAAKI,WAGnC,CAEO,iBAAAU,CAAkBG,GACxBC,QAAQC,MAAM,eAAgBC,KAAKC,UAAUJ,GAC9C,CAEO,mBAAAN,CAAoBM,GAC1B,MAAMR,KAAEA,EAAIa,UAAEA,KAAcC,GAASN,EAAMM,KACrCC,EAAiBxB,KAAKE,iBAAiBuB,IAAIH,GAE7CE,GACFA,EAAeD,EAElB,CAMD,iBAAAP,CAAkBP,EAAciB,GAC9B,OAAO,IAAIC,SAAQ,CAACC,EAASC,KAC3B,MAAMP,IAActB,KAAKC,eACzBD,KAAKE,iBAAiB4B,IAAIR,GAAYS,IACpC/B,KAAKE,iBAAiB8B,OAAOV,GACzBS,EAASR,KAAMK,EAAQG,EAASR,MAC3BQ,EAASZ,OAAOU,EAAOE,EAASZ,MAAM,IAEjDnB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,QACjCtD,KAAK+H,UAAY,IAAI9C,EAAiBjF,KAAKsD,QAC3CtD,KAAKgI,QAAU,IAAInD,EAAe7E,KAAKsD,QACvCtD,KAAKiI,WAAa,IAAIpB,EAAkB7G,KAAKsD,QAC7CtD,KAAKkI,SAAW,IAAIzB,EAAgBzG,KAAKsD,QAEpCoE,GACH1H,KAAKe,YAER,CAED,gBAAMA,SACEf,KAAKsD,OAAOvC,YACnB,CAED,iBAAMoH,GACJ,OAAInI,KAAK6H,QAAgBlG,QAAQC,UAC1B5B,KAAK2H,WACb,CAED,UAAMS,CAAKhB,EAAqBI,GAG9B,SAFMxH,KAAKsD,OAAOvC,aAEdf,KAAK6H,QAAS,MAAM,IAAIP,MAAM,uCAClC,MAAMD,QAAEA,SAAkBrH,KAAKsD,OAAOtC,kBAAkB,OAAQ,CAC9DoG,eAMF,OAJIC,IACFrH,KAAK6H,UAAYR,EACjBrH,KAAK4H,eAEAP,CACR,CAED,oBAAMH,CACJC,EACAC,EAAqBI,GAIrB,SAFMxH,KAAKsD,OAAOvC,aAEdf,KAAK6H,QACP,MAAM,IAAIP,MACR,oGAEmBtH,KAAKsD,OAAOtC,kBAAkB,OAAQ,CAC3DmG,aACAC,gBAEWC,UACXrH,KAAK6H,SAAU,EACf7H,KAAK4H,cAER,CAMD,aAAM1E,GACJlD,KAAK2H,YAAc,KACnB3H,KAAK6H,SAAU,EACf7H,KAAKsD,OAAOJ,SACb,CAED,MAAAmF,GACE,OAAOrI,KAAK6H,OACb"}
@@ -0,0 +1,8 @@
1
+ import { WorkerClient } from '../worker';
2
+ export declare class BalanceService {
3
+ private client;
4
+ constructor(client: WorkerClient);
5
+ getBalance(): Promise<number>;
6
+ subscribeBalance(onSuccess?: (balance: number) => void, onError?: (error: string) => void): import("../types/wallet").CancelFunction;
7
+ }
8
+ //# sourceMappingURL=BalanceService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BalanceService.d.ts","sourceRoot":"","sources":["../../src/services/BalanceService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAExC,qBAAa,cAAc;IACb,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,YAAY;IAElC,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;IAInC,gBAAgB,CACd,SAAS,GAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAe,EAC/C,OAAO,GAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAe;CAY9C"}
@@ -0,0 +1,12 @@
1
+ import { JSONValue } from '../types/wallet';
2
+ import { WorkerClient } from '../worker';
3
+ export declare class FederationService {
4
+ private client;
5
+ constructor(client: WorkerClient);
6
+ getConfig(): Promise<JSONValue>;
7
+ getFederationId(): Promise<string>;
8
+ getInviteCode(peer: number): Promise<string | null>;
9
+ joinFederation(inviteCode: string, clientName: string): Promise<void>;
10
+ listOperations(): Promise<JSONValue[]>;
11
+ }
12
+ //# sourceMappingURL=FederationService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FederationService.d.ts","sourceRoot":"","sources":["../../src/services/FederationService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAExC,qBAAa,iBAAiB;IAChB,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,YAAY;IAElC,SAAS,IAAI,OAAO,CAAC,SAAS,CAAC;IAI/B,eAAe,IAAI,OAAO,CAAC,MAAM,CAAC;IAIlC,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAInD,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAUrE,cAAc,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;CAG7C"}
@@ -0,0 +1,17 @@
1
+ import { WorkerClient } from '../worker';
2
+ import { CreateBolt11Response, GatewayInfo, JSONObject, JSONValue, LightningGateway, LnPayState, LnReceiveState, OutgoingLightningPayment } from '../types/wallet';
3
+ export declare class LightningService {
4
+ private client;
5
+ constructor(client: WorkerClient);
6
+ createBolt11InvoiceWithGateway(amount: number, description: string, expiryTime: (number | null) | undefined, extraMeta: JSONObject | undefined, gatewayInfo: GatewayInfo): Promise<JSONValue>;
7
+ createBolt11Invoice(amount: number, description: string, expiryTime?: number | null, extraMeta?: JSONObject): Promise<CreateBolt11Response>;
8
+ payBolt11InvoiceWithGateway(invoice: string, gatewayInfo: GatewayInfo, extraMeta?: JSONObject): Promise<JSONValue>;
9
+ _getDefaultGatewayInfo(): Promise<LightningGateway>;
10
+ payBolt11Invoice(invoice: string, extraMeta?: JSONObject): Promise<OutgoingLightningPayment>;
11
+ subscribeLnPay(operationId: string, onSuccess?: (state: LnPayState) => void, onError?: (error: string) => void): import("../types/wallet").CancelFunction;
12
+ subscribeLnReceive(operationId: string, onSuccess?: (state: LnReceiveState) => void, onError?: (error: string) => void): import("../types/wallet").CancelFunction;
13
+ getGateway(gatewayId?: string | null, forceInternal?: boolean): Promise<LightningGateway | null>;
14
+ listGateways(): Promise<LightningGateway[]>;
15
+ updateGatewayCache(): Promise<JSONValue>;
16
+ }
17
+ //# sourceMappingURL=LightningService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LightningService.d.ts","sourceRoot":"","sources":["../../src/services/LightningService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AACxC,OAAO,EACL,oBAAoB,EACpB,WAAW,EACX,UAAU,EACV,SAAS,EACT,gBAAgB,EAChB,UAAU,EACV,cAAc,EACd,wBAAwB,EACzB,MAAM,iBAAiB,CAAA;AAExB,qBAAa,gBAAgB;IACf,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,YAAY;IAElC,8BAA8B,CAClC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,EACnB,UAAU,GAAE,MAAM,GAAG,IAAI,aAAO,EAChC,SAAS,EAAE,UAAU,YAAK,EAC1B,WAAW,EAAE,WAAW;IAWpB,mBAAmB,CACvB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,EACnB,UAAU,GAAE,MAAM,GAAG,IAAW,EAChC,SAAS,GAAE,UAAe,GACzB,OAAO,CAAC,oBAAoB,CAAC;IAY1B,2BAA2B,CAC/B,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,WAAW,EACxB,SAAS,GAAE,UAAe;IAStB,sBAAsB,IAAI,OAAO,CAAC,gBAAgB,CAAC;IAKnD,gBAAgB,CACpB,OAAO,EAAE,MAAM,EACf,SAAS,GAAE,UAAe,GACzB,OAAO,CAAC,wBAAwB,CAAC;IAUpC,cAAc,CACZ,WAAW,EAAE,MAAM,EACnB,SAAS,GAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAe,EACjD,OAAO,GAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAe;IAa7C,kBAAkB,CAChB,WAAW,EAAE,MAAM,EACnB,SAAS,GAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAe,EACrD,OAAO,GAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAe;IAavC,UAAU,CACd,SAAS,GAAE,MAAM,GAAG,IAAW,EAC/B,aAAa,GAAE,OAAe,GAC7B,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC;IAO7B,YAAY,IAAI,OAAO,CAAC,gBAAgB,EAAE,CAAC;IAI3C,kBAAkB,IAAI,OAAO,CAAC,SAAS,CAAC;CAG/C"}
@@ -0,0 +1,15 @@
1
+ import { WorkerClient } from '../worker';
2
+ import { JSONObject, JSONValue } from '../types/wallet';
3
+ export declare class MintService {
4
+ private client;
5
+ constructor(client: WorkerClient);
6
+ redeemEcash(notes: string): Promise<void>;
7
+ reissueExternalNotes(oobNotes: string, extraMeta: JSONObject): Promise<string>;
8
+ subscribeReissueExternalNotes(operationId: string, onSuccess?: (state: JSONValue) => void, onError?: (error: string) => void): import("../types/wallet").CancelFunction;
9
+ spendNotes(minAmount: number, tryCancelAfter: number, includeInvite: boolean, extraMeta: JSONValue): Promise<JSONValue>;
10
+ validateNotes(oobNotes: string): Promise<number>;
11
+ tryCancelSpendNotes(operationId: string): Promise<void>;
12
+ subscribeSpendNotes(operationId: string, onSuccess?: (state: JSONValue) => void, onError?: (error: string) => void): import("../types/wallet").CancelFunction;
13
+ awaitSpendOobRefund(operationId: string): Promise<JSONValue>;
14
+ }
15
+ //# sourceMappingURL=MintService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MintService.d.ts","sourceRoot":"","sources":["../../src/services/MintService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AACxC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAEvD,qBAAa,WAAW;IACV,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,YAAY;IAElC,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOzC,oBAAoB,CACxB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,UAAU,GACpB,OAAO,CAAC,MAAM,CAAC;IAOlB,6BAA6B,CAC3B,WAAW,EAAE,MAAM,EACnB,SAAS,GAAE,CAAC,KAAK,EAAE,SAAS,KAAK,IAAe,EAChD,OAAO,GAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAe;IAmBvC,UAAU,CACd,SAAS,EAAE,MAAM,EACjB,cAAc,EAAE,MAAM,EACtB,aAAa,EAAE,OAAO,EACtB,SAAS,EAAE,SAAS,GACnB,OAAO,CAAC,SAAS,CAAC;IASf,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAMhD,mBAAmB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAM7D,mBAAmB,CACjB,WAAW,EAAE,MAAM,EACnB,SAAS,GAAE,CAAC,KAAK,EAAE,SAAS,KAAK,IAAe,EAChD,OAAO,GAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAe;IAavC,mBAAmB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;CAKnE"}
@@ -0,0 +1,13 @@
1
+ import { JSONValue } from '../types/wallet';
2
+ import { WorkerClient } from '../worker';
3
+ export declare class RecoveryService {
4
+ private client;
5
+ constructor(client: WorkerClient);
6
+ hasPendingRecoveries(): Promise<boolean>;
7
+ waitForAllRecoveries(): Promise<void>;
8
+ subscribeToRecoveryProgress(onSuccess: (progress: {
9
+ module_id: number;
10
+ progress: JSONValue;
11
+ }) => void, onError: (error: string) => void): () => void;
12
+ }
13
+ //# sourceMappingURL=RecoveryService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RecoveryService.d.ts","sourceRoot":"","sources":["../../src/services/RecoveryService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAExC,qBAAa,eAAe;IACd,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,YAAY;IAElC,oBAAoB,IAAI,OAAO,CAAC,OAAO,CAAC;IAIxC,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC;IAI3C,2BAA2B,CACzB,SAAS,EAAE,CAAC,QAAQ,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,SAAS,CAAA;KAAE,KAAK,IAAI,EACzE,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,GAC/B,MAAM,IAAI;CAQd"}
@@ -0,0 +1,6 @@
1
+ export { MintService } from './MintService';
2
+ export { BalanceService } from './BalanceService';
3
+ export { LightningService } from './LightningService';
4
+ export { RecoveryService } from './RecoveryService';
5
+ export { FederationService } from './FederationService';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA"}
@@ -0,0 +1,41 @@
1
+ import { CancelFunction, JSONValue, ModuleKind, StreamError } from '../types/wallet';
2
+ export declare class WorkerClient {
3
+ private worker;
4
+ private requestCounter;
5
+ private requestCallbacks;
6
+ private initPromise;
7
+ constructor();
8
+ initialize(): Promise<void>;
9
+ private handleWorkerError;
10
+ private handleWorkerMessage;
11
+ sendSingleMessage(type: string, payload?: any): Promise<any>;
12
+ /**
13
+ * @summary Initiates an RPC stream with the specified module and method.
14
+ *
15
+ * @description
16
+ * This function sets up an RPC stream by sending a request to a worker and
17
+ * handling responses asynchronously. It ensures that unsubscription is handled
18
+ * correctly, even if the unsubscribe function is called before the subscription
19
+ * is fully established, by deferring the unsubscription attempt using `setTimeout`.
20
+ *
21
+ * The function operates in a non-blocking manner, leveraging Promises to manage
22
+ * asynchronous operations and callbacks to handle responses.
23
+ *
24
+ *
25
+ * @template Response - The expected type of the successful response.
26
+ * @template Body - The type of the request body.
27
+ * @param module - The module kind to interact with.
28
+ * @param method - The method name to invoke on the module.
29
+ * @param body - The request payload.
30
+ * @param onSuccess - Callback invoked with the response data on success.
31
+ * @param onError - Callback invoked with error information if an error occurs.
32
+ * @param onEnd - Optional callback invoked when the stream ends.
33
+ * @returns A function that can be called to cancel the subscription.
34
+ *
35
+ */
36
+ 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;
37
+ private _rpcStreamInner;
38
+ rpcSingle<Response extends JSONValue = JSONValue>(module: ModuleKind, method: string, body: JSONValue): Promise<Response>;
39
+ cleanup(): void;
40
+ }
41
+ //# sourceMappingURL=WorkerClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WorkerClient.d.ts","sourceRoot":"","sources":["../../src/worker/WorkerClient.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,SAAS,EACT,UAAU,EACV,WAAW,EAEZ,MAAM,iBAAiB,CAAA;AAIxB,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAQ;IACtB,OAAO,CAAC,cAAc,CAAI;IAC1B,OAAO,CAAC,gBAAgB,CAA0C;IAClE,OAAO,CAAC,WAAW,CAA6B;;IAYhD,UAAU;IAMV,OAAO,CAAC,iBAAiB;IAIzB,OAAO,CAAC,mBAAmB;IAa3B,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;IAY5D;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,SAAS,CACP,QAAQ,SAAS,SAAS,GAAG,SAAS,EACtC,IAAI,SAAS,SAAS,GAAG,SAAS,EAElC,MAAM,EAAE,UAAU,EAClB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,IAAI,EACV,SAAS,EAAE,CAAC,GAAG,EAAE,QAAQ,KAAK,IAAI,EAClC,OAAO,EAAE,CAAC,GAAG,EAAE,WAAW,CAAC,OAAO,CAAC,KAAK,IAAI,EAC5C,KAAK,GAAE,MAAM,IAAe,GAC3B,cAAc;YAoCH,eAAe;IA2C7B,SAAS,CAAC,QAAQ,SAAS,SAAS,GAAG,SAAS,EAC9C,MAAM,EAAE,UAAU,EAClB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,SAAS,GACd,OAAO,CAAC,QAAQ,CAAC;IAMpB,OAAO;CAKR"}
@@ -0,0 +1,2 @@
1
+ export { WorkerClient } from './WorkerClient';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/worker/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA"}
package/dist/worker.js CHANGED
@@ -1,2 +1,2 @@
1
- let e=null,s=null;const t=new Map;self.onmessage=async n=>{const{type:a,payload:o,requestId:r}=n.data;if("init"===a)e=(await import("fedimint-client-wasm")).WasmClient,self.postMessage({type:"initialized",data:{},requestId:r});else if("open"===a){const{clientName:t}=o;s=await e.open(t)||null,self.postMessage({type:"open",data:{success:!!s},requestId:r})}else if("join"===a){const{inviteCode:t,clientName:n}=o;try{s=await e.join_federation(n,t),self.postMessage({type:"join",data:{success:!!s},requestId:r})}catch(e){self.postMessage({type:"error",error:e.message,requestId:r})}}else if("rpc"===a){const{module:e,method:n,body:a}=o;if(!s)return void self.postMessage({type:"error",error:"WasmClient not initialized",requestId:r});const i=await s.rpc(e,n,JSON.stringify(a),(e=>{const s=JSON.parse(e);if(self.postMessage({type:"rpcResponse",requestId:r,...s}),void 0===s.end)return;const n=t.get(r);n?.free()}));t.set(r,i)}else if("unsubscribe"===a){const e=t.get(r);e&&(e.cancel(),e.free(),t.delete(r))}else self.postMessage({type:"error",error:"Unknown message type",requestId:r})};
1
+ globalThis.__vitest_browser_runner__={wrapDynamicImport:e=>e()};let e=null,s=null;const t=new Map;self.onmessage=async o=>{const{type:n,payload:i,requestId:a}=o.data;if("init"===n)e=(await import("@fedimint/fedimint-client-wasm")).WasmClient,self.postMessage({type:"initialized",data:{},requestId:a});else if("open"===n){const{clientName:t}=i;s=await e.open(t)||null,self.postMessage({type:"open",data:{success:!!s},requestId:a})}else if("join"===n){const{inviteCode:t,clientName:o}=i;try{s=await e.join_federation(o,t),self.postMessage({type:"join",data:{success:!!s},requestId:a})}catch(e){self.postMessage({type:"error",error:e.message,requestId:a})}}else if("rpc"===n){const{module:e,method:o,body:n}=i;if(console.log("RPC received",e,o,n),!s)return void self.postMessage({type:"error",error:"WasmClient not initialized",requestId:a});const r=await s.rpc(e,o,JSON.stringify(n),(e=>{console.log("RPC response",a,e);const s=JSON.parse(e);if(self.postMessage({type:"rpcResponse",requestId:a,...s}),void 0!==s.end){const e=t.get(a);e?.free()}}));t.set(a,r)}else if("unsubscribe"===n){const e=t.get(a);e&&(e.cancel(),e.free(),t.delete(a))}else self.postMessage({type:"error",error:"Unknown message type",requestId:a})},self.postMessage({type:"init",data:{}});
2
2
  //# sourceMappingURL=worker.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"worker.js","sources":["../src/worker.js"],"sourcesContent":["// import { WasmClient } from '../wasm/fedimint_client_wasm.js'\n// import { WasmClient } from 'fedimint-client-wasm'\n// import wasm from '../wasm/fedimint_client_wasm_bg.wasm'\n\nlet WasmClient = null\nlet client = null\n\nconst streamCancelMap = new Map()\n\nconst handleFree = (requestId) => {\n streamCancelMap.delete(requestId)\n}\n\nself.onmessage = async (event) => {\n const { type, payload, requestId } = event.data\n\n if (type === 'init') {\n WasmClient = (await import('fedimint-client-wasm')).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 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 const data = JSON.parse(res)\n self.postMessage({ type: 'rpcResponse', requestId, ...data })\n\n if (data.end === undefined) return\n\n // Handle stream ending\n const handle = streamCancelMap.get(requestId)\n handle?.free()\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 {\n self.postMessage({\n type: 'error',\n error: 'Unknown message type',\n requestId,\n })\n }\n}\n"],"names":["WasmClient","client","streamCancelMap","Map","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","JSON","stringify","res","parse","undefined","end","handle","get","free","set","cancel","delete"],"mappings":"AAIA,IAAIA,EAAa,KACbC,EAAS,KAEb,MAAMC,EAAkB,IAAIC,IAM5BC,KAAKC,UAAYC,MAAOC,IACtB,MAAMC,KAAEA,EAAIC,QAAEA,EAAOC,UAAEA,GAAcH,EAAMI,KAE3C,GAAa,SAATH,EACFR,SAAoBY,OAAO,yBAAyBZ,WACpDI,KAAKS,YAAY,CAAEL,KAAM,cAAeG,KAAM,CAAA,EAAID,mBAC7C,GAAa,SAATF,EAAiB,CAC1B,MAAMM,WAAEA,GAAeL,EACvBR,QAAgBD,EAAWe,KAAKD,IAAgB,KAChDV,KAAKS,YAAY,CACfL,KAAM,OACNG,KAAM,CAAEK,UAAWf,GACnBS,aAEN,MAAS,GAAa,SAATF,EAAiB,CAC1B,MAAMS,WAAEA,EAAYH,WAAYI,GAAmBT,EACnD,IACER,QAAeD,EAAWmB,gBAAgBD,EAAgBD,GAC1Db,KAAKS,YAAY,CACfL,KAAM,OACNG,KAAM,CAAEK,UAAWf,GACnBS,aAEH,CAAC,MAAOU,GACPhB,KAAKS,YAAY,CAAEL,KAAM,QAASa,MAAOD,EAAEE,QAASZ,aACrD,CACL,MAAS,GAAa,QAATF,EAAgB,CACzB,MAAMe,OAAEA,EAAMC,OAAEA,EAAMC,KAAEA,GAAShB,EACjC,IAAKR,EAMH,YALAG,KAAKS,YAAY,CACfL,KAAM,QACNa,MAAO,6BACPX,cAIJ,MAAMgB,QAAkBzB,EAAO0B,IAC7BJ,EACAC,EACAI,KAAKC,UAAUJ,IACdK,IACC,MAAMnB,EAAOiB,KAAKG,MAAMD,GAGxB,GAFA1B,KAAKS,YAAY,CAAEL,KAAM,cAAeE,eAAcC,SAErCqB,IAAbrB,EAAKsB,IAAmB,OAG5B,MAAMC,EAAShC,EAAgBiC,IAAIzB,GACnCwB,GAAQE,MAAM,IAGlBlC,EAAgBmC,IAAI3B,EAAWgB,EACnC,MAAS,GAAa,gBAATlB,EAAwB,CACjC,MAAMkB,EAAYxB,EAAgBiC,IAAIzB,GAClCgB,IACFA,EAAUY,SACVZ,EAAUU,OACVlC,EAAgBqC,OAAO7B,GAE7B,MACIN,KAAKS,YAAY,CACfL,KAAM,QACNa,MAAO,uBACPX,aAEH"}
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\nglobalThis.__vitest_browser_runner__ = { wrapDynamicImport: (foo) => foo() }\n\nlet WasmClient = null\nlet client = null\n\nconst streamCancelMap = new Map()\n\nconst handleFree = (requestId) => {\n streamCancelMap.delete(requestId)\n}\n\nself.onmessage = async (event) => {\n const { type, payload, requestId } = event.data\n\n if (type === 'init') {\n WasmClient = (await import('@fedimint/fedimint-client-wasm')).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 {\n self.postMessage({\n type: 'error',\n error: 'Unknown message type',\n requestId,\n })\n }\n}\n\nself.postMessage({ type: 'init', data: {} })\n"],"names":["globalThis","__vitest_browser_runner__","wrapDynamicImport","foo","WasmClient","client","streamCancelMap","Map","self","onmessage","async","event","type","payload","requestId","data","import","postMessage","clientName","open","success","inviteCode","joinClientName","join_federation","e","error","message","module","method","body","console","log","rpcHandle","rpc","JSON","stringify","res","parse","undefined","end","handle","get","free","set","cancel","delete"],"mappings":"AAGAA,WAAWC,0BAA4B,CAAEC,kBAAoBC,GAAQA,KAErE,IAAIC,EAAa,KACbC,EAAS,KAEb,MAAMC,EAAkB,IAAIC,IAM5BC,KAAKC,UAAYC,MAAOC,IACtB,MAAMC,KAAEA,EAAIC,QAAEA,EAAOC,UAAEA,GAAcH,EAAMI,KAE3C,GAAa,SAATH,EACFR,SAAoBY,OAAO,mCAAmCZ,WAC9DI,KAAKS,YAAY,CAAEL,KAAM,cAAeG,KAAM,CAAA,EAAID,mBAC7C,GAAa,SAATF,EAAiB,CAC1B,MAAMM,WAAEA,GAAeL,EACvBR,QAAgBD,EAAWe,KAAKD,IAAgB,KAChD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module",
4
- "collaborators": [
5
- "The Fedimint Developers"
6
- ],
7
- "description": "fedimint client for wasm",
8
- "version": "0.5.0-alpha",
5
+ "description": "Wasm-pack output for fedimint-client-wasm",
9
6
  "license": "MIT",
10
7
  "repository": {
11
8
  "type": "git",
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.3",
4
+ "version": "0.0.4",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/fedimint/fedimint-web-sdk.git",
@@ -9,18 +9,20 @@
9
9
  },
10
10
  "files": [
11
11
  "dist",
12
- "src",
13
- "wasm"
12
+ "src"
13
+ ],
14
+ "sideEffects": [
15
+ "./dist/worker.js",
16
+ "./dist/index.js"
14
17
  ],
15
- "sideEffects": false,
16
18
  "type": "module",
17
19
  "main": "./dist/index.js",
18
20
  "types": "./dist/index.d.ts",
19
21
  "dependencies": {
20
- "fedimint-client-wasm": "file:./wasm"
22
+ "@fedimint/fedimint-client-wasm": "file:./wasm"
21
23
  },
22
- "bundledDependencies": [
23
- "fedimint-client-wasm"
24
+ "bundleDependencies": [
25
+ "@fedimint/fedimint-client-wasm"
24
26
  ],
25
27
  "devDependencies": {
26
28
  "@rollup/plugin-terser": "^0.4.4",
@@ -0,0 +1,74 @@
1
+ import { test, expect, vi } from 'vitest'
2
+ import { FedimintWallet } from './FedimintWallet'
3
+ import { beforeAll } from 'vitest'
4
+
5
+ let randomTestingId: string
6
+ let wallet: FedimintWallet
7
+ // Testnet
8
+ const TESTING_FEDERATION =
9
+ 'fed11qgqrgvnhwden5te0v9k8q6rp9ekh2arfdeukuet595cr2ttpd3jhq6rzve6zuer9wchxvetyd938gcewvdhk6tcqqysptkuvknc7erjgf4em3zfh90kffqf9srujn6q53d6r056e4apze5cw27h75'
10
+
11
+ beforeAll(() => {
12
+ randomTestingId = Math.random().toString(36).substring(2, 15)
13
+ wallet = new FedimintWallet()
14
+ expect(wallet).toBeDefined()
15
+
16
+ // Cleanup after all tests
17
+ return async () => {
18
+ // clear up browser resources
19
+ await wallet.cleanup()
20
+ // remove the wallet db
21
+ indexedDB.deleteDatabase(randomTestingId)
22
+ // swap out the randomTestingId for a new one, to avoid raciness
23
+ randomTestingId = Math.random().toString(36).substring(2, 15)
24
+ }
25
+ })
26
+
27
+ test('initial open & join', async () => {
28
+ expect(wallet).toBeDefined()
29
+ expect(wallet.isOpen()).toBe(false)
30
+ // On initial open, it should return false
31
+ // because no federations have been joined
32
+ await expect(wallet.open(randomTestingId)).resolves.toBe(false)
33
+ await expect(
34
+ wallet.joinFederation(TESTING_FEDERATION, randomTestingId),
35
+ ).resolves.toBeUndefined()
36
+ expect(wallet.isOpen()).toBe(true)
37
+ await expect(wallet.waitForOpen()).resolves.toBeUndefined()
38
+ })
39
+
40
+ test('Error on open & join if wallet is already open', async () => {
41
+ expect(wallet).toBeDefined()
42
+ expect(wallet.isOpen()).toBe(true)
43
+
44
+ // Test opening an already open wallet
45
+ try {
46
+ await wallet.open(randomTestingId)
47
+ } catch (error) {
48
+ expect(error).toBeInstanceOf(Error)
49
+ expect((error as Error).message).toBe('The FedimintWallet is already open.')
50
+ }
51
+
52
+ // Test joining federation on an already open wallet
53
+ try {
54
+ await wallet.joinFederation(TESTING_FEDERATION, randomTestingId)
55
+ } catch (error) {
56
+ expect(error).toBeInstanceOf(Error)
57
+ expect((error as Error).message).toBe(
58
+ 'The FedimintWallet is already open. You can only call `joinFederation` on closed clients.',
59
+ )
60
+ }
61
+ })
62
+ test('getConfig', async () => {
63
+ expect(wallet).toBeDefined()
64
+ expect(wallet.isOpen()).toBe(true)
65
+ const config = await wallet.federation.getConfig()
66
+ expect(config).toBeDefined()
67
+ })
68
+
69
+ test('empty getBalance', async () => {
70
+ expect(wallet).toBeDefined()
71
+ expect(wallet.isOpen()).toBe(true)
72
+ await expect(wallet.waitForOpen()).resolves.toBeUndefined()
73
+ await expect(wallet.balance.getBalance()).resolves.toEqual(0)
74
+ })