@layerzerolabs/onesig-evm 0.0.2 → 0.0.4

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.
Files changed (32) hide show
  1. package/contracts/MultiSig.sol +219 -0
  2. package/contracts/OneSig.sol +258 -0
  3. package/contracts/mocks/MockOApp.sol +13 -0
  4. package/dist/index.d.ts +12 -0
  5. package/dist/index.js +54 -0
  6. package/package.json +10 -14
  7. package/typechain-types/@openzeppelin/contracts/index.ts +5 -0
  8. package/typechain-types/@openzeppelin/contracts/utils/cryptography/ECDSA.ts +55 -0
  9. package/typechain-types/@openzeppelin/contracts/utils/cryptography/MerkleProof.ts +55 -0
  10. package/typechain-types/@openzeppelin/contracts/utils/cryptography/index.ts +5 -0
  11. package/typechain-types/@openzeppelin/contracts/utils/index.ts +5 -0
  12. package/typechain-types/@openzeppelin/index.ts +5 -0
  13. package/typechain-types/common.ts +46 -0
  14. package/typechain-types/contracts/MultiSig.ts +358 -0
  15. package/typechain-types/contracts/OneSig.ts +687 -0
  16. package/typechain-types/contracts/index.ts +7 -0
  17. package/typechain-types/contracts/mocks/MockOApp.ts +144 -0
  18. package/typechain-types/contracts/mocks/index.ts +4 -0
  19. package/typechain-types/factories/@openzeppelin/contracts/index.ts +4 -0
  20. package/typechain-types/factories/@openzeppelin/contracts/utils/cryptography/ECDSA__factory.ts +87 -0
  21. package/typechain-types/factories/@openzeppelin/contracts/utils/cryptography/MerkleProof__factory.ts +68 -0
  22. package/typechain-types/factories/@openzeppelin/contracts/utils/cryptography/index.ts +5 -0
  23. package/typechain-types/factories/@openzeppelin/contracts/utils/index.ts +4 -0
  24. package/typechain-types/factories/@openzeppelin/index.ts +4 -0
  25. package/typechain-types/factories/contracts/MultiSig__factory.ts +275 -0
  26. package/typechain-types/factories/contracts/OneSig__factory.ts +653 -0
  27. package/typechain-types/factories/contracts/index.ts +6 -0
  28. package/typechain-types/factories/contracts/mocks/MockOApp__factory.ts +104 -0
  29. package/typechain-types/factories/contracts/mocks/index.ts +4 -0
  30. package/typechain-types/factories/index.ts +5 -0
  31. package/typechain-types/hardhat.d.ts +78 -0
  32. package/typechain-types/index.ts +18 -0
@@ -0,0 +1,219 @@
1
+ // SPDX-License-Identifier: LZBL-1.2
2
+ // TODO confirm the license
3
+
4
+ pragma solidity ^0.8.22;
5
+
6
+ import { ECDSA } from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
7
+ import { EnumerableSet } from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
8
+
9
+ /**
10
+ * @title MultiSig
11
+ * @notice Abstract contract that manages a set of signers and a signature threshold.
12
+ * Designed to be inherited by contracts requiring multi-signature verification.
13
+ * @dev Uses EnumerableSet to store signer addresses and ECDSA for signature recovery.
14
+ */
15
+ abstract contract MultiSig {
16
+ using EnumerableSet for EnumerableSet.AddressSet;
17
+
18
+ /**
19
+ * @dev Set of available signers for the MultiSig.
20
+ */
21
+ EnumerableSet.AddressSet internal signerSet;
22
+
23
+ /**
24
+ * @notice The number of signatures required to execute a transaction.
25
+ */
26
+ uint256 public threshold;
27
+
28
+ /// @notice Error thrown when a signer address is invalid.
29
+ error InvalidSigner();
30
+
31
+ /// @notice Error thrown when a function is not called from this contract itself.
32
+ error OnlyMultiSig();
33
+
34
+ /// @notice Error thrown when the threshold is set to zero.
35
+ error ZeroThreshold();
36
+
37
+ /// @notice Error thrown when the total number of signers is less than the threshold.
38
+ /// @param totalSigners The current number of signers.
39
+ /// @param threshold The required threshold.
40
+ error TotalSignersLessThanThreshold(uint256 totalSigners, uint256 threshold);
41
+
42
+ /// @notice Error thrown when attempting to add a signer who is already active.
43
+ /// @param signer The address of the signer.
44
+ error SignerAlreadyAdded(address signer);
45
+
46
+ /// @notice Error thrown when attempting to remove a signer who is not found.
47
+ /// @param signer The address of the signer.
48
+ error SignerNotFound(address signer);
49
+
50
+ /// @notice Error thrown when there is a signature format error or mismatch in length.
51
+ error SignatureError();
52
+
53
+ /// @notice Error thrown when signers are not sorted in ascending order (prevents duplicates).
54
+ error UnsortedSigners();
55
+
56
+ /**
57
+ * @notice Emitted when a signer's active status is updated.
58
+ * @param signer The address of the signer.
59
+ * @param active True if added, false if removed.
60
+ */
61
+ event SignerSet(address signer, bool active);
62
+
63
+ /**
64
+ * @notice Emitted when the threshold for signatures is set.
65
+ * @param threshold The new threshold.
66
+ */
67
+ event ThresholdSet(uint256 threshold);
68
+
69
+ /**
70
+ * @dev Restricts access to functions so they can only be called via this contract itself.
71
+ */
72
+ modifier onlyMultiSig() {
73
+ if (msg.sender != address(this)) revert OnlyMultiSig();
74
+ _;
75
+ }
76
+
77
+ /**
78
+ * @dev Initializes the MultiSig with a list of signers and sets the signature threshold.
79
+ * @param _signers Array of signer addresses.
80
+ * @param _threshold The initial threshold for signatures.
81
+ */
82
+ constructor(address[] memory _signers, uint256 _threshold) {
83
+ for (uint256 i = 0; i < _signers.length; i++) {
84
+ _addSigner(_signers[i]);
85
+ }
86
+ _setThreshold(_threshold);
87
+ }
88
+
89
+ /**
90
+ * @notice Allows the MultiSig contract to update the signature threshold.
91
+ * @dev This function can only be called by the MultiSig contract itself.
92
+ * @param _threshold The new threshold value.
93
+ */
94
+ function setThreshold(uint256 _threshold) external onlyMultiSig {
95
+ _setThreshold(_threshold);
96
+ }
97
+
98
+ /**
99
+ * @dev Internal function to set the threshold for this MultiSig.
100
+ * - The threshold must be greater than zero.
101
+ * - The threshold must be less than or equal to the number of signers.
102
+ * @param _threshold The new threshold value.
103
+ */
104
+ function _setThreshold(uint256 _threshold) internal {
105
+ if (_threshold == 0) revert ZeroThreshold();
106
+ if (totalSigners() < _threshold) revert TotalSignersLessThanThreshold(totalSigners(), _threshold);
107
+
108
+ threshold = _threshold;
109
+ emit ThresholdSet(_threshold);
110
+ }
111
+
112
+ /**
113
+ * @notice Adds or removes a signer from this MultiSig.
114
+ * @dev Only callable via the MultiSig contract itself.
115
+ * @param _signer The address of the signer to add/remove.
116
+ * @param _active True to add signer, false to remove signer.
117
+ */
118
+ function setSigner(address _signer, bool _active) external onlyMultiSig {
119
+ if (_active) {
120
+ _addSigner(_signer);
121
+ } else {
122
+ _removeSigner(_signer);
123
+ }
124
+ }
125
+
126
+ /**
127
+ * @dev Internal function to add a signer.
128
+ * - `address(0)` is not a valid signer.
129
+ * - A signer cannot be added twice.
130
+ * @param _signer The address of the signer to add.
131
+ */
132
+ function _addSigner(address _signer) internal {
133
+ if (_signer == address(0)) revert InvalidSigner();
134
+ if (!signerSet.add(_signer)) revert SignerAlreadyAdded(_signer);
135
+
136
+ emit SignerSet(_signer, true);
137
+ }
138
+
139
+ /**
140
+ * @dev Internal function to remove a signer.
141
+ * - Signer must be part of the existing set of signers.
142
+ * - The threshold must be less than or equal to the number of remaining signers.
143
+ * @param _signer The address of the signer to remove.
144
+ */
145
+ function _removeSigner(address _signer) internal {
146
+ if (!signerSet.remove(_signer)) revert SignerNotFound(_signer);
147
+ if (totalSigners() < threshold) revert TotalSignersLessThanThreshold(totalSigners(), threshold);
148
+
149
+ emit SignerSet(_signer, false);
150
+ }
151
+
152
+ /**
153
+ * @notice Verifies signatures on a given digest against the threshold.
154
+ * @dev Verifies that exactly `threshold` signatures are present, sorted by ascending signer addresses.
155
+ * @param _digest The message digest (hash) being signed.
156
+ * @param _signatures The concatenated signatures.
157
+ */
158
+ function verifySignatures(bytes32 _digest, bytes calldata _signatures) public view {
159
+ verifyNSignatures(_digest, _signatures, threshold);
160
+ }
161
+
162
+ /**
163
+ * @notice Verifies N signatures on a given digest.
164
+ * @dev Reverts if:
165
+ * - The threshold passed is zero.
166
+ * - The number of signatures doesn't match N (each signature is 65 bytes).
167
+ * - The signers are not strictly increasing (to prevent duplicates).
168
+ * - Any signer is not in the set of authorized signers.
169
+ * @param _digest The message digest (hash) being signed.
170
+ * @param _signatures The concatenated signatures.
171
+ * @param _threshold The required number of valid signatures.
172
+ */
173
+ function verifyNSignatures(bytes32 _digest, bytes calldata _signatures, uint256 _threshold) public view {
174
+ if (_threshold == 0) revert ZeroThreshold();
175
+ // Each signature is 65 bytes (r=32, s=32, v=1).
176
+ if (_signatures.length != _threshold * 65) revert SignatureError();
177
+
178
+ // There cannot be a signer with address 0, so we start with address(0) to ensure ascending order.
179
+ address lastSigner = address(0);
180
+
181
+ for (uint256 i = 0; i < _threshold; i++) {
182
+ // Extract a single signature (65 bytes) at a time.
183
+ bytes calldata signature = _signatures[i * 65:(i + 1) * 65];
184
+ address currentSigner = ECDSA.recover(_digest, signature);
185
+
186
+ // Check ordering to avoid duplicates and ensure strictly increasing addresses.
187
+ if (currentSigner <= lastSigner) revert UnsortedSigners();
188
+ // Check if the signer is in our set.
189
+ if (!isSigner(currentSigner)) revert SignerNotFound(currentSigner);
190
+
191
+ lastSigner = currentSigner;
192
+ }
193
+ }
194
+
195
+ /**
196
+ * @notice Returns the list of all active signers.
197
+ * @return An array of addresses representing the current set of signers.
198
+ */
199
+ function getSigners() public view returns (address[] memory) {
200
+ return signerSet.values();
201
+ }
202
+
203
+ /**
204
+ * @notice Checks if a given address is in the set of signers.
205
+ * @param _signer The address to check.
206
+ * @return True if the address is a signer, otherwise false.
207
+ */
208
+ function isSigner(address _signer) public view returns (bool) {
209
+ return signerSet.contains(_signer);
210
+ }
211
+
212
+ /**
213
+ * @notice Returns the total number of active signers.
214
+ * @return The number of signers currently active.
215
+ */
216
+ function totalSigners() public view returns (uint256) {
217
+ return signerSet.length();
218
+ }
219
+ }
@@ -0,0 +1,258 @@
1
+ // SPDX-License-Identifier: LZBL-1.2
2
+ // TODO confirm the license
3
+
4
+ pragma solidity ^0.8.22;
5
+
6
+ import { MerkleProof } from "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";
7
+ import { MultiSig } from "./MultiSig.sol";
8
+
9
+ /**
10
+ * @title OneSig
11
+ * @author @TRileySchwarz, @Clearwood, @HansonYip, @mok-lz
12
+ * @notice A multi-chain enabled contract that uses a Merkle tree of transaction leaves.
13
+ * It allows transactions to be signed once (off-chain) and then executed on multiple chains,
14
+ * provided the Merkle proof is valid and the threshold of signers is met.
15
+ * @dev Inherits from MultiSig for signature threshold logic.
16
+ */
17
+ contract OneSig is MultiSig {
18
+ /// @notice The version string of the OneSig contract.
19
+ string public constant VERSION = "0.0.1";
20
+
21
+ /**
22
+ * @dev EIP-191 defines the format of the signature prefix.
23
+ * See https://eips.ethereum.org/EIPS/eip-191
24
+ */
25
+ string private constant EIP191_PREFIX_FOR_EIP712 = "\x19\x01";
26
+
27
+ /**
28
+ * @dev EIP-712 domain separator type-hash.
29
+ * See https://eips.ethereum.org/EIPS/eip-712
30
+ */
31
+ bytes32 private constant EIP712DOMAIN_TYPE_HASH =
32
+ keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");
33
+
34
+ /**
35
+ * @dev This domain separator is used to generate a signature hash for the merkle root,
36
+ * specifically using chainId = 1 (Ethereum Mainnet) and verifyingContract = 0xdEaD.
37
+ * This ensures that the same merkle root signatures can be used across different chains
38
+ * because they are all signed with this consistent "fake" domain.
39
+ *
40
+ * In other words, to verify the merkle root with the same signatures on different chains,
41
+ * we use the same chainId (1) and verifyingContract (0xdEaD) in the EIP-712 domain.
42
+ */
43
+ bytes32 private constant DOMAIN_SEPARATOR =
44
+ keccak256(
45
+ abi.encode(
46
+ EIP712DOMAIN_TYPE_HASH,
47
+ keccak256(bytes("OneSig")), // this contract name
48
+ keccak256(bytes("0.0.1")), // version
49
+ 1, // Ethereum mainnet chainId
50
+ address(0xdEaD) // verifyingContract
51
+ )
52
+ );
53
+
54
+ /**
55
+ * @dev The type-hash of the data being signed to authorize a merkle root.
56
+ */
57
+ bytes32 private constant SIGN_MERKLE_ROOT_TYPE_HASH =
58
+ keccak256("SignMerkleRoot(bytes32 seed,bytes32 merkleRoot,uint256 expiry)");
59
+
60
+ /**
61
+ * @notice The chain ID of the contract.
62
+ * @dev Because the chainId is part of the leaf, the same signatures can be used on different chains.
63
+ * Instead of signing a transaction per chain, we can sign a transaction once and execute it on multiple chains.
64
+ */
65
+ uint256 public immutable CHAIN_ID;
66
+
67
+ /**
68
+ * @notice A unique domain value for preventing replay attacks across different OneSig instances.
69
+ * @dev Computed as keccak256(abi.encode(_chainId, address(this))).
70
+ */
71
+ bytes32 private immutable TRANSACTION_DOMAIN;
72
+
73
+ /**
74
+ * @notice A random seed encoded into the signatures/root.
75
+ * @dev Allows for a previously signed, but unexecuted, transaction(s) to be 'revoked' by changing the seed.
76
+ */
77
+ bytes32 public seed;
78
+
79
+ /**
80
+ * @notice A sequential nonce to prevent replay attacks and enforce transaction ordering.
81
+ */
82
+ uint256 public nonce;
83
+
84
+ /// @notice Emitted when the seed is updated.
85
+ event SeedSet(bytes32 seed);
86
+
87
+ /// @notice Emitted when a transaction is executed.
88
+ /// @param merkleRoot The merkle root used to authorize the transaction.
89
+ /// @param nonce The nonce of the transaction.
90
+ event TransactionExecuted(bytes32 merkleRoot, uint256 nonce);
91
+
92
+ /// @notice Error thrown when a merkle proof is invalid or the nonce does not match the expected value.
93
+ error InvalidProofOrNonce();
94
+
95
+ /// @notice Error thrown when a merkle root has expired (past the _expiry timestamp).
96
+ error MerkleRootExpired();
97
+
98
+ /// @notice Error thrown when a call in the transaction array fails.
99
+ /// @param index The index of the failing call within the transaction.
100
+ error ExecutionFailed(uint256 index);
101
+
102
+ /**
103
+ * @notice Call to be executed as part of a Transaction.calls.
104
+ * - OneSig -> [Arbitrary contract].
105
+ * - e.g., setPeer(dstEid, remoteAddress).
106
+ * @param to Address of the contract for this data to be 'called' on.
107
+ * @param value Amount of ether to send with this call.
108
+ * @param data Encoded data to be sent to the contract (calldata).
109
+ */
110
+ struct Call {
111
+ address to;
112
+ uint256 value;
113
+ bytes data;
114
+ }
115
+
116
+ /**
117
+ * @notice Single call to the OneSig contract (address(this)).
118
+ * - EOA -> OneSig
119
+ * - This struct is 1:1 with a 'leaf' in the merkle tree.
120
+ * - Execution of the underlying calls are atomic.
121
+ * - Cannot be processed until the previous leaf (nonce-ordered) has been executed successfully.
122
+ * @param calls List of calls to be made.
123
+ * @param proof Merkle proof to verify the transaction.
124
+ */
125
+ struct Transaction {
126
+ Call[] calls;
127
+ bytes32[] proof;
128
+ }
129
+
130
+ /**
131
+ * @notice Constructor to initialize the OneSig contract.
132
+ * @dev Inherits MultiSig(_signers, _threshold).
133
+ * @param _signers The list of signers authorized to sign transactions.
134
+ * @param _threshold The initial threshold of signers required to execute a transaction.
135
+ * @param _chainId The chain ID of the contract (typically block.chainid).
136
+ * @param _seed The random seed to encode into the signatures/root.
137
+ */
138
+ constructor(
139
+ address[] memory _signers,
140
+ uint256 _threshold,
141
+ uint256 _chainId,
142
+ bytes32 _seed
143
+ ) MultiSig(_signers, _threshold) {
144
+ CHAIN_ID = _chainId;
145
+ TRANSACTION_DOMAIN = keccak256(abi.encode(_chainId, address(this)));
146
+
147
+ seed = _seed;
148
+ emit SeedSet(_seed);
149
+ }
150
+
151
+ /**
152
+ * @notice Sets the contract's seed.
153
+ * @dev Only callable via MultiSig functionality (i.e., requires threshold signatures from signers).
154
+ * @param _seed The new seed value.
155
+ */
156
+ function setSeed(bytes32 _seed) external onlyMultiSig {
157
+ seed = _seed;
158
+ emit SeedSet(_seed);
159
+ }
160
+
161
+ /**
162
+ * @notice Executes a single transaction (which corresponds to a leaf in the merkle tree) if valid signatures are provided.
163
+ * @dev '_transaction' corresponds 1:1 with a leaf. This function can be called by anyone (permissionless),
164
+ * provided the merkle root is verified with sufficient signatures.
165
+ * @param _transaction The transaction data struct, including calls and proof.
166
+ * @param _merkleRoot The merkle root that authorizes this transaction.
167
+ * @param _expiry The timestamp after which the merkle root expires.
168
+ * @param _signatures Signatures from signers that meet the threshold.
169
+ */
170
+ function executeTransaction(
171
+ Transaction calldata _transaction,
172
+ bytes32 _merkleRoot,
173
+ uint256 _expiry,
174
+ bytes calldata _signatures
175
+ ) external payable {
176
+ // Verify the merkle root and signatures
177
+ verifyMerkleRoot(_merkleRoot, _expiry, _signatures);
178
+
179
+ // Verify that this transaction matches the merkle root (using its proof)
180
+ verifyTransactionProof(_merkleRoot, _transaction);
181
+
182
+ // Increment nonce before execution to prevent replay
183
+ uint256 n = nonce++;
184
+
185
+ // Execute all calls atomically
186
+ for (uint256 i = 0; i < _transaction.calls.length; i++) {
187
+ (bool success, ) = _transaction.calls[i].to.call{ value: _transaction.calls[i].value }(
188
+ _transaction.calls[i].data
189
+ );
190
+
191
+ // Revert if the call fails
192
+ if (!success) revert ExecutionFailed(i);
193
+ }
194
+
195
+ emit TransactionExecuted(_merkleRoot, n);
196
+ }
197
+
198
+ /**
199
+ * @notice Validates the signatures on a given merkle root.
200
+ * @dev Reverts if the merkle root is expired or signatures do not meet the threshold.
201
+ * @param _merkleRoot The merkle root to verify.
202
+ * @param _expiry The timestamp after which the merkle root becomes invalid.
203
+ * @param _signatures The provided signatures.
204
+ */
205
+ function verifyMerkleRoot(bytes32 _merkleRoot, uint256 _expiry, bytes calldata _signatures) public view {
206
+ // Check expiry
207
+ if (block.timestamp > _expiry) revert MerkleRootExpired();
208
+
209
+ // Compute the EIP-712 hash
210
+ bytes32 digest = keccak256(
211
+ abi.encodePacked(
212
+ EIP191_PREFIX_FOR_EIP712,
213
+ DOMAIN_SEPARATOR,
214
+ keccak256(abi.encode(SIGN_MERKLE_ROOT_TYPE_HASH, seed, _merkleRoot, _expiry))
215
+ )
216
+ );
217
+
218
+ // Verify the threshold signatures
219
+ verifySignatures(digest, _signatures);
220
+ }
221
+
222
+ /**
223
+ * @notice Verifies that the provided merkle proof matches the current transaction leaf under the merkle root.
224
+ * @dev Reverts if the proof is invalid or the nonce doesn't match the expected value.
225
+ * @param _merkleRoot The merkle root being used.
226
+ * @param _transaction The transaction data containing proof and calls.
227
+ */
228
+ function verifyTransactionProof(bytes32 _merkleRoot, Transaction calldata _transaction) public view {
229
+ bytes32 leaf = encodeLeaf(nonce, _transaction.calls);
230
+ bool valid = MerkleProof.verifyCalldata(_transaction.proof, _merkleRoot, leaf);
231
+ if (!valid) revert InvalidProofOrNonce();
232
+ }
233
+
234
+ /**
235
+ * @notice Encodes the transaction leaf for inclusion in the merkle tree.
236
+ * @dev Includes the chain-specific TRANSACTION_DOMAIN, the current nonce, and the calls array.
237
+ * @param _nonce The nonce of the transaction.
238
+ * @param _calls The calls to be made in this transaction.
239
+ * @return The keccak256 hash of the encoded leaf.
240
+ */
241
+ function encodeLeaf(uint256 _nonce, Call[] calldata _calls) public view returns (bytes32) {
242
+ /**
243
+ * The leaves here are NOT 64 bytes long, so they do not need to be double-encoded.
244
+ *
245
+ * The attack relies on being able to pass the preimage of the intermediate node
246
+ * (e.g., `a = h(l₁) + h(l₂)`, which is 64 bytes) as the leaf. Since this contract
247
+ * does not accept 64-byte leaves, it is impossible to supply a malicious leaf
248
+ * that matches the required format (`h(l₁) + h(l₂)`), thereby preventing the attack.
249
+ */
250
+ return keccak256(abi.encode(TRANSACTION_DOMAIN, _nonce, _calls));
251
+ }
252
+
253
+ /**
254
+ * @notice Fallback function to receive ether.
255
+ * @dev Allows the contract to accept ETH.
256
+ */
257
+ receive() external payable {}
258
+ }
@@ -0,0 +1,13 @@
1
+ // SPDX-License-Identifier: UNLICENSED
2
+ pragma solidity ^0.8.22;
3
+
4
+ // A Mock contract for testing purposes
5
+ contract MockOApp {
6
+ mapping(uint32 => bytes) public bytesMapping;
7
+
8
+ function setBytes(uint32 _dstEid, bytes calldata _bytes) public {
9
+ bytesMapping[_dstEid] = _bytes;
10
+ }
11
+
12
+ receive() external payable {}
13
+ }
@@ -0,0 +1,12 @@
1
+ import { BigNumber } from 'ethers';
2
+ import { BaseLeafData, GenerateLeafsResult } from '@layerzerolabs/onesig-core';
3
+
4
+ interface ETHTransactionCallData {
5
+ to: string;
6
+ value: BigNumber;
7
+ data: string;
8
+ }
9
+ type ETHLeafData = BaseLeafData<string, ETHTransactionCallData>;
10
+ declare function evmLeafGenerator(leafs: ETHLeafData[]): GenerateLeafsResult<ETHLeafData>;
11
+
12
+ export { type ETHLeafData, evmLeafGenerator };
package/dist/index.js ADDED
@@ -0,0 +1,54 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/index.ts
20
+ var src_exports = {};
21
+ __export(src_exports, {
22
+ evmLeafGenerator: () => evmLeafGenerator
23
+ });
24
+ module.exports = __toCommonJS(src_exports);
25
+ var import_ethers = require("ethers");
26
+ function evmLeafGenerator(leafs) {
27
+ return {
28
+ leafs,
29
+ encodeLeaf(tx) {
30
+ return import_ethers.ethers.utils.keccak256(
31
+ import_ethers.ethers.utils.defaultAbiCoder.encode(
32
+ [
33
+ "bytes32",
34
+ // hash(abi.encode(chainId, target), this is the unique key of the world for the leaf
35
+ "uint256",
36
+ // nonce
37
+ "tuple(address to, uint256 value, bytes data)[]"
38
+ // calls array
39
+ ],
40
+ [
41
+ import_ethers.ethers.utils.keccak256(
42
+ import_ethers.ethers.utils.defaultAbiCoder.encode(
43
+ ["uint256", "address"],
44
+ [tx.chainId, tx.targetOneSigAddress]
45
+ )
46
+ ),
47
+ tx.nonce,
48
+ tx.calls
49
+ ]
50
+ )
51
+ );
52
+ }
53
+ };
54
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@layerzerolabs/onesig-evm",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "license": "MIT",
5
5
  "exports": {
6
6
  ".": {
@@ -11,9 +11,11 @@
11
11
  "./package.json": "./package.json"
12
12
  },
13
13
  "files": [
14
+ "contracts/**/*.sol",
14
15
  "artifacts/contracts/**/!(*.dbg).json",
15
16
  "artifacts-zk/contracts/**/!(*.dbg).json",
16
17
  "artifacts-tron/contracts/**/!(*.dbg).json",
18
+ "typechain-types/**/*",
17
19
  "dist/**/*"
18
20
  ],
19
21
  "lint-staged": {
@@ -29,6 +31,10 @@
29
31
  "pnpm solhint --fix --noPrompt"
30
32
  ]
31
33
  },
34
+ "dependencies": {
35
+ "ethers": "^5.7.2",
36
+ "@layerzerolabs/onesig-core": "0.0.4"
37
+ },
32
38
  "devDependencies": {
33
39
  "@babel/core": "^7.23.9",
34
40
  "@ethersproject/abstract-provider": "^5.7.0",
@@ -55,8 +61,6 @@
55
61
  "dotenv": "^16.4.1",
56
62
  "eslint": "^8.55.0",
57
63
  "eslint-plugin-jest-extended": "~2.0.0",
58
- "ethers": "^5.7.2",
59
- "fast-check": "^3.19.0",
60
64
  "hardhat": "~2.19.0",
61
65
  "hardhat-contract-sizer": "^2.10.0",
62
66
  "hardhat-deploy": "^0.12.4",
@@ -64,20 +68,15 @@
64
68
  "husky": "^8.0.3",
65
69
  "keccak256": "^1.0.6",
66
70
  "lint-staged": "^15.2.2",
67
- "merkletreejs": "^0.3.11",
68
71
  "mocha": "^10.2.0",
69
- "p-memoize": "~4.0.4",
70
72
  "prettier": "^3.2.5",
71
73
  "rimraf": "^5.0.5",
72
74
  "solhint": "^5.0.5",
73
75
  "solidity-bytes-utils": "^0.8.2",
74
76
  "solidity-coverage": "^0.8.12",
75
- "ts-node": "^10.9.2",
76
- "tsup": "~8.1.0",
77
77
  "typechain": "^8.3.2",
78
78
  "typescript": "^5.3.3",
79
- "zod": "~3.23.8",
80
- "@layerzerolabs/onesig-core": "0.0.2"
79
+ "zod": "~3.23.8"
81
80
  },
82
81
  "packageManager": "pnpm@8.14.0",
83
82
  "engines": {
@@ -87,8 +86,7 @@
87
86
  "access": "restricted"
88
87
  },
89
88
  "scripts": {
90
- "build": "pnpm forge:build && pnpm hardhat:build && pnpm hardhat:build:tron && pnpm hardhat:build:zk",
91
- "build:test": "pnpm build && pnpm test",
89
+ "build:js": "pnpm tsup",
92
90
  "clean": "pnpm clean:prebuild && rimraf cache out artifacts artifacts-zk artifacts-tron typechain-types",
93
91
  "clean:prebuild": "rimraf dist",
94
92
  "forge:build": "forge build",
@@ -98,10 +96,8 @@
98
96
  "hardhat:build:tron": "pnpm hardhat compile --network tron",
99
97
  "hardhat:build:zk": "pnpm hardhat compile --network zksync",
100
98
  "hardhat:test": "pnpm hardhat test",
101
- "lint": "pnpm run lint:js && pnpm run lint:sol",
102
99
  "lint:fix": "eslint --fix '**/*.{js,ts,json}' && prettier --write . && solhint 'contracts/**/*.sol' --fix --noPrompt",
103
100
  "lint:js": "eslint '**/*.{js,ts,json}' && prettier --check .",
104
- "lint:sol": "solhint 'contracts/**/*.sol'",
105
- "test": "pnpm forge:test && pnpm hardhat:test"
101
+ "lint:sol": "solhint 'contracts/**/*.sol'"
106
102
  }
107
103
  }
@@ -0,0 +1,5 @@
1
+ /* Autogenerated file. Do not edit manually. */
2
+ /* tslint:disable */
3
+ /* eslint-disable */
4
+ import type * as utils from "./utils";
5
+ export type { utils };