@platform-sec/sensitive-string-core 0.6.0 → 0.6.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.
Files changed (153) hide show
  1. package/dist/bson.d.ts +28 -0
  2. package/dist/bson.d.ts.map +1 -0
  3. package/dist/bson.js +37 -0
  4. package/dist/bson.js.map +1 -0
  5. package/dist/classification.d.ts +69 -0
  6. package/dist/classification.d.ts.map +1 -0
  7. package/dist/classification.js +104 -0
  8. package/dist/classification.js.map +1 -0
  9. package/dist/compare.d.ts +36 -0
  10. package/dist/compare.d.ts.map +1 -0
  11. package/dist/compare.js +123 -0
  12. package/dist/compare.js.map +1 -0
  13. package/dist/context.d.ts +78 -0
  14. package/dist/context.d.ts.map +1 -0
  15. package/dist/context.js +110 -0
  16. package/dist/context.js.map +1 -0
  17. package/dist/derive.d.ts +110 -0
  18. package/dist/derive.d.ts.map +1 -0
  19. package/dist/derive.js +153 -0
  20. package/dist/derive.js.map +1 -0
  21. package/dist/destination.d.ts +120 -0
  22. package/dist/destination.d.ts.map +1 -0
  23. package/dist/destination.js +352 -0
  24. package/dist/destination.js.map +1 -0
  25. package/dist/deterministic.d.ts +145 -0
  26. package/dist/deterministic.d.ts.map +1 -0
  27. package/dist/deterministic.js +352 -0
  28. package/dist/deterministic.js.map +1 -0
  29. package/dist/dev-mode.d.ts +177 -0
  30. package/dist/dev-mode.d.ts.map +1 -0
  31. package/dist/dev-mode.js +503 -0
  32. package/dist/dev-mode.js.map +1 -0
  33. package/dist/environment.d.ts +181 -0
  34. package/dist/environment.d.ts.map +1 -0
  35. package/dist/environment.js +558 -0
  36. package/dist/environment.js.map +1 -0
  37. package/dist/errors.d.ts +23 -0
  38. package/dist/errors.d.ts.map +1 -0
  39. package/dist/errors.js +21 -0
  40. package/dist/errors.js.map +1 -0
  41. package/dist/global-state.d.ts +8 -0
  42. package/dist/global-state.d.ts.map +1 -0
  43. package/dist/global-state.js +22 -0
  44. package/dist/global-state.js.map +1 -0
  45. package/dist/hash.d.ts +74 -0
  46. package/dist/hash.d.ts.map +1 -0
  47. package/dist/hash.js +253 -0
  48. package/dist/hash.js.map +1 -0
  49. package/dist/hygiene.d.ts +242 -0
  50. package/dist/hygiene.d.ts.map +1 -0
  51. package/dist/hygiene.js +257 -0
  52. package/dist/hygiene.js.map +1 -0
  53. package/dist/index.d.ts +85 -0
  54. package/dist/index.d.ts.map +1 -0
  55. package/dist/index.js +233 -0
  56. package/dist/index.js.map +1 -0
  57. package/dist/mask.d.ts +51 -0
  58. package/dist/mask.d.ts.map +1 -0
  59. package/dist/mask.js +461 -0
  60. package/dist/mask.js.map +1 -0
  61. package/dist/own-property.d.ts +20 -0
  62. package/dist/own-property.d.ts.map +1 -0
  63. package/dist/own-property.js +34 -0
  64. package/dist/own-property.js.map +1 -0
  65. package/dist/patterns.d.ts +12 -0
  66. package/dist/patterns.d.ts.map +1 -0
  67. package/dist/patterns.js +19 -0
  68. package/dist/patterns.js.map +1 -0
  69. package/dist/policy.d.ts +51 -0
  70. package/dist/policy.d.ts.map +1 -0
  71. package/dist/policy.js +181 -0
  72. package/dist/policy.js.map +1 -0
  73. package/dist/probe.d.ts +141 -0
  74. package/dist/probe.d.ts.map +1 -0
  75. package/dist/probe.js +213 -0
  76. package/dist/probe.js.map +1 -0
  77. package/dist/redact-copy.d.ts +61 -0
  78. package/dist/redact-copy.d.ts.map +1 -0
  79. package/dist/redact-copy.js +217 -0
  80. package/dist/redact-copy.js.map +1 -0
  81. package/dist/redact.d.ts +141 -0
  82. package/dist/redact.d.ts.map +1 -0
  83. package/dist/redact.js +514 -0
  84. package/dist/redact.js.map +1 -0
  85. package/dist/redaction-marker.d.ts +48 -0
  86. package/dist/redaction-marker.d.ts.map +1 -0
  87. package/dist/redaction-marker.js +138 -0
  88. package/dist/redaction-marker.js.map +1 -0
  89. package/dist/redaction-observer.d.ts +108 -0
  90. package/dist/redaction-observer.d.ts.map +1 -0
  91. package/dist/redaction-observer.js +103 -0
  92. package/dist/redaction-observer.js.map +1 -0
  93. package/dist/redaction-scope.d.ts +21 -0
  94. package/dist/redaction-scope.d.ts.map +1 -0
  95. package/dist/redaction-scope.js +44 -0
  96. package/dist/redaction-scope.js.map +1 -0
  97. package/dist/reference.d.ts +101 -0
  98. package/dist/reference.d.ts.map +1 -0
  99. package/dist/reference.js +123 -0
  100. package/dist/reference.js.map +1 -0
  101. package/dist/regexp.d.ts +25 -0
  102. package/dist/regexp.d.ts.map +1 -0
  103. package/dist/regexp.js +61 -0
  104. package/dist/regexp.js.map +1 -0
  105. package/dist/release.d.ts +88 -0
  106. package/dist/release.d.ts.map +1 -0
  107. package/dist/release.js +108 -0
  108. package/dist/release.js.map +1 -0
  109. package/dist/reveal-budget.d.ts +148 -0
  110. package/dist/reveal-budget.d.ts.map +1 -0
  111. package/dist/reveal-budget.js +314 -0
  112. package/dist/reveal-budget.js.map +1 -0
  113. package/dist/revocation.d.ts +168 -0
  114. package/dist/revocation.d.ts.map +1 -0
  115. package/dist/revocation.js +541 -0
  116. package/dist/revocation.js.map +1 -0
  117. package/dist/sealing.d.ts +283 -0
  118. package/dist/sealing.d.ts.map +1 -0
  119. package/dist/sealing.js +523 -0
  120. package/dist/sealing.js.map +1 -0
  121. package/dist/sensitive-string.d.ts +919 -0
  122. package/dist/sensitive-string.d.ts.map +1 -0
  123. package/dist/sensitive-string.js +2260 -0
  124. package/dist/sensitive-string.js.map +1 -0
  125. package/dist/serialized.d.ts +33 -0
  126. package/dist/serialized.d.ts.map +1 -0
  127. package/dist/serialized.js +65 -0
  128. package/dist/serialized.js.map +1 -0
  129. package/dist/template.d.ts +69 -0
  130. package/dist/template.d.ts.map +1 -0
  131. package/dist/template.js +158 -0
  132. package/dist/template.js.map +1 -0
  133. package/dist/ttl.d.ts +104 -0
  134. package/dist/ttl.d.ts.map +1 -0
  135. package/dist/ttl.js +330 -0
  136. package/dist/ttl.js.map +1 -0
  137. package/dist/types.d.ts +859 -0
  138. package/dist/types.d.ts.map +1 -0
  139. package/dist/types.js +13 -0
  140. package/dist/types.js.map +1 -0
  141. package/dist/winston.d.ts +114 -0
  142. package/dist/winston.d.ts.map +1 -0
  143. package/dist/winston.js +170 -0
  144. package/dist/winston.js.map +1 -0
  145. package/dist/worker.d.ts +398 -0
  146. package/dist/worker.d.ts.map +1 -0
  147. package/dist/worker.js +861 -0
  148. package/dist/worker.js.map +1 -0
  149. package/dist/wrap.d.ts +287 -0
  150. package/dist/wrap.d.ts.map +1 -0
  151. package/dist/wrap.js +553 -0
  152. package/dist/wrap.js.map +1 -0
  153. package/package.json +10 -10
@@ -0,0 +1,398 @@
1
+ import { SensitiveStringError } from './errors.js';
2
+ import { SensitiveString } from './sensitive-string.js';
3
+ import type { RevealContext, SensitiveStringOptions, SensitivityClass, SerializedSensitiveString } from './types.js';
4
+ /**
5
+ * How a payload will be sent.
6
+ *
7
+ * `'clone'` is structured clone: `workerData`, `postMessage`, a `MessagePort`,
8
+ * and `BroadcastChannel`. `'json'` is `child_process` IPC, whose serializer
9
+ * disagrees with structured clone in both directions: it drops a function
10
+ * where the clone throws, and it turns a `Date` into a string and a `Map` into
11
+ * `{}` where the clone keeps all three. A payload validated for one is not
12
+ * validated for the other.
13
+ */
14
+ export type WorkerTransport = 'clone' | 'json';
15
+ /**
16
+ * The constraint on what a payload carries: every property an instance.
17
+ *
18
+ * Written over the caller's own keys rather than as an index signature, so an
19
+ * `interface` declaring the shape satisfies it. A `Record<string, ...>` would
20
+ * reject every interface for lacking an index signature, which is the shape
21
+ * a caller most naturally writes.
22
+ */
23
+ export type SensitiveValues<T = Record<string, unknown>> = {
24
+ readonly [K in keyof T]: SensitiveString<SensitivityClass>;
25
+ };
26
+ /** The shape a payload defaults to when the caller claims none. */
27
+ export type AnySensitiveValues = Record<string, SensitiveString<SensitivityClass>>;
28
+ /**
29
+ * The part of a reveal context that can cross an isolate boundary.
30
+ *
31
+ * `auditReveal` is a function, and functions do not clone, so it is not here.
32
+ */
33
+ export interface PortableRevealContext {
34
+ readonly name: string;
35
+ readonly reason?: string;
36
+ readonly tags?: Record<string, unknown>;
37
+ }
38
+ /**
39
+ * Options for `toWorkerPayload()`.
40
+ */
41
+ export interface WorkerPayloadOptions {
42
+ /**
43
+ * Identifies the destination in the audit record: a file path, a URL, or
44
+ * any stable name.
45
+ *
46
+ * Recorded, never verified. Both sides of the boundary are inside the same
47
+ * trust boundary, so a check would stop no attacker and would break one
48
+ * payload builder feeding a pool of differently named workers.
49
+ */
50
+ worker?: string | URL;
51
+ /** The context to authorize against and to carry. Defaults to the ambient context. */
52
+ context?: RevealContext;
53
+ /**
54
+ * Non-sensitive data carried alongside the values, checked against
55
+ * `transport`.
56
+ *
57
+ * A `SensitiveString` anywhere inside it is refused: it would arrive as
58
+ * `{ klass, label }` in silence, and `values` is where it belongs.
59
+ */
60
+ data?: unknown;
61
+ /**
62
+ * How the payload will be sent, which decides how `data` and the context's
63
+ * `tags` are validated. Defaults to `'clone'`.
64
+ *
65
+ * `'json'` rejects everything `'clone'` rejects and more, so a payload built
66
+ * under it is safe for either transport. The one mistake this option cannot
67
+ * catch is the omission: a `Date` in `data` passes the clone check and
68
+ * arrives at a forked child as a string.
69
+ */
70
+ transport?: WorkerTransport;
71
+ }
72
+ /** The wire form of each value, under the key it had. */
73
+ export type WorkerPayloadValues<T> = {
74
+ readonly [K in keyof T]: SerializedSensitiveString;
75
+ };
76
+ /**
77
+ * What `toWorkerPayload()` returns.
78
+ *
79
+ * ⚠️ Contains RAW (UNREDACTED) values, one per entry of `values`, in the wire
80
+ * format. Pass it to the `Worker` constructor or to `postMessage` as an
81
+ * expression rather than binding it, so the sender's copy is unreachable as
82
+ * soon as it is cloned.
83
+ *
84
+ * Mutable on purpose: `fromWorkerPayload()` deletes the raw values from it and
85
+ * marks it consumed, so that the object the thread shares stops holding
86
+ * plaintext once the instances have been rebuilt.
87
+ */
88
+ export interface WorkerPayload<T extends SensitiveValues<T> = AnySensitiveValues> {
89
+ readonly __sensitiveWorkerPayload: 1;
90
+ readonly values: WorkerPayloadValues<T>;
91
+ readonly context?: PortableRevealContext;
92
+ /** The authorizing context carried an `auditReveal` that could not cross. */
93
+ readonly audited: boolean;
94
+ readonly data?: unknown;
95
+ /** Set by `fromWorkerPayload()`. Present only on a consumed payload. */
96
+ consumed?: true;
97
+ }
98
+ /**
99
+ * Options for `fromWorkerPayload()` and `withWorkerPayload()`.
100
+ */
101
+ export interface FromWorkerPayloadOptions {
102
+ /**
103
+ * Installed as this side's audit hook.
104
+ *
105
+ * Required when the payload was built under an audited context and no
106
+ * ambient context on this side carries a hook, because the sender's hook
107
+ * was dropped at the boundary and a reveal here would otherwise go
108
+ * unrecorded after the sender asked for it to be recorded.
109
+ */
110
+ auditReveal?: RevealContext['auditReveal'];
111
+ /**
112
+ * Accept an audited payload with no hook on this side. Off by default.
113
+ *
114
+ * ⚠️ Every reveal in this scope then goes unrecorded even though the sender
115
+ * asked for it to be recorded. The `no-allow-unaudited` ESLint rule reports
116
+ * it, and an inline disable comment is the place for the reason.
117
+ */
118
+ allowUnaudited?: boolean;
119
+ /**
120
+ * Keys that must be present. A missing one throws at the boundary rather
121
+ * than arriving as `undefined` and failing later inside worker code.
122
+ */
123
+ require?: readonly string[];
124
+ /**
125
+ * Leave the raw values in the payload object. Off by default.
126
+ *
127
+ * With it, the payload keeps holding plaintext for as long as it is
128
+ * reachable, which for `workerData` is the life of the thread, and a second
129
+ * `fromWorkerPayload()` on it succeeds. Only for a payload that genuinely
130
+ * has to feed two consumers.
131
+ */
132
+ keepPayload?: boolean;
133
+ }
134
+ /** What `fromWorkerPayload()` returns. */
135
+ export interface ReceivedWorkerPayload<T extends SensitiveValues<T>> {
136
+ /** The rebuilt instances, under the keys they were sent with. */
137
+ readonly values: T;
138
+ /**
139
+ * The carried context with this side's audit hook attached, or a context
140
+ * named `'worker'` carrying the hook when the payload carried none. Always
141
+ * installable, so a caller never branches on `undefined`.
142
+ */
143
+ readonly context: RevealContext;
144
+ /** The non-sensitive `data` the sender attached, untouched. */
145
+ readonly data: unknown;
146
+ }
147
+ /**
148
+ * Raised when what `fromWorkerPayload()` was handed is not a payload, or holds
149
+ * an entry that is not a serialized sensitive value.
150
+ *
151
+ * The message describes the shape received and never its contents.
152
+ */
153
+ export declare class MalformedWorkerPayloadError extends SensitiveStringError {
154
+ readonly name = "MalformedWorkerPayloadError";
155
+ readonly code = "malformed-payload";
156
+ constructor(detail: string);
157
+ }
158
+ /**
159
+ * Raised when a payload is consumed a second time.
160
+ *
161
+ * The first `fromWorkerPayload()` deleted the raw values, so there is nothing
162
+ * left to rebuild.
163
+ *
164
+ * ⚠️ This is per copy, not per payload. Every transport clones, so a payload
165
+ * the sender posts to two workers arrives twice, whole, and each copy is
166
+ * consumable once; only the copy that was consumed, and anything it is passed
167
+ * on to, refuses. Consumption shortens how long *one thread* holds plaintext.
168
+ * It is not a use-once token, and nothing here makes it one: build a payload
169
+ * per destination, and remember the sender's own object still holds the
170
+ * values until it is unreachable.
171
+ */
172
+ export declare class ConsumedWorkerPayloadError extends SensitiveStringError {
173
+ readonly name = "ConsumedWorkerPayloadError";
174
+ readonly code = "consumed-payload";
175
+ constructor();
176
+ }
177
+ /**
178
+ * Raised when a key named in `require` is absent from the payload.
179
+ */
180
+ export declare class MissingWorkerValueError extends SensitiveStringError {
181
+ readonly key: string;
182
+ readonly name = "MissingWorkerValueError";
183
+ readonly code = "missing-value";
184
+ constructor(key: string);
185
+ }
186
+ /**
187
+ * Raised when a payload names a sensitivity class this thread has not
188
+ * registered.
189
+ *
190
+ * Policies are per isolate: a class registered with `registerPolicy()` on the
191
+ * main thread does not exist in a worker, and a `redact` function could not be
192
+ * carried in the payload even if functions cloned, since a payload that can
193
+ * install a policy can install one that returns its input. The worker's own
194
+ * bootstrap registers what it needs.
195
+ */
196
+ export declare class UnregisteredClassError extends SensitiveStringError {
197
+ readonly key: string;
198
+ readonly klass: string;
199
+ readonly name = "UnregisteredClassError";
200
+ readonly code = "unregistered-class";
201
+ constructor(key: string, klass: string, registered: readonly string[]);
202
+ }
203
+ /**
204
+ * Raised when a payload built under an audited context is consumed with no
205
+ * audit hook on this side.
206
+ *
207
+ * A refusal rather than a warning. A warning from a worker is a line on the
208
+ * parent's stderr that nothing reads, and the condition it would report is a
209
+ * security control the sender asked for being dropped in silence.
210
+ */
211
+ export declare class UnauditedWorkerError extends SensitiveStringError {
212
+ readonly name = "UnauditedWorkerError";
213
+ readonly code = "unaudited-worker";
214
+ constructor();
215
+ }
216
+ /**
217
+ * Raised when `data` or the context's `tags` would not survive the transport.
218
+ *
219
+ * The message names the path of the offending entry and never its value. A
220
+ * `DataCloneError` from the runtime quotes the source text of a function it
221
+ * could not clone, so that message is discarded rather than wrapped.
222
+ */
223
+ export declare class UnportableDataError extends SensitiveStringError {
224
+ /** Where in the payload the entry sits, such as `data.batch.onDone`. */
225
+ readonly path: string;
226
+ readonly transport: WorkerTransport;
227
+ readonly name = "UnportableDataError";
228
+ readonly code = "unportable-data";
229
+ constructor(
230
+ /** Where in the payload the entry sits, such as `data.batch.onDone`. */
231
+ path: string, transport: WorkerTransport, detail: string);
232
+ }
233
+ /**
234
+ * Raised when a value carries a constraint no other isolate can share.
235
+ *
236
+ * Two things qualify. A reveal budget is a counter shared by reference between
237
+ * a value and its derivatives; a thread has no reference to share, and the wire
238
+ * format resets counters, so a handoff would hand every worker a fresh budget.
239
+ * A custom environment restriction is a function, which is not data and cannot
240
+ * be cloned into another isolate at all, so a handoff would leave the receiving
241
+ * thread enforcing the declarative half of a restriction and silently not the
242
+ * rest.
243
+ *
244
+ * Both refusals are the rule that a derivative carries its parent's constraint
245
+ * or refuses to exist, applied to a transport.
246
+ */
247
+ export declare class UnshareableConstraintError extends SensitiveStringError {
248
+ readonly key: string;
249
+ readonly constraints: readonly (keyof SensitiveStringOptions)[];
250
+ readonly name = "UnshareableConstraintError";
251
+ readonly code = "unshareable-constraint";
252
+ constructor(key: string, constraints: readonly (keyof SensitiveStringOptions)[]);
253
+ }
254
+ /**
255
+ * Build a payload that carries sensitive values across a thread or process
256
+ * boundary with their class, label, and deadline intact.
257
+ *
258
+ * ⚠️ RETURNS RAW VALUES, in the wire format, one per entry. Building the
259
+ * payload is a reveal of each value: it goes through the same gate as
260
+ * `reveal()`, so an expired, revoked, or policy-denied value refuses here, on
261
+ * the sending side, and each value produces one audit record with
262
+ * `operation: 'worker-handoff'`.
263
+ *
264
+ * The checks that do not need the value run first, over every entry: an
265
+ * unshareable constraint, a protected value in `data` or `tags`, and anything
266
+ * the transport would lose. Failing one of those reveals nothing and records
267
+ * nothing.
268
+ *
269
+ * The gate's own refusals cannot be hoisted that way, because deciding them
270
+ * means reading. Values are read in key order, so an expired, revoked or
271
+ * policy-denied value at key *n* leaves the values before it revealed and
272
+ * audited, with the payload discarded. That is `serialize()`'s behaviour in a
273
+ * loop, and it is why the audit record names the key.
274
+ *
275
+ * @param values - The instances to carry, keyed however the receiver expects.
276
+ * @param options - Destination, context, non-sensitive data, and transport.
277
+ * @throws TypeError If `values` is not a plain object of instances.
278
+ * @throws UnshareableConstraintError If a value carries a reveal limit or a custom environment restriction.
279
+ * @throws UnportableDataError If `data` holds a sensitive value, or `data` or the
280
+ * context's `tags` would not survive the transport.
281
+ * @throws ExpiredSensitiveValueError, RevokedSensitiveValueError, or whatever
282
+ * the class policy throws, from the gate, exactly as `reveal()` would.
283
+ *
284
+ * @example
285
+ * ```ts
286
+ * const worker = new Worker(workerFile, {
287
+ * workerData: toWorkerPayload({ token }, { worker: workerFile, data: { batchSize: 100 } }),
288
+ * });
289
+ * ```
290
+ *
291
+ * @remarks
292
+ * Pass the result as an expression, as above, rather than binding it: the
293
+ * sender's copy holds plaintext until it is unreachable. For a long-lived
294
+ * worker, `postMessage` after start keeps that window shorter than
295
+ * `workerData` does, because a message is garbage once its handler returns
296
+ * where `workerData` lives as long as the thread.
297
+ *
298
+ * The receiving thread's heap holds the plaintext once it consumes the
299
+ * payload. `fromWorkerPayload()` deletes the raw values from the payload
300
+ * object, which shortens the accident window; it does not erase a string from
301
+ * memory, which nothing in JavaScript can.
302
+ *
303
+ * A value that crosses leaves this side's revocation reach entirely, which is
304
+ * the part of the boundary most easily read backwards. Instance `revoke()` is
305
+ * per copy; `revokeByLabel()` and `revokeByPattern()` act on module state, and
306
+ * module state is per isolate; a `revocationRegistry` is a function table, so
307
+ * it does not clone, and the receiving side cannot bind one to a rebuilt value
308
+ * because `deserialize()` takes no options. What still reaches the copy is the
309
+ * worker's own label list, matched on the label that crossed, so a worker that
310
+ * must honour revocation keeps one. Revoking before the handoff is not a way
311
+ * round it either: the gate refuses to read a revoked value, so there is no
312
+ * payload. Measured in `__tests__/worker-boundary.test.ts` against a real
313
+ * thread.
314
+ */
315
+ export declare function toWorkerPayload<T extends SensitiveValues<T>>(values: T, options?: WorkerPayloadOptions): WorkerPayload<T>;
316
+ /**
317
+ * Rebuild the instances a payload carries, and take the raw values out of it.
318
+ *
319
+ * Validation runs in full before anything is rebuilt, and rebuilding runs in
320
+ * full before the payload is consumed, so a call that throws returns no
321
+ * partial result and, with one exception, leaves the payload intact for a
322
+ * corrected retry. The exception is a value that expired between build and
323
+ * consume: that cannot be fixed by retrying, so the payload is consumed before
324
+ * the throw rather than left holding plaintext for the life of the thread.
325
+ *
326
+ * @param payload - What arrived: `workerData`, a message, or an IPC message.
327
+ * @param options - This side's audit hook, and what to require.
328
+ * @throws MalformedWorkerPayloadError If `payload` is not what `toWorkerPayload()` returns.
329
+ * @throws ConsumedWorkerPayloadError If the payload was consumed already.
330
+ * @throws MissingWorkerValueError If a key in `require` is absent.
331
+ * @throws UnregisteredClassError If a value's class is not registered on this thread.
332
+ * @throws UnauditedWorkerError If the payload is audited and no hook is available here.
333
+ * @throws ExpiredSensitiveValueError If a value expired in transit, naming its key.
334
+ *
335
+ * @example
336
+ * ```ts
337
+ * const { values, context } = fromWorkerPayload<{ token: SensitiveString<'credential'> }>(
338
+ * workerData,
339
+ * { auditReveal: (value, details) => log.info('reveal', { klass: value.klass, ...details }) },
340
+ * );
341
+ * withRevealContext(context, () => callApi(values.token.reveal()));
342
+ * ```
343
+ *
344
+ * @remarks
345
+ * The type parameter is a claim about names and classes that the runtime
346
+ * cannot check, as with `deserialize()`. `require` is what makes the names
347
+ * enforceable.
348
+ *
349
+ * After this returns, the payload object holds no raw value and a second call
350
+ * on it throws. A heap snapshot or a debugger still sees the string, which is
351
+ * the same limitation the library has everywhere.
352
+ */
353
+ export declare function fromWorkerPayload<T extends SensitiveValues<T>>(payload: unknown, options?: FromWorkerPayloadOptions): ReceivedWorkerPayload<T>;
354
+ /**
355
+ * `fromWorkerPayload()` followed by `withRevealContext()`.
356
+ *
357
+ * The two-call form has a failure mode that is invisible in review:
358
+ * destructure `values`, forget `context`, and every reveal in the worker runs
359
+ * unaudited while the code still reads as if the context were handled. This
360
+ * form cannot express that mistake.
361
+ *
362
+ * Returns whatever `fn` returns, a Promise included, matching
363
+ * `withRevealContext()`.
364
+ *
365
+ * @typeParam T - The values the payload is claimed to carry. Unverifiable at
366
+ * runtime, as with `deserialize()`; pass `require` to enforce the names.
367
+ * @typeParam R - What `fn` returns. Inferred, and `unknown` when `T` is given
368
+ * explicitly, for the reason under @remarks.
369
+ *
370
+ * @example Annotate the callback, and both are inferred
371
+ * ```ts
372
+ * await withWorkerPayload(
373
+ * workerData,
374
+ * { auditReveal },
375
+ * ({ token }: { token: SensitiveString<'credential'> }, data) =>
376
+ * callApi(token.reveal(), data),
377
+ * );
378
+ * ```
379
+ *
380
+ * @example Or name both, when the return type matters and the callback is long
381
+ * ```ts
382
+ * const signatures = withWorkerPayload<SignerValues, string[]>(
383
+ * workerData,
384
+ * { auditReveal, require: ['signingKey'] },
385
+ * ({ signingKey }, data) => sign(signingKey.reveal(), data),
386
+ * );
387
+ * ```
388
+ *
389
+ * @remarks
390
+ * TypeScript has no partial type argument inference: naming `T` alone fills
391
+ * `R` from its default rather than inferring it, so the call still compiles
392
+ * and its result is `unknown`. That is harmless when the result is discarded,
393
+ * which is the common shape in a worker, and the two examples above are the
394
+ * ways to keep it. `fromWorkerPayload()` takes one type parameter and has no
395
+ * such wart, so the two-call form is the other way out.
396
+ */
397
+ export declare function withWorkerPayload<T extends SensitiveValues<T>, R = unknown>(payload: unknown, options: FromWorkerPayloadOptions, fn: (values: T, data: unknown) => R): R;
398
+ //# sourceMappingURL=worker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":"AAwBA,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAKnD,OAAO,EACL,eAAe,EAGhB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EACV,aAAa,EACb,sBAAsB,EACtB,gBAAgB,EAChB,yBAAyB,EAE1B,MAAM,YAAY,CAAC;AAYpB;;;;;;;;;GASG;AACH,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,MAAM,CAAC;AAE/C;;;;;;;GAOG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI;IACzD,QAAQ,EAAE,CAAC,IAAI,MAAM,CAAC,GAAG,eAAe,CAAC,gBAAgB,CAAC;CAC3D,CAAC;AAEF,mEAAmE;AACnE,MAAM,MAAM,kBAAkB,GAAG,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,gBAAgB,CAAC,CAAC,CAAC;AAEnF;;;;GAIG;AACH,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACzC;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;;;;;OAOG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;IAEtB,sFAAsF;IACtF,OAAO,CAAC,EAAE,aAAa,CAAC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