diff --git a/pkg/wallet/account.go b/pkg/wallet/account.go index c3a0ba098..ef426c08e 100644 --- a/pkg/wallet/account.go +++ b/pkg/wallet/account.go @@ -1,7 +1,6 @@ package wallet import ( - "bytes" "errors" "fmt" @@ -21,9 +20,6 @@ type Account struct { // NEO private key. privateKey *keys.PrivateKey - // NEO public key. - publicKey []byte - // NEO public address. Address string `json:"address"` @@ -160,8 +156,6 @@ func (a *Account) Decrypt(passphrase string, scrypt keys.ScryptParams) error { return err } - a.publicKey = a.privateKey.PublicKey().Bytes() - return nil } @@ -208,9 +202,13 @@ func (a *Account) ConvertMultisig(m int, pubs []*keys.PublicKey) error { if a.Locked { return errors.New("account is locked") } + if a.privateKey == nil { + return errors.New("account key is not available (need to decrypt?)") + } var found bool + accKey := a.privateKey.PublicKey() for i := range pubs { - if bytes.Equal(a.publicKey, pubs[i].Bytes()) { + if accKey.Equal(pubs[i]) { found = true break } @@ -240,7 +238,6 @@ func NewAccountFromPrivateKey(p *keys.PrivateKey) *Account { pubAddr := p.Address() a := &Account{ - publicKey: pubKey.Bytes(), privateKey: p, Address: pubAddr, Contract: &Contract{ diff --git a/pkg/wallet/account_test.go b/pkg/wallet/account_test.go index 841201edb..f424f779c 100644 --- a/pkg/wallet/account_test.go +++ b/pkg/wallet/account_test.go @@ -185,6 +185,13 @@ func TestAccount_ConvertMultisig(t *testing.T) { require.Error(t, a.ConvertMultisig(1, pubs)) a.Locked = false }) + t.Run("no private key", func(t *testing.T) { + pk := a.privateKey + a.privateKey = nil + pubs := convertPubs(t, hexs) + require.Error(t, a.ConvertMultisig(0, pubs)) + a.privateKey = pk + }) t.Run("invalid number of signatures", func(t *testing.T) { pubs := convertPubs(t, hexs) require.Error(t, a.ConvertMultisig(0, pubs)) @@ -223,7 +230,7 @@ func compareFields(t *testing.T, tk keytestcases.Ktype, acc *Account) { require.Equalf(t, want, have, "expected address %s got %s", want, have) want, have = tk.Wif, acc.privateKey.WIF() require.Equalf(t, want, have, "expected wif %s got %s", want, have) - want, have = tk.PublicKey, hex.EncodeToString(acc.publicKey) + want, have = tk.PublicKey, hex.EncodeToString(acc.privateKey.PublicKey().Bytes()) require.Equalf(t, want, have, "expected pub key %s got %s", want, have) want, have = tk.PrivateKey, acc.privateKey.String() require.Equalf(t, want, have, "expected priv key %s got %s", want, have) diff --git a/pkg/wallet/wallet_test.go b/pkg/wallet/wallet_test.go index 42d078663..98f940cd6 100644 --- a/pkg/wallet/wallet_test.go +++ b/pkg/wallet/wallet_test.go @@ -48,7 +48,6 @@ func TestAddAccount(t *testing.T) { wallet.AddAccount(&Account{ privateKey: nil, - publicKey: nil, Address: "real", EncryptedWIF: "", Label: "", @@ -77,7 +76,6 @@ func TestSave(t *testing.T) { wallet.AddAccount(&Account{ privateKey: nil, - publicKey: nil, Address: "", EncryptedWIF: "", Label: "",