// Type definitions for agent-escrow export interface Task { eventId: string; taskId: string; poster: string; title: string; description: string; budget: number; deadline: number | null; status: TaskStatus; capabilities: string[]; minTrust: number | null; lightningAddress: string | null; worker: string | null; createdAt: number; raw: NostrEvent; } export interface Bid { eventId: string; bidder: string; taskEventId: string; posterPubkey: string; amount: number; lightningAddress: string; eta: number | null; message: string; createdAt: number; raw: NostrEvent; } export interface Delivery { eventId: string; worker: string; taskEventId: string; posterPubkey: string; result: string; hash: string | null; createdAt: number; raw: NostrEvent; } export interface Resolution { eventId: string; poster: string; taskEventId: string; workerPubkey: string; type: ResolutionType; paymentBolt11: string | null; preimage: string | null; message: string; createdAt: number; raw: NostrEvent; } export interface NostrEvent { id: string; pubkey: string; kind: number; created_at: number; tags: string[][]; content: string; sig: string; } export type TaskStatus = 'open' | 'claimed' | 'delivered' | 'completed' | 'cancelled' | 'disputed' | 'expired'; export type ResolutionType = 'approve' | 'reject' | 'dispute'; export interface MarketplaceOptions { relays?: string[]; secretKey: string | Uint8Array; nwcUrl?: string; lightningAddress?: string; defaultMinTrust?: number; connectTimeoutMs?: number; } export interface PostTaskOptions { title: string; description?: string; budget: number; deadline?: number; capabilities?: string[]; minTrust?: number; lightningAddress?: string; taskId?: string; } export interface BrowseOptions { status?: TaskStatus | TaskStatus[]; capabilities?: string | string[]; poster?: string | string[]; minBudget?: number; maxBudget?: number; limit?: number; since?: number; timeoutMs?: number; } export interface SubmitBidOptions { taskEventId: string; posterPubkey: string; amount: number; lightningAddress?: string; eta?: number; message?: string; } export interface DeliverOptions { taskEventId: string; posterPubkey: string; result: string; includeHash?: boolean; } export interface ApproveOptions { taskId: string; workerPubkey: string; workerLightningAddress?: string; amount: number; message?: string; } export interface DisputeOptions { taskId: string; workerPubkey: string; reason: string; } export interface ApproveResult { resolution: Resolution; payment: { bolt11?: string; preimage?: string; amountSats: number; error?: string; manual?: boolean }; task: Task; } export interface DisputeResult { resolution: Resolution; task: Task; } export interface DeliveryVerification { valid: boolean; reason?: string; expected?: string; actual?: string; } export function createMarketplace(opts: MarketplaceOptions): Marketplace; export const KINDS: { TASK: 30950; BID: 950; DELIVERY: 951; RESOLUTION: 952; }; export const TASK_STATUS: { OPEN: 'open'; CLAIMED: 'claimed'; DELIVERED: 'delivered'; COMPLETED: 'completed'; CANCELLED: 'cancelled'; DISPUTED: 'disputed'; EXPIRED: 'expired'; }; export const RESOLUTION_TYPES: { APPROVE: 'approve'; REJECT: 'reject'; DISPUTE: 'dispute'; }; export function createTaskEvent(opts: PostTaskOptions): object; export function createBidEvent(opts: SubmitBidOptions & { lightningAddress: string }): object; export function createDeliveryEvent(opts: DeliverOptions): object; export function createResolutionEvent(opts: { taskEventId: string; workerPubkey: string; type: ResolutionType; paymentBolt11?: string; preimage?: string; message?: string }): object; export function parseTask(event: NostrEvent): Task; export function parseBid(event: NostrEvent): Bid; export function parseDelivery(event: NostrEvent): Delivery; export function parseResolution(event: NostrEvent): Resolution; export function findTasks(relays: any[], opts?: BrowseOptions): Promise; export function findBids(relays: any[], taskEventId: string): Promise; export function findDeliveries(relays: any[], taskEventId: string): Promise; export function findResolutions(relays: any[], taskEventId: string): Promise; export function getTask(relays: any[], posterPubkey: string, taskId: string): Promise; export function verifyDelivery(delivery: Delivery): DeliveryVerification; export function trustAvailable(): boolean; export function getTrustScore(pubkey: string, opts?: { relays?: string[] }): Promise; export function meetsTrustThreshold(pubkey: string, minScore: number, opts?: { relays?: string[] }): Promise; export function paymentsAvailable(): boolean; // Arbitration types export type RulingType = 'favor-poster' | 'favor-worker' | 'partial' | 'dismiss'; export interface Dispute { eventId: string; disputant: string; taskEventId: string; deliveryEventId: string | null; reason: string; evidence: string[]; proposedArbitrators: string[]; createdAt: number; raw: NostrEvent; } export interface Ruling { eventId: string; arbitrator: string; disputeEventId: string; taskEventId: string; posterPubkey: string; workerPubkey: string; ruling: RulingType; rationale: string; paymentSplit: { poster: number; worker: number } | null; trustAdjustments: any; createdAt: number; raw: NostrEvent; } export interface OpenDisputeOptions { taskId: string; deliveryEventId?: string; reason: string; evidence?: string[]; proposedArbitrators?: string[]; } export interface SubmitEvidenceOptions { disputeEventId: string; taskId: string; description: string; urls?: string[]; hashes?: string[]; } export interface AcceptArbitrationOptions { disputeEventId: string; taskId: string; posterPubkey: string; workerPubkey: string; fee?: number; estimatedHours?: number; } export interface IssueRulingOptions { disputeEventId: string; taskId: string; posterPubkey: string; workerPubkey: string; ruling: RulingType; rationale: string; paymentSplit?: { poster: number; worker: number }; publishAttestations?: boolean; } export interface TrustAdjustments { poster: { attestation: 'positive' | 'negative' | 'warning' | null; type: string | null }; worker: { attestation: 'positive' | 'negative' | 'warning' | null; type: string | null }; } export interface OpenDisputeResult { dispute: Dispute; task: Task; } // Extend Marketplace interface with arbitration methods export interface Marketplace { pubkey: string; postTask(opts: PostTaskOptions): Promise; cancelTask(taskId: string): Promise; browseTasks(opts?: BrowseOptions): Promise; fetchTask(posterPubkey: string, taskId: string): Promise; myTasks(opts?: { status?: TaskStatus | TaskStatus[]; limit?: number; timeoutMs?: number }): Promise; myJobs(opts?: { status?: TaskStatus | TaskStatus[]; limit?: number; timeoutMs?: number }): Promise; submitBid(opts: SubmitBidOptions): Promise; getBids(taskEventId: string): Promise; myBids(opts?: { limit?: number; since?: number; timeoutMs?: number }): Promise; acceptBid(taskId: string, bid: Bid): Promise; deliver(opts: DeliverOptions): Promise; getDeliveries(taskEventId: string): Promise; approve(opts: ApproveOptions): Promise; dispute(opts: DisputeOptions): Promise; // Arbitration openDispute(opts: OpenDisputeOptions): Promise; submitEvidence(opts: SubmitEvidenceOptions): Promise; acceptArbitration(opts: AcceptArbitrationOptions): Promise; issueRuling(opts: IssueRulingOptions): Promise; getDisputes(taskId: string): Promise; getRulings(disputeEventId: string): Promise; close(): Promise; } export const ARBITRATION_KINDS: { DISPUTE_OPEN: 953; EVIDENCE: 954; ARBITRATOR_ACCEPT: 955; RULING: 956; }; export const RULING_TYPES: { FAVOR_POSTER: 'favor-poster'; FAVOR_WORKER: 'favor-worker'; PARTIAL: 'partial'; DISMISS: 'dismiss'; }; export function createDisputeEvent(opts: { taskEventId: string; deliveryEventId?: string; reason: string; evidence?: string[]; proposedArbitrators?: string[] }): object; export function createEvidenceEvent(opts: { disputeEventId: string; taskEventId: string; description: string; evidenceUrls?: string[]; evidenceHashes?: string[] }): object; export function createArbitratorAcceptEvent(opts: AcceptArbitrationOptions): object; export function createRulingEvent(opts: IssueRulingOptions & { trustAdjustments?: TrustAdjustments }): object; export function parseDispute(event: NostrEvent): Dispute; export function parseRuling(event: NostrEvent): Ruling; export function findDisputes(relays: any[], taskEventId: string, timeoutMs?: number): Promise; export function findRulings(relays: any[], disputeEventId: string, timeoutMs?: number): Promise; export function findEvidence(relays: any[], disputeEventId: string, timeoutMs?: number): Promise; export function calculateTrustAdjustments(ruling: RulingType, context?: { posterHistory?: number; workerHistory?: number }): TrustAdjustments;