algosdk 3.7.0 → 3.8.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 (61) 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/client/v2/algod/getPeers.js +20 -0
  5. package/dist/cjs/client/v2/algod/getPeers.js.map +1 -0
  6. package/dist/cjs/ed25519-signer.js +18 -0
  7. package/dist/cjs/ed25519-signer.js.map +1 -1
  8. package/dist/cjs/encoding/address.js +9 -0
  9. package/dist/cjs/encoding/address.js.map +1 -1
  10. package/dist/cjs/falcon-signer.js +16 -0
  11. package/dist/cjs/falcon-signer.js.map +1 -1
  12. package/dist/cjs/logicsig.js +86 -6
  13. package/dist/cjs/logicsig.js.map +1 -1
  14. package/dist/cjs/mnemonic/mnemonic.js +2 -0
  15. package/dist/cjs/mnemonic/mnemonic.js.map +1 -1
  16. package/dist/cjs/pq-signer.js +25 -0
  17. package/dist/cjs/pq-signer.js.map +1 -1
  18. package/dist/cjs/signer.js.map +1 -1
  19. package/dist/cjs/signing.js +22 -0
  20. package/dist/cjs/signing.js.map +1 -1
  21. package/dist/cjs/types/block.js +28 -0
  22. package/dist/cjs/types/block.js.map +1 -1
  23. package/dist/esm/client/v2/algod/getPeers.js +14 -0
  24. package/dist/esm/client/v2/algod/getPeers.js.map +1 -0
  25. package/dist/esm/ed25519-signer.js +18 -0
  26. package/dist/esm/ed25519-signer.js.map +1 -1
  27. package/dist/esm/encoding/address.js +9 -0
  28. package/dist/esm/encoding/address.js.map +1 -1
  29. package/dist/esm/falcon-signer.js +16 -0
  30. package/dist/esm/falcon-signer.js.map +1 -1
  31. package/dist/esm/logicsig.js +86 -6
  32. package/dist/esm/logicsig.js.map +1 -1
  33. package/dist/esm/mnemonic/mnemonic.js +2 -0
  34. package/dist/esm/mnemonic/mnemonic.js.map +1 -1
  35. package/dist/esm/pq-signer.js +25 -0
  36. package/dist/esm/pq-signer.js.map +1 -1
  37. package/dist/esm/signer.js.map +1 -1
  38. package/dist/esm/signing.js +22 -0
  39. package/dist/esm/signing.js.map +1 -1
  40. package/dist/esm/types/block.js +28 -0
  41. package/dist/esm/types/block.js.map +1 -1
  42. package/dist/types/client/v2/algod/getPeers.d.ts +7 -0
  43. package/dist/types/ed25519-signer.d.ts +29 -0
  44. package/dist/types/encoding/address.d.ts +9 -0
  45. package/dist/types/falcon-signer.d.ts +27 -0
  46. package/dist/types/logicsig.d.ts +91 -6
  47. package/dist/types/mnemonic/mnemonic.d.ts +2 -0
  48. package/dist/types/pq-signer.d.ts +37 -0
  49. package/dist/types/signer.d.ts +68 -5
  50. package/dist/types/signing.d.ts +22 -0
  51. package/dist/types/types/block.d.ts +22 -0
  52. package/package.json +1 -1
  53. package/src/ed25519-signer.ts +29 -0
  54. package/src/encoding/address.ts +9 -0
  55. package/src/falcon-signer.ts +27 -0
  56. package/src/logicsig.ts +93 -6
  57. package/src/mnemonic/mnemonic.ts +2 -0
  58. package/src/pq-signer.ts +37 -0
  59. package/src/signer.ts +68 -5
  60. package/src/signing.ts +22 -0
  61. package/src/types/block.ts +54 -0
package/src/signer.ts CHANGED
@@ -36,10 +36,25 @@ export type TransactionSigner = (
36
36
  indexesToSign: number[]
37
37
  ) => Promise<Uint8Array[]>;
38
38
 
39
+ /**
40
+ * An address paired with a signer able to sign transactions on its behalf.
41
+ *
42
+ * @remarks
43
+ * `address` is the address transactions are sent from, which is not necessarily
44
+ * the address that authorizes them: for a rekeyed account the two differ, and
45
+ * `txnSigner` sets the transaction's `sgnr` field accordingly.
46
+ */
39
47
  export interface AddressWithTransactionSigner extends Addressable {
40
48
  txnSigner: TransactionSigner;
41
49
  }
42
50
 
51
+ /**
52
+ * An address paired with a signer that produces placeholder signatures for it.
53
+ *
54
+ * @remarks
55
+ * Useful for post-quantum accounts, whose real signatures are large and slow to
56
+ * produce, when only a simulation of the group is needed.
57
+ */
43
58
  export interface AddressWithEmptyTransactionSigner extends Addressable {
44
59
  /**
45
60
  * A TransactionSigner that produces unsigned (or placeholder-signed)
@@ -49,11 +64,26 @@ export interface AddressWithEmptyTransactionSigner extends Addressable {
49
64
  emptyTxnSigner: TransactionSigner;
50
65
  }
51
66
 
52
- /** Function for signing logic signatures for delegation
53
- * @param lsig - The logic signature that is being signed for delegation
54
- * @param msig - Optional multisig account that should be set when a public key is signing as a subsigner of a multisig
55
- * @returns The address of the delegator
56
- * */
67
+ /**
68
+ * This type represents a function which can sign a LogicSig for delegation.
69
+ *
70
+ * @remarks
71
+ * Exactly one of `sig`, `lmsig` and `pqsig` is returned, according to the kind
72
+ * of key the signer holds and whether `msig` was supplied:
73
+ *
74
+ * - `sig` - an ed25519 signature from a single delegating account
75
+ * - `lmsig` - a multisig containing this signer's subsignature, returned when
76
+ * `msig` is supplied
77
+ * - `pqsig` - a post-quantum signature from a single delegating account
78
+ *
79
+ * @param lsig - The logic signature that is being signed for delegation
80
+ * @param msig - Optional multisig account that should be set when a public key is signing as a subsigner of a multisig
81
+ * @returns A promise which resolves to the signature and the address that
82
+ * produced it. When `msig` is omitted this is the delegating account; when
83
+ * `msig` is supplied it is the individual subsigner rather than the multisig.
84
+ * Either way it is an authorizing address, which is not necessarily the
85
+ * address the signer sends transactions from.
86
+ */
57
87
  export type DelegatedLsigSigner = (
58
88
  lsig: LogicSig,
59
89
  msig?: MultisigMetadata
@@ -65,21 +95,54 @@ export type DelegatedLsigSigner = (
65
95
  )
66
96
  >;
67
97
 
98
+ /**
99
+ * An address paired with a signer able to delegate a LogicSig to it.
100
+ */
68
101
  export interface AddressWithDelegatedLsigSigner extends Addressable {
69
102
  delegatedLsigSigner: DelegatedLsigSigner;
70
103
  }
71
104
 
105
+ /**
106
+ * This type represents a function which can sign arbitrary bytes, for use with
107
+ * {@link verifyBytes}.
108
+ *
109
+ * @remarks
110
+ * The implementation is responsible for prepending the "MX" domain-separation
111
+ * prefix ({@link SIGN_BYTES_PREFIX}) before signing, so `bytesToSign` is the
112
+ * caller's bytes alone.
113
+ *
114
+ * @param bytesToSign - The bytes to sign, without any domain-separation prefix
115
+ * @returns A promise which resolves to the raw signature
116
+ */
72
117
  export type MxBytesSigner = (bytesToSign: Uint8Array) => Promise<Uint8Array>;
73
118
 
119
+ /**
120
+ * An address paired with a signer able to sign arbitrary bytes on its behalf.
121
+ */
74
122
  export interface AddressWithMxBytesSigner extends Addressable {
75
123
  mxBytesSigner: MxBytesSigner;
76
124
  }
77
125
 
126
+ /**
127
+ * This type represents a function which can sign data for use with the
128
+ * `ed25519verify` opcode from within a LogicSig's program.
129
+ *
130
+ * @remarks
131
+ * The implementation is responsible for prepending the "ProgData" prefix
132
+ * ({@link SIGN_PROGRAM_DATA_PREFIX}) and the LogicSig's address before signing.
133
+ *
134
+ * @param data - The data to sign, without any prefix
135
+ * @param lsig - The LogicSig whose program will verify the signature
136
+ * @returns A promise which resolves to the raw signature
137
+ */
78
138
  export type ProgramDataSigner = (
79
139
  data: Uint8Array,
80
140
  lsig: LogicSig
81
141
  ) => Promise<Uint8Array>;
82
142
 
143
+ /**
144
+ * An address paired with a signer able to sign program data on its behalf.
145
+ */
83
146
  export interface AddressWithProgramDataSigner extends Addressable {
84
147
  programDataSigner: ProgramDataSigner;
85
148
  }
package/src/signing.ts CHANGED
@@ -8,6 +8,11 @@ import { LogicSig, LogicSigAccount, sanityCheckProgram } from './logicsig.js';
8
8
  import { addressFromMultisigPreImg } from './multisig.js';
9
9
  import type { TransactionSigner } from './signer.js';
10
10
 
11
+ /**
12
+ * The domain-separation prefix prepended to arbitrary bytes before signing them
13
+ * with {@link signBytes}, so that such a signature can never be mistaken for a
14
+ * signature over a transaction or a program.
15
+ */
11
16
  export const SIGN_BYTES_PREFIX = Uint8Array.from([77, 88]); // "MX"
12
17
 
13
18
  /**
@@ -34,6 +39,23 @@ export function signTransaction(txn: Transaction, sk: Uint8Array) {
34
39
  };
35
40
  }
36
41
 
42
+ /**
43
+ * signTransactionWithSigner signs a single transaction with the given signer.
44
+ *
45
+ * @remarks
46
+ * This is the replacement for the deprecated {@link signTransaction}, which can
47
+ * only sign with a raw ed25519 secret key. Because a `TransactionSigner` signs
48
+ * a group, the transaction is passed as a one-element group and the single
49
+ * result is returned.
50
+ *
51
+ * The decoded `stxn` is returned alongside the blob so callers can read what
52
+ * the signer produced — its `sig`, `pqsig` or `msig` field, and the `sgnr` field
53
+ * naming the key that signed when it is not the transaction sender.
54
+ *
55
+ * @param txn - the transaction to sign
56
+ * @param signer - the signer to sign with
57
+ * @returns an object with blob, txID and stxn properties
58
+ */
37
59
  export async function signTransactionWithSigner(
38
60
  txn: Transaction,
39
61
  signer: TransactionSigner
@@ -112,6 +112,10 @@ export class TxnCommitments implements Encodable {
112
112
  key: 'txn256', // sha256Commitment
113
113
  valueSchema: new FixedLengthByteArraySchema(32),
114
114
  },
115
+ {
116
+ key: 'txn512', // sha512Commitment
117
+ valueSchema: new FixedLengthByteArraySchema(64),
118
+ },
115
119
  ])
116
120
  );
117
121
 
@@ -126,12 +130,19 @@ export class TxnCommitments implements Encodable {
126
130
  */
127
131
  public sha256Commitment: Uint8Array;
128
132
 
133
+ /**
134
+ * Root of transaction vector commitment merkle tree using SHA512 hash function
135
+ */
136
+ public sha512Commitment: Uint8Array;
137
+
129
138
  constructor(params: {
130
139
  nativeSha512_256Commitment: Uint8Array;
131
140
  sha256Commitment: Uint8Array;
141
+ sha512Commitment?: Uint8Array;
132
142
  }) {
133
143
  this.nativeSha512_256Commitment = params.nativeSha512_256Commitment;
134
144
  this.sha256Commitment = params.sha256Commitment;
145
+ this.sha512Commitment = params.sha512Commitment ?? new Uint8Array(64);
135
146
  }
136
147
 
137
148
  // eslint-disable-next-line class-methods-use-this
@@ -143,6 +154,7 @@ export class TxnCommitments implements Encodable {
143
154
  return new Map<string, unknown>([
144
155
  ['txn', this.nativeSha512_256Commitment],
145
156
  ['txn256', this.sha256Commitment],
157
+ ['txn512', this.sha512Commitment],
146
158
  ]);
147
159
  }
148
160
 
@@ -153,6 +165,7 @@ export class TxnCommitments implements Encodable {
153
165
  return new TxnCommitments({
154
166
  nativeSha512_256Commitment: data.get('txn'),
155
167
  sha256Commitment: data.get('txn256'),
168
+ sha512Commitment: data.get('txn512'),
156
169
  });
157
170
  }
158
171
  }
@@ -509,6 +522,10 @@ export class BlockHeader implements Encodable {
509
522
  key: 'prev', // branch
510
523
  valueSchema: new BlockHashSchema(),
511
524
  },
525
+ {
526
+ key: 'prev512', // branch512
527
+ valueSchema: new FixedLengthByteArraySchema(64),
528
+ },
512
529
  {
513
530
  key: 'seed', // seed
514
531
  valueSchema: new ByteArraySchema(),
@@ -574,6 +591,14 @@ export class BlockHeader implements Encodable {
574
591
  valueSchema: ParticipationUpdates.encodingSchema,
575
592
  embedded: true,
576
593
  },
594
+ {
595
+ key: 'ld', // load
596
+ valueSchema: new Uint64Schema(),
597
+ },
598
+ {
599
+ key: 'ct', // congestionTax
600
+ valueSchema: new Uint64Schema(),
601
+ },
577
602
  ])
578
603
  );
579
604
 
@@ -587,6 +612,11 @@ export class BlockHeader implements Encodable {
587
612
  */
588
613
  public branch: Uint8Array;
589
614
 
615
+ /**
616
+ * Previous block hash, using SHA-512
617
+ */
618
+ public branch512: Uint8Array;
619
+
590
620
  /**
591
621
  * Sortition seed
592
622
  */
@@ -655,9 +685,22 @@ export class BlockHeader implements Encodable {
655
685
 
656
686
  public participationUpdates: ParticipationUpdates;
657
687
 
688
+ /**
689
+ * Load is the degree to which a block is full. Currently, it is based on the number of bytes in
690
+ * the final block, compared to the maximum allowed. It is expressed as a fixed-point integer with
691
+ * 6 digits of precision. So, 1,000,000 is a completely full block.
692
+ */
693
+ public load: bigint;
694
+
695
+ /**
696
+ * CongestionTax is the fee required, beyond the MinFee, for "normal" transactions in this block.
697
+ */
698
+ public congestionTax: bigint;
699
+
658
700
  public constructor(params: {
659
701
  round: bigint;
660
702
  branch: Uint8Array;
703
+ branch512?: Uint8Array;
661
704
  seed: Uint8Array;
662
705
  txnCommitments: TxnCommitments;
663
706
  timestamp: bigint;
@@ -673,9 +716,12 @@ export class BlockHeader implements Encodable {
673
716
  txnCounter: bigint;
674
717
  stateproofTracking: Map<number, StateProofTrackingData>;
675
718
  participationUpdates: ParticipationUpdates;
719
+ load?: bigint;
720
+ congestionTax?: bigint;
676
721
  }) {
677
722
  this.round = params.round;
678
723
  this.branch = params.branch;
724
+ this.branch512 = params.branch512 ?? new Uint8Array(64);
679
725
  this.seed = params.seed;
680
726
  this.txnCommitments = params.txnCommitments;
681
727
  this.timestamp = params.timestamp;
@@ -691,6 +737,8 @@ export class BlockHeader implements Encodable {
691
737
  this.txnCounter = params.txnCounter;
692
738
  this.stateproofTracking = params.stateproofTracking;
693
739
  this.participationUpdates = params.participationUpdates;
740
+ this.load = params.load ?? BigInt(0);
741
+ this.congestionTax = params.congestionTax ?? BigInt(0);
694
742
  }
695
743
 
696
744
  // eslint-disable-next-line class-methods-use-this
@@ -702,6 +750,7 @@ export class BlockHeader implements Encodable {
702
750
  const data = new Map<string, unknown>([
703
751
  ['rnd', this.round],
704
752
  ['prev', this.branch],
753
+ ['prev512', this.branch512],
705
754
  ['seed', this.seed],
706
755
  ['ts', this.timestamp],
707
756
  ['gen', this.genesisID],
@@ -711,6 +760,8 @@ export class BlockHeader implements Encodable {
711
760
  ['bi', this.bonus],
712
761
  ['pp', this.proposerPayout],
713
762
  ['tc', this.txnCounter],
763
+ ['ld', this.load],
764
+ ['ct', this.congestionTax],
714
765
  [
715
766
  'spt',
716
767
  convertMap(this.stateproofTracking, (key, value) => [
@@ -736,6 +787,7 @@ export class BlockHeader implements Encodable {
736
787
  return new BlockHeader({
737
788
  round: data.get('rnd'),
738
789
  branch: data.get('prev'),
790
+ branch512: data.get('prev512'),
739
791
  seed: data.get('seed'),
740
792
  txnCommitments: TxnCommitments.fromEncodingData(data),
741
793
  timestamp: data.get('ts'),
@@ -757,6 +809,8 @@ export class BlockHeader implements Encodable {
757
809
  ]
758
810
  ),
759
811
  participationUpdates: ParticipationUpdates.fromEncodingData(data),
812
+ load: data.get('ld'),
813
+ congestionTax: data.get('ct'),
760
814
  });
761
815
  }
762
816
  }