diff --git a/packages/keyring-api/CHANGELOG.md b/packages/keyring-api/CHANGELOG.md index fd7ed981e..fbb94573c 100644 --- a/packages/keyring-api/CHANGELOG.md +++ b/packages/keyring-api/CHANGELOG.md @@ -11,6 +11,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add support for `base32` private key encoding in `exportAccount` ([#589](https://github.com/MetaMask/accounts/pull/589)) +### Changed + +- Use `sensitive` struct for `privateKey` in `PrivateKeyExportedAccountStruct` ([#577](https://github.com/MetaMask/accounts/pull/577)) + - This ensures the private key value is always redacted in case of validation errors. +- Bump `@metamask/superstruct` from `^3.3.0` to `^3.4.0` ([#577](https://github.com/MetaMask/accounts/pull/577)) + ## [23.5.0] ### Added diff --git a/packages/keyring-api/package.json b/packages/keyring-api/package.json index a5ef05625..bc5f4dab4 100644 --- a/packages/keyring-api/package.json +++ b/packages/keyring-api/package.json @@ -68,7 +68,7 @@ }, "dependencies": { "@metamask/keyring-utils": "^3.3.1", - "@metamask/superstruct": "^3.3.0", + "@metamask/superstruct": "^3.4.0", "@metamask/utils": "^11.11.0", "bitcoin-address-validation": "^2.2.3" }, diff --git a/packages/keyring-api/src/v2/api/export-account/private-key.test.ts b/packages/keyring-api/src/v2/api/export-account/private-key.test.ts new file mode 100644 index 000000000..ad1c6f536 --- /dev/null +++ b/packages/keyring-api/src/v2/api/export-account/private-key.test.ts @@ -0,0 +1,62 @@ +import type { StructError } from '@metamask/superstruct'; +import { assert } from '@metamask/superstruct'; + +import { PrivateKeyExportedAccountStruct } from './private-key'; + +const SENSITIVE_REDACTED = '***'; + +const RAW_PRIVATE_KEY = + '0xdeadbeef1234567890abcdef1234567890abcdef1234567890abcdef12345678'; + +describe('PrivateKeyExportedAccountStruct', () => { + it('accepts a valid exported account', () => { + expect(() => + assert( + { + type: 'private-key', + privateKey: RAW_PRIVATE_KEY, + encoding: 'hexadecimal', + }, + PrivateKeyExportedAccountStruct, + ), + ).not.toThrow(); + }); + + it('redacts the private key value from the error when `privateKey` is invalid', () => { + let error: StructError | undefined; + try { + assert( + { type: 'private-key', privateKey: 123, encoding: 'hexadecimal' }, + PrivateKeyExportedAccountStruct, + ); + } catch (caughtError) { + error = caughtError as StructError; + } + expect(error?.value).toBe(SENSITIVE_REDACTED); + expect(error?.message).toContain(SENSITIVE_REDACTED); + expect(error?.message).not.toContain('123'); + }); + + it('redacts the private key from `branch` when a sibling field fails', () => { + let error: StructError | undefined; + try { + assert( + { + type: 'private-key', + privateKey: RAW_PRIVATE_KEY, + encoding: 'invalid-encoding', + }, + PrivateKeyExportedAccountStruct, + ); + } catch (caughtError) { + error = caughtError as StructError; + } + expect(error?.message).toContain('encoding'); + const allBranchItems = (error?.failures() ?? []).flatMap( + (failure) => failure.branch, + ); + expect(allBranchItems).not.toContainEqual( + expect.objectContaining({ privateKey: RAW_PRIVATE_KEY }), + ); + }); +}); diff --git a/packages/keyring-api/src/v2/api/export-account/private-key.ts b/packages/keyring-api/src/v2/api/export-account/private-key.ts index 566820c73..517e96570 100644 --- a/packages/keyring-api/src/v2/api/export-account/private-key.ts +++ b/packages/keyring-api/src/v2/api/export-account/private-key.ts @@ -1,4 +1,4 @@ -import { literal, object, string } from '@metamask/superstruct'; +import { object, sensitive, literal, string } from '@metamask/superstruct'; import type { Infer } from '@metamask/superstruct'; import { PrivateKeyEncodingStruct } from '../private-key'; @@ -14,7 +14,7 @@ export const PrivateKeyExportedAccountStruct = object({ /** * The private key of the exported account. */ - privateKey: string(), + privateKey: sensitive(string()), /** * The encoding of the exported private key. */ diff --git a/packages/keyring-eth-hd/CHANGELOG.md b/packages/keyring-eth-hd/CHANGELOG.md index b1cb4d16b..5c65edb0c 100644 --- a/packages/keyring-eth-hd/CHANGELOG.md +++ b/packages/keyring-eth-hd/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Bump `@metamask/keyring-sdk` from `^2.0.2` to `^2.2.0` ([#544](https://github.com/MetaMask/accounts/pull/544), [#546](https://github.com/MetaMask/accounts/pull/546), [#562](https://github.com/MetaMask/accounts/pull/562)) - Bump `@metamask/keyring-utils` from `^3.2.0` to `^3.3.1` ([#544](https://github.com/MetaMask/accounts/pull/544), [#546](https://github.com/MetaMask/accounts/pull/546)) - Bump `@metamask/keyring-api` from `^23.1.0` to `^23.5.0` ([#562](https://github.com/MetaMask/accounts/pull/562), [#569](https://github.com/MetaMask/accounts/pull/569), [#583](https://github.com/MetaMask/accounts/pull/583), [#587](https://github.com/MetaMask/accounts/pull/587)) +- Bump `@metamask/superstruct` from `^3.3.0` to `^3.4.0` ([#577](https://github.com/MetaMask/accounts/pull/577)) ## [14.1.1] diff --git a/packages/keyring-eth-hd/package.json b/packages/keyring-eth-hd/package.json index 761aac147..5b934efb6 100644 --- a/packages/keyring-eth-hd/package.json +++ b/packages/keyring-eth-hd/package.json @@ -74,7 +74,7 @@ "@metamask/keyring-sdk": "^2.2.0", "@metamask/keyring-utils": "^3.3.1", "@metamask/scure-bip39": "^2.1.1", - "@metamask/superstruct": "^3.3.0", + "@metamask/superstruct": "^3.4.0", "@metamask/utils": "^11.11.0", "ethereum-cryptography": "^2.2.1" }, diff --git a/packages/keyring-eth-money/CHANGELOG.md b/packages/keyring-eth-money/CHANGELOG.md index 2e43e85fe..c9a96bdfe 100644 --- a/packages/keyring-eth-money/CHANGELOG.md +++ b/packages/keyring-eth-money/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Bump `@metamask/keyring-api` from `^23.1.0` to `^23.5.0` ([#562](https://github.com/MetaMask/accounts/pull/562), [#569](https://github.com/MetaMask/accounts/pull/569), [#583](https://github.com/MetaMask/accounts/pull/583), [#587](https://github.com/MetaMask/accounts/pull/587)) - Bump `@metamask/keyring-sdk` from `^2.1.1` to `^2.2.0` ([#562](https://github.com/MetaMask/accounts/pull/562)) +- Bump `@metamask/superstruct` from `^3.3.0` to `^3.4.0` ([#577](https://github.com/MetaMask/accounts/pull/577)) ## [3.0.0] diff --git a/packages/keyring-eth-money/package.json b/packages/keyring-eth-money/package.json index f71638ec5..db78510db 100644 --- a/packages/keyring-eth-money/package.json +++ b/packages/keyring-eth-money/package.json @@ -70,7 +70,7 @@ "@metamask/keyring-api": "^23.5.0", "@metamask/keyring-sdk": "^2.2.0", "@metamask/keyring-utils": "^3.3.1", - "@metamask/superstruct": "^3.3.0", + "@metamask/superstruct": "^3.4.0", "async-mutex": "^0.5.0" }, "devDependencies": { diff --git a/packages/keyring-internal-api/CHANGELOG.md b/packages/keyring-internal-api/CHANGELOG.md index ea4ff0eb7..8ec8c9f00 100644 --- a/packages/keyring-internal-api/CHANGELOG.md +++ b/packages/keyring-internal-api/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Bump `@metamask/keyring-utils` from `^3.2.0` to `^3.3.1` ([#544](https://github.com/MetaMask/accounts/pull/544), [#546](https://github.com/MetaMask/accounts/pull/546)) - Bump `@metamask/keyring-api` from `^23.1.0` to `^23.5.0` ([#562](https://github.com/MetaMask/accounts/pull/562), [#569](https://github.com/MetaMask/accounts/pull/569), [#583](https://github.com/MetaMask/accounts/pull/583), [#587](https://github.com/MetaMask/accounts/pull/587)) +- Bump `@metamask/superstruct` from `^3.3.0` to `^3.4.0` ([#577](https://github.com/MetaMask/accounts/pull/577)) ## [11.0.1] diff --git a/packages/keyring-internal-api/package.json b/packages/keyring-internal-api/package.json index fda7bbd2d..d1758c278 100644 --- a/packages/keyring-internal-api/package.json +++ b/packages/keyring-internal-api/package.json @@ -57,7 +57,7 @@ "dependencies": { "@metamask/keyring-api": "^23.5.0", "@metamask/keyring-utils": "^3.3.1", - "@metamask/superstruct": "^3.3.0" + "@metamask/superstruct": "^3.4.0" }, "devDependencies": { "@lavamoat/allow-scripts": "^3.2.1", diff --git a/packages/keyring-sdk/CHANGELOG.md b/packages/keyring-sdk/CHANGELOG.md index db2ca5e13..c1c02ef98 100644 --- a/packages/keyring-sdk/CHANGELOG.md +++ b/packages/keyring-sdk/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Bump `@metamask/keyring-api` from `^23.2.0` to `^23.5.0` ([#569](https://github.com/MetaMask/accounts/pull/569), [#583](https://github.com/MetaMask/accounts/pull/583), [#587](https://github.com/MetaMask/accounts/pull/587)) +- Bump `@metamask/superstruct` from `^3.3.0` to `^3.4.0` ([#577](https://github.com/MetaMask/accounts/pull/577)) ## [2.2.0] diff --git a/packages/keyring-sdk/package.json b/packages/keyring-sdk/package.json index 5f914e599..13ccd8bda 100644 --- a/packages/keyring-sdk/package.json +++ b/packages/keyring-sdk/package.json @@ -71,7 +71,7 @@ "@metamask/keyring-api": "^23.5.0", "@metamask/keyring-utils": "^3.3.1", "@metamask/scure-bip39": "^2.1.1", - "@metamask/superstruct": "^3.3.0", + "@metamask/superstruct": "^3.4.0", "@metamask/utils": "^11.11.0", "async-mutex": "^0.5.0", "ethereum-cryptography": "^2.2.1", diff --git a/packages/keyring-snap-bridge/CHANGELOG.md b/packages/keyring-snap-bridge/CHANGELOG.md index a73486aea..a58fd1fce 100644 --- a/packages/keyring-snap-bridge/CHANGELOG.md +++ b/packages/keyring-snap-bridge/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- Bump `@metamask/superstruct` from `^3.3.0` to `^3.4.0` ([#577](https://github.com/MetaMask/accounts/pull/577)) + ## [23.0.1] ### Fixed diff --git a/packages/keyring-snap-bridge/package.json b/packages/keyring-snap-bridge/package.json index 2ad6b42b3..a070d9dfa 100644 --- a/packages/keyring-snap-bridge/package.json +++ b/packages/keyring-snap-bridge/package.json @@ -78,7 +78,7 @@ "@metamask/snaps-controllers": "^19.0.1", "@metamask/snaps-sdk": "^11.0.0", "@metamask/snaps-utils": "^12.2.1", - "@metamask/superstruct": "^3.3.0", + "@metamask/superstruct": "^3.4.0", "@metamask/utils": "^11.11.0", "@types/uuid": "^9.0.8", "async-mutex": "^0.5.0", diff --git a/packages/keyring-snap-client/CHANGELOG.md b/packages/keyring-snap-client/CHANGELOG.md index fb1ac9de2..1639df06e 100644 --- a/packages/keyring-snap-client/CHANGELOG.md +++ b/packages/keyring-snap-client/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- Bump `@metamask/superstruct` from `^3.3.0` to `^3.4.0` ([#577](https://github.com/MetaMask/accounts/pull/577)) + ## [9.2.0] ### Added diff --git a/packages/keyring-snap-client/package.json b/packages/keyring-snap-client/package.json index 50bd4f13e..9d8a9e690 100644 --- a/packages/keyring-snap-client/package.json +++ b/packages/keyring-snap-client/package.json @@ -68,7 +68,7 @@ "dependencies": { "@metamask/keyring-api": "^23.5.0", "@metamask/keyring-utils": "^3.3.1", - "@metamask/superstruct": "^3.3.0", + "@metamask/superstruct": "^3.4.0", "@types/uuid": "^9.0.8", "uuid": "^9.0.1", "webextension-polyfill": "^0.12.0" diff --git a/packages/keyring-snap-sdk/CHANGELOG.md b/packages/keyring-snap-sdk/CHANGELOG.md index 9868a3de9..0c03c9a73 100644 --- a/packages/keyring-snap-sdk/CHANGELOG.md +++ b/packages/keyring-snap-sdk/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- Bump `@metamask/superstruct` from `^3.3.0` to `^3.4.0` ([#577](https://github.com/MetaMask/accounts/pull/577)) + ## [9.2.0] ### Added diff --git a/packages/keyring-snap-sdk/package.json b/packages/keyring-snap-sdk/package.json index 5b2a1d8a3..93d999a50 100644 --- a/packages/keyring-snap-sdk/package.json +++ b/packages/keyring-snap-sdk/package.json @@ -68,7 +68,7 @@ "dependencies": { "@metamask/keyring-utils": "^3.3.1", "@metamask/snaps-sdk": "^11.0.0", - "@metamask/superstruct": "^3.3.0", + "@metamask/superstruct": "^3.4.0", "@metamask/utils": "^11.11.0", "webextension-polyfill": "^0.12.0" }, diff --git a/packages/keyring-utils/CHANGELOG.md b/packages/keyring-utils/CHANGELOG.md index 66269dfd8..967f3be8d 100644 --- a/packages/keyring-utils/CHANGELOG.md +++ b/packages/keyring-utils/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- Bump `@metamask/superstruct` from `^3.3.0` to `^3.4.0` ([#577](https://github.com/MetaMask/accounts/pull/577)) + ### Removed - **BREAKING:** Removed `object`, `type` and `exactOptional` superstruct support ([#580](https://github.com/MetaMask/accounts/pull/580)) diff --git a/packages/keyring-utils/package.json b/packages/keyring-utils/package.json index c8e01cdf4..2a2bc7a3f 100644 --- a/packages/keyring-utils/package.json +++ b/packages/keyring-utils/package.json @@ -56,7 +56,7 @@ }, "dependencies": { "@ethereumjs/tx": "^5.4.0", - "@metamask/superstruct": "^3.3.0", + "@metamask/superstruct": "^3.4.0", "@metamask/utils": "^11.11.0", "bitcoin-address-validation": "^2.2.3" }, diff --git a/yarn.lock b/yarn.lock index ea6615f70..cb60bb4f4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1905,7 +1905,7 @@ __metadata: "@metamask/keyring-utils": "npm:^3.3.1" "@metamask/old-hd-keyring": "npm:@metamask/eth-hd-keyring@^4.0.1" "@metamask/scure-bip39": "npm:^2.1.1" - "@metamask/superstruct": "npm:^3.3.0" + "@metamask/superstruct": "npm:^3.4.0" "@metamask/utils": "npm:^11.11.0" "@ts-bridge/cli": "npm:^0.6.3" "@types/jest": "npm:^29.5.12" @@ -1976,7 +1976,7 @@ __metadata: "@metamask/keyring-api": "npm:^23.5.0" "@metamask/keyring-sdk": "npm:^2.2.0" "@metamask/keyring-utils": "npm:^3.3.1" - "@metamask/superstruct": "npm:^3.3.0" + "@metamask/superstruct": "npm:^3.4.0" "@metamask/utils": "npm:^11.11.0" "@ts-bridge/cli": "npm:^0.6.3" "@types/jest": "npm:^29.5.12" @@ -2111,7 +2111,7 @@ __metadata: "@metamask/snaps-controllers": "npm:^19.0.1" "@metamask/snaps-sdk": "npm:^11.0.0" "@metamask/snaps-utils": "npm:^12.2.1" - "@metamask/superstruct": "npm:^3.3.0" + "@metamask/superstruct": "npm:^3.4.0" "@metamask/utils": "npm:^11.11.0" "@ts-bridge/cli": "npm:^0.6.3" "@types/jest": "npm:^29.5.12" @@ -2258,7 +2258,7 @@ __metadata: "@lavamoat/preinstall-always-fail": "npm:^2.1.0" "@metamask/auto-changelog": "npm:^6.1.0" "@metamask/keyring-utils": "npm:^3.3.1" - "@metamask/superstruct": "npm:^3.3.0" + "@metamask/superstruct": "npm:^3.4.0" "@metamask/utils": "npm:^11.11.0" "@ts-bridge/cli": "npm:^0.6.3" "@types/jest": "npm:^29.5.12" @@ -2286,7 +2286,7 @@ __metadata: "@metamask/auto-changelog": "npm:^6.1.0" "@metamask/keyring-api": "npm:^23.5.0" "@metamask/keyring-utils": "npm:^3.3.1" - "@metamask/superstruct": "npm:^3.3.0" + "@metamask/superstruct": "npm:^3.4.0" "@ts-bridge/cli": "npm:^0.6.3" "@types/jest": "npm:^29.5.12" "@types/node": "npm:^20.12.12" @@ -2347,7 +2347,7 @@ __metadata: "@metamask/keyring-api": "npm:^23.5.0" "@metamask/keyring-utils": "npm:^3.3.1" "@metamask/scure-bip39": "npm:^2.1.1" - "@metamask/superstruct": "npm:^3.3.0" + "@metamask/superstruct": "npm:^3.4.0" "@metamask/utils": "npm:^11.11.0" "@ts-bridge/cli": "npm:^0.6.3" "@types/jest": "npm:^29.5.12" @@ -2379,7 +2379,7 @@ __metadata: "@metamask/keyring-api": "npm:^23.5.0" "@metamask/keyring-utils": "npm:^3.3.1" "@metamask/providers": "npm:^19.0.0" - "@metamask/superstruct": "npm:^3.3.0" + "@metamask/superstruct": "npm:^3.4.0" "@metamask/utils": "npm:^11.11.0" "@ts-bridge/cli": "npm:^0.6.3" "@types/jest": "npm:^29.5.12" @@ -2413,7 +2413,7 @@ __metadata: "@metamask/keyring-utils": "npm:^3.3.1" "@metamask/providers": "npm:^19.0.0" "@metamask/snaps-sdk": "npm:^11.0.0" - "@metamask/superstruct": "npm:^3.3.0" + "@metamask/superstruct": "npm:^3.4.0" "@metamask/utils": "npm:^11.11.0" "@ts-bridge/cli": "npm:^0.6.3" "@types/jest": "npm:^29.5.12" @@ -2443,7 +2443,7 @@ __metadata: "@lavamoat/allow-scripts": "npm:^3.2.1" "@lavamoat/preinstall-always-fail": "npm:^2.1.0" "@metamask/auto-changelog": "npm:^6.1.0" - "@metamask/superstruct": "npm:^3.3.0" + "@metamask/superstruct": "npm:^3.4.0" "@metamask/utils": "npm:^11.11.0" "@ts-bridge/cli": "npm:^0.6.3" "@types/jest": "npm:^29.5.12" @@ -2770,10 +2770,10 @@ __metadata: languageName: node linkType: hard -"@metamask/superstruct@npm:^3.1.0, @metamask/superstruct@npm:^3.2.1, @metamask/superstruct@npm:^3.3.0": - version: 3.3.0 - resolution: "@metamask/superstruct@npm:3.3.0" - checksum: 10/664d5e330484a86420bc004b1c7f8301e1501cce712f611fe657176b2979edbd7cc6f4c77c8b1610486a685ebbd0b72dacf4bd6cf143d6b52038069d2f4e84ab +"@metamask/superstruct@npm:^3.1.0, @metamask/superstruct@npm:^3.2.1, @metamask/superstruct@npm:^3.4.0": + version: 3.4.0 + resolution: "@metamask/superstruct@npm:3.4.0" + checksum: 10/915a6c10019631855368c75c4295a48ece7891cd6e1ab67ed65070142ef24ab019b12d6a71aff7a747a7d5273f64f61fcc42cded4def5d7519ed8441f12884a0 languageName: node linkType: hard