diff --git a/packages/api/src/promise/index.spec.ts b/packages/api/src/promise/index.spec.ts index b3c913e136..266dc20db0 100644 --- a/packages/api/src/promise/index.spec.ts +++ b/packages/api/src/promise/index.spec.ts @@ -36,7 +36,7 @@ describe('ApiPromise', (): void => { ] }; - const signer = new SingleAccountSigner(aliceEd); + const signer = new SingleAccountSigner(registry, aliceEd); const api = await ApiPromise.create({ provider, registry, signer }); const transfer = api.tx.balances.transfer(keyring.getPair('0xe659a7a1628cdd93febc04a4e0646ea20e9f5f0ce097d9a05290d4a9e054df4e').address, 321564789876512345n); @@ -121,7 +121,7 @@ describe('ApiPromise', (): void => { const api = new ApiPromise({ provider, registry, - signer: new SingleAccountSigner(aliceEd) + signer: new SingleAccountSigner(registry, aliceEd) }); expect( diff --git a/packages/api/src/rx/index.spec.ts b/packages/api/src/rx/index.spec.ts index e690f2a92c..7f25734fcd 100644 --- a/packages/api/src/rx/index.spec.ts +++ b/packages/api/src/rx/index.spec.ts @@ -24,7 +24,7 @@ describe('ApiRx', (): void => { describe('decorator.signAsync', (): void => { it('signs a transfer using an external signer', (): void => { - const signer = new SingleAccountSigner(keyring.alice_session); + const signer = new SingleAccountSigner(registry, keyring.alice_session); ApiRx.create({ provider, registry, signer }).pipe( switchMap((api: ApiRx): Observable> => @@ -41,7 +41,7 @@ describe('ApiRx', (): void => { }); it('allows the second argument to signAsync to be omitted', () => { - const signer = new SingleAccountSigner(keyring.alice_session); + const signer = new SingleAccountSigner(registry, keyring.alice_session); ApiRx.create({ provider, registry, signer }).pipe( switchMap((api: ApiRx): Observable> => diff --git a/packages/api/src/submittable/createClass.ts b/packages/api/src/submittable/createClass.ts index 2cd528bd5e..357eca7db4 100644 --- a/packages/api/src/submittable/createClass.ts +++ b/packages/api/src/submittable/createClass.ts @@ -288,19 +288,12 @@ export function createClass ({ api, apiType, decorate }); let result: SignerResult; - if (signer.signExtrinsic) { - const json = payload.toPayload(); - - result = await signer.signExtrinsic( - json.address, - this.registry.createType('ExtrinsicPayload', json, { version: json.version }) - ); - } else if (signer.signPayload) { + if (signer.signPayload) { result = await signer.signPayload(payload.toPayload()); } else if (signer.signRaw) { result = await signer.signRaw(payload.toRaw()); } else { - throw new Error('Invalid signer interface, it should implement one of sgnExtrinsic, signPayload or signRaw (or all)'); + throw new Error('Invalid signer interface, it should implement either signPayload or signRaw (or both)'); } // Here we explicitly call `toPayload()` again instead of working with an object diff --git a/packages/api/test/util/SingleAccountSigner.ts b/packages/api/test/util/SingleAccountSigner.ts index 4b79dd37a5..aaa93d5a52 100644 --- a/packages/api/test/util/SingleAccountSigner.ts +++ b/packages/api/test/util/SingleAccountSigner.ts @@ -3,8 +3,7 @@ import type { Signer, SignerResult } from '@polkadot/api/types'; import type { KeyringPair } from '@polkadot/keyring/types'; -import type { ExtrinsicPayload } from '@polkadot/types/interfaces'; -import type { SignerPayloadRaw } from '@polkadot/types/types'; +import type { Registry, SignerPayloadJSON, SignerPayloadRaw } from '@polkadot/types/types'; import { assert, hexToU8a, u8aToHex } from '@polkadot/util'; @@ -13,21 +12,26 @@ let id = 0; export class SingleAccountSigner implements Signer { readonly #keyringPair: KeyringPair; + readonly #registry: Registry; + readonly #signDelay: number; - constructor (keyringPair: KeyringPair, signDelay = 0) { + constructor (registry: Registry, keyringPair: KeyringPair, signDelay = 0) { this.#keyringPair = keyringPair; + this.#registry = registry; this.#signDelay = signDelay; } - public async signExtrinsic (address: string, payload: ExtrinsicPayload): Promise { - assert(address === this.#keyringPair.address, 'Signer does not have the keyringPair'); + public async signPayload (payload: SignerPayloadJSON): Promise { + assert(payload.address === this.#keyringPair.address, 'Signer does not have the keyringPair'); return new Promise((resolve): void => { setTimeout((): void => { + const signed = this.#registry.createType('ExtrinsicPayload', payload, { version: payload.version }).sign(this.#keyringPair); + resolve({ - ...payload.sign(this.#keyringPair), - id: ++id + id: ++id, + ...signed }); }, this.#signDelay); }); diff --git a/packages/types/src/types/extrinsic.ts b/packages/types/src/types/extrinsic.ts index 705e52d1c7..2cff15a27b 100644 --- a/packages/types/src/types/extrinsic.ts +++ b/packages/types/src/types/extrinsic.ts @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import { ExtrinsicStatus } from '../interfaces/author'; -import { EcdsaSignature, Ed25519Signature, ExtrinsicPayload, Sr25519Signature } from '../interfaces/extrinsics'; +import { EcdsaSignature, Ed25519Signature, Sr25519Signature } from '../interfaces/extrinsics'; import { Address, Balance, Call, H256, Index } from '../interfaces/runtime'; import { EventRecord } from '../interfaces/system'; import { Codec } from './codec'; @@ -128,12 +128,6 @@ export interface SignerResult { export interface Signer { /** - * @description signs an extrinsic payload - */ - signExtrinsic?: (address: string, payload: ExtrinsicPayload) => Promise; - - /** - * @deprecated Use signExtrinsic instead * @description signs an extrinsic payload from a serialized form */ signPayload?: (payload: SignerPayloadJSON) => Promise;