dash-platform-sdk 1.4.0-dev.1 → 1.4.0-dev.11
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/bundle.min.js +17 -17
- package/package.json +2 -2
- package/proto/generated/platform.client.d.ts +20 -0
- package/proto/generated/platform.client.js +14 -0
- package/proto/generated/platform.d.ts +293 -0
- package/proto/generated/platform.js +603 -1
- package/src/DashPlatformSDK.d.ts +3 -1
- package/src/DashPlatformSDK.js +8 -5
- package/src/contestedResources/getContestedResourceVoteState.js +1 -1
- package/src/dataContracts/create.d.ts +2 -2
- package/src/dataContracts/getDataContractByIdentifier.d.ts +1 -2
- package/src/dataContracts/index.d.ts +2 -2
- package/src/documents/create.d.ts +1 -2
- package/src/documents/index.d.ts +2 -2
- package/src/documents/index.js +1 -1
- package/src/documents/query.d.ts +1 -2
- package/src/documents/query.js +4 -6
- package/src/identities/getIdentityBalance.d.ts +1 -1
- package/src/identities/getIdentityByIdentifier.d.ts +1 -2
- package/src/identities/getIdentityContractNonce.d.ts +1 -1
- package/src/identities/getIdentityNonce.d.ts +1 -1
- package/src/identities/getIdentityPublicKeys.d.ts +1 -2
- package/src/identities/index.d.ts +2 -2
- package/src/names/index.d.ts +1 -2
- package/src/node/index.d.ts +2 -3
- package/src/node/index.js +2 -4
- package/src/node/totalCredits.d.ts +1 -2
- package/src/node/totalCredits.js +2 -2
- package/src/platformAddresses/getAddressInfo.d.ts +4 -0
- package/src/platformAddresses/getAddressInfo.js +45 -0
- package/src/platformAddresses/getAddressesInfos.d.ts +4 -0
- package/src/platformAddresses/getAddressesInfos.js +43 -0
- package/src/platformAddresses/index.d.ts +22 -0
- package/src/platformAddresses/index.js +27 -0
- package/src/stateTransitions/broadcast.js +17 -6
- package/src/tokens/getIdentitiesTokenBalances.d.ts +1 -2
- package/src/tokens/getIdentityTokensBalances.d.ts +1 -2
- package/src/tokens/getTokenContractInfo.d.ts +1 -2
- package/src/tokens/getTokenDirectPurchasePrices.d.ts +2 -1
- package/src/tokens/getTokenTotalSupply.d.ts +2 -1
- package/src/tokens/index.d.ts +2 -2
- package/src/utils/deserializeConsensusError.d.ts +1 -0
- package/src/utils/deserializeConsensusError.js +17 -0
- package/src/utils/index.d.ts +8 -2
- package/src/utils/index.js +10 -0
- package/src/voting/index.d.ts +2 -2
- package/test/unit/Document.spec.js +29 -0
- package/test/unit/PlatformAddress.spec.d.ts +1 -0
- package/test/unit/PlatformAddress.spec.js +22 -0
- package/test/unit/SDK.spec.js +4 -0
- package/types.d.ts +7 -3
package/src/DashPlatformSDK.js
CHANGED
|
@@ -10,6 +10,7 @@ import { DataContractsController } from './dataContracts/index.js';
|
|
|
10
10
|
import { ContestedResourcesController } from './contestedResources/index.js';
|
|
11
11
|
import { TokensController } from './tokens/index.js';
|
|
12
12
|
import { VotingController } from './voting/index.js';
|
|
13
|
+
import { PlatformAddressesController } from './platformAddresses/index.js';
|
|
13
14
|
/**
|
|
14
15
|
* Javascript SDK for that let you interact with a Dash Platform blockchain
|
|
15
16
|
*/
|
|
@@ -20,6 +21,7 @@ export class DashPlatformSDK {
|
|
|
20
21
|
/** @ignore **/
|
|
21
22
|
options;
|
|
22
23
|
contestedResources;
|
|
24
|
+
platformAddresses;
|
|
23
25
|
stateTransitions;
|
|
24
26
|
dataContracts;
|
|
25
27
|
identities;
|
|
@@ -49,7 +51,7 @@ export class DashPlatformSDK {
|
|
|
49
51
|
this.options.grpc = { dapiUrl: options.dapiUrl };
|
|
50
52
|
}
|
|
51
53
|
this.grpcPool = new GRPCConnectionPool(this.network, this.options?.grpc);
|
|
52
|
-
this._initialize(this.grpcPool
|
|
54
|
+
this._initialize(this.grpcPool);
|
|
53
55
|
}
|
|
54
56
|
/**
|
|
55
57
|
* @private
|
|
@@ -59,15 +61,16 @@ export class DashPlatformSDK {
|
|
|
59
61
|
* @param grpcPool
|
|
60
62
|
* @param network
|
|
61
63
|
*/
|
|
62
|
-
_initialize(grpcPool
|
|
64
|
+
_initialize(grpcPool) {
|
|
63
65
|
this.grpcPool = grpcPool;
|
|
64
|
-
this.stateTransitions = new StateTransitionsController(grpcPool);
|
|
65
66
|
this.contestedResources = new ContestedResourcesController(grpcPool);
|
|
67
|
+
this.platformAddresses = new PlatformAddressesController(grpcPool);
|
|
68
|
+
this.stateTransitions = new StateTransitionsController(grpcPool);
|
|
66
69
|
this.dataContracts = new DataContractsController(grpcPool);
|
|
67
70
|
this.identities = new IdentitiesController(grpcPool);
|
|
68
71
|
this.documents = new DocumentsController(grpcPool);
|
|
69
72
|
this.voting = new VotingController();
|
|
70
|
-
this.node = new NodeController(grpcPool
|
|
73
|
+
this.node = new NodeController(grpcPool);
|
|
71
74
|
this.tokens = new TokensController(grpcPool);
|
|
72
75
|
this.names = new NamesController(grpcPool);
|
|
73
76
|
this.keyPair = new KeyPairController();
|
|
@@ -91,6 +94,6 @@ export class DashPlatformSDK {
|
|
|
91
94
|
}
|
|
92
95
|
this.network = network;
|
|
93
96
|
const grpcPool = new GRPCConnectionPool(this.network, this.options?.grpc);
|
|
94
|
-
this._initialize(grpcPool
|
|
97
|
+
this._initialize(grpcPool);
|
|
95
98
|
}
|
|
96
99
|
}
|
|
@@ -66,7 +66,7 @@ export default async function getContestedResourceVoteState(grpcPool, contract,
|
|
|
66
66
|
finishedVoteInfo: (winner != null)
|
|
67
67
|
? {
|
|
68
68
|
type: winner.type,
|
|
69
|
-
wonByIdentityId: 'identityId' in winner ? new IdentifierWASM(winner.identityId) : undefined,
|
|
69
|
+
wonByIdentityId: 'identityId' in winner && winner.identityId != null ? new IdentifierWASM(winner.identityId) : undefined,
|
|
70
70
|
finishedAtBlockHeight: winner.blockInfo.height,
|
|
71
71
|
finishedAtCoreBlockHeight: winner.blockInfo.coreHeight,
|
|
72
72
|
finishedAtBlockTimeMs: winner.blockInfo.timeMs,
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { DataContractTokens, DataContractWASM, PlatformVersionWASM } from 'pshenmic-dpp';
|
|
2
|
-
import { DataContractConfig
|
|
1
|
+
import { DataContractTokens, DataContractWASM, IdentifierLike, PlatformVersionWASM } from 'pshenmic-dpp';
|
|
2
|
+
import { DataContractConfig } from '../../types.js';
|
|
3
3
|
export default function createDataContract(ownerId: IdentifierLike, identityNonce: bigint, schema: object, tokenConfiguration?: DataContractTokens[], config?: DataContractConfig, fullValidation?: boolean | undefined, platformVersion?: PlatformVersionWASM | undefined): DataContractWASM;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { DataContractWASM } from 'pshenmic-dpp';
|
|
2
|
-
import { IdentifierLike } from '../../types.js';
|
|
1
|
+
import { DataContractWASM, IdentifierLike } from 'pshenmic-dpp';
|
|
3
2
|
import GRPCConnectionPool from '../grpcConnectionPool.js';
|
|
4
3
|
export default function getByIdentifier(grpcPool: GRPCConnectionPool, identifier: IdentifierLike): Promise<DataContractWASM>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { DataContractTokens, DataContractWASM, PlatformVersionWASM, StateTransitionWASM } from 'pshenmic-dpp';
|
|
1
|
+
import { DataContractTokens, DataContractWASM, IdentifierLike, PlatformVersionWASM, StateTransitionWASM } from 'pshenmic-dpp';
|
|
3
2
|
import GRPCConnectionPool from '../grpcConnectionPool.js';
|
|
3
|
+
import { DataContractConfig } from '../../types.js';
|
|
4
4
|
/**
|
|
5
5
|
* Collection of methods necessary to work with Data Contracts in the network,
|
|
6
6
|
* such as data contract creation or retrieval
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import { DocumentWASM } from 'pshenmic-dpp';
|
|
2
|
-
import { IdentifierLike } from '../../types.js';
|
|
1
|
+
import { DocumentWASM, IdentifierLike } from 'pshenmic-dpp';
|
|
3
2
|
export default function createDocument(dataContractId: IdentifierLike, documentType: string, data: object, owner: IdentifierLike, revision?: bigint, documentId?: IdentifierLike): DocumentWASM;
|
package/src/documents/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DocumentTransitionParams
|
|
2
|
-
import { DocumentWASM, IdentifierWASM, StateTransitionWASM, WhereClause } from 'pshenmic-dpp';
|
|
1
|
+
import { DocumentTransitionParams } from '../../types.js';
|
|
2
|
+
import { DocumentWASM, IdentifierLike, IdentifierWASM, StateTransitionWASM, WhereClause } from 'pshenmic-dpp';
|
|
3
3
|
import GRPCConnectionPool from '../grpcConnectionPool.js';
|
|
4
4
|
/**
|
|
5
5
|
* Collection of methods to work with documents like creation, querying or preparing a transition action
|
package/src/documents/index.js
CHANGED
|
@@ -39,7 +39,7 @@ export class DocumentsController {
|
|
|
39
39
|
* @param startAfter {IdentifierLike=} Same as previous, but with exclusion. Cannot be set if startAt already provided
|
|
40
40
|
*/
|
|
41
41
|
async query(dataContractId, documentType, where, orderBy, limit, startAt, startAfter) {
|
|
42
|
-
if (startAfter != null && startAt
|
|
42
|
+
if (startAfter != null && startAt != null) {
|
|
43
43
|
throw new Error('You may only set either startAfter or startAt at once');
|
|
44
44
|
}
|
|
45
45
|
return await query(this.grpcPool, new IdentifierWASM(dataContractId), documentType, where, orderBy, limit ?? 100, startAt, startAfter);
|
package/src/documents/query.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { DocumentWASM, IdentifierWASM, WhereClause } from 'pshenmic-dpp';
|
|
2
|
-
import { IdentifierLike } from '../../types.js';
|
|
1
|
+
import { DocumentWASM, IdentifierLike, IdentifierWASM, WhereClause } from 'pshenmic-dpp';
|
|
3
2
|
import GRPCConnectionPool from '../grpcConnectionPool.js';
|
|
4
3
|
export default function query(grpcPool: GRPCConnectionPool, dataContractId: IdentifierLike, documentTypeName: string, where?: WhereClause[], orderBy?: string[][], limit?: number | undefined, startAt?: IdentifierWASM, startAfter?: IdentifierWASM): Promise<DocumentWASM[]>;
|
package/src/documents/query.js
CHANGED
|
@@ -7,20 +7,17 @@ import verifyTenderdashProof from '../utils/verifyTenderdashProof.js';
|
|
|
7
7
|
import { encode } from 'cbor-x';
|
|
8
8
|
import getDataContractByIdentifier from '../dataContracts/getDataContractByIdentifier.js';
|
|
9
9
|
export default async function query(grpcPool, dataContractId, documentTypeName, where, orderBy, limit = 100, startAt, startAfter) {
|
|
10
|
-
if ([startAt, startAfter].filter(e => e != null).length === 2) {
|
|
11
|
-
throw new Error('Only startAt or startAfter could be specified at one time');
|
|
12
|
-
}
|
|
13
10
|
let start;
|
|
14
11
|
if (startAt != null) {
|
|
15
12
|
start = {
|
|
16
13
|
oneofKind: 'startAt',
|
|
17
|
-
startAt: startAt.
|
|
14
|
+
startAt: startAt.bytes()
|
|
18
15
|
};
|
|
19
16
|
}
|
|
20
17
|
if (startAfter != null) {
|
|
21
18
|
start = {
|
|
22
19
|
oneofKind: 'startAfter',
|
|
23
|
-
|
|
20
|
+
startAfter: startAfter.bytes()
|
|
24
21
|
};
|
|
25
22
|
}
|
|
26
23
|
const getDocumentsRequest = GetDocumentsRequest.create({
|
|
@@ -52,7 +49,8 @@ export default async function query(grpcPool, dataContractId, documentTypeName,
|
|
|
52
49
|
throw new Error('Metadata not found');
|
|
53
50
|
}
|
|
54
51
|
const startAtIncluded = startAt != null;
|
|
55
|
-
const
|
|
52
|
+
const startIdentifier = startAt ?? startAfter;
|
|
53
|
+
const { rootHash, documents } = verifyDocumentsProof(proof.grovedbProof, dataContract, documentTypeName, where, orderBy, limit, startIdentifier?.bytes(), startAtIncluded, BigInt(metadata?.timeMs), LATEST_PLATFORM_VERSION);
|
|
56
54
|
const quorumPublicKey = await getQuorumPublicKey(grpcPool.network, proof.quorumType, bytesToHex(proof.quorumHash));
|
|
57
55
|
const verify = await verifyTenderdashProof(proof, metadata, rootHash, quorumPublicKey);
|
|
58
56
|
if (!verify) {
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { IdentifierLike } from '
|
|
1
|
+
import { IdentifierLike } from 'pshenmic-dpp';
|
|
2
2
|
import GRPCConnectionPool from '../grpcConnectionPool.js';
|
|
3
3
|
export default function getIdentityBalance(grpcPool: GRPCConnectionPool, identifier: IdentifierLike): Promise<bigint>;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { IdentityWASM } from 'pshenmic-dpp';
|
|
2
|
-
import { IdentifierLike } from '../../types.js';
|
|
1
|
+
import { IdentifierLike, IdentityWASM } from 'pshenmic-dpp';
|
|
3
2
|
import GRPCConnectionPool from '../grpcConnectionPool.js';
|
|
4
3
|
export default function getIdentityByIdentifier(grpcPool: GRPCConnectionPool, identifier: IdentifierLike): Promise<IdentityWASM>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { IdentifierLike } from '
|
|
1
|
+
import { IdentifierLike } from 'pshenmic-dpp';
|
|
2
2
|
import GRPCConnectionPool from '../grpcConnectionPool.js';
|
|
3
3
|
export default function getIdentityContractNonce(grpcPool: GRPCConnectionPool, identity: IdentifierLike, dataContract: IdentifierLike): Promise<bigint>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { IdentifierLike } from '
|
|
1
|
+
import { IdentifierLike } from 'pshenmic-dpp';
|
|
2
2
|
import GRPCConnectionPool from '../grpcConnectionPool.js';
|
|
3
3
|
export default function getIdentityNonce(grpcPool: GRPCConnectionPool, identifier: IdentifierLike): Promise<bigint>;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { IdentityPublicKeyWASM } from 'pshenmic-dpp';
|
|
2
|
-
import { IdentifierLike } from '../../types.js';
|
|
1
|
+
import { IdentifierLike, IdentityPublicKeyWASM } from 'pshenmic-dpp';
|
|
3
2
|
import GRPCConnectionPool from '../grpcConnectionPool.js';
|
|
4
3
|
export default function getIdentityPublicKeys(grpcPool: GRPCConnectionPool, identifier: IdentifierLike, keyIds?: number[]): Promise<IdentityPublicKeyWASM[]>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IdentityTransitionParams } from '../../types.js';
|
|
2
2
|
import GRPCConnectionPool from '../grpcConnectionPool.js';
|
|
3
|
-
import { IdentityPublicKeyWASM, IdentityWASM, StateTransitionWASM } from 'pshenmic-dpp';
|
|
3
|
+
import { IdentifierLike, IdentityPublicKeyWASM, IdentityWASM, StateTransitionWASM } from 'pshenmic-dpp';
|
|
4
4
|
/**
|
|
5
5
|
* Collection of methods to query identities and its related data
|
|
6
6
|
*
|
package/src/names/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import GRPCConnectionPool from '../grpcConnectionPool.js';
|
|
2
|
-
import { DocumentWASM, PrivateKeyWASM } from 'pshenmic-dpp';
|
|
3
|
-
import { IdentifierLike } from '../../types.js';
|
|
2
|
+
import { DocumentWASM, IdentifierLike, PrivateKeyWASM } from 'pshenmic-dpp';
|
|
4
3
|
/**
|
|
5
4
|
* Functions related to DPNS names (usernames)
|
|
6
5
|
*
|
package/src/node/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import GRPCConnectionPool from '../grpcConnectionPool.js';
|
|
2
|
-
import {
|
|
2
|
+
import { NodeStatus } from '../../types.js';
|
|
3
3
|
import { EpochInfo } from './epochs.js';
|
|
4
4
|
/**
|
|
5
5
|
* Node controller for requesting information about DAPI node
|
|
@@ -9,8 +9,7 @@ import { EpochInfo } from './epochs.js';
|
|
|
9
9
|
export declare class NodeController {
|
|
10
10
|
/** @ignore **/
|
|
11
11
|
grpcPool: GRPCConnectionPool;
|
|
12
|
-
|
|
13
|
-
constructor(grpcPool: GRPCConnectionPool, network: Network);
|
|
12
|
+
constructor(grpcPool: GRPCConnectionPool);
|
|
14
13
|
/**
|
|
15
14
|
* Retrieves an info about node
|
|
16
15
|
* Includes information about genesis, chain, software versions
|
package/src/node/index.js
CHANGED
|
@@ -9,10 +9,8 @@ import getTotalCredits from './totalCredits.js';
|
|
|
9
9
|
export class NodeController {
|
|
10
10
|
/** @ignore **/
|
|
11
11
|
grpcPool;
|
|
12
|
-
|
|
13
|
-
constructor(grpcPool, network) {
|
|
12
|
+
constructor(grpcPool) {
|
|
14
13
|
this.grpcPool = grpcPool;
|
|
15
|
-
this.network = network;
|
|
16
14
|
}
|
|
17
15
|
/**
|
|
18
16
|
* Retrieves an info about node
|
|
@@ -29,7 +27,7 @@ export class NodeController {
|
|
|
29
27
|
* @return {Promise<bigint>}
|
|
30
28
|
*/
|
|
31
29
|
async totalCredits() {
|
|
32
|
-
return await getTotalCredits(this.grpcPool
|
|
30
|
+
return await getTotalCredits(this.grpcPool);
|
|
33
31
|
}
|
|
34
32
|
/**
|
|
35
33
|
* Retrieves an info about epochs
|
|
@@ -1,3 +1,2 @@
|
|
|
1
1
|
import GRPCConnectionPool from '../grpcConnectionPool.js';
|
|
2
|
-
|
|
3
|
-
export default function totalCredits(grpcPool: GRPCConnectionPool, network: Network): Promise<bigint>;
|
|
2
|
+
export default function totalCredits(grpcPool: GRPCConnectionPool): Promise<bigint>;
|
package/src/node/totalCredits.js
CHANGED
|
@@ -4,7 +4,7 @@ import { verifyTotalCreditsProof } from 'pshenmic-dpp';
|
|
|
4
4
|
import { getQuorumPublicKey } from '../utils/getQuorumPublicKey.js';
|
|
5
5
|
import bytesToHex from '../utils/bytesToHex.js';
|
|
6
6
|
import verifyTenderdashProof from '../utils/verifyTenderdashProof.js';
|
|
7
|
-
export default async function totalCredits(grpcPool
|
|
7
|
+
export default async function totalCredits(grpcPool) {
|
|
8
8
|
const getTotalCreditsInPlatformRequest = GetTotalCreditsInPlatformRequest.create({
|
|
9
9
|
version: {
|
|
10
10
|
oneofKind: 'v0',
|
|
@@ -24,7 +24,7 @@ export default async function totalCredits(grpcPool, network) {
|
|
|
24
24
|
if (metadata == null) {
|
|
25
25
|
throw new Error('Metadata not found');
|
|
26
26
|
}
|
|
27
|
-
const activationHeight = network === 'testnet' ? TESTNET_ACTIVATION_HEIGHT : MAINNET_ACTIVATION_HEIGHT;
|
|
27
|
+
const activationHeight = grpcPool.network === 'testnet' ? TESTNET_ACTIVATION_HEIGHT : MAINNET_ACTIVATION_HEIGHT;
|
|
28
28
|
const { rootHash, totalCredits } = verifyTotalCreditsProof(proof.grovedbProof, HALVING_INTERVAL, activationHeight, Number(metadata.height), LATEST_PLATFORM_VERSION);
|
|
29
29
|
const quorumPublicKey = await getQuorumPublicKey(grpcPool.network, proof.quorumType, bytesToHex(proof.quorumHash));
|
|
30
30
|
const verify = await verifyTenderdashProof(proof, metadata, rootHash, quorumPublicKey);
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import GRPCConnectionPool from '../grpcConnectionPool.js';
|
|
2
|
+
import { PlatformAddressLike } from 'pshenmic-dpp';
|
|
3
|
+
import { PlatformAddressInfo } from '../../types.js';
|
|
4
|
+
export declare function getAddressInfo(grpcPool: GRPCConnectionPool, platformAddress: PlatformAddressLike): Promise<PlatformAddressInfo>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { PlatformAddressWASM, verifyPlatformAddressInfo } from 'pshenmic-dpp';
|
|
2
|
+
import { GetAddressInfoRequest } from '../../proto/generated/platform.js';
|
|
3
|
+
import { LATEST_PLATFORM_VERSION } from '../constants.js';
|
|
4
|
+
import { getQuorumPublicKey } from '../utils/getQuorumPublicKey.js';
|
|
5
|
+
import bytesToHex from '../utils/bytesToHex.js';
|
|
6
|
+
import verifyTenderdashProof from '../utils/verifyTenderdashProof.js';
|
|
7
|
+
export async function getAddressInfo(grpcPool, platformAddress) {
|
|
8
|
+
const platformAddressWASM = new PlatformAddressWASM(platformAddress);
|
|
9
|
+
const getAddressInfoRequest = GetAddressInfoRequest.create({
|
|
10
|
+
version: {
|
|
11
|
+
oneofKind: 'v0',
|
|
12
|
+
v0: {
|
|
13
|
+
address: platformAddressWASM.bytes(),
|
|
14
|
+
prove: true
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
const { response } = await grpcPool.getClient().getAddressInfo(getAddressInfoRequest);
|
|
19
|
+
const { version } = response;
|
|
20
|
+
if (version.oneofKind !== 'v0') {
|
|
21
|
+
throw new Error('Unexpected oneOf type returned from DAPI (must be v0)');
|
|
22
|
+
}
|
|
23
|
+
const { v0 } = version;
|
|
24
|
+
if (v0.result.oneofKind !== 'proof') {
|
|
25
|
+
throw new Error('Unexpected oneOf type returned from DAPI (must be proof)');
|
|
26
|
+
}
|
|
27
|
+
const { result: { proof }, metadata } = v0;
|
|
28
|
+
if (metadata == null) {
|
|
29
|
+
throw new Error('Metadata not found');
|
|
30
|
+
}
|
|
31
|
+
const { rootHash, address, nonce, balance } = verifyPlatformAddressInfo(proof.grovedbProof, platformAddressWASM, true, LATEST_PLATFORM_VERSION);
|
|
32
|
+
if (address == null || nonce == null || balance == null) {
|
|
33
|
+
throw new Error(`Failed to fetch info for address ${platformAddressWASM.toBech32m(grpcPool.network)}`);
|
|
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
|
+
address,
|
|
42
|
+
nonce,
|
|
43
|
+
balance
|
|
44
|
+
};
|
|
45
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import GRPCConnectionPool from '../grpcConnectionPool.js';
|
|
2
|
+
import { PlatformAddressLike } from 'pshenmic-dpp';
|
|
3
|
+
import { PlatformAddressInfo } from '../../types.js';
|
|
4
|
+
export declare function getAddressesInfos(grpcPool: GRPCConnectionPool, platformAddresses: PlatformAddressLike[]): Promise<PlatformAddressInfo[]>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { PlatformAddressWASM, verifyPlatformAddressesInfos } from 'pshenmic-dpp';
|
|
2
|
+
import { GetAddressesInfosRequest } from '../../proto/generated/platform.js';
|
|
3
|
+
import { LATEST_PLATFORM_VERSION } from '../constants.js';
|
|
4
|
+
import { getQuorumPublicKey } from '../utils/getQuorumPublicKey.js';
|
|
5
|
+
import bytesToHex from '../utils/bytesToHex.js';
|
|
6
|
+
import verifyTenderdashProof from '../utils/verifyTenderdashProof.js';
|
|
7
|
+
export async function getAddressesInfos(grpcPool, platformAddresses) {
|
|
8
|
+
const platformAddressesWASM = platformAddresses.map(addr => new PlatformAddressWASM(addr));
|
|
9
|
+
const getAddressInfoRequest = GetAddressesInfosRequest.create({
|
|
10
|
+
version: {
|
|
11
|
+
oneofKind: 'v0',
|
|
12
|
+
v0: {
|
|
13
|
+
addresses: platformAddressesWASM.map(addr => addr.bytes()),
|
|
14
|
+
prove: true
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
const { response } = await grpcPool.getClient().getAddressesInfos(getAddressInfoRequest);
|
|
19
|
+
const { version } = response;
|
|
20
|
+
if (version.oneofKind !== 'v0') {
|
|
21
|
+
throw new Error('Unexpected oneOf type returned from DAPI (must be v0)');
|
|
22
|
+
}
|
|
23
|
+
const { v0 } = version;
|
|
24
|
+
if (v0.result.oneofKind !== 'proof') {
|
|
25
|
+
throw new Error('Unexpected oneOf type returned from DAPI (must be proof)');
|
|
26
|
+
}
|
|
27
|
+
const { result: { proof }, metadata } = v0;
|
|
28
|
+
if (metadata == null) {
|
|
29
|
+
throw new Error('Metadata not found');
|
|
30
|
+
}
|
|
31
|
+
const { rootHash, infos } = verifyPlatformAddressesInfos(proof.grovedbProof, platformAddressesWASM, true, LATEST_PLATFORM_VERSION);
|
|
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 infos
|
|
38
|
+
.map(info => ({
|
|
39
|
+
address: info.address,
|
|
40
|
+
nonce: info.nonce ?? 0,
|
|
41
|
+
balance: BigInt(info.balance ?? 0)
|
|
42
|
+
}));
|
|
43
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import GRPCConnectionPool from '../grpcConnectionPool.js';
|
|
2
|
+
import { PlatformAddressLike } from 'pshenmic-dpp';
|
|
3
|
+
import { PlatformAddressInfo } from '../../types.js';
|
|
4
|
+
export declare class PlatformAddressesController {
|
|
5
|
+
/** @ignore **/
|
|
6
|
+
grpcPool: GRPCConnectionPool;
|
|
7
|
+
constructor(grpcPool: GRPCConnectionPool);
|
|
8
|
+
/**
|
|
9
|
+
* Makes a query for platform address info, returns an object with address, balance and nonce
|
|
10
|
+
*
|
|
11
|
+
* @param address {PlatformAddressLike}
|
|
12
|
+
* @return {Promise<PlatformAddressInfo>}
|
|
13
|
+
*/
|
|
14
|
+
getAddressInfo(address: PlatformAddressLike): Promise<PlatformAddressInfo>;
|
|
15
|
+
/**
|
|
16
|
+
* Makes a query for platform addresses infos, returns array with an object with address, balance and nonce
|
|
17
|
+
*
|
|
18
|
+
* @param addresses {PlatformAddressLike[]}
|
|
19
|
+
* @return {Promise<PlatformAddressInfo[]>}
|
|
20
|
+
*/
|
|
21
|
+
getAddressesInfos(addresses: PlatformAddressLike[]): Promise<PlatformAddressInfo[]>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { getAddressInfo } from './getAddressInfo.js';
|
|
2
|
+
import { getAddressesInfos } from './getAddressesInfos.js';
|
|
3
|
+
export class PlatformAddressesController {
|
|
4
|
+
/** @ignore **/
|
|
5
|
+
grpcPool;
|
|
6
|
+
constructor(grpcPool) {
|
|
7
|
+
this.grpcPool = grpcPool;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Makes a query for platform address info, returns an object with address, balance and nonce
|
|
11
|
+
*
|
|
12
|
+
* @param address {PlatformAddressLike}
|
|
13
|
+
* @return {Promise<PlatformAddressInfo>}
|
|
14
|
+
*/
|
|
15
|
+
async getAddressInfo(address) {
|
|
16
|
+
return await getAddressInfo(this.grpcPool, address);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Makes a query for platform addresses infos, returns array with an object with address, balance and nonce
|
|
20
|
+
*
|
|
21
|
+
* @param addresses {PlatformAddressLike[]}
|
|
22
|
+
* @return {Promise<PlatformAddressInfo[]>}
|
|
23
|
+
*/
|
|
24
|
+
async getAddressesInfos(addresses) {
|
|
25
|
+
return await getAddressesInfos(this.grpcPool, addresses);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -1,10 +1,21 @@
|
|
|
1
1
|
import { BroadcastStateTransitionRequest } from '../../proto/generated/platform.js';
|
|
2
|
+
import { deserializeConsensusError } from '../utils/deserializeConsensusError.js';
|
|
2
3
|
export default async function broadcast(grpcPool, stateTransition) {
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
try {
|
|
5
|
+
if (stateTransition.signature?.length === 0) {
|
|
6
|
+
throw new Error('State Transition is not signed');
|
|
7
|
+
}
|
|
8
|
+
const broadcastStateTransitionRequest = BroadcastStateTransitionRequest.create({
|
|
9
|
+
stateTransition: stateTransition.bytes()
|
|
10
|
+
});
|
|
11
|
+
await grpcPool.getClient().broadcastStateTransition(broadcastStateTransitionRequest);
|
|
12
|
+
}
|
|
13
|
+
catch (err) {
|
|
14
|
+
if (err.meta?.['dash-serialized-consensus-error-bin']?.length !== 0) {
|
|
15
|
+
throw new Error(deserializeConsensusError(err.meta['dash-serialized-consensus-error-bin']));
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
throw err;
|
|
19
|
+
}
|
|
5
20
|
}
|
|
6
|
-
const broadcastStateTransitionRequest = BroadcastStateTransitionRequest.create({
|
|
7
|
-
stateTransition: stateTransition.bytes()
|
|
8
|
-
});
|
|
9
|
-
await grpcPool.getClient().broadcastStateTransition(broadcastStateTransitionRequest);
|
|
10
21
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import GRPCConnectionPool from '../grpcConnectionPool.js';
|
|
2
|
-
import { IdentifierLike } from '
|
|
3
|
-
import { IdentifierWASM } from 'pshenmic-dpp';
|
|
2
|
+
import { IdentifierLike, IdentifierWASM } from 'pshenmic-dpp';
|
|
4
3
|
export interface IdentitiesTokenBalances {
|
|
5
4
|
identityId: IdentifierWASM;
|
|
6
5
|
balance?: bigint | undefined;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import GRPCConnectionPool from '../grpcConnectionPool.js';
|
|
2
|
-
import { IdentifierLike } from '
|
|
3
|
-
import { IdentifierWASM } from 'pshenmic-dpp';
|
|
2
|
+
import { IdentifierLike, IdentifierWASM } from 'pshenmic-dpp';
|
|
4
3
|
export interface IdentityTokenBalances {
|
|
5
4
|
tokenId: IdentifierWASM;
|
|
6
5
|
balance?: bigint | undefined;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import GRPCConnectionPool from '../grpcConnectionPool.js';
|
|
2
|
-
import { IdentifierLike } from '
|
|
3
|
-
import { IdentifierWASM } from 'pshenmic-dpp';
|
|
2
|
+
import { IdentifierLike, IdentifierWASM } from 'pshenmic-dpp';
|
|
4
3
|
export interface TokenContractInfo {
|
|
5
4
|
dataContractId: IdentifierWASM;
|
|
6
5
|
tokenContractPosition: number;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import GRPCConnectionPool from '../grpcConnectionPool.js';
|
|
2
|
-
import {
|
|
2
|
+
import { TokenDirectPurchasePrices } from '../../types.js';
|
|
3
|
+
import { IdentifierLike } from 'pshenmic-dpp';
|
|
3
4
|
export default function getTokenDirectPurchasePrices(grpcPool: GRPCConnectionPool, tokenIdentifiers: IdentifierLike[]): Promise<TokenDirectPurchasePrices[]>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import GRPCConnectionPool from '../grpcConnectionPool.js';
|
|
2
|
-
import {
|
|
2
|
+
import { TokenTotalSupply } from '../../types.js';
|
|
3
|
+
import { IdentifierLike } from 'pshenmic-dpp';
|
|
3
4
|
export default function getTokenTotalSupply(grpcPool: GRPCConnectionPool, tokenIdentifier: IdentifierLike): Promise<TokenTotalSupply>;
|
package/src/tokens/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import GRPCConnectionPool from '../grpcConnectionPool.js';
|
|
2
|
-
import {
|
|
2
|
+
import { TokenDirectPurchasePrices, TokenTotalSupply, TokenTransitionParams, TokenTransitionType } from '../../types.js';
|
|
3
3
|
import { IdentitiesTokenBalances } from './getIdentitiesTokenBalances.js';
|
|
4
4
|
import { IdentityTokenBalances } from './getIdentityTokensBalances.js';
|
|
5
5
|
import { TokenContractInfo } from './getTokenContractInfo.js';
|
|
6
|
-
import { StateTransitionWASM, TokenBaseTransitionWASM } from 'pshenmic-dpp';
|
|
6
|
+
import { IdentifierLike, StateTransitionWASM, TokenBaseTransitionWASM } from 'pshenmic-dpp';
|
|
7
7
|
/**
|
|
8
8
|
* Tokens controller for requesting information about tokens and tokens holders
|
|
9
9
|
*
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function deserializeConsensusError(error: string | Uint8Array): string;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { base64 } from '@scure/base';
|
|
2
|
+
import { ConsensusErrorWASM } from 'pshenmic-dpp';
|
|
3
|
+
export function deserializeConsensusError(error) {
|
|
4
|
+
let normError;
|
|
5
|
+
if (typeof error === 'string') {
|
|
6
|
+
// @scure/base64 works only with padded base64, but cbor can return unpadded base64
|
|
7
|
+
const padding = error.length % 4;
|
|
8
|
+
if (padding !== 0) {
|
|
9
|
+
error += '='.repeat(4 - padding);
|
|
10
|
+
}
|
|
11
|
+
normError = base64.decode(error);
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
normError = error;
|
|
15
|
+
}
|
|
16
|
+
return ConsensusErrorWASM.deserialize(normError).message;
|
|
17
|
+
}
|
package/src/utils/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { IdentifierWASM } from 'pshenmic-dpp';
|
|
2
|
-
import { IdentifierLike } from '../../types.js';
|
|
1
|
+
import { IdentifierLike, IdentifierWASM } from 'pshenmic-dpp';
|
|
3
2
|
/**
|
|
4
3
|
* Collection of conversion functions
|
|
5
4
|
*
|
|
@@ -70,4 +69,11 @@ export declare class UtilsController {
|
|
|
70
69
|
* @return {boolean}
|
|
71
70
|
* */
|
|
72
71
|
validateIdentifier(identifier: IdentifierLike): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Allows to deserialize consensus error
|
|
74
|
+
*
|
|
75
|
+
* @param error {string | Uint8Array} error in base64 or bytes
|
|
76
|
+
* @return {string}
|
|
77
|
+
*/
|
|
78
|
+
deserializeConsensusError(error: string | Uint8Array): string;
|
|
73
79
|
}
|
package/src/utils/index.js
CHANGED
|
@@ -5,6 +5,7 @@ import bytesToHex from './bytesToHex.js';
|
|
|
5
5
|
import { createVoterIdentityId } from './createVoterIdentityId.js';
|
|
6
6
|
import { IdentifierWASM } from 'pshenmic-dpp';
|
|
7
7
|
import { createMasternodeIdentityId } from './createMasternodeIdentityId.js';
|
|
8
|
+
import { deserializeConsensusError } from './deserializeConsensusError.js';
|
|
8
9
|
/**
|
|
9
10
|
* Collection of conversion functions
|
|
10
11
|
*
|
|
@@ -98,4 +99,13 @@ export class UtilsController {
|
|
|
98
99
|
return false;
|
|
99
100
|
}
|
|
100
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Allows to deserialize consensus error
|
|
104
|
+
*
|
|
105
|
+
* @param error {string | Uint8Array} error in base64 or bytes
|
|
106
|
+
* @return {string}
|
|
107
|
+
*/
|
|
108
|
+
deserializeConsensusError(error) {
|
|
109
|
+
return deserializeConsensusError(error);
|
|
110
|
+
}
|
|
101
111
|
}
|
package/src/voting/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { IdentifierLike,
|
|
2
|
-
import {
|
|
1
|
+
import { IdentifierLike, IdentifierWASM, StateTransitionWASM, VoteWASM } from 'pshenmic-dpp';
|
|
2
|
+
import { ResourceVoteChoice } from '../../types.js';
|
|
3
3
|
/**
|
|
4
4
|
* Voting controller for performing masternode votes
|
|
5
5
|
*
|
|
@@ -42,6 +42,35 @@ describe('Document', () => {
|
|
|
42
42
|
expect(document.dataContractId.base58()).toEqual(dataContract);
|
|
43
43
|
expect(document).toEqual(expect.any(DocumentWASM));
|
|
44
44
|
});
|
|
45
|
+
test('should be able to get document with startAt', async () => {
|
|
46
|
+
const dataContract = '6hVQW16jyvZyGSQk2YVty4ND6bgFXozizYWnPt753uW5';
|
|
47
|
+
const documentType = 'torrent';
|
|
48
|
+
const limit = 5;
|
|
49
|
+
// @ts-expect-error
|
|
50
|
+
const [firstQueriedDoc] = (await sdk.documents.query(dataContract, documentType, null, null, limit)).toReversed();
|
|
51
|
+
// @ts-expect-error
|
|
52
|
+
const [secondQueriedDoc] = await sdk.documents.query(dataContract, documentType, null, null, limit, firstQueriedDoc.id);
|
|
53
|
+
expect(secondQueriedDoc.id.base58()).toEqual(firstQueriedDoc.id.base58());
|
|
54
|
+
expect(secondQueriedDoc.createdAtBlockHeight).toEqual(undefined);
|
|
55
|
+
expect(secondQueriedDoc.dataContractId.base58()).toEqual(dataContract);
|
|
56
|
+
expect(secondQueriedDoc).toEqual(expect.any(DocumentWASM));
|
|
57
|
+
});
|
|
58
|
+
test('should be able to get document with startAfter', async () => {
|
|
59
|
+
const dataContract = '6hVQW16jyvZyGSQk2YVty4ND6bgFXozizYWnPt753uW5';
|
|
60
|
+
const documentType = 'torrent';
|
|
61
|
+
const limit = 5;
|
|
62
|
+
const masterQueryLimit = limit * 2;
|
|
63
|
+
// @ts-expect-error
|
|
64
|
+
const masterQuery = await sdk.documents.query(dataContract, documentType, null, null, masterQueryLimit);
|
|
65
|
+
// @ts-expect-error
|
|
66
|
+
const [firstQueriedDoc] = (await sdk.documents.query(dataContract, documentType, null, null, limit)).toReversed();
|
|
67
|
+
// @ts-expect-error
|
|
68
|
+
const [secondQueriedDoc] = await sdk.documents.query(dataContract, documentType, null, null, limit, undefined, firstQueriedDoc.id);
|
|
69
|
+
expect(masterQuery[5].id.base58()).toEqual(secondQueriedDoc.id.base58());
|
|
70
|
+
expect(secondQueriedDoc.createdAtBlockHeight).toEqual(undefined);
|
|
71
|
+
expect(secondQueriedDoc.dataContractId.base58()).toEqual(dataContract);
|
|
72
|
+
expect(secondQueriedDoc).toEqual(expect.any(DocumentWASM));
|
|
73
|
+
});
|
|
45
74
|
describe('should be able to create state transition', () => {
|
|
46
75
|
test('should be able to create a create transition', async () => {
|
|
47
76
|
const document = sdk.documents.create(dataContract, documentType, data, identity);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|