@fedimint/core-web 0.0.2 → 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 (53) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +34 -13
  3. package/dist/FedimintWallet.d.ts +40 -33
  4. package/dist/FedimintWallet.d.ts.map +1 -1
  5. package/dist/index.js +1 -1
  6. package/dist/index.js.map +1 -1
  7. package/dist/services/BalanceService.d.ts +8 -0
  8. package/dist/services/BalanceService.d.ts.map +1 -0
  9. package/dist/services/FederationService.d.ts +12 -0
  10. package/dist/services/FederationService.d.ts.map +1 -0
  11. package/dist/services/LightningService.d.ts +17 -0
  12. package/dist/services/LightningService.d.ts.map +1 -0
  13. package/dist/services/MintService.d.ts +15 -0
  14. package/dist/services/MintService.d.ts.map +1 -0
  15. package/dist/services/RecoveryService.d.ts +13 -0
  16. package/dist/services/RecoveryService.d.ts.map +1 -0
  17. package/dist/services/index.d.ts +6 -0
  18. package/dist/services/index.d.ts.map +1 -0
  19. package/dist/types/wallet.d.ts +19 -3
  20. package/dist/types/wallet.d.ts.map +1 -1
  21. package/dist/worker/WorkerClient.d.ts +41 -0
  22. package/dist/worker/WorkerClient.d.ts.map +1 -0
  23. package/dist/worker/index.d.ts +2 -0
  24. package/dist/worker/index.d.ts.map +1 -0
  25. package/dist/worker.js +2 -0
  26. package/dist/worker.js.map +1 -0
  27. package/node_modules/@fedimint/fedimint-client-wasm/fedimint_client_wasm.d.ts +49 -0
  28. package/node_modules/@fedimint/fedimint-client-wasm/fedimint_client_wasm.js +4 -0
  29. package/node_modules/@fedimint/fedimint-client-wasm/fedimint_client_wasm_bg.js +1411 -0
  30. package/{wasm → node_modules/@fedimint/fedimint-client-wasm}/fedimint_client_wasm_bg.wasm +0 -0
  31. package/node_modules/@fedimint/fedimint-client-wasm/package.json +23 -0
  32. package/package.json +12 -5
  33. package/src/FedimintWallet.test.ts +74 -0
  34. package/src/FedimintWallet.ts +88 -342
  35. package/src/services/BalanceService.ts +24 -0
  36. package/src/services/FederationService.ts +32 -0
  37. package/src/services/LightningService.ts +128 -0
  38. package/src/services/MintService.ts +93 -0
  39. package/src/services/RecoveryService.ts +26 -0
  40. package/src/services/index.ts +5 -0
  41. package/src/types/wallet.ts +25 -2
  42. package/src/worker/WorkerClient.ts +190 -0
  43. package/src/worker/index.ts +1 -0
  44. package/src/worker/worker.js +85 -0
  45. package/dist/assets/fedimint_client_wasm_bg-DxOUItb-.wasm +0 -0
  46. package/dist/wasm.worker.d.ts +0 -1
  47. package/dist/wasm.worker.d.ts.map +0 -1
  48. package/src/vite-env.d.ts +0 -1
  49. package/src/wasm.worker.ts +0 -41
  50. package/wasm/fedimint_client_wasm.d.ts +0 -104
  51. package/wasm/fedimint_client_wasm.js +0 -1120
  52. package/wasm/fedimint_client_wasm_bg.js +0 -873
  53. package/wasm/fedimint_client_wasm_bg.wasm.d.ts +0 -34
@@ -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"}
@@ -4,7 +4,7 @@ type JSONValue = string | number | boolean | null | {
4
4
  [key: string]: JSONValue;
5
5
  } | JSONValue[];
6
6
  type JSONObject = Record<string, JSONValue>;
7
- type LightningGateway = {
7
+ type GatewayInfo = {
8
8
  gateway_id: string;
9
9
  api: string;
10
10
  node_pub_key: string;
@@ -12,6 +12,14 @@ type LightningGateway = {
12
12
  route_hints: RouteHint[];
13
13
  fees: FeeToAmount;
14
14
  };
15
+ type LightningGateway = {
16
+ info: GatewayInfo;
17
+ vetted: boolean;
18
+ ttl: {
19
+ nanos: number;
20
+ secs: number;
21
+ };
22
+ };
15
23
  type RouteHint = {};
16
24
  type FeeToAmount = {};
17
25
  type OutgoingLightningPayment = {
@@ -61,11 +69,19 @@ type CreateBolt11Response = {
61
69
  type StreamError = {
62
70
  error: string;
63
71
  data: never;
72
+ end: never;
64
73
  };
65
74
  type StreamSuccess<T extends JSONValue> = {
66
75
  data: T;
67
76
  error: never;
77
+ end: never;
78
+ };
79
+ type StreamEnd = {
80
+ end: string;
81
+ data: never;
82
+ error: never;
68
83
  };
69
- type StreamResult<T extends JSONValue> = StreamSuccess<T> | StreamError;
70
- export { JSONValue, JSONObject, LightningGateway, RouteHint, FeeToAmount, OutgoingLightningPayment, PayType, LnPayState, LnReceiveState, CreateBolt11Response, StreamError, StreamSuccess, StreamResult, ModuleKind, };
84
+ type StreamResult<T extends JSONValue> = StreamSuccess<T> | StreamError | StreamEnd;
85
+ type CancelFunction = () => void;
86
+ export { JSONValue, JSONObject, LightningGateway, RouteHint, FeeToAmount, OutgoingLightningPayment, PayType, LnPayState, LnReceiveState, CreateBolt11Response, GatewayInfo, StreamError, StreamSuccess, StreamResult, ModuleKind, CancelFunction, };
71
87
  //# sourceMappingURL=wallet.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../../src/types/wallet.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,YAAY,6BAA8B,CAAA;AAChD,KAAK,UAAU,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAA;AAC/C,KAAK,SAAS,GACV,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,GAC5B,SAAS,EAAE,CAAA;AAEf,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;AAE3C,KAAK,gBAAgB,GAAG;IACtB,UAAU,EAAE,MAAM,CAAA;IAClB,GAAG,EAAE,MAAM,CAAA;IACX,YAAY,EAAE,MAAM,CAAA;IACpB,gBAAgB,EAAE,MAAM,CAAA;IACxB,WAAW,EAAE,SAAS,EAAE,CAAA;IACxB,IAAI,EAAE,WAAW,CAAA;CA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GAAG,EAAE,KAAK,CAAA;CACX,CAAA;AAED,KAAK,SAAS,GAAG;IACf,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,EAAE,KAAK,CAAA;IACX,KAAK,EAAE,KAAK,CAAA;CACb,CAAA;AAED,KAAK,YAAY,CAAC,CAAC,SAAS,SAAS,IACjC,aAAa,CAAC,CAAC,CAAC,GAChB,WAAW,GACX,SAAS,CAAA;AAEb,KAAK,cAAc,GAAG,MAAM,IAAI,CAAA;AAEhC,OAAO,EACL,SAAS,EACT,UAAU,EACV,gBAAgB,EAChB,SAAS,EACT,WAAW,EACX,wBAAwB,EACxB,OAAO,EACP,UAAU,EACV,cAAc,EACd,oBAAoB,EACpB,WAAW,EACX,WAAW,EACX,aAAa,EACb,YAAY,EACZ,UAAU,EACV,cAAc,GACf,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 ADDED
@@ -0,0 +1,2 @@
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
+ //# sourceMappingURL=worker.js.map
@@ -0,0 +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\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,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,EAEjC,GADAiB,QAAQC,IAAI,eAAgBJ,EAAQC,EAAQC,IACvCxB,EAMH,YALAG,KAAKS,YAAY,CACfL,KAAM,QACNa,MAAO,6BACPX,cAIJ,MAAMkB,QAAkB3B,EAAO4B,IAC7BN,EACAC,EACAM,KAAKC,UAAUN,IACdO,IACCN,QAAQC,IAAI,eAAgBjB,EAAWsB,GACvC,MAAMrB,EAAOmB,KAAKG,MAAMD,GAGxB,GAFA5B,KAAKS,YAAY,CAAEL,KAAM,cAAeE,eAAcC,SAErCuB,IAAbvB,EAAKwB,IAAmB,CAE1B,MAAMC,EAASlC,EAAgBmC,IAAI3B,GACnC0B,GAAQE,MACT,KAGLpC,EAAgBqC,IAAI7B,EAAWkB,EACnC,MAAS,GAAa,gBAATpB,EAAwB,CACjC,MAAMoB,EAAY1B,EAAgBmC,IAAI3B,GAClCkB,IACFA,EAAUY,SACVZ,EAAUU,OACVpC,EAAgBuC,OAAO/B,GAE7B,MACIN,KAAKS,YAAY,CACfL,KAAM,QACNa,MAAO,uBACPX,aAEH,EAGHN,KAAKS,YAAY,CAAEL,KAAM,OAAQG,KAAM,CAAA"}
@@ -0,0 +1,49 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ */
5
+ export class RpcHandle {
6
+ free(): void
7
+ /**
8
+ */
9
+ cancel(): void
10
+ }
11
+ /**
12
+ */
13
+ export class WasmClient {
14
+ free(): void
15
+ /**
16
+ * Open fedimint client with already joined federation.
17
+ *
18
+ * After you have joined a federation, you can reopen the fedimint client
19
+ * with same client_name. Opening client with same name at same time is
20
+ * not supported. You can close the current client by calling
21
+ * `client.free()`. NOTE: The client will remain active until all the
22
+ * running rpc calls have finished.
23
+ * @param {string} client_name
24
+ * @returns {Promise<WasmClient | undefined>}
25
+ */
26
+ static open(client_name: string): Promise<WasmClient | undefined>
27
+ /**
28
+ * Open a fedimint client by join a federation.
29
+ * @param {string} client_name
30
+ * @param {string} invite_code
31
+ * @returns {Promise<WasmClient>}
32
+ */
33
+ static join_federation(
34
+ client_name: string,
35
+ invite_code: string,
36
+ ): Promise<WasmClient>
37
+ /**
38
+ * Call a fedimint client rpc the responses are returned using `cb`
39
+ * callback. Each rpc call *can* return multiple responses by calling
40
+ * `cb` multiple times. The returned RpcHandle can be used to cancel the
41
+ * operation.
42
+ * @param {string} module
43
+ * @param {string} method
44
+ * @param {string} payload
45
+ * @param {Function} cb
46
+ * @returns {RpcHandle}
47
+ */
48
+ rpc(module: string, method: string, payload: string, cb: Function): RpcHandle
49
+ }
@@ -0,0 +1,4 @@
1
+ import * as wasm from './fedimint_client_wasm_bg.wasm'
2
+ import { __wbg_set_wasm } from './fedimint_client_wasm_bg.js'
3
+ __wbg_set_wasm(wasm)
4
+ export * from './fedimint_client_wasm_bg.js'