-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
export.go
29 lines (25 loc) · 881 Bytes
/
export.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package ethkey
import (
"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/google/uuid"
"github.com/pkg/errors"
"github.com/smartcontractkit/chainlink/v2/core/utils"
)
type EncryptedEthKeyExport struct {
KeyType string `json:"keyType"`
Address EIP55Address `json:"address"`
Crypto keystore.CryptoJSON `json:"crypto"`
}
func (key KeyV2) ToEncryptedJSON(password string, scryptParams utils.ScryptParams) (export []byte, err error) {
// DEV: uuid is derived directly from the address, since it is not stored internally
id, err := uuid.FromBytes(key.Address.Bytes()[:16])
if err != nil {
return nil, errors.Wrapf(err, "could not generate ethkey UUID")
}
dKey := &keystore.Key{
Id: id,
Address: key.Address,
PrivateKey: key.privateKey,
}
return keystore.EncryptKey(dKey, password, scryptParams.N, scryptParams.P)
}