Skip to content

Commit

Permalink
feat: add babylon address to keys output and moved public-key to publ…
Browse files Browse the repository at this point in the history
…ic-key-hex
  • Loading branch information
RafilxTenfen committed Dec 9, 2024
1 parent f73ac82 commit d869c3e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 15 deletions.
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
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 d869c3e

Please sign in to comment.