Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 60 additions & 39 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -206,36 +206,41 @@ <h3>
&lt;button&gt;Verify Identity&lt;/button&gt;
&lt;script&gt;
const button = document.querySelector("button");
button.addEventListener("click", async () =&gt; {
try {
const credential = await navigator.credentials.get({
digital: {
requests: [{
protocol: "example-protocol",
data: { /* request data */ }
}]
button.addEventListener("click", async () => {
// Check for DC API and protocol support
if (window.DigitalCredential && DigitalCredential.userAgentAllowsProtocol('example-protocol')) {
try {
const credential = await navigator.credentials.get({
digital: {
requests: [{
protocol: "example-protocol",
data: { /* request data */ }
}]
}
});

// Post it back to the verifier server for decryption and verification
const response = await fetch("/verify-credential", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(credential, null, 2)
});

// Check response
if (!response.ok) {
throw new Error("Failed to verify credential");
}
});

// Post it back to the server for decryption and verification
const response = await fetch("/verify-credential", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(credential, null, 2)
});

// Check response
if (!response.ok) {
throw new Error("Failed to verify credential");

// Render the verification result
displayVerificationResult(await response.json());

} catch (error) {
console.error("Error requesting digital credential:", error);
}

// Render the verification result
displayVerificationResult(await response.json());

} catch (error) {
console.error("Error requesting digital credential:", error);
} else {
// DC API not supported. Fall back to a different verification method.
}
});
&lt;/script&gt;
Expand Down Expand Up @@ -263,17 +268,22 @@ <h3>
&lt;script&gt;
const button = document.querySelector("button");
button.addEventListener("click", async () =&gt; {
try {
const credential = await navigator.credentials.create({
digital: {
requests: [{
protocol: "example-issuance-protocol",
data: { /* issuance request data */ }
}]
}
});
} catch (error) {
console.error("Error issuing digital credential:", error);
// Check for DC API and protocol support
if (window.DigitalCredential && DigitalCredential.userAgentAllowsProtocol('example-issuance-protocol')) {
try {
const credential = await navigator.credentials.create({
digital: {
requests: [{
protocol: "example-issuance-protocol",
data: { /* issuance request data */ }
}]
}
});
} catch (error) {
console.error("Error issuing digital credential:", error);
}
} else {
// DC API not supported. Fall back to a different issuance method.
}
});
&lt;/script&gt;
Expand Down Expand Up @@ -739,6 +749,17 @@ <h4>
`false`.
</li>
</ol>
<p id="protocol-allowed-examples">
<pre class="example js" title="Using the userAgentAllowsProtocol() method">
// Check if the user agent allows the protocol `example-protocol`

Copy link
Preview

Copilot AI Sep 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Remove the unnecessary blank line in the code example. It adds no value and makes the example less clean.

Suggested change

Copilot uses AI. Check for mistakes.

if (DigitalCredential.userAgentAllowsProtocol('example-protocol')) {
// Protocol is allowed, call .create or .get with a protocol-specific request
} else {
// Protocol is not allowed, fall back to another method
}
</pre>
</p>
<h2 id="credential-management-integration">
Integration with Credential Management API
</h2>
Expand Down