add DecodeClaimHex to python binding

This commit is contained in:
Jack Robison 2017-11-13 10:11:19 -05:00
parent 8aaa786512
commit 37a8c4cae1
No known key found for this signature in database
GPG key ID: 284699E7404E3CFF
3 changed files with 25 additions and 9 deletions

View file

@ -5,17 +5,36 @@ import (
)
//export VerifySignature
func VerifySignature(claimHex string, certificateHex string, claimAddress string, certificateId string) (bool) {
func VerifySignature(claimHex string, certificateHex string, claimAddress string, certificateId string) bool {
decodedClaim, err := claim.DecodeClaimHex(claimHex)
if err != nil {
return false
}
decodedCertificate, err := claim.DecodeClaimHex(certificateHex)
if err != nil {
return false
}
result, err := decodedClaim.ValidateClaimSignature(decodedCertificate, claimAddress, certificateId)
if err != nil {
return false
}
return result
if result == false {
return false
}
return true
}
//export DecodeClaimHex
func DecodeClaimHex(claimHex string) *C.char {
decodedClaim, err := claim.DecodeClaimHex(claimHex)
if err != nil {
return C.CString("decode error")
}
decoded, err := decodedClaim.RenderJSON()
if err != nil {
return C.CString("encode error")
}
return C.CString(decoded)
}
func main() {}

View file

@ -4,7 +4,6 @@ import (
"../address"
"crypto/sha256"
"errors"
"fmt"
"encoding/asn1"
"crypto/x509/pkix"
"github.com/btcsuite/btcd/btcec"
@ -30,22 +29,21 @@ func GetClaimSignatureDigest(claimAddress [25]byte, certificateId [20]byte, seri
return [32]byte(digest)
}
func (claim *ClaimHelper) GetCertificatePublicKey() (btcec.PublicKey, error) {
func (claim *ClaimHelper) GetCertificatePublicKey() (*btcec.PublicKey, error) {
derBytes := claim.GetCertificate().GetPublicKey()
pub := publicKeyInfo{}
asn1.Unmarshal(derBytes, &pub)
pubkey_bytes := []byte(pub.PublicKey.Bytes)
p, err := btcec.ParsePubKey(pubkey_bytes, btcec.S256())
if err != nil {
fmt.Println("parse public key error: ", err)
return &btcec.PublicKey{}, err
}
return *p, err
return p, err
}
func (claim *ClaimHelper) VerifyDigest(certificate *ClaimHelper, signature [64]byte, digest [32]byte) bool {
public_key, err := certificate.GetCertificatePublicKey()
if err != nil {
fmt.Println("parse public key error: ", err)
return false
}
@ -56,7 +54,6 @@ func (claim *ClaimHelper) VerifyDigest(certificate *ClaimHelper, signature [64]b
S.SetBytes(signature[32:64])
return ecdsa.Verify(public_key.ToECDSA(), digest[:], R, S)
}
fmt.Println("unknown curve:", claim.PublisherSignature.SignatureType.String())
return false
}