DigitalCredentials
Ask the user's wallet to present a verifiable credential - a mobile driving licence, an ID card, a diploma - and get back what it signed, with the browser mediating which claims are released.
@inject Bit.Butil.DigitalCredentials digitalCredentialsMDN reference
IsProtocolSupported rather than on a version. Build the request object on your
server - it is signed, and what it asks for is what the wallet shows the user - and verify the
response there too: its signature, its issuer, and the nonce you put in the request. Needs a
secure context, a user gesture, and a top-level page (or an iframe with
allow="digital-credentials-get").
Whether the runtime exposes window.DigitalCredential, and whether it will speak a given exchange protocol. During prerender/SSR these return false rather than throwing, so defer them to OnAfterRenderAsync.
@inject Bit.Butil.DigitalCredentials digitalCredentials
var supported = await digitalCredentials.IsSupported();
var openid4vp = await digitalCredentials.IsProtocolSupported("openid4vp");Opens the wallet chooser and resolves with the presentation the wallet signed, or null when the user declined, nothing matched, or the browser refused. Must be called from a user-gesture handler. Data arrives as raw JSON - hand it to the server as it stands.
var response = await digitalCredentials.Get(
[
new DigitalCredentialRequest
{
Protocol = "openid4vp",
Data = serverBuiltPresentationRequest // signed, built on the server
}
], CredentialMediation.Required);
if (response is not null)
{
// POST response.Data to the backend and verify it there.
}The other direction, for an issuer that has already established who the user is. Newer than Get and thinner on the ground, so check for it before offering it. Null when the user declined or no wallet accepted it.
var issued = await digitalCredentials.Create(
[
new DigitalCredentialRequest
{
Protocol = "openid4vci",
Data = serverBuiltIssuanceRequest
}
]);API reference
ValueTask<bool> IsSupported()ValueTask<bool> IsProtocolSupported(string protocol)ValueTask<DigitalCredentialResponse?> Get(DigitalCredentialRequest[] requests, CredentialMediation mediation = CredentialMediation.Required, CancellationToken cancellationToken = default)ValueTask<DigitalCredentialResponse?> Create(DigitalCredentialRequest[] requests, CancellationToken cancellationToken = default)ValueTask<bool> Abort()string Protocol, object Datastring Protocol, JsonElement Data