algosdk 3.3.1 → 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 (64) 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/appAccess.js +261 -0
  5. package/dist/cjs/appAccess.js.map +1 -0
  6. package/dist/cjs/client/v2/algod/getTransactionProof.js +1 -1
  7. package/dist/cjs/client/v2/algod/getTransactionProof.js.map +1 -1
  8. package/dist/cjs/client/v2/algod/models/types.js +8 -8
  9. package/dist/cjs/client/v2/algod/models/types.js.map +1 -1
  10. package/dist/cjs/client/v2/indexer/models/types.js +338 -8
  11. package/dist/cjs/client/v2/indexer/models/types.js.map +1 -1
  12. package/dist/cjs/client/v2/indexer/searchForTransactions.js +19 -0
  13. package/dist/cjs/client/v2/indexer/searchForTransactions.js.map +1 -1
  14. package/dist/cjs/encoding/schema/bytearray.js +3 -0
  15. package/dist/cjs/encoding/schema/bytearray.js.map +1 -1
  16. package/dist/cjs/logicsig.js +54 -17
  17. package/dist/cjs/logicsig.js.map +1 -1
  18. package/dist/cjs/makeTxn.js +66 -12
  19. package/dist/cjs/makeTxn.js.map +1 -1
  20. package/dist/cjs/signing.js +4 -4
  21. package/dist/cjs/signing.js.map +1 -1
  22. package/dist/cjs/transaction.js +107 -0
  23. package/dist/cjs/transaction.js.map +1 -1
  24. package/dist/esm/appAccess.js +255 -0
  25. package/dist/esm/appAccess.js.map +1 -0
  26. package/dist/esm/client/v2/algod/getTransactionProof.js +2 -2
  27. package/dist/esm/client/v2/algod/getTransactionProof.js.map +1 -1
  28. package/dist/esm/client/v2/algod/models/types.js +6 -6
  29. package/dist/esm/client/v2/algod/models/types.js.map +1 -1
  30. package/dist/esm/client/v2/indexer/models/types.js +332 -6
  31. package/dist/esm/client/v2/indexer/models/types.js.map +1 -1
  32. package/dist/esm/client/v2/indexer/searchForTransactions.js +19 -0
  33. package/dist/esm/client/v2/indexer/searchForTransactions.js.map +1 -1
  34. package/dist/esm/encoding/schema/bytearray.js +3 -0
  35. package/dist/esm/encoding/schema/bytearray.js.map +1 -1
  36. package/dist/esm/logicsig.js +54 -17
  37. package/dist/esm/logicsig.js.map +1 -1
  38. package/dist/esm/makeTxn.js +66 -12
  39. package/dist/esm/makeTxn.js.map +1 -1
  40. package/dist/esm/signing.js +4 -4
  41. package/dist/esm/signing.js.map +1 -1
  42. package/dist/esm/transaction.js +107 -0
  43. package/dist/esm/transaction.js.map +1 -1
  44. package/dist/types/appAccess.d.ts +28 -0
  45. package/dist/types/client/v2/algod/getTransactionProof.d.ts +3 -3
  46. package/dist/types/client/v2/algod/models/types.d.ts +4 -4
  47. package/dist/types/client/v2/indexer/models/types.d.ts +202 -8
  48. package/dist/types/client/v2/indexer/searchForTransactions.d.ts +16 -0
  49. package/dist/types/logicsig.d.ts +2 -0
  50. package/dist/types/makeTxn.d.ts +9 -9
  51. package/dist/types/transaction.d.ts +17 -0
  52. package/dist/types/types/transactions/base.d.ts +71 -0
  53. package/package.json +2 -2
  54. package/src/appAccess.ts +298 -0
  55. package/src/client/v2/algod/getTransactionProof.ts +4 -4
  56. package/src/client/v2/algod/models/types.ts +7 -7
  57. package/src/client/v2/indexer/models/types.ts +542 -5
  58. package/src/client/v2/indexer/searchForTransactions.ts +20 -0
  59. package/src/encoding/schema/bytearray.ts +3 -0
  60. package/src/logicsig.ts +68 -17
  61. package/src/makeTxn.ts +110 -12
  62. package/src/signing.ts +4 -4
  63. package/src/transaction.ts +162 -0
  64. package/src/types/transactions/base.ts +85 -0
@@ -0,0 +1,298 @@
1
+ import { Address } from './encoding/address.js';
2
+ import {
3
+ BoxReference,
4
+ HoldingReference,
5
+ LocalsReference,
6
+ ResourceReference,
7
+ } from './types/transactions/base.js';
8
+ import { ensureSafeUnsignedInteger } from './utils/utils.js';
9
+
10
+ /**
11
+ * resourceReferencesToEncodingData translates an array of ResourceReferences into an array of encoding data
12
+ * maps.
13
+ */
14
+ export function resourceReferencesToEncodingData(
15
+ appIndex: bigint,
16
+ references: ReadonlyArray<ResourceReference>
17
+ ): Array<Map<string, unknown>> {
18
+ const accessList: Array<Map<string, unknown>> = [];
19
+
20
+ function ensure(target: ResourceReference): number {
21
+ for (let idx = 0; idx < accessList.length; idx++) {
22
+ const a = accessList[idx];
23
+ if (
24
+ a.get('d') === target.address &&
25
+ a.get('s') === target.assetIndex &&
26
+ a.get('p') === target.appIndex
27
+ ) {
28
+ return idx + 1; // 1-based index
29
+ }
30
+ }
31
+ if (target.address) {
32
+ accessList.push(new Map<string, unknown>([['d', target.address]]));
33
+ }
34
+ if (target.assetIndex) {
35
+ accessList.push(new Map<string, unknown>([['s', target.assetIndex]]));
36
+ }
37
+ if (target.appIndex) {
38
+ accessList.push(new Map<string, unknown>([['p', target.appIndex]]));
39
+ }
40
+ return accessList.length; // length is 1-based position of new element
41
+ }
42
+
43
+ const zeroAddr = Address.zeroAddress();
44
+ for (const rr of references) {
45
+ if (rr.address || rr.assetIndex || rr.appIndex) {
46
+ ensure(rr);
47
+ continue;
48
+ }
49
+
50
+ if (rr.holding) {
51
+ const h = rr.holding;
52
+ let addrIdx = 0;
53
+ if (h.address && !(h.address as Address).equals(zeroAddr)) {
54
+ addrIdx = ensure({ address: h.address });
55
+ }
56
+ const assetIdx = ensure({ assetIndex: h.assetIndex });
57
+ accessList.push(
58
+ new Map<string, unknown>([
59
+ [
60
+ 'h',
61
+ new Map<string, unknown>([
62
+ ['d', addrIdx],
63
+ ['s', assetIdx],
64
+ ]),
65
+ ],
66
+ ])
67
+ );
68
+ continue;
69
+ }
70
+ if (rr.locals) {
71
+ const l = rr.locals;
72
+ let addrIdx = 0;
73
+ if (l.address && !(l.address as Address).equals(zeroAddr)) {
74
+ addrIdx = ensure({ address: l.address });
75
+ }
76
+ let appIdx = 0;
77
+ if (l.appIndex && BigInt(l.appIndex) !== appIndex) {
78
+ appIdx = ensure({ appIndex: l.appIndex });
79
+ }
80
+ accessList.push(
81
+ new Map<string, unknown>([
82
+ [
83
+ 'l',
84
+ new Map<string, unknown>([
85
+ ['d', addrIdx],
86
+ ['p', appIdx],
87
+ ]),
88
+ ],
89
+ ])
90
+ );
91
+ continue;
92
+ }
93
+ if (rr.box) {
94
+ const b = rr.box;
95
+ let appIdx = 0;
96
+ if (b.appIndex && BigInt(b.appIndex) !== appIndex) {
97
+ appIdx = ensure({ appIndex: b.appIndex });
98
+ }
99
+ accessList.push(
100
+ new Map<string, unknown>([
101
+ [
102
+ 'b',
103
+ new Map<string, unknown>([
104
+ ['i', appIdx],
105
+ ['n', b.name],
106
+ ]),
107
+ ],
108
+ ])
109
+ );
110
+ }
111
+ }
112
+ return accessList;
113
+ }
114
+
115
+ export function convertIndicesToResourceReferences(
116
+ accessList: Array<Map<string, unknown>>
117
+ ): Array<ResourceReference> {
118
+ const references: Array<ResourceReference> = [];
119
+ for (const item of accessList) {
120
+ const address = item.get('d') as Address | undefined;
121
+ const assetIndex = item.get('s') as bigint | undefined;
122
+ const appIndex = item.get('p') as bigint | undefined;
123
+ if (address) {
124
+ references.push({ address });
125
+ continue;
126
+ }
127
+ if (assetIndex) {
128
+ references.push({ assetIndex });
129
+ continue;
130
+ }
131
+ if (appIndex) {
132
+ references.push({ appIndex });
133
+ continue;
134
+ }
135
+ const holding = item.get('h') as Map<string, unknown> | undefined;
136
+ if (holding) {
137
+ const hAddressIndex = ensureSafeUnsignedInteger(holding.get('d') ?? 0);
138
+ const hAssetIndex = ensureSafeUnsignedInteger(holding.get('s'));
139
+ if (!hAssetIndex) {
140
+ throw new Error(`Holding missing asset index: ${holding}`);
141
+ }
142
+ const hAddress =
143
+ hAddressIndex === 0
144
+ ? Address.zeroAddress()
145
+ : (references[hAddressIndex - 1].address as Address);
146
+ const asset = references[hAssetIndex - 1].assetIndex as bigint;
147
+ references.push({ holding: { address: hAddress, assetIndex: asset } });
148
+ continue;
149
+ }
150
+ const locals = item.get('l') as Map<string, unknown> | undefined;
151
+ if (locals) {
152
+ const lAddressIndex = ensureSafeUnsignedInteger(locals.get('d') ?? 0);
153
+ const lAppIndex = ensureSafeUnsignedInteger(locals.get('p') ?? 0);
154
+ const lAddress =
155
+ lAddressIndex === 0
156
+ ? Address.zeroAddress()
157
+ : (references[lAddressIndex - 1].address as Address);
158
+ const app =
159
+ lAppIndex === 0
160
+ ? BigInt(0)
161
+ : (references[lAppIndex - 1].appIndex as bigint);
162
+ references.push({ locals: { address: lAddress, appIndex: app } });
163
+ continue;
164
+ }
165
+ const box = item.get('b') as Map<string, unknown> | undefined;
166
+ if (box) {
167
+ const bAppIndex = ensureSafeUnsignedInteger(box.get('i') ?? 0);
168
+ const name = box.get('n') as Uint8Array;
169
+ if (!name) {
170
+ throw new Error(`Box missing name: ${box}`);
171
+ }
172
+ const app =
173
+ bAppIndex === 0
174
+ ? BigInt(0)
175
+ : (references[bAppIndex - 1].appIndex as number | bigint);
176
+ references.push({ box: { appIndex: app, name } });
177
+ }
178
+ }
179
+ return references;
180
+ }
181
+
182
+ /**
183
+ * foreignArraysToResourceReferences makes a single array of ResourceReferences from various foreign resource arrays.
184
+ * Note, runtime representation of ResourceReference uses addresses, app and asset identifiers, not indexes.
185
+ *
186
+ * @param accounts - optional array of accounts
187
+ * @param foreignAssets - optional array of foreign assets
188
+ * @param foreignApps - optional array of foreign apps
189
+ * @param holdings - optional array of holdings
190
+ * @param locals - optional array of locals
191
+ * @param boxes - optional array of boxes
192
+ */
193
+ export function foreignArraysToResourceReferences({
194
+ appIndex,
195
+ accounts,
196
+ foreignAssets,
197
+ foreignApps,
198
+ holdings,
199
+ locals,
200
+ boxes,
201
+ }: {
202
+ appIndex: bigint | number;
203
+ accounts?: ReadonlyArray<string | Address>;
204
+ foreignAssets?: ReadonlyArray<number | bigint>;
205
+ foreignApps?: ReadonlyArray<number | bigint>;
206
+ holdings?: ReadonlyArray<HoldingReference>;
207
+ locals?: ReadonlyArray<LocalsReference>;
208
+ boxes?: ReadonlyArray<BoxReference>;
209
+ }): Array<ResourceReference> {
210
+ const accessList: Array<ResourceReference> = [];
211
+ function ensureAddress(addr: string | Address) {
212
+ let addr2: Address;
213
+ if (typeof addr === 'string') {
214
+ if (addr === '') {
215
+ return;
216
+ }
217
+ addr2 = Address.fromString(addr);
218
+ } else {
219
+ addr2 = addr;
220
+ }
221
+ if (addr2.equals(Address.zeroAddress())) {
222
+ return;
223
+ }
224
+ let addrFound = false;
225
+ for (const rr of accessList) {
226
+ if (!rr.address) {
227
+ continue;
228
+ }
229
+ let rrAddress = rr.address;
230
+ if (typeof rr.address === 'string') {
231
+ rrAddress = Address.fromString(rr.address);
232
+ }
233
+ if ((rrAddress as Address).equals(addr2)) {
234
+ addrFound = true;
235
+ break;
236
+ }
237
+ }
238
+ if (!addrFound) {
239
+ accessList.push({ address: addr });
240
+ }
241
+ }
242
+ function ensureAsset(asset: number | bigint) {
243
+ let assetFound = false;
244
+ for (const rr of accessList) {
245
+ if (rr.assetIndex === asset) {
246
+ assetFound = true;
247
+ break;
248
+ }
249
+ }
250
+ if (!assetFound) {
251
+ accessList.push({ assetIndex: asset });
252
+ }
253
+ }
254
+ function ensureApp(app: number | bigint) {
255
+ let appFound = false;
256
+ for (const rr of accessList) {
257
+ if (rr.appIndex === app) {
258
+ appFound = true;
259
+ break;
260
+ }
261
+ }
262
+ if (!appFound) {
263
+ accessList.push({ appIndex: app });
264
+ }
265
+ }
266
+ for (const acct of accounts ?? []) {
267
+ ensureAddress(acct);
268
+ }
269
+ for (const asset of foreignAssets ?? []) {
270
+ ensureAsset(asset);
271
+ }
272
+ for (const app of foreignApps ?? []) {
273
+ ensureApp(app);
274
+ }
275
+ for (const holding of holdings ?? []) {
276
+ if (holding.address) {
277
+ ensureAddress(holding.address);
278
+ }
279
+ ensureAsset(holding.assetIndex);
280
+ accessList.push({ holding });
281
+ }
282
+ for (const local of locals ?? []) {
283
+ if (local.address) {
284
+ ensureAddress(local.address);
285
+ }
286
+ if (local.appIndex && BigInt(local.appIndex) !== appIndex) {
287
+ ensureApp(local.appIndex);
288
+ }
289
+ accessList.push({ locals: local });
290
+ }
291
+ for (const box of boxes ?? []) {
292
+ if (box.appIndex && BigInt(box.appIndex) !== appIndex) {
293
+ ensureApp(box.appIndex);
294
+ }
295
+ accessList.push({ box });
296
+ }
297
+ return accessList;
298
+ }
@@ -1,9 +1,9 @@
1
1
  import JSONRequest from '../jsonrequest.js';
2
2
  import { HTTPClient, HTTPClientResponse } from '../../client.js';
3
3
  import { decodeJSON } from '../../../encoding/encoding.js';
4
- import { TransactionProofResponse } from './models/types.js';
4
+ import { TransactionProof } from './models/types.js';
5
5
 
6
- export default class GetTransactionProof extends JSONRequest<TransactionProofResponse> {
6
+ export default class GetTransactionProof extends JSONRequest<TransactionProof> {
7
7
  private round: bigint;
8
8
 
9
9
  constructor(
@@ -42,7 +42,7 @@ export default class GetTransactionProof extends JSONRequest<TransactionProofRes
42
42
  }
43
43
 
44
44
  // eslint-disable-next-line class-methods-use-this
45
- prepare(response: HTTPClientResponse): TransactionProofResponse {
46
- return decodeJSON(response.getJSONText(), TransactionProofResponse);
45
+ prepare(response: HTTPClientResponse): TransactionProof {
46
+ return decodeJSON(response.getJSONText(), TransactionProof);
47
47
  }
48
48
  }
@@ -3297,7 +3297,7 @@ export class BoxReference implements Encodable {
3297
3297
  }
3298
3298
 
3299
3299
  /**
3300
- * * Box names of an application
3300
+ * Box names of an application
3301
3301
  */
3302
3302
  export class BoxesResponse implements Encodable {
3303
3303
  private static encodingSchemaValue: Schema | undefined;
@@ -8439,7 +8439,7 @@ export class TransactionParametersResponse implements Encodable {
8439
8439
  /**
8440
8440
  * Proof of transaction in a block.
8441
8441
  */
8442
- export class TransactionProofResponse implements Encodable {
8442
+ export class TransactionProof implements Encodable {
8443
8443
  private static encodingSchemaValue: Schema | undefined;
8444
8444
 
8445
8445
  static get encodingSchema(): Schema {
@@ -8493,7 +8493,7 @@ export class TransactionProofResponse implements Encodable {
8493
8493
  public hashtype?: string;
8494
8494
 
8495
8495
  /**
8496
- * Creates a new `TransactionProofResponse` object.
8496
+ * Creates a new `TransactionProof` object.
8497
8497
  * @param idx - Index of the transaction in the block's payset.
8498
8498
  * @param proof - Proof of transaction membership.
8499
8499
  * @param stibhash - Hash of SignedTxnInBlock for verifying proof.
@@ -8526,7 +8526,7 @@ export class TransactionProofResponse implements Encodable {
8526
8526
 
8527
8527
  // eslint-disable-next-line class-methods-use-this
8528
8528
  getEncodingSchema(): Schema {
8529
- return TransactionProofResponse.encodingSchema;
8529
+ return TransactionProof.encodingSchema;
8530
8530
  }
8531
8531
 
8532
8532
  toEncodingData(): Map<string, unknown> {
@@ -8539,11 +8539,11 @@ export class TransactionProofResponse implements Encodable {
8539
8539
  ]);
8540
8540
  }
8541
8541
 
8542
- static fromEncodingData(data: unknown): TransactionProofResponse {
8542
+ static fromEncodingData(data: unknown): TransactionProof {
8543
8543
  if (!(data instanceof Map)) {
8544
- throw new Error(`Invalid decoded TransactionProofResponse: ${data}`);
8544
+ throw new Error(`Invalid decoded TransactionProof: ${data}`);
8545
8545
  }
8546
- return new TransactionProofResponse({
8546
+ return new TransactionProof({
8547
8547
  idx: data.get('idx'),
8548
8548
  proof: data.get('proof'),
8549
8549
  stibhash: data.get('stibhash'),