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

Hardhat-keystore #5654

Merged
merged 160 commits into from
Sep 10, 2024
Merged

Hardhat-keystore #5654

merged 160 commits into from
Sep 10, 2024

Conversation

ChristopherDedominici
Copy link
Contributor

@ChristopherDedominici ChristopherDedominici commented Aug 19, 2024

Task description

This PR implements the main logic for the the Hardhat keystore. The encryption part will be added in a separate PR.

The technical design doc can be found here.

Manual Testing

The keystore plugin has been added to the example project.

You can run the following command from there:

npx hardhat keystore set mykey
# Enter secret to store: ******
# Key "mykey" set

npx hardhat keystore list
# Keys:
# mykey

npx hardhat keystore get mykey
# secret

DEBUG=* npx hardhat keystore list # debug to see the path to your local keystore file

Implementation considerations

The plugin is modeled as:

  • keystore (in memory representation of key/value store)
  • keystore-file-loader (responsible for creating an in memory keystore, reading a keystore from file or writing a keystore to file)
  • user interactions (an abstraction putting the messages display to the user and the user input requests in one place)

The configuration variable hooks read from a keystore if present, and defer to the next config variable hook otherwise. The configuration variables cache the keystore between runs with shared state in the hook. The loader is shared, which itself has caching capabilities.

The tasks have no task level caching, the intention being to run as isolated tasks.

We are setting the process.exitCode within tasks where there is a failure (e.g. getting a non-existant key). This leads to some ugliness in tests were the process exit code has to be reset.

The file read from disk by the loader is validated with zod based on the format specified in the types file.

In CI environments a "empty" keystore plugin is returned from the ./index.ts file. It has not hooks or tasks, which effectively turns off the plugin in CI. A test has been added that asserts different results between local development and CI to test this case.

TODO

  • Look at coverage on configuration-variables.ts, are we missing a test or do we reconsider logic
  • Delete the key argument checks - they are done by the task manager
  • Switch the filepath test helper Hardhat plugin to use dynamic imports to avoid the error
  • Double check we aren't reading/writing to the global hardhat folder during test runs
  • Add Zod validation when loading the unencrypted file
  • Convert HardhatPlugin errors into Hardhat errors
  • Eliminate the keystore loader and keystore mocking in tests, replacing it with only integration tests and component level tests that mock UserInterruptions and FileManager interactions (@kanej)
  • revert the plugin to being inline
  • add a force flag on delete - it might need revist after we have more info on zero code exit
  • add debug entry in config.ts to show the keystore file path
  • Do we need to handle no zero exit codes from tasks - waiting for info - @ChristopherDedominici
  • disable the keystore in CI (@kanej)
  • look at cache (@kanej)
  • Move getConfigDir to hh-utils (@ChristopherDedominici) - depends on this PR
  • Update the CI check to be limited to config hook (@kanej)
  • Update comment on loader responsibilities (@kanej)
  • Ensure error rather than instance of (@ChristopherDedominici)
  • Cleanup validate password in setupPassword (@ChristopherDedominici)
  • Cleanup the user interactions abstractions and clarify interruptions usage (@kanej)

@ChristopherDedominici ChristopherDedominici added the v-next A Hardhat v3 development task label Aug 19, 2024
@ChristopherDedominici ChristopherDedominici self-assigned this Aug 19, 2024
Copy link

changeset-bot bot commented Aug 19, 2024

⚠️ No Changeset found

Latest commit: 3b7f03b

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

vercel bot commented Aug 19, 2024

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 Sep 10, 2024 7:58pm

…ndation/hardhat into features/keystore-first-version
The user interactions and user interruptions abstractions have been
replaced. There is now a static class of user messages (gathering the
messages in one place.

In each of the tasks, the messages are written to cli via console.log
(with a layer of indirection).
@@ -0,0 +1,53 @@
import { HardhatError } from "@ignored/hardhat-vnext-errors";

export async function requestSecretInput(
Copy link
Member

Choose a reason for hiding this comment

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

For a follow-up PR: I think we should move this to utils, we have similar things in a few places, including one implementation that uses enquirer.

@ChristopherDedominici ChristopherDedominici added this pull request to the merge queue Sep 10, 2024
Merged via the queue into v-next with commit 3982ce2 Sep 10, 2024
126 checks passed
@ChristopherDedominici ChristopherDedominici deleted the features/keystore-first-version branch September 10, 2024 20:18
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
Archived in project
Development

Successfully merging this pull request may close these issues.

hardhat-keystore
3 participants