@hyperlane-xyz/utils 1.4.2-beta69 → 1.4.2-beta71
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/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 +91 -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/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/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/package.json +1 -1
|
@@ -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(10 ** (fromDecimals - toDecimals));
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
// if (fromDecimals < toDecimals)
|
|
81
|
+
return value.mul(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,KAAU;IACvC,IAAI;QACF,IAAI,IAAA,kBAAS,EAAC,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC;QACnC,OAAO,kBAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,YAAY,CAAC;KAC3C;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,KAAK,CAAC;KACd;AACH,CAAC;AAPD,wCAOC;AAED,yEAAyE;AACzE,SAAgB,SAAS,CAAC,KAAmB;IAC3C,IAAI;QACF,IACE,CAAC,KAAK;YACN,KAAK,KAAK,kBAAS,CAAC,QAAQ;YAC5B,KAAK,KAAK,kBAAS,CAAC,WAAW;YAE/B,OAAO,IAAI,CAAC;QACd,OAAO,kBAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC;KACvC;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,KAAK,CAAC;KACd;AACH,CAAC;AAZD,8BAYC;AAED;;;;GAIG;AACH,SAAgB,UAAU,CAAC,GAAc;IACvC,OAAO,oBAAW,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;AAC1C,CAAC;AAFD,gCAEC;AAED;;;;;GAKG;AACH,SAAgB,UAAU,CAAC,KAAkB,EAAE,IAAI,GAAG,KAAK;IACzD,MAAM,cAAc,GAAG,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IAC9D,OAAO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""}
|
|
@@ -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":["../../src/big-numbers.test.ts"],"names":[],"mappings":";;AAAA,+BAA8B;AAC9B,mCAAgD;AAEhD,+CAAuE;AAEvE,QAAQ,CAAC,OAAO,EAAE,GAAG,EAAE;IACrB,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;QAC1B,EAAE,CAAC,uCAAuC,EAAE,GAAG,EAAE;YAC/C,MAAM,GAAG,GAAG,kBAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACnC,MAAM,KAAK,GAAG,IAAA,wBAAU,EAAC,GAAG,CAAC,CAAC;YAE9B,IAAA,aAAM,EAAC,KAAK,CAAC,aAAa,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC/C,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;QAC1B,EAAE,CAAC,+CAA+C,EAAE,GAAG,EAAE;YACvD,MAAM,KAAK,GAAG,oBAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACxC,MAAM,GAAG,GAAG,IAAA,wBAAU,EAAC,KAAK,CAAC,CAAC;YAE9B,IAAA,aAAM,EAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACtC,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,iDAAiD,EAAE,GAAG,EAAE;YACzD,MAAM,KAAK,GAAG,oBAAW,CAAC,IAAI,CAAC,OA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AK,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAEvC,wBAAgB,cAAc,CAC5B,CAAC,SAAS,QAAQ,EAClB,CAAC,SAAS,UAAU,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,oBAAoB,CAAC,CAAC,EAC1D,mBAAmB,EAAE,CAAC,EAAE,YAAY,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,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,mCAA+B;AAS/B,SAAS,gBAAgB,CAAC,SAAc;IACtC,OAAO,OAAO,SAAS,KAAK,QAAQ;QAClC,CAAC,CAAC,cAAK,CAAC,WAAW,CAAC,SAAS,CAAC;QAC9B,CAAC,CAAC,cAAK,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC;YAC5B,cAAK,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC;YAC9B,MAAM,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;AAC1C,CAAC;AAED,SAAgB,cAAc,CAAC,GAAQ;IACrC,OAAO,gBAAgB,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AACpE,CAAC;AAFD,wCAEC;AAED,SAAgB,oBAAoB,CAAC,GAAQ;IAC3C,OAAO,CACL,gBAAgB,CAAC,GAAG,CAAC,SAAS,CAAC;QAC/B,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC;QAClC,cAAK,CAAC,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,CACxC,CAAC;AACJ,CAAC;AAND,oDAMC;AAED,SAAgB,YAAY,CAAC,GAAQ;IACnC,MAAM,WAAW,GAAG,cAAK,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAChD,MAAM,YAAY,GAAG,MAAM,CAAC,aAAa,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACrD,MAAM,cAAc,GAAG,cAAK,CAAC,WAAW,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IAC9D,MAAM,aAAa,GAAG,MAAM,CAAC,aAAa,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IAC/D,OAAO,YAAY,IAAI,WAAW,IAAI,cAAc,IAAI,aAAa,CAAC;AACxE,CAAC;AAND,oCAMC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"domains.d.ts","sourceRoot":"","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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"math.d.ts","sourceRoot":"","sources":["../../src/math.ts"],"names":[],"mappings":"AAAA,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAM1C;AAED,wBAAgB,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAEvC;AAED,wBAAgB,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAExC;AAED,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAI1C"}
|
package/dist/src/math.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stdDev = exports.mean = exports.sum = exports.median = void 0;
|
|
4
|
+
function median(a) {
|
|
5
|
+
const sorted = a.slice().sort();
|
|
6
|
+
const mid = Math.floor(sorted.length / 2);
|
|
7
|
+
const median = sorted.length % 2 == 0 ? (sorted[mid] + sorted[mid + 1]) / 2 : sorted[mid];
|
|
8
|
+
return median;
|
|
9
|
+
}
|
|
10
|
+
exports.median = median;
|
|
11
|
+
function sum(a) {
|
|
12
|
+
return a.reduce((acc, i) => acc + i);
|
|
13
|
+
}
|
|
14
|
+
exports.sum = sum;
|
|
15
|
+
function mean(a) {
|
|
16
|
+
return sum(a) / a.length;
|
|
17
|
+
}
|
|
18
|
+
exports.mean = mean;
|
|
19
|
+
function stdDev(a) {
|
|
20
|
+
const xbar = mean(a);
|
|
21
|
+
const squaredDifferences = a.map((x) => Math.pow(x - xbar, 2));
|
|
22
|
+
return Math.sqrt(mean(squaredDifferences));
|
|
23
|
+
}
|
|
24
|
+
exports.stdDev = stdDev;
|
|
25
|
+
//# sourceMappingURL=math.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"math.js","sourceRoot":"","sources":["../../src/math.ts"],"names":[],"mappings":";;;AAAA,SAAgB,MAAM,CAAC,CAAW;IAChC,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,CAAC;IAChC,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC1C,MAAM,MAAM,GACV,MAAM,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC7E,OAAO,MAAM,CAAC;AAChB,CAAC;AAND,wBAMC;AAED,SAAgB,GAAG,CAAC,CAAW;IAC7B,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;AACvC,CAAC;AAFD,kBAEC;AAED,SAAgB,IAAI,CAAC,CAAW;IAC9B,OAAO,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;AAC3B,CAAC;AAFD,oBAEC;AAED,SAAgB,MAAM,CAAC,CAAW;IAChC,MAAM,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IACrB,MAAM,kBAAkB,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IAC/D,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,CAAC;AAC7C,CAAC;AAJD,wBAIC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { BigNumber } from 'ethers';
|
|
2
|
+
import { Address, Domain, HexString, ParsedMessage } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* JS Implementation of solidity/contracts/libs/Message.sol#formatMessage
|
|
5
|
+
* @returns Hex string of the packed message
|
|
6
|
+
*/
|
|
7
|
+
export declare const formatMessage: (version: number | BigNumber, nonce: number | BigNumber, originDomain: Domain, senderAddr: Address, destinationDomain: Domain, recipientAddr: Address, body: HexString) => HexString;
|
|
8
|
+
/**
|
|
9
|
+
* Get ID given message bytes
|
|
10
|
+
* @param message Hex string of the packed message (see formatMessage)
|
|
11
|
+
* @returns Hex string of message id
|
|
12
|
+
*/
|
|
13
|
+
export declare function messageId(message: HexString): HexString;
|
|
14
|
+
/**
|
|
15
|
+
* Parse a serialized Hyperlane message from raw bytes.
|
|
16
|
+
*
|
|
17
|
+
* @param message
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
export declare function parseMessage(message: string): ParsedMessage;
|
|
21
|
+
//# sourceMappingURL=messages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/messages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAiB,MAAM,QAAQ,CAAC;AAGlD,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAEpE;;;GAGG;AACH,eAAO,MAAM,aAAa,YACf,MAAM,GAAG,SAAS,SACpB,MAAM,GAAG,SAAS,gBACX,MAAM,cACR,OAAO,qBACA,MAAM,iBACV,OAAO,QAChB,SAAS,KACd,SAgBF,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,SAAS,GAAG,SAAS,CAEvD;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,aAAa,CAkB3D"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseMessage = exports.messageId = exports.formatMessage = void 0;
|
|
4
|
+
const ethers_1 = require("ethers");
|
|
5
|
+
const addresses_1 = require("./addresses");
|
|
6
|
+
/**
|
|
7
|
+
* JS Implementation of solidity/contracts/libs/Message.sol#formatMessage
|
|
8
|
+
* @returns Hex string of the packed message
|
|
9
|
+
*/
|
|
10
|
+
const formatMessage = (version, nonce, originDomain, senderAddr, destinationDomain, recipientAddr, body) => {
|
|
11
|
+
senderAddr = (0, addresses_1.addressToBytes32)(senderAddr);
|
|
12
|
+
recipientAddr = (0, addresses_1.addressToBytes32)(recipientAddr);
|
|
13
|
+
return ethers_1.ethers.utils.solidityPack(['uint8', 'uint32', 'uint32', 'bytes32', 'uint32', 'bytes32', 'bytes'], [
|
|
14
|
+
version,
|
|
15
|
+
nonce,
|
|
16
|
+
originDomain,
|
|
17
|
+
senderAddr,
|
|
18
|
+
destinationDomain,
|
|
19
|
+
recipientAddr,
|
|
20
|
+
body,
|
|
21
|
+
]);
|
|
22
|
+
};
|
|
23
|
+
exports.formatMessage = formatMessage;
|
|
24
|
+
/**
|
|
25
|
+
* Get ID given message bytes
|
|
26
|
+
* @param message Hex string of the packed message (see formatMessage)
|
|
27
|
+
* @returns Hex string of message id
|
|
28
|
+
*/
|
|
29
|
+
function messageId(message) {
|
|
30
|
+
return ethers_1.ethers.utils.solidityKeccak256(['bytes'], [message]);
|
|
31
|
+
}
|
|
32
|
+
exports.messageId = messageId;
|
|
33
|
+
/**
|
|
34
|
+
* Parse a serialized Hyperlane message from raw bytes.
|
|
35
|
+
*
|
|
36
|
+
* @param message
|
|
37
|
+
* @returns
|
|
38
|
+
*/
|
|
39
|
+
function parseMessage(message) {
|
|
40
|
+
const VERSION_OFFSET = 0;
|
|
41
|
+
const NONCE_OFFSET = 1;
|
|
42
|
+
const ORIGIN_OFFSET = 5;
|
|
43
|
+
const SENDER_OFFSET = 9;
|
|
44
|
+
const DESTINATION_OFFSET = 41;
|
|
45
|
+
const RECIPIENT_OFFSET = 45;
|
|
46
|
+
const BODY_OFFSET = 77;
|
|
47
|
+
const buf = Buffer.from(ethers_1.utils.arrayify(message));
|
|
48
|
+
const version = buf.readUint8(VERSION_OFFSET);
|
|
49
|
+
const nonce = buf.readUInt32BE(NONCE_OFFSET);
|
|
50
|
+
const origin = buf.readUInt32BE(ORIGIN_OFFSET);
|
|
51
|
+
const sender = ethers_1.utils.hexlify(buf.slice(SENDER_OFFSET, DESTINATION_OFFSET));
|
|
52
|
+
const destination = buf.readUInt32BE(DESTINATION_OFFSET);
|
|
53
|
+
const recipient = ethers_1.utils.hexlify(buf.slice(RECIPIENT_OFFSET, BODY_OFFSET));
|
|
54
|
+
const body = ethers_1.utils.hexlify(buf.slice(BODY_OFFSET));
|
|
55
|
+
return { version, nonce, origin, sender, destination, recipient, body };
|
|
56
|
+
}
|
|
57
|
+
exports.parseMessage = parseMessage;
|
|
58
|
+
//# sourceMappingURL=messages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file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AAO,GAAG,GAAG,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;IAC9C,MAAM,KAAK,GAAG,GAAG,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;IAC7C,MAAM,MAAM,GAAG,GAAG,CAAC,YAAY,CAAC,aAAa,CAAC,CAAC;IAC/C,MAAM,MAAM,GAAG,cAAK,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,aAAa,EAAE,kBAAkB,CAAC,CAAC,CAAC;IAC3E,MAAM,WAAW,GAAG,GAAG,CAAC,YAAY,CAAC,kBAAkB,CAAC,CAAC;IACzD,MAAM,SAAS,GAAG,cAAK,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,gBAAgB,EAAE,WAAW,CAAC,CAAC,CAAC;IAC1E,MAAM,IAAI,GAAG,cAAK,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC;IACnD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;AAC1E,CAAC;AAlBD,oCAkBC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ParsedLegacyMultisigIsmMetadata } from './types';
|
|
2
|
+
export declare const parseLegacyMultisigIsmMetadata: (metadata: string) => ParsedLegacyMultisigIsmMetadata;
|
|
3
|
+
export declare const formatLegacyMultisigIsmMetadata: (metadata: ParsedLegacyMultisigIsmMetadata) => string;
|
|
4
|
+
//# sourceMappingURL=multisig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multisig.d.ts","sourceRoot":"","sources":["../../src/multisig.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,+BAA+B,EAAE,MAAM,SAAS,CAAC;AAE1D,eAAO,MAAM,8BAA8B,aAC/B,MAAM,KACf,+BA4CF,CAAC;AAEF,eAAO,MAAM,+BAA+B,aAChC,+BAA+B,KACxC,MAqBF,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatLegacyMultisigIsmMetadata = exports.parseLegacyMultisigIsmMetadata = void 0;
|
|
4
|
+
const ethers_1 = require("ethers");
|
|
5
|
+
const addresses_1 = require("./addresses");
|
|
6
|
+
const parseLegacyMultisigIsmMetadata = (metadata) => {
|
|
7
|
+
const MERKLE_ROOT_OFFSET = 0;
|
|
8
|
+
const MERKLE_INDEX_OFFSET = 32;
|
|
9
|
+
const ORIGIN_MAILBOX_OFFSET = 36;
|
|
10
|
+
const MERKLE_PROOF_OFFSET = 68;
|
|
11
|
+
const THRESHOLD_OFFSET = 1092;
|
|
12
|
+
const SIGNATURES_OFFSET = 1093;
|
|
13
|
+
const SIGNATURE_LENGTH = 65;
|
|
14
|
+
const buf = Buffer.from(ethers_1.utils.arrayify(metadata));
|
|
15
|
+
const checkpointRoot = ethers_1.utils.hexlify(buf.slice(MERKLE_ROOT_OFFSET, MERKLE_INDEX_OFFSET));
|
|
16
|
+
const checkpointIndex = ethers_1.BigNumber.from(ethers_1.utils.hexlify(buf.slice(MERKLE_INDEX_OFFSET, ORIGIN_MAILBOX_OFFSET))).toNumber();
|
|
17
|
+
const originMailbox = ethers_1.utils.hexlify(buf.slice(ORIGIN_MAILBOX_OFFSET, MERKLE_PROOF_OFFSET));
|
|
18
|
+
const parseBytesArray = (start, count, size) => {
|
|
19
|
+
return [...Array(count).keys()].map((i) => ethers_1.utils.hexlify(buf.slice(start + size * i, start + size * (i + 1))));
|
|
20
|
+
};
|
|
21
|
+
const proof = parseBytesArray(MERKLE_PROOF_OFFSET, 32, 32);
|
|
22
|
+
const threshold = ethers_1.BigNumber.from(ethers_1.utils.hexlify(buf.slice(THRESHOLD_OFFSET, SIGNATURES_OFFSET))).toNumber();
|
|
23
|
+
const signatures = parseBytesArray(SIGNATURES_OFFSET, threshold, SIGNATURE_LENGTH);
|
|
24
|
+
const VALIDATORS_OFFSET = SIGNATURES_OFFSET + threshold * SIGNATURE_LENGTH;
|
|
25
|
+
const addressesCount = buf.slice(VALIDATORS_OFFSET).length / 32;
|
|
26
|
+
const validators = parseBytesArray(VALIDATORS_OFFSET, addressesCount, 32);
|
|
27
|
+
return {
|
|
28
|
+
checkpointRoot,
|
|
29
|
+
checkpointIndex,
|
|
30
|
+
originMailbox,
|
|
31
|
+
proof,
|
|
32
|
+
signatures,
|
|
33
|
+
validators,
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
exports.parseLegacyMultisigIsmMetadata = parseLegacyMultisigIsmMetadata;
|
|
37
|
+
const formatLegacyMultisigIsmMetadata = (metadata) => {
|
|
38
|
+
return ethers_1.utils.solidityPack([
|
|
39
|
+
'bytes32',
|
|
40
|
+
'uint32',
|
|
41
|
+
'bytes32',
|
|
42
|
+
'bytes32[32]',
|
|
43
|
+
'uint8',
|
|
44
|
+
'bytes',
|
|
45
|
+
'address[]',
|
|
46
|
+
], [
|
|
47
|
+
metadata.checkpointRoot,
|
|
48
|
+
metadata.checkpointIndex,
|
|
49
|
+
(0, addresses_1.addressToBytes32)(metadata.originMailbox),
|
|
50
|
+
metadata.proof,
|
|
51
|
+
metadata.signatures.length,
|
|
52
|
+
ethers_1.utils.hexConcat(metadata.signatures),
|
|
53
|
+
metadata.validators,
|
|
54
|
+
]);
|
|
55
|
+
};
|
|
56
|
+
exports.formatLegacyMultisigIsmMetadata = formatLegacyMultisigIsmMetadata;
|
|
57
|
+
//# sourceMappingURL=multisig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multisig.js","sourceRoot":"","sources":["../../src/multisig.ts"],"names":[],"mappings":";;;AAAA,mCAA0C;AAE1C,2CAA+C;AAGxC,MAAM,8BAA8B,GAAG,CAC5C,QAAgB,EACiB,EAAE;IACnC,MAAM,kBAAkB,GAAG,CAAC,CAAC;IAC7B,MAAM,mBAAmB,GAAG,EAA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KAAK,CAAC,gBAAgB,EAAE,iBAAiB,CAAC,CAAC,CAC9D,CAAC,QAAQ,EAAE,CAAC;IACb,MAAM,UAAU,GAAG,eAAe,CAChC,iBAAiB,EACjB,SAAS,EACT,gBAAgB,CACjB,CAAC;IACF,MAAM,iBAAiB,GAAG,iBAAiB,GAAG,SAAS,GAAG,gBAAgB,CAAC;IAC3E,MAAM,cAAc,GAAG,GAAG,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC,MAAM,GAAG,EAAE,CAAC;IAChE,MAAM,UAAU,GAAG,eAAe,CAAC,iBAAiB,EAAE,cAAc,EAAE,EAAE,CAAC,CAAC;IAC1E,OAAO;QACL,cAAc;QACd,eAAe;QACf,aAAa;QACb,KAAK;QACL,UAAU;QACV,UAAU;KACX,CAAC;AACJ,CAAC,CAAC;AA9CW,QAAA,8BAA8B,kCA8CzC;AAEK,MAAM,+BAA+B,GAAG,CAC7C,QAAyC,EACjC,EAAE;IACV,OAAO,cAAK,CAAC,YAAY,CACvB;QACE,SAAS;QACT,QAAQ;QACR,SAAS;QACT,aAAa;QACb,OAAO;QACP,OAAO;QACP,WAAW;KACZ,EACD;QACE,QAAQ,CAAC,cAAc;QACvB,QAAQ,CAAC,eAAe;QACxB,IAAA,4BAAgB,EAAC,QAAQ,CAAC,aAAa,CAAC;QACxC,QAAQ,CAAC,KAAK;QACd,QAAQ,CAAC,UAAU,CAAC,MAAM;QAC1B,cAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,UAAU,CAAC;QACpC,QAAQ,CAAC,UAAU;KACpB,CACF,CAAC;AACJ,CAAC,CAAC;AAvBW,QAAA,+BAA+B,mCAuB1C"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare function isObject(item: any): any;
|
|
2
|
+
export declare function deepEquals(v1: any, v2: any): boolean;
|
|
3
|
+
type MappedObject<M extends Record<any, any>, O> = {
|
|
4
|
+
[Property in keyof M]: O;
|
|
5
|
+
};
|
|
6
|
+
export type ValueOf<T> = T[keyof T];
|
|
7
|
+
export declare function objMapEntries<M extends Record<K, I>, K extends keyof M, O, I = ValueOf<M>>(obj: M, func: (k: K, v: I) => O): [K, O][];
|
|
8
|
+
export declare function objMap<M extends Record<K, I>, K extends keyof M, O, I = ValueOf<M>>(obj: M, func: (k: K, v: I) => O): MappedObject<M, O>;
|
|
9
|
+
export declare function objFilter<K extends string, I, O extends I>(obj: Record<K, I>, func: (k: K, v: I) => v is O): Record<K, O>;
|
|
10
|
+
export declare function promiseObjAll<K extends string, V>(obj: {
|
|
11
|
+
[key in K]: Promise<V>;
|
|
12
|
+
}): Promise<Record<K, V>>;
|
|
13
|
+
export declare function pick<K extends string, V = any>(obj: Record<K, V>, keys: K[]): Record<K, V>;
|
|
14
|
+
export declare function objMerge(a: Record<string, any>, b: Record<string, any>, max_depth?: number): any;
|
|
15
|
+
export declare function invertKeysAndValues(data: any): any;
|
|
16
|
+
export declare function arrayToObject(keys: Array<string | number>, val?: boolean): Record<string | number, boolean>;
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=objects.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"objects.d.ts","sourceRoot":"","sources":["../../src/objects.ts"],"names":[],"mappings":"AAAA,wBAAgB,QAAQ,CAAC,IAAI,EAAE,GAAG,OAEjC;AAED,wBAAgB,UAAU,CAAC,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,WAE1C;AAED,KAAK,YAAY,CAAC,CAAC,SAAS,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC,IAAI;KAChD,QAAQ,IAAI,MAAM,CAAC,GAAG,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;AAEpC,wBAAgB,aAAa,CAC3B,CAAC,SAAS,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EACtB,CAAC,SAAS,MAAM,CAAC,EACjB,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