dash-platform-sdk 1.3.0-dev.8 → 1.3.0

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 (78) hide show
  1. package/bundle.min.js +17 -17
  2. package/package.json +4 -3
  3. package/proto/generated/platform.client.d.ts +10 -0
  4. package/proto/generated/platform.client.js +7 -0
  5. package/proto/generated/platform.d.ts +114 -0
  6. package/proto/generated/platform.js +224 -1
  7. package/src/DashPlatformSDK.d.ts +1 -5
  8. package/src/DashPlatformSDK.js +0 -5
  9. package/src/constants.d.ts +2 -0
  10. package/src/constants.js +2 -0
  11. package/src/contestedResources/getContestedResourceVoteState.d.ts +1 -1
  12. package/src/contestedResources/getContestedResourceVoteState.js +6 -4
  13. package/src/contestedResources/index.d.ts +1 -1
  14. package/src/dataContracts/create.d.ts +1 -1
  15. package/src/dataContracts/create.js +3 -2
  16. package/src/dataContracts/getDataContractByIdentifier.d.ts +1 -1
  17. package/src/dataContracts/getDataContractByIdentifier.js +3 -3
  18. package/src/dataContracts/index.d.ts +1 -1
  19. package/src/documents/create.d.ts +1 -1
  20. package/src/documents/create.js +1 -1
  21. package/src/documents/createStateTransition.d.ts +1 -1
  22. package/src/documents/index.d.ts +1 -1
  23. package/src/documents/query.d.ts +1 -1
  24. package/src/documents/query.js +3 -3
  25. package/src/grpcConnectionPool.d.ts +1 -1
  26. package/src/identities/createStateTransition.d.ts +2 -2
  27. package/src/identities/createStateTransition.js +11 -1
  28. package/src/identities/getIdentityBalance.d.ts +1 -1
  29. package/src/identities/getIdentityBalance.js +3 -2
  30. package/src/identities/getIdentityByIdentifier.d.ts +1 -1
  31. package/src/identities/getIdentityByIdentifier.js +3 -2
  32. package/src/identities/getIdentityByNonUniquePublicKeyHash.js +3 -2
  33. package/src/identities/getIdentityByPublicKeyHash.js +3 -2
  34. package/src/identities/getIdentityContractNonce.d.ts +1 -1
  35. package/src/identities/getIdentityContractNonce.js +3 -2
  36. package/src/identities/getIdentityNonce.d.ts +1 -1
  37. package/src/identities/getIdentityNonce.js +3 -2
  38. package/src/identities/getIdentityPublicKeys.d.ts +2 -2
  39. package/src/identities/getIdentityPublicKeys.js +19 -9
  40. package/src/identities/index.d.ts +8 -5
  41. package/src/identities/index.js +18 -5
  42. package/src/keyPair/index.d.ts +1 -1
  43. package/src/names/index.d.ts +1 -1
  44. package/src/node/epochs.js +3 -2
  45. package/src/node/index.d.ts +1 -1
  46. package/src/node/status.d.ts +1 -1
  47. package/src/node/totalCredits.d.ts +1 -1
  48. package/src/node/totalCredits.js +3 -3
  49. package/src/stateTransitions/broadcast.js +1 -1
  50. package/src/stateTransitions/waitForStateTransitionResult.js +62 -5
  51. package/src/tokens/createStateTransition.d.ts +1 -1
  52. package/src/tokens/getIdentitiesTokenBalances.d.ts +1 -1
  53. package/src/tokens/getIdentitiesTokenBalances.js +3 -2
  54. package/src/tokens/getIdentityTokensBalances.d.ts +1 -1
  55. package/src/tokens/getIdentityTokensBalances.js +3 -2
  56. package/src/tokens/getTokenContractInfo.d.ts +1 -1
  57. package/src/tokens/getTokenContractInfo.js +3 -2
  58. package/src/tokens/getTokenDirectPurchasePrices.d.ts +1 -1
  59. package/src/tokens/getTokenDirectPurchasePrices.js +3 -2
  60. package/src/tokens/getTokenTotalSupply.d.ts +1 -1
  61. package/src/tokens/getTokenTotalSupply.js +3 -2
  62. package/src/tokens/index.d.ts +1 -1
  63. package/src/utils/getEvonodeList.d.ts +1 -1
  64. package/src/utils/index.d.ts +8 -0
  65. package/src/utils/index.js +17 -0
  66. package/src/voting/index.d.ts +1 -1
  67. package/test/unit/ContestedResources.spec.js +5 -3
  68. package/test/unit/DataContract.spec.js +4 -3
  69. package/test/unit/Identity.spec.js +36 -2
  70. package/test/unit/Names.spec.js +4 -2
  71. package/{src/types.d.ts → types.d.ts} +11 -4
  72. package/{src/types.js → types.js} +2 -2
  73. package/src/signer/AbstractSigner.d.ts +0 -12
  74. package/src/signer/AbstractSigner.js +0 -1
  75. package/src/signer/PrivateKeySigner.d.ts +0 -1
  76. package/src/signer/PrivateKeySigner.js +0 -65
  77. package/src/signer/setSigner.d.ts +0 -2
  78. package/src/signer/setSigner.js +0 -5
@@ -1,3 +1,3 @@
1
1
  import { DocumentWASM } from 'pshenmic-dpp';
2
- import { IdentifierLike } from '../types.js';
2
+ import { IdentifierLike } from '../../types.js';
3
3
  export default function createDocument(dataContractId: IdentifierLike, documentType: string, data: object, owner: IdentifierLike, revision?: bigint, documentId?: IdentifierLike): DocumentWASM;
@@ -1,4 +1,4 @@
1
1
  import { DocumentWASM } from 'pshenmic-dpp';
2
2
  export default function createDocument(dataContractId, documentType, data, owner, revision, documentId) {
3
- return new DocumentWASM(data, documentType, revision ?? BigInt(1), dataContractId, owner, documentId);
3
+ return new DocumentWASM(data, documentType, revision ?? BigInt(1), dataContractId, owner, documentId, owner);
4
4
  }
@@ -1,3 +1,3 @@
1
1
  import { DocumentWASM, StateTransitionWASM } from 'pshenmic-dpp';
2
- import { DocumentTransitionParams } from '../types.js';
2
+ import { DocumentTransitionParams } from '../../types.js';
3
3
  export default function createStateTransition(document: DocumentWASM, type: 'create' | 'replace' | 'delete' | 'updatePrice' | 'transfer' | 'purchase', params: DocumentTransitionParams): StateTransitionWASM;
@@ -1,4 +1,4 @@
1
- import { DocumentTransitionParams, IdentifierLike } from '../types.js';
1
+ import { DocumentTransitionParams, IdentifierLike } from '../../types.js';
2
2
  import { DocumentWASM, IdentifierWASM, StateTransitionWASM } from 'pshenmic-dpp';
3
3
  import GRPCConnectionPool from '../grpcConnectionPool.js';
4
4
  /**
@@ -1,4 +1,4 @@
1
1
  import { DocumentWASM, IdentifierWASM } from 'pshenmic-dpp';
2
- import { IdentifierLike } from '../types.js';
2
+ import { IdentifierLike } from '../../types.js';
3
3
  import GRPCConnectionPool from '../grpcConnectionPool.js';
4
4
  export default function query(grpcPool: GRPCConnectionPool, dataContractId: IdentifierLike, documentTypeName: string, where?: ArrayLike<any>, orderBy?: ArrayLike<any>, limit?: number | undefined, startAt?: IdentifierWASM, startAfter?: IdentifierWASM): Promise<DocumentWASM[]>;
@@ -1,6 +1,6 @@
1
1
  import { GetDocumentsRequest } from '../../proto/generated/platform.js';
2
- import { IdentifierWASM, PlatformVersionWASM, verifyDocumentsProof } from 'pshenmic-dpp';
3
- import { DAPI_DEFAULT_LIMIT } from '../constants.js';
2
+ import { IdentifierWASM, verifyDocumentsProof } from 'pshenmic-dpp';
3
+ import { DAPI_DEFAULT_LIMIT, LATEST_PLATFORM_VERSION } from '../constants.js';
4
4
  import { getQuorumPublicKey } from '../utils/getQuorumPublicKey.js';
5
5
  import bytesToHex from '../utils/bytesToHex.js';
6
6
  import verifyTenderdashProof from '../utils/verifyTenderdashProof.js';
@@ -52,7 +52,7 @@ export default async function query(grpcPool, dataContractId, documentTypeName,
52
52
  throw new Error('Metadata not found');
53
53
  }
54
54
  const startAtIncluded = startAt != null;
55
- const { rootHash, documents } = verifyDocumentsProof(proof.grovedbProof, dataContract, documentTypeName, where, orderBy, limit, startAt?.bytes(), startAtIncluded, BigInt(metadata?.timeMs), PlatformVersionWASM.PLATFORM_V9);
55
+ const { rootHash, documents } = verifyDocumentsProof(proof.grovedbProof, dataContract, documentTypeName, where, orderBy, limit, startAt?.bytes(), startAtIncluded, BigInt(metadata?.timeMs), LATEST_PLATFORM_VERSION);
56
56
  const quorumPublicKey = await getQuorumPublicKey(grpcPool.network, proof.quorumType, bytesToHex(proof.quorumHash));
57
57
  const verify = await verifyTenderdashProof(proof, metadata, rootHash, quorumPublicKey);
58
58
  if (!verify) {
@@ -1,5 +1,5 @@
1
1
  import { PlatformClient } from '../proto/generated/platform.client.js';
2
- import { Network } from './types.js';
2
+ import { Network } from '../types.js';
3
3
  export type MasternodeList = Record<string, MasternodeInfo>;
4
4
  export interface GRPCOptions {
5
5
  poolLimit: 5;
@@ -1,3 +1,3 @@
1
1
  import { StateTransitionWASM } from 'pshenmic-dpp';
2
- import { IdentityTransitionParams } from '../types.js';
3
- export default function createStateTransition(type: 'create' | 'update' | 'topUp', params: IdentityTransitionParams): StateTransitionWASM;
2
+ import { IdentityTransitionParams } from '../../types.js';
3
+ export default function createStateTransition(type: 'create' | 'update' | 'topUp' | 'creditTransfer' | 'withdrawal', params: IdentityTransitionParams): StateTransitionWASM;
@@ -1,4 +1,4 @@
1
- import { IdentityCreateTransitionWASM, IdentityTopUpTransitionWASM, IdentityUpdateTransitionWASM } from 'pshenmic-dpp';
1
+ import { IdentityCreateTransitionWASM, IdentityTopUpTransitionWASM, IdentityUpdateTransitionWASM, IdentityCreditTransferWASM, IdentityCreditWithdrawalTransitionWASM } from 'pshenmic-dpp';
2
2
  const identityTransitionsMap = {
3
3
  create: {
4
4
  class: IdentityCreateTransitionWASM,
@@ -14,6 +14,16 @@ const identityTransitionsMap = {
14
14
  class: IdentityUpdateTransitionWASM,
15
15
  arguments: ['identityId', 'revision', 'identityNonce', 'addPublicKeys', 'disablePublicKeyIds'],
16
16
  optionalArguments: ['userFeeIncrease']
17
+ },
18
+ creditTransfer: {
19
+ class: IdentityCreditTransferWASM,
20
+ arguments: ['identityId', 'amount', 'recipientId', 'identityNonce'],
21
+ optionalArguments: ['userFeeIncrease']
22
+ },
23
+ withdrawal: {
24
+ class: IdentityCreditWithdrawalTransitionWASM,
25
+ arguments: ['identityId', 'amount', 'coreFeePerByte', 'pooling', 'identityNonce', 'outputScript'],
26
+ optionalArguments: ['userFeeIncrease']
17
27
  }
18
28
  };
19
29
  export default function createStateTransition(type, params) {
@@ -1,3 +1,3 @@
1
- import { IdentifierLike } from '../types.js';
1
+ import { IdentifierLike } from '../../types.js';
2
2
  import GRPCConnectionPool from '../grpcConnectionPool.js';
3
3
  export default function getIdentityBalance(grpcPool: GRPCConnectionPool, identifier: IdentifierLike): Promise<bigint>;
@@ -1,8 +1,9 @@
1
1
  import { GetIdentityBalanceRequest } from '../../proto/generated/platform.js';
2
- import { IdentifierWASM, PlatformVersionWASM, verifyIdentityBalanceProof } from 'pshenmic-dpp';
2
+ import { IdentifierWASM, verifyIdentityBalanceProof } from 'pshenmic-dpp';
3
3
  import verifyTenderdashProof from '../utils/verifyTenderdashProof.js';
4
4
  import { getQuorumPublicKey } from '../utils/getQuorumPublicKey.js';
5
5
  import bytesToHex from '../utils/bytesToHex.js';
6
+ import { LATEST_PLATFORM_VERSION } from '../constants.js';
6
7
  export default async function getIdentityBalance(grpcPool, identifier) {
7
8
  const id = new IdentifierWASM(identifier);
8
9
  const getIdentityBalanceRequest = GetIdentityBalanceRequest.create({
@@ -27,7 +28,7 @@ export default async function getIdentityBalance(grpcPool, identifier) {
27
28
  if (metadata == null) {
28
29
  throw new Error('Metadata not found');
29
30
  }
30
- const { rootHash, balance } = verifyIdentityBalanceProof(proof.grovedbProof, id.bytes(), true, PlatformVersionWASM.PLATFORM_V9);
31
+ const { rootHash, balance } = verifyIdentityBalanceProof(proof.grovedbProof, id.bytes(), true, LATEST_PLATFORM_VERSION);
31
32
  if (balance == null) {
32
33
  throw new Error(`Failed to fetch balance for identifier ${id.base58()}`);
33
34
  }
@@ -1,4 +1,4 @@
1
1
  import { IdentityWASM } from 'pshenmic-dpp';
2
- import { IdentifierLike } from '../types.js';
2
+ import { IdentifierLike } from '../../types.js';
3
3
  import GRPCConnectionPool from '../grpcConnectionPool.js';
4
4
  export default function getIdentityByIdentifier(grpcPool: GRPCConnectionPool, identifier: IdentifierLike): Promise<IdentityWASM>;
@@ -1,8 +1,9 @@
1
1
  import { GetIdentityRequest } from '../../proto/generated/platform.js';
2
- import { IdentifierWASM, PlatformVersionWASM, verifyIdentityByIdentifierProof } from 'pshenmic-dpp';
2
+ import { IdentifierWASM, verifyIdentityByIdentifierProof } from 'pshenmic-dpp';
3
3
  import { getQuorumPublicKey } from '../utils/getQuorumPublicKey.js';
4
4
  import bytesToHex from '../utils/bytesToHex.js';
5
5
  import verifyTenderdashProof from '../utils/verifyTenderdashProof.js';
6
+ import { LATEST_PLATFORM_VERSION } from '../constants.js';
6
7
  export default async function getIdentityByIdentifier(grpcPool, identifier) {
7
8
  const id = new IdentifierWASM(identifier);
8
9
  const getIdentityRequest = GetIdentityRequest.create({
@@ -27,7 +28,7 @@ export default async function getIdentityByIdentifier(grpcPool, identifier) {
27
28
  if (metadata == null) {
28
29
  throw new Error('Metadata not found');
29
30
  }
30
- const { rootHash, identity } = verifyIdentityByIdentifierProof(proof.grovedbProof, id, true, PlatformVersionWASM.PLATFORM_V9);
31
+ const { rootHash, identity } = verifyIdentityByIdentifierProof(proof.grovedbProof, id, true, LATEST_PLATFORM_VERSION);
31
32
  if (identity == null) {
32
33
  throw new Error(`Identity with identifier ${id.base58()} not found`);
33
34
  }
@@ -1,10 +1,11 @@
1
1
  import { GetIdentityByNonUniquePublicKeyHashRequest } from '../../proto/generated/platform.js';
2
- import { PlatformVersionWASM, verifyIdentifierByNonUniquePublicKeyHashProof } from 'pshenmic-dpp';
2
+ import { verifyIdentifierByNonUniquePublicKeyHashProof } from 'pshenmic-dpp';
3
3
  import hexToBytes from '../utils/hexToBytes.js';
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
7
  import getIdentityByIdentifier from './getIdentityByIdentifier.js';
8
+ import { LATEST_PLATFORM_VERSION } from '../constants.js';
8
9
  export default async function getIdentityByNonUniquePublicKeyHash(grpcPool, hex) {
9
10
  const getIdentityByNonUniquePublicKeyHashRequest = GetIdentityByNonUniquePublicKeyHashRequest.create({
10
11
  version: {
@@ -31,7 +32,7 @@ export default async function getIdentityByNonUniquePublicKeyHash(grpcPool, hex)
31
32
  if (proof.grovedbIdentityPublicKeyHashProof == null) {
32
33
  throw new Error('GroveDB proof not found for identity by non unique public key request');
33
34
  }
34
- const { rootHash, identifier } = verifyIdentifierByNonUniquePublicKeyHashProof(proof.grovedbIdentityPublicKeyHashProof.grovedbProof, false, hexToBytes(hex), undefined, PlatformVersionWASM.PLATFORM_V9);
35
+ const { rootHash, identifier } = verifyIdentifierByNonUniquePublicKeyHashProof(proof.grovedbIdentityPublicKeyHashProof.grovedbProof, false, hexToBytes(hex), undefined, LATEST_PLATFORM_VERSION);
35
36
  if (identifier == null) {
36
37
  throw new Error(`Identity with non unique public key hash ${hex} not found`);
37
38
  }
@@ -1,9 +1,10 @@
1
1
  import { GetIdentityByPublicKeyHashRequest } from '../../proto/generated/platform.js';
2
- import { PlatformVersionWASM, verifyIdentityByUniqueKeyHashProof } from 'pshenmic-dpp';
2
+ import { verifyIdentityByUniqueKeyHashProof } from 'pshenmic-dpp';
3
3
  import hexToBytes from '../utils/hexToBytes.js';
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
+ import { LATEST_PLATFORM_VERSION } from '../constants.js';
7
8
  export default async function getIdentityByPublicKeyHash(grpcPool, hex) {
8
9
  const getIdentityByPublicKeyHashRequest = GetIdentityByPublicKeyHashRequest.create({
9
10
  version: {
@@ -27,7 +28,7 @@ export default async function getIdentityByPublicKeyHash(grpcPool, hex) {
27
28
  if (metadata == null) {
28
29
  throw new Error('Metadata not found');
29
30
  }
30
- const { rootHash, identity } = verifyIdentityByUniqueKeyHashProof(proof.grovedbProof, hexToBytes(hex), PlatformVersionWASM.PLATFORM_V9);
31
+ const { rootHash, identity } = verifyIdentityByUniqueKeyHashProof(proof.grovedbProof, hexToBytes(hex), LATEST_PLATFORM_VERSION);
31
32
  if (identity == null) {
32
33
  throw new Error(`Identity with public key hash ${hex} not found`);
33
34
  }
@@ -1,3 +1,3 @@
1
- import { IdentifierLike } from '../types.js';
1
+ import { IdentifierLike } from '../../types.js';
2
2
  import GRPCConnectionPool from '../grpcConnectionPool.js';
3
3
  export default function getIdentityContractNonce(grpcPool: GRPCConnectionPool, identity: IdentifierLike, dataContract: IdentifierLike): Promise<bigint>;
@@ -1,8 +1,9 @@
1
1
  import { GetIdentityContractNonceRequest } from '../../proto/generated/platform.js';
2
- import { IdentifierWASM, PlatformVersionWASM, verifyIdentityContractNonceProof } from 'pshenmic-dpp';
2
+ import { IdentifierWASM, verifyIdentityContractNonceProof } from 'pshenmic-dpp';
3
3
  import { getQuorumPublicKey } from '../utils/getQuorumPublicKey.js';
4
4
  import bytesToHex from '../utils/bytesToHex.js';
5
5
  import verifyTenderdashProof from '../utils/verifyTenderdashProof.js';
6
+ import { LATEST_PLATFORM_VERSION } from '../constants.js';
6
7
  const IDENTITY_CONTRACT_NONCE_VALUE_FILTER = BigInt(0xFFFFFFFFFF);
7
8
  export default async function getIdentityContractNonce(grpcPool, identity, dataContract) {
8
9
  const identityIdentifier = new IdentifierWASM(identity);
@@ -30,7 +31,7 @@ export default async function getIdentityContractNonce(grpcPool, identity, dataC
30
31
  if (metadata == null) {
31
32
  throw new Error('Metadata not found');
32
33
  }
33
- const { rootHash, contractNonce } = verifyIdentityContractNonceProof(proof.grovedbProof, identityIdentifier.bytes(), dataContractIdentifier.bytes(), true, PlatformVersionWASM.PLATFORM_V9);
34
+ const { rootHash, contractNonce } = verifyIdentityContractNonceProof(proof.grovedbProof, identityIdentifier.bytes(), dataContractIdentifier.bytes(), true, LATEST_PLATFORM_VERSION);
34
35
  if (contractNonce == null) {
35
36
  return BigInt(0);
36
37
  }
@@ -1,3 +1,3 @@
1
- import { IdentifierLike } from '../types.js';
1
+ import { IdentifierLike } from '../../types.js';
2
2
  import GRPCConnectionPool from '../grpcConnectionPool.js';
3
3
  export default function getIdentityNonce(grpcPool: GRPCConnectionPool, identifier: IdentifierLike): Promise<bigint>;
@@ -1,8 +1,9 @@
1
1
  import { GetIdentityNonceRequest } from '../../proto/generated/platform.js';
2
- import { IdentifierWASM, PlatformVersionWASM, verifyIdentityNonceProof } from 'pshenmic-dpp';
2
+ import { IdentifierWASM, verifyIdentityNonceProof } from 'pshenmic-dpp';
3
3
  import { getQuorumPublicKey } from '../utils/getQuorumPublicKey.js';
4
4
  import bytesToHex from '../utils/bytesToHex.js';
5
5
  import verifyTenderdashProof from '../utils/verifyTenderdashProof.js';
6
+ import { LATEST_PLATFORM_VERSION } from '../constants.js';
6
7
  const IDENTITY_NONCE_VALUE_FILTER = BigInt(0xFFFFFFFFFF);
7
8
  export default async function getIdentityNonce(grpcPool, identifier) {
8
9
  const id = new IdentifierWASM(identifier);
@@ -28,7 +29,7 @@ export default async function getIdentityNonce(grpcPool, identifier) {
28
29
  if (metadata == null) {
29
30
  throw new Error('Metadata not found');
30
31
  }
31
- const { rootHash, nonce } = verifyIdentityNonceProof(proof.grovedbProof, id.bytes(), true, PlatformVersionWASM.PLATFORM_V9);
32
+ const { rootHash, nonce } = verifyIdentityNonceProof(proof.grovedbProof, id.bytes(), true, LATEST_PLATFORM_VERSION);
32
33
  if (nonce == null) {
33
34
  return BigInt(0);
34
35
  }
@@ -1,4 +1,4 @@
1
1
  import { IdentityPublicKeyWASM } from 'pshenmic-dpp';
2
- import { IdentifierLike } from '../types.js';
2
+ import { IdentifierLike } from '../../types.js';
3
3
  import GRPCConnectionPool from '../grpcConnectionPool.js';
4
- export default function getIdentityPublicKeys(grpcPool: GRPCConnectionPool, identifier: IdentifierLike): Promise<IdentityPublicKeyWASM[]>;
4
+ export default function getIdentityPublicKeys(grpcPool: GRPCConnectionPool, identifier: IdentifierLike, keyIds?: number[]): Promise<IdentityPublicKeyWASM[]>;
@@ -1,21 +1,31 @@
1
1
  import { GetIdentityKeysRequest, KeyRequestType } from '../../proto/generated/platform.js';
2
- import { IdentifierWASM, PlatformVersionWASM, verifyIdentityKeysByIdentifierProof } from 'pshenmic-dpp';
2
+ import { IdentifierWASM, verifyIdentityKeysByIdentifierProof } from 'pshenmic-dpp';
3
3
  import { getQuorumPublicKey } from '../utils/getQuorumPublicKey.js';
4
4
  import bytesToHex from '../utils/bytesToHex.js';
5
5
  import verifyTenderdashProof from '../utils/verifyTenderdashProof.js';
6
- export default async function getIdentityPublicKeys(grpcPool, identifier) {
6
+ import { LATEST_PLATFORM_VERSION } from '../constants.js';
7
+ export default async function getIdentityPublicKeys(grpcPool, identifier, keyIds) {
7
8
  const id = new IdentifierWASM(identifier);
9
+ let requestType = {
10
+ request: {
11
+ oneofKind: 'allKeys',
12
+ allKeys: {}
13
+ }
14
+ };
15
+ if (keyIds != null) {
16
+ requestType = {
17
+ request: {
18
+ oneofKind: 'specificKeys',
19
+ specificKeys: { keyIds }
20
+ }
21
+ };
22
+ }
8
23
  const getIdentityKeysRequest = GetIdentityKeysRequest.create({
9
24
  version: {
10
25
  oneofKind: 'v0',
11
26
  v0: {
12
27
  identityId: id.bytes(),
13
- requestType: KeyRequestType.create({
14
- request: {
15
- oneofKind: 'allKeys',
16
- allKeys: {}
17
- }
18
- }),
28
+ requestType: KeyRequestType.create(requestType),
19
29
  prove: true
20
30
  }
21
31
  }
@@ -33,7 +43,7 @@ export default async function getIdentityPublicKeys(grpcPool, identifier) {
33
43
  if (metadata == null) {
34
44
  throw new Error('Metadata not found');
35
45
  }
36
- const { rootHash, identity } = verifyIdentityKeysByIdentifierProof(proof.grovedbProof, id.bytes(), null, false, false, true, null, null, PlatformVersionWASM.PLATFORM_V9);
46
+ const { rootHash, identity } = verifyIdentityKeysByIdentifierProof(proof.grovedbProof, id.bytes(), keyIds != null ? keyIds : null, false, false, true, null, null, LATEST_PLATFORM_VERSION);
37
47
  if (identity == null) {
38
48
  throw new Error(`Identity with identifier ${id.base58()} not found`);
39
49
  }
@@ -1,4 +1,4 @@
1
- import { IdentifierLike, IdentityTransitionParams } from '../types.js';
1
+ import { IdentifierLike, IdentityTransitionParams } from '../../types.js';
2
2
  import GRPCConnectionPool from '../grpcConnectionPool.js';
3
3
  import { IdentityPublicKeyWASM, IdentityWASM, StateTransitionWASM } from 'pshenmic-dpp';
4
4
  /**
@@ -56,11 +56,12 @@ export declare class IdentitiesController {
56
56
  getIdentityContractNonce(identifier: IdentifierLike, dataContract: IdentifierLike): Promise<bigint>;
57
57
  /**
58
58
  * Retrieve given Identity's public keys
59
- * @param identifier
59
+ * @param identifier {IdentifierLike}
60
+ * @param keyIds {=number[]} optional, specific keyIds to request
60
61
  *
61
62
  * @return {Promise<IdentityPublicKeyWASM[]>}
62
63
  */
63
- getIdentityPublicKeys(identifier: IdentifierLike): Promise<IdentityPublicKeyWASM[]>;
64
+ getIdentityPublicKeys(identifier: IdentifierLike, keyIds?: number[]): Promise<IdentityPublicKeyWASM[]>;
64
65
  /**
65
66
  * Helper function for creating {StateTransitionWASM} for Identity transitions
66
67
  *
@@ -68,8 +69,10 @@ export declare class IdentitiesController {
68
69
  * all necessary AssetLockProof data to make the transaction.
69
70
  * Both InstantSend and ChainLock AssetLock proofs supported
70
71
  *
71
- * @param type {string} type of transition, must be a one of ('create' | 'update' | 'topUp')
72
+ * Please refer to Identity.spec.js or README for example commands
73
+ *
74
+ * @param type {string} type of transition, must be a one of ('create' | 'update' | 'topUp' | 'creditTransfer' | 'withdrawal')
72
75
  * @param params {IdentityTransitionParams} params
73
76
  */
74
- createStateTransition(type: 'create' | 'update' | 'topUp', params: IdentityTransitionParams): StateTransitionWASM;
77
+ createStateTransition(type: 'create' | 'update' | 'topUp' | 'creditTransfer' | 'withdrawal', params: IdentityTransitionParams): StateTransitionWASM;
75
78
  }
@@ -4,10 +4,11 @@ import getIdentityNonce from './getIdentityNonce.js';
4
4
  import getIdentityBalance from './getIdentityBalance.js';
5
5
  import getIdentityByPublicKeyHash from './getIdentityByPublicKeyHash.js';
6
6
  import getIdentityByIdentifier from './getIdentityByIdentifier.js';
7
- import { AssetLockProofWASM, ContractBoundsWASM, IdentifierWASM, IdentityPublicKeyInCreationWASM, OutPointWASM } from 'pshenmic-dpp';
7
+ import { AssetLockProofWASM, ContractBoundsWASM, CoreScriptWASM, IdentifierWASM, IdentityPublicKeyInCreationWASM, OutPointWASM, PoolingWASM } from 'pshenmic-dpp';
8
8
  import createStateTransition from './createStateTransition.js';
9
9
  import getIdentityByNonUniquePublicKeyHash from './getIdentityByNonUniquePublicKeyHash.js';
10
10
  import hexToBytes from '../utils/hexToBytes.js';
11
+ import { base58 } from '@scure/base';
11
12
  /**
12
13
  * Collection of methods to query identities and its related data
13
14
  *
@@ -83,12 +84,13 @@ export class IdentitiesController {
83
84
  }
84
85
  /**
85
86
  * Retrieve given Identity's public keys
86
- * @param identifier
87
+ * @param identifier {IdentifierLike}
88
+ * @param keyIds {=number[]} optional, specific keyIds to request
87
89
  *
88
90
  * @return {Promise<IdentityPublicKeyWASM[]>}
89
91
  */
90
- async getIdentityPublicKeys(identifier) {
91
- return await getIdentityPublicKeys(this.grpcPool, identifier);
92
+ async getIdentityPublicKeys(identifier, keyIds) {
93
+ return await getIdentityPublicKeys(this.grpcPool, identifier, keyIds);
92
94
  }
93
95
  /**
94
96
  * Helper function for creating {StateTransitionWASM} for Identity transitions
@@ -97,7 +99,9 @@ export class IdentitiesController {
97
99
  * all necessary AssetLockProof data to make the transaction.
98
100
  * Both InstantSend and ChainLock AssetLock proofs supported
99
101
  *
100
- * @param type {string} type of transition, must be a one of ('create' | 'update' | 'topUp')
102
+ * Please refer to Identity.spec.js or README for example commands
103
+ *
104
+ * @param type {string} type of transition, must be a one of ('create' | 'update' | 'topUp' | 'creditTransfer' | 'withdrawal')
101
105
  * @param params {IdentityTransitionParams} params
102
106
  */
103
107
  createStateTransition(type, params) {
@@ -136,6 +140,15 @@ export class IdentitiesController {
136
140
  params.publicKeys = params.publicKeys
137
141
  .map(({ id, purpose, securityLevel, keyType, readOnly, data, signature, contractBounds }) => new IdentityPublicKeyInCreationWASM(id, purpose, securityLevel, keyType, readOnly, data, signature, (contractBounds != null) ? new ContractBoundsWASM(contractBounds.dataContractId, contractBounds.documentType) : undefined));
138
142
  }
143
+ if (params.recipientId != null) {
144
+ params.recipientId = new IdentifierWASM(params.recipientId);
145
+ }
146
+ if (type === 'withdrawal') {
147
+ // @ts-expect-error
148
+ params.pooling = params.pooling != null ? PoolingWASM[params.pooling] : PoolingWASM.Standard;
149
+ params.coreFeePerByte = params.coreFeePerByte ?? 1;
150
+ params.outputScript = params.outputScript ?? (params.withdrawalAddress != null ? CoreScriptWASM.newP2PKH(base58.decode(params.withdrawalAddress).slice(1, 21)) : undefined);
151
+ }
139
152
  return createStateTransition(type, params);
140
153
  }
141
154
  }
@@ -1,5 +1,5 @@
1
1
  import { HDKey } from '@scure/bip32';
2
- import { Network } from '../types.js';
2
+ import { Network } from '../../types.js';
3
3
  /**
4
4
  * Collection of functions to work with private keys and seed phrases
5
5
  *
@@ -1,6 +1,6 @@
1
1
  import GRPCConnectionPool from '../grpcConnectionPool.js';
2
2
  import { DocumentWASM, PrivateKeyWASM } from 'pshenmic-dpp';
3
- import { IdentifierLike } from '../types.js';
3
+ import { IdentifierLike } from '../../types.js';
4
4
  /**
5
5
  * Functions related to DPNS names (usernames)
6
6
  *
@@ -1,9 +1,10 @@
1
1
  import { GetEpochsInfoRequest } from '../../proto/generated/platform.js';
2
- import { PlatformVersionWASM, verifyEpochsInfoProof } from 'pshenmic-dpp';
2
+ import { verifyEpochsInfoProof } from 'pshenmic-dpp';
3
3
  import { getQuorumPublicKey } from '../utils/getQuorumPublicKey.js';
4
4
  import bytesToHex from '../utils/bytesToHex.js';
5
5
  import verifyTenderdashProof from '../utils/verifyTenderdashProof.js';
6
6
  import { UInt32Value } from '../../proto/generated/google/protobuf/wrappers.js';
7
+ import { LATEST_PLATFORM_VERSION } from '../constants.js';
7
8
  export default async function epochs(grpcPool, count, ascending, start) {
8
9
  const getEpochsInfoRequest = GetEpochsInfoRequest.create({
9
10
  version: {
@@ -29,7 +30,7 @@ export default async function epochs(grpcPool, count, ascending, start) {
29
30
  if (metadata == null) {
30
31
  throw new Error('Metadata not found');
31
32
  }
32
- const { rootHash, epochsInfo } = verifyEpochsInfoProof(proof.grovedbProof, metadata.epoch, start, count, ascending, PlatformVersionWASM.PLATFORM_V9);
33
+ const { rootHash, epochsInfo } = verifyEpochsInfoProof(proof.grovedbProof, metadata.epoch, start, count, ascending, LATEST_PLATFORM_VERSION);
33
34
  const quorumPublicKey = await getQuorumPublicKey(grpcPool.network, proof.quorumType, bytesToHex(proof.quorumHash));
34
35
  const verify = await verifyTenderdashProof(proof, metadata, rootHash, quorumPublicKey);
35
36
  if (!verify) {
@@ -1,5 +1,5 @@
1
1
  import GRPCConnectionPool from '../grpcConnectionPool.js';
2
- import { Network, NodeStatus } from '../types.js';
2
+ import { Network, NodeStatus } from '../../types.js';
3
3
  import { EpochInfo } from './epochs.js';
4
4
  /**
5
5
  * Node controller for requesting information about DAPI node
@@ -1,3 +1,3 @@
1
- import { NodeStatus } from '../types.js';
1
+ import { NodeStatus } from '../../types.js';
2
2
  import GRPCConnectionPool from '../grpcConnectionPool.js';
3
3
  export default function status(grpcPool: GRPCConnectionPool): Promise<NodeStatus>;
@@ -1,3 +1,3 @@
1
1
  import GRPCConnectionPool from '../grpcConnectionPool.js';
2
- import { Network } from '../types.js';
2
+ import { Network } from '../../types.js';
3
3
  export default function totalCredits(grpcPool: GRPCConnectionPool, network: Network): Promise<bigint>;
@@ -1,6 +1,6 @@
1
1
  import { GetTotalCreditsInPlatformRequest } from '../../proto/generated/platform.js';
2
- import { HALVING_INTERVAL, MAINNET_ACTIVATION_HEIGHT, TESTNET_ACTIVATION_HEIGHT } from '../constants.js';
3
- import { PlatformVersionWASM, verifyTotalCreditsProof } from 'pshenmic-dpp';
2
+ import { HALVING_INTERVAL, LATEST_PLATFORM_VERSION, MAINNET_ACTIVATION_HEIGHT, TESTNET_ACTIVATION_HEIGHT } from '../constants.js';
3
+ 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';
@@ -25,7 +25,7 @@ export default async function totalCredits(grpcPool, network) {
25
25
  throw new Error('Metadata not found');
26
26
  }
27
27
  const activationHeight = network === 'testnet' ? TESTNET_ACTIVATION_HEIGHT : MAINNET_ACTIVATION_HEIGHT;
28
- const { rootHash, totalCredits } = verifyTotalCreditsProof(proof.grovedbProof, HALVING_INTERVAL, activationHeight, Number(metadata.height), PlatformVersionWASM.PLATFORM_V9);
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);
31
31
  if (!verify) {
@@ -1,6 +1,6 @@
1
1
  import { BroadcastStateTransitionRequest } from '../../proto/generated/platform.js';
2
2
  export default async function broadcast(grpcPool, stateTransition) {
3
- if (stateTransition.signature.length === 0) {
3
+ if (stateTransition.signature?.length === 0) {
4
4
  throw new Error('State Transition is not signed');
5
5
  }
6
6
  const broadcastStateTransitionRequest = BroadcastStateTransitionRequest.create({
@@ -1,8 +1,65 @@
1
+ import { BatchTransitionWASM, BlockInfoWASM, MasternodeVoteTransitionWASM, verifyStateTransitionResult } from 'pshenmic-dpp';
2
+ import hexToBytes from '../utils/hexToBytes.js';
3
+ import { WaitForStateTransitionResultRequest } from '../../proto/generated/platform.js';
4
+ import { getQuorumPublicKey } from '../utils/getQuorumPublicKey.js';
5
+ import bytesToHex from '../utils/bytesToHex.js';
6
+ import verifyTenderdashProof from '../utils/verifyTenderdashProof.js';
7
+ import { base64 } from '@scure/base';
8
+ import { LATEST_PLATFORM_VERSION } from '../constants.js';
9
+ import getDataContractByIdentifier from '../dataContracts/getDataContractByIdentifier.js';
1
10
  export default async function waitForStateTransitionResult(grpcPool, stateTransition) {
2
- const url = `https://${grpcPool.network === 'mainnet' ? '' : 'testnet.'}platform-explorer.pshenmic.dev/waitForStateTransitionResult/${stateTransition.hash(false)}`;
3
- const resp = await fetch(url);
4
- if (resp.status !== 200) {
5
- console.log(await resp.json());
6
- throw new Error('Internal server error while waiting for state transition result');
11
+ const txHash = stateTransition.hash(false);
12
+ const waitForStateTransitionResultRequest = WaitForStateTransitionResultRequest.create({
13
+ version: {
14
+ oneofKind: 'v0',
15
+ v0: {
16
+ stateTransitionHash: hexToBytes(txHash),
17
+ prove: true
18
+ }
19
+ }
20
+ });
21
+ const { response } = await grpcPool.getClient().waitForStateTransitionResult(waitForStateTransitionResultRequest);
22
+ const { version } = response;
23
+ if (version.oneofKind !== 'v0') {
24
+ throw new Error('Unexpected oneOf type returned from DAPI (must be v0)');
25
+ }
26
+ const { v0 } = version;
27
+ if (v0.result.oneofKind !== 'proof' && v0.result.oneofKind !== 'error') {
28
+ throw new Error('Unexpected oneOf type returned from DAPI (must be proof)');
29
+ }
30
+ if (v0.result.oneofKind === 'proof') {
31
+ const { result: { proof }, metadata } = v0;
32
+ if (metadata == null) {
33
+ throw new Error('Metadata not found');
34
+ }
35
+ const { timeMs, height, coreChainLockedHeight, epoch } = metadata;
36
+ const knownContracts = [];
37
+ if (stateTransition.getActionType() === 'BATCH') {
38
+ const batchTransition = BatchTransitionWASM.fromStateTransition(stateTransition);
39
+ const [transition] = batchTransition.transitions;
40
+ const dataContract = await getDataContractByIdentifier(grpcPool, transition.dataContractId);
41
+ knownContracts.push(dataContract);
42
+ }
43
+ if (stateTransition.getActionType() === 'MASTERNODE_VOTE') {
44
+ const masternodeVote = MasternodeVoteTransitionWASM.fromStateTransition(stateTransition);
45
+ const dataContract = await getDataContractByIdentifier(grpcPool, masternodeVote.vote.votePoll.contractId);
46
+ knownContracts.push(dataContract);
47
+ }
48
+ const { rootHash, result } = verifyStateTransitionResult(proof.grovedbProof, stateTransition, new BlockInfoWASM(BigInt(timeMs), BigInt(height), coreChainLockedHeight, epoch), knownContracts, LATEST_PLATFORM_VERSION);
49
+ if (result == null) {
50
+ throw new Error('State transition result was null');
51
+ }
52
+ const quorumPublicKey = await getQuorumPublicKey(grpcPool.network, proof.quorumType, bytesToHex(proof.quorumHash));
53
+ const verify = await verifyTenderdashProof(proof, metadata, rootHash, quorumPublicKey);
54
+ if (!verify) {
55
+ throw new Error('Failed to verify wait for state transition result query');
56
+ }
57
+ }
58
+ else if (v0.result.oneofKind === 'error') {
59
+ const { code, message, data } = v0.result.error;
60
+ throw new Error(`State transition ${txHash} failed to execute with code ${String(code)}, message: ${String(message)}, data: ${base64.encode(data)}`);
61
+ }
62
+ else {
63
+ throw new Error('Unexpected oneOfKind returned for waitForStateTransitionResult');
7
64
  }
8
65
  }
@@ -1,3 +1,3 @@
1
1
  import { IdentifierWASM, StateTransitionWASM, TokenBaseTransitionWASM } from 'pshenmic-dpp';
2
- import { TokenTransitionParams, TokenTransitionType } from '../types.js';
2
+ import { TokenTransitionParams, TokenTransitionType } from '../../types.js';
3
3
  export default function createStateTransition(base: TokenBaseTransitionWASM, ownerId: IdentifierWASM, type: TokenTransitionType, params: TokenTransitionParams): StateTransitionWASM;
@@ -1,5 +1,5 @@
1
1
  import GRPCConnectionPool from '../grpcConnectionPool.js';
2
- import { IdentifierLike } from '../types.js';
2
+ import { IdentifierLike } from '../../types.js';
3
3
  import { IdentifierWASM } from 'pshenmic-dpp';
4
4
  export interface IdentitiesTokenBalances {
5
5
  identityId: IdentifierWASM;
@@ -1,8 +1,9 @@
1
1
  import { GetIdentitiesTokenBalancesRequest } from '../../proto/generated/platform.js';
2
- import { IdentifierWASM, PlatformVersionWASM, verifyTokenBalancesForIdentitiesProof } from 'pshenmic-dpp';
2
+ import { IdentifierWASM, verifyTokenBalancesForIdentitiesProof } from 'pshenmic-dpp';
3
3
  import { getQuorumPublicKey } from '../utils/getQuorumPublicKey.js';
4
4
  import bytesToHex from '../utils/bytesToHex.js';
5
5
  import verifyTenderdashProof from '../utils/verifyTenderdashProof.js';
6
+ import { LATEST_PLATFORM_VERSION } from '../constants.js';
6
7
  export default async function getIdentitiesTokenBalances(grpcPool, identifiers, tokenIdentifier) {
7
8
  const ids = identifiers.map(identifier => new IdentifierWASM(identifier));
8
9
  const tokenId = new IdentifierWASM(tokenIdentifier);
@@ -29,7 +30,7 @@ export default async function getIdentitiesTokenBalances(grpcPool, identifiers,
29
30
  if (metadata == null) {
30
31
  throw new Error('Metadata not found');
31
32
  }
32
- const { rootHash, balances } = verifyTokenBalancesForIdentitiesProof(proof.grovedbProof, tokenId, true, ids, PlatformVersionWASM.PLATFORM_V9);
33
+ const { rootHash, balances } = verifyTokenBalancesForIdentitiesProof(proof.grovedbProof, tokenId, true, ids, LATEST_PLATFORM_VERSION);
33
34
  const quorumPublicKey = await getQuorumPublicKey(grpcPool.network, proof.quorumType, bytesToHex(proof.quorumHash));
34
35
  const verify = await verifyTenderdashProof(proof, metadata, rootHash, quorumPublicKey);
35
36
  if (!verify) {
@@ -1,5 +1,5 @@
1
1
  import GRPCConnectionPool from '../grpcConnectionPool.js';
2
- import { IdentifierLike } from '../types.js';
2
+ import { IdentifierLike } from '../../types.js';
3
3
  import { IdentifierWASM } from 'pshenmic-dpp';
4
4
  export interface IdentityTokenBalances {
5
5
  tokenId: IdentifierWASM;