generated from Kwenta/foundry-scaffold
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
π·π»ββοΈ Test ValidateSessionUserOp
- Loading branch information
1 parent
7c7731e
commit 00f862b
Showing
3 changed files
with
202 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
pragma solidity 0.8.18; | ||
|
||
import { | ||
UserOperation, | ||
UserOperationLib | ||
} from "src/biconomy/interfaces/UserOperation.sol"; | ||
import {ECDSA} from "src/openzeppelin/ECDSA.sol"; | ||
import {Vm} from "lib/forge-std/src/Vm.sol"; | ||
|
||
contract UserOperationSignature { | ||
using ECDSA for bytes32; | ||
using UserOperationLib for UserOperation; | ||
|
||
Vm private constant vm = | ||
Vm(address(uint160(uint256(keccak256("hevm cheat code"))))); | ||
|
||
function getUserOperationSignature( | ||
UserOperation calldata op, | ||
uint256 privateKey | ||
) public returns (bytes memory sig) { | ||
bytes32 hash = hashUserOperation(op).toEthSignedMessageHash(); | ||
|
||
(uint8 v, bytes32 r, bytes32 s) = vm.sign(privateKey, hash); | ||
|
||
return bytes.concat(r, s, bytes1(v)); | ||
} | ||
|
||
function hashUserOperation(UserOperation calldata op) | ||
public | ||
pure | ||
returns (bytes32) | ||
{ | ||
return op.hash(); | ||
} | ||
} |