dash-platform-sdk 1.6.0-dev.2 → 1.6.0-dev.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -15
- package/bundle.min.js +1 -1
- package/index.d.ts +3 -1
- package/index.js +2 -1
- package/package.json +2 -2
- package/proto/generated/platform.client.d.ts +10 -0
- package/proto/generated/platform.client.js +27 -20
- package/proto/generated/platform.d.ts +350 -2
- package/proto/generated/platform.js +737 -8
- package/src/DashPlatformSDK.d.ts +19 -1
- package/src/DashPlatformSDK.js +28 -10
- package/src/QueryExecutor.d.ts +122 -0
- package/src/QueryExecutor.js +205 -0
- package/src/constants.d.ts +6 -0
- package/src/constants.js +6 -0
- package/src/contestedResources/getContestedResourceVoteState.d.ts +2 -1
- package/src/contestedResources/getContestedResourceVoteState.js +69 -49
- package/src/contestedResources/getVotePollsByEndDate.d.ts +4 -0
- package/src/contestedResources/getVotePollsByEndDate.js +39 -0
- package/src/contestedResources/index.d.ts +16 -2
- package/src/contestedResources/index.js +19 -2
- package/src/dataContracts/getDataContractByIdentifier.d.ts +2 -1
- package/src/dataContracts/getDataContractByIdentifier.js +15 -27
- package/src/dataContracts/index.d.ts +4 -1
- package/src/dataContracts/index.js +5 -2
- package/src/documents/getActionFeeAgreement.d.ts +2 -1
- package/src/documents/getActionFeeAgreement.js +3 -3
- package/src/documents/index.d.ts +12 -8
- package/src/documents/index.js +16 -13
- package/src/documents/query.d.ts +2 -1
- package/src/documents/query.js +16 -8
- package/src/documents/queryAggregate.d.ts +8 -1
- package/src/documents/queryAggregate.js +49 -15
- package/src/documents/queryJoined.d.ts +3 -2
- package/src/documents/queryJoined.js +54 -13
- package/src/documents/queryRanked.d.ts +3 -2
- package/src/documents/queryRanked.js +49 -15
- package/src/documents/v1.d.ts +25 -8
- package/src/documents/v1.js +50 -14
- package/src/grpcConnectionPool.d.ts +30 -4
- package/src/grpcConnectionPool.js +169 -39
- package/src/identities/getIdentityBalance.d.ts +2 -1
- package/src/identities/getIdentityBalance.js +13 -27
- package/src/identities/getIdentityByIdentifier.d.ts +2 -1
- package/src/identities/getIdentityByIdentifier.js +14 -28
- package/src/identities/getIdentityByNonUniquePublicKeyHash.d.ts +2 -1
- package/src/identities/getIdentityByNonUniquePublicKeyHash.js +49 -28
- package/src/identities/getIdentityByPublicKeyHash.d.ts +2 -1
- package/src/identities/getIdentityByPublicKeyHash.js +14 -28
- package/src/identities/getIdentityContractNonce.d.ts +2 -1
- package/src/identities/getIdentityContractNonce.js +10 -27
- package/src/identities/getIdentityNonce.d.ts +2 -1
- package/src/identities/getIdentityNonce.js +10 -27
- package/src/identities/getIdentityPublicKeys.d.ts +2 -1
- package/src/identities/getIdentityPublicKeys.js +16 -29
- package/src/identities/index.d.ts +4 -1
- package/src/identities/index.js +11 -8
- package/src/names/index.d.ts +4 -1
- package/src/names/index.js +8 -5
- package/src/names/registerName.d.ts +2 -1
- package/src/names/registerName.js +4 -4
- package/src/names/searchByIdentity.d.ts +2 -1
- package/src/names/searchByIdentity.js +2 -2
- package/src/names/searchByName.d.ts +2 -1
- package/src/names/searchByName.js +2 -2
- package/src/node/epochInfos.d.ts +2 -1
- package/src/node/epochInfos.js +27 -31
- package/src/node/finalizedEpochInfos.d.ts +4 -3
- package/src/node/finalizedEpochInfos.js +45 -39
- package/src/node/index.d.ts +4 -1
- package/src/node/index.js +7 -4
- package/src/node/totalCredits.d.ts +2 -1
- package/src/node/totalCredits.js +10 -25
- package/src/platformAddresses/getAddressInfo.d.ts +2 -1
- package/src/platformAddresses/getAddressInfo.js +17 -31
- package/src/platformAddresses/getAddressesBranchState.d.ts +2 -1
- package/src/platformAddresses/getAddressesBranchState.js +22 -8
- package/src/platformAddresses/getAddressesInfos.d.ts +2 -1
- package/src/platformAddresses/getAddressesInfos.js +18 -29
- package/src/platformAddresses/getAddressesTrunkState.d.ts +2 -1
- package/src/platformAddresses/getAddressesTrunkState.js +25 -23
- package/src/platformAddresses/getRecentAddressBalanceChanges.d.ts +2 -1
- package/src/platformAddresses/getRecentAddressBalanceChanges.js +26 -26
- package/src/platformAddresses/getRecentCompactedAddressBalanceChanges.d.ts +2 -1
- package/src/platformAddresses/getRecentCompactedAddressBalanceChanges.js +30 -26
- package/src/platformAddresses/index.d.ts +4 -1
- package/src/platformAddresses/index.js +10 -7
- package/src/quorumKeyProvider.d.ts +23 -0
- package/src/quorumKeyProvider.js +28 -0
- package/src/shielded/getMostRecentShieldedAnchor.d.ts +2 -1
- package/src/shielded/getMostRecentShieldedAnchor.js +8 -25
- package/src/shielded/getShieldedAnchors.d.ts +2 -1
- package/src/shielded/getShieldedAnchors.js +8 -25
- package/src/shielded/getShieldedEncryptedNotes.d.ts +2 -1
- package/src/shielded/getShieldedEncryptedNotes.js +16 -30
- package/src/shielded/getShieldedNotesCount.d.ts +2 -1
- package/src/shielded/getShieldedNotesCount.js +8 -25
- package/src/shielded/getShieldedNullifiers.d.ts +2 -1
- package/src/shielded/getShieldedNullifiers.js +14 -28
- package/src/shielded/getShieldedPoolState.d.ts +2 -1
- package/src/shielded/getShieldedPoolState.js +8 -25
- package/src/shielded/index.d.ts +4 -1
- package/src/shielded/index.js +10 -7
- package/src/stateTransitions/index.d.ts +4 -1
- package/src/stateTransitions/index.js +5 -2
- package/src/stateTransitions/waitForStateTransitionResult.d.ts +2 -1
- package/src/stateTransitions/waitForStateTransitionResult.js +42 -44
- package/src/tokens/getIdentitiesTokenBalances.d.ts +2 -1
- package/src/tokens/getIdentitiesTokenBalances.js +17 -28
- package/src/tokens/getIdentityTokensBalances.d.ts +2 -1
- package/src/tokens/getIdentityTokensBalances.js +17 -28
- package/src/tokens/getTokenContractInfo.d.ts +2 -1
- package/src/tokens/getTokenContractInfo.js +16 -30
- package/src/tokens/getTokenDirectPurchasePrices.d.ts +2 -1
- package/src/tokens/getTokenDirectPurchasePrices.js +26 -28
- package/src/tokens/getTokenTotalSupply.d.ts +2 -1
- package/src/tokens/getTokenTotalSupply.js +16 -28
- package/src/tokens/index.d.ts +4 -1
- package/src/tokens/index.js +11 -8
- package/src/utils/ProofError.d.ts +9 -0
- package/src/utils/ProofError.js +10 -0
- package/src/utils/verifyTenderdashProof.js +2 -1
- package/test/unit/SDK.spec.js +42 -0
- package/src/utils/getQuorumPublicKey.d.ts +0 -1
- package/src/utils/getQuorumPublicKey.js +0 -19
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { GetMostRecentShieldedAnchorRequest } from '../../proto/generated/platform.js';
|
|
2
2
|
import { IdentifierWASM, verifyMostRecentShieldedAnchorProof } from 'pshenmic-dpp';
|
|
3
|
-
import { LATEST_PLATFORM_VERSION } from
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
import verifyTenderdashProof from "../utils/verifyTenderdashProof.js";
|
|
7
|
-
export default async function getMostRecentShieldedAnchor(grpcPool, tokenIdentifier) {
|
|
3
|
+
import { LATEST_PLATFORM_VERSION } from '../constants.js';
|
|
4
|
+
import QueryExecutor from '../QueryExecutor.js';
|
|
5
|
+
export default async function getMostRecentShieldedAnchor(grpcPool, quorumKeyProvider, tokenIdentifier) {
|
|
8
6
|
const tokenId = tokenIdentifier != null ? new IdentifierWASM(tokenIdentifier) : undefined;
|
|
9
7
|
const getMostRecentShieldedAnchorRequest = GetMostRecentShieldedAnchorRequest.create({
|
|
10
8
|
version: {
|
|
@@ -15,24 +13,9 @@ export default async function getMostRecentShieldedAnchor(grpcPool, tokenIdentif
|
|
|
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, anchor } = verifyMostRecentShieldedAnchorProof(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 anchor;
|
|
16
|
+
return await QueryExecutor.build(grpcPool, quorumKeyProvider)
|
|
17
|
+
.setGrpcRequest('getMostRecentShieldedAnchor', getMostRecentShieldedAnchorRequest)
|
|
18
|
+
.setProofVerifier(verifyMostRecentShieldedAnchorProof, true, LATEST_PLATFORM_VERSION, tokenId)
|
|
19
|
+
.mapResponse(data => data.proved ? data.verified.anchor : data.result.anchor)
|
|
20
|
+
.execute();
|
|
38
21
|
}
|
|
@@ -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 getShieldedAnchors(grpcPool: GRPCPool, tokenIdentifier?: IdentifierLike): Promise<Uint8Array[]>;
|
|
4
|
+
export default function getShieldedAnchors(grpcPool: GRPCPool, quorumKeyProvider: QuorumKeyProvider, tokenIdentifier?: IdentifierLike): Promise<Uint8Array[]>;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { GetShieldedAnchorsRequest } from '../../proto/generated/platform.js';
|
|
2
2
|
import { IdentifierWASM, verifyShieldedAnchorsProof } from 'pshenmic-dpp';
|
|
3
|
-
import { LATEST_PLATFORM_VERSION } from
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
import verifyTenderdashProof from "../utils/verifyTenderdashProof.js";
|
|
7
|
-
export default async function getShieldedAnchors(grpcPool, tokenIdentifier) {
|
|
3
|
+
import { LATEST_PLATFORM_VERSION } from '../constants.js';
|
|
4
|
+
import QueryExecutor from '../QueryExecutor.js';
|
|
5
|
+
export default async function getShieldedAnchors(grpcPool, quorumKeyProvider, tokenIdentifier) {
|
|
8
6
|
const tokenId = tokenIdentifier != null ? new IdentifierWASM(tokenIdentifier) : undefined;
|
|
9
7
|
const getShieldedAnchorsRequest = GetShieldedAnchorsRequest.create({
|
|
10
8
|
version: {
|
|
@@ -15,24 +13,9 @@ export default async function getShieldedAnchors(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, anchors } = verifyShieldedAnchorsProof(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 anchors;
|
|
16
|
+
return await QueryExecutor.build(grpcPool, quorumKeyProvider)
|
|
17
|
+
.setGrpcRequest('getShieldedAnchors', getShieldedAnchorsRequest)
|
|
18
|
+
.setProofVerifier(verifyShieldedAnchorsProof, true, LATEST_PLATFORM_VERSION, tokenId)
|
|
19
|
+
.mapResponse(data => data.proved ? data.verified.anchors : data.result.anchors.anchors)
|
|
20
|
+
.execute();
|
|
38
21
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { GRPCPool } from '../grpcConnectionPool.js';
|
|
2
|
+
import { QuorumKeyProvider } from '../quorumKeyProvider.js';
|
|
2
3
|
import { ShieldedEncryptedNote } from '../../types.js';
|
|
3
4
|
import { IdentifierLike } from 'pshenmic-dpp';
|
|
4
|
-
export default function getShieldedEncryptedNotes(grpcPool: GRPCPool, startIndex: bigint, count: number, tokenIdentifier?: IdentifierLike): Promise<ShieldedEncryptedNote[]>;
|
|
5
|
+
export default function getShieldedEncryptedNotes(grpcPool: GRPCPool, quorumKeyProvider: QuorumKeyProvider, startIndex: bigint, count: number, tokenIdentifier?: IdentifierLike): Promise<ShieldedEncryptedNote[]>;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { GetShieldedEncryptedNotesRequest } from '../../proto/generated/platform.js';
|
|
2
2
|
import { IdentifierWASM, verifyShieldedEncryptedNotesProof } from 'pshenmic-dpp';
|
|
3
|
-
import { LATEST_PLATFORM_VERSION, SHIELDED_MAX_NOTES_PER_QUERY } from
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
import verifyTenderdashProof from "../utils/verifyTenderdashProof.js";
|
|
7
|
-
export default async function getShieldedEncryptedNotes(grpcPool, startIndex, count, tokenIdentifier) {
|
|
3
|
+
import { LATEST_PLATFORM_VERSION, SHIELDED_MAX_NOTES_PER_QUERY } from '../constants.js';
|
|
4
|
+
import QueryExecutor from '../QueryExecutor.js';
|
|
5
|
+
export default async function getShieldedEncryptedNotes(grpcPool, quorumKeyProvider, startIndex, count, tokenIdentifier) {
|
|
8
6
|
const tokenId = tokenIdentifier != null ? new IdentifierWASM(tokenIdentifier) : undefined;
|
|
9
7
|
const getShieldedEncryptedNotesRequest = GetShieldedEncryptedNotesRequest.create({
|
|
10
8
|
version: {
|
|
@@ -17,29 +15,17 @@ export default async function getShieldedEncryptedNotes(grpcPool, startIndex, co
|
|
|
17
15
|
}
|
|
18
16
|
}
|
|
19
17
|
});
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const { rootHash, notes } = verifyShieldedEncryptedNotesProof(proof.grovedbProof, startIndex, count, SHIELDED_MAX_NOTES_PER_QUERY, true, LATEST_PLATFORM_VERSION, tokenId);
|
|
34
|
-
const quorumPublicKey = await getQuorumPublicKey(grpcPool.network, proof.quorumType, bytesToHex(proof.quorumHash));
|
|
35
|
-
const verify = await verifyTenderdashProof(proof, metadata, rootHash, quorumPublicKey);
|
|
36
|
-
if (!verify) {
|
|
37
|
-
throw new Error('Failed to verify query');
|
|
38
|
-
}
|
|
39
|
-
return notes.map(note => ({
|
|
40
|
-
nullifier: note.nullifier,
|
|
41
|
-
cmx: note.cmx,
|
|
42
|
-
encryptedNote: note.encryptedNote,
|
|
43
|
-
cvNet: note.cvNet
|
|
44
|
-
}));
|
|
18
|
+
return await QueryExecutor.build(grpcPool, quorumKeyProvider)
|
|
19
|
+
.setGrpcRequest('getShieldedEncryptedNotes', getShieldedEncryptedNotesRequest)
|
|
20
|
+
.setProofVerifier(verifyShieldedEncryptedNotesProof, startIndex, count, SHIELDED_MAX_NOTES_PER_QUERY, true, LATEST_PLATFORM_VERSION, tokenId)
|
|
21
|
+
.mapResponse(data => {
|
|
22
|
+
const notes = data.proved ? data.verified.notes : data.result.encryptedNotes.entries;
|
|
23
|
+
return notes.map(note => ({
|
|
24
|
+
nullifier: note.nullifier,
|
|
25
|
+
cmx: note.cmx,
|
|
26
|
+
encryptedNote: note.encryptedNote,
|
|
27
|
+
cvNet: note.cvNet
|
|
28
|
+
}));
|
|
29
|
+
})
|
|
30
|
+
.execute();
|
|
45
31
|
}
|
|
@@ -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 getShieldedNotesCount(grpcPool: GRPCPool, tokenIdentifier?: IdentifierLike): Promise<bigint | undefined>;
|
|
4
|
+
export default function getShieldedNotesCount(grpcPool: GRPCPool, quorumKeyProvider: QuorumKeyProvider, tokenIdentifier?: IdentifierLike): Promise<bigint | undefined>;
|
|
@@ -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[]>;
|