Skip to content

Commit

Permalink
Fixed incorrect signature payload for extrinsics > 256 bytes; signatu…
Browse files Browse the repository at this point in the history
…re payload should be a 32 bytes blake2b hash #49
  • Loading branch information
Arjan Zijderveld committed Nov 16, 2020
1 parent 81e935f commit 1280c0d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
5 changes: 5 additions & 0 deletions substrateinterface/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# limitations under the License.

import asyncio
from hashlib import blake2b

import binascii
import json
import logging
Expand Down Expand Up @@ -1105,6 +1107,9 @@ def generate_signature_payload(self, call, era=None, nonce=0, tip=0, include_cal

signature_payload.encode(payload_dict)

if signature_payload.data.length > 256:
return ScaleBytes(data=blake2b(signature_payload.data.data, digest_size=32).digest())

return signature_payload.data

def create_signed_extrinsic(self, call, keypair: Keypair, era=None, nonce=None, tip=0, signature=None):
Expand Down
28 changes: 28 additions & 0 deletions test/test_create_extrinsics.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,34 @@ def test_payment_info(self):

self.assertGreater(payment_info['partialFee'], 0)

def test_generate_signature_payload_lte_256_bytes(self):

call = self.kusama_substrate.compose_call(
call_module='System',
call_function='remark',
call_params={
'_remark': '0x' + ('01' * 177)
}
)

signature_payload = self.kusama_substrate.generate_signature_payload(call=call)

self.assertEqual(signature_payload.length, 256)

def test_generate_signature_payload_gt_256_bytes(self):

call = self.kusama_substrate.compose_call(
call_module='System',
call_function='remark',
call_params={
'_remark': '0x' + ('01' * 178)
}
)

signature_payload = self.kusama_substrate.generate_signature_payload(call=call)

self.assertEqual(signature_payload.length, 32)


if __name__ == '__main__':
unittest.main()

0 comments on commit 1280c0d

Please sign in to comment.