frostfs-node/pkg/util/config/crypto.go
Leonard Lyubich dab33e0f9b [#652] Update Neo Go to v0.95.3
Add `keys.NEP2ScryptParams()` to `keys.NEP2Decrypt` call arguments.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-06-29 13:44:59 +03:00

35 lines
708 B
Go

package config
import (
"errors"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
"github.com/nspcc-dev/neo-go/pkg/wallet"
)
// LoadAccount loads NEP-6 load, unlocks and returns provided account.
func LoadAccount(path, addr, password string) (*wallet.Account, error) {
w, err := wallet.NewWalletFromFile(path)
if err != nil {
return nil, err
}
defer w.Close()
h, err := address.StringToUint160(addr)
if err != nil {
return nil, err
}
acc := w.GetAccount(h)
if acc == nil {
return nil, errors.New("account is missing")
}
if err := acc.Decrypt(password, keys.NEP2ScryptParams()); err != nil {
return nil, err
}
return acc, nil
}