@dfinity/verifiable-credentials

中文文档
1.3.0发布于 2026/03/27Apache-2.0TypeScriptESM + CJS构建来源已验证近 30 天下载 5870

Library to interact with the identity provider to get a credential presentation.

原始使用文档
文档目录5 节
  1. Installation
  2. Relying Party: Request Credentials
  3. Summary
  4. Usage
  5. Paremeters

Javascript SDK For Verifiable Credentials

At the moment, this library only contains a function to interact with an Identity Provider to get a credential presentation for a user.

The flow to request a credential is performed through a browser.

Installation

Install library

npm install @dfinity/verifiable-credentials

The bundle needs peer dependencies, be sure that following resources are available in your project as well.

npm install @dfinity/principal

Import per modules:

// import * from '@dfinity/verifiable-credentials'; // Error: use sub-imports, to ensure small app size
import { requestVerifiablePresentation } from "@dfinity/verifiable-credentials/request-verifiable-presentation";

Relying Party: Request Credentials

Use the function requestVerifiablePresentation to request credentials from an issuer.

Summary

The function performs the following steps:

  • Open a new window or tab with the Identity Provider.
  • Wait for a window post message from the Identity Provider.
  • Send a request to the Identity Provider through the window post message.
  • Wait for the response from the Identity Provider.
  • Call onSuccess callback when the flow was successful. Not necessarily that the credential was received.
  • Call onError callback when the flow has some technical error or the user closes the window.

More info in the Internet Identity Specification for Verifiable Credentials.

Usage

To start a flow, call the function with the expected parameters:

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>",
});

Paremeters

List of properties expected in the parameter when calling the function:

  • onSuccess: Function that will be called when the flow finishes. Not necessarily with the credential. This is also called if the user doesn't have the credential.
  • onError: Function that will be called when the flow failes due to a technical error. Also when the user interrupts the flow.
  • issuerData: Object with the origin and canisterId of the issuer.
  • credentialData: Object with the subbject and the credential requested.
  • identityProvider: URL of the Identity Provider. Ex: new URL("https://identity.ic0.app/").
  • derivationOrigin: Indicates an origin that should be used for principal derivation. It's the same value as the one used when logging in. More info.
  • windowOpenerFeatures The flow will open a new window or tab. Pass here a configuration string to customize it.

版本与发布记录

@dfinity/verifiable-credentials 共发布 26 个版本,首次发布于 2024/05/03;过去 12 个月发布了 2 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.3.0latest2026/03/277 个月前
1.2.0-next-2026-03-05next2026/03/058 个月前
1.2.02025/11/061 年前
1.2.0-next-2025-11-052025/11/051 年前
1.1.0-next-2025-11-052025/11/051 年前
1.1.0-next-2025-09-262025/09/261.1 年前

关于 @dfinity/verifiable-credentials 的常见问题

@dfinity/verifiable-credentials 是什么?

Library to interact with the identity provider to get a credential presentation.

如何安装 @dfinity/verifiable-credentials?

在项目目录运行 npm install @dfinity/verifiable-credentials,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@icp-sdk/core(^*)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@dfinity/verifiable-credentials 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@dfinity/verifiable-credentials 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@dfinity/verifiable-credentials 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=v22。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@dfinity/verifiable-credentials 可以商用吗?

@dfinity/verifiable-credentials 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@dfinity/verifiable-credentials 的下载量有多少?

根据 npm 官方下载统计,@dfinity/verifiable-credentials 在 2026/10/12 – 2026/11/10 这 30 天内被下载 5,870 次,日均约 196 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@dfinity/verifiable-credentials 还在维护吗?

最新版本 1.3.0 发布于 2026/03/27(7 个月前);至今共发布 26 个版本,其中过去 12 个月发布了 2 个;首次发布于 2024/05/03。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。