@digitalbazaar/vpqr

中文文档
6.0.0发布于 2025/04/25BSD-3-ClauseES Module近 30 天下载 8945

An isomorphic JS (for Node.js and browser) library that takes a Verifiable Presentation, compresses it via CBOR-LD, and turns it into a QR Code.

原始使用文档
文档目录12 节
  1. Table of Contents
  2. Background
  3. Security
  4. Install
  5. Usage
  6. Encoding Verifiable Presentations as QR Code Images
  7. Decoding QR Code Text to Verifiable Presentation
  8. Encoding Options
  9. Advanced Options
  10. Contribute
  11. Commercial Support
  12. License

Verifiable Presentations to QR Code JS Lib (@digitalbazaar/vpqr)

Build Status Coverage Status NPM Version

An isomorphic JS (for Node.js and browser) library that takes a Verifiable Presentation, compresses it via CBOR-LD, and turns it into a QR Code.

Table of Contents

Background

TBD

Security

TBD

Install

  • Browsers and Node.js 14+ are supported.

To install from NPM:

npm install @digitalbazaar/vpqr

To install locally (for development):

git clone https://github.com/digitalbazaar/vpqr.git
cd vpqr
npm install

Usage

Encoding Verifiable Presentations as QR Code Images

import vpqr from '@digitalbazaar/vpqr';

const vp = {
  "@context": "https://www.w3.org/2018/credentials/v1",
  "type": "VerifiablePresentation",
  "verifiableCredential": {
    "@context": [
      "https://www.w3.org/2018/credentials/v1",
      "https://w3id.org/cit/v1",
      "https://w3id.org/security/suites/ed25519-2020/v1"
    ],
    "id": "urn:uuid:188e8450-269e-11eb-b545-d3692cf35398",
    "type": [
      "VerifiableCredential",
      "ConcealedIdTokenCredential"
    ],
    "issuer": "did:key:z6Mku2yHBpMvm13KqtupN7MNEj7Y7AREUWsFfGBRhyP9YZf7",
    "issuanceDate": "2021-03-24T20:03:03Z",
    "expirationDate": "2021-06-24T20:03:03Z",
    "credentialSubject": {
      "concealedIdToken": "zo58FV8vqzY2ZqLT4fSaVhe7CsdBKsUikBMbKridqSyc7LceLmgWcNTeHm2gfvgjuNjrVif1G2A5EKx2eyNkSu5ZBc6gNnjF8ZkV3P8dPrX8o46SF"
    },
    "proof": {
      "type": "Ed25519Signature2020",
      "created": "2021-03-24T20:03:03Z",
      "verificationMethod": "did:key:z6Mku2yHBpMvm13KqtupN7MNEj7Y7AREUWsFfGBRhyP9YZf7#z6Mku2yHBpMvm13KqtupN7MNEj7Y7AREUWsFfGBRhyP9YZf7",
      "proofPurpose": "assertionMethod",
      "proofValue": "z5Z33Pi9zWUWMHdxhG1Ko7ssgeHsuT3ocyg46pJTTjbwk1YjjtSCa4CQ5UyjnkQ6ar5ohY5Kv2mncWbfgEqWcVrTQ"
    }
  }
};

// Set up your documentLoader
const documentLoader = {/*...*/};
const {imageDataUrl} = await vpqr.toQrCode({vp, documentLoader});
// data:image/gif;base64,R0lGODdhqgCqAIAAAAAAAP///ywAAAAAqgCqAAAC/4yPqcvt...

When these QR Codes are scanned, they are read as Alphanumeric mode text,

VP1-R3ECQDIYBCEMDGEAYG2UADAYRCV4DA2DUORYHGOR...

in the format:

<format and version, 'VP1-'><multibase prefix, 'R'><base45 RFC9285 encoded CBOR-LD>

Decoding QR Code Text to Verifiable Presentation

// Alphanumeric text from a QR Code Reader lib
const qrCodeText = 'VP1-R3ECQDIYBCEMDGEAYG2UADAYRCV4DA2DUORYHGOR...';

// Set up your documentLoader
const documentLoader = {/*...*/};

const {vp} = await vqpr.fromQrCode({text: qrCodeText, documentLoader});
// { "@context": "https://www.w3.org/2018/credentials/v1", ... }
// becomes a JSON object with the VP in the example above.

Encoding Options

  • qrMultibaseEncoding: Encoding for QR data. B for RFC4648 base32, R for RFC9285 base45. base45 is more efficient. Defaults to base45.
  • qrErrorCorrectionLevel: Error correction level used in the QR code. 'L' Low 7%, 'M' Medium 15%, 'Q' Qartile 25%, 'H' High 30%. Defaults to 'L'.
  • qrVersion: QR version. 1-40 or 0 for auto. Defaults to auto.

Advanced Options

More advanced use cases can use extra options and the lower level APIs in util:

  • Encode and decode Verifiable Credentials.
  • Use custome encoding headers like VP1- and VC1-.
  • Access other related outputs.
  • Use options to control the output module size (the pixel size of the small squares) and image quiet zone margin size.
  • Control QR options such as error correction level.
  • Provide a diagnostics function.
  • Pass in legacy cborld appContextMap or modern registryEntryId, typeTable, and typeTableLoader options.
import {util} from '@digitalbazaar/vpqr';

const {toQrCode} = util;

// setup options as needed

// encode QR code
const {
  version, payload, imageDataUrl, encodedCborld, rawCborldBytes
} = await toQrCode({
  header: 'VC1-',
  jsondldDocument: verifiableCredential,
  documentLoader,
  registryEntryId: 2000,
  typeTableLoader,
  moduleSize: 4,
  margin: 16,
  qrErrorCorrectionLevel: 'H'
});

// decode QR code text
const {
  jsondldDocument
} = await fromQrCode({
  expectedHeader = 'VC1-',
  text,
  decodeCborld: true,
  documentLoader,
  typeTableLoader
});

Contribute

See the contribute file!

PRs accepted.

If editing the Readme, please conform to the standard-readme specification.

Commercial Support

Commercial support for this library is available upon request from Digital Bazaar: [email protected]

License

New BSD License (3-clause) © Digital Bazaar

版本与发布记录

@digitalbazaar/vpqr 共发布 11 个版本,首次发布于 2021/04/02;过去 12 个月发布了 0 个版本。

版本发布日期距今
6.0.0latest2025/04/251.5 年前
5.2.02025/04/251.5 年前
5.1.02024/10/222 年前
5.0.02024/08/302 年前
4.2.02024/08/272 年前
4.1.02023/12/202 年前

关于 @digitalbazaar/vpqr 的常见问题

@digitalbazaar/vpqr 是什么?

An isomorphic JS (for Node.js and browser) library that takes a Verifiable Presentation, compresses it via CBOR-LD, and turns it into a QR Code.

如何安装 @digitalbazaar/vpqr?

在项目目录运行 npm install @digitalbazaar/vpqr,或使用 pnpm add / yarn add / bun add。

@digitalbazaar/vpqr 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/digitalbazaar__vpqr 是否存在。

@digitalbazaar/vpqr 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@digitalbazaar/vpqr 需要什么版本的 Node.js?

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

@digitalbazaar/vpqr 可以商用吗?

@digitalbazaar/vpqr 使用 BSD-3-Clause 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。另外不得用原作者名义为衍生产品背书。以上为概括,不构成法律意见,请以许可原文为准。

@digitalbazaar/vpqr 的下载量有多少?

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

@digitalbazaar/vpqr 还在维护吗?

最新版本 6.0.0 发布于 2025/04/25(1.5 年前);至今共发布 11 个版本,其中过去 12 个月发布了 0 个;首次发布于 2021/04/02。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。