@nomosprotocol/sdk 1.3.3 → 1.4.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.js CHANGED
@@ -20,49 +20,49 @@ __export(errors_exports, {
20
20
  NomosWebhookSignatureError: () => NomosWebhookSignatureError
21
21
  });
22
22
  var NomosError = class extends Error {
23
- constructor(message, code, status, requestId) {
23
+ constructor(message, code, status, requestId, details) {
24
24
  super(message);
25
25
  this.name = "NomosError";
26
26
  this.code = code;
27
27
  this.status = status;
28
28
  this.requestId = requestId;
29
+ this.details = details;
29
30
  }
30
31
  };
31
32
  var NomosAuthenticationError = class extends NomosError {
32
- constructor(message = "Invalid API key", requestId) {
33
- super(message, "authentication_error", 401, requestId);
33
+ constructor(message = "Invalid API key", requestId, details) {
34
+ super(message, "authentication_error", 401, requestId, details);
34
35
  this.name = "NomosAuthenticationError";
35
36
  }
36
37
  };
37
38
  var NomosAuthorizationError = class extends NomosError {
38
- constructor(message = "Access denied", requestId) {
39
- super(message, "authorization_error", 403, requestId);
39
+ constructor(message = "Access denied", requestId, details) {
40
+ super(message, "authorization_error", 403, requestId, details);
40
41
  this.name = "NomosAuthorizationError";
41
42
  }
42
43
  };
43
44
  var NomosRateLimitError = class extends NomosError {
44
- constructor(message = "Rate limit exceeded", retryAfter, requestId) {
45
- super(message, "rate_limit_error", 429, requestId);
45
+ constructor(message = "Rate limit exceeded", retryAfter, requestId, details) {
46
+ super(message, "rate_limit_error", 429, requestId, details);
46
47
  this.name = "NomosRateLimitError";
47
48
  this.retryAfter = retryAfter;
48
49
  }
49
50
  };
50
51
  var NomosValidationError = class extends NomosError {
51
52
  constructor(message, details, requestId) {
52
- super(message, "validation_error", 400, requestId);
53
+ super(message, "validation_error", 400, requestId, details);
53
54
  this.name = "NomosValidationError";
54
- this.details = details;
55
55
  }
56
56
  };
57
57
  var NomosNotFoundError = class extends NomosError {
58
- constructor(message, requestId) {
59
- super(message, "not_found", 404, requestId);
58
+ constructor(message, requestId, details) {
59
+ super(message, "not_found", 404, requestId, details);
60
60
  this.name = "NomosNotFoundError";
61
61
  }
62
62
  };
63
63
  var NomosAPIError = class extends NomosError {
64
- constructor(message, status, requestId) {
65
- super(message, "api_error", status, requestId);
64
+ constructor(message, status, requestId, details) {
65
+ super(message, "api_error", status, requestId, details);
66
66
  this.name = "NomosAPIError";
67
67
  }
68
68
  };
@@ -179,22 +179,27 @@ var HttpClient = class {
179
179
  const message = errBody?.error ?? errBody?.message ?? res.statusText;
180
180
  switch (res.status) {
181
181
  case 401:
182
- throw new NomosAuthenticationError(message, requestId);
182
+ throw new NomosAuthenticationError(message, requestId, errBody);
183
183
  case 403:
184
- throw new NomosAuthorizationError(message, requestId);
184
+ throw new NomosAuthorizationError(message, requestId, errBody);
185
185
  case 404:
186
- throw new NomosNotFoundError(message, requestId);
186
+ throw new NomosNotFoundError(message, requestId, errBody);
187
187
  case 422:
188
188
  case 400:
189
- throw new NomosValidationError(message, errBody?.details, requestId);
189
+ throw new NomosValidationError(message, errBody?.details ?? errBody, requestId);
190
190
  case 429:
191
191
  throw new NomosRateLimitError(
192
192
  message,
193
193
  res.headers.get("retry-after") ? parseInt(res.headers.get("retry-after"), 10) : void 0,
194
- requestId
194
+ requestId,
195
+ errBody
195
196
  );
197
+ // No case for 409 (conflict) specifically — several endpoints use it for distinct
198
+ // application-level rejections (e.g. conserved-state capacity/conflict/already-used);
199
+ // `errBody` (this default branch's `details`) is what lets a caller tell those apart via
200
+ // `err.details?.code`, not a status-code switch that would have to keep growing per feature.
196
201
  default:
197
- throw new NomosAPIError(message, res.status, requestId);
202
+ throw new NomosAPIError(message, res.status, requestId, errBody);
198
203
  }
199
204
  }
200
205
  };
@@ -512,6 +517,71 @@ var Webhooks = class {
512
517
  }
513
518
  };
514
519
 
520
+ // src/resources/conserved-state.ts
521
+ var ConservedState = class {
522
+ constructor(http) {
523
+ this.http = http;
524
+ }
525
+ /**
526
+ * Read a ledger's current balance — no auth required, same posture as `can()`'s own keyless
527
+ * rail (reading how much budget remains is no more sensitive than reading a verdict).
528
+ */
529
+ async get(artifactId, scope, opts) {
530
+ const qs = new URLSearchParams({ artifact_id: artifactId, scope });
531
+ const { data, lastResponse } = await this.http.get(
532
+ `/api/v1/conserved-state?${qs.toString()}`,
533
+ opts
534
+ );
535
+ return { ...data, lastResponse };
536
+ }
537
+ /**
538
+ * Commit capacity against a REAL, AUTHORIZED `can()` decision. Authenticated — unlike `can()`,
539
+ * spending against a shared budget requires an API key or session; `agent` on the returned
540
+ * reservation traces to that authenticated identity, never a value you pass in.
541
+ *
542
+ * Throws (via the SDK's standard NomosError hierarchy; `err.details?.code` carries the
543
+ * server's own code): `DECISION_NOT_FOUND` (the query_id names no real query), `DECISION_NOT
544
+ * _AUTHORIZED` (that decision didn't verdict AUTHORIZED for this artifact), `DECISION_ALREADY
545
+ * _USED` (already bound to a reservation — one decision authorizes one, ever), `STATE_CONFLICT`
546
+ * (a stale `expected_state_digest`), `INSUFFICIENT_CAPACITY` (`err.details.requested`/
547
+ * `.available` carry the numbers), or `NO_LEDGER` (nobody has declared this budget yet).
548
+ *
549
+ * Passing `{ artifact_id, scope, act }` instead authorizes the hold with a NOMOS-SPEC-008 Act.
550
+ * Extra codes: `ACT_NOT_ACCEPTED` (the ledger has no Act binding) and `ACT_REJECTED`, with the
551
+ * verifier's full answer in `err.details.result` — for `INCOMPLETE` it names the open rules and
552
+ * the facts whose testimony would decide them.
553
+ */
554
+ async reserve(params, opts) {
555
+ const { data, lastResponse } = await this.http.post("/api/v1/reserve", params, opts);
556
+ return { ...data, lastResponse };
557
+ }
558
+ /**
559
+ * The reserved action succeeded — moves the hold into real, settled spend. Idempotent when
560
+ * you pass the same `reference` again for a retry (e.g. after a network timeout): you get the
561
+ * ORIGINAL receipt back, never a double-charge.
562
+ */
563
+ async settle(reservationId, reference, opts) {
564
+ const { data, lastResponse } = await this.http.post(
565
+ "/api/v1/settle",
566
+ { reservation_id: reservationId, reference },
567
+ opts
568
+ );
569
+ return { ...data, lastResponse };
570
+ }
571
+ /**
572
+ * The reserved action failed, or you decided not to act — gives the hold's capacity back
573
+ * without ever touching what's actually been spent.
574
+ */
575
+ async release(reservationId, reference, opts) {
576
+ const { data, lastResponse } = await this.http.post(
577
+ "/api/v1/release",
578
+ { reservation_id: reservationId, reference },
579
+ opts
580
+ );
581
+ return { ...data, lastResponse };
582
+ }
583
+ };
584
+
515
585
  // src/can.ts
516
586
  var CHAIN_PROTOCOL_VERSION = "1";
517
587
  var DEFAULT_EXCHANGE_BASE = "https://www.nomosprotocol.com";
@@ -653,14 +723,17 @@ async function canViaChain(artifact, keyCerts, rootPublicKeyPem, facts, action,
653
723
  // data the caller is already holding.
654
724
  ...artifact?.meta?.version ? { version: artifact.meta.version } : {},
655
725
  missing_inputs: data.missing_inputs ?? [],
656
- ...Array.isArray(data.obligations) && data.obligations.length > 0 ? { obligations: data.obligations } : {}
726
+ ...Array.isArray(data.obligations) && data.obligations.length > 0 ? { obligations: data.obligations } : {},
727
+ // §5.5 — composing to a real permission decision must not silently drop the chain's own
728
+ // revocation-confidence disclosure; the server already threads this through, so forward it.
729
+ ...data.revocation_checked ? { revocation_checked: data.revocation_checked } : {}
657
730
  // Deliberately no query_id/url/audit — this evaluation is stateless by design (the whole
658
731
  // point is answering without NOMOS needing to have seen this artifact before); there is no
659
732
  // permanent transcript to point to, and faking one would misrepresent what just happened.
660
733
  };
661
734
  }
662
735
  const message = data?.detail ?? `Chain verification failed (HTTP ${res.status})`;
663
- if (data?.decision === "ISSUER_NOT_RECOGNIZED" || data?.decision === "KEY_REVOKED" || data?.decision === "SEAL_INVALID" || data?.decision === "ALLOWED") {
736
+ if (data?.decision === "ISSUER_NOT_RECOGNIZED" || data?.decision === "KEY_REVOKED" || data?.decision === "CERTIFICATE_REVOKED" || data?.decision === "OUT_OF_SCOPE" || data?.decision === "SEAL_INVALID" || data?.decision === "ALLOWED") {
664
737
  throw new NomosIssuerNotTrustedError(message, data.decision, requestId);
665
738
  }
666
739
  if (data?.decision === "MALFORMED") throw new NomosValidationError(message, data, requestId);
@@ -723,6 +796,7 @@ var Nomos = class {
723
796
  this.artifacts = new Artifacts(this.http);
724
797
  this.governance = new Governance(this.http);
725
798
  this.webhooks = new Webhooks();
799
+ this.conservedState = new ConservedState(this.http);
726
800
  }
727
801
  /**
728
802
  * "Can I do this?" — the one verb, now covering your own artifacts too. Pass `authority` for a
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/errors.ts","../src/util.ts","../src/http-client.ts","../src/resources/decisions.ts","../src/resources/artifacts.ts","../src/resources/governance.ts","../src/resources/webhooks.ts","../src/can.ts","../src/nomos.ts","../src/verify-chain.ts"],"sourcesContent":["export type NomosErrorCode =\n | 'authentication_error'\n | 'authorization_error'\n | 'rate_limit_error'\n | 'validation_error'\n | 'not_found'\n | 'api_error'\n | 'network_error'\n | 'webhook_signature_error'\n | 'payment_required'\n | 'issuer_not_trusted';\n\nexport class NomosError extends Error {\n readonly code: NomosErrorCode;\n readonly status?: number;\n readonly requestId?: string;\n\n constructor(message: string, code: NomosErrorCode, status?: number, requestId?: string) {\n super(message);\n this.name = 'NomosError';\n this.code = code;\n this.status = status;\n this.requestId = requestId;\n }\n}\n\nexport class NomosAuthenticationError extends NomosError {\n constructor(message = 'Invalid API key', requestId?: string) {\n super(message, 'authentication_error', 401, requestId);\n this.name = 'NomosAuthenticationError';\n }\n}\n\nexport class NomosAuthorizationError extends NomosError {\n constructor(message = 'Access denied', requestId?: string) {\n super(message, 'authorization_error', 403, requestId);\n this.name = 'NomosAuthorizationError';\n }\n}\n\nexport class NomosRateLimitError extends NomosError {\n readonly retryAfter?: number;\n\n constructor(message = 'Rate limit exceeded', retryAfter?: number, requestId?: string) {\n super(message, 'rate_limit_error', 429, requestId);\n this.name = 'NomosRateLimitError';\n this.retryAfter = retryAfter;\n }\n}\n\nexport class NomosValidationError extends NomosError {\n readonly details?: unknown;\n\n constructor(message: string, details?: unknown, requestId?: string) {\n super(message, 'validation_error', 400, requestId);\n this.name = 'NomosValidationError';\n this.details = details;\n }\n}\n\nexport class NomosNotFoundError extends NomosError {\n constructor(message: string, requestId?: string) {\n super(message, 'not_found', 404, requestId);\n this.name = 'NomosNotFoundError';\n }\n}\n\nexport class NomosAPIError extends NomosError {\n constructor(message: string, status: number, requestId?: string) {\n super(message, 'api_error', status, requestId);\n this.name = 'NomosAPIError';\n }\n}\n\nexport class NomosNetworkError extends NomosError {\n constructor(message: string) {\n super(message, 'network_error');\n this.name = 'NomosNetworkError';\n }\n}\n\nexport class NomosWebhookSignatureError extends NomosError {\n constructor(message: string) {\n super(message, 'webhook_signature_error', 400);\n this.name = 'NomosWebhookSignatureError';\n }\n}\n\n/** can() asked about a paid authority the caller hasn't purchased or licensed. Distinct from a\n * generic 403 on purpose: this isn't \"you're not allowed,\" it's \"here's exactly what unlocks\n * it\" — price and a URL to complete the purchase. NOMOS never auto-charges on your behalf;\n * this is the seam where a caller decides to buy, not where a payment silently happens. */\nexport class NomosPaymentRequiredError extends NomosError {\n readonly priceUsd: number;\n readonly purchaseUrl: string;\n\n constructor(message: string, priceUsd: number, purchaseUrl: string, requestId?: string) {\n super(message, 'payment_required', 402, requestId);\n this.name = 'NomosPaymentRequiredError';\n this.priceUsd = priceUsd;\n this.purchaseUrl = purchaseUrl;\n }\n}\n\n/** can()'s chain-of-trust rail couldn't establish that the presented artifact is trustworthy —\n * an unrecognized issuer, a revoked key, a tampered seal, or a malformed presentation. This is\n * deliberately NOT a DENIED verdict: \"the rules say no\" and \"we never got far enough to ask the\n * rules anything\" are different claims, and collapsing them would tell the caller the wrong\n * thing to do next (re-presenting a better chain can fix the first case; it can never fix a\n * genuinely tampered artifact). `reason` is the underlying chain decision\n * (ISSUER_NOT_RECOGNIZED / KEY_REVOKED / SEAL_INVALID / MALFORMED) for callers that need to\n * distinguish them. */\nexport class NomosIssuerNotTrustedError extends NomosError {\n readonly reason: string;\n\n constructor(message: string, reason: string, requestId?: string) {\n super(message, 'issuer_not_trusted', 403, requestId);\n this.name = 'NomosIssuerNotTrustedError';\n this.reason = reason;\n }\n}\n","export async function sleep(ms: number): Promise<void> {\n return new Promise(resolve => setTimeout(resolve, ms));\n}\n\nexport function jitteredBackoff(attempt: number, baseMs = 500): number {\n const exp = Math.min(baseMs * 2 ** attempt, 16000);\n return exp * (0.75 + Math.random() * 0.5); // ±25% jitter\n}\n\nexport function isRetryable(status: number): boolean {\n return status === 429 || status >= 500;\n}\n","import {\n NomosAuthenticationError,\n NomosAuthorizationError,\n NomosRateLimitError,\n NomosValidationError,\n NomosNotFoundError,\n NomosAPIError,\n NomosNetworkError,\n} from './errors.js';\nimport { sleep, jitteredBackoff, isRetryable } from './util.js';\nimport type { RequestOptions, NomosRawResponse } from './types.js';\n\nconst SDK_VERSION = '1.1.0';\n\nexport interface HttpClientOptions {\n apiKey: string;\n baseUrl: string;\n maxRetries: number;\n timeout: number;\n}\n\nexport interface HttpResponse<T> {\n data: T;\n lastResponse: NomosRawResponse;\n}\n\nexport class HttpClient {\n constructor(private readonly opts: HttpClientOptions) {}\n\n async get<T>(path: string, reqOpts?: RequestOptions): Promise<HttpResponse<T>> {\n return this.request<T>('GET', path, undefined, reqOpts);\n }\n\n async post<T>(path: string, body: unknown, reqOpts?: RequestOptions): Promise<HttpResponse<T>> {\n return this.request<T>('POST', path, body, reqOpts);\n }\n\n private async request<T>(\n method: string,\n path: string,\n body: unknown,\n reqOpts?: RequestOptions,\n attempt = 0,\n ): Promise<HttpResponse<T>> {\n const apiKey = reqOpts?.apiKey ?? this.opts.apiKey;\n const timeout = reqOpts?.timeout ?? this.opts.timeout;\n const maxRetries = reqOpts?.maxRetries ?? this.opts.maxRetries;\n\n const url = `${this.opts.baseUrl}${path}`;\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), timeout);\n\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n 'X-Nomos-Api-Key': apiKey,\n 'User-Agent': `nomos-node/${SDK_VERSION}`,\n 'NOMOS-SDK-Version': SDK_VERSION,\n };\n if (reqOpts?.idempotencyKey) {\n headers['Idempotency-Key'] = reqOpts.idempotencyKey;\n }\n\n let res: Response;\n try {\n res = await fetch(url, {\n method,\n signal: controller.signal,\n headers,\n body: body != null ? JSON.stringify(body) : undefined,\n });\n } catch (err: any) {\n clearTimeout(timer);\n if (err.name === 'AbortError') {\n throw new NomosNetworkError(`Request timed out after ${timeout}ms`);\n }\n throw new NomosNetworkError(err.message ?? 'Network error');\n } finally {\n clearTimeout(timer);\n }\n\n const requestId = res.headers.get('x-request-id') ?? '';\n const rawHeaders: Record<string, string> = {};\n res.headers.forEach((value, key) => { rawHeaders[key] = value; });\n const lastResponse: NomosRawResponse = {\n requestId,\n statusCode: res.status,\n headers: rawHeaders,\n };\n\n if (res.ok) {\n const data = await res.json() as T;\n return { data, lastResponse };\n }\n\n // Retry on 429 / 5xx\n if (isRetryable(res.status) && attempt < maxRetries) {\n const retryAfter = res.headers.get('retry-after');\n const delay = retryAfter ? parseInt(retryAfter, 10) * 1000 : jitteredBackoff(attempt);\n await sleep(delay);\n return this.request<T>(method, path, body, reqOpts, attempt + 1);\n }\n\n let errBody: any = {};\n try { errBody = await res.json(); } catch {}\n const message: string = errBody?.error ?? errBody?.message ?? res.statusText;\n\n switch (res.status) {\n case 401: throw new NomosAuthenticationError(message, requestId);\n case 403: throw new NomosAuthorizationError(message, requestId);\n case 404: throw new NomosNotFoundError(message, requestId);\n case 422:\n case 400: throw new NomosValidationError(message, errBody?.details, requestId);\n case 429: throw new NomosRateLimitError(\n message,\n res.headers.get('retry-after') ? parseInt(res.headers.get('retry-after')!, 10) : undefined,\n requestId,\n );\n default: throw new NomosAPIError(message, res.status, requestId);\n }\n }\n}\n","import type { HttpClient } from '../http-client.js';\nimport type {\n VerifyDecisionParams,\n VerifyDecisionResult,\n RequestOptions,\n WithLastResponse,\n} from '../types.js';\n\nexport class Decisions {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Verify whether an AI decision is permitted under a governance artifact.\n *\n * Public demo artifacts (`pub_*`) work without an API key.\n * Custom artifacts require a valid API key.\n *\n * @example\n * const result = await nomos.decisions.verify({\n * artifact_id: 'pub_lending_v1',\n * decision_context: { credit_score: 720, loan_amount: 50000 },\n * });\n *\n * if (!result.allowed) {\n * throw new Error(`Blocked: ${result.verdict_description}`);\n * }\n *\n * // Debugging / tracing\n * console.log(result.lastResponse.requestId);\n *\n * @example\n * // Per-request options\n * const result = await nomos.decisions.verify(params, {\n * idempotencyKey: `verify-${transactionId}`,\n * timeout: 5000,\n * });\n */\n async verify(\n params: VerifyDecisionParams,\n opts?: RequestOptions,\n ): Promise<WithLastResponse<VerifyDecisionResult>> {\n const { artifact_id, decision_context, proposed_decision, correlation_id } = params;\n\n // Public artifacts (pub_*) use the open /verify endpoint — no API key required\n const isPublic = artifact_id.startsWith('pub_');\n let httpResp: Awaited<ReturnType<HttpClient['post']>>;\n\n if (isPublic) {\n httpResp = await this.http.post<any>('/api/v1/verify', {\n artifact_id,\n decision: proposed_decision ?? 'evaluate',\n inputs: decision_context,\n }, opts);\n } else {\n // /verify-decision expects: { artifact_id, decision, inputs, caller? }\n // NOT decision_context / proposed_decision at the top level.\n httpResp = await this.http.post<any>('/api/v1/verify-decision', {\n artifact_id,\n decision: proposed_decision ?? 'evaluate',\n inputs: decision_context,\n caller: { correlation_id: correlation_id ?? globalThis.crypto.randomUUID() },\n }, opts);\n }\n\n const raw: any = httpResp.data;\n\n return {\n id: raw.id ?? `req_${raw.execution_id ?? globalThis.crypto.randomUUID()}`,\n object: raw.object ?? 'decision',\n artifact_id: raw.artifact_id ?? artifact_id,\n artifact_name: raw.artifact_name ?? '',\n allowed: raw.allowed ?? false,\n verdict: raw.verdict ?? (raw.outcome === 'auto_approved' ? 'approved' : raw.outcome === 'auto_rejected' ? 'rejected' : 'escalated'),\n rule: raw.rule,\n evaluation: raw.evaluation ?? { rules_evaluated: raw.rules_evaluated ?? 0, rules_matched: 0, rules_expired: 0, conflicts_resolved: 0 },\n confidence: raw.confidence ?? { tier: raw.artifact_confidence ?? 'DECLARED', score: 1, description: '' },\n audit: raw.audit ?? { hash: raw.audit_hash ?? raw.audit_record ?? '', timestamp: raw.ts ?? new Date().toISOString() },\n performance: raw.performance ?? { latency_ms: raw.latency_ms ?? 0 },\n schema_version: raw.schema_version ?? '1.0.0',\n verdict_description: raw.verdict_description ?? '',\n incomplete_inputs: raw.incomplete_inputs,\n paths_to_approval: raw.paths_to_approval,\n lastResponse: httpResp.lastResponse,\n };\n }\n}\n","import type { HttpClient } from '../http-client.js';\nimport type {\n Artifact,\n ArtifactList,\n ArtifactSchema,\n ListArtifactsParams,\n RequestOptions,\n WithLastResponse,\n} from '../types.js';\n\nexport class Artifacts {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Retrieve a single artifact by ID.\n *\n * @example\n * const artifact = await nomos.artifacts.retrieve('loan_approval_v1');\n * console.log(artifact.ari_score, artifact.autonomy_band);\n * console.log(artifact.lastResponse.requestId); // for support tickets\n */\n async retrieve(\n artifactId: string,\n opts?: RequestOptions,\n ): Promise<WithLastResponse<Artifact>> {\n const { data, lastResponse } = await this.http.get<Artifact>(\n `/api/exchange/artifacts/${encodeURIComponent(artifactId)}`,\n opts,\n );\n return { ...data, lastResponse };\n }\n\n /**\n * List published artifacts on the Exchange with optional filters.\n *\n * @example\n * const { data, total } = await nomos.artifacts.list({ band: 'autonomous', limit: 10 });\n *\n * @example\n * // With per-request options\n * const page = await nomos.artifacts.list({ limit: 20 }, { timeout: 5000 });\n */\n async list(\n params: ListArtifactsParams = {},\n opts?: RequestOptions,\n ): Promise<WithLastResponse<ArtifactList>> {\n const qs = new URLSearchParams();\n if (params.band) qs.set('band', params.band);\n if (params.domain) qs.set('domain', params.domain);\n if (params.jurisdiction) qs.set('jurisdiction', params.jurisdiction);\n if (params.sort) qs.set('sort', params.sort);\n if (params.limit != null) qs.set('limit', String(params.limit));\n if (params.offset != null) qs.set('offset', String(params.offset));\n const query = qs.toString();\n\n const { data: raw, lastResponse } = await this.http.get<any>(\n `/api/exchange/artifacts${query ? `?${query}` : ''}`,\n opts,\n );\n\n // API returns { artifacts: [], total: N } — normalise to { data: [], total: N }\n const normalized: ArtifactList = {\n data: Array.isArray(raw) ? raw : (raw.artifacts ?? raw.data ?? []),\n total: raw.total ?? (Array.isArray(raw) ? raw.length : 0),\n limit: params.limit ?? 20,\n offset: params.offset ?? 0,\n };\n\n return { ...normalized, lastResponse };\n }\n\n /**\n * Auto-paginating iterator — yields every artifact across all pages.\n * Stops automatically when the last page is reached.\n *\n * @example\n * for await (const artifact of nomos.artifacts.listAutoPaging({ band: 'autonomous' })) {\n * console.log(artifact.title, artifact.ari_score);\n * }\n */\n async *listAutoPaging(\n params: ListArtifactsParams = {},\n opts?: RequestOptions,\n ): AsyncGenerator<Artifact> {\n let offset = params.offset ?? 0;\n const limit = params.limit ?? 20;\n\n while (true) {\n const page = await this.list({ ...params, offset, limit }, opts);\n for (const item of page.data) yield item;\n if (page.data.length < limit || offset + page.data.length >= page.total) break;\n offset += page.data.length;\n }\n }\n\n /**\n * Retrieve the declared input schema for a sealed artifact.\n *\n * Returns every field the artifact's rules reference — name, type, whether it's\n * required, and a ready-to-use example_inputs object. Use this to build forms,\n * validate payloads, or generate API docs without reading the rules manually.\n *\n * Requires an API key (artifact schemas are not public).\n *\n * @example\n * const schema = await nomos.artifacts.schema('art_abc123');\n * console.log(schema.required_fields); // ['credit_score', 'loan_amount']\n * console.log(schema.example_inputs); // { credit_score: 0, loan_amount: 0 }\n */\n async schema(\n artifactId: string,\n opts?: RequestOptions,\n ): Promise<WithLastResponse<ArtifactSchema>> {\n const { data, lastResponse } = await this.http.get<ArtifactSchema>(\n `/api/v1/artifacts/${encodeURIComponent(artifactId)}/schema`,\n opts,\n );\n return { ...data, lastResponse };\n }\n}\n","import type { HttpClient } from '../http-client.js';\nimport type {\n GenerateGovernanceParams,\n GenerateGovernanceResult,\n DetectContradictionsParams,\n DetectContradictionsResult,\n RequestOptions,\n WithLastResponse,\n} from '../types.js';\n\nexport class Governance {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Generate a sealed .nomos governance artifact from policy documents\n * and optional historical decision logs.\n *\n * @example\n * const artifact = await nomos.governance.generate({\n * policies: [policyText],\n * decision_logs: historicalRows,\n * domain: 'loan_approval',\n * });\n * console.log(artifact.ari_score, artifact.seal_hash);\n */\n async generate(\n params: GenerateGovernanceParams,\n opts?: RequestOptions,\n ): Promise<WithLastResponse<GenerateGovernanceResult>> {\n const { data, lastResponse } = await this.http.post<GenerateGovernanceResult>(\n '/api/v1/generate-governance',\n params,\n opts,\n );\n return { ...data, lastResponse };\n }\n\n /**\n * Detect contradictions and conflicts in a rule set before sealing.\n *\n * @example\n * const report = await nomos.governance.detectContradictions({ rules });\n * if (!report.clean) {\n * console.log(report.contradictions);\n * }\n */\n async detectContradictions(\n params: DetectContradictionsParams,\n opts?: RequestOptions,\n ): Promise<WithLastResponse<DetectContradictionsResult>> {\n const { data, lastResponse } = await this.http.post<DetectContradictionsResult>(\n '/api/v1/detect-contradictions',\n params,\n opts,\n );\n return { ...data, lastResponse };\n }\n}\n","import { NomosWebhookSignatureError } from '../errors.js';\nimport type { NomosWebhookEvent } from '../types.js';\n\n// Hex string → Uint8Array (no Buffer dependency — works in Node and browsers)\nfunction hexToBytes(hex: string): Uint8Array {\n if (hex.length % 2 !== 0) throw new NomosWebhookSignatureError('Invalid hex encoding in signature');\n const bytes = new Uint8Array(hex.length / 2);\n for (let i = 0; i < hex.length; i += 2) {\n const byte = parseInt(hex.slice(i, i + 2), 16);\n if (isNaN(byte)) throw new NomosWebhookSignatureError('Invalid hex encoding in signature');\n bytes[i / 2] = byte;\n }\n return bytes;\n}\n\n// Constant-time comparison (prevents timing attacks)\nfunction safeEqual(a: Uint8Array, b: Uint8Array): boolean {\n if (a.length !== b.length) return false;\n let diff = 0;\n for (let i = 0; i < a.length; i++) diff |= a[i] ^ b[i];\n return diff === 0;\n}\n\nexport class Webhooks {\n /**\n * Verify a NOMOS webhook signature and return the parsed event.\n *\n * Signature header format: `t=<unix_ts>,v1=<hmac_sha256_hex>`\n * Signed payload: `<timestamp>.<raw_body>`\n *\n * @example\n * // Express\n * app.post('/webhooks/nomos', express.raw({ type: 'application/json' }), async (req, res) => {\n * const event = await nomos.webhooks.constructEvent(\n * req.body,\n * req.headers['nomos-signature'] as string,\n * process.env.NOMOS_WEBHOOK_SECRET!,\n * );\n * console.log(event.type, event.data);\n * res.sendStatus(200);\n * });\n *\n * @throws {NomosWebhookSignatureError} if signature is invalid, expired, or malformed\n */\n async constructEvent(\n payload: string | Uint8Array,\n signature: string,\n secret: string,\n toleranceSeconds = 300,\n ): Promise<NomosWebhookEvent> {\n const body = typeof payload === 'string'\n ? payload\n : new TextDecoder().decode(payload);\n\n // Parse \"t=<ts>,v1=<hex>\" header\n const parts: Record<string, string> = {};\n for (const part of signature.split(',')) {\n const eq = part.indexOf('=');\n if (eq > -1) parts[part.slice(0, eq).trim()] = part.slice(eq + 1).trim();\n }\n\n if (!parts['t'] || !parts['v1']) {\n throw new NomosWebhookSignatureError(\n 'Invalid signature format — expected \"t=<timestamp>,v1=<hmac>\"',\n );\n }\n\n const timestamp = parseInt(parts['t'], 10);\n if (isNaN(timestamp)) {\n throw new NomosWebhookSignatureError('Invalid timestamp in webhook signature');\n }\n\n const ageSecs = Math.abs(Date.now() / 1000 - timestamp);\n if (toleranceSeconds > 0 && ageSecs > toleranceSeconds) {\n throw new NomosWebhookSignatureError(\n `Webhook timestamp too old (${Math.round(ageSecs)}s > ${toleranceSeconds}s tolerance). ` +\n 'Ensure your server clock is synced and the event is not being replayed.',\n );\n }\n\n // HMAC-SHA256 via Web Crypto API (Node 18+ / modern browsers — no dependencies)\n const enc = new TextEncoder();\n const keyMaterial = await globalThis.crypto.subtle.importKey(\n 'raw',\n enc.encode(secret),\n { name: 'HMAC', hash: 'SHA-256' },\n false,\n ['sign'],\n );\n const signedPayload = `${parts['t']}.${body}`;\n const expectedBuf = await globalThis.crypto.subtle.sign(\n 'HMAC',\n keyMaterial,\n enc.encode(signedPayload),\n );\n const expected = new Uint8Array(expectedBuf);\n const received = hexToBytes(parts['v1']);\n\n if (!safeEqual(expected, received)) {\n throw new NomosWebhookSignatureError(\n 'Webhook signature mismatch — verify your NOMOS_WEBHOOK_SECRET matches the one in Studio.',\n );\n }\n\n try {\n return JSON.parse(body) as NomosWebhookEvent;\n } catch {\n throw new NomosWebhookSignatureError('Webhook payload is not valid JSON');\n }\n }\n\n /**\n * Verify a webhook signature without parsing the event.\n * Returns `true` if valid, `false` if not (never throws).\n *\n * @example\n * const valid = await nomos.webhooks.verifySignature(rawBody, sig, secret);\n * if (!valid) return res.sendStatus(400);\n */\n async verifySignature(\n payload: string | Uint8Array,\n signature: string,\n secret: string,\n toleranceSeconds = 300,\n ): Promise<boolean> {\n try {\n await this.constructEvent(payload, signature, secret, toleranceSeconds);\n return true;\n } catch {\n return false;\n }\n }\n}\n","import type { CanParams, CanResult, CanOptions } from './types.js';\nimport type { HttpClient } from './http-client.js';\nimport {\n NomosAuthenticationError,\n NomosAuthorizationError,\n NomosRateLimitError,\n NomosValidationError,\n NomosNotFoundError,\n NomosAPIError,\n NomosNetworkError,\n NomosPaymentRequiredError,\n NomosIssuerNotTrustedError,\n} from './errors.js';\n\nconst CHAIN_PROTOCOL_VERSION = '1';\n\n/**\n * The whole product in one verb: \"Can I do this?\"\n *\n * Same pattern as Stripe's PaymentIntents API: one function, several rails underneath (a public\n * Exchange authority — free or paid — or your own authenticated artifact), and the caller never\n * has to know which one ran. Don't read `can()` as \"the Exchange's query function\" — the\n * Exchange is one of two rails behind it, not what it means.\n *\n * Both rails call into the SAME server-side implementation NOMOS itself uses (POST /api/v1/can,\n * backed by authority-query.ts's runAuthorityQuery) — not a parallel path, so there is exactly\n * one place that can drift between \"what the SDK returns\" and \"what NOMOS actually decided.\"\n *\n * Verdicts are always AUTHORIZED / DENIED / ESCALATED, normalized into that one vocabulary\n * regardless of which rail answered. `allowed` is simply `verdict === 'AUTHORIZED'`; an\n * ESCALATED result means the authority needs more facts to decide (see `missing_inputs`), not a\n * flat \"no\". A paid Exchange artifact you haven't purchased throws NomosPaymentRequiredError —\n * with the price and a purchase URL attached — rather than a generic 403 or a silent failure.\n * NOMOS never auto-charges on your behalf; this is the seam where a caller decides to buy.\n *\n * @example\n * import { nomos } from '@nomosprotocol/sdk';\n *\n * const verdict = await nomos.can({\n * authority: 'eu-ai-act.nomos',\n * ai_system_circumvents_refugee_convention: true,\n * });\n * // → { allowed: false, verdict: 'DENIED', reason: 'Rule \"Prohibition…\" triggered…',\n * // query_id: 'qry_…', url: '/queries/qry_…', … }\n */\nconst DEFAULT_EXCHANGE_BASE = 'https://www.nomosprotocol.com';\n\nfunction splitFacts(params: CanParams): { facts: Record<string, unknown>; action: string | undefined } {\n const { authority, artifact_id, action, inputs, ...flat } = params;\n void authority; void artifact_id;\n // Two equally valid shapes: an explicit `inputs` object, or the facts spread flat\n // alongside `authority`/`artifact_id`/`action`. Explicit `inputs` wins when both are present.\n const facts: Record<string, unknown> =\n inputs && typeof inputs === 'object' ? inputs : (flat as Record<string, unknown>);\n return { facts, action };\n}\n\nfunction mapHttpError(status: number, data: any, requestId: string): never {\n const message: string = data?.error ?? data?.message ?? `NOMOS query failed (HTTP ${status})`;\n // Checked by CODE, not by the raw wire status (403) — this is \"here's what unlocks it,\" a\n // materially different thing for a caller to act on than \"you're not allowed at all.\"\n if (data?.code === 'PURCHASE_REQUIRED') {\n throw new NomosPaymentRequiredError(message, data.price_usd ?? 0, data.purchase_url ?? '', requestId);\n }\n switch (status) {\n case 401: throw new NomosAuthenticationError(message, requestId);\n case 403: throw new NomosAuthorizationError(message, requestId);\n case 404: throw new NomosNotFoundError(message, requestId);\n case 422:\n case 400: throw new NomosValidationError(message, data?.details, requestId);\n case 429: throw new NomosRateLimitError(message, undefined, requestId);\n default: throw new NomosAPIError(message, status, requestId);\n }\n}\n\n/** Both Exchange-rail paths (keyless and authenticated) return the same underlying shape —\n * authority-query.ts's AuthorityQueryResult, spread with a few convenience fields by the\n * /api/v1/can route. One normalizer for both, so they can't quietly drift apart. */\nfunction normalizeAuthorityQueryResult(data: any, authority: string): CanResult {\n return {\n allowed: data.verdict === 'AUTHORIZED',\n verdict: data.verdict,\n reason: data.verdict_description,\n rule: data.matched_rule_id ?? null,\n query_id: data.query_id,\n url: data.url,\n authority: {\n id: data.artifact?.id ?? authority,\n title: data.artifact?.title ?? '',\n standing: data.artifact?.standing ?? '',\n ...(data.artifact?.attestation ? { attestation: data.artifact.attestation } : {}),\n },\n ...(data.artifact?.version ? { version: data.artifact.version } : {}),\n missing_inputs: data.missing_inputs ?? [],\n ...(typeof data.max_age === 'number' ? { max_age: data.max_age } : {}),\n // authority-query.ts already returns { kind, rule_id, rule_name } — the public-safe shape\n // CanResult uses directly.\n ...(Array.isArray(data.obligations) && data.obligations.length > 0 ? { obligations: data.obligations } : {}),\n // NOMOS-SPEC-006 — present only when the issuer has actually revoked this exact sealed\n // version; omitted (not false) when revocation doesn't structurally apply here, so \"checked\n // and clean\" and \"couldn't check\" never look the same to a caller.\n ...(data.revoked === true ? { revoked: true, revocation_reason: data.revocation_reason } : {}),\n };\n}\n\n/** Keyless — used only by the free top-level `can()` export. Free Exchange artifacts answer\n * anonymously; a paid one throws NomosPaymentRequiredError, since there's no API key here to\n * check purchase/license ownership against. */\nasync function canViaExchange(authority: string, facts: Record<string, unknown>, action: string | undefined, opts?: CanOptions): Promise<CanResult> {\n const base = (opts?.baseUrl ?? DEFAULT_EXCHANGE_BASE).replace(/\\/$/, '');\n const url = `${base}/api/v1/can`;\n\n let res: Response;\n try {\n res = await fetch(url, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ artifact: authority, action, ...facts }),\n signal: opts?.signal,\n });\n } catch (err: any) {\n if (err?.name === 'AbortError') throw new NomosNetworkError('Request aborted');\n throw new NomosNetworkError(err?.message ?? 'Network error');\n }\n\n const requestId = res.headers.get('x-request-id') ?? '';\n const data: any = await res.json().catch(() => null);\n if (!res.ok) mapHttpError(res.status, data, requestId);\n return normalizeAuthorityQueryResult(data, authority);\n}\n\n/** Authenticated — used by `client.can({ authority })`. Same endpoint, same normalization, but\n * routed through the instance's own HttpClient so its API key rides along: a paid artifact the\n * caller has purchased or published now actually works, which the keyless rail structurally\n * cannot support (there is no key there to check ownership against). */\nasync function canViaExchangeAuthenticated(http: HttpClient, authority: string, facts: Record<string, unknown>, action: string | undefined): Promise<CanResult> {\n const { data } = await http.post<any>('/api/v1/can', { artifact: authority, action, ...facts });\n return normalizeAuthorityQueryResult(data, authority);\n}\n\n/** The authenticated-artifact rail — your own artifact, requires an API key (an authenticated\n * `Nomos` instance's HttpClient). Normalizes the engine's own response shape (approved/rejected/\n * escalated, an audit hash) into the SAME AUTHORIZED/DENIED/ESCALATED verdict shape the Exchange\n * rail returns, rather than leaking a second vocabulary out to the caller. */\nasync function canViaArtifact(http: HttpClient, artifactId: string, facts: Record<string, unknown>, action: string | undefined): Promise<CanResult> {\n const isPublic = artifactId.startsWith('pub_');\n const path = isPublic ? '/api/v1/verify' : '/api/v1/verify-decision';\n const body = isPublic\n ? { artifact_id: artifactId, decision: action ?? 'evaluate', inputs: facts }\n : { artifact_id: artifactId, decision: action ?? 'evaluate', inputs: facts, caller: { correlation_id: globalThis.crypto.randomUUID() } };\n\n // Note: CanOptions.signal has no effect here — HttpClient has no external abort-signal\n // passthrough anywhere in the SDK today (its own internal AbortController is timeout-only).\n // Pre-existing limitation, not introduced by this rail; not worth faking a parameter that\n // silently does nothing.\n const { data: raw } = await http.post<any>(path, body);\n\n const verdict: CanResult['verdict'] =\n raw.verdict === 'approved' ? 'AUTHORIZED'\n : raw.verdict === 'rejected' ? 'DENIED'\n : raw.outcome === 'auto_approved' ? 'AUTHORIZED'\n : raw.outcome === 'auto_rejected' ? 'DENIED'\n : 'ESCALATED';\n\n return {\n allowed: raw.allowed ?? verdict === 'AUTHORIZED',\n verdict,\n reason: raw.verdict_description ?? '',\n rule: raw.rule?.id ?? null,\n authority: {\n id: raw.artifact_id ?? artifactId,\n title: raw.artifact_name ?? '',\n standing: raw.confidence?.tier ?? '',\n },\n ...(raw.artifact_version ? { version: raw.artifact_version } : {}),\n missing_inputs: raw.incomplete_inputs?.fields ?? [],\n ...(raw.audit ? { audit: { hash: raw.audit.hash ?? raw.audit_hash ?? '', timestamp: raw.audit.timestamp ?? raw.ts ?? new Date().toISOString() } } : {}),\n // This rail's obligations are RuleEffect objects (authority-types.ts) — a richer, INTERNAL\n // shape ({ effect_type, value, provenance: { rule_id, rule_name } }), NOT the same shape the\n // Exchange rail already returns ({ kind, rule_id, rule_name }). Mapped explicitly here rather\n // than passed through raw — the two rails' server-side representations genuinely differ, and\n // assuming they matched would have been the actual bug.\n ...(Array.isArray(raw.obligations) && raw.obligations.length > 0\n ? { obligations: raw.obligations.map((o: any) => ({\n kind: o.kind ?? o.value ?? 'obligation',\n rule_id: o.rule_id ?? o.provenance?.rule_id ?? null,\n rule_name: o.rule_name ?? o.provenance?.rule_name ?? null,\n ...(o.reason ? { reason: o.reason } : {}),\n })) }\n : {}),\n };\n}\n\n/**\n * The chain-of-trust rail (PROTOTYPE, not a numbered spec). Keyless — works identically on the\n * free `can()` export and `client.can()`, since there's no account relationship to check here.\n * The server verifies the presented chain resolves to `root_public_key_pem` and, ONLY once that\n * succeeds, evaluates the artifact's own rules against `facts` — the same evaluator every other\n * rail uses (evaluateArtifactAgainstFacts, extracted from and proven identical to\n * /api/v1/verify-decision). An artifact whose chain doesn't resolve is never evaluated: this\n * throws NomosIssuerNotTrustedError instead of returning a verdict, because \"the rules say no\"\n * and \"we never established who's asking\" are different claims a caller needs to react to\n * differently — collapsing them into DENIED would tell the caller the wrong thing to do next.\n */\nasync function canViaChain(\n artifact: unknown, keyCerts: unknown, rootPublicKeyPem: string,\n facts: Record<string, unknown>, action: string | undefined, opts?: CanOptions,\n): Promise<CanResult> {\n const base = (opts?.baseUrl ?? DEFAULT_EXCHANGE_BASE).replace(/\\/$/, '');\n const url = `${base}/api/v1/chain-of-trust/verify`;\n\n let res: Response;\n try {\n res = await fetch(url, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ version: CHAIN_PROTOCOL_VERSION, artifact, key_certs: keyCerts, root_public_key_pem: rootPublicKeyPem, facts, action }),\n signal: opts?.signal,\n });\n } catch (err: any) {\n if (err?.name === 'AbortError') throw new NomosNetworkError('Request aborted');\n throw new NomosNetworkError(err?.message ?? 'Network error');\n }\n\n const requestId = res.headers.get('x-request-id') ?? '';\n const data: any = await res.json().catch(() => null);\n\n if (data?.decision === 'AUTHORIZED' || data?.decision === 'DENIED' || data?.decision === 'ESCALATED') {\n return {\n allowed: data.decision === 'AUTHORIZED',\n verdict: data.decision,\n reason: data.reason ?? '',\n rule: data.rule ?? null,\n authority: { id: 'presented-artifact', title: '', standing: '' },\n // Read directly off the artifact the caller already has — no server round-trip needed for\n // data the caller is already holding.\n ...((artifact as any)?.meta?.version ? { version: (artifact as any).meta.version } : {}),\n missing_inputs: data.missing_inputs ?? [],\n ...(Array.isArray(data.obligations) && data.obligations.length > 0 ? { obligations: data.obligations } : {}),\n // Deliberately no query_id/url/audit — this evaluation is stateless by design (the whole\n // point is answering without NOMOS needing to have seen this artifact before); there is no\n // permanent transcript to point to, and faking one would misrepresent what just happened.\n };\n }\n\n // ALLOWED (facts were somehow not evaluated — shouldn't happen when facts are always sent, but\n // handled rather than assumed impossible), or one of the chain-failure decisions.\n const message: string = data?.detail ?? `Chain verification failed (HTTP ${res.status})`;\n if (data?.decision === 'ISSUER_NOT_RECOGNIZED' || data?.decision === 'KEY_REVOKED' || data?.decision === 'SEAL_INVALID' || data?.decision === 'ALLOWED') {\n throw new NomosIssuerNotTrustedError(message, data.decision, requestId);\n }\n if (data?.decision === 'MALFORMED') throw new NomosValidationError(message, data, requestId);\n mapHttpError(res.status, data, requestId);\n}\n\nexport async function can(params: CanParams, opts?: CanOptions): Promise<CanResult> {\n if (params.artifact !== undefined) {\n if (!params.key_certs || !params.root_public_key_pem) {\n throw new Error('can(): `artifact` requires `key_certs` and `root_public_key_pem` alongside it.');\n }\n const { facts, action } = splitFacts(params);\n return canViaChain(params.artifact, params.key_certs, params.root_public_key_pem, facts, action, opts);\n }\n if (params.artifact_id) {\n throw new Error('can(): `artifact_id` requires an API key — use `client.can(...)` on an authenticated Nomos instance, not the free `can()` export.');\n }\n if (!params.authority || typeof params.authority !== 'string') {\n throw new Error('can(): `authority` (an Exchange artifact id or slug), `artifact_id` (via client.can()), or `artifact` (chain-of-trust) is required.');\n }\n const { facts, action } = splitFacts(params);\n return canViaExchange(params.authority, facts, action, opts);\n}\n\n/** Shared implementation behind `Nomos.prototype.can()` — see nomos.ts. Exported so the class\n * stays a thin wrapper and this routing logic lives in exactly one place. */\nexport async function canAuthenticated(http: HttpClient, params: CanParams, opts?: CanOptions): Promise<CanResult> {\n void opts; // reserved — HttpClient has no external signal passthrough today, see canViaArtifact's note\n const { facts, action } = splitFacts(params);\n if (params.artifact !== undefined) {\n if (!params.key_certs || !params.root_public_key_pem) {\n throw new Error('can(): `artifact` requires `key_certs` and `root_public_key_pem` alongside it.');\n }\n // Keyless rail — an authenticated client is still free to use it, same server endpoint.\n return canViaChain(params.artifact, params.key_certs, params.root_public_key_pem, facts, action, opts);\n }\n if (params.artifact_id) return canViaArtifact(http, params.artifact_id, facts, action);\n if (params.authority) return canViaExchangeAuthenticated(http, params.authority, facts, action);\n throw new Error('can(): `authority` (a public Exchange artifact), `artifact_id` (your own artifact), or `artifact` (chain-of-trust) is required.');\n}\n\n/**\n * Ready-to-use, keyless entry point matching the canonical `nomos.can(...)` form.\n * For paid artifacts or your own artifacts, use `client.can(...)` on an authenticated `Nomos`\n * instance instead — same function name, same verdict shape, the only difference is which rail\n * answers and what it can unlock.\n */\nexport const nomos = { can };\n","import { HttpClient } from './http-client.js';\nimport { Decisions } from './resources/decisions.js';\nimport { Artifacts } from './resources/artifacts.js';\nimport { Governance } from './resources/governance.js';\nimport { Webhooks } from './resources/webhooks.js';\nimport { canAuthenticated } from './can.js';\nimport * as errors from './errors.js';\nimport type { NomosConfig, CanParams, CanOptions, CanResult } from './types.js';\n\nconst DEFAULT_BASE_URL = 'https://nomos.ai';\nconst DEFAULT_MAX_RETRIES = 3;\nconst DEFAULT_TIMEOUT = 30_000;\n\nexport class Nomos {\n readonly decisions: Decisions;\n readonly artifacts: Artifacts;\n readonly governance: Governance;\n readonly webhooks: Webhooks;\n\n /** Whether this instance is using a live or test API key. */\n readonly mode: 'live' | 'test';\n\n static readonly errors = errors;\n\n private readonly http: HttpClient;\n\n constructor(apiKey: string, config: NomosConfig = {}) {\n if (!apiKey || typeof apiKey !== 'string') {\n throw new errors.NomosAuthenticationError(\n 'A valid API key is required. Pass it as the first argument: new Nomos(\"nms_live_...\")',\n );\n }\n\n this.mode = apiKey.startsWith('nms_test_') ? 'test' : 'live';\n\n this.http = new HttpClient({\n apiKey,\n baseUrl: (config.baseUrl ?? DEFAULT_BASE_URL).replace(/\\/$/, ''),\n maxRetries: config.maxRetries ?? DEFAULT_MAX_RETRIES,\n timeout: config.timeout ?? DEFAULT_TIMEOUT,\n });\n\n this.decisions = new Decisions(this.http);\n this.artifacts = new Artifacts(this.http);\n this.governance = new Governance(this.http);\n this.webhooks = new Webhooks();\n }\n\n /**\n * \"Can I do this?\" — the one verb, now covering your own artifacts too. Pass `authority` for a\n * public Exchange artifact, or `artifact_id` for your own (Studio or the Exchange) — same\n * return shape either way, so calling code never needs to know which rail answered.\n *\n * @example\n * const client = new Nomos('nms_live_...');\n * const verdict = await client.can({ artifact_id: 'loan_approval_v1', credit_score: 720 });\n */\n async can(params: CanParams, opts?: CanOptions): Promise<CanResult> {\n return canAuthenticated(this.http, params, opts);\n }\n}\n","import type { VerifyChainParams, VerifyChainOptions, VerifyChainResult } from './types.js';\nimport {\n NomosValidationError,\n NomosRateLimitError,\n NomosAPIError,\n NomosNetworkError,\n} from './errors.js';\n\nconst CHAIN_PROTOCOL_VERSION = '1';\nconst DEFAULT_BASE = 'https://www.nomosprotocol.com';\n\n/**\n * Chain-of-trust verification (PROTOTYPE — not a numbered spec). Checks whether a presented\n * artifact's signing key resolves, through the presented key certificates, back to a root you\n * have independently decided to trust — entirely server-side against nomos-chain.ts's pure\n * verifier, with no account or API key required (keyless, matching `nomos.can()`'s precedent).\n *\n * There is no default root anywhere in this call — `root_public_key_pem` is required. That's\n * deliberate: it keeps the trust decision with the caller, not with this SDK or the platform.\n *\n * @example\n * import { verifyChain } from '@nomosprotocol/sdk';\n *\n * const result = await verifyChain({\n * artifact: sealedArtifact,\n * key_certs: [rootToIntermediate, intermediateToLeaf],\n * root_public_key_pem: myPinnedRootPem,\n * });\n * if (result.decision === 'ALLOWED') { ... }\n */\nexport async function verifyChain(params: VerifyChainParams, opts?: VerifyChainOptions): Promise<VerifyChainResult> {\n if (!params.root_public_key_pem) {\n throw new Error('verifyChain(): `root_public_key_pem` is required — there is no default root.');\n }\n const base = (opts?.baseUrl ?? DEFAULT_BASE).replace(/\\/$/, '');\n const url = `${base}/api/v1/chain-of-trust/verify`;\n\n let res: Response;\n try {\n res = await fetch(url, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n version: CHAIN_PROTOCOL_VERSION,\n artifact: params.artifact,\n key_certs: params.key_certs,\n root_public_key_pem: params.root_public_key_pem,\n }),\n signal: opts?.signal,\n });\n } catch (err: any) {\n if (err?.name === 'AbortError') throw new NomosNetworkError('Request aborted');\n throw new NomosNetworkError(err?.message ?? 'Network error');\n }\n\n const requestId = res.headers.get('x-request-id') ?? '';\n const data: any = await res.json().catch(() => null);\n\n // 400/403/422 all carry a real ChainVerdict body (MALFORMED/ISSUER_NOT_RECOGNIZED/KEY_REVOKED/\n // SEAL_INVALID) — that's a verdict, not a transport failure, so it's returned, not thrown.\n if (data && typeof data.decision === 'string') {\n return data as VerifyChainResult;\n }\n\n const message: string = data?.error ?? `Chain verification request failed (HTTP ${res.status})`;\n if (res.status === 429) {\n throw new NomosRateLimitError(message, res.headers.get('retry-after') ? parseInt(res.headers.get('retry-after')!, 10) : undefined, requestId);\n }\n if (res.status === 400) throw new NomosValidationError(message, data?.details, requestId);\n throw new NomosAPIError(message, res.status, requestId);\n}\n"],"mappings":";;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAYO,IAAM,aAAN,cAAyB,MAAM;AAAA,EAKpC,YAAY,SAAiB,MAAsB,QAAiB,WAAoB;AACtF,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,YAAY;AAAA,EACnB;AACF;AAEO,IAAM,2BAAN,cAAuC,WAAW;AAAA,EACvD,YAAY,UAAU,mBAAmB,WAAoB;AAC3D,UAAM,SAAS,wBAAwB,KAAK,SAAS;AACrD,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,0BAAN,cAAsC,WAAW;AAAA,EACtD,YAAY,UAAU,iBAAiB,WAAoB;AACzD,UAAM,SAAS,uBAAuB,KAAK,SAAS;AACpD,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,sBAAN,cAAkC,WAAW;AAAA,EAGlD,YAAY,UAAU,uBAAuB,YAAqB,WAAoB;AACpF,UAAM,SAAS,oBAAoB,KAAK,SAAS;AACjD,SAAK,OAAO;AACZ,SAAK,aAAa;AAAA,EACpB;AACF;AAEO,IAAM,uBAAN,cAAmC,WAAW;AAAA,EAGnD,YAAY,SAAiB,SAAmB,WAAoB;AAClE,UAAM,SAAS,oBAAoB,KAAK,SAAS;AACjD,SAAK,OAAO;AACZ,SAAK,UAAU;AAAA,EACjB;AACF;AAEO,IAAM,qBAAN,cAAiC,WAAW;AAAA,EACjD,YAAY,SAAiB,WAAoB;AAC/C,UAAM,SAAS,aAAa,KAAK,SAAS;AAC1C,SAAK,OAAO;AAAA,EACd;AACF;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AY,IAAI,QAAQ,IAAI,cAAc,KAAK;AACrD,QAAM,OAAY,MAAM,IAAI,KAAK,EAAE,MAAM,MAAM,IAAI;AAInD,MAAI,QAAQ,OAAO,KAAK,aAAa,UAAU;AAC7C,WAAO;AAAA,EACT;AAEA,QAAM,UAAkB,MAAM,SAAS,2CAA2C,IAAI,MAAM;AAC5F,MAAI,IAAI,WAAW,KAAK;AACtB,UAAM,IAAI,oBAAoB,SAAS,IAAI,QAAQ,IAAI,aAAa,IAAI,SAAS,IAAI,QAAQ,IAAI,aAAa,GAAI,EAAE,IAAI,QAAW,SAAS;AAAA,EAC9I;AACA,MAAI,IAAI,WAAW,IAAK,OAAM,IAAI,qBAAqB,SAAS,MAAM,SAAS,SAAS;AACxF,QAAM,IAAI,cAAc,SAAS,IAAI,QAAQ,SAAS;AACxD;","names":["facts","action","CHAIN_PROTOCOL_VERSION"]}
1
+ {"version":3,"sources":["../src/errors.ts","../src/util.ts","../src/http-client.ts","../src/resources/decisions.ts","../src/resources/artifacts.ts","../src/resources/governance.ts","../src/resources/webhooks.ts","../src/resources/conserved-state.ts","../src/can.ts","../src/nomos.ts","../src/verify-chain.ts"],"sourcesContent":["export type NomosErrorCode =\n | 'authentication_error'\n | 'authorization_error'\n | 'rate_limit_error'\n | 'validation_error'\n | 'not_found'\n | 'api_error'\n | 'network_error'\n | 'webhook_signature_error'\n | 'payment_required'\n | 'issuer_not_trusted';\n\nexport class NomosError extends Error {\n readonly code: NomosErrorCode;\n readonly status?: number;\n readonly requestId?: string;\n /** The full parsed JSON response body, when the server sent one — every field it put there\n * (its own `code`, and anything endpoint-specific like `requested`/`available` on a\n * conserved-state capacity rejection, or `price_usd`/`purchase_url` before those got a\n * dedicated error class). `NomosError`'s own `code` above is the SDK's fixed HTTP-status\n * taxonomy; `details?.code` is the SERVER's own, finer-grained application code — the two\n * are deliberately not conflated into one field. */\n readonly details?: unknown;\n\n constructor(message: string, code: NomosErrorCode, status?: number, requestId?: string, details?: unknown) {\n super(message);\n this.name = 'NomosError';\n this.code = code;\n this.status = status;\n this.requestId = requestId;\n this.details = details;\n }\n}\n\nexport class NomosAuthenticationError extends NomosError {\n constructor(message = 'Invalid API key', requestId?: string, details?: unknown) {\n super(message, 'authentication_error', 401, requestId, details);\n this.name = 'NomosAuthenticationError';\n }\n}\n\nexport class NomosAuthorizationError extends NomosError {\n constructor(message = 'Access denied', requestId?: string, details?: unknown) {\n super(message, 'authorization_error', 403, requestId, details);\n this.name = 'NomosAuthorizationError';\n }\n}\n\nexport class NomosRateLimitError extends NomosError {\n readonly retryAfter?: number;\n\n constructor(message = 'Rate limit exceeded', retryAfter?: number, requestId?: string, details?: unknown) {\n super(message, 'rate_limit_error', 429, requestId, details);\n this.name = 'NomosRateLimitError';\n this.retryAfter = retryAfter;\n }\n}\n\n/** `details` is the parsed response body — kept as its own constructor param (rather than just\n * relying on the base class field) since it long predates NomosError.details and every caller\n * already passes it positionally in this slot; unchanged for backward compatibility. */\nexport class NomosValidationError extends NomosError {\n constructor(message: string, details?: unknown, requestId?: string) {\n super(message, 'validation_error', 400, requestId, details);\n this.name = 'NomosValidationError';\n }\n}\n\nexport class NomosNotFoundError extends NomosError {\n constructor(message: string, requestId?: string, details?: unknown) {\n super(message, 'not_found', 404, requestId, details);\n this.name = 'NomosNotFoundError';\n }\n}\n\nexport class NomosAPIError extends NomosError {\n constructor(message: string, status: number, requestId?: string, details?: unknown) {\n super(message, 'api_error', status, requestId, details);\n this.name = 'NomosAPIError';\n }\n}\n\nexport class NomosNetworkError extends NomosError {\n constructor(message: string) {\n super(message, 'network_error');\n this.name = 'NomosNetworkError';\n }\n}\n\nexport class NomosWebhookSignatureError extends NomosError {\n constructor(message: string) {\n super(message, 'webhook_signature_error', 400);\n this.name = 'NomosWebhookSignatureError';\n }\n}\n\n/** can() asked about a paid authority the caller hasn't purchased or licensed. Distinct from a\n * generic 403 on purpose: this isn't \"you're not allowed,\" it's \"here's exactly what unlocks\n * it\" — price and a URL to complete the purchase. NOMOS never auto-charges on your behalf;\n * this is the seam where a caller decides to buy, not where a payment silently happens. */\nexport class NomosPaymentRequiredError extends NomosError {\n readonly priceUsd: number;\n readonly purchaseUrl: string;\n\n constructor(message: string, priceUsd: number, purchaseUrl: string, requestId?: string) {\n super(message, 'payment_required', 402, requestId);\n this.name = 'NomosPaymentRequiredError';\n this.priceUsd = priceUsd;\n this.purchaseUrl = purchaseUrl;\n }\n}\n\n/** can()'s chain-of-trust rail could not establish that the presented artifact carries authority\n * it is entitled to — an unrecognized issuer, a revoked key, a delegation that never covered\n * this artifact, a tampered seal, or a malformed presentation. This is deliberately NOT a DENIED\n * verdict: \"the rules say no\" and \"we never got far enough to ask the rules anything\" are\n * different claims, and collapsing them would tell the caller the wrong thing to do next.\n *\n * `reason` carries the underlying chain decision so callers can distinguish them, because the\n * right next action genuinely differs:\n * ISSUER_NOT_RECOGNIZED — presenting a more complete chain may fix this\n * KEY_REVOKED — that key is dead; a different, unrevoked chain might work\n * CERTIFICATE_REVOKED — one delegation was withdrawn; another certificate for the same\n * key may still resolve\n * OUT_OF_SCOPE — the issuer IS recognized but was not delegated authority over this\n * artifact; only a broader (validly issued) delegation fixes it\n * SEAL_INVALID — the artifact itself was altered; nothing about presentation helps\n * MALFORMED — the request shape was wrong (a client-side bug) */\nexport class NomosIssuerNotTrustedError extends NomosError {\n readonly reason: string;\n\n constructor(message: string, reason: string, requestId?: string) {\n super(message, 'issuer_not_trusted', 403, requestId);\n this.name = 'NomosIssuerNotTrustedError';\n this.reason = reason;\n }\n}\n","export async function sleep(ms: number): Promise<void> {\n return new Promise(resolve => setTimeout(resolve, ms));\n}\n\nexport function jitteredBackoff(attempt: number, baseMs = 500): number {\n const exp = Math.min(baseMs * 2 ** attempt, 16000);\n return exp * (0.75 + Math.random() * 0.5); // ±25% jitter\n}\n\nexport function isRetryable(status: number): boolean {\n return status === 429 || status >= 500;\n}\n","import {\n NomosAuthenticationError,\n NomosAuthorizationError,\n NomosRateLimitError,\n NomosValidationError,\n NomosNotFoundError,\n NomosAPIError,\n NomosNetworkError,\n} from './errors.js';\nimport { sleep, jitteredBackoff, isRetryable } from './util.js';\nimport type { RequestOptions, NomosRawResponse } from './types.js';\n\nconst SDK_VERSION = '1.1.0';\n\nexport interface HttpClientOptions {\n apiKey: string;\n baseUrl: string;\n maxRetries: number;\n timeout: number;\n}\n\nexport interface HttpResponse<T> {\n data: T;\n lastResponse: NomosRawResponse;\n}\n\nexport class HttpClient {\n constructor(private readonly opts: HttpClientOptions) {}\n\n async get<T>(path: string, reqOpts?: RequestOptions): Promise<HttpResponse<T>> {\n return this.request<T>('GET', path, undefined, reqOpts);\n }\n\n async post<T>(path: string, body: unknown, reqOpts?: RequestOptions): Promise<HttpResponse<T>> {\n return this.request<T>('POST', path, body, reqOpts);\n }\n\n private async request<T>(\n method: string,\n path: string,\n body: unknown,\n reqOpts?: RequestOptions,\n attempt = 0,\n ): Promise<HttpResponse<T>> {\n const apiKey = reqOpts?.apiKey ?? this.opts.apiKey;\n const timeout = reqOpts?.timeout ?? this.opts.timeout;\n const maxRetries = reqOpts?.maxRetries ?? this.opts.maxRetries;\n\n const url = `${this.opts.baseUrl}${path}`;\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), timeout);\n\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n 'X-Nomos-Api-Key': apiKey,\n 'User-Agent': `nomos-node/${SDK_VERSION}`,\n 'NOMOS-SDK-Version': SDK_VERSION,\n };\n if (reqOpts?.idempotencyKey) {\n headers['Idempotency-Key'] = reqOpts.idempotencyKey;\n }\n\n let res: Response;\n try {\n res = await fetch(url, {\n method,\n signal: controller.signal,\n headers,\n body: body != null ? JSON.stringify(body) : undefined,\n });\n } catch (err: any) {\n clearTimeout(timer);\n if (err.name === 'AbortError') {\n throw new NomosNetworkError(`Request timed out after ${timeout}ms`);\n }\n throw new NomosNetworkError(err.message ?? 'Network error');\n } finally {\n clearTimeout(timer);\n }\n\n const requestId = res.headers.get('x-request-id') ?? '';\n const rawHeaders: Record<string, string> = {};\n res.headers.forEach((value, key) => { rawHeaders[key] = value; });\n const lastResponse: NomosRawResponse = {\n requestId,\n statusCode: res.status,\n headers: rawHeaders,\n };\n\n if (res.ok) {\n const data = await res.json() as T;\n return { data, lastResponse };\n }\n\n // Retry on 429 / 5xx\n if (isRetryable(res.status) && attempt < maxRetries) {\n const retryAfter = res.headers.get('retry-after');\n const delay = retryAfter ? parseInt(retryAfter, 10) * 1000 : jitteredBackoff(attempt);\n await sleep(delay);\n return this.request<T>(method, path, body, reqOpts, attempt + 1);\n }\n\n let errBody: any = {};\n try { errBody = await res.json(); } catch {}\n const message: string = errBody?.error ?? errBody?.message ?? res.statusText;\n\n switch (res.status) {\n case 401: throw new NomosAuthenticationError(message, requestId, errBody);\n case 403: throw new NomosAuthorizationError(message, requestId, errBody);\n case 404: throw new NomosNotFoundError(message, requestId, errBody);\n case 422:\n case 400: throw new NomosValidationError(message, errBody?.details ?? errBody, requestId);\n case 429: throw new NomosRateLimitError(\n message,\n res.headers.get('retry-after') ? parseInt(res.headers.get('retry-after')!, 10) : undefined,\n requestId,\n errBody,\n );\n // No case for 409 (conflict) specifically — several endpoints use it for distinct\n // application-level rejections (e.g. conserved-state capacity/conflict/already-used);\n // `errBody` (this default branch's `details`) is what lets a caller tell those apart via\n // `err.details?.code`, not a status-code switch that would have to keep growing per feature.\n default: throw new NomosAPIError(message, res.status, requestId, errBody);\n }\n }\n}\n","import type { HttpClient } from '../http-client.js';\nimport type {\n VerifyDecisionParams,\n VerifyDecisionResult,\n RequestOptions,\n WithLastResponse,\n} from '../types.js';\n\nexport class Decisions {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Verify whether an AI decision is permitted under a governance artifact.\n *\n * Public demo artifacts (`pub_*`) work without an API key.\n * Custom artifacts require a valid API key.\n *\n * @example\n * const result = await nomos.decisions.verify({\n * artifact_id: 'pub_lending_v1',\n * decision_context: { credit_score: 720, loan_amount: 50000 },\n * });\n *\n * if (!result.allowed) {\n * throw new Error(`Blocked: ${result.verdict_description}`);\n * }\n *\n * // Debugging / tracing\n * console.log(result.lastResponse.requestId);\n *\n * @example\n * // Per-request options\n * const result = await nomos.decisions.verify(params, {\n * idempotencyKey: `verify-${transactionId}`,\n * timeout: 5000,\n * });\n */\n async verify(\n params: VerifyDecisionParams,\n opts?: RequestOptions,\n ): Promise<WithLastResponse<VerifyDecisionResult>> {\n const { artifact_id, decision_context, proposed_decision, correlation_id } = params;\n\n // Public artifacts (pub_*) use the open /verify endpoint — no API key required\n const isPublic = artifact_id.startsWith('pub_');\n let httpResp: Awaited<ReturnType<HttpClient['post']>>;\n\n if (isPublic) {\n httpResp = await this.http.post<any>('/api/v1/verify', {\n artifact_id,\n decision: proposed_decision ?? 'evaluate',\n inputs: decision_context,\n }, opts);\n } else {\n // /verify-decision expects: { artifact_id, decision, inputs, caller? }\n // NOT decision_context / proposed_decision at the top level.\n httpResp = await this.http.post<any>('/api/v1/verify-decision', {\n artifact_id,\n decision: proposed_decision ?? 'evaluate',\n inputs: decision_context,\n caller: { correlation_id: correlation_id ?? globalThis.crypto.randomUUID() },\n }, opts);\n }\n\n const raw: any = httpResp.data;\n\n return {\n id: raw.id ?? `req_${raw.execution_id ?? globalThis.crypto.randomUUID()}`,\n object: raw.object ?? 'decision',\n artifact_id: raw.artifact_id ?? artifact_id,\n artifact_name: raw.artifact_name ?? '',\n allowed: raw.allowed ?? false,\n verdict: raw.verdict ?? (raw.outcome === 'auto_approved' ? 'approved' : raw.outcome === 'auto_rejected' ? 'rejected' : 'escalated'),\n rule: raw.rule,\n evaluation: raw.evaluation ?? { rules_evaluated: raw.rules_evaluated ?? 0, rules_matched: 0, rules_expired: 0, conflicts_resolved: 0 },\n confidence: raw.confidence ?? { tier: raw.artifact_confidence ?? 'DECLARED', score: 1, description: '' },\n audit: raw.audit ?? { hash: raw.audit_hash ?? raw.audit_record ?? '', timestamp: raw.ts ?? new Date().toISOString() },\n performance: raw.performance ?? { latency_ms: raw.latency_ms ?? 0 },\n schema_version: raw.schema_version ?? '1.0.0',\n verdict_description: raw.verdict_description ?? '',\n incomplete_inputs: raw.incomplete_inputs,\n paths_to_approval: raw.paths_to_approval,\n lastResponse: httpResp.lastResponse,\n };\n }\n}\n","import type { HttpClient } from '../http-client.js';\nimport type {\n Artifact,\n ArtifactList,\n ArtifactSchema,\n ListArtifactsParams,\n RequestOptions,\n WithLastResponse,\n} from '../types.js';\n\nexport class Artifacts {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Retrieve a single artifact by ID.\n *\n * @example\n * const artifact = await nomos.artifacts.retrieve('loan_approval_v1');\n * console.log(artifact.ari_score, artifact.autonomy_band);\n * console.log(artifact.lastResponse.requestId); // for support tickets\n */\n async retrieve(\n artifactId: string,\n opts?: RequestOptions,\n ): Promise<WithLastResponse<Artifact>> {\n const { data, lastResponse } = await this.http.get<Artifact>(\n `/api/exchange/artifacts/${encodeURIComponent(artifactId)}`,\n opts,\n );\n return { ...data, lastResponse };\n }\n\n /**\n * List published artifacts on the Exchange with optional filters.\n *\n * @example\n * const { data, total } = await nomos.artifacts.list({ band: 'autonomous', limit: 10 });\n *\n * @example\n * // With per-request options\n * const page = await nomos.artifacts.list({ limit: 20 }, { timeout: 5000 });\n */\n async list(\n params: ListArtifactsParams = {},\n opts?: RequestOptions,\n ): Promise<WithLastResponse<ArtifactList>> {\n const qs = new URLSearchParams();\n if (params.band) qs.set('band', params.band);\n if (params.domain) qs.set('domain', params.domain);\n if (params.jurisdiction) qs.set('jurisdiction', params.jurisdiction);\n if (params.sort) qs.set('sort', params.sort);\n if (params.limit != null) qs.set('limit', String(params.limit));\n if (params.offset != null) qs.set('offset', String(params.offset));\n const query = qs.toString();\n\n const { data: raw, lastResponse } = await this.http.get<any>(\n `/api/exchange/artifacts${query ? `?${query}` : ''}`,\n opts,\n );\n\n // API returns { artifacts: [], total: N } — normalise to { data: [], total: N }\n const normalized: ArtifactList = {\n data: Array.isArray(raw) ? raw : (raw.artifacts ?? raw.data ?? []),\n total: raw.total ?? (Array.isArray(raw) ? raw.length : 0),\n limit: params.limit ?? 20,\n offset: params.offset ?? 0,\n };\n\n return { ...normalized, lastResponse };\n }\n\n /**\n * Auto-paginating iterator — yields every artifact across all pages.\n * Stops automatically when the last page is reached.\n *\n * @example\n * for await (const artifact of nomos.artifacts.listAutoPaging({ band: 'autonomous' })) {\n * console.log(artifact.title, artifact.ari_score);\n * }\n */\n async *listAutoPaging(\n params: ListArtifactsParams = {},\n opts?: RequestOptions,\n ): AsyncGenerator<Artifact> {\n let offset = params.offset ?? 0;\n const limit = params.limit ?? 20;\n\n while (true) {\n const page = await this.list({ ...params, offset, limit }, opts);\n for (const item of page.data) yield item;\n if (page.data.length < limit || offset + page.data.length >= page.total) break;\n offset += page.data.length;\n }\n }\n\n /**\n * Retrieve the declared input schema for a sealed artifact.\n *\n * Returns every field the artifact's rules reference — name, type, whether it's\n * required, and a ready-to-use example_inputs object. Use this to build forms,\n * validate payloads, or generate API docs without reading the rules manually.\n *\n * Requires an API key (artifact schemas are not public).\n *\n * @example\n * const schema = await nomos.artifacts.schema('art_abc123');\n * console.log(schema.required_fields); // ['credit_score', 'loan_amount']\n * console.log(schema.example_inputs); // { credit_score: 0, loan_amount: 0 }\n */\n async schema(\n artifactId: string,\n opts?: RequestOptions,\n ): Promise<WithLastResponse<ArtifactSchema>> {\n const { data, lastResponse } = await this.http.get<ArtifactSchema>(\n `/api/v1/artifacts/${encodeURIComponent(artifactId)}/schema`,\n opts,\n );\n return { ...data, lastResponse };\n }\n}\n","import type { HttpClient } from '../http-client.js';\nimport type {\n GenerateGovernanceParams,\n GenerateGovernanceResult,\n DetectContradictionsParams,\n DetectContradictionsResult,\n RequestOptions,\n WithLastResponse,\n} from '../types.js';\n\nexport class Governance {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Generate a sealed .nomos governance artifact from policy documents\n * and optional historical decision logs.\n *\n * @example\n * const artifact = await nomos.governance.generate({\n * policies: [policyText],\n * decision_logs: historicalRows,\n * domain: 'loan_approval',\n * });\n * console.log(artifact.ari_score, artifact.seal_hash);\n */\n async generate(\n params: GenerateGovernanceParams,\n opts?: RequestOptions,\n ): Promise<WithLastResponse<GenerateGovernanceResult>> {\n const { data, lastResponse } = await this.http.post<GenerateGovernanceResult>(\n '/api/v1/generate-governance',\n params,\n opts,\n );\n return { ...data, lastResponse };\n }\n\n /**\n * Detect contradictions and conflicts in a rule set before sealing.\n *\n * @example\n * const report = await nomos.governance.detectContradictions({ rules });\n * if (!report.clean) {\n * console.log(report.contradictions);\n * }\n */\n async detectContradictions(\n params: DetectContradictionsParams,\n opts?: RequestOptions,\n ): Promise<WithLastResponse<DetectContradictionsResult>> {\n const { data, lastResponse } = await this.http.post<DetectContradictionsResult>(\n '/api/v1/detect-contradictions',\n params,\n opts,\n );\n return { ...data, lastResponse };\n }\n}\n","import { NomosWebhookSignatureError } from '../errors.js';\nimport type { NomosWebhookEvent } from '../types.js';\n\n// Hex string → Uint8Array (no Buffer dependency — works in Node and browsers)\nfunction hexToBytes(hex: string): Uint8Array {\n if (hex.length % 2 !== 0) throw new NomosWebhookSignatureError('Invalid hex encoding in signature');\n const bytes = new Uint8Array(hex.length / 2);\n for (let i = 0; i < hex.length; i += 2) {\n const byte = parseInt(hex.slice(i, i + 2), 16);\n if (isNaN(byte)) throw new NomosWebhookSignatureError('Invalid hex encoding in signature');\n bytes[i / 2] = byte;\n }\n return bytes;\n}\n\n// Constant-time comparison (prevents timing attacks)\nfunction safeEqual(a: Uint8Array, b: Uint8Array): boolean {\n if (a.length !== b.length) return false;\n let diff = 0;\n for (let i = 0; i < a.length; i++) diff |= a[i] ^ b[i];\n return diff === 0;\n}\n\nexport class Webhooks {\n /**\n * Verify a NOMOS webhook signature and return the parsed event.\n *\n * Signature header format: `t=<unix_ts>,v1=<hmac_sha256_hex>`\n * Signed payload: `<timestamp>.<raw_body>`\n *\n * @example\n * // Express\n * app.post('/webhooks/nomos', express.raw({ type: 'application/json' }), async (req, res) => {\n * const event = await nomos.webhooks.constructEvent(\n * req.body,\n * req.headers['nomos-signature'] as string,\n * process.env.NOMOS_WEBHOOK_SECRET!,\n * );\n * console.log(event.type, event.data);\n * res.sendStatus(200);\n * });\n *\n * @throws {NomosWebhookSignatureError} if signature is invalid, expired, or malformed\n */\n async constructEvent(\n payload: string | Uint8Array,\n signature: string,\n secret: string,\n toleranceSeconds = 300,\n ): Promise<NomosWebhookEvent> {\n const body = typeof payload === 'string'\n ? payload\n : new TextDecoder().decode(payload);\n\n // Parse \"t=<ts>,v1=<hex>\" header\n const parts: Record<string, string> = {};\n for (const part of signature.split(',')) {\n const eq = part.indexOf('=');\n if (eq > -1) parts[part.slice(0, eq).trim()] = part.slice(eq + 1).trim();\n }\n\n if (!parts['t'] || !parts['v1']) {\n throw new NomosWebhookSignatureError(\n 'Invalid signature format — expected \"t=<timestamp>,v1=<hmac>\"',\n );\n }\n\n const timestamp = parseInt(parts['t'], 10);\n if (isNaN(timestamp)) {\n throw new NomosWebhookSignatureError('Invalid timestamp in webhook signature');\n }\n\n const ageSecs = Math.abs(Date.now() / 1000 - timestamp);\n if (toleranceSeconds > 0 && ageSecs > toleranceSeconds) {\n throw new NomosWebhookSignatureError(\n `Webhook timestamp too old (${Math.round(ageSecs)}s > ${toleranceSeconds}s tolerance). ` +\n 'Ensure your server clock is synced and the event is not being replayed.',\n );\n }\n\n // HMAC-SHA256 via Web Crypto API (Node 18+ / modern browsers — no dependencies)\n const enc = new TextEncoder();\n const keyMaterial = await globalThis.crypto.subtle.importKey(\n 'raw',\n enc.encode(secret),\n { name: 'HMAC', hash: 'SHA-256' },\n false,\n ['sign'],\n );\n const signedPayload = `${parts['t']}.${body}`;\n const expectedBuf = await globalThis.crypto.subtle.sign(\n 'HMAC',\n keyMaterial,\n enc.encode(signedPayload),\n );\n const expected = new Uint8Array(expectedBuf);\n const received = hexToBytes(parts['v1']);\n\n if (!safeEqual(expected, received)) {\n throw new NomosWebhookSignatureError(\n 'Webhook signature mismatch — verify your NOMOS_WEBHOOK_SECRET matches the one in Studio.',\n );\n }\n\n try {\n return JSON.parse(body) as NomosWebhookEvent;\n } catch {\n throw new NomosWebhookSignatureError('Webhook payload is not valid JSON');\n }\n }\n\n /**\n * Verify a webhook signature without parsing the event.\n * Returns `true` if valid, `false` if not (never throws).\n *\n * @example\n * const valid = await nomos.webhooks.verifySignature(rawBody, sig, secret);\n * if (!valid) return res.sendStatus(400);\n */\n async verifySignature(\n payload: string | Uint8Array,\n signature: string,\n secret: string,\n toleranceSeconds = 300,\n ): Promise<boolean> {\n try {\n await this.constructEvent(payload, signature, secret, toleranceSeconds);\n return true;\n } catch {\n return false;\n }\n }\n}\n","import type { HttpClient } from '../http-client.js';\nimport type {\n ConservedStateInfo,\n ReserveParams,\n Reservation,\n ConservedStateReceipt,\n RequestOptions,\n WithLastResponse,\n} from '../types.js';\n\n/**\n * The state layer for a conserved (depleting) budget — R-12, a design in progress\n * (docs/design-notes/conserved-state-authority.md in the platform repo; public mirror:\n * computableauthority.com/research/conserved-state-authority). PROTOTYPE, not a numbered spec.\n *\n * `can()` stays exactly what it always was: pure, stateless, given facts and returning a\n * verdict. Nothing here changes that. This resource is what a caller consults BEFORE calling\n * `can()` (to build the `consumed_before` fact) and commits to AFTER `can()` returns AUTHORIZED\n * and the caller has actually decided to act — never at `can()` time itself (repeatedly calling\n * `can()` while deciding must never itself burn the budget).\n *\n * @example\n * const state = await client.conservedState.get('supplier-budget-2026', 'supplier:acme');\n * const verdict = await client.can({ artifact_id: 'supplier-budget-2026', consumed_before: state.consumed_before });\n * if (verdict.allowed) {\n * const reservation = await client.conservedState.reserve({\n * artifact_id: 'supplier-budget-2026', scope: 'supplier:acme',\n * amount: 5000, query_id: verdict.query_id!, action: 'payments.transfer',\n * });\n * try {\n * // ... perform the real action ...\n * await client.conservedState.settle(reservation.reservation_id);\n * } catch {\n * await client.conservedState.release(reservation.reservation_id);\n * }\n * }\n */\nexport class ConservedState {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Read a ledger's current balance — no auth required, same posture as `can()`'s own keyless\n * rail (reading how much budget remains is no more sensitive than reading a verdict).\n */\n async get(\n artifactId: string,\n scope: string,\n opts?: RequestOptions,\n ): Promise<WithLastResponse<ConservedStateInfo>> {\n const qs = new URLSearchParams({ artifact_id: artifactId, scope });\n const { data, lastResponse } = await this.http.get<ConservedStateInfo>(\n `/api/v1/conserved-state?${qs.toString()}`,\n opts,\n );\n return { ...data, lastResponse };\n }\n\n /**\n * Commit capacity against a REAL, AUTHORIZED `can()` decision. Authenticated — unlike `can()`,\n * spending against a shared budget requires an API key or session; `agent` on the returned\n * reservation traces to that authenticated identity, never a value you pass in.\n *\n * Throws (via the SDK's standard NomosError hierarchy; `err.details?.code` carries the\n * server's own code): `DECISION_NOT_FOUND` (the query_id names no real query), `DECISION_NOT\n * _AUTHORIZED` (that decision didn't verdict AUTHORIZED for this artifact), `DECISION_ALREADY\n * _USED` (already bound to a reservation — one decision authorizes one, ever), `STATE_CONFLICT`\n * (a stale `expected_state_digest`), `INSUFFICIENT_CAPACITY` (`err.details.requested`/\n * `.available` carry the numbers), or `NO_LEDGER` (nobody has declared this budget yet).\n *\n * Passing `{ artifact_id, scope, act }` instead authorizes the hold with a NOMOS-SPEC-008 Act.\n * Extra codes: `ACT_NOT_ACCEPTED` (the ledger has no Act binding) and `ACT_REJECTED`, with the\n * verifier's full answer in `err.details.result` — for `INCOMPLETE` it names the open rules and\n * the facts whose testimony would decide them.\n */\n async reserve(\n params: ReserveParams,\n opts?: RequestOptions,\n ): Promise<WithLastResponse<Reservation>> {\n const { data, lastResponse } = await this.http.post<Reservation>('/api/v1/reserve', params, opts);\n return { ...data, lastResponse };\n }\n\n /**\n * The reserved action succeeded — moves the hold into real, settled spend. Idempotent when\n * you pass the same `reference` again for a retry (e.g. after a network timeout): you get the\n * ORIGINAL receipt back, never a double-charge.\n */\n async settle(\n reservationId: string,\n reference?: string,\n opts?: RequestOptions,\n ): Promise<WithLastResponse<ConservedStateReceipt>> {\n const { data, lastResponse } = await this.http.post<ConservedStateReceipt>(\n '/api/v1/settle', { reservation_id: reservationId, reference }, opts,\n );\n return { ...data, lastResponse };\n }\n\n /**\n * The reserved action failed, or you decided not to act — gives the hold's capacity back\n * without ever touching what's actually been spent.\n */\n async release(\n reservationId: string,\n reference?: string,\n opts?: RequestOptions,\n ): Promise<WithLastResponse<ConservedStateReceipt>> {\n const { data, lastResponse } = await this.http.post<ConservedStateReceipt>(\n '/api/v1/release', { reservation_id: reservationId, reference }, opts,\n );\n return { ...data, lastResponse };\n }\n}\n","import type { CanParams, CanResult, CanOptions } from './types.js';\nimport type { HttpClient } from './http-client.js';\nimport {\n NomosAuthenticationError,\n NomosAuthorizationError,\n NomosRateLimitError,\n NomosValidationError,\n NomosNotFoundError,\n NomosAPIError,\n NomosNetworkError,\n NomosPaymentRequiredError,\n NomosIssuerNotTrustedError,\n} from './errors.js';\n\nconst CHAIN_PROTOCOL_VERSION = '1';\n\n/**\n * The whole product in one verb: \"Can I do this?\"\n *\n * Same pattern as Stripe's PaymentIntents API: one function, several rails underneath (a public\n * Exchange authority — free or paid — or your own authenticated artifact), and the caller never\n * has to know which one ran. Don't read `can()` as \"the Exchange's query function\" — the\n * Exchange is one of two rails behind it, not what it means.\n *\n * Both rails call into the SAME server-side implementation NOMOS itself uses (POST /api/v1/can,\n * backed by authority-query.ts's runAuthorityQuery) — not a parallel path, so there is exactly\n * one place that can drift between \"what the SDK returns\" and \"what NOMOS actually decided.\"\n *\n * Verdicts are always AUTHORIZED / DENIED / ESCALATED, normalized into that one vocabulary\n * regardless of which rail answered. `allowed` is simply `verdict === 'AUTHORIZED'`; an\n * ESCALATED result means the authority needs more facts to decide (see `missing_inputs`), not a\n * flat \"no\". A paid Exchange artifact you haven't purchased throws NomosPaymentRequiredError —\n * with the price and a purchase URL attached — rather than a generic 403 or a silent failure.\n * NOMOS never auto-charges on your behalf; this is the seam where a caller decides to buy.\n *\n * @example\n * import { nomos } from '@nomosprotocol/sdk';\n *\n * const verdict = await nomos.can({\n * authority: 'eu-ai-act.nomos',\n * ai_system_circumvents_refugee_convention: true,\n * });\n * // → { allowed: false, verdict: 'DENIED', reason: 'Rule \"Prohibition…\" triggered…',\n * // query_id: 'qry_…', url: '/queries/qry_…', … }\n */\nconst DEFAULT_EXCHANGE_BASE = 'https://www.nomosprotocol.com';\n\nfunction splitFacts(params: CanParams): { facts: Record<string, unknown>; action: string | undefined } {\n const { authority, artifact_id, action, inputs, ...flat } = params;\n void authority; void artifact_id;\n // Two equally valid shapes: an explicit `inputs` object, or the facts spread flat\n // alongside `authority`/`artifact_id`/`action`. Explicit `inputs` wins when both are present.\n const facts: Record<string, unknown> =\n inputs && typeof inputs === 'object' ? inputs : (flat as Record<string, unknown>);\n return { facts, action };\n}\n\nfunction mapHttpError(status: number, data: any, requestId: string): never {\n const message: string = data?.error ?? data?.message ?? `NOMOS query failed (HTTP ${status})`;\n // Checked by CODE, not by the raw wire status (403) — this is \"here's what unlocks it,\" a\n // materially different thing for a caller to act on than \"you're not allowed at all.\"\n if (data?.code === 'PURCHASE_REQUIRED') {\n throw new NomosPaymentRequiredError(message, data.price_usd ?? 0, data.purchase_url ?? '', requestId);\n }\n switch (status) {\n case 401: throw new NomosAuthenticationError(message, requestId);\n case 403: throw new NomosAuthorizationError(message, requestId);\n case 404: throw new NomosNotFoundError(message, requestId);\n case 422:\n case 400: throw new NomosValidationError(message, data?.details, requestId);\n case 429: throw new NomosRateLimitError(message, undefined, requestId);\n default: throw new NomosAPIError(message, status, requestId);\n }\n}\n\n/** Both Exchange-rail paths (keyless and authenticated) return the same underlying shape —\n * authority-query.ts's AuthorityQueryResult, spread with a few convenience fields by the\n * /api/v1/can route. One normalizer for both, so they can't quietly drift apart. */\nfunction normalizeAuthorityQueryResult(data: any, authority: string): CanResult {\n return {\n allowed: data.verdict === 'AUTHORIZED',\n verdict: data.verdict,\n reason: data.verdict_description,\n rule: data.matched_rule_id ?? null,\n query_id: data.query_id,\n url: data.url,\n authority: {\n id: data.artifact?.id ?? authority,\n title: data.artifact?.title ?? '',\n standing: data.artifact?.standing ?? '',\n ...(data.artifact?.attestation ? { attestation: data.artifact.attestation } : {}),\n },\n ...(data.artifact?.version ? { version: data.artifact.version } : {}),\n missing_inputs: data.missing_inputs ?? [],\n ...(typeof data.max_age === 'number' ? { max_age: data.max_age } : {}),\n // authority-query.ts already returns { kind, rule_id, rule_name } — the public-safe shape\n // CanResult uses directly.\n ...(Array.isArray(data.obligations) && data.obligations.length > 0 ? { obligations: data.obligations } : {}),\n // NOMOS-SPEC-006 — present only when the issuer has actually revoked this exact sealed\n // version; omitted (not false) when revocation doesn't structurally apply here, so \"checked\n // and clean\" and \"couldn't check\" never look the same to a caller.\n ...(data.revoked === true ? { revoked: true, revocation_reason: data.revocation_reason } : {}),\n };\n}\n\n/** Keyless — used only by the free top-level `can()` export. Free Exchange artifacts answer\n * anonymously; a paid one throws NomosPaymentRequiredError, since there's no API key here to\n * check purchase/license ownership against. */\nasync function canViaExchange(authority: string, facts: Record<string, unknown>, action: string | undefined, opts?: CanOptions): Promise<CanResult> {\n const base = (opts?.baseUrl ?? DEFAULT_EXCHANGE_BASE).replace(/\\/$/, '');\n const url = `${base}/api/v1/can`;\n\n let res: Response;\n try {\n res = await fetch(url, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ artifact: authority, action, ...facts }),\n signal: opts?.signal,\n });\n } catch (err: any) {\n if (err?.name === 'AbortError') throw new NomosNetworkError('Request aborted');\n throw new NomosNetworkError(err?.message ?? 'Network error');\n }\n\n const requestId = res.headers.get('x-request-id') ?? '';\n const data: any = await res.json().catch(() => null);\n if (!res.ok) mapHttpError(res.status, data, requestId);\n return normalizeAuthorityQueryResult(data, authority);\n}\n\n/** Authenticated — used by `client.can({ authority })`. Same endpoint, same normalization, but\n * routed through the instance's own HttpClient so its API key rides along: a paid artifact the\n * caller has purchased or published now actually works, which the keyless rail structurally\n * cannot support (there is no key there to check ownership against). */\nasync function canViaExchangeAuthenticated(http: HttpClient, authority: string, facts: Record<string, unknown>, action: string | undefined): Promise<CanResult> {\n const { data } = await http.post<any>('/api/v1/can', { artifact: authority, action, ...facts });\n return normalizeAuthorityQueryResult(data, authority);\n}\n\n/** The authenticated-artifact rail — your own artifact, requires an API key (an authenticated\n * `Nomos` instance's HttpClient). Normalizes the engine's own response shape (approved/rejected/\n * escalated, an audit hash) into the SAME AUTHORIZED/DENIED/ESCALATED verdict shape the Exchange\n * rail returns, rather than leaking a second vocabulary out to the caller. */\nasync function canViaArtifact(http: HttpClient, artifactId: string, facts: Record<string, unknown>, action: string | undefined): Promise<CanResult> {\n const isPublic = artifactId.startsWith('pub_');\n const path = isPublic ? '/api/v1/verify' : '/api/v1/verify-decision';\n const body = isPublic\n ? { artifact_id: artifactId, decision: action ?? 'evaluate', inputs: facts }\n : { artifact_id: artifactId, decision: action ?? 'evaluate', inputs: facts, caller: { correlation_id: globalThis.crypto.randomUUID() } };\n\n // Note: CanOptions.signal has no effect here — HttpClient has no external abort-signal\n // passthrough anywhere in the SDK today (its own internal AbortController is timeout-only).\n // Pre-existing limitation, not introduced by this rail; not worth faking a parameter that\n // silently does nothing.\n const { data: raw } = await http.post<any>(path, body);\n\n const verdict: CanResult['verdict'] =\n raw.verdict === 'approved' ? 'AUTHORIZED'\n : raw.verdict === 'rejected' ? 'DENIED'\n : raw.outcome === 'auto_approved' ? 'AUTHORIZED'\n : raw.outcome === 'auto_rejected' ? 'DENIED'\n : 'ESCALATED';\n\n return {\n allowed: raw.allowed ?? verdict === 'AUTHORIZED',\n verdict,\n reason: raw.verdict_description ?? '',\n rule: raw.rule?.id ?? null,\n authority: {\n id: raw.artifact_id ?? artifactId,\n title: raw.artifact_name ?? '',\n standing: raw.confidence?.tier ?? '',\n },\n ...(raw.artifact_version ? { version: raw.artifact_version } : {}),\n missing_inputs: raw.incomplete_inputs?.fields ?? [],\n ...(raw.audit ? { audit: { hash: raw.audit.hash ?? raw.audit_hash ?? '', timestamp: raw.audit.timestamp ?? raw.ts ?? new Date().toISOString() } } : {}),\n // This rail's obligations are RuleEffect objects (authority-types.ts) — a richer, INTERNAL\n // shape ({ effect_type, value, provenance: { rule_id, rule_name } }), NOT the same shape the\n // Exchange rail already returns ({ kind, rule_id, rule_name }). Mapped explicitly here rather\n // than passed through raw — the two rails' server-side representations genuinely differ, and\n // assuming they matched would have been the actual bug.\n ...(Array.isArray(raw.obligations) && raw.obligations.length > 0\n ? { obligations: raw.obligations.map((o: any) => ({\n kind: o.kind ?? o.value ?? 'obligation',\n rule_id: o.rule_id ?? o.provenance?.rule_id ?? null,\n rule_name: o.rule_name ?? o.provenance?.rule_name ?? null,\n ...(o.reason ? { reason: o.reason } : {}),\n })) }\n : {}),\n };\n}\n\n/**\n * The chain-of-trust rail (PROTOTYPE, not a numbered spec). Keyless — works identically on the\n * free `can()` export and `client.can()`, since there's no account relationship to check here.\n * The server verifies the presented chain resolves to `root_public_key_pem` and, ONLY once that\n * succeeds, evaluates the artifact's own rules against `facts` — the same evaluator every other\n * rail uses (evaluateArtifactAgainstFacts, extracted from and proven identical to\n * /api/v1/verify-decision). An artifact whose chain doesn't resolve is never evaluated: this\n * throws NomosIssuerNotTrustedError instead of returning a verdict, because \"the rules say no\"\n * and \"we never established who's asking\" are different claims a caller needs to react to\n * differently — collapsing them into DENIED would tell the caller the wrong thing to do next.\n */\nasync function canViaChain(\n artifact: unknown, keyCerts: unknown, rootPublicKeyPem: string,\n facts: Record<string, unknown>, action: string | undefined, opts?: CanOptions,\n): Promise<CanResult> {\n const base = (opts?.baseUrl ?? DEFAULT_EXCHANGE_BASE).replace(/\\/$/, '');\n const url = `${base}/api/v1/chain-of-trust/verify`;\n\n let res: Response;\n try {\n res = await fetch(url, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ version: CHAIN_PROTOCOL_VERSION, artifact, key_certs: keyCerts, root_public_key_pem: rootPublicKeyPem, facts, action }),\n signal: opts?.signal,\n });\n } catch (err: any) {\n if (err?.name === 'AbortError') throw new NomosNetworkError('Request aborted');\n throw new NomosNetworkError(err?.message ?? 'Network error');\n }\n\n const requestId = res.headers.get('x-request-id') ?? '';\n const data: any = await res.json().catch(() => null);\n\n if (data?.decision === 'AUTHORIZED' || data?.decision === 'DENIED' || data?.decision === 'ESCALATED') {\n return {\n allowed: data.decision === 'AUTHORIZED',\n verdict: data.decision,\n reason: data.reason ?? '',\n rule: data.rule ?? null,\n authority: { id: 'presented-artifact', title: '', standing: '' },\n // Read directly off the artifact the caller already has — no server round-trip needed for\n // data the caller is already holding.\n ...((artifact as any)?.meta?.version ? { version: (artifact as any).meta.version } : {}),\n missing_inputs: data.missing_inputs ?? [],\n ...(Array.isArray(data.obligations) && data.obligations.length > 0 ? { obligations: data.obligations } : {}),\n // §5.5 — composing to a real permission decision must not silently drop the chain's own\n // revocation-confidence disclosure; the server already threads this through, so forward it.\n ...(data.revocation_checked ? { revocation_checked: data.revocation_checked } : {}),\n // Deliberately no query_id/url/audit — this evaluation is stateless by design (the whole\n // point is answering without NOMOS needing to have seen this artifact before); there is no\n // permanent transcript to point to, and faking one would misrepresent what just happened.\n };\n }\n\n // ALLOWED (facts were somehow not evaluated — shouldn't happen when facts are always sent, but\n // handled rather than assumed impossible), or one of the chain-failure decisions.\n const message: string = data?.detail ?? `Chain verification failed (HTTP ${res.status})`;\n if (data?.decision === 'ISSUER_NOT_RECOGNIZED' || data?.decision === 'KEY_REVOKED' || data?.decision === 'CERTIFICATE_REVOKED' || data?.decision === 'OUT_OF_SCOPE' || data?.decision === 'SEAL_INVALID' || data?.decision === 'ALLOWED') {\n throw new NomosIssuerNotTrustedError(message, data.decision, requestId);\n }\n if (data?.decision === 'MALFORMED') throw new NomosValidationError(message, data, requestId);\n mapHttpError(res.status, data, requestId);\n}\n\nexport async function can(params: CanParams, opts?: CanOptions): Promise<CanResult> {\n if (params.artifact !== undefined) {\n if (!params.key_certs || !params.root_public_key_pem) {\n throw new Error('can(): `artifact` requires `key_certs` and `root_public_key_pem` alongside it.');\n }\n const { facts, action } = splitFacts(params);\n return canViaChain(params.artifact, params.key_certs, params.root_public_key_pem, facts, action, opts);\n }\n if (params.artifact_id) {\n throw new Error('can(): `artifact_id` requires an API key — use `client.can(...)` on an authenticated Nomos instance, not the free `can()` export.');\n }\n if (!params.authority || typeof params.authority !== 'string') {\n throw new Error('can(): `authority` (an Exchange artifact id or slug), `artifact_id` (via client.can()), or `artifact` (chain-of-trust) is required.');\n }\n const { facts, action } = splitFacts(params);\n return canViaExchange(params.authority, facts, action, opts);\n}\n\n/** Shared implementation behind `Nomos.prototype.can()` — see nomos.ts. Exported so the class\n * stays a thin wrapper and this routing logic lives in exactly one place. */\nexport async function canAuthenticated(http: HttpClient, params: CanParams, opts?: CanOptions): Promise<CanResult> {\n void opts; // reserved — HttpClient has no external signal passthrough today, see canViaArtifact's note\n const { facts, action } = splitFacts(params);\n if (params.artifact !== undefined) {\n if (!params.key_certs || !params.root_public_key_pem) {\n throw new Error('can(): `artifact` requires `key_certs` and `root_public_key_pem` alongside it.');\n }\n // Keyless rail — an authenticated client is still free to use it, same server endpoint.\n return canViaChain(params.artifact, params.key_certs, params.root_public_key_pem, facts, action, opts);\n }\n if (params.artifact_id) return canViaArtifact(http, params.artifact_id, facts, action);\n if (params.authority) return canViaExchangeAuthenticated(http, params.authority, facts, action);\n throw new Error('can(): `authority` (a public Exchange artifact), `artifact_id` (your own artifact), or `artifact` (chain-of-trust) is required.');\n}\n\n/**\n * Ready-to-use, keyless entry point matching the canonical `nomos.can(...)` form.\n * For paid artifacts or your own artifacts, use `client.can(...)` on an authenticated `Nomos`\n * instance instead — same function name, same verdict shape, the only difference is which rail\n * answers and what it can unlock.\n */\nexport const nomos = { can };\n","import { HttpClient } from './http-client.js';\nimport { Decisions } from './resources/decisions.js';\nimport { Artifacts } from './resources/artifacts.js';\nimport { Governance } from './resources/governance.js';\nimport { Webhooks } from './resources/webhooks.js';\nimport { ConservedState } from './resources/conserved-state.js';\nimport { canAuthenticated } from './can.js';\nimport * as errors from './errors.js';\nimport type { NomosConfig, CanParams, CanOptions, CanResult } from './types.js';\n\nconst DEFAULT_BASE_URL = 'https://nomos.ai';\nconst DEFAULT_MAX_RETRIES = 3;\nconst DEFAULT_TIMEOUT = 30_000;\n\nexport class Nomos {\n readonly decisions: Decisions;\n readonly artifacts: Artifacts;\n readonly governance: Governance;\n readonly webhooks: Webhooks;\n /** The R-12 conserved-state (depleting-budget) state layer — PROTOTYPE, not a numbered spec.\n * See resources/conserved-state.ts for the full reserve/settle/release lifecycle. */\n readonly conservedState: ConservedState;\n\n /** Whether this instance is using a live or test API key. */\n readonly mode: 'live' | 'test';\n\n static readonly errors = errors;\n\n private readonly http: HttpClient;\n\n constructor(apiKey: string, config: NomosConfig = {}) {\n if (!apiKey || typeof apiKey !== 'string') {\n throw new errors.NomosAuthenticationError(\n 'A valid API key is required. Pass it as the first argument: new Nomos(\"nms_live_...\")',\n );\n }\n\n this.mode = apiKey.startsWith('nms_test_') ? 'test' : 'live';\n\n this.http = new HttpClient({\n apiKey,\n baseUrl: (config.baseUrl ?? DEFAULT_BASE_URL).replace(/\\/$/, ''),\n maxRetries: config.maxRetries ?? DEFAULT_MAX_RETRIES,\n timeout: config.timeout ?? DEFAULT_TIMEOUT,\n });\n\n this.decisions = new Decisions(this.http);\n this.artifacts = new Artifacts(this.http);\n this.governance = new Governance(this.http);\n this.webhooks = new Webhooks();\n this.conservedState = new ConservedState(this.http);\n }\n\n /**\n * \"Can I do this?\" — the one verb, now covering your own artifacts too. Pass `authority` for a\n * public Exchange artifact, or `artifact_id` for your own (Studio or the Exchange) — same\n * return shape either way, so calling code never needs to know which rail answered.\n *\n * @example\n * const client = new Nomos('nms_live_...');\n * const verdict = await client.can({ artifact_id: 'loan_approval_v1', credit_score: 720 });\n */\n async can(params: CanParams, opts?: CanOptions): Promise<CanResult> {\n return canAuthenticated(this.http, params, opts);\n }\n}\n","import type { VerifyChainParams, VerifyChainOptions, VerifyChainResult } from './types.js';\nimport {\n NomosValidationError,\n NomosRateLimitError,\n NomosAPIError,\n NomosNetworkError,\n} from './errors.js';\n\nconst CHAIN_PROTOCOL_VERSION = '1';\nconst DEFAULT_BASE = 'https://www.nomosprotocol.com';\n\n/**\n * Chain-of-trust verification (PROTOTYPE — not a numbered spec). Checks whether a presented\n * artifact's signing key resolves, through the presented key certificates, back to a root you\n * have independently decided to trust — entirely server-side against nomos-chain.ts's pure\n * verifier, with no account or API key required (keyless, matching `nomos.can()`'s precedent).\n *\n * There is no default root anywhere in this call — `root_public_key_pem` is required. That's\n * deliberate: it keeps the trust decision with the caller, not with this SDK or the platform.\n *\n * @example\n * import { verifyChain } from '@nomosprotocol/sdk';\n *\n * const result = await verifyChain({\n * artifact: sealedArtifact,\n * key_certs: [rootToIntermediate, intermediateToLeaf],\n * root_public_key_pem: myPinnedRootPem,\n * });\n * if (result.decision === 'ALLOWED') { ... }\n */\nexport async function verifyChain(params: VerifyChainParams, opts?: VerifyChainOptions): Promise<VerifyChainResult> {\n if (!params.root_public_key_pem) {\n throw new Error('verifyChain(): `root_public_key_pem` is required — there is no default root.');\n }\n const base = (opts?.baseUrl ?? DEFAULT_BASE).replace(/\\/$/, '');\n const url = `${base}/api/v1/chain-of-trust/verify`;\n\n let res: Response;\n try {\n res = await fetch(url, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n version: CHAIN_PROTOCOL_VERSION,\n artifact: params.artifact,\n key_certs: params.key_certs,\n root_public_key_pem: params.root_public_key_pem,\n }),\n signal: opts?.signal,\n });\n } catch (err: any) {\n if (err?.name === 'AbortError') throw new NomosNetworkError('Request aborted');\n throw new NomosNetworkError(err?.message ?? 'Network error');\n }\n\n const requestId = res.headers.get('x-request-id') ?? '';\n const data: any = await res.json().catch(() => null);\n\n // 400/403/422 all carry a real ChainVerdict body (MALFORMED/ISSUER_NOT_RECOGNIZED/KEY_REVOKED/\n // SEAL_INVALID) — that's a verdict, not a transport failure, so it's returned, not thrown.\n if (data && typeof data.decision === 'string') {\n return data as VerifyChainResult;\n }\n\n const message: string = data?.error ?? `Chain verification request failed (HTTP ${res.status})`;\n if (res.status === 429) {\n throw new NomosRateLimitError(message, res.headers.get('retry-after') ? parseInt(res.headers.get('retry-after')!, 10) : undefined, requestId);\n }\n if (res.status === 400) throw new NomosValidationError(message, data?.details, requestId);\n throw new NomosAPIError(message, res.status, requestId);\n}\n"],"mappings":";;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAYO,IAAM,aAAN,cAAyB,MAAM;AAAA,EAYpC,YAAY,SAAiB,MAAsB,QAAiB,WAAoB,SAAmB;AACzG,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,YAAY;AACjB,SAAK,UAAU;AAAA,EACjB;AACF;AAEO,IAAM,2BAAN,cAAuC,WAAW;AAAA,EACvD,YAAY,UAAU,mBAAmB,WAAoB,SAAmB;AAC9E,UAAM,SAAS,wBAAwB,KAAK,WAAW,OAAO;AAC9D,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,0BAAN,cAAsC,WAAW;AAAA,EACtD,YAAY,UAAU,iBAAiB,WAAoB,SAAmB;AAC5E,UAAM,SAAS,uBAAuB,KAAK,WAAW,OAAO;AAC7D,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,sBAAN,cAAkC,WAAW;AAAA,EAGlD,YAAY,UAAU,uBAAuB,YAAqB,WAAoB,SAAmB;AACvG,UAAM,SAAS,oBAAoB,KAAK,WAAW,OAAO;AAC1D,SAAK,OAAO;AACZ,SAAK,aAAa;AAAA,EACpB;AACF;AAKO,IAAM,uBAAN,cAAmC,WAAW;AAAA,EACnD,YAAY,SAAiB,SAAmB,WAAoB;AAClE,UAAM,SAAS,oBAAoB,KAAK,WAAW,OAAO;AAC1D,SAAK,OAAO;AAAA,EACd;AACF;AAEO,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nB,SAASA;AAAA,QACT,UAAU,OAAO;AAAA,QACjB,WAAW,OAAO;AAAA,QAClB,qBAAqB,OAAO;AAAA,MAC9B,CAAC;AAAA,MACD,QAAQ,MAAM;AAAA,IAChB,CAAC;AAAA,EACH,SAAS,KAAU;AACjB,QAAI,KAAK,SAAS,aAAc,OAAM,IAAI,kBAAkB,iBAAiB;AAC7E,UAAM,IAAI,kBAAkB,KAAK,WAAW,eAAe;AAAA,EAC7D;AAEA,QAAM,YAAY,IAAI,QAAQ,IAAI,cAAc,KAAK;AACrD,QAAM,OAAY,MAAM,IAAI,KAAK,EAAE,MAAM,MAAM,IAAI;AAInD,MAAI,QAAQ,OAAO,KAAK,aAAa,UAAU;AAC7C,WAAO;AAAA,EACT;AAEA,QAAM,UAAkB,MAAM,SAAS,2CAA2C,IAAI,MAAM;AAC5F,MAAI,IAAI,WAAW,KAAK;AACtB,UAAM,IAAI,oBAAoB,SAAS,IAAI,QAAQ,IAAI,aAAa,IAAI,SAAS,IAAI,QAAQ,IAAI,aAAa,GAAI,EAAE,IAAI,QAAW,SAAS;AAAA,EAC9I;AACA,MAAI,IAAI,WAAW,IAAK,OAAM,IAAI,qBAAqB,SAAS,MAAM,SAAS,SAAS;AACxF,QAAM,IAAI,cAAc,SAAS,IAAI,QAAQ,SAAS;AACxD;","names":["facts","action","CHAIN_PROTOCOL_VERSION"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nomosprotocol/sdk",
3
- "version": "1.3.3",
3
+ "version": "1.4.0",
4
4
  "description": "Official TypeScript SDK for the NOMOS governance runtime",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -31,8 +31,13 @@
31
31
  "type-check": "tsc --noEmit"
32
32
  },
33
33
  "tsup": {
34
- "entry": ["src/index.ts"],
35
- "format": ["esm", "cjs"],
34
+ "entry": [
35
+ "src/index.ts"
36
+ ],
37
+ "format": [
38
+ "esm",
39
+ "cjs"
40
+ ],
36
41
  "dts": true,
37
42
  "clean": true,
38
43
  "target": "node18",