@orangecheck/me-client 0.19.0 → 0.20.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/identity-1VYMOhzV.d.mts +53 -0
- package/dist/identity-1VYMOhzV.d.ts +53 -0
- package/dist/index.d.mts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +231 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +229 -6
- package/dist/index.mjs.map +1 -1
- package/dist/server.d.mts +1 -0
- package/dist/server.d.ts +1 -0
- package/dist/server.js +442 -0
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +440 -1
- package/dist/server.mjs.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
interface ActivityAttestation {
|
|
2
|
+
id: string;
|
|
3
|
+
v: 1;
|
|
4
|
+
kind: 'oc-me-activity';
|
|
5
|
+
did_oc: string;
|
|
6
|
+
event_count: number;
|
|
7
|
+
human_event_count: number;
|
|
8
|
+
lifetime_sats: number;
|
|
9
|
+
distinct_integrator_count: number;
|
|
10
|
+
oldest_event_at: string | null;
|
|
11
|
+
active_days: number;
|
|
12
|
+
computed_at: string;
|
|
13
|
+
expires_at: string;
|
|
14
|
+
}
|
|
15
|
+
interface ActivityAttestationBundle {
|
|
16
|
+
attestation: ActivityAttestation;
|
|
17
|
+
sig: string;
|
|
18
|
+
kid: string;
|
|
19
|
+
canonical_b64: string;
|
|
20
|
+
}
|
|
21
|
+
interface ActivityVerifyCheck {
|
|
22
|
+
ok: boolean;
|
|
23
|
+
label: string;
|
|
24
|
+
detail?: string;
|
|
25
|
+
}
|
|
26
|
+
interface ActivityVerifyResult {
|
|
27
|
+
ok: boolean;
|
|
28
|
+
reason?: string;
|
|
29
|
+
attestation?: ActivityAttestation;
|
|
30
|
+
checks: ActivityVerifyCheck[];
|
|
31
|
+
}
|
|
32
|
+
interface OcEnvelopePublicJwk {
|
|
33
|
+
kty: 'OKP';
|
|
34
|
+
crv: 'Ed25519';
|
|
35
|
+
x: string;
|
|
36
|
+
kid: string;
|
|
37
|
+
alg?: 'EdDSA';
|
|
38
|
+
use?: 'sig';
|
|
39
|
+
}
|
|
40
|
+
interface VerifyActivityOptions {
|
|
41
|
+
issuer?: string;
|
|
42
|
+
jwk?: OcEnvelopePublicJwk;
|
|
43
|
+
jwksCacheTtlMs?: number;
|
|
44
|
+
now?: Date;
|
|
45
|
+
}
|
|
46
|
+
declare function verifyActivityAttestation(bundle: ActivityAttestationBundle, options?: VerifyActivityOptions): Promise<ActivityVerifyResult>;
|
|
47
|
+
declare function refreshEnvelopeJwks(issuer?: string): Promise<void>;
|
|
48
|
+
declare const identity: {
|
|
49
|
+
verifyActivityAttestation: typeof verifyActivityAttestation;
|
|
50
|
+
refreshEnvelopeJwks: typeof refreshEnvelopeJwks;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export { type ActivityAttestation as A, type VerifyActivityOptions as V, type ActivityAttestationBundle as a, type ActivityVerifyCheck as b, type ActivityVerifyResult as c, identity as i, refreshEnvelopeJwks as r, verifyActivityAttestation as v };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
interface ActivityAttestation {
|
|
2
|
+
id: string;
|
|
3
|
+
v: 1;
|
|
4
|
+
kind: 'oc-me-activity';
|
|
5
|
+
did_oc: string;
|
|
6
|
+
event_count: number;
|
|
7
|
+
human_event_count: number;
|
|
8
|
+
lifetime_sats: number;
|
|
9
|
+
distinct_integrator_count: number;
|
|
10
|
+
oldest_event_at: string | null;
|
|
11
|
+
active_days: number;
|
|
12
|
+
computed_at: string;
|
|
13
|
+
expires_at: string;
|
|
14
|
+
}
|
|
15
|
+
interface ActivityAttestationBundle {
|
|
16
|
+
attestation: ActivityAttestation;
|
|
17
|
+
sig: string;
|
|
18
|
+
kid: string;
|
|
19
|
+
canonical_b64: string;
|
|
20
|
+
}
|
|
21
|
+
interface ActivityVerifyCheck {
|
|
22
|
+
ok: boolean;
|
|
23
|
+
label: string;
|
|
24
|
+
detail?: string;
|
|
25
|
+
}
|
|
26
|
+
interface ActivityVerifyResult {
|
|
27
|
+
ok: boolean;
|
|
28
|
+
reason?: string;
|
|
29
|
+
attestation?: ActivityAttestation;
|
|
30
|
+
checks: ActivityVerifyCheck[];
|
|
31
|
+
}
|
|
32
|
+
interface OcEnvelopePublicJwk {
|
|
33
|
+
kty: 'OKP';
|
|
34
|
+
crv: 'Ed25519';
|
|
35
|
+
x: string;
|
|
36
|
+
kid: string;
|
|
37
|
+
alg?: 'EdDSA';
|
|
38
|
+
use?: 'sig';
|
|
39
|
+
}
|
|
40
|
+
interface VerifyActivityOptions {
|
|
41
|
+
issuer?: string;
|
|
42
|
+
jwk?: OcEnvelopePublicJwk;
|
|
43
|
+
jwksCacheTtlMs?: number;
|
|
44
|
+
now?: Date;
|
|
45
|
+
}
|
|
46
|
+
declare function verifyActivityAttestation(bundle: ActivityAttestationBundle, options?: VerifyActivityOptions): Promise<ActivityVerifyResult>;
|
|
47
|
+
declare function refreshEnvelopeJwks(issuer?: string): Promise<void>;
|
|
48
|
+
declare const identity: {
|
|
49
|
+
verifyActivityAttestation: typeof verifyActivityAttestation;
|
|
50
|
+
refreshEnvelopeJwks: typeof refreshEnvelopeJwks;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export { type ActivityAttestation as A, type VerifyActivityOptions as V, type ActivityAttestationBundle as a, type ActivityVerifyCheck as b, type ActivityVerifyResult as c, identity as i, refreshEnvelopeJwks as r, verifyActivityAttestation as v };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { v as verifyActivityAttestation, r as refreshEnvelopeJwks } from './identity-1VYMOhzV.mjs';
|
|
2
|
+
export { A as ActivityAttestation, a as ActivityAttestationBundle, b as ActivityVerifyCheck, c as ActivityVerifyResult, V as VerifyActivityOptions, i as identity } from './identity-1VYMOhzV.mjs';
|
|
1
3
|
import { E as EventSubtype, B as BillableEvent, I as IntegratorPriceConfig, S as SessionPolicy, a as Session, T as TelemetryEvent, b as SignInOptions, P as PaymentAuthorizeOptions, c as PaymentResult, V as ValidationResult, f as fromTemplate, g as getArchetypeTemplate, A as ArchetypeTemplate, F as Federation } from './integrator-m712Srxt.mjs';
|
|
2
4
|
export { d as ALL_EVENT_SUBTYPES, e as ARCHETYPE_TEMPLATES, h as AttestTier, C as ClassASubtype, i as ClassBSubtype, j as ClassCSubtype, k as ComputedFees, l as EVENT_SUBTYPES, m as EventClass, n as EventSubtypeMetadata, o as FederationStatus, p as IntegratorArchetype, q as IntegratorEventConfig, M as MIN_INTEGRATOR_PRICE_SATS, r as PLATFORM_FEE_POLICY, s as SigningMethod, t as SiteFeeShape, W as WebhookHeaders, u as WebhookPayload, v as computeFees, w as subtypesForClass, x as validateIntegratorConfig } from './integrator-m712Srxt.mjs';
|
|
3
5
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
@@ -245,6 +247,10 @@ declare const oc: {
|
|
|
245
247
|
family: {
|
|
246
248
|
scopes: (verb: FamilyVerb, options?: FamilyScopesOptions) => Promise<FamilyScopesResult>;
|
|
247
249
|
};
|
|
250
|
+
identity: {
|
|
251
|
+
verifyActivityAttestation: typeof verifyActivityAttestation;
|
|
252
|
+
refreshEnvelopeJwks: typeof refreshEnvelopeJwks;
|
|
253
|
+
};
|
|
248
254
|
};
|
|
249
255
|
|
|
250
|
-
export { ArchetypeTemplate, BillableEvent, EventSubtype, type FamilyScopesOptions, type FamilyScopesResult, type FamilyVerb, Federation, type FireEventOptions, type GrantedOptions, type GrantedResult, IntegratorPriceConfig, MeClientError, type OcPublicJwk, OcSignInButton, type OcSignInButtonProps, PaymentAuthorizeOptions, PaymentResult, type RequestOptions, type Scope, Session, SessionPolicy, SignInOptions, TelemetryEvent, type TrustAttestationCount, ValidationResult, type VerifyEventResult, type VerifyOptions, type VerifyResult, type WithRateLimitRetryOptions, clearBearerToken, config, fromTemplate as configFromTemplate, event, family, federations, getArchetypeTemplate, getBearerToken, getOrigin, oc, onTelemetry, parseTrustAttestationCount, payment, scope, session, setBearerToken, setOrigin, webhook, withRateLimitRetry };
|
|
256
|
+
export { ArchetypeTemplate, BillableEvent, EventSubtype, type FamilyScopesOptions, type FamilyScopesResult, type FamilyVerb, Federation, type FireEventOptions, type GrantedOptions, type GrantedResult, IntegratorPriceConfig, MeClientError, type OcPublicJwk, OcSignInButton, type OcSignInButtonProps, PaymentAuthorizeOptions, PaymentResult, type RequestOptions, type Scope, Session, SessionPolicy, SignInOptions, TelemetryEvent, type TrustAttestationCount, ValidationResult, type VerifyEventResult, type VerifyOptions, type VerifyResult, type WithRateLimitRetryOptions, clearBearerToken, config, fromTemplate as configFromTemplate, event, family, federations, getArchetypeTemplate, getBearerToken, getOrigin, oc, onTelemetry, parseTrustAttestationCount, payment, refreshEnvelopeJwks, scope, session, setBearerToken, setOrigin, verifyActivityAttestation, webhook, withRateLimitRetry };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { v as verifyActivityAttestation, r as refreshEnvelopeJwks } from './identity-1VYMOhzV.js';
|
|
2
|
+
export { A as ActivityAttestation, a as ActivityAttestationBundle, b as ActivityVerifyCheck, c as ActivityVerifyResult, V as VerifyActivityOptions, i as identity } from './identity-1VYMOhzV.js';
|
|
1
3
|
import { E as EventSubtype, B as BillableEvent, I as IntegratorPriceConfig, S as SessionPolicy, a as Session, T as TelemetryEvent, b as SignInOptions, P as PaymentAuthorizeOptions, c as PaymentResult, V as ValidationResult, f as fromTemplate, g as getArchetypeTemplate, A as ArchetypeTemplate, F as Federation } from './integrator-m712Srxt.js';
|
|
2
4
|
export { d as ALL_EVENT_SUBTYPES, e as ARCHETYPE_TEMPLATES, h as AttestTier, C as ClassASubtype, i as ClassBSubtype, j as ClassCSubtype, k as ComputedFees, l as EVENT_SUBTYPES, m as EventClass, n as EventSubtypeMetadata, o as FederationStatus, p as IntegratorArchetype, q as IntegratorEventConfig, M as MIN_INTEGRATOR_PRICE_SATS, r as PLATFORM_FEE_POLICY, s as SigningMethod, t as SiteFeeShape, W as WebhookHeaders, u as WebhookPayload, v as computeFees, w as subtypesForClass, x as validateIntegratorConfig } from './integrator-m712Srxt.js';
|
|
3
5
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
@@ -245,6 +247,10 @@ declare const oc: {
|
|
|
245
247
|
family: {
|
|
246
248
|
scopes: (verb: FamilyVerb, options?: FamilyScopesOptions) => Promise<FamilyScopesResult>;
|
|
247
249
|
};
|
|
250
|
+
identity: {
|
|
251
|
+
verifyActivityAttestation: typeof verifyActivityAttestation;
|
|
252
|
+
refreshEnvelopeJwks: typeof refreshEnvelopeJwks;
|
|
253
|
+
};
|
|
248
254
|
};
|
|
249
255
|
|
|
250
|
-
export { ArchetypeTemplate, BillableEvent, EventSubtype, type FamilyScopesOptions, type FamilyScopesResult, type FamilyVerb, Federation, type FireEventOptions, type GrantedOptions, type GrantedResult, IntegratorPriceConfig, MeClientError, type OcPublicJwk, OcSignInButton, type OcSignInButtonProps, PaymentAuthorizeOptions, PaymentResult, type RequestOptions, type Scope, Session, SessionPolicy, SignInOptions, TelemetryEvent, type TrustAttestationCount, ValidationResult, type VerifyEventResult, type VerifyOptions, type VerifyResult, type WithRateLimitRetryOptions, clearBearerToken, config, fromTemplate as configFromTemplate, event, family, federations, getArchetypeTemplate, getBearerToken, getOrigin, oc, onTelemetry, parseTrustAttestationCount, payment, scope, session, setBearerToken, setOrigin, webhook, withRateLimitRetry };
|
|
256
|
+
export { ArchetypeTemplate, BillableEvent, EventSubtype, type FamilyScopesOptions, type FamilyScopesResult, type FamilyVerb, Federation, type FireEventOptions, type GrantedOptions, type GrantedResult, IntegratorPriceConfig, MeClientError, type OcPublicJwk, OcSignInButton, type OcSignInButtonProps, PaymentAuthorizeOptions, PaymentResult, type RequestOptions, type Scope, Session, SessionPolicy, SignInOptions, TelemetryEvent, type TrustAttestationCount, ValidationResult, type VerifyEventResult, type VerifyOptions, type VerifyResult, type WithRateLimitRetryOptions, clearBearerToken, config, fromTemplate as configFromTemplate, event, family, federations, getArchetypeTemplate, getBearerToken, getOrigin, oc, onTelemetry, parseTrustAttestationCount, payment, refreshEnvelopeJwks, scope, session, setBearerToken, setOrigin, verifyActivityAttestation, webhook, withRateLimitRetry };
|
package/dist/index.js
CHANGED
|
@@ -640,7 +640,7 @@ var DEFAULT_DISABLED = {
|
|
|
640
640
|
site_pays: { kind: "fixed_sats", sats: 100 },
|
|
641
641
|
user_share_pct: 0.65
|
|
642
642
|
};
|
|
643
|
-
function fromTemplate(useCase,
|
|
643
|
+
function fromTemplate(useCase, identity2) {
|
|
644
644
|
const template = ARCHETYPES_BY_ID[useCase];
|
|
645
645
|
if (!template) {
|
|
646
646
|
throw new Error(
|
|
@@ -654,9 +654,9 @@ function fromTemplate(useCase, identity) {
|
|
|
654
654
|
events[sub] = template.events[sub] ?? DEFAULT_DISABLED;
|
|
655
655
|
}
|
|
656
656
|
return {
|
|
657
|
-
project_key:
|
|
658
|
-
domain:
|
|
659
|
-
display_name:
|
|
657
|
+
project_key: identity2.project_key,
|
|
658
|
+
domain: identity2.domain,
|
|
659
|
+
display_name: identity2.display_name,
|
|
660
660
|
updated_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
661
661
|
events
|
|
662
662
|
};
|
|
@@ -1138,6 +1138,219 @@ async function scopes(verb, options) {
|
|
|
1138
1138
|
}
|
|
1139
1139
|
var family = { scopes };
|
|
1140
1140
|
|
|
1141
|
+
// src/identity.ts
|
|
1142
|
+
var DEFAULT_ISSUER2 = "https://me.ochk.io";
|
|
1143
|
+
var DEFAULT_TTL_MS2 = 60 * 60 * 1e3;
|
|
1144
|
+
var ENVELOPE_JWKS_PATH = "/.well-known/oc-envelope-jwks.json";
|
|
1145
|
+
var jwksCache2 = /* @__PURE__ */ new Map();
|
|
1146
|
+
var inflight2 = /* @__PURE__ */ new Map();
|
|
1147
|
+
async function fetchEnvelopeJwks(issuer, ttlMs) {
|
|
1148
|
+
const cached = jwksCache2.get(issuer);
|
|
1149
|
+
if (cached && Date.now() - cached.fetchedAt < ttlMs) return cached;
|
|
1150
|
+
const existing = inflight2.get(issuer);
|
|
1151
|
+
if (existing) return existing;
|
|
1152
|
+
const p = (async () => {
|
|
1153
|
+
try {
|
|
1154
|
+
const url = `${issuer.replace(/\/$/, "")}${ENVELOPE_JWKS_PATH}`;
|
|
1155
|
+
const res = await fetch(url, { headers: { Accept: "application/json" } });
|
|
1156
|
+
if (!res.ok) throw new Error(`envelope JWKS fetch ${url} returned ${res.status}`);
|
|
1157
|
+
const json = await res.json();
|
|
1158
|
+
if (!json || !Array.isArray(json.keys)) {
|
|
1159
|
+
throw new Error(`envelope JWKS at ${url} did not return {keys:[\u2026]}`);
|
|
1160
|
+
}
|
|
1161
|
+
const keys = {};
|
|
1162
|
+
for (const k of json.keys) {
|
|
1163
|
+
if (typeof k.kid !== "string") continue;
|
|
1164
|
+
try {
|
|
1165
|
+
keys[k.kid] = await importJWK(k, "EdDSA");
|
|
1166
|
+
} catch {
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
const entry = { keys, fetchedAt: Date.now() };
|
|
1170
|
+
jwksCache2.set(issuer, entry);
|
|
1171
|
+
return entry;
|
|
1172
|
+
} catch (err) {
|
|
1173
|
+
const stale = jwksCache2.get(issuer);
|
|
1174
|
+
if (stale) return stale;
|
|
1175
|
+
throw err;
|
|
1176
|
+
}
|
|
1177
|
+
})().finally(() => {
|
|
1178
|
+
inflight2.delete(issuer);
|
|
1179
|
+
});
|
|
1180
|
+
inflight2.set(issuer, p);
|
|
1181
|
+
return p;
|
|
1182
|
+
}
|
|
1183
|
+
function hexToBytes2(hex) {
|
|
1184
|
+
if (typeof hex !== "string") return null;
|
|
1185
|
+
const s = hex.trim();
|
|
1186
|
+
if (s.length === 0 || s.length % 2 !== 0) return null;
|
|
1187
|
+
const out = new Uint8Array(s.length / 2);
|
|
1188
|
+
for (let i = 0; i < out.length; i++) {
|
|
1189
|
+
const b = parseInt(s.slice(i * 2, i * 2 + 2), 16);
|
|
1190
|
+
if (Number.isNaN(b)) return null;
|
|
1191
|
+
out[i] = b;
|
|
1192
|
+
}
|
|
1193
|
+
return out;
|
|
1194
|
+
}
|
|
1195
|
+
function base64ToBytes(b64) {
|
|
1196
|
+
try {
|
|
1197
|
+
const bin = typeof atob === "function" ? atob(b64) : Buffer.from(b64, "base64").toString("binary");
|
|
1198
|
+
const out = new Uint8Array(bin.length);
|
|
1199
|
+
for (let i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i);
|
|
1200
|
+
return out;
|
|
1201
|
+
} catch {
|
|
1202
|
+
return null;
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
function bytesToHex(bytes) {
|
|
1206
|
+
let out = "";
|
|
1207
|
+
for (const b of bytes) out += b.toString(16).padStart(2, "0");
|
|
1208
|
+
return out;
|
|
1209
|
+
}
|
|
1210
|
+
async function sha256(bytes) {
|
|
1211
|
+
const subtle = typeof globalThis.crypto !== "undefined" && globalThis.crypto.subtle ? globalThis.crypto.subtle : null;
|
|
1212
|
+
if (!subtle) {
|
|
1213
|
+
throw new Error("crypto.subtle unavailable \xB7 need Node 20+ / modern browser / Edge runtime");
|
|
1214
|
+
}
|
|
1215
|
+
const buf = await subtle.digest("SHA-256", bytes);
|
|
1216
|
+
return new Uint8Array(buf);
|
|
1217
|
+
}
|
|
1218
|
+
function toArrayBuffer2(view) {
|
|
1219
|
+
const buf = new ArrayBuffer(view.byteLength);
|
|
1220
|
+
new Uint8Array(buf).set(view);
|
|
1221
|
+
return buf;
|
|
1222
|
+
}
|
|
1223
|
+
async function verifyEd255192(key, sig, msg) {
|
|
1224
|
+
const subtle = typeof globalThis.crypto !== "undefined" && globalThis.crypto.subtle ? globalThis.crypto.subtle : null;
|
|
1225
|
+
if (!subtle) return false;
|
|
1226
|
+
try {
|
|
1227
|
+
return await subtle.verify(
|
|
1228
|
+
"Ed25519",
|
|
1229
|
+
key,
|
|
1230
|
+
toArrayBuffer2(sig),
|
|
1231
|
+
toArrayBuffer2(msg)
|
|
1232
|
+
);
|
|
1233
|
+
} catch {
|
|
1234
|
+
return false;
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
async function verifyActivityAttestation(bundle, options = {}) {
|
|
1238
|
+
const checks = [];
|
|
1239
|
+
const shapeOk = !!bundle && typeof bundle === "object" && typeof bundle.sig === "string" && typeof bundle.kid === "string" && typeof bundle.canonical_b64 === "string" && !!bundle.attestation && typeof bundle.attestation.id === "string" && typeof bundle.attestation.expires_at === "string";
|
|
1240
|
+
checks.push({
|
|
1241
|
+
ok: shapeOk,
|
|
1242
|
+
label: "bundle shape \xB7 sig / kid / canonical_b64 / attestation"
|
|
1243
|
+
});
|
|
1244
|
+
if (!shapeOk) {
|
|
1245
|
+
return { ok: false, reason: "bundle shape invalid", checks };
|
|
1246
|
+
}
|
|
1247
|
+
const a = bundle.attestation;
|
|
1248
|
+
const canonical = base64ToBytes(bundle.canonical_b64);
|
|
1249
|
+
checks.push({
|
|
1250
|
+
ok: canonical !== null,
|
|
1251
|
+
label: "canonical_b64 decodes",
|
|
1252
|
+
detail: canonical ? `${canonical.length} bytes` : "invalid base64"
|
|
1253
|
+
});
|
|
1254
|
+
if (!canonical) return { ok: false, reason: "canonical_b64 invalid base64", checks, attestation: a };
|
|
1255
|
+
const digest = await sha256(canonical);
|
|
1256
|
+
const computedId = bytesToHex(digest);
|
|
1257
|
+
const idOk = computedId === a.id;
|
|
1258
|
+
checks.push({
|
|
1259
|
+
ok: idOk,
|
|
1260
|
+
label: "sha256(canonical_bytes) === id",
|
|
1261
|
+
detail: idOk ? a.id : `expected ${a.id}, got ${computedId}`
|
|
1262
|
+
});
|
|
1263
|
+
if (!idOk) return { ok: false, reason: "id does not match canonical-bytes hash", checks, attestation: a };
|
|
1264
|
+
let key = null;
|
|
1265
|
+
if (options.jwk) {
|
|
1266
|
+
if (options.jwk.kid !== bundle.kid) {
|
|
1267
|
+
checks.push({
|
|
1268
|
+
ok: false,
|
|
1269
|
+
label: "JWK with matching kid present",
|
|
1270
|
+
detail: `provided jwk.kid=${options.jwk.kid} but bundle.kid=${bundle.kid}`
|
|
1271
|
+
});
|
|
1272
|
+
return { ok: false, reason: "kid mismatch with provided jwk", checks, attestation: a };
|
|
1273
|
+
}
|
|
1274
|
+
try {
|
|
1275
|
+
key = await importJWK(options.jwk, "EdDSA");
|
|
1276
|
+
checks.push({ ok: true, label: "JWK with matching kid present", detail: `kid ${bundle.kid} (provided)` });
|
|
1277
|
+
} catch (err) {
|
|
1278
|
+
checks.push({
|
|
1279
|
+
ok: false,
|
|
1280
|
+
label: "JWK with matching kid present",
|
|
1281
|
+
detail: `provided jwk failed import: ${err.message}`
|
|
1282
|
+
});
|
|
1283
|
+
return { ok: false, reason: "provided jwk failed import", checks, attestation: a };
|
|
1284
|
+
}
|
|
1285
|
+
} else {
|
|
1286
|
+
const issuer = options.issuer ?? DEFAULT_ISSUER2;
|
|
1287
|
+
const ttl = options.jwksCacheTtlMs ?? DEFAULT_TTL_MS2;
|
|
1288
|
+
try {
|
|
1289
|
+
let entry = await fetchEnvelopeJwks(issuer, ttl);
|
|
1290
|
+
key = entry.keys[bundle.kid] ?? null;
|
|
1291
|
+
if (!key) {
|
|
1292
|
+
jwksCache2.delete(issuer);
|
|
1293
|
+
entry = await fetchEnvelopeJwks(issuer, ttl);
|
|
1294
|
+
key = entry.keys[bundle.kid] ?? null;
|
|
1295
|
+
}
|
|
1296
|
+
checks.push({
|
|
1297
|
+
ok: !!key,
|
|
1298
|
+
label: "JWK with matching kid present",
|
|
1299
|
+
detail: key ? `kid ${bundle.kid}` : `no JWK with kid ${bundle.kid} at ${issuer}${ENVELOPE_JWKS_PATH}`
|
|
1300
|
+
});
|
|
1301
|
+
if (!key) {
|
|
1302
|
+
return { ok: false, reason: `kid ${bundle.kid} not in envelope JWKS`, checks, attestation: a };
|
|
1303
|
+
}
|
|
1304
|
+
} catch (err) {
|
|
1305
|
+
checks.push({
|
|
1306
|
+
ok: false,
|
|
1307
|
+
label: "JWK with matching kid present",
|
|
1308
|
+
detail: `envelope JWKS unavailable: ${err.message}`
|
|
1309
|
+
});
|
|
1310
|
+
return {
|
|
1311
|
+
ok: false,
|
|
1312
|
+
reason: `envelope JWKS unavailable: ${err.message}`,
|
|
1313
|
+
checks,
|
|
1314
|
+
attestation: a
|
|
1315
|
+
};
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
const sigBytes = hexToBytes2(bundle.sig);
|
|
1319
|
+
if (!sigBytes) {
|
|
1320
|
+
checks.push({
|
|
1321
|
+
ok: false,
|
|
1322
|
+
label: "ed25519.verify(sig, canonical_bytes, jwk.public)",
|
|
1323
|
+
detail: "malformed sig (expected hex)"
|
|
1324
|
+
});
|
|
1325
|
+
return { ok: false, reason: "malformed sig", checks, attestation: a };
|
|
1326
|
+
}
|
|
1327
|
+
const sigOk = await verifyEd255192(key, sigBytes, canonical);
|
|
1328
|
+
checks.push({
|
|
1329
|
+
ok: sigOk,
|
|
1330
|
+
label: "ed25519.verify(sig, canonical_bytes, jwk.public)",
|
|
1331
|
+
detail: sigOk ? "signature valid" : "signature does not match"
|
|
1332
|
+
});
|
|
1333
|
+
if (!sigOk) return { ok: false, reason: "signature does not match", checks, attestation: a };
|
|
1334
|
+
const now = options.now ?? /* @__PURE__ */ new Date();
|
|
1335
|
+
const expiresMs = Date.parse(a.expires_at);
|
|
1336
|
+
const freshOk = Number.isFinite(expiresMs) && expiresMs > now.getTime();
|
|
1337
|
+
checks.push({
|
|
1338
|
+
ok: freshOk,
|
|
1339
|
+
label: "now < attestation.expires_at",
|
|
1340
|
+
detail: freshOk ? `expires ${new Date(expiresMs).toISOString()}` : "attestation has expired"
|
|
1341
|
+
});
|
|
1342
|
+
if (!freshOk) return { ok: false, reason: "attestation has expired", checks, attestation: a };
|
|
1343
|
+
return { ok: true, attestation: a, checks };
|
|
1344
|
+
}
|
|
1345
|
+
async function refreshEnvelopeJwks(issuer = DEFAULT_ISSUER2) {
|
|
1346
|
+
jwksCache2.delete(issuer);
|
|
1347
|
+
await fetchEnvelopeJwks(issuer, DEFAULT_TTL_MS2);
|
|
1348
|
+
}
|
|
1349
|
+
var identity = {
|
|
1350
|
+
verifyActivityAttestation,
|
|
1351
|
+
refreshEnvelopeJwks
|
|
1352
|
+
};
|
|
1353
|
+
|
|
1141
1354
|
// src/subtypes.ts
|
|
1142
1355
|
var EVENT_SUBTYPES = {
|
|
1143
1356
|
// ── Class A · durable state transitions ──
|
|
@@ -1262,7 +1475,17 @@ var ALL_EVENT_SUBTYPES = [
|
|
|
1262
1475
|
];
|
|
1263
1476
|
|
|
1264
1477
|
// src/index.ts
|
|
1265
|
-
var oc = {
|
|
1478
|
+
var oc = {
|
|
1479
|
+
session,
|
|
1480
|
+
payment,
|
|
1481
|
+
event,
|
|
1482
|
+
config,
|
|
1483
|
+
webhook,
|
|
1484
|
+
federations,
|
|
1485
|
+
scope,
|
|
1486
|
+
family,
|
|
1487
|
+
identity
|
|
1488
|
+
};
|
|
1266
1489
|
|
|
1267
1490
|
exports.ALL_EVENT_SUBTYPES = ALL_EVENT_SUBTYPES;
|
|
1268
1491
|
exports.ARCHETYPE_TEMPLATES = ARCHETYPE_TEMPLATES;
|
|
@@ -1281,16 +1504,19 @@ exports.federations = federations;
|
|
|
1281
1504
|
exports.getArchetypeTemplate = getArchetypeTemplate;
|
|
1282
1505
|
exports.getBearerToken = getBearerToken;
|
|
1283
1506
|
exports.getOrigin = getOrigin;
|
|
1507
|
+
exports.identity = identity;
|
|
1284
1508
|
exports.oc = oc;
|
|
1285
1509
|
exports.onTelemetry = onTelemetry;
|
|
1286
1510
|
exports.parseTrustAttestationCount = parseTrustAttestationCount;
|
|
1287
1511
|
exports.payment = payment;
|
|
1512
|
+
exports.refreshEnvelopeJwks = refreshEnvelopeJwks;
|
|
1288
1513
|
exports.scope = scope;
|
|
1289
1514
|
exports.session = session;
|
|
1290
1515
|
exports.setBearerToken = setBearerToken;
|
|
1291
1516
|
exports.setOrigin = setOrigin;
|
|
1292
1517
|
exports.subtypesForClass = subtypesForClass;
|
|
1293
1518
|
exports.validateIntegratorConfig = validateIntegratorConfig;
|
|
1519
|
+
exports.verifyActivityAttestation = verifyActivityAttestation;
|
|
1294
1520
|
exports.webhook = webhook;
|
|
1295
1521
|
exports.withRateLimitRetry = withRateLimitRetry;
|
|
1296
1522
|
//# sourceMappingURL=index.js.map
|