Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/keyring-api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/keyring-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -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 }),
);
});
});
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -14,7 +14,7 @@ export const PrivateKeyExportedAccountStruct = object({
/**
* The private key of the exported account.
*/
privateKey: string(),
privateKey: sensitive(string()),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it's marked as sensitive AND that we use our object struct, this field will never be display in validation/error messages from superstruct.

/**
* The encoding of the exported private key.
*/
Expand Down
1 change: 1 addition & 0 deletions packages/keyring-eth-hd/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
2 changes: 1 addition & 1 deletion packages/keyring-eth-hd/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
1 change: 1 addition & 0 deletions packages/keyring-eth-money/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
2 changes: 1 addition & 1 deletion packages/keyring-eth-money/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
1 change: 1 addition & 0 deletions packages/keyring-internal-api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
2 changes: 1 addition & 1 deletion packages/keyring-internal-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions packages/keyring-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
2 changes: 1 addition & 1 deletion packages/keyring-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions packages/keyring-snap-bridge/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/keyring-snap-bridge/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions packages/keyring-snap-client/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/keyring-snap-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions packages/keyring-snap-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/keyring-snap-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
4 changes: 4 additions & 0 deletions packages/keyring-utils/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion packages/keyring-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
26 changes: 13 additions & 13 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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

Expand Down
Loading