Polkadot tx-wrapper 离线签名
Polkadot tx-wrapper offline signing
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使用随机签名,所以结果不会相同,但长度应该相同。
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使用随机签名,所以结果不会相同,但长度应该相同。