# @digitalbazaar/edv-client 中文文档

规范地址：https://npmcn.com/package/%40digitalbazaar/edv-client/

版本：16\.3\.0
npm 元数据更新时间：2025-09-18T03:16:34.629Z
中文译文更新时间：2026-11-13T04:42:21.143Z
软件包许可：BSD-3-Clause

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40digitalbazaar/edv-client
原文对照：https://npmcn.com/package/%40digitalbazaar/edv-client/?lang=original
项目主页：https://github.com/digitalbazaar/edv-client
源码仓库：https://github.com/digitalbazaar/edv-client

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：131 kB，14 个文件
- 模块格式：ES Module
- TypeScript 类型：未声明
- Node.js 要求：\>=18
- 运行依赖：8 个
- 首次发布：2022-01-11T21:42:13.047Z
- 最新版本发布：2025-09-18T03:16:34.439Z
- 近 30 天下载量：2307（2026-10-12 至 2026-11-10，npm 官方下载统计）
- 已发布版本数：23（近 12 个月 0 个）

## 中文简介

JavaScript 加密数据默认值

## 安装

```sh
npm install @digitalbazaar/edv-client
```

也可以使用：`pnpm add @digitalbazaar/edv-client`、`yarn add @digitalbazaar/edv-client`、`bun add @digitalbazaar/edv-client`

## README

# JavaScript 加密数据默认客户端 _(@digitalbazaar/edv-客户端)_

> 一个用于 Web 和 node.js 应用程序的 JavaScript 库,用于远程接口 加密的数据默认服务器

## 目录

-   [背景情况](https://npmcn.com/package/%40digitalbazaar/edv-client/#readme-background)
-   [安装](https://npmcn.com/package/%40digitalbazaar/edv-client/#readme-install)
-   [使用量](https://npmcn.com/package/%40digitalbazaar/edv-client/#readme-usage)
-   [API 密码](https://npmcn.com/package/%40digitalbazaar/edv-client/#readme-api)
-   [贡献](https://npmcn.com/package/%40digitalbazaar/edv-client/#readme-contribute)
-   [许可证](https://npmcn.com/package/%40digitalbazaar/edv-client/#readme-license)

## 背景情况

这个库提供了一个客户端, Web 和 node.js apps 可以用来接口 与远程加密的数据默认服务器.

它包括一个主要类别:

-   **`EdvClient`** - 实例为特定对象提供 CRUD (+ find) 接口 配置了加密的数据断层服务器并确保适当的数据库 设置索引 。 静态方法允许使用 远程存储服务,例如. 加密了数据默认存储服务器 .

#### 加密的数据默认存储服务器 :

-   基于蒙戈DB - [https://github.com/digitalbazaar/bedrock-edv- storage (中文(简体) )](https://github.com/digitalbazaar/bedrock-edv-storage)
-   以 PouchDB 为主 - [https://github.com/digitalbazaar/bedrock-web-pouch-edv (中文(简体) )](https://github.com/digitalbazaar/bedrock-web-pouch-edv)

## 安装

-   浏览器和Node.js 18+得到支持.
-   [流出 API](https://developer.mozilla.org/en-US/docs/Web/API/Streams_API) 所需经费。 旧浏览器必须使用多填充.
-   [网络加密 API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API) 所需经费。 旧浏览器必须使用多填充.

从国家预防机制安装:

```sh
npm install @digitalbazaar/edv-client
```

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

```sh
git clone https://github.com/digitalbazaar/edv-client.git
cd edv-client
npm install
```

## 使用量

### 创建和登记加密数据断层

首先,创建关键协议密钥和 HMAC( 基于 hash 信件认证) 代码)用于加密文档和使索引属性盲出 他们。 这需要创建一些密码关键材料,可以完成 当地或通过KMS系统。 当前的例子显示使用 KMS 系统 (TODO: 显示一个简单的本地示例):

```js
import {CapabilityAgent, KeystoreAgent, KmsClient} from 'webkms-client';
import {EdvClient} from 'edv-client';
```

尽管加密的数据断层没有约束于任何特定的密钥管理 我们建议你利用 执行,例如 [`webkms-switch`](https://github.com/digitalbazaar/webkms-switch) 可以连接到使用的 [`webkms-client`](https://github.com/digitalbazaar/webkms-client)。 。 。 .

可选 :

```js
// create a CapabilityAgent (for invoking zcaps)
const capabilityAgent = await CapabilityAgent.fromSecret({secret, handle});

// create a keystore and an agent for working with it
// the baseUrl can be set to a dev API or production API
const kmsBaseUrl = `${config.server.baseUri}/kms`;
const keystore = KmsClient.createKeystore({
  // the url for the keystore is configurable
  url: `${kmsBaseUrl}/keystores`,
  config: {
    // on init the sequence must be 0
    sequence: 0,
    controller: capabilityAgent.id,
    invoker: capabilityAgent.id,
    // this allows the capabilityAgent to delegate zCaps
    delegator: capabilityAgent.id
  },
  /**
   * optional `httpsAgent`,
   * usually not applicable for front-end (you may use axios),
   * for back-end use cases a nodejs `https.Agent`
   * may be used to allow the use of self signed certificates using
   * the `rejectUnauthorized: false` flag in the contructor.
  */
  httpsAgent
});
const keystoreAgent = new KeystoreAgent({keystore, capabilityAgent});

// use the keystore agent to create key agreement and HMAC keys
const keyAgreementKey = await keystoreAgent.generateKey({type: 'keyAgreement'});
const hmac = await keystoreAgent.generateKey({type: 'hmac'});
```

现在您可以创建并注册一个新的 EDV 配置 :

```js
// TODO: explain EDV service must be able to authenticate user
const controller = 'account id goes here';

const config = {
  // on init the sequence must be 0 and is required
  sequence: 0,
  controller,
  // TODO: Explain what 'referenceId' is
  referenceId: 'primary',
  keyAgreementKey: {id: keyAgreementKey.id, type: keyAgreementKey.type},
  hmac: {id: hmac.id, type: hmac.type}
};

// sends a POST request to the remote service to create an EDV
const remoteConfig = await EdvClient.createEdv({config});

// connect to the new EDV via a `EdvClient`
const client = new EdvClient({id: remoteConfig.id, keyAgreementKey, hmac});
// to only use fips-compliant key agreement and encryption algorithms:
const client = new EdvClient(
  {id: remoteConfig.id, keyAgreementKey, hmac, cipherVersion: 'fips'});
```

您可以在创建和注册新的 EDV 配置时指定 URL :

```js
// TODO: explain EDV service must be able to authenticate user
const controller = 'account id (or DID if using zcaps) goes here';

const config = {
  // on init the sequence must be 0 and is required
  sequence: 0,
  controller,
  // TODO: Explain what 'referenceId' is
  referenceId: 'primary',
  keyAgreementKey: {id: keyAgreementKey.id, type: keyAgreementKey.type},
  hmac: {id: hmac.id, type: hmac.type}
};

// sends a POST request to the remote service to create an EDV
const remoteConfig = await EdvClient.createEdv({
  url: 'https://server.example/edvs',
  config,
  // must pass `invocationSigner` and optional `capability` if `controller`
  // is a DID
  /* invocationSigner, capability */
});

// connect to the new EDV via a `EdvClient`
const client = new EdvClient({id: remoteConfig.id, keyAgreementKey, hmac});
```

### 正在装入保存的 EDV 配置

如果您已经注册过 EDV 配置( 通过 `createEdv()`, (中文(简体) ), 你知道这 `id`您可以通过 `get()`数字 :

```js
// registered config
const {id} = await EdvClient.createEdv({config});

// later, it can be fetched via the id
const remoteConfig = await EdvClient.getConfig({id});

// connect to the existing EDV via an `EdvClient` instance
const client = new EdvClient({id: remoteConfig.id, keyAgreementKey, hmac});
```

如果你知道一个控制器/`accountId` 但不知道具体的EDV `id`,你吗 可以通过控制范围自定义为 EDV 创建客户端 `referenceId`数字 :

```js
// get the account's 'primary' EDV config to connect to the EDV
// note that a referenceId can be any string but must be unique per controller
const config = await EdvClient.findConfig(
  {controller: accountId, referenceId: 'primary'});
const client = new EdvClient({id: config.id, keyAgreementKey, hmac});
```

### 文档存储使用 EdvClient 实例

见下文API部分.

## API 密码

### `EdvClient`

#### `constructor`

#### `insert`

#### `get`

#### `update`

#### `delete`

#### `find`

#### `ensureIndex`

#### `updateIndex`

## 贡献

请遵循现有的代码样式 .

公关接受.

请遵照 [标准读取](https://github.com/RichardLitt/standard-readme) 规格.

## 许可证

[BSD-3- 标签](https://npmcn.com/package/%40digitalbazaar/edv-client/LICENSE) 版权由2019-2025 Digital Bazaar, Inc.

商业支助是通过联系 [数字集市](https://digitalbazaar.com/) [支持@ digitalbazaar.com](mailto:support@digitalbazaar.com)。 。 。 .

## 常见问题

### @digitalbazaar/edv-client 是什么？

JavaScript 加密数据默认值

### 如何安装 @digitalbazaar/edv-client？

在项目目录运行 npm install @digitalbazaar/edv-client，或使用 pnpm add / yarn add / bun add。

### @digitalbazaar/edv-client 支持 TypeScript 吗？

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

### @digitalbazaar/edv-client 支持 ESM 还是 CommonJS？

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

### @digitalbazaar/edv-client 需要什么版本的 Node\.js？

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

### @digitalbazaar/edv-client 可以商用吗？

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

### @digitalbazaar/edv-client 的下载量有多少？

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

### @digitalbazaar/edv-client 还在维护吗？

最新版本 16\.3\.0 发布于 2025/09/18（1\.2 年前）；至今共发布 23 个版本，其中过去 12 个月发布了 0 个；首次发布于 2022/01/12。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

