@dedot/api 0.0.1-alpha.32 → 0.0.1-alpha.34

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 (32) hide show
  1. package/chaintypes/substrate/consts.js +0 -1
  2. package/chaintypes/substrate/errors.js +0 -1
  3. package/chaintypes/substrate/events.js +0 -1
  4. package/chaintypes/substrate/index.js +0 -1
  5. package/chaintypes/substrate/json-rpc.js +0 -1
  6. package/chaintypes/substrate/query.js +0 -1
  7. package/chaintypes/substrate/runtime.js +0 -1
  8. package/chaintypes/substrate/tx.js +0 -1
  9. package/chaintypes/substrate/types.js +0 -1
  10. package/cjs/chaintypes/substrate/consts.js +0 -1
  11. package/cjs/chaintypes/substrate/errors.js +0 -1
  12. package/cjs/chaintypes/substrate/events.js +0 -1
  13. package/cjs/chaintypes/substrate/index.js +0 -1
  14. package/cjs/chaintypes/substrate/json-rpc.js +0 -1
  15. package/cjs/chaintypes/substrate/query.js +0 -1
  16. package/cjs/chaintypes/substrate/runtime.js +0 -1
  17. package/cjs/chaintypes/substrate/tx.js +0 -1
  18. package/cjs/chaintypes/substrate/types.js +0 -1
  19. package/cjs/client/{Dedot.js → LegacyClient.js} +6 -6
  20. package/cjs/client/index.js +1 -1
  21. package/cjs/executor/v2/StorageQueryExecutorV2.js +3 -3
  22. package/cjs/extrinsic/extensions/known/CheckMetadataHash.js +31 -0
  23. package/cjs/extrinsic/extensions/known/index.js +2 -0
  24. package/client/{Dedot.d.ts → LegacyClient.d.ts} +4 -4
  25. package/client/{Dedot.js → LegacyClient.js} +4 -4
  26. package/client/index.d.ts +1 -1
  27. package/client/index.js +1 -1
  28. package/executor/v2/StorageQueryExecutorV2.js +3 -3
  29. package/extrinsic/extensions/known/CheckMetadataHash.d.ts +13 -0
  30. package/extrinsic/extensions/known/CheckMetadataHash.js +27 -0
  31. package/extrinsic/extensions/known/index.js +2 -0
  32. package/package.json +10 -10
@@ -1,2 +1 @@
1
- // Generated by @dedot/codegen
2
1
  export {};
@@ -1,2 +1 @@
1
- // Generated by @dedot/codegen
2
1
  export {};
@@ -1,2 +1 @@
1
- // Generated by @dedot/codegen
2
1
  export {};
@@ -1,2 +1 @@
1
- // Generated by @dedot/codegen
2
1
  export * from './types.js';
@@ -1,2 +1 @@
1
- // Generated by @dedot/codegen
2
1
  export {};
@@ -1,2 +1 @@
1
- // Generated by @dedot/codegen
2
1
  export {};
@@ -1,2 +1 @@
1
- // Generated by @dedot/codegen
2
1
  export {};
@@ -1,2 +1 @@
1
- // Generated by @dedot/codegen
2
1
  export {};
@@ -1,2 +1 @@
1
- // Generated by @dedot/codegen
2
1
  export {};
@@ -1,3 +1,2 @@
1
1
  "use strict";
2
- // Generated by @dedot/codegen
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,3 +1,2 @@
1
1
  "use strict";
2
- // Generated by @dedot/codegen
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,3 +1,2 @@
1
1
  "use strict";
2
- // Generated by @dedot/codegen
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,5 +1,4 @@
1
1
  "use strict";
2
- // Generated by @dedot/codegen
3
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
3
  if (k2 === undefined) k2 = k;
5
4
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -1,3 +1,2 @@
1
1
  "use strict";
2
- // Generated by @dedot/codegen
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,3 +1,2 @@
1
1
  "use strict";
2
- // Generated by @dedot/codegen
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,3 +1,2 @@
1
1
  "use strict";
2
- // Generated by @dedot/codegen
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,3 +1,2 @@
1
1
  "use strict";
2
- // Generated by @dedot/codegen
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,3 +1,2 @@
1
1
  "use strict";
2
- // Generated by @dedot/codegen
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Dedot = void 0;
3
+ exports.LegacyClient = void 0;
4
4
  const codecs_1 = require("@dedot/codecs");
5
5
  const index_js_1 = require("../executor/index.js");
6
6
  const proxychain_js_1 = require("../proxychain.js");
7
7
  const BaseSubstrateClient_js_1 = require("./BaseSubstrateClient.js");
8
8
  const KEEP_ALIVE_INTERVAL = 10_000; // in ms
9
9
  /**
10
- * @name Dedot
10
+ * @name LegacyClient
11
11
  * @description Promised-based API Client for Polkadot & Substrate
12
12
  *
13
13
  * Initialize API instance and interact with substrate-based network
@@ -44,7 +44,7 @@ const KEEP_ALIVE_INTERVAL = 10_000; // in ms
44
44
  * run().catch(console.error);
45
45
  * ```
46
46
  */
47
- class Dedot extends BaseSubstrateClient_js_1.BaseSubstrateClient {
47
+ class LegacyClient extends BaseSubstrateClient_js_1.BaseSubstrateClient {
48
48
  #runtimeSubscriptionUnsub;
49
49
  #healthTimer;
50
50
  #apiAtCache = {};
@@ -62,7 +62,7 @@ class Dedot extends BaseSubstrateClient_js_1.BaseSubstrateClient {
62
62
  * @param options
63
63
  */
64
64
  static async create(options) {
65
- return new Dedot(options).connect();
65
+ return new LegacyClient(options).connect();
66
66
  }
67
67
  /**
68
68
  * Alias for __Dedot.create__
@@ -70,7 +70,7 @@ class Dedot extends BaseSubstrateClient_js_1.BaseSubstrateClient {
70
70
  * @param options
71
71
  */
72
72
  static async new(options) {
73
- return Dedot.create(options);
73
+ return LegacyClient.create(options);
74
74
  }
75
75
  onDisconnected = async () => {
76
76
  await this.#unsubscribeUpdates();
@@ -247,4 +247,4 @@ class Dedot extends BaseSubstrateClient_js_1.BaseSubstrateClient {
247
247
  return api;
248
248
  }
249
249
  }
250
- exports.Dedot = Dedot;
250
+ exports.LegacyClient = LegacyClient;
@@ -14,5 +14,5 @@ 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
- __exportStar(require("./Dedot.js"), exports);
17
+ __exportStar(require("./LegacyClient.js"), exports);
18
18
  __exportStar(require("./DedotClient.js"), exports);
@@ -35,13 +35,13 @@ class StorageQueryExecutorV2 extends StorageQueryExecutor_js_1.StorageQueryExecu
35
35
  }, {});
36
36
  }
37
37
  async subscribeStorage(keys, callback) {
38
- let initialHash = await this.chainHead.bestHash();
38
+ let best = await this.chainHead.bestBlock();
39
39
  let eventToListen = 'bestBlock';
40
40
  // TODO subscribe to finalized data source
41
41
  // initialHash = this.chainHead.finalizedHash;
42
42
  // eventToListen = 'finalizedBlock';
43
43
  const latestChanges = {};
44
- const pull = async (hash) => {
44
+ const pull = async ({ hash }) => {
45
45
  const results = await this.queryStorage(keys, hash);
46
46
  let changed = false;
47
47
  keys.forEach((key) => {
@@ -55,7 +55,7 @@ class StorageQueryExecutorV2 extends StorageQueryExecutor_js_1.StorageQueryExecu
55
55
  return;
56
56
  callback(keys.map((key) => latestChanges[key]));
57
57
  };
58
- await pull(initialHash);
58
+ await pull(best);
59
59
  const unsub = this.chainHead.on(eventToListen, pull);
60
60
  return async () => {
61
61
  unsub();
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CheckMetadataHash = void 0;
4
+ const utils_1 = require("@dedot/utils");
5
+ const SignedExtension_js_1 = require("../SignedExtension.js");
6
+ /**
7
+ * @description Genesis hash check to provide replay protection between different networks.
8
+ */
9
+ class CheckMetadataHash extends SignedExtension_js_1.SignedExtension {
10
+ async init() {
11
+ let metadataHash = this.payloadOptions.metadataHash;
12
+ if (metadataHash) {
13
+ (0, utils_1.assert)((0, utils_1.isHex)(metadataHash), 'Metadata hash is not a valid hex string');
14
+ this.data = { mode: 'Enabled' };
15
+ this.additionalSigned = metadataHash;
16
+ }
17
+ else {
18
+ this.data = { mode: 'Disabled' };
19
+ this.additionalSigned = undefined;
20
+ }
21
+ }
22
+ toPayload() {
23
+ // Ref: https://github.com/paritytech/polkadot-sdk/blob/8dbe4ee80734bba6644c7e5f879a363ce7c0a19f/substrate/frame/metadata-hash-extension/src/lib.rs#L55-L58
24
+ let enabled = this.data.mode === 'Enabled';
25
+ return {
26
+ mode: enabled ? 1 : 0, // 0 -> disabled, 1 -> enabled
27
+ metadataHash: this.additionalSigned,
28
+ };
29
+ }
30
+ }
31
+ exports.CheckMetadataHash = CheckMetadataHash;
@@ -4,6 +4,7 @@ exports.knownSignedExtensions = void 0;
4
4
  const ChargeAssetTxPayment_js_1 = require("./ChargeAssetTxPayment.js");
5
5
  const ChargeTransactionPayment_js_1 = require("./ChargeTransactionPayment.js");
6
6
  const CheckGenesis_js_1 = require("./CheckGenesis.js");
7
+ const CheckMetadataHash_js_1 = require("./CheckMetadataHash.js");
7
8
  const CheckMortality_js_1 = require("./CheckMortality.js");
8
9
  const CheckNonZeroSender_js_1 = require("./CheckNonZeroSender.js");
9
10
  const CheckNonce_js_1 = require("./CheckNonce.js");
@@ -22,4 +23,5 @@ exports.knownSignedExtensions = {
22
23
  ChargeTransactionPayment: ChargeTransactionPayment_js_1.ChargeTransactionPayment,
23
24
  PrevalidateAttests: PrevalidateAttests_js_1.PrevalidateAttests,
24
25
  ChargeAssetTxPayment: ChargeAssetTxPayment_js_1.ChargeAssetTxPayment,
26
+ CheckMetadataHash: CheckMetadataHash_js_1.CheckMetadataHash,
25
27
  };
@@ -5,7 +5,7 @@ import type { SubstrateApi } from '../chaintypes/index.js';
5
5
  import type { ApiOptions, ISubstrateClientAt } from '../types.js';
6
6
  import { BaseSubstrateClient } from './BaseSubstrateClient.js';
7
7
  /**
8
- * @name Dedot
8
+ * @name LegacyClient
9
9
  * @description Promised-based API Client for Polkadot & Substrate
10
10
  *
11
11
  * Initialize API instance and interact with substrate-based network
@@ -42,7 +42,7 @@ import { BaseSubstrateClient } from './BaseSubstrateClient.js';
42
42
  * run().catch(console.error);
43
43
  * ```
44
44
  */
45
- export declare class Dedot<ChainApi extends VersionedGenericSubstrateApi = SubstrateApi> extends BaseSubstrateClient<ChainApi> {
45
+ export declare class LegacyClient<ChainApi extends VersionedGenericSubstrateApi = SubstrateApi> extends BaseSubstrateClient<ChainApi> {
46
46
  #private;
47
47
  /**
48
48
  * Use factory methods (`create`, `new`) to create `Dedot` instances.
@@ -55,13 +55,13 @@ export declare class Dedot<ChainApi extends VersionedGenericSubstrateApi = Subst
55
55
  *
56
56
  * @param options
57
57
  */
58
- static create<ChainApi extends VersionedGenericSubstrateApi = SubstrateApi>(options: ApiOptions | JsonRpcProvider): Promise<Dedot<ChainApi>>;
58
+ static create<ChainApi extends VersionedGenericSubstrateApi = SubstrateApi>(options: ApiOptions | JsonRpcProvider): Promise<LegacyClient<ChainApi>>;
59
59
  /**
60
60
  * Alias for __Dedot.create__
61
61
  *
62
62
  * @param options
63
63
  */
64
- static new<ChainApi extends VersionedGenericSubstrateApi = SubstrateApi>(options: ApiOptions | JsonRpcProvider): Promise<Dedot<ChainApi>>;
64
+ static new<ChainApi extends VersionedGenericSubstrateApi = SubstrateApi>(options: ApiOptions | JsonRpcProvider): Promise<LegacyClient<ChainApi>>;
65
65
  protected onDisconnected: () => Promise<void>;
66
66
  protected beforeDisconnect(): Promise<void>;
67
67
  /**
@@ -4,7 +4,7 @@ import { newProxyChain } from '../proxychain.js';
4
4
  import { BaseSubstrateClient } from './BaseSubstrateClient.js';
5
5
  const KEEP_ALIVE_INTERVAL = 10_000; // in ms
6
6
  /**
7
- * @name Dedot
7
+ * @name LegacyClient
8
8
  * @description Promised-based API Client for Polkadot & Substrate
9
9
  *
10
10
  * Initialize API instance and interact with substrate-based network
@@ -41,7 +41,7 @@ const KEEP_ALIVE_INTERVAL = 10_000; // in ms
41
41
  * run().catch(console.error);
42
42
  * ```
43
43
  */
44
- export class Dedot extends BaseSubstrateClient {
44
+ export class LegacyClient extends BaseSubstrateClient {
45
45
  #runtimeSubscriptionUnsub;
46
46
  #healthTimer;
47
47
  #apiAtCache = {};
@@ -59,7 +59,7 @@ export class Dedot extends BaseSubstrateClient {
59
59
  * @param options
60
60
  */
61
61
  static async create(options) {
62
- return new Dedot(options).connect();
62
+ return new LegacyClient(options).connect();
63
63
  }
64
64
  /**
65
65
  * Alias for __Dedot.create__
@@ -67,7 +67,7 @@ export class Dedot extends BaseSubstrateClient {
67
67
  * @param options
68
68
  */
69
69
  static async new(options) {
70
- return Dedot.create(options);
70
+ return LegacyClient.create(options);
71
71
  }
72
72
  onDisconnected = async () => {
73
73
  await this.#unsubscribeUpdates();
package/client/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export * from './Dedot.js';
1
+ export * from './LegacyClient.js';
2
2
  export * from './DedotClient.js';
package/client/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export * from './Dedot.js';
1
+ export * from './LegacyClient.js';
2
2
  export * from './DedotClient.js';
@@ -32,13 +32,13 @@ export class StorageQueryExecutorV2 extends StorageQueryExecutor {
32
32
  }, {});
33
33
  }
34
34
  async subscribeStorage(keys, callback) {
35
- let initialHash = await this.chainHead.bestHash();
35
+ let best = await this.chainHead.bestBlock();
36
36
  let eventToListen = 'bestBlock';
37
37
  // TODO subscribe to finalized data source
38
38
  // initialHash = this.chainHead.finalizedHash;
39
39
  // eventToListen = 'finalizedBlock';
40
40
  const latestChanges = {};
41
- const pull = async (hash) => {
41
+ const pull = async ({ hash }) => {
42
42
  const results = await this.queryStorage(keys, hash);
43
43
  let changed = false;
44
44
  keys.forEach((key) => {
@@ -52,7 +52,7 @@ export class StorageQueryExecutorV2 extends StorageQueryExecutor {
52
52
  return;
53
53
  callback(keys.map((key) => latestChanges[key]));
54
54
  };
55
- await pull(initialHash);
55
+ await pull(best);
56
56
  const unsub = this.chainHead.on(eventToListen, pull);
57
57
  return async () => {
58
58
  unsub();
@@ -0,0 +1,13 @@
1
+ import { SignerPayloadJSON } from '@polkadot/types/types';
2
+ import { Hash } from '@dedot/codecs';
3
+ import { SignedExtension } from '../SignedExtension.js';
4
+ export type CheckMetadataHashMode = 'Disabled' | 'Enabled';
5
+ /**
6
+ * @description Genesis hash check to provide replay protection between different networks.
7
+ */
8
+ export declare class CheckMetadataHash extends SignedExtension<{
9
+ mode: CheckMetadataHashMode;
10
+ }, Hash | undefined> {
11
+ init(): Promise<void>;
12
+ toPayload(): Partial<SignerPayloadJSON>;
13
+ }
@@ -0,0 +1,27 @@
1
+ import { assert, isHex } from '@dedot/utils';
2
+ import { SignedExtension } from '../SignedExtension.js';
3
+ /**
4
+ * @description Genesis hash check to provide replay protection between different networks.
5
+ */
6
+ export class CheckMetadataHash extends SignedExtension {
7
+ async init() {
8
+ let metadataHash = this.payloadOptions.metadataHash;
9
+ if (metadataHash) {
10
+ assert(isHex(metadataHash), 'Metadata hash is not a valid hex string');
11
+ this.data = { mode: 'Enabled' };
12
+ this.additionalSigned = metadataHash;
13
+ }
14
+ else {
15
+ this.data = { mode: 'Disabled' };
16
+ this.additionalSigned = undefined;
17
+ }
18
+ }
19
+ toPayload() {
20
+ // Ref: https://github.com/paritytech/polkadot-sdk/blob/8dbe4ee80734bba6644c7e5f879a363ce7c0a19f/substrate/frame/metadata-hash-extension/src/lib.rs#L55-L58
21
+ let enabled = this.data.mode === 'Enabled';
22
+ return {
23
+ mode: enabled ? 1 : 0, // 0 -> disabled, 1 -> enabled
24
+ metadataHash: this.additionalSigned,
25
+ };
26
+ }
27
+ }
@@ -1,6 +1,7 @@
1
1
  import { ChargeAssetTxPayment } from './ChargeAssetTxPayment.js';
2
2
  import { ChargeTransactionPayment } from './ChargeTransactionPayment.js';
3
3
  import { CheckGenesis } from './CheckGenesis.js';
4
+ import { CheckMetadataHash } from './CheckMetadataHash.js';
4
5
  import { CheckMortality } from './CheckMortality.js';
5
6
  import { CheckNonZeroSender } from './CheckNonZeroSender.js';
6
7
  import { CheckNonce } from './CheckNonce.js';
@@ -19,4 +20,5 @@ export const knownSignedExtensions = {
19
20
  ChargeTransactionPayment,
20
21
  PrevalidateAttests,
21
22
  ChargeAssetTxPayment,
23
+ CheckMetadataHash,
22
24
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dedot/api",
3
- "version": "0.0.1-alpha.32",
3
+ "version": "0.0.1-alpha.34",
4
4
  "description": "A delightful JavaScript/TypeScript client for Polkadot & Substrate",
5
5
  "author": "Thang X. Vu <thang@coongcrafts.io>",
6
6
  "homepage": "https://github.com/dedotdev/dedot",
@@ -13,13 +13,13 @@
13
13
  "type": "module",
14
14
  "sideEffects": false,
15
15
  "dependencies": {
16
- "@dedot/codecs": "0.0.1-alpha.32",
17
- "@dedot/providers": "0.0.1-alpha.32",
18
- "@dedot/runtime-specs": "0.0.1-alpha.32",
19
- "@dedot/shape": "0.0.1-alpha.32",
20
- "@dedot/storage": "0.0.1-alpha.32",
21
- "@dedot/types": "0.0.1-alpha.32",
22
- "@dedot/utils": "0.0.1-alpha.32"
16
+ "@dedot/codecs": "0.0.1-alpha.34",
17
+ "@dedot/providers": "0.0.1-alpha.34",
18
+ "@dedot/runtime-specs": "0.0.1-alpha.34",
19
+ "@dedot/shape": "0.0.1-alpha.34",
20
+ "@dedot/storage": "0.0.1-alpha.34",
21
+ "@dedot/types": "0.0.1-alpha.34",
22
+ "@dedot/utils": "0.0.1-alpha.34"
23
23
  },
24
24
  "scripts": {
25
25
  "build": "tsc --project tsconfig.build.json && tsc --project tsconfig.build.cjs.json",
@@ -46,9 +46,9 @@
46
46
  },
47
47
  "license": "Apache-2.0",
48
48
  "devDependencies": {
49
- "@polkadot/types": "^11.0.2"
49
+ "@polkadot/types": "^11.2.1"
50
50
  },
51
- "gitHead": "43501104eee360a19ae18a70fe506e16d9357835",
51
+ "gitHead": "053078f3aed79a3044314421967325b9fe0e6f57",
52
52
  "module": "./index.js",
53
53
  "types": "./index.d.ts"
54
54
  }