@interop/was-client 0.8.0 → 0.9.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/README.md +59 -88
- package/dist/Collection.d.ts +17 -4
- package/dist/Collection.d.ts.map +1 -1
- package/dist/Collection.js +26 -10
- package/dist/Collection.js.map +1 -1
- package/dist/Resource.d.ts +12 -3
- package/dist/Resource.d.ts.map +1 -1
- package/dist/Resource.js +19 -3
- package/dist/Resource.js.map +1 -1
- package/dist/Space.d.ts +6 -1
- package/dist/Space.d.ts.map +1 -1
- package/dist/Space.js +14 -2
- package/dist/Space.js.map +1 -1
- package/dist/WasClient.d.ts +7 -3
- package/dist/WasClient.d.ts.map +1 -1
- package/dist/WasClient.js +7 -3
- package/dist/WasClient.js.map +1 -1
- package/dist/codec.d.ts +34 -13
- package/dist/codec.d.ts.map +1 -1
- package/dist/edv/EdvCodec.d.ts +21 -11
- package/dist/edv/EdvCodec.d.ts.map +1 -1
- package/dist/edv/EdvCodec.js +28 -13
- package/dist/edv/EdvCodec.js.map +1 -1
- package/dist/edv/index.d.ts +5 -4
- package/dist/edv/index.d.ts.map +1 -1
- package/dist/edv/index.js +4 -4
- package/dist/edv/index.js.map +1 -1
- package/dist/errors.d.ts +12 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +16 -0
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/internal/codec.d.ts +14 -5
- package/dist/internal/codec.d.ts.map +1 -1
- package/dist/internal/codec.js +70 -9
- package/dist/internal/codec.js.map +1 -1
- package/dist/internal/describe.d.ts +27 -0
- package/dist/internal/describe.d.ts.map +1 -0
- package/dist/internal/describe.js +23 -0
- package/dist/internal/describe.js.map +1 -0
- package/dist/types.d.ts +26 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
- [Conditional writes (optimistic concurrency)](#conditional-writes-optimistic-concurrency)
|
|
23
23
|
- [Storage introspection: backends and quotas](#storage-introspection-backends-and-quotas)
|
|
24
24
|
- [Registering a Bring-Your-Own-Storage backend](#registering-a-bring-your-own-storage-backend)
|
|
25
|
-
- [Encrypted collections (EDV-over-WAS)](#encrypted-collections-edv-over-was)
|
|
25
|
+
- [Encrypted collections (EDV-over-WAS): pass-through encryption via the WAS client (recommended)](#encrypted-collections-edv-over-was-pass-through-encryption-via-the-was-client-recommended)
|
|
26
26
|
- [Export and import](#export-and-import)
|
|
27
27
|
- [The manual-request escape hatch](#the-manual-request-escape-hatch)
|
|
28
28
|
- [Errors and the 404/null caveat](#errors-and-the-404null-caveat)
|
|
@@ -498,38 +498,80 @@ sends no body on an in-place replace).
|
|
|
498
498
|
> can actually serve bytes depends on the server having a live provider adapter
|
|
499
499
|
> for it. Until then it is registered but inert (`status: 'registered'`).
|
|
500
500
|
|
|
501
|
-
### Encrypted collections (EDV-over-WAS)
|
|
501
|
+
### Encrypted collections (EDV-over-WAS): pass-through encryption via the WAS client (recommended)
|
|
502
502
|
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
503
|
+
This is the recommended way to use encrypted collections. For the low-level
|
|
504
|
+
alternative -- driving an `EdvClientCore` directly via `WasTransport` -- see
|
|
505
|
+
[docs/edv-client-core-usage.md](docs/edv-client-core-usage.md).
|
|
506
|
+
|
|
507
|
+
Client-side end-to-end encryption is a per-collection concern -- **not** a
|
|
508
|
+
backend feature (an encrypted document is opaque JSON any document backend
|
|
509
|
+
stores faithfully). Two things drive it, kept separate:
|
|
510
|
+
|
|
511
|
+
- **Policy** (is this collection encrypted?) is declared on the collection
|
|
512
|
+
itself: `createCollection({ encryption: { scheme: 'edv' } })` writes a
|
|
513
|
+
non-secret `encryption` marker to the Collection Description. Any authorized
|
|
514
|
+
reader -- including a delegated consumer that did **not** create the
|
|
515
|
+
collection -- discovers it by reading the Description, so it knows to decrypt.
|
|
516
|
+
- **Keys** come from an `encryption` provider you pass to `WasClient` (built
|
|
517
|
+
from the opt-in `@interop/was-client/edv` subpath, so plaintext consumers
|
|
518
|
+
never pull the crypto graph). It is a pure **keystore**: `resolveKeys` returns
|
|
519
|
+
the collection's keys, which live in your wallet. The server only ever stores
|
|
520
|
+
opaque JWE envelopes.
|
|
521
|
+
|
|
522
|
+
The ordinary `Collection`/`Resource` handles then transparently encrypt on write
|
|
523
|
+
and decrypt on read for any collection the marker (or an override) declares
|
|
524
|
+
encrypted.
|
|
512
525
|
|
|
513
526
|
```ts
|
|
514
527
|
import { WasClient } from '@interop/was-client'
|
|
515
528
|
import { createEdvEncryption } from '@interop/was-client/edv'
|
|
516
529
|
|
|
517
530
|
const encryption = createEdvEncryption({
|
|
518
|
-
//
|
|
531
|
+
// The keystore: return the collection's keys (from your wallet).
|
|
519
532
|
async resolveKeys({ spaceId, collectionId }) {
|
|
520
|
-
return { keyAgreementKey, keyResolver }
|
|
533
|
+
return { keyAgreementKey, keyResolver }
|
|
521
534
|
}
|
|
522
535
|
})
|
|
523
536
|
const was = WasClient.fromSigner({ serverUrl, signer, encryption })
|
|
524
537
|
|
|
525
|
-
|
|
538
|
+
// Declare the collection encrypted (writes the marker). The returned handle is
|
|
539
|
+
// pre-seeded, so the first write encrypts with no extra round-trip.
|
|
540
|
+
const vault = await was
|
|
541
|
+
.space(spaceId)
|
|
542
|
+
.createCollection({ id: 'vault', encryption: { scheme: 'edv' } })
|
|
526
543
|
const { id } = await vault.add({ secret: 'hello' }) // encrypted; id is an EDV id
|
|
527
544
|
const back = await vault.get(id) // { secret: 'hello' } -- decrypted
|
|
545
|
+
|
|
546
|
+
// A consumer that did not create it discovers the marker and decrypts with its
|
|
547
|
+
// own keys -- no override needed; one cached read of the Description:
|
|
548
|
+
const same = was.space(spaceId).collection('vault')
|
|
549
|
+
await same.get(id) // reads the marker, then decrypts
|
|
528
550
|
```
|
|
529
551
|
|
|
530
|
-
The switch is **
|
|
531
|
-
`
|
|
532
|
-
|
|
552
|
+
The switch is the **marker**: a handle encrypts a collection when its
|
|
553
|
+
Description declares `encryption` (resolution reads the Description once, then
|
|
554
|
+
caches -- no round-trip for plaintext-only clients or when an override is set).
|
|
555
|
+
Keys are then **required**: if the collection is declared encrypted but your
|
|
556
|
+
keystore returns no keys, reads/writes throw `EncryptionError` (fail-closed) --
|
|
557
|
+
they never silently fall back to plaintext.
|
|
558
|
+
|
|
559
|
+
**Per-handle override (escape hatch).** Pass `encryption` in the handle options
|
|
560
|
+
to force the decision and skip the Description read -- `{ scheme: 'edv' }` (keys
|
|
561
|
+
from the keystore), `{ scheme: 'edv', keys }` (keys inline), or `'plaintext'`:
|
|
562
|
+
|
|
563
|
+
```ts
|
|
564
|
+
const vault = was.space(spaceId).collection('vault', {
|
|
565
|
+
encryption: { scheme: 'edv' }
|
|
566
|
+
})
|
|
567
|
+
```
|
|
568
|
+
|
|
569
|
+
**Migrating a pre-marker vault** (created before the marker existed, keys-only):
|
|
570
|
+
re-declare it once with
|
|
571
|
+
`collection.configure({ encryption: { scheme: 'edv' } })` (the marker is
|
|
572
|
+
set-once: declaring it on a collection that lacks one is allowed, changing or
|
|
573
|
+
clearing an existing one is rejected). Until then, a per-handle override reads
|
|
574
|
+
it correctly.
|
|
533
575
|
|
|
534
576
|
Encrypted collections are a **stricter contract**, not a drop-in (documents-only
|
|
535
577
|
scope for now):
|
|
@@ -555,77 +597,6 @@ const stats = await otherSpace.import(archive)
|
|
|
555
597
|
// policiesCreated, policiesSkipped }
|
|
556
598
|
```
|
|
557
599
|
|
|
558
|
-
### Encrypted collections (EDV-over-WAS)
|
|
559
|
-
|
|
560
|
-
Client-side end-to-end encryption, where the server stores only opaque
|
|
561
|
-
ciphertext and the keys never leave the client. This is the "EDV-over-WAS"
|
|
562
|
-
layout profile (Layer 1): it maps
|
|
563
|
-
[Encrypted Data Vault](https://digitalbazaar.github.io/encrypted-data-vaults/)
|
|
564
|
-
documents onto ordinary WAS resources, so it works against **any** WAS server
|
|
565
|
-
with no server changes. It is shipped on the opt-in `@interop/was-client/edv`
|
|
566
|
-
subpath so plaintext consumers do not pull the crypto dependencies.
|
|
567
|
-
|
|
568
|
-
`WasTransport` is an `@interop/edv-client` `Transport`: pair it with
|
|
569
|
-
`EdvClientCore`, which does all encryption, decryption, and key handling
|
|
570
|
-
client-side. The WAS Collection is the vault; each encrypted document is one WAS
|
|
571
|
-
resource (its EDV id is used verbatim as the resource id).
|
|
572
|
-
|
|
573
|
-
This example assumes a WAS server is already running and you have created (or
|
|
574
|
-
have access to) a collection to use as the vault:
|
|
575
|
-
|
|
576
|
-
```ts
|
|
577
|
-
import { WasClient } from '@interop/was-client'
|
|
578
|
-
import { WasTransport } from '@interop/was-client/edv'
|
|
579
|
-
import { EdvClientCore } from '@interop/edv-client'
|
|
580
|
-
import { X25519KeyAgreementKey2020 } from '@interop/x25519-key-agreement-key'
|
|
581
|
-
|
|
582
|
-
const was = WasClient.fromSigner({ serverUrl, signer })
|
|
583
|
-
const space = await was.createSpace({ name: 'My Wallet' })
|
|
584
|
-
const collection = await space.createCollection({ id: 'vault', name: 'Vault' })
|
|
585
|
-
|
|
586
|
-
// Client-side key material (never sent to the server). In a real app these come
|
|
587
|
-
// from the wallet's key store; here we generate a key-agreement key.
|
|
588
|
-
const kak = await X25519KeyAgreementKey2020.generate({
|
|
589
|
-
controller: was.controllerDid
|
|
590
|
-
})
|
|
591
|
-
const keyResolver = async ({ id }: { id: string }) => {
|
|
592
|
-
if (id !== kak.id) throw new Error(`Unknown key id "${id}".`)
|
|
593
|
-
return {
|
|
594
|
-
id: kak.id,
|
|
595
|
-
type: kak.type,
|
|
596
|
-
publicKeyMultibase: kak.publicKeyMultibase
|
|
597
|
-
}
|
|
598
|
-
}
|
|
599
|
-
|
|
600
|
-
const edv = new EdvClientCore({ keyAgreementKey: kak, keyResolver })
|
|
601
|
-
const transport = new WasTransport({
|
|
602
|
-
was,
|
|
603
|
-
spaceId: space.id,
|
|
604
|
-
collectionId: collection.id
|
|
605
|
-
})
|
|
606
|
-
|
|
607
|
-
// Encrypt + write: the server stores a JWE envelope, not the cleartext.
|
|
608
|
-
const doc = await edv.insert({ doc: { content: { secret: 42 } }, transport })
|
|
609
|
-
|
|
610
|
-
// Read + decrypt:
|
|
611
|
-
const decrypted = await edv.get({ id: doc.id, transport })
|
|
612
|
-
console.log(decrypted.content) // { secret: 42 }
|
|
613
|
-
```
|
|
614
|
-
|
|
615
|
-
Scope and caveats (this is the first, documents-only increment):
|
|
616
|
-
|
|
617
|
-
- **Documents only.** `insert` / `update` / `get` are supported. Blinded `find`
|
|
618
|
-
/ `count` / index updates and chunked blob streams throw -- they need
|
|
619
|
-
server-side EDV affordances (a blinded `/query` endpoint, the
|
|
620
|
-
`/{id}/chunks/{n}` sub-segment) a plaintext WAS server does not provide.
|
|
621
|
-
- **Advisory `sequence`.** Without server-side conditional writes, a stale
|
|
622
|
-
`update` is not rejected (last-writer-wins). Safe for single-writer use.
|
|
623
|
-
- **Content type.** Envelopes are stored as `application/json` by default so any
|
|
624
|
-
WAS server accepts them. The preferred marker `application/edv+json` (exported
|
|
625
|
-
as `EDV_CONTENT_TYPE`) needs the server to register an `application/*+json`
|
|
626
|
-
content-type parser -- the reference was-teaching-server does; pass
|
|
627
|
-
`contentType: EDV_CONTENT_TYPE` to opt in.
|
|
628
|
-
|
|
629
600
|
### The manual-request escape hatch
|
|
630
601
|
|
|
631
602
|
`was.request(...)` mirrors ezcap's generic `request()` for hand-built calls. As
|
package/dist/Collection.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { ClientContext } from './internal/request.js';
|
|
2
2
|
import { Resource } from './Resource.js';
|
|
3
|
-
import type { AddResult, BackendDescriptor, BackendReference, BackendUsage, CollectionDescription, GrantOptions, HandleOptions, IDelegatedZcap, IZcap, Json, LinkSet, PolicyDocument, CollectionResourcesList } from './types.js';
|
|
3
|
+
import type { AddResult, BackendDescriptor, BackendReference, BackendUsage, CollectionDescription, CollectionEncryption, EncryptionOverride, GrantOptions, HandleOptions, IDelegatedZcap, IZcap, Json, LinkSet, PolicyDocument, CollectionResourcesList } from './types.js';
|
|
4
4
|
export declare class Collection {
|
|
5
5
|
readonly spaceId: string;
|
|
6
6
|
readonly id: string;
|
|
7
7
|
private readonly _context;
|
|
8
8
|
private readonly _capability?;
|
|
9
|
+
private readonly _encryptionOverride?;
|
|
9
10
|
private _codecPromise?;
|
|
10
11
|
/**
|
|
11
12
|
* @param options {object}
|
|
@@ -14,20 +15,27 @@ export declare class Collection {
|
|
|
14
15
|
* @param options.spaceId {string}
|
|
15
16
|
* @param options.collectionId {string}
|
|
16
17
|
* @param [options.capability] {IZcap} - capability attached to every request
|
|
18
|
+
* @param [options.encryption] {EncryptionOverride} - per-handle encryption
|
|
19
|
+
* override; wins over the Collection's declared marker and skips the
|
|
20
|
+
* marker-discovery round-trip
|
|
17
21
|
*/
|
|
18
|
-
constructor({ context, spaceId, collectionId, capability }: {
|
|
22
|
+
constructor({ context, spaceId, collectionId, capability, encryption }: {
|
|
19
23
|
context: ClientContext;
|
|
20
24
|
spaceId: string;
|
|
21
25
|
collectionId: string;
|
|
22
26
|
capability?: IZcap;
|
|
27
|
+
encryption?: EncryptionOverride;
|
|
23
28
|
});
|
|
24
29
|
private get _path();
|
|
25
30
|
private get _itemsPath();
|
|
26
31
|
/**
|
|
27
32
|
* Resolves (once, then caches) the codec for this collection's reads and
|
|
28
33
|
* writes: the identity codec for a plaintext collection, or the encrypting
|
|
29
|
-
* codec when
|
|
30
|
-
*
|
|
34
|
+
* codec when this collection is declared encrypted -- by a per-handle override
|
|
35
|
+
* or its `encryption` marker -- and the client's keystore supplies its keys.
|
|
36
|
+
* An encrypted collection the client cannot key for fails closed (throws), and
|
|
37
|
+
* the marker read happens at most once per handle (memoized here) -- a fresh
|
|
38
|
+
* handle to the same collection re-reads it, so retain the handle to reuse it.
|
|
31
39
|
*
|
|
32
40
|
* @returns {Promise<ResourceCodec>}
|
|
33
41
|
*/
|
|
@@ -47,11 +55,16 @@ export declare class Collection {
|
|
|
47
55
|
* @param desc {object}
|
|
48
56
|
* @param [desc.name] {string}
|
|
49
57
|
* @param [desc.backend] {BackendReference}
|
|
58
|
+
* @param [desc.encryption] {CollectionEncryption} declare the client-side
|
|
59
|
+
* encryption marker. Set-once on the server: it may be added to a Collection
|
|
60
|
+
* that lacks one, but changing/clearing an existing marker is rejected
|
|
61
|
+
* (`ConflictError`, `encryption-immutable`).
|
|
50
62
|
* @returns {Promise<CollectionDescription>}
|
|
51
63
|
*/
|
|
52
64
|
configure(desc: {
|
|
53
65
|
name?: string;
|
|
54
66
|
backend?: BackendReference;
|
|
67
|
+
encryption?: CollectionEncryption;
|
|
55
68
|
}): Promise<CollectionDescription>;
|
|
56
69
|
/**
|
|
57
70
|
* Deletes the whole collection. Idempotent. To delete a single resource, use
|
package/dist/Collection.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Collection.d.ts","sourceRoot":"","sources":["../src/Collection.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;
|
|
1
|
+
{"version":3,"file":"Collection.d.ts","sourceRoot":"","sources":["../src/Collection.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAM1D,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,KAAK,EACV,SAAS,EACT,iBAAiB,EACjB,gBAAgB,EAChB,YAAY,EACZ,qBAAqB,EACrB,oBAAoB,EACpB,kBAAkB,EAClB,YAAY,EACZ,aAAa,EACb,cAAc,EACd,KAAK,EACL,IAAI,EACJ,OAAO,EACP,cAAc,EACd,uBAAuB,EACxB,MAAM,YAAY,CAAA;AAEnB,q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/reserved.js';
|
|
|
11
11
|
import { delegateGrant } from './internal/grant.js';
|
|
12
12
|
import { send } from './internal/request.js';
|
|
13
13
|
import { resolveCodec } from './internal/codec.js';
|
|
14
|
+
import { describeCollection } from './internal/describe.js';
|
|
14
15
|
import { writeHeaders, readEtag } from './internal/conditional.js';
|
|
15
16
|
import { Resource } from './Resource.js';
|
|
16
17
|
export class Collection {
|
|
@@ -18,6 +19,7 @@ export class Collection {
|
|
|
18
19
|
id;
|
|
19
20
|
_context;
|
|
20
21
|
_capability;
|
|
22
|
+
_encryptionOverride;
|
|
21
23
|
_codecPromise;
|
|
22
24
|
/**
|
|
23
25
|
* @param options {object}
|
|
@@ -26,12 +28,16 @@ export class Collection {
|
|
|
26
28
|
* @param options.spaceId {string}
|
|
27
29
|
* @param options.collectionId {string}
|
|
28
30
|
* @param [options.capability] {IZcap} - capability attached to every request
|
|
31
|
+
* @param [options.encryption] {EncryptionOverride} - per-handle encryption
|
|
32
|
+
* override; wins over the Collection's declared marker and skips the
|
|
33
|
+
* marker-discovery round-trip
|
|
29
34
|
*/
|
|
30
|
-
constructor({ context, spaceId, collectionId, capability }) {
|
|
35
|
+
constructor({ context, spaceId, collectionId, capability, encryption }) {
|
|
31
36
|
this._context = context;
|
|
32
37
|
this.spaceId = spaceId;
|
|
33
38
|
this.id = collectionId;
|
|
34
39
|
this._capability = capability;
|
|
40
|
+
this._encryptionOverride = encryption;
|
|
35
41
|
}
|
|
36
42
|
get _path() {
|
|
37
43
|
return collectionPath(this.spaceId, this.id);
|
|
@@ -42,15 +48,20 @@ export class Collection {
|
|
|
42
48
|
/**
|
|
43
49
|
* Resolves (once, then caches) the codec for this collection's reads and
|
|
44
50
|
* writes: the identity codec for a plaintext collection, or the encrypting
|
|
45
|
-
* codec when
|
|
46
|
-
*
|
|
51
|
+
* codec when this collection is declared encrypted -- by a per-handle override
|
|
52
|
+
* or its `encryption` marker -- and the client's keystore supplies its keys.
|
|
53
|
+
* An encrypted collection the client cannot key for fails closed (throws), and
|
|
54
|
+
* the marker read happens at most once per handle (memoized here) -- a fresh
|
|
55
|
+
* handle to the same collection re-reads it, so retain the handle to reuse it.
|
|
47
56
|
*
|
|
48
57
|
* @returns {Promise<ResourceCodec>}
|
|
49
58
|
*/
|
|
50
59
|
_codec() {
|
|
51
60
|
return (this._codecPromise ??= resolveCodec(this._context, {
|
|
52
61
|
spaceId: this.spaceId,
|
|
53
|
-
collectionId: this.id
|
|
62
|
+
collectionId: this.id,
|
|
63
|
+
override: this._encryptionOverride,
|
|
64
|
+
readMarker: async () => (await this.describe())?.encryption
|
|
54
65
|
}));
|
|
55
66
|
}
|
|
56
67
|
/**
|
|
@@ -61,13 +72,11 @@ export class Collection {
|
|
|
61
72
|
* @returns {Promise<CollectionDescription | null>}
|
|
62
73
|
*/
|
|
63
74
|
async describe() {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
capability: this._capability
|
|
68
|
-
read: true
|
|
75
|
+
return describeCollection(this._context, {
|
|
76
|
+
spaceId: this.spaceId,
|
|
77
|
+
collectionId: this.id,
|
|
78
|
+
capability: this._capability
|
|
69
79
|
});
|
|
70
|
-
return response === null ? null : response.data;
|
|
71
80
|
}
|
|
72
81
|
/**
|
|
73
82
|
* Creates or updates the collection by id (upsert). Merges the given fields
|
|
@@ -76,6 +85,10 @@ export class Collection {
|
|
|
76
85
|
* @param desc {object}
|
|
77
86
|
* @param [desc.name] {string}
|
|
78
87
|
* @param [desc.backend] {BackendReference}
|
|
88
|
+
* @param [desc.encryption] {CollectionEncryption} declare the client-side
|
|
89
|
+
* encryption marker. Set-once on the server: it may be added to a Collection
|
|
90
|
+
* that lacks one, but changing/clearing an existing marker is rejected
|
|
91
|
+
* (`ConflictError`, `encryption-immutable`).
|
|
79
92
|
* @returns {Promise<CollectionDescription>}
|
|
80
93
|
*/
|
|
81
94
|
async configure(desc) {
|
|
@@ -86,6 +99,9 @@ export class Collection {
|
|
|
86
99
|
if (desc.backend) {
|
|
87
100
|
body.backend = desc.backend;
|
|
88
101
|
}
|
|
102
|
+
if (desc.encryption) {
|
|
103
|
+
body.encryption = desc.encryption;
|
|
104
|
+
}
|
|
89
105
|
await send(this._context, {
|
|
90
106
|
path: this._path,
|
|
91
107
|
method: 'PUT',
|
package/dist/Collection.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Collection.js","sourceRoot":"","sources":["../src/Collection.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;GAIG;AACH,OAAO,EACL,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,EACf,YAAY,EACZ,KAAK,EACN,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAEnD,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAA;AAElE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"Collection.js","sourceRoot":"","sources":["../src/Collection.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;GAIG;AACH,OAAO,EACL,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,EACf,YAAY,EACZ,KAAK,EACN,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAEnD,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,EAAE,k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CAAC,OAAO,EAAE,IAAI,CAAC,EAAE,CAAC;YAC5C,MAAM,EAAE,KAAK;YACb,UAAU,EAAE,IAAI,CAAC,WAAW;YAC5B,IAAI,EAAE,IAAI;SACX,CAAC,CAAA;QACF,OAAO,QAAQ,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAE,QAAQ,CAAC,IAAqB,CAAA;IACnE,CAAC;CACF"}
|
package/dist/Resource.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ClientContext } from './internal/request.js';
|
|
2
2
|
import type { ResourceCodec } from './codec.js';
|
|
3
|
-
import type { IZcap, Json, PolicyDocument, ResourceMetadata, ResourceMetadataCustom } from './types.js';
|
|
3
|
+
import type { EncryptionOverride, IZcap, Json, PolicyDocument, ResourceMetadata, ResourceMetadataCustom } from './types.js';
|
|
4
4
|
export declare class Resource {
|
|
5
5
|
readonly spaceId: string;
|
|
6
6
|
readonly collectionId: string;
|
|
@@ -8,6 +8,7 @@ export declare class Resource {
|
|
|
8
8
|
private readonly _context;
|
|
9
9
|
private readonly _capability?;
|
|
10
10
|
private readonly _codecThunk?;
|
|
11
|
+
private readonly _encryptionOverride?;
|
|
11
12
|
private _codecPromise?;
|
|
12
13
|
/**
|
|
13
14
|
* @param options {object}
|
|
@@ -20,20 +21,28 @@ export declare class Resource {
|
|
|
20
21
|
* codec, so a resource handle obtained via `collection.resource(id)` does
|
|
21
22
|
* not repeat the backend() round-trip. A standalone resource resolves its
|
|
22
23
|
* own.
|
|
24
|
+
* @param [options.encryption] {EncryptionOverride} per-handle encryption
|
|
25
|
+
* override for a standalone resource (ignored when `codec` is supplied --
|
|
26
|
+
* the shared parent codec wins)
|
|
23
27
|
*/
|
|
24
|
-
constructor({ context, spaceId, collectionId, resourceId, capability, codec }: {
|
|
28
|
+
constructor({ context, spaceId, collectionId, resourceId, capability, codec, encryption }: {
|
|
25
29
|
context: ClientContext;
|
|
26
30
|
spaceId: string;
|
|
27
31
|
collectionId: string;
|
|
28
32
|
resourceId: string;
|
|
29
33
|
capability?: IZcap;
|
|
30
34
|
codec?: () => Promise<ResourceCodec>;
|
|
35
|
+
encryption?: EncryptionOverride;
|
|
31
36
|
});
|
|
32
37
|
private get _path();
|
|
33
38
|
/**
|
|
34
39
|
* Resolves (once, then caches) the codec for this resource: the parent
|
|
35
40
|
* collection's shared codec when this handle came from
|
|
36
|
-
* `collection.resource(id)`, otherwise one resolved for its own collection.
|
|
41
|
+
* `collection.resource(id)`, otherwise one resolved for its own collection. A
|
|
42
|
+
* standalone resource discovers its collection's `encryption` marker (one GET
|
|
43
|
+
* on the collection, cached per handle) unless a per-handle override is set,
|
|
44
|
+
* and fails closed if it cannot key an encrypted collection. A fresh
|
|
45
|
+
* standalone handle re-reads the marker, so retain the handle to reuse it.
|
|
37
46
|
*
|
|
38
47
|
* @returns {Promise<ResourceCodec>}
|
|
39
48
|
*/
|
package/dist/Resource.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Resource.d.ts","sourceRoot":"","sources":["../src/Resource.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;
|
|
1
|
+
{"version":3,"file":"Resource.d.ts","sourceRoot":"","sources":["../src/Resource.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAK1D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAE/C,OAAO,KAAK,EAEV,kBAAkB,EAClB,KAAK,EACL,IAAI,EACJ,cAAc,EACd,gBAAgB,EAChB,sBAAsB,EACvB,MAAM,YAAY,CAAA;AAEnB,qBAAa,QAAQ;IACnB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;IAC7B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IAEnB,OAAO,CAAC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,MAAM,CAAC,OAAO,GAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAY/D,OAAO,KAAK,SAAS,GAEpB;IAED;;;;;;;;;;;OAWG;IACG,IAAI,IAAI,OAAO,CAAC,CAAC,gBAAgB,GAAG;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,GAAG,IAAI,CAAC;IAepE;;;;;;;;;;;;;;OAcG;IACG,OAAO,CAAC,IAAI,GAAE;QAAE,MAAM,CAAC,EAAE,sBAAsB,CAAA;KAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAiB5E;;;;;;OAMG;IACG,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAK1C;;;;;;OAMG;IACG,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAK1D,OAAO,KAAK,WAAW,GAEtB;IAED;;;;;;OAMG;IACG,SAAS,IAAI,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC;IAUjD;;;;;OAKG;IACG,SAAS,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAStD;;;;;OAKG;IACG,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAIhC;;;;OAIG;IACG,QAAQ,IAAI,OAAO,CAAC,OAAO,CAAC;IAKlC;;;;;OAKG;IACG,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;CAQnC"}
|
package/dist/Resource.js
CHANGED
|
@@ -2,6 +2,7 @@ import { resourcePath, resourcePolicy, resourceMeta } from './internal/paths.js'
|
|
|
2
2
|
import { assertNotReserved } from './internal/reserved.js';
|
|
3
3
|
import { send } from './internal/request.js';
|
|
4
4
|
import { resolveCodec } from './internal/codec.js';
|
|
5
|
+
import { describeCollection } from './internal/describe.js';
|
|
5
6
|
import { writeHeaders, readEtag } from './internal/conditional.js';
|
|
6
7
|
import { ValidationError } from './errors.js';
|
|
7
8
|
export class Resource {
|
|
@@ -11,6 +12,7 @@ export class Resource {
|
|
|
11
12
|
_context;
|
|
12
13
|
_capability;
|
|
13
14
|
_codecThunk;
|
|
15
|
+
_encryptionOverride;
|
|
14
16
|
_codecPromise;
|
|
15
17
|
/**
|
|
16
18
|
* @param options {object}
|
|
@@ -23,14 +25,18 @@ export class Resource {
|
|
|
23
25
|
* codec, so a resource handle obtained via `collection.resource(id)` does
|
|
24
26
|
* not repeat the backend() round-trip. A standalone resource resolves its
|
|
25
27
|
* own.
|
|
28
|
+
* @param [options.encryption] {EncryptionOverride} per-handle encryption
|
|
29
|
+
* override for a standalone resource (ignored when `codec` is supplied --
|
|
30
|
+
* the shared parent codec wins)
|
|
26
31
|
*/
|
|
27
|
-
constructor({ context, spaceId, collectionId, resourceId, capability, codec }) {
|
|
32
|
+
constructor({ context, spaceId, collectionId, resourceId, capability, codec, encryption }) {
|
|
28
33
|
this._context = context;
|
|
29
34
|
this.spaceId = spaceId;
|
|
30
35
|
this.collectionId = collectionId;
|
|
31
36
|
this.id = resourceId;
|
|
32
37
|
this._capability = capability;
|
|
33
38
|
this._codecThunk = codec;
|
|
39
|
+
this._encryptionOverride = encryption;
|
|
34
40
|
}
|
|
35
41
|
get _path() {
|
|
36
42
|
return resourcePath(this.spaceId, this.collectionId, this.id);
|
|
@@ -38,7 +44,11 @@ export class Resource {
|
|
|
38
44
|
/**
|
|
39
45
|
* Resolves (once, then caches) the codec for this resource: the parent
|
|
40
46
|
* collection's shared codec when this handle came from
|
|
41
|
-
* `collection.resource(id)`, otherwise one resolved for its own collection.
|
|
47
|
+
* `collection.resource(id)`, otherwise one resolved for its own collection. A
|
|
48
|
+
* standalone resource discovers its collection's `encryption` marker (one GET
|
|
49
|
+
* on the collection, cached per handle) unless a per-handle override is set,
|
|
50
|
+
* and fails closed if it cannot key an encrypted collection. A fresh
|
|
51
|
+
* standalone handle re-reads the marker, so retain the handle to reuse it.
|
|
42
52
|
*
|
|
43
53
|
* @returns {Promise<ResourceCodec>}
|
|
44
54
|
*/
|
|
@@ -47,7 +57,13 @@ export class Resource {
|
|
|
47
57
|
? this._codecThunk()
|
|
48
58
|
: resolveCodec(this._context, {
|
|
49
59
|
spaceId: this.spaceId,
|
|
50
|
-
collectionId: this.collectionId
|
|
60
|
+
collectionId: this.collectionId,
|
|
61
|
+
override: this._encryptionOverride,
|
|
62
|
+
readMarker: async () => (await describeCollection(this._context, {
|
|
63
|
+
spaceId: this.spaceId,
|
|
64
|
+
collectionId: this.collectionId,
|
|
65
|
+
capability: this._capability
|
|
66
|
+
}))?.encryption
|
|
51
67
|
}));
|
|
52
68
|
}
|
|
53
69
|
/**
|
package/dist/Resource.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Resource.js","sourceRoot":"","sources":["../src/Resource.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAChF,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAE1D,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAA;AAElE,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"Resource.js","sourceRoot":"","sources":["../src/Resource.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAChF,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAE1D,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,EA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C,WAAW;YAC5B,UAAU,EAAE,IAAI;SACjB,CAAC,CAAA;IACJ,CAAC;CACF"}
|
package/dist/Space.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ClientContext } from './internal/request.js';
|
|
2
2
|
import { Collection } from './Collection.js';
|
|
3
|
-
import type { BackendDescriptor, BackendReference, BackendRegistration, CollectionsList, GrantOptions, HandleOptions, IDelegatedZcap, IZcap, ImportStats, LinkSet, PolicyDocument, SpaceDescription, SpaceQuotaReport } from './types.js';
|
|
3
|
+
import type { BackendDescriptor, BackendReference, BackendRegistration, CollectionEncryption, CollectionsList, GrantOptions, HandleOptions, IDelegatedZcap, IZcap, ImportStats, LinkSet, PolicyDocument, SpaceDescription, SpaceQuotaReport } from './types.js';
|
|
4
4
|
export declare class Space {
|
|
5
5
|
readonly id: string;
|
|
6
6
|
private readonly _context;
|
|
@@ -60,12 +60,17 @@ export declare class Space {
|
|
|
60
60
|
* @param [desc.id] {string}
|
|
61
61
|
* @param [desc.name] {string}
|
|
62
62
|
* @param [desc.backend] {BackendReference}
|
|
63
|
+
* @param [desc.encryption] {CollectionEncryption} declare the collection
|
|
64
|
+
* client-side encrypted (e.g. `{ scheme: 'edv' }`). The returned handle is
|
|
65
|
+
* pre-seeded with a matching encryption override, so the immediate next
|
|
66
|
+
* write encrypts without a marker-discovery round-trip.
|
|
63
67
|
* @returns {Promise<Collection>}
|
|
64
68
|
*/
|
|
65
69
|
createCollection(desc?: {
|
|
66
70
|
id?: string;
|
|
67
71
|
name?: string;
|
|
68
72
|
backend?: BackendReference;
|
|
73
|
+
encryption?: CollectionEncryption;
|
|
69
74
|
}): Promise<Collection>;
|
|
70
75
|
/**
|
|
71
76
|
* Lists the collections in the space. Returns `null` if the space is missing
|
package/dist/Space.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Space.d.ts","sourceRoot":"","sources":["../src/Space.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK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package/dist/Space.js
CHANGED
|
@@ -99,7 +99,8 @@ export class Space {
|
|
|
99
99
|
context: this._context,
|
|
100
100
|
spaceId: this.id,
|
|
101
101
|
collectionId,
|
|
102
|
-
capability: options.capability ?? this._capability
|
|
102
|
+
capability: options.capability ?? this._capability,
|
|
103
|
+
encryption: options.encryption
|
|
103
104
|
});
|
|
104
105
|
}
|
|
105
106
|
/**
|
|
@@ -110,6 +111,10 @@ export class Space {
|
|
|
110
111
|
* @param [desc.id] {string}
|
|
111
112
|
* @param [desc.name] {string}
|
|
112
113
|
* @param [desc.backend] {BackendReference}
|
|
114
|
+
* @param [desc.encryption] {CollectionEncryption} declare the collection
|
|
115
|
+
* client-side encrypted (e.g. `{ scheme: 'edv' }`). The returned handle is
|
|
116
|
+
* pre-seeded with a matching encryption override, so the immediate next
|
|
117
|
+
* write encrypts without a marker-discovery round-trip.
|
|
113
118
|
* @returns {Promise<Collection>}
|
|
114
119
|
*/
|
|
115
120
|
async createCollection(desc = {}) {
|
|
@@ -126,6 +131,9 @@ export class Space {
|
|
|
126
131
|
if (desc.backend) {
|
|
127
132
|
body.backend = desc.backend;
|
|
128
133
|
}
|
|
134
|
+
if (desc.encryption) {
|
|
135
|
+
body.encryption = desc.encryption;
|
|
136
|
+
}
|
|
129
137
|
const response = await send(this._context, {
|
|
130
138
|
path: spaceItems(this.id),
|
|
131
139
|
method: 'POST',
|
|
@@ -134,7 +142,11 @@ export class Space {
|
|
|
134
142
|
});
|
|
135
143
|
const created = response
|
|
136
144
|
.data;
|
|
137
|
-
|
|
145
|
+
// Pre-seed the handle with an override matching the just-declared scheme so
|
|
146
|
+
// the first write encrypts immediately (keys come from the keystore); no
|
|
147
|
+
// describe() round-trip needed before the marker is locally known. A
|
|
148
|
+
// `CollectionEncryption` marker is itself a valid `EncryptionOverride`.
|
|
149
|
+
return this.collection(created.id, { encryption: desc.encryption });
|
|
138
150
|
}
|
|
139
151
|
/**
|
|
140
152
|
* Lists the collections in the space. Returns `null` if the space is missing
|