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