@peac/protocol 0.13.3 → 0.13.4

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 (29) hide show
  1. package/dist/_internal/record-core/bounded-validator.d.ts +65 -29
  2. package/dist/_internal/record-core/bounded-validator.d.ts.map +1 -1
  3. package/dist/_internal/record-core/validators/iat-not-yet-valid.d.ts +29 -0
  4. package/dist/_internal/record-core/validators/iat-not-yet-valid.d.ts.map +1 -0
  5. package/dist/_internal/record-core/validators/index.d.ts +7 -0
  6. package/dist/_internal/record-core/validators/index.d.ts.map +1 -1
  7. package/dist/_internal/record-core/validators/jose-typ-strictness.d.ts +39 -0
  8. package/dist/_internal/record-core/validators/jose-typ-strictness.d.ts.map +1 -0
  9. package/dist/_internal/record-core/validators/policy-binding.d.ts +33 -0
  10. package/dist/_internal/record-core/validators/policy-binding.d.ts.map +1 -0
  11. package/dist/_internal/record-core/validators/schema-parse.d.ts +42 -0
  12. package/dist/_internal/record-core/validators/schema-parse.d.ts.map +1 -0
  13. package/dist/_internal/record-core/validators/signature.d.ts +31 -0
  14. package/dist/_internal/record-core/validators/signature.d.ts.map +1 -0
  15. package/dist/_internal/record-core/validators/type-extension-enforcement.d.ts +42 -0
  16. package/dist/_internal/record-core/validators/type-extension-enforcement.d.ts.map +1 -0
  17. package/dist/_internal/record-core/validators/unknown-extension-grammar.d.ts +39 -0
  18. package/dist/_internal/record-core/validators/unknown-extension-grammar.d.ts.map +1 -0
  19. package/dist/_internal/test-helpers/candidate-runner.d.ts +52 -0
  20. package/dist/_internal/test-helpers/candidate-runner.d.ts.map +1 -0
  21. package/dist/index.cjs +183 -27
  22. package/dist/index.cjs.map +1 -1
  23. package/dist/index.mjs +183 -27
  24. package/dist/index.mjs.map +1 -1
  25. package/dist/verify-local.cjs +154 -0
  26. package/dist/verify-local.cjs.map +1 -1
  27. package/dist/verify-local.mjs +154 -0
  28. package/dist/verify-local.mjs.map +1 -1
  29. package/package.json +4 -4
package/dist/index.mjs CHANGED
@@ -310,6 +310,127 @@ function validateExtensionBudgetInternal(extensions) {
310
310
  if (violations.length === 0) return ACCEPTED4;
311
311
  return { accepted: false, violations };
312
312
  }
313
+ function validateSchemaParseInternal(payload) {
314
+ const pr = parseReceiptClaims(payload);
315
+ if (!pr.ok) {
316
+ return { accepted: false, errorCode: pr.error.code };
317
+ }
318
+ if (pr.wireVersion !== "0.2") {
319
+ return { accepted: false, errorCode: "E_UNSUPPORTED_WIRE_VERSION" };
320
+ }
321
+ return { accepted: true, claims: pr.claims };
322
+ }
323
+
324
+ // src/_internal/record-core/validators/jose-typ-strictness.ts
325
+ var ACCEPTED_NO_WARN = { accepted: true };
326
+ var ACCEPTED_TYP_MISSING = {
327
+ accepted: true,
328
+ warnings: [{ code: "typ_missing" }]
329
+ };
330
+ var REJECTED_INVALID_FORMAT = {
331
+ accepted: false,
332
+ errorCode: "E_INVALID_FORMAT"
333
+ };
334
+ function validateJoseTypStrictnessInternal(typ, strictness) {
335
+ const present = typeof typ === "string" && typ.length > 0;
336
+ if (present) return ACCEPTED_NO_WARN;
337
+ if (strictness === "strict") return REJECTED_INVALID_FORMAT;
338
+ return ACCEPTED_TYP_MISSING;
339
+ }
340
+
341
+ // src/_internal/record-core/validators/iat-not-yet-valid.ts
342
+ var ACCEPTED5 = { accepted: true };
343
+ var REJECTED2 = {
344
+ accepted: false,
345
+ errorCode: "E_NOT_YET_VALID"
346
+ };
347
+ function validateIatNotYetValidInternal(iat, now, maxClockSkew) {
348
+ if (iat > now + maxClockSkew) return REJECTED2;
349
+ return ACCEPTED5;
350
+ }
351
+ function validatePolicyBindingInternal(receiptPolicyDigest, localPolicyDigest) {
352
+ if (receiptPolicyDigest === void 0 || localPolicyDigest === void 0) {
353
+ return { accepted: true, status: "unavailable" };
354
+ }
355
+ const status = verifyPolicyBinding(receiptPolicyDigest, localPolicyDigest);
356
+ if (status === "failed") {
357
+ return { accepted: false, errorCode: "E_POLICY_BINDING_FAILED", status };
358
+ }
359
+ return { accepted: true, status };
360
+ }
361
+ var ACCEPTED_EMPTY = {
362
+ accepted: true,
363
+ warnings: []
364
+ };
365
+ function escapeJsonPointer(token) {
366
+ return token.replace(/~/g, "~0").replace(/\//g, "~1");
367
+ }
368
+ function validateUnknownExtensionGrammarInternal(extensions) {
369
+ if (extensions === void 0) return ACCEPTED_EMPTY;
370
+ const keys = Object.keys(extensions);
371
+ if (keys.length === 0) return ACCEPTED_EMPTY;
372
+ const warnings = [];
373
+ for (const key of keys) {
374
+ if (!REGISTERED_EXTENSION_GROUP_KEYS.has(key) && isValidExtensionKey(key)) {
375
+ warnings.push({
376
+ code: "unknown_extension_preserved",
377
+ pointer: `/extensions/${escapeJsonPointer(key)}`
378
+ });
379
+ }
380
+ }
381
+ return { accepted: true, warnings };
382
+ }
383
+
384
+ // src/type-extension-check.ts
385
+ function checkTypeExtensionMapping(kind, type, extensions, typeToExtensionMap, registeredExtensionGroupKeys) {
386
+ if (kind === "challenge") {
387
+ return { status: "skip" };
388
+ }
389
+ const expectedGroup = typeToExtensionMap.get(type);
390
+ if (expectedGroup === void 0) {
391
+ return { status: "skip" };
392
+ }
393
+ if (extensions !== void 0 && Object.prototype.hasOwnProperty.call(extensions, expectedGroup)) {
394
+ return { status: "ok" };
395
+ }
396
+ const presentRegistered = [];
397
+ if (extensions !== void 0) {
398
+ for (const key of Object.keys(extensions)) {
399
+ if (key !== expectedGroup && registeredExtensionGroupKeys.has(key)) {
400
+ presentRegistered.push(key);
401
+ }
402
+ }
403
+ }
404
+ return {
405
+ status: presentRegistered.length > 0 ? "mismatch" : "missing",
406
+ expected_extension_group: expectedGroup,
407
+ present_registered_extension_groups: presentRegistered
408
+ };
409
+ }
410
+
411
+ // src/_internal/record-core/validators/type-extension-enforcement.ts
412
+ var ACCEPTED_NO_WARN2 = { accepted: true };
413
+ function validateTypeExtensionEnforcementInternal(kind, type, extensions, strictness) {
414
+ const result = checkTypeExtensionMapping(
415
+ kind,
416
+ type,
417
+ extensions,
418
+ TYPE_TO_EXTENSION_MAP,
419
+ REGISTERED_EXTENSION_GROUP_KEYS
420
+ );
421
+ if (result.status === "ok" || result.status === "skip") {
422
+ return ACCEPTED_NO_WARN2;
423
+ }
424
+ if (strictness === "strict") {
425
+ const errorCode = result.status === "missing" ? "E_EXTENSION_GROUP_REQUIRED" : "E_EXTENSION_GROUP_MISMATCH";
426
+ return { accepted: false, errorCode, pointer: "/type" };
427
+ }
428
+ const warningCode = result.status === "missing" ? "extension_group_missing" : "extension_group_mismatch";
429
+ return {
430
+ accepted: true,
431
+ warnings: [{ code: warningCode, pointer: "/type" }]
432
+ };
433
+ }
313
434
 
314
435
  // src/_internal/record-core/bounded-validator.ts
315
436
  function runBoundedValidatorShadow(input) {
@@ -369,6 +490,68 @@ function runBoundedValidatorShadow(input) {
369
490
  violations.push({ layer: "extension-budget", code: v.code, path: v.path });
370
491
  }
371
492
  }
493
+ if (input.fullClaims !== void 0) {
494
+ const schemaRes = validateSchemaParseInternal(input.fullClaims);
495
+ if (!schemaRes.accepted && schemaRes.errorCode !== void 0) {
496
+ violations.push({ layer: "schema-parse", code: schemaRes.errorCode });
497
+ }
498
+ }
499
+ if (input.header !== void 0 && input.strictness !== void 0) {
500
+ const typRes = validateJoseTypStrictnessInternal(input.header.typ, input.strictness);
501
+ if (!typRes.accepted) {
502
+ violations.push({ layer: "jose-typ-strictness", code: typRes.errorCode });
503
+ } else if (typRes.warnings) {
504
+ for (const w of typRes.warnings) {
505
+ warnings.push({ layer: "jose-typ-strictness", code: w.code });
506
+ }
507
+ }
508
+ }
509
+ if (input.maxClockSkew !== void 0) {
510
+ const iatRes = validateIatNotYetValidInternal(input.claims.iat, input.now, input.maxClockSkew);
511
+ if (!iatRes.accepted && iatRes.errorCode !== void 0) {
512
+ violations.push({ layer: "iat-not-yet-valid", code: iatRes.errorCode });
513
+ }
514
+ }
515
+ if (input.receiptPolicyDigest !== void 0 && input.localPolicyDigest !== void 0) {
516
+ const policyRes = validatePolicyBindingInternal(
517
+ input.receiptPolicyDigest,
518
+ input.localPolicyDigest
519
+ );
520
+ if (!policyRes.accepted && policyRes.errorCode !== void 0) {
521
+ violations.push({ layer: "policy-binding", code: policyRes.errorCode });
522
+ }
523
+ }
524
+ const unknownExtRes = validateUnknownExtensionGrammarInternal(input.claims.extensions);
525
+ for (const w of unknownExtRes.warnings) {
526
+ warnings.push({
527
+ layer: "unknown-extension-grammar",
528
+ code: w.code,
529
+ path: w.pointer
530
+ });
531
+ }
532
+ if (input.strictness !== void 0) {
533
+ const enforceRes = validateTypeExtensionEnforcementInternal(
534
+ input.claims.kind,
535
+ input.claims.type,
536
+ input.claims.extensions,
537
+ input.strictness
538
+ );
539
+ if (!enforceRes.accepted) {
540
+ violations.push({
541
+ layer: "type-extension-enforcement",
542
+ code: enforceRes.errorCode,
543
+ path: enforceRes.pointer
544
+ });
545
+ } else if (enforceRes.warnings) {
546
+ for (const w of enforceRes.warnings) {
547
+ warnings.push({
548
+ layer: "type-extension-enforcement",
549
+ code: w.code,
550
+ path: w.pointer
551
+ });
552
+ }
553
+ }
554
+ }
372
555
  return {
373
556
  accepted: violations.length === 0,
374
557
  violations,
@@ -2062,33 +2245,6 @@ async function verifyReceipt(optionsOrJws) {
2062
2245
  }
2063
2246
  }
2064
2247
 
2065
- // src/type-extension-check.ts
2066
- function checkTypeExtensionMapping(kind, type, extensions, typeToExtensionMap, registeredExtensionGroupKeys) {
2067
- if (kind === "challenge") {
2068
- return { status: "skip" };
2069
- }
2070
- const expectedGroup = typeToExtensionMap.get(type);
2071
- if (expectedGroup === void 0) {
2072
- return { status: "skip" };
2073
- }
2074
- if (extensions !== void 0 && Object.prototype.hasOwnProperty.call(extensions, expectedGroup)) {
2075
- return { status: "ok" };
2076
- }
2077
- const presentRegistered = [];
2078
- if (extensions !== void 0) {
2079
- for (const key of Object.keys(extensions)) {
2080
- if (key !== expectedGroup && registeredExtensionGroupKeys.has(key)) {
2081
- presentRegistered.push(key);
2082
- }
2083
- }
2084
- }
2085
- return {
2086
- status: presentRegistered.length > 0 ? "mismatch" : "missing",
2087
- expected_extension_group: expectedGroup,
2088
- present_registered_extension_groups: presentRegistered
2089
- };
2090
- }
2091
-
2092
2248
  // src/_internal/record-core/shadow-hook.ts
2093
2249
  function maybeRunShadowValidation(input) {
2094
2250
  return void 0;