@@ -2,39 +2,10 @@ 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 { sampleCredential , samplePresentationRequest } from "./sample-data" ;
5
6
6
7
const store = createStore ( ) ;
7
8
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
- } ,
36
- } ;
37
-
38
9
export const TestZkApp = ( ) => {
39
10
const [ currentProvider , setCurrentProvider ] = useLocalStorage (
40
11
"minajs:provider" ,
@@ -45,6 +16,9 @@ export const TestZkApp = () => {
45
16
const [ credentialInput , setCredentialInput ] = useState (
46
17
JSON . stringify ( sampleCredential , null , 2 ) ,
47
18
) ;
19
+ const [ presentationRequest , setPresentationRequest ] = useState (
20
+ JSON . stringify ( samplePresentationRequest , null , 2 ) ,
21
+ ) ;
48
22
const [ transactionBody , setTransactionBody ] = useObjectState ( {
49
23
to : "B62qnVUL6A53E4ZaGd3qbTr6RCtEZYTu3kTijVrrquNpPo4d3MuJ3nb" ,
50
24
amount : "3000000000" ,
@@ -61,6 +35,7 @@ export const TestZkApp = () => {
61
35
mina_signTransaction : "" ,
62
36
mina_switchChain : "" ,
63
37
mina_storePrivateCredential : "" ,
38
+ mina_requestPresentation : "" ,
64
39
} ) ;
65
40
const providers = useSyncExternalStore ( store . subscribe , store . getProviders ) ;
66
41
const provider = providers . find (
@@ -85,6 +60,24 @@ export const TestZkApp = () => {
85
60
}
86
61
} ;
87
62
63
+ const requestPresentation = async ( ) => {
64
+ if ( ! provider ) return ;
65
+ try {
66
+ const parsedRequest = JSON . parse ( presentationRequest ) ;
67
+ const { result } = await provider . request ( {
68
+ method : "mina_requestPresentation" ,
69
+ params : [ parsedRequest ] ,
70
+ } ) ;
71
+ setResults ( ( ) => ( {
72
+ mina_requestPresentation : JSON . stringify ( result , null , 2 ) ,
73
+ } ) ) ;
74
+ } catch ( error ) {
75
+ setResults ( ( ) => ( {
76
+ mina_requestPresentation : `Error: ${ error . message } ` ,
77
+ } ) ) ;
78
+ }
79
+ } ;
80
+
88
81
const fetchAccounts = async ( ) => {
89
82
if ( ! provider ) return ;
90
83
const { result } = await provider . request ( {
@@ -479,6 +472,35 @@ export const TestZkApp = () => {
479
472
</ div >
480
473
</ div >
481
474
</ section >
475
+ < section className = "card bg-neutral" >
476
+ < div className = "card-body gap-4" >
477
+ < h2 className = "card-title" > Request Presentation</ h2 >
478
+ < p > mina_requestPresentation</ p >
479
+ < div className = "flex flex-col gap-2" >
480
+ < div className = "flex flex-col gap-4" >
481
+ < textarea
482
+ value = { presentationRequest }
483
+ onChange = { ( event ) => setPresentationRequest ( event . target . value ) }
484
+ className = "textarea textarea-bordered h-48 font-mono text-sm"
485
+ placeholder = "Enter presentation request JSON..."
486
+ />
487
+ < button
488
+ type = "button"
489
+ className = "btn btn-primary"
490
+ onClick = { requestPresentation }
491
+ >
492
+ Request Presentation
493
+ </ button >
494
+ </ div >
495
+ < label > Result</ label >
496
+ < textarea
497
+ value = { results . mina_requestPresentation }
498
+ readOnly
499
+ className = "textarea textarea-bordered h-24 resize-none font-mono"
500
+ />
501
+ </ div >
502
+ </ div >
503
+ </ section >
482
504
</ main >
483
505
) ;
484
506
} ;
0 commit comments