Skip to content

Commit

Permalink
feat(providers): add optional context record
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcnk committed Oct 27, 2024
1 parent 7b3f3c9 commit 8b829c4
Showing 1 changed file with 31 additions and 28 deletions.
59 changes: 31 additions & 28 deletions packages/providers/src/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,75 +27,78 @@ export const AddChainRequestParams = z
.strict();

// Params
export const AccountsRequestParamsSchema = z
.object({
export const RequestWithContext = z.object({
context: z.record(z.any()).default({}).optional()
}).strict()
export const AccountsRequestParamsSchema = RequestWithContext
.extend({
method: z.literal("mina_accounts"),
})
.strict();
export const RequestAccountsRequestParamsSchema = z
.object({
export const RequestAccountsRequestParamsSchema = RequestWithContext
.extend({
method: z.literal("mina_requestAccounts"),
})
.strict();
export const ChainIdRequestParamsSchema = z
.object({ method: z.literal("mina_chainId") })
export const ChainIdRequestParamsSchema = RequestWithContext
.extend({ method: z.literal("mina_chainId") })
.strict();
export const ChainInformationRequestParamsSchema = z
.object({ method: z.literal("mina_chainInformation") })
export const ChainInformationRequestParamsSchema = RequestWithContext
.extend({ method: z.literal("mina_chainInformation") })
.strict();
export const GetBalanceRequestParamsSchema = z
.object({ method: z.literal("mina_getBalance") })
export const GetBalanceRequestParamsSchema = RequestWithContext
.extend({ method: z.literal("mina_getBalance") })
.strict();
export const SignRequestParamsSchema = z
.object({
export const SignRequestParamsSchema = RequestWithContext
.extend({
method: z.literal("mina_sign"),
params: z.array(z.string()),
})
.strict();
export const SignFieldsRequestParamsSchema = z
.object({
export const SignFieldsRequestParamsSchema = RequestWithContext
.extend({
method: z.literal("mina_signFields"),
params: z.array(z.array(FieldSchema)),
})
.strict();
export const SignTransactionRequestParamsSchema = z
.object({
export const SignTransactionRequestParamsSchema = RequestWithContext
.extend({
method: z.literal("mina_signTransaction"),
params: z.array(z.union([TransactionPayload, ZkAppCommandPayload])),
})
.strict();
export const SendTransactionRequestParamsSchema = z
.object({
export const SendTransactionRequestParamsSchema = RequestWithContext
.extend({
method: z.literal("mina_sendTransaction"),
params: z.array(SignedTransactionSchema),
})
.strict();
export const CreateNullifierRequestParamsSchema = z
.object({
export const CreateNullifierRequestParamsSchema = RequestWithContext
.extend({
method: z.literal("mina_createNullifier"),
params: z.array(z.array(FieldSchema)),
})
.strict();
export const SwitchChainRequestParamsSchema = z
.object({
export const SwitchChainRequestParamsSchema = RequestWithContext
.extend({
method: z.literal("mina_switchChain"),
params: z.array(z.string()),
})
.strict();
export const AddChainRequestParamsSchema = z
.object({
export const AddChainRequestParamsSchema = RequestWithContext
.extend({
method: z.literal("mina_addChain"),
params: z.array(AddChainRequestParams),
})
.strict();
export const SetStateRequestParamsSchema = z
.object({
export const SetStateRequestParamsSchema = RequestWithContext
.extend({
method: z.literal("mina_setState"),
params: z.array(JsonSchema),
})
.strict();
export const GetStateRequestParamsSchema = z
.object({
export const GetStateRequestParamsSchema = RequestWithContext
.extend({
method: z.literal("mina_getState"),
params: z.array(z.string()),
})
Expand Down

0 comments on commit 8b829c4

Please sign in to comment.