diff --git a/substrateinterface/__init__.py b/substrateinterface/__init__.py index 4802e6e..bd24409 100644 --- a/substrateinterface/__init__.py +++ b/substrateinterface/__init__.py @@ -15,6 +15,8 @@ # limitations under the License. import asyncio +from hashlib import blake2b + import binascii import json import logging @@ -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): diff --git a/test/test_create_extrinsics.py b/test/test_create_extrinsics.py index 0d494fe..e6bd3dd 100644 --- a/test/test_create_extrinsics.py +++ b/test/test_create_extrinsics.py @@ -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()