@interop/was-client 0.13.3 → 0.14.1
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 +33 -0
- package/dist/Collection.d.ts +58 -0
- package/dist/Collection.d.ts.map +1 -1
- package/dist/Collection.js +106 -13
- package/dist/Collection.js.map +1 -1
- package/dist/Resource.d.ts +8 -0
- package/dist/Resource.d.ts.map +1 -1
- package/dist/Resource.js +52 -34
- package/dist/Resource.js.map +1 -1
- package/dist/Space.d.ts +42 -1
- package/dist/Space.d.ts.map +1 -1
- package/dist/Space.js +55 -2
- package/dist/Space.js.map +1 -1
- package/dist/WasClient.d.ts +15 -0
- package/dist/WasClient.d.ts.map +1 -1
- package/dist/WasClient.js +52 -21
- package/dist/WasClient.js.map +1 -1
- package/dist/codec.d.ts +14 -11
- package/dist/codec.d.ts.map +1 -1
- package/dist/edv/EdvCodec.d.ts +34 -56
- package/dist/edv/EdvCodec.d.ts.map +1 -1
- package/dist/edv/EdvCodec.js +155 -52
- package/dist/edv/EdvCodec.js.map +1 -1
- package/dist/edv/WasTransport.d.ts +84 -19
- package/dist/edv/WasTransport.d.ts.map +1 -1
- package/dist/edv/WasTransport.js +198 -44
- package/dist/edv/WasTransport.js.map +1 -1
- package/dist/edv/epochCrypto.d.ts +101 -0
- package/dist/edv/epochCrypto.d.ts.map +1 -0
- package/dist/edv/epochCrypto.js +211 -0
- package/dist/edv/epochCrypto.js.map +1 -0
- package/dist/edv/epochKeys.d.ts +57 -0
- package/dist/edv/epochKeys.d.ts.map +1 -0
- package/dist/edv/epochKeys.js +132 -0
- package/dist/edv/epochKeys.js.map +1 -0
- package/dist/edv/index.d.ts +8 -0
- package/dist/edv/index.d.ts.map +1 -1
- package/dist/edv/index.js +7 -0
- package/dist/edv/index.js.map +1 -1
- package/dist/edv/recipients.d.ts +122 -0
- package/dist/edv/recipients.d.ts.map +1 -0
- package/dist/edv/recipients.js +265 -0
- package/dist/edv/recipients.js.map +1 -0
- package/dist/errors.d.ts +31 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +37 -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.map +1 -1
- package/dist/internal/codec.js +12 -4
- package/dist/internal/codec.js.map +1 -1
- package/dist/internal/conditional.d.ts +6 -1
- package/dist/internal/conditional.d.ts.map +1 -1
- package/dist/internal/conditional.js +8 -1
- package/dist/internal/conditional.js.map +1 -1
- package/dist/internal/content.d.ts +2 -2
- package/dist/internal/content.d.ts.map +1 -1
- package/dist/internal/content.js +16 -6
- package/dist/internal/content.js.map +1 -1
- package/dist/internal/grant.d.ts +11 -1
- package/dist/internal/grant.d.ts.map +1 -1
- package/dist/internal/grant.js +32 -3
- package/dist/internal/grant.js.map +1 -1
- package/dist/internal/paths.d.ts +28 -0
- package/dist/internal/paths.d.ts.map +1 -1
- package/dist/internal/paths.js +52 -1
- package/dist/internal/paths.js.map +1 -1
- package/dist/internal/revoke.d.ts +34 -0
- package/dist/internal/revoke.d.ts.map +1 -0
- package/dist/internal/revoke.js +106 -0
- package/dist/internal/revoke.js.map +1 -0
- package/dist/internal/write.d.ts.map +1 -1
- package/dist/internal/write.js +5 -1
- package/dist/internal/write.js.map +1 -1
- package/dist/types.d.ts +77 -5
- package/dist/types.d.ts.map +1 -1
- package/package.json +7 -5
package/dist/Space.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { spacePath, spaceItems, spaceCollections, spaceExport, spaceImport, spaceBackends, registeredBackend, spaceQuotas, spacePolicy, spaceLinkset } from './internal/paths.js';
|
|
2
2
|
import { assertNotReserved } from './internal/reserved.js';
|
|
3
3
|
import { delegateGrantAt } from './internal/grant.js';
|
|
4
|
+
import { submitRevocation } from './internal/revoke.js';
|
|
4
5
|
import { send, readData } from './internal/request.js';
|
|
5
|
-
import { WasServerError } from './errors.js';
|
|
6
|
+
import { ValidationError, WasServerError } from './errors.js';
|
|
6
7
|
import { createdId, dataOrNull, toPlainBytes } from './internal/content.js';
|
|
7
8
|
import { readPolicy, writePolicy, deletePolicy } from './internal/policy.js';
|
|
8
9
|
import { Collection } from './Collection.js';
|
|
@@ -43,13 +44,36 @@ export class Space {
|
|
|
43
44
|
* Creates or updates the space by id (upsert). Merges the given fields over
|
|
44
45
|
* the current description; `controller` defaults to the wrapped signer's DID.
|
|
45
46
|
*
|
|
47
|
+
* Fails closed when the current description is unreadable and the caller did
|
|
48
|
+
* not supply a full description (both `name` and `controller`), mirroring
|
|
49
|
+
* {@link Collection.configure}: WAS returns 404 for both not-found and
|
|
50
|
+
* unauthorized, so a write-capable but not read-capable caller invoking
|
|
51
|
+
* `configure({ name })` would otherwise merge forward from a `null` current --
|
|
52
|
+
* silently defaulting `controller` to the wrapped signer's DID (a stealth
|
|
53
|
+
* ownership change) and dropping the existing `name`. Pass `force: true` to
|
|
54
|
+
* proceed anyway (a deliberate create through a handle), or supply both
|
|
55
|
+
* `name` and `controller` explicitly so nothing is merged from the unreadable
|
|
56
|
+
* current.
|
|
57
|
+
*
|
|
46
58
|
* @param desc {object}
|
|
47
59
|
* @param [desc.name] {string}
|
|
48
60
|
* @param [desc.controller] {string}
|
|
61
|
+
* @param [desc.force] {boolean} proceed even when the current description is
|
|
62
|
+
* unreadable and a full description is not supplied (see above)
|
|
49
63
|
* @returns {Promise<SpaceDescription>}
|
|
50
64
|
*/
|
|
51
65
|
async configure(desc) {
|
|
52
66
|
const current = await this.describe();
|
|
67
|
+
if (current === null &&
|
|
68
|
+
!desc.force &&
|
|
69
|
+
!(desc.name !== undefined && desc.controller !== undefined)) {
|
|
70
|
+
throw new ValidationError(`Cannot configure space "${this.id}": its current description is not ` +
|
|
71
|
+
'readable with this capability (WAS returns 404 for both not-found ' +
|
|
72
|
+
'and unauthorized), so merging forward could silently change the ' +
|
|
73
|
+
'controller or drop the existing name. Supply both `name` and ' +
|
|
74
|
+
'`controller` explicitly, use a read-capable capability, or pass ' +
|
|
75
|
+
'`force: true` if you are creating a new space.');
|
|
76
|
+
}
|
|
53
77
|
const name = desc.name ?? current?.name;
|
|
54
78
|
const controller = desc.controller ?? current?.controller ?? this._context.controllerDid;
|
|
55
79
|
await send(this._context, {
|
|
@@ -185,7 +209,7 @@ export class Space {
|
|
|
185
209
|
* connection (the re-consent path), use {@link updateBackend}.
|
|
186
210
|
*
|
|
187
211
|
* @param registration {BackendRegistration} the backend to register
|
|
188
|
-
* (`{ id, provider, connection: { kind,
|
|
212
|
+
* (`{ id, provider, connection: { kind, ... }, name?, storageMode?, features? }`)
|
|
189
213
|
* @returns {Promise<BackendDescriptor>} the sanitized descriptor of the
|
|
190
214
|
* newly registered backend
|
|
191
215
|
*/
|
|
@@ -281,6 +305,35 @@ export class Space {
|
|
|
281
305
|
capability: this._capability
|
|
282
306
|
});
|
|
283
307
|
}
|
|
308
|
+
/**
|
|
309
|
+
* Revokes a capability rooted in this space -- the inverse of {@link grant}.
|
|
310
|
+
* From then on the capability is rejected wherever a Space-rooted chain is
|
|
311
|
+
* verified: writes, privileged routes, and the capability leg of reads.
|
|
312
|
+
*
|
|
313
|
+
* Two callers are authorized: this space's controller, and any controller in
|
|
314
|
+
* the capability's own delegation chain (so a delegee can revoke the
|
|
315
|
+
* capability it holds, without a separate grant). Anyone else gets a
|
|
316
|
+
* `NotFoundError`, as does a capability rooted in a different space.
|
|
317
|
+
*
|
|
318
|
+
* Revocation withdraws only what the *capability* granted. Access an
|
|
319
|
+
* access-control policy grants independently survives it, so a `PublicCanRead`
|
|
320
|
+
* target stays publicly readable afterwards. It is also prospective: a revoked
|
|
321
|
+
* reader of an encrypted collection still holds the keys for ciphertext it
|
|
322
|
+
* already fetched.
|
|
323
|
+
*
|
|
324
|
+
* **Not idempotent.** Revoking an already-revoked capability throws
|
|
325
|
+
* `ValidationError` (the server's 400), because its chain now contains a
|
|
326
|
+
* revoked link. The server reports that with the same problem type it uses for
|
|
327
|
+
* a tampered, expired, or foreign-rooted capability, so this method cannot
|
|
328
|
+
* distinguish them and does not swallow any of them. Catch `ValidationError`
|
|
329
|
+
* if you want revoking twice to be a no-op.
|
|
330
|
+
*
|
|
331
|
+
* @param zcap {IDelegatedZcap} the delegated capability to revoke
|
|
332
|
+
* @returns {Promise<void>}
|
|
333
|
+
*/
|
|
334
|
+
async revoke(zcap) {
|
|
335
|
+
return submitRevocation(this._context, { spaceId: this.id, zcap });
|
|
336
|
+
}
|
|
284
337
|
/**
|
|
285
338
|
* Sends the export request and returns the raw response with its body stream
|
|
286
339
|
* intact, shared by `export`/`exportBlob`/`exportStream`.
|
package/dist/Space.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Space.js","sourceRoot":"","sources":["../src/Space.ts"],"names":[],"mappings":"AAUA,OAAO,EACL,SAAS,EACT,UAAU,EACV,gBAAgB,EAChB,WAAW,EACX,WAAW,EACX,aAAa,EACb,iBAAiB,EACjB,WAAW,EACX,WAAW,EACX,YAAY,EACb,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"Space.js","sourceRoot":"","sources":["../src/Space.ts"],"names":[],"mappings":"AAUA,OAAO,EACL,SAAS,EACT,UAAU,EACV,gBAAgB,EAChB,WAAW,EACX,WAAW,EACX,aAAa,EACb,iBAAiB,EACjB,WAAW,EACX,WAAW,EACX,YAAY,EACb,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAEvD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;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b,MAAM,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,eAAe,EAAE,CAAC,CAAA;IACjD,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,WAAW;QACf,OAAO,YAAY,CAAC,IAAI,CAAC,QAAQ,EAAE;YACjC,UAAU,EAAE,IAAI,CAAC,WAAW;YAC5B,UAAU,EAAE,IAAI,CAAC,WAAW;SAC7B,CAAC,CAAA;IACJ,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,OAAO;QACX,OAAO,QAAQ,CAAU,IAAI,CAAC,QAAQ,EAAE;YACtC,IAAI,EAAE,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;YAC3B,UAAU,EAAE,IAAI,CAAC,WAAW;SAC7B,CAAC,CAAA;IACJ,CAAC;CACF"}
|
package/dist/WasClient.d.ts
CHANGED
|
@@ -60,6 +60,7 @@ export declare class WasClient {
|
|
|
60
60
|
* @returns {string}
|
|
61
61
|
*/
|
|
62
62
|
get controllerDid(): string;
|
|
63
|
+
private _cachedContext?;
|
|
63
64
|
private get _context();
|
|
64
65
|
/**
|
|
65
66
|
* Returns a lazy handle to a space by id. No I/O.
|
|
@@ -183,6 +184,20 @@ export declare class WasClient {
|
|
|
183
184
|
* @returns {Promise<IDelegatedZcap>}
|
|
184
185
|
*/
|
|
185
186
|
grant(options: GrantOptions): Promise<IDelegatedZcap>;
|
|
187
|
+
/**
|
|
188
|
+
* The general revocation primitive -- the inverse of {@link grant}. Derives the
|
|
189
|
+
* owning space from the capability's `invocationTarget` (which a Space-rooted
|
|
190
|
+
* capability always addresses at or beneath) and submits it to that space's
|
|
191
|
+
* revocation endpoint. Equivalent to `was.space(id).revoke(zcap)`.
|
|
192
|
+
*
|
|
193
|
+
* Revocation is scoped to one space: there is no cross-space or global
|
|
194
|
+
* revocation. See {@link Space.revoke} for who may call it, what it does and
|
|
195
|
+
* does not withdraw, and why it is not idempotent.
|
|
196
|
+
*
|
|
197
|
+
* @param zcap {IDelegatedZcap} the delegated capability to revoke
|
|
198
|
+
* @returns {Promise<void>}
|
|
199
|
+
*/
|
|
200
|
+
revoke(zcap: IDelegatedZcap): Promise<void>;
|
|
186
201
|
/**
|
|
187
202
|
* The signed escape hatch, mirroring ezcap's generic `request()`. Resolves
|
|
188
203
|
* `path` against `serverUrl`, defaults `action` to `method`, and signs via the
|
package/dist/WasClient.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WasClient.d.ts","sourceRoot":"","sources":["../src/WasClient.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;;;GAOG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAE3C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"WasClient.d.ts","sourceRoot":"","sources":["../src/WasClient.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;;;GAOG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAE3C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAuBxD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AACpD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,KAAK,EACV,YAAY,EACZ,aAAa,EACb,cAAc,EACd,OAAO,EACP,KAAK,EACL,IAAI,EACJ,YAAY,EACZ,uBAAuB,EACvB,eAAe,EACf,YAAY,EACb,MAAM,YAAY,CAAA;AAEnB,qBAAa,SAAS;IACpB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAA;IAC/B,QAAQ,CAAC,UAAU,CAAC,EAAE,kBAAkB,CAAA;IAExC;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AC/B,aAAa,EACd,EAAE;QACD,aAAa,EAAE,MAAM,CAAA;KACtB,GAAG,cAAc,CAAC,uBAAuB,CAAC;IAQ3C;;;;;;;;;OASG;IACI,yBAAyB,CAAC,EAC/B,aAAa,EACd,EAAE;QACD,aAAa,EAAE,MAAM,CAAA;KACtB,GAAG,cAAc,CAAC,eAAe,CAAC;IAQnC;;;;;;;OAOG;IACH,cAAc,CAAC,IAAI,EAAE,KAAK,GAAG,KAAK,GAAG,UAAU,GAAG,QAAQ;IAuD1D;;;;;;;;OAQG;IACG,KAAK,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,cAAc,CAAC;IAI3D;;;;;;;;;;;;OAYG;IACG,MAAM,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAQjD;;;;;;;;OAQG;IACG,OAAO,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;CAG5D"}
|
package/dist/WasClient.js
CHANGED
|
@@ -11,11 +11,12 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import { ZcapClient } from '@interop/ezcap';
|
|
13
13
|
import { Ed25519Signature2020 } from '@interop/ed25519-signature';
|
|
14
|
-
import { collectionItemsUrl,
|
|
14
|
+
import { collectionItemsUrl, parseSpaceTarget, spacesRoot } from './internal/paths.js';
|
|
15
15
|
import { send, rawRequest, unsignedRequest } from './internal/request.js';
|
|
16
16
|
import { createdId, dataOrNull, parseResource, readJsonData } from './internal/content.js';
|
|
17
17
|
import { buildPageWalk, collectPages, walkPages } from './internal/pagination.js';
|
|
18
18
|
import { delegateGrant } from './internal/grant.js';
|
|
19
|
+
import { spaceIdOf, submitRevocation } from './internal/revoke.js';
|
|
19
20
|
import { ValidationError } from './errors.js';
|
|
20
21
|
import { Space } from './Space.js';
|
|
21
22
|
import { Collection } from './Collection.js';
|
|
@@ -73,13 +74,21 @@ export class WasClient {
|
|
|
73
74
|
}
|
|
74
75
|
return signer.id.split('#')[0];
|
|
75
76
|
}
|
|
77
|
+
_cachedContext;
|
|
76
78
|
get _context() {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
79
|
+
// `serverUrl`, `zcapClient` (and thus `controllerDid`), and `encryption`
|
|
80
|
+
// are all constructor-fixed, so the context is derived once and reused
|
|
81
|
+
// rather than re-deriving `controllerDid` and reallocating the object on
|
|
82
|
+
// every handle access.
|
|
83
|
+
if (this._cachedContext === undefined) {
|
|
84
|
+
this._cachedContext = {
|
|
85
|
+
serverUrl: this.serverUrl,
|
|
86
|
+
zcapClient: this.zcapClient,
|
|
87
|
+
controllerDid: this.controllerDid,
|
|
88
|
+
encryption: this.encryption
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
return this._cachedContext;
|
|
83
92
|
}
|
|
84
93
|
/**
|
|
85
94
|
* Returns a lazy handle to a space by id. No I/O.
|
|
@@ -249,27 +258,29 @@ export class WasClient {
|
|
|
249
258
|
* @returns {Space | Collection | Resource}
|
|
250
259
|
*/
|
|
251
260
|
fromCapability(zcap) {
|
|
252
|
-
|
|
261
|
+
const target = zcap.invocationTarget;
|
|
253
262
|
try {
|
|
254
|
-
;
|
|
255
|
-
({ pathname } = new URL(zcap.invocationTarget));
|
|
263
|
+
new URL(target);
|
|
256
264
|
}
|
|
257
265
|
catch (err) {
|
|
258
|
-
throw new ValidationError(`invocationTarget "${
|
|
259
|
-
'absolute URL.', { cause: err });
|
|
266
|
+
throw new ValidationError(`invocationTarget "${target}" is not a valid absolute URL.`, { cause: err });
|
|
260
267
|
}
|
|
261
|
-
// `
|
|
262
|
-
//
|
|
263
|
-
//
|
|
264
|
-
//
|
|
265
|
-
//
|
|
266
|
-
//
|
|
267
|
-
|
|
268
|
+
// `parseSpaceTarget` owns the path grammar: it strips `serverUrl`'s base
|
|
269
|
+
// path first (so a WAS mounted under a sub-path -- `https://host/was/` --
|
|
270
|
+
// classifies just as a bare-origin deployment does, which `parseSpacePath`
|
|
271
|
+
// alone cannot) and percent-decodes each segment, since the path builders
|
|
272
|
+
// re-encode every id. Classifying the full segment list -- rather than
|
|
273
|
+
// destructuring the first three ids -- keeps a sub-resource target
|
|
274
|
+
// (`/space/s/policy`, `/space/s/c/r/meta`, ...) from being silently
|
|
275
|
+
// truncated to the nearest containment handle, whose derived URLs would
|
|
276
|
+
// mismatch the capability's invocation target.
|
|
277
|
+
const parsed = parseSpaceTarget({ serverUrl: this.serverUrl, target });
|
|
268
278
|
if (parsed === null) {
|
|
269
|
-
throw new ValidationError(`Cannot derive a handle from invocationTarget "${
|
|
279
|
+
throw new ValidationError(`Cannot derive a handle from invocationTarget "${target}": it does ` +
|
|
280
|
+
`not address a resource on "${this.serverUrl}".`);
|
|
270
281
|
}
|
|
271
282
|
if (parsed.kind === 'sub-resource') {
|
|
272
|
-
throw new ValidationError(`invocationTarget "${
|
|
283
|
+
throw new ValidationError(`invocationTarget "${target}" addresses a reserved ` +
|
|
273
284
|
'sub-resource, which has no navigational handle. Invoke it via the ' +
|
|
274
285
|
'owning handle instead (e.g. `space.getPolicy()` / ' +
|
|
275
286
|
'`resource.meta()`), or use the `was.request()` escape hatch.');
|
|
@@ -306,6 +317,26 @@ export class WasClient {
|
|
|
306
317
|
async grant(options) {
|
|
307
318
|
return delegateGrant(this._context, options);
|
|
308
319
|
}
|
|
320
|
+
/**
|
|
321
|
+
* The general revocation primitive -- the inverse of {@link grant}. Derives the
|
|
322
|
+
* owning space from the capability's `invocationTarget` (which a Space-rooted
|
|
323
|
+
* capability always addresses at or beneath) and submits it to that space's
|
|
324
|
+
* revocation endpoint. Equivalent to `was.space(id).revoke(zcap)`.
|
|
325
|
+
*
|
|
326
|
+
* Revocation is scoped to one space: there is no cross-space or global
|
|
327
|
+
* revocation. See {@link Space.revoke} for who may call it, what it does and
|
|
328
|
+
* does not withdraw, and why it is not idempotent.
|
|
329
|
+
*
|
|
330
|
+
* @param zcap {IDelegatedZcap} the delegated capability to revoke
|
|
331
|
+
* @returns {Promise<void>}
|
|
332
|
+
*/
|
|
333
|
+
async revoke(zcap) {
|
|
334
|
+
const context = this._context;
|
|
335
|
+
return submitRevocation(context, {
|
|
336
|
+
spaceId: spaceIdOf(context, zcap),
|
|
337
|
+
zcap
|
|
338
|
+
});
|
|
339
|
+
}
|
|
309
340
|
/**
|
|
310
341
|
* The signed escape hatch, mirroring ezcap's generic `request()`. Resolves
|
|
311
342
|
* `path` against `serverUrl`, defaults `action` to `method`, and signs via the
|
package/dist/WasClient.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WasClient.js","sourceRoot":"","sources":["../src/WasClient.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;;;GAOG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAA;AAEjE,OAAO,EACL,kBAAkB,EAClB,
|
|
1
|
+
{"version":3,"file":"WasClient.js","sourceRoot":"","sources":["../src/WasClient.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;;;GAOG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAA;AAEjE,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,UAAU,EACX,MAAM,qBAAqB,CAAA;AAE5B,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AACzE,OAAO,EACL,SAAS,EACT,UAAU,EACV,aAAa,EACb,YAAY,EACb,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EACL,aAAa,EACb,YAAY,EACZ,SAAS,EACV,MAAM,0BAA0B,CAAA;AAEjC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAClE,O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OAQG;IACH,KAAK,CAAC,OAAO,CAAC,OAAqB;QACjC,OAAO,UAAU,CAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;IAC3C,CAAC;CACF"}
|
package/dist/codec.d.ts
CHANGED
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
* silently writing plaintext.
|
|
32
32
|
*/
|
|
33
33
|
import type { HttpResponse } from '@interop/http-client';
|
|
34
|
-
import type { Json, ResourceData, ResourceMetadataCustom } from './types.js';
|
|
34
|
+
import type { CollectionEncryption, Json, ResourceData, ResourceMetadataCustom } from './types.js';
|
|
35
35
|
/**
|
|
36
36
|
* The result of {@link ResourceCodec.encode}: the stored representation of a
|
|
37
37
|
* write, plus the id to store it under.
|
|
@@ -55,6 +55,11 @@ import type { Json, ResourceData, ResourceMetadataCustom } from './types.js';
|
|
|
55
55
|
* ETag for lost-update-safe updates, or `If-None-Match: *` for a fresh
|
|
56
56
|
* insert). The write path forwards these as the request's conditional headers.
|
|
57
57
|
* Only honored for a codec that sets {@link ResourceCodec.conditionalWrites}.
|
|
58
|
+
* - `epoch` -- the key-epoch id the codec encrypted this write under, on a
|
|
59
|
+
* multi-recipient encrypted collection. The write path emits it as the
|
|
60
|
+
* `WAS-Key-Epoch` request header, so the server stamps
|
|
61
|
+
* {@link ResourceMetadata.epoch}. Absent for a plaintext or single-key
|
|
62
|
+
* encrypted write (the header is then not sent, which clears any prior stamp).
|
|
58
63
|
*/
|
|
59
64
|
export interface EncodedWrite {
|
|
60
65
|
id?: string;
|
|
@@ -64,6 +69,7 @@ export interface EncodedWrite {
|
|
|
64
69
|
resourceContentType?: string;
|
|
65
70
|
ifMatch?: string;
|
|
66
71
|
ifNoneMatch?: boolean;
|
|
72
|
+
epoch?: string;
|
|
67
73
|
}
|
|
68
74
|
/**
|
|
69
75
|
* A pluggable encode/decode transform bound to a single collection handle.
|
|
@@ -71,16 +77,6 @@ export interface EncodedWrite {
|
|
|
71
77
|
* codec is reused across every read/write on the handle).
|
|
72
78
|
*/
|
|
73
79
|
export interface ResourceCodec {
|
|
74
|
-
/**
|
|
75
|
-
* How this codec stores a Resource's user-writable metadata (`custom`:
|
|
76
|
-
* `name` / `tags`, set via `resource.setName` / `setTags` / `setMeta`). The
|
|
77
|
-
* identity codec stores it as server-visible plaintext (`'plaintext'`); an
|
|
78
|
-
* encrypting codec stores it as an opaque envelope (`'encrypted'`) -- the same
|
|
79
|
-
* way it stores content -- so `name` / `tags` never reach the server in the
|
|
80
|
-
* clear. A mode rather than a boolean so a future scheme that stores metadata
|
|
81
|
-
* differently can extend the union.
|
|
82
|
-
*/
|
|
83
|
-
readonly metadataMode: 'plaintext' | 'encrypted';
|
|
84
80
|
/**
|
|
85
81
|
* Whether this codec drives optimistic-concurrency (conditional) writes. When
|
|
86
82
|
* `true`, the write path pre-reads the current stored resource and passes it
|
|
@@ -171,6 +167,12 @@ export interface EncryptionProvider {
|
|
|
171
167
|
* @param input.spaceId {string}
|
|
172
168
|
* @param input.collectionId {string}
|
|
173
169
|
* @param input.scheme {string} the declared encryption scheme (e.g. `edv`)
|
|
170
|
+
* @param [input.encryption] {CollectionEncryption} the full encryption
|
|
171
|
+
* marker read from the Collection Description (when core discovered it via
|
|
172
|
+
* the marker rather than an override). Carries the key-epoch public
|
|
173
|
+
* references (`epochs` / `currentEpoch`) a multi-recipient provider needs to
|
|
174
|
+
* resolve per-epoch keys; absent on an override-driven resolution, where the
|
|
175
|
+
* provider falls back to its single-key path.
|
|
174
176
|
* @param [input.keys] {unknown} override-supplied key material (a per-handle
|
|
175
177
|
* `encryption` override); when present the provider uses it instead of its
|
|
176
178
|
* keystore. Opaque to core; the provider interprets it per `scheme`.
|
|
@@ -181,6 +183,7 @@ export interface EncryptionProvider {
|
|
|
181
183
|
spaceId: string;
|
|
182
184
|
collectionId: string;
|
|
183
185
|
scheme: string;
|
|
186
|
+
encryption?: CollectionEncryption;
|
|
184
187
|
keys?: unknown;
|
|
185
188
|
}): Promise<ResourceCodec | null>;
|
|
186
189
|
}
|
package/dist/codec.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codec.d.ts","sourceRoot":"","sources":["../src/codec.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AACxD,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"codec.d.ts","sourceRoot":"","sources":["../src/codec.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AACxD,OAAO,KAAK,EACV,oBAAoB,EACpB,IAAI,EACJ,YAAY,EACZ,sBAAsB,EACvB,MAAM,YAAY,CAAA;AAEnB;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,WAAW,YAAY;IAC3B,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,UAAU,GAAG,IAAI,CAAA;IACxB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,mBAAmB,CAAC,EAAE,MAAM,CAAA;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B;;;;;;;;OAQG;IACH,QAAQ,CAAC,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAEpC;;;;;;;;;;;;;OAaG;IACH,MAAM,CAAC,KAAK,EAAE;QACZ,EAAE,CAAC,EAAE,MAAM,CAAA;QACX,IAAI,EAAE,YAAY,CAAA;QAClB,WAAW,CAAC,EAAE,MAAM,CAAA;QACpB,OAAO,CAAC,EAAE,YAAY,GAAG,IAAI,CAAA;KAC9B,GAAG,OAAO,CAAC,YAAY,CAAC,CAAA;IAEzB;;;;;;;OAOG;IACH,MAAM,CAAC,QAAQ,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,CAAA;IAEpD;;;;;;;;;;OAUG;IACH,UAAU,CAAC,KAAK,EAAE;QAChB,MAAM,EAAE,sBAAsB,CAAA;KAC/B,GAAG,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;IAE/B;;;;;;;;;OASG;IACH,UAAU,CAAC,MAAM,EAAE;QAAE,MAAM,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAAA;CAC1E;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;;;;;;;;;;;;;;;;OAkBG;IACH,QAAQ,CAAC,KAAK,EAAE;QACd,OAAO,EAAE,MAAM,CAAA;QACf,YAAY,EAAE,MAAM,CAAA;QACpB,MAAM,EAAE,MAAM,CAAA;QACd,UAAU,CAAC,EAAE,oBAAoB,CAAA;QACjC,IAAI,CAAC,EAAE,OAAO,CAAA;KACf,GAAG,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC,CAAA;CAClC"}
|
package/dist/edv/EdvCodec.d.ts
CHANGED
|
@@ -1,55 +1,3 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) 2026 Interop Alliance. All rights reserved.
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* The EDV (Encrypted Data Vault) resource codec and its `EncryptionProvider`
|
|
6
|
-
* factory -- the encrypting half of the codec seam. Bound to an
|
|
7
|
-
* encrypted collection, it encrypts a caller's value into an EDV envelope
|
|
8
|
-
* (`{ id, sequence, indexed, jwe }`) on write and decrypts it on read, so
|
|
9
|
-
* `collection.put(id, obj)` / `collection.get(id)` transparently round-trip
|
|
10
|
-
* ciphertext. Keys live in the wallet and are supplied per-collection by the
|
|
11
|
-
* app's `resolveKeys`; they never reach the server, which stores only opaque
|
|
12
|
-
* JWE envelopes.
|
|
13
|
-
*
|
|
14
|
-
* This reuses `EdvClientCore`'s transport-free `documentCipher` (its public
|
|
15
|
-
* `EdvDocumentCipher` -- the same JWE machinery as the standalone
|
|
16
|
-
* `WasTransport`), but here the WAS Resource CRUD -- the transport role -- is
|
|
17
|
-
* played by core was-client's `Collection`/`Resource` I/O, so the codec is a
|
|
18
|
-
* pure encode/decode transform and needs no transport of its own.
|
|
19
|
-
*
|
|
20
|
-
* Scope (documents-only):
|
|
21
|
-
*
|
|
22
|
-
* - **Restrict-mode ids.** `add()` mints a 128-bit multibase EDV id; the WAS
|
|
23
|
-
* resource id IS that EDV id. `put(id, ...)` accepts only an EDV-format id --
|
|
24
|
-
* a human-readable id is rejected (it would leak onto the URL). Carry a
|
|
25
|
-
* human-readable label inside the encrypted content instead. By default the
|
|
26
|
-
* minted id is random (`generateId()`, the classic mutable-document model);
|
|
27
|
-
* with `idDerivation: 'content'` it is content-derived instead -- encrypt
|
|
28
|
-
* first, then `deriveId()` a truncated SHA-256 of the JWE ciphertext and
|
|
29
|
-
* stamp it on the envelope -- making the document content-addressed (and so
|
|
30
|
-
* immutable: an "update" is delete-old + add-new). Both formats pass the same
|
|
31
|
-
* EDV id check and are indistinguishable on the wire.
|
|
32
|
-
* - **Inline non-JSON as a single JWE.** A `Blob`/`Uint8Array` under the size cap
|
|
33
|
-
* is encrypted as one document -- stored as a legible UTF-8 string for a
|
|
34
|
-
* text-family type (else base64) -- with the plaintext content type and the
|
|
35
|
-
* encoding carried in the document `meta`. An oversized one is
|
|
36
|
-
* rejected (large chunked encrypted blobs need the server's `chunked-streams`
|
|
37
|
-
* affordance).
|
|
38
|
-
* - **Enforced sequence (conditional writes).** The codec sets
|
|
39
|
-
* `conditionalWrites`, so the write path pre-reads the current envelope and
|
|
40
|
-
* hands it to `encode`: an update advances `sequence` from its prior value and
|
|
41
|
-
* pins the write to the server's current ETag via `If-Match`, while a fresh
|
|
42
|
-
* insert (`sequence: 0`) is guarded by `If-None-Match: *`. A stale write
|
|
43
|
-
* surfaces as a `PreconditionFailedError` (412) -- the lost-update guard --
|
|
44
|
-
* rather than the old advisory last-writer-wins. Against a backend that does
|
|
45
|
-
* not advertise `conditional-writes` (no ETag) it degrades to advisory.
|
|
46
|
-
* - **Encrypted metadata.** `metadataMode` is `'encrypted'`, so a Resource's
|
|
47
|
-
* user-writable `custom` (`name`/`tags`, via `setName`/`setTags`/`setMeta`) is
|
|
48
|
-
* encrypted into an EDV Document envelope with the same `documentCipher` used
|
|
49
|
-
* for content and stored opaquely under `/meta`; the server never sees
|
|
50
|
-
* plaintext `name`/`tags`. A reader with the keys decrypts it back
|
|
51
|
-
* transparently via `meta()`.
|
|
52
|
-
*/
|
|
53
1
|
import { EdvClientCore } from '@interop/edv-client';
|
|
54
2
|
import type { HttpResponse } from '@interop/http-client';
|
|
55
3
|
import type { IKeyAgreementKey, IKeyResolver } from '@interop/data-integrity-core';
|
|
@@ -61,26 +9,40 @@ import type { Json, ResourceData, ResourceMetadataCustom } from '../types.js';
|
|
|
61
9
|
* collection handle.
|
|
62
10
|
*/
|
|
63
11
|
export declare class EdvCodec implements ResourceCodec {
|
|
64
|
-
readonly metadataMode: "encrypted";
|
|
65
12
|
readonly conditionalWrites = true;
|
|
66
13
|
private readonly _edv;
|
|
67
|
-
private readonly
|
|
14
|
+
private readonly _writeKey;
|
|
15
|
+
private readonly _readKeys;
|
|
16
|
+
private readonly _writeEpoch?;
|
|
68
17
|
private readonly _contentType;
|
|
69
18
|
private readonly _maxBlobBytes;
|
|
70
19
|
private readonly _idDerivation;
|
|
71
20
|
/**
|
|
72
21
|
* @param options {object}
|
|
73
22
|
* @param options.edv {EdvClientCore} holds the cipher + key resolver
|
|
74
|
-
* @param options.keyAgreementKey {IKeyAgreementKey} the
|
|
23
|
+
* @param options.keyAgreementKey {IKeyAgreementKey} the key writes encrypt
|
|
24
|
+
* under and the default read key. On a single-key collection this is the
|
|
25
|
+
* wallet's own key-agreement key; on a multi-recipient (key-epoch)
|
|
26
|
+
* collection it is the reconstructed `currentEpoch` key pair.
|
|
27
|
+
* @param [options.readKeys] {IKeyAgreementKey[]} the candidate keys a read
|
|
28
|
+
* may decrypt with, one per epoch this reader can unwrap (defaults to just
|
|
29
|
+
* `keyAgreementKey`). A read selects the one whose id matches the stored
|
|
30
|
+
* envelope's recipient, so a resource written under an older epoch still
|
|
31
|
+
* decrypts.
|
|
32
|
+
* @param [options.writeEpoch] {string} the key-epoch id to stamp on writes
|
|
33
|
+
* (the `currentEpoch`), surfaced as {@link EncodedWrite.epoch}; absent on a
|
|
34
|
+
* single-key collection.
|
|
75
35
|
* @param options.contentType {string} stored envelope content type
|
|
76
36
|
* @param options.maxBlobBytes {number} single-document binary cap
|
|
77
37
|
* @param options.idDerivation {string} how `add()` mints a document
|
|
78
38
|
* id: `'random'` (classic `generateId()`) or `'content'` (derived from the
|
|
79
39
|
* JWE ciphertext, content-addressed)
|
|
80
40
|
*/
|
|
81
|
-
constructor({ edv, keyAgreementKey, contentType, maxBlobBytes, idDerivation }: {
|
|
41
|
+
constructor({ edv, keyAgreementKey, readKeys, writeEpoch, contentType, maxBlobBytes, idDerivation }: {
|
|
82
42
|
edv: EdvClientCore;
|
|
83
43
|
keyAgreementKey: IKeyAgreementKey;
|
|
44
|
+
readKeys?: IKeyAgreementKey[];
|
|
45
|
+
writeEpoch?: string;
|
|
84
46
|
contentType: string;
|
|
85
47
|
maxBlobBytes: number;
|
|
86
48
|
idDerivation: 'random' | 'content';
|
|
@@ -101,6 +63,22 @@ export declare class EdvCodec implements ResourceCodec {
|
|
|
101
63
|
data?: unknown;
|
|
102
64
|
json(): Promise<unknown>;
|
|
103
65
|
}): Promise<Json | Blob>;
|
|
66
|
+
/**
|
|
67
|
+
* Decrypts a stored EDV envelope, selecting which read key to use by matching
|
|
68
|
+
* the envelope's JWE recipient `kid` against this reader's candidate keys
|
|
69
|
+
* (one per epoch it can unwrap). On a single-key collection there is exactly
|
|
70
|
+
* one candidate; on a multi-recipient collection a resource written under an
|
|
71
|
+
* older epoch selects that epoch's key, so history stays readable.
|
|
72
|
+
*
|
|
73
|
+
* A stored envelope naming an epoch this reader holds no key for (it was never
|
|
74
|
+
* a recipient of that epoch, or was removed and the epoch rotated) fails with
|
|
75
|
+
* {@link KeyUnwrapError} -- the **read** axis only; it says nothing about
|
|
76
|
+
* whether the server will still serve (pull) the ciphertext.
|
|
77
|
+
*
|
|
78
|
+
* @param encryptedDoc {IEncryptedDocument}
|
|
79
|
+
* @returns {Promise<{ content?: unknown; meta?: Record<string, unknown> }>}
|
|
80
|
+
*/
|
|
81
|
+
private _decrypt;
|
|
104
82
|
/**
|
|
105
83
|
* @inheritdoc
|
|
106
84
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EdvCodec.d.ts","sourceRoot":"","sources":["../../src/edv/EdvCodec.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"EdvCodec.d.ts","sourceRoot":"","sources":["../../src/edv/EdvCodec.ts"],"names":[],"mappings":"AAqDA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AACxD,OAAO,KAAK,EAEV,gBAAgB,EAChB,YAAY,EACb,MAAM,8BAA8B,CAAA;AACrC,OAAO,KAAK,EACV,YAAY,EACZ,kBAAkB,EAClB,aAAa,EACd,MAAM,aAAa,CAAA;AAgBpB,OAAO,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AA6D7E;;;;GAIG;AACH,qBAAa,QAAS,YAAW,aAAa;IAC5C,QAAQ,CAAC,iBAAiB,QAAO;IAEjC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAe;IACpC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAkB;IAC5C,OAAO,CAAC,QAAQ,CAAC,S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