From ded9a84a919a536d0e51d27726179b1acd042163 Mon Sep 17 00:00:00 2001 From: clangenb <37865735+clangenb@users.noreply.github.com> Date: Sat, 3 Feb 2024 14:59:08 +0100 Subject: [PATCH] fix signing payloads > 256 bytes (#419) * fix signing payloads > 256 bytes * fmt --- packages/polkadart/lib/extrinsic/signing_payload.dart | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/polkadart/lib/extrinsic/signing_payload.dart b/packages/polkadart/lib/extrinsic/signing_payload.dart index 742be4a1..fa69f05e 100644 --- a/packages/polkadart/lib/extrinsic/signing_payload.dart +++ b/packages/polkadart/lib/extrinsic/signing_payload.dart @@ -1,6 +1,7 @@ import 'dart:typed_data'; import 'package:convert/convert.dart'; +import 'package:polkadart/polkadart.dart'; import 'package:polkadart/extrinsic/signed_extensions/signed_extensions_abstract.dart'; import 'package:polkadart/scale_codec.dart'; import 'package:polkadart/substrate/era.dart'; @@ -88,7 +89,12 @@ class SigningPayload { final String addExtra = additionalExtras.join(); final String payload = method + extra + addExtra; - return Uint8List.fromList(hex.decode(payload)); + final payloadEncoded = Uint8List.fromList(hex.decode(payload)); + + // See rust code: https://github.com/paritytech/polkadot-sdk/blob/e349fc9ef8354eea1bafc1040c20d6fe3189e1ec/substrate/primitives/runtime/src/generic/unchecked_extrinsic.rs#L253 + return payloadEncoded.length > 256 + ? Blake2bHasher(32).hash(payloadEncoded) + : payloadEncoded; } bool _usesChargeAssetTxPayment(dynamic registry) {