Skip to content

Commit

Permalink
Public Operation Data
Browse files Browse the repository at this point in the history
  • Loading branch information
nlordell committed Nov 22, 2023
1 parent 5f05e8b commit 3e4c4a1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion 4337/contracts/Safe4337Module.sol
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ contract Safe4337Module is IAccount, HandlerContext, CompatibilityFallbackHandle
uint256 maxPriorityFeePerGas,
uint96 signatureTimestamps,
address entryPoint
) internal view returns (bytes memory) {
) public view returns (bytes memory) {
bytes32 safeOperationHash = keccak256(
abi.encode(
SAFE_OP_TYPEHASH,
Expand Down
33 changes: 33 additions & 0 deletions 4337/test/eip4337/Safe4337Module.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { getTestSafe, getSafe4337Module, getEntryPoint } from '../utils/setup'
import { buildSignatureBytes, signHash } from '../../src/utils/execution'
import {
buildSafeUserOp,
calculateSafeOperationData,
calculateSafeOperationHash,
buildUserOperationFromSafeUserOperation,
buildSafeUserOpTransaction,
Expand Down Expand Up @@ -36,6 +37,38 @@ describe('Safe4337Module', () => {
}
})

describe('getOperationData', () => {
it('should correctly calculate EIP-712 encoded data of the operation', async () => {
const { validator, safeModule, entryPoint } = await setupTests()

const safeAddress = ethers.hexlify(ethers.randomBytes(20))
const validAfter = Date.now() + 10000
const validUntil = validAfter + 10000000000
const packedSignatureTimestamps = encodeSignatureTimestamp(validUntil, validAfter)

const operation = buildSafeUserOp({
safe: safeAddress,
nonce: '0',
entryPoint: await entryPoint.getAddress(),
signatureTimestamps: packedSignatureTimestamps,
})
const operationData = await safeModule.getOperationData(
safeAddress,
operation.callData,
operation.nonce,
operation.preVerificationGas,
operation.verificationGasLimit,
operation.callGasLimit,
operation.maxFeePerGas,
operation.maxPriorityFeePerGas,
operation.signatureTimestamps,
operation.entryPoint,
)

expect(operationData).to.equal(calculateSafeOperationData(await validator.getAddress(), operation, await chainId()))
})
})

describe('getOperationHash', () => {
it('should correctly calculate EIP-712 hash of the operation', async () => {
const { validator, safeModule, entryPoint } = await setupTests()
Expand Down

0 comments on commit 3e4c4a1

Please sign in to comment.