diff --git a/packages/types/src/create/registry.ts b/packages/types/src/create/registry.ts index c5f6b62cd9..215502716b 100644 --- a/packages/types/src/create/registry.ts +++ b/packages/types/src/create/registry.ts @@ -93,10 +93,10 @@ export class TypeRegistry implements Registry { #chainProperties?: ChainProperties; - #metadataExtensions: string[] = defaultExtensions; - #knownTypes: RegisteredTypes = {}; + #signedExtensions: string[] = defaultExtensions; + constructor () { // we only want to import these on creation, i.e. we want to avoid types // weird side-effects from circular references. (Since registry is injected @@ -136,7 +136,7 @@ export class TypeRegistry implements Registry { } public get signedExtensions (): string[] { - return this.#metadataExtensions; + return this.#signedExtensions; } /** @@ -240,11 +240,11 @@ export class TypeRegistry implements Registry { } public getSignedExtensionExtra (): Record { - return expandExtensionTypes(this.#metadataExtensions, 'extra'); + return expandExtensionTypes(this.#signedExtensions, 'extra'); } public getSignedExtensionTypes (): Record { - return expandExtensionTypes(this.#metadataExtensions, 'types'); + return expandExtensionTypes(this.#signedExtensions, 'types'); } public hasClass (name: string): boolean { @@ -326,10 +326,10 @@ export class TypeRegistry implements Registry { } // sets the available signed extensions - setSignedExtensions (signedExtensions: string[]): void { - this.#metadataExtensions = signedExtensions; + setSignedExtensions (signedExtensions: string[] = defaultExtensions): void { + this.#signedExtensions = signedExtensions; - const unknown = findUnknownExtensions(this.#metadataExtensions); + const unknown = findUnknownExtensions(this.#signedExtensions); if (unknown.length) { console.warn(`Unknown signed extensions ${unknown.join(', ')} found, treating them as no-efect`); diff --git a/packages/types/src/extrinsic/SignerPayload.spec.ts b/packages/types/src/extrinsic/SignerPayload.spec.ts index 476de5921a..a882d7e961 100644 --- a/packages/types/src/extrinsic/SignerPayload.spec.ts +++ b/packages/types/src/extrinsic/SignerPayload.spec.ts @@ -22,6 +22,7 @@ describe('SignerPayload', (): void => { genesisHash: '0xdcd1346701ca8396496e52aa2785b1748deb6db09551b72159dcb3e08991025b', method: '0x0600ffd7568e5f0a7eda67a82691ff379ac4bba4f9c9b859fe779b5d46363b61ad2db9e56c', nonce: '0x00001234', + signedExtensions: ['CheckNonce', 'CheckWeight'], specVersion: '0x00000006', tip: '0x00000000000000000000000000005678', transactionVersion: '0x00000007', @@ -38,6 +39,7 @@ describe('SignerPayload', (): void => { genesisHash: '0xdcd1346701ca8396496e52aa2785b1748deb6db09551b72159dcb3e08991025b', method: registry.createType('Call', '0x0600ffd7568e5f0a7eda67a82691ff379ac4bba4f9c9b859fe779b5d46363b61ad2db9e56c'), nonce: 0x1234, + signedExtensions: ['CheckNonce'], tip: 0x5678, version: 3 }).toPayload() @@ -49,6 +51,7 @@ describe('SignerPayload', (): void => { genesisHash: '0xdcd1346701ca8396496e52aa2785b1748deb6db09551b72159dcb3e08991025b', method: '0x0600ffd7568e5f0a7eda67a82691ff379ac4bba4f9c9b859fe779b5d46363b61ad2db9e56c', nonce: '0x00001234', + signedExtensions: ['CheckNonce'], specVersion: '0x00000000', tip: '0x00000000000000000000000000005678', transactionVersion: '0x00000000', @@ -58,7 +61,10 @@ describe('SignerPayload', (): void => { it('re-constructs from JSON', (): void => { expect( - new SignerPayload(registry, { ...TEST, runtimeVersion: { specVersion: 0x06, transactionVersion: 0x07 } }).toPayload() + new SignerPayload(registry, { + ...TEST, + runtimeVersion: { specVersion: 0x06, transactionVersion: 0x07 } + }).toPayload() ).toEqual(TEST); }); @@ -66,7 +72,10 @@ describe('SignerPayload', (): void => { expect( new SignerPayload( registry, - new SignerPayload(registry, { ...TEST, runtimeVersion: { specVersion: 0x06, transactionVersion: 0x07 } }) + new SignerPayload(registry, { + ...TEST, + runtimeVersion: { specVersion: 0x06, transactionVersion: 0x07 } + }) ).toPayload() ).toEqual(TEST); }); diff --git a/packages/types/src/extrinsic/SignerPayload.ts b/packages/types/src/extrinsic/SignerPayload.ts index 7443e58691..2ed8ef85a9 100644 --- a/packages/types/src/extrinsic/SignerPayload.ts +++ b/packages/types/src/extrinsic/SignerPayload.ts @@ -9,6 +9,8 @@ import { u8aToHex } from '@polkadot/util'; import Compact from '../codec/Compact'; import Struct from '../codec/Struct'; +import Vec from '../codec/Vec'; +import Text from '../primitive/Text'; import u8 from '../primitive/U8'; export interface SignerPayloadType extends Codec { @@ -20,6 +22,7 @@ export interface SignerPayloadType extends Codec { method: Call; nonce: Compact; runtimeVersion: RuntimeVersion; + signedExtensions: Vec; tip: Compact; version: u8; } @@ -35,6 +38,7 @@ const _Payload: Constructor = Struct.with({ method: 'Call', nonce: 'Compact', runtimeVersion: 'RuntimeVersion', + signedExtensions: 'Vec', tip: 'Compact', version: 'u8' }) as any; @@ -49,7 +53,7 @@ export default class SignerPayload extends _Payload implements ISignerPayload { * @description Creates an representation of the structure as an ISignerPayload JSON */ public toPayload (): SignerPayloadJSON { - const { address, blockHash, blockNumber, era, genesisHash, method, nonce, runtimeVersion: { specVersion, transactionVersion }, tip, version } = this; + const { address, blockHash, blockNumber, era, genesisHash, method, nonce, runtimeVersion: { specVersion, transactionVersion }, signedExtensions, tip, version } = this; return { address: address.toString(), @@ -59,6 +63,7 @@ export default class SignerPayload extends _Payload implements ISignerPayload { genesisHash: genesisHash.toHex(), method: method.toHex(), nonce: nonce.toHex(), + signedExtensions: signedExtensions.map((e) => e.toString()), specVersion: specVersion.toHex(), tip: tip.toHex(), transactionVersion: transactionVersion.toHex(), diff --git a/packages/types/src/types/extrinsic.ts b/packages/types/src/types/extrinsic.ts index 72f60b8383..e5c5de02d5 100644 --- a/packages/types/src/types/extrinsic.ts +++ b/packages/types/src/types/extrinsic.ts @@ -171,6 +171,11 @@ export interface SignerPayloadJSON { */ transactionVersion: string; + /** + * @description The applicable signed extensions for this runtime + */ + signedExtensions: string[]; + /** * @description The version of the extrinsic we are dealing with */ diff --git a/packages/types/src/types/registry.ts b/packages/types/src/types/registry.ts index 06e5e7c94e..481ee5b158 100644 --- a/packages/types/src/types/registry.ts +++ b/packages/types/src/types/registry.ts @@ -138,5 +138,5 @@ export interface Registry { register (arg1: string | Constructor | RegistryTypes, arg2?: Constructor): void; setChainProperties (properties?: ChainProperties): void; setMetadata (metadata: RegistryMetadata, signedExtensions?: string[]): void; - setSignedExtensions (signedExtensions: string[]): void; + setSignedExtensions (signedExtensions?: string[]): void; }