@metamask/keyring-sdk 2.1.1 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/CHANGELOG.md +27 -2
  2. package/dist/eth/eth-4337-keyring.cjs +3 -0
  3. package/dist/eth/eth-4337-keyring.cjs.map +1 -0
  4. package/dist/eth/eth-4337-keyring.d.cts +35 -0
  5. package/dist/eth/eth-4337-keyring.d.cts.map +1 -0
  6. package/dist/eth/eth-4337-keyring.d.mts +35 -0
  7. package/dist/eth/eth-4337-keyring.d.mts.map +1 -0
  8. package/dist/eth/eth-4337-keyring.mjs +2 -0
  9. package/dist/eth/eth-4337-keyring.mjs.map +1 -0
  10. package/dist/eth/index.cjs.map +1 -1
  11. package/dist/eth/index.d.cts +1 -0
  12. package/dist/eth/index.d.cts.map +1 -1
  13. package/dist/eth/index.d.mts +1 -0
  14. package/dist/eth/index.d.mts.map +1 -1
  15. package/dist/eth/index.mjs.map +1 -1
  16. package/dist/index.cjs +1 -0
  17. package/dist/index.cjs.map +1 -1
  18. package/dist/index.d.cts +1 -0
  19. package/dist/index.d.cts.map +1 -1
  20. package/dist/index.d.mts +1 -0
  21. package/dist/index.d.mts.map +1 -1
  22. package/dist/index.mjs +1 -0
  23. package/dist/index.mjs.map +1 -1
  24. package/dist/migration.cjs +95 -0
  25. package/dist/migration.cjs.map +1 -0
  26. package/dist/migration.d.cts +124 -0
  27. package/dist/migration.d.cts.map +1 -0
  28. package/dist/migration.d.mts +124 -0
  29. package/dist/migration.d.mts.map +1 -0
  30. package/dist/migration.mjs +90 -0
  31. package/dist/migration.mjs.map +1 -0
  32. package/dist/v2/eth/eth-keyring-v1-adapter.cjs +320 -0
  33. package/dist/v2/eth/eth-keyring-v1-adapter.cjs.map +1 -0
  34. package/dist/v2/eth/eth-keyring-v1-adapter.d.cts +156 -0
  35. package/dist/v2/eth/eth-keyring-v1-adapter.d.cts.map +1 -0
  36. package/dist/v2/eth/eth-keyring-v1-adapter.d.mts +156 -0
  37. package/dist/v2/eth/eth-keyring-v1-adapter.d.mts.map +1 -0
  38. package/dist/v2/eth/eth-keyring-v1-adapter.mjs +314 -0
  39. package/dist/v2/eth/eth-keyring-v1-adapter.mjs.map +1 -0
  40. package/dist/v2/eth/index.cjs +1 -0
  41. package/dist/v2/eth/index.cjs.map +1 -1
  42. package/dist/v2/eth/index.d.cts +1 -0
  43. package/dist/v2/eth/index.d.cts.map +1 -1
  44. package/dist/v2/eth/index.d.mts +1 -0
  45. package/dist/v2/eth/index.d.mts.map +1 -1
  46. package/dist/v2/eth/index.mjs +1 -0
  47. package/dist/v2/eth/index.mjs.map +1 -1
  48. package/dist/v2/keyring-v1-adapter.cjs +5 -19
  49. package/dist/v2/keyring-v1-adapter.cjs.map +1 -1
  50. package/dist/v2/keyring-v1-adapter.d.cts +1 -1
  51. package/dist/v2/keyring-v1-adapter.d.cts.map +1 -1
  52. package/dist/v2/keyring-v1-adapter.d.mts +1 -1
  53. package/dist/v2/keyring-v1-adapter.d.mts.map +1 -1
  54. package/dist/v2/keyring-v1-adapter.mjs +5 -19
  55. package/dist/v2/keyring-v1-adapter.mjs.map +1 -1
  56. package/package.json +4 -4
@@ -0,0 +1,90 @@
1
+ import { assert, integer, is, object } from "@metamask/superstruct";
2
+ import { JsonStruct } from "@metamask/utils";
3
+ /**
4
+ * Superstruct schema for the versioned state envelope.
5
+ */
6
+ export const VersionedStateStruct = object({
7
+ version: integer(),
8
+ data: JsonStruct,
9
+ });
10
+ /**
11
+ * Type guard to check if a value is a {@link VersionedState} envelope.
12
+ *
13
+ * @param state - The value to check.
14
+ * @returns `true` if the value is a versioned state envelope.
15
+ */
16
+ export function isVersionedState(state) {
17
+ return is(state, VersionedStateStruct);
18
+ }
19
+ /**
20
+ * Get the version and data from state, treating unversioned state as version 0.
21
+ *
22
+ * @param state - The state to check.
23
+ * @returns The version and data.
24
+ */
25
+ function getVersionAndData(state) {
26
+ return isVersionedState(state)
27
+ ? { version: state.version, data: state.data }
28
+ : { version: 0, data: state };
29
+ }
30
+ /**
31
+ * Apply the pending steps of a chain to `state`.
32
+ *
33
+ * Implements {@link MigrationChain.apply} for the chain built from `steps`.
34
+ *
35
+ * @param steps - All steps of the chain.
36
+ * @param state - The serialized keyring state.
37
+ * @returns The migrated state wrapped in a versioned envelope, plus a `migrated` flag.
38
+ */
39
+ async function applySteps(steps, state) {
40
+ const latestVersion = steps.length;
41
+ const { version, data: initialData } = getVersionAndData(state);
42
+ if (version < 0) {
43
+ throw new Error(`State version ${version} is invalid; it cannot be negative`);
44
+ }
45
+ if (version > latestVersion) {
46
+ throw new Error(`State version ${version} is newer than the latest migration version ${latestVersion}`);
47
+ }
48
+ const pendingSteps = steps.slice(version);
49
+ let data = initialData;
50
+ for (const step of pendingSteps) {
51
+ assert(data, step.inputSchema ?? JsonStruct);
52
+ data = await step.migrate(data);
53
+ assert(data, step.outputSchema ?? JsonStruct);
54
+ }
55
+ return {
56
+ version: latestVersion,
57
+ data,
58
+ migrated: pendingSteps.length > 0,
59
+ };
60
+ }
61
+ /**
62
+ * Build a {@link MigrationChain} wrapping the given internal steps.
63
+ *
64
+ * @param steps - The steps accumulated so far.
65
+ * @returns A chain exposing `add`, `version`, and `apply`.
66
+ */
67
+ function buildChain(steps) {
68
+ return {
69
+ version: steps.length,
70
+ add: (step) => buildChain([...steps, step]),
71
+ apply: async (state) => applySteps(steps, state),
72
+ };
73
+ }
74
+ /**
75
+ * Start a new, empty migration chain.
76
+ *
77
+ * @example
78
+ * ```typescript
79
+ * const migrations = createMigrations()
80
+ * .add({ migrate: (data) => ({ count: data.numberOfItems }) })
81
+ * .add({ migrate: (data) => ({ ...data, createdAt: Date.now() }) }); // data typed as the first step's output, no cast
82
+ *
83
+ * const { data } = await migrations.apply(state);
84
+ * ```
85
+ * @returns An empty chain, typed to accept `Json` as its first step's input.
86
+ */
87
+ export function createMigrations() {
88
+ return buildChain([]);
89
+ }
90
+ //# sourceMappingURL=migration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K,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC1C,IAAI,IAAI,GAAG,WAAW,CAAC;IAEvB,KAAK,MAAM,IAAI,IAAI,YAAY,EAAE,CAAC;QAChC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,IAAI,UAAU,CAAC,CAAC;QAC7C,IAAI,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAChC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,YAAY,IAAI,UAAU,CAAC,CAAC;IAChD,CAAC;IAED,OAAO;QACL,OAAO,EAAE,aAAa;QACtB,IAAI;QACJ,QAAQ,EAAE,YAAY,CAAC,MAAM,GAAG,CAAC;KACT,CAAC;AAC7B,CAAC;AAED;;;;;GAKG;AACH,SAAS,UAAU,CACjB,KAA+B;IAE/B,OAAO;QACL,OAAO,EAAE,KAAK,CAAC,MAAM;QACrB,GAAG,EAAE,CACH,IAAkC,EAClC,EAAE,CAAC,UAAU,CAAS,CAAC,GAAG,KAAK,EAAE,IAAgC,CAAC,CAAC;QACrE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,UAAU,CAAO,KAAK,EAAE,KAAK,CAAC;KACvD,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,gBAAgB;IAC9B,OAAO,UAAU,CAAO,EAAE,CAAC,CAAC;AAC9B,CAAC","sourcesContent":["import type { Infer, Struct } from '@metamask/superstruct';\nimport { assert, integer, is, object } from '@metamask/superstruct';\nimport { JsonStruct } from '@metamask/utils';\nimport type { Json } from '@metamask/utils';\n\n/**\n * Superstruct schema for the versioned state envelope.\n */\nexport const VersionedStateStruct = object({\n version: integer(),\n data: JsonStruct,\n});\n\n/**\n * Versioned state envelope wrapping the actual keyring data.\n *\n * After migrations are applied, state is always wrapped in this format. `serialize()`\n * should produce this envelope so that subsequent `deserialize()` calls can detect the\n * version.\n */\nexport type VersionedState<Data extends Json = Json> = Omit<\n Infer<typeof VersionedStateStruct>,\n 'data'\n> & {\n data: Data;\n};\n\n/**\n * Return value of {@link MigrationChain.apply}.\n *\n * Extends {@link VersionedState} with a `migrated` flag that is `true` when at least\n * one step was applied during the call. Callers can use this to detect that the\n * in-memory state has been upgraded and schedule a persist so the new version is\n * written to storage, even when no other state change happens in the session.\n */\nexport type MigrationResult<Data extends Json = Json> = VersionedState<Data> & {\n migrated: boolean;\n};\n\n/**\n * Type guard to check if a value is a {@link VersionedState} envelope.\n *\n * @param state - The value to check.\n * @returns `true` if the value is a versioned state envelope.\n */\nexport function isVersionedState<State extends Json = Json>(\n state: State | VersionedState<State>,\n): state is VersionedState<State> {\n return is(state, VersionedStateStruct);\n}\n\n/**\n * Get the version and data from state, treating unversioned state as version 0.\n *\n * @param state - The state to check.\n * @returns The version and data.\n */\nfunction getVersionAndData<State extends Json = Json>(\n state: State | VersionedState<State>,\n): VersionedState<State> {\n return isVersionedState(state)\n ? { version: state.version, data: state.data }\n : { version: 0, data: state };\n}\n\n/**\n * A single migration step, added to a {@link MigrationChain} via `.add()`.\n *\n * `Input` is bound automatically to the chain's current data type when the step is\n * passed to `.add()`, so `migrate` receives a correctly typed argument with no manual\n * cast.\n */\nexport type MigrationStep<\n Input extends Json = Json,\n Output extends Json = Json,\n> = {\n /**\n * Transform state from the previous step's output to this step's output.\n *\n * Receives the raw inner data (not the versioned envelope). May be sync or async to\n * support complex operations like re-deriving data from secrets.\n *\n * @param data - The state data from the previous step.\n * @returns The migrated data.\n */\n migrate(data: Input): Output | Promise<Output>;\n /**\n * Optional schema validating this step's input before `migrate` is called. Defaults\n * to a generic JSON-shape check when omitted.\n */\n inputSchema?: Struct<Input>;\n /**\n * Optional schema validating this step's output at runtime.\n */\n outputSchema?: Struct<Output>;\n};\n\n/**\n * A chain of migration steps for evolving keyring serialized state across versions.\n *\n * Steps are versioned by position: the first `.add()` call produces version 1, the\n * second version 2, and so on. Create one with {@link createMigrations}.\n */\nexport type MigrationChain<Data extends Json = Json> = {\n /**\n * The number of steps added so far. Since steps are versioned by position starting at\n * 1, this also doubles as \"the latest version\" (use it in `serialize()`).\n */\n readonly version: number;\n /**\n * Append a step to the chain.\n *\n * Returns a new chain typed to `Output`. It does not mutate the chain it's called on,\n * so branching from a shared base chain is safe.\n *\n * `Input` defaults to the chain's current `Data` type. Providing `inputSchema` lets\n * TypeScript infer a narrower `Input` (bounded to extend `Data`), so `migrate`\n * receives a schema-typed argument when narrowing raw state into a specific shape,\n * typically on a chain's first step, where `Data` is `Json`.\n *\n * @param step - The migration step to append.\n * @returns A new chain whose data type is the step's `Output`.\n */\n add<Input extends Data = Data, Output extends Json = Json>(\n step: MigrationStep<Input, Output>,\n ): MigrationChain<Output>;\n /**\n * Apply all pending steps to `state`.\n *\n * Handles both versioned state (wrapped in `{ version, data }` envelope) and\n * unversioned legacy state (treated as version 0).\n *\n * @param state - The serialized keyring state (from vault or previous serialize).\n * @returns The migrated state wrapped in a versioned envelope, plus a `migrated`\n * flag.\n * @throws If `state`'s version is newer than this chain's latest version, or if a\n * step's `inputSchema`/`outputSchema` validation fails.\n */\n apply(state: Json): Promise<MigrationResult<Data>>;\n};\n\n/**\n * Apply the pending steps of a chain to `state`.\n *\n * Implements {@link MigrationChain.apply} for the chain built from `steps`.\n *\n * @param steps - All steps of the chain.\n * @param state - The serialized keyring state.\n * @returns The migrated state wrapped in a versioned envelope, plus a `migrated` flag.\n */\nasync function applySteps<Data extends Json>(\n steps: readonly MigrationStep[],\n state: Json,\n): Promise<MigrationResult<Data>> {\n const latestVersion = steps.length;\n const { version, data: initialData } = getVersionAndData(state);\n\n if (version < 0) {\n throw new Error(\n `State version ${version} is invalid; it cannot be negative`,\n );\n }\n\n if (version > latestVersion) {\n throw new Error(\n `State version ${version} is newer than the latest migration version ${latestVersion}`,\n );\n }\n\n const pendingSteps = steps.slice(version);\n let data = initialData;\n\n for (const step of pendingSteps) {\n assert(data, step.inputSchema ?? JsonStruct);\n data = await step.migrate(data);\n assert(data, step.outputSchema ?? JsonStruct);\n }\n\n return {\n version: latestVersion,\n data,\n migrated: pendingSteps.length > 0,\n } as MigrationResult<Data>;\n}\n\n/**\n * Build a {@link MigrationChain} wrapping the given internal steps.\n *\n * @param steps - The steps accumulated so far.\n * @returns A chain exposing `add`, `version`, and `apply`.\n */\nfunction buildChain<Data extends Json>(\n steps: readonly MigrationStep[],\n): MigrationChain<Data> {\n return {\n version: steps.length,\n add: <Input extends Data, Output extends Json>(\n step: MigrationStep<Input, Output>,\n ) => buildChain<Output>([...steps, step as unknown as MigrationStep]),\n apply: async (state) => applySteps<Data>(steps, state),\n };\n}\n\n/**\n * Start a new, empty migration chain.\n *\n * @example\n * ```typescript\n * const migrations = createMigrations()\n * .add({ migrate: (data) => ({ count: data.numberOfItems }) })\n * .add({ migrate: (data) => ({ ...data, createdAt: Date.now() }) }); // data typed as the first step's output, no cast\n *\n * const { data } = await migrations.apply(state);\n * ```\n * @returns An empty chain, typed to accept `Json` as its first step's input.\n */\nexport function createMigrations(): MigrationChain<Json> {\n return buildChain<Json>([]);\n}\n"]}
@@ -0,0 +1,320 @@
1
+ "use strict";
2
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
4
+ 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");
5
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
+ };
7
+ var _EthKeyringV1Adapter_instances, _EthKeyringV1Adapter_getAccount, _EthKeyringV1Adapter_getAccountForMethod, _EthKeyringV1Adapter_getSignTypedDataMethod, _EthKeyringV1Adapter_submitRequest;
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.EthKeyringV1Adapter = exports.EthKeyringV1MethodNotSupportedError = exports.EthKeyringV1AccountNotFoundError = void 0;
10
+ const tx_1 = require("@ethereumjs/tx");
11
+ const eth_sig_util_1 = require("@metamask/eth-sig-util");
12
+ const keyring_api_1 = require("@metamask/keyring-api");
13
+ const v2_1 = require("@metamask/keyring-api/v2");
14
+ const keyring_utils_1 = require("@metamask/keyring-utils");
15
+ const superstruct_1 = require("@metamask/superstruct");
16
+ const utils_1 = require("@metamask/utils");
17
+ const uuid_1 = require("uuid");
18
+ const keyring_v1_adapter_1 = require("../keyring-v1-adapter.cjs");
19
+ const eth_keyring_wrapper_1 = require("./eth-keyring-wrapper.cjs");
20
+ const METAMASK_ORIGIN = 'metamask';
21
+ /**
22
+ * Convert a value to a valid JSON object.
23
+ *
24
+ * The function chains JSON.stringify and JSON.parse to ensure that the result
25
+ * is a valid JSON object.
26
+ *
27
+ * We assume that the input value is JSON-serializable.
28
+ *
29
+ * However, some transformations can occur like: in objects, undefined values
30
+ * are removed, and in arrays, they are replaced with null.
31
+ *
32
+ * @param value - Value to convert to JSON - Assumed to be JSON-serializable.
33
+ * @returns JSON representation of the value.
34
+ */
35
+ function toJson(value) {
36
+ return JSON.parse(JSON.stringify(value));
37
+ }
38
+ /**
39
+ * Convert a chain ID (number or hex) to an EIP-155 CAIP chain ID string for keyring request scoping.
40
+ *
41
+ * @param chainId - The chain ID to convert.
42
+ * @returns The EIP-155 CAIP chain ID string.
43
+ */
44
+ function toEip155Scope(chainId) {
45
+ return (0, utils_1.toCaipChainId)(utils_1.KnownCaipNamespace.Eip155, BigInt(chainId).toString());
46
+ }
47
+ /**
48
+ * Error thrown when an account cannot be resolved from the requested address.
49
+ */
50
+ class EthKeyringV1AccountNotFoundError extends Error {
51
+ constructor(address) {
52
+ super(`Account not found for address: ${address}`);
53
+ this.name = 'EthKeyringV1AccountNotFoundError';
54
+ this.address = address;
55
+ Object.setPrototypeOf(this, EthKeyringV1AccountNotFoundError.prototype);
56
+ }
57
+ }
58
+ exports.EthKeyringV1AccountNotFoundError = EthKeyringV1AccountNotFoundError;
59
+ /**
60
+ * Error thrown when a resolved account does not support a requested method.
61
+ */
62
+ class EthKeyringV1MethodNotSupportedError extends Error {
63
+ constructor(method, address) {
64
+ super(`Account ${address} does not support method: ${method}`);
65
+ this.name = 'EthKeyringV1MethodNotSupportedError';
66
+ this.address = address;
67
+ this.method = method;
68
+ Object.setPrototypeOf(this, EthKeyringV1MethodNotSupportedError.prototype);
69
+ }
70
+ }
71
+ exports.EthKeyringV1MethodNotSupportedError = EthKeyringV1MethodNotSupportedError;
72
+ /**
73
+ * Adapts a `KeyringV2` instance to the subset of the legacy ETH keyring API
74
+ * used by existing ETH export and signing flows.
75
+ *
76
+ * The adapter is account-agnostic: each method resolves the requested address
77
+ * against the wrapped v2 keyring's accounts, verifies that the resolved account
78
+ * supports the requested method, then forwards the request through the v2
79
+ * `submitRequest` or `exportAccount` APIs.
80
+ */
81
+ class EthKeyringV1Adapter extends keyring_v1_adapter_1.KeyringV1Adapter {
82
+ constructor() {
83
+ super(...arguments);
84
+ _EthKeyringV1Adapter_instances.add(this);
85
+ }
86
+ /**
87
+ * Gets the private data associated with the given address so
88
+ * that it may be exported.
89
+ *
90
+ * Used by the UI to export an account.
91
+ *
92
+ * @param address - Address of the account to export.
93
+ * @returns A promise that resolves to the exported private key.
94
+ * @throws {@link EthKeyringV1AccountNotFoundError} if no account matches the
95
+ * address.
96
+ */
97
+ async exportAccount(address) {
98
+ const { account } = await __classPrivateFieldGet(this, _EthKeyringV1Adapter_instances, "m", _EthKeyringV1Adapter_getAccount).call(this, address);
99
+ if (!this.inner.exportAccount) {
100
+ throw new Error('Keyring does not support exportAccount');
101
+ }
102
+ const exportedAccount = await this.inner.exportAccount(account.id, {
103
+ type: v2_1.AccountExportType.PrivateKey,
104
+ encoding: v2_1.PrivateKeyEncoding.Hexadecimal,
105
+ });
106
+ return (0, utils_1.remove0x)(exportedAccount.privateKey);
107
+ }
108
+ /**
109
+ * Sign a transaction.
110
+ *
111
+ * @param address - Sender's address.
112
+ * @param transaction - Transaction.
113
+ * @returns A promise that resolves to the signed transaction.
114
+ * @throws {@link EthKeyringV1AccountNotFoundError} if no account matches the
115
+ * address.
116
+ * @throws {@link EthKeyringV1MethodNotSupportedError} if the account does
117
+ * not support transaction signing.
118
+ */
119
+ async signTransaction(address, transaction) {
120
+ const { account, normalizedAddress } = await __classPrivateFieldGet(this, _EthKeyringV1Adapter_instances, "m", _EthKeyringV1Adapter_getAccountForMethod).call(this, address, keyring_api_1.EthMethod.SignTransaction);
121
+ const chainId = transaction.common.chainId();
122
+ const tx = toJson({
123
+ ...transaction.toJSON(),
124
+ from: normalizedAddress,
125
+ type: `0x${transaction.type.toString(16)}`,
126
+ chainId: (0, utils_1.bigIntToHex)(chainId),
127
+ });
128
+ const signedTx = await __classPrivateFieldGet(this, _EthKeyringV1Adapter_instances, "m", _EthKeyringV1Adapter_submitRequest).call(this, account, keyring_api_1.EthMethod.SignTransaction, toJson([tx]), toEip155Scope(chainId));
129
+ // Only take the signature fields from the keyring response. This prevents
130
+ // the keyring from overwriting the transaction payload we submitted.
131
+ const signature = (0, superstruct_1.mask)(signedTx, (0, superstruct_1.object)({
132
+ r: keyring_api_1.EthBytesStrictStruct,
133
+ s: keyring_api_1.EthBytesStrictStruct,
134
+ v: keyring_api_1.EthBytesStrictStruct,
135
+ }));
136
+ return tx_1.TransactionFactory.fromTxData({
137
+ ...tx,
138
+ r: signature.r,
139
+ s: signature.s,
140
+ v: signature.v,
141
+ });
142
+ }
143
+ /**
144
+ * Sign a message.
145
+ *
146
+ * @param address - Signer's address.
147
+ * @param data - Data to sign.
148
+ * @returns A promise that resolves to the signature.
149
+ * @throws {@link EthKeyringV1AccountNotFoundError} if no account matches the
150
+ * address.
151
+ * @throws {@link EthKeyringV1MethodNotSupportedError} if the account does
152
+ * not support message signing.
153
+ */
154
+ async signMessage(address, data) {
155
+ const { account, normalizedAddress } = await __classPrivateFieldGet(this, _EthKeyringV1Adapter_instances, "m", _EthKeyringV1Adapter_getAccountForMethod).call(this, address, keyring_api_1.EthMethod.Sign);
156
+ return (0, keyring_utils_1.strictMask)(await __classPrivateFieldGet(this, _EthKeyringV1Adapter_instances, "m", _EthKeyringV1Adapter_submitRequest).call(this, account, keyring_api_1.EthMethod.Sign, toJson([normalizedAddress, data]), ''), keyring_api_1.EthBytesStruct);
157
+ }
158
+ /**
159
+ * Sign an EIP-7702 authorization.
160
+ *
161
+ * @param address - Signer's address.
162
+ * @param authorization - Authorization tuple to sign.
163
+ * @returns A promise that resolves to the signature.
164
+ * @throws {@link EthKeyringV1AccountNotFoundError} if no account matches the
165
+ * address.
166
+ * @throws {@link EthKeyringV1MethodNotSupportedError} if the account does
167
+ * not support EIP-7702 authorization signing.
168
+ */
169
+ async signEip7702Authorization(address, authorization) {
170
+ const { account } = await __classPrivateFieldGet(this, _EthKeyringV1Adapter_instances, "m", _EthKeyringV1Adapter_getAccountForMethod).call(this, address, eth_keyring_wrapper_1.EthKeyringMethod.SignEip7702Authorization);
171
+ const [chainId] = authorization;
172
+ return (0, keyring_utils_1.strictMask)(await __classPrivateFieldGet(this, _EthKeyringV1Adapter_instances, "m", _EthKeyringV1Adapter_submitRequest).call(this, account, eth_keyring_wrapper_1.EthKeyringMethod.SignEip7702Authorization, [authorization], toEip155Scope(chainId)), keyring_api_1.EthBytesStruct);
173
+ }
174
+ /**
175
+ * Sign a personal message.
176
+ *
177
+ * Note: KeyringController says this should return a Buffer but it actually
178
+ * expects a string.
179
+ *
180
+ * @param address - Signer's address.
181
+ * @param message - Data to sign.
182
+ * @returns A promise that resolves to the signature.
183
+ * @throws {@link EthKeyringV1AccountNotFoundError} if no account matches the
184
+ * address.
185
+ * @throws {@link EthKeyringV1MethodNotSupportedError} if the account does
186
+ * not support personal message signing.
187
+ */
188
+ async signPersonalMessage(address, message) {
189
+ const { account, normalizedAddress } = await __classPrivateFieldGet(this, _EthKeyringV1Adapter_instances, "m", _EthKeyringV1Adapter_getAccountForMethod).call(this, address, keyring_api_1.EthMethod.PersonalSign);
190
+ return (0, keyring_utils_1.strictMask)(await __classPrivateFieldGet(this, _EthKeyringV1Adapter_instances, "m", _EthKeyringV1Adapter_submitRequest).call(this, account, keyring_api_1.EthMethod.PersonalSign, toJson([message, normalizedAddress]), ''), keyring_api_1.EthBytesStruct);
191
+ }
192
+ /**
193
+ * Sign a typed data message.
194
+ *
195
+ * @param address - Signer's address.
196
+ * @param typedData - Typed data to sign.
197
+ * @param options - Signing options.
198
+ * @param options.version - The typed data version to use.
199
+ * @returns A promise that resolves to the signature.
200
+ * @throws {@link EthKeyringV1AccountNotFoundError} if no account matches the
201
+ * address.
202
+ * @throws {@link EthKeyringV1MethodNotSupportedError} if the account does
203
+ * not support the requested typed data signing method.
204
+ */
205
+ async signTypedData(address, typedData, options) {
206
+ const version = options?.version;
207
+ const method = __classPrivateFieldGet(this, _EthKeyringV1Adapter_instances, "m", _EthKeyringV1Adapter_getSignTypedDataMethod).call(this, version);
208
+ const { account, normalizedAddress } = await __classPrivateFieldGet(this, _EthKeyringV1Adapter_instances, "m", _EthKeyringV1Adapter_getAccountForMethod).call(this, address, method);
209
+ // Extract chain ID as if it was a typed message (as defined by EIP-712), if
210
+ // input is not a typed message, then chain ID will be undefined!
211
+ const chainId = typedData.domain?.chainId;
212
+ return (0, keyring_utils_1.strictMask)(await __classPrivateFieldGet(this, _EthKeyringV1Adapter_instances, "m", _EthKeyringV1Adapter_submitRequest).call(this, account, method, toJson([normalizedAddress, typedData]), chainId === undefined ? '' : toEip155Scope(chainId)), keyring_api_1.EthBytesStruct);
213
+ }
214
+ /**
215
+ * Convert base transactions to a base UserOperation.
216
+ *
217
+ * @param address - Address of the sender.
218
+ * @param transactions - Base transactions to include in the UserOperation.
219
+ * @param context - Keyring execution context.
220
+ * @returns A pseudo-UserOperation that can be used to construct a real one.
221
+ * @throws {@link EthKeyringV1AccountNotFoundError} if no account matches the
222
+ * address.
223
+ * @throws {@link EthKeyringV1MethodNotSupportedError} if the account does
224
+ * not support UserOperation preparation.
225
+ */
226
+ async prepareUserOperation(address, transactions, context) {
227
+ const { account } = await __classPrivateFieldGet(this, _EthKeyringV1Adapter_instances, "m", _EthKeyringV1Adapter_getAccountForMethod).call(this, address, keyring_api_1.EthMethod.PrepareUserOperation);
228
+ return (0, keyring_utils_1.strictMask)(await __classPrivateFieldGet(this, _EthKeyringV1Adapter_instances, "m", _EthKeyringV1Adapter_submitRequest).call(this, account, keyring_api_1.EthMethod.PrepareUserOperation,
229
+ // NOTE: This is inconsistent with the other methods. We are not wrapping `transactions` in an array.
230
+ // Which means the receiver of the `submitRequest` call would see individual transactions spread as
231
+ // separate params rather than a single transactions array as the first param, which doesn't match
232
+ // the method signature of `prepareUserOperation(address, transactions, context)`.
233
+ // This was already implemented like this in the legacy Snap keyring, so we keep the same logic here
234
+ // too!
235
+ toJson(transactions), toEip155Scope(context.chainId)), keyring_api_1.EthBaseUserOperationStruct);
236
+ }
237
+ /**
238
+ * Patches properties of a UserOperation. Currently, only the
239
+ * `paymasterAndData` can be patched.
240
+ *
241
+ * @param address - Address of the sender.
242
+ * @param userOperation - UserOperation to patch.
243
+ * @param context - Keyring execution context.
244
+ * @returns A patch to apply to the UserOperation.
245
+ * @throws {@link EthKeyringV1AccountNotFoundError} if no account matches the
246
+ * address.
247
+ * @throws {@link EthKeyringV1MethodNotSupportedError} if the account does
248
+ * not support UserOperation patching.
249
+ */
250
+ async patchUserOperation(address, userOperation, context) {
251
+ const { account } = await __classPrivateFieldGet(this, _EthKeyringV1Adapter_instances, "m", _EthKeyringV1Adapter_getAccountForMethod).call(this, address, keyring_api_1.EthMethod.PatchUserOperation);
252
+ return (0, keyring_utils_1.strictMask)(await __classPrivateFieldGet(this, _EthKeyringV1Adapter_instances, "m", _EthKeyringV1Adapter_submitRequest).call(this, account, keyring_api_1.EthMethod.PatchUserOperation, toJson([userOperation]), toEip155Scope(context.chainId)), keyring_api_1.EthUserOperationPatchStruct);
253
+ }
254
+ /**
255
+ * Signs a UserOperation.
256
+ *
257
+ * @param address - Address of the sender.
258
+ * @param userOperation - UserOperation to sign.
259
+ * @param context - Keyring execution context.
260
+ * @returns The signature of the UserOperation.
261
+ * @throws {@link EthKeyringV1AccountNotFoundError} if no account matches the
262
+ * address.
263
+ * @throws {@link EthKeyringV1MethodNotSupportedError} if the account does
264
+ * not support UserOperation signing.
265
+ */
266
+ async signUserOperation(address, userOperation, context) {
267
+ const { account } = await __classPrivateFieldGet(this, _EthKeyringV1Adapter_instances, "m", _EthKeyringV1Adapter_getAccountForMethod).call(this, address, keyring_api_1.EthMethod.SignUserOperation);
268
+ return (0, keyring_utils_1.strictMask)(await __classPrivateFieldGet(this, _EthKeyringV1Adapter_instances, "m", _EthKeyringV1Adapter_submitRequest).call(this, account, keyring_api_1.EthMethod.SignUserOperation, toJson([userOperation]), toEip155Scope(context.chainId)), keyring_api_1.EthBytesStruct);
269
+ }
270
+ }
271
+ exports.EthKeyringV1Adapter = EthKeyringV1Adapter;
272
+ _EthKeyringV1Adapter_instances = new WeakSet(), _EthKeyringV1Adapter_getAccount = async function _EthKeyringV1Adapter_getAccount(address) {
273
+ const normalizedAddress = (0, eth_sig_util_1.normalize)(address);
274
+ const normalizedAddressLowerCase = normalizedAddress?.toLowerCase();
275
+ if (!normalizedAddress || !normalizedAddressLowerCase) {
276
+ throw new EthKeyringV1AccountNotFoundError(address);
277
+ }
278
+ const accounts = await this.inner.getAccounts();
279
+ const account = accounts.find((keyringAccount) => {
280
+ const accountAddress = (0, eth_sig_util_1.normalize)(keyringAccount.address);
281
+ return accountAddress?.toLowerCase() === normalizedAddressLowerCase;
282
+ });
283
+ if (!account) {
284
+ throw new EthKeyringV1AccountNotFoundError(address);
285
+ }
286
+ return {
287
+ account,
288
+ normalizedAddress: normalizedAddress,
289
+ };
290
+ }, _EthKeyringV1Adapter_getAccountForMethod = async function _EthKeyringV1Adapter_getAccountForMethod(address, method) {
291
+ const resolvedAccount = await __classPrivateFieldGet(this, _EthKeyringV1Adapter_instances, "m", _EthKeyringV1Adapter_getAccount).call(this, address);
292
+ if (!resolvedAccount.account.methods.includes(method)) {
293
+ throw new EthKeyringV1MethodNotSupportedError(method, address);
294
+ }
295
+ return resolvedAccount;
296
+ }, _EthKeyringV1Adapter_getSignTypedDataMethod = function _EthKeyringV1Adapter_getSignTypedDataMethod(version) {
297
+ switch (version) {
298
+ case 'V3':
299
+ return keyring_api_1.EthMethod.SignTypedDataV3;
300
+ case 'V4':
301
+ return keyring_api_1.EthMethod.SignTypedDataV4;
302
+ case 'V1':
303
+ default:
304
+ // Use 'V1' by default to match other keyring implementations. V1 will be
305
+ // used if the version is not specified or not supported.
306
+ return keyring_api_1.EthMethod.SignTypedDataV1;
307
+ }
308
+ }, _EthKeyringV1Adapter_submitRequest = async function _EthKeyringV1Adapter_submitRequest(account, method, params, scope) {
309
+ return (await this.inner.submitRequest({
310
+ id: (0, uuid_1.v4)(),
311
+ origin: METAMASK_ORIGIN,
312
+ scope,
313
+ account: account.id,
314
+ request: {
315
+ method,
316
+ params,
317
+ },
318
+ }));
319
+ };
320
+ //# sourceMappingURL=eth-keyring-v1-adapter.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eth-keyring-v1-adapter.cjs","sourceRoot":"","sources":["../../../src/v2/eth/eth-keyring-v1-adapter.ts"],"names":[],"mappings":";;;;;;;;;AACA,uCAAoD;AAEpD,yDAAmE;AACnE,uDAM+B;AAW/B,iDAGkC;AAElC,2DAAqD;AACrD,uDAAqD;AAErD,2CAKyB;AACzB,+BAAkC;AAGlC,kEAAyD;AACzD,mEAAyD;AAEzD,MAAM,eAAe,GAAG,UAAU,CAAC;AAenC;;;;;;;;;;;;;GAaG;AACH,SAAS,MAAM,CAA2B,KAAc;IACtD,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAS,CAAC;AACnD,CAAC;AAED;;;;;GAKG;AACH,SAAS,aAAa,CAAC,OAAiC;IACtD,OAAO,IAAA,qBAAa,EAAC,0BAAkB,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,CAAC,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EAAE,EAAE,IAAA,SAAI,GAAE;QACV,MAAM,EAAE,eAAe;QACvB,KAAK;QACL,OAAO,EAAE,OAAO,CAAC,EAAE;QACnB,OAAO,EAAE;YACP,MAAM;YACN,MAAM;SACP;KACF,CAAC,CAAW,CAAC;AAChB,CAAC","sourcesContent":["import type { TypedTransaction } from '@ethereumjs/tx';\nimport { TransactionFactory } from '@ethereumjs/tx';\nimport type { SignTypedDataVersion } from '@metamask/eth-sig-util';\nimport { normalize as ethNormalize } from '@metamask/eth-sig-util';\nimport {\n EthBaseUserOperationStruct,\n EthBytesStrictStruct,\n EthBytesStruct,\n EthMethod,\n EthUserOperationPatchStruct,\n} from '@metamask/keyring-api';\nimport type {\n EthBaseTransaction,\n EthBaseUserOperation,\n EthUserOperation,\n EthUserOperationPatch,\n KeyringAccount,\n KeyringExecutionContext,\n KeyringRequest,\n} from '@metamask/keyring-api';\nimport type { Keyring as KeyringV2 } from '@metamask/keyring-api/v2';\nimport {\n AccountExportType,\n PrivateKeyEncoding,\n} from '@metamask/keyring-api/v2';\nimport type { BaseKeyring, EthKeyring } from '@metamask/keyring-utils';\nimport { strictMask } from '@metamask/keyring-utils';\nimport { mask, object } from '@metamask/superstruct';\nimport type { Hex, Json } from '@metamask/utils';\nimport {\n bigIntToHex,\n KnownCaipNamespace,\n remove0x,\n toCaipChainId,\n} from '@metamask/utils';\nimport { v4 as uuid } from 'uuid';\n\nimport type { Eth4337Keyring } from '../../eth';\nimport { KeyringV1Adapter } from '../keyring-v1-adapter';\nimport { EthKeyringMethod } from './eth-keyring-wrapper';\n\nconst METAMASK_ORIGIN = 'metamask';\n\ntype RequestParams = NonNullable<KeyringRequest['request']['params']>;\n\ntype ResolvedAccount = {\n account: KeyringAccount;\n normalizedAddress: Hex;\n};\n\ntype TypedDataWithDomain = {\n domain?: {\n chainId?: string | number;\n };\n};\n\n/**\n * Convert a value to a valid JSON object.\n *\n * The function chains JSON.stringify and JSON.parse to ensure that the result\n * is a valid JSON object.\n *\n * We assume that the input value is JSON-serializable.\n *\n * However, some transformations can occur like: in objects, undefined values\n * are removed, and in arrays, they are replaced with null.\n *\n * @param value - Value to convert to JSON - Assumed to be JSON-serializable.\n * @returns JSON representation of the value.\n */\nfunction toJson<Type extends Json = Json>(value: unknown): Type {\n return JSON.parse(JSON.stringify(value)) as Type;\n}\n\n/**\n * Convert a chain ID (number or hex) to an EIP-155 CAIP chain ID string for keyring request scoping.\n *\n * @param chainId - The chain ID to convert.\n * @returns The EIP-155 CAIP chain ID string.\n */\nfunction toEip155Scope(chainId: string | number | bigint): string {\n return toCaipChainId(KnownCaipNamespace.Eip155, BigInt(chainId).toString());\n}\n\n/**\n * Legacy ETH keyring API surface exposed by {@link EthKeyringV1Adapter}.\n */\nexport type BaseEthKeyring = BaseKeyring &\n // Only pick account-related methods (signing and exporting).\n Pick<\n EthKeyring,\n | 'exportAccount'\n | 'signMessage'\n | 'signEip7702Authorization'\n | 'signPersonalMessage'\n | 'signTypedData'\n | 'signTransaction'\n > &\n Eth4337Keyring;\n\n/**\n * Error thrown when an account cannot be resolved from the requested address.\n */\nexport class EthKeyringV1AccountNotFoundError extends Error {\n readonly address: string;\n\n constructor(address: string) {\n super(`Account not found for address: ${address}`);\n this.name = 'EthKeyringV1AccountNotFoundError';\n this.address = address;\n Object.setPrototypeOf(this, EthKeyringV1AccountNotFoundError.prototype);\n }\n}\n\n/**\n * Error thrown when a resolved account does not support a requested method.\n */\nexport class EthKeyringV1MethodNotSupportedError extends Error {\n readonly address: string;\n\n readonly method: string;\n\n constructor(method: string, address: string) {\n super(`Account ${address} does not support method: ${method}`);\n this.name = 'EthKeyringV1MethodNotSupportedError';\n this.address = address;\n this.method = method;\n Object.setPrototypeOf(this, EthKeyringV1MethodNotSupportedError.prototype);\n }\n}\n\n/**\n * Adapts a `KeyringV2` instance to the subset of the legacy ETH keyring API\n * used by existing ETH export and signing flows.\n *\n * The adapter is account-agnostic: each method resolves the requested address\n * against the wrapped v2 keyring's accounts, verifies that the resolved account\n * supports the requested method, then forwards the request through the v2\n * `submitRequest` or `exportAccount` APIs.\n */\nexport class EthKeyringV1Adapter<InnerKeyring extends KeyringV2 = KeyringV2>\n extends KeyringV1Adapter<InnerKeyring>\n implements BaseEthKeyring\n{\n /**\n * Gets the private data associated with the given address so\n * that it may be exported.\n *\n * Used by the UI to export an account.\n *\n * @param address - Address of the account to export.\n * @returns A promise that resolves to the exported private key.\n * @throws {@link EthKeyringV1AccountNotFoundError} if no account matches the\n * address.\n */\n async exportAccount(address: Hex): Promise<string> {\n const { account } = await this.#getAccount(address);\n\n if (!this.inner.exportAccount) {\n throw new Error('Keyring does not support exportAccount');\n }\n\n const exportedAccount = await this.inner.exportAccount(account.id, {\n type: AccountExportType.PrivateKey,\n encoding: PrivateKeyEncoding.Hexadecimal,\n });\n\n return remove0x(exportedAccount.privateKey);\n }\n\n /**\n * Sign a transaction.\n *\n * @param address - Sender's address.\n * @param transaction - Transaction.\n * @returns A promise that resolves to the signed transaction.\n * @throws {@link EthKeyringV1AccountNotFoundError} if no account matches the\n * address.\n * @throws {@link EthKeyringV1MethodNotSupportedError} if the account does\n * not support transaction signing.\n */\n async signTransaction(\n address: Hex,\n transaction: TypedTransaction,\n ): Promise<TypedTransaction> {\n const { account, normalizedAddress } = await this.#getAccountForMethod(\n address,\n EthMethod.SignTransaction,\n );\n\n const chainId = transaction.common.chainId();\n const tx = toJson({\n ...transaction.toJSON(),\n from: normalizedAddress,\n type: `0x${transaction.type.toString(16)}`,\n chainId: bigIntToHex(chainId),\n });\n\n const signedTx = await this.#submitRequest(\n account,\n EthMethod.SignTransaction,\n toJson<Json[]>([tx]),\n toEip155Scope(chainId),\n );\n\n // Only take the signature fields from the keyring response. This prevents\n // the keyring from overwriting the transaction payload we submitted.\n const signature = mask(\n signedTx,\n object({\n r: EthBytesStrictStruct,\n s: EthBytesStrictStruct,\n v: EthBytesStrictStruct,\n }),\n );\n\n return TransactionFactory.fromTxData({\n ...(tx as Record<string, Json>),\n r: signature.r,\n s: signature.s,\n v: signature.v,\n });\n }\n\n /**\n * Sign a message.\n *\n * @param address - Signer's address.\n * @param data - Data to sign.\n * @returns A promise that resolves to the signature.\n * @throws {@link EthKeyringV1AccountNotFoundError} if no account matches the\n * address.\n * @throws {@link EthKeyringV1MethodNotSupportedError} if the account does\n * not support message signing.\n */\n async signMessage(address: Hex, data: string): Promise<string> {\n const { account, normalizedAddress } = await this.#getAccountForMethod(\n address,\n EthMethod.Sign,\n );\n\n return strictMask(\n await this.#submitRequest(\n account,\n EthMethod.Sign,\n toJson<Json[]>([normalizedAddress, data]),\n '',\n ),\n EthBytesStruct,\n );\n }\n\n /**\n * Sign an EIP-7702 authorization.\n *\n * @param address - Signer's address.\n * @param authorization - Authorization tuple to sign.\n * @returns A promise that resolves to the signature.\n * @throws {@link EthKeyringV1AccountNotFoundError} if no account matches the\n * address.\n * @throws {@link EthKeyringV1MethodNotSupportedError} if the account does\n * not support EIP-7702 authorization signing.\n */\n async signEip7702Authorization(\n address: Hex,\n authorization: [chainId: number, contractAddress: Hex, nonce: number],\n ): Promise<string> {\n const { account } = await this.#getAccountForMethod(\n address,\n EthKeyringMethod.SignEip7702Authorization,\n );\n\n const [chainId] = authorization;\n\n return strictMask(\n await this.#submitRequest(\n account,\n EthKeyringMethod.SignEip7702Authorization,\n [authorization],\n toEip155Scope(chainId),\n ),\n EthBytesStruct,\n );\n }\n\n /**\n * Sign a personal message.\n *\n * Note: KeyringController says this should return a Buffer but it actually\n * expects a string.\n *\n * @param address - Signer's address.\n * @param message - Data to sign.\n * @returns A promise that resolves to the signature.\n * @throws {@link EthKeyringV1AccountNotFoundError} if no account matches the\n * address.\n * @throws {@link EthKeyringV1MethodNotSupportedError} if the account does\n * not support personal message signing.\n */\n async signPersonalMessage(address: Hex, message: Hex): Promise<string> {\n const { account, normalizedAddress } = await this.#getAccountForMethod(\n address,\n EthMethod.PersonalSign,\n );\n\n return strictMask(\n await this.#submitRequest(\n account,\n EthMethod.PersonalSign,\n toJson<Json[]>([message, normalizedAddress]),\n '',\n ),\n EthBytesStruct,\n );\n }\n\n /**\n * Sign a typed data message.\n *\n * @param address - Signer's address.\n * @param typedData - Typed data to sign.\n * @param options - Signing options.\n * @param options.version - The typed data version to use.\n * @returns A promise that resolves to the signature.\n * @throws {@link EthKeyringV1AccountNotFoundError} if no account matches the\n * address.\n * @throws {@link EthKeyringV1MethodNotSupportedError} if the account does\n * not support the requested typed data signing method.\n */\n async signTypedData(\n address: Hex,\n typedData: unknown[] | Record<string, unknown>,\n options?: Record<string, unknown>,\n ): Promise<string> {\n const version = options?.version as SignTypedDataVersion | undefined;\n const method = this.#getSignTypedDataMethod(version);\n const { account, normalizedAddress } = await this.#getAccountForMethod(\n address,\n method,\n );\n\n // Extract chain ID as if it was a typed message (as defined by EIP-712), if\n // input is not a typed message, then chain ID will be undefined!\n const chainId = (typedData as TypedDataWithDomain).domain?.chainId;\n\n return strictMask(\n await this.#submitRequest(\n account,\n method,\n toJson<Json[]>([normalizedAddress, typedData]),\n chainId === undefined ? '' : toEip155Scope(chainId),\n ),\n EthBytesStruct,\n );\n }\n\n /**\n * Convert base transactions to a base UserOperation.\n *\n * @param address - Address of the sender.\n * @param transactions - Base transactions to include in the UserOperation.\n * @param context - Keyring execution context.\n * @returns A pseudo-UserOperation that can be used to construct a real one.\n * @throws {@link EthKeyringV1AccountNotFoundError} if no account matches the\n * address.\n * @throws {@link EthKeyringV1MethodNotSupportedError} if the account does\n * not support UserOperation preparation.\n */\n async prepareUserOperation(\n address: string,\n transactions: EthBaseTransaction[],\n context: KeyringExecutionContext,\n ): Promise<EthBaseUserOperation> {\n const { account } = await this.#getAccountForMethod(\n address,\n EthMethod.PrepareUserOperation,\n );\n\n return strictMask(\n await this.#submitRequest(\n account,\n EthMethod.PrepareUserOperation,\n // NOTE: This is inconsistent with the other methods. We are not wrapping `transactions` in an array.\n // Which means the receiver of the `submitRequest` call would see individual transactions spread as\n // separate params rather than a single transactions array as the first param, which doesn't match\n // the method signature of `prepareUserOperation(address, transactions, context)`.\n // This was already implemented like this in the legacy Snap keyring, so we keep the same logic here\n // too!\n toJson<Json[]>(transactions),\n toEip155Scope(context.chainId),\n ),\n EthBaseUserOperationStruct,\n );\n }\n\n /**\n * Patches properties of a UserOperation. Currently, only the\n * `paymasterAndData` can be patched.\n *\n * @param address - Address of the sender.\n * @param userOperation - UserOperation to patch.\n * @param context - Keyring execution context.\n * @returns A patch to apply to the UserOperation.\n * @throws {@link EthKeyringV1AccountNotFoundError} if no account matches the\n * address.\n * @throws {@link EthKeyringV1MethodNotSupportedError} if the account does\n * not support UserOperation patching.\n */\n async patchUserOperation(\n address: string,\n userOperation: EthUserOperation,\n context: KeyringExecutionContext,\n ): Promise<EthUserOperationPatch> {\n const { account } = await this.#getAccountForMethod(\n address,\n EthMethod.PatchUserOperation,\n );\n\n return strictMask(\n await this.#submitRequest(\n account,\n EthMethod.PatchUserOperation,\n toJson<Json[]>([userOperation]),\n toEip155Scope(context.chainId),\n ),\n EthUserOperationPatchStruct,\n );\n }\n\n /**\n * Signs a UserOperation.\n *\n * @param address - Address of the sender.\n * @param userOperation - UserOperation to sign.\n * @param context - Keyring execution context.\n * @returns The signature of the UserOperation.\n * @throws {@link EthKeyringV1AccountNotFoundError} if no account matches the\n * address.\n * @throws {@link EthKeyringV1MethodNotSupportedError} if the account does\n * not support UserOperation signing.\n */\n async signUserOperation(\n address: string,\n userOperation: EthUserOperation,\n context: KeyringExecutionContext,\n ): Promise<string> {\n const { account } = await this.#getAccountForMethod(\n address,\n EthMethod.SignUserOperation,\n );\n\n return strictMask(\n await this.#submitRequest(\n account,\n EthMethod.SignUserOperation,\n toJson<Json[]>([userOperation]),\n toEip155Scope(context.chainId),\n ),\n EthBytesStruct,\n );\n }\n\n async #getAccount(address: string): Promise<ResolvedAccount> {\n const normalizedAddress = ethNormalize(address);\n const normalizedAddressLowerCase = normalizedAddress?.toLowerCase();\n\n if (!normalizedAddress || !normalizedAddressLowerCase) {\n throw new EthKeyringV1AccountNotFoundError(address);\n }\n\n const accounts = await this.inner.getAccounts();\n const account = accounts.find((keyringAccount) => {\n const accountAddress = ethNormalize(keyringAccount.address);\n return accountAddress?.toLowerCase() === normalizedAddressLowerCase;\n });\n\n if (!account) {\n throw new EthKeyringV1AccountNotFoundError(address);\n }\n\n return {\n account,\n normalizedAddress: normalizedAddress as Hex,\n };\n }\n\n async #getAccountForMethod(\n address: string,\n method: string,\n ): Promise<ResolvedAccount> {\n const resolvedAccount = await this.#getAccount(address);\n\n if (!resolvedAccount.account.methods.includes(method)) {\n throw new EthKeyringV1MethodNotSupportedError(method, address);\n }\n\n return resolvedAccount;\n }\n\n #getSignTypedDataMethod(\n version: SignTypedDataVersion | undefined,\n ): EthMethod {\n switch (version) {\n case 'V3':\n return EthMethod.SignTypedDataV3;\n case 'V4':\n return EthMethod.SignTypedDataV4;\n case 'V1':\n default:\n // Use 'V1' by default to match other keyring implementations. V1 will be\n // used if the version is not specified or not supported.\n return EthMethod.SignTypedDataV1;\n }\n }\n\n async #submitRequest<Result extends Json = Json>(\n account: KeyringAccount,\n method: string,\n params: RequestParams,\n scope: string,\n ): Promise<Result> {\n return (await this.inner.submitRequest({\n id: uuid(),\n origin: METAMASK_ORIGIN,\n scope,\n account: account.id,\n request: {\n method,\n params,\n },\n })) as Result;\n }\n}\n"]}
@@ -0,0 +1,156 @@
1
+ import type { TypedTransaction } from "@ethereumjs/tx";
2
+ import type { EthBaseTransaction, EthBaseUserOperation, EthUserOperation, EthUserOperationPatch, KeyringExecutionContext } from "@metamask/keyring-api";
3
+ import type { Keyring as KeyringV2 } from "@metamask/keyring-api/v2";
4
+ import type { BaseKeyring, EthKeyring } from "@metamask/keyring-utils";
5
+ import type { Hex } from "@metamask/utils";
6
+ import type { Eth4337Keyring } from "../../eth/index.cjs";
7
+ import { KeyringV1Adapter } from "../keyring-v1-adapter.cjs";
8
+ /**
9
+ * Legacy ETH keyring API surface exposed by {@link EthKeyringV1Adapter}.
10
+ */
11
+ export type BaseEthKeyring = BaseKeyring & Pick<EthKeyring, 'exportAccount' | 'signMessage' | 'signEip7702Authorization' | 'signPersonalMessage' | 'signTypedData' | 'signTransaction'> & Eth4337Keyring;
12
+ /**
13
+ * Error thrown when an account cannot be resolved from the requested address.
14
+ */
15
+ export declare class EthKeyringV1AccountNotFoundError extends Error {
16
+ readonly address: string;
17
+ constructor(address: string);
18
+ }
19
+ /**
20
+ * Error thrown when a resolved account does not support a requested method.
21
+ */
22
+ export declare class EthKeyringV1MethodNotSupportedError extends Error {
23
+ readonly address: string;
24
+ readonly method: string;
25
+ constructor(method: string, address: string);
26
+ }
27
+ /**
28
+ * Adapts a `KeyringV2` instance to the subset of the legacy ETH keyring API
29
+ * used by existing ETH export and signing flows.
30
+ *
31
+ * The adapter is account-agnostic: each method resolves the requested address
32
+ * against the wrapped v2 keyring's accounts, verifies that the resolved account
33
+ * supports the requested method, then forwards the request through the v2
34
+ * `submitRequest` or `exportAccount` APIs.
35
+ */
36
+ export declare class EthKeyringV1Adapter<InnerKeyring extends KeyringV2 = KeyringV2> extends KeyringV1Adapter<InnerKeyring> implements BaseEthKeyring {
37
+ #private;
38
+ /**
39
+ * Gets the private data associated with the given address so
40
+ * that it may be exported.
41
+ *
42
+ * Used by the UI to export an account.
43
+ *
44
+ * @param address - Address of the account to export.
45
+ * @returns A promise that resolves to the exported private key.
46
+ * @throws {@link EthKeyringV1AccountNotFoundError} if no account matches the
47
+ * address.
48
+ */
49
+ exportAccount(address: Hex): Promise<string>;
50
+ /**
51
+ * Sign a transaction.
52
+ *
53
+ * @param address - Sender's address.
54
+ * @param transaction - Transaction.
55
+ * @returns A promise that resolves to the signed transaction.
56
+ * @throws {@link EthKeyringV1AccountNotFoundError} if no account matches the
57
+ * address.
58
+ * @throws {@link EthKeyringV1MethodNotSupportedError} if the account does
59
+ * not support transaction signing.
60
+ */
61
+ signTransaction(address: Hex, transaction: TypedTransaction): Promise<TypedTransaction>;
62
+ /**
63
+ * Sign a message.
64
+ *
65
+ * @param address - Signer's address.
66
+ * @param data - Data to sign.
67
+ * @returns A promise that resolves to the signature.
68
+ * @throws {@link EthKeyringV1AccountNotFoundError} if no account matches the
69
+ * address.
70
+ * @throws {@link EthKeyringV1MethodNotSupportedError} if the account does
71
+ * not support message signing.
72
+ */
73
+ signMessage(address: Hex, data: string): Promise<string>;
74
+ /**
75
+ * Sign an EIP-7702 authorization.
76
+ *
77
+ * @param address - Signer's address.
78
+ * @param authorization - Authorization tuple to sign.
79
+ * @returns A promise that resolves to the signature.
80
+ * @throws {@link EthKeyringV1AccountNotFoundError} if no account matches the
81
+ * address.
82
+ * @throws {@link EthKeyringV1MethodNotSupportedError} if the account does
83
+ * not support EIP-7702 authorization signing.
84
+ */
85
+ signEip7702Authorization(address: Hex, authorization: [chainId: number, contractAddress: Hex, nonce: number]): Promise<string>;
86
+ /**
87
+ * Sign a personal message.
88
+ *
89
+ * Note: KeyringController says this should return a Buffer but it actually
90
+ * expects a string.
91
+ *
92
+ * @param address - Signer's address.
93
+ * @param message - Data to sign.
94
+ * @returns A promise that resolves to the signature.
95
+ * @throws {@link EthKeyringV1AccountNotFoundError} if no account matches the
96
+ * address.
97
+ * @throws {@link EthKeyringV1MethodNotSupportedError} if the account does
98
+ * not support personal message signing.
99
+ */
100
+ signPersonalMessage(address: Hex, message: Hex): Promise<string>;
101
+ /**
102
+ * Sign a typed data message.
103
+ *
104
+ * @param address - Signer's address.
105
+ * @param typedData - Typed data to sign.
106
+ * @param options - Signing options.
107
+ * @param options.version - The typed data version to use.
108
+ * @returns A promise that resolves to the signature.
109
+ * @throws {@link EthKeyringV1AccountNotFoundError} if no account matches the
110
+ * address.
111
+ * @throws {@link EthKeyringV1MethodNotSupportedError} if the account does
112
+ * not support the requested typed data signing method.
113
+ */
114
+ signTypedData(address: Hex, typedData: unknown[] | Record<string, unknown>, options?: Record<string, unknown>): Promise<string>;
115
+ /**
116
+ * Convert base transactions to a base UserOperation.
117
+ *
118
+ * @param address - Address of the sender.
119
+ * @param transactions - Base transactions to include in the UserOperation.
120
+ * @param context - Keyring execution context.
121
+ * @returns A pseudo-UserOperation that can be used to construct a real one.
122
+ * @throws {@link EthKeyringV1AccountNotFoundError} if no account matches the
123
+ * address.
124
+ * @throws {@link EthKeyringV1MethodNotSupportedError} if the account does
125
+ * not support UserOperation preparation.
126
+ */
127
+ prepareUserOperation(address: string, transactions: EthBaseTransaction[], context: KeyringExecutionContext): Promise<EthBaseUserOperation>;
128
+ /**
129
+ * Patches properties of a UserOperation. Currently, only the
130
+ * `paymasterAndData` can be patched.
131
+ *
132
+ * @param address - Address of the sender.
133
+ * @param userOperation - UserOperation to patch.
134
+ * @param context - Keyring execution context.
135
+ * @returns A patch to apply to the UserOperation.
136
+ * @throws {@link EthKeyringV1AccountNotFoundError} if no account matches the
137
+ * address.
138
+ * @throws {@link EthKeyringV1MethodNotSupportedError} if the account does
139
+ * not support UserOperation patching.
140
+ */
141
+ patchUserOperation(address: string, userOperation: EthUserOperation, context: KeyringExecutionContext): Promise<EthUserOperationPatch>;
142
+ /**
143
+ * Signs a UserOperation.
144
+ *
145
+ * @param address - Address of the sender.
146
+ * @param userOperation - UserOperation to sign.
147
+ * @param context - Keyring execution context.
148
+ * @returns The signature of the UserOperation.
149
+ * @throws {@link EthKeyringV1AccountNotFoundError} if no account matches the
150
+ * address.
151
+ * @throws {@link EthKeyringV1MethodNotSupportedError} if the account does
152
+ * not support UserOperation signing.
153
+ */
154
+ signUserOperation(address: string, userOperation: EthUserOperation, context: KeyringExecutionContext): Promise<string>;
155
+ }
156
+ //# sourceMappingURL=eth-keyring-v1-adapter.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eth-keyring-v1-adapter.d.cts","sourceRoot":"","sources":["../../../src/v2/eth/eth-keyring-v1-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,uBAAuB;AAWvD,OAAO,KAAK,EACV,kBAAkB,EAClB,oBAAoB,EACpB,gBAAgB,EAChB,qB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