Skip to content

Commit 48c6873

Browse files
committed
channel_sign command has customizeable salt
1 parent 15dc52b commit 48c6873

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

lbry/extras/daemon/daemon.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -2943,19 +2943,21 @@ async def jsonrpc_channel_update(
29432943

29442944
@requires(WALLET_COMPONENT)
29452945
async def jsonrpc_channel_sign(
2946-
self, channel_name=None, channel_id=None, hexdata=None, channel_account_id=None, wallet_id=None):
2946+
self, channel_name=None, channel_id=None, hexdata=None, salt=None,
2947+
channel_account_id=None, wallet_id=None):
29472948
"""
29482949
Signs data using the specified channel signing key.
29492950
29502951
Usage:
2951-
channel_sign [<channel_name> | --channel_name=<channel_name>]
2952-
[<channel_id> | --channel_id=<channel_id>] [<hexdata> | --hexdata=<hexdata>]
2952+
channel_sign [<channel_name> | --channel_name=<channel_name>] [<channel_id> | --channel_id=<channel_id>]
2953+
[<hexdata> | --hexdata=<hexdata>] [<salt> | --salt=<salt>]
29532954
[--channel_account_id=<channel_account_id>...] [--wallet_id=<wallet_id>]
29542955
29552956
Options:
29562957
--channel_name=<channel_name> : (str) name of channel used to sign (or use channel id)
29572958
--channel_id=<channel_id> : (str) claim id of channel used to sign (or use channel name)
29582959
--hexdata=<hexdata> : (str) data to sign, encoded as hexadecimal
2960+
--salt=<salt> : (str) salt to use for signing, default is to use timestamp
29592961
--channel_account_id=<channel_account_id>: (str) one or more account ids for accounts to look in
29602962
for channel certificates, defaults to all accounts.
29612963
--wallet_id=<wallet_id> : (str) restrict operation to specific wallet
@@ -2972,11 +2974,13 @@ async def jsonrpc_channel_sign(
29722974
signing_channel = await self.get_channel_or_error(
29732975
wallet, channel_account_id, channel_id, channel_name, for_signing=True
29742976
)
2975-
timestamp = str(int(time.time()))
2976-
signature = signing_channel.sign_data(unhexlify(str(hexdata)), timestamp)
2977+
if salt is None:
2978+
salt = str(int(time.time()))
2979+
signature = signing_channel.sign_data(unhexlify(str(hexdata)), salt)
29772980
return {
29782981
'signature': signature,
2979-
'signing_ts': timestamp
2982+
'signing_ts': salt, # DEPRECATED
2983+
'salt': salt,
29802984
}
29812985

29822986
@requires(WALLET_COMPONENT)

tests/integration/claims/test_claim_commands.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
def verify(channel, data, signature, channel_hash=None):
3333
pieces = [
34-
signature['signing_ts'].encode(),
34+
signature['salt'].encode(),
3535
channel_hash or channel.claim_hash,
3636
data
3737
]
@@ -1239,8 +1239,13 @@ async def test_sign_hex_encoded_data(self):
12391239
channel = channel_tx.outputs[0]
12401240
signature1 = await self.out(self.daemon.jsonrpc_channel_sign(channel_name='@signer', hexdata=data_to_sign))
12411241
signature2 = await self.out(self.daemon.jsonrpc_channel_sign(channel_id=channel.claim_id, hexdata=data_to_sign))
1242+
signature3 = await self.out(self.daemon.jsonrpc_channel_sign(channel_id=channel.claim_id, hexdata=data_to_sign, salt='beef'))
1243+
signature4 = await self.out(self.daemon.jsonrpc_channel_sign(channel_id=channel.claim_id, hexdata=data_to_sign, salt='beef'))
1244+
self.assertNotEqual(signature2, signature3)
1245+
self.assertEqual(signature3, signature4)
12421246
self.assertTrue(verify(channel, unhexlify(data_to_sign), signature1))
12431247
self.assertTrue(verify(channel, unhexlify(data_to_sign), signature2))
1248+
self.assertTrue(verify(channel, unhexlify(data_to_sign), signature3))
12441249
signature3 = await self.out(self.daemon.jsonrpc_channel_sign(channel_id=channel.claim_id, hexdata=99))
12451250
self.assertTrue(verify(channel, unhexlify('99'), signature3))
12461251

0 commit comments

Comments
 (0)