From 1e4d57ab83a7751f54cdb51d91e4750d591baa16 Mon Sep 17 00:00:00 2001 From: Oleg Silkin Date: Wed, 24 Jul 2019 15:47:23 -0400 Subject: [PATCH] Simplifies signing function into one to make API symmetric --- lbry/lbry/extras/daemon/Daemon.py | 4 ++-- lbry/lbry/extras/daemon/comment_client.py | 13 ++----------- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/lbry/lbry/extras/daemon/Daemon.py b/lbry/lbry/extras/daemon/Daemon.py index 0d5e6efd4..5ae145fb6 100644 --- a/lbry/lbry/extras/daemon/Daemon.py +++ b/lbry/lbry/extras/daemon/Daemon.py @@ -33,7 +33,7 @@ from lbry.extras.daemon.Components import EXCHANGE_RATE_MANAGER_COMPONENT, UPNP_ from lbry.extras.daemon.ComponentManager import RequiredCondition from lbry.extras.daemon.ComponentManager import ComponentManager from lbry.extras.daemon.json_response_encoder import JSONResponseEncoder -from lbry.extras.daemon.comment_client import jsonrpc_post, sign_comment, sign_abandon_comment +from lbry.extras.daemon.comment_client import jsonrpc_post, sign_comment from lbry.extras.daemon.comment_client import is_comment_signed_by_channel from lbry.extras.daemon.undecorated import undecorated from lbry.wallet.transaction import Transaction, Output, Input @@ -3521,7 +3521,7 @@ class Daemon(metaclass=JSONRPCServerType): 'channel_id': channel.claim_id, 'channel_name': channel.claim_name, }) - sign_abandon_comment(abandon_comment_body, channel) + sign_comment(abandon_comment_body, channel, signing_field='comment_id') resp = await jsonrpc_post(self.conf.comment_server, 'delete_comment', abandon_comment_body) return {comment_id: resp} diff --git a/lbry/lbry/extras/daemon/comment_client.py b/lbry/lbry/extras/daemon/comment_client.py index 71b473dc7..900369f24 100644 --- a/lbry/lbry/extras/daemon/comment_client.py +++ b/lbry/lbry/extras/daemon/comment_client.py @@ -36,9 +36,9 @@ def is_comment_signed_by_channel(comment: dict, channel: Output): return False -def sign_comment(comment: dict, channel: Output): +def sign_comment(comment: dict, channel: Output, signing_field='comment'): timestamp = str(int(time.time())).encode() - pieces = [timestamp, channel.claim_hash, comment['comment'].encode()] + pieces = [timestamp, channel.claim_hash, comment[signing_field].encode()] digest = sha256(b''.join(pieces)) signature = channel.private_key.sign_digest_deterministic(digest, hashfunc=hashlib.sha256) comment.update({ @@ -47,15 +47,6 @@ def sign_comment(comment: dict, channel: Output): }) -def sign_abandon_comment(body: dict, channel: Output): - pieces = [body['comment_id'].encode(), channel.claim_hash] - digest = sha256(b''.join(pieces)) - signature = channel.private_key.sign_digest_deterministic(digest, hashfunc=hashlib.sha256) - body.update({ - 'signature': binascii.hexlify(signature).decode() - }) - - async def jsonrpc_post(url: str, method: str, params: dict = None, **kwargs) -> any: params = dict() if not params else params params.update(kwargs)