cleanup
This commit is contained in:
parent
4cff2dd233
commit
2fcc2f106e
2 changed files with 36 additions and 36 deletions
|
@ -1,43 +1,43 @@
|
|||
package claim
|
||||
|
||||
import (
|
||||
"../pb"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"encoding/hex"
|
||||
"../pb"
|
||||
)
|
||||
|
||||
func (claim *ClaimHelper) Serialized() ([]byte, error) {
|
||||
serialized := claim.String()
|
||||
func (c *ClaimHelper) Serialized() ([]byte, error) {
|
||||
serialized := c.String()
|
||||
if serialized == "" {
|
||||
return nil, errors.New("not initialized")
|
||||
}
|
||||
v := claim.GetVersion()
|
||||
t := claim.GetClaimType()
|
||||
v := c.GetVersion()
|
||||
t := c.GetClaimType()
|
||||
|
||||
return proto.Marshal(
|
||||
&pb.Claim{
|
||||
Version: &v,
|
||||
ClaimType: &t,
|
||||
Stream: claim.GetStream(),
|
||||
Certificate: claim.GetCertificate(),
|
||||
PublisherSignature: claim.GetPublisherSignature()})
|
||||
Stream: c.GetStream(),
|
||||
Certificate: c.GetCertificate(),
|
||||
PublisherSignature: c.GetPublisherSignature()})
|
||||
}
|
||||
|
||||
func (claim *ClaimHelper) GetProtobuf() (*pb.Claim) {
|
||||
v := claim.GetVersion()
|
||||
t := claim.GetClaimType()
|
||||
func (c *ClaimHelper) GetProtobuf() *pb.Claim {
|
||||
v := c.GetVersion()
|
||||
t := c.GetClaimType()
|
||||
|
||||
return &pb.Claim{
|
||||
Version: &v,
|
||||
ClaimType: &t,
|
||||
Stream: claim.GetStream(),
|
||||
Certificate: claim.GetCertificate(),
|
||||
PublisherSignature: claim.GetPublisherSignature()}
|
||||
Stream: c.GetStream(),
|
||||
Certificate: c.GetCertificate(),
|
||||
PublisherSignature: c.GetPublisherSignature()}
|
||||
}
|
||||
|
||||
func (claim *ClaimHelper) SerializedHexString() (string, error) {
|
||||
serialized, err := claim.Serialized()
|
||||
func (c *ClaimHelper) SerializedHexString() (string, error) {
|
||||
serialized, err := c.Serialized()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
@ -45,19 +45,19 @@ func (claim *ClaimHelper) SerializedHexString() (string, error) {
|
|||
return serialized_hex, nil
|
||||
}
|
||||
|
||||
func (claim *ClaimHelper) SerializedNoSignature() ([]byte, error) {
|
||||
if claim.String() == "" {
|
||||
func (c *ClaimHelper) SerializedNoSignature() ([]byte, error) {
|
||||
if c.String() == "" {
|
||||
return nil, errors.New("not initialized")
|
||||
}
|
||||
if claim.GetPublisherSignature() == nil {
|
||||
serialized, err := claim.Serialized()
|
||||
if c.GetPublisherSignature() == nil {
|
||||
serialized, err := c.Serialized()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return serialized, nil
|
||||
} else {
|
||||
clone := &pb.Claim{}
|
||||
proto.Merge(clone, claim.GetProtobuf())
|
||||
proto.Merge(clone, c.GetProtobuf())
|
||||
proto.ClearAllExtensions(clone.PublisherSignature)
|
||||
clone.PublisherSignature = nil
|
||||
return proto.Marshal(clone)
|
||||
|
|
|
@ -35,8 +35,8 @@ func GetClaimSignatureDigest(claimAddress [25]byte, certificateId [20]byte, seri
|
|||
return [32]byte(digest)
|
||||
}
|
||||
|
||||
func (claim *ClaimHelper) GetCertificatePublicKey() (*btcec.PublicKey, error) {
|
||||
derBytes := claim.GetCertificate().GetPublicKey()
|
||||
func (c *ClaimHelper) GetCertificatePublicKey() (*btcec.PublicKey, error) {
|
||||
derBytes := c.GetCertificate().GetPublicKey()
|
||||
pub := publicKeyInfo{}
|
||||
asn1.Unmarshal(derBytes, &pub)
|
||||
pubkey_bytes := []byte(pub.PublicKey.Bytes)
|
||||
|
@ -47,13 +47,13 @@ func (claim *ClaimHelper) GetCertificatePublicKey() (*btcec.PublicKey, error) {
|
|||
return p, err
|
||||
}
|
||||
|
||||
func (claim *ClaimHelper) VerifyDigest(certificate *ClaimHelper, signature [64]byte, digest [32]byte) bool {
|
||||
func (c *ClaimHelper) VerifyDigest(certificate *ClaimHelper, signature [64]byte, digest [32]byte) bool {
|
||||
public_key, err := certificate.GetCertificatePublicKey()
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
if claim.PublisherSignature.SignatureType.String() == SECP256k1 {
|
||||
if c.PublisherSignature.SignatureType.String() == SECP256k1 {
|
||||
R := &big.Int{}
|
||||
S := &big.Int{}
|
||||
R.SetBytes(signature[0:32])
|
||||
|
@ -63,8 +63,8 @@ func (claim *ClaimHelper) VerifyDigest(certificate *ClaimHelper, signature [64]b
|
|||
return false
|
||||
}
|
||||
|
||||
func (claim *ClaimHelper) ValidateClaimSignatureBytes(certificate *ClaimHelper, claimAddress [25]byte, certificateId [20]byte, blockchainName string) (bool, error) {
|
||||
signature := claim.GetPublisherSignature()
|
||||
func (c *ClaimHelper) ValidateClaimSignatureBytes(certificate *ClaimHelper, claimAddress [25]byte, certificateId [20]byte, blockchainName string) (bool, error) {
|
||||
signature := c.GetPublisherSignature()
|
||||
if signature == nil {
|
||||
return false, errors.New("claim does not have a signature")
|
||||
}
|
||||
|
@ -79,16 +79,16 @@ func (claim *ClaimHelper) ValidateClaimSignatureBytes(certificate *ClaimHelper,
|
|||
return false, errors.New("invalid address")
|
||||
}
|
||||
|
||||
serializedNoSig, err := claim.SerializedNoSignature()
|
||||
serializedNoSig, err := c.SerializedNoSignature()
|
||||
if err != nil {
|
||||
return false, errors.New("serialization error")
|
||||
}
|
||||
|
||||
claimDigest := GetClaimSignatureDigest(claimAddress, certificateId, serializedNoSig)
|
||||
return claim.VerifyDigest(certificate, signatureBytes, claimDigest), nil
|
||||
return c.VerifyDigest(certificate, signatureBytes, claimDigest), nil
|
||||
}
|
||||
|
||||
func (claim *ClaimHelper) ValidateClaimSignature(certificate *ClaimHelper, claimAddress string, certificateId string, blockchainName string) (bool, error) {
|
||||
func (c *ClaimHelper) ValidateClaimSignature(certificate *ClaimHelper, claimAddress string, certificateId string, blockchainName string) (bool, error) {
|
||||
addressBytes, err := address.DecodeAddress(claimAddress, blockchainName)
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
@ -101,5 +101,5 @@ func (claim *ClaimHelper) ValidateClaimSignature(certificate *ClaimHelper, claim
|
|||
for i := range certificateIdBytes {
|
||||
certificateIdBytes[i] = certificateIdSlice[i]
|
||||
}
|
||||
return claim.ValidateClaimSignatureBytes(certificate, addressBytes, certificateIdBytes, blockchainName)
|
||||
return c.ValidateClaimSignatureBytes(certificate, addressBytes, certificateIdBytes, blockchainName)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue