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,10 +1,8 @@
|
|
|
1
1
|
import { GetIdentitiesTokenBalancesRequest } from '../../proto/generated/platform.js';
|
|
2
2
|
import { IdentifierWASM, verifyTokenBalancesForIdentitiesProof } from 'pshenmic-dpp';
|
|
3
|
-
import
|
|
4
|
-
import bytesToHex from '../utils/bytesToHex.js';
|
|
5
|
-
import verifyTenderdashProof from '../utils/verifyTenderdashProof.js';
|
|
3
|
+
import QueryExecutor from '../QueryExecutor.js';
|
|
6
4
|
import { LATEST_PLATFORM_VERSION } from '../constants.js';
|
|
7
|
-
export default async function getIdentitiesTokenBalances(grpcPool, identifiers, tokenIdentifier) {
|
|
5
|
+
export default async function getIdentitiesTokenBalances(grpcPool, quorumKeyProvider, identifiers, tokenIdentifier) {
|
|
8
6
|
const ids = identifiers.map(identifier => new IdentifierWASM(identifier));
|
|
9
7
|
const tokenId = new IdentifierWASM(tokenIdentifier);
|
|
10
8
|
const getIdentitiesTokenBalancesRequest = GetIdentitiesTokenBalancesRequest.create({
|
|
@@ -17,28 +15,19 @@ export default async function getIdentitiesTokenBalances(grpcPool, identifiers,
|
|
|
17
15
|
}
|
|
18
16
|
}
|
|
19
17
|
});
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const verify = await verifyTenderdashProof(proof, metadata, rootHash, quorumPublicKey);
|
|
36
|
-
if (!verify) {
|
|
37
|
-
throw new Error('Failed to verify query');
|
|
38
|
-
}
|
|
39
|
-
return balances
|
|
40
|
-
.map(({ id, balance }) => ({
|
|
41
|
-
identityId: new IdentifierWASM(id),
|
|
42
|
-
balance
|
|
43
|
-
}));
|
|
18
|
+
return await QueryExecutor.build(grpcPool, quorumKeyProvider)
|
|
19
|
+
.setGrpcRequest('getIdentitiesTokenBalances', getIdentitiesTokenBalancesRequest)
|
|
20
|
+
.setProofVerifier(verifyTokenBalancesForIdentitiesProof, tokenId, true, ids, LATEST_PLATFORM_VERSION)
|
|
21
|
+
.mapResponse(data => {
|
|
22
|
+
const balances = data.proved
|
|
23
|
+
? data.verified.balances
|
|
24
|
+
: data.result.identityTokenBalances.identityTokenBalances
|
|
25
|
+
.map(({ identityId, balance }) => ({ id: identityId, balance: balance != null ? BigInt(balance) : undefined }));
|
|
26
|
+
return balances
|
|
27
|
+
.map(({ id, balance }) => ({
|
|
28
|
+
identityId: new IdentifierWASM(id),
|
|
29
|
+
balance
|
|
30
|
+
}));
|
|
31
|
+
})
|
|
32
|
+
.execute();
|
|
44
33
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { GRPCPool } from '../grpcConnectionPool.js';
|
|
2
|
+
import { QuorumKeyProvider } from '../quorumKeyProvider.js';
|
|
2
3
|
import { IdentifierLike, IdentifierWASM } from 'pshenmic-dpp';
|
|
3
4
|
export interface IdentityTokenBalances {
|
|
4
5
|
tokenId: IdentifierWASM;
|
|
5
6
|
balance?: bigint | undefined;
|
|
6
7
|
}
|
|
7
|
-
export default function getIdentityTokensBalances(grpcPool: GRPCPool, identifier: IdentifierLike, tokenIdentifiers: IdentifierLike[]): Promise<IdentityTokenBalances[]>;
|
|
8
|
+
export default function getIdentityTokensBalances(grpcPool: GRPCPool, quorumKeyProvider: QuorumKeyProvider, identifier: IdentifierLike, tokenIdentifiers: IdentifierLike[]): Promise<IdentityTokenBalances[]>;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { IdentifierWASM, verifyTokensBalancesForIdentityProof } from 'pshenmic-dpp';
|
|
2
2
|
import { GetIdentityTokenBalancesRequest } from '../../proto/generated/platform.js';
|
|
3
|
-
import
|
|
4
|
-
import bytesToHex from '../utils/bytesToHex.js';
|
|
5
|
-
import verifyTenderdashProof from '../utils/verifyTenderdashProof.js';
|
|
3
|
+
import QueryExecutor from '../QueryExecutor.js';
|
|
6
4
|
import { LATEST_PLATFORM_VERSION } from '../constants.js';
|
|
7
|
-
export default async function getIdentityTokensBalances(grpcPool, identifier, tokenIdentifiers) {
|
|
5
|
+
export default async function getIdentityTokensBalances(grpcPool, quorumKeyProvider, identifier, tokenIdentifiers) {
|
|
8
6
|
const id = new IdentifierWASM(identifier);
|
|
9
7
|
const tokenIds = tokenIdentifiers.map(tokenIdentifier => new IdentifierWASM(tokenIdentifier));
|
|
10
8
|
const getIdentityTokenBalancesRequest = GetIdentityTokenBalancesRequest.create({
|
|
@@ -17,28 +15,19 @@ export default async function getIdentityTokensBalances(grpcPool, identifier, to
|
|
|
17
15
|
}
|
|
18
16
|
}
|
|
19
17
|
});
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const verify = await verifyTenderdashProof(proof, metadata, rootHash, quorumPublicKey);
|
|
36
|
-
if (!verify) {
|
|
37
|
-
throw new Error('Failed to verify query');
|
|
38
|
-
}
|
|
39
|
-
return balances
|
|
40
|
-
.map(({ id, balance }) => ({
|
|
41
|
-
tokenId: new IdentifierWASM(id),
|
|
42
|
-
balance
|
|
43
|
-
}));
|
|
18
|
+
return await QueryExecutor.build(grpcPool, quorumKeyProvider)
|
|
19
|
+
.setGrpcRequest('getIdentityTokenBalances', getIdentityTokenBalancesRequest)
|
|
20
|
+
.setProofVerifier(verifyTokensBalancesForIdentityProof, tokenIds, id, true, LATEST_PLATFORM_VERSION)
|
|
21
|
+
.mapResponse(data => {
|
|
22
|
+
const balances = data.proved
|
|
23
|
+
? data.verified.balances
|
|
24
|
+
: data.result.tokenBalances.tokenBalances
|
|
25
|
+
.map(({ tokenId, balance }) => ({ id: tokenId, balance: balance != null ? BigInt(balance) : undefined }));
|
|
26
|
+
return balances
|
|
27
|
+
.map(({ id, balance }) => ({
|
|
28
|
+
tokenId: new IdentifierWASM(id),
|
|
29
|
+
balance
|
|
30
|
+
}));
|
|
31
|
+
})
|
|
32
|
+
.execute();
|
|
44
33
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { GRPCPool } from '../grpcConnectionPool.js';
|
|
2
|
+
import { QuorumKeyProvider } from '../quorumKeyProvider.js';
|
|
2
3
|
import { IdentifierLike, IdentifierWASM } from 'pshenmic-dpp';
|
|
3
4
|
export interface TokenContractInfo {
|
|
4
5
|
dataContractId: IdentifierWASM;
|
|
5
6
|
tokenContractPosition: number;
|
|
6
7
|
}
|
|
7
|
-
export default function getTokenContractInfo(grpcPool: GRPCPool, tokenIdentifier: IdentifierLike): Promise<TokenContractInfo>;
|
|
8
|
+
export default function getTokenContractInfo(grpcPool: GRPCPool, quorumKeyProvider: QuorumKeyProvider, tokenIdentifier: IdentifierLike): Promise<TokenContractInfo>;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { GetTokenContractInfoRequest } from '../../proto/generated/platform.js';
|
|
2
2
|
import { IdentifierWASM, verifyTokenContractInfoProof } from 'pshenmic-dpp';
|
|
3
|
-
import
|
|
4
|
-
import bytesToHex from '../utils/bytesToHex.js';
|
|
5
|
-
import verifyTenderdashProof from '../utils/verifyTenderdashProof.js';
|
|
3
|
+
import QueryExecutor from '../QueryExecutor.js';
|
|
6
4
|
import { LATEST_PLATFORM_VERSION } from '../constants.js';
|
|
7
|
-
export default async function getTokenContractInfo(grpcPool, tokenIdentifier) {
|
|
5
|
+
export default async function getTokenContractInfo(grpcPool, quorumKeyProvider, tokenIdentifier) {
|
|
8
6
|
const tokenId = new IdentifierWASM(tokenIdentifier);
|
|
9
7
|
const getTokenContractInfoRequest = GetTokenContractInfoRequest.create({
|
|
10
8
|
version: {
|
|
@@ -15,30 +13,18 @@ export default async function getTokenContractInfo(grpcPool, tokenIdentifier) {
|
|
|
15
13
|
}
|
|
16
14
|
}
|
|
17
15
|
});
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (contractInfo == null) {
|
|
33
|
-
throw new Error('ContractInfo not found');
|
|
34
|
-
}
|
|
35
|
-
const quorumPublicKey = await getQuorumPublicKey(grpcPool.network, proof.quorumType, bytesToHex(proof.quorumHash));
|
|
36
|
-
const verify = await verifyTenderdashProof(proof, metadata, rootHash, quorumPublicKey);
|
|
37
|
-
if (!verify) {
|
|
38
|
-
throw new Error('Failed to verify query');
|
|
39
|
-
}
|
|
40
|
-
return {
|
|
41
|
-
dataContractId: contractInfo.contractId,
|
|
42
|
-
tokenContractPosition: contractInfo.tokenContractPosition
|
|
43
|
-
};
|
|
16
|
+
return await QueryExecutor.build(grpcPool, quorumKeyProvider)
|
|
17
|
+
.setGrpcRequest('getTokenContractInfo', getTokenContractInfoRequest)
|
|
18
|
+
.setProofVerifier(verifyTokenContractInfoProof, tokenId, true, LATEST_PLATFORM_VERSION)
|
|
19
|
+
.mapResponse(data => {
|
|
20
|
+
const contractInfo = data.proved ? data.verified.contractInfo : data.result.data;
|
|
21
|
+
if (contractInfo == null) {
|
|
22
|
+
throw new Error('ContractInfo not found');
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
dataContractId: new IdentifierWASM(contractInfo.contractId),
|
|
26
|
+
tokenContractPosition: contractInfo.tokenContractPosition
|
|
27
|
+
};
|
|
28
|
+
})
|
|
29
|
+
.execute();
|
|
44
30
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { GRPCPool } from '../grpcConnectionPool.js';
|
|
2
|
+
import { QuorumKeyProvider } from '../quorumKeyProvider.js';
|
|
2
3
|
import { TokenDirectPurchasePrices } from '../../types.js';
|
|
3
4
|
import { IdentifierLike } from 'pshenmic-dpp';
|
|
4
|
-
export default function getTokenDirectPurchasePrices(grpcPool: GRPCPool, tokenIdentifiers: IdentifierLike[]): Promise<TokenDirectPurchasePrices[]>;
|
|
5
|
+
export default function getTokenDirectPurchasePrices(grpcPool: GRPCPool, quorumKeyProvider: QuorumKeyProvider, tokenIdentifiers: IdentifierLike[]): Promise<TokenDirectPurchasePrices[]>;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { IdentifierWASM, verifyTokenDirectPurchasePrices } from 'pshenmic-dpp';
|
|
2
|
-
import
|
|
3
|
-
import verifyTenderdashProof from '../utils/verifyTenderdashProof.js';
|
|
4
|
-
import bytesToHex from '../utils/bytesToHex.js';
|
|
1
|
+
import { IdentifierWASM, verifyTokenDirectPurchasePrices, TokenPricingScheduleWASM } from 'pshenmic-dpp';
|
|
2
|
+
import QueryExecutor from '../QueryExecutor.js';
|
|
5
3
|
import { GetTokenDirectPurchasePricesRequest } from '../../proto/generated/platform.js';
|
|
6
4
|
import { LATEST_PLATFORM_VERSION } from '../constants.js';
|
|
7
|
-
export default async function getTokenDirectPurchasePrices(grpcPool, tokenIdentifiers) {
|
|
5
|
+
export default async function getTokenDirectPurchasePrices(grpcPool, quorumKeyProvider, tokenIdentifiers) {
|
|
8
6
|
const tokenIds = tokenIdentifiers.map(tokenId => new IdentifierWASM(tokenId).bytes());
|
|
9
7
|
const request = GetTokenDirectPurchasePricesRequest.create({
|
|
10
8
|
version: {
|
|
@@ -15,27 +13,27 @@ export default async function getTokenDirectPurchasePrices(grpcPool, tokenIdenti
|
|
|
15
13
|
}
|
|
16
14
|
}
|
|
17
15
|
});
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
16
|
+
return await QueryExecutor.build(grpcPool, quorumKeyProvider)
|
|
17
|
+
.setGrpcRequest('getTokenDirectPurchasePrices', request)
|
|
18
|
+
.setProofVerifier(verifyTokenDirectPurchasePrices, tokenIds, true, LATEST_PLATFORM_VERSION)
|
|
19
|
+
.mapResponse(data => {
|
|
20
|
+
if (data.proved) {
|
|
21
|
+
if (data.verified.prices == null) {
|
|
22
|
+
throw new Error('Prices not found');
|
|
23
|
+
}
|
|
24
|
+
return data.verified.prices;
|
|
25
|
+
}
|
|
26
|
+
return data.result.tokenDirectPurchasePrices.tokenDirectPurchasePrice.map(({ tokenId, price }) => {
|
|
27
|
+
let pricingSchedule;
|
|
28
|
+
if (price.oneofKind === 'fixedPrice') {
|
|
29
|
+
pricingSchedule = TokenPricingScheduleWASM.SinglePrice(BigInt(price.fixedPrice));
|
|
30
|
+
}
|
|
31
|
+
else if (price.oneofKind === 'variablePrice') {
|
|
32
|
+
pricingSchedule = TokenPricingScheduleWASM.SetPrices(Object.fromEntries(price.variablePrice.priceForQuantity
|
|
33
|
+
.map(({ quantity, price }) => [quantity, BigInt(price)])));
|
|
34
|
+
}
|
|
35
|
+
return { tokenId: new IdentifierWASM(tokenId), pricingSchedule };
|
|
36
|
+
});
|
|
37
|
+
})
|
|
38
|
+
.execute();
|
|
41
39
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { GRPCPool } from '../grpcConnectionPool.js';
|
|
2
|
+
import { QuorumKeyProvider } from '../quorumKeyProvider.js';
|
|
2
3
|
import { TokenTotalSupply } from '../../types.js';
|
|
3
4
|
import { IdentifierLike } from 'pshenmic-dpp';
|
|
4
|
-
export default function getTokenTotalSupply(grpcPool: GRPCPool, tokenIdentifier: IdentifierLike): Promise<TokenTotalSupply>;
|
|
5
|
+
export default function getTokenTotalSupply(grpcPool: GRPCPool, quorumKeyProvider: QuorumKeyProvider, tokenIdentifier: IdentifierLike): Promise<TokenTotalSupply>;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { GetTokenTotalSupplyRequest } from '../../proto/generated/platform.js';
|
|
2
2
|
import { IdentifierWASM, verifyTokenTotalSupplyProof } from 'pshenmic-dpp';
|
|
3
|
-
import
|
|
4
|
-
import bytesToHex from '../utils/bytesToHex.js';
|
|
5
|
-
import verifyTenderdashProof from '../utils/verifyTenderdashProof.js';
|
|
3
|
+
import QueryExecutor from '../QueryExecutor.js';
|
|
6
4
|
import { LATEST_PLATFORM_VERSION } from '../constants.js';
|
|
7
|
-
export default async function getTokenTotalSupply(grpcPool, tokenIdentifier) {
|
|
5
|
+
export default async function getTokenTotalSupply(grpcPool, quorumKeyProvider, tokenIdentifier) {
|
|
8
6
|
const tokenId = new IdentifierWASM(tokenIdentifier);
|
|
9
7
|
const getTokenTotalSupplyRequest = GetTokenTotalSupplyRequest.create({
|
|
10
8
|
version: {
|
|
@@ -15,28 +13,18 @@ export default async function getTokenTotalSupply(grpcPool, tokenIdentifier) {
|
|
|
15
13
|
}
|
|
16
14
|
}
|
|
17
15
|
});
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const quorumPublicKey = await getQuorumPublicKey(grpcPool.network, proof.quorumType, bytesToHex(proof.quorumHash));
|
|
33
|
-
const verify = await verifyTenderdashProof(proof, metadata, rootHash, quorumPublicKey);
|
|
34
|
-
if (!verify) {
|
|
35
|
-
throw new Error('Failed to verify query');
|
|
36
|
-
}
|
|
37
|
-
return {
|
|
38
|
-
tokenId,
|
|
39
|
-
totalSystemAmount: totalBalance.tokenSupply,
|
|
40
|
-
totalAggregatedAmountInUserAccounts: totalBalance.aggregatedTokenAccountBalances
|
|
41
|
-
};
|
|
16
|
+
return await QueryExecutor.build(grpcPool, quorumKeyProvider)
|
|
17
|
+
.setGrpcRequest('getTokenTotalSupply', getTokenTotalSupplyRequest)
|
|
18
|
+
.setProofVerifier(verifyTokenTotalSupplyProof, tokenId, true, LATEST_PLATFORM_VERSION)
|
|
19
|
+
.mapResponse(data => {
|
|
20
|
+
const [totalSystemAmount, totalAggregatedAmountInUserAccounts] = data.proved
|
|
21
|
+
? [data.verified.totalBalance.tokenSupply, data.verified.totalBalance.aggregatedTokenAccountBalances]
|
|
22
|
+
: [BigInt(data.result.tokenTotalSupply.totalSystemAmount), BigInt(data.result.tokenTotalSupply.totalAggregatedAmountInUserAccounts)];
|
|
23
|
+
return {
|
|
24
|
+
tokenId,
|
|
25
|
+
totalSystemAmount,
|
|
26
|
+
totalAggregatedAmountInUserAccounts
|
|
27
|
+
};
|
|
28
|
+
})
|
|
29
|
+
.execute();
|
|
42
30
|
}
|
package/src/tokens/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { GRPCPool } from '../grpcConnectionPool.js';
|
|
2
|
+
import { QuorumKeyProvider } from '../quorumKeyProvider.js';
|
|
2
3
|
import { TokenDirectPurchasePrices, TokenTotalSupply, TokenTransitionParams, TokenTransitionType } from '../../types.js';
|
|
3
4
|
import { IdentitiesTokenBalances } from './getIdentitiesTokenBalances.js';
|
|
4
5
|
import { IdentityTokenBalances } from './getIdentityTokensBalances.js';
|
|
@@ -12,7 +13,9 @@ import { IdentifierLike, StateTransitionWASM, TokenBaseTransitionWASM } from 'ps
|
|
|
12
13
|
export declare class TokensController {
|
|
13
14
|
/** @ignore **/
|
|
14
15
|
grpcPool: GRPCPool;
|
|
15
|
-
|
|
16
|
+
/** @ignore **/
|
|
17
|
+
quorumKeyProvider: QuorumKeyProvider;
|
|
18
|
+
constructor(grpcPool: GRPCPool, quorumKeyProvider: QuorumKeyProvider);
|
|
16
19
|
/**
|
|
17
20
|
* Retrieves a token balances for identities
|
|
18
21
|
*
|
package/src/tokens/index.js
CHANGED
|
@@ -14,8 +14,11 @@ import getTokenDirectPurchasePrices from './getTokenDirectPurchasePrices.js';
|
|
|
14
14
|
export class TokensController {
|
|
15
15
|
/** @ignore **/
|
|
16
16
|
grpcPool;
|
|
17
|
-
|
|
17
|
+
/** @ignore **/
|
|
18
|
+
quorumKeyProvider;
|
|
19
|
+
constructor(grpcPool, quorumKeyProvider) {
|
|
18
20
|
this.grpcPool = grpcPool;
|
|
21
|
+
this.quorumKeyProvider = quorumKeyProvider;
|
|
19
22
|
}
|
|
20
23
|
/**
|
|
21
24
|
* Retrieves a token balances for identities
|
|
@@ -26,7 +29,7 @@ export class TokensController {
|
|
|
26
29
|
* @return {Promise<IdentitiesTokenBalances>}
|
|
27
30
|
*/
|
|
28
31
|
async getIdentitiesTokenBalances(identifiers, tokenIdentifier) {
|
|
29
|
-
return await getIdentitiesTokenBalances(this.grpcPool, identifiers, tokenIdentifier);
|
|
32
|
+
return await getIdentitiesTokenBalances(this.grpcPool, this.quorumKeyProvider, identifiers, tokenIdentifier);
|
|
30
33
|
}
|
|
31
34
|
/**
|
|
32
35
|
* Retrieves a tokens balances for identity
|
|
@@ -37,7 +40,7 @@ export class TokensController {
|
|
|
37
40
|
* @return {Promise<IdentityTokenBalances>}
|
|
38
41
|
*/
|
|
39
42
|
async getIdentityTokensBalances(identifier, tokenIdentifiers) {
|
|
40
|
-
return await getIdentityTokensBalances(this.grpcPool, identifier, tokenIdentifiers);
|
|
43
|
+
return await getIdentityTokensBalances(this.grpcPool, this.quorumKeyProvider, identifier, tokenIdentifiers);
|
|
41
44
|
}
|
|
42
45
|
/**
|
|
43
46
|
* Retrieves a tokens contract info by id
|
|
@@ -47,7 +50,7 @@ export class TokensController {
|
|
|
47
50
|
* @return {Promise<TokenContractInfo>}
|
|
48
51
|
*/
|
|
49
52
|
async getTokenContractInfo(tokenIdentifier) {
|
|
50
|
-
return await getTokenContractInfo(this.grpcPool, tokenIdentifier);
|
|
53
|
+
return await getTokenContractInfo(this.grpcPool, this.quorumKeyProvider, tokenIdentifier);
|
|
51
54
|
}
|
|
52
55
|
/**
|
|
53
56
|
* Retrieves a token total supply
|
|
@@ -57,7 +60,7 @@ export class TokensController {
|
|
|
57
60
|
* @return {Promise<TokenTotalSupply>}
|
|
58
61
|
*/
|
|
59
62
|
async getTokenTotalSupply(tokenIdentifier) {
|
|
60
|
-
return await getTokenTotalSupply(this.grpcPool, tokenIdentifier);
|
|
63
|
+
return await getTokenTotalSupply(this.grpcPool, this.quorumKeyProvider, tokenIdentifier);
|
|
61
64
|
}
|
|
62
65
|
/**
|
|
63
66
|
* Retrieves a tokens prices
|
|
@@ -67,7 +70,7 @@ export class TokensController {
|
|
|
67
70
|
* @return {Promise<TokenDirectPurchasePrices[]>}
|
|
68
71
|
*/
|
|
69
72
|
async getTokensDirectPurchasePrice(tokenIdentifiers) {
|
|
70
|
-
return await getTokenDirectPurchasePrices(this.grpcPool, tokenIdentifiers);
|
|
73
|
+
return await getTokenDirectPurchasePrices(this.grpcPool, this.quorumKeyProvider, tokenIdentifiers);
|
|
71
74
|
}
|
|
72
75
|
/**
|
|
73
76
|
* Creates a Token Base Transition that contains base information about token transition
|
|
@@ -78,8 +81,8 @@ export class TokensController {
|
|
|
78
81
|
* @return {TokenBaseTransitionWASM}
|
|
79
82
|
*/
|
|
80
83
|
async createBaseTransition(tokenId, ownerId) {
|
|
81
|
-
const { dataContractId, tokenContractPosition } = await getTokenContractInfo(this.grpcPool, tokenId);
|
|
82
|
-
const identityContractNonce = await getIdentityContractNonce(this.grpcPool, ownerId, dataContractId);
|
|
84
|
+
const { dataContractId, tokenContractPosition } = await getTokenContractInfo(this.grpcPool, this.quorumKeyProvider, tokenId);
|
|
85
|
+
const identityContractNonce = await getIdentityContractNonce(this.grpcPool, this.quorumKeyProvider, ownerId, dataContractId);
|
|
83
86
|
return new TokenBaseTransitionWASM(identityContractNonce + BigInt(1), tokenContractPosition, dataContractId, tokenId, undefined);
|
|
84
87
|
}
|
|
85
88
|
/**
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thrown when the response of a node can not be verified (invalid GroveDB proof, invalid quorum signature, stale metadata).
|
|
3
|
+
* Such node is banned and the request is retried on another node
|
|
4
|
+
*/
|
|
5
|
+
export default class ProofError extends Error {
|
|
6
|
+
constructor(message: string, options?: {
|
|
7
|
+
cause?: unknown;
|
|
8
|
+
});
|
|
9
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thrown when the response of a node can not be verified (invalid GroveDB proof, invalid quorum signature, stale metadata).
|
|
3
|
+
* Such node is banned and the request is retried on another node
|
|
4
|
+
*/
|
|
5
|
+
export default class ProofError extends Error {
|
|
6
|
+
constructor(message, options) {
|
|
7
|
+
super(message, options);
|
|
8
|
+
this.name = 'ProofError';
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -3,9 +3,10 @@ import { calculateSignHash } from './calculateSignHash.js';
|
|
|
3
3
|
import { calculateStateIdHash } from './calculateStateIdHash.js';
|
|
4
4
|
import { verifySignatureDigest } from 'pshenmic-dpp';
|
|
5
5
|
import hexToBytes from './hexToBytes.js';
|
|
6
|
+
import ProofError from './ProofError.js';
|
|
6
7
|
export default async function verifyTenderdashProof(proof, metadata, rootHash, quorumPublicKey) {
|
|
7
8
|
if (Date.now() - Number(metadata.timeMs) > 15 * 60 * 1000) {
|
|
8
|
-
throw new
|
|
9
|
+
throw new ProofError('Request is stalled (over 15 minutes)');
|
|
9
10
|
}
|
|
10
11
|
const stateId = StateId.create({
|
|
11
12
|
appVersion: String(metadata.protocolVersion),
|
package/test/unit/SDK.spec.js
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
import { DashPlatformSDK } from '../../src/DashPlatformSDK.js';
|
|
2
|
+
import { PlatformExplorerQuorumKeyProvider } from '../../src/quorumKeyProvider.js';
|
|
2
3
|
let sdk;
|
|
4
|
+
const identifier = 'QMfCRPcjXoTnZa9sA9JR2KWgGxZXMRJ4akgS3Uia1Qv';
|
|
5
|
+
// takes quorum public keys from DAPI validator sets, so proofs can be verified without Platform Explorer
|
|
6
|
+
const createQuorumKeyProvider = (sdk) => {
|
|
7
|
+
const requests = [];
|
|
8
|
+
return {
|
|
9
|
+
requests,
|
|
10
|
+
getQuorumPublicKey: async (quorumType, quorumHash) => {
|
|
11
|
+
requests.push(quorumHash);
|
|
12
|
+
const { validatorSets } = await sdk.node.getCurrentQuorumsInfo();
|
|
13
|
+
const validatorSet = validatorSets.find(validatorSet => validatorSet.quorumHash === quorumHash);
|
|
14
|
+
if (validatorSet == null) {
|
|
15
|
+
throw new Error(`Unknown quorum ${quorumHash}`);
|
|
16
|
+
}
|
|
17
|
+
return validatorSet.thresholdPublicKey;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
};
|
|
3
21
|
describe('DashPlatformSDK', () => {
|
|
4
22
|
beforeAll(() => {
|
|
5
23
|
sdk = new DashPlatformSDK({ network: 'testnet' });
|
|
@@ -7,6 +25,30 @@ describe('DashPlatformSDK', () => {
|
|
|
7
25
|
test('should be constructable throw `new`', () => {
|
|
8
26
|
expect(sdk).toEqual(expect.any(DashPlatformSDK));
|
|
9
27
|
});
|
|
28
|
+
test('should use Platform Explorer quorum key provider by default', () => {
|
|
29
|
+
expect(sdk.quorumKeyProvider).toEqual(expect.any(PlatformExplorerQuorumKeyProvider));
|
|
30
|
+
});
|
|
31
|
+
test('should verify proofs with custom quorum key provider', async () => {
|
|
32
|
+
const customSdk = new DashPlatformSDK({ network: 'testnet' });
|
|
33
|
+
const quorumKeyProvider = createQuorumKeyProvider(customSdk);
|
|
34
|
+
customSdk.setQuorumKeyProvider(quorumKeyProvider);
|
|
35
|
+
const balance = await customSdk.identities.getIdentityBalance(identifier);
|
|
36
|
+
expect(balance).toEqual(expect.any(BigInt));
|
|
37
|
+
expect(quorumKeyProvider.requests).toHaveLength(1);
|
|
38
|
+
});
|
|
39
|
+
test('should not share quorum key provider between instances', () => {
|
|
40
|
+
const quorumKeyProvider = createQuorumKeyProvider(sdk);
|
|
41
|
+
const customSdk = new DashPlatformSDK({ network: 'testnet', quorumKeyProvider });
|
|
42
|
+
const defaultSdk = new DashPlatformSDK({ network: 'testnet' });
|
|
43
|
+
expect(customSdk.quorumKeyProvider).toBe(quorumKeyProvider);
|
|
44
|
+
expect(defaultSdk.quorumKeyProvider).toEqual(expect.any(PlatformExplorerQuorumKeyProvider));
|
|
45
|
+
expect(defaultSdk.quorumKeyProvider).not.toBe(sdk.quorumKeyProvider);
|
|
46
|
+
});
|
|
47
|
+
test('should switch back to Platform Explorer quorum key provider', () => {
|
|
48
|
+
const customSdk = new DashPlatformSDK({ network: 'testnet', quorumKeyProvider: createQuorumKeyProvider(sdk) });
|
|
49
|
+
customSdk.setQuorumKeyProvider();
|
|
50
|
+
expect(customSdk.quorumKeyProvider).toEqual(expect.any(PlatformExplorerQuorumKeyProvider));
|
|
51
|
+
});
|
|
10
52
|
test('should be able to deserialize consensus error', () => {
|
|
11
53
|
const err = sdk.utils.deserializeConsensusError('AwIiSW52YWxpZCBTdGF0ZSBUcmFuc2l0aW9uIHNpZ25hdHVyZQ');
|
|
12
54
|
expect(err).toEqual('Invalid State Transition signature');
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function getQuorumPublicKey(network: string, quorumType: number, quorumHash: string): Promise<string>;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { fetchWithDetails } from './fetchWithDetails.js';
|
|
2
|
-
const cache = {};
|
|
3
|
-
export async function getQuorumPublicKey(network, quorumType, quorumHash) {
|
|
4
|
-
const cached = cache[`${quorumType}_${quorumHash}`];
|
|
5
|
-
if (cached != null) {
|
|
6
|
-
return cached;
|
|
7
|
-
}
|
|
8
|
-
const url = `https://${network === 'mainnet' ? '' : 'testnet.'}platform-explorer.pshenmic.dev/quorum/info?quorumType=${quorumType}&quorumHash=${quorumHash}`;
|
|
9
|
-
const resp = await fetchWithDetails(url, {
|
|
10
|
-
method: 'GET'
|
|
11
|
-
});
|
|
12
|
-
if (resp.status !== 200) {
|
|
13
|
-
throw new Error('Failed to query Platform Explorer for quorum public keys');
|
|
14
|
-
}
|
|
15
|
-
const data = await resp.json();
|
|
16
|
-
const { quorumPublicKey } = data;
|
|
17
|
-
cache[`${quorumType}_${quorumHash}`] = quorumPublicKey;
|
|
18
|
-
return quorumPublicKey;
|
|
19
|
-
}
|