-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
export.go
44 lines (38 loc) · 1.26 KB
/
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package dkgencryptkey
import (
"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys"
"github.com/smartcontractkit/chainlink/v2/core/utils"
)
const keyTypeIdentifier = "DKGEncrypt"
// FromEncryptedJSON returns a dkgencryptkey.KeyV2 from encrypted data in go-ethereum keystore format.
func FromEncryptedJSON(keyJSON []byte, password string) (Key, error) {
return keys.FromEncryptedJSON(
keyTypeIdentifier,
keyJSON,
password,
adulteratedPassword,
func(_ keys.EncryptedKeyExport, rawPrivKey []byte) (Key, error) {
return Raw(rawPrivKey).Key(), nil
})
}
// ToEncryptedJSON exports this key into a JSON object following the format of EncryptedDKGEncryptKeyExport
func (k Key) ToEncryptedJSON(password string, scryptParams utils.ScryptParams) (export []byte, err error) {
return keys.ToEncryptedJSON(
keyTypeIdentifier,
k.Raw(),
k,
password,
scryptParams,
adulteratedPassword,
func(id string, key Key, cryptoJSON keystore.CryptoJSON) (keys.EncryptedKeyExport, error) {
return keys.EncryptedKeyExport{
KeyType: id,
PublicKey: key.PublicKeyString(),
Crypto: cryptoJSON,
}, nil
})
}
func adulteratedPassword(password string) string {
return "dkgencryptkey" + password
}