mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-03-30 15:08:28 +00:00
replace byte cast with hex.DecodeString()
Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
This commit is contained in:
parent
3e18324004
commit
311a3596c2
@ -110,7 +110,7 @@ func Asset(sk string) (string, string) {
|
||||
skBytes, _ := hex.DecodeString(sk)
|
||||
privKey := &secp256k1.PrivKey{Key: skBytes}
|
||||
|
||||
cid_bytes := []byte(cid)
|
||||
cid_bytes, _ := hex.DecodeString(cid)
|
||||
sign, _ := privKey.Sign(cid_bytes)
|
||||
|
||||
signatureHex := hex.EncodeToString(sign)
|
||||
|
@ -7,21 +7,6 @@ import (
|
||||
)
|
||||
|
||||
func ValidateSignature(message string, signature string, publicKey string) bool {
|
||||
// Convert the message, signature, and public key from hex to bytes
|
||||
messageBytes := []byte(message)
|
||||
signatureBytes, _ := hex.DecodeString(signature)
|
||||
publicKeyBytes, _ := hex.DecodeString(publicKey)
|
||||
|
||||
// Create a secp256k1 public key object
|
||||
pubKey := &secp256k1.PubKey{Key: publicKeyBytes}
|
||||
|
||||
// Verify the signature
|
||||
isValid := pubKey.VerifySignature(messageBytes, signatureBytes)
|
||||
|
||||
return isValid
|
||||
}
|
||||
|
||||
func ValidateSignature_hexstring(message string, signature string, publicKey string) bool {
|
||||
// Convert the message, signature, and public key from hex to bytes
|
||||
messageBytes, _ := hex.DecodeString(message)
|
||||
signatureBytes, _ := hex.DecodeString(signature)
|
||||
|
@ -33,7 +33,7 @@ func (k msgServer) AttestMachine(goCtx context.Context, msg *types.MsgAttestMach
|
||||
return nil, errors.New("trust anchor has already been used for attestation")
|
||||
}
|
||||
|
||||
isValidMachineId := util.ValidateSignature_hexstring(msg.Machine.MachineId, msg.Machine.MachineIdSignature, msg.Machine.MachineId)
|
||||
isValidMachineId := util.ValidateSignature(msg.Machine.MachineId, msg.Machine.MachineIdSignature, msg.Machine.MachineId)
|
||||
if !isValidMachineId {
|
||||
return nil, errors.New("invalid machine id")
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user