@totochain/client 0.1.0 → 0.2.0

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 (158) hide show
  1. package/README.md +52 -28
  2. package/_cjs/accounts/substrateSigner.js +4 -1
  3. package/_cjs/actions/attestation/attest.d.cts +14 -9
  4. package/_cjs/actions/attestation/attest.js +6 -6
  5. package/_cjs/actions/attestation/index.d.cts +1 -1
  6. package/_cjs/actions/index.d.cts +1 -1
  7. package/_cjs/actions/index.js +1 -1
  8. package/_cjs/actions/{fractionalNft → puzzlePieces}/getCollectionsCount.js +1 -1
  9. package/_cjs/actions/{fractionalNft → puzzlePieces}/getItemsCount.js +1 -1
  10. package/_cjs/actions/{fractionalNft → puzzlePieces}/getOwner.js +1 -1
  11. package/_cjs/actions/puzzlePieces/getPendingWildcards.d.cts +8 -0
  12. package/_cjs/actions/puzzlePieces/getPendingWildcards.js +9 -0
  13. package/_cjs/actions/puzzlePieces/getTotalPuzzlePiecesMinted.d.cts +7 -0
  14. package/_cjs/actions/puzzlePieces/getTotalPuzzlePiecesMinted.js +8 -0
  15. package/_cjs/actions/{fractionalNft → puzzlePieces}/getWildcardCollectionId.js +1 -1
  16. package/_cjs/actions/{fractionalNft → puzzlePieces}/getWildcardDistributionMap.js +1 -1
  17. package/_cjs/actions/{fractionalNft → puzzlePieces}/getWildcardThreshold.js +1 -1
  18. package/_cjs/actions/{fractionalNft → puzzlePieces}/index.d.cts +5 -5
  19. package/_cjs/actions/{fractionalNft → puzzlePieces}/index.js +5 -5
  20. package/_cjs/actions/puzzlePieces/types.d.cts +5 -0
  21. package/_cjs/actions/rewardPool/index.d.cts +0 -4
  22. package/_cjs/actions/rewardPool/index.js +1 -5
  23. package/_cjs/client/compatibility.d.cts +16 -0
  24. package/_cjs/client/compatibility.js +60 -0
  25. package/_cjs/client/createClient.d.cts +2 -0
  26. package/_cjs/client/createClient.js +11 -0
  27. package/_cjs/crypto/index.d.cts +0 -2
  28. package/_cjs/crypto/index.js +1 -4
  29. package/_cjs/did/didUri.d.cts +11 -0
  30. package/_cjs/did/didUri.js +14 -0
  31. package/_cjs/index.d.cts +7 -4
  32. package/_cjs/index.js +9 -4
  33. package/_cjs/plugins/index.d.cts +2 -2
  34. package/_cjs/plugins/index.js +3 -3
  35. package/_cjs/plugins/{fractionalNft.d.cts → puzzlePieces.d.cts} +7 -10
  36. package/_cjs/plugins/{fractionalNft.js → puzzlePieces.js} +6 -6
  37. package/_cjs/plugins/rewardPool.d.cts +0 -5
  38. package/_cjs/plugins/rewardPool.js +0 -2
  39. package/_cjs/rpc/call.js +17 -1
  40. package/_cjs/rpc/definitions.js +49 -65
  41. package/_cjs/rpc/types.js +8 -12
  42. package/_esm/accounts/substrateSigner.js +5 -2
  43. package/_esm/actions/attestation/attest.js +6 -6
  44. package/_esm/actions/index.js +1 -1
  45. package/_esm/actions/{fractionalNft → puzzlePieces}/getCollectionsCount.js +1 -1
  46. package/_esm/actions/{fractionalNft → puzzlePieces}/getItemsCount.js +1 -1
  47. package/_esm/actions/{fractionalNft → puzzlePieces}/getOwner.js +1 -1
  48. package/_esm/actions/puzzlePieces/getPendingWildcards.js +6 -0
  49. package/_esm/actions/puzzlePieces/getTotalPuzzlePiecesMinted.js +5 -0
  50. package/_esm/actions/{fractionalNft → puzzlePieces}/getWildcardCollectionId.js +1 -1
  51. package/_esm/actions/{fractionalNft → puzzlePieces}/getWildcardDistributionMap.js +1 -1
  52. package/_esm/actions/{fractionalNft → puzzlePieces}/getWildcardThreshold.js +1 -1
  53. package/_esm/actions/{fractionalNft → puzzlePieces}/index.js +2 -2
  54. package/_esm/actions/rewardPool/index.js +0 -2
  55. package/_esm/client/compatibility.js +55 -0
  56. package/_esm/client/createClient.js +11 -0
  57. package/_esm/crypto/index.js +0 -1
  58. package/_esm/did/didUri.js +11 -0
  59. package/_esm/index.js +4 -2
  60. package/_esm/plugins/index.js +1 -1
  61. package/_esm/plugins/{fractionalNft.js → puzzlePieces.js} +5 -5
  62. package/_esm/plugins/rewardPool.js +1 -3
  63. package/_esm/rpc/call.js +17 -1
  64. package/_esm/rpc/definitions.js +49 -65
  65. package/_esm/rpc/types.js +8 -12
  66. package/_types/accounts/substrateSigner.d.ts.map +1 -1
  67. package/_types/actions/attestation/attest.d.ts +14 -9
  68. package/_types/actions/attestation/attest.d.ts.map +1 -1
  69. package/_types/actions/attestation/index.d.ts +1 -1
  70. package/_types/actions/attestation/index.d.ts.map +1 -1
  71. package/_types/actions/index.d.ts +1 -1
  72. package/_types/actions/index.d.ts.map +1 -1
  73. package/_types/actions/puzzlePieces/getCollectionsCount.d.ts.map +1 -0
  74. package/_types/actions/puzzlePieces/getItemsCount.d.ts.map +1 -0
  75. package/_types/actions/puzzlePieces/getOwner.d.ts.map +1 -0
  76. package/_types/actions/puzzlePieces/getPendingWildcards.d.ts +8 -0
  77. package/_types/actions/puzzlePieces/getPendingWildcards.d.ts.map +1 -0
  78. package/_types/actions/puzzlePieces/getTotalPuzzlePiecesMinted.d.ts +7 -0
  79. package/_types/actions/puzzlePieces/getTotalPuzzlePiecesMinted.d.ts.map +1 -0
  80. package/_types/actions/puzzlePieces/getWildcardCollectionId.d.ts.map +1 -0
  81. package/_types/actions/puzzlePieces/getWildcardDistributionMap.d.ts.map +1 -0
  82. package/_types/actions/puzzlePieces/getWildcardThreshold.d.ts.map +1 -0
  83. package/_types/actions/{fractionalNft → puzzlePieces}/index.d.ts +5 -5
  84. package/_types/actions/puzzlePieces/index.d.ts.map +1 -0
  85. package/_types/actions/puzzlePieces/types.d.ts +5 -0
  86. package/_types/actions/puzzlePieces/types.d.ts.map +1 -0
  87. package/_types/actions/rewardPool/index.d.ts +0 -4
  88. package/_types/actions/rewardPool/index.d.ts.map +1 -1
  89. package/_types/client/compatibility.d.ts +16 -0
  90. package/_types/client/compatibility.d.ts.map +1 -0
  91. package/_types/client/createClient.d.ts +2 -0
  92. package/_types/client/createClient.d.ts.map +1 -1
  93. package/_types/crypto/index.d.ts +0 -2
  94. package/_types/crypto/index.d.ts.map +1 -1
  95. package/_types/did/didUri.d.ts +11 -0
  96. package/_types/did/didUri.d.ts.map +1 -0
  97. package/_types/index.d.ts +7 -4
  98. package/_types/index.d.ts.map +1 -1
  99. package/_types/plugins/index.d.ts +2 -2
  100. package/_types/plugins/index.d.ts.map +1 -1
  101. package/_types/plugins/{fractionalNft.d.ts → puzzlePieces.d.ts} +7 -10
  102. package/_types/plugins/puzzlePieces.d.ts.map +1 -0
  103. package/_types/plugins/rewardPool.d.ts +0 -5
  104. package/_types/plugins/rewardPool.d.ts.map +1 -1
  105. package/_types/rpc/call.d.ts.map +1 -1
  106. package/_types/rpc/definitions.d.ts.map +1 -1
  107. package/_types/rpc/types.d.ts.map +1 -1
  108. package/package.json +1 -1
  109. package/_cjs/actions/fractionalNft/getNftInfo.d.cts +0 -9
  110. package/_cjs/actions/fractionalNft/getNftInfo.js +0 -12
  111. package/_cjs/actions/fractionalNft/getTotalFnftsMinted.d.cts +0 -7
  112. package/_cjs/actions/fractionalNft/getTotalFnftsMinted.js +0 -8
  113. package/_cjs/actions/fractionalNft/types.d.cts +0 -10
  114. package/_cjs/actions/rewardPool/getCollectionIds.d.cts +0 -7
  115. package/_cjs/actions/rewardPool/getCollectionIds.js +0 -8
  116. package/_cjs/actions/rewardPool/getItemIds.d.cts +0 -8
  117. package/_cjs/actions/rewardPool/getItemIds.js +0 -8
  118. package/_cjs/crypto/claimHash.d.cts +0 -23
  119. package/_cjs/crypto/claimHash.js +0 -38
  120. package/_esm/actions/fractionalNft/getNftInfo.js +0 -9
  121. package/_esm/actions/fractionalNft/getTotalFnftsMinted.js +0 -5
  122. package/_esm/actions/rewardPool/getCollectionIds.js +0 -5
  123. package/_esm/actions/rewardPool/getItemIds.js +0 -5
  124. package/_esm/crypto/claimHash.js +0 -34
  125. package/_types/actions/fractionalNft/getCollectionsCount.d.ts.map +0 -1
  126. package/_types/actions/fractionalNft/getItemsCount.d.ts.map +0 -1
  127. package/_types/actions/fractionalNft/getNftInfo.d.ts +0 -9
  128. package/_types/actions/fractionalNft/getNftInfo.d.ts.map +0 -1
  129. package/_types/actions/fractionalNft/getOwner.d.ts.map +0 -1
  130. package/_types/actions/fractionalNft/getTotalFnftsMinted.d.ts +0 -7
  131. package/_types/actions/fractionalNft/getTotalFnftsMinted.d.ts.map +0 -1
  132. package/_types/actions/fractionalNft/getWildcardCollectionId.d.ts.map +0 -1
  133. package/_types/actions/fractionalNft/getWildcardDistributionMap.d.ts.map +0 -1
  134. package/_types/actions/fractionalNft/getWildcardThreshold.d.ts.map +0 -1
  135. package/_types/actions/fractionalNft/index.d.ts.map +0 -1
  136. package/_types/actions/fractionalNft/types.d.ts +0 -10
  137. package/_types/actions/fractionalNft/types.d.ts.map +0 -1
  138. package/_types/actions/rewardPool/getCollectionIds.d.ts +0 -7
  139. package/_types/actions/rewardPool/getCollectionIds.d.ts.map +0 -1
  140. package/_types/actions/rewardPool/getItemIds.d.ts +0 -8
  141. package/_types/actions/rewardPool/getItemIds.d.ts.map +0 -1
  142. package/_types/crypto/claimHash.d.ts +0 -23
  143. package/_types/crypto/claimHash.d.ts.map +0 -1
  144. package/_types/plugins/fractionalNft.d.ts.map +0 -1
  145. /package/_cjs/actions/{fractionalNft → puzzlePieces}/getCollectionsCount.d.cts +0 -0
  146. /package/_cjs/actions/{fractionalNft → puzzlePieces}/getItemsCount.d.cts +0 -0
  147. /package/_cjs/actions/{fractionalNft → puzzlePieces}/getOwner.d.cts +0 -0
  148. /package/_cjs/actions/{fractionalNft → puzzlePieces}/getWildcardCollectionId.d.cts +0 -0
  149. /package/_cjs/actions/{fractionalNft → puzzlePieces}/getWildcardDistributionMap.d.cts +0 -0
  150. /package/_cjs/actions/{fractionalNft → puzzlePieces}/getWildcardThreshold.d.cts +0 -0
  151. /package/_cjs/actions/{fractionalNft → puzzlePieces}/types.js +0 -0
  152. /package/_esm/actions/{fractionalNft → puzzlePieces}/types.js +0 -0
  153. /package/_types/actions/{fractionalNft → puzzlePieces}/getCollectionsCount.d.ts +0 -0
  154. /package/_types/actions/{fractionalNft → puzzlePieces}/getItemsCount.d.ts +0 -0
  155. /package/_types/actions/{fractionalNft → puzzlePieces}/getOwner.d.ts +0 -0
  156. /package/_types/actions/{fractionalNft → puzzlePieces}/getWildcardCollectionId.d.ts +0 -0
  157. /package/_types/actions/{fractionalNft → puzzlePieces}/getWildcardDistributionMap.d.ts +0 -0
  158. /package/_types/actions/{fractionalNft → puzzlePieces}/getWildcardThreshold.d.ts +0 -0
@@ -1,16 +1,16 @@
1
1
  export { activityTrackerPlugin } from './activityTracker.cjs';
2
- export { fractionalNftPlugin } from './fractionalNft.cjs';
3
2
  export { handshakePlugin } from './handshake.cjs';
4
3
  export { potentialPlugin } from './potential.cjs';
4
+ export { puzzlePiecesPlugin } from './puzzlePieces.cjs';
5
5
  export { referralPlugin } from './referral.cjs';
6
6
  export { reputationVotingPlugin } from './reputationVoting.cjs';
7
7
  export { rewardPoolPlugin } from './rewardPool.cjs';
8
8
  export { techCommitteeManagerPlugin } from './techCommitteeManager.cjs';
9
9
  export { validatorManagerPlugin } from './validatorManager.cjs';
10
10
  export type { ActivityTrackerCapability } from './activityTracker.cjs';
11
- export type { FractionalNftCapability } from './fractionalNft.cjs';
12
11
  export type { HandshakeCapability } from './handshake.cjs';
13
12
  export type { PotentialCapability } from './potential.cjs';
13
+ export type { PuzzlePiecesCapability } from './puzzlePieces.cjs';
14
14
  export type { ReferralCapability } from './referral.cjs';
15
15
  export type { ReputationVotingCapability } from './reputationVoting.cjs';
16
16
  export type { RewardPoolCapability } from './rewardPool.cjs';
@@ -1,14 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validatorManagerPlugin = exports.techCommitteeManagerPlugin = exports.rewardPoolPlugin = exports.reputationVotingPlugin = exports.referralPlugin = exports.potentialPlugin = exports.handshakePlugin = exports.fractionalNftPlugin = exports.activityTrackerPlugin = void 0;
3
+ exports.validatorManagerPlugin = exports.techCommitteeManagerPlugin = exports.rewardPoolPlugin = exports.reputationVotingPlugin = exports.referralPlugin = exports.puzzlePiecesPlugin = exports.potentialPlugin = exports.handshakePlugin = exports.activityTrackerPlugin = void 0;
4
4
  var activityTracker_js_1 = require("./activityTracker.js");
5
5
  Object.defineProperty(exports, "activityTrackerPlugin", { enumerable: true, get: function () { return activityTracker_js_1.activityTrackerPlugin; } });
6
- var fractionalNft_js_1 = require("./fractionalNft.js");
7
- Object.defineProperty(exports, "fractionalNftPlugin", { enumerable: true, get: function () { return fractionalNft_js_1.fractionalNftPlugin; } });
8
6
  var handshake_js_1 = require("./handshake.js");
9
7
  Object.defineProperty(exports, "handshakePlugin", { enumerable: true, get: function () { return handshake_js_1.handshakePlugin; } });
10
8
  var potential_js_1 = require("./potential.js");
11
9
  Object.defineProperty(exports, "potentialPlugin", { enumerable: true, get: function () { return potential_js_1.potentialPlugin; } });
10
+ var puzzlePieces_js_1 = require("./puzzlePieces.js");
11
+ Object.defineProperty(exports, "puzzlePiecesPlugin", { enumerable: true, get: function () { return puzzlePieces_js_1.puzzlePiecesPlugin; } });
12
12
  var referral_js_1 = require("./referral.js");
13
13
  Object.defineProperty(exports, "referralPlugin", { enumerable: true, get: function () { return referral_js_1.referralPlugin; } });
14
14
  var reputationVoting_js_1 = require("./reputationVoting.js");
@@ -1,24 +1,21 @@
1
1
  import type { Client } from '../client/types.cjs';
2
2
  import type { Address, BlockHash } from '../types/index.cjs';
3
- import type { NftInfo, WildcardDistribution } from '../actions/fractionalNft/types.cjs';
3
+ import type { WildcardDistribution } from '../actions/puzzlePieces/types.cjs';
4
4
  interface At {
5
5
  at?: BlockHash;
6
6
  }
7
- export interface FractionalNftCapability {
8
- fractionalNft: {
7
+ export interface PuzzlePiecesCapability {
8
+ puzzlePieces: {
9
9
  getWildcardThreshold(p?: At): Promise<number | null>;
10
10
  getWildcardCollectionId(p?: At): Promise<number | null>;
11
11
  getWildcardDistributionMap(p?: At): Promise<WildcardDistribution[]>;
12
- getTotalFnftsMinted(p?: At): Promise<number | null>;
12
+ getPendingWildcards(p?: At): Promise<number>;
13
+ getTotalPuzzlePiecesMinted(p?: At): Promise<number | null>;
13
14
  getCollectionsCount(p?: At): Promise<number>;
14
15
  getItemsCount(p: {
15
16
  collectionId: number;
16
17
  at?: BlockHash;
17
18
  }): Promise<number>;
18
- getNftInfo(p: {
19
- collectionId: number;
20
- at?: BlockHash;
21
- }): Promise<NftInfo>;
22
19
  getOwner(p: {
23
20
  collectionId: number;
24
21
  itemId: number;
@@ -26,6 +23,6 @@ export interface FractionalNftCapability {
26
23
  }): Promise<Address | null>;
27
24
  };
28
25
  }
29
- export declare function fractionalNftPlugin(): (client: Client) => FractionalNftCapability;
26
+ export declare function puzzlePiecesPlugin(): (client: Client) => PuzzlePiecesCapability;
30
27
  export {};
31
- //# sourceMappingURL=fractionalNft.d.ts.map
28
+ //# sourceMappingURL=puzzlePieces.d.ts.map
@@ -1,17 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fractionalNftPlugin = fractionalNftPlugin;
4
- const index_js_1 = require("../actions/fractionalNft/index.js");
5
- function fractionalNftPlugin() {
3
+ exports.puzzlePiecesPlugin = puzzlePiecesPlugin;
4
+ const index_js_1 = require("../actions/puzzlePieces/index.js");
5
+ function puzzlePiecesPlugin() {
6
6
  return (client) => ({
7
- fractionalNft: {
7
+ puzzlePieces: {
8
8
  getWildcardThreshold: (p) => (0, index_js_1.getWildcardThreshold)(client, p),
9
9
  getWildcardCollectionId: (p) => (0, index_js_1.getWildcardCollectionId)(client, p),
10
10
  getWildcardDistributionMap: (p) => (0, index_js_1.getWildcardDistributionMap)(client, p),
11
- getTotalFnftsMinted: (p) => (0, index_js_1.getTotalFnftsMinted)(client, p),
11
+ getPendingWildcards: (p) => (0, index_js_1.getPendingWildcards)(client, p),
12
+ getTotalPuzzlePiecesMinted: (p) => (0, index_js_1.getTotalPuzzlePiecesMinted)(client, p),
12
13
  getCollectionsCount: (p) => (0, index_js_1.getCollectionsCount)(client, p),
13
14
  getItemsCount: (p) => (0, index_js_1.getItemsCount)(client, p),
14
- getNftInfo: (p) => (0, index_js_1.getNftInfo)(client, p),
15
15
  getOwner: (p) => (0, index_js_1.getOwner)(client, p),
16
16
  },
17
17
  });
@@ -7,11 +7,6 @@ export interface RewardPoolCapability {
7
7
  rewardPool: {
8
8
  getAccount(p?: At): Promise<Address>;
9
9
  getBalance(p?: At): Promise<bigint>;
10
- getCollectionIds(p?: At): Promise<number[]>;
11
- getItemIds(p: {
12
- collectionId: number;
13
- at?: BlockHash;
14
- }): Promise<number[]>;
15
10
  };
16
11
  }
17
12
  export declare function rewardPoolPlugin(): (client: Client) => RewardPoolCapability;
@@ -7,8 +7,6 @@ function rewardPoolPlugin() {
7
7
  rewardPool: {
8
8
  getAccount: (p) => (0, index_js_1.getRewardPoolAccount)(client, p),
9
9
  getBalance: (p) => (0, index_js_1.getRewardPoolBalance)(client, p),
10
- getCollectionIds: (p) => (0, index_js_1.getCollectionIds)(client, p),
11
- getItemIds: (p) => (0, index_js_1.getItemIds)(client, p),
12
10
  },
13
11
  });
14
12
  }
package/_cjs/rpc/call.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.callRpc = callRpc;
4
+ const definitions_js_1 = require("./definitions.js");
4
5
  async function callRpc(client, section, method, ...params) {
5
6
  const rpc = client.api.rpc;
6
7
  const fn = rpc[section]?.[method];
@@ -8,5 +9,20 @@ async function callRpc(client, section, method, ...params) {
8
9
  throw new Error(`The node does not expose ${section}_${method}. ` +
9
10
  `Check it was built with the ${section} RPC extension.`);
10
11
  }
11
- return fn(...params.filter((p) => p !== undefined));
12
+ // An omitted required parameter is refused: sent as null, it would encode as a default
13
+ // value — poll 0, collection 0 — and the call would answer for that instead.
14
+ const definitions = definitions_js_1.RPC_DEFINITIONS[section]?.[method]?.params ?? [];
15
+ params.forEach((param, index) => {
16
+ const definition = definitions[index];
17
+ if (param === undefined && definition && !definition.isOptional) {
18
+ throw new Error(`Missing required parameter ${definition.name} for ${section}_${method}`);
19
+ }
20
+ });
21
+ // An omitted optional parameter followed by a given one is sent as null, so the ones after
22
+ // it keep their positions. Omitted parameters at the end are left off instead:
23
+ // `@polkadot/api` encodes a null `at` as the zero block hash, not as an absent one.
24
+ let count = params.length;
25
+ while (count > 0 && params[count - 1] === undefined)
26
+ count -= 1;
27
+ return fn(...params.slice(0, count).map((param) => param ?? null));
12
28
  }
@@ -57,58 +57,6 @@ exports.RPC_DEFINITIONS = {
57
57
  type: '(u32, u64, u32)',
58
58
  },
59
59
  },
60
- fractionalNft: {
61
- wildcardThreshold: {
62
- description: 'Mints required before a wildcard is distributed',
63
- params: [{ name: 'at', type: 'BlockHash', isOptional: true }],
64
- type: 'Option<u32>',
65
- },
66
- wildcardCollectionId: {
67
- description: 'Collection wildcards are minted into',
68
- params: [{ name: 'at', type: 'BlockHash', isOptional: true }],
69
- type: 'Option<u32>',
70
- },
71
- wildcardDistributionMap: {
72
- description: 'Scheduled wildcard distributions, by block',
73
- params: [{ name: 'at', type: 'BlockHash', isOptional: true }],
74
- type: 'Vec<(u32, u32)>',
75
- },
76
- totalFnftsMinted: {
77
- description: 'Total fractional NFTs minted',
78
- params: [{ name: 'at', type: 'BlockHash', isOptional: true }],
79
- type: 'Option<u32>',
80
- },
81
- collectionsCount: {
82
- description: 'Number of collections',
83
- params: [{ name: 'at', type: 'BlockHash', isOptional: true }],
84
- type: 'u32',
85
- },
86
- itemsCount: {
87
- description: 'Number of items in a collection',
88
- params: [
89
- { name: 'collectionId', type: 'u32' },
90
- { name: 'at', type: 'BlockHash', isOptional: true },
91
- ],
92
- type: 'u32',
93
- },
94
- nftInfo: {
95
- description: 'Contract address and token id backing a collection',
96
- params: [
97
- { name: 'collectionId', type: 'u32' },
98
- { name: 'at', type: 'BlockHash', isOptional: true },
99
- ],
100
- type: 'NftInfo',
101
- },
102
- owner: {
103
- description: 'Owner of one item, if it exists',
104
- params: [
105
- { name: 'collectionId', type: 'u32' },
106
- { name: 'itemId', type: 'u32' },
107
- { name: 'at', type: 'BlockHash', isOptional: true },
108
- ],
109
- type: 'Option<AccountId>',
110
- },
111
- },
112
60
  handshake: {
113
61
  hasHandshakeCompleted: {
114
62
  description: 'Whether two accounts completed a handshake',
@@ -217,6 +165,55 @@ exports.RPC_DEFINITIONS = {
217
165
  type: 'u32',
218
166
  },
219
167
  },
168
+ puzzlePieces: {
169
+ wildcardThreshold: {
170
+ description: 'Mints required before a wildcard is distributed',
171
+ params: [{ name: 'at', type: 'BlockHash', isOptional: true }],
172
+ type: 'Option<u32>',
173
+ },
174
+ wildcardCollectionId: {
175
+ description: 'Collection wildcards are minted into',
176
+ params: [{ name: 'at', type: 'BlockHash', isOptional: true }],
177
+ type: 'Option<u32>',
178
+ },
179
+ wildcardDistributionMap: {
180
+ description: 'Scheduled wildcard distributions, by block',
181
+ params: [{ name: 'at', type: 'BlockHash', isOptional: true }],
182
+ type: 'Vec<(u32, u32)>',
183
+ },
184
+ pendingWildcards: {
185
+ description: 'Wildcards owed but not yet minted into the distribution map',
186
+ params: [{ name: 'at', type: 'BlockHash', isOptional: true }],
187
+ type: 'u32',
188
+ },
189
+ totalPuzzlePiecesMinted: {
190
+ description: 'Total puzzle pieces minted',
191
+ params: [{ name: 'at', type: 'BlockHash', isOptional: true }],
192
+ type: 'Option<u32>',
193
+ },
194
+ collectionsCount: {
195
+ description: 'Number of collections',
196
+ params: [{ name: 'at', type: 'BlockHash', isOptional: true }],
197
+ type: 'u32',
198
+ },
199
+ itemsCount: {
200
+ description: 'Number of items in a collection',
201
+ params: [
202
+ { name: 'collectionId', type: 'u32' },
203
+ { name: 'at', type: 'BlockHash', isOptional: true },
204
+ ],
205
+ type: 'u32',
206
+ },
207
+ owner: {
208
+ description: 'Owner of one item, if it exists',
209
+ params: [
210
+ { name: 'collectionId', type: 'u32' },
211
+ { name: 'itemId', type: 'u32' },
212
+ { name: 'at', type: 'BlockHash', isOptional: true },
213
+ ],
214
+ type: 'Option<AccountId>',
215
+ },
216
+ },
220
217
  referral: {
221
218
  activeReferralsCount: {
222
219
  description: 'Number of accounts in the referral subtree rooted at this account',
@@ -318,19 +315,6 @@ exports.RPC_DEFINITIONS = {
318
315
  params: [{ name: 'at', type: 'BlockHash', isOptional: true }],
319
316
  type: 'u128',
320
317
  },
321
- collectionIds: {
322
- description: 'Collections the reward pool holds items in',
323
- params: [{ name: 'at', type: 'BlockHash', isOptional: true }],
324
- type: 'Vec<u32>',
325
- },
326
- itemIds: {
327
- description: 'Items the reward pool holds in one collection',
328
- params: [
329
- { name: 'collectionId', type: 'u32' },
330
- { name: 'at', type: 'BlockHash', isOptional: true },
331
- ],
332
- type: 'Vec<u32>',
333
- },
334
318
  },
335
319
  techCommitteeManager: {
336
320
  candidates: {
package/_cjs/rpc/types.js CHANGED
@@ -6,20 +6,16 @@ exports.CHAIN_TYPES = {
6
6
  parent: 'Option<AccountId>',
7
7
  children: 'Vec<AccountId>',
8
8
  },
9
- NftInfo: {
10
- address: 'H160',
11
- token_id: 'U256',
12
- },
13
9
  Pagination: {
14
10
  page: 'Option<u32>',
15
- page_size: 'Option<u32>',
11
+ pageSize: 'Option<u32>',
16
12
  },
17
13
  PaginatedResponse: {
18
14
  items: 'Vec<AccountId>',
19
15
  total: 'Option<u32>',
20
16
  page: 'u32',
21
- page_size: 'u32',
22
- has_more: 'bool',
17
+ pageSize: 'u32',
18
+ hasMore: 'bool',
23
19
  },
24
20
  VoteDirection: {
25
21
  _enum: ['Aye', 'Nay'],
@@ -27,7 +23,7 @@ exports.CHAIN_TYPES = {
27
23
  VoteRecord: {
28
24
  direction: 'VoteDirection',
29
25
  reputation: 'u32',
30
- voted_at: 'u32',
26
+ votedAt: 'u32',
31
27
  },
32
28
  ReputationTally: {
33
29
  ayes: 'u128',
@@ -36,10 +32,10 @@ exports.CHAIN_TYPES = {
36
32
  electorate: 'u128',
37
33
  },
38
34
  ActivityReputationInfo: {
39
- current_reputation: 'u32',
40
- raw_reputation: 'u32',
41
- last_activity_block: 'u32',
42
- blocks_since_activity: 'u32',
35
+ currentReputation: 'u32',
36
+ rawReputation: 'u32',
37
+ lastActivityBlock: 'u32',
38
+ blocksSinceActivity: 'u32',
43
39
  },
44
40
  ActivityReputationPage: {
45
41
  entries: 'Vec<(AccountId, u32)>',
@@ -1,4 +1,4 @@
1
- import { keccakAsU8a } from '@polkadot/util-crypto';
1
+ import { blake2AsU8a, keccakAsU8a } from '@polkadot/util-crypto';
2
2
  import { hexToU8a, stringToU8a, u8aConcat, u8aToHex } from '@polkadot/util';
3
3
  const RAW_MESSAGE_DOMAIN = /*#__PURE__*/ stringToU8a('\x19Totochain Signed Message:\n');
4
4
  export function toSubstrateSigner(api, signer) {
@@ -27,7 +27,10 @@ export function toSubstrateSigner(api, signer) {
27
27
  const extrinsic = api.registry.createType('ExtrinsicPayload', payload, {
28
28
  version: payload.version,
29
29
  });
30
- const digest = keccakAsU8a(extrinsic.toU8a({ method: true }));
30
+ // A payload longer than 256 bytes is signed as its blake2_256 hash, which is what the
31
+ // chain checks the signature against.
32
+ const encoded = extrinsic.toU8a({ method: true });
33
+ const digest = keccakAsU8a(encoded.length > 256 ? blake2AsU8a(encoded) : encoded);
31
34
  return { id: 0, signature: u8aToHex(normalise(await signer.signDigest(digest))) };
32
35
  },
33
36
  async signRaw(raw) {
@@ -1,9 +1,9 @@
1
- export function attest(client, { claimHash, ctypeHash, subject }) {
2
- return client.api.tx['attestation']['add'](claimHash, ctypeHash, null, subject);
1
+ export function attest(client, { subject, ctypeHash }) {
2
+ return client.api.tx['attestation']['add'](subject, ctypeHash);
3
3
  }
4
- export function revokeAttestation(client, { claimHash }) {
5
- return client.api.tx['attestation']['revoke'](claimHash, null);
4
+ export function revokeAttestation(client, { subject, ctypeHash, issuanceId }) {
5
+ return client.api.tx['attestation']['revoke'](subject, ctypeHash, issuanceId);
6
6
  }
7
- export function removeAttestation(client, { claimHash }) {
8
- return client.api.tx['attestation']['remove'](claimHash, null);
7
+ export function removeAttestation(client, { subject, ctypeHash, issuanceId }) {
8
+ return client.api.tx['attestation']['remove'](subject, ctypeHash, issuanceId);
9
9
  }
@@ -1,9 +1,9 @@
1
1
  export * from './activityTracker/index.js';
2
2
  export * from './attestation/index.js';
3
3
  export * from './did/index.js';
4
- export * from './fractionalNft/index.js';
5
4
  export * from './handshake/index.js';
6
5
  export * from './potential/index.js';
6
+ export * from './puzzlePieces/index.js';
7
7
  export * from './referral/index.js';
8
8
  export * from './reputationVoting/index.js';
9
9
  export * from './rewardPool/index.js';
@@ -1,5 +1,5 @@
1
1
  import { callRpc } from '../../rpc/call.js';
2
2
  export async function getCollectionsCount(client, { at } = {}) {
3
- const result = await callRpc(client, 'fractionalNft', 'collectionsCount', at);
3
+ const result = await callRpc(client, 'puzzlePieces', 'collectionsCount', at);
4
4
  return result.toNumber();
5
5
  }
@@ -1,5 +1,5 @@
1
1
  import { callRpc } from '../../rpc/call.js';
2
2
  export async function getItemsCount(client, { collectionId, at }) {
3
- const result = await callRpc(client, 'fractionalNft', 'itemsCount', collectionId, at);
3
+ const result = await callRpc(client, 'puzzlePieces', 'itemsCount', collectionId, at);
4
4
  return result.toNumber();
5
5
  }
@@ -1,5 +1,5 @@
1
1
  import { callRpc } from '../../rpc/call.js';
2
2
  export async function getOwner(client, { collectionId, itemId, at }) {
3
- const result = await callRpc(client, 'fractionalNft', 'owner', collectionId, itemId, at);
3
+ const result = await callRpc(client, 'puzzlePieces', 'owner', collectionId, itemId, at);
4
4
  return result.isSome ? result.unwrap().toString() : null;
5
5
  }
@@ -0,0 +1,6 @@
1
+ import { callRpc } from '../../rpc/call.js';
2
+ /** Wildcards owed but not yet minted into the distribution map. */
3
+ export async function getPendingWildcards(client, { at } = {}) {
4
+ const result = await callRpc(client, 'puzzlePieces', 'pendingWildcards', at);
5
+ return result.toNumber();
6
+ }
@@ -0,0 +1,5 @@
1
+ import { callRpc } from '../../rpc/call.js';
2
+ export async function getTotalPuzzlePiecesMinted(client, { at } = {}) {
3
+ const result = await callRpc(client, 'puzzlePieces', 'totalPuzzlePiecesMinted', at);
4
+ return result.isSome ? result.unwrap().toNumber() : null;
5
+ }
@@ -1,5 +1,5 @@
1
1
  import { callRpc } from '../../rpc/call.js';
2
2
  export async function getWildcardCollectionId(client, { at } = {}) {
3
- const result = await callRpc(client, 'fractionalNft', 'wildcardCollectionId', at);
3
+ const result = await callRpc(client, 'puzzlePieces', 'wildcardCollectionId', at);
4
4
  return result.isSome ? result.unwrap().toNumber() : null;
5
5
  }
@@ -1,6 +1,6 @@
1
1
  import { callRpc } from '../../rpc/call.js';
2
2
  export async function getWildcardDistributionMap(client, { at } = {}) {
3
- const result = await callRpc(client, 'fractionalNft', 'wildcardDistributionMap', at);
3
+ const result = await callRpc(client, 'puzzlePieces', 'wildcardDistributionMap', at);
4
4
  const pairs = result.toJSON();
5
5
  return pairs.map(([blockNumber, itemId]) => ({ blockNumber, itemId }));
6
6
  }
@@ -1,5 +1,5 @@
1
1
  import { callRpc } from '../../rpc/call.js';
2
2
  export async function getWildcardThreshold(client, { at } = {}) {
3
- const result = await callRpc(client, 'fractionalNft', 'wildcardThreshold', at);
3
+ const result = await callRpc(client, 'puzzlePieces', 'wildcardThreshold', at);
4
4
  return result.isSome ? result.unwrap().toNumber() : null;
5
5
  }
@@ -1,8 +1,8 @@
1
1
  export { getCollectionsCount } from './getCollectionsCount.js';
2
2
  export { getItemsCount } from './getItemsCount.js';
3
- export { getNftInfo } from './getNftInfo.js';
4
3
  export { getOwner } from './getOwner.js';
5
- export { getTotalFnftsMinted } from './getTotalFnftsMinted.js';
4
+ export { getPendingWildcards } from './getPendingWildcards.js';
5
+ export { getTotalPuzzlePiecesMinted } from './getTotalPuzzlePiecesMinted.js';
6
6
  export { getWildcardCollectionId } from './getWildcardCollectionId.js';
7
7
  export { getWildcardDistributionMap } from './getWildcardDistributionMap.js';
8
8
  export { getWildcardThreshold } from './getWildcardThreshold.js';
@@ -1,4 +1,2 @@
1
- export { getCollectionIds } from './getCollectionIds.js';
2
- export { getItemIds } from './getItemIds.js';
3
1
  export { getRewardPoolAccount } from './getRewardPoolAccount.js';
4
2
  export { getRewardPoolBalance } from './getRewardPoolBalance.js';
@@ -0,0 +1,55 @@
1
+ import { RPC_DEFINITIONS } from '../rpc/definitions.js';
2
+ /** The runtime this client is written against. */
3
+ export const SPEC_NAME = 'totochain';
4
+ /** Every call an action builds, with the arguments it passes, as the node's metadata lists them. */
5
+ export const EXPECTED_CALLS = {
6
+ 'attestation.add': 'subject: AccountId20, ctypeHash: H256',
7
+ 'attestation.remove': 'subject: AccountId20, ctypeHash: H256, issuanceId: u64',
8
+ 'attestation.revoke': 'subject: AccountId20, ctypeHash: H256, issuanceId: u64',
9
+ 'did.createDidFor': 'subject: AccountId20',
10
+ 'did.createFromAccount': '',
11
+ };
12
+ /** Thrown by `createClient` in strict mode when the node does not match this client. */
13
+ export class IncompatibleNodeError extends Error {
14
+ problems;
15
+ constructor(problems) {
16
+ super(`The node does not match @totochain/client:\n- ${problems.join('\n- ')}`);
17
+ this.name = 'IncompatibleNodeError';
18
+ this.problems = problems;
19
+ }
20
+ }
21
+ /**
22
+ * Lists every way the connected node differs from what this client sends: the runtime, the
23
+ * calls the actions build and the custom RPCs. Empty when they match.
24
+ */
25
+ export function checkCompatibility(api) {
26
+ const problems = [];
27
+ const specName = api.runtimeVersion.specName.toString();
28
+ if (specName !== SPEC_NAME) {
29
+ problems.push(`runtime is ${specName}, expected ${SPEC_NAME}`);
30
+ }
31
+ for (const [call, expected] of Object.entries(EXPECTED_CALLS)) {
32
+ const [section, method] = call.split('.');
33
+ const fn = api.tx[section]?.[method];
34
+ if (!fn) {
35
+ problems.push(`call ${call} is missing`);
36
+ continue;
37
+ }
38
+ const actual = fn.meta.args
39
+ .map((arg) => `${arg.name.toString()}: ${arg.type.toString()}`)
40
+ .join(', ');
41
+ if (actual !== expected) {
42
+ problems.push(`call ${call} takes (${actual}), the client sends (${expected})`);
43
+ }
44
+ }
45
+ // polkadot-js removes every RPC the node does not list in `rpc_methods`.
46
+ const rpc = api.rpc;
47
+ for (const [section, methods] of Object.entries(RPC_DEFINITIONS)) {
48
+ for (const method of Object.keys(methods)) {
49
+ if (typeof rpc[section]?.[method] !== 'function') {
50
+ problems.push(`RPC ${section}_${method} is missing`);
51
+ }
52
+ }
53
+ }
54
+ return problems;
55
+ }
@@ -1,6 +1,7 @@
1
1
  import { ApiPromise, WsProvider } from '@polkadot/api';
2
2
  import { RPC_DEFINITIONS } from '../rpc/definitions.js';
3
3
  import { CHAIN_TYPES } from '../rpc/types.js';
4
+ import { checkCompatibility, IncompatibleNodeError } from './compatibility.js';
4
5
  export function createClientFromApi(api) {
5
6
  const client = {
6
7
  api,
@@ -17,5 +18,15 @@ export async function createClient(options) {
17
18
  rpc: RPC_DEFINITIONS,
18
19
  types: CHAIN_TYPES,
19
20
  });
21
+ const mode = options.compatibility ?? 'warn';
22
+ const problems = mode === 'off' ? [] : checkCompatibility(api);
23
+ if (problems.length > 0) {
24
+ const error = new IncompatibleNodeError(problems);
25
+ if (mode === 'strict') {
26
+ await api.disconnect();
27
+ throw error;
28
+ }
29
+ console.warn(error.message);
30
+ }
20
31
  return createClientFromApi(api);
21
32
  }
@@ -1,2 +1 @@
1
1
  export { canonicalCTypeBytes, ctypeHash } from './ctypeHash.js';
2
- export { deriveClaimHash, didUri } from './claimHash.js';
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Renders an address as its DID URI: `did:toto:` followed by the address without its `0x`.
3
+ *
4
+ * The address is passed through verbatim, case included. Nothing hashes the string and the chain
5
+ * never sees it — the DID and attestation pallets identify the account by its typed H160 — so the
6
+ * case carries no meaning, and two URIs for one account can differ in case alone. Lowercase the
7
+ * address first if you compare URIs as strings; `pallet_did::did_uri` renders lowercase.
8
+ */
9
+ export function didUri(address) {
10
+ return `did:toto:${address.slice(2)}`;
11
+ }
package/_esm/index.js CHANGED
@@ -1,10 +1,12 @@
1
1
  export { createClient, createClientFromApi } from './client/createClient.js';
2
- export { activityTrackerPlugin, fractionalNftPlugin, handshakePlugin, potentialPlugin, referralPlugin, reputationVotingPlugin, rewardPoolPlugin, techCommitteeManagerPlugin, validatorManagerPlugin, } from './plugins/index.js';
2
+ export { checkCompatibility, EXPECTED_CALLS, IncompatibleNodeError, SPEC_NAME, } from './client/compatibility.js';
3
+ export { activityTrackerPlugin, handshakePlugin, potentialPlugin, puzzlePiecesPlugin, referralPlugin, reputationVotingPlugin, rewardPoolPlugin, techCommitteeManagerPlugin, validatorManagerPlugin, } from './plugins/index.js';
3
4
  export { RPC_DEFINITIONS } from './rpc/definitions.js';
4
5
  export { CHAIN_TYPES } from './rpc/types.js';
5
6
  export { TOTOCHAIN_DEFINITIONS, typesBundle } from './rpc/bundle.js';
6
7
  export { DEFAULT_PAGE_SIZE, MAX_PAGE_SIZE } from './types/index.js';
7
- export { canonicalCTypeBytes, ctypeHash, deriveClaimHash, didUri } from './crypto/index.js';
8
+ export { canonicalCTypeBytes, ctypeHash } from './crypto/index.js';
9
+ export { didUri } from './did/didUri.js';
8
10
  export { REGISTERED_CTYPES } from './ctypes/index.js';
9
11
  export { DispatchFailedError, isDispatchFailure, NotIncludedError, SubmitTimeoutError, SubscriptionFailedError, submitAndWait, } from './actions/submitAndWait.js';
10
12
  export { totochain, totochainDev, totochainLocal, totochainTestnet, defineChain, } from './chains/index.js';
@@ -1,7 +1,7 @@
1
1
  export { activityTrackerPlugin } from './activityTracker.js';
2
- export { fractionalNftPlugin } from './fractionalNft.js';
3
2
  export { handshakePlugin } from './handshake.js';
4
3
  export { potentialPlugin } from './potential.js';
4
+ export { puzzlePiecesPlugin } from './puzzlePieces.js';
5
5
  export { referralPlugin } from './referral.js';
6
6
  export { reputationVotingPlugin } from './reputationVoting.js';
7
7
  export { rewardPoolPlugin } from './rewardPool.js';
@@ -1,14 +1,14 @@
1
- import { getCollectionsCount, getItemsCount, getNftInfo, getOwner, getTotalFnftsMinted, getWildcardCollectionId, getWildcardDistributionMap, getWildcardThreshold, } from '../actions/fractionalNft/index.js';
2
- export function fractionalNftPlugin() {
1
+ import { getCollectionsCount, getItemsCount, getOwner, getPendingWildcards, getTotalPuzzlePiecesMinted, getWildcardCollectionId, getWildcardDistributionMap, getWildcardThreshold, } from '../actions/puzzlePieces/index.js';
2
+ export function puzzlePiecesPlugin() {
3
3
  return (client) => ({
4
- fractionalNft: {
4
+ puzzlePieces: {
5
5
  getWildcardThreshold: (p) => getWildcardThreshold(client, p),
6
6
  getWildcardCollectionId: (p) => getWildcardCollectionId(client, p),
7
7
  getWildcardDistributionMap: (p) => getWildcardDistributionMap(client, p),
8
- getTotalFnftsMinted: (p) => getTotalFnftsMinted(client, p),
8
+ getPendingWildcards: (p) => getPendingWildcards(client, p),
9
+ getTotalPuzzlePiecesMinted: (p) => getTotalPuzzlePiecesMinted(client, p),
9
10
  getCollectionsCount: (p) => getCollectionsCount(client, p),
10
11
  getItemsCount: (p) => getItemsCount(client, p),
11
- getNftInfo: (p) => getNftInfo(client, p),
12
12
  getOwner: (p) => getOwner(client, p),
13
13
  },
14
14
  });
@@ -1,11 +1,9 @@
1
- import { getCollectionIds, getItemIds, getRewardPoolAccount, getRewardPoolBalance, } from '../actions/rewardPool/index.js';
1
+ import { getRewardPoolAccount, getRewardPoolBalance } from '../actions/rewardPool/index.js';
2
2
  export function rewardPoolPlugin() {
3
3
  return (client) => ({
4
4
  rewardPool: {
5
5
  getAccount: (p) => getRewardPoolAccount(client, p),
6
6
  getBalance: (p) => getRewardPoolBalance(client, p),
7
- getCollectionIds: (p) => getCollectionIds(client, p),
8
- getItemIds: (p) => getItemIds(client, p),
9
7
  },
10
8
  });
11
9
  }