algosdk 1.24.1 → 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 (222) hide show
  1. package/README.md +4 -4
  2. package/dist/browser/algosdk.min.js +1 -1
  3. package/dist/browser/algosdk.min.js.LICENSE.txt +0 -18
  4. package/dist/browser/algosdk.min.js.map +1 -1
  5. package/dist/cjs/abi/abi_type.js +6 -5
  6. package/dist/cjs/abi/abi_type.js.map +1 -1
  7. package/dist/cjs/bid.js +6 -5
  8. package/dist/cjs/bid.js.map +1 -1
  9. package/dist/cjs/client/client.js +4 -3
  10. package/dist/cjs/client/client.js.map +1 -1
  11. package/dist/cjs/client/kmd.js +12 -11
  12. package/dist/cjs/client/kmd.js.map +1 -1
  13. package/dist/cjs/client/urlTokenBaseHTTPClient.js +2 -1
  14. package/dist/cjs/client/urlTokenBaseHTTPClient.js.map +1 -1
  15. package/dist/cjs/client/v2/algod/algod.js +17 -1
  16. package/dist/cjs/client/v2/algod/algod.js.map +1 -1
  17. package/dist/cjs/client/v2/algod/compile.js +2 -1
  18. package/dist/cjs/client/v2/algod/compile.js.map +1 -1
  19. package/dist/cjs/client/v2/algod/disassemble.js +46 -0
  20. package/dist/cjs/client/v2/algod/disassemble.js.map +1 -0
  21. package/dist/cjs/client/v2/algod/dryrun.js +2 -1
  22. package/dist/cjs/client/v2/algod/dryrun.js.map +1 -1
  23. package/dist/cjs/client/v2/algod/getApplicationBoxByName.js +2 -1
  24. package/dist/cjs/client/v2/algod/getApplicationBoxByName.js.map +1 -1
  25. package/dist/cjs/client/v2/algod/models/types.js +182 -143
  26. package/dist/cjs/client/v2/algod/models/types.js.map +1 -1
  27. package/dist/cjs/client/v2/algod/sendRawTransaction.js +2 -1
  28. package/dist/cjs/client/v2/algod/sendRawTransaction.js.map +1 -1
  29. package/dist/cjs/client/v2/basemodel.js +3 -2
  30. package/dist/cjs/client/v2/basemodel.js.map +1 -1
  31. package/dist/cjs/client/v2/indexer/lookupAccountTransactions.js +2 -1
  32. package/dist/cjs/client/v2/indexer/lookupAccountTransactions.js.map +1 -1
  33. package/dist/cjs/client/v2/indexer/lookupApplicationBoxByIDandName.js +2 -1
  34. package/dist/cjs/client/v2/indexer/lookupApplicationBoxByIDandName.js.map +1 -1
  35. package/dist/cjs/client/v2/indexer/lookupAssetTransactions.js +0 -7
  36. package/dist/cjs/client/v2/indexer/lookupAssetTransactions.js.map +1 -1
  37. package/dist/cjs/client/v2/indexer/models/types.js +39 -38
  38. package/dist/cjs/client/v2/indexer/models/types.js.map +1 -1
  39. package/dist/cjs/composer.js +7 -6
  40. package/dist/cjs/composer.js.map +1 -1
  41. package/dist/cjs/dryrun.js +22 -12
  42. package/dist/cjs/dryrun.js.map +1 -1
  43. package/dist/cjs/encoding/address.js +2 -1
  44. package/dist/cjs/encoding/address.js.map +1 -1
  45. package/dist/cjs/encoding/bigint.js +2 -1
  46. package/dist/cjs/encoding/bigint.js.map +1 -1
  47. package/dist/cjs/encoding/uint64.js +14 -8
  48. package/dist/cjs/encoding/uint64.js.map +1 -1
  49. package/dist/cjs/group.js +6 -5
  50. package/dist/cjs/group.js.map +1 -1
  51. package/dist/cjs/logicsig.js +24 -21
  52. package/dist/cjs/logicsig.js.map +1 -1
  53. package/dist/cjs/main.js +8 -9
  54. package/dist/cjs/main.js.map +1 -1
  55. package/dist/cjs/makeTxn.js +1 -193
  56. package/dist/cjs/makeTxn.js.map +1 -1
  57. package/dist/cjs/multisig.js +6 -5
  58. package/dist/cjs/multisig.js.map +1 -1
  59. package/dist/cjs/transaction.js +64 -63
  60. package/dist/cjs/transaction.js.map +1 -1
  61. package/dist/cjs/types/transactions/encoded.js +0 -3
  62. package/dist/cjs/types/transactions/encoded.js.map +1 -1
  63. package/dist/cjs/utils/utils.js +5 -1
  64. package/dist/cjs/utils/utils.js.map +1 -1
  65. package/dist/esm/abi/abi_type.js +1 -0
  66. package/dist/esm/abi/abi_type.js.map +1 -1
  67. package/dist/esm/bid.js +1 -0
  68. package/dist/esm/bid.js.map +1 -1
  69. package/dist/esm/client/client.js +1 -0
  70. package/dist/esm/client/client.js.map +1 -1
  71. package/dist/esm/client/kmd.js +1 -0
  72. package/dist/esm/client/kmd.js.map +1 -1
  73. package/dist/esm/client/urlTokenBaseHTTPClient.js +1 -0
  74. package/dist/esm/client/urlTokenBaseHTTPClient.js.map +1 -1
  75. package/dist/esm/client/v2/algod/algod.js +17 -1
  76. package/dist/esm/client/v2/algod/algod.js.map +1 -1
  77. package/dist/esm/client/v2/algod/compile.js +1 -0
  78. package/dist/esm/client/v2/algod/compile.js.map +1 -1
  79. package/dist/esm/client/v2/algod/disassemble.js +38 -0
  80. package/dist/esm/client/v2/algod/disassemble.js.map +1 -0
  81. package/dist/esm/client/v2/algod/dryrun.js +1 -0
  82. package/dist/esm/client/v2/algod/dryrun.js.map +1 -1
  83. package/dist/esm/client/v2/algod/getApplicationBoxByName.js +1 -0
  84. package/dist/esm/client/v2/algod/getApplicationBoxByName.js.map +1 -1
  85. package/dist/esm/client/v2/algod/models/types.js +161 -120
  86. package/dist/esm/client/v2/algod/models/types.js.map +1 -1
  87. package/dist/esm/client/v2/algod/sendRawTransaction.js +1 -0
  88. package/dist/esm/client/v2/algod/sendRawTransaction.js.map +1 -1
  89. package/dist/esm/client/v2/basemodel.js +1 -0
  90. package/dist/esm/client/v2/basemodel.js.map +1 -1
  91. package/dist/esm/client/v2/indexer/lookupAccountTransactions.js +1 -0
  92. package/dist/esm/client/v2/indexer/lookupAccountTransactions.js.map +1 -1
  93. package/dist/esm/client/v2/indexer/lookupApplicationBoxByIDandName.js +1 -0
  94. package/dist/esm/client/v2/indexer/lookupApplicationBoxByIDandName.js.map +1 -1
  95. package/dist/esm/client/v2/indexer/lookupAssetTransactions.js +0 -7
  96. package/dist/esm/client/v2/indexer/lookupAssetTransactions.js.map +1 -1
  97. package/dist/esm/client/v2/indexer/models/types.js +1 -0
  98. package/dist/esm/client/v2/indexer/models/types.js.map +1 -1
  99. package/dist/esm/composer.js +5 -4
  100. package/dist/esm/composer.js.map +1 -1
  101. package/dist/esm/dryrun.js +17 -7
  102. package/dist/esm/dryrun.js.map +1 -1
  103. package/dist/esm/encoding/address.js +1 -0
  104. package/dist/esm/encoding/address.js.map +1 -1
  105. package/dist/esm/encoding/bigint.js +1 -0
  106. package/dist/esm/encoding/bigint.js.map +1 -1
  107. package/dist/esm/encoding/uint64.js +14 -8
  108. package/dist/esm/encoding/uint64.js.map +1 -1
  109. package/dist/esm/group.js +1 -0
  110. package/dist/esm/group.js.map +1 -1
  111. package/dist/esm/logicsig.js +15 -12
  112. package/dist/esm/logicsig.js.map +1 -1
  113. package/dist/esm/main.js +2 -4
  114. package/dist/esm/main.js.map +1 -1
  115. package/dist/esm/makeTxn.js +0 -185
  116. package/dist/esm/makeTxn.js.map +1 -1
  117. package/dist/esm/multisig.js +1 -0
  118. package/dist/esm/multisig.js.map +1 -1
  119. package/dist/esm/transaction.js +1 -0
  120. package/dist/esm/transaction.js.map +1 -1
  121. package/dist/esm/types/transactions/encoded.js +0 -3
  122. package/dist/esm/types/transactions/encoded.js.map +1 -1
  123. package/dist/esm/utils/utils.js +5 -1
  124. package/dist/esm/utils/utils.js.map +1 -1
  125. package/dist/types/client/v2/algod/algod.d.ts +15 -1
  126. package/dist/types/client/v2/algod/disassemble.d.ts +20 -0
  127. package/dist/types/client/v2/algod/models/types.d.ts +122 -67
  128. package/dist/types/client/v2/basemodel.d.ts +0 -3
  129. package/dist/types/client/v2/indexer/lookupAssetTransactions.d.ts +0 -4
  130. package/dist/types/composer.d.ts +7 -1
  131. package/dist/types/logicsig.d.ts +10 -10
  132. package/dist/types/main.d.ts +1 -3
  133. package/dist/types/makeTxn.d.ts +1 -147
  134. package/dist/types/types/transactions/encoded.d.ts +1 -16
  135. package/package.json +2 -3
  136. package/src/abi/abi_type.ts +1 -0
  137. package/src/bid.ts +1 -0
  138. package/src/client/client.ts +1 -0
  139. package/src/client/kmd.ts +1 -0
  140. package/src/client/urlTokenBaseHTTPClient.ts +1 -0
  141. package/src/client/v2/algod/algod.ts +19 -2
  142. package/src/client/v2/algod/compile.ts +1 -0
  143. package/src/client/v2/algod/disassemble.ts +46 -0
  144. package/src/client/v2/algod/dryrun.ts +1 -0
  145. package/src/client/v2/algod/getApplicationBoxByName.ts +1 -0
  146. package/src/client/v2/algod/models/types.ts +319 -249
  147. package/src/client/v2/algod/sendRawTransaction.ts +1 -0
  148. package/src/client/v2/basemodel.ts +2 -0
  149. package/src/client/v2/indexer/lookupAccountTransactions.ts +1 -0
  150. package/src/client/v2/indexer/lookupApplicationBoxByIDandName.ts +1 -0
  151. package/src/client/v2/indexer/lookupAssetTransactions.ts +0 -8
  152. package/src/client/v2/indexer/models/types.ts +1 -0
  153. package/src/composer.ts +16 -3
  154. package/src/dryrun.ts +14 -13
  155. package/src/encoding/address.ts +1 -0
  156. package/src/encoding/bigint.ts +2 -0
  157. package/src/encoding/uint64.ts +16 -10
  158. package/src/group.ts +1 -0
  159. package/src/logicsig.ts +26 -13
  160. package/src/main.ts +3 -5
  161. package/src/makeTxn.ts +0 -421
  162. package/src/multisig.ts +1 -0
  163. package/src/transaction.ts +1 -0
  164. package/src/types/transactions/encoded.ts +2 -17
  165. package/src/utils/utils.ts +3 -0
  166. package/dist/cjs/client/algod.js +0 -295
  167. package/dist/cjs/client/algod.js.map +0 -1
  168. package/dist/cjs/logic/langspec.json +0 -2014
  169. package/dist/cjs/logic/logic.js +0 -262
  170. package/dist/cjs/logic/logic.js.map +0 -1
  171. package/dist/cjs/logicTemplates/dynamicfee.js +0 -192
  172. package/dist/cjs/logicTemplates/dynamicfee.js.map +0 -1
  173. package/dist/cjs/logicTemplates/htlc.js +0 -145
  174. package/dist/cjs/logicTemplates/htlc.js.map +0 -1
  175. package/dist/cjs/logicTemplates/index.js +0 -19
  176. package/dist/cjs/logicTemplates/index.js.map +0 -1
  177. package/dist/cjs/logicTemplates/limitorder.js +0 -167
  178. package/dist/cjs/logicTemplates/limitorder.js.map +0 -1
  179. package/dist/cjs/logicTemplates/periodicpayment.js +0 -163
  180. package/dist/cjs/logicTemplates/periodicpayment.js.map +0 -1
  181. package/dist/cjs/logicTemplates/split.js +0 -154
  182. package/dist/cjs/logicTemplates/split.js.map +0 -1
  183. package/dist/cjs/logicTemplates/templates.js +0 -67
  184. package/dist/cjs/logicTemplates/templates.js.map +0 -1
  185. package/dist/esm/client/algod.js +0 -295
  186. package/dist/esm/client/algod.js.map +0 -1
  187. package/dist/esm/logic/langspec.json +0 -2014
  188. package/dist/esm/logic/logic.js +0 -249
  189. package/dist/esm/logic/logic.js.map +0 -1
  190. package/dist/esm/logicTemplates/dynamicfee.js +0 -192
  191. package/dist/esm/logicTemplates/dynamicfee.js.map +0 -1
  192. package/dist/esm/logicTemplates/htlc.js +0 -145
  193. package/dist/esm/logicTemplates/htlc.js.map +0 -1
  194. package/dist/esm/logicTemplates/index.js +0 -19
  195. package/dist/esm/logicTemplates/index.js.map +0 -1
  196. package/dist/esm/logicTemplates/limitorder.js +0 -167
  197. package/dist/esm/logicTemplates/limitorder.js.map +0 -1
  198. package/dist/esm/logicTemplates/periodicpayment.js +0 -163
  199. package/dist/esm/logicTemplates/periodicpayment.js.map +0 -1
  200. package/dist/esm/logicTemplates/split.js +0 -154
  201. package/dist/esm/logicTemplates/split.js.map +0 -1
  202. package/dist/esm/logicTemplates/templates.js +0 -67
  203. package/dist/esm/logicTemplates/templates.js.map +0 -1
  204. package/dist/types/client/algod.d.ts +0 -162
  205. package/dist/types/logic/logic.d.ts +0 -45
  206. package/dist/types/logicTemplates/dynamicfee.d.ts +0 -59
  207. package/dist/types/logicTemplates/htlc.d.ts +0 -51
  208. package/dist/types/logicTemplates/index.d.ts +0 -16
  209. package/dist/types/logicTemplates/limitorder.d.ts +0 -70
  210. package/dist/types/logicTemplates/periodicpayment.d.ts +0 -58
  211. package/dist/types/logicTemplates/split.d.ts +0 -57
  212. package/dist/types/logicTemplates/templates.d.ts +0 -6
  213. package/src/client/algod.js +0 -365
  214. package/src/logic/langspec.json +0 -2014
  215. package/src/logic/logic.ts +0 -316
  216. package/src/logicTemplates/dynamicfee.js +0 -219
  217. package/src/logicTemplates/htlc.js +0 -165
  218. package/src/logicTemplates/index.js +0 -20
  219. package/src/logicTemplates/limitorder.js +0 -227
  220. package/src/logicTemplates/periodicpayment.js +0 -208
  221. package/src/logicTemplates/split.js +0 -208
  222. package/src/logicTemplates/templates.js +0 -78
@@ -1,316 +0,0 @@
1
- /* eslint-disable no-bitwise */
2
- /**
3
- * Utilities for working with program bytes.
4
- */
5
-
6
- /** @deprecated langspec.json is deprecated aross all SDKs */
7
- import langspec from './langspec.json';
8
-
9
- /**
10
- * Langspec Op Structure
11
- * @deprecated for langspec.json is deprecated aross all SDKs
12
- */
13
- interface OpStructure {
14
- Opcode: number;
15
- Name: string;
16
- Args?: string;
17
- Returns?: string;
18
- Cost: number;
19
- Size: number;
20
- ArgEnum?: string[];
21
- ArgEnumTypes?: string;
22
- Doc: string;
23
- DocExtra?: string;
24
- ImmediateNote?: string;
25
- Groups: string[];
26
- }
27
-
28
- /** @deprecated for langspec.json is deprecated aross all SDKs */
29
- let opcodes: {
30
- [key: number]: OpStructure;
31
- };
32
-
33
- /** @deprecated for langspec.json is deprecated aross all SDKs */
34
- const maxCost = 20000;
35
- /** @deprecated for langspec.json is deprecated aross all SDKs */
36
- const maxLength = 1000;
37
-
38
- /** @deprecated for langspec.json is deprecated aross all SDKs */
39
- export function parseUvarint(
40
- array: Uint8Array
41
- ): [numberFound: number, size: number] {
42
- let x = 0;
43
- let s = 0;
44
- for (let i = 0; i < array.length; i++) {
45
- const b = array[i];
46
- if (b < 0x80) {
47
- if (i > 9 || (i === 9 && b > 1)) {
48
- return [0, -(i + 1)];
49
- }
50
- return [x | (b << s), i + 1];
51
- }
52
- x += (b & 0x7f) << s;
53
- s += 7;
54
- }
55
- return [0, 0];
56
- }
57
-
58
- /** @deprecated for langspec.json is deprecated aross all SDKs */
59
- function readIntConstBlock(
60
- program: Uint8Array,
61
- pc: number
62
- ): [size: number, ints: number[]] {
63
- let size = 1;
64
- const parsed = parseUvarint(program.slice(pc + size));
65
- const numInts = parsed[0];
66
- let bytesUsed = parsed[1];
67
- if (bytesUsed <= 0) {
68
- throw new Error(`could not decode int const block size at pc=${pc + size}`);
69
- }
70
- const ints: number[] = [];
71
- size += bytesUsed;
72
- for (let i = 0; i < numInts; i++) {
73
- if (pc + size >= program.length) {
74
- throw new Error('intcblock ran past end of program');
75
- }
76
- let numberFound: number;
77
- [numberFound, bytesUsed] = parseUvarint(program.slice(pc + size));
78
- if (bytesUsed <= 0) {
79
- throw new Error(
80
- `could not decode int const[${i}] block size at pc=${pc + size}`
81
- );
82
- }
83
- ints.push(numberFound);
84
- size += bytesUsed;
85
- }
86
- return [size, ints];
87
- }
88
-
89
- /** @deprecated for langspec.json is deprecated aross all SDKs */
90
- function readByteConstBlock(
91
- program: Uint8Array,
92
- pc: number
93
- ): [size: number, byteArrays: Uint8Array[]] {
94
- let size = 1;
95
- const parsed = parseUvarint(program.slice(pc + size));
96
- const numInts = parsed[0];
97
- let bytesUsed = parsed[1];
98
- if (bytesUsed <= 0) {
99
- throw new Error(
100
- `could not decode []byte const block size at pc=${pc + size}`
101
- );
102
- }
103
- const byteArrays: Uint8Array[] = [];
104
- size += bytesUsed;
105
- for (let i = 0; i < numInts; i++) {
106
- if (pc + size >= program.length) {
107
- throw new Error('bytecblock ran past end of program');
108
- }
109
- let itemLen: number;
110
- [itemLen, bytesUsed] = parseUvarint(program.slice(pc + size));
111
- if (bytesUsed <= 0) {
112
- throw new Error(
113
- `could not decode []byte] const[${i}] block size at pc=${pc + size}`
114
- );
115
- }
116
- size += bytesUsed;
117
- if (pc + size + itemLen > program.length) {
118
- throw new Error('bytecblock ran past end of program');
119
- }
120
- const byteArray = program.slice(pc + size, pc + size + itemLen);
121
- byteArrays.push(byteArray);
122
- size += itemLen;
123
- }
124
- return [size, byteArrays];
125
- }
126
-
127
- /** @deprecated for langspec.json is deprecated aross all SDKs */
128
- function readPushIntOp(
129
- program: Uint8Array,
130
- pc: number
131
- ): [size: number, numberFound: number] {
132
- let size = 1;
133
- const [numberFound, bytesUsed] = parseUvarint(program.slice(pc + size));
134
- if (bytesUsed <= 0) {
135
- throw new Error(`could not decode push int const at pc=${pc + size}`);
136
- }
137
- size += bytesUsed;
138
- return [size, numberFound];
139
- }
140
-
141
- /** @deprecated for langspec.json is deprecated aross all SDKs */
142
- function readPushByteOp(
143
- program: Uint8Array,
144
- pc: number
145
- ): [size: number, byteArray: Uint8Array] {
146
- let size = 1;
147
- const [itemLen, bytesUsed] = parseUvarint(program.slice(pc + size));
148
- if (bytesUsed <= 0) {
149
- throw new Error(
150
- `could not decode push []byte const size at pc=${pc + size}`
151
- );
152
- }
153
- size += bytesUsed;
154
- if (pc + size + itemLen > program.length) {
155
- throw new Error('pushbytes ran past end of program');
156
- }
157
- const byteArray = program.slice(pc + size, pc + size + itemLen);
158
- size += itemLen;
159
- return [size, byteArray];
160
- }
161
-
162
- /** readProgram validates program for length and running cost,
163
- * and additionally provides the found int variables and byte blocks
164
- *
165
- * @deprecated Validation relies on metadata (`langspec.json`) that
166
- * does not accurately represent opcode behavior across program versions.
167
- * The behavior of `readProgram` relies on `langspec.json`.
168
- * Thus, this method is being deprecated.
169
- *
170
- * @param program - Program to check
171
- * @param args - Program arguments as array of Uint8Array arrays
172
- * @throws
173
- * @returns
174
- */
175
- export function readProgram(
176
- program: Uint8Array,
177
- args?: Uint8Array[]
178
- ): [ints: number[], byteArrays: Uint8Array[], valid: boolean] {
179
- const intcblockOpcode = 32;
180
- const bytecblockOpcode = 38;
181
- const pushbytesOpcode = 128;
182
- const pushintOpcode = 129;
183
-
184
- if (!program) {
185
- throw new Error('empty program');
186
- }
187
-
188
- if (typeof args === 'undefined') {
189
- // eslint-disable-next-line no-param-reassign
190
- args = [];
191
- }
192
- if (!Array.isArray(args)) {
193
- throw new Error('invalid arguments');
194
- }
195
-
196
- const [version, vlen] = parseUvarint(program);
197
- if (vlen <= 0) {
198
- throw new Error('version parsing error');
199
- }
200
- if (version > langspec.EvalMaxVersion) {
201
- throw new Error('unsupported version');
202
- }
203
-
204
- let cost = 0;
205
- let { length } = program;
206
- for (const arg of args) {
207
- length += arg.length;
208
- }
209
- if (length > maxLength) {
210
- throw new Error('program too long');
211
- }
212
-
213
- if (!opcodes) {
214
- opcodes = {};
215
- for (const op of langspec.Ops) {
216
- opcodes[op.Opcode] = op;
217
- }
218
- }
219
-
220
- let pc = vlen;
221
- let ints: number[] = [];
222
- let byteArrays: Uint8Array[] = [];
223
- while (pc < program.length) {
224
- const op = opcodes[program[pc]];
225
- if (op === undefined) {
226
- throw new Error('invalid instruction');
227
- }
228
-
229
- cost += op.Cost;
230
- let size = op.Size;
231
- if (size === 0) {
232
- switch (op.Opcode) {
233
- case intcblockOpcode: {
234
- let foundInts: number[];
235
- [size, foundInts] = readIntConstBlock(program, pc);
236
- ints = ints.concat(foundInts);
237
- break;
238
- }
239
- case bytecblockOpcode: {
240
- let foundByteArrays: Uint8Array[];
241
- [size, foundByteArrays] = readByteConstBlock(program, pc);
242
- byteArrays = byteArrays.concat(foundByteArrays);
243
- break;
244
- }
245
- case pushintOpcode: {
246
- let foundInt: number;
247
- [size, foundInt] = readPushIntOp(program, pc);
248
- ints.push(foundInt);
249
- break;
250
- }
251
- case pushbytesOpcode: {
252
- let foundByteArray;
253
- [size, foundByteArray] = readPushByteOp(program, pc);
254
- byteArrays.push(foundByteArray);
255
- break;
256
- }
257
- default: {
258
- throw new Error('invalid instruction');
259
- }
260
- }
261
- }
262
- pc += size;
263
- }
264
- // costs calculated dynamically starting in v4
265
- if (version < 4 && cost > maxCost) {
266
- throw new Error('program too costly for version < 4. consider using v4.');
267
- }
268
- return [ints, byteArrays, true];
269
- }
270
-
271
- /**
272
- * checkProgram validates program for length and running cost
273
- *
274
- * @deprecated Validation relies on metadata (`langspec.json`) that
275
- * does not accurately represent opcode behavior across program versions.
276
- * The behavior of `checkProgram` relies on `langspec.json`.
277
- * Thus, this method is being deprecated.
278
- *
279
- * @param program - Program to check
280
- * @param args - Program arguments as array of Uint8Array arrays
281
- * @throws
282
- * @returns true if success
283
- */
284
- export function checkProgram(program: Uint8Array, args?: Uint8Array[]) {
285
- const [, , success] = readProgram(program, args);
286
- return success;
287
- }
288
-
289
- /** @deprecated for langspec.json is deprecated aross all SDKs */
290
- export function checkIntConstBlock(program: Uint8Array, pc: number) {
291
- const [size] = readIntConstBlock(program, pc);
292
- return size;
293
- }
294
-
295
- /** @deprecated for langspec.json is deprecated aross all SDKs */
296
- export function checkByteConstBlock(program: Uint8Array, pc: number) {
297
- const [size] = readByteConstBlock(program, pc);
298
- return size;
299
- }
300
-
301
- /** @deprecated for langspec.json is deprecated aross all SDKs */
302
- export function checkPushIntOp(program: Uint8Array, pc: number) {
303
- const [size] = readPushIntOp(program, pc);
304
- return size;
305
- }
306
-
307
- /** @deprecated for langspec.json is deprecated aross all SDKs */
308
- export function checkPushByteOp(program: Uint8Array, pc: number) {
309
- const [size] = readPushByteOp(program, pc);
310
- return size;
311
- }
312
-
313
- /** @deprecated for langspec.json is deprecated aross all SDKs */
314
- export const langspecEvalMaxVersion = langspec.EvalMaxVersion;
315
- /** @deprecated for langspec.json is deprecated aross all SDKs */
316
- export const langspecLogicSigVersion = langspec.LogicSigVersion;
@@ -1,219 +0,0 @@
1
- const address = require('../encoding/address');
2
- const encoding = require('../encoding/encoding');
3
- const group = require('../group');
4
- const logic = require('../logic/logic');
5
- const logicSig = require('../logicsig');
6
- const nacl = require('../nacl/naclWrappers');
7
- const templates = require('./templates');
8
- const transaction = require('../transaction');
9
-
10
- class DynamicFee {
11
- /**
12
- * DynamicFee contract allows you to create a transaction without
13
- * specifying the fee. The fee will be determined at the moment of
14
- * transfer.
15
- *
16
- * @deprecated This feature will be removed in v2.
17
- *
18
- * Constructor Parameters:
19
- * @param {string} receiver: address to receive the assets
20
- * @param {int} amount: amount of assets to transfer
21
- * @param {int} firstValid: first valid round for the transaction
22
- * @param {int} lastValid: last valid round for the transaction
23
- * @param {string} closeRemainder: if you would like to close the account after the transfer, specify the address that would recieve the remainder, else leave undefined
24
- * @param {string} lease: leave undefined to generate a random lease, or supply a lease as base64
25
- * @returns {DynamicFee}
26
- */
27
- constructor(receiver, amount, firstValid, lastValid, closeRemainder, lease) {
28
- // don't need to validate receiver, closeremainderto - insert will handle that
29
- if (!Number.isSafeInteger(amount) || amount < 0)
30
- throw Error('amount must be a positive number and smaller than 2^53-1');
31
- if (!Number.isSafeInteger(firstValid) || firstValid < 0)
32
- throw Error(
33
- 'firstValid must be a positive number and smaller than 2^53-1'
34
- );
35
- if (!Number.isSafeInteger(lastValid) || lastValid < 0)
36
- throw Error(
37
- 'lastValid must be a positive number and smaller than 2^53-1'
38
- );
39
-
40
- if (typeof closeRemainder === 'undefined') {
41
- // eslint-disable-next-line no-param-reassign
42
- closeRemainder = address.ALGORAND_ZERO_ADDRESS_STRING;
43
- }
44
- if (typeof lease === 'undefined') {
45
- const leaseBytes = nacl.randomBytes(32);
46
- // eslint-disable-next-line no-param-reassign
47
- lease = Buffer.from(leaseBytes).toString('base64');
48
- }
49
-
50
- const referenceProgramB64 =
51
- 'ASAFAgEHBgUmAyD+vKC7FEpaTqe0OKRoGsgObKEFvLYH/FZTJclWlfaiEyDmmpYeby1feshmB5JlUr6YI17TM2PKiJGLuck4qRW2+SB/g7Flf/H8U7ktwYFIodZd/C1LH6PWdyhK3dIAEm2QaTIEIhIzABAjEhAzAAcxABIQMwAIMQESEDEWIxIQMRAjEhAxBygSEDEJKRIQMQgkEhAxAiUSEDEEIQQSEDEGKhIQ';
52
- const referenceProgramBytes = Buffer.from(referenceProgramB64, 'base64');
53
- const referenceOffsets = [
54
- 5 /* firstValid */,
55
- 6 /* lastValid */,
56
- 7 /* receiver */,
57
- 11 /* closeRemainder */,
58
- 44 /* lease */,
59
- 76,
60
- ];
61
- const injectionVector = [
62
- amount,
63
- firstValid,
64
- lastValid,
65
- receiver,
66
- closeRemainder,
67
- lease,
68
- ];
69
- const injectionTypes = [
70
- templates.valTypes.INT,
71
- templates.valTypes.INT,
72
- templates.valTypes.INT,
73
- templates.valTypes.ADDRESS,
74
- templates.valTypes.ADDRESS,
75
- templates.valTypes.BASE64,
76
- ];
77
- const injectedBytes = templates.inject(
78
- referenceProgramBytes,
79
- referenceOffsets,
80
- injectionVector,
81
- injectionTypes
82
- );
83
- this.programBytes = injectedBytes;
84
- const lsig = new logicSig.LogicSig(injectedBytes, undefined);
85
- this.address = lsig.address();
86
- }
87
-
88
- /**
89
- * returns the program bytes
90
- * @returns {Uint8Array}
91
- */
92
- getProgram() {
93
- return this.programBytes;
94
- }
95
-
96
- /**
97
- * returns the string address of the contract
98
- * @returns {string}
99
- */
100
- getAddress() {
101
- return this.address;
102
- }
103
- }
104
- /**
105
- * signDynamicFee returns the main transaction and signed logic needed to complete the transfer.
106
- * These should be sent to the fee payer, who can use GetDynamicFeeTransactions
107
- *
108
- * @deprecated This feature will be removed in v2.
109
- *
110
- * @param {Uint8Array} contract: the bytearray representing the contract
111
- * @param {Uint8Array} secretKey: the secret key for building the logic sig
112
- * @param {string} genesisHash: the genesisHash to use for the txn
113
- * @returns {Object} object containing json of txnbuilder constructor arguments under "txn" and signed logicsig under "lsig"
114
- */
115
- function signDynamicFee(contract, secretKey, genesisHash) {
116
- const programOutputs = logic.readProgram(contract, undefined);
117
- const ints = programOutputs[0];
118
- const byteArrays = programOutputs[1];
119
- const keys = nacl.keyPairFromSecretKey(secretKey);
120
- const from = address.encodeAddress(keys.publicKey);
121
- const to = address.encodeAddress(byteArrays[0]);
122
- const fee = 0;
123
- const amount = ints[2];
124
- const closeRemainderTo = address.encodeAddress(byteArrays[1]);
125
- const firstRound = ints[3];
126
- const lastRound = ints[4];
127
- const lease = new Uint8Array(byteArrays[2]);
128
- const txn = {
129
- from,
130
- to,
131
- fee,
132
- amount,
133
- closeRemainderTo,
134
- firstRound,
135
- lastRound,
136
- genesisHash,
137
- type: 'pay',
138
- lease,
139
- };
140
-
141
- const lsig = new logicSig.LogicSig(contract, undefined);
142
- lsig.sign(secretKey);
143
- return { txn, lsig };
144
- }
145
-
146
- /**
147
- * getDynamicFeeTransactions creates and signs the secondary dynamic fee transaction, updates
148
- * transaction fields, and signs as the fee payer; it returns both
149
- * transactions as bytes suitable for sendRaw.
150
- *
151
- * @deprecated This feature will be removed in v2.
152
- *
153
- * Parameters:
154
- * @param {dict} txn - main transaction from payer's signDynamicFee output (a dict of constructor arguments, NOT a transaction.Transaction)
155
- * @param {LogicSig} lsig - the signed logic received from the payer's signDynamicFee output
156
- * @param {Uint8Array} privateKey - the private key for the account that pays the fee
157
- * @param {int} fee - fee per byte for both transactions
158
- *
159
- * @throws on invalid lsig
160
- */
161
- /* eslint-disable no-param-reassign */
162
- function getDynamicFeeTransactions(txn, lsig, privateKey, fee) {
163
- if (!lsig.verify(address.decodeAddress(txn.from).publicKey)) {
164
- throw new Error('invalid signature');
165
- }
166
-
167
- txn.fee = fee;
168
- if (txn.fee < transaction.ALGORAND_MIN_TX_FEE) {
169
- txn.fee = transaction.ALGORAND_MIN_TX_FEE;
170
- }
171
-
172
- const keys = nacl.keyPairFromSecretKey(privateKey);
173
- const from = address.encodeAddress(keys.publicKey);
174
-
175
- // must remove lease and re-add using addLease so that fee calculation will match other SDKs
176
- const { lease } = txn;
177
- delete txn.lease;
178
-
179
- const txnObj = new transaction.Transaction(txn);
180
- txnObj.addLease(lease, fee);
181
-
182
- const feePayTxn = {
183
- from,
184
- to: txn.from,
185
- fee,
186
- amount: txnObj.fee, // calculated after txnObj is built to have the correct fee
187
- firstRound: txn.firstRound,
188
- lastRound: txn.lastRound,
189
- genesisHash: txn.genesisHash,
190
- type: 'pay',
191
- };
192
- const feePayTxnObj = new transaction.Transaction(feePayTxn);
193
- feePayTxnObj.addLease(lease, fee);
194
-
195
- const txnGroup = group.assignGroupID([feePayTxnObj, txnObj], undefined);
196
- const feePayTxnWithGroup = txnGroup[0];
197
- const txnObjWithGroup = txnGroup[1];
198
-
199
- const lstx = {
200
- lsig: lsig.get_obj_for_encoding(),
201
- txn: txnObjWithGroup.get_obj_for_encoding(),
202
- };
203
-
204
- const stx1 = feePayTxnWithGroup.signTxn(privateKey);
205
- const stx2 = encoding.encode(lstx);
206
-
207
- const concatStx = new Uint8Array(stx1.length + stx2.length);
208
- concatStx.set(stx1);
209
- concatStx.set(stx2, stx1.length);
210
-
211
- return concatStx;
212
- }
213
- /* eslint-enable no-param-reassign */
214
-
215
- module.exports = {
216
- DynamicFee,
217
- getDynamicFeeTransactions,
218
- signDynamicFee,
219
- };
@@ -1,165 +0,0 @@
1
- const sha256 = require('js-sha256');
2
- const { keccak256 } = require('js-sha3');
3
- const logic = require('../logic/logic');
4
- const logicSig = require('../logicsig');
5
- const templates = require('./templates');
6
- const transaction = require('../transaction');
7
-
8
- class HTLC {
9
- /**
10
- * HTLC allows a user to receive the Algo prior to a deadline (in terms of a round) by proving a knowledge
11
- * of a special value or to forfeit the ability to claim, returning it to the payer.
12
- * This contract is usually used to perform cross-chained atomic swaps
13
- *
14
- * More formally -
15
- * Algos can be transferred under only two circumstances:
16
- * 1. To receiver if hash_function(arg_0) = hash_value
17
- * 2. To owner if txn.FirstValid > expiry_round
18
- * ...
19
- *
20
- * @deprecated This feature will be removed in v2.
21
- *
22
- *Parameters
23
- *----------
24
- * @param {string} owner: an address that can receive the asset after the expiry round
25
- * @param {string} receiver: address to receive Algos
26
- * @param {string} hashFunction: the hash function to be used (must be either sha256 or keccak256)
27
- * @param {string} hashImage: the hash image in base64
28
- * @param {int} expiryRound: the round on which the assets can be transferred back to owner
29
- * @param {int} maxFee: the maximum fee that can be paid to the network by the account
30
- * @returns {HTLC}
31
- */
32
- constructor(owner, receiver, hashFunction, hashImage, expiryRound, maxFee) {
33
- // don't need to validate owner, receiver - they'll be validated by template.insert
34
- if (!Number.isSafeInteger(expiryRound) || expiryRound < 0)
35
- throw Error(
36
- 'expiryRound must be a positive number and smaller than 2^53-1'
37
- );
38
- if (!Number.isSafeInteger(maxFee) || maxFee < 0)
39
- throw Error('maxFee must be a positive number and smaller than 2^53-1');
40
-
41
- let referenceProgramB64 = '';
42
- if (hashFunction === 'sha256') {
43
- referenceProgramB64 =
44
- 'ASAECAEACSYDIOaalh5vLV96yGYHkmVSvpgjXtMzY8qIkYu5yTipFbb5IH+DsWV/8fxTuS3BgUih1l38LUsfo9Z3KErd0gASbZBpIP68oLsUSlpOp7Q4pGgayA5soQW8tgf8VlMlyVaV9qITMQEiDjEQIxIQMQcyAxIQMQgkEhAxCSgSLQEpEhAxCSoSMQIlDRAREA==';
45
- } else if (hashFunction === 'keccak256') {
46
- referenceProgramB64 =
47
- 'ASAECAEACSYDIOaalh5vLV96yGYHkmVSvpgjXtMzY8qIkYu5yTipFbb5IH+DsWV/8fxTuS3BgUih1l38LUsfo9Z3KErd0gASbZBpIP68oLsUSlpOp7Q4pGgayA5soQW8tgf8VlMlyVaV9qITMQEiDjEQIxIQMQcyAxIQMQgkEhAxCSgSLQIpEhAxCSoSMQIlDRAREA==';
48
- } else {
49
- throw Error('hash function unrecognized');
50
- }
51
- // validate hashImage length
52
- const hashImageBytes = Buffer.from(hashImage, 'base64');
53
- if (hashImageBytes.length !== 32)
54
- throw Error('hash image must be 32 bytes');
55
-
56
- const referenceProgramBytes = Buffer.from(referenceProgramB64, 'base64');
57
- const referenceOffsets = [
58
- 3 /* expiryRound */,
59
- 6 /* receiver */,
60
- 10 /* hashImage */,
61
- 42 /* owner */,
62
- 76,
63
- ];
64
- const injectionVector = [maxFee, expiryRound, receiver, hashImage, owner];
65
- const injectionTypes = [
66
- templates.valTypes.INT,
67
- templates.valTypes.INT,
68
- templates.valTypes.ADDRESS,
69
- templates.valTypes.BASE64,
70
- templates.valTypes.ADDRESS,
71
- ];
72
- const injectedBytes = templates.inject(
73
- referenceProgramBytes,
74
- referenceOffsets,
75
- injectionVector,
76
- injectionTypes
77
- );
78
- this.programBytes = injectedBytes;
79
- const lsig = new logicSig.LogicSig(injectedBytes, undefined);
80
- this.address = lsig.address();
81
- }
82
-
83
- /**
84
- * returns the program bytes
85
- * @returns {Uint8Array}
86
- */
87
- getProgram() {
88
- return this.programBytes;
89
- }
90
-
91
- /**
92
- * returns the string address of the contract
93
- * @returns {string}
94
- */
95
- getAddress() {
96
- return this.address;
97
- }
98
- }
99
-
100
- /**
101
- * signTransactionWithHTLCUnlock accepts a transaction, such as a payment, and builds the HTLC-unlocking signature around that transaction
102
- *
103
- * @deprecated This feature will be removed in v2.
104
- *
105
- * @param {Uint8Array} contract : byte representation of the HTLC
106
- * @param {Object} txn dictionary containing constructor arguments for a transaction
107
- * @param {string} preImageAsBase64 : preimage of the hash as base64 string
108
- *
109
- * @returns {Object} Object containing txID and blob representing signed transaction.
110
- * @throws error on validation failure
111
- */
112
- function signTransactionWithHTLCUnlock(contract, txn, preImageAsBase64) {
113
- const preImageBytes = Buffer.from(preImageAsBase64, 'base64');
114
-
115
- // hash validation
116
- const readResult = logic.readProgram(contract, undefined);
117
- const ints = readResult[0];
118
- const byteArrays = readResult[1];
119
- const expectedHashedOutput = byteArrays[1];
120
- const hashFunction = contract[contract.length - 15];
121
- if (hashFunction === 1) {
122
- const hash = sha256.create();
123
- hash.update(preImageBytes);
124
- const actualHashedOutput = Buffer.from(hash.hex(), 'hex');
125
- if (!actualHashedOutput.equals(expectedHashedOutput)) {
126
- throw new Error(
127
- 'sha256 hash of preimage did not match stored contract hash'
128
- );
129
- }
130
- } else if (hashFunction === 2) {
131
- const hash = keccak256.create();
132
- hash.update(preImageBytes);
133
- const actualHashedOutput = Buffer.from(hash.hex(), 'hex');
134
- if (!actualHashedOutput.equals(expectedHashedOutput)) {
135
- throw new Error(
136
- 'keccak256 hash of preimage did not match stored contract hash'
137
- );
138
- }
139
- } else {
140
- throw new Error('hash function in contract unrecognized');
141
- }
142
-
143
- const args = [preImageBytes]; // array of one element, the Uint8Array preimage
144
-
145
- const lsig = new logicSig.LogicSig(contract, args);
146
- // clear out receiver just in case
147
- // eslint-disable-next-line no-param-reassign
148
- delete txn.to;
149
-
150
- const maxFee = ints[0];
151
- // check fee
152
- const tempTxn = new transaction.Transaction(txn);
153
- if (tempTxn.fee > maxFee) {
154
- throw new Error(
155
- `final fee of payment transaction${tempTxn.fee.toString()}greater than transaction max fee${maxFee.toString()}`
156
- );
157
- }
158
-
159
- return logicSig.signLogicSigTransaction(txn, lsig);
160
- }
161
-
162
- module.exports = {
163
- HTLC,
164
- signTransactionWithHTLCUnlock,
165
- };