-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding zod dto to vault, initial zod-based scheam for Action types
- Loading branch information
1 parent
af6bc5c
commit e467792
Showing
8 changed files
with
111 additions
and
36 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
13 changes: 12 additions & 1 deletion
13
apps/vault/src/vault/http/rest/controller/sign.controller.ts
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 was deleted.
Oops, something went wrong.
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
74 changes: 74 additions & 0 deletions
74
packages/policy-engine-shared/src/lib/schema/action.schema.ts
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,74 @@ | ||
import { z } from 'zod' | ||
import { Action } from '../type/action.type' | ||
import { addressSchema } from './address.schema' | ||
import { hexSchema } from './hex.schema' | ||
|
||
export const AccessListSchema = z.array( | ||
z.object({ | ||
address: addressSchema, | ||
storageKeys: z.array(hexSchema) | ||
}) | ||
) | ||
// export type AccessList = z.infer<typeof AccessList> | ||
|
||
export const ActionSchema = z.nativeEnum(Action) | ||
|
||
export const BaseActionSchema = z.object({ | ||
action: ActionSchema, | ||
nonce: z.string() | ||
}) | ||
// export type BaseActionSchema = z.infer<typeof BaseActionSchema> | ||
|
||
export const TransactionRequestSchema = z.object({ | ||
chainId: z.number(), | ||
from: addressSchema, | ||
nonce: z.number().optional(), | ||
accessList: AccessListSchema.optional(), | ||
data: hexSchema.optional(), | ||
gas: z.coerce.bigint().optional(), | ||
maxFeePerGas: z.coerce.bigint().optional(), | ||
maxPriorityFeePerGas: z.coerce.bigint().optional(), | ||
to: addressSchema.nullable().optional(), | ||
type: z.literal('2').optional(), | ||
value: hexSchema.optional() | ||
}) | ||
// export type TransactionRequest = z.infer<typeof TransactionRequest> | ||
|
||
export const SignTransactionActionSchema = z.intersection( | ||
BaseActionSchema, | ||
z.object({ | ||
action: z.literal(Action.SIGN_TRANSACTION), | ||
resourceId: z.string(), | ||
transactionRequest: TransactionRequestSchema | ||
}) | ||
) | ||
// export type SignTransactionAction = z.infer<typeof SignTransactionAction> | ||
|
||
// Matching viem's SignableMessage options https://viem.sh/docs/actions/wallet/signMessage#message | ||
export const SignableMessageSchema = z.union([ | ||
z.string(), | ||
z.object({ | ||
raw: hexSchema | ||
}) | ||
]) | ||
// export type SignableMessage = z.infer<typeof SignableMessage> | ||
|
||
export const SignMessageActionSchema = z.intersection( | ||
BaseActionSchema, | ||
z.object({ | ||
action: z.literal(Action.SIGN_MESSAGE), | ||
resourceId: z.string(), | ||
message: SignableMessageSchema | ||
}) | ||
) | ||
// export type SignMessageAction = z.infer<typeof SignMessageAction> | ||
|
||
export const SignTypedDataActionSchema = z.intersection( | ||
BaseActionSchema, | ||
z.object({ | ||
action: z.literal(Action.SIGN_TYPED_DATA), | ||
resourceId: z.string(), | ||
typedData: z.string() | ||
}) | ||
) | ||
// export type SignTypedDataAction = z.infer<typeof SignTypedDataAction> |
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