Skip to content

Commit c969a7c

Browse files
committed
trying to generate EIP712 signatures
1 parent a47f873 commit c969a7c

File tree

5 files changed

+729
-23
lines changed

5 files changed

+729
-23
lines changed

foundry.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ src = "src"
33
out = "out"
44
libs = ["lib"]
55
remappings=["@openzeppelin/contracts=lib/openzeppelin-contracts/contracts"]
6+
gas_reports = ["*"]
67
# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options

script/SendPackedUserOp.s.sol

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ contract SendPackedUserOp is Script {
1313

1414
function run() public {}
1515

16-
function generateSignedUserOperation(bytes memory callData, HelperConfig.NetworkConfig memory config,address minimalAccount)
17-
public
18-
view
19-
returns (PackedUserOperation memory, bytes32)
20-
{
16+
function generateSignedUserOperation(
17+
bytes memory callData,
18+
HelperConfig.NetworkConfig memory config,
19+
address minimalAccount
20+
) public view returns (PackedUserOperation memory, bytes32) {
2121
// 1 . Generate the unsigned data
2222
// uint256 nonce = vm.getNonce(config.account);
2323
// uint256 nonce = vm.getNonce(minimalAccount);
24-
uint256 nonce = vm.getNonce(minimalAccount)-1;
24+
uint256 nonce = vm.getNonce(minimalAccount) - 1;
2525
// PackedUserOperation memory userOp = _generateUnsignedUserOperation(callData, config.account, nonce);
2626
PackedUserOperation memory userOp = _generateUnsignedUserOperation(callData, minimalAccount, nonce);
2727
// 2. Get the userOpHash
@@ -36,7 +36,7 @@ contract SendPackedUserOp is Script {
3636
uint256 ANVIL_DEFAULT_KEY = 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80;
3737
if (block.chainid == 31337) {
3838
(v, r, s) = vm.sign(ANVIL_DEFAULT_KEY, digest); // here the issue will come because the foundry is yet to add wallet instead of pvt key support
39-
// userOp.signature = abi.encodePacked(r, s, v); // 65 bytes in length
39+
// userOp.signature = abi.encodePacked(r, s, v); // 65 bytes in length
4040
} else {
4141
// 3. Sign it and return it
4242
(v, r, s) = vm.sign(config.account, digest);

script/createVoucher.s.sol

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// SPDX-License-Identifier: SEE LICENSE IN LICENSE
2+
pragma solidity ^0.8.28;
3+
4+
import {Script, console2} from "forge-std/Script.sol";
5+
import {EIP712} from "lib/openzeppelin-contracts/contracts/utils/cryptography/EIP712.sol";
6+
import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
7+
8+
abstract contract CodeConstants is Script{
9+
string constant DOMAIN = "moshpit";
10+
string constant VERSION = "1";
11+
12+
struct NFTVoucher {
13+
uint256 tokenId;
14+
uint256 price;
15+
uint256 quantity;
16+
uint256 buyerQty;
17+
uint256 start;
18+
uint256 end;
19+
uint96 royalty;
20+
bool isStealth;
21+
bool isSbt;
22+
bytes creator; // signature 1
23+
bytes validator; // signature 2
24+
}
25+
26+
address user1 = makeAddr("user1");
27+
address user2 = makeAddr("user2");
28+
address user3 = makeAddr("user3");
29+
}
30+
31+
contract creationsVoucher is Script, CodeConstants {
32+
33+
function generateVoucher(uint256 collectionIndex,uint256 tokenIndex,uint256 price,uint256 quantity,uint256 buyerQty,uint256 start,uint256 end,uint96 royalty,bool isStealth,bool isSbt,address creator) public pure returns(NFTVoucher memory nftVoucher){
34+
uint256 tkID = generateTokenId(creator,collectionIndex,tokenIndex,quantity);
35+
nftVoucher = NFTVoucher({
36+
tokenId:tkID,
37+
price:price,
38+
quantity:quantity,
39+
buyerQty:buyerQty,
40+
start:start,
41+
end:end,
42+
royalty:royalty,
43+
isStealth:isStealth,
44+
isSbt:isSbt,
45+
creator: hex"",
46+
validator:hex""
47+
});
48+
}
49+
50+
function generateTokenId(address creator,uint256 collectionIndex,uint256 tokenIndex,uint256 tokenQty) internal pure returns(uint256){
51+
52+
// uint256 collectionIndexSize = 10; // in hex
53+
// uint256 tokenIndexSize = 10;
54+
// uint256 tokenQtySize = 4;
55+
56+
// one hex = 4 bits
57+
// total bits = 10*4 + 10*4 + 4*4 = 40+40+16 = 80+16 = 96 bits
58+
// with address = 160 + 96 = 256
59+
60+
uint256 tokenId = uint256(uint160(creator));
61+
tokenId = (tokenId << 40) + collectionIndex;
62+
tokenId = (tokenId << 40) + tokenIndex;
63+
tokenId = (tokenId << 16) + tokenQty;
64+
65+
return tokenId;
66+
67+
}
68+
69+
function generateEIP712SignedVoucher(NFTVoucher memory voucher) public returns (NFTVoucher memory,bytes32 voucherHash) {
70+
// STEP 1 : Generate a EIP712 compliant voucher hash.
71+
// STEP 2 : Generate a Signature from the creator.
72+
// STEP 3 : Generate a Signature from the Admin
73+
74+
// For step on Import the EIP712 sol
75+
76+
}
77+
}

0 commit comments

Comments
 (0)