Signing cleanups (w/ additional tests) (#1134)

This commit is contained in:
Jaco Greeff
2019-07-16 12:12:17 +02:00
committed by GitHub
parent c34ca9c36f
commit 9b15a373d3
3 changed files with 112 additions and 91 deletions
+10 -3
View File
@@ -12,8 +12,11 @@ let id = 0;
export default class SingleAccountSigner {
private keyringPair: KeyringPair;
public constructor (keyringPair: KeyringPair) {
private signDelay: number;
public constructor (keyringPair: KeyringPair, signDelay: number = 0) {
this.keyringPair = keyringPair;
this.signDelay = signDelay;
}
public async sign (extrinsic: Extrinsic, address: string, options: SignatureOptions): Promise<number> {
@@ -21,8 +24,12 @@ export default class SingleAccountSigner {
throw new Error('does not have the keyringPair');
}
extrinsic.sign(this.keyringPair, options);
return new Promise((resolve): void => {
setTimeout((): void => {
extrinsic.sign(this.keyringPair, options);
return ++id;
resolve(++id);
}, this.signDelay);
});
}
}