@dedot/api 0.12.0 → 0.12.1-next.c7fd0a6c.2

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 (42) hide show
  1. package/cjs/extrinsic/extensions/ExtraSignedExtension.js +6 -0
  2. package/cjs/extrinsic/extensions/FallbackSignedExtension.js +4 -0
  3. package/cjs/extrinsic/extensions/SignedExtension.js +4 -1
  4. package/cjs/extrinsic/extensions/known/ChargeAssetTxPayment.js +14 -0
  5. package/cjs/extrinsic/extensions/known/ChargeTransactionPayment.js +4 -0
  6. package/cjs/extrinsic/extensions/known/CheckGenesis.js +3 -0
  7. package/cjs/extrinsic/extensions/known/CheckMetadataHash.js +12 -0
  8. package/cjs/extrinsic/extensions/known/CheckMortality.js +6 -0
  9. package/cjs/extrinsic/extensions/known/CheckNonce.js +4 -0
  10. package/cjs/extrinsic/extensions/known/CheckSpecVersion.js +4 -0
  11. package/cjs/extrinsic/extensions/known/CheckTxVersion.js +4 -0
  12. package/cjs/extrinsic/submittable/BaseSubmittableExtrinsic.js +1 -1
  13. package/cjs/extrinsic/submittable/index.js +3 -0
  14. package/cjs/extrinsic/submittable/utils.js +3 -3
  15. package/extrinsic/extensions/ExtraSignedExtension.d.ts +3 -2
  16. package/extrinsic/extensions/ExtraSignedExtension.js +6 -0
  17. package/extrinsic/extensions/FallbackSignedExtension.d.ts +2 -1
  18. package/extrinsic/extensions/FallbackSignedExtension.js +4 -0
  19. package/extrinsic/extensions/SignedExtension.d.ts +2 -0
  20. package/extrinsic/extensions/SignedExtension.js +5 -2
  21. package/extrinsic/extensions/known/ChargeAssetTxPayment.d.ts +1 -0
  22. package/extrinsic/extensions/known/ChargeAssetTxPayment.js +15 -1
  23. package/extrinsic/extensions/known/ChargeTransactionPayment.d.ts +1 -0
  24. package/extrinsic/extensions/known/ChargeTransactionPayment.js +5 -1
  25. package/extrinsic/extensions/known/CheckGenesis.d.ts +1 -0
  26. package/extrinsic/extensions/known/CheckGenesis.js +3 -0
  27. package/extrinsic/extensions/known/CheckMetadataHash.d.ts +1 -0
  28. package/extrinsic/extensions/known/CheckMetadataHash.js +12 -0
  29. package/extrinsic/extensions/known/CheckMortality.d.ts +1 -0
  30. package/extrinsic/extensions/known/CheckMortality.js +7 -1
  31. package/extrinsic/extensions/known/CheckNonce.d.ts +1 -0
  32. package/extrinsic/extensions/known/CheckNonce.js +5 -1
  33. package/extrinsic/extensions/known/CheckSpecVersion.d.ts +1 -0
  34. package/extrinsic/extensions/known/CheckSpecVersion.js +5 -1
  35. package/extrinsic/extensions/known/CheckTxVersion.d.ts +1 -0
  36. package/extrinsic/extensions/known/CheckTxVersion.js +5 -1
  37. package/extrinsic/submittable/BaseSubmittableExtrinsic.js +2 -2
  38. package/extrinsic/submittable/index.d.ts +1 -0
  39. package/extrinsic/submittable/index.js +1 -0
  40. package/extrinsic/submittable/utils.d.ts +1 -1
  41. package/extrinsic/submittable/utils.js +1 -1
  42. package/package.json +9 -9
@@ -37,6 +37,12 @@ class ExtraSignedExtension extends SignedExtension_js_1.SignedExtension {
37
37
  this.data = this.#signedExtensions.map((se) => se.data);
38
38
  this.additionalSigned = this.#signedExtensions.map((se) => se.additionalSigned);
39
39
  }
40
+ async fromPayload(payload) {
41
+ this.#signedExtensions = this.#getSignedExtensions();
42
+ await Promise.all(this.#signedExtensions.map((se) => se.fromPayload(payload)));
43
+ this.data = this.#signedExtensions.map((se) => se.data);
44
+ this.additionalSigned = this.#signedExtensions.map((se) => se.additionalSigned);
45
+ }
40
46
  get identifier() {
41
47
  return 'ExtraSignedExtension';
42
48
  }
@@ -30,6 +30,10 @@ class FallbackSignedExtension extends SignedExtension_js_1.SignedExtension {
30
30
  this.data = {};
31
31
  this.additionalSigned = [];
32
32
  }
33
+ async fromPayload(_) {
34
+ this.data = {};
35
+ this.additionalSigned = [];
36
+ }
33
37
  toPayload() {
34
38
  return {}; // No payload contribution
35
39
  }
@@ -14,7 +14,10 @@ class SignedExtension {
14
14
  this.additionalSigned = [];
15
15
  }
16
16
  async init() {
17
- // TODO implement this method
17
+ throw new utils_1.DedotError('Unimplemented');
18
+ }
19
+ async fromPayload(payload) {
20
+ throw new utils_1.DedotError('Unimplemented');
18
21
  }
19
22
  get identifier() {
20
23
  return this.signedExtensionDef.ident;
@@ -14,6 +14,13 @@ class ChargeAssetTxPayment extends SignedExtension_js_1.SignedExtension {
14
14
  assetId,
15
15
  };
16
16
  }
17
+ async fromPayload(payload) {
18
+ const { tip, assetId } = payload;
19
+ this.data = {
20
+ tip: (0, utils_1.hexToBn)(tip) || 0n,
21
+ assetId: this.#decodeAssetId(assetId),
22
+ };
23
+ }
17
24
  toPayload() {
18
25
  const { tip, assetId } = this.data;
19
26
  return {
@@ -28,6 +35,13 @@ class ChargeAssetTxPayment extends SignedExtension_js_1.SignedExtension {
28
35
  }
29
36
  return (0, utils_1.u8aToHex)(this.$AssetId().tryEncode(assetId));
30
37
  }
38
+ #decodeAssetId(assetId) {
39
+ // @ts-ignore
40
+ if (assetId === null || assetId === undefined || assetId === '' || assetId === '0x') {
41
+ return undefined;
42
+ }
43
+ return this.$AssetId().tryDecode(assetId);
44
+ }
31
45
  $AssetId() {
32
46
  const extensionTypeDef = this.registry.findType(this.signedExtensionDef.typeId);
33
47
  (0, utils_1.assert)(extensionTypeDef.typeDef.type === 'Struct');
@@ -7,6 +7,10 @@ class ChargeTransactionPayment extends SignedExtension_js_1.SignedExtension {
7
7
  async init() {
8
8
  this.data = this.payloadOptions.tip || 0n;
9
9
  }
10
+ async fromPayload(payload) {
11
+ const { tip } = payload;
12
+ this.data = (0, utils_1.hexToBn)(tip) || 0n;
13
+ }
10
14
  toPayload() {
11
15
  return {
12
16
  tip: (0, utils_1.bnToHex)(this.data),
@@ -10,6 +10,9 @@ class CheckGenesis extends SignedExtension_js_1.SignedExtension {
10
10
  async init() {
11
11
  this.additionalSigned = (0, utils_1.ensurePresence)(this.client.genesisHash);
12
12
  }
13
+ async fromPayload(payload) {
14
+ this.additionalSigned = (0, utils_1.ensurePresence)(payload.genesisHash, 'Genesis hash not found in the payload');
15
+ }
13
16
  toPayload() {
14
17
  return {
15
18
  genesisHash: this.additionalSigned,
@@ -19,6 +19,18 @@ class CheckMetadataHash extends SignedExtension_js_1.SignedExtension {
19
19
  this.additionalSigned = undefined;
20
20
  }
21
21
  }
22
+ async fromPayload(payload) {
23
+ const { mode, metadataHash } = payload;
24
+ if (mode) {
25
+ (0, utils_1.assert)((0, utils_1.isHex)(metadataHash), 'Metadata hash is not a valid hex string');
26
+ this.data = { mode: 'Enabled' };
27
+ this.additionalSigned = metadataHash;
28
+ }
29
+ else {
30
+ this.data = { mode: 'Disabled' };
31
+ this.additionalSigned = undefined;
32
+ }
33
+ }
22
34
  toPayload() {
23
35
  // Ref: https://github.com/paritytech/polkadot-sdk/blob/8dbe4ee80734bba6644c7e5f879a363ce7c0a19f/substrate/frame/metadata-hash-extension/src/lib.rs#L55-L58
24
36
  let enabled = this.data.mode === 'Enabled';
@@ -17,6 +17,12 @@ class CheckMortality extends SignedExtension_js_1.SignedExtension {
17
17
  this.data = { period: this.#calculateMortalLength(), current: BigInt(this.#signingHeader.number) };
18
18
  this.additionalSigned = this.#signingHeader.hash;
19
19
  }
20
+ async fromPayload(payload) {
21
+ const { era, blockHash, blockNumber } = payload;
22
+ this.#signingHeader = { hash: blockHash, number: (0, utils_1.hexToNumber)(blockNumber) };
23
+ this.data = this.$Data.tryDecode(era);
24
+ this.additionalSigned = blockHash;
25
+ }
20
26
  async #getSigningHeader() {
21
27
  if (this.client.rpcVersion === 'v2') {
22
28
  return this.#getSigningHeaderRpcV2();
@@ -10,6 +10,10 @@ class CheckNonce extends SignedExtension_js_1.SignedExtension {
10
10
  async init() {
11
11
  this.data = this.payloadOptions.nonce || (await this.#getNonce());
12
12
  }
13
+ async fromPayload(payload) {
14
+ const { nonce } = payload;
15
+ this.data = (0, utils_1.hexToNumber)(nonce);
16
+ }
13
17
  async #getNonce() {
14
18
  const { signerAddress } = this.options || {};
15
19
  (0, utils_1.assert)(signerAddress, 'Signer address not found');
@@ -10,6 +10,10 @@ class CheckSpecVersion extends SignedExtension_js_1.SignedExtension {
10
10
  async init() {
11
11
  this.additionalSigned = this.client.runtimeVersion.specVersion;
12
12
  }
13
+ async fromPayload(payload) {
14
+ const { specVersion } = payload;
15
+ this.additionalSigned = (0, utils_1.hexToNumber)(specVersion);
16
+ }
13
17
  toPayload() {
14
18
  return {
15
19
  specVersion: (0, utils_1.numberToHex)(this.additionalSigned),
@@ -10,6 +10,10 @@ class CheckTxVersion extends SignedExtension_js_1.SignedExtension {
10
10
  async init() {
11
11
  this.additionalSigned = this.client.runtimeVersion.transactionVersion;
12
12
  }
13
+ async fromPayload(payload) {
14
+ const { transactionVersion } = payload;
15
+ this.additionalSigned = (0, utils_1.hexToNumber)(transactionVersion);
16
+ }
13
17
  toPayload() {
14
18
  return {
15
19
  transactionVersion: (0, utils_1.numberToHex)(this.additionalSigned),
@@ -29,7 +29,7 @@ class BaseSubmittableExtrinsic extends codecs_1.Extrinsic {
29
29
  const signer = this.#getSigner(options);
30
30
  let signature, alteredTx;
31
31
  if ((0, utils_js_1.isKeyringPair)(fromAccount)) {
32
- signature = (0, utils_1.u8aToHex)((0, utils_js_1.signRaw)(fromAccount, extra.toRawPayload(this.callHex).data));
32
+ signature = (0, utils_1.u8aToHex)((0, utils_js_1.signRawMessage)(fromAccount, extra.toRawPayload(this.callHex).data));
33
33
  }
34
34
  else if (signer?.signPayload) {
35
35
  const result = await signer.signPayload(extra.toPayload(this.callHex));
@@ -14,7 +14,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.signRawMessage = void 0;
17
18
  __exportStar(require("./errors.js"), exports);
18
19
  __exportStar(require("./SubmittableResult.js"), exports);
19
20
  __exportStar(require("./SubmittableExtrinsic.js"), exports);
20
21
  __exportStar(require("./SubmittableExtrinsicV2.js"), exports);
22
+ var utils_js_1 = require("./utils.js");
23
+ Object.defineProperty(exports, "signRawMessage", { enumerable: true, get: function () { return utils_js_1.signRawMessage; } });
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.txDefer = exports.toTxStatus = exports.signRaw = exports.isKeyringPair = void 0;
3
+ exports.txDefer = exports.toTxStatus = exports.signRawMessage = exports.isKeyringPair = void 0;
4
4
  const utils_1 = require("@dedot/utils");
5
5
  const errors_js_1 = require("./errors.js");
6
6
  function isKeyringPair(account) {
@@ -12,13 +12,13 @@ exports.isKeyringPair = isKeyringPair;
12
12
  * @param signerPair
13
13
  * @param raw
14
14
  */
15
- function signRaw(signerPair, raw) {
15
+ function signRawMessage(signerPair, raw) {
16
16
  const u8a = (0, utils_1.hexToU8a)(raw);
17
17
  // Ref: https://github.com/paritytech/polkadot-sdk/blob/943697fa693a4da6ef481ef93df522accb7d0583/substrate/primitives/runtime/src/generic/unchecked_extrinsic.rs#L234-L238
18
18
  const toSignRaw = u8a.length > 256 ? (0, utils_1.blake2AsU8a)(u8a, 256) : u8a;
19
19
  return signerPair.sign(toSignRaw, { withType: true });
20
20
  }
21
- exports.signRaw = signRaw;
21
+ exports.signRawMessage = signRawMessage;
22
22
  /**
23
23
  * Convert transaction status to transaction event
24
24
  *
@@ -5,6 +5,7 @@ import { SignedExtension } from './SignedExtension.js';
5
5
  export declare class ExtraSignedExtension extends SignedExtension<any[], any[]> {
6
6
  #private;
7
7
  init(): Promise<void>;
8
+ fromPayload(payload: SignerPayloadJSON): Promise<void>;
8
9
  get identifier(): string;
9
10
  get $Data(): $.AnyShape;
10
11
  get $AdditionalSigned(): $.AnyShape;
@@ -15,6 +16,6 @@ export declare class ExtraSignedExtension extends SignedExtension<any[], any[]>
15
16
  * @returns boolean
16
17
  */
17
18
  private isRequireNoExternalInputs;
18
- toPayload(call?: HexString): SignerPayloadJSON;
19
- toRawPayload(call?: HexString): SignerPayloadRaw;
19
+ toPayload(call?: HexString | string): SignerPayloadJSON;
20
+ toRawPayload(call?: HexString | string): SignerPayloadRaw;
20
21
  }
@@ -11,6 +11,12 @@ export class ExtraSignedExtension extends SignedExtension {
11
11
  this.data = this.#signedExtensions.map((se) => se.data);
12
12
  this.additionalSigned = this.#signedExtensions.map((se) => se.additionalSigned);
13
13
  }
14
+ async fromPayload(payload) {
15
+ this.#signedExtensions = this.#getSignedExtensions();
16
+ await Promise.all(this.#signedExtensions.map((se) => se.fromPayload(payload)));
17
+ this.data = this.#signedExtensions.map((se) => se.data);
18
+ this.additionalSigned = this.#signedExtensions.map((se) => se.additionalSigned);
19
+ }
14
20
  get identifier() {
15
21
  return 'ExtraSignedExtension';
16
22
  }
@@ -1,7 +1,7 @@
1
1
  import { PortableRegistry } from '@dedot/codecs';
2
2
  import { SignerPayloadJSON } from '@dedot/types';
3
- import { SignedExtension } from './SignedExtension.js';
4
3
  import { ISubstrateClient } from '../../types.js';
4
+ import { SignedExtension } from './SignedExtension.js';
5
5
  /**
6
6
  * A fallback signed extension that can be used for extensions
7
7
  * that don't require external input.
@@ -21,6 +21,7 @@ export declare class FallbackSignedExtension extends SignedExtension {
21
21
  constructor(client: ISubstrateClient, options: any, extensionIdent: string);
22
22
  get identifier(): string;
23
23
  init(): Promise<void>;
24
+ fromPayload(_: SignerPayloadJSON): Promise<void>;
24
25
  toPayload(): Partial<SignerPayloadJSON>;
25
26
  }
26
27
  /**
@@ -27,6 +27,10 @@ export class FallbackSignedExtension extends SignedExtension {
27
27
  this.data = {};
28
28
  this.additionalSigned = [];
29
29
  }
30
+ async fromPayload(_) {
31
+ this.data = {};
32
+ this.additionalSigned = [];
33
+ }
30
34
  toPayload() {
31
35
  return {}; // No payload contribution
32
36
  }
@@ -9,6 +9,7 @@ export interface ISignedExtension {
9
9
  data: any;
10
10
  additionalSigned: any;
11
11
  init(): Promise<void>;
12
+ fromPayload(payload: SignerPayloadJSON): Promise<void>;
12
13
  registry: PortableRegistry;
13
14
  toPayload(...additional: any[]): Partial<SignerPayloadJSON>;
14
15
  }
@@ -24,6 +25,7 @@ export declare abstract class SignedExtension<Data extends any = {}, AdditionalS
24
25
  additionalSigned: AdditionalSigned;
25
26
  constructor(client: ISubstrateClient, options?: SignedExtensionOptions | undefined);
26
27
  init(): Promise<void>;
28
+ fromPayload(payload: SignerPayloadJSON): Promise<void>;
27
29
  get identifier(): string;
28
30
  get $Data(): $.AnyShape;
29
31
  get $AdditionalSigned(): $.AnyShape;
@@ -1,4 +1,4 @@
1
- import { ensurePresence } from '@dedot/utils';
1
+ import { DedotError, ensurePresence } from '@dedot/utils';
2
2
  export class SignedExtension {
3
3
  client;
4
4
  options;
@@ -11,7 +11,10 @@ export class SignedExtension {
11
11
  this.additionalSigned = [];
12
12
  }
13
13
  async init() {
14
- // TODO implement this method
14
+ throw new DedotError('Unimplemented');
15
+ }
16
+ async fromPayload(payload) {
17
+ throw new DedotError('Unimplemented');
15
18
  }
16
19
  get identifier() {
17
20
  return this.signedExtensionDef.ident;
@@ -9,6 +9,7 @@ export declare class ChargeAssetTxPayment extends SignedExtension<{
9
9
  }> {
10
10
  #private;
11
11
  init(): Promise<void>;
12
+ fromPayload(payload: SignerPayloadJSON): Promise<void>;
12
13
  toPayload(): Partial<SignerPayloadJSON>;
13
14
  $AssetId(): any;
14
15
  }
@@ -1,4 +1,4 @@
1
- import { assert, bnToHex, u8aToHex } from '@dedot/utils';
1
+ import { assert, bnToHex, hexToBn, u8aToHex } from '@dedot/utils';
2
2
  import { SignedExtension } from '../SignedExtension.js';
3
3
  /**
4
4
  * @name ChargeAssetTxPayment
@@ -11,6 +11,13 @@ export class ChargeAssetTxPayment extends SignedExtension {
11
11
  assetId,
12
12
  };
13
13
  }
14
+ async fromPayload(payload) {
15
+ const { tip, assetId } = payload;
16
+ this.data = {
17
+ tip: hexToBn(tip) || 0n,
18
+ assetId: this.#decodeAssetId(assetId),
19
+ };
20
+ }
14
21
  toPayload() {
15
22
  const { tip, assetId } = this.data;
16
23
  return {
@@ -25,6 +32,13 @@ export class ChargeAssetTxPayment extends SignedExtension {
25
32
  }
26
33
  return u8aToHex(this.$AssetId().tryEncode(assetId));
27
34
  }
35
+ #decodeAssetId(assetId) {
36
+ // @ts-ignore
37
+ if (assetId === null || assetId === undefined || assetId === '' || assetId === '0x') {
38
+ return undefined;
39
+ }
40
+ return this.$AssetId().tryDecode(assetId);
41
+ }
28
42
  $AssetId() {
29
43
  const extensionTypeDef = this.registry.findType(this.signedExtensionDef.typeId);
30
44
  assert(extensionTypeDef.typeDef.type === 'Struct');
@@ -2,5 +2,6 @@ import { SignerPayloadJSON } from '@dedot/types';
2
2
  import { SignedExtension } from '../SignedExtension.js';
3
3
  export declare class ChargeTransactionPayment extends SignedExtension<bigint> {
4
4
  init(): Promise<void>;
5
+ fromPayload(payload: SignerPayloadJSON): Promise<void>;
5
6
  toPayload(): Partial<SignerPayloadJSON>;
6
7
  }
@@ -1,9 +1,13 @@
1
- import { bnToHex } from '@dedot/utils';
1
+ import { bnToHex, hexToBn } from '@dedot/utils';
2
2
  import { SignedExtension } from '../SignedExtension.js';
3
3
  export class ChargeTransactionPayment extends SignedExtension {
4
4
  async init() {
5
5
  this.data = this.payloadOptions.tip || 0n;
6
6
  }
7
+ async fromPayload(payload) {
8
+ const { tip } = payload;
9
+ this.data = hexToBn(tip) || 0n;
10
+ }
7
11
  toPayload() {
8
12
  return {
9
13
  tip: bnToHex(this.data),
@@ -6,5 +6,6 @@ import { SignedExtension } from '../SignedExtension.js';
6
6
  */
7
7
  export declare class CheckGenesis extends SignedExtension<{}, Hash> {
8
8
  init(): Promise<void>;
9
+ fromPayload(payload: SignerPayloadJSON): Promise<void>;
9
10
  toPayload(): Partial<SignerPayloadJSON>;
10
11
  }
@@ -7,6 +7,9 @@ export class CheckGenesis extends SignedExtension {
7
7
  async init() {
8
8
  this.additionalSigned = ensurePresence(this.client.genesisHash);
9
9
  }
10
+ async fromPayload(payload) {
11
+ this.additionalSigned = ensurePresence(payload.genesisHash, 'Genesis hash not found in the payload');
12
+ }
10
13
  toPayload() {
11
14
  return {
12
15
  genesisHash: this.additionalSigned,
@@ -9,5 +9,6 @@ export declare class CheckMetadataHash extends SignedExtension<{
9
9
  mode: CheckMetadataHashMode;
10
10
  }, Hash | undefined> {
11
11
  init(): Promise<void>;
12
+ fromPayload(payload: SignerPayloadJSON): Promise<void>;
12
13
  toPayload(): Partial<SignerPayloadJSON>;
13
14
  }
@@ -16,6 +16,18 @@ export class CheckMetadataHash extends SignedExtension {
16
16
  this.additionalSigned = undefined;
17
17
  }
18
18
  }
19
+ async fromPayload(payload) {
20
+ const { mode, metadataHash } = payload;
21
+ if (mode) {
22
+ assert(isHex(metadataHash), 'Metadata hash is not a valid hex string');
23
+ this.data = { mode: 'Enabled' };
24
+ this.additionalSigned = metadataHash;
25
+ }
26
+ else {
27
+ this.data = { mode: 'Disabled' };
28
+ this.additionalSigned = undefined;
29
+ }
30
+ }
19
31
  toPayload() {
20
32
  // Ref: https://github.com/paritytech/polkadot-sdk/blob/8dbe4ee80734bba6644c7e5f879a363ce7c0a19f/substrate/frame/metadata-hash-extension/src/lib.rs#L55-L58
21
33
  let enabled = this.data.mode === 'Enabled';
@@ -11,5 +11,6 @@ export declare const MORTAL_PERIOD: number;
11
11
  export declare class CheckMortality extends SignedExtension<EraLike, Hash> {
12
12
  #private;
13
13
  init(): Promise<void>;
14
+ fromPayload(payload: SignerPayloadJSON): Promise<void>;
14
15
  toPayload(): Partial<SignerPayloadJSON>;
15
16
  }
@@ -1,4 +1,4 @@
1
- import { assert, bnMin, isZeroHex, numberToHex, u8aToHex } from '@dedot/utils';
1
+ import { assert, bnMin, hexToNumber, isZeroHex, numberToHex, u8aToHex } from '@dedot/utils';
2
2
  import { SignedExtension } from '../SignedExtension.js';
3
3
  export const MAX_FINALITY_LAG = 5;
4
4
  export const FALLBACK_MAX_HASH_COUNT = 250;
@@ -14,6 +14,12 @@ export class CheckMortality extends SignedExtension {
14
14
  this.data = { period: this.#calculateMortalLength(), current: BigInt(this.#signingHeader.number) };
15
15
  this.additionalSigned = this.#signingHeader.hash;
16
16
  }
17
+ async fromPayload(payload) {
18
+ const { era, blockHash, blockNumber } = payload;
19
+ this.#signingHeader = { hash: blockHash, number: hexToNumber(blockNumber) };
20
+ this.data = this.$Data.tryDecode(era);
21
+ this.additionalSigned = blockHash;
22
+ }
17
23
  async #getSigningHeader() {
18
24
  if (this.client.rpcVersion === 'v2') {
19
25
  return this.#getSigningHeaderRpcV2();
@@ -6,5 +6,6 @@ import { SignedExtension } from '../SignedExtension.js';
6
6
  export declare class CheckNonce extends SignedExtension<number> {
7
7
  #private;
8
8
  init(): Promise<void>;
9
+ fromPayload(payload: SignerPayloadJSON): Promise<void>;
9
10
  toPayload(): Partial<SignerPayloadJSON>;
10
11
  }
@@ -1,4 +1,4 @@
1
- import { assert, numberToHex } from '@dedot/utils';
1
+ import { assert, hexToNumber, numberToHex } from '@dedot/utils';
2
2
  import { SignedExtension } from '../SignedExtension.js';
3
3
  /**
4
4
  * @description Nonce check and increment to give replay protection for transactions.
@@ -7,6 +7,10 @@ export class CheckNonce extends SignedExtension {
7
7
  async init() {
8
8
  this.data = this.payloadOptions.nonce || (await this.#getNonce());
9
9
  }
10
+ async fromPayload(payload) {
11
+ const { nonce } = payload;
12
+ this.data = hexToNumber(nonce);
13
+ }
10
14
  async #getNonce() {
11
15
  const { signerAddress } = this.options || {};
12
16
  assert(signerAddress, 'Signer address not found');
@@ -5,5 +5,6 @@ import { SignedExtension } from '../SignedExtension.js';
5
5
  */
6
6
  export declare class CheckSpecVersion extends SignedExtension<{}, number> {
7
7
  init(): Promise<void>;
8
+ fromPayload(payload: SignerPayloadJSON): Promise<void>;
8
9
  toPayload(): Partial<SignerPayloadJSON>;
9
10
  }
@@ -1,4 +1,4 @@
1
- import { numberToHex } from '@dedot/utils';
1
+ import { hexToNumber, numberToHex } from '@dedot/utils';
2
2
  import { SignedExtension } from '../SignedExtension.js';
3
3
  /**
4
4
  * @description Ensure the runtime version registered in the transaction is the same as at present.
@@ -7,6 +7,10 @@ export class CheckSpecVersion extends SignedExtension {
7
7
  async init() {
8
8
  this.additionalSigned = this.client.runtimeVersion.specVersion;
9
9
  }
10
+ async fromPayload(payload) {
11
+ const { specVersion } = payload;
12
+ this.additionalSigned = hexToNumber(specVersion);
13
+ }
10
14
  toPayload() {
11
15
  return {
12
16
  specVersion: numberToHex(this.additionalSigned),
@@ -5,5 +5,6 @@ import { SignedExtension } from '../SignedExtension.js';
5
5
  */
6
6
  export declare class CheckTxVersion extends SignedExtension<{}, number> {
7
7
  init(): Promise<void>;
8
+ fromPayload(payload: SignerPayloadJSON): Promise<void>;
8
9
  toPayload(): Partial<SignerPayloadJSON>;
9
10
  }
@@ -1,4 +1,4 @@
1
- import { numberToHex } from '@dedot/utils';
1
+ import { hexToNumber, numberToHex } from '@dedot/utils';
2
2
  import { SignedExtension } from '../SignedExtension.js';
3
3
  /**
4
4
  * @description Ensure the transaction version registered in the transaction is the same as at present.
@@ -7,6 +7,10 @@ export class CheckTxVersion extends SignedExtension {
7
7
  async init() {
8
8
  this.additionalSigned = this.client.runtimeVersion.transactionVersion;
9
9
  }
10
+ async fromPayload(payload) {
11
+ const { transactionVersion } = payload;
12
+ this.additionalSigned = hexToNumber(transactionVersion);
13
+ }
10
14
  toPayload() {
11
15
  return {
12
16
  transactionVersion: numberToHex(this.additionalSigned),
@@ -2,7 +2,7 @@ import { Extrinsic } from '@dedot/codecs';
2
2
  import { DedotError, isFunction, toHex, u8aToHex } from '@dedot/utils';
3
3
  import { ExtraSignedExtension } from '../extensions/index.js';
4
4
  import { fakeSigner } from './fakeSigner.js';
5
- import { isKeyringPair, signRaw, txDefer } from './utils.js';
5
+ import { isKeyringPair, signRawMessage, txDefer } from './utils.js';
6
6
  export class BaseSubmittableExtrinsic extends Extrinsic {
7
7
  client;
8
8
  #alterTx;
@@ -26,7 +26,7 @@ export class BaseSubmittableExtrinsic extends Extrinsic {
26
26
  const signer = this.#getSigner(options);
27
27
  let signature, alteredTx;
28
28
  if (isKeyringPair(fromAccount)) {
29
- signature = u8aToHex(signRaw(fromAccount, extra.toRawPayload(this.callHex).data));
29
+ signature = u8aToHex(signRawMessage(fromAccount, extra.toRawPayload(this.callHex).data));
30
30
  }
31
31
  else if (signer?.signPayload) {
32
32
  const result = await signer.signPayload(extra.toPayload(this.callHex));
@@ -2,3 +2,4 @@ export * from './errors.js';
2
2
  export * from './SubmittableResult.js';
3
3
  export * from './SubmittableExtrinsic.js';
4
4
  export * from './SubmittableExtrinsicV2.js';
5
+ export { signRawMessage } from './utils.js';
@@ -2,3 +2,4 @@ export * from './errors.js';
2
2
  export * from './SubmittableResult.js';
3
3
  export * from './SubmittableExtrinsic.js';
4
4
  export * from './SubmittableExtrinsicV2.js';
5
+ export { signRawMessage } from './utils.js';
@@ -7,7 +7,7 @@ export declare function isKeyringPair(account: AddressOrPair): account is IKeyri
7
7
  * @param signerPair
8
8
  * @param raw
9
9
  */
10
- export declare function signRaw(signerPair: IKeyringPair, raw: HexString): Uint8Array;
10
+ export declare function signRawMessage(signerPair: IKeyringPair, raw: HexString | string): Uint8Array;
11
11
  type TxInfo = {
12
12
  txIndex: number;
13
13
  blockNumber: number;
@@ -8,7 +8,7 @@ export function isKeyringPair(account) {
8
8
  * @param signerPair
9
9
  * @param raw
10
10
  */
11
- export function signRaw(signerPair, raw) {
11
+ export function signRawMessage(signerPair, raw) {
12
12
  const u8a = hexToU8a(raw);
13
13
  // Ref: https://github.com/paritytech/polkadot-sdk/blob/943697fa693a4da6ef481ef93df522accb7d0583/substrate/primitives/runtime/src/generic/unchecked_extrinsic.rs#L234-L238
14
14
  const toSignRaw = u8a.length > 256 ? blake2AsU8a(u8a, 256) : u8a;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dedot/api",
3
- "version": "0.12.0",
3
+ "version": "0.12.1-next.c7fd0a6c.2+c7fd0a6c",
4
4
  "description": "A delightful JavaScript/TypeScript client for Polkadot & Substrate",
5
5
  "author": "Thang X. Vu <thang@dedot.dev>",
6
6
  "homepage": "https://dedot.dev",
@@ -13,13 +13,13 @@
13
13
  "type": "module",
14
14
  "sideEffects": false,
15
15
  "dependencies": {
16
- "@dedot/codecs": "0.12.0",
17
- "@dedot/providers": "0.12.0",
18
- "@dedot/runtime-specs": "0.12.0",
19
- "@dedot/shape": "0.12.0",
20
- "@dedot/storage": "0.12.0",
21
- "@dedot/types": "0.12.0",
22
- "@dedot/utils": "0.12.0"
16
+ "@dedot/codecs": "0.12.1-next.c7fd0a6c.2+c7fd0a6c",
17
+ "@dedot/providers": "0.12.1-next.c7fd0a6c.2+c7fd0a6c",
18
+ "@dedot/runtime-specs": "0.12.1-next.c7fd0a6c.2+c7fd0a6c",
19
+ "@dedot/shape": "0.12.1-next.c7fd0a6c.2+c7fd0a6c",
20
+ "@dedot/storage": "0.12.1-next.c7fd0a6c.2+c7fd0a6c",
21
+ "@dedot/types": "0.12.1-next.c7fd0a6c.2+c7fd0a6c",
22
+ "@dedot/utils": "0.12.1-next.c7fd0a6c.2+c7fd0a6c"
23
23
  },
24
24
  "scripts": {
25
25
  "build": "tsc --project tsconfig.build.json && tsc --project tsconfig.build.cjs.json",
@@ -48,7 +48,7 @@
48
48
  "node": ">=18"
49
49
  },
50
50
  "license": "Apache-2.0",
51
- "gitHead": "3c95d17aedae13de99f6df81068cd61905091075",
51
+ "gitHead": "c7fd0a6c35b80d78cbf6dead68b12b2820f16f0b",
52
52
  "module": "./index.js",
53
53
  "types": "./index.d.ts"
54
54
  }