JavaScript 加密数据默认客户端 (@digitalbazaar/edv-客户端)
一个用于 Web 和 node.js 应用程序的 JavaScript 库,用于远程接口 加密的数据默认服务器
目录
背景情况
这个库提供了一个客户端, Web 和 node.js apps 可以用来接口 与远程加密的数据默认服务器.
它包括一个主要类别:
EdvClient- 实例为特定对象提供 CRUD (+ find) 接口 配置了加密的数据断层服务器并确保适当的数据库 设置索引 。 静态方法允许使用 远程存储服务,例如. 加密了数据默认存储服务器 .
加密的数据默认存储服务器 :
- 基于蒙戈DB - https://github.com/digitalbazaar/bedrock-edv- storage (中文(简体) )
- 以 PouchDB 为主 - https://github.com/digitalbazaar/bedrock-web-pouch-edv (中文(简体) )
安装
从国家预防机制安装:
npm install @digitalbazaar/edv-client
在当地安装(用于开发):
git clone https://github.com/digitalbazaar/edv-client.git
cd edv-client
npm install
使用量
创建和登记加密数据断层
首先,创建关键协议密钥和 HMAC( 基于 hash 信件认证) 代码)用于加密文档和使索引属性盲出 他们。 这需要创建一些密码关键材料,可以完成 当地或通过KMS系统。 当前的例子显示使用 KMS 系统 (TODO: 显示一个简单的本地示例):
import {CapabilityAgent, KeystoreAgent, KmsClient} from 'webkms-client';
import {EdvClient} from 'edv-client';
尽管加密的数据断层没有约束于任何特定的密钥管理
我们建议你利用
执行,例如
webkms-switch
可以连接到使用的
webkms-client。 。 。 .
可选 :
// 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 配置 :
// 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 :
// 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()数字 :
// 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数字 :
// 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
贡献
请遵循现有的代码样式 .
公关接受.
请遵照 标准读取 规格.
许可证
BSD-3- 标签 版权由2019-2025 Digital Bazaar, Inc.
商业支助是通过联系 数字集市 支持@ digitalbazaar.com。 。 。 .