-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
export.go
47 lines (41 loc) · 1.27 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
package starkkey
import (
"github.com/ethereum/go-ethereum/accounts/keystore"
stark "github.com/smartcontractkit/chainlink-starknet/relayer/pkg/chainlink/keys"
"github.com/smartcontractkit/chainlink/core/services/keystore/keys"
"github.com/smartcontractkit/chainlink/core/utils"
)
const keyTypeIdentifier = "StarkNet"
// FromEncryptedJSON gets key from json and password
func FromEncryptedJSON(keyJSON []byte, password string) (stark.Key, error) {
return keys.FromEncryptedJSON(
keyTypeIdentifier,
keyJSON,
password,
adulteratedPassword,
func(_ keys.EncryptedKeyExport, rawPrivKey []byte) (stark.Key, error) {
return stark.Raw(rawPrivKey).Key(), nil
},
)
}
// ToEncryptedJSON returns encrypted JSON representing key
func ToEncryptedJSON(key stark.Key, password string, scryptParams utils.ScryptParams) (export []byte, err error) {
return keys.ToEncryptedJSON(
keyTypeIdentifier,
key.Raw(),
key,
password,
scryptParams,
adulteratedPassword,
func(id string, key stark.Key, cryptoJSON keystore.CryptoJSON) (keys.EncryptedKeyExport, error) {
return keys.EncryptedKeyExport{
KeyType: id,
PublicKey: key.AccountAddressStr(),
Crypto: cryptoJSON,
}, nil
},
)
}
func adulteratedPassword(password string) string {
return "starkkey" + password
}