@algorandfoundation/algokit-utils 7.0.0-beta.3 → 7.0.0-beta.5

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 (170) hide show
  1. package/amount.d.ts +14 -4
  2. package/amount.d.ts.map +1 -1
  3. package/amount.js +6 -0
  4. package/amount.js.map +1 -1
  5. package/amount.mjs +6 -0
  6. package/amount.mjs.map +1 -1
  7. package/app-client.d.ts +15 -0
  8. package/app-client.d.ts.map +1 -1
  9. package/app-client.js +15 -0
  10. package/app-client.js.map +1 -1
  11. package/app-client.mjs +15 -0
  12. package/app-client.mjs.map +1 -1
  13. package/app-deploy.d.ts.map +1 -1
  14. package/app-deploy.js +4 -6
  15. package/app-deploy.js.map +1 -1
  16. package/app-deploy.mjs +5 -7
  17. package/app-deploy.mjs.map +1 -1
  18. package/app.d.ts +2 -2
  19. package/app.d.ts.map +1 -1
  20. package/app.js +7 -3
  21. package/app.js.map +1 -1
  22. package/app.mjs +7 -3
  23. package/app.mjs.map +1 -1
  24. package/asset.d.ts.map +1 -1
  25. package/asset.js +0 -3
  26. package/asset.js.map +1 -1
  27. package/asset.mjs +0 -3
  28. package/asset.mjs.map +1 -1
  29. package/debugging/debugging.d.ts +1 -1
  30. package/debugging/debugging.d.ts.map +1 -1
  31. package/debugging/debugging.js +4 -5
  32. package/debugging/debugging.js.map +1 -1
  33. package/debugging/debugging.mjs +4 -5
  34. package/debugging/debugging.mjs.map +1 -1
  35. package/index.d.ts +4 -4
  36. package/index.d.ts.map +1 -1
  37. package/index.js +37 -37
  38. package/index.mjs +5 -5
  39. package/package.json +1 -1
  40. package/testing/test-logger.d.ts.map +1 -1
  41. package/testing/test-logger.js +1 -3
  42. package/testing/test-logger.js.map +1 -1
  43. package/testing/test-logger.mjs +1 -3
  44. package/testing/test-logger.mjs.map +1 -1
  45. package/transaction/legacy-bridge.d.ts +3 -3
  46. package/transaction/legacy-bridge.d.ts.map +1 -1
  47. package/transaction/legacy-bridge.js +1 -1
  48. package/transaction/legacy-bridge.js.map +1 -1
  49. package/transaction/legacy-bridge.mjs +2 -2
  50. package/transaction/legacy-bridge.mjs.map +1 -1
  51. package/transaction/transaction.d.ts +34 -3
  52. package/transaction/transaction.d.ts.map +1 -1
  53. package/transaction/transaction.js +42 -11
  54. package/transaction/transaction.js.map +1 -1
  55. package/transaction/transaction.mjs +42 -11
  56. package/transaction/transaction.mjs.map +1 -1
  57. package/transfer/transfer.js +2 -2
  58. package/transfer/transfer.js.map +1 -1
  59. package/transfer/transfer.mjs +2 -2
  60. package/transfer/transfer.mjs.map +1 -1
  61. package/types/account-manager.d.ts +2 -2
  62. package/types/account-manager.d.ts.map +1 -1
  63. package/types/account-manager.js +1 -1
  64. package/types/account-manager.js.map +1 -1
  65. package/types/account-manager.mjs +1 -1
  66. package/types/account-manager.mjs.map +1 -1
  67. package/types/algorand-client-interface.d.ts +29 -0
  68. package/types/algorand-client-interface.d.ts.map +1 -0
  69. package/types/algorand-client-interface.js +3 -0
  70. package/types/algorand-client-interface.js.map +1 -0
  71. package/types/algorand-client-interface.mjs +2 -0
  72. package/types/algorand-client-interface.mjs.map +1 -0
  73. package/types/algorand-client-transaction-sender.d.ts +12 -12
  74. package/types/algorand-client-transaction-sender.d.ts.map +1 -1
  75. package/types/algorand-client-transaction-sender.js +22 -6
  76. package/types/algorand-client-transaction-sender.js.map +1 -1
  77. package/types/algorand-client-transaction-sender.mjs +22 -6
  78. package/types/algorand-client-transaction-sender.mjs.map +1 -1
  79. package/types/algorand-client.d.ts +2 -1
  80. package/types/algorand-client.d.ts.map +1 -1
  81. package/types/algorand-client.js +1 -1
  82. package/types/algorand-client.js.map +1 -1
  83. package/types/algorand-client.mjs +1 -1
  84. package/types/algorand-client.mjs.map +1 -1
  85. package/types/amount.d.ts +10 -10
  86. package/types/amount.d.ts.map +1 -1
  87. package/types/amount.js +7 -7
  88. package/types/amount.js.map +1 -1
  89. package/types/amount.mjs +7 -7
  90. package/types/amount.mjs.map +1 -1
  91. package/types/app-arc56.d.ts +326 -0
  92. package/types/app-arc56.d.ts.map +1 -0
  93. package/types/app-arc56.js +163 -0
  94. package/types/app-arc56.js.map +1 -0
  95. package/types/app-arc56.mjs +154 -0
  96. package/types/app-arc56.mjs.map +1 -0
  97. package/types/app-client.d.ts +1479 -7
  98. package/types/app-client.d.ts.map +1 -1
  99. package/types/app-client.js +814 -8
  100. package/types/app-client.js.map +1 -1
  101. package/types/app-client.mjs +814 -9
  102. package/types/app-client.mjs.map +1 -1
  103. package/types/app-deployer.d.ts +19 -13
  104. package/types/app-deployer.d.ts.map +1 -1
  105. package/types/app-deployer.js +2 -2
  106. package/types/app-deployer.js.map +1 -1
  107. package/types/app-deployer.mjs +2 -2
  108. package/types/app-deployer.mjs.map +1 -1
  109. package/types/app-factory.d.ts +967 -0
  110. package/types/app-factory.d.ts.map +1 -0
  111. package/types/app-factory.js +322 -0
  112. package/types/app-factory.js.map +1 -0
  113. package/types/app-factory.mjs +320 -0
  114. package/types/app-factory.mjs.map +1 -0
  115. package/types/app-manager.d.ts +12 -2
  116. package/types/app-manager.d.ts.map +1 -1
  117. package/types/app-manager.js +10 -1
  118. package/types/app-manager.js.map +1 -1
  119. package/types/app-manager.mjs +10 -1
  120. package/types/app-manager.mjs.map +1 -1
  121. package/types/app-spec.d.ts +2 -0
  122. package/types/app-spec.d.ts.map +1 -1
  123. package/types/app-spec.js +115 -0
  124. package/types/app-spec.js.map +1 -1
  125. package/types/app-spec.mjs +114 -0
  126. package/types/app-spec.mjs.map +1 -1
  127. package/types/app.d.ts +6 -2
  128. package/types/app.d.ts.map +1 -1
  129. package/types/asset-manager.d.ts +2 -1
  130. package/types/asset-manager.d.ts.map +1 -1
  131. package/types/asset-manager.js +0 -1
  132. package/types/asset-manager.js.map +1 -1
  133. package/types/asset-manager.mjs +0 -1
  134. package/types/asset-manager.mjs.map +1 -1
  135. package/types/client-manager.d.ts +109 -50
  136. package/types/client-manager.d.ts.map +1 -1
  137. package/types/client-manager.js +137 -23
  138. package/types/client-manager.js.map +1 -1
  139. package/types/client-manager.mjs +138 -24
  140. package/types/client-manager.mjs.map +1 -1
  141. package/types/composer.d.ts +31 -14
  142. package/types/composer.d.ts.map +1 -1
  143. package/types/composer.js +65 -10
  144. package/types/composer.js.map +1 -1
  145. package/types/composer.mjs +66 -11
  146. package/types/composer.mjs.map +1 -1
  147. package/types/debugging.d.ts +3 -2
  148. package/types/debugging.d.ts.map +1 -1
  149. package/types/debugging.js.map +1 -1
  150. package/types/debugging.mjs.map +1 -1
  151. package/types/dispenser-client.d.ts +1 -1
  152. package/types/dispenser-client.d.ts.map +1 -1
  153. package/types/dispenser-client.js +1 -1
  154. package/types/dispenser-client.js.map +1 -1
  155. package/types/dispenser-client.mjs +1 -1
  156. package/types/dispenser-client.mjs.map +1 -1
  157. package/types/network-client.d.ts +13 -0
  158. package/types/network-client.d.ts.map +1 -1
  159. package/types/network-client.js.map +1 -1
  160. package/types/network-client.mjs.map +1 -1
  161. package/types/testing.d.ts +3 -3
  162. package/types/testing.d.ts.map +1 -1
  163. package/types/transaction.d.ts +14 -1
  164. package/types/transaction.d.ts.map +1 -1
  165. package/util.d.ts +2 -1
  166. package/util.d.ts.map +1 -1
  167. package/util.js +11 -1
  168. package/util.js.map +1 -1
  169. package/util.mjs +11 -2
  170. package/util.mjs.map +1 -1
@@ -0,0 +1,326 @@
1
+ import algosdk from 'algosdk';
2
+ import { ABIReturn } from './app';
3
+ import { Expand } from './expand';
4
+ /**
5
+ * Wrapper around `algosdk.ABIMethod` that represents an ARC-56 ABI method.
6
+ */
7
+ export declare class Arc56Method extends algosdk.ABIMethod {
8
+ method: Method;
9
+ readonly args: Array<Expand<Omit<Method['args'][number], 'type'> & {
10
+ type: algosdk.ABIArgumentType;
11
+ }>>;
12
+ readonly returns: Expand<Omit<Method['returns'], 'type'> & {
13
+ type: algosdk.ABIReturnType;
14
+ }>;
15
+ constructor(method: Method);
16
+ toJSON(): Method;
17
+ }
18
+ /**
19
+ * Returns the `ABITupleType` for the given ARC-56 struct definition
20
+ * @param struct The ARC-56 struct definition
21
+ * @returns The `ABITupleType`
22
+ */
23
+ export declare function getABITupleTypeFromABIStructDefinition(struct: StructFields): algosdk.ABITupleType;
24
+ /**
25
+ * Converts a decoded ABI tuple as a struct.
26
+ * @param decodedABITuple The decoded ABI tuple value
27
+ * @param structFields The struct fields from an ARC-56 app spec
28
+ * @returns The struct as a Record<string, any>
29
+ */
30
+ export declare function getABIStructFromABITuple<TReturn extends ABIStruct = Record<string, any>>(decodedABITuple: algosdk.ABIValue[], structFields: StructFields): TReturn;
31
+ /**
32
+ * Converts an ARC-56 struct as an ABI tuple.
33
+ * @param struct The struct to convert
34
+ * @param structFields The struct fields from an ARC-56 app spec
35
+ * @returns The struct as a decoded ABI tuple
36
+ */
37
+ export declare function getABITupleFromABIStruct(struct: ABIStruct, structFields: StructFields): algosdk.ABIValue[];
38
+ /** Decoded ARC-56 struct as a struct rather than a tuple. */
39
+ export type ABIStruct = {
40
+ [key: string]: ABIStruct | algosdk.ABIValue;
41
+ };
42
+ /**
43
+ * Returns the decoded ABI value (or struct for a struct type)
44
+ * for the given raw Algorand value given an ARC-56 type and defined ARC-56 structs.
45
+ * @param value The raw Algorand value (bytes or uint64)
46
+ * @param type The ARC-56 type - either an ABI Type string or a struct name
47
+ * @param structs The defined ARC-56 structs
48
+ * @returns The decoded ABI value or struct
49
+ */
50
+ export declare function getABIDecodedValue(value: Uint8Array | number | bigint, type: string, structs: Record<string, StructFields>): algosdk.ABIValue | ABIStruct;
51
+ /**
52
+ * Returns the ABI-encoded value for the given value.
53
+ * @param value The value to encode either already in encoded binary form (`Uint8Array`), a decoded ABI value or an ARC-56 struct
54
+ * @param type The ARC-56 type - either an ABI Type string or a struct name
55
+ * @param structs The defined ARC-56 structs
56
+ * @returns The binary ABI-encoded value
57
+ */
58
+ export declare function getABIEncodedValue(value: Uint8Array | algosdk.ABIValue | ABIStruct, type: string, structs: Record<string, StructFields>): Uint8Array;
59
+ /**
60
+ * Returns the ARC-56 ABI method object for a given method name or signature and ARC-56 app spec.
61
+ * @param methodNameOrSignature The method name or method signature to call if an ABI call is being emitted.
62
+ * e.g. `my_method` or `my_method(unit64,string)bytes`
63
+ * @param appSpec The app spec for the app
64
+ * @returns The `Arc56Method`
65
+ */
66
+ export declare function getArc56Method(methodNameOrSignature: string, appSpec: Arc56Contract): Arc56Method;
67
+ /**
68
+ * Checks for decode errors on the AppCallTransactionResult and maps the return value to the specified generic type
69
+ *
70
+ * @param returnValue The smart contract response
71
+ * @param method The method that was called
72
+ * @param structs The struct fields from the app spec
73
+ * @returns The smart contract response with an updated return value
74
+ */
75
+ export declare function getArc56ReturnValue<TReturn extends Uint8Array | algosdk.ABIValue | ABIStruct | undefined>(returnValue: ABIReturn | undefined, method: Method | Arc56Method, structs: StructFields): TReturn;
76
+ /****************/
77
+ /** ARC-56 spec */
78
+ /****************/
79
+ /** Describes the entire contract. This interface is an extension of the interface described in ARC-4 */
80
+ export interface Arc56Contract {
81
+ /** The ARCs used and/or supported by this contract. All contracts implicity support ARC4 and ARC56 */
82
+ arcs: number[];
83
+ /** A user-friendly name for the contract */
84
+ name: string;
85
+ /** Optional, user-friendly description for the interface */
86
+ desc?: string;
87
+ /**
88
+ * Optional object listing the contract instances across different networks
89
+ */
90
+ networks?: {
91
+ /**
92
+ * The key is the base64 genesis hash of the network, and the value contains
93
+ * information about the deployed contract in the network indicated by the
94
+ * key. A key containing the human-readable name of the network MAY be
95
+ * included, but the corresponding genesis hash key MUST also be defined
96
+ */
97
+ [network: string]: {
98
+ /** The app ID of the deployed contract in this network */
99
+ appID: number;
100
+ };
101
+ };
102
+ /** Named structs use by the application */
103
+ structs: {
104
+ [structName: StructName]: StructFields;
105
+ };
106
+ /** All of the methods that the contract implements */
107
+ methods: Method[];
108
+ state: {
109
+ /** Defines the values that should be used for GlobalNumUint, GlobalNumByteSlice, LocalNumUint, and LocalNumByteSlice when creating the application */
110
+ schema: {
111
+ global: {
112
+ ints: number;
113
+ bytes: number;
114
+ };
115
+ local: {
116
+ ints: number;
117
+ bytes: number;
118
+ };
119
+ };
120
+ /** Mapping of human-readable names to StorageKey objects */
121
+ keys: {
122
+ global: {
123
+ [name: string]: StorageKey;
124
+ };
125
+ local: {
126
+ [name: string]: StorageKey;
127
+ };
128
+ box: {
129
+ [name: string]: StorageKey;
130
+ };
131
+ };
132
+ /** Mapping of human-readable names to StorageMap objects */
133
+ maps: {
134
+ global: {
135
+ [name: string]: StorageMap;
136
+ };
137
+ local: {
138
+ [name: string]: StorageMap;
139
+ };
140
+ box: {
141
+ [name: string]: StorageMap;
142
+ };
143
+ };
144
+ };
145
+ /** Supported bare actions for the contract. An action is a combination of call/create and an OnComplete */
146
+ bareActions: {
147
+ /** OnCompletes this method allows when appID === 0 */
148
+ create: ('NoOp' | 'OptIn' | 'DeleteApplication')[];
149
+ /** OnCompletes this method allows when appID !== 0 */
150
+ call: ('NoOp' | 'OptIn' | 'CloseOut' | 'ClearState' | 'UpdateApplication' | 'DeleteApplication')[];
151
+ };
152
+ /** Information about the TEAL programs */
153
+ sourceInfo?: {
154
+ /** Approval program information */
155
+ approval: SourceInfo[];
156
+ /** Clear program information */
157
+ clear: SourceInfo[];
158
+ };
159
+ /** The pre-compiled TEAL that may contain template variables. MUST be omitted if included as part of ARC23 */
160
+ source?: {
161
+ /** The approval program */
162
+ approval: string;
163
+ /** The clear program */
164
+ clear: string;
165
+ };
166
+ /** The compiled bytecode for the application. MUST be omitted if included as part of ARC23 */
167
+ byteCode?: {
168
+ /** The approval program */
169
+ approval: string;
170
+ /** The clear program */
171
+ clear: string;
172
+ };
173
+ /** Information used to get the given byteCode and/or PC values in sourceInfo. MUST be given if byteCode or PC values are present */
174
+ compilerInfo?: {
175
+ /** The name of the compiler */
176
+ compiler: 'algod' | 'puya';
177
+ /** Compiler version information */
178
+ compilerVersion: {
179
+ major: number;
180
+ minor: number;
181
+ patch: number;
182
+ commit?: string;
183
+ };
184
+ };
185
+ /** ARC-28 events that MAY be emitted by this contract */
186
+ events?: Array<Event>;
187
+ /** A mapping of template variable names as they appear in the teal (not including TMPL_ prefix) to their respecive types and values (if applicable) */
188
+ templateVariables?: {
189
+ [name: string]: {
190
+ /** The type of the template variable */
191
+ type: ABIType | AVMBytes | StructName;
192
+ /** If given, the the base64 encoded value used for the given app/program */
193
+ value?: string;
194
+ };
195
+ };
196
+ /** The scratch variables used during runtime */
197
+ scratchVariables?: {
198
+ [name: string]: {
199
+ slot: number;
200
+ type: ABIType | AVMBytes | StructName;
201
+ };
202
+ };
203
+ }
204
+ /** Describes a method in the contract. This interface is an extension of the interface described in ARC-4 */
205
+ export interface Method {
206
+ /** The name of the method */
207
+ name: string;
208
+ /** Optional, user-friendly description for the method */
209
+ desc?: string;
210
+ /** The arguments of the method, in order */
211
+ args: Array<{
212
+ /** The type of the argument */
213
+ type: ABIType;
214
+ /** If the type is a struct, the name of the struct */
215
+ struct?: StructName;
216
+ /** Optional, user-friendly name for the argument */
217
+ name?: string;
218
+ /** Optional, user-friendly description for the argument */
219
+ desc?: string;
220
+ /** The default value that clients should use. MUST be base64 encoded bytes */
221
+ defaultValue?: string;
222
+ }>;
223
+ /** Information about the method's return value */
224
+ returns: {
225
+ /** The type of the return value, or "void" to indicate no return value. */
226
+ type: ABIType;
227
+ /** If the type is a struct, the name of the struct */
228
+ struct?: StructName;
229
+ /** Optional, user-friendly description for the return value */
230
+ desc?: string;
231
+ };
232
+ /** an action is a combination of call/create and an OnComplete */
233
+ actions: {
234
+ /** OnCompletes this method allows when appID === 0 */
235
+ create: ('NoOp' | 'OptIn' | 'DeleteApplication')[];
236
+ /** OnCompletes this method allows when appID !== 0 */
237
+ call: ('NoOp' | 'OptIn' | 'CloseOut' | 'ClearState' | 'UpdateApplication' | 'DeleteApplication')[];
238
+ };
239
+ /** If this method does not write anything to the ledger (ARC-22) */
240
+ readonly?: boolean;
241
+ /** ARC-28 events that MAY be emitted by this method */
242
+ events?: Array<Event>;
243
+ /** Information that clients can use when calling the method */
244
+ recommendations?: {
245
+ /** The number of inner transactions the caller should cover the fees for */
246
+ innerTransactionCount?: number;
247
+ /** Recommended box references to include */
248
+ boxes?: {
249
+ /** The app ID for the box */
250
+ app?: number;
251
+ /** The base64 encoded box key */
252
+ key: string;
253
+ /** The number of bytes being read from the box */
254
+ readBytes: number;
255
+ /** The number of bytes being written to the box */
256
+ writeBytes: number;
257
+ };
258
+ /** Recommended foreign accounts */
259
+ accounts?: string[];
260
+ /** Recommended foreign apps */
261
+ apps?: number[];
262
+ /** Recommended foreign assets */
263
+ assets?: number[];
264
+ };
265
+ }
266
+ /** ARC-28 event */
267
+ export interface Event {
268
+ /** The name of the event */
269
+ name: string;
270
+ /** Optional, user-friendly description for the event */
271
+ desc?: string;
272
+ /** The arguments of the event, in order */
273
+ args: Array<{
274
+ /** The type of the argument */
275
+ type: ABIType;
276
+ /** Optional, user-friendly name for the argument */
277
+ name?: string;
278
+ /** Optional, user-friendly description for the argument */
279
+ desc?: string;
280
+ /** If the type is a struct, the name of the struct */
281
+ struct?: StructName;
282
+ }>;
283
+ }
284
+ /** An ABI-encoded type */
285
+ export type ABIType = string;
286
+ /** The name of a defined struct */
287
+ export type StructName = string;
288
+ /** Raw byteslice without the length prefixed that is specified in ARC-4 */
289
+ export type AVMBytes = 'bytes';
290
+ /** Mapping of named structs to the ABI type of their fields */
291
+ export interface StructFields {
292
+ [fieldName: string]: ABIType | StructFields;
293
+ }
294
+ /** Describes a single key in app storage */
295
+ export interface StorageKey {
296
+ /** Description of what this storage key holds */
297
+ desc?: string;
298
+ /** The type of the key */
299
+ keyType: ABIType | AVMBytes | StructName;
300
+ /** The type of the value */
301
+ valueType: ABIType | AVMBytes | StructName;
302
+ /** The bytes of the key encoded as base64 */
303
+ key: string;
304
+ }
305
+ /** Describes a mapping of key-value pairs in storage */
306
+ export interface StorageMap {
307
+ /** Description of what the key-value pairs in this mapping hold */
308
+ desc?: string;
309
+ /** The type of the keys in the map */
310
+ keyType: ABIType | AVMBytes | StructName;
311
+ /** The type of the values in the map */
312
+ valueType: ABIType | AVMBytes | StructName;
313
+ /** The base64-encoded prefix of the map keys*/
314
+ prefix?: string;
315
+ }
316
+ export interface SourceInfo {
317
+ /** The line of pre-compiled TEAL */
318
+ teal?: number;
319
+ /** The program counter offset(s) that correspond to this line of TEAL */
320
+ pc?: Array<number>;
321
+ /** A human-readable string that describes the error when the program fails at this given line of TEAL */
322
+ errorMessage?: string;
323
+ /** The line of the dissasembled TEAL this line of pre-compiled TEAL corresponds to */
324
+ disassembledTeal?: number;
325
+ }
326
+ //# sourceMappingURL=app-arc56.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app-arc56.d.ts","sourceRoot":"","sources":["../../src/types/app-arc56.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAA;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACjC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAEjC;;GAEG;AACH,qBAAa,WAAY,SAAQ,OAAO,CAAC,SAAS;IAc7B,MAAM,EAAE,MAAM;IAbjC,SAAkB,IAAI,EAAE,KAAK,CAC3B,MAAM,CACJ,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,GAAG;QACrC,IAAI,EAAE,OAAO,CAAC,eAAe,CAAA;KAC9B,CACF,CACF,CAAA;IACD,SAAkB,OAAO,EAAE,MAAM,CAC/B,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC,GAAG;QAChC,IAAI,EAAE,OAAO,CAAC,aAAa,CAAA;KAC5B,CACF,CAAA;gBAEkB,MAAM,EAAE,MAAM;IAYxB,MAAM,IAAI,MAAM;CAG1B;AAED;;;;GAIG;AACH,wBAAgB,sCAAsC,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,YAAY,CAIjG;AAED;;;;;GAKG;AAEH,wBA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A4C;AAC5C,MAAM,WAAW,UAAU;IACzB,iDAAiD;IACjD,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,0BAA0B;IAC1B,OAAO,EAAE,OAAO,GAAG,QAAQ,GAAG,UAAU,CAAA;IAExC,4BAA4B;IAC5B,SAAS,EAAE,OAAO,GAAG,QAAQ,GAAG,UAAU,CAAA;IAC1C,6CAA6C;IAC7C,GAAG,EAAE,MAAM,CAAA;CACZ;AAED,wDAAwD;AACxD,MAAM,WAAW,UAAU;IACzB,mEAAmE;IACnE,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,sCAAsC;IACtC,OAAO,EAAE,OAAO,GAAG,QAAQ,GAAG,UAAU,CAAA;IACxC,wCAAwC;IACxC,SAAS,EAAE,OAAO,GAAG,QAAQ,GAAG,UAAU,CAAA;IAC1C,+CAA+C;IAC/C,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,UAAU;IACzB,oCAAoC;IACpC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,yEAAyE;IACzE,EAAE,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;IAClB,yGAAyG;IACzG,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,sFAAsF;IACtF,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAC1B"}
@@ -0,0 +1,163 @@
1
+ 'use strict';
2
+
3
+ var algosdk = require('algosdk');
4
+
5
+ /**
6
+ * Wrapper around `algosdk.ABIMethod` that represents an ARC-56 ABI method.
7
+ */
8
+ class Arc56Method extends algosdk.ABIMethod {
9
+ constructor(method) {
10
+ super(method);
11
+ this.method = method;
12
+ this.args = method.args.map((arg) => ({
13
+ ...arg,
14
+ type: algosdk.abiTypeIsTransaction(arg.type) || algosdk.abiTypeIsReference(arg.type) ? arg.type : algosdk.ABIType.from(arg.type),
15
+ }));
16
+ this.returns = {
17
+ ...this.method.returns,
18
+ type: this.method.returns.type === 'void' ? 'void' : algosdk.ABIType.from(this.method.returns.type),
19
+ };
20
+ }
21
+ toJSON() {
22
+ return this.method;
23
+ }
24
+ }
25
+ /**
26
+ * Returns the `ABITupleType` for the given ARC-56 struct definition
27
+ * @param struct The ARC-56 struct definition
28
+ * @returns The `ABITupleType`
29
+ */
30
+ function getABITupleTypeFromABIStructDefinition(struct) {
31
+ return new algosdk.ABITupleType(Object.values(struct).map((v) => (typeof v === 'string' ? algosdk.ABIType.from(v) : getABITupleTypeFromABIStructDefinition(v))));
32
+ }
33
+ /**
34
+ * Converts a decoded ABI tuple as a struct.
35
+ * @param decodedABITuple The decoded ABI tuple value
36
+ * @param structFields The struct fields from an ARC-56 app spec
37
+ * @returns The struct as a Record<string, any>
38
+ */
39
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
40
+ function getABIStructFromABITuple(decodedABITuple, structFields) {
41
+ return Object.fromEntries(Object.entries(structFields).map(([key, type], i) => {
42
+ const abiValue = decodedABITuple[i];
43
+ return [key, typeof type === 'string' || !Array.isArray(abiValue) ? decodedABITuple[i] : getABIStructFromABITuple(abiValue, type)];
44
+ }));
45
+ }
46
+ /**
47
+ * Converts an ARC-56 struct as an ABI tuple.
48
+ * @param struct The struct to convert
49
+ * @param structFields The struct fields from an ARC-56 app spec
50
+ * @returns The struct as a decoded ABI tuple
51
+ */
52
+ function getABITupleFromABIStruct(struct, structFields) {
53
+ return Object.entries(structFields).map(([key, type]) => {
54
+ const value = struct[key];
55
+ return typeof type === 'string' ? value : getABITupleFromABIStruct(value, type);
56
+ });
57
+ }
58
+ /**
59
+ * Returns the decoded ABI value (or struct for a struct type)
60
+ * for the given raw Algorand value given an ARC-56 type and defined ARC-56 structs.
61
+ * @param value The raw Algorand value (bytes or uint64)
62
+ * @param type The ARC-56 type - either an ABI Type string or a struct name
63
+ * @param structs The defined ARC-56 structs
64
+ * @returns The decoded ABI value or struct
65
+ */
66
+ function getABIDecodedValue(value, type, structs) {
67
+ if (type === 'bytes' || typeof value !== 'object')
68
+ return value;
69
+ if (structs[type]) {
70
+ const tupleValue = getABITupleTypeFromABIStructDefinition(structs[type]).decode(value);
71
+ return getABIStructFromABITuple(tupleValue, structs[type]);
72
+ }
73
+ return algosdk.ABIType.from(type).decode(value);
74
+ }
75
+ /**
76
+ * Returns the ABI-encoded value for the given value.
77
+ * @param value The value to encode either already in encoded binary form (`Uint8Array`), a decoded ABI value or an ARC-56 struct
78
+ * @param type The ARC-56 type - either an ABI Type string or a struct name
79
+ * @param structs The defined ARC-56 structs
80
+ * @returns The binary ABI-encoded value
81
+ */
82
+ function getABIEncodedValue(value, type, structs) {
83
+ if (typeof value === 'object' && value instanceof Uint8Array)
84
+ return value;
85
+ if (type === 'bytes') {
86
+ if (typeof value === 'string')
87
+ return Buffer.from(value, 'utf-8');
88
+ if (typeof value !== 'object' || !(value instanceof Uint8Array))
89
+ throw new Error(`Expected bytes value for ${type}, but got ${value}`);
90
+ return value;
91
+ }
92
+ if (structs[type]) {
93
+ const tupleType = getABITupleTypeFromABIStructDefinition(structs[type]);
94
+ if (Array.isArray(value)) {
95
+ tupleType.encode(value);
96
+ }
97
+ else {
98
+ return tupleType.encode(getABITupleFromABIStruct(value, structs[type]));
99
+ }
100
+ }
101
+ return algosdk.ABIType.from(type).encode(value);
102
+ }
103
+ /**
104
+ * Returns the ARC-56 ABI method object for a given method name or signature and ARC-56 app spec.
105
+ * @param methodNameOrSignature The method name or method signature to call if an ABI call is being emitted.
106
+ * e.g. `my_method` or `my_method(unit64,string)bytes`
107
+ * @param appSpec The app spec for the app
108
+ * @returns The `Arc56Method`
109
+ */
110
+ function getArc56Method(methodNameOrSignature, appSpec) {
111
+ let method;
112
+ if (!methodNameOrSignature.includes('(')) {
113
+ const methods = appSpec.methods.filter((m) => m.name === methodNameOrSignature);
114
+ if (methods.length === 0)
115
+ throw new Error(`Unable to find method ${methodNameOrSignature} in ${appSpec.name} app.`);
116
+ if (methods.length > 1) {
117
+ throw new Error(`Received a call to method ${methodNameOrSignature} in contract ${appSpec.name}, but this resolved to multiple methods; please pass in an ABI signature instead: ${appSpec.methods
118
+ .map((m) => new algosdk.ABIMethod(m).getSignature())
119
+ .join(', ')}`);
120
+ }
121
+ method = methods[0];
122
+ }
123
+ else {
124
+ const m = appSpec.methods.find((m) => new algosdk.ABIMethod(m).getSignature() === methodNameOrSignature);
125
+ if (!m)
126
+ throw new Error(`Unable to find method ${methodNameOrSignature} in ${appSpec.name} app.`);
127
+ method = m;
128
+ }
129
+ return new Arc56Method(method);
130
+ }
131
+ /**
132
+ * Checks for decode errors on the AppCallTransactionResult and maps the return value to the specified generic type
133
+ *
134
+ * @param returnValue The smart contract response
135
+ * @param method The method that was called
136
+ * @param structs The struct fields from the app spec
137
+ * @returns The smart contract response with an updated return value
138
+ */
139
+ function getArc56ReturnValue(returnValue, method, structs) {
140
+ const m = 'method' in method ? method.method : method;
141
+ const type = m.returns.struct ?? m.returns.type;
142
+ if (returnValue?.decodeError) {
143
+ throw returnValue.decodeError;
144
+ }
145
+ if (type === undefined || type === 'void' || returnValue?.returnValue === undefined)
146
+ return undefined;
147
+ if (type === 'bytes')
148
+ return returnValue.rawReturnValue;
149
+ if (structs[type]) {
150
+ return getABIStructFromABITuple(returnValue.returnValue, structs[type]);
151
+ }
152
+ return returnValue.returnValue;
153
+ }
154
+
155
+ exports.Arc56Method = Arc56Method;
156
+ exports.getABIDecodedValue = getABIDecodedValue;
157
+ exports.getABIEncodedValue = getABIEncodedValue;
158
+ exports.getABIStructFromABITuple = getABIStructFromABITuple;
159
+ exports.getABITupleFromABIStruct = getABITupleFromABIStruct;
160
+ exports.getABITupleTypeFromABIStructDefinition = getABITupleTypeFromABIStructDefinition;
161
+ exports.getArc56Method = getArc56Method;
162
+ exports.getArc56ReturnValue = getArc56ReturnValue;
163
+ //# sourceMappingURL=app-arc56.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"app-arc56.js","sources":["../../src/types/app-arc56.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAIA;;AAEG;AACU,MAAA,WAAY,SAAQ,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AAED;;;;;;;AAOG;SACa,mBAAmB,CACjC,WAAkC,EAClC,MAA4B,EAC5B,OAAqB,EAAA;AAErB,IAAA,MAAM,CAAC,GAAG,QAAQ,IAAI,MAAM,GAAG,MAAM,CAAC,MAAM,GAAG,MAAM,CAAA;AACrD,IAAA,MAAM,IAAI,GAAG,CAAC,CAAC,OAAO,CAAC,MAAM,IAAI,CAAC,CAAC,OAAO,CAAC,IAAI,CAAA;AAC/C,IAAA,IAAI,WAAW,EAAE,WAAW,EAAE;QAC5B,MAAM,WAAW,CAAC,WAAW,CAAA;KAC9B;AACD,IAAA,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,MAAM,IAAI,WAAW,EAAE,WAAW,KAAK,SAAS;AAAE,QAAA,OAAO,SAAoB,CAAA;IAEhH,IAAI,IAAI,KAAK,OAAO;QAAE,OAAO,WAAW,CAAC,cAAyB,CAAA;AAElE,IAAA,IAAI,OAAO,CAAC,IAAI,CAAC,EAAE;QACjB,OAAO,wBAAwB,CAAC,WAAW,CAAC,WAAiC,EAAE,OAAO,CAAC,IAAI,CAAiB,CAAY,CAAA;KACzH;IAED,OAAO,WAAW,CAAC,WAAsB,CAAA;AAC3C;;;;;;;;;;;"}
@@ -0,0 +1,154 @@
1
+ import algosdk from 'algosdk';
2
+
3
+ /**
4
+ * Wrapper around `algosdk.ABIMethod` that represents an ARC-56 ABI method.
5
+ */
6
+ class Arc56Method extends algosdk.ABIMethod {
7
+ constructor(method) {
8
+ super(method);
9
+ this.method = method;
10
+ this.args = method.args.map((arg) => ({
11
+ ...arg,
12
+ type: algosdk.abiTypeIsTransaction(arg.type) || algosdk.abiTypeIsReference(arg.type) ? arg.type : algosdk.ABIType.from(arg.type),
13
+ }));
14
+ this.returns = {
15
+ ...this.method.returns,
16
+ type: this.method.returns.type === 'void' ? 'void' : algosdk.ABIType.from(this.method.returns.type),
17
+ };
18
+ }
19
+ toJSON() {
20
+ return this.method;
21
+ }
22
+ }
23
+ /**
24
+ * Returns the `ABITupleType` for the given ARC-56 struct definition
25
+ * @param struct The ARC-56 struct definition
26
+ * @returns The `ABITupleType`
27
+ */
28
+ function getABITupleTypeFromABIStructDefinition(struct) {
29
+ return new algosdk.ABITupleType(Object.values(struct).map((v) => (typeof v === 'string' ? algosdk.ABIType.from(v) : getABITupleTypeFromABIStructDefinition(v))));
30
+ }
31
+ /**
32
+ * Converts a decoded ABI tuple as a struct.
33
+ * @param decodedABITuple The decoded ABI tuple value
34
+ * @param structFields The struct fields from an ARC-56 app spec
35
+ * @returns The struct as a Record<string, any>
36
+ */
37
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
38
+ function getABIStructFromABITuple(decodedABITuple, structFields) {
39
+ return Object.fromEntries(Object.entries(structFields).map(([key, type], i) => {
40
+ const abiValue = decodedABITuple[i];
41
+ return [key, typeof type === 'string' || !Array.isArray(abiValue) ? decodedABITuple[i] : getABIStructFromABITuple(abiValue, type)];
42
+ }));
43
+ }
44
+ /**
45
+ * Converts an ARC-56 struct as an ABI tuple.
46
+ * @param struct The struct to convert
47
+ * @param structFields The struct fields from an ARC-56 app spec
48
+ * @returns The struct as a decoded ABI tuple
49
+ */
50
+ function getABITupleFromABIStruct(struct, structFields) {
51
+ return Object.entries(structFields).map(([key, type]) => {
52
+ const value = struct[key];
53
+ return typeof type === 'string' ? value : getABITupleFromABIStruct(value, type);
54
+ });
55
+ }
56
+ /**
57
+ * Returns the decoded ABI value (or struct for a struct type)
58
+ * for the given raw Algorand value given an ARC-56 type and defined ARC-56 structs.
59
+ * @param value The raw Algorand value (bytes or uint64)
60
+ * @param type The ARC-56 type - either an ABI Type string or a struct name
61
+ * @param structs The defined ARC-56 structs
62
+ * @returns The decoded ABI value or struct
63
+ */
64
+ function getABIDecodedValue(value, type, structs) {
65
+ if (type === 'bytes' || typeof value !== 'object')
66
+ return value;
67
+ if (structs[type]) {
68
+ const tupleValue = getABITupleTypeFromABIStructDefinition(structs[type]).decode(value);
69
+ return getABIStructFromABITuple(tupleValue, structs[type]);
70
+ }
71
+ return algosdk.ABIType.from(type).decode(value);
72
+ }
73
+ /**
74
+ * Returns the ABI-encoded value for the given value.
75
+ * @param value The value to encode either already in encoded binary form (`Uint8Array`), a decoded ABI value or an ARC-56 struct
76
+ * @param type The ARC-56 type - either an ABI Type string or a struct name
77
+ * @param structs The defined ARC-56 structs
78
+ * @returns The binary ABI-encoded value
79
+ */
80
+ function getABIEncodedValue(value, type, structs) {
81
+ if (typeof value === 'object' && value instanceof Uint8Array)
82
+ return value;
83
+ if (type === 'bytes') {
84
+ if (typeof value === 'string')
85
+ return Buffer.from(value, 'utf-8');
86
+ if (typeof value !== 'object' || !(value instanceof Uint8Array))
87
+ throw new Error(`Expected bytes value for ${type}, but got ${value}`);
88
+ return value;
89
+ }
90
+ if (structs[type]) {
91
+ const tupleType = getABITupleTypeFromABIStructDefinition(structs[type]);
92
+ if (Array.isArray(value)) {
93
+ tupleType.encode(value);
94
+ }
95
+ else {
96
+ return tupleType.encode(getABITupleFromABIStruct(value, structs[type]));
97
+ }
98
+ }
99
+ return algosdk.ABIType.from(type).encode(value);
100
+ }
101
+ /**
102
+ * Returns the ARC-56 ABI method object for a given method name or signature and ARC-56 app spec.
103
+ * @param methodNameOrSignature The method name or method signature to call if an ABI call is being emitted.
104
+ * e.g. `my_method` or `my_method(unit64,string)bytes`
105
+ * @param appSpec The app spec for the app
106
+ * @returns The `Arc56Method`
107
+ */
108
+ function getArc56Method(methodNameOrSignature, appSpec) {
109
+ let method;
110
+ if (!methodNameOrSignature.includes('(')) {
111
+ const methods = appSpec.methods.filter((m) => m.name === methodNameOrSignature);
112
+ if (methods.length === 0)
113
+ throw new Error(`Unable to find method ${methodNameOrSignature} in ${appSpec.name} app.`);
114
+ if (methods.length > 1) {
115
+ throw new Error(`Received a call to method ${methodNameOrSignature} in contract ${appSpec.name}, but this resolved to multiple methods; please pass in an ABI signature instead: ${appSpec.methods
116
+ .map((m) => new algosdk.ABIMethod(m).getSignature())
117
+ .join(', ')}`);
118
+ }
119
+ method = methods[0];
120
+ }
121
+ else {
122
+ const m = appSpec.methods.find((m) => new algosdk.ABIMethod(m).getSignature() === methodNameOrSignature);
123
+ if (!m)
124
+ throw new Error(`Unable to find method ${methodNameOrSignature} in ${appSpec.name} app.`);
125
+ method = m;
126
+ }
127
+ return new Arc56Method(method);
128
+ }
129
+ /**
130
+ * Checks for decode errors on the AppCallTransactionResult and maps the return value to the specified generic type
131
+ *
132
+ * @param returnValue The smart contract response
133
+ * @param method The method that was called
134
+ * @param structs The struct fields from the app spec
135
+ * @returns The smart contract response with an updated return value
136
+ */
137
+ function getArc56ReturnValue(returnValue, method, structs) {
138
+ const m = 'method' in method ? method.method : method;
139
+ const type = m.returns.struct ?? m.returns.type;
140
+ if (returnValue?.decodeError) {
141
+ throw returnValue.decodeError;
142
+ }
143
+ if (type === undefined || type === 'void' || returnValue?.returnValue === undefined)
144
+ return undefined;
145
+ if (type === 'bytes')
146
+ return returnValue.rawReturnValue;
147
+ if (structs[type]) {
148
+ return getABIStructFromABITuple(returnValue.returnValue, structs[type]);
149
+ }
150
+ return returnValue.returnValue;
151
+ }
152
+
153
+ export { Arc56Method, getABIDecodedValue, getABIEncodedValue, getABIStructFromABITuple, getABITupleFromABIStruct, getABITupleTypeFromABIStructDefinition, getArc56Method, getArc56ReturnValue };
154
+ //# sourceMappingURL=app-arc56.mjs.map