@nomosprotocol/sdk 2.0.0 → 2.3.1
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/README.md +28 -8
- package/dist/index.cjs +1234 -113
- package/dist/index.d.cts +431 -11
- package/dist/index.d.ts +431 -11
- package/dist/index.js +1210 -112
- package/package.json +4 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CurrencyPolicy, ActVerdict } from '@nomosprotocol/verify';
|
|
1
|
+
import { CurrencyPolicy, ActVerdict, KeyCertificate as KeyCertificate$2, RevocationStatement, RevocationList, ScopeTerms } from '@nomosprotocol/verify';
|
|
2
2
|
export { bindingDigest, verifyAct, verifyArtifact, verifySeal } from '@nomosprotocol/verify';
|
|
3
3
|
|
|
4
4
|
interface VerifyDecisionParams {
|
|
@@ -395,7 +395,7 @@ interface GenerateGovernanceResult {
|
|
|
395
395
|
download_url?: string;
|
|
396
396
|
}
|
|
397
397
|
interface NomosConfig {
|
|
398
|
-
/** Base URL override — defaults to https://
|
|
398
|
+
/** Base URL override — defaults to https://www.nomosprotocol.com */
|
|
399
399
|
baseUrl?: string;
|
|
400
400
|
/** Max retries on 429 / 5xx (default: 3) */
|
|
401
401
|
maxRetries?: number;
|
|
@@ -776,7 +776,7 @@ declare class Nomos {
|
|
|
776
776
|
* return shape either way, so calling code never needs to know which rail answered.
|
|
777
777
|
*
|
|
778
778
|
* @example
|
|
779
|
-
* const client = new Nomos('
|
|
779
|
+
* const client = new Nomos('nmk_...');
|
|
780
780
|
* const verdict = await client.can({ artifact_id: 'loan_approval_v1', credit_score: 720 });
|
|
781
781
|
*/
|
|
782
782
|
can(params: CanParams, opts?: CanOptions): Promise<CanResult>;
|
|
@@ -807,6 +807,86 @@ declare const nomos: {
|
|
|
807
807
|
*/
|
|
808
808
|
declare function verifyChain(params: VerifyChainParams, opts?: VerifyChainOptions): Promise<VerifyChainResult>;
|
|
809
809
|
|
|
810
|
+
/**
|
|
811
|
+
* Tool bindings: which of a tool's arguments is which fact a sealed policy reads. A policy reads
|
|
812
|
+
* `loan_amount`; a tool sends `amount_cents`. Without a binding the policy has nothing to decide on,
|
|
813
|
+
* and a fail-closed check holds every call.
|
|
814
|
+
*
|
|
815
|
+
* A binding decides what a policy sees, so it is built to be safe:
|
|
816
|
+
* - It is an explicit, reviewed file. Suggestions are proposals, marked unreviewed.
|
|
817
|
+
* - A fact only ever comes from an argument of the call. There are no constants, so nobody can
|
|
818
|
+
* hard-code a fact to quiet a policy.
|
|
819
|
+
* - With a binding, only bound facts reach the policy, so an agent can't state a fact the tool
|
|
820
|
+
* wouldn't act on by adding an argument of that name.
|
|
821
|
+
* - A missing argument or an unmapped value leaves the fact undecided. It is never guessed.
|
|
822
|
+
*
|
|
823
|
+
* Pure: no I/O, no model. Specified in NOMOS-SPEC-011 (Draft), nomos-spec/spec; see also
|
|
824
|
+
* docs/design-notes/tool-fact-binding.md.
|
|
825
|
+
*/
|
|
826
|
+
interface FactBinding {
|
|
827
|
+
/** The argument this fact comes from. Dots reach into objects: `customer.kyc`. */
|
|
828
|
+
arg: string;
|
|
829
|
+
/** Multiply a number: `amount_cents` into dollars is 0.01. */
|
|
830
|
+
scale?: number;
|
|
831
|
+
/** Translate a value: { "ok": "verified" }. A value not listed leaves the fact undecided. */
|
|
832
|
+
map?: Record<string, string | number | boolean>;
|
|
833
|
+
}
|
|
834
|
+
interface ToolBindings {
|
|
835
|
+
version: 1;
|
|
836
|
+
/** The sealed policy these facts belong to. */
|
|
837
|
+
artifact: string;
|
|
838
|
+
/** False until a person has checked it. The guard won't enforce an unreviewed file. */
|
|
839
|
+
reviewed: boolean;
|
|
840
|
+
tools: Record<string, {
|
|
841
|
+
facts: Record<string, FactBinding>;
|
|
842
|
+
}>;
|
|
843
|
+
}
|
|
844
|
+
/** Reads a bindings file, refusing anything it doesn't fully understand. Throws with a plain reason. */
|
|
845
|
+
declare function parseToolBindings(raw: unknown): ToolBindings;
|
|
846
|
+
interface UnresolvedFact {
|
|
847
|
+
fact: string;
|
|
848
|
+
arg: string;
|
|
849
|
+
why: 'missing' | 'not_a_number' | 'not_a_value' | 'not_in_map';
|
|
850
|
+
}
|
|
851
|
+
/** The facts a policy gets for this call, and which it couldn't get. */
|
|
852
|
+
declare function applyToolBindings(bindings: ToolBindings, tool: string, args: Record<string, unknown>): {
|
|
853
|
+
inputs: Record<string, string | number | boolean>;
|
|
854
|
+
unresolved: UnresolvedFact[];
|
|
855
|
+
};
|
|
856
|
+
interface ToolDescription {
|
|
857
|
+
name: string;
|
|
858
|
+
inputSchema?: {
|
|
859
|
+
properties?: Record<string, any>;
|
|
860
|
+
} | null;
|
|
861
|
+
}
|
|
862
|
+
interface PolicyField {
|
|
863
|
+
name: string;
|
|
864
|
+
type?: string;
|
|
865
|
+
description?: string | null;
|
|
866
|
+
values?: string[];
|
|
867
|
+
}
|
|
868
|
+
interface BindingProposal {
|
|
869
|
+
tool: string;
|
|
870
|
+
fact: string;
|
|
871
|
+
arg: string;
|
|
872
|
+
confidence: 'exact' | 'likely';
|
|
873
|
+
why: string;
|
|
874
|
+
scale?: number;
|
|
875
|
+
}
|
|
876
|
+
interface BindingSuggestion {
|
|
877
|
+
bindings: ToolBindings;
|
|
878
|
+
proposals: BindingProposal[];
|
|
879
|
+
unbound: Array<{
|
|
880
|
+
tool: string;
|
|
881
|
+
fact: string;
|
|
882
|
+
candidates: string[];
|
|
883
|
+
}>;
|
|
884
|
+
}
|
|
885
|
+
/** Proposes bindings from names alone, for a person to check. Never guesses a value translation. */
|
|
886
|
+
declare function suggestToolBindings(artifact: string, tools: ToolDescription[], fields: PolicyField[]): BindingSuggestion;
|
|
887
|
+
/** A plain report of a suggestion, for the person who has to check it. */
|
|
888
|
+
declare function describeSuggestion(s: BindingSuggestion): string;
|
|
889
|
+
|
|
810
890
|
type SignatureSuite = 'Ed25519' | 'ES256';
|
|
811
891
|
interface Signer {
|
|
812
892
|
/** NOMOS-SPEC-001 §8.4 key id of the public key. */
|
|
@@ -818,9 +898,11 @@ interface Signer {
|
|
|
818
898
|
/** Signs the exact payload bytes. Returns the signature in the suite's encoding, base64. */
|
|
819
899
|
sign(payload: Uint8Array): Promise<string>;
|
|
820
900
|
}
|
|
901
|
+
/** The key id of a canonical Ed25519 or P-256 public key (NOMOS-SPEC-010 §3.1–§3.2). Throws for
|
|
902
|
+
* any other key: a non-canonical key has no key id, because no verifier would accept it. */
|
|
821
903
|
declare function kidOf(publicKeyPem: string): string;
|
|
822
|
-
/** A signer over a private key held in this process: PKCS#8 PEM
|
|
823
|
-
* in production pass a Signer backed by your KMS or HSM. */
|
|
904
|
+
/** A signer over a private key held in this process: PKCS#8 PEM (or SEC1 for P-256). For
|
|
905
|
+
* development and tests; in production pass a Signer backed by your KMS or HSM. */
|
|
824
906
|
declare function localSigner(privateKeyPem: string): Signer;
|
|
825
907
|
/** A fresh in-memory key. For development and tests only. */
|
|
826
908
|
declare function generateSigner(algorithm?: SignatureSuite): Signer & {
|
|
@@ -1008,7 +1090,9 @@ interface Receipt {
|
|
|
1008
1090
|
interface AcceptTransaction<Tx = unknown> {
|
|
1009
1091
|
/** Records the nonce. false if it was already recorded (a concurrent duplicate). */
|
|
1010
1092
|
claimNonce(nonce: string): Promise<boolean>;
|
|
1011
|
-
|
|
1093
|
+
/** Stores the receipt, and the exact Act it verified (SPEC-008 §9: the receipt plus a retained
|
|
1094
|
+
* copy of the Act let a third party re-run the verification). */
|
|
1095
|
+
putReceipt(nonce: string, receipt: Receipt, act?: unknown): Promise<void>;
|
|
1012
1096
|
tx: Tx;
|
|
1013
1097
|
}
|
|
1014
1098
|
interface AcceptStore<Tx = unknown> {
|
|
@@ -1042,7 +1126,10 @@ interface AcceptOptions<Tx = unknown> {
|
|
|
1042
1126
|
/** SPEC-008 §5.1 / SPEC-009 §6.3. Long enough for a person to approve. Default 900. */
|
|
1043
1127
|
maxWindowSeconds?: number;
|
|
1044
1128
|
maxActBytes?: number;
|
|
1045
|
-
/** Current revocation state (SPEC-006, SPEC-007 §5)
|
|
1129
|
+
/** Current revocation state (SPEC-006, SPEC-007 §5), read once per Act. Use revocationSource()
|
|
1130
|
+
* for an issuer's published list. If it throws, the Act is refused with 503 and nothing is
|
|
1131
|
+
* committed: revocations that cannot be checked are never treated as "nothing revoked"
|
|
1132
|
+
* (SPEC-007 rev. 1.10 §5.6). */
|
|
1046
1133
|
revocations?: () => Promise<{
|
|
1047
1134
|
kids?: Set<string>;
|
|
1048
1135
|
certs?: Set<string>;
|
|
@@ -1068,7 +1155,7 @@ interface Answer {
|
|
|
1068
1155
|
declare const statusFor: (decision: string) => number;
|
|
1069
1156
|
declare const ACT_MEDIA_TYPE = "application/nomos-act+json";
|
|
1070
1157
|
/** Nonces and receipts in memory, one transaction at a time. Lost on restart, single process:
|
|
1071
|
-
* for development and tests only.
|
|
1158
|
+
* for development and tests only. In production use postgresStore() or your own AcceptStore. */
|
|
1072
1159
|
declare function memoryStore(): AcceptStore<null>;
|
|
1073
1160
|
declare function accept<Tx = unknown>(o: AcceptOptions<Tx>): {
|
|
1074
1161
|
handle: (req: {
|
|
@@ -1082,6 +1169,327 @@ declare function accept<Tx = unknown>(o: AcceptOptions<Tx>): {
|
|
|
1082
1169
|
node: () => (req: any, res: any, next?: () => void) => Promise<void>;
|
|
1083
1170
|
};
|
|
1084
1171
|
|
|
1172
|
+
/**
|
|
1173
|
+
* postgresStore() — the production store for accept(): nonces, receipts and the Acts themselves,
|
|
1174
|
+
* in your own Postgres, in the same transaction as your own change.
|
|
1175
|
+
*
|
|
1176
|
+
* import pg from 'pg';
|
|
1177
|
+
* const pool = new pg.Pool({ connectionString: process.env.DATABASE_URL });
|
|
1178
|
+
* const store = postgresStore(pool);
|
|
1179
|
+
* await store.migrate(); // once; or apply store.schema yourself
|
|
1180
|
+
* accept({ ..., store, commit: async (action, { tx }) => tx.query('INSERT INTO orders …', […]) });
|
|
1181
|
+
*
|
|
1182
|
+
* What it guarantees (NOMOS-SPEC-008 §8, NOMOS-SPEC-009 §6.3–§6.4):
|
|
1183
|
+
* - One transaction. `commit` receives `tx`, the very client the nonce is recorded on, so your
|
|
1184
|
+
* change, the nonce and the receipt commit together or not at all.
|
|
1185
|
+
* - One commit per Act, under any concurrency. The nonce is the table's primary key; a second
|
|
1186
|
+
* submission of the same Act waits for the first transaction and then finds the nonce taken,
|
|
1187
|
+
* so it is answered REPLAYED with the first receipt. If the first rolled back, the second
|
|
1188
|
+
* commits instead: a nonce is recorded only when the change is.
|
|
1189
|
+
* - An audit trail. Each row keeps the receipt and the exact Act it verified, so a third party
|
|
1190
|
+
* can re-run SPEC-008 §6 later (SPEC-008 §9). Rows are never deleted by this store: how long
|
|
1191
|
+
* to retain them is your policy. They must outlive the Acts' validity windows at least, or a
|
|
1192
|
+
* replayed Act could commit twice.
|
|
1193
|
+
*
|
|
1194
|
+
* It depends on no driver: pass a `pg` Pool (node-postgres) or anything with the same two
|
|
1195
|
+
* methods, for example a pool adapter over postgres.js, Neon's serverless driver or PGlite.
|
|
1196
|
+
*/
|
|
1197
|
+
|
|
1198
|
+
/** The part of a node-postgres client this store uses. */
|
|
1199
|
+
interface PgClient {
|
|
1200
|
+
query(text: string, values?: unknown[]): Promise<{
|
|
1201
|
+
rows: any[];
|
|
1202
|
+
rowCount: number | null;
|
|
1203
|
+
}>;
|
|
1204
|
+
}
|
|
1205
|
+
/** The part of a node-postgres Pool this store uses. */
|
|
1206
|
+
interface PgPool extends PgClient {
|
|
1207
|
+
connect(): Promise<PgClient & {
|
|
1208
|
+
release(err?: unknown): void;
|
|
1209
|
+
}>;
|
|
1210
|
+
}
|
|
1211
|
+
interface PostgresStoreOptions {
|
|
1212
|
+
/** Table name, optionally schema-qualified. Default `nomos_acts`. */
|
|
1213
|
+
table?: string;
|
|
1214
|
+
}
|
|
1215
|
+
declare function postgresStore(pool: PgPool, opts?: PostgresStoreOptions): AcceptStore<PgClient> & {
|
|
1216
|
+
schema: string;
|
|
1217
|
+
migrate(): Promise<void>;
|
|
1218
|
+
};
|
|
1219
|
+
|
|
1220
|
+
/**
|
|
1221
|
+
* Certificates and revocations, as the carrier and the relying party need them.
|
|
1222
|
+
*
|
|
1223
|
+
* presentedCertificates(available, act) NOMOS-SPEC-009 0.2.0 §6.5: exactly the certificates an Act presents
|
|
1224
|
+
* signRevocation(parent, target, reason) NOMOS-SPEC-007 rev. 1.10 §5.1: revoke a key or one certificate
|
|
1225
|
+
* signRevocationList(signer, …) rev. 1.10 §5.3: a list a relying party can check for itself
|
|
1226
|
+
* revocationSource({ url, root, … }) rev. 1.10 §5.3a, §5.6: current revocations for accept(), fail closed when stale
|
|
1227
|
+
*/
|
|
1228
|
+
|
|
1229
|
+
declare const MAX_PRESENTED = 20;
|
|
1230
|
+
/** The kids an Act relies on: its seal's key, every witness's and every approver's. */
|
|
1231
|
+
declare function reliedKids(act: any): string[];
|
|
1232
|
+
/** NOMOS-SPEC-009 0.2.0 §6.5: the closure of `available` over the kids `act` relies on, each
|
|
1233
|
+
* certificate once. Deterministic, so two carriers with the same certificates present the same set. */
|
|
1234
|
+
declare function presentedCertificates(available: KeyCertificate$2[], act: any): KeyCertificate$2[];
|
|
1235
|
+
/** NOMOS-SPEC-007 rev. 1.10 §5.1: `parent` revokes a key it certified, or one certificate it issued. */
|
|
1236
|
+
declare function signRevocation(parent: Signer, target: {
|
|
1237
|
+
kid: string;
|
|
1238
|
+
} | {
|
|
1239
|
+
certificate: KeyCertificate$2;
|
|
1240
|
+
}, reason: string, issuedAt?: Date): Promise<RevocationStatement>;
|
|
1241
|
+
/** NOMOS-SPEC-007 rev. 1.10 §5.3: a signed, dated list. `keyCerts` should be the closure over
|
|
1242
|
+
* the signers and what they revoke (and the list signer), so any relying party can check it. */
|
|
1243
|
+
declare function signRevocationList(signer: Signer, statements: RevocationStatement[], keyCerts?: KeyCertificate$2[], generatedAt?: Date): Promise<RevocationList>;
|
|
1244
|
+
/** The certificates a revocation list should carry (rev. 1.10 §5.3): the closure over every
|
|
1245
|
+
* statement's signer and target, and the list's own signer, within the publisher's certificates. */
|
|
1246
|
+
declare function revocationListCertificates(available: KeyCertificate$2[], statements: RevocationStatement[], listSignerKid: string): KeyCertificate$2[];
|
|
1247
|
+
declare class RevocationUnavailable extends Error {
|
|
1248
|
+
readonly retryAfterSeconds: number;
|
|
1249
|
+
constructor(message: string, retryAfterSeconds: number);
|
|
1250
|
+
}
|
|
1251
|
+
interface RevocationSourceOptions {
|
|
1252
|
+
/** The issuer's revocation list (its NOMOS-SPEC-009 `revocations_url`). */
|
|
1253
|
+
url: string;
|
|
1254
|
+
/** The root you pin: statements count only from parents it reaches; the list's date only from a signer it reaches. */
|
|
1255
|
+
root: string;
|
|
1256
|
+
/** How old the newest current list may be before accept() refuses to commit (rev. 1.10 §5.6). Policy, not protocol. Default 3600. */
|
|
1257
|
+
maxAgeSeconds?: number;
|
|
1258
|
+
/** Your own certificates, for statements whose certificates the list does not carry. */
|
|
1259
|
+
ownCerts?: KeyCertificate$2[];
|
|
1260
|
+
/** How long to reuse a fetched list before fetching again. Default 60 s, as the reference deployment publishes. */
|
|
1261
|
+
refreshSeconds?: number;
|
|
1262
|
+
fetch?: typeof fetch;
|
|
1263
|
+
now?: () => Date;
|
|
1264
|
+
}
|
|
1265
|
+
/**
|
|
1266
|
+
* Current revocations from an issuer's list, for accept({ revocations }).
|
|
1267
|
+
*
|
|
1268
|
+
* Every counted statement is kept for good: a later fetch that fails, or a list that omits it,
|
|
1269
|
+
* never un-revokes a key (rev. 1.10 §5.6). When the newest list with an established `as_of` is
|
|
1270
|
+
* older than `maxAgeSeconds`, it throws RevocationUnavailable, and accept() refuses to commit
|
|
1271
|
+
* with 503 and Retry-After rather than acting as if nothing were revoked.
|
|
1272
|
+
*/
|
|
1273
|
+
declare function revocationSource(o: RevocationSourceOptions): () => Promise<{
|
|
1274
|
+
kids: Set<string>;
|
|
1275
|
+
certs: Set<string>;
|
|
1276
|
+
}>;
|
|
1277
|
+
|
|
1278
|
+
/**
|
|
1279
|
+
* certificateRegistry() — an institution's certificates and revocations, managed rather than
|
|
1280
|
+
* minted in code.
|
|
1281
|
+
*
|
|
1282
|
+
* const registry = certificateRegistry({ root: ROOT_PUBLIC_PEM, store: postgresRegistryStore(pool) });
|
|
1283
|
+
* await registry.issue({ parent: rootSigner, child: finance, scope: 'claim:budget_remaining', days: 365 });
|
|
1284
|
+
* await registry.revokeKey({ parent: rootSigner, kid: lostPhone.kid, reason: 'Phone lost' });
|
|
1285
|
+
* issuer({ …, keyCerts: () => registry.pool(), revocations: () => registry.revocationList(listSigner) });
|
|
1286
|
+
* witness({ …, keyCerts: await registry.chainFor(finance.kid) });
|
|
1287
|
+
*
|
|
1288
|
+
* Everything it writes is exactly NOMOS-SPEC-007: certificates (§3), revocation statements and
|
|
1289
|
+
* lists (rev. 1.10 §5). It refuses, at issue time, what a relying party would refuse later: a
|
|
1290
|
+
* parent the root does not reach, a scope wider than the parent's, a suite the parent may not
|
|
1291
|
+
* sign under, a malformed scope. Nothing it publishes is trusted because the registry published
|
|
1292
|
+
* it: every relying party checks it again.
|
|
1293
|
+
*/
|
|
1294
|
+
|
|
1295
|
+
/** Where a registry keeps its certificates and revocation statements. Append-only. */
|
|
1296
|
+
interface RegistryStore {
|
|
1297
|
+
certificates(): Promise<KeyCertificate$2[]>;
|
|
1298
|
+
addCertificate(c: KeyCertificate$2): Promise<void>;
|
|
1299
|
+
statements(): Promise<RevocationStatement[]>;
|
|
1300
|
+
addStatement(s: RevocationStatement): Promise<void>;
|
|
1301
|
+
}
|
|
1302
|
+
/** In memory, for tests and development. */
|
|
1303
|
+
declare function memoryRegistryStore(): RegistryStore;
|
|
1304
|
+
declare class RegistryError extends Error {
|
|
1305
|
+
readonly code: string;
|
|
1306
|
+
constructor(message: string, code: string);
|
|
1307
|
+
}
|
|
1308
|
+
interface IssueOptions {
|
|
1309
|
+
parent: Signer;
|
|
1310
|
+
child: {
|
|
1311
|
+
kid: string;
|
|
1312
|
+
publicKeyPem: string;
|
|
1313
|
+
};
|
|
1314
|
+
scope?: string;
|
|
1315
|
+
/** Validity: `expiresAt`, or `days` from now. */
|
|
1316
|
+
expiresAt?: Date;
|
|
1317
|
+
days?: number;
|
|
1318
|
+
issuedAt?: Date;
|
|
1319
|
+
}
|
|
1320
|
+
declare function certificateRegistry(o: {
|
|
1321
|
+
root: string;
|
|
1322
|
+
store: RegistryStore;
|
|
1323
|
+
now?: () => Date;
|
|
1324
|
+
}): {
|
|
1325
|
+
rootKid: string;
|
|
1326
|
+
pool: (filter?: (c: KeyCertificate$2) => boolean) => Promise<KeyCertificate$2[]>;
|
|
1327
|
+
/** NOMOS-SPEC-007 §3: certify `child` under `parent`. Refuses anything a verifier would refuse. */
|
|
1328
|
+
issue(io: IssueOptions): Promise<KeyCertificate$2>;
|
|
1329
|
+
/** rev. 1.10 §5.1: `parent` revokes a key it certified. The key is dead on every path. */
|
|
1330
|
+
revokeKey(io: {
|
|
1331
|
+
parent: Signer;
|
|
1332
|
+
kid: string;
|
|
1333
|
+
reason: string;
|
|
1334
|
+
}): Promise<RevocationStatement>;
|
|
1335
|
+
/** rev. 1.10 §5.1: withdraw one certificate; the key stays valid under any other. */
|
|
1336
|
+
revokeCertificate(io: {
|
|
1337
|
+
parent: Signer;
|
|
1338
|
+
fingerprint: string;
|
|
1339
|
+
reason: string;
|
|
1340
|
+
}): Promise<RevocationStatement>;
|
|
1341
|
+
/** The certificates that connect `kid` to the root: what a witness or approver returns with
|
|
1342
|
+
* what it signs (SPEC-009 0.2.0 §4, §5). */
|
|
1343
|
+
chainFor(kid: string): Promise<KeyCertificate$2[]>;
|
|
1344
|
+
/** How `kid` is reached from the root, and with which effective scopes, or why it is not. */
|
|
1345
|
+
check(kid: string): Promise<{
|
|
1346
|
+
ok: true;
|
|
1347
|
+
scopes: ScopeTerms[];
|
|
1348
|
+
} | {
|
|
1349
|
+
ok: false;
|
|
1350
|
+
reason: string;
|
|
1351
|
+
}>;
|
|
1352
|
+
certificates: () => Promise<KeyCertificate$2[]>;
|
|
1353
|
+
statements: () => Promise<RevocationStatement[]>;
|
|
1354
|
+
/** rev. 1.10 §5.3: the signed list, carrying the certificates that make it checkable. The
|
|
1355
|
+
* signer should be reached from the root, or the list establishes no date (§5.3). */
|
|
1356
|
+
revocationList(signer: Signer): Promise<RevocationList>;
|
|
1357
|
+
};
|
|
1358
|
+
type CertificateRegistry = ReturnType<typeof certificateRegistry>;
|
|
1359
|
+
/** The registry in your own Postgres (two append-only tables), for an issuer that runs on more
|
|
1360
|
+
* than one instance. Same structural pool as postgresStore(). */
|
|
1361
|
+
declare function postgresRegistryStore(pool: {
|
|
1362
|
+
query(text: string, values?: unknown[]): Promise<{
|
|
1363
|
+
rows: any[];
|
|
1364
|
+
}>;
|
|
1365
|
+
}, opts?: {
|
|
1366
|
+
prefix?: string;
|
|
1367
|
+
}): RegistryStore & {
|
|
1368
|
+
schema: string;
|
|
1369
|
+
migrate(): Promise<void>;
|
|
1370
|
+
};
|
|
1371
|
+
|
|
1372
|
+
/** A registration's authenticator data, and the passkey's public key as canonical SPKI PEM. */
|
|
1373
|
+
declare function readAttestation(attestationObject: Uint8Array): {
|
|
1374
|
+
authData: Uint8Array;
|
|
1375
|
+
flags: number;
|
|
1376
|
+
credentialId: Uint8Array;
|
|
1377
|
+
publicKeyPem: string;
|
|
1378
|
+
};
|
|
1379
|
+
interface EnrolmentClaims {
|
|
1380
|
+
approver: string;
|
|
1381
|
+
roles: string[];
|
|
1382
|
+
origin: string;
|
|
1383
|
+
expires_at: string;
|
|
1384
|
+
nonce: string;
|
|
1385
|
+
}
|
|
1386
|
+
/** Sign a single-use enrolment link for one person (`nomos enroll` does this). */
|
|
1387
|
+
declare function signEnrolmentToken(authority: Signer, c: {
|
|
1388
|
+
approver: string;
|
|
1389
|
+
roles: string[];
|
|
1390
|
+
origin: string;
|
|
1391
|
+
expiresAt: Date;
|
|
1392
|
+
}): Promise<string>;
|
|
1393
|
+
/** The claims of a valid, unexpired link for this origin, or the reason it is not one. */
|
|
1394
|
+
declare function verifyEnrolmentToken(token: string, authorityPem: string, origin: string, now: Date): EnrolmentClaims | {
|
|
1395
|
+
error: string;
|
|
1396
|
+
};
|
|
1397
|
+
interface PasskeyCredential {
|
|
1398
|
+
credential_id: string;
|
|
1399
|
+
approver: string;
|
|
1400
|
+
roles: string[];
|
|
1401
|
+
kid: string;
|
|
1402
|
+
public_key_pem: string;
|
|
1403
|
+
label: string;
|
|
1404
|
+
created_at: string;
|
|
1405
|
+
}
|
|
1406
|
+
interface PendingApproval {
|
|
1407
|
+
id: string;
|
|
1408
|
+
role: string;
|
|
1409
|
+
act: any;
|
|
1410
|
+
status: 'pending' | 'approved' | 'refused';
|
|
1411
|
+
created_at: string;
|
|
1412
|
+
/** Every ceremony offered, by its challenge: the consent fields fixed before the person was
|
|
1413
|
+
* asked (§4.5). Append-only, so asking again never invalidates a ceremony already in flight. */
|
|
1414
|
+
attempts: Record<string, Attempt>;
|
|
1415
|
+
consent?: any;
|
|
1416
|
+
key_certs?: KeyCertificate[];
|
|
1417
|
+
}
|
|
1418
|
+
interface Attempt {
|
|
1419
|
+
credential_id: string;
|
|
1420
|
+
signed_at: string;
|
|
1421
|
+
expires_at: string;
|
|
1422
|
+
}
|
|
1423
|
+
interface PasskeyStore {
|
|
1424
|
+
/** Marks an enrolment link used. false if it already was: a link works once. */
|
|
1425
|
+
claimToken(nonce: string): Promise<boolean>;
|
|
1426
|
+
tokenUsed(nonce: string): Promise<boolean>;
|
|
1427
|
+
saveEnrolmentChallenge(nonce: string, challenge: string): Promise<void>;
|
|
1428
|
+
enrolmentChallenge(nonce: string): Promise<string | null>;
|
|
1429
|
+
addCredential(c: PasskeyCredential): Promise<void>;
|
|
1430
|
+
credentials(): Promise<PasskeyCredential[]>;
|
|
1431
|
+
/** A new request. */
|
|
1432
|
+
createPending(p: PendingApproval): Promise<void>;
|
|
1433
|
+
pending(id: string): Promise<PendingApproval | null>;
|
|
1434
|
+
/** Adds one ceremony, only while the request is pending. false otherwise. */
|
|
1435
|
+
addAttempt(id: string, challenge: string, a: Attempt): Promise<boolean>;
|
|
1436
|
+
/** pending → approved or refused, exactly once: false if the request was no longer pending.
|
|
1437
|
+
* The only transition out of pending, so no stale write can undo an approval. */
|
|
1438
|
+
resolvePending(id: string, outcome: {
|
|
1439
|
+
status: 'approved';
|
|
1440
|
+
consent: any;
|
|
1441
|
+
key_certs: KeyCertificate[];
|
|
1442
|
+
} | {
|
|
1443
|
+
status: 'refused';
|
|
1444
|
+
}): Promise<boolean>;
|
|
1445
|
+
}
|
|
1446
|
+
declare function memoryPasskeyStore(): PasskeyStore;
|
|
1447
|
+
/** The same store in Postgres, for an approval service on more than one instance. */
|
|
1448
|
+
declare function postgresPasskeyStore(pool: {
|
|
1449
|
+
query(text: string, values?: unknown[]): Promise<{
|
|
1450
|
+
rows: any[];
|
|
1451
|
+
rowCount: number | null;
|
|
1452
|
+
}>;
|
|
1453
|
+
}, opts?: {
|
|
1454
|
+
prefix?: string;
|
|
1455
|
+
}): PasskeyStore & {
|
|
1456
|
+
schema: string;
|
|
1457
|
+
migrate(): Promise<void>;
|
|
1458
|
+
};
|
|
1459
|
+
interface PasskeyApproverOptions {
|
|
1460
|
+
origin: string;
|
|
1461
|
+
roles: string[];
|
|
1462
|
+
registry: CertificateRegistry;
|
|
1463
|
+
/** Certifies passkeys. Certified with `consent:<the roles it may enrol>` and no `approver` term. */
|
|
1464
|
+
enroller: Signer;
|
|
1465
|
+
/** The public key whose signed enrolment links this service honours (an administrator's). */
|
|
1466
|
+
enrolmentAuthority: string;
|
|
1467
|
+
store?: PasskeyStore;
|
|
1468
|
+
/** WebAuthn relying-party id. Default: the origin's hostname. */
|
|
1469
|
+
rpId?: string;
|
|
1470
|
+
rpName?: string;
|
|
1471
|
+
/** How long a passkey's certificate is valid. Default 365 days. */
|
|
1472
|
+
certificateDays?: number;
|
|
1473
|
+
/** List the people who may approve, by name and device, on the approval page. Default false: the
|
|
1474
|
+
* approval link goes to the carrier, which is not trusted with your roster, so the person types
|
|
1475
|
+
* their approver id and is shown only their own devices. */
|
|
1476
|
+
listApprovers?: boolean;
|
|
1477
|
+
/** Called for every new request, e.g. to notify the people who can approve it (email, chat). */
|
|
1478
|
+
onPending?: (request: {
|
|
1479
|
+
id: string;
|
|
1480
|
+
role: string;
|
|
1481
|
+
act: any;
|
|
1482
|
+
approvalUrl: string;
|
|
1483
|
+
}) => void | Promise<void>;
|
|
1484
|
+
now?: () => Date;
|
|
1485
|
+
}
|
|
1486
|
+
declare function passkeyApprover(o: PasskeyApproverOptions): {
|
|
1487
|
+
store: PasskeyStore;
|
|
1488
|
+
fetch: (request: Request) => Promise<Response>;
|
|
1489
|
+
express: () => (req: any, res: any, next?: () => void) => Promise<any>;
|
|
1490
|
+
node: () => (req: any, res: any, next?: () => void) => Promise<any>;
|
|
1491
|
+
};
|
|
1492
|
+
|
|
1085
1493
|
type ActStatus = 'committed' | 'escalated' | 'incomplete' | 'denied' | 'refused' | 'replayed';
|
|
1086
1494
|
interface ActResult {
|
|
1087
1495
|
status: ActStatus;
|
|
@@ -1139,8 +1547,13 @@ interface IssuerOptions {
|
|
|
1139
1547
|
signer: Signer;
|
|
1140
1548
|
/** Sealed artifacts, each the version currently in force. */
|
|
1141
1549
|
authorities: any[];
|
|
1142
|
-
/** The
|
|
1143
|
-
|
|
1550
|
+
/** The pool carriers select from (SPEC-009 0.2.0 §3.2, §6.5): at least the certificates for your
|
|
1551
|
+
* sealing keys. May hold more than 20. A function is read on every request, so a certificate
|
|
1552
|
+
* registry can change it without a restart. */
|
|
1553
|
+
keyCerts: KeyCertificate[] | (() => KeyCertificate[] | Promise<KeyCertificate[]>);
|
|
1554
|
+
/** Your signed revocation list (SPEC-007 rev. 1.10 §5.3), served at /nomos/revocations and
|
|
1555
|
+
* advertised as revocations_url. */
|
|
1556
|
+
revocations?: () => RevocationList | Promise<RevocationList>;
|
|
1144
1557
|
witnesses?: string[];
|
|
1145
1558
|
approvals?: Array<{
|
|
1146
1559
|
role: string;
|
|
@@ -1153,6 +1566,7 @@ declare function issuer(o: IssuerOptions): {
|
|
|
1153
1566
|
express: () => (req: any, res: any, next?: () => void) => Promise<any>;
|
|
1154
1567
|
node: () => (req: any, res: any, next?: () => void) => Promise<any>;
|
|
1155
1568
|
document: () => IssuerDocument;
|
|
1569
|
+
resolveDocument: () => Promise<IssuerDocument>;
|
|
1156
1570
|
};
|
|
1157
1571
|
interface WitnessOptions {
|
|
1158
1572
|
origin: string;
|
|
@@ -1169,6 +1583,9 @@ interface WitnessOptions {
|
|
|
1169
1583
|
claim: string;
|
|
1170
1584
|
about: string | null;
|
|
1171
1585
|
}) => boolean | Promise<boolean>;
|
|
1586
|
+
/** The certificates connecting your key toward the roots, returned with every statement
|
|
1587
|
+
* (SPEC-009 0.2.0 §4) so the issuer document need not list them. */
|
|
1588
|
+
keyCerts?: KeyCertificate[];
|
|
1172
1589
|
access?: string;
|
|
1173
1590
|
}
|
|
1174
1591
|
declare function witness(o: WitnessOptions): {
|
|
@@ -1182,6 +1599,9 @@ interface ApproverOptions {
|
|
|
1182
1599
|
/** The person's key, certified with `consent:<role> approver:<their id>` (SPEC-007 rev. 1.9 §3.7). */
|
|
1183
1600
|
signer: Signer;
|
|
1184
1601
|
roles: string[];
|
|
1602
|
+
/** The certificates connecting the person's key toward the roots, returned with every consent
|
|
1603
|
+
* (SPEC-009 0.2.0 §5) so the issuer document need not list every approver. */
|
|
1604
|
+
keyCerts?: KeyCertificate[];
|
|
1185
1605
|
/** 'page' (default): a person approves on a page this handler serves. 'auto': approve every
|
|
1186
1606
|
* request at once — development only. Or a function that decides. */
|
|
1187
1607
|
decide?: 'page' | 'auto' | ((request: {
|
|
@@ -1202,4 +1622,4 @@ declare function approver(o: ApproverOptions): {
|
|
|
1202
1622
|
pending: Map<string, Pending>;
|
|
1203
1623
|
};
|
|
1204
1624
|
|
|
1205
|
-
export { ACT_MEDIA_TYPE, type AcceptOptions, type AcceptStore, type AcceptTransaction, type AcceptedAuthority, type KeyCertificate as ActKeyCertificate, type ActOptions, type ActResult, type ActStatus, type Action, type Answer, type ApproverOptions, type Artifact, type ArtifactList, type ArtifactSchema, type ArtifactSchemaField, type AttestationInfo, type BuildActOptions, type CanOptions, type CanParams, type CanResult, type CanVerdict, type ChainVerdictDecision, type ConservedStateInfo, type ConservedStateReceipt, type Contradiction, type DetectContradictionsParams, type DetectContradictionsResult, type GenerateGovernanceParams, type GenerateGovernanceResult, type IssuerDocument, type IssuerOptions, type KeyCertificate$1 as KeyCertificate, type ListArtifactsParams, Nomos, NomosAPIError, NomosActError, NomosAuthenticationError, NomosAuthorizationError, type NomosConfig, NomosDiscoveryError, NomosError, type NomosErrorCode, NomosIssuerNotTrustedError, NomosNetworkError, NomosNotFoundError, NomosPaymentRequiredError, NomosRateLimitError, type NomosRawResponse, NomosValidationError, type NomosWebhookEvent, type NomosWebhookEventType, NomosWebhookSignatureError, type Receipt, type RelyingPartyDocument, type RequestOptions, type Reservation, type ReserveByActParams, type ReserveByQueryParams, type ReserveParams, type SignatureSuite, type Signer, type Verdict, type VerifyChainOptions, type VerifyChainParams, type VerifyChainResult, type VerifyDecisionParams, type VerifyDecisionResult, WELL_KNOWN, type WithLastResponse, type WitnessDocument, type WitnessOptions, accept, act, approver, buildAct, can, certify, fetchDocument, generateSigner, issuer, kidOf, localSigner, memoryStore, nomos, originOf, seal, seededSigner, signConsent, signInForce, signTestimony, statusFor, verifyChain, witness };
|
|
1625
|
+
export { ACT_MEDIA_TYPE, type AcceptOptions, type AcceptStore, type AcceptTransaction, type AcceptedAuthority, type KeyCertificate as ActKeyCertificate, type ActOptions, type ActResult, type ActStatus, type Action, type Answer, type ApproverOptions, type Artifact, type ArtifactList, type ArtifactSchema, type ArtifactSchemaField, type AttestationInfo, type BindingProposal, type BindingSuggestion, type BuildActOptions, type CanOptions, type CanParams, type CanResult, type CanVerdict, type CertificateRegistry, type ChainVerdictDecision, type ConservedStateInfo, type ConservedStateReceipt, type Contradiction, type DetectContradictionsParams, type DetectContradictionsResult, type EnrolmentClaims, type FactBinding, type GenerateGovernanceParams, type GenerateGovernanceResult, type IssueOptions, type IssuerDocument, type IssuerOptions, type KeyCertificate$1 as KeyCertificate, type ListArtifactsParams, MAX_PRESENTED, Nomos, NomosAPIError, NomosActError, NomosAuthenticationError, NomosAuthorizationError, type NomosConfig, NomosDiscoveryError, NomosError, type NomosErrorCode, NomosIssuerNotTrustedError, NomosNetworkError, NomosNotFoundError, NomosPaymentRequiredError, NomosRateLimitError, type NomosRawResponse, NomosValidationError, type NomosWebhookEvent, type NomosWebhookEventType, NomosWebhookSignatureError, type PasskeyApproverOptions, type PasskeyCredential, type PasskeyStore, type PendingApproval, type PgClient, type PgPool, type PolicyField, type PostgresStoreOptions, type Receipt, RegistryError, type RegistryStore, type RelyingPartyDocument, type RequestOptions, type Reservation, type ReserveByActParams, type ReserveByQueryParams, type ReserveParams, type RevocationSourceOptions, RevocationUnavailable, type SignatureSuite, type Signer, type ToolBindings, type ToolDescription, type UnresolvedFact, type Verdict, type VerifyChainOptions, type VerifyChainParams, type VerifyChainResult, type VerifyDecisionParams, type VerifyDecisionResult, WELL_KNOWN, type WithLastResponse, type WitnessDocument, type WitnessOptions, accept, act, applyToolBindings, approver, buildAct, can, certificateRegistry, certify, describeSuggestion, fetchDocument, generateSigner, issuer, kidOf, localSigner, memoryPasskeyStore, memoryRegistryStore, memoryStore, nomos, originOf, parseToolBindings, passkeyApprover, postgresPasskeyStore, postgresRegistryStore, postgresStore, presentedCertificates, readAttestation, reliedKids, revocationListCertificates, revocationSource, seal, seededSigner, signConsent, signEnrolmentToken, signInForce, signRevocation, signRevocationList, signTestimony, statusFor, suggestToolBindings, verifyChain, verifyEnrolmentToken, witness };
|