@metamask-previews/eth-simple-keyring 11.1.2-5c366be → 12.0.1-7275dbc

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 (38) hide show
  1. package/CHANGELOG.md +30 -1
  2. package/README.md +8 -7
  3. package/dist/index.cjs +1 -3
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.d.cts +0 -1
  6. package/dist/index.d.cts.map +1 -1
  7. package/dist/index.d.mts +0 -1
  8. package/dist/index.d.mts.map +1 -1
  9. package/dist/index.mjs +0 -1
  10. package/dist/index.mjs.map +1 -1
  11. package/dist/simple-keyring.cjs.map +1 -1
  12. package/dist/simple-keyring.d.cts +2 -1
  13. package/dist/simple-keyring.d.cts.map +1 -1
  14. package/dist/simple-keyring.d.mts +2 -1
  15. package/dist/simple-keyring.d.mts.map +1 -1
  16. package/dist/simple-keyring.mjs.map +1 -1
  17. package/dist/v2/index.cjs +6 -0
  18. package/dist/v2/index.cjs.map +1 -0
  19. package/dist/v2/index.d.cts +2 -0
  20. package/dist/v2/index.d.cts.map +1 -0
  21. package/dist/v2/index.d.mts +2 -0
  22. package/dist/v2/index.d.mts.map +1 -0
  23. package/dist/v2/index.mjs +2 -0
  24. package/dist/v2/index.mjs.map +1 -0
  25. package/dist/{simple-keyring-v2.cjs → v2/simple-keyring.cjs} +39 -38
  26. package/dist/v2/simple-keyring.cjs.map +1 -0
  27. package/dist/{simple-keyring-v2.d.mts → v2/simple-keyring.d.cts} +10 -9
  28. package/dist/v2/simple-keyring.d.cts.map +1 -0
  29. package/dist/{simple-keyring-v2.d.cts → v2/simple-keyring.d.mts} +10 -9
  30. package/dist/v2/simple-keyring.d.mts.map +1 -0
  31. package/dist/{simple-keyring-v2.mjs → v2/simple-keyring.mjs} +25 -24
  32. package/dist/v2/simple-keyring.mjs.map +1 -0
  33. package/package.json +42 -23
  34. package/v2.js +3 -0
  35. package/dist/simple-keyring-v2.cjs.map +0 -1
  36. package/dist/simple-keyring-v2.d.cts.map +0 -1
  37. package/dist/simple-keyring-v2.d.mts.map +0 -1
  38. package/dist/simple-keyring-v2.mjs.map +0 -1
package/CHANGELOG.md CHANGED
@@ -7,6 +7,33 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [12.0.1]
11
+
12
+ ### Changed
13
+
14
+ - Bump `@metamask/keyring-api` from `^23.0.0` to `^23.0.1` ([#518](https://github.com/MetaMask/accounts/pull/518))
15
+ - Bump `@metamask/keyring-sdk` from `^2.0.0` to `^2.0.1` ([#518](https://github.com/MetaMask/accounts/pull/518))
16
+
17
+ ### Fixed
18
+
19
+ - Workaround Browserify subpath export for `/v2` ([#516](https://github.com/MetaMask/accounts/pull/516))
20
+
21
+ ## [12.0.0]
22
+
23
+ ### Added
24
+
25
+ - Add `./v2` subpath export for keyring v2 implementation ([#513](https://github.com/MetaMask/accounts/pull/513))
26
+ - `SimpleKeyring` and `SimpleKeyringOptions` are now available from `@metamask/eth-simple-keyring/v2`.
27
+
28
+ ### Changed
29
+
30
+ - **BREAKING:** Move and rename `SimpleKeyringV2` and `SimpleKeyringV2Options` to the new `./v2` subpath export ([#513](https://github.com/MetaMask/accounts/pull/513))
31
+ - `SimpleKeyringV2` is now `SimpleKeyring` from `@metamask/eth-simple-keyring/v2`.
32
+ - `SimpleKeyringV2Options` is now `SimpleKeyringOptions` from `@metamask/eth-simple-keyring/v2`.
33
+ - Bump `@metamask/utils` from `^11.10.0` to `^11.11.0` ([#483](https://github.com/MetaMask/accounts/pull/483))
34
+ - Bump `@metamask/keyring-api` from `^22.0.0` to `^23.0.0` ([#515](https://github.com/MetaMask/accounts/pull/515))
35
+ - Bump `@metamask/keyring-sdk` from `^1.2.0` to `^2.0.0` ([#515](https://github.com/MetaMask/accounts/pull/515))
36
+
10
37
  ## [11.1.2]
11
38
 
12
39
  ### Changed
@@ -178,7 +205,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
178
205
  - **BREAKING:** Remove redundant `newGethSignMessage` method ([#72](https://github.com/MetaMask/eth-simple-keyring/pull/72))
179
206
  - Consumers can use `signPersonalMessage` method as a replacement for `newGethSignMessage`.
180
207
 
181
- [Unreleased]: https://github.com/MetaMask/accounts/compare/@metamask/eth-simple-keyring@11.1.2...HEAD
208
+ [Unreleased]: https://github.com/MetaMask/accounts/compare/@metamask/eth-simple-keyring@12.0.1...HEAD
209
+ [12.0.1]: https://github.com/MetaMask/accounts/compare/@metamask/eth-simple-keyring@12.0.0...@metamask/eth-simple-keyring@12.0.1
210
+ [12.0.0]: https://github.com/MetaMask/accounts/compare/@metamask/eth-simple-keyring@11.1.2...@metamask/eth-simple-keyring@12.0.0
182
211
  [11.1.2]: https://github.com/MetaMask/accounts/compare/@metamask/eth-simple-keyring@11.1.1...@metamask/eth-simple-keyring@11.1.2
183
212
  [11.1.1]: https://github.com/MetaMask/accounts/compare/@metamask/eth-simple-keyring@11.1.0...@metamask/eth-simple-keyring@11.1.1
184
213
  [11.1.0]: https://github.com/MetaMask/accounts/compare/@metamask/eth-simple-keyring@11.0.0...@metamask/eth-simple-keyring@11.1.0
package/README.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Simple Keyring
2
2
 
3
+ ## Installation
4
+
5
+ `yarn add @metamask/eth-simple-keyring`
6
+
7
+ or
8
+
9
+ `npm install @metamask/eth-simple-keyring`
10
+
3
11
  A simple JS class wrapped around [ethereumjs-wallet](https://github.com/ethereumjs/ethereumjs-wallet) designed to expose an interface common to many different signing strategies to be used in a `KeyringController`; such as the one used in [MetaMask](https://metamask.io/)
4
12
 
5
13
  ## The Keyring Class Protocol
@@ -99,35 +107,28 @@ Run `yarn lint` to run the linter, or run `yarn lint:fix` to run the linter and
99
107
  The project follows the same release process as the other libraries in the MetaMask organization. The GitHub Actions [`action-create-release-pr`](https://github.com/MetaMask/action-create-release-pr) and [`action-publish-release`](https://github.com/MetaMask/action-publish-release) are used to automate the release process; see those repositories for more information about how they work.
100
108
 
101
109
  1. Choose a release version.
102
-
103
110
  - The release version should be chosen according to SemVer. Analyze the changes to see whether they include any breaking changes, new features, or deprecations, then choose the appropriate SemVer version. See [the SemVer specification](https://semver.org/) for more information.
104
111
 
105
112
  2. If this release is backporting changes onto a previous release, then ensure there is a major version branch for that version (e.g. `1.x` for a `v1` backport release).
106
-
107
113
  - The major version branch should be set to the most recent release with that major version. For example, when backporting a `v1.0.2` release, you'd want to ensure there was a `1.x` branch that was set to the `v1.0.1` tag.
108
114
 
109
115
  3. Trigger the [`workflow_dispatch`](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#workflow_dispatch) event [manually](https://docs.github.com/en/actions/managing-workflow-runs/manually-running-a-workflow) for the `Create Release Pull Request` action to create the release PR.
110
-
111
116
  - For a backport release, the base branch should be the major version branch that you ensured existed in step 2. For a normal release, the base branch should be the main branch for that repository (which should be the default value).
112
117
  - This should trigger the [`action-create-release-pr`](https://github.com/MetaMask/action-create-release-pr) workflow to create the release PR.
113
118
 
114
119
  4. Update the changelog to move each change entry into the appropriate change category ([See here](https://keepachangelog.com/en/1.0.0/#types) for the full list of change categories, and the correct ordering), and edit them to be more easily understood by users of the package.
115
-
116
120
  - Generally any changes that don't affect consumers of the package (e.g. lockfile changes or development environment changes) are omitted. Exceptions may be made for changes that might be of interest despite not having an effect upon the published package (e.g. major test improvements, security improvements, improved documentation, etc.).
117
121
  - Try to explain each change in terms that users of the package would understand (e.g. avoid referencing internal variables/concepts).
118
122
  - Consolidate related changes into one change entry if it makes it easier to explain.
119
123
  - Run `yarn auto-changelog validate --rc` to check that the changelog is correctly formatted.
120
124
 
121
125
  5. Review and QA the release.
122
-
123
126
  - If changes are made to the base branch, the release branch will need to be updated with these changes and review/QA will need to restart again. As such, it's probably best to avoid merging other PRs into the base branch while review is underway.
124
127
 
125
128
  6. Squash & Merge the release.
126
-
127
129
  - This should trigger the [`action-publish-release`](https://github.com/MetaMask/action-publish-release) workflow to tag the final release commit and publish the release on GitHub.
128
130
 
129
131
  7. Publish the release on npm.
130
-
131
132
  - Be very careful to use a clean local environment to publish the release, and follow exactly the same steps used during CI.
132
133
  - Use `npm publish --dry-run` to examine the release contents to ensure the correct files are included. Compare to previous releases if necessary (e.g. using `https://unpkg.com/browse/[package name]@[package version]/`).
133
134
  - Once you are confident the release contents are correct, publish the release using `npm publish`.
package/dist/index.cjs CHANGED
@@ -3,9 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.SimpleKeyringV2 = exports.default = void 0;
6
+ exports.default = void 0;
7
7
  var simple_keyring_1 = require("./simple-keyring.cjs");
8
8
  Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(simple_keyring_1).default; } });
9
- var simple_keyring_v2_1 = require("./simple-keyring-v2.cjs");
10
- Object.defineProperty(exports, "SimpleKeyringV2", { enumerable: true, get: function () { return simple_keyring_v2_1.SimpleKeyringV2; } });
11
9
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,uDAA2C;AAAlC,0HAAA,OAAO,OAAA;AAChB,6DAG6B;AAF3B,oHAAA,eAAe,OAAA","sourcesContent":["export { default } from './simple-keyring';\nexport {\n SimpleKeyringV2,\n type SimpleKeyringV2Options,\n} from './simple-keyring-v2';\n"]}
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,uDAA2C;AAAlC,0HAAA,OAAO,OAAA","sourcesContent":["export { default } from './simple-keyring';\n"]}
package/dist/index.d.cts CHANGED
@@ -1,3 +1,2 @@
1
1
  export { default } from "./simple-keyring.cjs";
2
- export { SimpleKeyringV2, type SimpleKeyringV2Options, } from "./simple-keyring-v2.cjs";
3
2
  //# sourceMappingURL=index.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,6BAAyB;AAC3C,OAAO,EACL,eAAe,EACf,KAAK,sBAAsB,GAC5B,gCAA4B"}
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,6BAAyB"}
package/dist/index.d.mts CHANGED
@@ -1,3 +1,2 @@
1
1
  export { default } from "./simple-keyring.mjs";
2
- export { SimpleKeyringV2, type SimpleKeyringV2Options, } from "./simple-keyring-v2.mjs";
3
2
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,6BAAyB;AAC3C,OAAO,EACL,eAAe,EACf,KAAK,sBAAsB,GAC5B,gCAA4B"}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,6BAAyB"}
package/dist/index.mjs CHANGED
@@ -1,3 +1,2 @@
1
1
  export { default } from "./simple-keyring.mjs";
2
- export { SimpleKeyringV2 } from "./simple-keyring-v2.mjs";
3
2
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,6BAAyB;AAC3C,OAAO,EACL,eAAe,EAEhB,gCAA4B","sourcesContent":["export { default } from './simple-keyring';\nexport {\n SimpleKeyringV2,\n type SimpleKeyringV2Options,\n} from './simple-keyring-v2';\n"]}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,6BAAyB","sourcesContent":["export { default } from './simple-keyring';\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"simple-keyring.cjs","sourceRoot":"","sources":["../src/simple-keyring.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AACA,2CAM0B;AAC1B,yDAagC;AAEhC,2CAMyB;AACzB,yDAAyD;AACzD,8DAAsC;AAYtC,MAAM,IAAI,GAAG,iBAAiB,CAAC;AAE/B,iDAAiD;AACjD,MAAqB,aAAa;IAOhC,YAAY,cAAwB,EAAE;;QANtC,yCAAsD;QAE7C,SAAI,GAAW,IAAI,CAAC;QAK3B,uBAAA,IAAI,0BAAY,EAAE,MAAA,CAAC;QAEnB;iHACyG;QACzG,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC,KAAK,CAAC,CAAC,KAAY,EAAE,EAAE;YACnD,MAAM,IAAI,KAAK,CAAC,uCAAuC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QAC1E,CAAC,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,SAAS;QACb,OAAO,uBAAA,IAAI,8BAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;IAChE,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,WAAqB;QACrC,uBAAA,IAAI,0BAAY,WAAW,CAAC,GAAG,CAAC,CAAC,aAAa,EAAE,EAAE;YAChD,MAAM,qBAAqB,GAAG,IAAA,qBAAc,EAAC,aAAa,CAAC,CAAC;YAC5D,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,qBAAqB,EAAE,KAAK,CAAC,CAAC;YAC7D,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,IAAA,sBAAe,EAAC,UAAU,CAAC,CAAC,CAAC;YAC3D,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC;QACnC,CAAC,CAAC,MAAA,CAAC;IACL,CAAC;IAED,KAAK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,GAAG,IAAA,sBAAe,EAAC,gBAAgB,CAAC,CAAC;QAC1D,MAAM,GAAG;YACP,UAAU,EAAE,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC;YACzC,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC;SACxC,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AArNM,kBAAI,GAAW,IAAI,AAAf,CAAgB;kBALR,aAAa;AA6NlC;;;;GAIG;AACH,SAAS,WAAW;IAClB,MAAM,UAAU,GAAG,IAAA,qBAAW,EAAC,EAAE,CAAC,CAAC;IAEnC,IAAI,CAAC,IAAA,qBAAc,EAAC,UAAU,CAAC,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CACb,yEAAyE,CAC1E,CAAC;IACJ,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC;AAED;;;;;GAKG;AACH,2CAA2C;AAC3C,SAAS,sBAAsB,CAC7B,OAAsC;IAEtC,OAAO,OAAO,IAAI,mCAAoB,CAAC;AACzC,CAAC","sourcesContent":["import { TypedTransaction } from '@ethereumjs/tx';\nimport {\n ecsign,\n isValidPrivate,\n privateToPublic,\n publicToAddress,\n stripHexPrefix,\n} from '@ethereumjs/util';\nimport {\n type TypedDataV1,\n type MessageTypes,\n type TypedMessage,\n concatSig,\n decrypt,\n EIP7702Authorization,\n getEncryptionPublicKey,\n normalize,\n personalSign,\n signEIP7702Authorization,\n signTypedData,\n SignTypedDataVersion,\n} from '@metamask/eth-sig-util';\nimport { Keyring } from '@metamask/keyring-utils';\nimport {\n add0x,\n bigIntToBytes,\n bytesToHex,\n Eip1024EncryptedData,\n Hex,\n} from '@metamask/utils';\nimport { keccak256 } from 'ethereum-cryptography/keccak';\nimport randombytes from 'randombytes';\n\ntype KeyringOpt = {\n withAppKeyOrigin?: string;\n version?: SignTypedDataVersion | string;\n};\n\ntype Wallet = {\n privateKey: Buffer;\n publicKey: Buffer;\n};\n\nconst TYPE = 'Simple Key Pair';\n\n// FIXME: This should not be exported as default.\nexport default class SimpleKeyring implements Keyring {\n #wallets: { privateKey: Buffer; publicKey: Buffer }[];\n\n readonly type: string = TYPE;\n\n static type: string = TYPE;\n\n constructor(privateKeys: string[] = []) {\n this.#wallets = [];\n\n /* istanbul ignore next: It's not possible to write a unit test for this, because a constructor isn't allowed\n * to be async. Jest can't await the constructor, and when the error gets thrown, Jest can't catch it. */\n this.deserialize(privateKeys).catch((error: Error) => {\n throw new Error(`Problem deserializing SimpleKeyring ${error.message}`);\n });\n }\n\n async serialize(): Promise<string[]> {\n return this.#wallets.map((a) => a.privateKey.toString('hex'));\n }\n\n async deserialize(privateKeys: string[]): Promise<void> {\n this.#wallets = privateKeys.map((hexPrivateKey) => {\n const strippedHexPrivateKey = stripHexPrefix(hexPrivateKey);\n const privateKey = Buffer.from(strippedHexPrivateKey, 'hex');\n const publicKey = Buffer.from(privateToPublic(privateKey));\n return { privateKey, publicKey };\n });\n }\n\n async addAccounts(numAccounts = 1): Promise<Hex[]> {\n const newWallets = [];\n for (let i = 0; i < numAccounts; i++) {\n const privateKey = generateKey();\n const publicKey = Buffer.from(privateToPublic(privateKey));\n newWallets.push({ privateKey, publicKey });\n }\n this.#wallets = this.#wallets.concat(newWallets);\n const hexWallets = newWallets.map(({ publicKey }) =>\n add0x(bytesToHex(publicToAddress(publicKey))),\n );\n return hexWallets;\n }\n\n async getAccounts(): Promise<Hex[]> {\n return this.#wallets.map(({ publicKey }) =>\n add0x(bytesToHex(publicToAddress(publicKey))),\n );\n }\n\n async signTransaction(\n address: Hex,\n transaction: TypedTransaction,\n opts: KeyringOpt = {},\n ): Promise<TypedTransaction> {\n const privKey = this.#getPrivateKeyFor(address, opts);\n const signedTx = transaction.sign(privKey);\n // Newer versions of Ethereumjs-tx are immutable and return a new tx object\n return signedTx ?? transaction;\n }\n\n async signEip7702Authorization(\n address: Hex,\n authorization: EIP7702Authorization,\n opts: KeyringOpt = {},\n ): Promise<string> {\n const privateKey = this.#getPrivateKeyFor(address, opts);\n return signEIP7702Authorization({ privateKey, authorization });\n }\n\n // For eth_sign, we need to sign arbitrary data:\n async signMessage(\n address: Hex,\n data: string,\n opts = { withAppKeyOrigin: '', validateMessage: true },\n ): Promise<string> {\n const message = stripHexPrefix(data);\n if (\n opts.validateMessage &&\n (message.length === 0 || !message.match(/^[a-fA-F0-9]*$/u))\n ) {\n throw new Error('Cannot sign invalid message');\n }\n const privKey = this.#getPrivateKeyFor(address, opts);\n const msgSig = ecsign(Buffer.from(message, 'hex'), privKey);\n const rawMsgSig = concatSig(\n Buffer.from(bigIntToBytes(msgSig.v)),\n Buffer.from(msgSig.r),\n Buffer.from(msgSig.s),\n );\n return rawMsgSig;\n }\n\n // For personal_sign, we need to prefix the message:\n async signPersonalMessage(\n address: Hex,\n msgHex: Hex,\n opts = { withAppKeyOrigin: '' },\n ): Promise<string> {\n const privKey = this.#getPrivateKeyFor(address, opts);\n return personalSign({ privateKey: privKey, data: msgHex });\n }\n\n // For eth_decryptMessage:\n async decryptMessage(\n withAccount: Hex,\n encryptedData: Eip1024EncryptedData,\n ): Promise<string> {\n const wallet = this.#getWalletForAccount(withAccount);\n const privateKey = wallet.privateKey.toString('hex');\n return decrypt({ privateKey, encryptedData });\n }\n\n async signTypedData<\n Version extends SignTypedDataVersion,\n Types extends MessageTypes,\n Options extends { version?: Version } & KeyringOpt,\n >(\n address: Hex,\n data: Version extends 'V1' ? TypedDataV1 : TypedMessage<Types>,\n options?: Options,\n ): Promise<string> {\n let { version } = options ?? { version: SignTypedDataVersion.V1 };\n\n // Treat invalid versions as \"V1\"\n if (!version || !isSignTypedDataVersion(version)) {\n version = SignTypedDataVersion.V1;\n }\n\n const privateKey = this.#getPrivateKeyFor(address, options);\n return signTypedData({ privateKey, data, version });\n }\n\n // get public key for nacl\n async getEncryptionPublicKey(\n withAccount: Hex,\n opts?: KeyringOpt,\n ): Promise<string> {\n const privKey = this.#getPrivateKeyFor(withAccount, opts);\n const publicKey = getEncryptionPublicKey(privKey.toString('hex'));\n return publicKey;\n }\n\n #getPrivateKeyFor(\n address: Hex,\n opts: KeyringOpt = { withAppKeyOrigin: '' },\n ): Buffer {\n if (!address) {\n throw new Error('Must specify address.');\n }\n const wallet = this.#getWalletForAccount(address, opts);\n return wallet.privateKey;\n }\n\n // returns an address specific to an app\n async getAppKeyAddress(address: Hex, origin: string): Promise<Hex> {\n if (!origin || typeof origin !== 'string') {\n throw new Error(`'origin' must be a non-empty string`);\n }\n const wallet = this.#getWalletForAccount(address, {\n withAppKeyOrigin: origin,\n });\n const appKeyAddress = add0x(bytesToHex(publicToAddress(wallet.publicKey)));\n return appKeyAddress;\n }\n\n // exportAccount should return a hex-encoded private key:\n async exportAccount(\n address: Hex,\n opts = { withAppKeyOrigin: '' },\n ): Promise<string> {\n const wallet = this.#getWalletForAccount(address, opts);\n return wallet.privateKey.toString('hex');\n }\n\n removeAccount(address: string): void {\n if (\n !this.#wallets\n .map(({ publicKey }) =>\n bytesToHex(publicToAddress(publicKey)).toLowerCase(),\n )\n .includes(address.toLowerCase())\n ) {\n throw new Error(`Address ${address} not found in this keyring`);\n }\n\n this.#wallets = this.#wallets.filter(\n ({ publicKey }) =>\n bytesToHex(publicToAddress(publicKey)).toLowerCase() !==\n address.toLowerCase(),\n );\n }\n\n #getWalletForAccount(\n account: string | number,\n opts: KeyringOpt = {},\n ): Wallet {\n const address = normalize(account);\n let wallet = this.#wallets.find(\n ({ publicKey }) => bytesToHex(publicToAddress(publicKey)) === address,\n );\n if (!wallet) {\n throw new Error('Simple Keyring - Unable to find matching address.');\n }\n\n if (opts.withAppKeyOrigin) {\n const { privateKey } = wallet;\n const appKeyOriginBuffer = Buffer.from(opts.withAppKeyOrigin, 'utf8');\n const appKeyBuffer = Buffer.concat([privateKey, appKeyOriginBuffer]);\n const appKeyPrivateKey = keccak256(appKeyBuffer);\n const appKeyPublicKey = privateToPublic(appKeyPrivateKey);\n wallet = {\n privateKey: Buffer.from(appKeyPrivateKey),\n publicKey: Buffer.from(appKeyPublicKey),\n };\n }\n\n return wallet;\n }\n}\n\n/**\n * Generate and validate a new random key of 32 bytes.\n *\n * @returns Buffer The generated key.\n */\nfunction generateKey(): Buffer {\n const privateKey = randombytes(32);\n\n if (!isValidPrivate(privateKey)) {\n throw new Error(\n 'Private key does not satisfy the curve requirements (ie. it is invalid)',\n );\n }\n return privateKey;\n}\n\n/**\n * Type predicate type guard to check if a string is in the enum SignTypedDataVersion.\n *\n * @param version - The string to check.\n * @returns Whether it's in the enum.\n */\n// TODO: Put this in @metamask/eth-sig-util\nfunction isSignTypedDataVersion(\n version: SignTypedDataVersion | string,\n): version is SignTypedDataVersion {\n return version in SignTypedDataVersion;\n}\n"]}
1
+ {"version":3,"file":"simple-keyring.cjs","sourceRoot":"","sources":["../src/simple-keyring.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AACA,2CAM0B;AAC1B,yDAUgC;AAOhC,2CAMyB;AACzB,yDAAyD;AACzD,8DAAsC;AAYtC,MAAM,IAAI,GAAG,iBAAiB,CAAC;AAE/B,iDAAiD;AACjD,MAAqB,aAAa;IAOhC,YAAY,cAAwB,EAAE;;QANtC,yCAAsD;QAE7C,SAAI,GAAW,IAAI,CAAC;QAK3B,uBAAA,IAAI,0BAAY,EAAE,MAAA,CAAC;QAEnB;iHACyG;QACzG,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC,KAAK,CAAC,CAAC,KAAY,EAAE,EAAE;YACnD,MAAM,IAAI,KAAK,CAAC,uCAAuC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QAC1E,CAAC,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,SAAS;QACb,OAAO,uBAAA,IAAI,8BAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;IAChE,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,WAAqB;QACrC,uBA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K,CAAC,mDAAmD,CAAC,CAAC;IACvE,CAAC;IAED,IAAI,IAAI,CAAC,gBAAgB,EAAE,CAAC;QAC1B,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC;QAC9B,MAAM,kBAAkB,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAAC;QACtE,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,UAAU,EAAE,kBAAkB,CAAC,CAAC,CAAC;QACrE,MAAM,gBAAgB,GAAG,IAAA,kBAAS,EAAC,YAAY,CAAC,CAAC;QACjD,MAAM,eAAe,GAAG,IAAA,sBAAe,EAAC,gBAAgB,CAAC,CAAC;QAC1D,MAAM,GAAG;YACP,UAAU,EAAE,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC;YACzC,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC;SACxC,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AArNM,kBAAI,GAAW,IAAI,AAAf,CAAgB;kBALR,aAAa;AA6NlC;;;;GAIG;AACH,SAAS,WAAW;IAClB,MAAM,UAAU,GAAG,IAAA,qBAAW,EAAC,EAAE,CAAC,CAAC;IAEnC,IAAI,CAAC,IAAA,qBAAc,EAAC,UAAU,CAAC,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CACb,yEAAyE,CAC1E,CAAC;IACJ,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC;AAED;;;;;GAKG;AACH,2CAA2C;AAC3C,SAAS,sBAAsB,CAC7B,OAAsC;IAEtC,OAAO,OAAO,IAAI,mCAAoB,CAAC;AACzC,CAAC","sourcesContent":["import { TypedTransaction } from '@ethereumjs/tx';\nimport {\n ecsign,\n isValidPrivate,\n privateToPublic,\n publicToAddress,\n stripHexPrefix,\n} from '@ethereumjs/util';\nimport {\n concatSig,\n decrypt,\n EIP7702Authorization,\n getEncryptionPublicKey,\n normalize,\n personalSign,\n signEIP7702Authorization,\n signTypedData,\n SignTypedDataVersion,\n} from '@metamask/eth-sig-util';\nimport type {\n TypedDataV1,\n MessageTypes,\n TypedMessage,\n} from '@metamask/eth-sig-util';\nimport { Keyring } from '@metamask/keyring-utils';\nimport {\n add0x,\n bigIntToBytes,\n bytesToHex,\n Eip1024EncryptedData,\n Hex,\n} from '@metamask/utils';\nimport { keccak256 } from 'ethereum-cryptography/keccak';\nimport randombytes from 'randombytes';\n\ntype KeyringOpt = {\n withAppKeyOrigin?: string;\n version?: SignTypedDataVersion | string;\n};\n\ntype Wallet = {\n privateKey: Buffer;\n publicKey: Buffer;\n};\n\nconst TYPE = 'Simple Key Pair';\n\n// FIXME: This should not be exported as default.\nexport default class SimpleKeyring implements Keyring {\n #wallets: { privateKey: Buffer; publicKey: Buffer }[];\n\n readonly type: string = TYPE;\n\n static type: string = TYPE;\n\n constructor(privateKeys: string[] = []) {\n this.#wallets = [];\n\n /* istanbul ignore next: It's not possible to write a unit test for this, because a constructor isn't allowed\n * to be async. Jest can't await the constructor, and when the error gets thrown, Jest can't catch it. */\n this.deserialize(privateKeys).catch((error: Error) => {\n throw new Error(`Problem deserializing SimpleKeyring ${error.message}`);\n });\n }\n\n async serialize(): Promise<string[]> {\n return this.#wallets.map((a) => a.privateKey.toString('hex'));\n }\n\n async deserialize(privateKeys: string[]): Promise<void> {\n this.#wallets = privateKeys.map((hexPrivateKey) => {\n const strippedHexPrivateKey = stripHexPrefix(hexPrivateKey);\n const privateKey = Buffer.from(strippedHexPrivateKey, 'hex');\n const publicKey = Buffer.from(privateToPublic(privateKey));\n return { privateKey, publicKey };\n });\n }\n\n async addAccounts(numAccounts = 1): Promise<Hex[]> {\n const newWallets = [];\n for (let i = 0; i < numAccounts; i++) {\n const privateKey = generateKey();\n const publicKey = Buffer.from(privateToPublic(privateKey));\n newWallets.push({ privateKey, publicKey });\n }\n this.#wallets = this.#wallets.concat(newWallets);\n const hexWallets = newWallets.map(({ publicKey }) =>\n add0x(bytesToHex(publicToAddress(publicKey))),\n );\n return hexWallets;\n }\n\n async getAccounts(): Promise<Hex[]> {\n return this.#wallets.map(({ publicKey }) =>\n add0x(bytesToHex(publicToAddress(publicKey))),\n );\n }\n\n async signTransaction(\n address: Hex,\n transaction: TypedTransaction,\n opts: KeyringOpt = {},\n ): Promise<TypedTransaction> {\n const privKey = this.#getPrivateKeyFor(address, opts);\n const signedTx = transaction.sign(privKey);\n // Newer versions of Ethereumjs-tx are immutable and return a new tx object\n return signedTx ?? transaction;\n }\n\n async signEip7702Authorization(\n address: Hex,\n authorization: EIP7702Authorization,\n opts: KeyringOpt = {},\n ): Promise<string> {\n const privateKey = this.#getPrivateKeyFor(address, opts);\n return signEIP7702Authorization({ privateKey, authorization });\n }\n\n // For eth_sign, we need to sign arbitrary data:\n async signMessage(\n address: Hex,\n data: string,\n opts = { withAppKeyOrigin: '', validateMessage: true },\n ): Promise<string> {\n const message = stripHexPrefix(data);\n if (\n opts.validateMessage &&\n (message.length === 0 || !message.match(/^[a-fA-F0-9]*$/u))\n ) {\n throw new Error('Cannot sign invalid message');\n }\n const privKey = this.#getPrivateKeyFor(address, opts);\n const msgSig = ecsign(Buffer.from(message, 'hex'), privKey);\n const rawMsgSig = concatSig(\n Buffer.from(bigIntToBytes(msgSig.v)),\n Buffer.from(msgSig.r),\n Buffer.from(msgSig.s),\n );\n return rawMsgSig;\n }\n\n // For personal_sign, we need to prefix the message:\n async signPersonalMessage(\n address: Hex,\n msgHex: Hex,\n opts = { withAppKeyOrigin: '' },\n ): Promise<string> {\n const privKey = this.#getPrivateKeyFor(address, opts);\n return personalSign({ privateKey: privKey, data: msgHex });\n }\n\n // For eth_decryptMessage:\n async decryptMessage(\n withAccount: Hex,\n encryptedData: Eip1024EncryptedData,\n ): Promise<string> {\n const wallet = this.#getWalletForAccount(withAccount);\n const privateKey = wallet.privateKey.toString('hex');\n return decrypt({ privateKey, encryptedData });\n }\n\n async signTypedData<\n Version extends SignTypedDataVersion,\n Types extends MessageTypes,\n Options extends { version?: Version } & KeyringOpt,\n >(\n address: Hex,\n data: Version extends 'V1' ? TypedDataV1 : TypedMessage<Types>,\n options?: Options,\n ): Promise<string> {\n let { version } = options ?? { version: SignTypedDataVersion.V1 };\n\n // Treat invalid versions as \"V1\"\n if (!version || !isSignTypedDataVersion(version)) {\n version = SignTypedDataVersion.V1;\n }\n\n const privateKey = this.#getPrivateKeyFor(address, options);\n return signTypedData({ privateKey, data, version });\n }\n\n // get public key for nacl\n async getEncryptionPublicKey(\n withAccount: Hex,\n opts?: KeyringOpt,\n ): Promise<string> {\n const privKey = this.#getPrivateKeyFor(withAccount, opts);\n const publicKey = getEncryptionPublicKey(privKey.toString('hex'));\n return publicKey;\n }\n\n #getPrivateKeyFor(\n address: Hex,\n opts: KeyringOpt = { withAppKeyOrigin: '' },\n ): Buffer {\n if (!address) {\n throw new Error('Must specify address.');\n }\n const wallet = this.#getWalletForAccount(address, opts);\n return wallet.privateKey;\n }\n\n // returns an address specific to an app\n async getAppKeyAddress(address: Hex, origin: string): Promise<Hex> {\n if (!origin || typeof origin !== 'string') {\n throw new Error(`'origin' must be a non-empty string`);\n }\n const wallet = this.#getWalletForAccount(address, {\n withAppKeyOrigin: origin,\n });\n const appKeyAddress = add0x(bytesToHex(publicToAddress(wallet.publicKey)));\n return appKeyAddress;\n }\n\n // exportAccount should return a hex-encoded private key:\n async exportAccount(\n address: Hex,\n opts = { withAppKeyOrigin: '' },\n ): Promise<string> {\n const wallet = this.#getWalletForAccount(address, opts);\n return wallet.privateKey.toString('hex');\n }\n\n removeAccount(address: string): void {\n if (\n !this.#wallets\n .map(({ publicKey }) =>\n bytesToHex(publicToAddress(publicKey)).toLowerCase(),\n )\n .includes(address.toLowerCase())\n ) {\n throw new Error(`Address ${address} not found in this keyring`);\n }\n\n this.#wallets = this.#wallets.filter(\n ({ publicKey }) =>\n bytesToHex(publicToAddress(publicKey)).toLowerCase() !==\n address.toLowerCase(),\n );\n }\n\n #getWalletForAccount(\n account: string | number,\n opts: KeyringOpt = {},\n ): Wallet {\n const address = normalize(account);\n let wallet = this.#wallets.find(\n ({ publicKey }) => bytesToHex(publicToAddress(publicKey)) === address,\n );\n if (!wallet) {\n throw new Error('Simple Keyring - Unable to find matching address.');\n }\n\n if (opts.withAppKeyOrigin) {\n const { privateKey } = wallet;\n const appKeyOriginBuffer = Buffer.from(opts.withAppKeyOrigin, 'utf8');\n const appKeyBuffer = Buffer.concat([privateKey, appKeyOriginBuffer]);\n const appKeyPrivateKey = keccak256(appKeyBuffer);\n const appKeyPublicKey = privateToPublic(appKeyPrivateKey);\n wallet = {\n privateKey: Buffer.from(appKeyPrivateKey),\n publicKey: Buffer.from(appKeyPublicKey),\n };\n }\n\n return wallet;\n }\n}\n\n/**\n * Generate and validate a new random key of 32 bytes.\n *\n * @returns Buffer The generated key.\n */\nfunction generateKey(): Buffer {\n const privateKey = randombytes(32);\n\n if (!isValidPrivate(privateKey)) {\n throw new Error(\n 'Private key does not satisfy the curve requirements (ie. it is invalid)',\n );\n }\n return privateKey;\n}\n\n/**\n * Type predicate type guard to check if a string is in the enum SignTypedDataVersion.\n *\n * @param version - The string to check.\n * @returns Whether it's in the enum.\n */\n// TODO: Put this in @metamask/eth-sig-util\nfunction isSignTypedDataVersion(\n version: SignTypedDataVersion | string,\n): version is SignTypedDataVersion {\n return version in SignTypedDataVersion;\n}\n"]}
@@ -1,5 +1,6 @@
1
1
  import { TypedTransaction } from "@ethereumjs/tx";
2
- import { type TypedDataV1, type MessageTypes, type TypedMessage, EIP7702Authorization, SignTypedDataVersion } from "@metamask/eth-sig-util";
2
+ import { EIP7702Authorization, SignTypedDataVersion } from "@metamask/eth-sig-util";
3
+ import type { TypedDataV1, MessageTypes, TypedMessage } from "@metamask/eth-sig-util";
3
4
  import { Keyring } from "@metamask/keyring-utils";
4
5
  import { Eip1024EncryptedData, Hex } from "@metamask/utils";
5
6
  type KeyringOpt = {
@@ -1 +1 @@
1
- {"version":3,"file":"sim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G,YAAY,CAAC,KAAK,CAAC,EAC9D,OAAO,CAAC,EAAE,OAAO,GAChB,OAAO,CAAC,MAAM,CAAC;IAaZ,sBAAsB,CAC1B,WAAW,EAAE,GAAG,EAChB,IAAI,CAAC,EAAE,UAAU,GAChB,OAAO,CAAC,MAAM,CAAC;IAkBZ,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAY5D,aAAa,CACjB,OAAO,EAAE,GAAG,EACZ,IAAI;;KAA2B,GAC9B,OAAO,CAAC,MAAM,CAAC;IAKlB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;CA4CrC"}
@@ -1,5 +1,6 @@
1
1
  import { TypedTransaction } from "@ethereumjs/tx";
2
- import { type TypedDataV1, type MessageTypes, type TypedMessage, EIP7702Authorization, SignTypedDataVersion } from "@metamask/eth-sig-util";
2
+ import { EIP7702Authorization, SignTypedDataVersion } from "@metamask/eth-sig-util";
3
+ import type { TypedDataV1, MessageTypes, TypedMessage } from "@metamask/eth-sig-util";
3
4
  import { Keyring } from "@metamask/keyring-utils";
4
5
  import { Eip1024EncryptedData, Hex } from "@metamask/utils";
5
6
  type KeyringOpt = {
@@ -1 +1 @@
1
- {"version":3,"file":"simple-keyring.d.mts","sourceRoot":"","sources":["../src/simple-keyring.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,uBAAuB;AAQlD,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,YAAY,EAGjB,oBAAoB,EAMpB,oBAAoB,EACrB,+BAA+B;AAChC,OAAO,EAAE,OAAO,EAAE,gCAAgC;AAClD,OAAO,EAIL,oBAAoB,EACpB,GAAG,EACJ,wBAAwB;AAIzB,KAAK,UAAU,GAAG;IAChB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,OAAO,CAAC,EAAE,oBAAoB,GAAG,MAAM,CAAC;CACzC,CAAC;AAU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AAY,CAAC,CAAC;QACjD,MAAM,eAAe,GAAG,eAAe,CAAC,gBAAgB,CAAC,CAAC;QAC1D,MAAM,GAAG;YACP,UAAU,EAAE,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC;YACzC,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC;SACxC,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AArNM,kBAAI,GAAW,IAAI,AAAf,CAAgB;eALR,aAAa;AA6NlC;;;;GAIG;AACH,SAAS,WAAW;IAClB,MAAM,UAAU,GAAG,WAAW,CAAC,EAAE,CAAC,CAAC;IAEnC,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CACb,yEAAyE,CAC1E,CAAC;IACJ,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC;AAED;;;;;GAKG;AACH,2CAA2C;AAC3C,SAAS,sBAAsB,CAC7B,OAAsC;IAEtC,OAAO,OAAO,IAAI,oBAAoB,CAAC;AACzC,CAAC","sourcesContent":["import { TypedTransaction } from '@ethereumjs/tx';\nimport {\n ecsign,\n isValidPrivate,\n privateToPublic,\n publicToAddress,\n stripHexPrefix,\n} from '@ethereumjs/util';\nimport {\n type TypedDataV1,\n type MessageTypes,\n type TypedMessage,\n concatSig,\n decrypt,\n EIP7702Authorization,\n getEncryptionPublicKey,\n normalize,\n personalSign,\n signEIP7702Authorization,\n signTypedData,\n SignTypedDataVersion,\n} from '@metamask/eth-sig-util';\nimport { Keyring } from '@metamask/keyring-utils';\nimport {\n add0x,\n bigIntToBytes,\n bytesToHex,\n Eip1024EncryptedData,\n Hex,\n} from '@metamask/utils';\nimport { keccak256 } from 'ethereum-cryptography/keccak';\nimport randombytes from 'randombytes';\n\ntype KeyringOpt = {\n withAppKeyOrigin?: string;\n version?: SignTypedDataVersion | string;\n};\n\ntype Wallet = {\n privateKey: Buffer;\n publicKey: Buffer;\n};\n\nconst TYPE = 'Simple Key Pair';\n\n// FIXME: This should not be exported as default.\nexport default class SimpleKeyring implements Keyring {\n #wallets: { privateKey: Buffer; publicKey: Buffer }[];\n\n readonly type: string = TYPE;\n\n static type: string = TYPE;\n\n constructor(privateKeys: string[] = []) {\n this.#wallets = [];\n\n /* istanbul ignore next: It's not possible to write a unit test for this, because a constructor isn't allowed\n * to be async. Jest can't await the constructor, and when the error gets thrown, Jest can't catch it. */\n this.deserialize(privateKeys).catch((error: Error) => {\n throw new Error(`Problem deserializing SimpleKeyring ${error.message}`);\n });\n }\n\n async serialize(): Promise<string[]> {\n return this.#wallets.map((a) => a.privateKey.toString('hex'));\n }\n\n async deserialize(privateKeys: string[]): Promise<void> {\n this.#wallets = privateKeys.map((hexPrivateKey) => {\n const strippedHexPrivateKey = stripHexPrefix(hexPrivateKey);\n const privateKey = Buffer.from(strippedHexPrivateKey, 'hex');\n const publicKey = Buffer.from(privateToPublic(privateKey));\n return { privateKey, publicKey };\n });\n }\n\n async addAccounts(numAccounts = 1): Promise<Hex[]> {\n const newWallets = [];\n for (let i = 0; i < numAccounts; i++) {\n const privateKey = generateKey();\n const publicKey = Buffer.from(privateToPublic(privateKey));\n newWallets.push({ privateKey, publicKey });\n }\n this.#wallets = this.#wallets.concat(newWallets);\n const hexWallets = newWallets.map(({ publicKey }) =>\n add0x(bytesToHex(publicToAddress(publicKey))),\n );\n return hexWallets;\n }\n\n async getAccounts(): Promise<Hex[]> {\n return this.#wallets.map(({ publicKey }) =>\n add0x(bytesToHex(publicToAddress(publicKey))),\n );\n }\n\n async signTransaction(\n address: Hex,\n transaction: TypedTransaction,\n opts: KeyringOpt = {},\n ): Promise<TypedTransaction> {\n const privKey = this.#getPrivateKeyFor(address, opts);\n const signedTx = transaction.sign(privKey);\n // Newer versions of Ethereumjs-tx are immutable and return a new tx object\n return signedTx ?? transaction;\n }\n\n async signEip7702Authorization(\n address: Hex,\n authorization: EIP7702Authorization,\n opts: KeyringOpt = {},\n ): Promise<string> {\n const privateKey = this.#getPrivateKeyFor(address, opts);\n return signEIP7702Authorization({ privateKey, authorization });\n }\n\n // For eth_sign, we need to sign arbitrary data:\n async signMessage(\n address: Hex,\n data: string,\n opts = { withAppKeyOrigin: '', validateMessage: true },\n ): Promise<string> {\n const message = stripHexPrefix(data);\n if (\n opts.validateMessage &&\n (message.length === 0 || !message.match(/^[a-fA-F0-9]*$/u))\n ) {\n throw new Error('Cannot sign invalid message');\n }\n const privKey = this.#getPrivateKeyFor(address, opts);\n const msgSig = ecsign(Buffer.from(message, 'hex'), privKey);\n const rawMsgSig = concatSig(\n Buffer.from(bigIntToBytes(msgSig.v)),\n Buffer.from(msgSig.r),\n Buffer.from(msgSig.s),\n );\n return rawMsgSig;\n }\n\n // For personal_sign, we need to prefix the message:\n async signPersonalMessage(\n address: Hex,\n msgHex: Hex,\n opts = { withAppKeyOrigin: '' },\n ): Promise<string> {\n const privKey = this.#getPrivateKeyFor(address, opts);\n return personalSign({ privateKey: privKey, data: msgHex });\n }\n\n // For eth_decryptMessage:\n async decryptMessage(\n withAccount: Hex,\n encryptedData: Eip1024EncryptedData,\n ): Promise<string> {\n const wallet = this.#getWalletForAccount(withAccount);\n const privateKey = wallet.privateKey.toString('hex');\n return decrypt({ privateKey, encryptedData });\n }\n\n async signTypedData<\n Version extends SignTypedDataVersion,\n Types extends MessageTypes,\n Options extends { version?: Version } & KeyringOpt,\n >(\n address: Hex,\n data: Version extends 'V1' ? TypedDataV1 : TypedMessage<Types>,\n options?: Options,\n ): Promise<string> {\n let { version } = options ?? { version: SignTypedDataVersion.V1 };\n\n // Treat invalid versions as \"V1\"\n if (!version || !isSignTypedDataVersion(version)) {\n version = SignTypedDataVersion.V1;\n }\n\n const privateKey = this.#getPrivateKeyFor(address, options);\n return signTypedData({ privateKey, data, version });\n }\n\n // get public key for nacl\n async getEncryptionPublicKey(\n withAccount: Hex,\n opts?: KeyringOpt,\n ): Promise<string> {\n const privKey = this.#getPrivateKeyFor(withAccount, opts);\n const publicKey = getEncryptionPublicKey(privKey.toString('hex'));\n return publicKey;\n }\n\n #getPrivateKeyFor(\n address: Hex,\n opts: KeyringOpt = { withAppKeyOrigin: '' },\n ): Buffer {\n if (!address) {\n throw new Error('Must specify address.');\n }\n const wallet = this.#getWalletForAccount(address, opts);\n return wallet.privateKey;\n }\n\n // returns an address specific to an app\n async getAppKeyAddress(address: Hex, origin: string): Promise<Hex> {\n if (!origin || typeof origin !== 'string') {\n throw new Error(`'origin' must be a non-empty string`);\n }\n const wallet = this.#getWalletForAccount(address, {\n withAppKeyOrigin: origin,\n });\n const appKeyAddress = add0x(bytesToHex(publicToAddress(wallet.publicKey)));\n return appKeyAddress;\n }\n\n // exportAccount should return a hex-encoded private key:\n async exportAccount(\n address: Hex,\n opts = { withAppKeyOrigin: '' },\n ): Promise<string> {\n const wallet = this.#getWalletForAccount(address, opts);\n return wallet.privateKey.toString('hex');\n }\n\n removeAccount(address: string): void {\n if (\n !this.#wallets\n .map(({ publicKey }) =>\n bytesToHex(publicToAddress(publicKey)).toLowerCase(),\n )\n .includes(address.toLowerCase())\n ) {\n throw new Error(`Address ${address} not found in this keyring`);\n }\n\n this.#wallets = this.#wallets.filter(\n ({ publicKey }) =>\n bytesToHex(publicToAddress(publicKey)).toLowerCase() !==\n address.toLowerCase(),\n );\n }\n\n #getWalletForAccount(\n account: string | number,\n opts: KeyringOpt = {},\n ): Wallet {\n const address = normalize(account);\n let wallet = this.#wallets.find(\n ({ publicKey }) => bytesToHex(publicToAddress(publicKey)) === address,\n );\n if (!wallet) {\n throw new Error('Simple Keyring - Unable to find matching address.');\n }\n\n if (opts.withAppKeyOrigin) {\n const { privateKey } = wallet;\n const appKeyOriginBuffer = Buffer.from(opts.withAppKeyOrigin, 'utf8');\n const appKeyBuffer = Buffer.concat([privateKey, appKeyOriginBuffer]);\n const appKeyPrivateKey = keccak256(appKeyBuffer);\n const appKeyPublicKey = privateToPublic(appKeyPrivateKey);\n wallet = {\n privateKey: Buffer.from(appKeyPrivateKey),\n publicKey: Buffer.from(appKeyPublicKey),\n };\n }\n\n return wallet;\n }\n}\n\n/**\n * Generate and validate a new random key of 32 bytes.\n *\n * @returns Buffer The generated key.\n */\nfunction generateKey(): Buffer {\n const privateKey = randombytes(32);\n\n if (!isValidPrivate(privateKey)) {\n throw new Error(\n 'Private key does not satisfy the curve requirements (ie. it is invalid)',\n );\n }\n return privateKey;\n}\n\n/**\n * Type predicate type guard to check if a string is in the enum SignTypedDataVersion.\n *\n * @param version - The string to check.\n * @returns Whether it's in the enum.\n */\n// TODO: Put this in @metamask/eth-sig-util\nfunction isSignTypedDataVersion(\n version: SignTypedDataVersion | string,\n): version is SignTypedDataVersion {\n return version in SignTypedDataVersion;\n}\n"]}
1
+ {"version":3,"file":"simple-keyring.mjs","sourceRoot":"","sources":["../src/simple-keyring.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AACA,OAAO,EACL,MAAM,EACN,cAAc,EACd,eAAe,EACf,eAAe,EACf,cAAc,EACf,yBAAyB;AAC1B,OAAO,EACL,SAAS,EACT,OAAO,EAEP,sBAAsB,EACtB,SAAS,EACT,YAAY,EACZ,wBAAwB,EACxB,aAAa,EACb,oBAAoB,EACrB,+BAA+B;AAOhC,OAAO,EACL,KAAK,EACL,aAAa,EACb,UAAU,EAGX,wBAAwB;AACzB,OAAO,EAAE,SAAS,EAAE,qCAAqC;AACzD,OAAO,YAAW,oBAAoB;;AAYtC,MAAM,IAAI,GAAG,iBAAiB,CAAC;AAE/B,iDAAiD;AACjD,MAAqB,aAAa;IAOhC,YAAY,cAAwB,EAAE;;QANtC,yCAAsD;QAE7C,SAAI,GAAW,IAAI,CAAC;QAK3B,uBAAA,IAAI,0BAAY,EAAE,MAAA,CAAC;QAEnB;iHACyG;QACzG,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC,KAAK,CAAC,CAAC,KAAY,EAAE,EAAE;YACnD,MAAM,IAAI,KAAK,CAAC,uCAAuC,KAAK,CAAC,OAAO,EAAE,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OAAO,CACtE,CAAC;IACF,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;IACvE,CAAC;IAED,IAAI,IAAI,CAAC,gBAAgB,EAAE,CAAC;QAC1B,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC;QAC9B,MAAM,kBAAkB,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAAC;QACtE,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,UAAU,EAAE,kBAAkB,CAAC,CAAC,CAAC;QACrE,MAAM,gBAAgB,GAAG,SAAS,CAAC,YAAY,CAAC,CAAC;QACjD,MAAM,eAAe,GAAG,eAAe,CAAC,gBAAgB,CAAC,CAAC;QAC1D,MAAM,GAAG;YACP,UAAU,EAAE,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC;YACzC,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC;SACxC,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AArNM,kBAAI,GAAW,IAAI,AAAf,CAAgB;eALR,aAAa;AA6NlC;;;;GAIG;AACH,SAAS,WAAW;IAClB,MAAM,UAAU,GAAG,WAAW,CAAC,EAAE,CAAC,CAAC;IAEnC,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CACb,yEAAyE,CAC1E,CAAC;IACJ,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC;AAED;;;;;GAKG;AACH,2CAA2C;AAC3C,SAAS,sBAAsB,CAC7B,OAAsC;IAEtC,OAAO,OAAO,IAAI,oBAAoB,CAAC;AACzC,CAAC","sourcesContent":["import { TypedTransaction } from '@ethereumjs/tx';\nimport {\n ecsign,\n isValidPrivate,\n privateToPublic,\n publicToAddress,\n stripHexPrefix,\n} from '@ethereumjs/util';\nimport {\n concatSig,\n decrypt,\n EIP7702Authorization,\n getEncryptionPublicKey,\n normalize,\n personalSign,\n signEIP7702Authorization,\n signTypedData,\n SignTypedDataVersion,\n} from '@metamask/eth-sig-util';\nimport type {\n TypedDataV1,\n MessageTypes,\n TypedMessage,\n} from '@metamask/eth-sig-util';\nimport { Keyring } from '@metamask/keyring-utils';\nimport {\n add0x,\n bigIntToBytes,\n bytesToHex,\n Eip1024EncryptedData,\n Hex,\n} from '@metamask/utils';\nimport { keccak256 } from 'ethereum-cryptography/keccak';\nimport randombytes from 'randombytes';\n\ntype KeyringOpt = {\n withAppKeyOrigin?: string;\n version?: SignTypedDataVersion | string;\n};\n\ntype Wallet = {\n privateKey: Buffer;\n publicKey: Buffer;\n};\n\nconst TYPE = 'Simple Key Pair';\n\n// FIXME: This should not be exported as default.\nexport default class SimpleKeyring implements Keyring {\n #wallets: { privateKey: Buffer; publicKey: Buffer }[];\n\n readonly type: string = TYPE;\n\n static type: string = TYPE;\n\n constructor(privateKeys: string[] = []) {\n this.#wallets = [];\n\n /* istanbul ignore next: It's not possible to write a unit test for this, because a constructor isn't allowed\n * to be async. Jest can't await the constructor, and when the error gets thrown, Jest can't catch it. */\n this.deserialize(privateKeys).catch((error: Error) => {\n throw new Error(`Problem deserializing SimpleKeyring ${error.message}`);\n });\n }\n\n async serialize(): Promise<string[]> {\n return this.#wallets.map((a) => a.privateKey.toString('hex'));\n }\n\n async deserialize(privateKeys: string[]): Promise<void> {\n this.#wallets = privateKeys.map((hexPrivateKey) => {\n const strippedHexPrivateKey = stripHexPrefix(hexPrivateKey);\n const privateKey = Buffer.from(strippedHexPrivateKey, 'hex');\n const publicKey = Buffer.from(privateToPublic(privateKey));\n return { privateKey, publicKey };\n });\n }\n\n async addAccounts(numAccounts = 1): Promise<Hex[]> {\n const newWallets = [];\n for (let i = 0; i < numAccounts; i++) {\n const privateKey = generateKey();\n const publicKey = Buffer.from(privateToPublic(privateKey));\n newWallets.push({ privateKey, publicKey });\n }\n this.#wallets = this.#wallets.concat(newWallets);\n const hexWallets = newWallets.map(({ publicKey }) =>\n add0x(bytesToHex(publicToAddress(publicKey))),\n );\n return hexWallets;\n }\n\n async getAccounts(): Promise<Hex[]> {\n return this.#wallets.map(({ publicKey }) =>\n add0x(bytesToHex(publicToAddress(publicKey))),\n );\n }\n\n async signTransaction(\n address: Hex,\n transaction: TypedTransaction,\n opts: KeyringOpt = {},\n ): Promise<TypedTransaction> {\n const privKey = this.#getPrivateKeyFor(address, opts);\n const signedTx = transaction.sign(privKey);\n // Newer versions of Ethereumjs-tx are immutable and return a new tx object\n return signedTx ?? transaction;\n }\n\n async signEip7702Authorization(\n address: Hex,\n authorization: EIP7702Authorization,\n opts: KeyringOpt = {},\n ): Promise<string> {\n const privateKey = this.#getPrivateKeyFor(address, opts);\n return signEIP7702Authorization({ privateKey, authorization });\n }\n\n // For eth_sign, we need to sign arbitrary data:\n async signMessage(\n address: Hex,\n data: string,\n opts = { withAppKeyOrigin: '', validateMessage: true },\n ): Promise<string> {\n const message = stripHexPrefix(data);\n if (\n opts.validateMessage &&\n (message.length === 0 || !message.match(/^[a-fA-F0-9]*$/u))\n ) {\n throw new Error('Cannot sign invalid message');\n }\n const privKey = this.#getPrivateKeyFor(address, opts);\n const msgSig = ecsign(Buffer.from(message, 'hex'), privKey);\n const rawMsgSig = concatSig(\n Buffer.from(bigIntToBytes(msgSig.v)),\n Buffer.from(msgSig.r),\n Buffer.from(msgSig.s),\n );\n return rawMsgSig;\n }\n\n // For personal_sign, we need to prefix the message:\n async signPersonalMessage(\n address: Hex,\n msgHex: Hex,\n opts = { withAppKeyOrigin: '' },\n ): Promise<string> {\n const privKey = this.#getPrivateKeyFor(address, opts);\n return personalSign({ privateKey: privKey, data: msgHex });\n }\n\n // For eth_decryptMessage:\n async decryptMessage(\n withAccount: Hex,\n encryptedData: Eip1024EncryptedData,\n ): Promise<string> {\n const wallet = this.#getWalletForAccount(withAccount);\n const privateKey = wallet.privateKey.toString('hex');\n return decrypt({ privateKey, encryptedData });\n }\n\n async signTypedData<\n Version extends SignTypedDataVersion,\n Types extends MessageTypes,\n Options extends { version?: Version } & KeyringOpt,\n >(\n address: Hex,\n data: Version extends 'V1' ? TypedDataV1 : TypedMessage<Types>,\n options?: Options,\n ): Promise<string> {\n let { version } = options ?? { version: SignTypedDataVersion.V1 };\n\n // Treat invalid versions as \"V1\"\n if (!version || !isSignTypedDataVersion(version)) {\n version = SignTypedDataVersion.V1;\n }\n\n const privateKey = this.#getPrivateKeyFor(address, options);\n return signTypedData({ privateKey, data, version });\n }\n\n // get public key for nacl\n async getEncryptionPublicKey(\n withAccount: Hex,\n opts?: KeyringOpt,\n ): Promise<string> {\n const privKey = this.#getPrivateKeyFor(withAccount, opts);\n const publicKey = getEncryptionPublicKey(privKey.toString('hex'));\n return publicKey;\n }\n\n #getPrivateKeyFor(\n address: Hex,\n opts: KeyringOpt = { withAppKeyOrigin: '' },\n ): Buffer {\n if (!address) {\n throw new Error('Must specify address.');\n }\n const wallet = this.#getWalletForAccount(address, opts);\n return wallet.privateKey;\n }\n\n // returns an address specific to an app\n async getAppKeyAddress(address: Hex, origin: string): Promise<Hex> {\n if (!origin || typeof origin !== 'string') {\n throw new Error(`'origin' must be a non-empty string`);\n }\n const wallet = this.#getWalletForAccount(address, {\n withAppKeyOrigin: origin,\n });\n const appKeyAddress = add0x(bytesToHex(publicToAddress(wallet.publicKey)));\n return appKeyAddress;\n }\n\n // exportAccount should return a hex-encoded private key:\n async exportAccount(\n address: Hex,\n opts = { withAppKeyOrigin: '' },\n ): Promise<string> {\n const wallet = this.#getWalletForAccount(address, opts);\n return wallet.privateKey.toString('hex');\n }\n\n removeAccount(address: string): void {\n if (\n !this.#wallets\n .map(({ publicKey }) =>\n bytesToHex(publicToAddress(publicKey)).toLowerCase(),\n )\n .includes(address.toLowerCase())\n ) {\n throw new Error(`Address ${address} not found in this keyring`);\n }\n\n this.#wallets = this.#wallets.filter(\n ({ publicKey }) =>\n bytesToHex(publicToAddress(publicKey)).toLowerCase() !==\n address.toLowerCase(),\n );\n }\n\n #getWalletForAccount(\n account: string | number,\n opts: KeyringOpt = {},\n ): Wallet {\n const address = normalize(account);\n let wallet = this.#wallets.find(\n ({ publicKey }) => bytesToHex(publicToAddress(publicKey)) === address,\n );\n if (!wallet) {\n throw new Error('Simple Keyring - Unable to find matching address.');\n }\n\n if (opts.withAppKeyOrigin) {\n const { privateKey } = wallet;\n const appKeyOriginBuffer = Buffer.from(opts.withAppKeyOrigin, 'utf8');\n const appKeyBuffer = Buffer.concat([privateKey, appKeyOriginBuffer]);\n const appKeyPrivateKey = keccak256(appKeyBuffer);\n const appKeyPublicKey = privateToPublic(appKeyPrivateKey);\n wallet = {\n privateKey: Buffer.from(appKeyPrivateKey),\n publicKey: Buffer.from(appKeyPublicKey),\n };\n }\n\n return wallet;\n }\n}\n\n/**\n * Generate and validate a new random key of 32 bytes.\n *\n * @returns Buffer The generated key.\n */\nfunction generateKey(): Buffer {\n const privateKey = randombytes(32);\n\n if (!isValidPrivate(privateKey)) {\n throw new Error(\n 'Private key does not satisfy the curve requirements (ie. it is invalid)',\n );\n }\n return privateKey;\n}\n\n/**\n * Type predicate type guard to check if a string is in the enum SignTypedDataVersion.\n *\n * @param version - The string to check.\n * @returns Whether it's in the enum.\n */\n// TODO: Put this in @metamask/eth-sig-util\nfunction isSignTypedDataVersion(\n version: SignTypedDataVersion | string,\n): version is SignTypedDataVersion {\n return version in SignTypedDataVersion;\n}\n"]}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SimpleKeyring = void 0;
4
+ var simple_keyring_1 = require("./simple-keyring.cjs");
5
+ Object.defineProperty(exports, "SimpleKeyring", { enumerable: true, get: function () { return simple_keyring_1.SimpleKeyring; } });
6
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/v2/index.ts"],"names":[],"mappings":";;;AAAA,uDAA4E;AAAnE,+GAAA,aAAa,OAAA","sourcesContent":["export { SimpleKeyring, type SimpleKeyringOptions } from './simple-keyring';\n"]}
@@ -0,0 +1,2 @@
1
+ export { SimpleKeyring, type SimpleKeyringOptions } from "./simple-keyring.cjs";
2
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../src/v2/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,KAAK,oBAAoB,EAAE,6BAAyB"}
@@ -0,0 +1,2 @@
1
+ export { SimpleKeyring, type SimpleKeyringOptions } from "./simple-keyring.mjs";
2
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/v2/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,KAAK,oBAAoB,EAAE,6BAAyB"}
@@ -0,0 +1,2 @@
1
+ export { SimpleKeyring } from "./simple-keyring.mjs";
2
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/v2/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAA6B,6BAAyB","sourcesContent":["export { SimpleKeyring, type SimpleKeyringOptions } from './simple-keyring';\n"]}
@@ -4,11 +4,12 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
4
4
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
5
5
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
6
  };
7
- var _SimpleKeyringV2_instances, _SimpleKeyringV2_createKeyringAccount, _SimpleKeyringV2_getPrivateKeys, _SimpleKeyringV2_setPrivateKeys, _SimpleKeyringV2_withRollback, _SimpleKeyringV2_importPrivateKeyOrRollback;
7
+ var _SimpleKeyring_instances, _SimpleKeyring_createKeyringAccount, _SimpleKeyring_getPrivateKeys, _SimpleKeyring_setPrivateKeys, _SimpleKeyring_withRollback, _SimpleKeyring_importPrivateKeyOrRollback;
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.SimpleKeyringV2 = void 0;
9
+ exports.SimpleKeyring = void 0;
10
10
  const keyring_api_1 = require("@metamask/keyring-api");
11
- const keyring_sdk_1 = require("@metamask/keyring-sdk");
11
+ const v2_1 = require("@metamask/keyring-api/v2");
12
+ const v2_2 = require("@metamask/keyring-sdk/v2");
12
13
  const utils_1 = require("@metamask/utils");
13
14
  /**
14
15
  * Methods supported by SimpleKeyring EOA accounts.
@@ -21,28 +22,28 @@ const SIMPLE_KEYRING_METHODS = [
21
22
  keyring_api_1.EthMethod.SignTypedDataV1,
22
23
  keyring_api_1.EthMethod.SignTypedDataV3,
23
24
  keyring_api_1.EthMethod.SignTypedDataV4,
24
- keyring_sdk_1.EthKeyringMethod.Decrypt,
25
- keyring_sdk_1.EthKeyringMethod.GetEncryptionPublicKey,
26
- keyring_sdk_1.EthKeyringMethod.GetAppKeyAddress,
27
- keyring_sdk_1.EthKeyringMethod.SignEip7702Authorization,
25
+ v2_2.EthKeyringMethod.Decrypt,
26
+ v2_2.EthKeyringMethod.GetEncryptionPublicKey,
27
+ v2_2.EthKeyringMethod.GetAppKeyAddress,
28
+ v2_2.EthKeyringMethod.SignEip7702Authorization,
28
29
  ];
29
- const simpleKeyringV2Capabilities = {
30
+ const simpleKeyringCapabilities = {
30
31
  scopes: [keyring_api_1.EthScope.Eoa],
31
32
  privateKey: {
32
33
  importFormats: [
33
- { encoding: keyring_api_1.PrivateKeyEncoding.Hexadecimal, type: keyring_api_1.EthAccountType.Eoa },
34
+ { encoding: v2_1.PrivateKeyEncoding.Hexadecimal, type: keyring_api_1.EthAccountType.Eoa },
34
35
  ],
35
- exportFormats: [{ encoding: keyring_api_1.PrivateKeyEncoding.Hexadecimal }],
36
+ exportFormats: [{ encoding: v2_1.PrivateKeyEncoding.Hexadecimal }],
36
37
  },
37
38
  };
38
- class SimpleKeyringV2 extends keyring_sdk_1.EthKeyringWrapper {
39
+ class SimpleKeyring extends v2_2.EthKeyringWrapper {
39
40
  constructor(options) {
40
41
  super({
41
- type: keyring_api_1.KeyringType.PrivateKey,
42
+ type: v2_1.KeyringType.PrivateKey,
42
43
  inner: options.legacyKeyring,
43
- capabilities: simpleKeyringV2Capabilities,
44
+ capabilities: simpleKeyringCapabilities,
44
45
  });
45
- _SimpleKeyringV2_instances.add(this);
46
+ _SimpleKeyring_instances.add(this);
46
47
  }
47
48
  async getAccounts() {
48
49
  const addresses = await this.inner.getAccounts();
@@ -56,7 +57,7 @@ class SimpleKeyringV2 extends keyring_sdk_1.EthKeyringWrapper {
56
57
  }
57
58
  }
58
59
  // Create and register the account if not already cached
59
- return __classPrivateFieldGet(this, _SimpleKeyringV2_instances, "m", _SimpleKeyringV2_createKeyringAccount).call(this, address);
60
+ return __classPrivateFieldGet(this, _SimpleKeyring_instances, "m", _SimpleKeyring_createKeyringAccount).call(this, address);
60
61
  });
61
62
  }
62
63
  async createAccounts(options) {
@@ -71,13 +72,13 @@ class SimpleKeyringV2 extends keyring_sdk_1.EthKeyringWrapper {
71
72
  }
72
73
  const { encoding, privateKey } = options;
73
74
  // Validate encoding
74
- if (encoding !== keyring_api_1.PrivateKeyEncoding.Hexadecimal) {
75
- throw new Error(`Unsupported encoding for SimpleKeyring: ${encoding}. Only '${keyring_api_1.PrivateKeyEncoding.Hexadecimal}' is supported.`);
75
+ if (encoding !== v2_1.PrivateKeyEncoding.Hexadecimal) {
76
+ throw new Error(`Unsupported encoding for SimpleKeyring: ${encoding}. Only '${v2_1.PrivateKeyEncoding.Hexadecimal}' is supported.`);
76
77
  }
77
78
  // Import the private key (with automatic rollback on failure)
78
- const newAddress = await __classPrivateFieldGet(this, _SimpleKeyringV2_instances, "m", _SimpleKeyringV2_importPrivateKeyOrRollback).call(this, privateKey);
79
+ const newAddress = await __classPrivateFieldGet(this, _SimpleKeyring_instances, "m", _SimpleKeyring_importPrivateKeyOrRollback).call(this, privateKey);
79
80
  // Create and return the new KeyringAccount
80
- const newAccount = __classPrivateFieldGet(this, _SimpleKeyringV2_instances, "m", _SimpleKeyringV2_createKeyringAccount).call(this, newAddress);
81
+ const newAccount = __classPrivateFieldGet(this, _SimpleKeyring_instances, "m", _SimpleKeyring_createKeyringAccount).call(this, newAddress);
81
82
  return [newAccount];
82
83
  });
83
84
  }
@@ -104,9 +105,9 @@ class SimpleKeyringV2 extends keyring_sdk_1.EthKeyringWrapper {
104
105
  */
105
106
  async exportAccount(accountId, options) {
106
107
  const account = await this.getAccount(accountId);
107
- const requestedEncoding = options?.encoding ?? keyring_api_1.PrivateKeyEncoding.Hexadecimal;
108
- if (requestedEncoding !== keyring_api_1.PrivateKeyEncoding.Hexadecimal) {
109
- throw new Error(`Unsupported encoding for SimpleKeyring: ${requestedEncoding}. Only '${keyring_api_1.PrivateKeyEncoding.Hexadecimal}' is supported.`);
108
+ const requestedEncoding = options?.encoding ?? v2_1.PrivateKeyEncoding.Hexadecimal;
109
+ if (requestedEncoding !== v2_1.PrivateKeyEncoding.Hexadecimal) {
110
+ throw new Error(`Unsupported encoding for SimpleKeyring: ${requestedEncoding}. Only '${v2_1.PrivateKeyEncoding.Hexadecimal}' is supported.`);
110
111
  }
111
112
  const privateKeyHex = await this.inner.exportAccount(this.toHexAddress(account.address));
112
113
  // Sanitize private key format
@@ -114,13 +115,13 @@ class SimpleKeyringV2 extends keyring_sdk_1.EthKeyringWrapper {
114
115
  const exported = {
115
116
  type: 'private-key',
116
117
  privateKey,
117
- encoding: keyring_api_1.PrivateKeyEncoding.Hexadecimal,
118
+ encoding: v2_1.PrivateKeyEncoding.Hexadecimal,
118
119
  };
119
120
  return exported;
120
121
  }
121
122
  }
122
- exports.SimpleKeyringV2 = SimpleKeyringV2;
123
- _SimpleKeyringV2_instances = new WeakSet(), _SimpleKeyringV2_createKeyringAccount = function _SimpleKeyringV2_createKeyringAccount(address) {
123
+ exports.SimpleKeyring = SimpleKeyring;
124
+ _SimpleKeyring_instances = new WeakSet(), _SimpleKeyring_createKeyringAccount = function _SimpleKeyring_createKeyringAccount(address) {
124
125
  const id = this.registry.register(address);
125
126
  const account = {
126
127
  id,
@@ -138,23 +139,23 @@ _SimpleKeyringV2_instances = new WeakSet(), _SimpleKeyringV2_createKeyringAccoun
138
139
  // Add the account to the registry
139
140
  this.registry.set(account);
140
141
  return account;
141
- }, _SimpleKeyringV2_getPrivateKeys =
142
+ }, _SimpleKeyring_getPrivateKeys =
142
143
  /**
143
144
  * Get all private keys from the inner SimpleKeyring.
144
145
  *
145
146
  * @returns An array of private keys in hexadecimal format.
146
147
  */
147
- async function _SimpleKeyringV2_getPrivateKeys() {
148
+ async function _SimpleKeyring_getPrivateKeys() {
148
149
  return await this.inner.serialize();
149
- }, _SimpleKeyringV2_setPrivateKeys =
150
+ }, _SimpleKeyring_setPrivateKeys =
150
151
  /**
151
152
  * Set private keys in the inner SimpleKeyring.
152
153
  *
153
154
  * @param privateKeys - An array of private keys in hexadecimal format.
154
155
  */
155
- async function _SimpleKeyringV2_setPrivateKeys(privateKeys) {
156
+ async function _SimpleKeyring_setPrivateKeys(privateKeys) {
156
157
  await this.inner.deserialize(privateKeys);
157
- }, _SimpleKeyringV2_withRollback =
158
+ }, _SimpleKeyring_withRollback =
158
159
  /**
159
160
  * Executes a transactional update on the inner keyring state.
160
161
  * If the callback throws, the state is automatically rolled back.
@@ -164,17 +165,17 @@ async function _SimpleKeyringV2_setPrivateKeys(privateKeys) {
164
165
  * @returns The result of the callback.
165
166
  * @throws Error if the callback throws (after rollback).
166
167
  */
167
- async function _SimpleKeyringV2_withRollback(callback) {
168
- const originalPrivateKeys = await __classPrivateFieldGet(this, _SimpleKeyringV2_instances, "m", _SimpleKeyringV2_getPrivateKeys).call(this);
168
+ async function _SimpleKeyring_withRollback(callback) {
169
+ const originalPrivateKeys = await __classPrivateFieldGet(this, _SimpleKeyring_instances, "m", _SimpleKeyring_getPrivateKeys).call(this);
169
170
  try {
170
171
  return await callback(originalPrivateKeys);
171
172
  }
172
173
  catch (error) {
173
174
  // Rollback on error
174
- await __classPrivateFieldGet(this, _SimpleKeyringV2_instances, "m", _SimpleKeyringV2_setPrivateKeys).call(this, originalPrivateKeys);
175
+ await __classPrivateFieldGet(this, _SimpleKeyring_instances, "m", _SimpleKeyring_setPrivateKeys).call(this, originalPrivateKeys);
175
176
  throw error;
176
177
  }
177
- }, _SimpleKeyringV2_importPrivateKeyOrRollback =
178
+ }, _SimpleKeyring_importPrivateKeyOrRollback =
178
179
  /**
179
180
  * Import a private key and return the new address.
180
181
  * If the import fails (no new address added), rolls back to the original state.
@@ -183,12 +184,12 @@ async function _SimpleKeyringV2_withRollback(callback) {
183
184
  * @returns The address of the newly imported account.
184
185
  * @throws Error if the import fails or no new address is added.
185
186
  */
186
- async function _SimpleKeyringV2_importPrivateKeyOrRollback(privateKey) {
187
- return __classPrivateFieldGet(this, _SimpleKeyringV2_instances, "m", _SimpleKeyringV2_withRollback).call(this, async (currentPrivateKeys) => {
187
+ async function _SimpleKeyring_importPrivateKeyOrRollback(privateKey) {
188
+ return __classPrivateFieldGet(this, _SimpleKeyring_instances, "m", _SimpleKeyring_withRollback).call(this, async (currentPrivateKeys) => {
188
189
  // Get current addresses before import
189
190
  const addressesBefore = new Set(await this.inner.getAccounts());
190
191
  // Import the new private key
191
- await __classPrivateFieldGet(this, _SimpleKeyringV2_instances, "m", _SimpleKeyringV2_setPrivateKeys).call(this, [...currentPrivateKeys, privateKey]);
192
+ await __classPrivateFieldGet(this, _SimpleKeyring_instances, "m", _SimpleKeyring_setPrivateKeys).call(this, [...currentPrivateKeys, privateKey]);
192
193
  // Get addresses after import and find the newly added one
193
194
  const addressesAfter = await this.inner.getAccounts();
194
195
  // Find the new address by diffing the two sets
@@ -199,4 +200,4 @@ async function _SimpleKeyringV2_importPrivateKeyOrRollback(privateKey) {
199
200
  return newAddresses[0];
200
201
  });
201
202
  };
202
- //# sourceMappingURL=simple-keyring-v2.cjs.map
203
+ //# sourceMappingURL=simple-keyring.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"simple-keyring.cjs","sourceRoot":"","sources":["../../src/v2/simple-keyring.ts"],"names":[],"mappings":";;;;;;;;;AAAA,uDAK+B;AAE/B,iDAA2E;AAQ3E,iDAA+E;AAE/E,2CAAwC;AAKxC;;;GAGG;AACH,MAAM,sBAAsB,GAAG;IAC7B,uBAAS,CAAC,eAAe;IACzB,uBAAS,CAAC,IAAI;IACd,uBAAS,CAAC,YAAY;IACtB,uBAAS,CAAC,eAAe;IACzB,uBAAS,CAAC,eAAe;IACzB,uBAAS,CAAC,eAAe;IACzB,qBAAgB,CAAC,OAAO;IACxB,qBAAgB,CAAC,sBAAsB;IACvC,qBAAgB,CAAC,gBAAgB;IACjC,qBAAgB,CAAC,wBAAwB;CAC1C,CAAC;AAEF,MAAM,yBAAyB,GAAwB;IACrD,MAAM,EAAE,CAAC,sBAAQ,CAAC,GAAG,CAAC;IACtB,UAAU,EAAE;QACV,aAAa,EAAE;YACb,EAAE,QAAQ,EAAE,uBAAkB,CAAC,WAAW,EAAE,IAAI,EAAE,4BAAc,CAAC,GAAG,EAAE;SACvE;QACD,aAAa,EAAE,CAAC,EAAE,QAAQ,EAAE,uBAAkB,CAAC,WAAW,EAAE,CAAC;KAC9D;CACF,CAAC;AAYF,MAAa,aACX,SAAQ,sBAAsC;IAG9C,YAAY,OAA6B;QACvC,KAAK,CAAC;YACJ,IAAI,EAAE,gBAAW,CAAC,UAAU;YAC5B,KAAK,EAAE,OAAO,CAAC,aAAa;YAC5B,YAAY,EAAE,yBAAyB;SACxC,CAAC,CAAC;;IACL,CAAC;IAwGD,KAAK,CAAC,WAAW;QACf,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC;QAEjD,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,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DAAc,MAAlB,IAAI,EAAe,KAAK,EAAE,kBAAkB,EAAE,EAAE;QACrD,sCAAsC;QACtC,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC;QAEhE,6BAA6B;QAC7B,MAAM,uBAAA,IAAI,+DAAgB,MAApB,IAAI,EAAiB,CAAC,GAAG,kBAAkB,EAAE,UAAU,CAAC,CAAC,CAAC;QAEhE,0DAA0D;QAC1D,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC;QAEtD,+CAA+C;QAC/C,MAAM,YAAY,GAAG,cAAc,CAAC,MAAM,CACxC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,CACrC,CAAC;QAEF,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC;YAClD,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;QAClD,CAAC;QAED,OAAO,YAAY,CAAC,CAAC,CAAC,CAAC;IACzB,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n EthAccountType,\n EthMethod,\n EthScope,\n KeyringAccountEntropyTypeOption,\n} from '@metamask/keyring-api';\nimport type { KeyringAccount } from '@metamask/keyring-api';\nimport { KeyringType, PrivateKeyEncoding } from '@metamask/keyring-api/v2';\nimport type {\n CreateAccountOptions,\n ExportAccountOptions,\n ExportedAccount,\n KeyringCapabilities,\n Keyring,\n} from '@metamask/keyring-api/v2';\nimport { EthKeyringMethod, EthKeyringWrapper } from '@metamask/keyring-sdk/v2';\nimport type { AccountId } from '@metamask/keyring-utils';\nimport { add0x } from '@metamask/utils';\nimport type { Hex } from '@metamask/utils';\n\nimport type LegacySimpleKeyring from '../simple-keyring';\n\n/**\n * Methods supported by SimpleKeyring EOA accounts.\n * SimpleKeyring supports all standard signing methods plus encryption and app keys.\n */\nconst SIMPLE_KEYRING_METHODS = [\n EthMethod.SignTransaction,\n EthMethod.Sign,\n EthMethod.PersonalSign,\n EthMethod.SignTypedDataV1,\n EthMethod.SignTypedDataV3,\n EthMethod.SignTypedDataV4,\n EthKeyringMethod.Decrypt,\n EthKeyringMethod.GetEncryptionPublicKey,\n EthKeyringMethod.GetAppKeyAddress,\n EthKeyringMethod.SignEip7702Authorization,\n];\n\nconst simpleKeyringCapabilities: KeyringCapabilities = {\n scopes: [EthScope.Eoa],\n privateKey: {\n importFormats: [\n { encoding: PrivateKeyEncoding.Hexadecimal, type: EthAccountType.Eoa },\n ],\n exportFormats: [{ encoding: PrivateKeyEncoding.Hexadecimal }],\n },\n};\n\n/**\n * Concrete {@link Keyring} adapter for {@link SimpleKeyring}.\n *\n * This wrapper exposes the accounts and signing capabilities of the legacy\n * SimpleKeyring via the unified V2 interface.\n */\nexport type SimpleKeyringOptions = {\n legacyKeyring: LegacySimpleKeyring;\n};\n\nexport class SimpleKeyring\n extends EthKeyringWrapper<LegacySimpleKeyring>\n implements Keyring\n{\n constructor(options: SimpleKeyringOptions) {\n super({\n type: KeyringType.PrivateKey,\n inner: options.legacyKeyring,\n capabilities: simpleKeyringCapabilities,\n });\n }\n\n /**\n * Creates a KeyringAccount object for the given address and index.\n *\n * @param address - The account address.\n * @returns The created KeyringAccount.\n */\n #createKeyringAccount(address: Hex): KeyringAccount {\n const id = this.registry.register(address);\n\n const account: KeyringAccount = {\n id,\n type: EthAccountType.Eoa,\n address,\n scopes: [...this.capabilities.scopes],\n methods: [...SIMPLE_KEYRING_METHODS],\n options: {\n entropy: {\n type: KeyringAccountEntropyTypeOption.PrivateKey,\n },\n exportable: true,\n },\n };\n\n // Add the account to the registry\n this.registry.set(account);\n\n return account;\n }\n\n /**\n * Get all private keys from the inner SimpleKeyring.\n *\n * @returns An array of private keys in hexadecimal format.\n */\n async #getPrivateKeys(): Promise<string[]> {\n return await this.inner.serialize();\n }\n\n /**\n * Set private keys in the inner SimpleKeyring.\n *\n * @param privateKeys - An array of private keys in hexadecimal format.\n */\n async #setPrivateKeys(privateKeys: string[]): Promise<void> {\n await this.inner.deserialize(privateKeys);\n }\n\n /**\n * Executes a transactional update on the inner keyring state.\n * If the callback throws, the state is automatically rolled back.\n *\n * @param callback - A function that receives the current private keys and performs the update.\n * Should return the result on success, or throw to trigger rollback.\n * @returns The result of the callback.\n * @throws Error if the callback throws (after rollback).\n */\n async #withRollback<Result>(\n callback: (currentPrivateKeys: string[]) => Promise<Result>,\n ): Promise<Result> {\n const originalPrivateKeys = await this.#getPrivateKeys();\n\n try {\n return await callback(originalPrivateKeys);\n } catch (error) {\n // Rollback on error\n await this.#setPrivateKeys(originalPrivateKeys);\n throw error;\n }\n }\n\n /**\n * Import a private key and return the new address.\n * If the import fails (no new address added), rolls back to the original state.\n *\n * @param privateKey - The private key to import in hexadecimal format.\n * @returns The address of the newly imported account.\n * @throws Error if the import fails or no new address is added.\n */\n async #importPrivateKeyOrRollback(privateKey: string): Promise<Hex> {\n return this.#withRollback(async (currentPrivateKeys) => {\n // Get current addresses before import\n const addressesBefore = new Set(await this.inner.getAccounts());\n\n // Import the new private key\n await this.#setPrivateKeys([...currentPrivateKeys, privateKey]);\n\n // Get addresses after import and find the newly added one\n const addressesAfter = await this.inner.getAccounts();\n\n // Find the new address by diffing the two sets\n const newAddresses = addressesAfter.filter(\n (addr) => !addressesBefore.has(addr),\n );\n\n if (newAddresses.length !== 1 || !newAddresses[0]) {\n throw new Error('Failed to import private key');\n }\n\n return newAddresses[0];\n });\n }\n\n async getAccounts(): Promise<KeyringAccount[]> {\n const addresses = await this.inner.getAccounts();\n\n return addresses.map((address) => {\n // Check if we already have this account in the registry\n const existingId = this.registry.getAccountId(address);\n if (existingId) {\n const cached = this.registry.get(existingId);\n if (cached) {\n return cached;\n }\n }\n\n // Create and register the account if not already cached\n return this.#createKeyringAccount(address);\n });\n }\n\n async createAccounts(\n options: CreateAccountOptions,\n ): Promise<KeyringAccount[]> {\n return this.withLock(async () => {\n // For SimpleKeyring, we only support private key import\n if (options.type !== 'private-key:import') {\n throw new Error(\n `Unsupported account creation type for SimpleKeyring: ${options.type}`,\n );\n }\n\n // Validate account type\n if (options.accountType !== EthAccountType.Eoa) {\n throw new Error(\n `Unsupported account type for SimpleKeyring: ${options.accountType}. Only '${EthAccountType.Eoa}' is supported.`,\n );\n }\n\n const { encoding, privateKey } = options;\n\n // Validate encoding\n if (encoding !== PrivateKeyEncoding.Hexadecimal) {\n throw new Error(\n `Unsupported encoding for SimpleKeyring: ${encoding}. Only '${PrivateKeyEncoding.Hexadecimal}' is supported.`,\n );\n }\n\n // Import the private key (with automatic rollback on failure)\n const newAddress = await this.#importPrivateKeyOrRollback(privateKey);\n\n // Create and return the new KeyringAccount\n const newAccount = this.#createKeyringAccount(newAddress);\n return [newAccount];\n });\n }\n\n /**\n * Delete an account from the keyring.\n *\n * @param accountId - The account ID to delete.\n */\n async deleteAccount(accountId: AccountId): Promise<void> {\n await this.withLock(async () => {\n const account = await this.getAccount(accountId);\n\n // Remove from the legacy keyring\n this.inner.removeAccount(account.address);\n\n // Remove from the registry\n this.registry.delete(accountId);\n });\n }\n\n /**\n * Export the private key for an account in hexadecimal format.\n *\n * @param accountId - The ID of the account to export.\n * @param options - Export options (only hexadecimal encoding is supported).\n * @returns The exported account with private key.\n */\n async exportAccount(\n accountId: AccountId,\n options?: ExportAccountOptions,\n ): Promise<ExportedAccount> {\n const account = await this.getAccount(accountId);\n\n const requestedEncoding =\n options?.encoding ?? PrivateKeyEncoding.Hexadecimal;\n\n if (requestedEncoding !== PrivateKeyEncoding.Hexadecimal) {\n throw new Error(\n `Unsupported encoding for SimpleKeyring: ${requestedEncoding}. Only '${PrivateKeyEncoding.Hexadecimal}' is supported.`,\n );\n }\n\n const privateKeyHex = await this.inner.exportAccount(\n this.toHexAddress(account.address),\n );\n // Sanitize private key format\n const privateKey = add0x(privateKeyHex);\n\n const exported: ExportedAccount = {\n type: 'private-key',\n privateKey,\n encoding: PrivateKeyEncoding.Hexadecimal,\n };\n\n return exported;\n }\n}\n"]}
@@ -1,19 +1,20 @@
1
- import { type CreateAccountOptions, type ExportAccountOptions, type ExportedAccount, type KeyringAccount, type KeyringV2 } from "@metamask/keyring-api";
2
- import { EthKeyringWrapper } from "@metamask/keyring-sdk";
1
+ import type { KeyringAccount } from "@metamask/keyring-api";
2
+ import type { CreateAccountOptions, ExportAccountOptions, ExportedAccount, Keyring } from "@metamask/keyring-api/v2";
3
+ import { EthKeyringWrapper } from "@metamask/keyring-sdk/v2";
3
4
  import type { AccountId } from "@metamask/keyring-utils";
4
- import type SimpleKeyring from "./simple-keyring.mjs";
5
+ import type LegacySimpleKeyring from "../simple-keyring.cjs";
5
6
  /**
6
- * Concrete {@link KeyringV2} adapter for {@link SimpleKeyring}.
7
+ * Concrete {@link Keyring} adapter for {@link SimpleKeyring}.
7
8
  *
8
9
  * This wrapper exposes the accounts and signing capabilities of the legacy
9
10
  * SimpleKeyring via the unified V2 interface.
10
11
  */
11
- export type SimpleKeyringV2Options = {
12
- legacyKeyring: SimpleKeyring;
12
+ export type SimpleKeyringOptions = {
13
+ legacyKeyring: LegacySimpleKeyring;
13
14
  };
14
- export declare class SimpleKeyringV2 extends EthKeyringWrapper<SimpleKeyring> implements KeyringV2 {
15
+ export declare class SimpleKeyring extends EthKeyringWrapper<LegacySimpleKeyring> implements Keyring {
15
16
  #private;
16
- constructor(options: SimpleKeyringV2Options);
17
+ constructor(options: SimpleKeyringOptions);
17
18
  getAccounts(): Promise<KeyringAccount[]>;
18
19
  createAccounts(options: CreateAccountOptions): Promise<KeyringAccount[]>;
19
20
  /**
@@ -31,4 +32,4 @@ export declare class SimpleKeyringV2 extends EthKeyringWrapper<SimpleKeyring> im
31
32
  */
32
33
  exportAccount(accountId: AccountId, options?: ExportAccountOptions): Promise<ExportedAccount>;
33
34
  }
34
- //# sourceMappingURL=simple-keyring-v2.d.mts.map
35
+ //# sourceMappingURL=simple-keyring.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"simple-keyring.d.cts","sourceRoot":"","sources":["../../src/v2/simple-keyring.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,cAAc,EAAE,8BAA8B;AAE5D,OAAO,KAAK,EACV,oBAAoB,EACpB,oBAAoB,EACpB,eAAe,EAEf,OAAO,EACR,iCAAiC;AAClC,OAAO,EAAoB,iBAAiB,EAAE,iCAAiC;AAC/E,OAAO,KAAK,EAAE,SAAS,EAAE,gCAAgC;AAIzD,OAAO,KAAK,mBAAmB,8BAA0B;AA6BzD;;;;;GAKG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,aAAa,EAAE,mBAAmB,CAAC;CACpC,CAAC;AAEF,qBAAa,aACX,SAAQ,iBAAiB,CAAC,mBAAmB,CAC7C,YAAW,OAAO;;gBAEN,OAAO,EAAE,oBAAoB;IA8GnC,WAAW,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;IAkBxC,cAAc,CAClB,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,cAAc,EAAE,CAAC;IAkC5B;;;;OAIG;IACG,aAAa,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IAYxD;;;;;;OAMG;IACG,aAAa,CACjB,SAAS,EAAE,SAAS,EACpB,OAAO,CAAC,EAAE,oBAAoB,GAC7B,OAAO,CAAC,eAAe,CAAC;CA0B5B"}
@@ -1,19 +1,20 @@
1
- import { type CreateAccountOptions, type ExportAccountOptions, type ExportedAccount, type KeyringAccount, type KeyringV2 } from "@metamask/keyring-api";
2
- import { EthKeyringWrapper } from "@metamask/keyring-sdk";
1
+ import type { KeyringAccount } from "@metamask/keyring-api";
2
+ import type { CreateAccountOptions, ExportAccountOptions, ExportedAccount, Keyring } from "@metamask/keyring-api/v2";
3
+ import { EthKeyringWrapper } from "@metamask/keyring-sdk/v2";
3
4
  import type { AccountId } from "@metamask/keyring-utils";
4
- import type SimpleKeyring from "./simple-keyring.cjs";
5
+ import type LegacySimpleKeyring from "../simple-keyring.mjs";
5
6
  /**
6
- * Concrete {@link KeyringV2} adapter for {@link SimpleKeyring}.
7
+ * Concrete {@link Keyring} adapter for {@link SimpleKeyring}.
7
8
  *
8
9
  * This wrapper exposes the accounts and signing capabilities of the legacy
9
10
  * SimpleKeyring via the unified V2 interface.
10
11
  */
11
- export type SimpleKeyringV2Options = {
12
- legacyKeyring: SimpleKeyring;
12
+ export type SimpleKeyringOptions = {
13
+ legacyKeyring: LegacySimpleKeyring;
13
14
  };
14
- export declare class SimpleKeyringV2 extends EthKeyringWrapper<SimpleKeyring> implements KeyringV2 {
15
+ export declare class SimpleKeyring extends EthKeyringWrapper<LegacySimpleKeyring> implements Keyring {
15
16
  #private;
16
- constructor(options: SimpleKeyringV2Options);
17
+ constructor(options: SimpleKeyringOptions);
17
18
  getAccounts(): Promise<KeyringAccount[]>;
18
19
  createAccounts(options: CreateAccountOptions): Promise<KeyringAccount[]>;
19
20
  /**
@@ -31,4 +32,4 @@ export declare class SimpleKeyringV2 extends EthKeyringWrapper<SimpleKeyring> im
31
32
  */
32
33
  exportAccount(accountId: AccountId, options?: ExportAccountOptions): Promise<ExportedAccount>;
33
34
  }
34
- //# sourceMappingURL=simple-keyring-v2.d.cts.map
35
+ //# sourceMappingURL=simple-keyring.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"simple-keyring.d.mts","sourceRoot":"","sources":["../../src/v2/simple-keyring.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,cAAc,EAAE,8BAA8B;AAE5D,OAAO,KAAK,EACV,oBAAoB,EACpB,oBAAoB,EACpB,eAAe,EAEf,OAAO,EACR,iCAAiC;AAClC,OAAO,EAAoB,iBAAiB,EAAE,iCAAiC;AAC/E,OAAO,KAAK,EAAE,SAAS,EAAE,gCAAgC;AAIzD,OAAO,KAAK,mBAAmB,8BAA0B;AA6BzD;;;;;GAKG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,aAAa,EAAE,mBAAmB,CAAC;CACpC,CAAC;AAEF,qBAAa,aACX,SAAQ,iBAAiB,CAAC,mBAAmB,CAC7C,YAAW,OAAO;;gBAEN,OAAO,EAAE,oBAAoB;IA8GnC,WAAW,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;IAkBxC,cAAc,CAClB,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,cAAc,EAAE,CAAC;IAkC5B;;;;OAIG;IACG,aAAa,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IAYxD;;;;;;OAMG;IACG,aAAa,CACjB,SAAS,EAAE,SAAS,EACpB,OAAO,CAAC,EAAE,oBAAoB,GAC7B,OAAO,CAAC,eAAe,CAAC;CA0B5B"}
@@ -3,9 +3,10 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
3
3
  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
4
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
5
  };
6
- var _SimpleKeyringV2_instances, _SimpleKeyringV2_createKeyringAccount, _SimpleKeyringV2_getPrivateKeys, _SimpleKeyringV2_setPrivateKeys, _SimpleKeyringV2_withRollback, _SimpleKeyringV2_importPrivateKeyOrRollback;
7
- import { EthAccountType, EthMethod, EthScope, KeyringAccountEntropyTypeOption, KeyringType, PrivateKeyEncoding } from "@metamask/keyring-api";
8
- import { EthKeyringMethod, EthKeyringWrapper } from "@metamask/keyring-sdk";
6
+ var _SimpleKeyring_instances, _SimpleKeyring_createKeyringAccount, _SimpleKeyring_getPrivateKeys, _SimpleKeyring_setPrivateKeys, _SimpleKeyring_withRollback, _SimpleKeyring_importPrivateKeyOrRollback;
7
+ import { EthAccountType, EthMethod, EthScope, KeyringAccountEntropyTypeOption } from "@metamask/keyring-api";
8
+ import { KeyringType, PrivateKeyEncoding } from "@metamask/keyring-api/v2";
9
+ import { EthKeyringMethod, EthKeyringWrapper } from "@metamask/keyring-sdk/v2";
9
10
  import { add0x } from "@metamask/utils";
10
11
  /**
11
12
  * Methods supported by SimpleKeyring EOA accounts.
@@ -23,7 +24,7 @@ const SIMPLE_KEYRING_METHODS = [
23
24
  EthKeyringMethod.GetAppKeyAddress,
24
25
  EthKeyringMethod.SignEip7702Authorization,
25
26
  ];
26
- const simpleKeyringV2Capabilities = {
27
+ const simpleKeyringCapabilities = {
27
28
  scopes: [EthScope.Eoa],
28
29
  privateKey: {
29
30
  importFormats: [
@@ -32,14 +33,14 @@ const simpleKeyringV2Capabilities = {
32
33
  exportFormats: [{ encoding: PrivateKeyEncoding.Hexadecimal }],
33
34
  },
34
35
  };
35
- export class SimpleKeyringV2 extends EthKeyringWrapper {
36
+ export class SimpleKeyring extends EthKeyringWrapper {
36
37
  constructor(options) {
37
38
  super({
38
39
  type: KeyringType.PrivateKey,
39
40
  inner: options.legacyKeyring,
40
- capabilities: simpleKeyringV2Capabilities,
41
+ capabilities: simpleKeyringCapabilities,
41
42
  });
42
- _SimpleKeyringV2_instances.add(this);
43
+ _SimpleKeyring_instances.add(this);
43
44
  }
44
45
  async getAccounts() {
45
46
  const addresses = await this.inner.getAccounts();
@@ -53,7 +54,7 @@ export class SimpleKeyringV2 extends EthKeyringWrapper {
53
54
  }
54
55
  }
55
56
  // Create and register the account if not already cached
56
- return __classPrivateFieldGet(this, _SimpleKeyringV2_instances, "m", _SimpleKeyringV2_createKeyringAccount).call(this, address);
57
+ return __classPrivateFieldGet(this, _SimpleKeyring_instances, "m", _SimpleKeyring_createKeyringAccount).call(this, address);
57
58
  });
58
59
  }
59
60
  async createAccounts(options) {
@@ -72,9 +73,9 @@ export class SimpleKeyringV2 extends EthKeyringWrapper {
72
73
  throw new Error(`Unsupported encoding for SimpleKeyring: ${encoding}. Only '${PrivateKeyEncoding.Hexadecimal}' is supported.`);
73
74
  }
74
75
  // Import the private key (with automatic rollback on failure)
75
- const newAddress = await __classPrivateFieldGet(this, _SimpleKeyringV2_instances, "m", _SimpleKeyringV2_importPrivateKeyOrRollback).call(this, privateKey);
76
+ const newAddress = await __classPrivateFieldGet(this, _SimpleKeyring_instances, "m", _SimpleKeyring_importPrivateKeyOrRollback).call(this, privateKey);
76
77
  // Create and return the new KeyringAccount
77
- const newAccount = __classPrivateFieldGet(this, _SimpleKeyringV2_instances, "m", _SimpleKeyringV2_createKeyringAccount).call(this, newAddress);
78
+ const newAccount = __classPrivateFieldGet(this, _SimpleKeyring_instances, "m", _SimpleKeyring_createKeyringAccount).call(this, newAddress);
78
79
  return [newAccount];
79
80
  });
80
81
  }
@@ -116,7 +117,7 @@ export class SimpleKeyringV2 extends EthKeyringWrapper {
116
117
  return exported;
117
118
  }
118
119
  }
119
- _SimpleKeyringV2_instances = new WeakSet(), _SimpleKeyringV2_createKeyringAccount = function _SimpleKeyringV2_createKeyringAccount(address) {
120
+ _SimpleKeyring_instances = new WeakSet(), _SimpleKeyring_createKeyringAccount = function _SimpleKeyring_createKeyringAccount(address) {
120
121
  const id = this.registry.register(address);
121
122
  const account = {
122
123
  id,
@@ -134,23 +135,23 @@ _SimpleKeyringV2_instances = new WeakSet(), _SimpleKeyringV2_createKeyringAccoun
134
135
  // Add the account to the registry
135
136
  this.registry.set(account);
136
137
  return account;
137
- }, _SimpleKeyringV2_getPrivateKeys =
138
+ }, _SimpleKeyring_getPrivateKeys =
138
139
  /**
139
140
  * Get all private keys from the inner SimpleKeyring.
140
141
  *
141
142
  * @returns An array of private keys in hexadecimal format.
142
143
  */
143
- async function _SimpleKeyringV2_getPrivateKeys() {
144
+ async function _SimpleKeyring_getPrivateKeys() {
144
145
  return await this.inner.serialize();
145
- }, _SimpleKeyringV2_setPrivateKeys =
146
+ }, _SimpleKeyring_setPrivateKeys =
146
147
  /**
147
148
  * Set private keys in the inner SimpleKeyring.
148
149
  *
149
150
  * @param privateKeys - An array of private keys in hexadecimal format.
150
151
  */
151
- async function _SimpleKeyringV2_setPrivateKeys(privateKeys) {
152
+ async function _SimpleKeyring_setPrivateKeys(privateKeys) {
152
153
  await this.inner.deserialize(privateKeys);
153
- }, _SimpleKeyringV2_withRollback =
154
+ }, _SimpleKeyring_withRollback =
154
155
  /**
155
156
  * Executes a transactional update on the inner keyring state.
156
157
  * If the callback throws, the state is automatically rolled back.
@@ -160,17 +161,17 @@ async function _SimpleKeyringV2_setPrivateKeys(privateKeys) {
160
161
  * @returns The result of the callback.
161
162
  * @throws Error if the callback throws (after rollback).
162
163
  */
163
- async function _SimpleKeyringV2_withRollback(callback) {
164
- const originalPrivateKeys = await __classPrivateFieldGet(this, _SimpleKeyringV2_instances, "m", _SimpleKeyringV2_getPrivateKeys).call(this);
164
+ async function _SimpleKeyring_withRollback(callback) {
165
+ const originalPrivateKeys = await __classPrivateFieldGet(this, _SimpleKeyring_instances, "m", _SimpleKeyring_getPrivateKeys).call(this);
165
166
  try {
166
167
  return await callback(originalPrivateKeys);
167
168
  }
168
169
  catch (error) {
169
170
  // Rollback on error
170
- await __classPrivateFieldGet(this, _SimpleKeyringV2_instances, "m", _SimpleKeyringV2_setPrivateKeys).call(this, originalPrivateKeys);
171
+ await __classPrivateFieldGet(this, _SimpleKeyring_instances, "m", _SimpleKeyring_setPrivateKeys).call(this, originalPrivateKeys);
171
172
  throw error;
172
173
  }
173
- }, _SimpleKeyringV2_importPrivateKeyOrRollback =
174
+ }, _SimpleKeyring_importPrivateKeyOrRollback =
174
175
  /**
175
176
  * Import a private key and return the new address.
176
177
  * If the import fails (no new address added), rolls back to the original state.
@@ -179,12 +180,12 @@ async function _SimpleKeyringV2_withRollback(callback) {
179
180
  * @returns The address of the newly imported account.
180
181
  * @throws Error if the import fails or no new address is added.
181
182
  */
182
- async function _SimpleKeyringV2_importPrivateKeyOrRollback(privateKey) {
183
- return __classPrivateFieldGet(this, _SimpleKeyringV2_instances, "m", _SimpleKeyringV2_withRollback).call(this, async (currentPrivateKeys) => {
183
+ async function _SimpleKeyring_importPrivateKeyOrRollback(privateKey) {
184
+ return __classPrivateFieldGet(this, _SimpleKeyring_instances, "m", _SimpleKeyring_withRollback).call(this, async (currentPrivateKeys) => {
184
185
  // Get current addresses before import
185
186
  const addressesBefore = new Set(await this.inner.getAccounts());
186
187
  // Import the new private key
187
- await __classPrivateFieldGet(this, _SimpleKeyringV2_instances, "m", _SimpleKeyringV2_setPrivateKeys).call(this, [...currentPrivateKeys, privateKey]);
188
+ await __classPrivateFieldGet(this, _SimpleKeyring_instances, "m", _SimpleKeyring_setPrivateKeys).call(this, [...currentPrivateKeys, privateKey]);
188
189
  // Get addresses after import and find the newly added one
189
190
  const addressesAfter = await this.inner.getAccounts();
190
191
  // Find the new address by diffing the two sets
@@ -195,4 +196,4 @@ async function _SimpleKeyringV2_importPrivateKeyOrRollback(privateKey) {
195
196
  return newAddresses[0];
196
197
  });
197
198
  };
198
- //# sourceMappingURL=simple-keyring-v2.mjs.map
199
+ //# sourceMappingURL=simple-keyring.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"simple-keyring.mjs","sourceRoot":"","sources":["../../src/v2/simple-keyring.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EACL,cAAc,EACd,SAAS,EACT,QAAQ,EACR,+BAA+B,EAChC,8BAA8B;AAE/B,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,iCAAiC;AAQ3E,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,iCAAiC;AAE/E,OAAO,EAAE,KAAK,EAAE,wBAAwB;AAKxC;;;GAGG;AACH,MAAM,sBAAsB,GAAG;IAC7B,SAAS,CAAC,eAAe;IACzB,SAAS,CAAC,IAAI;IACd,SAAS,CAAC,YAAY;IACtB,SAAS,CAAC,eAAe;IACzB,SAAS,CAAC,eAAe;IACzB,SAAS,CAAC,eAAe;IACzB,gBAAgB,CAAC,OAAO;IACxB,gBAAgB,CAAC,sBAAsB;IACvC,gBAAgB,CAAC,gBAAgB;IACjC,gBAAgB,CAAC,wBAAwB;C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AAC,CAAC,CAAC,EAAE,CAAC;YAClD,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;QAClD,CAAC;QAED,OAAO,YAAY,CAAC,CAAC,CAAC,CAAC;IACzB,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n EthAccountType,\n EthMethod,\n EthScope,\n KeyringAccountEntropyTypeOption,\n} from '@metamask/keyring-api';\nimport type { KeyringAccount } from '@metamask/keyring-api';\nimport { KeyringType, PrivateKeyEncoding } from '@metamask/keyring-api/v2';\nimport type {\n CreateAccountOptions,\n ExportAccountOptions,\n ExportedAccount,\n KeyringCapabilities,\n Keyring,\n} from '@metamask/keyring-api/v2';\nimport { EthKeyringMethod, EthKeyringWrapper } from '@metamask/keyring-sdk/v2';\nimport type { AccountId } from '@metamask/keyring-utils';\nimport { add0x } from '@metamask/utils';\nimport type { Hex } from '@metamask/utils';\n\nimport type LegacySimpleKeyring from '../simple-keyring';\n\n/**\n * Methods supported by SimpleKeyring EOA accounts.\n * SimpleKeyring supports all standard signing methods plus encryption and app keys.\n */\nconst SIMPLE_KEYRING_METHODS = [\n EthMethod.SignTransaction,\n EthMethod.Sign,\n EthMethod.PersonalSign,\n EthMethod.SignTypedDataV1,\n EthMethod.SignTypedDataV3,\n EthMethod.SignTypedDataV4,\n EthKeyringMethod.Decrypt,\n EthKeyringMethod.GetEncryptionPublicKey,\n EthKeyringMethod.GetAppKeyAddress,\n EthKeyringMethod.SignEip7702Authorization,\n];\n\nconst simpleKeyringCapabilities: KeyringCapabilities = {\n scopes: [EthScope.Eoa],\n privateKey: {\n importFormats: [\n { encoding: PrivateKeyEncoding.Hexadecimal, type: EthAccountType.Eoa },\n ],\n exportFormats: [{ encoding: PrivateKeyEncoding.Hexadecimal }],\n },\n};\n\n/**\n * Concrete {@link Keyring} adapter for {@link SimpleKeyring}.\n *\n * This wrapper exposes the accounts and signing capabilities of the legacy\n * SimpleKeyring via the unified V2 interface.\n */\nexport type SimpleKeyringOptions = {\n legacyKeyring: LegacySimpleKeyring;\n};\n\nexport class SimpleKeyring\n extends EthKeyringWrapper<LegacySimpleKeyring>\n implements Keyring\n{\n constructor(options: SimpleKeyringOptions) {\n super({\n type: KeyringType.PrivateKey,\n inner: options.legacyKeyring,\n capabilities: simpleKeyringCapabilities,\n });\n }\n\n /**\n * Creates a KeyringAccount object for the given address and index.\n *\n * @param address - The account address.\n * @returns The created KeyringAccount.\n */\n #createKeyringAccount(address: Hex): KeyringAccount {\n const id = this.registry.register(address);\n\n const account: KeyringAccount = {\n id,\n type: EthAccountType.Eoa,\n address,\n scopes: [...this.capabilities.scopes],\n methods: [...SIMPLE_KEYRING_METHODS],\n options: {\n entropy: {\n type: KeyringAccountEntropyTypeOption.PrivateKey,\n },\n exportable: true,\n },\n };\n\n // Add the account to the registry\n this.registry.set(account);\n\n return account;\n }\n\n /**\n * Get all private keys from the inner SimpleKeyring.\n *\n * @returns An array of private keys in hexadecimal format.\n */\n async #getPrivateKeys(): Promise<string[]> {\n return await this.inner.serialize();\n }\n\n /**\n * Set private keys in the inner SimpleKeyring.\n *\n * @param privateKeys - An array of private keys in hexadecimal format.\n */\n async #setPrivateKeys(privateKeys: string[]): Promise<void> {\n await this.inner.deserialize(privateKeys);\n }\n\n /**\n * Executes a transactional update on the inner keyring state.\n * If the callback throws, the state is automatically rolled back.\n *\n * @param callback - A function that receives the current private keys and performs the update.\n * Should return the result on success, or throw to trigger rollback.\n * @returns The result of the callback.\n * @throws Error if the callback throws (after rollback).\n */\n async #withRollback<Result>(\n callback: (currentPrivateKeys: string[]) => Promise<Result>,\n ): Promise<Result> {\n const originalPrivateKeys = await this.#getPrivateKeys();\n\n try {\n return await callback(originalPrivateKeys);\n } catch (error) {\n // Rollback on error\n await this.#setPrivateKeys(originalPrivateKeys);\n throw error;\n }\n }\n\n /**\n * Import a private key and return the new address.\n * If the import fails (no new address added), rolls back to the original state.\n *\n * @param privateKey - The private key to import in hexadecimal format.\n * @returns The address of the newly imported account.\n * @throws Error if the import fails or no new address is added.\n */\n async #importPrivateKeyOrRollback(privateKey: string): Promise<Hex> {\n return this.#withRollback(async (currentPrivateKeys) => {\n // Get current addresses before import\n const addressesBefore = new Set(await this.inner.getAccounts());\n\n // Import the new private key\n await this.#setPrivateKeys([...currentPrivateKeys, privateKey]);\n\n // Get addresses after import and find the newly added one\n const addressesAfter = await this.inner.getAccounts();\n\n // Find the new address by diffing the two sets\n const newAddresses = addressesAfter.filter(\n (addr) => !addressesBefore.has(addr),\n );\n\n if (newAddresses.length !== 1 || !newAddresses[0]) {\n throw new Error('Failed to import private key');\n }\n\n return newAddresses[0];\n });\n }\n\n async getAccounts(): Promise<KeyringAccount[]> {\n const addresses = await this.inner.getAccounts();\n\n return addresses.map((address) => {\n // Check if we already have this account in the registry\n const existingId = this.registry.getAccountId(address);\n if (existingId) {\n const cached = this.registry.get(existingId);\n if (cached) {\n return cached;\n }\n }\n\n // Create and register the account if not already cached\n return this.#createKeyringAccount(address);\n });\n }\n\n async createAccounts(\n options: CreateAccountOptions,\n ): Promise<KeyringAccount[]> {\n return this.withLock(async () => {\n // For SimpleKeyring, we only support private key import\n if (options.type !== 'private-key:import') {\n throw new Error(\n `Unsupported account creation type for SimpleKeyring: ${options.type}`,\n );\n }\n\n // Validate account type\n if (options.accountType !== EthAccountType.Eoa) {\n throw new Error(\n `Unsupported account type for SimpleKeyring: ${options.accountType}. Only '${EthAccountType.Eoa}' is supported.`,\n );\n }\n\n const { encoding, privateKey } = options;\n\n // Validate encoding\n if (encoding !== PrivateKeyEncoding.Hexadecimal) {\n throw new Error(\n `Unsupported encoding for SimpleKeyring: ${encoding}. Only '${PrivateKeyEncoding.Hexadecimal}' is supported.`,\n );\n }\n\n // Import the private key (with automatic rollback on failure)\n const newAddress = await this.#importPrivateKeyOrRollback(privateKey);\n\n // Create and return the new KeyringAccount\n const newAccount = this.#createKeyringAccount(newAddress);\n return [newAccount];\n });\n }\n\n /**\n * Delete an account from the keyring.\n *\n * @param accountId - The account ID to delete.\n */\n async deleteAccount(accountId: AccountId): Promise<void> {\n await this.withLock(async () => {\n const account = await this.getAccount(accountId);\n\n // Remove from the legacy keyring\n this.inner.removeAccount(account.address);\n\n // Remove from the registry\n this.registry.delete(accountId);\n });\n }\n\n /**\n * Export the private key for an account in hexadecimal format.\n *\n * @param accountId - The ID of the account to export.\n * @param options - Export options (only hexadecimal encoding is supported).\n * @returns The exported account with private key.\n */\n async exportAccount(\n accountId: AccountId,\n options?: ExportAccountOptions,\n ): Promise<ExportedAccount> {\n const account = await this.getAccount(accountId);\n\n const requestedEncoding =\n options?.encoding ?? PrivateKeyEncoding.Hexadecimal;\n\n if (requestedEncoding !== PrivateKeyEncoding.Hexadecimal) {\n throw new Error(\n `Unsupported encoding for SimpleKeyring: ${requestedEncoding}. Only '${PrivateKeyEncoding.Hexadecimal}' is supported.`,\n );\n }\n\n const privateKeyHex = await this.inner.exportAccount(\n this.toHexAddress(account.address),\n );\n // Sanitize private key format\n const privateKey = add0x(privateKeyHex);\n\n const exported: ExportedAccount = {\n type: 'private-key',\n privateKey,\n encoding: PrivateKeyEncoding.Hexadecimal,\n };\n\n return exported;\n }\n}\n"]}
package/package.json CHANGED
@@ -1,19 +1,27 @@
1
1
  {
2
2
  "name": "@metamask-previews/eth-simple-keyring",
3
- "version": "11.1.2-5c366be",
4
- "description": "A simple standard interface for a series of Ethereum private keys.",
3
+ "version": "12.0.1-7275dbc",
4
+ "description": "A simple standard interface for a series of Ethereum private keys",
5
5
  "keywords": [
6
6
  "ethereum",
7
7
  "keyring"
8
8
  ],
9
- "homepage": "https://github.com/MetaMask/eth-simple-keyring#readme",
9
+ "homepage": "https://github.com/MetaMask/accounts/tree/main/packages/keyring-eth-simple#readme",
10
10
  "bugs": {
11
- "url": "https://github.com/MetaMask/eth-simple-keyring/issues"
11
+ "url": "https://github.com/MetaMask/accounts/issues"
12
12
  },
13
+ "license": "ISC",
13
14
  "repository": {
14
15
  "type": "git",
15
- "url": "https://github.com/MetaMask/eth-simple-keyring.git"
16
+ "url": "https://github.com/MetaMask/accounts.git"
16
17
  },
18
+ "files": [
19
+ "dist/",
20
+ "v2.js"
21
+ ],
22
+ "sideEffects": false,
23
+ "main": "./dist/index.cjs",
24
+ "types": "./dist/index.d.cts",
17
25
  "exports": {
18
26
  ".": {
19
27
  "import": {
@@ -24,31 +32,46 @@
24
32
  "types": "./dist/index.d.cts",
25
33
  "default": "./dist/index.cjs"
26
34
  }
27
- }
35
+ },
36
+ "./v2": {
37
+ "import": {
38
+ "types": "./dist/v2/index.d.mts",
39
+ "default": "./dist/v2/index.mjs"
40
+ },
41
+ "require": {
42
+ "types": "./dist/v2/index.d.cts",
43
+ "default": "./dist/v2/index.cjs"
44
+ }
45
+ },
46
+ "./package.json": "./package.json"
47
+ },
48
+ "publishConfig": {
49
+ "access": "public",
50
+ "registry": "https://registry.npmjs.org/"
28
51
  },
29
- "main": "./dist/index.cjs",
30
- "types": "./dist/index.d.cts",
31
- "files": [
32
- "dist/"
33
- ],
34
52
  "scripts": {
35
- "build": "ts-bridge --project tsconfig.build.json --no-references",
53
+ "build": "ts-bridge --project tsconfig.build.json --verbose --clean --no-references",
54
+ "build:all": "ts-bridge --project tsconfig.build.json --verbose --clean",
36
55
  "build:clean": "yarn build --clean",
37
56
  "build:docs": "typedoc",
38
57
  "changelog:update": "../../scripts/update-changelog.sh @metamask/eth-simple-keyring",
39
58
  "changelog:validate": "../../scripts/validate-changelog.sh @metamask/eth-simple-keyring",
40
59
  "publish:preview": "yarn npm publish --tag preview",
41
60
  "sample": "ts-node src/sample.ts",
42
- "test": "jest",
43
- "test:clean": "jest --clearCache",
44
- "test:watch": "jest --watch"
61
+ "since-latest-release": "../../scripts/since-latest-release.sh",
62
+ "test": "yarn test:source && yarn test:types",
63
+ "test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",
64
+ "test:source": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
65
+ "test:types": "../../scripts/tsd-test.sh ./src",
66
+ "test:verbose": "NODE_OPTIONS=--experimental-vm-modules jest --verbose",
67
+ "test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
45
68
  },
46
69
  "dependencies": {
47
70
  "@ethereumjs/util": "^9.1.0",
48
71
  "@metamask/eth-sig-util": "^8.2.0",
49
- "@metamask/keyring-api": "22.0.0",
50
- "@metamask/keyring-sdk": "1.2.0",
51
- "@metamask/utils": "^11.10.0",
72
+ "@metamask/keyring-api": "23.0.1",
73
+ "@metamask/keyring-sdk": "2.0.1",
74
+ "@metamask/utils": "^11.11.0",
52
75
  "ethereum-cryptography": "^2.2.1",
53
76
  "randombytes": "^2.1.0"
54
77
  },
@@ -56,7 +79,7 @@
56
79
  "@ethereumjs/tx": "^5.4.0",
57
80
  "@lavamoat/allow-scripts": "^3.2.1",
58
81
  "@lavamoat/preinstall-always-fail": "^2.1.0",
59
- "@metamask/auto-changelog": "^3.4.4",
82
+ "@metamask/auto-changelog": "^6.1.0",
60
83
  "@metamask/keyring-utils": "3.2.0",
61
84
  "@ts-bridge/cli": "^0.6.3",
62
85
  "@types/ethereumjs-tx": "^1.0.1",
@@ -75,10 +98,6 @@
75
98
  "engines": {
76
99
  "node": "^18.18 || >=20"
77
100
  },
78
- "publishConfig": {
79
- "access": "public",
80
- "registry": "https://registry.npmjs.org/"
81
- },
82
101
  "lavamoat": {
83
102
  "allowScripts": {
84
103
  "keccak": true,
package/v2.js ADDED
@@ -0,0 +1,3 @@
1
+ // Re-exported for compatibility with Browserify.
2
+ // eslint-disable-next-line
3
+ module.exports = require('./dist/v2/index.cjs');
@@ -1 +0,0 @@
1
- {"version":3,"file":"simple-keyring-v2.cjs","sourceRoot":"","sources":["../src/simple-keyring-v2.ts"],"names":[],"mappings":";;;;;;;;;AAAA,uDAa+B;AAC/B,uDAA4E;AAE5E,2CAAkD;AAKlD;;;GAGG;AACH,MAAM,sBAAsB,GAAG;IAC7B,uBAAS,CAAC,eAAe;IACzB,uBAAS,CAAC,IAAI;IACd,uB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C,WAAW,EAAE,CAAC;QAEtD,+CAA+C;QAC/C,MAAM,YAAY,GAAG,cAAc,CAAC,MAAM,CACxC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,CACrC,CAAC;QAEF,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC;YAClD,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;QAClD,CAAC;QAED,OAAO,YAAY,CAAC,CAAC,CAAC,CAAC;IACzB,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n type CreateAccountOptions,\n EthAccountType,\n EthMethod,\n EthScope,\n type ExportAccountOptions,\n type ExportedAccount,\n type KeyringAccount,\n KeyringAccountEntropyTypeOption,\n type KeyringCapabilities,\n type KeyringV2,\n KeyringType,\n PrivateKeyEncoding,\n} from '@metamask/keyring-api';\nimport { EthKeyringMethod, EthKeyringWrapper } from '@metamask/keyring-sdk';\nimport type { AccountId } from '@metamask/keyring-utils';\nimport { add0x, type Hex } from '@metamask/utils';\n\n// eslint-disable-next-line @typescript-eslint/naming-convention\nimport type SimpleKeyring from './simple-keyring';\n\n/**\n * Methods supported by SimpleKeyring EOA accounts.\n * SimpleKeyring supports all standard signing methods plus encryption and app keys.\n */\nconst SIMPLE_KEYRING_METHODS = [\n EthMethod.SignTransaction,\n EthMethod.Sign,\n EthMethod.PersonalSign,\n EthMethod.SignTypedDataV1,\n EthMethod.SignTypedDataV3,\n EthMethod.SignTypedDataV4,\n EthKeyringMethod.Decrypt,\n EthKeyringMethod.GetEncryptionPublicKey,\n EthKeyringMethod.GetAppKeyAddress,\n EthKeyringMethod.SignEip7702Authorization,\n];\n\nconst simpleKeyringV2Capabilities: KeyringCapabilities = {\n scopes: [EthScope.Eoa],\n privateKey: {\n importFormats: [\n { encoding: PrivateKeyEncoding.Hexadecimal, type: EthAccountType.Eoa },\n ],\n exportFormats: [{ encoding: PrivateKeyEncoding.Hexadecimal }],\n },\n};\n\n/**\n * Concrete {@link KeyringV2} adapter for {@link SimpleKeyring}.\n *\n * This wrapper exposes the accounts and signing capabilities of the legacy\n * SimpleKeyring via the unified V2 interface.\n */\nexport type SimpleKeyringV2Options = {\n legacyKeyring: SimpleKeyring;\n};\n\nexport class SimpleKeyringV2\n extends EthKeyringWrapper<SimpleKeyring>\n implements KeyringV2\n{\n constructor(options: SimpleKeyringV2Options) {\n super({\n type: KeyringType.PrivateKey,\n inner: options.legacyKeyring,\n capabilities: simpleKeyringV2Capabilities,\n });\n }\n\n /**\n * Creates a KeyringAccount object for the given address and index.\n *\n * @param address - The account address.\n * @returns The created KeyringAccount.\n */\n #createKeyringAccount(address: Hex): KeyringAccount {\n const id = this.registry.register(address);\n\n const account: KeyringAccount = {\n id,\n type: EthAccountType.Eoa,\n address,\n scopes: [...this.capabilities.scopes],\n methods: [...SIMPLE_KEYRING_METHODS],\n options: {\n entropy: {\n type: KeyringAccountEntropyTypeOption.PrivateKey,\n },\n exportable: true,\n },\n };\n\n // Add the account to the registry\n this.registry.set(account);\n\n return account;\n }\n\n /**\n * Get all private keys from the inner SimpleKeyring.\n *\n * @returns An array of private keys in hexadecimal format.\n */\n async #getPrivateKeys(): Promise<string[]> {\n return await this.inner.serialize();\n }\n\n /**\n * Set private keys in the inner SimpleKeyring.\n *\n * @param privateKeys - An array of private keys in hexadecimal format.\n */\n async #setPrivateKeys(privateKeys: string[]): Promise<void> {\n await this.inner.deserialize(privateKeys);\n }\n\n /**\n * Executes a transactional update on the inner keyring state.\n * If the callback throws, the state is automatically rolled back.\n *\n * @param callback - A function that receives the current private keys and performs the update.\n * Should return the result on success, or throw to trigger rollback.\n * @returns The result of the callback.\n * @throws Error if the callback throws (after rollback).\n */\n async #withRollback<Result>(\n callback: (currentPrivateKeys: string[]) => Promise<Result>,\n ): Promise<Result> {\n const originalPrivateKeys = await this.#getPrivateKeys();\n\n try {\n return await callback(originalPrivateKeys);\n } catch (error) {\n // Rollback on error\n await this.#setPrivateKeys(originalPrivateKeys);\n throw error;\n }\n }\n\n /**\n * Import a private key and return the new address.\n * If the import fails (no new address added), rolls back to the original state.\n *\n * @param privateKey - The private key to import in hexadecimal format.\n * @returns The address of the newly imported account.\n * @throws Error if the import fails or no new address is added.\n */\n async #importPrivateKeyOrRollback(privateKey: string): Promise<Hex> {\n return this.#withRollback(async (currentPrivateKeys) => {\n // Get current addresses before import\n const addressesBefore = new Set(await this.inner.getAccounts());\n\n // Import the new private key\n await this.#setPrivateKeys([...currentPrivateKeys, privateKey]);\n\n // Get addresses after import and find the newly added one\n const addressesAfter = await this.inner.getAccounts();\n\n // Find the new address by diffing the two sets\n const newAddresses = addressesAfter.filter(\n (addr) => !addressesBefore.has(addr),\n );\n\n if (newAddresses.length !== 1 || !newAddresses[0]) {\n throw new Error('Failed to import private key');\n }\n\n return newAddresses[0];\n });\n }\n\n async getAccounts(): Promise<KeyringAccount[]> {\n const addresses = await this.inner.getAccounts();\n\n return addresses.map((address) => {\n // Check if we already have this account in the registry\n const existingId = this.registry.getAccountId(address);\n if (existingId) {\n const cached = this.registry.get(existingId);\n if (cached) {\n return cached;\n }\n }\n\n // Create and register the account if not already cached\n return this.#createKeyringAccount(address);\n });\n }\n\n async createAccounts(\n options: CreateAccountOptions,\n ): Promise<KeyringAccount[]> {\n return this.withLock(async () => {\n // For SimpleKeyring, we only support private key import\n if (options.type !== 'private-key:import') {\n throw new Error(\n `Unsupported account creation type for SimpleKeyring: ${options.type}`,\n );\n }\n\n // Validate account type\n if (options.accountType !== EthAccountType.Eoa) {\n throw new Error(\n `Unsupported account type for SimpleKeyring: ${options.accountType}. Only '${EthAccountType.Eoa}' is supported.`,\n );\n }\n\n const { encoding, privateKey } = options;\n\n // Validate encoding\n if (encoding !== PrivateKeyEncoding.Hexadecimal) {\n throw new Error(\n `Unsupported encoding for SimpleKeyring: ${encoding}. Only '${PrivateKeyEncoding.Hexadecimal}' is supported.`,\n );\n }\n\n // Import the private key (with automatic rollback on failure)\n const newAddress = await this.#importPrivateKeyOrRollback(privateKey);\n\n // Create and return the new KeyringAccount\n const newAccount = this.#createKeyringAccount(newAddress);\n return [newAccount];\n });\n }\n\n /**\n * Delete an account from the keyring.\n *\n * @param accountId - The account ID to delete.\n */\n async deleteAccount(accountId: AccountId): Promise<void> {\n await this.withLock(async () => {\n const account = await this.getAccount(accountId);\n\n // Remove from the legacy keyring\n this.inner.removeAccount(account.address);\n\n // Remove from the registry\n this.registry.delete(accountId);\n });\n }\n\n /**\n * Export the private key for an account in hexadecimal format.\n *\n * @param accountId - The ID of the account to export.\n * @param options - Export options (only hexadecimal encoding is supported).\n * @returns The exported account with private key.\n */\n async exportAccount(\n accountId: AccountId,\n options?: ExportAccountOptions,\n ): Promise<ExportedAccount> {\n const account = await this.getAccount(accountId);\n\n const requestedEncoding =\n options?.encoding ?? PrivateKeyEncoding.Hexadecimal;\n\n if (requestedEncoding !== PrivateKeyEncoding.Hexadecimal) {\n throw new Error(\n `Unsupported encoding for SimpleKeyring: ${requestedEncoding}. Only '${PrivateKeyEncoding.Hexadecimal}' is supported.`,\n );\n }\n\n const privateKeyHex = await this.inner.exportAccount(\n this.toHexAddress(account.address),\n );\n // Sanitize private key format\n const privateKey = add0x(privateKeyHex);\n\n const exported: ExportedAccount = {\n type: 'private-key',\n privateKey,\n encoding: PrivateKeyEncoding.Hexadecimal,\n };\n\n return exported;\n }\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"simple-keyring-v2.d.cts","sourceRoot":"","sources":["../src/simple-keyring-v2.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,oBAAoB,EAIzB,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACpB,KAAK,cAAc,EAGnB,KAAK,SAAS,EAGf,8BAA8B;AAC/B,OAAO,EAAoB,iBAAiB,EAAE,8BAA8B;AAC5E,OAAO,KAAK,EAAE,SAAS,EAAE,gCAAgC;AAIzD,OAAO,KAAK,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AoB;QACpB,MAAM,uBAAA,IAAI,mEAAgB,MAApB,IAAI,EAAiB,mBAAmB,CAAC,CAAC;QAChD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED;;;;;;;GAOG;AACH,KAAK,sDAA6B,UAAkB;IAClD,OAAO,uBAAA,IAAI,iEAAc,MAAlB,IAAI,EAAe,KAAK,EAAE,kBAAkB,EAAE,EAAE;QACrD,sCAAsC;QACtC,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC;QAEhE,6BAA6B;QAC7B,MAAM,uBAAA,IAAI,mEAAgB,MAApB,IAAI,EAAiB,CAAC,GAAG,kBAAkB,EAAE,UAAU,CAAC,CAAC,CAAC;QAEhE,0DAA0D;QAC1D,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC;QAEtD,+CAA+C;QAC/C,MAAM,YAAY,GAAG,cAAc,CAAC,MAAM,CACxC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,CACrC,CAAC;QAEF,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC;YAClD,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;QAClD,CAAC;QAED,OAAO,YAAY,CAAC,CAAC,CAAC,CAAC;IACzB,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n type CreateAccountOptions,\n EthAccountType,\n EthMethod,\n EthScope,\n type ExportAccountOptions,\n type ExportedAccount,\n type KeyringAccount,\n KeyringAccountEntropyTypeOption,\n type KeyringCapabilities,\n type KeyringV2,\n KeyringType,\n PrivateKeyEncoding,\n} from '@metamask/keyring-api';\nimport { EthKeyringMethod, EthKeyringWrapper } from '@metamask/keyring-sdk';\nimport type { AccountId } from '@metamask/keyring-utils';\nimport { add0x, type Hex } from '@metamask/utils';\n\n// eslint-disable-next-line @typescript-eslint/naming-convention\nimport type SimpleKeyring from './simple-keyring';\n\n/**\n * Methods supported by SimpleKeyring EOA accounts.\n * SimpleKeyring supports all standard signing methods plus encryption and app keys.\n */\nconst SIMPLE_KEYRING_METHODS = [\n EthMethod.SignTransaction,\n EthMethod.Sign,\n EthMethod.PersonalSign,\n EthMethod.SignTypedDataV1,\n EthMethod.SignTypedDataV3,\n EthMethod.SignTypedDataV4,\n EthKeyringMethod.Decrypt,\n EthKeyringMethod.GetEncryptionPublicKey,\n EthKeyringMethod.GetAppKeyAddress,\n EthKeyringMethod.SignEip7702Authorization,\n];\n\nconst simpleKeyringV2Capabilities: KeyringCapabilities = {\n scopes: [EthScope.Eoa],\n privateKey: {\n importFormats: [\n { encoding: PrivateKeyEncoding.Hexadecimal, type: EthAccountType.Eoa },\n ],\n exportFormats: [{ encoding: PrivateKeyEncoding.Hexadecimal }],\n },\n};\n\n/**\n * Concrete {@link KeyringV2} adapter for {@link SimpleKeyring}.\n *\n * This wrapper exposes the accounts and signing capabilities of the legacy\n * SimpleKeyring via the unified V2 interface.\n */\nexport type SimpleKeyringV2Options = {\n legacyKeyring: SimpleKeyring;\n};\n\nexport class SimpleKeyringV2\n extends EthKeyringWrapper<SimpleKeyring>\n implements KeyringV2\n{\n constructor(options: SimpleKeyringV2Options) {\n super({\n type: KeyringType.PrivateKey,\n inner: options.legacyKeyring,\n capabilities: simpleKeyringV2Capabilities,\n });\n }\n\n /**\n * Creates a KeyringAccount object for the given address and index.\n *\n * @param address - The account address.\n * @returns The created KeyringAccount.\n */\n #createKeyringAccount(address: Hex): KeyringAccount {\n const id = this.registry.register(address);\n\n const account: KeyringAccount = {\n id,\n type: EthAccountType.Eoa,\n address,\n scopes: [...this.capabilities.scopes],\n methods: [...SIMPLE_KEYRING_METHODS],\n options: {\n entropy: {\n type: KeyringAccountEntropyTypeOption.PrivateKey,\n },\n exportable: true,\n },\n };\n\n // Add the account to the registry\n this.registry.set(account);\n\n return account;\n }\n\n /**\n * Get all private keys from the inner SimpleKeyring.\n *\n * @returns An array of private keys in hexadecimal format.\n */\n async #getPrivateKeys(): Promise<string[]> {\n return await this.inner.serialize();\n }\n\n /**\n * Set private keys in the inner SimpleKeyring.\n *\n * @param privateKeys - An array of private keys in hexadecimal format.\n */\n async #setPrivateKeys(privateKeys: string[]): Promise<void> {\n await this.inner.deserialize(privateKeys);\n }\n\n /**\n * Executes a transactional update on the inner keyring state.\n * If the callback throws, the state is automatically rolled back.\n *\n * @param callback - A function that receives the current private keys and performs the update.\n * Should return the result on success, or throw to trigger rollback.\n * @returns The result of the callback.\n * @throws Error if the callback throws (after rollback).\n */\n async #withRollback<Result>(\n callback: (currentPrivateKeys: string[]) => Promise<Result>,\n ): Promise<Result> {\n const originalPrivateKeys = await this.#getPrivateKeys();\n\n try {\n return await callback(originalPrivateKeys);\n } catch (error) {\n // Rollback on error\n await this.#setPrivateKeys(originalPrivateKeys);\n throw error;\n }\n }\n\n /**\n * Import a private key and return the new address.\n * If the import fails (no new address added), rolls back to the original state.\n *\n * @param privateKey - The private key to import in hexadecimal format.\n * @returns The address of the newly imported account.\n * @throws Error if the import fails or no new address is added.\n */\n async #importPrivateKeyOrRollback(privateKey: string): Promise<Hex> {\n return this.#withRollback(async (currentPrivateKeys) => {\n // Get current addresses before import\n const addressesBefore = new Set(await this.inner.getAccounts());\n\n // Import the new private key\n await this.#setPrivateKeys([...currentPrivateKeys, privateKey]);\n\n // Get addresses after import and find the newly added one\n const addressesAfter = await this.inner.getAccounts();\n\n // Find the new address by diffing the two sets\n const newAddresses = addressesAfter.filter(\n (addr) => !addressesBefore.has(addr),\n );\n\n if (newAddresses.length !== 1 || !newAddresses[0]) {\n throw new Error('Failed to import private key');\n }\n\n return newAddresses[0];\n });\n }\n\n async getAccounts(): Promise<KeyringAccount[]> {\n const addresses = await this.inner.getAccounts();\n\n return addresses.map((address) => {\n // Check if we already have this account in the registry\n const existingId = this.registry.getAccountId(address);\n if (existingId) {\n const cached = this.registry.get(existingId);\n if (cached) {\n return cached;\n }\n }\n\n // Create and register the account if not already cached\n return this.#createKeyringAccount(address);\n });\n }\n\n async createAccounts(\n options: CreateAccountOptions,\n ): Promise<KeyringAccount[]> {\n return this.withLock(async () => {\n // For SimpleKeyring, we only support private key import\n if (options.type !== 'private-key:import') {\n throw new Error(\n `Unsupported account creation type for SimpleKeyring: ${options.type}`,\n );\n }\n\n // Validate account type\n if (options.accountType !== EthAccountType.Eoa) {\n throw new Error(\n `Unsupported account type for SimpleKeyring: ${options.accountType}. Only '${EthAccountType.Eoa}' is supported.`,\n );\n }\n\n const { encoding, privateKey } = options;\n\n // Validate encoding\n if (encoding !== PrivateKeyEncoding.Hexadecimal) {\n throw new Error(\n `Unsupported encoding for SimpleKeyring: ${encoding}. Only '${PrivateKeyEncoding.Hexadecimal}' is supported.`,\n );\n }\n\n // Import the private key (with automatic rollback on failure)\n const newAddress = await this.#importPrivateKeyOrRollback(privateKey);\n\n // Create and return the new KeyringAccount\n const newAccount = this.#createKeyringAccount(newAddress);\n return [newAccount];\n });\n }\n\n /**\n * Delete an account from the keyring.\n *\n * @param accountId - The account ID to delete.\n */\n async deleteAccount(accountId: AccountId): Promise<void> {\n await this.withLock(async () => {\n const account = await this.getAccount(accountId);\n\n // Remove from the legacy keyring\n this.inner.removeAccount(account.address);\n\n // Remove from the registry\n this.registry.delete(accountId);\n });\n }\n\n /**\n * Export the private key for an account in hexadecimal format.\n *\n * @param accountId - The ID of the account to export.\n * @param options - Export options (only hexadecimal encoding is supported).\n * @returns The exported account with private key.\n */\n async exportAccount(\n accountId: AccountId,\n options?: ExportAccountOptions,\n ): Promise<ExportedAccount> {\n const account = await this.getAccount(accountId);\n\n const requestedEncoding =\n options?.encoding ?? PrivateKeyEncoding.Hexadecimal;\n\n if (requestedEncoding !== PrivateKeyEncoding.Hexadecimal) {\n throw new Error(\n `Unsupported encoding for SimpleKeyring: ${requestedEncoding}. Only '${PrivateKeyEncoding.Hexadecimal}' is supported.`,\n );\n }\n\n const privateKeyHex = await this.inner.exportAccount(\n this.toHexAddress(account.address),\n );\n // Sanitize private key format\n const privateKey = add0x(privateKeyHex);\n\n const exported: ExportedAccount = {\n type: 'private-key',\n privateKey,\n encoding: PrivateKeyEncoding.Hexadecimal,\n };\n\n return exported;\n }\n}\n"]}