@metamask/keyring-sdk 1.1.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 (75) hide show
  1. package/CHANGELOG.md +25 -1
  2. package/LICENSE +21 -0
  3. package/dist/eth/account-id.cjs +27 -0
  4. package/dist/eth/account-id.cjs.map +1 -0
  5. package/dist/eth/account-id.d.cts +16 -0
  6. package/dist/eth/account-id.d.cts.map +1 -0
  7. package/dist/eth/account-id.d.mts +16 -0
  8. package/dist/eth/account-id.d.mts.map +1 -0
  9. package/dist/eth/account-id.mjs +24 -0
  10. package/dist/eth/account-id.mjs.map +1 -0
  11. package/dist/eth/index.cjs +1 -1
  12. package/dist/eth/index.cjs.map +1 -1
  13. package/dist/eth/index.d.cts +1 -1
  14. package/dist/eth/index.d.cts.map +1 -1
  15. package/dist/eth/index.d.mts +1 -1
  16. package/dist/eth/index.d.mts.map +1 -1
  17. package/dist/eth/index.mjs +1 -1
  18. package/dist/eth/index.mjs.map +1 -1
  19. package/dist/index.cjs +0 -1
  20. package/dist/index.cjs.map +1 -1
  21. package/dist/index.d.cts +0 -1
  22. package/dist/index.d.cts.map +1 -1
  23. package/dist/index.d.mts +0 -1
  24. package/dist/index.d.mts.map +1 -1
  25. package/dist/index.mjs +0 -1
  26. package/dist/index.mjs.map +1 -1
  27. package/dist/keyring-account-registry.cjs +18 -4
  28. package/dist/keyring-account-registry.cjs.map +1 -1
  29. package/dist/keyring-account-registry.d.cts +19 -0
  30. package/dist/keyring-account-registry.d.cts.map +1 -1
  31. package/dist/keyring-account-registry.d.mts +19 -0
  32. package/dist/keyring-account-registry.d.mts.map +1 -1
  33. package/dist/keyring-account-registry.mjs +18 -4
  34. package/dist/keyring-account-registry.mjs.map +1 -1
  35. package/dist/{eth → v2/eth}/eth-keyring-wrapper.cjs +10 -1
  36. package/dist/v2/eth/eth-keyring-wrapper.cjs.map +1 -0
  37. package/dist/{eth → v2/eth}/eth-keyring-wrapper.d.cts +8 -3
  38. package/dist/v2/eth/eth-keyring-wrapper.d.cts.map +1 -0
  39. package/dist/{eth → v2/eth}/eth-keyring-wrapper.d.mts +8 -3
  40. package/dist/v2/eth/eth-keyring-wrapper.d.mts.map +1 -0
  41. package/dist/{eth → v2/eth}/eth-keyring-wrapper.mjs +10 -1
  42. package/dist/v2/eth/eth-keyring-wrapper.mjs.map +1 -0
  43. package/dist/v2/eth/index.cjs +18 -0
  44. package/dist/v2/eth/index.cjs.map +1 -0
  45. package/dist/v2/eth/index.d.cts +2 -0
  46. package/dist/v2/eth/index.d.cts.map +1 -0
  47. package/dist/v2/eth/index.d.mts +2 -0
  48. package/dist/v2/eth/index.d.mts.map +1 -0
  49. package/dist/v2/eth/index.mjs +2 -0
  50. package/dist/v2/eth/index.mjs.map +1 -0
  51. package/dist/v2/index.cjs +19 -0
  52. package/dist/v2/index.cjs.map +1 -0
  53. package/dist/v2/index.d.cts +3 -0
  54. package/dist/v2/index.d.cts.map +1 -0
  55. package/dist/v2/index.d.mts +3 -0
  56. package/dist/v2/index.d.mts.map +1 -0
  57. package/dist/v2/index.mjs +3 -0
  58. package/dist/v2/index.mjs.map +1 -0
  59. package/dist/{keyring-wrapper.cjs → v2/keyring-wrapper.cjs} +3 -10
  60. package/dist/v2/keyring-wrapper.cjs.map +1 -0
  61. package/dist/{keyring-wrapper.d.cts → v2/keyring-wrapper.d.cts} +11 -6
  62. package/dist/v2/keyring-wrapper.d.cts.map +1 -0
  63. package/dist/{keyring-wrapper.d.mts → v2/keyring-wrapper.d.mts} +11 -6
  64. package/dist/v2/keyring-wrapper.d.mts.map +1 -0
  65. package/dist/{keyring-wrapper.mjs → v2/keyring-wrapper.mjs} +3 -10
  66. package/dist/v2/keyring-wrapper.mjs.map +1 -0
  67. package/package.json +25 -8
  68. package/dist/eth/eth-keyring-wrapper.cjs.map +0 -1
  69. package/dist/eth/eth-keyring-wrapper.d.cts.map +0 -1
  70. package/dist/eth/eth-keyring-wrapper.d.mts.map +0 -1
  71. package/dist/eth/eth-keyring-wrapper.mjs.map +0 -1
  72. package/dist/keyring-wrapper.cjs.map +0 -1
  73. package/dist/keyring-wrapper.d.cts.map +0 -1
  74. package/dist/keyring-wrapper.d.mts.map +0 -1
  75. package/dist/keyring-wrapper.mjs.map +0 -1
package/CHANGELOG.md CHANGED
@@ -7,6 +7,28 @@ 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
+
25
+ ## [1.2.0]
26
+
27
+ ### Added
28
+
29
+ - Add `generateId` option to `KeyringAccountRegistry` ([#503](https://github.com/MetaMask/accounts/pull/503))
30
+ - Add `generateEthAccountId` to generate deterministic account IDs for EVM addresses, and use it by default in `EthKeyringWrapper` ([#504](https://github.com/MetaMask/accounts/pull/504))
31
+
10
32
  ## [1.1.0]
11
33
 
12
34
  ### Added
@@ -23,6 +45,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
23
45
 
24
46
  - Initial release, extracted from `@metamask/keyring-api` ([#478](https://github.com/MetaMask/accounts/pull/478)), ([#482](https://github.com/MetaMask/accounts/pull/482))
25
47
 
26
- [Unreleased]: https://github.com/MetaMask/accounts/compare/@metamask/keyring-sdk@1.1.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
50
+ [1.2.0]: https://github.com/MetaMask/accounts/compare/@metamask/keyring-sdk@1.1.0...@metamask/keyring-sdk@1.2.0
27
51
  [1.1.0]: https://github.com/MetaMask/accounts/compare/@metamask/keyring-sdk@1.0.0...@metamask/keyring-sdk@1.1.0
28
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.
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateEthAccountId = generateEthAccountId;
4
+ const eth_sig_util_1 = require("@metamask/eth-sig-util");
5
+ const utils_1 = require("@metamask/utils");
6
+ const sha256_1 = require("ethereum-cryptography/sha256");
7
+ const uuid_1 = require("uuid");
8
+ /**
9
+ * Generates a deterministic account ID for a given Ethereum address.
10
+ *
11
+ * The address is first normalized (lowercased, `0x`-prefixed) so that
12
+ * checksum-cased and lowercase variants of the same address produce the
13
+ * same ID. The ID is then a UUID v4 derived by seeding the UUID generator
14
+ * with the first 16 bytes of the SHA-256 hash of the normalized address
15
+ * bytes.
16
+ *
17
+ * @param address - The Ethereum address (hex string) to generate the account
18
+ * ID from.
19
+ * @returns A deterministic UUID v4 string to use as the account ID.
20
+ */
21
+ function generateEthAccountId(address) {
22
+ const normalized = (0, eth_sig_util_1.normalize)(address);
23
+ return (0, uuid_1.v4)({
24
+ random: (0, sha256_1.sha256)((0, utils_1.hexToBytes)(normalized)).slice(0, 16),
25
+ });
26
+ }
27
+ //# sourceMappingURL=account-id.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account-id.cjs","sourceRoot":"","sources":["../../src/eth/account-id.ts"],"names":[],"mappings":";;AAmBA,oDAKC;AAxBD,yDAAmD;AAEnD,2CAA6C;AAC7C,yDAAsD;AACtD,+BAAoC;AAEpC;;;;;;;;;;;;GAYG;AACH,SAAgB,oBAAoB,CAAC,OAAe;IAClD,MAAM,UAAU,GAAG,IAAA,wBAAS,EAAC,OAAO,CAAW,CAAC;IAChD,OAAO,IAAA,SAAM,EAAC;QACZ,MAAM,EAAE,IAAA,eAAM,EAAC,IAAA,kBAAU,EAAC,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC;KACpD,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { normalize } from '@metamask/eth-sig-util';\nimport type { AccountId } from '@metamask/keyring-utils';\nimport { hexToBytes } from '@metamask/utils';\nimport { sha256 } from 'ethereum-cryptography/sha256';\nimport { v4 as uuidv4 } from 'uuid';\n\n/**\n * Generates a deterministic account ID for a given Ethereum address.\n *\n * The address is first normalized (lowercased, `0x`-prefixed) so that\n * checksum-cased and lowercase variants of the same address produce the\n * same ID. The ID is then a UUID v4 derived by seeding the UUID generator\n * with the first 16 bytes of the SHA-256 hash of the normalized address\n * bytes.\n *\n * @param address - The Ethereum address (hex string) to generate the account\n * ID from.\n * @returns A deterministic UUID v4 string to use as the account ID.\n */\nexport function generateEthAccountId(address: string): AccountId {\n const normalized = normalize(address) as string;\n return uuidv4({\n random: sha256(hexToBytes(normalized)).slice(0, 16),\n });\n}\n"]}
@@ -0,0 +1,16 @@
1
+ import type { AccountId } from "@metamask/keyring-utils";
2
+ /**
3
+ * Generates a deterministic account ID for a given Ethereum address.
4
+ *
5
+ * The address is first normalized (lowercased, `0x`-prefixed) so that
6
+ * checksum-cased and lowercase variants of the same address produce the
7
+ * same ID. The ID is then a UUID v4 derived by seeding the UUID generator
8
+ * with the first 16 bytes of the SHA-256 hash of the normalized address
9
+ * bytes.
10
+ *
11
+ * @param address - The Ethereum address (hex string) to generate the account
12
+ * ID from.
13
+ * @returns A deterministic UUID v4 string to use as the account ID.
14
+ */
15
+ export declare function generateEthAccountId(address: string): AccountId;
16
+ //# sourceMappingURL=account-id.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account-id.d.cts","sourceRoot":"","sources":["../../src/eth/account-id.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,gCAAgC;AAKzD;;;;;;;;;;;;GAYG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAK/D"}
@@ -0,0 +1,16 @@
1
+ import type { AccountId } from "@metamask/keyring-utils";
2
+ /**
3
+ * Generates a deterministic account ID for a given Ethereum address.
4
+ *
5
+ * The address is first normalized (lowercased, `0x`-prefixed) so that
6
+ * checksum-cased and lowercase variants of the same address produce the
7
+ * same ID. The ID is then a UUID v4 derived by seeding the UUID generator
8
+ * with the first 16 bytes of the SHA-256 hash of the normalized address
9
+ * bytes.
10
+ *
11
+ * @param address - The Ethereum address (hex string) to generate the account
12
+ * ID from.
13
+ * @returns A deterministic UUID v4 string to use as the account ID.
14
+ */
15
+ export declare function generateEthAccountId(address: string): AccountId;
16
+ //# sourceMappingURL=account-id.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account-id.d.mts","sourceRoot":"","sources":["../../src/eth/account-id.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,gCAAgC;AAKzD;;;;;;;;;;;;GAYG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAK/D"}
@@ -0,0 +1,24 @@
1
+ import { normalize } from "@metamask/eth-sig-util";
2
+ import { hexToBytes } from "@metamask/utils";
3
+ import { sha256 } from "ethereum-cryptography/sha256";
4
+ import { v4 as uuidv4 } from "uuid";
5
+ /**
6
+ * Generates a deterministic account ID for a given Ethereum address.
7
+ *
8
+ * The address is first normalized (lowercased, `0x`-prefixed) so that
9
+ * checksum-cased and lowercase variants of the same address produce the
10
+ * same ID. The ID is then a UUID v4 derived by seeding the UUID generator
11
+ * with the first 16 bytes of the SHA-256 hash of the normalized address
12
+ * bytes.
13
+ *
14
+ * @param address - The Ethereum address (hex string) to generate the account
15
+ * ID from.
16
+ * @returns A deterministic UUID v4 string to use as the account ID.
17
+ */
18
+ export function generateEthAccountId(address) {
19
+ const normalized = normalize(address);
20
+ return uuidv4({
21
+ random: sha256(hexToBytes(normalized)).slice(0, 16),
22
+ });
23
+ }
24
+ //# sourceMappingURL=account-id.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account-id.mjs","sourceRoot":"","sources":["../../src/eth/account-id.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,+BAA+B;AAEnD,OAAO,EAAE,UAAU,EAAE,wBAAwB;AAC7C,OAAO,EAAE,MAAM,EAAE,qCAAqC;AACtD,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,aAAa;AAEpC;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,oBAAoB,CAAC,OAAe;IAClD,MAAM,UAAU,GAAG,SAAS,CAAC,OAAO,CAAW,CAAC;IAChD,OAAO,MAAM,CAAC;QACZ,MAAM,EAAE,MAAM,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC;KACpD,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { normalize } from '@metamask/eth-sig-util';\nimport type { AccountId } from '@metamask/keyring-utils';\nimport { hexToBytes } from '@metamask/utils';\nimport { sha256 } from 'ethereum-cryptography/sha256';\nimport { v4 as uuidv4 } from 'uuid';\n\n/**\n * Generates a deterministic account ID for a given Ethereum address.\n *\n * The address is first normalized (lowercased, `0x`-prefixed) so that\n * checksum-cased and lowercase variants of the same address produce the\n * same ID. The ID is then a UUID v4 derived by seeding the UUID generator\n * with the first 16 bytes of the SHA-256 hash of the normalized address\n * bytes.\n *\n * @param address - The Ethereum address (hex string) to generate the account\n * ID from.\n * @returns A deterministic UUID v4 string to use as the account ID.\n */\nexport function generateEthAccountId(address: string): AccountId {\n const normalized = normalize(address) as string;\n return uuidv4({\n random: sha256(hexToBytes(normalized)).slice(0, 16),\n });\n}\n"]}
@@ -14,5 +14,5 @@ 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("./eth-keyring-wrapper.cjs"), exports);
17
+ __exportStar(require("./account-id.cjs"), exports);
18
18
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/eth/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4DAAsC","sourcesContent":["export * 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,2 +1,2 @@
1
- export * from "./eth-keyring-wrapper.cjs";
1
+ export * from "./account-id.cjs";
2
2
  //# sourceMappingURL=index.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../src/eth/index.ts"],"names":[],"mappings":"AAAA,0CAAsC"}
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../src/eth/index.ts"],"names":[],"mappings":"AAAA,iCAA6B"}
@@ -1,2 +1,2 @@
1
- export * from "./eth-keyring-wrapper.mjs";
1
+ export * from "./account-id.mjs";
2
2
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/eth/index.ts"],"names":[],"mappings":"AAAA,0CAAsC"}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/eth/index.ts"],"names":[],"mappings":"AAAA,iCAA6B"}
@@ -1,2 +1,2 @@
1
- export * from "./eth-keyring-wrapper.mjs";
1
+ export * from "./account-id.mjs";
2
2
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/eth/index.ts"],"names":[],"mappings":"AAAA,0CAAsC","sourcesContent":["export * 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"]}
@@ -1,10 +1,16 @@
1
1
  "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
2
8
  var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
3
9
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
4
10
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
5
11
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
12
  };
7
- var _KeyringAccountRegistry_accountById, _KeyringAccountRegistry_idByAddress;
13
+ var _KeyringAccountRegistry_accountById, _KeyringAccountRegistry_idByAddress, _KeyringAccountRegistry_generateId;
8
14
  Object.defineProperty(exports, "__esModule", { value: true });
9
15
  exports.KeyringAccountRegistry = void 0;
10
16
  const uuid_1 = require("uuid");
@@ -15,9 +21,17 @@ const uuid_1 = require("uuid");
15
21
  * KeyringAccount objects for efficient retrieval.
16
22
  */
17
23
  class KeyringAccountRegistry {
18
- constructor() {
24
+ /**
25
+ * Create a new KeyringAccountRegistry.
26
+ *
27
+ * @param options - Optional configuration.
28
+ * @param options.generateId - Custom ID generator. Defaults to `uuidv4`.
29
+ */
30
+ constructor(options) {
19
31
  _KeyringAccountRegistry_accountById.set(this, new Map());
20
32
  _KeyringAccountRegistry_idByAddress.set(this, new Map());
33
+ _KeyringAccountRegistry_generateId.set(this, void 0);
34
+ __classPrivateFieldSet(this, _KeyringAccountRegistry_generateId, options?.generateId ?? (() => (0, uuid_1.v4)()), "f");
21
35
  }
22
36
  /**
23
37
  * Get an account by its account ID.
@@ -58,7 +72,7 @@ class KeyringAccountRegistry {
58
72
  if (existing) {
59
73
  return existing;
60
74
  }
61
- const id = (0, uuid_1.v4)();
75
+ const id = __classPrivateFieldGet(this, _KeyringAccountRegistry_generateId, "f").call(this, address);
62
76
  __classPrivateFieldGet(this, _KeyringAccountRegistry_idByAddress, "f").set(address, id);
63
77
  return id;
64
78
  }
@@ -131,5 +145,5 @@ class KeyringAccountRegistry {
131
145
  }
132
146
  }
133
147
  exports.KeyringAccountRegistry = KeyringAccountRegistry;
134
- _KeyringAccountRegistry_accountById = new WeakMap(), _KeyringAccountRegistry_idByAddress = new WeakMap();
148
+ _KeyringAccountRegistry_accountById = new WeakMap(), _KeyringAccountRegistry_idByAddress = new WeakMap(), _KeyringAccountRegistry_generateId = new WeakMap();
135
149
  //# sourceMappingURL=keyring-account-registry.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"keyring-account-registry.cjs","sourceRoot":"","sources":["../src/keyring-account-registry.ts"],"names":[],"mappings":";;;;;;;;;AAEA,+BAAoC;AAEpC;;;;;GAKG;AACH,MAAa,sBAAsB;IAAnC;QAGW,8CAAe,IAAI,GAAG,EAAiC,EAAC;QAExD,8CAAe,IAAI,GAAG,EAAqB,EAAC;IA0HvD,CAAC;IAxHC;;;;;OAKG;IACH,GAAG,CAAC,SAAoB;QACtB,OAAO,uBAAA,IAAI,2CAAa,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IAC1C,CAAC;IAED;;;;;OAKG;IACH,UAAU,CAAC,SAAoB;QAC7B,OAAO,uBAAA,IAAI,2CAAa,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC;IACnD,CAAC;IAED;;;;;OAKG;IACH,YAAY,CAAC,OAAe;QAC1B,OAAO,uBAAA,IAAI,2CAAa,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACxC,CAAC;IAED;;;;;;OAMG;IACH,QAAQ,CAAC,OAAe;QACtB,MAAM,QAAQ,GAAG,uBAAA,IAAI,2CAAa,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAChD,IAAI,QAAQ,EAAE,CAAC;YACb,OAAO,QAAQ,CAAC;QAClB,CAAC;QACD,MAAM,EAAE,GAAG,IAAA,SAAM,GAAE,CAAC;QACpB,uBAAA,IAAI,2CAAa,CAAC,GAAG,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QACnC,OAAO,EAAE,CAAC;IACZ,CAAC;IAED;;;;;;;;;;OAUG;IACH,GAAG,CAAC,OAA2B;QAC7B,uBAAA,IAAI,2CAAa,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;QAC3C,uBAAA,IAAI,2CAAa,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;IACrD,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,SAAoB;QACzB,MAAM,OAAO,GAAG,uBAAA,IAAI,2CAAa,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QACjD,IAAI,OAAO,EAAE,CAAC;YACZ,uBAAA,IAAI,2CAAa,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YAC1C,uBAAA,IAAI,2CAAa,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QACtC,CAAC;IACH,CAAC;IAED;;OAEG;IACH,KAAK;QACH,uBAAA,IAAI,2CAAa,CAAC,KAAK,EAAE,CAAC;QAC1B,uBAAA,IAAI,2CAAa,CAAC,KAAK,EAAE,CAAC;IAC5B,CAAC;IAED;;;;OAIG;IACH,MAAM;QACJ,OAAO,KAAK,CAAC,IAAI,CAAC,uBAAA,IAAI,2CAAa,CAAC,MAAM,EAAE,CAAC,CAAC;IAChD,CAAC;IAED;;;;OAIG;IACH,IAAI;QACF,OAAO,KAAK,CAAC,IAAI,CAAC,uBAAA,IAAI,2CAAa,CAAC,IAAI,EAAE,CAAC,CAAC;IAC9C,CAAC;IAED;;;;;OAKG;IACH,GAAG,CAAC,SAAoB;QACtB,OAAO,uBAAA,IAAI,2CAAa,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IAC1C,CAAC;IAED;;;;OAIG;IACH,IAAI,IAAI;QACN,OAAO,uBAAA,IAAI,2CAAa,CAAC,IAAI,CAAC;IAChC,CAAC;CACF;AA/HD,wDA+HC","sourcesContent":["import type { KeyringAccount } from '@metamask/keyring-api';\nimport type { AccountId } from '@metamask/keyring-utils';\nimport { v4 as uuidv4 } from 'uuid';\n\n/**\n * In-memory registry for KeyringAccount objects.\n *\n * Provides O(1) lookups by account ID or address, and stores the full\n * KeyringAccount objects for efficient retrieval.\n */\nexport class KeyringAccountRegistry<\n KeyringAccountType extends KeyringAccount = KeyringAccount,\n> {\n readonly #accountById = new Map<AccountId, KeyringAccountType>();\n\n readonly #idByAddress = new Map<string, AccountId>();\n\n /**\n * Get an account by its account ID.\n *\n * @param accountId - The account ID to look up.\n * @returns The KeyringAccount, or undefined if not found.\n */\n get(accountId: AccountId): KeyringAccountType | undefined {\n return this.#accountById.get(accountId);\n }\n\n /**\n * Get an account's address by its account ID.\n *\n * @param accountId - The account ID to look up.\n * @returns The address, or undefined if not found.\n */\n getAddress(accountId: AccountId): string | undefined {\n return this.#accountById.get(accountId)?.address;\n }\n\n /**\n * Get an account ID by the underlying address.\n *\n * @param address - The address to look up.\n * @returns The account ID, or undefined if not found.\n */\n getAccountId(address: string): AccountId | undefined {\n return this.#idByAddress.get(address);\n }\n\n /**\n * Register a new address and generate an account ID for it.\n * If the address is already registered, returns the existing account ID.\n *\n * @param address - The address to register.\n * @returns The account ID for this address.\n */\n register(address: string): AccountId {\n const existing = this.#idByAddress.get(address);\n if (existing) {\n return existing;\n }\n const id = uuidv4();\n this.#idByAddress.set(address, id);\n return id;\n }\n\n /**\n * Add an account to the registry.\n * Also registers the address → account ID mapping.\n *\n * ⚠️ If an address was previously registered via `register()` with a\n * different account ID, calling `set()` with an account that has a new ID for\n * the same address will overwrite the address → ID mapping. The old ID\n * becomes \"dangling\" (i.e., `get(oldId)` will return undefined).\n *\n * @param account - The KeyringAccount to cache.\n */\n set(account: KeyringAccountType): void {\n this.#accountById.set(account.id, account);\n this.#idByAddress.set(account.address, account.id);\n }\n\n /**\n * Remove an account from the registry.\n *\n * @param accountId - The account ID to remove.\n */\n delete(accountId: AccountId): void {\n const account = this.#accountById.get(accountId);\n if (account) {\n this.#idByAddress.delete(account.address);\n this.#accountById.delete(accountId);\n }\n }\n\n /**\n * Clear all accounts from the registry.\n */\n clear(): void {\n this.#accountById.clear();\n this.#idByAddress.clear();\n }\n\n /**\n * Get all cached accounts as an array.\n *\n * @returns Array of all KeyringAccountType objects in the registry.\n */\n values(): KeyringAccountType[] {\n return Array.from(this.#accountById.values());\n }\n\n /**\n * Get all account IDs in the registry.\n *\n * @returns Array of all account IDs.\n */\n keys(): AccountId[] {\n return Array.from(this.#accountById.keys());\n }\n\n /**\n * Check if an account exists in the registry.\n *\n * @param accountId - The account ID to check.\n * @returns True if the account exists.\n */\n has(accountId: AccountId): boolean {\n return this.#accountById.has(accountId);\n }\n\n /**\n * Get the number of accounts in the registry.\n *\n * @returns The number of accounts.\n */\n get size(): number {\n return this.#accountById.size;\n }\n}\n"]}
1
+ {"version":3,"file":"keyring-account-registry.cjs","sourceRoot":"","sources":["../src/keyring-account-registry.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAEA,+BAAoC;AAepC;;;;;GAKG;AACH,MAAa,sBAAsB;IASjC;;;;;OAKG;IACH,YAAY,OAAuC;QAZ1C,8CAAe,IAAI,GAAG,EAAiC,EAAC;QAExD,8CAAe,IAAI,GAAG,EAAqB,EAAC;QAE5C,qDAA4C;QASnD,uBAAA,IAAI,sCAAe,OAAO,EAAE,UAAU,IAAI,CAAC,GAAc,EAAE,CAAC,IAAA,SAAM,GAAE,CAAC,MAAA,CAAC;IACxE,CAAC;IAED;;;;;OAKG;IACH,GAAG,CAAC,SAAoB;QACtB,OAAO,uBAAA,IAAI,2CAAa,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IAC1C,CAAC;IAED;;;;;OAKG;IACH,UAAU,CAAC,SAAoB;QAC7B,OAAO,uBAAA,IAAI,2CAAa,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC;IACnD,CAAC;IAED;;;;;OAKG;IACH,YAAY,CAAC,OAAe;QAC1B,OAAO,uBAAA,IAAI,2CAAa,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACxC,CAAC;IAED;;;;;;OAMG;IACH,QAAQ,CAAC,OAAe;QACtB,MAAM,QAAQ,GAAG,uBAAA,IAAI,2CAAa,CAAC,GAAG,CAAC,OAAO,CAAC,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CAAC,SAAoB;QACtB,OAAO,uBAAA,IAAI,2CAAa,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IAC1C,CAAC;IAED;;;;OAIG;IACH,IAAI,IAAI;QACN,OAAO,uBAAA,IAAI,2CAAa,CAAC,IAAI,CAAC;IAChC,CAAC;CACF;AA3ID,wDA2IC","sourcesContent":["import type { KeyringAccount } from '@metamask/keyring-api';\nimport type { AccountId } from '@metamask/keyring-utils';\nimport { v4 as uuidv4 } from 'uuid';\n\nexport type KeyringAccountRegistryOptions = {\n /**\n * Custom ID generator invoked when registering a new address.\n *\n * Receives the address being registered and must return a unique account ID.\n * Defaults to a random UUID v4 when not provided.\n *\n * @param address - The address for which to generate an account ID.\n * @returns A unique account ID string.\n */\n generateId?: (address: string) => AccountId;\n};\n\n/**\n * In-memory registry for KeyringAccount objects.\n *\n * Provides O(1) lookups by account ID or address, and stores the full\n * KeyringAccount objects for efficient retrieval.\n */\nexport class KeyringAccountRegistry<\n KeyringAccountType extends KeyringAccount = KeyringAccount,\n> {\n readonly #accountById = new Map<AccountId, KeyringAccountType>();\n\n readonly #idByAddress = new Map<string, AccountId>();\n\n readonly #generateId: (address: string) => AccountId;\n\n /**\n * Create a new KeyringAccountRegistry.\n *\n * @param options - Optional configuration.\n * @param options.generateId - Custom ID generator. Defaults to `uuidv4`.\n */\n constructor(options?: KeyringAccountRegistryOptions) {\n this.#generateId = options?.generateId ?? ((): AccountId => uuidv4());\n }\n\n /**\n * Get an account by its account ID.\n *\n * @param accountId - The account ID to look up.\n * @returns The KeyringAccount, or undefined if not found.\n */\n get(accountId: AccountId): KeyringAccountType | undefined {\n return this.#accountById.get(accountId);\n }\n\n /**\n * Get an account's address by its account ID.\n *\n * @param accountId - The account ID to look up.\n * @returns The address, or undefined if not found.\n */\n getAddress(accountId: AccountId): string | undefined {\n return this.#accountById.get(accountId)?.address;\n }\n\n /**\n * Get an account ID by the underlying address.\n *\n * @param address - The address to look up.\n * @returns The account ID, or undefined if not found.\n */\n getAccountId(address: string): AccountId | undefined {\n return this.#idByAddress.get(address);\n }\n\n /**\n * Register a new address and generate an account ID for it.\n * If the address is already registered, returns the existing account ID.\n *\n * @param address - The address to register.\n * @returns The account ID for this address.\n */\n register(address: string): AccountId {\n const existing = this.#idByAddress.get(address);\n if (existing) {\n return existing;\n }\n const id = this.#generateId(address);\n this.#idByAddress.set(address, id);\n return id;\n }\n\n /**\n * Add an account to the registry.\n * Also registers the address → account ID mapping.\n *\n * ⚠️ If an address was previously registered via `register()` with a\n * different account ID, calling `set()` with an account that has a new ID for\n * the same address will overwrite the address → ID mapping. The old ID\n * becomes \"dangling\" (i.e., `get(oldId)` will return undefined).\n *\n * @param account - The KeyringAccount to cache.\n */\n set(account: KeyringAccountType): void {\n this.#accountById.set(account.id, account);\n this.#idByAddress.set(account.address, account.id);\n }\n\n /**\n * Remove an account from the registry.\n *\n * @param accountId - The account ID to remove.\n */\n delete(accountId: AccountId): void {\n const account = this.#accountById.get(accountId);\n if (account) {\n this.#idByAddress.delete(account.address);\n this.#accountById.delete(accountId);\n }\n }\n\n /**\n * Clear all accounts from the registry.\n */\n clear(): void {\n this.#accountById.clear();\n this.#idByAddress.clear();\n }\n\n /**\n * Get all cached accounts as an array.\n *\n * @returns Array of all KeyringAccountType objects in the registry.\n */\n values(): KeyringAccountType[] {\n return Array.from(this.#accountById.values());\n }\n\n /**\n * Get all account IDs in the registry.\n *\n * @returns Array of all account IDs.\n */\n keys(): AccountId[] {\n return Array.from(this.#accountById.keys());\n }\n\n /**\n * Check if an account exists in the registry.\n *\n * @param accountId - The account ID to check.\n * @returns True if the account exists.\n */\n has(accountId: AccountId): boolean {\n return this.#accountById.has(accountId);\n }\n\n /**\n * Get the number of accounts in the registry.\n *\n * @returns The number of accounts.\n */\n get size(): number {\n return this.#accountById.size;\n }\n}\n"]}
@@ -1,5 +1,17 @@
1
1
  import type { KeyringAccount } from "@metamask/keyring-api";
2
2
  import type { AccountId } from "@metamask/keyring-utils";
3
+ export type KeyringAccountRegistryOptions = {
4
+ /**
5
+ * Custom ID generator invoked when registering a new address.
6
+ *
7
+ * Receives the address being registered and must return a unique account ID.
8
+ * Defaults to a random UUID v4 when not provided.
9
+ *
10
+ * @param address - The address for which to generate an account ID.
11
+ * @returns A unique account ID string.
12
+ */
13
+ generateId?: (address: string) => AccountId;
14
+ };
3
15
  /**
4
16
  * In-memory registry for KeyringAccount objects.
5
17
  *
@@ -8,6 +20,13 @@ import type { AccountId } from "@metamask/keyring-utils";
8
20
  */
9
21
  export declare class KeyringAccountRegistry<KeyringAccountType extends KeyringAccount = KeyringAccount> {
10
22
  #private;
23
+ /**
24
+ * Create a new KeyringAccountRegistry.
25
+ *
26
+ * @param options - Optional configuration.
27
+ * @param options.generateId - Custom ID generator. Defaults to `uuidv4`.
28
+ */
29
+ constructor(options?: KeyringAccountRegistryOptions);
11
30
  /**
12
31
  * Get an account by its account ID.
13
32
  *
@@ -1 +1 @@
1
- {"version":3,"file":"keyring-account-registry.d.cts","sourceRoot":"","sources":["../src/keyring-account-registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,8BAA8B;AAC5D,OAAO,KAAK,EAAE,SAAS,EAAE,gCAAgC;AAGzD;;;;;GAKG;AACH,qBAAa,sBAAsB,CACjC,kBAAkB,SAAS,cAAc,GAAG,cAAc;;IAM1D;;;;;OAKG;IACH,GAAG,CAAC,SAAS,EAAE,SAAS,GAAG,kBAAkB,GAAG,SAAS;IAIzD;;;;;OAKG;IACH,UAAU,CAAC,SAAS,EAAE,SAAS,GAAG,MAAM,GAAG,SAAS;IAIpD;;;;;OAKG;IACH,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS;IAIpD;;;;;;OAMG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS;IAUpC;;;;;;;;;;OAUG;IACH,GAAG,CAAC,OAAO,EAAE,kBAAkB,GAAG,IAAI;IAKtC;;;;OAIG;IACH,MAAM,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BAAkB,EAAE;IAI9B;;;;OAIG;IACH,IAAI,IAAI,SAAS,EAAE;IAInB;;;;;OAKG;IACH,GAAG,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO;IAIlC;;;;OAIG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;CACF"}
@@ -1,5 +1,17 @@
1
1
  import type { KeyringAccount } from "@metamask/keyring-api";
2
2
  import type { AccountId } from "@metamask/keyring-utils";
3
+ export type KeyringAccountRegistryOptions = {
4
+ /**
5
+ * Custom ID generator invoked when registering a new address.
6
+ *
7
+ * Receives the address being registered and must return a unique account ID.
8
+ * Defaults to a random UUID v4 when not provided.
9
+ *
10
+ * @param address - The address for which to generate an account ID.
11
+ * @returns A unique account ID string.
12
+ */
13
+ generateId?: (address: string) => AccountId;
14
+ };
3
15
  /**
4
16
  * In-memory registry for KeyringAccount objects.
5
17
  *
@@ -8,6 +20,13 @@ import type { AccountId } from "@metamask/keyring-utils";
8
20
  */
9
21
  export declare class KeyringAccountRegistry<KeyringAccountType extends KeyringAccount = KeyringAccount> {
10
22
  #private;
23
+ /**
24
+ * Create a new KeyringAccountRegistry.
25
+ *
26
+ * @param options - Optional configuration.
27
+ * @param options.generateId - Custom ID generator. Defaults to `uuidv4`.
28
+ */
29
+ constructor(options?: KeyringAccountRegistryOptions);
11
30
  /**
12
31
  * Get an account by its account ID.
13
32
  *
@@ -1 +1 @@
1
- {"version":3,"file":"keyring-account-registry.d.mts","sourceRoot":"","sources":["../src/keyring-account-registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,8BAA8B;AAC5D,OAAO,KAAK,EAAE,SAAS,EAAE,gCAAgC;AAGzD;;;;;GAKG;AACH,qBAAa,sBAAsB,CACjC,kBAAkB,SAAS,cAAc,GAAG,cAAc;;IAM1D;;;;;OAKG;IACH,GAAG,CAAC,SAAS,EAAE,SAAS,GAAG,kBAAkB,GAAG,SAAS;IAIzD;;;;;OAKG;IACH,UAAU,CAAC,SAAS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,SAAS;IAIpD;;;;;;OAMG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS;IAUpC;;;;;;;;;;OAUG;IACH,GAAG,CAAC,OAAO,EAAE,kBAAkB,GAAG,IAAI;IAKtC;;;;OAIG;IACH,MAAM,CAAC,SAAS,EAAE,SAAS,GAAG,IAAI;IAQlC;;OAEG;IACH,KAAK,IAAI,IAAI;IAKb;;;;OAIG;IACH,MAAM,IAAI,kBAAkB,EAAE;IAI9B;;;;OAIG;IACH,IAAI,IAAI,SAAS,EAAE;IAInB;;;;;OAKG;IACH,GAAG,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO;IAIlC;;;;OAIG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;CACF"}
@@ -1,9 +1,15 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
1
7
  var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
8
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
9
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
11
  };
6
- var _KeyringAccountRegistry_accountById, _KeyringAccountRegistry_idByAddress;
12
+ var _KeyringAccountRegistry_accountById, _KeyringAccountRegistry_idByAddress, _KeyringAccountRegistry_generateId;
7
13
  import { v4 as uuidv4 } from "uuid";
8
14
  /**
9
15
  * In-memory registry for KeyringAccount objects.
@@ -12,9 +18,17 @@ import { v4 as uuidv4 } from "uuid";
12
18
  * KeyringAccount objects for efficient retrieval.
13
19
  */
14
20
  export class KeyringAccountRegistry {
15
- constructor() {
21
+ /**
22
+ * Create a new KeyringAccountRegistry.
23
+ *
24
+ * @param options - Optional configuration.
25
+ * @param options.generateId - Custom ID generator. Defaults to `uuidv4`.
26
+ */
27
+ constructor(options) {
16
28
  _KeyringAccountRegistry_accountById.set(this, new Map());
17
29
  _KeyringAccountRegistry_idByAddress.set(this, new Map());
30
+ _KeyringAccountRegistry_generateId.set(this, void 0);
31
+ __classPrivateFieldSet(this, _KeyringAccountRegistry_generateId, options?.generateId ?? (() => uuidv4()), "f");
18
32
  }
19
33
  /**
20
34
  * Get an account by its account ID.
@@ -55,7 +69,7 @@ export class KeyringAccountRegistry {
55
69
  if (existing) {
56
70
  return existing;
57
71
  }
58
- const id = uuidv4();
72
+ const id = __classPrivateFieldGet(this, _KeyringAccountRegistry_generateId, "f").call(this, address);
59
73
  __classPrivateFieldGet(this, _KeyringAccountRegistry_idByAddress, "f").set(address, id);
60
74
  return id;
61
75
  }
@@ -127,5 +141,5 @@ export class KeyringAccountRegistry {
127
141
  return __classPrivateFieldGet(this, _KeyringAccountRegistry_accountById, "f").size;
128
142
  }
129
143
  }
130
- _KeyringAccountRegistry_accountById = new WeakMap(), _KeyringAccountRegistry_idByAddress = new WeakMap();
144
+ _KeyringAccountRegistry_accountById = new WeakMap(), _KeyringAccountRegistry_idByAddress = new WeakMap(), _KeyringAccountRegistry_generateId = new WeakMap();
131
145
  //# sourceMappingURL=keyring-account-registry.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"keyring-account-registry.mjs","sourceRoot":"","sources":["../src/keyring-account-registry.ts"],"names":[],"mappings":";;;;;;AAEA,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,aAAa;AAEpC;;;;;GAKG;AACH,MAAM,OAAO,sBAAsB;IAAnC;QAGW,8CAAe,IAAI,GAAG,EAAiC,EAAC;QAExD,8CAAe,IAAI,G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AA,IAAI,2CAAa,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QACtC,CAAC;IACH,CAAC;IAED;;OAEG;IACH,KAAK;QACH,uBAAA,IAAI,2CAAa,CAAC,KAAK,EAAE,CAAC;QAC1B,uBAAA,IAAI,2CAAa,CAAC,KAAK,EAAE,CAAC;IAC5B,CAAC;IAED;;;;OAIG;IACH,MAAM;QACJ,OAAO,KAAK,CAAC,IAAI,CAAC,uBAAA,IAAI,2CAAa,CAAC,MAAM,EAAE,CAAC,CAAC;IAChD,CAAC;IAED;;;;OAIG;IACH,IAAI;QACF,OAAO,KAAK,CAAC,IAAI,CAAC,uBAAA,IAAI,2CAAa,CAAC,IAAI,EAAE,CAAC,CAAC;IAC9C,CAAC;IAED;;;;;OAKG;IACH,GAAG,CAAC,SAAoB;QACtB,OAAO,uBAAA,IAAI,2CAAa,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IAC1C,CAAC;IAED;;;;OAIG;IACH,IAAI,IAAI;QACN,OAAO,uBAAA,IAAI,2CAAa,CAAC,IAAI,CAAC;IAChC,CAAC;CACF","sourcesContent":["import type { KeyringAccount } from '@metamask/keyring-api';\nimport type { AccountId } from '@metamask/keyring-utils';\nimport { v4 as uuidv4 } from 'uuid';\n\n/**\n * In-memory registry for KeyringAccount objects.\n *\n * Provides O(1) lookups by account ID or address, and stores the full\n * KeyringAccount objects for efficient retrieval.\n */\nexport class KeyringAccountRegistry<\n KeyringAccountType extends KeyringAccount = KeyringAccount,\n> {\n readonly #accountById = new Map<AccountId, KeyringAccountType>();\n\n readonly #idByAddress = new Map<string, AccountId>();\n\n /**\n * Get an account by its account ID.\n *\n * @param accountId - The account ID to look up.\n * @returns The KeyringAccount, or undefined if not found.\n */\n get(accountId: AccountId): KeyringAccountType | undefined {\n return this.#accountById.get(accountId);\n }\n\n /**\n * Get an account's address by its account ID.\n *\n * @param accountId - The account ID to look up.\n * @returns The address, or undefined if not found.\n */\n getAddress(accountId: AccountId): string | undefined {\n return this.#accountById.get(accountId)?.address;\n }\n\n /**\n * Get an account ID by the underlying address.\n *\n * @param address - The address to look up.\n * @returns The account ID, or undefined if not found.\n */\n getAccountId(address: string): AccountId | undefined {\n return this.#idByAddress.get(address);\n }\n\n /**\n * Register a new address and generate an account ID for it.\n * If the address is already registered, returns the existing account ID.\n *\n * @param address - The address to register.\n * @returns The account ID for this address.\n */\n register(address: string): AccountId {\n const existing = this.#idByAddress.get(address);\n if (existing) {\n return existing;\n }\n const id = uuidv4();\n this.#idByAddress.set(address, id);\n return id;\n }\n\n /**\n * Add an account to the registry.\n * Also registers the address → account ID mapping.\n *\n * ⚠️ If an address was previously registered via `register()` with a\n * different account ID, calling `set()` with an account that has a new ID for\n * the same address will overwrite the address → ID mapping. The old ID\n * becomes \"dangling\" (i.e., `get(oldId)` will return undefined).\n *\n * @param account - The KeyringAccount to cache.\n */\n set(account: KeyringAccountType): void {\n this.#accountById.set(account.id, account);\n this.#idByAddress.set(account.address, account.id);\n }\n\n /**\n * Remove an account from the registry.\n *\n * @param accountId - The account ID to remove.\n */\n delete(accountId: AccountId): void {\n const account = this.#accountById.get(accountId);\n if (account) {\n this.#idByAddress.delete(account.address);\n this.#accountById.delete(accountId);\n }\n }\n\n /**\n * Clear all accounts from the registry.\n */\n clear(): void {\n this.#accountById.clear();\n this.#idByAddress.clear();\n }\n\n /**\n * Get all cached accounts as an array.\n *\n * @returns Array of all KeyringAccountType objects in the registry.\n */\n values(): KeyringAccountType[] {\n return Array.from(this.#accountById.values());\n }\n\n /**\n * Get all account IDs in the registry.\n *\n * @returns Array of all account IDs.\n */\n keys(): AccountId[] {\n return Array.from(this.#accountById.keys());\n }\n\n /**\n * Check if an account exists in the registry.\n *\n * @param accountId - The account ID to check.\n * @returns True if the account exists.\n */\n has(accountId: AccountId): boolean {\n return this.#accountById.has(accountId);\n }\n\n /**\n * Get the number of accounts in the registry.\n *\n * @returns The number of accounts.\n */\n get size(): number {\n return this.#accountById.size;\n }\n}\n"]}
1
+ {"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,uBAAA,IAAI,2CAAa,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;QAC3C,uBAAA,IAAI,2CAAa,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;IACrD,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,SAAoB;QACzB,MAAM,OAAO,GAAG,uBAAA,IAAI,2CAAa,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QACjD,IAAI,OAAO,EAAE,CAAC;YACZ,uBAAA,IAAI,2CAAa,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YAC1C,uBAAA,IAAI,2CAAa,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QACtC,CAAC;IACH,CAAC;IAED;;OAEG;IACH,KAAK;QACH,uBAAA,IAAI,2CAAa,CAAC,KAAK,EAAE,CAAC;QAC1B,uBAAA,IAAI,2CAAa,CAAC,KAAK,EAAE,CAAC;IAC5B,CAAC;IAED;;;;OAIG;IACH,MAAM;QACJ,OAAO,KAAK,CAAC,IAAI,CAAC,uBAAA,IAAI,2CAAa,CAAC,MAAM,EAAE,CAAC,CAAC;IAChD,CAAC;IAED;;;;OAIG;IACH,IAAI;QACF,OAAO,KAAK,CAAC,IAAI,CAAC,uBAAA,IAAI,2CAAa,CAAC,IAAI,EAAE,CAAC,CAAC;IAC9C,CAAC;IAED;;;;;OAKG;IACH,GAAG,CAAC,SAAoB;QACtB,OAAO,uBAAA,IAAI,2CAAa,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IAC1C,CAAC;IAED;;;;OAIG;IACH,IAAI,IAAI;QACN,OAAO,uBAAA,IAAI,2CAAa,CAAC,IAAI,CAAC;IAChC,CAAC;CACF","sourcesContent":["import type { KeyringAccount } from '@metamask/keyring-api';\nimport type { AccountId } from '@metamask/keyring-utils';\nimport { v4 as uuidv4 } from 'uuid';\n\nexport type KeyringAccountRegistryOptions = {\n /**\n * Custom ID generator invoked when registering a new address.\n *\n * Receives the address being registered and must return a unique account ID.\n * Defaults to a random UUID v4 when not provided.\n *\n * @param address - The address for which to generate an account ID.\n * @returns A unique account ID string.\n */\n generateId?: (address: string) => AccountId;\n};\n\n/**\n * In-memory registry for KeyringAccount objects.\n *\n * Provides O(1) lookups by account ID or address, and stores the full\n * KeyringAccount objects for efficient retrieval.\n */\nexport class KeyringAccountRegistry<\n KeyringAccountType extends KeyringAccount = KeyringAccount,\n> {\n readonly #accountById = new Map<AccountId, KeyringAccountType>();\n\n readonly #idByAddress = new Map<string, AccountId>();\n\n readonly #generateId: (address: string) => AccountId;\n\n /**\n * Create a new KeyringAccountRegistry.\n *\n * @param options - Optional configuration.\n * @param options.generateId - Custom ID generator. Defaults to `uuidv4`.\n */\n constructor(options?: KeyringAccountRegistryOptions) {\n this.#generateId = options?.generateId ?? ((): AccountId => uuidv4());\n }\n\n /**\n * Get an account by its account ID.\n *\n * @param accountId - The account ID to look up.\n * @returns The KeyringAccount, or undefined if not found.\n */\n get(accountId: AccountId): KeyringAccountType | undefined {\n return this.#accountById.get(accountId);\n }\n\n /**\n * Get an account's address by its account ID.\n *\n * @param accountId - The account ID to look up.\n * @returns The address, or undefined if not found.\n */\n getAddress(accountId: AccountId): string | undefined {\n return this.#accountById.get(accountId)?.address;\n }\n\n /**\n * Get an account ID by the underlying address.\n *\n * @param address - The address to look up.\n * @returns The account ID, or undefined if not found.\n */\n getAccountId(address: string): AccountId | undefined {\n return this.#idByAddress.get(address);\n }\n\n /**\n * Register a new address and generate an account ID for it.\n * If the address is already registered, returns the existing account ID.\n *\n * @param address - The address to register.\n * @returns The account ID for this address.\n */\n register(address: string): AccountId {\n const existing = this.#idByAddress.get(address);\n if (existing) {\n return existing;\n }\n const id = this.#generateId(address);\n this.#idByAddress.set(address, id);\n return id;\n }\n\n /**\n * Add an account to the registry.\n * Also registers the address → account ID mapping.\n *\n * ⚠️ If an address was previously registered via `register()` with a\n * different account ID, calling `set()` with an account that has a new ID for\n * the same address will overwrite the address → ID mapping. The old ID\n * becomes \"dangling\" (i.e., `get(oldId)` will return undefined).\n *\n * @param account - The KeyringAccount to cache.\n */\n set(account: KeyringAccountType): void {\n this.#accountById.set(account.id, account);\n this.#idByAddress.set(account.address, account.id);\n }\n\n /**\n * Remove an account from the registry.\n *\n * @param accountId - The account ID to remove.\n */\n delete(accountId: AccountId): void {\n const account = this.#accountById.get(accountId);\n if (account) {\n this.#idByAddress.delete(account.address);\n this.#accountById.delete(accountId);\n }\n }\n\n /**\n * Clear all accounts from the registry.\n */\n clear(): void {\n this.#accountById.clear();\n this.#idByAddress.clear();\n }\n\n /**\n * Get all cached accounts as an array.\n *\n * @returns Array of all KeyringAccountType objects in the registry.\n */\n values(): KeyringAccountType[] {\n return Array.from(this.#accountById.values());\n }\n\n /**\n * Get all account IDs in the registry.\n *\n * @returns Array of all account IDs.\n */\n keys(): AccountId[] {\n return Array.from(this.#accountById.keys());\n }\n\n /**\n * Check if an account exists in the registry.\n *\n * @param accountId - The account ID to check.\n * @returns True if the account exists.\n */\n has(accountId: AccountId): boolean {\n return this.#accountById.has(accountId);\n }\n\n /**\n * Get the number of accounts in the registry.\n *\n * @returns The number of accounts.\n */\n get size(): number {\n return this.#accountById.size;\n }\n}\n"]}
@@ -6,6 +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("../../eth/account-id.cjs");
9
10
  const keyring_wrapper_1 = require("../keyring-wrapper.cjs");
10
11
  /**
11
12
  * Additional Ethereum methods supported by Eth keyrings that are not in the standard EthMethod enum.
@@ -19,7 +20,7 @@ var EthKeyringMethod;
19
20
  EthKeyringMethod["SignEip7702Authorization"] = "eth_signEip7702Authorization";
20
21
  })(EthKeyringMethod || (exports.EthKeyringMethod = EthKeyringMethod = {}));
21
22
  /**
22
- * 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.
23
24
  *
24
25
  * This class provides common functionality for all Ethereum keyrings including:
25
26
  * - Request handling for standard Ethereum signing methods
@@ -32,6 +33,14 @@ var EthKeyringMethod;
32
33
  * - `exportAccount()` (optional): Export private key in specified format
33
34
  */
34
35
  class EthKeyringWrapper extends keyring_wrapper_1.KeyringWrapper {
36
+ constructor(options) {
37
+ super({
38
+ ...options,
39
+ // We use a custom ID generator to ensure that account IDs are deterministic based on
40
+ // the Ethereum address.
41
+ registryOptions: { generateId: account_id_1.generateEthAccountId },
42
+ });
43
+ }
35
44
  /**
36
45
  * Helper method to safely cast a KeyringAccount address to Hex type.
37
46
  * The KeyringAccount.address is typed as string, but for Ethereum accounts
@@ -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,yDAA8D;AAE9D,uDAW+B;AAE/B,uDAA+C;AAC/C,2CAA6D;AAE7D,yDAA4D;AAC5D,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,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;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"]}
@@ -13,11 +13,15 @@ export declare enum EthKeyringMethod {
13
13
  SignEip7702Authorization = "eth_signEip7702Authorization"
14
14
  }
15
15
  /**
16
- * Options for constructing an EthKeyringWrapper.
16
+ * Options for constructing an {@link EthKeyringWrapper}.
17
+ *
18
+ * `registryOptions` is intentionally omitted: the registry is always
19
+ * configured with {@link generateEthAccountId} to produce deterministic
20
+ * account IDs for Ethereum addresses.
17
21
  */
18
- export type EthKeyringWrapperOptions<InnerKeyring extends EthKeyring> = KeyringWrapperOptions<InnerKeyring>;
22
+ export type EthKeyringWrapperOptions<InnerKeyring extends EthKeyring> = Omit<KeyringWrapperOptions<InnerKeyring>, 'registryOptions'>;
19
23
  /**
20
- * 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.
21
25
  *
22
26
  * This class provides common functionality for all Ethereum keyrings including:
23
27
  * - Request handling for standard Ethereum signing methods
@@ -30,6 +34,7 @@ export type EthKeyringWrapperOptions<InnerKeyring extends EthKeyring> = KeyringW
30
34
  * - `exportAccount()` (optional): Export private key in specified format
31
35
  */
32
36
  export declare abstract class EthKeyringWrapper<InnerKeyring extends EthKeyring, KeyringAccountType extends KeyringAccount = KeyringAccount> extends KeyringWrapper<InnerKeyring, KeyringAccountType> {
37
+ constructor(options: EthKeyringWrapperOptions<InnerKeyring>);
33
38
  /**
34
39
  * Helper method to safely cast a KeyringAccount address to Hex type.
35
40
  * The KeyringAccount.address is typed as string, but for Ethereum accounts