dash-platform-sdk 1.3.0-dev.7 → 1.3.0-dev.9

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.3.0-dev.7",
3
+ "version": "1.3.0-dev.9",
4
4
  "main": "index.js",
5
5
  "description": "Lightweight SDK for accessing Dash Platform blockchain",
6
6
  "ts-standard": {
@@ -1,3 +1,3 @@
1
1
  import { StateTransitionWASM } from 'pshenmic-dpp';
2
2
  import { IdentityTransitionParams } from '../types.js';
3
- export default function createStateTransition(type: 'create' | 'update' | 'topUp', params: IdentityTransitionParams): StateTransitionWASM;
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) {
@@ -68,8 +68,10 @@ export declare class IdentitiesController {
68
68
  * all necessary AssetLockProof data to make the transaction.
69
69
  * Both InstantSend and ChainLock AssetLock proofs supported
70
70
  *
71
- * @param type {string} type of transition, must be a one of ('create' | 'update' | 'topUp')
71
+ * Please refer to Identity.spec.js or README for example commands
72
+ *
73
+ * @param type {string} type of transition, must be a one of ('create' | 'update' | 'topUp' | 'creditTransfer' | 'withdrawal')
72
74
  * @param params {IdentityTransitionParams} params
73
75
  */
74
- createStateTransition(type: 'create' | 'update' | 'topUp', params: IdentityTransitionParams): StateTransitionWASM;
76
+ createStateTransition(type: 'create' | 'update' | 'topUp' | 'creditTransfer' | 'withdrawal', params: IdentityTransitionParams): StateTransitionWASM;
75
77
  }
@@ -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
  *
@@ -97,7 +98,9 @@ export class IdentitiesController {
97
98
  * all necessary AssetLockProof data to make the transaction.
98
99
  * Both InstantSend and ChainLock AssetLock proofs supported
99
100
  *
100
- * @param type {string} type of transition, must be a one of ('create' | 'update' | 'topUp')
101
+ * Please refer to Identity.spec.js or README for example commands
102
+ *
103
+ * @param type {string} type of transition, must be a one of ('create' | 'update' | 'topUp' | 'creditTransfer' | 'withdrawal')
101
104
  * @param params {IdentityTransitionParams} params
102
105
  */
103
106
  createStateTransition(type, params) {
@@ -136,6 +139,15 @@ export class IdentitiesController {
136
139
  params.publicKeys = params.publicKeys
137
140
  .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
141
  }
142
+ if (params.recipientId != null) {
143
+ params.recipientId = new IdentifierWASM(params.recipientId);
144
+ }
145
+ if (type === 'withdrawal') {
146
+ // @ts-expect-error
147
+ params.pooling = params.pooling != null ? PoolingWASM[params.pooling] : PoolingWASM.Standard;
148
+ params.coreFeePerByte = params.coreFeePerByte ?? 1;
149
+ params.outputScript = params.outputScript ?? (params.withdrawalAddress != null ? CoreScriptWASM.newP2PKH(base58.decode(params.withdrawalAddress).slice(1, 21)) : undefined);
150
+ }
139
151
  return createStateTransition(type, params);
140
152
  }
141
153
  }
package/src/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { DocumentWASM, GasFeesPaidByWASM, IdentifierWASM, KeyType, Purpose, SecurityLevel, TokenEmergencyActionWASM, TokenPricingScheduleWASM } from 'pshenmic-dpp';
2
- export { IdentifierWASM, IdentityWASM, DocumentWASM, DataContractWASM, StateTransitionWASM, IdentityPublicKeyWASM } from 'pshenmic-dpp';
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 } from 'pshenmic-dpp';
3
3
  export type IdentifierLike = IdentifierWASM | string | Uint8Array;
4
4
  export type Network = 'mainnet' | 'testnet';
5
5
  export { DashPlatformSDK } from './DashPlatformSDK.js';
@@ -186,7 +186,13 @@ export interface IdentityTransitionParams {
186
186
  disablePublicKeyIds?: number[];
187
187
  revision?: bigint;
188
188
  identityNonce?: bigint;
189
+ amount?: bigint;
189
190
  identityId?: IdentifierLike;
191
+ recipientId?: IdentifierLike;
192
+ withdrawalAddress?: string;
193
+ outputScript?: CoreScriptWASM;
194
+ pooling?: 'Standard' | 'Never' | 'IfAvailable';
195
+ coreFeePerByte?: number;
190
196
  userFeeIncrease?: number;
191
197
  }
192
198
  export interface TokenTotalSupply {
package/src/types.js CHANGED
@@ -1,4 +1,4 @@
1
- export { IdentifierWASM, IdentityWASM, DocumentWASM, DataContractWASM, StateTransitionWASM, IdentityPublicKeyWASM } from 'pshenmic-dpp';
1
+ export { CoreScriptWASM, DocumentWASM, GasFeesPaidByWASM, IdentifierWASM, KeyType, Purpose, SecurityLevel, TokenEmergencyActionWASM, TokenPricingScheduleWASM } from 'pshenmic-dpp';
2
2
  export { DashPlatformSDK } from './DashPlatformSDK.js';
3
3
  export var ContestedStateResultType;
4
4
  (function (ContestedStateResultType) {
@@ -0,0 +1,2 @@
1
+ import { IdentifierWASM } from 'pshenmic-dpp';
2
+ export declare function createMasternodeIdentityId(proTxHash: string): IdentifierWASM;
@@ -0,0 +1,4 @@
1
+ import { IdentifierWASM } from 'pshenmic-dpp';
2
+ export function createMasternodeIdentityId(proTxHash) {
3
+ return IdentifierWASM.fromHex(proTxHash);
4
+ }
@@ -1,3 +1,4 @@
1
+ import { IdentifierWASM } from 'pshenmic-dpp';
1
2
  /**
2
3
  * Collection of conversion functions
3
4
  *
@@ -44,4 +45,21 @@ export declare class UtilsController {
44
45
  * @return {string}
45
46
  */
46
47
  convertToHomographSafeChars(str: string): string;
48
+ /**
49
+ * Creates a voting identity identifier from proTxHash and voting address
50
+ *
51
+ * @param proTxHash {string} Pro TX Hash in hex format
52
+ * @param publicKeyHash {string} Voting address's public key hash (20 bytes), in hex
53
+ *
54
+ * @return {Promise<string>}
55
+ */
56
+ createVoterIdentifier(proTxHash: string, publicKeyHash: string): Promise<IdentifierWASM>;
57
+ /**
58
+ * Creates a masternode identity identifier from proTxHash
59
+ *
60
+ * @param proTxHash {string} Pro TX Hash in hex format
61
+ *
62
+ * @return {string}
63
+ * */
64
+ createMasternodeIdentifier(proTxHash: string): IdentifierWASM;
47
65
  }
@@ -2,6 +2,8 @@ import convertToHomographSafeChars from './convertToHomographSafeChars.js';
2
2
  import { base58 } from '@scure/base';
3
3
  import hexToBytes from './hexToBytes.js';
4
4
  import bytesToHex from './bytesToHex.js';
5
+ import { createVoterIdentityId } from './createVoterIdentityId.js';
6
+ import { createMasternodeIdentityId } from './createMasternodeIdentityId.js';
5
7
  /**
6
8
  * Collection of conversion functions
7
9
  *
@@ -58,4 +60,25 @@ export class UtilsController {
58
60
  convertToHomographSafeChars(str) {
59
61
  return convertToHomographSafeChars(str);
60
62
  }
63
+ /**
64
+ * Creates a voting identity identifier from proTxHash and voting address
65
+ *
66
+ * @param proTxHash {string} Pro TX Hash in hex format
67
+ * @param publicKeyHash {string} Voting address's public key hash (20 bytes), in hex
68
+ *
69
+ * @return {Promise<string>}
70
+ */
71
+ async createVoterIdentifier(proTxHash, publicKeyHash) {
72
+ return await createVoterIdentityId(proTxHash, publicKeyHash);
73
+ }
74
+ /**
75
+ * Creates a masternode identity identifier from proTxHash
76
+ *
77
+ * @param proTxHash {string} Pro TX Hash in hex format
78
+ *
79
+ * @return {string}
80
+ * */
81
+ createMasternodeIdentifier(proTxHash) {
82
+ return createMasternodeIdentityId(proTxHash);
83
+ }
61
84
  }
@@ -26,9 +26,9 @@ export declare class VotingController {
26
26
  */
27
27
  createVote(dataContractId: IdentifierLike, documentTypeName: string, indexName: string, indexValues: string[], choice: ResourceVoteChoice): VoteWASM;
28
28
  /**
29
- * Creates a {StateTransitionWASM} from masternoe protxhash and voter identity
29
+ * Creates a {StateTransitionWASM} from masternode Pro Tx Hash and voter identity
30
30
  *
31
- * @param voteWASM {VoteWASM} vote instance from .createMsternodeVote() method
31
+ * @param voteWASM {VoteWASM} vote instance from .createMasternodeVote() method
32
32
  * @param proTxHash {string} pro tx hash of the masternode as hex
33
33
  * @param voterIdentity {IdentifierWASM} voter identity identifier
34
34
  * @param identityNonce {BigInt} identity nonce
@@ -41,9 +41,9 @@ export class VotingController {
41
41
  return createVote(new IdentifierWASM(dataContractId), documentTypeName, indexName, indexValues, resourceVoteChoice);
42
42
  }
43
43
  /**
44
- * Creates a {StateTransitionWASM} from masternoe protxhash and voter identity
44
+ * Creates a {StateTransitionWASM} from masternode Pro Tx Hash and voter identity
45
45
  *
46
- * @param voteWASM {VoteWASM} vote instance from .createMsternodeVote() method
46
+ * @param voteWASM {VoteWASM} vote instance from .createMasternodeVote() method
47
47
  * @param proTxHash {string} pro tx hash of the masternode as hex
48
48
  * @param voterIdentity {IdentifierWASM} voter identity identifier
49
49
  * @param identityNonce {BigInt} identity nonce
@@ -1,5 +1,6 @@
1
- import { IdentityPublicKeyWASM, IdentityWASM, KeyType, PrivateKeyWASM, Purpose, SecurityLevel } from 'pshenmic-dpp';
1
+ import { CoreScriptWASM, IdentityPublicKeyWASM, IdentityWASM, KeyType, PrivateKeyWASM, Purpose, SecurityLevel, StateTransitionWASM } from 'pshenmic-dpp';
2
2
  import { DashPlatformSDK } from '../../src/types.js';
3
+ import { base58 } from '@scure/base';
3
4
  let sdk;
4
5
  describe('Identity', () => {
5
6
  beforeAll(() => {
@@ -228,5 +229,38 @@ describe('Identity', () => {
228
229
  });
229
230
  identityUpdateTransition.signByPrivateKey(masterPrivateKey, masterKeyId, KeyType.ECDSA_SECP256K1);
230
231
  });
232
+ test('should able be create credit transfer transition', async () => {
233
+ const identityId = 'QMfCRPcjXoTnZa9sA9JR2KWgGxZXMRJ4akgS3Uia1Qv';
234
+ const recipientId = 'HT3pUBM1Uv2mKgdPEN1gxa7A4PdsvNY89aJbdSKQb5wR';
235
+ const amount = 100000n;
236
+ const identityNonce = await sdk.identities.getIdentityNonce(identityId);
237
+ const stateTransition = sdk.identities.createStateTransition('creditTransfer', { identityId, identityNonce, recipientId, amount });
238
+ expect(stateTransition).toEqual(expect.any(StateTransitionWASM));
239
+ });
240
+ test('should be able create credit withdrawal', async () => {
241
+ const identityId = 'QMfCRPcjXoTnZa9sA9JR2KWgGxZXMRJ4akgS3Uia1Qv';
242
+ const amount = 100000n;
243
+ const identityNonce = await sdk.identities.getIdentityNonce(identityId);
244
+ const withdrawalAddress = 'yjHVQ3dj37UJwXFmvMTKR9ZVfoJSc3opTD';
245
+ const stateTransition = sdk.identities.createStateTransition('withdrawal', { identityId, identityNonce, amount, withdrawalAddress });
246
+ expect(stateTransition).toEqual(expect.any(StateTransitionWASM));
247
+ });
248
+ test('should be able create credit withdrawal with custom CoreScript', async () => {
249
+ const identityId = 'QMfCRPcjXoTnZa9sA9JR2KWgGxZXMRJ4akgS3Uia1Qv';
250
+ const amount = 100000n;
251
+ const identityNonce = await sdk.identities.getIdentityNonce(identityId);
252
+ const withdrawalAddress = 'yjHVQ3dj37UJwXFmvMTKR9ZVfoJSc3opTD';
253
+ const outputScript = CoreScriptWASM.newP2PKH(base58.decode(withdrawalAddress).slice(1, 21));
254
+ const stateTransition = sdk.identities.createStateTransition('withdrawal', { identityId, identityNonce, amount, outputScript });
255
+ expect(stateTransition).toEqual(expect.any(StateTransitionWASM));
256
+ });
257
+ test('should be able create credit withdrawal with no withdrawal address', async () => {
258
+ const identityId = 'QMfCRPcjXoTnZa9sA9JR2KWgGxZXMRJ4akgS3Uia1Qv';
259
+ const recipientId = 'HT3pUBM1Uv2mKgdPEN1gxa7A4PdsvNY89aJbdSKQb5wR';
260
+ const amount = 100000n;
261
+ const identityNonce = await sdk.identities.getIdentityNonce(identityId);
262
+ const stateTransition = sdk.identities.createStateTransition('creditTransfer', { identityId, recipientId, amount, identityNonce });
263
+ expect(stateTransition).toEqual(expect.any(StateTransitionWASM));
264
+ });
231
265
  });
232
266
  });