Extrinsic v2 (#1150)

* Extrinsic v2

* Save after last move of files

* Signature V2

* Rework signature decoding

* Simplify V1 and V2 underlying impl.

* Detect chain extrinsic version

* SignaturePayload

* remove Raw payload variant link (Payload is now raw)

* Remove v2 comments referring to v1 data

* Pass isSigned to Extrinsic{V1, V2}

* Cleanup era injection

* It flows :)

* Add SignerPayload and signPayload for Signer (#1152)

* Add SignerPayload and signPayload for Signer

* Submittables use signPayload

* Don't pass version on deprecated interface

* Update after all e2e tx tests passes

* Comment around payload generation

* Adjust blocktime to default (nice round 50 block eras)

* Fix calc

* Re-add test comment

* Update packages/api/src/types.ts

Co-Authored-By: Amaury Martiny <amaury.martiny@protonmail.com>

* Update packages/types/src/primitive/BalanceCompact.ts

Co-Authored-By: Amaury Martiny <amaury.martiny@protonmail.com>

* Backwards compatibility for current in-store signers

* Apply options suggestions

* Add missing Compact params (linting)
This commit is contained in:
Jaco Greeff
2019-07-22 17:08:06 +02:00
committed by GitHub
co-authored by Amaury Martiny
parent ed0979a50c
commit 50a2314544
45 changed files with 1843 additions and 956 deletions
+23 -7
View File
@@ -2,14 +2,14 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { Signer, SignerPayload, SignerResult } from '@polkadot/api/types';
import { KeyringPair } from '@polkadot/keyring/types';
import { SignatureOptions } from '@polkadot/types/types';
import { Extrinsic } from '@polkadot/types';
import { SignaturePayload } from '@polkadot/types';
let id = 0;
export default class SingleAccountSigner {
export default class SingleAccountSigner implements Signer {
private keyringPair: KeyringPair;
private signDelay: number;
@@ -19,16 +19,32 @@ export default class SingleAccountSigner {
this.signDelay = signDelay;
}
public async sign (extrinsic: Extrinsic, address: string, options: SignatureOptions): Promise<number> {
if (!this.keyringPair || String(address) !== this.keyringPair.address) {
// @deprecated Kept here until we have it removed completely
// public async sign (extrinsic: IExtrinsic, address: string, options: SignatureOptions): Promise<number> {
// if (!this.keyringPair || String(address) !== this.keyringPair.address) {
// throw new Error('does not have the keyringPair');
// }
// return new Promise((resolve): void => {
// setTimeout((): void => {
// extrinsic.sign(this.keyringPair, options);
// resolve(++id);
// }, this.signDelay);
// });
// }
public async signPayload (payload: SignerPayload): Promise<SignerResult> {
if (!this.keyringPair || payload.address !== this.keyringPair.address) {
throw new Error('does not have the keyringPair');
}
return new Promise((resolve): void => {
setTimeout((): void => {
extrinsic.sign(this.keyringPair, options);
const signed = new SignaturePayload(payload, { version: payload.version }).sign(this.keyringPair);
const result: SignerResult = { id: ++id, ...signed };
resolve(++id);
resolve(result);
}, this.signDelay);
});
}