algosdk 2.2.0 → 2.4.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 (116) hide show
  1. package/README.md +5 -7
  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/algod.js +252 -25
  5. package/dist/cjs/client/v2/algod/algod.js.map +1 -1
  6. package/dist/cjs/client/v2/algod/getApplicationBoxByName.js +1 -1
  7. package/dist/cjs/client/v2/algod/getApplicationBoxes.js +1 -1
  8. package/dist/cjs/client/v2/algod/getBlockOffsetTimestamp.js +19 -0
  9. package/dist/cjs/client/v2/algod/getBlockOffsetTimestamp.js.map +1 -0
  10. package/dist/cjs/client/v2/algod/getLedgerStateDelta.js +20 -0
  11. package/dist/cjs/client/v2/algod/getLedgerStateDelta.js.map +1 -0
  12. package/dist/cjs/client/v2/algod/getLedgerStateDeltaForTransactionGroup.js +20 -0
  13. package/dist/cjs/client/v2/algod/getLedgerStateDeltaForTransactionGroup.js.map +1 -0
  14. package/dist/cjs/client/v2/algod/getSyncRound.js +19 -0
  15. package/dist/cjs/client/v2/algod/getSyncRound.js.map +1 -0
  16. package/dist/cjs/client/v2/algod/getTransactionGroupLedgerStateDeltasForRound.js +25 -0
  17. package/dist/cjs/client/v2/algod/getTransactionGroupLedgerStateDeltasForRound.js.map +1 -0
  18. package/dist/cjs/client/v2/algod/models/types.js +327 -23
  19. package/dist/cjs/client/v2/algod/models/types.js.map +1 -1
  20. package/dist/cjs/client/v2/algod/ready.js +14 -0
  21. package/dist/cjs/client/v2/algod/ready.js.map +1 -0
  22. package/dist/cjs/client/v2/algod/setBlockOffsetTimestamp.js +22 -0
  23. package/dist/cjs/client/v2/algod/setBlockOffsetTimestamp.js.map +1 -0
  24. package/dist/cjs/client/v2/algod/setSyncRound.js +22 -0
  25. package/dist/cjs/client/v2/algod/setSyncRound.js.map +1 -0
  26. package/dist/cjs/client/v2/algod/simulateTransaction.js +4 -19
  27. package/dist/cjs/client/v2/algod/simulateTransaction.js.map +1 -1
  28. package/dist/cjs/client/v2/algod/suggestedParams.js +1 -0
  29. package/dist/cjs/client/v2/algod/suggestedParams.js.map +1 -1
  30. package/dist/cjs/client/v2/algod/unsetSyncRound.js +18 -0
  31. package/dist/cjs/client/v2/algod/unsetSyncRound.js.map +1 -0
  32. package/dist/cjs/client/v2/serviceClient.js +3 -0
  33. package/dist/cjs/client/v2/serviceClient.js.map +1 -1
  34. package/dist/cjs/composer.js +40 -3
  35. package/dist/cjs/composer.js.map +1 -1
  36. package/dist/cjs/main.js.map +1 -1
  37. package/dist/cjs/makeTxn.js.map +1 -1
  38. package/dist/cjs/transaction.js +1 -2
  39. package/dist/cjs/transaction.js.map +1 -1
  40. package/dist/esm/client/v2/algod/algod.js +229 -25
  41. package/dist/esm/client/v2/algod/algod.js.map +1 -1
  42. package/dist/esm/client/v2/algod/getApplicationBoxByName.js +1 -1
  43. package/dist/esm/client/v2/algod/getApplicationBoxes.js +1 -1
  44. package/dist/esm/client/v2/algod/getBlockOffsetTimestamp.js +13 -0
  45. package/dist/esm/client/v2/algod/getBlockOffsetTimestamp.js.map +1 -0
  46. package/dist/esm/client/v2/algod/getLedgerStateDelta.js +14 -0
  47. package/dist/esm/client/v2/algod/getLedgerStateDelta.js.map +1 -0
  48. package/dist/esm/client/v2/algod/getLedgerStateDeltaForTransactionGroup.js +14 -0
  49. package/dist/esm/client/v2/algod/getLedgerStateDeltaForTransactionGroup.js.map +1 -0
  50. package/dist/esm/client/v2/algod/getSyncRound.js +13 -0
  51. package/dist/esm/client/v2/algod/getSyncRound.js.map +1 -0
  52. package/dist/esm/client/v2/algod/getTransactionGroupLedgerStateDeltasForRound.js +19 -0
  53. package/dist/esm/client/v2/algod/getTransactionGroupLedgerStateDeltasForRound.js.map +1 -0
  54. package/dist/esm/client/v2/algod/models/types.js +317 -22
  55. package/dist/esm/client/v2/algod/models/types.js.map +1 -1
  56. package/dist/esm/client/v2/algod/ready.js +8 -0
  57. package/dist/esm/client/v2/algod/ready.js.map +1 -0
  58. package/dist/esm/client/v2/algod/setBlockOffsetTimestamp.js +16 -0
  59. package/dist/esm/client/v2/algod/setBlockOffsetTimestamp.js.map +1 -0
  60. package/dist/esm/client/v2/algod/setSyncRound.js +16 -0
  61. package/dist/esm/client/v2/algod/setSyncRound.js.map +1 -0
  62. package/dist/esm/client/v2/algod/simulateTransaction.js +4 -19
  63. package/dist/esm/client/v2/algod/simulateTransaction.js.map +1 -1
  64. package/dist/esm/client/v2/algod/suggestedParams.js +1 -0
  65. package/dist/esm/client/v2/algod/suggestedParams.js.map +1 -1
  66. package/dist/esm/client/v2/algod/unsetSyncRound.js +12 -0
  67. package/dist/esm/client/v2/algod/unsetSyncRound.js.map +1 -0
  68. package/dist/esm/client/v2/serviceClient.js +3 -0
  69. package/dist/esm/client/v2/serviceClient.js.map +1 -1
  70. package/dist/esm/composer.js +17 -3
  71. package/dist/esm/composer.js.map +1 -1
  72. package/dist/esm/main.js.map +1 -1
  73. package/dist/esm/makeTxn.js.map +1 -1
  74. package/dist/esm/transaction.js +1 -2
  75. package/dist/esm/transaction.js.map +1 -1
  76. package/dist/types/client/v2/algod/algod.d.ts +190 -24
  77. package/dist/types/client/v2/algod/getApplicationBoxByName.d.ts +1 -1
  78. package/dist/types/client/v2/algod/getApplicationBoxes.d.ts +1 -1
  79. package/dist/types/client/v2/algod/getBlockOffsetTimestamp.d.ts +6 -0
  80. package/dist/types/client/v2/algod/getLedgerStateDelta.d.ts +8 -0
  81. package/dist/types/client/v2/algod/getLedgerStateDeltaForTransactionGroup.d.ts +8 -0
  82. package/dist/types/client/v2/algod/getSyncRound.d.ts +6 -0
  83. package/dist/types/client/v2/algod/getTransactionGroupLedgerStateDeltasForRound.d.ts +10 -0
  84. package/dist/types/client/v2/algod/models/types.d.ts +283 -29
  85. package/dist/types/client/v2/algod/ready.d.ts +4 -0
  86. package/dist/types/client/v2/algod/setBlockOffsetTimestamp.d.ts +9 -0
  87. package/dist/types/client/v2/algod/setSyncRound.d.ts +9 -0
  88. package/dist/types/client/v2/algod/simulateTransaction.d.ts +3 -3
  89. package/dist/types/client/v2/algod/suggestedParams.d.ts +3 -3
  90. package/dist/types/client/v2/algod/unsetSyncRound.d.ts +5 -0
  91. package/dist/types/composer.d.ts +5 -2
  92. package/dist/types/main.d.ts +1 -0
  93. package/dist/types/makeTxn.d.ts +1 -3
  94. package/dist/types/types/transactions/base.d.ts +6 -0
  95. package/package.json +2 -4
  96. package/src/client/v2/algod/algod.ts +246 -25
  97. package/src/client/v2/algod/getApplicationBoxByName.ts +1 -1
  98. package/src/client/v2/algod/getApplicationBoxes.ts +1 -1
  99. package/src/client/v2/algod/getBlockOffsetTimestamp.ts +17 -0
  100. package/src/client/v2/algod/getLedgerStateDelta.ts +16 -0
  101. package/src/client/v2/algod/getLedgerStateDeltaForTransactionGroup.ts +16 -0
  102. package/src/client/v2/algod/getSyncRound.ts +17 -0
  103. package/src/client/v2/algod/getTransactionGroupLedgerStateDeltasForRound.ts +29 -0
  104. package/src/client/v2/algod/models/types.ts +560 -36
  105. package/src/client/v2/algod/ready.ts +8 -0
  106. package/src/client/v2/algod/setBlockOffsetTimestamp.ts +20 -0
  107. package/src/client/v2/algod/setSyncRound.ts +20 -0
  108. package/src/client/v2/algod/simulateTransaction.ts +6 -22
  109. package/src/client/v2/algod/suggestedParams.ts +4 -3
  110. package/src/client/v2/algod/unsetSyncRound.ts +13 -0
  111. package/src/client/v2/serviceClient.ts +3 -0
  112. package/src/composer.ts +28 -4
  113. package/src/main.ts +7 -0
  114. package/src/makeTxn.ts +2 -4
  115. package/src/transaction.ts +1 -2
  116. package/src/types/transactions/base.ts +7 -0
@@ -0,0 +1,8 @@
1
+ import JSONRequest from '../jsonrequest';
2
+
3
+ export default class Ready extends JSONRequest {
4
+ // eslint-disable-next-line class-methods-use-this
5
+ path() {
6
+ return `/ready`;
7
+ }
8
+ }
@@ -0,0 +1,20 @@
1
+ import JSONRequest from '../jsonrequest';
2
+ import HTTPClient from '../../client';
3
+ import IntDecoding from '../../../types/intDecoding';
4
+
5
+ export default class SetBlockOffsetTimestamp extends JSONRequest {
6
+ constructor(c: HTTPClient, intDecoding: IntDecoding, private offset: number) {
7
+ super(c, intDecoding);
8
+
9
+ this.offset = offset;
10
+ }
11
+
12
+ path() {
13
+ return `/v2/devmode/blocks/offset/${this.offset}`;
14
+ }
15
+
16
+ async do(headers = {}) {
17
+ const res = await this.c.post(this.path(), headers);
18
+ return res.body;
19
+ }
20
+ }
@@ -0,0 +1,20 @@
1
+ import JSONRequest from '../jsonrequest';
2
+ import HTTPClient from '../../client';
3
+ import IntDecoding from '../../../types/intDecoding';
4
+
5
+ export default class SetSyncRound extends JSONRequest {
6
+ constructor(c: HTTPClient, intDecoding: IntDecoding, private round: number) {
7
+ super(c, intDecoding);
8
+
9
+ this.round = round;
10
+ }
11
+
12
+ path() {
13
+ return `/v2/ledger/sync/${this.round}`;
14
+ }
15
+
16
+ async do(headers = {}) {
17
+ const res = await this.c.post(this.path(), headers);
18
+ return res.body;
19
+ }
20
+ }
@@ -1,9 +1,8 @@
1
1
  import { Buffer } from 'buffer';
2
2
  import * as encoding from '../../../encoding/encoding';
3
- import { concatArrays } from '../../../utils/utils';
4
3
  import HTTPClient from '../../client';
5
4
  import JSONRequest from '../jsonrequest';
6
- import { SimulateResponse } from './models/types';
5
+ import { SimulateRequest, SimulateResponse } from './models/types';
7
6
 
8
7
  /**
9
8
  * Sets the default header (if not previously set) for simulating a raw
@@ -14,15 +13,11 @@ export function setSimulateTransactionsHeaders(headers = {}) {
14
13
  let hdrs = headers;
15
14
  if (Object.keys(hdrs).every((key) => key.toLowerCase() !== 'content-type')) {
16
15
  hdrs = { ...headers };
17
- hdrs['Content-Type'] = 'application/x-binary';
16
+ hdrs['Content-Type'] = 'application/msgpack';
18
17
  }
19
18
  return hdrs;
20
19
  }
21
20
 
22
- function isByteArray(array: any): array is Uint8Array {
23
- return array && array.byteLength !== undefined;
24
- }
25
-
26
21
  /**
27
22
  * Simulates signed txns.
28
23
  */
@@ -30,23 +25,12 @@ export default class SimulateRawTransactions extends JSONRequest<
30
25
  SimulateResponse,
31
26
  Uint8Array
32
27
  > {
33
- private txnBytesToPost: Uint8Array;
28
+ private requestBytes: Uint8Array;
34
29
 
35
- constructor(c: HTTPClient, stxOrStxs: Uint8Array | Uint8Array[]) {
30
+ constructor(c: HTTPClient, request: SimulateRequest) {
36
31
  super(c);
37
32
  this.query.format = 'msgpack';
38
-
39
- let forPosting = stxOrStxs;
40
- if (Array.isArray(stxOrStxs)) {
41
- if (!stxOrStxs.every(isByteArray)) {
42
- throw new TypeError('Array elements must be byte arrays');
43
- }
44
- // Flatten into a single Uint8Array
45
- forPosting = concatArrays(...stxOrStxs);
46
- } else if (!isByteArray(forPosting)) {
47
- throw new TypeError('Argument must be byte array');
48
- }
49
- this.txnBytesToPost = forPosting;
33
+ this.requestBytes = encoding.rawEncode(request.get_obj_for_encoding(true));
50
34
  }
51
35
 
52
36
  // eslint-disable-next-line class-methods-use-this
@@ -58,7 +42,7 @@ export default class SimulateRawTransactions extends JSONRequest<
58
42
  const txHeaders = setSimulateTransactionsHeaders(headers);
59
43
  const res = await this.c.post(
60
44
  this.path(),
61
- Buffer.from(this.txnBytesToPost),
45
+ Buffer.from(this.requestBytes),
62
46
  txHeaders,
63
47
  this.query,
64
48
  false
@@ -1,16 +1,16 @@
1
1
  import JSONRequest from '../jsonrequest';
2
- import { SuggestedParams } from '../../../types/transactions/base';
2
+ import { SuggestedParamsWithMinFee } from '../../../types/transactions/base';
3
3
 
4
4
  /**
5
5
  * Returns the common needed parameters for a new transaction, in a format the transaction builder expects
6
6
  */
7
- export default class SuggestedParamsRequest extends JSONRequest<SuggestedParams> {
7
+ export default class SuggestedParamsRequest extends JSONRequest<SuggestedParamsWithMinFee> {
8
8
  /* eslint-disable class-methods-use-this */
9
9
  path() {
10
10
  return '/v2/transactions/params';
11
11
  }
12
12
 
13
- prepare(body: Record<string, any>): SuggestedParams {
13
+ prepare(body: Record<string, any>): SuggestedParamsWithMinFee {
14
14
  return {
15
15
  flatFee: false,
16
16
  fee: body.fee,
@@ -18,6 +18,7 @@ export default class SuggestedParamsRequest extends JSONRequest<SuggestedParams>
18
18
  lastRound: body['last-round'] + 1000,
19
19
  genesisID: body['genesis-id'],
20
20
  genesisHash: body['genesis-hash'],
21
+ minFee: body['min-fee'],
21
22
  };
22
23
  }
23
24
  /* eslint-enable class-methods-use-this */
@@ -0,0 +1,13 @@
1
+ import JSONRequest from '../jsonrequest';
2
+
3
+ export default class UnsetSyncRound extends JSONRequest {
4
+ // eslint-disable-next-line class-methods-use-this
5
+ path() {
6
+ return `/v2/ledger/sync`;
7
+ }
8
+
9
+ async do(headers = {}) {
10
+ const res = await this.c.delete(this.path(), headers);
11
+ return res.body;
12
+ }
13
+ }
@@ -19,6 +19,9 @@ function convertTokenStringToTokenHeader(
19
19
  headerIdentifier: TokenHeaderIdentifier
20
20
  ): TokenHeader {
21
21
  const tokenHeader = {};
22
+ if (token === '') {
23
+ return tokenHeader;
24
+ }
22
25
  tokenHeader[headerIdentifier] = token;
23
26
  return tokenHeader as TokenHeader;
24
27
  }
package/src/composer.ts CHANGED
@@ -12,7 +12,12 @@ import {
12
12
  ABIValue,
13
13
  } from './abi';
14
14
  import Algodv2 from './client/v2/algod/algod';
15
- import { SimulateResponse } from './client/v2/algod/models/types';
15
+ import {
16
+ SimulateResponse,
17
+ SimulateRequest,
18
+ SimulateRequestTransactionGroup,
19
+ } from './client/v2/algod/models/types';
20
+ import { EncodedSignedTransaction } from './types';
16
21
  import { assignGroupID } from './group';
17
22
  import { makeApplicationCallTxnFromObject } from './makeTxn';
18
23
  import {
@@ -27,6 +32,7 @@ import {
27
32
  SuggestedParams,
28
33
  } from './types/transactions/base';
29
34
  import { waitForConfirmation } from './wait';
35
+ import * as encoding from './encoding/encoding';
30
36
 
31
37
  // First 4 bytes of SHA-512/256 hash of "return"
32
38
  const RETURN_PREFIX = Buffer.from([21, 31, 124, 117]);
@@ -345,7 +351,7 @@ export class AtomicTransactionComposer {
345
351
  !abiCheckTransactionType(argType, argValue.txn)
346
352
  ) {
347
353
  throw new Error(
348
- `Expected ${argType} transaction for argument at index ${i}`
354
+ `Expected ${argType} TransactionWithSigner for argument at index ${i}`
349
355
  );
350
356
  }
351
357
  if (argValue.txn.group && argValue.txn.group.some((v) => v !== 0)) {
@@ -609,13 +615,17 @@ export class AtomicTransactionComposer {
609
615
  * Simulating the group will not change the composer's status.
610
616
  *
611
617
  * @param client - An Algodv2 client
618
+ * @param request - SimulateRequest with options in simulation.
619
+ * If provided, the request's transaction group will be overrwritten by the composer's group,
620
+ * only simulation related options will be used.
612
621
  *
613
622
  * @returns A promise that, upon success, resolves to an object containing an
614
623
  * array of results containing one element for each method call transaction
615
624
  * in this group (ABIResult[]) and the SimulateResponse object.
616
625
  */
617
626
  async simulate(
618
- client: Algodv2
627
+ client: Algodv2,
628
+ request?: SimulateRequest
619
629
  ): Promise<{
620
630
  methodResults: ABIResult[];
621
631
  simulateResponse: SimulateResponse;
@@ -627,8 +637,22 @@ export class AtomicTransactionComposer {
627
637
  }
628
638
 
629
639
  const stxns = await this.gatherSignatures();
640
+ const txnObjects: EncodedSignedTransaction[] = stxns.map(
641
+ (stxn) => encoding.decode(stxn) as EncodedSignedTransaction
642
+ );
643
+
644
+ const currentRequest: SimulateRequest =
645
+ request == null ? new SimulateRequest({ txnGroups: [] }) : request;
646
+
647
+ currentRequest.txnGroups = [
648
+ new SimulateRequestTransactionGroup({
649
+ txns: txnObjects,
650
+ }),
651
+ ];
630
652
 
631
- const simulateResponse = await client.simulateRawTransactions(stxns).do();
653
+ const simulateResponse = await client
654
+ .simulateTransactions(currentRequest)
655
+ .do();
632
656
 
633
657
  // Parse method response
634
658
  const methodResults: ABIResult[] = [];
package/src/main.ts CHANGED
@@ -127,6 +127,13 @@ export {
127
127
  BaseHTTPClientResponse,
128
128
  BaseHTTPClientError,
129
129
  } from './client/baseHTTPClient';
130
+ export {
131
+ AlgodTokenHeader,
132
+ IndexerTokenHeader,
133
+ KMDTokenHeader,
134
+ CustomTokenHeader,
135
+ TokenHeader,
136
+ } from './client/urlTokenBaseHTTPClient';
130
137
  export { waitForConfirmation } from './wait';
131
138
  export {
132
139
  isValidAddress,
package/src/makeTxn.ts CHANGED
@@ -200,10 +200,8 @@ export function makeKeyRegistrationTxnWithSuggestedParamsFromObject(
200
200
  'reKeyTo',
201
201
  'rekeyTo'
202
202
  >,
203
- 'from' | 'note' | 'suggestedParams' | 'rekeyTo'
204
- > & {
205
- nonParticipation: true;
206
- }
203
+ 'from' | 'note' | 'suggestedParams' | 'rekeyTo' | 'nonParticipation'
204
+ >
207
205
  >
208
206
  ): txnBuilder.Transaction;
209
207
  export function makeKeyRegistrationTxnWithSuggestedParamsFromObject(o: any) {
@@ -1290,10 +1290,9 @@ export function encodeUnsignedSimulateTransaction(
1290
1290
  transactionObject: Transaction
1291
1291
  ) {
1292
1292
  const objToEncode: EncodedSignedTransaction = {
1293
- sig: null,
1294
1293
  txn: transactionObject.get_obj_for_encoding(),
1295
1294
  };
1296
- return encoding.rawEncode(objToEncode);
1295
+ return encoding.encode(objToEncode);
1297
1296
  }
1298
1297
 
1299
1298
  /**
@@ -130,6 +130,13 @@ export interface SuggestedParams {
130
130
  genesisHash: string;
131
131
  }
132
132
 
133
+ export type SuggestedParamsWithMinFee = SuggestedParams & {
134
+ /**
135
+ * Minimum fee (not per byte) required for the transaction to be confirmed
136
+ */
137
+ minFee: number;
138
+ };
139
+
133
140
  /**
134
141
  * A grouping of the app ID and name of the box in an Uint8Array
135
142
  */