@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,919 @@
1
+ import type { SensitivityClass, SensitiveStringOptions, SerializedSensitiveString, MaskOptions, HashAlgorithm, HashOptions, HmacOptions, RenewalOptions, RevealContext, RevealDetails } from './types.js';
2
+ import { type DevInfo } from './dev-mode.js';
3
+ /**
4
+ * Node.js custom inspect symbol for util.inspect() and console.log().
5
+ */
6
+ declare const NODE_INSPECT_SYMBOL: unique symbol;
7
+ /**
8
+ * Package-internal derivation of a value from one or more existing values.
9
+ *
10
+ * An operation that builds on protected values must retain the state of every
11
+ * value it read, so a constraint such as a reveal counter is never dropped by
12
+ * deriving from it. That logic lives in the private `SensitiveString.#derived`,
13
+ * which is only reachable from inside the class body, so the class publishes it
14
+ * here for the sibling modules that build derived values.
15
+ *
16
+ * This binding is deliberately absent from `index.ts`, and the package `exports`
17
+ * map declares no deep entry, so it is not part of the published API.
18
+ *
19
+ * @internal
20
+ */
21
+ export type DeriveSensitiveString = <D extends SensitivityClass>(value: string, klass: D, label: string | undefined, sources: readonly SensitiveString<SensitivityClass>[]) => SensitiveString<D>;
22
+ /**
23
+ * Assigned once, from the static block at the end of the class body.
24
+ *
25
+ * @internal
26
+ */
27
+ export declare let deriveSensitiveString: DeriveSensitiveString;
28
+ /**
29
+ * Package-internal serialization under a caller-described audit record.
30
+ *
31
+ * `serialize()` reads through the gate with the fixed `reveal` record, so a
32
+ * sibling module that puts a value on the wire for a reason of its own, as
33
+ * `toWorkerPayload()` does, could not say so in the audit log. This is the
34
+ * same read with the details supplied, published the way `deriveSensitiveString`
35
+ * is: absent from `index.ts` and unreachable through the package `exports` map.
36
+ *
37
+ * @internal
38
+ */
39
+ export type SerializeSensitiveString = (value: SensitiveString<SensitivityClass>, ctx: RevealContext | undefined, details: RevealDetails) => SerializedSensitiveString;
40
+ /**
41
+ * Assigned once, from the static block at the end of the class body.
42
+ *
43
+ * @internal
44
+ */
45
+ export declare let serializeSensitiveString: SerializeSensitiveString;
46
+ /**
47
+ * Package-internal question: which of this value's constraints cannot be
48
+ * shared with another isolate. Empty for a value that can cross.
49
+ *
50
+ * Reads nothing through the gate, so asking is not a reveal and is not
51
+ * charged, audited, or refused by anything the gate enforces.
52
+ *
53
+ * @internal
54
+ */
55
+ export type UnshareableConstraints = (value: SensitiveString<SensitivityClass>) => readonly (keyof SensitiveStringOptions)[];
56
+ /**
57
+ * Assigned once, from the static block at the end of the class body.
58
+ *
59
+ * @internal
60
+ */
61
+ export declare let unshareableConstraints: UnshareableConstraints;
62
+ /**
63
+ * Package-internal rendering for the structure walkers.
64
+ *
65
+ * A walker that replaced a value with `String(value)` would report the
66
+ * rendering to an observer as a coercion, and a coercion is the one surface an
67
+ * observer cannot read as a prevented leak. This renders through the class's
68
+ * own path under the `'structure'` surface, and answers `undefined` where the
69
+ * receiver refuses: a Proxy around an instance answers `instanceof` through
70
+ * the prototype it forwards and then fails the brand check. It also means an
71
+ * own or subclass `toString` no longer decides what a walker writes. Published
72
+ * the way `deriveSensitiveString` is, absent from `index.ts` and unreachable
73
+ * through the package `exports` map.
74
+ *
75
+ * @internal
76
+ */
77
+ export type RenderStructureRedaction = (value: object) => string | undefined;
78
+ /**
79
+ * Assigned once, from the static block at the end of the class body.
80
+ *
81
+ * @internal
82
+ */
83
+ export declare let renderStructureRedaction: RenderStructureRedaction;
84
+ export declare class SensitiveString<C extends SensitivityClass = 'sensitive'> {
85
+ #private;
86
+ /**
87
+ * The sensitivity classification for this value.
88
+ */
89
+ readonly klass: C;
90
+ /**
91
+ * Optional label for audit/compliance categorization.
92
+ * Examples: 'api_key', 'email', 'ssn', 'session_token'
93
+ */
94
+ readonly label: string | undefined;
95
+ /**
96
+ * Create a new SensitiveString.
97
+ *
98
+ * @param value - The raw string value to protect
99
+ * @param klass - The sensitivity classification ('credential' or 'sensitive')
100
+ * @param label - Optional label for audit/compliance (e.g., 'api_key', 'email')
101
+ * @param options - Shared options for access constraints and feature behavior
102
+ * @throws Error If both `ttl` and `expiresAt` are given, if only one half of the rate limit is given, if a restriction set expresses no restriction, or if the class policy requires an expiration and neither is.
103
+ * @throws TypeError If `value` is not a string, or an option has the wrong type.
104
+ * @throws RangeError If `ttl` is negative, `expiresAt` is an invalid Date, a reveal limit is out of range, or a restriction list is empty or holds a pattern that is neither a literal name nor a prefix.
105
+ */
106
+ constructor(value: string, klass: C, label?: string, options?: SensitiveStringOptions);
107
+ /**
108
+ * Get the policy for this instance's sensitivity class.
109
+ */
110
+ private get policy();
111
+ /**
112
+ * Returns the redacted form of this value.
113
+ * Safe for logging and display.
114
+ */
115
+ toString(): string;
116
+ /**
117
+ * Returns the redacted form for JSON serialization.
118
+ * Automatically called by JSON.stringify().
119
+ */
120
+ toJSON(): string;
121
+ /**
122
+ * Refuses BSON serialization.
123
+ *
124
+ * Called by the BSON encoder under every MongoDB write and every filter, on
125
+ * the ODM and the raw driver alike. It throws rather than redacting because
126
+ * BSON is a persistence and matching format: see {@link SensitiveBsonError}
127
+ * for why the two serializers differ, and why the silent outcome this
128
+ * replaces is worse than a leak.
129
+ *
130
+ * Nothing but a BSON encoder calls this, so it costs nothing on any other
131
+ * path.
132
+ */
133
+ toBSON(): never;
134
+ /**
135
+ * Custom inspect for Node.js util.inspect() and console.log().
136
+ * Displays the class, optional label, redacted value, and expiry state.
137
+ *
138
+ * The redacted form stays exactly what the class policy produces: expiry is
139
+ * reported next to it rather than in place of it, so a custom redaction is
140
+ * never replaced by a lifecycle marker. Inspecting is not an access, so this
141
+ * does not fire `onExpire`, and it neither calls out to an external
142
+ * revocation registry nor latches what it finds: a log line must not make a
143
+ * network call, and a value that was only printed has not been used.
144
+ */
145
+ [NODE_INSPECT_SYMBOL](): string;
146
+ /**
147
+ * Returns the raw (unredacted) value.
148
+ *
149
+ * Triggers audit logging if a RevealContext is active.
150
+ *
151
+ * @param ctx - Optional explicit reveal context.
152
+ * @throws If policy checking fails.
153
+ * @throws ExpiredSensitiveValueError If the value has expired.
154
+ * @throws RevokedSensitiveValueError If the value has been revoked, or a registry it consults cannot be reached.
155
+ * @throws RevealLimitExceededError If `maxReveals` has been reached.
156
+ * @throws RevealRateLimitError If `maxRevealsPerWindow` has been reached within the window.
157
+ */
158
+ reveal(ctx?: RevealContext): string;
159
+ /**
160
+ * Returns the raw (unredacted) value as UTF-8 bytes, in a buffer the caller
161
+ * owns and should zero.
162
+ *
163
+ * A reveal in every sense the gate cares about: same checks, same order, same
164
+ * audit record, and it counts against a reveal budget exactly as
165
+ * {@link reveal} does. What differs is only the representation, and that
166
+ * difference is the whole reason it exists.
167
+ *
168
+ * A string-returning reveal leaves one copy of the plaintext in process
169
+ * memory that garbage collection does not remove, and the copies accumulate:
170
+ * a thousand `reveal()` calls on a sealed value leave about a thousand. This
171
+ * returns bytes the caller can overwrite, so a thousand calls can leave none.
172
+ *
173
+ * Works on an unsealed value too, which encodes rather than decrypts, so a
174
+ * caller need not know how the value is stored to use the careful path.
175
+ *
176
+ * @param ctx - Optional explicit reveal context.
177
+ * @throws ClearedSensitiveValueError If the value, or one it was derived from, has been cleared.
178
+ * @throws ExpiredSensitiveValueError If the value has expired.
179
+ * @throws RevokedSensitiveValueError If the value has been revoked, or a registry it consults cannot be reached.
180
+ * @throws RevealLimitExceededError If `maxReveals` has been reached.
181
+ * @throws SealingKeyDestroyedError If `destroySealingKey()` has run since this value was sealed.
182
+ * @throws SealedValueIntegrityError If the stored box, its class or its label was modified.
183
+ *
184
+ * @example
185
+ * ```ts
186
+ * const bytes = token.revealBytes(ctx);
187
+ * try {
188
+ * socket.write(bytes);
189
+ * } finally {
190
+ * bytes.fill(0);
191
+ * }
192
+ * ```
193
+ */
194
+ revealBytes(ctx?: RevealContext): Buffer;
195
+ /**
196
+ * Whether this value is held as ciphertext rather than as a string.
197
+ *
198
+ * Decided once, at construction, from the `sealed` option or the process
199
+ * default, and never afterwards. A derivative reports `true` when any value
200
+ * it was built from does.
201
+ *
202
+ * `false` in a process that never configured sealing, and `false` on a value
203
+ * whose `sealed: true` fell back because sealing was unavailable and `strict`
204
+ * was off. There is no state in which this reports `true` for a value holding
205
+ * a plaintext string.
206
+ */
207
+ get isSealed(): boolean;
208
+ /**
209
+ * What development mode recorded about this value, or `undefined`.
210
+ *
211
+ * `undefined` unless development mode is on and was on when this value was
212
+ * constructed, so a production build reads `undefined` here rather than
213
+ * failing on a missing property. The record holds no part of the raw value:
214
+ * when the value was made, where it was made, how often it has been exposed
215
+ * and from where.
216
+ *
217
+ * @see setDevMode
218
+ */
219
+ get __devInfo(): DevInfo | undefined;
220
+ /**
221
+ * Returns a partially masked rendering of the value, for display.
222
+ *
223
+ * This is a partial reveal: it runs the same authorization and audit hooks as
224
+ * `reveal()`, and the audit record says `operation: 'mask'` so a log can tell
225
+ * the two apart. The result is a plain string and is not protected; it is
226
+ * meant for a support screen, a confirmation prompt, or a log line, not for
227
+ * further processing.
228
+ *
229
+ * The rendering must hide at least `minMasked` characters, which defaults to
230
+ * 4 for `sensitive` and 8 for `credential` and may only be raised. Positional
231
+ * masking clamps what it shows to satisfy the floor; a strategy that cannot
232
+ * reach it, including one applied to a value of the wrong shape, falls back
233
+ * to the class's full redaction. Counts are code points, and the length of
234
+ * the value is disclosed by construction.
235
+ *
236
+ * @param options - Positional bounds or a format strategy. Defaults to hiding everything.
237
+ * @param ctx - Optional reveal context for authorization and auditing.
238
+ * @throws Error If the class policy sets `allowMask: false`, as `credential` does by default.
239
+ * @throws TypeError If an option has the wrong type or names an unknown strategy.
240
+ * @throws RangeError If a count is not a whole number, or `minMasked` is below the class floor.
241
+ *
242
+ * @example
243
+ * ```ts
244
+ * const key = new SensitiveString('sk_live_abc123xyz9', 'sensitive', 'api_key');
245
+ * key.mask({ showFirst: 2, showLast: 4 }); // 'sk************xyz9'
246
+ *
247
+ * const email = new SensitiveString('jane@example.com', 'sensitive', 'email');
248
+ * email.mask({ strategy: 'email' }); // 'j***@e******.com'
249
+ * ```
250
+ */
251
+ mask(options?: MaskOptions, ctx?: RevealContext): string;
252
+ /**
253
+ * A one-way digest of the value, as a protected value.
254
+ *
255
+ * For a lookup key, a deduplication key, or a correlation token: something
256
+ * derived from the value that can be stored or compared without storing the
257
+ * value. It is an exposure like any other, so it runs the class policy, fires
258
+ * the audit hook with `operation: 'hash'`, counts against a reveal budget,
259
+ * and refuses on an expired or revoked value.
260
+ *
261
+ * ⚠️ This is not password hashing. The digest is fast to compute, which is
262
+ * the one property a stored password must not have: a wordlist runs through
263
+ * SHA-256 at billions of guesses a second, and a salt does not slow that down
264
+ * for the attacker who has the salt, which is everyone holding the record.
265
+ * Use `hashForStorage` from `@platform-sec/sensitive-string-kdf`.
266
+ *
267
+ * The result is always `credential`, whatever the source class was, because a
268
+ * digest of a value an attacker can guess is a copy of that value behind a
269
+ * lookup table, and one that correlates the same subject across every system
270
+ * that stores it. It carries the deadline, the reveal budget and the
271
+ * revocation of the value it came from, for the same reason.
272
+ *
273
+ * @param algorithm - One of sha256, sha384, sha512, sha3-256, sha3-512.
274
+ * @param options - Salt and digest encoding.
275
+ * @param ctx - Optional reveal context for authorization and auditing.
276
+ * @throws Error If the class policy sets `advisory.allowHash: false`, or the algorithm is broken or unavailable in this Node build.
277
+ * @throws TypeError If the algorithm, encoding, salt or options object has the wrong type.
278
+ * @throws RangeError If the salt is empty.
279
+ *
280
+ * @example
281
+ * ```ts
282
+ * const token = new SensitiveString(raw, 'credential', 'session_token');
283
+ * const lookupKey = token.hash('sha256'); // SensitiveString<'credential'>
284
+ * await db.sessions.findUnique({ where: { tokenHash: lookupKey.reveal() } });
285
+ * ```
286
+ */
287
+ hash(algorithm: HashAlgorithm, options?: HashOptions, ctx?: RevealContext): SensitiveString<'credential'>;
288
+ /**
289
+ * A keyed one-way digest of the value, as a protected value.
290
+ *
291
+ * The version of `hash()` to reach for when the value is something an
292
+ * attacker can enumerate: an email address, a phone number, a card number, a
293
+ * six-digit code. A salt stops precomputation and nothing else, because the
294
+ * salt sits beside the digest in the same record; a key that the attacker
295
+ * does not have is what makes the digest unanswerable, and it is also what
296
+ * stops the same subject being correlated across two systems that both
297
+ * store one.
298
+ *
299
+ * The key may itself be protected, and then it is read through its own gate:
300
+ * its policy, its audit hook, its budget and its revocation all apply, and
301
+ * the result carries the constraints of the value and the key both. Using a
302
+ * value as a key reads it.
303
+ *
304
+ * @param algorithm - One of sha256, sha384, sha512, sha3-256, sha3-512.
305
+ * @param key - At least 16 bytes. 32 bytes from `randomBytes` or a secrets manager is the recommendation.
306
+ * @param options - Digest encoding.
307
+ * @param ctx - Optional reveal context for authorization and auditing.
308
+ * @throws Error If the class policy sets `advisory.allowHash: false`, or the algorithm is broken or unavailable in this Node build.
309
+ * @throws TypeError If the algorithm, encoding, key or options object has the wrong type, or a salt is supplied.
310
+ * @throws RangeError If the key is shorter than 16 bytes.
311
+ *
312
+ * @example
313
+ * ```ts
314
+ * const email = new SensitiveString('jane@example.com', 'sensitive', 'email');
315
+ * const pseudonym = email.hmac('sha256', process.env.CORRELATION_KEY!);
316
+ * ```
317
+ */
318
+ hmac(algorithm: HashAlgorithm, key: string | Uint8Array | SensitiveString<SensitivityClass>, options?: HmacOptions, ctx?: RevealContext): SensitiveString<'credential'>;
319
+ /**
320
+ * The deadline after which this value can no longer be read, if it has one.
321
+ *
322
+ * A derived value carries the deadlines of every value it came from, and this
323
+ * reports the earliest of them: a substring of an expired OTP is expired, and
324
+ * a concatenation is only usable while both of its operands are.
325
+ *
326
+ * Returns a copy, so the deadline cannot be moved through it.
327
+ */
328
+ get expiresAt(): Date | undefined;
329
+ /**
330
+ * Whether the deadline has passed. A value is not usable at its own deadline.
331
+ *
332
+ * The first detection fires the `onExpire` callback of every expired source.
333
+ */
334
+ isExpired(): boolean;
335
+ /**
336
+ * Milliseconds until the deadline, `-1` once it has passed, or `undefined`
337
+ * when this value does not expire.
338
+ */
339
+ ttlRemaining(): number | undefined;
340
+ /**
341
+ * Whether `renew()` would be accepted right now.
342
+ *
343
+ * Renewal needs a deadline to extend, permission from the class policy and
344
+ * the construction options, an unexhausted renewal budget, and ownership of
345
+ * the deadline: a derived value cannot renew one it shares.
346
+ */
347
+ isRenewable(): boolean;
348
+ /**
349
+ * How many times this value has extended the deadline it owns.
350
+ *
351
+ * A derived value owns no deadline and reports `0`, however often the value
352
+ * it came from has been renewed.
353
+ */
354
+ get renewalCount(): number;
355
+ /**
356
+ * Extend the deadline, when the class policy and the construction options
357
+ * allow it.
358
+ *
359
+ * An expired value extends from now rather than from its lapsed deadline, so
360
+ * a sliding session that missed a heartbeat is granted the full duration.
361
+ * Reviving a value this way is why `allowRenewal` defaults to `false` for
362
+ * `credential` and why a policy may forbid it outright.
363
+ *
364
+ * The extension is audited before it takes effect, so an audit sink that
365
+ * throws stops it, and a refused renewal leaves no record of one that never
366
+ * happened. Renewing is not a read: it does not disclose the value, and it
367
+ * works on an expired one. It does not work on a revoked one, or on one this
368
+ * environment may not read, because neither of those is a lapsed deadline:
369
+ * both say the value must not be used here, and extending its life is using
370
+ * it.
371
+ *
372
+ * @param additionalTtl - Milliseconds to add. Must be positive.
373
+ * @param options - `maxExtension` clamps the resulting deadline.
374
+ * @param ctx - Optional reveal context for authorization and auditing.
375
+ * @throws ClearedSensitiveValueError If the value, or one it was derived from, has been cleared.
376
+ * @throws RenewalNotAllowedError If renewal is refused, or a cap leaves no room to extend.
377
+ * @throws RangeError If `additionalTtl` is not a positive, finite number.
378
+ * @throws RevokedSensitiveValueError If the value has been revoked.
379
+ * @throws EnvironmentRestrictedError If this environment may not read the value.
380
+ *
381
+ * @example
382
+ * ```ts
383
+ * const session = new SensitiveString(token, 'sensitive', 'session', { ttl: 15 * 60_000 });
384
+ * session.renew(15 * 60_000, { maxExtension: absoluteSessionDeadline });
385
+ * ```
386
+ */
387
+ renew(additionalTtl: number, options?: RenewalOptions, ctx?: RevealContext): void;
388
+ /**
389
+ * Stop this value from being read, permanently.
390
+ *
391
+ * There is no way back. Nothing lifts a revocation: not a policy, not a new
392
+ * options object, not a round trip through the wire format.
393
+ *
394
+ * Revocation runs along derivation edges in both directions. Every value this
395
+ * one was derived from is revoked too, and so is everything else derived from
396
+ * those, because a derivative is made of its sources' material: a leaked
397
+ * substring is a leaked secret. Refusing to revoke through the handle a
398
+ * caller happens to be holding would fail open in exactly the incident this
399
+ * exists for, which is why this is the one piece of shared state a derived
400
+ * value may write, where `renew()` refuses.
401
+ *
402
+ * Nothing may refuse a revocation, so no policy hook is consulted and the
403
+ * audit record is reported after the fact, with anything the sink throws
404
+ * swallowed. `renew()` audits first for the opposite reason.
405
+ *
406
+ * Revoking an already-revoked value changes nothing and reports nothing: the
407
+ * first reason and timestamp stand, because a revocation is a fact that
408
+ * already happened.
409
+ *
410
+ * @param reason - Why, for the error message and the audit record. Developer
411
+ * text: it must not carry any part of the protected value.
412
+ * @param ctx - Optional reveal context for auditing.
413
+ * @throws TypeError If `reason` is not a string.
414
+ *
415
+ * @example
416
+ * ```ts
417
+ * apiKey.revoke('Rotated 2026-08-01');
418
+ * apiKey.reveal(); // throws RevokedSensitiveValueError
419
+ * ```
420
+ */
421
+ revoke(reason: string, ctx?: RevealContext): void;
422
+ /**
423
+ * Whether this value has been revoked, by any of the four sources: its own
424
+ * `revoke()`, the process-global label and pattern lists, or the registry it
425
+ * was constructed with.
426
+ *
427
+ * `true` as well when a registry it was given cannot be reached, because a
428
+ * value whose revocation cannot be checked is not one to hand out.
429
+ */
430
+ get isRevoked(): boolean;
431
+ /**
432
+ * Why this value was revoked, or `undefined` when it was not.
433
+ *
434
+ * The reason recorded by whichever source refused first. For a value revoked
435
+ * through several of them, that is the one observed earliest rather than the
436
+ * one highest in any precedence order: a latched revocation is a fact that
437
+ * already happened.
438
+ */
439
+ get revocationReason(): string | undefined;
440
+ /**
441
+ * When this value was revoked, or `undefined` when it was not.
442
+ *
443
+ * For a label or pattern revocation this is when the list was written, not
444
+ * when this value first noticed.
445
+ */
446
+ get revokedAt(): Date | undefined;
447
+ /**
448
+ * Destroy this instance's copy of the plaintext, permanently.
449
+ *
450
+ * What it does is narrow, and the first paragraph of the documentation is the
451
+ * right place to say so: it drops **the library's** reference to the string
452
+ * and refuses every later read. It is not zeroing. JavaScript cannot
453
+ * overwrite the backing store of a string it holds a reference to, and
454
+ * whether the library's was the last reference is a property of the calling
455
+ * code rather than of this method.
456
+ *
457
+ * ```ts
458
+ * // Works: the library's copy is the only copy.
459
+ * const password = new SensitiveString(await kms.decrypt(blob), 'credential', 'db_password');
460
+ * await connect(password.reveal(ctx));
461
+ * password.clear();
462
+ *
463
+ * // Does nothing while the handler still holds req.body: req.body.token and
464
+ * // the instance's value are the same string object.
465
+ * const token = new SensitiveString(req.body.token, 'credential');
466
+ * token.clear();
467
+ * ```
468
+ *
469
+ * The second shape is not fixable from inside the library, and no boundary
470
+ * integration fixes it either: a body has to be parsed into strings before
471
+ * any field can be classified. The fix belongs to the caller, which is to
472
+ * drop or delete the source property once the value is wrapped.
473
+ *
474
+ * Derivatives are refused, not released. Clearing an owner refuses every
475
+ * value derived from it, because they share the state object this writes;
476
+ * clearing a derivative refuses only that derivative, because it has no
477
+ * shared state of its own to write. The traffic also runs the other way: a
478
+ * derivative of 13 characters or more is a V8 `SlicedString` pinning its
479
+ * origin's entire backing store, and a `concat()` result pins both operands,
480
+ * so an origin's `clear()` releases nothing at all until the derivatives are
481
+ * cleared too. Clear them, or turn on `trackInstances` and let
482
+ * `clearAllSensitiveValues()` find the ones you no longer hold.
483
+ *
484
+ * Redaction keeps working: `toString()`, `toJSON()` and `inspect()` render
485
+ * the rendering this snapshotted from the live value, so logging a cleared
486
+ * value never throws. `length` and `isEmpty()` refuse instead of answering
487
+ * `0` and `true`, which would be wrong rather than degraded.
488
+ *
489
+ * No policy is consulted. Clearing reduces exposure, so there is no
490
+ * confidentiality outcome a denial would protect, and the same caller could
491
+ * drop the reference by letting it go out of scope. It is audited, after the
492
+ * fact, with anything the sink throws swallowed.
493
+ *
494
+ * Irreversible, and idempotent per instance: a second call on the same
495
+ * instance changes nothing and reports nothing. A derivative whose origin was
496
+ * cleared has still not dropped its own copy, so `clear()` on it is not a
497
+ * no-op.
498
+ *
499
+ * @param ctx - Optional reveal context for auditing. The ambient context is used when this is omitted.
500
+ *
501
+ * @example
502
+ * ```ts
503
+ * token.clear();
504
+ * token.isCleared; // true
505
+ * token.toString(); // '[REDACTED:credential]', unchanged
506
+ * token.reveal(); // throws ClearedSensitiveValueError
507
+ * ```
508
+ */
509
+ clear(ctx?: RevealContext): void;
510
+ /**
511
+ * Whether this value has been destroyed, by its own `clear()` or by one on a
512
+ * value it was derived from.
513
+ */
514
+ get isCleared(): boolean;
515
+ /**
516
+ * When this value was destroyed, or `undefined` when it was not.
517
+ *
518
+ * The earliest clear affecting it, so a derivative cleared after its origin
519
+ * reports the origin's time: that is when it stopped being usable.
520
+ */
521
+ get clearedAt(): Date | undefined;
522
+ /**
523
+ * How many times this value has been exposed.
524
+ *
525
+ * Counted for every value, whether or not it limits reveals. An exposure is
526
+ * what an audit hook sees: `reveal()`, `mask()`, `hash()`, `hmac()`,
527
+ * `serialize()`, `map()`, and the string, regex, and template operations, one
528
+ * per call. An `hmac()` with a protected key counts once against the value
529
+ * and once against the key. `equals()` is
530
+ * not, because a comparison reads the value without disclosing it, and
531
+ * neither is redaction. A read the gate refused, or one an audit hook stopped
532
+ * by throwing, is not counted: a denied reveal is not a reveal.
533
+ *
534
+ * A derived value reports the highest count among the values it was built
535
+ * from, which is the one nearest a limit.
536
+ */
537
+ get revealCount(): number;
538
+ /**
539
+ * Exposures still allowed before `maxReveals` is reached, or `undefined` when
540
+ * this value sets no lifetime limit.
541
+ *
542
+ * A derived value reports the smallest remaining budget among the values it
543
+ * was built from, which is the one that will refuse first.
544
+ */
545
+ get revealsRemaining(): number | undefined;
546
+ /**
547
+ * Whether the lifetime limit has been reached, so no further exposure is
548
+ * possible. Permanent: nothing resets a reveal count.
549
+ *
550
+ * A rate limit does not make a value exhausted, because waiting clears it.
551
+ */
552
+ isExhausted(): boolean;
553
+ /**
554
+ * Compare this value with another string or SensitiveString.
555
+ *
556
+ * Uses constant-time comparison when either operand's class requires it, as
557
+ * 'credential' does, to prevent timing attacks. The receiver alone used to
558
+ * decide, so `input.equals(storedCredential)` compared with `===` while
559
+ * `storedCredential.equals(input)` did not, and which side of the call a
560
+ * credential lands on is not a decision anyone makes on purpose.
561
+ *
562
+ * @param other - The value to compare against
563
+ * @param ctx - Optional reveal context for policy checks
564
+ * @returns true if values are equal
565
+ *
566
+ * @remarks
567
+ * The constant-time path hides the stored value's contents, and hides its
568
+ * length to the granularity of a SHA-256 block: a comparand of the wrong
569
+ * length costs what a comparand of the right length costs, and a stored
570
+ * value of 8 bytes costs what one of 55 costs. See `compare.ts` for why that
571
+ * needs more than `timingSafeEqual` alone, and for what it still leaves.
572
+ */
573
+ equals(other: string | SensitiveString<SensitivityClass>, ctx?: RevealContext): boolean;
574
+ /**
575
+ * Concatenate with another string or SensitiveString.
576
+ *
577
+ * Inherits the most restrictive sensitivity class.
578
+ * Labels are combined with '/' separator.
579
+ *
580
+ * @param other - The value to append.
581
+ * @param ctx - Audit context for raw-value access.
582
+ */
583
+ concat<D extends SensitivityClass>(other: string | SensitiveString<D>, ctx?: RevealContext): SensitiveString<SensitivityClass>;
584
+ /**
585
+ * Get the length of the raw value.
586
+ * Note: Length is generally not considered sensitive for most use cases.
587
+ *
588
+ * @throws ClearedSensitiveValueError If the value, or one it was derived from, has been cleared. `0` would be a wrong answer, not a degraded one.
589
+ */
590
+ get length(): number;
591
+ /**
592
+ * Check if the raw value is empty.
593
+ *
594
+ * @throws ClearedSensitiveValueError If the value, or one it was derived from, has been cleared. `true` would be a wrong answer, not a degraded one.
595
+ */
596
+ isEmpty(): boolean;
597
+ /**
598
+ * Create a substring, preserving sensitivity class and label.
599
+ *
600
+ * @param start - Start index.
601
+ * @param end - Optional end index.
602
+ * @param ctx - Audit context.
603
+ * @throws If policy checking fails (e.g., context required but not provided).
604
+ */
605
+ substring(start: number, end?: number, ctx?: RevealContext): SensitiveString<C>;
606
+ /**
607
+ * Remove whitespace from both ends, preserving sensitivity and label.
608
+ *
609
+ * @param ctx - Optional reveal context for authorization and auditing.
610
+ */
611
+ trim(ctx?: RevealContext): SensitiveString<C>;
612
+ /**
613
+ * Remove leading whitespace, preserving sensitivity and label.
614
+ *
615
+ * @param ctx - Optional reveal context for authorization and auditing.
616
+ */
617
+ trimStart(ctx?: RevealContext): SensitiveString<C>;
618
+ /**
619
+ * Remove trailing whitespace, preserving sensitivity and label.
620
+ *
621
+ * @param ctx - Optional reveal context for authorization and auditing.
622
+ */
623
+ trimEnd(ctx?: RevealContext): SensitiveString<C>;
624
+ /**
625
+ * Convert the value to lowercase, preserving sensitivity and label.
626
+ *
627
+ * @param ctx - Optional reveal context for authorization and auditing.
628
+ */
629
+ toLowerCase(ctx?: RevealContext): SensitiveString<C>;
630
+ /**
631
+ * Convert the value to uppercase, preserving sensitivity and label.
632
+ *
633
+ * @param ctx - Optional reveal context for authorization and auditing.
634
+ */
635
+ toUpperCase(ctx?: RevealContext): SensitiveString<C>;
636
+ /**
637
+ * Pad the start of the value to a target length.
638
+ *
639
+ * @param targetLength - Desired result length.
640
+ * @param padString - String used for padding.
641
+ * @param ctx - Optional reveal context for authorization and auditing.
642
+ */
643
+ padStart(targetLength: number, padString?: string, ctx?: RevealContext): SensitiveString<C>;
644
+ /**
645
+ * Pad the end of the value to a target length.
646
+ *
647
+ * @param targetLength - Desired result length.
648
+ * @param padString - String used for padding.
649
+ * @param ctx - Optional reveal context for authorization and auditing.
650
+ */
651
+ padEnd(targetLength: number, padString?: string, ctx?: RevealContext): SensitiveString<C>;
652
+ /**
653
+ * Extract a section of the value, preserving sensitivity and label.
654
+ *
655
+ * @param start - Zero-based start index. Negative indices count from the end.
656
+ * @param end - Optional exclusive end index.
657
+ * @param ctx - Optional reveal context for authorization and auditing.
658
+ */
659
+ slice(start?: number, end?: number, ctx?: RevealContext): SensitiveString<C>;
660
+ /**
661
+ * Test whether the value begins with a string.
662
+ *
663
+ * Partial queries are disabled for credentials by default because their
664
+ * results can be used as a character-by-character oracle.
665
+ *
666
+ * @param searchString - Prefix to find.
667
+ * @param position - Position at which to begin searching.
668
+ * @param ctx - Optional reveal context for authorization and auditing.
669
+ */
670
+ startsWith(searchString: string, position?: number, ctx?: RevealContext): boolean;
671
+ /**
672
+ * Test whether the value ends with a string.
673
+ *
674
+ * @param searchString - Suffix to find.
675
+ * @param endPosition - End position to use for the search.
676
+ * @param ctx - Optional reveal context for authorization and auditing.
677
+ */
678
+ endsWith(searchString: string, endPosition?: number, ctx?: RevealContext): boolean;
679
+ /**
680
+ * Test whether the value contains a string.
681
+ *
682
+ * @param searchString - String to find.
683
+ * @param position - Position at which to begin searching.
684
+ * @param ctx - Optional reveal context for authorization and auditing.
685
+ */
686
+ includes(searchString: string, position?: number, ctx?: RevealContext): boolean;
687
+ /**
688
+ * Find the first index of a string in the value.
689
+ *
690
+ * @param searchString - String to find.
691
+ * @param position - Position at which to begin searching.
692
+ * @param ctx - Optional reveal context for authorization and auditing.
693
+ */
694
+ indexOf(searchString: string, position?: number, ctx?: RevealContext): number;
695
+ /**
696
+ * Find the last index of a string in the value.
697
+ *
698
+ * @param searchString - String to find.
699
+ * @param position - Position at which to begin searching backward.
700
+ * @param ctx - Optional reveal context for authorization and auditing.
701
+ */
702
+ lastIndexOf(searchString: string, position?: number, ctx?: RevealContext): number;
703
+ /**
704
+ * Test whether a regular expression matches the value.
705
+ *
706
+ * Regex tests are partial queries and are disabled for credentials by default
707
+ * because caller-controlled patterns can form a powerful content oracle.
708
+ *
709
+ * @param pattern - Regular expression to test.
710
+ * @param ctx - Optional reveal context for authorization and auditing.
711
+ */
712
+ test(pattern: RegExp, ctx?: RevealContext): boolean;
713
+ /**
714
+ * Find the index of the first regular-expression match.
715
+ *
716
+ * This is a partial query and is disabled for credentials by default.
717
+ *
718
+ * @param pattern - Regular expression to search for.
719
+ * @param ctx - Optional reveal context for authorization and auditing.
720
+ */
721
+ search(pattern: RegExp, ctx?: RevealContext): number;
722
+ /**
723
+ * Return regular-expression matches as protected values.
724
+ *
725
+ * Native match metadata such as `input` is intentionally omitted because it
726
+ * contains the complete raw value. Unmatched optional captures are omitted.
727
+ *
728
+ * @param pattern - Regular expression to match.
729
+ * @param ctx - Optional reveal context for authorization and auditing.
730
+ */
731
+ match(pattern: RegExp, ctx?: RevealContext): SensitiveString<C>[] | null;
732
+ /**
733
+ * Return named regular-expression groups as protected values.
734
+ *
735
+ * A successful match without named groups returns an empty, null-prototype
736
+ * object. Named groups that did not participate in the match are omitted.
737
+ *
738
+ * @param pattern - Regular expression containing optional named groups.
739
+ * @param ctx - Optional reveal context for authorization and auditing.
740
+ */
741
+ matchGroups(pattern: RegExp, ctx?: RevealContext): Record<string, SensitiveString<C>> | null;
742
+ /**
743
+ * Return every regular-expression match as an iterator of protected arrays.
744
+ *
745
+ * The pattern must have the global (`g`) flag, matching native String.matchAll
746
+ * requirements. Match metadata containing the complete input is omitted.
747
+ *
748
+ * @param pattern - Global regular expression to match.
749
+ * @param ctx - Optional reveal context for authorization and auditing.
750
+ */
751
+ matchAll(pattern: RegExp, ctx?: RevealContext): IterableIterator<SensitiveString<C>[]>;
752
+ /**
753
+ * Split the value into protected parts.
754
+ *
755
+ * @param separator - String or regular expression used to divide the value.
756
+ * @param limit - Maximum number of results.
757
+ * @param ctx - Optional reveal context for authorization and auditing.
758
+ */
759
+ split(separator: string | RegExp, limit?: number, ctx?: RevealContext): SensitiveString<C>[];
760
+ /**
761
+ * Replace the first matching string or the matches selected by a regular expression.
762
+ *
763
+ * Replacement callbacks are intentionally unsupported because they receive raw
764
+ * matched content.
765
+ *
766
+ * @param searchValue - String or regular expression to replace.
767
+ * @param replaceValue - String replacement pattern.
768
+ * @param ctx - Optional reveal context for authorization and auditing.
769
+ */
770
+ replace(searchValue: string | RegExp, replaceValue: string, ctx?: RevealContext): SensitiveString<C>;
771
+ /**
772
+ * Replace every matching string or regular-expression match.
773
+ *
774
+ * Replacement callbacks are intentionally unsupported because they receive raw
775
+ * matched content.
776
+ *
777
+ * @param searchValue - String or global regular expression to replace.
778
+ * @param replaceValue - String replacement pattern.
779
+ * @param ctx - Optional reveal context for authorization and auditing.
780
+ */
781
+ replaceAll(searchValue: string | RegExp, replaceValue: string, ctx?: RevealContext): SensitiveString<C>;
782
+ /**
783
+ * Return the character at an index as a protected value.
784
+ *
785
+ * An out-of-range index returns a protected empty string, matching String.charAt().
786
+ *
787
+ * @param index - Zero-based character index.
788
+ * @param ctx - Optional reveal context for authorization and auditing.
789
+ */
790
+ charAt(index: number, ctx?: RevealContext): SensitiveString<C>;
791
+ /**
792
+ * Return the character at an index as a protected value.
793
+ *
794
+ * @param index - Character index. Negative indices count from the end.
795
+ * @param ctx - Optional reveal context for authorization and auditing.
796
+ */
797
+ at(index: number, ctx?: RevealContext): SensitiveString<C> | undefined;
798
+ /**
799
+ * Serialize for secure service boundary transmission.
800
+ *
801
+ * ⚠️ RETURNS RAW VALUE - DO NOT LOG ⚠️
802
+ *
803
+ * Intended for mTLS/encrypted transmission only.
804
+ *
805
+ * A deadline travels with the value, so a token with five minutes left still
806
+ * has five minutes left on the other side. The receiver enforces it against
807
+ * its own clock: a receiver whose clock runs ahead of the sender's rejects the
808
+ * value early, which is the direction to fail in. Renewal permission and
809
+ * renewal counts do not travel, so a payload cannot grant the right to extend
810
+ * a credential's lifetime.
811
+ *
812
+ * A revoked value is not transmittable: reading it to build the payload goes
813
+ * through the same gate as any other read, so this throws rather than
814
+ * emitting the wire format's `revoked` flag. That flag is for the receiving
815
+ * side, and `deserialize()` honours it.
816
+ *
817
+ * Environment restrictions travel too, so a value that may only be read in
818
+ * the EU is still restricted to the EU on the other side. A restriction that
819
+ * is a function does not travel and cannot: such a value refuses to
820
+ * serialize rather than arriving with half of its restriction enforced.
821
+ *
822
+ * Destination bindings travel as well, and serializing is itself a reveal
823
+ * toward wherever the payload is going: a bound value serializes only under
824
+ * a context whose tags name a sink or host the binding allows.
825
+ *
826
+ * @param ctx - Optional context for audit/permission checks
827
+ * @throws ExpiredSensitiveValueError If the value has expired.
828
+ * @throws RevokedSensitiveValueError If the value has been revoked.
829
+ * @throws EnvironmentRestrictedError If this environment may not read the value.
830
+ * @throws DestinationRestrictedError If the context names no destination the value allows.
831
+ * @throws UnserializableRestrictionError If the value carries a custom restriction.
832
+ */
833
+ serialize(ctx?: RevealContext): SerializedSensitiveString;
834
+ /**
835
+ * Reconstruct a SensitiveString from a serialized form.
836
+ *
837
+ * @param serialized - The serialized form (potentially untrusted data from external source).
838
+ * @throws If the serialized form is invalid or missing required fields.
839
+ * @throws If the klass is not a registered sensitivity class.
840
+ */
841
+ static deserialize<C extends SensitivityClass>(serialized: unknown): SensitiveString<C>;
842
+ /**
843
+ * Create a SensitiveString if the input is truthy, otherwise return null.
844
+ * Useful for optional fields.
845
+ */
846
+ /**
847
+ * Create a sealed SensitiveString from bytes, without the value ever becoming
848
+ * a JavaScript string.
849
+ *
850
+ * The reason to reach for this over the ordinary constructor: a string passed
851
+ * to the constructor survives in process memory after the instance drops it,
852
+ * permanently as far as a core dump is concerned, because JavaScript cannot
853
+ * overwrite a string's backing store. A value that arrives as bytes, from a
854
+ * KMS client or a secrets manager, need never become one.
855
+ *
856
+ * **`bytes` is zeroed before this returns.** A caller that needs to keep them
857
+ * must copy first. That is the point of the method rather than a side effect
858
+ * of it: leaving the caller's buffer intact would move the exposure rather
859
+ * than remove it.
860
+ *
861
+ * Seals unconditionally, so it refuses `{ sealed: false }` rather than
862
+ * accepting an option that contradicts its only purpose. Every other option
863
+ * behaves as it does on the constructor.
864
+ *
865
+ * One exception to the promise, and it is the policy's doing rather than this
866
+ * method's. A sealed value's redacted rendering is captured at construction,
867
+ * and there is no live value here to capture it from. When the class policy's
868
+ * rendering ignores its argument, which every default one does, that costs
869
+ * nothing. When the policy reads the value, which is exactly what
870
+ * deterministic redaction is for, the bytes are decoded once so the tag is the
871
+ * tag of this value rather than the shared tag of the empty string, and that
872
+ * one plaintext string is then in process memory for good. A process that
873
+ * wants both `fromBuffer`'s guarantee and a value-derived rendering cannot
874
+ * have both, and this resolves it in favour of a rendering that is not
875
+ * silently wrong.
876
+ *
877
+ * @param bytes - The value as UTF-8 bytes. Zeroed before this returns.
878
+ * @param klass - The sensitivity classification.
879
+ * @param label - Optional label for audit and compliance.
880
+ * @param options - Shared options, as on the constructor.
881
+ * @throws TypeError If `bytes` is not a Buffer, if it is not valid UTF-8, or if `options.sealed` is false.
882
+ * @throws SealingUnavailableError If this process cannot seal.
883
+ *
884
+ * @example
885
+ * ```ts
886
+ * const bytes = await kms.decryptToBuffer(blob); // a Buffer, never a string
887
+ * const password = SensitiveString.fromBuffer(bytes, 'credential', 'db_password');
888
+ * // `bytes` is now zeroed.
889
+ * ```
890
+ */
891
+ static fromBuffer<C extends SensitivityClass>(bytes: Buffer, klass: C, label?: string, options?: SensitiveStringOptions): SensitiveString<C>;
892
+ static fromOptional<C extends SensitivityClass>(value: string | null | undefined, klass: C, label?: string, options?: SensitiveStringOptions): SensitiveString<C> | null;
893
+ /**
894
+ * Map over the raw value, producing a new SensitiveString.
895
+ * The transformation function receives the raw value.
896
+ *
897
+ * @param fn - Transformation function
898
+ * @param ctx - Reveal context for audit
899
+ * @returns A new SensitiveString with the transformed value, preserving class and label
900
+ * @throws If policy checking fails (e.g., context required but not provided).
901
+ */
902
+ map(fn: (value: string) => string, ctx?: RevealContext): SensitiveString<C>;
903
+ /**
904
+ * Reclassify this value with a different sensitivity class and/or label.
905
+ * Creates a new SensitiveString with the same value but different class/label.
906
+ *
907
+ * @param newKlass - The new sensitivity class
908
+ * @param newLabel - Optional new label (if undefined, preserves existing label)
909
+ * @param ctx - Reveal context for audit
910
+ * @returns A new SensitiveString with the new class
911
+ * @throws If policy checking fails (e.g., context required but not provided).
912
+ *
913
+ * @remarks
914
+ * Use with caution - this bypasses the automatic class escalation logic.
915
+ */
916
+ reclassify<D extends SensitivityClass>(newKlass: D, newLabel?: string, ctx?: RevealContext): SensitiveString<D>;
917
+ }
918
+ export {};
919
+ //# sourceMappingURL=sensitive-string.d.ts.map