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
@@ -1,10 +1,8 @@
1
1
  import { GetIdentityRequest } from '../../proto/generated/platform.js';
2
- import { IdentifierWASM, verifyIdentityByIdentifierProof } from 'pshenmic-dpp';
3
- import { getQuorumPublicKey } from '../utils/getQuorumPublicKey.js';
4
- import bytesToHex from '../utils/bytesToHex.js';
5
- import verifyTenderdashProof from '../utils/verifyTenderdashProof.js';
2
+ import { IdentifierWASM, IdentityWASM, verifyIdentityByIdentifierProof } from 'pshenmic-dpp';
3
+ import QueryExecutor from '../QueryExecutor.js';
6
4
  import { LATEST_PLATFORM_VERSION } from '../constants.js';
7
- export default async function getIdentityByIdentifier(grpcPool, identifier) {
5
+ export default async function getIdentityByIdentifier(grpcPool, quorumKeyProvider, identifier) {
8
6
  const id = new IdentifierWASM(identifier);
9
7
  const getIdentityRequest = GetIdentityRequest.create({
10
8
  version: {
@@ -15,27 +13,15 @@ export default async function getIdentityByIdentifier(grpcPool, identifier) {
15
13
  }
16
14
  }
17
15
  });
18
- const { response } = await (await grpcPool.getClient()).getIdentity(getIdentityRequest);
19
- const { version } = response;
20
- if (version.oneofKind !== 'v0') {
21
- throw new Error('Unexpected oneOf type returned from DAPI (must be v0)');
22
- }
23
- const { v0 } = version;
24
- if (v0.result.oneofKind !== 'proof') {
25
- throw new Error('Unexpected oneOf type returned from DAPI (must be proof)');
26
- }
27
- const { result: { proof }, metadata } = v0;
28
- if (metadata == null) {
29
- throw new Error('Metadata not found');
30
- }
31
- const { rootHash, identity } = verifyIdentityByIdentifierProof(proof.grovedbProof, id, true, LATEST_PLATFORM_VERSION);
32
- if (identity == null) {
33
- throw new Error(`Identity with identifier ${id.base58()} 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 identity;
16
+ return await QueryExecutor.build(grpcPool, quorumKeyProvider)
17
+ .setGrpcRequest('getIdentity', getIdentityRequest)
18
+ .setProofVerifier(verifyIdentityByIdentifierProof, id, true, LATEST_PLATFORM_VERSION)
19
+ .mapResponse(data => {
20
+ const identity = data.proved ? data.verified.identity : IdentityWASM.fromBytes(data.result.identity);
21
+ if (identity == null) {
22
+ throw new Error(`Identity with identifier ${id.base58()} not found`);
23
+ }
24
+ return identity;
25
+ })
26
+ .execute();
41
27
  }
@@ -1,3 +1,4 @@
1
1
  import { IdentityWASM } from 'pshenmic-dpp';
2
2
  import { GRPCPool } from '../grpcConnectionPool.js';
3
- export default function getIdentityByNonUniquePublicKeyHash(grpcPool: GRPCPool, hex: string): Promise<IdentityWASM>;
3
+ import { QuorumKeyProvider } from '../quorumKeyProvider.js';
4
+ export default function getIdentityByNonUniquePublicKeyHash(grpcPool: GRPCPool, quorumKeyProvider: QuorumKeyProvider, hex: string): Promise<IdentityWASM>;
@@ -1,13 +1,34 @@
1
1
  import { GetIdentityByNonUniquePublicKeyHashRequest } from '../../proto/generated/platform.js';
2
- import { verifyFullIdentityByNonUniquePublicKeyHashProof } from 'pshenmic-dpp';
2
+ import { IdentityWASM, verifyFullIdentityByNonUniquePublicKeyHashProof, verifyFullIdentityByNonUniquePublicKeyHashTwoProofs } from 'pshenmic-dpp';
3
3
  import hexToBytes from '../utils/hexToBytes.js';
4
- import { getQuorumPublicKey } from '../utils/getQuorumPublicKey.js';
5
- import bytesToHex from '../utils/bytesToHex.js';
6
- import verifyTenderdashProof from '../utils/verifyTenderdashProof.js';
4
+ import QueryExecutor from '../QueryExecutor.js';
7
5
  import { LATEST_PLATFORM_VERSION } from '../constants.js';
8
- export default async function getIdentityByNonUniquePublicKeyHash(grpcPool, hex) {
6
+ function getNonUniquePublicKeyHashProof({ version }) {
7
+ if (version.oneofKind !== 'v0') {
8
+ throw new Error('Unexpected oneOf type returned from DAPI (must be v0)');
9
+ }
10
+ const { result, metadata } = version.v0;
11
+ if (metadata == null) {
12
+ throw new Error('Metadata not found');
13
+ }
14
+ if (result.oneofKind === 'legacyProof') {
15
+ return { proof: result.legacyProof, metadata, twoProofs: false };
16
+ }
17
+ if (result.oneofKind !== 'proof' || result.proof.grovedbIdentityPublicKeyHashProof == null) {
18
+ throw new Error('Unexpected oneOf type returned from DAPI (must be proof)');
19
+ }
20
+ // the quorum signature is carried by the index proof
21
+ return { proof: result.proof.grovedbIdentityPublicKeyHashProof, metadata, identityProof: result.proof.identityProofBytes, twoProofs: true };
22
+ }
23
+ function verifyNonUniquePublicKeyHashProof(proof, identityProof, twoProofs, publicKeyHash, queryPlatformVersion, platformVersion) {
24
+ return twoProofs
25
+ ? verifyFullIdentityByNonUniquePublicKeyHashTwoProofs(proof, identityProof, publicKeyHash, undefined, queryPlatformVersion, platformVersion)
26
+ : verifyFullIdentityByNonUniquePublicKeyHashProof(proof, publicKeyHash, undefined, queryPlatformVersion, platformVersion);
27
+ }
28
+ export default async function getIdentityByNonUniquePublicKeyHash(grpcPool, quorumKeyProvider, hex) {
9
29
  const getIdentityByNonUniquePublicKeyHashRequest = GetIdentityByNonUniquePublicKeyHashRequest.create({
10
30
  version: {
31
+ // v0 is supported by all nodes, v1 only since platform v5.0.0-rc.8
11
32
  oneofKind: 'v0',
12
33
  v0: {
13
34
  publicKeyHash: hexToBytes(hex),
@@ -15,27 +36,27 @@ export default async function getIdentityByNonUniquePublicKeyHash(grpcPool, hex)
15
36
  }
16
37
  }
17
38
  });
18
- const { response } = await (await grpcPool.getClient()).getIdentityByNonUniquePublicKeyHash(getIdentityByNonUniquePublicKeyHashRequest);
19
- const { version } = response;
20
- if (version.oneofKind !== 'v0') {
21
- throw new Error('Unexpected oneOf type returned from DAPI (must be v0)');
22
- }
23
- const { v0 } = version;
24
- if (v0.result.oneofKind !== 'proof') {
25
- throw new Error('Unexpected oneOf type returned from DAPI (must be proof)');
26
- }
27
- const { result: { proof }, metadata } = v0;
28
- if (metadata == null) {
29
- throw new Error('Metadata not found');
30
- }
31
- const { rootHash, identity } = verifyFullIdentityByNonUniquePublicKeyHashProof(proof.grovedbProof, hexToBytes(hex), undefined, metadata.protocolVersion, LATEST_PLATFORM_VERSION);
32
- if (identity == null) {
33
- throw new Error(`Identity with non unique public key hash ${hex} 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 identity;
39
+ return await QueryExecutor.build(grpcPool, quorumKeyProvider)
40
+ .setGrpcRequest('getIdentityByNonUniquePublicKeyHash', getIdentityByNonUniquePublicKeyHashRequest)
41
+ .mapProof(getNonUniquePublicKeyHashProof)
42
+ .setProofVerifier(verifyNonUniquePublicKeyHashProof, ({ metadata, identityProof, twoProofs }) => [
43
+ identityProof,
44
+ twoProofs,
45
+ hexToBytes(hex),
46
+ metadata.protocolVersion,
47
+ LATEST_PLATFORM_VERSION
48
+ ])
49
+ .mapResponse(data => {
50
+ if (data.proved) {
51
+ if (data.verified.identity == null) {
52
+ throw new Error(`Identity with non unique public key hash ${hex} not found`);
53
+ }
54
+ return data.verified.identity;
55
+ }
56
+ if (data.result.oneofKind !== 'identity' || data.result.identity.identity == null) {
57
+ throw new Error(`Identity with non unique public key hash ${hex} not found`);
58
+ }
59
+ return IdentityWASM.fromBytes(data.result.identity.identity);
60
+ })
61
+ .execute();
41
62
  }
@@ -1,3 +1,4 @@
1
1
  import { IdentityWASM } from 'pshenmic-dpp';
2
2
  import { GRPCPool } from '../grpcConnectionPool.js';
3
- export default function getIdentityByPublicKeyHash(grpcPool: GRPCPool, hex: string): Promise<IdentityWASM>;
3
+ import { QuorumKeyProvider } from '../quorumKeyProvider.js';
4
+ export default function getIdentityByPublicKeyHash(grpcPool: GRPCPool, quorumKeyProvider: QuorumKeyProvider, hex: string): Promise<IdentityWASM>;
@@ -1,11 +1,9 @@
1
1
  import { GetIdentityByPublicKeyHashRequest } from '../../proto/generated/platform.js';
2
- import { verifyIdentityByUniqueKeyHashProof } from 'pshenmic-dpp';
2
+ import { IdentityWASM, verifyIdentityByUniqueKeyHashProof } from 'pshenmic-dpp';
3
3
  import hexToBytes from '../utils/hexToBytes.js';
4
- import { getQuorumPublicKey } from '../utils/getQuorumPublicKey.js';
5
- import bytesToHex from '../utils/bytesToHex.js';
6
- import verifyTenderdashProof from '../utils/verifyTenderdashProof.js';
4
+ import QueryExecutor from '../QueryExecutor.js';
7
5
  import { LATEST_PLATFORM_VERSION } from '../constants.js';
8
- export default async function getIdentityByPublicKeyHash(grpcPool, hex) {
6
+ export default async function getIdentityByPublicKeyHash(grpcPool, quorumKeyProvider, hex) {
9
7
  const getIdentityByPublicKeyHashRequest = GetIdentityByPublicKeyHashRequest.create({
10
8
  version: {
11
9
  oneofKind: 'v0',
@@ -15,27 +13,15 @@ export default async function getIdentityByPublicKeyHash(grpcPool, hex) {
15
13
  }
16
14
  }
17
15
  });
18
- const { response } = await (await grpcPool.getClient()).getIdentityByPublicKeyHash(getIdentityByPublicKeyHashRequest);
19
- const { version } = response;
20
- if (version.oneofKind !== 'v0') {
21
- throw new Error('Unexpected oneOf type returned from DAPI (must be v0)');
22
- }
23
- const { v0 } = version;
24
- if (v0.result.oneofKind !== 'proof') {
25
- throw new Error('Unexpected oneOf type returned from DAPI (must be proof)');
26
- }
27
- const { result: { proof }, metadata } = v0;
28
- if (metadata == null) {
29
- throw new Error('Metadata not found');
30
- }
31
- const { rootHash, identity } = verifyIdentityByUniqueKeyHashProof(proof.grovedbProof, hexToBytes(hex), LATEST_PLATFORM_VERSION);
32
- if (identity == null) {
33
- throw new Error(`Identity with public key hash ${hex} 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 identity;
16
+ return await QueryExecutor.build(grpcPool, quorumKeyProvider)
17
+ .setGrpcRequest('getIdentityByPublicKeyHash', getIdentityByPublicKeyHashRequest)
18
+ .setProofVerifier(verifyIdentityByUniqueKeyHashProof, hexToBytes(hex), LATEST_PLATFORM_VERSION)
19
+ .mapResponse(data => {
20
+ const identity = data.proved ? data.verified.identity : IdentityWASM.fromBytes(data.result.identity);
21
+ if (identity == null) {
22
+ throw new Error(`Identity with public key hash ${hex} not found`);
23
+ }
24
+ return identity;
25
+ })
26
+ .execute();
41
27
  }
@@ -1,3 +1,4 @@
1
1
  import { IdentifierLike } from 'pshenmic-dpp';
2
2
  import { GRPCPool } from '../grpcConnectionPool.js';
3
- export default function getIdentityContractNonce(grpcPool: GRPCPool, identity: IdentifierLike, dataContract: IdentifierLike): Promise<bigint>;
3
+ import { QuorumKeyProvider } from '../quorumKeyProvider.js';
4
+ export default function getIdentityContractNonce(grpcPool: GRPCPool, quorumKeyProvider: QuorumKeyProvider, identity: IdentifierLike, dataContract: IdentifierLike): Promise<bigint>;
@@ -1,11 +1,9 @@
1
1
  import { GetIdentityContractNonceRequest } from '../../proto/generated/platform.js';
2
2
  import { IdentifierWASM, verifyIdentityContractNonceProof } from 'pshenmic-dpp';
3
- import { getQuorumPublicKey } from '../utils/getQuorumPublicKey.js';
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
5
  const IDENTITY_CONTRACT_NONCE_VALUE_FILTER = BigInt(0xFFFFFFFFFF);
8
- export default async function getIdentityContractNonce(grpcPool, identity, dataContract) {
6
+ export default async function getIdentityContractNonce(grpcPool, quorumKeyProvider, identity, dataContract) {
9
7
  const identityIdentifier = new IdentifierWASM(identity);
10
8
  const dataContractIdentifier = new IdentifierWASM(dataContract);
11
9
  const getIdentityContractNonceRequest = GetIdentityContractNonceRequest.create({
@@ -18,27 +16,12 @@ export default async function getIdentityContractNonce(grpcPool, identity, dataC
18
16
  }
19
17
  }
20
18
  });
21
- const { response } = await (await grpcPool.getClient()).getIdentityContractNonce(getIdentityContractNonceRequest);
22
- const { version } = response;
23
- if (version.oneofKind !== 'v0') {
24
- throw new Error('Unexpected oneOf type returned from DAPI (must be v0)');
25
- }
26
- const { v0 } = version;
27
- if (v0.result.oneofKind !== 'proof') {
28
- throw new Error('Unexpected oneOf type returned from DAPI (must be proof)');
29
- }
30
- const { result: { proof }, metadata } = v0;
31
- if (metadata == null) {
32
- throw new Error('Metadata not found');
33
- }
34
- const { rootHash, contractNonce } = verifyIdentityContractNonceProof(proof.grovedbProof, identityIdentifier.bytes(), dataContractIdentifier.bytes(), true, LATEST_PLATFORM_VERSION);
35
- if (contractNonce == null) {
36
- return BigInt(0);
37
- }
38
- const quorumPublicKey = await getQuorumPublicKey(grpcPool.network, proof.quorumType, bytesToHex(proof.quorumHash));
39
- const verify = await verifyTenderdashProof(proof, metadata, rootHash, quorumPublicKey);
40
- if (!verify) {
41
- throw new Error('Failed to verify query');
42
- }
43
- return BigInt(contractNonce) & IDENTITY_CONTRACT_NONCE_VALUE_FILTER;
19
+ return await QueryExecutor.build(grpcPool, quorumKeyProvider)
20
+ .setGrpcRequest('getIdentityContractNonce', getIdentityContractNonceRequest)
21
+ .setProofVerifier(verifyIdentityContractNonceProof, identityIdentifier.bytes(), dataContractIdentifier.bytes(), true, LATEST_PLATFORM_VERSION)
22
+ .mapResponse(data => {
23
+ const contractNonce = data.proved ? data.verified.contractNonce : BigInt(data.result.identityContractNonce);
24
+ return contractNonce != null ? contractNonce & IDENTITY_CONTRACT_NONCE_VALUE_FILTER : BigInt(0);
25
+ })
26
+ .execute();
44
27
  }
@@ -1,3 +1,4 @@
1
1
  import { IdentifierLike } from 'pshenmic-dpp';
2
2
  import { GRPCPool } from '../grpcConnectionPool.js';
3
- export default function getIdentityNonce(grpcPool: GRPCPool, identifier: IdentifierLike): Promise<bigint>;
3
+ import { QuorumKeyProvider } from '../quorumKeyProvider.js';
4
+ export default function getIdentityNonce(grpcPool: GRPCPool, quorumKeyProvider: QuorumKeyProvider, identifier: IdentifierLike): Promise<bigint>;
@@ -1,11 +1,9 @@
1
1
  import { GetIdentityNonceRequest } from '../../proto/generated/platform.js';
2
2
  import { IdentifierWASM, verifyIdentityNonceProof } from 'pshenmic-dpp';
3
- import { getQuorumPublicKey } from '../utils/getQuorumPublicKey.js';
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
5
  const IDENTITY_NONCE_VALUE_FILTER = BigInt(0xFFFFFFFFFF);
8
- export default async function getIdentityNonce(grpcPool, identifier) {
6
+ export default async function getIdentityNonce(grpcPool, quorumKeyProvider, identifier) {
9
7
  const id = new IdentifierWASM(identifier);
10
8
  const getIdentityNonceRequest = GetIdentityNonceRequest.create({
11
9
  version: {
@@ -16,27 +14,12 @@ export default async function getIdentityNonce(grpcPool, identifier) {
16
14
  }
17
15
  }
18
16
  });
19
- const { response } = await (await grpcPool.getClient()).getIdentityNonce(getIdentityNonceRequest);
20
- const { version } = response;
21
- if (version.oneofKind !== 'v0') {
22
- throw new Error('Unexpected oneOf type returned from DAPI (must be v0)');
23
- }
24
- const { v0 } = version;
25
- if (v0.result.oneofKind !== 'proof') {
26
- throw new Error('Unexpected oneOf type returned from DAPI (must be proof)');
27
- }
28
- const { result: { proof }, metadata } = v0;
29
- if (metadata == null) {
30
- throw new Error('Metadata not found');
31
- }
32
- const { rootHash, nonce } = verifyIdentityNonceProof(proof.grovedbProof, id.bytes(), true, LATEST_PLATFORM_VERSION);
33
- if (nonce == null) {
34
- return BigInt(0);
35
- }
36
- const quorumPublicKey = await getQuorumPublicKey(grpcPool.network, proof.quorumType, bytesToHex(proof.quorumHash));
37
- const verify = await verifyTenderdashProof(proof, metadata, rootHash, quorumPublicKey);
38
- if (!verify) {
39
- throw new Error('Failed to verify query');
40
- }
41
- return BigInt(nonce) & IDENTITY_NONCE_VALUE_FILTER;
17
+ return await QueryExecutor.build(grpcPool, quorumKeyProvider)
18
+ .setGrpcRequest('getIdentityNonce', getIdentityNonceRequest)
19
+ .setProofVerifier(verifyIdentityNonceProof, id.bytes(), true, LATEST_PLATFORM_VERSION)
20
+ .mapResponse(data => {
21
+ const nonce = data.proved ? data.verified.nonce : BigInt(data.result.identityNonce);
22
+ return nonce != null ? nonce & IDENTITY_NONCE_VALUE_FILTER : BigInt(0);
23
+ })
24
+ .execute();
42
25
  }
@@ -1,3 +1,4 @@
1
1
  import { IdentifierLike, IdentityPublicKeyWASM } from 'pshenmic-dpp';
2
2
  import { GRPCPool } from '../grpcConnectionPool.js';
3
- export default function getIdentityPublicKeys(grpcPool: GRPCPool, identifier: IdentifierLike, keyIds?: number[]): Promise<IdentityPublicKeyWASM[]>;
3
+ import { QuorumKeyProvider } from '../quorumKeyProvider.js';
4
+ export default function getIdentityPublicKeys(grpcPool: GRPCPool, quorumKeyProvider: QuorumKeyProvider, identifier: IdentifierLike, keyIds?: number[]): Promise<IdentityPublicKeyWASM[]>;
@@ -1,10 +1,8 @@
1
1
  import { GetIdentityKeysRequest, KeyRequestType } from '../../proto/generated/platform.js';
2
- import { IdentifierWASM, verifyIdentityKeysByIdentifierProof } from 'pshenmic-dpp';
3
- import { getQuorumPublicKey } from '../utils/getQuorumPublicKey.js';
4
- import bytesToHex from '../utils/bytesToHex.js';
5
- import verifyTenderdashProof from '../utils/verifyTenderdashProof.js';
2
+ import { IdentifierWASM, IdentityPublicKeyWASM, verifyIdentityKeysByIdentifierProof } from 'pshenmic-dpp';
3
+ import QueryExecutor from '../QueryExecutor.js';
6
4
  import { LATEST_PLATFORM_VERSION } from '../constants.js';
7
- export default async function getIdentityPublicKeys(grpcPool, identifier, keyIds) {
5
+ export default async function getIdentityPublicKeys(grpcPool, quorumKeyProvider, identifier, keyIds) {
8
6
  const id = new IdentifierWASM(identifier);
9
7
  let requestType = {
10
8
  request: {
@@ -30,28 +28,17 @@ export default async function getIdentityPublicKeys(grpcPool, identifier, keyIds
30
28
  }
31
29
  }
32
30
  });
33
- const { response } = await (await grpcPool.getClient()).getIdentityKeys(getIdentityKeysRequest);
34
- const { version } = response;
35
- if (version.oneofKind !== 'v0') {
36
- throw new Error('Unexpected oneOf type returned from DAPI (must be v0)');
37
- }
38
- const { v0 } = version;
39
- if (v0.result.oneofKind !== 'proof') {
40
- throw new Error('Unexpected oneOf type returned from DAPI (must be proof)');
41
- }
42
- const { result: { proof }, metadata } = v0;
43
- if (metadata == null) {
44
- throw new Error('Metadata not found');
45
- }
46
- const { rootHash, identity } = verifyIdentityKeysByIdentifierProof(proof.grovedbProof, id.bytes(), keyIds != null ? keyIds : null, false, false, true, null, null, LATEST_PLATFORM_VERSION);
47
- if (identity == null) {
48
- throw new Error(`Identity with identifier ${id.base58()} not found`);
49
- }
50
- const quorumPublicKey = await getQuorumPublicKey(grpcPool.network, proof.quorumType, bytesToHex(proof.quorumHash));
51
- const verify = await verifyTenderdashProof(proof, metadata, rootHash, quorumPublicKey);
52
- if (!verify) {
53
- throw new Error('Failed to verify query');
54
- }
55
- const loadedKeysIds = Object.keys(identity.loadedPublicKeys);
56
- return loadedKeysIds.map((id) => identity.loadedPublicKeys[id]);
31
+ return await QueryExecutor.build(grpcPool, quorumKeyProvider)
32
+ .setGrpcRequest('getIdentityKeys', getIdentityKeysRequest)
33
+ .setProofVerifier(verifyIdentityKeysByIdentifierProof, id.bytes(), keyIds ?? null, false, false, true, null, null, LATEST_PLATFORM_VERSION)
34
+ .mapResponse(data => {
35
+ const keys = data.proved
36
+ ? data.verified.identity?.loadedPublicKeys
37
+ : data.result.keys.keysBytes.map(bytes => IdentityPublicKeyWASM.fromBytes(bytes));
38
+ if (keys == null) {
39
+ throw new Error(`Identity with identifier ${id.base58()} not found`);
40
+ }
41
+ return Object.values(keys);
42
+ })
43
+ .execute();
57
44
  }
@@ -1,5 +1,6 @@
1
1
  import { IdentityTransitionParams } from '../../types.js';
2
2
  import { GRPCPool } from '../grpcConnectionPool.js';
3
+ import { QuorumKeyProvider } from '../quorumKeyProvider.js';
3
4
  import { IdentifierLike, IdentityPublicKeyWASM, IdentityWASM, StateTransitionWASM } from 'pshenmic-dpp';
4
5
  /**
5
6
  * Collection of methods to query identities and its related data
@@ -9,7 +10,9 @@ import { IdentifierLike, IdentityPublicKeyWASM, IdentityWASM, StateTransitionWAS
9
10
  export declare class IdentitiesController {
10
11
  /** @ignore */
11
12
  grpcPool: GRPCPool;
12
- constructor(grpcPool: GRPCPool);
13
+ /** @ignore */
14
+ quorumKeyProvider: QuorumKeyProvider;
15
+ constructor(grpcPool: GRPCPool, quorumKeyProvider: QuorumKeyProvider);
13
16
  /**
14
17
  * Get current balance of your Identity by identifier
15
18
  *
@@ -17,8 +17,11 @@ import { base58 } from '@scure/base';
17
17
  export class IdentitiesController {
18
18
  /** @ignore */
19
19
  grpcPool;
20
- constructor(grpcPool) {
20
+ /** @ignore */
21
+ quorumKeyProvider;
22
+ constructor(grpcPool, quorumKeyProvider) {
21
23
  this.grpcPool = grpcPool;
24
+ this.quorumKeyProvider = quorumKeyProvider;
22
25
  }
23
26
  /**
24
27
  * Get current balance of your Identity by identifier
@@ -28,7 +31,7 @@ export class IdentitiesController {
28
31
  * @return {Promise<bigint>}
29
32
  */
30
33
  async getIdentityBalance(identifier) {
31
- return await getIdentityBalance(this.grpcPool, identifier);
34
+ return await getIdentityBalance(this.grpcPool, this.quorumKeyProvider, identifier);
32
35
  }
33
36
  /**
34
37
  * Retrieves an Identity from the network by give public key hash
@@ -41,7 +44,7 @@ export class IdentitiesController {
41
44
  if (hex.length !== 40) {
42
45
  throw new Error('Public key hash should equal 40');
43
46
  }
44
- return await getIdentityByPublicKeyHash(this.grpcPool, hex);
47
+ return await getIdentityByPublicKeyHash(this.grpcPool, this.quorumKeyProvider, hex);
45
48
  }
46
49
  /**
47
50
  * Retrieves an Identity from the network by non-unique public key hash (like Voter Identity, SHA160)
@@ -54,7 +57,7 @@ export class IdentitiesController {
54
57
  if (hex.length !== 40) {
55
58
  throw new Error('Public key hash should equal 40');
56
59
  }
57
- return await getIdentityByNonUniquePublicKeyHash(this.grpcPool, hex);
60
+ return await getIdentityByNonUniquePublicKeyHash(this.grpcPool, this.quorumKeyProvider, hex);
58
61
  }
59
62
  /**
60
63
  * Retrieves Identity by identifier from the network
@@ -63,14 +66,14 @@ export class IdentitiesController {
63
66
  * @return {Promise<IdentityWASM>}
64
67
  */
65
68
  async getIdentityByIdentifier(identifier) {
66
- return await getIdentityByIdentifier(this.grpcPool, identifier);
69
+ return await getIdentityByIdentifier(this.grpcPool, this.quorumKeyProvider, identifier);
67
70
  }
68
71
  /**
69
72
  * Get Identity Nonce (usually used by Identity transitions)
70
73
  * @param identifier
71
74
  */
72
75
  async getIdentityNonce(identifier) {
73
- return await getIdentityNonce(this.grpcPool, identifier);
76
+ return await getIdentityNonce(this.grpcPool, this.quorumKeyProvider, identifier);
74
77
  }
75
78
  /**
76
79
  * Get Identity Contract Nonce (usually used by Document transitions)
@@ -80,7 +83,7 @@ export class IdentitiesController {
80
83
  * @return {Promise<bigint>}
81
84
  */
82
85
  async getIdentityContractNonce(identifier, dataContract) {
83
- return await getIdentityContractNonce(this.grpcPool, identifier, dataContract);
86
+ return await getIdentityContractNonce(this.grpcPool, this.quorumKeyProvider, identifier, dataContract);
84
87
  }
85
88
  /**
86
89
  * Retrieve given Identity's public keys
@@ -90,7 +93,7 @@ export class IdentitiesController {
90
93
  * @return {Promise<IdentityPublicKeyWASM[]>}
91
94
  */
92
95
  async getIdentityPublicKeys(identifier, keyIds) {
93
- return await getIdentityPublicKeys(this.grpcPool, identifier, keyIds);
96
+ return await getIdentityPublicKeys(this.grpcPool, this.quorumKeyProvider, identifier, keyIds);
94
97
  }
95
98
  /**
96
99
  * Helper function for creating {StateTransitionWASM} for Identity transitions
@@ -1,4 +1,5 @@
1
1
  import { GRPCPool } from '../grpcConnectionPool.js';
2
+ import { QuorumKeyProvider } from '../quorumKeyProvider.js';
2
3
  import { DocumentWASM, IdentifierLike, PrivateKeyWASM } from 'pshenmic-dpp';
3
4
  /**
4
5
  * Functions related to DPNS names (usernames)
@@ -8,7 +9,9 @@ import { DocumentWASM, IdentifierLike, PrivateKeyWASM } from 'pshenmic-dpp';
8
9
  export declare class NamesController {
9
10
  /** @ignore **/
10
11
  grpcPool: GRPCPool;
11
- constructor(grpcPool: GRPCPool);
12
+ /** @ignore **/
13
+ quorumKeyProvider: QuorumKeyProvider;
14
+ constructor(grpcPool: GRPCPool, quorumKeyProvider: QuorumKeyProvider);
12
15
  /**
13
16
  * Searches for a registered DPNS name in the network
14
17
  *
@@ -14,8 +14,11 @@ import testNameContested from './testNameContested.js';
14
14
  export class NamesController {
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
  * Searches for a registered DPNS name in the network
@@ -36,7 +39,7 @@ export class NamesController {
36
39
  if (validation != null) {
37
40
  throw new Error(validation);
38
41
  }
39
- return await searchByName(this.grpcPool, name);
42
+ return await searchByName(this.grpcPool, this.quorumKeyProvider, name);
40
43
  }
41
44
  /**
42
45
  * Tests a given username against contested names rules.
@@ -57,7 +60,7 @@ export class NamesController {
57
60
  return testNameContested(normalizedLabel);
58
61
  }
59
62
  async searchByIdentity(identifier) {
60
- return await searchByIdentity(this.grpcPool, new IdentifierWASM(identifier));
63
+ return await searchByIdentity(this.grpcPool, this.quorumKeyProvider, new IdentifierWASM(identifier));
61
64
  }
62
65
  /**
63
66
  * Performs a DPNS name registration sequence
@@ -76,8 +79,8 @@ export class NamesController {
76
79
  if (validation != null) {
77
80
  throw new Error(validation);
78
81
  }
79
- const identity = await getIdentityByIdentifier(this.grpcPool, identityId);
80
- return await registerName(this.grpcPool, name, identity, privateKey, preorderSalt);
82
+ const identity = await getIdentityByIdentifier(this.grpcPool, this.quorumKeyProvider, identityId);
83
+ return await registerName(this.grpcPool, this.quorumKeyProvider, name, identity, privateKey, preorderSalt);
81
84
  }
82
85
  /**
83
86
  * Converts DPNS name to normalized format (ex. alice.dash -> al1ce.dash)
@@ -1,3 +1,4 @@
1
1
  import { IdentityWASM, PrivateKeyWASM } from 'pshenmic-dpp';
2
2
  import { GRPCPool } from '../grpcConnectionPool.js';
3
- export default function registerName(grpcPool: GRPCPool, name: string, identity: IdentityWASM, privateKey: PrivateKeyWASM, preorderSalt?: Uint8Array): Promise<Uint8Array>;
3
+ import { QuorumKeyProvider } from '../quorumKeyProvider.js';
4
+ export default function registerName(grpcPool: GRPCPool, quorumKeyProvider: QuorumKeyProvider, name: string, identity: IdentityWASM, privateKey: PrivateKeyWASM, preorderSalt?: Uint8Array): Promise<Uint8Array>;
@@ -9,7 +9,7 @@ import broadcast from '../stateTransitions/broadcast.js';
9
9
  import waitForStateTransitionResult from '../stateTransitions/waitForStateTransitionResult.js';
10
10
  import testNameContested from './testNameContested.js';
11
11
  import { DPNS_DATA_CONTRACT_ID } from '../constants.js';
12
- export default async function registerName(grpcPool, name, identity, privateKey, preorderSalt) {
12
+ export default async function registerName(grpcPool, quorumKeyProvider, name, identity, privateKey, preorderSalt) {
13
13
  const [identityPublicKey] = identity.getPublicKeys().filter(identityPublicKey => identityPublicKey.getPublicKeyHash() === privateKey.getPublicKeyHash());
14
14
  if (identityPublicKey == null) {
15
15
  throw new Error('Private key does not match the identity');
@@ -29,7 +29,7 @@ export default async function registerName(grpcPool, name, identity, privateKey,
29
29
  ...salt,
30
30
  ...new TextEncoder().encode(normalizedFullDomainName)
31
31
  ])));
32
- const identityContractNonce = await getIdentityContractNonce(grpcPool, identity.id, DPNS_DATA_CONTRACT_ID);
32
+ const identityContractNonce = await getIdentityContractNonce(grpcPool, quorumKeyProvider, identity.id, DPNS_DATA_CONTRACT_ID);
33
33
  // skip preorder if salt of existing preorder is provided
34
34
  const domainNonce = identityContractNonce + BigInt(preorderSalt == null ? 2 : 1);
35
35
  // salt is exposed in the error only once preorder exists (passed in or its broadcast accepted),
@@ -47,7 +47,7 @@ export default async function registerName(grpcPool, name, identity, privateKey,
47
47
  await broadcast(grpcPool, preorderStateTransition);
48
48
  preorderSent = true;
49
49
  // wait for state transition confirmation before next broadcast
50
- await waitForStateTransitionResult(grpcPool, preorderStateTransition);
50
+ await waitForStateTransitionResult(grpcPool, quorumKeyProvider, preorderStateTransition);
51
51
  }
52
52
  // 2. Create domain document
53
53
  const domainData = {
@@ -72,7 +72,7 @@ export default async function registerName(grpcPool, name, identity, privateKey,
72
72
  await domainStateTransition.sign(privateKey, identityPublicKey);
73
73
  await broadcast(grpcPool, domainStateTransition);
74
74
  // wait for the domain too, so the next transition reads a nonce past it
75
- await waitForStateTransitionResult(grpcPool, domainStateTransition);
75
+ await waitForStateTransitionResult(grpcPool, quorumKeyProvider, domainStateTransition);
76
76
  }
77
77
  catch (e) {
78
78
  if (preorderSent && e instanceof Error) {
@@ -1,3 +1,4 @@
1
1
  import { DocumentWASM, IdentifierWASM } from 'pshenmic-dpp';
2
2
  import { GRPCPool } from '../grpcConnectionPool.js';
3
- export default function searchByIdentity(grpcPool: GRPCPool, identifier: IdentifierWASM): Promise<DocumentWASM[]>;
3
+ import { QuorumKeyProvider } from '../quorumKeyProvider.js';
4
+ export default function searchByIdentity(grpcPool: GRPCPool, quorumKeyProvider: QuorumKeyProvider, identifier: IdentifierWASM): Promise<DocumentWASM[]>;
@@ -1,5 +1,5 @@
1
1
  import query from '../documents/query.js';
2
2
  const DPNS_DATA_CONTRACT_ID = 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec';
3
- export default async function searchByIdentity(grpcPool, identifier) {
4
- return await query(grpcPool, DPNS_DATA_CONTRACT_ID, 'domain', [['records.identity', '=', identifier.base58()]], [['records.identity', 'asc']]);
3
+ export default async function searchByIdentity(grpcPool, quorumKeyProvider, identifier) {
4
+ return await query(grpcPool, quorumKeyProvider, DPNS_DATA_CONTRACT_ID, 'domain', [['records.identity', '=', identifier.base58()]], [['records.identity', 'asc']]);
5
5
  }
@@ -1,3 +1,4 @@
1
1
  import { DocumentWASM } from 'pshenmic-dpp';
2
2
  import { GRPCPool } from '../grpcConnectionPool.js';
3
- export default function search(grpcPool: GRPCPool, name: string): Promise<DocumentWASM[]>;
3
+ import { QuorumKeyProvider } from '../quorumKeyProvider.js';
4
+ export default function search(grpcPool: GRPCPool, quorumKeyProvider: QuorumKeyProvider, name: string): Promise<DocumentWASM[]>;