@algorandfoundation/algokit-utils 9.2.0 → 9.2.1-beta.2
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/_virtual/_rolldown/runtime.js +33 -0
- package/_virtual/_rolldown/runtime.mjs +13 -0
- package/account/account.d.ts +25 -30
- package/account/account.js +151 -146
- package/account/account.js.map +1 -1
- package/account/account.mjs +149 -144
- package/account/account.mjs.map +1 -1
- package/account/get-account-config-from-environment.d.ts +7 -2
- package/account/get-account-config-from-environment.js +19 -21
- package/account/get-account-config-from-environment.js.map +1 -1
- package/account/get-account-config-from-environment.mjs +19 -19
- package/account/get-account-config-from-environment.mjs.map +1 -1
- package/account/get-account.d.ts +14 -12
- package/account/get-account.js +56 -59
- package/account/get-account.js.map +1 -1
- package/account/get-account.mjs +56 -57
- package/account/get-account.mjs.map +1 -1
- package/account/get-dispenser-account.d.ts +9 -5
- package/account/get-dispenser-account.js +20 -18
- package/account/get-dispenser-account.js.map +1 -1
- package/account/get-dispenser-account.mjs +20 -16
- package/account/get-dispenser-account.mjs.map +1 -1
- package/account/mnemonic-account.d.ts +7 -3
- package/account/mnemonic-account.js +17 -17
- package/account/mnemonic-account.js.map +1 -1
- package/account/mnemonic-account.mjs +15 -15
- package/account/mnemonic-account.mjs.map +1 -1
- package/amount.d.ts +40 -35
- package/amount.js +33 -34
- package/amount.js.map +1 -1
- package/amount.mjs +33 -32
- package/amount.mjs.map +1 -1
- package/app-client.d.ts +10 -6
- package/app-client.js +91 -86
- package/app-client.js.map +1 -1
- package/app-client.mjs +91 -84
- package/app-client.mjs.map +1 -1
- package/app-deploy.d.ts +26 -24
- package/app-deploy.js +235 -253
- package/app-deploy.js.map +1 -1
- package/app-deploy.mjs +233 -251
- package/app-deploy.mjs.map +1 -1
- package/app.d.ts +45 -46
- package/app.js +253 -271
- package/app.js.map +1 -1
- package/app.mjs +249 -267
- package/app.mjs.map +1 -1
- package/asset.d.ts +16 -12
- package/asset.js +116 -122
- package/asset.js.map +1 -1
- package/asset.mjs +116 -120
- package/asset.mjs.map +1 -1
- package/config.d.ts +7 -2
- package/config.js +5 -7
- package/config.js.map +1 -1
- package/config.mjs +5 -4
- package/config.mjs.map +1 -1
- package/debugging/debugging.d.ts +5 -1
- package/debugging/debugging.js +11 -11
- package/debugging/debugging.js.map +1 -1
- package/debugging/debugging.mjs +11 -9
- package/debugging/debugging.mjs.map +1 -1
- package/dispenser-client.d.ts +7 -2
- package/dispenser-client.js +23 -24
- package/dispenser-client.js.map +1 -1
- package/dispenser-client.mjs +23 -22
- package/dispenser-client.mjs.map +1 -1
- package/index.d.ts +27 -18
- package/index.js +140 -143
- package/index.mjs +27 -29
- package/indexer-lookup.d.ts +18 -11
- package/indexer-lookup.js +112 -120
- package/indexer-lookup.js.map +1 -1
- package/indexer-lookup.mjs +105 -118
- package/indexer-lookup.mjs.map +1 -1
- package/localnet/get-kmd-wallet-account.d.ts +9 -7
- package/localnet/get-kmd-wallet-account.js +28 -26
- package/localnet/get-kmd-wallet-account.js.map +1 -1
- package/localnet/get-kmd-wallet-account.mjs +28 -24
- package/localnet/get-kmd-wallet-account.mjs.map +1 -1
- package/localnet/get-localnet-dispenser-account.d.ts +7 -5
- package/localnet/get-localnet-dispenser-account.js +17 -15
- package/localnet/get-localnet-dispenser-account.js.map +1 -1
- package/localnet/get-localnet-dispenser-account.mjs +17 -13
- package/localnet/get-localnet-dispenser-account.mjs.map +1 -1
- package/localnet/get-or-create-kmd-wallet-account.d.ts +10 -8
- package/localnet/get-or-create-kmd-wallet-account.js +28 -26
- package/localnet/get-or-create-kmd-wallet-account.js.map +1 -1
- package/localnet/get-or-create-kmd-wallet-account.mjs +28 -24
- package/localnet/get-or-create-kmd-wallet-account.mjs.map +1 -1
- package/localnet/is-localnet.d.ts +7 -3
- package/localnet/is-localnet.js +9 -10
- package/localnet/is-localnet.js.map +1 -1
- package/localnet/is-localnet.mjs +9 -8
- package/localnet/is-localnet.mjs.map +1 -1
- package/network-client.d.ts +17 -15
- package/network-client.js +115 -116
- package/network-client.js.map +1 -1
- package/network-client.mjs +115 -114
- package/network-client.mjs.map +1 -1
- package/package.json +12 -3
- package/testing/account.d.ts +11 -9
- package/testing/account.js +31 -33
- package/testing/account.js.map +1 -1
- package/testing/account.mjs +29 -31
- package/testing/account.mjs.map +1 -1
- package/testing/fixtures/algokit-log-capture-fixture.d.ts +7 -2
- package/testing/fixtures/algokit-log-capture-fixture.js +36 -41
- package/testing/fixtures/algokit-log-capture-fixture.js.map +1 -1
- package/testing/fixtures/algokit-log-capture-fixture.mjs +36 -39
- package/testing/fixtures/algokit-log-capture-fixture.mjs.map +1 -1
- package/testing/fixtures/algorand-fixture.d.ts +9 -4
- package/testing/fixtures/algorand-fixture.js +67 -62
- package/testing/fixtures/algorand-fixture.js.map +1 -1
- package/testing/fixtures/algorand-fixture.mjs +66 -59
- package/testing/fixtures/algorand-fixture.mjs.map +1 -1
- package/testing/index.d.ts +7 -5
- package/testing/index.js +13 -18
- package/testing/index.mjs +7 -7
- package/testing/indexer.d.ts +5 -1
- package/testing/indexer.js +28 -37
- package/testing/indexer.js.map +1 -1
- package/testing/indexer.mjs +28 -35
- package/testing/indexer.mjs.map +1 -1
- package/testing/test-logger.d.ts +41 -36
- package/testing/test-logger.js +71 -76
- package/testing/test-logger.js.map +1 -1
- package/testing/test-logger.mjs +71 -74
- package/testing/test-logger.mjs.map +1 -1
- package/testing/transaction-logger.d.ts +30 -27
- package/testing/transaction-logger.js +77 -93
- package/testing/transaction-logger.js.map +1 -1
- package/testing/transaction-logger.mjs +74 -90
- package/testing/transaction-logger.mjs.map +1 -1
- package/transaction/legacy-bridge.js +100 -111
- package/transaction/legacy-bridge.js.map +1 -1
- package/transaction/legacy-bridge.mjs +97 -108
- package/transaction/legacy-bridge.mjs.map +1 -1
- package/transaction/perform-atomic-transaction-composer-simulate.d.ts +7 -5
- package/transaction/perform-atomic-transaction-composer-simulate.js +31 -36
- package/transaction/perform-atomic-transaction-composer-simulate.js.map +1 -1
- package/transaction/perform-atomic-transaction-composer-simulate.mjs +28 -33
- package/transaction/perform-atomic-transaction-composer-simulate.mjs.map +1 -1
- package/transaction/transaction.d.ts +34 -35
- package/transaction/transaction.js +716 -914
- package/transaction/transaction.js.map +1 -1
- package/transaction/transaction.mjs +713 -911
- package/transaction/transaction.mjs.map +1 -1
- package/transfer/transfer-algos.d.ts +9 -5
- package/transfer/transfer-algos.js +26 -27
- package/transfer/transfer-algos.js.map +1 -1
- package/transfer/transfer-algos.mjs +26 -25
- package/transfer/transfer-algos.mjs.map +1 -1
- package/transfer/transfer.d.ts +11 -8
- package/transfer/transfer.js +94 -100
- package/transfer/transfer.js.map +1 -1
- package/transfer/transfer.mjs +94 -98
- package/transfer/transfer.mjs.map +1 -1
- package/types/account-manager.d.ts +432 -429
- package/types/account-manager.js +591 -602
- package/types/account-manager.js.map +1 -1
- package/types/account-manager.mjs +587 -599
- package/types/account-manager.mjs.map +1 -1
- package/types/account.d.ts +192 -202
- package/types/account.js +91 -88
- package/types/account.js.map +1 -1
- package/types/account.mjs +88 -86
- package/types/account.mjs.map +1 -1
- package/types/algo-http-client-with-retry.d.ts +15 -10
- package/types/algo-http-client-with-retry.js +70 -92
- package/types/algo-http-client-with-retry.js.map +1 -1
- package/types/algo-http-client-with-retry.mjs +69 -90
- package/types/algo-http-client-with-retry.mjs.map +1 -1
- package/types/algorand-client-transaction-creator.d.ts +778 -771
- package/types/algorand-client-transaction-creator.js +733 -732
- package/types/algorand-client-transaction-creator.js.map +1 -1
- package/types/algorand-client-transaction-creator.mjs +732 -730
- package/types/algorand-client-transaction-creator.mjs.map +1 -1
- package/types/algorand-client-transaction-sender.d.ts +1090 -1360
- package/types/algorand-client-transaction-sender.js +930 -961
- package/types/algorand-client-transaction-sender.js.map +1 -1
- package/types/algorand-client-transaction-sender.mjs +927 -959
- package/types/algorand-client-transaction-sender.mjs.map +1 -1
- package/types/algorand-client.d.ts +239 -236
- package/types/algorand-client.js +322 -320
- package/types/algorand-client.js.map +1 -1
- package/types/algorand-client.mjs +321 -318
- package/types/algorand-client.mjs.map +1 -1
- package/types/amount.d.ts +47 -43
- package/types/amount.js +66 -70
- package/types/amount.js.map +1 -1
- package/types/amount.mjs +63 -68
- package/types/amount.mjs.map +1 -1
- package/types/app-arc56.d.ts +235 -272
- package/types/app-arc56.js +124 -170
- package/types/app-arc56.js.map +1 -1
- package/types/app-arc56.mjs +121 -168
- package/types/app-arc56.mjs.map +1 -1
- package/types/app-client.d.ts +1128 -2009
- package/types/app-client.js +1633 -1791
- package/types/app-client.js.map +1 -1
- package/types/app-client.mjs +1624 -1783
- package/types/app-client.mjs.map +1 -1
- package/types/app-deployer.d.ts +139 -141
- package/types/app-deployer.js +344 -384
- package/types/app-deployer.js.map +1 -1
- package/types/app-deployer.mjs +341 -382
- package/types/app-deployer.mjs.map +1 -1
- package/types/app-factory.d.ts +762 -932
- package/types/app-factory.js +496 -488
- package/types/app-factory.js.map +1 -1
- package/types/app-factory.mjs +491 -484
- package/types/app-factory.mjs.map +1 -1
- package/types/app-manager.d.ts +304 -310
- package/types/app-manager.js +422 -475
- package/types/app-manager.js.map +1 -1
- package/types/app-manager.mjs +419 -473
- package/types/app-manager.mjs.map +1 -1
- package/types/app-spec.d.ts +118 -117
- package/types/app-spec.js +125 -135
- package/types/app-spec.js.map +1 -1
- package/types/app-spec.mjs +121 -132
- package/types/app-spec.mjs.map +1 -1
- package/types/app.d.ts +229 -241
- package/types/app.js +36 -28
- package/types/app.js.map +1 -1
- package/types/app.mjs +33 -26
- package/types/app.mjs.map +1 -1
- package/types/asset-manager.d.ts +204 -199
- package/types/asset-manager.js +165 -174
- package/types/asset-manager.js.map +1 -1
- package/types/asset-manager.mjs +164 -172
- package/types/asset-manager.mjs.map +1 -1
- package/types/asset.d.ts +95 -91
- package/types/asset.js +0 -3
- package/types/asset.mjs +0 -2
- package/types/async-event-emitter.d.ts +18 -13
- package/types/async-event-emitter.js +37 -49
- package/types/async-event-emitter.js.map +1 -1
- package/types/async-event-emitter.mjs +36 -47
- package/types/async-event-emitter.mjs.map +1 -1
- package/types/client-manager.d.ts +453 -451
- package/types/client-manager.js +602 -598
- package/types/client-manager.js.map +1 -1
- package/types/client-manager.mjs +597 -594
- package/types/client-manager.mjs.map +1 -1
- package/types/composer.d.ts +1211 -1258
- package/types/composer.js +1436 -1498
- package/types/composer.js.map +1 -1
- package/types/composer.mjs +1430 -1493
- package/types/composer.mjs.map +1 -1
- package/types/config.d.ts +53 -48
- package/types/config.js +78 -77
- package/types/config.js.map +1 -1
- package/types/config.mjs +77 -75
- package/types/config.mjs.map +1 -1
- package/types/debugging.d.ts +25 -23
- package/types/debugging.js +9 -11
- package/types/debugging.js.map +1 -1
- package/types/debugging.mjs +8 -9
- package/types/debugging.mjs.map +1 -1
- package/types/dispenser-client.d.ts +57 -52
- package/types/dispenser-client.js +120 -141
- package/types/dispenser-client.js.map +1 -1
- package/types/dispenser-client.mjs +119 -139
- package/types/dispenser-client.mjs.map +1 -1
- package/types/expand.d.ts +5 -3
- package/types/expand.js +0 -3
- package/types/expand.mjs +0 -2
- package/types/indexer.d.ts +104 -100
- package/types/indexer.js +36 -31
- package/types/indexer.js.map +1 -1
- package/types/indexer.mjs +32 -30
- package/types/indexer.mjs.map +1 -1
- package/types/instance-of.d.ts +5 -3
- package/types/instance-of.js +0 -3
- package/types/instance-of.mjs +0 -2
- package/types/kmd-account-manager.d.ts +75 -70
- package/types/kmd-account-manager.js +150 -184
- package/types/kmd-account-manager.js.map +1 -1
- package/types/kmd-account-manager.mjs +147 -182
- package/types/kmd-account-manager.mjs.map +1 -1
- package/types/lifecycle-events.d.ts +13 -8
- package/types/lifecycle-events.js +10 -7
- package/types/lifecycle-events.js.map +1 -1
- package/types/lifecycle-events.mjs +9 -7
- package/types/lifecycle-events.mjs.map +1 -1
- package/types/logging.d.ts +15 -11
- package/types/logging.js +30 -31
- package/types/logging.js.map +1 -1
- package/types/logging.mjs +29 -29
- package/types/logging.mjs.map +1 -1
- package/types/logic-error.d.ts +33 -29
- package/types/logic-error.js +50 -49
- package/types/logic-error.js.map +1 -1
- package/types/logic-error.mjs +49 -47
- package/types/logic-error.mjs.map +1 -1
- package/types/network-client.d.ts +32 -27
- package/types/network-client.js +10 -9
- package/types/network-client.js.map +1 -1
- package/types/network-client.mjs +9 -7
- package/types/network-client.mjs.map +1 -1
- package/types/testing.d.ts +131 -132
- package/types/testing.js +0 -3
- package/types/testing.mjs +0 -2
- package/types/transaction.d.ts +110 -110
- package/types/transaction.js +0 -3
- package/types/transaction.mjs +0 -2
- package/types/transfer.d.ts +70 -66
- package/types/transfer.js +0 -3
- package/types/transfer.mjs +0 -2
- package/util.js +73 -118
- package/util.js.map +1 -1
- package/util.mjs +73 -116
- package/util.mjs.map +1 -1
- package/account/index.d.ts +0 -5
- package/debugging/index.d.ts +0 -1
- package/index.js.map +0 -1
- package/index.mjs.map +0 -1
- package/localnet/index.d.ts +0 -4
- package/testing/_asset.d.ts +0 -3
- package/testing/fixtures/index.d.ts +0 -2
- package/testing/index.js.map +0 -1
- package/testing/index.mjs.map +0 -1
- package/transaction/index.d.ts +0 -2
- package/transaction/legacy-bridge.d.ts +0 -35
- package/transfer/index.d.ts +0 -2
- package/types/asset.js.map +0 -1
- package/types/asset.mjs.map +0 -1
- package/types/expand.js.map +0 -1
- package/types/expand.mjs.map +0 -1
- package/types/instance-of.js.map +0 -1
- package/types/instance-of.mjs.map +0 -1
- package/types/testing.js.map +0 -1
- package/types/testing.mjs.map +0 -1
- package/types/transaction.js.map +0 -1
- package/types/transaction.mjs.map +0 -1
- package/types/transfer.js.map +0 -1
- package/types/transfer.mjs.map +0 -1
- package/util.d.ts +0 -48
package/util.mjs
CHANGED
|
@@ -1,144 +1,101 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { APP_PAGE_MAX_SIZE } from "./types/app.mjs";
|
|
2
|
+
import { ABIArrayDynamicType, ABIArrayStaticType, ABIByteType, ABITupleType, ABIUintType } from "algosdk";
|
|
3
|
+
//#region src/util.ts
|
|
4
4
|
/**
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
* Converts a value which might be a number or a bigint into a number to be used with apis that don't support bigint.
|
|
6
|
+
*
|
|
7
|
+
* Throws an UnsafeConversionError if the conversion would result in an unsafe integer for the Number type
|
|
8
|
+
* @param value
|
|
9
|
+
*/
|
|
10
10
|
const toNumber = (value) => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
else if (value < BigInt(Number.MIN_SAFE_INTEGER)) {
|
|
17
|
-
throw new UnsafeConversionError(`Cannot convert ${value} to a Number as it is smaller than the minimum safe integer the Number type can hold.`);
|
|
18
|
-
}
|
|
19
|
-
return Number(value);
|
|
11
|
+
if (typeof value === "number") return value;
|
|
12
|
+
if (value > BigInt(Number.MAX_SAFE_INTEGER)) throw new UnsafeConversionError(`Cannot convert ${value} to a Number as it is larger than the maximum safe integer the Number type can hold.`);
|
|
13
|
+
else if (value < BigInt(Number.MIN_SAFE_INTEGER)) throw new UnsafeConversionError(`Cannot convert ${value} to a Number as it is smaller than the minimum safe integer the Number type can hold.`);
|
|
14
|
+
return Number(value);
|
|
20
15
|
};
|
|
21
|
-
|
|
22
|
-
}
|
|
16
|
+
var UnsafeConversionError = class extends Error {};
|
|
23
17
|
/**
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
18
|
+
* Calculates the amount of funds to add to a wallet to bring it up to the minimum spending balance.
|
|
19
|
+
* @param minSpendingBalance The minimum spending balance for the wallet
|
|
20
|
+
* @param currentSpendingBalance The current spending balance for the wallet
|
|
21
|
+
* @param minFundingIncrement The minimum amount of funds that can be added to the wallet
|
|
22
|
+
* @returns The amount of funds to add to the wallet or null if the wallet is already above the minimum spending balance
|
|
23
|
+
*/
|
|
30
24
|
const calculateFundAmount = (minSpendingBalance, currentSpendingBalance, minFundingIncrement) => {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
else {
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
25
|
+
if (minSpendingBalance > currentSpendingBalance) {
|
|
26
|
+
const minFundAmount = minSpendingBalance - currentSpendingBalance;
|
|
27
|
+
return BigInt(Math.max(Number(minFundAmount), Number(minFundingIncrement)));
|
|
28
|
+
} else return null;
|
|
38
29
|
};
|
|
39
30
|
/**
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
31
|
+
* Returns the given array split into chunks of `batchSize` batches.
|
|
32
|
+
* @param array The array to chunk
|
|
33
|
+
* @param batchSize The size of batches to split the array into
|
|
34
|
+
* @returns A generator that yields the array split into chunks of `batchSize` batches
|
|
35
|
+
*/
|
|
45
36
|
function* chunkArray(array, batchSize) {
|
|
46
|
-
|
|
47
|
-
yield array.slice(i, i + batchSize);
|
|
37
|
+
for (let i = 0; i < array.length; i += batchSize) yield array.slice(i, i + batchSize);
|
|
48
38
|
}
|
|
49
39
|
/**
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
40
|
+
* Memoize calls to the given function in an in-memory map.
|
|
41
|
+
* @param fn The function to memoize
|
|
42
|
+
* @returns The memoized function
|
|
43
|
+
*/
|
|
54
44
|
const memoize = (fn) => {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
45
|
+
const cache = /* @__PURE__ */ new Map();
|
|
46
|
+
const cached = function(val) {
|
|
47
|
+
return cache.has(val) ? cache.get(val) : cache.set(val, fn.call(this, val)) && cache.get(val);
|
|
48
|
+
};
|
|
49
|
+
cached.cache = cache;
|
|
50
|
+
return cached;
|
|
61
51
|
};
|
|
62
52
|
const binaryStartsWith = (base, startsWith) => {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if (base[i] !== startsWith[i])
|
|
67
|
-
return false;
|
|
68
|
-
}
|
|
69
|
-
return true;
|
|
53
|
+
if (startsWith.length > base.length) return false;
|
|
54
|
+
for (let i = 0; i < startsWith.length; i++) if (base[i] !== startsWith[i]) return false;
|
|
55
|
+
return true;
|
|
70
56
|
};
|
|
71
57
|
const defaultJsonValueReplacer = (key, value) => {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
return value;
|
|
58
|
+
if (typeof value === "bigint") try {
|
|
59
|
+
return toNumber(value);
|
|
60
|
+
} catch {
|
|
61
|
+
return value.toString();
|
|
62
|
+
}
|
|
63
|
+
return value;
|
|
81
64
|
};
|
|
82
65
|
const asJson = (value, replacer = defaultJsonValueReplacer, space) => {
|
|
83
|
-
|
|
66
|
+
return JSON.stringify(value, replacer, space);
|
|
84
67
|
};
|
|
85
68
|
/** Calculate minimum number of extra program pages required for provided approval and clear state programs */
|
|
86
69
|
const calculateExtraProgramPages = (approvalProgram, clearStateProgram) => {
|
|
87
|
-
|
|
70
|
+
return Math.floor((approvalProgram.length + (clearStateProgram?.length ?? 0) - 1) / APP_PAGE_MAX_SIZE);
|
|
88
71
|
};
|
|
89
72
|
/** Take a decoded ABI value and convert all byte arrays (including nested ones) from number[] to Uint8Arrays */
|
|
90
73
|
function convertAbiByteArrays(value, type) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
for (let i = 0; i < value.length; i++) {
|
|
105
|
-
result.push(convertAbiByteArrays(value[i], type.childType));
|
|
106
|
-
}
|
|
107
|
-
return result;
|
|
108
|
-
}
|
|
109
|
-
// Handle tuples (for nested structures)
|
|
110
|
-
if (type instanceof ABITupleType && Array.isArray(value)) {
|
|
111
|
-
const result = [];
|
|
112
|
-
for (let i = 0; i < value.length && i < type.childTypes.length; i++) {
|
|
113
|
-
result.push(convertAbiByteArrays(value[i], type.childTypes[i]));
|
|
114
|
-
}
|
|
115
|
-
return result;
|
|
116
|
-
}
|
|
117
|
-
// For other types, return the value as is
|
|
118
|
-
return value;
|
|
74
|
+
if (!type.toString().includes("byte") || value instanceof Uint8Array) return value;
|
|
75
|
+
if ((type instanceof ABIArrayStaticType || type instanceof ABIArrayDynamicType) && type.childType instanceof ABIByteType && Array.isArray(value)) return new Uint8Array(value);
|
|
76
|
+
if ((type instanceof ABIArrayStaticType || type instanceof ABIArrayDynamicType) && Array.isArray(value)) {
|
|
77
|
+
const result = [];
|
|
78
|
+
for (let i = 0; i < value.length; i++) result.push(convertAbiByteArrays(value[i], type.childType));
|
|
79
|
+
return result;
|
|
80
|
+
}
|
|
81
|
+
if (type instanceof ABITupleType && Array.isArray(value)) {
|
|
82
|
+
const result = [];
|
|
83
|
+
for (let i = 0; i < value.length && i < type.childTypes.length; i++) result.push(convertAbiByteArrays(value[i], type.childTypes[i]));
|
|
84
|
+
return result;
|
|
85
|
+
}
|
|
86
|
+
return value;
|
|
119
87
|
}
|
|
120
88
|
/**
|
|
121
|
-
|
|
122
|
-
|
|
89
|
+
* Convert bigint values to numbers for uint types with bit size < 53
|
|
90
|
+
*/
|
|
123
91
|
const convertABIDecodedBigIntToNumber = (value, type) => {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
return value;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
else if (Array.isArray(value) && (type instanceof ABIArrayStaticType || type instanceof ABIArrayDynamicType)) {
|
|
133
|
-
return value.map((v) => convertABIDecodedBigIntToNumber(v, type.childType));
|
|
134
|
-
}
|
|
135
|
-
else if (Array.isArray(value) && type instanceof ABITupleType) {
|
|
136
|
-
return value.map((v, i) => convertABIDecodedBigIntToNumber(v, type.childTypes[i]));
|
|
137
|
-
}
|
|
138
|
-
else {
|
|
139
|
-
return value;
|
|
140
|
-
}
|
|
92
|
+
if (typeof value === "bigint") if (type instanceof ABIUintType) return type.bitSize < 53 ? Number(value) : value;
|
|
93
|
+
else return value;
|
|
94
|
+
else if (Array.isArray(value) && (type instanceof ABIArrayStaticType || type instanceof ABIArrayDynamicType)) return value.map((v) => convertABIDecodedBigIntToNumber(v, type.childType));
|
|
95
|
+
else if (Array.isArray(value) && type instanceof ABITupleType) return value.map((v, i) => convertABIDecodedBigIntToNumber(v, type.childTypes[i]));
|
|
96
|
+
else return value;
|
|
141
97
|
};
|
|
142
|
-
|
|
98
|
+
//#endregion
|
|
143
99
|
export { UnsafeConversionError, asJson, binaryStartsWith, calculateExtraProgramPages, calculateFundAmount, chunkArray, convertABIDecodedBigIntToNumber, convertAbiByteArrays, defaultJsonValueReplacer, memoize, toNumber };
|
|
144
|
-
|
|
100
|
+
|
|
101
|
+
//# sourceMappingURL=util.mjs.map
|
package/util.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.mjs","sources":["../src/util.ts"],"sourcesContent":["import { ABIArrayDynamicType, ABIArrayStaticType, ABIByteType, ABIReturnType, ABITupleType, ABIType, ABIUintType, ABIValue } from 'algosdk'\nimport { APP_PAGE_MAX_SIZE } from './types/app'\n\n/**\n * Converts a value which might be a number or a bigint into a number to be used with apis that don't support bigint.\n *\n * Throws an UnsafeConversionError if the conversion would result in an unsafe integer for the Number type\n * @param value\n */\nexport const toNumber = (value: number | bigint) => {\n if (typeof value === 'number') return value\n\n if (value > BigInt(Number.MAX_SAFE_INTEGER)) {\n throw new UnsafeConversionError(\n `Cannot convert ${value} to a Number as it is larger than the maximum safe integer the Number type can hold.`,\n )\n } else if (value < BigInt(Number.MIN_SAFE_INTEGER)) {\n throw new UnsafeConversionError(\n `Cannot convert ${value} to a Number as it is smaller than the minimum safe integer the Number type can hold.`,\n )\n }\n return Number(value)\n}\n\nexport class UnsafeConversionError extends Error {}\n\n/**\n * Calculates the amount of funds to add to a wallet to bring it up to the minimum spending balance.\n * @param minSpendingBalance The minimum spending balance for the wallet\n * @param currentSpendingBalance The current spending balance for the wallet\n * @param minFundingIncrement The minimum amount of funds that can be added to the wallet\n * @returns The amount of funds to add to the wallet or null if the wallet is already above the minimum spending balance\n */\nexport const calculateFundAmount = (\n minSpendingBalance: bigint,\n currentSpendingBalance: bigint,\n minFundingIncrement: bigint,\n): bigint | null => {\n if (minSpendingBalance > currentSpendingBalance) {\n const minFundAmount = minSpendingBalance - currentSpendingBalance\n return BigInt(Math.max(Number(minFundAmount), Number(minFundingIncrement)))\n } else {\n return null\n }\n}\n\n/**\n * Checks if the current environment is Node.js\n *\n * @returns A boolean indicating whether the current environment is Node.js\n */\nexport const isNode = () => {\n return typeof process !== 'undefined' && process.versions != null && process.versions.node != null\n}\n\n/**\n * Returns the given array split into chunks of `batchSize` batches.\n * @param array The array to chunk\n * @param batchSize The size of batches to split the array into\n * @returns A generator that yields the array split into chunks of `batchSize` batches\n */\nexport function* chunkArray<T>(array: T[], batchSize: number): Generator<T[], void> {\n for (let i = 0; i < array.length; i += batchSize) yield array.slice(i, i + batchSize)\n}\n\n/**\n * Memoize calls to the given function in an in-memory map.\n * @param fn The function to memoize\n * @returns The memoized function\n */\nexport const memoize = <T = unknown, R = unknown>(fn: (val: T) => R) => {\n const cache = new Map()\n const cached = function (this: unknown, val: T) {\n return cache.has(val) ? cache.get(val) : cache.set(val, fn.call(this, val)) && cache.get(val)\n }\n cached.cache = cache\n return cached as (val: T) => R\n}\n\nexport const binaryStartsWith = (base: Uint8Array, startsWith: Uint8Array): boolean => {\n if (startsWith.length > base.length) return false\n for (let i = 0; i < startsWith.length; i++) {\n if (base[i] !== startsWith[i]) return false\n }\n return true\n}\n\nexport const defaultJsonValueReplacer = (key: string, value: unknown) => {\n if (typeof value === 'bigint') {\n try {\n return toNumber(value)\n } catch {\n return value.toString()\n }\n }\n return value\n}\nexport const asJson = (\n value: unknown,\n replacer: (key: string, value: unknown) => unknown = defaultJsonValueReplacer,\n space?: string | number,\n) => {\n return JSON.stringify(value, replacer, space)\n}\n\n/** Calculate minimum number of extra program pages required for provided approval and clear state programs */\nexport const calculateExtraProgramPages = (approvalProgram: Uint8Array, clearStateProgram?: Uint8Array): number => {\n return Math.floor((approvalProgram.length + (clearStateProgram?.length ?? 0) - 1) / APP_PAGE_MAX_SIZE)\n}\n\n/** Take a decoded ABI value and convert all byte arrays (including nested ones) from number[] to Uint8Arrays */\nexport function convertAbiByteArrays(value: ABIValue, type: ABIReturnType): ABIValue {\n // Return value as is if the type doesn't have any bytes or if it's already an Uint8Array\n if (!type.toString().includes('byte') || value instanceof Uint8Array) {\n return value\n }\n\n // Handle byte arrays (byte[N] or byte[])\n if (\n (type instanceof ABIArrayStaticType || type instanceof ABIArrayDynamicType) &&\n type.childType instanceof ABIByteType &&\n Array.isArray(value)\n ) {\n return new Uint8Array(value as number[])\n }\n\n // Handle other arrays (for nested structures)\n if ((type instanceof ABIArrayStaticType || type instanceof ABIArrayDynamicType) && Array.isArray(value)) {\n const result = []\n for (let i = 0; i < value.length; i++) {\n result.push(convertAbiByteArrays(value[i], type.childType))\n }\n return result\n }\n\n // Handle tuples (for nested structures)\n if (type instanceof ABITupleType && Array.isArray(value)) {\n const result = []\n for (let i = 0; i < value.length && i < type.childTypes.length; i++) {\n result.push(convertAbiByteArrays(value[i], type.childTypes[i]))\n }\n return result\n }\n\n // For other types, return the value as is\n return value\n}\n\n/**\n * Convert bigint values to numbers for uint types with bit size < 53\n */\nexport const convertABIDecodedBigIntToNumber = (value: ABIValue, type: ABIType): ABIValue => {\n if (typeof value === 'bigint') {\n if (type instanceof ABIUintType) {\n return type.bitSize < 53 ? Number(value) : value\n } else {\n return value\n }\n } else if (Array.isArray(value) && (type instanceof ABIArrayStaticType || type instanceof ABIArrayDynamicType)) {\n return value.map((v) => convertABIDecodedBigIntToNumber(v, type.childType))\n } else if (Array.isArray(value) && type instanceof ABITupleType) {\n return value.map((v, i) => convertABIDecodedBigIntToNumber(v, type.childTypes[i]))\n } else {\n return value\n }\n}\n"],"names":[],"mappings":";;;AAGA;;;;;AAKG;AACU,MAAA,QAAQ,GAAG,CAAC,KAAsB,KAAI;IACjD,IAAI,OAAO,KAAK,KAAK,QAAQ;AAAE,QAAA,OAAO,KAAK;IAE3C,IAAI,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,EAAE;AAC3C,QAAA,MAAM,IAAI,qBAAqB,CAC7B,kBAAkB,KAAK,CAAA,oFAAA,CAAsF,CAC9G;;SACI,IAAI,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,EAAE;AAClD,QAAA,MAAM,IAAI,qBAAqB,CAC7B,kBAAkB,KAAK,CAAA,qFAAA,CAAuF,CAC/G;;AAEH,IAAA,OAAO,MAAM,CAAC,KAAK,CAAC;AACtB;AAEM,MAAO,qBAAsB,SAAQ,KAAK,CAAA;AAAG;AAEnD;;;;;;AAMG;AACU,MAAA,mBAAmB,GAAG,CACjC,kBAA0B,EAC1B,sBAA8B,EAC9B,mBAA2B,KACV;AACjB,IAAA,IAAI,kBAAkB,GAAG,sBAAsB,EAAE;AAC/C,QAAA,MAAM,aAAa,GAAG,kBAAkB,GAAG,sBAAsB;AACjE,QAAA,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC,mBAAmB,CAAC,CAAC,CAAC;;SACtE;AACL,QAAA,OAAO,IAAI;;AAEf;AAWA;;;;;AAKG;UACc,UAAU,CAAI,KAAU,EAAE,SAAiB,EAAA;AAC1D,IAAA,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,IAAI,SAAS;QAAE,MAAM,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,SAA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,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;AACnE,YAAA,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;;AAEjE,QAAA,OAAO,MAAM;;;AAIf,IAAA,OAAO,KAAK;AACd;AAEA;;AAEG;MACU,+BAA+B,GAAG,CAAC,KAAe,EAAE,IAAa,KAAc;AAC1F,IAAA,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;AAC7B,QAAA,IAAI,IAAI,YAAY,WAAW,EAAE;AAC/B,YAAA,OAAO,IAAI,CAAC,OAAO,GAAG,EAAE,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,KAAK;;aAC3C;AACL,YAAA,OAAO,KAAK;;;AAET,SAAA,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,IAAI,YAAY,kBAAkB,IAAI,IAAI,YAAY,mBAAmB,CAAC,EAAE;AAC9G,QAAA,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,+BAA+B,CAAC,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;;SACtE,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,IAAI,YAAY,YAAY,EAAE;QAC/D,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,+BAA+B,CAAC,CAAC,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;;SAC7E;AACL,QAAA,OAAO,KAAK;;AAEhB;;;;"}
|
|
1
|
+
{"version":3,"file":"util.mjs","names":[],"sources":["../src/util.ts"],"sourcesContent":["import { ABIArrayDynamicType, ABIArrayStaticType, ABIByteType, ABIReturnType, ABITupleType, ABIType, ABIUintType, ABIValue } from 'algosdk'\nimport { APP_PAGE_MAX_SIZE } from './types/app'\n\n/**\n * Converts a value which might be a number or a bigint into a number to be used with apis that don't support bigint.\n *\n * Throws an UnsafeConversionError if the conversion would result in an unsafe integer for the Number type\n * @param value\n */\nexport const toNumber = (value: number | bigint) => {\n if (typeof value === 'number') return value\n\n if (value > BigInt(Number.MAX_SAFE_INTEGER)) {\n throw new UnsafeConversionError(\n `Cannot convert ${value} to a Number as it is larger than the maximum safe integer the Number type can hold.`,\n )\n } else if (value < BigInt(Number.MIN_SAFE_INTEGER)) {\n throw new UnsafeConversionError(\n `Cannot convert ${value} to a Number as it is smaller than the minimum safe integer the Number type can hold.`,\n )\n }\n return Number(value)\n}\n\nexport class UnsafeConversionError extends Error {}\n\n/**\n * Calculates the amount of funds to add to a wallet to bring it up to the minimum spending balance.\n * @param minSpendingBalance The minimum spending balance for the wallet\n * @param currentSpendingBalance The current spending balance for the wallet\n * @param minFundingIncrement The minimum amount of funds that can be added to the wallet\n * @returns The amount of funds to add to the wallet or null if the wallet is already above the minimum spending balance\n */\nexport const calculateFundAmount = (\n minSpendingBalance: bigint,\n currentSpendingBalance: bigint,\n minFundingIncrement: bigint,\n): bigint | null => {\n if (minSpendingBalance > currentSpendingBalance) {\n const minFundAmount = minSpendingBalance - currentSpendingBalance\n return BigInt(Math.max(Number(minFundAmount), Number(minFundingIncrement)))\n } else {\n return null\n }\n}\n\n/**\n * Checks if the current environment is Node.js\n *\n * @returns A boolean indicating whether the current environment is Node.js\n */\nexport const isNode = () => {\n return typeof process !== 'undefined' && process.versions != null && process.versions.node != null\n}\n\n/**\n * Returns the given array split into chunks of `batchSize` batches.\n * @param array The array to chunk\n * @param batchSize The size of batches to split the array into\n * @returns A generator that yields the array split into chunks of `batchSize` batches\n */\nexport function* chunkArray<T>(array: T[], batchSize: number): Generator<T[], void> {\n for (let i = 0; i < array.length; i += batchSize) yield array.slice(i, i + batchSize)\n}\n\n/**\n * Memoize calls to the given function in an in-memory map.\n * @param fn The function to memoize\n * @returns The memoized function\n */\nexport const memoize = <T = unknown, R = unknown>(fn: (val: T) => R) => {\n const cache = new Map()\n const cached = function (this: unknown, val: T) {\n return cache.has(val) ? cache.get(val) : cache.set(val, fn.call(this, val)) && cache.get(val)\n }\n cached.cache = cache\n return cached as (val: T) => R\n}\n\nexport const binaryStartsWith = (base: Uint8Array, startsWith: Uint8Array): boolean => {\n if (startsWith.length > base.length) return false\n for (let i = 0; i < startsWith.length; i++) {\n if (base[i] !== startsWith[i]) return false\n }\n return true\n}\n\nexport const defaultJsonValueReplacer = (key: string, value: unknown) => {\n if (typeof value === 'bigint') {\n try {\n return toNumber(value)\n } catch {\n return value.toString()\n }\n }\n return value\n}\nexport const asJson = (\n value: unknown,\n replacer: (key: string, value: unknown) => unknown = defaultJsonValueReplacer,\n space?: string | number,\n) => {\n return JSON.stringify(value, replacer, space)\n}\n\n/** Calculate minimum number of extra program pages required for provided approval and clear state programs */\nexport const calculateExtraProgramPages = (approvalProgram: Uint8Array, clearStateProgram?: Uint8Array): number => {\n return Math.floor((approvalProgram.length + (clearStateProgram?.length ?? 0) - 1) / APP_PAGE_MAX_SIZE)\n}\n\n/** Take a decoded ABI value and convert all byte arrays (including nested ones) from number[] to Uint8Arrays */\nexport function convertAbiByteArrays(value: ABIValue, type: ABIReturnType): ABIValue {\n // Return value as is if the type doesn't have any bytes or if it's already an Uint8Array\n if (!type.toString().includes('byte') || value instanceof Uint8Array) {\n return value\n }\n\n // Handle byte arrays (byte[N] or byte[])\n if (\n (type instanceof ABIArrayStaticType || type instanceof ABIArrayDynamicType) &&\n type.childType instanceof ABIByteType &&\n Array.isArray(value)\n ) {\n return new Uint8Array(value as number[])\n }\n\n // Handle other arrays (for nested structures)\n if ((type instanceof ABIArrayStaticType || type instanceof ABIArrayDynamicType) && Array.isArray(value)) {\n const result = []\n for (let i = 0; i < value.length; i++) {\n result.push(convertAbiByteArrays(value[i], type.childType))\n }\n return result\n }\n\n // Handle tuples (for nested structures)\n if (type instanceof ABITupleType && Array.isArray(value)) {\n const result = []\n for (let i = 0; i < value.length && i < type.childTypes.length; i++) {\n result.push(convertAbiByteArrays(value[i], type.childTypes[i]))\n }\n return result\n }\n\n // For other types, return the value as is\n return value\n}\n\n/**\n * Convert bigint values to numbers for uint types with bit size < 53\n */\nexport const convertABIDecodedBigIntToNumber = (value: ABIValue, type: ABIType): ABIValue => {\n if (typeof value === 'bigint') {\n if (type instanceof ABIUintType) {\n return type.bitSize < 53 ? Number(value) : value\n } else {\n return value\n }\n } else if (Array.isArray(value) && (type instanceof ABIArrayStaticType || type instanceof ABIArrayDynamicType)) {\n return value.map((v) => convertABIDecodedBigIntToNumber(v, type.childType))\n } else if (Array.isArray(value) && type instanceof ABITupleType) {\n return value.map((v, i) => convertABIDecodedBigIntToNumber(v, type.childTypes[i]))\n } else {\n return value\n }\n}\n"],"mappings":";;;;;;;;;AASA,MAAa,YAAY,UAA2B;CAClD,IAAI,OAAO,UAAU,UAAU,OAAO;CAEtC,IAAI,QAAQ,OAAO,OAAO,gBAAgB,GACxC,MAAM,IAAI,sBACR,kBAAkB,MAAM,qFAC1B;MACK,IAAI,QAAQ,OAAO,OAAO,gBAAgB,GAC/C,MAAM,IAAI,sBACR,kBAAkB,MAAM,sFAC1B;CAEF,OAAO,OAAO,KAAK;AACrB;AAEA,IAAa,wBAAb,cAA2C,MAAM,CAAC;;;;;;;;AASlD,MAAa,uBACX,oBACA,wBACA,wBACkB;CAClB,IAAI,qBAAqB,wBAAwB;EAC/C,MAAM,gBAAgB,qBAAqB;EAC3C,OAAO,OAAO,KAAK,IAAI,OAAO,aAAa,GAAG,OAAO,mBAAmB,CAAC,CAAC;CAC5E,OACE,OAAO;AAEX;;;;;;;AAiBA,UAAiB,WAAc,OAAY,WAAyC;CAClF,KAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK,WAAW,MAAM,MAAM,MAAM,GAAG,IAAI,SAAS;AACtF;;;;;;AAOA,MAAa,WAAqC,OAAsB;CACtE,MAAM,wBAAQ,IAAI,IAAI;CACtB,MAAM,SAAS,SAAyB,KAAQ;EAC9C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AM,SAAS,CAAC;EAChB,KAAK,IAAI,IAAI,GAAG,IAAI,MAAM,UAAU,IAAI,KAAK,WAAW,QAAQ,KAC9D,OAAO,KAAK,qBAAqB,MAAM,IAAI,KAAK,WAAW,EAAE,CAAC;EAEhE,OAAO;CACT;CAGA,OAAO;AACT;;;;AAKA,MAAa,mCAAmC,OAAiB,SAA4B;CAC3F,IAAI,OAAO,UAAU,UACnB,IAAI,gBAAgB,aAClB,OAAO,KAAK,UAAU,KAAK,OAAO,KAAK,IAAI;MAE3C,OAAO;MAEJ,IAAI,MAAM,QAAQ,KAAK,MAAM,gBAAgB,sBAAsB,gBAAgB,sBACxF,OAAO,MAAM,KAAK,MAAM,gCAAgC,GAAG,KAAK,SAAS,CAAC;MACrE,IAAI,MAAM,QAAQ,KAAK,KAAK,gBAAgB,cACjD,OAAO,MAAM,KAAK,GAAG,MAAM,gCAAgC,GAAG,KAAK,WAAW,EAAE,CAAC;MAEjF,OAAO;AAEX"}
|
package/account/index.d.ts
DELETED
package/debugging/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './debugging';
|
package/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/localnet/index.d.ts
DELETED
package/testing/_asset.d.ts
DELETED
package/testing/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;"}
|
package/testing/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;"}
|
package/transaction/index.d.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import algosdk from 'algosdk';
|
|
2
|
-
import { AlgorandClientTransactionCreator } from '../types/algorand-client-transaction-creator';
|
|
3
|
-
import { AlgorandClientTransactionSender } from '../types/algorand-client-transaction-sender';
|
|
4
|
-
import { ABIAppCallArgs, BoxIdentifier as LegacyBoxIdentifier, BoxReference as LegacyBoxReference, RawAppCallArgs } from '../types/app';
|
|
5
|
-
import { AppCallMethodCall, AppCallParams, AppCreateMethodCall, AppCreateParams, AppDeleteMethodCall, AppDeleteParams, AppUpdateMethodCall, AppUpdateParams, BuiltTransactions, CommonTransactionParams } from '../types/composer';
|
|
6
|
-
import { SendParams, SendSingleTransactionResult, SendTransactionFrom, SendTransactionParams, SendTransactionResult, TransactionNote } from '../types/transaction';
|
|
7
|
-
import Algodv2 = algosdk.Algodv2;
|
|
8
|
-
import Transaction = algosdk.Transaction;
|
|
9
|
-
/** @deprecated Bridges between legacy `sendTransaction` behaviour and new `AlgorandClient` behaviour. */
|
|
10
|
-
export declare function legacySendTransactionBridge<T extends CommonTransactionParams, TResult extends SendSingleTransactionResult>(algod: Algodv2, from: SendTransactionFrom, sendParams: SendTransactionParams, params: T, txn: ((c: AlgorandClientTransactionCreator) => (params: T) => Promise<Transaction>) | ((c: AlgorandClientTransactionCreator) => (params: T) => Promise<BuiltTransactions>), send: (c: AlgorandClientTransactionSender) => (params: T & SendParams) => Promise<TResult>, suggestedParams?: algosdk.SuggestedParams): Promise<(SendTransactionResult | TResult) & {
|
|
11
|
-
transactions: Transaction[];
|
|
12
|
-
}>;
|
|
13
|
-
/** @deprecated Bridges between legacy `sendTransaction` behaviour for app transactions and new `AlgorandClient` behaviour. */
|
|
14
|
-
export declare function legacySendAppTransactionBridge<T extends AppCreateParams | AppUpdateParams | AppDeleteParams | AppCallParams | AppCreateMethodCall | AppUpdateMethodCall | AppDeleteMethodCall | AppCallMethodCall, TResult extends SendSingleTransactionResult>(algod: Algodv2, from: SendTransactionFrom, appArgs: RawAppCallArgs | ABIAppCallArgs | undefined, sendParams: SendTransactionParams & {
|
|
15
|
-
note?: TransactionNote;
|
|
16
|
-
}, params: Omit<T, 'accountReferences' | 'appReferences' | 'assetReferences' | 'boxReferences' | 'args' | 'lease' | 'rekeyTo' | 'note'>, txn: ((c: AlgorandClientTransactionCreator) => (params: T) => Promise<Transaction>) | ((c: AlgorandClientTransactionCreator) => (params: T) => Promise<BuiltTransactions>), send: (c: AlgorandClientTransactionSender) => (params: T & SendParams) => Promise<TResult>, suggestedParams?: algosdk.SuggestedParams): Promise<(SendTransactionResult | TResult) & {
|
|
17
|
-
transactions: Transaction[];
|
|
18
|
-
}>;
|
|
19
|
-
/**
|
|
20
|
-
* @deprecated
|
|
21
|
-
*/
|
|
22
|
-
export declare function _getAppArgsForABICall(args: ABIAppCallArgs, from: SendTransactionFrom): Promise<{
|
|
23
|
-
method: algosdk.ABIMethod;
|
|
24
|
-
sender: string;
|
|
25
|
-
signer: algosdk.TransactionSigner;
|
|
26
|
-
boxes: algosdk.BoxReference[] | undefined;
|
|
27
|
-
lease: Uint8Array | undefined;
|
|
28
|
-
appForeignApps: number[] | undefined;
|
|
29
|
-
appForeignAssets: number[] | undefined;
|
|
30
|
-
appAccounts: string[] | undefined;
|
|
31
|
-
methodArgs: (string | number | bigint | boolean | algosdk.Address | Uint8Array | algosdk.ABIValue[] | algosdk.TransactionWithSigner)[];
|
|
32
|
-
rekeyTo: string | undefined;
|
|
33
|
-
}>;
|
|
34
|
-
/** @deprecated */
|
|
35
|
-
export declare function _getBoxReference(box: LegacyBoxIdentifier | LegacyBoxReference | algosdk.BoxReference): algosdk.BoxReference;
|
package/transfer/index.d.ts
DELETED
package/types/asset.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"asset.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
package/types/asset.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"asset.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/types/expand.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"expand.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
package/types/expand.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"expand.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/types/instance-of.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"instance-of.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"instance-of.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/types/testing.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"testing.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
package/types/testing.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"testing.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/types/transaction.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"transaction.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"transaction.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/types/transfer.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"transfer.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
package/types/transfer.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"transfer.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/util.d.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { ABIReturnType, ABIType, ABIValue } from 'algosdk';
|
|
2
|
-
/**
|
|
3
|
-
* Converts a value which might be a number or a bigint into a number to be used with apis that don't support bigint.
|
|
4
|
-
*
|
|
5
|
-
* Throws an UnsafeConversionError if the conversion would result in an unsafe integer for the Number type
|
|
6
|
-
* @param value
|
|
7
|
-
*/
|
|
8
|
-
export declare const toNumber: (value: number | bigint) => number;
|
|
9
|
-
export declare class UnsafeConversionError extends Error {
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Calculates the amount of funds to add to a wallet to bring it up to the minimum spending balance.
|
|
13
|
-
* @param minSpendingBalance The minimum spending balance for the wallet
|
|
14
|
-
* @param currentSpendingBalance The current spending balance for the wallet
|
|
15
|
-
* @param minFundingIncrement The minimum amount of funds that can be added to the wallet
|
|
16
|
-
* @returns The amount of funds to add to the wallet or null if the wallet is already above the minimum spending balance
|
|
17
|
-
*/
|
|
18
|
-
export declare const calculateFundAmount: (minSpendingBalance: bigint, currentSpendingBalance: bigint, minFundingIncrement: bigint) => bigint | null;
|
|
19
|
-
/**
|
|
20
|
-
* Checks if the current environment is Node.js
|
|
21
|
-
*
|
|
22
|
-
* @returns A boolean indicating whether the current environment is Node.js
|
|
23
|
-
*/
|
|
24
|
-
export declare const isNode: () => boolean;
|
|
25
|
-
/**
|
|
26
|
-
* Returns the given array split into chunks of `batchSize` batches.
|
|
27
|
-
* @param array The array to chunk
|
|
28
|
-
* @param batchSize The size of batches to split the array into
|
|
29
|
-
* @returns A generator that yields the array split into chunks of `batchSize` batches
|
|
30
|
-
*/
|
|
31
|
-
export declare function chunkArray<T>(array: T[], batchSize: number): Generator<T[], void>;
|
|
32
|
-
/**
|
|
33
|
-
* Memoize calls to the given function in an in-memory map.
|
|
34
|
-
* @param fn The function to memoize
|
|
35
|
-
* @returns The memoized function
|
|
36
|
-
*/
|
|
37
|
-
export declare const memoize: <T = unknown, R = unknown>(fn: (val: T) => R) => (val: T) => R;
|
|
38
|
-
export declare const binaryStartsWith: (base: Uint8Array, startsWith: Uint8Array) => boolean;
|
|
39
|
-
export declare const defaultJsonValueReplacer: (key: string, value: unknown) => unknown;
|
|
40
|
-
export declare const asJson: (value: unknown, replacer?: (key: string, value: unknown) => unknown, space?: string | number) => string;
|
|
41
|
-
/** Calculate minimum number of extra program pages required for provided approval and clear state programs */
|
|
42
|
-
export declare const calculateExtraProgramPages: (approvalProgram: Uint8Array, clearStateProgram?: Uint8Array) => number;
|
|
43
|
-
/** Take a decoded ABI value and convert all byte arrays (including nested ones) from number[] to Uint8Arrays */
|
|
44
|
-
export declare function convertAbiByteArrays(value: ABIValue, type: ABIReturnType): ABIValue;
|
|
45
|
-
/**
|
|
46
|
-
* Convert bigint values to numbers for uint types with bit size < 53
|
|
47
|
-
*/
|
|
48
|
-
export declare const convertABIDecodedBigIntToNumber: (value: ABIValue, type: ABIType) => ABIValue;
|