-
Notifications
You must be signed in to change notification settings - Fork 27
Editorial: Add feature and protocol detection examples #371
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+72
−4
Merged
Changes from 2 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
50ae297
Adds feature and protocol detection examples
timcappalli 6586474
add inline example for userAgentAllowsProtocol
timcappalli ec48d8c
simplify example
timcappalli f2ce478
Update index.html
marcoscaceres 6c6019b
Cleanup example section
marcoscaceres ce0af14
fixup
marcoscaceres 7f89f58
Update index.html
marcoscaceres 927f23e
Apply suggestions from code review
marcoscaceres 8764827
Apply suggestions from code review
marcoscaceres 318097f
Apply suggestions from code review
marcoscaceres 4416679
Update index.html
marcoscaceres 435c915
tidy
marcoscaceres 00b015f
Clarify usage a bit more
marcoscaceres 4ae5338
fixup
marcoscaceres 6b9bb1a
Merge branch 'main' into tc-detection
marcoscaceres a2f0dce
Apply suggestions from code review
marcoscaceres 5a4484c
Relocate protocol check
marcoscaceres 0402b91
Fixup examples
marcoscaceres 408e280
fix typo
marcoscaceres 460363c
Apply suggestions from code review
marcoscaceres 471ae69
Apply suggestions from code review
marcoscaceres 2935f74
Apply suggestions from code review
marcoscaceres 2b1df10
Merge branch 'main' into tc-detection
marcoscaceres File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -206,36 +206,41 @@ <h3> | |||
<button>Verify Identity</button> | ||||
<script> | ||||
const button = document.querySelector("button"); | ||||
button.addEventListener("click", async () => { | ||||
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. | ||||
} | ||||
}); | ||||
</script> | ||||
|
@@ -263,17 +268,22 @@ <h3> | |||
<script> | ||||
const button = document.querySelector("button"); | ||||
button.addEventListener("click", async () => { | ||||
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')) { | ||||
marcoscaceres marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||
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. | ||||
} | ||||
}); | ||||
</script> | ||||
|
@@ -739,6 +749,17 @@ <h4> | |||
`false`. | ||||
</li> | ||||
</ol> | ||||
<p id="protocol-allowed-examples"> | ||||
timcappalli marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||
<pre class="example js" title="Using the userAgentAllowsProtocol() method"> | ||||
timcappalli marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||
// Check if the user agent allows the protocol `example-protocol` | ||||
|
||||
|
Copilot uses AI. Check for mistakes.
Positive FeedbackNegative Feedback
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.