fixes from review

This commit is contained in:
Victor Shyba 2019-01-17 21:24:24 -03:00 committed by Lex Berezhny
parent 68b56b7858
commit 0e9888be3b
2 changed files with 9 additions and 10 deletions

View file

@ -39,7 +39,7 @@ class ClaimDict(OrderedDict):
@property
def serialized(self):
"""Serialized Claim protobuf"""
if self.detached_signature and self.detached_signature.payload:
if self.detached_signature:
return self.detached_signature.serialized
return self.protobuf.SerializeToString()
@ -52,10 +52,9 @@ class ClaimDict(OrderedDict):
@property
def has_signature(self):
claim = self.protobuf
if claim.HasField("publisherSignature"):
return True
return self.detached_signature and self.detached_signature.certificate_id
return self.protobuf.HasField("publisherSignature") or (
self.detached_signature and self.detached_signature.raw_signature
)
@property
def is_certificate(self):
@ -94,11 +93,10 @@ class ClaimDict(OrderedDict):
@property
def certificate_id(self):
if self.protobuf.HasField("publisherSignature"):
return binascii.hexlify(self.protobuf.publisherSignature.certificateId)
if self.detached_signature and self.detached_signature.certificate_id:
return binascii.hexlify(self.detached_signature.certificate_id)
if not self.has_signature:
return None
return binascii.hexlify(self.protobuf.publisherSignature.certificateId)
@property
def signature(self):

View file

@ -1,5 +1,7 @@
from collections import namedtuple
from typing import Union
LEGACY = namedtuple('Legacy', 'payload')
NAMED_SECP256K1 = namedtuple('NamedSECP256k1', 'raw_signature certificate_id payload')
FLAGS = {
@ -9,8 +11,7 @@ FLAGS = {
class Signature:
def __init__(self, data: namedtuple):
assert isinstance(data, (LEGACY, NAMED_SECP256K1))
def __init__(self, data: Union[LEGACY, NAMED_SECP256K1]):
self.data = data
@property