fix str/bytes confusion from resolve/claimdict on certificate_id

This commit is contained in:
Victor Shyba 2019-01-17 23:37:37 -03:00 committed by Lex Berezhny
parent b707ee4844
commit be6448b74f
3 changed files with 10 additions and 17 deletions

View file

@ -155,8 +155,8 @@ class Resolver:
certificate = None
certificate_id = smart_decode(claim_result['value']).certificate_id
if certificate_id:
certificate = await self.network.get_claims_by_ids(certificate_id.decode())
certificate = certificate.pop(certificate_id.decode()) if certificate else None
certificate = await self.network.get_claims_by_ids(certificate_id)
certificate = certificate.pop(certificate_id) if certificate else None
return await self.parse_and_validate_claim_result(claim_result, certificate=certificate)
async def parse_and_validate_claim_result(self, claim_result, certificate=None, raw=False):
@ -180,7 +180,7 @@ class Resolver:
if decoded.has_signature:
if certificate is None:
log.info("fetching certificate to check claim signature")
certificate = await self.network.get_claims_by_ids(decoded.certificate_id.decode())
certificate = await self.network.get_claims_by_ids(decoded.certificate_id)
if not certificate:
log.warning('Certificate %s not found', decoded.certificate_id)
claim_result['has_signature'] = True
@ -308,17 +308,10 @@ def format_amount_value(obj):
def _get_permanent_url(claim_result, certificate_id):
if claim_result.get('has_signature') and claim_result.get('channel_name'):
return "{}#{}/{}".format(
claim_result['channel_name'],
certificate_id,
claim_result['name']
)
if certificate_id:
return f"{claim_result['channel_name']}#{certificate_id}/{claim_result['name']}"
else:
return "{}#{}".format(
claim_result['name'],
claim_result['claim_id']
)
return f"{claim_result['name']}#{claim_result['claim_id']}"
def _verify_proof(name, claim_trie_root, result, height, depth, transaction_class, hash160_to_address):

View file

@ -92,11 +92,11 @@ class ClaimDict(OrderedDict):
return None
@property
def certificate_id(self):
def certificate_id(self) -> str:
if self.protobuf.HasField("publisherSignature"):
return binascii.hexlify(self.protobuf.publisherSignature.certificateId)
return binascii.hexlify(self.protobuf.publisherSignature.certificateId).decode()
if self.detached_signature and self.detached_signature.certificate_id:
return binascii.hexlify(self.detached_signature.certificate_id)
return binascii.hexlify(self.detached_signature.certificate_id).decode()
@property
def signature(self):

View file

@ -346,7 +346,7 @@ class TestDetachedNamedSECP256k1Signatures(UnitTest):
curve=SECP256k1, name='example', force_detached=True)
self.assertEqual(
signed.claim_dict['publisherSignature']['detached_signature'],
binascii.hexlify(signed.serialized)
binascii.hexlify(signed.serialized).decode()
)
signed_copy = ClaimDict.load_dict(signed.claim_dict)
self.assertEqual(signed_copy.validate_signature(claim_address_2, cert, name='example'), True)