dash-platform-sdk 1.4.0-dev.4 → 1.4.0-dev.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/bundle.min.js +17 -17
  2. package/package.json +2 -2
  3. package/proto/generated/platform.client.d.ts +20 -0
  4. package/proto/generated/platform.client.js +14 -0
  5. package/proto/generated/platform.d.ts +293 -0
  6. package/proto/generated/platform.js +603 -1
  7. package/src/DashPlatformSDK.d.ts +3 -1
  8. package/src/DashPlatformSDK.js +8 -5
  9. package/src/dataContracts/create.d.ts +2 -2
  10. package/src/dataContracts/getDataContractByIdentifier.d.ts +1 -2
  11. package/src/dataContracts/index.d.ts +2 -2
  12. package/src/documents/create.d.ts +1 -2
  13. package/src/documents/index.d.ts +2 -2
  14. package/src/documents/query.d.ts +1 -2
  15. package/src/identities/getIdentityBalance.d.ts +1 -1
  16. package/src/identities/getIdentityByIdentifier.d.ts +1 -2
  17. package/src/identities/getIdentityContractNonce.d.ts +1 -1
  18. package/src/identities/getIdentityNonce.d.ts +1 -1
  19. package/src/identities/getIdentityPublicKeys.d.ts +1 -2
  20. package/src/identities/index.d.ts +2 -2
  21. package/src/names/index.d.ts +1 -2
  22. package/src/node/index.d.ts +2 -3
  23. package/src/node/index.js +2 -4
  24. package/src/node/totalCredits.d.ts +1 -2
  25. package/src/node/totalCredits.js +2 -2
  26. package/src/platformAddresses/getAddressInfo.d.ts +4 -0
  27. package/src/platformAddresses/getAddressInfo.js +45 -0
  28. package/src/platformAddresses/getAddressesInfos.d.ts +4 -0
  29. package/src/platformAddresses/getAddressesInfos.js +43 -0
  30. package/src/platformAddresses/index.d.ts +22 -0
  31. package/src/platformAddresses/index.js +27 -0
  32. package/src/stateTransitions/broadcast.js +17 -6
  33. package/src/tokens/getIdentitiesTokenBalances.d.ts +1 -2
  34. package/src/tokens/getIdentityTokensBalances.d.ts +1 -2
  35. package/src/tokens/getTokenContractInfo.d.ts +1 -2
  36. package/src/tokens/getTokenDirectPurchasePrices.d.ts +2 -1
  37. package/src/tokens/getTokenTotalSupply.d.ts +2 -1
  38. package/src/tokens/index.d.ts +2 -2
  39. package/src/utils/deserializeConsensusError.d.ts +1 -0
  40. package/src/utils/deserializeConsensusError.js +17 -0
  41. package/src/utils/index.d.ts +8 -2
  42. package/src/utils/index.js +10 -0
  43. package/src/voting/index.d.ts +2 -2
  44. package/test/unit/PlatformAddress.spec.d.ts +1 -0
  45. package/test/unit/PlatformAddress.spec.js +22 -0
  46. package/test/unit/SDK.spec.js +4 -0
  47. package/types.d.ts +7 -3
@@ -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, this.network);
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, network) {
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, network);
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, this.network);
97
+ this._initialize(grpcPool);
95
98
  }
96
99
  }
@@ -1,3 +1,3 @@
1
- import { DataContractTokens, DataContractWASM, PlatformVersionWASM } from 'pshenmic-dpp';
2
- import { DataContractConfig, IdentifierLike } from '../../types.js';
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 { DataContractConfig, IdentifierLike } from '../../types.js';
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;
@@ -1,5 +1,5 @@
1
- import { DocumentTransitionParams, IdentifierLike } from '../../types.js';
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
@@ -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[]>;
@@ -1,3 +1,3 @@
1
- import { IdentifierLike } from '../../types.js';
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 '../../types.js';
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 '../../types.js';
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 { IdentifierLike, IdentityTransitionParams } from '../../types.js';
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
  *
@@ -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
  *
@@ -1,5 +1,5 @@
1
1
  import GRPCConnectionPool from '../grpcConnectionPool.js';
2
- import { Network, NodeStatus } from '../../types.js';
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
- network: Network;
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
- network;
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, this.network);
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
- import { Network } from '../../types.js';
3
- export default function totalCredits(grpcPool: GRPCConnectionPool, network: Network): Promise<bigint>;
2
+ export default function totalCredits(grpcPool: GRPCConnectionPool): Promise<bigint>;
@@ -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, network) {
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
- if (stateTransition.signature?.length === 0) {
4
- throw new Error('State Transition is not signed');
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 '../../types.js';
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 '../../types.js';
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 '../../types.js';
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 { IdentifierLike, TokenDirectPurchasePrices } from '../../types.js';
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 { IdentifierLike, TokenTotalSupply } from '../../types.js';
2
+ import { TokenTotalSupply } from '../../types.js';
3
+ import { IdentifierLike } from 'pshenmic-dpp';
3
4
  export default function getTokenTotalSupply(grpcPool: GRPCConnectionPool, tokenIdentifier: IdentifierLike): Promise<TokenTotalSupply>;
@@ -1,9 +1,9 @@
1
1
  import GRPCConnectionPool from '../grpcConnectionPool.js';
2
- import { IdentifierLike, TokenDirectPurchasePrices, TokenTotalSupply, TokenTransitionParams, TokenTransitionType } from '../../types.js';
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
+ }
@@ -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
  }
@@ -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
  }
@@ -1,5 +1,5 @@
1
- import { IdentifierLike, ResourceVoteChoice } from '../../types.js';
2
- import { IdentifierWASM, StateTransitionWASM, VoteWASM } from 'pshenmic-dpp';
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
  *
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,22 @@
1
+ import { DashPlatformSDK } from '../../src/DashPlatformSDK.js';
2
+ let sdk;
3
+ describe('PlatformAddress', () => {
4
+ beforeAll(() => {
5
+ sdk = new DashPlatformSDK({ network: 'testnet' });
6
+ });
7
+ test('getAddressInfo', async () => {
8
+ const info = await sdk.platformAddresses.getAddressInfo('tdashevo1qpgz9hk6tkn5zj3653s8qkjmk9439qkf0gl4yxxw');
9
+ expect(info.balance).toBeDefined();
10
+ expect(info.nonce).toBeDefined();
11
+ expect(info.address).toBeDefined();
12
+ });
13
+ test('getAddressesInfos', async () => {
14
+ const addresses = [
15
+ 'tdashevo1qpgz9hk6tkn5zj3653s8qkjmk9439qkf0gl4yxxw',
16
+ 'tdashevo1qq79z66rh34l4u2axlz3jv34zwshggnenut9k093',
17
+ 'tdashevo1qpwyg4khd0rh8px5cjphv9wx38psl6hma5krg9gk'
18
+ ];
19
+ const info = await sdk.platformAddresses.getAddressesInfos(addresses);
20
+ expect(info).toHaveLength(addresses.length);
21
+ });
22
+ });
@@ -7,4 +7,8 @@ describe('DashPlatformSDK', () => {
7
7
  test('should be constructable throw `new`', () => {
8
8
  expect(sdk).toEqual(expect.any(DashPlatformSDK));
9
9
  });
10
+ test('should be able to deserialize consensus error', () => {
11
+ const err = sdk.utils.deserializeConsensusError('AwIiSW52YWxpZCBTdGF0ZSBUcmFuc2l0aW9uIHNpZ25hdHVyZQ');
12
+ expect(err).toEqual('Invalid State Transition signature');
13
+ });
10
14
  });
package/types.d.ts CHANGED
@@ -1,6 +1,5 @@
1
- import { CoreScriptWASM, DocumentWASM, GasFeesPaidByWASM, IdentifierWASM, KeyType, Purpose, SecurityLevel, TokenEmergencyActionWASM, TokenPricingScheduleWASM } from 'pshenmic-dpp';
2
- export { CoreScriptWASM, DocumentWASM, GasFeesPaidByWASM, IdentifierWASM, KeyType, Purpose, SecurityLevel, TokenEmergencyActionWASM, TokenPricingScheduleWASM, StateTransitionWASM, BatchTransitionWASM, IdentityPublicKeyWASM, PrivateKeyWASM, DataContractUpdateTransitionWASM, IdentityWASM, IdentityUpdateTransitionWASM, IdentityCreditTransferWASM, MasternodeVoteTransitionWASM } from 'pshenmic-dpp';
3
- export type IdentifierLike = IdentifierWASM | string | Uint8Array;
1
+ import { CoreScriptWASM, DocumentWASM, GasFeesPaidByWASM, IdentifierLike, IdentifierWASM, KeyType, PlatformAddressWASM, Purpose, SecurityLevel, TokenEmergencyActionWASM, TokenPricingScheduleWASM } from 'pshenmic-dpp';
2
+ export { CoreScriptWASM, DocumentWASM, GasFeesPaidByWASM, IdentifierWASM, KeyType, Purpose, SecurityLevel, TokenEmergencyActionWASM, TokenPricingScheduleWASM, StateTransitionWASM, BatchTransitionWASM, IdentityPublicKeyWASM, PrivateKeyWASM, DataContractUpdateTransitionWASM, IdentityWASM, IdentityUpdateTransitionWASM, IdentityCreditTransferWASM, MasternodeVoteTransitionWASM, IdentifierLike, PlatformAddressLike } from 'pshenmic-dpp';
4
3
  export type Network = 'mainnet' | 'testnet';
5
4
  export { DashPlatformSDK } from './src/DashPlatformSDK.js';
6
5
  export type MasternodeList = Record<string, MasternodeInfo>;
@@ -206,3 +205,8 @@ export interface TokenDirectPurchasePrices {
206
205
  pricingSchedule?: TokenPricingScheduleWASM | undefined;
207
206
  }
208
207
  export type ResourceVoteChoice = IdentifierLike | 'lock' | 'abstain';
208
+ export interface PlatformAddressInfo {
209
+ address: PlatformAddressWASM;
210
+ nonce: number;
211
+ balance: bigint;
212
+ }