@algorandfoundation/algorand-typescript 1.0.0-beta.3 → 1.0.0-beta.30

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 (54) hide show
  1. package/arc-28.d.ts +1 -1
  2. package/arc4/c2c.d.ts +81 -0
  3. package/arc4/encoded-types.d.ts +233 -30
  4. package/arc4/index.d.ts +87 -12
  5. package/arc4/index.mjs +2 -4
  6. package/arc4/index.mjs.map +1 -1
  7. package/base-contract.d.ts +17 -11
  8. package/box.d.ts +184 -15
  9. package/compiled.d.ts +3 -4
  10. package/errors-D124-zqo.js +12 -0
  11. package/errors-D124-zqo.js.map +1 -0
  12. package/gtxn-CXBH4yay.js +71 -0
  13. package/gtxn-CXBH4yay.js.map +1 -0
  14. package/gtxn.d.ts +608 -16
  15. package/gtxn.mjs +3 -0
  16. package/gtxn.mjs.map +1 -0
  17. package/index-C_qZ2M7-.js +512 -0
  18. package/index-C_qZ2M7-.js.map +1 -0
  19. package/index.d.ts +4 -4
  20. package/index.mjs +180 -150
  21. package/index.mjs.map +1 -1
  22. package/internal/errors.d.ts +7 -0
  23. package/{typescript-helpers.d.ts → internal/typescript-helpers.d.ts} +1 -0
  24. package/itxn-CPeSA_Q_.js +202 -0
  25. package/itxn-CPeSA_Q_.js.map +1 -0
  26. package/itxn.d.ts +1010 -72
  27. package/itxn.mjs +3 -0
  28. package/itxn.mjs.map +1 -0
  29. package/logic-sig.d.ts +28 -1
  30. package/mutable-array.d.ts +10 -17
  31. package/on-complete-action.d.ts +33 -0
  32. package/{op-types.d.ts → op-BgdftarW.js} +1706 -697
  33. package/op-BgdftarW.js.map +1 -0
  34. package/op.d.ts +2621 -67
  35. package/op.mjs +2 -1
  36. package/op.mjs.map +1 -1
  37. package/package.json +13 -2
  38. package/primitives.d.ts +88 -0
  39. package/reference.d.ts +34 -1
  40. package/state.d.ts +67 -10
  41. package/template-var.d.ts +7 -0
  42. package/transactions.d.ts +0 -313
  43. package/util.d.ts +100 -3
  44. package/execution-context.d.ts +0 -47
  45. package/impl/base-32.d.ts +0 -2
  46. package/impl/encoding-util.d.ts +0 -10
  47. package/impl/errors.d.ts +0 -36
  48. package/impl/name-of-type.d.ts +0 -1
  49. package/impl/primitives.d.ts +0 -82
  50. package/index-ki5AN0aM.js +0 -924
  51. package/index-ki5AN0aM.js.map +0 -1
  52. package/internal.d.ts +0 -6
  53. package/op-Mj11EGRt.js +0 -170
  54. package/op-Mj11EGRt.js.map +0 -1
package/arc-28.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { DeliberateAny } from './typescript-helpers';
1
+ import { DeliberateAny } from './internal/typescript-helpers';
2
2
  /**
3
3
  * Emit an arc28 event log using either an ARC4Struct type or a named object type.
4
4
  * Object types must have an ARC4 equivalent type.
package/arc4/c2c.d.ts ADDED
@@ -0,0 +1,81 @@
1
+ import { CompileContractOptions, CompiledContract } from '../compiled';
2
+ import * as gtxn from '../gtxn';
3
+ import { AnyFunction, ConstructorFor, DeliberateAny, InstanceMethod } from '../internal/typescript-helpers';
4
+ import * as itxn from '../itxn';
5
+ import { ApplicationCallFields, ApplicationCallInnerTxn } from '../itxn';
6
+ import { Contract } from './index';
7
+ /**
8
+ * Defines txn fields that are available for a bare create application call.
9
+ *
10
+ * This is the regular application call fields minus:
11
+ * - appId: because the appId is not known when creating an application
12
+ * - appArgs: because a bare call cannot have arguments
13
+ */
14
+ export type BareCreateApplicationCallFields = Omit<ApplicationCallFields, 'appId' | 'appArgs'>;
15
+ /**
16
+ * Conditional type which given a group transaction type, returns the equivalent inner transaction
17
+ * params type.
18
+ */
19
+ export type GtxnToItxnFields<T extends gtxn.Transaction> = T extends gtxn.PaymentTxn ? itxn.PaymentItxnParams : T extends gtxn.KeyRegistrationTxn ? itxn.KeyRegistrationItxnParams : T extends gtxn.AssetConfigTxn ? itxn.AssetConfigItxnParams : T extends gtxn.AssetTransferTxn ? itxn.AssetTransferItxnParams : T extends gtxn.AssetFreezeTxn ? itxn.AssetFreezeItxnParams : T extends gtxn.ApplicationCallTxn ? itxn.ApplicationCallItxnParams : itxn.ItxnParams;
20
+ /**
21
+ * Conditional type which given an application argument, returns the input type for that argument.
22
+ *
23
+ * The input type will usually be the original type apart from group transactions which will be substituted
24
+ * with their equivalent inner transaction type.
25
+ */
26
+ export type TypedApplicationArg<TArg> = TArg extends gtxn.Transaction ? GtxnToItxnFields<TArg> : TArg;
27
+ /**
28
+ * Conditional type which maps a tuple of application arguments to a tuple of input types for specifying those arguments.
29
+ */
30
+ export type TypedApplicationArgs<TArgs> = TArgs extends [] ? [] : TArgs extends [infer TArg, ...infer TRest] ? [TypedApplicationArg<TArg>, ...TypedApplicationArgs<TRest>] : never;
31
+ /**
32
+ * Application call fields with `appArgs` replaced with an `args` property that is strongly typed to the actual arguments for the
33
+ * given application call.
34
+ */
35
+ export type TypedApplicationCallFields<TArgs> = Omit<ApplicationCallFields, 'appArgs'> & (TArgs extends [] ? {
36
+ args?: TypedApplicationArgs<TArgs>;
37
+ } : {
38
+ args: TypedApplicationArgs<TArgs>;
39
+ });
40
+ /**
41
+ * The response type of a typed application call. Includes the raw itxn result object and the parsed ABI return value if applicable.
42
+ */
43
+ export type TypedApplicationCallResponse<TReturn> = TReturn extends void ? {
44
+ itxn: ApplicationCallInnerTxn;
45
+ } : {
46
+ itxn: ApplicationCallInnerTxn;
47
+ returnValue: TReturn;
48
+ };
49
+ /**
50
+ * Conditional type which maps an ABI method to a factory method for constructing an application call transaction to call that method.
51
+ */
52
+ export type ContractProxyMethod<TMethod> = TMethod extends (...args: infer TArgs) => infer TReturn ? (fields?: TypedApplicationCallFields<TArgs>) => TypedApplicationCallResponse<TReturn> : never;
53
+ /**
54
+ * Conditional type which maps an ARC4 compatible contract to a proxy object which allows for constructing application call transactions for
55
+ * all available ABI and bare methods. Also includes the compiled contract result data.
56
+ */
57
+ export type ContractProxy<TContract extends Contract> = CompiledContract & {
58
+ /**
59
+ * Get methods for calling ABI and bare methods on the target contract
60
+ */
61
+ call: {
62
+ [key in keyof TContract as key extends 'approvalProgram' | 'clearStateProgram' ? never : TContract[key] extends AnyFunction ? key : never]: ContractProxyMethod<TContract[key]>;
63
+ };
64
+ /**
65
+ * Create a bare application call itxn to create the contract.
66
+ * @param fields Specify values for transaction fields which should override the default values.
67
+ */
68
+ bareCreate(fields?: BareCreateApplicationCallFields): ApplicationCallInnerTxn;
69
+ };
70
+ /**
71
+ * Pre compile the target ARC4 contract and return a proxy object for constructing inner transactions to call an instance of that contract.
72
+ * @param contract An ARC4 contract class
73
+ * @param options Compile contract arguments
74
+ */
75
+ export declare function compileArc4<TContract extends Contract>(contract: ConstructorFor<TContract>, options?: CompileContractOptions): ContractProxy<TContract>;
76
+ /**
77
+ * Invokes the target ABI method using a strongly typed fields object.
78
+ * @param method An ABI method function reference.
79
+ * @param fields Specify values for transaction fields.
80
+ */
81
+ export declare function abiCall<TArgs extends DeliberateAny[], TReturn>(method: InstanceMethod<Contract, TArgs, TReturn>, fields: TypedApplicationCallFields<TArgs>): TypedApplicationCallResponse<TReturn>;
@@ -1,51 +1,143 @@
1
- import { biguint, BigUintCompat, bytes, BytesBacked, BytesCompat, StringCompat, uint64, Uint64Compat } from '../primitives';
1
+ import { biguint, BigUintCompat, bytes, BytesBacked, StringCompat, uint64, Uint64Compat } from '../primitives';
2
2
  import { Account } from '../reference';
3
+ /**
4
+ * Defines UintN bit sizes which are compatible with the uint64 type
5
+ */
3
6
  type UintBitSize = 8 | 16 | 24 | 32 | 40 | 48 | 56 | 64;
7
+ /**
8
+ * Defines UintN bit sizes which are only compatible with the biguint type
9
+ */
4
10
  type BigUintBitSize = 72 | 80 | 88 | 96 | 104 | 112 | 120 | 128 | 136 | 144 | 152 | 160 | 168 | 176 | 184 | 192 | 200 | 208 | 216 | 224 | 232 | 240 | 248 | 256 | 264 | 272 | 280 | 288 | 296 | 304 | 312 | 320 | 328 | 336 | 344 | 352 | 360 | 368 | 376 | 384 | 392 | 400 | 408 | 416 | 424 | 432 | 440 | 448 | 456 | 464 | 472 | 480 | 488 | 496 | 504 | 512;
11
+ /**
12
+ * Defines supported bit sizes for the UintN and UFixedNxM types
13
+ */
5
14
  export type BitSize = UintBitSize | BigUintBitSize;
15
+ /**
16
+ * Conditional type which returns the native equivalent type for a given UintN bit size
17
+ */
6
18
  type NativeForArc4Int<N extends BitSize> = N extends UintBitSize ? uint64 : biguint;
19
+ /**
20
+ * Conditional type which returns the compat type relevant to a given UintN bit size
21
+ */
7
22
  type CompatForArc4Int<N extends BitSize> = N extends UintBitSize ? Uint64Compat : BigUintCompat;
23
+ /**
24
+ * @hidden
25
+ */
8
26
  declare const TypeProperty: unique symbol;
27
+ /**
28
+ * A base type for ARC4 encoded values
29
+ */
9
30
  export declare abstract class ARC4Encoded implements BytesBacked {
31
+ /** @hidden */
10
32
  abstract [TypeProperty]?: string;
33
+ /**
34
+ * Retrieve the encoded bytes for this type
35
+ */
11
36
  get bytes(): bytes;
12
37
  }
38
+ /**
39
+ * A utf8 encoded string prefixed with its length expressed as a 2 byte uint
40
+ */
13
41
  export declare class Str extends ARC4Encoded {
14
- #private;
42
+ /** @hidden */
15
43
  [TypeProperty]?: 'arc4.Str';
44
+ /**
45
+ * Create a new Str instance
46
+ * @param s The native string to initialize this Str from
47
+ */
16
48
  constructor(s?: StringCompat);
49
+ /**
50
+ * Retrieve the decoded native string
51
+ */
17
52
  get native(): string;
18
53
  }
54
+ /**
55
+ * A fixed bit size unsigned int
56
+ */
19
57
  export declare class UintN<N extends BitSize> extends ARC4Encoded {
58
+ /** @hidden */
20
59
  [TypeProperty]?: `arc4.UintN<${N}>`;
60
+ /**
61
+ * Create a new UintN instance
62
+ * @param v The native uint64 or biguint value to initialize this UintN from
63
+ */
21
64
  constructor(v?: CompatForArc4Int<N>);
65
+ /**
66
+ * Retrieve the decoded native uint64 or biguint
67
+ */
22
68
  get native(): NativeForArc4Int<N>;
23
69
  }
70
+ /**
71
+ * An alias for UintN<8>
72
+ */
24
73
  export declare class Byte extends UintN<8> {
25
74
  }
75
+ /**
76
+ * An alias for UintN<8>
77
+ */
26
78
  export declare class UintN8 extends UintN<8> {
27
79
  }
80
+ /**
81
+ * An alias for UintN<16>
82
+ */
28
83
  export declare class UintN16 extends UintN<16> {
29
84
  }
85
+ /**
86
+ * An alias for UintN<32>
87
+ */
30
88
  export declare class UintN32 extends UintN<32> {
31
89
  }
90
+ /**
91
+ * An alias for UintN<64>
92
+ */
32
93
  export declare class UintN64 extends UintN<64> {
33
94
  }
95
+ /**
96
+ * An alias for UintN<128>
97
+ */
34
98
  export declare class UintN128 extends UintN<128> {
35
99
  }
100
+ /**
101
+ * An alias for UintN<256>
102
+ */
36
103
  export declare class UintN256 extends UintN<256> {
37
104
  }
105
+ /**
106
+ * A fixed bit size, fixed decimal unsigned value
107
+ */
38
108
  export declare class UFixedNxM<N extends BitSize, M extends number> extends ARC4Encoded {
109
+ /** @hidden */
39
110
  [TypeProperty]?: `arc4.UFixedNxM<${N}x${M}>`;
40
- constructor(v: `${number}.${number}`);
111
+ /**
112
+ * Create a new UFixedNxM value
113
+ * @param v A string representing the integer and fractional portion of the number
114
+ */
115
+ constructor(v?: `${number}.${number}`);
116
+ /**
117
+ * Retrieve the decoded native uint64 or biguint where the returned integer represents the fixed decimal value * (10 ^ M)
118
+ */
41
119
  get native(): NativeForArc4Int<N>;
42
120
  }
121
+ /**
122
+ * A boolean value
123
+ */
43
124
  export declare class Bool extends ARC4Encoded {
125
+ /** @hidden */
44
126
  [TypeProperty]?: `arc4.Bool`;
127
+ /**
128
+ * Create a new Bool value
129
+ * @param v The native boolean to initialize this value from
130
+ */
45
131
  constructor(v?: boolean);
132
+ /**
133
+ * Get the decoded native boolean for this value
134
+ */
46
135
  get native(): boolean;
47
136
  }
48
- declare abstract class Arc4ReadonlyArray<TItem extends ARC4Encoded> extends ARC4Encoded {
137
+ /**
138
+ * A base type for arc4 array types
139
+ */
140
+ declare abstract class Arc4ArrayBase<TItem extends ARC4Encoded> extends ARC4Encoded {
49
141
  protected constructor();
50
142
  /**
51
143
  * Returns the current length of this array
@@ -75,17 +167,46 @@ declare abstract class Arc4ReadonlyArray<TItem extends ARC4Encoded> extends ARC4
75
167
  */
76
168
  [index: uint64]: TItem;
77
169
  }
78
- export declare class StaticArray<TItem extends ARC4Encoded, TLength extends number> extends Arc4ReadonlyArray<TItem> {
170
+ /**
171
+ * A fixed sized array of arc4 items
172
+ * @typeParam TItem The type of a single item in the array
173
+ * @typeParam TLength The fixed length of the array
174
+ */
175
+ export declare class StaticArray<TItem extends ARC4Encoded, TLength extends number> extends Arc4ArrayBase<TItem> {
176
+ /** @hidden */
79
177
  [TypeProperty]?: `arc4.StaticArray<${TItem[typeof TypeProperty]}, ${TLength}>`;
178
+ /**
179
+ * Create a new StaticArray instance
180
+ */
80
181
  constructor();
182
+ /**
183
+ * Create a new StaticArray instance with the specified items
184
+ * @param items The initial items for the array
185
+ */
81
186
  constructor(...items: TItem[] & {
82
187
  length: TLength;
83
188
  });
84
- constructor(...items: TItem[]);
189
+ /**
190
+ * Returns a copy of this array
191
+ */
85
192
  copy(): StaticArray<TItem, TLength>;
193
+ /**
194
+ * Returns a new array containing all items from _this_ array, and _other_ array
195
+ * @param other Another array to concat with this one
196
+ */
197
+ concat(other: Arc4ArrayBase<TItem>): DynamicArray<TItem>;
86
198
  }
87
- export declare class DynamicArray<TItem extends ARC4Encoded> extends Arc4ReadonlyArray<TItem> {
199
+ /**
200
+ * A dynamic sized array of arc4 items
201
+ * @typeParam TItem The type of a single item in the array
202
+ */
203
+ export declare class DynamicArray<TItem extends ARC4Encoded> extends Arc4ArrayBase<TItem> {
204
+ /** @hidden */
88
205
  [TypeProperty]?: `arc4.DynamicArray<${TItem[typeof TypeProperty]}>`;
206
+ /**
207
+ * Create a new DynamicArray with the specified items
208
+ * @param items The initial items for the array
209
+ */
89
210
  constructor(...items: TItem[]);
90
211
  /**
91
212
  * Push a number of items into this array
@@ -96,52 +217,134 @@ export declare class DynamicArray<TItem extends ARC4Encoded> extends Arc4Readonl
96
217
  * Pop a single item from this array
97
218
  */
98
219
  pop(): TItem;
220
+ /**
221
+ * Returns a copy of this array
222
+ */
99
223
  copy(): DynamicArray<TItem>;
224
+ /**
225
+ * Returns a new array containing all items from _this_ array, and _other_ array
226
+ * @param other Another array to concat with this one
227
+ */
228
+ concat(other: Arc4ArrayBase<TItem>): DynamicArray<TItem>;
100
229
  }
230
+ /**
231
+ * @hidden
232
+ */
101
233
  type ExpandTupleType<T extends ARC4Encoded[]> = T extends [infer T1 extends ARC4Encoded, ...infer TRest extends ARC4Encoded[]] ? TRest extends [] ? `${T1[typeof TypeProperty]}` : `${T1[typeof TypeProperty]},${ExpandTupleType<TRest>}` : '';
234
+ /**
235
+ * An arc4 encoded tuple of values
236
+ * @typeParam TTuple A type representing the native tuple of item types
237
+ */
102
238
  export declare class Tuple<TTuple extends [ARC4Encoded, ...ARC4Encoded[]]> extends ARC4Encoded {
239
+ /** @hidden */
103
240
  [TypeProperty]?: `arc4.Tuple<${ExpandTupleType<TTuple>}>`;
241
+ /**
242
+ * Create a new Tuple with the default zero values for items
243
+ */
244
+ constructor();
245
+ /**
246
+ * Create a new Tuple with the specified items
247
+ * @param items The tuple items
248
+ */
104
249
  constructor(...items: TTuple);
250
+ /**
251
+ * Returns the item at the specified index
252
+ * @param index The index of the item to get. Must be a positive literal representing a tuple index
253
+ */
105
254
  at<TIndex extends keyof TTuple>(index: TIndex): TTuple[TIndex];
255
+ /**
256
+ * Returns the length of this tuple
257
+ */
106
258
  get length(): TTuple['length'] & uint64;
259
+ /**
260
+ * Returns the decoded native tuple (with arc4 encoded items)
261
+ */
107
262
  get native(): TTuple;
108
263
  }
109
- export declare class Address extends Arc4ReadonlyArray<Byte> {
264
+ /**
265
+ * A 32 byte Algorand Address
266
+ */
267
+ export declare class Address extends Arc4ArrayBase<Byte> {
268
+ /** @hidden */
110
269
  [TypeProperty]?: `arc4.Address`;
270
+ /**
271
+ * Create a new Address instance
272
+ * @param value An Account, base 32 address string, or the address bytes
273
+ */
111
274
  constructor(value?: Account | string | bytes);
275
+ /**
276
+ * Returns an Account instance for this Address
277
+ */
112
278
  get native(): Account;
113
279
  }
114
- type StructConstraint = Record<string, ARC4Encoded>;
115
- declare class StructBase extends ARC4Encoded {
280
+ /**
281
+ * The base type for arc4 structs
282
+ */
283
+ declare class StructBase<T> extends ARC4Encoded {
284
+ /** @hidden */
116
285
  [TypeProperty]: string;
286
+ get native(): T;
287
+ /**
288
+ * Returns a deep copy of this struct
289
+ */
290
+ copy(): this;
117
291
  }
118
- type StructConstructor = new <T extends StructConstraint>(initial: T) => StructBase & T;
292
+ /**
293
+ * Type alias for the Struct constructor function
294
+ * @typeParam T The shape of the arc4 struct
295
+ */
296
+ type StructConstructor = {
297
+ new <T extends Record<string, ARC4Encoded>>(initial: T): StructBase<T> & T;
298
+ };
299
+ /**
300
+ * The base type of arc4 structs
301
+ *
302
+ * Usage:
303
+ * ```
304
+ * class MyStruct extends Struct<{ x: UintN8, y: Str, z: DynamicBytes }> {}
305
+ * ```
306
+ */
119
307
  export declare const Struct: StructConstructor;
120
- export declare class DynamicBytes extends Arc4ReadonlyArray<Byte> {
308
+ /**
309
+ * A variable length sequence of bytes prefixed with its length expressed as a 2 byte uint
310
+ */
311
+ export declare class DynamicBytes extends Arc4ArrayBase<Byte> {
312
+ /** @hidden */
121
313
  [TypeProperty]?: `arc4.DynamicBytes`;
314
+ /**
315
+ * Create a new DynamicBytes instance
316
+ * @param value The bytes or utf8 interpreted string to initialize this type
317
+ */
122
318
  constructor(value?: bytes | string);
319
+ /**
320
+ * Get the native bytes value (excludes the length prefix)
321
+ */
123
322
  get native(): bytes;
323
+ /**
324
+ * Returns a dynamic bytes object containing all bytes from _this_ and _other_
325
+ * @param other Another array of bytes to concat with this one
326
+ */
327
+ concat(other: Arc4ArrayBase<Byte>): DynamicBytes;
124
328
  }
125
- export declare class StaticBytes<TLength extends number = 0> extends Arc4ReadonlyArray<Byte> {
329
+ /**
330
+ * A fixed length sequence of bytes
331
+ */
332
+ export declare class StaticBytes<TLength extends number = 0> extends Arc4ArrayBase<Byte> {
333
+ /** @hidden */
126
334
  [TypeProperty]?: `arc4.StaticBytes<${TLength}>`;
335
+ /**
336
+ * Create a new StaticBytes instance
337
+ * @param value THe bytes or utf8 interpreted string to initialize this type
338
+ */
127
339
  constructor(value?: bytes | string);
340
+ /**
341
+ * Get the native bytes value
342
+ */
128
343
  get native(): bytes;
344
+ /**
345
+ * Returns a dynamic bytes object containing all bytes from _this_ and _other_
346
+ * @param other Another array of bytes to concat with this one
347
+ */
348
+ concat(other: Arc4ArrayBase<Byte>): DynamicBytes;
129
349
  }
130
- /**
131
- * Interpret the provided bytes as an ARC4 encoded type with no validation
132
- * @param bytes An arc4 encoded bytes value
133
- * @param prefix The prefix (if any), present in the bytes value. This prefix will be validated and removed
134
- */
135
- export declare function interpretAsArc4<T extends ARC4Encoded>(bytes: BytesCompat, prefix?: 'none' | 'log'): T;
136
- /**
137
- * Decode the provided bytes to a native Algorand TypeScript value
138
- * @param bytes An arc4 encoded bytes value
139
- * @param prefix The prefix (if any), present in the bytes value. This prefix will be validated and removed
140
- */
141
- export declare function decodeArc4<T>(bytes: BytesCompat, prefix?: 'none' | 'log'): T;
142
- /**
143
- * Encode the provided Algorand TypeScript value as ARC4 bytes
144
- * @param value Any native Algorand TypeScript value with a supported ARC4 encoding
145
- */
146
- export declare function encodeArc4<T>(value: T): bytes;
147
350
  export {};
package/arc4/index.d.ts CHANGED
@@ -1,25 +1,51 @@
1
1
  import { BaseContract } from '../base-contract';
2
- import { bytes } from '../primitives';
3
- import { DeliberateAny } from '../typescript-helpers';
2
+ import { DeliberateAny, InstanceMethod } from '../internal/typescript-helpers';
3
+ import { OnCompleteActionStr } from '../on-complete-action';
4
+ import { bytes, BytesCompat, uint64 } from '../primitives';
5
+ import { ARC4Encoded } from './encoded-types';
4
6
  export * from './encoded-types';
7
+ export * from './c2c';
8
+ /**
9
+ * The base type for all ARC4 contracts in Algorand TypeScript
10
+ */
5
11
  export declare class Contract extends BaseContract {
12
+ /**
13
+ * Default implementation of an ARC4 approval program, routes transactions to ABI or bare methods based on application
14
+ * args and on completion actions
15
+ */
6
16
  approvalProgram(): boolean;
7
17
  }
18
+ /**
19
+ * The possible options for a method being available on application create
20
+ *
21
+ * allow: This method CAN be called when the application is being created, but it is not required
22
+ * disallow: This method CANNOT be called when the application is being created
23
+ * require: This method CAN ONLY be called when the application is being created
24
+ */
8
25
  export type CreateOptions = 'allow' | 'disallow' | 'require';
9
- export type OnCompleteActionStr = 'NoOp' | 'OptIn' | 'ClearState' | 'CloseOut' | 'UpdateApplication' | 'DeleteApplication';
10
- export declare enum OnCompleteAction {
11
- NoOp,
12
- OptIn,
13
- CloseOut,
14
- ClearState,
15
- UpdateApplication,
16
- DeleteApplication
17
- }
26
+ /**
27
+ * Type alias for a default argument schema
28
+ * @typeParam TContract The type of the contract containing the method this default argument is for
29
+ */
18
30
  export type DefaultArgument<TContract extends Contract> = {
31
+ /**
32
+ * A compile time constant value to be used as a default
33
+ */
19
34
  constant: string | boolean | number | bigint;
20
35
  } | {
36
+ /**
37
+ * Retrieve the default value from a member of this contract. The member can be
38
+ *
39
+ * LocalState: The value is retrieved from the calling user's local state before invoking this method
40
+ * GlobalState: The value is retrieved from the specified global state key before invoking this method
41
+ * Method: Any readonly abimethod with no arguments can be used as a source
42
+ */
21
43
  from: keyof TContract;
22
44
  };
45
+ /**
46
+ * Configuration options for an abi method
47
+ * @typeParam TContract the type of the contract this method is a part of
48
+ */
23
49
  export type AbiMethodConfig<TContract extends Contract> = {
24
50
  /**
25
51
  * Which on complete action(s) are allowed when invoking this method.
@@ -40,9 +66,22 @@ export type AbiMethodConfig<TContract extends Contract> = {
40
66
  * Override the name used to generate the abi method selector
41
67
  */
42
68
  name?: string;
69
+ /**
70
+ * Specify default arguments that can be populated by clients calling this method.
71
+ *
72
+ * A map of parameter names to the default argument source
73
+ */
43
74
  defaultArguments?: Record<string, DefaultArgument<TContract>>;
44
75
  };
76
+ /**
77
+ * Declares the decorated method as an abimethod that is called when the first transaction arg matches the method selector
78
+ * @param config The config for this abi method
79
+ * @typeParam TContract the type of the contract this method is a part of
80
+ */
45
81
  export declare function abimethod<TContract extends Contract>(config?: AbiMethodConfig<TContract>): <TArgs extends DeliberateAny[], TReturn>(target: (this: TContract, ...args: TArgs) => TReturn, ctx: ClassMethodDecoratorContext<TContract>) => (this: TContract, ...args: TArgs) => TReturn;
82
+ /**
83
+ * Configuration options for a bare method
84
+ */
46
85
  export type BareMethodConfig = {
47
86
  /**
48
87
  * Which on complete action(s) are allowed when invoking this method.
@@ -55,11 +94,47 @@ export type BareMethodConfig = {
55
94
  */
56
95
  onCreate?: CreateOptions;
57
96
  };
97
+ /**
98
+ * Declares the decorated method as a baremethod that can only be called with no transaction args
99
+ * @param config The config for this bare method
100
+ * @typeParam TContract the type of the contract this method is a part of
101
+ */
58
102
  export declare function baremethod<TContract extends Contract>(config?: BareMethodConfig): <TArgs extends DeliberateAny[], TReturn>(target: (this: TContract, ...args: TArgs) => TReturn, ctx: ClassMethodDecoratorContext<TContract>) => (this: TContract, ...args: TArgs) => TReturn;
59
103
  /**
60
104
  * Returns the ARC4 method selector for a given ARC4 method signature. The method selector is the first
61
105
  * 4 bytes of the SHA512/256 hash of the method signature.
62
- * @param methodSignature An ARC4 method signature. Eg. `hello(string)string`. Must be a compile time constant.
106
+ * @param methodSignature An ARC4 contract method reference. (Eg. `MyContract.prototype.myMethod`)
107
+ * @returns The ARC4 method selector. Eg. `02BECE11`
108
+ */
109
+ export declare function methodSelector(methodSignature: InstanceMethod<Contract>): bytes;
110
+ /**
111
+ * Returns the ARC4 method selector for a given ARC4 method signature. The method selector is the first
112
+ * 4 bytes of the SHA512/256 hash of the method signature.
113
+ * @param methodSignature An ARC4 method signature string (Eg. `hello(string)string`. Must be a compile time constant)
63
114
  * @returns The ARC4 method selector. Eg. `02BECE11`
64
115
  */
65
116
  export declare function methodSelector(methodSignature: string): bytes;
117
+ /**
118
+ * Interpret the provided bytes as an ARC4 encoded type with no validation
119
+ * @param bytes An arc4 encoded bytes value
120
+ * @param prefix The prefix (if any), present in the bytes value. This prefix will be validated and removed
121
+ */
122
+ export declare function interpretAsArc4<T extends ARC4Encoded>(bytes: BytesCompat, prefix?: 'none' | 'log'): T;
123
+ /**
124
+ * Decode the provided bytes to a native Algorand TypeScript value
125
+ * @param bytes An arc4 encoded bytes value
126
+ * @param prefix The prefix (if any), present in the bytes value. This prefix will be validated and removed
127
+ */
128
+ export declare function decodeArc4<T>(bytes: BytesCompat, prefix?: 'none' | 'log'): T;
129
+ /**
130
+ * Encode the provided Algorand TypeScript value as ARC4 bytes
131
+ * @param value Any native Algorand TypeScript value with a supported ARC4 encoding
132
+ */
133
+ export declare function encodeArc4<const T>(value: T): bytes;
134
+ /**
135
+ * Return the total number of bytes required to store T as ARC4 bytes.
136
+ *
137
+ * T must represent a type with a fixed length encoding scheme.
138
+ * @typeParam T Any native or arc4 type with a fixed encoding size.
139
+ */
140
+ export declare function arc4EncodedLength<T>(): uint64;
package/arc4/index.mjs CHANGED
@@ -1,5 +1,3 @@
1
- export { d as ARC4Encoded, I as Address, F as Bool, u as Byte, h as Contract, H as DynamicArray, K as DynamicBytes, O as OnCompleteAction, G as StaticArray, L as StaticBytes, S as Str, J as Struct, T as Tuple, E as UFixedNxM, t as UintN, z as UintN128, w as UintN16, D as UintN256, x as UintN32, y as UintN64, v as UintN8, j as abimethod, r as baremethod, P as decodeArc4, Q as encodeArc4, M as interpretAsArc4, s as methodSelector } from '../index-ki5AN0aM.js';
2
- import '../op-Mj11EGRt.js';
3
- import 'node:buffer';
4
- import 'node:util';
1
+ export { A as ARC4Encoded, t as Address, r as Bool, h as Byte, C as Contract, D as DynamicArray, v as DynamicBytes, s as StaticArray, w as StaticBytes, S as Str, u as Struct, T as Tuple, q as UFixedNxM, U as UintN, o as UintN128, k as UintN16, p as UintN256, l as UintN32, n as UintN64, j as UintN8, y as abiCall, a as abimethod, g as arc4EncodedLength, b as baremethod, x as compileArc4, e as decodeArc4, f as encodeArc4, d as interpretAsArc4, m as methodSelector } from '../index-C_qZ2M7-.js';
2
+ import '../errors-D124-zqo.js';
5
3
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
@@ -1,14 +1,19 @@
1
- import { Contract } from './arc4';
1
+ import { ConstructorFor } from './internal/typescript-helpers';
2
2
  import { uint64 } from './primitives';
3
- import { ConstructorFor } from './typescript-helpers';
3
+ import { NumberRange } from './util';
4
+ /**
5
+ * The base type for all Algorand TypeScript contracts
6
+ */
4
7
  export declare abstract class BaseContract {
8
+ /**
9
+ * The program to be run when the On Completion Action is != ClearState (3)
10
+ */
5
11
  abstract approvalProgram(): boolean | uint64;
12
+ /**
13
+ * The program to be run when the On Completion Action is == ClearState (3)
14
+ */
6
15
  clearStateProgram(): boolean | uint64;
7
16
  }
8
- type NumberRange = {
9
- from: number;
10
- to: number;
11
- };
12
17
  /**
13
18
  * Options class to manually define the total amount of global and local state contract will use.
14
19
  *
@@ -17,13 +22,16 @@ type NumberRange = {
17
22
  * to reserve additional state storage for future contract updates, since the Algorand protocol
18
23
  * doesn't allow increasing them after creation.
19
24
  */
20
- type StateTotals = {
25
+ export type StateTotals = {
21
26
  globalUints?: number;
22
27
  globalBytes?: number;
23
28
  localUints?: number;
24
29
  localBytes?: number;
25
30
  };
26
- type ContractOptions = {
31
+ /**
32
+ * Additional configuration options for a contract
33
+ */
34
+ export type ContractOptions = {
27
35
  /**
28
36
  * Determines which AVM version to use, this affects what operations are supported.
29
37
  * Defaults to value provided supplied on command line (which defaults to current mainnet version)
@@ -66,6 +74,4 @@ type ContractOptions = {
66
74
  * The contract decorator can be used to specify additional configuration options for a smart contract
67
75
  * @param options An object containing the configuration options
68
76
  */
69
- export declare const ContractOptionsSymbol: unique symbol;
70
- export declare function contract(options: ContractOptions): <T extends ConstructorFor<Contract>>(contract: T, ctx: ClassDecoratorContext) => T;
71
- export {};
77
+ export declare function contract(options: ContractOptions): <T extends ConstructorFor<BaseContract>>(contract: T, ctx: ClassDecoratorContext) => never;