@metamask/wallet 1.0.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.
- package/CHANGELOG.md +17 -0
- package/LICENSE +6 -0
- package/LICENSE.APACHE2 +201 -0
- package/LICENSE.MIT +21 -0
- package/README.md +15 -0
- package/dist/Wallet.cjs +113 -0
- package/dist/Wallet.cjs.map +1 -0
- package/dist/Wallet.d.cts +40 -0
- package/dist/Wallet.d.cts.map +1 -0
- package/dist/Wallet.d.mts +40 -0
- package/dist/Wallet.d.mts.map +1 -0
- package/dist/Wallet.mjs +109 -0
- package/dist/Wallet.mjs.map +1 -0
- package/dist/index.cjs +6 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +4 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -0
- package/dist/initialization/defaults.cjs +29 -0
- package/dist/initialization/defaults.cjs.map +1 -0
- package/dist/initialization/defaults.d.cts +30 -0
- package/dist/initialization/defaults.d.cts.map +1 -0
- package/dist/initialization/defaults.d.mts +30 -0
- package/dist/initialization/defaults.d.mts.map +1 -0
- package/dist/initialization/defaults.mjs +3 -0
- package/dist/initialization/defaults.mjs.map +1 -0
- package/dist/initialization/initialization.cjs +32 -0
- package/dist/initialization/initialization.cjs.map +1 -0
- package/dist/initialization/initialization.d.cts +15 -0
- package/dist/initialization/initialization.d.cts.map +1 -0
- package/dist/initialization/initialization.d.mts +15 -0
- package/dist/initialization/initialization.d.mts.map +1 -0
- package/dist/initialization/initialization.mjs +28 -0
- package/dist/initialization/initialization.mjs.map +1 -0
- package/dist/initialization/instances/index.cjs +6 -0
- package/dist/initialization/instances/index.cjs.map +1 -0
- package/dist/initialization/instances/index.d.cts +2 -0
- package/dist/initialization/instances/index.d.cts.map +1 -0
- package/dist/initialization/instances/index.d.mts +2 -0
- package/dist/initialization/instances/index.d.mts.map +1 -0
- package/dist/initialization/instances/index.mjs +2 -0
- package/dist/initialization/instances/index.mjs.map +1 -0
- package/dist/initialization/instances/keyring-controller.cjs +98 -0
- package/dist/initialization/instances/keyring-controller.cjs.map +1 -0
- package/dist/initialization/instances/keyring-controller.d.cts +31 -0
- package/dist/initialization/instances/keyring-controller.d.cts.map +1 -0
- package/dist/initialization/instances/keyring-controller.d.mts +31 -0
- package/dist/initialization/instances/keyring-controller.d.mts.map +1 -0
- package/dist/initialization/instances/keyring-controller.mjs +94 -0
- package/dist/initialization/instances/keyring-controller.mjs.map +1 -0
- package/dist/initialization/types.cjs +3 -0
- package/dist/initialization/types.cjs.map +1 -0
- package/dist/initialization/types.d.cts +35 -0
- package/dist/initialization/types.d.cts.map +1 -0
- package/dist/initialization/types.d.mts +35 -0
- package/dist/initialization/types.d.mts.map +1 -0
- package/dist/initialization/types.mjs +2 -0
- package/dist/initialization/types.mjs.map +1 -0
- package/dist/types.cjs +3 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.cts +18 -0
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.mts +18 -0
- package/dist/types.d.mts.map +1 -0
- package/dist/types.mjs +2 -0
- package/dist/types.mjs.map +1 -0
- package/dist/utilities.cjs +20 -0
- package/dist/utilities.cjs.map +1 -0
- package/dist/utilities.d.cts +10 -0
- package/dist/utilities.d.cts.map +1 -0
- package/dist/utilities.d.mts +10 -0
- package/dist/utilities.d.mts.map +1 -0
- package/dist/utilities.mjs +16 -0
- package/dist/utilities.mjs.map +1 -0
- package/package.json +78 -0
|
@@ -0,0 +1 @@
|
|
|
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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
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 @@
|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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 @@
|
|
|
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.cjs","sourceRoot":"","sources":["../../src/initialization/initialization.ts"],"names":[],"mappings":";;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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"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { WalletOptions } from "../types.mjs";
|
|
2
|
+
import type { DefaultActions, DefaultEvents, DefaultInstances } from "./defaults.mjs";
|
|
3
|
+
import { RootMessenger } from "./defaults.mjs";
|
|
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.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"initialization.d.mts","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"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { defaultConfigurations } from "./defaults.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* Initialize all instances based on th default configurations and any additional configurations specified in `options`.
|
|
4
|
+
*
|
|
5
|
+
* @param options - The wallet options.
|
|
6
|
+
* @returns A map containing the instances.
|
|
7
|
+
*/
|
|
8
|
+
export function initialize(options) {
|
|
9
|
+
const { messenger, state = {}, initializationConfigurations = [], instanceOptions, } = options;
|
|
10
|
+
const overriddenConfiguration = initializationConfigurations.map((config) => config.name);
|
|
11
|
+
const configurationEntries = initializationConfigurations.concat(Object.values(defaultConfigurations).filter((config) => !overriddenConfiguration.includes(config.name)));
|
|
12
|
+
const instances = {};
|
|
13
|
+
for (const config of configurationEntries) {
|
|
14
|
+
const { name } = config;
|
|
15
|
+
const instanceState = state[name];
|
|
16
|
+
const instanceMessenger = config.getMessenger(messenger);
|
|
17
|
+
const camelCaseName = `${name.charAt(0).toLowerCase()}${name.slice(1)}`;
|
|
18
|
+
const instance = config.init({
|
|
19
|
+
// TODO: Consider whether this can be improved
|
|
20
|
+
state: instanceState,
|
|
21
|
+
messenger: instanceMessenger,
|
|
22
|
+
options: instanceOptions?.[camelCaseName] ?? {},
|
|
23
|
+
});
|
|
24
|
+
instances[name] = instance;
|
|
25
|
+
}
|
|
26
|
+
return instances;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=initialization.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"initialization.mjs","sourceRoot":"","sources":["../../src/initial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O,SAA6B,CAAC;AACvC,CAAC","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,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.keyringController = void 0;
|
|
4
|
+
var keyring_controller_1 = require("./keyring-controller.cjs");
|
|
5
|
+
Object.defineProperty(exports, "keyringController", { enumerable: true, get: function () { return keyring_controller_1.keyringController; } });
|
|
6
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../src/initialization/instances/index.ts"],"names":[],"mappings":";;;AAAA,+DAAyD;AAAhD,uHAAA,iBAAiB,OAAA","sourcesContent":["export { keyringController } from './keyring-controller';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../src/initialization/instances/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,iCAA6B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/initialization/instances/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,iCAA6B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../src/initialization/instances/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,iCAA6B","sourcesContent":["export { keyringController } from './keyring-controller';\n"]}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.keyringController = exports.encryptorFactory = void 0;
|
|
4
|
+
const browser_passworder_1 = require("@metamask/browser-passworder");
|
|
5
|
+
const keyring_controller_1 = require("@metamask/keyring-controller");
|
|
6
|
+
const messenger_1 = require("@metamask/messenger");
|
|
7
|
+
/**
|
|
8
|
+
* A factory function for the encrypt method of the browser-passworder library,
|
|
9
|
+
* that encrypts with a given number of iterations.
|
|
10
|
+
*
|
|
11
|
+
* @param iterations - The number of iterations to use for the PBKDF2 algorithm.
|
|
12
|
+
* @returns A function that encrypts with the given number of iterations.
|
|
13
|
+
*/
|
|
14
|
+
const encryptFactory = (iterations) => async (password, data, key, salt) => (0, browser_passworder_1.encrypt)(password, data, key, salt, {
|
|
15
|
+
algorithm: 'PBKDF2',
|
|
16
|
+
params: {
|
|
17
|
+
iterations,
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
/**
|
|
21
|
+
* A factory function for the encryptWithDetail method of the browser-passworder library,
|
|
22
|
+
* that encrypts with a given number of iterations.
|
|
23
|
+
*
|
|
24
|
+
* @param iterations - The number of iterations to use for the PBKDF2 algorithm.
|
|
25
|
+
* @returns A function that encrypts with the given number of iterations.
|
|
26
|
+
*/
|
|
27
|
+
const encryptWithDetailFactory = (iterations) => async (password, object, salt) => (0, browser_passworder_1.encryptWithDetail)(password, object, salt, {
|
|
28
|
+
algorithm: 'PBKDF2',
|
|
29
|
+
params: {
|
|
30
|
+
iterations,
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
/**
|
|
34
|
+
* A factory function for the keyFromPassword method of the browser-passworder library,
|
|
35
|
+
* that generates a key from a password and a salt.
|
|
36
|
+
*
|
|
37
|
+
* This factory function overrides the default key derivation options with the specified
|
|
38
|
+
* number of iterations, unless existing key derivation options are passed in.
|
|
39
|
+
*
|
|
40
|
+
* @param iterations - The number of iterations to use for the PBKDF2 algorithm.
|
|
41
|
+
* @returns A function that generates a key with a potentially overriden number of iterations.
|
|
42
|
+
*/
|
|
43
|
+
const keyFromPasswordFactory = (iterations) => async (password, salt, exportable, opts) => (0, browser_passworder_1.keyFromPassword)(password, salt, exportable, opts ?? {
|
|
44
|
+
algorithm: 'PBKDF2',
|
|
45
|
+
params: {
|
|
46
|
+
iterations,
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
/**
|
|
50
|
+
* A factory function for the isVaultUpdated method of the browser-passworder library,
|
|
51
|
+
* that checks if the given vault was encrypted with the given number of iterations.
|
|
52
|
+
*
|
|
53
|
+
* @param iterations - The number of iterations to use for the PBKDF2 algorithm.
|
|
54
|
+
* @returns A function that checks if the vault was encrypted with the given number of iterations.
|
|
55
|
+
*/
|
|
56
|
+
const isVaultUpdatedFactory = (iterations) => (vault) => (0, browser_passworder_1.isVaultUpdated)(vault, {
|
|
57
|
+
algorithm: 'PBKDF2',
|
|
58
|
+
params: {
|
|
59
|
+
iterations,
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
/**
|
|
63
|
+
* A factory function that returns an encryptor with the given number of iterations.
|
|
64
|
+
*
|
|
65
|
+
* The returned encryptor is a wrapper around the browser-passworder library, that
|
|
66
|
+
* calls the encrypt and encryptWithDetail methods with the given number of iterations.
|
|
67
|
+
*
|
|
68
|
+
* @param iterations - The number of iterations to use for the PBKDF2 algorithm.
|
|
69
|
+
* @returns An encryptor set with the given number of iterations.
|
|
70
|
+
*/
|
|
71
|
+
const encryptorFactory = (iterations) => ({
|
|
72
|
+
encrypt: encryptFactory(iterations),
|
|
73
|
+
encryptWithKey: browser_passworder_1.encryptWithKey,
|
|
74
|
+
encryptWithDetail: encryptWithDetailFactory(iterations),
|
|
75
|
+
decrypt: browser_passworder_1.decrypt,
|
|
76
|
+
decryptWithKey: browser_passworder_1.decryptWithKey,
|
|
77
|
+
decryptWithDetail: browser_passworder_1.decryptWithDetail,
|
|
78
|
+
keyFromPassword: keyFromPasswordFactory(iterations),
|
|
79
|
+
isVaultUpdated: isVaultUpdatedFactory(iterations),
|
|
80
|
+
importKey: browser_passworder_1.importKey,
|
|
81
|
+
exportKey: browser_passworder_1.exportKey,
|
|
82
|
+
generateSalt: browser_passworder_1.generateSalt,
|
|
83
|
+
});
|
|
84
|
+
exports.encryptorFactory = encryptorFactory;
|
|
85
|
+
exports.keyringController = {
|
|
86
|
+
name: 'KeyringController',
|
|
87
|
+
init: ({ state, messenger, options }) => new keyring_controller_1.KeyringController({
|
|
88
|
+
state,
|
|
89
|
+
messenger,
|
|
90
|
+
keyringBuilders: options.keyringBuilders,
|
|
91
|
+
encryptor: (options.encryptor ?? (0, exports.encryptorFactory)(600000)),
|
|
92
|
+
}),
|
|
93
|
+
getMessenger: (parent) => new messenger_1.Messenger({
|
|
94
|
+
namespace: 'KeyringController',
|
|
95
|
+
parent,
|
|
96
|
+
}),
|
|
97
|
+
};
|
|
98
|
+
//# sourceMappingURL=keyring-controller.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyring-controller.cjs","sourceRoot":"","sources":["../../../src/initialization/instances/keyring-controller.ts"],"names":[],"mappings":";;;AAKA,qEAYsC;AAEtC,qEAGsC;AACtC,mDAAgD;AAIhD;;;;;;GAMG;AACH,MAAM,cAAc,GAClB,CAAC,UAAkB,EAAE,EAAE,CACvB,KAAK,EACH,QAAgB,EAChB,IAAa,EACb,GAA+B,EAC/B,IAAa,EACI,EAAE,CACnB,IAAA,4BAAO,EAAC,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE;IACjC,SAAS,EAAE,QAAQ;IACnB,MAAM,EAAE;QACN,UAAU;KACX;CACF,CAAC,CAAC;AAEP;;;;;;GAMG;AACH,MAAM,wBAAwB,GAC5B,CAAC,UAAkB,EAAE,EAAE,CACvB,KAAK,EACH,QAAgB,EAChB,MAAe,EACf,IAAa,EACsB,EAAE,CACrC,IAAA,sCAAiB,EAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE;IACxC,SAAS,EAAE,QAAQ;IACnB,MAAM,EAAE;QACN,UAAU;KACX;CACF,CAAC,CAAC;AAEP;;;;;;;;;GASG;AACH,MAAM,sBAAsB,GAC1B,CAAC,UAAkB,EAAE,EAAE,CACvB,KAAK,EACH,QAAgB,EAChB,IAAY,EACZ,UAAoB,EACpB,IAA2B,EACH,EAAE,CAC1B,IAAA,oCAAe,EACb,QAAQ,EACR,IAAI,EACJ,UAAU,EACV,IAAI,IAAI;IACN,SAAS,EAAE,QAAQ;IACnB,MAAM,EAAE;QACN,UAAU;KACX;CACF,CACF,CAAC;AAEN;;;;;;GAMG;AACH,MAAM,qBAAqB,GACzB,CAAC,UAAkB,EAAE,EAAE,CACvB,CAAC,KAAa,EAAW,EAAE,CACzB,IAAA,mCAAc,EAAC,KAAK,EAAE;IACpB,SAAS,EAAE,QAAQ;IACnB,MAAM,EAAE;QACN,UAAU;KACX;CACF,CAAC,CAAC;AAEP;;;;;;;;GAQG;AACI,MAAM,gBAAgB,GAAG,CAAC,UAAkB,EAAa,EAAE,CAAC,CAAC;IAClE,OAAO,EAAE,cAAc,CAAC,UAAU,CAAC;IACnC,cAAc,EAAd,mCAAc;IACd,iBAAiB,EAAE,wBAAwB,CAAC,UAAU,CAAC;IACvD,OAAO,EAAP,4BAAO;IACP,cAAc,EAAd,mCAAc;IACd,iBAAiB,EAAjB,sCAAiB;IACjB,eAAe,EAAE,sBAAsB,CAAC,UAAU,CAAC;IACnD,cAAc,EAAE,qBAAqB,CAAC,UAAU,CAAC;IACjD,SAAS,EAAT,8BAAS;IACT,SAAS,EAAT,8BAAS;IACT,YAAY,EAAZ,iCAAY;CACb,CAAC,CAAC;AAZU,QAAA,gBAAgB,oBAY1B;AAyBU,QAAA,iBAAiB,GAG1B;IACF,IAAI,EAAE,mBAAmB;IACzB,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,EAAE,EAAE,CACtC,IAAI,sCAAiB,CAAC;QACpB,KAAK;QACL,SAAS;QACT,eAAe,EAAE,OAAO,CAAC,eAAe;QACxC,SAAS,EAAE,CAAC,OAAO,CAAC,SAAS,IAAI,IAAA,wBAAgB,EAAC,MAAO,CAAC,CAEzD;KACF,CAAC;IACJ,YAAY,EAAE,CAAC,MAAM,EAAE,EAAE,CACvB,IAAI,qBAAS,CAAC;QACZ,SAAS,EAAE,mBAAmB;QAC9B,MAAM;KACP,CAAC;CACL,CAAC","sourcesContent":["import type {\n DetailedEncryptionResult,\n EncryptionKey,\n KeyDerivationOptions,\n} from '@metamask/browser-passworder';\nimport {\n encrypt,\n encryptWithDetail,\n encryptWithKey,\n decrypt,\n decryptWithDetail,\n decryptWithKey,\n isVaultUpdated,\n keyFromPassword,\n importKey,\n exportKey,\n generateSalt,\n} from '@metamask/browser-passworder';\nimport type { Encryptor } from '@metamask/keyring-controller';\nimport {\n KeyringController,\n KeyringControllerMessenger,\n} from '@metamask/keyring-controller';\nimport { Messenger } from '@metamask/messenger';\n\nimport { InitializationConfiguration } from '../types';\n\n/**\n * A factory function for the encrypt method of the browser-passworder library,\n * that encrypts with a given number of iterations.\n *\n * @param iterations - The number of iterations to use for the PBKDF2 algorithm.\n * @returns A function that encrypts with the given number of iterations.\n */\nconst encryptFactory =\n (iterations: number) =>\n async (\n password: string,\n data: unknown,\n key?: EncryptionKey | CryptoKey,\n salt?: string,\n ): Promise<string> =>\n encrypt(password, data, key, salt, {\n algorithm: 'PBKDF2',\n params: {\n iterations,\n },\n });\n\n/**\n * A factory function for the encryptWithDetail method of the browser-passworder library,\n * that encrypts with a given number of iterations.\n *\n * @param iterations - The number of iterations to use for the PBKDF2 algorithm.\n * @returns A function that encrypts with the given number of iterations.\n */\nconst encryptWithDetailFactory =\n (iterations: number) =>\n async (\n password: string,\n object: unknown,\n salt?: string,\n ): Promise<DetailedEncryptionResult> =>\n encryptWithDetail(password, object, salt, {\n algorithm: 'PBKDF2',\n params: {\n iterations,\n },\n });\n\n/**\n * A factory function for the keyFromPassword method of the browser-passworder library,\n * that generates a key from a password and a salt.\n *\n * This factory function overrides the default key derivation options with the specified\n * number of iterations, unless existing key derivation options are passed in.\n *\n * @param iterations - The number of iterations to use for the PBKDF2 algorithm.\n * @returns A function that generates a key with a potentially overriden number of iterations.\n */\nconst keyFromPasswordFactory =\n (iterations: number) =>\n async (\n password: string,\n salt: string,\n exportable?: boolean,\n opts?: KeyDerivationOptions,\n ): Promise<EncryptionKey> =>\n keyFromPassword(\n password,\n salt,\n exportable,\n opts ?? {\n algorithm: 'PBKDF2',\n params: {\n iterations,\n },\n },\n );\n\n/**\n * A factory function for the isVaultUpdated method of the browser-passworder library,\n * that checks if the given vault was encrypted with the given number of iterations.\n *\n * @param iterations - The number of iterations to use for the PBKDF2 algorithm.\n * @returns A function that checks if the vault was encrypted with the given number of iterations.\n */\nconst isVaultUpdatedFactory =\n (iterations: number) =>\n (vault: string): boolean =>\n isVaultUpdated(vault, {\n algorithm: 'PBKDF2',\n params: {\n iterations,\n },\n });\n\n/**\n * A factory function that returns an encryptor with the given number of iterations.\n *\n * The returned encryptor is a wrapper around the browser-passworder library, that\n * calls the encrypt and encryptWithDetail methods with the given number of iterations.\n *\n * @param iterations - The number of iterations to use for the PBKDF2 algorithm.\n * @returns An encryptor set with the given number of iterations.\n */\nexport const encryptorFactory = (iterations: number): Encryptor => ({\n encrypt: encryptFactory(iterations),\n encryptWithKey,\n encryptWithDetail: encryptWithDetailFactory(iterations),\n decrypt,\n decryptWithKey,\n decryptWithDetail,\n keyFromPassword: keyFromPasswordFactory(iterations),\n isVaultUpdated: isVaultUpdatedFactory(iterations),\n importKey,\n exportKey,\n generateSalt,\n});\n\ntype MobileEncryptionKey = {\n key: string;\n lib: string;\n exportable: boolean;\n keyMetadata: KeyDerivationOptions;\n};\n\ntype MobileEncryptionResult = {\n cipher: string;\n iv: string;\n salt?: string;\n lib?: string;\n keyMetadata?: KeyDerivationOptions;\n};\n\nexport type GenericEncryptor =\n | Encryptor<EncryptionKey | CryptoKey>\n | Encryptor<\n MobileEncryptionKey,\n KeyDerivationOptions,\n MobileEncryptionResult\n >;\n\nexport const keyringController: InitializationConfiguration<\n KeyringController,\n KeyringControllerMessenger\n> = {\n name: 'KeyringController',\n init: ({ state, messenger, options }) =>\n new KeyringController({\n state,\n messenger,\n keyringBuilders: options.keyringBuilders,\n encryptor: (options.encryptor ?? encryptorFactory(600_000)) as Encryptor<\n EncryptionKey | CryptoKey\n >,\n }),\n getMessenger: (parent) =>\n new Messenger({\n namespace: 'KeyringController',\n parent,\n }),\n};\n"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { EncryptionKey, KeyDerivationOptions } from "@metamask/browser-passworder";
|
|
2
|
+
import type { Encryptor } from "@metamask/keyring-controller";
|
|
3
|
+
import { KeyringController, KeyringControllerMessenger } from "@metamask/keyring-controller";
|
|
4
|
+
import { InitializationConfiguration } from "../types.cjs";
|
|
5
|
+
/**
|
|
6
|
+
* A factory function that returns an encryptor with the given number of iterations.
|
|
7
|
+
*
|
|
8
|
+
* The returned encryptor is a wrapper around the browser-passworder library, that
|
|
9
|
+
* calls the encrypt and encryptWithDetail methods with the given number of iterations.
|
|
10
|
+
*
|
|
11
|
+
* @param iterations - The number of iterations to use for the PBKDF2 algorithm.
|
|
12
|
+
* @returns An encryptor set with the given number of iterations.
|
|
13
|
+
*/
|
|
14
|
+
export declare const encryptorFactory: (iterations: number) => Encryptor;
|
|
15
|
+
type MobileEncryptionKey = {
|
|
16
|
+
key: string;
|
|
17
|
+
lib: string;
|
|
18
|
+
exportable: boolean;
|
|
19
|
+
keyMetadata: KeyDerivationOptions;
|
|
20
|
+
};
|
|
21
|
+
type MobileEncryptionResult = {
|
|
22
|
+
cipher: string;
|
|
23
|
+
iv: string;
|
|
24
|
+
salt?: string;
|
|
25
|
+
lib?: string;
|
|
26
|
+
keyMetadata?: KeyDerivationOptions;
|
|
27
|
+
};
|
|
28
|
+
export type GenericEncryptor = Encryptor<EncryptionKey | CryptoKey> | Encryptor<MobileEncryptionKey, KeyDerivationOptions, MobileEncryptionResult>;
|
|
29
|
+
export declare const keyringController: InitializationConfiguration<KeyringController, KeyringControllerMessenger>;
|
|
30
|
+
export {};
|
|
31
|
+
//# sourceMappingURL=keyring-controller.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyring-controller.d.cts","sourceRoot":"","sources":["../../../src/initialization/instances/keyring-controller.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,aAAa,EACb,oBAAoB,EACrB,qCAAqC;AActC,OAAO,KAAK,EAAE,SAAS,EAAE,qCAAqC;AAC9D,OAAO,EACL,iBAAiB,EACjB,0BAA0B,EAC3B,qCAAqC;AAGtC,OAAO,EAAE,2BAA2B,EAAE,qBAAiB;AA4FvD;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,eAAgB,MAAM,KAAG,SAYpD,CAAC;AAEH,KAAK,mBAAmB,GAAG;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,EAAE,OAAO,CAAC;IACpB,WAAW,EAAE,oBAAoB,CAAC;CACnC,CAAC;AAEF,KAAK,sBAAsB,GAAG;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,oBAAoB,CAAC;CACpC,CAAC;AAEF,MAAM,MAAM,gBAAgB,GACxB,SAAS,CAAC,aAAa,GAAG,SAAS,CAAC,GACpC,SAAS,CACP,mBAAmB,EACnB,oBAAoB,EACpB,sBAAsB,CACvB,CAAC;AAEN,eAAO,MAAM,iBAAiB,EAAE,2BAA2B,CACzD,iBAAiB,EACjB,0BAA0B,CAiB3B,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { EncryptionKey, KeyDerivationOptions } from "@metamask/browser-passworder";
|
|
2
|
+
import type { Encryptor } from "@metamask/keyring-controller";
|
|
3
|
+
import { KeyringController, KeyringControllerMessenger } from "@metamask/keyring-controller";
|
|
4
|
+
import { InitializationConfiguration } from "../types.mjs";
|
|
5
|
+
/**
|
|
6
|
+
* A factory function that returns an encryptor with the given number of iterations.
|
|
7
|
+
*
|
|
8
|
+
* The returned encryptor is a wrapper around the browser-passworder library, that
|
|
9
|
+
* calls the encrypt and encryptWithDetail methods with the given number of iterations.
|
|
10
|
+
*
|
|
11
|
+
* @param iterations - The number of iterations to use for the PBKDF2 algorithm.
|
|
12
|
+
* @returns An encryptor set with the given number of iterations.
|
|
13
|
+
*/
|
|
14
|
+
export declare const encryptorFactory: (iterations: number) => Encryptor;
|
|
15
|
+
type MobileEncryptionKey = {
|
|
16
|
+
key: string;
|
|
17
|
+
lib: string;
|
|
18
|
+
exportable: boolean;
|
|
19
|
+
keyMetadata: KeyDerivationOptions;
|
|
20
|
+
};
|
|
21
|
+
type MobileEncryptionResult = {
|
|
22
|
+
cipher: string;
|
|
23
|
+
iv: string;
|
|
24
|
+
salt?: string;
|
|
25
|
+
lib?: string;
|
|
26
|
+
keyMetadata?: KeyDerivationOptions;
|
|
27
|
+
};
|
|
28
|
+
export type GenericEncryptor = Encryptor<EncryptionKey | CryptoKey> | Encryptor<MobileEncryptionKey, KeyDerivationOptions, MobileEncryptionResult>;
|
|
29
|
+
export declare const keyringController: InitializationConfiguration<KeyringController, KeyringControllerMessenger>;
|
|
30
|
+
export {};
|
|
31
|
+
//# sourceMappingURL=keyring-controller.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyring-controller.d.mts","sourceRoot":"","sources":["../../../src/initialization/instances/keyring-controller.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,aAAa,EACb,oBAAoB,EACrB,qCAAqC;AActC,OAAO,KAAK,EAAE,SAAS,EAAE,qCAAqC;AAC9D,OAAO,EACL,iBAAiB,EACjB,0BAA0B,EAC3B,qCAAqC;AAGtC,OAAO,EAAE,2BAA2B,EAAE,qBAAiB;AA4FvD;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,eAAgB,MAAM,KAAG,SAYpD,CAAC;AAEH,KAAK,mBAAmB,GAAG;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,EAAE,OAAO,CAAC;IACpB,WAAW,EAAE,oBAAoB,CAAC;CACnC,CAAC;AAEF,KAAK,sBAAsB,GAAG;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,oBAAoB,CAAC;CACpC,CAAC;AAEF,MAAM,MAAM,gBAAgB,GACxB,SAAS,CAAC,aAAa,GAAG,SAAS,CAAC,GACpC,SAAS,CACP,mBAAmB,EACnB,oBAAoB,EACpB,sBAAsB,CACvB,CAAC;AAEN,eAAO,MAAM,iBAAiB,EAAE,2BAA2B,CACzD,iBAAiB,EACjB,0BAA0B,CAiB3B,CAAC"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { encrypt, encryptWithDetail, encryptWithKey, decrypt, decryptWithDetail, decryptWithKey, isVaultUpdated, keyFromPassword, importKey, exportKey, generateSalt } from "@metamask/browser-passworder";
|
|
2
|
+
import { KeyringController } from "@metamask/keyring-controller";
|
|
3
|
+
import { Messenger } from "@metamask/messenger";
|
|
4
|
+
/**
|
|
5
|
+
* A factory function for the encrypt method of the browser-passworder library,
|
|
6
|
+
* that encrypts with a given number of iterations.
|
|
7
|
+
*
|
|
8
|
+
* @param iterations - The number of iterations to use for the PBKDF2 algorithm.
|
|
9
|
+
* @returns A function that encrypts with the given number of iterations.
|
|
10
|
+
*/
|
|
11
|
+
const encryptFactory = (iterations) => async (password, data, key, salt) => encrypt(password, data, key, salt, {
|
|
12
|
+
algorithm: 'PBKDF2',
|
|
13
|
+
params: {
|
|
14
|
+
iterations,
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
/**
|
|
18
|
+
* A factory function for the encryptWithDetail method of the browser-passworder library,
|
|
19
|
+
* that encrypts with a given number of iterations.
|
|
20
|
+
*
|
|
21
|
+
* @param iterations - The number of iterations to use for the PBKDF2 algorithm.
|
|
22
|
+
* @returns A function that encrypts with the given number of iterations.
|
|
23
|
+
*/
|
|
24
|
+
const encryptWithDetailFactory = (iterations) => async (password, object, salt) => encryptWithDetail(password, object, salt, {
|
|
25
|
+
algorithm: 'PBKDF2',
|
|
26
|
+
params: {
|
|
27
|
+
iterations,
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
/**
|
|
31
|
+
* A factory function for the keyFromPassword method of the browser-passworder library,
|
|
32
|
+
* that generates a key from a password and a salt.
|
|
33
|
+
*
|
|
34
|
+
* This factory function overrides the default key derivation options with the specified
|
|
35
|
+
* number of iterations, unless existing key derivation options are passed in.
|
|
36
|
+
*
|
|
37
|
+
* @param iterations - The number of iterations to use for the PBKDF2 algorithm.
|
|
38
|
+
* @returns A function that generates a key with a potentially overriden number of iterations.
|
|
39
|
+
*/
|
|
40
|
+
const keyFromPasswordFactory = (iterations) => async (password, salt, exportable, opts) => keyFromPassword(password, salt, exportable, opts ?? {
|
|
41
|
+
algorithm: 'PBKDF2',
|
|
42
|
+
params: {
|
|
43
|
+
iterations,
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
/**
|
|
47
|
+
* A factory function for the isVaultUpdated method of the browser-passworder library,
|
|
48
|
+
* that checks if the given vault was encrypted with the given number of iterations.
|
|
49
|
+
*
|
|
50
|
+
* @param iterations - The number of iterations to use for the PBKDF2 algorithm.
|
|
51
|
+
* @returns A function that checks if the vault was encrypted with the given number of iterations.
|
|
52
|
+
*/
|
|
53
|
+
const isVaultUpdatedFactory = (iterations) => (vault) => isVaultUpdated(vault, {
|
|
54
|
+
algorithm: 'PBKDF2',
|
|
55
|
+
params: {
|
|
56
|
+
iterations,
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
/**
|
|
60
|
+
* A factory function that returns an encryptor with the given number of iterations.
|
|
61
|
+
*
|
|
62
|
+
* The returned encryptor is a wrapper around the browser-passworder library, that
|
|
63
|
+
* calls the encrypt and encryptWithDetail methods with the given number of iterations.
|
|
64
|
+
*
|
|
65
|
+
* @param iterations - The number of iterations to use for the PBKDF2 algorithm.
|
|
66
|
+
* @returns An encryptor set with the given number of iterations.
|
|
67
|
+
*/
|
|
68
|
+
export const encryptorFactory = (iterations) => ({
|
|
69
|
+
encrypt: encryptFactory(iterations),
|
|
70
|
+
encryptWithKey,
|
|
71
|
+
encryptWithDetail: encryptWithDetailFactory(iterations),
|
|
72
|
+
decrypt,
|
|
73
|
+
decryptWithKey,
|
|
74
|
+
decryptWithDetail,
|
|
75
|
+
keyFromPassword: keyFromPasswordFactory(iterations),
|
|
76
|
+
isVaultUpdated: isVaultUpdatedFactory(iterations),
|
|
77
|
+
importKey,
|
|
78
|
+
exportKey,
|
|
79
|
+
generateSalt,
|
|
80
|
+
});
|
|
81
|
+
export const keyringController = {
|
|
82
|
+
name: 'KeyringController',
|
|
83
|
+
init: ({ state, messenger, options }) => new KeyringController({
|
|
84
|
+
state,
|
|
85
|
+
messenger,
|
|
86
|
+
keyringBuilders: options.keyringBuilders,
|
|
87
|
+
encryptor: (options.encryptor ?? encryptorFactory(600000)),
|
|
88
|
+
}),
|
|
89
|
+
getMessenger: (parent) => new Messenger({
|
|
90
|
+
namespace: 'KeyringController',
|
|
91
|
+
parent,
|
|
92
|
+
}),
|
|
93
|
+
};
|
|
94
|
+
//# sourceMappingURL=keyring-controller.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyring-controller.mjs","sourceRoot":"","sources":["../../../src/initialization/instances/keyring-controller.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,OAAO,EACP,iBAAiB,EACjB,cAAc,EACd,OAAO,EACP,iBAAiB,EACjB,cAAc,EACd,cAAc,EACd,eAAe,EACf,SAAS,EACT,SAAS,EACT,YAAY,EACb,qCAAqC;AAEtC,OAAO,EACL,iBAAiB,EAElB,qCAAqC;AACtC,OAAO,EAAE,SAAS,EAAE,4BAA4B;AAIhD;;;;;;GAMG;AACH,MAAM,cAAc,GAClB,CAAC,UAAkB,EAAE,EAAE,CACvB,KAAK,EACH,QAAgB,EAChB,IAAa,EACb,GAA+B,EAC/B,IAAa,EACI,EAAE,CACnB,OAAO,CAAC,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE;IACjC,SAAS,EAAE,QAAQ;IACnB,MAAM,EAAE;QACN,UAAU;KACX;CACF,CAAC,CAAC;AAEP;;;;;;GAMG;AACH,MAAM,wBAAwB,GAC5B,CAAC,UAAkB,EAAE,EAAE,CACvB,KAAK,EACH,QAAgB,EAChB,MAAe,EACf,IAAa,EACsB,EAAE,CACrC,iBAAiB,CAAC,QAAQ,EAAE,MAAM,E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AgB,CAAC,MAAO,CAAC,CAEzD;KACF,CAAC;IACJ,YAAY,EAAE,CAAC,MAAM,EAAE,EAAE,CACvB,IAAI,SAAS,CAAC;QACZ,SAAS,EAAE,mBAAmB;QAC9B,MAAM;KACP,CAAC;CACL,CAAC","sourcesContent":["import type {\n DetailedEncryptionResult,\n EncryptionKey,\n KeyDerivationOptions,\n} from '@metamask/browser-passworder';\nimport {\n encrypt,\n encryptWithDetail,\n encryptWithKey,\n decrypt,\n decryptWithDetail,\n decryptWithKey,\n isVaultUpdated,\n keyFromPassword,\n importKey,\n exportKey,\n generateSalt,\n} from '@metamask/browser-passworder';\nimport type { Encryptor } from '@metamask/keyring-controller';\nimport {\n KeyringController,\n KeyringControllerMessenger,\n} from '@metamask/keyring-controller';\nimport { Messenger } from '@metamask/messenger';\n\nimport { InitializationConfiguration } from '../types';\n\n/**\n * A factory function for the encrypt method of the browser-passworder library,\n * that encrypts with a given number of iterations.\n *\n * @param iterations - The number of iterations to use for the PBKDF2 algorithm.\n * @returns A function that encrypts with the given number of iterations.\n */\nconst encryptFactory =\n (iterations: number) =>\n async (\n password: string,\n data: unknown,\n key?: EncryptionKey | CryptoKey,\n salt?: string,\n ): Promise<string> =>\n encrypt(password, data, key, salt, {\n algorithm: 'PBKDF2',\n params: {\n iterations,\n },\n });\n\n/**\n * A factory function for the encryptWithDetail method of the browser-passworder library,\n * that encrypts with a given number of iterations.\n *\n * @param iterations - The number of iterations to use for the PBKDF2 algorithm.\n * @returns A function that encrypts with the given number of iterations.\n */\nconst encryptWithDetailFactory =\n (iterations: number) =>\n async (\n password: string,\n object: unknown,\n salt?: string,\n ): Promise<DetailedEncryptionResult> =>\n encryptWithDetail(password, object, salt, {\n algorithm: 'PBKDF2',\n params: {\n iterations,\n },\n });\n\n/**\n * A factory function for the keyFromPassword method of the browser-passworder library,\n * that generates a key from a password and a salt.\n *\n * This factory function overrides the default key derivation options with the specified\n * number of iterations, unless existing key derivation options are passed in.\n *\n * @param iterations - The number of iterations to use for the PBKDF2 algorithm.\n * @returns A function that generates a key with a potentially overriden number of iterations.\n */\nconst keyFromPasswordFactory =\n (iterations: number) =>\n async (\n password: string,\n salt: string,\n exportable?: boolean,\n opts?: KeyDerivationOptions,\n ): Promise<EncryptionKey> =>\n keyFromPassword(\n password,\n salt,\n exportable,\n opts ?? {\n algorithm: 'PBKDF2',\n params: {\n iterations,\n },\n },\n );\n\n/**\n * A factory function for the isVaultUpdated method of the browser-passworder library,\n * that checks if the given vault was encrypted with the given number of iterations.\n *\n * @param iterations - The number of iterations to use for the PBKDF2 algorithm.\n * @returns A function that checks if the vault was encrypted with the given number of iterations.\n */\nconst isVaultUpdatedFactory =\n (iterations: number) =>\n (vault: string): boolean =>\n isVaultUpdated(vault, {\n algorithm: 'PBKDF2',\n params: {\n iterations,\n },\n });\n\n/**\n * A factory function that returns an encryptor with the given number of iterations.\n *\n * The returned encryptor is a wrapper around the browser-passworder library, that\n * calls the encrypt and encryptWithDetail methods with the given number of iterations.\n *\n * @param iterations - The number of iterations to use for the PBKDF2 algorithm.\n * @returns An encryptor set with the given number of iterations.\n */\nexport const encryptorFactory = (iterations: number): Encryptor => ({\n encrypt: encryptFactory(iterations),\n encryptWithKey,\n encryptWithDetail: encryptWithDetailFactory(iterations),\n decrypt,\n decryptWithKey,\n decryptWithDetail,\n keyFromPassword: keyFromPasswordFactory(iterations),\n isVaultUpdated: isVaultUpdatedFactory(iterations),\n importKey,\n exportKey,\n generateSalt,\n});\n\ntype MobileEncryptionKey = {\n key: string;\n lib: string;\n exportable: boolean;\n keyMetadata: KeyDerivationOptions;\n};\n\ntype MobileEncryptionResult = {\n cipher: string;\n iv: string;\n salt?: string;\n lib?: string;\n keyMetadata?: KeyDerivationOptions;\n};\n\nexport type GenericEncryptor =\n | Encryptor<EncryptionKey | CryptoKey>\n | Encryptor<\n MobileEncryptionKey,\n KeyDerivationOptions,\n MobileEncryptionResult\n >;\n\nexport const keyringController: InitializationConfiguration<\n KeyringController,\n KeyringControllerMessenger\n> = {\n name: 'KeyringController',\n init: ({ state, messenger, options }) =>\n new KeyringController({\n state,\n messenger,\n keyringBuilders: options.keyringBuilders,\n encryptor: (options.encryptor ?? encryptorFactory(600_000)) as Encryptor<\n EncryptionKey | CryptoKey\n >,\n }),\n getMessenger: (parent) =>\n new Messenger({\n namespace: 'KeyringController',\n parent,\n }),\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../../src/initialization/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { InstanceSpecificOptions } from '../types';\nimport type { DefaultActions, DefaultEvents, RootMessenger } from './defaults';\n\n/**\n * Utility type for inferring the state of an instance.\n */\nexport type InstanceState<Instance> = Instance extends { state: unknown }\n ? Instance['state']\n : undefined;\n\n/**\n * Utility type for inferring the name of an instance.\n */\ntype InstanceName<Instance> = Instance extends {\n name: infer Name extends string;\n}\n ? Name\n : string;\n\n/**\n * Utility type for lower-casing the first character of an instance name, required for camel-casing.\n */\ntype LowerCaseFirstLetter<Name extends string> =\n Name extends `${infer Character1}${infer Rest}`\n ? `${Lowercase<Character1>}${Rest}`\n : Lowercase<Name>;\n\ntype CamelCaseInstanceName<Instance> = LowerCaseFirstLetter<\n InstanceName<Instance>\n>;\n\n/**\n * Utility type for narrowing the InstanceSpecificOptions to just the options required for the instance.\n */\ntype InstanceOptions<Instance> =\n CamelCaseInstanceName<Instance> extends keyof InstanceSpecificOptions\n ? NonNullable<InstanceSpecificOptions[CamelCaseInstanceName<Instance>]>\n : unknown;\n\nexport type InitFunctionArguments<Instance, InstanceMessenger> = {\n state: InstanceState<Instance> | undefined;\n messenger: InstanceMessenger;\n options: InstanceOptions<Instance>;\n};\n\nexport type InitializationConfiguration<Instance, InstanceMessenger> = {\n name: InstanceName<Instance>;\n init(args: InitFunctionArguments<Instance, InstanceMessenger>): Instance;\n getMessenger(\n parent: RootMessenger<DefaultActions, DefaultEvents>,\n ): InstanceMessenger;\n};\n"]}
|