Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encrypted keystore #6232

Open
wants to merge 14 commits into
base: v-next
Choose a base branch
from
Open

Encrypted keystore #6232

wants to merge 14 commits into from

Conversation

ChristopherDedominici
Copy link
Contributor

@ChristopherDedominici ChristopherDedominici commented Feb 6, 2025

For a list of follow-up tasks related to user experience improvements (not security improvements), see the parent issue here

QUESTIONS:

  • user inputs are handled via requestSecretInput from hre.interruptions, but outputs are not currently managed by hre.interruptions. I believe they should be. Should we address this in this PR, or should I add it to the follow-up tasks?

Copy link

vercel bot commented Feb 6, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
hardhat ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 11, 2025 3:26pm

Copy link

changeset-bot bot commented Feb 6, 2025

⚠️ No Changeset found

Latest commit: e2f9b77

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

github-actions bot commented Feb 6, 2025

hardhat

Total size of the bundle: 213M
Total number of dependencies (including transitive): 54

List of dependencies (sorted by size)
208M	total
29M	@ignored/edr-optimism-linux-x64-musl
29M	@ignored/edr-optimism-linux-x64-gnu
26M	@ignored/edr-optimism-linux-arm64-musl
26M	@ignored/edr-optimism-linux-arm64-gnu
22M	@ignored/edr-optimism-win32-x64-msvc
20M	esbuild
20M	@ignored/edr-optimism-darwin-x64
19M	@ignored/edr-optimism-darwin-arm64
2.8M	@sentry/tracing
2.5M	micro-eth-signer
1.9M	@noble/curves
1.7M	undici
1.2M	@sentry/types
1.2M	@noble/hashes
932K	@sentry/node
920K	@sentry/utils
856K	zod
844K	@ignored/hardhat-vnext-utils
624K	micro-packed
576K	tsx
548K	@sentry/core
544K	fast-equals
492K	@scure/bip39
368K	ethereum-cryptography
344K	@sentry/hub
336K	@ignored/edr
324K	@ignored/hardhat-vnext-errors
320K	enquirer
288K	semver
264K	@ignored/edr-optimism
192K	ws
168K	@scure/base
136K	get-tsconfig
136K	adm-zip
96K	@scure/bip32
92K	chalk
88K	tslib
88K	@sentry/minimal
76K	agent-base
72K	@nomicfoundation/solidity-analyzer
68K	debug
64K	lru_map
64K	https-proxy-agent
60K	@ignored/hardhat-vnext-zod-utils
56K	rfdc
48K	ansi-colors
44K	resolve.exports
40K	resolve-pkg-maps
36K	p-map
32K	cookie
24K	strip-ansi
24K	env-paths
24K	ansi-regex
20K	ms

@kanej kanej linked an issue Feb 10, 2025 that may be closed by this pull request
2 tasks
@@ -706,25 +706,12 @@ Try using another mnemonic or deriving less keys.`,
},
},
KEYSTORE: {
INVALID_KEYSTORE_FILE_FORMAT: {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed because it is no longer needed, as user input is now handled via the requestSecretInput hook.

@@ -39,7 +41,16 @@ export default async (): Promise<Partial<ConfigurationVariableHooks>> => {
return next(context, variable);
}

return keystore.readValue(variable.name);
const password = await askPassword(
context.interruptions.requestSecretInput.bind(context.interruptions),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

bind is needed because requestSecretInput is a method of hre.interruptions, and when passed as an argument, it loses its original this context. Since method calls rely on the object reference for this, passing it as a standalone function removes that association. To ensure it retains the correct context, we need to explicitly bind this using .bind(hre.interruptions).

This approach will be used also later in other files

password: string;
salt: Uint8Array;
}): Uint8Array {
password = password.normalize(PASSWORD_NORMALIZATION_FORM);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I need a double check that the normalization is only required here

@@ -0,0 +1,630 @@
import { siv } from "@noble/ciphers/aes";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need a decision on this comment

return this.#keystoreData;
}

public async listKeys(): Promise<string[]> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

When listing the keys, HMAC file validation is not performed. Is this acceptable, or do we want to validate it? If we choose to validate, we will need to request the password. I suggest keeping it as is, without validation.

) => Promise<string>,
consoleLog: (text: string) => void = console.log,
): Promise<string> {
const PASSWORD_REGEX = /^.{8,}$/;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently, we only require a minimum of 8 characters. Do we want to introduce additional rules?

): Promise<string> {
const PASSWORD_REGEX = /^.{8,}$/;

consoleLog(UserDisplayMessages.keystoreBannerMessage());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

How it currently looks like:
image

}

let confirmPassword: string | undefined;
while (confirmPassword === undefined) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This loop will continue indefinitely until the confirmation password matches the original password.
This check ensures that the user saves the correct password, preventing spelling mistakes.

@@ -43,23 +34,28 @@ export class KeystoreFileLoader implements KeystoreLoader {
this.#keystoreFilePath,
);

this.#throwIfInvalidKeystoreFormat(keystoreFile);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The keystore validation file has been removed since HMAC validation now handles the validation process.

@ChristopherDedominici ChristopherDedominici marked this pull request as ready for review February 11, 2025 15:15
@ChristopherDedominici ChristopherDedominici added the v-next A Hardhat v3 development task label Feb 11, 2025
@ChristopherDedominici ChristopherDedominici added this to the Public Alpha milestone Feb 11, 2025
});
});

describe("password normalization", () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added this additional test to validate that the normalization is working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no changeset needed This PR doesn't require a changeset v-next A Hardhat v3 development task
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

encrypted keystore
3 participants