Skip to content

Signing payload is not the actually signing payload #472

@MoMannn

Description

@MoMannn

In the polkadot examples for creating a raw transaction we have this line:

const signingPayload1 = construct.signingPayload(unsigned, { registry });

If we try and actually sign this payload via:

  const signature = await pair.sign(hexToU8a(signingPayload), {
    withType: true,
  });

The signature will be invalid. This is because this is not the actual signing payload.

If we go further by the code we can also do:

const signingPayload2 = registry
      .createType("ExtrinsicPayload", payload, {
        version: payload.version,
      })
      .toHex()

Which will return the same as payload above but its still not the actual raw payload we need to sign.

Doing:

 const signingPayload3 = u8aToHex(
      registry
        .createType("ExtrinsicPayload", payload, {
          version: payload.version,
        })
        .toU8a(true)
    )

Is what the actual signing payload is.

From my example the return of the above where:

signingPayload1: 0xa4040300fe747dadf0f62c7d1bac6988a156fdd41cf2d14ccfdc15e289512a7073bbf2660700e40b540295020c0000a9840f001b000000e143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e71e97c702816bfef0025cf7d067ec52fb8d345a5cbf2e69b81f7196ae80781bb00
signingPayload2: 0xa4040300fe747dadf0f62c7d1bac6988a156fdd41cf2d14ccfdc15e289512a7073bbf2660700e40b540295020c0000a9840f001b000000e143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e71e97c702816bfef0025cf7d067ec52fb8d345a5cbf2e69b81f7196ae80781bb00
signingPayload3: 0x040300fe747dadf0f62c7d1bac6988a156fdd41cf2d14ccfdc15e289512a7073bbf2660700e40b540295020c0000a9840f001b000000e143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e71e97c702816bfef0025cf7d067ec52fb8d345a5cbf2e69b81f7196ae80781bb00

Basically in first and second case 1 byte was added at the begining: a4.

Why is that? Why is it not documented anywhere? The naming is also extremely misleading when you are trying to actually generate and sign a raw extrinsic.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions