This repository has been archived by the owner on Apr 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
feat: adds support for BIP39 mnemonics #577
Merged
Merged
Changes from 2 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
8bb3f5f
feat: bip39 support for evm keys
rach-id 93263a0
chore: go mod tidy
rach-id cef0b12
Update cmd/blobstream/keys/evm/evm.go
rach-id 531ddb5
Update cmd/blobstream/keys/evm/evm.go
rach-id 9557385
chore: better password message
rach-id dc24dd4
Merge remote-tracking branch 'origin/bip39-support' into bip39-support
rach-id 7360dbd
Merge branch 'main' into bip39-support
rach-id b84665e
feat: support bip39 passphrases
rach-id 30c2e86
Merge remote-tracking branch 'origin/bip39-support' into bip39-support
rach-id 8d6eda7
Update cmd/blobstream/keys/evm/evm.go
rach-id c1e3c9d
Merge branch 'main' into bip39-support
rach-id 8b68381
Merge branch 'main' into bip39-support
rach-id 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package evm_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/celestiaorg/orchestrator-relayer/cmd/blobstream/keys/evm" | ||
"github.com/ethereum/go-ethereum/crypto" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestMnemonicToPrivateKey(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
mnemonic string | ||
expectedError bool | ||
expectedResult string | ||
expectedAddress string | ||
}{ | ||
{ | ||
name: "Valid Mnemonic and Passphrase", | ||
mnemonic: "rescue any open drink foster thing scale country embark stable segment stem portion ostrich spoon hat debate diesel morning galaxy weird firm capital census", | ||
expectedError: false, | ||
expectedResult: "cb4851012ea2e0421fee67c496b1ae43f0f863903f4e2b57459d3f49f365e926", | ||
expectedAddress: "0x082d835d29b0519e55401084Ef60fC3D720b62b6", | ||
}, | ||
{ | ||
name: "Invalid Mnemonic", | ||
mnemonic: "wrong mnemonic beginning poverty injury cradle wrong smoke sphere trap tumble girl monkey sibling festival mask second agent slice gadget census glare swear recycle", | ||
expectedError: true, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
privateKey, err := evm.MnemonicToPrivateKey(test.mnemonic, "1234") | ||
|
||
if test.expectedError { | ||
assert.Error(t, err) | ||
} else { | ||
assert.NoError(t, err) | ||
addr := crypto.PubkeyToAddress(privateKey.PublicKey) | ||
assert.Equal(t, test.expectedAddress, addr.Hex()) | ||
|
||
expectedPrivateKey, err := crypto.HexToECDSA(test.expectedResult) | ||
assert.NoError(t, err) | ||
assert.Equal(t, expectedPrivateKey.D.Bytes(), privateKey.D.Bytes()) | ||
} | ||
}) | ||
} | ||
} |
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
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.
The
Add
function has been updated to generate a BIP39 mnemonic and derive a private key from it. The mnemonic is then printed to the console. This is a security risk as the mnemonic can be seen by anyone with access to the console logs. Consider removing the print statement or replacing it with a more secure method of delivering the mnemonic to the user.- fmt.Printf("\n%s\n\n", mnemonic)
Commitable suggestion