-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
export.go
44 lines (38 loc) · 1.05 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 csakey
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 = "CSA"
func FromEncryptedJSON(keyJSON []byte, password string) (KeyV2, error) {
return keys.FromEncryptedJSON(
keyTypeIdentifier,
keyJSON,
password,
adulteratedPassword,
func(_ keys.EncryptedKeyExport, rawPrivKey []byte) (KeyV2, error) {
return Raw(rawPrivKey).Key(), nil
},
)
}
func (k KeyV2) ToEncryptedJSON(password string, scryptParams utils.ScryptParams) (export []byte, err error) {
return keys.ToEncryptedJSON(
keyTypeIdentifier,
k.Raw(),
k,
password,
scryptParams,
adulteratedPassword,
func(id string, key KeyV2, cryptoJSON keystore.CryptoJSON) (keys.EncryptedKeyExport, error) {
return keys.EncryptedKeyExport{
KeyType: id,
PublicKey: key.PublicKeyString(),
Crypto: cryptoJSON,
}, nil
},
)
}
func adulteratedPassword(password string) string {
return "csakey" + password
}