dash-platform-sdk 1.6.0-dev.6 → 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.
- package/README.md +14 -14
- package/bundle.min.js +1 -1
- package/package.json +1 -1
- package/src/QueryExecutor.d.ts +40 -4
- package/src/QueryExecutor.js +61 -8
- package/src/constants.d.ts +7 -1
- package/src/constants.js +9 -2
- package/src/contestedResources/getContestedResourceVoteState.js +14 -6
- package/src/contestedResources/getVotePollsByEndDate.js +7 -2
- package/src/dataContracts/getDataContractByIdentifier.js +3 -3
- package/src/documents/index.d.ts +4 -1
- package/src/documents/index.js +6 -2
- package/src/documents/query.js +4 -4
- package/src/documents/queryAggregate.js +2 -3
- package/src/documents/queryJoined.js +6 -7
- package/src/documents/queryRanked.js +2 -3
- package/src/documents/v1.d.ts +2 -2
- package/src/documents/v1.js +2 -3
- package/src/grpcConnectionPool.d.ts +9 -2
- package/src/grpcConnectionPool.js +7 -8
- package/src/identities/getIdentityBalance.js +1 -2
- package/src/identities/getIdentityByIdentifier.js +1 -2
- package/src/identities/getIdentityByNonUniquePublicKeyHash.js +2 -3
- package/src/identities/getIdentityByPublicKeyHash.js +1 -2
- package/src/identities/getIdentityContractNonce.js +1 -2
- package/src/identities/getIdentityNonce.js +1 -2
- package/src/identities/getIdentityPublicKeys.js +1 -2
- package/src/names/index.d.ts +1 -1
- package/src/names/index.js +1 -1
- package/src/names/registerName.js +5 -2
- package/src/node/epochInfos.js +1 -2
- package/src/node/finalizedEpochInfos.js +1 -2
- package/src/node/getProtocolVersion.d.ts +9 -0
- package/src/node/getProtocolVersion.js +29 -0
- package/src/node/index.d.ts +9 -0
- package/src/node/index.js +11 -0
- package/src/node/totalCredits.js +3 -3
- package/src/platformAddresses/getAddressInfo.js +1 -2
- package/src/platformAddresses/getAddressesBranchState.js +1 -2
- package/src/platformAddresses/getAddressesInfos.js +1 -2
- package/src/platformAddresses/getAddressesTrunkState.js +1 -2
- package/src/platformAddresses/getRecentAddressBalanceChanges.js +2 -2
- package/src/platformAddresses/getRecentCompactedAddressBalanceChanges.js +2 -2
- package/src/shielded/getMostRecentShieldedAnchor.js +1 -2
- package/src/shielded/getShieldedAnchors.js +1 -2
- package/src/shielded/getShieldedEncryptedNotes.js +2 -2
- package/src/shielded/getShieldedNotesCount.js +1 -2
- package/src/shielded/getShieldedNullifiers.js +1 -2
- package/src/shielded/getShieldedPoolState.js +1 -2
- package/src/stateTransitions/waitForStateTransitionResult.js +14 -12
- package/src/tokens/getIdentitiesTokenBalances.js +1 -2
- package/src/tokens/getIdentityTokensBalances.js +1 -2
- package/src/tokens/getTokenContractInfo.js +1 -2
- package/src/tokens/getTokenDirectPurchasePrices.js +1 -2
- package/src/tokens/getTokenTotalSupply.js +1 -2
- package/test/unit/SDK.spec.js +38 -0
|
@@ -3,7 +3,7 @@ import hexToBytes from '../utils/hexToBytes.js';
|
|
|
3
3
|
import { WaitForStateTransitionResultRequest } from '../../proto/generated/platform.js';
|
|
4
4
|
import QueryExecutor, { getResponseProof } from '../QueryExecutor.js';
|
|
5
5
|
import { base64 } from '@scure/base';
|
|
6
|
-
import { LATEST_PLATFORM_VERSION } from '../constants.js';
|
|
6
|
+
import { LATEST_PLATFORM_VERSION, WITHDRAWALS_DATA_CONTRACT_ID } from '../constants.js';
|
|
7
7
|
import getDataContractByIdentifier from '../dataContracts/getDataContractByIdentifier.js';
|
|
8
8
|
function toStateTransitionError(txHash, { code, message, data }) {
|
|
9
9
|
return new Error(`State transition ${txHash} failed to execute with code ${String(code)}, message: ${String(message)}, data: ${base64.encode(data)}`);
|
|
@@ -16,8 +16,7 @@ export default async function waitForStateTransitionResult(grpcPool, quorumKeyPr
|
|
|
16
16
|
v0: {
|
|
17
17
|
stateTransitionHash: hexToBytes(txHash),
|
|
18
18
|
prove: true,
|
|
19
|
-
|
|
20
|
-
requestUserBalance: grpcPool.proofs === false
|
|
19
|
+
requestUserBalance: false
|
|
21
20
|
}
|
|
22
21
|
}
|
|
23
22
|
});
|
|
@@ -32,8 +31,14 @@ export default async function waitForStateTransitionResult(grpcPool, quorumKeyPr
|
|
|
32
31
|
const masternodeVote = MasternodeVoteTransitionWASM.fromStateTransition(stateTransition);
|
|
33
32
|
knownContracts.push(await getDataContractByIdentifier(grpcPool, quorumKeyProvider, masternodeVote.vote.votePoll.contractId));
|
|
34
33
|
}
|
|
34
|
+
// withdrawal documents of the shielded pool are created in the withdrawals system contract
|
|
35
|
+
if (stateTransition.getActionType() === 'SHIELDED_WITHDRAWAL') {
|
|
36
|
+
knownContracts.push(await getDataContractByIdentifier(grpcPool, quorumKeyProvider, WITHDRAWALS_DATA_CONTRACT_ID));
|
|
37
|
+
}
|
|
35
38
|
return await QueryExecutor.build(grpcPool, quorumKeyProvider)
|
|
36
39
|
.setGrpcRequest('waitForStateTransitionResult', waitForStateTransitionResultRequest)
|
|
40
|
+
// the result is always verified, also if proofs are disabled in the pool
|
|
41
|
+
.setRequireProof(true)
|
|
37
42
|
.mapProof(response => {
|
|
38
43
|
const { version } = response;
|
|
39
44
|
if (version.oneofKind !== 'v0') {
|
|
@@ -53,19 +58,16 @@ export default async function waitForStateTransitionResult(grpcPool, quorumKeyPr
|
|
|
53
58
|
coreHeight: coreChainLockedHeight,
|
|
54
59
|
epoch
|
|
55
60
|
};
|
|
56
|
-
return [stateTransition, blockInfo, knownContracts, LATEST_PLATFORM_VERSION];
|
|
61
|
+
return [stateTransition, blockInfo, knownContracts, Math.min(metadata.protocolVersion, LATEST_PLATFORM_VERSION)];
|
|
57
62
|
})
|
|
58
63
|
.mapResponse(data => {
|
|
59
|
-
if (data.proved) {
|
|
60
|
-
|
|
61
|
-
throw new Error('State transition result was null');
|
|
62
|
-
}
|
|
63
|
-
return data.verified.ownerBalance;
|
|
64
|
+
if (!data.proved) {
|
|
65
|
+
throw new Error('State transition result must be proved');
|
|
64
66
|
}
|
|
65
|
-
if (data.result
|
|
66
|
-
throw
|
|
67
|
+
if (data.verified.result == null) {
|
|
68
|
+
throw new Error('State transition result was null');
|
|
67
69
|
}
|
|
68
|
-
return
|
|
70
|
+
return data.verified.ownerBalance;
|
|
69
71
|
})
|
|
70
72
|
.execute();
|
|
71
73
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { GetIdentitiesTokenBalancesRequest } from '../../proto/generated/platform.js';
|
|
2
2
|
import { IdentifierWASM, verifyTokenBalancesForIdentitiesProof } from 'pshenmic-dpp';
|
|
3
3
|
import QueryExecutor from '../QueryExecutor.js';
|
|
4
|
-
import { LATEST_PLATFORM_VERSION } from '../constants.js';
|
|
5
4
|
export default async function getIdentitiesTokenBalances(grpcPool, quorumKeyProvider, identifiers, tokenIdentifier) {
|
|
6
5
|
const ids = identifiers.map(identifier => new IdentifierWASM(identifier));
|
|
7
6
|
const tokenId = new IdentifierWASM(tokenIdentifier);
|
|
@@ -17,7 +16,7 @@ export default async function getIdentitiesTokenBalances(grpcPool, quorumKeyProv
|
|
|
17
16
|
});
|
|
18
17
|
return await QueryExecutor.build(grpcPool, quorumKeyProvider)
|
|
19
18
|
.setGrpcRequest('getIdentitiesTokenBalances', getIdentitiesTokenBalancesRequest)
|
|
20
|
-
.setProofVerifier(verifyTokenBalancesForIdentitiesProof, tokenId, true, ids,
|
|
19
|
+
.setProofVerifier(verifyTokenBalancesForIdentitiesProof, (_, platformVersion) => [tokenId, true, ids, platformVersion])
|
|
21
20
|
.mapResponse(data => {
|
|
22
21
|
const balances = data.proved
|
|
23
22
|
? data.verified.balances
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { IdentifierWASM, verifyTokensBalancesForIdentityProof } from 'pshenmic-dpp';
|
|
2
2
|
import { GetIdentityTokenBalancesRequest } 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 getIdentityTokensBalances(grpcPool, quorumKeyProvider, identifier, tokenIdentifiers) {
|
|
6
5
|
const id = new IdentifierWASM(identifier);
|
|
7
6
|
const tokenIds = tokenIdentifiers.map(tokenIdentifier => new IdentifierWASM(tokenIdentifier));
|
|
@@ -17,7 +16,7 @@ export default async function getIdentityTokensBalances(grpcPool, quorumKeyProvi
|
|
|
17
16
|
});
|
|
18
17
|
return await QueryExecutor.build(grpcPool, quorumKeyProvider)
|
|
19
18
|
.setGrpcRequest('getIdentityTokenBalances', getIdentityTokenBalancesRequest)
|
|
20
|
-
.setProofVerifier(verifyTokensBalancesForIdentityProof, tokenIds, id, true,
|
|
19
|
+
.setProofVerifier(verifyTokensBalancesForIdentityProof, (_, platformVersion) => [tokenIds, id, true, platformVersion])
|
|
21
20
|
.mapResponse(data => {
|
|
22
21
|
const balances = data.proved
|
|
23
22
|
? data.verified.balances
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { GetTokenContractInfoRequest } from '../../proto/generated/platform.js';
|
|
2
2
|
import { IdentifierWASM, verifyTokenContractInfoProof } from 'pshenmic-dpp';
|
|
3
3
|
import QueryExecutor from '../QueryExecutor.js';
|
|
4
|
-
import { LATEST_PLATFORM_VERSION } from '../constants.js';
|
|
5
4
|
export default async function getTokenContractInfo(grpcPool, quorumKeyProvider, tokenIdentifier) {
|
|
6
5
|
const tokenId = new IdentifierWASM(tokenIdentifier);
|
|
7
6
|
const getTokenContractInfoRequest = GetTokenContractInfoRequest.create({
|
|
@@ -15,7 +14,7 @@ export default async function getTokenContractInfo(grpcPool, quorumKeyProvider,
|
|
|
15
14
|
});
|
|
16
15
|
return await QueryExecutor.build(grpcPool, quorumKeyProvider)
|
|
17
16
|
.setGrpcRequest('getTokenContractInfo', getTokenContractInfoRequest)
|
|
18
|
-
.setProofVerifier(verifyTokenContractInfoProof, tokenId, true,
|
|
17
|
+
.setProofVerifier(verifyTokenContractInfoProof, (_, platformVersion) => [tokenId, true, platformVersion])
|
|
19
18
|
.mapResponse(data => {
|
|
20
19
|
const contractInfo = data.proved ? data.verified.contractInfo : data.result.data;
|
|
21
20
|
if (contractInfo == null) {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { IdentifierWASM, verifyTokenDirectPurchasePrices, TokenPricingScheduleWASM } from 'pshenmic-dpp';
|
|
2
2
|
import QueryExecutor from '../QueryExecutor.js';
|
|
3
3
|
import { GetTokenDirectPurchasePricesRequest } from '../../proto/generated/platform.js';
|
|
4
|
-
import { LATEST_PLATFORM_VERSION } from '../constants.js';
|
|
5
4
|
export default async function getTokenDirectPurchasePrices(grpcPool, quorumKeyProvider, tokenIdentifiers) {
|
|
6
5
|
const tokenIds = tokenIdentifiers.map(tokenId => new IdentifierWASM(tokenId).bytes());
|
|
7
6
|
const request = GetTokenDirectPurchasePricesRequest.create({
|
|
@@ -15,7 +14,7 @@ export default async function getTokenDirectPurchasePrices(grpcPool, quorumKeyPr
|
|
|
15
14
|
});
|
|
16
15
|
return await QueryExecutor.build(grpcPool, quorumKeyProvider)
|
|
17
16
|
.setGrpcRequest('getTokenDirectPurchasePrices', request)
|
|
18
|
-
.setProofVerifier(verifyTokenDirectPurchasePrices, tokenIds, true,
|
|
17
|
+
.setProofVerifier(verifyTokenDirectPurchasePrices, (_, platformVersion) => [tokenIds, true, platformVersion])
|
|
19
18
|
.mapResponse(data => {
|
|
20
19
|
if (data.proved) {
|
|
21
20
|
if (data.verified.prices == null) {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { GetTokenTotalSupplyRequest } from '../../proto/generated/platform.js';
|
|
2
2
|
import { IdentifierWASM, verifyTokenTotalSupplyProof } from 'pshenmic-dpp';
|
|
3
3
|
import QueryExecutor from '../QueryExecutor.js';
|
|
4
|
-
import { LATEST_PLATFORM_VERSION } from '../constants.js';
|
|
5
4
|
export default async function getTokenTotalSupply(grpcPool, quorumKeyProvider, tokenIdentifier) {
|
|
6
5
|
const tokenId = new IdentifierWASM(tokenIdentifier);
|
|
7
6
|
const getTokenTotalSupplyRequest = GetTokenTotalSupplyRequest.create({
|
|
@@ -15,7 +14,7 @@ export default async function getTokenTotalSupply(grpcPool, quorumKeyProvider, t
|
|
|
15
14
|
});
|
|
16
15
|
return await QueryExecutor.build(grpcPool, quorumKeyProvider)
|
|
17
16
|
.setGrpcRequest('getTokenTotalSupply', getTokenTotalSupplyRequest)
|
|
18
|
-
.setProofVerifier(verifyTokenTotalSupplyProof, tokenId, true,
|
|
17
|
+
.setProofVerifier(verifyTokenTotalSupplyProof, (_, platformVersion) => [tokenId, true, platformVersion])
|
|
19
18
|
.mapResponse(data => {
|
|
20
19
|
const [totalSystemAmount, totalAggregatedAmountInUserAccounts] = data.proved
|
|
21
20
|
? [data.verified.totalBalance.tokenSupply, data.verified.totalBalance.aggregatedTokenAccountBalances]
|
package/test/unit/SDK.spec.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { DashPlatformSDK } from '../../src/DashPlatformSDK.js';
|
|
2
2
|
import { PlatformExplorerQuorumKeyProvider } from '../../src/quorumKeyProvider.js';
|
|
3
|
+
import { getVerifierVersion } from '../../src/QueryExecutor.js';
|
|
4
|
+
import { DocumentWASM, PlatformVersionWASM } from 'pshenmic-dpp';
|
|
5
|
+
import { DPNS_DATA_CONTRACT_ID, LATEST_PLATFORM_VERSION, MIN_PROTOCOL_VERSION } from '../../src/constants.js';
|
|
3
6
|
let sdk;
|
|
4
7
|
const identifier = 'QMfCRPcjXoTnZa9sA9JR2KWgGxZXMRJ4akgS3Uia1Qv';
|
|
5
8
|
// takes quorum public keys from DAPI validator sets, so proofs can be verified without Platform Explorer
|
|
@@ -49,6 +52,41 @@ describe('DashPlatformSDK', () => {
|
|
|
49
52
|
customSdk.setQuorumKeyProvider();
|
|
50
53
|
expect(customSdk.quorumKeyProvider).toEqual(expect.any(PlatformExplorerQuorumKeyProvider));
|
|
51
54
|
});
|
|
55
|
+
test('should learn protocol version of the network from verified responses', async () => {
|
|
56
|
+
const customSdk = new DashPlatformSDK({ network: 'testnet' });
|
|
57
|
+
expect(customSdk.grpcPool.protocolVersion).toEqual(MIN_PROTOCOL_VERSION.testnet);
|
|
58
|
+
await customSdk.identities.getIdentityBalance(identifier);
|
|
59
|
+
expect(customSdk.grpcPool.protocolVersion).toEqual(LATEST_PLATFORM_VERSION);
|
|
60
|
+
});
|
|
61
|
+
test('should not learn protocol version from unverified responses', async () => {
|
|
62
|
+
const customSdk = new DashPlatformSDK({ network: 'testnet', proofs: false });
|
|
63
|
+
await customSdk.identities.getIdentityBalance(identifier);
|
|
64
|
+
expect(customSdk.grpcPool.protocolVersion).toEqual(MIN_PROTOCOL_VERSION.testnet);
|
|
65
|
+
});
|
|
66
|
+
test('should learn protocol version of the network with proofs disabled', async () => {
|
|
67
|
+
const customSdk = new DashPlatformSDK({ network: 'testnet', proofs: false });
|
|
68
|
+
expect(await customSdk.node.getProtocolVersion()).toEqual(LATEST_PLATFORM_VERSION);
|
|
69
|
+
expect(customSdk.grpcPool.protocolVersion).toEqual(LATEST_PLATFORM_VERSION);
|
|
70
|
+
});
|
|
71
|
+
test('should create documents with id of the protocol version of the network', () => {
|
|
72
|
+
const customSdk = new DashPlatformSDK({ network: 'testnet' });
|
|
73
|
+
const nonce = 5n;
|
|
74
|
+
for (const protocolVersion of [PlatformVersionWASM.PLATFORM_V13, PlatformVersionWASM.PLATFORM_V14]) {
|
|
75
|
+
customSdk.grpcPool.protocolVersion = protocolVersion;
|
|
76
|
+
const document = customSdk.documents.create(DPNS_DATA_CONTRACT_ID, 'preorder', { saltedDomainHash: new Uint8Array(32) }, identifier, nonce);
|
|
77
|
+
const expectedId = DocumentWASM.generateId('preorder', identifier, DPNS_DATA_CONTRACT_ID, document.entropy, nonce, protocolVersion);
|
|
78
|
+
expect(document.id.base58()).toEqual(expectedId.base58());
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
test('should select platform version to verify proofs with', () => {
|
|
82
|
+
// newer signed version is used
|
|
83
|
+
expect(getVerifierVersion(13, 14)).toEqual(14);
|
|
84
|
+
// older signed version is not
|
|
85
|
+
expect(getVerifierVersion(14, 13)).toEqual(14);
|
|
86
|
+
expect(getVerifierVersion(13, 0)).toEqual(13);
|
|
87
|
+
// unknown version falls back to the latest known one
|
|
88
|
+
expect(getVerifierVersion(13, LATEST_PLATFORM_VERSION + 1)).toEqual(LATEST_PLATFORM_VERSION);
|
|
89
|
+
});
|
|
52
90
|
test('should be able to deserialize consensus error', () => {
|
|
53
91
|
const err = sdk.utils.deserializeConsensusError('AwIiSW52YWxpZCBTdGF0ZSBUcmFuc2l0aW9uIHNpZ25hdHVyZQ');
|
|
54
92
|
expect(err).toEqual('Invalid State Transition signature');
|