发布时间:2025 年 11 月 26 日
您可以加入从 Chrome 143 开始的数字凭据 API 颁发源试用。借助此新 API,网站可以更轻松地向用户首选的钱包提供数字凭据。
背景资料
在发行方、验证方(信赖方)和持有者(钱包)组成的三方数字身份生态系统中,用户通常会通过推送配置在其钱包中配置数字身份证件。在此过程中,用户直接从签发机构的网站或应用开始身份证件签发流程。例如,用户访问州机动车辆管理处(签发机构)的网站后,可以开始将数字驾照保存到设备上首选的钱包应用(持有者)的流程。
为了使此模型成功运行,发卡机构需要一种安全可靠的方式来与钱包应用连接,以便签发身份证件。此流程一直较为零散,因为每个发卡机构都必须为合作的每个钱包应用构建自己的连接,通常依赖于自定义 URI 方案。这种方法造成了巨大的实施摩擦,迫使发卡机构构建并维护对不同钱包集成碎片化生态系统的支持。
数字凭据 API 签发
为了简化此流程,Chrome 正在扩大对 W3C Digital Credentials API 的支持,并添加了最近发布的凭证出示功能。
借助 navigator.credentials.create() 方法,签发方网站可以安全地调用钱包应用来签发凭据。当发卡机构网站使用 digital 成员调用 navigator.credentials.create() 时,浏览器会将流程委托给平台(截至 Chrome 143,仅限 Android)。平台会显示设备上安装的兼容钱包的列表。
然后,用户可以选择钱包,并同意添加凭据。
数字凭据 API 签发适用于同一设备(在移动设备上)和跨设备(桌面设备发起)场景。在跨设备场景中,桌面浏览器会显示一个二维码。当用户在移动设备上扫描该代码时,如果两部设备距离很近,系统将启动平台中介流程。
如何使用该 API
该 API 与协议无关,旨在与开放标准(例如 OpenID for Verifiable Credential Issuance (OpenID4VCI) 标准)搭配使用。
如需启动卡券发放流程,发卡机构网站必须调用 navigator.credentials.create() 并在 digital 对象内传递卡券发放请求,例如:
// Check if the browser supports Digital Credentials issuance and the protocol.
if (window.DigitalCredential && DigitalCredential.userAgentAllowsProtocol('openid4vci-v1')) {
// Construct a credential offer according to the OpenID4VCI specification.
// Note: The API is in an active development stage. Always consult the
// specification and documentation for the most recent implementation details
const credentialOffer = {
credential_issuer: 'https://digital-credentials.dev',
credential_configuration_ids: [
'org.iso.18013.5.1.mDL'
],
authorization_server_metadata: {
issuer: 'https://digital-credentials.dev',
token_endpoint: 'https://digital-credentials.dev/openid4vci/token',
authorization_endpoint: 'https://digital-credentials.dev/openid4vci/auth',
grant_types_supported: [
'authorization_code',
'urn:ietf:params:oauth:grant-type:pre-authorized_code'
],
response_types_supported: ['code','token']
},
// Metadata details to help the wallet display the credential correctly.
credential_issuer_metadata: {
credential_endpoint: 'https://digital-credentials.dev/openid4vci/credential',
credential_configurations_supported: {
'org.iso.18013.5.1.mDL': {
format: 'mso_mdoc',
display: [{
name: 'Driving License',
locale: 'en-US',
description: 'Mobile Driving License'
}],
// The claims that this document contains.
// For a full list of standard mDL claims, see the ISO/IEC 18013-5 specification.
claims: [{
path: ['org.iso.18013.5.1', 'family_name'],
display: [{ name: 'Family Name', locale: 'en-US' }]
}
// ... Add any other claims for your document here.
]
}
}
}
};
// This call is made from the issuer's frontend, likely inside a button's click handler.
try {
await navigator.credentials.create({
digital: {
requests: [{
// The protocol identifier for this version of OpenID4VCI.
protocol: 'openid4vci-v1',
data: credentialOffer
}
}]
}
});
console.log('Credential issuance handoff to OS was successful.');
} catch (e) {
console.error('Error starting the credential issuance flow:', e);
}
} else {
// The API is not supported. Provide an alternative issuance method.
console.log('Digital Credential Issuance API is not supported in this browser.');
}
试试看
在浏览器和 Android 设备中测试 Digital Credentials API 之前,请执行以下操作:
- 在桌面设备上更新到 Chrome 143 或更高版本,并在 Android 设备上安装 Google Play 服务 24.0 或更高版本。
- 在浏览器中启用
chrome://flags/#web-identity-digital-credentials-creation处的标志。 - 在 Android 设备上安装受支持的钱包应用,例如 demo CMWallet。
如需测试用于签发数字凭据的跨设备流程,请执行以下操作:
- 在桌面设备上前往 https://digital-credentials.dev/dmv。
- 按添加按钮启动卡片核发流程。
- 使用 Android 设备扫描二维码,然后按照提示操作。
按照这些步骤操作后,您会在 Android 设备上的钱包中获得新签发的凭据。
如需在您的网站上为用户启用此功能,请加入数字凭据 API 签发源试用计划。如需了解详情,请参阅源试用使用入门一文。
分享您的反馈
您的反馈至关重要,有助于我们不断改进该平台。在 Chromium bug 跟踪器上提交任何 bug 或功能请求。