dash-platform-sdk 1.6.0-dev.2 → 1.6.0-dev.3

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 (121) hide show
  1. package/README.md +33 -15
  2. package/bundle.min.js +1 -1
  3. package/index.d.ts +3 -1
  4. package/index.js +2 -1
  5. package/package.json +2 -2
  6. package/proto/generated/platform.d.ts +128 -2
  7. package/proto/generated/platform.js +266 -8
  8. package/src/DashPlatformSDK.d.ts +19 -1
  9. package/src/DashPlatformSDK.js +28 -10
  10. package/src/QueryExecutor.d.ts +122 -0
  11. package/src/QueryExecutor.js +205 -0
  12. package/src/constants.d.ts +6 -0
  13. package/src/constants.js +6 -0
  14. package/src/contestedResources/getContestedResourceVoteState.d.ts +2 -1
  15. package/src/contestedResources/getContestedResourceVoteState.js +69 -49
  16. package/src/contestedResources/index.d.ts +4 -1
  17. package/src/contestedResources/index.js +5 -2
  18. package/src/dataContracts/getDataContractByIdentifier.d.ts +2 -1
  19. package/src/dataContracts/getDataContractByIdentifier.js +15 -27
  20. package/src/dataContracts/index.d.ts +4 -1
  21. package/src/dataContracts/index.js +5 -2
  22. package/src/documents/getActionFeeAgreement.d.ts +2 -1
  23. package/src/documents/getActionFeeAgreement.js +3 -3
  24. package/src/documents/index.d.ts +12 -8
  25. package/src/documents/index.js +16 -13
  26. package/src/documents/query.d.ts +2 -1
  27. package/src/documents/query.js +16 -8
  28. package/src/documents/queryAggregate.d.ts +8 -1
  29. package/src/documents/queryAggregate.js +49 -15
  30. package/src/documents/queryJoined.d.ts +3 -2
  31. package/src/documents/queryJoined.js +54 -13
  32. package/src/documents/queryRanked.d.ts +3 -2
  33. package/src/documents/queryRanked.js +49 -15
  34. package/src/documents/v1.d.ts +25 -8
  35. package/src/documents/v1.js +50 -14
  36. package/src/grpcConnectionPool.d.ts +24 -4
  37. package/src/grpcConnectionPool.js +153 -37
  38. package/src/identities/getIdentityBalance.d.ts +2 -1
  39. package/src/identities/getIdentityBalance.js +13 -27
  40. package/src/identities/getIdentityByIdentifier.d.ts +2 -1
  41. package/src/identities/getIdentityByIdentifier.js +14 -28
  42. package/src/identities/getIdentityByNonUniquePublicKeyHash.d.ts +2 -1
  43. package/src/identities/getIdentityByNonUniquePublicKeyHash.js +49 -28
  44. package/src/identities/getIdentityByPublicKeyHash.d.ts +2 -1
  45. package/src/identities/getIdentityByPublicKeyHash.js +14 -28
  46. package/src/identities/getIdentityContractNonce.d.ts +2 -1
  47. package/src/identities/getIdentityContractNonce.js +10 -27
  48. package/src/identities/getIdentityNonce.d.ts +2 -1
  49. package/src/identities/getIdentityNonce.js +10 -27
  50. package/src/identities/getIdentityPublicKeys.d.ts +2 -1
  51. package/src/identities/getIdentityPublicKeys.js +16 -29
  52. package/src/identities/index.d.ts +4 -1
  53. package/src/identities/index.js +11 -8
  54. package/src/names/index.d.ts +4 -1
  55. package/src/names/index.js +8 -5
  56. package/src/names/registerName.d.ts +2 -1
  57. package/src/names/registerName.js +4 -4
  58. package/src/names/searchByIdentity.d.ts +2 -1
  59. package/src/names/searchByIdentity.js +2 -2
  60. package/src/names/searchByName.d.ts +2 -1
  61. package/src/names/searchByName.js +2 -2
  62. package/src/node/epochInfos.d.ts +2 -1
  63. package/src/node/epochInfos.js +27 -31
  64. package/src/node/finalizedEpochInfos.d.ts +4 -3
  65. package/src/node/finalizedEpochInfos.js +45 -39
  66. package/src/node/index.d.ts +4 -1
  67. package/src/node/index.js +7 -4
  68. package/src/node/totalCredits.d.ts +2 -1
  69. package/src/node/totalCredits.js +10 -25
  70. package/src/platformAddresses/getAddressInfo.d.ts +2 -1
  71. package/src/platformAddresses/getAddressInfo.js +17 -31
  72. package/src/platformAddresses/getAddressesBranchState.d.ts +2 -1
  73. package/src/platformAddresses/getAddressesBranchState.js +22 -8
  74. package/src/platformAddresses/getAddressesInfos.d.ts +2 -1
  75. package/src/platformAddresses/getAddressesInfos.js +18 -29
  76. package/src/platformAddresses/getAddressesTrunkState.d.ts +2 -1
  77. package/src/platformAddresses/getAddressesTrunkState.js +25 -23
  78. package/src/platformAddresses/getRecentAddressBalanceChanges.d.ts +2 -1
  79. package/src/platformAddresses/getRecentAddressBalanceChanges.js +26 -26
  80. package/src/platformAddresses/getRecentCompactedAddressBalanceChanges.d.ts +2 -1
  81. package/src/platformAddresses/getRecentCompactedAddressBalanceChanges.js +30 -26
  82. package/src/platformAddresses/index.d.ts +4 -1
  83. package/src/platformAddresses/index.js +10 -7
  84. package/src/quorumKeyProvider.d.ts +23 -0
  85. package/src/quorumKeyProvider.js +28 -0
  86. package/src/shielded/getMostRecentShieldedAnchor.d.ts +2 -1
  87. package/src/shielded/getMostRecentShieldedAnchor.js +8 -25
  88. package/src/shielded/getShieldedAnchors.d.ts +2 -1
  89. package/src/shielded/getShieldedAnchors.js +8 -25
  90. package/src/shielded/getShieldedEncryptedNotes.d.ts +2 -1
  91. package/src/shielded/getShieldedEncryptedNotes.js +16 -30
  92. package/src/shielded/getShieldedNotesCount.d.ts +2 -1
  93. package/src/shielded/getShieldedNotesCount.js +8 -25
  94. package/src/shielded/getShieldedNullifiers.d.ts +2 -1
  95. package/src/shielded/getShieldedNullifiers.js +14 -28
  96. package/src/shielded/getShieldedPoolState.d.ts +2 -1
  97. package/src/shielded/getShieldedPoolState.js +8 -25
  98. package/src/shielded/index.d.ts +4 -1
  99. package/src/shielded/index.js +10 -7
  100. package/src/stateTransitions/index.d.ts +4 -1
  101. package/src/stateTransitions/index.js +5 -2
  102. package/src/stateTransitions/waitForStateTransitionResult.d.ts +2 -1
  103. package/src/stateTransitions/waitForStateTransitionResult.js +42 -44
  104. package/src/tokens/getIdentitiesTokenBalances.d.ts +2 -1
  105. package/src/tokens/getIdentitiesTokenBalances.js +17 -28
  106. package/src/tokens/getIdentityTokensBalances.d.ts +2 -1
  107. package/src/tokens/getIdentityTokensBalances.js +17 -28
  108. package/src/tokens/getTokenContractInfo.d.ts +2 -1
  109. package/src/tokens/getTokenContractInfo.js +16 -30
  110. package/src/tokens/getTokenDirectPurchasePrices.d.ts +2 -1
  111. package/src/tokens/getTokenDirectPurchasePrices.js +26 -28
  112. package/src/tokens/getTokenTotalSupply.d.ts +2 -1
  113. package/src/tokens/getTokenTotalSupply.js +16 -28
  114. package/src/tokens/index.d.ts +4 -1
  115. package/src/tokens/index.js +11 -8
  116. package/src/utils/ProofError.d.ts +9 -0
  117. package/src/utils/ProofError.js +10 -0
  118. package/src/utils/verifyTenderdashProof.js +2 -1
  119. package/test/unit/SDK.spec.js +42 -0
  120. package/src/utils/getQuorumPublicKey.d.ts +0 -1
  121. package/src/utils/getQuorumPublicKey.js +0 -19
@@ -14,8 +14,11 @@ import getTokenDirectPurchasePrices from './getTokenDirectPurchasePrices.js';
14
14
  export class TokensController {
15
15
  /** @ignore **/
16
16
  grpcPool;
17
- constructor(grpcPool) {
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 Error('Request is stalled (over 15 minutes)');
9
+ throw new ProofError('Request is stalled (over 15 minutes)');
9
10
  }
10
11
  const stateId = StateId.create({
11
12
  appVersion: String(metadata.protocolVersion),
@@ -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
- }