diff --git a/packages/api/src/SubmittableExtrinsic.ts b/packages/api/src/SubmittableExtrinsic.ts index 9780f11e29..7eeaa99a5b 100644 --- a/packages/api/src/SubmittableExtrinsic.ts +++ b/packages/api/src/SubmittableExtrinsic.ts @@ -4,11 +4,11 @@ import { AccountId, Address, ExtrinsicStatus, EventRecord, getTypeRegistry, Hash, Header, Index, Method, SignedBlock, Vector, ExtrinsicEra } from '@polkadot/types'; import { AnyNumber, AnyU8a, Callback, Codec, IExtrinsic, IExtrinsicEra, IKeyringPair, SignatureOptions } from '@polkadot/types/types'; -import { ApiInterface$Rx, ApiTypes, Signer } from './types'; +import { ApiInterface$Rx, ApiTypes } from './types'; import { Observable, combineLatest, of } from 'rxjs'; import { first, map, mergeMap, switchMap, tap } from 'rxjs/operators'; -import { assert, isBn, isFunction, isNumber, isUndefined } from '@polkadot/util'; +import { isBn, isFunction, isNumber, isUndefined } from '@polkadot/util'; import ApiBase from './Base'; import filterEvents from './util/filterEvents'; @@ -45,7 +45,8 @@ type SignerOptions = { }; // pick a default - in the case of 4s blocktimes, this translates to 60 seconds -const DEFAULT_MORTAL_LENGTH = 15; +const ONE_MINUTE = 15; +const DEFAULT_MORTAL_LENGTH = 5 * ONE_MINUTE; export class SubmittableResult implements ISubmittableResult { readonly events: Array; @@ -250,13 +251,13 @@ export default function createSubmittableExtrinsic ( if (isKeyringPair) { this.sign(account as IKeyringPair, { ...options, ...eraOptions, nonce }); - } else { - assert(api.signer, 'no signer exists'); - - updateId = await (api.signer as Signer).sign(_extrinsic, address, { + } else if (api.signer) { + updateId = await api.signer.sign(_extrinsic, address, { ...expandOptions({ ...options, ...eraOptions, nonce }), genesisHash: api.genesisHash }); + } else { + throw new Error('no signer exists'); } }), switchMap(() => { diff --git a/packages/types/src/type/SignaturePayload.ts b/packages/types/src/type/SignaturePayload.ts index e77cd10a21..f0f0d7e5ef 100644 --- a/packages/types/src/type/SignaturePayload.ts +++ b/packages/types/src/type/SignaturePayload.ts @@ -44,7 +44,7 @@ function sign (signerPair: IKeyringPair, u8a: Uint8Array): Uint8Array { export default class SignaturePayload extends Struct { protected _signature?: Uint8Array; - constructor (value?: SignaturePayloadValue | Uint8Array) { + public constructor (value?: SignaturePayloadValue | Uint8Array) { super({ nonce: Nonce, method: Method, @@ -56,42 +56,42 @@ export default class SignaturePayload extends Struct { /** * @description `true` if the payload refers to a valid signature */ - get isSigned (): boolean { + public get isSigned (): boolean { return !!(this._signature && this._signature.length === 64); } /** * @description The block [[Hash]] the signature applies to (mortal/immortal) */ - get blockHash (): Hash { + public get blockHash (): Hash { return this.get('blockHash') as Hash; } /** * @description The [[Method]] contained in the payload */ - get method (): Method { + public get method (): Method { return this.get('method') as Method; } /** * @description The [[ExtrinsicEra]] */ - get era (): ExtrinsicEra { + public get era (): ExtrinsicEra { return this.get('era') as ExtrinsicEra; } /** * @description The [[Nonce]] */ - get nonce (): Nonce { + public get nonce (): Nonce { return this.get('nonce') as Nonce; } /** * @description The raw signature as a `Uint8Array` */ - get signature (): Uint8Array { + public get signature (): Uint8Array { if (!this.isSigned) { throw new Error('Transaction is not signed'); } @@ -102,7 +102,7 @@ export default class SignaturePayload extends Struct { /** * @description Sign the payload with the keypair */ - sign (signerPair: IKeyringPair, version?: RuntimeVersion): Uint8Array { + public sign (signerPair: IKeyringPair, version?: RuntimeVersion): Uint8Array { this._signature = sign(signerPair, this.toU8a()); return this._signature; @@ -115,7 +115,7 @@ export default class SignaturePayload extends Struct { * A version of [[SignaturePayload]] where it does not rely on [[Method]] being initalized with metadata. When constructing, it treats the [[Method]] as a raw stream of bytes, so will always apply the signature over this without any additional checking. Unlike the [[SignaturePayload]], it assumed that you will only construct and sign, thereby providing no insigt into constructed values */ export class SignaturePayloadRaw extends Struct { - constructor (value?: any) { + public constructor (value?: any) { super({ nonce: Nonce, method: U8a, @@ -124,10 +124,17 @@ export class SignaturePayloadRaw extends Struct { }, value); } + /** + * @description The [[ExtrinsicEra]] + */ + public get era (): ExtrinsicEra { + return this.get('era') as ExtrinsicEra; + } + /** * @description Sign the payload with the keypair */ - sign (signerPair: IKeyringPair): Uint8Array { + public sign (signerPair: IKeyringPair): Uint8Array { return sign(signerPair, this.toU8a()); } }