dedot 0.0.1-alpha.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +245 -0
  3. package/cjs/client/Dedot.js +444 -0
  4. package/cjs/client/index.js +17 -0
  5. package/cjs/executor/ConstantExecutor.js +22 -0
  6. package/cjs/executor/ErrorExecutor.js +47 -0
  7. package/cjs/executor/EventExecutor.js +53 -0
  8. package/cjs/executor/Executor.js +39 -0
  9. package/cjs/executor/RpcExecutor.js +109 -0
  10. package/cjs/executor/RuntimeApiExecutor.js +93 -0
  11. package/cjs/executor/StorageQueryExecutor.js +33 -0
  12. package/cjs/executor/TxExecutor.js +153 -0
  13. package/cjs/executor/index.js +24 -0
  14. package/cjs/extrinsic/SubmittableResult.js +33 -0
  15. package/cjs/extrinsic/extensions/ExtraSignedExtension.js +65 -0
  16. package/cjs/extrinsic/extensions/SignedExtension.js +41 -0
  17. package/cjs/extrinsic/extensions/index.js +19 -0
  18. package/cjs/extrinsic/extensions/known/ChargeAssetTxPayment.js +44 -0
  19. package/cjs/extrinsic/extensions/known/ChargeTransactionPayment.js +16 -0
  20. package/cjs/extrinsic/extensions/known/CheckGenesis.js +19 -0
  21. package/cjs/extrinsic/extensions/known/CheckMortality.js +71 -0
  22. package/cjs/extrinsic/extensions/known/CheckNonZeroSender.js +10 -0
  23. package/cjs/extrinsic/extensions/known/CheckNonce.js +34 -0
  24. package/cjs/extrinsic/extensions/known/CheckSpecVersion.js +19 -0
  25. package/cjs/extrinsic/extensions/known/CheckTxVersion.js +19 -0
  26. package/cjs/extrinsic/extensions/known/CheckWeight.js +10 -0
  27. package/cjs/extrinsic/extensions/known/PrevalidateAttests.js +11 -0
  28. package/cjs/extrinsic/extensions/known/index.js +25 -0
  29. package/cjs/extrinsic/index.js +18 -0
  30. package/cjs/index.js +25 -0
  31. package/cjs/package.json +1 -0
  32. package/cjs/packageInfo.js +5 -0
  33. package/cjs/proxychain.js +20 -0
  34. package/cjs/storage/QueryableStorage.js +99 -0
  35. package/cjs/types.js +2 -0
  36. package/client/Dedot.d.ts +181 -0
  37. package/client/Dedot.js +440 -0
  38. package/client/index.d.ts +1 -0
  39. package/client/index.js +1 -0
  40. package/executor/ConstantExecutor.d.ts +11 -0
  41. package/executor/ConstantExecutor.js +18 -0
  42. package/executor/ErrorExecutor.d.ts +11 -0
  43. package/executor/ErrorExecutor.js +43 -0
  44. package/executor/EventExecutor.d.ts +11 -0
  45. package/executor/EventExecutor.js +49 -0
  46. package/executor/Executor.d.ts +150 -0
  47. package/executor/Executor.js +35 -0
  48. package/executor/RpcExecutor.d.ts +14 -0
  49. package/executor/RpcExecutor.js +105 -0
  50. package/executor/RuntimeApiExecutor.d.ts +9 -0
  51. package/executor/RuntimeApiExecutor.js +89 -0
  52. package/executor/StorageQueryExecutor.d.ts +10 -0
  53. package/executor/StorageQueryExecutor.js +29 -0
  54. package/executor/TxExecutor.d.ts +47 -0
  55. package/executor/TxExecutor.js +147 -0
  56. package/executor/index.d.ts +8 -0
  57. package/executor/index.js +8 -0
  58. package/extrinsic/SubmittableResult.d.ts +19 -0
  59. package/extrinsic/SubmittableResult.js +29 -0
  60. package/extrinsic/extensions/ExtraSignedExtension.d.ts +14 -0
  61. package/extrinsic/extensions/ExtraSignedExtension.js +61 -0
  62. package/extrinsic/extensions/SignedExtension.d.ts +40 -0
  63. package/extrinsic/extensions/SignedExtension.js +37 -0
  64. package/extrinsic/extensions/index.d.ts +3 -0
  65. package/extrinsic/extensions/index.js +3 -0
  66. package/extrinsic/extensions/known/ChargeAssetTxPayment.d.ts +14 -0
  67. package/extrinsic/extensions/known/ChargeAssetTxPayment.js +40 -0
  68. package/extrinsic/extensions/known/ChargeTransactionPayment.d.ts +6 -0
  69. package/extrinsic/extensions/known/ChargeTransactionPayment.js +12 -0
  70. package/extrinsic/extensions/known/CheckGenesis.d.ts +10 -0
  71. package/extrinsic/extensions/known/CheckGenesis.js +15 -0
  72. package/extrinsic/extensions/known/CheckMortality.d.ts +15 -0
  73. package/extrinsic/extensions/known/CheckMortality.js +67 -0
  74. package/extrinsic/extensions/known/CheckNonZeroSender.d.ts +6 -0
  75. package/extrinsic/extensions/known/CheckNonZeroSender.js +6 -0
  76. package/extrinsic/extensions/known/CheckNonce.d.ts +10 -0
  77. package/extrinsic/extensions/known/CheckNonce.js +30 -0
  78. package/extrinsic/extensions/known/CheckSpecVersion.d.ts +9 -0
  79. package/extrinsic/extensions/known/CheckSpecVersion.js +15 -0
  80. package/extrinsic/extensions/known/CheckTxVersion.d.ts +9 -0
  81. package/extrinsic/extensions/known/CheckTxVersion.js +15 -0
  82. package/extrinsic/extensions/known/CheckWeight.d.ts +6 -0
  83. package/extrinsic/extensions/known/CheckWeight.js +6 -0
  84. package/extrinsic/extensions/known/PrevalidateAttests.d.ts +7 -0
  85. package/extrinsic/extensions/known/PrevalidateAttests.js +7 -0
  86. package/extrinsic/extensions/known/index.d.ts +3 -0
  87. package/extrinsic/extensions/known/index.js +22 -0
  88. package/extrinsic/index.d.ts +2 -0
  89. package/extrinsic/index.js +2 -0
  90. package/index.d.ts +6 -0
  91. package/index.js +5 -0
  92. package/package.json +54 -0
  93. package/packageInfo.d.ts +4 -0
  94. package/packageInfo.js +3 -0
  95. package/proxychain.d.ts +7 -0
  96. package/proxychain.js +16 -0
  97. package/storage/QueryableStorage.d.ts +16 -0
  98. package/storage/QueryableStorage.js +95 -0
  99. package/types.d.ts +44 -0
  100. package/types.js +1 -0
@@ -0,0 +1,19 @@
1
+ import { IEventRecord, ISubmittableResult } from '@dedot/types';
2
+ import { DispatchError, DispatchInfo, Hash, TransactionStatus } from '@dedot/codecs';
3
+ import { FrameSystemEventRecord } from '@dedot/chaintypes/substrate';
4
+ export interface SubmittableResultInputs<E extends IEventRecord = FrameSystemEventRecord> {
5
+ events?: E[];
6
+ status: TransactionStatus;
7
+ txHash: Hash;
8
+ txIndex?: number;
9
+ }
10
+ export declare class SubmittableResult<E extends IEventRecord = FrameSystemEventRecord> implements ISubmittableResult<E> {
11
+ #private;
12
+ dispatchInfo?: DispatchInfo;
13
+ dispatchError?: DispatchError;
14
+ events: E[];
15
+ status: TransactionStatus;
16
+ txHash: Hash;
17
+ txIndex?: number;
18
+ constructor({ events, status, txHash, txIndex }: SubmittableResultInputs<E>);
19
+ }
@@ -0,0 +1,29 @@
1
+ export class SubmittableResult {
2
+ dispatchInfo;
3
+ dispatchError;
4
+ events;
5
+ status;
6
+ txHash;
7
+ txIndex;
8
+ constructor({ events, status, txHash, txIndex }) {
9
+ this.events = events || [];
10
+ this.status = status;
11
+ this.txHash = txHash;
12
+ this.txIndex = txIndex;
13
+ [this.dispatchInfo, this.dispatchError] = this.#extractInfo();
14
+ }
15
+ #extractInfo() {
16
+ for (const { event } of this.events) {
17
+ const { pallet, palletEvent } = event;
18
+ if (pallet === 'System' && palletEvent.name === 'ExtrinsicFailed') {
19
+ const { dispatchInfo, dispatchError } = palletEvent.data;
20
+ return [dispatchInfo, dispatchError];
21
+ }
22
+ else if (pallet === 'System' && palletEvent.name === 'ExtrinsicSuccess') {
23
+ const { dispatchInfo } = palletEvent.data;
24
+ return [dispatchInfo, undefined];
25
+ }
26
+ }
27
+ return [undefined, undefined];
28
+ }
29
+ }
@@ -0,0 +1,14 @@
1
+ import { SignedExtension } from './SignedExtension';
2
+ import { HexString } from '@dedot/utils';
3
+ import * as $ from '@dedot/shape';
4
+ import { SignerPayloadJSON, SignerPayloadRaw } from '@polkadot/types/types';
5
+ export declare class ExtraSignedExtension extends SignedExtension<any[], any[]> {
6
+ #private;
7
+ init(): Promise<void>;
8
+ get identifier(): string;
9
+ get dataCodec(): $.AnyShape;
10
+ get additionalSignedCodec(): $.AnyShape;
11
+ get payloadCodec(): $.AnyShape;
12
+ toPayload(call?: HexString): SignerPayloadJSON;
13
+ toRawPayload(call?: HexString): SignerPayloadRaw;
14
+ }
@@ -0,0 +1,61 @@
1
+ import { SignedExtension } from './SignedExtension';
2
+ import { assert, ensurePresence } from '@dedot/utils';
3
+ import * as $ from '@dedot/shape';
4
+ import { knownSignedExtensions } from './known';
5
+ import { objectSpread, u8aToHex } from '@polkadot/util';
6
+ export class ExtraSignedExtension extends SignedExtension {
7
+ #signedExtensions;
8
+ async init() {
9
+ this.#signedExtensions = this.#getSignedExtensions();
10
+ await Promise.all(this.#signedExtensions.map((se) => se.init()));
11
+ this.data = this.#signedExtensions.map((se) => se.data);
12
+ this.additionalSigned = this.#signedExtensions.map((se) => se.additionalSigned);
13
+ }
14
+ get identifier() {
15
+ return 'ExtraSignedExtension';
16
+ }
17
+ get dataCodec() {
18
+ const { extraTypeId } = this.api.metadataLatest.extrinsic;
19
+ return ensurePresence(this.registry.findPortableCodec(extraTypeId));
20
+ }
21
+ get additionalSignedCodec() {
22
+ const $AdditionalSignedCodecs = this.#signedExtensionDefs.map((se) => this.registry.findPortableCodec(se.additionalSigned));
23
+ return $.Tuple(...$AdditionalSignedCodecs);
24
+ }
25
+ get payloadCodec() {
26
+ const { callTypeId } = this.api.metadataLatest.extrinsic;
27
+ const $Call = this.registry.findPortableCodec(callTypeId);
28
+ return $.Tuple($Call, this.dataCodec, this.additionalSignedCodec);
29
+ }
30
+ get #signedExtensionDefs() {
31
+ return this.api.metadataLatest.extrinsic.signedExtensions;
32
+ }
33
+ #getSignedExtensions() {
34
+ return this.#signedExtensionDefs.map((extDef) => {
35
+ const { signedExtensions: userSignedExtensions = {} } = this.api.options;
36
+ const Extension = userSignedExtensions[extDef.ident] ||
37
+ knownSignedExtensions[extDef.ident];
38
+ assert(Extension, `SignedExtension for ${extDef.ident} not found`);
39
+ return new Extension(this.api, {
40
+ ...ensurePresence(this.options),
41
+ def: extDef,
42
+ });
43
+ });
44
+ }
45
+ toPayload(call = '0x') {
46
+ const signedExtensions = this.#signedExtensions.map((se) => se.identifier);
47
+ const { version } = this.api.registry.metadata.extrinsic;
48
+ return objectSpread({ address: this.options.signerAddress, signedExtensions, version, method: call }, ...this.#signedExtensions.map((se) => se.toPayload()));
49
+ }
50
+ toRawPayload(call = '0x') {
51
+ const payload = this.toPayload(call);
52
+ const $ToSignPayload = $.Tuple($.RawHex, this.dataCodec, this.additionalSignedCodec);
53
+ const toSignPayload = [call, this.data, this.additionalSigned];
54
+ const rawPayload = $ToSignPayload.tryEncode(toSignPayload);
55
+ return {
56
+ address: payload.address,
57
+ data: u8aToHex(rawPayload),
58
+ type: 'payload',
59
+ };
60
+ }
61
+ }
@@ -0,0 +1,40 @@
1
+ import { Dedot } from '../../client';
2
+ import { CodecRegistry, SignedExtensionDefLatest } from '@dedot/codecs';
3
+ import * as $ from '@dedot/shape';
4
+ import { PayloadOptions } from '@dedot/types';
5
+ import { SignerPayloadJSON } from '@polkadot/types/types';
6
+ export interface ISignedExtension {
7
+ identifier: string;
8
+ dataCodec: $.AnyShape;
9
+ additionalSignedCodec: $.AnyShape;
10
+ data: any;
11
+ additionalSigned: any;
12
+ init(): Promise<void>;
13
+ registry: CodecRegistry;
14
+ toPayload(...additional: any[]): Partial<SignerPayloadJSON>;
15
+ }
16
+ interface SignedExtensionOptions {
17
+ def?: SignedExtensionDefLatest;
18
+ signerAddress?: string;
19
+ payloadOptions?: Partial<PayloadOptions>;
20
+ }
21
+ export declare abstract class SignedExtension<Data extends any = {}, AdditionalSigned extends any = []> implements ISignedExtension {
22
+ api: Dedot;
23
+ options?: SignedExtensionOptions | undefined;
24
+ data: Data;
25
+ additionalSigned: AdditionalSigned;
26
+ constructor(api: Dedot, options?: SignedExtensionOptions | undefined);
27
+ init(): Promise<void>;
28
+ get identifier(): string;
29
+ get dataCodec(): $.AnyShape;
30
+ get additionalSignedCodec(): $.AnyShape;
31
+ get registry(): CodecRegistry;
32
+ get signedExtensionDef(): {
33
+ ident: string;
34
+ typeId: number;
35
+ additionalSigned: number;
36
+ };
37
+ get payloadOptions(): Partial<PayloadOptions>;
38
+ toPayload(...args: any[]): Partial<SignerPayloadJSON>;
39
+ }
40
+ export {};
@@ -0,0 +1,37 @@
1
+ import { ensurePresence } from '@dedot/utils';
2
+ export class SignedExtension {
3
+ api;
4
+ options;
5
+ data;
6
+ additionalSigned;
7
+ constructor(api, options) {
8
+ this.api = api;
9
+ this.options = options;
10
+ this.data = {};
11
+ this.additionalSigned = [];
12
+ }
13
+ async init() {
14
+ // TODO implement this method
15
+ }
16
+ get identifier() {
17
+ return this.signedExtensionDef.ident;
18
+ }
19
+ get dataCodec() {
20
+ return ensurePresence(this.api.registry.findPortableCodec(this.signedExtensionDef.typeId));
21
+ }
22
+ get additionalSignedCodec() {
23
+ return ensurePresence(this.api.registry.findPortableCodec(this.signedExtensionDef.additionalSigned));
24
+ }
25
+ get registry() {
26
+ return this.api.registry;
27
+ }
28
+ get signedExtensionDef() {
29
+ return ensurePresence(this.options.def);
30
+ }
31
+ get payloadOptions() {
32
+ return this.options?.payloadOptions || {};
33
+ }
34
+ toPayload(...args) {
35
+ return {};
36
+ }
37
+ }
@@ -0,0 +1,3 @@
1
+ export * from './SignedExtension';
2
+ export * from './known';
3
+ export * from './ExtraSignedExtension';
@@ -0,0 +1,3 @@
1
+ export * from './SignedExtension';
2
+ export * from './known';
3
+ export * from './ExtraSignedExtension';
@@ -0,0 +1,14 @@
1
+ import { SignedExtension } from '../SignedExtension';
2
+ import { SignerPayloadJSON } from '@polkadot/types/types';
3
+ /**
4
+ * @name ChargeAssetTxPayment
5
+ */
6
+ export declare class ChargeAssetTxPayment extends SignedExtension<{
7
+ tip: bigint;
8
+ assetId?: number | object;
9
+ }> {
10
+ #private;
11
+ init(): Promise<void>;
12
+ toPayload(): Partial<SignerPayloadJSON>;
13
+ $AssetId(): any;
14
+ }
@@ -0,0 +1,40 @@
1
+ import { SignedExtension } from '../SignedExtension';
2
+ import { bnToHex, u8aToHex } from '@polkadot/util';
3
+ import { assert } from '@dedot/utils';
4
+ /**
5
+ * @name ChargeAssetTxPayment
6
+ */
7
+ export class ChargeAssetTxPayment extends SignedExtension {
8
+ async init() {
9
+ const { tip, assetId } = this.payloadOptions;
10
+ this.data = {
11
+ tip: tip || 0n,
12
+ assetId,
13
+ };
14
+ }
15
+ toPayload() {
16
+ const { tip, assetId } = this.data;
17
+ return {
18
+ tip: bnToHex(tip, { isLe: false }),
19
+ // @ts-ignore
20
+ assetId: this.#encodeAssetId(assetId),
21
+ };
22
+ }
23
+ #encodeAssetId(assetId) {
24
+ if (assetId === null || assetId === undefined) {
25
+ return undefined;
26
+ }
27
+ return u8aToHex(this.$AssetId().tryEncode(assetId));
28
+ }
29
+ $AssetId() {
30
+ const extensionTypeDef = this.registry.findPortableType(this.signedExtensionDef.typeId);
31
+ assert(extensionTypeDef.type.tag === 'Struct');
32
+ const assetIdTypeDef = extensionTypeDef.type.value.fields.find((f) => f.name === 'asset_id');
33
+ const $codec = this.registry.findPortableCodec(assetIdTypeDef.typeId);
34
+ const codecMetadata = $codec.metadata[0];
35
+ if (codecMetadata.name === '$.option') {
36
+ return codecMetadata.args[0]; // inner shape
37
+ }
38
+ return $codec;
39
+ }
40
+ }
@@ -0,0 +1,6 @@
1
+ import { SignedExtension } from '../SignedExtension';
2
+ import { SignerPayloadJSON } from '@polkadot/types/types';
3
+ export declare class ChargeTransactionPayment extends SignedExtension<bigint> {
4
+ init(): Promise<void>;
5
+ toPayload(): Partial<SignerPayloadJSON>;
6
+ }
@@ -0,0 +1,12 @@
1
+ import { SignedExtension } from '../SignedExtension';
2
+ import { bnToHex } from '@polkadot/util';
3
+ export class ChargeTransactionPayment extends SignedExtension {
4
+ async init() {
5
+ this.data = this.payloadOptions.tip || 0n;
6
+ }
7
+ toPayload() {
8
+ return {
9
+ tip: bnToHex(this.data, { isLe: false }),
10
+ };
11
+ }
12
+ }
@@ -0,0 +1,10 @@
1
+ import { SignedExtension } from '../SignedExtension';
2
+ import { Hash } from '@dedot/codecs';
3
+ import { SignerPayloadJSON } from '@polkadot/types/types';
4
+ /**
5
+ * @description Genesis hash check to provide replay protection between different networks.
6
+ */
7
+ export declare class CheckGenesis extends SignedExtension<{}, Hash> {
8
+ init(): Promise<void>;
9
+ toPayload(): Partial<SignerPayloadJSON>;
10
+ }
@@ -0,0 +1,15 @@
1
+ import { SignedExtension } from '../SignedExtension';
2
+ import { ensurePresence } from '@dedot/utils';
3
+ /**
4
+ * @description Genesis hash check to provide replay protection between different networks.
5
+ */
6
+ export class CheckGenesis extends SignedExtension {
7
+ async init() {
8
+ this.additionalSigned = ensurePresence(this.api.genesisHash);
9
+ }
10
+ toPayload() {
11
+ return {
12
+ genesisHash: this.additionalSigned,
13
+ };
14
+ }
15
+ }
@@ -0,0 +1,15 @@
1
+ import { SignedExtension } from '../SignedExtension';
2
+ import { EraLike, Hash } from '@dedot/codecs';
3
+ import { SignerPayloadJSON } from '@polkadot/types/types';
4
+ export declare const MAX_FINALITY_LAG: number;
5
+ export declare const FALLBACK_MAX_HASH_COUNT: number;
6
+ export declare const FALLBACK_PERIOD: number;
7
+ export declare const MORTAL_PERIOD: number;
8
+ /**
9
+ * @description Check for transaction mortality.
10
+ */
11
+ export declare class CheckMortality extends SignedExtension<EraLike, Hash> {
12
+ #private;
13
+ init(): Promise<void>;
14
+ toPayload(): Partial<SignerPayloadJSON>;
15
+ }
@@ -0,0 +1,67 @@
1
+ import { SignedExtension } from '../SignedExtension';
2
+ import { assert, isZeroHash, min } from '@dedot/utils';
3
+ import { numberToHex, u8aToHex } from '@polkadot/util';
4
+ export const MAX_FINALITY_LAG = 5;
5
+ export const FALLBACK_MAX_HASH_COUNT = 250;
6
+ export const FALLBACK_PERIOD = 6 * 1000;
7
+ export const MORTAL_PERIOD = 5 * 60 * 1000;
8
+ /**
9
+ * @description Check for transaction mortality.
10
+ */
11
+ export class CheckMortality extends SignedExtension {
12
+ #signingHeader;
13
+ async init() {
14
+ this.#signingHeader = await this.#determineSigningHeader();
15
+ this.data = { period: this.#calculateMortalLength(), current: BigInt(this.#signingHeader.number) };
16
+ this.additionalSigned = (await this.api.rpc.chain.getBlockHash(this.#signingHeader.number));
17
+ }
18
+ // Ref: https://github.com/polkadot-js/api/blob/3bdf49b0428a62f16b3222b9a31bfefa43c1ca55/packages/api-derive/src/tx/signingInfo.ts#L34-L64
19
+ async #determineSigningHeader() {
20
+ const [header, finalizedHash] = await Promise.all([
21
+ this.api.rpc.chain.getHeader(),
22
+ this.api.rpc.chain.getFinalizedHead(),
23
+ ]);
24
+ assert(header, 'Current header not found');
25
+ const [currentHeader, finalizedHeader] = await Promise.all([
26
+ Promise.resolve(header).then((header) => {
27
+ const { parentHash } = header;
28
+ if (parentHash.length === 0 || isZeroHash(parentHash)) {
29
+ return header;
30
+ }
31
+ else {
32
+ return this.api.rpc.chain.getHeader(parentHash);
33
+ }
34
+ }),
35
+ this.api.rpc.chain.getHeader(finalizedHash),
36
+ ]);
37
+ assert(currentHeader, 'Cannot determine current header');
38
+ if (!finalizedHeader || currentHeader.number - finalizedHeader.number > MAX_FINALITY_LAG) {
39
+ return currentHeader;
40
+ }
41
+ return finalizedHeader;
42
+ }
43
+ // Ref: https://github.com/polkadot-js/api/blob/3bdf49b0428a62f16b3222b9a31bfefa43c1ca55/packages/api-derive/src/tx/signingInfo.ts#L83-L93
44
+ #calculateMortalLength() {
45
+ return min(BigInt(this.#getConst('system', 'blockHashCount') || FALLBACK_MAX_HASH_COUNT), BigInt(MORTAL_PERIOD) /
46
+ BigInt(this.#getConst('babe', 'expectedBlockTime') ||
47
+ BigInt(this.#getConst('timestamp', 'minimumPeriod') || 0) * 2n ||
48
+ FALLBACK_PERIOD) +
49
+ BigInt(MAX_FINALITY_LAG));
50
+ }
51
+ #getConst(pallet, name) {
52
+ try {
53
+ return this.api.consts[pallet][name];
54
+ }
55
+ catch {
56
+ // ignore this on purpose
57
+ }
58
+ return undefined;
59
+ }
60
+ toPayload() {
61
+ return {
62
+ era: u8aToHex(this.dataCodec.tryEncode(this.data)),
63
+ blockHash: this.additionalSigned,
64
+ blockNumber: numberToHex(this.#signingHeader.number),
65
+ };
66
+ }
67
+ }
@@ -0,0 +1,6 @@
1
+ import { SignedExtension } from '../SignedExtension';
2
+ /**
3
+ * @description Check to ensure that the sender is not the zero address
4
+ */
5
+ export declare class CheckNonZeroSender extends SignedExtension {
6
+ }
@@ -0,0 +1,6 @@
1
+ import { SignedExtension } from '../SignedExtension';
2
+ /**
3
+ * @description Check to ensure that the sender is not the zero address
4
+ */
5
+ export class CheckNonZeroSender extends SignedExtension {
6
+ }
@@ -0,0 +1,10 @@
1
+ import { SignedExtension } from '../SignedExtension';
2
+ import { SignerPayloadJSON } from '@polkadot/types/types';
3
+ /**
4
+ * @description Nonce check and increment to give replay protection for transactions.
5
+ */
6
+ export declare class CheckNonce extends SignedExtension<number> {
7
+ #private;
8
+ init(): Promise<void>;
9
+ toPayload(): Partial<SignerPayloadJSON>;
10
+ }
@@ -0,0 +1,30 @@
1
+ import { SignedExtension } from '../SignedExtension';
2
+ import { numberToHex } from '@polkadot/util';
3
+ import { assert } from '@dedot/utils';
4
+ /**
5
+ * @description Nonce check and increment to give replay protection for transactions.
6
+ */
7
+ export class CheckNonce extends SignedExtension {
8
+ async init() {
9
+ this.data = this.payloadOptions.nonce || (await this.#getNonce());
10
+ }
11
+ async #getNonce() {
12
+ const { signerAddress } = this.options || {};
13
+ assert(signerAddress, 'Signer address not found');
14
+ try {
15
+ return (await this.api.query.system.account(signerAddress)).nonce;
16
+ }
17
+ catch { }
18
+ try {
19
+ return await this.api.call.accountNonceApi.accountNonce(signerAddress);
20
+ }
21
+ catch { }
22
+ // TODO fallback to api.rpc.system.accountNextIndex if needed
23
+ return 0;
24
+ }
25
+ toPayload() {
26
+ return {
27
+ nonce: numberToHex(this.data),
28
+ };
29
+ }
30
+ }
@@ -0,0 +1,9 @@
1
+ import { SignedExtension } from '../SignedExtension';
2
+ import { SignerPayloadJSON } from '@polkadot/types/types';
3
+ /**
4
+ * @description Ensure the runtime version registered in the transaction is the same as at present.
5
+ */
6
+ export declare class CheckSpecVersion extends SignedExtension<{}, number> {
7
+ init(): Promise<void>;
8
+ toPayload(): Partial<SignerPayloadJSON>;
9
+ }
@@ -0,0 +1,15 @@
1
+ import { SignedExtension } from '../SignedExtension';
2
+ import { numberToHex } from '@polkadot/util';
3
+ /**
4
+ * @description Ensure the runtime version registered in the transaction is the same as at present.
5
+ */
6
+ export class CheckSpecVersion extends SignedExtension {
7
+ async init() {
8
+ this.additionalSigned = this.api.runtimeVersion.specVersion;
9
+ }
10
+ toPayload() {
11
+ return {
12
+ specVersion: numberToHex(this.additionalSigned),
13
+ };
14
+ }
15
+ }
@@ -0,0 +1,9 @@
1
+ import { SignedExtension } from '../SignedExtension';
2
+ import { SignerPayloadJSON } from '@polkadot/types/types';
3
+ /**
4
+ * @description Ensure the transaction version registered in the transaction is the same as at present.
5
+ */
6
+ export declare class CheckTxVersion extends SignedExtension<{}, number> {
7
+ init(): Promise<void>;
8
+ toPayload(): Partial<SignerPayloadJSON>;
9
+ }
@@ -0,0 +1,15 @@
1
+ import { SignedExtension } from '../SignedExtension';
2
+ import { numberToHex } from '@polkadot/util';
3
+ /**
4
+ * @description Ensure the transaction version registered in the transaction is the same as at present.
5
+ */
6
+ export class CheckTxVersion extends SignedExtension {
7
+ async init() {
8
+ this.additionalSigned = this.api.runtimeVersion.transactionVersion;
9
+ }
10
+ toPayload() {
11
+ return {
12
+ transactionVersion: numberToHex(this.additionalSigned),
13
+ };
14
+ }
15
+ }
@@ -0,0 +1,6 @@
1
+ import { SignedExtension } from '../SignedExtension';
2
+ /**
3
+ * @description Block resource (weight) limit check.
4
+ */
5
+ export declare class CheckWeight extends SignedExtension {
6
+ }
@@ -0,0 +1,6 @@
1
+ import { SignedExtension } from '../SignedExtension';
2
+ /**
3
+ * @description Block resource (weight) limit check.
4
+ */
5
+ export class CheckWeight extends SignedExtension {
6
+ }
@@ -0,0 +1,7 @@
1
+ import { SignedExtension } from '../SignedExtension';
2
+ /**
3
+ * @description Validate `attest` calls prior to execution.
4
+ * Needed to avoid a DoS attack since they are otherwise free to place on chain.
5
+ */
6
+ export declare class PrevalidateAttests extends SignedExtension {
7
+ }
@@ -0,0 +1,7 @@
1
+ import { SignedExtension } from '../SignedExtension';
2
+ /**
3
+ * @description Validate `attest` calls prior to execution.
4
+ * Needed to avoid a DoS attack since they are otherwise free to place on chain.
5
+ */
6
+ export class PrevalidateAttests extends SignedExtension {
7
+ }
@@ -0,0 +1,3 @@
1
+ import { ISignedExtension } from '../SignedExtension';
2
+ export type AnySignedExtension = new (...args: any[]) => ISignedExtension;
3
+ export declare const knownSignedExtensions: Record<string, AnySignedExtension>;
@@ -0,0 +1,22 @@
1
+ import { CheckNonZeroSender } from './CheckNonZeroSender';
2
+ import { CheckSpecVersion } from './CheckSpecVersion';
3
+ import { CheckTxVersion } from './CheckTxVersion';
4
+ import { CheckGenesis } from './CheckGenesis';
5
+ import { CheckMortality } from './CheckMortality';
6
+ import { CheckNonce } from './CheckNonce';
7
+ import { CheckWeight } from './CheckWeight';
8
+ import { ChargeTransactionPayment } from './ChargeTransactionPayment';
9
+ import { PrevalidateAttests } from './PrevalidateAttests';
10
+ import { ChargeAssetTxPayment } from './ChargeAssetTxPayment';
11
+ export const knownSignedExtensions = {
12
+ CheckNonZeroSender,
13
+ CheckSpecVersion,
14
+ CheckTxVersion,
15
+ CheckGenesis,
16
+ CheckMortality,
17
+ CheckNonce,
18
+ CheckWeight,
19
+ ChargeTransactionPayment,
20
+ PrevalidateAttests,
21
+ ChargeAssetTxPayment,
22
+ };
@@ -0,0 +1,2 @@
1
+ export * from './extensions';
2
+ export * from './SubmittableResult';
@@ -0,0 +1,2 @@
1
+ export * from './extensions';
2
+ export * from './SubmittableResult';
package/index.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import { Dedot } from './client';
2
+ export type * from './types';
3
+ export * from './executor';
4
+ export * from './extrinsic';
5
+ export { Dedot };
6
+ export { HttpProvider, ScProvider, WsProvider } from '@polkadot/rpc-provider';
package/index.js ADDED
@@ -0,0 +1,5 @@
1
+ import { Dedot } from './client';
2
+ export * from './executor';
3
+ export * from './extrinsic';
4
+ export { Dedot };
5
+ export { HttpProvider, ScProvider, WsProvider } from '@polkadot/rpc-provider';