mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-06-28 00:42:30 +00:00
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:
parent
311a3596c2
commit
ea1e316852
@ -3,6 +3,7 @@ package util
|
||||
import (
|
||||
"encoding/hex"
|
||||
|
||||
"github.com/btcsuite/btcd/btcutil/hdkeychain"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
||||
)
|
||||
|
||||
@ -20,3 +21,16 @@ func ValidateSignature(message string, signature string, publicKey string) bool
|
||||
|
||||
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
|
||||
}
|
||||
|
@ -18,8 +18,11 @@ func (k msgServer) NotarizeAsset(goCtx context.Context, msg *types.MsgNotarizeAs
|
||||
if !found {
|
||||
return nil, errors.New("machine not found")
|
||||
}
|
||||
|
||||
valid := util.ValidateSignature(msg.Hash, msg.Signature, msg.PubKey)
|
||||
hex_pub_key, err := util.GetHexPubKey(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 {
|
||||
return nil, errors.New("invalid signature")
|
||||
}
|
||||
@ -34,3 +37,7 @@ func (k msgServer) NotarizeAsset(goCtx context.Context, msg *types.MsgNotarizeAs
|
||||
|
||||
return &types.MsgNotarizeAssetResponse{}, nil
|
||||
}
|
||||
|
||||
func getHexPubKey(s string) {
|
||||
panic("unimplemented")
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user