@hyperlane-xyz/utils 1.4.3-beta0 → 1.4.3-beta1
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/dist/index.d.ts +21 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +115 -29
- package/dist/index.js.map +1 -1
- package/dist/src/addresses.d.ts +29 -0
- package/dist/src/addresses.d.ts.map +1 -0
- package/dist/src/addresses.js +202 -0
- package/dist/src/addresses.js.map +1 -0
- package/dist/src/amount.d.ts +9 -0
- package/dist/src/amount.d.ts.map +1 -0
- package/dist/src/amount.js +79 -0
- package/dist/src/amount.js.map +1 -0
- package/dist/src/arrays.d.ts +8 -0
- package/dist/src/arrays.d.ts.map +1 -0
- package/dist/src/arrays.js +16 -0
- package/dist/src/arrays.js.map +1 -0
- package/dist/src/async.d.ts +37 -0
- package/dist/src/async.d.ts.map +1 -0
- package/dist/src/async.js +106 -0
- package/dist/src/async.js.map +1 -0
- package/dist/src/base64.d.ts +3 -0
- package/dist/src/base64.d.ts.map +1 -0
- package/dist/src/base64.js +30 -0
- package/dist/src/base64.js.map +1 -0
- package/dist/src/big-numbers.d.ts +36 -0
- package/dist/src/big-numbers.d.ts.map +1 -0
- package/dist/src/big-numbers.js +93 -0
- package/dist/src/big-numbers.js.map +1 -0
- package/dist/src/big-numbers.test.d.ts +2 -0
- package/dist/src/big-numbers.test.d.ts.map +1 -0
- package/dist/src/big-numbers.test.js +41 -0
- package/dist/src/big-numbers.test.js.map +1 -0
- package/dist/src/calldata.d.ts +3 -0
- package/dist/src/calldata.d.ts.map +1 -0
- package/dist/src/calldata.js +8 -0
- package/dist/src/calldata.js.map +1 -0
- package/dist/src/checkpoints.d.ts +5 -0
- package/dist/src/checkpoints.d.ts.map +1 -0
- package/dist/src/checkpoints.js +30 -0
- package/dist/src/checkpoints.js.map +1 -0
- package/dist/src/domains.d.ts +2 -0
- package/dist/src/domains.d.ts.map +1 -0
- package/dist/src/domains.js +10 -0
- package/dist/src/domains.js.map +1 -0
- package/dist/src/env.d.ts +2 -0
- package/dist/src/env.d.ts.map +1 -0
- package/dist/src/env.js +15 -0
- package/dist/src/env.js.map +1 -0
- package/dist/src/ids.d.ts +20 -0
- package/dist/src/ids.d.ts.map +1 -0
- package/dist/src/ids.js +47 -0
- package/dist/src/ids.js.map +1 -0
- package/dist/src/logging.js +5 -7
- package/dist/src/logging.js.map +1 -1
- package/dist/src/math.d.ts +5 -0
- package/dist/src/math.d.ts.map +1 -0
- package/dist/src/math.js +25 -0
- package/dist/src/math.js.map +1 -0
- package/dist/src/messages.d.ts +21 -0
- package/dist/src/messages.d.ts.map +1 -0
- package/dist/src/messages.js +58 -0
- package/dist/src/messages.js.map +1 -0
- package/dist/src/multisig.d.ts +4 -0
- package/dist/src/multisig.d.ts.map +1 -0
- package/dist/src/multisig.js +57 -0
- package/dist/src/multisig.js.map +1 -0
- package/dist/src/objects.d.ts +18 -0
- package/dist/src/objects.d.ts.map +1 -0
- package/dist/src/objects.js +84 -0
- package/dist/src/objects.js.map +1 -0
- package/dist/src/sets.d.ts +4 -0
- package/dist/src/sets.d.ts.map +1 -0
- package/dist/src/sets.js +30 -0
- package/dist/src/sets.js.map +1 -0
- package/dist/src/strings.d.ts +7 -0
- package/dist/src/strings.d.ts.map +1 -0
- package/dist/src/strings.js +51 -0
- package/dist/src/strings.js.map +1 -0
- package/dist/src/typeof.d.ts +3 -0
- package/dist/src/typeof.d.ts.map +1 -0
- package/dist/src/typeof.js +15 -0
- package/dist/src/typeof.js.map +1 -0
- package/dist/src/types.d.ts +23 -13
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.js +13 -3
- package/dist/src/types.js.map +1 -1
- package/dist/src/validation.d.ts +2 -0
- package/dist/src/validation.d.ts.map +1 -0
- package/dist/src/validation.js +10 -0
- package/dist/src/validation.js.map +1 -0
- package/dist/src/validator.d.ts.map +1 -1
- package/dist/src/validator.js +33 -20
- package/dist/src/validator.js.map +1 -1
- package/package.json +9 -6
- package/dist/src/utils.d.ts +0 -57
- package/dist/src/utils.d.ts.map +0 -1
- package/dist/src/utils.js +0 -307
- package/dist/src/utils.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,23 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export {
|
|
1
|
+
export { addressToByteHexString, addressToBytes, addressToBytes32, addressToBytesSol, adressToBytesEvm, bytes32ToAddress, capitalizeAddress, convertToProtocolAddress, ensure0x, eqAddress, eqAddressEvm, eqAddressSol, getAddressProtocolType, isAddressEvm, isAddressSealevel, isValidAddress, isValidAddressEvm, isValidAddressSealevel, isValidTransactionHash, isValidTransactionHashEvm, isValidTransactionHashSealevel, isZeroishAddress, normalizeAddress, normalizeAddressEvm, normalizeAddressSealevel, shortenAddress, strip0x, } from './src/addresses';
|
|
2
|
+
export { eqAmountApproximate, fromWei, fromWeiRounded, toWei, tryParseAmount, } from './src/amount';
|
|
3
|
+
export { chunk, exclude } from './src/arrays';
|
|
4
|
+
export { pollAsync, retryAsync, runWithTimeout, sleep, timeout, } from './src/async';
|
|
5
|
+
export { fromBase64, toBase64 } from './src/base64';
|
|
6
|
+
export { BigNumberMax, BigNumberMin, bigToFixed, convertDecimalValue, fixedToBig, isBigNumberish, isZeroish, mulBigAndFixed, } from './src/big-numbers';
|
|
7
|
+
export { formatCallData } from './src/calldata';
|
|
8
|
+
export { isCheckpoint, isS3Checkpoint, isS3CheckpointWithId, } from './src/checkpoints';
|
|
9
|
+
export { domainHash } from './src/domains';
|
|
10
|
+
export { safelyAccessEnvVar } from './src/env';
|
|
11
|
+
export { canonizeId, evmId } from './src/ids';
|
|
12
|
+
export { debug, error, log, trace, warn } from './src/logging';
|
|
13
|
+
export { mean, median, stdDev, sum } from './src/math';
|
|
14
|
+
export { formatMessage, messageId, parseMessage } from './src/messages';
|
|
15
|
+
export { formatLegacyMultisigIsmMetadata, parseLegacyMultisigIsmMetadata, } from './src/multisig';
|
|
16
|
+
export { ValueOf, arrayToObject, deepEquals, invertKeysAndValues, isObject, objFilter, objMap, objMapEntries, objMerge, pick, promiseObjAll, } from './src/objects';
|
|
17
|
+
export { difference, setEquality, symmetricDifference } from './src/sets';
|
|
18
|
+
export { errorToString, sanitizeString, streamToString, toTitleCase, trimToLength, } from './src/strings';
|
|
19
|
+
export { isNullish, isNumeric } from './src/typeof';
|
|
20
|
+
export { Address, AddressBytes32, CallData, Checkpoint, Domain, HexString, InterchainSecurityModuleType, MerkleProof, MessageStatus, ParsedLegacyMultisigIsmMetadata, ParsedMessage, ProtocolSmallestUnit, ProtocolType, ProtocolTypeValue, S3Checkpoint, S3CheckpointWithId, SignatureLike, } from './src/types';
|
|
21
|
+
export { assert } from './src/validation';
|
|
5
22
|
export { BaseValidator, Validator } from './src/validator';
|
|
6
23
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,wBAAwB,EACxB,QAAQ,EACR,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,sBAAsB,EACtB,YAAY,EACZ,iBAAiB,EACjB,cAAc,EACd,iBAAiB,EACjB,sBAAsB,EACtB,sBAAsB,EACtB,yBAAyB,EACzB,8BAA8B,EAC9B,gBAAgB,EAChB,gBAAgB,EAChB,mBAAmB,EACnB,wBAAwB,EACxB,cAAc,EACd,OAAO,GACR,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,mBAAmB,EACnB,OAAO,EACP,cAAc,EACd,KAAK,EACL,cAAc,GACf,MAAM,cAAc,CA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ACd,cAAc,EACd,WAAW,EACX,YAAY,GACb,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EACL,OAAO,EACP,cAAc,EACd,QAAQ,EACR,UAAU,EACV,MAAM,EACN,SAAS,EACT,4BAA4B,EAC5B,WAAW,EACX,aAAa,EACb,+BAA+B,EAC/B,aAAa,EACb,oBAAoB,EACpB,YAAY,EACZ,iBAAiB,EACjB,YAAY,EACZ,kBAAkB,EAClB,aAAa,GACd,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,38 +1,124 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
27
|
-
exports.
|
|
28
|
-
|
|
29
|
-
exports
|
|
3
|
+
exports.formatCallData = exports.mulBigAndFixed = exports.isZeroish = exports.isBigNumberish = exports.fixedToBig = exports.convertDecimalValue = exports.bigToFixed = exports.BigNumberMin = exports.BigNumberMax = exports.toBase64 = exports.fromBase64 = exports.timeout = exports.sleep = exports.runWithTimeout = exports.retryAsync = exports.pollAsync = exports.exclude = exports.chunk = exports.tryParseAmount = exports.toWei = exports.fromWeiRounded = exports.fromWei = exports.eqAmountApproximate = exports.strip0x = exports.shortenAddress = exports.normalizeAddressSealevel = exports.normalizeAddressEvm = exports.normalizeAddress = exports.isZeroishAddress = exports.isValidTransactionHashSealevel = exports.isValidTransactionHashEvm = exports.isValidTransactionHash = exports.isValidAddressSealevel = exports.isValidAddressEvm = exports.isValidAddress = exports.isAddressSealevel = exports.isAddressEvm = exports.getAddressProtocolType = exports.eqAddressSol = exports.eqAddressEvm = exports.eqAddress = exports.ensure0x = exports.convertToProtocolAddress = exports.capitalizeAddress = exports.bytes32ToAddress = exports.adressToBytesEvm = exports.addressToBytesSol = exports.addressToBytes32 = exports.addressToBytes = exports.addressToByteHexString = void 0;
|
|
4
|
+
exports.Validator = exports.BaseValidator = exports.assert = exports.ProtocolType = exports.ProtocolSmallestUnit = exports.MessageStatus = exports.InterchainSecurityModuleType = exports.isNumeric = exports.isNullish = exports.trimToLength = exports.toTitleCase = exports.streamToString = exports.sanitizeString = exports.errorToString = exports.symmetricDifference = exports.setEquality = exports.difference = exports.promiseObjAll = exports.pick = exports.objMerge = exports.objMapEntries = exports.objMap = exports.objFilter = exports.isObject = exports.invertKeysAndValues = exports.deepEquals = exports.arrayToObject = exports.parseLegacyMultisigIsmMetadata = exports.formatLegacyMultisigIsmMetadata = exports.parseMessage = exports.messageId = exports.formatMessage = exports.sum = exports.stdDev = exports.median = exports.mean = exports.warn = exports.trace = exports.log = exports.error = exports.debug = exports.evmId = exports.canonizeId = exports.safelyAccessEnvVar = exports.domainHash = exports.isS3CheckpointWithId = exports.isS3Checkpoint = exports.isCheckpoint = void 0;
|
|
5
|
+
var addresses_1 = require("./src/addresses");
|
|
6
|
+
Object.defineProperty(exports, "addressToByteHexString", { enumerable: true, get: function () { return addresses_1.addressToByteHexString; } });
|
|
7
|
+
Object.defineProperty(exports, "addressToBytes", { enumerable: true, get: function () { return addresses_1.addressToBytes; } });
|
|
8
|
+
Object.defineProperty(exports, "addressToBytes32", { enumerable: true, get: function () { return addresses_1.addressToBytes32; } });
|
|
9
|
+
Object.defineProperty(exports, "addressToBytesSol", { enumerable: true, get: function () { return addresses_1.addressToBytesSol; } });
|
|
10
|
+
Object.defineProperty(exports, "adressToBytesEvm", { enumerable: true, get: function () { return addresses_1.adressToBytesEvm; } });
|
|
11
|
+
Object.defineProperty(exports, "bytes32ToAddress", { enumerable: true, get: function () { return addresses_1.bytes32ToAddress; } });
|
|
12
|
+
Object.defineProperty(exports, "capitalizeAddress", { enumerable: true, get: function () { return addresses_1.capitalizeAddress; } });
|
|
13
|
+
Object.defineProperty(exports, "convertToProtocolAddress", { enumerable: true, get: function () { return addresses_1.convertToProtocolAddress; } });
|
|
14
|
+
Object.defineProperty(exports, "ensure0x", { enumerable: true, get: function () { return addresses_1.ensure0x; } });
|
|
15
|
+
Object.defineProperty(exports, "eqAddress", { enumerable: true, get: function () { return addresses_1.eqAddress; } });
|
|
16
|
+
Object.defineProperty(exports, "eqAddressEvm", { enumerable: true, get: function () { return addresses_1.eqAddressEvm; } });
|
|
17
|
+
Object.defineProperty(exports, "eqAddressSol", { enumerable: true, get: function () { return addresses_1.eqAddressSol; } });
|
|
18
|
+
Object.defineProperty(exports, "getAddressProtocolType", { enumerable: true, get: function () { return addresses_1.getAddressProtocolType; } });
|
|
19
|
+
Object.defineProperty(exports, "isAddressEvm", { enumerable: true, get: function () { return addresses_1.isAddressEvm; } });
|
|
20
|
+
Object.defineProperty(exports, "isAddressSealevel", { enumerable: true, get: function () { return addresses_1.isAddressSealevel; } });
|
|
21
|
+
Object.defineProperty(exports, "isValidAddress", { enumerable: true, get: function () { return addresses_1.isValidAddress; } });
|
|
22
|
+
Object.defineProperty(exports, "isValidAddressEvm", { enumerable: true, get: function () { return addresses_1.isValidAddressEvm; } });
|
|
23
|
+
Object.defineProperty(exports, "isValidAddressSealevel", { enumerable: true, get: function () { return addresses_1.isValidAddressSealevel; } });
|
|
24
|
+
Object.defineProperty(exports, "isValidTransactionHash", { enumerable: true, get: function () { return addresses_1.isValidTransactionHash; } });
|
|
25
|
+
Object.defineProperty(exports, "isValidTransactionHashEvm", { enumerable: true, get: function () { return addresses_1.isValidTransactionHashEvm; } });
|
|
26
|
+
Object.defineProperty(exports, "isValidTransactionHashSealevel", { enumerable: true, get: function () { return addresses_1.isValidTransactionHashSealevel; } });
|
|
27
|
+
Object.defineProperty(exports, "isZeroishAddress", { enumerable: true, get: function () { return addresses_1.isZeroishAddress; } });
|
|
28
|
+
Object.defineProperty(exports, "normalizeAddress", { enumerable: true, get: function () { return addresses_1.normalizeAddress; } });
|
|
29
|
+
Object.defineProperty(exports, "normalizeAddressEvm", { enumerable: true, get: function () { return addresses_1.normalizeAddressEvm; } });
|
|
30
|
+
Object.defineProperty(exports, "normalizeAddressSealevel", { enumerable: true, get: function () { return addresses_1.normalizeAddressSealevel; } });
|
|
31
|
+
Object.defineProperty(exports, "shortenAddress", { enumerable: true, get: function () { return addresses_1.shortenAddress; } });
|
|
32
|
+
Object.defineProperty(exports, "strip0x", { enumerable: true, get: function () { return addresses_1.strip0x; } });
|
|
33
|
+
var amount_1 = require("./src/amount");
|
|
34
|
+
Object.defineProperty(exports, "eqAmountApproximate", { enumerable: true, get: function () { return amount_1.eqAmountApproximate; } });
|
|
35
|
+
Object.defineProperty(exports, "fromWei", { enumerable: true, get: function () { return amount_1.fromWei; } });
|
|
36
|
+
Object.defineProperty(exports, "fromWeiRounded", { enumerable: true, get: function () { return amount_1.fromWeiRounded; } });
|
|
37
|
+
Object.defineProperty(exports, "toWei", { enumerable: true, get: function () { return amount_1.toWei; } });
|
|
38
|
+
Object.defineProperty(exports, "tryParseAmount", { enumerable: true, get: function () { return amount_1.tryParseAmount; } });
|
|
39
|
+
var arrays_1 = require("./src/arrays");
|
|
40
|
+
Object.defineProperty(exports, "chunk", { enumerable: true, get: function () { return arrays_1.chunk; } });
|
|
41
|
+
Object.defineProperty(exports, "exclude", { enumerable: true, get: function () { return arrays_1.exclude; } });
|
|
42
|
+
var async_1 = require("./src/async");
|
|
43
|
+
Object.defineProperty(exports, "pollAsync", { enumerable: true, get: function () { return async_1.pollAsync; } });
|
|
44
|
+
Object.defineProperty(exports, "retryAsync", { enumerable: true, get: function () { return async_1.retryAsync; } });
|
|
45
|
+
Object.defineProperty(exports, "runWithTimeout", { enumerable: true, get: function () { return async_1.runWithTimeout; } });
|
|
46
|
+
Object.defineProperty(exports, "sleep", { enumerable: true, get: function () { return async_1.sleep; } });
|
|
47
|
+
Object.defineProperty(exports, "timeout", { enumerable: true, get: function () { return async_1.timeout; } });
|
|
48
|
+
var base64_1 = require("./src/base64");
|
|
49
|
+
Object.defineProperty(exports, "fromBase64", { enumerable: true, get: function () { return base64_1.fromBase64; } });
|
|
50
|
+
Object.defineProperty(exports, "toBase64", { enumerable: true, get: function () { return base64_1.toBase64; } });
|
|
51
|
+
var big_numbers_1 = require("./src/big-numbers");
|
|
52
|
+
Object.defineProperty(exports, "BigNumberMax", { enumerable: true, get: function () { return big_numbers_1.BigNumberMax; } });
|
|
53
|
+
Object.defineProperty(exports, "BigNumberMin", { enumerable: true, get: function () { return big_numbers_1.BigNumberMin; } });
|
|
54
|
+
Object.defineProperty(exports, "bigToFixed", { enumerable: true, get: function () { return big_numbers_1.bigToFixed; } });
|
|
55
|
+
Object.defineProperty(exports, "convertDecimalValue", { enumerable: true, get: function () { return big_numbers_1.convertDecimalValue; } });
|
|
56
|
+
Object.defineProperty(exports, "fixedToBig", { enumerable: true, get: function () { return big_numbers_1.fixedToBig; } });
|
|
57
|
+
Object.defineProperty(exports, "isBigNumberish", { enumerable: true, get: function () { return big_numbers_1.isBigNumberish; } });
|
|
58
|
+
Object.defineProperty(exports, "isZeroish", { enumerable: true, get: function () { return big_numbers_1.isZeroish; } });
|
|
59
|
+
Object.defineProperty(exports, "mulBigAndFixed", { enumerable: true, get: function () { return big_numbers_1.mulBigAndFixed; } });
|
|
60
|
+
var calldata_1 = require("./src/calldata");
|
|
61
|
+
Object.defineProperty(exports, "formatCallData", { enumerable: true, get: function () { return calldata_1.formatCallData; } });
|
|
62
|
+
var checkpoints_1 = require("./src/checkpoints");
|
|
63
|
+
Object.defineProperty(exports, "isCheckpoint", { enumerable: true, get: function () { return checkpoints_1.isCheckpoint; } });
|
|
64
|
+
Object.defineProperty(exports, "isS3Checkpoint", { enumerable: true, get: function () { return checkpoints_1.isS3Checkpoint; } });
|
|
65
|
+
Object.defineProperty(exports, "isS3CheckpointWithId", { enumerable: true, get: function () { return checkpoints_1.isS3CheckpointWithId; } });
|
|
66
|
+
var domains_1 = require("./src/domains");
|
|
67
|
+
Object.defineProperty(exports, "domainHash", { enumerable: true, get: function () { return domains_1.domainHash; } });
|
|
68
|
+
var env_1 = require("./src/env");
|
|
69
|
+
Object.defineProperty(exports, "safelyAccessEnvVar", { enumerable: true, get: function () { return env_1.safelyAccessEnvVar; } });
|
|
70
|
+
var ids_1 = require("./src/ids");
|
|
71
|
+
Object.defineProperty(exports, "canonizeId", { enumerable: true, get: function () { return ids_1.canonizeId; } });
|
|
72
|
+
Object.defineProperty(exports, "evmId", { enumerable: true, get: function () { return ids_1.evmId; } });
|
|
30
73
|
var logging_1 = require("./src/logging");
|
|
74
|
+
Object.defineProperty(exports, "debug", { enumerable: true, get: function () { return logging_1.debug; } });
|
|
31
75
|
Object.defineProperty(exports, "error", { enumerable: true, get: function () { return logging_1.error; } });
|
|
32
|
-
Object.defineProperty(exports, "warn", { enumerable: true, get: function () { return logging_1.warn; } });
|
|
33
76
|
Object.defineProperty(exports, "log", { enumerable: true, get: function () { return logging_1.log; } });
|
|
34
|
-
Object.defineProperty(exports, "debug", { enumerable: true, get: function () { return logging_1.debug; } });
|
|
35
77
|
Object.defineProperty(exports, "trace", { enumerable: true, get: function () { return logging_1.trace; } });
|
|
78
|
+
Object.defineProperty(exports, "warn", { enumerable: true, get: function () { return logging_1.warn; } });
|
|
79
|
+
var math_1 = require("./src/math");
|
|
80
|
+
Object.defineProperty(exports, "mean", { enumerable: true, get: function () { return math_1.mean; } });
|
|
81
|
+
Object.defineProperty(exports, "median", { enumerable: true, get: function () { return math_1.median; } });
|
|
82
|
+
Object.defineProperty(exports, "stdDev", { enumerable: true, get: function () { return math_1.stdDev; } });
|
|
83
|
+
Object.defineProperty(exports, "sum", { enumerable: true, get: function () { return math_1.sum; } });
|
|
84
|
+
var messages_1 = require("./src/messages");
|
|
85
|
+
Object.defineProperty(exports, "formatMessage", { enumerable: true, get: function () { return messages_1.formatMessage; } });
|
|
86
|
+
Object.defineProperty(exports, "messageId", { enumerable: true, get: function () { return messages_1.messageId; } });
|
|
87
|
+
Object.defineProperty(exports, "parseMessage", { enumerable: true, get: function () { return messages_1.parseMessage; } });
|
|
88
|
+
var multisig_1 = require("./src/multisig");
|
|
89
|
+
Object.defineProperty(exports, "formatLegacyMultisigIsmMetadata", { enumerable: true, get: function () { return multisig_1.formatLegacyMultisigIsmMetadata; } });
|
|
90
|
+
Object.defineProperty(exports, "parseLegacyMultisigIsmMetadata", { enumerable: true, get: function () { return multisig_1.parseLegacyMultisigIsmMetadata; } });
|
|
91
|
+
var objects_1 = require("./src/objects");
|
|
92
|
+
Object.defineProperty(exports, "arrayToObject", { enumerable: true, get: function () { return objects_1.arrayToObject; } });
|
|
93
|
+
Object.defineProperty(exports, "deepEquals", { enumerable: true, get: function () { return objects_1.deepEquals; } });
|
|
94
|
+
Object.defineProperty(exports, "invertKeysAndValues", { enumerable: true, get: function () { return objects_1.invertKeysAndValues; } });
|
|
95
|
+
Object.defineProperty(exports, "isObject", { enumerable: true, get: function () { return objects_1.isObject; } });
|
|
96
|
+
Object.defineProperty(exports, "objFilter", { enumerable: true, get: function () { return objects_1.objFilter; } });
|
|
97
|
+
Object.defineProperty(exports, "objMap", { enumerable: true, get: function () { return objects_1.objMap; } });
|
|
98
|
+
Object.defineProperty(exports, "objMapEntries", { enumerable: true, get: function () { return objects_1.objMapEntries; } });
|
|
99
|
+
Object.defineProperty(exports, "objMerge", { enumerable: true, get: function () { return objects_1.objMerge; } });
|
|
100
|
+
Object.defineProperty(exports, "pick", { enumerable: true, get: function () { return objects_1.pick; } });
|
|
101
|
+
Object.defineProperty(exports, "promiseObjAll", { enumerable: true, get: function () { return objects_1.promiseObjAll; } });
|
|
102
|
+
var sets_1 = require("./src/sets");
|
|
103
|
+
Object.defineProperty(exports, "difference", { enumerable: true, get: function () { return sets_1.difference; } });
|
|
104
|
+
Object.defineProperty(exports, "setEquality", { enumerable: true, get: function () { return sets_1.setEquality; } });
|
|
105
|
+
Object.defineProperty(exports, "symmetricDifference", { enumerable: true, get: function () { return sets_1.symmetricDifference; } });
|
|
106
|
+
var strings_1 = require("./src/strings");
|
|
107
|
+
Object.defineProperty(exports, "errorToString", { enumerable: true, get: function () { return strings_1.errorToString; } });
|
|
108
|
+
Object.defineProperty(exports, "sanitizeString", { enumerable: true, get: function () { return strings_1.sanitizeString; } });
|
|
109
|
+
Object.defineProperty(exports, "streamToString", { enumerable: true, get: function () { return strings_1.streamToString; } });
|
|
110
|
+
Object.defineProperty(exports, "toTitleCase", { enumerable: true, get: function () { return strings_1.toTitleCase; } });
|
|
111
|
+
Object.defineProperty(exports, "trimToLength", { enumerable: true, get: function () { return strings_1.trimToLength; } });
|
|
112
|
+
var typeof_1 = require("./src/typeof");
|
|
113
|
+
Object.defineProperty(exports, "isNullish", { enumerable: true, get: function () { return typeof_1.isNullish; } });
|
|
114
|
+
Object.defineProperty(exports, "isNumeric", { enumerable: true, get: function () { return typeof_1.isNumeric; } });
|
|
115
|
+
var types_1 = require("./src/types");
|
|
116
|
+
Object.defineProperty(exports, "InterchainSecurityModuleType", { enumerable: true, get: function () { return types_1.InterchainSecurityModuleType; } });
|
|
117
|
+
Object.defineProperty(exports, "MessageStatus", { enumerable: true, get: function () { return types_1.MessageStatus; } });
|
|
118
|
+
Object.defineProperty(exports, "ProtocolSmallestUnit", { enumerable: true, get: function () { return types_1.ProtocolSmallestUnit; } });
|
|
119
|
+
Object.defineProperty(exports, "ProtocolType", { enumerable: true, get: function () { return types_1.ProtocolType; } });
|
|
120
|
+
var validation_1 = require("./src/validation");
|
|
121
|
+
Object.defineProperty(exports, "assert", { enumerable: true, get: function () { return validation_1.assert; } });
|
|
36
122
|
var validator_1 = require("./src/validator");
|
|
37
123
|
Object.defineProperty(exports, "BaseValidator", { enumerable: true, get: function () { return validator_1.BaseValidator; } });
|
|
38
124
|
Object.defineProperty(exports, "Validator", { enumerable: true, get: function () { return validator_1.Validator; } });
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;AAAA,6CA4ByB;AA3BvB,mHAAA,sBAAsB,OAAA;AACtB,2GAAA,cAAc,OAAA;AACd,6GAAA,gBAAgB,OAAA;AAChB,8GAAA,iBAAiB,OAAA;AACjB,6GAAA,gBAAgB,OAAA;AAChB,6GAAA,gBAAgB,OAAA;AAChB,8GAAA,iBAAiB,OAAA;AACjB,qHAAA,wBAAwB,OAAA;AACxB,qGAAA,QAAQ,OAAA;AACR,sGAAA,SAAS,OAAA;AACT,yGAAA,YAAY,OAAA;AACZ,yGAAA,YAAY,OAAA;AACZ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f,6CAA2D;AAAlD,0GAAA,aAAa,OAAA;AAAE,sGAAA,SAAS,OAAA"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Address, HexString, ProtocolType } from './types';
|
|
2
|
+
export declare function isAddressEvm(address: Address): boolean;
|
|
3
|
+
export declare function isAddressSealevel(address: Address): boolean;
|
|
4
|
+
export declare function getAddressProtocolType(address: Address): ProtocolType.Ethereum | ProtocolType.Sealevel | undefined;
|
|
5
|
+
export declare function isValidAddressEvm(address: Address): boolean;
|
|
6
|
+
export declare function isValidAddressSealevel(address: Address): boolean;
|
|
7
|
+
export declare function isValidAddress(address: Address, protocol?: ProtocolType): boolean;
|
|
8
|
+
export declare function normalizeAddressEvm(address: Address): string;
|
|
9
|
+
export declare function normalizeAddressSealevel(address: Address): string;
|
|
10
|
+
export declare function normalizeAddress(address: Address, protocol?: ProtocolType): string;
|
|
11
|
+
export declare function eqAddressEvm(a1: Address, a2: Address): boolean;
|
|
12
|
+
export declare function eqAddressSol(a1: Address, a2: Address): boolean;
|
|
13
|
+
export declare function eqAddress(a1: Address, a2: Address): boolean;
|
|
14
|
+
export declare function isValidTransactionHashEvm(input: string): boolean;
|
|
15
|
+
export declare function isValidTransactionHashSealevel(input: string): boolean;
|
|
16
|
+
export declare function isValidTransactionHash(input: string, protocol?: ProtocolType): boolean;
|
|
17
|
+
export declare function isZeroishAddress(address: Address): boolean;
|
|
18
|
+
export declare function shortenAddress(address: Address, capitalize?: boolean): string;
|
|
19
|
+
export declare function capitalizeAddress(address: Address): string;
|
|
20
|
+
export declare function addressToBytes32(address: Address): string;
|
|
21
|
+
export declare function bytes32ToAddress(bytes32: HexString): Address;
|
|
22
|
+
export declare function adressToBytesEvm(address: Address): Uint8Array;
|
|
23
|
+
export declare function addressToBytesSol(address: Address): Uint8Array;
|
|
24
|
+
export declare function addressToBytes(address: Address, protocol?: ProtocolType): Uint8Array;
|
|
25
|
+
export declare function addressToByteHexString(address: string, protocol?: ProtocolType): string;
|
|
26
|
+
export declare function convertToProtocolAddress(address: string, protocol: ProtocolType): string;
|
|
27
|
+
export declare function ensure0x(hexstr: string): string;
|
|
28
|
+
export declare function strip0x(hexstr: string): string;
|
|
29
|
+
//# sourceMappingURL=addresses.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addresses.d.ts","sourceRoot":"","sources":["../../src/addresses.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAU3D,wBAAgB,YAAY,CAAC,OAAO,EAAE,OAAO,WAE5C;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,OAAO,WAEjD;AAED,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,OAAO,6DAStD;AAoBD,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,OAAO,WAQjD;AAGD,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,OAAO,WAOtD;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,YAAY,WAQvE;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,UAOnD;AAED,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,OAAO,UAOxD;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,YAAY,UAQzE;AAED,wBAAgB,YAAY,CAAC,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,WAEpD;AAED,wBAAgB,YAAY,CAAC,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,WAEpD;AAED,wBAAgB,SAAS,CAAC,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,WAWjD;AAED,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,MAAM,WAEtD;AAED,wBAAgB,8BAA8B,CAAC,KAAK,EAAE,MAAM,WAE3D;AAED,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,YAAY,WAQ5E;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,WAEhD;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,UAAU,CAAC,EAAE,OAAO,UASpE;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,OAAO,UAIjD;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAIzD;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,SAAS,GAAG,OAAO,CAE5D;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,GAAG,UAAU,CAG7D;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,OAAO,GAAG,UAAU,CAE9D;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,YAAY,cAQvE;AAED,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,MAAM,EACf,QAAQ,CAAC,EAAE,YAAY,UAGxB;AAED,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,YAAY,UAyBvB;AAED,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,UAEtC;AAED,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,UAErC"}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.strip0x = exports.ensure0x = exports.convertToProtocolAddress = exports.addressToByteHexString = exports.addressToBytes = exports.addressToBytesSol = exports.adressToBytesEvm = exports.bytes32ToAddress = exports.addressToBytes32 = exports.capitalizeAddress = exports.shortenAddress = exports.isZeroishAddress = exports.isValidTransactionHash = exports.isValidTransactionHashSealevel = exports.isValidTransactionHashEvm = exports.eqAddress = exports.eqAddressSol = exports.eqAddressEvm = exports.normalizeAddress = exports.normalizeAddressSealevel = exports.normalizeAddressEvm = exports.isValidAddress = exports.isValidAddressSealevel = exports.isValidAddressEvm = exports.getAddressProtocolType = exports.isAddressSealevel = exports.isAddressEvm = void 0;
|
|
4
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
5
|
+
const ethers_1 = require("ethers");
|
|
6
|
+
const types_1 = require("./types");
|
|
7
|
+
const EVM_ADDRESS_REGEX = /^0x[a-fA-F0-9]{40}$/;
|
|
8
|
+
const SEALEVEL_ADDRESS_REGEX = /^[a-zA-Z0-9]{36,44}$/;
|
|
9
|
+
const EVM_TX_HASH_REGEX = /^0x([A-Fa-f0-9]{64})$/;
|
|
10
|
+
const SEALEVEL_TX_HASH_REGEX = /^[a-zA-Z1-9]{88}$/;
|
|
11
|
+
const ZEROISH_ADDRESS_REGEX = /^(0x)?0*$/;
|
|
12
|
+
function isAddressEvm(address) {
|
|
13
|
+
return EVM_ADDRESS_REGEX.test(address);
|
|
14
|
+
}
|
|
15
|
+
exports.isAddressEvm = isAddressEvm;
|
|
16
|
+
function isAddressSealevel(address) {
|
|
17
|
+
return SEALEVEL_ADDRESS_REGEX.test(address);
|
|
18
|
+
}
|
|
19
|
+
exports.isAddressSealevel = isAddressSealevel;
|
|
20
|
+
function getAddressProtocolType(address) {
|
|
21
|
+
if (!address)
|
|
22
|
+
return undefined;
|
|
23
|
+
if (isAddressEvm(address)) {
|
|
24
|
+
return types_1.ProtocolType.Ethereum;
|
|
25
|
+
}
|
|
26
|
+
else if (isAddressSealevel(address)) {
|
|
27
|
+
return types_1.ProtocolType.Sealevel;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.getAddressProtocolType = getAddressProtocolType;
|
|
34
|
+
function routeAddressUtil(evmFn, sealevelFn, fallback, param, protocol) {
|
|
35
|
+
protocol = protocol || getAddressProtocolType(param);
|
|
36
|
+
if (protocol === types_1.ProtocolType.Ethereum) {
|
|
37
|
+
return evmFn(param);
|
|
38
|
+
}
|
|
39
|
+
else if (protocol === types_1.ProtocolType.Sealevel) {
|
|
40
|
+
return sealevelFn(param);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
return fallback;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
// Slower than isAddressEvm above but actually validates content and checksum
|
|
47
|
+
function isValidAddressEvm(address) {
|
|
48
|
+
// Need to catch because ethers' isAddress throws in some cases (bad checksum)
|
|
49
|
+
try {
|
|
50
|
+
const isValid = address && ethers_1.utils.isAddress(address);
|
|
51
|
+
return !!isValid;
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.isValidAddressEvm = isValidAddressEvm;
|
|
58
|
+
// Slower than isAddressSealevel above but actually validates content and checksum
|
|
59
|
+
function isValidAddressSealevel(address) {
|
|
60
|
+
try {
|
|
61
|
+
const isValid = address && new web3_js_1.PublicKey(address).toBase58();
|
|
62
|
+
return !!isValid;
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.isValidAddressSealevel = isValidAddressSealevel;
|
|
69
|
+
function isValidAddress(address, protocol) {
|
|
70
|
+
return routeAddressUtil(isValidAddressEvm, isValidAddressSealevel, false, address, protocol);
|
|
71
|
+
}
|
|
72
|
+
exports.isValidAddress = isValidAddress;
|
|
73
|
+
function normalizeAddressEvm(address) {
|
|
74
|
+
if (isZeroishAddress(address))
|
|
75
|
+
return address;
|
|
76
|
+
try {
|
|
77
|
+
return ethers_1.utils.getAddress(address);
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
return address;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.normalizeAddressEvm = normalizeAddressEvm;
|
|
84
|
+
function normalizeAddressSealevel(address) {
|
|
85
|
+
if (isZeroishAddress(address))
|
|
86
|
+
return address;
|
|
87
|
+
try {
|
|
88
|
+
return new web3_js_1.PublicKey(address).toBase58();
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
return address;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
exports.normalizeAddressSealevel = normalizeAddressSealevel;
|
|
95
|
+
function normalizeAddress(address, protocol) {
|
|
96
|
+
return routeAddressUtil(normalizeAddressEvm, normalizeAddressSealevel, address, address, protocol);
|
|
97
|
+
}
|
|
98
|
+
exports.normalizeAddress = normalizeAddress;
|
|
99
|
+
function eqAddressEvm(a1, a2) {
|
|
100
|
+
return normalizeAddressEvm(a1) === normalizeAddressEvm(a2);
|
|
101
|
+
}
|
|
102
|
+
exports.eqAddressEvm = eqAddressEvm;
|
|
103
|
+
function eqAddressSol(a1, a2) {
|
|
104
|
+
return normalizeAddressSealevel(a1) === normalizeAddressSealevel(a2);
|
|
105
|
+
}
|
|
106
|
+
exports.eqAddressSol = eqAddressSol;
|
|
107
|
+
function eqAddress(a1, a2) {
|
|
108
|
+
const p1 = getAddressProtocolType(a1);
|
|
109
|
+
const p2 = getAddressProtocolType(a2);
|
|
110
|
+
if (p1 !== p2)
|
|
111
|
+
return false;
|
|
112
|
+
return routeAddressUtil((_a1) => eqAddressEvm(_a1, a2), (_a1) => eqAddressSol(_a1, a2), false, a1, p1);
|
|
113
|
+
}
|
|
114
|
+
exports.eqAddress = eqAddress;
|
|
115
|
+
function isValidTransactionHashEvm(input) {
|
|
116
|
+
return EVM_TX_HASH_REGEX.test(input);
|
|
117
|
+
}
|
|
118
|
+
exports.isValidTransactionHashEvm = isValidTransactionHashEvm;
|
|
119
|
+
function isValidTransactionHashSealevel(input) {
|
|
120
|
+
return SEALEVEL_TX_HASH_REGEX.test(input);
|
|
121
|
+
}
|
|
122
|
+
exports.isValidTransactionHashSealevel = isValidTransactionHashSealevel;
|
|
123
|
+
function isValidTransactionHash(input, protocol) {
|
|
124
|
+
return routeAddressUtil(isValidTransactionHashEvm, isValidTransactionHashSealevel, false, input, protocol);
|
|
125
|
+
}
|
|
126
|
+
exports.isValidTransactionHash = isValidTransactionHash;
|
|
127
|
+
function isZeroishAddress(address) {
|
|
128
|
+
return ZEROISH_ADDRESS_REGEX.test(address);
|
|
129
|
+
}
|
|
130
|
+
exports.isZeroishAddress = isZeroishAddress;
|
|
131
|
+
function shortenAddress(address, capitalize) {
|
|
132
|
+
if (!address)
|
|
133
|
+
return '';
|
|
134
|
+
if (address.length < 8)
|
|
135
|
+
return address;
|
|
136
|
+
const normalized = normalizeAddress(address);
|
|
137
|
+
const shortened = normalized.substring(0, 5) +
|
|
138
|
+
'...' +
|
|
139
|
+
normalized.substring(normalized.length - 4);
|
|
140
|
+
return capitalize ? capitalizeAddress(shortened) : shortened;
|
|
141
|
+
}
|
|
142
|
+
exports.shortenAddress = shortenAddress;
|
|
143
|
+
function capitalizeAddress(address) {
|
|
144
|
+
if (address.startsWith('0x'))
|
|
145
|
+
return '0x' + address.substring(2).toUpperCase();
|
|
146
|
+
else
|
|
147
|
+
return address.toUpperCase();
|
|
148
|
+
}
|
|
149
|
+
exports.capitalizeAddress = capitalizeAddress;
|
|
150
|
+
function addressToBytes32(address) {
|
|
151
|
+
return ethers_1.utils
|
|
152
|
+
.hexZeroPad(ethers_1.utils.hexStripZeros(address), 32)
|
|
153
|
+
.toLowerCase();
|
|
154
|
+
}
|
|
155
|
+
exports.addressToBytes32 = addressToBytes32;
|
|
156
|
+
function bytes32ToAddress(bytes32) {
|
|
157
|
+
return ethers_1.utils.getAddress(bytes32.slice(-40));
|
|
158
|
+
}
|
|
159
|
+
exports.bytes32ToAddress = bytes32ToAddress;
|
|
160
|
+
function adressToBytesEvm(address) {
|
|
161
|
+
const addrBytes32 = addressToBytes32(address);
|
|
162
|
+
return Buffer.from(addrBytes32.substring(2), 'hex');
|
|
163
|
+
}
|
|
164
|
+
exports.adressToBytesEvm = adressToBytesEvm;
|
|
165
|
+
function addressToBytesSol(address) {
|
|
166
|
+
return new web3_js_1.PublicKey(address).toBytes();
|
|
167
|
+
}
|
|
168
|
+
exports.addressToBytesSol = addressToBytesSol;
|
|
169
|
+
function addressToBytes(address, protocol) {
|
|
170
|
+
return routeAddressUtil(adressToBytesEvm, addressToBytesSol, new Uint8Array(), address, protocol);
|
|
171
|
+
}
|
|
172
|
+
exports.addressToBytes = addressToBytes;
|
|
173
|
+
function addressToByteHexString(address, protocol) {
|
|
174
|
+
return '0x' + Buffer.from(addressToBytes(address, protocol)).toString('hex');
|
|
175
|
+
}
|
|
176
|
+
exports.addressToByteHexString = addressToByteHexString;
|
|
177
|
+
function convertToProtocolAddress(address, protocol) {
|
|
178
|
+
const currentProtocol = getAddressProtocolType(address);
|
|
179
|
+
if (currentProtocol === protocol)
|
|
180
|
+
return address;
|
|
181
|
+
if (currentProtocol === types_1.ProtocolType.Ethereum &&
|
|
182
|
+
protocol === types_1.ProtocolType.Sealevel) {
|
|
183
|
+
return new web3_js_1.PublicKey(addressToBytes(address, types_1.ProtocolType.Ethereum)).toBase58();
|
|
184
|
+
}
|
|
185
|
+
else if (currentProtocol === types_1.ProtocolType.Sealevel &&
|
|
186
|
+
protocol === types_1.ProtocolType.Ethereum) {
|
|
187
|
+
return bytes32ToAddress(Buffer.from(addressToBytes(address, types_1.ProtocolType.Sealevel)).toString('hex'));
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
throw new Error(`Unsupported protocol combination ${currentProtocol} -> ${protocol}`);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
exports.convertToProtocolAddress = convertToProtocolAddress;
|
|
194
|
+
function ensure0x(hexstr) {
|
|
195
|
+
return hexstr.startsWith('0x') ? hexstr : `0x${hexstr}`;
|
|
196
|
+
}
|
|
197
|
+
exports.ensure0x = ensure0x;
|
|
198
|
+
function strip0x(hexstr) {
|
|
199
|
+
return hexstr.startsWith('0x') ? hexstr.slice(2) : hexstr;
|
|
200
|
+
}
|
|
201
|
+
exports.strip0x = strip0x;
|
|
202
|
+
//# sourceMapp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,EAClC;QACA,OAAO,gBAAgB,CACrB,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,oBAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAClE,KAAK,CACN,CACF,CAAC;KACH;SAAM;QACL,MAAM,IAAI,KAAK,CACb,oCAAoC,eAAe,OAAO,QAAQ,EAAE,CACrE,CAAC;KACH;AACH,CAAC;AA3BD,4DA2BC;AAED,SAAgB,QAAQ,CAAC,MAAc;IACrC,OAAO,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,MAAM,EAAE,CAAC;AAC1D,CAAC;AAFD,4BAEC;AAED,SAAgB,OAAO,CAAC,MAAc;IACpC,OAAO,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;AAC5D,CAAC;AAFD,0BAEC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import BigNumber from 'bignumber.js';
|
|
2
|
+
declare type NumberT = BigNumber.Value;
|
|
3
|
+
export declare function fromWei(value: NumberT | null | undefined, decimals?: number): number;
|
|
4
|
+
export declare function fromWeiRounded(value: NumberT | null | undefined, decimals?: number, roundDownIfSmall?: boolean): string;
|
|
5
|
+
export declare function toWei(value: NumberT | null | undefined, decimals?: number): BigNumber;
|
|
6
|
+
export declare function tryParseAmount(value: NumberT | null | undefined): BigNumber | null;
|
|
7
|
+
export declare function eqAmountApproximate(amountInWei1: BigNumber, amountInWei2: NumberT): boolean;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=amount.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"amount.d.ts","sourceRoot":"","sources":["../../src/amount.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,MAAM,cAAc,CAAC;AAMrC,aAAK,OAAO,GAAG,SAAS,CAAC,KAAK,CAAC;AAE/B,wBAAgB,OAAO,CACrB,KAAK,EAAE,OAAO,GAAG,IAAI,GAAG,SAAS,EACjC,QAAQ,SAAyB,GAChC,MAAM,CAQR;AAID,wBAAgB,cAAc,CAC5B,KAAK,EAAE,OAAO,GAAG,IAAI,GAAG,SAAS,EACjC,QAAQ,SAAyB,EACjC,gBAAgB,UAAO,GACtB,MAAM,CAaR;AAED,wBAAgB,KAAK,CACnB,KAAK,EAAE,OAAO,GAAG,IAAI,GAAG,SAAS,EACjC,QAAQ,SAAyB,GAChC,SAAS,CAcX;AAED,wBAAgB,cAAc,CAC5B,KAAK,EAAE,OAAO,GAAG,IAAI,GAAG,SAAS,GAChC,SAAS,GAAG,IAAI,CASlB;AAID,wBAAgB,mBAAmB,CACjC,YAAY,EAAE,SAAS,EACvB,YAAY,EAAE,OAAO,WAKtB"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.eqAmountApproximate = exports.tryParseAmount = exports.toWei = exports.fromWeiRounded = exports.fromWei = void 0;
|
|
7
|
+
const units_1 = require("@ethersproject/units");
|
|
8
|
+
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
9
|
+
const DEFAULT_MIN_ROUNDED_VALUE = 0.00001;
|
|
10
|
+
const DEFAULT_DISPLAY_DECIMALS = 5;
|
|
11
|
+
const DEFAULT_TOKEN_DECIMALS = 18;
|
|
12
|
+
function fromWei(value, decimals = DEFAULT_TOKEN_DECIMALS) {
|
|
13
|
+
if (!value)
|
|
14
|
+
return 0;
|
|
15
|
+
const valueString = value.toString().trim();
|
|
16
|
+
const flooredValue = new bignumber_js_1.default(valueString).toFixed(0, bignumber_js_1.default.ROUND_FLOOR);
|
|
17
|
+
return parseFloat((0, units_1.formatUnits)(flooredValue, decimals));
|
|
18
|
+
}
|
|
19
|
+
exports.fromWei = fromWei;
|
|
20
|
+
// Similar to fromWei above but rounds to set number of decimals
|
|
21
|
+
// with a minimum floor, configured per token
|
|
22
|
+
function fromWeiRounded(value, decimals = DEFAULT_TOKEN_DECIMALS, roundDownIfSmall = true) {
|
|
23
|
+
if (!value)
|
|
24
|
+
return '0';
|
|
25
|
+
const flooredValue = new bignumber_js_1.default(value).toFixed(0, bignumber_js_1.default.ROUND_FLOOR);
|
|
26
|
+
const amount = new bignumber_js_1.default((0, units_1.formatUnits)(flooredValue, decimals));
|
|
27
|
+
if (amount.isZero())
|
|
28
|
+
return '0';
|
|
29
|
+
// If amount is less than min value
|
|
30
|
+
if (amount.lt(DEFAULT_MIN_ROUNDED_VALUE)) {
|
|
31
|
+
if (roundDownIfSmall)
|
|
32
|
+
return '0';
|
|
33
|
+
else
|
|
34
|
+
return DEFAULT_MIN_ROUNDED_VALUE.toString();
|
|
35
|
+
}
|
|
36
|
+
return amount.toFixed(DEFAULT_DISPLAY_DECIMALS).toString();
|
|
37
|
+
}
|
|
38
|
+
exports.fromWeiRounded = fromWeiRounded;
|
|
39
|
+
function toWei(value, decimals = DEFAULT_TOKEN_DECIMALS) {
|
|
40
|
+
if (!value)
|
|
41
|
+
return new bignumber_js_1.default(0);
|
|
42
|
+
const valueString = value.toString().trim();
|
|
43
|
+
const components = valueString.split('.');
|
|
44
|
+
if (components.length === 1) {
|
|
45
|
+
return new bignumber_js_1.default((0, units_1.parseUnits)(valueString, decimals).toString());
|
|
46
|
+
}
|
|
47
|
+
else if (components.length === 2) {
|
|
48
|
+
const trimmedFraction = components[1].substring(0, decimals);
|
|
49
|
+
return new bignumber_js_1.default((0, units_1.parseUnits)(`${components[0]}.${trimmedFraction}`, decimals).toString());
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
throw new Error(`Cannot convert ${valueString} to wei`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.toWei = toWei;
|
|
56
|
+
function tryParseAmount(value) {
|
|
57
|
+
try {
|
|
58
|
+
if (!value)
|
|
59
|
+
return null;
|
|
60
|
+
const parsed = new bignumber_js_1.default(value);
|
|
61
|
+
if (!parsed || parsed.isNaN() || !parsed.isFinite())
|
|
62
|
+
return null;
|
|
63
|
+
else
|
|
64
|
+
return parsed;
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.tryParseAmount = tryParseAmount;
|
|
71
|
+
// Checks if an amount is equal of nearly equal to balance within a small margin of error
|
|
72
|
+
// Necessary because amounts in the UI are often rounded
|
|
73
|
+
function eqAmountApproximate(amountInWei1, amountInWei2) {
|
|
74
|
+
const minValueWei = toWei(DEFAULT_MIN_ROUNDED_VALUE);
|
|
75
|
+
// Is difference btwn amount and balance less than min amount shown for token
|
|
76
|
+
return amountInWei1.minus(amountInWei2).abs().lt(minValueWei);
|
|
77
|
+
}
|
|
78
|
+
exports.eqAmountApproximate = eqAmountApproximate;
|
|
79
|
+
//# sourceMappingURL=amount.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"amount.js","sourceRoot":"","sources":["../../src/amount.ts"],"names":[],"mappings":";;;;;;AAAA,gDAA+D;AAC/D,gEAAqC;AAErC,MAAM,yBAAyB,GAAG,OAAO,CAAC;AAC1C,MAAM,wBAAwB,GAAG,CAAC,CAAC;AACnC,MAAM,sBAAsB,GAAG,EAAE,CAAC;AAIlC,SAAgB,OAAO,CACrB,KAAiC,EACjC,QAAQ,GAAG,sBAAsB;IAEjC,IAAI,CAAC,KAAK;QAAE,OAAO,CAAC,CAAC;IACrB,MAAM,WAAW,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC;IAC5C,MAAM,YAAY,GAAG,IAAI,sBAAS,CAAC,WAAW,CAAC,CAAC,OAAO,CACrD,CAAC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
}
|
|
5
|
+
export declare function chunk<T extends Sliceable>(str: T, size: number): T[];
|
|
6
|
+
export declare function exclude<T>(item: T, list: T[]): T[];
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=arrays.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arrays.d.ts","sourceRoot":"","sources":["../../src/arrays.ts"],"names":[],"mappings":"AAAA,UAAU,SAAS;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,GAAG,CAAC;CACtC;AAED,wBAAgB,KAAK,CAAC,CAAC,SAAS,SAAS,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,OAM9D;AAED,wBAAgB,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,OAE5C"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.exclude = exports.chunk = void 0;
|
|
4
|
+
function chunk(str, size) {
|
|
5
|
+
const R = [];
|
|
6
|
+
for (let i = 0; i < str.length; i += size) {
|
|
7
|
+
R.push(str.slice(i, i + size));
|
|
8
|
+
}
|
|
9
|
+
return R;
|
|
10
|
+
}
|
|
11
|
+
exports.chunk = chunk;
|
|
12
|
+
function exclude(item, list) {
|
|
13
|
+
return list.filter((i) => i !== item);
|
|
14
|
+
}
|
|
15
|
+
exports.exclude = exclude;
|
|
16
|
+
//# sourceMappingURL=arrays.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arrays.js","sourceRoot":"","sources":["../../src/arrays.ts"],"names":[],"mappings":";;;AAKA,SAAgB,KAAK,CAAsB,GAAM,EAAE,IAAY;IAC7D,MAAM,CAAC,GAAa,EAAE,CAAC;IACvB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,IAAI,IAAI,EAAE;QACzC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;KAChC;IACD,OAAO,CAAC,CAAC;AACX,CAAC;AAND,sBAMC;AAED,SAAgB,OAAO,CAAI,IAAO,EAAE,IAAS;IAC3C,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC;AACxC,CAAC;AAFD,0BAEC"}
|