@orangecheck/me-client 0.62.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/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) {
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 > (options.maxAgeSeconds ?? DEFAULT_MAX_AGE_SECONDS) * 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,7 @@ 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();
1265
1314
  if (!sigHex) return { ok: false, reason: "missing signature" };
1266
1315
  if (!kid) return { ok: false, reason: "missing kid" };
1267
1316
  const sig2 = hexToBytes(sigHex);
@@ -1278,7 +1327,8 @@ async function verify2(rawBody, sigHex, kid, options = {}) {
1278
1327
  return { ok: false, reason: "could not import provided jwk" };
1279
1328
  }
1280
1329
  } else {
1281
- const issuer = options.issuer ?? DEFAULT_ISSUER;
1330
+ const issuer = issuerOrigin$1.parseIssuerOrigin(options.issuer ?? DEFAULT_ISSUER);
1331
+ if (issuer === null) return { ok: false, reason: `issuer must be ${issuerOrigin$1.ISSUER_ORIGIN_RULE}` };
1282
1332
  const ttl = options.jwksCacheTtlMs ?? DEFAULT_TTL_MS;
1283
1333
  const maxStale = options.jwksMaxStaleMs ?? DEFAULT_MAX_STALE_MS;
1284
1334
  try {
@@ -1294,12 +1344,13 @@ async function verify2(rawBody, sigHex, kid, options = {}) {
1294
1344
  }
1295
1345
  if (!key) return { ok: false, reason: `kid ${kid} not in JWKS` };
1296
1346
  }
1297
- const ok = await verifyEd25519(key, sig2, msg);
1298
- return ok ? { ok: true } : { ok: false, reason: "signature does not match" };
1347
+ if (!await verifyEd25519(key, sig2, msg)) return { ok: false, reason: "signature does not match" };
1348
+ return signedFields(msg, options);
1299
1349
  }
1300
1350
  async function fetchJwksForce(issuer = DEFAULT_ISSUER) {
1301
- jwksCache.delete(issuer);
1302
- await fetchJwks(issuer, DEFAULT_TTL_MS);
1351
+ const origin2 = issuerOrigin(issuer, "webhook.fetchJwks: issuer");
1352
+ jwksCache.delete(origin2);
1353
+ await fetchJwks(origin2, DEFAULT_TTL_MS);
1303
1354
  }
1304
1355
  var webhook = { verify: verify2, fetchJwks: fetchJwksForce };
1305
1356
 
@@ -1474,8 +1525,6 @@ function safeReturnPath(raw, fallback = "/") {
1474
1525
  return fallback;
1475
1526
  }
1476
1527
  }
1477
-
1478
- // src/identity.ts
1479
1528
  var DEFAULT_ISSUER2 = "https://me.ochk.io";
1480
1529
  var DEFAULT_TTL_MS2 = 60 * 60 * 1e3;
1481
1530
  var DEFAULT_MAX_STALE_MS2 = 6 * 60 * 60 * 1e3;
@@ -1675,7 +1724,12 @@ async function verifyActivityAttestation(bundle, options = {}) {
1675
1724
  return { ok: false, reason: "provided jwk failed import", checks };
1676
1725
  }
1677
1726
  } else {
1678
- const issuer = options.issuer ?? DEFAULT_ISSUER2;
1727
+ const issuer = issuerOrigin$1.parseIssuerOrigin(options.issuer ?? DEFAULT_ISSUER2);
1728
+ if (issuer === null) {
1729
+ const reason = `issuer must be ${issuerOrigin$1.ISSUER_ORIGIN_RULE}`;
1730
+ checks.push({ ok: false, label: "JWK with matching kid present", detail: reason });
1731
+ return { ok: false, reason, checks };
1732
+ }
1679
1733
  const ttl = options.jwksCacheTtlMs ?? DEFAULT_TTL_MS2;
1680
1734
  const maxStale = options.jwksMaxStaleMs ?? DEFAULT_MAX_STALE_MS2;
1681
1735
  try {
@@ -1735,8 +1789,9 @@ async function verifyActivityAttestation(bundle, options = {}) {
1735
1789
  return { ok: true, attestation: signed, checks };
1736
1790
  }
1737
1791
  async function refreshEnvelopeJwks(issuer = DEFAULT_ISSUER2) {
1738
- jwksCache2.delete(issuer);
1739
- await fetchEnvelopeJwks(issuer, DEFAULT_TTL_MS2);
1792
+ const origin2 = issuerOrigin(issuer, "refreshEnvelopeJwks: issuer");
1793
+ jwksCache2.delete(origin2);
1794
+ await fetchEnvelopeJwks(origin2, DEFAULT_TTL_MS2);
1740
1795
  }
1741
1796
  var identity = {
1742
1797
  verifyActivityAttestation,