@digitalbazaar/di-sd-primitives

中文文档
3.3.0发布于 2026/04/28BSD-3-ClauseES Module近 30 天下载 2.6万

数据完整性 选择性披露

中文使用文档
文档目录8 节
  1. 目录
  2. 背景情况
  3. 警卫
  4. 安装
  5. 使用量
  6. 贡献
  7. 商业支助
  8. 许可证

数据完整性 选择性披露 (@digitalbazaar/di-sd-primitives) (中文(简体) )

Build Status Coverage Status NPM Version

DI-SD(发布"DICED")(数据完整性选择披露) 与数据完整性选择性披露密码套件和jsonld签名.

目录

背景情况

用于与 https://github.com/digitalbazaar/jsonld-signers (中文(简体) ) v11.2及以上编.

另见相关的规格:

警卫

传统发展

安装

该软件需要并支持维持的最近版本的Node.js和 浏览器. 更新可能会去除对旧的未维护的平台版本的支持. 请使用依赖性版本锁文件和测试以确保兼容性 与这个软件.

从国家预防机制安装:

npm install @digitalbazaar/di-sd-primitives

在当地安装(用于开发):

git clone https://github.com/digitalbazaar/di-sd-primitives.git
cd di-sd-primitives
npm install

使用量

以下代码片段提供了一个完整的数字签名示例 使用此库的可核查证书:

import * as primitives from '@digitalbazaar/di-sd-primitives';

// canonize a document (e.g., Verifiable Credential (VC)) and replace blank
// node IDs that are informationally decoupled from the data in the document
const hmac = await primitives.createHmac({key: hmacKey});
const labelMapFactoryFunction =
  primitives.createHmacIdLabelMapFunction({hmac});
// returns an array of nquads
const result = await primitives.labelReplacementCanonicalizeJsonLd(
  {document: credential, labelMapFactoryFunction, options: {documentLoader}});

// canonize a document (e.g., VC) and replace blank node IDs with any
// values; most useful for verifiers to use a label map provided in a
// selectively disclosed proof (verifiers do not get the HMAC key, so they
// cannot generate *any* HMAC'd ID, they only get the disclosed labels)
const labelMap = new Map([
  ['c14n0', 'uSomeBase64UrlHMACDigest1'],
  ['c14n1', 'uSomeBase64UrlHMACDigest2'],
  ['c14n2', 'uSomeBase64UrlHMACDigest3']
]);
const labelMapFactoryFunction = primitives.createLabelMapFunction({labelMap});
// returns an array of nquads
const result = await primitives.labelReplacementCanonicalizeJsonLd(
  {document: credential, labelMapFactoryFunction, options: {documentLoader}});

// skolemize a document (e.g., VC), which replaces blank node IDs with stable
// URL IDs; most useful for performing selecting portions of a JSON-LD document
// and finding the matching selected N-Quads;
// `result` has `{expanded, compact}` for both expanded and compact forms of
// the skolemized JSON-LD document; the expanded form is often deskolemized to
// N-Quads and then canonicalized to produce canonical N-Quads and a mapping
// from the deskolemized blank node IDs to the canonical IDs; the compact form
// can then have N-many selection operations performed on it with the selection
// outputs too being converted to deskolemized N-Quads which can be mapped to
// matching canonical N-Quads
const result = await skolemizeCompactJsonLd({document, options});

// get deskolemized N-Quads from a document; most useful for converting
// previously skolemized expanded JSON-LD documents to canonicalize and
// generate a map of stable identifiers or for converting previously skolemized
// compact JSON-LD documents after selecting a portion of them for selective
// disclosure; see `selectCanonicalNQuads` primitive
const deskolemizedNQuads = await toDeskolemizedNQuads(
  {document: skolemizedExpandedOrCompactJsonLd, options});

// canonize N-Quads and replace blank node IDs and get a label mapping from
// the original blank node IDs to the new ones; most useful for canonizing
// deskolemized N-Quads to produce a
const hmac = await primitives.createHmac({key: hmacKey});
const labelMapFactoryFunction =
  primitives.createHmacIdLabelMapFunction({hmac});
// returns an object with `{nquads, labelMap}`, the array of nquads and the
// mapping from input blank node IDs to output blank node IDs (after the
// canonical IDs have been replaced using the given replacement label map)
const result = await primitives.labelReplacementCanonicalizeNQuads(
  {nquads, labelMapFactoryFunction, options: {documentLoader}});

// use JSON pointers to select a specific part of a JSON-LD document
// (e.g., VC); can be used on a regular or skolemized compact JSON-LD document
const pointers = [
  '/credentialSubject/driverLicense/dateOfBirth',
  '/credentialSubject/driverLicense/expirationDate'
];
const result = await primitives.selectJsonLd(
  {document: credential, pointers});

贡献

见 贡献文件来啊!

公关接受.

请遵照 标准读取 规格.

商业支助

该图书馆的商务支助可应下列请求提供: 数字集市: 支持@ digitalbazaar.com

许可证

新建 BSD 许可证( 3- clause) 2023年数字集市

版本与发布记录

@digitalbazaar/di-sd-primitives 共发布 10 个版本,首次发布于 2023/05/20;过去 12 个月发布了 2 个版本。

版本发布日期距今
3.3.0latest2026/04/286 个月前
3.2.02026/02/069 个月前
3.1.02024/11/262 年前
3.0.42024/08/272 年前
3.0.32024/08/062 年前
3.0.22024/08/022 年前

关于 @digitalbazaar/di-sd-primitives 的常见问题

@digitalbazaar/di-sd-primitives 是什么?

数据完整性 选择性披露

如何安装 @digitalbazaar/di-sd-primitives?

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

@digitalbazaar/di-sd-primitives 支持 TypeScript 吗?

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

@digitalbazaar/di-sd-primitives 支持 ESM 还是 CommonJS?

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

@digitalbazaar/di-sd-primitives 需要什么版本的 Node.js?

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

@digitalbazaar/di-sd-primitives 可以商用吗?

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

@digitalbazaar/di-sd-primitives 的下载量有多少?

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

@digitalbazaar/di-sd-primitives 还在维护吗?

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