Skip to content

Commit

Permalink
feat(providers): validation for mina_signFieldsWithPassphrase
Browse files Browse the repository at this point in the history
  • Loading branch information
martonmoro committed Nov 18, 2024
1 parent 188a048 commit 9ce9c53
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions apps/docs/src/components/test-zkapp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createStore } from "@mina-js/connect";
import { useLocalStorage, useObjectState } from "@uidotdev/usehooks";
import { clsx } from "clsx";
import { useState, useSyncExternalStore } from "react";
import { sampleCredential1, samplePresentationRequest } from "./sample-data";
import { sampleCredential, samplePresentationRequest } from "./sample-data";

const store = createStore();

Expand All @@ -14,7 +14,7 @@ export const TestZkApp = () => {
const [message, setMessage] = useState("A message to sign");
const [fields, setFields] = useState('["1", "2", "3"]');
const [credentialInput, setCredentialInput] = useState(
JSON.stringify(sampleCredential1, null, 2),
JSON.stringify(sampleCredential, null, 2),
);
const [presentationRequest, setPresentationRequest] = useState(
JSON.stringify(samplePresentationRequest, null, 2),
Expand Down
11 changes: 11 additions & 0 deletions packages/providers/src/validation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
FieldSchema,
FieldsAndPassphraseSchema,
JsonSchema,
NetworkId,
NullifierSchema,
Expand Down Expand Up @@ -59,6 +60,10 @@ export const SignFieldsRequestParamsSchema = RequestWithContext.extend({
method: z.literal("mina_signFields"),
params: z.array(z.array(FieldSchema)),
}).strict();
export const signFieldsWithPassphraseParamsSchema = RequestWithContext.extend({
method: z.literal("mina_signFieldsWithPassphrase"),
params: z.array(FieldsAndPassphraseSchema),
});
export const SignTransactionRequestParamsSchema = RequestWithContext.extend({
method: z.literal("mina_signTransaction"),
params: z.array(z.union([TransactionPayloadSchema, ZkAppCommandPayload])),
Expand Down Expand Up @@ -140,6 +145,10 @@ export const SignFieldsRequestReturnSchema = z
result: SignedFieldsSchema,
})
.strict();
export const signFieldsWithPassphraseRequestReturnSchema = z.object({
method: z.literal("mina_signFieldsWithPassphrase"),
result: SignedFieldsSchema,
});
export const SignTransactionRequestReturnSchema = z
.object({
method: z.literal("mina_signTransaction"),
Expand Down Expand Up @@ -212,6 +221,7 @@ export const RpcReturnTypesUnion = z.discriminatedUnion("method", [
GetStateRequestReturnSchema,
StorePrivateCredentialReturnSchema,
PresentationRequestReturnSchema,
signFieldsWithPassphraseRequestReturnSchema,
]);

export const ProviderRequestParamsUnion = z.discriminatedUnion("method", [
Expand All @@ -231,6 +241,7 @@ export const ProviderRequestParamsUnion = z.discriminatedUnion("method", [
GetStateRequestParamsSchema,
StorePrivateCredentialRequestParamsSchema,
PresentationRequestParamsSchema,
signFieldsWithPassphraseParamsSchema,
]);
export type RpcReturnTypesUnionType = z.infer<typeof RpcReturnTypesUnion>;
export type ResultType<M extends string> = {
Expand Down
7 changes: 7 additions & 0 deletions packages/utils/src/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ export const ZkAppCommandPayload = z
})
.strict();

export const FieldsAndPassphraseSchema = z
.object({
fields: z.array(FieldSchema),
passphrase: z.string(),
})
.strict();

/**
* Return type schemas
*/
Expand Down

0 comments on commit 9ce9c53

Please sign in to comment.