forked from cosmos/relayer
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathkeys.go
201 lines (178 loc) · 6.7 KB
/
keys.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
package archway
import (
// "errors"
// "os"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/relayer/v2/relayer/provider"
// "github.com/cosmos/go-bip39"
// "github.com/cosmos/relayer/v2/relayer/codecs/ethermint"
// "github.com/cosmos/relayer/v2/relayer/codecs/injective"
// "github.com/cosmos/relayer/v2/relayer/provider"
)
// const ethereumCoinType = uint32(60)
// var (
// // SupportedAlgorithms defines the list of signing algorithms used on Evmos:
// // - secp256k1 (Cosmos)
// // - eth_secp256k1 (Ethereum)
// SupportedAlgorithms = keyring.SigningAlgoList{hd.Secp256k1, ethermint.EthSecp256k1, injective.EthSecp256k1}
// // SupportedAlgorithmsLedger defines the list of signing algorithms used on Evmos for the Ledger device:
// // - secp256k1 (Cosmos)
// // - eth_secp256k1 (Ethereum)
// SupportedAlgorithmsLedger = keyring.SigningAlgoList{hd.Secp256k1, ethermint.EthSecp256k1, injective.EthSecp256k1}
// )
// // KeyringAlgoOptions defines a function keys options for the ethereum Secp256k1 curve.
// // It supports secp256k1 and eth_secp256k1 keys for accounts.
// func KeyringAlgoOptions() keyring.Option {
// return func(options *keyring.Options) {
// options.SupportedAlgos = SupportedAlgorithms
// options.SupportedAlgosLedger = SupportedAlgorithmsLedger
// }
// }
// // CreateKeystore initializes a new instance of a keyring at the specified path in the local filesystem.
func (cc *ArchwayProvider) CreateKeystore(path string) error {
// keybase, err := keyring.New(cc.PCfg.ChainID, cc.PCfg.KeyringBackend, cc.PCfg.KeyDirectory, cc.Input, cc.Cdc.Marshaler, KeyringAlgoOptions())
// if err != nil {
// return err
// }
// cc.Keybase = keybase
return nil
}
// // KeystoreCreated returns true if there is an existing keystore instance at the specified path, it returns false otherwise.
func (cc *ArchwayProvider) KeystoreCreated(path string) bool {
// if _, err := os.Stat(cc.PCfg.KeyDirectory); errors.Is(err, os.ErrNotExist) {
// return false
// } else if cc.Keybase == nil {
// return false
// }
return true
}
// // AddKey generates a new mnemonic which is then converted to a private key and BIP-39 HD Path and persists it to the keystore.
// // It fails if there is an existing key with the same address.
func (cc *ArchwayProvider) AddKey(name string, coinType uint32) (output *provider.KeyOutput, err error) {
// ko, err := cc.KeyAddOrRestore(name, coinType)
// if err != nil {
// return nil, err
// }
return nil, nil
}
// // RestoreKey converts a mnemonic to a private key and BIP-39 HD Path and persists it to the keystore.
// // It fails if there is an existing key with the same address.
func (cc *ArchwayProvider) RestoreKey(name, mnemonic string, coinType uint32) (address string, err error) {
// ko, err := cc.KeyAddOrRestore(name, coinType, mnemonic)
// if err != nil {
// return "", err
// }
return "", nil
}
// // KeyAddOrRestore either generates a new mnemonic or uses the specified mnemonic and converts it to a private key
// // and BIP-39 HD Path which is then persisted to the keystore. It fails if there is an existing key with the same address.
// func (cc *ArchwayProvider) KeyAddOrRestore(keyName string, coinType uint32, mnemonic ...string) (*provider.KeyOutput, error) {
// var mnemonicStr string
// var err error
// algo := keyring.SignatureAlgo(hd.Secp256k1)
// if len(mnemonic) > 0 {
// mnemonicStr = mnemonic[0]
// } else {
// mnemonicStr, err = CreateMnemonic()
// if err != nil {
// return nil, err
// }
// }
// info, err := cc.Keybase.NewAccount(keyName, mnemonicStr, "", hd.CreateHDPath(coinType, 0, 0).String(), algo)
// if err != nil {
// return nil, err
// }
// acc, err := info.GetAddress()
// if err != nil {
// return nil, err
// }
// out, err := cc.EncodeBech32AccAddr(acc)
// if err != nil {
// return nil, err
// }
// return &provider.KeyOutput{Mnemonic: mnemonicStr, Address: out}, nil
// }
// // ShowAddress retrieves a key by name from the keystore and returns the bech32 encoded string representation of that key.
func (cc *ArchwayProvider) ShowAddress(name string) (address string, err error) {
// info, err := cc.Keybase.Key(name)
// if err != nil {
// return "", err
// }
// acc, err := info.GetAddress()
// if err != nil {
// return "", nil
// }
// out, err := cc.EncodeBech32AccAddr(acc)
// if err != nil {
// return "", err
// }
return "", nil
}
// // ListAddresses returns a map of bech32 encoded strings representing all keys currently in the keystore.
func (cc *ArchwayProvider) ListAddresses() (map[string]string, error) {
out := map[string]string{}
// info, err := cc.Keybase.List()
// if err != nil {
// return nil, err
// }
// for _, k := range info {
// acc, err := k.GetAddress()
// if err != nil {
// return nil, err
// }
// addr, err := cc.EncodeBech32AccAddr(acc)
// if err != nil {
// return nil, err
// }
// out[k.Name] = addr
// }
return out, nil
}
// // DeleteKey removes a key from the keystore for the specified name.
func (cc *ArchwayProvider) DeleteKey(name string) error {
// if err := cc.Keybase.Delete(name); err != nil {
// return err
// }
return nil
}
// // KeyExists returns true if a key with the specified name exists in the keystore, it returns false otherwise.
func (cc *ArchwayProvider) KeyExists(name string) bool {
// k, err := cc.Keybase.Key(name)
// if err != nil {
// return false
// }
// return k.Name == name
return false
}
// // ExportPrivKeyArmor returns a private key in ASCII armored format.
// // It returns an error if the key does not exist or a wrong encryption passphrase is supplied.
func (cc *ArchwayProvider) ExportPrivKeyArmor(keyName string) (armor string, err error) {
// return cc.Keybase.ExportPrivKeyArmor(keyName, ckeys.DefaultKeyPass)
return "", nil
}
// // GetKeyAddress returns the account address representation for the currently configured key.
// func (cc *ArchwayProvider) GetKeyAddress() (sdk.AccAddress, error) {
// info, err := cc.Keybase.Key(cc.PCfg.Key)
// if err != nil {
// return nil, err
// }
// return info.GetAddress()
// }
// // CreateMnemonic generates a new mnemonic.
// func CreateMnemonic() (string, error) {
// entropySeed, err := bip39.NewEntropy(256)
// if err != nil {
// return "", err
// }
// mnemonic, err := bip39.NewMnemonic(entropySeed)
// if err != nil {
// return "", err
// }
// return mnemonic, nil
// }
// EncodeBech32AccAddr returns the string bech32 representation for the specified account address.
// It returns an empty sting if the byte slice is 0-length.
// It returns an error if the bech32 conversion fails or the prefix is empty.
func (cc *ArchwayProvider) EncodeBech32AccAddr(addr sdk.AccAddress) (string, error) {
return sdk.Bech32ifyAddressBytes(cc.PCfg.AccountPrefix, addr)
}