algosdk 3.4.0 → 3.5.1

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 (47) hide show
  1. package/README.md +4 -4
  2. package/dist/browser/algosdk.min.js +1 -1
  3. package/dist/browser/algosdk.min.js.map +1 -1
  4. package/dist/cjs/appAccess.js +261 -0
  5. package/dist/cjs/appAccess.js.map +1 -0
  6. package/dist/cjs/client/v2/indexer/models/types.js +266 -8
  7. package/dist/cjs/client/v2/indexer/models/types.js.map +1 -1
  8. package/dist/cjs/composer.js +13 -5
  9. package/dist/cjs/composer.js.map +1 -1
  10. package/dist/cjs/logicsig.js +54 -17
  11. package/dist/cjs/logicsig.js.map +1 -1
  12. package/dist/cjs/makeTxn.js +60 -12
  13. package/dist/cjs/makeTxn.js.map +1 -1
  14. package/dist/cjs/signing.js +4 -4
  15. package/dist/cjs/signing.js.map +1 -1
  16. package/dist/cjs/transaction.js +110 -0
  17. package/dist/cjs/transaction.js.map +1 -1
  18. package/dist/esm/appAccess.js +255 -0
  19. package/dist/esm/appAccess.js.map +1 -0
  20. package/dist/esm/client/v2/indexer/models/types.js +261 -6
  21. package/dist/esm/client/v2/indexer/models/types.js.map +1 -1
  22. package/dist/esm/composer.js +13 -5
  23. package/dist/esm/composer.js.map +1 -1
  24. package/dist/esm/logicsig.js +54 -17
  25. package/dist/esm/logicsig.js.map +1 -1
  26. package/dist/esm/makeTxn.js +60 -12
  27. package/dist/esm/makeTxn.js.map +1 -1
  28. package/dist/esm/signing.js +4 -4
  29. package/dist/esm/signing.js.map +1 -1
  30. package/dist/esm/transaction.js +110 -0
  31. package/dist/esm/transaction.js.map +1 -1
  32. package/dist/types/appAccess.d.ts +28 -0
  33. package/dist/types/client/v2/indexer/models/types.d.ts +157 -8
  34. package/dist/types/composer.d.ts +6 -2
  35. package/dist/types/logicsig.d.ts +2 -0
  36. package/dist/types/makeTxn.d.ts +9 -9
  37. package/dist/types/transaction.d.ts +18 -0
  38. package/dist/types/types/transactions/base.d.ts +76 -0
  39. package/package.json +1 -1
  40. package/src/appAccess.ts +298 -0
  41. package/src/client/v2/indexer/models/types.ts +423 -5
  42. package/src/composer.ts +24 -4
  43. package/src/logicsig.ts +68 -17
  44. package/src/makeTxn.ts +105 -12
  45. package/src/signing.ts +4 -4
  46. package/src/transaction.ts +168 -0
  47. package/src/types/transactions/base.ts +91 -0
@@ -1,5 +1,9 @@
1
1
  import base32 from 'hi-base32';
2
2
  import { boxReferencesToEncodingData } from './boxStorage.js';
3
+ import {
4
+ resourceReferencesToEncodingData,
5
+ convertIndicesToResourceReferences,
6
+ } from './appAccess.js';
3
7
  import { Address } from './encoding/address.js';
4
8
  import * as encoding from './encoding/encoding.js';
5
9
  import {
@@ -180,6 +184,73 @@ function ensureBoxReference(input: unknown): TransactionBoxReference {
180
184
  throw new Error(`Not a box reference: ${input}`);
181
185
  }
182
186
 
187
+ export interface TransactionHoldingReference {
188
+ readonly assetIndex: bigint;
189
+ readonly address: Address;
190
+ }
191
+
192
+ function ensureHoldingReference(input: unknown): TransactionHoldingReference {
193
+ if (input != null && typeof input === 'object') {
194
+ const { assetIndex, address } = input as TransactionHoldingReference;
195
+ return {
196
+ assetIndex: utils.ensureUint64(assetIndex),
197
+ address: ensureAddress(address),
198
+ };
199
+ }
200
+ throw new Error(`Not a holding reference: ${input}`);
201
+ }
202
+
203
+ export interface TransactionLocalsReference {
204
+ readonly appIndex: bigint;
205
+ readonly address: Address;
206
+ }
207
+
208
+ function ensureLocalsReference(input: unknown): TransactionLocalsReference {
209
+ if (input != null && typeof input === 'object') {
210
+ const { appIndex, address } = input as TransactionLocalsReference;
211
+ return {
212
+ appIndex: utils.ensureUint64(appIndex),
213
+ address: ensureAddress(address),
214
+ };
215
+ }
216
+ throw new Error(`Not a locals reference: ${input}`);
217
+ }
218
+
219
+ export interface TransactionResourceReference {
220
+ readonly address?: Readonly<Address>;
221
+ readonly appIndex?: Readonly<bigint>;
222
+ readonly assetIndex?: Readonly<bigint>;
223
+ readonly holding?: Readonly<TransactionHoldingReference>;
224
+ readonly locals?: Readonly<TransactionLocalsReference>;
225
+ readonly box?: Readonly<TransactionBoxReference>;
226
+ }
227
+
228
+ function ensureResourceReference(input: unknown): TransactionResourceReference {
229
+ if (input != null && typeof input === 'object') {
230
+ const { address, appIndex, assetIndex, holding, locals, box } =
231
+ input as TransactionResourceReference;
232
+ if (address !== undefined) {
233
+ return { address: ensureAddress(address) };
234
+ }
235
+ if (appIndex !== undefined) {
236
+ return { appIndex: utils.ensureUint64(appIndex) };
237
+ }
238
+ if (assetIndex !== undefined) {
239
+ return { assetIndex: utils.ensureUint64(assetIndex) };
240
+ }
241
+ if (holding !== undefined) {
242
+ return { holding: ensureHoldingReference(holding) };
243
+ }
244
+ if (locals !== undefined) {
245
+ return { locals: ensureLocalsReference(locals) };
246
+ }
247
+ if (box !== undefined) {
248
+ return { box: ensureBoxReference(box) };
249
+ }
250
+ }
251
+ throw new Error(`Not a resource reference: ${input}`);
252
+ }
253
+
183
254
  const TX_TAG = new TextEncoder().encode('TX');
184
255
 
185
256
  export interface PaymentTransactionFields {
@@ -242,6 +313,8 @@ export interface ApplicationTransactionFields {
242
313
  readonly foreignApps: ReadonlyArray<bigint>;
243
314
  readonly foreignAssets: ReadonlyArray<bigint>;
244
315
  readonly boxes: ReadonlyArray<TransactionBoxReference>;
316
+ readonly access: ReadonlyArray<TransactionResourceReference>;
317
+ readonly rejectVersion: number;
245
318
  }
246
319
 
247
320
  export interface StateProofTransactionFields {
@@ -404,6 +477,80 @@ export class Transaction implements encoding.Encodable {
404
477
  )
405
478
  ),
406
479
  },
480
+ {
481
+ key: 'al',
482
+ valueSchema: new OptionalSchema(
483
+ new ArraySchema(
484
+ new NamedMapSchema(
485
+ allOmitEmpty([
486
+ {
487
+ key: 'd',
488
+ valueSchema: new OptionalSchema(new AddressSchema()),
489
+ },
490
+ {
491
+ key: 's',
492
+ valueSchema: new OptionalSchema(new Uint64Schema()),
493
+ },
494
+ {
495
+ key: 'p',
496
+ valueSchema: new OptionalSchema(new Uint64Schema()),
497
+ },
498
+ {
499
+ key: 'h',
500
+ valueSchema: new OptionalSchema(
501
+ new NamedMapSchema(
502
+ allOmitEmpty([
503
+ {
504
+ key: 'd',
505
+ valueSchema: new Uint64Schema(),
506
+ },
507
+ {
508
+ key: 's',
509
+ valueSchema: new Uint64Schema(),
510
+ },
511
+ ])
512
+ )
513
+ ),
514
+ },
515
+ {
516
+ key: 'l',
517
+ valueSchema: new OptionalSchema(
518
+ new NamedMapSchema(
519
+ allOmitEmpty([
520
+ {
521
+ key: 'd',
522
+ valueSchema: new Uint64Schema(),
523
+ },
524
+ {
525
+ key: 'p',
526
+ valueSchema: new Uint64Schema(),
527
+ },
528
+ ])
529
+ )
530
+ ),
531
+ },
532
+ {
533
+ key: 'b',
534
+ valueSchema: new OptionalSchema(
535
+ new NamedMapSchema(
536
+ allOmitEmpty([
537
+ {
538
+ key: 'i',
539
+ valueSchema: new Uint64Schema(),
540
+ },
541
+ {
542
+ key: 'n',
543
+ valueSchema: new ByteArraySchema(),
544
+ },
545
+ ])
546
+ )
547
+ ),
548
+ },
549
+ ])
550
+ )
551
+ )
552
+ ),
553
+ },
407
554
  { key: 'apap', valueSchema: new OptionalSchema(new ByteArraySchema()) },
408
555
  { key: 'apsu', valueSchema: new OptionalSchema(new ByteArraySchema()) },
409
556
  {
@@ -702,6 +849,12 @@ export class Transaction implements encoding.Encodable {
702
849
  boxes: ensureArray(params.appCallParams.boxes ?? []).map(
703
850
  ensureBoxReference
704
851
  ),
852
+ access: ensureArray(params.appCallParams.access ?? []).map(
853
+ ensureResourceReference
854
+ ),
855
+ rejectVersion: utils.ensureSafeUnsignedInteger(
856
+ params.appCallParams.rejectVersion ?? 0
857
+ ),
705
858
  };
706
859
  }
707
860
 
@@ -829,6 +982,13 @@ export class Transaction implements encoding.Encodable {
829
982
  this.applicationCall.appIndex
830
983
  )
831
984
  );
985
+ data.set(
986
+ 'al',
987
+ resourceReferencesToEncodingData(
988
+ this.applicationCall.appIndex,
989
+ this.applicationCall.access
990
+ )
991
+ );
832
992
  data.set('apap', this.applicationCall.approvalProgram);
833
993
  data.set('apsu', this.applicationCall.clearProgram);
834
994
  data.set(
@@ -846,6 +1006,7 @@ export class Transaction implements encoding.Encodable {
846
1006
  ])
847
1007
  );
848
1008
  data.set('apep', this.applicationCall.extraPages);
1009
+ data.set('aprv', this.applicationCall.rejectVersion);
849
1010
  return data;
850
1011
  }
851
1012
 
@@ -990,6 +1151,7 @@ export class Transaction implements encoding.Encodable {
990
1151
  approvalProgram: data.get('apap'),
991
1152
  clearProgram: data.get('apsu'),
992
1153
  extraPages: data.get('apep'),
1154
+ rejectVersion: data.get('aprv') ?? 0,
993
1155
  };
994
1156
  const localSchema = data.get('apls') as Map<string, number> | undefined;
995
1157
  if (localSchema) {
@@ -1030,6 +1192,12 @@ export class Transaction implements encoding.Encodable {
1030
1192
  };
1031
1193
  });
1032
1194
  }
1195
+ const references = data.get('al') as
1196
+ | Array<Map<string, unknown>>
1197
+ | undefined;
1198
+ if (references) {
1199
+ appCallParams.access = convertIndicesToResourceReferences(references);
1200
+ }
1033
1201
  params.appCallParams = appCallParams;
1034
1202
  } else if (params.type === TransactionType.stpf) {
1035
1203
  const stateProofParams: StateProofTransactionParams = {
@@ -181,6 +181,86 @@ export interface BoxReference {
181
181
  name: Uint8Array;
182
182
  }
183
183
 
184
+ /**
185
+ * A grouping of the asset index and address of the account
186
+ */
187
+ export interface HoldingReference {
188
+ /**
189
+ * The asset index of the holding
190
+ */
191
+ assetIndex: number | bigint;
192
+
193
+ /**
194
+ * The address of the account holding the asset
195
+ */
196
+ address: string | Address;
197
+ }
198
+
199
+ /** A grouping of the application index and address of the account
200
+ */
201
+ export interface LocalsReference {
202
+ /**
203
+ * The application index of the local state
204
+ */
205
+ appIndex: number | bigint;
206
+
207
+ /**
208
+ * The address of the account holding the local state
209
+ */
210
+ address: string | Address;
211
+ }
212
+
213
+ /**
214
+ * Parameters for resource references in application transactions
215
+ */
216
+ export interface ApplicationCallReferenceParams {
217
+ /**
218
+ * A grouping of the asset index and address of the account
219
+ */
220
+ holdings?: HoldingReference[];
221
+
222
+ /** A grouping of the application index and address of the account
223
+ */
224
+ locals?: LocalsReference[];
225
+
226
+ /**
227
+ * If true, use the foreign accounts, apps, assets, boxes, holdings, and locals fields to construct the access list
228
+ */
229
+ convertToAccess?: boolean;
230
+ }
231
+
232
+ export interface ResourceReference {
233
+ /**
234
+ * Address string, any additional accounts to supply to the application
235
+ */
236
+ address?: string | Address;
237
+
238
+ /**
239
+ * Asset index uniquely specifying the asset
240
+ */
241
+ assetIndex?: number | bigint;
242
+
243
+ /**
244
+ * A unique application ID
245
+ */
246
+ appIndex?: number | bigint;
247
+
248
+ /**
249
+ * Holding definition: asset ID and account address
250
+ */
251
+ holding?: HoldingReference;
252
+
253
+ /**
254
+ * Local state definition: application ID and account address
255
+ */
256
+ locals?: LocalsReference;
257
+
258
+ /**
259
+ * Box definition: application ID and a name of the box
260
+ */
261
+ box?: BoxReference;
262
+ }
263
+
184
264
  /**
185
265
  * Contains payment transaction parameters.
186
266
  *
@@ -451,6 +531,17 @@ export interface ApplicationCallTransactionParams {
451
531
  * A grouping of the app ID and name of the box in an Uint8Array
452
532
  */
453
533
  boxes?: BoxReference[];
534
+
535
+ /**
536
+ * Resources accessed by the application
537
+ */
538
+ access?: ResourceReference[];
539
+
540
+ /**
541
+ * The lowest application version for which this transaction should immediately fail.
542
+ * 0 indicates that no version check should be performed.
543
+ */
544
+ rejectVersion?: number | bigint;
454
545
  }
455
546
 
456
547
  /**