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

fix(lib/crypto/ed25519): update ed25519 to use go-schnorrkel bip39 derivation #1488

Merged
merged 4 commits into from
Mar 24, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 5 additions & 2 deletions lib/crypto/ed25519/ed25519.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/ChainSafe/gossamer/lib/common"
"github.com/ChainSafe/gossamer/lib/crypto"

bip39 "github.com/cosmos/go-bip39"
"github.com/ChainSafe/go-schnorrkel"
)

// PublicKeyLength is the fixed Public Key Length
Expand Down Expand Up @@ -120,7 +120,10 @@ func NewKeypairFromPrivateKeyString(in string) (*Keypair, error) {

// NewKeypairFromMnenomic returns a new Keypair using the given mnemonic and password.
func NewKeypairFromMnenomic(mnemonic, password string) (*Keypair, error) {
seed := bip39.NewSeed(mnemonic, password)
seed, err := schnorrkel.SeedFromMnemonic(mnemonic, password)
if err != nil {
return nil, err
}
return NewKeypairFromSeed(seed[:32])
}

Expand Down
11 changes: 11 additions & 0 deletions lib/crypto/ed25519/ed25519_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"reflect"
"testing"

"github.com/ChainSafe/gossamer/lib/common"

bip39 "github.com/cosmos/go-bip39"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -101,3 +103,12 @@ func TestNewKeypairFromMnenomic(t *testing.T) {
_, err = NewKeypairFromMnenomic(mnemonic, "")
require.NoError(t, err)
}

func TestNewKeypairFromMnenomic_Again(t *testing.T) {
mnemonic := "twist sausage october vivid neglect swear crumble hawk beauty fabric egg fragile"
kp, err := NewKeypairFromMnenomic(mnemonic, "")
require.NoError(t, err)

expectedPubkey := common.MustHexToBytes("0xf56d9231e7b7badd3f1e10ad15ef8aa08b70839723d0a2d10d7329f0ea2b8c61")
require.Equal(t, expectedPubkey, kp.Public().Encode())
}