2017-11-09 04:01:32 +01:00
|
|
|
package main
|
2017-11-20 19:44:19 +01:00
|
|
|
|
2017-11-09 04:01:32 +01:00
|
|
|
import (
|
2017-11-20 19:44:19 +01:00
|
|
|
"C"
|
2017-11-27 16:25:04 +01:00
|
|
|
"encoding/hex"
|
2018-02-15 20:51:51 +01:00
|
|
|
"github.com/lbryio/lbryschema.go/address"
|
|
|
|
"github.com/lbryio/lbryschema.go/claim"
|
2017-11-09 04:01:32 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
//export VerifySignature
|
2017-11-20 19:44:19 +01:00
|
|
|
func VerifySignature(claimHex string, certificateHex string, claimAddress string, certificateId string, blockchainName string) bool {
|
|
|
|
decodedClaim, err := claim.DecodeClaimHex(claimHex, blockchainName)
|
2017-11-09 04:01:32 +01:00
|
|
|
if err != nil {
|
|
|
|
return false
|
|
|
|
}
|
2017-11-20 19:44:19 +01:00
|
|
|
decodedCertificate, err := claim.DecodeClaimHex(certificateHex, blockchainName)
|
2017-11-13 16:11:19 +01:00
|
|
|
if err != nil {
|
|
|
|
return false
|
|
|
|
}
|
2017-11-20 19:44:19 +01:00
|
|
|
result, err := decodedClaim.ValidateClaimSignature(decodedCertificate, claimAddress, certificateId, blockchainName)
|
2017-11-09 04:01:32 +01:00
|
|
|
if err != nil {
|
|
|
|
return false
|
|
|
|
}
|
2017-11-27 16:25:04 +01:00
|
|
|
return result
|
2017-11-13 16:11:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//export DecodeClaimHex
|
2017-11-20 19:44:19 +01:00
|
|
|
func DecodeClaimHex(claimHex string, blockchainName string) *C.char {
|
|
|
|
decodedClaim, err := claim.DecodeClaimHex(claimHex, blockchainName)
|
2017-11-13 16:11:19 +01:00
|
|
|
if err != nil {
|
2017-11-27 16:25:04 +01:00
|
|
|
return C.CString("decode error: " + err.Error())
|
2017-11-13 16:11:19 +01:00
|
|
|
}
|
|
|
|
decoded, err := decodedClaim.RenderJSON()
|
|
|
|
if err != nil {
|
2017-11-27 16:25:04 +01:00
|
|
|
return C.CString("encode error: " + err.Error())
|
2017-11-13 16:11:19 +01:00
|
|
|
}
|
|
|
|
return C.CString(decoded)
|
2017-11-09 04:01:32 +01:00
|
|
|
}
|
|
|
|
|
2017-11-27 16:25:04 +01:00
|
|
|
//export SerializeClaimFromJSON
|
|
|
|
func SerializeClaimFromJSON(claimJSON string, blockchainName string) *C.char {
|
|
|
|
decodedClaim, err := claim.DecodeClaimJSON(claimJSON, blockchainName)
|
|
|
|
if err != nil {
|
|
|
|
return C.CString("decode error: " + err.Error())
|
|
|
|
}
|
|
|
|
SerializedHex, err := decodedClaim.SerializedHexString()
|
|
|
|
if err != nil {
|
|
|
|
return C.CString("encode error: " + err.Error())
|
|
|
|
}
|
|
|
|
return C.CString(SerializedHex)
|
|
|
|
}
|
|
|
|
|
|
|
|
//export DecodeAddress
|
|
|
|
func DecodeAddress(addressString string, blockchainName string) *C.char {
|
|
|
|
addressBytes, err := address.DecodeAddress(addressString, blockchainName)
|
|
|
|
if err != nil {
|
|
|
|
return C.CString("error: " + err.Error())
|
|
|
|
}
|
|
|
|
return C.CString(hex.EncodeToString(addressBytes[:]))
|
|
|
|
}
|
|
|
|
|
|
|
|
//export EncodeAddress
|
|
|
|
func EncodeAddress(addressChars string, blockchainName string) *C.char {
|
|
|
|
addressBytes := [25]byte{}
|
|
|
|
if len(addressChars) != 25 {
|
|
|
|
return C.CString("error: address is not 25 bytes")
|
|
|
|
}
|
|
|
|
for i := range addressBytes {
|
|
|
|
addressBytes[i] = byte(addressChars[i])
|
|
|
|
}
|
|
|
|
encodedAddress, err := address.EncodeAddress(addressBytes, blockchainName)
|
|
|
|
if err != nil {
|
|
|
|
return C.CString("error: " + err.Error())
|
|
|
|
}
|
|
|
|
return C.CString(encodedAddress)
|
|
|
|
}
|
|
|
|
|
2017-11-09 04:01:32 +01:00
|
|
|
func main() {}
|