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
|
-
import { IdentifierWASM, verifyTokenDirectPurchasePrices } from 'pshenmic-dpp';
|
|
2
|
-
import
|
|
3
|
-
import verifyTenderdashProof from '../utils/verifyTenderdashProof.js';
|
|
4
|
-
import bytesToHex from '../utils/bytesToHex.js';
|
|
1
|
+
import { IdentifierWASM, verifyTokenDirectPurchasePrices, TokenPricingScheduleWASM } from 'pshenmic-dpp';
|
|
2
|
+
import QueryExecutor from '../QueryExecutor.js';
|
|
5
3
|
import { GetTokenDirectPurchasePricesRequest } from '../../proto/generated/platform.js';
|
|
6
4
|
import { LATEST_PLATFORM_VERSION } from '../constants.js';
|
|
7
|
-
export default async function getTokenDirectPurchasePrices(grpcPool, tokenIdentifiers) {
|
|
5
|
+
export default async function getTokenDirectPurchasePrices(grpcPool, quorumKeyProvider, tokenIdentifiers) {
|
|
8
6
|
const tokenIds = tokenIdentifiers.map(tokenId => new IdentifierWASM(tokenId).bytes());
|
|
9
7
|
const request = GetTokenDirectPurchasePricesRequest.create({
|
|
10
8
|
version: {
|
|
@@ -15,27 +13,27 @@ export default async function getTokenDirectPurchasePrices(grpcPool, tokenIdenti
|
|
|
15
13
|
}
|
|
16
14
|
}
|
|
17
15
|
});
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
16
|
+
return await QueryExecutor.build(grpcPool, quorumKeyProvider)
|
|
17
|
+
.setGrpcRequest('getTokenDirectPurchasePrices', request)
|
|
18
|
+
.setProofVerifier(verifyTokenDirectPurchasePrices, tokenIds, true, LATEST_PLATFORM_VERSION)
|
|
19
|
+
.mapResponse(data => {
|
|
20
|
+
if (data.proved) {
|
|
21
|
+
if (data.verified.prices == null) {
|
|
22
|
+
throw new Error('Prices not found');
|
|
23
|
+
}
|
|
24
|
+
return data.verified.prices;
|
|
25
|
+
}
|
|
26
|
+
return data.result.tokenDirectPurchasePrices.tokenDirectPurchasePrice.map(({ tokenId, price }) => {
|
|
27
|
+
let pricingSchedule;
|
|
28
|
+
if (price.oneofKind === 'fixedPrice') {
|
|
29
|
+
pricingSchedule = TokenPricingScheduleWASM.SinglePrice(BigInt(price.fixedPrice));
|
|
30
|
+
}
|
|
31
|
+
else if (price.oneofKind === 'variablePrice') {
|
|
32
|
+
pricingSchedule = TokenPricingScheduleWASM.SetPrices(Object.fromEntries(price.variablePrice.priceForQuantity
|
|
33
|
+
.map(({ quantity, price }) => [quantity, BigInt(price)])));
|
|
34
|
+
}
|
|
35
|
+
return { tokenId: new IdentifierWASM(tokenId), pricingSchedule };
|
|
36
|
+
});
|
|
37
|
+
})
|
|
38
|
+
.execute();
|
|
41
39
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { GRPCPool } from '../grpcConnectionPool.js';
|
|
2
|
+
import { QuorumKeyProvider } from '../quorumKeyProvider.js';
|
|
2
3
|
import { TokenTotalSupply } from '../../types.js';
|
|
3
4
|
import { IdentifierLike } from 'pshenmic-dpp';
|
|
4
|
-
export default function getTokenTotalSupply(grpcPool: GRPCPool, tokenIdentifier: IdentifierLike): Promise<TokenTotalSupply>;
|
|
5
|
+
export default function getTokenTotalSupply(grpcPool: GRPCPool, quorumKeyProvider: QuorumKeyProvider, tokenIdentifier: IdentifierLike): Promise<TokenTotalSupply>;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { GetTokenTotalSupplyRequest } from '../../proto/generated/platform.js';
|
|
2
2
|
import { IdentifierWASM, verifyTokenTotalSupplyProof } 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 getTokenTotalSupply(grpcPool, tokenIdentifier) {
|
|
5
|
+
export default async function getTokenTotalSupply(grpcPool, quorumKeyProvider, tokenIdentifier) {
|
|
8
6
|
const tokenId = new IdentifierWASM(tokenIdentifier);
|
|
9
7
|
const getTokenTotalSupplyRequest = GetTokenTotalSupplyRequest.create({
|
|
10
8
|
version: {
|
|
@@ -15,28 +13,18 @@ export default async function getTokenTotalSupply(grpcPool, tokenIdentifier) {
|
|
|
15
13
|
}
|
|
16
14
|
}
|
|
17
15
|
});
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
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 {
|
|
38
|
-
tokenId,
|
|
39
|
-
totalSystemAmount: totalBalance.tokenSupply,
|
|
40
|
-
totalAggregatedAmountInUserAccounts: totalBalance.aggregatedTokenAccountBalances
|
|
41
|
-
};
|
|
16
|
+
return await QueryExecutor.build(grpcPool, quorumKeyProvider)
|
|
17
|
+
.setGrpcRequest('getTokenTotalSupply', getTokenTotalSupplyRequest)
|
|
18
|
+
.setProofVerifier(verifyTokenTotalSupplyProof, tokenId, true, LATEST_PLATFORM_VERSION)
|
|
19
|
+
.mapResponse(data => {
|
|
20
|
+
const [totalSystemAmount, totalAggregatedAmountInUserAccounts] = data.proved
|
|
21
|
+
? [data.verified.totalBalance.tokenSupply, data.verified.totalBalance.aggregatedTokenAccountBalances]
|
|
22
|
+
: [BigInt(data.result.tokenTotalSupply.totalSystemAmount), BigInt(data.result.tokenTotalSupply.totalAggregatedAmountInUserAccounts)];
|
|
23
|
+
return {
|
|
24
|
+
tokenId,
|
|
25
|
+
totalSystemAmount,
|
|
26
|
+
totalAggregatedAmountInUserAccounts
|
|
27
|
+
};
|
|
28
|
+
})
|
|
29
|
+
.execute();
|
|
42
30
|
}
|
package/src/tokens/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { GRPCPool } from '../grpcConnectionPool.js';
|
|
2
|
+
import { QuorumKeyProvider } from '../quorumKeyProvider.js';
|
|
2
3
|
import { TokenDirectPurchasePrices, TokenTotalSupply, TokenTransitionParams, TokenTransitionType } from '../../types.js';
|
|
3
4
|
import { IdentitiesTokenBalances } from './getIdentitiesTokenBalances.js';
|
|
4
5
|
import { IdentityTokenBalances } from './getIdentityTokensBalances.js';
|
|
@@ -12,7 +13,9 @@ import { IdentifierLike, StateTransitionWASM, TokenBaseTransitionWASM } from 'ps
|
|
|
12
13
|
export declare class TokensController {
|
|
13
14
|
/** @ignore **/
|
|
14
15
|
grpcPool: GRPCPool;
|
|
15
|
-
|
|
16
|
+
/** @ignore **/
|
|
17
|
+
quorumKeyProvider: QuorumKeyProvider;
|
|
18
|
+
constructor(grpcPool: GRPCPool, quorumKeyProvider: QuorumKeyProvider);
|
|
16
19
|
/**
|
|
17
20
|
* Retrieves a token balances for identities
|
|
18
21
|
*
|
package/src/tokens/index.js
CHANGED
|
@@ -14,8 +14,11 @@ import getTokenDirectPurchasePrices from './getTokenDirectPurchasePrices.js';
|
|
|
14
14
|
export class TokensController {
|
|
15
15
|
/** @ignore **/
|
|
16
16
|
grpcPool;
|
|
17
|
-
|
|
17
|
+
/** @ignore **/
|
|
18
|
+
quorumKeyProvider;
|
|
19
|
+
constructor(grpcPool, quorumKeyProvider) {
|
|
18
20
|
this.grpcPool = grpcPool;
|
|
21
|
+
this.quorumKeyProvider = quorumKeyProvider;
|
|
19
22
|
}
|
|
20
23
|
/**
|
|
21
24
|
* Retrieves a token balances for identities
|
|
@@ -26,7 +29,7 @@ export class TokensController {
|
|
|
26
29
|
* @return {Promise<IdentitiesTokenBalances>}
|
|
27
30
|
*/
|
|
28
31
|
async getIdentitiesTokenBalances(identifiers, tokenIdentifier) {
|
|
29
|
-
return await getIdentitiesTokenBalances(this.grpcPool, identifiers, tokenIdentifier);
|
|
32
|
+
return await getIdentitiesTokenBalances(this.grpcPool, this.quorumKeyProvider, identifiers, tokenIdentifier);
|
|
30
33
|
}
|
|
31
34
|
/**
|
|
32
35
|
* Retrieves a tokens balances for identity
|
|
@@ -37,7 +40,7 @@ export class TokensController {
|
|
|
37
40
|
* @return {Promise<IdentityTokenBalances>}
|
|
38
41
|
*/
|
|
39
42
|
async getIdentityTokensBalances(identifier, tokenIdentifiers) {
|
|
40
|
-
return await getIdentityTokensBalances(this.grpcPool, identifier, tokenIdentifiers);
|
|
43
|
+
return await getIdentityTokensBalances(this.grpcPool, this.quorumKeyProvider, identifier, tokenIdentifiers);
|
|
41
44
|
}
|
|
42
45
|
/**
|
|
43
46
|
* Retrieves a tokens contract info by id
|
|
@@ -47,7 +50,7 @@ export class TokensController {
|
|
|
47
50
|
* @return {Promise<TokenContractInfo>}
|
|
48
51
|
*/
|
|
49
52
|
async getTokenContractInfo(tokenIdentifier) {
|
|
50
|
-
return await getTokenContractInfo(this.grpcPool, tokenIdentifier);
|
|
53
|
+
return await getTokenContractInfo(this.grpcPool, this.quorumKeyProvider, tokenIdentifier);
|
|
51
54
|
}
|
|
52
55
|
/**
|
|
53
56
|
* Retrieves a token total supply
|
|
@@ -57,7 +60,7 @@ export class TokensController {
|
|
|
57
60
|
* @return {Promise<TokenTotalSupply>}
|
|
58
61
|
*/
|
|
59
62
|
async getTokenTotalSupply(tokenIdentifier) {
|
|
60
|
-
return await getTokenTotalSupply(this.grpcPool, tokenIdentifier);
|
|
63
|
+
return await getTokenTotalSupply(this.grpcPool, this.quorumKeyProvider, tokenIdentifier);
|
|
61
64
|
}
|
|
62
65
|
/**
|
|
63
66
|
* Retrieves a tokens prices
|
|
@@ -67,7 +70,7 @@ export class TokensController {
|
|
|
67
70
|
* @return {Promise<TokenDirectPurchasePrices[]>}
|
|
68
71
|
*/
|
|
69
72
|
async getTokensDirectPurchasePrice(tokenIdentifiers) {
|
|
70
|
-
return await getTokenDirectPurchasePrices(this.grpcPool, tokenIdentifiers);
|
|
73
|
+
return await getTokenDirectPurchasePrices(this.grpcPool, this.quorumKeyProvider, tokenIdentifiers);
|
|
71
74
|
}
|
|
72
75
|
/**
|
|
73
76
|
* Creates a Token Base Transition that contains base information about token transition
|
|
@@ -78,8 +81,8 @@ export class TokensController {
|
|
|
78
81
|
* @return {TokenBaseTransitionWASM}
|
|
79
82
|
*/
|
|
80
83
|
async createBaseTransition(tokenId, ownerId) {
|
|
81
|
-
const { dataContractId, tokenContractPosition } = await getTokenContractInfo(this.grpcPool, tokenId);
|
|
82
|
-
const identityContractNonce = await getIdentityContractNonce(this.grpcPool, ownerId, dataContractId);
|
|
84
|
+
const { dataContractId, tokenContractPosition } = await getTokenContractInfo(this.grpcPool, this.quorumKeyProvider, tokenId);
|
|
85
|
+
const identityContractNonce = await getIdentityContractNonce(this.grpcPool, this.quorumKeyProvider, ownerId, dataContractId);
|
|
83
86
|
return new TokenBaseTransitionWASM(identityContractNonce + BigInt(1), tokenContractPosition, dataContractId, tokenId, undefined);
|
|
84
87
|
}
|
|
85
88
|
/**
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thrown when the response of a node can not be verified (invalid GroveDB proof, invalid quorum signature, stale metadata).
|
|
3
|
+
* Such node is banned and the request is retried on another node
|
|
4
|
+
*/
|
|
5
|
+
export default class ProofError extends Error {
|
|
6
|
+
constructor(message: string, options?: {
|
|
7
|
+
cause?: unknown;
|
|
8
|
+
});
|
|
9
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thrown when the response of a node can not be verified (invalid GroveDB proof, invalid quorum signature, stale metadata).
|
|
3
|
+
* Such node is banned and the request is retried on another node
|
|
4
|
+
*/
|
|
5
|
+
export default class ProofError extends Error {
|
|
6
|
+
constructor(message, options) {
|
|
7
|
+
super(message, options);
|
|
8
|
+
this.name = 'ProofError';
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -3,9 +3,10 @@ import { calculateSignHash } from './calculateSignHash.js';
|
|
|
3
3
|
import { calculateStateIdHash } from './calculateStateIdHash.js';
|
|
4
4
|
import { verifySignatureDigest } from 'pshenmic-dpp';
|
|
5
5
|
import hexToBytes from './hexToBytes.js';
|
|
6
|
+
import ProofError from './ProofError.js';
|
|
6
7
|
export default async function verifyTenderdashProof(proof, metadata, rootHash, quorumPublicKey) {
|
|
7
8
|
if (Date.now() - Number(metadata.timeMs) > 15 * 60 * 1000) {
|
|
8
|
-
throw new
|
|
9
|
+
throw new ProofError('Request is stalled (over 15 minutes)');
|
|
9
10
|
}
|
|
10
11
|
const stateId = StateId.create({
|
|
11
12
|
appVersion: String(metadata.protocolVersion),
|
|
@@ -21,7 +21,7 @@ describe('Document', () => {
|
|
|
21
21
|
};
|
|
22
22
|
});
|
|
23
23
|
test('should be able to create document', async () => {
|
|
24
|
-
const document = sdk.documents.create(dataContract, documentType, data, identity, revision);
|
|
24
|
+
const document = sdk.documents.create(dataContract, documentType, data, identity, BigInt(1), revision);
|
|
25
25
|
expect(document).toEqual(expect.any(DocumentWASM));
|
|
26
26
|
});
|
|
27
27
|
test('should be able to get documents', async () => {
|
|
@@ -73,14 +73,14 @@ describe('Document', () => {
|
|
|
73
73
|
});
|
|
74
74
|
describe('should be able to create state transition', () => {
|
|
75
75
|
test('should be able to create a create transition', async () => {
|
|
76
|
-
const document = sdk.documents.create(dataContract, documentType, data, identity);
|
|
77
76
|
const identityContractNonce = BigInt(1);
|
|
77
|
+
const document = sdk.documents.create(dataContract, documentType, data, identity, identityContractNonce);
|
|
78
78
|
const stateTransition = sdk.documents.createStateTransition(document, 'create', { identityContractNonce });
|
|
79
79
|
expect(stateTransition).toEqual(expect.any(StateTransitionWASM));
|
|
80
80
|
});
|
|
81
81
|
test('should be able to create a contested document transition', async () => {
|
|
82
|
-
const document = sdk.documents.create(dataContract, documentType, data, identity);
|
|
83
82
|
const identityContractNonce = BigInt(1);
|
|
83
|
+
const document = sdk.documents.create(dataContract, documentType, data, identity, identityContractNonce);
|
|
84
84
|
// 0.2 Dash typically
|
|
85
85
|
const contestedFee = BigInt(20000000000);
|
|
86
86
|
const indexName = 'parentNameAndLabel';
|
|
@@ -89,8 +89,8 @@ describe('Document', () => {
|
|
|
89
89
|
expect(stateTransition).toEqual(expect.any(StateTransitionWASM));
|
|
90
90
|
});
|
|
91
91
|
test('should be able to create a document with token payment info', async () => {
|
|
92
|
-
const document = sdk.documents.create(dataContract, documentType, data, identity);
|
|
93
92
|
const identityContractNonce = BigInt(1);
|
|
93
|
+
const document = sdk.documents.create(dataContract, documentType, data, identity, identityContractNonce);
|
|
94
94
|
const tokenPaymentInfo = {
|
|
95
95
|
tokenContractId: '6hVQW16jyvZyGSQk2YVty4ND6bgFXozizYWnPt753uW5',
|
|
96
96
|
tokenContractPosition: 0,
|
|
@@ -102,34 +102,34 @@ describe('Document', () => {
|
|
|
102
102
|
expect(stateTransition).toEqual(expect.any(StateTransitionWASM));
|
|
103
103
|
});
|
|
104
104
|
test('should be able to create a replace transition', async () => {
|
|
105
|
-
const document = sdk.documents.create(dataContract, documentType, data, identity, revision + BigInt(1));
|
|
106
105
|
const identityContractNonce = BigInt(1);
|
|
106
|
+
const document = sdk.documents.create(dataContract, documentType, data, identity, identityContractNonce, revision + BigInt(1));
|
|
107
107
|
const stateTransition = sdk.documents.createStateTransition(document, 'replace', { identityContractNonce });
|
|
108
108
|
expect(stateTransition).toEqual(expect.any(StateTransitionWASM));
|
|
109
109
|
});
|
|
110
110
|
test('should be able to create a delete transition', async () => {
|
|
111
|
-
const document = sdk.documents.create(dataContract, documentType, data, identity, revision + BigInt(1));
|
|
112
111
|
const identityContractNonce = BigInt(1);
|
|
112
|
+
const document = sdk.documents.create(dataContract, documentType, data, identity, identityContractNonce, revision + BigInt(1));
|
|
113
113
|
const stateTransition = sdk.documents.createStateTransition(document, 'delete', { identityContractNonce });
|
|
114
114
|
expect(stateTransition).toEqual(expect.any(StateTransitionWASM));
|
|
115
115
|
});
|
|
116
116
|
test('should be able to create a transfer transition', async () => {
|
|
117
|
-
const document = sdk.documents.create(dataContract, documentType, data, identity, revision + BigInt(1));
|
|
118
117
|
const identityContractNonce = BigInt(1);
|
|
118
|
+
const document = sdk.documents.create(dataContract, documentType, data, identity, identityContractNonce, revision + BigInt(1));
|
|
119
119
|
const recipientId = '6hVQW16jyvZyGSQk2YVty4ND6bgFXozizYWnPt753uW5';
|
|
120
120
|
const stateTransition = sdk.documents.createStateTransition(document, 'transfer', { identityContractNonce, recipientId });
|
|
121
121
|
expect(stateTransition).toEqual(expect.any(StateTransitionWASM));
|
|
122
122
|
});
|
|
123
123
|
test('should be able to create an updatePrice transition', async () => {
|
|
124
|
-
const document = sdk.documents.create(dataContract, documentType, data, identity, revision + BigInt(1));
|
|
125
124
|
const identityContractNonce = BigInt(1);
|
|
125
|
+
const document = sdk.documents.create(dataContract, documentType, data, identity, identityContractNonce, revision + BigInt(1));
|
|
126
126
|
const price = BigInt(10000000);
|
|
127
127
|
const stateTransition = sdk.documents.createStateTransition(document, 'updatePrice', { identityContractNonce, price });
|
|
128
128
|
expect(stateTransition).toEqual(expect.any(StateTransitionWASM));
|
|
129
129
|
});
|
|
130
130
|
test('should be able to create a purchase transition', async () => {
|
|
131
|
-
const document = sdk.documents.create(dataContract, documentType, data, identity, revision + BigInt(1));
|
|
132
131
|
const identityContractNonce = BigInt(1);
|
|
132
|
+
const document = sdk.documents.create(dataContract, documentType, data, identity, identityContractNonce, revision + BigInt(1));
|
|
133
133
|
const amount = BigInt(10000000);
|
|
134
134
|
const stateTransition = sdk.documents.createStateTransition(document, 'purchase', { identityContractNonce, amount });
|
|
135
135
|
expect(stateTransition).toEqual(expect.any(StateTransitionWASM));
|
|
@@ -70,14 +70,14 @@ describe('Document action fees', () => {
|
|
|
70
70
|
expect(agreement.verify(multipliedContract, 'note', 'Purchase', 1000n)).toEqual(false);
|
|
71
71
|
});
|
|
72
72
|
test('should be able to create a transition with an agreement', () => {
|
|
73
|
-
const document = sdk.documents.create(fixedContract.id, 'note', { message: 'hello' }, owner);
|
|
73
|
+
const document = sdk.documents.create(fixedContract.id, 'note', { message: 'hello' }, owner, 1n);
|
|
74
74
|
const feeMultiplier = new AgreedFeeMultiplierWASM(1000n, 0);
|
|
75
75
|
const actionFeeAgreement = DocumentActionFeeAgreementWASM.forDocumentTypeAction(fixedContract, 'note', 'Create', feeMultiplier);
|
|
76
76
|
const stateTransition = sdk.documents.createStateTransition(document, 'create', { identityContractNonce: 1n, actionFeeAgreement });
|
|
77
77
|
expect(agreementOf(stateTransition)?.owner).toEqual(10000000n);
|
|
78
78
|
});
|
|
79
79
|
test('should be able to create a transition with an agreement as a plain object', () => {
|
|
80
|
-
const document = sdk.documents.create(multipliedContract.id, 'note', { message: 'hello' }, owner);
|
|
80
|
+
const document = sdk.documents.create(multipliedContract.id, 'note', { message: 'hello' }, owner, 1n);
|
|
81
81
|
const stateTransition = sdk.documents.createStateTransition(document, 'create', {
|
|
82
82
|
identityContractNonce: 1n,
|
|
83
83
|
actionFeeAgreement: {
|
package/test/unit/Names.spec.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import broadcast from '../../src/stateTransitions/broadcast.js';
|
|
2
|
+
import waitForStateTransitionResult from '../../src/stateTransitions/waitForStateTransitionResult.js';
|
|
2
3
|
import { DocumentWASM, PrivateKeyWASM } from 'pshenmic-dpp';
|
|
3
4
|
import { DashPlatformSDK } from '../../src/DashPlatformSDK.js';
|
|
4
5
|
import sleep from '../../src/utils/sleep.js';
|
|
@@ -32,4 +33,33 @@ describe('DPNS names', () => {
|
|
|
32
33
|
await sdk.names.registerName(fullName, identityId, privateKey);
|
|
33
34
|
expect(broadcast).toHaveBeenCalledTimes(2);
|
|
34
35
|
});
|
|
36
|
+
test('should be able to register a name with existing preorder salt', async () => {
|
|
37
|
+
const fullName = 'test-identity-050.dash';
|
|
38
|
+
const identityId = 'CKKYnVeKoxCbvuEhiT6MDoQaRyXgDECwtxoKL5cqucZE';
|
|
39
|
+
const privateKey = PrivateKeyWASM.fromWIF('XERm528aQWJ3hzEcb79KMQKewbSSJQtni3fWHbu75wDxg6xg6AA3');
|
|
40
|
+
const preorderSalt = new Uint8Array(32).fill(1);
|
|
41
|
+
jest.mocked(broadcast).mockClear();
|
|
42
|
+
const salt = await sdk.names.registerName(fullName, identityId, privateKey, preorderSalt);
|
|
43
|
+
expect(salt).toEqual(preorderSalt);
|
|
44
|
+
expect(broadcast).toHaveBeenCalledTimes(1);
|
|
45
|
+
});
|
|
46
|
+
test('should expose preorder salt in error if preorder confirmation fails', async () => {
|
|
47
|
+
const fullName = 'test-identity-050.dash';
|
|
48
|
+
const identityId = 'CKKYnVeKoxCbvuEhiT6MDoQaRyXgDECwtxoKL5cqucZE';
|
|
49
|
+
const privateKey = PrivateKeyWASM.fromWIF('XERm528aQWJ3hzEcb79KMQKewbSSJQtni3fWHbu75wDxg6xg6AA3');
|
|
50
|
+
jest.mocked(waitForStateTransitionResult).mockRejectedValueOnce(new Error('Timeout'));
|
|
51
|
+
const error = await sdk.names.registerName(fullName, identityId, privateKey).catch(e => e);
|
|
52
|
+
expect(error.message).toEqual('Timeout');
|
|
53
|
+
expect(error.preorderSalt).toBeInstanceOf(Uint8Array);
|
|
54
|
+
expect(error.preorderSalt.length).toEqual(32);
|
|
55
|
+
});
|
|
56
|
+
test('should not expose preorder salt in error if preorder broadcast is refused', async () => {
|
|
57
|
+
const fullName = 'test-identity-050.dash';
|
|
58
|
+
const identityId = 'CKKYnVeKoxCbvuEhiT6MDoQaRyXgDECwtxoKL5cqucZE';
|
|
59
|
+
const privateKey = PrivateKeyWASM.fromWIF('XERm528aQWJ3hzEcb79KMQKewbSSJQtni3fWHbu75wDxg6xg6AA3');
|
|
60
|
+
jest.mocked(broadcast).mockRejectedValueOnce(new Error('Refused'));
|
|
61
|
+
const error = await sdk.names.registerName(fullName, identityId, privateKey).catch(e => e);
|
|
62
|
+
expect(error.message).toEqual('Refused');
|
|
63
|
+
expect(error.preorderSalt).toBeUndefined();
|
|
64
|
+
});
|
|
35
65
|
});
|
package/test/unit/Node.spec.js
CHANGED
|
@@ -26,14 +26,17 @@ describe('Node', () => {
|
|
|
26
26
|
expect(status.network?.chainId).toEqual(expect.any(String));
|
|
27
27
|
expect(status.network?.peersCount).toEqual(expect.any(Number));
|
|
28
28
|
expect(status.network?.listening).toEqual(expect.any(Boolean));
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
29
|
+
// rs-dapi (v5) returns state sync info only if tenderdash reports non-zero state sync counters
|
|
30
|
+
if (status.stateSync != null) {
|
|
31
|
+
expect(status.stateSync.totalSyncedTime).toEqual(expect.any(String));
|
|
32
|
+
expect(status.stateSync.remainingTime).toEqual(expect.any(String));
|
|
33
|
+
expect(status.stateSync.totalSnapshots).toEqual(expect.any(Number));
|
|
34
|
+
expect(status.stateSync.chunkProcessAvgTime).toEqual(expect.any(String));
|
|
35
|
+
expect(status.stateSync.snapshotHeight).toEqual(expect.any(String));
|
|
36
|
+
expect(status.stateSync.snapshotChunksCount).toEqual(expect.any(String));
|
|
37
|
+
expect(status.stateSync.backfilledBlocks).toEqual(expect.any(String));
|
|
38
|
+
expect(status.stateSync.backfillBlocksTotal).toEqual(expect.any(String));
|
|
39
|
+
}
|
|
37
40
|
expect(status.time?.local).toEqual(expect.any(String));
|
|
38
41
|
expect(status.time?.block).toEqual(expect.any(String));
|
|
39
42
|
expect(status.time?.genesis).toEqual(expect.any(String));
|
package/test/unit/SDK.spec.js
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
import { DashPlatformSDK } from '../../src/DashPlatformSDK.js';
|
|
2
|
+
import { PlatformExplorerQuorumKeyProvider } from '../../src/quorumKeyProvider.js';
|
|
2
3
|
let sdk;
|
|
4
|
+
const identifier = 'QMfCRPcjXoTnZa9sA9JR2KWgGxZXMRJ4akgS3Uia1Qv';
|
|
5
|
+
// takes quorum public keys from DAPI validator sets, so proofs can be verified without Platform Explorer
|
|
6
|
+
const createQuorumKeyProvider = (sdk) => {
|
|
7
|
+
const requests = [];
|
|
8
|
+
return {
|
|
9
|
+
requests,
|
|
10
|
+
getQuorumPublicKey: async (quorumType, quorumHash) => {
|
|
11
|
+
requests.push(quorumHash);
|
|
12
|
+
const { validatorSets } = await sdk.node.getCurrentQuorumsInfo();
|
|
13
|
+
const validatorSet = validatorSets.find(validatorSet => validatorSet.quorumHash === quorumHash);
|
|
14
|
+
if (validatorSet == null) {
|
|
15
|
+
throw new Error(`Unknown quorum ${quorumHash}`);
|
|
16
|
+
}
|
|
17
|
+
return validatorSet.thresholdPublicKey;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
};
|
|
3
21
|
describe('DashPlatformSDK', () => {
|
|
4
22
|
beforeAll(() => {
|
|
5
23
|
sdk = new DashPlatformSDK({ network: 'testnet' });
|
|
@@ -7,6 +25,30 @@ describe('DashPlatformSDK', () => {
|
|
|
7
25
|
test('should be constructable throw `new`', () => {
|
|
8
26
|
expect(sdk).toEqual(expect.any(DashPlatformSDK));
|
|
9
27
|
});
|
|
28
|
+
test('should use Platform Explorer quorum key provider by default', () => {
|
|
29
|
+
expect(sdk.quorumKeyProvider).toEqual(expect.any(PlatformExplorerQuorumKeyProvider));
|
|
30
|
+
});
|
|
31
|
+
test('should verify proofs with custom quorum key provider', async () => {
|
|
32
|
+
const customSdk = new DashPlatformSDK({ network: 'testnet' });
|
|
33
|
+
const quorumKeyProvider = createQuorumKeyProvider(customSdk);
|
|
34
|
+
customSdk.setQuorumKeyProvider(quorumKeyProvider);
|
|
35
|
+
const balance = await customSdk.identities.getIdentityBalance(identifier);
|
|
36
|
+
expect(balance).toEqual(expect.any(BigInt));
|
|
37
|
+
expect(quorumKeyProvider.requests).toHaveLength(1);
|
|
38
|
+
});
|
|
39
|
+
test('should not share quorum key provider between instances', () => {
|
|
40
|
+
const quorumKeyProvider = createQuorumKeyProvider(sdk);
|
|
41
|
+
const customSdk = new DashPlatformSDK({ network: 'testnet', quorumKeyProvider });
|
|
42
|
+
const defaultSdk = new DashPlatformSDK({ network: 'testnet' });
|
|
43
|
+
expect(customSdk.quorumKeyProvider).toBe(quorumKeyProvider);
|
|
44
|
+
expect(defaultSdk.quorumKeyProvider).toEqual(expect.any(PlatformExplorerQuorumKeyProvider));
|
|
45
|
+
expect(defaultSdk.quorumKeyProvider).not.toBe(sdk.quorumKeyProvider);
|
|
46
|
+
});
|
|
47
|
+
test('should switch back to Platform Explorer quorum key provider', () => {
|
|
48
|
+
const customSdk = new DashPlatformSDK({ network: 'testnet', quorumKeyProvider: createQuorumKeyProvider(sdk) });
|
|
49
|
+
customSdk.setQuorumKeyProvider();
|
|
50
|
+
expect(customSdk.quorumKeyProvider).toEqual(expect.any(PlatformExplorerQuorumKeyProvider));
|
|
51
|
+
});
|
|
10
52
|
test('should be able to deserialize consensus error', () => {
|
|
11
53
|
const err = sdk.utils.deserializeConsensusError('AwIiSW52YWxpZCBTdGF0ZSBUcmFuc2l0aW9uIHNpZ25hdHVyZQ');
|
|
12
54
|
expect(err).toEqual('Invalid State Transition signature');
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function getQuorumPublicKey(network: string, quorumType: number, quorumHash: string): Promise<string>;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { fetchWithDetails } from './fetchWithDetails.js';
|
|
2
|
-
const cache = {};
|
|
3
|
-
export async function getQuorumPublicKey(network, quorumType, quorumHash) {
|
|
4
|
-
const cached = cache[`${quorumType}_${quorumHash}`];
|
|
5
|
-
if (cached != null) {
|
|
6
|
-
return cached;
|
|
7
|
-
}
|
|
8
|
-
const url = `https://${network === 'mainnet' ? '' : 'testnet.'}platform-explorer.pshenmic.dev/quorum/info?quorumType=${quorumType}&quorumHash=${quorumHash}`;
|
|
9
|
-
const resp = await fetchWithDetails(url, {
|
|
10
|
-
method: 'GET'
|
|
11
|
-
});
|
|
12
|
-
if (resp.status !== 200) {
|
|
13
|
-
throw new Error('Failed to query Platform Explorer for quorum public keys');
|
|
14
|
-
}
|
|
15
|
-
const data = await resp.json();
|
|
16
|
-
const { quorumPublicKey } = data;
|
|
17
|
-
cache[`${quorumType}_${quorumHash}`] = quorumPublicKey;
|
|
18
|
-
return quorumPublicKey;
|
|
19
|
-
}
|