From 08f90c628566d1bf28e460d6a7031980b2d29c83 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Mon, 9 Dec 2024 13:32:55 -0300 Subject: [PATCH] feat: add babylon address to keys output (#63) * feat: add babylon address to keys output and moved public-key to public-key-hex * fix: Casing on covenant-signer Dockerfile (#65) * chore: add #63 to changelog --------- Co-authored-by: Vitalis Salis --- CHANGELOG.md | 5 +++++ cmd/covd/key.go | 26 +++++++++++++++++++------- covenant-signer/Dockerfile | 2 +- keyring/keyringcontroller.go | 7 +------ types/chainkey.go | 22 ++++++++++++++++++++-- 5 files changed, 46 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index becfe47..1a60ab0 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 + +* [#63](https://github.com/babylonlabs-io/covenant-emulator/pull/63) Add babylon +address to keys command output and fix casing in dockerfile + ## v0.10.0 ### Improvements diff --git a/cmd/covd/key.go b/cmd/covd/key.go index b2511e4..379ce23 100644 --- a/cmd/covd/key.go +++ b/cmd/covd/key.go @@ -15,8 +15,9 @@ import ( ) type covenantKey struct { - Name string `json:"name"` - PublicKey string `json:"public-key"` + Name string `json:"name"` + PublicKey string `json:"public-key-hex"` + BabylonAddr string `json:"babylon-address"` } var createKeyCommand = cli.Command{ @@ -88,8 +89,9 @@ func createKey(ctx *cli.Context) error { bip340Key := types.NewBIP340PubKeyFromBTCPK(keyPair.PublicKey) printRespJSON( &covenantKey{ - Name: ctx.String(keyNameFlag), - PublicKey: bip340Key.MarshalHex(), + Name: ctx.String(keyNameFlag), + PublicKey: bip340Key.MarshalHex(), + BabylonAddr: keyPair.Address, }, ) @@ -157,15 +159,25 @@ func showKey(ctx *cli.Context) error { return err } + r, err := krController.KeyRecord() + if err != nil { + return err + } + + babylonAddr, err := r.GetAddress() + if err != nil { + return err + } + _, pk := btcec.PrivKeyFromBytes(privKey.Key) bip340Key := types.NewBIP340PubKeyFromBTCPK(pk) printRespJSON( &covenantKey{ - Name: ctx.String(keyNameFlag), - PublicKey: bip340Key.MarshalHex(), + Name: ctx.String(keyNameFlag), + PublicKey: bip340Key.MarshalHex(), + BabylonAddr: babylonAddr.String(), }, ) - return nil } diff --git a/covenant-signer/Dockerfile b/covenant-signer/Dockerfile index 8fc3e2f..08b5f03 100644 --- a/covenant-signer/Dockerfile +++ b/covenant-signer/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.23.1-alpine as builder +FROM golang:1.23.1-alpine AS builder # Use muslc for static libs ARG BUILD_TAGS="muslc" diff --git a/keyring/keyringcontroller.go b/keyring/keyringcontroller.go index 0852947..5654116 100644 --- a/keyring/keyringcontroller.go +++ b/keyring/keyringcontroller.go @@ -99,12 +99,7 @@ func (kc *ChainKeyringController) CreateChainKey(passphrase, hdPath string) (*ty switch v := privKey.(type) { case *sdksecp256k1.PrivKey: sk, pk := btcec.PrivKeyFromBytes(v.Key) - return &types.ChainKeyInfo{ - Name: kc.keyName, - PublicKey: pk, - PrivateKey: sk, - Mnemonic: mnemonic, - }, nil + return types.NewChainKeyInfo(record, pk, sk) default: return nil, fmt.Errorf("unsupported key type in keyring") } diff --git a/types/chainkey.go b/types/chainkey.go index 4e56c55..bb22d9d 100644 --- a/types/chainkey.go +++ b/types/chainkey.go @@ -2,11 +2,29 @@ package types import ( "github.com/btcsuite/btcd/btcec/v2" + "github.com/cosmos/cosmos-sdk/client/keys" + "github.com/cosmos/cosmos-sdk/crypto/keyring" + "github.com/decred/dcrd/dcrec/secp256k1/v4" ) type ChainKeyInfo struct { - Name string - Mnemonic string + keys.KeyOutput PublicKey *btcec.PublicKey PrivateKey *btcec.PrivateKey } + +func NewChainKeyInfo( + k *keyring.Record, + pk *secp256k1.PublicKey, + sk *secp256k1.PrivateKey, +) (*ChainKeyInfo, error) { + keyOut, err := keys.MkAccKeyOutput(k) + if err != nil { + return nil, err + } + return &ChainKeyInfo{ + KeyOutput: keyOut, + PublicKey: pk, + PrivateKey: sk, + }, nil +}