-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add zod runtime validation for base account (#186)
* feat: add zod runtime validation for base account * feat: add zod runtime validation for base account * feat: add zod runtime validation for simple account * refactor: clean up base schemas * refactor: rebase * refactor: rename abitype import
- Loading branch information
1 parent
1e1883b
commit e9c48ed
Showing
15 changed files
with
179 additions
and
80 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,22 @@ | ||
import { Address } from "abitype/zod"; | ||
import type { Transport } from "viem"; | ||
import z from "zod"; | ||
import { createPublicErc4337ClientSchema } from "../client/schema.js"; | ||
import type { SupportedTransports } from "../client/types"; | ||
import { SignerSchema } from "../signer/schema.js"; | ||
import { ChainSchema } from "../utils/index.js"; | ||
|
||
export const createBaseSmartAccountParamsSchema = < | ||
TTransport extends SupportedTransports = Transport | ||
>() => | ||
z.object({ | ||
rpcClient: z.union([ | ||
z.string(), | ||
createPublicErc4337ClientSchema<TTransport>(), | ||
]), | ||
factoryAddress: Address, | ||
owner: SignerSchema.optional(), | ||
entryPointAddress: Address.optional(), | ||
chain: ChainSchema, | ||
accountAddress: Address.optional(), | ||
}); |
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,17 @@ | ||
import type { Transport } from "viem"; | ||
import { z } from "zod"; | ||
import type { PublicErc4337Client, SupportedTransports } from "./types"; | ||
|
||
export const createPublicErc4337ClientSchema = < | ||
TTransport extends SupportedTransports = Transport | ||
>() => | ||
z.custom<PublicErc4337Client<TTransport>>((provider) => { | ||
return ( | ||
provider != null && | ||
typeof provider === "object" && | ||
"request" in provider && | ||
"type" in provider && | ||
"key" in provider && | ||
"name" in provider | ||
); | ||
}); |
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
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,13 @@ | ||
import { z } from "zod"; | ||
import type { SmartAccountSigner } from "./types"; | ||
|
||
export const SignerSchema = z.custom<SmartAccountSigner>((signer) => { | ||
return ( | ||
signer != null && | ||
typeof signer === "object" && | ||
"signerType" in signer && | ||
"signMessage" in signer && | ||
"signTypedData" in signer && | ||
"getAddress" in signer | ||
); | ||
}); |
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
Oops, something went wrong.