@digitalcredentials/jsonld-signatures

中文文档
12.0.1发布于 2024/09/18BSD-3-ClauseCommonJS近 30 天下载 9.1万

An implementation of the Linked Data Signatures specifications for JSON-LD in JavaScript.

原始使用文档
文档目录11 节
  1. Table of Contents
  2. Background
  3. Relationship to Verifiable Credentials
  4. Security
  5. Document Loader
  6. Install
  7. Usage
  8. React Native Usage
  9. Node.js and Browser Usage
  10. Contribute
  11. License

JSON-LD Signatures (@digitalcredentials/jsonld-signatures)

NPM Version

An implementation of the Linked Data Signatures specification for JSON-LD, for Node.js and browsers.

Table of Contents

(Forked from jsonld-signatures v9.0.0 to provide TypeScript, Jest, and React Native compatibility.)

Background

A Linked Data Signature proof is created (or verified) by specifying a signature suite and a proof purpose.

The signature suite performs the cryptographic operation required to sign (or verify) a digital signature and includes information in a proof such as the verificationMethod identifier, the proof's controller, and the date the proof was created.

The proof purpose indicates why the proof was created and what its intended use is. This information can also be used to make sure that the verificationMethod was authorized for the stated purpose in the proof. Using a proof purpose helps to encourage people to authorize certain cryptographic keys (verification methods) for explicit purposes rather than granting them ambient authority. This approach can help prevent people from accidentally signing documents for reasons they did not intend.

This library provides base classes for signature suites and proof purposes so that custom extensions can be written. It also provides some commonly used proof purposes.

Relationship to Verifiable Credentials

jsonld-signatures is a low-level library that is meant to sign any JSON-LD document.

One common use case for creating these signatures is for use with Verifiable Credentials (VCs). If you're working with those, you should use a higher-level library that's specifically made for that purpose, such as @digitalcredentials/vc. (Incidentally, vc-js uses this library, jsonld-signatures, under the hood.)

Security

As with most security- and cryptography-related tools, the overall security of your system will largely depend on your design decisions (which key types you will use, where you'll store the private keys, what you put into your credentials, and so on).

Document Loader

During verification, the key and key controller information must be discovered. This library allows for the key and key controller information to be looked up via a documentLoader or it can be provided directly to the API via the signature suite or proof purpose, respectively.

This library's default documentLoader is very strict for security and content integrity purposes. It will only load locally available copies of the context documents that define the terms it uses internally. Any attempt to load any other documents (including other contexts) will throw an error. If other documents such as verification methods (e.g., public key documents), cannot be provided directly to the API and thus need to be loaded, a custom document loader must be passed. For the sake of clarity, the default document loader will only load locally available copies of the following documents:

If you require other documents to be loaded then you will need to provide a documentLoader that can provide them. jsonld.js provides both a node and browser documentLoader you can use, however, depending on your use case, you may increase security by using a custom documentLoader that is similarly strict and will only load a subset of documents that is constrained by some technical, security, or business rules.

Install

  • Node.js 12+ is required.

To install locally (for development):

git clone https://github.com/digitalcredentials/jsonld-signatures.git
cd jsonld-signatures
npm install

Usage

React Native Usage

This library depends on expo-crypto when used inside React Native projects. That means you must add expo-crypto to your project's dependencies.

Sample package.json:

  "dependencies": {
    "expo-crypto": "~12.8.0"
  }

Node.js and Browser Usage

jsonld-signatures (version 12.x and above) is not meant for standalone use. Instead, it's generally used through an individual crypto suite. For detailed usage instructions, see the READMEs of the supported suites:

Most of the usages with individual suites and key types will have elements in common. You'll need to:

  • Generate or import cryptographic keys to sign with (see the @digitalbazaar/crypto-ld >=v5.0) library), or use a secure signer() function provided by your secure cryptographic module.
  • Authorize those keys for the specific purpose you're using them for (see section on Proof Purpose below), using a Controller Document (such as a DID Document or similar).
  • Pair those keys with a corresponding cryptographic Signature Suite. For greenfield development, we recommend the Ed25519Signature2020 suite, and for legacy/compatibility work, you can use Ed25519Signature2018 suite. See also the Choosing a Key Type section of crypto-ld documentation.
  • Set up your documentLoader to fetch contexts and documents securely.
  • Lastly, perform the jsigs.sign() or jsigs.verify() operations.

Contribute

See the contribute file!

PRs accepted.

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

License

  • MIT License - DCC - TypeScript compatibility.
  • New BSD License (3-clause) © 2020-2021 Digital Bazaar - Initial implementation.

版本与发布记录

@digitalcredentials/jsonld-signatures 共发布 10 个版本,首次发布于 2021/05/20;过去 12 个月发布了 0 个版本。

版本发布日期距今
12.0.1latest2024/09/182 年前
12.0.02024/09/182 年前
11.0.02024/08/042 年前
10.1.02024/08/042 年前
10.0.12024/02/082 年前
10.0.02024/02/082 年前

关于 @digitalcredentials/jsonld-signatures 的常见问题

@digitalcredentials/jsonld-signatures 是什么?

An implementation of the Linked Data Signatures specifications for JSON-LD in JavaScript.

如何安装 @digitalcredentials/jsonld-signatures?

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

@digitalcredentials/jsonld-signatures 支持 TypeScript 吗?

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

@digitalcredentials/jsonld-signatures 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@digitalcredentials/jsonld-signatures 需要什么版本的 Node.js?

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

@digitalcredentials/jsonld-signatures 可以商用吗?

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

@digitalcredentials/jsonld-signatures 的下载量有多少?

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

@digitalcredentials/jsonld-signatures 还在维护吗?

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