Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

signTypedData implementation + tests + nexus contracts update #573

Merged
merged 7 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified bun.lockb
Binary file not shown.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
"execa": "^9.3.1",
"get-port": "^7.1.0",
"gh-pages": "^6.1.1",
"nexus": "git@github.com:bcnmy/nexus.git#b8085a3d688afb9149c129a34b4bb9cefb93ae38",
"nexus": "github:bcnmy/nexus#7f8410d6f8037b698b9dd08e6da9008cbd30418a",
"prool": "^0.0.16",
"rimraf": "^5.0.5",
"simple-git-hooks": "^2.9.0",
Expand Down Expand Up @@ -126,4 +126,4 @@
"dependencies": {
"merkletreejs": "^0.3.11"
}
}
}
2 changes: 1 addition & 1 deletion scripts/fetch:deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type FetchDetails = {
}
const {
nexusDeploymentPath = "../node_modules/nexus/deployments",
chainName = "anvil-55000",
chainName = "anvil-51139",
forSrc = ["K1ValidatorFactory", "Nexus", "K1Validator"]
} = yargs(hideBin(process.argv)).argv as unknown as FetchDetails

Expand Down
31 changes: 31 additions & 0 deletions src/__contracts/abi/EIP1271Abi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
export const EIP1271Abi = [
{
type: "function",
name: "eip712Domain",
inputs: [],
outputs: [
{ name: "fields", type: "bytes1", internalType: "bytes1" },
{ name: "name", type: "string", internalType: "string" },
{ name: "version", type: "string", internalType: "string" },
{ name: "chainId", type: "uint256", internalType: "uint256" },
{
name: "verifyingContract",
type: "address",
internalType: "address"
},
{ name: "salt", type: "bytes32", internalType: "bytes32" },
{ name: "extensions", type: "uint256[]", internalType: "uint256[]" }
],
stateMutability: "view"
},
{
type: "function",
name: "isValidSignature",
inputs: [
{ name: "data", type: "bytes32", internalType: "bytes32" },
{ name: "signature", type: "bytes", internalType: "bytes" }
],
outputs: [{ name: "magicValue", type: "bytes4", internalType: "bytes4" }],
stateMutability: "view"
}
] as const
76 changes: 76 additions & 0 deletions src/__contracts/abi/K1ValidatorAbi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
export const K1ValidatorAbi = [
{
inputs: [],
name: "InvalidDataLength",
type: "error"
},
{
inputs: [],
name: "ModuleAlreadyInitialized",
Expand Down Expand Up @@ -86,6 +91,35 @@ export const K1ValidatorAbi = [
stateMutability: "view",
type: "function"
},
{
inputs: [
{
internalType: "address",
name: "",
type: "address"
},
{
internalType: "bytes32",
name: "hash",
type: "bytes32"
},
{
internalType: "bytes",
name: "signature",
type: "bytes"
}
],
name: "isValidSignatureWithSenderLegacy",
outputs: [
{
internalType: "bytes4",
name: "",
type: "bytes4"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [],
name: "name",
Expand Down Expand Up @@ -144,6 +178,19 @@ export const K1ValidatorAbi = [
stateMutability: "view",
type: "function"
},
{
inputs: [],
name: "supportsNestedTypedDataSign",
outputs: [
{
internalType: "bytes32",
name: "result",
type: "bytes32"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
{
Expand All @@ -157,6 +204,35 @@ export const K1ValidatorAbi = [
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [
{
internalType: "bytes32",
name: "hash",
type: "bytes32"
},
{
internalType: "bytes",
name: "sig",
type: "bytes"
},
{
internalType: "bytes",
name: "data",
type: "bytes"
}
],
name: "validateSignatureWithData",
outputs: [
{
internalType: "bool",
name: "validSig",
type: "bool"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
{
Expand Down
67 changes: 64 additions & 3 deletions src/__contracts/abi/NexusAbi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ export const NexusAbi = [
name: "CanNotRemoveLastValidator",
type: "error"
},
{
inputs: [],
name: "EmergencyTimeLockNotExpired",
type: "error"
},
{
inputs: [],
name: "EnableModeSigError",
Expand Down Expand Up @@ -309,6 +314,25 @@ export const NexusAbi = [
name: "ERC7484RegistryConfigured",
type: "event"
},
{
anonymous: false,
inputs: [
{
indexed: false,
internalType: "address",
name: "hook",
type: "address"
},
{
indexed: false,
internalType: "uint256",
name: "timestamp",
type: "uint256"
}
],
name: "EmergencyHookUninstallRequest",
type: "event"
},
{
anonymous: false,
inputs: [
Expand Down Expand Up @@ -544,6 +568,24 @@ export const NexusAbi = [
stateMutability: "view",
type: "function"
},
{
inputs: [
{
internalType: "address",
name: "hook",
type: "address"
},
{
internalType: "bytes",
name: "deInitData",
type: "bytes"
}
],
name: "emergencyUninstallHook",
outputs: [],
stateMutability: "payable",
type: "function"
},
{
inputs: [],
name: "entryPoint",
Expand Down Expand Up @@ -878,7 +920,7 @@ export const NexusAbi = [
},
{
internalType: "bytes",
name: "data",
name: "signature",
type: "bytes"
}
],
Expand Down Expand Up @@ -1005,11 +1047,30 @@ export const NexusAbi = [
outputs: [
{
internalType: "bytes32",
name: "result",
name: "",
type: "bytes32"
}
],
stateMutability: "pure",
stateMutability: "view",
type: "function"
},
{
inputs: [
{
internalType: "address",
name: "validator",
type: "address"
}
],
name: "supportsNestedTypedDataSignWithValidator",
outputs: [
{
internalType: "bytes32",
name: "",
type: "bytes32"
}
],
stateMutability: "view",
type: "function"
},
{
Expand Down
6 changes: 3 additions & 3 deletions src/__contracts/addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import type { Hex } from "viem"
export const addresses: Record<string, Hex> = {
Nexus: "0x776d63154D2aa9256D72C420416c930F3B735464",
K1Validator: "0xd98238BBAeA4f91683d250003799EAd31d7F5c55",
K1ValidatorFactory: "0x8025afaD10209b8bEF3A3C94684AaE4D309c9996",
Nexus: "0x21f4C007C9f091B93B7C1C6911E13ACcd3DAd403",
K1Validator: "0x6854688d3D9A87a33Addd5f4deB5cea1B97fa5b7",
K1ValidatorFactory: "0x976869CF9c5Dd5046b41963EF1bBcE62b5366869",
UniActionPolicy: "0x28120dC008C36d95DE5fa0603526f219c1Ba80f6"
} as const
export default addresses
11 changes: 3 additions & 8 deletions src/account/BaseSmartContractAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import type {
BaseSmartContractAccountProps,
BatchUserOperationCallData,
ISmartContractAccount,
SignTypedDataParams,
Transaction
} from "./utils/Types.js"
import { wrapSignatureWith6492 } from "./utils/Utils.js"
Expand Down Expand Up @@ -130,9 +129,7 @@ export abstract class BaseSmartContractAccount<
*
* @param _params -- Typed Data params to sign
*/
async signTypedData(_params: SignTypedDataParams): Promise<`0x${string}`> {
throw new Error("signTypedData not supported")
}
abstract signTypedData(typedData: any): Promise<`0x${string}`>

/**
* This method should wrap the result of `signMessage` as per
Expand All @@ -156,12 +153,10 @@ export abstract class BaseSmartContractAccount<
*
* @param params -- Typed Data params to sign
*/
async signTypedDataWith6492(
params: SignTypedDataParams
): Promise<`0x${string}`> {
async signTypedDataWith6492(typedData: any): Promise<`0x${string}`> {
const [isDeployed, signature] = await Promise.all([
this.isAccountDeployed(),
this.signTypedData(params)
this.signTypedData(typedData)
])

return this.create6492Signature(isDeployed, signature)
Expand Down
Loading