Revert "Add signExtrinsic on the Signer interface (#2912)"
This reverts commit a9e8388cc8.
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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<SubmittableExtrinsic<'rxjs'>> =>
|
||||
@@ -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<SubmittableExtrinsic<'rxjs'>> =>
|
||||
|
||||
@@ -288,19 +288,12 @@ export function createClass <ApiType extends ApiTypes> ({ 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
|
||||
|
||||
@@ -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<SignerResult> {
|
||||
assert(address === this.#keyringPair.address, 'Signer does not have the keyringPair');
|
||||
public async signPayload (payload: SignerPayloadJSON): Promise<SignerResult> {
|
||||
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);
|
||||
});
|
||||
|
||||
@@ -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<SignerResult>;
|
||||
|
||||
/**
|
||||
* @deprecated Use signExtrinsic instead
|
||||
* @description signs an extrinsic payload from a serialized form
|
||||
*/
|
||||
signPayload?: (payload: SignerPayloadJSON) => Promise<SignerResult>;
|
||||
|
||||
Reference in New Issue
Block a user