wallet: don't permanently store wif in the Account

It's useless and it's just another copy of the key. If really needed, it can
be derived from the key.
This commit is contained in:
Roman Khimov 2022-09-01 15:27:38 +03:00
parent 20224cb39c
commit 0090577446
3 changed files with 1 additions and 9 deletions

View file

@ -24,9 +24,6 @@ type Account struct {
// NEO public key. // NEO public key.
publicKey []byte publicKey []byte
// Account import file.
wif string
// NEO public address. // NEO public address.
Address string `json:"address"` Address string `json:"address"`
@ -164,7 +161,6 @@ func (a *Account) Decrypt(passphrase string, scrypt keys.ScryptParams) error {
} }
a.publicKey = a.privateKey.PublicKey().Bytes() a.publicKey = a.privateKey.PublicKey().Bytes()
a.wif = a.privateKey.WIF()
return nil return nil
} }
@ -239,13 +235,11 @@ func (a *Account) ConvertMultisig(m int, pubs []*keys.PublicKey) error {
func NewAccountFromPrivateKey(p *keys.PrivateKey) *Account { func NewAccountFromPrivateKey(p *keys.PrivateKey) *Account {
pubKey := p.PublicKey() pubKey := p.PublicKey()
pubAddr := p.Address() pubAddr := p.Address()
wif := p.WIF()
a := &Account{ a := &Account{
publicKey: pubKey.Bytes(), publicKey: pubKey.Bytes(),
privateKey: p, privateKey: p,
Address: pubAddr, Address: pubAddr,
wif: wif,
Contract: &Contract{ Contract: &Contract{
Script: pubKey.GetVerificationScript(), Script: pubKey.GetVerificationScript(),
Parameters: getContractParams(1), Parameters: getContractParams(1),

View file

@ -215,7 +215,7 @@ func convertPubs(t *testing.T, hexKeys []string) []*keys.PublicKey {
func compareFields(t *testing.T, tk keytestcases.Ktype, acc *Account) { func compareFields(t *testing.T, tk keytestcases.Ktype, acc *Account) {
want, have := tk.Address, acc.Address want, have := tk.Address, acc.Address
require.Equalf(t, want, have, "expected address %s got %s", want, have) require.Equalf(t, want, have, "expected address %s got %s", want, have)
want, have = tk.Wif, acc.wif want, have = tk.Wif, acc.privateKey.WIF()
require.Equalf(t, want, have, "expected wif %s got %s", want, have) 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.publicKey)
require.Equalf(t, want, have, "expected pub key %s got %s", want, have) require.Equalf(t, want, have, "expected pub key %s got %s", want, have)

View file

@ -49,7 +49,6 @@ func TestAddAccount(t *testing.T) {
wallet.AddAccount(&Account{ wallet.AddAccount(&Account{
privateKey: nil, privateKey: nil,
publicKey: nil, publicKey: nil,
wif: "",
Address: "real", Address: "real",
EncryptedWIF: "", EncryptedWIF: "",
Label: "", Label: "",
@ -79,7 +78,6 @@ func TestSave(t *testing.T) {
wallet.AddAccount(&Account{ wallet.AddAccount(&Account{
privateKey: nil, privateKey: nil,
publicKey: nil, publicKey: nil,
wif: "",
Address: "", Address: "",
EncryptedWIF: "", EncryptedWIF: "",
Label: "", Label: "",