@metamask-previews/wallet 0.0.0-preview-784cc181c → 0.0.0-preview-681bd3562

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 (74) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/Wallet.cjs +113 -0
  3. package/dist/Wallet.cjs.map +1 -0
  4. package/dist/Wallet.d.cts +40 -0
  5. package/dist/Wallet.d.cts.map +1 -0
  6. package/dist/Wallet.d.mts +40 -0
  7. package/dist/Wallet.d.mts.map +1 -0
  8. package/dist/Wallet.mjs +109 -0
  9. package/dist/Wallet.mjs.map +1 -0
  10. package/dist/index.cjs +3 -10
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.d.cts +3 -7
  13. package/dist/index.d.cts.map +1 -1
  14. package/dist/index.d.mts +3 -7
  15. package/dist/index.d.mts.map +1 -1
  16. package/dist/index.mjs +1 -9
  17. package/dist/index.mjs.map +1 -1
  18. package/dist/initialization/defaults.cjs +29 -0
  19. package/dist/initialization/defaults.cjs.map +1 -0
  20. package/dist/initialization/defaults.d.cts +30 -0
  21. package/dist/initialization/defaults.d.cts.map +1 -0
  22. package/dist/initialization/defaults.d.mts +30 -0
  23. package/dist/initialization/defaults.d.mts.map +1 -0
  24. package/dist/initialization/defaults.mjs +3 -0
  25. package/dist/initialization/defaults.mjs.map +1 -0
  26. package/dist/initialization/initialization.cjs +32 -0
  27. package/dist/initialization/initialization.cjs.map +1 -0
  28. package/dist/initialization/initialization.d.cts +15 -0
  29. package/dist/initialization/initialization.d.cts.map +1 -0
  30. package/dist/initialization/initialization.d.mts +15 -0
  31. package/dist/initialization/initialization.d.mts.map +1 -0
  32. package/dist/initialization/initialization.mjs +28 -0
  33. package/dist/initialization/initialization.mjs.map +1 -0
  34. package/dist/initialization/instances/index.cjs +6 -0
  35. package/dist/initialization/instances/index.cjs.map +1 -0
  36. package/dist/initialization/instances/index.d.cts +2 -0
  37. package/dist/initialization/instances/index.d.cts.map +1 -0
  38. package/dist/initialization/instances/index.d.mts +2 -0
  39. package/dist/initialization/instances/index.d.mts.map +1 -0
  40. package/dist/initialization/instances/index.mjs +2 -0
  41. package/dist/initialization/instances/index.mjs.map +1 -0
  42. package/dist/initialization/instances/keyring-controller.cjs +97 -0
  43. package/dist/initialization/instances/keyring-controller.cjs.map +1 -0
  44. package/dist/initialization/instances/keyring-controller.d.cts +21 -0
  45. package/dist/initialization/instances/keyring-controller.d.cts.map +1 -0
  46. package/dist/initialization/instances/keyring-controller.d.mts +21 -0
  47. package/dist/initialization/instances/keyring-controller.d.mts.map +1 -0
  48. package/dist/initialization/instances/keyring-controller.mjs +94 -0
  49. package/dist/initialization/instances/keyring-controller.mjs.map +1 -0
  50. package/dist/initialization/types.cjs +3 -0
  51. package/dist/initialization/types.cjs.map +1 -0
  52. package/dist/initialization/types.d.cts +35 -0
  53. package/dist/initialization/types.d.cts.map +1 -0
  54. package/dist/initialization/types.d.mts +35 -0
  55. package/dist/initialization/types.d.mts.map +1 -0
  56. package/dist/initialization/types.mjs +2 -0
  57. package/dist/initialization/types.mjs.map +1 -0
  58. package/dist/types.cjs +3 -0
  59. package/dist/types.cjs.map +1 -0
  60. package/dist/types.d.cts +18 -0
  61. package/dist/types.d.cts.map +1 -0
  62. package/dist/types.d.mts +18 -0
  63. package/dist/types.d.mts.map +1 -0
  64. package/dist/types.mjs +2 -0
  65. package/dist/types.mjs.map +1 -0
  66. package/dist/utilities.cjs +20 -0
  67. package/dist/utilities.cjs.map +1 -0
  68. package/dist/utilities.d.cts +10 -0
  69. package/dist/utilities.d.cts.map +1 -0
  70. package/dist/utilities.d.mts +10 -0
  71. package/dist/utilities.d.mts.map +1 -0
  72. package/dist/utilities.mjs +16 -0
  73. package/dist/utilities.mjs.map +1 -0
  74. package/package.json +9 -1
package/CHANGELOG.md CHANGED
@@ -7,4 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ### Added
11
+
12
+ - Initial release ([#8838](https://github.com/MetaMask/core/pull/8838))
13
+
10
14
  [Unreleased]: https://github.com/MetaMask/core/
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _Wallet_messenger, _Wallet_instances, _Wallet_controllerMetadata, _Wallet_isDestroyed;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.Wallet = void 0;
16
+ const messenger_1 = require("@metamask/messenger");
17
+ const utils_1 = require("@metamask/utils");
18
+ const initialization_1 = require("./initialization/initialization.cjs");
19
+ class Wallet {
20
+ /**
21
+ * Creates a `Wallet` instance, initializing all instances as specified by the passed options.
22
+ *
23
+ * @param options - Options bag.
24
+ * @param options.messenger - An optional messenger to override the default one.
25
+ * @param options.state - An optional state blob.
26
+ * @param options.initializationConfigurations - An optional list of additional initialization configurations
27
+ * required beyond the ones included by default.
28
+ * @param options.instanceOptions - An optional object containing options that should be passed
29
+ * to specific instances for additional customization.
30
+ */
31
+ constructor(options) {
32
+ // TODO: Expand default types when passing additionalConfigurations.
33
+ _Wallet_messenger.set(this, void 0);
34
+ _Wallet_instances.set(this, void 0);
35
+ _Wallet_controllerMetadata.set(this, void 0);
36
+ _Wallet_isDestroyed.set(this, false);
37
+ __classPrivateFieldSet(this, _Wallet_messenger, options.messenger ??
38
+ new messenger_1.Messenger({
39
+ namespace: 'Root',
40
+ }), "f");
41
+ __classPrivateFieldSet(this, _Wallet_instances, (0, initialization_1.initialize)({
42
+ ...options,
43
+ messenger: __classPrivateFieldGet(this, _Wallet_messenger, "f"),
44
+ }), "f");
45
+ __classPrivateFieldSet(this, _Wallet_controllerMetadata, Object.fromEntries(Object.entries(__classPrivateFieldGet(this, _Wallet_instances, "f"))
46
+ .filter(([_, instance]) => (0, utils_1.hasProperty)(instance, 'metadata'))
47
+ .map(([name, instance]) => [name, instance.metadata])), "f");
48
+ }
49
+ /**
50
+ * @returns The root messenger of the wallet.
51
+ */
52
+ get messenger() {
53
+ return __classPrivateFieldGet(this, _Wallet_messenger, "f");
54
+ }
55
+ set messenger(_) {
56
+ throw new Error('The messenger cannot be directly mutated.');
57
+ }
58
+ /**
59
+ * @returns The combined state of the wallet.
60
+ */
61
+ get state() {
62
+ return Object.entries(__classPrivateFieldGet(this, _Wallet_instances, "f")).reduce((totalState, [name, instance]) => {
63
+ if (instance.state) {
64
+ totalState[name] = instance.state;
65
+ }
66
+ return totalState;
67
+ }, {});
68
+ }
69
+ set state(_) {
70
+ throw new Error('Wallet state cannot be directly mutated.');
71
+ }
72
+ /**
73
+ * @returns The controller metadata; containing per-controller information about what properties to persist etc.
74
+ */
75
+ get controllerMetadata() {
76
+ return __classPrivateFieldGet(this, _Wallet_controllerMetadata, "f");
77
+ }
78
+ set controllerMetadata(_) {
79
+ throw new Error('The controller metadata cannot be directly mutated.');
80
+ }
81
+ /**
82
+ * Get an instantiated controller or service.
83
+ *
84
+ * @param name - The name.
85
+ * @returns The instance, if it exists.
86
+ * @deprecated - Please use the messenger instead of direct access.
87
+ */
88
+ getInstance(name) {
89
+ return __classPrivateFieldGet(this, _Wallet_instances, "f")[name];
90
+ }
91
+ /**
92
+ * Destroy the wallet instance.
93
+ */
94
+ async destroy() {
95
+ if (__classPrivateFieldGet(this, _Wallet_isDestroyed, "f")) {
96
+ return;
97
+ }
98
+ __classPrivateFieldSet(this, _Wallet_isDestroyed, true, "f");
99
+ await Promise.allSettled(Object.values(__classPrivateFieldGet(this, _Wallet_instances, "f")).map(async (instance) => {
100
+ // @ts-expect-error Accessing protected property.
101
+ if (typeof instance.destroy === 'function') {
102
+ // @ts-expect-error Accessing protected property.
103
+ // eslint-disable-next-line @typescript-eslint/await-thenable
104
+ return await instance.destroy();
105
+ }
106
+ /* istanbul ignore next */
107
+ return undefined;
108
+ }));
109
+ }
110
+ }
111
+ exports.Wallet = Wallet;
112
+ _Wallet_messenger = new WeakMap(), _Wallet_instances = new WeakMap(), _Wallet_controllerMetadata = new WeakMap(), _Wallet_isDestroyed = new WeakMap();
113
+ //# sourceMappingURL=Wallet.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Wallet.cjs","sourceRoot":"","sources":["../src/Wallet.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,mDAAgD;AAChD,2CAA8C;AAS9C,wEAA6D;AAG7D,MAAa,MAAM;IAYjB;;;;;;;;;;OAUG;IACH,YAAY,OAAsB;QAtBlC,oEAAoE;QAC3D,oCAAyD;QAEzD,oCAA6B;QAE7B,6CAEP;QAEF,8BAAe,KAAK,EAAC;QAcnB,uBAAA,IAAI,qBACF,OAAO,CAAC,SAAS;YACjB,IAAI,qBAAS,CAAC;gBACZ,SAAS,EAAE,MAAM;aAClB,CAAC,MAAA,CAAC;QAEL,uBAAA,IAAI,qBAAc,IAAA,2BAAU,EAAC;YAC3B,GAAG,OAAO;YACV,SAAS,EAAE,uBAAA,IAAI,yBAAW;SAC3B,CAAC,MAAA,CAAC;QAEH,uBAAA,IAAI,8BAAuB,MAAM,CAAC,WAAW,CAC3C,MAAM,CAAC,OAAO,CAAC,uBAAA,IAAI,yBAAW,CAAC;aAC5B,MAAM,CAAC,CAAC,CAAC,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AC;YACtB,OAAO;QACT,CAAC;QAED,uBAAA,IAAI,uBAAgB,IAAI,MAAA,CAAC;QAEzB,MAAM,OAAO,CAAC,UAAU,CACtB,MAAM,CAAC,MAAM,CAAC,uBAAA,IAAI,yBAAW,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE;YACpD,iDAAiD;YACjD,IAAI,OAAO,QAAQ,CAAC,OAAO,KAAK,UAAU,EAAE,CAAC;gBAC3C,iDAAiD;gBACjD,6DAA6D;gBAC7D,OAAO,MAAM,QAAQ,CAAC,OAAO,EAAE,CAAC;YAClC,CAAC;YACD,0BAA0B;YAC1B,OAAO,SAAS,CAAC;QACnB,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;CACF;AAjID,wBAiIC","sourcesContent":["import type { StateMetadataConstraint } from '@metamask/base-controller';\nimport { Messenger } from '@metamask/messenger';\nimport { hasProperty } from '@metamask/utils';\n\nimport type {\n DefaultActions,\n DefaultEvents,\n DefaultInstances,\n DefaultState,\n RootMessenger,\n} from './initialization/defaults';\nimport { initialize } from './initialization/initialization';\nimport { WalletOptions } from './types';\n\nexport class Wallet {\n // TODO: Expand default types when passing additionalConfigurations.\n readonly #messenger: RootMessenger<DefaultActions, DefaultEvents>;\n\n readonly #instances: DefaultInstances;\n\n readonly #controllerMetadata: Readonly<\n Record<string, Readonly<StateMetadataConstraint>>\n >;\n\n #isDestroyed = false;\n\n /**\n * Creates a `Wallet` instance, initializing all instances as specified by the passed options.\n *\n * @param options - Options bag.\n * @param options.messenger - An optional messenger to override the default one.\n * @param options.state - An optional state blob.\n * @param options.initializationConfigurations - An optional list of additional initialization configurations\n * required beyond the ones included by default.\n * @param options.instanceOptions - An optional object containing options that should be passed\n * to specific instances for additional customization.\n */\n constructor(options: WalletOptions) {\n this.#messenger =\n options.messenger ??\n new Messenger({\n namespace: 'Root',\n });\n\n this.#instances = initialize({\n ...options,\n messenger: this.#messenger,\n });\n\n this.#controllerMetadata = Object.fromEntries(\n Object.entries(this.#instances)\n .filter(([_, instance]) => hasProperty(instance, 'metadata'))\n .map(([name, instance]) => [name, instance.metadata]),\n );\n }\n\n /**\n * @returns The root messenger of the wallet.\n */\n get messenger(): Readonly<RootMessenger<DefaultActions, DefaultEvents>> {\n return this.#messenger;\n }\n\n set messenger(_) {\n throw new Error('The messenger cannot be directly mutated.');\n }\n\n /**\n * @returns The combined state of the wallet.\n */\n get state(): DefaultState {\n return Object.entries(this.#instances).reduce<Record<string, unknown>>(\n (totalState, [name, instance]) => {\n if (instance.state) {\n totalState[name] = instance.state;\n }\n return totalState;\n },\n {},\n ) as DefaultState;\n }\n\n set state(_) {\n throw new Error('Wallet state cannot be directly mutated.');\n }\n\n /**\n * @returns The controller metadata; containing per-controller information about what properties to persist etc.\n */\n get controllerMetadata(): Readonly<\n Record<string, Readonly<StateMetadataConstraint>>\n > {\n return this.#controllerMetadata;\n }\n\n set controllerMetadata(_) {\n throw new Error('The controller metadata cannot be directly mutated.');\n }\n\n getInstance<Name extends keyof DefaultInstances>(\n name: Name,\n ): DefaultInstances[Name];\n\n getInstance(\n name: string,\n ): DefaultInstances[keyof DefaultInstances] | undefined;\n\n /**\n * Get an instantiated controller or service.\n *\n * @param name - The name.\n * @returns The instance, if it exists.\n * @deprecated - Please use the messenger instead of direct access.\n */\n getInstance(\n name: string,\n ): DefaultInstances[keyof DefaultInstances] | undefined {\n return this.#instances[name as keyof DefaultInstances];\n }\n\n /**\n * Destroy the wallet instance.\n */\n async destroy(): Promise<void> {\n if (this.#isDestroyed) {\n return;\n }\n\n this.#isDestroyed = true;\n\n await Promise.allSettled(\n Object.values(this.#instances).map(async (instance) => {\n // @ts-expect-error Accessing protected property.\n if (typeof instance.destroy === 'function') {\n // @ts-expect-error Accessing protected property.\n // eslint-disable-next-line @typescript-eslint/await-thenable\n return await instance.destroy();\n }\n /* istanbul ignore next */\n return undefined;\n }),\n );\n }\n}\n"]}
@@ -0,0 +1,40 @@
1
+ import type { StateMetadataConstraint } from "@metamask/base-controller";
2
+ import type { DefaultActions, DefaultEvents, DefaultInstances, DefaultState, RootMessenger } from "./initialization/defaults.cjs";
3
+ import { WalletOptions } from "./types.cjs";
4
+ export declare class Wallet {
5
+ #private;
6
+ /**
7
+ * Creates a `Wallet` instance, initializing all instances as specified by the passed options.
8
+ *
9
+ * @param options - Options bag.
10
+ * @param options.messenger - An optional messenger to override the default one.
11
+ * @param options.state - An optional state blob.
12
+ * @param options.initializationConfigurations - An optional list of additional initialization configurations
13
+ * required beyond the ones included by default.
14
+ * @param options.instanceOptions - An optional object containing options that should be passed
15
+ * to specific instances for additional customization.
16
+ */
17
+ constructor(options: WalletOptions);
18
+ /**
19
+ * @returns The root messenger of the wallet.
20
+ */
21
+ get messenger(): Readonly<RootMessenger<DefaultActions, DefaultEvents>>;
22
+ set messenger(_: Readonly<RootMessenger<DefaultActions, DefaultEvents>>);
23
+ /**
24
+ * @returns The combined state of the wallet.
25
+ */
26
+ get state(): DefaultState;
27
+ set state(_: DefaultState);
28
+ /**
29
+ * @returns The controller metadata; containing per-controller information about what properties to persist etc.
30
+ */
31
+ get controllerMetadata(): Readonly<Record<string, Readonly<StateMetadataConstraint>>>;
32
+ set controllerMetadata(_: Readonly<Record<string, Readonly<StateMetadataConstraint>>>);
33
+ getInstance<Name extends keyof DefaultInstances>(name: Name): DefaultInstances[Name];
34
+ getInstance(name: string): DefaultInstances[keyof DefaultInstances] | undefined;
35
+ /**
36
+ * Destroy the wallet instance.
37
+ */
38
+ destroy(): Promise<void>;
39
+ }
40
+ //# sourceMappingURL=Wallet.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Wallet.d.cts","sourceRoot":"","sources":["../src/Wallet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,kCAAkC;AAIzE,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACd,sCAAkC;AAEnC,OAAO,EAAE,aAAa,EAAE,oBAAgB;AAExC,qBAAa,MAAM;;IAYjB;;;;;;;;;;OAUG;gBACS,OAAO,EAAE,aAAa;IAmBlC;;OAEG;IACH,IAAI,SAAS,IAAI,QAAQ,CAAC,aAAa,CAAC,cAAc,EAAE,aAAa,CAAC,CAAC,CAEtE;IAED,IAAI,SAAS,CAAC,CAAC,EAJE,QAAQ,CAAC,aAAa,CAAC,cAAc,EAAE,aAAa,CAAC,CAIvD,EAEd;IAED;;OAEG;IACH,IAAI,KAAK,IAAI,YAAY,CAUxB;IAED,IAAI,KAAK,CAAC,CAAC,EAZE,YAYF,EAEV;IAED;;OAEG;IACH,IAAI,kBAAkB,IAAI,QAAQ,CAChC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,uBAAuB,CAAC,CAAC,CAClD,CAEA;IAED,IAAI,kBAAkB,CAAC,CAAC,EANE,QAAQ,CAChC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,uBAAuB,CAAC,CAAC,CAK3B,EAEvB;IAED,WAAW,CAAC,IAAI,SAAS,MAAM,gBAAgB,EAC7C,IAAI,EAAE,IAAI,GACT,gBAAgB,CAAC,IAAI,CAAC;IAEzB,WAAW,CACT,IAAI,EAAE,MAAM,GACX,gBAAgB,CAAC,MAAM,gBAAgB,CAAC,GAAG,SAAS;IAevD;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAoB/B"}
@@ -0,0 +1,40 @@
1
+ import type { StateMetadataConstraint } from "@metamask/base-controller";
2
+ import type { DefaultActions, DefaultEvents, DefaultInstances, DefaultState, RootMessenger } from "./initialization/defaults.mjs";
3
+ import { WalletOptions } from "./types.mjs";
4
+ export declare class Wallet {
5
+ #private;
6
+ /**
7
+ * Creates a `Wallet` instance, initializing all instances as specified by the passed options.
8
+ *
9
+ * @param options - Options bag.
10
+ * @param options.messenger - An optional messenger to override the default one.
11
+ * @param options.state - An optional state blob.
12
+ * @param options.initializationConfigurations - An optional list of additional initialization configurations
13
+ * required beyond the ones included by default.
14
+ * @param options.instanceOptions - An optional object containing options that should be passed
15
+ * to specific instances for additional customization.
16
+ */
17
+ constructor(options: WalletOptions);
18
+ /**
19
+ * @returns The root messenger of the wallet.
20
+ */
21
+ get messenger(): Readonly<RootMessenger<DefaultActions, DefaultEvents>>;
22
+ set messenger(_: Readonly<RootMessenger<DefaultActions, DefaultEvents>>);
23
+ /**
24
+ * @returns The combined state of the wallet.
25
+ */
26
+ get state(): DefaultState;
27
+ set state(_: DefaultState);
28
+ /**
29
+ * @returns The controller metadata; containing per-controller information about what properties to persist etc.
30
+ */
31
+ get controllerMetadata(): Readonly<Record<string, Readonly<StateMetadataConstraint>>>;
32
+ set controllerMetadata(_: Readonly<Record<string, Readonly<StateMetadataConstraint>>>);
33
+ getInstance<Name extends keyof DefaultInstances>(name: Name): DefaultInstances[Name];
34
+ getInstance(name: string): DefaultInstances[keyof DefaultInstances] | undefined;
35
+ /**
36
+ * Destroy the wallet instance.
37
+ */
38
+ destroy(): Promise<void>;
39
+ }
40
+ //# sourceMappingURL=Wallet.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Wallet.d.mts","sourceRoot":"","sources":["../src/Wallet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,kCAAkC;AAIzE,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACd,sCAAkC;AAEnC,OAAO,EAAE,aAAa,EAAE,oBAAgB;AAExC,qBAAa,MAAM;;IAYjB;;;;;;;;;;OAUG;gBACS,OAAO,EAAE,aAAa;IAmBlC;;OAEG;IACH,IAAI,SAAS,IAAI,QAAQ,CAAC,aAAa,CAAC,cAAc,EAAE,aAAa,CAAC,CAAC,CAEtE;IAED,IAAI,SAAS,CAAC,CAAC,EAJE,QAAQ,CAAC,aAAa,CAAC,cAAc,EAAE,aAAa,CAAC,CAIvD,EAEd;IAED;;OAEG;IACH,IAAI,KAAK,IAAI,YAAY,CAUxB;IAED,IAAI,KAAK,CAAC,CAAC,EAZE,YAYF,EAEV;IAED;;OAEG;IACH,IAAI,kBAAkB,IAAI,QAAQ,CAChC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,uBAAuB,CAAC,CAAC,CAClD,CAEA;IAED,IAAI,kBAAkB,CAAC,CAAC,EANE,QAAQ,CAChC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,uBAAuB,CAAC,CAAC,CAK3B,EAEvB;IAED,WAAW,CAAC,IAAI,SAAS,MAAM,gBAAgB,EAC7C,IAAI,EAAE,IAAI,GACT,gBAAgB,CAAC,IAAI,CAAC;IAEzB,WAAW,CACT,IAAI,EAAE,MAAM,GACX,gBAAgB,CAAC,MAAM,gBAAgB,CAAC,GAAG,SAAS;IAevD;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAoB/B"}
@@ -0,0 +1,109 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _Wallet_messenger, _Wallet_instances, _Wallet_controllerMetadata, _Wallet_isDestroyed;
13
+ import { Messenger } from "@metamask/messenger";
14
+ import { hasProperty } from "@metamask/utils";
15
+ import { initialize } from "./initialization/initialization.mjs";
16
+ export class Wallet {
17
+ /**
18
+ * Creates a `Wallet` instance, initializing all instances as specified by the passed options.
19
+ *
20
+ * @param options - Options bag.
21
+ * @param options.messenger - An optional messenger to override the default one.
22
+ * @param options.state - An optional state blob.
23
+ * @param options.initializationConfigurations - An optional list of additional initialization configurations
24
+ * required beyond the ones included by default.
25
+ * @param options.instanceOptions - An optional object containing options that should be passed
26
+ * to specific instances for additional customization.
27
+ */
28
+ constructor(options) {
29
+ // TODO: Expand default types when passing additionalConfigurations.
30
+ _Wallet_messenger.set(this, void 0);
31
+ _Wallet_instances.set(this, void 0);
32
+ _Wallet_controllerMetadata.set(this, void 0);
33
+ _Wallet_isDestroyed.set(this, false);
34
+ __classPrivateFieldSet(this, _Wallet_messenger, options.messenger ??
35
+ new Messenger({
36
+ namespace: 'Root',
37
+ }), "f");
38
+ __classPrivateFieldSet(this, _Wallet_instances, initialize({
39
+ ...options,
40
+ messenger: __classPrivateFieldGet(this, _Wallet_messenger, "f"),
41
+ }), "f");
42
+ __classPrivateFieldSet(this, _Wallet_controllerMetadata, Object.fromEntries(Object.entries(__classPrivateFieldGet(this, _Wallet_instances, "f"))
43
+ .filter(([_, instance]) => hasProperty(instance, 'metadata'))
44
+ .map(([name, instance]) => [name, instance.metadata])), "f");
45
+ }
46
+ /**
47
+ * @returns The root messenger of the wallet.
48
+ */
49
+ get messenger() {
50
+ return __classPrivateFieldGet(this, _Wallet_messenger, "f");
51
+ }
52
+ set messenger(_) {
53
+ throw new Error('The messenger cannot be directly mutated.');
54
+ }
55
+ /**
56
+ * @returns The combined state of the wallet.
57
+ */
58
+ get state() {
59
+ return Object.entries(__classPrivateFieldGet(this, _Wallet_instances, "f")).reduce((totalState, [name, instance]) => {
60
+ if (instance.state) {
61
+ totalState[name] = instance.state;
62
+ }
63
+ return totalState;
64
+ }, {});
65
+ }
66
+ set state(_) {
67
+ throw new Error('Wallet state cannot be directly mutated.');
68
+ }
69
+ /**
70
+ * @returns The controller metadata; containing per-controller information about what properties to persist etc.
71
+ */
72
+ get controllerMetadata() {
73
+ return __classPrivateFieldGet(this, _Wallet_controllerMetadata, "f");
74
+ }
75
+ set controllerMetadata(_) {
76
+ throw new Error('The controller metadata cannot be directly mutated.');
77
+ }
78
+ /**
79
+ * Get an instantiated controller or service.
80
+ *
81
+ * @param name - The name.
82
+ * @returns The instance, if it exists.
83
+ * @deprecated - Please use the messenger instead of direct access.
84
+ */
85
+ getInstance(name) {
86
+ return __classPrivateFieldGet(this, _Wallet_instances, "f")[name];
87
+ }
88
+ /**
89
+ * Destroy the wallet instance.
90
+ */
91
+ async destroy() {
92
+ if (__classPrivateFieldGet(this, _Wallet_isDestroyed, "f")) {
93
+ return;
94
+ }
95
+ __classPrivateFieldSet(this, _Wallet_isDestroyed, true, "f");
96
+ await Promise.allSettled(Object.values(__classPrivateFieldGet(this, _Wallet_instances, "f")).map(async (instance) => {
97
+ // @ts-expect-error Accessing protected property.
98
+ if (typeof instance.destroy === 'function') {
99
+ // @ts-expect-error Accessing protected property.
100
+ // eslint-disable-next-line @typescript-eslint/await-thenable
101
+ return await instance.destroy();
102
+ }
103
+ /* istanbul ignore next */
104
+ return undefined;
105
+ }));
106
+ }
107
+ }
108
+ _Wallet_messenger = new WeakMap(), _Wallet_instances = new WeakMap(), _Wallet_controllerMetadata = new WeakMap(), _Wallet_isDestroyed = new WeakMap();
109
+ //# sourceMappingURL=Wallet.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Wallet.mjs","sourceRoot":"","sources":["../src/Wallet.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,OAAO,EAAE,SAAS,EAAE,4BAA4B;AAChD,OAAO,EAAE,WAAW,EAAE,wBAAwB;AAS9C,OAAO,EAAE,UAAU,EAAE,4CAAwC;AAG7D,MAAM,OAAO,MAAM;IAYjB;;;;;;;;;;OAUG;IACH,YAAY,OAAsB;QAtBlC,oEAAoE;QAC3D,oCAAyD;QAEzD,oCAA6B;QAE7B,6CAEP;Q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,CAAC,CAAC;IAC9D,CAAC;IAED;;OAEG;IACH,IAAI,kBAAkB;QAGpB,OAAO,uBAAA,IAAI,kCAAoB,CAAC;IAClC,CAAC;IAED,IAAI,kBAAkB,CAAC,CAAC;QACtB,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;IACzE,CAAC;IAUD;;;;;;OAMG;IACH,WAAW,CACT,IAAY;QAEZ,OAAO,uBAAA,IAAI,yBAAW,CAAC,IAA8B,CAAC,CAAC;IACzD,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,OAAO;QACX,IAAI,uBAAA,IAAI,2BAAa,EAAE,CAAC;YACtB,OAAO;QACT,CAAC;QAED,uBAAA,IAAI,uBAAgB,IAAI,MAAA,CAAC;QAEzB,MAAM,OAAO,CAAC,UAAU,CACtB,MAAM,CAAC,MAAM,CAAC,uBAAA,IAAI,yBAAW,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE;YACpD,iDAAiD;YACjD,IAAI,OAAO,QAAQ,CAAC,OAAO,KAAK,UAAU,EAAE,CAAC;gBAC3C,iDAAiD;gBACjD,6DAA6D;gBAC7D,OAAO,MAAM,QAAQ,CAAC,OAAO,EAAE,CAAC;YAClC,CAAC;YACD,0BAA0B;YAC1B,OAAO,SAAS,CAAC;QACnB,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;CACF","sourcesContent":["import type { StateMetadataConstraint } from '@metamask/base-controller';\nimport { Messenger } from '@metamask/messenger';\nimport { hasProperty } from '@metamask/utils';\n\nimport type {\n DefaultActions,\n DefaultEvents,\n DefaultInstances,\n DefaultState,\n RootMessenger,\n} from './initialization/defaults';\nimport { initialize } from './initialization/initialization';\nimport { WalletOptions } from './types';\n\nexport class Wallet {\n // TODO: Expand default types when passing additionalConfigurations.\n readonly #messenger: RootMessenger<DefaultActions, DefaultEvents>;\n\n readonly #instances: DefaultInstances;\n\n readonly #controllerMetadata: Readonly<\n Record<string, Readonly<StateMetadataConstraint>>\n >;\n\n #isDestroyed = false;\n\n /**\n * Creates a `Wallet` instance, initializing all instances as specified by the passed options.\n *\n * @param options - Options bag.\n * @param options.messenger - An optional messenger to override the default one.\n * @param options.state - An optional state blob.\n * @param options.initializationConfigurations - An optional list of additional initialization configurations\n * required beyond the ones included by default.\n * @param options.instanceOptions - An optional object containing options that should be passed\n * to specific instances for additional customization.\n */\n constructor(options: WalletOptions) {\n this.#messenger =\n options.messenger ??\n new Messenger({\n namespace: 'Root',\n });\n\n this.#instances = initialize({\n ...options,\n messenger: this.#messenger,\n });\n\n this.#controllerMetadata = Object.fromEntries(\n Object.entries(this.#instances)\n .filter(([_, instance]) => hasProperty(instance, 'metadata'))\n .map(([name, instance]) => [name, instance.metadata]),\n );\n }\n\n /**\n * @returns The root messenger of the wallet.\n */\n get messenger(): Readonly<RootMessenger<DefaultActions, DefaultEvents>> {\n return this.#messenger;\n }\n\n set messenger(_) {\n throw new Error('The messenger cannot be directly mutated.');\n }\n\n /**\n * @returns The combined state of the wallet.\n */\n get state(): DefaultState {\n return Object.entries(this.#instances).reduce<Record<string, unknown>>(\n (totalState, [name, instance]) => {\n if (instance.state) {\n totalState[name] = instance.state;\n }\n return totalState;\n },\n {},\n ) as DefaultState;\n }\n\n set state(_) {\n throw new Error('Wallet state cannot be directly mutated.');\n }\n\n /**\n * @returns The controller metadata; containing per-controller information about what properties to persist etc.\n */\n get controllerMetadata(): Readonly<\n Record<string, Readonly<StateMetadataConstraint>>\n > {\n return this.#controllerMetadata;\n }\n\n set controllerMetadata(_) {\n throw new Error('The controller metadata cannot be directly mutated.');\n }\n\n getInstance<Name extends keyof DefaultInstances>(\n name: Name,\n ): DefaultInstances[Name];\n\n getInstance(\n name: string,\n ): DefaultInstances[keyof DefaultInstances] | undefined;\n\n /**\n * Get an instantiated controller or service.\n *\n * @param name - The name.\n * @returns The instance, if it exists.\n * @deprecated - Please use the messenger instead of direct access.\n */\n getInstance(\n name: string,\n ): DefaultInstances[keyof DefaultInstances] | undefined {\n return this.#instances[name as keyof DefaultInstances];\n }\n\n /**\n * Destroy the wallet instance.\n */\n async destroy(): Promise<void> {\n if (this.#isDestroyed) {\n return;\n }\n\n this.#isDestroyed = true;\n\n await Promise.allSettled(\n Object.values(this.#instances).map(async (instance) => {\n // @ts-expect-error Accessing protected property.\n if (typeof instance.destroy === 'function') {\n // @ts-expect-error Accessing protected property.\n // eslint-disable-next-line @typescript-eslint/await-thenable\n return await instance.destroy();\n }\n /* istanbul ignore next */\n return undefined;\n }),\n );\n }\n}\n"]}
package/dist/index.cjs CHANGED
@@ -1,13 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- /**
4
- * Example function that returns a greeting for the given name.
5
- *
6
- * @param name - The name to greet.
7
- * @returns The greeting.
8
- */
9
- function greeter(name) {
10
- return `Hello, ${name}!`;
11
- }
12
- exports.default = greeter;
3
+ exports.Wallet = void 0;
4
+ var Wallet_1 = require("./Wallet.cjs");
5
+ Object.defineProperty(exports, "Wallet", { enumerable: true, get: function () { return Wallet_1.Wallet; } });
13
6
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA;;;;;GAKG;AACH,SAAwB,OAAO,CAAC,IAAY;IAC1C,OAAO,UAAU,IAAI,GAAG,CAAC;AAC3B,CAAC;AAFD,0BAEC","sourcesContent":["/**\n * Example function that returns a greeting for the given name.\n *\n * @param name - The name to greet.\n * @returns The greeting.\n */\nexport default function greeter(name: string): string {\n return `Hello, ${name}!`;\n}\n"]}
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,uCAAkC;AAAzB,gGAAA,MAAM,OAAA","sourcesContent":["export { Wallet } from './Wallet';\nexport type { WalletOptions } from './types';\nexport type {\n DefaultActions,\n DefaultEvents,\n DefaultInstances,\n DefaultState,\n RootMessenger,\n} from './initialization/defaults';\n"]}
package/dist/index.d.cts CHANGED
@@ -1,8 +1,4 @@
1
- /**
2
- * Example function that returns a greeting for the given name.
3
- *
4
- * @param name - The name to greet.
5
- * @returns The greeting.
6
- */
7
- export default function greeter(name: string): string;
1
+ export { Wallet } from "./Wallet.cjs";
2
+ export type { WalletOptions } from "./types.cjs";
3
+ export type { DefaultActions, DefaultEvents, DefaultInstances, DefaultState, RootMessenger, } from "./initialization/defaults.cjs";
8
4
  //# sourceMappingURL=index.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEpD"}
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,qBAAiB;AAClC,YAAY,EAAE,aAAa,EAAE,oBAAgB;AAC7C,YAAY,EACV,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,YAAY,EACZ,aAAa,GACd,sCAAkC"}
package/dist/index.d.mts CHANGED
@@ -1,8 +1,4 @@
1
- /**
2
- * Example function that returns a greeting for the given name.
3
- *
4
- * @param name - The name to greet.
5
- * @returns The greeting.
6
- */
7
- export default function greeter(name: string): string;
1
+ export { Wallet } from "./Wallet.mjs";
2
+ export type { WalletOptions } from "./types.mjs";
3
+ export type { DefaultActions, DefaultEvents, DefaultInstances, DefaultState, RootMessenger, } from "./initialization/defaults.mjs";
8
4
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEpD"}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,qBAAiB;AAClC,YAAY,EAAE,aAAa,EAAE,oBAAgB;AAC7C,YAAY,EACV,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,YAAY,EACZ,aAAa,GACd,sCAAkC"}
package/dist/index.mjs CHANGED
@@ -1,10 +1,2 @@
1
- /**
2
- * Example function that returns a greeting for the given name.
3
- *
4
- * @param name - The name to greet.
5
- * @returns The greeting.
6
- */
7
- export default function greeter(name) {
8
- return `Hello, ${name}!`;
9
- }
1
+ export { Wallet } from "./Wallet.mjs";
10
2
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,IAAY;IAC1C,OAAO,UAAU,IAAI,GAAG,CAAC;AAC3B,CAAC","sourcesContent":["/**\n * Example function that returns a greeting for the given name.\n *\n * @param name - The name to greet.\n * @returns The greeting.\n */\nexport default function greeter(name: string): string {\n return `Hello, ${name}!`;\n}\n"]}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,qBAAiB","sourcesContent":["export { Wallet } from './Wallet';\nexport type { WalletOptions } from './types';\nexport type {\n DefaultActions,\n DefaultEvents,\n DefaultInstances,\n DefaultState,\n RootMessenger,\n} from './initialization/defaults';\n"]}
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.defaultConfigurations = void 0;
27
+ const defaultConfigurations = __importStar(require("./instances/index.cjs"));
28
+ exports.defaultConfigurations = defaultConfigurations;
29
+ //# sourceMappingURL=defaults.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defaults.cjs","sourceRoot":"","sources":["../../src/initialization/defaults.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAQA,6EAAqD;AAG5C,sDAAqB","sourcesContent":["import type {\n ActionConstraint,\n EventConstraint,\n Messenger,\n MessengerActions,\n MessengerEvents,\n} from '@metamask/messenger';\n\nimport * as defaultConfigurations from './instances';\nimport type { InitializationConfiguration, InstanceState } from './types';\n\nexport { defaultConfigurations };\n\n/**\n * Utility type for inferring and extracting an instance type from an initialization configuration.\n */\ntype ExtractInstance<Config> =\n Config extends InitializationConfiguration<infer Instance, unknown>\n ? Instance\n : never;\n\n/**\n * Utility type for inferring and extracting an instance messenger type from an initialization configuration.\n */\ntype ExtractInstanceMessenger<Config> =\n Config extends InitializationConfiguration<unknown, infer InferredMessenger>\n ? InferredMessenger\n : never;\n\n/**\n * Utility type for inferring and extracting the name of an instance from an initialization configuration.\n */\ntype ExtractName<Config> =\n ExtractInstance<Config> extends { name: infer Name extends string }\n ? Name\n : never;\n\ntype DefaultConfigs = typeof defaultConfigurations;\n\ntype AllDefaultMessengers = ExtractInstanceMessenger<\n DefaultConfigs[keyof DefaultConfigs]\n>;\n\nexport type DefaultInstances = {\n [Key in keyof DefaultConfigs as ExtractName<\n DefaultConfigs[Key]\n >]: ExtractInstance<DefaultConfigs[Key]>;\n};\n\nexport type DefaultActions = MessengerActions<AllDefaultMessengers>;\n\nexport type DefaultEvents = MessengerEvents<AllDefaultMessengers>;\n\nexport type RootMessenger<\n AllowedActions extends ActionConstraint,\n AllowedEvents extends EventConstraint,\n> = Messenger<'Root', AllowedActions, AllowedEvents>;\n\nexport type DefaultState = {\n [Key in keyof DefaultInstances]: InstanceState<DefaultInstances[Key]>;\n};\n"]}
@@ -0,0 +1,30 @@
1
+ import type { ActionConstraint, EventConstraint, Messenger, MessengerActions, MessengerEvents } from "@metamask/messenger";
2
+ import * as defaultConfigurations from "./instances/index.cjs";
3
+ import type { InitializationConfiguration, InstanceState } from "./types.cjs";
4
+ export { defaultConfigurations };
5
+ /**
6
+ * Utility type for inferring and extracting an instance type from an initialization configuration.
7
+ */
8
+ type ExtractInstance<Config> = Config extends InitializationConfiguration<infer Instance, unknown> ? Instance : never;
9
+ /**
10
+ * Utility type for inferring and extracting an instance messenger type from an initialization configuration.
11
+ */
12
+ type ExtractInstanceMessenger<Config> = Config extends InitializationConfiguration<unknown, infer InferredMessenger> ? InferredMessenger : never;
13
+ /**
14
+ * Utility type for inferring and extracting the name of an instance from an initialization configuration.
15
+ */
16
+ type ExtractName<Config> = ExtractInstance<Config> extends {
17
+ name: infer Name extends string;
18
+ } ? Name : never;
19
+ type DefaultConfigs = typeof defaultConfigurations;
20
+ type AllDefaultMessengers = ExtractInstanceMessenger<DefaultConfigs[keyof DefaultConfigs]>;
21
+ export type DefaultInstances = {
22
+ [Key in keyof DefaultConfigs as ExtractName<DefaultConfigs[Key]>]: ExtractInstance<DefaultConfigs[Key]>;
23
+ };
24
+ export type DefaultActions = MessengerActions<AllDefaultMessengers>;
25
+ export type DefaultEvents = MessengerEvents<AllDefaultMessengers>;
26
+ export type RootMessenger<AllowedActions extends ActionConstraint, AllowedEvents extends EventConstraint> = Messenger<'Root', AllowedActions, AllowedEvents>;
27
+ export type DefaultState = {
28
+ [Key in keyof DefaultInstances]: InstanceState<DefaultInstances[Key]>;
29
+ };
30
+ //# sourceMappingURL=defaults.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defaults.d.cts","sourceRoot":"","sources":["../../src/initialization/defaults.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EACf,SAAS,EACT,gBAAgB,EAChB,eAAe,EAChB,4BAA4B;AAE7B,OAAO,KAAK,qBAAqB,8BAAoB;AACrD,OAAO,KAAK,EAAE,2BAA2B,EAAE,aAAa,EAAE,oBAAgB;AAE1E,OAAO,EAAE,qBAAqB,EAAE,CAAC;AAEjC;;GAEG;AACH,KAAK,eAAe,CAAC,MAAM,IACzB,MAAM,SAAS,2BAA2B,CAAC,MAAM,QAAQ,EAAE,OAAO,CAAC,GAC/D,QAAQ,GACR,KAAK,CAAC;AAEZ;;GAEG;AACH,KAAK,wBAAwB,CAAC,MAAM,IAClC,MAAM,SAAS,2BAA2B,CAAC,OAAO,EAAE,MAAM,iBAAiB,CAAC,GACxE,iBAAiB,GACjB,KAAK,CAAC;AAEZ;;GAEG;AACH,KAAK,WAAW,CAAC,MAAM,IACrB,eAAe,CAAC,MAAM,CAAC,SAAS;IAAE,IAAI,EAAE,MAAM,IAAI,SAAS,MAAM,CAAA;CAAE,GAC/D,IAAI,GACJ,KAAK,CAAC;AAEZ,KAAK,cAAc,GAAG,OAAO,qBAAqB,CAAC;AAEnD,KAAK,oBAAoB,GAAG,wBAAwB,CAClD,cAAc,CAAC,MAAM,cAAc,CAAC,CACrC,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;KAC5B,GAAG,IAAI,MAAM,cAAc,IAAI,WAAW,CACzC,cAAc,CAAC,GAAG,CAAC,CACpB,GAAG,eAAe,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;CACzC,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,gBAAgB,CAAC,oBAAoB,CAAC,CAAC;AAEpE,MAAM,MAAM,aAAa,GAAG,eAAe,CAAC,oBAAoB,CAAC,CAAC;AAElE,MAAM,MAAM,aAAa,CACvB,cAAc,SAAS,gBAAgB,EACvC,aAAa,SAAS,eAAe,IACnC,SAAS,CAAC,MAAM,EAAE,cAAc,EAAE,aAAa,CAAC,CAAC;AAErD,MAAM,MAAM,YAAY,GAAG;KACxB,GAAG,IAAI,MAAM,gBAAgB,GAAG,aAAa,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC;CACtE,CAAC"}
@@ -0,0 +1,30 @@
1
+ import type { ActionConstraint, EventConstraint, Messenger, MessengerActions, MessengerEvents } from "@metamask/messenger";
2
+ import * as defaultConfigurations from "./instances/index.mjs";
3
+ import type { InitializationConfiguration, InstanceState } from "./types.mjs";
4
+ export { defaultConfigurations };
5
+ /**
6
+ * Utility type for inferring and extracting an instance type from an initialization configuration.
7
+ */
8
+ type ExtractInstance<Config> = Config extends InitializationConfiguration<infer Instance, unknown> ? Instance : never;
9
+ /**
10
+ * Utility type for inferring and extracting an instance messenger type from an initialization configuration.
11
+ */
12
+ type ExtractInstanceMessenger<Config> = Config extends InitializationConfiguration<unknown, infer InferredMessenger> ? InferredMessenger : never;
13
+ /**
14
+ * Utility type for inferring and extracting the name of an instance from an initialization configuration.
15
+ */
16
+ type ExtractName<Config> = ExtractInstance<Config> extends {
17
+ name: infer Name extends string;
18
+ } ? Name : never;
19
+ type DefaultConfigs = typeof defaultConfigurations;
20
+ type AllDefaultMessengers = ExtractInstanceMessenger<DefaultConfigs[keyof DefaultConfigs]>;
21
+ export type DefaultInstances = {
22
+ [Key in keyof DefaultConfigs as ExtractName<DefaultConfigs[Key]>]: ExtractInstance<DefaultConfigs[Key]>;
23
+ };
24
+ export type DefaultActions = MessengerActions<AllDefaultMessengers>;
25
+ export type DefaultEvents = MessengerEvents<AllDefaultMessengers>;
26
+ export type RootMessenger<AllowedActions extends ActionConstraint, AllowedEvents extends EventConstraint> = Messenger<'Root', AllowedActions, AllowedEvents>;
27
+ export type DefaultState = {
28
+ [Key in keyof DefaultInstances]: InstanceState<DefaultInstances[Key]>;
29
+ };
30
+ //# sourceMappingURL=defaults.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defaults.d.mts","sourceRoot":"","sources":["../../src/initialization/defaults.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EACf,SAAS,EACT,gBAAgB,EAChB,eAAe,EAChB,4BAA4B;AAE7B,OAAO,KAAK,qBAAqB,8BAAoB;AACrD,OAAO,KAAK,EAAE,2BAA2B,EAAE,aAAa,EAAE,oBAAgB;AAE1E,OAAO,EAAE,qBAAqB,EAAE,CAAC;AAEjC;;GAEG;AACH,KAAK,eAAe,CAAC,MAAM,IACzB,MAAM,SAAS,2BAA2B,CAAC,MAAM,QAAQ,EAAE,OAAO,CAAC,GAC/D,QAAQ,GACR,KAAK,CAAC;AAEZ;;GAEG;AACH,KAAK,wBAAwB,CAAC,MAAM,IAClC,MAAM,SAAS,2BAA2B,CAAC,OAAO,EAAE,MAAM,iBAAiB,CAAC,GACxE,iBAAiB,GACjB,KAAK,CAAC;AAEZ;;GAEG;AACH,KAAK,WAAW,CAAC,MAAM,IACrB,eAAe,CAAC,MAAM,CAAC,SAAS;IAAE,IAAI,EAAE,MAAM,IAAI,SAAS,MAAM,CAAA;CAAE,GAC/D,IAAI,GACJ,KAAK,CAAC;AAEZ,KAAK,cAAc,GAAG,OAAO,qBAAqB,CAAC;AAEnD,KAAK,oBAAoB,GAAG,wBAAwB,CAClD,cAAc,CAAC,MAAM,cAAc,CAAC,CACrC,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;KAC5B,GAAG,IAAI,MAAM,cAAc,IAAI,WAAW,CACzC,cAAc,CAAC,GAAG,CAAC,CACpB,GAAG,eAAe,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;CACzC,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,gBAAgB,CAAC,oBAAoB,CAAC,CAAC;AAEpE,MAAM,MAAM,aAAa,GAAG,eAAe,CAAC,oBAAoB,CAAC,CAAC;AAElE,MAAM,MAAM,aAAa,CACvB,cAAc,SAAS,gBAAgB,EACvC,aAAa,SAAS,eAAe,IACnC,SAAS,CAAC,MAAM,EAAE,cAAc,EAAE,aAAa,CAAC,CAAC;AAErD,MAAM,MAAM,YAAY,GAAG;KACxB,GAAG,IAAI,MAAM,gBAAgB,GAAG,aAAa,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC;CACtE,CAAC"}
@@ -0,0 +1,3 @@
1
+ import * as defaultConfigurations from "./instances/index.mjs";
2
+ export { defaultConfigurations };
3
+ //# sourceMappingURL=defaults.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defaults.mjs","sourceRoot":"","sources":["../../src/initialization/defaults.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,qBAAqB,8BAAoB;AAGrD,OAAO,EAAE,qBAAqB,EAAE,CAAC","sourcesContent":["import type {\n ActionConstraint,\n EventConstraint,\n Messenger,\n MessengerActions,\n MessengerEvents,\n} from '@metamask/messenger';\n\nimport * as defaultConfigurations from './instances';\nimport type { InitializationConfiguration, InstanceState } from './types';\n\nexport { defaultConfigurations };\n\n/**\n * Utility type for inferring and extracting an instance type from an initialization configuration.\n */\ntype ExtractInstance<Config> =\n Config extends InitializationConfiguration<infer Instance, unknown>\n ? Instance\n : never;\n\n/**\n * Utility type for inferring and extracting an instance messenger type from an initialization configuration.\n */\ntype ExtractInstanceMessenger<Config> =\n Config extends InitializationConfiguration<unknown, infer InferredMessenger>\n ? InferredMessenger\n : never;\n\n/**\n * Utility type for inferring and extracting the name of an instance from an initialization configuration.\n */\ntype ExtractName<Config> =\n ExtractInstance<Config> extends { name: infer Name extends string }\n ? Name\n : never;\n\ntype DefaultConfigs = typeof defaultConfigurations;\n\ntype AllDefaultMessengers = ExtractInstanceMessenger<\n DefaultConfigs[keyof DefaultConfigs]\n>;\n\nexport type DefaultInstances = {\n [Key in keyof DefaultConfigs as ExtractName<\n DefaultConfigs[Key]\n >]: ExtractInstance<DefaultConfigs[Key]>;\n};\n\nexport type DefaultActions = MessengerActions<AllDefaultMessengers>;\n\nexport type DefaultEvents = MessengerEvents<AllDefaultMessengers>;\n\nexport type RootMessenger<\n AllowedActions extends ActionConstraint,\n AllowedEvents extends EventConstraint,\n> = Messenger<'Root', AllowedActions, AllowedEvents>;\n\nexport type DefaultState = {\n [Key in keyof DefaultInstances]: InstanceState<DefaultInstances[Key]>;\n};\n"]}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.initialize = void 0;
4
+ const defaults_1 = require("./defaults.cjs");
5
+ /**
6
+ * Initialize all instances based on th default configurations and any additional configurations specified in `options`.
7
+ *
8
+ * @param options - The wallet options.
9
+ * @returns A map containing the instances.
10
+ */
11
+ function initialize(options) {
12
+ const { messenger, state = {}, initializationConfigurations = [], instanceOptions, } = options;
13
+ const overriddenConfiguration = initializationConfigurations.map((config) => config.name);
14
+ const configurationEntries = initializationConfigurations.concat(Object.values(defaults_1.defaultConfigurations).filter((config) => !overriddenConfiguration.includes(config.name)));
15
+ const instances = {};
16
+ for (const config of configurationEntries) {
17
+ const { name } = config;
18
+ const instanceState = state[name];
19
+ const instanceMessenger = config.getMessenger(messenger);
20
+ const camelCaseName = `${name.charAt(0).toLowerCase()}${name.slice(1)}`;
21
+ const instance = config.init({
22
+ // TODO: Consider whether this can be improved
23
+ state: instanceState,
24
+ messenger: instanceMessenger,
25
+ options: instanceOptions?.[camelCaseName] ?? {},
26
+ });
27
+ instances[name] = instance;
28
+ }
29
+ return instances;
30
+ }
31
+ exports.initialize = initialize;
32
+ //# sourceMappingURL=initialization.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"initialization.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SAA6B,CAAC;AACvC,CAAC;AAzCD,gCAyCC","sourcesContent":["import type { InstanceSpecificOptions, WalletOptions } from '../types';\nimport type {\n DefaultActions,\n DefaultEvents,\n DefaultInstances,\n} from './defaults';\nimport { defaultConfigurations, RootMessenger } from './defaults';\n\ntype InitializeOptions = WalletOptions & {\n messenger: RootMessenger<DefaultActions, DefaultEvents>;\n};\n\n/**\n * Initialize all instances based on th default configurations and any additional configurations specified in `options`.\n *\n * @param options - The wallet options.\n * @returns A map containing the instances.\n */\nexport function initialize(options: InitializeOptions): DefaultInstances {\n const {\n messenger,\n state = {},\n initializationConfigurations = [],\n instanceOptions,\n } = options;\n\n const overriddenConfiguration = initializationConfigurations.map(\n (config) => config.name,\n );\n\n const configurationEntries = initializationConfigurations.concat(\n Object.values(defaultConfigurations).filter(\n (config) => !overriddenConfiguration.includes(config.name),\n ),\n );\n\n const instances: Record<string, unknown> = {};\n\n for (const config of configurationEntries) {\n const { name } = config;\n\n const instanceState = state[name];\n\n const instanceMessenger = config.getMessenger(messenger);\n\n const camelCaseName =\n `${name.charAt(0).toLowerCase()}${name.slice(1)}` as keyof InstanceSpecificOptions;\n\n const instance = config.init({\n // TODO: Consider whether this can be improved\n state: instanceState as never,\n messenger: instanceMessenger,\n options: instanceOptions?.[camelCaseName] ?? {},\n });\n\n instances[name] = instance as Record<string, unknown>;\n }\n\n return instances as DefaultInstances;\n}\n"]}
@@ -0,0 +1,15 @@
1
+ import type { WalletOptions } from "../types.cjs";
2
+ import type { DefaultActions, DefaultEvents, DefaultInstances } from "./defaults.cjs";
3
+ import { RootMessenger } from "./defaults.cjs";
4
+ type InitializeOptions = WalletOptions & {
5
+ messenger: RootMessenger<DefaultActions, DefaultEvents>;
6
+ };
7
+ /**
8
+ * Initialize all instances based on th default configurations and any additional configurations specified in `options`.
9
+ *
10
+ * @param options - The wallet options.
11
+ * @returns A map containing the instances.
12
+ */
13
+ export declare function initialize(options: InitializeOptions): DefaultInstances;
14
+ export {};
15
+ //# sourceMappingURL=initialization.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"initialization.d.cts","sourceRoot":"","sources":["../../src/initialization/initialization.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAA2B,aAAa,EAAE,qBAAiB;AACvE,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,gBAAgB,EACjB,uBAAmB;AACpB,OAAO,EAAyB,aAAa,EAAE,uBAAmB;AAElE,KAAK,iBAAiB,GAAG,aAAa,GAAG;IACvC,SAAS,EAAE,aAAa,CAAC,cAAc,EAAE,aAAa,CAAC,CAAC;CACzD,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,iBAAiB,GAAG,gBAAgB,CAyCvE"}