Skip to content

Commit 71571ee

Browse files
authored
Merge pull request #157 from initia-labs/feat/add-coin-type
feat: add coin-type and key-type when generate key
2 parents 96c04ab + a855f37 commit 71571ee

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

cosmosutils/keys.go

+16-9
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,12 @@ func UnmarshalKeyInfo(rawJson string) (KeyInfo, error) {
3535

3636
// AddOrReplace adds or replaces a key using `initiad keys add <keyname> --keyring-backend test` with 'y' confirmation
3737
func AddOrReplace(appName, keyname string) (string, error) {
38-
// Command to add the key: echo 'y' | initiad keys add <keyname> --keyring-backend test
39-
cmd := exec.Command(appName, "keys", "add", keyname, "--keyring-backend", "test", "--output", "json")
40-
38+
var cmd *exec.Cmd
39+
if strings.HasSuffix(appName, "celestia-appd") {
40+
cmd = exec.Command(appName, "keys", "add", keyname, "--keyring-backend", "test", "--output", "json")
41+
} else {
42+
cmd = exec.Command(appName, "keys", "add", keyname, "--coin-type", "118", "--key-type", "secp256k1", "--keyring-backend", "test", "--output", "json")
43+
}
4144
// Simulate pressing 'y' for confirmation
4245
cmd.Stdin = bytes.NewBufferString("y\n")
4346

@@ -78,8 +81,12 @@ func RecoverKeyFromMnemonic(appName, keyname, mnemonic string) (string, error) {
7881
// Add the mnemonic input after the confirmation (if any)
7982
inputBuffer.WriteString(mnemonic + "\n")
8083

81-
// Command to recover (or replace) the key: initiad keys add <keyname> --recover --keyring-backend test
82-
cmd := exec.Command(appName, "keys", "add", keyname, "--recover", "--keyring-backend", "test", "--output", "json")
84+
var cmd *exec.Cmd
85+
if strings.HasSuffix(appName, "celestia-appd") {
86+
cmd = exec.Command(appName, "keys", "add", keyname, "--recover", "--keyring-backend", "test", "--output", "json")
87+
} else {
88+
cmd = exec.Command(appName, "keys", "add", keyname, "--coin-type", "118", "--key-type", "secp256k1", "--recover", "--keyring-backend", "test", "--output", "json")
89+
}
8390

8491
// Pass the combined confirmation and mnemonic as input to the command
8592
cmd.Stdin = &inputBuffer
@@ -148,9 +155,9 @@ func OPInitRecoverKeyFromMnemonic(appName, keyname, mnemonic string, isCelestia
148155
// Add the mnemonic input after the confirmation (if any)
149156
inputBuffer.WriteString(mnemonic + "\n")
150157
if isCelestia {
151-
cmd = exec.Command(appName, "keys", "add", "weave-dummy", keyname, "--recover", "--bech32", "celestia", "--home", opInitHome)
158+
cmd = exec.Command(appName, "keys", "add", "weave-dummy", keyname, "--coin-type", "118", "--key-type", "secp256k1", "--recover", "--bech32", "celestia", "--home", opInitHome)
152159
} else {
153-
cmd = exec.Command(appName, "keys", "add", "weave-dummy", keyname, "--recover", "--home", opInitHome)
160+
cmd = exec.Command(appName, "keys", "add", "weave-dummy", keyname, "--coin-type", "118", "--key-type", "secp256k1", "--recover", "--home", opInitHome)
154161
}
155162
// Pass the combined confirmation and mnemonic as input to the command
156163
cmd.Stdin = &inputBuffer
@@ -241,9 +248,9 @@ func OPInitAddOrReplace(appName, keyname string, isCelestia bool, opInitHome str
241248
var cmd *exec.Cmd
242249

243250
if isCelestia {
244-
cmd = exec.Command(appName, "keys", "add", "weave-dummy", keyname, "--bech32", "celestia", "--home", opInitHome)
251+
cmd = exec.Command(appName, "keys", "add", "weave-dummy", keyname, "--coin-type", "118", "--key-type", "secp256k1", "--bech32", "celestia", "--home", opInitHome)
245252
} else {
246-
cmd = exec.Command(appName, "keys", "add", "weave-dummy", keyname, "--home", opInitHome)
253+
cmd = exec.Command(appName, "keys", "add", "weave-dummy", keyname, "--coin-type", "118", "--key-type", "secp256k1", "--home", opInitHome)
247254

248255
}
249256
// Simulate pressing 'y' for confirmation

0 commit comments

Comments
 (0)