@interop/edv-client 17.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +27 -0
- package/README.md +276 -0
- package/dist/EdvClient.d.ts +412 -0
- package/dist/EdvClient.d.ts.map +1 -0
- package/dist/EdvClient.js +663 -0
- package/dist/EdvClient.js.map +1 -0
- package/dist/EdvClientCore.d.ts +264 -0
- package/dist/EdvClientCore.d.ts.map +1 -0
- package/dist/EdvClientCore.js +698 -0
- package/dist/EdvClientCore.js.map +1 -0
- package/dist/EdvDocument.d.ts +92 -0
- package/dist/EdvDocument.d.ts.map +1 -0
- package/dist/EdvDocument.js +149 -0
- package/dist/EdvDocument.js.map +1 -0
- package/dist/HttpsTransport.d.ts +87 -0
- package/dist/HttpsTransport.d.ts.map +1 -0
- package/dist/HttpsTransport.js +415 -0
- package/dist/HttpsTransport.js.map +1 -0
- package/dist/IndexHelper.d.ts +163 -0
- package/dist/IndexHelper.d.ts.map +1 -0
- package/dist/IndexHelper.js +539 -0
- package/dist/IndexHelper.js.map +1 -0
- package/dist/LegacyIndexHelperVersion1.d.ts +150 -0
- package/dist/LegacyIndexHelperVersion1.d.ts.map +1 -0
- package/dist/LegacyIndexHelperVersion1.js +475 -0
- package/dist/LegacyIndexHelperVersion1.js.map +1 -0
- package/dist/Transport.d.ts +142 -0
- package/dist/Transport.d.ts.map +1 -0
- package/dist/Transport.js +181 -0
- package/dist/Transport.js.map +1 -0
- package/dist/assert.d.ts +6 -0
- package/dist/assert.d.ts.map +1 -0
- package/dist/assert.js +61 -0
- package/dist/assert.js.map +1 -0
- package/dist/baseX.d.ts +7 -0
- package/dist/baseX.d.ts.map +1 -0
- package/dist/baseX.js +8 -0
- package/dist/baseX.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/util.d.ts +3 -0
- package/dist/util.d.ts.map +1 -0
- package/dist/util.js +13 -0
- package/dist/util.js.map +1 -0
- package/package.json +112 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
Copyright (c) 2018-2020, Digital Bazaar, Inc.
|
|
2
|
+
All rights reserved.
|
|
3
|
+
|
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
|
6
|
+
|
|
7
|
+
* Redistributions of source code must retain the above copyright notice, this
|
|
8
|
+
list of conditions and the following disclaimer.
|
|
9
|
+
|
|
10
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
|
11
|
+
this list of conditions and the following disclaimer in the documentation
|
|
12
|
+
and/or other materials provided with the distribution.
|
|
13
|
+
|
|
14
|
+
* Neither the name of the copyright holder nor the names of its
|
|
15
|
+
contributors may be used to endorse or promote products derived from
|
|
16
|
+
this software without specific prior written permission.
|
|
17
|
+
|
|
18
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
19
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
20
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
21
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
22
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
23
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
24
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
25
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
26
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
27
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
ADDED
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
# JavaScript Encrypted Data Vault Client _(@interop/edv-client)_
|
|
2
|
+
|
|
3
|
+
> A JavaScript library for Web and node.js apps for interfacing with a remote
|
|
4
|
+
> Encrypted Data Vault server
|
|
5
|
+
|
|
6
|
+
## Table of Contents
|
|
7
|
+
|
|
8
|
+
- [Background](#background)
|
|
9
|
+
- [Install](#install)
|
|
10
|
+
- [Usage](#usage)
|
|
11
|
+
- [API](#api)
|
|
12
|
+
- [Contribute](#contribute)
|
|
13
|
+
- [License](#license)
|
|
14
|
+
|
|
15
|
+
## Background
|
|
16
|
+
|
|
17
|
+
This library provides a client that Web and node.js apps can use to interface
|
|
18
|
+
with remote Encrypted Data Vault (EDV) servers.
|
|
19
|
+
|
|
20
|
+
It consists of one main class:
|
|
21
|
+
|
|
22
|
+
- **`EdvClient`** - instances provide a CRUD (+ find) interface to a specific
|
|
23
|
+
configured Encrypted Data Vault server and ensure appropriate database indexes
|
|
24
|
+
are set up. Static methods allow for the creation of EDVs with a remote
|
|
25
|
+
storage service, e.g. Encrypted Data Vault storage servers.
|
|
26
|
+
|
|
27
|
+
#### Encrypted Data Vault storage servers:
|
|
28
|
+
|
|
29
|
+
- MongoDB-based - https://github.com/digitalbazaar/bedrock-edv-storage
|
|
30
|
+
- PouchDB-based - https://github.com/digitalbazaar/bedrock-web-pouch-edv
|
|
31
|
+
|
|
32
|
+
## Install
|
|
33
|
+
|
|
34
|
+
- Browsers and Node.js 24+ are supported.
|
|
35
|
+
- [Streams API][] required. Older browsers must use a polyfill.
|
|
36
|
+
- [Web Crypto API][] required. Older browsers must use a polyfill.
|
|
37
|
+
|
|
38
|
+
To install from NPM:
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
npm install @interop/edv-client
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
To install locally (for development):
|
|
45
|
+
|
|
46
|
+
```sh
|
|
47
|
+
git clone https://github.com/interop-alliance/edv-client.git
|
|
48
|
+
cd edv-client
|
|
49
|
+
pnpm install
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
This library is written in TypeScript and built with `tsc`. Common scripts:
|
|
53
|
+
|
|
54
|
+
```sh
|
|
55
|
+
pnpm run build # compile src/ to dist/
|
|
56
|
+
pnpm run lint # eslint
|
|
57
|
+
pnpm run test:node # vitest (Node)
|
|
58
|
+
pnpm run test:browser # playwright (browser smoke test)
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### React Native
|
|
62
|
+
|
|
63
|
+
This library is isomorphic and runs on React Native, with one environment
|
|
64
|
+
requirement: it uses the Web Crypto `crypto.getRandomValues()` API to generate
|
|
65
|
+
random identifiers, which React Native does not provide natively. Consumers must
|
|
66
|
+
install the [`react-native-get-random-values`][] polyfill and import it
|
|
67
|
+
**once**, before any `edv-client` code runs (typically at the very top of your
|
|
68
|
+
app entry, e.g. `index.js`):
|
|
69
|
+
|
|
70
|
+
```sh
|
|
71
|
+
npm install react-native-get-random-values
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
```js
|
|
75
|
+
// must be the first import in your app entry
|
|
76
|
+
import 'react-native-get-random-values'
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
It is declared as an optional `peerDependency`. No additional shim is needed for
|
|
80
|
+
hashing -- SHA-256 is provided by the pure-JS [`@noble/hashes`][]
|
|
81
|
+
implementation.
|
|
82
|
+
|
|
83
|
+
## Usage
|
|
84
|
+
|
|
85
|
+
### Creating and registering an Encrypted Data Vault (EDV)
|
|
86
|
+
|
|
87
|
+
First, create a key agreement key and an HMAC (hash-based message authentication
|
|
88
|
+
code) key for encrypting your documents and blinding any indexed attributes in
|
|
89
|
+
them. This requires creating some cryptographic key material which can be done
|
|
90
|
+
locally or via a KMS system. The current example shows using a KMS system (TODO:
|
|
91
|
+
show a simpler local example):
|
|
92
|
+
|
|
93
|
+
```js
|
|
94
|
+
import { CapabilityAgent, KeystoreAgent, KmsClient } from 'webkms-client'
|
|
95
|
+
import { EdvClient } from '@interop/edv-client'
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Although Encrypted Data Vaults are not bound to any particular key management
|
|
99
|
+
system, we recommend that you set up a Key Management Service using an
|
|
100
|
+
implementation such as
|
|
101
|
+
[`webkms-switch`](https://github.com/digitalbazaar/webkms-switch) which you can
|
|
102
|
+
connect to using
|
|
103
|
+
[`webkms-client`](https://github.com/digitalbazaar/webkms-client).
|
|
104
|
+
|
|
105
|
+
Optional:
|
|
106
|
+
|
|
107
|
+
```js
|
|
108
|
+
// create a CapabilityAgent (for invoking zcaps)
|
|
109
|
+
const capabilityAgent = await CapabilityAgent.fromSecret({ secret, handle })
|
|
110
|
+
|
|
111
|
+
// create a keystore and an agent for working with it
|
|
112
|
+
// the baseUrl can be set to a dev API or production API
|
|
113
|
+
const kmsBaseUrl = `${config.server.baseUri}/kms`
|
|
114
|
+
const keystore = KmsClient.createKeystore({
|
|
115
|
+
// the url for the keystore is configurable
|
|
116
|
+
url: `${kmsBaseUrl}/keystores`,
|
|
117
|
+
config: {
|
|
118
|
+
// on init the sequence must be 0
|
|
119
|
+
sequence: 0,
|
|
120
|
+
controller: capabilityAgent.id,
|
|
121
|
+
invoker: capabilityAgent.id,
|
|
122
|
+
// this allows the capabilityAgent to delegate zCaps
|
|
123
|
+
delegator: capabilityAgent.id
|
|
124
|
+
},
|
|
125
|
+
/**
|
|
126
|
+
* optional `httpsAgent`,
|
|
127
|
+
* usually not applicable for front-end (you may use axios),
|
|
128
|
+
* for back-end use cases a nodejs `https.Agent`
|
|
129
|
+
* may be used to allow the use of self signed certificates using
|
|
130
|
+
* the `rejectUnauthorized: false` flag in the contructor.
|
|
131
|
+
*/
|
|
132
|
+
httpsAgent
|
|
133
|
+
})
|
|
134
|
+
const keystoreAgent = new KeystoreAgent({ keystore, capabilityAgent })
|
|
135
|
+
|
|
136
|
+
// use the keystore agent to create key agreement and HMAC keys
|
|
137
|
+
const keyAgreementKey = await keystoreAgent.generateKey({
|
|
138
|
+
type: 'keyAgreement'
|
|
139
|
+
})
|
|
140
|
+
const hmac = await keystoreAgent.generateKey({ type: 'hmac' })
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Now you can create and register a new EDV configuration:
|
|
144
|
+
|
|
145
|
+
```js
|
|
146
|
+
// TODO: explain EDV service must be able to authenticate user
|
|
147
|
+
const controller = 'account id goes here'
|
|
148
|
+
|
|
149
|
+
const config = {
|
|
150
|
+
// on init the sequence must be 0 and is required
|
|
151
|
+
sequence: 0,
|
|
152
|
+
controller,
|
|
153
|
+
// TODO: Explain what 'referenceId' is
|
|
154
|
+
referenceId: 'primary',
|
|
155
|
+
keyAgreementKey: { id: keyAgreementKey.id, type: keyAgreementKey.type },
|
|
156
|
+
hmac: { id: hmac.id, type: hmac.type }
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// sends a POST request to the remote service to create an EDV
|
|
160
|
+
const remoteConfig = await EdvClient.createEdv({ config })
|
|
161
|
+
|
|
162
|
+
// connect to the new EDV via a `EdvClient`
|
|
163
|
+
const client = new EdvClient({ id: remoteConfig.id, keyAgreementKey, hmac })
|
|
164
|
+
// to only use fips-compliant key agreement and encryption algorithms:
|
|
165
|
+
const client = new EdvClient({
|
|
166
|
+
id: remoteConfig.id,
|
|
167
|
+
keyAgreementKey,
|
|
168
|
+
hmac,
|
|
169
|
+
cipherVersion: 'fips'
|
|
170
|
+
})
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
You can specify a url when you create and register a new EDV configuration:
|
|
174
|
+
|
|
175
|
+
```js
|
|
176
|
+
// TODO: explain EDV service must be able to authenticate user
|
|
177
|
+
const controller = 'account id (or DID if using zcaps) goes here'
|
|
178
|
+
|
|
179
|
+
const config = {
|
|
180
|
+
// on init the sequence must be 0 and is required
|
|
181
|
+
sequence: 0,
|
|
182
|
+
controller,
|
|
183
|
+
// TODO: Explain what 'referenceId' is
|
|
184
|
+
referenceId: 'primary',
|
|
185
|
+
keyAgreementKey: { id: keyAgreementKey.id, type: keyAgreementKey.type },
|
|
186
|
+
hmac: { id: hmac.id, type: hmac.type }
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// sends a POST request to the remote service to create an EDV
|
|
190
|
+
const remoteConfig = await EdvClient.createEdv({
|
|
191
|
+
url: 'https://server.example/edvs',
|
|
192
|
+
config
|
|
193
|
+
// must pass `invocationSigner` and optional `capability` if `controller`
|
|
194
|
+
// is a DID
|
|
195
|
+
/* invocationSigner, capability */
|
|
196
|
+
})
|
|
197
|
+
|
|
198
|
+
// connect to the new EDV via a `EdvClient`
|
|
199
|
+
const client = new EdvClient({ id: remoteConfig.id, keyAgreementKey, hmac })
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### Loading a saved EDV config
|
|
203
|
+
|
|
204
|
+
If you have previously registered an EDV config (via `createEdv()`), and you
|
|
205
|
+
know its `id`, you can fetch its config via `get()`:
|
|
206
|
+
|
|
207
|
+
```js
|
|
208
|
+
// registered config
|
|
209
|
+
const { id } = await EdvClient.createEdv({ config })
|
|
210
|
+
|
|
211
|
+
// later, it can be fetched via the id
|
|
212
|
+
const remoteConfig = await EdvClient.getConfig({ id })
|
|
213
|
+
|
|
214
|
+
// connect to the existing EDV via an `EdvClient` instance
|
|
215
|
+
const client = new EdvClient({ id: remoteConfig.id, keyAgreementKey, hmac })
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
If you know a controller/`accountId` but do not know a specific EDV `id`, you
|
|
219
|
+
can create a client for an EDV by a controller-scoped custom `referenceId`:
|
|
220
|
+
|
|
221
|
+
```js
|
|
222
|
+
// get the account's 'primary' EDV config to connect to the EDV
|
|
223
|
+
// note that a referenceId can be any string but must be unique per controller
|
|
224
|
+
const config = await EdvClient.findConfig({
|
|
225
|
+
controller: accountId,
|
|
226
|
+
referenceId: 'primary'
|
|
227
|
+
})
|
|
228
|
+
const client = new EdvClient({ id: config.id, keyAgreementKey, hmac })
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
### Using a EdvClient instance for document storage
|
|
232
|
+
|
|
233
|
+
See the API section below.
|
|
234
|
+
|
|
235
|
+
## API
|
|
236
|
+
|
|
237
|
+
### `EdvClient`
|
|
238
|
+
|
|
239
|
+
#### `constructor`
|
|
240
|
+
|
|
241
|
+
#### `insert`
|
|
242
|
+
|
|
243
|
+
#### `get`
|
|
244
|
+
|
|
245
|
+
#### `update`
|
|
246
|
+
|
|
247
|
+
#### `delete`
|
|
248
|
+
|
|
249
|
+
#### `find`
|
|
250
|
+
|
|
251
|
+
#### `ensureIndex`
|
|
252
|
+
|
|
253
|
+
#### `updateIndex`
|
|
254
|
+
|
|
255
|
+
## Contribute
|
|
256
|
+
|
|
257
|
+
Please follow the existing code style.
|
|
258
|
+
|
|
259
|
+
PRs accepted.
|
|
260
|
+
|
|
261
|
+
If editing the Readme, please conform to the
|
|
262
|
+
[standard-readme](https://github.com/RichardLitt/standard-readme) specification.
|
|
263
|
+
|
|
264
|
+
## License
|
|
265
|
+
|
|
266
|
+
[BSD-3-Clause](LICENSE) Copyright 2019-2025 Digital Bazaar, Inc.
|
|
267
|
+
|
|
268
|
+
Commercial support is available by contacting
|
|
269
|
+
[Digital Bazaar](https://digitalbazaar.com/) <support@digitalbazaar.com>.
|
|
270
|
+
|
|
271
|
+
[`@noble/hashes`]: https://github.com/paulmillr/noble-hashes
|
|
272
|
+
[`react-native-get-random-values`]:
|
|
273
|
+
https://github.com/LinusU/react-native-get-random-values
|
|
274
|
+
[Streams API]: https://developer.mozilla.org/en-US/docs/Web/API/Streams_API
|
|
275
|
+
[Web Crypto API]:
|
|
276
|
+
https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API
|