Skip to content

Commit 44bedb6

Browse files
committed
feat(docs): add test for mina_signFieldsWithPassphrase
1 parent c1c90e5 commit 44bedb6

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

apps/docs/src/components/test-zkapp.tsx

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,24 @@ import { sampleCredential, samplePresentationRequest } from "./sample-data";
66

77
const store = createStore();
88

9+
const sampleSignFieldsWithPassphrase = {
10+
fields: [
11+
"15194438335254979123992673494772742932886141479807135737958843785282001151979",
12+
"13058445919007356413345300070030973942059862825965583483176167800381508277987",
13+
"26067489438851605530938171293652363087823200555042082718868551789908955769071",
14+
],
15+
passphrase: "1234",
16+
};
17+
918
export const TestZkApp = () => {
1019
const [currentProvider, setCurrentProvider] = useLocalStorage(
1120
"minajs:provider",
1221
"",
1322
);
1423
const [message, setMessage] = useState("A message to sign");
1524
const [fields, setFields] = useState('["1", "2", "3"]');
25+
const [signFieldsWithPassphraseInput, setSignFieldsWithPassphraseInput] =
26+
useState(JSON.stringify(sampleSignFieldsWithPassphrase, null, 2));
1627
const [credentialInput, setCredentialInput] = useState(
1728
JSON.stringify(sampleCredential, null, 2),
1829
);
@@ -32,6 +43,7 @@ export const TestZkApp = () => {
3243
mina_getBalance: "",
3344
mina_sign: "",
3445
mina_signFields: "",
46+
mina_signFieldsWithPassphrase: "",
3547
mina_signTransaction: "",
3648
mina_switchChain: "",
3749
mina_storePrivateCredential: "",
@@ -125,6 +137,23 @@ export const TestZkApp = () => {
125137
mina_signFields: JSON.stringify(result, undefined, "\t"),
126138
}));
127139
};
140+
const signFieldsWithPassphrase = async () => {
141+
if (!provider) return;
142+
try {
143+
const parsedInput = JSON.parse(signFieldsWithPassphraseInput);
144+
const { result } = await provider.request({
145+
method: "mina_signFieldsWithPassphrase",
146+
params: [parsedInput],
147+
});
148+
setResults(() => ({
149+
mina_signFieldsWithPassphrase: JSON.stringify(result, null, 2),
150+
}));
151+
} catch (error) {
152+
setResults(() => ({
153+
mina_signFieldsWithPassphrase: `Error: ${error.message}`,
154+
}));
155+
}
156+
};
128157
const createNullifier = async () => {
129158
if (!provider) return;
130159
const parsedFields = JSON.parse(fields);
@@ -501,6 +530,37 @@ export const TestZkApp = () => {
501530
</div>
502531
</div>
503532
</section>
533+
<section className="card bg-neutral">
534+
<div className="card-body gap-4">
535+
<h2 className="card-title">Sign Fields With Passphrase</h2>
536+
<p>mina_signFieldsWithPassphrase</p>
537+
<div className="flex flex-col gap-2">
538+
<div className="flex flex-col gap-4">
539+
<textarea
540+
value={signFieldsWithPassphraseInput}
541+
onChange={(event) =>
542+
setSignFieldsWithPassphraseInput(event.target.value)
543+
}
544+
className="textarea textarea-bordered h-48 font-mono text-sm"
545+
placeholder="Enter fields and passphrase JSON..."
546+
/>
547+
<button
548+
type="button"
549+
className="btn btn-primary"
550+
onClick={signFieldsWithPassphrase}
551+
>
552+
Sign Fields With Passphrase
553+
</button>
554+
</div>
555+
<label>Result</label>
556+
<textarea
557+
value={results.mina_signFieldsWithPassphrase}
558+
readOnly
559+
className="textarea textarea-bordered h-24 resize-none font-mono"
560+
/>
561+
</div>
562+
</div>
563+
</section>
504564
</main>
505565
);
506566
};

0 commit comments

Comments
 (0)