add DecodeClaimHex to python binding
This commit is contained in:
parent
8aaa786512
commit
37a8c4cae1
3 changed files with 25 additions and 9 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,4 +1,4 @@
|
||||||
.idea/
|
.idea/
|
||||||
lbryschema-cli
|
lbryschema-cli
|
||||||
lbryschema-python-binding.h
|
lbryschema-python-binding.h
|
||||||
lbryschema-python-binding.so
|
lbryschema-python-binding.so
|
||||||
|
|
|
@ -5,17 +5,36 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
//export VerifySignature
|
//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)
|
decodedClaim, err := claim.DecodeClaimHex(claimHex)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
decodedCertificate, err := claim.DecodeClaimHex(certificateHex)
|
decodedCertificate, err := claim.DecodeClaimHex(certificateHex)
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
result, err := decodedClaim.ValidateClaimSignature(decodedCertificate, claimAddress, certificateId)
|
result, err := decodedClaim.ValidateClaimSignature(decodedCertificate, claimAddress, certificateId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
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() {}
|
func main() {}
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"../address"
|
"../address"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"encoding/asn1"
|
"encoding/asn1"
|
||||||
"crypto/x509/pkix"
|
"crypto/x509/pkix"
|
||||||
"github.com/btcsuite/btcd/btcec"
|
"github.com/btcsuite/btcd/btcec"
|
||||||
|
@ -30,22 +29,21 @@ func GetClaimSignatureDigest(claimAddress [25]byte, certificateId [20]byte, seri
|
||||||
return [32]byte(digest)
|
return [32]byte(digest)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (claim *ClaimHelper) GetCertificatePublicKey() (btcec.PublicKey, error) {
|
func (claim *ClaimHelper) GetCertificatePublicKey() (*btcec.PublicKey, error) {
|
||||||
derBytes := claim.GetCertificate().GetPublicKey()
|
derBytes := claim.GetCertificate().GetPublicKey()
|
||||||
pub := publicKeyInfo{}
|
pub := publicKeyInfo{}
|
||||||
asn1.Unmarshal(derBytes, &pub)
|
asn1.Unmarshal(derBytes, &pub)
|
||||||
pubkey_bytes := []byte(pub.PublicKey.Bytes)
|
pubkey_bytes := []byte(pub.PublicKey.Bytes)
|
||||||
p, err := btcec.ParsePubKey(pubkey_bytes, btcec.S256())
|
p, err := btcec.ParsePubKey(pubkey_bytes, btcec.S256())
|
||||||
if err != nil {
|
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 {
|
func (claim *ClaimHelper) VerifyDigest(certificate *ClaimHelper, signature [64]byte, digest [32]byte) bool {
|
||||||
public_key, err := certificate.GetCertificatePublicKey()
|
public_key, err := certificate.GetCertificatePublicKey()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("parse public key error: ", err)
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,7 +54,6 @@ func (claim *ClaimHelper) VerifyDigest(certificate *ClaimHelper, signature [64]b
|
||||||
S.SetBytes(signature[32:64])
|
S.SetBytes(signature[32:64])
|
||||||
return ecdsa.Verify(public_key.ToECDSA(), digest[:], R, S)
|
return ecdsa.Verify(public_key.ToECDSA(), digest[:], R, S)
|
||||||
}
|
}
|
||||||
fmt.Println("unknown curve:", claim.PublisherSignature.SignatureType.String())
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue