algosdk 3.1.0 → 3.3.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 +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/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/algod/getApplicationBoxes.js +58 -1
  9. package/dist/cjs/client/v2/algod/getApplicationBoxes.js.map +1 -1
  10. package/dist/cjs/client/v2/algod/models/types.js +165 -141
  11. package/dist/cjs/client/v2/algod/models/types.js.map +1 -1
  12. package/dist/cjs/client/v2/indexer/indexer.js +15 -0
  13. package/dist/cjs/client/v2/indexer/indexer.js.map +1 -1
  14. package/dist/cjs/client/v2/indexer/models/types.js +10 -1
  15. package/dist/cjs/client/v2/indexer/models/types.js.map +1 -1
  16. package/dist/cjs/client/v2/indexer/searchAccounts.js +19 -0
  17. package/dist/cjs/client/v2/indexer/searchAccounts.js.map +1 -1
  18. package/dist/cjs/client/v2/indexer/searchForBlockHeaders.js +217 -0
  19. package/dist/cjs/client/v2/indexer/searchForBlockHeaders.js.map +1 -0
  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/algod/getApplicationBoxes.js +58 -1
  25. package/dist/esm/client/v2/algod/getApplicationBoxes.js.map +1 -1
  26. package/dist/esm/client/v2/algod/models/types.js +161 -136
  27. package/dist/esm/client/v2/algod/models/types.js.map +1 -1
  28. package/dist/esm/client/v2/indexer/indexer.js +15 -0
  29. package/dist/esm/client/v2/indexer/indexer.js.map +1 -1
  30. package/dist/esm/client/v2/indexer/models/types.js +10 -1
  31. package/dist/esm/client/v2/indexer/models/types.js.map +1 -1
  32. package/dist/esm/client/v2/indexer/searchAccounts.js +19 -0
  33. package/dist/esm/client/v2/indexer/searchAccounts.js.map +1 -1
  34. package/dist/esm/client/v2/indexer/searchForBlockHeaders.js +211 -0
  35. package/dist/esm/client/v2/indexer/searchForBlockHeaders.js.map +1 -0
  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/algod/getApplicationBoxes.d.ts +49 -1
  39. package/dist/types/client/v2/algod/models/types.d.ts +93 -83
  40. package/dist/types/client/v2/indexer/indexer.d.ts +13 -0
  41. package/dist/types/client/v2/indexer/models/types.d.ts +7 -1
  42. package/dist/types/client/v2/indexer/searchAccounts.d.ts +16 -0
  43. package/dist/types/client/v2/indexer/searchForBlockHeaders.d.ts +176 -0
  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/algod/getApplicationBoxes.ts +61 -1
  48. package/src/client/v2/algod/models/types.ts +285 -197
  49. package/src/client/v2/indexer/indexer.ts +16 -0
  50. package/src/client/v2/indexer/models/types.ts +17 -0
  51. package/src/client/v2/indexer/searchAccounts.ts +20 -0
  52. package/src/client/v2/indexer/searchForBlockHeaders.ts +223 -0
@@ -224,5 +224,21 @@ export default class SearchAccounts extends JSONRequest<AccountsResponse> {
224
224
  * @category query
225
225
  */
226
226
  exclude(exclude: string): this;
227
+ /**
228
+ * If true, only online accounts will be returned in the response.
229
+ *
230
+ * #### Example
231
+ * ```typescript
232
+ * const onlineOnly = true;
233
+ * const accounts = await indexerClient
234
+ * .searchAccounts
235
+ * .onlineOnly(onlineOnly)
236
+ * .do();
237
+ * ```
238
+ *
239
+ * @param onlineOnly - if true, only online accounts will be returned in the response
240
+ * @category query
241
+ */
242
+ onlineOnly(onlineOnly: boolean): this;
227
243
  prepare(response: HTTPClientResponse): AccountsResponse;
228
244
  }
@@ -0,0 +1,176 @@
1
+ import JSONRequest from '../jsonrequest.js';
2
+ import { HTTPClientResponse } from '../../client.js';
3
+ import { Address } from '../../../encoding/address.js';
4
+ import { BlockHeadersResponse } from './models/types.js';
5
+ /**
6
+ * Returns information about indexed block headers.
7
+ *
8
+ * #### Example
9
+ * ```typescript
10
+ * const bhs = await indexerClient.searchForBlockHeaders().do();
11
+ * ```
12
+ *
13
+ * [Response data schema details](https://developer.algorand.org/docs/rest-apis/indexer/#get-v2block-headers)
14
+ * @category GET
15
+ */
16
+ export default class SearchForBlockHeaders extends JSONRequest<BlockHeadersResponse> {
17
+ /**
18
+ * @returns `/v2/block-headers`
19
+ */
20
+ path(): string;
21
+ /**
22
+ * Accounts marked as absent in the block header's participation updates.
23
+ *
24
+ * #### Example
25
+ * ```typescript
26
+ * const address1 = "XBYLS2E6YI6XXL5BWCAMOA4GTWHXWENZMX5UHXMRNWWUQ7BXCY5WC5TEPA";
27
+ * const address2 = "4H5UNRBJ2Q6JENAXQ6HNTGKLKINP4J4VTQBEPK5F3I6RDICMZBPGNH6KD4";
28
+ * const bhs = await indexerClient
29
+ * .searchForBlockHeaders()
30
+ * .absent([address1,address2])
31
+ * .do();
32
+ * ```
33
+ *
34
+ * @param absent - a comma separated list of addresses
35
+ * @category query
36
+ */
37
+ absent(absent: (string | Address)[]): this;
38
+ /**
39
+ * Include results after the given time.
40
+ *
41
+ * #### Example
42
+ * ```typescript
43
+ * const afterTime = "2022-10-21T00:00:11.55Z";
44
+ * const bhs = await indexerClient
45
+ * .searchForBlockHeaders()
46
+ * .afterTime(afterTime)
47
+ * .do();
48
+ * ```
49
+ *
50
+ * @param after - rfc3339 string or Date object
51
+ * @category query
52
+ */
53
+ afterTime(after: string | Date): this;
54
+ /**
55
+ * Include results before the given time.
56
+ *
57
+ * #### Example
58
+ * ```typescript
59
+ * const beforeTime = "2022-02-02T20:20:22.02Z";
60
+ * const bhs = await indexerClient
61
+ * .searchForBlockHeaders()
62
+ * .beforeTime(beforeTime)
63
+ * .do();
64
+ * ```
65
+ *
66
+ * @param before - rfc3339 string or Date object
67
+ * @category query
68
+ */
69
+ beforeTime(before: string | Date): this;
70
+ /**
71
+ * Accounts marked as expired in the block header's participation updates.
72
+ *
73
+ * #### Example
74
+ * ```typescript
75
+ * const address1 = "XBYLS2E6YI6XXL5BWCAMOA4GTWHXWENZMX5UHXMRNWWUQ7BXCY5WC5TEPA";
76
+ * const address2 = "4H5UNRBJ2Q6JENAXQ6HNTGKLKINP4J4VTQBEPK5F3I6RDICMZBPGNH6KD4";
77
+ * const bhs = await indexerClient
78
+ * .searchForBlockHeaders()
79
+ * .expired([address1,address2])
80
+ * .do();
81
+ * ```
82
+ *
83
+ * @param expired - - a comma separated list of addresses
84
+ * @category query
85
+ */
86
+ expired(expired: (string | Address)[]): this;
87
+ /**
88
+ * Maximum number of results to return.
89
+ *
90
+ * #### Example
91
+ * ```typescript
92
+ * const maxResults = 25;
93
+ * const bhs = await indexerClient
94
+ * .searchForBlockHeaders()
95
+ * .limit(maxResults)
96
+ * .do();
97
+ * ```
98
+ *
99
+ * @param limit
100
+ * @category query
101
+ */
102
+ limit(limit: number): this;
103
+ /**
104
+ * Include results at or before the specified max-round.
105
+ *
106
+ * #### Example
107
+ * ```typescript
108
+ * const maxRound = 18309917;
109
+ * const bhs = await indexerClient
110
+ * .searchForBlockHeaders()
111
+ * .maxRound(maxRound)
112
+ * .do();
113
+ * ```
114
+ *
115
+ * @param round
116
+ * @category query
117
+ */
118
+ maxRound(round: number | bigint): this;
119
+ /**
120
+ * Include results at or after the specified min-round.
121
+ *
122
+ * #### Example
123
+ * ```typescript
124
+ * const minRound = 18309917;
125
+ * const bhs = await indexerClient
126
+ * .searchForBlockHeaders()
127
+ * .minRound(minRound)
128
+ * .do();
129
+ * ```
130
+ *
131
+ * @param round
132
+ * @category query
133
+ */
134
+ minRound(round: number | bigint): this;
135
+ /**
136
+ * The next page of results.
137
+ *
138
+ * #### Example
139
+ * ```typescript
140
+ * const maxResults = 25;
141
+ *
142
+ * const bh1 = await indexerClient
143
+ * .searchForBlockHeaders()
144
+ * .limit(maxResults)
145
+ * .do();
146
+ *
147
+ * const bh2 = await indexerClient
148
+ * .searchForBlockHeaders()
149
+ * .limit(maxResults)
150
+ * .nextToken(bh1["next-token"])
151
+ * .do();
152
+ * ```
153
+ *
154
+ * @param nextToken - provided by the previous results
155
+ * @category query
156
+ */
157
+ nextToken(nextToken: string): this;
158
+ /**
159
+ * Accounts marked as proposer in the block header's participation updates.
160
+ *
161
+ * #### Example
162
+ * ```typescript
163
+ * const address1 = "XBYLS2E6YI6XXL5BWCAMOA4GTWHXWENZMX5UHXMRNWWUQ7BXCY5WC5TEPA";
164
+ * const address2 = "4H5UNRBJ2Q6JENAXQ6HNTGKLKINP4J4VTQBEPK5F3I6RDICMZBPGNH6KD4";
165
+ * const bhs = await indexerClient
166
+ * .searchForBlockHeaders()
167
+ * .proposers([address1,address2])
168
+ * .do();
169
+ * ```
170
+ *
171
+ * @param proposers - a comma separated list of addresses
172
+ * @category query
173
+ */
174
+ proposers(proposers: (string | Address)[]): this;
175
+ prepare(response: HTTPClientResponse): BlockHeadersResponse;
176
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "algosdk",
3
- "version": "3.1.0",
3
+ "version": "3.3.0",
4
4
  "description": "The official JavaScript SDK for Algorand",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -78,7 +78,7 @@
78
78
  "geckodriver": "^4.3.0",
79
79
  "husky": "^4.3.8",
80
80
  "lint-staged": "^10.5.4",
81
- "mocha": "^9.0.0",
81
+ "mocha": "^11.1.0",
82
82
  "mock-http-server": "^1.4.3",
83
83
  "prettier": "^3.2.1",
84
84
  "selenium-webdriver": "^4.10.0",
@@ -13,7 +13,7 @@
13
13
  // | string
14
14
  // | (T1, ..., Tn)
15
15
  */
16
- import { encodeAddress, decodeAddress } from '../encoding/address.js';
16
+ import { encodeAddress, decodeAddress, Address } from '../encoding/address.js';
17
17
  import { bigIntToBytes, bytesToBigInt } from '../encoding/bigint.js';
18
18
  import { concatArrays } from '../utils/utils.js';
19
19
 
@@ -37,7 +37,8 @@ export type ABIValue =
37
37
  | bigint
38
38
  | string
39
39
  | Uint8Array
40
- | ABIValue[];
40
+ | ABIValue[]
41
+ | Address;
41
42
 
42
43
  export abstract class ABIType {
43
44
  // Converts a ABIType object to a string
@@ -255,18 +256,24 @@ export class ABIAddressType extends ABIType {
255
256
  }
256
257
 
257
258
  encode(value: ABIValue) {
258
- if (typeof value !== 'string' && !(value instanceof Uint8Array)) {
259
- throw new Error(`Cannot encode value as ${this.toString()}: ${value}`);
260
- }
261
259
  if (typeof value === 'string') {
262
260
  const decodedAddress = decodeAddress(value);
263
261
  return decodedAddress.publicKey;
264
262
  }
265
- // Return the address if it is already in bytes
266
- if (value.byteLength !== 32) {
267
- throw new Error(`byte string must be 32 bytes long for an address`);
263
+
264
+ if (value instanceof Address) {
265
+ return value.publicKey;
268
266
  }
269
- return value;
267
+
268
+ if (value instanceof Uint8Array) {
269
+ if (value.byteLength !== 32) {
270
+ throw new Error(`byte string must be 32 bytes long for an address`);
271
+ }
272
+
273
+ return value;
274
+ }
275
+
276
+ throw new Error(`Cannot encode value as ${this.toString()}: ${value}`);
270
277
  }
271
278
 
272
279
  decode(byteString: Uint8Array): string {
@@ -19,6 +19,28 @@ export default class Block extends JSONRequest<BlockResponse> {
19
19
  return `/v2/blocks/${this.round}`;
20
20
  }
21
21
 
22
+ /**
23
+ * If true, only the block header (exclusive of payset or certificate) may be included in response.
24
+ *
25
+ * #### Example
26
+ * ```typescript
27
+ *
28
+ * const roundNumber = 41000000;
29
+ *
30
+ * const blockResponse = await algodClient
31
+ * .block(roundNumber)
32
+ * .headerOnly(true)
33
+ * .do();
34
+ * ```
35
+ *
36
+ * @param headerOnly - the flag indicating whether exclusively return header in response
37
+ * @category query
38
+ */
39
+ headerOnly(headerOnly: boolean) {
40
+ this.query['header-only'] = headerOnly;
41
+ return this;
42
+ }
43
+
22
44
  // eslint-disable-next-line class-methods-use-this
23
45
  prepare(response: HTTPClientResponse): BlockResponse {
24
46
  return decodeMsgpack(response.body, BlockResponse);
@@ -9,7 +9,7 @@ import { BoxesResponse } from './models/types.js';
9
9
  * #### Example
10
10
  * ```typescript
11
11
  * const index = 60553466;
12
- * const boxesResponse = await algodClient.getApplicationBoxes(index).max(3).do();
12
+ * const boxesResponse = await algodClient.getApplicationBoxes(index).prefix('int:1234').next('b64:A==').values(true).do();
13
13
  * const boxNames = boxesResponse.boxes.map(box => box.name);
14
14
  * ```
15
15
  *
@@ -53,6 +53,66 @@ export default class GetApplicationBoxes extends JSONRequest<BoxesResponse> {
53
53
  return this;
54
54
  }
55
55
 
56
+ /**
57
+ * A box name prefix, in the goal app call arg form 'encoding:value'. For ints, use the form 'int:1234'. For raw bytes, use the form 'b64:A=='. For printable strings, use the form 'str:hello'. For addresses, use the form 'addr:XYZ...'.
58
+ *
59
+ * #### Example
60
+ * ```typescript
61
+ * const prefix = 'int:1234';
62
+ * const boxesResult = await algodClient
63
+ * .GetApplicationBoxes(1234)
64
+ * .prefix(prefix)
65
+ * .do();
66
+ * ```
67
+ *
68
+ * @param prefix - the box name prefix in the form 'encoding:value'
69
+ * @category query
70
+ */
71
+ prefix(prefix: string) {
72
+ this.query.prefix = prefix;
73
+ return this;
74
+ }
75
+
76
+ /**
77
+ * A box name, in the goal app call arg form 'encoding:value'. When provided, the returned boxes begin (lexographically) with the supplied name. Callers may implement pagination by reinvoking the endpoint with the token from a previous call's next-token.
78
+ *
79
+ * #### Example
80
+ * ```typescript
81
+ * const next = 'int:1234';
82
+ * const boxesResult = await algodClient
83
+ * .GetApplicationBoxes(1234)
84
+ * .next(next)
85
+ * .do();
86
+ * ```
87
+ *
88
+ * @param next - the next box name for pagination, in the goal app call arg form 'encoding:value'
89
+ * @category query
90
+ */
91
+ next(next: string) {
92
+ this.query.next = next;
93
+ return this;
94
+ }
95
+
96
+ /**
97
+ * If true, box values will be returned.
98
+ *
99
+ * #### Example
100
+ * ```typescript
101
+ * const values = true;
102
+ * const boxesResult = await algodClient
103
+ * .GetApplicationBoxes(1234)
104
+ * .values(values)
105
+ * .do();
106
+ * ```
107
+ *
108
+ * @param values - if true, box values will be returned
109
+ * @category query
110
+ */
111
+ values(values: boolean) {
112
+ this.query.values = values;
113
+ return this;
114
+ }
115
+
56
116
  // eslint-disable-next-line class-methods-use-this
57
117
  prepare(response: HTTPClientResponse): BoxesResponse {
58
118
  return decodeJSON(response.getJSONText(), BoxesResponse);