/** * Identity attestations — sybil-resistance primitives. * * Problem: `did:key` identities are free to mint. An adversary can spin up * a million fresh DIDs in seconds to vote in consensus, drain rate limits, * poison reputation systems, or game open marketplaces. Soma has no * built-in defense against this today. * * This module gives applications the raw material to defend themselves: * cryptographically-signed claims by issuers about subjects. An * `IdentityAttestation` is a signed statement "I, issuer D, vouch that * subject S has property X". It is NOT a credential the subject carries — * it is a record issuers publish, that verifiers look up, to decide how * much weight a subject's identity carries. * * Attestation layers (from simplest to strongest): * 1. `peer-vouched` — another identity (possibly also anonymous) mentions * this subject. Cheap. Millions of these != trust. * 2. `time-in-network` — subject has been active for N days (signed by * a timekeeper). Hard to fake if timekeepers are honest. * 3. `organization-member` — org signs that subject is part of it. * 4. `stake-bonded` — subject has posted economic collateral. * 5. `kyc-verified` — issuer has verified subject against real-world ID. * * The weight knob and type multipliers let applications decide policy * (e.g. "only subjects with tier >= staked can participate in governance"). * * The registry supports expiry + revocation, and a reputation score that * decays with time so an attestation from three years ago carries less * weight than one from last week. Decay rates are configurable. * * This is deliberately PASSIVE: it does not talk to any chain, registry, * or oracle. Applications inject attestations from whatever source they * trust (on-chain ERC-8004, off-chain signed claims, Soul-bound tokens). */ import { type CryptoProvider } from '../core/crypto-provider.js'; export type AttestationType = 'peer-vouched' | 'time-in-network' | 'organization-member' | 'stake-bonded' | 'kyc-verified' | 'skill-verified' | 'custom'; export interface IdentityAttestation { /** Opaque attestation ID. */ id: string; /** DID of the subject this attestation is about. */ subjectDid: string; /** DID of the issuer making this claim. */ issuerDid: string; /** Kind of claim being made. */ attestationType: AttestationType; /** Weight, 0-100. Lets the issuer grade how strong their claim is. */ weight: number; /** When issued (ms epoch). */ issuedAt: number; /** When this expires, or null for never-expires. */ expiresAt: number | null; /** Optional hex hash of off-chain evidence. */ evidence: string | null; /** Optional custom label when type='custom'. */ customLabel: string | null; /** Anti-replay nonce. */ nonce: string; /** Issuer's base64 public key. */ issuerPublicKey: string; /** Issuer's Ed25519 signature over the canonical payload. */ signature: string; } export type AttestationVerification = { valid: true; } | { valid: false; reason: string; }; export type IdentityTier = 'anonymous' | 'attested' | 'staked' | 'verified'; export interface ReputationScore { subjectDid: string; score: number; tier: IdentityTier; attestationCount: number; countByType: Record; computedAt: number; } /** Configuration for score computation. */ export interface ScoreConfig { /** Half-life for freshness decay, ms. Default 180 days. */ halfLifeMs: number; /** Per-type multipliers (default set provides sensible ordering). */ typeMultipliers: Record; /** Trusted issuer DIDs — only their attestations count. Empty = any. */ trustedIssuers: string[] | null; /** Current time (for tests). */ now: number; } export declare function createAttestation(opts: { subjectDid: string; issuerDid: string; issuerPublicKey: string; issuerSigningKey: Uint8Array; attestationType: AttestationType; weight: number; expiresAt?: number | null; evidence?: string | null; customLabel?: string | null; provider?: CryptoProvider; }): IdentityAttestation; export declare function verifyAttestation(at: IdentityAttestation, provider?: CryptoProvider): AttestationVerification; /** * Pluggable storage for attestations, with sybil-resistance scoring built-in. * Stateless over identity: query by subjectDid, filter by issuer. */ export declare class AttestationRegistry { private readonly bySubject; private readonly byId; private readonly revoked; private readonly provider; constructor(provider?: CryptoProvider); /** Add an attestation. Returns true if accepted, false if invalid or duplicate. */ add(at: IdentityAttestation): boolean; /** Mark an attestation as revoked. Revocation can come from the issuer. */ revoke(attestationId: string): boolean; /** Check if an attestation is currently valid (not revoked, not expired). */ isActive(attestationId: string, now?: number): boolean; /** Get all attestations for a subject (active + expired + revoked). */ getForSubject(subjectDid: string): readonly IdentityAttestation[]; /** Get only currently-active attestations for a subject. */ getActiveForSubject(subjectDid: string, now?: number): IdentityAttestation[]; /** Compute a subject's tier qualitatively. */ getTier(subjectDid: string, opts?: { trustedIssuers?: string[]; now?: number; }): IdentityTier; /** * Compute a quantitative reputation score with freshness decay. * Returns score + tier + metadata. */ getScore(subjectDid: string, config?: Partial): ReputationScore; /** Export all attestations for persistence. */ export(): IdentityAttestation[]; /** Import attestations (signatures re-verified). Returns count accepted. */ import(attestations: IdentityAttestation[]): number; /** Number of attestations stored (including revoked/expired). */ get size(): number; } //# sourceMappingURL=attestation.d.ts.map