Add signExtrinsic on the Signer interface (#2912)
* Add signExtrinsic on the Signer interface * Unused registry
This commit is contained in:
@@ -3,7 +3,8 @@
|
||||
|
||||
import type { Signer, SignerResult } from '@polkadot/api/types';
|
||||
import type { KeyringPair } from '@polkadot/keyring/types';
|
||||
import type { Registry, SignerPayloadJSON, SignerPayloadRaw } from '@polkadot/types/types';
|
||||
import type { ExtrinsicPayload } from '@polkadot/types/interfaces';
|
||||
import type { SignerPayloadRaw } from '@polkadot/types/types';
|
||||
|
||||
import { assert, hexToU8a, u8aToHex } from '@polkadot/util';
|
||||
|
||||
@@ -12,26 +13,21 @@ let id = 0;
|
||||
export class SingleAccountSigner implements Signer {
|
||||
readonly #keyringPair: KeyringPair;
|
||||
|
||||
readonly #registry: Registry;
|
||||
|
||||
readonly #signDelay: number;
|
||||
|
||||
constructor (registry: Registry, keyringPair: KeyringPair, signDelay = 0) {
|
||||
constructor (keyringPair: KeyringPair, signDelay = 0) {
|
||||
this.#keyringPair = keyringPair;
|
||||
this.#registry = registry;
|
||||
this.#signDelay = signDelay;
|
||||
}
|
||||
|
||||
public async signPayload (payload: SignerPayloadJSON): Promise<SignerResult> {
|
||||
assert(payload.address === this.#keyringPair.address, 'Signer does not have the keyringPair');
|
||||
public async signExtrinsic (address: string, payload: ExtrinsicPayload): Promise<SignerResult> {
|
||||
assert(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({
|
||||
id: ++id,
|
||||
...signed
|
||||
...payload.sign(this.#keyringPair),
|
||||
id: ++id
|
||||
});
|
||||
}, this.#signDelay);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user