@layerzerolabs/lz-proof-utility 0.0.3

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.
@@ -0,0 +1,93 @@
1
+ export declare const NETWORKS: string[];
2
+ export declare const OutboundProofType: {
3
+ MPT: number;
4
+ FP: number;
5
+ };
6
+ export declare const EVMUtilityVersion: {
7
+ V1: number;
8
+ V2: number;
9
+ V3: number;
10
+ V4: number;
11
+ };
12
+ export declare const UTILS_VERSION_LOOKUP: {
13
+ arbitrum: {
14
+ '0x4ee2f9b7cf3a68966c370f3eb2c16613d3235245': number;
15
+ '0x50500ccd11e29f14008c7778a6ced655727a21c3': number;
16
+ '0x5b23e2bae5c5f00e804ea2c4c9abe601604378fa': number;
17
+ };
18
+ avalanche: {
19
+ '0x4ee2f9b7cf3a68966c370f3eb2c16613d3235245': number;
20
+ '0x50500ccd11e29f14008c7778a6ced655727a21c3': number;
21
+ '0xcbd35a9b849342ad34a71e072d9947d4afb4e164': number;
22
+ };
23
+ bsc: {
24
+ '0x4ee2f9b7cf3a68966c370f3eb2c16613d3235245': number;
25
+ '0x50500ccd11e29f14008c7778a6ced655727a21c3': number;
26
+ '0xcff08a35a5f27f306e2da99ff198db90f13def77': number;
27
+ };
28
+ 'bsc-testnet': {
29
+ '0xfc256f1007e67abbd027536818142823b4596a24': number;
30
+ '0x1de92e6b8e8b6b150ea8588fe387a4f5fb4da778': number;
31
+ '0x76860669184330e6966a61188cfbd13486c7a6a6': number;
32
+ '0x4652b61781f5ee79dad354ab5d249aa2b99b4def': number;
33
+ };
34
+ 'bsc-sandbox': {
35
+ '0xf96093134adf151889ed72517979b2cd7144a831': number;
36
+ '0x1751181f9af72b37934006bbe989238498067563': number;
37
+ '0x8953031e74a172586e89ddb40b7d269b9186e74c': number;
38
+ };
39
+ ethereum: {
40
+ '0x2d61dcdd36f10b22176e0433b86f74567d529aaa': number;
41
+ '0x50500ccd11e29f14008c7778a6ced655727a21c3': number;
42
+ '0xe9ae261d3aff7d3fccf38fa2d612dd3897e07b2d': number;
43
+ };
44
+ fantom: {
45
+ '0x3c2269811836af69497e5f486a85d7316753cf62': number;
46
+ '0x50500ccd11e29f14008c7778a6ced655727a21c3': number;
47
+ '0x6f1686189f32e78f1d83e7c6ed433fcebc3a5b51': number;
48
+ };
49
+ 'fantom-testnet': {
50
+ '0x0c3d09a7d86652f5599b836ce3db685a86513487': number;
51
+ '0x7669ac2bb50d567fd4bfb1cb5154b79c1e5e4a92': number;
52
+ '0xdafbd7a68e4ddcaa864c6a1171bd6030d0ca9a43': number;
53
+ '0x843986e31e0e3fea5eaf01086f36e7d85c458bb1': number;
54
+ };
55
+ 'fantom-sandbox': {
56
+ '0x54f51642779b9dbf48cc653c40499c82b8f261b3': number;
57
+ '0x01de566a13dc4be329351d930b0d9a569a495e46': number;
58
+ '0xf96093134adf151889ed72517979b2cd7144a831': number;
59
+ };
60
+ 'avalanche-testnet': {
61
+ '0xa7ac9fadbe9f51e7aa96751aa53f4cbb8a07b9ba': number;
62
+ '0x08c2e2b98d35973a4b2ca7ce8815cdb7c6f474f0': number;
63
+ '0x0a833b15305ce8b64946098db286710ace7bbe94': number;
64
+ '0xd81a1c5c52495a23f75d7269c17c73cebea61233': number;
65
+ };
66
+ 'avalanche-sandbox': {
67
+ '0x8953031e74a172586e89ddb40b7d269b9186e74c': number;
68
+ '0x4d7248986395d24ec777b16ca3fa32de64ec0330': number;
69
+ '0x4489a462f812d6dca0bde380ebdac12eb5a9e85a': number;
70
+ };
71
+ 'polygon-testnet': {
72
+ '0x2c7b02ffbc9602e8c04901609ef17cb1c4c2a7f7': number;
73
+ '0x3f6055024105d22b9400e025a1ca3259bd8b1893': number;
74
+ '0xcb97d107a87c5e172e075de94d7ef4498f6f06d2': number;
75
+ '0xd8b2de57ccfbbd5cd1713542cb6790fd2e33fed6': number;
76
+ };
77
+ 'polygon-sandbox': {
78
+ '0x369cc088dcedaaad27df0185c4f78caae42ff942': number;
79
+ '0x46f703c2a92874d5d526878a2ccc44e9431720a5': number;
80
+ '0xee404727abfca5d08a2480b0b881745f25362828': number;
81
+ };
82
+ optimism: {
83
+ '0x4ee2f9b7cf3a68966c370f3eb2c16613d3235245': number;
84
+ '0x50500ccd11e29f14008c7778a6ced655727a21c3': number;
85
+ '0x5b23e2bae5c5f00e804ea2c4c9abe601604378fa': number;
86
+ };
87
+ polygon: {
88
+ '0x4ee2f9b7cf3a68966c370f3eb2c16613d3235245': number;
89
+ '0x50500ccd11e29f14008c7778a6ced655727a21c3': number;
90
+ '0x6f1686189f32e78f1d83e7c6ed433fcebc3a5b51': number;
91
+ };
92
+ };
93
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,QAAQ,UAA2D,CAAA;AAEhF,eAAO,MAAM,iBAAiB;;;CAG7B,CAAA;AAED,eAAO,MAAM,iBAAiB;;;;;CAK7B,CAAA;AAED,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgFhC,CAAA"}
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UTILS_VERSION_LOOKUP = exports.EVMUtilityVersion = exports.OutboundProofType = exports.NETWORKS = void 0;
4
+ exports.NETWORKS = ['default', 'hardhat', 'arbitrum', 'polygon', 'harmony'];
5
+ exports.OutboundProofType = {
6
+ MPT: 1,
7
+ FP: 2,
8
+ };
9
+ exports.EVMUtilityVersion = {
10
+ V1: 1,
11
+ V2: 2,
12
+ V3: 3,
13
+ V4: 4,
14
+ };
15
+ exports.UTILS_VERSION_LOOKUP = {
16
+ arbitrum: {
17
+ '0x4ee2f9b7cf3a68966c370f3eb2c16613d3235245': 1,
18
+ '0x50500ccd11e29f14008c7778a6ced655727a21c3': 2,
19
+ '0x5b23e2bae5c5f00e804ea2c4c9abe601604378fa': 2,
20
+ },
21
+ avalanche: {
22
+ '0x4ee2f9b7cf3a68966c370f3eb2c16613d3235245': 1,
23
+ '0x50500ccd11e29f14008c7778a6ced655727a21c3': 2,
24
+ '0xcbd35a9b849342ad34a71e072d9947d4afb4e164': 2,
25
+ },
26
+ bsc: {
27
+ '0x4ee2f9b7cf3a68966c370f3eb2c16613d3235245': 1,
28
+ '0x50500ccd11e29f14008c7778a6ced655727a21c3': 2,
29
+ '0xcff08a35a5f27f306e2da99ff198db90f13def77': 2,
30
+ },
31
+ 'bsc-testnet': {
32
+ '0xfc256f1007e67abbd027536818142823b4596a24': 1,
33
+ '0x1de92e6b8e8b6b150ea8588fe387a4f5fb4da778': 2,
34
+ '0x76860669184330e6966a61188cfbd13486c7a6a6': 2,
35
+ '0x4652b61781f5ee79dad354ab5d249aa2b99b4def': 2,
36
+ },
37
+ 'bsc-sandbox': {
38
+ '0xf96093134adf151889ed72517979b2cd7144a831': 1,
39
+ '0x1751181f9af72b37934006bbe989238498067563': 2,
40
+ '0x8953031e74a172586e89ddb40b7d269b9186e74c': 2,
41
+ },
42
+ ethereum: {
43
+ '0x2d61dcdd36f10b22176e0433b86f74567d529aaa': 1,
44
+ '0x50500ccd11e29f14008c7778a6ced655727a21c3': 2,
45
+ '0xe9ae261d3aff7d3fccf38fa2d612dd3897e07b2d': 2,
46
+ },
47
+ fantom: {
48
+ '0x3c2269811836af69497e5f486a85d7316753cf62': 1,
49
+ '0x50500ccd11e29f14008c7778a6ced655727a21c3': 2,
50
+ '0x6f1686189f32e78f1d83e7c6ed433fcebc3a5b51': 2,
51
+ },
52
+ 'fantom-testnet': {
53
+ '0x0c3d09a7d86652f5599b836ce3db685a86513487': 1,
54
+ '0x7669ac2bb50d567fd4bfb1cb5154b79c1e5e4a92': 2,
55
+ '0xdafbd7a68e4ddcaa864c6a1171bd6030d0ca9a43': 2,
56
+ '0x843986e31e0e3fea5eaf01086f36e7d85c458bb1': 2,
57
+ },
58
+ 'fantom-sandbox': {
59
+ '0x54f51642779b9dbf48cc653c40499c82b8f261b3': 1,
60
+ '0x01de566a13dc4be329351d930b0d9a569a495e46': 2,
61
+ '0xf96093134adf151889ed72517979b2cd7144a831': 2,
62
+ },
63
+ 'avalanche-testnet': {
64
+ '0xa7ac9fadbe9f51e7aa96751aa53f4cbb8a07b9ba': 1,
65
+ '0x08c2e2b98d35973a4b2ca7ce8815cdb7c6f474f0': 2,
66
+ '0x0a833b15305ce8b64946098db286710ace7bbe94': 2,
67
+ '0xd81a1c5c52495a23f75d7269c17c73cebea61233': 2,
68
+ },
69
+ 'avalanche-sandbox': {
70
+ '0x8953031e74a172586e89ddb40b7d269b9186e74c': 1,
71
+ '0x4d7248986395d24ec777b16ca3fa32de64ec0330': 2,
72
+ '0x4489a462f812d6dca0bde380ebdac12eb5a9e85a': 2,
73
+ },
74
+ 'polygon-testnet': {
75
+ '0x2c7b02ffbc9602e8c04901609ef17cb1c4c2a7f7': 1,
76
+ '0x3f6055024105d22b9400e025a1ca3259bd8b1893': 2,
77
+ '0xcb97d107a87c5e172e075de94d7ef4498f6f06d2': 2,
78
+ '0xd8b2de57ccfbbd5cd1713542cb6790fd2e33fed6': 2,
79
+ },
80
+ 'polygon-sandbox': {
81
+ '0x369cc088dcedaaad27df0185c4f78caae42ff942': 1,
82
+ '0x46f703c2a92874d5d526878a2ccc44e9431720a5': 2,
83
+ '0xee404727abfca5d08a2480b0b881745f25362828': 2,
84
+ },
85
+ optimism: {
86
+ '0x4ee2f9b7cf3a68966c370f3eb2c16613d3235245': 1,
87
+ '0x50500ccd11e29f14008c7778a6ced655727a21c3': 2,
88
+ '0x5b23e2bae5c5f00e804ea2c4c9abe601604378fa': 2,
89
+ },
90
+ polygon: {
91
+ '0x4ee2f9b7cf3a68966c370f3eb2c16613d3235245': 1,
92
+ '0x50500ccd11e29f14008c7778a6ced655727a21c3': 2,
93
+ '0x6f1686189f32e78f1d83e7c6ed433fcebc3a5b51': 2,
94
+ },
95
+ };
96
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,QAAQ,GAAG,CAAC,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,CAAC,CAAA;AAEnE,QAAA,iBAAiB,GAAG;IAC7B,GAAG,EAAE,CAAC;IACN,EAAE,EAAE,CAAC;CACR,CAAA;AAEY,QAAA,iBAAiB,GAAG;IAC7B,EAAE,EAAE,CAAC;IACL,EAAE,EAAE,CAAC;IACL,EAAE,EAAE,CAAC;IACL,EAAE,EAAE,CAAC;CACR,CAAA;AAEY,QAAA,oBAAoB,GAAG;IAChC,QAAQ,EAAE;QACN,4CAA4C,EAAE,CAAC;QAC/C,4CAA4C,EAAE,CAAC;QAC/C,4CAA4C,EAAE,CAAC;KAClD;IACD,SAAS,EAAE;QACP,4CAA4C,EAAE,CAAC;QAC/C,4CAA4C,EAAE,CAAC;QAC/C,4CAA4C,EAAE,CAAC;KAClD;IACD,GAAG,EAAE;QACD,4CAA4C,EAAE,CAAC;QAC/C,4CAA4C,EAAE,CAAC;QAC/C,4CAA4C,EAAE,CAAC;KAClD;IACD,aAAa,EAAE;QACX,4CAA4C,EAAE,CAAC;QAC/C,4CAA4C,EAAE,CAAC;QAC/C,4CAA4C,EAAE,CAAC;QAC/C,4CAA4C,EAAE,CAAC;KAClD;IACD,aAAa,EAAE;QACX,4CAA4C,EAAE,CAAC;QAC/C,4CAA4C,EAAE,CAAC;QAC/C,4CAA4C,EAAE,CAAC;KAClD;IACD,QAAQ,EAAE;QACN,4CAA4C,EAAE,CAAC;QAC/C,4CAA4C,EAAE,CAAC;QAC/C,4CAA4C,EAAE,CAAC;KAClD;IACD,MAAM,EAAE;QACJ,4CAA4C,EAAE,CAAC;QAC/C,4CAA4C,EAAE,CAAC;QAC/C,4CAA4C,EAAE,CAAC;KAClD;IACD,gBAAgB,EAAE;QACd,4CAA4C,EAAE,CAAC;QAC/C,4CAA4C,EAAE,CAAC;QAC/C,4CAA4C,EAAE,CAAC;QAC/C,4CAA4C,EAAE,CAAC;KAClD;IACD,gBAAgB,EAAE;QACd,4CAA4C,EAAE,CAAC;QAC/C,4CAA4C,EAAE,CAAC;QAC/C,4CAA4C,EAAE,CAAC;KAClD;IACD,mBAAmB,EAAE;QACjB,4CAA4C,EAAE,CAAC;QAC/C,4CAA4C,EAAE,CAAC;QAC/C,4CAA4C,EAAE,CAAC;QAC/C,4CAA4C,EAAE,CAAC;KAClD;IACD,mBAAmB,EAAE;QACjB,4CAA4C,EAAE,CAAC;QAC/C,4CAA4C,EAAE,CAAC;QAC/C,4CAA4C,EAAE,CAAC;KAClD;IACD,iBAAiB,EAAE;QACf,4CAA4C,EAAE,CAAC;QAC/C,4CAA4C,EAAE,CAAC;QAC/C,4CAA4C,EAAE,CAAC;QAC/C,4CAA4C,EAAE,CAAC;KAClD;IACD,iBAAiB,EAAE;QACf,4CAA4C,EAAE,CAAC;QAC/C,4CAA4C,EAAE,CAAC;QAC/C,4CAA4C,EAAE,CAAC;KAClD;IACD,QAAQ,EAAE;QACN,4CAA4C,EAAE,CAAC;QAC/C,4CAA4C,EAAE,CAAC;QAC/C,4CAA4C,EAAE,CAAC;KAClD;IACD,OAAO,EAAE;QACL,4CAA4C,EAAE,CAAC;QAC/C,4CAA4C,EAAE,CAAC;QAC/C,4CAA4C,EAAE,CAAC;KAClD;CACJ,CAAA"}
@@ -0,0 +1,3 @@
1
+ export * from './constants';
2
+ export * as proofUtils from './proof';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,OAAO,KAAK,UAAU,MAAM,SAAS,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,32 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
19
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
20
+ };
21
+ var __importStar = (this && this.__importStar) || function (mod) {
22
+ if (mod && mod.__esModule) return mod;
23
+ var result = {};
24
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
25
+ __setModuleDefault(result, mod);
26
+ return result;
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.proofUtils = void 0;
30
+ __exportStar(require("./constants"), exports);
31
+ exports.proofUtils = __importStar(require("./proof"));
32
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8CAA2B;AAC3B,sDAAqC"}
@@ -0,0 +1,7 @@
1
+ export declare function getPolygonStateSyncTxHash(block: any): any;
2
+ export declare function buffer2hex(buffer: any): string;
3
+ export declare function receiptProofFrom(network: any, block: any, transactionReceipts: any, transactionIndex: any): Promise<{
4
+ stack: any;
5
+ receiptProof: any;
6
+ }>;
7
+ //# sourceMappingURL=common.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/mpt/common.ts"],"names":[],"mappings":"AAgBA,wBAAgB,yBAAyB,CAAC,KAAK,KAAA,OAU9C;AAED,wBAAgB,UAAU,CAAC,MAAM,KAAA,UAEhC;AAED,wBAAsB,gBAAgB,CAAC,OAAO,KAAA,EAAE,KAAK,KAAA,EAAE,mBAAmB,KAAA,EAAE,gBAAgB,KAAA;;;GAgD3F"}
@@ -0,0 +1,92 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.receiptProofFrom = exports.buffer2hex = exports.getPolygonStateSyncTxHash = void 0;
30
+ // getStateSyncTxHash returns block's tx hash for state-sync receipt
31
+ // Bor blockchain includes extra receipt/tx for state-sync logs,
32
+ // but it is not included in transactionRoot or receiptRoot.
33
+ // So, while calculating proof, we have to exclude them.
34
+ //
35
+ // This is derived from block's hash and number
36
+ // state-sync tx hash = keccak256("matic-bor-receipt-" + block.number + block.hash)
37
+ const eth_object_1 = require("eth-object");
38
+ const eth_util_lite_1 = require("eth-util-lite");
39
+ const ethUtils = __importStar(require("ethereumjs-util"));
40
+ const promisfy_1 = require("promisfy");
41
+ const safer_buffer_1 = require("safer-buffer");
42
+ const tiny_invariant_1 = __importDefault(require("tiny-invariant"));
43
+ const Tree = require('merkle-patricia-tree');
44
+ function getPolygonStateSyncTxHash(block) {
45
+ return ethUtils.bufferToHex(ethUtils.keccak256(safer_buffer_1.Buffer.concat([
46
+ ethUtils.toBuffer('matic-bor-receipt-'),
47
+ ethUtils.setLengthLeft(ethUtils.toBuffer(block.number), 8),
48
+ ethUtils.toBuffer(block.hash), // block hash
49
+ ])));
50
+ }
51
+ exports.getPolygonStateSyncTxHash = getPolygonStateSyncTxHash;
52
+ function buffer2hex(buffer) {
53
+ return '0x' + buffer.toString('hex');
54
+ }
55
+ exports.buffer2hex = buffer2hex;
56
+ async function receiptProofFrom(network, block, transactionReceipts, transactionIndex) {
57
+ // handle the polygon special receipt
58
+ if (network === 'polygon') {
59
+ const ignoredTxnHash = getPolygonStateSyncTxHash(block);
60
+ transactionReceipts = transactionReceipts.filter((receipt) => receipt.transactionHash !== ignoredTxnHash);
61
+ }
62
+ const tree = new Tree();
63
+ await Promise.all(transactionReceipts.map((siblingReceipt, index) => {
64
+ const siblingPath = (0, eth_util_lite_1.encode)(index);
65
+ if (network === 'harmony' && index >= block.transactions.length) {
66
+ // void staking receipt type, which works differently from EIP2718
67
+ siblingReceipt.type = 0;
68
+ }
69
+ let serializedReceipt = eth_object_1.Receipt.fromRpc(siblingReceipt);
70
+ //handles the arbitrum receipt
71
+ if (network === 'arbitrum') {
72
+ //todo: will not need this in aribtrum nitro
73
+ serializedReceipt[0] = (0, eth_util_lite_1.toBuffer)(0);
74
+ }
75
+ serializedReceipt = serializedReceipt.serialize();
76
+ // if type is defined, concat type and RLP buffer seperately (for receipts/transactions following EIP2718)
77
+ if (siblingReceipt.type) {
78
+ serializedReceipt = safer_buffer_1.Buffer.concat([(0, eth_util_lite_1.toBuffer)(siblingReceipt.type), serializedReceipt]);
79
+ }
80
+ return (0, promisfy_1.promisfy)(tree.put, tree)(siblingPath, serializedReceipt);
81
+ }));
82
+ const [_, __, stack] = await (0, promisfy_1.promisfy)(tree.findPath, tree)((0, eth_util_lite_1.encode)(transactionIndex));
83
+ // assert the tree root
84
+ const receiptRootFromBlock = block.receiptsRoot.slice(2);
85
+ (0, tiny_invariant_1.default)(receiptRootFromBlock === tree._root.toString('hex'), 'receiptRoot from rpc block != receipt root we built');
86
+ return {
87
+ stack: stack,
88
+ receiptProof: eth_object_1.Proof.fromStack(stack),
89
+ };
90
+ }
91
+ exports.receiptProofFrom = receiptProofFrom;
92
+ //# sourceMappingURL=common.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.js","sourceRoot":"","sources":["../../src/mpt/common.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oEAAoE;AACpE,gEAAgE;AAChE,4DAA4D;AAC5D,wDAAwD;AACxD,EAAE;AACF,+CAA+C;AAC/C,mFAAmF;AACnF,2CAA2C;AAC3C,iDAAgD;AAChD,0DAA2C;AAC3C,uCAAmC;AACnC,+CAAqC;AACrC,oEAAsC;AAEtC,MAAM,IAAI,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAAA;AAE5C,SAAgB,yBAAyB,CAAC,KAAK;IAC3C,OAAO,QAAQ,CAAC,WAAW,CACvB,QAAQ,CAAC,SAAS,CACd,qBAAM,CAAC,MAAM,CAAC;QACV,QAAQ,CAAC,QAAQ,CAAC,oBAAoB,CAAC;QACvC,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;Q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AI,EAAE;YACrB,iBAAiB,GAAG,qBAAM,CAAC,MAAM,CAAC,CAAC,IAAA,wBAAQ,EAAC,cAAc,CAAC,IAAI,CAAC,EAAE,iBAAiB,CAAC,CAAC,CAAA;SACxF;QAED,OAAO,IAAA,mBAAQ,EAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,WAAW,EAAE,iBAAiB,CAAC,CAAA;IACnE,CAAC,CAAC,CACL,CAAA;IAED,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,CAAC,GAAG,MAAM,IAAA,mBAAQ,EAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,IAAA,sBAAM,EAAC,gBAAgB,CAAC,CAAC,CAAA;IAEpF,uBAAuB;IACvB,MAAM,oBAAoB,GAAG,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IACxD,IAAA,wBAAS,EACL,oBAAoB,KAAK,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,EACnD,qDAAqD,CACxD,CAAA;IAED,OAAO;QACH,KAAK,EAAE,KAAK;QACZ,YAAY,EAAE,kBAAK,CAAC,SAAS,CAAC,KAAK,CAAC;KACvC,CAAA;AACL,CAAC;AAhDD,4CAgDC"}
@@ -0,0 +1,7 @@
1
+ export declare function getReceiptProof(network: any, block: any, transactionReceipts: any, transactionIndex: any): Promise<{
2
+ receiptRoot: any;
3
+ proof: string[];
4
+ pointers: number[];
5
+ receiptSlotIndex: any;
6
+ }>;
7
+ //# sourceMappingURL=v1.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"v1.d.ts","sourceRoot":"","sources":["../../src/mpt/v1.ts"],"names":[],"mappings":"AA0HA,wBAAsB,eAAe,CAAC,OAAO,KAAA,EAAE,KAAK,KAAA,EAAE,mBAAmB,KAAA,EAAE,gBAAgB,KAAA;;;;;GAG1F"}
package/dist/mpt/v1.js ADDED
@@ -0,0 +1,115 @@
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.getReceiptProof = void 0;
7
+ const ethereumjs_util_1 = require("ethereumjs-util");
8
+ const ethers_1 = require("ethers");
9
+ const nibbles_1 = require("merkle-patricia-tree/util/nibbles");
10
+ const tiny_invariant_1 = __importDefault(require("tiny-invariant"));
11
+ const common_1 = require("./common");
12
+ function findPointer(fullBytes, currentNodeElement) {
13
+ const fullBytesHex = fullBytes.toString('hex');
14
+ const slicedBytesHex = currentNodeElement.toString('hex');
15
+ const result = fullBytesHex.indexOf(slicedBytesHex);
16
+ (0, tiny_invariant_1.default)(result >= 0, 'wrong index');
17
+ return (result - 2) / 2;
18
+ }
19
+ /*
20
+ running MPT locally, strictly the same as solidity file
21
+ */
22
+ function assertReceiptInclusion(receiptsRoot, expectedLogValue, rlpProof, pointers) {
23
+ let nextRoot = receiptsRoot;
24
+ const proofDepth = rlpProof.length;
25
+ let pointer;
26
+ let proofBytes;
27
+ for (let i = 0; i < proofDepth; i++) {
28
+ proofBytes = rlpProof[i];
29
+ if (nextRoot !== ethers_1.ethers.utils.keccak256(proofBytes))
30
+ return false;
31
+ // load 32 bytes from the proofBytes
32
+ if (i < pointers.length) {
33
+ pointer = 2 + pointers[i] * 2;
34
+ nextRoot = '0x' + proofBytes.substring(pointer, pointer + 64);
35
+ }
36
+ }
37
+ return true;
38
+ }
39
+ function assembleMPTProof(proof, block, transactionIndex) {
40
+ const stack = proof.stack;
41
+ // convert receipt Proof L2 nested contents into hex
42
+ const rlpNestedProof = [...proof.receiptProof].map((node) => node.map((elem) => (0, common_1.buffer2hex)(elem)));
43
+ const rlpProof = rlpNestedProof.map((node) => (0, common_1.buffer2hex)(ethereumjs_util_1.rlp.encode(node)));
44
+ // decimal of transaction index
45
+ const receiptIndexDeci = ethers_1.ethers.BigNumber.from(transactionIndex).toNumber();
46
+ const encodedMerklePath = (0, nibbles_1.stringToNibbles)(ethereumjs_util_1.rlp.encode(receiptIndexDeci)); // if index = 252, encoded = 81fc
47
+ // prepare the data for offline traversal
48
+ let hashRoot = block.receiptsRoot;
49
+ const proofDepth = stack.length;
50
+ // const targetReceipt = stack[proofDepth - 1].value;
51
+ const targetReceipt = rlpNestedProof[rlpNestedProof.length - 1][1];
52
+ let proofPathCounter = 0;
53
+ const totalPathLength = encodedMerklePath.length;
54
+ const pointers = [];
55
+ let receiptSlotIndex;
56
+ for (let i = 0; i < proofDepth; i++) {
57
+ // assert the path depth constaints
58
+ (0, tiny_invariant_1.default)(proofPathCounter <= totalPathLength, `proofPathCounter wrong at ${proofPathCounter}, where totalPathLength = ${totalPathLength}`);
59
+ // thisNodeValue in array form, easier to retrieve data
60
+ const thisNode = stack[i];
61
+ const thisNodeValue = thisNode.raw;
62
+ // convert the elem first then hex again, it is == rlpNestedProof[i]
63
+ const thisNodeRlp = rlpProof[i];
64
+ (0, tiny_invariant_1.default)(ethers_1.ethers.utils.keccak256(thisNodeRlp) === hashRoot, `invalid hashlink at depth ${i} | proofPathCounter ${proofPathCounter} | totalPathLength = ${totalPathLength}`);
65
+ if (thisNode.type === 'branch') {
66
+ // branch node
67
+ if (proofPathCounter === totalPathLength) {
68
+ // has reach the end, assert targetReceipt ==
69
+ (0, tiny_invariant_1.default)(ethers_1.ethers.utils.keccak256(thisNodeValue[16]) === targetReceipt, 'invalid branch value node');
70
+ receiptSlotIndex = 16;
71
+ }
72
+ else {
73
+ // a normal branch node, step down
74
+ const nextNibble = encodedMerklePath[proofPathCounter];
75
+ (0, tiny_invariant_1.default)(nextNibble <= 16, `invalid nibble at ${nextNibble} | proofPathCounter ${proofPathCounter} | totalPathLength = ${totalPathLength}`);
76
+ // hashRoot = buffer2hex(thisNode._branches[nextNibble])
77
+ hashRoot = (0, common_1.buffer2hex)(thisNodeValue[nextNibble]);
78
+ proofPathCounter += 1;
79
+ // retrieve the pointer for the branch value
80
+ pointers.push(findPointer(thisNodeRlp, thisNodeValue[nextNibble]));
81
+ }
82
+ }
83
+ else if (thisNode.type === 'leaf' || thisNode.type === 'extention') {
84
+ const progressKey = encodedMerklePath.slice(0, proofPathCounter);
85
+ const keyRemainder = encodedMerklePath.slice((0, nibbles_1.matchingNibbleLength)(progressKey, encodedMerklePath));
86
+ proofPathCounter += (0, nibbles_1.matchingNibbleLength)(keyRemainder, stack[i].key);
87
+ if (thisNode.type === 'leaf') {
88
+ (0, tiny_invariant_1.default)(proofPathCounter === totalPathLength, 'invalid leaf node');
89
+ (0, tiny_invariant_1.default)(ethers_1.ethers.utils.keccak256(thisNodeValue[1]) === ethers_1.ethers.utils.keccak256(targetReceipt), 'wrong leaf value');
90
+ receiptSlotIndex = 1;
91
+ }
92
+ else if (thisNode.type === 'extention') {
93
+ hashRoot = (0, common_1.buffer2hex)(thisNodeValue[1]);
94
+ // retrieve the pointer for the leaf node
95
+ pointers.push(findPointer(thisNodeRlp, thisNodeValue[1]));
96
+ }
97
+ }
98
+ else {
99
+ throw `unsupported node type in MPT ${thisNode} ${encodedMerklePath}`;
100
+ }
101
+ }
102
+ (0, tiny_invariant_1.default)(assertReceiptInclusion(block.receiptsRoot, targetReceipt, rlpProof, pointers), 'MPTLite local fails');
103
+ return {
104
+ receiptRoot: block.receiptsRoot,
105
+ proof: rlpProof,
106
+ pointers: pointers,
107
+ receiptSlotIndex: receiptSlotIndex,
108
+ };
109
+ }
110
+ async function getReceiptProof(network, block, transactionReceipts, transactionIndex) {
111
+ const proof = await (0, common_1.receiptProofFrom)(network, block, transactionReceipts, transactionIndex);
112
+ return assembleMPTProof(proof, block, transactionIndex);
113
+ }
114
+ exports.getReceiptProof = getReceiptProof;
115
+ //# sourceMappingURL=v1.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"v1.js","sourceRoot":"","sources":["../../src/mpt/v1.ts"],"names":[],"mappings":";;;;;;AAAA,qDAAqC;AACrC,mCAA+B;AAC/B,+DAAyF;AACzF,oEAAsC;A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GAAG,MAAM,IAAA,yBAAgB,EAAC,OAAO,EAAE,KAAK,EAAE,mBAAmB,EAAE,gBAAgB,CAAC,CAAA;IAC3F,OAAO,gBAAgB,CAAC,KAAK,EAAE,KAAK,EAAE,gBAAgB,CAAC,CAAA;AAC3D,CAAC;AAHD,0CAGC"}
@@ -0,0 +1,6 @@
1
+ export declare function getReceiptProof(network: any, block: any, transactionReceipts: any, transactionIndex: any): Promise<{
2
+ receiptRoot: any;
3
+ proof: string[];
4
+ receiptSlotIndex: number[];
5
+ }>;
6
+ //# sourceMappingURL=v2.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"v2.d.ts","sourceRoot":"","sources":["../../src/mpt/v2.ts"],"names":[],"mappings":"AAiHA,wBAAsB,eAAe,CAAC,OAAO,KAAA,EAAE,KAAK,KAAA,EAAE,mBAAmB,KAAA,EAAE,gBAAgB,KAAA;;;;GAG1F"}
package/dist/mpt/v2.js ADDED
@@ -0,0 +1,106 @@
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.getReceiptProof = void 0;
7
+ const ethereumjs_util_1 = require("ethereumjs-util");
8
+ const ethers_1 = require("ethers");
9
+ const nibbles_1 = require("merkle-patricia-tree/util/nibbles");
10
+ const tiny_invariant_1 = __importDefault(require("tiny-invariant"));
11
+ const common_1 = require("./common");
12
+ function assembleMPTProof(proof, block, transactionIndex) {
13
+ const stack = proof.stack;
14
+ // convert receipt Proof L2 nested contents into hex
15
+ const rlpNestedProof = [...proof.receiptProof].map((node) => node.map((elem) => (0, common_1.buffer2hex)(elem)));
16
+ const rlpProof = rlpNestedProof.map((node) => (0, common_1.buffer2hex)(ethereumjs_util_1.rlp.encode(node)));
17
+ // decimal of transaction index
18
+ const receiptIndexDeci = ethers_1.ethers.BigNumber.from(transactionIndex).toNumber();
19
+ const encodedMerklePath = (0, nibbles_1.stringToNibbles)(ethereumjs_util_1.rlp.encode(receiptIndexDeci)); // if index = 252, encoded = 81fc
20
+ // prepare the data for offline traversal
21
+ let hashRoot = block.receiptsRoot;
22
+ const proofDepth = stack.length;
23
+ // const targetReceipt = stack[proofDepth - 1].value;
24
+ const targetReceipt = rlpNestedProof[rlpNestedProof.length - 1][1];
25
+ let proofPathCounter = 0;
26
+ const totalPathLength = encodedMerklePath.length;
27
+ const path = [];
28
+ for (let i = 0; i < proofDepth; i++) {
29
+ // console.log(`hashroot at ${i} : ${hashRoot}`)
30
+ // console.log(` rlpProof at ${rlpProof[i]}`)
31
+ // assert the path depth constraints
32
+ (0, tiny_invariant_1.default)(proofPathCounter <= totalPathLength, `proofPathCounter wrong at ${proofPathCounter}, where totalPathLength = ${totalPathLength}`);
33
+ // thisNodeValue in array form, easier to retrieve data
34
+ const thisNode = stack[i];
35
+ const thisNodeValue = thisNode.raw;
36
+ // convert the elem first then hex again, it is == rlpNestedProof[i]
37
+ const thisNodeRlp = rlpProof[i];
38
+ (0, tiny_invariant_1.default)(ethers_1.ethers.utils.keccak256(thisNodeRlp) === hashRoot, `invalid hashlink at depth ${i} | proofPathCounter ${proofPathCounter} | totalPathLength = ${totalPathLength}`);
39
+ if (thisNode.type === 'branch') {
40
+ // branch node
41
+ if (proofPathCounter === totalPathLength) {
42
+ // has reach the end, assert targetReceipt ==
43
+ (0, tiny_invariant_1.default)(ethers_1.ethers.utils.keccak256(thisNodeValue[16]) === targetReceipt, 'invalid branch value node');
44
+ path[i] = 16;
45
+ console.warn(`a branch node 16 value type ${transactionIndex} receipt root ${block.receiptsRoot}`);
46
+ }
47
+ else {
48
+ // a normal branch node, step down
49
+ const nextNibble = encodedMerklePath[proofPathCounter];
50
+ (0, tiny_invariant_1.default)(nextNibble <= 16, `invalid nibble at ${nextNibble} | proofPathCounter ${proofPathCounter} | totalPathLength = ${totalPathLength}`);
51
+ // hashRoot = buffer2hex(thisNode._branches[nextNibble])
52
+ hashRoot = (0, common_1.buffer2hex)(thisNodeValue[nextNibble]);
53
+ proofPathCounter += 1;
54
+ // retrieve the pointer for the branch value
55
+ path[i] = nextNibble;
56
+ }
57
+ }
58
+ else if (thisNode.type === 'leaf' || thisNode.type === 'extention') {
59
+ const progressKey = encodedMerklePath.slice(0, proofPathCounter);
60
+ const keyRemainder = encodedMerklePath.slice((0, nibbles_1.matchingNibbleLength)(progressKey, encodedMerklePath));
61
+ proofPathCounter += (0, nibbles_1.matchingNibbleLength)(keyRemainder, stack[i].key);
62
+ if (thisNode.type === 'leaf') {
63
+ (0, tiny_invariant_1.default)(proofPathCounter === totalPathLength, 'invalid leaf node');
64
+ (0, tiny_invariant_1.default)(ethers_1.ethers.utils.keccak256(thisNodeValue[1]) === ethers_1.ethers.utils.keccak256(targetReceipt), 'wrong leaf value');
65
+ path[i] = 1;
66
+ }
67
+ else if (thisNode.type === 'extention') {
68
+ path[i] = 1;
69
+ hashRoot = (0, common_1.buffer2hex)(thisNodeValue[1]);
70
+ // retrieve the pointer for the leaf node
71
+ }
72
+ }
73
+ else {
74
+ throw `unsupported node type in MPT ${thisNode} ${encodedMerklePath}`;
75
+ }
76
+ }
77
+ (0, tiny_invariant_1.default)(assertReceiptInclusion(block.receiptsRoot, targetReceipt, rlpProof, path, stack), 'MPTLite local fails');
78
+ return {
79
+ receiptRoot: block.receiptsRoot,
80
+ proof: rlpProof,
81
+ receiptSlotIndex: path,
82
+ };
83
+ }
84
+ /*
85
+ running MPT locally, strictly the same as solidity file
86
+ */
87
+ function assertReceiptInclusion(receiptsRoot, expectedLogValue, rlpProof, path, stack) {
88
+ let nextRoot = receiptsRoot;
89
+ const proofDepth = rlpProof.length;
90
+ for (let i = 0; i < proofDepth; i++) {
91
+ const proofBytes = rlpProof[i];
92
+ const thisNodeValue = stack[i].raw;
93
+ if (nextRoot !== ethers_1.ethers.utils.keccak256(proofBytes))
94
+ return false;
95
+ if (i < proofDepth - 1) {
96
+ nextRoot = (0, common_1.buffer2hex)(thisNodeValue[path[i]]);
97
+ }
98
+ }
99
+ return true;
100
+ }
101
+ async function getReceiptProof(network, block, transactionReceipts, transactionIndex) {
102
+ const proof = await (0, common_1.receiptProofFrom)(network, block, transactionReceipts, transactionIndex);
103
+ return assembleMPTProof(proof, block, transactionIndex);
104
+ }
105
+ exports.getReceiptProof = getReceiptProof;
106
+ //# sourceMappingURL=v2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"v2.js","sourceRoot":"","sources":["../../src/mpt/v2.ts"],"names":[],"mappings":";;;;;;AAAA,qDAAqC;AACrC,mCAA+B;AAC/B,+DAAyF;AACzF,oEAAsC;AAEtC,qCAAuD;AAEvD,SAAS,gBAAgB,CAAC,KAAK,EAAE,KAAK,EAAE,gBAAgB;IACpD,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAA;IAEzB,oDAAoD;IACpD,MAAM,cAAc,GAAG,CAAC,GAAG,KAAK,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAA,mBAAU,EAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IAClG,MAAM,QAAQ,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAA,mBAAU,EAAC,qBAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IAE3E,+BAA+B;IAC/B,MAAM,gBAAgB,GAAG,eAAM,CAAC,SAAS,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,QAAQ,EAAE,CAAA;IAC3E,MAAM,iBAAiB,GAAG,IAAA,yBAAe,EAAC,qBAAG,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC,CAAA,CAAC,iCAAiC;IAEzG,yCAAyC;IACzC,IAAI,QAAQ,GAAG,KAAK,CAAC,YAAY,CAAA;IACjC,MAAM,UAAU,GAAG,KAAK,CAAC,MAAM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AE,mBAAmB,EAAE,gBAAgB,CAAC,CAAA;IAC3F,OAAO,gBAAgB,CAAC,KAAK,EAAE,KAAK,EAAE,gBAAgB,CAAC,CAAA;AAC3D,CAAC;AAHD,0CAGC"}
@@ -0,0 +1,24 @@
1
+ export declare function getFeatherProof(utilsVersion: any, emitterAddress: any, packetPayload: any): {
2
+ proof: any;
3
+ };
4
+ export declare function getReceiptProof(network: any, block: any, transactionReceipts: any, transactionIndex: any, outboundProofType: any, utilsVersion: any): Promise<{
5
+ receiptRoot: any;
6
+ proof: string[];
7
+ pointers: number[];
8
+ receiptSlotIndex: any;
9
+ } | {
10
+ receiptRoot: any;
11
+ proof: string[];
12
+ receiptSlotIndex: number[];
13
+ }>;
14
+ export declare function encodeParams(proof: any, outboundProofType: any, utilsVersion: any, logIndex: any, srcEndpointId?: undefined): string;
15
+ export declare function getLayerZeroPacket(srcChainId: any, _log: any): {
16
+ srcChainId: any;
17
+ dstChainId: number;
18
+ nonce: number;
19
+ dstAddress: string;
20
+ srcAddress: string;
21
+ ulnAddress: string;
22
+ payload: string;
23
+ };
24
+ //# sourceMappingURL=proof.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proof.d.ts","sourceRoot":"","sources":["../src/proof.ts"],"names":[],"mappings":"AAOA,wBAAgB,eAAe,CAAC,YAAY,KAAA,EAAE,cAAc,KAAA,EAAE,aAAa,KAAA;;EAgB1E;AAED,wBAAsB,eAAe,CACjC,OAAO,KAAA,EACP,KAAK,KAAA,EACL,mBAAmB,KAAA,EACnB,gBAAgB,KAAA,EAChB,iBAAiB,KAAA,EACjB,YAAY,KAAA;;;;;;;;;GA0Bf;AAED,wBAAgB,YAAY,CAAC,KAAK,KAAA,EAAE,iBAAiB,KAAA,EAAE,YAAY,KAAA,EAAE,QAAQ,KAAA,EAAE,aAAa,YAAY,UAmCvG;AAED,wBAAgB,kBAAkB,CAAC,UAAU,KAAA,EAAE,IAAI,KAAA;;;;;;;;EA0BlD"}
package/dist/proof.js ADDED
@@ -0,0 +1,106 @@
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.getLayerZeroPacket = exports.encodeParams = exports.getReceiptProof = exports.getFeatherProof = void 0;
7
+ const ethers_1 = require("ethers");
8
+ const tiny_invariant_1 = __importDefault(require("tiny-invariant"));
9
+ const constants_1 = require("./constants");
10
+ const v1_1 = require("./mpt/v1");
11
+ const v2_1 = require("./mpt/v2");
12
+ function getFeatherProof(utilsVersion, emitterAddress, packetPayload) {
13
+ switch (utilsVersion) {
14
+ case constants_1.EVMUtilityVersion.V1: {
15
+ const contractAddrByte32 = ethers_1.ethers.utils.hexZeroPad(emitterAddress, 32);
16
+ return {
17
+ proof: ethers_1.ethers.utils.solidityPack(['bytes32', 'bytes'], [contractAddrByte32, packetPayload]),
18
+ };
19
+ }
20
+ case constants_1.EVMUtilityVersion.V2: {
21
+ return {
22
+ proof: packetPayload,
23
+ };
24
+ }
25
+ default:
26
+ throw new Error(`Unknown utility version ${utilsVersion}`);
27
+ }
28
+ }
29
+ exports.getFeatherProof = getFeatherProof;
30
+ async function getReceiptProof(network, block, transactionReceipts, transactionIndex, outboundProofType, utilsVersion) {
31
+ (0, tiny_invariant_1.default)(constants_1.NETWORKS.includes(network), `Unsupported network: ${network}`);
32
+ switch (outboundProofType) {
33
+ case constants_1.OutboundProofType.MPT: {
34
+ switch (utilsVersion) {
35
+ case constants_1.EVMUtilityVersion.V1: {
36
+ return await (0, v1_1.getReceiptProof)(network, block, transactionReceipts, transactionIndex);
37
+ }
38
+ case constants_1.EVMUtilityVersion.V2:
39
+ case constants_1.EVMUtilityVersion.V4: {
40
+ return await (0, v2_1.getReceiptProof)(network, block, transactionReceipts, transactionIndex);
41
+ }
42
+ case constants_1.EVMUtilityVersion.V3: {
43
+ const proof = await (0, v2_1.getReceiptProof)(network, block, transactionReceipts, transactionIndex);
44
+ proof['blockHash'] = block.hash;
45
+ return proof;
46
+ }
47
+ default:
48
+ throw new Error(`Unsupported utility version ${utilsVersion}`);
49
+ }
50
+ }
51
+ default:
52
+ throw new Error(`Unsupported Outbound Proof Type ${outboundProofType}`);
53
+ }
54
+ }
55
+ exports.getReceiptProof = getReceiptProof;
56
+ function encodeParams(proof, outboundProofType, utilsVersion, logIndex, srcEndpointId = undefined) {
57
+ switch (outboundProofType) {
58
+ case constants_1.OutboundProofType.MPT: {
59
+ switch (utilsVersion) {
60
+ case constants_1.EVMUtilityVersion.V1: {
61
+ return ethers_1.ethers.utils.defaultAbiCoder.encode(['uint16', 'bytes[]', 'uint256[]', 'uint256', 'uint256'], [srcEndpointId, proof.proof, proof.pointers, proof.receiptSlotIndex, logIndex]);
62
+ }
63
+ case constants_1.EVMUtilityVersion.V2: {
64
+ return ethers_1.ethers.utils.defaultAbiCoder.encode(['uint16', 'bytes[]', 'uint256[]', 'uint256'], [srcEndpointId, proof.proof, proof.receiptSlotIndex, logIndex]);
65
+ }
66
+ case constants_1.EVMUtilityVersion.V3: {
67
+ return ethers_1.ethers.utils.defaultAbiCoder.encode(['uint16', 'bytes32', 'bytes[]', 'uint256[]', 'uint256'], [srcEndpointId, proof.blockHash, proof.proof, proof.receiptSlotIndex, logIndex]);
68
+ }
69
+ case constants_1.EVMUtilityVersion.V4: {
70
+ return ethers_1.ethers.utils.defaultAbiCoder.encode(['bytes[]', 'uint256[]', 'uint256'], [proof.proof, proof.receiptSlotIndex, logIndex]);
71
+ }
72
+ default:
73
+ throw new Error(`Unsupported utility version ${utilsVersion}`);
74
+ }
75
+ }
76
+ default:
77
+ throw new Error(`Unsupported Outbound Proof Type ${outboundProofType}`);
78
+ }
79
+ }
80
+ exports.encodeParams = encodeParams;
81
+ function getLayerZeroPacket(srcChainId, _log) {
82
+ //todo: what if src address differs from 20 bytes
83
+ const packet = ethers_1.ethers.utils.defaultAbiCoder.decode(['uint16', 'bytes'], _log.data);
84
+ const data = packet[1].slice(2);
85
+ //todo: what if dst address differs from 20 bytes
86
+ const dstChainId = parseInt(packet[0]);
87
+ const nonce = ethers_1.ethers.BigNumber.from('0x' + data.slice(0, 16)).toNumber();
88
+ const srcAddress = '0x' + data.slice(16, 56);
89
+ const dstAddress = '0x' + data.slice(56, 96);
90
+ let payload = '0x';
91
+ if (data.length > 96) {
92
+ //has payload
93
+ payload = '0x' + data.slice(96, data.length);
94
+ }
95
+ return {
96
+ srcChainId,
97
+ dstChainId,
98
+ nonce,
99
+ dstAddress,
100
+ srcAddress,
101
+ ulnAddress: ethers_1.ethers.utils.defaultAbiCoder.encode(['address'], [_log.address]),
102
+ payload,
103
+ };
104
+ }
105
+ exports.getLayerZeroPacket = getLayerZeroPacket;
106
+ //# sourceMappingURL=proof.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proof.js","sourceRoot":"","sources":["../src/proof.ts"],"names":[],"mappings":";;;;;;AAAA,mCAA+B;AAC/B,oEAAsC;AAEtC,2CAA4E;AAC5E,iCAA+D;AAC/D,iCAA+D;AAE/D,SAAgB,eAAe,CAAC,YAAY,EAAE,cAAc,EAAE,aAAa;IACvE,QAAQ,YAAY,EAAE;QAClB,KAAK,6BAAiB,CAAC,EAAE,CAAC,CAAC;YACvB,MAAM,kBAAkB,GAAG,eAAM,CAAC,KAAK,CAAC,UAAU,CAAC,cAAc,EAAE,EAAE,CAAC,CAAA;YACtE,OAAO;gBACH,KAAK,EAAE,eAAM,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,SAAS,EAAE,OAAO,CAAC,EAAE,CAAC,kBAAkB,EAAE,aAAa,CAAC,CAAC;aAC9F,CAAA;SACJ;QACD,KAAK,6BAAiB,CAAC,EAAE,CAAC,CAAC;YACvB,OAAO;gBACH,KAAK,EAAE,aAAa;aACvB,CAAA;SACJ;QACD;YACI,MAAM,IAAI,KAAK,CAAC,2BAA2B,YAAY,EAAE,CAAC,CAAA;KACjE;AACL,CAAC;AAhBD,0CAgBC;AA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ACL,CAAC;AA1BD,gDA0BC"}
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@layerzerolabs/lz-proof-utility",
3
+ "version": "0.0.3",
4
+ "description": "LayerZero Proof Utility",
5
+ "license": "MIT",
6
+ "exports": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "scripts": {
12
+ "build": "$npm_execpath tsc",
13
+ "clean": "$npm_execpath rimraf .turbo && $npm_execpath rimraf dist",
14
+ "format": "$npm_execpath prettier --ignore-path $(git rev-parse --show-toplevel)/.prettierignore --write ",
15
+ "lint": "TIMING=1 $npm_execpath eslint --no-error-on-unmatched-pattern src/**/*.ts --fix"
16
+ },
17
+ "dependencies": {
18
+ "@types/safer-buffer": "^2.1.0",
19
+ "eth-object": "^1.0.3",
20
+ "eth-util-lite": "^1.0.1",
21
+ "ethereumjs-util": "^5.2.0",
22
+ "ethers": "^5.7.2",
23
+ "merkle-patricia-tree": "github:zmitton/merkle-patricia-tree#build",
24
+ "promisfy": "^1.2.0",
25
+ "safer-buffer": "^2.1.2",
26
+ "tiny-invariant": "^1.3.1"
27
+ },
28
+ "devDependencies": {
29
+ "@layerzerolabs/eslint-config": "workspace:^",
30
+ "@layerzerolabs/typescript-config": "workspace:^",
31
+ "eslint": "^8.17.0",
32
+ "rimraf": "^3.0.2",
33
+ "typescript": "^4.9.5"
34
+ }
35
+ }