forked from TrueCloudLab/neoneo-go
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
|
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.
|
// newAccountFromPrivateKey creates a wallet from the given PrivateKey.
|
||||||
func newAccountFromPrivateKey(p *keys.PrivateKey) *Account {
|
func newAccountFromPrivateKey(p *keys.PrivateKey) *Account {
|
||||||
pubKey := p.PublicKey()
|
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) {
|
func TestContract_MarshalJSON(t *testing.T) {
|
||||||
var c Contract
|
var c Contract
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue