-
Notifications
You must be signed in to change notification settings - Fork 393
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
Use JSON onboarding in e2e tests of transactions #3559
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f13d2da
Use JSON onboarding in e2e tests of transactions
michalinacienciala 513bce5
Merge remote-tracking branch 'origin/main' into json-import-in-e2e
michalinacienciala 24b20bc
Run `yarn install` in the `scripts/key-generation` folder before linting
michalinacienciala 4a59635
Change name of the variables storing JSON body & password
michalinacienciala 2229425
Uncomment code sending transaction
michalinacienciala 3e22845
Add quotes to the command generating JSON in README
michalinacienciala 1cce0db
Add a comment explaining use of `eslint-disable`
michalinacienciala c3f274c
Update names of the JSON-related variables and secrets
michalinacienciala 4693c0f
Merge branch 'main' into json-import-in-e2e
Shadowfiend faa9b99
Give dev fork builds the -fork suffix
Shadowfiend 60f56b5
Merge remote-tracking branch 'origin/main' into json-import-in-e2e
michalinacienciala 6a1cc7f
Merge branch 'main' into json-import-in-e2e
Shadowfiend File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# JSON keystore generation | ||
|
||
## What is a keystore file? | ||
|
||
A JSON keystore is a file format commonly used to securely store and manage | ||
cryptographic keys associated with cryptocurrency wallets. It provides a | ||
structured and standardized way to store the private key in a JSON format. | ||
|
||
Typically, a JSON keystore file contains the encrypted private key along with | ||
relevant metadata and parameters needed for key derivation and decryption. The | ||
metadata may include information such as the key derivation function used, | ||
encryption algorithm, initialization vector (IV), salt, and other necessary | ||
parameters. | ||
|
||
The private key is encrypted within the JSON keystore file using a user-defined | ||
password or passphrase. This encryption adds an extra layer of security, | ||
protecting the private key from unauthorized access. The encrypted private key | ||
can only be decrypted and accessed by providing the correct password or | ||
passphrase. | ||
|
||
When a user wants to use their crypto wallet, they can import the JSON keystore | ||
file into a wallet software or application that supports this file format (one | ||
of them being the Taho extension). The wallet software will prompt the user to | ||
enter their password or passphrase to decrypt the private key stored in the JSON | ||
file. Once the private key is decrypted, the wallet software can utilize it to | ||
sign transactions and perform other wallet-related operations. | ||
|
||
JSON keystore files are designed to be portable, allowing users to easily back | ||
up and transfer their private keys between different wallet applications or | ||
devices while maintaining a standardized format. However, it's crucial to | ||
protect the JSON keystore file and the associated password or passphrase since | ||
they provide access to the private key and, ultimately, control over the | ||
associated cryptocurrency funds. | ||
|
||
## Generating JSON keystore for a private key | ||
|
||
In order to produce a keystore file run: | ||
|
||
```sh | ||
$ yarn install # installs dependencies | ||
$ PRIVATE_KEY="<private key without the 0x prefix>" PASSWORD="<password>" yarn run generate # executes the script | ||
``` | ||
|
||
As a result a JSON keystore file encoding the provided private key with the | ||
provided password will be created in the current directory. | ||
|
||
## Credits | ||
|
||
The script was based on a solution suggested in | ||
[this comment](https://ethereum.stackexchange.com/a/55617). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Since this is a script we can’t use import yet. | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
const fs = require("fs") | ||
const wallet = require("ethereumjs-wallet").default | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the lint error below—we need to yarn install in the parent dir in the actions workflow. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added in 24b20bc, it helped, thanks! |
||
|
||
const pk = Buffer.from( | ||
process.env.PRIVATE_KEY, // should not contrain `0x` prefix | ||
"hex" | ||
) | ||
const account = wallet.fromPrivateKey(pk) | ||
const password = process.env.PASSWORD | ||
account.toV3(password).then((value) => { | ||
const address = account.getAddress().toString("hex") | ||
const file = `UTC--${new Date() | ||
.toISOString() | ||
.replace(/[:]/g, "-")}--${address}.json` | ||
fs.writeFileSync(file, JSON.stringify(value)) | ||
}) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decided to add a linter exception here, as I couldn't make the linter happy without braking the script (can't say confidently that this can't be done though...).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choice looks correct, just drop a note above it that since this is a script we can’t use import yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1cce0db