@interop/was-client 0.9.1 → 0.10.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.
Files changed (79) hide show
  1. package/README.md +27 -1
  2. package/dist/Collection.d.ts +49 -10
  3. package/dist/Collection.d.ts.map +1 -1
  4. package/dist/Collection.js +161 -61
  5. package/dist/Collection.js.map +1 -1
  6. package/dist/Resource.d.ts +13 -5
  7. package/dist/Resource.d.ts.map +1 -1
  8. package/dist/Resource.js +50 -38
  9. package/dist/Resource.js.map +1 -1
  10. package/dist/Space.d.ts +1 -0
  11. package/dist/Space.d.ts.map +1 -1
  12. package/dist/Space.js +24 -27
  13. package/dist/Space.js.map +1 -1
  14. package/dist/WasClient.d.ts +43 -2
  15. package/dist/WasClient.d.ts.map +1 -1
  16. package/dist/WasClient.js +90 -14
  17. package/dist/WasClient.js.map +1 -1
  18. package/dist/codec.d.ts +11 -4
  19. package/dist/codec.d.ts.map +1 -1
  20. package/dist/edv/EdvCodec.d.ts +64 -33
  21. package/dist/edv/EdvCodec.d.ts.map +1 -1
  22. package/dist/edv/EdvCodec.js +194 -86
  23. package/dist/edv/EdvCodec.js.map +1 -1
  24. package/dist/edv/WasTransport.d.ts +6 -12
  25. package/dist/edv/WasTransport.d.ts.map +1 -1
  26. package/dist/edv/WasTransport.js +6 -21
  27. package/dist/edv/WasTransport.js.map +1 -1
  28. package/dist/edv/constants.d.ts +30 -0
  29. package/dist/edv/constants.d.ts.map +1 -0
  30. package/dist/edv/constants.js +30 -0
  31. package/dist/edv/constants.js.map +1 -0
  32. package/dist/edv/index.d.ts +1 -1
  33. package/dist/edv/index.d.ts.map +1 -1
  34. package/dist/edv/index.js +1 -1
  35. package/dist/edv/index.js.map +1 -1
  36. package/dist/errors.d.ts +3 -1
  37. package/dist/errors.d.ts.map +1 -1
  38. package/dist/errors.js +15 -5
  39. package/dist/errors.js.map +1 -1
  40. package/dist/index.d.ts +1 -1
  41. package/dist/index.d.ts.map +1 -1
  42. package/dist/internal/codec.d.ts +69 -4
  43. package/dist/internal/codec.d.ts.map +1 -1
  44. package/dist/internal/codec.js +93 -5
  45. package/dist/internal/codec.js.map +1 -1
  46. package/dist/internal/content.d.ts +74 -3
  47. package/dist/internal/content.d.ts.map +1 -1
  48. package/dist/internal/content.js +78 -7
  49. package/dist/internal/content.js.map +1 -1
  50. package/dist/internal/describe.d.ts.map +1 -1
  51. package/dist/internal/describe.js +2 -1
  52. package/dist/internal/describe.js.map +1 -1
  53. package/dist/internal/pagination.d.ts +45 -0
  54. package/dist/internal/pagination.d.ts.map +1 -0
  55. package/dist/internal/pagination.js +53 -0
  56. package/dist/internal/pagination.js.map +1 -0
  57. package/dist/internal/paths.d.ts +4 -0
  58. package/dist/internal/paths.d.ts.map +1 -1
  59. package/dist/internal/paths.js +10 -1
  60. package/dist/internal/paths.js.map +1 -1
  61. package/dist/internal/policy.d.ts +54 -0
  62. package/dist/internal/policy.d.ts.map +1 -0
  63. package/dist/internal/policy.js +58 -0
  64. package/dist/internal/policy.js.map +1 -0
  65. package/dist/internal/request.d.ts +4 -2
  66. package/dist/internal/request.d.ts.map +1 -1
  67. package/dist/internal/request.js +9 -2
  68. package/dist/internal/request.js.map +1 -1
  69. package/dist/internal/reserved.d.ts +3 -8
  70. package/dist/internal/reserved.d.ts.map +1 -1
  71. package/dist/internal/reserved.js +10 -20
  72. package/dist/internal/reserved.js.map +1 -1
  73. package/dist/internal/write.d.ts +37 -0
  74. package/dist/internal/write.d.ts.map +1 -0
  75. package/dist/internal/write.js +29 -0
  76. package/dist/internal/write.js.map +1 -0
  77. package/dist/types.d.ts +14 -0
  78. package/dist/types.d.ts.map +1 -1
  79. package/package.json +6 -6
package/dist/WasClient.js CHANGED
@@ -13,7 +13,8 @@ import { ZcapClient } from '@interop/ezcap';
13
13
  import { Ed25519Signature2020 } from '@interop/ed25519-signature';
14
14
  import { spacesRoot } from './internal/paths.js';
15
15
  import { send, rawRequest, unsignedRequest } from './internal/request.js';
16
- import { parseResource, readJsonData } from './internal/content.js';
16
+ import { createdId, parseResource, readJsonData } from './internal/content.js';
17
+ import { collectPages, walkPages } from './internal/pagination.js';
17
18
  import { delegateGrant } from './internal/grant.js';
18
19
  import { ValidationError } from './errors.js';
19
20
  import { Space } from './Space.js';
@@ -120,8 +121,7 @@ export class WasClient {
120
121
  method: 'POST',
121
122
  json: body
122
123
  });
123
- const created = response.data;
124
- return this.space(created.id);
124
+ return this.space(createdId(response));
125
125
  }
126
126
  /**
127
127
  * Lists the spaces in the repository visible to the wrapped signer, as a
@@ -159,16 +159,15 @@ export class WasClient {
159
159
  return parseResource(response);
160
160
  }
161
161
  /**
162
- * Lists a public (`PublicCanRead`) collection by its URL with no authorization
163
- * -- an unsigned `GET` -- e.g. to browse a blog published as a public-read
164
- * collection. Returns `null` if the collection is missing or not publicly
165
- * readable (404 conflation caveat).
162
+ * Reads the first page of a public (`PublicCanRead`) collection listing with an
163
+ * unsigned `GET` and packages the means to follow its `next` links. Returns
164
+ * `null` if the collection is missing or not publicly readable (404 conflation
165
+ * caveat).
166
166
  *
167
- * @param options {object}
168
- * @param options.collectionUrl {string} the absolute collection URL
169
- * @returns {Promise<CollectionResourcesList | null>}
167
+ * @param collectionUrl {string} the absolute collection URL
168
+ * @returns {Promise<PageWalk | null>}
170
169
  */
171
- async publicListCollection({ collectionUrl }) {
170
+ async _publicListWalk(collectionUrl) {
172
171
  // The collection listing endpoint is the trailing-slash items URL.
173
172
  const url = collectionUrl.endsWith('/')
174
173
  ? collectionUrl
@@ -177,7 +176,73 @@ export class WasClient {
177
176
  if (response === null) {
178
177
  return null;
179
178
  }
180
- return (await readJsonData(response));
179
+ return {
180
+ first: (await readJsonData(response)),
181
+ firstUrl: url,
182
+ fetchPage: async (pageUrl) => {
183
+ const pageResponse = await unsignedRequest({
184
+ url: pageUrl,
185
+ method: 'GET',
186
+ read: true
187
+ });
188
+ return pageResponse === null
189
+ ? null
190
+ : (await readJsonData(pageResponse));
191
+ }
192
+ };
193
+ }
194
+ /**
195
+ * Lists a public (`PublicCanRead`) collection by its URL with no authorization
196
+ * -- an unsigned `GET` -- e.g. to browse a blog published as a public-read
197
+ * collection. Transparently follows the server's `next` pagination links,
198
+ * buffering every page into a single list (the returned envelope omits `next`).
199
+ * For a large collection prefer `publicListCollectionPages()` or
200
+ * `publicListCollectionItems()`, which stream one page at a time and allow
201
+ * stopping early. Returns `null` if the collection is missing or not publicly
202
+ * readable (404 conflation caveat).
203
+ *
204
+ * @param options {object}
205
+ * @param options.collectionUrl {string} the absolute collection URL
206
+ * @returns {Promise<CollectionResourcesList | null>}
207
+ */
208
+ async publicListCollection({ collectionUrl }) {
209
+ const walk = await this._publicListWalk(collectionUrl);
210
+ return walk === null ? null : collectPages(walk);
211
+ }
212
+ /**
213
+ * Lazily yields a public collection listing one page at a time, following the
214
+ * server's `next` links on demand with unsigned `GET`s. Use this to stream a
215
+ * large public collection in constant memory or to stop early. Yields nothing
216
+ * if the collection is missing or not publicly readable (404 conflation
217
+ * caveat).
218
+ *
219
+ * @param options {object}
220
+ * @param options.collectionUrl {string} the absolute collection URL
221
+ * @returns {AsyncGenerator<CollectionResourcesList>}
222
+ */
223
+ async *publicListCollectionPages({ collectionUrl }) {
224
+ const walk = await this._publicListWalk(collectionUrl);
225
+ if (walk === null) {
226
+ return;
227
+ }
228
+ yield* walkPages(walk);
229
+ }
230
+ /**
231
+ * Lazily yields each item of a public collection across every page, flattening
232
+ * `publicListCollectionPages()`. Yields the listing's `ResourceSummary` entries
233
+ * (id / url / contentType / name), not the resource bodies. Yields nothing if
234
+ * the collection is missing or not publicly readable (404 conflation caveat).
235
+ *
236
+ * @param options {object}
237
+ * @param options.collectionUrl {string} the absolute collection URL
238
+ * @returns {AsyncGenerator<ResourceSummary>}
239
+ */
240
+ async *publicListCollectionItems({ collectionUrl }) {
241
+ for await (const page of this.publicListCollectionPages({
242
+ collectionUrl
243
+ })) {
244
+ yield* page.items;
245
+ }
181
246
  }
182
247
  /**
183
248
  * Rebuilds an access handle from a received capability, returning a handle at
@@ -188,8 +253,19 @@ export class WasClient {
188
253
  * @returns {Space | Collection | Resource}
189
254
  */
190
255
  fromCapability(zcap) {
191
- const { pathname } = new URL(zcap.invocationTarget);
192
- const segments = pathname.split('/').filter(Boolean);
256
+ let pathname;
257
+ try {
258
+ ;
259
+ ({ pathname } = new URL(zcap.invocationTarget));
260
+ }
261
+ catch (err) {
262
+ throw new ValidationError(`invocationTarget "${zcap.invocationTarget}" is not a valid ` +
263
+ 'absolute URL.', { cause: err });
264
+ }
265
+ // Decode each path segment before splitting it back into handle ids: the
266
+ // path builders re-encode every id with encodeURIComponent, so passing a
267
+ // still-encoded segment through would double-encode it.
268
+ const segments = pathname.split('/').filter(Boolean).map(decodeURIComponent);
193
269
  if (segments[0] !== 'space') {
194
270
  throw new ValidationError(`Cannot derive a handle from invocationTarget "${zcap.invocationTarget}".`);
195
271
  }
@@ -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,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAEhD,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AACzE,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAE7C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAaxC,MAAM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;QACD,MAAM,CAAC,EAAE,OAAO,EAAE,YAAY,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAA;QACtD,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,eAAe,CACvB,qBAAqB,IAAI,CAAC,gBAAgB,oBAAoB,CAC/D,CAAA;QACH,CAAC;QACD,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAA;QAC7B,IAAI,UAAU,EAAE,CAAC;YACf,OAAO,IAAI,QAAQ,CAAC;gBAClB,OAAO;gBACP,OAAO;gBACP,YAAY,EAAE,YAAsB;gBACpC,UAAU;gBACV,UAAU,EAAE,IAAI;aACjB,CAAC,CAAA;QACJ,CAAC;QACD,IAAI,YAAY,EAAE,CAAC;YACjB,OAAO,IAAI,UAAU,CAAC;gBACpB,OAAO;gBACP,OAAO;gBACP,YAAY;gBACZ,UAAU,EAAE,IAAI;aACjB,CAAC,CAAA;QACJ,CAAC;QACD,OAAO,IAAI,KAAK,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAA;IAC1D,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,KAAK,CAAC,OAAqB;QAC/B,OAAO,aAAa,CAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;IAC9C,CAAC;IAED;;;;;;;;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 } from './types.js';
34
+ import type { Json, ResourceData } 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.
@@ -43,7 +43,13 @@ import type { Json } from './types.js';
43
43
  * - `json` / `body` -- mutually exclusive payloads, mirroring the request
44
44
  * layer: `json` for a structured body, `body` for raw bytes.
45
45
  * - `contentType` -- the content type to send for a `body` write (e.g.
46
- * `application/edv+json` for an encrypted envelope).
46
+ * `application/jose+json` for an encrypted envelope).
47
+ * - `resourceContentType` -- the plaintext content type of the resource, when it
48
+ * differs from the stored `contentType`. An encrypting codec sets this to the
49
+ * caller's resolved type (e.g. `image/png`) while `contentType` stays the
50
+ * opaque envelope type, so `add()` can report the real type in
51
+ * {@link AddResult.contentType}. Absent for the identity codec (its
52
+ * `contentType` already is the resource type).
47
53
  * - `ifMatch` / `ifNoneMatch` -- an optional conditional-write precondition the
48
54
  * codec computed (e.g. the EDV codec maps its `sequence` onto an `If-Match`
49
55
  * ETag for lost-update-safe updates, or `If-None-Match: *` for a fresh
@@ -55,6 +61,7 @@ export interface EncodedWrite {
55
61
  json?: object;
56
62
  body?: Uint8Array | Blob;
57
63
  contentType?: string;
64
+ resourceContentType?: string;
58
65
  ifMatch?: string;
59
66
  ifNoneMatch?: boolean;
60
67
  }
@@ -88,7 +95,7 @@ export interface ResourceCodec {
88
95
  *
89
96
  * @param input {object}
90
97
  * @param [input.id] {string} resource id (absent on add)
91
- * @param input.data {Json | Blob | Uint8Array} the plaintext value
98
+ * @param input.data {ResourceData} the plaintext value
92
99
  * @param [input.contentType] {string} caller-supplied content type
93
100
  * @param [input.current] {HttpResponse | null} the current stored response
94
101
  * (or `null` if absent), supplied only when {@link conditionalWrites} is set,
@@ -97,7 +104,7 @@ export interface ResourceCodec {
97
104
  */
98
105
  encode(input: {
99
106
  id?: string;
100
- data: Json | Blob | Uint8Array;
107
+ data: ResourceData;
101
108
  contentType?: string;
102
109
  current?: HttpResponse | null;
103
110
  }): Promise<EncodedWrite>;
@@ -1 +1 @@
1
- {"version":3,"file":"codec.d.ts","sourceRoot":"","sources":["../src/codec.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG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E;QACd,OAAO,EAAE,MAAM,CAAA;QACf,YAAY,EAAE,MAAM,CAAA;QACpB,MAAM,EAAE,MAAM,CAAA;QACd,IAAI,CAAC,EAAE,OAAO,CAAA;KACf,GAAG,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC,CAAA;CAClC"}
@@ -11,11 +11,11 @@
11
11
  * app's `resolveKeys`; they never reach the server, which stores only opaque
12
12
  * JWE envelopes.
13
13
  *
14
- * This reuses `EdvClientCore`'s encrypt/decrypt primitives (the same JWE
15
- * machinery as the standalone `WasTransport`), but here the WAS Resource CRUD --
16
- * the transport role -- is played by core was-client's `Collection`/`Resource`
17
- * I/O, so the codec is a pure encode/decode transform and needs no transport of
18
- * its own.
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
19
  *
20
20
  * Scope (documents-only):
21
21
  *
@@ -24,9 +24,12 @@
24
24
  * a human-readable id is rejected (it would leak onto the URL). Carry a
25
25
  * human-readable label inside the encrypted content instead. (Blind-derived
26
26
  * ids are a deferred future item.)
27
- * - **Small binary as a single JWE.** A `Blob`/`Uint8Array` under the size cap
28
- * is wrapped and encrypted as one document; an oversized one is rejected
29
- * (chunked encrypted blobs need the server's `chunked-streams` affordance).
27
+ * - **Inline non-JSON as a single JWE.** A `Blob`/`Uint8Array` under the size cap
28
+ * is encrypted as one document -- stored as a legible UTF-8 string for a
29
+ * text-family type (else base64) -- with the plaintext content type and the
30
+ * encoding carried in the document `meta`. An oversized one is
31
+ * rejected (large chunked encrypted blobs need the server's `chunked-streams`
32
+ * affordance).
30
33
  * - **Enforced sequence (conditional writes).** The codec sets
31
34
  * `conditionalWrites`, so the write path pre-reads the current envelope and
32
35
  * hands it to `encode`: an update advances `sequence` from its prior value and
@@ -43,11 +46,10 @@ import { EdvClientCore } from '@interop/edv-client';
43
46
  import type { HttpResponse } from '@interop/http-client';
44
47
  import type { IKeyAgreementKey, IKeyResolver } from '@interop/data-integrity-core';
45
48
  import type { EncodedWrite, EncryptionProvider, ResourceCodec } from '../codec.js';
46
- import type { Json } from '../types.js';
47
- import { EDV_CONTENT_TYPE } from './WasTransport.js';
49
+ import type { Json, ResourceData } from '../types.js';
48
50
  /**
49
51
  * A {@link ResourceCodec} that encrypts on write and decrypts on read using an
50
- * `EdvClientCore`'s JWE primitives. One instance is bound per encrypted
52
+ * `EdvClientCore`'s public `documentCipher`. One instance is bound per encrypted
51
53
  * collection handle.
52
54
  */
53
55
  export declare class EdvCodec implements ResourceCodec {
@@ -75,7 +77,7 @@ export declare class EdvCodec implements ResourceCodec {
75
77
  */
76
78
  encode({ id, data, contentType, current }: {
77
79
  id?: string;
78
- data: Json | Blob | Uint8Array;
80
+ data: ResourceData;
79
81
  contentType?: string;
80
82
  current?: HttpResponse | null;
81
83
  }): Promise<EncodedWrite>;
@@ -87,35 +89,65 @@ export declare class EdvCodec implements ResourceCodec {
87
89
  json(): Promise<unknown>;
88
90
  }): Promise<Json | Blob>;
89
91
  /**
90
- * Resolves a caller value to the EDV document `content`: a JSON object/array
91
- * passes through; a `Blob`/`Uint8Array` (under the cap) is wrapped as a
92
- * base64 blob record; a bare primitive is rejected (mirroring the plaintext
93
- * `prepareBody` contract).
92
+ * Asserts that a document read from an encrypted collection is an EDV envelope
93
+ * (`{ jwe, ... }`) before it is handed to the cipher. A plaintext or foreign
94
+ * resource -- one written without this codec -- carries no `jwe`, which would
95
+ * otherwise make the EDV core throw a raw `TypeError`. Surfacing a typed
96
+ * `EncryptionError` keeps the fail-closed contract legible to callers.
94
97
  *
95
- * @param data {Json | Blob | Uint8Array}
96
- * @param [contentType] {string}
97
- * @returns {Promise<object>}
98
+ * @param doc {unknown}
99
+ * @param context {string} the operation in progress (`read` / `update`),
100
+ * for the message
101
+ * @returns {asserts doc is IEncryptedDocument}
98
102
  */
99
- private _toContent;
103
+ private _assertEnvelope;
100
104
  /**
101
- * Wraps binary bytes as an EDV document content record, enforcing the
102
- * single-document size cap.
105
+ * Splits a caller value into a decrypted EDV document `{ content, meta }`,
106
+ * carrying the plaintext content type and inline-encoding discriminator in
107
+ * `meta`. Three cases:
103
108
  *
104
- * @param bytes {Uint8Array}
105
- * @param contentType {string}
106
- * @returns {object}
109
+ * 1. JSON object/array to `content` verbatim, `meta = { contentType }` (no
110
+ * `encoding`); the shape of `content` is never inspected on read, so a
111
+ * caller object shaped like `{ text }` / `{ bytes }` round-trips as itself.
112
+ * 2. Text (`Blob`/`Uint8Array` of a text-family type that is valid UTF-8)
113
+ * to `content = { text }`, `meta = { contentType, encoding: 'utf-8' }`;
114
+ * stored legibly with no base64 inflation.
115
+ * 3. Binary (any other `Blob`/`Uint8Array`) to `content = { bytes: base64 }`,
116
+ * `meta = { contentType, encoding: 'base64' }`.
117
+ *
118
+ * A bare primitive is rejected (mirroring the plaintext `prepareBody`
119
+ * contract). The binary/text content type resolves as
120
+ * `contentType || blob.type || guessContentTypeFromId(id) || octet-stream`,
121
+ * mirroring `prepareBody`.
122
+ *
123
+ * @param data {ResourceData}
124
+ * @param [contentType] {string} caller-supplied content type
125
+ * @param [id] {string} resource id, for the extension guess
126
+ * @returns {Promise<{ content: Record<string, unknown>; meta:
127
+ * Record<string, unknown> }>}
107
128
  */
108
- private _blobContent;
129
+ private _toDocument;
109
130
  /**
110
- * Reconstructs a caller value from decrypted EDV document content: a `Blob`
111
- * for a wrapped blob record, otherwise the JSON content verbatim.
131
+ * Reconstructs a caller value from a decrypted EDV document, discriminating
132
+ * on `meta.encoding`:
133
+ *
134
+ * - `'utf-8'` to a `Blob` typed `meta.contentType` from `content.text`.
135
+ * - `'base64'` to a `Blob` typed `meta.contentType` from `content.bytes`.
136
+ * - absent (or `meta` absent) to `content` returned verbatim as JSON.
137
+ *
138
+ * A malformed inner shape (an encoding that does not match its container key's
139
+ * type) throws {@link EncryptionError} -- the decrypted-document analogue of
140
+ * `_assertEnvelope`'s outer guard.
112
141
  *
113
142
  * @param content {unknown}
143
+ * @param [meta] {Record<string, unknown>}
114
144
  * @returns {Json | Blob}
115
145
  */
116
- private _fromContent;
146
+ private _fromDocument;
117
147
  }
118
- /** The per-collection key material an EDV codec is built from. */
148
+ /**
149
+ * The per-collection key material an EDV codec is built from.
150
+ */
119
151
  export interface EdvKeys {
120
152
  keyAgreementKey: IKeyAgreementKey;
121
153
  keyResolver: IKeyResolver;
@@ -139,8 +171,8 @@ export interface EdvKeys {
139
171
  * `{ keyAgreementKey, keyResolver }`, or `null` if this client holds no keys
140
172
  * for it (fail-closed -- not a plaintext signal)
141
173
  * @param [options.contentType] {string} stored envelope content type;
142
- * defaults to `application/json`. Pass `EDV_CONTENT_TYPE`
143
- * (`application/edv+json`) against a server that registers an
174
+ * defaults to `application/json`. Pass `JOSE_CONTENT_TYPE`
175
+ * (`application/jose+json`) against a server that registers an
144
176
  * `application/*+json` parser.
145
177
  * @param [options.maxBlobBytes] {number} single-document binary cap (default
146
178
  * 1 MiB)
@@ -154,5 +186,4 @@ export declare function createEdvEncryption({ resolveKeys, contentType, maxBlobB
154
186
  contentType?: string;
155
187
  maxBlobBytes?: number;
156
188
  }): EncryptionProvider;
157
- export { EDV_CONTENT_TYPE };
158
189
  //# sourceMappingURL=EdvCodec.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"EdvCodec.d.ts","sourceRoot":"","sources":["../../src/edv/EdvCodec.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,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,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