Skip to content

Commit

Permalink
VerifyDerSig
Browse files Browse the repository at this point in the history
  • Loading branch information
Evanfeenstra committed Feb 26, 2024
1 parent 4479847 commit 7ca8fae
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,31 @@ func VerifyAndExtract(msg, sig []byte) (string, bool, error) {
return pubKeyHex, valid, nil
}

// all 3 arguments are hex strings
func VerifyDerSig(sig string, hash string, pubkey string) (bool, error) {
decoded, err := hex.DecodeString(sig)
if err != nil {
return false, err
}
signature, err := btcecdsa.ParseDERSignature(decoded)
if err != nil {
return false, err
}
msg, err := hex.DecodeString(hash)
if err != nil {
return false, err
}
pubkeyBytes, err := hex.DecodeString(pubkey)
if err != nil {
return false, err
}
publicKey, err := btcec.ParsePubKey(pubkeyBytes)
if err != nil {
return false, err
}
return signature.Verify(msg, publicKey), nil
}

func DecodeJwt(token string) (jwt.MapClaims, error) {
claims := jwt.MapClaims{}
_, err := jwt.ParseWithClaims(token, claims, func(token *jwt.Token) (interface{}, error) {
Expand Down

0 comments on commit 7ca8fae

Please sign in to comment.