@algorandfoundation/algorand-typescript 0.0.1-alpha.1
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.
- package/arc4/encoded-types.d.ts +65 -0
- package/arc4/index.d.ts +57 -0
- package/base-contract.d.ts +5 -0
- package/box.d.ts +52 -0
- package/execution-context.d.ts +40 -0
- package/gtxn.d.ts +30 -0
- package/impl/base-32.d.ts +2 -0
- package/impl/encoding-util.d.ts +8 -0
- package/impl/errors.d.ts +28 -0
- package/impl/name-of-type.d.ts +1 -0
- package/impl/primitives.d.ts +77 -0
- package/impl/state.d.ts +24 -0
- package/index-7MfWJL4Q.js +741 -0
- package/index-7MfWJL4Q.js.map +1 -0
- package/index.d.ts +14 -0
- package/index.mjs +364 -0
- package/index.mjs.map +1 -0
- package/index2.mjs +3 -0
- package/index2.mjs.map +1 -0
- package/internal.d.ts +6 -0
- package/itxn.d.ts +161 -0
- package/op-types.d.ts +2102 -0
- package/op.d.ts +55 -0
- package/package.json +32 -0
- package/primitives.d.ts +55 -0
- package/reference.d.ts +207 -0
- package/state.d.ts +28 -0
- package/transactions.d.ts +342 -0
- package/typescript-helpers.d.ts +2 -0
- package/util.d.ts +31 -0
@@ -0,0 +1,741 @@
|
|
1
|
+
import { TextDecoder } from 'node:util';
|
2
|
+
|
3
|
+
const BASE32_ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567'.split('');
|
4
|
+
const CHAR_TO_NUM = BASE32_ALPHABET.reduce((acc, cur, index) => ((acc[cur] = index), acc), {});
|
5
|
+
const base32ToUint8Array = (value) => {
|
6
|
+
let allChars = value
|
7
|
+
.split('')
|
8
|
+
.filter((c) => c !== '=')
|
9
|
+
.map((c) => {
|
10
|
+
const cUpper = c.toUpperCase();
|
11
|
+
if (cUpper in CHAR_TO_NUM)
|
12
|
+
return CHAR_TO_NUM[cUpper];
|
13
|
+
throw new Error(`Invalid base32 char ${c}`);
|
14
|
+
});
|
15
|
+
const bytes = new Array();
|
16
|
+
while (allChars.length) {
|
17
|
+
const [a, b, c, d, e, f, g, h, ...rest] = allChars;
|
18
|
+
if (a === undefined || b === undefined)
|
19
|
+
break;
|
20
|
+
bytes.push(((a << 3) | (b >>> 2)) & 255);
|
21
|
+
if (c === undefined || d === undefined)
|
22
|
+
break;
|
23
|
+
bytes.push(((b << 6) | (c << 1) | (d >>> 4)) & 255);
|
24
|
+
if (e === undefined)
|
25
|
+
break;
|
26
|
+
bytes.push(((d << 4) | (e >>> 1)) & 255);
|
27
|
+
if (f === undefined || g === undefined)
|
28
|
+
break;
|
29
|
+
bytes.push(((e << 7) | (f << 2) | (g >>> 3)) & 255);
|
30
|
+
if (h === undefined)
|
31
|
+
break;
|
32
|
+
bytes.push(((g << 5) | h) & 255);
|
33
|
+
allChars = rest;
|
34
|
+
}
|
35
|
+
return new Uint8Array(bytes);
|
36
|
+
};
|
37
|
+
const uint8ArrayToBase32 = (value) => {
|
38
|
+
let allBytes = Array.from(value);
|
39
|
+
let base32str = '';
|
40
|
+
while (allBytes.length) {
|
41
|
+
const [a, b, c, d, e, ...rest] = allBytes ?? [0, 0, 0, 0, 0];
|
42
|
+
if (allBytes.length < 1)
|
43
|
+
break;
|
44
|
+
base32str += BASE32_ALPHABET[a >>> 3];
|
45
|
+
base32str += BASE32_ALPHABET[((a << 2) | ((b || 0) >>> 6)) & 32];
|
46
|
+
if (allBytes.length < 2)
|
47
|
+
break;
|
48
|
+
base32str += BASE32_ALPHABET[(b >>> 1) & 31];
|
49
|
+
base32str += BASE32_ALPHABET[((b << 4) | (c >>> 4)) & 31];
|
50
|
+
if (allBytes.length < 3)
|
51
|
+
break;
|
52
|
+
base32str += BASE32_ALPHABET[((c << 1) | (d >>> 7)) & 31];
|
53
|
+
if (allBytes.length < 4)
|
54
|
+
break;
|
55
|
+
base32str += BASE32_ALPHABET[(d >>> 2) & 31];
|
56
|
+
base32str += BASE32_ALPHABET[((d << 3) | (e >>> 5)) & 31];
|
57
|
+
if (allBytes.length < 5)
|
58
|
+
break;
|
59
|
+
base32str += BASE32_ALPHABET[e & 31];
|
60
|
+
allBytes = rest;
|
61
|
+
}
|
62
|
+
return base32str;
|
63
|
+
};
|
64
|
+
|
65
|
+
/**
|
66
|
+
* Raised when an `err` op is encountered, or when the testing VM is asked to do something that would cause
|
67
|
+
* the AVM to fail.
|
68
|
+
*/
|
69
|
+
class AvmError extends Error {
|
70
|
+
constructor(message) {
|
71
|
+
super(message);
|
72
|
+
}
|
73
|
+
}
|
74
|
+
function avmError(message) {
|
75
|
+
throw new AvmError(message);
|
76
|
+
}
|
77
|
+
/**
|
78
|
+
* Raised when an assertion fails
|
79
|
+
*/
|
80
|
+
class AssertError extends AvmError {
|
81
|
+
constructor(message) {
|
82
|
+
super(message);
|
83
|
+
}
|
84
|
+
}
|
85
|
+
/**
|
86
|
+
* Raised when testing code errors
|
87
|
+
*/
|
88
|
+
class InternalError extends Error {
|
89
|
+
constructor(message, options) {
|
90
|
+
super(message, options);
|
91
|
+
}
|
92
|
+
}
|
93
|
+
function internalError(message) {
|
94
|
+
throw new InternalError(message);
|
95
|
+
}
|
96
|
+
/**
|
97
|
+
* Raised when unsupported user code is encountered
|
98
|
+
*/
|
99
|
+
class CodeError extends Error {
|
100
|
+
constructor(message, options) {
|
101
|
+
super(message, options);
|
102
|
+
}
|
103
|
+
}
|
104
|
+
function codeError(message) {
|
105
|
+
throw new CodeError(message);
|
106
|
+
}
|
107
|
+
|
108
|
+
var errors = /*#__PURE__*/Object.freeze({
|
109
|
+
__proto__: null,
|
110
|
+
AssertError: AssertError,
|
111
|
+
AvmError: AvmError,
|
112
|
+
CodeError: CodeError,
|
113
|
+
InternalError: InternalError,
|
114
|
+
avmError: avmError,
|
115
|
+
codeError: codeError,
|
116
|
+
internalError: internalError
|
117
|
+
});
|
118
|
+
|
119
|
+
const uint8ArrayToBigInt = (v) => {
|
120
|
+
// Assume big-endian
|
121
|
+
return Array.from(v)
|
122
|
+
.toReversed()
|
123
|
+
.map((byte_value, i) => BigInt(byte_value) << BigInt(i * 8))
|
124
|
+
.reduce((a, b) => a + b, 0n);
|
125
|
+
};
|
126
|
+
const bigIntToUint8Array = (val, fixedSize = 'dynamic') => {
|
127
|
+
if (val === 0n && fixedSize === 'dynamic') {
|
128
|
+
return new Uint8Array(0);
|
129
|
+
}
|
130
|
+
const maxBytes = fixedSize === 'dynamic' ? undefined : fixedSize;
|
131
|
+
let hex = val.toString(16);
|
132
|
+
// Pad the hex with zeros so it matches the size in bytes
|
133
|
+
if (fixedSize !== 'dynamic' && hex.length !== fixedSize * 2) {
|
134
|
+
hex = hex.padStart(fixedSize * 2, '0');
|
135
|
+
}
|
136
|
+
else if (hex.length % 2 == 1) {
|
137
|
+
// Pad to 'whole' byte
|
138
|
+
hex = `0${hex}`;
|
139
|
+
}
|
140
|
+
if (maxBytes && hex.length > maxBytes * 2) {
|
141
|
+
throw new AvmError(`Cannot encode ${val} as ${maxBytes} bytes as it would overflow`);
|
142
|
+
}
|
143
|
+
const byteArray = new Uint8Array(hex.length / 2);
|
144
|
+
for (let i = 0, j = 0; i < hex.length / 2; i++, j += 2) {
|
145
|
+
byteArray[i] = parseInt(hex.slice(j, j + 2), 16);
|
146
|
+
}
|
147
|
+
return byteArray;
|
148
|
+
};
|
149
|
+
const utf8ToUint8Array = (value) => {
|
150
|
+
const encoder = new TextEncoder();
|
151
|
+
return encoder.encode(value);
|
152
|
+
};
|
153
|
+
const uint8ArrayToUtf8 = (value) => {
|
154
|
+
const decoder = new TextDecoder();
|
155
|
+
return decoder.decode(value);
|
156
|
+
};
|
157
|
+
const uint8ArrayToHex = (value) => Buffer.from(value).toString('hex');
|
158
|
+
const uint8ArrayToBase64 = (value) => Buffer.from(value).toString('base64');
|
159
|
+
const uint8ArrayToBase64Url = (value) => Buffer.from(value).toString('base64url');
|
160
|
+
|
161
|
+
var encodingUtil = /*#__PURE__*/Object.freeze({
|
162
|
+
__proto__: null,
|
163
|
+
bigIntToUint8Array: bigIntToUint8Array,
|
164
|
+
uint8ArrayToBase32: uint8ArrayToBase32,
|
165
|
+
uint8ArrayToBase64: uint8ArrayToBase64,
|
166
|
+
uint8ArrayToBase64Url: uint8ArrayToBase64Url,
|
167
|
+
uint8ArrayToBigInt: uint8ArrayToBigInt,
|
168
|
+
uint8ArrayToHex: uint8ArrayToHex,
|
169
|
+
uint8ArrayToUtf8: uint8ArrayToUtf8,
|
170
|
+
utf8ToUint8Array: utf8ToUint8Array
|
171
|
+
});
|
172
|
+
|
173
|
+
const nameOfType = (x) => {
|
174
|
+
if (typeof x === 'object') {
|
175
|
+
if (x === null)
|
176
|
+
return 'Null';
|
177
|
+
if (x === undefined)
|
178
|
+
return 'undefined';
|
179
|
+
if ('constructor' in x) {
|
180
|
+
return x.constructor.name;
|
181
|
+
}
|
182
|
+
}
|
183
|
+
return typeof x;
|
184
|
+
};
|
185
|
+
|
186
|
+
const MAX_UINT8 = 2 ** 8 - 1;
|
187
|
+
const MAX_BYTES_SIZE = 4096;
|
188
|
+
function toExternalValue(val) {
|
189
|
+
const instance = val;
|
190
|
+
if (instance instanceof BytesCls)
|
191
|
+
return instance.asUint8Array();
|
192
|
+
if (instance instanceof Uint64Cls)
|
193
|
+
return instance.asBigInt();
|
194
|
+
if (instance instanceof BigUintCls)
|
195
|
+
return instance.asBigInt();
|
196
|
+
if (typeof val === 'string')
|
197
|
+
return val;
|
198
|
+
}
|
199
|
+
const toBytes = (val) => {
|
200
|
+
if (val instanceof AlgoTsPrimitiveCls)
|
201
|
+
return val.toBytes().asAlgoTs();
|
202
|
+
switch (typeof val) {
|
203
|
+
case 'string':
|
204
|
+
return BytesCls.fromCompat(val).asAlgoTs();
|
205
|
+
case 'bigint':
|
206
|
+
return BigUintCls.fromCompat(val).toBytes().asAlgoTs();
|
207
|
+
case 'number':
|
208
|
+
return Uint64Cls.fromCompat(val).toBytes().asAlgoTs();
|
209
|
+
default:
|
210
|
+
internalError(`Unsupported arg type ${nameOfType(val)}`);
|
211
|
+
}
|
212
|
+
};
|
213
|
+
const isBytes = (v) => {
|
214
|
+
if (typeof v === 'string')
|
215
|
+
return true;
|
216
|
+
if (v instanceof BytesCls)
|
217
|
+
return true;
|
218
|
+
return v instanceof Uint8Array;
|
219
|
+
};
|
220
|
+
const isUint64 = (v) => {
|
221
|
+
if (typeof v == 'boolean')
|
222
|
+
return true;
|
223
|
+
if (typeof v == 'number')
|
224
|
+
return true;
|
225
|
+
if (typeof v == 'bigint')
|
226
|
+
return true;
|
227
|
+
return v instanceof Uint64Cls;
|
228
|
+
};
|
229
|
+
const isBigUint = (v) => {
|
230
|
+
return v instanceof BigUintCls;
|
231
|
+
};
|
232
|
+
const checkUint64 = (v) => {
|
233
|
+
const u64 = BigInt.asUintN(64, v);
|
234
|
+
if (u64 !== v)
|
235
|
+
throw new AvmError(`Uint64 over or underflow`);
|
236
|
+
return u64;
|
237
|
+
};
|
238
|
+
const checkBigUint = (v) => {
|
239
|
+
const uBig = BigInt.asUintN(64 * 8, v);
|
240
|
+
if (uBig !== v)
|
241
|
+
throw new AvmError(`BigUint over or underflow`);
|
242
|
+
return uBig;
|
243
|
+
};
|
244
|
+
const checkBytes = (v) => {
|
245
|
+
if (v.length > MAX_BYTES_SIZE)
|
246
|
+
throw new AvmError(`Bytes length ${v.length} exceeds maximum length ${MAX_BYTES_SIZE}`);
|
247
|
+
return v;
|
248
|
+
};
|
249
|
+
class AlgoTsPrimitiveCls {
|
250
|
+
_type = AlgoTsPrimitiveCls.name;
|
251
|
+
constructor(t) {
|
252
|
+
this._type = `${AlgoTsPrimitiveCls.name}.${t}`;
|
253
|
+
}
|
254
|
+
static [Symbol.hasInstance](x) {
|
255
|
+
return x instanceof Object && '_type' in x && x['_type'].startsWith(AlgoTsPrimitiveCls.name);
|
256
|
+
}
|
257
|
+
}
|
258
|
+
class Uint64Cls extends AlgoTsPrimitiveCls {
|
259
|
+
value;
|
260
|
+
constructor(value) {
|
261
|
+
super(Uint64Cls.name);
|
262
|
+
this.value = BigInt(value);
|
263
|
+
checkUint64(this.value);
|
264
|
+
}
|
265
|
+
static [Symbol.hasInstance](x) {
|
266
|
+
return x instanceof Object && '_type' in x && x['_type'].endsWith(Uint64Cls.name);
|
267
|
+
}
|
268
|
+
static fromCompat(v) {
|
269
|
+
if (typeof v == 'boolean')
|
270
|
+
return new Uint64Cls(v ? 1n : 0n);
|
271
|
+
if (typeof v == 'number')
|
272
|
+
return new Uint64Cls(BigInt(v));
|
273
|
+
if (typeof v == 'bigint')
|
274
|
+
return new Uint64Cls(v);
|
275
|
+
if (v instanceof Uint64Cls)
|
276
|
+
return v;
|
277
|
+
internalError(`Cannot convert ${v} to uint64`);
|
278
|
+
}
|
279
|
+
static getNumber(v) {
|
280
|
+
return Uint64Cls.fromCompat(v).asNumber();
|
281
|
+
}
|
282
|
+
valueOf() {
|
283
|
+
return this.value;
|
284
|
+
}
|
285
|
+
toBytes(isDynamic = false) {
|
286
|
+
return new BytesCls(bigIntToUint8Array(this.value, isDynamic ? 'dynamic' : 8));
|
287
|
+
}
|
288
|
+
asAlgoTs() {
|
289
|
+
return this;
|
290
|
+
}
|
291
|
+
asBigInt() {
|
292
|
+
return this.value;
|
293
|
+
}
|
294
|
+
asNumber() {
|
295
|
+
if (this.value > Number.MAX_SAFE_INTEGER) {
|
296
|
+
throw new AvmError('value cannot be safely converted to a number');
|
297
|
+
}
|
298
|
+
return Number(this.value);
|
299
|
+
}
|
300
|
+
}
|
301
|
+
class BigUintCls extends AlgoTsPrimitiveCls {
|
302
|
+
value;
|
303
|
+
constructor(value) {
|
304
|
+
super(BigUintCls.name);
|
305
|
+
this.value = value;
|
306
|
+
}
|
307
|
+
valueOf() {
|
308
|
+
return this.value;
|
309
|
+
}
|
310
|
+
toBytes() {
|
311
|
+
return new BytesCls(bigIntToUint8Array(this.value));
|
312
|
+
}
|
313
|
+
asAlgoTs() {
|
314
|
+
return this;
|
315
|
+
}
|
316
|
+
asBigInt() {
|
317
|
+
return this.value;
|
318
|
+
}
|
319
|
+
asNumber() {
|
320
|
+
if (this.value > Number.MAX_SAFE_INTEGER) {
|
321
|
+
throw new AvmError('value cannot be safely converted to a number');
|
322
|
+
}
|
323
|
+
return Number(this.value);
|
324
|
+
}
|
325
|
+
static [Symbol.hasInstance](x) {
|
326
|
+
return x instanceof Object && '_type' in x && x['_type'].endsWith(BigUintCls.name);
|
327
|
+
}
|
328
|
+
static fromCompat(v) {
|
329
|
+
if (typeof v == 'boolean')
|
330
|
+
return new BigUintCls(v ? 1n : 0n);
|
331
|
+
if (typeof v == 'number')
|
332
|
+
return new BigUintCls(BigInt(v));
|
333
|
+
if (typeof v == 'bigint')
|
334
|
+
return new BigUintCls(v);
|
335
|
+
if (v instanceof Uint64Cls)
|
336
|
+
return new BigUintCls(v.value);
|
337
|
+
if (v instanceof BytesCls)
|
338
|
+
return v.toBigUint();
|
339
|
+
if (v instanceof BigUintCls)
|
340
|
+
return v;
|
341
|
+
internalError(`Cannot convert ${nameOfType(v)} to BigUint`);
|
342
|
+
}
|
343
|
+
}
|
344
|
+
class BytesCls extends AlgoTsPrimitiveCls {
|
345
|
+
#v;
|
346
|
+
constructor(v) {
|
347
|
+
super(BytesCls.name);
|
348
|
+
this.#v = v;
|
349
|
+
checkBytes(this.#v);
|
350
|
+
}
|
351
|
+
get length() {
|
352
|
+
return new Uint64Cls(this.#v.length);
|
353
|
+
}
|
354
|
+
toBytes() {
|
355
|
+
return this;
|
356
|
+
}
|
357
|
+
at(i) {
|
358
|
+
const start = Uint64Cls.fromCompat(i).asNumber();
|
359
|
+
return new BytesCls(this.#v.slice(start, start + 1));
|
360
|
+
}
|
361
|
+
slice(start, end) {
|
362
|
+
const startNumber = start instanceof Uint64Cls ? start.asNumber() : start;
|
363
|
+
const endNumber = end instanceof Uint64Cls ? end.asNumber() : end;
|
364
|
+
const sliced = arrayUtil.arraySlice(this.#v, startNumber, endNumber);
|
365
|
+
return new BytesCls(sliced);
|
366
|
+
}
|
367
|
+
concat(other) {
|
368
|
+
const otherArray = BytesCls.fromCompat(other).asUint8Array();
|
369
|
+
const mergedArray = new Uint8Array(this.#v.length + otherArray.length);
|
370
|
+
mergedArray.set(this.#v);
|
371
|
+
mergedArray.set(otherArray, this.#v.length);
|
372
|
+
return new BytesCls(mergedArray);
|
373
|
+
}
|
374
|
+
bitwiseAnd(other) {
|
375
|
+
return this.bitwiseOp(other, (a, b) => a & b);
|
376
|
+
}
|
377
|
+
bitwiseOr(other) {
|
378
|
+
return this.bitwiseOp(other, (a, b) => a | b);
|
379
|
+
}
|
380
|
+
bitwiseXor(other) {
|
381
|
+
return this.bitwiseOp(other, (a, b) => a ^ b);
|
382
|
+
}
|
383
|
+
bitwiseInvert() {
|
384
|
+
const result = new Uint8Array(this.#v.length);
|
385
|
+
this.#v.forEach((v, i) => {
|
386
|
+
result[i] = ~v & MAX_UINT8;
|
387
|
+
});
|
388
|
+
return new BytesCls(result);
|
389
|
+
}
|
390
|
+
equals(other) {
|
391
|
+
const otherArray = BytesCls.fromCompat(other).asUint8Array();
|
392
|
+
if (this.#v.length !== otherArray.length)
|
393
|
+
return false;
|
394
|
+
for (let i = 0; i < this.#v.length; i++) {
|
395
|
+
if (this.#v[i] !== otherArray[i])
|
396
|
+
return false;
|
397
|
+
}
|
398
|
+
return true;
|
399
|
+
}
|
400
|
+
bitwiseOp(other, op) {
|
401
|
+
const otherArray = BytesCls.fromCompat(other).asUint8Array();
|
402
|
+
const result = new Uint8Array(Math.max(this.#v.length, otherArray.length));
|
403
|
+
for (let i = result.length - 1; i >= 0; i--) {
|
404
|
+
const thisIndex = i - (result.length - this.#v.length);
|
405
|
+
const otherIndex = i - (result.length - otherArray.length);
|
406
|
+
result[i] = op(this.#v[thisIndex] ?? 0, otherArray[otherIndex] ?? 0);
|
407
|
+
}
|
408
|
+
return new BytesCls(result);
|
409
|
+
}
|
410
|
+
valueOf() {
|
411
|
+
return uint8ArrayToUtf8(this.#v);
|
412
|
+
}
|
413
|
+
static [Symbol.hasInstance](x) {
|
414
|
+
return x instanceof Object && '_type' in x && x['_type'].endsWith(BytesCls.name);
|
415
|
+
}
|
416
|
+
static fromCompat(v) {
|
417
|
+
if (v === undefined)
|
418
|
+
return new BytesCls(new Uint8Array());
|
419
|
+
if (typeof v === 'string')
|
420
|
+
return new BytesCls(utf8ToUint8Array(v));
|
421
|
+
if (v instanceof BytesCls)
|
422
|
+
return v;
|
423
|
+
if (v instanceof Uint8Array)
|
424
|
+
return new BytesCls(v);
|
425
|
+
internalError(`Cannot convert ${nameOfType(v)} to bytes`);
|
426
|
+
}
|
427
|
+
static fromInterpolation(template, replacements) {
|
428
|
+
return template
|
429
|
+
.flatMap((templateText, index) => {
|
430
|
+
const replacement = replacements[index];
|
431
|
+
if (replacement) {
|
432
|
+
return [BytesCls.fromCompat(templateText), BytesCls.fromCompat(replacement)];
|
433
|
+
}
|
434
|
+
return [BytesCls.fromCompat(templateText)];
|
435
|
+
})
|
436
|
+
.reduce((a, b) => a.concat(b));
|
437
|
+
}
|
438
|
+
static fromHex(hex) {
|
439
|
+
return new BytesCls(Uint8Array.from(Buffer.from(hex, 'hex')));
|
440
|
+
}
|
441
|
+
static fromBase64(b64) {
|
442
|
+
return new BytesCls(Uint8Array.from(Buffer.from(b64, 'base64')));
|
443
|
+
}
|
444
|
+
static fromBase32(b32) {
|
445
|
+
return new BytesCls(base32ToUint8Array(b32));
|
446
|
+
}
|
447
|
+
toUint64() {
|
448
|
+
return new Uint64Cls(uint8ArrayToBigInt(this.#v));
|
449
|
+
}
|
450
|
+
toBigUint() {
|
451
|
+
return new BigUintCls(uint8ArrayToBigInt(this.#v));
|
452
|
+
}
|
453
|
+
toString() {
|
454
|
+
return this.valueOf();
|
455
|
+
}
|
456
|
+
asAlgoTs() {
|
457
|
+
return this;
|
458
|
+
}
|
459
|
+
asUint8Array() {
|
460
|
+
return this.#v;
|
461
|
+
}
|
462
|
+
}
|
463
|
+
const arrayUtil = new (class {
|
464
|
+
arrayAt(arrayLike, index) {
|
465
|
+
return arrayLike.at(Uint64Cls.fromCompat(index).asNumber()) ?? avmError('Index out of bounds');
|
466
|
+
}
|
467
|
+
arraySlice(arrayLike, start, end) {
|
468
|
+
return arrayLike.slice(Uint64Cls.getNumber(start), Uint64Cls.getNumber(end));
|
469
|
+
}
|
470
|
+
})();
|
471
|
+
|
472
|
+
var primitives = /*#__PURE__*/Object.freeze({
|
473
|
+
__proto__: null,
|
474
|
+
AlgoTsPrimitiveCls: AlgoTsPrimitiveCls,
|
475
|
+
BigUintCls: BigUintCls,
|
476
|
+
BytesCls: BytesCls,
|
477
|
+
Uint64Cls: Uint64Cls,
|
478
|
+
arrayUtil: arrayUtil,
|
479
|
+
checkBigUint: checkBigUint,
|
480
|
+
checkBytes: checkBytes,
|
481
|
+
checkUint64: checkUint64,
|
482
|
+
isBigUint: isBigUint,
|
483
|
+
isBytes: isBytes,
|
484
|
+
isUint64: isUint64,
|
485
|
+
toBytes: toBytes,
|
486
|
+
toExternalValue: toExternalValue
|
487
|
+
});
|
488
|
+
|
489
|
+
function Uint64(v) {
|
490
|
+
return Uint64Cls.fromCompat(v).asAlgoTs();
|
491
|
+
}
|
492
|
+
function BigUint(v) {
|
493
|
+
return BigUintCls.fromCompat(v).asAlgoTs();
|
494
|
+
}
|
495
|
+
function Bytes(value, ...replacements) {
|
496
|
+
if (isTemplateStringsArray(value)) {
|
497
|
+
return BytesCls.fromInterpolation(value, replacements).asAlgoTs();
|
498
|
+
}
|
499
|
+
else {
|
500
|
+
return BytesCls.fromCompat(value).asAlgoTs();
|
501
|
+
}
|
502
|
+
}
|
503
|
+
/**
|
504
|
+
* Create a new bytes value from a hexadecimal encoded string
|
505
|
+
* @param hex
|
506
|
+
*/
|
507
|
+
Bytes.fromHex = (hex) => {
|
508
|
+
return BytesCls.fromHex(hex).asAlgoTs();
|
509
|
+
};
|
510
|
+
/**
|
511
|
+
* Create a new bytes value from a base 64 encoded string
|
512
|
+
* @param b64
|
513
|
+
*/
|
514
|
+
Bytes.fromBase64 = (b64) => {
|
515
|
+
return BytesCls.fromBase64(b64).asAlgoTs();
|
516
|
+
};
|
517
|
+
/**
|
518
|
+
* Create a new bytes value from a base 32 encoded string
|
519
|
+
* @param b32
|
520
|
+
*/
|
521
|
+
Bytes.fromBase32 = (b32) => {
|
522
|
+
return BytesCls.fromBase32(b32).asAlgoTs();
|
523
|
+
};
|
524
|
+
function isTemplateStringsArray(v) {
|
525
|
+
return Boolean(v) && Array.isArray(v) && typeof v[0] === 'string';
|
526
|
+
}
|
527
|
+
|
528
|
+
const ctxMgr = {
|
529
|
+
set instance(ctx) {
|
530
|
+
const instance = global.puyaTsExecutionContext;
|
531
|
+
if (instance != undefined)
|
532
|
+
throw new Error('Execution context has already been set');
|
533
|
+
global.puyaTsExecutionContext = ctx;
|
534
|
+
},
|
535
|
+
get instance() {
|
536
|
+
const instance = global.puyaTsExecutionContext;
|
537
|
+
if (instance == undefined)
|
538
|
+
throw new Error('No execution context has been set');
|
539
|
+
return instance;
|
540
|
+
},
|
541
|
+
reset() {
|
542
|
+
global.puyaTsExecutionContext = undefined;
|
543
|
+
},
|
544
|
+
};
|
545
|
+
|
546
|
+
function log(...args) {
|
547
|
+
ctxMgr.instance.log(args.map(toBytes).reduce((left, right) => left.concat(right)));
|
548
|
+
}
|
549
|
+
function assert(condition, message) {
|
550
|
+
if (!condition) {
|
551
|
+
throw new AssertError(message ?? 'Assertion failed');
|
552
|
+
}
|
553
|
+
}
|
554
|
+
function err(message) {
|
555
|
+
throw new AvmError(message ?? 'Err');
|
556
|
+
}
|
557
|
+
function match(subject, test) {
|
558
|
+
return true;
|
559
|
+
}
|
560
|
+
function assertMatch(subject, test, message) {
|
561
|
+
return true;
|
562
|
+
}
|
563
|
+
var OpUpFeeSource;
|
564
|
+
(function (OpUpFeeSource) {
|
565
|
+
OpUpFeeSource[OpUpFeeSource["GroupCredit"] = 0] = "GroupCredit";
|
566
|
+
OpUpFeeSource[OpUpFeeSource["AppAccount"] = 1] = "AppAccount";
|
567
|
+
OpUpFeeSource[OpUpFeeSource["Any"] = 2] = "Any";
|
568
|
+
})(OpUpFeeSource || (OpUpFeeSource = {}));
|
569
|
+
function ensureBudget(budget, feeSource = OpUpFeeSource.GroupCredit) {
|
570
|
+
throw new Error('Not implemented');
|
571
|
+
}
|
572
|
+
function urange(a, b, c) {
|
573
|
+
throw new Error('Not implemented');
|
574
|
+
}
|
575
|
+
|
576
|
+
class BaseContract {
|
577
|
+
clearStateProgram() {
|
578
|
+
return true;
|
579
|
+
}
|
580
|
+
}
|
581
|
+
|
582
|
+
class AbiEncoded {
|
583
|
+
get bytes() {
|
584
|
+
throw new Error('todo');
|
585
|
+
}
|
586
|
+
}
|
587
|
+
class Str extends AbiEncoded {
|
588
|
+
constructor(s) {
|
589
|
+
super();
|
590
|
+
}
|
591
|
+
get native() {
|
592
|
+
throw new Error('TODO');
|
593
|
+
}
|
594
|
+
}
|
595
|
+
class UintN extends AbiEncoded {
|
596
|
+
constructor(v) {
|
597
|
+
super();
|
598
|
+
}
|
599
|
+
get native() {
|
600
|
+
throw new Error('TODO');
|
601
|
+
}
|
602
|
+
}
|
603
|
+
class UFixedNxM {
|
604
|
+
constructor(v, n, m) { }
|
605
|
+
get native() {
|
606
|
+
throw new Error('TODO');
|
607
|
+
}
|
608
|
+
}
|
609
|
+
class Byte extends UintN {
|
610
|
+
constructor(v) {
|
611
|
+
super(v);
|
612
|
+
}
|
613
|
+
get native() {
|
614
|
+
throw new Error('TODO');
|
615
|
+
}
|
616
|
+
}
|
617
|
+
class Bool {
|
618
|
+
#v;
|
619
|
+
constructor(v) {
|
620
|
+
this.#v = v;
|
621
|
+
}
|
622
|
+
get native() {
|
623
|
+
return this.#v;
|
624
|
+
}
|
625
|
+
}
|
626
|
+
class Arc4Array extends AbiEncoded {
|
627
|
+
items;
|
628
|
+
constructor(items) {
|
629
|
+
super();
|
630
|
+
this.items = items;
|
631
|
+
}
|
632
|
+
get length() {
|
633
|
+
throw new Error('TODO');
|
634
|
+
}
|
635
|
+
at(index) {
|
636
|
+
return arrayUtil.arrayAt(this.items, index);
|
637
|
+
}
|
638
|
+
slice(start, end) {
|
639
|
+
return new DynamicArray(...arrayUtil.arraySlice(this.items, start, end));
|
640
|
+
}
|
641
|
+
[Symbol.iterator]() {
|
642
|
+
return this.items[Symbol.iterator]();
|
643
|
+
}
|
644
|
+
entries() {
|
645
|
+
throw new Error('TODO');
|
646
|
+
}
|
647
|
+
keys() {
|
648
|
+
throw new Error('TODO');
|
649
|
+
}
|
650
|
+
}
|
651
|
+
class StaticArray extends Arc4Array {
|
652
|
+
constructor(...items) {
|
653
|
+
super(items);
|
654
|
+
}
|
655
|
+
copy() {
|
656
|
+
return new StaticArray(...this.items);
|
657
|
+
}
|
658
|
+
}
|
659
|
+
class DynamicArray extends Arc4Array {
|
660
|
+
constructor(...items) {
|
661
|
+
super(items);
|
662
|
+
}
|
663
|
+
push(...items) { }
|
664
|
+
pop() {
|
665
|
+
throw new Error('Not implemented');
|
666
|
+
}
|
667
|
+
copy() {
|
668
|
+
return new DynamicArray(...this.items);
|
669
|
+
}
|
670
|
+
}
|
671
|
+
class Tuple {
|
672
|
+
#items;
|
673
|
+
constructor(...items) {
|
674
|
+
this.#items = items;
|
675
|
+
}
|
676
|
+
at(index) {
|
677
|
+
return (this.#items[index] ?? err('Index out of bounds'));
|
678
|
+
}
|
679
|
+
get native() {
|
680
|
+
return this.#items;
|
681
|
+
}
|
682
|
+
}
|
683
|
+
class Address extends StaticArray {
|
684
|
+
constructor(value) {
|
685
|
+
super();
|
686
|
+
}
|
687
|
+
get native() {
|
688
|
+
throw new Error('TODO');
|
689
|
+
}
|
690
|
+
}
|
691
|
+
|
692
|
+
class Contract extends BaseContract {
|
693
|
+
approvalProgram() {
|
694
|
+
return true;
|
695
|
+
}
|
696
|
+
}
|
697
|
+
var OnCompleteAction;
|
698
|
+
(function (OnCompleteAction) {
|
699
|
+
OnCompleteAction[OnCompleteAction["NoOp"] = Uint64(0)] = "NoOp";
|
700
|
+
OnCompleteAction[OnCompleteAction["OptIn"] = Uint64(1)] = "OptIn";
|
701
|
+
OnCompleteAction[OnCompleteAction["CloseOut"] = Uint64(2)] = "CloseOut";
|
702
|
+
OnCompleteAction[OnCompleteAction["ClearState"] = Uint64(3)] = "ClearState";
|
703
|
+
OnCompleteAction[OnCompleteAction["UpdateApplication"] = Uint64(4)] = "UpdateApplication";
|
704
|
+
OnCompleteAction[OnCompleteAction["DeleteApplication"] = Uint64(5)] = "DeleteApplication";
|
705
|
+
})(OnCompleteAction || (OnCompleteAction = {}));
|
706
|
+
function abimethod(config) {
|
707
|
+
return function (target, ctx) {
|
708
|
+
ctx.addInitializer(function () {
|
709
|
+
ctxMgr.instance.abiMetadata.captureMethodConfig(this, target.name, config);
|
710
|
+
});
|
711
|
+
return target;
|
712
|
+
};
|
713
|
+
}
|
714
|
+
function baremethod(config) {
|
715
|
+
return function (target, ctx) {
|
716
|
+
ctx.addInitializer(function () {
|
717
|
+
ctxMgr.instance.abiMetadata.captureMethodConfig(this, target.name, config);
|
718
|
+
});
|
719
|
+
return target;
|
720
|
+
};
|
721
|
+
}
|
722
|
+
|
723
|
+
var index = /*#__PURE__*/Object.freeze({
|
724
|
+
__proto__: null,
|
725
|
+
Address: Address,
|
726
|
+
Bool: Bool,
|
727
|
+
Byte: Byte,
|
728
|
+
Contract: Contract,
|
729
|
+
DynamicArray: DynamicArray,
|
730
|
+
get OnCompleteAction () { return OnCompleteAction; },
|
731
|
+
StaticArray: StaticArray,
|
732
|
+
Str: Str,
|
733
|
+
Tuple: Tuple,
|
734
|
+
UFixedNxM: UFixedNxM,
|
735
|
+
UintN: UintN,
|
736
|
+
abimethod: abimethod,
|
737
|
+
baremethod: baremethod
|
738
|
+
});
|
739
|
+
|
740
|
+
export { AssertError as A, BytesCls as B, Contract as C, DynamicArray as D, OpUpFeeSource as O, Str as S, Tuple as T, Uint64 as U, errors as a, err as b, ctxMgr as c, assert as d, encodingUtil as e, assertMatch as f, ensureBudget as g, abimethod as h, index as i, BaseContract as j, BigUint as k, log as l, match as m, Bytes as n, OnCompleteAction as o, primitives as p, baremethod as q, UintN as r, UFixedNxM as s, Byte as t, urange as u, Bool as v, StaticArray as w, Address as x };
|
741
|
+
//# sourceMappingURL=index-7MfWJL4Q.js.map
|