@teepin/sdk 0.2.1 → 0.3.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 (134) hide show
  1. package/README.md +41 -36
  2. package/dist/cjs/client.js +42 -4
  3. package/dist/cjs/client.js.map +1 -1
  4. package/dist/cjs/direct/bytes.js +50 -0
  5. package/dist/cjs/direct/bytes.js.map +1 -0
  6. package/dist/cjs/direct/common.js +167 -0
  7. package/dist/cjs/direct/common.js.map +1 -0
  8. package/dist/cjs/direct/downloads-plan.js +127 -0
  9. package/dist/cjs/direct/downloads-plan.js.map +1 -0
  10. package/dist/cjs/direct/engine.js +405 -0
  11. package/dist/cjs/direct/engine.js.map +1 -0
  12. package/dist/cjs/direct/formats.js +44 -0
  13. package/dist/cjs/direct/formats.js.map +1 -0
  14. package/dist/cjs/direct/hpke.js +275 -0
  15. package/dist/cjs/direct/hpke.js.map +1 -0
  16. package/dist/cjs/direct/journal.js +80 -0
  17. package/dist/cjs/direct/journal.js.map +1 -0
  18. package/dist/cjs/direct/large.js +850 -0
  19. package/dist/cjs/direct/large.js.map +1 -0
  20. package/dist/cjs/direct/reads.js +1314 -0
  21. package/dist/cjs/direct/reads.js.map +1 -0
  22. package/dist/cjs/direct/sha256.js +122 -0
  23. package/dist/cjs/direct/sha256.js.map +1 -0
  24. package/dist/cjs/direct/tws1.js +480 -0
  25. package/dist/cjs/direct/tws1.js.map +1 -0
  26. package/dist/cjs/direct/uploads.js +1706 -0
  27. package/dist/cjs/direct/uploads.js.map +1 -0
  28. package/dist/cjs/errors.js +70 -13
  29. package/dist/cjs/errors.js.map +1 -1
  30. package/dist/cjs/index.js +5 -1
  31. package/dist/cjs/index.js.map +1 -1
  32. package/dist/cjs/links.js +195 -0
  33. package/dist/cjs/links.js.map +1 -0
  34. package/dist/cjs/node/downloads.js +835 -0
  35. package/dist/cjs/node/downloads.js.map +1 -0
  36. package/dist/cjs/node/journal.js +841 -0
  37. package/dist/cjs/node/journal.js.map +1 -0
  38. package/dist/cjs/node/uploads.js +219 -0
  39. package/dist/cjs/node/uploads.js.map +1 -0
  40. package/dist/cjs/node.js +26 -39
  41. package/dist/cjs/node.js.map +1 -1
  42. package/dist/cjs/storage.js +214 -184
  43. package/dist/cjs/storage.js.map +1 -1
  44. package/dist/cjs/transfer.js +18 -351
  45. package/dist/cjs/transfer.js.map +1 -1
  46. package/dist/esm/client.js +42 -4
  47. package/dist/esm/client.js.map +1 -1
  48. package/dist/esm/direct/bytes.js +42 -0
  49. package/dist/esm/direct/bytes.js.map +1 -0
  50. package/dist/esm/direct/common.js +155 -0
  51. package/dist/esm/direct/common.js.map +1 -0
  52. package/dist/esm/direct/downloads-plan.js +117 -0
  53. package/dist/esm/direct/downloads-plan.js.map +1 -0
  54. package/dist/esm/direct/engine.js +385 -0
  55. package/dist/esm/direct/engine.js.map +1 -0
  56. package/dist/esm/direct/formats.js +40 -0
  57. package/dist/esm/direct/formats.js.map +1 -0
  58. package/dist/esm/direct/hpke.js +262 -0
  59. package/dist/esm/direct/hpke.js.map +1 -0
  60. package/dist/esm/direct/journal.js +75 -0
  61. package/dist/esm/direct/journal.js.map +1 -0
  62. package/dist/esm/direct/large.js +816 -0
  63. package/dist/esm/direct/large.js.map +1 -0
  64. package/dist/esm/direct/reads.js +1275 -0
  65. package/dist/esm/direct/reads.js.map +1 -0
  66. package/dist/esm/direct/sha256.js +118 -0
  67. package/dist/esm/direct/sha256.js.map +1 -0
  68. package/dist/esm/direct/tws1.js +460 -0
  69. package/dist/esm/direct/tws1.js.map +1 -0
  70. package/dist/esm/direct/uploads.js +1660 -0
  71. package/dist/esm/direct/uploads.js.map +1 -0
  72. package/dist/esm/errors.js +64 -11
  73. package/dist/esm/errors.js.map +1 -1
  74. package/dist/esm/index.js +1 -0
  75. package/dist/esm/index.js.map +1 -1
  76. package/dist/esm/links.js +189 -0
  77. package/dist/esm/links.js.map +1 -0
  78. package/dist/esm/node/downloads.js +829 -0
  79. package/dist/esm/node/downloads.js.map +1 -0
  80. package/dist/esm/node/journal.js +824 -0
  81. package/dist/esm/node/journal.js.map +1 -0
  82. package/dist/esm/node/uploads.js +187 -0
  83. package/dist/esm/node/uploads.js.map +1 -0
  84. package/dist/esm/node.js +17 -14
  85. package/dist/esm/node.js.map +1 -1
  86. package/dist/esm/storage.js +214 -184
  87. package/dist/esm/storage.js.map +1 -1
  88. package/dist/esm/transfer.js +19 -349
  89. package/dist/esm/transfer.js.map +1 -1
  90. package/dist/types/client.d.ts +45 -4
  91. package/dist/types/client.d.ts.map +1 -1
  92. package/dist/types/direct/bytes.d.ts +11 -0
  93. package/dist/types/direct/bytes.d.ts.map +1 -0
  94. package/dist/types/direct/common.d.ts +47 -0
  95. package/dist/types/direct/common.d.ts.map +1 -0
  96. package/dist/types/direct/downloads-plan.d.ts +75 -0
  97. package/dist/types/direct/downloads-plan.d.ts.map +1 -0
  98. package/dist/types/direct/engine.d.ts +191 -0
  99. package/dist/types/direct/engine.d.ts.map +1 -0
  100. package/dist/types/direct/formats.d.ts +9 -0
  101. package/dist/types/direct/formats.d.ts.map +1 -0
  102. package/dist/types/direct/hpke.d.ts +55 -0
  103. package/dist/types/direct/hpke.d.ts.map +1 -0
  104. package/dist/types/direct/journal.d.ts +55 -0
  105. package/dist/types/direct/journal.d.ts.map +1 -0
  106. package/dist/types/direct/large.d.ts +170 -0
  107. package/dist/types/direct/large.d.ts.map +1 -0
  108. package/dist/types/direct/reads.d.ts +306 -0
  109. package/dist/types/direct/reads.d.ts.map +1 -0
  110. package/dist/types/direct/sha256.d.ts +16 -0
  111. package/dist/types/direct/sha256.d.ts.map +1 -0
  112. package/dist/types/direct/tws1.d.ts +157 -0
  113. package/dist/types/direct/tws1.d.ts.map +1 -0
  114. package/dist/types/direct/uploads.d.ts +461 -0
  115. package/dist/types/direct/uploads.d.ts.map +1 -0
  116. package/dist/types/errors.d.ts +47 -8
  117. package/dist/types/errors.d.ts.map +1 -1
  118. package/dist/types/index.d.ts +1 -0
  119. package/dist/types/index.d.ts.map +1 -1
  120. package/dist/types/links.d.ts +86 -0
  121. package/dist/types/links.d.ts.map +1 -0
  122. package/dist/types/node/downloads.d.ts +73 -0
  123. package/dist/types/node/downloads.d.ts.map +1 -0
  124. package/dist/types/node/journal.d.ts +162 -0
  125. package/dist/types/node/journal.d.ts.map +1 -0
  126. package/dist/types/node/uploads.d.ts +86 -0
  127. package/dist/types/node/uploads.d.ts.map +1 -0
  128. package/dist/types/node.d.ts +4 -2
  129. package/dist/types/node.d.ts.map +1 -1
  130. package/dist/types/storage.d.ts +107 -64
  131. package/dist/types/storage.d.ts.map +1 -1
  132. package/dist/types/transfer.d.ts +14 -23
  133. package/dist/types/transfer.d.ts.map +1 -1
  134. package/package.json +2 -2
@@ -0,0 +1,306 @@
1
+ import { type TeepinClient } from '../client.js';
2
+ import { TeepinError } from '../errors.js';
3
+ import type { ObjectInfo, StorageObject } from '../storage.js';
4
+ /** The server's read window until it shows its own: 64 MiB of stored bytes. */
5
+ export declare const DEFAULT_WINDOW: number;
6
+ /** How long a data key stays cached, in ms, unless the client says. */
7
+ export declare const DEFAULT_KEY_CACHE_TTL_MS = 600000;
8
+ /** The error for reading an object still in the API's old stage (a session with source "api"): it can't be read yet. */
9
+ export declare function stagedError(key: string): TeepinError;
10
+ /** A controller that aborts with parent's reason, and a function that unlinks it once it is no longer needed. */
11
+ export declare function linked(parent?: AbortSignal): {
12
+ ctl: AbortController;
13
+ unlink: () => void;
14
+ };
15
+ /** One signed request to the storage network. */
16
+ export declare class Signed {
17
+ readonly url: string;
18
+ readonly headers: Record<string, string>;
19
+ /** When the signature expires (ms since the epoch); undefined when the session didn't say. */
20
+ readonly expires: number | undefined;
21
+ /** Bytes before the object's own (a packed object's needle). */
22
+ readonly prefix: number;
23
+ /** The object's stored bytes it covers, inclusive. */
24
+ readonly first: number;
25
+ readonly last: number;
26
+ constructor(url: string, headers: Record<string, string>,
27
+ /** When the signature expires (ms since the epoch); undefined when the session didn't say. */
28
+ expires: number | undefined,
29
+ /** Bytes before the object's own (a packed object's needle). */
30
+ prefix: number,
31
+ /** The object's stored bytes it covers, inclusive. */
32
+ first: number, last: number);
33
+ static of(d: Record<string, unknown>): Signed;
34
+ /** The bytes it answers: the prefix and the object's own. */
35
+ get length(): number;
36
+ /** Whether it can still be used: not within a minute of its expiry. */
37
+ fresh(): boolean;
38
+ }
39
+ /** One read session. dek is this session's own copy of the data key. */
40
+ export declare class Session {
41
+ readonly bucket: string;
42
+ readonly key: string;
43
+ readonly version: string;
44
+ readonly size: number;
45
+ readonly storedSize: number;
46
+ readonly etag: string;
47
+ readonly sha256: string;
48
+ readonly contentType: string;
49
+ readonly metadata: Record<string, string>;
50
+ readonly format: string;
51
+ readonly source: string;
52
+ readonly uploadedAt?: Date;
53
+ dek: Uint8Array | null;
54
+ readonly ad: Uint8Array;
55
+ readonly requests: Signed[];
56
+ constructor(bucket: string, d: Record<string, unknown>);
57
+ /** Still in the API's old stage: not readable yet (stagedError). */
58
+ get staged(): boolean;
59
+ get packed(): boolean;
60
+ /** The window it signs: its last request (a later window's first one is the header). */
61
+ get window(): Signed;
62
+ get needsKey(): boolean;
63
+ /** Whether the whole object's SHA-256 can be checked (not a legacy composite of parts). */
64
+ get checkable(): boolean;
65
+ /** Zeroes this session's copy of the key. */
66
+ forget(): void;
67
+ /** The object's details, as statObject would give them. */
68
+ object(): StorageObject;
69
+ }
70
+ /**
71
+ * Data keys by bucket and key, each for one version, for ttl ms (0: none are kept). It hands out copies, so zeroing one
72
+ * never breaks a read in progress, and zeroes its own on expiry, replacement, drop and clear.
73
+ */
74
+ export declare class KeyCache {
75
+ readonly ttl: number;
76
+ /** The clock, in ms (monotonic); a test may move it. */
77
+ now: () => number;
78
+ private readonly entries;
79
+ constructor(ttl: number);
80
+ private static id;
81
+ /** The cached version and a copy of its key, or undefined. */
82
+ get(bucket: string, key: string): {
83
+ version: string;
84
+ key: Uint8Array;
85
+ } | undefined;
86
+ /** Keeps a copy of dek for this version (the caller keeps its own). */
87
+ put(bucket: string, key: string, version: string, dek: Uint8Array): void;
88
+ drop(bucket: string, key: string): void;
89
+ clear(): void;
90
+ get size(): number;
91
+ }
92
+ /** One read's failures since its last verified bytes, and what each means. */
93
+ export declare class Tries {
94
+ readonly reads: DirectReads;
95
+ readonly s: Session;
96
+ readonly signal?: AbortSignal | undefined;
97
+ passing: number;
98
+ bad: number;
99
+ notFound: boolean;
100
+ constructor(reads: DirectReads, s: Session, signal?: AbortSignal | undefined);
101
+ progressed(): void;
102
+ /** Resolves when the read should try again (after any wait); throws otherwise. An abort is never tried again. */
103
+ failed(err: unknown): Promise<void>;
104
+ }
105
+ /** A signed GET's body as it arrives, read a piece at a time; each read waits at most idleMs for bytes. */
106
+ export declare class Body {
107
+ private readonly ctl;
108
+ private readonly unlink;
109
+ private readonly idleMs;
110
+ private readonly signal?;
111
+ private readonly reader?;
112
+ private rest;
113
+ private ended;
114
+ private closed;
115
+ constructor(response: Response, ctl: AbortController, unlink: () => void, idleMs: number, signal?: AbortSignal | undefined);
116
+ /** Up to max bytes (fewer is fine), empty at the end. A body that breaks off throws ConnectionError. */
117
+ read(max: number): Promise<Uint8Array>;
118
+ /** n bytes, or fewer where the body ends. */
119
+ readExact(n: number): Promise<Uint8Array>;
120
+ private next;
121
+ /** Ends the request: a body not read to its end is cancelled and its connection dropped. Never waits. */
122
+ close(): void;
123
+ }
124
+ /** A read about to stream: its session, its own key copy, and the object's bytes [a, b) it reads. */
125
+ export interface Opened {
126
+ session: Session;
127
+ dek: Uint8Array | null;
128
+ a: number;
129
+ b: number;
130
+ /** A range was asked for (so the whole object's SHA-256 isn't checked). */
131
+ ranged: boolean;
132
+ }
133
+ /** Where a download writes: any offset, in any order. sha256, when it can read back what it holds, hashes its first size bytes. */
134
+ export interface Target {
135
+ write(offset: number, data: Uint8Array): void | Promise<void>;
136
+ sha256?(size: number): Promise<string>;
137
+ }
138
+ export interface DownloadParams {
139
+ /** Plaintext bytes per range inside a window (0: one range per window). */
140
+ partSize: number;
141
+ /** Ranges fetched at once. */
142
+ concurrency: number;
143
+ onProgress?: (done: number, total: number) => void;
144
+ /** Check the whole object's SHA-256. */
145
+ verify: boolean;
146
+ signal?: AbortSignal;
147
+ }
148
+ /**
149
+ * Reads through read sessions, for one client. The methods tests replace (as the Python tests patch _reads.py) are
150
+ * call, session, window, open and plaintext.
151
+ */
152
+ export declare class DirectReads {
153
+ readonly client: TeepinClient;
154
+ readonly keys: KeyCache;
155
+ constructor(client: TeepinClient);
156
+ /** Zeroes the cached data keys. */
157
+ close(): void;
158
+ /** One read session (object/read), retried by the client as a safe call. */
159
+ call(bucket: string, key: string, off: number, length: number, includeKey: boolean, signal?: AbortSignal): Promise<Session>;
160
+ /**
161
+ * A read's first session, with the data key: from the cache when it holds this version's, so the server needn't send
162
+ * it again. An object still in the old stage throws stagedError.
163
+ */
164
+ session(bucket: string, key: string, off?: number, length?: number, signal?: AbortSignal): Promise<Session>;
165
+ /**
166
+ * Read sessions for many objects, signed 1,000 to a request (objects/read): a Session, or the error for an object
167
+ * that can't be read (each on its own; stagedError for one still in the old stage). Each Session holds its own key;
168
+ * the caller forgets it.
169
+ */
170
+ sessions(bucket: string, keys: readonly string[], signal?: AbortSignal): Promise<Map<string, Session | TeepinError>>;
171
+ /** A later window of the same version, signed without the key. */
172
+ window(s0: Session, off: number, length: number, signal?: AbortSignal): Promise<Session>;
173
+ /** A signed GET, its headers in (the client's timeout), its body to read; Expired for a signature about to expire. */
174
+ open(r: Signed, signal?: AbortSignal): Promise<Body>;
175
+ /**
176
+ * The object's bytes [a, b), each verified before it is yielded; with check (a whole read), the object's SHA-256
177
+ * too, throwing ChecksumMismatchError after the last bytes.
178
+ */
179
+ plaintext(s: Session, dek: Uint8Array | null, a: number, b: number, check: boolean, signal?: AbortSignal): AsyncGenerator<Uint8Array, void, undefined>;
180
+ /** A packed object, its needle checked and decrypted whole; or a teepin-v1 object in its own blob, read whole and opened. */
181
+ private whole;
182
+ private packed;
183
+ private tws1Blob;
184
+ /** The object's keys from the header a later window's session signs first; its commitment is checked. */
185
+ private header;
186
+ /** Stored bytes [a, b) of an object in its own blob, as stored. */
187
+ private rawBlob;
188
+ /** How a download splits: one range per server window (partSize may split finer), or one range for an object read whole. */
189
+ ranges(s: Session, partSize: number): [number, number][];
190
+ /**
191
+ * Writes the whole object to the target open makes (once per attempt, given the object's details): windows in
192
+ * parallel, each pinned to the first session's version. A SHA-256 mismatch is tried again once.
193
+ */
194
+ download(bucket: string, key: string, open: (obj: StorageObject) => Target, p: DownloadParams): Promise<StorageObject>;
195
+ private writeRange;
196
+ /**
197
+ * The first part of getObject: the session, checked, and the range [a, b) to read (start and end inclusive, end
198
+ * undefined for to the end); the bytes come from body.
199
+ */
200
+ get(bucket: string, key: string, start: number, end: number | undefined, ifMatch: string, signal?: AbortSignal): Promise<Opened>;
201
+ /** The verified bytes [a, b); the key copy is zeroed at the end, or when the reader stops early. */
202
+ body(s: Session, dek: Uint8Array | null, a: number, b: number, check: boolean, signal?: AbortSignal): AsyncGenerator<Uint8Array, void, undefined>;
203
+ /**
204
+ * The first part of openObject: the session, the key copy, the block (one window, or the whole object) and the
205
+ * alignment of a jump.
206
+ */
207
+ openFile(bucket: string, key: string, signal?: AbortSignal): Promise<{
208
+ session: Session;
209
+ dek: Uint8Array | null;
210
+ block: number;
211
+ align: number;
212
+ }>;
213
+ /** How an ObjectFile reads s: its block (one window, or the whole object) and the alignment of a jump. */
214
+ layout(s: Session): {
215
+ block: number;
216
+ align: number;
217
+ };
218
+ /** The verified bytes [a, b), joined; the whole object's SHA-256 is checked when that is what's asked for. */
219
+ fetch(s: Session, dek: Uint8Array | null, a: number, b: number, signal?: AbortSignal): Promise<Uint8Array>;
220
+ }
221
+ /** The route that opens a share link: a read session for the token, with no sign-in (section 26.2). */
222
+ export declare const LINK_READ_PATH = "/v1/storage/links/read";
223
+ /**
224
+ * Reads through a share link (section 26.3): the same engine and checks as DirectReads, with the link's read sessions
225
+ * (POST /v1/storage/links/read) in place of the authenticated ones. Every session carries the data key, so none is
226
+ * cached (the client's keyCacheTtl is 0), and every session after the first must be of the version the link first
227
+ * opened: ObjectChangedError otherwise. The bucket and key the engine passes around are unused: the token names the
228
+ * object.
229
+ *
230
+ * The first session takes the link's token. Each answer brings a continuation, and every later session takes the
231
+ * newest one instead: it reads only the version first opened (the server answers 412 for a replaced object, which is
232
+ * ObjectChangedError here), lasts 30 minutes from its issue, and never past the link's expiry plus 24 hours, so a
233
+ * download that began while the link was valid can finish after it expires. A continuation left idle too long is
234
+ * refused; the link's token is then tried once more, which opens only while the link itself is valid.
235
+ */
236
+ export declare class LinkReads extends DirectReads {
237
+ private readonly token;
238
+ /** The version the link first opened (set by openLink); '' until then. */
239
+ version: string;
240
+ /** From the link's answers: how the link is meant to be offered, and the name to save the object as. */
241
+ disposition: string;
242
+ fileName: string;
243
+ /** The newest continuation, and when it stops working (ms); '' until the first answer. */
244
+ private continuation;
245
+ private continuationEnds;
246
+ constructor(client: TeepinClient, token: string);
247
+ /** One read session for the link, retried by the client as a safe call; the version pinned once it is known. */
248
+ call(bucket: string, _key: string, off: number, length: number, _includeKey: boolean, signal?: AbortSignal): Promise<Session>;
249
+ /** POST /v1/storage/links/read with the link's token or a continuation. */
250
+ private openWith;
251
+ /** Keeps an answer's continuation when it lasts at least as long as the one held (windows may answer out of order). */
252
+ private keep;
253
+ /** A read's first session, always with its key (nothing is cached); an object still in the old stage throws stagedError. */
254
+ session(bucket: string, key: string, off?: number, length?: number, signal?: AbortSignal): Promise<Session>;
255
+ }
256
+ /** Everything chunks yields, joined. */
257
+ export declare function collect(chunks: AsyncIterable<Uint8Array>): Promise<Uint8Array>;
258
+ /**
259
+ * A ReadableStream of a read's verified chunks, made only as they are asked for. An abort of signal, or a cancel, ends
260
+ * it at once: the stream errors with the reason, the read's requests stop, and release runs (it zeroes the read's key
261
+ * copy), as it does when the stream ends.
262
+ */
263
+ export declare function readable(chunks: (signal: AbortSignal) => AsyncGenerator<Uint8Array, void, undefined>, signal?: AbortSignal, release?: () => void): ReadableStream<Uint8Array>;
264
+ /** A stream's bytes, joined; its error, as it is. */
265
+ export declare function drain(body: ReadableStream<Uint8Array>): Promise<Uint8Array>;
266
+ /**
267
+ * An object open for reading at any offset (TEEPIN-STORAGE-DESIGN.md section 22.5): read(offset, length), size, info
268
+ * and close().
269
+ *
270
+ * Reading straight on (each read starting where the last ended) fetches a block at a time (one window, 64 MiB on the
271
+ * storage network) and the next prefetch blocks ahead, each signed as it is fetched; a read somewhere else fetches
272
+ * only what it needs, in whole segments. Up to prefetch + 2 blocks are held. Every byte is verified before it is read,
273
+ * and every block is read from the version first opened: ObjectChangedError if the object is replaced. Close it when
274
+ * done: that stops its fetches and zeroes its copy of the data key.
275
+ */
276
+ export declare class ObjectFile {
277
+ /** The object's size in bytes. */
278
+ readonly size: number;
279
+ /** The object's details, as headObject gives them. */
280
+ readonly info: ObjectInfo;
281
+ private fetch;
282
+ private readonly block;
283
+ private readonly align;
284
+ private readonly prefetch;
285
+ private readonly onClose?;
286
+ private readonly signal?;
287
+ private readonly ctl;
288
+ private readonly unlink;
289
+ private readonly blocks;
290
+ private end;
291
+ private isClosed;
292
+ constructor(fetch: (a: number, b: number, signal: AbortSignal) => Promise<Uint8Array>, size: number, block: number, align: number, info: ObjectInfo, prefetch?: number, onClose?: () => void, signal?: AbortSignal);
293
+ get closed(): boolean;
294
+ /** Up to length bytes from offset: fewer only at the object's end, none past it. */
295
+ read(offset: number, length: number): Promise<Uint8Array>;
296
+ /** Stops every fetch and zeroes this file's copy of the data key. Reads after it fail. */
297
+ close(): void;
298
+ private checkOpen;
299
+ /** Block i's fetch, started if it isn't, and made the newest; the oldest past the bound are dropped. */
300
+ private submit;
301
+ private get;
302
+ private ahead;
303
+ /** n bytes from pos, fetched alone, whole segments only. */
304
+ private some;
305
+ }
306
+ //# sourceMappingURL=reads.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reads.d.ts","sourceRoot":"","sources":["../../../src/direct/reads.ts"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AE,WAAW;IAetB,IAAI,MAAM,IAAI,OAAO,CAEpB;IAED,oFAAoF;IAC9E,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IA0C/D,0FAA0F;IAC1F,KAAK,IAAI,IAAI;IASb,OAAO,CAAC,SAAS;IAKjB,wGAAwG;IACxG,OAAO,CAAC,MAAM;YA+BA,GAAG;IAUjB,OAAO,CAAC,KAAK;IAKb,4DAA4D;YAC9C,IAAI;CAMnB"}
@@ -0,0 +1,16 @@
1
+ /** An incremental SHA-256: update with each piece in order, then digest once. */
2
+ export declare class Sha256 {
3
+ private readonly h;
4
+ private readonly w;
5
+ private readonly block;
6
+ private filled;
7
+ private bytes;
8
+ private done;
9
+ update(data: Uint8Array): this;
10
+ /** The 32-byte digest. The hash can't be updated after. */
11
+ digest(): Uint8Array;
12
+ /** The digest as lowercase hex. */
13
+ hexDigest(): string;
14
+ private compress;
15
+ }
16
+ //# sourceMappingURL=sha256.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sha256.d.ts","sourceRoot":"","sources":["../../../src/direct/sha256.ts"],"names":[],"mappings":"AAmBA,iFAAiF;AACjF,qBAAa,MAAM;IACjB,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAyB;IAC3C,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAuB;IACzC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAsB;IAC5C,OAAO,CAAC,MAAM,CAAK;IACnB,OAAO,CAAC,KAAK,CAAK;IAClB,OAAO,CAAC,IAAI,CAAS;IAErB,MAAM,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI;IAqB9B,2DAA2D;IAC3D,MAAM,IAAI,UAAU;IAiBpB,mCAAmC;IACnC,SAAS,IAAI,MAAM;IAInB,OAAO,CAAC,QAAQ;CA+CjB"}
@@ -0,0 +1,157 @@
1
+ import { DataIntegrityError } from '../errors.js';
2
+ /**
3
+ * Data that failed a check (errors.ts): reason is "segment", "commitment", "needle", "truncated" or "format" here.
4
+ * Re-exported, as this module threw its own before the read surface landed.
5
+ */
6
+ export { DataIntegrityError };
7
+ export declare const HEADER_SIZE = 72;
8
+ export declare const SEGMENT_SIZE: number;
9
+ export declare const TAG_SIZE = 16;
10
+ export declare const STORED_SEGMENT_SIZE: number;
11
+ export declare const KEY_SIZE = 32;
12
+ export declare const SALT_SIZE = 32;
13
+ /** The most segments one object may have (the index is a uint32). */
14
+ export declare const MAX_SEGMENTS: number;
15
+ export declare const NEEDLE_HEADER_SIZE = 64;
16
+ /**
17
+ * Where fresh salts come from. Only tests replace salt, to reproduce the shared vectors; the public functions take no
18
+ * salt, so callers can't choose one, and a test checks that no file under src assigns it. Shared state is safe here,
19
+ * unlike for HPKE's ephemeral keys (hpke.sealWith): every object has a fresh random data key, so even a fixed salt
20
+ * never repeats a segment key and nonce.
21
+ */
22
+ export declare const testHooks: {
23
+ salt: () => Uint8Array;
24
+ };
25
+ /** A fresh 32-byte data key; the caller zeroes it (fill(0)) when done. */
26
+ export declare function newDataKey(): Uint8Array;
27
+ /** How many segments an object of this size has: at least one, since an empty object is one empty last segment. */
28
+ export declare function segments(plaintextSize: number): number;
29
+ /** The size of the stored object, from the plaintext's size alone. */
30
+ export declare function storedSize(plaintextSize: number): number;
31
+ /** The keys derived from a data key and an object's header. */
32
+ export declare class Keys {
33
+ private readonly aad;
34
+ private readonly commit;
35
+ private readonly aead;
36
+ private readonly prefix;
37
+ private constructor();
38
+ /**
39
+ * The keys for an object's header. Given only the header's first 40 bytes, the derived commitment completes it (how
40
+ * a new header is made); a full header's commitment is not checked here, openHeader does that.
41
+ */
42
+ static derive(dek: Uint8Array, header: Uint8Array): Promise<Keys>;
43
+ /** The object's 72-byte header (a copy). */
44
+ get header(): Uint8Array;
45
+ /** The commitment derived from the data key (a copy); in a valid header it is the last 32 bytes. */
46
+ get commitment(): Uint8Array;
47
+ /** Segment index's nonce: the prefix, the index (uint32 big-endian) and 1 on the last segment, else 0. */
48
+ nonce(index: number, last: boolean): Uint8Array;
49
+ /** One segment, sealed: its ciphertext and tag. */
50
+ seal(index: number, last: boolean, plain: Uint8Array): Promise<Uint8Array>;
51
+ /** One segment, opened; DataIntegrityError if it fails authentication. */
52
+ open(index: number, last: boolean, sealed: Uint8Array): Promise<Uint8Array>;
53
+ }
54
+ /** A new object's header, with a fresh salt and its commitment, and the keys to seal its segments. */
55
+ export declare function newHeader(dek: Uint8Array): Promise<{
56
+ header: Uint8Array;
57
+ keys: Keys;
58
+ }>;
59
+ /** The keys for an existing object, after checking its header and, in constant time, that the data key matches its commitment. */
60
+ export declare function openHeader(dek: Uint8Array, header: Uint8Array): Promise<Keys>;
61
+ /** A whole object, encrypted with a fresh salt. */
62
+ export declare function encrypt(dek: Uint8Array, plaintext: Uint8Array): Promise<Uint8Array>;
63
+ /** A whole object, decrypted and verified. */
64
+ export declare function decrypt(dek: Uint8Array, stored: Uint8Array): Promise<Uint8Array>;
65
+ /** The stored bytes that hold a plaintext range: whole segments only. */
66
+ export interface Range {
67
+ /** The index of the first segment to fetch. */
68
+ readonly firstSegment: number;
69
+ /** Where that segment starts in the stored object. */
70
+ readonly storedOffset: number;
71
+ /** How many stored bytes to fetch. */
72
+ readonly storedLength: number;
73
+ /** Plaintext bytes to drop from the front of the decrypted segments. */
74
+ readonly skip: number;
75
+ /** Plaintext bytes to return after skip. */
76
+ readonly length: number;
77
+ }
78
+ /** The segments holding plaintext bytes [offset, offset + length). */
79
+ export declare function locate(plaintextSize: number, offset: number, length: number): Range;
80
+ /** A located range, decrypted from exactly its stored bytes. */
81
+ export declare function decryptRange(keys: Keys, plaintextSize: number, r: Range, stored: Uint8Array): Promise<Uint8Array>;
82
+ /** [stored offset, stored length] of segment index. */
83
+ export declare function segmentAt(plaintextSize: number, index: number): [offset: number, length: number];
84
+ /** One part of a large object: where its plaintext and stored bytes are. */
85
+ export interface Part {
86
+ readonly number: number;
87
+ readonly plainFirst: number;
88
+ readonly plainSize: number;
89
+ /** Part 1 starts at 0, with the header. */
90
+ readonly storedFirst: number;
91
+ readonly storedSize: number;
92
+ }
93
+ /** How many parts parts() makes, without making them. */
94
+ export declare function partCount(plaintextSize: number, partSize: number): number;
95
+ /** Every part of an object of plaintextSize cut into partSize plaintext bytes (a multiple of 64 KiB). */
96
+ export declare function parts(plaintextSize: number, partSize: number): Part[];
97
+ /** Part number (1-based) of the layout parts() makes. */
98
+ export declare function partOf(plaintextSize: number, partSize: number, number: number): Part;
99
+ /** One large object's encryption, sealed a part at a time in any order. */
100
+ export declare class Stream {
101
+ readonly size: number;
102
+ readonly partSize: number;
103
+ readonly partCount: number;
104
+ private readonly keys;
105
+ private readonly segmentCount;
106
+ constructor(keys: Keys, size: number, partSize: number);
107
+ /** A new stream, with a fresh header. */
108
+ static create(dek: Uint8Array, size: number, partSize: number): Promise<Stream>;
109
+ /** The stream an earlier header began, to seal its remaining parts. */
110
+ static resume(dek: Uint8Array, header: Uint8Array, size: number, partSize: number): Promise<Stream>;
111
+ /** The object's header (a copy): the start of part 1, kept to seal any part again after a restart. */
112
+ get header(): Uint8Array;
113
+ /** Part number, sealed from exactly its plaintext. */
114
+ sealPart(number: number, plain: Uint8Array): Promise<Uint8Array>;
115
+ }
116
+ /**
117
+ * A stream whose size isn't known yet (section 22.1, E2 b), sealed a part at a time in any order. Every part but the
118
+ * last holds exactly partSize plaintext bytes; the last holds 1 to partSize and is sealed as the last, so its final
119
+ * segment carries the last flag. For the same key, header and plaintext it seals exactly the bytes Stream would, so
120
+ * storage and readers can't tell the two apart.
121
+ */
122
+ export declare class OpenStream {
123
+ readonly partSize: number;
124
+ private readonly keys;
125
+ constructor(keys: Keys, partSize: number);
126
+ /** A new stream, with a fresh header. */
127
+ static create(dek: Uint8Array, partSize: number): Promise<OpenStream>;
128
+ /** The object's header (a copy): the start of part 1. */
129
+ get header(): Uint8Array;
130
+ /** Part number, sealed from exactly its plaintext; last says it ends the stream. */
131
+ sealPart(number: number, plain: Uint8Array, last: boolean): Promise<Uint8Array>;
132
+ /** sealPart as its pieces (the header first on part 1), so a caller can drop the plaintext before joining them. */
133
+ sealSegments(number: number, plain: Uint8Array, last: boolean): Promise<Uint8Array[]>;
134
+ }
135
+ /** The 64-byte header that precedes an object in a pack. */
136
+ export declare function needle(objectId: Uint8Array, stored: Uint8Array): Promise<Uint8Array>;
137
+ /** A pack being built: each object's needle, then its stored bytes. */
138
+ export declare class Pack {
139
+ private readonly chunks;
140
+ private length;
141
+ /** The pack's size so far, in bytes. */
142
+ get size(): number;
143
+ /**
144
+ * Appends an object's needle and a copy of its stored bytes; returns the offset of the stored bytes in the pack.
145
+ * Appends may overlap: each lands whole, and returns where its own bytes are.
146
+ */
147
+ appendNeedle(objectId: Uint8Array, stored: Uint8Array): Promise<number>;
148
+ /** The whole pack (await every appendNeedle first). */
149
+ bytes(): Uint8Array;
150
+ }
151
+ /** Checks that a needle names this object, its size and its stored bytes' SHA-256; DataIntegrityError otherwise. */
152
+ export declare function checkNeedle(head: Uint8Array, objectId: Uint8Array, stored: Uint8Array): Promise<void>;
153
+ /** The stored bytes (a copy) of the object at offset in a pack, after checking its needle. */
154
+ export declare function readNeedle(pack: Uint8Array, offset: number, objectId: Uint8Array, size: number): Promise<Uint8Array>;
155
+ /** A UUID string's 16 bytes (hyphens, braces and a urn:uuid: prefix are allowed). */
156
+ export declare function objectIdBytes(objectId: string): Uint8Array;
157
+ //# sourceMappingURL=tws1.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tws1.d.ts","sourceRoot":"","sources":["../../../src/direct/tws1.ts"],"names":[],"mappings":"AA+BA,OAAO,EAAE,kBAAkB,EAAe,MAAM,cAAc,CAAC;AAG/D;;;GAGG;AACH,OAAO,EAAE,kBAAkB,EAAE,CAAC;AAE9B,eAAO,MAAM,WAAW,KAAK,CAAC;AAC9B,eAAO,MAAM,YAAY,QAAU,CAAC;AACpC,eAAO,MAAM,QAAQ,KAAK,CAAC;AAC3B,eAAO,MAAM,mBAA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