@peac/protocol 0.12.13 → 0.13.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.
package/dist/index.d.ts CHANGED
@@ -7,8 +7,10 @@ export * from './verify';
7
7
  export * from './verify-local';
8
8
  export * from './headers';
9
9
  export * from './discovery';
10
- export * from './jwks-resolver';
10
+ export type { JWK, JWKS, RevokedKeyInfo, JWKSResolveSuccess, JWKSResolveError, JWKSResolveResult, ResolveJWKSOptions, } from './jwks-resolver';
11
+ export { clearKidThumbprints, getKidThumbprintSize, clearJWKSCache, getJWKSCacheSize, resolveJWKS, } from './jwks-resolver';
11
12
  export { computePolicyDigestJcs, checkPolicyBinding } from './policy-binding';
13
+ export { computeJsonDocumentDigestJcs, computeTextDocumentDigestUtf8, computeDocumentDigest, checkDocumentBinding, } from './document-binding';
12
14
  export * from './verifier-types';
13
15
  export * from './verifier-core';
14
16
  export * from './verification-report';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAGhC,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAG9E,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC;AAGhC,OAAO,EACL,eAAe,EACf,eAAe,EACf,oBAAoB,EACpB,eAAe,EACf,mBAAmB,EACnB,WAAW,EACX,SAAS,EACT,MAAM,GACP,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,YAAY,EACV,GAAG,EACH,IAAI,EACJ,cAAc,EACd,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,mBAAmB,EACnB,oBAAoB,EACpB,cAAc,EACd,gBAAgB,EAChB,WAAW,GACZ,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAK9E,OAAO,EACL,4BAA4B,EAC5B,6BAA6B,EAC7B,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,oBAAoB,CAAC;AAG5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC;AAGhC,OAAO,EACL,eAAe,EACf,eAAe,EACf,oBAAoB,EACpB,eAAe,EACf,mBAAmB,EACnB,WAAW,EACX,SAAS,EACT,MAAM,GACP,MAAM,cAAc,CAAC"}
package/dist/index.mjs CHANGED
@@ -990,8 +990,23 @@ async function fetchPointerSafe(pointerUrl, options) {
990
990
  }
991
991
 
992
992
  // src/jwks-resolver.ts
993
- var DEFAULT_CACHE_TTL_MS = 5 * 60 * 1e3;
994
- var DEFAULT_MAX_CACHE_ENTRIES = 1e3;
993
+ var HARD_CACHE_TTL_MS_BUILTIN = 5 * 60 * 1e3;
994
+ var HARD_MAX_CACHE_ENTRIES_BUILTIN = 1e3;
995
+ function __parseEnvPositiveInt(name, fallback, env = typeof process !== "undefined" ? process.env : {}) {
996
+ const raw = env[name];
997
+ if (!raw) return fallback;
998
+ if (!/^[1-9][0-9]*$/.test(raw)) return fallback;
999
+ const parsed = parseInt(raw, 10);
1000
+ return parsed > 0 ? parsed : fallback;
1001
+ }
1002
+ var DEFAULT_CACHE_TTL_MS = __parseEnvPositiveInt(
1003
+ "PEAC_JWKS_CACHE_TTL_MS",
1004
+ HARD_CACHE_TTL_MS_BUILTIN
1005
+ );
1006
+ var DEFAULT_MAX_CACHE_ENTRIES = __parseEnvPositiveInt(
1007
+ "PEAC_JWKS_CACHE_MAX_ENTRIES",
1008
+ HARD_MAX_CACHE_ENTRIES_BUILTIN
1009
+ );
995
1010
  var jwksCache = /* @__PURE__ */ new Map();
996
1011
  var KID_RETENTION_MS = 30 * 24 * 60 * 60 * 1e3;
997
1012
  var MAX_KID_THUMBPRINT_ENTRIES = 1e4;
@@ -1446,7 +1461,14 @@ function sanitizeParseIssues(issues) {
1446
1461
  }));
1447
1462
  }
1448
1463
  async function verifyLocal(jws, publicKey, options = {}) {
1449
- const { issuer, subjectUri, maxClockSkew = 300, strictness = "strict", policyDigest } = options;
1464
+ const {
1465
+ issuer,
1466
+ subjectUri,
1467
+ maxClockSkew = 300,
1468
+ strictness = "strict",
1469
+ policyDigest,
1470
+ bindings: callerBindings
1471
+ } = options;
1450
1472
  const now = options.now ?? Math.floor(Date.now() / 1e3);
1451
1473
  try {
1452
1474
  const result = await verify(jws, publicKey);
@@ -1596,6 +1618,11 @@ async function verifyLocal(jws, publicKey, options = {}) {
1596
1618
  }
1597
1619
  };
1598
1620
  }
1621
+ const bindings = {
1622
+ policy: bindingStatus,
1623
+ ...callerBindings?.terms !== void 0 && { terms: callerBindings.terms },
1624
+ ...callerBindings?.documents !== void 0 && callerBindings.documents.length > 0 && { documents: callerBindings.documents }
1625
+ };
1599
1626
  return {
1600
1627
  valid: true,
1601
1628
  variant: "wire-02",
@@ -1603,7 +1630,8 @@ async function verifyLocal(jws, publicKey, options = {}) {
1603
1630
  kid: result.header.kid,
1604
1631
  wireVersion: "0.2",
1605
1632
  warnings: sortWarnings(accumulatedWarnings),
1606
- policy_binding: bindingStatus
1633
+ policy_binding: bindingStatus,
1634
+ bindings
1607
1635
  };
1608
1636
  }
1609
1637
  return {
@@ -1708,16 +1736,44 @@ function setVaryPurposeHeader(headers) {
1708
1736
  headers.set("Vary", PEAC_PURPOSE_HEADER);
1709
1737
  }
1710
1738
  }
1711
- async function computePolicyDigestJcs(policy) {
1712
- const hex = await jcsHash(policy);
1739
+ async function computeJsonDocumentDigestJcs(value) {
1740
+ const hex = await jcsHash(value);
1713
1741
  return `${HASH.prefix}${hex}`;
1714
1742
  }
1715
- function checkPolicyBinding(receiptDigest, localDigest) {
1743
+ async function computeTextDocumentDigestUtf8(bytes, _representation) {
1744
+ const normalized = bytes.replace(/\r\n/g, "\n").replace(/\r/g, "\n").normalize("NFC");
1745
+ const buf = new TextEncoder().encode(normalized);
1746
+ const hashBuffer = await crypto.subtle.digest("SHA-256", buf);
1747
+ const hashArray = Array.from(new Uint8Array(hashBuffer));
1748
+ const hex = hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
1749
+ return `${HASH.prefix}${hex}`;
1750
+ }
1751
+ async function computeDocumentDigest(input) {
1752
+ switch (input.representation) {
1753
+ case "json":
1754
+ return computeJsonDocumentDigestJcs(input.value);
1755
+ case "markdown":
1756
+ case "plaintext":
1757
+ return computeTextDocumentDigestUtf8(input.bytes, input.representation);
1758
+ case "uri":
1759
+ if (typeof input.bytes !== "string") return "unavailable";
1760
+ return computeTextDocumentDigestUtf8(input.bytes);
1761
+ }
1762
+ }
1763
+ function checkDocumentBinding(receiptDigest, localDigest) {
1716
1764
  if (receiptDigest === void 0 || localDigest === void 0) {
1717
1765
  return "unavailable";
1718
1766
  }
1719
1767
  return verifyPolicyBinding(receiptDigest, localDigest);
1720
1768
  }
1769
+
1770
+ // src/policy-binding.ts
1771
+ async function computePolicyDigestJcs(policy) {
1772
+ return computeJsonDocumentDigestJcs(policy);
1773
+ }
1774
+ function checkPolicyBinding(receiptDigest, localDigest) {
1775
+ return checkDocumentBinding(receiptDigest, localDigest);
1776
+ }
1721
1777
  var DEFAULT_VERIFIER_LIMITS = {
1722
1778
  max_receipt_bytes: VERIFIER_LIMITS.maxReceiptBytes,
1723
1779
  max_jwks_bytes: VERIFIER_LIMITS.maxJwksBytes,
@@ -2993,6 +3049,6 @@ async function verifyAndFetchPointer(pointerHeader, fetchOptions) {
2993
3049
  });
2994
3050
  }
2995
3051
 
2996
- export { CHECK_IDS, DEFAULT_NETWORK_SECURITY, DEFAULT_VERIFIER_LIMITS, IssueError, NON_DETERMINISTIC_ARTIFACT_KEYS, VerificationReportBuilder, buildFailureReport, buildSuccessReport, checkPolicyBinding, clearJWKSCache, clearKidThumbprints, computePolicyDigestJcs, computeReceiptDigest, createDefaultPolicy, createDigest, createEmptyReport, createReportBuilder, fetchDiscovery, fetchIssuerConfig, fetchJWKSSafe, fetchPointerSafe, fetchPointerWithDigest, fetchPolicyManifest, getJWKSCacheSize, getKidThumbprintSize, getPurposeHeader, getReceiptHeader, getSSRFCapabilities, isAttestationResult, isBlockedIP, isCommerceResult, isWire02Result, issue, issueJws, issueWire01, issueWire02, parseBodyProfile, parseDiscovery, parseHeaderProfile, parseIssuerConfig, parsePointerProfile, parsePolicyManifest, parseTransportProfile, reasonCodeToErrorCode, reasonCodeToSeverity, resetSSRFCapabilitiesCache, resolveJWKS, setPurposeAppliedHeader, setPurposeReasonHeader, setReceiptHeader, setVaryHeader, setVaryPurposeHeader, ssrfErrorToReasonCode, ssrfSafeFetch, verifyAndFetchPointer, verifyLocal, verifyReceipt, verifyReceiptCore };
3052
+ export { CHECK_IDS, DEFAULT_NETWORK_SECURITY, DEFAULT_VERIFIER_LIMITS, IssueError, NON_DETERMINISTIC_ARTIFACT_KEYS, VerificationReportBuilder, buildFailureReport, buildSuccessReport, checkDocumentBinding, checkPolicyBinding, clearJWKSCache, clearKidThumbprints, computeDocumentDigest, computeJsonDocumentDigestJcs, computePolicyDigestJcs, computeReceiptDigest, computeTextDocumentDigestUtf8, createDefaultPolicy, createDigest, createEmptyReport, createReportBuilder, fetchDiscovery, fetchIssuerConfig, fetchJWKSSafe, fetchPointerSafe, fetchPointerWithDigest, fetchPolicyManifest, getJWKSCacheSize, getKidThumbprintSize, getPurposeHeader, getReceiptHeader, getSSRFCapabilities, isAttestationResult, isBlockedIP, isCommerceResult, isWire02Result, issue, issueJws, issueWire01, issueWire02, parseBodyProfile, parseDiscovery, parseHeaderProfile, parseIssuerConfig, parsePointerProfile, parsePolicyManifest, parseTransportProfile, reasonCodeToErrorCode, reasonCodeToSeverity, resetSSRFCapabilitiesCache, resolveJWKS, setPurposeAppliedHeader, setPurposeReasonHeader, setReceiptHeader, setVaryHeader, setVaryPurposeHeader, ssrfErrorToReasonCode, ssrfSafeFetch, verifyAndFetchPointer, verifyLocal, verifyReceipt, verifyReceiptCore };
2997
3053
  //# sourceMappingURL=index.mjs.map
2998
3054
  //# sourceMappingURL=index.mjs.map