import { ErrorObject } from 'ajv/dist/ajv.js';

declare const POLICY_SCHEMA_VERSION: "oasg.policy.v1";
declare const REQUEST_SCHEMA_VERSION: "oasg.request.v1";
declare const DECISION_SCHEMA_VERSION: "oasg.decision.v1";
declare const EVIDENCE_SCHEMA_VERSION: "oasg.evidence.v1";
type AtomicAmount = string;
type DecisionOutcome = 'allow' | 'block' | 'approval_required';
interface PeriodBudget {
    period: 'day';
    limit: AtomicAmount;
}
interface AssetRule {
    assetId: string;
    maxPerTransaction: AtomicAmount;
    approvalRequiredAbove?: AtomicAmount;
    periodBudget?: PeriodBudget;
}
interface SpendPolicy {
    schemaVersion: typeof POLICY_SCHEMA_VERSION;
    policyId: string;
    version: number;
    name?: string;
    rules: {
        allowedChains: string[];
        assets: AssetRule[];
        allowedCounterparties?: string[];
        allowedPurposes?: string[];
    };
}
interface RequestSource {
    type: string;
    reference?: string;
    rawHash?: string;
    metadata?: Record<string, string | number | boolean | null>;
}
interface SpendRequest {
    schemaVersion: typeof REQUEST_SCHEMA_VERSION;
    requestId: string;
    agentId: string;
    chainId: string;
    assetId: string;
    amount: AtomicAmount;
    counterparty: string;
    purpose: string;
    observedAt: string;
    spentInPeriod?: AtomicAmount;
    source?: RequestSource;
}
type ReasonCode = 'chain.not_allowed' | 'asset.chain_mismatch' | 'asset.not_allowed' | 'counterparty.not_allowed' | 'purpose.not_allowed' | 'amount.max_transaction' | 'budget.snapshot_required' | 'budget.period_limit' | 'approval.threshold' | 'policy.allow';
interface SpendDecision {
    schemaVersion: typeof DECISION_SCHEMA_VERSION;
    decisionId: string;
    outcome: DecisionOutcome;
    reasonCode: ReasonCode;
    explanation: string;
    matchedRule: string;
    policy: {
        policyId: string;
        version: number;
        hash: string;
    };
    request: {
        requestId: string;
        hash: string;
    };
    facts: {
        chainId: string;
        assetId: string;
        amount: AtomicAmount;
        counterparty: string;
        purpose: string;
        spentInPeriod?: AtomicAmount;
        projectedPeriodSpend?: AtomicAmount;
    };
    evaluatedAt: string;
}
interface EvidencePackage {
    schemaVersion: typeof EVIDENCE_SCHEMA_VERSION;
    packageId: string;
    createdAt: string;
    policy: SpendPolicy;
    request: SpendRequest;
    decision: SpendDecision;
}
interface X402PaymentRequirementV2 {
    scheme: string;
    network: string;
    asset: string;
    amount: string;
    payTo: string;
    maxTimeoutSeconds: number;
    extra?: Record<string, unknown>;
}
interface X402PaymentRequiredV2 {
    x402Version: 2;
    error?: string;
    resource: {
        url: string;
        description?: string;
        mimeType?: string;
        serviceName?: string;
        tags?: string[];
        iconUrl?: string;
    };
    accepts: X402PaymentRequirementV2[];
    extensions?: Record<string, unknown>;
}
interface SafeMultisigTransaction {
    safe: string;
    to: string;
    value: string;
    data?: string | null;
    operation: number;
    safeTxGas: string;
    baseGas: string;
    gasPrice: string;
    gasToken: string;
    refundReceiver?: string | null;
    nonce: number | string;
    safeTxHash?: string;
    transactionHash?: string | null;
    submissionDate?: string;
    isExecuted?: boolean;
    confirmationsRequired?: number;
    confirmations?: unknown[];
}

declare class OasgError extends Error {
    readonly code: string;
    readonly details?: unknown;
    constructor(code: string, message: string, details?: unknown);
}
declare class ValidationError extends OasgError {
    constructor(subject: 'policy' | 'request' | 'decision' | 'evidence' | 'x402' | 'safe', details: unknown);
}

declare function canonicalJson(value: unknown): string;
declare function sha256(value: unknown): string;

declare function assertPolicy(value: unknown): asserts value is SpendPolicy;
declare function assertRequest(value: unknown): asserts value is SpendRequest;
declare function assertDecision(value: unknown): asserts value is SpendDecision;
declare function assertEvidence(value: unknown): asserts value is EvidencePackage;
declare function validationResult(kind: 'policy' | 'request' | 'decision' | 'evidence', value: unknown): {
    valid: boolean;
    errors: ErrorObject[];
};

declare function evaluate(policyInput: unknown, requestInput: unknown): SpendDecision;

declare function createEvidencePackage(policyInput: unknown, requestInput: unknown): EvidencePackage;

interface X402AdapterOptions {
    agentId: string;
    observedAt: string;
    purpose?: string;
    requestId?: string;
    acceptIndex?: number;
    spentInPeriod?: string;
}
declare function normalizeX402PaymentRequired(value: unknown, options: X402AdapterOptions): SpendRequest;

interface SafeAdapterOptions {
    agentId: string;
    chainId: string;
    assetId: string;
    observedAt?: string;
    purpose?: string;
    requestId?: string;
    spentInPeriod?: string;
}
declare function normalizeSafeMultisigTransaction(value: unknown, options: SafeAdapterOptions): SpendRequest;

export { type AssetRule, type AtomicAmount, DECISION_SCHEMA_VERSION, type DecisionOutcome, EVIDENCE_SCHEMA_VERSION, type EvidencePackage, OasgError, POLICY_SCHEMA_VERSION, type PeriodBudget, REQUEST_SCHEMA_VERSION, type ReasonCode, type RequestSource, type SafeAdapterOptions, type SafeMultisigTransaction, type SpendDecision, type SpendPolicy, type SpendRequest, ValidationError, type X402AdapterOptions, type X402PaymentRequiredV2, type X402PaymentRequirementV2, assertDecision, assertEvidence, assertPolicy, assertRequest, canonicalJson, createEvidencePackage, evaluate, normalizeSafeMultisigTransaction, normalizeX402PaymentRequired, sha256, validationResult };
