Javascript SDK 用于验证证书
目前,这个库只包含一个功能,可以与身份提供者互动,为用户获取证书演示文稿.
请求证书的流程是通过浏览器实现的.
安装
安装库
npm install @dfinity/verifiable-credentials
捆绑需要同伴的依赖关系, 请确定您的项目中也提供后续资源 .
npm install @dfinity/principal
每个模块导入 :
// import * from '@dfinity/verifiable-credentials'; // Error: use sub-imports, to ensure small app size
import { requestVerifiablePresentation } from "@dfinity/verifiable-credentials/request-verifiable-presentation";
依赖方:申请全权证书
使用函数 requestVerifiablePresentation 请签发人出示全权证书.
内容提要
该职能履行以下步骤:
- 使用身份提供者打开新窗口或标签 .
- 等待身份提供者的窗口留言.
- 通过窗口后留言向身份提供者发送请求 .
- 等待身份提供者的回应.
- 打电话
onSuccess流量成功时调用 。 不一定收到证书. - 打电话
onError当流量出现技术错误或用户关闭窗口时调用.
更多信息在 核证证书的因特网身份规格。 。 。 .
使用量
要启动流量,请使用预期参数调用函数:
requestVerifiablePresentation({
onSuccess: async (verifiablePresentation: VerifiablePresentationResponse) => {
// Called when the flow finishes successfully.
},
onError() {
// Called when there is a technical error.
},
issuerData: {
origin: "<url of the origin>",
canisterId: "<canister id>",
},
credentialData: {
credentialSpec: {
credentialType: '<credential type as expected by issuer>',
arguments: {
// Arguments to verify with the credential
},
},
credentialSubject: "<user's principal>",
},
identityProvider: "<url identity provider>",
derivationOrigin: "<[optional] origin for delegated identity>",
windowOpenerFeatures: "<[optional] window opener config string>",
});
平分仪
调用函数时, 参数中预期属性列表 :
onSuccess: 当流结束时将调用函数 。 不一定与证书。 如果用户没有证书,也叫这个.onError: 当流量因技术错误而故障时将调用函数 。 另外当用户中断流量时.issuerData: 带有origin财务报告和审定财务报表canisterId发行人.credentialData: 带有子项目和所要求的证书的对象.identityProvider:身份提供者的URL. 实例:new URL("https://identity.ic0.app/")。 。 。 .derivationOrigin: 说明主要衍生来源。 和登入时使用的一样值. 更多信息。 。 。 .windowOpenerFeatures流量会打开一个新的窗口或标签 。 在此通过一个配置字符串来自定义它 .