@kya-os/checkpoint-shared 1.6.0 → 1.7.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.
Files changed (83) hide show
  1. package/dist/{browser-posture-DIaVLuW3.d.ts → browser-posture-B8YiPa5c.d.ts} +5 -5
  2. package/dist/{browser-posture-DIaVLuW3.d.ts.map → browser-posture-B8YiPa5c.d.ts.map} +1 -1
  3. package/dist/{browser-posture-BuChqmH5.d.mts → browser-posture-BLhw-MON.d.mts} +5 -5
  4. package/dist/{browser-posture-BuChqmH5.d.mts.map → browser-posture-BLhw-MON.d.mts.map} +1 -1
  5. package/dist/browser-posture-cookie.js +1 -1
  6. package/dist/browser-posture-cookie.mjs +1 -1
  7. package/dist/browser-posture-cookie.mjs.map +1 -1
  8. package/dist/browser-posture-proof.d.mts +1 -1
  9. package/dist/browser-posture-proof.d.mts.map +1 -1
  10. package/dist/browser-posture-proof.d.ts +1 -1
  11. package/dist/browser-posture-proof.d.ts.map +1 -1
  12. package/dist/browser-posture-proof.js +42 -1
  13. package/dist/browser-posture-proof.mjs +42 -1
  14. package/dist/browser-posture-proof.mjs.map +1 -1
  15. package/dist/browser-posture.d.mts +1 -1
  16. package/dist/browser-posture.d.ts +1 -1
  17. package/dist/browser-posture.js +1 -1
  18. package/dist/browser-posture.mjs +1 -1
  19. package/dist/canonical-signer/index.d.mts.map +1 -1
  20. package/dist/canonical-signer/index.d.ts.map +1 -1
  21. package/dist/canonical-signer/index.js +86 -51
  22. package/dist/canonical-signer/index.mjs +86 -51
  23. package/dist/canonical-signer/index.mjs.map +1 -1
  24. package/dist/client-ip-DFamiNoz.d.mts +34 -0
  25. package/dist/client-ip-DFamiNoz.d.mts.map +1 -0
  26. package/dist/client-ip-DFamiNoz.d.ts +34 -0
  27. package/dist/client-ip-DFamiNoz.d.ts.map +1 -0
  28. package/dist/client-ip.d.mts +2 -0
  29. package/dist/client-ip.d.ts +2 -0
  30. package/dist/client-ip.js +7 -0
  31. package/dist/client-ip.mjs +3 -0
  32. package/dist/host-adapter/index.d.mts +2 -0
  33. package/dist/host-adapter/index.d.ts +2 -0
  34. package/dist/host-adapter/index.js +23 -0
  35. package/dist/host-adapter/index.mjs +3 -0
  36. package/dist/host-adapter-C-4IxmqM.mjs +540 -0
  37. package/dist/host-adapter-C-4IxmqM.mjs.map +1 -0
  38. package/dist/host-adapter-CwW9YB0U.js +694 -0
  39. package/dist/index-B7rTovHa.d.mts +707 -0
  40. package/dist/index-B7rTovHa.d.mts.map +1 -0
  41. package/dist/index-HaqfPtaL.d.ts +707 -0
  42. package/dist/index-HaqfPtaL.d.ts.map +1 -0
  43. package/dist/index.d.mts +107 -981
  44. package/dist/index.d.mts.map +1 -1
  45. package/dist/index.d.ts +107 -981
  46. package/dist/index.d.ts.map +1 -1
  47. package/dist/index.js +73 -2308
  48. package/dist/index.mjs +5 -2240
  49. package/dist/index.mjs.map +1 -1
  50. package/dist/kya-http-error-codes-7ewV5RuK.d.mts +29 -0
  51. package/dist/kya-http-error-codes-7ewV5RuK.d.mts.map +1 -0
  52. package/dist/kya-http-error-codes-7ewV5RuK.d.ts +29 -0
  53. package/dist/kya-http-error-codes-7ewV5RuK.d.ts.map +1 -0
  54. package/dist/kya-http-error-codes-C2JiWPsi.mjs +73 -0
  55. package/dist/kya-http-error-codes-C2JiWPsi.mjs.map +1 -0
  56. package/dist/kya-http-error-codes-UYb1zpGM.js +83 -0
  57. package/dist/kya-http.d.mts +3 -0
  58. package/dist/kya-http.d.ts +3 -0
  59. package/dist/kya-http.js +11 -0
  60. package/dist/kya-http.mjs +4 -0
  61. package/dist/policy/enforcement.d.mts +2 -0
  62. package/dist/policy/enforcement.d.ts +2 -0
  63. package/dist/policy/enforcement.js +15 -0
  64. package/dist/policy/enforcement.mjs +3 -0
  65. package/dist/{posture-origins-Pn-ii-Pp.mjs → posture-origins-Ba83O0cD.mjs} +2 -2
  66. package/dist/posture-origins-Ba83O0cD.mjs.map +1 -0
  67. package/dist/{posture-origins-LFkX80oF.js → posture-origins-CdVOdiMT.js} +1 -1
  68. package/dist/registered-sid-D3g-gZQF.d.mts +11 -0
  69. package/dist/registered-sid-D3g-gZQF.d.mts.map +1 -0
  70. package/dist/registered-sid-D3g-gZQF.d.ts +11 -0
  71. package/dist/registered-sid-D3g-gZQF.d.ts.map +1 -0
  72. package/dist/registered-sid-eLCNZvIF.js +170 -0
  73. package/dist/registered-sid-hUl-bvM5.mjs +142 -0
  74. package/dist/registered-sid-hUl-bvM5.mjs.map +1 -0
  75. package/dist/step-up-BjP--hG-.d.mts +114 -0
  76. package/dist/step-up-BjP--hG-.d.mts.map +1 -0
  77. package/dist/step-up-BjP--hG-.d.ts +114 -0
  78. package/dist/step-up-BjP--hG-.d.ts.map +1 -0
  79. package/dist/step-up-C2d8C20x.js +1697 -0
  80. package/dist/step-up-COlmWJN8.mjs +1513 -0
  81. package/dist/step-up-COlmWJN8.mjs.map +1 -0
  82. package/package.json +23 -1
  83. package/dist/posture-origins-Pn-ii-Pp.mjs.map +0 -1
@@ -14,8 +14,8 @@ declare const BrowserPostureSchema: ZodObject<{
14
14
  session_id: ZodGUID;
15
15
  binding: ZodString;
16
16
  verdict: ZodEnum<{
17
- human: "human";
18
17
  "agent-driven": "agent-driven";
18
+ human: "human";
19
19
  insufficient: "insufficient";
20
20
  }>;
21
21
  score: ZodNullable<ZodNumber>;
@@ -46,8 +46,8 @@ declare const BrowserPostureReportSchema: ZodObject<{
46
46
  projectId: ZodString;
47
47
  sessionId: ZodGUID;
48
48
  verdict: ZodEnum<{
49
- human: "human";
50
49
  "agent-driven": "agent-driven";
50
+ human: "human";
51
51
  insufficient: "insufficient";
52
52
  }>;
53
53
  score: ZodNullable<ZodNumber>;
@@ -84,8 +84,8 @@ declare const BrowserPostureReportIngestSchema: ZodObject<{
84
84
  projectId: ZodString;
85
85
  sessionId: ZodGUID;
86
86
  verdict: ZodEnum<{
87
- human: "human";
88
87
  "agent-driven": "agent-driven";
88
+ human: "human";
89
89
  insufficient: "insufficient";
90
90
  }>;
91
91
  scorerVersion: ZodNumber;
@@ -98,7 +98,7 @@ declare const BrowserPostureReportIngestSchema: ZodObject<{
98
98
  declare function browserPostureReport(posture: BrowserPosture): {
99
99
  projectId: string;
100
100
  sessionId: string;
101
- verdict: "human" | "agent-driven" | "insufficient";
101
+ verdict: "agent-driven" | "human" | "insufficient";
102
102
  score: number | null;
103
103
  scorerVersion: number;
104
104
  reasons: string[];
@@ -166,4 +166,4 @@ declare function postureRequiredScopes(config: BrowserPostureConfig, path: strin
166
166
  declare function validateBrowserPostureConfig(config: BrowserPostureConfig, projectId: string | undefined): void;
167
167
  //#endregion
168
168
  export { POSTURE_VERIFICATION_STATUSES as A, verifyBrowserPosture as C, BrowserPostureRejectionReason as D, BrowserPostureOutcomeSchema as E, POSTURE_TTL_SECONDS as F, postureCookieName as I, browserPostureReport as M, BrowserPosture as N, BrowserPostureReportIngestSchema as O, BrowserPostureSchema as P, validateBrowserPostureConfig as S, BrowserPostureOutcome as T, postureRequiredScopes as _, POSTURE_SESSION_HEADER as a, readPostureCookie as b, PostureVerification as c, inspectBrowserPosture as d, postureFromCookies as f, postureRequestFromHeaders as g, postureOutcomeReport as h, POSTURE_ISSUER as i, PostureVerificationStatus as j, BrowserPostureReportSchema as k, UNSIGNED_BROWSER_AGENT as l, postureOutcomeFromRequest as m, JWK$1 as n, POSTURE_TYPE as o, postureFromRequest as p, POSTURE_HEADER as r, PostureRequest as s, BrowserPostureConfig as t, behavioralConfidence as u, postureSessionBinding as v, BROWSER_POSTURE_REJECTION_REASONS as w, signBrowserPosture as x, postureUpgrade as y };
169
- //# sourceMappingURL=browser-posture-DIaVLuW3.d.ts.map
169
+ //# sourceMappingURL=browser-posture-B8YiPa5c.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"browser-posture-DIaVLuW3.d.ts","names":[],"sources":["../src/browser-posture-cookie.ts","../src/beacon-types/index.ts","../src/browser-posture-schema.ts","../src/browser-posture-report.ts","../src/browser-posture.ts"],"mappings":";;;iBAgBgB,kBAAkB;;;cC4jDrB;;;cC1kDA,sBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2C/B;KAGU,iBAAiB,cAAe;;;cC7C/B;KACD,oCAAoC;cAGnC,4BAA0B;;;;;;;;;;;;;;GAWrC;cAEW;KAaD,wCAAwC;cAEvC,6BAA2B;;;;;;;;;;;;;;;;;;;GAQpC;KACQ,wBAAwB,cAAe;cA2BtC,kCAAgC;;;;;;;;;;;;;;GAE3C;iBAEc,qBAAqB,SAAS;;;;;;;;;;;;;cClDjC;;;;;cAKA,uBAAwB;UAG3B;EACR;EACA;EACA;EACA;EACA;EACA;;iBAGc,eAAe,SAAS,iBAAiB;cAyC5C;cAGA;UAEI;EAEf,WAAW;EACX;EAEA;EACA;EACA;EAEA,kBAAkB;IAAQ;IAAc;;;iBAI1B,kBACd,mCACA;iBAcoB,sBAAsB,oBAAoB;iBAc1C,mBACpB,SAAS,gBACT,YAAY,KACZ,gBACC;KAqBS;EACN;EAAoB,SAAS;;EAC7B;;EACA;EAAoB,QAAQ;;cAOrB,uBAAwB,SAAS,wBAAsB;iBAM9C,sBACpB,2BACA,QAAQ,sBACR,mBACA,sCACA,eACC,QAAQ;iBA2EW,qBACpB,2BACA,QAAQ,sBACR,mBACA,sCACA,eACC,QAAQ;cAYE;cACA;UAGI;EACf;EAEA;EAEA;;iBAIc,0BACd,MAAM,iEACL;iBA6BmB,0BACpB,SAAS,gBACT,QAAQ,sBACR,mBACA,eACC,QAAQ;iBAcW,mBACpB,SAAS,gBACT,QAAQ,sBACR,mBACA,eACC,QAAQ;iBAIW,mBACpB,mCACA,QAAQ,sBACR,oBACC,QAAQ;iBAKK,sBACd,QAAQ,sBACR;iBAmBc,6BACd,QAAQ,sBACR"}
1
+ {"version":3,"file":"browser-posture-B8YiPa5c.d.ts","names":[],"sources":["../src/browser-posture-cookie.ts","../src/beacon-types/index.ts","../src/browser-posture-schema.ts","../src/browser-posture-report.ts","../src/browser-posture.ts"],"mappings":";;;iBAgBgB,kBAAkB;;;cC4jDrB;;;cC1kDA,sBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2C/B;KAGU,iBAAiB,cAAe;;;cC7C/B;KACD,oCAAoC;cAGnC,4BAA0B;;;;;;;;;;;;;;GAWrC;cAEW;KAaD,wCAAwC;cAEvC,6BAA2B;;;;;;;;;;;;;;;;;;;GAQpC;KACQ,wBAAwB,cAAe;cA2BtC,kCAAgC;;;;;;;;;;;;;;GAE3C;iBAEc,qBAAqB,SAAS;;;;;;;;;;;;;cClDjC;;;;;cAKA,uBAAwB;UAG3B;EACR;EACA;EACA;EACA;EACA;EACA;;iBAGc,eAAe,SAAS,iBAAiB;cAyC5C;cAGA;UAEI;EAEf,WAAW;EACX;EAEA;EACA;EACA;EAEA,kBAAkB;IAAQ;IAAc;;;iBAI1B,kBACd,mCACA;iBAcoB,sBAAsB,oBAAoB;iBAc1C,mBACpB,SAAS,gBACT,YAAY,KACZ,gBACC;KAqBS;EACN;EAAoB,SAAS;;EAC7B;;EACA;EAAoB,QAAQ;;cAOrB,uBAAwB,SAAS,wBAAsB;iBAM9C,sBACpB,2BACA,QAAQ,sBACR,mBACA,sCACA,eACC,QAAQ;iBA2EW,qBACpB,2BACA,QAAQ,sBACR,mBACA,sCACA,eACC,QAAQ;cAYE;cACA;UAGI;EACf;EAEA;EAEA;;iBAIc,0BACd,MAAM,iEACL;iBA6BmB,0BACpB,SAAS,gBACT,QAAQ,sBACR,mBACA,eACC,QAAQ;iBAcW,mBACpB,SAAS,gBACT,QAAQ,sBACR,mBACA,eACC,QAAQ;iBAIW,mBACpB,mCACA,QAAQ,sBACR,oBACC,QAAQ;iBAKK,sBACd,QAAQ,sBACR;iBAmBc,6BACd,QAAQ,sBACR"}
@@ -14,8 +14,8 @@ declare const BrowserPostureSchema: ZodObject<{
14
14
  session_id: ZodGUID;
15
15
  binding: ZodString;
16
16
  verdict: ZodEnum<{
17
- human: "human";
18
17
  "agent-driven": "agent-driven";
18
+ human: "human";
19
19
  insufficient: "insufficient";
20
20
  }>;
21
21
  score: ZodNullable<ZodNumber>;
@@ -46,8 +46,8 @@ declare const BrowserPostureReportSchema: ZodObject<{
46
46
  projectId: ZodString;
47
47
  sessionId: ZodGUID;
48
48
  verdict: ZodEnum<{
49
- human: "human";
50
49
  "agent-driven": "agent-driven";
50
+ human: "human";
51
51
  insufficient: "insufficient";
52
52
  }>;
53
53
  score: ZodNullable<ZodNumber>;
@@ -84,8 +84,8 @@ declare const BrowserPostureReportIngestSchema: ZodObject<{
84
84
  projectId: ZodString;
85
85
  sessionId: ZodGUID;
86
86
  verdict: ZodEnum<{
87
- human: "human";
88
87
  "agent-driven": "agent-driven";
88
+ human: "human";
89
89
  insufficient: "insufficient";
90
90
  }>;
91
91
  scorerVersion: ZodNumber;
@@ -98,7 +98,7 @@ declare const BrowserPostureReportIngestSchema: ZodObject<{
98
98
  declare function browserPostureReport(posture: BrowserPosture): {
99
99
  projectId: string;
100
100
  sessionId: string;
101
- verdict: "human" | "agent-driven" | "insufficient";
101
+ verdict: "agent-driven" | "human" | "insufficient";
102
102
  score: number | null;
103
103
  scorerVersion: number;
104
104
  reasons: string[];
@@ -166,4 +166,4 @@ declare function postureRequiredScopes(config: BrowserPostureConfig, path: strin
166
166
  declare function validateBrowserPostureConfig(config: BrowserPostureConfig, projectId: string | undefined): void;
167
167
  //#endregion
168
168
  export { POSTURE_VERIFICATION_STATUSES as A, verifyBrowserPosture as C, BrowserPostureRejectionReason as D, BrowserPostureOutcomeSchema as E, POSTURE_TTL_SECONDS as F, postureCookieName as I, browserPostureReport as M, BrowserPosture as N, BrowserPostureReportIngestSchema as O, BrowserPostureSchema as P, validateBrowserPostureConfig as S, BrowserPostureOutcome as T, postureRequiredScopes as _, POSTURE_SESSION_HEADER as a, readPostureCookie as b, PostureVerification as c, inspectBrowserPosture as d, postureFromCookies as f, postureRequestFromHeaders as g, postureOutcomeReport as h, POSTURE_ISSUER as i, PostureVerificationStatus as j, BrowserPostureReportSchema as k, UNSIGNED_BROWSER_AGENT as l, postureOutcomeFromRequest as m, JWK$1 as n, POSTURE_TYPE as o, postureFromRequest as p, POSTURE_HEADER as r, PostureRequest as s, BrowserPostureConfig as t, behavioralConfidence as u, postureSessionBinding as v, BROWSER_POSTURE_REJECTION_REASONS as w, signBrowserPosture as x, postureUpgrade as y };
169
- //# sourceMappingURL=browser-posture-BuChqmH5.d.mts.map
169
+ //# sourceMappingURL=browser-posture-BLhw-MON.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"browser-posture-BuChqmH5.d.mts","names":[],"sources":["../src/browser-posture-cookie.ts","../src/beacon-types/index.ts","../src/browser-posture-schema.ts","../src/browser-posture-report.ts","../src/browser-posture.ts"],"mappings":";;;iBAgBgB,kBAAkB;;;cC4jDrB;;;cC1kDA,sBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2C/B;KAGU,iBAAiB,cAAe;;;cC7C/B;KACD,oCAAoC;cAGnC,4BAA0B;;;;;;;;;;;;;;GAWrC;cAEW;KAaD,wCAAwC;cAEvC,6BAA2B;;;;;;;;;;;;;;;;;;;GAQpC;KACQ,wBAAwB,cAAe;cA2BtC,kCAAgC;;;;;;;;;;;;;;GAE3C;iBAEc,qBAAqB,SAAS;;;;;;;;;;;;;cClDjC;;;;;cAKA,uBAAwB;UAG3B;EACR;EACA;EACA;EACA;EACA;EACA;;iBAGc,eAAe,SAAS,iBAAiB;cAyC5C;cAGA;UAEI;EAEf,WAAW;EACX;EAEA;EACA;EACA;EAEA,kBAAkB;IAAQ;IAAc;;;iBAI1B,kBACd,mCACA;iBAcoB,sBAAsB,oBAAoB;iBAc1C,mBACpB,SAAS,gBACT,YAAY,KACZ,gBACC;KAqBS;EACN;EAAoB,SAAS;;EAC7B;;EACA;EAAoB,QAAQ;;cAOrB,uBAAwB,SAAS,wBAAsB;iBAM9C,sBACpB,2BACA,QAAQ,sBACR,mBACA,sCACA,eACC,QAAQ;iBA2EW,qBACpB,2BACA,QAAQ,sBACR,mBACA,sCACA,eACC,QAAQ;cAYE;cACA;UAGI;EACf;EAEA;EAEA;;iBAIc,0BACd,MAAM,iEACL;iBA6BmB,0BACpB,SAAS,gBACT,QAAQ,sBACR,mBACA,eACC,QAAQ;iBAcW,mBACpB,SAAS,gBACT,QAAQ,sBACR,mBACA,eACC,QAAQ;iBAIW,mBACpB,mCACA,QAAQ,sBACR,oBACC,QAAQ;iBAKK,sBACd,QAAQ,sBACR;iBAmBc,6BACd,QAAQ,sBACR"}
1
+ {"version":3,"file":"browser-posture-BLhw-MON.d.mts","names":[],"sources":["../src/browser-posture-cookie.ts","../src/beacon-types/index.ts","../src/browser-posture-schema.ts","../src/browser-posture-report.ts","../src/browser-posture.ts"],"mappings":";;;iBAgBgB,kBAAkB;;;cC4jDrB;;;cC1kDA,sBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2C/B;KAGU,iBAAiB,cAAe;;;cC7C/B;KACD,oCAAoC;cAGnC,4BAA0B;;;;;;;;;;;;;;GAWrC;cAEW;KAaD,wCAAwC;cAEvC,6BAA2B;;;;;;;;;;;;;;;;;;;GAQpC;KACQ,wBAAwB,cAAe;cA2BtC,kCAAgC;;;;;;;;;;;;;;GAE3C;iBAEc,qBAAqB,SAAS;;;;;;;;;;;;;cClDjC;;;;;cAKA,uBAAwB;UAG3B;EACR;EACA;EACA;EACA;EACA;EACA;;iBAGc,eAAe,SAAS,iBAAiB;cAyC5C;cAGA;UAEI;EAEf,WAAW;EACX;EAEA;EACA;EACA;EAEA,kBAAkB;IAAQ;IAAc;;;iBAI1B,kBACd,mCACA;iBAcoB,sBAAsB,oBAAoB;iBAc1C,mBACpB,SAAS,gBACT,YAAY,KACZ,gBACC;KAqBS;EACN;EAAoB,SAAS;;EAC7B;;EACA;EAAoB,QAAQ;;cAOrB,uBAAwB,SAAS,wBAAsB;iBAM9C,sBACpB,2BACA,QAAQ,sBACR,mBACA,sCACA,eACC,QAAQ;iBA2EW,qBACpB,2BACA,QAAQ,sBACR,mBACA,sCACA,eACC,QAAQ;cAYE;cACA;UAGI;EACf;EAEA;EAEA;;iBAIc,0BACd,MAAM,iEACL;iBA6BmB,0BACpB,SAAS,gBACT,QAAQ,sBACR,mBACA,eACC,QAAQ;iBAcW,mBACpB,SAAS,gBACT,QAAQ,sBACR,mBACA,eACC,QAAQ;iBAIW,mBACpB,mCACA,QAAQ,sBACR,oBACC,QAAQ;iBAKK,sBACd,QAAQ,sBACR;iBAmBc,6BACd,QAAQ,sBACR"}
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$/i;function t(t){if(!e.test(t)||t!==t.toLowerCase())throw Error(`Invalid posture project id`);return`__Host-checkpoint_posture_${t}`}exports.postureCookieName=t;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;function t(t){if(!e.test(t)||t!==t.toLowerCase())throw Error(`Invalid posture project id`);return`__Host-checkpoint_posture_${t}`}exports.postureCookieName=t;
@@ -1,2 +1,2 @@
1
- const e=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$/i;function t(t){if(!e.test(t)||t!==t.toLowerCase())throw Error(`Invalid posture project id`);return`__Host-checkpoint_posture_${t}`}export{t as postureCookieName};
1
+ const e=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;function t(t){if(!e.test(t)||t!==t.toLowerCase())throw Error(`Invalid posture project id`);return`__Host-checkpoint_posture_${t}`}export{t as postureCookieName};
2
2
  //# sourceMappingURL=browser-posture-cookie.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"browser-posture-cookie.mjs","names":[],"sources":["../src/constants/patterns.ts","../src/browser-posture-cookie.ts"],"sourcesContent":["/**\n * Regular Expression Patterns\n *\n * Common regex patterns used for validation and detection\n */\n\n/**\n * Validation Patterns\n */\n// Hoisted out of the object literal below so bundle-size-critical leaves can\n// import JUST this one pattern. `VALIDATION_PATTERNS` re-exports it, so there\n// is still exactly one definition and no drift.\n//\n// Why it matters: rolldown (via tsdown) does not do property-level DCE on a\n// const object literal the way esbuild did. `browser-posture-cookie.ts` uses\n// only `.UUID`, but importing the whole object dragged every pattern —\n// ULID, SLUG, IPV4, IPV6 — into that leaf, taking it from 272 to 2,870 bytes.\n// The beacon inlines that leaf (`noExternal`), which pushed its gzipped\n// bundle from 29,337 to 30,123 against a 29,696-byte CI budget.\n//\n// UUID pattern: accepts versions 0-5 (0 is nil UUID, 1-5 are standard versions)\n// Variants: 0 (nil), 8-9-a-b (standard variants)\nexport const UUID_PATTERN =\n /^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$/i;\n\nexport const VALIDATION_PATTERNS = {\n // Identifiers\n UUID: UUID_PATTERN,\n ULID: /^[0-9A-HJKMNP-TV-Z]{26}$/,\n SLUG: /^[a-z0-9]+(?:-[a-z0-9]+)*$/,\n\n // Network\n IPV4: /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/,\n IPV6: /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,\n IP: /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$|^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/,\n // eslint-disable-next-line no-useless-escape\n // CIDR pattern: uses IPV4 pattern and restricts mask to 0-32\n CIDR: /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\/(?:[0-9]|[12][0-9]|3[0-2])$/,\n // eslint-disable-next-line no-useless-escape\n DOMAIN: /^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\\.)*[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/i,\n HOSTNAME:\n /^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9-]*[A-Za-z0-9])$/,\n // eslint-disable-next-line no-useless-escape\n URL: /^https?:\\/\\/(www\\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)$/,\n\n // Contact\n // Email pattern: stricter validation (rejects consecutive dots, requires TLD)\n // Local part: alphanumeric start/end, dots allowed but not consecutive\n EMAIL:\n /^[a-zA-Z0-9](?:[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]|\\.(?!\\.))*[a-zA-Z0-9]?@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+$/,\n PHONE: /^[+]?[(]?[0-9]{3}[)]?[-\\s.]?[0-9]{3}[-\\s.]?[0-9]{4,6}$/,\n\n // Security\n // JWT pattern: requires 3 parts (header.payload.signature) - signature cannot be empty\n JWT: /^[A-Za-z0-9-_]+\\.[A-Za-z0-9-_]+\\.[A-Za-z0-9-_]+$/,\n // eslint-disable-next-line no-useless-escape\n BASE64: /^[A-Za-z0-9+\\/]*={0,2}$/,\n HEX: /^[0-9a-fA-F]+$/,\n MD5: /^[a-f0-9]{32}$/i,\n SHA1: /^[a-f0-9]{40}$/i,\n SHA256: /^[a-f0-9]{64}$/i,\n\n // Versions\n SEMVER:\n /^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$/,\n\n // Files\n FILENAME: /^[a-zA-Z0-9](?:[a-zA-Z0-9 ._-]*[a-zA-Z0-9])?\\.[a-zA-Z0-9_-]+$/,\n PATH: /^(\\/[^/ ]*)+\\/?$/,\n\n // Keys\n API_KEY: /^[A-Za-z0-9_-]{32,}$/,\n SECRET_KEY: /^[A-Za-z0-9_-]{64,}$/,\n PIXEL_ID: /^px_[A-Za-z0-9]{16}$/,\n} as const;\n\n/**\n * User Agent Patterns for Agent Detection\n */\nexport const USER_AGENT_PATTERNS = {\n // AI Agents\n OPENAI: /(?:GPTBot|ChatGPT-User|OpenAI)/i,\n ANTHROPIC: /(?:Claude-Web|Claude-User|anthropic-ai|claude-web|claude-user|ClaudeBot)/i,\n PERPLEXITY: /(?:PerplexityBot|Perplexica)/i,\n GOOGLE_AI: /(?:Bard|Google-InspectionTool)/i,\n MICROSOFT_AI: /(?:BingPreview\\/.*ChatGPT|Copilot)/i,\n\n // Search Bots\n GOOGLEBOT: /Googlebot/i,\n BINGBOT: /(?:bingbot|BingPreview|msnbot)/i,\n DUCKDUCKBOT: /DuckDuckBot/i,\n BAIDUBOT: /Baiduspider/i,\n YANDEXBOT: /YandexBot/i,\n\n // Social Media Bots\n FACEBOOK: /(?:facebookexternalhit|facebookcatalog)/i,\n TWITTER: /(?:Twitterbot|TwitterImageProxy)/i,\n LINKEDIN: /LinkedInBot/i,\n WHATSAPP: /WhatsApp/i,\n TELEGRAM: /TelegramBot/i,\n DISCORD: /Discordbot/i,\n SLACK: /Slackbot/i,\n\n // Crawlers and Scrapers\n GENERIC_BOT: /(?:bot|crawler|spider|scraper|agent)/i,\n SCRAPY: /Scrapy/i,\n PUPPETEER: /(?:HeadlessChrome|Puppeteer)/i,\n PLAYWRIGHT: /Playwright/i,\n SELENIUM: /(?:selenium|webdriver)/i,\n\n // Development Tools\n POSTMAN: /PostmanRuntime/i,\n INSOMNIA: /insomnia/i,\n CURL: /curl/i,\n WGET: /Wget/i,\n HTTPIE: /HTTPie/i,\n\n // Monitoring Services\n UPTIMEROBOT: /UptimeRobot/i,\n PINGDOM: /Pingdom/i,\n NEWRELIC: /NewRelicPinger/i,\n DATADOG: /Datadog/i,\n} as const;\n\n/**\n * Header Patterns for Agent Detection\n */\nexport const HEADER_PATTERNS = {\n // AI-specific headers\n AI_HEADERS: /^(?:X-(?:OpenAI|Anthropic|AI|Bot|Agent|LLM))/i,\n\n // Automation headers\n AUTOMATION_HEADERS: /^(?:X-(?:Automated|Robot|Crawler|Scraper))/i,\n\n // Missing standard headers\n MISSING_ACCEPT: /^$/,\n MISSING_ACCEPT_LANGUAGE: /^$/,\n MISSING_ACCEPT_ENCODING: /^$/,\n\n // Suspicious patterns\n GENERIC_ACCEPT: /^\\*\\/\\*$/,\n NO_COOKIES: /^$/,\n\n // Known proxy headers\n PROXY_HEADERS: /^(?:X-Forwarded-|X-Real-IP|X-Originating-IP|Via|Forwarded)/i,\n\n // Cloud provider headers\n CLOUD_HEADERS: /^(?:X-(?:AWS|Azure|GCP|Cloudflare))/i,\n} as const;\n\n/**\n * Browser Patterns\n */\nexport const BROWSER_PATTERNS = {\n CHROME: /Chrome\\/([0-9.]+)/,\n FIREFOX: /Firefox\\/([0-9.]+)/,\n SAFARI: /Version\\/([0-9.]+).*Safari/,\n EDGE: /Edg\\/([0-9.]+)/,\n OPERA: /OPR\\/([0-9.]+)/,\n IE: /MSIE ([0-9.]+)/,\n} as const;\n\n/**\n * Operating System Patterns\n */\nexport const OS_PATTERNS = {\n WINDOWS: /Windows NT ([0-9.]+)/,\n MACOS: /Mac OS X ([0-9_]+)/,\n LINUX: /Linux/,\n ANDROID: /Android ([0-9.]+)/,\n IOS: /OS ([0-9_]+) like Mac OS X/,\n} as const;\n\n/**\n * Mobile Device Patterns\n */\nexport const MOBILE_PATTERNS = {\n MOBILE: /(?:Mobile|Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini)/i,\n TABLET: /(?:iPad|Android.*Tablet|Tablet.*Android|Kindle|Silk)/i,\n DESKTOP: /(?:Windows NT|Mac OS X|Linux|CrOS)/i,\n} as const;\n\n/**\n * Suspicious Behavior Patterns\n */\nexport const SUSPICIOUS_PATTERNS = {\n // Rapid requests\n RAPID_REQUESTS: /^[0-9]{1,3}$/,\n\n // Sequential access\n SEQUENTIAL_URLS: /\\?(?:page|offset|id)=[0-9]+/,\n\n // Data extraction\n API_ENDPOINTS: /\\/api\\/|\\.json$|\\.xml$/i,\n\n // Form submission without interaction\n DIRECT_POST: /^POST$/,\n\n // Known attack patterns\n SQL_INJECTION:\n /(?:union|select|insert|update|delete|drop|create|alter|exec|script|javascript|onerror|onload|eval|src=)/i,\n XSS_ATTEMPT: /(?:<script|javascript:|onerror=|onclick=|<iframe|<embed|<object)/i,\n PATH_TRAVERSAL: /(?:\\.\\.\\/|\\.\\.\\\\|%2e%2e%2f|%252e%252e%252f)/i,\n\n // Encoding attempts\n URL_ENCODED: /%[0-9a-f]{2}/i,\n BASE64_DATA: /data:[^;]+;base64,/i,\n} as const;\n\n/**\n * Maximum input length for pattern matching. UAs, header values, and\n * detection payloads are bounded in practice (<4KB even for the most\n * verbose Chrome/Firefox UAs). Caps worst-case complexity for any\n * polynomial-shaped pattern an external caller might supply to\n * `testPattern` / `extractMatch`; CodeQL flagged the unbounded path\n * (js/polynomial-redos) on PR #2576.\n */\nconst MAX_PATTERN_INPUT_LENGTH = 4096;\n\n/**\n * Helper function to test a pattern. Returns `false` on inputs longer\n * than {@link MAX_PATTERN_INPUT_LENGTH} — an abuse signal we'd rather\n * reject than process.\n */\nexport function testPattern(pattern: RegExp, value: string): boolean {\n if (value.length > MAX_PATTERN_INPUT_LENGTH) return false;\n return pattern.test(value);\n}\n\n/**\n * Helper function to extract match from pattern. Returns `null` on\n * over-long inputs (same ReDoS defense as `testPattern`).\n */\nexport function extractMatch(pattern: RegExp, value: string): string | null {\n if (value.length > MAX_PATTERN_INPUT_LENGTH) return null;\n const match = value.match(pattern);\n return match ? match[1] || match[0] : null;\n}\n\n/**\n * Helper function to test multiple patterns\n */\nexport function testPatterns(patterns: RegExp[], value: string): boolean {\n return patterns.some((pattern) => testPattern(pattern, value));\n}\n\n/**\n * Helper function to find matching pattern\n */\nexport function findMatchingPattern(\n patterns: Record<string, RegExp>,\n value: string\n): string | null {\n for (const [name, pattern] of Object.entries(patterns)) {\n if (testPattern(pattern, value)) {\n return name;\n }\n }\n return null;\n}\n","// Imports the single hoisted pattern, not the whole `VALIDATION_PATTERNS`\n// object — same definition, but it keeps this leaf actually dependency-free\n// under rolldown, which does not property-shake object literals.\nimport { UUID_PATTERN } from './constants/patterns';\n\n/**\n * The browser-posture cookie name. Kept in its own dependency-free leaf so the\n * beacon (bundle-size budgeted, no `jose`) derives the name from the SAME\n * function every SDK reader uses via `./browser-posture`; two independent\n * derivations of this name is exactly the drift that dropped the cookie.\n *\n * The lowercase UUID only: the issuer signs `project_id` as the database's\n * lowercase project UUID and cookie names compare case-sensitively, so a\n * friendly id, or the same UUID in upper case, can never name a cookie a\n * reader will look for.\n */\nexport function postureCookieName(projectId: string): string {\n if (!UUID_PATTERN.test(projectId) || projectId !== projectId.toLowerCase())\n throw new Error('Invalid posture project id');\n return `__Host-checkpoint_posture_${projectId}`;\n}\n"],"mappings":"AAsBA,MAAa,EACX,8ECPF,SAAgB,EAAkB,EAA2B,CAC3D,GAAI,CAAC,EAAa,KAAK,CAAS,GAAK,IAAc,EAAU,YAAY,EACvE,MAAU,MAAM,4BAA4B,EAC9C,MAAO,6BAA6B,GACtC"}
1
+ {"version":3,"file":"browser-posture-cookie.mjs","names":[],"sources":["../src/constants/patterns.ts","../src/browser-posture-cookie.ts"],"sourcesContent":["/**\n * Regular Expression Patterns\n *\n * Common regex patterns used for validation and detection\n */\n\n/**\n * Validation Patterns\n */\n// Hoisted out of the object literal below so bundle-size-critical leaves can\n// import JUST this one pattern. `VALIDATION_PATTERNS` re-exports it, so there\n// is still exactly one definition and no drift.\n//\n// Why it matters: rolldown (via tsdown) does not do property-level DCE on a\n// const object literal the way esbuild did. `browser-posture-cookie.ts` uses\n// only `.UUID`, but importing the whole object dragged every pattern —\n// ULID, SLUG, IPV4, IPV6 — into that leaf, taking it from 272 to 2,870 bytes.\nexport const UUID_PATTERN =\n /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;\n\nexport const VALIDATION_PATTERNS = {\n // Identifiers\n UUID: UUID_PATTERN,\n ULID: /^[0-9A-HJKMNP-TV-Z]{26}$/,\n SLUG: /^[a-z0-9]+(?:-[a-z0-9]+)*$/,\n\n // Network\n IPV4: /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/,\n IPV6: /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,\n IP: /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$|^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/,\n // eslint-disable-next-line no-useless-escape\n // CIDR pattern: uses IPV4 pattern and restricts mask to 0-32\n CIDR: /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\/(?:[0-9]|[12][0-9]|3[0-2])$/,\n // eslint-disable-next-line no-useless-escape\n DOMAIN: /^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\\.)*[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/i,\n HOSTNAME:\n /^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9-]*[A-Za-z0-9])$/,\n // eslint-disable-next-line no-useless-escape\n URL: /^https?:\\/\\/(www\\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)$/,\n\n // Contact\n // Email pattern: stricter validation (rejects consecutive dots, requires TLD)\n // Local part: alphanumeric start/end, dots allowed but not consecutive\n EMAIL:\n /^[a-zA-Z0-9](?:[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]|\\.(?!\\.))*[a-zA-Z0-9]?@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+$/,\n PHONE: /^[+]?[(]?[0-9]{3}[)]?[-\\s.]?[0-9]{3}[-\\s.]?[0-9]{4,6}$/,\n\n // Security\n // JWT pattern: requires 3 parts (header.payload.signature) - signature cannot be empty\n JWT: /^[A-Za-z0-9-_]+\\.[A-Za-z0-9-_]+\\.[A-Za-z0-9-_]+$/,\n // eslint-disable-next-line no-useless-escape\n BASE64: /^[A-Za-z0-9+\\/]*={0,2}$/,\n HEX: /^[0-9a-fA-F]+$/,\n MD5: /^[a-f0-9]{32}$/i,\n SHA1: /^[a-f0-9]{40}$/i,\n SHA256: /^[a-f0-9]{64}$/i,\n\n // Versions\n SEMVER:\n /^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$/,\n\n // Files\n FILENAME: /^[a-zA-Z0-9](?:[a-zA-Z0-9 ._-]*[a-zA-Z0-9])?\\.[a-zA-Z0-9_-]+$/,\n PATH: /^(\\/[^/ ]*)+\\/?$/,\n\n // Keys\n API_KEY: /^[A-Za-z0-9_-]{32,}$/,\n SECRET_KEY: /^[A-Za-z0-9_-]{64,}$/,\n PIXEL_ID: /^px_[A-Za-z0-9]{16}$/,\n} as const;\n\n/**\n * User Agent Patterns for Agent Detection\n */\nexport const USER_AGENT_PATTERNS = {\n // AI Agents\n OPENAI: /(?:GPTBot|ChatGPT-User|OpenAI)/i,\n ANTHROPIC: /(?:Claude-Web|Claude-User|anthropic-ai|claude-web|claude-user|ClaudeBot)/i,\n PERPLEXITY: /(?:PerplexityBot|Perplexica)/i,\n GOOGLE_AI: /(?:Bard|Google-InspectionTool)/i,\n MICROSOFT_AI: /(?:BingPreview\\/.*ChatGPT|Copilot)/i,\n\n // Search Bots\n GOOGLEBOT: /Googlebot/i,\n BINGBOT: /(?:bingbot|BingPreview|msnbot)/i,\n DUCKDUCKBOT: /DuckDuckBot/i,\n BAIDUBOT: /Baiduspider/i,\n YANDEXBOT: /YandexBot/i,\n\n // Social Media Bots\n FACEBOOK: /(?:facebookexternalhit|facebookcatalog)/i,\n TWITTER: /(?:Twitterbot|TwitterImageProxy)/i,\n LINKEDIN: /LinkedInBot/i,\n WHATSAPP: /WhatsApp/i,\n TELEGRAM: /TelegramBot/i,\n DISCORD: /Discordbot/i,\n SLACK: /Slackbot/i,\n\n // Crawlers and Scrapers\n GENERIC_BOT: /(?:bot|crawler|spider|scraper|agent)/i,\n SCRAPY: /Scrapy/i,\n PUPPETEER: /(?:HeadlessChrome|Puppeteer)/i,\n PLAYWRIGHT: /Playwright/i,\n SELENIUM: /(?:selenium|webdriver)/i,\n\n // Development Tools\n POSTMAN: /PostmanRuntime/i,\n INSOMNIA: /insomnia/i,\n CURL: /curl/i,\n WGET: /Wget/i,\n HTTPIE: /HTTPie/i,\n\n // Monitoring Services\n UPTIMEROBOT: /UptimeRobot/i,\n PINGDOM: /Pingdom/i,\n NEWRELIC: /NewRelicPinger/i,\n DATADOG: /Datadog/i,\n} as const;\n\n/**\n * Header Patterns for Agent Detection\n */\nexport const HEADER_PATTERNS = {\n // AI-specific headers\n AI_HEADERS: /^(?:X-(?:OpenAI|Anthropic|AI|Bot|Agent|LLM))/i,\n\n // Automation headers\n AUTOMATION_HEADERS: /^(?:X-(?:Automated|Robot|Crawler|Scraper))/i,\n\n // Missing standard headers\n MISSING_ACCEPT: /^$/,\n MISSING_ACCEPT_LANGUAGE: /^$/,\n MISSING_ACCEPT_ENCODING: /^$/,\n\n // Suspicious patterns\n GENERIC_ACCEPT: /^\\*\\/\\*$/,\n NO_COOKIES: /^$/,\n\n // Known proxy headers\n PROXY_HEADERS: /^(?:X-Forwarded-|X-Real-IP|X-Originating-IP|Via|Forwarded)/i,\n\n // Cloud provider headers\n CLOUD_HEADERS: /^(?:X-(?:AWS|Azure|GCP|Cloudflare))/i,\n} as const;\n\n/**\n * Browser Patterns\n */\nexport const BROWSER_PATTERNS = {\n CHROME: /Chrome\\/([0-9.]+)/,\n FIREFOX: /Firefox\\/([0-9.]+)/,\n SAFARI: /Version\\/([0-9.]+).*Safari/,\n EDGE: /Edg\\/([0-9.]+)/,\n OPERA: /OPR\\/([0-9.]+)/,\n IE: /MSIE ([0-9.]+)/,\n} as const;\n\n/**\n * Operating System Patterns\n */\nexport const OS_PATTERNS = {\n WINDOWS: /Windows NT ([0-9.]+)/,\n MACOS: /Mac OS X ([0-9_]+)/,\n LINUX: /Linux/,\n ANDROID: /Android ([0-9.]+)/,\n IOS: /OS ([0-9_]+) like Mac OS X/,\n} as const;\n\n/**\n * Mobile Device Patterns\n */\nexport const MOBILE_PATTERNS = {\n MOBILE: /(?:Mobile|Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini)/i,\n TABLET: /(?:iPad|Android.*Tablet|Tablet.*Android|Kindle|Silk)/i,\n DESKTOP: /(?:Windows NT|Mac OS X|Linux|CrOS)/i,\n} as const;\n\n/**\n * Suspicious Behavior Patterns\n */\nexport const SUSPICIOUS_PATTERNS = {\n // Rapid requests\n RAPID_REQUESTS: /^[0-9]{1,3}$/,\n\n // Sequential access\n SEQUENTIAL_URLS: /\\?(?:page|offset|id)=[0-9]+/,\n\n // Data extraction\n API_ENDPOINTS: /\\/api\\/|\\.json$|\\.xml$/i,\n\n // Form submission without interaction\n DIRECT_POST: /^POST$/,\n\n // Known attack patterns\n SQL_INJECTION:\n /(?:union|select|insert|update|delete|drop|create|alter|exec|script|javascript|onerror|onload|eval|src=)/i,\n XSS_ATTEMPT: /(?:<script|javascript:|onerror=|onclick=|<iframe|<embed|<object)/i,\n PATH_TRAVERSAL: /(?:\\.\\.\\/|\\.\\.\\\\|%2e%2e%2f|%252e%252e%252f)/i,\n\n // Encoding attempts\n URL_ENCODED: /%[0-9a-f]{2}/i,\n BASE64_DATA: /data:[^;]+;base64,/i,\n} as const;\n\n/**\n * Maximum input length for pattern matching. UAs, header values, and\n * detection payloads are bounded in practice (<4KB even for the most\n * verbose Chrome/Firefox UAs). Caps worst-case complexity for any\n * polynomial-shaped pattern an external caller might supply to\n * `testPattern` / `extractMatch`; CodeQL flagged the unbounded path\n * (js/polynomial-redos) on PR #2576.\n */\nconst MAX_PATTERN_INPUT_LENGTH = 4096;\n\n/**\n * Helper function to test a pattern. Returns `false` on inputs longer\n * than {@link MAX_PATTERN_INPUT_LENGTH} — an abuse signal we'd rather\n * reject than process.\n */\nexport function testPattern(pattern: RegExp, value: string): boolean {\n if (value.length > MAX_PATTERN_INPUT_LENGTH) return false;\n return pattern.test(value);\n}\n\n/**\n * Helper function to extract match from pattern. Returns `null` on\n * over-long inputs (same ReDoS defense as `testPattern`).\n */\nexport function extractMatch(pattern: RegExp, value: string): string | null {\n if (value.length > MAX_PATTERN_INPUT_LENGTH) return null;\n const match = value.match(pattern);\n return match ? match[1] || match[0] : null;\n}\n\n/**\n * Helper function to test multiple patterns\n */\nexport function testPatterns(patterns: RegExp[], value: string): boolean {\n return patterns.some((pattern) => testPattern(pattern, value));\n}\n\n/**\n * Helper function to find matching pattern\n */\nexport function findMatchingPattern(\n patterns: Record<string, RegExp>,\n value: string\n): string | null {\n for (const [name, pattern] of Object.entries(patterns)) {\n if (testPattern(pattern, value)) {\n return name;\n }\n }\n return null;\n}\n","// Imports the single hoisted pattern, not the whole `VALIDATION_PATTERNS`\n// object — same definition, but it keeps this leaf actually dependency-free\n// under rolldown, which does not property-shake object literals.\nimport { UUID_PATTERN } from './constants/patterns';\n\n/**\n * The browser-posture cookie name. Kept in its own dependency-free leaf so the\n * beacon (bundle-size budgeted, no `jose`) derives the name from the SAME\n * function every SDK reader uses via `./browser-posture`; two independent\n * derivations of this name is exactly the drift that dropped the cookie.\n *\n * The lowercase UUID only: the issuer signs `project_id` as the database's\n * lowercase project UUID and cookie names compare case-sensitively, so a\n * friendly id, or the same UUID in upper case, can never name a cookie a\n * reader will look for.\n */\nexport function postureCookieName(projectId: string): string {\n if (!UUID_PATTERN.test(projectId) || projectId !== projectId.toLowerCase())\n throw new Error('Invalid posture project id');\n return `__Host-checkpoint_posture_${projectId}`;\n}\n"],"mappings":"AAiBA,MAAa,EACX,6ECFF,SAAgB,EAAkB,EAA2B,CAC3D,GAAI,CAAC,EAAa,KAAK,CAAS,GAAK,IAAc,EAAU,YAAY,EACvE,MAAU,MAAM,4BAA4B,EAC9C,MAAO,6BAA6B,GACtC"}
@@ -1,5 +1,5 @@
1
1
  import { E as ZodObject, L as output, T as ZodNumber, V as $strip, j as ZodString, t as external_d_exports } from "./external-B7WI9FyQ.mjs";
2
- import { N as BrowserPosture } from "./browser-posture-BuChqmH5.mjs";
2
+ import { N as BrowserPosture } from "./browser-posture-BLhw-MON.mjs";
3
3
  //#region src/browser-posture-proof.d.ts
4
4
  export declare const POSTURE_PROOF_TYPE = "dpop+jwt";
5
5
  export declare const DEFAULT_POSTURE_PROOF_MAX_AGE_SECONDS = 60;
@@ -1 +1 @@
1
- {"version":3,"file":"browser-posture-proof.d.mts","names":[],"sources":["../src/browser-posture-proof.ts"],"mappings":";;;qBAYa;qBAKA;qBAEA,2BAAyB;;;;;GAKpC;YACU,sBAAsB,cAAe;wBAgB3B,0BACpB,8BACA,SAAS,gBACT;EAAW;EAAgB;GAC3B,cACA,yBACC,QAAQ"}
1
+ {"version":3,"file":"browser-posture-proof.d.mts","names":[],"sources":["../src/browser-posture-proof.ts"],"mappings":";;;qBAaa;qBAKA;qBAEA,2BAAyB;;;;;GAKpC;YACU,sBAAsB,cAAe;wBAgB3B,0BACpB,8BACA,SAAS,gBACT;EAAW;EAAgB;GAC3B,cACA,yBACC,QAAQ"}
@@ -1,5 +1,5 @@
1
1
  import { E as ZodObject, L as output, T as ZodNumber, V as $strip, j as ZodString, t as external_d_exports } from "./external-B7WI9FyQ.js";
2
- import { N as BrowserPosture } from "./browser-posture-DIaVLuW3.js";
2
+ import { N as BrowserPosture } from "./browser-posture-B8YiPa5c.js";
3
3
  //#region src/browser-posture-proof.d.ts
4
4
  export declare const POSTURE_PROOF_TYPE = "dpop+jwt";
5
5
  export declare const DEFAULT_POSTURE_PROOF_MAX_AGE_SECONDS = 60;
@@ -1 +1 @@
1
- {"version":3,"file":"browser-posture-proof.d.ts","names":[],"sources":["../src/browser-posture-proof.ts"],"mappings":";;;qBAYa;qBAKA;qBAEA,2BAAyB;;;;;GAKpC;YACU,sBAAsB,cAAe;wBAgB3B,0BACpB,8BACA,SAAS,gBACT;EAAW;EAAgB;GAC3B,cACA,yBACC,QAAQ"}
1
+ {"version":3,"file":"browser-posture-proof.d.ts","names":[],"sources":["../src/browser-posture-proof.ts"],"mappings":";;;qBAaa;qBAKA;qBAEA,2BAAyB;;;;;GAKpC;YACU,sBAAsB,cAAe;wBAgB3B,0BACpB,8BACA,SAAS,gBACT;EAAW;EAAgB;GAC3B,cACA,yBACC,QAAQ"}
@@ -2,6 +2,47 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_schemas = require('./schemas-YhagYDx_.js');
3
3
  let jose = require("jose");
4
4
 
5
+ //#region src/utils/base64url.ts
6
+ /**
7
+ * Base64url (RFC 4648 § 5) built on `atob` and `btoa` rather than Node's
8
+ * buffer API, so it runs on every runtime the SDKs support, Cloudflare Workers
9
+ * without `nodejs_compat` included.
10
+ */
11
+ const BASE64URL_UNPADDED = /^[A-Za-z0-9_-]*$/;
12
+ const PADDING = 61;
13
+ /**
14
+ * `text` without its trailing `=` padding. A backward scan, not
15
+ * `replace(/=+$/, '')`: that regex retries from every `=` in a long run that
16
+ * does not reach the end, which is quadratic on hostile input.
17
+ */
18
+ function withoutPadding(text) {
19
+ let end = text.length;
20
+ while (end > 0 && text.charCodeAt(end - 1) === PADDING) end -= 1;
21
+ return text.slice(0, end);
22
+ }
23
+ /**
24
+ * Decode base64url, with or without `=` padding.
25
+ *
26
+ * Strict where Node's buffer decoder is lenient: a character outside the
27
+ * alphabet, or a length no encoder produces (one character past a multiple of
28
+ * four), throws a `TypeError` instead of being skipped or truncated. This
29
+ * matches the engine's decoder.
30
+ */
31
+ function base64UrlToBytes(text) {
32
+ const unpadded = withoutPadding(text);
33
+ if (!BASE64URL_UNPADDED.test(unpadded) || unpadded.length % 4 === 1) throw new TypeError("not valid base64url (RFC 4648 § 5)");
34
+ const base64 = unpadded.replace(/-/g, "+").replace(/_/g, "/");
35
+ const binary = atob(base64 + "=".repeat((4 - base64.length % 4) % 4));
36
+ const bytes = new Uint8Array(binary.length);
37
+ for (let index = 0; index < binary.length; index += 1) bytes[index] = binary.charCodeAt(index);
38
+ return bytes;
39
+ }
40
+ /** Decode base64url to a string as UTF-8, replacing invalid sequences with U+FFFD. */
41
+ function base64UrlToString(text) {
42
+ return new TextDecoder().decode(base64UrlToBytes(text));
43
+ }
44
+
45
+ //#endregion
5
46
  //#region src/browser-posture-proof.ts
6
47
  /**
7
48
  * RFC 9449 DPoP-shaped proof verification (P37): binds a browser-posture
@@ -40,7 +81,7 @@ const BrowserPostureProofSchema = require_schemas.object({
40
81
  async function verifyBrowserPostureProof(proofJws, posture, request, now = Math.floor(Date.now() / 1e3), maxAgeSeconds = 60) {
41
82
  if (!proofJws || proofJws.length > 2e3 || !posture.cnf) return void 0;
42
83
  try {
43
- const decoded = JSON.parse(Buffer.from(proofJws.split(".")[0], "base64url").toString("utf8"));
84
+ const decoded = JSON.parse(base64UrlToString(proofJws.split(".")[0]));
44
85
  if (decoded.typ !== "dpop+jwt" || decoded.alg !== "ES256" || !decoded.jwk || decoded.jwk.kty !== "EC" || decoded.jwk.crv !== "P-256" || decoded.jwk.d) return void 0;
45
86
  if (await (0, jose.calculateJwkThumbprint)(decoded.jwk, "sha256") !== posture.cnf.jkt) return void 0;
46
87
  const key = await (0, jose.importJWK)(decoded.jwk, "ES256");
@@ -1,6 +1,47 @@
1
1
  import { C as string, v as number, y as object } from "./schemas-7qodsG-Z.mjs";
2
2
  import { calculateJwkThumbprint, importJWK, jwtVerify } from "jose";
3
3
 
4
+ //#region src/utils/base64url.ts
5
+ /**
6
+ * Base64url (RFC 4648 § 5) built on `atob` and `btoa` rather than Node's
7
+ * buffer API, so it runs on every runtime the SDKs support, Cloudflare Workers
8
+ * without `nodejs_compat` included.
9
+ */
10
+ const BASE64URL_UNPADDED = /^[A-Za-z0-9_-]*$/;
11
+ const PADDING = 61;
12
+ /**
13
+ * `text` without its trailing `=` padding. A backward scan, not
14
+ * `replace(/=+$/, '')`: that regex retries from every `=` in a long run that
15
+ * does not reach the end, which is quadratic on hostile input.
16
+ */
17
+ function withoutPadding(text) {
18
+ let end = text.length;
19
+ while (end > 0 && text.charCodeAt(end - 1) === PADDING) end -= 1;
20
+ return text.slice(0, end);
21
+ }
22
+ /**
23
+ * Decode base64url, with or without `=` padding.
24
+ *
25
+ * Strict where Node's buffer decoder is lenient: a character outside the
26
+ * alphabet, or a length no encoder produces (one character past a multiple of
27
+ * four), throws a `TypeError` instead of being skipped or truncated. This
28
+ * matches the engine's decoder.
29
+ */
30
+ function base64UrlToBytes(text) {
31
+ const unpadded = withoutPadding(text);
32
+ if (!BASE64URL_UNPADDED.test(unpadded) || unpadded.length % 4 === 1) throw new TypeError("not valid base64url (RFC 4648 § 5)");
33
+ const base64 = unpadded.replace(/-/g, "+").replace(/_/g, "/");
34
+ const binary = atob(base64 + "=".repeat((4 - base64.length % 4) % 4));
35
+ const bytes = new Uint8Array(binary.length);
36
+ for (let index = 0; index < binary.length; index += 1) bytes[index] = binary.charCodeAt(index);
37
+ return bytes;
38
+ }
39
+ /** Decode base64url to a string as UTF-8, replacing invalid sequences with U+FFFD. */
40
+ function base64UrlToString(text) {
41
+ return new TextDecoder().decode(base64UrlToBytes(text));
42
+ }
43
+
44
+ //#endregion
4
45
  //#region src/browser-posture-proof.ts
5
46
  /**
6
47
  * RFC 9449 DPoP-shaped proof verification (P37): binds a browser-posture
@@ -39,7 +80,7 @@ const BrowserPostureProofSchema = object({
39
80
  async function verifyBrowserPostureProof(proofJws, posture, request, now = Math.floor(Date.now() / 1e3), maxAgeSeconds = 60) {
40
81
  if (!proofJws || proofJws.length > 2e3 || !posture.cnf) return void 0;
41
82
  try {
42
- const decoded = JSON.parse(Buffer.from(proofJws.split(".")[0], "base64url").toString("utf8"));
83
+ const decoded = JSON.parse(base64UrlToString(proofJws.split(".")[0]));
43
84
  if (decoded.typ !== "dpop+jwt" || decoded.alg !== "ES256" || !decoded.jwk || decoded.jwk.kty !== "EC" || decoded.jwk.crv !== "P-256" || decoded.jwk.d) return void 0;
44
85
  if (await calculateJwkThumbprint(decoded.jwk, "sha256") !== posture.cnf.jkt) return void 0;
45
86
  const key = await importJWK(decoded.jwk, "ES256");
@@ -1 +1 @@
1
- {"version":3,"file":"browser-posture-proof.mjs","names":["z.object","z.string","z.number"],"sources":["../src/browser-posture-proof.ts"],"sourcesContent":["import { calculateJwkThumbprint, importJWK, jwtVerify, type JWK } from 'jose';\nimport { z } from 'zod';\nimport type { BrowserPosture } from './browser-posture';\n\n/**\n * RFC 9449 DPoP-shaped proof verification (P37): binds a browser-posture\n * token to a non-extractable key the page holds, so the posture token's\n * TTL stops being the whole replay window. The literal RFC 9449 `typ`\n * value, not a project-specific string like the posture token's own\n * `checkpoint-posture+jwt` - adopting the registered value buys real\n * interoperability with any existing DPoP-aware tooling for no cost.\n */\nexport const POSTURE_PROOF_TYPE = 'dpop+jwt';\n/** Half the posture TTL: a per-request, single-use artifact needs a much\n * tighter freshness window than a session-scoped token. A caller-supplied\n * parameter, not a private constant - this must never repeat\n * `POSTURE_TTL_SECONDS`'s own hardcoding mistake. */\nexport const DEFAULT_POSTURE_PROOF_MAX_AGE_SECONDS = 60;\n\nexport const BrowserPostureProofSchema = z.object({\n jti: z.string().min(1).max(255),\n htm: z.string().min(1).max(16),\n htu: z.string().url(),\n iat: z.number().int().nonnegative(),\n});\nexport type BrowserPostureProof = z.infer<typeof BrowserPostureProofSchema>;\n\n/**\n * Verifies a DPoP-shaped proof (RFC 9449) against an ALREADY-VERIFIED\n * `BrowserPosture` (call `verifyBrowserPosture` first). Checks, in order:\n * the proof's own header shape (`typ`, `alg`, embedded `jwk`); that the\n * embedded key's RFC 7638 thumbprint matches `posture.cnf.jkt`; the\n * proof's ES256 signature against that same embedded key; `htm`/`htu`\n * against the real request; `iat` freshness. Returns `undefined` on ANY\n * failure, including when `posture.cnf` is absent (no binding to check\n * against), never throws.\n *\n * Does NOT check `jti` replay: that needs a store this library does not\n * own. The caller checks the returned proof's `jti` against their own\n * replay store as the final step before trusting the request.\n */\nexport async function verifyBrowserPostureProof(\n proofJws: string | undefined,\n posture: BrowserPosture,\n request: { method: string; url: string },\n now = Math.floor(Date.now() / 1000),\n maxAgeSeconds = DEFAULT_POSTURE_PROOF_MAX_AGE_SECONDS\n): Promise<BrowserPostureProof | undefined> {\n if (!proofJws || proofJws.length > 2000 || !posture.cnf) return undefined;\n try {\n // `proofJws` is already a non-empty, length-bounded string (checked\n // above), so `split('.')[0]` always yields a string, never `undefined`\n // - no `?? ''` fallback to dead-code around.\n const decoded = JSON.parse(\n Buffer.from(proofJws.split('.')[0], 'base64url').toString('utf8')\n ) as { typ?: string; alg?: string; jwk?: JWK };\n if (\n decoded.typ !== POSTURE_PROOF_TYPE ||\n decoded.alg !== 'ES256' ||\n !decoded.jwk ||\n decoded.jwk.kty !== 'EC' ||\n decoded.jwk.crv !== 'P-256' ||\n decoded.jwk.d\n )\n return undefined;\n const thumbprint = await calculateJwkThumbprint(decoded.jwk, 'sha256');\n if (thumbprint !== posture.cnf.jkt) return undefined;\n const key = await importJWK(decoded.jwk, 'ES256');\n const { payload } = await jwtVerify(proofJws, key, {\n algorithms: ['ES256'],\n typ: POSTURE_PROOF_TYPE,\n currentDate: new Date(now * 1000),\n });\n const parsed = BrowserPostureProofSchema.safeParse(payload);\n if (!parsed.success) return undefined;\n const claims = parsed.data;\n if (\n claims.htm.toUpperCase() !== request.method.toUpperCase() ||\n claims.htu !== request.url ||\n Math.abs(now - claims.iat) > maxAgeSeconds\n )\n return undefined;\n return claims;\n } catch {\n return undefined;\n }\n}\n"],"mappings":";;;;;;;;;;;;AAYA,MAAa,qBAAqB;;;;;AAKlC,MAAa,wCAAwC;AAErD,MAAa,4BAA4BA,OAAS;CAChD,KAAKC,OAAS,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG;CAC9B,KAAKA,OAAS,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE;CAC7B,KAAKA,OAAS,CAAC,CAAC,IAAI;CACpB,KAAKC,OAAS,CAAC,CAAC,IAAI,CAAC,CAAC,YAAY;AACpC,CAAC;;;;;;;;;;;;;;;AAiBD,eAAsB,0BACpB,UACA,SACA,SACA,MAAM,KAAK,MAAM,KAAK,IAAI,IAAI,GAAI,GAClC,oBAC0C;CAC1C,IAAI,CAAC,YAAY,SAAS,SAAS,OAAQ,CAAC,QAAQ,KAAK,OAAO;CAChE,IAAI;EAIF,MAAM,UAAU,KAAK,MACnB,OAAO,KAAK,SAAS,MAAM,GAAG,CAAC,CAAC,IAAI,WAAW,CAAC,CAAC,SAAS,MAAM,CAClE;EACA,IACE,QAAQ,sBACR,QAAQ,QAAQ,WAChB,CAAC,QAAQ,OACT,QAAQ,IAAI,QAAQ,QACpB,QAAQ,IAAI,QAAQ,WACpB,QAAQ,IAAI,GAEZ,OAAO;EAET,IAAI,MADqB,uBAAuB,QAAQ,KAAK,QAAQ,MAClD,QAAQ,IAAI,KAAK,OAAO;EAC3C,MAAM,MAAM,MAAM,UAAU,QAAQ,KAAK,OAAO;EAChD,MAAM,EAAE,YAAY,MAAM,UAAU,UAAU,KAAK;GACjD,YAAY,CAAC,OAAO;GACpB,KAAK;GACL,6BAAa,IAAI,KAAK,MAAM,GAAI;EAClC,CAAC;EACD,MAAM,SAAS,0BAA0B,UAAU,OAAO;EAC1D,IAAI,CAAC,OAAO,SAAS,OAAO;EAC5B,MAAM,SAAS,OAAO;EACtB,IACE,OAAO,IAAI,YAAY,MAAM,QAAQ,OAAO,YAAY,KACxD,OAAO,QAAQ,QAAQ,OACvB,KAAK,IAAI,MAAM,OAAO,GAAG,IAAI,eAE7B,OAAO;EACT,OAAO;CACT,QAAQ;EACN;CACF;AACF"}
1
+ {"version":3,"file":"browser-posture-proof.mjs","names":["z.object","z.string","z.number"],"sources":["../src/utils/base64url.ts","../src/browser-posture-proof.ts"],"sourcesContent":["/**\n * Base64url (RFC 4648 § 5) built on `atob` and `btoa` rather than Node's\n * buffer API, so it runs on every runtime the SDKs support, Cloudflare Workers\n * without `nodejs_compat` included.\n */\n\nconst BASE64URL_UNPADDED = /^[A-Za-z0-9_-]*$/;\nconst PADDING = 61; // '='\n\n/**\n * `text` without its trailing `=` padding. A backward scan, not\n * `replace(/=+$/, '')`: that regex retries from every `=` in a long run that\n * does not reach the end, which is quadratic on hostile input.\n */\nfunction withoutPadding(text: string): string {\n let end = text.length;\n while (end > 0 && text.charCodeAt(end - 1) === PADDING) end -= 1;\n return text.slice(0, end);\n}\n\n/**\n * Decode base64url, with or without `=` padding.\n *\n * Strict where Node's buffer decoder is lenient: a character outside the\n * alphabet, or a length no encoder produces (one character past a multiple of\n * four), throws a `TypeError` instead of being skipped or truncated. This\n * matches the engine's decoder.\n */\nexport function base64UrlToBytes(text: string): Uint8Array {\n const unpadded = withoutPadding(text);\n if (!BASE64URL_UNPADDED.test(unpadded) || unpadded.length % 4 === 1) {\n throw new TypeError('not valid base64url (RFC 4648 § 5)');\n }\n const base64 = unpadded.replace(/-/g, '+').replace(/_/g, '/');\n const binary = atob(base64 + '='.repeat((4 - (base64.length % 4)) % 4));\n const bytes = new Uint8Array(binary.length);\n for (let index = 0; index < binary.length; index += 1) {\n bytes[index] = binary.charCodeAt(index);\n }\n return bytes;\n}\n\n/** Decode base64url to a string as UTF-8, replacing invalid sequences with U+FFFD. */\nexport function base64UrlToString(text: string): string {\n return new TextDecoder().decode(base64UrlToBytes(text));\n}\n\n/** Encode bytes as base64url without padding. */\nexport function bytesToBase64Url(bytes: Uint8Array): string {\n let binary = '';\n for (const byte of bytes) binary += String.fromCharCode(byte);\n return withoutPadding(btoa(binary).replace(/\\+/g, '-').replace(/\\//g, '_'));\n}\n","import { calculateJwkThumbprint, importJWK, jwtVerify, type JWK } from 'jose';\nimport { z } from 'zod';\nimport type { BrowserPosture } from './browser-posture';\nimport { base64UrlToString } from './utils/base64url';\n\n/**\n * RFC 9449 DPoP-shaped proof verification (P37): binds a browser-posture\n * token to a non-extractable key the page holds, so the posture token's\n * TTL stops being the whole replay window. The literal RFC 9449 `typ`\n * value, not a project-specific string like the posture token's own\n * `checkpoint-posture+jwt` - adopting the registered value buys real\n * interoperability with any existing DPoP-aware tooling for no cost.\n */\nexport const POSTURE_PROOF_TYPE = 'dpop+jwt';\n/** Half the posture TTL: a per-request, single-use artifact needs a much\n * tighter freshness window than a session-scoped token. A caller-supplied\n * parameter, not a private constant - this must never repeat\n * `POSTURE_TTL_SECONDS`'s own hardcoding mistake. */\nexport const DEFAULT_POSTURE_PROOF_MAX_AGE_SECONDS = 60;\n\nexport const BrowserPostureProofSchema = z.object({\n jti: z.string().min(1).max(255),\n htm: z.string().min(1).max(16),\n htu: z.string().url(),\n iat: z.number().int().nonnegative(),\n});\nexport type BrowserPostureProof = z.infer<typeof BrowserPostureProofSchema>;\n\n/**\n * Verifies a DPoP-shaped proof (RFC 9449) against an ALREADY-VERIFIED\n * `BrowserPosture` (call `verifyBrowserPosture` first). Checks, in order:\n * the proof's own header shape (`typ`, `alg`, embedded `jwk`); that the\n * embedded key's RFC 7638 thumbprint matches `posture.cnf.jkt`; the\n * proof's ES256 signature against that same embedded key; `htm`/`htu`\n * against the real request; `iat` freshness. Returns `undefined` on ANY\n * failure, including when `posture.cnf` is absent (no binding to check\n * against), never throws.\n *\n * Does NOT check `jti` replay: that needs a store this library does not\n * own. The caller checks the returned proof's `jti` against their own\n * replay store as the final step before trusting the request.\n */\nexport async function verifyBrowserPostureProof(\n proofJws: string | undefined,\n posture: BrowserPosture,\n request: { method: string; url: string },\n now = Math.floor(Date.now() / 1000),\n maxAgeSeconds = DEFAULT_POSTURE_PROOF_MAX_AGE_SECONDS\n): Promise<BrowserPostureProof | undefined> {\n if (!proofJws || proofJws.length > 2000 || !posture.cnf) return undefined;\n try {\n // `proofJws` is already a non-empty, length-bounded string (checked\n // above), so `split('.')[0]` always yields a string, never `undefined`\n // - no `?? ''` fallback to dead-code around.\n const decoded = JSON.parse(base64UrlToString(proofJws.split('.')[0])) as {\n typ?: string;\n alg?: string;\n jwk?: JWK;\n };\n if (\n decoded.typ !== POSTURE_PROOF_TYPE ||\n decoded.alg !== 'ES256' ||\n !decoded.jwk ||\n decoded.jwk.kty !== 'EC' ||\n decoded.jwk.crv !== 'P-256' ||\n decoded.jwk.d\n )\n return undefined;\n const thumbprint = await calculateJwkThumbprint(decoded.jwk, 'sha256');\n if (thumbprint !== posture.cnf.jkt) return undefined;\n const key = await importJWK(decoded.jwk, 'ES256');\n const { payload } = await jwtVerify(proofJws, key, {\n algorithms: ['ES256'],\n typ: POSTURE_PROOF_TYPE,\n currentDate: new Date(now * 1000),\n });\n const parsed = BrowserPostureProofSchema.safeParse(payload);\n if (!parsed.success) return undefined;\n const claims = parsed.data;\n if (\n claims.htm.toUpperCase() !== request.method.toUpperCase() ||\n claims.htu !== request.url ||\n Math.abs(now - claims.iat) > maxAgeSeconds\n )\n return undefined;\n return claims;\n } catch {\n return undefined;\n }\n}\n"],"mappings":";;;;;;;;;AAMA,MAAM,qBAAqB;AAC3B,MAAM,UAAU;;;;;;AAOhB,SAAS,eAAe,MAAsB;CAC5C,IAAI,MAAM,KAAK;CACf,OAAO,MAAM,KAAK,KAAK,WAAW,MAAM,CAAC,MAAM,SAAS,OAAO;CAC/D,OAAO,KAAK,MAAM,GAAG,GAAG;AAC1B;;;;;;;;;AAUA,SAAgB,iBAAiB,MAA0B;CACzD,MAAM,WAAW,eAAe,IAAI;CACpC,IAAI,CAAC,mBAAmB,KAAK,QAAQ,KAAK,SAAS,SAAS,MAAM,GAChE,MAAM,IAAI,UAAU,oCAAoC;CAE1D,MAAM,SAAS,SAAS,QAAQ,MAAM,GAAG,CAAC,CAAC,QAAQ,MAAM,GAAG;CAC5D,MAAM,SAAS,KAAK,SAAS,IAAI,QAAQ,IAAK,OAAO,SAAS,KAAM,CAAC,CAAC;CACtE,MAAM,QAAQ,IAAI,WAAW,OAAO,MAAM;CAC1C,KAAK,IAAI,QAAQ,GAAG,QAAQ,OAAO,QAAQ,SAAS,GAClD,MAAM,SAAS,OAAO,WAAW,KAAK;CAExC,OAAO;AACT;;AAGA,SAAgB,kBAAkB,MAAsB;CACtD,OAAO,IAAI,YAAY,CAAC,CAAC,OAAO,iBAAiB,IAAI,CAAC;AACxD;;;;;;;;;;;;AChCA,MAAa,qBAAqB;;;;;AAKlC,MAAa,wCAAwC;AAErD,MAAa,4BAA4BA,OAAS;CAChD,KAAKC,OAAS,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG;CAC9B,KAAKA,OAAS,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE;CAC7B,KAAKA,OAAS,CAAC,CAAC,IAAI;CACpB,KAAKC,OAAS,CAAC,CAAC,IAAI,CAAC,CAAC,YAAY;AACpC,CAAC;;;;;;;;;;;;;;;AAiBD,eAAsB,0BACpB,UACA,SACA,SACA,MAAM,KAAK,MAAM,KAAK,IAAI,IAAI,GAAI,GAClC,oBAC0C;CAC1C,IAAI,CAAC,YAAY,SAAS,SAAS,OAAQ,CAAC,QAAQ,KAAK,OAAO;CAChE,IAAI;EAIF,MAAM,UAAU,KAAK,MAAM,kBAAkB,SAAS,MAAM,GAAG,CAAC,CAAC,EAAE,CAAC;EAKpE,IACE,QAAQ,sBACR,QAAQ,QAAQ,WAChB,CAAC,QAAQ,OACT,QAAQ,IAAI,QAAQ,QACpB,QAAQ,IAAI,QAAQ,WACpB,QAAQ,IAAI,GAEZ,OAAO;EAET,IAAI,MADqB,uBAAuB,QAAQ,KAAK,QAAQ,MAClD,QAAQ,IAAI,KAAK,OAAO;EAC3C,MAAM,MAAM,MAAM,UAAU,QAAQ,KAAK,OAAO;EAChD,MAAM,EAAE,YAAY,MAAM,UAAU,UAAU,KAAK;GACjD,YAAY,CAAC,OAAO;GACpB,KAAK;GACL,6BAAa,IAAI,KAAK,MAAM,GAAI;EAClC,CAAC;EACD,MAAM,SAAS,0BAA0B,UAAU,OAAO;EAC1D,IAAI,CAAC,OAAO,SAAS,OAAO;EAC5B,MAAM,SAAS,OAAO;EACtB,IACE,OAAO,IAAI,YAAY,MAAM,QAAQ,OAAO,YAAY,KACxD,OAAO,QAAQ,QAAQ,OACvB,KAAK,IAAI,MAAM,OAAO,GAAG,IAAI,eAE7B,OAAO;EACT,OAAO;CACT,QAAQ;EACN;CACF;AACF"}
@@ -1,2 +1,2 @@
1
- import { A as POSTURE_VERIFICATION_STATUSES, C as verifyBrowserPosture, D as BrowserPostureRejectionReason, E as BrowserPostureOutcomeSchema, F as POSTURE_TTL_SECONDS, I as postureCookieName, M as browserPostureReport, N as BrowserPosture, O as BrowserPostureReportIngestSchema, P as BrowserPostureSchema, S as validateBrowserPostureConfig, T as BrowserPostureOutcome, _ as postureRequiredScopes, a as POSTURE_SESSION_HEADER, b as readPostureCookie, c as PostureVerification, d as inspectBrowserPosture, f as postureFromCookies, g as postureRequestFromHeaders, h as postureOutcomeReport, i as POSTURE_ISSUER, j as PostureVerificationStatus, k as BrowserPostureReportSchema, l as UNSIGNED_BROWSER_AGENT, m as postureOutcomeFromRequest, n as JWK, o as POSTURE_TYPE, p as postureFromRequest, r as POSTURE_HEADER, s as PostureRequest, t as BrowserPostureConfig, u as behavioralConfidence, v as postureSessionBinding, w as BROWSER_POSTURE_REJECTION_REASONS, x as signBrowserPosture, y as postureUpgrade } from "./browser-posture-BuChqmH5.mjs";
1
+ import { A as POSTURE_VERIFICATION_STATUSES, C as verifyBrowserPosture, D as BrowserPostureRejectionReason, E as BrowserPostureOutcomeSchema, F as POSTURE_TTL_SECONDS, I as postureCookieName, M as browserPostureReport, N as BrowserPosture, O as BrowserPostureReportIngestSchema, P as BrowserPostureSchema, S as validateBrowserPostureConfig, T as BrowserPostureOutcome, _ as postureRequiredScopes, a as POSTURE_SESSION_HEADER, b as readPostureCookie, c as PostureVerification, d as inspectBrowserPosture, f as postureFromCookies, g as postureRequestFromHeaders, h as postureOutcomeReport, i as POSTURE_ISSUER, j as PostureVerificationStatus, k as BrowserPostureReportSchema, l as UNSIGNED_BROWSER_AGENT, m as postureOutcomeFromRequest, n as JWK, o as POSTURE_TYPE, p as postureFromRequest, r as POSTURE_HEADER, s as PostureRequest, t as BrowserPostureConfig, u as behavioralConfidence, v as postureSessionBinding, w as BROWSER_POSTURE_REJECTION_REASONS, x as signBrowserPosture, y as postureUpgrade } from "./browser-posture-BLhw-MON.mjs";
2
2
  export { BROWSER_POSTURE_REJECTION_REASONS, type BrowserPosture, BrowserPostureConfig, type BrowserPostureOutcome, BrowserPostureOutcomeSchema, type BrowserPostureRejectionReason, BrowserPostureReportIngestSchema, BrowserPostureReportSchema, BrowserPostureSchema, type JWK, POSTURE_HEADER, POSTURE_ISSUER, POSTURE_SESSION_HEADER, POSTURE_TTL_SECONDS, POSTURE_TYPE, POSTURE_VERIFICATION_STATUSES, PostureRequest, PostureVerification, type PostureVerificationStatus, UNSIGNED_BROWSER_AGENT, behavioralConfidence, browserPostureReport, inspectBrowserPosture, postureCookieName, postureFromCookies, postureFromRequest, postureOutcomeFromRequest, postureOutcomeReport, postureRequestFromHeaders, postureRequiredScopes, postureSessionBinding, postureUpgrade, readPostureCookie, signBrowserPosture, validateBrowserPostureConfig, verifyBrowserPosture };
@@ -1,2 +1,2 @@
1
- import { A as POSTURE_VERIFICATION_STATUSES, C as verifyBrowserPosture, D as BrowserPostureRejectionReason, E as BrowserPostureOutcomeSchema, F as POSTURE_TTL_SECONDS, I as postureCookieName, M as browserPostureReport, N as BrowserPosture, O as BrowserPostureReportIngestSchema, P as BrowserPostureSchema, S as validateBrowserPostureConfig, T as BrowserPostureOutcome, _ as postureRequiredScopes, a as POSTURE_SESSION_HEADER, b as readPostureCookie, c as PostureVerification, d as inspectBrowserPosture, f as postureFromCookies, g as postureRequestFromHeaders, h as postureOutcomeReport, i as POSTURE_ISSUER, j as PostureVerificationStatus, k as BrowserPostureReportSchema, l as UNSIGNED_BROWSER_AGENT, m as postureOutcomeFromRequest, n as JWK, o as POSTURE_TYPE, p as postureFromRequest, r as POSTURE_HEADER, s as PostureRequest, t as BrowserPostureConfig, u as behavioralConfidence, v as postureSessionBinding, w as BROWSER_POSTURE_REJECTION_REASONS, x as signBrowserPosture, y as postureUpgrade } from "./browser-posture-DIaVLuW3.js";
1
+ import { A as POSTURE_VERIFICATION_STATUSES, C as verifyBrowserPosture, D as BrowserPostureRejectionReason, E as BrowserPostureOutcomeSchema, F as POSTURE_TTL_SECONDS, I as postureCookieName, M as browserPostureReport, N as BrowserPosture, O as BrowserPostureReportIngestSchema, P as BrowserPostureSchema, S as validateBrowserPostureConfig, T as BrowserPostureOutcome, _ as postureRequiredScopes, a as POSTURE_SESSION_HEADER, b as readPostureCookie, c as PostureVerification, d as inspectBrowserPosture, f as postureFromCookies, g as postureRequestFromHeaders, h as postureOutcomeReport, i as POSTURE_ISSUER, j as PostureVerificationStatus, k as BrowserPostureReportSchema, l as UNSIGNED_BROWSER_AGENT, m as postureOutcomeFromRequest, n as JWK, o as POSTURE_TYPE, p as postureFromRequest, r as POSTURE_HEADER, s as PostureRequest, t as BrowserPostureConfig, u as behavioralConfidence, v as postureSessionBinding, w as BROWSER_POSTURE_REJECTION_REASONS, x as signBrowserPosture, y as postureUpgrade } from "./browser-posture-B8YiPa5c.js";
2
2
  export { BROWSER_POSTURE_REJECTION_REASONS, type BrowserPosture, BrowserPostureConfig, type BrowserPostureOutcome, BrowserPostureOutcomeSchema, type BrowserPostureRejectionReason, BrowserPostureReportIngestSchema, BrowserPostureReportSchema, BrowserPostureSchema, type JWK, POSTURE_HEADER, POSTURE_ISSUER, POSTURE_SESSION_HEADER, POSTURE_TTL_SECONDS, POSTURE_TYPE, POSTURE_VERIFICATION_STATUSES, PostureRequest, PostureVerification, type PostureVerificationStatus, UNSIGNED_BROWSER_AGENT, behavioralConfidence, browserPostureReport, inspectBrowserPosture, postureCookieName, postureFromCookies, postureFromRequest, postureOutcomeFromRequest, postureOutcomeReport, postureRequestFromHeaders, postureRequiredScopes, postureSessionBinding, postureUpgrade, readPostureCookie, signBrowserPosture, validateBrowserPostureConfig, verifyBrowserPosture };
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_schemas = require('./schemas-YhagYDx_.js');
3
- const require_posture_origins = require('./posture-origins-LFkX80oF.js');
3
+ const require_posture_origins = require('./posture-origins-CdVOdiMT.js');
4
4
  const require_project_verification_key = require('./project-verification-key-BccT12tQ.js');
5
5
  let jose = require("jose");
6
6
 
@@ -1,5 +1,5 @@
1
1
  import { C as string, T as unknown, c as array, g as literal, i as _enum, l as boolean, p as guid, v as number, x as record, y as object } from "./schemas-7qodsG-Z.mjs";
2
- import { d as UUID_PATTERN, f as VALIDATION_PATTERNS, n as matchAllowedOrigin, r as parseOriginPattern } from "./posture-origins-Pn-ii-Pp.mjs";
2
+ import { d as UUID_PATTERN, f as VALIDATION_PATTERNS, n as matchAllowedOrigin, r as parseOriginPattern } from "./posture-origins-Ba83O0cD.mjs";
3
3
  import { t as projectVerificationKey } from "./project-verification-key-66N4edKn.mjs";
4
4
  import { SignJWT, compactVerify, decodeProtectedHeader, importJWK } from "jose";
5
5
 
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/canonical-signer/payload.ts","../../src/canonical-signer/key.ts","../../src/canonical-signer/envelope.ts","../../src/canonical-signer/parse.ts"],"mappings":";UA+BiB;EAEf;EAEA;EAEA;EAEA;EAEA;EAEA;EAEA;EAEA;;wBAsBc,wBAAwB,SAAS,cAAc;wBAmD/C,oBAAoB,iBAAiB;;;UC7EpC;EAEf,YAAY;EAEZ,WAAW;EAEX;EAMA;;wBAmBoB,gBAAgB,MAAM,aAAa,QAAQ;;;wBCjB3C,iBAAiB,SAAS,aAAa,KAAK,cAAc;;;UCnB/D;EAEf;IACE;IAIA;IAGA;;EAGF,SAAS;EAET,gBAAgB;EAMhB,cAAc;;qBAQH,sBAAsB;WAGf;EAAA,YAAA,gKAQhB;;wBAwFY,gBAAgB,cAAc"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/canonical-signer/payload.ts","../../src/canonical-signer/key.ts","../../src/canonical-signer/envelope.ts","../../src/canonical-signer/parse.ts"],"mappings":";UA+BiB;EAEf;EAEA;EAEA;EAEA;EAEA;EAEA;EAEA;EAEA;;wBAsBc,wBAAwB,SAAS,cAAc;wBAmD/C,oBAAoB,iBAAiB;;;UC7EpC;EAEf,YAAY;EAEZ,WAAW;EAEX;EAMA;;wBAmBoB,gBAAgB,MAAM,aAAa,QAAQ;;;wBCrC3C,iBAAiB,SAAS,aAAa,KAAK,cAAc;;;UCE/D;EAEf;IACE;IAIA;IAGA;;EAGF,SAAS;EAET,gBAAgB;EAMhB,cAAc;;qBAQH,sBAAsB;WAGf;EAAA,YAAA,gKAQhB;;wBAwFY,gBAAgB,cAAc"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/canonical-signer/payload.ts","../../src/canonical-signer/key.ts","../../src/canonical-signer/envelope.ts","../../src/canonical-signer/parse.ts"],"mappings":";UA+BiB;EAEf;EAEA;EAEA;EAEA;EAEA;EAEA;EAEA;EAEA;;wBAsBc,wBAAwB,SAAS,cAAc;wBAmD/C,oBAAoB,iBAAiB;;;UC7EpC;EAEf,YAAY;EAEZ,WAAW;EAEX;EAMA;;wBAmBoB,gBAAgB,MAAM,aAAa,QAAQ;;;wBCjB3C,iBAAiB,SAAS,aAAa,KAAK,cAAc;;;UCnB/D;EAEf;IACE;IAIA;IAGA;;EAGF,SAAS;EAET,gBAAgB;EAMhB,cAAc;;qBAQH,sBAAsB;WAGf;EAAA,YAAA,gKAQhB;;wBAwFY,gBAAgB,cAAc"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/canonical-signer/payload.ts","../../src/canonical-signer/key.ts","../../src/canonical-signer/envelope.ts","../../src/canonical-signer/parse.ts"],"mappings":";UA+BiB;EAEf;EAEA;EAEA;EAEA;EAEA;EAEA;EAEA;EAEA;;wBAsBc,wBAAwB,SAAS,cAAc;wBAmD/C,oBAAoB,iBAAiB;;;UC7EpC;EAEf,YAAY;EAEZ,WAAW;EAEX;EAMA;;wBAmBoB,gBAAgB,MAAM,aAAa,QAAQ;;;wBCrC3C,iBAAiB,SAAS,aAAa,KAAK,cAAc;;;UCE/D;EAEf;IACE;IAIA;IAGA;;EAGF,SAAS;EAET,gBAAgB;EAMhB,cAAc;;qBAQH,sBAAsB;WAGf;EAAA,YAAA,gKAQhB;;wBAwFY,gBAAgB,cAAc"}
@@ -235,6 +235,53 @@ async function parseSigningKey(seed) {
235
235
  };
236
236
  }
237
237
 
238
+ //#endregion
239
+ //#region src/utils/base64url.ts
240
+ /**
241
+ * Base64url (RFC 4648 § 5) built on `atob` and `btoa` rather than Node's
242
+ * buffer API, so it runs on every runtime the SDKs support, Cloudflare Workers
243
+ * without `nodejs_compat` included.
244
+ */
245
+ const BASE64URL_UNPADDED = /^[A-Za-z0-9_-]*$/;
246
+ const PADDING = 61;
247
+ /**
248
+ * `text` without its trailing `=` padding. A backward scan, not
249
+ * `replace(/=+$/, '')`: that regex retries from every `=` in a long run that
250
+ * does not reach the end, which is quadratic on hostile input.
251
+ */
252
+ function withoutPadding(text) {
253
+ let end = text.length;
254
+ while (end > 0 && text.charCodeAt(end - 1) === PADDING) end -= 1;
255
+ return text.slice(0, end);
256
+ }
257
+ /**
258
+ * Decode base64url, with or without `=` padding.
259
+ *
260
+ * Strict where Node's buffer decoder is lenient: a character outside the
261
+ * alphabet, or a length no encoder produces (one character past a multiple of
262
+ * four), throws a `TypeError` instead of being skipped or truncated. This
263
+ * matches the engine's decoder.
264
+ */
265
+ function base64UrlToBytes(text) {
266
+ const unpadded = withoutPadding(text);
267
+ if (!BASE64URL_UNPADDED.test(unpadded) || unpadded.length % 4 === 1) throw new TypeError("not valid base64url (RFC 4648 § 5)");
268
+ const base64 = unpadded.replace(/-/g, "+").replace(/_/g, "/");
269
+ const binary = atob(base64 + "=".repeat((4 - base64.length % 4) % 4));
270
+ const bytes = new Uint8Array(binary.length);
271
+ for (let index = 0; index < binary.length; index += 1) bytes[index] = binary.charCodeAt(index);
272
+ return bytes;
273
+ }
274
+ /** Decode base64url to a string as UTF-8, replacing invalid sequences with U+FFFD. */
275
+ function base64UrlToString(text) {
276
+ return new TextDecoder().decode(base64UrlToBytes(text));
277
+ }
278
+ /** Encode bytes as base64url without padding. */
279
+ function bytesToBase64Url(bytes) {
280
+ let binary = "";
281
+ for (const byte of bytes) binary += String.fromCharCode(byte);
282
+ return withoutPadding(btoa(binary).replace(/\+/g, "-").replace(/\//g, "_"));
283
+ }
284
+
238
285
  //#endregion
239
286
  //#region src/canonical-signer/envelope.ts
240
287
  /**
@@ -254,22 +301,6 @@ async function parseSigningKey(seed) {
254
301
  * Sites-4 parity drivers, the Adobe trial.
255
302
  */
256
303
  /**
257
- * URL-safe base64 encoding without padding (RFC 4648 § 5).
258
- *
259
- * **Node-only.** Uses Node's `Buffer` API because every current consumer
260
- * of this module runs on Node (Vercel functions, Sites-1/2 Playwright
261
- * suites, future SDKs that bundle for Node + bundler-polyfilled runtimes
262
- * like Vercel Edge with `nodejs_compat`). If a future consumer needs a
263
- * pure-Web-API runtime (Cloudflare Workers without `nodejs_compat`,
264
- * Deno's stricter modes), swap to `Uint8Array.toBase64()` (Stage 4 as
265
- * of mid-2026) or a small inline encoder — but verify against the
266
- * envelope.test.ts round-trip first; the `base64url` character
267
- * substitution path is the part that has historically tripped polyfills.
268
- */
269
- function base64UrlEncode(bytes) {
270
- return Buffer.from(bytes).toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
271
- }
272
- /**
273
304
  * Sign an `McpIPayload` and produce a compact-JWS envelope ready to drop
274
305
  * into `_meta.proof.jws` of the request body per KYA-OS spec § 7.4.
275
306
  *
@@ -290,15 +321,40 @@ async function signMcpiEnvelope(payload, key) {
290
321
  kid: key.kid
291
322
  };
292
323
  const headerJson = JSON.stringify(header);
293
- const headerB64 = base64UrlEncode(new TextEncoder().encode(headerJson));
294
- const payloadB64 = base64UrlEncode(canonicalSigningPayload(payload));
324
+ const headerB64 = bytesToBase64Url(new TextEncoder().encode(headerJson));
325
+ const payloadB64 = bytesToBase64Url(canonicalSigningPayload(payload));
295
326
  const signingInput = new TextEncoder().encode(`${headerB64}.${payloadB64}`);
296
- return `${headerB64}.${payloadB64}.${base64UrlEncode(await (0, _noble_ed25519.signAsync)(signingInput, key.signingKey))}`;
327
+ const signature = await (0, _noble_ed25519.signAsync)(signingInput, key.signingKey);
328
+ return `${headerB64}.${payloadB64}.${bytesToBase64Url(signature)}`;
297
329
  }
298
330
 
299
331
  //#endregion
300
332
  //#region src/canonical-signer/parse.ts
301
333
  /**
334
+ * Compact-JWS parser for KYA-OS detached proofs.
335
+ *
336
+ * Producer-side counterpart to Sign-1's `signMcpiEnvelope`: takes the
337
+ * wire string the engine's H-1 parser would consume and decomposes it
338
+ * into the same logical pieces (header, payload, signature, signing
339
+ * input). Lives in `checkpoint-shared/canonical-signer/` so producer
340
+ * AND consumer share one wire-format implementation — the JCS / base64
341
+ * subtleties are handled in one place, not three.
342
+ *
343
+ * Consumed by:
344
+ * - `@kya-os/bouncer-middleware` (Envelope-1 / #2537)
345
+ * - any future TS host that needs to introspect a JWS without going
346
+ * through the WASM bridge
347
+ *
348
+ * The Rust engine's `jws::parse_jws_compact` is the structural mirror
349
+ * (`rust/crates/kya-os-engine/src/jws.rs`); this module produces the
350
+ * same logical decomposition. Cross-runtime parity here is implicit:
351
+ * if both parsers consume the same JWS string and disagree on what's
352
+ * inside, the H-1 fixtures would catch it.
353
+ *
354
+ * Sign-1 (#2500). Anti-pattern: don't write a parallel parser
355
+ * elsewhere in the org — import from here.
356
+ */
357
+ /**
302
358
  * Discriminated error type so consumers can map parse failures to
303
359
  * appropriate response codes (400 for malformed shape, 422 for
304
360
  * unsupported alg) without string-matching error messages.
@@ -364,7 +420,7 @@ function parseJwsCompact(jws) {
364
420
  const [headerB64, payloadB64, signatureB64] = parts;
365
421
  let headerJson;
366
422
  try {
367
- headerJson = JSON.parse(base64UrlDecodeToString(headerB64));
423
+ headerJson = JSON.parse(base64UrlToString(headerB64));
368
424
  } catch (cause) {
369
425
  throw new JwsParseError("InvalidJson", `JWS header is not valid JSON: ${String(cause)}`);
370
426
  }
@@ -382,7 +438,7 @@ function parseJwsCompact(jws) {
382
438
  };
383
439
  let payloadJson;
384
440
  try {
385
- payloadJson = JSON.parse(base64UrlDecodeToString(payloadB64));
441
+ payloadJson = JSON.parse(base64UrlToString(payloadB64));
386
442
  } catch (cause) {
387
443
  throw new JwsParseError("InvalidJson", `JWS payload is not valid JSON: ${String(cause)}`);
388
444
  }
@@ -393,7 +449,12 @@ function parseJwsCompact(jws) {
393
449
  throw new JwsParseError("InvalidPayloadShape", `JWS payload does not match McpIPayload shape: ${cause.message}`);
394
450
  }
395
451
  if (!BASE64URL_ALPHABET.test(signatureB64)) throw new JwsParseError("InvalidBase64", `JWS signature segment contains characters outside the base64url alphabet (RFC 4648 § 5)`);
396
- const signatureBytes = base64UrlDecodeToBytes(signatureB64);
452
+ let signatureBytes;
453
+ try {
454
+ signatureBytes = base64UrlToBytes(signatureB64);
455
+ } catch {
456
+ throw new JwsParseError("InvalidBase64", `JWS signature segment is not a valid base64url length (RFC 4648 § 5)`);
457
+ }
397
458
  if (signatureBytes.length !== 64) throw new JwsParseError("InvalidSignatureLength", `Ed25519 signatures are 64 bytes (RFC 8032 § 5.1.6); got ${signatureBytes.length}`);
398
459
  const signingInput = new TextEncoder().encode(`${headerB64}.${payloadB64}`);
399
460
  return {
@@ -404,37 +465,11 @@ function parseJwsCompact(jws) {
404
465
  };
405
466
  }
406
467
  /**
407
- * Strict base64url alphabet check (RFC 4648 § 5). The set is
408
- * `A-Za-z0-9-_` plus optional `=` padding. We use this to validate
409
- * input BEFORE handing to Node's `Buffer.from(s, 'base64')`, which
410
- * silently drops invalid characters rather than throwing — bypassing
411
- * the discriminated `InvalidBase64` error code consumers rely on for
412
- * HTTP-status mapping.
413
- *
414
- * The empty-string case is rejected by the regex (`+` requires ≥1
415
- * char), which is the desired behavior — an empty segment is a
416
- * different bug class from "non-base64 characters in a non-empty
417
- * segment" but both warrant the same `InvalidBase64` response.
468
+ * Strict base64url alphabet check (RFC 4648 § 5): `A-Za-z0-9-_` plus optional
469
+ * `=` padding. The empty string fails it on purpose: an empty signature
470
+ * segment is reported as `InvalidBase64` too.
418
471
  */
419
472
  const BASE64URL_ALPHABET = /^[A-Za-z0-9_-]+=*$/;
420
- /**
421
- * Decode URL-safe base64 (with optional padding) to bytes. RFC 4648 § 5.
422
- * Tolerates the no-padding form Sign-1 produces AND the padded form
423
- * some external producers emit.
424
- *
425
- * **Caller must validate the input alphabet first** if they want
426
- * `InvalidBase64` reported as a distinct error class — Node's underlying
427
- * `Buffer.from(s, 'base64')` silently truncates on invalid characters
428
- * rather than throwing.
429
- */
430
- function base64UrlDecodeToBytes(s) {
431
- const padded = s.replace(/-/g, "+").replace(/_/g, "/");
432
- const padLen = padded.length % 4 === 0 ? 0 : 4 - padded.length % 4;
433
- return new Uint8Array(Buffer.from(padded + "=".repeat(padLen), "base64"));
434
- }
435
- function base64UrlDecodeToString(s) {
436
- return Buffer.from(base64UrlDecodeToBytes(s)).toString("utf-8");
437
- }
438
473
 
439
474
  //#endregion
440
475
  exports.JwsParseError = JwsParseError;