From 005eed1360f71d352ff0f87c6487d327144efbf2 Mon Sep 17 00:00:00 2001 From: Jim McDonald Date: Tue, 28 Jan 2025 19:32:01 +0000 Subject: [PATCH] Avoid corner case when deriving from mnemonic. --- CHANGELOG.md | 3 +++ cmd/version.go | 2 +- util/account.go | 7 +++++++ util/account_test.go | 14 +++++++++++++- 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9278187..44f554b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/cmd/version.go b/cmd/version.go index de785fd..8262579 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -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{ diff --git a/util/account.go b/util/account.go index 68032b2..d0f10ea 100644 --- a/util/account.go +++ b/util/account.go @@ -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 @@ -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 } diff --git a/util/account_test.go b/util/account_test.go index d74e2b5..6b5cfd6 100644 --- a/util/account_test.go +++ b/util/account_test.go @@ -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 @@ -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",