dash-platform-sdk 1.6.0-dev.7 → 1.6.0-dev.8

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 (56) hide show
  1. package/README.md +14 -14
  2. package/bundle.min.js +1 -1
  3. package/package.json +1 -1
  4. package/src/QueryExecutor.d.ts +40 -4
  5. package/src/QueryExecutor.js +61 -8
  6. package/src/constants.d.ts +7 -1
  7. package/src/constants.js +9 -2
  8. package/src/contestedResources/getContestedResourceVoteState.js +14 -6
  9. package/src/contestedResources/getVotePollsByEndDate.js +7 -2
  10. package/src/dataContracts/getDataContractByIdentifier.js +3 -3
  11. package/src/documents/index.d.ts +4 -1
  12. package/src/documents/index.js +6 -2
  13. package/src/documents/query.js +4 -4
  14. package/src/documents/queryAggregate.js +2 -3
  15. package/src/documents/queryJoined.js +6 -7
  16. package/src/documents/queryRanked.js +2 -3
  17. package/src/documents/v1.d.ts +2 -2
  18. package/src/documents/v1.js +2 -3
  19. package/src/grpcConnectionPool.d.ts +9 -2
  20. package/src/grpcConnectionPool.js +7 -8
  21. package/src/identities/getIdentityBalance.js +1 -2
  22. package/src/identities/getIdentityByIdentifier.js +1 -2
  23. package/src/identities/getIdentityByNonUniquePublicKeyHash.js +2 -3
  24. package/src/identities/getIdentityByPublicKeyHash.js +1 -2
  25. package/src/identities/getIdentityContractNonce.js +1 -2
  26. package/src/identities/getIdentityNonce.js +1 -2
  27. package/src/identities/getIdentityPublicKeys.js +1 -2
  28. package/src/names/index.d.ts +1 -1
  29. package/src/names/index.js +1 -1
  30. package/src/names/registerName.js +5 -2
  31. package/src/node/epochInfos.js +1 -2
  32. package/src/node/finalizedEpochInfos.js +1 -2
  33. package/src/node/getProtocolVersion.d.ts +9 -0
  34. package/src/node/getProtocolVersion.js +29 -0
  35. package/src/node/index.d.ts +9 -0
  36. package/src/node/index.js +11 -0
  37. package/src/node/totalCredits.js +3 -3
  38. package/src/platformAddresses/getAddressInfo.js +1 -2
  39. package/src/platformAddresses/getAddressesBranchState.js +1 -2
  40. package/src/platformAddresses/getAddressesInfos.js +1 -2
  41. package/src/platformAddresses/getAddressesTrunkState.js +1 -2
  42. package/src/platformAddresses/getRecentAddressBalanceChanges.js +2 -2
  43. package/src/platformAddresses/getRecentCompactedAddressBalanceChanges.js +2 -2
  44. package/src/shielded/getMostRecentShieldedAnchor.js +1 -2
  45. package/src/shielded/getShieldedAnchors.js +1 -2
  46. package/src/shielded/getShieldedEncryptedNotes.js +2 -2
  47. package/src/shielded/getShieldedNotesCount.js +1 -2
  48. package/src/shielded/getShieldedNullifiers.js +1 -2
  49. package/src/shielded/getShieldedPoolState.js +1 -2
  50. package/src/stateTransitions/waitForStateTransitionResult.js +13 -11
  51. package/src/tokens/getIdentitiesTokenBalances.js +1 -2
  52. package/src/tokens/getIdentityTokensBalances.js +1 -2
  53. package/src/tokens/getTokenContractInfo.js +1 -2
  54. package/src/tokens/getTokenDirectPurchasePrices.js +1 -2
  55. package/src/tokens/getTokenTotalSupply.js +1 -2
  56. package/test/unit/SDK.spec.js +38 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dash-platform-sdk",
3
- "version": "1.6.0-dev.7",
3
+ "version": "1.6.0-dev.8",
4
4
  "main": "index.js",
5
5
  "description": "Lightweight SDK for accessing Dash Platform blockchain",
6
6
  "repository": {
@@ -2,6 +2,7 @@ import { PlatformClient } from '../proto/generated/platform.client.js';
2
2
  import { Proof, ResponseMetadata } from '../proto/generated/platform.js';
3
3
  import { GRPCPool } from './grpcConnectionPool.js';
4
4
  import { QuorumKeyProvider } from './quorumKeyProvider.js';
5
+ import { PlatformVersionWASM } from 'pshenmic-dpp';
5
6
  type SubType<Base, Condition> = Pick<Base, {
6
7
  [Key in keyof Base]: Base[Key] extends Condition ? Key : never;
7
8
  }[keyof Base]>;
@@ -15,6 +16,7 @@ export interface ResponseProof {
15
16
  }
16
17
  type MapProof<Response, P extends ResponseProof = ResponseProof> = (response: Response) => P;
17
18
  type GroveDBVerifier<Args extends unknown[], V> = (grovedbProof: Uint8Array, ...args: Args) => V;
19
+ type GetVerifierArgs<P, Args> = (responseProof: P, platformVersion: PlatformVersionWASM) => Args;
18
20
  /**
19
21
  * Body of the version (e.g. `v0`) of a versioned response, distributed over all versions
20
22
  */
@@ -39,12 +41,37 @@ export type QueryData<Response, V> = {
39
41
  proved: true;
40
42
  verified: V;
41
43
  metadata: ResponseMetadata;
44
+ /** Platform version the proof was verified with, see {getVerifierVersion} **/
45
+ platformVersion: PlatformVersionWASM;
42
46
  } | {
43
47
  proved: false;
44
48
  result: ResponseResult<Response>;
45
49
  metadata: ResponseMetadata;
50
+ /**
51
+ * Platform version to parse the response with, the protocol version of the response is used to parse it
52
+ * (like the response itself, it is not verified), but it is not learned by the pool
53
+ */
54
+ platformVersion: PlatformVersionWASM;
46
55
  };
47
56
  type MapResponse<Response, V, T> = (data: QueryData<Response, V>) => T | Promise<T>;
57
+ /**
58
+ * Returns the highest protocol version of the responses of the pool whose proof and quorum signature were verified,
59
+ * or undefined if no response was verified yet
60
+ */
61
+ export declare function getVerifiedProtocolVersion(grpcPool: GRPCPool): number | undefined;
62
+ /**
63
+ * Returns the protocol version of the pool, the lowest version the network runs if it was not learned yet
64
+ */
65
+ export declare function getPoolProtocolVersion(grpcPool: GRPCPool): PlatformVersionWASM;
66
+ /**
67
+ * Returns the platform version to verify a response signed with the given protocol version.
68
+ * A newer signed version is used (up to the latest version known to the SDK), an older one is not,
69
+ * so a node behind the network fails the verification and the request is sent to another node.
70
+ *
71
+ * Choosing the version before the quorum signature is verified is safe:
72
+ * the signature covers the protocol version, so a false version fails the verification
73
+ */
74
+ export declare function getVerifierVersion(protocolVersion: number, signedProtocolVersion: number): PlatformVersionWASM;
48
75
  /**
49
76
  * Minimal shape of a v0 response that may contain a proof
50
77
  */
@@ -68,9 +95,12 @@ export declare function getResponseProof(response: ProvedResponse): ResponseProo
68
95
  * Sends a GRPC request to a node from the pool and returns the mapped result of the response.
69
96
  *
70
97
  * Queries are requested with proofs, unless proofs are disabled in the pool (`grpcPool.proofs === false`):
71
- * - with proofs: request (`prove: true`) -> proof mapping -> GroveDB proof verification -> quorum signature verification -> mapping
98
+ * - with proofs: request (`prove: true`) -> proof mapping -> GroveDB proof verification -> quorum signature verification -> protocol version update -> mapping
72
99
  * - without proofs: request (`prove: false`) -> mapping of the response result
73
100
  *
101
+ * The protocol version of the pool is raised to the protocol version of the verified responses,
102
+ * the platform version to verify the proof with is passed to the args callback of the proof verifier, see {getVerifierVersion}
103
+ *
74
104
  * `mapResponse` handles both cases, the verified data or the response result, see {QueryData}.
75
105
  * Requests without the `prove` field are always proved
76
106
  *
@@ -80,7 +110,7 @@ export declare function getResponseProof(response: ProvedResponse): ResponseProo
80
110
  * @example
81
111
  * const balance = await QueryExecutor.build(grpcPool, quorumKeyProvider)
82
112
  * .setGrpcRequest('getIdentityBalance', request)
83
- * .setProofVerifier(verifyIdentityBalanceProof, id.bytes(), true, LATEST_PLATFORM_VERSION)
113
+ * .setProofVerifier(verifyIdentityBalanceProof, (_, platformVersion) => [id.bytes(), true, platformVersion])
84
114
  * .mapResponse(data => data.proved ? data.verified.balance : BigInt(data.result.balance))
85
115
  * .execute()
86
116
  */
@@ -102,10 +132,11 @@ export default class QueryExecutor<Response = unknown, V = unknown, T = unknown,
102
132
  mapProof<E extends ResponseProof>(mapProof: MapProof<Response, E>): QueryExecutor<Response, V, T, E>;
103
133
  /**
104
134
  * Sets the GroveDB proof verification function, which is called with the GroveDB proof of the response
105
- * followed by the given args. Args depending on the response (e.g. metadata) can be passed as a callback.
135
+ * followed by the given args. Args depending on the response (e.g. metadata) or the platform version
136
+ * to verify the proof with can be passed as a callback.
106
137
  * Failure of the verification is thrown as ProofError, so the request is retried on another node
107
138
  */
108
- setProofVerifier<Args extends unknown[] | [], U>(verify: GroveDBVerifier<Args, U>, getArgs: (responseProof: P) => NoInfer<Args>): QueryExecutor<Response, U, T, P>;
139
+ setProofVerifier<Args extends unknown[] | [], U>(verify: GroveDBVerifier<Args, U>, getArgs: GetVerifierArgs<P, NoInfer<Args>>): QueryExecutor<Response, U, T, P>;
109
140
  setProofVerifier<Args extends unknown[] | [], U>(verify: GroveDBVerifier<Args, U>, ...args: Args): QueryExecutor<Response, U, T, P>;
110
141
  /**
111
142
  * Sets the mapping of the query data to the result of the query, also the place for "not found" checks.
@@ -117,6 +148,11 @@ export default class QueryExecutor<Response = unknown, V = unknown, T = unknown,
117
148
  * e.g. if the GroveDB proof is verified against an already verified root hash
118
149
  */
119
150
  setValidateProof(validateProof: boolean): this;
151
+ /**
152
+ * Requests and verifies the proof even if proofs are disabled in the pool,
153
+ * e.g. to learn the protocol version of the network from a verified response
154
+ */
155
+ setRequireProof(requireProof: boolean): this;
120
156
  execute(): Promise<T>;
121
157
  }
122
158
  export {};
@@ -2,6 +2,7 @@ import bytesToHex from './utils/bytesToHex.js';
2
2
  import verifyTenderdashProof from './utils/verifyTenderdashProof.js';
3
3
  import ProofError from './utils/ProofError.js';
4
4
  import sleep from './utils/sleep.js';
5
+ import { LATEST_PLATFORM_VERSION, MIN_PROTOCOL_VERSION } from './constants.js';
5
6
  const RETRY_DELAY_MS = 10;
6
7
  /**
7
8
  * Returns the versioned body of a request or a response (e.g. `version.v0`)
@@ -13,6 +14,42 @@ function getVersionBody(message) {
13
14
  }
14
15
  return version[version.oneofKind];
15
16
  }
17
+ // highest protocol version of the verified responses of the pool, unlike `grpcPool.protocolVersion` it is never seeded
18
+ const verifiedProtocolVersions = new WeakMap();
19
+ /**
20
+ * Returns the highest protocol version of the responses of the pool whose proof and quorum signature were verified,
21
+ * or undefined if no response was verified yet
22
+ */
23
+ export function getVerifiedProtocolVersion(grpcPool) {
24
+ return verifiedProtocolVersions.get(grpcPool);
25
+ }
26
+ /**
27
+ * Returns the protocol version of the pool, the lowest version the network runs if it was not learned yet
28
+ */
29
+ export function getPoolProtocolVersion(grpcPool) {
30
+ return Math.min(grpcPool.protocolVersion ?? MIN_PROTOCOL_VERSION[grpcPool.network], LATEST_PLATFORM_VERSION);
31
+ }
32
+ /**
33
+ * Returns the platform version to verify a response signed with the given protocol version.
34
+ * A newer signed version is used (up to the latest version known to the SDK), an older one is not,
35
+ * so a node behind the network fails the verification and the request is sent to another node.
36
+ *
37
+ * Choosing the version before the quorum signature is verified is safe:
38
+ * the signature covers the protocol version, so a false version fails the verification
39
+ */
40
+ export function getVerifierVersion(protocolVersion, signedProtocolVersion) {
41
+ return Math.min(Math.max(protocolVersion, signedProtocolVersion), LATEST_PLATFORM_VERSION);
42
+ }
43
+ /**
44
+ * Raises the protocol version of the pool to the one of a response whose proof and quorum signature were verified.
45
+ * The version is never lowered, versions unknown to the SDK are ignored
46
+ */
47
+ function updateProtocolVersion(grpcPool, signedProtocolVersion) {
48
+ verifiedProtocolVersions.set(grpcPool, Math.max(verifiedProtocolVersions.get(grpcPool) ?? 0, signedProtocolVersion));
49
+ if (signedProtocolVersion > getPoolProtocolVersion(grpcPool) && signedProtocolVersion <= LATEST_PLATFORM_VERSION) {
50
+ grpcPool.protocolVersion = signedProtocolVersion;
51
+ }
52
+ }
16
53
  /**
17
54
  * Returns the proof and the metadata of a v0 response, requested with `prove: true`
18
55
  */
@@ -34,9 +71,12 @@ export function getResponseProof(response) {
34
71
  * Sends a GRPC request to a node from the pool and returns the mapped result of the response.
35
72
  *
36
73
  * Queries are requested with proofs, unless proofs are disabled in the pool (`grpcPool.proofs === false`):
37
- * - with proofs: request (`prove: true`) -> proof mapping -> GroveDB proof verification -> quorum signature verification -> mapping
74
+ * - with proofs: request (`prove: true`) -> proof mapping -> GroveDB proof verification -> quorum signature verification -> protocol version update -> mapping
38
75
  * - without proofs: request (`prove: false`) -> mapping of the response result
39
76
  *
77
+ * The protocol version of the pool is raised to the protocol version of the verified responses,
78
+ * the platform version to verify the proof with is passed to the args callback of the proof verifier, see {getVerifierVersion}
79
+ *
40
80
  * `mapResponse` handles both cases, the verified data or the response result, see {QueryData}.
41
81
  * Requests without the `prove` field are always proved
42
82
  *
@@ -46,7 +86,7 @@ export function getResponseProof(response) {
46
86
  * @example
47
87
  * const balance = await QueryExecutor.build(grpcPool, quorumKeyProvider)
48
88
  * .setGrpcRequest('getIdentityBalance', request)
49
- * .setProofVerifier(verifyIdentityBalanceProof, id.bytes(), true, LATEST_PLATFORM_VERSION)
89
+ * .setProofVerifier(verifyIdentityBalanceProof, (_, platformVersion) => [id.bytes(), true, platformVersion])
50
90
  * .mapResponse(data => data.proved ? data.verified.balance : BigInt(data.result.balance))
51
91
  * .execute()
52
92
  */
@@ -59,6 +99,7 @@ export default class QueryExecutor {
59
99
  #verifyProof;
60
100
  #mapResponse;
61
101
  #validateProof = true;
102
+ #requireProof = false;
62
103
  constructor(grpcPool, quorumKeyProvider) {
63
104
  this.#grpcPool = grpcPool;
64
105
  this.#quorumKeyProvider = quorumKeyProvider;
@@ -93,9 +134,9 @@ export default class QueryExecutor {
93
134
  const getArgs = args.length === 1 && typeof args[0] === 'function'
94
135
  ? args[0]
95
136
  : () => args;
96
- executor.#verifyProof = (responseProof) => {
137
+ executor.#verifyProof = (responseProof, platformVersion) => {
97
138
  try {
98
- return verify(responseProof.proof.grovedbProof, ...getArgs(responseProof));
139
+ return verify(responseProof.proof.grovedbProof, ...getArgs(responseProof, platformVersion));
99
140
  }
100
141
  catch (e) {
101
142
  throw new ProofError(`Failed to verify GroveDB proof: ${String(e)}`, { cause: e });
@@ -120,6 +161,14 @@ export default class QueryExecutor {
120
161
  this.#validateProof = validateProof;
121
162
  return this;
122
163
  }
164
+ /**
165
+ * Requests and verifies the proof even if proofs are disabled in the pool,
166
+ * e.g. to learn the protocol version of the network from a verified response
167
+ */
168
+ setRequireProof(requireProof) {
169
+ this.#requireProof = requireProof;
170
+ return this;
171
+ }
123
172
  async execute() {
124
173
  const request = this.#request;
125
174
  const mapResponse = this.#mapResponse;
@@ -134,7 +183,7 @@ export default class QueryExecutor {
134
183
  }
135
184
  const requestBody = getVersionBody(this.#requestMessage);
136
185
  const canSkipProof = requestBody != null && 'prove' in requestBody;
137
- const prove = this.#grpcPool.proofs !== false || !canSkipProof;
186
+ const prove = this.#requireProof || this.#grpcPool.proofs !== false || !canSkipProof;
138
187
  if (canSkipProof) {
139
188
  requestBody.prove = prove;
140
189
  }
@@ -152,7 +201,7 @@ export default class QueryExecutor {
152
201
  if (metadata == null) {
153
202
  throw new Error('Metadata not found');
154
203
  }
155
- return { proved: false, result: result, metadata };
204
+ return { proved: false, result: result, metadata, platformVersion: getVerifierVersion(getPoolProtocolVersion(this.#grpcPool), metadata.protocolVersion) };
156
205
  }
157
206
  async #executeWithProof(request) {
158
207
  const verifyProof = this.#verifyProof;
@@ -172,12 +221,16 @@ export default class QueryExecutor {
172
221
  try {
173
222
  const { response } = await request(client);
174
223
  const responseProof = this.#mapProof(response);
175
- const verified = verifyProof(responseProof);
224
+ const { metadata } = responseProof;
225
+ const platformVersion = getVerifierVersion(getPoolProtocolVersion(grpcPool), metadata.protocolVersion);
226
+ const verified = verifyProof(responseProof, platformVersion);
176
227
  if (this.#validateProof) {
177
228
  await this.#verifySignature(responseProof, verified.rootHash);
229
+ // protocol version is learned only from the responses with verified quorum signature
230
+ updateProtocolVersion(grpcPool, metadata.protocolVersion);
178
231
  grpcPool.unbanNode?.(client);
179
232
  }
180
- return { proved: true, verified, metadata: responseProof.metadata };
233
+ return { proved: true, verified, metadata, platformVersion };
181
234
  }
182
235
  catch (e) {
183
236
  if (!(e instanceof ProofError)) {
@@ -1,4 +1,5 @@
1
1
  import { PlatformVersionWASM } from 'pshenmic-dpp';
2
+ import { Network } from '../types.js';
2
3
  /**
3
4
  * Default amount of documents to retrieve from DAPI
4
5
  */
@@ -15,6 +16,11 @@ export declare const GRPC_DEFAULT_POOL_LIMIT = 5;
15
16
  export declare const RECENT_ADDRESS_BALANCE_CHANGES_LIMIT = 100;
16
17
  export declare const RECENT_COMPACTED_ADDRESS_BALANCE_CHANGES_LIMIT = 25;
17
18
  export declare const DPNS_DATA_CONTRACT_ID = "GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec";
19
+ export declare const WITHDRAWALS_DATA_CONTRACT_ID = "4fJLR2GYTPFdomuTVvNy3VRrvWgvkKPzqehEBpNf2nk6";
18
20
  export declare const DPNS_DATA_CONTRACT_BYTES = "AeZoxlmvZq7h5ywYbd57W34KHXEqCcQNVyH2Ir9TxTFVAAAAAAABAQAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIGZG9tYWluFgsSEGRvY3VtZW50c011dGFibGUTABIMY2FuQmVEZWxldGVkEwESDHRyYW5zZmVyYWJsZQIBEgl0cmFkZU1vZGUCARIEdHlwZRIGb2JqZWN0EgdpbmRpY2VzFQIWBBIEbmFtZRIScGFyZW50TmFtZUFuZExhYmVsEgpwcm9wZXJ0aWVzFQIWARIabm9ybWFsaXplZFBhcmVudERvbWFpbk5hbWUSA2FzYxYBEg9ub3JtYWxpemVkTGFiZWwSA2FzYxIGdW5pcXVlEwESCWNvbnRlc3RlZBYDEgxmaWVsZE1hdGNoZXMVARYCEgVmaWVsZBIPbm9ybWFsaXplZExhYmVsEgxyZWdleFBhdHRlcm4SE15bYS16QS1aMDEtXXszLDE5fSQSCnJlc29sdXRpb24CABILZGVzY3JpcHRpb24SqklmIHRoZSBub3JtYWxpemVkIGxhYmVsIHBhcnQgb2YgdGhpcyBpbmRleCBpcyBsZXNzIHRoYW4gMjAgY2hhcmFjdGVycyAoYWxsIGFscGhhYmV0IGEteiwgQS1aLCAwLCAxLCBhbmQgLSkgdGhlbiBhIG1hc3Rlcm5vZGUgdm90ZSBjb250ZXN0IHRha2VzIHBsYWNlIHRvIGdpdmUgb3V0IHRoZSBuYW1lFgMSBG5hbWUSCmlkZW50aXR5SWQSDm51bGxTZWFyY2hhYmxlEwASCnByb3BlcnRpZXMVARYBEhByZWNvcmRzLmlkZW50aXR5EgNhc2MSCnByb3BlcnRpZXMWBxIFbGFiZWwWBhIEdHlwZRIGc3R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IG1hbi1pbi10aGUtbWlkZGxlIGF0dGFja3MuIG5vcm1hbGl6ZWRMYWJlbCArICcuJyArIG5vcm1hbGl6ZWRQYXJlbnREb21haW4gbXVzdCBub3QgYmUgbG9uZ2VyIHRoYW4gMjUzIGNoYXJzIGxlbmd0aCBhcyBkZWZpbmVkIGJ5IFJGQyAxMDM1LiBEb21haW4gZG9jdW1lbnRzIGFyZSBpbW11dGFibGU6IG1vZGlmaWNhdGlvbiBhbmQgZGVsZXRpb24gYXJlIHJlc3RyaWN0ZWQIcHJlb3JkZXIWCBIQZG9jdW1lbnRzTXV0YWJsZRMAEgxjYW5CZURlbGV0ZWQTARIEdHlwZRIGb2JqZWN0EgdpbmRpY2VzFQEWAxIEbmFtZRIKc2FsdGVkSGFzaBIKcHJvcGVydGllcxUBFgESEHNhbHRlZERvbWFpbkhhc2gSA2FzYxIGdW5pcXVlEwESCnByb3BlcnRpZXMWARIQc2FsdGVkRG9tYWluSGFzaBYGEgR0eXBlEgVhcnJheRIJYnl0ZUFycmF5EwESCG1pbkl0ZW1zAiASCG1heEl0ZW1zAiASCHBvc2l0aW9uAgASC2Rlc2NyaXB0aW9uEllEb3VibGUgc2hhLTI1NiBvZiB0aGUgY29uY2F0ZW5hdGlvbiBvZiBhIDMyIGJ5dGUgcmFuZG9tIHNhbHQgYW5kIGEgbm9ybWFsaXplZCBkb21haW4gbmFtZRIIcmVxdWlyZWQVARIQc2FsdGVkRG9tYWluSGFzaBIUYWRkaXRpb25hbFByb3BlcnRpZXMTABIIJGNvbW1lbnQSSlByZW9yZGVyIGRvY3VtZW50cyBhcmUgaW1tdXRhYmxlOiBtb2RpZmljYXRpb24gYW5kIGRlbGV0aW9uIGFyZSByZXN0cmljdGVkAAAAAAAAAAAAAA==";
19
21
  export declare const LATEST_PLATFORM_VERSION = PlatformVersionWASM.PLATFORM_V14;
20
- export declare const SHIELDED_PLATFORM_VERSION = PlatformVersionWASM.PLATFORM_V13;
22
+ /**
23
+ * Protocol version the SDK starts with before it learns the protocol version of the network,
24
+ * the lowest version the network still runs. It is raised by the verified responses, see {GRPCPool.protocolVersion}
25
+ */
26
+ export declare const MIN_PROTOCOL_VERSION: Record<Network, PlatformVersionWASM>;
package/src/constants.js CHANGED
@@ -15,7 +15,14 @@ export const GRPC_DEFAULT_POOL_LIMIT = 5;
15
15
  export const RECENT_ADDRESS_BALANCE_CHANGES_LIMIT = 100;
16
16
  export const RECENT_COMPACTED_ADDRESS_BALANCE_CHANGES_LIMIT = 25;
17
17
  export const DPNS_DATA_CONTRACT_ID = 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec';
18
+ export const WITHDRAWALS_DATA_CONTRACT_ID = '4fJLR2GYTPFdomuTVvNy3VRrvWgvkKPzqehEBpNf2nk6';
18
19
  export const DPNS_DATA_CONTRACT_BYTES = 'AeZoxlmvZq7h5ywYbd57W34KHXEqCcQNVyH2Ir9TxTFVAAAAAAABAQAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIGZG9tYWluFgsSEGRvY3VtZW50c011dGFibGUTABIMY2FuQmVEZWxldGVkEwESDHRyYW5zZmVyYWJsZQIBEgl0cmFkZU1vZGUCARIEdHlwZRIGb2JqZWN0EgdpbmRpY2VzFQIWBBIEbmFtZRIScGFyZW50TmFtZUFuZExhYmVsEgpwcm9wZXJ0aWVzFQIWARIabm9ybWFsaXplZFBhcmVudERvbWFpbk5hbWUSA2FzYxYBEg9ub3JtYWxpemVkTGFiZWwSA2FzYxIGdW5pcXVlEwESCWNvbnRlc3RlZBYDEgxmaWVsZE1hdGNoZXMVARYCEgVmaWVsZBIPbm9ybWFsaXplZExhYmVsEgxyZWdleFBhdHRlcm4SE15bYS16QS1aMDEtXXszLDE5fSQSCnJlc29sdXRpb24CABILZGVzY3JpcHRpb24SqklmIHRoZSBub3JtYWxpemVkIGxhYmVsIHBhcnQgb2YgdGhpcyBpbmRleCBpcyBsZXNzIHRoYW4gMjAgY2hhcmF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zaBIUYWRkaXRpb25hbFByb3BlcnRpZXMTABIIJGNvbW1lbnQSSlByZW9yZGVyIGRvY3VtZW50cyBhcmUgaW1tdXRhYmxlOiBtb2RpZmljYXRpb24gYW5kIGRlbGV0aW9uIGFyZSByZXN0cmljdGVkAAAAAAAAAAAAAA==';
19
20
  export const LATEST_PLATFORM_VERSION = PlatformVersionWASM.PLATFORM_V14;
20
- // TODO: must be deleted after mainnet migrate to v14
21
- export const SHIELDED_PLATFORM_VERSION = PlatformVersionWASM.PLATFORM_V13;
21
+ /**
22
+ * Protocol version the SDK starts with before it learns the protocol version of the network,
23
+ * the lowest version the network still runs. It is raised by the verified responses, see {GRPCPool.protocolVersion}
24
+ */
25
+ export const MIN_PROTOCOL_VERSION = {
26
+ mainnet: PlatformVersionWASM.PLATFORM_V13,
27
+ testnet: PlatformVersionWASM.PLATFORM_V13
28
+ };
@@ -1,7 +1,6 @@
1
1
  import { GetContestedResourceVoteStateRequest, GetContestedResourceVoteStateResponse_GetContestedResourceVoteStateResponseV0_FinishedVoteInfo_FinishedVoteOutcome as FinishedVoteOutcome } from '../../proto/generated/platform.js';
2
2
  import { DocumentWASM, IdentifierWASM, verifyVotePollVoteStateProof } from 'pshenmic-dpp';
3
3
  import QueryExecutor from '../QueryExecutor.js';
4
- import { LATEST_PLATFORM_VERSION } from '../constants.js';
5
4
  // winner types of the proof verification by finished vote outcome of the response
6
5
  const FINISHED_VOTE_OUTCOMES = {
7
6
  [FinishedVoteOutcome.TOWARDS_IDENTITY]: 'WonByIdentity',
@@ -33,12 +32,21 @@ export default async function getContestedResourceVoteState(grpcPool, quorumKeyP
33
32
  });
34
33
  return await QueryExecutor.build(grpcPool, quorumKeyProvider)
35
34
  .setGrpcRequest('getContestedResourceVoteState', getContestedResourceVoteStateRequest)
36
- .setProofVerifier(verifyVotePollVoteStateProof, contract, documentTypeName, indexName, indexValues,
37
- // same enums
38
- // @ts-expect-error
39
- resultType, allowIncludeLockedAndAbstainingVoteTally, count, startAtIdentifierInfo, LATEST_PLATFORM_VERSION)
35
+ .setProofVerifier(verifyVotePollVoteStateProof, (_, platformVersion) => [
36
+ contract,
37
+ documentTypeName,
38
+ indexName,
39
+ indexValues,
40
+ // same enums
41
+ // @ts-expect-error
42
+ resultType,
43
+ allowIncludeLockedAndAbstainingVoteTally,
44
+ count,
45
+ startAtIdentifierInfo,
46
+ platformVersion
47
+ ])
40
48
  .mapResponse(data => {
41
- const toDocument = (bytes) => bytes != null ? DocumentWASM.fromBytes(bytes, contract, documentTypeName, LATEST_PLATFORM_VERSION) : undefined;
49
+ const toDocument = (bytes) => bytes != null ? DocumentWASM.fromBytes(bytes, contract, documentTypeName, data.platformVersion) : undefined;
42
50
  if (data.proved) {
43
51
  const { result: voteState } = data.verified;
44
52
  const { contenders } = voteState ?? { contenders: [] };
@@ -1,7 +1,6 @@
1
1
  import { VotePollWASM, verifyVotePollsByEndDateProof } from 'pshenmic-dpp';
2
2
  import { GetVotePollsByEndDateRequest } from '../../proto/generated/platform.js';
3
3
  import QueryExecutor from '../QueryExecutor.js';
4
- import { LATEST_PLATFORM_VERSION } from '../constants.js';
5
4
  export default async function getVotePollsByEndDate(grpcPool, quorumKeyProvider, startTime, endTime, limit, ascending = true) {
6
5
  const getVotePollsByEndDateRequest = GetVotePollsByEndDateRequest.create({
7
6
  version: {
@@ -21,7 +20,13 @@ export default async function getVotePollsByEndDate(grpcPool, quorumKeyProvider,
21
20
  });
22
21
  return await QueryExecutor.build(grpcPool, quorumKeyProvider)
23
22
  .setGrpcRequest('getVotePollsByEndDate', getVotePollsByEndDateRequest)
24
- .setProofVerifier(verifyVotePollsByEndDateProof, startTime, endTime, limit, ascending, LATEST_PLATFORM_VERSION)
23
+ .setProofVerifier(verifyVotePollsByEndDateProof, (_, platformVersion) => [
24
+ startTime,
25
+ endTime,
26
+ limit,
27
+ ascending,
28
+ platformVersion
29
+ ])
25
30
  .mapResponse(data => {
26
31
  if (data.proved) {
27
32
  return data.verified.votePolls;
@@ -1,7 +1,7 @@
1
1
  import { DataContractWASM, IdentifierWASM, verifyContractProof } from 'pshenmic-dpp';
2
2
  import { GetDataContractRequest } from '../../proto/generated/platform.js';
3
3
  import QueryExecutor from '../QueryExecutor.js';
4
- import { DPNS_DATA_CONTRACT_BYTES, DPNS_DATA_CONTRACT_ID, LATEST_PLATFORM_VERSION } from '../constants.js';
4
+ import { DPNS_DATA_CONTRACT_BYTES, DPNS_DATA_CONTRACT_ID } from '../constants.js';
5
5
  export default async function getByIdentifier(grpcPool, quorumKeyProvider, identifier) {
6
6
  const id = new IdentifierWASM(identifier);
7
7
  if (id.base58() === DPNS_DATA_CONTRACT_ID) {
@@ -18,11 +18,11 @@ export default async function getByIdentifier(grpcPool, quorumKeyProvider, ident
18
18
  });
19
19
  return await QueryExecutor.build(grpcPool, quorumKeyProvider)
20
20
  .setGrpcRequest('getDataContract', getDataContractRequest)
21
- .setProofVerifier(verifyContractProof, undefined, false, false, id.bytes(), LATEST_PLATFORM_VERSION)
21
+ .setProofVerifier(verifyContractProof, (_, platformVersion) => [undefined, false, false, id.bytes(), platformVersion])
22
22
  .mapResponse(data => {
23
23
  const dataContract = data.proved
24
24
  ? data.verified.dataContract
25
- : DataContractWASM.fromBytes(data.result.dataContract, false, LATEST_PLATFORM_VERSION);
25
+ : DataContractWASM.fromBytes(data.result.dataContract, false, data.platformVersion);
26
26
  if (dataContract == null) {
27
27
  throw new Error(`Data Contract with identifier ${id.base58()} not found`);
28
28
  }
@@ -24,7 +24,10 @@ export declare class DocumentsController {
24
24
  * @param owner {IdentifierLike} Identifier of the document's owner
25
25
  * @param identityContractNonce {bigint} Identity contract nonce of the transition that will create the document, used for document id generation
26
26
  * @param revision {bigint=} revision (optional)
27
- * @param platformVersion {PlatformVersionLike=} platform version used to create the document (optional, latest by default)
27
+ * @param platformVersion {PlatformVersionLike=} platform version used to create the document (optional).
28
+ * By default, the protocol version of the network learned from the verified responses is used, it determines
29
+ * the document id generation (v13 and v14 generate different ids). If no response was verified yet,
30
+ * call {NodeController.getProtocolVersion} first
28
31
  *
29
32
  * @return {DataContractWASM}
30
33
  */
@@ -2,6 +2,7 @@ import createDocument from './create.js';
2
2
  import { AgreedFeeMultiplierWASM, DocumentActionFeeAgreementWASM, IdentifierWASM, PrefundedVotingBalanceWASM, TokenPaymentInfoWASM } from 'pshenmic-dpp';
3
3
  import createStateTransition from './createStateTransition.js';
4
4
  import query from './query.js';
5
+ import { getPoolProtocolVersion } from '../QueryExecutor.js';
5
6
  import getActionFeeAgreement from './getActionFeeAgreement.js';
6
7
  import queryAggregate from './queryAggregate.js';
7
8
  import { queryHaving, queryRanked } from './queryRanked.js';
@@ -29,12 +30,15 @@ export class DocumentsController {
29
30
  * @param owner {IdentifierLike} Identifier of the document's owner
30
31
  * @param identityContractNonce {bigint} Identity contract nonce of the transition that will create the document, used for document id generation
31
32
  * @param revision {bigint=} revision (optional)
32
- * @param platformVersion {PlatformVersionLike=} platform version used to create the document (optional, latest by default)
33
+ * @param platformVersion {PlatformVersionLike=} platform version used to create the document (optional).
34
+ * By default, the protocol version of the network learned from the verified responses is used, it determines
35
+ * the document id generation (v13 and v14 generate different ids). If no response was verified yet,
36
+ * call {NodeController.getProtocolVersion} first
33
37
  *
34
38
  * @return {DataContractWASM}
35
39
  */
36
40
  create(dataContractId, documentType, data, owner, identityContractNonce, revision, platformVersion) {
37
- return createDocument(new IdentifierWASM(dataContractId), documentType, data, new IdentifierWASM(owner), identityContractNonce, revision, undefined, platformVersion);
41
+ return createDocument(new IdentifierWASM(dataContractId), documentType, data, new IdentifierWASM(owner), identityContractNonce, revision, undefined, platformVersion ?? getPoolProtocolVersion(this.grpcPool));
38
42
  }
39
43
  /**
40
44
  * Make a query for documents retrieval from the network.
@@ -1,5 +1,5 @@
1
1
  import { IdentifierWASM, verifyDocumentsProof } from 'pshenmic-dpp';
2
- import { DAPI_DEFAULT_LIMIT, LATEST_PLATFORM_VERSION } from '../constants.js';
2
+ import { DAPI_DEFAULT_LIMIT } from '../constants.js';
3
3
  import getDataContractByIdentifier from '../dataContracts/getDataContractByIdentifier.js';
4
4
  import QueryExecutor from '../QueryExecutor.js';
5
5
  import { createDocumentsV1Request, getDocumentsV1Data, getDocumentsV1Proof, toDocuments, toOrderClauses, toStart, toWhereClauses } from './v1.js';
@@ -18,12 +18,12 @@ export default async function query(grpcPool, quorumKeyProvider, dataContractId,
18
18
  return await QueryExecutor.build(grpcPool, quorumKeyProvider)
19
19
  .setGrpcRequest('getDocuments', request)
20
20
  .mapProof(getDocumentsV1Proof)
21
- .setProofVerifier(verifyDocumentsProof, ({ metadata }) => {
21
+ .setProofVerifier(verifyDocumentsProof, ({ metadata }, platformVersion) => {
22
22
  const metadataTimeMs = BigInt(metadata.timeMs);
23
- return [dataContract, documentTypeName, where, orderBy, limit, startIdentifier?.bytes(), startAtIncluded, metadataTimeMs, LATEST_PLATFORM_VERSION, metadataTimeMs];
23
+ return [dataContract, documentTypeName, where, orderBy, limit, startIdentifier?.bytes(), startAtIncluded, metadataTimeMs, platformVersion, metadataTimeMs];
24
24
  })
25
25
  .mapResponse(data => data.proved
26
26
  ? data.verified.documents ?? []
27
- : toDocuments(getDocumentsV1Data(data.result, 'documents').documents, dataContract, documentTypeName))
27
+ : toDocuments(getDocumentsV1Data(data.result, 'documents').documents, dataContract, documentTypeName, data.platformVersion))
28
28
  .execute();
29
29
  }
@@ -1,5 +1,4 @@
1
1
  import { IdentifierWASM, verifyDocumentsAverageProof, verifyDocumentsCountProof, verifyDocumentsSumProof } from 'pshenmic-dpp';
2
- import { LATEST_PLATFORM_VERSION } from '../constants.js';
3
2
  import getDataContractByIdentifier from '../dataContracts/getDataContractByIdentifier.js';
4
3
  import QueryExecutor from '../QueryExecutor.js';
5
4
  import { createDocumentsV1Request, getDocumentsV1Data, getDocumentsV1Proof, toOrderClauses, toSelect, toWhereClauses } from './v1.js';
@@ -54,13 +53,13 @@ export default async function queryAggregate(grpcPool, quorumKeyProvider, dataCo
54
53
  .mapProof(getDocumentsV1Proof);
55
54
  if (aggregateFunction === 'count') {
56
55
  return await executor
57
- .setProofVerifier(verifyDocumentsCountProof, ({ metadata }) => [dataContract, query, LATEST_PLATFORM_VERSION, BigInt(metadata.timeMs)])
56
+ .setProofVerifier(verifyDocumentsCountProof, ({ metadata }, platformVersion) => [dataContract, query, platformVersion, BigInt(metadata.timeMs)])
58
57
  .mapResponse(data => data.proved ? data.verified.value : toDocumentsAggregate(data.result, aggregateFunction))
59
58
  .execute();
60
59
  }
61
60
  const verify = aggregateFunction === 'sum' ? verifyDocumentsSumProof : verifyDocumentsAverageProof;
62
61
  return await executor
63
- .setProofVerifier(verify, ({ metadata }) => [dataContract, query, field, LATEST_PLATFORM_VERSION, BigInt(metadata.timeMs)])
62
+ .setProofVerifier(verify, ({ metadata }, platformVersion) => [dataContract, query, field, platformVersion, BigInt(metadata.timeMs)])
64
63
  .mapResponse(data => data.proved ? data.verified.value : toDocumentsAggregate(data.result, aggregateFunction))
65
64
  .execute();
66
65
  }
@@ -1,5 +1,4 @@
1
1
  import { IdentifierWASM, verifyChainedDocumentsProof, verifyCompositeDocumentsProof } from 'pshenmic-dpp';
2
- import { LATEST_PLATFORM_VERSION } from '../constants.js';
3
2
  import getDataContractByIdentifier from '../dataContracts/getDataContractByIdentifier.js';
4
3
  import QueryExecutor from '../QueryExecutor.js';
5
4
  import { createDocumentsV1Request, getDocumentsV1Data, getDocumentsV1Proof, toDocumentRemovalEntry, toDocuments, toOrderClauses, toStart, toSubQueries, toWhereClauses } from './v1.js';
@@ -21,7 +20,7 @@ export async function queryChained(grpcPool, quorumKeyProvider, dataContractId,
21
20
  return await QueryExecutor.build(grpcPool, quorumKeyProvider)
22
21
  .setGrpcRequest('getDocuments', request)
23
22
  .mapProof(getDocumentsV1Proof)
24
- .setProofVerifier(verifyChainedDocumentsProof, dataContract, query, joinProperty, outerDocumentTypeName, LATEST_PLATFORM_VERSION)
23
+ .setProofVerifier(verifyChainedDocumentsProof, (_, platformVersion) => [dataContract, query, joinProperty, outerDocumentTypeName, platformVersion])
25
24
  .mapResponse(data => {
26
25
  if (data.proved) {
27
26
  const { rootHash, ...result } = data.verified;
@@ -29,8 +28,8 @@ export async function queryChained(grpcPool, quorumKeyProvider, dataContractId,
29
28
  }
30
29
  const { innerDocuments, outerDocuments, missingOuterIds, removedOuterDocuments } = getDocumentsV1Data(data.result, 'chained');
31
30
  return {
32
- innerDocuments: toDocuments(innerDocuments, dataContract, query.documentTypeName),
33
- outerDocuments: toDocuments(outerDocuments, dataContract, outerDocumentTypeName),
31
+ innerDocuments: toDocuments(innerDocuments, dataContract, query.documentTypeName, data.platformVersion),
32
+ outerDocuments: toDocuments(outerDocuments, dataContract, outerDocumentTypeName, data.platformVersion),
34
33
  missingOuterIds: missingOuterIds.map(id => new IdentifierWASM(id)),
35
34
  removedOuterDocuments: removedOuterDocuments.map(toDocumentRemovalEntry)
36
35
  };
@@ -57,7 +56,7 @@ export async function queryComposite(grpcPool, quorumKeyProvider, dataContractId
57
56
  return await QueryExecutor.build(grpcPool, quorumKeyProvider)
58
57
  .setGrpcRequest('getDocuments', request)
59
58
  .mapProof(getDocumentsV1Proof)
60
- .setProofVerifier(verifyCompositeDocumentsProof, dataContract, query, subQueries, LATEST_PLATFORM_VERSION)
59
+ .setProofVerifier(verifyCompositeDocumentsProof, (_, platformVersion) => [dataContract, query, subQueries, platformVersion])
61
60
  .mapResponse(data => {
62
61
  if (data.proved) {
63
62
  const { rootHash, ...result } = data.verified;
@@ -65,12 +64,12 @@ export async function queryComposite(grpcPool, quorumKeyProvider, dataContractId
65
64
  }
66
65
  const { pageDocuments, subResults } = getDocumentsV1Data(data.result, 'composite');
67
66
  return {
68
- pageDocuments: toDocuments(pageDocuments, dataContract, query.documentTypeName),
67
+ pageDocuments: toDocuments(pageDocuments, dataContract, query.documentTypeName, data.platformVersion),
69
68
  subResults: subResults.map(({ result, missingIds, removed }, index) => {
70
69
  const subQuery = subQueries[index];
71
70
  return {
72
71
  documents: result.oneofKind === 'documents'
73
- ? toDocuments(result.documents.documents, subQuery.dataContract ?? dataContract, subQuery.documentTypeName)
72
+ ? toDocuments(result.documents.documents, subQuery.dataContract ?? dataContract, subQuery.documentTypeName, data.platformVersion)
74
73
  : undefined,
75
74
  counts: result.oneofKind === 'counts'
76
75
  ? result.counts.entries.map(({ inKey, key, count }) => ({ inKey: inKey ?? null, key, count: BigInt(count) }))
@@ -1,5 +1,4 @@
1
1
  import { IdentifierWASM, verifyHavingDocumentsProof, verifyRankedDocumentsProof } from 'pshenmic-dpp';
2
- import { LATEST_PLATFORM_VERSION } from '../constants.js';
3
2
  import getDataContractByIdentifier from '../dataContracts/getDataContractByIdentifier.js';
4
3
  import QueryExecutor from '../QueryExecutor.js';
5
4
  import { createDocumentsV1Request, getDocumentsV1Data, getDocumentsV1Proof, toHavingClauses, toOrderClauses, toSelect, toWhereClauses } from './v1.js';
@@ -46,7 +45,7 @@ export async function queryRanked(grpcPool, quorumKeyProvider, dataContractId, q
46
45
  return await QueryExecutor.build(grpcPool, quorumKeyProvider)
47
46
  .setGrpcRequest('getDocuments', request)
48
47
  .mapProof(getDocumentsV1Proof)
49
- .setProofVerifier(verifyRankedDocumentsProof, ({ metadata }) => [dataContract, query, LATEST_PLATFORM_VERSION, BigInt(metadata.timeMs)])
48
+ .setProofVerifier(verifyRankedDocumentsProof, ({ metadata }, platformVersion) => [dataContract, query, platformVersion, BigInt(metadata.timeMs)])
50
49
  .mapResponse(data => {
51
50
  if (data.proved) {
52
51
  return data.verified.value;
@@ -65,7 +64,7 @@ export async function queryHaving(grpcPool, quorumKeyProvider, dataContractId, q
65
64
  return await QueryExecutor.build(grpcPool, quorumKeyProvider)
66
65
  .setGrpcRequest('getDocuments', request)
67
66
  .mapProof(getDocumentsV1Proof)
68
- .setProofVerifier(verifyHavingDocumentsProof, ({ metadata }) => [dataContract, query, LATEST_PLATFORM_VERSION, BigInt(metadata.timeMs)])
67
+ .setProofVerifier(verifyHavingDocumentsProof, ({ metadata }, platformVersion) => [dataContract, query, platformVersion, BigInt(metadata.timeMs)])
69
68
  .mapResponse(data => data.proved ? data.verified.value : toRankedEntries(getDocumentsV1Data(data.result, 'ranked').entries))
70
69
  .execute();
71
70
  }
@@ -1,5 +1,5 @@
1
1
  import { GetDocumentsRequest, GetDocumentsRequest_DocumentFieldValue, GetDocumentsRequest_GetDocumentsRequestV1, GetDocumentsRequest_GetDocumentsRequestV1_SubQuery, GetDocumentsRequest_HavingClause, GetDocumentsRequest_OrderClause, GetDocumentsRequest_WhereClause, GetContractDocumentRemovalsResponse_ContractDocumentRemoval, GetDocumentsResponse, GetDocumentsResponse_GetDocumentsResponseV1_ResultData, Proof, ResponseMetadata } from '../../proto/generated/platform.js';
2
- import { AggregateSelect, CompositeSubQuery, DataContractWASM, DocumentWASM, HavingClause, IdentifierLike, IdentifierWASM, ProvenDocumentRemovalEntry, WhereClause } from 'pshenmic-dpp';
2
+ import { AggregateSelect, CompositeSubQuery, DataContractWASM, DocumentWASM, HavingClause, IdentifierLike, IdentifierWASM, PlatformVersionWASM, ProvenDocumentRemovalEntry, WhereClause } from 'pshenmic-dpp';
3
3
  import { ResponseResult } from '../QueryExecutor.js';
4
4
  type DocumentFieldValue = GetDocumentsRequest_DocumentFieldValue;
5
5
  /**
@@ -42,7 +42,7 @@ export declare function getDocumentsV1Data<K extends DocumentsV1Kind>(result: Re
42
42
  /**
43
43
  * Deserializes the documents of a getDocuments response requested without proof
44
44
  */
45
- export declare function toDocuments(documents: Uint8Array[], dataContract: DataContractWASM, documentTypeName: string): DocumentWASM[];
45
+ export declare function toDocuments(documents: Uint8Array[], dataContract: DataContractWASM, documentTypeName: string, platformVersion: PlatformVersionWASM): DocumentWASM[];
46
46
  /**
47
47
  * Converts the document removal of a getDocuments response requested without proof to the one of the proof verification
48
48
  */
@@ -1,6 +1,5 @@
1
1
  import { GetDocumentsRequest, GetDocumentsRequest_GetDocumentsRequestV1, GetDocumentsRequest_GetDocumentsRequestV1_Select_Function, GetDocumentsRequest_GetDocumentsRequestV1_SubQuery_Kind, GetDocumentsRequest_HavingAggregate_Function, GetDocumentsRequest_HavingClause_Operator, GetDocumentsRequest_IntegerRangeSelection, GetDocumentsRequest_TimeRangeSelection, GetDocumentsRequest_TimeRangeSelection_Selector, GetDocumentsRequest_WhereClause, GetDocumentsRequest_WhereOperator } from '../../proto/generated/platform.js';
2
2
  import { DocumentWASM, IdentifierWASM } from 'pshenmic-dpp';
3
- import { LATEST_PLATFORM_VERSION } from '../constants.js';
4
3
  const WHERE_OPERATORS = {
5
4
  '=': GetDocumentsRequest_WhereOperator.EQUAL,
6
5
  '==': GetDocumentsRequest_WhereOperator.EQUAL,
@@ -239,8 +238,8 @@ export function getDocumentsV1Data(result, kind) {
239
238
  /**
240
239
  * Deserializes the documents of a getDocuments response requested without proof
241
240
  */
242
- export function toDocuments(documents, dataContract, documentTypeName) {
243
- return documents.map(bytes => DocumentWASM.fromBytes(bytes, dataContract, documentTypeName, LATEST_PLATFORM_VERSION));
241
+ export function toDocuments(documents, dataContract, documentTypeName, platformVersion) {
242
+ return documents.map(bytes => DocumentWASM.fromBytes(bytes, dataContract, documentTypeName, platformVersion));
244
243
  }
245
244
  /**
246
245
  * Converts the document removal of a getDocuments response requested without proof to the one of the proof verification
@@ -6,8 +6,8 @@ export interface GRPCOptions {
6
6
  retries?: number;
7
7
  /**
8
8
  * Minimal protocol version of the nodes, nodes with the protocol version from `minProtocolVersion` up to the latest
9
- * version supported by the SDK are used. By default, only nodes with the latest protocol version are used.
10
- * Proofs of the older nodes are still verified with the latest platform version of the SDK
9
+ * version supported by the SDK are used. By default, nodes with any protocol version up to the latest one are used.
10
+ * The SDK starts with the higher of it and the lowest version the network runs, see {GRPCPool.protocolVersion}
11
11
  */
12
12
  minProtocolVersion?: number;
13
13
  /** Custom connection pool, if set, `poolLimit`, `dapiUrl` and `retries` are ignored **/
@@ -28,6 +28,12 @@ export interface GRPCPool {
28
28
  unbanNode?: (client: PlatformClient) => void;
29
29
  /** Requests and verifies proofs of the queries, `true` if not set **/
30
30
  proofs?: boolean;
31
+ /**
32
+ * Protocol version used to verify proofs and to parse responses, the lowest version the network runs if not set.
33
+ * Raised by the SDK to the protocol version of the responses whose proof and quorum signature were verified,
34
+ * it is never lowered and versions unknown to the SDK are ignored
35
+ */
36
+ protocolVersion?: number;
31
37
  }
32
38
  export interface MasternodeInfo {
33
39
  proTxHash: string;
@@ -54,6 +60,7 @@ export default class GRPCConnectionPool implements GRPCPool {
54
60
  network: Network;
55
61
  readonly retries: number;
56
62
  proofs?: boolean;
63
+ protocolVersion: number;
57
64
  constructor(network: Network, grpcOptions?: GRPCOptions);
58
65
  /**
59
66
  * Waits for the pool initialization and returns a client connected to the next healthy node (round-robin)