@algorandfoundation/algorand-typescript 1.0.0-beta.19 → 1.0.0-beta.20

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.
@@ -1,51 +1,143 @@
1
1
  import { biguint, BigUintCompat, bytes, BytesBacked, BytesCompat, 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}>`;
111
+ /**
112
+ * Create a new UFixedNxM value
113
+ * @param v A string representing the integer and fractional portion of the number
114
+ */
40
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,22 +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>;
86
193
  /**
87
194
  * Returns a new array containing all items from _this_ array, and _other_ array
88
195
  * @param other Another array to concat with this one
89
196
  */
90
- concat(other: Arc4ReadonlyArray<TItem>): DynamicArray<TItem>;
197
+ concat(other: Arc4ArrayBase<TItem>): DynamicArray<TItem>;
91
198
  }
92
- 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 */
93
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
+ */
94
210
  constructor(...items: TItem[]);
95
211
  /**
96
212
  * Push a number of items into this array
@@ -101,51 +217,127 @@ export declare class DynamicArray<TItem extends ARC4Encoded> extends Arc4Readonl
101
217
  * Pop a single item from this array
102
218
  */
103
219
  pop(): TItem;
220
+ /**
221
+ * Returns a copy of this array
222
+ */
104
223
  copy(): DynamicArray<TItem>;
105
224
  /**
106
225
  * Returns a new array containing all items from _this_ array, and _other_ array
107
226
  * @param other Another array to concat with this one
108
227
  */
109
- concat(other: Arc4ReadonlyArray<TItem>): DynamicArray<TItem>;
228
+ concat(other: Arc4ArrayBase<TItem>): DynamicArray<TItem>;
110
229
  }
230
+ /**
231
+ * @hidden
232
+ */
111
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
+ */
112
238
  export declare class Tuple<TTuple extends [ARC4Encoded, ...ARC4Encoded[]]> extends ARC4Encoded {
239
+ /** @hidden */
113
240
  [TypeProperty]?: `arc4.Tuple<${ExpandTupleType<TTuple>}>`;
241
+ /**
242
+ * Create a new Tuple with the specified items
243
+ * @param items The tuple items
244
+ */
114
245
  constructor(...items: TTuple);
246
+ /**
247
+ * Returns the item at the specified index
248
+ * @param index The index of the item to get. Must be a positive literal representing a tuple index
249
+ */
115
250
  at<TIndex extends keyof TTuple>(index: TIndex): TTuple[TIndex];
251
+ /**
252
+ * Returns the length of this tuple
253
+ */
116
254
  get length(): TTuple['length'] & uint64;
255
+ /**
256
+ * Returns the decoded native tuple (with arc4 encoded items)
257
+ */
117
258
  get native(): TTuple;
118
259
  }
119
- export declare class Address extends Arc4ReadonlyArray<Byte> {
260
+ /**
261
+ * A 32 byte Algorand Address
262
+ */
263
+ export declare class Address extends Arc4ArrayBase<Byte> {
264
+ /** @hidden */
120
265
  [TypeProperty]?: `arc4.Address`;
266
+ /**
267
+ * Create a new Address instance
268
+ * @param value An Account, base 32 address string, or the address bytes
269
+ */
121
270
  constructor(value?: Account | string | bytes);
271
+ /**
272
+ * Returns an Account instance for this Address
273
+ */
122
274
  get native(): Account;
123
275
  }
124
- type StructConstraint = Record<string, ARC4Encoded>;
125
- declare class StructBase extends ARC4Encoded {
276
+ /**
277
+ * The base type for arc4 structs
278
+ */
279
+ declare class StructBase<T> extends ARC4Encoded {
280
+ /** @hidden */
126
281
  [TypeProperty]: string;
282
+ get native(): T;
127
283
  }
128
- type StructConstructor = new <T extends StructConstraint>(initial: T) => StructBase & Readonly<T>;
284
+ /**
285
+ * Type alias for the Struct constructor function
286
+ * @typeParam T The shape of the arc4 struct
287
+ */
288
+ type StructConstructor = {
289
+ new <T extends Record<string, ARC4Encoded>>(initial: T): StructBase<T> & Readonly<T>;
290
+ };
291
+ /**
292
+ * The base type of arc4 structs
293
+ *
294
+ * Usage:
295
+ * ```
296
+ * class MyStruct extends Struct<{ x: UintN8, y: Str, z: DynamicBytes }> {}
297
+ * ```
298
+ */
129
299
  export declare const Struct: StructConstructor;
130
- export declare class DynamicBytes extends Arc4ReadonlyArray<Byte> {
300
+ /**
301
+ * A variable length sequence of bytes prefixed with its length expressed as a 2 byte uint
302
+ */
303
+ export declare class DynamicBytes extends Arc4ArrayBase<Byte> {
304
+ /** @hidden */
131
305
  [TypeProperty]?: `arc4.DynamicBytes`;
306
+ /**
307
+ * Create a new DynamicBytes instance
308
+ * @param value The bytes or utf8 interpreted string to initialize this type
309
+ */
132
310
  constructor(value?: bytes | string);
311
+ /**
312
+ * Get the native bytes value (excludes the length prefix)
313
+ */
133
314
  get native(): bytes;
134
315
  /**
135
316
  * Returns a dynamic bytes object containing all bytes from _this_ and _other_
136
317
  * @param other Another array of bytes to concat with this one
137
318
  */
138
- concat(other: Arc4ReadonlyArray<Byte>): DynamicBytes;
319
+ concat(other: Arc4ArrayBase<Byte>): DynamicBytes;
139
320
  }
140
- export declare class StaticBytes<TLength extends number = 0> extends Arc4ReadonlyArray<Byte> {
321
+ /**
322
+ * A fixed length sequence of bytes
323
+ */
324
+ export declare class StaticBytes<TLength extends number = 0> extends Arc4ArrayBase<Byte> {
325
+ /** @hidden */
141
326
  [TypeProperty]?: `arc4.StaticBytes<${TLength}>`;
327
+ /**
328
+ * Create a new StaticBytes instance
329
+ * @param value THe bytes or utf8 interpreted string to initialize this type
330
+ */
142
331
  constructor(value?: bytes | string);
332
+ /**
333
+ * Get the native bytes value
334
+ */
143
335
  get native(): bytes;
144
336
  /**
145
337
  * Returns a dynamic bytes object containing all bytes from _this_ and _other_
146
338
  * @param other Another array of bytes to concat with this one
147
339
  */
148
- concat(other: Arc4ReadonlyArray<Byte>): DynamicBytes;
340
+ concat(other: Arc4ArrayBase<Byte>): DynamicBytes;
149
341
  }
150
342
  /**
151
343
  * Interpret the provided bytes as an ARC4 encoded type with no validation
package/arc4/index.d.ts CHANGED
@@ -2,24 +2,80 @@ import { BaseContract } from '../base-contract';
2
2
  import { DeliberateAny } from '../internal/typescript-helpers';
3
3
  import { bytes } from '../primitives';
4
4
  export * from './encoded-types';
5
+ /**
6
+ * The base type for all ARC4 contracts in Algorand TypeScript
7
+ */
5
8
  export declare class Contract extends BaseContract {
9
+ /**
10
+ * Default implementation of an ARC4 approval program, routes transactions to ABI or bare methods based on application
11
+ * args and on completion actions
12
+ */
6
13
  approvalProgram(): boolean;
7
14
  }
15
+ /**
16
+ * The possible options for a method being available on application create
17
+ *
18
+ * allow: This method CAN be called when the application is being created, but it is not required
19
+ * disallow: This method CANNOT be called when the application is being created
20
+ * require: This method CAN ONLY be called when the application is being created
21
+ */
8
22
  export type CreateOptions = 'allow' | 'disallow' | 'require';
23
+ /**
24
+ * The possible on complete actions a method can handle, represented as a string
25
+ */
9
26
  export type OnCompleteActionStr = 'NoOp' | 'OptIn' | 'ClearState' | 'CloseOut' | 'UpdateApplication' | 'DeleteApplication';
27
+ /**
28
+ * The possible on complete actions a method can handle, represented as an integer
29
+ */
10
30
  export declare enum OnCompleteAction {
31
+ /**
32
+ * Do nothing after the transaction has completed
33
+ */
11
34
  NoOp = 0,
35
+ /**
36
+ * Opt the calling user into the contract
37
+ */
12
38
  OptIn = 1,
39
+ /**
40
+ * Close the calling user out of the contract
41
+ */
13
42
  CloseOut = 2,
43
+ /**
44
+ * Run the clear state program and forcibly close the user out of the contract
45
+ */
14
46
  ClearState = 3,
47
+ /**
48
+ * Replace the application's approval and clear state programs with the bytes from this transaction
49
+ */
15
50
  UpdateApplication = 4,
51
+ /**
52
+ * Delete the application
53
+ */
16
54
  DeleteApplication = 5
17
55
  }
56
+ /**
57
+ * Type alias for a default argument schema
58
+ * @typeParam TContract The type of the contract containing the method this default argument is for
59
+ */
18
60
  export type DefaultArgument<TContract extends Contract> = {
61
+ /**
62
+ * A compile time constant value to be used as a default
63
+ */
19
64
  constant: string | boolean | number | bigint;
20
65
  } | {
66
+ /**
67
+ * Retrieve the default value from a member of this contract. The member can be
68
+ *
69
+ * LocalState: The value is retrieved from the calling user's local state before invoking this method
70
+ * GlobalState: The value is retrieved from the specified global state key before invoking this method
71
+ * Method: Any readonly abimethod with no arguments can be used as a source
72
+ */
21
73
  from: keyof TContract;
22
74
  };
75
+ /**
76
+ * Configuration options for an abi method
77
+ * @typeParam TContract the type of the contract this method is a part of
78
+ */
23
79
  export type AbiMethodConfig<TContract extends Contract> = {
24
80
  /**
25
81
  * Which on complete action(s) are allowed when invoking this method.
@@ -40,13 +96,22 @@ export type AbiMethodConfig<TContract extends Contract> = {
40
96
  * Override the name used to generate the abi method selector
41
97
  */
42
98
  name?: string;
99
+ /**
100
+ * Specify default arguments that can be populated by clients calling this method.
101
+ *
102
+ * A map of parameter names to the default argument source
103
+ */
43
104
  defaultArguments?: Record<string, DefaultArgument<TContract>>;
44
105
  };
45
106
  /**
46
107
  * Declares the decorated method as an abimethod that is called when the first transaction arg matches the method selector
47
- * @param config
108
+ * @param config The config for this abi method
109
+ * @typeParam TContract the type of the contract this method is a part of
48
110
  */
49
111
  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;
112
+ /**
113
+ * Configuration options for a bare method
114
+ */
50
115
  export type BareMethodConfig = {
51
116
  /**
52
117
  * Which on complete action(s) are allowed when invoking this method.
@@ -61,13 +126,18 @@ export type BareMethodConfig = {
61
126
  };
62
127
  /**
63
128
  * Declares the decorated method as a baremethod that can only be called with no transaction args
64
- * @param config
129
+ * @param config The config for this bare method
130
+ * @typeParam TContract the type of the contract this method is a part of
65
131
  */
66
132
  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;
133
+ /**
134
+ * A type alias for a contract instance method
135
+ */
136
+ type ContractMethod = (this: Contract, ...args: DeliberateAny[]) => DeliberateAny;
67
137
  /**
68
138
  * Returns the ARC4 method selector for a given ARC4 method signature. The method selector is the first
69
139
  * 4 bytes of the SHA512/256 hash of the method signature.
70
- * @param methodSignature An ARC4 method signature. Eg. `hello(string)string`. Must be a compile time constant.
140
+ * @param methodSignature An ARC4 method signature string ( Eg. `hello(string)string`. Must be a compile time constant), or a contract method reference. (Eg. `MyContract.prototype.myMethod`)
71
141
  * @returns The ARC4 method selector. Eg. `02BECE11`
72
142
  */
73
- export declare function methodSelector<TMethod extends (this: TContract, ...args: TArgs) => TReturn, TContract extends Contract, TArgs extends DeliberateAny[], TReturn>(methodSignature: string | TMethod): bytes;
143
+ export declare function methodSelector(methodSignature: string | ContractMethod): bytes;
package/arc4/index.mjs CHANGED
@@ -1,3 +1,3 @@
1
- export { A as ARC4Encoded, p as Address, n as Bool, d as Byte, C as Contract, D as DynamicArray, r as DynamicBytes, O as OnCompleteAction, o as StaticArray, s as StaticBytes, S as Str, q as Struct, T as Tuple, l as UFixedNxM, U as UintN, j as UintN128, f as UintN16, k as UintN256, g as UintN32, h as UintN64, e as UintN8, a as abimethod, b as baremethod, u as decodeArc4, v as encodeArc4, t as interpretAsArc4, m as methodSelector } from '../index-DLHfNF70.js';
1
+ export { A as ARC4Encoded, p as Address, n as Bool, d as Byte, C as Contract, D as DynamicArray, r as DynamicBytes, O as OnCompleteAction, o as StaticArray, s as StaticBytes, S as Str, q as Struct, T as Tuple, l as UFixedNxM, U as UintN, j as UintN128, f as UintN16, k as UintN256, g as UintN32, h as UintN64, e as UintN8, a as abimethod, b as baremethod, u as decodeArc4, v as encodeArc4, t as interpretAsArc4, m as methodSelector } from '../index-BPETuMat.js';
2
2
  import '../errors-D124-zqo.js';
3
3
  //# sourceMappingURL=index.mjs.map
@@ -1,8 +1,17 @@
1
1
  import { ConstructorFor } from './internal/typescript-helpers';
2
2
  import { uint64 } from './primitives';
3
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
17
  /**
@@ -19,6 +28,9 @@ export type StateTotals = {
19
28
  localUints?: number;
20
29
  localBytes?: number;
21
30
  };
31
+ /**
32
+ * Additional configuration options for a contract
33
+ */
22
34
  export type ContractOptions = {
23
35
  /**
24
36
  * Determines which AVM version to use, this affects what operations are supported.