@sealkeeper/schema 0.4.7 → 0.4.9

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/dist/api.d.ts +4411 -364
  2. package/dist/api.js +1753 -46
  3. package/dist/blocks.d.ts +21 -0
  4. package/dist/blocks.js +43 -0
  5. package/dist/cli-version.d.ts +7 -0
  6. package/dist/cli-version.js +89 -0
  7. package/dist/conformance.d.ts +4 -0
  8. package/dist/conformance.js +7 -0
  9. package/dist/credential.d.ts +763 -21
  10. package/dist/credential.js +253 -35
  11. package/dist/dimensions.d.ts +16 -3
  12. package/dist/dimensions.js +52 -2
  13. package/dist/fingerprint-conformance.d.ts +17 -0
  14. package/dist/fingerprint-conformance.js +83 -0
  15. package/dist/fingerprint.d.ts +133 -0
  16. package/dist/fingerprint.js +178 -0
  17. package/dist/game.d.ts +100 -0
  18. package/dist/game.js +190 -0
  19. package/dist/goal.d.ts +22 -1
  20. package/dist/goal.js +50 -7
  21. package/dist/handshake-conformance.d.ts +18 -0
  22. package/dist/handshake-conformance.js +276 -0
  23. package/dist/handshake.d.ts +66 -0
  24. package/dist/handshake.js +188 -0
  25. package/dist/index.d.ts +8 -0
  26. package/dist/index.js +8 -0
  27. package/dist/model-comparison.d.ts +70 -0
  28. package/dist/model-comparison.js +208 -0
  29. package/dist/model-name.d.ts +3 -0
  30. package/dist/model-name.js +48 -0
  31. package/dist/moderation.d.ts +2 -0
  32. package/dist/moderation.js +14 -8
  33. package/dist/policy.d.ts +1 -1
  34. package/dist/policy.js +1 -1
  35. package/dist/seal-conformance.js +263 -2
  36. package/dist/standing.d.ts +90 -0
  37. package/dist/standing.js +253 -13
  38. package/dist/task-templates.d.ts +47 -0
  39. package/dist/task-templates.js +506 -0
  40. package/dist/tasks.d.ts +97 -0
  41. package/dist/tasks.js +230 -0
  42. package/dist/template-conformance.d.ts +10 -0
  43. package/dist/template-conformance.js +298 -0
  44. package/dist/top-dimensions.d.ts +3 -3
  45. package/dist/top-dimensions.js +16 -6
  46. package/package.json +3 -3
@@ -18,6 +18,29 @@ const COUNTED = {
18
18
  server_checked_tasks: 0,
19
19
  confirmed_tasks: 0,
20
20
  };
21
+ // The three posted counts of a version 3 SEAL, and a fingerprint hash,
22
+ // SHA-256 of some bytes in base64url, 43 characters.
23
+ const POSTED = {
24
+ posted_tasks: 4,
25
+ posted_distinct_operators: 2,
26
+ posted_confirmed_tasks: 1,
27
+ };
28
+ const FINGERPRINT_HASH = 'BwjgHg-Z9sC4K05UnygMCN_CD7onYm12GfK83VEIpTQ';
29
+ // The counted evidence of a version 3 SEAL, COUNTED plus the counted twins
30
+ // of posted_tasks and posted_confirmed_tasks, each at most its raw count.
31
+ const COUNTED_V3 = {
32
+ ...COUNTED,
33
+ posted_tasks: 3,
34
+ posted_confirmed_tasks: 1,
35
+ };
36
+ // trust and top_categories of a version 4 SEAL. Three categories highest
37
+ // first, the tie of data and math in category order, data before math.
38
+ const TRUST = 412;
39
+ const TOP_CATEGORIES = [
40
+ { category: 'code', score: 230 },
41
+ { category: 'data', score: 90 },
42
+ { category: 'math', score: 90 },
43
+ ];
21
44
  const header = (kid) => base64urlEncode(utf8Encode(JSON.stringify({ alg: 'EdDSA', kid })));
22
45
  // Signs payload bytes as they are, so a case can carry a payload that is not
23
46
  // JSON. sign() in envelope.ts always writes JSON.
@@ -54,6 +77,22 @@ export async function sealConformanceCases() {
54
77
  last_active: NOW - HOUR,
55
78
  dormant_days: 0,
56
79
  };
80
+ // Version 3 is version 2 without version, with the posted counts,
81
+ // fingerprint and state.
82
+ const { version: _dropped, ...v2Fields } = base;
83
+ const v3 = {
84
+ ...v2Fields,
85
+ ver: 3,
86
+ counts: { ...base.counts, ...POSTED },
87
+ counted: COUNTED_V3,
88
+ fingerprint: { hash: FINGERPRINT_HASH, at: NOW - 2 * HOUR },
89
+ state: 'matches',
90
+ };
91
+ const { state: _state, ...v3NoState } = v3;
92
+ // Version 4 is version 3 with trust and top_categories.
93
+ const v4 = { ...v3, ver: 4, trust: TRUST, top_categories: TOP_CATEGORIES };
94
+ const { trust: _trust, ...v4NoTrust } = v4;
95
+ const { top_categories: _top, ...v4NoTop } = v4;
57
96
  const signed = (payload) => sign(payload, pair.privateKey, KID);
58
97
  const valid = await signed(base);
59
98
  const [h, , s] = valid.split('.');
@@ -108,14 +147,187 @@ export async function sealConformanceCases() {
108
147
  }),
109
148
  'malformed',
110
149
  ],
111
- ['an unknown ver', signed({ ...base, ver: 3 }), 'unsupported_version'],
150
+ [
151
+ 'version 3 with posted counts, fingerprint and state',
152
+ signed(v3),
153
+ 'valid',
154
+ ],
155
+ [
156
+ 'version 3 with no fingerprint yet and a reserved state',
157
+ signed({ ...v3, fingerprint: null, state: 'provisional' }),
158
+ 'valid',
159
+ ],
160
+ [
161
+ 'version 3 with a field it does not define',
162
+ signed({ ...v3, extra: true }),
163
+ 'malformed',
164
+ ],
165
+ ['version 3 without state', signed(v3NoState), 'malformed'],
166
+ [
167
+ 'version 3 with a state outside the set',
168
+ signed({ ...v3, state: 'unknown' }),
169
+ 'malformed',
170
+ ],
171
+ [
172
+ 'version 3 with a fingerprint hash of the wrong length',
173
+ signed({
174
+ ...v3,
175
+ fingerprint: { hash: FINGERPRINT_HASH.slice(1), at: NOW - HOUR },
176
+ }),
177
+ 'malformed',
178
+ ],
179
+ [
180
+ 'version 3 with the dropped version field',
181
+ signed({ ...v3, version: '1.0.0' }),
182
+ 'malformed',
183
+ ],
184
+ [
185
+ 'version 3 without the posted counts',
186
+ signed({ ...v3, counts: base.counts }),
187
+ 'malformed',
188
+ ],
189
+ [
190
+ 'version 3 with a counted posted value above its count',
191
+ signed({
192
+ ...v3,
193
+ counted: { ...COUNTED_V3, posted_tasks: 5 },
194
+ }),
195
+ 'malformed',
196
+ ],
197
+ [
198
+ 'version 3 with the version 2 counted evidence',
199
+ signed({ ...v3, counted: COUNTED }),
200
+ 'malformed',
201
+ ],
202
+ [
203
+ 'version 3 with a fingerprint after iat',
204
+ signed({
205
+ ...v3,
206
+ fingerprint: { hash: FINGERPRINT_HASH, at: v3.iat + 1 },
207
+ }),
208
+ 'malformed',
209
+ ],
210
+ [
211
+ 'version 3 with a fingerprint hash whose last character no SHA-256 has',
212
+ signed({
213
+ ...v3,
214
+ fingerprint: {
215
+ hash: `${FINGERPRINT_HASH.slice(0, 42)}R`,
216
+ at: NOW - HOUR,
217
+ },
218
+ }),
219
+ 'malformed',
220
+ ],
221
+ [
222
+ 'version 3 with more posted confirmed tasks than posted tasks',
223
+ signed({
224
+ ...v3,
225
+ counts: { ...v3.counts, posted_confirmed_tasks: 5 },
226
+ }),
227
+ 'malformed',
228
+ ],
229
+ [
230
+ 'version 2 with a fingerprint and state',
231
+ signed({
232
+ ...base,
233
+ ver: 2,
234
+ counted: COUNTED,
235
+ fingerprint: v3.fingerprint,
236
+ state: 'matches',
237
+ }),
238
+ 'malformed',
239
+ ],
240
+ ['version 4 with a Trust Score and top categories', signed(v4), 'valid'],
241
+ [
242
+ 'version 4 with no category yet',
243
+ signed({ ...v4, trust: 0, top_categories: [] }),
244
+ 'valid',
245
+ ],
246
+ [
247
+ 'version 4 with a field it does not define',
248
+ signed({ ...v4, extra: true }),
249
+ 'malformed',
250
+ ],
251
+ ['version 4 without trust', signed(v4NoTrust), 'malformed'],
252
+ ['version 4 without top_categories', signed(v4NoTop), 'malformed'],
253
+ [
254
+ 'version 4 with a Trust Score that is not a whole number',
255
+ signed({ ...v4, trust: 412.5 }),
256
+ 'malformed',
257
+ ],
258
+ [
259
+ 'version 4 with a negative Trust Score',
260
+ signed({ ...v4, trust: -1 }),
261
+ 'malformed',
262
+ ],
263
+ [
264
+ 'version 4 with four top categories',
265
+ signed({
266
+ ...v4,
267
+ top_categories: [...TOP_CATEGORIES, { category: 'writing', score: 10 }],
268
+ }),
269
+ 'malformed',
270
+ ],
271
+ [
272
+ 'version 4 with top categories lowest first',
273
+ signed({ ...v4, top_categories: [...TOP_CATEGORIES].reverse() }),
274
+ 'malformed',
275
+ ],
276
+ [
277
+ 'version 4 with a tie out of category order',
278
+ signed({
279
+ ...v4,
280
+ top_categories: [
281
+ TOP_CATEGORIES[0],
282
+ TOP_CATEGORIES[2],
283
+ TOP_CATEGORIES[1],
284
+ ],
285
+ }),
286
+ 'malformed',
287
+ ],
288
+ [
289
+ 'version 4 with one category twice',
290
+ signed({
291
+ ...v4,
292
+ top_categories: [TOP_CATEGORIES[0], TOP_CATEGORIES[0]],
293
+ }),
294
+ 'malformed',
295
+ ],
296
+ [
297
+ 'version 4 with a category the standard does not name',
298
+ signed({
299
+ ...v4,
300
+ top_categories: [{ category: 'Data Work', score: 90 }],
301
+ }),
302
+ 'malformed',
303
+ ],
304
+ [
305
+ 'version 4 with a category score that is not a whole number',
306
+ signed({
307
+ ...v4,
308
+ top_categories: [{ category: 'code', score: 0.5 }],
309
+ }),
310
+ 'malformed',
311
+ ],
312
+ [
313
+ 'version 4 with the dropped version field',
314
+ signed({ ...v4, version: '1.0.0' }),
315
+ 'malformed',
316
+ ],
317
+ [
318
+ 'version 3 with trust and top_categories',
319
+ signed({ ...v4, ver: 3 }),
320
+ 'malformed',
321
+ ],
322
+ ['an unknown ver', signed({ ...base, ver: 5 }), 'unsupported_version'],
112
323
  [
113
324
  'no ver after the legacy cutoff',
114
325
  signed({ ...base, ver: undefined }),
115
326
  'unsupported_version',
116
327
  ],
117
328
  // Intended. Platinum is reserved on LADDER and is not a Level under ver
118
- // 1 or 2 (standard, section 9). It becomes valid only with a ver bump.
329
+ // 1, 2, 3 or 4 (standard, section 9). It becomes valid only with a ver
330
+ // bump.
119
331
  [
120
332
  'the wrong shape, a level not in the standard',
121
333
  signed({ ...base, level: 'platinum' }),
@@ -126,6 +338,55 @@ export async function sealConformanceCases() {
126
338
  signed({ ...base, scores: { reliability: 1.2 } }),
127
339
  'malformed',
128
340
  ],
341
+ // Competence is keyed by category from RT-3. A SEAL issued before it
342
+ // carries competence by task type, and a verifier accepts both
343
+ // (standard, section 2). Any of the eight stored categories is valid,
344
+ // math, which a poster can choose from D-UI-12, and conversation and
345
+ // other, which are no longer offered but past tasks keep.
346
+ [
347
+ 'competence by category',
348
+ signed({
349
+ ...base,
350
+ scores: { ...base.scores, 'competence:data': 0.8 },
351
+ }),
352
+ 'valid',
353
+ ],
354
+ [
355
+ 'competence in math',
356
+ signed({
357
+ ...base,
358
+ scores: { ...base.scores, 'competence:math': 0.8 },
359
+ }),
360
+ 'valid',
361
+ ],
362
+ [
363
+ 'competence in conversation and other, kept by past tasks',
364
+ signed({
365
+ ...base,
366
+ scores: {
367
+ ...base.scores,
368
+ 'competence:conversation': 0.7,
369
+ 'competence:other': 0.6,
370
+ },
371
+ }),
372
+ 'valid',
373
+ ],
374
+ [
375
+ 'competence by task type, issued before categories',
376
+ signed({
377
+ ...base,
378
+ scores: { ...base.scores, 'competence:csv_normalise': 0.8 },
379
+ }),
380
+ 'valid',
381
+ ],
382
+ [
383
+ 'a competence key that is not a task type',
384
+ signed({
385
+ ...base,
386
+ scores: { ...base.scores, 'competence:Data Work': 0.8 },
387
+ }),
388
+ 'malformed',
389
+ ],
129
390
  [
130
391
  'a negative count',
131
392
  signed({
@@ -37,6 +37,20 @@ export declare const StandingCounts: z.ZodObject<{
37
37
  safety_incidents_90d: z.ZodInt;
38
38
  }, z.core.$strict>;
39
39
  export type StandingCounts = z.infer<typeof StandingCounts>;
40
+ export declare const StandingCountsV3: z.ZodObject<{
41
+ events: z.ZodInt;
42
+ history_days: z.ZodInt;
43
+ verified_tasks: z.ZodInt;
44
+ seed_tasks: z.ZodInt;
45
+ server_checked_tasks: z.ZodInt;
46
+ confirmed_tasks: z.ZodInt;
47
+ distinct_operators: z.ZodInt;
48
+ safety_incidents_90d: z.ZodInt;
49
+ posted_tasks: z.ZodInt;
50
+ posted_distinct_operators: z.ZodInt;
51
+ posted_confirmed_tasks: z.ZodInt;
52
+ }, z.core.$strict>;
53
+ export type StandingCountsV3 = z.infer<typeof StandingCountsV3>;
40
54
  export declare const CountedCounts: z.ZodObject<{
41
55
  verified_tasks: z.ZodInt;
42
56
  seed_tasks: z.ZodInt;
@@ -44,10 +58,52 @@ export declare const CountedCounts: z.ZodObject<{
44
58
  confirmed_tasks: z.ZodInt;
45
59
  }, z.core.$strict>;
46
60
  export type CountedCounts = z.infer<typeof CountedCounts>;
61
+ export declare const CountedCountsV3: z.ZodObject<{
62
+ verified_tasks: z.ZodInt;
63
+ seed_tasks: z.ZodInt;
64
+ server_checked_tasks: z.ZodInt;
65
+ confirmed_tasks: z.ZodInt;
66
+ posted_tasks: z.ZodInt;
67
+ posted_confirmed_tasks: z.ZodInt;
68
+ }, z.core.$strict>;
69
+ export type CountedCountsV3 = z.infer<typeof CountedCountsV3>;
70
+ export declare const AnswerCounts: z.ZodObject<{
71
+ events: z.ZodInt;
72
+ history_days: z.ZodInt;
73
+ verified_tasks: z.ZodInt;
74
+ seed_tasks: z.ZodInt;
75
+ server_checked_tasks: z.ZodInt;
76
+ confirmed_tasks: z.ZodInt;
77
+ distinct_operators: z.ZodInt;
78
+ safety_incidents_90d: z.ZodInt;
79
+ posted_tasks: z.ZodOptional<z.ZodInt>;
80
+ posted_distinct_operators: z.ZodOptional<z.ZodInt>;
81
+ posted_confirmed_tasks: z.ZodOptional<z.ZodInt>;
82
+ }, z.core.$strict>;
83
+ export type AnswerCounts = z.infer<typeof AnswerCounts>;
84
+ export declare const AnswerCounted: z.ZodObject<{
85
+ verified_tasks: z.ZodInt;
86
+ seed_tasks: z.ZodInt;
87
+ server_checked_tasks: z.ZodInt;
88
+ confirmed_tasks: z.ZodInt;
89
+ posted_tasks: z.ZodOptional<z.ZodInt>;
90
+ posted_confirmed_tasks: z.ZodOptional<z.ZodInt>;
91
+ }, z.core.$strict>;
92
+ export type AnswerCounted = z.infer<typeof AnswerCounted>;
47
93
  export declare const COUNTED_EVIDENCE: {
48
94
  readonly dailyCeiling: 20;
49
95
  readonly diminishingK: 25;
96
+ readonly pairCurve: {
97
+ readonly free: 5;
98
+ readonly k: 5;
99
+ readonly windowDays: 30;
100
+ };
101
+ readonly operatorShareCap: {
102
+ readonly share: 0.5;
103
+ readonly floor: 5;
104
+ };
50
105
  };
106
+ export declare const POSTER_RESPONSE_HOURS = 48;
51
107
  export declare const DAY_MS = 86400000;
52
108
  export declare const DORMANCY: {
53
109
  readonly quietDays: 14;
@@ -55,24 +111,49 @@ export declare const DORMANCY: {
55
111
  readonly dropTwoDays: 60;
56
112
  readonly noneDays: 90;
57
113
  };
114
+ export declare const TRUST_SCORE: {
115
+ readonly decay: {
116
+ readonly fullDays: 30;
117
+ readonly zeroDays: 180;
118
+ };
119
+ readonly diversityWeight: 1.1;
120
+ readonly diversityMinTasks: 5;
121
+ readonly operatorK: 2;
122
+ readonly seriesDays: 30;
123
+ readonly deltaDays: 7;
124
+ readonly rankMax: 10000;
125
+ readonly rankWeeks: 8;
126
+ };
127
+ export declare function trustWeekOf(at: Date): string;
128
+ export declare const SAFETY_MEASURED: boolean;
58
129
  export declare const LEVEL_THRESHOLDS: {
59
130
  readonly bronze: {
60
131
  readonly verifiedTasks: 25;
132
+ readonly trustScore: 50;
61
133
  readonly historyDays: 3;
62
134
  readonly reliability: 0.8;
63
135
  readonly incidents90d: 0;
136
+ readonly postedTasks: 5;
137
+ readonly postedOperators: 1;
138
+ readonly postedConfirmedTasks: 0;
64
139
  };
65
140
  readonly silver: {
66
141
  readonly verifiedTasks: 200;
142
+ readonly trustScore: 400;
143
+ readonly trustCategories: 2;
67
144
  readonly historyDays: 30;
68
145
  readonly reliability: 0.9;
69
146
  readonly safety: 0.9;
70
147
  readonly incidents90d: 0;
71
148
  readonly provenance: 0.8;
72
149
  readonly modelDeclared: true;
150
+ readonly postedTasks: 40;
151
+ readonly postedOperators: 5;
152
+ readonly postedConfirmedTasks: 10;
73
153
  };
74
154
  readonly gold: {
75
155
  readonly verifiedTasks: 200;
156
+ readonly trustScore: 400;
76
157
  readonly confirmedTasks: 25;
77
158
  readonly confirmedOperators: 3;
78
159
  readonly historySpanDays: 90;
@@ -81,6 +162,9 @@ export declare const LEVEL_THRESHOLDS: {
81
162
  readonly safety: 0.95;
82
163
  readonly cleanDays: 180;
83
164
  readonly operatorVerified: true;
165
+ readonly postedTasks: 40;
166
+ readonly postedOperators: 5;
167
+ readonly postedConfirmedTasks: 25;
84
168
  };
85
169
  };
86
170
  export declare const OPERATOR_SILVER_CAP: {
@@ -99,16 +183,22 @@ export declare const Standing: z.ZodObject<{
99
183
  confirmed_tasks: z.ZodInt;
100
184
  distinct_operators: z.ZodInt;
101
185
  safety_incidents_90d: z.ZodInt;
186
+ posted_tasks: z.ZodOptional<z.ZodInt>;
187
+ posted_distinct_operators: z.ZodOptional<z.ZodInt>;
188
+ posted_confirmed_tasks: z.ZodOptional<z.ZodInt>;
102
189
  }, z.core.$strict>;
103
190
  counted: z.ZodObject<{
104
191
  verified_tasks: z.ZodInt;
105
192
  seed_tasks: z.ZodInt;
106
193
  server_checked_tasks: z.ZodInt;
107
194
  confirmed_tasks: z.ZodInt;
195
+ posted_tasks: z.ZodOptional<z.ZodInt>;
196
+ posted_confirmed_tasks: z.ZodOptional<z.ZodInt>;
108
197
  }, z.core.$strict>;
109
198
  history_days: z.ZodInt;
110
199
  last_active: z.ZodNullable<z.ZodISODateTime>;
111
200
  dormant_days: z.ZodNullable<z.ZodInt>;
112
201
  quiet: z.ZodBoolean;
202
+ held: z.ZodOptional<z.ZodBoolean>;
113
203
  }, z.core.$strict>;
114
204
  export type Standing = z.infer<typeof Standing>;