@fedimint/core 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +18 -0
  3. package/dist/dts/FedimintWallet.d.ts +51 -0
  4. package/dist/dts/FedimintWallet.d.ts.map +1 -0
  5. package/dist/dts/WalletDirector.d.ts +79 -0
  6. package/dist/dts/WalletDirector.d.ts.map +1 -0
  7. package/dist/dts/index.d.ts +5 -0
  8. package/dist/dts/index.d.ts.map +1 -0
  9. package/dist/dts/services/BalanceService.d.ts +15 -0
  10. package/dist/dts/services/BalanceService.d.ts.map +1 -0
  11. package/dist/dts/services/FederationService.d.ts +13 -0
  12. package/dist/dts/services/FederationService.d.ts.map +1 -0
  13. package/dist/dts/services/LightningService.d.ts +48 -0
  14. package/dist/dts/services/LightningService.d.ts.map +1 -0
  15. package/dist/dts/services/MintService.d.ts +23 -0
  16. package/dist/dts/services/MintService.d.ts.map +1 -0
  17. package/dist/dts/services/RecoveryService.d.ts +13 -0
  18. package/dist/dts/services/RecoveryService.d.ts.map +1 -0
  19. package/dist/dts/services/WalletService.d.ts +13 -0
  20. package/dist/dts/services/WalletService.d.ts.map +1 -0
  21. package/dist/dts/services/index.d.ts +7 -0
  22. package/dist/dts/services/index.d.ts.map +1 -0
  23. package/dist/dts/transport/TransportClient.d.ts +55 -0
  24. package/dist/dts/transport/TransportClient.d.ts.map +1 -0
  25. package/dist/dts/transport/index.d.ts +2 -0
  26. package/dist/dts/transport/index.d.ts.map +1 -0
  27. package/dist/dts/types/index.d.ts +4 -0
  28. package/dist/dts/types/index.d.ts.map +1 -0
  29. package/dist/dts/types/transport.d.ts +2 -0
  30. package/dist/dts/types/transport.d.ts.map +1 -0
  31. package/dist/dts/types/utils.d.ts +21 -0
  32. package/dist/dts/types/utils.d.ts.map +1 -0
  33. package/dist/dts/types/wallet.d.ts +241 -0
  34. package/dist/dts/types/wallet.d.ts.map +1 -0
  35. package/dist/dts/utils/logger.d.ts +24 -0
  36. package/dist/dts/utils/logger.d.ts.map +1 -0
  37. package/dist/index.d.ts +578 -0
  38. package/dist/index.js +2 -0
  39. package/dist/index.js.map +1 -0
  40. package/package.json +40 -0
  41. package/src/FedimintWallet.ts +119 -0
  42. package/src/WalletDirector.ts +119 -0
  43. package/src/index.ts +4 -0
  44. package/src/services/BalanceService.test.ts +26 -0
  45. package/src/services/BalanceService.ts +29 -0
  46. package/src/services/FederationService.test.ts +58 -0
  47. package/src/services/FederationService.ts +216 -0
  48. package/src/services/LightningService.test.ts +265 -0
  49. package/src/services/LightningService.ts +289 -0
  50. package/src/services/MintService.test.ts +74 -0
  51. package/src/services/MintService.ts +129 -0
  52. package/src/services/RecoveryService.ts +28 -0
  53. package/src/services/WalletService.test.ts +59 -0
  54. package/src/services/WalletService.ts +50 -0
  55. package/src/services/index.ts +6 -0
  56. package/src/transport/TransportClient.ts +254 -0
  57. package/src/transport/index.ts +1 -0
  58. package/src/types/index.ts +3 -0
  59. package/src/types/transport.ts +1 -0
  60. package/src/types/utils.ts +23 -0
  61. package/src/types/wallet.ts +298 -0
  62. package/src/utils/logger.ts +69 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 fedimint
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,18 @@
1
+ # @fedimint/core
2
+
3
+ ### This is early software. Use with caution. Report Bugs.
4
+
5
+ Check out the [Getting Started Guide](https://web.fedimint.org/core/getting-started.html) for more information.
6
+
7
+ > Note: `@fedimint/core` now expects a platform-specific transport implementation. For browser usage install `@fedimint/transport-web` and provide a `WasmWorkerTransport` instance when constructing a `WalletDirector`.
8
+
9
+ ---
10
+
11
+ Also check out the examples for working code
12
+
13
+ - [Vite + React](https://web.fedimint.org/examples/vite-react)
14
+ - [Bare JS](https://web.fedimint.org/examples/bare-js)
15
+
16
+ ### Resources
17
+
18
+ - [Bitcoin Mints](https://bitcoinmints.com/?tab=mints&showFedimint=true) - list of public federations with invite codes
@@ -0,0 +1,51 @@
1
+ import { TransportClient } from './transport';
2
+ import { BalanceService, MintService, LightningService, FederationService, RecoveryService, WalletService } from './services';
3
+ export declare class FedimintWallet {
4
+ private _client;
5
+ balance: BalanceService;
6
+ mint: MintService;
7
+ lightning: LightningService;
8
+ federation: FederationService;
9
+ recovery: RecoveryService;
10
+ wallet: WalletService;
11
+ private _openPromise;
12
+ private _resolveOpen;
13
+ private _isOpen;
14
+ /**
15
+ * Creates a new instance of FedimintWallet.
16
+ *
17
+ * This constructor initializes a FedimintWallet instance, which manages communication
18
+ * with a Web Worker. The Web Worker is responsible for running WebAssembly code that
19
+ * handles the core Fedimint Client operations.
20
+ *
21
+ * (default) When not in lazy mode, the constructor immediately initializes the
22
+ * Web Worker and begins loading the WebAssembly module in the background. This
23
+ * allows for faster subsequent operations but may increase initial load time.
24
+ *
25
+ * In lazy mode, the Web Worker and WebAssembly initialization are deferred until
26
+ * the first operation that requires them, reducing initial overhead at the cost
27
+ * of a slight delay on the first operation.
28
+ *
29
+ * @example
30
+ * // Create a wallet with immediate initialization
31
+ * const wallet = new FedimintWallet();
32
+ * wallet.open();
33
+ *
34
+ * // Create a wallet with lazy initialization
35
+ * const lazyWallet = new FedimintWallet(true);
36
+ * // Some time later...
37
+ * lazyWallet.initialize();
38
+ * lazyWallet.open();
39
+ */
40
+ constructor(_client: TransportClient);
41
+ waitForOpen(): Promise<void>;
42
+ open(clientName?: string): Promise<boolean>;
43
+ joinFederation(inviteCode: string, clientName?: string): Promise<boolean>;
44
+ /**
45
+ * This should ONLY be called when UNLOADING the wallet client.
46
+ * After this call, the FedimintWallet instance should be discarded.
47
+ */
48
+ cleanup(): Promise<void>;
49
+ isOpen(): boolean;
50
+ }
51
+ //# sourceMappingURL=FedimintWallet.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FedimintWallet.d.ts","sourceRoot":"","sources":["../../src/FedimintWallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,EACL,cAAc,EACd,WAAW,EACX,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,EACf,aAAa,EACd,MAAM,YAAY,CAAA;AAInB,qBAAa,cAAc;IAsCb,OAAO,CAAC,OAAO;IArCpB,OAAO,EAAE,cAAc,CAAA;IACvB,IAAI,EAAE,WAAW,CAAA;IACjB,SAAS,EAAE,gBAAgB,CAAA;IAC3B,UAAU,EAAE,iBAAiB,CAAA;IAC7B,QAAQ,EAAE,eAAe,CAAA;IACzB,MAAM,EAAE,aAAa,CAAA;IAE5B,OAAO,CAAC,YAAY,CAAuC;IAC3D,OAAO,CAAC,YAAY,CAAuB;IAC3C,OAAO,CAAC,OAAO,CAAiB;IAEhC;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;gBACiB,OAAO,EAAE,eAAe;IAYtC,WAAW;IAKX,IAAI,CAAC,UAAU,GAAE,MAA4B;IAa7C,cAAc,CAClB,UAAU,EAAE,MAAM,EAClB,UAAU,GAAE,MAA4B;IAuB1C;;;OAGG;IACG,OAAO;IAMb,MAAM;CAGP"}
@@ -0,0 +1,79 @@
1
+ import { TransportClient } from './transport';
2
+ import { type LogLevel } from './utils/logger';
3
+ import { FederationConfig, JSONValue } from './types';
4
+ import { Transport } from '@fedimint/types';
5
+ import { FedimintWallet } from './FedimintWallet';
6
+ export declare class WalletDirector {
7
+ protected _client: TransportClient;
8
+ /**
9
+ * Creates a new instance of WalletDirector.
10
+ *
11
+ * @param {Transport} [transport] - Optional worker client instance. Provide your
12
+ * own to use a custom transport (e.g. React Native).
13
+ *
14
+ * @param {boolean} lazy - If true, delays Web Worker and WebAssembly initialization
15
+ * until needed. Default is false.
16
+ */
17
+ constructor(transport: Transport, lazy?: boolean);
18
+ initialize(): Promise<void>;
19
+ createWallet(): Promise<FedimintWallet>;
20
+ previewFederation(inviteCode: string): Promise<{
21
+ config: FederationConfig;
22
+ federation_id: string;
23
+ }>;
24
+ /**
25
+ * Sets the log level for the library.
26
+ * @param level The desired log level ('DEBUG', 'INFO', 'WARN', 'ERROR', 'NONE').
27
+ */
28
+ setLogLevel(level: LogLevel): void;
29
+ /**
30
+ * Parses a federation invite code and retrieves its details.
31
+ *
32
+ * This method sends the provided invite code to the TransportClient for parsing.
33
+ * The response includes the federation_id and url.
34
+ *
35
+ * @param {string} inviteCode - The invite code to be parsed.
36
+ * @returns {Promise<{ federation_id: string, url: string}>}
37
+ * A promise that resolves to an object containing:
38
+ * - `federation_id`: The id of the feder.
39
+ * - `url`: One of the apipoints to connect to the federation
40
+ *
41
+ * @throws {Error} If the TransportClient encounters an issue during the parsing process.
42
+ *
43
+ * @example
44
+ * const inviteCode = "example-invite-code";
45
+ * const parsedCode = await wallet.parseInviteCode(inviteCode);
46
+ * console.log(parsedCode.federation_id, parsedCode.url);
47
+ */
48
+ parseInviteCode(inviteCode: string): Promise<{
49
+ type: string;
50
+ data: JSONValue;
51
+ requestId: number;
52
+ }>;
53
+ /**
54
+ * Parses a BOLT11 Lightning invoice and retrieves its details.
55
+ *
56
+ * This method sends the provided invoice string to the TransportClient for parsing.
57
+ * The response includes details such as the amount, expiry, and memo.
58
+ *
59
+ * @param {string} invoiceStr - The BOLT11 invoice string to be parsed.
60
+ * @returns {Promise<{ amount: string, expiry: number, memo: string }>}
61
+ * A promise that resolves to an object containing:
62
+ * - `amount`: The amount specified in the invoice.
63
+ * - `expiry`: The expiry time of the invoice in seconds.
64
+ * - `memo`: A description or memo attached to the invoice.
65
+ *
66
+ * @throws {Error} If the TransportClient encounters an issue during the parsing process.
67
+ *
68
+ * @example
69
+ * const invoiceStr = "lnbc1...";
70
+ * const parsedInvoice = await wallet.parseBolt11Invoice(invoiceStr);
71
+ * console.log(parsedInvoice.amount, parsedInvoice.expiry, parsedInvoice.memo);
72
+ */
73
+ parseBolt11Invoice(invoiceStr: string): Promise<{
74
+ type: string;
75
+ data: JSONValue;
76
+ requestId: number;
77
+ }>;
78
+ }
79
+ //# sourceMappingURL=WalletDirector.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WalletDirector.d.ts","sourceRoot":"","sources":["../../src/WalletDirector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAEjD,qBAAa,cAAc;IAEzB,SAAS,CAAC,OAAO,EAAE,eAAe,CAAA;IAElC;;;;;;;;OAQG;gBACS,SAAS,EAAE,SAAS,EAAE,IAAI,GAAE,OAAe;IAWjD,UAAU;IAOV,YAAY;IAKZ,iBAAiB,CAAC,UAAU,EAAE,MAAM;gBAG9B,gBAAgB;uBACT,MAAM;;IAKzB;;;OAGG;IACH,WAAW,CAAC,KAAK,EAAE,QAAQ;IAK3B;;;;;;;;;;;;;;;;;;OAkBG;IACG,eAAe,CAAC,UAAU,EAAE,MAAM;cAG9B,MAAM;cACN,SAAS;mBACJ,MAAM;;IAKrB;;;;;;;;;;;;;;;;;;;OAmBG;IACG,kBAAkB,CAAC,UAAU,EAAE,MAAM;cAGjC,MAAM;cACN,SAAS;mBACJ,MAAM;;CAItB"}
@@ -0,0 +1,5 @@
1
+ export { WalletDirector } from './WalletDirector';
2
+ export { TransportClient } from './transport';
3
+ export type { FedimintWallet } from './FedimintWallet';
4
+ export type * from './types';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC7C,YAAY,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACtD,mBAAmB,SAAS,CAAA"}
@@ -0,0 +1,15 @@
1
+ import { TransportClient } from '../transport';
2
+ /**
3
+ * Balance Service
4
+ *
5
+ * The Balance Service provides methods to interact with the balance of a Fedimint wallet.
6
+ */
7
+ export declare class BalanceService {
8
+ private client;
9
+ constructor(client: TransportClient);
10
+ /** https://web.fedimint.org/core/FedimintWallet/BalanceService/getBalance */
11
+ getBalance(): Promise<number>;
12
+ /** https://web.fedimint.org/core/FedimintWallet/BalanceService/subscribeBalance */
13
+ subscribeBalance(onSuccess?: (balanceMsats: number) => void, onError?: (error: string) => void): import("..").CancelFunction;
14
+ }
15
+ //# 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,eAAe,EAAE,MAAM,cAAc,CAAA;AAE9C;;;;GAIG;AACH,qBAAa,cAAc;IACb,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,eAAe;IAE3C,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"}
@@ -0,0 +1,13 @@
1
+ import type { OperationKey, OperationLog, Transactions } from '../types';
2
+ import { TransportClient } from '../transport';
3
+ export declare class FederationService {
4
+ private client;
5
+ constructor(client: TransportClient);
6
+ getConfig(): Promise<import("@fedimint/types").JSONValue>;
7
+ getFederationId(): Promise<string>;
8
+ getInviteCode(peer?: number): Promise<string | null>;
9
+ listOperations(limit?: number, last_seen?: OperationKey): Promise<[OperationKey, OperationLog][]>;
10
+ getOperation(operationId: string): Promise<OperationLog | null>;
11
+ listTransactions(limit?: number, last_seen?: OperationKey): Promise<Transactions[]>;
12
+ }
13
+ //# 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,KAAK,EAKV,YAAY,EACZ,YAAY,EACZ,YAAY,EAGb,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAE9C,qBAAa,iBAAiB;IAChB,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,eAAe;IAErC,SAAS;IAIT,eAAe;IAIf,aAAa,CAAC,IAAI,GAAE,MAAU;IAM9B,cAAc,CAClB,KAAK,CAAC,EAAE,MAAM,EACd,SAAS,CAAC,EAAE,YAAY,GACvB,OAAO,CAAC,CAAC,YAAY,EAAE,YAAY,CAAC,EAAE,CAAC;IAWpC,YAAY,CAAC,WAAW,EAAE,MAAM;IAQhC,gBAAgB,CACpB,KAAK,CAAC,EAAE,MAAM,EACd,SAAS,CAAC,EAAE,YAAY,GACvB,OAAO,CAAC,YAAY,EAAE,CAAC;CAgK3B"}
@@ -0,0 +1,48 @@
1
+ import { TransportClient } from '../transport';
2
+ import type { CreateBolt11Response, GatewayInfo, JSONObject, LightningGateway, LnInternalPayState, LnPayState, LnReceiveState, OutgoingLightningPayment } from '../types';
3
+ export declare class LightningService {
4
+ private client;
5
+ constructor(client: TransportClient);
6
+ /** https://web.fedimint.org/core/FedimintWallet/LightningService/createInvoice#lightning-createinvoice */
7
+ createInvoice(amountMsats: number, description: string, expiryTime?: number, // in seconds
8
+ gatewayInfo?: GatewayInfo, extraMeta?: JSONObject): Promise<CreateBolt11Response>;
9
+ createInvoiceTweaked(amountMsats: number, description: string, tweakKey: string, index: number, expiryTime?: number, // in seconds
10
+ gatewayInfo?: GatewayInfo, extraMeta?: JSONObject): Promise<CreateBolt11Response>;
11
+ scanReceivesForTweaks(tweakKey: string, indices: number[], extraMeta?: JSONObject): Promise<string[]>;
12
+ private _getDefaultGatewayInfo;
13
+ /** https://web.fedimint.org/core/FedimintWallet/LightningService/payInvoice#lightning-payinvoice-invoice-string */
14
+ payInvoice(invoice: string, gatewayInfo?: GatewayInfo, extraMeta?: JSONObject): Promise<OutgoingLightningPayment>;
15
+ /** https://web.fedimint.org/core/FedimintWallet/LightningService/payInvoice#lightning-payinvoicesync-invoice-string */
16
+ payInvoiceSync(invoice: string, timeoutMs?: number, gatewayInfo?: GatewayInfo, extraMeta?: JSONObject): Promise<{
17
+ success: false;
18
+ error?: string;
19
+ } | {
20
+ success: true;
21
+ data: {
22
+ feeMsats: number;
23
+ preimage: string;
24
+ };
25
+ }>;
26
+ subscribeInternalPayment(operation_id: string, onSuccess?: (state: LnInternalPayState) => void, onError?: (error: string) => void): import("../types").CancelFunction;
27
+ subscribeLnClaim(operationId: string, onSuccess?: (state: LnReceiveState) => void, onError?: (error: string) => void): import("../types").CancelFunction;
28
+ /** https://web.fedimint.org/core/FedimintWallet/LightningService/payInvoice#lightning-payinvoice-invoice-string */
29
+ subscribeLnPay(operationId: string, onSuccess?: (state: LnPayState) => void, onError?: (error: string) => void): import("../types").CancelFunction;
30
+ /** https://web.fedimint.org/core/FedimintWallet/LightningService/payInvoice#lightning-payinvoice-invoice-string */
31
+ waitForPay(operationId: string): Promise<{
32
+ success: false;
33
+ error?: string;
34
+ } | {
35
+ success: true;
36
+ data: {
37
+ preimage: string;
38
+ };
39
+ }>;
40
+ /** https://web.fedimint.org/core/FedimintWallet/LightningService/createInvoice#lightning-createinvoice */
41
+ subscribeLnReceive(operationId: string, onSuccess?: (state: LnReceiveState) => void, onError?: (error: string) => void): import("../types").CancelFunction;
42
+ /** https://web.fedimint.org/core/FedimintWallet/LightningService/createInvoice#lightning-createinvoice */
43
+ waitForReceive(operationId: string, timeoutMs?: number): Promise<LnReceiveState>;
44
+ getGateway(gatewayId?: string | null, forceInternal?: boolean): Promise<LightningGateway | null>;
45
+ listGateways(): Promise<LightningGateway[]>;
46
+ updateGatewayCache(): Promise<import("@fedimint/types").JSONValue>;
47
+ }
48
+ //# 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,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,KAAK,EACV,oBAAoB,EACpB,WAAW,EACX,UAAU,EACV,gBAAgB,EAChB,kBAAkB,EAClB,UAAU,EACV,cAAc,EACd,wBAAwB,EACzB,MAAM,UAAU,CAAA;AAEjB,qBAAa,gBAAgB;IACf,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,eAAe;IAE3C,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;;IA8BpD,wBAAwB,CACtB,YAAY,EAAE,MAAM,EACpB,SAAS,GAAE,CAAC,KAAK,EAAE,kBAAkB,KAAK,IAAe,EACzD,OAAO,GAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAe;IAY7C,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"}
@@ -0,0 +1,23 @@
1
+ import { TransportClient } from '../transport';
2
+ import type { Duration, JSONObject, JSONValue, NoteCountByDenomination, ReissueExternalNotesState, SpendNotesState } from '../types';
3
+ export declare class MintService {
4
+ private client;
5
+ constructor(client: TransportClient);
6
+ /** https://web.fedimint.org/core/FedimintWallet/MintService/redeemEcash */
7
+ redeemEcash(notes: string): Promise<string>;
8
+ reissueExternalNotes(oobNotes: string, extraMeta?: JSONObject): Promise<string>;
9
+ subscribeReissueExternalNotes(operationId: string, onSuccess?: (state: ReissueExternalNotesState) => void, onError?: (error: string) => void): import("../types").CancelFunction;
10
+ /** https://web.fedimint.org/core/FedimintWallet/MintService/spendNotes */
11
+ spendNotes(amountMsats: number, tryCancelAfter?: number | Duration, // defaults to 1 day
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>;
18
+ tryCancelSpendNotes(operationId: string): Promise<void>;
19
+ subscribeSpendNotes(operationId: string, onSuccess?: (state: SpendNotesState) => void, onError?: (error: string) => void): import("../types").CancelFunction;
20
+ awaitSpendOobRefund(operationId: string): Promise<JSONValue>;
21
+ getNotesByDenomination(): Promise<NoteCountByDenomination>;
22
+ }
23
+ //# 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,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,KAAK,EACV,QAAQ,EACR,UAAU,EACV,SAAS,EAGT,uBAAuB,EACvB,yBAAyB,EACzB,eAAe,EAChB,MAAM,UAAU,CAAA;AAEjB,qBAAa,WAAW;IACV,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,eAAe;IAE3C,2EAA2E;IACrE,WAAW,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;IAMvC,sBAAsB;CAO7B"}
@@ -0,0 +1,13 @@
1
+ import type { JSONValue } from '../types';
2
+ import { TransportClient } from '../transport';
3
+ export declare class RecoveryService {
4
+ private client;
5
+ constructor(client: TransportClient);
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): import("../types").CancelFunction;
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,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAE9C,qBAAa,eAAe;IACd,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,eAAe;IAErC,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"}
@@ -0,0 +1,13 @@
1
+ import { JSONValue, WalletSummary, GenerateAddressResponse, WalletDepositState } from '../types';
2
+ import { TransportClient } from '../transport';
3
+ export declare class WalletService {
4
+ private client;
5
+ constructor(client: TransportClient);
6
+ getWalletSummary(): Promise<WalletSummary>;
7
+ generateAddress(extraMeta?: JSONValue): Promise<GenerateAddressResponse>;
8
+ sendOnchain(amountSat: number, address: string, extraMeta?: JSONValue): Promise<{
9
+ operation_id: string;
10
+ }>;
11
+ subscribeDeposit(operation_id: string, onSuccess?: (state: WalletDepositState) => void, onError?: (error: string) => void): import("../types").CancelFunction;
12
+ }
13
+ //# sourceMappingURL=WalletService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WalletService.d.ts","sourceRoot":"","sources":["../../../src/services/WalletService.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,aAAa,EACb,uBAAuB,EACvB,kBAAkB,EACnB,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAE9C,qBAAa,aAAa;IACZ,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,eAAe;IAErC,gBAAgB,IAAI,OAAO,CAAC,aAAa,CAAC;IAI1C,eAAe,CAAC,SAAS,GAAE,SAAc;IAUzC,WAAW,CACf,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,SAAS,GAAE,SAAc,GACxB,OAAO,CAAC;QAAE,YAAY,EAAE,MAAM,CAAA;KAAE,CAAC;IAOpC,gBAAgB,CACd,YAAY,EAAE,MAAM,EACpB,SAAS,GAAE,CAAC,KAAK,EAAE,kBAAkB,KAAK,IAAe,EACzD,OAAO,GAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAe;CAU9C"}
@@ -0,0 +1,7 @@
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
+ export { WalletService } from './WalletService';
7
+ //# 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;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA"}
@@ -0,0 +1,55 @@
1
+ import type { CancelFunction, JSONValue, ModuleKind, StreamError } from '../types';
2
+ import { Logger } from '../utils/logger';
3
+ import type { Transport, TransportMessageType } from '@fedimint/types';
4
+ /**
5
+ * Handles communication with a generic transport.
6
+ * Must be instantiated with a platform-specific transport. (wasm for web, react native, etc.)
7
+ */
8
+ export declare class TransportClient {
9
+ private readonly transport;
10
+ private requestCounter;
11
+ private requestCallbacks;
12
+ private initPromise;
13
+ logger: Logger;
14
+ /**
15
+ * @summary Constructor for the TransportClient
16
+ * @param transport - The platform-specific transport to use. (wasm for web, react native, etc.)
17
+ */
18
+ constructor(transport: Transport);
19
+ initialize(): Promise<boolean>;
20
+ private handleLogMessage;
21
+ private handleTransportError;
22
+ private handleTransportMessage;
23
+ sendSingleMessage<Response extends JSONValue = JSONValue, Payload extends JSONValue = JSONValue>(type: TransportMessageType, payload?: Payload): Promise<Response>;
24
+ /**
25
+ * @summary Initiates an RPC stream with the specified module and method.
26
+ *
27
+ * @description
28
+ * This function sets up an RPC stream by sending a request to a worker and
29
+ * handling responses asynchronously. It ensures that unsubscription is handled
30
+ * correctly, even if the unsubscribe function is called before the subscription
31
+ * is fully established, by deferring the unsubscription attempt using `setTimeout`.
32
+ *
33
+ * The function operates in a non-blocking manner, leveraging Promises to manage
34
+ * asynchronous operations and callbacks to handle responses.
35
+ *
36
+ *
37
+ * @template Response - The expected type of the successful response.
38
+ * @template Body - The type of the request body.
39
+ * @param module - The module kind to interact with.
40
+ * @param method - The method name to invoke on the module.
41
+ * @param body - The request payload.
42
+ * @param onSuccess - Callback invoked with the response data on success.
43
+ * @param onError - Callback invoked with error information if an error occurs.
44
+ * @param onEnd - Optional callback invoked when the stream ends.
45
+ * @returns A function that can be called to cancel the subscription.
46
+ *
47
+ */
48
+ 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;
49
+ private _rpcStreamInner;
50
+ rpcSingle<Response extends JSONValue = JSONValue, Error extends string = string>(module: ModuleKind, method: string, body: JSONValue): Promise<Response>;
51
+ cleanup(): Promise<void>;
52
+ _getRequestCounter(): number;
53
+ _getRequestCallbackMap(): Map<number, (value: any) => void>;
54
+ }
55
+ //# sourceMappingURL=TransportClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TransportClient.d.ts","sourceRoot":"","sources":["../../../src/transport/TransportClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,SAAS,EACT,UAAU,EACV,WAAW,EAEZ,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxC,OAAO,KAAK,EACV,SAAS,EAET,oBAAoB,EACrB,MAAM,iBAAiB,CAAA;AAExB;;;GAGG;AACH,qBAAa,eAAe;IAE1B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAW;IACrC,OAAO,CAAC,cAAc,CAAI;IAC1B,OAAO,CAAC,gBAAgB,CAA0C;IAClE,OAAO,CAAC,WAAW,CAA0C;IAC7D,MAAM,EAAE,MAAM,CAAA;IAEd;;;OAGG;gBACS,SAAS,EAAE,SAAS;IAUhC,UAAU;IAMV,OAAO,CAAC,gBAAgB;IAKxB,OAAO,CAAC,oBAAoB,CAE3B;IAED,OAAO,CAAC,sBAAsB,CAkB7B;IAMD,iBAAiB,CACf,QAAQ,SAAS,SAAS,GAAG,SAAS,EACtC,OAAO,SAAS,SAAS,GAAG,SAAS,EACrC,IAAI,EAAE,oBAAoB,EAAE,OAAO,CAAC,EAAE,OAAO;IAgC/C;;;;;;;;;;;;;;;;;;;;;;;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;YA0CH,eAAe;IAuC7B,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,wBApO6B,GAAG,KAAK,IAAI;CAuOhE"}
@@ -0,0 +1,2 @@
1
+ export { TransportClient } from './TransportClient';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/transport/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA"}
@@ -0,0 +1,4 @@
1
+ export * from './wallet';
2
+ export * from './utils';
3
+ export * from './transport';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,aAAa,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from '@fedimint/types';
2
+ //# sourceMappingURL=transport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../../src/types/transport.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA"}
@@ -0,0 +1,21 @@
1
+ import type { JSONValue } from '@fedimint/types';
2
+ type Alias<T> = T & {};
3
+ type Resolve<T> = T & unknown;
4
+ type Seconds = Alias<number>;
5
+ type Nanos = Alias<number>;
6
+ type Duration = {
7
+ nanos: Nanos;
8
+ secs: Seconds;
9
+ };
10
+ type MSats = Alias<number>;
11
+ type Sats = Alias<number>;
12
+ type JSONObject = Record<string, JSONValue>;
13
+ type Result<T, U = string> = {
14
+ success: true;
15
+ data?: T;
16
+ } | {
17
+ success: false;
18
+ error: U;
19
+ };
20
+ export { Alias, Resolve, Duration, MSats, Sats, JSONValue, JSONObject, Result };
21
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/types/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAEhD,KAAK,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAA;AACtB,KAAK,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAA;AAE7B,KAAK,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,CAAA;AAC5B,KAAK,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,CAAA;AAE1B,KAAK,QAAQ,GAAG;IACd,KAAK,EAAE,KAAK,CAAA;IACZ,IAAI,EAAE,OAAO,CAAA;CACd,CAAA;AAED,KAAK,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,CAAA;AAC1B,KAAK,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC,CAAA;AAEzB,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"}