import type { AithosAuth } from "./auth.js"; import type { AithosSdkEndpoints } from "./endpoints.js"; /** * The audience set scopes which consumers are eligible. `"open"` lets * any DID invoke the app; `"list"` restricts to an explicit allowlist. */ export type AudienceSet = "open" | "list"; export interface SponsorshipBudgetInput { /** * Authority-interpreted unit of account. Default `"aithos.mc"` (the * platform microcredit, ≈ €0.001 of AWS pass-through cost). Authorities * MAY accept other units — see draft §13.3.4. */ readonly unit?: string; /** Lifetime cap per consumer, in `unit`. */ readonly perUserCap: number; /** If set, the per-user cap applies over a sliding window. */ readonly perUserWindowSeconds?: number | null; /** UTC-day cap on total sponsored consumption across all consumers. */ readonly perDayTotalCap: number; /** Lifetime pool cap across all consumers. `null` ≡ no cap. */ readonly poolCapTotal?: number | null; } export interface SponsorshipAudienceInput { /** App DID the sponsorship covers (typically `sdk.appDid`). */ readonly appDid: string; readonly audienceSet: AudienceSet; /** Required iff `audienceSet === "list"`. */ readonly consumers?: readonly string[]; } export interface SponsorshipAccountingAuthorityInput { readonly did: string; readonly endpoint: string; } export interface CreateSponsorshipMandateArgs { readonly audience: SponsorshipAudienceInput; readonly scopes: readonly string[]; readonly allowedMethods: readonly string[]; readonly allowedModels?: readonly string[]; readonly budget: SponsorshipBudgetInput; readonly accountingAuthority: SponsorshipAccountingAuthorityInput; /** Defaults to now. */ readonly notBefore?: Date; /** Defaults to 365 days. */ readonly ttlSeconds?: number; } /** * Signed sponsorship mandate, ready to seed into the authority's * `aithos-app-sponsorships` table. Same shape as * `@aithos/protocol-core`'s `SponsorshipMandate`. */ export interface SignedSponsorshipMandate { readonly "aithos-sponsorship-mandate": "0.1.0"; readonly id: string; readonly issuer: string; readonly issued_by_key: string; readonly audience: { readonly app_did: string; readonly audience_set: AudienceSet; readonly consumers?: readonly string[]; }; readonly scopes: readonly string[]; readonly allowed_methods: readonly string[]; readonly allowed_models?: readonly string[]; readonly budget: { readonly unit: string; readonly per_user_cap: number; readonly per_user_window_seconds: number | null; readonly per_day_total_cap: number; readonly pool_cap_total: number | null; }; readonly accounting_authority: { readonly did: string; readonly endpoint: string; }; readonly not_before: string; readonly not_after: string; readonly issued_at: string; readonly nonce: string; readonly signature: { readonly alg: "ed25519"; readonly key: string; readonly value: string; }; } export interface SignedSponsorshipRevocation { readonly "aithos-revocation": "0.1.0"; readonly mandate_id: string; readonly mandate_kind: "sponsorship-mandate"; readonly issuer: string; readonly issued_by_key: string; readonly revoked_at: string; readonly reason: string; readonly signature: { readonly alg: "ed25519"; readonly key: string; readonly value: string; }; } export type AppCreditPackId = "app-credits-10k" | "app-credits-50k" | "app-credits-200k"; export interface CreateAppTopupSessionArgs { /** Which app-credits pack to purchase. */ readonly packId: AppCreditPackId; /** Where Stripe redirects after a successful payment. */ readonly successUrl: string; /** Where Stripe redirects if the user cancels. */ readonly cancelUrl: string; /** Abort signal to cancel the request. */ readonly signal?: AbortSignal; } export interface CreateAppTopupSessionResult { readonly checkoutUrl: string; readonly sessionId: string; } export interface AppsNamespaceDeps { readonly auth: AithosAuth; readonly appDid: string; readonly endpoints: AithosSdkEndpoints; readonly fetch: typeof fetch; } export declare class AppsNamespace { #private; constructor(deps: AppsNamespaceDeps); /** * Build and sign a `SponsorshipMandate` as the calling owner. The * returned JSON is signed by the owner's `#public` sphere key, ready * to be seeded into the authority's `aithos-app-sponsorships` table. * * V0.1 has no server endpoint — get the row into DDB via: * 1. `aws dynamodb put-item --table-name aithos-app-sponsorships * --item file://mandate.json` (raw), or * 2. The ops bootstrap script in * `innoesate/aithos/platform/scripts/seed-sponsorship.mjs` * (planned for V0.2). * * Hash with `sponsorshipMandateHash()` from `@aithos/protocol-core` * if you need to embed it in an envelope's `sponsorship.hash` field. */ createSponsorshipMandate(args: CreateSponsorshipMandateArgs): Promise; /** * Build and sign a §4.6 revocation document targeting a sponsorship * mandate. Same upload caveat as `createSponsorshipMandate`. */ revokeSponsorshipMandate(mandate: SignedSponsorshipMandate, reason: string): Promise; /** * Stripe Checkout session for an `app-credits-*` pack. The session is * bound to the calling owner's DID (which is treated as the app's * funding DID — Option A unified wallet, see plan §3.4). * * Same endpoint and auth pattern as `sdk.wallet.createTopupSession`, * just with the app-credits pack id family. */ createAppTopupSession(args: CreateAppTopupSessionArgs): Promise; /** * Build, sign, and PUBLISH a SponsorshipMandate to the authority's * `aithos-app-sponsorships` table via `aithos.sponsorship_create`. * * Combines local signing (see {@link createSponsorshipMandate}) with the * server upload step. After this resolves, the sponsorship is active — * the next `sdk.compute.invokeBedrock` call targeting `args.audience.appDid` * may be sponsored (subject to caps). * * Requires that the calling owner is the registered `owner_did` of * `args.audience.appDid` in `aithos-auth-apps`; otherwise the server * rejects with `-32042` "not the owner". */ publishSponsorship(args: CreateSponsorshipMandateArgs): Promise<{ mandate: SignedSponsorshipMandate; sponsorshipId: string; mandateHash: string; status: "active"; createdAt: number; }>; /** * Read the active sponsorship for an app. Open endpoint (no envelope * required): the mandate is publicly signed and resolvable anyway. * * Returns `{ exists: false }` when no row exists for the app. */ getSponsorship(args: { appDid: string; signal?: AbortSignal; }): Promise<{ exists: false; } | { exists: true; sponsorshipId: string; mandate: SignedSponsorshipMandate; mandateHash: string; status: "active" | "paused" | "depleted" | "expired" | "revoked"; poolConsumedLifetime: number; createdAt: number; lastUpdatedAt: number; }>; /** * Revoke a published sponsorship by `app_did` + `sponsorship_id`. The * row is marked `status: "revoked"` server-side; the routing cache is * invalidated so the next compute call falls back to the user wallet. */ revokeSponsorship(args: { appDid: string; sponsorshipId: string; reason: string; signal?: AbortSignal; }): Promise<{ status: "revoked"; }>; /** * Read the app's wallet balance (= the sponsor pool). Requires owner * signature. */ getAppWalletBalance(args: { appDid: string; signal?: AbortSignal; }): Promise<{ appDid: string; exists: boolean; balance: number; balancePurchase: number; balanceGrant: number; dailySpent: number; }>; } //# sourceMappingURL=apps.d.ts.map