dash-platform-sdk 1.3.0-dev.8 → 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.8",
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) {
@@ -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
  });