@astrasyncai/verification-gateway 5.13.0 → 5.15.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 (98) hide show
  1. package/README.md +27 -17
  2. package/dist/adapters/express.d.mts +1 -1
  3. package/dist/adapters/express.d.ts +1 -1
  4. package/dist/adapters/express.js +504 -249
  5. package/dist/adapters/express.js.map +1 -1
  6. package/dist/adapters/express.mjs +504 -249
  7. package/dist/adapters/express.mjs.map +1 -1
  8. package/dist/adapters/mcp.d.mts +1 -1
  9. package/dist/adapters/mcp.d.ts +1 -1
  10. package/dist/adapters/mcp.js +20 -6
  11. package/dist/adapters/mcp.js.map +1 -1
  12. package/dist/adapters/mcp.mjs +20 -6
  13. package/dist/adapters/mcp.mjs.map +1 -1
  14. package/dist/adapters/nextjs.d.mts +1 -1
  15. package/dist/adapters/nextjs.d.ts +1 -1
  16. package/dist/adapters/nextjs.js +487 -248
  17. package/dist/adapters/nextjs.js.map +1 -1
  18. package/dist/adapters/nextjs.mjs +487 -248
  19. package/dist/adapters/nextjs.mjs.map +1 -1
  20. package/dist/adapters/sdk.d.mts +18 -10
  21. package/dist/adapters/sdk.d.ts +18 -10
  22. package/dist/adapters/sdk.js +80 -23
  23. package/dist/adapters/sdk.js.map +1 -1
  24. package/dist/adapters/sdk.mjs +80 -23
  25. package/dist/adapters/sdk.mjs.map +1 -1
  26. package/dist/agent/index.js +1 -1
  27. package/dist/agent/index.js.map +1 -1
  28. package/dist/agent/index.mjs +1 -1
  29. package/dist/agent/index.mjs.map +1 -1
  30. package/dist/bin/astrasync-claude-hook.js +82 -20
  31. package/dist/bin/astrasync-codex-hook.js +82 -20
  32. package/dist/bin/astrasync-guard.js +82 -20
  33. package/dist/bin/astrasync.js +316 -43
  34. package/dist/browser/background.js +77 -15
  35. package/dist/browser/background.js.map +1 -1
  36. package/dist/browser/background.mjs +87 -15
  37. package/dist/browser/background.mjs.map +1 -1
  38. package/dist/cli/index.js +1 -1
  39. package/dist/cli/index.js.map +1 -1
  40. package/dist/cli/index.mjs +1 -1
  41. package/dist/cli/index.mjs.map +1 -1
  42. package/dist/codex/index.js +82 -20
  43. package/dist/codex/index.js.map +1 -1
  44. package/dist/codex/index.mjs +92 -20
  45. package/dist/codex/index.mjs.map +1 -1
  46. package/dist/cursor/extension.js +82 -20
  47. package/dist/cursor/extension.js.map +1 -1
  48. package/dist/cursor/extension.mjs +92 -20
  49. package/dist/cursor/extension.mjs.map +1 -1
  50. package/dist/edge-config.d.mts +31 -2
  51. package/dist/edge-config.d.ts +31 -2
  52. package/dist/edge-config.js +35 -5
  53. package/dist/edge-config.js.map +1 -1
  54. package/dist/edge-config.mjs +32 -4
  55. package/dist/edge-config.mjs.map +1 -1
  56. package/dist/edge-core/index.d.mts +43 -6
  57. package/dist/edge-core/index.d.ts +43 -6
  58. package/dist/edge-core/index.js +120 -19
  59. package/dist/edge-core/index.js.map +1 -1
  60. package/dist/edge-core/index.mjs +118 -19
  61. package/dist/edge-core/index.mjs.map +1 -1
  62. package/dist/gateway/gateway.js +77 -15
  63. package/dist/gateway/gateway.js.map +1 -1
  64. package/dist/gateway/gateway.mjs +87 -15
  65. package/dist/gateway/gateway.mjs.map +1 -1
  66. package/dist/git-trigger/git-hooks.d.mts +1 -1
  67. package/dist/git-trigger/git-hooks.d.ts +1 -1
  68. package/dist/index.d.mts +1314 -34
  69. package/dist/index.d.ts +1314 -34
  70. package/dist/index.js +5143 -2621
  71. package/dist/index.js.map +1 -1
  72. package/dist/index.mjs +5090 -2623
  73. package/dist/index.mjs.map +1 -1
  74. package/dist/registration/index.d.mts +28 -2
  75. package/dist/registration/index.d.ts +28 -2
  76. package/dist/registration/index.js +18 -3
  77. package/dist/registration/index.js.map +1 -1
  78. package/dist/registration/index.mjs +15 -2
  79. package/dist/registration/index.mjs.map +1 -1
  80. package/dist/transport/index.d.mts +7 -5
  81. package/dist/transport/index.d.ts +7 -5
  82. package/dist/transport/index.js +61 -5
  83. package/dist/transport/index.js.map +1 -1
  84. package/dist/transport/index.mjs +67 -11
  85. package/dist/transport/index.mjs.map +1 -1
  86. package/dist/{types-C_b4QTyO.d.ts → types-DtJjlW4O.d.ts} +104 -10
  87. package/dist/{types-BCkwBA84.d.mts → types-Dxf9DBpr.d.mts} +106 -12
  88. package/dist/{types-BCkwBA84.d.ts → types-Dxf9DBpr.d.ts} +106 -12
  89. package/dist/{types-DlshIIR-.d.mts → types-Eg6VoBNH.d.mts} +104 -10
  90. package/dist/ui/index.d.mts +1 -1
  91. package/dist/ui/index.d.ts +1 -1
  92. package/dist/verify.d.mts +1 -1
  93. package/dist/verify.d.ts +1 -1
  94. package/dist/verify.js +20 -6
  95. package/dist/verify.js.map +1 -1
  96. package/dist/verify.mjs +20 -6
  97. package/dist/verify.mjs.map +1 -1
  98. package/package.json +1 -1
@@ -437,6 +437,7 @@ function bufferToBase64(bytes) {
437
437
  }
438
438
 
439
439
  // src/transport/rfc9421-verify.ts
440
+ import { createHash } from "crypto";
440
441
  import { httpbis } from "http-message-signatures";
441
442
 
442
443
  // src/transport/nonce-store.ts
@@ -508,6 +509,16 @@ async function verifyRFC9421(request, options) {
508
509
  normalizeRequest(request)
509
510
  );
510
511
  if (result === true) {
512
+ const digestError = checkContentDigest(request);
513
+ if (digestError) {
514
+ return {
515
+ ok: false,
516
+ kid: resolvedKid,
517
+ registry: resolver.name,
518
+ algorithm: resolvedAlg,
519
+ error: digestError
520
+ };
521
+ }
511
522
  return {
512
523
  ok: true,
513
524
  kid: resolvedKid,
@@ -532,6 +543,21 @@ async function verifyRFC9421(request, options) {
532
543
  };
533
544
  }
534
545
  }
546
+ function checkContentDigest(request) {
547
+ if (request.body === void 0) return null;
548
+ const raw = Object.entries(request.headers).find(
549
+ ([k]) => k.toLowerCase() === "content-digest"
550
+ )?.[1];
551
+ if (!raw) return null;
552
+ const header = Array.isArray(raw) ? raw.join(", ") : raw;
553
+ const entries = [...header.matchAll(/(sha-256|sha-512)=:([A-Za-z0-9+/=]+):/g)];
554
+ if (entries.length === 0) return null;
555
+ for (const [, alg, value] of entries) {
556
+ const expected = createHash(alg === "sha-256" ? "sha256" : "sha512").update(request.body, "utf8").digest("base64");
557
+ if (expected !== value) return "content-digest does not match the body";
558
+ }
559
+ return null;
560
+ }
535
561
  function normalizeRequest(request) {
536
562
  return {
537
563
  method: request.method.toUpperCase(),
@@ -633,7 +659,7 @@ async function getCrypto() {
633
659
  }
634
660
 
635
661
  // src/version.ts
636
- var SDK_VERSION = "5.13.0";
662
+ var SDK_VERSION = "5.15.0";
637
663
 
638
664
  // src/http.ts
639
665
  var SDK_USER_AGENT = `astrasync-sdk/${SDK_VERSION}`;
@@ -781,8 +807,9 @@ function extractBearer(authHeader) {
781
807
  function extractPaymentToken(body) {
782
808
  const paymentData = body.payment_data;
783
809
  if (!paymentData) return void 0;
784
- const raw = coerceString3(paymentData.token);
785
- const provider = coerceString3(paymentData.provider);
810
+ const instrument = paymentData.instrument;
811
+ const raw = coerceString3(instrument?.credential?.token) ?? coerceString3(paymentData.token);
812
+ const provider = coerceString3(paymentData.provider) ?? coerceString3(paymentData.handler_id);
786
813
  if (!raw) return { raw: void 0, type: null, provider };
787
814
  const type = classifyPaymentToken(raw);
788
815
  return { raw, type, provider };
@@ -825,7 +852,7 @@ function coerceString3(v) {
825
852
 
826
853
  // src/transport/vi.ts
827
854
  import { splitSdJwt, decodeSdJwtSync } from "@sd-jwt/core";
828
- import { createHash } from "crypto";
855
+ import { createHash as createHash2 } from "crypto";
829
856
  function extractVIClaims(sdJwtCompact) {
830
857
  if (!sdJwtCompact || typeof sdJwtCompact !== "string") return null;
831
858
  let decoded;
@@ -976,7 +1003,7 @@ function coerceNumber2(v) {
976
1003
  }
977
1004
  function sha256Sync(data) {
978
1005
  const buf = typeof data === "string" ? Buffer.from(data, "utf-8") : Buffer.from(new Uint8Array(data));
979
- const hash = createHash("sha256").update(buf).digest();
1006
+ const hash = createHash2("sha256").update(buf).digest();
980
1007
  return new Uint8Array(hash.buffer, hash.byteOffset, hash.byteLength);
981
1008
  }
982
1009
 
@@ -1218,7 +1245,7 @@ var claim = {
1218
1245
 
1219
1246
  // src/transport/ap2.ts
1220
1247
  import { decodeSdJwtSync as decodeSdJwtSync2 } from "@sd-jwt/core";
1221
- import { createHash as createHash2 } from "crypto";
1248
+ import { createHash as createHash3 } from "crypto";
1222
1249
  function extractAP2Mandate(sdJwtCompact) {
1223
1250
  if (!sdJwtCompact || typeof sdJwtCompact !== "string") return null;
1224
1251
  let decoded;
@@ -1358,7 +1385,7 @@ function coerceStringOrNumber(v) {
1358
1385
  }
1359
1386
  function sha256Sync2(data) {
1360
1387
  const buf = typeof data === "string" ? Buffer.from(data, "utf-8") : Buffer.from(new Uint8Array(data));
1361
- const hash = createHash2("sha256").update(buf).digest();
1388
+ const hash = createHash3("sha256").update(buf).digest();
1362
1389
  return new Uint8Array(hash.buffer, hash.byteOffset, hash.byteLength);
1363
1390
  }
1364
1391
 
@@ -1645,8 +1672,10 @@ async function getSubtle() {
1645
1672
  // src/transport/mpp.ts
1646
1673
  import { Challenge, Credential, Receipt } from "mppx";
1647
1674
  function extractMPPFromRequest(request) {
1648
- const auth = readHeader3(request.headers, "authorization");
1649
- if (!auth || !/^\s*Payment\s+/i.test(auth)) return null;
1675
+ const alt = readHeader3(request.headers, "payment-authorization");
1676
+ const authHeader = readHeader3(request.headers, "authorization");
1677
+ const auth = authHeader && /^\s*Payment\s+/i.test(authHeader) ? authHeader : alt ? /^\s*Payment\s+/i.test(alt) ? alt : `Payment ${alt.trim()}` : void 0;
1678
+ if (!auth) return null;
1650
1679
  try {
1651
1680
  const credential = Credential.deserialize(auth);
1652
1681
  return {
@@ -1836,6 +1865,16 @@ import {
1836
1865
  } from "@x402/core/schemas";
1837
1866
  import { safeBase64Decode } from "@x402/core/utils";
1838
1867
  function extractX402FromRequest(request) {
1868
+ const v2Header = readHeader4(request.headers, "payment-signature");
1869
+ if (v2Header) {
1870
+ try {
1871
+ const decoded = safeBase64Decode(v2Header);
1872
+ const parsed = decoded ? tryParsePayload(JSON.parse(decoded)) : null;
1873
+ if (parsed) return buildPayloadContext(parsed, "header");
1874
+ } catch {
1875
+ }
1876
+ return { kind: "error", version: 2, source: "header", error: { type: "invalid-x402-payload" } };
1877
+ }
1839
1878
  const headerValue = readHeader4(request.headers, "x-payment");
1840
1879
  if (request.body && typeof request.body === "object") {
1841
1880
  const parsed = tryParsePayload(request.body);
@@ -1862,6 +1901,21 @@ function extractX402FromRequest(request) {
1862
1901
  }
1863
1902
  function extractX402FromResponse(response) {
1864
1903
  if (response.status !== 402) return null;
1904
+ const v2Header = readHeader4(response.headers, "payment-required");
1905
+ if (v2Header) {
1906
+ try {
1907
+ const decoded = safeBase64Decode(v2Header);
1908
+ const parsed = decoded ? tryParseRequired(JSON.parse(decoded)) : null;
1909
+ if (parsed) return buildRequiredContext(parsed, "header");
1910
+ } catch {
1911
+ }
1912
+ return {
1913
+ kind: "error",
1914
+ version: 2,
1915
+ source: "header",
1916
+ error: { type: "invalid-x402-required" }
1917
+ };
1918
+ }
1865
1919
  if (response.body && typeof response.body === "object") {
1866
1920
  const parsed = tryParseRequired(response.body);
1867
1921
  if (parsed) return buildRequiredContext(parsed, "body");
@@ -1979,7 +2033,7 @@ function readHeader4(headers, name) {
1979
2033
  }
1980
2034
 
1981
2035
  // src/transport/vi-verify.ts
1982
- import { createHash as createHash3, webcrypto } from "crypto";
2036
+ import { createHash as createHash4, webcrypto } from "crypto";
1983
2037
  async function verifyVIChain(input) {
1984
2038
  const errors = [];
1985
2039
  const tolerance = input.clockSkewSec ?? 60;
@@ -2120,7 +2174,7 @@ function computeCheckoutHashFromL2(l2) {
2120
2174
  const checkoutDisclosure = l2.payload.checkout ?? l2.payload.checkout_mandate;
2121
2175
  if (!checkoutDisclosure) return null;
2122
2176
  const canonical = canonicalStringify(checkoutDisclosure);
2123
- const hash = createHash3("sha256").update(canonical).digest("base64url").replace(/=+$/, "");
2177
+ const hash = createHash4("sha256").update(canonical).digest("base64url").replace(/=+$/, "");
2124
2178
  return hash;
2125
2179
  }
2126
2180
  function canonicalStringify(value) {
@@ -2375,6 +2429,8 @@ function resolvePaymentToken(input) {
2375
2429
  const mppMethod = input.mpp?.context.credential?.challenge?.method;
2376
2430
  if (mppMethod === "tempo") return { present: true, type: "tempo-tx" };
2377
2431
  if (mppMethod === "stripe") return { present: true, type: "stripe-spt" };
2432
+ if (input.x402?.paymentPayload) return { present: true, type: "x402-payload" };
2433
+ if (input.ap2?.triple.payment) return { present: true, type: "ap2-payment-mandate" };
2378
2434
  return void 0;
2379
2435
  }
2380
2436
  function runConstraintEval(input) {