dash-platform-sdk 1.5.0-dev.1 → 1.5.0-dev.3

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.
@@ -32,7 +32,7 @@ const shieldedTransitionsMap = {
32
32
  optionalArguments: []
33
33
  }
34
34
  };
35
- export default function createStateTransition(builder, type, params) {
35
+ export default async function createStateTransition(builder, type, params) {
36
36
  const { method: builderMethod, arguments: classArguments, optionalArguments } = shieldedTransitionsMap[type];
37
37
  if (builderMethod == null) {
38
38
  throw new Error(`Unimplemented shielded transition type: ${type}`);
@@ -43,7 +43,7 @@ export default function createStateTransition(builder, type, params) {
43
43
  throw new Error(`Shielded transition param "${missingArgument}" is missing`);
44
44
  }
45
45
  const transitionParams = classArguments.concat(optionalArguments).map((classArgument) => params[classArgument]);
46
- const result = builderMethod.apply(builder, [...transitionParams, params.platformVersion ?? LATEST_PLATFORM_VERSION]);
46
+ const result = await builderMethod.apply(builder, [...transitionParams, params.platformVersion ?? LATEST_PLATFORM_VERSION]);
47
47
  if (result instanceof StateTransitionWASM) {
48
48
  return result;
49
49
  }
@@ -16,14 +16,14 @@ export declare class ShieldedController {
16
16
  * Set bindings instance of builder
17
17
  * Needed for custom builder load, because ShieldedBuilderWASM inits very slow on old hardware
18
18
  */
19
- init(builder?: ShieldedBuilderWASM): ShieldedBuilderWASM;
19
+ init(builder?: ShieldedBuilderWASM): Promise<ShieldedBuilderWASM>;
20
20
  /**
21
21
  * Lazily constructs and caches a {ShieldedBuilderWASM}. Construction builds
22
22
  * the Halo 2 proving key (~seconds), so the instance is created once and reused.
23
23
  *
24
24
  * @ignore
25
25
  */
26
- getShieldedBuilder(): ShieldedBuilderWASM;
26
+ getShieldedBuilder(): Promise<ShieldedBuilderWASM>;
27
27
  /**
28
28
  * Retrieves a batch of shielded encrypted notes from the shielded pool,
29
29
  * starting from the given note index.
@@ -126,5 +126,5 @@ export declare class ShieldedController {
126
126
  *
127
127
  * @return {StateTransitionWASM}
128
128
  */
129
- createStateTransition<K extends ShieldedTransitionType>(type: K, params: ShieldedTransitionParamsMap[K]): StateTransitionWASM;
129
+ createStateTransition<K extends ShieldedTransitionType>(type: K, params: ShieldedTransitionParamsMap[K]): Promise<StateTransitionWASM>;
130
130
  }
@@ -23,8 +23,9 @@ export class ShieldedController {
23
23
  * Set bindings instance of builder
24
24
  * Needed for custom builder load, because ShieldedBuilderWASM inits very slow on old hardware
25
25
  */
26
- init(builder) {
26
+ async init(builder) {
27
27
  this.shieldedBuilder = builder ?? new ShieldedBuilderWASM();
28
+ await this.shieldedBuilder.init();
28
29
  return this.shieldedBuilder;
29
30
  }
30
31
  /**
@@ -33,9 +34,9 @@ export class ShieldedController {
33
34
  *
34
35
  * @ignore
35
36
  */
36
- getShieldedBuilder() {
37
+ async getShieldedBuilder() {
37
38
  if (this.shieldedBuilder == null) {
38
- return this.init();
39
+ return await this.init();
39
40
  }
40
41
  return this.shieldedBuilder;
41
42
  }
@@ -172,7 +173,7 @@ export class ShieldedController {
172
173
  *
173
174
  * @return {StateTransitionWASM}
174
175
  */
175
- createStateTransition(type, params) {
176
+ async createStateTransition(type, params) {
176
177
  // @ts-expect-error a plain string memo is normalized to ShieldedMemoWASM (empty when omitted)
177
178
  params.memo = typeof params.memo === 'string' ? ShieldedMemoWASM.fromString(params.memo) : ShieldedMemoWASM.empty();
178
179
  if (type === 'identityCreateFromShieldedPool') {
@@ -181,6 +182,6 @@ export class ShieldedController {
181
182
  identityParams.publicKeys = identityParams.publicKeys
182
183
  .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));
183
184
  }
184
- return createStateTransition(this.getShieldedBuilder(), type, params);
185
+ return await createStateTransition(await this.getShieldedBuilder(), type, params);
185
186
  }
186
187
  }
@@ -51,6 +51,12 @@ describe('Node', () => {
51
51
  expect(epochsInfo.length).toEqual(10);
52
52
  expect(epochsInfo.map(epochInfo => epochInfo.number)).toEqual(expectedEpochsNumbers);
53
53
  });
54
+ test('should be able to call getFinalizedEpochInfos', async () => {
55
+ const epochsInfo = await sdk.node.getFinalizedEpochsInfo(17100, true, 17110, false);
56
+ const expectedEpochsNumbers = Array.from({ length: 10 }, (_val, index) => 17100 + index);
57
+ expect(epochsInfo.length).toEqual(10);
58
+ expect(epochsInfo.map(epochInfo => epochInfo.epochIndex)).toEqual(expectedEpochsNumbers);
59
+ });
54
60
  test('should be able to call getTotalCreditsInPlatform', async () => {
55
61
  const totalCredits = await sdk.node.totalCredits();
56
62
  expect(Number(totalCredits)).toBeGreaterThan(0);
@@ -35,9 +35,10 @@ function makeSpendableNote(seed, value) {
35
35
  return { spend: new SpendableNoteWASM(note, merklePath), anchor, owner };
36
36
  }
37
37
  describe('Shielded', () => {
38
- beforeAll(() => {
38
+ beforeAll(async () => {
39
39
  sdk = new DashPlatformSDK({ network: 'testnet' });
40
- });
40
+ await sdk.shielded.init();
41
+ }, 60000);
41
42
  test('getShieldedNotesCount', async () => {
42
43
  const count = await sdk.shielded.getShieldedNotesCount();
43
44
  expect(typeof count).toBe('bigint');
@@ -89,7 +90,7 @@ describe('Shielded', () => {
89
90
  expect(Array.isArray(recovered)).toBe(true);
90
91
  expect(recovered).toHaveLength(0);
91
92
  });
92
- test('buildSpendableNotes produces a spend usable by a transition', () => {
93
+ test('buildSpendableNotes produces a spend usable by a transition', async () => {
93
94
  const seed = randomBytes(32);
94
95
  const owner = OrchardAddressWASM.fromSeed(seed, COIN_TYPE, ACCOUNT);
95
96
  const rho = randomBytes(32);
@@ -106,7 +107,7 @@ describe('Shielded', () => {
106
107
  expect(spends[0]).toEqual(expect.any(SpendableNoteWASM));
107
108
  expect(anchor).toBeInstanceOf(Uint8Array);
108
109
  // the produced spend + anchor must actually prove a spend transition
109
- const stateTransition = sdk.shielded.createStateTransition('shieldedTransfer', {
110
+ const stateTransition = await sdk.shielded.createStateTransition('shieldedTransfer', {
110
111
  spends,
111
112
  recipient: OrchardAddressWASM.fromSeed(randomBytes(32), COIN_TYPE, ACCOUNT),
112
113
  transferAmount: BigInt(1000000),
@@ -119,12 +120,12 @@ describe('Shielded', () => {
119
120
  expect(stateTransition).toEqual(expect.any(StateTransitionWASM));
120
121
  }, 60000);
121
122
  describe('should be able to create state transition', () => {
122
- test('should be able to create a shield transition', () => {
123
+ test('should be able to create a shield transition', async () => {
123
124
  const seed = randomBytes(32);
124
125
  const recipient = OrchardAddressWASM.fromSeed(seed, COIN_TYPE, ACCOUNT);
125
126
  const privateKey = new PrivateKeyWASM(randomBytes(32), 'testnet');
126
127
  const address = platformAddress(privateKey.getPublicKey().hash160());
127
- const stateTransition = sdk.shielded.createStateTransition('shield', {
128
+ const stateTransition = await sdk.shielded.createStateTransition('shield', {
128
129
  recipient,
129
130
  shieldAmount: BigInt(50000000),
130
131
  inputs: [new InputAddressWASM(address, 0, BigInt(100000000))],
@@ -135,13 +136,13 @@ describe('Shielded', () => {
135
136
  });
136
137
  expect(stateTransition).toEqual(expect.any(StateTransitionWASM));
137
138
  }, 60000);
138
- test('should be able to create a shieldFromAssetLock transition', () => {
139
+ test('should be able to create a shieldFromAssetLock transition', async () => {
139
140
  const seed = randomBytes(32);
140
141
  const recipient = OrchardAddressWASM.fromSeed(seed, COIN_TYPE, ACCOUNT);
141
142
  const privateKey = PrivateKeyWASM.fromHex('edd04a71bddb31e530f6c2314fd42ada333f6656bb853ece13f0577a8fd30612', 'testnet');
142
143
  const txid = '61aede830477254876d435a317241ad46753c4b1350dc991a45ebcf19ab80a11';
143
144
  const assetLockProof = AssetLockProofWASM.createChainAssetLockProof(1337, new OutPointWASM(txid, 0));
144
- const stateTransition = sdk.shielded.createStateTransition('shieldFromAssetLock', {
145
+ const stateTransition = await sdk.shielded.createStateTransition('shieldFromAssetLock', {
145
146
  recipient,
146
147
  shieldAmount: BigInt(50000000),
147
148
  assetLockProof,
@@ -151,11 +152,11 @@ describe('Shielded', () => {
151
152
  });
152
153
  expect(stateTransition).toEqual(expect.any(StateTransitionWASM));
153
154
  }, 60000);
154
- test('should be able to create a shieldedTransfer transition', () => {
155
+ test('should be able to create a shieldedTransfer transition', async () => {
155
156
  const seed = randomBytes(32);
156
157
  const { spend, anchor, owner } = makeSpendableNote(seed, BigInt(10000000000));
157
158
  const recipient = OrchardAddressWASM.fromSeed(randomBytes(32), COIN_TYPE, ACCOUNT);
158
- const stateTransition = sdk.shielded.createStateTransition('shieldedTransfer', {
159
+ const stateTransition = await sdk.shielded.createStateTransition('shieldedTransfer', {
159
160
  spends: [spend],
160
161
  recipient,
161
162
  transferAmount: BigInt(1000000),
@@ -168,10 +169,10 @@ describe('Shielded', () => {
168
169
  });
169
170
  expect(stateTransition).toEqual(expect.any(StateTransitionWASM));
170
171
  }, 60000);
171
- test('should be able to create an unshield transition', () => {
172
+ test('should be able to create an unshield transition', async () => {
172
173
  const seed = randomBytes(32);
173
174
  const { spend, anchor, owner } = makeSpendableNote(seed, BigInt(10000000000));
174
- const stateTransition = sdk.shielded.createStateTransition('unshield', {
175
+ const stateTransition = await sdk.shielded.createStateTransition('unshield', {
175
176
  spends: [spend],
176
177
  outputAddress: platformAddress(),
177
178
  unshieldAmount: BigInt(1000000),
@@ -184,10 +185,10 @@ describe('Shielded', () => {
184
185
  });
185
186
  expect(stateTransition).toEqual(expect.any(StateTransitionWASM));
186
187
  }, 60000);
187
- test('should be able to create a shieldedWithdrawal transition', () => {
188
+ test('should be able to create a shieldedWithdrawal transition', async () => {
188
189
  const seed = randomBytes(32);
189
190
  const { spend, anchor, owner } = makeSpendableNote(seed, BigInt(10000000000));
190
- const stateTransition = sdk.shielded.createStateTransition('shieldedWithdrawal', {
191
+ const stateTransition = await sdk.shielded.createStateTransition('shieldedWithdrawal', {
191
192
  spends: [spend],
192
193
  withdrawalAmount: BigInt(1000000),
193
194
  outputScript: CoreScriptWASM.newP2PKH(randomBytes(20)),
@@ -205,7 +206,7 @@ describe('Shielded', () => {
205
206
  // The proving step succeeds, but `IdentityCreateFromShieldedPoolResultWASM.identityId`
206
207
  // (read while assembling the transition) rejects the derived id for synthetic notes.
207
208
  // A real run needs a funded note and signed keys, so this is covered against a live pool.
208
- test('should be able to create an identityCreateFromShieldedPool transition', () => {
209
+ test('should be able to create an identityCreateFromShieldedPool transition', async () => {
209
210
  const seed = randomBytes(32);
210
211
  const { spend, anchor, owner } = makeSpendableNote(seed, BigInt(20000000000));
211
212
  const privateKey = PrivateKeyWASM.fromHex('a1286dd195e2b8e1f6bdc946c56a53e0c544750d6452ddc0f4c593ef311f21af', 'testnet');
@@ -217,7 +218,7 @@ describe('Shielded', () => {
217
218
  readOnly: false,
218
219
  data: privateKey.getPublicKey().bytes()
219
220
  };
220
- const stateTransition = sdk.shielded.createStateTransition('identityCreateFromShieldedPool', {
221
+ const stateTransition = await sdk.shielded.createStateTransition('identityCreateFromShieldedPool', {
221
222
  publicKeys: [identityPublicKeyInCreation],
222
223
  privateKeys: [privateKey],
223
224
  denomination: BigInt(10000000000),