@@ -2,37 +2,16 @@ import { createStore } from "@mina-js/connect";
2
2
import { useLocalStorage , useObjectState } from "@uidotdev/usehooks" ;
3
3
import { clsx } from "clsx" ;
4
4
import { useState , useSyncExternalStore } from "react" ;
5
+ import {
6
+ sampleCredentialRecursiveUpdated ,
7
+ samplePresentationRequestHttpsFromExampleUpdated ,
8
+ } from "./sample-data" ;
5
9
6
10
const store = createStore ( ) ;
7
11
8
- const sampleCredential = {
9
- version : "v0" ,
10
- witness : {
11
- type : "simple" ,
12
- issuer : {
13
- _type : "PublicKey" ,
14
- value : "B62qqMxueXzenrchT5CKC5eCSmfcbHic9wJd9GEdHVcd9uCWrjPJjHS" ,
15
- } ,
16
- issuerSignature : {
17
- _type : "Signature" ,
18
- value : {
19
- r : "27355434072539307953235904941558417174103383443074165997458891331674091021280" ,
20
- s : "22156398191479529717864137276005168653180340733374387165875910835098679659803" ,
21
- } ,
22
- } ,
23
- } ,
24
- credential : {
25
- owner : {
26
- _type : "PublicKey" ,
27
- value : "B62qqCMx9YvvjhMFVcRXBqHtAbjWWUhyA9HmgpYCehLHTGKgXsxiZpz" ,
28
- } ,
29
- data : {
30
- age : {
31
- _type : "Field" ,
32
- value : "25" ,
33
- } ,
34
- } ,
35
- } ,
12
+ const sampleSignFieldsWithPassphrase = {
13
+ fields : [ "1" , "2" , "3" ] ,
14
+ passphrase : "1234" ,
36
15
} ;
37
16
38
17
export const TestZkApp = ( ) => {
@@ -42,8 +21,13 @@ export const TestZkApp = () => {
42
21
) ;
43
22
const [ message , setMessage ] = useState ( "A message to sign" ) ;
44
23
const [ fields , setFields ] = useState ( '["1", "2", "3"]' ) ;
24
+ const [ signFieldsWithPassphraseInput , setSignFieldsWithPassphraseInput ] =
25
+ useState ( JSON . stringify ( sampleSignFieldsWithPassphrase , null , 2 ) ) ;
45
26
const [ credentialInput , setCredentialInput ] = useState (
46
- JSON . stringify ( sampleCredential , null , 2 ) ,
27
+ JSON . stringify ( sampleCredentialRecursiveUpdated , null , 2 ) ,
28
+ ) ;
29
+ const [ presentationRequest , setPresentationRequest ] = useState (
30
+ JSON . stringify ( samplePresentationRequestHttpsFromExampleUpdated , null , 2 ) ,
47
31
) ;
48
32
const [ transactionBody , setTransactionBody ] = useObjectState ( {
49
33
to : "B62qnVUL6A53E4ZaGd3qbTr6RCtEZYTu3kTijVrrquNpPo4d3MuJ3nb" ,
@@ -58,9 +42,11 @@ export const TestZkApp = () => {
58
42
mina_getBalance : "" ,
59
43
mina_sign : "" ,
60
44
mina_signFields : "" ,
45
+ mina_signFieldsWithPassphrase : "" ,
61
46
mina_signTransaction : "" ,
62
47
mina_switchChain : "" ,
63
48
mina_storePrivateCredential : "" ,
49
+ mina_requestPresentation : "" ,
64
50
} ) ;
65
51
const providers = useSyncExternalStore ( store . subscribe , store . getProviders ) ;
66
52
const provider = providers . find (
@@ -85,6 +71,24 @@ export const TestZkApp = () => {
85
71
}
86
72
} ;
87
73
74
+ const requestPresentation = async ( ) => {
75
+ if ( ! provider ) return ;
76
+ try {
77
+ const parsedRequest = JSON . parse ( presentationRequest ) ;
78
+ const { result } = await provider . request ( {
79
+ method : "mina_requestPresentation" ,
80
+ params : [ parsedRequest ] ,
81
+ } ) ;
82
+ setResults ( ( ) => ( {
83
+ mina_requestPresentation : result ,
84
+ } ) ) ;
85
+ } catch ( error ) {
86
+ setResults ( ( ) => ( {
87
+ mina_requestPresentation : `Error: ${ error . message } ` ,
88
+ } ) ) ;
89
+ }
90
+ } ;
91
+
88
92
const fetchAccounts = async ( ) => {
89
93
if ( ! provider ) return ;
90
94
const { result } = await provider . request ( {
@@ -132,6 +136,23 @@ export const TestZkApp = () => {
132
136
mina_signFields : JSON . stringify ( result , undefined , "\t" ) ,
133
137
} ) ) ;
134
138
} ;
139
+ const signFieldsWithPassphrase = async ( ) => {
140
+ if ( ! provider ) return ;
141
+ try {
142
+ const parsedInput = JSON . parse ( signFieldsWithPassphraseInput ) ;
143
+ const { result } = await provider . request ( {
144
+ method : "mina_signFieldsWithPassphrase" ,
145
+ params : [ parsedInput ] ,
146
+ } ) ;
147
+ setResults ( ( ) => ( {
148
+ mina_signFieldsWithPassphrase : JSON . stringify ( result , null , 2 ) ,
149
+ } ) ) ;
150
+ } catch ( error ) {
151
+ setResults ( ( ) => ( {
152
+ mina_signFieldsWithPassphrase : `Error: ${ error . message } ` ,
153
+ } ) ) ;
154
+ }
155
+ } ;
135
156
const createNullifier = async ( ) => {
136
157
if ( ! provider ) return ;
137
158
const parsedFields = JSON . parse ( fields ) ;
@@ -479,6 +500,66 @@ export const TestZkApp = () => {
479
500
</ div >
480
501
</ div >
481
502
</ section >
503
+ < section className = "card bg-neutral" >
504
+ < div className = "card-body gap-4" >
505
+ < h2 className = "card-title" > Request Presentation</ h2 >
506
+ < p > mina_requestPresentation</ p >
507
+ < div className = "flex flex-col gap-2" >
508
+ < div className = "flex flex-col gap-4" >
509
+ < textarea
510
+ value = { presentationRequest }
511
+ onChange = { ( event ) => setPresentationRequest ( event . target . value ) }
512
+ className = "textarea textarea-bordered h-48 font-mono text-sm"
513
+ placeholder = "Enter presentation request JSON..."
514
+ />
515
+ < button
516
+ type = "button"
517
+ className = "btn btn-primary"
518
+ onClick = { requestPresentation }
519
+ >
520
+ Request Presentation
521
+ </ button >
522
+ </ div >
523
+ < label > Result</ label >
524
+ < textarea
525
+ value = { results . mina_requestPresentation }
526
+ readOnly
527
+ className = "textarea textarea-bordered h-24 resize-none font-mono"
528
+ />
529
+ </ div >
530
+ </ div >
531
+ </ section >
532
+ < section className = "card bg-neutral" >
533
+ < div className = "card-body gap-4" >
534
+ < h2 className = "card-title" > Sign Fields With Passphrase</ h2 >
535
+ < p > mina_signFieldsWithPassphrase</ p >
536
+ < div className = "flex flex-col gap-2" >
537
+ < div className = "flex flex-col gap-4" >
538
+ < textarea
539
+ value = { signFieldsWithPassphraseInput }
540
+ onChange = { ( event ) =>
541
+ setSignFieldsWithPassphraseInput ( event . target . value )
542
+ }
543
+ className = "textarea textarea-bordered h-48 font-mono text-sm"
544
+ placeholder = "Enter fields and passphrase JSON..."
545
+ />
546
+ < button
547
+ type = "button"
548
+ className = "btn btn-primary"
549
+ onClick = { signFieldsWithPassphrase }
550
+ >
551
+ Sign Fields With Passphrase
552
+ </ button >
553
+ </ div >
554
+ < label > Result</ label >
555
+ < textarea
556
+ value = { results . mina_signFieldsWithPassphrase }
557
+ readOnly
558
+ className = "textarea textarea-bordered h-24 resize-none font-mono"
559
+ />
560
+ </ div >
561
+ </ div >
562
+ </ section >
482
563
</ main >
483
564
) ;
484
565
} ;
0 commit comments