@coffre/core 0.15.0 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/README.md +1 -1
  2. package/dist/{access-CgQTlUMz.js → access-CF8UG59J.js} +70 -95
  3. package/dist/{access-DqLJjnLM.d.ts → access-ERdGGHG7.d.ts} +45 -64
  4. package/dist/access.d.ts +2 -2
  5. package/dist/access.js +2 -2
  6. package/dist/envelope.d.ts +28 -9
  7. package/dist/envelope.js +25 -8
  8. package/dist/identity.d.ts +3 -1018
  9. package/dist/identity.js +885 -623
  10. package/dist/index-DuG9p3GH.d.ts +1233 -0
  11. package/dist/kek.d.ts +10 -16
  12. package/dist/kek.js +26 -41
  13. package/dist/log.d.ts +114 -0
  14. package/dist/log.js +291 -0
  15. package/dist/mcp.d.ts +27 -4
  16. package/dist/mcp.js +31 -10
  17. package/dist/recipe-BgJpmJum.d.ts +128 -0
  18. package/dist/recipe.d.ts +2 -127
  19. package/dist/{registry-D7X-x202.d.ts → registry-B7_LUDsJ.d.ts} +30 -5
  20. package/dist/schemas.d.ts +14 -12
  21. package/dist/schemas.js +16 -14
  22. package/dist/{types-Cp3lB_-W.js → types-DwTO_b4H.js} +17 -5
  23. package/dist/vault.d.ts +1771 -1419
  24. package/dist/vault.js +96 -302
  25. package/dist/{workloads-D049JH0M.d.ts → workloads-CW2dK4AW.d.ts} +1 -9
  26. package/dist/workloads.d.ts +2 -2
  27. package/dist/workloads.js +1 -9
  28. package/package.json +7 -7
  29. package/src/access.ts +63 -95
  30. package/src/changes/access.ts +140 -0
  31. package/src/changes/freezes.ts +40 -0
  32. package/src/changes/mcp.ts +150 -0
  33. package/src/changes/places.ts +219 -0
  34. package/src/changes/secrets.ts +235 -0
  35. package/src/changes/signin.ts +197 -0
  36. package/src/changes/workloads.ts +166 -0
  37. package/src/context.ts +18 -2
  38. package/src/envelope.ts +35 -12
  39. package/src/identity/auth.ts +11 -3
  40. package/src/identity/aws.ts +62 -0
  41. package/src/identity/github-app.ts +45 -24
  42. package/src/identity/index.ts +3 -2
  43. package/src/identity/{profile-rules.ts → profiles.ts} +1 -9
  44. package/src/identity/proofs.ts +306 -0
  45. package/src/identity/signin/config.ts +1 -1
  46. package/src/identity/tokens.ts +10 -3
  47. package/src/identity/verifier.ts +73 -14
  48. package/src/identity/workload-token.ts +4 -0
  49. package/src/identity/workloads.ts +0 -11
  50. package/src/kek/aws-kms.ts +18 -13
  51. package/src/kek/check.ts +16 -46
  52. package/src/kek/index.ts +2 -2
  53. package/src/kek/types.ts +15 -3
  54. package/src/log/index.ts +7 -0
  55. package/src/{audit → log}/tiles.ts +18 -49
  56. package/src/{audit → log}/tree.ts +2 -2
  57. package/src/mcp.ts +36 -9
  58. package/src/schemas.ts +15 -12
  59. package/src/vault.ts +251 -1150
  60. package/dist/merkle.d.ts +0 -456
  61. package/dist/merkle.js +0 -964
  62. package/src/answers.ts +0 -209
  63. package/src/audit/leaf.ts +0 -81
  64. package/src/audit/merkle.ts +0 -13
  65. package/src/audit/note.ts +0 -187
  66. package/src/audit/pair.ts +0 -86
  67. package/src/audit/verify.ts +0 -393
  68. package/src/audit/witness.ts +0 -50
  69. package/src/checkpoint.ts +0 -22
  70. package/src/identity/run-proof.ts +0 -159
package/dist/mcp.js CHANGED
@@ -30,6 +30,22 @@ const MCP_SCOPE_INFO = {
30
30
  description: "Grants, members, service tokens and trusted workloads. Each change waits for your approval on coffre."
31
31
  }
32
32
  };
33
+ /** How long a code waits for its client: long enough for a redirect, and no longer. */
34
+ const CODE_SECONDS = 60;
35
+ /** An hour: what a leaked access token is good for, at most, unless its connection ends sooner. */
36
+ const ACCESS_TOKEN_MINUTES = 60;
37
+ /** Connections a person may hold at once, codes waiting included, before Connected apps has to lose one. */
38
+ const MAX_CONNECTIONS = 20;
39
+ /** Registered clients the instance keeps at most: anyone may register one, so the table has a ceiling. */
40
+ const MAX_CLIENTS = 1e4;
41
+ /** How long an approval waits for its person: a change an MCP client asks for that nobody decides by then expired. */
42
+ const APPROVAL_SECONDS = 300;
43
+ /** Approvals a connection holds waiting at once: no flood of prompts, and no more than this many entries an expiry. */
44
+ const MAX_PENDING = 5;
45
+ /** The longest a call's arguments are, as canonical JSON, that an approval keeps: a few names, a note, a scope of some places. */
46
+ const MAX_ASK_ARGUMENTS = 4096;
47
+ /** The tools whose Approve changes nothing but shows the person a value (`mcp.decide`): every other is approved by its change. */
48
+ const MCP_SHOWS = ["show_secret_value"];
33
49
  /** What OAuth's `offline_access` asks for, a refresh token, every connection has: accepted and dropped. */
34
50
  const IGNORED_SCOPES = /* @__PURE__ */ new Set(["offline_access"]);
35
51
  function isMcpScope(value) {
@@ -90,6 +106,7 @@ const LOOPBACK_HOSTS = /* @__PURE__ */ new Set([
90
106
  * scheme, no fragment, no user or password.
91
107
  */
92
108
  function redirectKind(value) {
109
+ if (/[\0\p{Cs}]/u.test(value)) throw new ClientInvalid("a redirect holds a NUL or half of a surrogate pair");
93
110
  let url;
94
111
  try {
95
112
  url = new URL(value);
@@ -128,16 +145,20 @@ function redirectHost(value) {
128
145
  }
129
146
  const MAX_REDIRECTS = 10;
130
147
  const MAX_NAME = 100;
131
- /** The longest client ID URL: a token's issue or revoke through its connection names it in the vault's record, which takes no longer. */
132
- const MAX_CLIENT_ID = 2048;
148
+ /** The longest client id the vault keeps (`text` in its ops). */
149
+ const MAX_CLIENT_ID = 256;
150
+ /**
151
+ * Whether a client_id is one the vault and Postgres keep: 256 characters at
152
+ * most, with no NUL and no half of a surrogate pair. Any other is no
153
+ * client's, and is answered as such before it is read or sent anywhere.
154
+ */
155
+ const clientIdKept = (value) => value.length <= 256 && !/[\0\p{Cs}]/u.test(value);
133
156
  /**
134
157
  * Whether `value` is a Client ID Metadata Document's URL: HTTPS, with a
135
- * path, and nothing a document's address has no use for, no longer than
136
- * `MAX_CLIENT_ID`. On a loopback instance, a loopback one too, for
137
- * development and conformance.
158
+ * path, and nothing a document's address has no use for. On a loopback
159
+ * instance, a loopback one too, for development and conformance.
138
160
  */
139
161
  function isClientIdUrl(value, options) {
140
- if (value.length > MAX_CLIENT_ID) return false;
141
162
  if (!value.startsWith("https://") && !(options.allowLoopback && value.startsWith("http://"))) return false;
142
163
  let url;
143
164
  try {
@@ -196,10 +217,10 @@ function registrationRedirects(value) {
196
217
  dropped
197
218
  };
198
219
  }
199
- /** A client's name as shown: its own, cut short, or its host when it gives none. */
220
+ /** A client's name as shown: its own, or its host when it gives none, cut short. */
200
221
  function clientName(value, fallback) {
201
- const name = typeof value === "string" ? value.replace(/[\p{Cc}\p{Cf}]/gu, "").trim() : "";
202
- return name === "" ? fallback : name.slice(0, MAX_NAME);
222
+ const own = typeof value === "string" ? value.replace(/[\p{Cc}\p{Cf}\p{Cs}]/gu, "").trim() : "";
223
+ return (own === "" ? fallback : own).slice(0, MAX_NAME).replace(/[\uD800-\uDBFF]$/, "").trim();
203
224
  }
204
225
  function redirectList(value) {
205
226
  if (!Array.isArray(value) || value.length === 0 || value.length > MAX_REDIRECTS || value.some((uri) => typeof uri !== "string")) throw new ClientInvalid(`the client metadata document must list 1 to ${MAX_REDIRECTS} redirect_uris`);
@@ -207,4 +228,4 @@ function redirectList(value) {
207
228
  return value;
208
229
  }
209
230
  //#endregion
210
- export { ClientInvalid, MCP_SCOPES, MCP_SCOPE_INFO, clientFromDocument, clientName, grantedScopes, isClientIdUrl, isMcpScope, parseScopes, redirectHost, redirectKind, redirectMatches, registrationRedirects, scopeString, supersedes };
231
+ export { ACCESS_TOKEN_MINUTES, APPROVAL_SECONDS, CODE_SECONDS, ClientInvalid, MAX_ASK_ARGUMENTS, MAX_CLIENTS, MAX_CLIENT_ID, MAX_CONNECTIONS, MAX_PENDING, MCP_SCOPES, MCP_SCOPE_INFO, MCP_SHOWS, clientFromDocument, clientIdKept, clientName, grantedScopes, isClientIdUrl, isMcpScope, parseScopes, redirectHost, redirectKind, redirectMatches, registrationRedirects, scopeString, supersedes };
@@ -0,0 +1,128 @@
1
+ //#region src/recipe.d.ts
2
+ /**
3
+ * How a secret's value is made, when a client makes it rather than a person
4
+ * typing it: random strings, AES keys and EC key pairs, from Web Crypto
5
+ * alone, the same in the browser and in the CLI.
6
+ *
7
+ * A recipe is short text, `bytes:32:hex`, which the CLI takes as
8
+ * `--generate` and the server stores beside the version it made, so that
9
+ * `coffre regenerate` and the page's Regenerate make the next one the same
10
+ * way. The server checks a recipe's shape and never makes a value: a value
11
+ * is made where it is sent from, and nothing here talks to the server.
12
+ *
13
+ * ```
14
+ * bytes:<1-256>[:base62|hex|base64|base64url] random bytes, base62 unless named
15
+ * aes:<128|256> an AES-GCM key: the raw key, base64
16
+ * ecdsa:<p-256|p-384|p-521> a key pair: PKCS #8 private, SPKI public, base64
17
+ * ecdh:<p-256|p-384|p-521>
18
+ * ```
19
+ */
20
+ type Encoding = 'base62' | 'hex' | 'base64' | 'base64url';
21
+ type AesSize = 128 | 256;
22
+ type Curve = 'P-256' | 'P-384' | 'P-521';
23
+ type PairAlgorithm = 'ECDSA' | 'ECDH';
24
+ type Recipe = {
25
+ kind: 'random';
26
+ encoding: Encoding;
27
+ bytes: number;
28
+ } | {
29
+ kind: 'aes';
30
+ size: AesSize;
31
+ } | {
32
+ kind: 'pair';
33
+ algorithm: PairAlgorithm;
34
+ curve: Curve;
35
+ };
36
+ /** A value, and for a key pair its public key, which is saved as a secret of its own. */
37
+ type Generated = {
38
+ value: string;
39
+ publicKey?: string;
40
+ };
41
+ /**
42
+ * What a write says about how its value was made, and what a listing says
43
+ * of a key's current value: its recipe, and for a key pair the two keys it
44
+ * wrote together, which only a write of both at once makes.
45
+ */
46
+ type Generation = {
47
+ recipe: string;
48
+ pair?: KeyPairNames;
49
+ };
50
+ type KeyPairNames = {
51
+ private: string;
52
+ public: string;
53
+ };
54
+ declare const MIN_BYTES = 1;
55
+ declare const MAX_BYTES = 256;
56
+ /** Longer than any recipe there is: `bytes:256:base64url` is 19. */
57
+ declare const MAX_RECIPE_LENGTH = 32;
58
+ declare const DEFAULT_RECIPE: Recipe;
59
+ declare const ENCODINGS: {
60
+ id: Encoding;
61
+ name: string;
62
+ }[];
63
+ declare const CURVES: readonly Curve[];
64
+ /** Strongest first, as a new key should be. */
65
+ declare const PAIRS: {
66
+ algorithm: PairAlgorithm;
67
+ curve: Curve;
68
+ }[];
69
+ declare const RECIPE_SYNTAX = "bytes:<1-256>[:base62|hex|base64|base64url], aes:<128|256>, ecdsa:<p-256|p-384|p-521> or ecdh:<curve>";
70
+ /**
71
+ * The recipe a text names, in any case: `bytes:32` is `bytes:32:base62`,
72
+ * `ECDSA:P-256` is `ecdsa:p-256`. Throws, saying what is wrong, for any
73
+ * other text.
74
+ */
75
+ declare function parseRecipe(text: string): Recipe;
76
+ /** What is wrong with a recipe's text, or null for a recipe. */
77
+ declare function recipeProblem(text: string): string | null;
78
+ /** A recipe as it is stored and shown: lowercase, every part named. */
79
+ declare function formatRecipe(recipe: Recipe): string;
80
+ /** A recipe in words, for a confirmation or a listing: "32 random bytes as 64 hex characters". */
81
+ declare function describeRecipe(recipe: Recipe): string;
82
+ /**
83
+ * How many characters carry `bytes` of entropy. Hex and base64 encode the
84
+ * bytes themselves; base62 draws whole characters, each worth log2(62) bits,
85
+ * so it takes as many as reach the same number of bits: 43 for 32 bytes.
86
+ * Base64 pads to a multiple of four; base64 URL leaves the padding off.
87
+ */
88
+ declare function encodedLength(encoding: Encoding, bytes: number): number;
89
+ type RandomBytes = (bytes: Uint8Array<ArrayBuffer>) => Uint8Array<ArrayBuffer>;
90
+ /** `length` characters of base62, each drawn uniformly by rejecting the bytes 248 to 255. */
91
+ declare function base62(length: number, random?: RandomBytes): string;
92
+ declare function randomValue(encoding: Encoding, bytes: number, random?: RandomBytes): string;
93
+ /** A value made by the recipe, with the platform's CSPRNG. */
94
+ declare function generate(recipe: Recipe): Promise<Generated>;
95
+ /**
96
+ * What a write of generated values sends, by key: each value with how it
97
+ * was made, for a regenerate the version it replaces, which the server
98
+ * holds it to, and who sees it, where the write says.
99
+ */
100
+ type GeneratedWrite = Record<string, {
101
+ value: string;
102
+ generated: Generation;
103
+ replaces?: string;
104
+ sensitivity?: 'secret' | 'sensitive';
105
+ }>;
106
+ /**
107
+ * A value made by the recipe for `key`, as a write sends it, and for a key
108
+ * pair its public key beside it, under `publicKey` or the name that follows
109
+ * from the private key's (`publicKeyName`). The two halves name each other.
110
+ */
111
+ declare function generateWrite(key: string, recipe: Recipe, publicKey?: string): Promise<GeneratedWrite>;
112
+ /**
113
+ * The next value of a key by the recipe its current one was made by, as a
114
+ * listing says it: a key pair's either half makes the pair again, whole,
115
+ * under the names its halves have now. Each key says the version it
116
+ * replaces, by the id `versionIdOf` gives as listed, and the server refuses
117
+ * the write (409) if any has changed since: renamed, archived, typed over
118
+ * or regenerated meanwhile. A regenerate addresses keys by name, and
119
+ * without that it could write a name that no longer holds the pair.
120
+ */
121
+ declare function regenerateWrite(key: string, generated: Generation, versionIdOf: (key: string) => string | null): Promise<GeneratedWrite>;
122
+ /**
123
+ * The name a key pair's public key gets beside its private key's:
124
+ * `JWT_PRIVATE_KEY` gives `JWT_PUBLIC_KEY`, any other name gains `_PUBLIC`.
125
+ */
126
+ declare function publicKeyName(privateName: string): string;
127
+ //#endregion
128
+ export { generate as C, randomValue as D, publicKeyName as E, recipeProblem as O, formatRecipe as S, parseRecipe as T, RandomBytes as _, ENCODINGS as a, describeRecipe as b, GeneratedWrite as c, MAX_BYTES as d, MAX_RECIPE_LENGTH as f, RECIPE_SYNTAX as g, PairAlgorithm as h, DEFAULT_RECIPE as i, regenerateWrite as k, Generation as l, PAIRS as m, CURVES as n, Encoding as o, MIN_BYTES as p, Curve as r, Generated as s, AesSize as t, KeyPairNames as u, Recipe as v, generateWrite as w, encodedLength as x, base62 as y };
package/dist/recipe.d.ts CHANGED
@@ -1,127 +1,2 @@
1
- //#region src/recipe.d.ts
2
- /**
3
- * How a secret's value is made, when a client makes it rather than a person
4
- * typing it: random strings, AES keys and EC key pairs, from Web Crypto
5
- * alone, the same in the browser and in the CLI.
6
- *
7
- * A recipe is short text, `bytes:32:hex`, which the CLI takes as
8
- * `--generate` and the server stores beside the version it made, so that
9
- * `coffre regenerate` and the page's Regenerate make the next one the same
10
- * way. The server checks a recipe's shape and never makes a value: a value
11
- * is made where it is sent from, and nothing here talks to the server.
12
- *
13
- * ```
14
- * bytes:<1-256>[:base62|hex|base64|base64url] random bytes, base62 unless named
15
- * aes:<128|256> an AES-GCM key: the raw key, base64
16
- * ecdsa:<p-256|p-384|p-521> a key pair: PKCS #8 private, SPKI public, base64
17
- * ecdh:<p-256|p-384|p-521>
18
- * ```
19
- */
20
- export type Encoding = 'base62' | 'hex' | 'base64' | 'base64url';
21
- export type AesSize = 128 | 256;
22
- export type Curve = 'P-256' | 'P-384' | 'P-521';
23
- export type PairAlgorithm = 'ECDSA' | 'ECDH';
24
- export type Recipe = {
25
- kind: 'random';
26
- encoding: Encoding;
27
- bytes: number;
28
- } | {
29
- kind: 'aes';
30
- size: AesSize;
31
- } | {
32
- kind: 'pair';
33
- algorithm: PairAlgorithm;
34
- curve: Curve;
35
- };
36
- /** A value, and for a key pair its public key, which is saved as a secret of its own. */
37
- export type Generated = {
38
- value: string;
39
- publicKey?: string;
40
- };
41
- /**
42
- * What a write says about how its value was made, and what a listing says
43
- * of a key's current value: its recipe, and for a key pair the two keys it
44
- * wrote together, which only a write of both at once makes.
45
- */
46
- export type Generation = {
47
- recipe: string;
48
- pair?: KeyPairNames;
49
- };
50
- export type KeyPairNames = {
51
- private: string;
52
- public: string;
53
- };
54
- export declare const MIN_BYTES = 1;
55
- export declare const MAX_BYTES = 256;
56
- /** Longer than any recipe there is: `bytes:256:base64url` is 19. */
57
- export declare const MAX_RECIPE_LENGTH = 32;
58
- export declare const DEFAULT_RECIPE: Recipe;
59
- export declare const ENCODINGS: {
60
- id: Encoding;
61
- name: string;
62
- }[];
63
- export declare const CURVES: readonly Curve[];
64
- /** Strongest first, as a new key should be. */
65
- export declare const PAIRS: {
66
- algorithm: PairAlgorithm;
67
- curve: Curve;
68
- }[];
69
- export declare const RECIPE_SYNTAX = "bytes:<1-256>[:base62|hex|base64|base64url], aes:<128|256>, ecdsa:<p-256|p-384|p-521> or ecdh:<curve>";
70
- /**
71
- * The recipe a text names, in any case: `bytes:32` is `bytes:32:base62`,
72
- * `ECDSA:P-256` is `ecdsa:p-256`. Throws, saying what is wrong, for any
73
- * other text.
74
- */
75
- export declare function parseRecipe(text: string): Recipe;
76
- /** What is wrong with a recipe's text, or null for a recipe. */
77
- export declare function recipeProblem(text: string): string | null;
78
- /** A recipe as it is stored and shown: lowercase, every part named. */
79
- export declare function formatRecipe(recipe: Recipe): string;
80
- /** A recipe in words, for a confirmation or a listing: "32 random bytes as 64 hex characters". */
81
- export declare function describeRecipe(recipe: Recipe): string;
82
- /**
83
- * How many characters carry `bytes` of entropy. Hex and base64 encode the
84
- * bytes themselves; base62 draws whole characters, each worth log2(62) bits,
85
- * so it takes as many as reach the same number of bits: 43 for 32 bytes.
86
- * Base64 pads to a multiple of four; base64 URL leaves the padding off.
87
- */
88
- export declare function encodedLength(encoding: Encoding, bytes: number): number;
89
- export type RandomBytes = (bytes: Uint8Array<ArrayBuffer>) => Uint8Array<ArrayBuffer>;
90
- /** `length` characters of base62, each drawn uniformly by rejecting the bytes 248 to 255. */
91
- export declare function base62(length: number, random?: RandomBytes): string;
92
- export declare function randomValue(encoding: Encoding, bytes: number, random?: RandomBytes): string;
93
- /** A value made by the recipe, with the platform's CSPRNG. */
94
- export declare function generate(recipe: Recipe): Promise<Generated>;
95
- /**
96
- * What a write of generated values sends, by key: each value with how it
97
- * was made, for a regenerate the version it replaces, which the server
98
- * holds it to, and who sees it, where the write says.
99
- */
100
- export type GeneratedWrite = Record<string, {
101
- value: string;
102
- generated: Generation;
103
- replaces?: string;
104
- sensitivity?: 'secret' | 'sensitive';
105
- }>;
106
- /**
107
- * A value made by the recipe for `key`, as a write sends it, and for a key
108
- * pair its public key beside it, under `publicKey` or the name that follows
109
- * from the private key's (`publicKeyName`). The two halves name each other.
110
- */
111
- export declare function generateWrite(key: string, recipe: Recipe, publicKey?: string): Promise<GeneratedWrite>;
112
- /**
113
- * The next value of a key by the recipe its current one was made by, as a
114
- * listing says it: a key pair's either half makes the pair again, whole,
115
- * under the names its halves have now. Each key says the version it
116
- * replaces, by the id `versionIdOf` gives as listed, and the server refuses
117
- * the write (409) if any has changed since: renamed, archived, typed over
118
- * or regenerated meanwhile. A regenerate addresses keys by name, and
119
- * without that it could write a name that no longer holds the pair.
120
- */
121
- export declare function regenerateWrite(key: string, generated: Generation, versionIdOf: (key: string) => string | null): Promise<GeneratedWrite>;
122
- /**
123
- * The name a key pair's public key gets beside its private key's:
124
- * `JWT_PRIVATE_KEY` gives `JWT_PUBLIC_KEY`, any other name gains `_PUBLIC`.
125
- */
126
- export declare function publicKeyName(privateName: string): string;
127
- //#endregion
1
+ import { C as generate, D as randomValue, E as publicKeyName, O as recipeProblem, S as formatRecipe, T as parseRecipe, _ as RandomBytes, a as ENCODINGS, b as describeRecipe, c as GeneratedWrite, d as MAX_BYTES, f as MAX_RECIPE_LENGTH, g as RECIPE_SYNTAX, h as PairAlgorithm, i as DEFAULT_RECIPE, k as regenerateWrite, l as Generation, m as PAIRS, n as CURVES, o as Encoding, p as MIN_BYTES, r as Curve, s as Generated, t as AesSize, u as KeyPairNames, v as Recipe, w as generateWrite, x as encodedLength, y as base62 } from "./recipe-BgJpmJum.js";
2
+ export { AesSize, CURVES, Curve, DEFAULT_RECIPE, ENCODINGS, Encoding, Generated, GeneratedWrite, Generation, KeyPairNames, MAX_BYTES, MAX_RECIPE_LENGTH, MIN_BYTES, PAIRS, PairAlgorithm, RECIPE_SYNTAX, RandomBytes, Recipe, base62, describeRecipe, encodedLength, formatRecipe, generate, generateWrite, parseRecipe, publicKeyName, randomValue, recipeProblem, regenerateWrite };
@@ -17,6 +17,11 @@
17
17
  * docs/design/credential-proxy.md, section 2): a forged owner or sensitivity
18
18
  * column fails to open, rather than granting. The value's own ciphertext
19
19
  * binds the ids alone, so a version made sensitive keeps its ciphertext.
20
+ *
21
+ * From envelope version 2 the wrap names the version's number too,
22
+ * `version`: a version's row copied over another of the same secret, an old
23
+ * value put back as the current one, does not open either. And whether the
24
+ * value is plain, `plain`, as it names whether it is sensitive.
20
25
  */
21
26
  type SecretContext = {
22
27
  projectId: string;
@@ -26,13 +31,22 @@ type SecretContext = {
26
31
  owner?: string;
27
32
  /** A sensitive value's: never handed back to a person (`sensitive` in @coffre/core/vault). Absent otherwise, never false. */
28
33
  sensitive?: true;
34
+ /**
35
+ * A plain value's, one marked not secret, which whoever lists its
36
+ * environment sees: never sensitive too. From envelope version 2, so that
37
+ * a secret relabelled plain, to be handed to whoever reads plain values,
38
+ * does not open. Absent otherwise, never false.
39
+ */
40
+ plain?: true;
41
+ /** The version's number among its secret's, from 1. Absent in the wrap of a value written before envelope version 2. */
42
+ version?: number;
29
43
  };
30
44
  /**
31
45
  * Version prefix for the AAD encoding. If the encoding ever changes, this
32
46
  * changes with it, and old ciphertexts keep decrypting under the old rule.
33
47
  */
34
48
  declare const AAD_VERSION = "coffre.aad.v1";
35
- /** Throw unless every field is a lowercase UUID, an owner a lowercase SHA-256, and `sensitive` true if there. */
49
+ /** Throw unless every field is a lowercase UUID, an owner a lowercase SHA-256, `sensitive` and `plain` true if there and never both, and a version a number from 1. */
36
50
  declare function checkContext(ctx: SecretContext): void;
37
51
  /**
38
52
  * A personal config's owner as its values' context binds them: the SHA-256
@@ -83,7 +97,8 @@ type KeyOperation = {
83
97
  * context (`aws-kms.ts`). Scaleway's Audit Trail does not log Key Manager
84
98
  * Decrypt at all, which is why AWS came first.
85
99
  *
86
- * `unwrap` throws `KekUnavailableError` when the service cannot answer, and
100
+ * `unwrap` throws `KekUnavailableError` when the service cannot answer,
101
+ * `KekRefusedError` when it refuses coffre itself for good, and
87
102
  * `KekBadClaimError` when the wrapped DEK does not open under `ctx`. Other
88
103
  * errors are unexpected faults; the vault records them and fails the call.
89
104
  */
@@ -98,8 +113,9 @@ interface KekProvider {
98
113
  declare const DEK_BYTES = 32;
99
114
  /**
100
115
  * The key service could not answer: it is down, throttling past the
101
- * retries, or refusing coffre's own credentials. Nothing is known about the
102
- * wrapped key, so the vault fails the call instead of refusing it.
116
+ * retries, or out of time; or it refuses coffre itself (`KekRefusedError`).
117
+ * Nothing is known about the wrapped key, so the vault fails the call
118
+ * instead of refusing it.
103
119
  */
104
120
  declare class KekUnavailableError extends Error {
105
121
  readonly name: string;
@@ -111,6 +127,15 @@ declare class KekCancelledError extends KekUnavailableError {
111
127
  readonly name = "KekCancelledError";
112
128
  constructor(uncertain?: boolean);
113
129
  }
130
+ /**
131
+ * The key service answered, and said no for good: it refuses coffre's
132
+ * credentials, the key is disabled or gone, or it opened under another key.
133
+ * Asked again, it says the same: the vault fails the call as for any other
134
+ * `KekUnavailableError`, but whoever runs coffre must act, and nobody's retry helps.
135
+ */
136
+ declare class KekRefusedError extends KekUnavailableError {
137
+ readonly name = "KekRefusedError";
138
+ }
114
139
  /** The ciphertext does not open under the claimed key and context. */
115
140
  declare class KekBadClaimError extends Error {
116
141
  readonly name = "KekBadClaimError";
@@ -140,4 +165,4 @@ declare class KekRegistry {
140
165
  unwrap(wrapped: WrappedDek, ctx: SecretContext, operation?: KeyOperation): Promise<Buffer>;
141
166
  }
142
167
  //#endregion
143
- export { KekProvider as a, WrappedDek as c, checkContext as d, encodeAad as f, KekCancelledError as i, AAD_VERSION as l, DEK_BYTES as n, KekUnavailableError as o, ownerKey as p, KekBadClaimError as r, KeyOperation as s, KekRegistry as t, SecretContext as u };
168
+ export { KekProvider as a, KeyOperation as c, SecretContext as d, checkContext as f, KekCancelledError as i, WrappedDek as l, ownerKey as m, DEK_BYTES as n, KekRefusedError as o, encodeAad as p, KekBadClaimError as r, KekUnavailableError as s, KekRegistry as t, AAD_VERSION as u };
package/dist/schemas.d.ts CHANGED
@@ -23,16 +23,10 @@ export declare const TOMBSTONE = "~";
23
23
  export declare function isTombstone(slug: string): boolean;
24
24
  /** The slug a place deleted on `day` keeps: the `n`th that day is `market~deleted-2026-10-05-<n>`. */
25
25
  export declare function tombstoneOf(slug: string, day: Date, n?: number): string;
26
- /**
27
- * The slug an environment deleted with its project keeps, with 0.15's log:
28
- * `dev~deleted`, undated. Its project is deleted once, so within it no other
29
- * environment holds it, and an environment deleted alone holds a dated one.
30
- * The project's tombstone dates both; its old path still names it,
31
- * `market~deleted-2026-10-05/dev` (`resolvePath`'s `tombstones`).
32
- */
33
- export declare function deletedWithProject(slug: string): string;
26
+ /** A tombstone's slug, as `tombstoneOf` writes it: the name a deleted place's log is still read by. */
27
+ export declare const tombstoneSlug: z.ZodString;
34
28
  export declare const displayName: z.ZodString;
35
- /** A folder: 1 to 64 characters, no `/`, no control character, no space at either end (the tables check it too). */
29
+ /** A folder: 1 to 64 characters of well-formed Unicode, no `/`, no control character, no space at either end (the tables and the vault check it too). */
36
30
  export declare const folderName: z.ZodString;
37
31
  export declare const secretKey: z.ZodString;
38
32
  /**
@@ -40,6 +34,14 @@ export declare const secretKey: z.ZodString;
40
34
  * as `service:<name>`, though the API, the vault and the log keep the
41
35
  * `token:<name>` their signed entries hold.
42
36
  */
37
+ /** A service account by its member id, `token:<name>`, as the vault takes one (`principals_id_check`). */
38
+ export declare const SERVICE_MEMBER: RegExp;
39
+ /** A service account's member id as the vault's contract takes one: `SERVICE_MEMBER`, in 256 characters of well-formed Unicode with no NUL. */
40
+ export declare function isServiceMember(value: unknown): value is string;
41
+ /** A row's id as the vault draws and takes one: a UUID, in lowercase. */
42
+ export declare const ROW_ID: RegExp;
43
+ /** A row's id as a request may spell it: any UUID, in the lowercase the vault takes. */
44
+ export declare const rowId: z.ZodPipe<z.ZodUUID, z.ZodTransform<string, string>>;
43
45
  export declare function shownMember(member: string): string;
44
46
  export declare const principalType: z.ZodEnum<{
45
47
  user: "user";
@@ -47,11 +49,11 @@ export declare const principalType: z.ZodEnum<{
47
49
  }>;
48
50
  export declare const principalId: z.ZodString;
49
51
  export declare const instanceRole: z.ZodEnum<{
50
- member: "member";
51
- auditor: "auditor";
52
52
  developer: "developer";
53
- admin: "admin";
53
+ auditor: "auditor";
54
54
  owner: "owner";
55
+ member: "member";
56
+ admin: "admin";
55
57
  }>;
56
58
  /** A project role's id: one coffre ships, or one an Owner made (`ROLE_ID`). Which the instance defines, its policy says. */
57
59
  export declare const roleId: z.ZodString;
package/dist/schemas.js CHANGED
@@ -1,4 +1,4 @@
1
- import { u as INSTANCE_ROLE_NAMES, v as ROLE_ID } from "./access-CgQTlUMz.js";
1
+ import { c as INSTANCE_ROLE_NAMES, h as ROLE_ID } from "./access-CF8UG59J.js";
2
2
  import { PROJECT_PAGES } from "./pages.js";
3
3
  import { z } from "zod";
4
4
  //#region src/schemas.ts
@@ -32,25 +32,27 @@ function tombstoneOf(slug, day, n = 1) {
32
32
  const base = `${slug}~deleted-${day.toISOString().slice(0, 10)}`;
33
33
  return n === 1 ? base : `${base}-${n}`;
34
34
  }
35
- /**
36
- * The slug an environment deleted with its project keeps, with 0.15's log:
37
- * `dev~deleted`, undated. Its project is deleted once, so within it no other
38
- * environment holds it, and an environment deleted alone holds a dated one.
39
- * The project's tombstone dates both; its old path still names it,
40
- * `market~deleted-2026-10-05/dev` (`resolvePath`'s `tombstones`).
41
- */
42
- function deletedWithProject(slug) {
43
- return `${slug}~deleted`;
44
- }
35
+ /** A tombstone's slug, as `tombstoneOf` writes it: the name a deleted place's log is still read by. */
36
+ const tombstoneSlug = z.string().regex(/^[a-z0-9][a-z0-9-]{0,62}~deleted-\d{4}-\d{2}-\d{2}(?:-[1-9]\d*)?$/);
45
37
  const displayName = z.string().trim().min(1).max(120);
46
- /** A folder: 1 to 64 characters, no `/`, no control character, no space at either end (the tables check it too). */
47
- const folderName = z.string().min(1).max(64).refine((name) => name === name.trim(), "a folder name cannot start or end with a space").refine((name) => !/[/\p{Cc}]/u.test(name), "a folder name cannot hold \"/\" or a control character");
38
+ /** A folder: 1 to 64 characters of well-formed Unicode, no `/`, no control character, no space at either end (the tables and the vault check it too). */
39
+ const folderName = z.string().min(1).max(64).refine((name) => name === name.trim(), "a folder name cannot start or end with a space").refine((name) => !/[/\p{Cc}\p{Cs}]/u.test(name), "a folder name cannot hold \"/\", a control character or half of a surrogate pair");
48
40
  const secretKey = z.string().regex(/^[A-Za-z_][A-Za-z0-9_]{0,127}$/);
49
41
  /**
50
42
  * A member as people read it, in a message or on a page: a service account
51
43
  * as `service:<name>`, though the API, the vault and the log keep the
52
44
  * `token:<name>` their signed entries hold.
53
45
  */
46
+ /** A service account by its member id, `token:<name>`, as the vault takes one (`principals_id_check`). */
47
+ const SERVICE_MEMBER = /^token:[^\s:]\S*$/;
48
+ /** A service account's member id as the vault's contract takes one: `SERVICE_MEMBER`, in 256 characters of well-formed Unicode with no NUL. */
49
+ function isServiceMember(value) {
50
+ return typeof value === "string" && value.length <= 256 && !/[\0\p{Cs}]/u.test(value) && SERVICE_MEMBER.test(value);
51
+ }
52
+ /** A row's id as the vault draws and takes one: a UUID, in lowercase. */
53
+ const ROW_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
54
+ /** A row's id as a request may spell it: any UUID, in the lowercase the vault takes. */
55
+ const rowId = z.uuid().transform((id) => id.toLowerCase());
54
56
  function shownMember(member) {
55
57
  return member.startsWith("token:") ? `service:${member.slice(6)}` : member;
56
58
  }
@@ -73,4 +75,4 @@ const scopeInput = z.object({
73
75
  const grantId = z.string().uuid();
74
76
  const emailAddress = z.string().email().max(320);
75
77
  //#endregion
76
- export { PERSONAL_SUFFIX, TOMBSTONE, deletedWithProject, displayName, emailAddress, environmentPath, environmentSlug, folderName, grantId, instanceRole, isTombstone, personalOf, principalId, principalType, roleId, scopeFilter, scopeInput, secretKey, shownMember, slug, tombstoneOf };
78
+ export { PERSONAL_SUFFIX, ROW_ID, SERVICE_MEMBER, TOMBSTONE, displayName, emailAddress, environmentPath, environmentSlug, folderName, grantId, instanceRole, isServiceMember, isTombstone, personalOf, principalId, principalType, roleId, rowId, scopeFilter, scopeInput, secretKey, shownMember, slug, tombstoneOf, tombstoneSlug };
@@ -9,13 +9,15 @@ const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/
9
9
  function assertUuid(value, field) {
10
10
  if (typeof value !== "string" || !UUID_RE.test(value)) throw new Error(`context.${field} must be a lowercase UUID, got: ${String(value)}`);
11
11
  }
12
- /** Throw unless every field is a lowercase UUID, an owner a lowercase SHA-256, and `sensitive` true if there. */
12
+ /** Throw unless every field is a lowercase UUID, an owner a lowercase SHA-256, `sensitive` and `plain` true if there and never both, and a version a number from 1. */
13
13
  function checkContext(ctx) {
14
14
  assertUuid(ctx.projectId, "projectId");
15
15
  assertUuid(ctx.environmentId, "environmentId");
16
16
  assertUuid(ctx.secretId, "secretId");
17
17
  if (ctx.owner !== void 0 && (typeof ctx.owner !== "string" || !OWNER_RE.test(ctx.owner))) throw new Error(`context.owner must be a lowercase SHA-256, got: ${String(ctx.owner)}`);
18
18
  if (ctx.sensitive !== void 0 && ctx.sensitive !== true) throw new Error(`context.sensitive is true or absent, got: ${String(ctx.sensitive)}`);
19
+ if (ctx.plain !== void 0 && (ctx.plain !== true || ctx.sensitive === true)) throw new Error(`context.plain is true or absent, and never with sensitive, got: ${String(ctx.plain)}`);
20
+ if (ctx.version !== void 0 && !(Number.isSafeInteger(ctx.version) && ctx.version > 0)) throw new Error(`context.version is a version's number, from 1, got: ${String(ctx.version)}`);
19
21
  }
20
22
  const OWNER_RE = /^[0-9a-f]{64}$/;
21
23
  /**
@@ -35,7 +37,7 @@ function ownerKey(member) {
35
37
  */
36
38
  function encodeAad(ctx) {
37
39
  checkContext(ctx);
38
- return Buffer.from(`${AAD_VERSION}|${ctx.projectId}|${ctx.environmentId}|${ctx.secretId}${ctx.owner === void 0 ? "" : `|owner:${ctx.owner}`}${ctx.sensitive === true ? "|sensitive" : ""}`, "utf8");
40
+ return Buffer.from(`${AAD_VERSION}|${ctx.projectId}|${ctx.environmentId}|${ctx.secretId}${ctx.owner === void 0 ? "" : `|owner:${ctx.owner}`}${ctx.sensitive === true ? "|sensitive" : ""}${ctx.plain === true ? "|plain" : ""}${ctx.version === void 0 ? "" : `|version:${ctx.version}`}`, "utf8");
39
41
  }
40
42
  //#endregion
41
43
  //#region src/kek/types.ts
@@ -43,8 +45,9 @@ function encodeAad(ctx) {
43
45
  const DEK_BYTES = 32;
44
46
  /**
45
47
  * The key service could not answer: it is down, throttling past the
46
- * retries, or refusing coffre's own credentials. Nothing is known about the
47
- * wrapped key, so the vault fails the call instead of refusing it.
48
+ * retries, or out of time; or it refuses coffre itself (`KekRefusedError`).
49
+ * Nothing is known about the wrapped key, so the vault fails the call
50
+ * instead of refusing it.
48
51
  */
49
52
  var KekUnavailableError = class extends Error {
50
53
  name = "KekUnavailableError";
@@ -61,9 +64,18 @@ var KekCancelledError = class extends KekUnavailableError {
61
64
  super("key operation was cancelled", uncertain);
62
65
  }
63
66
  };
67
+ /**
68
+ * The key service answered, and said no for good: it refuses coffre's
69
+ * credentials, the key is disabled or gone, or it opened under another key.
70
+ * Asked again, it says the same: the vault fails the call as for any other
71
+ * `KekUnavailableError`, but whoever runs coffre must act, and nobody's retry helps.
72
+ */
73
+ var KekRefusedError = class extends KekUnavailableError {
74
+ name = "KekRefusedError";
75
+ };
64
76
  /** The ciphertext does not open under the claimed key and context. */
65
77
  var KekBadClaimError = class extends Error {
66
78
  name = "KekBadClaimError";
67
79
  };
68
80
  //#endregion
69
- export { AAD_VERSION as a, ownerKey as c, KekUnavailableError as i, KekBadClaimError as n, checkContext as o, KekCancelledError as r, encodeAad as s, DEK_BYTES as t };
81
+ export { KekUnavailableError as a, encodeAad as c, KekRefusedError as i, ownerKey as l, KekBadClaimError as n, AAD_VERSION as o, KekCancelledError as r, checkContext as s, DEK_BYTES as t };