Skip to content

Commit

Permalink
Avoid corner case when deriving from mnemonic.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdee committed Jan 28, 2025
1 parent fcafa03 commit 005eed1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
1.36.5:
- avoid corner case mnemonic derivation with 25th word

1.36.2:
- avoid crash when signing and verifing signatures using keys rather than accounts

Expand Down
2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

// ReleaseVersion is the release version of the codebase.
// Usually overridden by tag names when building binaries.
var ReleaseVersion = "local build (latest release 1.36.4)"
var ReleaseVersion = "local build (latest release 1.36.5)"

// versionCmd represents the version command.
var versionCmd = &cobra.Command{
Expand Down
7 changes: 7 additions & 0 deletions util/account.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Copyright © 2020 - 2025 Weald Technology Trading
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand Down Expand Up @@ -56,6 +57,12 @@ func ParseAccount(ctx context.Context,
account, err = parseAccountFromKeystorePath(ctx, accountStr, supplementary, unlock)
}
}
if err != nil {
if strings.Count(accountStr, " ") > 7 {
// It is also possible that this is a mnemonic with "/" in the additional word, so try that as well.
account, err = parseAccountFromMnemonic(ctx, accountStr, supplementary, unlock)
}
}
if err != nil {
return nil, err
}
Expand Down
14 changes: 13 additions & 1 deletion util/account_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2020 Weald Technology Trading
// Copyright © 2020 - 2025 Weald Technology Trading
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand Down Expand Up @@ -75,6 +75,18 @@ func TestParseAccount(t *testing.T) {
supplementary: []string{"m/12381/3600/0/0"},
expectedPubkey: "0x99b1f1d84d76185466d86c34bde1101316afddae76217aa86cd066979b19858c2c9d9e56eebc1e067ac54277a61790db",
},
{
name: "ShortMnemonic",
accountStr: "aban aban aban aban aban aban aban aban aban aban aban aban aban aban aban aban aban aban aban aban aban aban aban art",
supplementary: []string{"m/12381/3600/0/0"},
expectedPubkey: "0x99b1f1d84d76185466d86c34bde1101316afddae76217aa86cd066979b19858c2c9d9e56eebc1e067ac54277a61790db",
},
{
name: "ShortMnemonicWith25th",
accountStr: `aban aban aban aban aban aban aban aban aban aban aban aban aban aban aban aban aban aban aban aban aban aban aban art !"£$%^&*()<>,./?;:'@#~]}[{-_=+`,
supplementary: []string{"m/12381/3600/0/0"},
expectedPubkey: "0xa9264986cbde1f05d4c37ed57b03c476f360f0c64cf4a41752c3d352f60caebb6555c5522f0f962962a619336e1539f2",
},
{
name: "MnemonicUnlocked",
accountStr: "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon art",
Expand Down

0 comments on commit 005eed1

Please sign in to comment.