-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
export.go
48 lines (41 loc) · 1.17 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
45
46
47
48
package solkey
import (
"encoding/hex"
"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 = "Solana"
// FromEncryptedJSON gets key from json and password
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 returns encrypted JSON representing key
func (key Key) ToEncryptedJSON(password string, scryptParams utils.ScryptParams) (export []byte, err error) {
return keys.ToEncryptedJSON(
keyTypeIdentifier,
key.Raw(),
key,
password,
scryptParams,
adulteratedPassword,
func(id string, key Key, cryptoJSON keystore.CryptoJSON) keys.EncryptedKeyExport {
return keys.EncryptedKeyExport{
KeyType: id,
PublicKey: hex.EncodeToString(key.pubKey),
Crypto: cryptoJSON,
}
},
)
}
func adulteratedPassword(password string) string {
return "solkey" + password
}