forked from TrueCloudLab/frostfs-node
[#562] cmd/neofs-ir: use NEP-6 wallet for keys
Also remove neofs-crypto uses from `pkg/innerring`. Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
88b4fe009a
commit
1553967328
7 changed files with 85 additions and 31 deletions
34
pkg/util/config/crypto.go
Normal file
34
pkg/util/config/crypto.go
Normal file
|
@ -0,0 +1,34 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"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); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return acc, nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue