algosdk 2.0.0 → 2.1.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 (151) 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 +6 -5
  5. package/dist/cjs/abi/abi_type.js.map +1 -1
  6. package/dist/cjs/bid.js +6 -5
  7. package/dist/cjs/bid.js.map +1 -1
  8. package/dist/cjs/client/client.js +4 -3
  9. package/dist/cjs/client/client.js.map +1 -1
  10. package/dist/cjs/client/kmd.js +12 -11
  11. package/dist/cjs/client/kmd.js.map +1 -1
  12. package/dist/cjs/client/urlTokenBaseHTTPClient.js +2 -1
  13. package/dist/cjs/client/urlTokenBaseHTTPClient.js.map +1 -1
  14. package/dist/cjs/client/v2/algod/algod.js +16 -0
  15. package/dist/cjs/client/v2/algod/algod.js.map +1 -1
  16. package/dist/cjs/client/v2/algod/compile.js +2 -1
  17. package/dist/cjs/client/v2/algod/compile.js.map +1 -1
  18. package/dist/cjs/client/v2/algod/disassemble.js +46 -0
  19. package/dist/cjs/client/v2/algod/disassemble.js.map +1 -0
  20. package/dist/cjs/client/v2/algod/dryrun.js +2 -1
  21. package/dist/cjs/client/v2/algod/dryrun.js.map +1 -1
  22. package/dist/cjs/client/v2/algod/getApplicationBoxByName.js +2 -1
  23. package/dist/cjs/client/v2/algod/getApplicationBoxByName.js.map +1 -1
  24. package/dist/cjs/client/v2/algod/models/types.js +21 -20
  25. package/dist/cjs/client/v2/algod/models/types.js.map +1 -1
  26. package/dist/cjs/client/v2/algod/sendRawTransaction.js +2 -1
  27. package/dist/cjs/client/v2/algod/sendRawTransaction.js.map +1 -1
  28. package/dist/cjs/client/v2/basemodel.js +3 -2
  29. package/dist/cjs/client/v2/basemodel.js.map +1 -1
  30. package/dist/cjs/client/v2/indexer/lookupAccountTransactions.js +2 -1
  31. package/dist/cjs/client/v2/indexer/lookupAccountTransactions.js.map +1 -1
  32. package/dist/cjs/client/v2/indexer/lookupApplicationBoxByIDandName.js +2 -1
  33. package/dist/cjs/client/v2/indexer/lookupApplicationBoxByIDandName.js.map +1 -1
  34. package/dist/cjs/client/v2/indexer/models/types.js +39 -38
  35. package/dist/cjs/client/v2/indexer/models/types.js.map +1 -1
  36. package/dist/cjs/composer.js +7 -6
  37. package/dist/cjs/composer.js.map +1 -1
  38. package/dist/cjs/dryrun.js +6 -5
  39. package/dist/cjs/dryrun.js.map +1 -1
  40. package/dist/cjs/encoding/address.js +2 -1
  41. package/dist/cjs/encoding/address.js.map +1 -1
  42. package/dist/cjs/encoding/bigint.js +2 -1
  43. package/dist/cjs/encoding/bigint.js.map +1 -1
  44. package/dist/cjs/encoding/uint64.js +14 -8
  45. package/dist/cjs/encoding/uint64.js.map +1 -1
  46. package/dist/cjs/group.js +6 -5
  47. package/dist/cjs/group.js.map +1 -1
  48. package/dist/cjs/logicsig.js +22 -8
  49. package/dist/cjs/logicsig.js.map +1 -1
  50. package/dist/cjs/main.js +7 -5
  51. package/dist/cjs/main.js.map +1 -1
  52. package/dist/cjs/multisig.js +6 -5
  53. package/dist/cjs/multisig.js.map +1 -1
  54. package/dist/cjs/transaction.js +64 -63
  55. package/dist/cjs/transaction.js.map +1 -1
  56. package/dist/cjs/types/transactions/encoded.js +0 -3
  57. package/dist/cjs/types/transactions/encoded.js.map +1 -1
  58. package/dist/cjs/utils/utils.js +5 -1
  59. package/dist/cjs/utils/utils.js.map +1 -1
  60. package/dist/esm/abi/abi_type.js +1 -0
  61. package/dist/esm/abi/abi_type.js.map +1 -1
  62. package/dist/esm/bid.js +1 -0
  63. package/dist/esm/bid.js.map +1 -1
  64. package/dist/esm/client/client.js +1 -0
  65. package/dist/esm/client/client.js.map +1 -1
  66. package/dist/esm/client/kmd.js +1 -0
  67. package/dist/esm/client/kmd.js.map +1 -1
  68. package/dist/esm/client/urlTokenBaseHTTPClient.js +1 -0
  69. package/dist/esm/client/urlTokenBaseHTTPClient.js.map +1 -1
  70. package/dist/esm/client/v2/algod/algod.js +16 -0
  71. package/dist/esm/client/v2/algod/algod.js.map +1 -1
  72. package/dist/esm/client/v2/algod/compile.js +1 -0
  73. package/dist/esm/client/v2/algod/compile.js.map +1 -1
  74. package/dist/esm/client/v2/algod/disassemble.js +38 -0
  75. package/dist/esm/client/v2/algod/disassemble.js.map +1 -0
  76. package/dist/esm/client/v2/algod/dryrun.js +1 -0
  77. package/dist/esm/client/v2/algod/dryrun.js.map +1 -1
  78. package/dist/esm/client/v2/algod/getApplicationBoxByName.js +1 -0
  79. package/dist/esm/client/v2/algod/getApplicationBoxByName.js.map +1 -1
  80. package/dist/esm/client/v2/algod/models/types.js +1 -0
  81. package/dist/esm/client/v2/algod/models/types.js.map +1 -1
  82. package/dist/esm/client/v2/algod/sendRawTransaction.js +1 -0
  83. package/dist/esm/client/v2/algod/sendRawTransaction.js.map +1 -1
  84. package/dist/esm/client/v2/basemodel.js +1 -0
  85. package/dist/esm/client/v2/basemodel.js.map +1 -1
  86. package/dist/esm/client/v2/indexer/lookupAccountTransactions.js +1 -0
  87. package/dist/esm/client/v2/indexer/lookupAccountTransactions.js.map +1 -1
  88. package/dist/esm/client/v2/indexer/lookupApplicationBoxByIDandName.js +1 -0
  89. package/dist/esm/client/v2/indexer/lookupApplicationBoxByIDandName.js.map +1 -1
  90. package/dist/esm/client/v2/indexer/models/types.js +1 -0
  91. package/dist/esm/client/v2/indexer/models/types.js.map +1 -1
  92. package/dist/esm/composer.js +5 -4
  93. package/dist/esm/composer.js.map +1 -1
  94. package/dist/esm/dryrun.js +1 -0
  95. package/dist/esm/dryrun.js.map +1 -1
  96. package/dist/esm/encoding/address.js +1 -0
  97. package/dist/esm/encoding/address.js.map +1 -1
  98. package/dist/esm/encoding/bigint.js +1 -0
  99. package/dist/esm/encoding/bigint.js.map +1 -1
  100. package/dist/esm/encoding/uint64.js +14 -8
  101. package/dist/esm/encoding/uint64.js.map +1 -1
  102. package/dist/esm/group.js +1 -0
  103. package/dist/esm/group.js.map +1 -1
  104. package/dist/esm/logicsig.js +13 -0
  105. package/dist/esm/logicsig.js.map +1 -1
  106. package/dist/esm/main.js +2 -1
  107. package/dist/esm/main.js.map +1 -1
  108. package/dist/esm/multisig.js +1 -0
  109. package/dist/esm/multisig.js.map +1 -1
  110. package/dist/esm/transaction.js +1 -0
  111. package/dist/esm/transaction.js.map +1 -1
  112. package/dist/esm/types/transactions/encoded.js +0 -3
  113. package/dist/esm/types/transactions/encoded.js.map +1 -1
  114. package/dist/esm/utils/utils.js +5 -1
  115. package/dist/esm/utils/utils.js.map +1 -1
  116. package/dist/types/client/v2/algod/algod.d.ts +14 -0
  117. package/dist/types/client/v2/algod/disassemble.d.ts +20 -0
  118. package/dist/types/client/v2/basemodel.d.ts +0 -3
  119. package/dist/types/composer.d.ts +7 -1
  120. package/dist/types/logicsig.d.ts +8 -0
  121. package/dist/types/main.d.ts +1 -1
  122. package/dist/types/types/transactions/encoded.d.ts +1 -1
  123. package/package.json +2 -3
  124. package/src/abi/abi_type.ts +1 -0
  125. package/src/bid.ts +1 -0
  126. package/src/client/client.ts +1 -0
  127. package/src/client/kmd.ts +1 -0
  128. package/src/client/urlTokenBaseHTTPClient.ts +1 -0
  129. package/src/client/v2/algod/algod.ts +17 -0
  130. package/src/client/v2/algod/compile.ts +1 -0
  131. package/src/client/v2/algod/disassemble.ts +46 -0
  132. package/src/client/v2/algod/dryrun.ts +1 -0
  133. package/src/client/v2/algod/getApplicationBoxByName.ts +1 -0
  134. package/src/client/v2/algod/models/types.ts +1 -0
  135. package/src/client/v2/algod/sendRawTransaction.ts +1 -0
  136. package/src/client/v2/basemodel.ts +2 -0
  137. package/src/client/v2/indexer/lookupAccountTransactions.ts +1 -0
  138. package/src/client/v2/indexer/lookupApplicationBoxByIDandName.ts +1 -0
  139. package/src/client/v2/indexer/models/types.ts +1 -0
  140. package/src/composer.ts +16 -3
  141. package/src/dryrun.ts +1 -0
  142. package/src/encoding/address.ts +1 -0
  143. package/src/encoding/bigint.ts +2 -0
  144. package/src/encoding/uint64.ts +16 -10
  145. package/src/group.ts +1 -0
  146. package/src/logicsig.ts +24 -0
  147. package/src/main.ts +2 -0
  148. package/src/multisig.ts +1 -0
  149. package/src/transaction.ts +1 -0
  150. package/src/types/transactions/encoded.ts +2 -0
  151. package/src/utils/utils.ts +3 -0
@@ -1,3 +1,4 @@
1
+ import { Buffer } from 'buffer';
1
2
  import JSONRequest from '../jsonrequest';
2
3
  import HTTPClient from '../../client';
3
4
 
@@ -0,0 +1,46 @@
1
+ import { Buffer } from 'buffer';
2
+ import JSONRequest from '../jsonrequest';
3
+ import HTTPClient from '../../client';
4
+
5
+ /**
6
+ * Sets the default header (if not previously set)
7
+ * @param headers - A headers object
8
+ */
9
+ export function setHeaders(headers = {}) {
10
+ let hdrs = headers;
11
+ if (Object.keys(hdrs).every((key) => key.toLowerCase() !== 'content-type')) {
12
+ hdrs = { ...headers };
13
+ hdrs['Content-Type'] = 'text/plain';
14
+ }
15
+ return hdrs;
16
+ }
17
+
18
+ /**
19
+ * Executes disassemble
20
+ */
21
+ export default class Disassemble extends JSONRequest {
22
+ constructor(c: HTTPClient, private source: string | Uint8Array) {
23
+ super(c);
24
+ this.source = source;
25
+ }
26
+
27
+ // eslint-disable-next-line class-methods-use-this
28
+ path() {
29
+ return `/v2/teal/disassemble`;
30
+ }
31
+
32
+ /**
33
+ * Executes disassemble
34
+ * @param headers - A headers object
35
+ */
36
+ async do(headers = {}) {
37
+ const txHeaders = setHeaders(headers);
38
+ const res = await this.c.post(
39
+ this.path(),
40
+ Buffer.from(this.source),
41
+ txHeaders,
42
+ this.query
43
+ );
44
+ return res.body;
45
+ }
46
+ }
@@ -1,3 +1,4 @@
1
+ import { Buffer } from 'buffer';
1
2
  import JSONRequest from '../jsonrequest';
2
3
  import HTTPClient from '../../client';
3
4
  import * as modelsv2 from './models/types';
@@ -1,3 +1,4 @@
1
+ import { Buffer } from 'buffer';
1
2
  import JSONRequest from '../jsonrequest';
2
3
  import HTTPClient from '../../client';
3
4
  import IntDecoding from '../../../types/intDecoding';
@@ -3,6 +3,7 @@
3
3
  */
4
4
 
5
5
  /* eslint-disable no-use-before-define */
6
+ import { Buffer } from 'buffer';
6
7
  import BaseModel from '../../basemodel';
7
8
  import { EncodedSignedTransaction } from '../../../../types/transactions/encoded';
8
9
  import BlockHeader from '../../../../types/blockHeader';
@@ -1,3 +1,4 @@
1
+ import { Buffer } from 'buffer';
1
2
  import JSONRequest from '../jsonrequest';
2
3
  import HTTPClient from '../../client';
3
4
  import { concatArrays } from '../../../utils/utils';
@@ -1,3 +1,5 @@
1
+ import { Buffer } from 'buffer';
2
+
1
3
  /**
2
4
  * Base class for models
3
5
  */
@@ -1,3 +1,4 @@
1
+ import { Buffer } from 'buffer';
1
2
  import JSONRequest from '../jsonrequest';
2
3
  import HTTPClient from '../../client';
3
4
  import IntDecoding from '../../../types/intDecoding';
@@ -1,3 +1,4 @@
1
+ import { Buffer } from 'buffer';
1
2
  import JSONRequest from '../jsonrequest';
2
3
  import HTTPClient from '../../client';
3
4
  import IntDecoding from '../../../types/intDecoding';
@@ -3,6 +3,7 @@
3
3
  */
4
4
 
5
5
  /* eslint-disable no-use-before-define */
6
+ import { Buffer } from 'buffer';
6
7
  import BaseModel from '../../basemodel';
7
8
 
8
9
  /**
package/src/composer.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { Buffer } from 'buffer';
1
2
  import {
2
3
  ABIType,
3
4
  ABITupleType,
@@ -202,6 +203,9 @@ export class AtomicTransactionComposer {
202
203
  numLocalInts,
203
204
  numLocalByteSlices,
204
205
  extraPages,
206
+ appAccounts,
207
+ appForeignApps,
208
+ appForeignAssets,
205
209
  boxes,
206
210
  note,
207
211
  lease,
@@ -234,6 +238,12 @@ export class AtomicTransactionComposer {
234
238
  numLocalByteSlices?: number;
235
239
  /** The number of extra pages to allocate for the application's programs. Only set this if this is an application creation call. If omitted, defaults to 0. */
236
240
  extraPages?: number;
241
+ /** Array of Address strings that represent external accounts supplied to this application. If accounts are provided here, the accounts specified in the method args will appear after these. */
242
+ appAccounts?: string[];
243
+ /** Array of App ID numbers that represent external apps supplied to this application. If apps are provided here, the apps specified in the method args will appear after these. */
244
+ appForeignApps?: number[];
245
+ /** Array of Asset ID numbers that represent external assets supplied to this application. If assets are provided here, the assets specified in the method args will appear after these. */
246
+ appForeignAssets?: number[];
237
247
  /** The box references for this application call */
238
248
  boxes?: BoxReference[];
239
249
  /** The note value for this application call */
@@ -370,9 +380,12 @@ export class AtomicTransactionComposer {
370
380
  }
371
381
 
372
382
  const resolvedRefIndexes: number[] = [];
373
- const foreignAccounts: string[] = [];
374
- const foreignApps: number[] = [];
375
- const foreignAssets: number[] = [];
383
+ const foreignAccounts: string[] =
384
+ appAccounts == null ? [] : appAccounts.slice();
385
+ const foreignApps: number[] =
386
+ appForeignApps == null ? [] : appForeignApps.slice();
387
+ const foreignAssets: number[] =
388
+ appForeignAssets == null ? [] : appForeignAssets.slice();
376
389
  for (let i = 0; i < refArgTypes.length; i++) {
377
390
  const refType = refArgTypes[i];
378
391
  const refValue = refArgValues[i];
package/src/dryrun.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { Buffer } from 'buffer';
1
2
  import AlgodClient from './client/v2/algod/algod';
2
3
  import {
3
4
  AccountStateDelta,
@@ -1,3 +1,4 @@
1
+ import { Buffer } from 'buffer';
1
2
  import base32 from 'hi-base32';
2
3
  import * as nacl from '../nacl/naclWrappers';
3
4
  import * as utils from '../utils/utils';
@@ -1,3 +1,5 @@
1
+ import { Buffer } from 'buffer';
2
+
1
3
  /**
2
4
  * bigIntToBytes converts a BigInt to a big-endian Uint8Array for encoding.
3
5
  * @param bi - The bigint to convert.
@@ -1,3 +1,10 @@
1
+ import { concatArrays } from '../utils/utils';
2
+
3
+ // NOTE: at the moment we specifically do not use Buffer.writeBigUInt64BE and
4
+ // Buffer.readBigUInt64BE. This is because projects using webpack v4
5
+ // automatically include an old version of the npm `buffer` package (v4.9.2 at
6
+ // the time of writing), and this old version does not have these methods.
7
+
1
8
  /**
2
9
  * encodeUint64 converts an integer to its binary representation.
3
10
  * @param num - The number to convert. This must be an unsigned integer less than
@@ -12,11 +19,11 @@ export function encodeUint64(num: number | bigint) {
12
19
  throw new Error('Input is not a 64-bit unsigned integer');
13
20
  }
14
21
 
15
- const buf = Buffer.allocUnsafe(8);
22
+ const encoding = new Uint8Array(8);
23
+ const view = new DataView(encoding.buffer);
24
+ view.setBigUint64(0, BigInt(num));
16
25
 
17
- buf.writeBigUInt64BE(BigInt(num));
18
-
19
- return new Uint8Array(buf);
26
+ return encoding;
20
27
  }
21
28
 
22
29
  /**
@@ -59,13 +66,12 @@ export function decodeUint64(data: any, decodingMode: any = 'safe') {
59
66
  }
60
67
 
61
68
  // insert 0s at the beginning if data is smaller than 8 bytes
62
- const padding = Buffer.allocUnsafe(8 - data.byteLength);
63
- padding.fill(0);
64
-
65
- const buf = Buffer.concat([padding, Buffer.from(data)]);
69
+ const padding = new Uint8Array(8 - data.byteLength);
70
+ const encoding = concatArrays(padding, data);
71
+ const view = new DataView(encoding.buffer);
66
72
 
67
- const num = buf.readBigUInt64BE();
68
- const isBig = num > Number.MAX_SAFE_INTEGER;
73
+ const num = view.getBigUint64(0);
74
+ const isBig = num > BigInt(Number.MAX_SAFE_INTEGER);
69
75
 
70
76
  if (decodingMode === 'safe') {
71
77
  if (isBig) {
package/src/group.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { Buffer } from 'buffer';
1
2
  import * as txnBuilder from './transaction';
2
3
  import * as nacl from './nacl/naclWrappers';
3
4
  import * as encoding from './encoding/encoding';
package/src/logicsig.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { Buffer } from 'buffer';
1
2
  import * as nacl from './nacl/naclWrappers';
2
3
  import * as address from './encoding/address';
3
4
  import * as encoding from './encoding/encoding';
@@ -495,6 +496,29 @@ export function tealSign(
495
496
  return nacl.sign(toBeSigned, sk);
496
497
  }
497
498
 
499
+ /**
500
+ * verifyTealSign verifies a signature as would the ed25519verify opcode
501
+ * @param data - buffer with original signed data
502
+ * @param programHash - string representation of teal program hash (= contract address for LogicSigs)
503
+ * @param sig - uint8array with the signature to verify (produced by tealSign/tealSignFromProgram)
504
+ * @param pk - uint8array with public key to verify against
505
+ */
506
+ export function verifyTealSign(
507
+ data: Uint8Array | Buffer,
508
+ programHash: string,
509
+ sig: Uint8Array,
510
+ pk: Uint8Array
511
+ ) {
512
+ const parts = utils.concatArrays(
513
+ address.decodeAddress(programHash).publicKey,
514
+ data
515
+ );
516
+ const toBeSigned = Buffer.from(
517
+ utils.concatArrays(SIGN_PROGRAM_DATA_PREFIX, parts)
518
+ );
519
+ return nacl.verify(toBeSigned, sig, pk);
520
+ }
521
+
498
522
  /**
499
523
  * tealSignFromProgram creates a signature compatible with ed25519verify opcode from raw program bytes
500
524
  * @param sk - uint8array with secret key
package/src/main.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { Buffer } from 'buffer';
1
2
  import * as nacl from './nacl/naclWrappers';
2
3
  import * as address from './encoding/address';
3
4
  import * as encoding from './encoding/encoding';
@@ -160,6 +161,7 @@ export {
160
161
  logicSigFromByte,
161
162
  tealSign,
162
163
  tealSignFromProgram,
164
+ verifyTealSign,
163
165
  } from './logicsig';
164
166
  export {
165
167
  signMultisigTransaction,
package/src/multisig.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { Buffer } from 'buffer';
1
2
  import * as nacl from './nacl/naclWrappers';
2
3
  import * as address from './encoding/address';
3
4
  import * as encoding from './encoding/encoding';
@@ -1,3 +1,4 @@
1
+ import { Buffer } from 'buffer';
1
2
  import base32 from 'hi-base32';
2
3
  import * as address from './encoding/address';
3
4
  import * as encoding from './encoding/encoding';
@@ -1,3 +1,5 @@
1
+ import { Buffer } from 'buffer';
2
+
1
3
  /**
2
4
  * Interfaces for the encoded transaction object. Every property is labelled with its associated Transaction type property
3
5
  */
@@ -114,8 +114,11 @@ export function removeUndefinedProperties(
114
114
  */
115
115
  export function isNode() {
116
116
  return (
117
+ // @ts-ignore
117
118
  typeof process === 'object' &&
119
+ // @ts-ignore
118
120
  typeof process.versions === 'object' &&
121
+ // @ts-ignore
119
122
  typeof process.versions.node !== 'undefined'
120
123
  );
121
124
  }