Skip to content

Commit

Permalink
check whether account number is a valid base58 string
Browse files Browse the repository at this point in the history
  • Loading branch information
nodestory committed Oct 15, 2019
1 parent f075de2 commit 3b0b981
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions account/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,9 @@ func Verify(accountNumber string, message, signature []byte) error {

func extractAuthPublicKey(accountNumber string) (publicKey []byte, err error) {
accountNumberBytes := encoding.FromBase58(accountNumber)
if len(accountNumberBytes) == 0 {
return nil, errors.New("invalid base58 string")
}

variantAndPubkey := accountNumberBytes[:len(accountNumberBytes)-ChecksumLength]
computedChecksum := sha3.Sum256(variantAndPubkey)
Expand Down
3 changes: 3 additions & 0 deletions account/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,9 @@ func TestValidateAccountNumber(t *testing.T) {

err = ValidateAccountNumber(livenetDeprecatedAccount.accountNumber)
assert.NoError(t, err)

err = ValidateAccountNumber("IOl")
assert.Error(t, err, "invalid base58 string")
}

func TestRecoverV1Account(t *testing.T) {
Expand Down

0 comments on commit 3b0b981

Please sign in to comment.