algosdk 3.4.0 → 3.5.0

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 (41) 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/logicsig.js +54 -17
  9. package/dist/cjs/logicsig.js.map +1 -1
  10. package/dist/cjs/makeTxn.js +66 -12
  11. package/dist/cjs/makeTxn.js.map +1 -1
  12. package/dist/cjs/signing.js +4 -4
  13. package/dist/cjs/signing.js.map +1 -1
  14. package/dist/cjs/transaction.js +107 -0
  15. package/dist/cjs/transaction.js.map +1 -1
  16. package/dist/esm/appAccess.js +255 -0
  17. package/dist/esm/appAccess.js.map +1 -0
  18. package/dist/esm/client/v2/indexer/models/types.js +261 -6
  19. package/dist/esm/client/v2/indexer/models/types.js.map +1 -1
  20. package/dist/esm/logicsig.js +54 -17
  21. package/dist/esm/logicsig.js.map +1 -1
  22. package/dist/esm/makeTxn.js +66 -12
  23. package/dist/esm/makeTxn.js.map +1 -1
  24. package/dist/esm/signing.js +4 -4
  25. package/dist/esm/signing.js.map +1 -1
  26. package/dist/esm/transaction.js +107 -0
  27. package/dist/esm/transaction.js.map +1 -1
  28. package/dist/types/appAccess.d.ts +28 -0
  29. package/dist/types/client/v2/indexer/models/types.d.ts +157 -8
  30. package/dist/types/logicsig.d.ts +2 -0
  31. package/dist/types/makeTxn.d.ts +9 -9
  32. package/dist/types/transaction.d.ts +17 -0
  33. package/dist/types/types/transactions/base.d.ts +71 -0
  34. package/package.json +1 -1
  35. package/src/appAccess.ts +298 -0
  36. package/src/client/v2/indexer/models/types.ts +423 -5
  37. package/src/logicsig.ts +68 -17
  38. package/src/makeTxn.ts +110 -12
  39. package/src/signing.ts +4 -4
  40. package/src/transaction.ts +162 -0
  41. package/src/types/transactions/base.ts +85 -0
package/src/logicsig.ts CHANGED
@@ -60,6 +60,7 @@ export function sanityCheckProgram(program: Uint8Array) {
60
60
  }
61
61
 
62
62
  const programTag = new TextEncoder().encode('Program');
63
+ const multisigProgramTag = new TextEncoder().encode('MsigProgram');
63
64
 
64
65
  /**
65
66
  LogicSig implementation
@@ -85,6 +86,10 @@ export class LogicSig implements encoding.Encodable {
85
86
  key: 'msig',
86
87
  valueSchema: new OptionalSchema(ENCODED_MULTISIG_SCHEMA),
87
88
  },
89
+ {
90
+ key: 'lmsig',
91
+ valueSchema: new OptionalSchema(ENCODED_MULTISIG_SCHEMA),
92
+ },
88
93
  ])
89
94
  );
90
95
 
@@ -92,6 +97,7 @@ export class LogicSig implements encoding.Encodable {
92
97
  args: Uint8Array[];
93
98
  sig?: Uint8Array;
94
99
  msig?: EncodedMultisig;
100
+ lmsig?: EncodedMultisig;
95
101
 
96
102
  constructor(program: Uint8Array, programArgs?: Array<Uint8Array> | null) {
97
103
  if (
@@ -112,6 +118,7 @@ export class LogicSig implements encoding.Encodable {
112
118
  this.args = args;
113
119
  this.sig = undefined;
114
120
  this.msig = undefined;
121
+ this.lmsig = undefined;
115
122
  }
116
123
 
117
124
  // eslint-disable-next-line class-methods-use-this
@@ -128,6 +135,9 @@ export class LogicSig implements encoding.Encodable {
128
135
  if (this.msig) {
129
136
  data.set('msig', encodedMultiSigToEncodingData(this.msig));
130
137
  }
138
+ if (this.lmsig) {
139
+ data.set('lmsig', encodedMultiSigToEncodingData(this.lmsig));
140
+ }
131
141
  return data;
132
142
  }
133
143
 
@@ -140,6 +150,9 @@ export class LogicSig implements encoding.Encodable {
140
150
  if (data.get('msig')) {
141
151
  lsig.msig = encodedMultiSigFromEncodingData(data.get('msig'));
142
152
  }
153
+ if (data.get('lmsig')) {
154
+ lsig.lmsig = encodedMultiSigFromEncodingData(data.get('lmsig'));
155
+ }
143
156
  return lsig;
144
157
  }
145
158
 
@@ -148,7 +161,8 @@ export class LogicSig implements encoding.Encodable {
148
161
  * @param publicKey - Verification key (derived from sender address or escrow address)
149
162
  */
150
163
  verify(publicKey: Uint8Array) {
151
- if (this.sig && this.msig) {
164
+ const sigCount = [this.sig, this.msig, this.lmsig].filter(Boolean).length;
165
+ if (sigCount > 1) {
152
166
  return false;
153
167
  }
154
168
 
@@ -160,7 +174,7 @@ export class LogicSig implements encoding.Encodable {
160
174
 
161
175
  const toBeSigned = utils.concatArrays(programTag, this.logic);
162
176
 
163
- if (!this.sig && !this.msig) {
177
+ if (!this.sig && !this.msig && !this.lmsig) {
164
178
  const hash = nacl.genericHash(toBeSigned);
165
179
  return utils.arrayEqual(hash, publicKey);
166
180
  }
@@ -169,7 +183,25 @@ export class LogicSig implements encoding.Encodable {
169
183
  return nacl.verify(toBeSigned, this.sig, publicKey);
170
184
  }
171
185
 
172
- return verifyMultisig(toBeSigned, this.msig!, publicKey);
186
+ if (this.lmsig) {
187
+ const multisigAddr = addressFromMultisigPreImg({
188
+ version: this.lmsig.v,
189
+ threshold: this.lmsig.thr,
190
+ pks: this.lmsig.subsig.map((subsig) => subsig.pk),
191
+ });
192
+ const lmsigProgram = utils.concatArrays(
193
+ multisigProgramTag,
194
+ multisigAddr.publicKey,
195
+ this.logic
196
+ );
197
+ return verifyMultisig(lmsigProgram, this.lmsig!, publicKey);
198
+ }
199
+
200
+ if (this.msig) {
201
+ return verifyMultisig(toBeSigned, this.msig!, publicKey);
202
+ }
203
+
204
+ return false;
173
205
  }
174
206
 
175
207
  /**
@@ -193,14 +225,14 @@ export class LogicSig implements encoding.Encodable {
193
225
  } else {
194
226
  const subsigs = pksFromAddresses(msig.addrs).map((pk) => ({ pk }));
195
227
 
196
- this.msig = {
228
+ this.lmsig = {
197
229
  v: msig.version,
198
230
  thr: msig.threshold,
199
231
  subsig: subsigs,
200
232
  };
201
233
 
202
- const [sig, index] = this.singleSignMultisig(secretKey, this.msig);
203
- this.msig.subsig[index].s = sig;
234
+ const [sig, index] = this.singleSignMultisig(secretKey, this.lmsig);
235
+ this.lmsig.subsig[index].s = sig;
204
236
  }
205
237
  }
206
238
 
@@ -209,11 +241,11 @@ export class LogicSig implements encoding.Encodable {
209
241
  * @param secretKey - Secret key to sign with
210
242
  */
211
243
  appendToMultisig(secretKey: Uint8Array) {
212
- if (this.msig === undefined) {
244
+ if (this.lmsig === undefined) {
213
245
  throw new Error('no multisig present');
214
246
  }
215
- const [sig, index] = this.singleSignMultisig(secretKey, this.msig);
216
- this.msig.subsig[index].s = sig;
247
+ const [sig, index] = this.singleSignMultisig(secretKey, this.lmsig);
248
+ this.lmsig.subsig[index].s = sig;
217
249
  }
218
250
 
219
251
  signProgram(secretKey: Uint8Array) {
@@ -222,6 +254,21 @@ export class LogicSig implements encoding.Encodable {
222
254
  return sig;
223
255
  }
224
256
 
257
+ signProgramMultisig(secretKey: Uint8Array, msig: EncodedMultisig) {
258
+ const multisigAddr = addressFromMultisigPreImg({
259
+ version: msig.v,
260
+ threshold: msig.thr,
261
+ pks: msig.subsig.map((subsig) => subsig.pk),
262
+ });
263
+ const toBeSigned = utils.concatArrays(
264
+ multisigProgramTag,
265
+ multisigAddr.publicKey,
266
+ this.logic
267
+ );
268
+ const sig = nacl.sign(toBeSigned, secretKey);
269
+ return sig;
270
+ }
271
+
225
272
  singleSignMultisig(
226
273
  secretKey: Uint8Array,
227
274
  msig: EncodedMultisig
@@ -238,7 +285,7 @@ export class LogicSig implements encoding.Encodable {
238
285
  if (index === -1) {
239
286
  throw new Error('invalid secret key');
240
287
  }
241
- const sig = this.signProgram(secretKey);
288
+ const sig = this.signProgramMultisig(secretKey, msig);
242
289
  return [sig, index];
243
290
  }
244
291
 
@@ -332,7 +379,7 @@ export class LogicSigAccount implements encoding.Encodable {
332
379
  * To verify the delegation signature, use `verify`.
333
380
  */
334
381
  isDelegated() {
335
- return !!(this.lsig.sig || this.lsig.msig);
382
+ return !!(this.lsig.sig || this.lsig.msig || this.lsig.lmsig);
336
383
  }
337
384
 
338
385
  /**
@@ -354,9 +401,12 @@ export class LogicSigAccount implements encoding.Encodable {
354
401
  * escrow address that is the hash of the LogicSig's program code.
355
402
  */
356
403
  address(): Address {
357
- if (this.lsig.sig && this.lsig.msig) {
404
+ const sigCount = [this.lsig.sig, this.lsig.msig, this.lsig.lmsig].filter(
405
+ Boolean
406
+ ).length;
407
+ if (sigCount > 1) {
358
408
  throw new Error(
359
- 'LogicSig has too many signatures. At most one of sig or msig may be present'
409
+ 'LogicSig has too many signatures. At most one of sig, msig, or lmsig may be present'
360
410
  );
361
411
  }
362
412
 
@@ -367,11 +417,12 @@ export class LogicSigAccount implements encoding.Encodable {
367
417
  return new Address(this.sigkey);
368
418
  }
369
419
 
370
- if (this.lsig.msig) {
420
+ const msig = this.lsig.lmsig || this.lsig.msig;
421
+ if (msig) {
371
422
  const msigMetadata = {
372
- version: this.lsig.msig.v,
373
- threshold: this.lsig.msig.thr,
374
- pks: this.lsig.msig.subsig.map((subsig) => subsig.pk),
423
+ version: msig.v,
424
+ threshold: msig.thr,
425
+ pks: msig.subsig.map((subsig) => subsig.pk),
375
426
  };
376
427
  return addressFromMultisigPreImg(msigMetadata);
377
428
  }
package/src/makeTxn.ts CHANGED
@@ -9,8 +9,10 @@ import {
9
9
  AssetTransferTransactionParams,
10
10
  AssetFreezeTransactionParams,
11
11
  ApplicationCallTransactionParams,
12
+ ApplicationCallReferenceParams,
12
13
  } from './types/transactions/base.js';
13
14
  import { Address } from './encoding/address.js';
15
+ import { foreignArraysToResourceReferences } from './appAccess.js';
14
16
 
15
17
  /** Contains parameters common to every transaction type */
16
18
  export interface CommonTransactionParams {
@@ -397,6 +399,10 @@ export function makeApplicationCallTxnFromObject({
397
399
  foreignApps,
398
400
  foreignAssets,
399
401
  boxes,
402
+ convertToAccess,
403
+ holdings,
404
+ locals,
405
+ access,
400
406
  approvalProgram,
401
407
  clearProgram,
402
408
  numLocalInts,
@@ -408,10 +414,38 @@ export function makeApplicationCallTxnFromObject({
408
414
  lease,
409
415
  rekeyTo,
410
416
  suggestedParams,
411
- }: ApplicationCallTransactionParams & CommonTransactionParams): Transaction {
417
+ }: ApplicationCallTransactionParams &
418
+ CommonTransactionParams &
419
+ ApplicationCallReferenceParams): Transaction {
412
420
  if (onComplete == null) {
413
421
  throw Error('onComplete must be provided');
414
422
  }
423
+ if (
424
+ access &&
425
+ (accounts || foreignApps || foreignAssets || boxes || holdings || locals)
426
+ ) {
427
+ throw Error('cannot specify both access and other access fields');
428
+ }
429
+ let accounts2 = accounts;
430
+ let foreignApps2 = foreignApps;
431
+ let foreignAssets2 = foreignAssets;
432
+ let boxes2 = boxes;
433
+ let access2 = access;
434
+ if (convertToAccess) {
435
+ access2 = foreignArraysToResourceReferences({
436
+ appIndex,
437
+ accounts,
438
+ foreignApps,
439
+ foreignAssets,
440
+ holdings,
441
+ locals,
442
+ boxes,
443
+ });
444
+ accounts2 = undefined;
445
+ foreignApps2 = undefined;
446
+ foreignAssets2 = undefined;
447
+ boxes2 = undefined;
448
+ }
415
449
  return new Transaction({
416
450
  type: TransactionType.appl,
417
451
  sender,
@@ -423,10 +457,11 @@ export function makeApplicationCallTxnFromObject({
423
457
  appIndex,
424
458
  onComplete,
425
459
  appArgs,
426
- accounts,
427
- foreignAssets,
428
- foreignApps,
429
- boxes,
460
+ accounts: accounts2,
461
+ foreignAssets: foreignAssets2,
462
+ foreignApps: foreignApps2,
463
+ boxes: boxes2,
464
+ access: access2,
430
465
  approvalProgram,
431
466
  clearProgram,
432
467
  numLocalInts,
@@ -451,6 +486,10 @@ export function makeApplicationCreateTxnFromObject({
451
486
  foreignApps,
452
487
  foreignAssets,
453
488
  boxes,
489
+ convertToAccess,
490
+ holdings,
491
+ locals,
492
+ access,
454
493
  approvalProgram,
455
494
  clearProgram,
456
495
  numLocalInts,
@@ -469,7 +508,8 @@ export function makeApplicationCreateTxnFromObject({
469
508
  Required<
470
509
  Pick<ApplicationCallTransactionParams, 'approvalProgram' | 'clearProgram'>
471
510
  > &
472
- CommonTransactionParams): Transaction {
511
+ CommonTransactionParams &
512
+ ApplicationCallReferenceParams): Transaction {
473
513
  if (!approvalProgram || !clearProgram) {
474
514
  throw Error('approvalProgram and clearProgram must be provided');
475
515
  }
@@ -485,6 +525,10 @@ export function makeApplicationCreateTxnFromObject({
485
525
  foreignApps,
486
526
  foreignAssets,
487
527
  boxes,
528
+ convertToAccess,
529
+ holdings,
530
+ locals,
531
+ access,
488
532
  approvalProgram,
489
533
  clearProgram,
490
534
  numLocalInts,
@@ -512,6 +556,10 @@ export function makeApplicationUpdateTxnFromObject({
512
556
  foreignApps,
513
557
  foreignAssets,
514
558
  boxes,
559
+ convertToAccess,
560
+ holdings,
561
+ locals,
562
+ access,
515
563
  approvalProgram,
516
564
  clearProgram,
517
565
  note,
@@ -532,7 +580,8 @@ export function makeApplicationUpdateTxnFromObject({
532
580
  Required<
533
581
  Pick<ApplicationCallTransactionParams, 'approvalProgram' | 'clearProgram'>
534
582
  > &
535
- CommonTransactionParams): Transaction {
583
+ CommonTransactionParams &
584
+ ApplicationCallReferenceParams): Transaction {
536
585
  if (!appIndex) {
537
586
  throw Error('appIndex must be provided');
538
587
  }
@@ -548,6 +597,10 @@ export function makeApplicationUpdateTxnFromObject({
548
597
  foreignApps,
549
598
  foreignAssets,
550
599
  boxes,
600
+ convertToAccess,
601
+ holdings,
602
+ locals,
603
+ access,
551
604
  approvalProgram,
552
605
  clearProgram,
553
606
  note,
@@ -570,6 +623,10 @@ export function makeApplicationDeleteTxnFromObject({
570
623
  foreignApps,
571
624
  foreignAssets,
572
625
  boxes,
626
+ convertToAccess,
627
+ holdings,
628
+ locals,
629
+ access,
573
630
  note,
574
631
  lease,
575
632
  rekeyTo,
@@ -585,7 +642,8 @@ export function makeApplicationDeleteTxnFromObject({
585
642
  | 'approvalProgram'
586
643
  | 'clearProgram'
587
644
  > &
588
- CommonTransactionParams): Transaction {
645
+ CommonTransactionParams &
646
+ ApplicationCallReferenceParams): Transaction {
589
647
  if (!appIndex) {
590
648
  throw Error('appIndex must be provided');
591
649
  }
@@ -598,6 +656,10 @@ export function makeApplicationDeleteTxnFromObject({
598
656
  foreignApps,
599
657
  foreignAssets,
600
658
  boxes,
659
+ convertToAccess,
660
+ holdings,
661
+ locals,
662
+ access,
601
663
  note,
602
664
  lease,
603
665
  rekeyTo,
@@ -618,6 +680,10 @@ export function makeApplicationOptInTxnFromObject({
618
680
  foreignApps,
619
681
  foreignAssets,
620
682
  boxes,
683
+ convertToAccess,
684
+ holdings,
685
+ locals,
686
+ access,
621
687
  note,
622
688
  lease,
623
689
  rekeyTo,
@@ -633,7 +699,8 @@ export function makeApplicationOptInTxnFromObject({
633
699
  | 'approvalProgram'
634
700
  | 'clearProgram'
635
701
  > &
636
- CommonTransactionParams): Transaction {
702
+ CommonTransactionParams &
703
+ ApplicationCallReferenceParams): Transaction {
637
704
  if (!appIndex) {
638
705
  throw Error('appIndex must be provided');
639
706
  }
@@ -647,6 +714,10 @@ export function makeApplicationOptInTxnFromObject({
647
714
  foreignAssets,
648
715
  boxes,
649
716
  note,
717
+ convertToAccess,
718
+ holdings,
719
+ locals,
720
+ access,
650
721
  lease,
651
722
  rekeyTo,
652
723
  suggestedParams,
@@ -666,6 +737,10 @@ export function makeApplicationCloseOutTxnFromObject({
666
737
  foreignApps,
667
738
  foreignAssets,
668
739
  boxes,
740
+ convertToAccess,
741
+ holdings,
742
+ locals,
743
+ access,
669
744
  note,
670
745
  lease,
671
746
  rekeyTo,
@@ -681,7 +756,8 @@ export function makeApplicationCloseOutTxnFromObject({
681
756
  | 'approvalProgram'
682
757
  | 'clearProgram'
683
758
  > &
684
- CommonTransactionParams): Transaction {
759
+ CommonTransactionParams &
760
+ ApplicationCallReferenceParams): Transaction {
685
761
  if (!appIndex) {
686
762
  throw Error('appIndex must be provided');
687
763
  }
@@ -694,6 +770,10 @@ export function makeApplicationCloseOutTxnFromObject({
694
770
  foreignApps,
695
771
  foreignAssets,
696
772
  boxes,
773
+ convertToAccess,
774
+ holdings,
775
+ locals,
776
+ access,
697
777
  note,
698
778
  lease,
699
779
  rekeyTo,
@@ -714,6 +794,10 @@ export function makeApplicationClearStateTxnFromObject({
714
794
  foreignApps,
715
795
  foreignAssets,
716
796
  boxes,
797
+ convertToAccess,
798
+ holdings,
799
+ locals,
800
+ access,
717
801
  note,
718
802
  lease,
719
803
  rekeyTo,
@@ -729,7 +813,8 @@ export function makeApplicationClearStateTxnFromObject({
729
813
  | 'approvalProgram'
730
814
  | 'clearProgram'
731
815
  > &
732
- CommonTransactionParams): Transaction {
816
+ CommonTransactionParams &
817
+ ApplicationCallReferenceParams): Transaction {
733
818
  if (!appIndex) {
734
819
  throw Error('appIndex must be provided');
735
820
  }
@@ -742,6 +827,10 @@ export function makeApplicationClearStateTxnFromObject({
742
827
  foreignApps,
743
828
  foreignAssets,
744
829
  boxes,
830
+ convertToAccess,
831
+ holdings,
832
+ locals,
833
+ access,
745
834
  note,
746
835
  lease,
747
836
  rekeyTo,
@@ -762,6 +851,10 @@ export function makeApplicationNoOpTxnFromObject({
762
851
  foreignApps,
763
852
  foreignAssets,
764
853
  boxes,
854
+ convertToAccess,
855
+ holdings,
856
+ locals,
857
+ access,
765
858
  note,
766
859
  lease,
767
860
  rekeyTo,
@@ -777,7 +870,8 @@ export function makeApplicationNoOpTxnFromObject({
777
870
  | 'approvalProgram'
778
871
  | 'clearProgram'
779
872
  > &
780
- CommonTransactionParams): Transaction {
873
+ CommonTransactionParams &
874
+ ApplicationCallReferenceParams): Transaction {
781
875
  if (!appIndex) {
782
876
  throw Error('appIndex must be provided');
783
877
  }
@@ -790,6 +884,10 @@ export function makeApplicationNoOpTxnFromObject({
790
884
  foreignApps,
791
885
  foreignAssets,
792
886
  boxes,
887
+ convertToAccess,
888
+ holdings,
889
+ locals,
890
+ access,
793
891
  note,
794
892
  lease,
795
893
  rekeyTo,
package/src/signing.ts CHANGED
@@ -62,11 +62,11 @@ export function signLogicSigTransactionObject(
62
62
  // delegating account is the sender. If that's not the case, the signing
63
63
  // will fail.
64
64
  lsigAddress = new Address(txn.sender.publicKey);
65
- } else if (lsig.msig) {
65
+ } else if (lsig.lmsig) {
66
66
  const msigMetadata = {
67
- version: lsig.msig.v,
68
- threshold: lsig.msig.thr,
69
- pks: lsig.msig.subsig.map((subsig) => subsig.pk),
67
+ version: lsig.lmsig.v,
68
+ threshold: lsig.lmsig.thr,
69
+ pks: lsig.lmsig.subsig.map((subsig) => subsig.pk),
70
70
  };
71
71
  lsigAddress = addressFromMultisigPreImg(msigMetadata);
72
72
  } else {