@cloudhal/comments 0.0.0-stage → 0.1.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 (46) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +86 -2
  3. package/dist/src/client/comments.browser.js +245 -0
  4. package/dist/src/client/index.d.ts +19 -0
  5. package/dist/src/client/index.js +39 -0
  6. package/dist/src/client/solver.browser.js +118 -0
  7. package/dist/src/crypto.d.ts +64 -0
  8. package/dist/src/crypto.js +170 -0
  9. package/dist/src/errors.d.ts +38 -0
  10. package/dist/src/errors.js +61 -0
  11. package/dist/src/fixtures/comment-text.json +335 -0
  12. package/dist/src/hashes.d.ts +70 -0
  13. package/dist/src/hashes.js +191 -0
  14. package/dist/src/index.d.ts +24 -0
  15. package/dist/src/index.js +24 -0
  16. package/dist/src/limits.d.ts +73 -0
  17. package/dist/src/limits.js +227 -0
  18. package/dist/src/linkify.d.ts +53 -0
  19. package/dist/src/linkify.js +142 -0
  20. package/dist/src/model.d.ts +287 -0
  21. package/dist/src/model.js +341 -0
  22. package/dist/src/normalize.d.ts +17 -0
  23. package/dist/src/normalize.js +125 -0
  24. package/dist/src/pipeline.d.ts +176 -0
  25. package/dist/src/pipeline.js +898 -0
  26. package/dist/src/pow.d.ts +86 -0
  27. package/dist/src/pow.js +239 -0
  28. package/dist/src/purge.d.ts +87 -0
  29. package/dist/src/purge.js +186 -0
  30. package/dist/src/retention.d.ts +32 -0
  31. package/dist/src/retention.js +106 -0
  32. package/dist/src/rules.d.ts +68 -0
  33. package/dist/src/rules.js +218 -0
  34. package/dist/src/settings.d.ts +108 -0
  35. package/dist/src/settings.js +347 -0
  36. package/dist/src/sql/index.d.ts +7 -0
  37. package/dist/src/sql/index.js +29 -0
  38. package/dist/src/sql/portability.d.ts +113 -0
  39. package/dist/src/sql/portability.js +514 -0
  40. package/dist/src/sql/rows.d.ts +54 -0
  41. package/dist/src/sql/rows.js +145 -0
  42. package/dist/src/sql/store.d.ts +312 -0
  43. package/dist/src/sql/store.js +2111 -0
  44. package/dist/src/thread.d.ts +35 -0
  45. package/dist/src/thread.js +64 -0
  46. package/package.json +61 -3
@@ -0,0 +1,335 @@
1
+ {
2
+ "description": "Shared fixture for the comment link rule (RFC-0007 §6.4, §8.1, §14): parseCommentText(text) must equal paragraphs. Used by @cloudhal/comments and, once reconciled, by @cloudhal/ui's comment blocks.",
3
+ "cases": [
4
+ {
5
+ "name": "paragraphs and lines",
6
+ "text": "First line\r\nsecond line\n\n\n\nNext paragraph",
7
+ "paragraphs": [
8
+ [
9
+ [
10
+ {
11
+ "kind": "text",
12
+ "text": "First line"
13
+ }
14
+ ],
15
+ [
16
+ {
17
+ "kind": "text",
18
+ "text": "second line"
19
+ }
20
+ ]
21
+ ],
22
+ [
23
+ [
24
+ {
25
+ "kind": "text",
26
+ "text": "Next paragraph"
27
+ }
28
+ ]
29
+ ]
30
+ ]
31
+ },
32
+ {
33
+ "name": "blank line with spaces splits paragraphs",
34
+ "text": "one\n \t\ntwo",
35
+ "paragraphs": [
36
+ [
37
+ [
38
+ {
39
+ "kind": "text",
40
+ "text": "one"
41
+ }
42
+ ]
43
+ ],
44
+ [
45
+ [
46
+ {
47
+ "kind": "text",
48
+ "text": "two"
49
+ }
50
+ ]
51
+ ]
52
+ ]
53
+ },
54
+ {
55
+ "name": "empty",
56
+ "text": " \n\n ",
57
+ "paragraphs": []
58
+ },
59
+ {
60
+ "name": "https with query",
61
+ "text": "https://example.com/a?b=1",
62
+ "paragraphs": [
63
+ [
64
+ [
65
+ {
66
+ "kind": "link",
67
+ "text": "https://example.com/a?b=1",
68
+ "href": "https://example.com/a?b=1"
69
+ }
70
+ ]
71
+ ]
72
+ ]
73
+ },
74
+ {
75
+ "name": "http, www and javascript stay text",
76
+ "text": "http://example.com www.example.com javascript:alert(1)",
77
+ "paragraphs": [
78
+ [
79
+ [
80
+ {
81
+ "kind": "text",
82
+ "text": "http://example.com www.example.com javascript:alert(1)"
83
+ }
84
+ ]
85
+ ]
86
+ ]
87
+ },
88
+ {
89
+ "name": "credentials stay text",
90
+ "text": "https://bank.example@evil.example/login",
91
+ "paragraphs": [
92
+ [
93
+ [
94
+ {
95
+ "kind": "text",
96
+ "text": "https://bank.example@evil.example/login"
97
+ }
98
+ ]
99
+ ]
100
+ ]
101
+ },
102
+ {
103
+ "name": "dotless host stays text",
104
+ "text": "https://localhost/x",
105
+ "paragraphs": [
106
+ [
107
+ [
108
+ {
109
+ "kind": "text",
110
+ "text": "https://localhost/x"
111
+ }
112
+ ]
113
+ ]
114
+ ]
115
+ },
116
+ {
117
+ "name": "trailing-dot host stays text",
118
+ "text": "https://example.com./x",
119
+ "paragraphs": [
120
+ [
121
+ [
122
+ {
123
+ "kind": "text",
124
+ "text": "https://example.com./x"
125
+ }
126
+ ]
127
+ ]
128
+ ]
129
+ },
130
+ {
131
+ "name": "glued to a word",
132
+ "text": "foohttps://example.com",
133
+ "paragraphs": [
134
+ [
135
+ [
136
+ {
137
+ "kind": "text",
138
+ "text": "foohttps://example.com"
139
+ }
140
+ ]
141
+ ]
142
+ ]
143
+ },
144
+ {
145
+ "name": "glued to an underscore",
146
+ "text": "_https://example.com",
147
+ "paragraphs": [
148
+ [
149
+ [
150
+ {
151
+ "kind": "text",
152
+ "text": "_https://example.com"
153
+ }
154
+ ]
155
+ ]
156
+ ]
157
+ },
158
+ {
159
+ "name": "punctuation and brackets",
160
+ "text": "See https://example.com/x, or (https://en.wikipedia.org/wiki/Ferry_(boat)) or http://old.example and www.example.com",
161
+ "paragraphs": [
162
+ [
163
+ [
164
+ {
165
+ "kind": "text",
166
+ "text": "See "
167
+ },
168
+ {
169
+ "kind": "link",
170
+ "text": "https://example.com/x",
171
+ "href": "https://example.com/x"
172
+ },
173
+ {
174
+ "kind": "text",
175
+ "text": ", or ("
176
+ },
177
+ {
178
+ "kind": "link",
179
+ "text": "https://en.wikipedia.org/wiki/Ferry_(boat)",
180
+ "href": "https://en.wikipedia.org/wiki/Ferry_(boat)"
181
+ },
182
+ {
183
+ "kind": "text",
184
+ "text": ") or http://old.example and www.example.com"
185
+ }
186
+ ]
187
+ ]
188
+ ]
189
+ },
190
+ {
191
+ "name": "trailing quote marks",
192
+ "text": "“https://example.com/q” and «https://example.org»",
193
+ "paragraphs": [
194
+ [
195
+ [
196
+ {
197
+ "kind": "text",
198
+ "text": "“"
199
+ },
200
+ {
201
+ "kind": "link",
202
+ "text": "https://example.com/q",
203
+ "href": "https://example.com/q"
204
+ },
205
+ {
206
+ "kind": "text",
207
+ "text": "” and «"
208
+ },
209
+ {
210
+ "kind": "link",
211
+ "text": "https://example.org",
212
+ "href": "https://example.org/"
213
+ },
214
+ {
215
+ "kind": "text",
216
+ "text": "»"
217
+ }
218
+ ]
219
+ ]
220
+ ]
221
+ },
222
+ {
223
+ "name": "https inside an http candidate stays text",
224
+ "text": "http://a.example/?u=https://b.example",
225
+ "paragraphs": [
226
+ [
227
+ [
228
+ {
229
+ "kind": "text",
230
+ "text": "http://a.example/?u=https://b.example"
231
+ }
232
+ ]
233
+ ]
234
+ ]
235
+ },
236
+ {
237
+ "name": "markup stays text",
238
+ "text": "<script>alert(1)</script> <a href=\"https://x.example\">x</a>",
239
+ "paragraphs": [
240
+ [
241
+ [
242
+ {
243
+ "kind": "text",
244
+ "text": "<script>alert(1)</script> <a href=\""
245
+ },
246
+ {
247
+ "kind": "link",
248
+ "text": "https://x.example",
249
+ "href": "https://x.example/"
250
+ },
251
+ {
252
+ "kind": "text",
253
+ "text": "\">x</a>"
254
+ }
255
+ ]
256
+ ]
257
+ ]
258
+ },
259
+ {
260
+ "name": "quote ends the candidate",
261
+ "text": "https://a.example/\"onmouseover=alert(1)",
262
+ "paragraphs": [
263
+ [
264
+ [
265
+ {
266
+ "kind": "link",
267
+ "text": "https://a.example/",
268
+ "href": "https://a.example/"
269
+ },
270
+ {
271
+ "kind": "text",
272
+ "text": "\"onmouseover=alert(1)"
273
+ }
274
+ ]
275
+ ]
276
+ ]
277
+ },
278
+ {
279
+ "name": "upper-case scheme",
280
+ "text": "HTTPS://Example.COM/Path",
281
+ "paragraphs": [
282
+ [
283
+ [
284
+ {
285
+ "kind": "link",
286
+ "text": "HTTPS://Example.COM/Path",
287
+ "href": "https://example.com/Path"
288
+ }
289
+ ]
290
+ ]
291
+ ]
292
+ },
293
+ {
294
+ "name": "international host in punycode",
295
+ "text": "https://bücher.example/kitap",
296
+ "paragraphs": [
297
+ [
298
+ [
299
+ {
300
+ "kind": "link",
301
+ "text": "https://bücher.example/kitap",
302
+ "href": "https://xn--bcher-kva.example/kitap"
303
+ }
304
+ ]
305
+ ]
306
+ ]
307
+ },
308
+ {
309
+ "name": "two links on two lines",
310
+ "text": "https://a.example\nhttps://b.example.",
311
+ "paragraphs": [
312
+ [
313
+ [
314
+ {
315
+ "kind": "link",
316
+ "text": "https://a.example",
317
+ "href": "https://a.example/"
318
+ }
319
+ ],
320
+ [
321
+ {
322
+ "kind": "link",
323
+ "text": "https://b.example",
324
+ "href": "https://b.example/"
325
+ },
326
+ {
327
+ "kind": "text",
328
+ "text": "."
329
+ }
330
+ ]
331
+ ]
332
+ ]
333
+ }
334
+ ]
335
+ }
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Hashes and ids (RFC-0007 §4.4, §9.2, §10.3):
3
+ *
4
+ * - `ipHmac` — first 16 bytes of HMAC-SHA-256(salt_month, siteId ‖ "\n" ‖ network), hex. IPv6
5
+ * addresses are cut to their /64 first and IPv4-mapped addresses read as IPv4, so a client
6
+ * cannot dodge limits by rotating within its own prefix. The salt is random per UTC month and
7
+ * deleted when two months old; without it the hash cannot be recomputed.
8
+ * - `emailHmac` — HMAC-SHA-256(K_email-hmac, lower-cased address), hex: lookups and bans.
9
+ * - `sealEmail` — AES-GCM under K_email with the site id bound as additional data.
10
+ * - `commentRecordHash` — SHA-256 of the canonical `Comment` record (the `hash` column that guards
11
+ * follow-up statements, AGENTS.md rule 4).
12
+ * - `commentStateHash` — the `cm1:` binding of an approval to comment state: SHA-256 over the
13
+ * sorted lines `c <commentId> <rev> <status>` and `t <nodeId> <rev|0> <effective state>`.
14
+ */
15
+ import type { Comment } from "@cloudhal/core-contracts";
16
+ import { type CommentKeys, type Sealed } from "./crypto.js";
17
+ import type { CommentStatus, ThreadState } from "./model.js";
18
+ /** Deterministic JSON: object keys sorted recursively, undefined dropped. */
19
+ export declare function canonicalJson(value: unknown): string;
20
+ export declare const commentRecordHash: (comment: Comment) => Promise<string>;
21
+ /**
22
+ * The network a client is limited and banned by: an IPv4 address as is, an IPv6 address as its
23
+ * /64 (`2001:0db8:0001:0002::/64`), an IPv4-mapped IPv6 address as its IPv4. Anything else is used
24
+ * lower-cased as given (the runtime vouches for the address; it is never a client header).
25
+ */
26
+ export declare function clientNetwork(address: string): string;
27
+ /** 32 random bytes as 64 lower-case hex characters (a fresh monthly salt). */
28
+ export declare function randomSalt(): string;
29
+ export declare function ipHmac(salt: string, siteId: string, address: string): Promise<string>;
30
+ /**
31
+ * The `COMMENTS_RL` Rate Limiting binding's key for a client: an HMAC of its network (IPv6 /64)
32
+ * under the key derived for that purpose (`cloudhal/comments/rl/v1`), so it is the same in every
33
+ * isolate and never the raw deployment secret (threat-model review of 2026-10-12, item 9).
34
+ */
35
+ export declare function rateLimitKey(keys: CommentKeys, address: string): Promise<string>;
36
+ /** Placeholder address when the runtime vouches for none (a separate, stricter bucket, §6.5). */
37
+ export declare const UNKNOWN_CLIENT = "unknown";
38
+ /** True for an IPv4 or IPv6 address (what the runtime vouches for); false for anything else. */
39
+ export declare function isClientAddress(address: string): boolean;
40
+ export declare function emailHmac(keys: CommentKeys, email: string): Promise<string>;
41
+ export declare const sealEmail: (keys: CommentKeys, siteId: string, email: string) => Promise<Sealed>;
42
+ export declare const openEmail: (keys: CommentKeys, siteId: string, sealed: Sealed) => Promise<string>;
43
+ export declare const sealSecret: (keys: CommentKeys, siteId: string, name: string, value: string) => Promise<Sealed>;
44
+ export declare const openSecret: (keys: CommentKeys, siteId: string, name: string, sealed: Sealed) => Promise<string>;
45
+ export interface StateHashInput {
46
+ readonly comments: readonly {
47
+ readonly id: string;
48
+ readonly rev: number;
49
+ readonly status: CommentStatus | "missing";
50
+ }[];
51
+ readonly threads: readonly {
52
+ readonly nodeId: string;
53
+ readonly rev: number;
54
+ readonly state: ThreadState;
55
+ }[];
56
+ }
57
+ export declare const STATE_HASH_PREFIX = "cm1:";
58
+ /** The `cm1:` binding of an approval to the comments and threads it names (§10.3). */
59
+ export declare function commentStateHash(input: StateHashInput): Promise<string>;
60
+ /** A prefixed random id (`cmt_…`, `cmr_…`), Crockford base32 like core-ts `newId`. */
61
+ export declare function newCommentsId(prefix: string, length?: number): string;
62
+ export declare const ID_PREFIX: {
63
+ readonly comment: "cmt";
64
+ readonly commenter: "cmr";
65
+ readonly report: "crp";
66
+ readonly ban: "cban";
67
+ readonly op: "op";
68
+ };
69
+ /** True for a base64url string that decodes (used to validate stored ciphertext columns). */
70
+ export declare const isBase64Url: (s: string) => boolean;
@@ -0,0 +1,191 @@
1
+ /**
2
+ * Hashes and ids (RFC-0007 §4.4, §9.2, §10.3):
3
+ *
4
+ * - `ipHmac` — first 16 bytes of HMAC-SHA-256(salt_month, siteId ‖ "\n" ‖ network), hex. IPv6
5
+ * addresses are cut to their /64 first and IPv4-mapped addresses read as IPv4, so a client
6
+ * cannot dodge limits by rotating within its own prefix. The salt is random per UTC month and
7
+ * deleted when two months old; without it the hash cannot be recomputed.
8
+ * - `emailHmac` — HMAC-SHA-256(K_email-hmac, lower-cased address), hex: lookups and bans.
9
+ * - `sealEmail` — AES-GCM under K_email with the site id bound as additional data.
10
+ * - `commentRecordHash` — SHA-256 of the canonical `Comment` record (the `hash` column that guards
11
+ * follow-up statements, AGENTS.md rule 4).
12
+ * - `commentStateHash` — the `cm1:` binding of an approval to comment state: SHA-256 over the
13
+ * sorted lines `c <commentId> <rev> <status>` and `t <nodeId> <rev|0> <effective state>`.
14
+ */
15
+
16
+ import {
17
+
18
+ fromBase64Url,
19
+ hmac,
20
+ hmacRaw,
21
+ open,
22
+
23
+ seal,
24
+ sha256Hex,
25
+ toHex,
26
+ utf8,
27
+ } from "./crypto.js";
28
+
29
+
30
+ /** Deterministic JSON: object keys sorted recursively, undefined dropped. */
31
+ export function canonicalJson(value ) {
32
+ const sort = (v ) => {
33
+ if (Array.isArray(v)) return v.map(sort);
34
+ if (v !== null && typeof v === "object") {
35
+ const out = {};
36
+ for (const k of Object.keys(v).sort()) {
37
+ const x = (v )[k];
38
+ if (x !== undefined) out[k] = sort(x);
39
+ }
40
+ return out;
41
+ }
42
+ return v;
43
+ };
44
+ return JSON.stringify(sort(value));
45
+ }
46
+
47
+ export const commentRecordHash = (comment ) =>
48
+ sha256Hex(canonicalJson(comment));
49
+
50
+ const IPV4 = /^(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}$/;
51
+
52
+ /** Expands an IPv6 address to 8 groups of 4 hex digits; `undefined` when it is not one. */
53
+ function expandIpv6(address ) {
54
+ let a = address.toLowerCase();
55
+ const zone = a.indexOf("%");
56
+ if (zone >= 0) a = a.slice(0, zone);
57
+ if (a.startsWith("[") && a.endsWith("]")) a = a.slice(1, -1);
58
+ // embedded IPv4 tail
59
+ const lastColon = a.lastIndexOf(":");
60
+ const tail = a.slice(lastColon + 1);
61
+ if (tail.includes(".")) {
62
+ if (!IPV4.test(tail)) return undefined;
63
+ const [p, q, r, s] = tail.split(".").map(Number) ;
64
+ a = `${a.slice(0, lastColon + 1)}${((p << 8) | q).toString(16)}:${((r << 8) | s).toString(16)}`;
65
+ }
66
+ const halves = a.split("::");
67
+ if (halves.length > 2) return undefined;
68
+ const left = halves[0] ? halves[0].split(":") : [];
69
+ const right = halves.length === 2 && halves[1] ? halves[1].split(":") : [];
70
+ const missing = 8 - left.length - right.length;
71
+ if (halves.length === 1 ? missing !== 0 : missing < 1) return undefined;
72
+ const groups = [...left, ...Array (halves.length === 2 ? missing : 0).fill("0"), ...right];
73
+ if (groups.length !== 8 || groups.some((g) => !/^[0-9a-f]{1,4}$/.test(g))) return undefined;
74
+ return groups.map((g) => g.padStart(4, "0"));
75
+ }
76
+
77
+ /**
78
+ * The network a client is limited and banned by: an IPv4 address as is, an IPv6 address as its
79
+ * /64 (`2001:0db8:0001:0002::/64`), an IPv4-mapped IPv6 address as its IPv4. Anything else is used
80
+ * lower-cased as given (the runtime vouches for the address; it is never a client header).
81
+ */
82
+ export function clientNetwork(address ) {
83
+ const a = address.trim();
84
+ if (IPV4.test(a)) return a;
85
+ const groups = expandIpv6(a);
86
+ if (!groups) return a.toLowerCase();
87
+ if (groups.slice(0, 5).every((g) => g === "0000") && groups[5] === "ffff") {
88
+ const hi = Number.parseInt(groups[6] ?? "0", 16);
89
+ const lo = Number.parseInt(groups[7] ?? "0", 16);
90
+ return `${hi >> 8}.${hi & 255}.${lo >> 8}.${lo & 255}`;
91
+ }
92
+ return `${groups.slice(0, 4).join(":")}::/64`;
93
+ }
94
+
95
+ const SALT_RE = /^[0-9a-f]{64}$/;
96
+
97
+ /** 32 random bytes as 64 lower-case hex characters (a fresh monthly salt). */
98
+ export function randomSalt() {
99
+ return toHex(crypto.getRandomValues(new Uint8Array(32)));
100
+ }
101
+
102
+ export async function ipHmac(salt , siteId , address ) {
103
+ if (!SALT_RE.test(salt)) throw new Error("a salt is 64 lower-case hex characters");
104
+ const raw = new Uint8Array(32);
105
+ for (let i = 0; i < 32; i++) raw[i] = Number.parseInt(salt.slice(i * 2, i * 2 + 2), 16);
106
+ const mac = await hmacRaw(raw, `${siteId}\n${clientNetwork(address)}`);
107
+ return toHex(mac.slice(0, 16));
108
+ }
109
+
110
+ /**
111
+ * The `COMMENTS_RL` Rate Limiting binding's key for a client: an HMAC of its network (IPv6 /64)
112
+ * under the key derived for that purpose (`cloudhal/comments/rl/v1`), so it is the same in every
113
+ * isolate and never the raw deployment secret (threat-model review of 2026-10-12, item 9).
114
+ */
115
+ export async function rateLimitKey(keys , address ) {
116
+ return toHex((await hmac(keys.rateLimit, utf8(clientNetwork(address)))).slice(0, 16));
117
+ }
118
+
119
+ /** Placeholder address when the runtime vouches for none (a separate, stricter bucket, §6.5). */
120
+ export const UNKNOWN_CLIENT = "unknown";
121
+
122
+ /** True for an IPv4 or IPv6 address (what the runtime vouches for); false for anything else. */
123
+ export function isClientAddress(address ) {
124
+ const a = address.trim();
125
+ return IPV4.test(a) || expandIpv6(a) !== undefined;
126
+ }
127
+
128
+ export async function emailHmac(keys , email ) {
129
+ return toHex(await hmac(keys.emailHmac, utf8(email.trim().toLowerCase())));
130
+ }
131
+
132
+ const emailContext = (siteId ) => `email\n${siteId}`;
133
+ const secretContext = (siteId , name ) => `secret\n${siteId}\n${name}`;
134
+
135
+ export const sealEmail = (keys , siteId , email ) =>
136
+ seal(keys.email, email.trim().toLowerCase(), emailContext(siteId));
137
+
138
+ export const openEmail = (keys , siteId , sealed ) =>
139
+ open(keys.email, sealed, emailContext(siteId));
140
+
141
+ export const sealSecret = (keys , siteId , name , value ) =>
142
+ seal(keys.secrets, value, secretContext(siteId, name));
143
+
144
+ export const openSecret = (keys , siteId , name , sealed ) =>
145
+ open(keys.secrets, sealed, secretContext(siteId, name));
146
+
147
+
148
+
149
+
150
+
151
+
152
+
153
+
154
+
155
+
156
+
157
+
158
+
159
+
160
+ export const STATE_HASH_PREFIX = "cm1:";
161
+
162
+ /** The `cm1:` binding of an approval to the comments and threads it names (§10.3). */
163
+ export async function commentStateHash(input ) {
164
+ const lines = [
165
+ ...input.comments.map((c) => `c ${c.id} ${c.rev} ${c.status}`),
166
+ ...input.threads.map((t) => `t ${t.nodeId} ${t.rev} ${t.state}`),
167
+ ];
168
+ lines.sort();
169
+ return `${STATE_HASH_PREFIX}${await sha256Hex(lines.join("\n"))}`;
170
+ }
171
+
172
+ const ALPHABET = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
173
+
174
+ /** A prefixed random id (`cmt_…`, `cmr_…`), Crockford base32 like core-ts `newId`. */
175
+ export function newCommentsId(prefix , length = 20) {
176
+ if (!/^[a-z]+$/.test(prefix)) throw new Error(`invalid id prefix "${prefix}"`);
177
+ let out = "";
178
+ for (const b of crypto.getRandomValues(new Uint8Array(length))) out += ALPHABET[b % 32];
179
+ return `${prefix}_${out}`;
180
+ }
181
+
182
+ export const ID_PREFIX = {
183
+ comment: "cmt",
184
+ commenter: "cmr",
185
+ report: "crp",
186
+ ban: "cban",
187
+ op: "op",
188
+ } ;
189
+
190
+ /** True for a base64url string that decodes (used to validate stored ciphertext columns). */
191
+ export const isBase64Url = (s ) => fromBase64Url(s) !== undefined;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @cloudhal/comments — first-party reader comments (RFC-0007, ADR-0022).
3
+ *
4
+ * This entry is Worker-safe and has no storage dependency: the settings model and `threadState`,
5
+ * text normalising, content rules (word lists with Turkish case folding, link limits,
6
+ * instruction-like text), linkify, the proof of work, the pure submission pipeline with its
7
+ * answers, keys and hashes (`cm1:` state hashes, IP hashes with a monthly salt, email encryption),
8
+ * isolate limits, the purge planner and the retention plan. The SQLite/D1 store is
9
+ * `@cloudhal/comments/sql`; the conformance suite `@cloudhal/comments/testing`.
10
+ */
11
+ export * from "./crypto.js";
12
+ export * from "./errors.js";
13
+ export * from "./hashes.js";
14
+ export * from "./limits.js";
15
+ export * from "./linkify.js";
16
+ export * from "./model.js";
17
+ export * from "./normalize.js";
18
+ export * from "./pipeline.js";
19
+ export * from "./pow.js";
20
+ export * from "./purge.js";
21
+ export * from "./retention.js";
22
+ export * from "./rules.js";
23
+ export * from "./settings.js";
24
+ export * from "./thread.js";
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @cloudhal/comments — first-party reader comments (RFC-0007, ADR-0022).
3
+ *
4
+ * This entry is Worker-safe and has no storage dependency: the settings model and `threadState`,
5
+ * text normalising, content rules (word lists with Turkish case folding, link limits,
6
+ * instruction-like text), linkify, the proof of work, the pure submission pipeline with its
7
+ * answers, keys and hashes (`cm1:` state hashes, IP hashes with a monthly salt, email encryption),
8
+ * isolate limits, the purge planner and the retention plan. The SQLite/D1 store is
9
+ * `@cloudhal/comments/sql`; the conformance suite `@cloudhal/comments/testing`.
10
+ */
11
+ export * from "./crypto.js";
12
+ export * from "./errors.js";
13
+ export * from "./hashes.js";
14
+ export * from "./limits.js";
15
+ export * from "./linkify.js";
16
+ export * from "./model.js";
17
+ export * from "./normalize.js";
18
+ export * from "./pipeline.js";
19
+ export * from "./pow.js";
20
+ export * from "./purge.js";
21
+ export * from "./retention.js";
22
+ export * from "./rules.js";
23
+ export * from "./settings.js";
24
+ export * from "./thread.js";