@daxni/sdk 0.0.0-stage → 1.0.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.
Files changed (46) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +244 -2
  3. package/daxni-logo-black.png +0 -0
  4. package/dist/bin/daxni.js +6765 -0
  5. package/dist/index.js +6206 -0
  6. package/dist/packages/sdk/index.d.ts +339 -0
  7. package/dist/src/ai/matchmaker.d.ts +21 -0
  8. package/dist/src/billing/autonomous.d.ts +21 -0
  9. package/dist/src/billing/railAdapter.d.ts +62 -0
  10. package/dist/src/cache/edgeResolver.d.ts +11 -0
  11. package/dist/src/cache/passport-cache.d.ts +13 -0
  12. package/dist/src/credentials/c2pa.d.ts +33 -0
  13. package/dist/src/credentials/card.d.ts +9 -0
  14. package/dist/src/credentials/did.d.ts +44 -0
  15. package/dist/src/credentials/encoding.d.ts +14 -0
  16. package/dist/src/credentials/jcs.d.ts +1 -0
  17. package/dist/src/credentials/png.d.ts +18 -0
  18. package/dist/src/credentials/qr.d.ts +24 -0
  19. package/dist/src/credentials/vc2.d.ts +129 -0
  20. package/dist/src/credentials/verify.d.ts +42 -0
  21. package/dist/src/crypto/merkle.d.ts +6 -0
  22. package/dist/src/crypto/switches.d.ts +18 -0
  23. package/dist/src/do/NamespaceGuard.d.ts +36 -0
  24. package/dist/src/do/handle-registry.d.ts +12 -0
  25. package/dist/src/env.d.ts +26 -0
  26. package/dist/src/index.d.ts +25 -0
  27. package/dist/src/ledger/anchor.d.ts +12 -0
  28. package/dist/src/lib/agents.d.ts +78 -0
  29. package/dist/src/lib/attestations.d.ts +15 -0
  30. package/dist/src/lib/audit.d.ts +21 -0
  31. package/dist/src/lib/auth.d.ts +15 -0
  32. package/dist/src/lib/certificates.d.ts +10 -0
  33. package/dist/src/lib/crypto.d.ts +11 -0
  34. package/dist/src/lib/founder-key.d.ts +75 -0
  35. package/dist/src/lib/mandates.d.ts +28 -0
  36. package/dist/src/lib/meter.d.ts +18 -0
  37. package/dist/src/lib/principals.d.ts +13 -0
  38. package/dist/src/lib/pulse.d.ts +17 -0
  39. package/dist/src/lib/root-rotation.d.ts +93 -0
  40. package/dist/src/lib/staticFiles.d.ts +5 -0
  41. package/dist/src/lib/store.d.ts +82 -0
  42. package/dist/src/lib/tee.d.ts +3 -0
  43. package/dist/src/lib/wimse.d.ts +164 -0
  44. package/dist/src/lib/zk.d.ts +10 -0
  45. package/dist/src/portal/livingImpression.d.ts +48 -0
  46. package/package.json +1 -6
@@ -0,0 +1,129 @@
1
+ export declare const W3C_VC_CONTEXT = "https://www.w3.org/ns/credentials/v2";
2
+ export declare const DAXNI_CONTEXT_URL = "https://api.daxni.com/contexts/daxni/v1";
3
+ export declare const VC_MEDIA_TYPE = "application/vc+ld+json";
4
+ export declare const EDDSA_JCS_2022 = "eddsa-jcs-2022";
5
+ export declare const MLDSA65_JCS_2022 = "mldsa65-jcs-2022";
6
+ export declare const CERTIFICATE_TYPE = "DaxniBirthCertificate";
7
+ export declare const PASSPORT_TYPE = "DaxniPortablePassport";
8
+ export declare const PASSPORT_TTL_MS: number;
9
+ export interface DataIntegrityProof {
10
+ type: "DataIntegrityProof";
11
+ cryptosuite: string;
12
+ created: string;
13
+ verificationMethod: string;
14
+ proofPurpose: string;
15
+ proofValue: string;
16
+ }
17
+ export interface DaxniCredential {
18
+ "@context": string[];
19
+ id: string;
20
+ type: string[];
21
+ issuer: string;
22
+ validFrom: string;
23
+ expirationDate?: string;
24
+ credentialSubject: Record<string, unknown>;
25
+ proof?: DataIntegrityProof | DataIntegrityProof[];
26
+ }
27
+ export type ByteSigner = (bytes: Uint8Array) => Promise<Uint8Array> | Uint8Array;
28
+ /** Noble-backed Ed25519 signer from a 32-byte seed (SDK / tests / portal bundle). */
29
+ export declare function nobleEd25519Signer(seed: Uint8Array): ByteSigner;
30
+ /** Noble-backed ML-DSA-65 signer from a 32-byte seed. */
31
+ export declare function nobleMldsa65Signer(seed: Uint8Array): ByteSigner;
32
+ /** SHA-256 hex of the JCS-canonicalized credentialSubject. */
33
+ export declare function subjectDigest(subject: Record<string, unknown>): string;
34
+ /** The Data Integrity hash input: hash(proof config) ‖ hash(document). */
35
+ export declare function proofHashInput(document: Record<string, unknown>, proofConfig: Omit<DataIntegrityProof, "proofValue">): Uint8Array;
36
+ export declare function proofsOf(credential: DaxniCredential): DataIntegrityProof[];
37
+ export interface CertificateFacts {
38
+ uri: string;
39
+ namespace: string;
40
+ name: string;
41
+ publicKey: string;
42
+ pqcPublicKey?: string | null;
43
+ cryptoSuite: string;
44
+ generationDepth: number;
45
+ parentUri?: string | null;
46
+ chainIndex: number;
47
+ bornAt: string;
48
+ recordHash: string;
49
+ liabilityCapUsd: number;
50
+ sovereignZone: string;
51
+ jurisdiction: string;
52
+ avatarUrl?: string | null;
53
+ }
54
+ export declare function buildCertificateCredential(facts: CertificateFacts): DaxniCredential;
55
+ export interface PassportFacts {
56
+ uri: string;
57
+ publicKey: string;
58
+ pqcPublicKey?: string | null;
59
+ cryptoSuite: string;
60
+ status: string;
61
+ liveness: string;
62
+ liabilityCapUsd: number;
63
+ sovereignZone: string;
64
+ hardwareSealed: boolean;
65
+ enclaveProfile?: {
66
+ vendor: string;
67
+ measurementHash: string;
68
+ modelHash: string;
69
+ } | null;
70
+ memoryRootHash: string | null;
71
+ recordHash: string;
72
+ exportedAt: string;
73
+ }
74
+ export declare function buildPassportCredential(facts: PassportFacts): DaxniCredential;
75
+ export declare function credentialKind(credential: DaxniCredential): "certificate" | "passport" | "unknown";
76
+ /**
77
+ * Attach the being's own proof(s): the Ed25519 assertionMethod proof,
78
+ * plus the ML-DSA-65 assertionMethod proof when the being is hybrid.
79
+ * Returns a NEW credential; the input is not mutated.
80
+ */
81
+ export declare function addSelfProofs(credential: DaxniCredential, signers: {
82
+ ed25519: ByteSigner;
83
+ mldsa65?: ByteSigner;
84
+ }, created?: string): Promise<DaxniCredential>;
85
+ /**
86
+ * Attach the registrar root's witness proof over the credential WITH
87
+ * its self-proof(s). The root signs bytes through the supplied signer
88
+ * (the worker's signBytesWithRoot — the private half never moves).
89
+ * `verificationMethod` names the root key that signed: the CURRENT
90
+ * method after a rotation (#root-2, #root-3, …) — a new witness proof
91
+ * must name the key that actually signed it, or no verifier can
92
+ * resolve it. Defaults to #root-1 (no rotation has ever happened).
93
+ */
94
+ export declare function addWitnessProof(credential: DaxniCredential, rootSigner: ByteSigner, created?: string, verificationMethod?: string): Promise<DaxniCredential>;
95
+ export interface ProofVerdict {
96
+ index: number;
97
+ proofPurpose: string;
98
+ cryptosuite: string;
99
+ ok: boolean;
100
+ detail: string;
101
+ }
102
+ /**
103
+ * Verify one proof in place. Key resolution is OFFLINE by design: the
104
+ * being's keys come from credentialSubject (and the verificationMethod
105
+ * must be exactly the did:key method derived from the subject key — a
106
+ * proof naming any other method fails), and the witness key is the
107
+ * pinned registrar root key supplied by the caller.
108
+ */
109
+ export declare function verifyProofAt(credential: DaxniCredential, index: number, rootPublicKeyB64url: string, rootKeysByMethod?: Record<string, string>): ProofVerdict;
110
+ export interface CredentialProofReport {
111
+ verdicts: ProofVerdict[];
112
+ selfOk: boolean;
113
+ witnessOk: boolean;
114
+ }
115
+ /** Verify the full proof chain of a credential against the pinned root key. */
116
+ export declare function verifyCredentialProofs(credential: DaxniCredential, rootPublicKeyB64url: string, rootKeysByMethod?: Record<string, string>): CredentialProofReport;
117
+ /**
118
+ * What goes into the credential's QR code. Classical credentials carry
119
+ * the FULL VC in one QR (ECC level L fits it). Hybrid credentials
120
+ * cannot: an ML-DSA-65 proofValue alone is ~4.4 KB of base64url — past
121
+ * the largest QR — so the hybrid QR carries the compact root-signed ZK
122
+ * claim token instead (challenge-bound to this credential's recordHash
123
+ * by the issuing flow), and the full hybrid credential travels only in
124
+ * the .vc.json / C2PA exports.
125
+ */
126
+ export declare function selectQrPayload(credential: DaxniCredential, zkToken?: string): {
127
+ kind: "vc" | "zk";
128
+ payload: string;
129
+ };
@@ -0,0 +1,42 @@
1
+ import { type DaxniCredential } from "./vc2";
2
+ export interface VerifyCheck {
3
+ name: string;
4
+ status: "pass" | "fail" | "skip";
5
+ detail: string;
6
+ }
7
+ export interface VerifyReport {
8
+ ok: boolean;
9
+ kind: "certificate" | "passport" | "zk-token" | "unknown";
10
+ verdict: string;
11
+ checks: VerifyCheck[];
12
+ credential?: DaxniCredential;
13
+ claims?: Record<string, unknown>;
14
+ }
15
+ export interface VerifyOptions {
16
+ /** Override ONLY for tests / non-production roots. Production pins the key below. */
17
+ rootPublicKeyB64?: string;
18
+ /**
19
+ * OPTIONAL: the list of registrar root public keys to trust for
20
+ * kid-less tokens (ZK claim tokens carry no kid — the verifier tries
21
+ * each key in turn). First entry is the current root. Defaults to
22
+ * [rootPublicKeyB64]. During a rotation window pass [new, old]; after
23
+ * an emergency termination pass [new] only — an old-key token then
24
+ * fails, as it must.
25
+ */
26
+ rootPublicKeyB64s?: string[];
27
+ /**
28
+ * OPTIONAL: method id → root key (base64url x) for witness proofs.
29
+ * When supplied, a witness proof's key is resolved by the method it
30
+ * names (old certificates witnessed under #root-1 verify against the
31
+ * old key, new ones under #root-2 against the new key); a method
32
+ * absent from the map fails (a revoked key, after an emergency
33
+ * termination). When absent, behavior is exactly as before: the
34
+ * witness proof must name #root-1 and verifies against the single
35
+ * pinned key.
36
+ */
37
+ rootPublicKeysByMethod?: Record<string, string>;
38
+ now?: number;
39
+ }
40
+ export declare const VERIFIED_VERDICT = "AUTHENTIC SOVEREIGN BEING \u00B7 VERIFIED OFFLINE";
41
+ export declare const ZK_VERDICT = "ZK CLAIM \u00B7 VERIFIED OFFLINE";
42
+ export declare function verifyCredentialOffline(input: string | Uint8Array, opts?: VerifyOptions): VerifyReport;
@@ -0,0 +1,6 @@
1
+ export declare const GENESIS_HASH = "GENESIS";
2
+ export declare function entryPayload(targetUri: string, action: string, actorSignature: string): string;
3
+ export declare function computeEntryHash(prevHash: string, targetUri: string, action: string, actorSignature: string, timestamp: number): Promise<string>;
4
+ export declare function rootSigningKey(secret: string): Promise<CryptoKey>;
5
+ export declare function rootPublicKeyFromSecret(secret: string): Promise<JsonWebKey | null>;
6
+ export declare function signEntryHash(secret: string, entryHash: string): Promise<string>;
@@ -0,0 +1,18 @@
1
+ import type { Env } from "../env";
2
+ export declare const SWITCH_DEFAULTS: Record<string, string>;
3
+ export declare function getSwitch(env: Env, key: string): Promise<string>;
4
+ export declare function getSwitchBool(env: Env, key: string): Promise<boolean>;
5
+ export declare function getSwitchNumber(env: Env, key: string): Promise<number>;
6
+ export declare function getSwitches(env: Env, keys: string[]): Promise<Map<string, string>>;
7
+ export type CryptoSuite = "ed25519" | "hybrid-ed25519-mldsa65";
8
+ export declare function isCryptoSuite(v: unknown): v is CryptoSuite;
9
+ export interface DualSignaturePayload {
10
+ ed25519Sig: string;
11
+ mldsa65Sig?: string;
12
+ }
13
+ export declare function verifyPqcSignature(message: Uint8Array, pqcPublicKeyB64url: string, mldsa65SigB64url: string): boolean;
14
+ export declare function verifyAgentSignature(message: Uint8Array, agent: {
15
+ public_key: string;
16
+ pqc_public_key?: string | null;
17
+ crypto_suite: string;
18
+ }, sigs: DualSignaturePayload): boolean;
@@ -0,0 +1,36 @@
1
+ import { DurableObject } from "cloudflare:workers";
2
+ import type { Env } from "../env";
3
+ export declare class NamespaceGuard extends DurableObject<Env> {
4
+ private liabilityTail;
5
+ private serialized;
6
+ fetch(req: Request): Promise<Response>;
7
+ private checkSpawn;
8
+ private d1Children;
9
+ private seedLiability;
10
+ private reserveSpawn;
11
+ private releaseSpawn;
12
+ private reconcile;
13
+ webSocketClose(ws: WebSocket): Promise<void>;
14
+ webSocketError(ws: WebSocket): Promise<void>;
15
+ private markSevered;
16
+ }
17
+ export declare function guardStub(env: Env, namespace: string): DurableObjectStub;
18
+ export declare function checkSpawnCircuit(env: Env, namespace: string): Promise<{
19
+ allowed: true;
20
+ } | {
21
+ allowed: false;
22
+ reason: string;
23
+ }>;
24
+ export declare function reserveSpawnLiability(env: Env, namespace: string, parentUri: string, childUri: string, childCapUsd: number): Promise<{
25
+ allowed: true;
26
+ } | {
27
+ allowed: false;
28
+ reason: string;
29
+ }>;
30
+ export declare function releaseSpawnLiability(env: Env, namespace: string, parentUri: string, childUri: string): Promise<void>;
31
+ export declare function releaseSpawnLiabilityForChild(env: Env, childUri: string): Promise<void>;
32
+ export declare function reconcileSpawnLiability(env: Env, namespace: string): Promise<{
33
+ parentUri: string;
34
+ before: number;
35
+ after: number;
36
+ }[]>;
@@ -0,0 +1,12 @@
1
+ import { DurableObject } from "cloudflare:workers";
2
+ import type { Env } from "../env";
3
+ export declare class HandleRegistry extends DurableObject<Env> {
4
+ constructor(ctx: DurableObjectState, env: Env);
5
+ private ensureRootKey;
6
+ private stageIncomingRootKey;
7
+ private getIncomingRootKey;
8
+ private signWithIncomingKey;
9
+ private activateIncomingRoot;
10
+ fetch(req: Request): Promise<Response>;
11
+ }
12
+ export declare function registryStub(env: Env): DurableObjectStub;
@@ -0,0 +1,26 @@
1
+ export interface RateLimiter {
2
+ limit(options: {
3
+ key: string;
4
+ }): Promise<{
5
+ success: boolean;
6
+ }>;
7
+ }
8
+ export interface Env {
9
+ DB: D1Database;
10
+ EDGE_CACHE: KVNamespace;
11
+ HANDLE_REGISTRY: DurableObjectNamespace;
12
+ NAMESPACE_GUARD: DurableObjectNamespace;
13
+ ASSETS: Fetcher;
14
+ REGISTER_LIMITER: RateLimiter;
15
+ RESOLVE_LIMITER: RateLimiter;
16
+ DOH_ENDPOINT?: string;
17
+ DAXNI_ROOT_PRIVATE_KEY?: string;
18
+ AI: Ai;
19
+ AGENT_INDEX: VectorizeIndex;
20
+ BILLING_WEBHOOK_SECRET?: string;
21
+ BILLING_STRIPE_CHECKOUT_URL?: string;
22
+ BILLING_CRYPTO_ADDRESS?: string;
23
+ PAYMENT_RAIL_MODE?: string;
24
+ TEE_ROOT_CERTS?: string;
25
+ DAXNI_TEST_STUB_AI?: string;
26
+ }
@@ -0,0 +1,25 @@
1
+ import type { Env } from "./env";
2
+ import { HandleRegistry } from "./do/handle-registry";
3
+ import { NamespaceGuard } from "./do/NamespaceGuard";
4
+ export { HandleRegistry, NamespaceGuard };
5
+ export declare const PORTAL_CSP = "default-src 'self'; script-src 'self'; style-src 'self'; img-src 'self' data:; connect-src 'self'; frame-ancestors 'none'; base-uri 'self'; form-action 'self'";
6
+ export declare function purgePendingHandles(env: Env): Promise<{
7
+ purged: number;
8
+ }>;
9
+ export declare function runLiabilityReconcile(env: Env): Promise<{
10
+ repaired: number;
11
+ repairs: {
12
+ parentUri: string;
13
+ before: number;
14
+ after: number;
15
+ }[];
16
+ }>;
17
+ export declare function runEphemeralSweep(env: Env): Promise<{
18
+ swept: number;
19
+ mintPruned: number;
20
+ }>;
21
+ declare const _default: {
22
+ fetch: (request: Request, env?: Env | {} | undefined, executionCtx?: import("hono").ExecutionContext) => Response | Promise<Response>;
23
+ scheduled(event: ScheduledEvent, env: Env, ctx: ExecutionContext): Promise<void>;
24
+ };
25
+ export default _default;
@@ -0,0 +1,12 @@
1
+ import type { Env } from "../env";
2
+ export interface Checkpoint {
3
+ rootHash: string;
4
+ entryCount: number;
5
+ timestamp: string;
6
+ signature: string;
7
+ }
8
+ export declare function checkpointStatement(cp: Omit<Checkpoint, "signature">): string;
9
+ export declare function computeCheckpoint(env: Env): Promise<Checkpoint>;
10
+ export declare function runHourlyCheckpoint(env: Env): Promise<Checkpoint>;
11
+ export declare function verifyCheckpointSignature(cp: Checkpoint, publicKeyB64url: string): Promise<boolean>;
12
+ export declare function getCheckpoint(env: Env): Promise<Checkpoint>;
@@ -0,0 +1,78 @@
1
+ import type { Env } from "../env";
2
+ import { type CryptoSuite } from "../crypto/switches";
3
+ import { type ResolveView } from "./store";
4
+ export interface ActionResult {
5
+ status: number;
6
+ body: Record<string, unknown>;
7
+ }
8
+ export interface BirthRecord {
9
+ v: 1;
10
+ type: "daxni.birth";
11
+ namespace: string;
12
+ name: string;
13
+ publicKey: string;
14
+ pqcAlgorithm?: string;
15
+ pqcPublicKey?: string;
16
+ capabilityManifest?: unknown;
17
+ liabilityCapUsd?: number;
18
+ jurisdiction?: string;
19
+ parentHandle?: string;
20
+ forkHash?: string;
21
+ cryptoSuite?: CryptoSuite;
22
+ nextKeyHash?: string;
23
+ ephemeralExpiresAt?: number;
24
+ sovereignZone?: string;
25
+ aud?: string;
26
+ createdAt: string;
27
+ }
28
+ export declare function registerAgent(env: Env, payload: {
29
+ record: BirthRecord;
30
+ signature: string;
31
+ mldsa65Sig?: string;
32
+ }): Promise<ActionResult>;
33
+ export declare function ancestorUris(env: Env, agentId: string): Promise<Set<string>>;
34
+ export declare function rotateKey(env: Env, payload: {
35
+ uri: string;
36
+ newPublicKey: string;
37
+ newPqcPublicKey?: string;
38
+ timestamp: string;
39
+ oldSignature: string;
40
+ newSignature: string;
41
+ oldPqcSignature?: string;
42
+ newPqcSignature?: string;
43
+ }): Promise<ActionResult>;
44
+ export declare function rotateCrypto(env: Env, callerUri: string, payload: {
45
+ targetCryptoSuite?: unknown;
46
+ newPqcPublicKey?: unknown;
47
+ timestamp?: unknown;
48
+ aud?: unknown;
49
+ signatures?: {
50
+ ed25519Sig?: unknown;
51
+ mldsa65Sig?: unknown;
52
+ };
53
+ }): Promise<ActionResult>;
54
+ export declare function setPublicBadge(env: Env, payload: {
55
+ uri: string;
56
+ public_badge: boolean;
57
+ timestamp: string;
58
+ signature: string;
59
+ }): Promise<ActionResult>;
60
+ export declare function revokeAgent(env: Env, payload: {
61
+ uri: string;
62
+ timestamp?: string;
63
+ signature?: string;
64
+ principalToken?: string;
65
+ }): Promise<ActionResult>;
66
+ export declare function spawnAgent(env: Env, parent: ResolveView, payload: {
67
+ record: BirthRecord;
68
+ childSignature: string;
69
+ mldsa65Sig?: string;
70
+ }): Promise<ActionResult>;
71
+ export declare function succeedAgent(env: Env, payload: {
72
+ uri: string;
73
+ successorPublicKey: string;
74
+ successorPqcPublicKey?: string;
75
+ signature: string;
76
+ pqcSignature?: string;
77
+ timestamp: string;
78
+ }): Promise<ActionResult>;
@@ -0,0 +1,15 @@
1
+ import type { Env } from "../env";
2
+ export interface AttestationResult {
3
+ status: number;
4
+ body: Record<string, unknown>;
5
+ }
6
+ export declare const ATTEST_MESSAGE_PREFIX = "DAXNI-REGISTRAR-ATTEST-v1\n";
7
+ export declare function attestationWeight(kybTier: string, senderCreatedAt: number, now?: number): number;
8
+ export declare function submitAttestation(env: Env, payload: {
9
+ senderUri: string;
10
+ targetUri: string;
11
+ kind: string;
12
+ detail?: string;
13
+ timestamp: string;
14
+ signature: string;
15
+ }): Promise<AttestationResult>;
@@ -0,0 +1,21 @@
1
+ import type { Env } from "../env";
2
+ export type AuditAction = "REGISTER" | "KEY_ROTATE" | "DOMAIN_VERIFY" | "KILL_SWITCH" | "QUARANTINE" | "QUARANTINE_LIFTED" | "TIER_UPGRADE" | "BADGE_TOGGLE" | "SPAWN" | "KEY_SUCCESSION" | "EPHEMERAL_EXPIRED" | "LIABILITY_RECONCILE" | "ARTIFACT_ATTEST" | "CRYPTO_MIGRATION" | "ROOT_ROTATION" | "FOUNDER_KEY_ENROLLED" | "FOUNDER_KEY_REPLACED";
3
+ export declare function appendAudit(env: Env, targetUri: string, action: AuditAction, actorSignature: string): Promise<string>;
4
+ export declare function signWithRoot(env: Env, text: string): Promise<string>;
5
+ export declare function signBytesWithRoot(env: Env, bytes: Uint8Array): Promise<string>;
6
+ export declare function signRootToken(env: Env, typ: string, payload: Record<string, unknown>, headerExtra?: Record<string, unknown>): Promise<string>;
7
+ export declare function getRootPublicKey(env: Env): Promise<JsonWebKey | null>;
8
+ export interface AuditEntry {
9
+ id: number;
10
+ target_uri: string;
11
+ action: string;
12
+ actor_signature: string;
13
+ timestamp: number;
14
+ prev_hash: string | null;
15
+ entry_hash: string | null;
16
+ root_signature: string | null;
17
+ }
18
+ export declare function verifyChain(env: Env): Promise<{
19
+ valid: boolean;
20
+ entries: AuditEntry[];
21
+ }>;
@@ -0,0 +1,15 @@
1
+ import type { Env } from "../env";
2
+ import { type ResolveView } from "./store";
3
+ export interface CallerAuth {
4
+ handle: string;
5
+ timestamp: string;
6
+ signature: string;
7
+ pqcSignature?: string;
8
+ }
9
+ export declare const DAXNI_AUD = "daxni.com";
10
+ export declare function authMessage(handle: string, method: string, path: string, timestamp: string, audBound?: boolean): string;
11
+ export declare function authenticateCaller(env: Env, auth: CallerAuth | undefined, method: string, path: string, opts?: {
12
+ audBound?: boolean;
13
+ authoritative?: boolean;
14
+ }): Promise<ResolveView | null>;
15
+ export declare function authFromHeaders(get: (name: string) => string | undefined): CallerAuth | undefined;
@@ -0,0 +1,10 @@
1
+ import type { Env } from "../env";
2
+ import type { ResolveView } from "./store";
3
+ import { type DaxniCredential } from "../credentials/vc2";
4
+ export type WitnessResult = {
5
+ ok: true;
6
+ credential: DaxniCredential;
7
+ } | {
8
+ ok: false;
9
+ };
10
+ export declare function witnessCredential(env: Env, caller: ResolveView, presented: unknown): Promise<WitnessResult>;
@@ -0,0 +1,11 @@
1
+ export declare function canonicalJSON(v: unknown): string;
2
+ export declare function generateEd25519KeyPair(): Promise<{
3
+ privateKey: CryptoKey;
4
+ publicKey: CryptoKey;
5
+ publicKeyB64: string;
6
+ privateJwk: JsonWebKey;
7
+ publicJwk: JsonWebKey;
8
+ }>;
9
+ export declare function b64urlToBytes(s: string): Uint8Array;
10
+ export declare function jwkThumbprint(jwk: JsonWebKey): Promise<string>;
11
+ export declare function verifyEd25519(publicKeyB64url: string, signatureB64url: string, message: string): Promise<boolean>;
@@ -0,0 +1,75 @@
1
+ import type { Env } from "../env";
2
+ export type FounderKeyRole = "founder" | "recovery";
3
+ export interface FounderKeyRecord {
4
+ id: number;
5
+ /** RFC 7638 thumbprint of the public JWK — the stable key id. */
6
+ keyId: string;
7
+ /** Ed25519 public key x (base64url). Public material only. */
8
+ publicKeyX: string;
9
+ role: FounderKeyRole;
10
+ status: "active" | "superseded" | "revoked";
11
+ enrolledAt: number;
12
+ enrolledBy: string;
13
+ note: string | null;
14
+ }
15
+ export declare function founderDecisionMessage(params: {
16
+ kind: "planned" | "emergency";
17
+ oldKeyX: string;
18
+ newKeyX: string | null;
19
+ reason: string;
20
+ }): string;
21
+ export declare function founderReplacementMessage(params: {
22
+ role: FounderKeyRole;
23
+ oldKeyId: string;
24
+ newPublicKeyX: string;
25
+ }): string;
26
+ /** The active key of a role, or null when none is enrolled. */
27
+ export declare function getActiveFounderKey(env: Env, role: FounderKeyRole): Promise<FounderKeyRecord | null>;
28
+ /** Every founder key ever enrolled, newest first (active + superseded + revoked). */
29
+ export declare function listFounderKeys(env: Env): Promise<FounderKeyRecord[]>;
30
+ /** Verify an Ed25519 signature against an enrolled key record. False on any failure — bad format, wrong key, bad signature — never throws. */
31
+ export declare function verifyFounderSignature(key: FounderKeyRecord, message: string, signature: string): Promise<boolean>;
32
+ /**
33
+ * Enroll a founder or recovery PUBLIC key. This is the bootstrap: it
34
+ * is only allowed when NO active key of that role exists — there is
35
+ * nothing to verify against yet, so the enrollment is performed by
36
+ * worker code at the founder's direction and recorded in the chain
37
+ * (FOUNDER_KEY_ENROLLED, actor = the enrolled key's thumbprint — an
38
+ * identifier, not a signature, because the bootstrap has none).
39
+ * A second key of the same role must go through replaceFounderKey.
40
+ * NEVER pass private key material here — this function takes the
41
+ * public x only, and the table has no column that could hold a
42
+ * private half.
43
+ */
44
+ export declare function enrollFounderKey(env: Env, opts: {
45
+ publicKeyX: string;
46
+ role: FounderKeyRole;
47
+ enrolledBy: string;
48
+ note?: string;
49
+ }): Promise<FounderKeyRecord>;
50
+ /**
51
+ * Replace an enrolled key. The authorizing signature must verify
52
+ * against the key being replaced (its own rollover — e.g. the founder
53
+ * got a new phone and enrolls its key with the old phone's signature)
54
+ * or, when replacing a LOST founder key, against the active recovery
55
+ * key (the recovery path). A recovery key is replaced by a signature
56
+ * from the current founder key or the current recovery key.
57
+ * The old row is marked superseded (never deleted — history is the
58
+ * audit trail); the new row becomes the active key of that role.
59
+ * The authorizing signature is recorded in the chain
60
+ * (FOUNDER_KEY_REPLACED). A signature from any other key — including
61
+ * a recovery key offered for a ROTATION — is refused here by
62
+ * construction: this function only ever replaces keys, never
63
+ * authorizes a rotation.
64
+ */
65
+ export declare function replaceFounderKey(env: Env, opts: {
66
+ role: FounderKeyRole;
67
+ newPublicKeyX: string;
68
+ /** The authorizing signature over founderReplacementMessage. */
69
+ signature: string;
70
+ enrolledBy: string;
71
+ note?: string;
72
+ }): Promise<{
73
+ record: FounderKeyRecord;
74
+ authorizedBy: "founder" | "recovery";
75
+ }>;
@@ -0,0 +1,28 @@
1
+ import type { Env } from "../env";
2
+ import { type ResolveView } from "./store";
3
+ export interface DelegationMandate {
4
+ agentUri: string;
5
+ principalNamespace: string;
6
+ principalPublicKey: string;
7
+ maxPerTxUsd: number;
8
+ dailyCapUsd: number;
9
+ allowedCapabilities: string[];
10
+ expiresAt: number;
11
+ aud: string;
12
+ }
13
+ export declare const MANDATE_AUD = "daxni.com";
14
+ export declare const MANDATE_SIGN_PREFIX = "DAXNI-MANDATE-v1";
15
+ export declare const MANDATE_PRESENT_PREFIX = "DAXNI-MANDATE-PRESENT-v1";
16
+ export interface MandatePresentation {
17
+ mandate: DelegationMandate;
18
+ principalSignature: string;
19
+ presentationSignature: string;
20
+ presentationPqcSignature?: string;
21
+ }
22
+ export declare function verifyMandate(env: Env, presentation: MandatePresentation, presenter: ResolveView): Promise<{
23
+ ok: true;
24
+ mandate: DelegationMandate;
25
+ } | {
26
+ ok: false;
27
+ }>;
28
+ export declare function mandateFacts(mandate: DelegationMandate): Record<string, unknown>;
@@ -0,0 +1,18 @@
1
+ import type { Env } from "../env";
2
+ export type MeterPath = "signin_proof" | "signature_check" | "token_check";
3
+ export interface MeterRow {
4
+ caller_key_id: string;
5
+ day_utc: string;
6
+ signin_proof: number;
7
+ signature_check: number;
8
+ token_check: number;
9
+ updated_at: string;
10
+ }
11
+ export declare function callerKeyId(uri: string): Promise<string>;
12
+ export declare function dayUtc(now?: Date): string;
13
+ export declare function incrementMeter(env: Env, callerKeyIdValue: string, path: MeterPath, now?: Date): Promise<void>;
14
+ export declare function readMeter(env: Env, callerKeyIdValue: string, day: string): Promise<MeterRow | null>;
15
+ export declare function pruneMeterRows(env: Env, retentionDays?: number, now?: Date): Promise<number>;
16
+ export declare function recordMeter(env: Env, execCtx: {
17
+ waitUntil(p: Promise<unknown>): void;
18
+ } | undefined, callerUri: string, path: MeterPath): void;
@@ -0,0 +1,13 @@
1
+ import type { Env } from "../env";
2
+ export interface PrincipalResult {
3
+ status: number;
4
+ body: Record<string, unknown>;
5
+ }
6
+ export declare function registerPrincipal(env: Env, payload: {
7
+ handle: string;
8
+ displayName: string;
9
+ domain?: string;
10
+ }): Promise<PrincipalResult>;
11
+ export declare function verifyPrincipalDns(env: Env, payload: {
12
+ handle: string;
13
+ }): Promise<PrincipalResult>;
@@ -0,0 +1,17 @@
1
+ import type { Env } from "../env";
2
+ export interface PulseRecord {
3
+ firstSeen: number;
4
+ lastSeen: number;
5
+ pulses: number;
6
+ }
7
+ export type Liveness = "LIVE" | "DEGRADED" | "DORMANT";
8
+ export declare function getPulse(env: Env, uri: string): Promise<PulseRecord | null>;
9
+ export declare function recordPulse(env: Env, uri: string): Promise<PulseRecord>;
10
+ export declare function getSeveredAt(env: Env, uri: string): Promise<number | null>;
11
+ export type LivenessX = Liveness | "SEVERED";
12
+ export declare function livenessNow(env: Env, uri: string): Promise<{
13
+ state: LivenessX;
14
+ lastSeen: number | null;
15
+ }>;
16
+ export declare function livenessState(lastSeen: number | null, now?: number): Liveness;
17
+ export declare function livenessScore(state: Liveness): number;