Skip to content

Commit

Permalink
feat(logic): add Secp256k1 support for ECDSAVerify predicate
Browse files Browse the repository at this point in the history
  • Loading branch information
ccamel committed Oct 27, 2023
1 parent 2a71e15 commit b9f930b
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion x/logic/util/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"crypto/x509"
"encoding/pem"
"fmt"

"github.com/dustinxie/ecc"
)

// Alg is the type of algorithm supported by the crypto util functions.
Expand Down Expand Up @@ -46,7 +48,19 @@ func VerifySignature(alg Alg, pubKey []byte, msg, sig []byte) (r bool, err error
pk := genericPublicKey.(*ecdsa.PublicKey)
r = ecdsa.VerifyASN1(pk, msg, sig)
case Secp256k1:
err = fmt.Errorf("secp256k1 public key not implemented yet")
block, _ := pem.Decode(pubKey)
if block == nil {
err = fmt.Errorf("failed decode PEM public key")
break
}
genericPublicKey, err := x509.ParsePKIXPublicKey(block.Bytes)
if err != nil {
break
}
pk := genericPublicKey.(*ecdsa.PublicKey)
if !ecc.VerifyBytes(pk, msg, sig, ecc.Normal) {
return false, nil
}
default:
err = fmt.Errorf("algo %s not supported", alg)
}
Expand Down

0 comments on commit b9f930b

Please sign in to comment.