@digitalcredentials/security-document-loader

中文文档
9.0.0发布于 2026/05/23MITTypeScriptES Module近 30 天下载 5023

A secure and convenient JSON-LD document loader for Node.js, browsers, and React Native.

原始使用文档
文档目录11 节
  1. Table of Contents
  2. Background
  3. Security
  4. Install
  5. NPM
  6. Development
  7. Usage
  8. Fetching From the Web
  9. Supported URL Protocol Handlers
  10. Contribute
  11. License

JSON-LD Document Loader (@digitalcredentials/security-document-loader)

Build status NPM Version

A secure and convenient JSON-LD document loader for Node.js, browsers, and React Native.

Table of Contents

Background

Included functionality:

  • Bundled contexts:
    • DID, VC 1.0, DCC, Open Badges v3, ed25519 and x25519 crypto suite contexts
  • DID resolver for did:key and did:web
  • Optional loading of arbitrary contexts from the web (see Usage).

Security

TBD

Install

  • Node.js 16+ is recommended.

NPM

To install via NPM:

npm install @digitalcredentials/security-document-loader

Development

To install locally (for development):

git clone https://github.com/digitalcredentials/security-document-loader.git
cd security-document-loader
npm install

Usage

To get a default document loader (with the stock set of bundled contexts):

import { securityLoader } from '@digitalcredentials/security-document-loader'

const documentLoader = securityLoader().build()

To add additional contexts:

import { securityLoader } from '@digitalcredentials/security-document-loader'

const loader = securityLoader()
loader.addStatic('https://example.com/my-context/v1', contextObject)

const documentLoader = loader.build()

Fetching From the Web

To enable fetching arbitrary contexts from the web (not recommended, if you can avoid it):

const documentLoader = securityLoader({ fetchRemoteContexts: true }).build()

Supported URL Protocol Handlers

Out of the box, this library supports loading the following documents:

  • Explicitly added URLs from static local caches (that is, ones that you explicitly add via loader.addStatic)
  • DID Documents using the did:key and did:web methods.

Additionally, if your use case allows it, you can enable fetchRemoteContexts, which will add support for URLs using the http and https protocols (see previous section).

Adding Custom Protocol Handlers

Sometimes you will need to add documents with other URL protocols. If you have internal code to resolve those protocols (for example, you can fetch some urn: documents from a local database), you can write a custom protocol handler:

import { securityLoader } from '@digitalcredentials/security-document-loader'

function getDocument (url) {
  // Some internal function that fetches or creates documents
}

const customResolver = {
  /**
   * @param {object} options - Options hashmap.
   * @param {string} options.url - Document URL (here `urn:...` key id)
   * @returns {Promise<object>} - Resolves with key object document.
   */
  async get(params: Record<string, string>): Promise<unknown> {
    let document
    try {
      document = await getDocument(params.url)
    } catch(e) {
      throw new Error('NotFoundError')
    }

    return document
  }
};

// For example, use your `getDocument` function to resolve all `urn:` URIs:
securityLoader.setProtocolHandler({protocol: 'urn', handler: customResolver})

const documentLoader = securityLoader().build()

Contribute

PRs accepted.

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

License

MIT License © 2022 Digital Credentials Consortium.

版本与发布记录

@digitalcredentials/security-document-loader 共发布 21 个版本,首次发布于 2022/10/18;过去 12 个月发布了 1 个版本。

版本发布日期距今
9.0.0latest2026/05/235 个月前
8.0.02025/05/221.5 年前
7.0.02025/05/011.5 年前
7.0.0-beta.1beta2025/03/151.7 年前
6.0.12024/11/132 年前
6.0.02024/08/052 年前

关于 @digitalcredentials/security-document-loader 的常见问题

@digitalcredentials/security-document-loader 是什么?

A secure and convenient JSON-LD document loader for Node.js, browsers, and React Native.

如何安装 @digitalcredentials/security-document-loader?

在项目目录运行 npm install @digitalcredentials/security-document-loader,或使用 pnpm add / yarn add / bun add。

@digitalcredentials/security-document-loader 支持 TypeScript 吗?

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

@digitalcredentials/security-document-loader 支持 ESM 还是 CommonJS?

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

@digitalcredentials/security-document-loader 需要什么版本的 Node.js?

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

@digitalcredentials/security-document-loader 可以商用吗?

@digitalcredentials/security-document-loader 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@digitalcredentials/security-document-loader 的下载量有多少?

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

@digitalcredentials/security-document-loader 还在维护吗?

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