From 64fcf944b2d46b20f7dabf32b3d5e7a52b80771d Mon Sep 17 00:00:00 2001 From: jeronimoalbi Date: Wed, 10 Aug 2022 12:09:27 +0200 Subject: [PATCH] fix: change relayer call to use secp256k1 private keys in call This chage uses secp256k1 private keys instead of ASCII armored ones as gRPC arguments when calling the TS relayer. --- ignite/pkg/relayer/relayer.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/ignite/pkg/relayer/relayer.go b/ignite/pkg/relayer/relayer.go index 1c6df3cf9a..58056bcf8f 100644 --- a/ignite/pkg/relayer/relayer.go +++ b/ignite/pkg/relayer/relayer.go @@ -2,11 +2,13 @@ package relayer import ( "context" + "encoding/hex" "fmt" "strings" "sync" "time" + "github.com/cosmos/cosmos-sdk/crypto" sdk "github.com/cosmos/cosmos-sdk/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" @@ -19,6 +21,7 @@ import ( ) const ( + algoSecp256k1 = "secp256k1" ibcSetupGas int64 = 2256000 relayDuration = time.Second * 5 ) @@ -200,12 +203,25 @@ func (r Relayer) prepare(ctx context.Context, conf relayerconf.Config, chainID s } } - key, err := r.ca.ExportHex(chain.Account, "") + // Get the key in ASCII armored format + passphrase := "" + key, err := r.ca.Export(chain.Account, passphrase) if err != nil { return relayerconf.Chain{}, "", err } - return chain, key, nil + // Unarmor the key to be able to read it as bytes + priv, algo, err := crypto.UnarmorDecryptPrivKey(key, passphrase) + if err != nil { + return relayerconf.Chain{}, "", err + } + + // Check the algorithm because the TS relayer expects a secp256k1 private key + if algo != algoSecp256k1 { + return relayerconf.Chain{}, "", fmt.Errorf("private key algorithm must be secp256k1 instead of %s", algo) + } + + return chain, hex.EncodeToString(priv.Bytes()), nil } func (r Relayer) balance(ctx context.Context, rpcAddress, account, addressPrefix string) (sdk.Coins, error) {