@metamask/keyring-sdk 1.2.0 → 2.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.
Files changed (59) hide show
  1. package/CHANGELOG.md +17 -1
  2. package/LICENSE +21 -0
  3. package/dist/eth/index.cjs +0 -1
  4. package/dist/eth/index.cjs.map +1 -1
  5. package/dist/eth/index.d.cts +0 -1
  6. package/dist/eth/index.d.cts.map +1 -1
  7. package/dist/eth/index.d.mts +0 -1
  8. package/dist/eth/index.d.mts.map +1 -1
  9. package/dist/eth/index.mjs +0 -1
  10. package/dist/eth/index.mjs.map +1 -1
  11. package/dist/index.cjs +0 -1
  12. package/dist/index.cjs.map +1 -1
  13. package/dist/index.d.cts +0 -1
  14. package/dist/index.d.cts.map +1 -1
  15. package/dist/index.d.mts +0 -1
  16. package/dist/index.d.mts.map +1 -1
  17. package/dist/index.mjs +0 -1
  18. package/dist/index.mjs.map +1 -1
  19. package/dist/{eth → v2/eth}/eth-keyring-wrapper.cjs +2 -2
  20. package/dist/v2/eth/eth-keyring-wrapper.cjs.map +1 -0
  21. package/dist/{eth → v2/eth}/eth-keyring-wrapper.d.cts +1 -1
  22. package/dist/v2/eth/eth-keyring-wrapper.d.cts.map +1 -0
  23. package/dist/{eth → v2/eth}/eth-keyring-wrapper.d.mts +1 -1
  24. package/dist/v2/eth/eth-keyring-wrapper.d.mts.map +1 -0
  25. package/dist/{eth → v2/eth}/eth-keyring-wrapper.mjs +2 -2
  26. package/dist/v2/eth/eth-keyring-wrapper.mjs.map +1 -0
  27. package/dist/v2/eth/index.cjs +18 -0
  28. package/dist/v2/eth/index.cjs.map +1 -0
  29. package/dist/v2/eth/index.d.cts +2 -0
  30. package/dist/v2/eth/index.d.cts.map +1 -0
  31. package/dist/v2/eth/index.d.mts +2 -0
  32. package/dist/v2/eth/index.d.mts.map +1 -0
  33. package/dist/v2/eth/index.mjs +2 -0
  34. package/dist/v2/eth/index.mjs.map +1 -0
  35. package/dist/v2/index.cjs +19 -0
  36. package/dist/v2/index.cjs.map +1 -0
  37. package/dist/v2/index.d.cts +3 -0
  38. package/dist/v2/index.d.cts.map +1 -0
  39. package/dist/v2/index.d.mts +3 -0
  40. package/dist/v2/index.d.mts.map +1 -0
  41. package/dist/v2/index.mjs +3 -0
  42. package/dist/v2/index.mjs.map +1 -0
  43. package/dist/{keyring-wrapper.cjs → v2/keyring-wrapper.cjs} +2 -2
  44. package/dist/v2/keyring-wrapper.cjs.map +1 -0
  45. package/dist/{keyring-wrapper.d.cts → v2/keyring-wrapper.d.cts} +7 -6
  46. package/dist/v2/keyring-wrapper.d.cts.map +1 -0
  47. package/dist/{keyring-wrapper.d.mts → v2/keyring-wrapper.d.mts} +7 -6
  48. package/dist/v2/keyring-wrapper.d.mts.map +1 -0
  49. package/dist/{keyring-wrapper.mjs → v2/keyring-wrapper.mjs} +2 -2
  50. package/dist/v2/keyring-wrapper.mjs.map +1 -0
  51. package/package.json +25 -9
  52. package/dist/eth/eth-keyring-wrapper.cjs.map +0 -1
  53. package/dist/eth/eth-keyring-wrapper.d.cts.map +0 -1
  54. package/dist/eth/eth-keyring-wrapper.d.mts.map +0 -1
  55. package/dist/eth/eth-keyring-wrapper.mjs.map +0 -1
  56. package/dist/keyring-wrapper.cjs.map +0 -1
  57. package/dist/keyring-wrapper.d.cts.map +0 -1
  58. package/dist/keyring-wrapper.d.mts.map +0 -1
  59. package/dist/keyring-wrapper.mjs.map +0 -1
package/CHANGELOG.md CHANGED
@@ -7,6 +7,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [2.0.0]
11
+
12
+ ### Added
13
+
14
+ - Add `./v2` subpath export for keyring v2 building blocks ([#513](https://github.com/MetaMask/accounts/pull/513))
15
+ - `KeyringWrapper`, `EthKeyringWrapper`, `EthKeyringMethod`, and `EthKeyringWrapperOptions` are now available from `@metamask/keyring-sdk/v2`.
16
+
17
+ ### Changed
18
+
19
+ - **BREAKING:** Move `KeyringWrapper` and `EthKeyringWrapper` (and related types) to the new `./v2` subpath export ([#513](https://github.com/MetaMask/accounts/pull/513))
20
+ - Use `import { KeyringWrapper, EthKeyringWrapper, EthKeyringMethod } from '@metamask/keyring-sdk/v2'` instead.
21
+ - `KeyringAccountRegistry`, `encodeMnemonic`, and `generateEthAccountId` remain available from the main entry point.
22
+ - Bump `@metamask/utils` from `^11.10.0` to `^11.11.0` ([#483](https://github.com/MetaMask/accounts/pull/483))
23
+ - Bump `@metamask/keyring-api` from `^22.0.0` to `^23.0.0` ([#515](https://github.com/MetaMask/accounts/pull/515))
24
+
10
25
  ## [1.2.0]
11
26
 
12
27
  ### Added
@@ -30,7 +45,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
30
45
 
31
46
  - Initial release, extracted from `@metamask/keyring-api` ([#478](https://github.com/MetaMask/accounts/pull/478)), ([#482](https://github.com/MetaMask/accounts/pull/482))
32
47
 
33
- [Unreleased]: https://github.com/MetaMask/accounts/compare/@metamask/keyring-sdk@1.2.0...HEAD
48
+ [Unreleased]: https://github.com/MetaMask/accounts/compare/@metamask/keyring-sdk@2.0.0...HEAD
49
+ [2.0.0]: https://github.com/MetaMask/accounts/compare/@metamask/keyring-sdk@1.2.0...@metamask/keyring-sdk@2.0.0
34
50
  [1.2.0]: https://github.com/MetaMask/accounts/compare/@metamask/keyring-sdk@1.1.0...@metamask/keyring-sdk@1.2.0
35
51
  [1.1.0]: https://github.com/MetaMask/accounts/compare/@metamask/keyring-sdk@1.0.0...@metamask/keyring-sdk@1.1.0
36
52
  [1.0.0]: https://github.com/MetaMask/accounts/releases/tag/@metamask/keyring-sdk@1.0.0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 MetaMask
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -15,5 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./account-id.cjs"), exports);
18
- __exportStar(require("./eth-keyring-wrapper.cjs"), exports);
19
18
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/eth/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAA6B;AAC7B,4DAAsC","sourcesContent":["export * from './account-id';\nexport * from './eth-keyring-wrapper';\n"]}
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/eth/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAA6B","sourcesContent":["export * from './account-id';\n"]}
@@ -1,3 +1,2 @@
1
1
  export * from "./account-id.cjs";
2
- export * from "./eth-keyring-wrapper.cjs";
3
2
  //# sourceMappingURL=index.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../src/eth/index.ts"],"names":[],"mappings":"AAAA,iCAA6B;AAC7B,0CAAsC"}
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../src/eth/index.ts"],"names":[],"mappings":"AAAA,iCAA6B"}
@@ -1,3 +1,2 @@
1
1
  export * from "./account-id.mjs";
2
- export * from "./eth-keyring-wrapper.mjs";
3
2
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/eth/index.ts"],"names":[],"mappings":"AAAA,iCAA6B;AAC7B,0CAAsC"}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/eth/index.ts"],"names":[],"mappings":"AAAA,iCAA6B"}
@@ -1,3 +1,2 @@
1
1
  export * from "./account-id.mjs";
2
- export * from "./eth-keyring-wrapper.mjs";
3
2
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/eth/index.ts"],"names":[],"mappings":"AAAA,iCAA6B;AAC7B,0CAAsC","sourcesContent":["export * from './account-id';\nexport * from './eth-keyring-wrapper';\n"]}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/eth/index.ts"],"names":[],"mappings":"AAAA,iCAA6B","sourcesContent":["export * from './account-id';\n"]}
package/dist/index.cjs CHANGED
@@ -14,7 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./keyring-wrapper.cjs"), exports);
18
17
  __exportStar(require("./keyring-account-registry.cjs"), exports);
19
18
  __exportStar(require("./mnemonic.cjs"), exports);
20
19
  __exportStar(require("./eth/index.cjs"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wDAAkC;AAClC,iEAA2C;AAC3C,iDAA2B;AAC3B,kDAAsB","sourcesContent":["export * from './keyring-wrapper';\nexport * from './keyring-account-registry';\nexport * from './mnemonic';\nexport * from './eth';\n"]}
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iEAA2C;AAC3C,iDAA2B;AAC3B,kDAAsB","sourcesContent":["export * from './keyring-account-registry';\nexport * from './mnemonic';\nexport * from './eth';\n"]}
package/dist/index.d.cts CHANGED
@@ -1,4 +1,3 @@
1
- export * from "./keyring-wrapper.cjs";
2
1
  export * from "./keyring-account-registry.cjs";
3
2
  export * from "./mnemonic.cjs";
4
3
  export * from "./eth/index.cjs";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,sCAAkC;AAClC,+CAA2C;AAC3C,+BAA2B;AAC3B,gCAAsB"}
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,+CAA2C;AAC3C,+BAA2B;AAC3B,gCAAsB"}
package/dist/index.d.mts CHANGED
@@ -1,4 +1,3 @@
1
- export * from "./keyring-wrapper.mjs";
2
1
  export * from "./keyring-account-registry.mjs";
3
2
  export * from "./mnemonic.mjs";
4
3
  export * from "./eth/index.mjs";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,sCAAkC;AAClC,+CAA2C;AAC3C,+BAA2B;AAC3B,gCAAsB"}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,+CAA2C;AAC3C,+BAA2B;AAC3B,gCAAsB"}
package/dist/index.mjs CHANGED
@@ -1,4 +1,3 @@
1
- export * from "./keyring-wrapper.mjs";
2
1
  export * from "./keyring-account-registry.mjs";
3
2
  export * from "./mnemonic.mjs";
4
3
  export * from "./eth/index.mjs";
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,sCAAkC;AAClC,+CAA2C;AAC3C,+BAA2B;AAC3B,gCAAsB","sourcesContent":["export * from './keyring-wrapper';\nexport * from './keyring-account-registry';\nexport * from './mnemonic';\nexport * from './eth';\n"]}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,+CAA2C;AAC3C,+BAA2B;AAC3B,gCAAsB","sourcesContent":["export * from './keyring-account-registry';\nexport * from './mnemonic';\nexport * from './eth';\n"]}
@@ -6,7 +6,7 @@ const eth_sig_util_1 = require("@metamask/eth-sig-util");
6
6
  const keyring_api_1 = require("@metamask/keyring-api");
7
7
  const superstruct_1 = require("@metamask/superstruct");
8
8
  const utils_1 = require("@metamask/utils");
9
- const account_id_1 = require("./account-id.cjs");
9
+ const account_id_1 = require("../../eth/account-id.cjs");
10
10
  const keyring_wrapper_1 = require("../keyring-wrapper.cjs");
11
11
  /**
12
12
  * Additional Ethereum methods supported by Eth keyrings that are not in the standard EthMethod enum.
@@ -20,7 +20,7 @@ var EthKeyringMethod;
20
20
  EthKeyringMethod["SignEip7702Authorization"] = "eth_signEip7702Authorization";
21
21
  })(EthKeyringMethod || (exports.EthKeyringMethod = EthKeyringMethod = {}));
22
22
  /**
23
- * Abstract wrapper for Ethereum-based keyrings that extends KeyringWrapper, that itself implements KeyringV2.
23
+ * Abstract wrapper for Ethereum-based keyrings that extends KeyringWrapper, that itself implements Keyring.
24
24
  *
25
25
  * This class provides common functionality for all Ethereum keyrings including:
26
26
  * - Request handling for standard Ethereum signing methods
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eth-keyring-wrapper.cjs","sourceRoot":"","sources":["../../../src/v2/eth/eth-keyring-wrapper.ts"],"names":[],"mappings":";;;AAAA,uCAAsE;AAEtE,yDAA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AK,CAAC,gBAAgB,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;YACzD,CAAC;YAED,KAAK,GAAG,gBAAgB,CAAC,wBAAwB,EAAE,CAAC,CAAC,CAAC;gBACpD,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,wBAAwB,EAAE,CAAC;oBACzC,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;gBACvE,CAAC;gBACD,IAAA,oBAAM,EAAC,MAAM,EAAE,qDAAuC,CAAC,CAAC;gBACxD,MAAM,CAAC,aAAa,CAAC,GAAG,MAAM,CAAC;gBAC/B,OAAO,IAAI,CAAC,KAAK,CAAC,wBAAwB,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;YACxE,CAAC;YAED;gBACE,MAAM,IAAI,KAAK,CAAC,6CAA6C,MAAM,EAAE,CAAC,CAAC;QAC3E,CAAC;IACH,CAAC;CACF;AArKD,8CAqKC","sourcesContent":["import { TransactionFactory, type TypedTxData } from '@ethereumjs/tx';\nimport type { MessageTypes, TypedMessage } from '@metamask/eth-sig-util';\nimport { SignTypedDataVersion } from '@metamask/eth-sig-util';\nimport type { KeyringAccount, KeyringRequest } from '@metamask/keyring-api';\nimport {\n EthDecryptParamsStruct,\n EthGetAppKeyAddressParamsStruct,\n EthGetEncryptionPublicKeyParamsStruct,\n EthPersonalSignParamsStruct,\n EthSignEip7702AuthorizationParamsStruct,\n EthSignParamsStruct,\n EthSignTransactionParamsStruct,\n EthSignTypedDataParamsStruct,\n EthSignTypedDataV1ParamsStruct,\n EthMethod,\n} from '@metamask/keyring-api';\nimport type { EthKeyring } from '@metamask/keyring-utils';\nimport { assert } from '@metamask/superstruct';\nimport { add0x, type Hex, type Json } from '@metamask/utils';\n\nimport { generateEthAccountId } from '../../eth/account-id';\nimport { KeyringWrapper, type KeyringWrapperOptions } from '../keyring-wrapper';\n\n/**\n * Additional Ethereum methods supported by Eth keyrings that are not in the standard EthMethod enum.\n * These are primarily encryption and utility methods.\n */\nexport enum EthKeyringMethod {\n Decrypt = 'eth_decrypt',\n GetEncryptionPublicKey = 'eth_getEncryptionPublicKey',\n GetAppKeyAddress = 'eth_getAppKeyAddress',\n SignEip7702Authorization = 'eth_signEip7702Authorization',\n}\n\n/**\n * Options for constructing an {@link EthKeyringWrapper}.\n *\n * `registryOptions` is intentionally omitted: the registry is always\n * configured with {@link generateEthAccountId} to produce deterministic\n * account IDs for Ethereum addresses.\n */\nexport type EthKeyringWrapperOptions<InnerKeyring extends EthKeyring> = Omit<\n KeyringWrapperOptions<InnerKeyring>,\n 'registryOptions'\n>;\n\n/**\n * Abstract wrapper for Ethereum-based keyrings that extends KeyringWrapper, that itself implements Keyring.\n *\n * This class provides common functionality for all Ethereum keyrings including:\n * - Request handling for standard Ethereum signing methods\n * - Helper methods for Hex address conversion\n *\n * Subclasses must implement:\n * - `getAccounts()`: Return all managed accounts\n * - `createAccounts()`: Create new accounts based on options\n * - `deleteAccount()`: Remove an account from the keyring\n * - `exportAccount()` (optional): Export private key in specified format\n */\nexport abstract class EthKeyringWrapper<\n InnerKeyring extends EthKeyring,\n KeyringAccountType extends KeyringAccount = KeyringAccount,\n> extends KeyringWrapper<InnerKeyring, KeyringAccountType> {\n constructor(options: EthKeyringWrapperOptions<InnerKeyring>) {\n super({\n ...options,\n // We use a custom ID generator to ensure that account IDs are deterministic based on\n // the Ethereum address.\n registryOptions: { generateId: generateEthAccountId },\n });\n }\n\n /**\n * Helper method to safely cast a KeyringAccount address to Hex type.\n * The KeyringAccount.address is typed as string, but for Ethereum accounts\n * it should always be a valid Hex address.\n *\n * @param address - The address from a KeyringAccount.\n * @returns The address as Hex type.\n */\n protected toHexAddress(address: string): Hex {\n return add0x(address);\n }\n\n /**\n * Handle an Ethereum signing request.\n *\n * Routes the request to the appropriate legacy keyring method based on\n * the RPC method name.\n *\n * @param request - The keyring request containing method and params.\n * @returns The result of the signing operation.\n */\n async submitRequest(request: KeyringRequest): Promise<Json> {\n const { method, params } = request.request;\n\n const { address, methods } = await this.getAccount(request.account);\n const hexAddress = this.toHexAddress(address);\n\n // Validate account can handle the method\n if (!methods.includes(method)) {\n throw new Error(\n `Account ${request.account} cannot handle method: ${method}`,\n );\n }\n\n switch (method) {\n case `${EthMethod.SignTransaction}`: {\n if (!this.inner.signTransaction) {\n throw new Error('Keyring does not support signTransaction');\n }\n assert(params, EthSignTransactionParamsStruct);\n const [txData] = params;\n // Convert validated transaction data to TypedTransaction\n // TODO: Improve typing to ensure txData matches TypedTxData\n const tx = TransactionFactory.fromTxData(txData as TypedTxData);\n // Note: Bigints are not directly representable in JSON\n return (await this.inner.signTransaction(\n hexAddress,\n tx,\n )) as unknown as Json; // FIXME: Should return type be unknown?\n }\n\n case `${EthMethod.Sign}`: {\n if (!this.inner.signMessage) {\n throw new Error('Keyring does not support signMessage');\n }\n assert(params, EthSignParamsStruct);\n const [, data] = params;\n return this.inner.signMessage(hexAddress, data);\n }\n\n case `${EthMethod.PersonalSign}`: {\n if (!this.inner.signPersonalMessage) {\n throw new Error('Keyring does not support signPersonalMessage');\n }\n assert(params, EthPersonalSignParamsStruct);\n const [data] = params;\n return this.inner.signPersonalMessage(hexAddress, data as Hex);\n }\n\n case `${EthMethod.SignTypedDataV1}`: {\n if (!this.inner.signTypedData) {\n throw new Error('Keyring does not support signTypedData');\n }\n assert(params, EthSignTypedDataV1ParamsStruct);\n const [, data] = params;\n return this.inner.signTypedData(hexAddress, data, {\n version: SignTypedDataVersion.V1,\n });\n }\n\n case `${EthMethod.SignTypedDataV3}`: {\n if (!this.inner.signTypedData) {\n throw new Error('Keyring does not support signTypedData');\n }\n assert(params, EthSignTypedDataParamsStruct);\n const [, data] = params;\n return this.inner.signTypedData(\n hexAddress,\n // TODO: Improve typing to ensure data matches MessageTypes\n data as TypedMessage<MessageTypes>,\n {\n version: SignTypedDataVersion.V3,\n },\n );\n }\n\n case `${EthMethod.SignTypedDataV4}`: {\n if (!this.inner.signTypedData) {\n throw new Error('Keyring does not support signTypedData');\n }\n assert(params, EthSignTypedDataParamsStruct);\n const [, data] = params;\n return this.inner.signTypedData(\n hexAddress,\n // TODO: Improve typing to ensure data matches MessageTypes\n data as TypedMessage<MessageTypes>,\n {\n version: SignTypedDataVersion.V4,\n },\n );\n }\n\n case `${EthKeyringMethod.Decrypt}`: {\n if (!this.inner.decryptMessage) {\n throw new Error('Keyring does not support decryptMessage');\n }\n assert(params, EthDecryptParamsStruct);\n const [encryptedData] = params;\n return this.inner.decryptMessage(hexAddress, encryptedData);\n }\n\n case `${EthKeyringMethod.GetEncryptionPublicKey}`: {\n if (!this.inner.getEncryptionPublicKey) {\n throw new Error('Keyring does not support getEncryptionPublicKey');\n }\n assert(params, EthGetEncryptionPublicKeyParamsStruct);\n const [, options] = params;\n return this.inner.getEncryptionPublicKey(hexAddress, options);\n }\n\n case `${EthKeyringMethod.GetAppKeyAddress}`: {\n if (!this.inner.getAppKeyAddress) {\n throw new Error('Keyring does not support getAppKeyAddress');\n }\n assert(params, EthGetAppKeyAddressParamsStruct);\n const [origin] = params;\n return this.inner.getAppKeyAddress(hexAddress, origin);\n }\n\n case `${EthKeyringMethod.SignEip7702Authorization}`: {\n if (!this.inner.signEip7702Authorization) {\n throw new Error('Keyring does not support signEip7702Authorization');\n }\n assert(params, EthSignEip7702AuthorizationParamsStruct);\n const [authorization] = params;\n return this.inner.signEip7702Authorization(hexAddress, authorization);\n }\n\n default:\n throw new Error(`Unsupported method for EthKeyringWrapper: ${method}`);\n }\n }\n}\n"]}
@@ -21,7 +21,7 @@ export declare enum EthKeyringMethod {
21
21
  */
22
22
  export type EthKeyringWrapperOptions<InnerKeyring extends EthKeyring> = Omit<KeyringWrapperOptions<InnerKeyring>, 'registryOptions'>;
23
23
  /**
24
- * Abstract wrapper for Ethereum-based keyrings that extends KeyringWrapper, that itself implements KeyringV2.
24
+ * Abstract wrapper for Ethereum-based keyrings that extends KeyringWrapper, that itself implements Keyring.
25
25
  *
26
26
  * This class provides common functionality for all Ethereum keyrings including:
27
27
  * - Request handling for standard Ethereum signing methods
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eth-keyring-wrapper.d.cts","sourceRoot":"","sources":["../../../src/v2/eth/eth-keyring-wrapper.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,8BAA8B;AAa5E,OAAO,KAAK,EAAE,UAAU,EAAE,gCAAgC;AAE1D,OAAO,EAAS,KAAK,GAAG,EAAE,KAAK,IAAI,EAAE,wBAAwB;AAG7D,OAAO,EAAE,cAAc,EAAE,KAAK,qBAAqB,EAAE,+BAA2B;AAEhF;;;GAGG;AACH,oBAAY,gBAAgB;IAC1B,OAAO,gBAAgB;IACvB,sBAAsB,+BAA+B;IACrD,gBAAgB,yBAAyB;IACzC,wBAAwB,iCAAiC;CAC1D;AAED;;;;;;GAMG;AACH,MAAM,MAAM,wBAAwB,CAAC,YAAY,SAAS,UAAU,IAAI,IAAI,CAC1E,qBAAqB,CAAC,YAAY,CAAC,EACnC,iBAAiB,CAClB,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,8BAAsB,iBAAiB,CACrC,YAAY,SAAS,UAAU,EAC/B,kBAAkB,SAAS,cAAc,GAAG,cAAc,CAC1D,SAAQ,cAAc,CAAC,YAAY,EAAE,kBAAkB,CAAC;gBAC5C,OAAO,EAAE,wBAAwB,CAAC,YAAY,CAAC;IAS3D;;;;;;;OAOG;IACH,SAAS,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG;IAI5C;;;;;;;;OAQG;IACG,aAAa,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CAmI5D"}
@@ -21,7 +21,7 @@ export declare enum EthKeyringMethod {
21
21
  */
22
22
  export type EthKeyringWrapperOptions<InnerKeyring extends EthKeyring> = Omit<KeyringWrapperOptions<InnerKeyring>, 'registryOptions'>;
23
23
  /**
24
- * Abstract wrapper for Ethereum-based keyrings that extends KeyringWrapper, that itself implements KeyringV2.
24
+ * Abstract wrapper for Ethereum-based keyrings that extends KeyringWrapper, that itself implements Keyring.
25
25
  *
26
26
  * This class provides common functionality for all Ethereum keyrings including:
27
27
  * - Request handling for standard Ethereum signing methods
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eth-keyring-wrapper.d.mts","sourceRoot":"","sources":["../../../src/v2/eth/eth-keyring-wrapper.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,8BAA8B;AAa5E,OAAO,KAAK,EAAE,UAAU,EAAE,gCAAgC;AAE1D,OAAO,EAAS,KAAK,GAAG,EAAE,KAAK,IAAI,EAAE,wBAAwB;AAG7D,OAAO,EAAE,cAAc,EAAE,KAAK,qBAAqB,EAAE,+BAA2B;AAEhF;;;GAGG;AACH,oBAAY,gBAAgB;IAC1B,OAAO,gBAAgB;IACvB,sBAAsB,+BAA+B;IACrD,gBAAgB,yBAAyB;IACzC,wBAAwB,iCAAiC;CAC1D;AAED;;;;;;GAMG;AACH,MAAM,MAAM,wBAAwB,CAAC,YAAY,SAAS,UAAU,IAAI,IAAI,CAC1E,qBAAqB,CAAC,YAAY,CAAC,EACnC,iBAAiB,CAClB,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,8BAAsB,iBAAiB,CACrC,YAAY,SAAS,UAAU,EAC/B,kBAAkB,SAAS,cAAc,GAAG,cAAc,CAC1D,SAAQ,cAAc,CAAC,YAAY,EAAE,kBAAkB,CAAC;gBAC5C,OAAO,EAAE,wBAAwB,CAAC,YAAY,CAAC;IAS3D;;;;;;;OAOG;IACH,SAAS,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG;IAI5C;;;;;;;;OAQG;IACG,aAAa,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CAmI5D"}
@@ -3,7 +3,7 @@ import { SignTypedDataVersion } from "@metamask/eth-sig-util";
3
3
  import { EthDecryptParamsStruct, EthGetAppKeyAddressParamsStruct, EthGetEncryptionPublicKeyParamsStruct, EthPersonalSignParamsStruct, EthSignEip7702AuthorizationParamsStruct, EthSignParamsStruct, EthSignTransactionParamsStruct, EthSignTypedDataParamsStruct, EthSignTypedDataV1ParamsStruct, EthMethod } from "@metamask/keyring-api";
4
4
  import { assert } from "@metamask/superstruct";
5
5
  import { add0x } from "@metamask/utils";
6
- import { generateEthAccountId } from "./account-id.mjs";
6
+ import { generateEthAccountId } from "../../eth/account-id.mjs";
7
7
  import { KeyringWrapper } from "../keyring-wrapper.mjs";
8
8
  /**
9
9
  * Additional Ethereum methods supported by Eth keyrings that are not in the standard EthMethod enum.
@@ -17,7 +17,7 @@ export var EthKeyringMethod;
17
17
  EthKeyringMethod["SignEip7702Authorization"] = "eth_signEip7702Authorization";
18
18
  })(EthKeyringMethod || (EthKeyringMethod = {}));
19
19
  /**
20
- * Abstract wrapper for Ethereum-based keyrings that extends KeyringWrapper, that itself implements KeyringV2.
20
+ * Abstract wrapper for Ethereum-based keyrings that extends KeyringWrapper, that itself implements Keyring.
21
21
  *
22
22
  * This class provides common functionality for all Ethereum keyrings including:
23
23
  * - Request handling for standard Ethereum signing methods
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eth-keyring-wrapper.mjs","sourceRoot":"","sources":["../../../src/v2/eth/eth-keyring-wrapper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAoB,uBAAuB;AAEtE,OAAO,EAAE,oBAAoB,EAAE,+BAA+B;AAE9D,OAAO,EACL,sBAAsB,EACtB,+BAA+B,EAC/B,qCAAqC,EACrC,2BAA2B,EAC3B,uCAAuC,EACvC,mBAAmB,EACnB,8BAA8B,EAC9B,4BAA4B,EAC5B,8BAA8B,EAC9B,SAAS,EACV,8BAA8B;AAE/B,OAAO,EAAE,MAAM,EAAE,8BAA8B;AAC/C,OAAO,EAAE,KAAK,EAAuB,wBAAwB;AAE7D,OAAO,EAAE,oBAAoB,EAAE,iCAA6B;AAC5D,OAAO,EAAE,cAAc,EAA8B,+BAA2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,CAAC,IAAI,CAAC,KAAK,CAAC,wBAAwB,EAAE,CAAC;oBACzC,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;gBACvE,CAAC;gBACD,MAAM,CAAC,MAAM,EAAE,uCAAuC,CAAC,CAAC;gBACxD,MAAM,CAAC,aAAa,CAAC,GAAG,MAAM,CAAC;gBAC/B,OAAO,IAAI,CAAC,KAAK,CAAC,wBAAwB,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;YACxE,CAAC;YAED;gBACE,MAAM,IAAI,KAAK,CAAC,6CAA6C,MAAM,EAAE,CAAC,CAAC;QAC3E,CAAC;IACH,CAAC;CACF","sourcesContent":["import { TransactionFactory, type TypedTxData } from '@ethereumjs/tx';\nimport type { MessageTypes, TypedMessage } from '@metamask/eth-sig-util';\nimport { SignTypedDataVersion } from '@metamask/eth-sig-util';\nimport type { KeyringAccount, KeyringRequest } from '@metamask/keyring-api';\nimport {\n EthDecryptParamsStruct,\n EthGetAppKeyAddressParamsStruct,\n EthGetEncryptionPublicKeyParamsStruct,\n EthPersonalSignParamsStruct,\n EthSignEip7702AuthorizationParamsStruct,\n EthSignParamsStruct,\n EthSignTransactionParamsStruct,\n EthSignTypedDataParamsStruct,\n EthSignTypedDataV1ParamsStruct,\n EthMethod,\n} from '@metamask/keyring-api';\nimport type { EthKeyring } from '@metamask/keyring-utils';\nimport { assert } from '@metamask/superstruct';\nimport { add0x, type Hex, type Json } from '@metamask/utils';\n\nimport { generateEthAccountId } from '../../eth/account-id';\nimport { KeyringWrapper, type KeyringWrapperOptions } from '../keyring-wrapper';\n\n/**\n * Additional Ethereum methods supported by Eth keyrings that are not in the standard EthMethod enum.\n * These are primarily encryption and utility methods.\n */\nexport enum EthKeyringMethod {\n Decrypt = 'eth_decrypt',\n GetEncryptionPublicKey = 'eth_getEncryptionPublicKey',\n GetAppKeyAddress = 'eth_getAppKeyAddress',\n SignEip7702Authorization = 'eth_signEip7702Authorization',\n}\n\n/**\n * Options for constructing an {@link EthKeyringWrapper}.\n *\n * `registryOptions` is intentionally omitted: the registry is always\n * configured with {@link generateEthAccountId} to produce deterministic\n * account IDs for Ethereum addresses.\n */\nexport type EthKeyringWrapperOptions<InnerKeyring extends EthKeyring> = Omit<\n KeyringWrapperOptions<InnerKeyring>,\n 'registryOptions'\n>;\n\n/**\n * Abstract wrapper for Ethereum-based keyrings that extends KeyringWrapper, that itself implements Keyring.\n *\n * This class provides common functionality for all Ethereum keyrings including:\n * - Request handling for standard Ethereum signing methods\n * - Helper methods for Hex address conversion\n *\n * Subclasses must implement:\n * - `getAccounts()`: Return all managed accounts\n * - `createAccounts()`: Create new accounts based on options\n * - `deleteAccount()`: Remove an account from the keyring\n * - `exportAccount()` (optional): Export private key in specified format\n */\nexport abstract class EthKeyringWrapper<\n InnerKeyring extends EthKeyring,\n KeyringAccountType extends KeyringAccount = KeyringAccount,\n> extends KeyringWrapper<InnerKeyring, KeyringAccountType> {\n constructor(options: EthKeyringWrapperOptions<InnerKeyring>) {\n super({\n ...options,\n // We use a custom ID generator to ensure that account IDs are deterministic based on\n // the Ethereum address.\n registryOptions: { generateId: generateEthAccountId },\n });\n }\n\n /**\n * Helper method to safely cast a KeyringAccount address to Hex type.\n * The KeyringAccount.address is typed as string, but for Ethereum accounts\n * it should always be a valid Hex address.\n *\n * @param address - The address from a KeyringAccount.\n * @returns The address as Hex type.\n */\n protected toHexAddress(address: string): Hex {\n return add0x(address);\n }\n\n /**\n * Handle an Ethereum signing request.\n *\n * Routes the request to the appropriate legacy keyring method based on\n * the RPC method name.\n *\n * @param request - The keyring request containing method and params.\n * @returns The result of the signing operation.\n */\n async submitRequest(request: KeyringRequest): Promise<Json> {\n const { method, params } = request.request;\n\n const { address, methods } = await this.getAccount(request.account);\n const hexAddress = this.toHexAddress(address);\n\n // Validate account can handle the method\n if (!methods.includes(method)) {\n throw new Error(\n `Account ${request.account} cannot handle method: ${method}`,\n );\n }\n\n switch (method) {\n case `${EthMethod.SignTransaction}`: {\n if (!this.inner.signTransaction) {\n throw new Error('Keyring does not support signTransaction');\n }\n assert(params, EthSignTransactionParamsStruct);\n const [txData] = params;\n // Convert validated transaction data to TypedTransaction\n // TODO: Improve typing to ensure txData matches TypedTxData\n const tx = TransactionFactory.fromTxData(txData as TypedTxData);\n // Note: Bigints are not directly representable in JSON\n return (await this.inner.signTransaction(\n hexAddress,\n tx,\n )) as unknown as Json; // FIXME: Should return type be unknown?\n }\n\n case `${EthMethod.Sign}`: {\n if (!this.inner.signMessage) {\n throw new Error('Keyring does not support signMessage');\n }\n assert(params, EthSignParamsStruct);\n const [, data] = params;\n return this.inner.signMessage(hexAddress, data);\n }\n\n case `${EthMethod.PersonalSign}`: {\n if (!this.inner.signPersonalMessage) {\n throw new Error('Keyring does not support signPersonalMessage');\n }\n assert(params, EthPersonalSignParamsStruct);\n const [data] = params;\n return this.inner.signPersonalMessage(hexAddress, data as Hex);\n }\n\n case `${EthMethod.SignTypedDataV1}`: {\n if (!this.inner.signTypedData) {\n throw new Error('Keyring does not support signTypedData');\n }\n assert(params, EthSignTypedDataV1ParamsStruct);\n const [, data] = params;\n return this.inner.signTypedData(hexAddress, data, {\n version: SignTypedDataVersion.V1,\n });\n }\n\n case `${EthMethod.SignTypedDataV3}`: {\n if (!this.inner.signTypedData) {\n throw new Error('Keyring does not support signTypedData');\n }\n assert(params, EthSignTypedDataParamsStruct);\n const [, data] = params;\n return this.inner.signTypedData(\n hexAddress,\n // TODO: Improve typing to ensure data matches MessageTypes\n data as TypedMessage<MessageTypes>,\n {\n version: SignTypedDataVersion.V3,\n },\n );\n }\n\n case `${EthMethod.SignTypedDataV4}`: {\n if (!this.inner.signTypedData) {\n throw new Error('Keyring does not support signTypedData');\n }\n assert(params, EthSignTypedDataParamsStruct);\n const [, data] = params;\n return this.inner.signTypedData(\n hexAddress,\n // TODO: Improve typing to ensure data matches MessageTypes\n data as TypedMessage<MessageTypes>,\n {\n version: SignTypedDataVersion.V4,\n },\n );\n }\n\n case `${EthKeyringMethod.Decrypt}`: {\n if (!this.inner.decryptMessage) {\n throw new Error('Keyring does not support decryptMessage');\n }\n assert(params, EthDecryptParamsStruct);\n const [encryptedData] = params;\n return this.inner.decryptMessage(hexAddress, encryptedData);\n }\n\n case `${EthKeyringMethod.GetEncryptionPublicKey}`: {\n if (!this.inner.getEncryptionPublicKey) {\n throw new Error('Keyring does not support getEncryptionPublicKey');\n }\n assert(params, EthGetEncryptionPublicKeyParamsStruct);\n const [, options] = params;\n return this.inner.getEncryptionPublicKey(hexAddress, options);\n }\n\n case `${EthKeyringMethod.GetAppKeyAddress}`: {\n if (!this.inner.getAppKeyAddress) {\n throw new Error('Keyring does not support getAppKeyAddress');\n }\n assert(params, EthGetAppKeyAddressParamsStruct);\n const [origin] = params;\n return this.inner.getAppKeyAddress(hexAddress, origin);\n }\n\n case `${EthKeyringMethod.SignEip7702Authorization}`: {\n if (!this.inner.signEip7702Authorization) {\n throw new Error('Keyring does not support signEip7702Authorization');\n }\n assert(params, EthSignEip7702AuthorizationParamsStruct);\n const [authorization] = params;\n return this.inner.signEip7702Authorization(hexAddress, authorization);\n }\n\n default:\n throw new Error(`Unsupported method for EthKeyringWrapper: ${method}`);\n }\n }\n}\n"]}
@@ -0,0 +1,18 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./eth-keyring-wrapper.cjs"), exports);
18
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../src/v2/eth/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4DAAsC","sourcesContent":["export * from './eth-keyring-wrapper';\n"]}
@@ -0,0 +1,2 @@
1
+ export * from "./eth-keyring-wrapper.cjs";
2
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../src/v2/eth/index.ts"],"names":[],"mappings":"AAAA,0CAAsC"}
@@ -0,0 +1,2 @@
1
+ export * from "./eth-keyring-wrapper.mjs";
2
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/v2/eth/index.ts"],"names":[],"mappings":"AAAA,0CAAsC"}
@@ -0,0 +1,2 @@
1
+ export * from "./eth-keyring-wrapper.mjs";
2
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../src/v2/eth/index.ts"],"names":[],"mappings":"AAAA,0CAAsC","sourcesContent":["export * from './eth-keyring-wrapper';\n"]}
@@ -0,0 +1,19 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./keyring-wrapper.cjs"), exports);
18
+ __exportStar(require("./eth/index.cjs"), exports);
19
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/v2/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wDAAkC;AAClC,kDAAsB","sourcesContent":["export * from './keyring-wrapper';\nexport * from './eth';\n"]}
@@ -0,0 +1,3 @@
1
+ export * from "./keyring-wrapper.cjs";
2
+ export * from "./eth/index.cjs";
3
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../src/v2/index.ts"],"names":[],"mappings":"AAAA,sCAAkC;AAClC,gCAAsB"}
@@ -0,0 +1,3 @@
1
+ export * from "./keyring-wrapper.mjs";
2
+ export * from "./eth/index.mjs";
3
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/v2/index.ts"],"names":[],"mappings":"AAAA,sCAAkC;AAClC,gCAAsB"}
@@ -0,0 +1,3 @@
1
+ export * from "./keyring-wrapper.mjs";
2
+ export * from "./eth/index.mjs";
3
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/v2/index.ts"],"names":[],"mappings":"AAAA,sCAAkC;AAClC,gCAAsB","sourcesContent":["export * from './keyring-wrapper';\nexport * from './eth';\n"]}
@@ -14,10 +14,10 @@ var _KeyringWrapper_capabilities, _KeyringWrapper_lock;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.KeyringWrapper = void 0;
16
16
  const async_mutex_1 = require("async-mutex");
17
- const keyring_account_registry_1 = require("./keyring-account-registry.cjs");
17
+ const keyring_account_registry_1 = require("../keyring-account-registry.cjs");
18
18
  /**
19
19
  * Generic adapter that turns an existing {@link Keyring} implementation into a
20
- * {@link KeyringV2} instance.
20
+ * {@link Keyring} instance.
21
21
  *
22
22
  * Consumers are expected to provide concrete mappings between high-level V2
23
23
  * operations and the underlying keyring methods (for example BIP-44 account
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyring-wrapper.cjs","sourceRoot":"","sources":["../../src/v2/keyring-wrapper.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAcA,6CAAoC;AAEpC,8EAGqC;AA2BrC;;;;;;;;;GASG;AACH,MAAsB,cAAc;IA0BlC,YAAY,OAA4C;QAnB/C,+CAAmC;QAI5C;;;WAGG;QACM,+BAAQ,IAAI,mBAAK,EAAE,EAAC;QAY3B,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;QAC9B,uBAAA,IAAI,gCAAiB,OAAO,CAAC,YAAY,MAAA,CAAC;QAC1C,IAAI,CAAC,QAAQ,GAAG,IAAI,iDAAsB,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;IACtE,CAAC;IAED;;;;;;;OAOG;IACH,IAAI,YAAY;QACd,OAAO,uBAAA,IAAI,oCAAc,CAAC;IAC5B,CAAC;IAED;;;;;;;;;;;;OAYG;IACO,KAAK,CAAC,QAAQ,CACtB,QAA+B;QAE/B,OAAO,uBAAA,IAAI,4BAAM,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;IAC3C,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,SAAS;QACb,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC;IAChC,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,WAAW,CAAC,KAAW;QAC3B,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,IAAI,EAAE;YAC7B,wCAAwC;YACxC,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;YAEtB,iCAAiC;YACjC,MAAM,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;YAEpC,iDAAiD;YACjD,yEAAyE;YACzE,8DAA8D;YAC9D,MAAM,IAAI,CAAC,WAAW,EAAE,CAAC;QAC3B,CAAC,CAAC,CAAC;IACL,CAAC;IAgBD;;;;;;;;;OASG;IACH,KAAK,CAAC,UAAU,CAAC,SAAoB;QACnC,IAAI,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAC1C,IAAI,MAAM,EAAE,CAAC;YACX,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,4CAA4C;QAC5C,MAAM,IAAI,CAAC,WAAW,EAAE,CAAC;QAEzB,mCAAmC;QACnC,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QACtC,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CAAC,6BAA6B,SAAS,EAAE,CAAC,CAAC;QAC5D,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CA+CF;AA3LD,wCA2LC","sourcesContent":["import type { KeyringAccount, KeyringRequest } from '@metamask/keyring-api';\nimport type {\n CreateAccountOptions,\n ExportAccountOptions,\n ExportedAccount,\n Keyring,\n KeyringCapabilities,\n KeyringType,\n} from '@metamask/keyring-api/v2';\nimport type {\n Keyring as LegacyKeyring,\n AccountId,\n} from '@metamask/keyring-utils';\nimport type { Json } from '@metamask/utils';\nimport { Mutex } from 'async-mutex';\n\nimport {\n KeyringAccountRegistry,\n type KeyringAccountRegistryOptions,\n} from '../keyring-account-registry';\n\n/**\n * Basic options for constructing a {@link KeyringWrapper}.\n */\nexport type KeyringWrapperOptions<InnerKeyring extends LegacyKeyring> = {\n /**\n * The underlying \"old\" keyring instance that this wrapper adapts.\n */\n inner: InnerKeyring;\n\n /**\n * The concrete keyring type exposed through the V2 interface.\n */\n type: KeyringType;\n\n /**\n * Capabilities of the underlying keyring.\n */\n capabilities: KeyringCapabilities;\n\n /**\n * Options forwarded to the {@link KeyringAccountRegistry} constructor.\n */\n registryOptions?: KeyringAccountRegistryOptions;\n};\n\n/**\n * Generic adapter that turns an existing {@link Keyring} implementation into a\n * {@link Keyring} instance.\n *\n * Consumers are expected to provide concrete mappings between high-level V2\n * operations and the underlying keyring methods (for example BIP-44 account\n * creation, private-key import, and request handling). This class focuses on\n * the common mechanics required by all adapters: state serialization,\n * account-ID/address mapping and basic account management.\n */\nexport abstract class KeyringWrapper<\n InnerKeyring extends LegacyKeyring,\n KeyringAccountType extends KeyringAccount = KeyringAccount,\n> implements Keyring\n{\n readonly type: `${KeyringType}`;\n\n readonly #capabilities: KeyringCapabilities;\n\n protected readonly inner: InnerKeyring;\n\n /**\n * Mutex to ensure exclusive access to the inner keyring during\n * operations that mutate its state.\n */\n readonly #lock = new Mutex();\n\n /**\n * Registry for KeyringAccount objects.\n * Provides O(1) lookups by AccountId or address.\n *\n * Subclasses should use this registry when creating accounts and\n * clear/update it when deleting accounts or deserializing state.\n */\n protected readonly registry: KeyringAccountRegistry<KeyringAccountType>;\n\n constructor(options: KeyringWrapperOptions<InnerKeyring>) {\n this.inner = options.inner;\n this.type = `${options.type}`;\n this.#capabilities = options.capabilities;\n this.registry = new KeyringAccountRegistry(options.registryOptions);\n }\n\n /**\n * Get the capabilities of this keyring.\n *\n * Subclasses can override this getter to return capabilities dynamically\n * based on runtime state.\n *\n * @returns The keyring's capabilities.\n */\n get capabilities(): KeyringCapabilities {\n return this.#capabilities;\n }\n\n /**\n * Execute an operation with exclusive access to the inner keyring.\n *\n * This method ensures thread-safety for operations that read or mutate\n * the inner keyring state. All operations that modify the keyring\n * (createAccounts, deleteAccount, deserialize) should use this method\n * to prevent race conditions.\n *\n * Within the callback, use `this.inner` to access the inner keyring.\n *\n * @param callback - A function that performs the operation.\n * @returns The result of the callback.\n */\n protected async withLock<Result>(\n callback: () => Promise<Result>,\n ): Promise<Result> {\n return this.#lock.runExclusive(callback);\n }\n\n /**\n * Serialize the underlying keyring state to a JSON-serializable object.\n *\n * This simply delegates to the legacy keyring's {@link Keyring.serialize}\n * implementation.\n *\n * @returns The serialized keyring state.\n */\n async serialize(): Promise<Json> {\n return this.inner.serialize();\n }\n\n /**\n * Hydrate the underlying keyring from a previously serialized state.\n *\n * This clears the registry, delegates to the legacy keyring's\n * {@link Keyring.deserialize} implementation, and rebuilds the registry\n * by calling {@link getAccounts}.\n *\n * @param state - The serialized keyring state.\n */\n async deserialize(state: Json): Promise<void> {\n await this.withLock(async () => {\n // Clear the registry when deserializing\n this.registry.clear();\n\n // Deserialize the legacy keyring\n await this.inner.deserialize(state);\n\n // Rebuild the registry by calling getAccounts().\n // Subclass implementations of getAccounts() should populate the registry\n // as a side effect (see the abstract method's documentation).\n await this.getAccounts();\n });\n }\n\n /**\n * Return all accounts managed by this keyring.\n *\n * Concrete adapters are responsible for mapping the underlying keyring's\n * notion of accounts (typically addresses returned by\n * {@link Keyring.getAccounts}) into {@link KeyringAccount} objects.\n * Implementations should use the configured {@link KeyringAccountRegistry}\n * to establish the account ID/address mapping so that\n * {@link getAccount} works as expected.\n *\n * @returns The list of managed accounts.\n */\n abstract getAccounts(): Promise<KeyringAccount[]>;\n\n /**\n * Look up a single account by its {@link AccountId}.\n *\n * This method first checks the registry for O(1) lookup.\n * If not found, it falls back to calling {@link getAccounts} which\n * should populate the registry as a side effect.\n *\n * @param accountId - The AccountId to look up.\n * @returns The matching KeyringAccount.\n */\n async getAccount(accountId: AccountId): Promise<KeyringAccount> {\n let cached = this.registry.get(accountId);\n if (cached) {\n return cached;\n }\n\n // Prime the registry by calling getAccounts\n await this.getAccounts();\n\n // Try registry again after priming\n cached = this.registry.get(accountId);\n if (!cached) {\n throw new Error(`Account not found for id: ${accountId}`);\n }\n\n return cached;\n }\n\n /**\n * Create one or more new accounts managed by this keyring.\n *\n * Implementations are responsible for interpreting the\n * {@link CreateAccountOptions} (for example BIP-44 derivation or\n * private-key import) and returning the resulting {@link KeyringAccount}\n * objects. Implementors should also ensure that the registry is updated so\n * that {@link getAccount} works for newly created accounts.\n */\n abstract createAccounts(\n options: CreateAccountOptions,\n ): Promise<KeyringAccount[]>;\n\n /**\n * Remove the account associated with the given {@link AccountId} from this\n * keyring.\n *\n * Implementations are expected to translate the ID to an underlying\n * address (typically via the registry) and then invoke the appropriate\n * removal mechanism on the legacy keyring.\n */\n abstract deleteAccount(accountId: AccountId): Promise<void>;\n\n /**\n * Export the secrets associated with the given account in a format\n * described by {@link ExportAccountOptions}.\n *\n * This method is optional, and concrete adapters should only\n * implement it if the underlying keyring supports exporting\n * accounts.\n */\n exportAccount?(\n accountId: AccountId,\n options?: ExportAccountOptions,\n ): Promise<ExportedAccount>;\n\n /**\n * Handle a high-level {@link KeyringRequest} on behalf of this keyring.\n *\n * Concrete adapters are responsible for routing the request's method and\n * parameters to the appropriate legacy keyring APIs (for example signing\n * transactions or decrypting messages) and returning a JSON-serializable\n * result.\n */\n abstract submitRequest(request: KeyringRequest): Promise<Json>;\n}\n"]}
@@ -1,11 +1,12 @@
1
- import type { CreateAccountOptions, ExportAccountOptions, ExportedAccount, KeyringAccount, KeyringRequest, KeyringV2, KeyringCapabilities, KeyringType } from "@metamask/keyring-api";
2
- import type { Keyring, AccountId } from "@metamask/keyring-utils";
1
+ import type { KeyringAccount, KeyringRequest } from "@metamask/keyring-api";
2
+ import type { CreateAccountOptions, ExportAccountOptions, ExportedAccount, Keyring, KeyringCapabilities, KeyringType } from "@metamask/keyring-api/v2";
3
+ import type { Keyring as LegacyKeyring, AccountId } from "@metamask/keyring-utils";
3
4
  import type { Json } from "@metamask/utils";
4
- import { KeyringAccountRegistry, type KeyringAccountRegistryOptions } from "./keyring-account-registry.cjs";
5
+ import { KeyringAccountRegistry, type KeyringAccountRegistryOptions } from "../keyring-account-registry.cjs";
5
6
  /**
6
7
  * Basic options for constructing a {@link KeyringWrapper}.
7
8
  */
8
- export type KeyringWrapperOptions<InnerKeyring extends Keyring> = {
9
+ export type KeyringWrapperOptions<InnerKeyring extends LegacyKeyring> = {
9
10
  /**
10
11
  * The underlying "old" keyring instance that this wrapper adapts.
11
12
  */
@@ -25,7 +26,7 @@ export type KeyringWrapperOptions<InnerKeyring extends Keyring> = {
25
26
  };
26
27
  /**
27
28
  * Generic adapter that turns an existing {@link Keyring} implementation into a
28
- * {@link KeyringV2} instance.
29
+ * {@link Keyring} instance.
29
30
  *
30
31
  * Consumers are expected to provide concrete mappings between high-level V2
31
32
  * operations and the underlying keyring methods (for example BIP-44 account
@@ -33,7 +34,7 @@ export type KeyringWrapperOptions<InnerKeyring extends Keyring> = {
33
34
  * the common mechanics required by all adapters: state serialization,
34
35
  * account-ID/address mapping and basic account management.
35
36
  */
36
- export declare abstract class KeyringWrapper<InnerKeyring extends Keyring, KeyringAccountType extends KeyringAccount = KeyringAccount> implements KeyringV2 {
37
+ export declare abstract class KeyringWrapper<InnerKeyring extends LegacyKeyring, KeyringAccountType extends KeyringAccount = KeyringAccount> implements Keyring {
37
38
  #private;
38
39
  readonly type: `${KeyringType}`;
39
40
  protected readonly inner: InnerKeyring;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyring-wrapper.d.cts","sourceRoot":"","sources":["../../src/v2/keyring-wrapper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,8BAA8B;AAC5E,OAAO,KAAK,EACV,oBAAoB,EACpB,oBAAoB,EACpB,eAAe,EACf,OAAO,EACP,mBAAmB,EACnB,WAAW,EACZ,iCAAiC;AAClC,OAAO,KAAK,EACV,OAAO,IAAI,aAAa,EACxB,SAAS,EACV,gCAAgC;AACjC,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAG5C,OAAO,EACL,sBAAsB,EACtB,KAAK,6BAA6B,EACnC,wCAAoC;AAErC;;GAEG;AACH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AAE,CAAC;IAE5B;;;;;;;OAOG;IACH,QAAQ,CAAC,aAAa,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IAE3D;;;;;;;OAOG;IACH,aAAa,CAAC,CACZ,SAAS,EAAE,SAAS,EACpB,OAAO,CAAC,EAAE,oBAAoB,GAC7B,OAAO,CAAC,eAAe,CAAC;IAE3B;;;;;;;OAOG;IACH,QAAQ,CAAC,aAAa,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CAC/D"}
@@ -1,11 +1,12 @@
1
- import type { CreateAccountOptions, ExportAccountOptions, ExportedAccount, KeyringAccount, KeyringRequest, KeyringV2, KeyringCapabilities, KeyringType } from "@metamask/keyring-api";
2
- import type { Keyring, AccountId } from "@metamask/keyring-utils";
1
+ import type { KeyringAccount, KeyringRequest } from "@metamask/keyring-api";
2
+ import type { CreateAccountOptions, ExportAccountOptions, ExportedAccount, Keyring, KeyringCapabilities, KeyringType } from "@metamask/keyring-api/v2";
3
+ import type { Keyring as LegacyKeyring, AccountId } from "@metamask/keyring-utils";
3
4
  import type { Json } from "@metamask/utils";
4
- import { KeyringAccountRegistry, type KeyringAccountRegistryOptions } from "./keyring-account-registry.mjs";
5
+ import { KeyringAccountRegistry, type KeyringAccountRegistryOptions } from "../keyring-account-registry.mjs";
5
6
  /**
6
7
  * Basic options for constructing a {@link KeyringWrapper}.
7
8
  */
8
- export type KeyringWrapperOptions<InnerKeyring extends Keyring> = {
9
+ export type KeyringWrapperOptions<InnerKeyring extends LegacyKeyring> = {
9
10
  /**
10
11
  * The underlying "old" keyring instance that this wrapper adapts.
11
12
  */
@@ -25,7 +26,7 @@ export type KeyringWrapperOptions<InnerKeyring extends Keyring> = {
25
26
  };
26
27
  /**
27
28
  * Generic adapter that turns an existing {@link Keyring} implementation into a
28
- * {@link KeyringV2} instance.
29
+ * {@link Keyring} instance.
29
30
  *
30
31
  * Consumers are expected to provide concrete mappings between high-level V2
31
32
  * operations and the underlying keyring methods (for example BIP-44 account
@@ -33,7 +34,7 @@ export type KeyringWrapperOptions<InnerKeyring extends Keyring> = {
33
34
  * the common mechanics required by all adapters: state serialization,
34
35
  * account-ID/address mapping and basic account management.
35
36
  */
36
- export declare abstract class KeyringWrapper<InnerKeyring extends Keyring, KeyringAccountType extends KeyringAccount = KeyringAccount> implements KeyringV2 {
37
+ export declare abstract class KeyringWrapper<InnerKeyring extends LegacyKeyring, KeyringAccountType extends KeyringAccount = KeyringAccount> implements Keyring {
37
38
  #private;
38
39
  readonly type: `${KeyringType}`;
39
40
  protected readonly inner: InnerKeyring;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyring-wrapper.d.mts","sourceRoot":"","sources":["../../src/v2/keyring-wrapper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,8BAA8B;AAC5E,OAAO,KAAK,EACV,oBAAoB,EACpB,oBAAoB,EACpB,eAAe,EACf,OAAO,EACP,mBAAmB,EACnB,WAAW,EACZ,iCAAiC;AAClC,OAAO,KAAK,EACV,OAAO,IAAI,aAAa,EACxB,SAAS,EACV,gCAAgC;AACjC,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAG5C,OAAO,EACL,sBAAsB,EACtB,KAAK,6BAA6B,EACnC,wCAAoC;AAErC;;GAEG;AACH,MAAM,MAAM,qBAAqB,CAAC,YAAY,SAAS,aAAa,IAAI;IACtE;;OAEG;IACH,KAAK,EAAE,YAAY,CAAC;IAEpB;;OAEG;IACH,IAAI,EAAE,WAAW,CAAC;IAElB;;OAEG;IACH,YAAY,EAAE,mBAAmB,CAAC;IAElC;;OAEG;IACH,eAAe,CAAC,EAAE,6BAA6B,CAAC;CACjD,CAAC;AAEF;;;;;;;;;GASG;AACH,8BAAsB,cAAc,CAClC,YAAY,SAAS,aAAa,EAClC,kBAAkB,SAAS,cAAc,GAAG,cAAc,CAC1D,YAAW,OAAO;;IAElB,QAAQ,CAAC,IAA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ateFieldGet) || function (
11
11
  };
12
12
  var _KeyringWrapper_capabilities, _KeyringWrapper_lock;
13
13
  import { Mutex } from "async-mutex";
14
- import { KeyringAccountRegistry } from "./keyring-account-registry.mjs";
14
+ import { KeyringAccountRegistry } from "../keyring-account-registry.mjs";
15
15
  /**
16
16
  * Generic adapter that turns an existing {@link Keyring} implementation into a
17
- * {@link KeyringV2} instance.
17
+ * {@link Keyring} instance.
18
18
  *
19
19
  * Consumers are expected to provide concrete mappings between high-level V2
20
20
  * operations and the underlying keyring methods (for example BIP-44 account
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyring-wrapper.mjs","sourceRoot":"","sources":["../../src/v2/keyring-wrapper.ts"],"names":[],"mappings":";;;;;;;;;;;;AAcA,OAAO,EAAE,KAAK,EAAE,oBAAoB;AAEpC,OAAO,EACL,sBAAsB,EAEvB,wCAAoC;AA2BrC;;;;;;;;;GASG;AACH,MAAM,OAAgB,cAAc;IA0BlC,YAAY,OAA4C;QAnB/C,+CAAmC;QAI5C;;;WAGG;QACM,+BAAQ,IAAI,KAAK,EAAE,EAAC;QAY3B,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;QAC9B,uBAAA,IAAI,gCAAiB,OAAO,CAAC,YAAY,MAAA,CAAC;QAC1C,IAAI,CAAC,QAAQ,GAAG,IAAI,sBAAsB,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;IACtE,CAAC;IAED;;;;;;;OAOG;IACH,IAAI,YAAY;QACd,OAAO,uBAAA,IAAI,oCAAc,CAAC;IAC5B,CAAC;IAED;;;;;;;;;;;;OAYG;IACO,KAAK,CAAC,QAAQ,CACtB,QAA+B;QAE/B,OAAO,uBAAA,IAAI,4BAAM,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;IAC3C,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,SAAS;QACb,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC;IAChC,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,WAAW,CAAC,KAAW;QAC3B,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,IAAI,EAAE;YAC7B,wCAAwC;YACxC,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;YAEtB,iCAAiC;YACjC,MAAM,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;YAEpC,iDAAiD;YACjD,yEAAyE;YACzE,8DAA8D;YAC9D,MAAM,IAAI,CAAC,WAAW,EAAE,CAAC;QAC3B,CAAC,CAAC,CAAC;IACL,CAAC;IAgBD;;;;;;;;;OASG;IACH,KAAK,CAAC,UAAU,CAAC,SAAoB;QACnC,IAAI,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAC1C,IAAI,MAAM,EAAE,CAAC;YACX,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,4CAA4C;QAC5C,MAAM,IAAI,CAAC,WAAW,EAAE,CAAC;QAEzB,mCAAmC;QACnC,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QACtC,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CAAC,6BAA6B,SAAS,EAAE,CAAC,CAAC;QAC5D,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CA+CF","sourcesContent":["import type { KeyringAccount, KeyringRequest } from '@metamask/keyring-api';\nimport type {\n CreateAccountOptions,\n ExportAccountOptions,\n ExportedAccount,\n Keyring,\n KeyringCapabilities,\n KeyringType,\n} from '@metamask/keyring-api/v2';\nimport type {\n Keyring as LegacyKeyring,\n AccountId,\n} from '@metamask/keyring-utils';\nimport type { Json } from '@metamask/utils';\nimport { Mutex } from 'async-mutex';\n\nimport {\n KeyringAccountRegistry,\n type KeyringAccountRegistryOptions,\n} from '../keyring-account-registry';\n\n/**\n * Basic options for constructing a {@link KeyringWrapper}.\n */\nexport type KeyringWrapperOptions<InnerKeyring extends LegacyKeyring> = {\n /**\n * The underlying \"old\" keyring instance that this wrapper adapts.\n */\n inner: InnerKeyring;\n\n /**\n * The concrete keyring type exposed through the V2 interface.\n */\n type: KeyringType;\n\n /**\n * Capabilities of the underlying keyring.\n */\n capabilities: KeyringCapabilities;\n\n /**\n * Options forwarded to the {@link KeyringAccountRegistry} constructor.\n */\n registryOptions?: KeyringAccountRegistryOptions;\n};\n\n/**\n * Generic adapter that turns an existing {@link Keyring} implementation into a\n * {@link Keyring} instance.\n *\n * Consumers are expected to provide concrete mappings between high-level V2\n * operations and the underlying keyring methods (for example BIP-44 account\n * creation, private-key import, and request handling). This class focuses on\n * the common mechanics required by all adapters: state serialization,\n * account-ID/address mapping and basic account management.\n */\nexport abstract class KeyringWrapper<\n InnerKeyring extends LegacyKeyring,\n KeyringAccountType extends KeyringAccount = KeyringAccount,\n> implements Keyring\n{\n readonly type: `${KeyringType}`;\n\n readonly #capabilities: KeyringCapabilities;\n\n protected readonly inner: InnerKeyring;\n\n /**\n * Mutex to ensure exclusive access to the inner keyring during\n * operations that mutate its state.\n */\n readonly #lock = new Mutex();\n\n /**\n * Registry for KeyringAccount objects.\n * Provides O(1) lookups by AccountId or address.\n *\n * Subclasses should use this registry when creating accounts and\n * clear/update it when deleting accounts or deserializing state.\n */\n protected readonly registry: KeyringAccountRegistry<KeyringAccountType>;\n\n constructor(options: KeyringWrapperOptions<InnerKeyring>) {\n this.inner = options.inner;\n this.type = `${options.type}`;\n this.#capabilities = options.capabilities;\n this.registry = new KeyringAccountRegistry(options.registryOptions);\n }\n\n /**\n * Get the capabilities of this keyring.\n *\n * Subclasses can override this getter to return capabilities dynamically\n * based on runtime state.\n *\n * @returns The keyring's capabilities.\n */\n get capabilities(): KeyringCapabilities {\n return this.#capabilities;\n }\n\n /**\n * Execute an operation with exclusive access to the inner keyring.\n *\n * This method ensures thread-safety for operations that read or mutate\n * the inner keyring state. All operations that modify the keyring\n * (createAccounts, deleteAccount, deserialize) should use this method\n * to prevent race conditions.\n *\n * Within the callback, use `this.inner` to access the inner keyring.\n *\n * @param callback - A function that performs the operation.\n * @returns The result of the callback.\n */\n protected async withLock<Result>(\n callback: () => Promise<Result>,\n ): Promise<Result> {\n return this.#lock.runExclusive(callback);\n }\n\n /**\n * Serialize the underlying keyring state to a JSON-serializable object.\n *\n * This simply delegates to the legacy keyring's {@link Keyring.serialize}\n * implementation.\n *\n * @returns The serialized keyring state.\n */\n async serialize(): Promise<Json> {\n return this.inner.serialize();\n }\n\n /**\n * Hydrate the underlying keyring from a previously serialized state.\n *\n * This clears the registry, delegates to the legacy keyring's\n * {@link Keyring.deserialize} implementation, and rebuilds the registry\n * by calling {@link getAccounts}.\n *\n * @param state - The serialized keyring state.\n */\n async deserialize(state: Json): Promise<void> {\n await this.withLock(async () => {\n // Clear the registry when deserializing\n this.registry.clear();\n\n // Deserialize the legacy keyring\n await this.inner.deserialize(state);\n\n // Rebuild the registry by calling getAccounts().\n // Subclass implementations of getAccounts() should populate the registry\n // as a side effect (see the abstract method's documentation).\n await this.getAccounts();\n });\n }\n\n /**\n * Return all accounts managed by this keyring.\n *\n * Concrete adapters are responsible for mapping the underlying keyring's\n * notion of accounts (typically addresses returned by\n * {@link Keyring.getAccounts}) into {@link KeyringAccount} objects.\n * Implementations should use the configured {@link KeyringAccountRegistry}\n * to establish the account ID/address mapping so that\n * {@link getAccount} works as expected.\n *\n * @returns The list of managed accounts.\n */\n abstract getAccounts(): Promise<KeyringAccount[]>;\n\n /**\n * Look up a single account by its {@link AccountId}.\n *\n * This method first checks the registry for O(1) lookup.\n * If not found, it falls back to calling {@link getAccounts} which\n * should populate the registry as a side effect.\n *\n * @param accountId - The AccountId to look up.\n * @returns The matching KeyringAccount.\n */\n async getAccount(accountId: AccountId): Promise<KeyringAccount> {\n let cached = this.registry.get(accountId);\n if (cached) {\n return cached;\n }\n\n // Prime the registry by calling getAccounts\n await this.getAccounts();\n\n // Try registry again after priming\n cached = this.registry.get(accountId);\n if (!cached) {\n throw new Error(`Account not found for id: ${accountId}`);\n }\n\n return cached;\n }\n\n /**\n * Create one or more new accounts managed by this keyring.\n *\n * Implementations are responsible for interpreting the\n * {@link CreateAccountOptions} (for example BIP-44 derivation or\n * private-key import) and returning the resulting {@link KeyringAccount}\n * objects. Implementors should also ensure that the registry is updated so\n * that {@link getAccount} works for newly created accounts.\n */\n abstract createAccounts(\n options: CreateAccountOptions,\n ): Promise<KeyringAccount[]>;\n\n /**\n * Remove the account associated with the given {@link AccountId} from this\n * keyring.\n *\n * Implementations are expected to translate the ID to an underlying\n * address (typically via the registry) and then invoke the appropriate\n * removal mechanism on the legacy keyring.\n */\n abstract deleteAccount(accountId: AccountId): Promise<void>;\n\n /**\n * Export the secrets associated with the given account in a format\n * described by {@link ExportAccountOptions}.\n *\n * This method is optional, and concrete adapters should only\n * implement it if the underlying keyring supports exporting\n * accounts.\n */\n exportAccount?(\n accountId: AccountId,\n options?: ExportAccountOptions,\n ): Promise<ExportedAccount>;\n\n /**\n * Handle a high-level {@link KeyringRequest} on behalf of this keyring.\n *\n * Concrete adapters are responsible for routing the request's method and\n * parameters to the appropriate legacy keyring APIs (for example signing\n * transactions or decrypting messages) and returning a JSON-serializable\n * result.\n */\n abstract submitRequest(request: KeyringRequest): Promise<Json>;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/keyring-sdk",
3
- "version": "1.2.0",
3
+ "version": "2.0.0",
4
4
  "description": "MetaMask Keyring SDK",
5
5
  "keywords": [
6
6
  "metamask",
@@ -14,6 +14,8 @@
14
14
  "type": "git",
15
15
  "url": "https://github.com/MetaMask/accounts.git"
16
16
  },
17
+ "license": "MIT",
18
+ "sideEffects": false,
17
19
  "exports": {
18
20
  ".": {
19
21
  "import": {
@@ -24,7 +26,18 @@
24
26
  "types": "./dist/index.d.cts",
25
27
  "default": "./dist/index.cjs"
26
28
  }
27
- }
29
+ },
30
+ "./v2": {
31
+ "import": {
32
+ "types": "./dist/v2/index.d.mts",
33
+ "default": "./dist/v2/index.mjs"
34
+ },
35
+ "require": {
36
+ "types": "./dist/v2/index.d.cts",
37
+ "default": "./dist/v2/index.cjs"
38
+ }
39
+ },
40
+ "./package.json": "./package.json"
28
41
  },
29
42
  "main": "./dist/index.cjs",
30
43
  "types": "./dist/index.d.cts",
@@ -32,28 +45,31 @@
32
45
  "dist/"
33
46
  ],
34
47
  "scripts": {
35
- "build": "ts-bridge --project tsconfig.build.json --no-references",
48
+ "build": "ts-bridge --project tsconfig.build.json --verbose --clean --no-references",
49
+ "build:all": "ts-bridge --project tsconfig.build.json --verbose --clean",
36
50
  "build:clean": "yarn build --clean",
37
51
  "build:docs": "typedoc",
38
52
  "changelog:update": "../../scripts/update-changelog.sh @metamask/keyring-sdk",
39
53
  "changelog:validate": "../../scripts/validate-changelog.sh @metamask/keyring-sdk",
40
54
  "publish:preview": "yarn npm publish --tag preview",
55
+ "since-latest-release": "../../scripts/since-latest-release.sh",
41
56
  "test": "yarn test:source && yarn test:types",
42
- "test:clean": "jest --clearCache",
43
- "test:source": "jest && jest-it-up",
57
+ "test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",
58
+ "test:source": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
44
59
  "test:types": "../../scripts/tsd-test.sh ./src",
45
- "test:watch": "jest --watch"
60
+ "test:verbose": "NODE_OPTIONS=--experimental-vm-modules jest --verbose",
61
+ "test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
46
62
  },
47
63
  "dependencies": {
48
64
  "@ethereumjs/tx": "^5.4.0",
49
65
  "@metamask/eth-sig-util": "^8.2.0",
50
- "@metamask/keyring-api": "^22.0.0",
66
+ "@metamask/keyring-api": "^23.0.0",
51
67
  "@metamask/keyring-utils": "^3.2.0",
52
68
  "@metamask/scure-bip39": "^2.1.1",
53
69
  "@metamask/superstruct": "^3.1.0",
54
- "@metamask/utils": "^11.10.0",
70
+ "@metamask/utils": "^11.11.0",
55
71
  "async-mutex": "^0.5.0",
56
- "ethereum-cryptography": "^2.1.2",
72
+ "ethereum-cryptography": "^2.2.1",
57
73
  "uuid": "^9.0.1"
58
74
  },
59
75
  "devDependencies": {
@@ -1 +0,0 @@
1
- {"version":3,"file":"eth-keyring-wrapper.cjs","sourceRoot":"","sources":["../../src/eth/eth-keyring-wrapper.ts"],"names":[],"mappings":";;;AAAA,uCAAsE;AAEtE,yDAA8D;AAE9D,uDAW+B;AAE/B,uDAA+C;AAC/C,2CAA6D;AAE7D,iDAAoD;AACpD,4DAAgF;AAEhF;;;GAGG;AACH,IAAY,gBAKX;AALD,WAAY,gBAAgB;IAC1B,2CAAuB,CAAA;IACvB,yEAAqD,CAAA;IACrD,6DAAyC,CAAA;IACzC,6EAAyD,CAAA;AAC3D,CAAC,EALW,gBAAgB,gCAAhB,gBAAgB,QAK3B;AAcD;;;;;;;;;;;;GAYG;AACH,MAAsB,iBAGpB,SAAQ,gCAAgD;IACxD,YAAY,OAA+C;QACzD,KAAK,CAAC;YACJ,GAAG,OAAO;YACV,qFAAqF;YACrF,wBAAwB;YACxB,eAAe,EAAE,EAAE,UAAU,EAAE,iCAAoB,EAAE;SACtD,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;OAOG;IACO,YAAY,CAAC,OAAe;QACpC,OAAO,IAAA,aAAK,EAAC,OAAO,CAAC,CAAC;IACxB,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,aAAa,CAAC,OAAuB;QACzC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;QAE3C,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACpE,MAAM,UAAU,GAAG,IAAI,CAAC,YAAY,C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AAO,CAAC,CAAC;YAChE,CAAC;YAED,KAAK,GAAG,gBAAgB,CAAC,gBAAgB,EAAE,CAAC,CAAC,CAAC;gBAC5C,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,gBAAgB,EAAE,CAAC;oBACjC,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;gBAC/D,CAAC;gBACD,IAAA,oBAAM,EAAC,MAAM,EAAE,6CAA+B,CAAC,CAAC;gBAChD,MAAM,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;gBACxB,OAAO,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;YACzD,CAAC;YAED,KAAK,GAAG,gBAAgB,CAAC,wBAAwB,EAAE,CAAC,CAAC,CAAC;gBACpD,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,wBAAwB,EAAE,CAAC;oBACzC,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;gBACvE,CAAC;gBACD,IAAA,oBAAM,EAAC,MAAM,EAAE,qDAAuC,CAAC,CAAC;gBACxD,MAAM,CAAC,aAAa,CAAC,GAAG,MAAM,CAAC;gBAC/B,OAAO,IAAI,CAAC,KAAK,CAAC,wBAAwB,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;YACxE,CAAC;YAED;gBACE,MAAM,IAAI,KAAK,CAAC,6CAA6C,MAAM,EAAE,CAAC,CAAC;QAC3E,CAAC;IACH,CAAC;CACF;AArKD,8CAqKC","sourcesContent":["import { TransactionFactory, type TypedTxData } from '@ethereumjs/tx';\nimport type { MessageTypes, TypedMessage } from '@metamask/eth-sig-util';\nimport { SignTypedDataVersion } from '@metamask/eth-sig-util';\nimport type { KeyringAccount, KeyringRequest } from '@metamask/keyring-api';\nimport {\n EthDecryptParamsStruct,\n EthGetAppKeyAddressParamsStruct,\n EthGetEncryptionPublicKeyParamsStruct,\n EthPersonalSignParamsStruct,\n EthSignEip7702AuthorizationParamsStruct,\n EthSignParamsStruct,\n EthSignTransactionParamsStruct,\n EthSignTypedDataParamsStruct,\n EthSignTypedDataV1ParamsStruct,\n EthMethod,\n} from '@metamask/keyring-api';\nimport type { EthKeyring } from '@metamask/keyring-utils';\nimport { assert } from '@metamask/superstruct';\nimport { add0x, type Hex, type Json } from '@metamask/utils';\n\nimport { generateEthAccountId } from './account-id';\nimport { KeyringWrapper, type KeyringWrapperOptions } from '../keyring-wrapper';\n\n/**\n * Additional Ethereum methods supported by Eth keyrings that are not in the standard EthMethod enum.\n * These are primarily encryption and utility methods.\n */\nexport enum EthKeyringMethod {\n Decrypt = 'eth_decrypt',\n GetEncryptionPublicKey = 'eth_getEncryptionPublicKey',\n GetAppKeyAddress = 'eth_getAppKeyAddress',\n SignEip7702Authorization = 'eth_signEip7702Authorization',\n}\n\n/**\n * Options for constructing an {@link EthKeyringWrapper}.\n *\n * `registryOptions` is intentionally omitted: the registry is always\n * configured with {@link generateEthAccountId} to produce deterministic\n * account IDs for Ethereum addresses.\n */\nexport type EthKeyringWrapperOptions<InnerKeyring extends EthKeyring> = Omit<\n KeyringWrapperOptions<InnerKeyring>,\n 'registryOptions'\n>;\n\n/**\n * Abstract wrapper for Ethereum-based keyrings that extends KeyringWrapper, that itself implements KeyringV2.\n *\n * This class provides common functionality for all Ethereum keyrings including:\n * - Request handling for standard Ethereum signing methods\n * - Helper methods for Hex address conversion\n *\n * Subclasses must implement:\n * - `getAccounts()`: Return all managed accounts\n * - `createAccounts()`: Create new accounts based on options\n * - `deleteAccount()`: Remove an account from the keyring\n * - `exportAccount()` (optional): Export private key in specified format\n */\nexport abstract class EthKeyringWrapper<\n InnerKeyring extends EthKeyring,\n KeyringAccountType extends KeyringAccount = KeyringAccount,\n> extends KeyringWrapper<InnerKeyring, KeyringAccountType> {\n constructor(options: EthKeyringWrapperOptions<InnerKeyring>) {\n super({\n ...options,\n // We use a custom ID generator to ensure that account IDs are deterministic based on\n // the Ethereum address.\n registryOptions: { generateId: generateEthAccountId },\n });\n }\n\n /**\n * Helper method to safely cast a KeyringAccount address to Hex type.\n * The KeyringAccount.address is typed as string, but for Ethereum accounts\n * it should always be a valid Hex address.\n *\n * @param address - The address from a KeyringAccount.\n * @returns The address as Hex type.\n */\n protected toHexAddress(address: string): Hex {\n return add0x(address);\n }\n\n /**\n * Handle an Ethereum signing request.\n *\n * Routes the request to the appropriate legacy keyring method based on\n * the RPC method name.\n *\n * @param request - The keyring request containing method and params.\n * @returns The result of the signing operation.\n */\n async submitRequest(request: KeyringRequest): Promise<Json> {\n const { method, params } = request.request;\n\n const { address, methods } = await this.getAccount(request.account);\n const hexAddress = this.toHexAddress(address);\n\n // Validate account can handle the method\n if (!methods.includes(method)) {\n throw new Error(\n `Account ${request.account} cannot handle method: ${method}`,\n );\n }\n\n switch (method) {\n case `${EthMethod.SignTransaction}`: {\n if (!this.inner.signTransaction) {\n throw new Error('Keyring does not support signTransaction');\n }\n assert(params, EthSignTransactionParamsStruct);\n const [txData] = params;\n // Convert validated transaction data to TypedTransaction\n // TODO: Improve typing to ensure txData matches TypedTxData\n const tx = TransactionFactory.fromTxData(txData as TypedTxData);\n // Note: Bigints are not directly representable in JSON\n return (await this.inner.signTransaction(\n hexAddress,\n tx,\n )) as unknown as Json; // FIXME: Should return type be unknown?\n }\n\n case `${EthMethod.Sign}`: {\n if (!this.inner.signMessage) {\n throw new Error('Keyring does not support signMessage');\n }\n assert(params, EthSignParamsStruct);\n const [, data] = params;\n return this.inner.signMessage(hexAddress, data);\n }\n\n case `${EthMethod.PersonalSign}`: {\n if (!this.inner.signPersonalMessage) {\n throw new Error('Keyring does not support signPersonalMessage');\n }\n assert(params, EthPersonalSignParamsStruct);\n const [data] = params;\n return this.inner.signPersonalMessage(hexAddress, data as Hex);\n }\n\n case `${EthMethod.SignTypedDataV1}`: {\n if (!this.inner.signTypedData) {\n throw new Error('Keyring does not support signTypedData');\n }\n assert(params, EthSignTypedDataV1ParamsStruct);\n const [, data] = params;\n return this.inner.signTypedData(hexAddress, data, {\n version: SignTypedDataVersion.V1,\n });\n }\n\n case `${EthMethod.SignTypedDataV3}`: {\n if (!this.inner.signTypedData) {\n throw new Error('Keyring does not support signTypedData');\n }\n assert(params, EthSignTypedDataParamsStruct);\n const [, data] = params;\n return this.inner.signTypedData(\n hexAddress,\n // TODO: Improve typing to ensure data matches MessageTypes\n data as TypedMessage<MessageTypes>,\n {\n version: SignTypedDataVersion.V3,\n },\n );\n }\n\n case `${EthMethod.SignTypedDataV4}`: {\n if (!this.inner.signTypedData) {\n throw new Error('Keyring does not support signTypedData');\n }\n assert(params, EthSignTypedDataParamsStruct);\n const [, data] = params;\n return this.inner.signTypedData(\n hexAddress,\n // TODO: Improve typing to ensure data matches MessageTypes\n data as TypedMessage<MessageTypes>,\n {\n version: SignTypedDataVersion.V4,\n },\n );\n }\n\n case `${EthKeyringMethod.Decrypt}`: {\n if (!this.inner.decryptMessage) {\n throw new Error('Keyring does not support decryptMessage');\n }\n assert(params, EthDecryptParamsStruct);\n const [encryptedData] = params;\n return this.inner.decryptMessage(hexAddress, encryptedData);\n }\n\n case `${EthKeyringMethod.GetEncryptionPublicKey}`: {\n if (!this.inner.getEncryptionPublicKey) {\n throw new Error('Keyring does not support getEncryptionPublicKey');\n }\n assert(params, EthGetEncryptionPublicKeyParamsStruct);\n const [, options] = params;\n return this.inner.getEncryptionPublicKey(hexAddress, options);\n }\n\n case `${EthKeyringMethod.GetAppKeyAddress}`: {\n if (!this.inner.getAppKeyAddress) {\n throw new Error('Keyring does not support getAppKeyAddress');\n }\n assert(params, EthGetAppKeyAddressParamsStruct);\n const [origin] = params;\n return this.inner.getAppKeyAddress(hexAddress, origin);\n }\n\n case `${EthKeyringMethod.SignEip7702Authorization}`: {\n if (!this.inner.signEip7702Authorization) {\n throw new Error('Keyring does not support signEip7702Authorization');\n }\n assert(params, EthSignEip7702AuthorizationParamsStruct);\n const [authorization] = params;\n return this.inner.signEip7702Authorization(hexAddress, authorization);\n }\n\n default:\n throw new Error(`Unsupported method for EthKeyringWrapper: ${method}`);\n }\n }\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"eth-keyring-wrapper.d.cts","sourceRoot":"","sources":["../../src/eth/eth-keyring-wrapper.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,8BAA8B;AAa5E,OAAO,KAAK,EAAE,UAAU,EAAE,gCAAgC;AAE1D,OAAO,EAAS,KAAK,GAAG,EAAE,KAAK,IAAI,EAAE,wBAAwB;AAG7D,OAAO,EAAE,cAAc,EAAE,KAAK,qBAAqB,EAAE,+BAA2B;AAEhF;;;GAGG;AACH,oBAAY,gBAAgB;IAC1B,OAAO,gBAAgB;IACvB,sBAAsB,+BAA+B;IACrD,gBAAgB,yBAAyB;IACzC,wBAAwB,iCAAiC;CAC1D;AAED;;;;;;GAMG;AACH,MAAM,MAAM,wBAAwB,CAAC,YAAY,SAAS,UAAU,IAAI,IAAI,CAC1E,qBAAqB,CAAC,YAAY,CAAC,EACnC,iBAAiB,CAClB,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,8BAAsB,iBAAiB,CACrC,YAAY,SAAS,UAAU,EAC/B,kBAAkB,SAAS,cAAc,GAAG,cAAc,CAC1D,SAAQ,cAAc,CAAC,YAAY,EAAE,kBAAkB,CAAC;gBAC5C,OAAO,EAAE,wBAAwB,CAAC,YAAY,CAAC;IAS3D;;;;;;;OAOG;IACH,SAAS,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG;IAI5C;;;;;;;;OAQG;IACG,aAAa,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CAmI5D"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"eth-keyring-wrapper.d.mts","sourceRoot":"","sources":["../../src/eth/eth-keyring-wrapper.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,8BAA8B;AAa5E,OAAO,KAAK,EAAE,UAAU,EAA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YACzD,CAAC;YAED,KAAK,GAAG,gBAAgB,CAAC,wBAAwB,EAAE,CAAC,CAAC,CAAC;gBACpD,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,wBAAwB,EAAE,CAAC;oBACzC,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;gBACvE,CAAC;gBACD,MAAM,CAAC,MAAM,EAAE,uCAAuC,CAAC,CAAC;gBACxD,MAAM,CAAC,aAAa,CAAC,GAAG,MAAM,CAAC;gBAC/B,OAAO,IAAI,CAAC,KAAK,CAAC,wBAAwB,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;YACxE,CAAC;YAED;gBACE,MAAM,IAAI,KAAK,CAAC,6CAA6C,MAAM,EAAE,CAAC,CAAC;QAC3E,CAAC;IACH,CAAC;CACF","sourcesContent":["import { TransactionFactory, type TypedTxData } from '@ethereumjs/tx';\nimport type { MessageTypes, TypedMessage } from '@metamask/eth-sig-util';\nimport { SignTypedDataVersion } from '@metamask/eth-sig-util';\nimport type { KeyringAccount, KeyringRequest } from '@metamask/keyring-api';\nimport {\n EthDecryptParamsStruct,\n EthGetAppKeyAddressParamsStruct,\n EthGetEncryptionPublicKeyParamsStruct,\n EthPersonalSignParamsStruct,\n EthSignEip7702AuthorizationParamsStruct,\n EthSignParamsStruct,\n EthSignTransactionParamsStruct,\n EthSignTypedDataParamsStruct,\n EthSignTypedDataV1ParamsStruct,\n EthMethod,\n} from '@metamask/keyring-api';\nimport type { EthKeyring } from '@metamask/keyring-utils';\nimport { assert } from '@metamask/superstruct';\nimport { add0x, type Hex, type Json } from '@metamask/utils';\n\nimport { generateEthAccountId } from './account-id';\nimport { KeyringWrapper, type KeyringWrapperOptions } from '../keyring-wrapper';\n\n/**\n * Additional Ethereum methods supported by Eth keyrings that are not in the standard EthMethod enum.\n * These are primarily encryption and utility methods.\n */\nexport enum EthKeyringMethod {\n Decrypt = 'eth_decrypt',\n GetEncryptionPublicKey = 'eth_getEncryptionPublicKey',\n GetAppKeyAddress = 'eth_getAppKeyAddress',\n SignEip7702Authorization = 'eth_signEip7702Authorization',\n}\n\n/**\n * Options for constructing an {@link EthKeyringWrapper}.\n *\n * `registryOptions` is intentionally omitted: the registry is always\n * configured with {@link generateEthAccountId} to produce deterministic\n * account IDs for Ethereum addresses.\n */\nexport type EthKeyringWrapperOptions<InnerKeyring extends EthKeyring> = Omit<\n KeyringWrapperOptions<InnerKeyring>,\n 'registryOptions'\n>;\n\n/**\n * Abstract wrapper for Ethereum-based keyrings that extends KeyringWrapper, that itself implements KeyringV2.\n *\n * This class provides common functionality for all Ethereum keyrings including:\n * - Request handling for standard Ethereum signing methods\n * - Helper methods for Hex address conversion\n *\n * Subclasses must implement:\n * - `getAccounts()`: Return all managed accounts\n * - `createAccounts()`: Create new accounts based on options\n * - `deleteAccount()`: Remove an account from the keyring\n * - `exportAccount()` (optional): Export private key in specified format\n */\nexport abstract class EthKeyringWrapper<\n InnerKeyring extends EthKeyring,\n KeyringAccountType extends KeyringAccount = KeyringAccount,\n> extends KeyringWrapper<InnerKeyring, KeyringAccountType> {\n constructor(options: EthKeyringWrapperOptions<InnerKeyring>) {\n super({\n ...options,\n // We use a custom ID generator to ensure that account IDs are deterministic based on\n // the Ethereum address.\n registryOptions: { generateId: generateEthAccountId },\n });\n }\n\n /**\n * Helper method to safely cast a KeyringAccount address to Hex type.\n * The KeyringAccount.address is typed as string, but for Ethereum accounts\n * it should always be a valid Hex address.\n *\n * @param address - The address from a KeyringAccount.\n * @returns The address as Hex type.\n */\n protected toHexAddress(address: string): Hex {\n return add0x(address);\n }\n\n /**\n * Handle an Ethereum signing request.\n *\n * Routes the request to the appropriate legacy keyring method based on\n * the RPC method name.\n *\n * @param request - The keyring request containing method and params.\n * @returns The result of the signing operation.\n */\n async submitRequest(request: KeyringRequest): Promise<Json> {\n const { method, params } = request.request;\n\n const { address, methods } = await this.getAccount(request.account);\n const hexAddress = this.toHexAddress(address);\n\n // Validate account can handle the method\n if (!methods.includes(method)) {\n throw new Error(\n `Account ${request.account} cannot handle method: ${method}`,\n );\n }\n\n switch (method) {\n case `${EthMethod.SignTransaction}`: {\n if (!this.inner.signTransaction) {\n throw new Error('Keyring does not support signTransaction');\n }\n assert(params, EthSignTransactionParamsStruct);\n const [txData] = params;\n // Convert validated transaction data to TypedTransaction\n // TODO: Improve typing to ensure txData matches TypedTxData\n const tx = TransactionFactory.fromTxData(txData as TypedTxData);\n // Note: Bigints are not directly representable in JSON\n return (await this.inner.signTransaction(\n hexAddress,\n tx,\n )) as unknown as Json; // FIXME: Should return type be unknown?\n }\n\n case `${EthMethod.Sign}`: {\n if (!this.inner.signMessage) {\n throw new Error('Keyring does not support signMessage');\n }\n assert(params, EthSignParamsStruct);\n const [, data] = params;\n return this.inner.signMessage(hexAddress, data);\n }\n\n case `${EthMethod.PersonalSign}`: {\n if (!this.inner.signPersonalMessage) {\n throw new Error('Keyring does not support signPersonalMessage');\n }\n assert(params, EthPersonalSignParamsStruct);\n const [data] = params;\n return this.inner.signPersonalMessage(hexAddress, data as Hex);\n }\n\n case `${EthMethod.SignTypedDataV1}`: {\n if (!this.inner.signTypedData) {\n throw new Error('Keyring does not support signTypedData');\n }\n assert(params, EthSignTypedDataV1ParamsStruct);\n const [, data] = params;\n return this.inner.signTypedData(hexAddress, data, {\n version: SignTypedDataVersion.V1,\n });\n }\n\n case `${EthMethod.SignTypedDataV3}`: {\n if (!this.inner.signTypedData) {\n throw new Error('Keyring does not support signTypedData');\n }\n assert(params, EthSignTypedDataParamsStruct);\n const [, data] = params;\n return this.inner.signTypedData(\n hexAddress,\n // TODO: Improve typing to ensure data matches MessageTypes\n data as TypedMessage<MessageTypes>,\n {\n version: SignTypedDataVersion.V3,\n },\n );\n }\n\n case `${EthMethod.SignTypedDataV4}`: {\n if (!this.inner.signTypedData) {\n throw new Error('Keyring does not support signTypedData');\n }\n assert(params, EthSignTypedDataParamsStruct);\n const [, data] = params;\n return this.inner.signTypedData(\n hexAddress,\n // TODO: Improve typing to ensure data matches MessageTypes\n data as TypedMessage<MessageTypes>,\n {\n version: SignTypedDataVersion.V4,\n },\n );\n }\n\n case `${EthKeyringMethod.Decrypt}`: {\n if (!this.inner.decryptMessage) {\n throw new Error('Keyring does not support decryptMessage');\n }\n assert(params, EthDecryptParamsStruct);\n const [encryptedData] = params;\n return this.inner.decryptMessage(hexAddress, encryptedData);\n }\n\n case `${EthKeyringMethod.GetEncryptionPublicKey}`: {\n if (!this.inner.getEncryptionPublicKey) {\n throw new Error('Keyring does not support getEncryptionPublicKey');\n }\n assert(params, EthGetEncryptionPublicKeyParamsStruct);\n const [, options] = params;\n return this.inner.getEncryptionPublicKey(hexAddress, options);\n }\n\n case `${EthKeyringMethod.GetAppKeyAddress}`: {\n if (!this.inner.getAppKeyAddress) {\n throw new Error('Keyring does not support getAppKeyAddress');\n }\n assert(params, EthGetAppKeyAddressParamsStruct);\n const [origin] = params;\n return this.inner.getAppKeyAddress(hexAddress, origin);\n }\n\n case `${EthKeyringMethod.SignEip7702Authorization}`: {\n if (!this.inner.signEip7702Authorization) {\n throw new Error('Keyring does not support signEip7702Authorization');\n }\n assert(params, EthSignEip7702AuthorizationParamsStruct);\n const [authorization] = params;\n return this.inner.signEip7702Authorization(hexAddress, authorization);\n }\n\n default:\n throw new Error(`Unsupported method for EthKeyringWrapper: ${method}`);\n }\n }\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"keyring-wrapper.cjs","sourceRoot":"","sources":["../src/keyring-wrapper.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAYA,6CAAoC;AAEpC,6EAGoC;AA2BpC;;;;;;;;;GASG;AACH,MAAsB,cAAc;IA0BlC,YAAY,OAA4C;QAnB/C,+CAAmC;QAI5C;;;WAGG;QACM,+BAAQ,IAAI,mBAAK,EAAE,EAAC;QAY3B,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC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I,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CAAC,6BAA6B,SAAS,EAAE,CAAC,CAAC;QAC5D,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CA+CF;AA3LD,wCA2LC","sourcesContent":["import type {\n CreateAccountOptions,\n ExportAccountOptions,\n ExportedAccount,\n KeyringAccount,\n KeyringRequest,\n KeyringV2,\n KeyringCapabilities,\n KeyringType,\n} from '@metamask/keyring-api';\nimport type { Keyring, AccountId } from '@metamask/keyring-utils';\nimport type { Json } from '@metamask/utils';\nimport { Mutex } from 'async-mutex';\n\nimport {\n KeyringAccountRegistry,\n type KeyringAccountRegistryOptions,\n} from './keyring-account-registry';\n\n/**\n * Basic options for constructing a {@link KeyringWrapper}.\n */\nexport type KeyringWrapperOptions<InnerKeyring extends Keyring> = {\n /**\n * The underlying \"old\" keyring instance that this wrapper adapts.\n */\n inner: InnerKeyring;\n\n /**\n * The concrete keyring type exposed through the V2 interface.\n */\n type: KeyringType;\n\n /**\n * Capabilities of the underlying keyring.\n */\n capabilities: KeyringCapabilities;\n\n /**\n * Options forwarded to the {@link KeyringAccountRegistry} constructor.\n */\n registryOptions?: KeyringAccountRegistryOptions;\n};\n\n/**\n * Generic adapter that turns an existing {@link Keyring} implementation into a\n * {@link KeyringV2} instance.\n *\n * Consumers are expected to provide concrete mappings between high-level V2\n * operations and the underlying keyring methods (for example BIP-44 account\n * creation, private-key import, and request handling). This class focuses on\n * the common mechanics required by all adapters: state serialization,\n * account-ID/address mapping and basic account management.\n */\nexport abstract class KeyringWrapper<\n InnerKeyring extends Keyring,\n KeyringAccountType extends KeyringAccount = KeyringAccount,\n> implements KeyringV2\n{\n readonly type: `${KeyringType}`;\n\n readonly #capabilities: KeyringCapabilities;\n\n protected readonly inner: InnerKeyring;\n\n /**\n * Mutex to ensure exclusive access to the inner keyring during\n * operations that mutate its state.\n */\n readonly #lock = new Mutex();\n\n /**\n * Registry for KeyringAccount objects.\n * Provides O(1) lookups by AccountId or address.\n *\n * Subclasses should use this registry when creating accounts and\n * clear/update it when deleting accounts or deserializing state.\n */\n protected readonly registry: KeyringAccountRegistry<KeyringAccountType>;\n\n constructor(options: KeyringWrapperOptions<InnerKeyring>) {\n this.inner = options.inner;\n this.type = `${options.type}`;\n this.#capabilities = options.capabilities;\n this.registry = new KeyringAccountRegistry(options.registryOptions);\n }\n\n /**\n * Get the capabilities of this keyring.\n *\n * Subclasses can override this getter to return capabilities dynamically\n * based on runtime state.\n *\n * @returns The keyring's capabilities.\n */\n get capabilities(): KeyringCapabilities {\n return this.#capabilities;\n }\n\n /**\n * Execute an operation with exclusive access to the inner keyring.\n *\n * This method ensures thread-safety for operations that read or mutate\n * the inner keyring state. All operations that modify the keyring\n * (createAccounts, deleteAccount, deserialize) should use this method\n * to prevent race conditions.\n *\n * Within the callback, use `this.inner` to access the inner keyring.\n *\n * @param callback - A function that performs the operation.\n * @returns The result of the callback.\n */\n protected async withLock<Result>(\n callback: () => Promise<Result>,\n ): Promise<Result> {\n return this.#lock.runExclusive(callback);\n }\n\n /**\n * Serialize the underlying keyring state to a JSON-serializable object.\n *\n * This simply delegates to the legacy keyring's {@link Keyring.serialize}\n * implementation.\n *\n * @returns The serialized keyring state.\n */\n async serialize(): Promise<Json> {\n return this.inner.serialize();\n }\n\n /**\n * Hydrate the underlying keyring from a previously serialized state.\n *\n * This clears the registry, delegates to the legacy keyring's\n * {@link Keyring.deserialize} implementation, and rebuilds the registry\n * by calling {@link getAccounts}.\n *\n * @param state - The serialized keyring state.\n */\n async deserialize(state: Json): Promise<void> {\n await this.withLock(async () => {\n // Clear the registry when deserializing\n this.registry.clear();\n\n // Deserialize the legacy keyring\n await this.inner.deserialize(state);\n\n // Rebuild the registry by calling getAccounts().\n // Subclass implementations of getAccounts() should populate the registry\n // as a side effect (see the abstract method's documentation).\n await this.getAccounts();\n });\n }\n\n /**\n * Return all accounts managed by this keyring.\n *\n * Concrete adapters are responsible for mapping the underlying keyring's\n * notion of accounts (typically addresses returned by\n * {@link Keyring.getAccounts}) into {@link KeyringAccount} objects.\n * Implementations should use the configured {@link KeyringAccountRegistry}\n * to establish the account ID/address mapping so that\n * {@link getAccount} works as expected.\n *\n * @returns The list of managed accounts.\n */\n abstract getAccounts(): Promise<KeyringAccount[]>;\n\n /**\n * Look up a single account by its {@link AccountId}.\n *\n * This method first checks the registry for O(1) lookup.\n * If not found, it falls back to calling {@link getAccounts} which\n * should populate the registry as a side effect.\n *\n * @param accountId - The AccountId to look up.\n * @returns The matching KeyringAccount.\n */\n async getAccount(accountId: AccountId): Promise<KeyringAccount> {\n let cached = this.registry.get(accountId);\n if (cached) {\n return cached;\n }\n\n // Prime the registry by calling getAccounts\n await this.getAccounts();\n\n // Try registry again after priming\n cached = this.registry.get(accountId);\n if (!cached) {\n throw new Error(`Account not found for id: ${accountId}`);\n }\n\n return cached;\n }\n\n /**\n * Create one or more new accounts managed by this keyring.\n *\n * Implementations are responsible for interpreting the\n * {@link CreateAccountOptions} (for example BIP-44 derivation or\n * private-key import) and returning the resulting {@link KeyringAccount}\n * objects. Implementors should also ensure that the registry is updated so\n * that {@link getAccount} works for newly created accounts.\n */\n abstract createAccounts(\n options: CreateAccountOptions,\n ): Promise<KeyringAccount[]>;\n\n /**\n * Remove the account associated with the given {@link AccountId} from this\n * keyring.\n *\n * Implementations are expected to translate the ID to an underlying\n * address (typically via the registry) and then invoke the appropriate\n * removal mechanism on the legacy keyring.\n */\n abstract deleteAccount(accountId: AccountId): Promise<void>;\n\n /**\n * Export the secrets associated with the given account in a format\n * described by {@link ExportAccountOptions}.\n *\n * This method is optional, and concrete adapters should only\n * implement it if the underlying keyring supports exporting\n * accounts.\n */\n exportAccount?(\n accountId: AccountId,\n options?: ExportAccountOptions,\n ): Promise<ExportedAccount>;\n\n /**\n * Handle a high-level {@link KeyringRequest} on behalf of this keyring.\n *\n * Concrete adapters are responsible for routing the request's method and\n * parameters to the appropriate legacy keyring APIs (for example signing\n * transactions or decrypting messages) and returning a JSON-serializable\n * result.\n */\n abstract submitRequest(request: KeyringRequest): Promise<Json>;\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"keyring-wrapper.d.cts","sourceRoot":"","sources":["../src/keyring-wrapper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EACpB,oBAAoB,EACpB,eAAe,EACf,cAAc,EACd,cAAc,EACd,SAAS,EACT,mBAAmB,EACnB,WAAW,EACZ,8BAA8B;AAC/B,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,gCAAgC;AAClE,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAG5C,OAAO,EACL,sBAAsB,EACtB,KAAK,6BAA6B,EACnC,uCAAmC;AAEpC;;GAEG;AACH,MAAM,MAAM,qBAAqB,CAAC,YAAY,SAAS,OAAO,IAAI;IAChE;;OAEG;IACH,KAAK,EAAE,YAAY,CAAC;IAEpB;;OAEG;IACH,IAAI,EAAE,WAAW,CAAC;IAElB;;OAEG;IACH,YAAY,EAAE,mBAAmB,CAAC;IAElC;;OAEG;IACH,eAAe,CAAC,EAAE,6BAA6B,CAAC;CACjD,CAAC;AAEF;;;;;;;;;GASG;AACH,8BAAsB,cAAc,CAClC,YAAY,SAAS,OAAO,EAC5B,kBAAkB,SAAS,cAAc,GAAG,cAAc,CAC1D,YAAW,SAAS;;IAEpB,QAAQ,CAAC,IAAI,EAAE,GAAG,WAAW,EAAE,CAAC;IAIhC,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC;IAQvC;;;;;;OAMG;IACH,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,sBAAsB,CAAC,kBAAkB,CAAC,CAAC;gBAE5D,OAAO,EAAE,qBAAqB,CAAC,YAAY,CAAC;IAOxD;;;;;;;OAOG;IACH,IAAI,YAAY,IAAI,mBAAmB,CAEtC;IAED;;;;;;;;;;;;OAYG;cACa,QAAQ,CAAC,MAAM,EAC7B,QAAQ,EAAE,MAAM,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I,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC;IAChC,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,WAAW,CAAC,KAAW;QAC3B,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,IAAI,EAAE;YAC7B,wCAAwC;YACxC,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;YAEtB,iCAAiC;YACjC,MAAM,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;YAEpC,iDAAiD;YACjD,yEAAyE;YACzE,8DAA8D;YAC9D,MAAM,IAAI,CAAC,WAAW,EAAE,CAAC;QAC3B,CAAC,CAAC,CAAC;IACL,CAAC;IAgBD;;;;;;;;;OASG;IACH,KAAK,CAAC,UAAU,CAAC,SAAoB;QACnC,IAAI,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAC1C,IAAI,MAAM,EAAE,CAAC;YACX,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,4CAA4C;QAC5C,MAAM,IAAI,CAAC,WAAW,EAAE,CAAC;QAEzB,mCAAmC;QACnC,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QACtC,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CAAC,6BAA6B,SAAS,EAAE,CAAC,CAAC;QAC5D,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CA+CF","sourcesContent":["import type {\n CreateAccountOptions,\n ExportAccountOptions,\n ExportedAccount,\n KeyringAccount,\n KeyringRequest,\n KeyringV2,\n KeyringCapabilities,\n KeyringType,\n} from '@metamask/keyring-api';\nimport type { Keyring, AccountId } from '@metamask/keyring-utils';\nimport type { Json } from '@metamask/utils';\nimport { Mutex } from 'async-mutex';\n\nimport {\n KeyringAccountRegistry,\n type KeyringAccountRegistryOptions,\n} from './keyring-account-registry';\n\n/**\n * Basic options for constructing a {@link KeyringWrapper}.\n */\nexport type KeyringWrapperOptions<InnerKeyring extends Keyring> = {\n /**\n * The underlying \"old\" keyring instance that this wrapper adapts.\n */\n inner: InnerKeyring;\n\n /**\n * The concrete keyring type exposed through the V2 interface.\n */\n type: KeyringType;\n\n /**\n * Capabilities of the underlying keyring.\n */\n capabilities: KeyringCapabilities;\n\n /**\n * Options forwarded to the {@link KeyringAccountRegistry} constructor.\n */\n registryOptions?: KeyringAccountRegistryOptions;\n};\n\n/**\n * Generic adapter that turns an existing {@link Keyring} implementation into a\n * {@link KeyringV2} instance.\n *\n * Consumers are expected to provide concrete mappings between high-level V2\n * operations and the underlying keyring methods (for example BIP-44 account\n * creation, private-key import, and request handling). This class focuses on\n * the common mechanics required by all adapters: state serialization,\n * account-ID/address mapping and basic account management.\n */\nexport abstract class KeyringWrapper<\n InnerKeyring extends Keyring,\n KeyringAccountType extends KeyringAccount = KeyringAccount,\n> implements KeyringV2\n{\n readonly type: `${KeyringType}`;\n\n readonly #capabilities: KeyringCapabilities;\n\n protected readonly inner: InnerKeyring;\n\n /**\n * Mutex to ensure exclusive access to the inner keyring during\n * operations that mutate its state.\n */\n readonly #lock = new Mutex();\n\n /**\n * Registry for KeyringAccount objects.\n * Provides O(1) lookups by AccountId or address.\n *\n * Subclasses should use this registry when creating accounts and\n * clear/update it when deleting accounts or deserializing state.\n */\n protected readonly registry: KeyringAccountRegistry<KeyringAccountType>;\n\n constructor(options: KeyringWrapperOptions<InnerKeyring>) {\n this.inner = options.inner;\n this.type = `${options.type}`;\n this.#capabilities = options.capabilities;\n this.registry = new KeyringAccountRegistry(options.registryOptions);\n }\n\n /**\n * Get the capabilities of this keyring.\n *\n * Subclasses can override this getter to return capabilities dynamically\n * based on runtime state.\n *\n * @returns The keyring's capabilities.\n */\n get capabilities(): KeyringCapabilities {\n return this.#capabilities;\n }\n\n /**\n * Execute an operation with exclusive access to the inner keyring.\n *\n * This method ensures thread-safety for operations that read or mutate\n * the inner keyring state. All operations that modify the keyring\n * (createAccounts, deleteAccount, deserialize) should use this method\n * to prevent race conditions.\n *\n * Within the callback, use `this.inner` to access the inner keyring.\n *\n * @param callback - A function that performs the operation.\n * @returns The result of the callback.\n */\n protected async withLock<Result>(\n callback: () => Promise<Result>,\n ): Promise<Result> {\n return this.#lock.runExclusive(callback);\n }\n\n /**\n * Serialize the underlying keyring state to a JSON-serializable object.\n *\n * This simply delegates to the legacy keyring's {@link Keyring.serialize}\n * implementation.\n *\n * @returns The serialized keyring state.\n */\n async serialize(): Promise<Json> {\n return this.inner.serialize();\n }\n\n /**\n * Hydrate the underlying keyring from a previously serialized state.\n *\n * This clears the registry, delegates to the legacy keyring's\n * {@link Keyring.deserialize} implementation, and rebuilds the registry\n * by calling {@link getAccounts}.\n *\n * @param state - The serialized keyring state.\n */\n async deserialize(state: Json): Promise<void> {\n await this.withLock(async () => {\n // Clear the registry when deserializing\n this.registry.clear();\n\n // Deserialize the legacy keyring\n await this.inner.deserialize(state);\n\n // Rebuild the registry by calling getAccounts().\n // Subclass implementations of getAccounts() should populate the registry\n // as a side effect (see the abstract method's documentation).\n await this.getAccounts();\n });\n }\n\n /**\n * Return all accounts managed by this keyring.\n *\n * Concrete adapters are responsible for mapping the underlying keyring's\n * notion of accounts (typically addresses returned by\n * {@link Keyring.getAccounts}) into {@link KeyringAccount} objects.\n * Implementations should use the configured {@link KeyringAccountRegistry}\n * to establish the account ID/address mapping so that\n * {@link getAccount} works as expected.\n *\n * @returns The list of managed accounts.\n */\n abstract getAccounts(): Promise<KeyringAccount[]>;\n\n /**\n * Look up a single account by its {@link AccountId}.\n *\n * This method first checks the registry for O(1) lookup.\n * If not found, it falls back to calling {@link getAccounts} which\n * should populate the registry as a side effect.\n *\n * @param accountId - The AccountId to look up.\n * @returns The matching KeyringAccount.\n */\n async getAccount(accountId: AccountId): Promise<KeyringAccount> {\n let cached = this.registry.get(accountId);\n if (cached) {\n return cached;\n }\n\n // Prime the registry by calling getAccounts\n await this.getAccounts();\n\n // Try registry again after priming\n cached = this.registry.get(accountId);\n if (!cached) {\n throw new Error(`Account not found for id: ${accountId}`);\n }\n\n return cached;\n }\n\n /**\n * Create one or more new accounts managed by this keyring.\n *\n * Implementations are responsible for interpreting the\n * {@link CreateAccountOptions} (for example BIP-44 derivation or\n * private-key import) and returning the resulting {@link KeyringAccount}\n * objects. Implementors should also ensure that the registry is updated so\n * that {@link getAccount} works for newly created accounts.\n */\n abstract createAccounts(\n options: CreateAccountOptions,\n ): Promise<KeyringAccount[]>;\n\n /**\n * Remove the account associated with the given {@link AccountId} from this\n * keyring.\n *\n * Implementations are expected to translate the ID to an underlying\n * address (typically via the registry) and then invoke the appropriate\n * removal mechanism on the legacy keyring.\n */\n abstract deleteAccount(accountId: AccountId): Promise<void>;\n\n /**\n * Export the secrets associated with the given account in a format\n * described by {@link ExportAccountOptions}.\n *\n * This method is optional, and concrete adapters should only\n * implement it if the underlying keyring supports exporting\n * accounts.\n */\n exportAccount?(\n accountId: AccountId,\n options?: ExportAccountOptions,\n ): Promise<ExportedAccount>;\n\n /**\n * Handle a high-level {@link KeyringRequest} on behalf of this keyring.\n *\n * Concrete adapters are responsible for routing the request's method and\n * parameters to the appropriate legacy keyring APIs (for example signing\n * transactions or decrypting messages) and returning a JSON-serializable\n * result.\n */\n abstract submitRequest(request: KeyringRequest): Promise<Json>;\n}\n"]}