Skip to content

Commit 62d3982

Browse files
authored
Merge pull request #44 from docknetwork/sync/heads/master_d9740a33fbb920d8bf474007cdb3de6e80de8e3a
Merge pull request #373 from docknetwork/fix/web-example-version Fix copied web-example version.
2 parents 370d85f + bfdce4e commit 62d3982

3 files changed

Lines changed: 110 additions & 16 deletions

File tree

developer-documentation/wallet-sdk/examples/flutter-webview/src/credentials/basic-credential.js

Lines changed: 46 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

developer-documentation/wallet-sdk/examples/flutter-webview/src/index.js

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ import "./shim";
33
import { createWallet } from "@docknetwork/wallet-sdk-core/lib/wallet";
44
import { createDataStore } from "@docknetwork/wallet-sdk-data-store-web/lib/index";
55
import { createCredentialProvider } from "@docknetwork/wallet-sdk-core/lib/credential-provider";
6+
import { createVerificationController } from "@docknetwork/wallet-sdk-core/lib/verification-controller";
67
import { createDIDProvider } from "@docknetwork/wallet-sdk-core/lib/did-provider";
78
import { 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
}

developer-documentation/wallet-sdk/examples/web-example/src/App.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { setLocalStorageImpl } from "@docknetwork/wallet-sdk-data-store-web/lib/
88
import { edvService } from "@docknetwork/wallet-sdk-wasm/lib/services/edv";
99

1010
import useCloudWallet from './hooks/useCloudWallet';
11-
import ClarityModal from './components/ClarityModal';
1211

1312
setLocalStorageImpl(global.localStorage);
1413

@@ -24,7 +23,6 @@ function App() {
2423
const [selectedCredential, setSelectedCredential] = useState(null);
2524
const [walletKeys, setWalletKeys] = useState(null);
2625
const [uploadError, setUploadError] = useState(null);
27-
const [clarityModalOpen, setClarityModalOpen] = useState(false);
2826

2927
// Styles for the modals
3028
const modalStyle = {
@@ -246,20 +244,7 @@ function App() {
246244
>
247245
Create New Wallet
248246
</Button>
249-
<Button
250-
variant="contained"
251-
onClick={() => setClarityModalOpen(true)}
252-
>
253-
Open Clarity Modal
254-
</Button>
255247
</Box>
256-
<ClarityModal
257-
open={clarityModalOpen}
258-
onClose={() => setClarityModalOpen(false)}
259-
onComplete={() => {
260-
alert("Identity verification successful!");
261-
}}
262-
/>
263248
</div>
264249
);
265250
}

0 commit comments

Comments
 (0)