@hyperlane-xyz/utils 1.4.2 → 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 +2 -2
- 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 +11 -1
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.js +11 -1
- 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 +5 -5
- package/dist/src/validator.js.map +1 -1
- package/package.json +8 -4
- package/dist/src/utils.d.ts +0 -57
- package/dist/src/utils.d.ts.map +0 -1
- package/dist/src/utils.js +0 -322
- package/dist/src/utils.js.map +0 -1
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Return a promise that resolves in ms milliseconds.
|
|
3
|
+
* @param ms Time to wait
|
|
4
|
+
*/
|
|
5
|
+
export declare function sleep(ms: number): Promise<void>;
|
|
6
|
+
/**
|
|
7
|
+
* Wait up to a given amount of time, and throw an error if the promise does not resolve in time.
|
|
8
|
+
* @param promise The promise to timeout on.
|
|
9
|
+
* @param timeoutMs How long to wait for the promise in milliseconds.
|
|
10
|
+
* @param message The error message if a timeout occurs.
|
|
11
|
+
*/
|
|
12
|
+
export declare function timeout<T>(promise: Promise<T>, timeoutMs?: number, message?: string): Promise<T>;
|
|
13
|
+
/**
|
|
14
|
+
* Run a callback with a timeout.
|
|
15
|
+
* @param timeoutMs How long to wait for the promise in milliseconds.
|
|
16
|
+
* @param callback The callback to run.
|
|
17
|
+
* @returns callback return value
|
|
18
|
+
*/
|
|
19
|
+
export declare function runWithTimeout<T>(timeoutMs: number, callback: () => Promise<T>): Promise<T | void>;
|
|
20
|
+
/**
|
|
21
|
+
* Retries an async function if it raises an exception,
|
|
22
|
+
* using exponential backoff.
|
|
23
|
+
* @param runner callback to run
|
|
24
|
+
* @param attempts max number of attempts
|
|
25
|
+
* @param baseRetryMs base delay between attempts
|
|
26
|
+
* @returns runner return value
|
|
27
|
+
*/
|
|
28
|
+
export declare function retryAsync<T>(runner: () => T, attempts?: number, baseRetryMs?: number): Promise<T>;
|
|
29
|
+
/**
|
|
30
|
+
* Run a callback with a timeout, and retry if the callback throws an error.
|
|
31
|
+
* @param runner callback to run
|
|
32
|
+
* @param delayMs base delay between attempts
|
|
33
|
+
* @param maxAttempts maximum number of attempts
|
|
34
|
+
* @returns runner return value
|
|
35
|
+
*/
|
|
36
|
+
export declare function pollAsync<T>(runner: () => Promise<T>, delayMs?: number, maxAttempts?: number | undefined): Promise<T>;
|
|
37
|
+
//# sourceMappingURL=async.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async.d.ts","sourceRoot":"","sources":["../../src/async.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE/C;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,CAAC,EACvB,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EACnB,SAAS,CAAC,EAAE,MAAM,EAClB,OAAO,SAAoB,GAC1B,OAAO,CAAC,CAAC,CAAC,CAQZ;AAED;;;;;GAKG;AACH,wBAAsB,cAAc,CAAC,CAAC,EACpC,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GACzB,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAanB;AAED;;;;;;;GAOG;AACH,wBAAsB,UAAU,CAAC,CAAC,EAChC,MAAM,EAAE,MAAM,CAAC,EACf,QAAQ,SAAI,EACZ,WAAW,SAAK,cAajB;AAED;;;;;;GAMG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAC/B,MAAM,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACxB,OAAO,SAAM,EACb,WAAW,GAAE,MAAM,GAAG,SAAqB,cAe5C"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.pollAsync = exports.retryAsync = exports.runWithTimeout = exports.timeout = exports.sleep = void 0;
|
|
13
|
+
/**
|
|
14
|
+
* Return a promise that resolves in ms milliseconds.
|
|
15
|
+
* @param ms Time to wait
|
|
16
|
+
*/
|
|
17
|
+
function sleep(ms) {
|
|
18
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
19
|
+
}
|
|
20
|
+
exports.sleep = sleep;
|
|
21
|
+
/**
|
|
22
|
+
* Wait up to a given amount of time, and throw an error if the promise does not resolve in time.
|
|
23
|
+
* @param promise The promise to timeout on.
|
|
24
|
+
* @param timeoutMs How long to wait for the promise in milliseconds.
|
|
25
|
+
* @param message The error message if a timeout occurs.
|
|
26
|
+
*/
|
|
27
|
+
function timeout(promise, timeoutMs, message = 'Timeout reached') {
|
|
28
|
+
if (!timeoutMs || timeoutMs <= 0)
|
|
29
|
+
return promise;
|
|
30
|
+
return new Promise((resolve, reject) => {
|
|
31
|
+
setTimeout(() => {
|
|
32
|
+
reject(new Error(message));
|
|
33
|
+
}, timeoutMs);
|
|
34
|
+
promise.then(resolve).catch(reject);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
exports.timeout = timeout;
|
|
38
|
+
/**
|
|
39
|
+
* Run a callback with a timeout.
|
|
40
|
+
* @param timeoutMs How long to wait for the promise in milliseconds.
|
|
41
|
+
* @param callback The callback to run.
|
|
42
|
+
* @returns callback return value
|
|
43
|
+
*/
|
|
44
|
+
function runWithTimeout(timeoutMs, callback) {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
let timeout;
|
|
47
|
+
const timeoutProm = new Promise((_, reject) => (timeout = setTimeout(() => reject(new Error(`Timed out in ${timeoutMs}ms.`)), timeoutMs)));
|
|
48
|
+
const ret = yield Promise.race([callback(), timeoutProm]);
|
|
49
|
+
// @ts-ignore timeout gets set immediately by the promise constructor
|
|
50
|
+
clearTimeout(timeout);
|
|
51
|
+
return ret;
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
exports.runWithTimeout = runWithTimeout;
|
|
55
|
+
/**
|
|
56
|
+
* Retries an async function if it raises an exception,
|
|
57
|
+
* using exponential backoff.
|
|
58
|
+
* @param runner callback to run
|
|
59
|
+
* @param attempts max number of attempts
|
|
60
|
+
* @param baseRetryMs base delay between attempts
|
|
61
|
+
* @returns runner return value
|
|
62
|
+
*/
|
|
63
|
+
function retryAsync(runner, attempts = 5, baseRetryMs = 50) {
|
|
64
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
let saveError;
|
|
66
|
+
for (let i = 0; i < attempts; i++) {
|
|
67
|
+
try {
|
|
68
|
+
const result = yield runner();
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
saveError = error;
|
|
73
|
+
yield sleep(baseRetryMs * Math.pow(2, i));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
throw saveError;
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
exports.retryAsync = retryAsync;
|
|
80
|
+
/**
|
|
81
|
+
* Run a callback with a timeout, and retry if the callback throws an error.
|
|
82
|
+
* @param runner callback to run
|
|
83
|
+
* @param delayMs base delay between attempts
|
|
84
|
+
* @param maxAttempts maximum number of attempts
|
|
85
|
+
* @returns runner return value
|
|
86
|
+
*/
|
|
87
|
+
function pollAsync(runner, delayMs = 500, maxAttempts = undefined) {
|
|
88
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
89
|
+
let attempts = 0;
|
|
90
|
+
let saveError;
|
|
91
|
+
while (!maxAttempts || attempts < maxAttempts) {
|
|
92
|
+
try {
|
|
93
|
+
const ret = yield runner();
|
|
94
|
+
return ret;
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
saveError = error;
|
|
98
|
+
attempts += 1;
|
|
99
|
+
yield sleep(delayMs);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
throw saveError;
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
exports.pollAsync = pollAsync;
|
|
106
|
+
//# sourceMappingURL=async.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async.js","sourceRoot":"","sources":["../../src/async.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;GAGG;AACH,SAAgB,KAAK,CAAC,EAAU;IAC9B,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AACjE,CAAC;AAFD,sBAEC;AAED;;;;;GAKG;AACH,SAAgB,OAAO,CACrB,OAAmB,EACnB,SAAkB,EAClB,OAAO,GAAG,iBAAiB;IAE3B,IAAI,CAAC,SAAS,IAAI,SAAS,IAAI,CAAC;QAAE,OAAO,OAAO,CAAC;IACjD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,UAAU,CAAC,GAAG,EAAE;YACd,MAAM,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;QAC7B,CAAC,EAAE,SAAS,CAAC,CAAC;QACd,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;AACL,CAAC;AAZD,0BAYC;AAED;;;;;GAKG;AACH,SAAsB,cAAc,CAClC,SAAiB,EACjB,QAA0B;;QAE1B,IAAI,OAAuB,CAAC;QAC5B,MAAM,WAAW,GAAG,IAAI,OAAO,CAC7B,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CACZ,CAAC,OAAO,GAAG,UAAU,CACnB,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,gB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S,CAAC;IAClB,CAAC;CAAA;AAlBD,8BAkBC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base64.d.ts","sourceRoot":"","sources":["../../src/base64.ts"],"names":[],"mappings":"AAEA,wBAAgB,QAAQ,CAAC,IAAI,EAAE,GAAG,GAAG,MAAM,GAAG,SAAS,CAQtD;AAED,wBAAgB,UAAU,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,CASpE"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fromBase64 = exports.toBase64 = void 0;
|
|
4
|
+
const logging_1 = require("./logging");
|
|
5
|
+
function toBase64(data) {
|
|
6
|
+
try {
|
|
7
|
+
if (!data)
|
|
8
|
+
throw new Error('No data to encode');
|
|
9
|
+
return btoa(JSON.stringify(data));
|
|
10
|
+
}
|
|
11
|
+
catch (error) {
|
|
12
|
+
(0, logging_1.log)('Unable to serialize + encode data to base64', data);
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.toBase64 = toBase64;
|
|
17
|
+
function fromBase64(data) {
|
|
18
|
+
try {
|
|
19
|
+
if (!data)
|
|
20
|
+
throw new Error('No data to decode');
|
|
21
|
+
const msg = Array.isArray(data) ? data[0] : data;
|
|
22
|
+
return JSON.parse(atob(msg));
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
(0, logging_1.log)('Unable to decode + deserialize data from base64', data);
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.fromBase64 = fromBase64;
|
|
30
|
+
//# sourceMappingURL=base64.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base64.js","sourceRoot":"","sources":["../../src/base64.ts"],"names":[],"mappings":";;;AAAA,uCAAgC;AAEhC,SAAgB,QAAQ,CAAC,IAAS;IAChC,IAAI;QACF,IAAI,CAAC,IAAI;YAAE,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;QAChD,OAAO,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;KACnC;IAAC,OAAO,KAAK,EAAE;QACd,IAAA,aAAG,EAAC,6CAA6C,EAAE,IAAI,CAAC,CAAC;QACzD,OAAO,SAAS,CAAC;KAClB;AACH,CAAC;AARD,4BAQC;AAED,SAAgB,UAAU,CAAI,IAAuB;IACnD,IAAI;QACF,IAAI,CAAC,IAAI;YAAE,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;QAChD,MAAM,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QACjD,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;KAC9B;IAAC,OAAO,KAAK,EAAE;QACd,IAAA,aAAG,EAAC,iDAAiD,EAAE,IAAI,CAAC,CAAC;QAC7D,OAAO,SAAS,CAAC;KAClB;AACH,CAAC;AATD,gCASC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { BigNumber, BigNumberish, FixedNumber } from 'ethers';
|
|
2
|
+
export declare function isBigNumberish(value: any): value is BigNumberish;
|
|
3
|
+
export declare function isZeroish(value: BigNumberish): boolean;
|
|
4
|
+
/**
|
|
5
|
+
* Converts a BigNumber to a FixedNumber of the format fixed128x18.
|
|
6
|
+
* @param big The BigNumber to convert.
|
|
7
|
+
* @returns A FixedNumber representation of a BigNumber.
|
|
8
|
+
*/
|
|
9
|
+
export declare function bigToFixed(big: BigNumber): FixedNumber;
|
|
10
|
+
/**
|
|
11
|
+
* Converts a FixedNumber (of any format) to a BigNumber.
|
|
12
|
+
* @param fixed The FixedNumber to convert.
|
|
13
|
+
* @param ceil If true, the ceiling of fixed is used. Otherwise, the floor is used.
|
|
14
|
+
* @returns A BigNumber representation of a FixedNumber.
|
|
15
|
+
*/
|
|
16
|
+
export declare function fixedToBig(fixed: FixedNumber, ceil?: boolean): BigNumber;
|
|
17
|
+
/**
|
|
18
|
+
* Multiplies a BigNumber by a FixedNumber, returning the BigNumber product.
|
|
19
|
+
* @param big The BigNumber to multiply.
|
|
20
|
+
* @param fixed The FixedNumber to multiply.
|
|
21
|
+
* @param ceil If true, the ceiling of the product is used. Otherwise, the floor is used.
|
|
22
|
+
* @returns The BigNumber product.
|
|
23
|
+
*/
|
|
24
|
+
export declare function mulBigAndFixed(big: BigNumber, fixed: FixedNumber, ceil?: boolean): BigNumber;
|
|
25
|
+
/**
|
|
26
|
+
* Converts a value with `fromDecimals` decimals to a value with `toDecimals` decimals.
|
|
27
|
+
* Incurs a loss of precision when `fromDecimals` > `toDecimals`.
|
|
28
|
+
* @param value The value to convert.
|
|
29
|
+
* @param fromDecimals The number of decimals `value` has.
|
|
30
|
+
* @param toDecimals The number of decimals to convert `value` to.
|
|
31
|
+
* @returns `value` represented with `toDecimals` decimals.
|
|
32
|
+
*/
|
|
33
|
+
export declare function convertDecimalValue(value: BigNumber, fromDecimals: number, toDecimals: number): BigNumber;
|
|
34
|
+
export declare function BigNumberMin(bn1: BigNumber, bn2: BigNumber): BigNumber;
|
|
35
|
+
export declare function BigNumberMax(bn1: BigNumber, bn2: BigNumber): BigNumber;
|
|
36
|
+
//# sourceMappingURL=big-numbers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"big-numbers.d.ts","sourceRoot":"","sources":["../../src/big-numbers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,EAAa,MAAM,QAAQ,CAAC;AAIzE,wBAAgB,cAAc,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,YAAY,CAOhE;AAGD,wBAAgB,SAAS,CAAC,KAAK,EAAE,YAAY,WAY5C;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,SAAS,GAAG,WAAW,CAEtD;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,WAAW,EAAE,IAAI,UAAQ,GAAG,SAAS,CAGtE;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC5B,GAAG,EAAE,SAAS,EACd,KAAK,EAAE,WAAW,EAClB,IAAI,UAAQ,GACX,SAAS,CAIX;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,SAAS,EAChB,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE,MAAM,GACjB,SAAS,CASX;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,aAE1D;AACD,wBAAgB,YAAY,CAAC,GAAG,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,aAE1D"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BigNumberMax = exports.BigNumberMin = exports.convertDecimalValue = exports.mulBigAndFixed = exports.fixedToBig = exports.bigToFixed = exports.isZeroish = exports.isBigNumberish = void 0;
|
|
4
|
+
const ethers_1 = require("ethers");
|
|
5
|
+
const typeof_1 = require("./typeof");
|
|
6
|
+
function isBigNumberish(value) {
|
|
7
|
+
try {
|
|
8
|
+
if ((0, typeof_1.isNullish)(value))
|
|
9
|
+
return false;
|
|
10
|
+
return ethers_1.BigNumber.from(value)._isBigNumber;
|
|
11
|
+
}
|
|
12
|
+
catch (error) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.isBigNumberish = isBigNumberish;
|
|
17
|
+
// If a value (e.g. hex string or number) is zeroish (0, 0x0, 0x00, etc.)
|
|
18
|
+
function isZeroish(value) {
|
|
19
|
+
try {
|
|
20
|
+
if (!value ||
|
|
21
|
+
value === ethers_1.constants.HashZero ||
|
|
22
|
+
value === ethers_1.constants.AddressZero)
|
|
23
|
+
return true;
|
|
24
|
+
return ethers_1.BigNumber.from(value).isZero();
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.isZeroish = isZeroish;
|
|
31
|
+
/**
|
|
32
|
+
* Converts a BigNumber to a FixedNumber of the format fixed128x18.
|
|
33
|
+
* @param big The BigNumber to convert.
|
|
34
|
+
* @returns A FixedNumber representation of a BigNumber.
|
|
35
|
+
*/
|
|
36
|
+
function bigToFixed(big) {
|
|
37
|
+
return ethers_1.FixedNumber.from(big.toString());
|
|
38
|
+
}
|
|
39
|
+
exports.bigToFixed = bigToFixed;
|
|
40
|
+
/**
|
|
41
|
+
* Converts a FixedNumber (of any format) to a BigNumber.
|
|
42
|
+
* @param fixed The FixedNumber to convert.
|
|
43
|
+
* @param ceil If true, the ceiling of fixed is used. Otherwise, the floor is used.
|
|
44
|
+
* @returns A BigNumber representation of a FixedNumber.
|
|
45
|
+
*/
|
|
46
|
+
function fixedToBig(fixed, ceil = false) {
|
|
47
|
+
const fixedAsInteger = ceil ? fixed.ceiling() : fixed.floor();
|
|
48
|
+
return ethers_1.BigNumber.from(fixedAsInteger.toFormat('fixed256x0').toString());
|
|
49
|
+
}
|
|
50
|
+
exports.fixedToBig = fixedToBig;
|
|
51
|
+
/**
|
|
52
|
+
* Multiplies a BigNumber by a FixedNumber, returning the BigNumber product.
|
|
53
|
+
* @param big The BigNumber to multiply.
|
|
54
|
+
* @param fixed The FixedNumber to multiply.
|
|
55
|
+
* @param ceil If true, the ceiling of the product is used. Otherwise, the floor is used.
|
|
56
|
+
* @returns The BigNumber product.
|
|
57
|
+
*/
|
|
58
|
+
function mulBigAndFixed(big, fixed, ceil = false) {
|
|
59
|
+
// Converts big to a FixedNumber, multiplies it by fixed, and converts the product back
|
|
60
|
+
// to a BigNumber.
|
|
61
|
+
return fixedToBig(fixed.mulUnsafe(bigToFixed(big)), ceil);
|
|
62
|
+
}
|
|
63
|
+
exports.mulBigAndFixed = mulBigAndFixed;
|
|
64
|
+
/**
|
|
65
|
+
* Converts a value with `fromDecimals` decimals to a value with `toDecimals` decimals.
|
|
66
|
+
* Incurs a loss of precision when `fromDecimals` > `toDecimals`.
|
|
67
|
+
* @param value The value to convert.
|
|
68
|
+
* @param fromDecimals The number of decimals `value` has.
|
|
69
|
+
* @param toDecimals The number of decimals to convert `value` to.
|
|
70
|
+
* @returns `value` represented with `toDecimals` decimals.
|
|
71
|
+
*/
|
|
72
|
+
function convertDecimalValue(value, fromDecimals, toDecimals) {
|
|
73
|
+
if (fromDecimals === toDecimals) {
|
|
74
|
+
return value;
|
|
75
|
+
}
|
|
76
|
+
else if (fromDecimals > toDecimals) {
|
|
77
|
+
return value.div(Math.pow(10, (fromDecimals - toDecimals)));
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
// if (fromDecimals < toDecimals)
|
|
81
|
+
return value.mul(Math.pow(10, (toDecimals - fromDecimals)));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.convertDecimalValue = convertDecimalValue;
|
|
85
|
+
function BigNumberMin(bn1, bn2) {
|
|
86
|
+
return bn1.gte(bn2) ? bn2 : bn1;
|
|
87
|
+
}
|
|
88
|
+
exports.BigNumberMin = BigNumberMin;
|
|
89
|
+
function BigNumberMax(bn1, bn2) {
|
|
90
|
+
return bn1.lte(bn2) ? bn2 : bn1;
|
|
91
|
+
}
|
|
92
|
+
exports.BigNumberMax = BigNumberMax;
|
|
93
|
+
//# sourceMappingURL=big-numbers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"big-numbers.js","sourceRoot":"","sources":["../../src/big-numbers.ts"],"names":[],"mappings":";;;AAAA,mCAAyE;AAEzE,qCAAqC;AAErC,SAAgB,cAAc,CAAC,KAA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AE,IAAI,CAAC,CAAC;AAC5D,CAAC;AARD,wCAQC;AAED;;;;;;;GAOG;AACH,SAAgB,mBAAmB,CACjC,KAAgB,EAChB,YAAoB,EACpB,UAAkB;IAElB,IAAI,YAAY,KAAK,UAAU,EAAE;QAC/B,OAAO,KAAK,CAAC;KACd;SAAM,IAAI,YAAY,GAAG,UAAU,EAAE;QACpC,OAAO,KAAK,CAAC,GAAG,CAAC,SAAA,EAAE,EAAI,CAAC,YAAY,GAAG,UAAU,CAAC,CAAA,CAAC,CAAC;KACrD;SAAM;QACL,iCAAiC;QACjC,OAAO,KAAK,CAAC,GAAG,CAAC,SAAA,EAAE,EAAI,CAAC,UAAU,GAAG,YAAY,CAAC,CAAA,CAAC,CAAC;KACrD;AACH,CAAC;AAbD,kDAaC;AAED,SAAgB,YAAY,CAAC,GAAc,EAAE,GAAc;IACzD,OAAO,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;AAClC,CAAC;AAFD,oCAEC;AACD,SAAgB,YAAY,CAAC,GAAc,EAAE,GAAc;IACzD,OAAO,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;AAClC,CAAC;AAFD,oCAEC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"big-numbers.test.d.ts","sourceRoot":"","sources":["../../src/big-numbers.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const chai_1 = require("chai");
|
|
4
|
+
const ethers_1 = require("ethers");
|
|
5
|
+
const big_numbers_1 = require("./big-numbers");
|
|
6
|
+
describe('utils', () => {
|
|
7
|
+
describe('bigToFixed', () => {
|
|
8
|
+
it('converts a BigNumber to a FixedNumber', () => {
|
|
9
|
+
const big = ethers_1.BigNumber.from('1234');
|
|
10
|
+
const fixed = (0, big_numbers_1.bigToFixed)(big);
|
|
11
|
+
(0, chai_1.expect)(fixed.toUnsafeFloat()).to.equal(1234);
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
describe('fixedToBig', () => {
|
|
15
|
+
it('converts a FixedNumber to a floored BigNumber', () => {
|
|
16
|
+
const fixed = ethers_1.FixedNumber.from('12.34');
|
|
17
|
+
const big = (0, big_numbers_1.fixedToBig)(fixed);
|
|
18
|
+
(0, chai_1.expect)(big.toNumber()).to.equal(12);
|
|
19
|
+
});
|
|
20
|
+
it('converts a FixedNumber to a ceilinged BigNumber', () => {
|
|
21
|
+
const fixed = ethers_1.FixedNumber.from('12.34');
|
|
22
|
+
const big = (0, big_numbers_1.fixedToBig)(fixed, true);
|
|
23
|
+
(0, chai_1.expect)(big.toNumber()).to.equal(13);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
describe('mulBigAndFixed', () => {
|
|
27
|
+
it('gets the floored product of a BigNumber and FixedNumber', () => {
|
|
28
|
+
const big = ethers_1.BigNumber.from('1000');
|
|
29
|
+
const fixed = ethers_1.FixedNumber.from('1.2345');
|
|
30
|
+
const product = (0, big_numbers_1.mulBigAndFixed)(big, fixed);
|
|
31
|
+
(0, chai_1.expect)(product.toNumber()).to.equal(1234);
|
|
32
|
+
});
|
|
33
|
+
it('gets the ceilinged product of a BigNumber and FixedNumber', () => {
|
|
34
|
+
const big = ethers_1.BigNumber.from('1000');
|
|
35
|
+
const fixed = ethers_1.FixedNumber.from('1.2345');
|
|
36
|
+
const product = (0, big_numbers_1.mulBigAndFixed)(big, fixed, true);
|
|
37
|
+
(0, chai_1.expect)(product.toNumber()).to.equal(1235);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
//# sourceMappingURL=big-numbers.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"big-numbers.test.js","sourceRoot":"","sources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M,CAKxE"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatCallData = void 0;
|
|
4
|
+
function formatCallData(destinationContract, functionName, functionArgs) {
|
|
5
|
+
return destinationContract.interface.encodeFunctionData(functionName, functionArgs);
|
|
6
|
+
}
|
|
7
|
+
exports.formatCallData = formatCallData;
|
|
8
|
+
//# sourceMappingURL=calldata.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calldata.js","sourceRoot":"","sources":["../../src/calldata.ts"],"names":[],"mappings":";;;AAEA,SAAgB,cAAc,CAG5B,mBAAsB,EAAE,YAAkB,EAAE,YAAkB;IAC9D,OAAO,mBAAmB,CAAC,SAAS,CAAC,kBAAkB,CACrD,YAAY,EACZ,YAAY,CACb,CAAC;AACJ,CAAC;AARD,wCAQC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Checkpoint, S3Checkpoint, S3CheckpointWithId } from './types';
|
|
2
|
+
export declare function isS3Checkpoint(obj: any): obj is S3Checkpoint;
|
|
3
|
+
export declare function isS3CheckpointWithId(obj: any): obj is S3CheckpointWithId;
|
|
4
|
+
export declare function isCheckpoint(obj: any): obj is Checkpoint;
|
|
5
|
+
//# sourceMappingURL=checkpoints.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkpoints.d.ts","sourceRoot":"","sources":["../../src/checkpoints.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,UAAU,EACV,YAAY,EACZ,kBAAkB,EAEnB,MAAM,SAAS,CAAC;AAUjB,wBAAgB,cAAc,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,YAAY,CAE5D;AAED,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,kBAAkB,CAMxE;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,UAAU,CAMxD"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isCheckpoint = exports.isS3CheckpointWithId = exports.isS3Checkpoint = void 0;
|
|
4
|
+
const ethers_1 = require("ethers");
|
|
5
|
+
function isValidSignature(signature) {
|
|
6
|
+
return typeof signature === 'string'
|
|
7
|
+
? ethers_1.utils.isHexString(signature)
|
|
8
|
+
: ethers_1.utils.isHexString(signature.r) &&
|
|
9
|
+
ethers_1.utils.isHexString(signature.s) &&
|
|
10
|
+
Number.isSafeInteger(signature.v);
|
|
11
|
+
}
|
|
12
|
+
function isS3Checkpoint(obj) {
|
|
13
|
+
return isValidSignature(obj.signature) && isCheckpoint(obj.value);
|
|
14
|
+
}
|
|
15
|
+
exports.isS3Checkpoint = isS3Checkpoint;
|
|
16
|
+
function isS3CheckpointWithId(obj) {
|
|
17
|
+
return (isValidSignature(obj.signature) &&
|
|
18
|
+
isCheckpoint(obj.value.checkpoint) &&
|
|
19
|
+
ethers_1.utils.isHexString(obj.value.message_id));
|
|
20
|
+
}
|
|
21
|
+
exports.isS3CheckpointWithId = isS3CheckpointWithId;
|
|
22
|
+
function isCheckpoint(obj) {
|
|
23
|
+
const isValidRoot = ethers_1.utils.isHexString(obj.root);
|
|
24
|
+
const isValidIndex = Number.isSafeInteger(obj.index);
|
|
25
|
+
const isValidMailbox = ethers_1.utils.isHexString(obj.mailbox_address);
|
|
26
|
+
const isValidDomain = Number.isSafeInteger(obj.mailbox_domain);
|
|
27
|
+
return isValidIndex && isValidRoot && isValidMailbox && isValidDomain;
|
|
28
|
+
}
|
|
29
|
+
exports.isCheckpoint = isCheckpoint;
|
|
30
|
+
//# sourceMappingURL=checkpoints.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkpoints.js","sourceRoot":"","sources":["../../src/checkpoints.ts"],"names":[],"mappings":";;;AAAA,mCA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sources":["../../src/domains.ts"],"names":[],"mappings":"AAIA,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAKlE"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.domainHash = void 0;
|
|
4
|
+
const ethers_1 = require("ethers");
|
|
5
|
+
const addresses_1 = require("./addresses");
|
|
6
|
+
function domainHash(domain, mailbox) {
|
|
7
|
+
return ethers_1.utils.solidityKeccak256(['uint32', 'bytes32', 'string'], [domain, (0, addresses_1.addressToBytes32)(mailbox), 'HYPERLANE']);
|
|
8
|
+
}
|
|
9
|
+
exports.domainHash = domainHash;
|
|
10
|
+
//# sourceMappingURL=domains.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"domains.js","sourceRoot":"","sources":["../../src/domains.ts"],"names":[],"mappings":";;;AAAA,mCAA+B;AAE/B,2CAA+C;AAE/C,SAAgB,UAAU,CAAC,MAAc,EAAE,OAAe;IACxD,OAAO,cAAK,CAAC,iBAAiB,CAC5B,CAAC,QAAQ,EAAE,SAAS,EAAE,QAAQ,CAAC,EAC/B,CAAC,MAAM,EAAE,IAAA,4BAAgB,EAAC,OAAO,CAAC,EAAE,WAAW,CAAC,CACjD,CAAC;AACJ,CAAC;AALD,gCAKC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../src/env.ts"],"names":[],"mappings":"AAEA,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,sBAM9C"}
|
package/dist/src/env.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.safelyAccessEnvVar = void 0;
|
|
4
|
+
// Should be used instead of referencing process directly in case we don't
|
|
5
|
+
// run in node.js
|
|
6
|
+
function safelyAccessEnvVar(name) {
|
|
7
|
+
try {
|
|
8
|
+
return process.env[name];
|
|
9
|
+
}
|
|
10
|
+
catch (error) {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.safelyAccessEnvVar = safelyAccessEnvVar;
|
|
15
|
+
//# sourceMappingURL=env.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.js","sourceRoot":"","sources":["../../src/env.ts"],"names":[],"mappings":";;;AAAA,0EAA0E;AAC1E,iBAAiB;AACjB,SAAgB,kBAAkB,CAAC,IAAY;IAC7C,IAAI;QACF,OAAO,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;KAC1B;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,SAAS,CAAC;KAClB;AACH,CAAC;AAND,gDAMC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { BytesLike } from 'ethers';
|
|
2
|
+
/**
|
|
3
|
+
* Converts a 20-byte (or other length) ID to a 32-byte ID.
|
|
4
|
+
* Ensures that a bytes-like is 32 long. left-padding with 0s if not.
|
|
5
|
+
*
|
|
6
|
+
* @param data A string or array of bytes to canonize
|
|
7
|
+
* @returns A Uint8Array of length 32
|
|
8
|
+
*/
|
|
9
|
+
export declare function canonizeId(data: BytesLike): Uint8Array;
|
|
10
|
+
/**
|
|
11
|
+
* Converts an Hyperlane ID of 20 or 32 bytes to the corresponding EVM Address.
|
|
12
|
+
*
|
|
13
|
+
* For 32-byte IDs this enforces the EVM convention of using the LAST 20 bytes.
|
|
14
|
+
*
|
|
15
|
+
* @param data The data to truncate
|
|
16
|
+
* @returns A 20-byte, 0x-prepended hex string representing the EVM Address
|
|
17
|
+
* @throws if the data is not 20 or 32 bytes
|
|
18
|
+
*/
|
|
19
|
+
export declare function evmId(data: BytesLike): string;
|
|
20
|
+
//# sourceMappingURL=ids.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ids.d.ts","sourceRoot":"","sources":["../../src/ids.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAS,MAAM,QAAQ,CAAC;AAE1C;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,SAAS,GAAG,UAAU,CAUtD;AAED;;;;;;;;GAQG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM,CAU7C"}
|
package/dist/src/ids.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.evmId = exports.canonizeId = void 0;
|
|
4
|
+
const ethers_1 = require("ethers");
|
|
5
|
+
/**
|
|
6
|
+
* Converts a 20-byte (or other length) ID to a 32-byte ID.
|
|
7
|
+
* Ensures that a bytes-like is 32 long. left-padding with 0s if not.
|
|
8
|
+
*
|
|
9
|
+
* @param data A string or array of bytes to canonize
|
|
10
|
+
* @returns A Uint8Array of length 32
|
|
11
|
+
*/
|
|
12
|
+
function canonizeId(data) {
|
|
13
|
+
if (!data)
|
|
14
|
+
throw new Error('Bad input. Undefined');
|
|
15
|
+
const buf = ethers_1.utils.arrayify(data);
|
|
16
|
+
if (buf.length > 32) {
|
|
17
|
+
throw new Error('Too long');
|
|
18
|
+
}
|
|
19
|
+
if (buf.length !== 20 && buf.length != 32) {
|
|
20
|
+
throw new Error('bad input, expect address or bytes32');
|
|
21
|
+
}
|
|
22
|
+
return ethers_1.utils.zeroPad(buf, 32);
|
|
23
|
+
}
|
|
24
|
+
exports.canonizeId = canonizeId;
|
|
25
|
+
/**
|
|
26
|
+
* Converts an Hyperlane ID of 20 or 32 bytes to the corresponding EVM Address.
|
|
27
|
+
*
|
|
28
|
+
* For 32-byte IDs this enforces the EVM convention of using the LAST 20 bytes.
|
|
29
|
+
*
|
|
30
|
+
* @param data The data to truncate
|
|
31
|
+
* @returns A 20-byte, 0x-prepended hex string representing the EVM Address
|
|
32
|
+
* @throws if the data is not 20 or 32 bytes
|
|
33
|
+
*/
|
|
34
|
+
function evmId(data) {
|
|
35
|
+
const u8a = ethers_1.utils.arrayify(data);
|
|
36
|
+
if (u8a.length === 32) {
|
|
37
|
+
return ethers_1.utils.hexlify(u8a.slice(12, 32));
|
|
38
|
+
}
|
|
39
|
+
else if (u8a.length === 20) {
|
|
40
|
+
return ethers_1.utils.hexlify(u8a);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
throw new Error(`Invalid id length. expected 20 or 32. Got ${u8a.length}`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.evmId = evmId;
|
|
47
|
+
//# sourceMappingURL=ids.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ids.js","sourceRoot":"","sources":["../../src/ids.ts"],"names":[],"mappings":";;;AAAA,mCAA0C;AAE1C;;;;;;GAMG;AACH,SAAgB,UAAU,CAAC,IAAe;IACxC,IAAI,CAAC,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;IACnD,MAAM,GAAG,GAAG,cAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IACjC,IAAI,GAAG,CAAC,MAAM,GAAG,EAAE,EAAE;QACnB,MAAM,IAAI,KAAK,CAAC,UAAU,CAAC,CAAC;KAC7B;IACD,IAAI,GAAG,CAAC,MAAM,KAAK,EAAE,IAAI,GAAG,CAAC,MAAM,IAAI,EAAE,EAAE;QACzC,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;KACzD;IACD,OAAO,cAAK,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;AAChC,CAAC;AAVD,gCAUC;AAED;;;;;;;;GAQG;AACH,SAAgB,KAAK,CAAC,IAAe;IACnC,MAAM,GAAG,GAAG,cAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAEjC,IAAI,GAAG,CAAC,MAAM,KAAK,EAAE,EAAE;QACrB,OAAO,cAAK,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;KACzC;SAAM,IAAI,GAAG,CAAC,MAAM,KAAK,EAAE,EAAE;QAC5B,OAAO,cAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;KAC3B;SAAM;QACL,MAAM,IAAI,KAAK,CAAC,6CAA6C,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC;KAC5E;AACH,CAAC;AAVD,sBAUC"}
|
package/dist/src/logging.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
var _a;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.error = exports.warn = exports.log = exports.debug = exports.trace = void 0;
|
|
5
|
-
const
|
|
6
|
-
const ENV_LOG_LEVEL = ((_a = (0,
|
|
5
|
+
const env_1 = require("./env");
|
|
6
|
+
const ENV_LOG_LEVEL = ((_a = (0, env_1.safelyAccessEnvVar)('LOG_LEVEL')) !== null && _a !== void 0 ? _a : 'debug').toLowerCase();
|
|
7
7
|
const LOG_TRACE = ENV_LOG_LEVEL == 'trace';
|
|
8
8
|
const LOG_DEBUG = LOG_TRACE || ENV_LOG_LEVEL == 'debug';
|
|
9
9
|
const LOG_INFO = LOG_DEBUG || ENV_LOG_LEVEL == 'info';
|
package/dist/src/logging.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logging.js","sourceRoot":"","sources":["../../src/logging.ts"],"names":[],"mappings":";;;;AAAA
|
|
1
|
+
{"version":3,"file":"logging.js","sourceRoot":"","sources":["../../src/logging.ts"],"names":[],"mappings":";;;;AAAA,+BAA2C;AAK3C,MAAM,aAAa,GAAG,CACpB,MAAA,IAAA,wBAAkB,EAAC,WAAW,CAAC,mCAAI,OAAO,CAC3C,CAAC,WAAW,EAAe,CAAC;AAC7B,MAAM,SAAS,GAAG,aAAa,IAA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