@metamask/keyring-sdk 4.0.0 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -1
- package/dist/v2/keyring-v1-adapter.cjs +26 -1
- package/dist/v2/keyring-v1-adapter.cjs.map +1 -1
- package/dist/v2/keyring-v1-adapter.d.cts +15 -0
- package/dist/v2/keyring-v1-adapter.d.cts.map +1 -1
- package/dist/v2/keyring-v1-adapter.d.mts +15 -0
- package/dist/v2/keyring-v1-adapter.d.mts.map +1 -1
- package/dist/v2/keyring-v1-adapter.mjs +24 -0
- package/dist/v2/keyring-v1-adapter.mjs.map +1 -1
- package/package.json +2 -3
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [4.1.0]
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Add `isKeyringV1Adapter` type guard ([#685](https://github.com/MetaMask/accounts/pull/685))
|
|
15
|
+
- Use this instead of doing type checks with `instanceof`.
|
|
16
|
+
|
|
17
|
+
### Changed
|
|
18
|
+
|
|
19
|
+
- Bump `@metamask/keyring-api` from `^24.2.0` to `^24.3.0` ([#674](https://github.com/MetaMask/accounts/pull/674))
|
|
20
|
+
|
|
10
21
|
## [4.0.0]
|
|
11
22
|
|
|
12
23
|
### Changed
|
|
@@ -130,7 +141,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
130
141
|
|
|
131
142
|
- Initial release, extracted from `@metamask/keyring-api` ([#478](https://github.com/MetaMask/accounts/pull/478), [#482](https://github.com/MetaMask/accounts/pull/482))
|
|
132
143
|
|
|
133
|
-
[Unreleased]: https://github.com/MetaMask/accounts/compare/@metamask/keyring-sdk@4.
|
|
144
|
+
[Unreleased]: https://github.com/MetaMask/accounts/compare/@metamask/keyring-sdk@4.1.0...HEAD
|
|
145
|
+
[4.1.0]: https://github.com/MetaMask/accounts/compare/@metamask/keyring-sdk@4.0.0...@metamask/keyring-sdk@4.1.0
|
|
134
146
|
[4.0.0]: https://github.com/MetaMask/accounts/compare/@metamask/keyring-sdk@3.1.0...@metamask/keyring-sdk@4.0.0
|
|
135
147
|
[3.1.0]: https://github.com/MetaMask/accounts/compare/@metamask/keyring-sdk@3.0.0...@metamask/keyring-sdk@3.1.0
|
|
136
148
|
[3.0.0]: https://github.com/MetaMask/accounts/compare/@metamask/keyring-sdk@2.3.0...@metamask/keyring-sdk@3.0.0
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.KeyringV1Adapter = void 0;
|
|
3
|
+
exports.isKeyringV1Adapter = exports.KeyringV1Adapter = void 0;
|
|
4
|
+
const utils_1 = require("@metamask/utils");
|
|
4
5
|
/**
|
|
5
6
|
* Generic adapter that wraps a v2 {@link KeyringV2} instance and exposes it
|
|
6
7
|
* through the v1 {@link BaseKeyring} interface expected by `KeyringController`.
|
|
@@ -81,4 +82,28 @@ class KeyringV1Adapter {
|
|
|
81
82
|
}
|
|
82
83
|
}
|
|
83
84
|
exports.KeyringV1Adapter = KeyringV1Adapter;
|
|
85
|
+
/**
|
|
86
|
+
* Check whether the given value is a {@link KeyringV1Adapter}, including
|
|
87
|
+
* subclasses such as `EthKeyringV1Adapter` or `SnapKeyringV1Adapter`.
|
|
88
|
+
*
|
|
89
|
+
* This is a structural check on the adapter's public surface, not an
|
|
90
|
+
* `instanceof` check: a consumer may hold a different copy of this package
|
|
91
|
+
* than the one that constructed the adapter (a split dependency tree), in
|
|
92
|
+
* which case `instanceof` is always `false`. `unwrap` is the distinguishing
|
|
93
|
+
* API — no v1 or v2 keyring exposes it — and it is the method consumers call
|
|
94
|
+
* to retrieve the inner v2 instance.
|
|
95
|
+
*
|
|
96
|
+
* @param value - The value to check.
|
|
97
|
+
* @returns Whether the value is a `KeyringV1Adapter`.
|
|
98
|
+
*/
|
|
99
|
+
function isKeyringV1Adapter(value) {
|
|
100
|
+
if (!(0, utils_1.isObject)(value)) {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
// Property access rather than `hasProperty`: `unwrap` is a prototype
|
|
104
|
+
// method, not an own property, so own-property checks miss it.
|
|
105
|
+
const { type, unwrap } = value;
|
|
106
|
+
return typeof type === 'string' && typeof unwrap === 'function';
|
|
107
|
+
}
|
|
108
|
+
exports.isKeyringV1Adapter = isKeyringV1Adapter;
|
|
84
109
|
//# sourceMappingURL=keyring-v1-adapter.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyring-v1-adapter.cjs","sourceRoot":"","sources":["../../src/v2/keyring-v1-adapter.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"keyring-v1-adapter.cjs","sourceRoot":"","sources":["../../src/v2/keyring-v1-adapter.ts"],"names":[],"mappings":";;;AAGA,2CAA2C;AAG3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAa,gBAAgB;IAU3B,YAAY,KAAmB;QAC7B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC;IACzB,CAAC;IAED;;;;;;;OAOG;IACH,MAAM;QACJ,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,WAAW;QACf,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC;QAChD,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,IAAI,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC;IAChC,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,WAAW,CAAC,KAAW;QAC3B,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IACvC,CAAC;CACF;AA9DD,4CA8DC;AAED;;;;;;;;;;;;;GAaG;AACH,SAAgB,kBAAkB,CAChC,KAAc;IAEd,IAAI,CAAC,IAAA,gBAAQ,EAAC,KAAK,CAAC,EAAE,CAAC;QACrB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,qEAAqE;IACrE,+DAA+D;IAC/D,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,KAA6C,CAAC;IAEvE,OAAO,OAAO,IAAI,KAAK,QAAQ,IAAI,OAAO,MAAM,KAAK,UAAU,CAAC;AAClE,CAAC;AAZD,gDAYC","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 { isObject } from '@metamask/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 protected 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\n/**\n * Check whether the given value is a {@link KeyringV1Adapter}, including\n * subclasses such as `EthKeyringV1Adapter` or `SnapKeyringV1Adapter`.\n *\n * This is a structural check on the adapter's public surface, not an\n * `instanceof` check: a consumer may hold a different copy of this package\n * than the one that constructed the adapter (a split dependency tree), in\n * which case `instanceof` is always `false`. `unwrap` is the distinguishing\n * API — no v1 or v2 keyring exposes it — and it is the method consumers call\n * to retrieve the inner v2 instance.\n *\n * @param value - The value to check.\n * @returns Whether the value is a `KeyringV1Adapter`.\n */\nexport function isKeyringV1Adapter<InnerKeyring extends KeyringV2 = KeyringV2>(\n value: unknown,\n): value is KeyringV1Adapter<InnerKeyring> {\n if (!isObject(value)) {\n return false;\n }\n\n // Property access rather than `hasProperty`: `unwrap` is a prototype\n // method, not an own property, so own-property checks miss it.\n const { type, unwrap } = value as { type?: unknown; unwrap?: unknown };\n\n return typeof type === 'string' && typeof unwrap === 'function';\n}\n"]}
|
|
@@ -73,4 +73,19 @@ export declare class KeyringV1Adapter<InnerKeyring extends KeyringV2 = KeyringV2
|
|
|
73
73
|
*/
|
|
74
74
|
deserialize(state: Json): Promise<void>;
|
|
75
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Check whether the given value is a {@link KeyringV1Adapter}, including
|
|
78
|
+
* subclasses such as `EthKeyringV1Adapter` or `SnapKeyringV1Adapter`.
|
|
79
|
+
*
|
|
80
|
+
* This is a structural check on the adapter's public surface, not an
|
|
81
|
+
* `instanceof` check: a consumer may hold a different copy of this package
|
|
82
|
+
* than the one that constructed the adapter (a split dependency tree), in
|
|
83
|
+
* which case `instanceof` is always `false`. `unwrap` is the distinguishing
|
|
84
|
+
* API — no v1 or v2 keyring exposes it — and it is the method consumers call
|
|
85
|
+
* to retrieve the inner v2 instance.
|
|
86
|
+
*
|
|
87
|
+
* @param value - The value to check.
|
|
88
|
+
* @returns Whether the value is a `KeyringV1Adapter`.
|
|
89
|
+
*/
|
|
90
|
+
export declare function isKeyringV1Adapter<InnerKeyring extends KeyringV2 = KeyringV2>(value: unknown): value is KeyringV1Adapter<InnerKeyring>;
|
|
76
91
|
//# sourceMappingURL=keyring-v1-adapter.d.cts.map
|
|
@@ -1 +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;
|
|
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;AAE3D,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;IAEtB,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC;gBAE3B,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;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kBAAkB,CAAC,YAAY,SAAS,SAAS,GAAG,SAAS,EAC3E,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,gBAAgB,CAAC,YAAY,CAAC,CAUzC"}
|
|
@@ -73,4 +73,19 @@ export declare class KeyringV1Adapter<InnerKeyring extends KeyringV2 = KeyringV2
|
|
|
73
73
|
*/
|
|
74
74
|
deserialize(state: Json): Promise<void>;
|
|
75
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Check whether the given value is a {@link KeyringV1Adapter}, including
|
|
78
|
+
* subclasses such as `EthKeyringV1Adapter` or `SnapKeyringV1Adapter`.
|
|
79
|
+
*
|
|
80
|
+
* This is a structural check on the adapter's public surface, not an
|
|
81
|
+
* `instanceof` check: a consumer may hold a different copy of this package
|
|
82
|
+
* than the one that constructed the adapter (a split dependency tree), in
|
|
83
|
+
* which case `instanceof` is always `false`. `unwrap` is the distinguishing
|
|
84
|
+
* API — no v1 or v2 keyring exposes it — and it is the method consumers call
|
|
85
|
+
* to retrieve the inner v2 instance.
|
|
86
|
+
*
|
|
87
|
+
* @param value - The value to check.
|
|
88
|
+
* @returns Whether the value is a `KeyringV1Adapter`.
|
|
89
|
+
*/
|
|
90
|
+
export declare function isKeyringV1Adapter<InnerKeyring extends KeyringV2 = KeyringV2>(value: unknown): value is KeyringV1Adapter<InnerKeyring>;
|
|
76
91
|
//# sourceMappingURL=keyring-v1-adapter.d.mts.map
|
|
@@ -1 +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;
|
|
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;AAE3D,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;IAEtB,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC;gBAE3B,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;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kBAAkB,CAAC,YAAY,SAAS,SAAS,GAAG,SAAS,EAC3E,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,gBAAgB,CAAC,YAAY,CAAC,CAUzC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isObject } from "@metamask/utils";
|
|
1
2
|
/**
|
|
2
3
|
* Generic adapter that wraps a v2 {@link KeyringV2} instance and exposes it
|
|
3
4
|
* through the v1 {@link BaseKeyring} interface expected by `KeyringController`.
|
|
@@ -77,4 +78,27 @@ export class KeyringV1Adapter {
|
|
|
77
78
|
return this.inner.deserialize(state);
|
|
78
79
|
}
|
|
79
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* Check whether the given value is a {@link KeyringV1Adapter}, including
|
|
83
|
+
* subclasses such as `EthKeyringV1Adapter` or `SnapKeyringV1Adapter`.
|
|
84
|
+
*
|
|
85
|
+
* This is a structural check on the adapter's public surface, not an
|
|
86
|
+
* `instanceof` check: a consumer may hold a different copy of this package
|
|
87
|
+
* than the one that constructed the adapter (a split dependency tree), in
|
|
88
|
+
* which case `instanceof` is always `false`. `unwrap` is the distinguishing
|
|
89
|
+
* API — no v1 or v2 keyring exposes it — and it is the method consumers call
|
|
90
|
+
* to retrieve the inner v2 instance.
|
|
91
|
+
*
|
|
92
|
+
* @param value - The value to check.
|
|
93
|
+
* @returns Whether the value is a `KeyringV1Adapter`.
|
|
94
|
+
*/
|
|
95
|
+
export function isKeyringV1Adapter(value) {
|
|
96
|
+
if (!isObject(value)) {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
// Property access rather than `hasProperty`: `unwrap` is a prototype
|
|
100
|
+
// method, not an own property, so own-property checks miss it.
|
|
101
|
+
const { type, unwrap } = value;
|
|
102
|
+
return typeof type === 'string' && typeof unwrap === 'function';
|
|
103
|
+
}
|
|
80
104
|
//# sourceMappingURL=keyring-v1-adapter.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyring-v1-adapter.mjs","sourceRoot":"","sources":["../../src/v2/keyring-v1-adapter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"keyring-v1-adapter.mjs","sourceRoot":"","sources":["../../src/v2/keyring-v1-adapter.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,wBAAwB;AAG3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,OAAO,gBAAgB;IAU3B,YAAY,KAAmB;QAC7B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC;IACzB,CAAC;IAED;;;;;;;OAOG;IACH,MAAM;QACJ,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,WAAW;QACf,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC;QAChD,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,IAAI,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC;IAChC,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,WAAW,CAAC,KAAW;QAC3B,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IACvC,CAAC;CACF;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,kBAAkB,CAChC,KAAc;IAEd,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QACrB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,qEAAqE;IACrE,+DAA+D;IAC/D,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,KAA6C,CAAC;IAEvE,OAAO,OAAO,IAAI,KAAK,QAAQ,IAAI,OAAO,MAAM,KAAK,UAAU,CAAC;AAClE,CAAC","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 { isObject } from '@metamask/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 protected 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\n/**\n * Check whether the given value is a {@link KeyringV1Adapter}, including\n * subclasses such as `EthKeyringV1Adapter` or `SnapKeyringV1Adapter`.\n *\n * This is a structural check on the adapter's public surface, not an\n * `instanceof` check: a consumer may hold a different copy of this package\n * than the one that constructed the adapter (a split dependency tree), in\n * which case `instanceof` is always `false`. `unwrap` is the distinguishing\n * API — no v1 or v2 keyring exposes it — and it is the method consumers call\n * to retrieve the inner v2 instance.\n *\n * @param value - The value to check.\n * @returns Whether the value is a `KeyringV1Adapter`.\n */\nexport function isKeyringV1Adapter<InnerKeyring extends KeyringV2 = KeyringV2>(\n value: unknown,\n): value is KeyringV1Adapter<InnerKeyring> {\n if (!isObject(value)) {\n return false;\n }\n\n // Property access rather than `hasProperty`: `unwrap` is a prototype\n // method, not an own property, so own-property checks miss it.\n const { type, unwrap } = value as { type?: unknown; unwrap?: unknown };\n\n return typeof type === 'string' && typeof unwrap === 'function';\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/keyring-sdk",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "MetaMask Keyring SDK",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"keyring",
|
|
@@ -56,7 +56,6 @@
|
|
|
56
56
|
"build:docs": "typedoc",
|
|
57
57
|
"changelog:update": "../../scripts/update-changelog.sh @metamask/keyring-sdk",
|
|
58
58
|
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/keyring-sdk",
|
|
59
|
-
"publish:preview": "yarn npm publish --tag preview",
|
|
60
59
|
"since-latest-release": "../../scripts/since-latest-release.sh",
|
|
61
60
|
"test": "yarn test:source && yarn test:types",
|
|
62
61
|
"test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",
|
|
@@ -68,7 +67,7 @@
|
|
|
68
67
|
"dependencies": {
|
|
69
68
|
"@ethereumjs/tx": "^5.4.0",
|
|
70
69
|
"@metamask/eth-sig-util": "^9.0.0",
|
|
71
|
-
"@metamask/keyring-api": "^24.
|
|
70
|
+
"@metamask/keyring-api": "^24.3.0",
|
|
72
71
|
"@metamask/keyring-utils": "^5.0.0",
|
|
73
72
|
"@metamask/scure-bip39": "^2.1.1",
|
|
74
73
|
"@metamask/superstruct": "^3.4.1",
|