dash-platform-sdk 1.6.0-dev.5 → 1.6.0-dev.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dash-platform-sdk",
3
- "version": "1.6.0-dev.5",
3
+ "version": "1.6.0-dev.7",
4
4
  "main": "index.js",
5
5
  "description": "Lightweight SDK for accessing Dash Platform blockchain",
6
6
  "repository": {
@@ -1,2 +1,2 @@
1
- import { DocumentWASM, IdentifierLike } from 'pshenmic-dpp';
2
- export default function createDocument(dataContractId: IdentifierLike, documentType: string, data: object, owner: IdentifierLike, identityContractNonce: bigint, revision?: bigint, documentId?: IdentifierLike): DocumentWASM;
1
+ import { DocumentWASM, IdentifierLike, PlatformVersionLike } from 'pshenmic-dpp';
2
+ export default function createDocument(dataContractId: IdentifierLike, documentType: string, data: object, owner: IdentifierLike, identityContractNonce: bigint, revision?: bigint, documentId?: IdentifierLike, platformVersion?: PlatformVersionLike): DocumentWASM;
@@ -1,4 +1,4 @@
1
1
  import { DocumentWASM } from 'pshenmic-dpp';
2
- export default function createDocument(dataContractId, documentType, data, owner, identityContractNonce, revision, documentId) {
3
- return new DocumentWASM(data, documentType, revision ?? BigInt(1), dataContractId, owner, documentId, owner, identityContractNonce);
2
+ export default function createDocument(dataContractId, documentType, data, owner, identityContractNonce, revision, documentId, platformVersion) {
3
+ return new DocumentWASM(data, documentType, revision ?? BigInt(1), dataContractId, owner, documentId, owner, identityContractNonce, platformVersion);
4
4
  }
@@ -1,5 +1,5 @@
1
1
  import { DocumentTransitionParams, DocumentTransitionType } from '../../types.js';
2
- import { AggregateDocumentsQuery, AggregateProofQuery, CompositeSubQuery, DocumentActionFeeAgreementWASM, DocumentsQuery, DocumentWASM, HavingClause, IdentifierLike, IdentifierWASM, ProvenRankedEntry, ProvenRankedPage, StateTransitionWASM, WhereClause } from 'pshenmic-dpp';
2
+ import { AggregateDocumentsQuery, AggregateProofQuery, CompositeSubQuery, DocumentActionFeeAgreementWASM, DocumentsQuery, DocumentWASM, HavingClause, IdentifierLike, IdentifierWASM, PlatformVersionLike, ProvenRankedEntry, ProvenRankedPage, StateTransitionWASM, WhereClause } from 'pshenmic-dpp';
3
3
  import { GRPCPool } from '../grpcConnectionPool.js';
4
4
  import { QuorumKeyProvider } from '../quorumKeyProvider.js';
5
5
  import { DocumentsAggregate } from './queryAggregate.js';
@@ -24,10 +24,11 @@ export declare class DocumentsController {
24
24
  * @param owner {IdentifierLike} Identifier of the document's owner
25
25
  * @param identityContractNonce {bigint} Identity contract nonce of the transition that will create the document, used for document id generation
26
26
  * @param revision {bigint=} revision (optional)
27
+ * @param platformVersion {PlatformVersionLike=} platform version used to create the document (optional, latest by default)
27
28
  *
28
29
  * @return {DataContractWASM}
29
30
  */
30
- create(dataContractId: IdentifierLike, documentType: string, data: object, owner: IdentifierLike, identityContractNonce: bigint, revision?: bigint): DocumentWASM;
31
+ create(dataContractId: IdentifierLike, documentType: string, data: object, owner: IdentifierLike, identityContractNonce: bigint, revision?: bigint, platformVersion?: PlatformVersionLike): DocumentWASM;
31
32
  /**
32
33
  * Make a query for documents retrieval from the network.
33
34
  *
@@ -29,11 +29,12 @@ export class DocumentsController {
29
29
  * @param owner {IdentifierLike} Identifier of the document's owner
30
30
  * @param identityContractNonce {bigint} Identity contract nonce of the transition that will create the document, used for document id generation
31
31
  * @param revision {bigint=} revision (optional)
32
+ * @param platformVersion {PlatformVersionLike=} platform version used to create the document (optional, latest by default)
32
33
  *
33
34
  * @return {DataContractWASM}
34
35
  */
35
- create(dataContractId, documentType, data, owner, identityContractNonce, revision) {
36
- return createDocument(new IdentifierWASM(dataContractId), documentType, data, new IdentifierWASM(owner), identityContractNonce, revision);
36
+ create(dataContractId, documentType, data, owner, identityContractNonce, revision, platformVersion) {
37
+ return createDocument(new IdentifierWASM(dataContractId), documentType, data, new IdentifierWASM(owner), identityContractNonce, revision, undefined, platformVersion);
37
38
  }
38
39
  /**
39
40
  * Make a query for documents retrieval from the network.
@@ -72,6 +72,11 @@ export declare class IdentitiesController {
72
72
  * all necessary AssetLockProof data to make the transaction.
73
73
  * Both InstantSend and ChainLock AssetLock proofs supported
74
74
  *
75
+ * Withdrawals are created as IdentityCreditWithdrawalTransition V1. Destination can be set
76
+ * with params.withdrawalAddress (P2PKH) or params.outputScript. If both are omitted,
77
+ * the transition is created without output script and platform pays out to the address
78
+ * of the identity's withdrawal key (see getPurposeRequirement() for the signing key purpose)
79
+ *
75
80
  * Please refer to Identity.spec.js or README for example commands
76
81
  *
77
82
  * @param type {string} type of transition, must be a one of ('create' | 'update' | 'topUp' | 'creditTransfer' | 'withdrawal')
@@ -102,6 +102,11 @@ export class IdentitiesController {
102
102
  * all necessary AssetLockProof data to make the transaction.
103
103
  * Both InstantSend and ChainLock AssetLock proofs supported
104
104
  *
105
+ * Withdrawals are created as IdentityCreditWithdrawalTransition V1. Destination can be set
106
+ * with params.withdrawalAddress (P2PKH) or params.outputScript. If both are omitted,
107
+ * the transition is created without output script and platform pays out to the address
108
+ * of the identity's withdrawal key (see getPurposeRequirement() for the signing key purpose)
109
+ *
105
110
  * Please refer to Identity.spec.js or README for example commands
106
111
  *
107
112
  * @param type {string} type of transition, must be a one of ('create' | 'update' | 'topUp' | 'creditTransfer' | 'withdrawal')
@@ -1,6 +1,6 @@
1
1
  import { GRPCPool } from '../grpcConnectionPool.js';
2
2
  import { QuorumKeyProvider } from '../quorumKeyProvider.js';
3
- import { DocumentWASM, IdentifierLike, PrivateKeyWASM } from 'pshenmic-dpp';
3
+ import { DocumentWASM, IdentifierLike, PlatformVersionLike, PrivateKeyWASM } from 'pshenmic-dpp';
4
4
  /**
5
5
  * Functions related to DPNS names (usernames)
6
6
  *
@@ -47,10 +47,11 @@ export declare class NamesController {
47
47
  * @param identityId {IdentifierLike} identity identifier
48
48
  * @param privateKey {PrivateKeyWASM} Authentication / High private key from your identity
49
49
  * @param preorderSalt {Uint8Array=} Optional 32 bytes salt of already existing preorder document. If provided, preorder step is skipped
50
+ * @param platformVersion {PlatformVersionLike=} Optional platform version used to create preorder and domain documents (latest by default)
50
51
  *
51
52
  * @return {Promise<Uint8Array>} preorder salt (also attached as `preorderSalt` to the error if domain broadcast fails)
52
53
  */
53
- registerName(name: string, identityId: IdentifierLike, privateKey: PrivateKeyWASM, preorderSalt?: Uint8Array): Promise<Uint8Array>;
54
+ registerName(name: string, identityId: IdentifierLike, privateKey: PrivateKeyWASM, preorderSalt?: Uint8Array, platformVersion?: PlatformVersionLike): Promise<Uint8Array>;
54
55
  /**
55
56
  * Converts DPNS name to normalized format (ex. alice.dash -> al1ce.dash)
56
57
  *
@@ -71,16 +71,17 @@ export class NamesController {
71
71
  * @param identityId {IdentifierLike} identity identifier
72
72
  * @param privateKey {PrivateKeyWASM} Authentication / High private key from your identity
73
73
  * @param preorderSalt {Uint8Array=} Optional 32 bytes salt of already existing preorder document. If provided, preorder step is skipped
74
+ * @param platformVersion {PlatformVersionLike=} Optional platform version used to create preorder and domain documents (latest by default)
74
75
  *
75
76
  * @return {Promise<Uint8Array>} preorder salt (also attached as `preorderSalt` to the error if domain broadcast fails)
76
77
  */
77
- async registerName(name, identityId, privateKey, preorderSalt) {
78
+ async registerName(name, identityId, privateKey, preorderSalt, platformVersion) {
78
79
  const validation = validateName(name);
79
80
  if (validation != null) {
80
81
  throw new Error(validation);
81
82
  }
82
83
  const identity = await getIdentityByIdentifier(this.grpcPool, this.quorumKeyProvider, identityId);
83
- return await registerName(this.grpcPool, this.quorumKeyProvider, name, identity, privateKey, preorderSalt);
84
+ return await registerName(this.grpcPool, this.quorumKeyProvider, name, identity, privateKey, preorderSalt, platformVersion);
84
85
  }
85
86
  /**
86
87
  * Converts DPNS name to normalized format (ex. alice.dash -> al1ce.dash)
@@ -1,4 +1,4 @@
1
- import { IdentityWASM, PrivateKeyWASM } from 'pshenmic-dpp';
1
+ import { IdentityWASM, PlatformVersionLike, PrivateKeyWASM } from 'pshenmic-dpp';
2
2
  import { GRPCPool } from '../grpcConnectionPool.js';
3
3
  import { QuorumKeyProvider } from '../quorumKeyProvider.js';
4
- export default function registerName(grpcPool: GRPCPool, quorumKeyProvider: QuorumKeyProvider, name: string, identity: IdentityWASM, privateKey: PrivateKeyWASM, preorderSalt?: Uint8Array): Promise<Uint8Array>;
4
+ export default function registerName(grpcPool: GRPCPool, quorumKeyProvider: QuorumKeyProvider, name: string, identity: IdentityWASM, privateKey: PrivateKeyWASM, preorderSalt?: Uint8Array, platformVersion?: PlatformVersionLike): Promise<Uint8Array>;
@@ -9,7 +9,7 @@ import broadcast from '../stateTransitions/broadcast.js';
9
9
  import waitForStateTransitionResult from '../stateTransitions/waitForStateTransitionResult.js';
10
10
  import testNameContested from './testNameContested.js';
11
11
  import { DPNS_DATA_CONTRACT_ID } from '../constants.js';
12
- export default async function registerName(grpcPool, quorumKeyProvider, name, identity, privateKey, preorderSalt) {
12
+ export default async function registerName(grpcPool, quorumKeyProvider, name, identity, privateKey, preorderSalt, platformVersion) {
13
13
  const [identityPublicKey] = identity.getPublicKeys().filter(identityPublicKey => identityPublicKey.getPublicKeyHash() === privateKey.getPublicKeyHash());
14
14
  if (identityPublicKey == null) {
15
15
  throw new Error('Private key does not match the identity');
@@ -41,7 +41,7 @@ export default async function registerName(grpcPool, quorumKeyProvider, name, id
41
41
  const preorderData = {
42
42
  saltedDomainHash
43
43
  };
44
- const preorderDocument = createDocument(DPNS_DATA_CONTRACT_ID, 'preorder', preorderData, identity.id.base58(), identityContractNonce + BigInt(1));
44
+ const preorderDocument = createDocument(DPNS_DATA_CONTRACT_ID, 'preorder', preorderData, identity.id.base58(), identityContractNonce + BigInt(1), undefined, undefined, platformVersion);
45
45
  const preorderStateTransition = createStateTransition(preorderDocument, 'create', { identityContractNonce: identityContractNonce + BigInt(1) });
46
46
  await preorderStateTransition.sign(privateKey, identityPublicKey);
47
47
  await broadcast(grpcPool, preorderStateTransition);
@@ -63,7 +63,7 @@ export default async function registerName(grpcPool, quorumKeyProvider, name, id
63
63
  allowSubdomains: false
64
64
  }
65
65
  };
66
- const domainDocument = createDocument(DPNS_DATA_CONTRACT_ID, 'domain', domainData, identity.id.base58(), domainNonce);
66
+ const domainDocument = createDocument(DPNS_DATA_CONTRACT_ID, 'domain', domainData, identity.id.base58(), domainNonce, undefined, undefined, platformVersion);
67
67
  const domainStateTransition = createStateTransition(domainDocument, 'create', {
68
68
  identityContractNonce: domainNonce,
69
69
  // @ts-expect-error
@@ -53,7 +53,7 @@ export default async function waitForStateTransitionResult(grpcPool, quorumKeyPr
53
53
  coreHeight: coreChainLockedHeight,
54
54
  epoch
55
55
  };
56
- return [stateTransition, blockInfo, knownContracts, LATEST_PLATFORM_VERSION];
56
+ return [stateTransition, blockInfo, knownContracts, Math.min(metadata.protocolVersion, LATEST_PLATFORM_VERSION)];
57
57
  })
58
58
  .mapResponse(data => {
59
59
  if (data.proved) {
@@ -1,4 +1,4 @@
1
- import { DocumentWASM, GasFeesPaidByWASM, StateTransitionWASM } from 'pshenmic-dpp';
1
+ import { DocumentWASM, GasFeesPaidByWASM, PlatformVersionWASM, StateTransitionWASM } from 'pshenmic-dpp';
2
2
  import { DashPlatformSDK } from '../../src/DashPlatformSDK.js';
3
3
  let sdk;
4
4
  let dataContract;
@@ -24,6 +24,10 @@ describe('Document', () => {
24
24
  const document = sdk.documents.create(dataContract, documentType, data, identity, BigInt(1), revision);
25
25
  expect(document).toEqual(expect.any(DocumentWASM));
26
26
  });
27
+ test('should be able to create document with custom platform version', async () => {
28
+ const document = sdk.documents.create(dataContract, documentType, data, identity, BigInt(1), revision, PlatformVersionWASM.PLATFORM_V13);
29
+ expect(document).toEqual(expect.any(DocumentWASM));
30
+ });
27
31
  test('should be able to get documents', async () => {
28
32
  const dataContract = 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec';
29
33
  const documentType = 'domain';
@@ -1,4 +1,4 @@
1
- import { CoreScriptWASM, IdentityPublicKeyWASM, IdentityWASM, KeyType, PrivateKeyWASM, Purpose, SecurityLevel, StateTransitionWASM } from 'pshenmic-dpp';
1
+ import { CoreScriptWASM, IdentityCreditWithdrawalTransitionWASM, IdentityPublicKeyWASM, IdentityWASM, KeyType, PrivateKeyWASM, Purpose, SecurityLevel, StateTransitionWASM } from 'pshenmic-dpp';
2
2
  import { DashPlatformSDK } from '../../types.js';
3
3
  import { base58 } from '@scure/base';
4
4
  let sdk;
@@ -256,11 +256,23 @@ describe('Identity', () => {
256
256
  });
257
257
  test('should be able create credit withdrawal with no withdrawal address', async () => {
258
258
  const identityId = 'QMfCRPcjXoTnZa9sA9JR2KWgGxZXMRJ4akgS3Uia1Qv';
259
- const recipientId = 'HT3pUBM1Uv2mKgdPEN1gxa7A4PdsvNY89aJbdSKQb5wR';
260
259
  const amount = 100000n;
261
260
  const identityNonce = await sdk.identities.getIdentityNonce(identityId);
262
- const stateTransition = sdk.identities.createStateTransition('withdrawal', { identityId, recipientId, amount, identityNonce });
261
+ const stateTransition = sdk.identities.createStateTransition('withdrawal', { identityId, amount, identityNonce });
262
+ const withdrawalTransition = IdentityCreditWithdrawalTransitionWASM.fromStateTransition(stateTransition);
263
263
  expect(stateTransition).toEqual(expect.any(StateTransitionWASM));
264
+ expect(withdrawalTransition.outputScript).toBeUndefined();
265
+ });
266
+ test('should create credit withdrawal as V1 transition', async () => {
267
+ const identityId = 'QMfCRPcjXoTnZa9sA9JR2KWgGxZXMRJ4akgS3Uia1Qv';
268
+ const amount = 100000n;
269
+ const identityNonce = 1n;
270
+ const withdrawalAddress = 'yjHVQ3dj37UJwXFmvMTKR9ZVfoJSc3opTD';
271
+ const withScript = sdk.identities.createStateTransition('withdrawal', { identityId, identityNonce, amount, withdrawalAddress });
272
+ const withoutScript = sdk.identities.createStateTransition('withdrawal', { identityId, identityNonce, amount });
273
+ // first byte is state transition type (5 - IdentityCreditWithdrawal), second is transition version
274
+ expect(withScript.hex().slice(0, 4)).toEqual('0501');
275
+ expect(withoutScript.hex().slice(0, 4)).toEqual('0501');
264
276
  });
265
277
  });
266
278
  });