Simplifies signing function into one to make API symmetric

This commit is contained in:
Oleg Silkin 2019-07-24 15:47:23 -04:00 committed by Lex Berezhny
parent 49b42b7e03
commit 1e4d57ab83
2 changed files with 4 additions and 13 deletions

View file

@ -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}

View file

@ -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)