@fedimint/core-web 0.0.10 → 0.0.11

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 (37) hide show
  1. package/dist/dts/FedimintWallet.d.ts +50 -0
  2. package/dist/dts/FedimintWallet.d.ts.map +1 -1
  3. package/dist/dts/services/BalanceService.d.ts +2 -21
  4. package/dist/dts/services/BalanceService.d.ts.map +1 -1
  5. package/dist/dts/services/FederationService.d.ts +1 -1
  6. package/dist/dts/services/FederationService.d.ts.map +1 -1
  7. package/dist/dts/services/LightningService.d.ts +11 -2
  8. package/dist/dts/services/LightningService.d.ts.map +1 -1
  9. package/dist/dts/services/MintService.d.ts +12 -6
  10. package/dist/dts/services/MintService.d.ts.map +1 -1
  11. package/dist/dts/services/RecoveryService.d.ts +1 -1
  12. package/dist/dts/services/RecoveryService.d.ts.map +1 -1
  13. package/dist/dts/types/utils.d.ts +8 -1
  14. package/dist/dts/types/utils.d.ts.map +1 -1
  15. package/dist/dts/types/wallet.d.ts +4 -10
  16. package/dist/dts/types/wallet.d.ts.map +1 -1
  17. package/dist/dts/types/worker.d.ts +1 -1
  18. package/dist/dts/types/worker.d.ts.map +1 -1
  19. package/dist/dts/worker/WorkerClient.d.ts +1 -1
  20. package/dist/dts/worker/WorkerClient.d.ts.map +1 -1
  21. package/dist/index.d.ts +87 -40
  22. package/dist/index.js +1 -1
  23. package/dist/index.js.map +1 -1
  24. package/dist/worker.js +1 -1
  25. package/dist/worker.js.map +1 -1
  26. package/package.json +8 -8
  27. package/src/FedimintWallet.ts +58 -0
  28. package/src/services/BalanceService.ts +5 -26
  29. package/src/services/FederationService.ts +9 -7
  30. package/src/services/LightningService.ts +81 -65
  31. package/src/services/MintService.ts +32 -25
  32. package/src/services/RecoveryService.ts +9 -7
  33. package/src/types/utils.ts +5 -1
  34. package/src/types/wallet.ts +12 -9
  35. package/src/types/worker.ts +2 -0
  36. package/src/worker/WorkerClient.ts +8 -9
  37. package/src/worker/worker.js +34 -0
@@ -1,5 +1,6 @@
1
1
  import { BalanceService, MintService, LightningService, FederationService, RecoveryService } from './services';
2
2
  import { type LogLevel } from './utils/logger';
3
+ import { JSONValue } from './types';
3
4
  export declare class FedimintWallet {
4
5
  private _client;
5
6
  balance: BalanceService;
@@ -55,5 +56,54 @@ export declare class FedimintWallet {
55
56
  * @param level The desired log level ('DEBUG', 'INFO', 'WARN', 'ERROR', 'NONE').
56
57
  */
57
58
  setLogLevel(level: LogLevel): void;
59
+ /**
60
+ * Parses a federation invite code and retrieves its details.
61
+ *
62
+ * This method sends the provided invite code to the WorkerClient for parsing.
63
+ * The response includes the federation_id and url.
64
+ *
65
+ * @param {string} inviteCode - The invite code to be parsed.
66
+ * @returns {Promise<{ federation_id: string, url: string}>}
67
+ * A promise that resolves to an object containing:
68
+ * - `federation_id`: The id of the feder.
69
+ * - `url`: One of the apipoints to connect to the federation
70
+ *
71
+ * @throws {Error} If the WorkerClient encounters an issue during the parsing process.
72
+ *
73
+ * @example
74
+ * const inviteCode = "example-invite-code";
75
+ * const parsedCode = await wallet.parseInviteCode(inviteCode);
76
+ * console.log(parsedCode.federation_id, parsedCode.url);
77
+ */
78
+ parseInviteCode(inviteCode: string): Promise<{
79
+ type: string;
80
+ data: JSONValue;
81
+ requestId: number;
82
+ }>;
83
+ /**
84
+ * Parses a BOLT11 Lightning invoice and retrieves its details.
85
+ *
86
+ * This method sends the provided invoice string to the WorkerClient for parsing.
87
+ * The response includes details such as the amount, expiry, and memo.
88
+ *
89
+ * @param {string} invoiceStr - The BOLT11 invoice string to be parsed.
90
+ * @returns {Promise<{ amount: string, expiry: number, memo: string }>}
91
+ * A promise that resolves to an object containing:
92
+ * - `amount`: The amount specified in the invoice.
93
+ * - `expiry`: The expiry time of the invoice in seconds.
94
+ * - `memo`: A description or memo attached to the invoice.
95
+ *
96
+ * @throws {Error} If the WorkerClient encounters an issue during the parsing process.
97
+ *
98
+ * @example
99
+ * const invoiceStr = "lnbc1...";
100
+ * const parsedInvoice = await wallet.parseBolt11Invoice(invoiceStr);
101
+ * console.log(parsedInvoice.amount, parsedInvoice.expiry, parsedInvoice.memo);
102
+ */
103
+ parseBolt11Invoice(invoiceStr: string): Promise<{
104
+ type: string;
105
+ data: JSONValue;
106
+ requestId: number;
107
+ }>;
58
108
  }
59
109
  //# sourceMappingURL=FedimintWallet.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"FedimintWallet.d.ts","sourceRoot":"","sources":["../../src/FedimintWallet.ts"],"names":[],"mappings":"AACA,OAAO,EACL,cAAc,EACd,WAAW,EACX,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,EAChB,MAAM,YAAY,CAAA;AACnB,OAAO,EAAU,KAAK,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAItD,qBAAa,cAAc;IACzB,OAAO,CAAC,OAAO,CAAc;IAEtB,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,YAAY,CAAuC;IAC3D,OAAO,CAAC,YAAY,CAAuB;IAC3C,OAAO,CAAC,OAAO,CAAiB;IAEhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;gBACS,IAAI,GAAE,OAAe;IAkB3B,UAAU;IAMV,WAAW;IAKX,IAAI,CAAC,UAAU,GAAE,MAA4B;IAc7C,cAAc,CAClB,UAAU,EAAE,MAAM,EAClB,UAAU,GAAE,MAA4B;IAwB1C;;;OAGG;IACG,OAAO;IAMb,MAAM;IAIN;;;OAGG;IACH,WAAW,CAAC,KAAK,EAAE,QAAQ;CAI5B"}
1
+ {"version":3,"file":"FedimintWallet.d.ts","sourceRoot":"","sources":["../../src/FedimintWallet.ts"],"names":[],"mappings":"AACA,OAAO,EACL,cAAc,EACd,WAAW,EACX,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,EAChB,MAAM,YAAY,CAAA;AACnB,OAAO,EAAU,KAAK,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAInC,qBAAa,cAAc;IACzB,OAAO,CAAC,OAAO,CAAc;IAEtB,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,YAAY,CAAuC;IAC3D,OAAO,CAAC,YAAY,CAAuB;IAC3C,OAAO,CAAC,OAAO,CAAiB;IAEhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;gBACS,IAAI,GAAE,OAAe;IAkB3B,UAAU;IAMV,WAAW;IAKX,IAAI,CAAC,UAAU,GAAE,MAA4B;IAc7C,cAAc,CAClB,UAAU,EAAE,MAAM,EAClB,UAAU,GAAE,MAA4B;IAwB1C;;;OAGG;IACG,OAAO;IAMb,MAAM;IAIN;;;OAGG;IACH,WAAW,CAAC,KAAK,EAAE,QAAQ;IAK3B;;;;;;;;;;;;;;;;;;OAkBG;IACG,eAAe,CAAC,UAAU,EAAE,MAAM;cAE9B,MAAM;cACN,SAAS;mBACJ,MAAM;;IAKrB;;;;;;;;;;;;;;;;;;;OAmBG;IACG,kBAAkB,CAAC,UAAU,EAAE,MAAM;cAEjC,MAAM;cACN,SAAS;mBACJ,MAAM;;CAItB"}
@@ -7,28 +7,9 @@ import { WorkerClient } from '../worker';
7
7
  export declare class BalanceService {
8
8
  private client;
9
9
  constructor(client: WorkerClient);
10
- /**
11
- * Get the balance of the current wallet in milli-satoshis (MSats)
12
- *
13
- * @example
14
- * ```ts
15
- * const balance = await wallet.balance.getBalance()
16
- * ```
17
- */
10
+ /** https://web.fedimint.org/core/FedimintWallet/BalanceService/getBalance */
18
11
  getBalance(): Promise<number>;
19
- /**
20
- * Subscribe to the balance of the current wallet in milli-satoshis (MSats)
21
- *
22
- * @example
23
- * ```ts
24
- * const unsubscribe = wallet.balance.subscribeBalance((balance) => {
25
- * console.log(balance)
26
- * })
27
- *
28
- * // ...Cleanup Later
29
- * unsubscribe()
30
- * ```
31
- */
12
+ /** https://web.fedimint.org/core/FedimintWallet/BalanceService/subscribeBalance */
32
13
  subscribeBalance(onSuccess?: (balanceMsats: number) => void, onError?: (error: string) => void): import("..").CancelFunction;
33
14
  }
34
15
  //# sourceMappingURL=BalanceService.d.ts.map
@@ -1 +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;;;;GAIG;AACH,qBAAa,cAAc;IACb,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,YAAY;IAExC;;;;;;;OAOG;IACG,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;IAInC;;;;;;;;;;;;OAYG;IACH,gBAAgB,CACd,SAAS,GAAE,CAAC,YAAY,EAAE,MAAM,KAAK,IAAe,EACpD,OAAO,GAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAe;CAY9C"}
1
+ {"version":3,"file":"BalanceService.d.ts","sourceRoot":"","sources":["../../../src/services/BalanceService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAExC;;;;GAIG;AACH,qBAAa,cAAc;IACb,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,YAAY;IAExC,6EAA6E;IACvE,UAAU;IAIhB,mFAAmF;IACnF,gBAAgB,CACd,SAAS,GAAE,CAAC,YAAY,EAAE,MAAM,KAAK,IAAe,EACpD,OAAO,GAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAe;CAU9C"}
@@ -5,7 +5,7 @@ export declare class FederationService {
5
5
  constructor(client: WorkerClient);
6
6
  getConfig(): Promise<JSONValue>;
7
7
  getFederationId(): Promise<string>;
8
- getInviteCode(peer: number): Promise<string | null>;
8
+ getInviteCode(peer?: number): Promise<string | null>;
9
9
  listOperations(): Promise<JSONValue[]>;
10
10
  }
11
11
  //# sourceMappingURL=FederationService.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"FederationService.d.ts","sourceRoot":"","sources":["../../../src/services/FederationService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AACzC,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,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;CAG7C"}
1
+ {"version":3,"file":"FederationService.d.ts","sourceRoot":"","sources":["../../../src/services/FederationService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAExC,qBAAa,iBAAiB;IAChB,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,YAAY;IAElC,SAAS;IAIT,eAAe;IAIf,aAAa,CAAC,IAAI,GAAE,MAAU;IAM9B,cAAc;CAGrB"}
@@ -1,17 +1,21 @@
1
1
  import { WorkerClient } from '../worker';
2
- import type { CreateBolt11Response, GatewayInfo, JSONObject, JSONValue, LightningGateway, LnPayState, LnReceiveState, OutgoingLightningPayment } from '../types';
2
+ import type { CreateBolt11Response, GatewayInfo, JSONObject, LightningGateway, LnPayState, LnReceiveState, OutgoingLightningPayment } from '../types';
3
3
  export declare class LightningService {
4
4
  private client;
5
5
  constructor(client: WorkerClient);
6
+ /** https://web.fedimint.org/core/FedimintWallet/LightningService/createInvoice#lightning-createinvoice */
6
7
  createInvoice(amountMsats: number, description: string, expiryTime?: number, // in seconds
7
8
  gatewayInfo?: GatewayInfo, extraMeta?: JSONObject): Promise<CreateBolt11Response>;
8
9
  createInvoiceTweaked(amountMsats: number, description: string, tweakKey: string, index: number, expiryTime?: number, // in seconds
9
10
  gatewayInfo?: GatewayInfo, extraMeta?: JSONObject): Promise<CreateBolt11Response>;
10
11
  scanReceivesForTweaks(tweakKey: string, indices: number[], extraMeta?: JSONObject): Promise<string[]>;
11
12
  private _getDefaultGatewayInfo;
13
+ /** https://web.fedimint.org/core/FedimintWallet/LightningService/payInvoice#lightning-payinvoice-invoice-string */
12
14
  payInvoice(invoice: string, gatewayInfo?: GatewayInfo, extraMeta?: JSONObject): Promise<OutgoingLightningPayment>;
15
+ /** https://web.fedimint.org/core/FedimintWallet/LightningService/payInvoice#lightning-payinvoicesync-invoice-string */
13
16
  payInvoiceSync(invoice: string, timeoutMs?: number, gatewayInfo?: GatewayInfo, extraMeta?: JSONObject): Promise<{
14
17
  success: false;
18
+ error?: string;
15
19
  } | {
16
20
  success: true;
17
21
  data: {
@@ -20,19 +24,24 @@ export declare class LightningService {
20
24
  };
21
25
  }>;
22
26
  subscribeLnClaim(operationId: string, onSuccess?: (state: LnReceiveState) => void, onError?: (error: string) => void): import("../types").CancelFunction;
27
+ /** https://web.fedimint.org/core/FedimintWallet/LightningService/payInvoice#lightning-payinvoice-invoice-string */
23
28
  subscribeLnPay(operationId: string, onSuccess?: (state: LnPayState) => void, onError?: (error: string) => void): import("../types").CancelFunction;
29
+ /** https://web.fedimint.org/core/FedimintWallet/LightningService/payInvoice#lightning-payinvoice-invoice-string */
24
30
  waitForPay(operationId: string): Promise<{
25
31
  success: false;
32
+ error?: string;
26
33
  } | {
27
34
  success: true;
28
35
  data: {
29
36
  preimage: string;
30
37
  };
31
38
  }>;
39
+ /** https://web.fedimint.org/core/FedimintWallet/LightningService/createInvoice#lightning-createinvoice */
32
40
  subscribeLnReceive(operationId: string, onSuccess?: (state: LnReceiveState) => void, onError?: (error: string) => void): import("../types").CancelFunction;
41
+ /** https://web.fedimint.org/core/FedimintWallet/LightningService/createInvoice#lightning-createinvoice */
33
42
  waitForReceive(operationId: string, timeoutMs?: number): Promise<LnReceiveState>;
34
43
  getGateway(gatewayId?: string | null, forceInternal?: boolean): Promise<LightningGateway | null>;
35
44
  listGateways(): Promise<LightningGateway[]>;
36
- updateGatewayCache(): Promise<JSONValue>;
45
+ updateGatewayCache(): Promise<import("../types").JSONValue>;
37
46
  }
38
47
  //# sourceMappingURL=LightningService.d.ts.map
@@ -1 +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,KAAK,EACV,oBAAoB,EACpB,WAAW,EACX,UAAU,EACV,SAAS,EACT,gBAAgB,EAChB,UAAU,EACV,cAAc,EACd,wBAAwB,EACzB,MAAM,UAAU,CAAA;AAEjB,qBAAa,gBAAgB;IACf,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,YAAY;IAElC,aAAa,CACjB,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,EACnB,UAAU,CAAC,EAAE,MAAM,EAAE,aAAa;IAClC,WAAW,CAAC,EAAE,WAAW,EACzB,SAAS,CAAC,EAAE,UAAU,GACrB,OAAO,CAAC,oBAAoB,CAAC;IAW1B,oBAAoB,CACxB,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,UAAU,CAAC,EAAE,MAAM,EAAE,aAAa;IAClC,WAAW,CAAC,EAAE,WAAW,EACzB,SAAS,CAAC,EAAE,UAAU,GACrB,OAAO,CAAC,oBAAoB,CAAC;IAk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avC,cAAc,CAClB,WAAW,EAAE,MAAM,EACnB,SAAS,GAAE,MAAc,GACxB,OAAO,CAAC,cAAc,CAAC;IAyBpB,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"}
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,KAAK,EACV,oBAAoB,EACpB,WAAW,EACX,UAAU,EACV,gBAAgB,EAChB,UAAU,EACV,cAAc,EACd,wBAAwB,EACzB,MAAM,UAAU,CAAA;AAEjB,qBAAa,gBAAgB;IACf,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,YAAY;IAExC,0GAA0G;IACpG,aAAa,CACjB,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,EACnB,UAAU,CAAC,EAAE,MAAM,EAAE,aAAa;IAClC,WAAW,CAAC,EAAE,WAAW,EACzB,SAAS,CAAC,EAAE,UAAU;IAgBlB,oBAAoB,CACxB,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,UAAU,CAAC,EAAE,MAAM,EAAE,aAAa;IAClC,WAAW,CAAC,EAAE,WAAW,EACzB,SAAS,CAAC,EAAE,UAAU;IAmBlB,qBAAqB,CACzB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EAAE,EACjB,SAAS,CAAC,EAAE,UAAU;YAaV,sBAAsB;IAMpC,mHAAmH;IAC7G,UAAU,CACd,OAAO,EAAE,MAAM,EACf,WAAW,CAAC,EAAE,WAAW,EACzB,SAAS,CAAC,EAAE,UAAU;IAcxB,uHAAuH;IACjH,cAAc,CAClB,OAAO,EAAE,MAAM,EACf,SAAS,GAAE,MAAc,EACzB,WAAW,CAAC,EAAE,WAAW,EACzB,SAAS,CAAC,EAAE,UAAU;iBAGP,KAAK;gBAAU,MAAM;;iBAErB,IAAI;cACP;YAAE,QAAQ,EAAE,MAAM,CAAC;YAAC,QAAQ,EAAE,MAAM,CAAA;SAAE;;IA+BpD,gBAAgB,CACd,WAAW,EAAE,MAAM,EACnB,SAAS,GAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAe,EACrD,OAAO,GAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAe;IAa7C,mHAAmH;IACnH,cAAc,CACZ,WAAW,EAAE,MAAM,EACnB,SAAS,GAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAe,EACjD,OAAO,GAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAe;IAW7C,mHAAmH;IAC7G,UAAU,CAAC,WAAW,EAAE,MAAM;iBAEnB,KAAK;gBAAU,MAAM;;iBACrB,IAAI;cAAQ;YAAE,QAAQ,EAAE,MAAM,CAAA;SAAE;;IA4BjD,0GAA0G;IAC1G,kBAAkB,CAChB,WAAW,EAAE,MAAM,EACnB,SAAS,GAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAe,EACrD,OAAO,GAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAe;IAW7C,0GAA0G;IACpG,cAAc,CAAC,WAAW,EAAE,MAAM,EAAE,SAAS,GAAE,MAAc;IAyB7D,UAAU,CACd,SAAS,GAAE,MAAM,GAAG,IAAW,EAC/B,aAAa,GAAE,OAAe;IAY1B,YAAY;IAQZ,kBAAkB;CAGzB"}
@@ -1,16 +1,22 @@
1
1
  import { WorkerClient } from '../worker';
2
- import type { Duration, JSONObject, JSONValue, MintSpendNotesResponse, MSats } from '../types';
2
+ import type { Duration, JSONObject, JSONValue, ReissueExternalNotesState, SpendNotesState } from '../types';
3
3
  export declare class MintService {
4
4
  private client;
5
5
  constructor(client: WorkerClient);
6
- redeemEcash(notes: string): Promise<void>;
6
+ /** https://web.fedimint.org/core/FedimintWallet/MintService/redeemEcash */
7
+ redeemEcash(notes: string): Promise<string>;
7
8
  reissueExternalNotes(oobNotes: string, extraMeta?: JSONObject): Promise<string>;
8
- subscribeReissueExternalNotes(operationId: string, onSuccess?: (state: JSONValue) => void, onError?: (error: string) => void): import("../types").CancelFunction;
9
+ subscribeReissueExternalNotes(operationId: string, onSuccess?: (state: ReissueExternalNotesState) => void, onError?: (error: string) => void): import("../types").CancelFunction;
10
+ /** https://web.fedimint.org/core/FedimintWallet/MintService/spendNotes */
9
11
  spendNotes(amountMsats: number, tryCancelAfter?: number | Duration, // defaults to 1 day
10
- includeInvite?: boolean, extraMeta?: JSONValue): Promise<MintSpendNotesResponse>;
11
- parseNotes(oobNotes: string): Promise<MSats>;
12
+ includeInvite?: boolean, extraMeta?: JSONValue): Promise<{
13
+ notes: string;
14
+ operation_id: string;
15
+ }>;
16
+ /** https://web.fedimint.org/core/FedimintWallet/MintService/parseEcash */
17
+ parseNotes(oobNotes: string): Promise<number>;
12
18
  tryCancelSpendNotes(operationId: string): Promise<void>;
13
- subscribeSpendNotes(operationId: string, onSuccess?: (state: JSONValue) => void, onError?: (error: string) => void): import("../types").CancelFunction;
19
+ subscribeSpendNotes(operationId: string, onSuccess?: (state: SpendNotesState) => void, onError?: (error: string) => void): import("../types").CancelFunction;
14
20
  awaitSpendOobRefund(operationId: string): Promise<JSONValue>;
15
21
  }
16
22
  //# sourceMappingURL=MintService.d.ts.map
@@ -1 +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,KAAK,EACV,QAAQ,EACR,UAAU,EACV,SAAS,EACT,sBAAsB,EACtB,KAAK,EAEN,MAAM,UAAU,CA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AAW,CAAC,KAAK,EAAE,MAAM;IAWzB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,GAAE,UAAe;IAWvE,6BAA6B,CAC3B,WAAW,EAAE,MAAM,EACnB,SAAS,GAAE,CAAC,KAAK,EAAE,yBAAyB,KAAK,IAAe,EAChE,OAAO,GAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAe;IAa7C,0EAA0E;IACpE,UAAU,CACd,WAAW,EAAE,MAAM,EAInB,cAAc,GAAE,MAAM,GAAG,QAAoB,EAAE,oBAAoB;IACnE,aAAa,GAAE,OAAe,EAC9B,SAAS,GAAE,SAAc;;;;IA0B3B,0EAA0E;IACpE,UAAU,CAAC,QAAQ,EAAE,MAAM;IAM3B,mBAAmB,CAAC,WAAW,EAAE,MAAM;IAM7C,mBAAmB,CACjB,WAAW,EAAE,MAAM,EACnB,SAAS,GAAE,CAAC,KAAK,EAAE,eAAe,KAAK,IAAe,EACtD,OAAO,GAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAe;IAWvC,mBAAmB,CAAC,WAAW,EAAE,MAAM;CAK9C"}
@@ -8,6 +8,6 @@ export declare class RecoveryService {
8
8
  subscribeToRecoveryProgress(onSuccess: (progress: {
9
9
  module_id: number;
10
10
  progress: JSONValue;
11
- }) => void, onError: (error: string) => void): () => void;
11
+ }) => void, onError: (error: string) => void): import("../types").CancelFunction;
12
12
  }
13
13
  //# sourceMappingURL=RecoveryService.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"RecoveryService.d.ts","sourceRoot":"","sources":["../../../src/services/RecoveryService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AACzC,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"}
1
+ {"version":3,"file":"RecoveryService.d.ts","sourceRoot":"","sources":["../../../src/services/RecoveryService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAExC,qBAAa,eAAe;IACd,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,YAAY;IAElC,oBAAoB;IAQpB,oBAAoB;IAI1B,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;CAOnC"}
@@ -12,5 +12,12 @@ type JSONValue = string | number | boolean | null | {
12
12
  [key: string]: JSONValue;
13
13
  } | JSONValue[];
14
14
  type JSONObject = Record<string, JSONValue>;
15
- export { Alias, Resolve, Duration, MSats, Sats, JSONValue, JSONObject };
15
+ type Result<T, U = string> = {
16
+ success: true;
17
+ data?: T;
18
+ } | {
19
+ success: false;
20
+ error: U;
21
+ };
22
+ export { Alias, Resolve, Duration, MSats, Sats, JSONValue, JSONObject, Result };
16
23
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/types/utils.ts"],"names":[],"mappings":"AAAA,KAAK,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAA;AACtB,KAAK,OAAO,CAAC,CAAC,IAAI,CAA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,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,MAAM,CAAC,CAAC,EAAE,CAAC,GAAG,MAAM,IACrB;IAAE,OAAO,EAAE,IAAI,CAAC;IAAC,IAAI,CAAC,EAAE,CAAC,CAAA;CAAE,GAC3B;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAE,CAAA;AAEhC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,EAAE,CAAA"}
@@ -78,14 +78,8 @@ type StreamEnd = {
78
78
  };
79
79
  type StreamResult<T extends JSONValue> = StreamSuccess<T> | StreamError | StreamEnd;
80
80
  type CancelFunction = () => void;
81
- type ReissueExternalNotesState = 'Created' | 'Issuing' | 'Done' | {
82
- Failed: {
83
- error: string;
84
- };
85
- };
86
- type MintSpendNotesResponse = {
87
- notes: string;
88
- operation_id: string;
89
- };
90
- export { LightningGateway, RouteHint, FeeToAmount, OutgoingLightningPayment, PayType, LnPayState, LnReceiveState, CreateBolt11Response, GatewayInfo, StreamError, StreamSuccess, StreamResult, ModuleKind, CancelFunction, ReissueExternalNotesState, MintSpendNotesResponse, };
81
+ type ReissueExternalNotesState = 'Created' | 'Issuing' | 'Done';
82
+ type MintSpendNotesResponse = Array<string>;
83
+ type SpendNotesState = 'Created' | 'UserCanceledProcessing' | 'UserCanceledSuccess' | 'UserCanceledFailure' | 'Success' | 'Refunded';
84
+ export { LightningGateway, RouteHint, FeeToAmount, OutgoingLightningPayment, PayType, LnPayState, LnReceiveState, CreateBolt11Response, GatewayInfo, StreamError, StreamSuccess, StreamResult, ModuleKind, CancelFunction, ReissueExternalNotesState, MintSpendNotesResponse, SpendNotesState, };
91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,GAAG,MAAM,IAAI,CAAA;AAEhC,KAAK,yBAAyB,GAAG,SAAS,GAAG,SAAS,GAAG,MAAM,CAAA;AAG/D,KAAK,sBAAsB,GAAG,KAAK,CAAC,MAAM,CAAC,CAAA;AAE3C,KAAK,eAAe,GAChB,SAAS,GACT,wBAAwB,GACxB,qBAAqB,GACrB,qBAAqB,GACrB,SAAS,GACT,UAAU,CAAA;AAEd,OAAO,EACL,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,EACd,yBAAyB,EACzB,sBAAsB,EACtB,eAAe,GAChB,CAAA"}
@@ -1,4 +1,4 @@
1
- declare const WorkerMessageTypes: readonly ["init", "initialized", "rpc", "log", "open", "join", "error", "unsubscribe", "cleanup"];
1
+ declare const WorkerMessageTypes: readonly ["init", "initialized", "rpc", "log", "open", "join", "error", "unsubscribe", "cleanup", "parseInviteCode", "parseBolt11Invoice"];
2
2
  export type WorkerMessageType = (typeof WorkerMessageTypes)[number];
3
3
  export {};
4
4
  //# sourceMappingURL=worker.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../../../src/types/worker.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,kBAAkB,mGAUd,CAAA;AAEV,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAA"}
1
+ {"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../../../src/types/worker.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,kBAAkB,4IAYd,CAAA;AAEV,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAA"}
@@ -36,7 +36,7 @@ export declare class WorkerClient {
36
36
  */
37
37
  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;
38
38
  private _rpcStreamInner;
39
- rpcSingle<Response extends JSONValue = JSONValue>(module: ModuleKind, method: string, body: JSONValue): Promise<Response>;
39
+ rpcSingle<Response extends JSONValue = JSONValue, Error extends string = string>(module: ModuleKind, method: string, body: JSONValue): Promise<Response>;
40
40
  cleanup(): Promise<void>;
41
41
  _getRequestCounter(): number;
42
42
  _getRequestCallbackMap(): Map<number, (value: any) => void>;
@@ -1 +1 @@
1
- {"version":3,"file":"WorkerClient.d.ts","sourceRoot":"","sources":["../../../src/worker/WorkerClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,SAAS,EACT,UAAU,EACV,WAAW,EAEX,iBAAiB,EAClB,MAAM,UAAU,CAAA;AAKjB,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAQ;IACtB,OAAO,CAAC,cAAc,CAAI;IAC1B,OAAO,CAAC,gBAAgB,CAA0C;IAClE,OAAO,CAAC,WAAW,CAA0C;;IAc7D,UAAU;IAMV,OAAO,CAAC,gBAAgB;IAKxB,OAAO,CAAC,iBAAiB;IAIzB,OAAO,CAAC,mBAAmB;IAuB3B,iBAAiB,CACf,QAAQ,SAAS,SAAS,GAAG,SAAS,EACtC,OAAO,SAAS,SAAS,GAAG,SAAS,EACrC,IAAI,EAAE,iBAAiB,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC;IA2BhE;;;;;;;;;;;;;;;;;;;;;;;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,E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C,OAAO,CAAC,KAAK,IAAI,EAC5C,KAAK,GAAE,MAAM,IAAe,GAC3B,cAAc;YAoCH,eAAe;IA2C7B,SAAS,CACP,QAAQ,SAAS,SAAS,GAAG,SAAS,EACtC,KAAK,SAAS,MAAM,GAAG,MAAM,EAC7B,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS;IAO/C,OAAO;IAQb,kBAAkB;IAGlB,sBAAsB,wBAzN6B,GAAG,KAAK,IAAI;CA4NhE"}
package/dist/index.d.ts CHANGED
@@ -12,6 +12,13 @@ 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
24
  declare const MODULE_KINDS: readonly ["", "ln", "mint"];
@@ -93,18 +100,12 @@ type StreamEnd = {
93
100
  };
94
101
  type StreamResult<T extends JSONValue> = StreamSuccess<T> | StreamError | StreamEnd;
95
102
  type CancelFunction = () => void;
96
- type ReissueExternalNotesState = 'Created' | 'Issuing' | 'Done' | {
97
- Failed: {
98
- error: string;
99
- };
100
- };
101
- type MintSpendNotesResponse = {
102
- notes: string;
103
- operation_id: string;
104
- };
103
+ type ReissueExternalNotesState = 'Created' | 'Issuing' | 'Done';
104
+ type MintSpendNotesResponse = Array<string>;
105
+ type SpendNotesState = 'Created' | 'UserCanceledProcessing' | 'UserCanceledSuccess' | 'UserCanceledFailure' | 'Success' | 'Refunded';
105
106
  //# sourceMappingURL=wallet.d.ts.map
106
107
 
107
- declare const WorkerMessageTypes: readonly ["init", "initialized", "rpc", "log", "open", "join", "error", "unsubscribe", "cleanup"];
108
+ declare const WorkerMessageTypes: readonly ["init", "initialized", "rpc", "log", "open", "join", "error", "unsubscribe", "cleanup", "parseInviteCode", "parseBolt11Invoice"];
108
109
  type WorkerMessageType = (typeof WorkerMessageTypes)[number];
109
110
 
110
111
  declare class WorkerClient {
@@ -144,7 +145,7 @@ declare class WorkerClient {
144
145
  */
145
146
  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
147
  private _rpcStreamInner;
147
- rpcSingle<Response extends JSONValue = JSONValue>(module: ModuleKind, method: string, body: JSONValue): Promise<Response>;
148
+ rpcSingle<Response extends JSONValue = JSONValue, Error extends string = string>(module: ModuleKind, method: string, body: JSONValue): Promise<Response>;
148
149
  cleanup(): Promise<void>;
149
150
  _getRequestCounter(): number;
150
151
  _getRequestCallbackMap(): Map<number, (value: any) => void>;
@@ -153,14 +154,20 @@ declare class WorkerClient {
153
154
  declare class MintService {
154
155
  private client;
155
156
  constructor(client: WorkerClient);
156
- redeemEcash(notes: string): Promise<void>;
157
+ /** https://web.fedimint.org/core/FedimintWallet/MintService/redeemEcash */
158
+ redeemEcash(notes: string): Promise<string>;
157
159
  reissueExternalNotes(oobNotes: string, extraMeta?: JSONObject): Promise<string>;
158
- subscribeReissueExternalNotes(operationId: string, onSuccess?: (state: JSONValue) => void, onError?: (error: string) => void): CancelFunction;
160
+ subscribeReissueExternalNotes(operationId: string, onSuccess?: (state: ReissueExternalNotesState) => void, onError?: (error: string) => void): CancelFunction;
161
+ /** https://web.fedimint.org/core/FedimintWallet/MintService/spendNotes */
159
162
  spendNotes(amountMsats: number, tryCancelAfter?: number | Duration, // defaults to 1 day
160
- includeInvite?: boolean, extraMeta?: JSONValue): Promise<MintSpendNotesResponse>;
161
- parseNotes(oobNotes: string): Promise<MSats>;
163
+ includeInvite?: boolean, extraMeta?: JSONValue): Promise<{
164
+ notes: string;
165
+ operation_id: string;
166
+ }>;
167
+ /** https://web.fedimint.org/core/FedimintWallet/MintService/parseEcash */
168
+ parseNotes(oobNotes: string): Promise<number>;
162
169
  tryCancelSpendNotes(operationId: string): Promise<void>;
163
- subscribeSpendNotes(operationId: string, onSuccess?: (state: JSONValue) => void, onError?: (error: string) => void): CancelFunction;
170
+ subscribeSpendNotes(operationId: string, onSuccess?: (state: SpendNotesState) => void, onError?: (error: string) => void): CancelFunction;
164
171
  awaitSpendOobRefund(operationId: string): Promise<JSONValue>;
165
172
  }
166
173
 
@@ -172,43 +179,28 @@ declare class MintService {
172
179
  declare class BalanceService {
173
180
  private client;
174
181
  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
- */
182
+ /** https://web.fedimint.org/core/FedimintWallet/BalanceService/getBalance */
183
183
  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
- */
184
+ /** https://web.fedimint.org/core/FedimintWallet/BalanceService/subscribeBalance */
197
185
  subscribeBalance(onSuccess?: (balanceMsats: number) => void, onError?: (error: string) => void): CancelFunction;
198
186
  }
199
187
 
200
188
  declare class LightningService {
201
189
  private client;
202
190
  constructor(client: WorkerClient);
191
+ /** https://web.fedimint.org/core/FedimintWallet/LightningService/createInvoice#lightning-createinvoice */
203
192
  createInvoice(amountMsats: number, description: string, expiryTime?: number, // in seconds
204
193
  gatewayInfo?: GatewayInfo, extraMeta?: JSONObject): Promise<CreateBolt11Response>;
205
194
  createInvoiceTweaked(amountMsats: number, description: string, tweakKey: string, index: number, expiryTime?: number, // in seconds
206
195
  gatewayInfo?: GatewayInfo, extraMeta?: JSONObject): Promise<CreateBolt11Response>;
207
196
  scanReceivesForTweaks(tweakKey: string, indices: number[], extraMeta?: JSONObject): Promise<string[]>;
208
197
  private _getDefaultGatewayInfo;
198
+ /** https://web.fedimint.org/core/FedimintWallet/LightningService/payInvoice#lightning-payinvoice-invoice-string */
209
199
  payInvoice(invoice: string, gatewayInfo?: GatewayInfo, extraMeta?: JSONObject): Promise<OutgoingLightningPayment>;
200
+ /** https://web.fedimint.org/core/FedimintWallet/LightningService/payInvoice#lightning-payinvoicesync-invoice-string */
210
201
  payInvoiceSync(invoice: string, timeoutMs?: number, gatewayInfo?: GatewayInfo, extraMeta?: JSONObject): Promise<{
211
202
  success: false;
203
+ error?: string;
212
204
  } | {
213
205
  success: true;
214
206
  data: {
@@ -217,16 +209,21 @@ declare class LightningService {
217
209
  };
218
210
  }>;
219
211
  subscribeLnClaim(operationId: string, onSuccess?: (state: LnReceiveState) => void, onError?: (error: string) => void): CancelFunction;
212
+ /** https://web.fedimint.org/core/FedimintWallet/LightningService/payInvoice#lightning-payinvoice-invoice-string */
220
213
  subscribeLnPay(operationId: string, onSuccess?: (state: LnPayState) => void, onError?: (error: string) => void): CancelFunction;
214
+ /** https://web.fedimint.org/core/FedimintWallet/LightningService/payInvoice#lightning-payinvoice-invoice-string */
221
215
  waitForPay(operationId: string): Promise<{
222
216
  success: false;
217
+ error?: string;
223
218
  } | {
224
219
  success: true;
225
220
  data: {
226
221
  preimage: string;
227
222
  };
228
223
  }>;
224
+ /** https://web.fedimint.org/core/FedimintWallet/LightningService/createInvoice#lightning-createinvoice */
229
225
  subscribeLnReceive(operationId: string, onSuccess?: (state: LnReceiveState) => void, onError?: (error: string) => void): CancelFunction;
226
+ /** https://web.fedimint.org/core/FedimintWallet/LightningService/createInvoice#lightning-createinvoice */
230
227
  waitForReceive(operationId: string, timeoutMs?: number): Promise<LnReceiveState>;
231
228
  getGateway(gatewayId?: string | null, forceInternal?: boolean): Promise<LightningGateway | null>;
232
229
  listGateways(): Promise<LightningGateway[]>;
@@ -241,7 +238,7 @@ declare class RecoveryService {
241
238
  subscribeToRecoveryProgress(onSuccess: (progress: {
242
239
  module_id: number;
243
240
  progress: JSONValue;
244
- }) => void, onError: (error: string) => void): () => void;
241
+ }) => void, onError: (error: string) => void): CancelFunction;
245
242
  }
246
243
 
247
244
  declare class FederationService {
@@ -249,7 +246,7 @@ declare class FederationService {
249
246
  constructor(client: WorkerClient);
250
247
  getConfig(): Promise<JSONValue>;
251
248
  getFederationId(): Promise<string>;
252
- getInviteCode(peer: number): Promise<string | null>;
249
+ getInviteCode(peer?: number): Promise<string | null>;
253
250
  listOperations(): Promise<JSONValue[]>;
254
251
  }
255
252
 
@@ -311,6 +308,56 @@ declare class FedimintWallet {
311
308
  * @param level The desired log level ('DEBUG', 'INFO', 'WARN', 'ERROR', 'NONE').
312
309
  */
313
310
  setLogLevel(level: LogLevel): void;
311
+ /**
312
+ * Parses a federation invite code and retrieves its details.
313
+ *
314
+ * This method sends the provided invite code to the WorkerClient for parsing.
315
+ * The response includes the federation_id and url.
316
+ *
317
+ * @param {string} inviteCode - The invite code to be parsed.
318
+ * @returns {Promise<{ federation_id: string, url: string}>}
319
+ * A promise that resolves to an object containing:
320
+ * - `federation_id`: The id of the feder.
321
+ * - `url`: One of the apipoints to connect to the federation
322
+ *
323
+ * @throws {Error} If the WorkerClient encounters an issue during the parsing process.
324
+ *
325
+ * @example
326
+ * const inviteCode = "example-invite-code";
327
+ * const parsedCode = await wallet.parseInviteCode(inviteCode);
328
+ * console.log(parsedCode.federation_id, parsedCode.url);
329
+ */
330
+ parseInviteCode(inviteCode: string): Promise<{
331
+ type: string;
332
+ data: JSONValue;
333
+ requestId: number;
334
+ }>;
335
+ /**
336
+ * Parses a BOLT11 Lightning invoice and retrieves its details.
337
+ *
338
+ * This method sends the provided invoice string to the WorkerClient for parsing.
339
+ * The response includes details such as the amount, expiry, and memo.
340
+ *
341
+ * @param {string} invoiceStr - The BOLT11 invoice string to be parsed.
342
+ * @returns {Promise<{ amount: string, expiry: number, memo: string }>}
343
+ * A promise that resolves to an object containing:
344
+ * - `amount`: The amount specified in the invoice.
345
+ * - `expiry`: The expiry time of the invoice in seconds.
346
+ * - `memo`: A description or memo attached to the invoice.
347
+ *
348
+ * @throws {Error} If the WorkerClient encounters an issue during the parsing process.
349
+ *
350
+ * @example
351
+ * const invoiceStr = "lnbc1...";
352
+ * const parsedInvoice = await wallet.parseBolt11Invoice(invoiceStr);
353
+ * console.log(parsedInvoice.amount, parsedInvoice.expiry, parsedInvoice.memo);
354
+ */
355
+ parseBolt11Invoice(invoiceStr: string): Promise<{
356
+ type: string;
357
+ data: JSONValue;
358
+ requestId: number;
359
+ }>;
314
360
  }
315
361
 
316
- export { type Alias, type CancelFunction, type CreateBolt11Response, type Duration, FedimintWallet, type FeeToAmount, type GatewayInfo, type JSONObject, type JSONValue, type LightningGateway, type LnPayState, type LnReceiveState, type MSats, type MintSpendNotesResponse, type ModuleKind, type OutgoingLightningPayment, type PayType, type ReissueExternalNotesState, type Resolve, type RouteHint, type Sats, type StreamError, type StreamResult, type StreamSuccess, type WorkerMessageType };
362
+ export { FedimintWallet };
363
+ export type { Alias, CancelFunction, CreateBolt11Response, Duration, FeeToAmount, GatewayInfo, JSONObject, JSONValue, LightningGateway, LnPayState, LnReceiveState, MSats, MintSpendNotesResponse, ModuleKind, OutgoingLightningPayment, PayType, ReissueExternalNotesState, Resolve, Result, RouteHint, Sats, SpendNotesState, StreamError, StreamResult, StreamSuccess, 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",{min_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})}}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}}))})),l=setTimeout((()=>{c(),r(new Error("Timeout waiting for pay"))}),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((()=>{i(new Error("Timeout waiting for receive"))}),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){return await this.client.rpcSingle("","get_invite_code",{peer:e})}async listOperations(){return await this.client.rpcSingle("","list_operations",{})}}const c="fm-default";class l{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),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=c){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=c){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}setLogLevel(e){t.setLevel(e),t.info(`Log level set to ${e}.`)}}export{l as FedimintWallet};
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 s=this.coerceLevel(e);if(!this.shouldLog(s))return;(0,console[s])(`[${s.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:s,message:n,...r}=e.data;t.log(s,n,...r)}handleWorkerError(e){t.error("Worker error",e)}handleWorkerMessage(e){const{type:i,requestId:s,...n}=e.data;"log"===i&&this.handleWorkerLogs(e.data);const r=this.requestCallbacks.get(s);t.debug("WorkerClient - handleWorkerMessage",e.data),r?r(n):t.warn("WorkerClient - handleWorkerMessage - received message with no callback",s,e.data)}sendSingleMessage(e,i){return new Promise(((s,n)=>{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?s(e.data):e.error?n(e.error):t.warn("WorkerClient - sendSingleMessage - malformed response",r,e)})),this.worker.postMessage({type:e,payload:i,requestId:r})}))}rpcStream(e,i,s,n,r,a=()=>{}){const o=++this.requestCounter;t.debug("WorkerClient - rpcStream",o,e,i,s);let c=()=>{},l=!1;const u=new Promise((e=>{c=()=>{l?e():setTimeout((()=>c()),0)}}));return this._rpcStreamInner(o,e,i,s,n,r,a,u).then((()=>{l=!0})),c}async _rpcStreamInner(e,t,i,s,n,r,a=()=>{},o){this.requestCallbacks.set(e,(t=>{void 0!==t.error?r(t.error):void 0!==t.data?n(t.data):void 0!==t.end&&(this.requestCallbacks.delete(e),a())})),this.worker.postMessage({type:"rpc",payload:{module:t,method:i,body:s},requestId:e}),o.then((()=>{this.worker?.postMessage({type:"unsubscribe",requestId:e}),this.requestCallbacks.delete(e)}))}rpcSingle(e,i,s){return t.debug("WorkerClient - rpcSingle",e,i,s),new Promise(((t,n)=>{this.rpcStream(e,i,s,t,n)}))}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 s{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,s={}){const n="number"==typeof t?{nanos:0,secs:t}:t,r=await this.client.rpcSingle("mint","spend_notes",{amount:e,try_cancel_after:n,include_invite:i,extra_meta:s});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})}}class n{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,s,n){const r=s??await this._getDefaultGatewayInfo();return await this.client.rpcSingle("ln","create_bolt11_invoice",{amount:e,description:t,expiry_time:i??null,extra_meta:n??{},gateway:r})}async createInvoiceTweaked(e,t,i,s,n,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:n??null,user_key:i,index:s,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 s=t??await this._getDefaultGatewayInfo();return await this.client.rpcSingle("ln","pay_bolt11_invoice",{maybe_gateway:s,invoice:e,extra_meta:i??{}})}async payInvoiceSync(e,t=1e4,i,s){return new Promise((async(n,r)=>{const{contract_id:a,fee:o}=await this.payInvoice(e,i,s),c=this.subscribeLnPay(a,(e=>{"string"!=typeof e&&"success"in e?(clearTimeout(l),c(),n({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(),n({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 s;const n=setTimeout((()=>{t({success:!1,error:"Waiting for receive timeout"})}),15e3);s=this.subscribeLnPay(e,(e=>{"string"!=typeof e&&"success"in e&&(clearTimeout(n),s(),t({success:!0,data:{preimage:e.success.preimage}}))}),(e=>{clearTimeout(n),s(),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,s)=>{let n;const r=setTimeout((()=>{s(new Error("Timeout waiting for receive"))}),t);n=this.subscribeLnReceive(e,(e=>{"claimed"===e&&(clearTimeout(r),n(),i(e))}),(e=>{clearTimeout(r),n(),s(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",{})}}const c="fm-default";class l{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 s(this._client),this.lightning=new r(this._client),this.balance=new n(this._client),this.federation=new o(this._client),this.recovery=new a(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=c){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=c){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}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{l as FedimintWallet};
2
2
  //# sourceMappingURL=index.js.map