@peac/protocol 0.13.2 → 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 (36) hide show
  1. package/dist/_internal/legacy-path.d.ts +49 -0
  2. package/dist/_internal/legacy-path.d.ts.map +1 -0
  3. package/dist/_internal/record-core/bounded-validator.d.ts +65 -29
  4. package/dist/_internal/record-core/bounded-validator.d.ts.map +1 -1
  5. package/dist/_internal/record-core/validators/iat-not-yet-valid.d.ts +29 -0
  6. package/dist/_internal/record-core/validators/iat-not-yet-valid.d.ts.map +1 -0
  7. package/dist/_internal/record-core/validators/index.d.ts +7 -0
  8. package/dist/_internal/record-core/validators/index.d.ts.map +1 -1
  9. package/dist/_internal/record-core/validators/jose-typ-strictness.d.ts +39 -0
  10. package/dist/_internal/record-core/validators/jose-typ-strictness.d.ts.map +1 -0
  11. package/dist/_internal/record-core/validators/policy-binding.d.ts +33 -0
  12. package/dist/_internal/record-core/validators/policy-binding.d.ts.map +1 -0
  13. package/dist/_internal/record-core/validators/schema-parse.d.ts +42 -0
  14. package/dist/_internal/record-core/validators/schema-parse.d.ts.map +1 -0
  15. package/dist/_internal/record-core/validators/signature.d.ts +31 -0
  16. package/dist/_internal/record-core/validators/signature.d.ts.map +1 -0
  17. package/dist/_internal/record-core/validators/type-extension-enforcement.d.ts +42 -0
  18. package/dist/_internal/record-core/validators/type-extension-enforcement.d.ts.map +1 -0
  19. package/dist/_internal/record-core/validators/unknown-extension-grammar.d.ts +39 -0
  20. package/dist/_internal/record-core/validators/unknown-extension-grammar.d.ts.map +1 -0
  21. package/dist/_internal/test-helpers/candidate-runner.d.ts +52 -0
  22. package/dist/_internal/test-helpers/candidate-runner.d.ts.map +1 -0
  23. package/dist/_internal/test-helpers/parity-verdict.d.ts +35 -0
  24. package/dist/_internal/test-helpers/parity-verdict.d.ts.map +1 -1
  25. package/dist/index.cjs +195 -27
  26. package/dist/index.cjs.map +1 -1
  27. package/dist/index.mjs +195 -27
  28. package/dist/index.mjs.map +1 -1
  29. package/dist/issue.d.ts.map +1 -1
  30. package/dist/verify-local.cjs +163 -0
  31. package/dist/verify-local.cjs.map +1 -1
  32. package/dist/verify-local.d.ts.map +1 -1
  33. package/dist/verify-local.mjs +163 -0
  34. package/dist/verify-local.mjs.map +1 -1
  35. package/dist/verify.d.ts.map +1 -1
  36. 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,
@@ -595,6 +778,14 @@ function pruneStale() {
595
778
  while (SHADOW_LOG.length > 0 && SHADOW_LOG[0].timestamp < cutoffIso) SHADOW_LOG.shift();
596
779
  }
597
780
 
781
+ // src/_internal/legacy-path.ts
782
+ function readLegacyPathFlag(options) {
783
+ if (options?._internal?.legacyPath === true) return true;
784
+ if (typeof process === "undefined" || process === null) return false;
785
+ const env = process.env;
786
+ return env?.PEAC_INTERNAL_LEGACY_PATH === "1";
787
+ }
788
+
598
789
  // src/_internal/shadow-observe.ts
599
790
  function realObservationForIssue() {
600
791
  return EMPTY_ACCEPTED;
@@ -805,6 +996,7 @@ async function issue(options) {
805
996
  return issueWire02(options);
806
997
  }
807
998
  async function issueWire02(options) {
999
+ void readLegacyPathFlag(options);
808
1000
  if (!schema.isCanonicalIss(options.iss)) {
809
1001
  throw new IssueError({
810
1002
  code: "E_ISS_NOT_CANONICAL",
@@ -1919,6 +2111,8 @@ function jwkToPublicKey(jwk) {
1919
2111
  return new Uint8Array(xBytes);
1920
2112
  }
1921
2113
  async function verifyReceipt(optionsOrJws) {
2114
+ const legacyPathOptions = typeof optionsOrJws === "string" ? void 0 : optionsOrJws;
2115
+ void readLegacyPathFlag(legacyPathOptions);
1922
2116
  const receiptJws = typeof optionsOrJws === "string" ? optionsOrJws : optionsOrJws.receiptJws;
1923
2117
  const inputSnapshot = typeof optionsOrJws === "string" ? void 0 : optionsOrJws.subject_snapshot;
1924
2118
  const telemetry = typeof optionsOrJws === "string" ? void 0 : optionsOrJws.telemetry;
@@ -2052,33 +2246,6 @@ async function verifyReceipt(optionsOrJws) {
2052
2246
  }
2053
2247
  }
2054
2248
 
2055
- // src/type-extension-check.ts
2056
- function checkTypeExtensionMapping(kind, type, extensions, typeToExtensionMap, registeredExtensionGroupKeys) {
2057
- if (kind === "challenge") {
2058
- return { status: "skip" };
2059
- }
2060
- const expectedGroup = typeToExtensionMap.get(type);
2061
- if (expectedGroup === void 0) {
2062
- return { status: "skip" };
2063
- }
2064
- if (extensions !== void 0 && Object.prototype.hasOwnProperty.call(extensions, expectedGroup)) {
2065
- return { status: "ok" };
2066
- }
2067
- const presentRegistered = [];
2068
- if (extensions !== void 0) {
2069
- for (const key of Object.keys(extensions)) {
2070
- if (key !== expectedGroup && registeredExtensionGroupKeys.has(key)) {
2071
- presentRegistered.push(key);
2072
- }
2073
- }
2074
- }
2075
- return {
2076
- status: presentRegistered.length > 0 ? "mismatch" : "missing",
2077
- expected_extension_group: expectedGroup,
2078
- present_registered_extension_groups: presentRegistered
2079
- };
2080
- }
2081
-
2082
2249
  // src/_internal/record-core/shadow-hook.ts
2083
2250
  function maybeRunShadowValidation(input) {
2084
2251
  return void 0;
@@ -2110,6 +2277,7 @@ function sanitizeParseIssues(issues) {
2110
2277
  }));
2111
2278
  }
2112
2279
  async function verifyLocal(jws, publicKey, options = {}) {
2280
+ void readLegacyPathFlag(options);
2113
2281
  const {
2114
2282
  issuer,
2115
2283
  subjectUri,