@algorandfoundation/algorand-typescript-testing 1.0.0-beta.12 → 1.0.0-beta.13
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/{runtime-helpers-C6O92q80.js → encoded-types-CuGiO_X_.js} +691 -523
- package/encoded-types-CuGiO_X_.js.map +1 -0
- package/impl/acct-params.d.ts +2 -3
- package/impl/app-global.d.ts +2 -2
- package/impl/app-local.d.ts +2 -2
- package/impl/app-params.d.ts +2 -2
- package/impl/asset-holding.d.ts +2 -2
- package/impl/asset-params.d.ts +2 -2
- package/impl/block.d.ts +2 -2
- package/impl/box.d.ts +2 -2
- package/impl/crypto.d.ts +9 -2
- package/impl/encoded-types.d.ts +2 -1
- package/impl/global.d.ts +2 -3
- package/impl/gtxn.d.ts +9 -2
- package/impl/itxn.d.ts +4 -4
- package/impl/online-stake.d.ts +2 -2
- package/impl/pure.d.ts +5 -1
- package/impl/scratch.d.ts +4 -4
- package/impl/txn.d.ts +2 -2
- package/impl/voter-params.d.ts +2 -2
- package/index.mjs +15 -3468
- package/index.mjs.map +1 -1
- package/internal/arc4.mjs +10 -0
- package/internal/arc4.mjs.map +1 -1
- package/internal/op.mjs +13 -0
- package/internal/op.mjs.map +1 -1
- package/{internal-arc4-BPiMhb9a.js → internal-arc4-C9t-aREu.js} +4 -2
- package/internal-arc4-C9t-aREu.js.map +1 -0
- package/internal-arc4.d.ts +1 -0
- package/internal-op-DlLQ5gew.js +1597 -0
- package/internal-op-DlLQ5gew.js.map +1 -0
- package/internal-op.d.ts +18 -0
- package/internal.d.ts +22 -0
- package/internal.mjs +35 -6
- package/internal.mjs.map +1 -1
- package/package.json +2 -2
- package/pure-CKz3aJeT.js +1059 -0
- package/pure-CKz3aJeT.js.map +1 -0
- package/runtime-helpers-Dg42m-TM.js +436 -0
- package/runtime-helpers-Dg42m-TM.js.map +1 -0
- package/runtime-helpers.mjs +4 -4
- package/state-BZHLEhrM.js +837 -0
- package/state-BZHLEhrM.js.map +1 -0
- package/test-execution-context.d.ts +1 -1
- package/internal-arc4-BPiMhb9a.js.map +0 -1
- package/internal-op-BJR4Xrem.js +0 -23
- package/internal-op-BJR4Xrem.js.map +0 -1
- package/log-C5qsaKI5.js +0 -602
- package/log-C5qsaKI5.js.map +0 -1
- package/runtime-helpers-C6O92q80.js.map +0 -1
|
@@ -1,14 +1,693 @@
|
|
|
1
|
-
import { Bytes, internal,
|
|
1
|
+
import { Bytes, internal, BaseContract, Ecdsa, arc4, Uint64 } from '@algorandfoundation/algorand-typescript';
|
|
2
2
|
import { UintN, UFixedNxM, Byte, Str, Bool, StaticArray, Address, DynamicArray, Tuple, Struct, DynamicBytes, StaticBytes, ARC4Encoded } from '@algorandfoundation/algorand-typescript/arc4';
|
|
3
|
-
import { a4 as asBigUintCls, F as UINT64_SIZE, b as asUint64, x as asBigUint, v as asBytesCls, L as ABI_RETURN_VALUE_LOG_PREFIX, q as asUint8Array, a5 as ALGORAND_ADDRESS_BYTE_LENGTH, a6 as ALGORAND_CHECKSUM_BYTE_LENGTH, A as Account, w as conactUint8Arrays, a7 as uint8ArrayToNumber, y as BITS_IN_BYTE, m as AccountCls, l as lazyContext, T as asBigInt, p as AssetCls, o as ApplicationCls, a8 as PROGRAM_TAG, a9 as LOGIC_DATA_PREFIX, r as asBytes, aa as log, n as nameOfType, U as Uint64BackedCls, G as MAX_UINT64 } from './log-C5qsaKI5.js';
|
|
4
|
-
import js_sha512 from 'js-sha512';
|
|
5
3
|
import { encodingUtil } from '@algorandfoundation/puya-ts';
|
|
6
4
|
import assert from 'assert';
|
|
5
|
+
import { randomBytes } from 'crypto';
|
|
7
6
|
import elliptic from 'elliptic';
|
|
8
7
|
import js_sha256 from 'js-sha256';
|
|
9
8
|
import js_sha3 from 'js-sha3';
|
|
9
|
+
import js_sha512 from 'js-sha512';
|
|
10
10
|
import nacl from 'tweetnacl';
|
|
11
11
|
|
|
12
|
+
const UINT64_SIZE = 64;
|
|
13
|
+
const UINT512_SIZE = 512;
|
|
14
|
+
const MAX_UINT8 = 2 ** 8 - 1;
|
|
15
|
+
const MAX_UINT16 = 2 ** 16 - 1;
|
|
16
|
+
const MAX_UINT32 = 2 ** 32 - 1;
|
|
17
|
+
const MAX_UINT64 = 2n ** 64n - 1n;
|
|
18
|
+
const MAX_UINT128 = 2n ** 128n - 1n;
|
|
19
|
+
const MAX_UINT256 = 2n ** 256n - 1n;
|
|
20
|
+
const MAX_UINT512 = 2n ** 512n - 1n;
|
|
21
|
+
const MAX_BYTES_SIZE = 4096;
|
|
22
|
+
const MAX_ITEMS_IN_LOG = 32;
|
|
23
|
+
const MAX_BOX_SIZE = 32768;
|
|
24
|
+
const BITS_IN_BYTE = 8;
|
|
25
|
+
const DEFAULT_ACCOUNT_MIN_BALANCE = 100_000;
|
|
26
|
+
const DEFAULT_MAX_TXN_LIFE = 1_000;
|
|
27
|
+
const DEFAULT_ASSET_CREATE_MIN_BALANCE = 1000_000;
|
|
28
|
+
const DEFAULT_ASSET_OPT_IN_MIN_BALANCE = 10_000;
|
|
29
|
+
// from python code: list(b"\x85Y\xb5\x14x\xfd\x89\xc1vC\xd0]\x15\xa8\xaek\x10\xabG\xbbm\x8a1\x88\x11V\xe6\xbd;\xae\x95\xd1")
|
|
30
|
+
const DEFAULT_GLOBAL_GENESIS_HASH = Bytes(new Uint8Array([
|
|
31
|
+
133, 89, 181, 20, 120, 253, 137, 193, 118, 67, 208, 93, 21, 168, 174, 107, 16, 171, 71, 187, 109, 138, 49, 136, 17, 86, 230, 189, 59,
|
|
32
|
+
174, 149, 209,
|
|
33
|
+
]));
|
|
34
|
+
// algorand encoded address of 32 zero bytes
|
|
35
|
+
const ZERO_ADDRESS = Bytes.fromBase32('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA');
|
|
36
|
+
/**
|
|
37
|
+
"\x09" # pragma version 9
|
|
38
|
+
"\x81\x01" # pushint 1
|
|
39
|
+
*/
|
|
40
|
+
const ALWAYS_APPROVE_TEAL_PROGRAM = Bytes(new Uint8Array([0x09, 0x81, 0x01]));
|
|
41
|
+
// bytes: program (logic) data prefix when signing
|
|
42
|
+
const LOGIC_DATA_PREFIX = Bytes('ProgData');
|
|
43
|
+
//number: minimum transaction fee
|
|
44
|
+
const MIN_TXN_FEE = 1000;
|
|
45
|
+
const ABI_RETURN_VALUE_LOG_PREFIX = Bytes.fromHex('151F7C75');
|
|
46
|
+
const DEFAULT_TEMPLATE_VAR_PREFIX = 'TMPL_';
|
|
47
|
+
const APP_ID_PREFIX = 'appID';
|
|
48
|
+
const HASH_BYTES_LENGTH = 32;
|
|
49
|
+
const ALGORAND_ADDRESS_BYTE_LENGTH = 36;
|
|
50
|
+
const ALGORAND_CHECKSUM_BYTE_LENGTH = 4;
|
|
51
|
+
const ALGORAND_ADDRESS_LENGTH = 58;
|
|
52
|
+
const PROGRAM_TAG = 'Program';
|
|
53
|
+
const TRANSACTION_GROUP_MAX_SIZE = 16;
|
|
54
|
+
var OnApplicationComplete;
|
|
55
|
+
(function (OnApplicationComplete) {
|
|
56
|
+
OnApplicationComplete[OnApplicationComplete["NoOpOC"] = 0] = "NoOpOC";
|
|
57
|
+
OnApplicationComplete[OnApplicationComplete["OptInOC"] = 1] = "OptInOC";
|
|
58
|
+
OnApplicationComplete[OnApplicationComplete["CloseOutOC"] = 2] = "CloseOutOC";
|
|
59
|
+
OnApplicationComplete[OnApplicationComplete["ClearStateOC"] = 3] = "ClearStateOC";
|
|
60
|
+
OnApplicationComplete[OnApplicationComplete["UpdateApplicationOC"] = 4] = "UpdateApplicationOC";
|
|
61
|
+
OnApplicationComplete[OnApplicationComplete["DeleteApplicationOC"] = 5] = "DeleteApplicationOC";
|
|
62
|
+
})(OnApplicationComplete || (OnApplicationComplete = {}));
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* For accessing implementation specific functions, with a convenient single entry
|
|
66
|
+
* point for other modules to import Also allows for a single place to check and
|
|
67
|
+
* provide.
|
|
68
|
+
*/
|
|
69
|
+
class InternalContext {
|
|
70
|
+
get value() {
|
|
71
|
+
return internal.ctxMgr.instance;
|
|
72
|
+
}
|
|
73
|
+
get defaultSender() {
|
|
74
|
+
return this.value.defaultSender;
|
|
75
|
+
}
|
|
76
|
+
get ledger() {
|
|
77
|
+
return this.value.ledger;
|
|
78
|
+
}
|
|
79
|
+
get txn() {
|
|
80
|
+
return this.value.txn;
|
|
81
|
+
}
|
|
82
|
+
get contract() {
|
|
83
|
+
return this.value.contract;
|
|
84
|
+
}
|
|
85
|
+
get any() {
|
|
86
|
+
return this.value.any;
|
|
87
|
+
}
|
|
88
|
+
get activeApplication() {
|
|
89
|
+
return this.ledger.getApplication(this.activeGroup.activeApplicationId);
|
|
90
|
+
}
|
|
91
|
+
get activeGroup() {
|
|
92
|
+
return this.value.txn.activeGroup;
|
|
93
|
+
}
|
|
94
|
+
getAccountData(account) {
|
|
95
|
+
const data = this.ledger.accountDataMap.get(account);
|
|
96
|
+
if (!data) {
|
|
97
|
+
throw internal.errors.internalError('Unknown account, check correct testing context is active');
|
|
98
|
+
}
|
|
99
|
+
return data;
|
|
100
|
+
}
|
|
101
|
+
getAssetData(id) {
|
|
102
|
+
const key = internal.primitives.Uint64Cls.fromCompat(id);
|
|
103
|
+
const data = this.ledger.assetDataMap.get(key.asBigInt());
|
|
104
|
+
if (!data) {
|
|
105
|
+
throw internal.errors.internalError('Unknown asset, check correct testing context is active');
|
|
106
|
+
}
|
|
107
|
+
return data;
|
|
108
|
+
}
|
|
109
|
+
getApplicationData(id) {
|
|
110
|
+
const uint64Id = id instanceof BaseContract ? this.ledger.getApplicationForContract(id).id : internal.primitives.Uint64Cls.fromCompat(id);
|
|
111
|
+
const data = this.ledger.applicationDataMap.get(uint64Id);
|
|
112
|
+
if (!data) {
|
|
113
|
+
throw internal.errors.internalError('Unknown application, check correct testing context is active');
|
|
114
|
+
}
|
|
115
|
+
return data;
|
|
116
|
+
}
|
|
117
|
+
getVoterData(account) {
|
|
118
|
+
const data = this.ledger.voterDataMap.get(account);
|
|
119
|
+
if (!data) {
|
|
120
|
+
throw internal.errors.internalError('Unknown voter, check correct testing context is active');
|
|
121
|
+
}
|
|
122
|
+
return data;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
const lazyContext = new InternalContext();
|
|
126
|
+
|
|
127
|
+
const nameOfType = (x) => {
|
|
128
|
+
if (typeof x === 'object') {
|
|
129
|
+
if (x === null)
|
|
130
|
+
return 'Null';
|
|
131
|
+
if (x === undefined)
|
|
132
|
+
return 'undefined';
|
|
133
|
+
if ('constructor' in x) {
|
|
134
|
+
return x.constructor.name;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return typeof x;
|
|
138
|
+
};
|
|
139
|
+
function* iterBigInt(start, end) {
|
|
140
|
+
for (let i = start; i < end; i++) {
|
|
141
|
+
yield BigInt(i);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
const asBigInt = (v) => asUint64Cls(v).asBigInt();
|
|
145
|
+
const asNumber = (v) => asUint64Cls(v).asNumber();
|
|
146
|
+
const asUint64Cls = (val) => internal.primitives.Uint64Cls.fromCompat(val);
|
|
147
|
+
const asBigUintCls = (val) => internal.primitives.BigUintCls.fromCompat(val instanceof Uint8Array ? asBytes(val) : Array.isArray(val) ? asBytes(new Uint8Array(val)) : val);
|
|
148
|
+
const asBytesCls = (val) => internal.primitives.BytesCls.fromCompat(val);
|
|
149
|
+
const asUint64 = (val) => asUint64Cls(val).asAlgoTs();
|
|
150
|
+
const asBigUint = (val) => asBigUintCls(val).asAlgoTs();
|
|
151
|
+
const asBytes = (val) => asBytesCls(val).asAlgoTs();
|
|
152
|
+
const asUint8Array = (val) => asBytesCls(val).asUint8Array();
|
|
153
|
+
const asMaybeUint64Cls = (val) => {
|
|
154
|
+
try {
|
|
155
|
+
return internal.primitives.Uint64Cls.fromCompat(val);
|
|
156
|
+
}
|
|
157
|
+
catch (e) {
|
|
158
|
+
if (e instanceof internal.errors.InternalError) ;
|
|
159
|
+
else {
|
|
160
|
+
throw e;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return undefined;
|
|
164
|
+
};
|
|
165
|
+
const asMaybeBigUintCls = (val) => {
|
|
166
|
+
try {
|
|
167
|
+
return internal.primitives.BigUintCls.fromCompat(val);
|
|
168
|
+
}
|
|
169
|
+
catch (e) {
|
|
170
|
+
if (e instanceof internal.errors.InternalError) ;
|
|
171
|
+
else {
|
|
172
|
+
throw e;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return undefined;
|
|
176
|
+
};
|
|
177
|
+
const asMaybeBytesCls = (val) => {
|
|
178
|
+
try {
|
|
179
|
+
return internal.primitives.BytesCls.fromCompat(val);
|
|
180
|
+
}
|
|
181
|
+
catch (e) {
|
|
182
|
+
if (e instanceof internal.errors.InternalError) ;
|
|
183
|
+
else {
|
|
184
|
+
throw e;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return undefined;
|
|
188
|
+
};
|
|
189
|
+
const binaryStringToBytes = (s) => internal.primitives.BytesCls.fromCompat(new Uint8Array(s.match(/.{1,8}/g).map((x) => parseInt(x, 2))));
|
|
190
|
+
const getRandomNumber = (min, max) => {
|
|
191
|
+
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
192
|
+
};
|
|
193
|
+
const getRandomBigInt = (min, max) => {
|
|
194
|
+
const bigIntMin = BigInt(min);
|
|
195
|
+
const bigIntMax = BigInt(max);
|
|
196
|
+
const randomValue = [...Array(UINT512_SIZE / BITS_IN_BYTE).keys()]
|
|
197
|
+
.map(() => getRandomNumber(0, MAX_UINT8))
|
|
198
|
+
.reduce((acc, x) => acc * 256n + BigInt(x), 0n);
|
|
199
|
+
return (randomValue % (bigIntMax - bigIntMin)) + bigIntMin;
|
|
200
|
+
};
|
|
201
|
+
const getRandomBytes = (length) => asBytesCls(Bytes(randomBytes(length)));
|
|
202
|
+
const ObjectReferenceSymbol = Symbol('ObjectReference');
|
|
203
|
+
const objectRefIter = iterBigInt(1001n, MAX_UINT512);
|
|
204
|
+
const getObjectReference = (obj) => {
|
|
205
|
+
const tryGetReference = (obj) => {
|
|
206
|
+
const s = Object.getOwnPropertySymbols(obj).find((s) => s.toString() === ObjectReferenceSymbol.toString());
|
|
207
|
+
return s ? obj[s] : ObjectReferenceSymbol in obj ? obj[ObjectReferenceSymbol] : undefined;
|
|
208
|
+
};
|
|
209
|
+
const existingRef = tryGetReference(obj);
|
|
210
|
+
if (existingRef !== undefined) {
|
|
211
|
+
return existingRef;
|
|
212
|
+
}
|
|
213
|
+
const ref = objectRefIter.next().value;
|
|
214
|
+
Object.defineProperty(obj, ObjectReferenceSymbol, {
|
|
215
|
+
value: ref,
|
|
216
|
+
enumerable: false,
|
|
217
|
+
writable: false,
|
|
218
|
+
});
|
|
219
|
+
return ref;
|
|
220
|
+
};
|
|
221
|
+
const combineIntoMaxBytePages = (pages) => {
|
|
222
|
+
const combined = pages.reduce((acc, x) => acc.concat(x), asBytesCls(''));
|
|
223
|
+
const totalPages = (asNumber(combined.length) + MAX_BYTES_SIZE - 1) / MAX_BYTES_SIZE;
|
|
224
|
+
const result = [];
|
|
225
|
+
for (let i = 0; i < totalPages; i++) {
|
|
226
|
+
const start = i * MAX_BYTES_SIZE;
|
|
227
|
+
const end = Math.min((i + 1) * MAX_BYTES_SIZE, asNumber(combined.length));
|
|
228
|
+
const page = combined.slice(start, end);
|
|
229
|
+
result.push(page.asAlgoTs());
|
|
230
|
+
}
|
|
231
|
+
return result;
|
|
232
|
+
};
|
|
233
|
+
const conactUint8Arrays = (...values) => {
|
|
234
|
+
const result = new Uint8Array(values.reduce((acc, value) => acc + value.length, 0));
|
|
235
|
+
let index = 0;
|
|
236
|
+
for (const value of values) {
|
|
237
|
+
result.set(value, index);
|
|
238
|
+
index += value.length;
|
|
239
|
+
}
|
|
240
|
+
return result;
|
|
241
|
+
};
|
|
242
|
+
const uint8ArrayToNumber = (value) => {
|
|
243
|
+
return value.reduce((acc, x) => acc * 256 + x, 0);
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
class NotImplementedError extends Error {
|
|
247
|
+
constructor(feature) {
|
|
248
|
+
super(`${feature} is not available in test context. Mock using your preferred testing framework.`);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
function notImplementedError(feature) {
|
|
252
|
+
throw new NotImplementedError(feature);
|
|
253
|
+
}
|
|
254
|
+
function testInvariant(condition, message) {
|
|
255
|
+
if (!condition) {
|
|
256
|
+
throw new internal.errors.InternalError(message);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const sha256 = (a) => {
|
|
261
|
+
const bytesA = internal.primitives.BytesCls.fromCompat(a);
|
|
262
|
+
const hashArray = js_sha256.sha256.create().update(bytesA.asUint8Array()).digest();
|
|
263
|
+
const hashBytes = internal.primitives.BytesCls.fromCompat(new Uint8Array(hashArray));
|
|
264
|
+
return hashBytes.asAlgoTs();
|
|
265
|
+
};
|
|
266
|
+
const sha3_256 = (a) => {
|
|
267
|
+
const bytesA = internal.primitives.BytesCls.fromCompat(a);
|
|
268
|
+
const hashArray = js_sha3.sha3_256.create().update(bytesA.asUint8Array()).digest();
|
|
269
|
+
const hashBytes = internal.primitives.BytesCls.fromCompat(new Uint8Array(hashArray));
|
|
270
|
+
return hashBytes.asAlgoTs();
|
|
271
|
+
};
|
|
272
|
+
const keccak256 = (a) => {
|
|
273
|
+
const bytesA = internal.primitives.BytesCls.fromCompat(a);
|
|
274
|
+
const hashArray = js_sha3.keccak256.create().update(bytesA.asUint8Array()).digest();
|
|
275
|
+
const hashBytes = internal.primitives.BytesCls.fromCompat(new Uint8Array(hashArray));
|
|
276
|
+
return hashBytes.asAlgoTs();
|
|
277
|
+
};
|
|
278
|
+
const sha512_256 = (a) => {
|
|
279
|
+
const bytesA = internal.primitives.BytesCls.fromCompat(a);
|
|
280
|
+
const hashArray = js_sha512.sha512_256.create().update(bytesA.asUint8Array()).digest();
|
|
281
|
+
const hashBytes = internal.primitives.BytesCls.fromCompat(new Uint8Array(hashArray));
|
|
282
|
+
return hashBytes.asAlgoTs();
|
|
283
|
+
};
|
|
284
|
+
const ed25519verifyBare = (a, b, c) => {
|
|
285
|
+
const bytesA = internal.primitives.BytesCls.fromCompat(a);
|
|
286
|
+
const bytesB = internal.primitives.BytesCls.fromCompat(b);
|
|
287
|
+
const bytesC = internal.primitives.BytesCls.fromCompat(c);
|
|
288
|
+
return nacl.sign.detached.verify(bytesA.asUint8Array(), bytesB.asUint8Array(), bytesC.asUint8Array());
|
|
289
|
+
};
|
|
290
|
+
const ed25519verify = (a, b, c) => {
|
|
291
|
+
const txn = lazyContext.activeGroup.activeTransaction;
|
|
292
|
+
const programBytes = asBytesCls(txn.onCompletion == arc4.OnCompleteAction[arc4.OnCompleteAction.ClearState] ? txn.clearStateProgram : txn.approvalProgram);
|
|
293
|
+
const logicSig = conactUint8Arrays(asUint8Array(PROGRAM_TAG), programBytes.asUint8Array());
|
|
294
|
+
const logicSigAddress = js_sha512.sha512_256.array(logicSig);
|
|
295
|
+
const addressBytes = Bytes(logicSigAddress);
|
|
296
|
+
const data = LOGIC_DATA_PREFIX.concat(addressBytes).concat(asBytes(a));
|
|
297
|
+
return ed25519verifyBare(data, b, c);
|
|
298
|
+
};
|
|
299
|
+
const ecdsaVerify = (v, a, b, c, d, e) => {
|
|
300
|
+
const dataBytes = internal.primitives.BytesCls.fromCompat(a);
|
|
301
|
+
const sigRBytes = internal.primitives.BytesCls.fromCompat(b);
|
|
302
|
+
const sigSBytes = internal.primitives.BytesCls.fromCompat(c);
|
|
303
|
+
const pubkeyXBytes = internal.primitives.BytesCls.fromCompat(d);
|
|
304
|
+
const pubkeyYBytes = internal.primitives.BytesCls.fromCompat(e);
|
|
305
|
+
const publicKey = internal.primitives.BytesCls.fromCompat(new Uint8Array([0x04]))
|
|
306
|
+
.concat(pubkeyXBytes)
|
|
307
|
+
.concat(pubkeyYBytes);
|
|
308
|
+
const ecdsa = new elliptic.ec(curveMap[v]);
|
|
309
|
+
const keyPair = ecdsa.keyFromPublic(publicKey.asUint8Array());
|
|
310
|
+
return keyPair.verify(dataBytes.asUint8Array(), { r: sigRBytes.asUint8Array(), s: sigSBytes.asUint8Array() });
|
|
311
|
+
};
|
|
312
|
+
const ecdsaPkRecover = (v, a, b, c, d) => {
|
|
313
|
+
if (v !== Ecdsa.Secp256k1) {
|
|
314
|
+
internal.errors.internalError(`Unsupported ECDSA curve: ${v}`);
|
|
315
|
+
}
|
|
316
|
+
const dataBytes = internal.primitives.BytesCls.fromCompat(a);
|
|
317
|
+
const rBytes = internal.primitives.BytesCls.fromCompat(c);
|
|
318
|
+
const sBytes = internal.primitives.BytesCls.fromCompat(d);
|
|
319
|
+
const recoveryId = internal.primitives.Uint64Cls.fromCompat(b);
|
|
320
|
+
const ecdsa = new elliptic.ec(curveMap[v]);
|
|
321
|
+
const pubKey = ecdsa.recoverPubKey(dataBytes.asUint8Array(), { r: rBytes.asUint8Array(), s: sBytes.asUint8Array() }, recoveryId.asNumber());
|
|
322
|
+
const x = pubKey.getX().toArray('be');
|
|
323
|
+
const y = pubKey.getY().toArray('be');
|
|
324
|
+
return [Bytes(x), Bytes(y)];
|
|
325
|
+
};
|
|
326
|
+
const ecdsaPkDecompress = (v, a) => {
|
|
327
|
+
const bytesA = internal.primitives.BytesCls.fromCompat(a);
|
|
328
|
+
const ecdsa = new elliptic.ec(curveMap[v]);
|
|
329
|
+
const keyPair = ecdsa.keyFromPublic(bytesA.asUint8Array());
|
|
330
|
+
const pubKey = keyPair.getPublic();
|
|
331
|
+
const x = pubKey.getX().toArray('be');
|
|
332
|
+
const y = pubKey.getY().toArray('be');
|
|
333
|
+
return [Bytes(new Uint8Array(x)), Bytes(new Uint8Array(y))];
|
|
334
|
+
};
|
|
335
|
+
const vrfVerify = (_s, _a, _b, _c) => {
|
|
336
|
+
notImplementedError('vrfVerify');
|
|
337
|
+
};
|
|
338
|
+
const EllipticCurve = new Proxy({}, {
|
|
339
|
+
get: (_target, prop) => {
|
|
340
|
+
notImplementedError(`EllipticCurve.${prop.toString()}`);
|
|
341
|
+
},
|
|
342
|
+
});
|
|
343
|
+
const mimc = (_c, _a) => {
|
|
344
|
+
notImplementedError('mimc');
|
|
345
|
+
};
|
|
346
|
+
const curveMap = {
|
|
347
|
+
[Ecdsa.Secp256k1]: 'secp256k1',
|
|
348
|
+
[Ecdsa.Secp256r1]: 'p256',
|
|
349
|
+
};
|
|
350
|
+
|
|
351
|
+
class CustomKeyMap {
|
|
352
|
+
#keySerializer;
|
|
353
|
+
#map = new Map();
|
|
354
|
+
constructor(keySerializer) {
|
|
355
|
+
this.#keySerializer = keySerializer;
|
|
356
|
+
}
|
|
357
|
+
clear() {
|
|
358
|
+
this.#map.clear();
|
|
359
|
+
}
|
|
360
|
+
delete(key) {
|
|
361
|
+
return this.#map.delete(this.#keySerializer(key));
|
|
362
|
+
}
|
|
363
|
+
forEach(callbackfn, thisArg) {
|
|
364
|
+
for (const [key, value] of this.#map.values()) {
|
|
365
|
+
callbackfn.call(thisArg ?? this, value, key, this);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
get(key) {
|
|
369
|
+
return this.#map.get(this.#keySerializer(key))?.[1];
|
|
370
|
+
}
|
|
371
|
+
getOrFail(key) {
|
|
372
|
+
const value = this.get(key);
|
|
373
|
+
if (value === undefined) {
|
|
374
|
+
throw internal.errors.internalError('Key not found');
|
|
375
|
+
}
|
|
376
|
+
return value;
|
|
377
|
+
}
|
|
378
|
+
has(key) {
|
|
379
|
+
return this.#map.has(this.#keySerializer(key));
|
|
380
|
+
}
|
|
381
|
+
set(key, value) {
|
|
382
|
+
this.#map.set(this.#keySerializer(key), [key, value]);
|
|
383
|
+
return this;
|
|
384
|
+
}
|
|
385
|
+
get size() {
|
|
386
|
+
return this.#map.size;
|
|
387
|
+
}
|
|
388
|
+
entries() {
|
|
389
|
+
return this.#map.values();
|
|
390
|
+
}
|
|
391
|
+
*keys() {
|
|
392
|
+
for (const [key] of this.#map.values()) {
|
|
393
|
+
yield key;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
*values() {
|
|
397
|
+
for (const [, value] of this.#map.values()) {
|
|
398
|
+
yield value;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
[Symbol.iterator]() {
|
|
402
|
+
return this.#map.values();
|
|
403
|
+
}
|
|
404
|
+
get [Symbol.toStringTag]() {
|
|
405
|
+
return this.constructor.name;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
class AccountMap extends CustomKeyMap {
|
|
409
|
+
constructor() {
|
|
410
|
+
super(AccountMap.getAddressStrFromAccount);
|
|
411
|
+
}
|
|
412
|
+
static getAddressStrFromAccount = (acc) => {
|
|
413
|
+
return asBytesCls(acc.bytes).valueOf();
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
class BytesMap extends CustomKeyMap {
|
|
417
|
+
constructor() {
|
|
418
|
+
super((bytes) => asBytesCls(bytes).valueOf());
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
class Uint64Map extends CustomKeyMap {
|
|
422
|
+
constructor() {
|
|
423
|
+
super((uint64) => asUint64Cls(uint64).valueOf());
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
class BytesBackedCls {
|
|
428
|
+
#value;
|
|
429
|
+
// #typeInfo: GenericTypeInfo | undefined
|
|
430
|
+
get bytes() {
|
|
431
|
+
return this.#value;
|
|
432
|
+
}
|
|
433
|
+
constructor(value, _typeInfo) {
|
|
434
|
+
this.#value = value;
|
|
435
|
+
// this.#typeInfo = typeInfo
|
|
436
|
+
}
|
|
437
|
+
static fromBytes(value, typeInfo) {
|
|
438
|
+
return new this(internal.primitives.BytesCls.fromCompat(value).asAlgoTs(), typeInfo);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
class Uint64BackedCls {
|
|
442
|
+
#value;
|
|
443
|
+
get uint64() {
|
|
444
|
+
return this.#value;
|
|
445
|
+
}
|
|
446
|
+
constructor(value) {
|
|
447
|
+
this.#value = value;
|
|
448
|
+
}
|
|
449
|
+
static fromBytes(value) {
|
|
450
|
+
const uint8ArrayValue = value instanceof Uint8Array ? value : internal.primitives.BytesCls.fromCompat(value).asUint8Array();
|
|
451
|
+
const uint64Value = Uint64(encodingUtil.uint8ArrayToBigInt(uint8ArrayValue));
|
|
452
|
+
return new this(uint64Value);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
class AssetHolding {
|
|
457
|
+
balance;
|
|
458
|
+
frozen;
|
|
459
|
+
constructor(balance, frozen) {
|
|
460
|
+
this.balance = asUint64(balance);
|
|
461
|
+
this.frozen = frozen;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
class AccountData {
|
|
465
|
+
optedAssets = new Uint64Map();
|
|
466
|
+
optedApplications = new Uint64Map();
|
|
467
|
+
incentiveEligible = false;
|
|
468
|
+
lastProposed;
|
|
469
|
+
lastHeartbeat;
|
|
470
|
+
account;
|
|
471
|
+
constructor() {
|
|
472
|
+
this.account = {
|
|
473
|
+
totalAppsCreated: 0,
|
|
474
|
+
totalAppsOptedIn: 0,
|
|
475
|
+
totalAssets: 0,
|
|
476
|
+
totalAssetsCreated: 0,
|
|
477
|
+
totalBoxBytes: 0,
|
|
478
|
+
totalBoxes: 0,
|
|
479
|
+
totalExtraAppPages: 0,
|
|
480
|
+
totalNumByteSlice: 0,
|
|
481
|
+
totalNumUint: 0,
|
|
482
|
+
minBalance: DEFAULT_ACCOUNT_MIN_BALANCE,
|
|
483
|
+
balance: 0,
|
|
484
|
+
authAddress: Account(),
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
function Account(address) {
|
|
489
|
+
return new AccountCls(address);
|
|
490
|
+
}
|
|
491
|
+
class AccountCls extends BytesBackedCls {
|
|
492
|
+
constructor(address) {
|
|
493
|
+
const addressBytes = address ?? ZERO_ADDRESS;
|
|
494
|
+
if (![32n, 36n].includes(asUint64Cls(addressBytes.length).valueOf())) {
|
|
495
|
+
throw new internal.errors.AvmError('Address must be 32 bytes long, or 36 bytes including checksum');
|
|
496
|
+
}
|
|
497
|
+
super(addressBytes.slice(0, 32));
|
|
498
|
+
}
|
|
499
|
+
get data() {
|
|
500
|
+
return lazyContext.getAccountData(this);
|
|
501
|
+
}
|
|
502
|
+
get balance() {
|
|
503
|
+
return this.data.account.balance;
|
|
504
|
+
}
|
|
505
|
+
get minBalance() {
|
|
506
|
+
return this.data.account.minBalance;
|
|
507
|
+
}
|
|
508
|
+
get authAddress() {
|
|
509
|
+
return this.data.account.authAddress;
|
|
510
|
+
}
|
|
511
|
+
get totalNumUint() {
|
|
512
|
+
return this.data.account.totalNumUint;
|
|
513
|
+
}
|
|
514
|
+
get totalNumByteSlice() {
|
|
515
|
+
return this.data.account.totalNumByteSlice;
|
|
516
|
+
}
|
|
517
|
+
get totalExtraAppPages() {
|
|
518
|
+
return this.data.account.totalExtraAppPages;
|
|
519
|
+
}
|
|
520
|
+
get totalAppsCreated() {
|
|
521
|
+
return this.data.account.totalAppsCreated;
|
|
522
|
+
}
|
|
523
|
+
get totalAppsOptedIn() {
|
|
524
|
+
return this.data.account.totalAppsOptedIn;
|
|
525
|
+
}
|
|
526
|
+
get totalAssetsCreated() {
|
|
527
|
+
return this.data.account.totalAssetsCreated;
|
|
528
|
+
}
|
|
529
|
+
get totalAssets() {
|
|
530
|
+
return this.data.account.totalAssets;
|
|
531
|
+
}
|
|
532
|
+
get totalBoxes() {
|
|
533
|
+
return this.data.account.totalBoxes;
|
|
534
|
+
}
|
|
535
|
+
get totalBoxBytes() {
|
|
536
|
+
return this.data.account.totalBoxBytes;
|
|
537
|
+
}
|
|
538
|
+
isOptedIn(assetOrApp) {
|
|
539
|
+
if (assetOrApp instanceof AssetCls) {
|
|
540
|
+
return this.data.optedAssets.has(assetOrApp.id);
|
|
541
|
+
}
|
|
542
|
+
if (assetOrApp instanceof ApplicationCls) {
|
|
543
|
+
return this.data.optedApplications.has(asUint64Cls(assetOrApp.id).asBigInt());
|
|
544
|
+
}
|
|
545
|
+
throw new internal.errors.InternalError('Invalid argument type. Must be an `Asset` or `Application` instance.');
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
class ApplicationData {
|
|
549
|
+
application;
|
|
550
|
+
isCreating = false;
|
|
551
|
+
get appLogs() {
|
|
552
|
+
return this.application.appLogs;
|
|
553
|
+
}
|
|
554
|
+
constructor() {
|
|
555
|
+
this.application = {
|
|
556
|
+
approvalProgram: ALWAYS_APPROVE_TEAL_PROGRAM,
|
|
557
|
+
clearStateProgram: ALWAYS_APPROVE_TEAL_PROGRAM,
|
|
558
|
+
globalNumUint: 0,
|
|
559
|
+
globalNumBytes: 0,
|
|
560
|
+
localNumUint: 0,
|
|
561
|
+
localNumBytes: 0,
|
|
562
|
+
extraProgramPages: 0,
|
|
563
|
+
creator: lazyContext.defaultSender,
|
|
564
|
+
appLogs: [],
|
|
565
|
+
globalStates: new BytesMap(),
|
|
566
|
+
localStates: new BytesMap(),
|
|
567
|
+
boxes: new BytesMap(),
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
function Application(id) {
|
|
572
|
+
return new ApplicationCls(id);
|
|
573
|
+
}
|
|
574
|
+
class ApplicationCls extends Uint64BackedCls {
|
|
575
|
+
get id() {
|
|
576
|
+
return this.uint64;
|
|
577
|
+
}
|
|
578
|
+
constructor(id) {
|
|
579
|
+
super(asUint64(id ?? 0));
|
|
580
|
+
}
|
|
581
|
+
get data() {
|
|
582
|
+
return lazyContext.getApplicationData(this.id);
|
|
583
|
+
}
|
|
584
|
+
get approvalProgram() {
|
|
585
|
+
return this.data.application.approvalProgram;
|
|
586
|
+
}
|
|
587
|
+
get clearStateProgram() {
|
|
588
|
+
return this.data.application.clearStateProgram;
|
|
589
|
+
}
|
|
590
|
+
get globalNumUint() {
|
|
591
|
+
return this.data.application.globalNumUint;
|
|
592
|
+
}
|
|
593
|
+
get globalNumBytes() {
|
|
594
|
+
return this.data.application.globalNumBytes;
|
|
595
|
+
}
|
|
596
|
+
get localNumUint() {
|
|
597
|
+
return this.data.application.localNumUint;
|
|
598
|
+
}
|
|
599
|
+
get localNumBytes() {
|
|
600
|
+
return this.data.application.localNumBytes;
|
|
601
|
+
}
|
|
602
|
+
get extraProgramPages() {
|
|
603
|
+
return this.data.application.extraProgramPages;
|
|
604
|
+
}
|
|
605
|
+
get creator() {
|
|
606
|
+
return this.data.application.creator;
|
|
607
|
+
}
|
|
608
|
+
get address() {
|
|
609
|
+
return getApplicationAddress(this.id);
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
function Asset(id) {
|
|
613
|
+
return new AssetCls(id);
|
|
614
|
+
}
|
|
615
|
+
class AssetCls extends Uint64BackedCls {
|
|
616
|
+
get id() {
|
|
617
|
+
return this.uint64;
|
|
618
|
+
}
|
|
619
|
+
constructor(id) {
|
|
620
|
+
super(asUint64(id ?? 0));
|
|
621
|
+
}
|
|
622
|
+
get data() {
|
|
623
|
+
return lazyContext.getAssetData(this.id);
|
|
624
|
+
}
|
|
625
|
+
get total() {
|
|
626
|
+
return this.data.total;
|
|
627
|
+
}
|
|
628
|
+
get decimals() {
|
|
629
|
+
return this.data.decimals;
|
|
630
|
+
}
|
|
631
|
+
get defaultFrozen() {
|
|
632
|
+
return this.data.defaultFrozen;
|
|
633
|
+
}
|
|
634
|
+
get unitName() {
|
|
635
|
+
return this.data.unitName;
|
|
636
|
+
}
|
|
637
|
+
get name() {
|
|
638
|
+
return this.data.name;
|
|
639
|
+
}
|
|
640
|
+
get url() {
|
|
641
|
+
return this.data.url;
|
|
642
|
+
}
|
|
643
|
+
get metadataHash() {
|
|
644
|
+
return this.data.metadataHash;
|
|
645
|
+
}
|
|
646
|
+
get manager() {
|
|
647
|
+
return this.data.manager;
|
|
648
|
+
}
|
|
649
|
+
get reserve() {
|
|
650
|
+
return this.data.reserve;
|
|
651
|
+
}
|
|
652
|
+
get freeze() {
|
|
653
|
+
return this.data.freeze;
|
|
654
|
+
}
|
|
655
|
+
get clawback() {
|
|
656
|
+
return this.data.clawback;
|
|
657
|
+
}
|
|
658
|
+
get creator() {
|
|
659
|
+
return this.data.creator;
|
|
660
|
+
}
|
|
661
|
+
balance(account) {
|
|
662
|
+
return this.getAssetHolding(account).balance;
|
|
663
|
+
}
|
|
664
|
+
frozen(account) {
|
|
665
|
+
return this.getAssetHolding(account).frozen;
|
|
666
|
+
}
|
|
667
|
+
getAssetHolding(account) {
|
|
668
|
+
const accountData = lazyContext.getAccountData(account);
|
|
669
|
+
const assetHolding = accountData.optedAssets.get(this.id);
|
|
670
|
+
if (assetHolding === undefined) {
|
|
671
|
+
internal.errors.internalError('The asset is not opted into the account! Use `ctx.any.account(opted_asset_balances={{ASSET_ID: VALUE}})` to set emulated opted asset into the account.');
|
|
672
|
+
}
|
|
673
|
+
return assetHolding;
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
const checksumFromPublicKey = (pk) => {
|
|
677
|
+
return Uint8Array.from(js_sha512.sha512_256.array(pk).slice(HASH_BYTES_LENGTH - ALGORAND_CHECKSUM_BYTE_LENGTH, HASH_BYTES_LENGTH));
|
|
678
|
+
};
|
|
679
|
+
const getApplicationAddress = (appId) => {
|
|
680
|
+
const toBeSigned = conactUint8Arrays(asUint8Array(APP_ID_PREFIX), encodingUtil.bigIntToUint8Array(asBigInt(appId), 8));
|
|
681
|
+
const appIdHash = js_sha512.sha512_256.array(toBeSigned);
|
|
682
|
+
const publicKey = Uint8Array.from(appIdHash);
|
|
683
|
+
const address = encodeAddress(publicKey);
|
|
684
|
+
return Account(Bytes.fromBase32(address));
|
|
685
|
+
};
|
|
686
|
+
const encodeAddress = (address) => {
|
|
687
|
+
const checksum = checksumFromPublicKey(address);
|
|
688
|
+
return encodingUtil.uint8ArrayToBase32(conactUint8Arrays(address, checksum)).slice(0, ALGORAND_ADDRESS_LENGTH);
|
|
689
|
+
};
|
|
690
|
+
|
|
12
691
|
const ABI_LENGTH_SIZE = 2;
|
|
13
692
|
const maxBigIntValue = (bitSize) => 2n ** BigInt(bitSize) - 1n;
|
|
14
693
|
const maxBytesLength = (bitSize) => Math.floor(bitSize / BITS_IN_BYTE);
|
|
@@ -331,7 +1010,7 @@ class StaticArrayImpl extends StaticArray {
|
|
|
331
1010
|
}
|
|
332
1011
|
static getArc4TypeName = (t) => {
|
|
333
1012
|
const genericArgs = t.genericArgs;
|
|
334
|
-
return `${getArc4TypeName
|
|
1013
|
+
return `${getArc4TypeName(genericArgs.elementType)}[${genericArgs.size.name}]`;
|
|
335
1014
|
};
|
|
336
1015
|
}
|
|
337
1016
|
class AddressImpl extends Address {
|
|
@@ -467,7 +1146,7 @@ class DynamicArrayImpl extends DynamicArray {
|
|
|
467
1146
|
}
|
|
468
1147
|
static getArc4TypeName = (t) => {
|
|
469
1148
|
const genericArgs = t.genericArgs;
|
|
470
|
-
return `${getArc4TypeName
|
|
1149
|
+
return `${getArc4TypeName(genericArgs.elementType)}[]`;
|
|
471
1150
|
};
|
|
472
1151
|
encodeWithLength(items) {
|
|
473
1152
|
return conactUint8Arrays(encodeLength(items.length).asUint8Array(), encode(items));
|
|
@@ -550,7 +1229,7 @@ class TupleImpl extends Tuple {
|
|
|
550
1229
|
}
|
|
551
1230
|
static getArc4TypeName = (t) => {
|
|
552
1231
|
const genericArgs = Object.values(t.genericArgs);
|
|
553
|
-
return `(${genericArgs.map(getArc4TypeName
|
|
1232
|
+
return `(${genericArgs.map(getArc4TypeName).join(',')})`;
|
|
554
1233
|
};
|
|
555
1234
|
}
|
|
556
1235
|
class StructImpl extends Struct {
|
|
@@ -618,7 +1297,7 @@ class StructImpl extends Struct {
|
|
|
618
1297
|
}
|
|
619
1298
|
static getArc4TypeName = (t) => {
|
|
620
1299
|
const genericArgs = Object.values(t.genericArgs);
|
|
621
|
-
return `(${genericArgs.map(getArc4TypeName
|
|
1300
|
+
return `(${genericArgs.map(getArc4TypeName).join(',')})`;
|
|
622
1301
|
};
|
|
623
1302
|
}
|
|
624
1303
|
class DynamicBytesImpl extends DynamicBytes {
|
|
@@ -942,7 +1621,7 @@ const getArc4Encoder = (typeInfo, encoders) => {
|
|
|
942
1621
|
}
|
|
943
1622
|
return encoder;
|
|
944
1623
|
};
|
|
945
|
-
const getArc4TypeName
|
|
1624
|
+
const getArc4TypeName = (typeInfo) => {
|
|
946
1625
|
const map = {
|
|
947
1626
|
Address: 'address',
|
|
948
1627
|
Bool: 'bool',
|
|
@@ -1042,520 +1721,9 @@ const getArc4Encoded = (value) => {
|
|
|
1042
1721
|
}
|
|
1043
1722
|
throw internal.errors.codeError(`Unsupported type for encoding: ${typeof value}`);
|
|
1044
1723
|
};
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
const isContractProxy = Symbol('isContractProxy');
|
|
1048
|
-
const attachAbiMetadata = (contract, methodName, metadata) => {
|
|
1049
|
-
const metadatas = (AbiMetaSymbol in contract ? contract[AbiMetaSymbol] : {});
|
|
1050
|
-
metadatas[methodName] = metadata;
|
|
1051
|
-
if (!(AbiMetaSymbol in contract)) {
|
|
1052
|
-
Object.defineProperty(contract, AbiMetaSymbol, {
|
|
1053
|
-
value: metadatas,
|
|
1054
|
-
writable: true,
|
|
1055
|
-
enumerable: false,
|
|
1056
|
-
});
|
|
1057
|
-
}
|
|
1058
|
-
};
|
|
1059
|
-
const copyAbiMetadatas = (sourceContract, targetContract) => {
|
|
1060
|
-
const metadatas = getContractAbiMetadata(sourceContract);
|
|
1061
|
-
Object.defineProperty(targetContract, AbiMetaSymbol, {
|
|
1062
|
-
value: metadatas,
|
|
1063
|
-
writable: true,
|
|
1064
|
-
enumerable: false,
|
|
1065
|
-
});
|
|
1066
|
-
};
|
|
1067
|
-
const captureMethodConfig = (contract, methodName, config) => {
|
|
1068
|
-
const metadata = getContractMethodAbiMetadata(contract, methodName);
|
|
1069
|
-
metadata.onCreate = config?.onCreate ?? 'disallow';
|
|
1070
|
-
metadata.allowActions = [].concat(config?.allowActions ?? 'NoOp');
|
|
1071
|
-
};
|
|
1072
|
-
const getContractAbiMetadata = (contract) => {
|
|
1073
|
-
if (contract[isContractProxy]) {
|
|
1074
|
-
return contract[AbiMetaSymbol];
|
|
1075
|
-
}
|
|
1076
|
-
const contractClass = contract.constructor;
|
|
1077
|
-
const s = Object.getOwnPropertySymbols(contractClass).find((s) => s.toString() === AbiMetaSymbol.toString());
|
|
1078
|
-
const metadatas = (s ? contractClass[s] : AbiMetaSymbol in contractClass ? contractClass[AbiMetaSymbol] : {});
|
|
1079
|
-
return metadatas;
|
|
1080
|
-
};
|
|
1081
|
-
const getContractMethodAbiMetadata = (contract, methodName) => {
|
|
1082
|
-
const metadatas = getContractAbiMetadata(contract);
|
|
1083
|
-
return metadatas[methodName];
|
|
1084
|
-
};
|
|
1085
|
-
const getArc4Signature = (metadata) => {
|
|
1086
|
-
if (metadata.methodSignature === undefined) {
|
|
1087
|
-
const argTypes = metadata.argTypes.map((t) => JSON.parse(t)).map(getArc4TypeName);
|
|
1088
|
-
const returnType = getArc4TypeName(JSON.parse(metadata.returnType));
|
|
1089
|
-
metadata.methodSignature = `${metadata.methodName}(${argTypes.join(',')})${returnType}`;
|
|
1090
|
-
}
|
|
1091
|
-
return metadata.methodSignature;
|
|
1092
|
-
};
|
|
1093
|
-
const getArc4Selector = (metadata) => {
|
|
1094
|
-
const hash = js_sha512.sha512_256.array(getArc4Signature(metadata));
|
|
1095
|
-
return new Uint8Array(hash.slice(0, 4));
|
|
1096
|
-
};
|
|
1097
|
-
const getArc4TypeName = (t) => {
|
|
1098
|
-
const map = {
|
|
1099
|
-
void: 'void',
|
|
1100
|
-
account: 'account',
|
|
1101
|
-
application: 'application',
|
|
1102
|
-
asset: 'asset',
|
|
1103
|
-
boolean: 'bool',
|
|
1104
|
-
biguint: 'uint512',
|
|
1105
|
-
bytes: 'byte[]',
|
|
1106
|
-
string: 'string',
|
|
1107
|
-
uint64: 'uint64',
|
|
1108
|
-
OnCompleteAction: 'uint64',
|
|
1109
|
-
TransactionType: 'uint64',
|
|
1110
|
-
Transaction: 'txn',
|
|
1111
|
-
PaymentTxn: 'pay',
|
|
1112
|
-
KeyRegistrationTxn: 'keyreg',
|
|
1113
|
-
AssetConfigTxn: 'acfg',
|
|
1114
|
-
AssetTransferTxn: 'axfer',
|
|
1115
|
-
AssetFreezeTxn: 'afrz',
|
|
1116
|
-
ApplicationTxn: 'appl',
|
|
1117
|
-
'Tuple(<.*>)?': (t) => `(${Object.values(t.genericArgs)
|
|
1118
|
-
.map(getArc4TypeName)
|
|
1119
|
-
.join(',')})`,
|
|
1120
|
-
};
|
|
1121
|
-
const entry = Object.entries(map).find(([k, _]) => new RegExp(`^${k}$`, 'i').test(t.name))?.[1];
|
|
1122
|
-
if (entry === undefined) {
|
|
1123
|
-
return getArc4TypeName$1(t) ?? t.name;
|
|
1124
|
-
}
|
|
1125
|
-
if (entry instanceof Function) {
|
|
1126
|
-
return entry(t);
|
|
1127
|
-
}
|
|
1128
|
-
return entry;
|
|
1129
|
-
};
|
|
1130
|
-
|
|
1131
|
-
class NotImplementedError extends Error {
|
|
1132
|
-
constructor(feature) {
|
|
1133
|
-
super(`${feature} is not available in test context. Mock using your preferred testing framework.`);
|
|
1134
|
-
}
|
|
1135
|
-
}
|
|
1136
|
-
function notImplementedError(feature) {
|
|
1137
|
-
throw new NotImplementedError(feature);
|
|
1138
|
-
}
|
|
1139
|
-
function testInvariant(condition, message) {
|
|
1140
|
-
if (!condition) {
|
|
1141
|
-
throw new internal.errors.InternalError(message);
|
|
1142
|
-
}
|
|
1143
|
-
}
|
|
1144
|
-
|
|
1145
|
-
const sha256 = (a) => {
|
|
1146
|
-
const bytesA = internal.primitives.BytesCls.fromCompat(a);
|
|
1147
|
-
const hashArray = js_sha256.sha256.create().update(bytesA.asUint8Array()).digest();
|
|
1148
|
-
const hashBytes = internal.primitives.BytesCls.fromCompat(new Uint8Array(hashArray));
|
|
1149
|
-
return hashBytes.asAlgoTs();
|
|
1150
|
-
};
|
|
1151
|
-
const sha3_256 = (a) => {
|
|
1152
|
-
const bytesA = internal.primitives.BytesCls.fromCompat(a);
|
|
1153
|
-
const hashArray = js_sha3.sha3_256.create().update(bytesA.asUint8Array()).digest();
|
|
1154
|
-
const hashBytes = internal.primitives.BytesCls.fromCompat(new Uint8Array(hashArray));
|
|
1155
|
-
return hashBytes.asAlgoTs();
|
|
1156
|
-
};
|
|
1157
|
-
const keccak256 = (a) => {
|
|
1158
|
-
const bytesA = internal.primitives.BytesCls.fromCompat(a);
|
|
1159
|
-
const hashArray = js_sha3.keccak256.create().update(bytesA.asUint8Array()).digest();
|
|
1160
|
-
const hashBytes = internal.primitives.BytesCls.fromCompat(new Uint8Array(hashArray));
|
|
1161
|
-
return hashBytes.asAlgoTs();
|
|
1162
|
-
};
|
|
1163
|
-
const sha512_256 = (a) => {
|
|
1164
|
-
const bytesA = internal.primitives.BytesCls.fromCompat(a);
|
|
1165
|
-
const hashArray = js_sha512.sha512_256.create().update(bytesA.asUint8Array()).digest();
|
|
1166
|
-
const hashBytes = internal.primitives.BytesCls.fromCompat(new Uint8Array(hashArray));
|
|
1167
|
-
return hashBytes.asAlgoTs();
|
|
1168
|
-
};
|
|
1169
|
-
const ed25519verifyBare = (a, b, c) => {
|
|
1170
|
-
const bytesA = internal.primitives.BytesCls.fromCompat(a);
|
|
1171
|
-
const bytesB = internal.primitives.BytesCls.fromCompat(b);
|
|
1172
|
-
const bytesC = internal.primitives.BytesCls.fromCompat(c);
|
|
1173
|
-
return nacl.sign.detached.verify(bytesA.asUint8Array(), bytesB.asUint8Array(), bytesC.asUint8Array());
|
|
1174
|
-
};
|
|
1175
|
-
const ed25519verify = (a, b, c) => {
|
|
1176
|
-
const txn = lazyContext.activeGroup.activeTransaction;
|
|
1177
|
-
const programBytes = asBytesCls(txn.onCompletion == arc4.OnCompleteAction[arc4.OnCompleteAction.ClearState] ? txn.clearStateProgram : txn.approvalProgram);
|
|
1178
|
-
const logicSig = conactUint8Arrays(asUint8Array(PROGRAM_TAG), programBytes.asUint8Array());
|
|
1179
|
-
const logicSigAddress = js_sha512.sha512_256.array(logicSig);
|
|
1180
|
-
const addressBytes = Bytes(logicSigAddress);
|
|
1181
|
-
const data = LOGIC_DATA_PREFIX.concat(addressBytes).concat(asBytes(a));
|
|
1182
|
-
return ed25519verifyBare(data, b, c);
|
|
1183
|
-
};
|
|
1184
|
-
const ecdsaVerify = (v, a, b, c, d, e) => {
|
|
1185
|
-
const dataBytes = internal.primitives.BytesCls.fromCompat(a);
|
|
1186
|
-
const sigRBytes = internal.primitives.BytesCls.fromCompat(b);
|
|
1187
|
-
const sigSBytes = internal.primitives.BytesCls.fromCompat(c);
|
|
1188
|
-
const pubkeyXBytes = internal.primitives.BytesCls.fromCompat(d);
|
|
1189
|
-
const pubkeyYBytes = internal.primitives.BytesCls.fromCompat(e);
|
|
1190
|
-
const publicKey = internal.primitives.BytesCls.fromCompat(new Uint8Array([0x04]))
|
|
1191
|
-
.concat(pubkeyXBytes)
|
|
1192
|
-
.concat(pubkeyYBytes);
|
|
1193
|
-
const ecdsa = new elliptic.ec(curveMap[v]);
|
|
1194
|
-
const keyPair = ecdsa.keyFromPublic(publicKey.asUint8Array());
|
|
1195
|
-
return keyPair.verify(dataBytes.asUint8Array(), { r: sigRBytes.asUint8Array(), s: sigSBytes.asUint8Array() });
|
|
1196
|
-
};
|
|
1197
|
-
const ecdsaPkRecover = (v, a, b, c, d) => {
|
|
1198
|
-
if (v !== Ecdsa.Secp256k1) {
|
|
1199
|
-
internal.errors.internalError(`Unsupported ECDSA curve: ${v}`);
|
|
1200
|
-
}
|
|
1201
|
-
const dataBytes = internal.primitives.BytesCls.fromCompat(a);
|
|
1202
|
-
const rBytes = internal.primitives.BytesCls.fromCompat(c);
|
|
1203
|
-
const sBytes = internal.primitives.BytesCls.fromCompat(d);
|
|
1204
|
-
const recoveryId = internal.primitives.Uint64Cls.fromCompat(b);
|
|
1205
|
-
const ecdsa = new elliptic.ec(curveMap[v]);
|
|
1206
|
-
const pubKey = ecdsa.recoverPubKey(dataBytes.asUint8Array(), { r: rBytes.asUint8Array(), s: sBytes.asUint8Array() }, recoveryId.asNumber());
|
|
1207
|
-
const x = pubKey.getX().toArray('be');
|
|
1208
|
-
const y = pubKey.getY().toArray('be');
|
|
1209
|
-
return [Bytes(x), Bytes(y)];
|
|
1210
|
-
};
|
|
1211
|
-
const ecdsaPkDecompress = (v, a) => {
|
|
1212
|
-
const bytesA = internal.primitives.BytesCls.fromCompat(a);
|
|
1213
|
-
const ecdsa = new elliptic.ec(curveMap[v]);
|
|
1214
|
-
const keyPair = ecdsa.keyFromPublic(bytesA.asUint8Array());
|
|
1215
|
-
const pubKey = keyPair.getPublic();
|
|
1216
|
-
const x = pubKey.getX().toArray('be');
|
|
1217
|
-
const y = pubKey.getY().toArray('be');
|
|
1218
|
-
return [Bytes(new Uint8Array(x)), Bytes(new Uint8Array(y))];
|
|
1219
|
-
};
|
|
1220
|
-
const vrfVerify = (_s, _a, _b, _c) => {
|
|
1221
|
-
notImplementedError('vrfVerify');
|
|
1222
|
-
};
|
|
1223
|
-
const EllipticCurve = new Proxy({}, {
|
|
1224
|
-
get: (_target, prop) => {
|
|
1225
|
-
notImplementedError(`EllipticCurve.${prop.toString()}`);
|
|
1226
|
-
},
|
|
1227
|
-
});
|
|
1228
|
-
const mimc = (_c, _a) => {
|
|
1229
|
-
notImplementedError('mimc');
|
|
1230
|
-
};
|
|
1231
|
-
const curveMap = {
|
|
1232
|
-
[Ecdsa.Secp256k1]: 'secp256k1',
|
|
1233
|
-
[Ecdsa.Secp256r1]: 'p256',
|
|
1724
|
+
const methodSelector = (methodSignature) => {
|
|
1725
|
+
return sha512_256(Bytes(encodingUtil.utf8ToUint8Array(methodSignature))).slice(0, 4);
|
|
1234
1726
|
};
|
|
1235
1727
|
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
let eventName;
|
|
1239
|
-
if (typeof event === 'string') {
|
|
1240
|
-
eventData = getArc4Encoded(eventProps);
|
|
1241
|
-
eventName = event;
|
|
1242
|
-
const argTypes = getArc4TypeName$1(eventData.typeInfo);
|
|
1243
|
-
if (eventName.indexOf('(') === -1) {
|
|
1244
|
-
eventName += argTypes;
|
|
1245
|
-
}
|
|
1246
|
-
else if (event.indexOf(argTypes) === -1) {
|
|
1247
|
-
throw internal.errors.codeError(`Event signature ${event} does not match arg types ${argTypes}`);
|
|
1248
|
-
}
|
|
1249
|
-
}
|
|
1250
|
-
else {
|
|
1251
|
-
eventData = getArc4Encoded(event);
|
|
1252
|
-
const typeInfo = JSON.parse(typeInfoString);
|
|
1253
|
-
const argTypes = getArc4TypeName$1(eventData.typeInfo);
|
|
1254
|
-
eventName = typeInfo.name.replace(/.*</, '').replace(/>.*/, '') + argTypes;
|
|
1255
|
-
}
|
|
1256
|
-
const eventHash = sha512_256(eventName);
|
|
1257
|
-
log(eventHash.slice(0, 4).concat(eventData.bytes));
|
|
1258
|
-
}
|
|
1259
|
-
|
|
1260
|
-
function switchableValue(x) {
|
|
1261
|
-
if (typeof x === 'boolean')
|
|
1262
|
-
return x;
|
|
1263
|
-
if (typeof x === 'bigint')
|
|
1264
|
-
return x;
|
|
1265
|
-
if (typeof x === 'string')
|
|
1266
|
-
return x;
|
|
1267
|
-
if (x instanceof internal.primitives.AlgoTsPrimitiveCls)
|
|
1268
|
-
return x.valueOf();
|
|
1269
|
-
internal.errors.internalError(`Cannot convert ${nameOfType(x)} to switchable value`);
|
|
1270
|
-
}
|
|
1271
|
-
function tryGetBigInt(value) {
|
|
1272
|
-
if (typeof value == 'bigint')
|
|
1273
|
-
return value;
|
|
1274
|
-
if (typeof value == 'number' && Number.isInteger(value))
|
|
1275
|
-
return BigInt(value);
|
|
1276
|
-
if (value instanceof internal.primitives.Uint64Cls)
|
|
1277
|
-
return value.valueOf();
|
|
1278
|
-
if (value instanceof internal.primitives.BigUintCls)
|
|
1279
|
-
return value.valueOf();
|
|
1280
|
-
return undefined;
|
|
1281
|
-
}
|
|
1282
|
-
function binaryOp(left, right, op) {
|
|
1283
|
-
if (left instanceof ARC4Encoded && right instanceof ARC4Encoded) {
|
|
1284
|
-
return arc4EncodedOp(left, right, op);
|
|
1285
|
-
}
|
|
1286
|
-
if (left instanceof AccountCls && right instanceof AccountCls) {
|
|
1287
|
-
return accountBinaryOp(left, right, op);
|
|
1288
|
-
}
|
|
1289
|
-
if (left instanceof Uint64BackedCls && right instanceof Uint64BackedCls) {
|
|
1290
|
-
return uint64BackedClsBinaryOp(left, right, op);
|
|
1291
|
-
}
|
|
1292
|
-
if (left instanceof internal.primitives.BigUintCls || right instanceof internal.primitives.BigUintCls) {
|
|
1293
|
-
return bigUintBinaryOp(left, right, op);
|
|
1294
|
-
}
|
|
1295
|
-
if (left instanceof internal.primitives.Uint64Cls || right instanceof internal.primitives.Uint64Cls) {
|
|
1296
|
-
return uint64BinaryOp(left, right, op);
|
|
1297
|
-
}
|
|
1298
|
-
if (left instanceof internal.primitives.BytesCls || right instanceof internal.primitives.BytesCls) {
|
|
1299
|
-
return bytesBinaryOp(left, right, op);
|
|
1300
|
-
}
|
|
1301
|
-
const lbi = tryGetBigInt(left);
|
|
1302
|
-
const rbi = tryGetBigInt(right);
|
|
1303
|
-
if (lbi !== undefined && rbi !== undefined) {
|
|
1304
|
-
const result = defaultBinaryOp(lbi, rbi, op);
|
|
1305
|
-
if (typeof result === 'boolean') {
|
|
1306
|
-
return result;
|
|
1307
|
-
}
|
|
1308
|
-
if (typeof left === 'number' && typeof right === 'number' && result <= Number.MAX_SAFE_INTEGER) {
|
|
1309
|
-
return Number(result);
|
|
1310
|
-
}
|
|
1311
|
-
return result;
|
|
1312
|
-
}
|
|
1313
|
-
return defaultBinaryOp(left, right, op);
|
|
1314
|
-
}
|
|
1315
|
-
function unaryOp(operand, op) {
|
|
1316
|
-
if (operand instanceof internal.primitives.Uint64Cls) {
|
|
1317
|
-
return uint64UnaryOp(operand, op);
|
|
1318
|
-
}
|
|
1319
|
-
return defaultUnaryOp(operand, op);
|
|
1320
|
-
}
|
|
1321
|
-
function arc4EncodedOp(left, right, op) {
|
|
1322
|
-
const hasEqualsMethod = (x) => Object.hasOwn(x, 'equals') && typeof x.equals === 'function';
|
|
1323
|
-
const compareEquality = (x, y) => hasEqualsMethod(x) ? x.equals(y) : y.equals(x);
|
|
1324
|
-
switch (op) {
|
|
1325
|
-
case '===':
|
|
1326
|
-
return compareEquality(left, right);
|
|
1327
|
-
case '!==':
|
|
1328
|
-
return !compareEquality(left, right);
|
|
1329
|
-
default:
|
|
1330
|
-
internal.errors.internalError(`Unsupported operator ${op}`);
|
|
1331
|
-
}
|
|
1332
|
-
}
|
|
1333
|
-
function accountBinaryOp(left, right, op) {
|
|
1334
|
-
switch (op) {
|
|
1335
|
-
case '===':
|
|
1336
|
-
case '!==':
|
|
1337
|
-
return bytesBinaryOp(left.bytes, right.bytes, op);
|
|
1338
|
-
default:
|
|
1339
|
-
internal.errors.internalError(`Unsupported operator ${op}`);
|
|
1340
|
-
}
|
|
1341
|
-
}
|
|
1342
|
-
function uint64BackedClsBinaryOp(left, right, op) {
|
|
1343
|
-
switch (op) {
|
|
1344
|
-
case '===':
|
|
1345
|
-
case '!==':
|
|
1346
|
-
return uint64BinaryOp(left.uint64, right.uint64, op);
|
|
1347
|
-
default:
|
|
1348
|
-
internal.errors.internalError(`Unsupported operator ${op}`);
|
|
1349
|
-
}
|
|
1350
|
-
}
|
|
1351
|
-
function uint64BinaryOp(left, right, op) {
|
|
1352
|
-
const lbi = internal.primitives.Uint64Cls.fromCompat(left).valueOf();
|
|
1353
|
-
const rbi = internal.primitives.Uint64Cls.fromCompat(right).valueOf();
|
|
1354
|
-
const result = (function () {
|
|
1355
|
-
switch (op) {
|
|
1356
|
-
case '+':
|
|
1357
|
-
return lbi + rbi;
|
|
1358
|
-
case '-':
|
|
1359
|
-
return lbi - rbi;
|
|
1360
|
-
case '*':
|
|
1361
|
-
return lbi * rbi;
|
|
1362
|
-
case '**':
|
|
1363
|
-
if (lbi === 0n && rbi === 0n) {
|
|
1364
|
-
throw internal.errors.codeError('0 ** 0 is undefined');
|
|
1365
|
-
}
|
|
1366
|
-
return lbi ** rbi;
|
|
1367
|
-
case '/':
|
|
1368
|
-
return lbi / rbi;
|
|
1369
|
-
case '%':
|
|
1370
|
-
return lbi % rbi;
|
|
1371
|
-
case '>>':
|
|
1372
|
-
if (rbi > 63n) {
|
|
1373
|
-
throw new internal.errors.CodeError('expected shift <= 63');
|
|
1374
|
-
}
|
|
1375
|
-
return (lbi >> rbi) & MAX_UINT64;
|
|
1376
|
-
case '<<':
|
|
1377
|
-
if (rbi > 63n) {
|
|
1378
|
-
throw new internal.errors.CodeError('expected shift <= 63');
|
|
1379
|
-
}
|
|
1380
|
-
return (lbi << rbi) & MAX_UINT64;
|
|
1381
|
-
case '>':
|
|
1382
|
-
return lbi > rbi;
|
|
1383
|
-
case '<':
|
|
1384
|
-
return lbi < rbi;
|
|
1385
|
-
case '>=':
|
|
1386
|
-
return lbi >= rbi;
|
|
1387
|
-
case '<=':
|
|
1388
|
-
return lbi <= rbi;
|
|
1389
|
-
case '===':
|
|
1390
|
-
return lbi === rbi;
|
|
1391
|
-
case '!==':
|
|
1392
|
-
return lbi !== rbi;
|
|
1393
|
-
case '&':
|
|
1394
|
-
return lbi & rbi;
|
|
1395
|
-
case '|':
|
|
1396
|
-
return lbi | rbi;
|
|
1397
|
-
case '^':
|
|
1398
|
-
return lbi ^ rbi;
|
|
1399
|
-
default:
|
|
1400
|
-
internal.errors.internalError(`Unsupported operator ${op}`);
|
|
1401
|
-
}
|
|
1402
|
-
})();
|
|
1403
|
-
return typeof result === 'boolean' ? result : new internal.primitives.Uint64Cls(result);
|
|
1404
|
-
}
|
|
1405
|
-
function bigUintBinaryOp(left, right, op) {
|
|
1406
|
-
const lbi = internal.primitives.checkBigUint(internal.primitives.BigUintCls.fromCompat(left).valueOf());
|
|
1407
|
-
const rbi = internal.primitives.checkBigUint(internal.primitives.BigUintCls.fromCompat(right).valueOf());
|
|
1408
|
-
const result = (function () {
|
|
1409
|
-
switch (op) {
|
|
1410
|
-
case '+':
|
|
1411
|
-
return lbi + rbi;
|
|
1412
|
-
case '-':
|
|
1413
|
-
return lbi - rbi;
|
|
1414
|
-
case '*':
|
|
1415
|
-
return lbi * rbi;
|
|
1416
|
-
case '**':
|
|
1417
|
-
if (lbi === 0n && rbi === 0n) {
|
|
1418
|
-
throw internal.errors.codeError('0 ** 0 is undefined');
|
|
1419
|
-
}
|
|
1420
|
-
return lbi ** rbi;
|
|
1421
|
-
case '/':
|
|
1422
|
-
return lbi / rbi;
|
|
1423
|
-
case '%':
|
|
1424
|
-
return lbi % rbi;
|
|
1425
|
-
case '>>':
|
|
1426
|
-
throw new internal.errors.CodeError('BigUint does not support >> operator');
|
|
1427
|
-
case '<<':
|
|
1428
|
-
throw new internal.errors.CodeError('BigUint does not support << operator');
|
|
1429
|
-
case '>':
|
|
1430
|
-
return lbi > rbi;
|
|
1431
|
-
case '<':
|
|
1432
|
-
return lbi < rbi;
|
|
1433
|
-
case '>=':
|
|
1434
|
-
return lbi >= rbi;
|
|
1435
|
-
case '<=':
|
|
1436
|
-
return lbi <= rbi;
|
|
1437
|
-
case '===':
|
|
1438
|
-
return lbi === rbi;
|
|
1439
|
-
case '!==':
|
|
1440
|
-
return lbi !== rbi;
|
|
1441
|
-
case '&':
|
|
1442
|
-
return lbi & rbi;
|
|
1443
|
-
case '|':
|
|
1444
|
-
return lbi | rbi;
|
|
1445
|
-
case '^':
|
|
1446
|
-
return lbi ^ rbi;
|
|
1447
|
-
default:
|
|
1448
|
-
internal.errors.internalError(`Unsupported operator ${op}`);
|
|
1449
|
-
}
|
|
1450
|
-
})();
|
|
1451
|
-
if (typeof result === 'boolean') {
|
|
1452
|
-
return result;
|
|
1453
|
-
}
|
|
1454
|
-
if (result < 0) {
|
|
1455
|
-
internal.errors.avmError('BigUint underflow');
|
|
1456
|
-
}
|
|
1457
|
-
return new internal.primitives.BigUintCls(result);
|
|
1458
|
-
}
|
|
1459
|
-
function bytesBinaryOp(left, right, op) {
|
|
1460
|
-
const lbb = internal.primitives.checkBytes(internal.primitives.BytesCls.fromCompat(left).asUint8Array());
|
|
1461
|
-
const rbb = internal.primitives.checkBytes(internal.primitives.BytesCls.fromCompat(right).asUint8Array());
|
|
1462
|
-
const lbi = internal.encodingUtil.uint8ArrayToBigInt(lbb);
|
|
1463
|
-
const rbi = internal.encodingUtil.uint8ArrayToBigInt(rbb);
|
|
1464
|
-
const result = (function () {
|
|
1465
|
-
switch (op) {
|
|
1466
|
-
case '>':
|
|
1467
|
-
return lbi > rbi;
|
|
1468
|
-
case '<':
|
|
1469
|
-
return lbi < rbi;
|
|
1470
|
-
case '>=':
|
|
1471
|
-
return lbi >= rbi;
|
|
1472
|
-
case '<=':
|
|
1473
|
-
return lbi <= rbi;
|
|
1474
|
-
case '===':
|
|
1475
|
-
return lbi === rbi;
|
|
1476
|
-
case '!==':
|
|
1477
|
-
return lbi !== rbi;
|
|
1478
|
-
default:
|
|
1479
|
-
internal.errors.internalError(`Unsupported operator ${op}`);
|
|
1480
|
-
}
|
|
1481
|
-
})();
|
|
1482
|
-
return result;
|
|
1483
|
-
}
|
|
1484
|
-
function defaultBinaryOp(left, right, op) {
|
|
1485
|
-
switch (op) {
|
|
1486
|
-
case '+':
|
|
1487
|
-
return left + right;
|
|
1488
|
-
case '-':
|
|
1489
|
-
return left - right;
|
|
1490
|
-
case '*':
|
|
1491
|
-
return left * right;
|
|
1492
|
-
case '**':
|
|
1493
|
-
if (left === 0n && right === 0n) {
|
|
1494
|
-
throw new internal.errors.CodeError('0 ** 0 is undefined');
|
|
1495
|
-
}
|
|
1496
|
-
return left ** right;
|
|
1497
|
-
case '/':
|
|
1498
|
-
return left / right;
|
|
1499
|
-
case '%':
|
|
1500
|
-
return left % right;
|
|
1501
|
-
case '>>':
|
|
1502
|
-
if (typeof left === 'bigint' && typeof right === 'bigint') {
|
|
1503
|
-
if (right > 63n) {
|
|
1504
|
-
throw new internal.errors.CodeError('expected shift <= 63');
|
|
1505
|
-
}
|
|
1506
|
-
return (left >> right) & MAX_UINT64;
|
|
1507
|
-
}
|
|
1508
|
-
return left >> right;
|
|
1509
|
-
case '<<':
|
|
1510
|
-
if (typeof left === 'bigint' && typeof right === 'bigint') {
|
|
1511
|
-
if (right > 63n) {
|
|
1512
|
-
throw new internal.errors.CodeError('expected shift <= 63');
|
|
1513
|
-
}
|
|
1514
|
-
return (left << right) & MAX_UINT64;
|
|
1515
|
-
}
|
|
1516
|
-
return left << right;
|
|
1517
|
-
case '>':
|
|
1518
|
-
return left > right;
|
|
1519
|
-
case '<':
|
|
1520
|
-
return left < right;
|
|
1521
|
-
case '>=':
|
|
1522
|
-
return left >= right;
|
|
1523
|
-
case '<=':
|
|
1524
|
-
return left <= right;
|
|
1525
|
-
case '===':
|
|
1526
|
-
return left === right;
|
|
1527
|
-
case '!==':
|
|
1528
|
-
return left !== right;
|
|
1529
|
-
case '&':
|
|
1530
|
-
return left & right;
|
|
1531
|
-
case '|':
|
|
1532
|
-
return left | right;
|
|
1533
|
-
case '^':
|
|
1534
|
-
return left ^ right;
|
|
1535
|
-
default:
|
|
1536
|
-
internal.errors.internalError(`Unsupported operator ${op}`);
|
|
1537
|
-
}
|
|
1538
|
-
}
|
|
1539
|
-
function uint64UnaryOp(operand, op) {
|
|
1540
|
-
const obi = internal.primitives.Uint64Cls.fromCompat(operand).valueOf();
|
|
1541
|
-
switch (op) {
|
|
1542
|
-
case '~':
|
|
1543
|
-
return ~obi & MAX_UINT64;
|
|
1544
|
-
default:
|
|
1545
|
-
internal.errors.internalError(`Unsupported operator ${op}`);
|
|
1546
|
-
}
|
|
1547
|
-
}
|
|
1548
|
-
function defaultUnaryOp(_operand, op) {
|
|
1549
|
-
internal.errors.internalError(`Unsupported operator ${op}`);
|
|
1550
|
-
}
|
|
1551
|
-
const genericTypeMap = new WeakMap();
|
|
1552
|
-
function captureGenericTypeInfo(target, t) {
|
|
1553
|
-
genericTypeMap.set(target, JSON.parse(t));
|
|
1554
|
-
return target;
|
|
1555
|
-
}
|
|
1556
|
-
function getGenericTypeInfo(target) {
|
|
1557
|
-
return genericTypeMap.get(target);
|
|
1558
|
-
}
|
|
1559
|
-
|
|
1560
|
-
export { AddressImpl as A, captureGenericTypeInfo as B, attachAbiMetadata as C, DynamicBytesImpl as D, EllipticCurve as E, emitImpl as F, decodeArc4Impl as G, UFixedNxMImpl as H, ByteImpl as I, BoolImpl as J, StaticArrayImpl as K, DynamicArrayImpl as L, StructImpl as M, StaticBytesImpl as N, interpretAsArc4Impl as O, getArc4TypeName$1 as P, getArc4Encoded as Q, StrImpl as S, TupleImpl as T, UintNImpl as U, arc4Encoders as a, ecdsaPkDecompress as b, ecdsaPkRecover as c, ecdsaVerify as d, encodeArc4Impl as e, ed25519verify as f, getArc4Encoder as g, ed25519verifyBare as h, sha3_256 as i, sha512_256 as j, keccak256 as k, getGenericTypeInfo as l, mimc as m, notImplementedError as n, getArc4Selector as o, isContractProxy as p, getContractMethodAbiMetadata as q, copyAbiMetadatas as r, sha256 as s, testInvariant as t, getContractAbiMetadata as u, vrfVerify as v, captureMethodConfig as w, switchableValue as x, binaryOp as y, unaryOp as z };
|
|
1561
|
-
//# sourceMappingURL=runtime-helpers-C6O92q80.js.map
|
|
1728
|
+
export { getArc4Encoded as $, AccountCls as A, BytesMap as B, MAX_UINT16 as C, MAX_UINT32 as D, MAX_UINT128 as E, MAX_UINT256 as F, MAX_UINT512 as G, DynamicBytesImpl as H, BITS_IN_BYTE as I, DEFAULT_TEMPLATE_VAR_PREFIX as J, asBytes as K, BytesBackedCls as L, MAX_UINT64 as M, Uint64BackedCls as N, asMaybeBigUintCls as O, combineIntoMaxBytePages as P, MAX_ITEMS_IN_LOG as Q, asUint8Array as R, StrImpl as S, TRANSACTION_GROUP_MAX_SIZE as T, Uint64Map as U, asBytesCls as V, MAX_BOX_SIZE as W, conactUint8Arrays as X, getArc4TypeName as Y, ZERO_ADDRESS as Z, nameOfType as _, ApplicationCls as a, sha512_256 as a0, decodeArc4Impl as a1, encodeArc4Impl as a2, UFixedNxMImpl as a3, ByteImpl as a4, BoolImpl as a5, StaticArrayImpl as a6, DynamicArrayImpl as a7, TupleImpl as a8, StructImpl as a9, UINT64_SIZE as aA, notImplementedError as aB, StaticBytesImpl as aa, interpretAsArc4Impl as ab, arc4Encoders as ac, getArc4Encoder as ad, methodSelector as ae, EllipticCurve as af, ecdsaPkDecompress as ag, ecdsaPkRecover as ah, ecdsaVerify as ai, ed25519verify as aj, ed25519verifyBare as ak, keccak256 as al, mimc as am, sha256 as an, sha3_256 as ao, vrfVerify as ap, getObjectReference as aq, getApplicationAddress as ar, MIN_TXN_FEE as as, DEFAULT_ACCOUNT_MIN_BALANCE as at, DEFAULT_MAX_TXN_LIFE as au, DEFAULT_ASSET_CREATE_MIN_BALANCE as av, DEFAULT_ASSET_OPT_IN_MIN_BALANCE as aw, DEFAULT_GLOBAL_GENESIS_HASH as ax, asBigUint as ay, binaryStringToBytes as az, AssetCls as b, AccountMap as c, Account as d, Asset as e, asUint64 as f, Application as g, asMaybeUint64Cls as h, iterBigInt as i, asUint64Cls as j, AssetHolding as k, lazyContext as l, AccountData as m, asBigInt as n, asMaybeBytesCls as o, asNumber as p, ABI_RETURN_VALUE_LOG_PREFIX as q, getRandomBigInt as r, MAX_BYTES_SIZE as s, testInvariant as t, getRandomBytes as u, ApplicationData as v, AddressImpl as w, UintNImpl as x, getRandomNumber as y, MAX_UINT8 as z };
|
|
1729
|
+
//# sourceMappingURL=encoded-types-CuGiO_X_.js.map
|