Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add babylon address to keys output #63

Merged
merged 5 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Loading