mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-22 19:29:39 +00:00
wallet: allow to create accounts from encrypted WIFs
This commit is contained in:
parent
02954285c1
commit
d837eb3761
2 changed files with 26 additions and 0 deletions
|
@ -150,6 +150,19 @@ func NewAccountFromWIF(wif string) (*Account, error) {
|
|||
return newAccountFromPrivateKey(privKey), nil
|
||||
}
|
||||
|
||||
// NewAccountFromEncryptedWIF creates a new Account from the given encrypted WIF.
|
||||
func NewAccountFromEncryptedWIF(wif string, pass string) (*Account, error) {
|
||||
priv, err := keys.NEP2Decrypt(wif, pass)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
a := newAccountFromPrivateKey(priv)
|
||||
a.EncryptedWIF = wif
|
||||
|
||||
return a, nil
|
||||
}
|
||||
|
||||
// newAccountFromPrivateKey creates a wallet from the given PrivateKey.
|
||||
func newAccountFromPrivateKey(p *keys.PrivateKey) *Account {
|
||||
pubKey := p.PublicKey()
|
||||
|
|
|
@ -49,6 +49,19 @@ func TestNewFromWif(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestNewAccountFromEncryptedWIF(t *testing.T) {
|
||||
for _, tc := range keytestcases.Arr {
|
||||
acc, err := NewAccountFromEncryptedWIF(tc.EncryptedWif, tc.Passphrase)
|
||||
if tc.Invalid {
|
||||
assert.Error(t, err)
|
||||
continue
|
||||
}
|
||||
|
||||
assert.NoError(t, err)
|
||||
compareFields(t, tc, acc)
|
||||
}
|
||||
}
|
||||
|
||||
func TestContract_MarshalJSON(t *testing.T) {
|
||||
var c Contract
|
||||
|
||||
|
|
Loading…
Reference in a new issue