@orangecheck/me-client 0.63.0 → 0.65.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/CHANGELOG.md CHANGED
@@ -10,6 +10,77 @@ this file tracks the package's TS / Node / runtime API surface.
10
10
 
11
11
  ## [Unreleased]
12
12
 
13
+ ## [0.65.0] — 2026-11-25
14
+
15
+ ### Changed
16
+
17
+ - `webhook.verify` refuses every delivery, before it fetches a key, when
18
+ `maxAgeSeconds` is set to anything but a finite number above 0 (NaN from an
19
+ unset env var, Infinity, 0, a negative, a string or null). Left out, it is
20
+ still a day.
21
+
22
+ ## [0.64.0] — 2026-11-24
23
+
24
+ ### Added
25
+
26
+ - `webhook.verify` takes `project`, your project key, and refuses a delivery
27
+ signed for another project. It is optional until the next major version; a
28
+ verify without it warns once per process.
29
+ - On success `webhook.verify` answers the delivery's signed `id`,
30
+ `project_key` and `issued_at`. Deduplicate on that `id`, for billable events
31
+ and project notices alike.
32
+ - `maxAgeSeconds`: the oldest delivery accepted, in seconds since it was
33
+ signed. Defaults to a day.
34
+ - `WebhookPayload` carries `project_key` and `issued_at`; `SystemWebhookPayload`
35
+ carries `id` and `issued_at`.
36
+
37
+ ### Changed
38
+
39
+ - **Every issuer and `meOrigin` is taken by auth-core's one rule**
40
+ (`parseIssuerOrigin`, so `@orangecheck/auth-core` is now `^2.34.0`): one origin
41
+ with no path, https, or http on `localhost`, `127.0.0.1` or `[::1]`. That
42
+ covers `revokeToken`, `exchangeNativeCode`, `checkOcSession`, `withOcAuth`,
43
+ `ocAuthExpress`, `ocAuthHono`, `checkSignInRule`, `webhook.verify`,
44
+ `webhook.fetchJwks`, `identity.verifyActivityAttestation` and
45
+ `identity.refreshEnvelopeJwks`. Every origin that was already one origin
46
+ answers as before.
47
+ - **Where a refused one is caught.** The adapters throw when they are made,
48
+ `checkOcSession` and `checkSignInRule` when they are called, and
49
+ `exchangeNativeCode` before it sends anything. `webhook.verify` and
50
+ `verifyActivityAttestation`, which never throw, answer `ok: false` with the
51
+ rule as the reason and fetch nothing.
52
+ - `webhook.verify` refuses a delivery whose signed body has no `id`,
53
+ `project_key` or `issued_at` (an ISO time in UTC, as `toISOString` writes
54
+ it), one signed more than a day ago, and one more than five minutes ahead
55
+ of this clock. me.ochk.io signs all three into every delivery, and has for
56
+ at least a day before this release. It signs each send as it sends it, a
57
+ retry or a dead letter sent again included, so a retry is as fresh as its
58
+ send and keeps the delivery's `id`.
59
+
60
+ ### Now refused
61
+
62
+ As the issuer of `revokeToken` and `exchangeNativeCode`, each of these used to
63
+ be accepted:
64
+
65
+ - the scheme's own port, port 0, an empty port or a leading zero:
66
+ `https://ochk.io:443`, `http://localhost:80`, `https://ochk.io:0`,
67
+ `https://ochk.io:`, `https://ochk.io:08443`
68
+ - no `//` after the scheme: `https:ochk.io`, `https:/ochk.io`
69
+ - a space at either end, or a tab or newline anywhere
70
+ - a trailing dot, a label that starts or ends with a hyphen, an underscore, a
71
+ percent escape: `https://ochk.io.`, `https://-ochk.io`, `https://och_k.io`,
72
+ `https://och%6b.io`
73
+ - a host outside printable ASCII: `https://bücher.example` (write its
74
+ `xn--` form), a Kelvin sign for `k`, a NUL
75
+ - a short or zero-padded IPv4 address, or a long form of `[::1]`:
76
+ `http://127.1:3000`, `https://127.1`, `https://192.0.2`, `https://01.2.3.4`,
77
+ `http://[0:0:0:0:0:0:0:1]:3000`
78
+
79
+ As `meOrigin` anywhere, and as the issuer `webhook` and `identity` read keys
80
+ from, which were taken as given: anything that is not one origin, all of the
81
+ above included, plus a path, a query, a fragment, a user name, and plain http
82
+ to any host but `localhost`, `127.0.0.1` and `[::1]`.
83
+
13
84
  ## [0.63.0] — 2026-11-20
14
85
 
15
86
  ### Added
package/dist/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { v as verifyActivityAttestation, r as refreshEnvelopeJwks } from './identity-DfxCvxuH.mjs';
2
2
  export { A as ActivityAttestation, a as ActivityAttestationBundle, b as ActivityVerifyCheck, c as ActivityVerifyResult, V as VerifyActivityOptions, i as identity } from './identity-DfxCvxuH.mjs';
3
- import { S as Scope, B as BillableEvent, D as DropResponseBlock, E as EventKey, I as IntegratorPriceConfig, T as TelemetryEvent, a as SignInOptions, b as Session, P as PaymentAuthorizeOptions, c as PaymentResult, V as ValidationResult, f as fromTemplate, g as getArchetypeTemplate, A as ArchetypeTemplate, F as Federation, G as GrantedOptions, d as GrantedResult, r as request, p as parseTrustAttestationCount } from './integrator-BiJgTlse.mjs';
4
- export { e as ALL_EVENT_SUBTYPES, h as ARCHETYPE_TEMPLATES, i as AgentClassOverride, j as AttestTier, C as CUSTOM_EVENT_KEY_RE, k as ClassASubtype, l as ClassBSubtype, m as ClassCSubtype, n as ComputedFees, o as DropCadence, q as DropClosedWebhookPayload, s as DropScheduleSummary, t as EVENT_SUBTYPES, u as EventClass, v as EventSubtype, w as EventSubtypeMetadata, x as FederationMigratingWebhookPayload, y as FederationMigrationCancelledWebhookPayload, z as FederationStatus, H as FederationSuccessor, J as IntegratorArchetype, K as IntegratorEventConfig, M as MAX_DROP_WINDOW_DAYS, L as MIN_INTEGRATOR_PRICE_SATS, N as PLATFORM_FEE_POLICY, R as RequestOptions, O as SCOPE_IDS, Q as SessionPolicy, U as SigningMethod, W as SiteFeeShape, X as SystemWebhookPayload, Y as TrustAttestationCount, Z as WebhookHeaders, _ as WebhookPayload, $ as computeFees, a0 as isEventClass, a1 as isInheritedName, a2 as scope, a3 as subtypesForClass, a4 as validateIntegratorConfig } from './integrator-BiJgTlse.mjs';
3
+ import { S as Scope, B as BillableEvent, D as DropResponseBlock, E as EventKey, I as IntegratorPriceConfig, T as TelemetryEvent, a as SignInOptions, b as Session, P as PaymentAuthorizeOptions, c as PaymentResult, V as ValidationResult, f as fromTemplate, g as getArchetypeTemplate, A as ArchetypeTemplate, F as Federation, G as GrantedOptions, d as GrantedResult, r as request, p as parseTrustAttestationCount } from './integrator-DDLwyj8-.mjs';
4
+ export { e as ALL_EVENT_SUBTYPES, h as ARCHETYPE_TEMPLATES, i as AgentClassOverride, j as AttestTier, C as CUSTOM_EVENT_KEY_RE, k as ClassASubtype, l as ClassBSubtype, m as ClassCSubtype, n as ComputedFees, o as DropCadence, q as DropClosedWebhookPayload, s as DropScheduleSummary, t as EVENT_SUBTYPES, u as EventClass, v as EventSubtype, w as EventSubtypeMetadata, x as FederationMigratingWebhookPayload, y as FederationMigrationCancelledWebhookPayload, z as FederationStatus, H as FederationSuccessor, J as IntegratorArchetype, K as IntegratorEventConfig, M as MAX_DROP_WINDOW_DAYS, L as MIN_INTEGRATOR_PRICE_SATS, N as PLATFORM_FEE_POLICY, R as RequestOptions, O as SCOPE_IDS, Q as SessionPolicy, U as SigningMethod, W as SiteFeeShape, X as SystemWebhookPayload, Y as TrustAttestationCount, Z as WebhookHeaders, _ as WebhookPayload, $ as computeFees, a0 as isEventClass, a1 as isInheritedName, a2 as scope, a3 as subtypesForClass, a4 as validateIntegratorConfig } from './integrator-DDLwyj8-.mjs';
5
5
  export { CONNECT_CONSENT_BLURB, CONNECT_CONSENT_LABEL } from './connect-consent.mjs';
6
6
 
7
7
  type FamilyVerb = 'oc-vote' | 'oc-stamp' | 'oc-agent' | 'oc-attest' | 'oc-lock' | 'oc-pledge';
@@ -27,6 +27,9 @@ declare const family: {
27
27
  interface VerifyResult {
28
28
  ok: boolean;
29
29
  reason?: string;
30
+ id?: string;
31
+ project_key?: string;
32
+ issued_at?: string;
30
33
  }
31
34
  interface OcPublicJwk {
32
35
  kty: 'OKP';
@@ -41,6 +44,8 @@ interface VerifyOptions {
41
44
  jwk?: OcPublicJwk;
42
45
  jwksCacheTtlMs?: number;
43
46
  jwksMaxStaleMs?: number;
47
+ project?: string;
48
+ maxAgeSeconds?: number;
44
49
  }
45
50
  declare function verify$1(rawBody: string | Uint8Array, sigHex: string | null | undefined, kid: string | null | undefined, options?: VerifyOptions): Promise<VerifyResult>;
46
51
  declare function fetchJwksForce(issuer?: string): Promise<void>;
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { v as verifyActivityAttestation, r as refreshEnvelopeJwks } from './identity-DfxCvxuH.js';
2
2
  export { A as ActivityAttestation, a as ActivityAttestationBundle, b as ActivityVerifyCheck, c as ActivityVerifyResult, V as VerifyActivityOptions, i as identity } from './identity-DfxCvxuH.js';
3
- import { S as Scope, B as BillableEvent, D as DropResponseBlock, E as EventKey, I as IntegratorPriceConfig, T as TelemetryEvent, a as SignInOptions, b as Session, P as PaymentAuthorizeOptions, c as PaymentResult, V as ValidationResult, f as fromTemplate, g as getArchetypeTemplate, A as ArchetypeTemplate, F as Federation, G as GrantedOptions, d as GrantedResult, r as request, p as parseTrustAttestationCount } from './integrator-BiJgTlse.js';
4
- export { e as ALL_EVENT_SUBTYPES, h as ARCHETYPE_TEMPLATES, i as AgentClassOverride, j as AttestTier, C as CUSTOM_EVENT_KEY_RE, k as ClassASubtype, l as ClassBSubtype, m as ClassCSubtype, n as ComputedFees, o as DropCadence, q as DropClosedWebhookPayload, s as DropScheduleSummary, t as EVENT_SUBTYPES, u as EventClass, v as EventSubtype, w as EventSubtypeMetadata, x as FederationMigratingWebhookPayload, y as FederationMigrationCancelledWebhookPayload, z as FederationStatus, H as FederationSuccessor, J as IntegratorArchetype, K as IntegratorEventConfig, M as MAX_DROP_WINDOW_DAYS, L as MIN_INTEGRATOR_PRICE_SATS, N as PLATFORM_FEE_POLICY, R as RequestOptions, O as SCOPE_IDS, Q as SessionPolicy, U as SigningMethod, W as SiteFeeShape, X as SystemWebhookPayload, Y as TrustAttestationCount, Z as WebhookHeaders, _ as WebhookPayload, $ as computeFees, a0 as isEventClass, a1 as isInheritedName, a2 as scope, a3 as subtypesForClass, a4 as validateIntegratorConfig } from './integrator-BiJgTlse.js';
3
+ import { S as Scope, B as BillableEvent, D as DropResponseBlock, E as EventKey, I as IntegratorPriceConfig, T as TelemetryEvent, a as SignInOptions, b as Session, P as PaymentAuthorizeOptions, c as PaymentResult, V as ValidationResult, f as fromTemplate, g as getArchetypeTemplate, A as ArchetypeTemplate, F as Federation, G as GrantedOptions, d as GrantedResult, r as request, p as parseTrustAttestationCount } from './integrator-DDLwyj8-.js';
4
+ export { e as ALL_EVENT_SUBTYPES, h as ARCHETYPE_TEMPLATES, i as AgentClassOverride, j as AttestTier, C as CUSTOM_EVENT_KEY_RE, k as ClassASubtype, l as ClassBSubtype, m as ClassCSubtype, n as ComputedFees, o as DropCadence, q as DropClosedWebhookPayload, s as DropScheduleSummary, t as EVENT_SUBTYPES, u as EventClass, v as EventSubtype, w as EventSubtypeMetadata, x as FederationMigratingWebhookPayload, y as FederationMigrationCancelledWebhookPayload, z as FederationStatus, H as FederationSuccessor, J as IntegratorArchetype, K as IntegratorEventConfig, M as MAX_DROP_WINDOW_DAYS, L as MIN_INTEGRATOR_PRICE_SATS, N as PLATFORM_FEE_POLICY, R as RequestOptions, O as SCOPE_IDS, Q as SessionPolicy, U as SigningMethod, W as SiteFeeShape, X as SystemWebhookPayload, Y as TrustAttestationCount, Z as WebhookHeaders, _ as WebhookPayload, $ as computeFees, a0 as isEventClass, a1 as isInheritedName, a2 as scope, a3 as subtypesForClass, a4 as validateIntegratorConfig } from './integrator-DDLwyj8-.js';
5
5
  export { CONNECT_CONSENT_BLURB, CONNECT_CONSENT_LABEL } from './connect-consent.js';
6
6
 
7
7
  type FamilyVerb = 'oc-vote' | 'oc-stamp' | 'oc-agent' | 'oc-attest' | 'oc-lock' | 'oc-pledge';
@@ -27,6 +27,9 @@ declare const family: {
27
27
  interface VerifyResult {
28
28
  ok: boolean;
29
29
  reason?: string;
30
+ id?: string;
31
+ project_key?: string;
32
+ issued_at?: string;
30
33
  }
31
34
  interface OcPublicJwk {
32
35
  kty: 'OKP';
@@ -41,6 +44,8 @@ interface VerifyOptions {
41
44
  jwk?: OcPublicJwk;
42
45
  jwksCacheTtlMs?: number;
43
46
  jwksMaxStaleMs?: number;
47
+ project?: string;
48
+ maxAgeSeconds?: number;
44
49
  }
45
50
  declare function verify$1(rawBody: string | Uint8Array, sigHex: string | null | undefined, kid: string | null | undefined, options?: VerifyOptions): Promise<VerifyResult>;
46
51
  declare function fetchJwksForce(issuer?: string): Promise<void>;
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ var issuerOrigin$1 = require('@orangecheck/auth-core/issuer-origin');
3
4
  var identifiers = require('@orangecheck/auth-core/identifiers');
4
5
 
5
6
  var __defProp = Object.defineProperty;
@@ -1180,6 +1181,13 @@ async function importJWK(jwk, alg, options) {
1180
1181
  throw new JOSENotSupported('Unsupported "kty" (Key Type) Parameter value');
1181
1182
  }
1182
1183
  }
1184
+ function issuerOrigin(value, what) {
1185
+ const origin2 = issuerOrigin$1.parseIssuerOrigin(value);
1186
+ if (origin2 === null) {
1187
+ throw new TypeError(`@orangecheck/me-client: ${what} must be ${issuerOrigin$1.ISSUER_ORIGIN_RULE}; got ${JSON.stringify(value)}`);
1188
+ }
1189
+ return origin2;
1190
+ }
1183
1191
 
1184
1192
  // src/webhook.ts
1185
1193
  var DEFAULT_ISSUER = "https://me.ochk.io";
@@ -1187,6 +1195,46 @@ var JWKS_PATH = "/api/dev-jwks";
1187
1195
  var DEFAULT_TTL_MS = 60 * 60 * 1e3;
1188
1196
  var DEFAULT_MAX_STALE_MS = 6 * 60 * 60 * 1e3;
1189
1197
  var FORCED_REFRESH_MIN_INTERVAL_MS = 6e4;
1198
+ var DEFAULT_MAX_AGE_SECONDS = 24 * 60 * 60;
1199
+ var FUTURE_SKEW_MS = 5 * 60 * 1e3;
1200
+ var ISSUED_AT = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,9})?Z$/;
1201
+ var warnedNoProject = false;
1202
+ function warnNoProjectOnce() {
1203
+ if (warnedNoProject) return;
1204
+ warnedNoProject = true;
1205
+ console.warn(
1206
+ "@orangecheck/me-client: webhook.verify was called without `project`, so it accepts a delivery signed for any project. Pass your project key; it is required from the next major version."
1207
+ );
1208
+ }
1209
+ function isIsoTime(v) {
1210
+ if (!ISSUED_AT.test(v)) return false;
1211
+ const t = Date.parse(v);
1212
+ return Number.isFinite(t) && new Date(t).toISOString().slice(0, 19) === v.slice(0, 19);
1213
+ }
1214
+ function signedFields(msg, options, maxAgeSeconds) {
1215
+ let parsed;
1216
+ try {
1217
+ parsed = JSON.parse(new TextDecoder().decode(msg));
1218
+ } catch {
1219
+ return { ok: false, reason: "body is not JSON" };
1220
+ }
1221
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
1222
+ return { ok: false, reason: "body is not a JSON object" };
1223
+ }
1224
+ const { id, project_key, issued_at } = parsed;
1225
+ if (typeof id !== "string" || id === "" || typeof project_key !== "string" || project_key === "" || typeof issued_at !== "string" || !isIsoTime(issued_at)) {
1226
+ return { ok: false, reason: "missing a signed id, project_key or issued_at" };
1227
+ }
1228
+ if (options.project !== void 0 && project_key !== options.project) {
1229
+ return { ok: false, reason: `signed for another project (${project_key})` };
1230
+ }
1231
+ const age = Date.now() - Date.parse(issued_at);
1232
+ if (age > maxAgeSeconds * 1e3) {
1233
+ return { ok: false, reason: "older than the accepted age (issued_at)" };
1234
+ }
1235
+ if (-age > FUTURE_SKEW_MS) return { ok: false, reason: "issued_at is in the future" };
1236
+ return { ok: true, id, project_key, issued_at };
1237
+ }
1190
1238
  var jwksCache = /* @__PURE__ */ new Map();
1191
1239
  var inflight = /* @__PURE__ */ new Map();
1192
1240
  var lastForcedRefresh = /* @__PURE__ */ new Map();
@@ -1262,6 +1310,11 @@ async function verifyEd25519(key, sig2, msg) {
1262
1310
  }
1263
1311
  }
1264
1312
  async function verify2(rawBody, sigHex, kid, options = {}) {
1313
+ if (options.project === void 0) warnNoProjectOnce();
1314
+ const maxAgeSeconds = options.maxAgeSeconds === void 0 ? DEFAULT_MAX_AGE_SECONDS : options.maxAgeSeconds;
1315
+ if (!Number.isFinite(maxAgeSeconds) || maxAgeSeconds <= 0) {
1316
+ return { ok: false, reason: "maxAgeSeconds must be a finite number above 0" };
1317
+ }
1265
1318
  if (!sigHex) return { ok: false, reason: "missing signature" };
1266
1319
  if (!kid) return { ok: false, reason: "missing kid" };
1267
1320
  const sig2 = hexToBytes(sigHex);
@@ -1278,7 +1331,8 @@ async function verify2(rawBody, sigHex, kid, options = {}) {
1278
1331
  return { ok: false, reason: "could not import provided jwk" };
1279
1332
  }
1280
1333
  } else {
1281
- const issuer = options.issuer ?? DEFAULT_ISSUER;
1334
+ const issuer = issuerOrigin$1.parseIssuerOrigin(options.issuer ?? DEFAULT_ISSUER);
1335
+ if (issuer === null) return { ok: false, reason: `issuer must be ${issuerOrigin$1.ISSUER_ORIGIN_RULE}` };
1282
1336
  const ttl = options.jwksCacheTtlMs ?? DEFAULT_TTL_MS;
1283
1337
  const maxStale = options.jwksMaxStaleMs ?? DEFAULT_MAX_STALE_MS;
1284
1338
  try {
@@ -1294,12 +1348,13 @@ async function verify2(rawBody, sigHex, kid, options = {}) {
1294
1348
  }
1295
1349
  if (!key) return { ok: false, reason: `kid ${kid} not in JWKS` };
1296
1350
  }
1297
- const ok = await verifyEd25519(key, sig2, msg);
1298
- return ok ? { ok: true } : { ok: false, reason: "signature does not match" };
1351
+ if (!await verifyEd25519(key, sig2, msg)) return { ok: false, reason: "signature does not match" };
1352
+ return signedFields(msg, options, maxAgeSeconds);
1299
1353
  }
1300
1354
  async function fetchJwksForce(issuer = DEFAULT_ISSUER) {
1301
- jwksCache.delete(issuer);
1302
- await fetchJwks(issuer, DEFAULT_TTL_MS);
1355
+ const origin2 = issuerOrigin(issuer, "webhook.fetchJwks: issuer");
1356
+ jwksCache.delete(origin2);
1357
+ await fetchJwks(origin2, DEFAULT_TTL_MS);
1303
1358
  }
1304
1359
  var webhook = { verify: verify2, fetchJwks: fetchJwksForce };
1305
1360
 
@@ -1474,8 +1529,6 @@ function safeReturnPath(raw, fallback = "/") {
1474
1529
  return fallback;
1475
1530
  }
1476
1531
  }
1477
-
1478
- // src/identity.ts
1479
1532
  var DEFAULT_ISSUER2 = "https://me.ochk.io";
1480
1533
  var DEFAULT_TTL_MS2 = 60 * 60 * 1e3;
1481
1534
  var DEFAULT_MAX_STALE_MS2 = 6 * 60 * 60 * 1e3;
@@ -1675,7 +1728,12 @@ async function verifyActivityAttestation(bundle, options = {}) {
1675
1728
  return { ok: false, reason: "provided jwk failed import", checks };
1676
1729
  }
1677
1730
  } else {
1678
- const issuer = options.issuer ?? DEFAULT_ISSUER2;
1731
+ const issuer = issuerOrigin$1.parseIssuerOrigin(options.issuer ?? DEFAULT_ISSUER2);
1732
+ if (issuer === null) {
1733
+ const reason = `issuer must be ${issuerOrigin$1.ISSUER_ORIGIN_RULE}`;
1734
+ checks.push({ ok: false, label: "JWK with matching kid present", detail: reason });
1735
+ return { ok: false, reason, checks };
1736
+ }
1679
1737
  const ttl = options.jwksCacheTtlMs ?? DEFAULT_TTL_MS2;
1680
1738
  const maxStale = options.jwksMaxStaleMs ?? DEFAULT_MAX_STALE_MS2;
1681
1739
  try {
@@ -1735,8 +1793,9 @@ async function verifyActivityAttestation(bundle, options = {}) {
1735
1793
  return { ok: true, attestation: signed, checks };
1736
1794
  }
1737
1795
  async function refreshEnvelopeJwks(issuer = DEFAULT_ISSUER2) {
1738
- jwksCache2.delete(issuer);
1739
- await fetchEnvelopeJwks(issuer, DEFAULT_TTL_MS2);
1796
+ const origin2 = issuerOrigin(issuer, "refreshEnvelopeJwks: issuer");
1797
+ jwksCache2.delete(origin2);
1798
+ await fetchEnvelopeJwks(origin2, DEFAULT_TTL_MS2);
1740
1799
  }
1741
1800
  var identity = {
1742
1801
  verifyActivityAttestation,