2

具体是做什么ExtrinsicPayload的?我想复制逻辑,但缺少一些东西。

import {
    getRegistry
} from '@substrate/txwrapper-polkadot';

const registry = getRegistry({
        chainName: 'Polkadot',
        specName,
        specVersion,
        metadataRpc,
    });

const extrinsicPayload = registry.createType('ExtrinsicPayload', unsigned, {version: unsigned.version});
const extrinsicPayloadU8a = extrinsicPayload.toU8a({method: true})
const actualPayload = extrinsicPayloadU8a.length > 256 ? registry.hash(extrinsicPayloadU8a) : extrinsicPayloadU8a;

const s1 = u8aToHex(alice.sign(actualPayload));
console.log("s1", s1, s1.length);
const s2 = extrinsicPayload.sign(alice).signature;
console.log("s2", s2, s2.length);

s1 和 s2 应该具有相同的长度,但它们没有。什么原因?

4

1 回答 1

1

您也应该传递{"withType": true}给 sign 方法。

const s1 = u8aToHex(alice.sign(actualPayload, {"withType": true}));

sr25519 使用随机性进行签名,因此结果不会相同,但它们应该具有相同的长度。

于 2021-11-10T11:00:17.197 回答