@orangecheck/me-client 0.63.0 → 0.64.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/server.mjs CHANGED
@@ -1,10 +1,18 @@
1
1
  import { verifyOcToken as verifyOcToken$1, checkOcToken as checkOcToken$1, readOcSessionToken, SAFE_METHODS, readBondNeed, familyRevocationCheck, integratorRevocationCheck, bondMeets, readBondClaim } from '@orangecheck/auth-core';
2
2
  export { bondMeets, readBondClaim, readBondNeed } from '@orangecheck/auth-core';
3
+ import { parseIssuerOrigin, ISSUER_ORIGIN_RULE } from '@orangecheck/auth-core/issuer-origin';
3
4
  import { isDidOc } from '@orangecheck/auth-core/identifiers';
4
5
 
5
6
  var __defProp = Object.defineProperty;
6
7
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
8
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
9
+ function issuerOrigin(value, what) {
10
+ const origin = parseIssuerOrigin(value);
11
+ if (origin === null) {
12
+ throw new TypeError(`@orangecheck/me-client: ${what} must be ${ISSUER_ORIGIN_RULE}; got ${JSON.stringify(value)}`);
13
+ }
14
+ return origin;
15
+ }
8
16
 
9
17
  // src/own-options.ts
10
18
  function inheritedKeys(opts, known) {
@@ -305,8 +313,6 @@ async function importJWK(jwk, alg, options) {
305
313
  throw new JOSENotSupported('Unsupported "kty" (Key Type) Parameter value');
306
314
  }
307
315
  }
308
-
309
- // src/identity.ts
310
316
  var DEFAULT_ISSUER = "https://me.ochk.io";
311
317
  var DEFAULT_TTL_MS = 60 * 60 * 1e3;
312
318
  var DEFAULT_MAX_STALE_MS = 6 * 60 * 60 * 1e3;
@@ -506,7 +512,12 @@ async function verifyActivityAttestation(bundle, options = {}) {
506
512
  return { ok: false, reason: "provided jwk failed import", checks };
507
513
  }
508
514
  } else {
509
- const issuer = options.issuer ?? DEFAULT_ISSUER;
515
+ const issuer = parseIssuerOrigin(options.issuer ?? DEFAULT_ISSUER);
516
+ if (issuer === null) {
517
+ const reason = `issuer must be ${ISSUER_ORIGIN_RULE}`;
518
+ checks.push({ ok: false, label: "JWK with matching kid present", detail: reason });
519
+ return { ok: false, reason, checks };
520
+ }
510
521
  const ttl = options.jwksCacheTtlMs ?? DEFAULT_TTL_MS;
511
522
  const maxStale = options.jwksMaxStaleMs ?? DEFAULT_MAX_STALE_MS;
512
523
  try {
@@ -566,8 +577,9 @@ async function verifyActivityAttestation(bundle, options = {}) {
566
577
  return { ok: true, attestation: signed, checks };
567
578
  }
568
579
  async function refreshEnvelopeJwks(issuer = DEFAULT_ISSUER) {
569
- jwksCache.delete(issuer);
570
- await fetchEnvelopeJwks(issuer, DEFAULT_TTL_MS);
580
+ const origin = issuerOrigin(issuer, "refreshEnvelopeJwks: issuer");
581
+ jwksCache.delete(origin);
582
+ await fetchEnvelopeJwks(origin, DEFAULT_TTL_MS);
571
583
  }
572
584
  var identity = {
573
585
  verifyActivityAttestation,
@@ -774,23 +786,6 @@ function spendOnce(jti, exp, store) {
774
786
  });
775
787
  }
776
788
  var REVOKE_OPTIONS = /* @__PURE__ */ new Set(["issuer", "timeoutMs"]);
777
- function issuerOrigin(issuer, where = "revokeToken") {
778
- if (typeof issuer !== "string") fail2(`${where}: issuer must be a URL`);
779
- const refuse = () => fail2(`${where}: issuer must be one https origin (http only on this machine), such as https://ochk.io, got ${issuer}`);
780
- if (/[?#@\\]/.test(issuer)) refuse();
781
- let url;
782
- try {
783
- url = new URL(issuer);
784
- } catch {
785
- return refuse();
786
- }
787
- const local = ["localhost", "127.0.0.1", "[::1]"].includes(url.hostname);
788
- if (url.protocol !== "https:" && !(url.protocol === "http:" && local)) refuse();
789
- if (url.pathname !== "/" || url.search !== "" || url.hash !== "" || url.username !== "" || url.password !== "") {
790
- refuse();
791
- }
792
- return url.origin;
793
- }
794
789
  function revokeToken(token, options = {}) {
795
790
  if (options === null || typeof options !== "object") fail2("revokeToken: options must be an object");
796
791
  const unknown = Object.keys(options).filter((k) => !REVOKE_OPTIONS.has(k));
@@ -803,7 +798,7 @@ function revokeToken(token, options = {}) {
803
798
  if (!tokens || tokens.length < 1 || tokens.length > MAX_TOKENS || !tokens.every((t) => typeof t === "string" && t.length > 0 && t.length <= MAX_TOKEN_LENGTH)) {
804
799
  fail2(`revokeToken: pass one token, or 1 to ${MAX_TOKENS}, each a non-empty string of at most ${MAX_TOKEN_LENGTH} characters`);
805
800
  }
806
- const origin = issuerOrigin(options.issuer ?? DEFAULT_ISSUER2);
801
+ const origin = issuerOrigin(options.issuer ?? DEFAULT_ISSUER2, "revokeToken: issuer");
807
802
  const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS2;
808
803
  if (typeof timeoutMs !== "number" || !(timeoutMs > 0 && timeoutMs <= MAX_TIMEOUT_MS2)) {
809
804
  fail2(`revokeToken: timeoutMs must be above 0 and at most ${MAX_TIMEOUT_MS2}`);
@@ -885,7 +880,8 @@ async function exchangeNativeCode(input, options = {}) {
885
880
  if (typeof projectKey !== "string" || projectKey.length === 0 || projectKey.length > MAX_FIELD_LENGTH) {
886
881
  fail3("needs your project key: options.projectKey, or OC_PROJECT_KEY");
887
882
  }
888
- const issuer = issuerOrigin(options.issuer ?? DEFAULT_ISSUER3, "exchangeNativeCode");
883
+ const issuer = issuerOrigin(options.issuer ?? DEFAULT_ISSUER3, "exchangeNativeCode: issuer");
884
+ const meOrigin = options.meOrigin === void 0 ? void 0 : issuerOrigin(options.meOrigin, "exchangeNativeCode: meOrigin");
889
885
  const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS3;
890
886
  if (typeof timeoutMs !== "number" || !(timeoutMs > 0 && timeoutMs <= MAX_TIMEOUT_MS3)) {
891
887
  fail3(`timeoutMs must be above 0 and at most ${MAX_TIMEOUT_MS3}`);
@@ -896,7 +892,7 @@ async function exchangeNativeCode(input, options = {}) {
896
892
  const verified = await checkOcToken(token, { audience: input.audience, issuer });
897
893
  if (verified.status === "unavailable") return { status: "unavailable", reason: "key_set_unavailable" };
898
894
  if (verified.status === "invalid") return { status: "invalid", reason: verified.reason ?? "invalid_token" };
899
- const where = options.meOrigin ? { meOrigin: options.meOrigin } : {};
895
+ const where = meOrigin ? { meOrigin } : {};
900
896
  const checked = await checkOcSession(
901
897
  { authorization: `Bearer ${token}` },
902
898
  {
@@ -1186,6 +1182,8 @@ function checkOptions(options) {
1186
1182
  );
1187
1183
  }
1188
1184
  refuseInherited("", options, KNOWN_OPTIONS);
1185
+ if (options.issuer !== void 0) issuerOrigin(options.issuer, "issuer");
1186
+ if (options.meOrigin !== void 0) issuerOrigin(options.meOrigin, "meOrigin");
1189
1187
  checkRequireHandle(options.requireHandle);
1190
1188
  const bond = options.requireBond;
1191
1189
  if (bond === void 0) return;
@@ -1229,7 +1227,7 @@ function standing(slot) {
1229
1227
  return hit?.at && since(hit.at) < POLICY_MAX_STALE_MS ? hit.need : void 0;
1230
1228
  }
1231
1229
  async function projectRequirement(options) {
1232
- const base = (options.meOrigin ?? "https://me.ochk.io").replace(/\/$/, "");
1230
+ const base = issuerOrigin(options.meOrigin ?? "https://me.ochk.io", "meOrigin");
1233
1231
  const key = options.projectKey;
1234
1232
  const slot = `${base} ${key}`;
1235
1233
  const unknownAt = unknownKeys.get(slot);