@algorandfoundation/algorand-typescript-testing 1.0.0-beta.14 → 1.0.0-beta.16
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/abi-metadata-CRbKDwP2.js +90 -0
- package/abi-metadata-CRbKDwP2.js.map +1 -0
- package/{asset-params-CzUcFBcQ.js → asset-params-BfwgiVLK.js} +79 -78
- package/asset-params-BfwgiVLK.js.map +1 -0
- package/collections/custom-key-map.d.ts +3 -3
- package/context-helpers/context-manager.d.ts +7 -0
- package/context-helpers/internal-context.d.ts +4 -3
- package/contract-B0nKfmx-.js +24 -0
- package/contract-B0nKfmx-.js.map +1 -0
- package/{encoded-types-9PSWSstF.js → crypto-DmkHXzw6.js} +750 -190
- package/crypto-DmkHXzw6.js.map +1 -0
- package/encoders.d.ts +2 -2
- package/errors.d.ts +27 -1
- package/impl/acct-params.d.ts +6 -5
- package/impl/app-params.d.ts +3 -2
- package/impl/asset-params.d.ts +3 -3
- package/impl/base-32.d.ts +2 -0
- package/impl/base-contract.d.ts +9 -0
- package/impl/base.d.ts +3 -3
- package/impl/contract.d.ts +10 -0
- package/impl/crypto.d.ts +13 -12
- package/impl/encoded-types.d.ts +16 -17
- package/impl/global.d.ts +1 -1
- package/impl/log.d.ts +2 -2
- package/impl/logicSigArg.d.ts +3 -2
- package/impl/primitives.d.ts +211 -0
- package/impl/pure.d.ts +30 -29
- package/impl/reference.d.ts +9 -6
- package/impl/state.d.ts +15 -15
- package/impl/transactions.d.ts +12 -11
- package/impl/txn.d.ts +2 -2
- package/impl/urange.d.ts +2 -2
- package/index.d.ts +2 -14
- package/index.mjs +693 -119
- package/index.mjs.map +1 -1
- package/{inner-transactions-CR-mVBgh.js → inner-transactions-BoH3ye09.js} +66 -51
- package/inner-transactions-BoH3ye09.js.map +1 -0
- package/internal/arc4.mjs +8 -4
- package/internal/arc4.mjs.map +1 -1
- package/internal/op.mjs +8 -6
- package/internal/op.mjs.map +1 -1
- package/{internal-arc4-BL2mIZPS.js → internal-arc4-DDw3e9T3.js} +4 -2
- package/internal-arc4-DDw3e9T3.js.map +1 -0
- package/internal-arc4.d.ts +1 -1
- package/{internal-op-BeEW2jMq.js → internal-op-CABGy0tk.js} +22 -22
- package/internal-op-CABGy0tk.js.map +1 -0
- package/internal.d.ts +4 -0
- package/internal.mjs +19 -15
- package/internal.mjs.map +1 -1
- package/package.json +3 -3
- package/{runtime-helpers-Dv_gjCvF.js → runtime-helpers-KXJavAF1.js} +51 -136
- package/runtime-helpers-KXJavAF1.js.map +1 -0
- package/runtime-helpers.mjs +8 -5
- package/runtime-helpers.mjs.map +1 -1
- package/set-up.d.ts +20 -0
- package/subcontexts/contract-context.d.ts +16 -4
- package/subcontexts/ledger-context.d.ts +137 -19
- package/subcontexts/transaction-context.d.ts +171 -26
- package/test-execution-context.d.ts +103 -2
- package/test-transformer/index.d.ts +29 -0
- package/test-transformer/index.mjs +36 -9
- package/test-transformer/index.mjs.map +1 -1
- package/typescript-helpers-CAukFXpp.js +18 -0
- package/typescript-helpers-CAukFXpp.js.map +1 -0
- package/typescript-helpers.d.ts +4 -0
- package/util.d.ts +48 -15
- package/value-generators/arc4.d.ts +14 -14
- package/value-generators/avm.d.ts +44 -7
- package/value-generators/txn.d.ts +35 -2
- package/asset-params-CzUcFBcQ.js.map +0 -1
- package/encoded-types-9PSWSstF.js.map +0 -1
- package/inner-transactions-CR-mVBgh.js.map +0 -1
- package/internal-arc4-BL2mIZPS.js.map +0 -1
- package/internal-op-BeEW2jMq.js.map +0 -1
- package/runtime-helpers-Dv_gjCvF.js.map +0 -1
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import js_sha512 from 'js-sha512';
|
|
2
|
+
import { al as getArc4TypeName$1 } from './crypto-DmkHXzw6.js';
|
|
3
|
+
|
|
4
|
+
const AbiMetaSymbol = Symbol('AbiMetadata');
|
|
5
|
+
const isContractProxy = Symbol('isContractProxy');
|
|
6
|
+
const attachAbiMetadata = (contract, methodName, metadata) => {
|
|
7
|
+
const metadatas = (AbiMetaSymbol in contract ? contract[AbiMetaSymbol] : {});
|
|
8
|
+
metadatas[methodName] = metadata;
|
|
9
|
+
if (!(AbiMetaSymbol in contract)) {
|
|
10
|
+
Object.defineProperty(contract, AbiMetaSymbol, {
|
|
11
|
+
value: metadatas,
|
|
12
|
+
writable: true,
|
|
13
|
+
enumerable: false,
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
const copyAbiMetadatas = (sourceContract, targetContract) => {
|
|
18
|
+
const metadatas = getContractAbiMetadata(sourceContract);
|
|
19
|
+
Object.defineProperty(targetContract, AbiMetaSymbol, {
|
|
20
|
+
value: metadatas,
|
|
21
|
+
writable: true,
|
|
22
|
+
enumerable: false,
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
const captureMethodConfig = (contract, methodName, config) => {
|
|
26
|
+
const metadata = getContractMethodAbiMetadata(contract, methodName);
|
|
27
|
+
metadata.onCreate = config?.onCreate ?? 'disallow';
|
|
28
|
+
metadata.allowActions = [].concat(config?.allowActions ?? 'NoOp');
|
|
29
|
+
};
|
|
30
|
+
const getContractAbiMetadata = (contract) => {
|
|
31
|
+
if (contract[isContractProxy]) {
|
|
32
|
+
return contract[AbiMetaSymbol];
|
|
33
|
+
}
|
|
34
|
+
const contractClass = contract.constructor;
|
|
35
|
+
const s = Object.getOwnPropertySymbols(contractClass).find((s) => s.toString() === AbiMetaSymbol.toString());
|
|
36
|
+
const metadatas = (s ? contractClass[s] : AbiMetaSymbol in contractClass ? contractClass[AbiMetaSymbol] : {});
|
|
37
|
+
return metadatas;
|
|
38
|
+
};
|
|
39
|
+
const getContractMethodAbiMetadata = (contract, methodName) => {
|
|
40
|
+
const metadatas = getContractAbiMetadata(contract);
|
|
41
|
+
return metadatas[methodName];
|
|
42
|
+
};
|
|
43
|
+
const getArc4Signature = (metadata) => {
|
|
44
|
+
if (metadata.methodSignature === undefined) {
|
|
45
|
+
const argTypes = metadata.argTypes.map((t) => JSON.parse(t)).map(getArc4TypeName);
|
|
46
|
+
const returnType = getArc4TypeName(JSON.parse(metadata.returnType));
|
|
47
|
+
metadata.methodSignature = `${metadata.methodName}(${argTypes.join(',')})${returnType}`;
|
|
48
|
+
}
|
|
49
|
+
return metadata.methodSignature;
|
|
50
|
+
};
|
|
51
|
+
const getArc4Selector = (metadata) => {
|
|
52
|
+
const hash = js_sha512.sha512_256.array(getArc4Signature(metadata));
|
|
53
|
+
return new Uint8Array(hash.slice(0, 4));
|
|
54
|
+
};
|
|
55
|
+
const getArc4TypeName = (t) => {
|
|
56
|
+
const map = {
|
|
57
|
+
void: 'void',
|
|
58
|
+
account: 'account',
|
|
59
|
+
application: 'application',
|
|
60
|
+
asset: 'asset',
|
|
61
|
+
boolean: 'bool',
|
|
62
|
+
biguint: 'uint512',
|
|
63
|
+
bytes: 'byte[]',
|
|
64
|
+
string: 'string',
|
|
65
|
+
uint64: 'uint64',
|
|
66
|
+
OnCompleteAction: 'uint64',
|
|
67
|
+
TransactionType: 'uint64',
|
|
68
|
+
Transaction: 'txn',
|
|
69
|
+
PaymentTxn: 'pay',
|
|
70
|
+
KeyRegistrationTxn: 'keyreg',
|
|
71
|
+
AssetConfigTxn: 'acfg',
|
|
72
|
+
AssetTransferTxn: 'axfer',
|
|
73
|
+
AssetFreezeTxn: 'afrz',
|
|
74
|
+
ApplicationTxn: 'appl',
|
|
75
|
+
'Tuple(<.*>)?': (t) => `(${Object.values(t.genericArgs)
|
|
76
|
+
.map(getArc4TypeName)
|
|
77
|
+
.join(',')})`,
|
|
78
|
+
};
|
|
79
|
+
const entry = Object.entries(map).find(([k, _]) => new RegExp(`^${k}$`, 'i').test(t.name))?.[1];
|
|
80
|
+
if (entry === undefined) {
|
|
81
|
+
return getArc4TypeName$1(t) ?? t.name;
|
|
82
|
+
}
|
|
83
|
+
if (entry instanceof Function) {
|
|
84
|
+
return entry(t);
|
|
85
|
+
}
|
|
86
|
+
return entry;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export { getContractMethodAbiMetadata as a, getContractAbiMetadata as b, copyAbiMetadatas as c, attachAbiMetadata as d, captureMethodConfig as e, getArc4Selector as g, isContractProxy as i };
|
|
90
|
+
//# sourceMappingURL=abi-metadata-CRbKDwP2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abi-metadata-CRbKDwP2.js","sources":["../src/abi-metadata.ts"],"sourcesContent":["import type { BaseContract, Contract } from '@algorandfoundation/algorand-typescript'\nimport type { AbiMethodConfig, BareMethodConfig, CreateOptions, OnCompleteActionStr } from '@algorandfoundation/algorand-typescript/arc4'\nimport js_sha512 from 'js-sha512'\nimport type { TypeInfo } from './encoders'\nimport { getArc4TypeName as getArc4TypeNameForARC4Encoded } from './impl/encoded-types'\nimport type { DeliberateAny } from './typescript-helpers'\n\nexport interface AbiMetadata {\n methodName: string\n methodSignature: string | undefined\n argTypes: string[]\n returnType: string\n onCreate?: CreateOptions\n allowActions?: OnCompleteActionStr[]\n}\nconst AbiMetaSymbol = Symbol('AbiMetadata')\nexport const isContractProxy = Symbol('isContractProxy')\nexport const attachAbiMetadata = (contract: { new (): Contract }, methodName: string, metadata: AbiMetadata): void => {\n const metadatas: Record<string, AbiMetadata> = (AbiMetaSymbol in contract ? contract[AbiMetaSymbol] : {}) as Record<string, AbiMetadata>\n metadatas[methodName] = metadata\n if (!(AbiMetaSymbol in contract)) {\n Object.defineProperty(contract, AbiMetaSymbol, {\n value: metadatas,\n writable: true,\n enumerable: false,\n })\n }\n}\n\nexport const copyAbiMetadatas = <T extends BaseContract>(sourceContract: T, targetContract: T): void => {\n const metadatas = getContractAbiMetadata(sourceContract)\n Object.defineProperty(targetContract, AbiMetaSymbol, {\n value: metadatas,\n writable: true,\n enumerable: false,\n })\n}\n\nexport const captureMethodConfig = <T extends Contract>(\n contract: T,\n methodName: string,\n config?: AbiMethodConfig<T> | BareMethodConfig,\n): void => {\n const metadata = getContractMethodAbiMetadata(contract, methodName)\n metadata.onCreate = config?.onCreate ?? 'disallow'\n metadata.allowActions = ([] as OnCompleteActionStr[]).concat(config?.allowActions ?? 'NoOp')\n}\n\nexport const hasAbiMetadata = <T extends Contract>(contract: T): boolean => {\n const contractClass = contract.constructor as { new (): T }\n return (\n Object.getOwnPropertySymbols(contractClass).some((s) => s.toString() === AbiMetaSymbol.toString()) || AbiMetaSymbol in contractClass\n )\n}\nexport const getContractAbiMetadata = <T extends BaseContract>(contract: T): Record<string, AbiMetadata> => {\n if ((contract as DeliberateAny)[isContractProxy]) {\n return (contract as DeliberateAny)[AbiMetaSymbol] as Record<string, AbiMetadata>\n }\n const contractClass = contract.constructor as { new (): T }\n const s = Object.getOwnPropertySymbols(contractClass).find((s) => s.toString() === AbiMetaSymbol.toString())\n const metadatas: Record<string, AbiMetadata> = (\n s ? (contractClass as DeliberateAny)[s] : AbiMetaSymbol in contractClass ? contractClass[AbiMetaSymbol] : {}\n ) as Record<string, AbiMetadata>\n return metadatas\n}\n\nexport const getContractMethodAbiMetadata = <T extends BaseContract>(contract: T, methodName: string): AbiMetadata => {\n const metadatas = getContractAbiMetadata(contract)\n return metadatas[methodName]\n}\n\nexport const getArc4Signature = (metadata: AbiMetadata): string => {\n if (metadata.methodSignature === undefined) {\n const argTypes = metadata.argTypes.map((t) => JSON.parse(t) as TypeInfo).map(getArc4TypeName)\n const returnType = getArc4TypeName(JSON.parse(metadata.returnType) as TypeInfo)\n metadata.methodSignature = `${metadata.methodName}(${argTypes.join(',')})${returnType}`\n }\n return metadata.methodSignature\n}\n\nexport const getArc4Selector = (metadata: AbiMetadata): Uint8Array => {\n const hash = js_sha512.sha512_256.array(getArc4Signature(metadata))\n return new Uint8Array(hash.slice(0, 4))\n}\n\nconst getArc4TypeName = (t: TypeInfo): string => {\n const map: Record<string, string | ((t: TypeInfo) => string)> = {\n void: 'void',\n account: 'account',\n application: 'application',\n asset: 'asset',\n boolean: 'bool',\n biguint: 'uint512',\n bytes: 'byte[]',\n string: 'string',\n uint64: 'uint64',\n OnCompleteAction: 'uint64',\n TransactionType: 'uint64',\n Transaction: 'txn',\n PaymentTxn: 'pay',\n KeyRegistrationTxn: 'keyreg',\n AssetConfigTxn: 'acfg',\n AssetTransferTxn: 'axfer',\n AssetFreezeTxn: 'afrz',\n ApplicationTxn: 'appl',\n 'Tuple(<.*>)?': (t) =>\n `(${Object.values(t.genericArgs as Record<string, TypeInfo>)\n .map(getArc4TypeName)\n .join(',')})`,\n }\n const entry = Object.entries(map).find(([k, _]) => new RegExp(`^${k}$`, 'i').test(t.name))?.[1]\n if (entry === undefined) {\n return getArc4TypeNameForARC4Encoded(t) ?? t.name\n }\n if (entry instanceof Function) {\n return entry(t)\n }\n return entry\n}\n"],"names":["getArc4TypeNameForARC4Encoded"],"mappings":";;;AAeA,MAAM,aAAa,GAAG,MAAM,CAAC,aAAa,CAAC;MAC9B,eAAe,GAAG,MAAM,CAAC,iBAAiB;AAC1C,MAAA,iBAAiB,GAAG,CAAC,QAA8B,EAAE,UAAkB,EAAE,QAAqB,KAAU;AACnH,IAAA,MAAM,SAAS,IAAiC,aAAa,IAAI,QAAQ,GAAG,QAAQ,CAAC,aAAa,CAAC,GAAG,EAAE,CAAgC;AACxI,IAAA,SAAS,CAAC,UAAU,CAAC,GAAG,QAAQ;AAChC,IAAA,IAAI,EAAE,aAAa,IAAI,QAAQ,CAAC,EAAE;AAChC,QAAA,MAAM,CAAC,cAAc,CAAC,QAAQ,EAAE,aAAa,EAAE;AAC7C,YAAA,KAAK,EAAE,SAAS;AAChB,YAAA,QAAQ,EAAE,IAAI;AACd,YAAA,UAAU,EAAE,KAAK;AAClB,SAAA,CAAC;;AAEN;MAEa,gBAAgB,GAAG,CAAyB,cAAiB,EAAE,cAAiB,KAAU;AACrG,IAAA,MAAM,SAAS,GAAG,sBAAsB,CAAC,cAAc,CAAC;AACxD,IAAA,MAAM,CAAC,cAAc,CAAC,cAAc,EAAE,aAAa,EAAE;AACnD,QAAA,KAAK,EAAE,SAAS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AAE,MAAM;AACtB,QAAA,cAAc,EAAE,MAAM;AACtB,QAAA,cAAc,EAAE,CAAC,CAAC,KAChB,CAAA,CAAA,EAAI,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,WAAuC;aACxD,GAAG,CAAC,eAAe;aACnB,IAAI,CAAC,GAAG,CAAC,CAAG,CAAA,CAAA;KAClB;AACD,IAAA,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,IAAI,MAAM,CAAC,CAAI,CAAA,EAAA,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;AAC/F,IAAA,IAAI,KAAK,KAAK,SAAS,EAAE;QACvB,OAAOA,iBAA6B,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI;;AAEnD,IAAA,IAAI,KAAK,YAAY,QAAQ,EAAE;AAC7B,QAAA,OAAO,KAAK,CAAC,CAAC,CAAC;;AAEjB,IAAA,OAAO,KAAK;AACd,CAAC;;;;"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { internal, BigUint, Uint64, Bytes, Base64 } from '@algorandfoundation/algorand-typescript';
|
|
2
1
|
import { ARC4Encoded } from '@algorandfoundation/algorand-typescript/arc4';
|
|
3
|
-
import {
|
|
2
|
+
import { encodingUtil } from '@algorandfoundation/puya-ts';
|
|
3
|
+
import { q as asMaybeUint64Cls, y as asMaybeBytesCls, a8 as asMaybeBigUintCls, a5 as BytesBackedCls, a6 as Uint64BackedCls, r as asUint64Cls, aq as encodeArc4Impl, I as InternalError, aj as nameOfType, aB as getArc4Encoder, A as AccountCls, f as ApplicationCls, g as AssetCls, aA as arc4Encoders, z as asUint8Array, K as BigUint, x as asBytes, G as Uint64, l as lazyContext, O as getRandomBytes, o as asUint64, N as Account, aN as getObjectReference, h as Bytes, aK as sha256, aO as getApplicationAddress, aP as MIN_TXN_FEE, aQ as DEFAULT_ACCOUNT_MIN_BALANCE, aR as DEFAULT_MAX_TXN_LIFE, aS as ZERO_ADDRESS, aT as DEFAULT_ASSET_CREATE_MIN_BALANCE, aU as DEFAULT_ASSET_OPT_IN_MIN_BALANCE, aV as DEFAULT_GLOBAL_GENESIS_HASH, U as Uint64Cls, a as BytesCls, a2 as AvmError, B as BigUintCls, an as checkBigUint, aW as asBigUint, _ as BITS_IN_BYTE, L as MAX_BYTES_SIZE, C as CodeError, aX as isUint64, ad as asBytesCls, F as testInvariant, S as MAX_UINT8, aY as binaryStringToBytes, aZ as UINT64_SIZE, a3 as NotImplementedError, M as MAX_UINT64 } from './crypto-DmkHXzw6.js';
|
|
4
|
+
import { Base64 } from '@algorandfoundation/algorand-typescript';
|
|
4
5
|
|
|
5
6
|
const booleanFromBytes = (val) => {
|
|
6
|
-
return
|
|
7
|
+
return encodingUtil.uint8ArrayToBigInt(asUint8Array(val)) > 0n;
|
|
7
8
|
};
|
|
8
9
|
const bigUintFromBytes = (val) => {
|
|
9
|
-
return BigUint(
|
|
10
|
+
return BigUint(encodingUtil.uint8ArrayToBigInt(asUint8Array(val)));
|
|
10
11
|
};
|
|
11
12
|
const bytesFromBytes = (val) => {
|
|
12
13
|
return asBytes(val);
|
|
@@ -15,13 +16,13 @@ const stringFromBytes = (val) => {
|
|
|
15
16
|
return asBytes(val).toString();
|
|
16
17
|
};
|
|
17
18
|
const uint64FromBytes = (val) => {
|
|
18
|
-
return Uint64(
|
|
19
|
+
return Uint64(encodingUtil.uint8ArrayToBigInt(asUint8Array(val)));
|
|
19
20
|
};
|
|
20
21
|
const onCompletionFromBytes = (val) => {
|
|
21
|
-
return Uint64(
|
|
22
|
+
return Uint64(encodingUtil.uint8ArrayToBigInt(asUint8Array(val)));
|
|
22
23
|
};
|
|
23
24
|
const transactionTypeFromBytes = (val) => {
|
|
24
|
-
return Uint64(
|
|
25
|
+
return Uint64(encodingUtil.uint8ArrayToBigInt(asUint8Array(val)));
|
|
25
26
|
};
|
|
26
27
|
const encoders = {
|
|
27
28
|
account: AccountCls.fromBytes,
|
|
@@ -64,7 +65,7 @@ const toBytes = (val) => {
|
|
|
64
65
|
if (Array.isArray(val) || typeof val === 'object') {
|
|
65
66
|
return encodeArc4Impl('', val);
|
|
66
67
|
}
|
|
67
|
-
|
|
68
|
+
throw new InternalError(`Invalid type for bytes: ${nameOfType(val)}`);
|
|
68
69
|
};
|
|
69
70
|
|
|
70
71
|
class BlockData {
|
|
@@ -200,7 +201,7 @@ const Global = {
|
|
|
200
201
|
const data = getGlobalData();
|
|
201
202
|
if (data.logicSigVersion !== undefined)
|
|
202
203
|
return data.logicSigVersion;
|
|
203
|
-
throw new
|
|
204
|
+
throw new InternalError(getMissingValueErrorMessage('logicSigVersion'));
|
|
204
205
|
},
|
|
205
206
|
/**
|
|
206
207
|
* Current round number. ApplicationType mode only.
|
|
@@ -247,7 +248,7 @@ const Global = {
|
|
|
247
248
|
if (data.groupId !== undefined)
|
|
248
249
|
return data.groupId;
|
|
249
250
|
const reference = getObjectReference(lazyContext.activeGroup);
|
|
250
|
-
const referenceBytes = Bytes(
|
|
251
|
+
const referenceBytes = Bytes(encodingUtil.bigIntToUint8Array(reference));
|
|
251
252
|
return sha256(referenceBytes);
|
|
252
253
|
},
|
|
253
254
|
/**
|
|
@@ -257,7 +258,7 @@ const Global = {
|
|
|
257
258
|
const data = getGlobalData();
|
|
258
259
|
if (data.opcodeBudget !== undefined)
|
|
259
260
|
return data.opcodeBudget;
|
|
260
|
-
throw new
|
|
261
|
+
throw new InternalError(getMissingValueErrorMessage('opcodeBudget'));
|
|
261
262
|
},
|
|
262
263
|
/**
|
|
263
264
|
* The application ID of the application that called this application. 0 if this application is at the top-level. ApplicationType mode only.
|
|
@@ -499,18 +500,18 @@ const VoterParams = {
|
|
|
499
500
|
};
|
|
500
501
|
|
|
501
502
|
const addw = (a, b) => {
|
|
502
|
-
const uint64A =
|
|
503
|
-
const uint64B =
|
|
503
|
+
const uint64A = Uint64Cls.fromCompat(a);
|
|
504
|
+
const uint64B = Uint64Cls.fromCompat(b);
|
|
504
505
|
const sum = uint64A.asBigInt() + uint64B.asBigInt();
|
|
505
506
|
return toUint128(sum);
|
|
506
507
|
};
|
|
507
508
|
const base64Decode = (e, a) => {
|
|
508
509
|
const encoding = e === Base64.StdEncoding ? 'base64' : 'base64url';
|
|
509
|
-
const bytesValue =
|
|
510
|
+
const bytesValue = BytesCls.fromCompat(a);
|
|
510
511
|
const stringValue = bytesValue.toString();
|
|
511
512
|
const bufferResult = Buffer.from(stringValue, encoding);
|
|
512
513
|
if (bufferResult.toString(encoding) !== stringValue) {
|
|
513
|
-
|
|
514
|
+
throw new AvmError('illegal base64 data');
|
|
514
515
|
}
|
|
515
516
|
const uint8ArrayResult = new Uint8Array(bufferResult);
|
|
516
517
|
return Bytes(uint8ArrayResult);
|
|
@@ -523,28 +524,28 @@ const bitLength = (a) => {
|
|
|
523
524
|
return Uint64(binaryValue.length);
|
|
524
525
|
};
|
|
525
526
|
const bsqrt = (a) => {
|
|
526
|
-
const bigUintClsValue =
|
|
527
|
-
const bigintValue =
|
|
527
|
+
const bigUintClsValue = BigUintCls.fromCompat(a);
|
|
528
|
+
const bigintValue = checkBigUint(bigUintClsValue.asBigInt());
|
|
528
529
|
const sqrtValue = squareroot(bigintValue);
|
|
529
530
|
return asBigUint(sqrtValue);
|
|
530
531
|
};
|
|
531
532
|
const btoi = (a) => {
|
|
532
|
-
const bytesValue =
|
|
533
|
+
const bytesValue = BytesCls.fromCompat(a);
|
|
533
534
|
if (bytesValue.length.asAlgoTs() > BITS_IN_BYTE) {
|
|
534
|
-
|
|
535
|
+
throw new AvmError(`btoi arg too long, got [${bytesValue.length.valueOf()}]bytes`);
|
|
535
536
|
}
|
|
536
537
|
return bytesValue.toUint64().asAlgoTs();
|
|
537
538
|
};
|
|
538
539
|
const bzero = (a) => {
|
|
539
|
-
const size =
|
|
540
|
+
const size = Uint64Cls.fromCompat(a).asBigInt();
|
|
540
541
|
if (size > MAX_BYTES_SIZE) {
|
|
541
|
-
|
|
542
|
+
throw new AvmError('bzero attempted to create a too large string');
|
|
542
543
|
}
|
|
543
544
|
return Bytes(new Uint8Array(Number(size)));
|
|
544
545
|
};
|
|
545
546
|
const concat = (a, b) => {
|
|
546
|
-
const bytesA =
|
|
547
|
-
const bytesB =
|
|
547
|
+
const bytesA = BytesCls.fromCompat(a);
|
|
548
|
+
const bytesB = BytesCls.fromCompat(b);
|
|
548
549
|
return bytesA.concat(bytesB).asAlgoTs();
|
|
549
550
|
};
|
|
550
551
|
const divmodw = (a, b, c, d) => {
|
|
@@ -556,68 +557,68 @@ const divmodw = (a, b, c, d) => {
|
|
|
556
557
|
};
|
|
557
558
|
const divw = (a, b, c) => {
|
|
558
559
|
const i = uint128ToBigInt(a, b);
|
|
559
|
-
const j =
|
|
560
|
+
const j = Uint64Cls.fromCompat(c).asBigInt();
|
|
560
561
|
return Uint64(i / j);
|
|
561
562
|
};
|
|
562
563
|
const exp = (a, b) => {
|
|
563
|
-
const base =
|
|
564
|
-
const exponent =
|
|
564
|
+
const base = Uint64Cls.fromCompat(a).asBigInt();
|
|
565
|
+
const exponent = Uint64Cls.fromCompat(b).asBigInt();
|
|
565
566
|
if (base === 0n && exponent === 0n) {
|
|
566
|
-
throw
|
|
567
|
+
throw new CodeError('0 ** 0 is undefined');
|
|
567
568
|
}
|
|
568
569
|
return Uint64(base ** exponent);
|
|
569
570
|
};
|
|
570
571
|
const expw = (a, b) => {
|
|
571
|
-
const base =
|
|
572
|
-
const exponent =
|
|
572
|
+
const base = Uint64Cls.fromCompat(a).asBigInt();
|
|
573
|
+
const exponent = Uint64Cls.fromCompat(b).asBigInt();
|
|
573
574
|
if (base === 0n && exponent === 0n) {
|
|
574
|
-
throw
|
|
575
|
+
throw new CodeError('0 ** 0 is undefined');
|
|
575
576
|
}
|
|
576
577
|
return toUint128(base ** exponent);
|
|
577
578
|
};
|
|
578
579
|
const extract = ((a, b, c) => {
|
|
579
|
-
const bytesValue =
|
|
580
|
+
const bytesValue = BytesCls.fromCompat(a);
|
|
580
581
|
const bytesLength = bytesValue.length.asBigInt();
|
|
581
|
-
const start =
|
|
582
|
-
const length = c !== undefined ?
|
|
582
|
+
const start = Uint64Cls.fromCompat(b).asBigInt();
|
|
583
|
+
const length = c !== undefined ? Uint64Cls.fromCompat(c).asBigInt() : undefined;
|
|
583
584
|
const end = length !== undefined ? start + length : undefined;
|
|
584
585
|
if (start > bytesLength) {
|
|
585
|
-
|
|
586
|
+
throw new CodeError(`extraction start ${start} is beyond length`);
|
|
586
587
|
}
|
|
587
588
|
if (end !== undefined && end > bytesLength) {
|
|
588
|
-
|
|
589
|
+
throw new CodeError(`extraction end ${end} is beyond length`);
|
|
589
590
|
}
|
|
590
591
|
return bytesValue.slice(start, end).asAlgoTs();
|
|
591
592
|
});
|
|
592
593
|
const extractUint16 = (a, b) => {
|
|
593
594
|
const result = extract(a, b, 2);
|
|
594
|
-
const bytesResult =
|
|
595
|
+
const bytesResult = BytesCls.fromCompat(result);
|
|
595
596
|
return bytesResult.toUint64().asAlgoTs();
|
|
596
597
|
};
|
|
597
598
|
const extractUint32 = (a, b) => {
|
|
598
599
|
const result = extract(a, b, 4);
|
|
599
|
-
const bytesResult =
|
|
600
|
+
const bytesResult = BytesCls.fromCompat(result);
|
|
600
601
|
return bytesResult.toUint64().asAlgoTs();
|
|
601
602
|
};
|
|
602
603
|
const extractUint64 = (a, b) => {
|
|
603
604
|
const result = extract(a, b, 8);
|
|
604
|
-
const bytesResult =
|
|
605
|
+
const bytesResult = BytesCls.fromCompat(result);
|
|
605
606
|
return bytesResult.toUint64().asAlgoTs();
|
|
606
607
|
};
|
|
607
608
|
const getBit = (a, b) => {
|
|
608
|
-
const binaryString = toBinaryString(
|
|
609
|
-
const index =
|
|
609
|
+
const binaryString = toBinaryString(isUint64(a) ? asUint64Cls(a).toBytes().asAlgoTs() : asBytes(a));
|
|
610
|
+
const index = Uint64Cls.fromCompat(b).asNumber();
|
|
610
611
|
const adjustedIndex = asMaybeUint64Cls(a) ? binaryString.length - index - 1 : index;
|
|
611
612
|
if (adjustedIndex < 0 || adjustedIndex >= binaryString.length) {
|
|
612
|
-
|
|
613
|
+
throw new CodeError(`getBit index ${index} is beyond length`);
|
|
613
614
|
}
|
|
614
|
-
return binaryString[adjustedIndex] === '1' ?
|
|
615
|
+
return binaryString[adjustedIndex] === '1' ? 1 : 0;
|
|
615
616
|
};
|
|
616
617
|
const getByte = (a, b) => {
|
|
617
|
-
const bytesValue =
|
|
618
|
-
const index =
|
|
618
|
+
const bytesValue = BytesCls.fromCompat(a);
|
|
619
|
+
const index = Uint64Cls.fromCompat(b).asNumber();
|
|
619
620
|
if (index >= bytesValue.length.asNumber()) {
|
|
620
|
-
|
|
621
|
+
throw new CodeError(`getBytes index ${index} is beyond length`);
|
|
621
622
|
}
|
|
622
623
|
return bytesValue.at(index).toUint64().asAlgoTs();
|
|
623
624
|
};
|
|
@@ -628,19 +629,19 @@ const len = (a) => {
|
|
|
628
629
|
return asBytesCls(a).length.asAlgoTs();
|
|
629
630
|
};
|
|
630
631
|
const mulw = (a, b) => {
|
|
631
|
-
const uint64A =
|
|
632
|
-
const uint64B =
|
|
632
|
+
const uint64A = Uint64Cls.fromCompat(a);
|
|
633
|
+
const uint64B = Uint64Cls.fromCompat(b);
|
|
633
634
|
const product = uint64A.asBigInt() * uint64B.asBigInt();
|
|
634
635
|
return toUint128(product);
|
|
635
636
|
};
|
|
636
637
|
const replace = (a, b, c) => {
|
|
637
|
-
const bytesValue =
|
|
638
|
-
const index =
|
|
639
|
-
const replacement =
|
|
638
|
+
const bytesValue = BytesCls.fromCompat(a);
|
|
639
|
+
const index = Uint64Cls.fromCompat(b).asNumber();
|
|
640
|
+
const replacement = BytesCls.fromCompat(c);
|
|
640
641
|
const valueLength = bytesValue.length.asNumber();
|
|
641
642
|
const replacementLength = replacement.length.asNumber();
|
|
642
643
|
if (index + replacementLength > valueLength) {
|
|
643
|
-
|
|
644
|
+
throw new CodeError(`expected value <= ${valueLength}, got: ${index + replacementLength}`);
|
|
644
645
|
}
|
|
645
646
|
return bytesValue
|
|
646
647
|
.slice(0, index)
|
|
@@ -653,13 +654,13 @@ const select = ((a, b, c) => {
|
|
|
653
654
|
const uint64B = asMaybeUint64Cls(b);
|
|
654
655
|
const bytesA = asMaybeBytesCls(a);
|
|
655
656
|
const bytesB = asMaybeBytesCls(b);
|
|
656
|
-
const bigIntC =
|
|
657
|
+
const bigIntC = Uint64Cls.fromCompat(c).asBigInt();
|
|
657
658
|
return (bigIntC !== 0n ? (uint64B ?? bytesB) : (uint64A ?? bytesA)).asAlgoTs();
|
|
658
659
|
});
|
|
659
660
|
const setBit = ((a, b, c) => {
|
|
660
661
|
const uint64Cls = asMaybeUint64Cls(a);
|
|
661
|
-
const indexParam =
|
|
662
|
-
const bit =
|
|
662
|
+
const indexParam = Uint64Cls.fromCompat(b).asNumber();
|
|
663
|
+
const bit = Uint64Cls.fromCompat(c).asNumber();
|
|
663
664
|
if (uint64Cls) {
|
|
664
665
|
const binaryString = toBinaryString(uint64Cls?.toBytes().asAlgoTs());
|
|
665
666
|
const index = binaryString.length - indexParam - 1;
|
|
@@ -675,63 +676,63 @@ const setBit = ((a, b, c) => {
|
|
|
675
676
|
}
|
|
676
677
|
});
|
|
677
678
|
const setByte = (a, b, c) => {
|
|
678
|
-
const binaryString = toBinaryString(
|
|
679
|
-
const byteIndex =
|
|
679
|
+
const binaryString = toBinaryString(BytesCls.fromCompat(a).asAlgoTs());
|
|
680
|
+
const byteIndex = Uint64Cls.fromCompat(b).asNumber();
|
|
680
681
|
const bitIndex = byteIndex * BITS_IN_BYTE;
|
|
681
|
-
const replacementNumber =
|
|
682
|
+
const replacementNumber = Uint64Cls.fromCompat(c);
|
|
682
683
|
const replacement = toBinaryString(replacementNumber.toBytes().at(-1).asAlgoTs());
|
|
683
684
|
if (bitIndex >= binaryString.length) {
|
|
684
|
-
|
|
685
|
+
throw new CodeError(`setByte index ${byteIndex} is beyond length`);
|
|
685
686
|
}
|
|
686
687
|
if (replacementNumber.valueOf() > MAX_UINT8) {
|
|
687
|
-
|
|
688
|
+
throw new CodeError(`setByte value ${replacementNumber.asNumber()} > ${MAX_UINT8}`);
|
|
688
689
|
}
|
|
689
690
|
const updatedString = binaryString.slice(0, bitIndex) + replacement + binaryString.slice(bitIndex + replacement.length);
|
|
690
691
|
const updatedBytes = binaryStringToBytes(updatedString);
|
|
691
692
|
return updatedBytes.asAlgoTs();
|
|
692
693
|
};
|
|
693
694
|
const shl = (a, b) => {
|
|
694
|
-
const uint64A =
|
|
695
|
-
const uint64B =
|
|
695
|
+
const uint64A = Uint64Cls.fromCompat(a);
|
|
696
|
+
const uint64B = Uint64Cls.fromCompat(b);
|
|
696
697
|
const bigIntA = uint64A.asBigInt();
|
|
697
698
|
const bigIntB = uint64B.asBigInt();
|
|
698
699
|
if (bigIntB >= UINT64_SIZE) {
|
|
699
|
-
|
|
700
|
+
throw new CodeError(`shl value ${bigIntB} >= ${UINT64_SIZE}`);
|
|
700
701
|
}
|
|
701
702
|
const shifted = (bigIntA * 2n ** bigIntB) % 2n ** BigInt(UINT64_SIZE);
|
|
702
703
|
return Uint64(shifted);
|
|
703
704
|
};
|
|
704
705
|
const shr = (a, b) => {
|
|
705
|
-
const uint64A =
|
|
706
|
-
const uint64B =
|
|
706
|
+
const uint64A = Uint64Cls.fromCompat(a);
|
|
707
|
+
const uint64B = Uint64Cls.fromCompat(b);
|
|
707
708
|
const bigIntA = uint64A.asBigInt();
|
|
708
709
|
const bigIntB = uint64B.asBigInt();
|
|
709
710
|
if (bigIntB >= UINT64_SIZE) {
|
|
710
|
-
|
|
711
|
+
throw new CodeError(`shr value ${bigIntB} >= ${UINT64_SIZE}`);
|
|
711
712
|
}
|
|
712
713
|
const shifted = bigIntA / 2n ** bigIntB;
|
|
713
714
|
return Uint64(shifted);
|
|
714
715
|
};
|
|
715
716
|
const sqrt = (a) => {
|
|
716
|
-
const bigIntValue =
|
|
717
|
+
const bigIntValue = Uint64Cls.fromCompat(a).asBigInt();
|
|
717
718
|
const sqrtValue = squareroot(bigIntValue);
|
|
718
719
|
return Uint64(sqrtValue);
|
|
719
720
|
};
|
|
720
721
|
const substring = (a, b, c) => {
|
|
721
|
-
const bytesValue =
|
|
722
|
-
const start =
|
|
723
|
-
const end =
|
|
722
|
+
const bytesValue = BytesCls.fromCompat(a);
|
|
723
|
+
const start = Uint64Cls.fromCompat(b).asBigInt();
|
|
724
|
+
const end = Uint64Cls.fromCompat(c).asBigInt();
|
|
724
725
|
if (start > end) {
|
|
725
|
-
|
|
726
|
+
throw new CodeError('substring end before start');
|
|
726
727
|
}
|
|
727
728
|
if (end > bytesValue.length.asNumber()) {
|
|
728
|
-
|
|
729
|
+
throw new CodeError('substring range beyond length of string');
|
|
729
730
|
}
|
|
730
731
|
return bytesValue.slice(start, end).asAlgoTs();
|
|
731
732
|
};
|
|
732
733
|
const JsonRef = new Proxy({}, {
|
|
733
734
|
get: (_target, prop) => {
|
|
734
|
-
|
|
735
|
+
throw new NotImplementedError(`JsonRef.${prop.toString()}`);
|
|
735
736
|
},
|
|
736
737
|
});
|
|
737
738
|
const squareroot = (x) => {
|
|
@@ -751,19 +752,19 @@ const toUint128 = (value) => {
|
|
|
751
752
|
return [Uint64(cf), Uint64(rest)];
|
|
752
753
|
};
|
|
753
754
|
const uint128ToBigInt = (a, b) => {
|
|
754
|
-
const bigIntA =
|
|
755
|
-
const bigIntB =
|
|
755
|
+
const bigIntA = Uint64Cls.fromCompat(a).asBigInt();
|
|
756
|
+
const bigIntB = Uint64Cls.fromCompat(b).asBigInt();
|
|
756
757
|
return (bigIntA << 64n) + bigIntB;
|
|
757
758
|
};
|
|
758
759
|
const toBinaryString = (a) => {
|
|
759
|
-
return [...
|
|
760
|
+
return [...BytesCls.fromCompat(a).asUint8Array()].map((x) => x.toString(2).padStart(BITS_IN_BYTE, '0')).join('');
|
|
760
761
|
};
|
|
761
762
|
const doSetBit = (binaryString, index, bit) => {
|
|
762
763
|
if (index < 0 || index >= binaryString.length) {
|
|
763
|
-
|
|
764
|
+
throw new CodeError(`setBit index ${index < 0 ? binaryString.length - index : index} is beyond length`);
|
|
764
765
|
}
|
|
765
766
|
if (bit !== 0 && bit !== 1) {
|
|
766
|
-
|
|
767
|
+
throw new CodeError(`setBit value > 1`);
|
|
767
768
|
}
|
|
768
769
|
const updatedString = binaryString.slice(0, index) + bit.toString() + binaryString.slice(index + 1);
|
|
769
770
|
return binaryStringToBytes(updatedString);
|
|
@@ -841,4 +842,4 @@ const AssetParams = {
|
|
|
841
842
|
};
|
|
842
843
|
|
|
843
844
|
export { AcctParams as A, BlockData as B, extractUint64 as C, getBit as D, getByte as E, itob as F, GlobalData as G, len as H, minBalance as I, JsonRef as J, mulw as K, replace as L, select as M, setBit as N, setByte as O, shl as P, shr as Q, sqrt as R, substring as S, VoterData as V, Global as a, btoi as b, getAsset as c, getApp as d, getAccount as e, AppParams as f, getEncoder as g, AssetParams as h, Block as i, VoterParams as j, addw as k, appOptedIn as l, balance as m, base64Decode as n, bitLength as o, bsqrt as p, bzero as q, concat as r, divmodw as s, toBytes as t, divw as u, exp as v, expw as w, extract as x, extractUint16 as y, extractUint32 as z };
|
|
844
|
-
//# sourceMappingURL=asset-params-
|
|
845
|
+
//# sourceMappingURL=asset-params-BfwgiVLK.js.map
|