@@ -3,8 +3,10 @@ import "./shim";
33import { createWallet } from "@docknetwork/wallet-sdk-core/lib/wallet" ;
44import { createDataStore } from "@docknetwork/wallet-sdk-data-store-web/lib/index" ;
55import { createCredentialProvider } from "@docknetwork/wallet-sdk-core/lib/credential-provider" ;
6+ import { createVerificationController } from "@docknetwork/wallet-sdk-core/lib/verification-controller" ;
67import { createDIDProvider } from "@docknetwork/wallet-sdk-core/lib/did-provider" ;
78import { setLocalStorageImpl } from "@docknetwork/wallet-sdk-data-store-web/lib/localStorageJSON" ;
9+ import { basicCredential } from './credentials/basic-credential' ;
810
911// Here you can define a JSON-RPC storage implementation
1012// So that all data will be stored in the Flutter App instead of the browser
@@ -94,6 +96,51 @@ const rpcMethods = {
9496 }
9597 } ,
9698
99+ async verifyCredential ( { credentialJson, proofRequestJson } ) {
100+ const credentialProvider = createCredentialProvider ( {
101+ wallet,
102+ } ) ;
103+
104+ let credential = await credentialProvider . getById ( credentialJson . id ) ;
105+
106+ if ( ! credential ) {
107+ credential = await credentialProvider . addCredential ( credentialJson ) ;
108+ }
109+
110+ console . log ( "Credential:" ) ;
111+ console . log ( credential ) ;
112+
113+ const verificationController = createVerificationController ( {
114+ wallet,
115+ } )
116+
117+ await verificationController . start ( {
118+ template : proofRequestJson ,
119+ } ) ;
120+
121+ verificationController . selectedCredentials . set ( credential . id , {
122+ credential : credential ,
123+ attributesToReveal : [ 'credentialSubject.name' ]
124+ } ) ;
125+
126+ const presentation = await verificationController . createPresentation ( ) ;
127+
128+ console . log ( 'Presentation created...' )
129+ // For debugging purposes, we can log the presentation
130+ // Logging a full presentation in production is a bad idea because of potential PII leaking into logs
131+ console . log ( presentation ) ;
132+
133+ const apiResult = await fetch ( proofRequestJson . response_url , {
134+ method : 'POST' ,
135+ headers : {
136+ 'content-type' : 'application/json'
137+ } ,
138+ body : JSON . stringify ( presentation ) ,
139+ } ) . then ( res => res . json ( ) ) ;
140+
141+ return apiResult ;
142+ } ,
143+
97144 async clearData ( { id } ) {
98145 try {
99146 await dataStore . documents . removeAllDocuments ( ) ;
@@ -155,7 +202,23 @@ async function initializeWallet() {
155202 sendMessageToFlutter ( {
156203 body : {
157204 type : "WALLET_INITIALIZED" ,
158- data : { defaultDID, otherData : "testing demo 33" } ,
205+ data : { defaultDID, otherData : "testing demo" } ,
206+ } ,
207+ } ) ;
208+
209+ // Starts a credential verification
210+
211+ const proofRequestJson = await fetch ( 'https://creds-testnet.truvera.io/proof/be02aed0-0eba-42ed-b938-a33c111189ca' ) . then ( res => res . json ( ) ) ;
212+
213+ const verificationResult = await rpcMethods . verifyCredential ( {
214+ credentialJson : basicCredential
215+ proofRequestJson ,
216+ } ) ;
217+
218+ sendMessageToFlutter ( {
219+ body : {
220+ type : "WALLET_INITIALIZED" ,
221+ data : { defaultDID, verificationResult } ,
159222 } ,
160223 } ) ;
161224}
0 commit comments