algosdk 3.0.0 → 3.2.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 (52) 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/abi/abi_type.js +9 -7
  5. package/dist/cjs/abi/abi_type.js.map +1 -1
  6. package/dist/cjs/client/v2/algod/block.js +21 -0
  7. package/dist/cjs/client/v2/algod/block.js.map +1 -1
  8. package/dist/cjs/client/v2/indexer/indexer.js +15 -0
  9. package/dist/cjs/client/v2/indexer/indexer.js.map +1 -1
  10. package/dist/cjs/client/v2/indexer/models/types.js +227 -3
  11. package/dist/cjs/client/v2/indexer/models/types.js.map +1 -1
  12. package/dist/cjs/client/v2/indexer/searchForBlockHeaders.js +217 -0
  13. package/dist/cjs/client/v2/indexer/searchForBlockHeaders.js.map +1 -0
  14. package/dist/cjs/heartbeat.js +119 -0
  15. package/dist/cjs/heartbeat.js.map +1 -0
  16. package/dist/cjs/transaction.js +36 -0
  17. package/dist/cjs/transaction.js.map +1 -1
  18. package/dist/cjs/types/transactions/base.js +6 -1
  19. package/dist/cjs/types/transactions/base.js.map +1 -1
  20. package/dist/esm/abi/abi_type.js +10 -8
  21. package/dist/esm/abi/abi_type.js.map +1 -1
  22. package/dist/esm/client/v2/algod/block.js +21 -0
  23. package/dist/esm/client/v2/algod/block.js.map +1 -1
  24. package/dist/esm/client/v2/indexer/indexer.js +15 -0
  25. package/dist/esm/client/v2/indexer/indexer.js.map +1 -1
  26. package/dist/esm/client/v2/indexer/models/types.js +222 -1
  27. package/dist/esm/client/v2/indexer/models/types.js.map +1 -1
  28. package/dist/esm/client/v2/indexer/searchForBlockHeaders.js +211 -0
  29. package/dist/esm/client/v2/indexer/searchForBlockHeaders.js.map +1 -0
  30. package/dist/esm/heartbeat.js +114 -0
  31. package/dist/esm/heartbeat.js.map +1 -0
  32. package/dist/esm/transaction.js +36 -0
  33. package/dist/esm/transaction.js.map +1 -1
  34. package/dist/esm/types/transactions/base.js +6 -1
  35. package/dist/esm/types/transactions/base.js.map +1 -1
  36. package/dist/types/abi/abi_type.d.ts +13 -1
  37. package/dist/types/client/v2/algod/block.d.ts +18 -0
  38. package/dist/types/client/v2/indexer/indexer.d.ts +13 -0
  39. package/dist/types/client/v2/indexer/models/types.d.ts +146 -1
  40. package/dist/types/client/v2/indexer/searchForBlockHeaders.d.ts +176 -0
  41. package/dist/types/heartbeat.d.ts +39 -0
  42. package/dist/types/transaction.d.ts +9 -0
  43. package/dist/types/types/transactions/base.d.ts +32 -1
  44. package/package.json +2 -2
  45. package/src/abi/abi_type.ts +16 -9
  46. package/src/client/v2/algod/block.ts +22 -0
  47. package/src/client/v2/indexer/indexer.ts +16 -0
  48. package/src/client/v2/indexer/models/types.ts +375 -0
  49. package/src/client/v2/indexer/searchForBlockHeaders.ts +223 -0
  50. package/src/heartbeat.ts +168 -0
  51. package/src/transaction.ts +46 -0
  52. package/src/types/transactions/base.ts +43 -1
@@ -0,0 +1,168 @@
1
+ import { Address } from './encoding/address.js';
2
+ import { Encodable, Schema } from './encoding/encoding.js';
3
+ import {
4
+ AddressSchema,
5
+ Uint64Schema,
6
+ ByteArraySchema,
7
+ FixedLengthByteArraySchema,
8
+ NamedMapSchema,
9
+ allOmitEmpty,
10
+ } from './encoding/schema/index.js';
11
+
12
+ export class HeartbeatProof implements Encodable {
13
+ public static readonly encodingSchema = new NamedMapSchema(
14
+ allOmitEmpty([
15
+ {
16
+ key: 's', // Sig
17
+ valueSchema: new FixedLengthByteArraySchema(64),
18
+ },
19
+ {
20
+ key: 'p', // PK
21
+ valueSchema: new FixedLengthByteArraySchema(32),
22
+ },
23
+ {
24
+ key: 'p2', // PK2
25
+ valueSchema: new FixedLengthByteArraySchema(32),
26
+ },
27
+ {
28
+ key: 'p1s', // PK1Sig
29
+ valueSchema: new FixedLengthByteArraySchema(64),
30
+ },
31
+ {
32
+ key: 'p2s', // PK2Sig
33
+ valueSchema: new FixedLengthByteArraySchema(64),
34
+ },
35
+ ])
36
+ );
37
+
38
+ public sig: Uint8Array;
39
+
40
+ public pk: Uint8Array;
41
+
42
+ public pk2: Uint8Array;
43
+
44
+ public pk1Sig: Uint8Array;
45
+
46
+ public pk2Sig: Uint8Array;
47
+
48
+ public constructor(params: {
49
+ sig: Uint8Array;
50
+ pk: Uint8Array;
51
+ pk2: Uint8Array;
52
+ pk1Sig: Uint8Array;
53
+ pk2Sig: Uint8Array;
54
+ }) {
55
+ this.sig = params.sig;
56
+ this.pk = params.pk;
57
+ this.pk2 = params.pk2;
58
+ this.pk1Sig = params.pk1Sig;
59
+ this.pk2Sig = params.pk2Sig;
60
+ }
61
+
62
+ // eslint-disable-next-line class-methods-use-this
63
+ public getEncodingSchema(): Schema {
64
+ return HeartbeatProof.encodingSchema;
65
+ }
66
+
67
+ public toEncodingData(): Map<string, unknown> {
68
+ return new Map<string, unknown>([
69
+ ['s', this.sig],
70
+ ['p', this.pk],
71
+ ['p2', this.pk2],
72
+ ['p1s', this.pk1Sig],
73
+ ['p2s', this.pk2Sig],
74
+ ]);
75
+ }
76
+
77
+ public static fromEncodingData(data: unknown): HeartbeatProof {
78
+ if (!(data instanceof Map)) {
79
+ throw new Error(`Invalid decoded HeartbeatProof: ${data}`);
80
+ }
81
+ return new HeartbeatProof({
82
+ sig: data.get('s'),
83
+ pk: data.get('p'),
84
+ pk2: data.get('p2'),
85
+ pk1Sig: data.get('p1s'),
86
+ pk2Sig: data.get('p2s'),
87
+ });
88
+ }
89
+ }
90
+
91
+ export class Heartbeat implements Encodable {
92
+ public static readonly encodingSchema = new NamedMapSchema(
93
+ allOmitEmpty([
94
+ {
95
+ key: 'a', // HbAddress
96
+ valueSchema: new AddressSchema(),
97
+ },
98
+ {
99
+ key: 'prf', // HbProof
100
+ valueSchema: HeartbeatProof.encodingSchema,
101
+ },
102
+ {
103
+ key: 'sd', // HbSeed
104
+ valueSchema: new ByteArraySchema(),
105
+ },
106
+ {
107
+ key: 'vid', // HbVoteID
108
+ valueSchema: new FixedLengthByteArraySchema(32),
109
+ },
110
+ {
111
+ key: 'kd', // HbKeyDilution
112
+ valueSchema: new Uint64Schema(),
113
+ },
114
+ ])
115
+ );
116
+
117
+ public address: Address;
118
+
119
+ public proof: HeartbeatProof;
120
+
121
+ public seed: Uint8Array;
122
+
123
+ public voteID: Uint8Array;
124
+
125
+ public keyDilution: bigint;
126
+
127
+ public constructor(params: {
128
+ address: Address;
129
+ proof: HeartbeatProof;
130
+ seed: Uint8Array;
131
+ voteID: Uint8Array;
132
+ keyDilution: bigint;
133
+ }) {
134
+ this.address = params.address;
135
+ this.proof = params.proof;
136
+ this.seed = params.seed;
137
+ this.voteID = params.voteID;
138
+ this.keyDilution = params.keyDilution;
139
+ }
140
+
141
+ // eslint-disable-next-line class-methods-use-this
142
+ public getEncodingSchema(): Schema {
143
+ return Heartbeat.encodingSchema;
144
+ }
145
+
146
+ public toEncodingData(): Map<string, unknown> {
147
+ return new Map<string, unknown>([
148
+ ['a', this.address],
149
+ ['prf', this.proof.toEncodingData()],
150
+ ['sd', this.seed],
151
+ ['vid', this.voteID],
152
+ ['kd', this.keyDilution],
153
+ ]);
154
+ }
155
+
156
+ public static fromEncodingData(data: unknown): Heartbeat {
157
+ if (!(data instanceof Map)) {
158
+ throw new Error(`Invalid decoded Heartbeat: ${data}`);
159
+ }
160
+ return new Heartbeat({
161
+ address: data.get('a'),
162
+ proof: HeartbeatProof.fromEncodingData(data.get('prf')),
163
+ seed: data.get('sd'),
164
+ voteID: data.get('vid'),
165
+ keyDilution: data.get('kd'),
166
+ });
167
+ }
168
+ }
@@ -30,8 +30,10 @@ import {
30
30
  KeyRegistrationTransactionParams,
31
31
  ApplicationCallTransactionParams,
32
32
  StateProofTransactionParams,
33
+ HeartbeatTransactionParams,
33
34
  } from './types/transactions/base.js';
34
35
  import { StateProof, StateProofMessage } from './stateproof.js';
36
+ import { Heartbeat, HeartbeatProof } from './heartbeat.js';
35
37
  import * as utils from './utils/utils.js';
36
38
 
37
39
  const ALGORAND_TRANSACTION_LENGTH = 52;
@@ -248,6 +250,14 @@ export interface StateProofTransactionFields {
248
250
  readonly message?: StateProofMessage;
249
251
  }
250
252
 
253
+ export interface HeartbeatTransactionFields {
254
+ readonly address: Address;
255
+ readonly proof: HeartbeatProof;
256
+ readonly seed: Uint8Array;
257
+ readonly voteID: Uint8Array;
258
+ readonly keyDilution: bigint;
259
+ }
260
+
251
261
  /**
252
262
  * Transaction enables construction of Algorand transactions
253
263
  * */
@@ -438,6 +448,8 @@ export class Transaction implements encoding.Encodable {
438
448
  key: 'spmsg',
439
449
  valueSchema: new OptionalSchema(StateProofMessage.encodingSchema),
440
450
  },
451
+ // Heartbeat
452
+ { key: 'hb', valueSchema: new OptionalSchema(Heartbeat.encodingSchema) },
441
453
  ])
442
454
  );
443
455
 
@@ -466,6 +478,7 @@ export class Transaction implements encoding.Encodable {
466
478
  public readonly assetFreeze?: AssetFreezeTransactionFields;
467
479
  public readonly applicationCall?: ApplicationTransactionFields;
468
480
  public readonly stateProof?: StateProofTransactionFields;
481
+ public readonly heartbeat?: HeartbeatTransactionFields;
469
482
 
470
483
  constructor(params: TransactionParams) {
471
484
  if (!isTransactionType(params.type)) {
@@ -506,6 +519,7 @@ export class Transaction implements encoding.Encodable {
506
519
  if (params.assetFreezeParams) fieldsPresent.push(TransactionType.afrz);
507
520
  if (params.appCallParams) fieldsPresent.push(TransactionType.appl);
508
521
  if (params.stateProofParams) fieldsPresent.push(TransactionType.stpf);
522
+ if (params.heartbeatParams) fieldsPresent.push(TransactionType.hb);
509
523
 
510
524
  if (fieldsPresent.length !== 1) {
511
525
  throw new Error(
@@ -701,6 +715,16 @@ export class Transaction implements encoding.Encodable {
701
715
  };
702
716
  }
703
717
 
718
+ if (params.heartbeatParams) {
719
+ this.heartbeat = new Heartbeat({
720
+ address: params.heartbeatParams.address,
721
+ proof: params.heartbeatParams.proof,
722
+ seed: params.heartbeatParams.seed,
723
+ voteID: params.heartbeatParams.voteID,
724
+ keyDilution: params.heartbeatParams.keyDilution,
725
+ });
726
+ }
727
+
704
728
  // Determine fee
705
729
  this.fee = utils.ensureUint64(params.suggestedParams.fee);
706
730
 
@@ -842,6 +866,18 @@ export class Transaction implements encoding.Encodable {
842
866
  return data;
843
867
  }
844
868
 
869
+ if (this.heartbeat) {
870
+ const heartbeat = new Heartbeat({
871
+ address: this.heartbeat.address,
872
+ proof: this.heartbeat.proof,
873
+ seed: this.heartbeat.seed,
874
+ voteID: this.heartbeat.voteID,
875
+ keyDilution: this.heartbeat.keyDilution,
876
+ });
877
+ data.set('hb', heartbeat.toEncodingData());
878
+ return data;
879
+ }
880
+
845
881
  throw new Error(`Unexpected transaction type: ${this.type}`);
846
882
  }
847
883
 
@@ -1006,6 +1042,16 @@ export class Transaction implements encoding.Encodable {
1006
1042
  : undefined,
1007
1043
  };
1008
1044
  params.stateProofParams = stateProofParams;
1045
+ } else if (params.type === TransactionType.hb) {
1046
+ const heartbeat = Heartbeat.fromEncodingData(data.get('hb'));
1047
+ const heartbeatParams: HeartbeatTransactionParams = {
1048
+ address: heartbeat.address,
1049
+ proof: heartbeat.proof,
1050
+ seed: heartbeat.seed,
1051
+ voteID: heartbeat.voteID,
1052
+ keyDilution: heartbeat.keyDilution,
1053
+ };
1054
+ params.heartbeatParams = heartbeatParams;
1009
1055
  } else {
1010
1056
  const exhaustiveCheck: never = params.type;
1011
1057
  throw new Error(`Unexpected transaction type: ${exhaustiveCheck}`);
@@ -1,5 +1,6 @@
1
1
  import { Address } from '../../encoding/address.js';
2
2
  import { StateProof, StateProofMessage } from '../../stateproof.js';
3
+ import { HeartbeatProof } from '../../heartbeat.js';
3
4
 
4
5
  /**
5
6
  * Enum for application transaction types.
@@ -38,6 +39,11 @@ export enum TransactionType {
38
39
  * State proof transaction
39
40
  */
40
41
  stpf = 'stpf',
42
+
43
+ /**
44
+ * Heartbeat transaction
45
+ */
46
+ hb = 'hb',
41
47
  }
42
48
 
43
49
  /**
@@ -53,7 +59,8 @@ export function isTransactionType(s: string): s is TransactionType {
53
59
  s === TransactionType.axfer ||
54
60
  s === TransactionType.afrz ||
55
61
  s === TransactionType.appl ||
56
- s === TransactionType.stpf
62
+ s === TransactionType.stpf ||
63
+ s === TransactionType.hb
57
64
  );
58
65
  }
59
66
 
@@ -466,6 +473,36 @@ export interface StateProofTransactionParams {
466
473
  message?: StateProofMessage;
467
474
  }
468
475
 
476
+ /**
477
+ * Contains heartbeat transaction parameters.
478
+ */
479
+ export interface HeartbeatTransactionParams {
480
+ /*
481
+ * Account address this txn is proving onlineness for
482
+ */
483
+ address: Address;
484
+
485
+ /**
486
+ * Signature using HeartbeatAddress's partkey, thereby showing it is online.
487
+ */
488
+ proof: HeartbeatProof;
489
+
490
+ /**
491
+ * The block seed for the this transaction's firstValid block.
492
+ */
493
+ seed: Uint8Array;
494
+
495
+ /**
496
+ * Must match the hbAddress account's current VoteID
497
+ */
498
+ voteID: Uint8Array;
499
+
500
+ /**
501
+ * Must match hbAddress account's current KeyDilution.
502
+ */
503
+ keyDilution: bigint;
504
+ }
505
+
469
506
  /**
470
507
  * A full list of all available transaction parameters
471
508
  *
@@ -540,4 +577,9 @@ export interface TransactionParams {
540
577
  * State proof transaction parameters. Only set if type is TransactionType.stpf
541
578
  */
542
579
  stateProofParams?: StateProofTransactionParams;
580
+
581
+ /**
582
+ * Heartbeat transaction parameters. Only set if type is TransactionType.hb
583
+ */
584
+ heartbeatParams?: HeartbeatTransactionParams;
543
585
  }