adjusted signing to work with ext pub keys being commited within the cid notarization message

Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
This commit is contained in:
Jürgen Eckel 2023-09-12 14:49:25 +02:00
parent 311a3596c2
commit ea1e316852
No known key found for this signature in database
2 changed files with 23 additions and 2 deletions

View File

@ -3,6 +3,7 @@ package util
import ( import (
"encoding/hex" "encoding/hex"
"github.com/btcsuite/btcd/btcutil/hdkeychain"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
) )
@ -20,3 +21,16 @@ func ValidateSignature(message string, signature string, publicKey string) bool
return isValid return isValid
} }
func GetHexPubKey(ext_pub_key string) (string, error) {
xpubKey, err := hdkeychain.NewKeyFromString(ext_pub_key)
if err != nil {
return "", err
}
pubKey, err := xpubKey.ECPubKey()
if err != nil {
return "", err
}
byte_key := pubKey.SerializeCompressed()
return hex.EncodeToString(byte_key), nil
}

View File

@ -18,8 +18,11 @@ func (k msgServer) NotarizeAsset(goCtx context.Context, msg *types.MsgNotarizeAs
if !found { if !found {
return nil, errors.New("machine not found") return nil, errors.New("machine not found")
} }
hex_pub_key, err := util.GetHexPubKey(msg.PubKey)
valid := util.ValidateSignature(msg.Hash, msg.Signature, msg.PubKey) if err != nil {
return nil, errors.New("could not convert xpub key to hex pub key")
}
valid := util.ValidateSignature(msg.Hash, msg.Signature, hex_pub_key)
if !valid { if !valid {
return nil, errors.New("invalid signature") return nil, errors.New("invalid signature")
} }
@ -34,3 +37,7 @@ func (k msgServer) NotarizeAsset(goCtx context.Context, msg *types.MsgNotarizeAs
return &types.MsgNotarizeAssetResponse{}, nil return &types.MsgNotarizeAssetResponse{}, nil
} }
func getHexPubKey(s string) {
panic("unimplemented")
}