algosdk 1.11.1 → 1.13.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 (148) hide show
  1. package/README.md +17 -6
  2. package/dist/browser/algosdk.min.js +1 -1
  3. package/dist/browser/algosdk.min.js.map +1 -1
  4. package/dist/cjs/src/abi/abi_type.js +693 -0
  5. package/dist/cjs/src/abi/abi_type.js.map +1 -0
  6. package/dist/cjs/src/abi/contract.js +27 -0
  7. package/dist/cjs/src/abi/contract.js.map +1 -0
  8. package/dist/cjs/src/abi/index.js +19 -0
  9. package/dist/cjs/src/abi/index.js.map +1 -0
  10. package/dist/cjs/src/abi/interface.js +23 -0
  11. package/dist/cjs/src/abi/interface.js.map +1 -0
  12. package/dist/cjs/src/abi/method.js +114 -0
  13. package/dist/cjs/src/abi/method.js.map +1 -0
  14. package/dist/cjs/src/abi/reference.js +25 -0
  15. package/dist/cjs/src/abi/reference.js.map +1 -0
  16. package/dist/cjs/src/abi/transaction.js +52 -0
  17. package/dist/cjs/src/abi/transaction.js.map +1 -0
  18. package/dist/cjs/src/client/baseHTTPClient.js +3 -0
  19. package/dist/cjs/src/client/baseHTTPClient.js.map +1 -0
  20. package/dist/cjs/src/client/client.js +165 -104
  21. package/dist/cjs/src/client/client.js.map +1 -1
  22. package/dist/cjs/src/client/urlTokenBaseHTTPClient.js +138 -0
  23. package/dist/cjs/src/client/urlTokenBaseHTTPClient.js.map +1 -0
  24. package/dist/cjs/src/client/v2/algod/algod.js +262 -9
  25. package/dist/cjs/src/client/v2/algod/algod.js.map +1 -1
  26. package/dist/cjs/src/client/v2/algod/models/types.js +13 -33
  27. package/dist/cjs/src/client/v2/algod/models/types.js.map +1 -1
  28. package/dist/cjs/src/client/v2/indexer/indexer.js +168 -3
  29. package/dist/cjs/src/client/v2/indexer/indexer.js.map +1 -1
  30. package/dist/cjs/src/client/v2/indexer/lookupApplicationLogs.js +48 -0
  31. package/dist/cjs/src/client/v2/indexer/lookupApplicationLogs.js.map +1 -0
  32. package/dist/cjs/src/client/v2/indexer/lookupAssetBalances.js +98 -6
  33. package/dist/cjs/src/client/v2/indexer/lookupAssetBalances.js.map +1 -1
  34. package/dist/cjs/src/client/v2/serviceClient.js +17 -8
  35. package/dist/cjs/src/client/v2/serviceClient.js.map +1 -1
  36. package/dist/cjs/src/composer.js +439 -0
  37. package/dist/cjs/src/composer.js.map +1 -0
  38. package/dist/cjs/src/dryrun.js +103 -0
  39. package/dist/cjs/src/dryrun.js.map +1 -0
  40. package/dist/cjs/src/encoding/address.js +14 -1
  41. package/dist/cjs/src/encoding/address.js.map +1 -1
  42. package/dist/cjs/src/encoding/bigint.js +38 -0
  43. package/dist/cjs/src/encoding/bigint.js.map +1 -0
  44. package/dist/cjs/src/logic/langspec.json +392 -77
  45. package/dist/cjs/src/logicsig.js +2 -2
  46. package/dist/cjs/src/logicsig.js.map +1 -1
  47. package/dist/cjs/src/main.js +18 -91
  48. package/dist/cjs/src/main.js.map +1 -1
  49. package/dist/cjs/src/makeTxn.js +29 -1
  50. package/dist/cjs/src/makeTxn.js.map +1 -1
  51. package/dist/cjs/src/multisig.js +77 -2
  52. package/dist/cjs/src/multisig.js.map +1 -1
  53. package/dist/cjs/src/signer.js +66 -0
  54. package/dist/cjs/src/signer.js.map +1 -0
  55. package/dist/cjs/src/transaction.js +50 -10
  56. package/dist/cjs/src/transaction.js.map +1 -1
  57. package/dist/cjs/src/types/intDecoding.js +0 -2
  58. package/dist/cjs/src/types/intDecoding.js.map +1 -1
  59. package/dist/cjs/src/types/transactions/base.js +0 -1
  60. package/dist/cjs/src/types/transactions/base.js.map +1 -1
  61. package/dist/cjs/src/wait.js +53 -0
  62. package/dist/cjs/src/wait.js.map +1 -0
  63. package/dist/esm/src/abi/abi_type.js +680 -0
  64. package/dist/esm/src/abi/abi_type.js.map +1 -0
  65. package/dist/esm/src/abi/contract.js +23 -0
  66. package/dist/esm/src/abi/contract.js.map +1 -0
  67. package/dist/esm/src/abi/index.js +7 -0
  68. package/dist/esm/src/abi/index.js.map +1 -0
  69. package/dist/esm/src/abi/interface.js +19 -0
  70. package/dist/esm/src/abi/interface.js.map +1 -0
  71. package/dist/esm/src/abi/method.js +110 -0
  72. package/dist/esm/src/abi/method.js.map +1 -0
  73. package/dist/esm/src/abi/reference.js +21 -0
  74. package/dist/esm/src/abi/reference.js.map +1 -0
  75. package/dist/esm/src/abi/transaction.js +47 -0
  76. package/dist/esm/src/abi/transaction.js.map +1 -0
  77. package/dist/esm/src/client/baseHTTPClient.js +2 -0
  78. package/dist/esm/src/client/baseHTTPClient.js.map +1 -0
  79. package/dist/esm/src/client/client.js +165 -101
  80. package/dist/esm/src/client/client.js.map +1 -1
  81. package/dist/esm/src/client/urlTokenBaseHTTPClient.js +112 -0
  82. package/dist/esm/src/client/urlTokenBaseHTTPClient.js.map +1 -0
  83. package/dist/esm/src/client/v2/algod/algod.js +262 -9
  84. package/dist/esm/src/client/v2/algod/algod.js.map +1 -1
  85. package/dist/esm/src/client/v2/algod/models/types.js +12 -31
  86. package/dist/esm/src/client/v2/algod/models/types.js.map +1 -1
  87. package/dist/esm/src/client/v2/indexer/indexer.js +168 -3
  88. package/dist/esm/src/client/v2/indexer/indexer.js.map +1 -1
  89. package/dist/esm/src/client/v2/indexer/lookupApplicationLogs.js +42 -0
  90. package/dist/esm/src/client/v2/indexer/lookupApplicationLogs.js.map +1 -0
  91. package/dist/esm/src/client/v2/indexer/lookupAssetBalances.js +98 -6
  92. package/dist/esm/src/client/v2/indexer/lookupAssetBalances.js.map +1 -1
  93. package/dist/esm/src/client/v2/serviceClient.js +17 -8
  94. package/dist/esm/src/client/v2/serviceClient.js.map +1 -1
  95. package/dist/esm/src/composer.js +435 -0
  96. package/dist/esm/src/composer.js.map +1 -0
  97. package/dist/esm/src/dryrun.js +99 -0
  98. package/dist/esm/src/dryrun.js.map +1 -0
  99. package/dist/esm/src/encoding/address.js +12 -0
  100. package/dist/esm/src/encoding/address.js.map +1 -1
  101. package/dist/esm/src/encoding/bigint.js +33 -0
  102. package/dist/esm/src/encoding/bigint.js.map +1 -0
  103. package/dist/esm/src/logic/langspec.json +392 -77
  104. package/dist/esm/src/logicsig.js +2 -2
  105. package/dist/esm/src/logicsig.js.map +1 -1
  106. package/dist/esm/src/main.js +8 -85
  107. package/dist/esm/src/main.js.map +1 -1
  108. package/dist/esm/src/makeTxn.js +27 -0
  109. package/dist/esm/src/makeTxn.js.map +1 -1
  110. package/dist/esm/src/multisig.js +73 -1
  111. package/dist/esm/src/multisig.js.map +1 -1
  112. package/dist/esm/src/signer.js +59 -0
  113. package/dist/esm/src/signer.js.map +1 -0
  114. package/dist/esm/src/transaction.js +50 -10
  115. package/dist/esm/src/transaction.js.map +1 -1
  116. package/dist/esm/src/types/intDecoding.js +0 -2
  117. package/dist/esm/src/types/intDecoding.js.map +1 -1
  118. package/dist/esm/src/types/transactions/base.js +0 -1
  119. package/dist/esm/src/types/transactions/base.js.map +1 -1
  120. package/dist/esm/src/wait.js +49 -0
  121. package/dist/esm/src/wait.js.map +1 -0
  122. package/dist/types/src/abi/abi_type.d.ts +102 -0
  123. package/dist/types/src/abi/contract.d.ts +21 -0
  124. package/dist/types/src/abi/index.d.ts +6 -0
  125. package/dist/types/src/abi/interface.d.ts +13 -0
  126. package/dist/types/src/abi/method.d.ts +39 -0
  127. package/dist/types/src/abi/reference.d.ts +15 -0
  128. package/dist/types/src/abi/transaction.d.ts +33 -0
  129. package/dist/types/src/client/baseHTTPClient.d.ts +41 -0
  130. package/dist/types/src/client/client.d.ts +67 -31
  131. package/dist/types/src/client/kmd.d.ts +1 -1
  132. package/dist/types/src/client/urlTokenBaseHTTPClient.d.ts +44 -0
  133. package/dist/types/src/client/v2/algod/algod.d.ts +263 -9
  134. package/dist/types/src/client/v2/algod/models/types.d.ts +24 -37
  135. package/dist/types/src/client/v2/indexer/indexer.d.ts +167 -3
  136. package/dist/types/src/client/v2/indexer/lookupApplicationLogs.d.ts +20 -0
  137. package/dist/types/src/client/v2/indexer/lookupAssetBalances.d.ts +98 -0
  138. package/dist/types/src/client/v2/serviceClient.d.ts +6 -2
  139. package/dist/types/src/composer.d.ts +160 -0
  140. package/dist/types/src/dryrun.d.ts +20 -0
  141. package/dist/types/src/encoding/address.d.ts +6 -0
  142. package/dist/types/src/encoding/bigint.d.ts +14 -0
  143. package/dist/types/src/main.d.ts +9 -48
  144. package/dist/types/src/makeTxn.d.ts +18 -1
  145. package/dist/types/src/multisig.d.ts +39 -1
  146. package/dist/types/src/signer.d.ts +40 -0
  147. package/dist/types/src/wait.d.ts +11 -0
  148. package/package.json +6 -4
@@ -1 +1 @@
1
- {"version":3,"file":"lookupAssetBalances.js","sourceRoot":"","sources":["../../../../../../src/client/v2/indexer/lookupAssetBalances.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,gBAAgB,CAAC;AAIzC,MAAM,CAAC,OAAO,OAAO,mBAAoB,SAAQ,WAAW;IAC1D,YAAY,CAAa,EAAE,WAAwB,EAAU,KAAa;QACxE,KAAK,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC;QADqC,UAAK,GAAL,KAAK,CAAQ;QAExE,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED,IAAI;QACF,OAAO,cAAc,IAAI,CAAC,KAAK,WAAW,CAAC;IAC7C,CAAC;IAED,2BAA2B;IAC3B,KAAK,CAAC,KAAa;QACjB,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC;QACzB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,+BAA+B;IAC/B,KAAK,CAAC,KAAa;QACjB,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC;QACzB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,4GAA4G;IAC5G,mBAAmB,CAAC,OAAe;QACjC,IAAI,CAAC,KAAK,CAAC,uBAAuB,CAAC,GAAG,OAAO,CAAC;QAC9C,OAAO,IAAI,CAAC;IACd,CAAC;IAED,+GAA+G;IAC/G,gBAAgB,CAAC,MAAc;QAC7B,IAAI,CAAC,KAAK,CAAC,oBAAoB,CAAC,GAAG,MAAM,CAAC;QAC1C,OAAO,IAAI,CAAC;IACd,CAAC;IAED,sBAAsB;IACtB,SAAS,CAAC,SAAiB;QACzB,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,SAAS,CAAC;QAC5B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,wJAAwJ;IACxJ,UAAU,CAAC,KAAK,GAAG,IAAI;QACrB,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,GAAG,KAAK,CAAC;QAClC,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
1
+ {"version":3,"file":"lookupAssetBalances.js","sourceRoot":"","sources":["../../../../../../src/client/v2/indexer/lookupAssetBalances.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,gBAAgB,CAAC;AAIzC,MAAM,CAAC,OAAO,OAAO,mBAAoB,SAAQ,WAAW;IAC1D;;;;;;;;;;;OAWG;IACH,YAAY,CAAa,EAAE,WAAwB,EAAU,KAAa;QACxE,KAAK,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC;QADqC,UAAK,GAAL,KAAK,CAAQ;QAExE,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED,IAAI;QACF,OAAO,cAAc,IAAI,CAAC,KAAK,WAAW,CAAC;IAC7C,CAAC;IAED;;;;;;;;;;;;;;OAcG;IACH,KAAK,CAAC,KAAa;QACjB,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC;QACzB,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,KAAK,CAAC,KAAa;QACjB,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC;QACzB,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,mBAAmB,CAAC,OAAe;QACjC,IAAI,CAAC,KAAK,CAAC,uBAAuB,CAAC,GAAG,OAAO,CAAC;QAC9C,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,gBAAgB,CAAC,MAAc;QAC7B,IAAI,CAAC,KAAK,CAAC,oBAAoB,CAAC,GAAG,MAAM,CAAC;QAC1C,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;;;;;;;;;;OAeG;IACH,SAAS,CAAC,SAAiB;QACzB,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,SAAS,CAAC;QAC5B,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,UAAU,CAAC,KAAK,GAAG,IAAI;QACrB,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,GAAG,KAAK,CAAC;QAClC,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
@@ -10,21 +10,30 @@ function convertTokenStringToTokenHeader(token = '', headerIdentifier) {
10
10
  tokenHeader[headerIdentifier] = token;
11
11
  return tokenHeader;
12
12
  }
13
+ function isBaseHTTPClient(tbc) {
14
+ return typeof tbc.get === 'function';
15
+ }
13
16
  /**
14
17
  * Abstract service client to encapsulate shared AlgodClient and IndexerClient logic
15
18
  */
16
19
  export default class ServiceClient {
17
- constructor(tokenHeaderIdentifier, tokenHeaderOrStr, baseServer, port, defaultHeaders = {}) {
18
- // Accept token header as string or object
19
- // - workaround to allow backwards compatibility for multiple headers
20
- let tokenHeader;
21
- if (typeof tokenHeaderOrStr === 'string') {
22
- tokenHeader = convertTokenStringToTokenHeader(tokenHeaderOrStr, tokenHeaderIdentifier);
20
+ constructor(tokenHeaderIdentifier, tokenHeaderOrStrOrBaseClient, baseServer, port, defaultHeaders = {}) {
21
+ if (isBaseHTTPClient(tokenHeaderOrStrOrBaseClient)) {
22
+ // we are using a base client
23
+ this.c = new HTTPClient(tokenHeaderOrStrOrBaseClient);
23
24
  }
24
25
  else {
25
- tokenHeader = tokenHeaderOrStr;
26
+ // Accept token header as string or object
27
+ // - workaround to allow backwards compatibility for multiple headers
28
+ let tokenHeader;
29
+ if (typeof tokenHeaderOrStrOrBaseClient === 'string') {
30
+ tokenHeader = convertTokenStringToTokenHeader(tokenHeaderOrStrOrBaseClient, tokenHeaderIdentifier);
31
+ }
32
+ else {
33
+ tokenHeader = tokenHeaderOrStrOrBaseClient;
34
+ }
35
+ this.c = new HTTPClient(tokenHeader, baseServer, port, defaultHeaders);
26
36
  }
27
- this.c = new HTTPClient(tokenHeader, baseServer, port, defaultHeaders);
28
37
  this.intDecoding = IntDecoding.DEFAULT;
29
38
  }
30
39
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"serviceClient.js","sourceRoot":"","sources":["../../../../../src/client/v2/serviceClient.ts"],"names":[],"mappings":"AAAA,OAAO,UAA2B,MAAM,WAAW,CAAC;AACpD,OAAO,WAAW,MAAM,yBAAyB,CAAC;AAQlD;;;;GAIG;AACH,SAAS,+BAA+B,CACtC,QAAgB,EAAE,EAClB,gBAAuC;IAEvC,MAAM,WAAW,GAAG,EAAE,CAAC;IACvB,WAAW,CAAC,gBAAgB,CAAC,GAAG,KAAK,CAAC;IACtC,OAAO,WAA0B,CAAC;AACpC,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,OAAO,OAAgB,aAAa;IAIzC,YACE,qBAA4C,EAC5C,gBAAsC,EACtC,UAAkB,EAClB,IAAsB,EACtB,iBAAsC,EAAE;QAExC,0CAA0C;QAC1C,qEAAqE;QACrE,IAAI,WAAwB,CAAC;QAC7B,IAAI,OAAO,gBAAgB,KAAK,QAAQ,EAAE;YACxC,WAAW,GAAG,+BAA+B,CAC3C,gBAAgB,EAChB,qBAAqB,CACtB,CAAC;SACH;aAAM;YACL,WAAW,GAAG,gBAAgB,CAAC;SAChC;QAED,IAAI,CAAC,CAAC,GAAG,IAAI,UAAU,CAAC,WAAW,EAAE,UAAU,EAAE,IAAI,EAAE,cAAc,CAAC,CAAC;QACvE,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC,OAAO,CAAC;IACzC,CAAC;IAED;;;;;OAKG;IACH,cAAc,CAAC,MAAmB;QAChC,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC;IAC5B,CAAC;IAED;;OAEG;IACH,cAAc;QACZ,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;CACF"}
1
+ {"version":3,"file":"serviceClient.js","sourceRoot":"","sources":["../../../../../src/client/v2/serviceClient.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,WAAW,CAAC;AACnC,OAAO,WAAW,MAAM,yBAAyB,CAAC;AAUlD;;;;GAIG;AACH,SAAS,+BAA+B,CACtC,QAAgB,EAAE,EAClB,gBAAuC;IAEvC,MAAM,WAAW,GAAG,EAAE,CAAC;IACvB,WAAW,CAAC,gBAAgB,CAAC,GAAG,KAAK,CAAC;IACtC,OAAO,WAA0B,CAAC;AACpC,CAAC;AAED,SAAS,gBAAgB,CACvB,GAA0C;IAE1C,OAAO,OAAQ,GAAsB,CAAC,GAAG,KAAK,UAAU,CAAC;AAC3D,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,OAAO,OAAgB,aAAa;IAMzC,YACE,qBAA4C,EAC5C,4BAAmE,EACnE,UAAkB,EAClB,IAAsB,EACtB,iBAAsC,EAAE;QAExC,IAAI,gBAAgB,CAAC,4BAA4B,CAAC,EAAE;YAClD,6BAA6B;YAC7B,IAAI,CAAC,CAAC,GAAG,IAAI,UAAU,CAAC,4BAA4B,CAAC,CAAC;SACvD;aAAM;YACL,0CAA0C;YAC1C,qEAAqE;YACrE,IAAI,WAAwB,CAAC;YAC7B,IAAI,OAAO,4BAA4B,KAAK,QAAQ,EAAE;gBACpD,WAAW,GAAG,+BAA+B,CAC3C,4BAA4B,EAC5B,qBAAqB,CACtB,CAAC;aACH;iBAAM;gBACL,WAAW,GAAG,4BAA4B,CAAC;aAC5C;YAED,IAAI,CAAC,CAAC,GAAG,IAAI,UAAU,CAAC,WAAW,EAAE,UAAU,EAAE,IAAI,EAAE,cAAc,CAAC,CAAC;SACxE;QAED,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC,OAAO,CAAC;IACzC,CAAC;IAED;;;;;OAKG;IACH,cAAc,CAAC,MAAmB;QAChC,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC;IAC5B,CAAC;IAED;;OAEG;IACH,cAAc;QACZ,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;CACF"}
@@ -0,0 +1,435 @@
1
+ import { ABITupleType, ABIUintType, ABIAddressType, ABIReferenceType, abiTypeIsTransaction, abiCheckTransactionType, abiTypeIsReference, } from './abi';
2
+ import { Transaction, decodeSignedTransaction } from './transaction';
3
+ import { makeApplicationCallTxnFromObject } from './makeTxn';
4
+ import { assignGroupID } from './group';
5
+ import { waitForConfirmation } from './wait';
6
+ import { isTransactionWithSigner, } from './signer';
7
+ import { OnApplicationComplete, } from './types/transactions/base';
8
+ // First 4 bytes of SHA-512/256 hash of "return"
9
+ const RETURN_PREFIX = Buffer.from([21, 31, 124, 117]);
10
+ // The maximum number of arguments for an application call transaction
11
+ const MAX_APP_ARGS = 16;
12
+ export var AtomicTransactionComposerStatus;
13
+ (function (AtomicTransactionComposerStatus) {
14
+ /** The atomic group is still under construction. */
15
+ AtomicTransactionComposerStatus[AtomicTransactionComposerStatus["BUILDING"] = 0] = "BUILDING";
16
+ /** The atomic group has been finalized, but not yet signed. */
17
+ AtomicTransactionComposerStatus[AtomicTransactionComposerStatus["BUILT"] = 1] = "BUILT";
18
+ /** The atomic group has been finalized and signed, but not yet submitted to the network. */
19
+ AtomicTransactionComposerStatus[AtomicTransactionComposerStatus["SIGNED"] = 2] = "SIGNED";
20
+ /** The atomic group has been finalized, signed, and submitted to the network. */
21
+ AtomicTransactionComposerStatus[AtomicTransactionComposerStatus["SUBMITTED"] = 3] = "SUBMITTED";
22
+ /** The atomic group has been finalized, signed, submitted, and successfully committed to a block. */
23
+ AtomicTransactionComposerStatus[AtomicTransactionComposerStatus["COMMITTED"] = 4] = "COMMITTED";
24
+ })(AtomicTransactionComposerStatus || (AtomicTransactionComposerStatus = {}));
25
+ /**
26
+ * Add a value to an application call's foreign array. The addition will be as compact as possible,
27
+ * and this function will return an index that can be used to reference `valueToAdd` in `array`.
28
+ *
29
+ * @param valueToAdd - The value to add to the array. If this value is already present in the array,
30
+ * it will not be added again. Instead, the existing index will be returned.
31
+ * @param array - The existing foreign array. This input may be modified to append `valueToAdd`.
32
+ * @param zeroValue - If provided, this value indicated two things: the 0 value is special for this
33
+ * array, so all indexes into `array` must start at 1; additionally, if `valueToAdd` equals
34
+ * `zeroValue`, then `valueToAdd` will not be added to the array, and instead the 0 indexes will
35
+ * be returned.
36
+ * @returns An index that can be used to reference `valueToAdd` in `array`.
37
+ */
38
+ function populateForeignArray(valueToAdd, array, zeroValue) {
39
+ if (zeroValue != null && valueToAdd === zeroValue) {
40
+ return 0;
41
+ }
42
+ const offset = zeroValue == null ? 0 : 1;
43
+ for (let i = 0; i < array.length; i++) {
44
+ if (valueToAdd === array[i]) {
45
+ return i + offset;
46
+ }
47
+ }
48
+ array.push(valueToAdd);
49
+ return array.length - 1 + offset;
50
+ }
51
+ /** A class used to construct and execute atomic transaction groups */
52
+ export class AtomicTransactionComposer {
53
+ constructor() {
54
+ this.status = AtomicTransactionComposerStatus.BUILDING;
55
+ this.transactions = [];
56
+ this.methodCalls = new Map();
57
+ this.signedTxns = [];
58
+ this.txIDs = [];
59
+ }
60
+ /**
61
+ * Get the status of this composer's transaction group.
62
+ */
63
+ getStatus() {
64
+ return this.status;
65
+ }
66
+ /**
67
+ * Get the number of transactions currently in this atomic group.
68
+ */
69
+ count() {
70
+ return this.transactions.length;
71
+ }
72
+ /**
73
+ * Create a new composer with the same underlying transactions. The new composer's status will be
74
+ * BUILDING, so additional transactions may be added to it.
75
+ */
76
+ clone() {
77
+ const theClone = new AtomicTransactionComposer();
78
+ theClone.transactions = this.transactions.map(({ txn, signer }) => ({
79
+ // not quite a deep copy, but good enough for our purposes (modifying txn.group in buildGroup)
80
+ txn: Transaction.from_obj_for_encoding({
81
+ ...txn.get_obj_for_encoding(),
82
+ // erase the group ID
83
+ grp: undefined,
84
+ }),
85
+ signer,
86
+ }));
87
+ theClone.methodCalls = new Map(this.methodCalls);
88
+ return theClone;
89
+ }
90
+ /**
91
+ * Add a transaction to this atomic group.
92
+ *
93
+ * An error will be thrown if the transaction has a nonzero group ID, the composer's status is
94
+ * not BUILDING, or if adding this transaction causes the current group to exceed MAX_GROUP_SIZE.
95
+ */
96
+ addTransaction(txnAndSigner) {
97
+ if (this.status !== AtomicTransactionComposerStatus.BUILDING) {
98
+ throw new Error('Cannot add transactions when composer status is not BUILDING');
99
+ }
100
+ if (this.transactions.length === AtomicTransactionComposer.MAX_GROUP_SIZE) {
101
+ throw new Error(`Adding an additional transaction exceeds the maximum atomic group size of ${AtomicTransactionComposer.MAX_GROUP_SIZE}`);
102
+ }
103
+ if (txnAndSigner.txn.group && txnAndSigner.txn.group.some((v) => v !== 0)) {
104
+ throw new Error('Cannot add a transaction with nonzero group ID');
105
+ }
106
+ this.transactions.push(txnAndSigner);
107
+ }
108
+ /**
109
+ * Add a smart contract method call to this atomic group.
110
+ *
111
+ * An error will be thrown if the composer's status is not BUILDING, if adding this transaction
112
+ * causes the current group to exceed MAX_GROUP_SIZE, or if the provided arguments are invalid
113
+ * for the given method.
114
+ */
115
+ addMethodCall({ appID, method, methodArgs, sender, suggestedParams, onComplete, approvalProgram, clearProgram, numGlobalInts, numGlobalByteSlices, numLocalInts, numLocalByteSlices, extraPages, note, lease, rekeyTo, signer, }) {
116
+ if (this.status !== AtomicTransactionComposerStatus.BUILDING) {
117
+ throw new Error('Cannot add transactions when composer status is not BUILDING');
118
+ }
119
+ if (this.transactions.length + method.txnCount() >
120
+ AtomicTransactionComposer.MAX_GROUP_SIZE) {
121
+ throw new Error(`Adding additional transactions exceeds the maximum atomic group size of ${AtomicTransactionComposer.MAX_GROUP_SIZE}`);
122
+ }
123
+ if (appID === 0) {
124
+ if (approvalProgram == null ||
125
+ clearProgram == null ||
126
+ numGlobalInts == null ||
127
+ numGlobalByteSlices == null ||
128
+ numLocalInts == null ||
129
+ numLocalByteSlices == null) {
130
+ throw new Error('One of the following required parameters for application creation is missing: approvalProgram, clearProgram, numGlobalInts, numGlobalByteSlices, numLocalInts, numLocalByteSlices');
131
+ }
132
+ }
133
+ else if (onComplete === OnApplicationComplete.UpdateApplicationOC) {
134
+ if (approvalProgram == null || clearProgram == null) {
135
+ throw new Error('One of the following required parameters for OnApplicationComplete.UpdateApplicationOC is missing: approvalProgram, clearProgram');
136
+ }
137
+ if (numGlobalInts != null ||
138
+ numGlobalByteSlices != null ||
139
+ numLocalInts != null ||
140
+ numLocalByteSlices != null ||
141
+ extraPages != null) {
142
+ throw new Error('One of the following application creation parameters were set on a non-creation call: numGlobalInts, numGlobalByteSlices, numLocalInts, numLocalByteSlices, extraPages');
143
+ }
144
+ }
145
+ else if (approvalProgram != null ||
146
+ clearProgram != null ||
147
+ numGlobalInts != null ||
148
+ numGlobalByteSlices != null ||
149
+ numLocalInts != null ||
150
+ numLocalByteSlices != null ||
151
+ extraPages != null) {
152
+ throw new Error('One of the following application creation parameters were set on a non-creation call: approvalProgram, clearProgram, numGlobalInts, numGlobalByteSlices, numLocalInts, numLocalByteSlices, extraPages');
153
+ }
154
+ if (methodArgs == null) {
155
+ // eslint-disable-next-line no-param-reassign
156
+ methodArgs = [];
157
+ }
158
+ if (methodArgs.length !== method.args.length) {
159
+ throw new Error(`Incorrect number of method arguments. Expected ${method.args.length}, got ${methodArgs.length}`);
160
+ }
161
+ let basicArgTypes = [];
162
+ let basicArgValues = [];
163
+ const txnArgs = [];
164
+ const refArgTypes = [];
165
+ const refArgValues = [];
166
+ const refArgIndexToBasicArgIndex = new Map();
167
+ for (let i = 0; i < methodArgs.length; i++) {
168
+ let argType = method.args[i].type;
169
+ const argValue = methodArgs[i];
170
+ if (abiTypeIsTransaction(argType)) {
171
+ if (!isTransactionWithSigner(argValue) ||
172
+ !abiCheckTransactionType(argType, argValue.txn)) {
173
+ throw new Error(`Expected ${argType} transaction for argument at index ${i}`);
174
+ }
175
+ if (argValue.txn.group && argValue.txn.group.some((v) => v !== 0)) {
176
+ throw new Error('Cannot add a transaction with nonzero group ID');
177
+ }
178
+ txnArgs.push(argValue);
179
+ continue;
180
+ }
181
+ if (isTransactionWithSigner(argValue)) {
182
+ throw new Error(`Expected non-transaction value for argument at index ${i}`);
183
+ }
184
+ if (abiTypeIsReference(argType)) {
185
+ refArgIndexToBasicArgIndex.set(refArgTypes.length, basicArgTypes.length);
186
+ refArgTypes.push(argType);
187
+ refArgValues.push(argValue);
188
+ // treat the reference as a uint8 for encoding purposes
189
+ argType = new ABIUintType(8);
190
+ }
191
+ if (typeof argType === 'string') {
192
+ throw new Error(`Unknown ABI type: ${argType}`);
193
+ }
194
+ basicArgTypes.push(argType);
195
+ basicArgValues.push(argValue);
196
+ }
197
+ const resolvedRefIndexes = [];
198
+ const foreignAccounts = [];
199
+ const foreignApps = [];
200
+ const foreignAssets = [];
201
+ for (let i = 0; i < refArgTypes.length; i++) {
202
+ const refType = refArgTypes[i];
203
+ const refValue = refArgValues[i];
204
+ let resolved = 0;
205
+ switch (refType) {
206
+ case ABIReferenceType.account: {
207
+ const addressType = new ABIAddressType();
208
+ const address = addressType.decode(addressType.encode(refValue));
209
+ resolved = populateForeignArray(address, foreignAccounts, sender);
210
+ break;
211
+ }
212
+ case ABIReferenceType.application: {
213
+ const uint64Type = new ABIUintType(64);
214
+ const refAppID = uint64Type.decode(uint64Type.encode(refValue));
215
+ if (refAppID > Number.MAX_SAFE_INTEGER) {
216
+ throw new Error(`Expected safe integer for application value, got ${refAppID}`);
217
+ }
218
+ resolved = populateForeignArray(Number(refAppID), foreignApps, appID);
219
+ break;
220
+ }
221
+ case ABIReferenceType.asset: {
222
+ const uint64Type = new ABIUintType(64);
223
+ const refAssetID = uint64Type.decode(uint64Type.encode(refValue));
224
+ if (refAssetID > Number.MAX_SAFE_INTEGER) {
225
+ throw new Error(`Expected safe integer for asset value, got ${refAssetID}`);
226
+ }
227
+ resolved = populateForeignArray(Number(refAssetID), foreignAssets);
228
+ break;
229
+ }
230
+ default:
231
+ throw new Error(`Unknown reference type: ${refType}`);
232
+ }
233
+ resolvedRefIndexes.push(resolved);
234
+ }
235
+ for (let i = 0; i < resolvedRefIndexes.length; i++) {
236
+ const basicArgIndex = refArgIndexToBasicArgIndex.get(i);
237
+ basicArgValues[basicArgIndex] = resolvedRefIndexes[i];
238
+ }
239
+ if (basicArgTypes.length > MAX_APP_ARGS - 1) {
240
+ const lastArgTupleTypes = basicArgTypes.slice(MAX_APP_ARGS - 2);
241
+ const lastArgTupleValues = basicArgValues.slice(MAX_APP_ARGS - 2);
242
+ basicArgTypes = basicArgTypes.slice(0, MAX_APP_ARGS - 2);
243
+ basicArgValues = basicArgValues.slice(0, MAX_APP_ARGS - 2);
244
+ basicArgTypes.push(new ABITupleType(lastArgTupleTypes));
245
+ basicArgValues.push(lastArgTupleValues);
246
+ }
247
+ const appArgsEncoded = [method.getSelector()];
248
+ for (let i = 0; i < basicArgTypes.length; i++) {
249
+ appArgsEncoded.push(basicArgTypes[i].encode(basicArgValues[i]));
250
+ }
251
+ const appCall = {
252
+ txn: makeApplicationCallTxnFromObject({
253
+ from: sender,
254
+ appIndex: appID,
255
+ appArgs: appArgsEncoded,
256
+ accounts: foreignAccounts,
257
+ foreignApps,
258
+ foreignAssets,
259
+ onComplete: onComplete == null ? OnApplicationComplete.NoOpOC : onComplete,
260
+ approvalProgram,
261
+ clearProgram,
262
+ numGlobalInts,
263
+ numGlobalByteSlices,
264
+ numLocalInts,
265
+ numLocalByteSlices,
266
+ extraPages,
267
+ lease,
268
+ note,
269
+ rekeyTo,
270
+ suggestedParams,
271
+ }),
272
+ signer,
273
+ };
274
+ this.transactions.push(...txnArgs, appCall);
275
+ this.methodCalls.set(this.transactions.length - 1, method);
276
+ }
277
+ /**
278
+ * Finalize the transaction group and returned the finalized transactions.
279
+ *
280
+ * The composer's status will be at least BUILT after executing this method.
281
+ */
282
+ buildGroup() {
283
+ if (this.status === AtomicTransactionComposerStatus.BUILDING) {
284
+ if (this.transactions.length === 0) {
285
+ throw new Error('Cannot build a group with 0 transactions');
286
+ }
287
+ if (this.transactions.length > 1) {
288
+ assignGroupID(this.transactions.map((txnWithSigner) => txnWithSigner.txn));
289
+ }
290
+ this.status = AtomicTransactionComposerStatus.BUILT;
291
+ }
292
+ return this.transactions;
293
+ }
294
+ /**
295
+ * Obtain signatures for each transaction in this group. If signatures have already been obtained,
296
+ * this method will return cached versions of the signatures.
297
+ *
298
+ * The composer's status will be at least SIGNED after executing this method.
299
+ *
300
+ * An error will be thrown if signing any of the transactions fails.
301
+ *
302
+ * @returns A promise that resolves to an array of signed transactions.
303
+ */
304
+ async gatherSignatures() {
305
+ if (this.status >= AtomicTransactionComposerStatus.SIGNED) {
306
+ return this.signedTxns;
307
+ }
308
+ // retrieve built transactions and verify status is BUILT
309
+ const txnsWithSigners = this.buildGroup();
310
+ const txnGroup = txnsWithSigners.map((txnWithSigner) => txnWithSigner.txn);
311
+ const indexesPerSigner = new Map();
312
+ for (let i = 0; i < txnsWithSigners.length; i++) {
313
+ const { signer } = txnsWithSigners[i];
314
+ if (!indexesPerSigner.has(signer)) {
315
+ indexesPerSigner.set(signer, []);
316
+ }
317
+ indexesPerSigner.get(signer).push(i);
318
+ }
319
+ const orderedSigners = Array.from(indexesPerSigner);
320
+ const batchedSigs = await Promise.all(orderedSigners.map(([signer, indexes]) => signer(txnGroup, indexes)));
321
+ const signedTxns = txnsWithSigners.map(() => null);
322
+ for (let signerIndex = 0; signerIndex < orderedSigners.length; signerIndex++) {
323
+ const indexes = orderedSigners[signerIndex][1];
324
+ const sigs = batchedSigs[signerIndex];
325
+ for (let i = 0; i < indexes.length; i++) {
326
+ signedTxns[indexes[i]] = sigs[i];
327
+ }
328
+ }
329
+ if (!signedTxns.every((sig) => sig != null)) {
330
+ throw new Error(`Missing signatures. Got ${signedTxns}`);
331
+ }
332
+ const txIDs = signedTxns.map((stxn, index) => {
333
+ try {
334
+ return decodeSignedTransaction(stxn).txn.txID();
335
+ }
336
+ catch (err) {
337
+ throw new Error(`Cannot decode signed transaction at index ${index}. ${err}`);
338
+ }
339
+ });
340
+ this.signedTxns = signedTxns;
341
+ this.txIDs = txIDs;
342
+ this.status = AtomicTransactionComposerStatus.SIGNED;
343
+ return signedTxns;
344
+ }
345
+ /**
346
+ * Send the transaction group to the network, but don't wait for it to be committed to a block. An
347
+ * error will be thrown if submission fails.
348
+ *
349
+ * The composer's status must be SUBMITTED or lower before calling this method. If submission is
350
+ * successful, this composer's status will update to SUBMITTED.
351
+ *
352
+ * Note: a group can only be submitted again if it fails.
353
+ *
354
+ * @param client - An Algodv2 client
355
+ *
356
+ * @returns A promise that, upon success, resolves to a list of TxIDs of the submitted transactions.
357
+ */
358
+ async submit(client) {
359
+ if (this.status > AtomicTransactionComposerStatus.SUBMITTED) {
360
+ throw new Error('Transaction group cannot be resubmitted');
361
+ }
362
+ const stxns = await this.gatherSignatures();
363
+ await client.sendRawTransaction(stxns).do();
364
+ this.status = AtomicTransactionComposerStatus.SUBMITTED;
365
+ return this.txIDs;
366
+ }
367
+ /**
368
+ * Send the transaction group to the network and wait until it's committed to a block. An error
369
+ * will be thrown if submission or execution fails.
370
+ *
371
+ * The composer's status must be SUBMITTED or lower before calling this method, since execution is
372
+ * only allowed once. If submission is successful, this composer's status will update to SUBMITTED.
373
+ * If the execution is also successful, this composer's status will update to COMMITTED.
374
+ *
375
+ * Note: a group can only be submitted again if it fails.
376
+ *
377
+ * @param client - An Algodv2 client
378
+ * @param waitRounds - The maximum number of rounds to wait for transaction confirmation
379
+ *
380
+ * @returns A promise that, upon success, resolves to an object containing the confirmed round for
381
+ * this transaction, the txIDs of the submitted transactions, and an array of results containing
382
+ * one element for each method call transaction in this group.
383
+ */
384
+ async execute(client, waitRounds) {
385
+ if (this.status === AtomicTransactionComposerStatus.COMMITTED) {
386
+ throw new Error('Transaction group has already been executed successfully');
387
+ }
388
+ const txIDs = await this.submit(client);
389
+ this.status = AtomicTransactionComposerStatus.SUBMITTED;
390
+ const firstMethodCallIndex = this.transactions.findIndex((_, index) => this.methodCalls.has(index));
391
+ const indexToWaitFor = firstMethodCallIndex === -1 ? 0 : firstMethodCallIndex;
392
+ const confirmedTxnInfo = await waitForConfirmation(client, txIDs[indexToWaitFor], waitRounds);
393
+ this.status = AtomicTransactionComposerStatus.COMMITTED;
394
+ const confirmedRound = confirmedTxnInfo['confirmed-round'];
395
+ const methodResults = [];
396
+ for (const [txnIndex, method] of this.methodCalls) {
397
+ const txID = txIDs[txnIndex];
398
+ const methodResult = {
399
+ txID,
400
+ rawReturnValue: new Uint8Array(),
401
+ };
402
+ try {
403
+ if (method.returns.type !== 'void') {
404
+ const pendingInfo = txnIndex === firstMethodCallIndex
405
+ ? confirmedTxnInfo
406
+ : // eslint-disable-next-line no-await-in-loop
407
+ await client.pendingTransactionInformation(txID).do();
408
+ const logs = pendingInfo.logs || [];
409
+ if (logs.length === 0) {
410
+ throw new Error('App call transaction did not log a return value');
411
+ }
412
+ const lastLog = Buffer.from(logs[logs.length - 1], 'base64');
413
+ if (lastLog.byteLength < 4 ||
414
+ !lastLog.slice(0, 4).equals(RETURN_PREFIX)) {
415
+ throw new Error('App call transaction did not log a return value');
416
+ }
417
+ methodResult.rawReturnValue = new Uint8Array(lastLog.slice(4));
418
+ methodResult.returnValue = method.returns.type.decode(methodResult.rawReturnValue);
419
+ }
420
+ }
421
+ catch (err) {
422
+ methodResult.decodeError = err;
423
+ }
424
+ methodResults.push(methodResult);
425
+ }
426
+ return {
427
+ confirmedRound,
428
+ txIDs,
429
+ methodResults,
430
+ };
431
+ }
432
+ }
433
+ /** The maximum size of an atomic transaction group. */
434
+ AtomicTransactionComposer.MAX_GROUP_SIZE = 16;
435
+ //# sourceMappingURL=composer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"composer.js","sourceRoot":"","sources":["../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C/D,YAAY,CAAC,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CACnD,YAAY,CAAC,cAAc,CAC5B,CAAC;iBACH;aACF;YAAC,OAAO,GAAG,EAAE;gBACZ,YAAY,CAAC,WAAW,GAAG,GAAG,CAAC;aAChC;YAED,aAAa,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;SAClC;QAED,OAAO;YACL,cAAc;YACd,KAAK;YACL,aAAa;SACd,CAAC;IACJ,CAAC;;AAtjBD,uDAAuD;AAChD,wCAAc,GAAW,EAAE,CAAC"}
@@ -0,0 +1,99 @@
1
+ import { Application, ApplicationParams, ApplicationStateSchema, DryrunRequest, } from './client/v2/algod/models/types';
2
+ import { TransactionType } from './types/transactions';
3
+ import { encodeAddress, getApplicationAddress } from './encoding/address';
4
+ const defaultAppId = 1380011588;
5
+ function decodePrograms(ap) {
6
+ // eslint-disable-next-line no-param-reassign
7
+ ap.params['approval-program'] = Buffer.from(ap.params['approval-program'].toString(), 'base64');
8
+ // eslint-disable-next-line no-param-reassign
9
+ ap.params['clear-state-program'] = Buffer.from(ap.params['clear-state-program'].toString(), 'base64');
10
+ return ap;
11
+ }
12
+ /**
13
+ * createDryrun takes an Algod Client (from algod.AlgodV2Client) and an array of Signed Transactions
14
+ * from (transaction.SignedTransaction) and creates a DryrunRequest object with relevant balances
15
+ * @param client - the AlgodClient to make requests against
16
+ * @param txns - the array of SignedTransaction to use for generating the DryrunRequest object
17
+ * @param protocolVersion - the string representing the protocol version to use
18
+ * @param latestTimestamp - the timestamp
19
+ * @returns the DryrunRequest object constructed from the SignedTransactions passed
20
+ */
21
+ export async function createDryrun({ client, txns, protocolVersion, latestTimestamp, round, sources, }) {
22
+ const appInfos = [];
23
+ const acctInfos = [];
24
+ const apps = [];
25
+ const assets = [];
26
+ const accts = [];
27
+ for (const t of txns) {
28
+ if (t.txn.type === TransactionType.appl) {
29
+ accts.push(encodeAddress(t.txn.from.publicKey));
30
+ if (t.txn.appAccounts)
31
+ accts.push(...t.txn.appAccounts.map((a) => encodeAddress(a.publicKey)));
32
+ if (t.txn.appForeignApps)
33
+ apps.push(...t.txn.appForeignApps);
34
+ if (t.txn.appForeignAssets)
35
+ assets.push(...t.txn.appForeignAssets);
36
+ // Create application,
37
+ if (t.txn.appIndex === 0) {
38
+ appInfos.push(new Application(defaultAppId, new ApplicationParams({
39
+ creator: encodeAddress(t.txn.from.publicKey),
40
+ approvalProgram: t.txn.appApprovalProgram,
41
+ clearStateProgram: t.txn.appClearProgram,
42
+ localStateSchema: new ApplicationStateSchema(t.txn.appLocalInts, t.txn.appLocalByteSlices),
43
+ globalStateSchema: new ApplicationStateSchema(t.txn.appGlobalInts, t.txn.appGlobalByteSlices),
44
+ })));
45
+ }
46
+ else {
47
+ apps.push(t.txn.appIndex);
48
+ accts.push(getApplicationAddress(t.txn.appIndex));
49
+ }
50
+ }
51
+ }
52
+ // Dedupe and add creator to accts array
53
+ const assetPromises = [];
54
+ for (const assetId of [...new Set(assets)]) {
55
+ assetPromises.push(client
56
+ .getAssetByID(assetId)
57
+ .do()
58
+ .then((assetInfo) => {
59
+ accts.push(assetInfo.params.creator);
60
+ }));
61
+ }
62
+ // Wait for assets to finish since we append to accts array
63
+ await Promise.all(assetPromises);
64
+ // Dedupe and get app info for all apps
65
+ const appPromises = [];
66
+ for (const appId of [...new Set(apps)]) {
67
+ appPromises.push(client
68
+ .getApplicationByID(appId)
69
+ .do()
70
+ .then((appInfo) => {
71
+ const ai = decodePrograms(appInfo);
72
+ appInfos.push(ai);
73
+ }));
74
+ }
75
+ const acctPromises = [];
76
+ for (const acct of [...new Set(accts)]) {
77
+ acctPromises.push(client
78
+ .accountInformation(acct)
79
+ .do()
80
+ .then((acctInfo) => {
81
+ if ('created-apps' in acctInfo) {
82
+ // eslint-disable-next-line no-param-reassign
83
+ acctInfo['created-apps'] = acctInfo['created-apps'].map((app) => decodePrograms(app));
84
+ }
85
+ acctInfos.push(acctInfo);
86
+ }));
87
+ }
88
+ await Promise.all([...appPromises, ...acctPromises]);
89
+ return new DryrunRequest({
90
+ txns: txns.map((st) => ({ ...st, txn: st.txn.get_obj_for_encoding() })),
91
+ accounts: acctInfos,
92
+ apps: appInfos,
93
+ latestTimestamp,
94
+ round,
95
+ protocolVersion,
96
+ sources,
97
+ });
98
+ }
99
+ //# sourceMappingURL=dryrun.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dryrun.js","sourceRoot":"","sources":["../../../src/dryrun.ts"],"names":[],"mappings":"AACA,OAAO,EACL,WAAW,EACX,iBAAiB,EACjB,sBAAsB,EACtB,aAAa,GAEd,MAAM,gCAAgC,CAAC;AAExC,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAE1E,MAAM,YAAY,GAAG,UAAU,CAAC;AAYhC,SAAS,cAAc,CAAC,EAAoB;IAC1C,6CAA6C;IAC7C,EAAE,CAAC,MAAM,CAAC,kBAAkB,CAAC,GAAG,MAAM,CAAC,IAAI,CACzC,EAAE,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC,QAAQ,EAAE,EACxC,QAAQ,CACT,CAAC;IACF,6CAA6C;IAC7C,EAAE,CAAC,MAAM,CAAC,qBAAqB,CAAC,GAAG,MAAM,CAAC,IAAI,CAC5C,EAAE,CAAC,MAAM,CAAC,qBAAqB,CAAC,CAAC,QAAQ,EAAE,EAC3C,QAAQ,CACT,CAAC;IAEF,OAAO,EAAE,CAAC;AACZ,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,EACjC,MAAM,EACN,IAAI,EACJ,eAAe,EACf,eAAe,EACf,KAAK,EACL,OAAO,GAQR;IACC,MAAM,QAAQ,GAAG,EAAE,CAAC;IACpB,MAAM,SAAS,GAAG,EAAE,CAAC;IAErB,MAAM,IAAI,GAAa,EAAE,CAAC;IAC1B,MAAM,MA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G,CAAC,KAAK,CAAC,CAAC,EAAE;QACtC,YAAY,CAAC,IAAI,CACf,MAAM;aACH,kBAAkB,CAAC,IAAI,CAAC;aACxB,EAAE,EAAE;aACJ,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE;YACjB,IAAI,cAAc,IAAI,QAAQ,EAAE;gBAC9B,6CAA6C;gBAC7C,QAAQ,CAAC,cAAc,CAAC,GAAG,QAAQ,CAAC,cAAc,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAC9D,cAAc,CAAC,GAAG,CAAC,CACpB,CAAC;aACH;YACD,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC3B,CAAC,CAAC,CACL,CAAC;KACH;IACD,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,WAAW,EAAE,GAAG,YAAY,CAAC,CAAC,CAAC;IAErD,OAAO,IAAI,aAAa,CAAC;QACvB,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,oBAAoB,EAAE,EAAE,CAAC,CAAC;QACvE,QAAQ,EAAE,SAAS;QACnB,IAAI,EAAE,QAAQ;QACd,eAAe;QACf,KAAK;QACL,eAAe;QACf,OAAO;KACR,CAAC,CAAC;AACL,CAAC"}
@@ -1,6 +1,7 @@
1
1
  import base32 from 'hi-base32';
2
2
  import * as nacl from '../nacl/naclWrappers';
3
3
  import * as utils from '../utils/utils';
4
+ import { encodeUint64 } from './uint64';
4
5
  const ALGORAND_ADDRESS_BYTE_LENGTH = 36;
5
6
  const ALGORAND_CHECKSUM_BYTE_LENGTH = 4;
6
7
  const ALGORAND_ADDRESS_LENGTH = 58;
@@ -20,6 +21,7 @@ const MULTISIG_PREIMG2ADDR_PREFIX = new Uint8Array([
20
21
  100,
21
22
  114,
22
23
  ]);
24
+ const APP_ID_PREFIX = Buffer.from('appID');
23
25
  export const MALFORMED_ADDRESS_ERROR_MSG = 'address seems to be malformed';
24
26
  export const CHECKSUM_ADDRESS_ERROR_MSG = 'wrong checksum for address';
25
27
  export const INVALID_MSIG_VERSION_ERROR_MSG = 'invalid multisig version';
@@ -126,4 +128,14 @@ export function fromMultisigPreImgAddrs({ version, threshold, addrs, }) {
126
128
  const pks = addrs.map((addr) => decodeAddress(addr).publicKey);
127
129
  return encodeAddress(fromMultisigPreImg({ version, threshold, pks }));
128
130
  }
131
+ /**
132
+ * Get the escrow address of an application.
133
+ * @param appID - The ID of the application.
134
+ * @returns The address corresponding to that application's escrow account.
135
+ */
136
+ export function getApplicationAddress(appID) {
137
+ const toBeSigned = utils.concatArrays(APP_ID_PREFIX, encodeUint64(appID));
138
+ const hash = nacl.genericHash(toBeSigned);
139
+ return encodeAddress(new Uint8Array(hash));
140
+ }
129
141
  //# sourceMappingURL=address.js.map