Skip to content

Commit

Permalink
feat: add babylon address to keys output (#63)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
RafilxTenfen and vitsalis authored Dec 9, 2024
1 parent 8f03c5a commit 08f90c6
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 16 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 19 additions & 7 deletions cmd/covd/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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,
},
)

Expand Down Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion covenant-signer/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
7 changes: 1 addition & 6 deletions keyring/keyringcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
22 changes: 20 additions & 2 deletions types/chainkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 08f90c6

Please sign in to comment.