dash-platform-sdk 1.6.0-dev.1 → 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.
- 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.d.ts +128 -2
- package/proto/generated/platform.js +266 -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/index.d.ts +4 -1
- package/src/contestedResources/index.js +5 -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/create.d.ts +1 -1
- package/src/documents/create.js +2 -2
- package/src/documents/getActionFeeAgreement.d.ts +2 -1
- package/src/documents/getActionFeeAgreement.js +3 -3
- package/src/documents/index.d.ts +14 -9
- package/src/documents/index.js +19 -15
- 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 +24 -4
- package/src/grpcConnectionPool.js +153 -37
- 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 +8 -2
- package/src/names/index.js +12 -6
- package/src/names/registerName.d.ts +2 -1
- package/src/names/registerName.js +56 -36
- 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/Document.spec.js +9 -9
- package/test/unit/DocumentActionFees.spec.js +2 -2
- package/test/unit/Names.spec.js +30 -0
- package/test/unit/Node.spec.js +11 -8
- 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 { GetShieldedNotesCountRequest } from '../../proto/generated/platform.js';
|
|
2
2
|
import { IdentifierWASM, verifyShieldedNotesCountProof } from 'pshenmic-dpp';
|
|
3
|
-
import { LATEST_PLATFORM_VERSION } from
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
import verifyTenderdashProof from "../utils/verifyTenderdashProof.js";
|
|
7
|
-
export default async function getShieldedNotesCount(grpcPool, tokenIdentifier) {
|
|
3
|
+
import { LATEST_PLATFORM_VERSION } from '../constants.js';
|
|
4
|
+
import QueryExecutor from '../QueryExecutor.js';
|
|
5
|
+
export default async function getShieldedNotesCount(grpcPool, quorumKeyProvider, tokenIdentifier) {
|
|
8
6
|
const tokenId = tokenIdentifier != null ? new IdentifierWASM(tokenIdentifier) : undefined;
|
|
9
7
|
const getShieldedNotesCountRequest = GetShieldedNotesCountRequest.create({
|
|
10
8
|
version: {
|
|
@@ -15,24 +13,9 @@ export default async function getShieldedNotesCount(grpcPool, tokenIdentifier) {
|
|
|
15
13
|
}
|
|
16
14
|
}
|
|
17
15
|
});
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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, count } = verifyShieldedNotesCountProof(proof.grovedbProof, true, LATEST_PLATFORM_VERSION, tokenId);
|
|
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 count;
|
|
16
|
+
return await QueryExecutor.build(grpcPool, quorumKeyProvider)
|
|
17
|
+
.setGrpcRequest('getShieldedNotesCount', getShieldedNotesCountRequest)
|
|
18
|
+
.setProofVerifier(verifyShieldedNotesCountProof, true, LATEST_PLATFORM_VERSION, tokenId)
|
|
19
|
+
.mapResponse(data => data.proved ? data.verified.count : BigInt(data.result.totalNotesCount))
|
|
20
|
+
.execute();
|
|
38
21
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { GRPCPool } from '../grpcConnectionPool.js';
|
|
2
|
+
import { QuorumKeyProvider } from '../quorumKeyProvider.js';
|
|
2
3
|
import { ShieldedNullifierStatus } from '../../types.js';
|
|
3
4
|
import { IdentifierLike } from 'pshenmic-dpp';
|
|
4
|
-
export default function getShieldedNullifiers(grpcPool: GRPCPool, nullifiers: Uint8Array[], tokenIdentifier?: IdentifierLike): Promise<ShieldedNullifierStatus[]>;
|
|
5
|
+
export default function getShieldedNullifiers(grpcPool: GRPCPool, quorumKeyProvider: QuorumKeyProvider, nullifiers: Uint8Array[], tokenIdentifier?: IdentifierLike): Promise<ShieldedNullifierStatus[]>;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { GetShieldedNullifiersRequest } from '../../proto/generated/platform.js';
|
|
2
2
|
import { IdentifierWASM, verifyShieldedNullifiersProof } from 'pshenmic-dpp';
|
|
3
|
-
import { LATEST_PLATFORM_VERSION } from
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
import verifyTenderdashProof from "../utils/verifyTenderdashProof.js";
|
|
7
|
-
export default async function getShieldedNullifiers(grpcPool, nullifiers, tokenIdentifier) {
|
|
3
|
+
import { LATEST_PLATFORM_VERSION } from '../constants.js';
|
|
4
|
+
import QueryExecutor from '../QueryExecutor.js';
|
|
5
|
+
export default async function getShieldedNullifiers(grpcPool, quorumKeyProvider, nullifiers, tokenIdentifier) {
|
|
8
6
|
const tokenId = tokenIdentifier != null ? new IdentifierWASM(tokenIdentifier) : undefined;
|
|
9
7
|
const getShieldedNullifiersRequest = GetShieldedNullifiersRequest.create({
|
|
10
8
|
version: {
|
|
@@ -16,27 +14,15 @@ export default async function getShieldedNullifiers(grpcPool, nullifiers, tokenI
|
|
|
16
14
|
}
|
|
17
15
|
}
|
|
18
16
|
});
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
throw new Error('Metadata not found');
|
|
31
|
-
}
|
|
32
|
-
const { rootHash, nullifiers: nullifiersStatuses } = verifyShieldedNullifiersProof(proof.grovedbProof, nullifiers, true, LATEST_PLATFORM_VERSION, tokenId);
|
|
33
|
-
const quorumPublicKey = await getQuorumPublicKey(grpcPool.network, proof.quorumType, bytesToHex(proof.quorumHash));
|
|
34
|
-
const verify = await verifyTenderdashProof(proof, metadata, rootHash, quorumPublicKey);
|
|
35
|
-
if (!verify) {
|
|
36
|
-
throw new Error('Failed to verify query');
|
|
37
|
-
}
|
|
38
|
-
return nullifiersStatuses.map(entry => ({
|
|
39
|
-
nullifier: entry.nullifier,
|
|
40
|
-
isSpent: entry.isSpent
|
|
41
|
-
}));
|
|
17
|
+
return await QueryExecutor.build(grpcPool, quorumKeyProvider)
|
|
18
|
+
.setGrpcRequest('getShieldedNullifiers', getShieldedNullifiersRequest)
|
|
19
|
+
.setProofVerifier(verifyShieldedNullifiersProof, nullifiers, true, LATEST_PLATFORM_VERSION, tokenId)
|
|
20
|
+
.mapResponse(data => {
|
|
21
|
+
const nullifiersStatuses = data.proved ? data.verified.nullifiers : data.result.nullifierStatuses.entries;
|
|
22
|
+
return nullifiersStatuses.map(entry => ({
|
|
23
|
+
nullifier: entry.nullifier,
|
|
24
|
+
isSpent: entry.isSpent
|
|
25
|
+
}));
|
|
26
|
+
})
|
|
27
|
+
.execute();
|
|
42
28
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { GRPCPool } from '../grpcConnectionPool.js';
|
|
2
|
+
import { QuorumKeyProvider } from '../quorumKeyProvider.js';
|
|
2
3
|
import { IdentifierLike } from 'pshenmic-dpp';
|
|
3
|
-
export default function getShieldedPoolState(grpcPool: GRPCPool, tokenIdentifier?: IdentifierLike): Promise<bigint | undefined>;
|
|
4
|
+
export default function getShieldedPoolState(grpcPool: GRPCPool, quorumKeyProvider: QuorumKeyProvider, tokenIdentifier?: IdentifierLike): Promise<bigint | undefined>;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { GetShieldedPoolStateRequest } from '../../proto/generated/platform.js';
|
|
2
|
-
import
|
|
3
|
-
import bytesToHex from "../utils/bytesToHex.js";
|
|
4
|
-
import verifyTenderdashProof from "../utils/verifyTenderdashProof.js";
|
|
2
|
+
import QueryExecutor from '../QueryExecutor.js';
|
|
5
3
|
import { IdentifierWASM, verifyShieldedPoolStateProof } from 'pshenmic-dpp';
|
|
6
|
-
import { LATEST_PLATFORM_VERSION } from
|
|
7
|
-
export default async function getShieldedPoolState(grpcPool, tokenIdentifier) {
|
|
4
|
+
import { LATEST_PLATFORM_VERSION } from '../constants.js';
|
|
5
|
+
export default async function getShieldedPoolState(grpcPool, quorumKeyProvider, tokenIdentifier) {
|
|
8
6
|
const tokenId = tokenIdentifier != null ? new IdentifierWASM(tokenIdentifier) : undefined;
|
|
9
7
|
const getShieldedPoolStateRequest = GetShieldedPoolStateRequest.create({
|
|
10
8
|
version: {
|
|
@@ -15,24 +13,9 @@ export default async function getShieldedPoolState(grpcPool, tokenIdentifier) {
|
|
|
15
13
|
}
|
|
16
14
|
}
|
|
17
15
|
});
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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, totalBalance } = verifyShieldedPoolStateProof(proof.grovedbProof, true, LATEST_PLATFORM_VERSION, tokenId);
|
|
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 totalBalance;
|
|
16
|
+
return await QueryExecutor.build(grpcPool, quorumKeyProvider)
|
|
17
|
+
.setGrpcRequest('getShieldedPoolState', getShieldedPoolStateRequest)
|
|
18
|
+
.setProofVerifier(verifyShieldedPoolStateProof, true, LATEST_PLATFORM_VERSION, tokenId)
|
|
19
|
+
.mapResponse(data => data.proved ? data.verified.totalBalance : BigInt(data.result.totalBalance))
|
|
20
|
+
.execute();
|
|
38
21
|
}
|
package/src/shielded/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { GRPCPool } from '../grpcConnectionPool.js';
|
|
2
|
+
import { QuorumKeyProvider } from '../quorumKeyProvider.js';
|
|
2
3
|
import { ShieldedEncryptedNote, ShieldedNullifierStatus, ShieldedTransitionParamsMap, ShieldedTransitionType } from '../../types.js';
|
|
3
4
|
import { IdentifierLike, RecoveredNoteWASM, ShieldedBuilderWASM, SpendableNoteWASM, StateTransitionWASM } from 'pshenmic-dpp';
|
|
4
5
|
/**
|
|
@@ -10,8 +11,10 @@ export declare class ShieldedController {
|
|
|
10
11
|
/** @ignore **/
|
|
11
12
|
grpcPool: GRPCPool;
|
|
12
13
|
/** @ignore **/
|
|
14
|
+
quorumKeyProvider: QuorumKeyProvider;
|
|
15
|
+
/** @ignore **/
|
|
13
16
|
shieldedBuilder?: ShieldedBuilderWASM;
|
|
14
|
-
constructor(grpcPool: GRPCPool);
|
|
17
|
+
constructor(grpcPool: GRPCPool, quorumKeyProvider: QuorumKeyProvider);
|
|
15
18
|
/**
|
|
16
19
|
* Set bindings instance of builder
|
|
17
20
|
* Needed for custom builder load, because ShieldedBuilderWASM inits very slow on old hardware
|
package/src/shielded/index.js
CHANGED
|
@@ -15,9 +15,12 @@ export class ShieldedController {
|
|
|
15
15
|
/** @ignore **/
|
|
16
16
|
grpcPool;
|
|
17
17
|
/** @ignore **/
|
|
18
|
+
quorumKeyProvider;
|
|
19
|
+
/** @ignore **/
|
|
18
20
|
shieldedBuilder;
|
|
19
|
-
constructor(grpcPool) {
|
|
21
|
+
constructor(grpcPool, quorumKeyProvider) {
|
|
20
22
|
this.grpcPool = grpcPool;
|
|
23
|
+
this.quorumKeyProvider = quorumKeyProvider;
|
|
21
24
|
}
|
|
22
25
|
/**
|
|
23
26
|
* Set bindings instance of builder
|
|
@@ -54,7 +57,7 @@ export class ShieldedController {
|
|
|
54
57
|
* @return {Promise<ShieldedEncryptedNote[]>}
|
|
55
58
|
*/
|
|
56
59
|
async getShieldedEncryptedNotes(startIndex, count, tokenIdentifier) {
|
|
57
|
-
return await getShieldedEncryptedNotes(this.grpcPool, startIndex, count, tokenIdentifier);
|
|
60
|
+
return await getShieldedEncryptedNotes(this.grpcPool, this.quorumKeyProvider, startIndex, count, tokenIdentifier);
|
|
58
61
|
}
|
|
59
62
|
/**
|
|
60
63
|
* Retrieves the set of valid anchors (note commitment tree roots) currently
|
|
@@ -65,7 +68,7 @@ export class ShieldedController {
|
|
|
65
68
|
* @return {Promise<Uint8Array[]>}
|
|
66
69
|
*/
|
|
67
70
|
async getShieldedAnchors(tokenIdentifier) {
|
|
68
|
-
return await getShieldedAnchors(this.grpcPool, tokenIdentifier);
|
|
71
|
+
return await getShieldedAnchors(this.grpcPool, this.quorumKeyProvider, tokenIdentifier);
|
|
69
72
|
}
|
|
70
73
|
/**
|
|
71
74
|
* Retrieves the most recent anchor (note commitment tree root) of the shielded pool.
|
|
@@ -75,7 +78,7 @@ export class ShieldedController {
|
|
|
75
78
|
* @return {Promise<Uint8Array>}
|
|
76
79
|
*/
|
|
77
80
|
async getMostRecentShieldedAnchor(tokenIdentifier) {
|
|
78
|
-
return await getMostRecentShieldedAnchor(this.grpcPool, tokenIdentifier);
|
|
81
|
+
return await getMostRecentShieldedAnchor(this.grpcPool, this.quorumKeyProvider, tokenIdentifier);
|
|
79
82
|
}
|
|
80
83
|
/**
|
|
81
84
|
* Retrieves the total balance currently held in the shielded pool.
|
|
@@ -85,7 +88,7 @@ export class ShieldedController {
|
|
|
85
88
|
* @return {Promise<bigint>}
|
|
86
89
|
*/
|
|
87
90
|
async getShieldedPoolState(tokenIdentifier) {
|
|
88
|
-
return await getShieldedPoolState(this.grpcPool, tokenIdentifier);
|
|
91
|
+
return await getShieldedPoolState(this.grpcPool, this.quorumKeyProvider, tokenIdentifier);
|
|
89
92
|
}
|
|
90
93
|
/**
|
|
91
94
|
* Retrieves the total count of notes (leaves) in the shielded notes
|
|
@@ -96,7 +99,7 @@ export class ShieldedController {
|
|
|
96
99
|
* @return {Promise<bigint>}
|
|
97
100
|
*/
|
|
98
101
|
async getShieldedNotesCount(tokenIdentifier) {
|
|
99
|
-
return await getShieldedNotesCount(this.grpcPool, tokenIdentifier);
|
|
102
|
+
return await getShieldedNotesCount(this.grpcPool, this.quorumKeyProvider, tokenIdentifier);
|
|
100
103
|
}
|
|
101
104
|
/**
|
|
102
105
|
* Checks the spent status of the given nullifiers in the shielded pool.
|
|
@@ -110,7 +113,7 @@ export class ShieldedController {
|
|
|
110
113
|
* @return {Promise<ShieldedNullifierStatus[]>}
|
|
111
114
|
*/
|
|
112
115
|
async getShieldedNullifiers(nullifiers, tokenIdentifier) {
|
|
113
|
-
return await getShieldedNullifiers(this.grpcPool, nullifiers, tokenIdentifier);
|
|
116
|
+
return await getShieldedNullifiers(this.grpcPool, this.quorumKeyProvider, nullifiers, tokenIdentifier);
|
|
114
117
|
}
|
|
115
118
|
/**
|
|
116
119
|
* Recovers the notes owned by a wallet from a set of shielded encrypted notes
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { StateTransitionWASM } from 'pshenmic-dpp';
|
|
2
2
|
import { GRPCPool } from '../grpcConnectionPool.js';
|
|
3
|
+
import { QuorumKeyProvider } from '../quorumKeyProvider.js';
|
|
3
4
|
/**
|
|
4
5
|
* Collection of methods to perform state transitions (transactions) such like broadcast, wait for state transition result
|
|
5
6
|
*
|
|
@@ -8,7 +9,9 @@ import { GRPCPool } from '../grpcConnectionPool.js';
|
|
|
8
9
|
export declare class StateTransitionsController {
|
|
9
10
|
/** @ignore **/
|
|
10
11
|
grpcPool: GRPCPool;
|
|
11
|
-
|
|
12
|
+
/** @ignore **/
|
|
13
|
+
quorumKeyProvider: QuorumKeyProvider;
|
|
14
|
+
constructor(grpcPool: GRPCPool, quorumKeyProvider: QuorumKeyProvider);
|
|
12
15
|
/**
|
|
13
16
|
* Broadcasts a state transition to a network
|
|
14
17
|
*
|
|
@@ -8,8 +8,11 @@ import broadcast from './broadcast.js';
|
|
|
8
8
|
export class StateTransitionsController {
|
|
9
9
|
/** @ignore **/
|
|
10
10
|
grpcPool;
|
|
11
|
-
|
|
11
|
+
/** @ignore **/
|
|
12
|
+
quorumKeyProvider;
|
|
13
|
+
constructor(grpcPool, quorumKeyProvider) {
|
|
12
14
|
this.grpcPool = grpcPool;
|
|
15
|
+
this.quorumKeyProvider = quorumKeyProvider;
|
|
13
16
|
}
|
|
14
17
|
/**
|
|
15
18
|
* Broadcasts a state transition to a network
|
|
@@ -33,6 +36,6 @@ export class StateTransitionsController {
|
|
|
33
36
|
* @return {Promise<bigint | undefined>}
|
|
34
37
|
*/
|
|
35
38
|
async waitForStateTransitionResult(stateTransition) {
|
|
36
|
-
return await waitForStateTransitionResult(this.grpcPool, stateTransition);
|
|
39
|
+
return await waitForStateTransitionResult(this.grpcPool, this.quorumKeyProvider, stateTransition);
|
|
37
40
|
}
|
|
38
41
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { StateTransitionWASM } from 'pshenmic-dpp';
|
|
2
2
|
import { GRPCPool } from '../grpcConnectionPool.js';
|
|
3
|
-
|
|
3
|
+
import { QuorumKeyProvider } from '../quorumKeyProvider.js';
|
|
4
|
+
export default function waitForStateTransitionResult(grpcPool: GRPCPool, quorumKeyProvider: QuorumKeyProvider, stateTransition: StateTransitionWASM): Promise<bigint | undefined>;
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { BatchTransitionWASM, MasternodeVoteTransitionWASM, verifyStateTransitionResult } from 'pshenmic-dpp';
|
|
2
2
|
import hexToBytes from '../utils/hexToBytes.js';
|
|
3
3
|
import { WaitForStateTransitionResultRequest } from '../../proto/generated/platform.js';
|
|
4
|
-
import {
|
|
5
|
-
import bytesToHex from '../utils/bytesToHex.js';
|
|
6
|
-
import verifyTenderdashProof from '../utils/verifyTenderdashProof.js';
|
|
4
|
+
import QueryExecutor, { getResponseProof } from '../QueryExecutor.js';
|
|
7
5
|
import { base64 } from '@scure/base';
|
|
8
6
|
import { LATEST_PLATFORM_VERSION } from '../constants.js';
|
|
9
7
|
import getDataContractByIdentifier from '../dataContracts/getDataContractByIdentifier.js';
|
|
10
|
-
|
|
8
|
+
function toStateTransitionError(txHash, { code, message, data }) {
|
|
9
|
+
return new Error(`State transition ${txHash} failed to execute with code ${String(code)}, message: ${String(message)}, data: ${base64.encode(data)}`);
|
|
10
|
+
}
|
|
11
|
+
export default async function waitForStateTransitionResult(grpcPool, quorumKeyProvider, stateTransition) {
|
|
11
12
|
const txHash = stateTransition.hash(false);
|
|
12
13
|
const waitForStateTransitionResultRequest = WaitForStateTransitionResultRequest.create({
|
|
13
14
|
version: {
|
|
@@ -15,59 +16,56 @@ export default async function waitForStateTransitionResult(grpcPool, stateTransi
|
|
|
15
16
|
v0: {
|
|
16
17
|
stateTransitionHash: hexToBytes(txHash),
|
|
17
18
|
prove: true,
|
|
18
|
-
|
|
19
|
+
// without proof the owner balance is returned only if requested
|
|
20
|
+
requestUserBalance: grpcPool.proofs === false
|
|
19
21
|
}
|
|
20
22
|
}
|
|
21
23
|
});
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
if (
|
|
25
|
-
|
|
24
|
+
// contracts are fetched before the request, so their proof errors are not attributed to the node of the request
|
|
25
|
+
const knownContracts = [];
|
|
26
|
+
if (stateTransition.getActionType() === 'BATCH') {
|
|
27
|
+
const batchTransition = BatchTransitionWASM.fromStateTransition(stateTransition);
|
|
28
|
+
const [transition] = batchTransition.transitions;
|
|
29
|
+
knownContracts.push(await getDataContractByIdentifier(grpcPool, quorumKeyProvider, transition.dataContractId));
|
|
26
30
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
if (stateTransition.getActionType() === 'MASTERNODE_VOTE') {
|
|
32
|
+
const masternodeVote = MasternodeVoteTransitionWASM.fromStateTransition(stateTransition);
|
|
33
|
+
knownContracts.push(await getDataContractByIdentifier(grpcPool, quorumKeyProvider, masternodeVote.vote.votePoll.contractId));
|
|
30
34
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const knownContracts = [];
|
|
38
|
-
if (stateTransition.getActionType() === 'BATCH') {
|
|
39
|
-
const batchTransition = BatchTransitionWASM.fromStateTransition(stateTransition);
|
|
40
|
-
const [transition] = batchTransition.transitions;
|
|
41
|
-
const dataContract = await getDataContractByIdentifier(grpcPool, transition.dataContractId);
|
|
42
|
-
knownContracts.push(dataContract);
|
|
35
|
+
return await QueryExecutor.build(grpcPool, quorumKeyProvider)
|
|
36
|
+
.setGrpcRequest('waitForStateTransitionResult', waitForStateTransitionResultRequest)
|
|
37
|
+
.mapProof(response => {
|
|
38
|
+
const { version } = response;
|
|
39
|
+
if (version.oneofKind !== 'v0') {
|
|
40
|
+
throw new Error('Unexpected oneOf type returned from DAPI (must be v0)');
|
|
43
41
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
knownContracts.push(dataContract);
|
|
42
|
+
const { v0 } = version;
|
|
43
|
+
if (v0.result.oneofKind === 'error') {
|
|
44
|
+
throw toStateTransitionError(txHash, v0.result.error);
|
|
48
45
|
}
|
|
46
|
+
return getResponseProof(response);
|
|
47
|
+
})
|
|
48
|
+
.setProofVerifier(verifyStateTransitionResult, ({ metadata }) => {
|
|
49
|
+
const { timeMs, height, coreChainLockedHeight, epoch } = metadata;
|
|
49
50
|
const blockInfo = {
|
|
50
51
|
timeMs: BigInt(timeMs),
|
|
51
52
|
height: BigInt(height),
|
|
52
53
|
coreHeight: coreChainLockedHeight,
|
|
53
54
|
epoch
|
|
54
55
|
};
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
return [stateTransition, blockInfo, knownContracts, LATEST_PLATFORM_VERSION];
|
|
57
|
+
})
|
|
58
|
+
.mapResponse(data => {
|
|
59
|
+
if (data.proved) {
|
|
60
|
+
if (data.verified.result == null) {
|
|
61
|
+
throw new Error('State transition result was null');
|
|
62
|
+
}
|
|
63
|
+
return data.verified.ownerBalance;
|
|
58
64
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if (!verify) {
|
|
62
|
-
throw new Error('Failed to verify wait for state transition result query');
|
|
65
|
+
if (data.result.oneofKind === 'error') {
|
|
66
|
+
throw toStateTransitionError(txHash, data.result.error);
|
|
63
67
|
}
|
|
64
|
-
return ownerBalance;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const { code, message, data } = v0.result.error;
|
|
68
|
-
throw new Error(`State transition ${txHash} failed to execute with code ${String(code)}, message: ${String(message)}, data: ${base64.encode(data)}`);
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
throw new Error('Unexpected oneOfKind returned for waitForStateTransitionResult');
|
|
72
|
-
}
|
|
68
|
+
return BigInt(data.result.successWithOwnerBalance.ownerBalance);
|
|
69
|
+
})
|
|
70
|
+
.execute();
|
|
73
71
|
}
|
|
@@ -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 IdentitiesTokenBalances {
|
|
4
5
|
identityId: IdentifierWASM;
|
|
5
6
|
balance?: bigint | undefined;
|
|
6
7
|
}
|
|
7
|
-
export default function getIdentitiesTokenBalances(grpcPool: GRPCPool, identifiers: IdentifierLike[], tokenIdentifier: IdentifierLike): Promise<IdentitiesTokenBalances[]>;
|
|
8
|
+
export default function getIdentitiesTokenBalances(grpcPool: GRPCPool, quorumKeyProvider: QuorumKeyProvider, identifiers: IdentifierLike[], tokenIdentifier: IdentifierLike): Promise<IdentitiesTokenBalances[]>;
|
|
@@ -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[]>;
|