algosdk 3.7.0 → 3.9.0-beta.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 (62) hide show
  1. package/README.md +5 -5
  2. package/dist/browser/algosdk.min.js +1 -1
  3. package/dist/browser/algosdk.min.js.map +1 -1
  4. package/dist/cjs/ed25519-signer.js +18 -0
  5. package/dist/cjs/ed25519-signer.js.map +1 -1
  6. package/dist/cjs/encoding/address.js +9 -0
  7. package/dist/cjs/encoding/address.js.map +1 -1
  8. package/dist/cjs/falcon-signer.js +16 -0
  9. package/dist/cjs/falcon-signer.js.map +1 -1
  10. package/dist/cjs/logicsig.js +86 -6
  11. package/dist/cjs/logicsig.js.map +1 -1
  12. package/dist/cjs/main.js +4 -2
  13. package/dist/cjs/main.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/ed25519-signer.js +18 -0
  24. package/dist/esm/ed25519-signer.js.map +1 -1
  25. package/dist/esm/encoding/address.js +9 -0
  26. package/dist/esm/encoding/address.js.map +1 -1
  27. package/dist/esm/falcon-signer.js +16 -0
  28. package/dist/esm/falcon-signer.js.map +1 -1
  29. package/dist/esm/logicsig.js +86 -6
  30. package/dist/esm/logicsig.js.map +1 -1
  31. package/dist/esm/main.js +1 -0
  32. package/dist/esm/main.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/ed25519-signer.d.ts +29 -0
  43. package/dist/types/encoding/address.d.ts +9 -0
  44. package/dist/types/falcon-signer.d.ts +27 -0
  45. package/dist/types/logicsig.d.ts +91 -6
  46. package/dist/types/main.d.ts +1 -0
  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 +120 -12
  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/main.ts +1 -0
  58. package/src/mnemonic/mnemonic.ts +2 -0
  59. package/src/pq-signer.ts +37 -0
  60. package/src/signer.ts +68 -5
  61. package/src/signing.ts +22 -0
  62. package/src/types/block.ts +54 -0
package/src/logicsig.ts CHANGED
@@ -68,8 +68,22 @@ export function sanityCheckProgram(program: Uint8Array) {
68
68
  }
69
69
  }
70
70
 
71
+ /**
72
+ * The domain-separation prefix prepended to a program before it is hashed into
73
+ * an escrow address, or signed for delegation by a single ed25519 account.
74
+ */
71
75
  export const PROGRAM_TAG = new TextEncoder().encode('Program');
76
+
77
+ /**
78
+ * The domain-separation prefix prepended to a post-quantum delegating account's
79
+ * address and a program before the program is signed for delegation.
80
+ */
72
81
  export const PQ_PROGRAM_TAG = new TextEncoder().encode('PQProgram');
82
+
83
+ /**
84
+ * The domain-separation prefix prepended to a delegating multisig account's
85
+ * address and a program before the program is signed for delegation.
86
+ */
73
87
  export const MSIG_PROGRAM_TAG = new TextEncoder().encode('MsigProgram');
74
88
 
75
89
  /**
@@ -112,6 +126,11 @@ export class LogicSig implements encoding.Encodable {
112
126
  sig?: Uint8Array;
113
127
  msig?: EncodedMultisig;
114
128
  lmsig?: EncodedMultisig;
129
+ /**
130
+ * The post-quantum delegation signature, if the delegating account is a
131
+ * post-quantum account. At most one of `sig`, `msig`, `lmsig` and `pqsig` may
132
+ * be set.
133
+ */
115
134
  pqsig?: EncodedPQSig;
116
135
 
117
136
  constructor(program: Uint8Array, programArgs?: Array<Uint8Array> | null) {
@@ -276,6 +295,11 @@ export class LogicSig implements encoding.Encodable {
276
295
  /**
277
296
  * Signs this LogicSig for delegation using the given signer.
278
297
  *
298
+ * @remarks
299
+ * Re-signing an already-signed LogicSig is allowed, and replaces the previous
300
+ * delegation signature. At most one of `sig`, `msig`, `lmsig` and `pqsig` may
301
+ * be set, so any signature left over from an earlier call is cleared.
302
+ *
279
303
  * @param signer - The signer to delegate to
280
304
  * @param msig - Optional multisig account the signer is a subsigner of
281
305
  * @returns The address the signer signed as. When `msig` is omitted this is
@@ -283,10 +307,9 @@ export class LogicSig implements encoding.Encodable {
283
307
  * subsigner, not the multisig, so the delegating account is
284
308
  * `multisigAddress(msig)`. Either way it is an authorizing address, which
285
309
  * is not necessarily the address a signer sends transactions from.
286
- *
287
- * Re-signing an already-signed LogicSig is allowed, and replaces the previous
288
- * delegation signature. At most one of `sig`, `msig`, `lmsig` and `pqsig` may
289
- * be set, so any signature left over from an earlier call is cleared.
310
+ * @throws If the signer returns a signature of the wrong kind for the
311
+ * requested delegation, or an `lmsig` whose version, threshold or public
312
+ * keys do not match `msig`
290
313
  */
291
314
  async signWithSigner(
292
315
  signer: DelegatedLsigSigner,
@@ -360,6 +383,24 @@ export class LogicSig implements encoding.Encodable {
360
383
  this.lmsig.subsig[index].s = sig;
361
384
  }
362
385
 
386
+ /**
387
+ * Appends an additional subsignature to this LogicSig's existing multisig
388
+ * delegation.
389
+ *
390
+ * @remarks
391
+ * The multisig preimage is taken from the `lmsig` already on this LogicSig,
392
+ * so {@link signWithSigner} must have been called with an `msig` argument
393
+ * first. The signer must hold a key belonging to that multisig.
394
+ *
395
+ * A signature already collected from another member is never silently
396
+ * replaced: if the signer returns a different signature for a subsig that is
397
+ * already filled in, this throws instead.
398
+ *
399
+ * @param signer - The signer to append a subsignature from
400
+ * @throws If there is no multisig on this LogicSig, if the signer returns no
401
+ * signature, a signature for a key outside the multisig, or one that
402
+ * conflicts with a signature already collected
403
+ */
363
404
  async appendToMultisigWithSigner(signer: DelegatedLsigSigner) {
364
405
  if (this.lmsig === undefined) {
365
406
  throw new Error('no multisig present');
@@ -475,8 +516,15 @@ export class LogicSig implements encoding.Encodable {
475
516
  * Signs arbitrary data for use with the `ed25519verify` opcode from within
476
517
  * this LogicSig's program.
477
518
  *
519
+ * @remarks
520
+ * This does not modify the LogicSig or delegate it; the LogicSig is only used
521
+ * for the address that domain-separates the signature. The program is
522
+ * responsible for verifying the returned signature against the signer's
523
+ * public key.
524
+ *
478
525
  * @param signer - The signer to sign the data with
479
526
  * @param data - The data to sign
527
+ * @returns A promise which resolves to the raw signature over the data
480
528
  */
481
529
  async signDataWithSigner(signer: ProgramDataSigner, data: Uint8Array) {
482
530
  return signer(data, this);
@@ -656,6 +704,22 @@ export class LogicSigAccount implements encoding.Encodable {
656
704
  this.lsig.sign(secretKey, msig);
657
705
  }
658
706
 
707
+ /**
708
+ * Turns this LogicSigAccount into a delegated LogicSig, signed by one member
709
+ * of a delegating multisig account.
710
+ *
711
+ * @remarks
712
+ * This produces a LogicSig with a single subsignature filled in. Unless the
713
+ * multisig's threshold is 1, call {@link LogicSigAccount.appendToMultisigWithSigner}
714
+ * with the remaining members' signers before the LogicSig can authorize
715
+ * transactions.
716
+ *
717
+ * If the delegating account is not a multisig, use
718
+ * {@link LogicSigAccount.signWithSigner} instead.
719
+ *
720
+ * @param msig - The multisig delegating to this LogicSig
721
+ * @param signer - The signer of one member of `msig`
722
+ */
659
723
  async signMultisigWithSigner(
660
724
  msig: MultisigMetadata,
661
725
  signer: DelegatedLsigSigner
@@ -676,6 +740,16 @@ export class LogicSigAccount implements encoding.Encodable {
676
740
  this.lsig.appendToMultisig(secretKey);
677
741
  }
678
742
 
743
+ /**
744
+ * Adds an additional signature from a member of the delegating multisig
745
+ * account.
746
+ *
747
+ * @remarks
748
+ * {@link LogicSigAccount.signMultisigWithSigner} must have been called first
749
+ * to establish the multisig this signature belongs to.
750
+ *
751
+ * @param signer - The signer of another member of the delegating multisig account
752
+ */
679
753
  async appendToMultisigWithSigner(signer: DelegatedLsigSigner) {
680
754
  await this.lsig.appendToMultisigWithSigner(signer);
681
755
  }
@@ -697,8 +771,17 @@ export class LogicSigAccount implements encoding.Encodable {
697
771
 
698
772
  /**
699
773
  * Turns this LogicSigAccount into a delegated LogicSig, signed by the given
700
- * signer. If the delegating account is a multisig account, use
701
- * `signMultisigWithSigner` instead.
774
+ * signer. This type of LogicSig has the authority to sign transactions on
775
+ * behalf of another account, called the delegating account.
776
+ *
777
+ * @remarks
778
+ * If the delegating account is a multisig account, use
779
+ * {@link LogicSigAccount.signMultisigWithSigner} instead.
780
+ *
781
+ * The delegating account is taken to be the address the signer reports having
782
+ * signed as, not any sending address the signer advertises: for a rekeyed
783
+ * account the latter is the address it sends transactions from, which is not
784
+ * the account authorizing this delegation.
702
785
  *
703
786
  * @param signer - The signer of the delegating account.
704
787
  */
@@ -720,6 +803,10 @@ export function logicSigFromByte(encoded: Uint8Array): LogicSig {
720
803
  return encoding.decodeMsgpack(encoded, LogicSig);
721
804
  }
722
805
 
806
+ /**
807
+ * The domain-separation prefix prepended, along with the program's address, to
808
+ * data signed for verification by the `ed25519verify` opcode.
809
+ */
723
810
  export const SIGN_PROGRAM_DATA_PREFIX = new TextEncoder().encode('ProgData');
724
811
 
725
812
  /**
package/src/main.ts CHANGED
@@ -67,6 +67,7 @@ export {
67
67
  } from './encoding/binarydata.js';
68
68
  export { encodeUint64, decodeUint64 } from './encoding/uint64.js';
69
69
  export { parseJSON, ParseJSONOptions, stringifyJSON } from './utils/utils.js';
70
+ export { couldBeCurvePoint } from './utils/ed25519-check.js';
70
71
  export { default as generateAccount } from './account.js';
71
72
  export * from './types/block.js';
72
73
  export * from './types/statedelta.js';
@@ -198,6 +198,8 @@ const PQ_KEY_PREFIX = new TextEncoder().encode('PQK');
198
198
  * @param mn - A 25-word Algorand mnemonic
199
199
  * @param scheme - The 2-byte ASCII PQ scheme identifier (e.g. "f1" for Falcon-1024)
200
200
  * @returns The 32-byte seed to hand to the scheme's key generator
201
+ * @throws If `mn` is not a valid 25-word mnemonic, or if `scheme` is not
202
+ * exactly {@link PQ_SCHEME_SIZE} bytes
201
203
  */
202
204
  export function pq25WordMnemonicToSeed(
203
205
  mn: string,
package/src/pq-signer.ts CHANGED
@@ -14,12 +14,49 @@ import { Transaction } from './transaction.js';
14
14
  import { EncodedPQSig } from './types/transactions/encoded.js';
15
15
  import { concatArrays } from './utils/utils.js';
16
16
 
17
+ /**
18
+ * A post-quantum public key, its scheme identifier, and a function that signs
19
+ * raw bytes with the corresponding secret key.
20
+ *
21
+ * @remarks
22
+ * `pqSigner` receives the exact bytes to sign, with every domain-separation
23
+ * prefix already applied, so it can be backed by a key that never leaves a
24
+ * wallet, HSM or hardware device.
25
+ */
17
26
  export interface PQSigningKey {
27
+ /** The 2-byte ASCII PQ scheme identifier (e.g. "f1" for Falcon-1024). */
18
28
  pqScheme: Uint8Array;
29
+ /** The scheme's canonical public key. */
19
30
  pqPublicKey: Uint8Array;
31
+ /** Signs the given bytes verbatim with the corresponding secret key. */
20
32
  pqSigner: (bytesToSign: Uint8Array) => Promise<Uint8Array>;
21
33
  }
22
34
 
35
+ /**
36
+ * Build the full set of signers for a post-quantum key from a function that
37
+ * signs raw bytes with it.
38
+ *
39
+ * @remarks
40
+ * The account address is derived from the scheme and public key via
41
+ * {@link addressFromPQKey}, so it does not have to be supplied. Every signature
42
+ * produced carries the scheme, canonical salt and public key alongside the
43
+ * signature bytes, which is what lets the network recover the authorizing
44
+ * address from the signature alone.
45
+ *
46
+ * PQ schemes cannot participate in multisig, so `delegatedLsigSigner` throws if
47
+ * given an `msig` argument, and no `mxBytesSigner` or `programDataSigner` is
48
+ * returned — signing arbitrary bytes and program data are ed25519-only
49
+ * operations.
50
+ *
51
+ * @param signingKey - The scheme, public key and raw signing function to build the signers from
52
+ * @param sendingAddress - The address transactions are sent from. Defaults to
53
+ * the derived PQ address; supply it when the PQ key is the auth address of a
54
+ * rekeyed account, in which case the produced transactions carry the derived
55
+ * address in their `sgnr` field.
56
+ * @returns An address bundled with transaction, empty transaction and delegated
57
+ * LogicSig signers
58
+ * @throws If `pqScheme` is not exactly 2 bytes
59
+ */
23
60
  export function addressWithSignersFromRawPQSigner(
24
61
  signingKey: PQSigningKey,
25
62
  sendingAddress?: Address
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
  }