dash-platform-sdk 1.6.0-dev.2 → 1.6.0-dev.4
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 +33 -15
- package/bundle.min.js +1 -1
- package/index.d.ts +3 -1
- package/index.js +2 -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 +350 -2
- package/proto/generated/platform.js +737 -8
- package/src/DashPlatformSDK.d.ts +19 -1
- package/src/DashPlatformSDK.js +28 -10
- package/src/QueryExecutor.d.ts +122 -0
- package/src/QueryExecutor.js +205 -0
- package/src/constants.d.ts +6 -0
- package/src/constants.js +6 -0
- package/src/contestedResources/getContestedResourceVoteState.d.ts +2 -1
- package/src/contestedResources/getContestedResourceVoteState.js +69 -49
- package/src/contestedResources/getVotePollsByEndDate.d.ts +4 -0
- package/src/contestedResources/getVotePollsByEndDate.js +39 -0
- package/src/contestedResources/index.d.ts +16 -2
- package/src/contestedResources/index.js +19 -2
- package/src/dataContracts/getDataContractByIdentifier.d.ts +2 -1
- package/src/dataContracts/getDataContractByIdentifier.js +15 -27
- package/src/dataContracts/index.d.ts +4 -1
- package/src/dataContracts/index.js +5 -2
- package/src/documents/getActionFeeAgreement.d.ts +2 -1
- package/src/documents/getActionFeeAgreement.js +3 -3
- package/src/documents/index.d.ts +12 -8
- package/src/documents/index.js +16 -13
- package/src/documents/query.d.ts +2 -1
- package/src/documents/query.js +16 -8
- package/src/documents/queryAggregate.d.ts +8 -1
- package/src/documents/queryAggregate.js +49 -15
- package/src/documents/queryJoined.d.ts +3 -2
- package/src/documents/queryJoined.js +54 -13
- package/src/documents/queryRanked.d.ts +3 -2
- package/src/documents/queryRanked.js +49 -15
- package/src/documents/v1.d.ts +25 -8
- package/src/documents/v1.js +50 -14
- package/src/grpcConnectionPool.d.ts +30 -4
- package/src/grpcConnectionPool.js +169 -39
- package/src/identities/getIdentityBalance.d.ts +2 -1
- package/src/identities/getIdentityBalance.js +13 -27
- package/src/identities/getIdentityByIdentifier.d.ts +2 -1
- package/src/identities/getIdentityByIdentifier.js +14 -28
- package/src/identities/getIdentityByNonUniquePublicKeyHash.d.ts +2 -1
- package/src/identities/getIdentityByNonUniquePublicKeyHash.js +49 -28
- package/src/identities/getIdentityByPublicKeyHash.d.ts +2 -1
- package/src/identities/getIdentityByPublicKeyHash.js +14 -28
- package/src/identities/getIdentityContractNonce.d.ts +2 -1
- package/src/identities/getIdentityContractNonce.js +10 -27
- package/src/identities/getIdentityNonce.d.ts +2 -1
- package/src/identities/getIdentityNonce.js +10 -27
- package/src/identities/getIdentityPublicKeys.d.ts +2 -1
- package/src/identities/getIdentityPublicKeys.js +16 -29
- package/src/identities/index.d.ts +4 -1
- package/src/identities/index.js +11 -8
- package/src/names/index.d.ts +4 -1
- package/src/names/index.js +8 -5
- package/src/names/registerName.d.ts +2 -1
- package/src/names/registerName.js +4 -4
- package/src/names/searchByIdentity.d.ts +2 -1
- package/src/names/searchByIdentity.js +2 -2
- package/src/names/searchByName.d.ts +2 -1
- package/src/names/searchByName.js +2 -2
- package/src/node/epochInfos.d.ts +2 -1
- package/src/node/epochInfos.js +27 -31
- package/src/node/finalizedEpochInfos.d.ts +4 -3
- package/src/node/finalizedEpochInfos.js +45 -39
- package/src/node/index.d.ts +4 -1
- package/src/node/index.js +7 -4
- package/src/node/totalCredits.d.ts +2 -1
- package/src/node/totalCredits.js +10 -25
- package/src/platformAddresses/getAddressInfo.d.ts +2 -1
- package/src/platformAddresses/getAddressInfo.js +17 -31
- package/src/platformAddresses/getAddressesBranchState.d.ts +2 -1
- package/src/platformAddresses/getAddressesBranchState.js +22 -8
- package/src/platformAddresses/getAddressesInfos.d.ts +2 -1
- package/src/platformAddresses/getAddressesInfos.js +18 -29
- package/src/platformAddresses/getAddressesTrunkState.d.ts +2 -1
- package/src/platformAddresses/getAddressesTrunkState.js +25 -23
- package/src/platformAddresses/getRecentAddressBalanceChanges.d.ts +2 -1
- package/src/platformAddresses/getRecentAddressBalanceChanges.js +26 -26
- package/src/platformAddresses/getRecentCompactedAddressBalanceChanges.d.ts +2 -1
- package/src/platformAddresses/getRecentCompactedAddressBalanceChanges.js +30 -26
- package/src/platformAddresses/index.d.ts +4 -1
- package/src/platformAddresses/index.js +10 -7
- package/src/quorumKeyProvider.d.ts +23 -0
- package/src/quorumKeyProvider.js +28 -0
- package/src/shielded/getMostRecentShieldedAnchor.d.ts +2 -1
- package/src/shielded/getMostRecentShieldedAnchor.js +8 -25
- package/src/shielded/getShieldedAnchors.d.ts +2 -1
- package/src/shielded/getShieldedAnchors.js +8 -25
- package/src/shielded/getShieldedEncryptedNotes.d.ts +2 -1
- package/src/shielded/getShieldedEncryptedNotes.js +16 -30
- package/src/shielded/getShieldedNotesCount.d.ts +2 -1
- package/src/shielded/getShieldedNotesCount.js +8 -25
- package/src/shielded/getShieldedNullifiers.d.ts +2 -1
- package/src/shielded/getShieldedNullifiers.js +14 -28
- package/src/shielded/getShieldedPoolState.d.ts +2 -1
- package/src/shielded/getShieldedPoolState.js +8 -25
- package/src/shielded/index.d.ts +4 -1
- package/src/shielded/index.js +10 -7
- package/src/stateTransitions/index.d.ts +4 -1
- package/src/stateTransitions/index.js +5 -2
- package/src/stateTransitions/waitForStateTransitionResult.d.ts +2 -1
- package/src/stateTransitions/waitForStateTransitionResult.js +42 -44
- package/src/tokens/getIdentitiesTokenBalances.d.ts +2 -1
- package/src/tokens/getIdentitiesTokenBalances.js +17 -28
- package/src/tokens/getIdentityTokensBalances.d.ts +2 -1
- package/src/tokens/getIdentityTokensBalances.js +17 -28
- package/src/tokens/getTokenContractInfo.d.ts +2 -1
- package/src/tokens/getTokenContractInfo.js +16 -30
- package/src/tokens/getTokenDirectPurchasePrices.d.ts +2 -1
- package/src/tokens/getTokenDirectPurchasePrices.js +26 -28
- package/src/tokens/getTokenTotalSupply.d.ts +2 -1
- package/src/tokens/getTokenTotalSupply.js +16 -28
- package/src/tokens/index.d.ts +4 -1
- package/src/tokens/index.js +11 -8
- package/src/utils/ProofError.d.ts +9 -0
- package/src/utils/ProofError.js +10 -0
- package/src/utils/verifyTenderdashProof.js +2 -1
- package/test/unit/SDK.spec.js +42 -0
- package/src/utils/getQuorumPublicKey.d.ts +0 -1
- package/src/utils/getQuorumPublicKey.js +0 -19
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { IdentifierWASM, verifyChainedDocumentsProof, verifyCompositeDocumentsProof } from 'pshenmic-dpp';
|
|
2
2
|
import { LATEST_PLATFORM_VERSION } from '../constants.js';
|
|
3
3
|
import getDataContractByIdentifier from '../dataContracts/getDataContractByIdentifier.js';
|
|
4
|
-
import
|
|
4
|
+
import QueryExecutor from '../QueryExecutor.js';
|
|
5
|
+
import { createDocumentsV1Request, getDocumentsV1Data, getDocumentsV1Proof, toDocumentRemovalEntry, toDocuments, toOrderClauses, toStart, toSubQueries, toWhereClauses } from './v1.js';
|
|
5
6
|
/**
|
|
6
7
|
* Chained join: documents of `query`, then the documents of `outerDocumentTypeName`
|
|
7
8
|
* their `joinProperty` refers to
|
|
8
9
|
*/
|
|
9
|
-
export async function queryChained(grpcPool, dataContractId, query, joinProperty, outerDocumentTypeName) {
|
|
10
|
-
const dataContract = await getDataContractByIdentifier(grpcPool, dataContractId);
|
|
11
|
-
const
|
|
10
|
+
export async function queryChained(grpcPool, quorumKeyProvider, dataContractId, query, joinProperty, outerDocumentTypeName) {
|
|
11
|
+
const dataContract = await getDataContractByIdentifier(grpcPool, quorumKeyProvider, dataContractId);
|
|
12
|
+
const request = createDocumentsV1Request({
|
|
12
13
|
dataContractId: (new IdentifierWASM(dataContractId)).bytes(),
|
|
13
14
|
documentType: query.documentTypeName,
|
|
14
15
|
whereClauses: toWhereClauses(query.where),
|
|
@@ -17,18 +18,33 @@ export async function queryChained(grpcPool, dataContractId, query, joinProperty
|
|
|
17
18
|
start: toStart(query.startAt, query.startAtIncluded),
|
|
18
19
|
chained: { joinProperty, outerDocumentType: outerDocumentTypeName }
|
|
19
20
|
});
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
return await QueryExecutor.build(grpcPool, quorumKeyProvider)
|
|
22
|
+
.setGrpcRequest('getDocuments', request)
|
|
23
|
+
.mapProof(getDocumentsV1Proof)
|
|
24
|
+
.setProofVerifier(verifyChainedDocumentsProof, dataContract, query, joinProperty, outerDocumentTypeName, LATEST_PLATFORM_VERSION)
|
|
25
|
+
.mapResponse(data => {
|
|
26
|
+
if (data.proved) {
|
|
27
|
+
const { rootHash, ...result } = data.verified;
|
|
28
|
+
return result;
|
|
29
|
+
}
|
|
30
|
+
const { innerDocuments, outerDocuments, missingOuterIds, removedOuterDocuments } = getDocumentsV1Data(data.result, 'chained');
|
|
31
|
+
return {
|
|
32
|
+
innerDocuments: toDocuments(innerDocuments, dataContract, query.documentTypeName),
|
|
33
|
+
outerDocuments: toDocuments(outerDocuments, dataContract, outerDocumentTypeName),
|
|
34
|
+
missingOuterIds: missingOuterIds.map(id => new IdentifierWASM(id)),
|
|
35
|
+
removedOuterDocuments: removedOuterDocuments.map(toDocumentRemovalEntry)
|
|
36
|
+
};
|
|
37
|
+
})
|
|
38
|
+
.execute();
|
|
23
39
|
}
|
|
24
40
|
/**
|
|
25
41
|
* Composite query: a page of documents plus up to 10 sub-queries, each optionally bound
|
|
26
42
|
* to values the page or an earlier sub-query proved
|
|
27
43
|
*/
|
|
28
|
-
export async function queryComposite(grpcPool, dataContractId, query, subQueries) {
|
|
29
|
-
const dataContract = await getDataContractByIdentifier(grpcPool, dataContractId);
|
|
44
|
+
export async function queryComposite(grpcPool, quorumKeyProvider, dataContractId, query, subQueries) {
|
|
45
|
+
const dataContract = await getDataContractByIdentifier(grpcPool, quorumKeyProvider, dataContractId);
|
|
30
46
|
const identifier = new IdentifierWASM(dataContractId);
|
|
31
|
-
const
|
|
47
|
+
const request = createDocumentsV1Request({
|
|
32
48
|
dataContractId: identifier.bytes(),
|
|
33
49
|
documentType: query.documentTypeName,
|
|
34
50
|
whereClauses: toWhereClauses(query.where),
|
|
@@ -38,7 +54,32 @@ export async function queryComposite(grpcPool, dataContractId, query, subQueries
|
|
|
38
54
|
start: toStart(query.startAt, query.startAtIncluded),
|
|
39
55
|
subQueries: toSubQueries(subQueries, identifier)
|
|
40
56
|
});
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
57
|
+
return await QueryExecutor.build(grpcPool, quorumKeyProvider)
|
|
58
|
+
.setGrpcRequest('getDocuments', request)
|
|
59
|
+
.mapProof(getDocumentsV1Proof)
|
|
60
|
+
.setProofVerifier(verifyCompositeDocumentsProof, dataContract, query, subQueries, LATEST_PLATFORM_VERSION)
|
|
61
|
+
.mapResponse(data => {
|
|
62
|
+
if (data.proved) {
|
|
63
|
+
const { rootHash, ...result } = data.verified;
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
const { pageDocuments, subResults } = getDocumentsV1Data(data.result, 'composite');
|
|
67
|
+
return {
|
|
68
|
+
pageDocuments: toDocuments(pageDocuments, dataContract, query.documentTypeName),
|
|
69
|
+
subResults: subResults.map(({ result, missingIds, removed }, index) => {
|
|
70
|
+
const subQuery = subQueries[index];
|
|
71
|
+
return {
|
|
72
|
+
documents: result.oneofKind === 'documents'
|
|
73
|
+
? toDocuments(result.documents.documents, subQuery.dataContract ?? dataContract, subQuery.documentTypeName)
|
|
74
|
+
: undefined,
|
|
75
|
+
counts: result.oneofKind === 'counts'
|
|
76
|
+
? result.counts.entries.map(({ inKey, key, count }) => ({ inKey: inKey ?? null, key, count: BigInt(count) }))
|
|
77
|
+
: undefined,
|
|
78
|
+
missingIds: missingIds.map(id => new IdentifierWASM(id)),
|
|
79
|
+
removals: removed.map(toDocumentRemovalEntry)
|
|
80
|
+
};
|
|
81
|
+
})
|
|
82
|
+
};
|
|
83
|
+
})
|
|
84
|
+
.execute();
|
|
44
85
|
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { AggregateDocumentsQuery, HavingClause, IdentifierLike, ProvenRankedEntry, ProvenRankedPage } from 'pshenmic-dpp';
|
|
2
2
|
import { GRPCPool } from '../grpcConnectionPool.js';
|
|
3
|
+
import { QuorumKeyProvider } from '../quorumKeyProvider.js';
|
|
3
4
|
/**
|
|
4
5
|
* Top-K query: groups of `groupBy` ranked by the selected aggregate in the order `orderBy` names
|
|
5
6
|
*/
|
|
6
|
-
export declare function queryRanked(grpcPool: GRPCPool, dataContractId: IdentifierLike, query: AggregateDocumentsQuery): Promise<ProvenRankedPage>;
|
|
7
|
+
export declare function queryRanked(grpcPool: GRPCPool, quorumKeyProvider: QuorumKeyProvider, dataContractId: IdentifierLike, query: AggregateDocumentsQuery): Promise<ProvenRankedPage>;
|
|
7
8
|
/**
|
|
8
9
|
* Having query: groups of `groupBy` whose aggregate falls within the `having` bounds
|
|
9
10
|
*/
|
|
10
|
-
export declare function queryHaving(grpcPool: GRPCPool, dataContractId: IdentifierLike, query: AggregateDocumentsQuery & {
|
|
11
|
+
export declare function queryHaving(grpcPool: GRPCPool, quorumKeyProvider: QuorumKeyProvider, dataContractId: IdentifierLike, query: AggregateDocumentsQuery & {
|
|
11
12
|
having: HavingClause[];
|
|
12
13
|
}): Promise<ProvenRankedEntry[]>;
|
|
@@ -1,9 +1,31 @@
|
|
|
1
1
|
import { IdentifierWASM, verifyHavingDocumentsProof, verifyRankedDocumentsProof } from 'pshenmic-dpp';
|
|
2
2
|
import { LATEST_PLATFORM_VERSION } from '../constants.js';
|
|
3
3
|
import getDataContractByIdentifier from '../dataContracts/getDataContractByIdentifier.js';
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
import QueryExecutor from '../QueryExecutor.js';
|
|
5
|
+
import { createDocumentsV1Request, getDocumentsV1Data, getDocumentsV1Proof, toHavingClauses, toOrderClauses, toSelect, toWhereClauses } from './v1.js';
|
|
6
|
+
// average of the proof verification is a fixed point number scaled by 10^19
|
|
7
|
+
const AVG_FIXED_POINT_SCALE = 1e19;
|
|
8
|
+
/**
|
|
9
|
+
* Converts the ranked entries of a response requested without proof to the ones of the proof verification
|
|
10
|
+
*/
|
|
11
|
+
function toRankedEntries(entries) {
|
|
12
|
+
return entries.map(({ key, inKey, value }) => {
|
|
13
|
+
let rankedValue = {};
|
|
14
|
+
if (value.oneofKind === 'count') {
|
|
15
|
+
rankedValue = { count: BigInt(value.count) };
|
|
16
|
+
}
|
|
17
|
+
else if (value.oneofKind === 'sum') {
|
|
18
|
+
rankedValue = { sum: BigInt(value.sum) };
|
|
19
|
+
}
|
|
20
|
+
else if (value.oneofKind === 'avg') {
|
|
21
|
+
// average is returned as a double without proof, so its precision is limited
|
|
22
|
+
rankedValue = { avgFixedPoint: BigInt(Math.round(value.avg * AVG_FIXED_POINT_SCALE)) };
|
|
23
|
+
}
|
|
24
|
+
return { key, inKey: inKey ?? null, value: rankedValue };
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
function createRankedRequest(dataContractId, query, having) {
|
|
28
|
+
return createDocumentsV1Request({
|
|
7
29
|
dataContractId: (new IdentifierWASM(dataContractId)).bytes(),
|
|
8
30
|
documentType: query.documentTypeName,
|
|
9
31
|
whereClauses: toWhereClauses(query.where),
|
|
@@ -18,20 +40,32 @@ async function getRankedProof(grpcPool, dataContractId, query, having) {
|
|
|
18
40
|
/**
|
|
19
41
|
* Top-K query: groups of `groupBy` ranked by the selected aggregate in the order `orderBy` names
|
|
20
42
|
*/
|
|
21
|
-
export async function queryRanked(grpcPool, dataContractId, query) {
|
|
22
|
-
const dataContract = await getDataContractByIdentifier(grpcPool, dataContractId);
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
43
|
+
export async function queryRanked(grpcPool, quorumKeyProvider, dataContractId, query) {
|
|
44
|
+
const dataContract = await getDataContractByIdentifier(grpcPool, quorumKeyProvider, dataContractId);
|
|
45
|
+
const request = createRankedRequest(dataContractId, query, []);
|
|
46
|
+
return await QueryExecutor.build(grpcPool, quorumKeyProvider)
|
|
47
|
+
.setGrpcRequest('getDocuments', request)
|
|
48
|
+
.mapProof(getDocumentsV1Proof)
|
|
49
|
+
.setProofVerifier(verifyRankedDocumentsProof, ({ metadata }) => [dataContract, query, LATEST_PLATFORM_VERSION, BigInt(metadata.timeMs)])
|
|
50
|
+
.mapResponse(data => {
|
|
51
|
+
if (data.proved) {
|
|
52
|
+
return data.verified.value;
|
|
53
|
+
}
|
|
54
|
+
const { entries, skipped } = getDocumentsV1Data(data.result, 'ranked');
|
|
55
|
+
return { skipped: BigInt(skipped ?? 0), entries: toRankedEntries(entries) };
|
|
56
|
+
})
|
|
57
|
+
.execute();
|
|
27
58
|
}
|
|
28
59
|
/**
|
|
29
60
|
* Having query: groups of `groupBy` whose aggregate falls within the `having` bounds
|
|
30
61
|
*/
|
|
31
|
-
export async function queryHaving(grpcPool, dataContractId, query) {
|
|
32
|
-
const dataContract = await getDataContractByIdentifier(grpcPool, dataContractId);
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
62
|
+
export async function queryHaving(grpcPool, quorumKeyProvider, dataContractId, query) {
|
|
63
|
+
const dataContract = await getDataContractByIdentifier(grpcPool, quorumKeyProvider, dataContractId);
|
|
64
|
+
const request = createRankedRequest(dataContractId, query, query.having);
|
|
65
|
+
return await QueryExecutor.build(grpcPool, quorumKeyProvider)
|
|
66
|
+
.setGrpcRequest('getDocuments', request)
|
|
67
|
+
.mapProof(getDocumentsV1Proof)
|
|
68
|
+
.setProofVerifier(verifyHavingDocumentsProof, ({ metadata }) => [dataContract, query, LATEST_PLATFORM_VERSION, BigInt(metadata.timeMs)])
|
|
69
|
+
.mapResponse(data => data.proved ? data.verified.value : toRankedEntries(getDocumentsV1Data(data.result, 'ranked').entries))
|
|
70
|
+
.execute();
|
|
37
71
|
}
|
package/src/documents/v1.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { GetDocumentsRequest_DocumentFieldValue, GetDocumentsRequest_GetDocumentsRequestV1, GetDocumentsRequest_GetDocumentsRequestV1_SubQuery, GetDocumentsRequest_HavingClause, GetDocumentsRequest_OrderClause, GetDocumentsRequest_WhereClause, Proof, ResponseMetadata } from '../../proto/generated/platform.js';
|
|
2
|
-
import { AggregateSelect, CompositeSubQuery, HavingClause, IdentifierLike, IdentifierWASM, WhereClause } from 'pshenmic-dpp';
|
|
3
|
-
import {
|
|
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';
|
|
3
|
+
import { ResponseResult } from '../QueryExecutor.js';
|
|
4
4
|
type DocumentFieldValue = GetDocumentsRequest_DocumentFieldValue;
|
|
5
5
|
/**
|
|
6
6
|
* Converts a JS value of a where / having clause into a typed v1 document field value
|
|
@@ -20,14 +20,31 @@ export declare function toHavingClauses(having: HavingClause[]): GetDocumentsReq
|
|
|
20
20
|
export declare function toSubQueries(subQueries: CompositeSubQuery[], dataContractId: IdentifierWASM): GetDocumentsRequest_GetDocumentsRequestV1_SubQuery[];
|
|
21
21
|
export declare function toStart(startAt?: IdentifierLike | null, startAtIncluded?: boolean): GetDocumentsRequest_GetDocumentsRequestV1['start'];
|
|
22
22
|
/**
|
|
23
|
-
*
|
|
23
|
+
* Creates a v1 getDocuments request with a proof
|
|
24
24
|
*/
|
|
25
|
-
export declare function
|
|
25
|
+
export declare function createDocumentsV1Request(v1: Partial<GetDocumentsRequest_GetDocumentsRequestV1>): GetDocumentsRequest;
|
|
26
|
+
/**
|
|
27
|
+
* Returns the proof and the metadata of a v1 getDocuments response
|
|
28
|
+
*/
|
|
29
|
+
export declare function getDocumentsV1Proof(response: GetDocumentsResponse): {
|
|
26
30
|
proof: Proof;
|
|
27
31
|
metadata: ResponseMetadata;
|
|
28
|
-
}
|
|
32
|
+
};
|
|
33
|
+
type DocumentsV1Variant = GetDocumentsResponse_GetDocumentsResponseV1_ResultData['variant'];
|
|
34
|
+
type DocumentsV1Kind = NonNullable<DocumentsV1Variant['oneofKind']>;
|
|
35
|
+
type DocumentsV1Data<K extends DocumentsV1Kind> = Extract<DocumentsV1Variant, {
|
|
36
|
+
oneofKind: K;
|
|
37
|
+
}> extends infer V ? V[K & keyof V] : never;
|
|
38
|
+
/**
|
|
39
|
+
* Returns the data of the given kind from the result of a v1 getDocuments response requested without proof
|
|
40
|
+
*/
|
|
41
|
+
export declare function getDocumentsV1Data<K extends DocumentsV1Kind>(result: ResponseResult<GetDocumentsResponse>, kind: K): DocumentsV1Data<K>;
|
|
42
|
+
/**
|
|
43
|
+
* Deserializes the documents of a getDocuments response requested without proof
|
|
44
|
+
*/
|
|
45
|
+
export declare function toDocuments(documents: Uint8Array[], dataContract: DataContractWASM, documentTypeName: string): DocumentWASM[];
|
|
29
46
|
/**
|
|
30
|
-
*
|
|
47
|
+
* Converts the document removal of a getDocuments response requested without proof to the one of the proof verification
|
|
31
48
|
*/
|
|
32
|
-
export declare function
|
|
49
|
+
export declare function toDocumentRemovalEntry(removal: GetContractDocumentRemovalsResponse_ContractDocumentRemoval): ProvenDocumentRemovalEntry;
|
|
33
50
|
export {};
|
package/src/documents/v1.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
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
|
-
import { IdentifierWASM } from 'pshenmic-dpp';
|
|
3
|
-
import {
|
|
4
|
-
import bytesToHex from '../utils/bytesToHex.js';
|
|
5
|
-
import verifyTenderdashProof from '../utils/verifyTenderdashProof.js';
|
|
2
|
+
import { DocumentWASM, IdentifierWASM } from 'pshenmic-dpp';
|
|
3
|
+
import { LATEST_PLATFORM_VERSION } from '../constants.js';
|
|
6
4
|
const WHERE_OPERATORS = {
|
|
7
5
|
'=': GetDocumentsRequest_WhereOperator.EQUAL,
|
|
8
6
|
'==': GetDocumentsRequest_WhereOperator.EQUAL,
|
|
@@ -198,16 +196,20 @@ export function toStart(startAt, startAtIncluded) {
|
|
|
198
196
|
: { oneofKind: 'startAt', startAt: bytes };
|
|
199
197
|
}
|
|
200
198
|
/**
|
|
201
|
-
*
|
|
199
|
+
* Creates a v1 getDocuments request with a proof
|
|
202
200
|
*/
|
|
203
|
-
export
|
|
204
|
-
|
|
201
|
+
export function createDocumentsV1Request(v1) {
|
|
202
|
+
return GetDocumentsRequest.create({
|
|
205
203
|
version: {
|
|
206
204
|
oneofKind: 'v1',
|
|
207
205
|
v1: GetDocumentsRequest_GetDocumentsRequestV1.create({ ...v1, prove: true })
|
|
208
206
|
}
|
|
209
207
|
});
|
|
210
|
-
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Returns the proof and the metadata of a v1 getDocuments response
|
|
211
|
+
*/
|
|
212
|
+
export function getDocumentsV1Proof(response) {
|
|
211
213
|
const { version } = response;
|
|
212
214
|
if (version.oneofKind !== 'v1') {
|
|
213
215
|
throw new Error('Unexpected oneOf type returned from DAPI (must be v1)');
|
|
@@ -222,12 +224,46 @@ export async function getDocumentsV1Proof(grpcPool, v1) {
|
|
|
222
224
|
return { proof: result.proof, metadata };
|
|
223
225
|
}
|
|
224
226
|
/**
|
|
225
|
-
*
|
|
227
|
+
* Returns the data of the given kind from the result of a v1 getDocuments response requested without proof
|
|
226
228
|
*/
|
|
227
|
-
export
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
if (!verify) {
|
|
231
|
-
throw new Error('Failed to verify query');
|
|
229
|
+
export function getDocumentsV1Data(result, kind) {
|
|
230
|
+
if (result.oneofKind !== 'data') {
|
|
231
|
+
throw new Error('Unexpected oneOf type returned from DAPI (must be data)');
|
|
232
232
|
}
|
|
233
|
+
const { variant } = result.data;
|
|
234
|
+
if (variant.oneofKind !== kind) {
|
|
235
|
+
throw new Error(`Unexpected oneOf type returned from DAPI (must be ${String(kind)})`);
|
|
236
|
+
}
|
|
237
|
+
return variant[kind];
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Deserializes the documents of a getDocuments response requested without proof
|
|
241
|
+
*/
|
|
242
|
+
export function toDocuments(documents, dataContract, documentTypeName) {
|
|
243
|
+
return documents.map(bytes => DocumentWASM.fromBytes(bytes, dataContract, documentTypeName, LATEST_PLATFORM_VERSION));
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Converts the document removal of a getDocuments response requested without proof to the one of the proof verification
|
|
247
|
+
*/
|
|
248
|
+
export function toDocumentRemovalEntry(removal) {
|
|
249
|
+
const { documentId, documentOwnerId, moderatorId, removedAt, reason, documentHash, restoration, keptFields } = removal;
|
|
250
|
+
return {
|
|
251
|
+
documentId: new IdentifierWASM(documentId),
|
|
252
|
+
removal: {
|
|
253
|
+
documentOwnerId: new IdentifierWASM(documentOwnerId),
|
|
254
|
+
moderatorId: new IdentifierWASM(moderatorId),
|
|
255
|
+
reason: {
|
|
256
|
+
code: reason?.code ?? null,
|
|
257
|
+
text: reason?.text ?? '',
|
|
258
|
+
documents: reason?.documents.map(({ documentTypeName, documentId }) => ({ documentTypeName, documentId: new IdentifierWASM(documentId) })),
|
|
259
|
+
reasonDocumentId: reason?.reasonDocumentId != null ? new IdentifierWASM(reason.reasonDocumentId) : undefined
|
|
260
|
+
},
|
|
261
|
+
removedAt: BigInt(removedAt),
|
|
262
|
+
documentHash,
|
|
263
|
+
restoration: restoration != null
|
|
264
|
+
? { moderatorId: new IdentifierWASM(restoration.moderatorId), restoredAt: BigInt(restoration.restoredAt) }
|
|
265
|
+
: null,
|
|
266
|
+
keptFields: keptFields.length > 0 ? keptFields : undefined
|
|
267
|
+
}
|
|
268
|
+
};
|
|
233
269
|
}
|
|
@@ -3,7 +3,14 @@ import { Network } from '../types.js';
|
|
|
3
3
|
export interface GRPCOptions {
|
|
4
4
|
poolLimit?: number;
|
|
5
5
|
dapiUrl?: string | string[];
|
|
6
|
-
|
|
6
|
+
retries?: number;
|
|
7
|
+
/**
|
|
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
|
|
11
|
+
*/
|
|
12
|
+
minProtocolVersion?: number;
|
|
13
|
+
/** Custom connection pool, if set, `poolLimit`, `dapiUrl` and `retries` are ignored **/
|
|
7
14
|
pool?: GRPCPool;
|
|
8
15
|
}
|
|
9
16
|
/**
|
|
@@ -13,6 +20,14 @@ export interface GRPCOptions {
|
|
|
13
20
|
export interface GRPCPool {
|
|
14
21
|
network: Network;
|
|
15
22
|
getClient: (abortController?: AbortController) => PlatformClient | Promise<PlatformClient>;
|
|
23
|
+
/** How many times a request is retried on another node, if not set, the SDK default is used **/
|
|
24
|
+
retries?: number;
|
|
25
|
+
/** Temporarily excludes the node that served the request of the client from node selection, e.g. after an invalid proof **/
|
|
26
|
+
banNode?: (client: PlatformClient) => void;
|
|
27
|
+
/** Lifts the ban of the node that served the request of the client, e.g. after its response was verified **/
|
|
28
|
+
unbanNode?: (client: PlatformClient) => void;
|
|
29
|
+
/** Requests and verifies proofs of the queries, `true` if not set **/
|
|
30
|
+
proofs?: boolean;
|
|
16
31
|
}
|
|
17
32
|
export interface MasternodeInfo {
|
|
18
33
|
proTxHash: string;
|
|
@@ -32,15 +47,26 @@ export interface MasternodeInfo {
|
|
|
32
47
|
collateraladdress: string;
|
|
33
48
|
pubkeyoperator: string;
|
|
34
49
|
}
|
|
35
|
-
export declare const createClient: (url: string, abortController?: AbortController) => PlatformClient;
|
|
50
|
+
export declare const createClient: (url: string, abortController?: AbortController, fetch?: typeof globalThis.fetch) => PlatformClient;
|
|
36
51
|
export default class GRPCConnectionPool implements GRPCPool {
|
|
37
52
|
#private;
|
|
38
53
|
dapiUrls: string[];
|
|
39
54
|
network: Network;
|
|
55
|
+
readonly retries: number;
|
|
56
|
+
proofs?: boolean;
|
|
40
57
|
constructor(network: Network, grpcOptions?: GRPCOptions);
|
|
41
|
-
_initialize(network: Network, poolLimit: number, dapiUrl?: string | string[]): Promise<void>;
|
|
42
58
|
/**
|
|
43
|
-
* Waits for the pool initialization and returns a client connected to
|
|
59
|
+
* Waits for the pool initialization and returns a client connected to the next healthy node (round-robin)
|
|
44
60
|
*/
|
|
45
61
|
getClient(abortController?: AbortController): Promise<PlatformClient>;
|
|
62
|
+
/**
|
|
63
|
+
* Bans the node that served the request of the client, e.g. when it returned an invalid proof.
|
|
64
|
+
* The first ban lasts 60 seconds, every next ban lasts e times longer, until the node is unbanned
|
|
65
|
+
*/
|
|
66
|
+
banNode(client: PlatformClient): void;
|
|
67
|
+
/**
|
|
68
|
+
* Unbans the node that served the request of the client and resets its ban period,
|
|
69
|
+
* should be called once the response of the node was successfully verified
|
|
70
|
+
*/
|
|
71
|
+
unbanNode(client: PlatformClient): void;
|
|
46
72
|
}
|