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应该具有相同的长度,但它们没有。原因是什么?
您也应该将{"withType": true}
传递给sign方法。
const s1 = u8aToHex(alice.sign(actualPayload, {"withType": true}));
sr25519使用随机性进行签名,因此结果不会相同,但它们应该具有相同的长度。