dash-platform-sdk 1.6.0-dev.3 → 1.6.0-dev.5
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.
- package/README.md +14 -14
- package/bundle.min.js +1 -1
- package/package.json +2 -2
- package/proto/generated/platform.client.d.ts +10 -0
- package/proto/generated/platform.client.js +27 -20
- package/proto/generated/platform.d.ts +222 -0
- package/proto/generated/platform.js +471 -0
- package/src/constants.d.ts +1 -0
- package/src/constants.js +2 -0
- package/src/contestedResources/getVotePollsByEndDate.d.ts +4 -0
- package/src/contestedResources/getVotePollsByEndDate.js +39 -0
- package/src/contestedResources/index.d.ts +12 -1
- package/src/contestedResources/index.js +14 -0
- package/src/grpcConnectionPool.d.ts +6 -0
- package/src/grpcConnectionPool.js +18 -4
- package/src/shielded/getMostRecentShieldedAnchor.js +2 -2
- package/src/shielded/getShieldedAnchors.js +2 -2
- package/src/shielded/getShieldedEncryptedNotes.js +2 -2
- package/src/shielded/getShieldedNotesCount.js +2 -2
- package/src/shielded/getShieldedNullifiers.js +2 -2
- package/src/shielded/getShieldedPoolState.js +2 -2
|
@@ -86,7 +86,7 @@ const withTimeout = async (request, timeoutMs = HEALTHCHECK_TIMEOUT_MS) => {
|
|
|
86
86
|
clearTimeout(timeout);
|
|
87
87
|
}
|
|
88
88
|
};
|
|
89
|
-
const isNodeHealthy = async (url) => {
|
|
89
|
+
const isNodeHealthy = async (url, minProtocolVersion) => {
|
|
90
90
|
try {
|
|
91
91
|
const response = await withTimeout(async (abortController) => {
|
|
92
92
|
const { response } = await createClient(url, abortController).getStatus(GetStatusRequest.create({}));
|
|
@@ -103,7 +103,15 @@ const isNodeHealthy = async (url) => {
|
|
|
103
103
|
// node runs a protocol version that is not supported by the SDK
|
|
104
104
|
// (e.g. newer software with incompatible proofs / responses)
|
|
105
105
|
const protocol = version?.protocol?.drive;
|
|
106
|
-
if (protocol == null
|
|
106
|
+
if (protocol == null) {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
if (minProtocolVersion == null) {
|
|
110
|
+
if (protocol.current !== Number(LATEST_PLATFORM_VERSION) || protocol.latest !== Number(LATEST_PLATFORM_VERSION)) {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
else if (protocol.current < minProtocolVersion || protocol.current > Number(LATEST_PLATFORM_VERSION)) {
|
|
107
115
|
return false;
|
|
108
116
|
}
|
|
109
117
|
// chain is stalled, last block is too old relative to the node's own clock
|
|
@@ -132,6 +140,7 @@ export default class GRPCConnectionPool {
|
|
|
132
140
|
network;
|
|
133
141
|
#poolLimit;
|
|
134
142
|
#dapiUrl;
|
|
143
|
+
#minProtocolVersion;
|
|
135
144
|
retries;
|
|
136
145
|
proofs;
|
|
137
146
|
#nodeIndex = 0;
|
|
@@ -145,6 +154,11 @@ export default class GRPCConnectionPool {
|
|
|
145
154
|
if (!Number.isInteger(retries) || retries < 0) {
|
|
146
155
|
throw new Error(`GRPC retries must be a non-negative integer, got ${String(retries)}`);
|
|
147
156
|
}
|
|
157
|
+
const minProtocolVersion = grpcOptions?.minProtocolVersion;
|
|
158
|
+
if (minProtocolVersion != null && (!Number.isInteger(minProtocolVersion) || minProtocolVersion < 1 || minProtocolVersion > Number(LATEST_PLATFORM_VERSION))) {
|
|
159
|
+
throw new Error(`GRPC minProtocolVersion must be an integer from 1 to ${Number(LATEST_PLATFORM_VERSION)}, got ${String(minProtocolVersion)}`);
|
|
160
|
+
}
|
|
161
|
+
this.#minProtocolVersion = minProtocolVersion;
|
|
148
162
|
this.network = network;
|
|
149
163
|
this.#poolLimit = grpcOptions?.poolLimit ?? GRPC_DEFAULT_POOL_LIMIT;
|
|
150
164
|
this.#dapiUrl = grpcOptions?.dapiUrl;
|
|
@@ -189,13 +203,13 @@ export default class GRPCConnectionPool {
|
|
|
189
203
|
const dapiUrls = [];
|
|
190
204
|
for (let i = 0; i < networkDAPIUrls.length && dapiUrls.length < this.#poolLimit; i += this.#poolLimit) {
|
|
191
205
|
const batch = networkDAPIUrls.slice(i, i + this.#poolLimit);
|
|
192
|
-
const healthy = await Promise.all(batch.map(isNodeHealthy));
|
|
206
|
+
const healthy = await Promise.all(batch.map(async (url) => await isNodeHealthy(url, this.#minProtocolVersion)));
|
|
193
207
|
dapiUrls.push(...batch.filter((_, j) => healthy[j]));
|
|
194
208
|
}
|
|
195
209
|
// fail the initialization, so it is retried on the next request
|
|
196
210
|
if (dapiUrls.length === 0) {
|
|
197
211
|
throw new Error(`None of the ${network} evonodes are available (${networkDAPIUrls.length} checked, ` +
|
|
198
|
-
`nodes must be synced and run protocol version ${Number(LATEST_PLATFORM_VERSION)})`);
|
|
212
|
+
`nodes must be synced and run protocol version ${this.#minProtocolVersion != null ? `${this.#minProtocolVersion}-` : ''}${Number(LATEST_PLATFORM_VERSION)})`);
|
|
199
213
|
}
|
|
200
214
|
this.dapiUrls = dapiUrls.slice(0, this.#poolLimit);
|
|
201
215
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { GetMostRecentShieldedAnchorRequest } from '../../proto/generated/platform.js';
|
|
2
2
|
import { IdentifierWASM, verifyMostRecentShieldedAnchorProof } from 'pshenmic-dpp';
|
|
3
|
-
import {
|
|
3
|
+
import { SHIELDED_PLATFORM_VERSION } from '../constants.js';
|
|
4
4
|
import QueryExecutor from '../QueryExecutor.js';
|
|
5
5
|
export default async function getMostRecentShieldedAnchor(grpcPool, quorumKeyProvider, tokenIdentifier) {
|
|
6
6
|
const tokenId = tokenIdentifier != null ? new IdentifierWASM(tokenIdentifier) : undefined;
|
|
@@ -15,7 +15,7 @@ export default async function getMostRecentShieldedAnchor(grpcPool, quorumKeyPro
|
|
|
15
15
|
});
|
|
16
16
|
return await QueryExecutor.build(grpcPool, quorumKeyProvider)
|
|
17
17
|
.setGrpcRequest('getMostRecentShieldedAnchor', getMostRecentShieldedAnchorRequest)
|
|
18
|
-
.setProofVerifier(verifyMostRecentShieldedAnchorProof, true,
|
|
18
|
+
.setProofVerifier(verifyMostRecentShieldedAnchorProof, true, SHIELDED_PLATFORM_VERSION, tokenId)
|
|
19
19
|
.mapResponse(data => data.proved ? data.verified.anchor : data.result.anchor)
|
|
20
20
|
.execute();
|
|
21
21
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { GetShieldedAnchorsRequest } from '../../proto/generated/platform.js';
|
|
2
2
|
import { IdentifierWASM, verifyShieldedAnchorsProof } from 'pshenmic-dpp';
|
|
3
|
-
import {
|
|
3
|
+
import { SHIELDED_PLATFORM_VERSION } from '../constants.js';
|
|
4
4
|
import QueryExecutor from '../QueryExecutor.js';
|
|
5
5
|
export default async function getShieldedAnchors(grpcPool, quorumKeyProvider, tokenIdentifier) {
|
|
6
6
|
const tokenId = tokenIdentifier != null ? new IdentifierWASM(tokenIdentifier) : undefined;
|
|
@@ -15,7 +15,7 @@ export default async function getShieldedAnchors(grpcPool, quorumKeyProvider, to
|
|
|
15
15
|
});
|
|
16
16
|
return await QueryExecutor.build(grpcPool, quorumKeyProvider)
|
|
17
17
|
.setGrpcRequest('getShieldedAnchors', getShieldedAnchorsRequest)
|
|
18
|
-
.setProofVerifier(verifyShieldedAnchorsProof, true,
|
|
18
|
+
.setProofVerifier(verifyShieldedAnchorsProof, true, SHIELDED_PLATFORM_VERSION, tokenId)
|
|
19
19
|
.mapResponse(data => data.proved ? data.verified.anchors : data.result.anchors.anchors)
|
|
20
20
|
.execute();
|
|
21
21
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { GetShieldedEncryptedNotesRequest } from '../../proto/generated/platform.js';
|
|
2
2
|
import { IdentifierWASM, verifyShieldedEncryptedNotesProof } from 'pshenmic-dpp';
|
|
3
|
-
import {
|
|
3
|
+
import { SHIELDED_PLATFORM_VERSION, SHIELDED_MAX_NOTES_PER_QUERY } from '../constants.js';
|
|
4
4
|
import QueryExecutor from '../QueryExecutor.js';
|
|
5
5
|
export default async function getShieldedEncryptedNotes(grpcPool, quorumKeyProvider, startIndex, count, tokenIdentifier) {
|
|
6
6
|
const tokenId = tokenIdentifier != null ? new IdentifierWASM(tokenIdentifier) : undefined;
|
|
@@ -17,7 +17,7 @@ export default async function getShieldedEncryptedNotes(grpcPool, quorumKeyProvi
|
|
|
17
17
|
});
|
|
18
18
|
return await QueryExecutor.build(grpcPool, quorumKeyProvider)
|
|
19
19
|
.setGrpcRequest('getShieldedEncryptedNotes', getShieldedEncryptedNotesRequest)
|
|
20
|
-
.setProofVerifier(verifyShieldedEncryptedNotesProof, startIndex, count, SHIELDED_MAX_NOTES_PER_QUERY, true,
|
|
20
|
+
.setProofVerifier(verifyShieldedEncryptedNotesProof, startIndex, count, SHIELDED_MAX_NOTES_PER_QUERY, true, SHIELDED_PLATFORM_VERSION, tokenId)
|
|
21
21
|
.mapResponse(data => {
|
|
22
22
|
const notes = data.proved ? data.verified.notes : data.result.encryptedNotes.entries;
|
|
23
23
|
return notes.map(note => ({
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { GetShieldedNotesCountRequest } from '../../proto/generated/platform.js';
|
|
2
2
|
import { IdentifierWASM, verifyShieldedNotesCountProof } from 'pshenmic-dpp';
|
|
3
|
-
import {
|
|
3
|
+
import { SHIELDED_PLATFORM_VERSION } from '../constants.js';
|
|
4
4
|
import QueryExecutor from '../QueryExecutor.js';
|
|
5
5
|
export default async function getShieldedNotesCount(grpcPool, quorumKeyProvider, tokenIdentifier) {
|
|
6
6
|
const tokenId = tokenIdentifier != null ? new IdentifierWASM(tokenIdentifier) : undefined;
|
|
@@ -15,7 +15,7 @@ export default async function getShieldedNotesCount(grpcPool, quorumKeyProvider,
|
|
|
15
15
|
});
|
|
16
16
|
return await QueryExecutor.build(grpcPool, quorumKeyProvider)
|
|
17
17
|
.setGrpcRequest('getShieldedNotesCount', getShieldedNotesCountRequest)
|
|
18
|
-
.setProofVerifier(verifyShieldedNotesCountProof, true,
|
|
18
|
+
.setProofVerifier(verifyShieldedNotesCountProof, true, SHIELDED_PLATFORM_VERSION, tokenId)
|
|
19
19
|
.mapResponse(data => data.proved ? data.verified.count : BigInt(data.result.totalNotesCount))
|
|
20
20
|
.execute();
|
|
21
21
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { GetShieldedNullifiersRequest } from '../../proto/generated/platform.js';
|
|
2
2
|
import { IdentifierWASM, verifyShieldedNullifiersProof } from 'pshenmic-dpp';
|
|
3
|
-
import {
|
|
3
|
+
import { SHIELDED_PLATFORM_VERSION } from '../constants.js';
|
|
4
4
|
import QueryExecutor from '../QueryExecutor.js';
|
|
5
5
|
export default async function getShieldedNullifiers(grpcPool, quorumKeyProvider, nullifiers, tokenIdentifier) {
|
|
6
6
|
const tokenId = tokenIdentifier != null ? new IdentifierWASM(tokenIdentifier) : undefined;
|
|
@@ -16,7 +16,7 @@ export default async function getShieldedNullifiers(grpcPool, quorumKeyProvider,
|
|
|
16
16
|
});
|
|
17
17
|
return await QueryExecutor.build(grpcPool, quorumKeyProvider)
|
|
18
18
|
.setGrpcRequest('getShieldedNullifiers', getShieldedNullifiersRequest)
|
|
19
|
-
.setProofVerifier(verifyShieldedNullifiersProof, nullifiers, true,
|
|
19
|
+
.setProofVerifier(verifyShieldedNullifiersProof, nullifiers, true, SHIELDED_PLATFORM_VERSION, tokenId)
|
|
20
20
|
.mapResponse(data => {
|
|
21
21
|
const nullifiersStatuses = data.proved ? data.verified.nullifiers : data.result.nullifierStatuses.entries;
|
|
22
22
|
return nullifiersStatuses.map(entry => ({
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { GetShieldedPoolStateRequest } from '../../proto/generated/platform.js';
|
|
2
2
|
import QueryExecutor from '../QueryExecutor.js';
|
|
3
3
|
import { IdentifierWASM, verifyShieldedPoolStateProof } from 'pshenmic-dpp';
|
|
4
|
-
import {
|
|
4
|
+
import { SHIELDED_PLATFORM_VERSION } from '../constants.js';
|
|
5
5
|
export default async function getShieldedPoolState(grpcPool, quorumKeyProvider, tokenIdentifier) {
|
|
6
6
|
const tokenId = tokenIdentifier != null ? new IdentifierWASM(tokenIdentifier) : undefined;
|
|
7
7
|
const getShieldedPoolStateRequest = GetShieldedPoolStateRequest.create({
|
|
@@ -15,7 +15,7 @@ export default async function getShieldedPoolState(grpcPool, quorumKeyProvider,
|
|
|
15
15
|
});
|
|
16
16
|
return await QueryExecutor.build(grpcPool, quorumKeyProvider)
|
|
17
17
|
.setGrpcRequest('getShieldedPoolState', getShieldedPoolStateRequest)
|
|
18
|
-
.setProofVerifier(verifyShieldedPoolStateProof, true,
|
|
18
|
+
.setProofVerifier(verifyShieldedPoolStateProof, true, SHIELDED_PLATFORM_VERSION, tokenId)
|
|
19
19
|
.mapResponse(data => data.proved ? data.verified.totalBalance : BigInt(data.result.totalBalance))
|
|
20
20
|
.execute();
|
|
21
21
|
}
|