From 0ff6bb5d348cd250ae113ae962c6dc8209cb8075 Mon Sep 17 00:00:00 2001 From: KonradStaniec Date: Tue, 26 Nov 2024 11:25:10 +0100 Subject: [PATCH 1/2] test importing private key --- covenant-signer/itest/testmanager.go | 17 ++++++++++++----- .../keystore/cosmos/keyringcontroller.go | 1 - 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/covenant-signer/itest/testmanager.go b/covenant-signer/itest/testmanager.go index 97a60c8..abb3993 100644 --- a/covenant-signer/itest/testmanager.go +++ b/covenant-signer/itest/testmanager.go @@ -2,6 +2,7 @@ package e2etest import ( "context" + "encoding/hex" "fmt" "testing" "time" @@ -54,7 +55,6 @@ func StartManager( _ = h.GenerateBlocks(int(numMatureOutputsInWallet) + 100) appConfig := config.DefaultConfig() - appConfig.KeyStore.KeyStoreType = "cosmos" appConfig.KeyStore.CosmosKeyStore.ChainID = "test-chain" appConfig.KeyStore.CosmosKeyStore.Passphrase = passphrase @@ -65,9 +65,16 @@ func StartManager( retriever, err := cosmos.NewCosmosKeyringRetriever(appConfig.KeyStore.CosmosKeyStore) require.NoError(t, err) - keyInfo, err := retriever.Kr.CreateChainKey( - appConfig.KeyStore.CosmosKeyStore.Passphrase, - "", + covPrivKey, err := btcec.NewPrivateKey() + require.NoError(t, err) + + hexPrivKey := hex.EncodeToString(covPrivKey.Serialize()) + + // Import private key to keyring, from hex string + err = retriever.Kr.GetKeyring().ImportPrivKeyHex( + appConfig.KeyStore.CosmosKeyStore.KeyName, + hexPrivKey, + "secp256k1", ) require.NoError(t, err) @@ -103,7 +110,7 @@ func StartManager( t: t, bitcoindHandler: h, walletPass: passphrase, - covenantPrivKey: keyInfo.PrivateKey, + covenantPrivKey: covPrivKey, signerConfig: appConfig, app: app, server: server, diff --git a/covenant-signer/keystore/cosmos/keyringcontroller.go b/covenant-signer/keystore/cosmos/keyringcontroller.go index 0e594a2..c3bfcbf 100644 --- a/covenant-signer/keystore/cosmos/keyringcontroller.go +++ b/covenant-signer/keystore/cosmos/keyringcontroller.go @@ -80,7 +80,6 @@ func (kc *ChainKeyringController) CreateChainKey(passphrase, hdPath string) (*Ch if err != nil { return nil, err } - // read entropy seed straight from tmcrypto.Rand and convert to mnemonic entropySeed, err := bip39.NewEntropy(mnemonicEntropySize) if err != nil { From dcc86e6d6e4ddff7298a4ab7c455c5e129eb3a28 Mon Sep 17 00:00:00 2001 From: KonradStaniec Date: Tue, 26 Nov 2024 11:28:37 +0100 Subject: [PATCH 2/2] change log --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fe99bc6..508884a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ## Unreleased +### Improvements + +* [#43](https://github.com/babylonlabs-io/covenant-emulator/pull/43) Test importing +private key to the cosmos keyring + ## v0.9.0 * [#33](https://github.com/babylonlabs-io/covenant-emulator/pull/33) Add remote