@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.
- package/dist/bson.d.ts +28 -0
- package/dist/bson.d.ts.map +1 -0
- package/dist/bson.js +37 -0
- package/dist/bson.js.map +1 -0
- package/dist/classification.d.ts +69 -0
- package/dist/classification.d.ts.map +1 -0
- package/dist/classification.js +104 -0
- package/dist/classification.js.map +1 -0
- package/dist/compare.d.ts +36 -0
- package/dist/compare.d.ts.map +1 -0
- package/dist/compare.js +123 -0
- package/dist/compare.js.map +1 -0
- package/dist/context.d.ts +78 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +110 -0
- package/dist/context.js.map +1 -0
- package/dist/derive.d.ts +110 -0
- package/dist/derive.d.ts.map +1 -0
- package/dist/derive.js +153 -0
- package/dist/derive.js.map +1 -0
- package/dist/destination.d.ts +120 -0
- package/dist/destination.d.ts.map +1 -0
- package/dist/destination.js +352 -0
- package/dist/destination.js.map +1 -0
- package/dist/deterministic.d.ts +145 -0
- package/dist/deterministic.d.ts.map +1 -0
- package/dist/deterministic.js +352 -0
- package/dist/deterministic.js.map +1 -0
- package/dist/dev-mode.d.ts +177 -0
- package/dist/dev-mode.d.ts.map +1 -0
- package/dist/dev-mode.js +503 -0
- package/dist/dev-mode.js.map +1 -0
- package/dist/environment.d.ts +181 -0
- package/dist/environment.d.ts.map +1 -0
- package/dist/environment.js +558 -0
- package/dist/environment.js.map +1 -0
- package/dist/errors.d.ts +23 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +21 -0
- package/dist/errors.js.map +1 -0
- package/dist/global-state.d.ts +8 -0
- package/dist/global-state.d.ts.map +1 -0
- package/dist/global-state.js +22 -0
- package/dist/global-state.js.map +1 -0
- package/dist/hash.d.ts +74 -0
- package/dist/hash.d.ts.map +1 -0
- package/dist/hash.js +253 -0
- package/dist/hash.js.map +1 -0
- package/dist/hygiene.d.ts +242 -0
- package/dist/hygiene.d.ts.map +1 -0
- package/dist/hygiene.js +257 -0
- package/dist/hygiene.js.map +1 -0
- package/dist/index.d.ts +85 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +233 -0
- package/dist/index.js.map +1 -0
- package/dist/mask.d.ts +51 -0
- package/dist/mask.d.ts.map +1 -0
- package/dist/mask.js +461 -0
- package/dist/mask.js.map +1 -0
- package/dist/own-property.d.ts +20 -0
- package/dist/own-property.d.ts.map +1 -0
- package/dist/own-property.js +34 -0
- package/dist/own-property.js.map +1 -0
- package/dist/patterns.d.ts +12 -0
- package/dist/patterns.d.ts.map +1 -0
- package/dist/patterns.js +19 -0
- package/dist/patterns.js.map +1 -0
- package/dist/policy.d.ts +51 -0
- package/dist/policy.d.ts.map +1 -0
- package/dist/policy.js +181 -0
- package/dist/policy.js.map +1 -0
- package/dist/probe.d.ts +141 -0
- package/dist/probe.d.ts.map +1 -0
- package/dist/probe.js +213 -0
- package/dist/probe.js.map +1 -0
- package/dist/redact-copy.d.ts +61 -0
- package/dist/redact-copy.d.ts.map +1 -0
- package/dist/redact-copy.js +217 -0
- package/dist/redact-copy.js.map +1 -0
- package/dist/redact.d.ts +141 -0
- package/dist/redact.d.ts.map +1 -0
- package/dist/redact.js +514 -0
- package/dist/redact.js.map +1 -0
- package/dist/redaction-marker.d.ts +48 -0
- package/dist/redaction-marker.d.ts.map +1 -0
- package/dist/redaction-marker.js +138 -0
- package/dist/redaction-marker.js.map +1 -0
- package/dist/redaction-observer.d.ts +108 -0
- package/dist/redaction-observer.d.ts.map +1 -0
- package/dist/redaction-observer.js +103 -0
- package/dist/redaction-observer.js.map +1 -0
- package/dist/redaction-scope.d.ts +21 -0
- package/dist/redaction-scope.d.ts.map +1 -0
- package/dist/redaction-scope.js +44 -0
- package/dist/redaction-scope.js.map +1 -0
- package/dist/reference.d.ts +101 -0
- package/dist/reference.d.ts.map +1 -0
- package/dist/reference.js +123 -0
- package/dist/reference.js.map +1 -0
- package/dist/regexp.d.ts +25 -0
- package/dist/regexp.d.ts.map +1 -0
- package/dist/regexp.js +61 -0
- package/dist/regexp.js.map +1 -0
- package/dist/release.d.ts +88 -0
- package/dist/release.d.ts.map +1 -0
- package/dist/release.js +108 -0
- package/dist/release.js.map +1 -0
- package/dist/reveal-budget.d.ts +148 -0
- package/dist/reveal-budget.d.ts.map +1 -0
- package/dist/reveal-budget.js +314 -0
- package/dist/reveal-budget.js.map +1 -0
- package/dist/revocation.d.ts +168 -0
- package/dist/revocation.d.ts.map +1 -0
- package/dist/revocation.js +541 -0
- package/dist/revocation.js.map +1 -0
- package/dist/sealing.d.ts +283 -0
- package/dist/sealing.d.ts.map +1 -0
- package/dist/sealing.js +523 -0
- package/dist/sealing.js.map +1 -0
- package/dist/sensitive-string.d.ts +919 -0
- package/dist/sensitive-string.d.ts.map +1 -0
- package/dist/sensitive-string.js +2260 -0
- package/dist/sensitive-string.js.map +1 -0
- package/dist/serialized.d.ts +33 -0
- package/dist/serialized.d.ts.map +1 -0
- package/dist/serialized.js +65 -0
- package/dist/serialized.js.map +1 -0
- package/dist/template.d.ts +69 -0
- package/dist/template.d.ts.map +1 -0
- package/dist/template.js +158 -0
- package/dist/template.js.map +1 -0
- package/dist/ttl.d.ts +104 -0
- package/dist/ttl.d.ts.map +1 -0
- package/dist/ttl.js +330 -0
- package/dist/ttl.js.map +1 -0
- package/dist/types.d.ts +859 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +13 -0
- package/dist/types.js.map +1 -0
- package/dist/winston.d.ts +114 -0
- package/dist/winston.d.ts.map +1 -0
- package/dist/winston.js +170 -0
- package/dist/winston.js.map +1 -0
- package/dist/worker.d.ts +398 -0
- package/dist/worker.d.ts.map +1 -0
- package/dist/worker.js +861 -0
- package/dist/worker.js.map +1 -0
- package/dist/wrap.d.ts +287 -0
- package/dist/wrap.d.ts.map +1 -0
- package/dist/wrap.js +553 -0
- package/dist/wrap.js.map +1 -0
- package/package.json +10 -10
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.REFERENCE_VERSION = void 0;
|
|
4
|
+
exports.carriesReferenceMarker = carriesReferenceMarker;
|
|
5
|
+
exports.referenceFormatVersion = referenceFormatVersion;
|
|
6
|
+
exports.isSensitiveValueReference = isSensitiveValueReference;
|
|
7
|
+
const probe_js_1 = require("./probe.js");
|
|
8
|
+
const policy_js_1 = require("./policy.js");
|
|
9
|
+
/**
|
|
10
|
+
* The wire shape of a pointer to a value in a secrets store, and the guards
|
|
11
|
+
* that recognize one.
|
|
12
|
+
*
|
|
13
|
+
* `serialize()` puts the raw value on the wire and asks the transport for
|
|
14
|
+
* confidentiality. A reference asks for nothing: it names where the value is
|
|
15
|
+
* and the receiver fetches it with its own credentials, so the value never
|
|
16
|
+
* leaves the process that read it. That is the whole of what this file knows.
|
|
17
|
+
* Minting a reference needs the store identity, the version and the provider,
|
|
18
|
+
* and resolving one needs credentials and an authorization decision, so both
|
|
19
|
+
* live in `@platform-sec/sensitive-string-secrets`. The format lives here for
|
|
20
|
+
* the same reason the `serialize()` format does: the walks that must decide
|
|
21
|
+
* what to do with a wire object when they meet one are here.
|
|
22
|
+
*
|
|
23
|
+
* What they decide, for this shape, is to leave it alone. A reference carries
|
|
24
|
+
* no secret material at any version of the format, and reading one gets an
|
|
25
|
+
* attacker no closer to the value than the label already does, since resolving
|
|
26
|
+
* it needs credentials of their own. Redacting it would break the debugging
|
|
27
|
+
* that a reference-passing system exists to make possible, which is being able
|
|
28
|
+
* to see which secret a job refers to. So there is no `redactReference` next to
|
|
29
|
+
* `redactSerialized`, the walks descend into a reference as they would into any
|
|
30
|
+
* other plain object, and `containsSensitive()` answers false for one. Those
|
|
31
|
+
* are asserted positively in `reference.test.ts` rather than left to be
|
|
32
|
+
* incidental, so that a later change to redact everything carrying a
|
|
33
|
+
* `__sensitive`-shaped marker fails a test and arrives here.
|
|
34
|
+
*/
|
|
35
|
+
/**
|
|
36
|
+
* The only format version this build understands.
|
|
37
|
+
*
|
|
38
|
+
* A receiver that does not recognize a version refuses rather than guessing,
|
|
39
|
+
* and the refusal names the version it saw and nothing else from the payload.
|
|
40
|
+
*/
|
|
41
|
+
exports.REFERENCE_VERSION = 1;
|
|
42
|
+
/**
|
|
43
|
+
* Whether an object carries the reference marker, judged by the marker alone.
|
|
44
|
+
*
|
|
45
|
+
* Separate from {@link isSensitiveValueReference} because the two answer
|
|
46
|
+
* different questions. This one asks whether a sender meant to send a
|
|
47
|
+
* reference, which is what decides between "this is not a reference at all" and
|
|
48
|
+
* "this is a reference this build cannot accept": a receiver that answered the
|
|
49
|
+
* first for a marked object with a version it does not know would report a
|
|
50
|
+
* caller's own payload as malformed rather than reporting the version skew it
|
|
51
|
+
* actually found.
|
|
52
|
+
*
|
|
53
|
+
* The read goes through `probeProperty` because a walk runs it against every
|
|
54
|
+
* object it reaches, and an object that refuses the question is not a payload
|
|
55
|
+
* this library built.
|
|
56
|
+
*/
|
|
57
|
+
function carriesReferenceMarker(value) {
|
|
58
|
+
return (0, probe_js_1.probeProperty)(value, '__sensitiveRef') === true;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The format version a marked object claims, or `undefined` when it claims
|
|
62
|
+
* none this build can read.
|
|
63
|
+
*
|
|
64
|
+
* A receiver refusing a version it does not know has to name the version it
|
|
65
|
+
* saw, and it must name a number rather than whatever the sender put in the
|
|
66
|
+
* field, so the read is guarded and anything that is not a number answers
|
|
67
|
+
* `undefined`.
|
|
68
|
+
*/
|
|
69
|
+
function referenceFormatVersion(value) {
|
|
70
|
+
const version = (0, probe_js_1.probeProperty)(value, 'v');
|
|
71
|
+
return typeof version === 'number' && Number.isFinite(version) ? version : undefined;
|
|
72
|
+
}
|
|
73
|
+
/** Whether a value is a non-empty string, which every required field must be. */
|
|
74
|
+
function isNonEmptyString(value) {
|
|
75
|
+
return typeof value === 'string' && value !== '';
|
|
76
|
+
}
|
|
77
|
+
/** Whether an optional field is absent or a non-empty string. */
|
|
78
|
+
function isAbsentOrNonEmptyString(value) {
|
|
79
|
+
return value === undefined || isNonEmptyString(value);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Whether a value is a well-formed reference of the version this build knows.
|
|
83
|
+
*
|
|
84
|
+
* Structural rather than nominal, because a reference crosses a process
|
|
85
|
+
* boundary as JSON and arrives as a plain object that no `instanceof` can
|
|
86
|
+
* recognize. Every required member is checked, so a resolver that has this
|
|
87
|
+
* answer can read the members it needs without repeating the question, and the
|
|
88
|
+
* advisory `klass` is checked against the policy registry here rather than
|
|
89
|
+
* accepted as any string: a class the receiving process never registered is not
|
|
90
|
+
* a class it can act on.
|
|
91
|
+
*
|
|
92
|
+
* A registered class is still only advisory. This answers whether the field is
|
|
93
|
+
* readable, never whether the receiver should honour it.
|
|
94
|
+
*/
|
|
95
|
+
function isSensitiveValueReference(value) {
|
|
96
|
+
if (typeof value !== 'object' || value === null) {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
if (!carriesReferenceMarker(value)) {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
if (referenceFormatVersion(value) !== exports.REFERENCE_VERSION) {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
if (!isNonEmptyString((0, probe_js_1.probeProperty)(value, 'store'))) {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
if (!isNonEmptyString((0, probe_js_1.probeProperty)(value, 'path'))) {
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
if (!isAbsentOrNonEmptyString((0, probe_js_1.probeProperty)(value, 'version'))) {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
if (!isAbsentOrNonEmptyString((0, probe_js_1.probeProperty)(value, 'field'))) {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
if (!isAbsentOrNonEmptyString((0, probe_js_1.probeProperty)(value, 'label'))) {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
const klass = (0, probe_js_1.probeProperty)(value, 'klass');
|
|
121
|
+
return klass === undefined || (typeof klass === 'string' && (0, policy_js_1.hasPolicy)(klass));
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=reference.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reference.js","sourceRoot":"","sources":["../src/reference.ts"],"names":[],"mappings":";;;AAgFA,wDAEC;AAWD,wDAIC;AA0BD,8DAoCC;AA/JD,yCAA2C;AAC3C,2CAAwC;AAGxC;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH;;;;;GAKG;AACU,QAAA,iBAAiB,GAAG,CAAC,CAAC;AA4BnC;;;;;;;;;;;;;;GAcG;AACH,SAAgB,sBAAsB,CAAC,KAAa;IAClD,OAAO,IAAA,wBAAa,EAAC,KAAK,EAAE,gBAAgB,CAAC,KAAK,IAAI,CAAC;AACzD,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,sBAAsB,CAAC,KAAa;IAClD,MAAM,OAAO,GAAG,IAAA,wBAAa,EAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAE1C,OAAO,OAAO,OAAO,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;AACvF,CAAC;AAED,iFAAiF;AACjF,SAAS,gBAAgB,CAAC,KAAc;IACtC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,EAAE,CAAC;AACnD,CAAC;AAED,iEAAiE;AACjE,SAAS,wBAAwB,CAAC,KAAc;IAC9C,OAAO,KAAK,KAAK,SAAS,IAAI,gBAAgB,CAAC,KAAK,CAAC,CAAC;AACxD,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,SAAgB,yBAAyB,CAAC,KAAc;IACtD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KA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classes and instances with overridden `exec` or symbol methods must
|
|
5
|
+
* not receive a sensitive value, so the pattern is rebuilt from its own source
|
|
6
|
+
* and flags rather than used directly. The copy also keeps a match from moving
|
|
7
|
+
* the caller's `lastIndex`.
|
|
8
|
+
*
|
|
9
|
+
* @param operation - The fully qualified name to name in a rejection, such as
|
|
10
|
+
* `'SensitiveString.test'`. It is the whole message, not a suffix, so a
|
|
11
|
+
* caller reads back the function they actually called.
|
|
12
|
+
*/
|
|
13
|
+
export declare function snapshotRegExp(pattern: RegExp, operation: string): RegExp;
|
|
14
|
+
/**
|
|
15
|
+
* The same, without the flags that make `test()` stateful.
|
|
16
|
+
*
|
|
17
|
+
* A stored pattern is tested repeatedly against different strings. `g` and `y`
|
|
18
|
+
* make `test()` advance `lastIndex` and answer differently on each call, so a
|
|
19
|
+
* pattern kept for the life of a process would match every other time it was
|
|
20
|
+
* consulted. Dropping them is not a restriction on what a caller may express:
|
|
21
|
+
* neither flag changes which strings the pattern matches, only where the next
|
|
22
|
+
* search resumes.
|
|
23
|
+
*/
|
|
24
|
+
export declare function snapshotStatelessRegExp(pattern: RegExp, operation: string): RegExp;
|
|
25
|
+
//# sourceMappingURL=regexp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"regexp.d.ts","sourceRoot":"","sources":["../src/regexp.ts"],"names":[],"mappings":"AA+BA;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAGzE;AAED;;;;;;;;;GASG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAGlF"}
|
package/dist/regexp.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.snapshotRegExp = snapshotRegExp;
|
|
4
|
+
exports.snapshotStatelessRegExp = snapshotStatelessRegExp;
|
|
5
|
+
/* eslint-disable @typescript-eslint/unbound-method --
|
|
6
|
+
Detaching these getters from RegExp.prototype is the point: a subclass or an
|
|
7
|
+
instance with an overridden `source` cannot influence what is read. Each is
|
|
8
|
+
annotated `this: RegExp` and invoked through .call() with the pattern as the
|
|
9
|
+
receiver, which is the binding the rule asks for. */
|
|
10
|
+
const REGEXP_SOURCE_GETTER = Object.getOwnPropertyDescriptor(RegExp.prototype, 'source')?.get;
|
|
11
|
+
const REGEXP_FLAGS_GETTER = Object.getOwnPropertyDescriptor(RegExp.prototype, 'flags')?.get;
|
|
12
|
+
/* eslint-enable @typescript-eslint/unbound-method */
|
|
13
|
+
/**
|
|
14
|
+
* The pattern's own source and flags, read through the intrinsic getters.
|
|
15
|
+
*
|
|
16
|
+
* Calling them verifies the RegExp internal slots, works across realms, and
|
|
17
|
+
* bypasses an instance's overridden `source` or `flags`, which could otherwise
|
|
18
|
+
* report one pattern to the library and match another.
|
|
19
|
+
*/
|
|
20
|
+
function readPattern(pattern, operation) {
|
|
21
|
+
try {
|
|
22
|
+
return {
|
|
23
|
+
source: REGEXP_SOURCE_GETTER.call(pattern),
|
|
24
|
+
flags: REGEXP_FLAGS_GETTER.call(pattern),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
throw new TypeError(`${operation} requires a regular expression`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Copy a caller-provided regular expression into a plain RegExp.
|
|
33
|
+
*
|
|
34
|
+
* RegExp subclasses and instances with overridden `exec` or symbol methods must
|
|
35
|
+
* not receive a sensitive value, so the pattern is rebuilt from its own source
|
|
36
|
+
* and flags rather than used directly. The copy also keeps a match from moving
|
|
37
|
+
* the caller's `lastIndex`.
|
|
38
|
+
*
|
|
39
|
+
* @param operation - The fully qualified name to name in a rejection, such as
|
|
40
|
+
* `'SensitiveString.test'`. It is the whole message, not a suffix, so a
|
|
41
|
+
* caller reads back the function they actually called.
|
|
42
|
+
*/
|
|
43
|
+
function snapshotRegExp(pattern, operation) {
|
|
44
|
+
const { source, flags } = readPattern(pattern, operation);
|
|
45
|
+
return new RegExp(source, flags);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The same, without the flags that make `test()` stateful.
|
|
49
|
+
*
|
|
50
|
+
* A stored pattern is tested repeatedly against different strings. `g` and `y`
|
|
51
|
+
* make `test()` advance `lastIndex` and answer differently on each call, so a
|
|
52
|
+
* pattern kept for the life of a process would match every other time it was
|
|
53
|
+
* consulted. Dropping them is not a restriction on what a caller may express:
|
|
54
|
+
* neither flag changes which strings the pattern matches, only where the next
|
|
55
|
+
* search resumes.
|
|
56
|
+
*/
|
|
57
|
+
function snapshotStatelessRegExp(pattern, operation) {
|
|
58
|
+
const { source, flags } = readPattern(pattern, operation);
|
|
59
|
+
return new RegExp(source, flags.replace(/[gy]/g, ''));
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=regexp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"regexp.js","sourceRoot":"","sources":["../src/regexp.ts"],"names":[],"mappings":";;AA2CA,wCAGC;AAYD,0DAGC;AA7DD;;;;uDAIuD;AACvD,MAAM,oBAAoB,GAAG,MAAM,CAAC,wBAAwB,CAAC,MAAM,CAAC,SAAS,EAAE,QAAQ,CAAC,EAAE,GAE/E,CAAC;AACZ,MAAM,mBAAmB,GAAG,MAAM,CAAC,wBAAwB,CAAC,MAAM,CAAC,SAAS,EAAE,OAAO,CAAC,EAAE,GAE7E,CAAC;AACZ,qDAAqD;AAErD;;;;;;GAMG;AACH,SAAS,WAAW,CAAC,OAAe,EAAE,SAAiB;IACrD,IAAI,CAAC;QACH,OAAO;YACL,MAAM,EAAE,oBAAoB,CAAC,IAAI,CAAC,OAAO,CAAC;YAC1C,KAAK,EAAE,mBAAmB,CAAC,IAAI,CAAC,OAAO,CAAC;SACzC,CAAC;IACJ,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,SAAS,CAAC,GAAG,SAAS,gCAAgC,CAAC,CAAC;IACpE,CAAC;AACH,CAAC;AAED;;;;;;;;;;;GAWG;AACH,SAAgB,cAAc,CAAC,OAAe,EAAE,SAAiB;IAC/D,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,WAAW,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IAC1D,OAAO,IAAI,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AACnC,CAAC;AAED;;;;;;;;;GASG;AACH,SAAgB,uBAAuB,CAAC,OAAe,EAAE,SAAiB;IACxE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,WAAW,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IAC1D,OAAO,IAAI,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AACxD,CAAC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { SensitiveStringOptions } from './types.js';
|
|
2
|
+
import { SensitiveStringError } from './errors.js';
|
|
3
|
+
/**
|
|
4
|
+
* A reveal that waits on a verification.
|
|
5
|
+
*
|
|
6
|
+
* The destination binding answers where a value may go; it cannot answer
|
|
7
|
+
* whether the recipient has been checked yet. The adoption corpus has the
|
|
8
|
+
* case: a credential whose destination trust is decided by an SSH host key
|
|
9
|
+
* digest against a known-hosts store, an asynchronous check that settles
|
|
10
|
+
* after the connection is opened and before the password may be sent. No
|
|
11
|
+
* arrangement of wrappers expressed "not readable until this promise
|
|
12
|
+
* resolves", and the record said a primitive for it would sit beside the
|
|
13
|
+
* model rather than inside it.
|
|
14
|
+
*
|
|
15
|
+
* This is that primitive. A value constructed with `releasedBy` holds a cell
|
|
16
|
+
* that starts `pending`, becomes `released` when the promise resolves `true`,
|
|
17
|
+
* and becomes `refused`, for good, when it resolves anything else or rejects.
|
|
18
|
+
* The gate reads the cell on every exposing read. Nothing lifts a refusal:
|
|
19
|
+
* a verification that did not say yes has said no, and a retry is a new
|
|
20
|
+
* value with a new check.
|
|
21
|
+
*
|
|
22
|
+
* Shared by reference between a value and its derivatives, like every other
|
|
23
|
+
* lifecycle cell, though a derivative of an unreleased value cannot be built:
|
|
24
|
+
* deriving reads the value, and the read refuses.
|
|
25
|
+
*/
|
|
26
|
+
/** Where a released value stands. */
|
|
27
|
+
export type ReleaseStatus = 'pending' | 'released' | 'refused';
|
|
28
|
+
/**
|
|
29
|
+
* Raised when an operation needs the raw value of an instance whose
|
|
30
|
+
* verification has not settled, or settled against it.
|
|
31
|
+
*
|
|
32
|
+
* `status` separates the two, because they invite different responses: a
|
|
33
|
+
* caller who reads a `pending` value read it too early and can await the
|
|
34
|
+
* verification, and one who reads a `refused` value has a credential the
|
|
35
|
+
* check rejected. `label` is developer text; the message carries no part of
|
|
36
|
+
* the value.
|
|
37
|
+
*/
|
|
38
|
+
export declare class UnreleasedSensitiveValueError extends SensitiveStringError {
|
|
39
|
+
readonly status: Exclude<ReleaseStatus, 'released'>;
|
|
40
|
+
readonly label?: string | undefined;
|
|
41
|
+
readonly name = "UnreleasedSensitiveValueError";
|
|
42
|
+
readonly code = "unreleased-value";
|
|
43
|
+
constructor(status: Exclude<ReleaseStatus, 'released'>, label?: string | undefined, detail?: string, cause?: unknown);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The release state a value and its derivatives share.
|
|
47
|
+
*
|
|
48
|
+
* Mutated only by the promise's own settlement, from inside this module. The
|
|
49
|
+
* cell is the promise's answer and nothing else: there is no setter, and no
|
|
50
|
+
* way to release a value from outside.
|
|
51
|
+
*/
|
|
52
|
+
export interface ReleaseCell {
|
|
53
|
+
status: ReleaseStatus;
|
|
54
|
+
/** Why a `refused` cell refused, as text that carries no value. */
|
|
55
|
+
detail: string | undefined;
|
|
56
|
+
/** What the verification threw, when it threw. */
|
|
57
|
+
cause: unknown;
|
|
58
|
+
}
|
|
59
|
+
/** A state object that may carry a release cell. */
|
|
60
|
+
export interface ReleaseHolder {
|
|
61
|
+
readonly release: ReleaseCell | undefined;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Build the release cell for a newly constructed value, or `undefined` when
|
|
65
|
+
* the value waits on nothing.
|
|
66
|
+
*
|
|
67
|
+
* The option has to be a thenable. A plain boolean is refused rather than read
|
|
68
|
+
* as an already-settled verification, because a caller who wrote
|
|
69
|
+
* `releasedBy: verified` where `verified` is the result rather than the
|
|
70
|
+
* promise has a bug this would otherwise hide in both directions: `true`
|
|
71
|
+
* releases a value nothing checked and `false` bricks one for no reason.
|
|
72
|
+
*
|
|
73
|
+
* Both handlers are attached here, so a rejected verification is consumed by
|
|
74
|
+
* the cell and never surfaces as an unhandled rejection: the refusal is
|
|
75
|
+
* reported where the value is read, which is where it matters.
|
|
76
|
+
*
|
|
77
|
+
* @throws TypeError If `releasedBy` is not a thenable.
|
|
78
|
+
*/
|
|
79
|
+
export declare function planRelease(options: SensitiveStringOptions | undefined): ReleaseCell | undefined;
|
|
80
|
+
/**
|
|
81
|
+
* The first release cell among these states that is not released, or
|
|
82
|
+
* `undefined` when every value this one came from is readable.
|
|
83
|
+
*
|
|
84
|
+
* A pending cell is reported ahead of a refused one only by state order; both
|
|
85
|
+
* refuse, and a value derived from a refused value cannot exist anyway.
|
|
86
|
+
*/
|
|
87
|
+
export declare function releaseInForce(states: readonly ReleaseHolder[]): ReleaseCell | undefined;
|
|
88
|
+
//# sourceMappingURL=release.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"release.d.ts","sourceRoot":"","sources":["../src/release.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AACzD,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,qCAAqC;AACrC,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,UAAU,GAAG,SAAS,CAAC;AAE/D;;;;;;;;;GASG;AACH,qBAAa,6BAA8B,SAAQ,oBAAoB;IAKnE,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,aAAa,EAAE,UAAU,CAAC;IACnD,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM;IALzB,SAAkB,IAAI,mCAAmC;IACzD,SAAkB,IAAI,sBAAsB;gBAGjC,MAAM,EAAE,OAAO,CAAC,aAAa,EAAE,UAAU,CAAC,EAC1C,KAAK,CAAC,EAAE,MAAM,YAAA,EACvB,MAAM,CAAC,EAAE,MAAM,EACf,KAAK,CAAC,EAAE,OAAO;CAalB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,aAAa,CAAC;IACtB,mEAAmE;IACnE,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,kDAAkD;IAClD,KAAK,EAAE,OAAO,CAAC;CAChB;AAED,oDAAoD;AACpD,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,OAAO,EAAE,WAAW,GAAG,SAAS,CAAC;CAC3C;AAMD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,sBAAsB,GAAG,SAAS,GAAG,WAAW,GAAG,SAAS,CAqDhG;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,SAAS,aAAa,EAAE,GAAG,WAAW,GAAG,SAAS,CAUxF"}
|
package/dist/release.js
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UnreleasedSensitiveValueError = void 0;
|
|
4
|
+
exports.planRelease = planRelease;
|
|
5
|
+
exports.releaseInForce = releaseInForce;
|
|
6
|
+
const errors_js_1 = require("./errors.js");
|
|
7
|
+
/**
|
|
8
|
+
* Raised when an operation needs the raw value of an instance whose
|
|
9
|
+
* verification has not settled, or settled against it.
|
|
10
|
+
*
|
|
11
|
+
* `status` separates the two, because they invite different responses: a
|
|
12
|
+
* caller who reads a `pending` value read it too early and can await the
|
|
13
|
+
* verification, and one who reads a `refused` value has a credential the
|
|
14
|
+
* check rejected. `label` is developer text; the message carries no part of
|
|
15
|
+
* the value.
|
|
16
|
+
*/
|
|
17
|
+
class UnreleasedSensitiveValueError extends errors_js_1.SensitiveStringError {
|
|
18
|
+
status;
|
|
19
|
+
label;
|
|
20
|
+
name = 'UnreleasedSensitiveValueError';
|
|
21
|
+
code = 'unreleased-value';
|
|
22
|
+
constructor(status, label, detail, cause) {
|
|
23
|
+
const named = label !== undefined ? ` '${label}'` : '';
|
|
24
|
+
super(status === 'pending'
|
|
25
|
+
? `Sensitive value${named} cannot be read yet: the verification it was constructed ` +
|
|
26
|
+
'with has not settled. Await it before reading the value.'
|
|
27
|
+
: `Sensitive value${named} cannot be read: ${detail ?? 'its verification refused'}. ` +
|
|
28
|
+
'A refusal is final; construct a new value with a new verification to try again.', cause === undefined ? undefined : { cause });
|
|
29
|
+
this.status = status;
|
|
30
|
+
this.label = label;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.UnreleasedSensitiveValueError = UnreleasedSensitiveValueError;
|
|
34
|
+
function describeType(value) {
|
|
35
|
+
return value === null ? 'null' : typeof value;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Build the release cell for a newly constructed value, or `undefined` when
|
|
39
|
+
* the value waits on nothing.
|
|
40
|
+
*
|
|
41
|
+
* The option has to be a thenable. A plain boolean is refused rather than read
|
|
42
|
+
* as an already-settled verification, because a caller who wrote
|
|
43
|
+
* `releasedBy: verified` where `verified` is the result rather than the
|
|
44
|
+
* promise has a bug this would otherwise hide in both directions: `true`
|
|
45
|
+
* releases a value nothing checked and `false` bricks one for no reason.
|
|
46
|
+
*
|
|
47
|
+
* Both handlers are attached here, so a rejected verification is consumed by
|
|
48
|
+
* the cell and never surfaces as an unhandled rejection: the refusal is
|
|
49
|
+
* reported where the value is read, which is where it matters.
|
|
50
|
+
*
|
|
51
|
+
* @throws TypeError If `releasedBy` is not a thenable.
|
|
52
|
+
*/
|
|
53
|
+
function planRelease(options) {
|
|
54
|
+
const verification = options?.releasedBy;
|
|
55
|
+
if (verification === undefined) {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
if (verification === null ||
|
|
59
|
+
(typeof verification !== 'object' && typeof verification !== 'function') ||
|
|
60
|
+
typeof verification.then !== 'function') {
|
|
61
|
+
throw new TypeError(`SensitiveString: releasedBy must be a promise of a boolean, received ${describeType(verification)}. ` +
|
|
62
|
+
'Pass the verification itself, not its result.');
|
|
63
|
+
}
|
|
64
|
+
const cell = { status: 'pending', detail: undefined, cause: undefined };
|
|
65
|
+
// `Promise.resolve` adopts a foreign thenable, so a handler runs at most
|
|
66
|
+
// once whatever the thenable does. The cell latches: the first settlement
|
|
67
|
+
// decides, and a status other than `pending` is never overwritten.
|
|
68
|
+
Promise.resolve(verification).then((answer) => {
|
|
69
|
+
if (cell.status !== 'pending') {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (answer === true) {
|
|
73
|
+
cell.status = 'released';
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
cell.status = 'refused';
|
|
77
|
+
cell.detail =
|
|
78
|
+
answer === false
|
|
79
|
+
? 'its verification refused'
|
|
80
|
+
: `its verification answered with ${describeType(answer)} instead of a boolean, which ` +
|
|
81
|
+
'is read as a refusal';
|
|
82
|
+
}, (error) => {
|
|
83
|
+
if (cell.status !== 'pending') {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
cell.status = 'refused';
|
|
87
|
+
cell.detail = 'its verification threw instead of answering';
|
|
88
|
+
cell.cause = error;
|
|
89
|
+
});
|
|
90
|
+
return cell;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* The first release cell among these states that is not released, or
|
|
94
|
+
* `undefined` when every value this one came from is readable.
|
|
95
|
+
*
|
|
96
|
+
* A pending cell is reported ahead of a refused one only by state order; both
|
|
97
|
+
* refuse, and a value derived from a refused value cannot exist anyway.
|
|
98
|
+
*/
|
|
99
|
+
function releaseInForce(states) {
|
|
100
|
+
for (const state of states) {
|
|
101
|
+
const cell = state.release;
|
|
102
|
+
if (cell !== undefined && cell.status !== 'released') {
|
|
103
|
+
return cell;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=release.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"release.js","sourceRoot":"","sources":["../src/release.ts"],"names":[],"mappings":";;;AAuGA,kCAqDC;AASD,wCAUC;AA9KD,2CAAmD;AA6BnD;;;;;;;;;GASG;AACH,MAAa,6BAA8B,SAAQ,gCAAoB;IAK1D;IACA;IALO,IAAI,GAAG,+BAA+B,CAAC;IACvC,IAAI,GAAG,kBAAkB,CAAC;IAE5C,YACW,MAA0C,EAC1C,KAAc,EACvB,MAAe,EACf,KAAe;QAEf,MAAM,KAAK,GAAG,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QAEvD,KAAK,CACH,MAAM,KAAK,SAAS;YAClB,CAAC,CAAC,kBAAkB,KAAK,2DAA2D;gBAChF,0DAA0D;YAC9D,CAAC,CAAC,kBAAkB,KAAK,oBAAoB,MAAM,IAAI,0BAA0B,IAAI;gBACjF,iFAAiF,EACvF,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAC5C,CAAC;QAdO,WAAM,GAAN,MAAM,CAAoC;QAC1C,UAAK,GAAL,KAAK,CAAS;IAczB,CAAC;CACF;AArBD,sEAqBC;AAsBD,SAAS,YAAY,CAAC,KAAc;IAClC,OAAO,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,MAAM,CA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AC;QAED,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC;QACxB,IAAI,CAAC,MAAM,GAAG,6CAA6C,CAAC;QAC5D,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC,CACF,CAAC;IAEF,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,cAAc,CAAC,MAAgC;IAC7D,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC;QAE3B,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,MAAM,KAAK,UAAU,EAAE,CAAC;YACrD,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import type { SensitiveStringOptions } from './types.js';
|
|
2
|
+
import { SensitiveStringError } from './errors.js';
|
|
3
|
+
/**
|
|
4
|
+
* Raised when a value has been exposed as many times as it is allowed to be.
|
|
5
|
+
*
|
|
6
|
+
* The condition is permanent: nothing resets the count, so a caller that sees
|
|
7
|
+
* this fetches a fresh secret rather than retrying.
|
|
8
|
+
*/
|
|
9
|
+
export declare class RevealLimitExceededError extends SensitiveStringError {
|
|
10
|
+
/** The lifetime limit that was reached. */
|
|
11
|
+
readonly limit: number;
|
|
12
|
+
/** Which attempt this was, counting from one. Always greater than `limit`. */
|
|
13
|
+
readonly attempts: number;
|
|
14
|
+
readonly label?: string | undefined;
|
|
15
|
+
readonly name = "RevealLimitExceededError";
|
|
16
|
+
readonly code = "reveal-limit-exceeded";
|
|
17
|
+
constructor(
|
|
18
|
+
/** The lifetime limit that was reached. */
|
|
19
|
+
limit: number,
|
|
20
|
+
/** Which attempt this was, counting from one. Always greater than `limit`. */
|
|
21
|
+
attempts: number, label?: string | undefined);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Raised when a value has been exposed too often within its window.
|
|
25
|
+
*
|
|
26
|
+
* The condition is temporary, and `retryAfter` says how temporary, so a caller
|
|
27
|
+
* that means to continue can back off rather than fetch a new secret.
|
|
28
|
+
*/
|
|
29
|
+
export declare class RevealRateLimitError extends SensitiveStringError {
|
|
30
|
+
/** Milliseconds until the window has room again. Always positive. */
|
|
31
|
+
readonly retryAfter: number;
|
|
32
|
+
/** The number of reveals the window allows. */
|
|
33
|
+
readonly windowLimit: number;
|
|
34
|
+
readonly label?: string | undefined;
|
|
35
|
+
readonly name = "RevealRateLimitError";
|
|
36
|
+
readonly code = "reveal-rate-limited";
|
|
37
|
+
constructor(
|
|
38
|
+
/** Milliseconds until the window has room again. Always positive. */
|
|
39
|
+
retryAfter: number,
|
|
40
|
+
/** The number of reveals the window allows. */
|
|
41
|
+
windowLimit: number, label?: string | undefined);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The sliding window, when one is configured.
|
|
45
|
+
*
|
|
46
|
+
* `times` holds the charge times still inside the window, oldest at `head`.
|
|
47
|
+
* Entries ahead of `head` are dead and are dropped in place, which keeps the
|
|
48
|
+
* common case free of allocation; the array is compacted once its dead prefix
|
|
49
|
+
* is at least as large as what remains, so it holds at most twice the limit
|
|
50
|
+
* however long the value lives and however much traffic passes through it.
|
|
51
|
+
*/
|
|
52
|
+
export interface RevealRate {
|
|
53
|
+
readonly window: number;
|
|
54
|
+
readonly limit: number;
|
|
55
|
+
readonly times: number[];
|
|
56
|
+
head: number;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The limits on how often a value may be exposed.
|
|
60
|
+
*
|
|
61
|
+
* Shared by reference between a value and everything derived from it, so a
|
|
62
|
+
* substring of a single-use token spends the same budget the token has. A value
|
|
63
|
+
* with neither limit has no budget object at all, which is what keeps the gate
|
|
64
|
+
* free for the values that configure nothing.
|
|
65
|
+
*/
|
|
66
|
+
export interface RevealBudget {
|
|
67
|
+
/** Lifetime limit, or `undefined` when the number of reveals is unbounded. */
|
|
68
|
+
readonly maxReveals: number | undefined;
|
|
69
|
+
/** Sliding window, or `undefined` when there is no rate limit. */
|
|
70
|
+
readonly rate: RevealRate | undefined;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The part of a value's shared state this module reads and writes.
|
|
74
|
+
*
|
|
75
|
+
* Every value counts its reveals, whether or not it limits them, so
|
|
76
|
+
* `revealCount` answers honestly for a value that was constructed with no
|
|
77
|
+
* options at all.
|
|
78
|
+
*/
|
|
79
|
+
export interface RevealCounted {
|
|
80
|
+
reveals: number;
|
|
81
|
+
readonly budget: RevealBudget | undefined;
|
|
82
|
+
}
|
|
83
|
+
/** A state that carries limits, which is the only kind the check walks. */
|
|
84
|
+
export interface RevealConstrained extends RevealCounted {
|
|
85
|
+
readonly budget: RevealBudget;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Build the reveal budget for a newly constructed value, or `undefined` when it
|
|
89
|
+
* has no limits.
|
|
90
|
+
*
|
|
91
|
+
* @throws TypeError If an option has the wrong type.
|
|
92
|
+
* @throws RangeError If a limit is out of range.
|
|
93
|
+
* @throws Error If only one half of the rate limit is given.
|
|
94
|
+
*/
|
|
95
|
+
export declare function planRevealBudget(options: SensitiveStringOptions | undefined): RevealBudget | undefined;
|
|
96
|
+
/**
|
|
97
|
+
* Decide whether every budget admits one more reveal, without charging any.
|
|
98
|
+
*
|
|
99
|
+
* Separating the decision from the charge is what lets the gate refuse before
|
|
100
|
+
* it authorizes and audits, so a refusal is not recorded as a reveal, and lets
|
|
101
|
+
* an audit hook that throws stop a reveal before it is counted.
|
|
102
|
+
*
|
|
103
|
+
* Every budget is checked before any is charged, so a derivative of two values
|
|
104
|
+
* cannot spend one parent's budget on a read the other refused.
|
|
105
|
+
*
|
|
106
|
+
* @throws RevealLimitExceededError If a lifetime limit has been reached.
|
|
107
|
+
* @throws RevealRateLimitError If a window is full.
|
|
108
|
+
*/
|
|
109
|
+
export declare function checkRevealBudget(states: readonly RevealConstrained[], label: string | undefined): void;
|
|
110
|
+
/**
|
|
111
|
+
* Charge one reveal against every state a value reads.
|
|
112
|
+
*
|
|
113
|
+
* Called only once {@link checkRevealBudget} has admitted the read and the
|
|
114
|
+
* policy and audit hooks have let it through, so the count is of reveals that
|
|
115
|
+
* reached the caller rather than of attempts.
|
|
116
|
+
*
|
|
117
|
+
* The window records this instant rather than the one the check read, because
|
|
118
|
+
* the two are separated by however long a caller's audit hook takes. Dating a
|
|
119
|
+
* charge from the check would let an audit hook slower than the window push
|
|
120
|
+
* every entry out of it as it was written.
|
|
121
|
+
*/
|
|
122
|
+
export declare function chargeReveal(states: readonly RevealCounted[]): void;
|
|
123
|
+
/**
|
|
124
|
+
* Whether any of these states has spent its lifetime limit.
|
|
125
|
+
*/
|
|
126
|
+
export declare function isBudgetExhausted(states: readonly RevealConstrained[]): boolean;
|
|
127
|
+
/**
|
|
128
|
+
* The smallest number of reveals any of these states still allows, or
|
|
129
|
+
* `undefined` when none of them limits the total.
|
|
130
|
+
*/
|
|
131
|
+
export declare function revealsRemaining(states: readonly RevealConstrained[]): number | undefined;
|
|
132
|
+
/**
|
|
133
|
+
* The construction options, among these states, that describe a limit no
|
|
134
|
+
* other isolate can share.
|
|
135
|
+
*
|
|
136
|
+
* A budget is a counter held by reference between a value and everything
|
|
137
|
+
* derived from it. A thread or a child process is a different isolate, so
|
|
138
|
+
* there is no reference to hand it, and the wire format resets counters for
|
|
139
|
+
* the same reason. A handoff would therefore give the far side a fresh budget,
|
|
140
|
+
* which turns a three-reveal limit into three per thread. `toWorkerPayload()`
|
|
141
|
+
* asks this before reading anything and refuses a value that answers.
|
|
142
|
+
*
|
|
143
|
+
* Named by option rather than by state so the message tells the caller what
|
|
144
|
+
* they wrote. The two halves of a rate limit are reported together, because
|
|
145
|
+
* they are given together.
|
|
146
|
+
*/
|
|
147
|
+
export declare function unshareableBudgetOptions(states: readonly RevealConstrained[]): readonly (keyof SensitiveStringOptions)[];
|
|
148
|
+
//# sourceMappingURL=reveal-budget.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