@metamask/keyring-sdk 2.0.2 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [2.1.1]
11
+
12
+ ### Changed
13
+
14
+ - Bump `@metamask/keyring-utils` from `^3.3.0` to `^3.3.1` ([#546](https://github.com/MetaMask/accounts/pull/546))
15
+
16
+ ## [2.1.0]
17
+
18
+ ### Added
19
+
20
+ - Add `KeyringV1Adapter` ([#543](https://github.com/MetaMask/accounts/pull/543))
21
+ - This adapter can be used when a keyring v2 instance has no v1 equivalent (`KeyringController` still rely on v1 logic for its vault/state management).
22
+
23
+ ### Changed
24
+
25
+ - Bump `@metamask/keyring-utils` from `^3.2.0` to `^3.3.0` ([#544](https://github.com/MetaMask/accounts/pull/544))
26
+
10
27
  ## [2.0.2]
11
28
 
12
29
  ### Changed
@@ -61,7 +78,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
61
78
 
62
79
  - Initial release, extracted from `@metamask/keyring-api` ([#478](https://github.com/MetaMask/accounts/pull/478)), ([#482](https://github.com/MetaMask/accounts/pull/482))
63
80
 
64
- [Unreleased]: https://github.com/MetaMask/accounts/compare/@metamask/keyring-sdk@2.0.2...HEAD
81
+ [Unreleased]: https://github.com/MetaMask/accounts/compare/@metamask/keyring-sdk@2.1.1...HEAD
82
+ [2.1.1]: https://github.com/MetaMask/accounts/compare/@metamask/keyring-sdk@2.1.0...@metamask/keyring-sdk@2.1.1
83
+ [2.1.0]: https://github.com/MetaMask/accounts/compare/@metamask/keyring-sdk@2.0.2...@metamask/keyring-sdk@2.1.0
65
84
  [2.0.2]: https://github.com/MetaMask/accounts/compare/@metamask/keyring-sdk@2.0.1...@metamask/keyring-sdk@2.0.2
66
85
  [2.0.1]: https://github.com/MetaMask/accounts/compare/@metamask/keyring-sdk@2.0.0...@metamask/keyring-sdk@2.0.1
67
86
  [2.0.0]: https://github.com/MetaMask/accounts/compare/@metamask/keyring-sdk@1.2.0...@metamask/keyring-sdk@2.0.0
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateEthAccountId = generateEthAccountId;
3
+ exports.generateEthAccountId = void 0;
4
4
  const eth_sig_util_1 = require("@metamask/eth-sig-util");
5
5
  const utils_1 = require("@metamask/utils");
6
6
  const sha256_1 = require("ethereum-cryptography/sha256");
@@ -24,4 +24,5 @@ function generateEthAccountId(address) {
24
24
  random: (0, sha256_1.sha256)((0, utils_1.hexToBytes)(normalized)).slice(0, 16),
25
25
  });
26
26
  }
27
+ exports.generateEthAccountId = generateEthAccountId;
27
28
  //# sourceMappingURL=account-id.cjs.map
@@ -1 +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"]}
1
+ {"version":3,"file":"account-id.cjs","sourceRoot":"","sources":["../../src/eth/account-id.ts"],"names":[],"mappings":";;;AAAA,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;AALD,oDAKC","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"]}
package/dist/mnemonic.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.encodeMnemonic = encodeMnemonic;
3
+ exports.encodeMnemonic = void 0;
4
4
  const english_1 = require("@metamask/scure-bip39/dist/wordlists/english.js");
5
5
  /**
6
6
  * Encodes a mnemonic as an array of bytes (UTF-8).
@@ -17,4 +17,5 @@ function encodeMnemonic(mnemonicIndicesBytes) {
17
17
  const mnemonic = mnemonicIndices.map((i) => english_1.wordlist[i]).join(' ');
18
18
  return Array.from(new TextEncoder().encode(mnemonic));
19
19
  }
20
+ exports.encodeMnemonic = encodeMnemonic;
20
21
  //# sourceMappingURL=mnemonic.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"mnemonic.cjs","sourceRoot":"","sources":["../src/mnemonic.ts"],"names":[],"mappings":";;AAQA,wCASC;AAjBD,6EAAwE;AAExE;;;;;GAKG;AACH,SAAgB,cAAc,CAAC,oBAAgC;IAC7D,MAAM,eAAe,GAAG,KAAK,CAAC,IAAI;IAChC,0EAA0E;IAC1E,iEAAiE;IACjE,oBAAoB;IACpB,IAAI,WAAW,CAAC,IAAI,UAAU,CAAC,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAC7D,CAAC;IACF,MAAM,QAAQ,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,kBAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACnE,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;AACxD,CAAC","sourcesContent":["import { wordlist } from '@metamask/scure-bip39/dist/wordlists/english';\n\n/**\n * Encodes a mnemonic as an array of bytes (UTF-8).\n *\n * @param mnemonicIndicesBytes - An array of bytes (16-bit unsigned integers) representing the indices of the words in the mnemonic.\n * @returns An array of bytes (UTF-8) representing the mnemonic.\n */\nexport function encodeMnemonic(mnemonicIndicesBytes: Uint8Array): number[] {\n const mnemonicIndices = Array.from(\n // Create a new `Uint8Array` to ensure we have a proper view on the buffer\n // without having to worry about `byteOffset` and `byteLength` of\n // the inner buffer.\n new Uint16Array(new Uint8Array(mnemonicIndicesBytes).buffer),\n );\n const mnemonic = mnemonicIndices.map((i) => wordlist[i]).join(' ');\n return Array.from(new TextEncoder().encode(mnemonic));\n}\n"]}
1
+ {"version":3,"file":"mnemonic.cjs","sourceRoot":"","sources":["../src/mnemonic.ts"],"names":[],"mappings":";;;AAAA,6EAAwE;AAExE;;;;;GAKG;AACH,SAAgB,cAAc,CAAC,oBAAgC;IAC7D,MAAM,eAAe,GAAG,KAAK,CAAC,IAAI;IAChC,0EAA0E;IAC1E,iEAAiE;IACjE,oBAAoB;IACpB,IAAI,WAAW,CAAC,IAAI,UAAU,CAAC,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAC7D,CAAC;IACF,MAAM,QAAQ,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,kBAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACnE,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;AACxD,CAAC;AATD,wCASC","sourcesContent":["import { wordlist } from '@metamask/scure-bip39/dist/wordlists/english';\n\n/**\n * Encodes a mnemonic as an array of bytes (UTF-8).\n *\n * @param mnemonicIndicesBytes - An array of bytes (16-bit unsigned integers) representing the indices of the words in the mnemonic.\n * @returns An array of bytes (UTF-8) representing the mnemonic.\n */\nexport function encodeMnemonic(mnemonicIndicesBytes: Uint8Array): number[] {\n const mnemonicIndices = Array.from(\n // Create a new `Uint8Array` to ensure we have a proper view on the buffer\n // without having to worry about `byteOffset` and `byteLength` of\n // the inner buffer.\n new Uint16Array(new Uint8Array(mnemonicIndicesBytes).buffer),\n );\n const mnemonic = mnemonicIndices.map((i) => wordlist[i]).join(' ');\n return Array.from(new TextEncoder().encode(mnemonic));\n}\n"]}
package/dist/v2/index.cjs CHANGED
@@ -14,6 +14,7 @@ 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-v1-adapter.cjs"), exports);
17
18
  __exportStar(require("./keyring-wrapper.cjs"), exports);
18
19
  __exportStar(require("./eth/index.cjs"), exports);
19
20
  //# sourceMappingURL=index.cjs.map
@@ -1 +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"]}
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/v2/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2DAAqC;AACrC,wDAAkC;AAClC,kDAAsB","sourcesContent":["export * from './keyring-v1-adapter';\nexport * from './keyring-wrapper';\nexport * from './eth';\n"]}
@@ -1,3 +1,4 @@
1
+ export * from "./keyring-v1-adapter.cjs";
1
2
  export * from "./keyring-wrapper.cjs";
2
3
  export * from "./eth/index.cjs";
3
4
  //# sourceMappingURL=index.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../src/v2/index.ts"],"names":[],"mappings":"AAAA,sCAAkC;AAClC,gCAAsB"}
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../src/v2/index.ts"],"names":[],"mappings":"AAAA,yCAAqC;AACrC,sCAAkC;AAClC,gCAAsB"}
@@ -1,3 +1,4 @@
1
+ export * from "./keyring-v1-adapter.mjs";
1
2
  export * from "./keyring-wrapper.mjs";
2
3
  export * from "./eth/index.mjs";
3
4
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/v2/index.ts"],"names":[],"mappings":"AAAA,sCAAkC;AAClC,gCAAsB"}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/v2/index.ts"],"names":[],"mappings":"AAAA,yCAAqC;AACrC,sCAAkC;AAClC,gCAAsB"}
package/dist/v2/index.mjs CHANGED
@@ -1,3 +1,4 @@
1
+ export * from "./keyring-v1-adapter.mjs";
1
2
  export * from "./keyring-wrapper.mjs";
2
3
  export * from "./eth/index.mjs";
3
4
  //# sourceMappingURL=index.mjs.map
@@ -1 +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"]}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/v2/index.ts"],"names":[],"mappings":"AAAA,yCAAqC;AACrC,sCAAkC;AAClC,gCAAsB","sourcesContent":["export * from './keyring-v1-adapter';\nexport * from './keyring-wrapper';\nexport * from './eth';\n"]}
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _KeyringV1Adapter_inner;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.KeyringV1Adapter = void 0;
16
+ /**
17
+ * Generic adapter that wraps a v2 {@link KeyringV2} instance and exposes it
18
+ * through the v1 {@link BaseKeyring} interface expected by `KeyringController`.
19
+ *
20
+ * ## Why this exists
21
+ *
22
+ * `KeyringController` interacts with all keyrings via the v1 `BaseKeyring`
23
+ * interface — notably `getAccounts()` which must return `Promise<string[]>`
24
+ * (addresses). The v2 `Keyring` interface returns `Promise<KeyringAccount[]>`
25
+ * from `getAccounts()`, an incompatible signature.
26
+ *
27
+ * ## Architecture
28
+ *
29
+ * This class holds a v2 `Keyring` instance and exposes it via {@link unwrap}.
30
+ * `KeyringController` stores this adapter as the v1 keyring entry; its
31
+ * `KeyringV2Builder` calls `unwrap()` to retrieve the same inner instance for
32
+ * the v2 entry — no state duplication.
33
+ *
34
+ * ```
35
+ * KeyringEntry {
36
+ * keyring: KeyringV1Adapter ← v1 face (this class)
37
+ * keyringV2: InnerKeyring ← v2 face (same instance via unwrap())
38
+ * }
39
+ * ```
40
+ *
41
+ * @typeParam InnerKeyring - The concrete v2 keyring type being wrapped.
42
+ * Defaults to the base {@link KeyringV2} interface. Specifying a concrete
43
+ * subtype preserves full type information through {@link unwrap}.
44
+ */
45
+ class KeyringV1Adapter {
46
+ constructor(inner) {
47
+ _KeyringV1Adapter_inner.set(this, void 0);
48
+ __classPrivateFieldSet(this, _KeyringV1Adapter_inner, inner, "f");
49
+ this.type = inner.type;
50
+ }
51
+ /**
52
+ * Returns the inner v2 {@link KeyringV2} instance.
53
+ *
54
+ * Intended for use by `KeyringController`'s `KeyringV2Builder` so that both
55
+ * the v1 and v2 keyring entries in a `KeyringEntry` share the same object.
56
+ *
57
+ * @returns The inner v2 keyring instance.
58
+ */
59
+ unwrap() {
60
+ return __classPrivateFieldGet(this, _KeyringV1Adapter_inner, "f");
61
+ }
62
+ /**
63
+ * Returns the addresses of all accounts in this keyring.
64
+ *
65
+ * Adapts the v2 `getAccounts()` (which returns `KeyringAccount[]`) to the
66
+ * v1 `BaseKeyring` interface (`string[]`).
67
+ *
68
+ * @returns A promise resolving to the list of account addresses.
69
+ */
70
+ async getAccounts() {
71
+ const accounts = await __classPrivateFieldGet(this, _KeyringV1Adapter_inner, "f").getAccounts();
72
+ return accounts.map((account) => account.address);
73
+ }
74
+ /**
75
+ * Serializes the keyring state.
76
+ *
77
+ * Delegates to the inner v2 instance.
78
+ *
79
+ * @returns A promise resolving to the serialized state.
80
+ */
81
+ async serialize() {
82
+ return __classPrivateFieldGet(this, _KeyringV1Adapter_inner, "f").serialize();
83
+ }
84
+ /**
85
+ * Restores keyring state from a serialized snapshot.
86
+ *
87
+ * Delegates to the inner v2 instance.
88
+ *
89
+ * @param state - The serialized state to restore.
90
+ * @returns A promise that resolves when deserialization is complete.
91
+ */
92
+ async deserialize(state) {
93
+ return __classPrivateFieldGet(this, _KeyringV1Adapter_inner, "f").deserialize(state);
94
+ }
95
+ }
96
+ exports.KeyringV1Adapter = KeyringV1Adapter;
97
+ _KeyringV1Adapter_inner = new WeakMap();
98
+ //# sourceMappingURL=keyring-v1-adapter.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyring-v1-adapter.cjs","sourceRoot":"","sources":["../../src/v2/keyring-v1-adapter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAKA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAa,gBAAgB;IAU3B,YAAY,KAAmB;QAFtB,0CAAqB;QAG5B,uBAAA,IAAI,2BAAU,KAAK,MAAA,CAAC;QACpB,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC;IACzB,CAAC;IAED;;;;;;;OAOG;IACH,MAAM;QACJ,OAAO,uBAAA,IAAI,+BAAO,CAAC;IACrB,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,WAAW;QACf,MAAM,QAAQ,GAAG,MAAM,uBAAA,IAAI,+BAAO,CAAC,WAAW,EAAE,CAAC;QACjD,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAuB,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IACpE,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,SAAS;QACb,OAAO,uBAAA,IAAI,+BAAO,CAAC,SAAS,EAAE,CAAC;IACjC,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,WAAW,CAAC,KAAW;QAC3B,OAAO,uBAAA,IAAI,+BAAO,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IACxC,CAAC;CACF;AA9DD,4CA8DC","sourcesContent":["import type { KeyringAccount } from '@metamask/keyring-api';\nimport type { Keyring as KeyringV2 } from '@metamask/keyring-api/v2';\nimport type { BaseKeyring } from '@metamask/keyring-utils';\nimport type { Json } from '@metamask/utils';\n\n/**\n * Generic adapter that wraps a v2 {@link KeyringV2} instance and exposes it\n * through the v1 {@link BaseKeyring} interface expected by `KeyringController`.\n *\n * ## Why this exists\n *\n * `KeyringController` interacts with all keyrings via the v1 `BaseKeyring`\n * interface — notably `getAccounts()` which must return `Promise<string[]>`\n * (addresses). The v2 `Keyring` interface returns `Promise<KeyringAccount[]>`\n * from `getAccounts()`, an incompatible signature.\n *\n * ## Architecture\n *\n * This class holds a v2 `Keyring` instance and exposes it via {@link unwrap}.\n * `KeyringController` stores this adapter as the v1 keyring entry; its\n * `KeyringV2Builder` calls `unwrap()` to retrieve the same inner instance for\n * the v2 entry — no state duplication.\n *\n * ```\n * KeyringEntry {\n * keyring: KeyringV1Adapter ← v1 face (this class)\n * keyringV2: InnerKeyring ← v2 face (same instance via unwrap())\n * }\n * ```\n *\n * @typeParam InnerKeyring - The concrete v2 keyring type being wrapped.\n * Defaults to the base {@link KeyringV2} interface. Specifying a concrete\n * subtype preserves full type information through {@link unwrap}.\n */\nexport class KeyringV1Adapter<\n InnerKeyring extends KeyringV2 = KeyringV2,\n> implements BaseKeyring {\n /**\n * Keyring type identifier, mirroring the inner v2 instance's type.\n */\n readonly type: string;\n\n readonly #inner: InnerKeyring;\n\n constructor(inner: InnerKeyring) {\n this.#inner = inner;\n this.type = inner.type;\n }\n\n /**\n * Returns the inner v2 {@link KeyringV2} instance.\n *\n * Intended for use by `KeyringController`'s `KeyringV2Builder` so that both\n * the v1 and v2 keyring entries in a `KeyringEntry` share the same object.\n *\n * @returns The inner v2 keyring instance.\n */\n unwrap(): InnerKeyring {\n return this.#inner;\n }\n\n /**\n * Returns the addresses of all accounts in this keyring.\n *\n * Adapts the v2 `getAccounts()` (which returns `KeyringAccount[]`) to the\n * v1 `BaseKeyring` interface (`string[]`).\n *\n * @returns A promise resolving to the list of account addresses.\n */\n async getAccounts(): Promise<string[]> {\n const accounts = await this.#inner.getAccounts();\n return accounts.map((account: KeyringAccount) => account.address);\n }\n\n /**\n * Serializes the keyring state.\n *\n * Delegates to the inner v2 instance.\n *\n * @returns A promise resolving to the serialized state.\n */\n async serialize(): Promise<Json> {\n return this.#inner.serialize();\n }\n\n /**\n * Restores keyring state from a serialized snapshot.\n *\n * Delegates to the inner v2 instance.\n *\n * @param state - The serialized state to restore.\n * @returns A promise that resolves when deserialization is complete.\n */\n async deserialize(state: Json): Promise<void> {\n return this.#inner.deserialize(state);\n }\n}\n"]}
@@ -0,0 +1,76 @@
1
+ import type { Keyring as KeyringV2 } from "@metamask/keyring-api/v2";
2
+ import type { BaseKeyring } from "@metamask/keyring-utils";
3
+ import type { Json } from "@metamask/utils";
4
+ /**
5
+ * Generic adapter that wraps a v2 {@link KeyringV2} instance and exposes it
6
+ * through the v1 {@link BaseKeyring} interface expected by `KeyringController`.
7
+ *
8
+ * ## Why this exists
9
+ *
10
+ * `KeyringController` interacts with all keyrings via the v1 `BaseKeyring`
11
+ * interface — notably `getAccounts()` which must return `Promise<string[]>`
12
+ * (addresses). The v2 `Keyring` interface returns `Promise<KeyringAccount[]>`
13
+ * from `getAccounts()`, an incompatible signature.
14
+ *
15
+ * ## Architecture
16
+ *
17
+ * This class holds a v2 `Keyring` instance and exposes it via {@link unwrap}.
18
+ * `KeyringController` stores this adapter as the v1 keyring entry; its
19
+ * `KeyringV2Builder` calls `unwrap()` to retrieve the same inner instance for
20
+ * the v2 entry — no state duplication.
21
+ *
22
+ * ```
23
+ * KeyringEntry {
24
+ * keyring: KeyringV1Adapter ← v1 face (this class)
25
+ * keyringV2: InnerKeyring ← v2 face (same instance via unwrap())
26
+ * }
27
+ * ```
28
+ *
29
+ * @typeParam InnerKeyring - The concrete v2 keyring type being wrapped.
30
+ * Defaults to the base {@link KeyringV2} interface. Specifying a concrete
31
+ * subtype preserves full type information through {@link unwrap}.
32
+ */
33
+ export declare class KeyringV1Adapter<InnerKeyring extends KeyringV2 = KeyringV2> implements BaseKeyring {
34
+ #private;
35
+ /**
36
+ * Keyring type identifier, mirroring the inner v2 instance's type.
37
+ */
38
+ readonly type: string;
39
+ constructor(inner: InnerKeyring);
40
+ /**
41
+ * Returns the inner v2 {@link KeyringV2} instance.
42
+ *
43
+ * Intended for use by `KeyringController`'s `KeyringV2Builder` so that both
44
+ * the v1 and v2 keyring entries in a `KeyringEntry` share the same object.
45
+ *
46
+ * @returns The inner v2 keyring instance.
47
+ */
48
+ unwrap(): InnerKeyring;
49
+ /**
50
+ * Returns the addresses of all accounts in this keyring.
51
+ *
52
+ * Adapts the v2 `getAccounts()` (which returns `KeyringAccount[]`) to the
53
+ * v1 `BaseKeyring` interface (`string[]`).
54
+ *
55
+ * @returns A promise resolving to the list of account addresses.
56
+ */
57
+ getAccounts(): Promise<string[]>;
58
+ /**
59
+ * Serializes the keyring state.
60
+ *
61
+ * Delegates to the inner v2 instance.
62
+ *
63
+ * @returns A promise resolving to the serialized state.
64
+ */
65
+ serialize(): Promise<Json>;
66
+ /**
67
+ * Restores keyring state from a serialized snapshot.
68
+ *
69
+ * Delegates to the inner v2 instance.
70
+ *
71
+ * @param state - The serialized state to restore.
72
+ * @returns A promise that resolves when deserialization is complete.
73
+ */
74
+ deserialize(state: Json): Promise<void>;
75
+ }
76
+ //# sourceMappingURL=keyring-v1-adapter.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyring-v1-adapter.d.cts","sourceRoot":"","sources":["../../src/v2/keyring-v1-adapter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,IAAI,SAAS,EAAE,iCAAiC;AACrE,OAAO,KAAK,EAAE,WAAW,EAAE,gCAAgC;AAC3D,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAE5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,qBAAa,gBAAgB,CAC3B,YAAY,SAAS,SAAS,GAAG,SAAS,CAC1C,YAAW,WAAW;;IACtB;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAIV,KAAK,EAAE,YAAY;IAK/B;;;;;;;OAOG;IACH,MAAM,IAAI,YAAY;IAItB;;;;;;;OAOG;IACG,WAAW,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAKtC;;;;;;OAMG;IACG,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAIhC;;;;;;;OAOG;IACG,WAAW,CAAC,KAAK,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;CAG9C"}
@@ -0,0 +1,76 @@
1
+ import type { Keyring as KeyringV2 } from "@metamask/keyring-api/v2";
2
+ import type { BaseKeyring } from "@metamask/keyring-utils";
3
+ import type { Json } from "@metamask/utils";
4
+ /**
5
+ * Generic adapter that wraps a v2 {@link KeyringV2} instance and exposes it
6
+ * through the v1 {@link BaseKeyring} interface expected by `KeyringController`.
7
+ *
8
+ * ## Why this exists
9
+ *
10
+ * `KeyringController` interacts with all keyrings via the v1 `BaseKeyring`
11
+ * interface — notably `getAccounts()` which must return `Promise<string[]>`
12
+ * (addresses). The v2 `Keyring` interface returns `Promise<KeyringAccount[]>`
13
+ * from `getAccounts()`, an incompatible signature.
14
+ *
15
+ * ## Architecture
16
+ *
17
+ * This class holds a v2 `Keyring` instance and exposes it via {@link unwrap}.
18
+ * `KeyringController` stores this adapter as the v1 keyring entry; its
19
+ * `KeyringV2Builder` calls `unwrap()` to retrieve the same inner instance for
20
+ * the v2 entry — no state duplication.
21
+ *
22
+ * ```
23
+ * KeyringEntry {
24
+ * keyring: KeyringV1Adapter ← v1 face (this class)
25
+ * keyringV2: InnerKeyring ← v2 face (same instance via unwrap())
26
+ * }
27
+ * ```
28
+ *
29
+ * @typeParam InnerKeyring - The concrete v2 keyring type being wrapped.
30
+ * Defaults to the base {@link KeyringV2} interface. Specifying a concrete
31
+ * subtype preserves full type information through {@link unwrap}.
32
+ */
33
+ export declare class KeyringV1Adapter<InnerKeyring extends KeyringV2 = KeyringV2> implements BaseKeyring {
34
+ #private;
35
+ /**
36
+ * Keyring type identifier, mirroring the inner v2 instance's type.
37
+ */
38
+ readonly type: string;
39
+ constructor(inner: InnerKeyring);
40
+ /**
41
+ * Returns the inner v2 {@link KeyringV2} instance.
42
+ *
43
+ * Intended for use by `KeyringController`'s `KeyringV2Builder` so that both
44
+ * the v1 and v2 keyring entries in a `KeyringEntry` share the same object.
45
+ *
46
+ * @returns The inner v2 keyring instance.
47
+ */
48
+ unwrap(): InnerKeyring;
49
+ /**
50
+ * Returns the addresses of all accounts in this keyring.
51
+ *
52
+ * Adapts the v2 `getAccounts()` (which returns `KeyringAccount[]`) to the
53
+ * v1 `BaseKeyring` interface (`string[]`).
54
+ *
55
+ * @returns A promise resolving to the list of account addresses.
56
+ */
57
+ getAccounts(): Promise<string[]>;
58
+ /**
59
+ * Serializes the keyring state.
60
+ *
61
+ * Delegates to the inner v2 instance.
62
+ *
63
+ * @returns A promise resolving to the serialized state.
64
+ */
65
+ serialize(): Promise<Json>;
66
+ /**
67
+ * Restores keyring state from a serialized snapshot.
68
+ *
69
+ * Delegates to the inner v2 instance.
70
+ *
71
+ * @param state - The serialized state to restore.
72
+ * @returns A promise that resolves when deserialization is complete.
73
+ */
74
+ deserialize(state: Json): Promise<void>;
75
+ }
76
+ //# sourceMappingURL=keyring-v1-adapter.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyring-v1-adapter.d.mts","sourceRoot":"","sources":["../../src/v2/keyring-v1-adapter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,IAAI,SAAS,EAAE,iCAAiC;AACrE,OAAO,KAAK,EAAE,WAAW,EAAE,gCAAgC;AAC3D,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAE5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,qBAAa,gBAAgB,CAC3B,YAAY,SAAS,SAAS,GAAG,SAAS,CAC1C,YAAW,WAAW;;IACtB;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAIV,KAAK,EAAE,YAAY;IAK/B;;;;;;;OAOG;IACH,MAAM,IAAI,YAAY;IAItB;;;;;;;OAOG;IACG,WAAW,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAKtC;;;;;;OAMG;IACG,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAIhC;;;;;;;OAOG;IACG,WAAW,CAAC,KAAK,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;CAG9C"}
@@ -0,0 +1,94 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _KeyringV1Adapter_inner;
13
+ /**
14
+ * Generic adapter that wraps a v2 {@link KeyringV2} instance and exposes it
15
+ * through the v1 {@link BaseKeyring} interface expected by `KeyringController`.
16
+ *
17
+ * ## Why this exists
18
+ *
19
+ * `KeyringController` interacts with all keyrings via the v1 `BaseKeyring`
20
+ * interface — notably `getAccounts()` which must return `Promise<string[]>`
21
+ * (addresses). The v2 `Keyring` interface returns `Promise<KeyringAccount[]>`
22
+ * from `getAccounts()`, an incompatible signature.
23
+ *
24
+ * ## Architecture
25
+ *
26
+ * This class holds a v2 `Keyring` instance and exposes it via {@link unwrap}.
27
+ * `KeyringController` stores this adapter as the v1 keyring entry; its
28
+ * `KeyringV2Builder` calls `unwrap()` to retrieve the same inner instance for
29
+ * the v2 entry — no state duplication.
30
+ *
31
+ * ```
32
+ * KeyringEntry {
33
+ * keyring: KeyringV1Adapter ← v1 face (this class)
34
+ * keyringV2: InnerKeyring ← v2 face (same instance via unwrap())
35
+ * }
36
+ * ```
37
+ *
38
+ * @typeParam InnerKeyring - The concrete v2 keyring type being wrapped.
39
+ * Defaults to the base {@link KeyringV2} interface. Specifying a concrete
40
+ * subtype preserves full type information through {@link unwrap}.
41
+ */
42
+ export class KeyringV1Adapter {
43
+ constructor(inner) {
44
+ _KeyringV1Adapter_inner.set(this, void 0);
45
+ __classPrivateFieldSet(this, _KeyringV1Adapter_inner, inner, "f");
46
+ this.type = inner.type;
47
+ }
48
+ /**
49
+ * Returns the inner v2 {@link KeyringV2} instance.
50
+ *
51
+ * Intended for use by `KeyringController`'s `KeyringV2Builder` so that both
52
+ * the v1 and v2 keyring entries in a `KeyringEntry` share the same object.
53
+ *
54
+ * @returns The inner v2 keyring instance.
55
+ */
56
+ unwrap() {
57
+ return __classPrivateFieldGet(this, _KeyringV1Adapter_inner, "f");
58
+ }
59
+ /**
60
+ * Returns the addresses of all accounts in this keyring.
61
+ *
62
+ * Adapts the v2 `getAccounts()` (which returns `KeyringAccount[]`) to the
63
+ * v1 `BaseKeyring` interface (`string[]`).
64
+ *
65
+ * @returns A promise resolving to the list of account addresses.
66
+ */
67
+ async getAccounts() {
68
+ const accounts = await __classPrivateFieldGet(this, _KeyringV1Adapter_inner, "f").getAccounts();
69
+ return accounts.map((account) => account.address);
70
+ }
71
+ /**
72
+ * Serializes the keyring state.
73
+ *
74
+ * Delegates to the inner v2 instance.
75
+ *
76
+ * @returns A promise resolving to the serialized state.
77
+ */
78
+ async serialize() {
79
+ return __classPrivateFieldGet(this, _KeyringV1Adapter_inner, "f").serialize();
80
+ }
81
+ /**
82
+ * Restores keyring state from a serialized snapshot.
83
+ *
84
+ * Delegates to the inner v2 instance.
85
+ *
86
+ * @param state - The serialized state to restore.
87
+ * @returns A promise that resolves when deserialization is complete.
88
+ */
89
+ async deserialize(state) {
90
+ return __classPrivateFieldGet(this, _KeyringV1Adapter_inner, "f").deserialize(state);
91
+ }
92
+ }
93
+ _KeyringV1Adapter_inner = new WeakMap();
94
+ //# sourceMappingURL=keyring-v1-adapter.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyring-v1-adapter.mjs","sourceRoot":"","sources":["../../src/v2/keyring-v1-adapter.ts"],"names":[],"mappings":";;;;;;;;;;;;AAKA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,OAAO,gBAAgB;IAU3B,YAAY,KAAmB;QAFtB,0CAAqB;QAG5B,uBAAA,IAAI,2BAAU,KAAK,MAAA,CAAC;QACpB,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC;IACzB,CAAC;IAED;;;;;;;OAOG;IACH,MAAM;QACJ,OAAO,uBAAA,IAAI,+BAAO,CAAC;IACrB,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,WAAW;QACf,MAAM,QAAQ,GAAG,MAAM,uBAAA,IAAI,+BAAO,CAAC,WAAW,EAAE,CAAC;QACjD,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAuB,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IACpE,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,SAAS;QACb,OAAO,uBAAA,IAAI,+BAAO,CAAC,SAAS,EAAE,CAAC;IACjC,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,WAAW,CAAC,KAAW;QAC3B,OAAO,uBAAA,IAAI,+BAAO,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IACxC,CAAC;CACF","sourcesContent":["import type { KeyringAccount } from '@metamask/keyring-api';\nimport type { Keyring as KeyringV2 } from '@metamask/keyring-api/v2';\nimport type { BaseKeyring } from '@metamask/keyring-utils';\nimport type { Json } from '@metamask/utils';\n\n/**\n * Generic adapter that wraps a v2 {@link KeyringV2} instance and exposes it\n * through the v1 {@link BaseKeyring} interface expected by `KeyringController`.\n *\n * ## Why this exists\n *\n * `KeyringController` interacts with all keyrings via the v1 `BaseKeyring`\n * interface — notably `getAccounts()` which must return `Promise<string[]>`\n * (addresses). The v2 `Keyring` interface returns `Promise<KeyringAccount[]>`\n * from `getAccounts()`, an incompatible signature.\n *\n * ## Architecture\n *\n * This class holds a v2 `Keyring` instance and exposes it via {@link unwrap}.\n * `KeyringController` stores this adapter as the v1 keyring entry; its\n * `KeyringV2Builder` calls `unwrap()` to retrieve the same inner instance for\n * the v2 entry — no state duplication.\n *\n * ```\n * KeyringEntry {\n * keyring: KeyringV1Adapter ← v1 face (this class)\n * keyringV2: InnerKeyring ← v2 face (same instance via unwrap())\n * }\n * ```\n *\n * @typeParam InnerKeyring - The concrete v2 keyring type being wrapped.\n * Defaults to the base {@link KeyringV2} interface. Specifying a concrete\n * subtype preserves full type information through {@link unwrap}.\n */\nexport class KeyringV1Adapter<\n InnerKeyring extends KeyringV2 = KeyringV2,\n> implements BaseKeyring {\n /**\n * Keyring type identifier, mirroring the inner v2 instance's type.\n */\n readonly type: string;\n\n readonly #inner: InnerKeyring;\n\n constructor(inner: InnerKeyring) {\n this.#inner = inner;\n this.type = inner.type;\n }\n\n /**\n * Returns the inner v2 {@link KeyringV2} instance.\n *\n * Intended for use by `KeyringController`'s `KeyringV2Builder` so that both\n * the v1 and v2 keyring entries in a `KeyringEntry` share the same object.\n *\n * @returns The inner v2 keyring instance.\n */\n unwrap(): InnerKeyring {\n return this.#inner;\n }\n\n /**\n * Returns the addresses of all accounts in this keyring.\n *\n * Adapts the v2 `getAccounts()` (which returns `KeyringAccount[]`) to the\n * v1 `BaseKeyring` interface (`string[]`).\n *\n * @returns A promise resolving to the list of account addresses.\n */\n async getAccounts(): Promise<string[]> {\n const accounts = await this.#inner.getAccounts();\n return accounts.map((account: KeyringAccount) => account.address);\n }\n\n /**\n * Serializes the keyring state.\n *\n * Delegates to the inner v2 instance.\n *\n * @returns A promise resolving to the serialized state.\n */\n async serialize(): Promise<Json> {\n return this.#inner.serialize();\n }\n\n /**\n * Restores keyring state from a serialized snapshot.\n *\n * Delegates to the inner v2 instance.\n *\n * @param state - The serialized state to restore.\n * @returns A promise that resolves when deserialization is complete.\n */\n async deserialize(state: Json): Promise<void> {\n return this.#inner.deserialize(state);\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/keyring-sdk",
3
- "version": "2.0.2",
3
+ "version": "2.1.1",
4
4
  "description": "MetaMask Keyring SDK",
5
5
  "keywords": [
6
6
  "keyring",
@@ -69,7 +69,7 @@
69
69
  "@ethereumjs/tx": "^5.4.0",
70
70
  "@metamask/eth-sig-util": "^8.2.0",
71
71
  "@metamask/keyring-api": "^23.1.0",
72
- "@metamask/keyring-utils": "^3.2.0",
72
+ "@metamask/keyring-utils": "^3.3.1",
73
73
  "@metamask/scure-bip39": "^2.1.1",
74
74
  "@metamask/superstruct": "^3.1.0",
75
75
  "@metamask/utils": "^11.11.0",
@@ -94,7 +94,7 @@
94
94
  "ts-node": "^10.9.2",
95
95
  "tsd": "^0.31.0",
96
96
  "typedoc": "^0.25.13",
97
- "typescript": "~5.6.3"
97
+ "typescript": "~5.3.3"
98
98
  },
99
99
  "tsd": {
100
100
  "compilerOptions": {