@aithos/sdk 0.1.0-alpha.5 → 0.1.0-alpha.51
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.
- package/README.md +245 -7
- package/dist/src/apps.d.ts +224 -0
- package/dist/src/apps.js +432 -0
- package/dist/src/assets.d.ts +209 -0
- package/dist/src/assets.js +534 -0
- package/dist/src/auth-api.d.ts +219 -0
- package/dist/src/auth-api.js +248 -0
- package/dist/src/auth.d.ts +543 -0
- package/dist/src/auth.js +937 -31
- package/dist/src/compute.d.ts +464 -6
- package/dist/src/compute.js +746 -20
- package/dist/src/data-schema-contacts-v1.d.ts +14 -0
- package/dist/src/data-schema-contacts-v1.js +28 -0
- package/dist/src/data.d.ts +342 -0
- package/dist/src/data.js +1002 -0
- package/dist/src/endpoints.d.ts +25 -0
- package/dist/src/endpoints.js +7 -0
- package/dist/src/ethos.d.ts +85 -0
- package/dist/src/ethos.js +463 -7
- package/dist/src/index.d.ts +17 -6
- package/dist/src/index.js +25 -3
- package/dist/src/internal/delegate-bundle.js +7 -2
- package/dist/src/internal/envelope.d.ts +93 -0
- package/dist/src/internal/envelope.js +59 -0
- package/dist/src/mandates.d.ts +111 -2
- package/dist/src/mandates.js +150 -7
- package/dist/src/react/AithosAsset.d.ts +66 -0
- package/dist/src/react/AithosAsset.js +67 -0
- package/dist/src/react/context.d.ts +29 -0
- package/dist/src/react/context.js +31 -0
- package/dist/src/react/index.d.ts +29 -0
- package/dist/src/react/index.js +31 -0
- package/dist/src/react/use-aithos-asset.d.ts +39 -0
- package/dist/src/react/use-aithos-asset.js +118 -0
- package/dist/src/react/use-transcribe-pending.d.ts +21 -0
- package/dist/src/react/use-transcribe-pending.js +47 -0
- package/dist/src/sdk.d.ts +10 -0
- package/dist/src/sdk.js +22 -0
- package/dist/src/transcribe-resilience.d.ts +57 -0
- package/dist/src/transcribe-resilience.js +203 -0
- package/dist/src/web.d.ts +279 -0
- package/dist/src/web.js +186 -0
- package/dist/test/auth-j3.test.js +32 -1
- package/dist/test/canonical-conformance.test.d.ts +2 -0
- package/dist/test/canonical-conformance.test.js +86 -0
- package/dist/test/compute-delegate-path.test.d.ts +2 -0
- package/dist/test/compute-delegate-path.test.js +183 -0
- package/dist/test/compute.test.js +4 -0
- package/dist/test/endpoints.test.js +30 -1
- package/dist/test/envelope-core-conformance.test.d.ts +2 -0
- package/dist/test/envelope-core-conformance.test.js +75 -0
- package/dist/test/envelope.test.d.ts +2 -0
- package/dist/test/envelope.test.js +318 -0
- package/dist/test/ethos-first-edition.test.d.ts +2 -0
- package/dist/test/ethos-first-edition.test.js +371 -0
- package/dist/test/mandates-compute.test.d.ts +2 -0
- package/dist/test/mandates-compute.test.js +256 -0
- package/dist/test/sdk.test.js +11 -2
- package/dist/test/signup-bootstrap.test.d.ts +2 -0
- package/dist/test/signup-bootstrap.test.js +311 -0
- package/dist/test/transcribe-invoke.test.d.ts +2 -0
- package/dist/test/transcribe-invoke.test.js +204 -0
- package/dist/test/transcribe.test.d.ts +2 -0
- package/dist/test/transcribe.test.js +186 -0
- package/dist/test/web.test.d.ts +2 -0
- package/dist/test/web.test.js +270 -0
- package/package.json +20 -3
package/README.md
CHANGED
|
@@ -55,15 +55,253 @@ const reply = await sdk.compute.invokeBedrock({
|
|
|
55
55
|
console.log(reply.content);
|
|
56
56
|
```
|
|
57
57
|
|
|
58
|
+
## Transcribing audio → text
|
|
59
|
+
|
|
60
|
+
`sdk.compute.invokeTranscribe` turns an audio `Blob` into text through AWS
|
|
61
|
+
Transcribe. It does one thing — audio → text — and **stores nothing**: it
|
|
62
|
+
returns the transcript and you decide what to do with it (write it to an
|
|
63
|
+
ethos, a PDS, your own database, email it, or throw it away).
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
// Browser: a Blob from MediaRecorder; backend: a Blob from a Buffer.
|
|
67
|
+
const result = await sdk.compute.invokeTranscribe({
|
|
68
|
+
audio: blob, // Blob/File (Node 18+ has global Blob)
|
|
69
|
+
model: "transcribe:aws-fr-standard", // default; also aws-en-standard
|
|
70
|
+
languageCode: "fr-FR", // optional
|
|
71
|
+
// durationSecOverride: 127, // REQUIRED on backends (no DOM probe)
|
|
72
|
+
onProgress: (s) => console.log(s.phase), // uploading → starting → processing → completed
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
console.log(result.text); // "Bonjour, je voulais te dire que…"
|
|
76
|
+
console.log(result.segments); // [{ start_sec, end_sec, text }]
|
|
77
|
+
console.log(result.creditsCharged);
|
|
78
|
+
|
|
79
|
+
// Then YOU choose where it goes — the compute has no opinion:
|
|
80
|
+
await myEthos.addRevision(result.text); // or PDS, DB, email, nothing…
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
The core is isomorphic (Node + browser) and depends only on `Blob`, `fetch`
|
|
84
|
+
and timers. Browser-only resilience is opt-in and framework-agnostic:
|
|
85
|
+
`sdk.compute.transcribeDraft` (IndexedDB queue of recordings) and
|
|
86
|
+
`sdk.compute.listLocalPendingTranscribes()` /
|
|
87
|
+
`subscribeLocalPendingTranscribes()` / `resumeTranscribe(jobId)` recover jobs
|
|
88
|
+
across reloads. React users get `useAithosTranscribePendingJobs(sdk.compute)`
|
|
89
|
+
from `@aithos/sdk/react`. Advanced callers can drive the flow manually with
|
|
90
|
+
`prepareTranscribe` / `startTranscribe` / `getTranscribeStatus`.
|
|
91
|
+
|
|
92
|
+
## Delegating compute to an agent — opt-in token spending
|
|
93
|
+
|
|
94
|
+
To let an agent (or another user, or a third-party app) invoke Bedrock
|
|
95
|
+
**in your name**, with **your credits**, you mint a mandate. Token
|
|
96
|
+
spending is its own opt-in capability — passing it is a separate,
|
|
97
|
+
named, validated input that a consent UI can review. It is NEVER an
|
|
98
|
+
implicit side-effect of an ethos read/write scope.
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
// Mint a mandate that lets agent Bob read your public ethos AND
|
|
102
|
+
// spend up to 5 000 microcredits/day on Haiku, capped at 100 000
|
|
103
|
+
// microcredits over the whole mandate lifetime.
|
|
104
|
+
const mandate = await sdk.mandates.create({
|
|
105
|
+
granteeId: "urn:agent:bob",
|
|
106
|
+
scopes: ["ethos.read.public"],
|
|
107
|
+
ttlSeconds: 86_400,
|
|
108
|
+
compute: {
|
|
109
|
+
dailyCapMicrocredits: 5_000,
|
|
110
|
+
totalCapMicrocredits: 100_000,
|
|
111
|
+
maxCreditsPerCall: 500,
|
|
112
|
+
allowedModels: ["claude-haiku-4-5"],
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
// Hand `mandate.bundle` (a `.aithos-delegate.json` Blob) to Bob.
|
|
117
|
+
// He imports it, then signs his own envelopes and calls
|
|
118
|
+
// sdk.compute.invokeBedrock({ mandateId: mandate.mandateId, … })
|
|
119
|
+
// — every invocation debits *your* wallet, capped per the budget
|
|
120
|
+
// you set.
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Three invariants the SDK enforces synchronously, before reaching the
|
|
124
|
+
network — they fail fast with a precise `AithosSDKError`:
|
|
125
|
+
|
|
126
|
+
- **No smuggling.** Adding `"compute.invoke"` directly to `scopes[]`
|
|
127
|
+
throws `mandates_invalid_scopes`. The `compute` namespace is the
|
|
128
|
+
only path, so a UI reviewing `compute` can never be bypassed.
|
|
129
|
+
- **No bearer compute.** A `compute` namespace without at least one
|
|
130
|
+
of `dailyCapMicrocredits` or `totalCapMicrocredits` throws
|
|
131
|
+
`mandates_invalid_compute`. Unbounded compute mandates are forbidden
|
|
132
|
+
by construction.
|
|
133
|
+
- **Compute-only is fine.** `scopes: []` is allowed when `compute` is
|
|
134
|
+
set — useful for agents that only consume tokens (e.g. creative
|
|
135
|
+
assistants) without seeing any of your data.
|
|
136
|
+
|
|
137
|
+
## Custodial auth — onboarding users without a recovery file
|
|
138
|
+
|
|
139
|
+
Three new methods on `AithosAuth` let an app create and authenticate
|
|
140
|
+
its end-users via a server-managed custody flow — the user only needs
|
|
141
|
+
an email address and a password sent by mail. No recovery file, no
|
|
142
|
+
Google account, no client-side cryptography to handle.
|
|
143
|
+
|
|
144
|
+
The model is honest custody: Aithos KMS-wraps the user's Ed25519
|
|
145
|
+
identity seeds, and unwraps them on every sign-in after password
|
|
146
|
+
verification. Equivalent to how Coinbase or any hosted SaaS keeps your
|
|
147
|
+
private key. Annunciated to the user in the welcome email.
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
import { AithosSDK } from "@aithos/sdk";
|
|
151
|
+
|
|
152
|
+
// ─── Server-side: sign-up ───────────────────────────────────────────
|
|
153
|
+
// MUST run on your backend. The API key is a server secret —
|
|
154
|
+
// provisioned by Aithos via the operator runbook.
|
|
155
|
+
const sdk = new AithosSDK({ identity });
|
|
156
|
+
const result = await sdk.auth.signUpCustodial({
|
|
157
|
+
apiKey: process.env.AITHOS_API_KEY!,
|
|
158
|
+
email: "alice@example.com",
|
|
159
|
+
displayName: "Alice",
|
|
160
|
+
});
|
|
161
|
+
// → { userId, did, handle, email, mailSent }
|
|
162
|
+
// The user receives an email with their password and a sign-in link.
|
|
163
|
+
|
|
164
|
+
// ─── Browser-side: sign-in ──────────────────────────────────────────
|
|
165
|
+
// User pastes the password from their mail into your sign-in form,
|
|
166
|
+
// then your frontend calls this. No API key needed — the password
|
|
167
|
+
// is the credential.
|
|
168
|
+
const { session, passwordMustChange } = await sdk.auth.signInCustodial({
|
|
169
|
+
email: "alice@example.com",
|
|
170
|
+
password: "MyTempPass32chars",
|
|
171
|
+
});
|
|
172
|
+
// Local KeyStore is now hydrated with the 4 Ed25519 sphere seeds —
|
|
173
|
+
// the user can publish ethos editions, mint mandates, invoke compute,
|
|
174
|
+
// exactly as if they had signed in via a recovery file or Google SSO.
|
|
175
|
+
if (passwordMustChange) {
|
|
176
|
+
// Optional: nudge the user to set their own password via the
|
|
177
|
+
// standard reset flow.
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// ─── Browser-side: request password reset ───────────────────────────
|
|
181
|
+
// The backend always returns silently (anti-enumeration). If the email
|
|
182
|
+
// is registered AND in custodial mode AND not in cooldown AND under the
|
|
183
|
+
// daily cap, a magic-link email is sent to the address.
|
|
184
|
+
await sdk.auth.requestPasswordReset({ email: "alice@example.com" });
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
The reset finalization (collecting the new password from the user) is
|
|
188
|
+
done on a small web page hosted by Aithos at `https://app.aithos.be/reset`
|
|
189
|
+
(or your app's own `reset_base_url` if you've registered one — see the
|
|
190
|
+
operator runbook). The page POSTs to `/auth/custodial/reset/finalize`
|
|
191
|
+
and returns the user to your sign-in page on success.
|
|
192
|
+
|
|
193
|
+
### Getting an API key
|
|
194
|
+
|
|
195
|
+
API keys are provisioned out-of-band by Aithos. Contact the maintainer
|
|
196
|
+
(or use the self-service console at `aithos.be/console` when it ships
|
|
197
|
+
in V2). The pattern is `aithos_<env>_<32 chars b58>`. Keep it in your
|
|
198
|
+
backend's secrets manager — never in browser code.
|
|
199
|
+
|
|
200
|
+
### Trade-offs vs. the zk and Google SSO flows
|
|
201
|
+
|
|
202
|
+
| | zk (recovery file) | Google SSO (KMS) | **Custodial** |
|
|
203
|
+
|----------------|----------------------------|----------------------|---------------|
|
|
204
|
+
| User burden | downloads `recovery.json` | Google consent | email only |
|
|
205
|
+
| Password reset | requires recovery file | re-auth via Google | magic-link mail |
|
|
206
|
+
| Trust model | zero-knowledge (you only) | Aithos + Google | Aithos only |
|
|
207
|
+
| Multi-device | re-import recovery | re-Google | email + password |
|
|
208
|
+
| SDK signing capability | full | full | full |
|
|
209
|
+
|
|
210
|
+
Custodial is the right default for SDK-integrated apps that want
|
|
211
|
+
SaaS-grade UX. zk is the right default for power users who want
|
|
212
|
+
sovereign custody. SSO is the right default for users already invested
|
|
213
|
+
in the Google ecosystem.
|
|
214
|
+
|
|
215
|
+
## Extracting webpages without an LLM
|
|
216
|
+
|
|
217
|
+
`sdk.web` is a token-priced primitive that lets your agent read a
|
|
218
|
+
public webpage and get back cleaned HTML, purged CSS and a
|
|
219
|
+
deterministic visual signature — all computed server-side without an
|
|
220
|
+
LLM in the loop. Pricing is a flat **1 microcredit** per successful
|
|
221
|
+
extraction (refunded on failure), versus ~30 mc for a comparable
|
|
222
|
+
LLM-based extraction.
|
|
223
|
+
|
|
224
|
+
```ts
|
|
225
|
+
import { AithosSDK } from "@aithos/sdk";
|
|
226
|
+
|
|
227
|
+
const sdk = new AithosSDK({ auth, appDid });
|
|
228
|
+
|
|
229
|
+
const { data, creditsCharged } = await sdk.web.extract({
|
|
230
|
+
url: "https://example.com",
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
console.log(data.meta.title); // "Example Domain"
|
|
234
|
+
console.log(data.visual_signature.colors.primary); // "#0078d4"
|
|
235
|
+
console.log(data.styles.css.length); // purged + minified CSS
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
Owners can mint a mandate for delegate-only extraction:
|
|
239
|
+
|
|
240
|
+
```ts
|
|
241
|
+
import { WEB_EXTRACT_SCOPE } from "@aithos/sdk";
|
|
242
|
+
|
|
243
|
+
await sdk.mandates.create({
|
|
244
|
+
appDid: "did:aithos:app:my-agent",
|
|
245
|
+
scopes: [WEB_EXTRACT_SCOPE],
|
|
246
|
+
// ...
|
|
247
|
+
});
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
## Calling a third-party Aithos-aware backend
|
|
251
|
+
|
|
252
|
+
If your app talks to its own backend (a service you built that verifies
|
|
253
|
+
Aithos envelopes per spec §11.2 using
|
|
254
|
+
`@aithos/protocol-core/envelope`), use `sdk.auth.signEnvelope` to sign
|
|
255
|
+
the request with the same primitive that SDK namespaces use internally
|
|
256
|
+
for `api.aithos.be`. No JWT, no shadow session — the user's DID in the
|
|
257
|
+
envelope's `iss` field is the identity.
|
|
258
|
+
|
|
259
|
+
```ts
|
|
260
|
+
import { AithosSDK, type SignedEnvelope } from "@aithos/sdk";
|
|
261
|
+
|
|
262
|
+
// Sign a request to your own backend with the active owner's
|
|
263
|
+
// public-sphere key. Default TTL is 60 s.
|
|
264
|
+
const envelope: SignedEnvelope = await sdk.auth.signEnvelope({
|
|
265
|
+
aud: "https://api.example.com/v1/widgets",
|
|
266
|
+
method: "myapp.widgets.create",
|
|
267
|
+
params: { name: "Widget #1" },
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
await fetch("https://api.example.com/v1/widgets", {
|
|
271
|
+
method: "POST",
|
|
272
|
+
headers: { "content-type": "application/json" },
|
|
273
|
+
body: JSON.stringify({
|
|
274
|
+
jsonrpc: "2.0",
|
|
275
|
+
id: crypto.randomUUID(),
|
|
276
|
+
method: "myapp.widgets.create",
|
|
277
|
+
params: { name: "Widget #1", _envelope: envelope },
|
|
278
|
+
}),
|
|
279
|
+
});
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
The envelope binds the signature to `(iss, aud, method, params_hash,
|
|
283
|
+
nonce, iat, exp)`, so a single envelope cannot be replayed against a
|
|
284
|
+
different endpoint, method, or payload. Throws
|
|
285
|
+
`AithosSDKError("auth_not_signed_in")` if no owner is loaded; throws
|
|
286
|
+
`AithosSDKError("auth_invalid_sphere")` if you pass a sphere outside
|
|
287
|
+
`"root" | "public" | "circle" | "self"` (default is `"public"`).
|
|
288
|
+
|
|
289
|
+
Server-side, your backend verifies the envelope with
|
|
290
|
+
`@aithos/protocol-core`'s `verifyEnvelope` (the 9-step check from spec
|
|
291
|
+
§11.4) — same algorithm that `api.aithos.be` uses, no re-implementation
|
|
292
|
+
needed.
|
|
293
|
+
|
|
58
294
|
## What lives where
|
|
59
295
|
|
|
60
|
-
| Namespace
|
|
61
|
-
|
|
|
62
|
-
| `sdk.
|
|
63
|
-
| `sdk.
|
|
64
|
-
| `sdk.
|
|
65
|
-
| `sdk.
|
|
66
|
-
| `sdk.
|
|
296
|
+
| Namespace | Purpose |
|
|
297
|
+
| -------------------------- | ------------------------------------------------------------------------------------------ |
|
|
298
|
+
| `sdk.auth` | Sign-in, sign-up, key custody — and `signEnvelope` for calls to your own Aithos-aware backend. |
|
|
299
|
+
| `sdk.compute` | Bedrock invocation through the Aithos compute proxy (signed envelope, wallet enforcement). |
|
|
300
|
+
| `sdk.web` | Webpage extraction without an LLM through the web extractor proxy (1 mc / call). |
|
|
301
|
+
| `sdk.wallet` | Stripe Checkout sessions for credit-pack top-ups, balance helpers. |
|
|
302
|
+
| `sdk.ethos` | Ethos-zone composition / parsing — re-exported from `@aithos/protocol-client`. |
|
|
303
|
+
| `sdk.onboarding` | First-run identity / DID flows — re-exported. |
|
|
304
|
+
| `sdk.mandates` | Mint / verify mandates — re-exported. |
|
|
67
305
|
|
|
68
306
|
## License
|
|
69
307
|
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import type { AithosAuth } from "./auth.js";
|
|
2
|
+
import type { AithosSdkEndpoints } from "./endpoints.js";
|
|
3
|
+
/**
|
|
4
|
+
* The audience set scopes which consumers are eligible. `"open"` lets
|
|
5
|
+
* any DID invoke the app; `"list"` restricts to an explicit allowlist.
|
|
6
|
+
*/
|
|
7
|
+
export type AudienceSet = "open" | "list";
|
|
8
|
+
export interface SponsorshipBudgetInput {
|
|
9
|
+
/**
|
|
10
|
+
* Authority-interpreted unit of account. Default `"aithos.mc"` (the
|
|
11
|
+
* platform microcredit, ≈ €0.001 of AWS pass-through cost). Authorities
|
|
12
|
+
* MAY accept other units — see draft §13.3.4.
|
|
13
|
+
*/
|
|
14
|
+
readonly unit?: string;
|
|
15
|
+
/** Lifetime cap per consumer, in `unit`. */
|
|
16
|
+
readonly perUserCap: number;
|
|
17
|
+
/** If set, the per-user cap applies over a sliding window. */
|
|
18
|
+
readonly perUserWindowSeconds?: number | null;
|
|
19
|
+
/** UTC-day cap on total sponsored consumption across all consumers. */
|
|
20
|
+
readonly perDayTotalCap: number;
|
|
21
|
+
/** Lifetime pool cap across all consumers. `null` ≡ no cap. */
|
|
22
|
+
readonly poolCapTotal?: number | null;
|
|
23
|
+
}
|
|
24
|
+
export interface SponsorshipAudienceInput {
|
|
25
|
+
/** App DID the sponsorship covers (typically `sdk.appDid`). */
|
|
26
|
+
readonly appDid: string;
|
|
27
|
+
readonly audienceSet: AudienceSet;
|
|
28
|
+
/** Required iff `audienceSet === "list"`. */
|
|
29
|
+
readonly consumers?: readonly string[];
|
|
30
|
+
}
|
|
31
|
+
export interface SponsorshipAccountingAuthorityInput {
|
|
32
|
+
readonly did: string;
|
|
33
|
+
readonly endpoint: string;
|
|
34
|
+
}
|
|
35
|
+
export interface CreateSponsorshipMandateArgs {
|
|
36
|
+
readonly audience: SponsorshipAudienceInput;
|
|
37
|
+
readonly scopes: readonly string[];
|
|
38
|
+
readonly allowedMethods: readonly string[];
|
|
39
|
+
readonly allowedModels?: readonly string[];
|
|
40
|
+
readonly budget: SponsorshipBudgetInput;
|
|
41
|
+
readonly accountingAuthority: SponsorshipAccountingAuthorityInput;
|
|
42
|
+
/** Defaults to now. */
|
|
43
|
+
readonly notBefore?: Date;
|
|
44
|
+
/** Defaults to 365 days. */
|
|
45
|
+
readonly ttlSeconds?: number;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Signed sponsorship mandate, ready to seed into the authority's
|
|
49
|
+
* `aithos-app-sponsorships` table. Same shape as
|
|
50
|
+
* `@aithos/protocol-core`'s `SponsorshipMandate`.
|
|
51
|
+
*/
|
|
52
|
+
export interface SignedSponsorshipMandate {
|
|
53
|
+
readonly "aithos-sponsorship-mandate": "0.1.0";
|
|
54
|
+
readonly id: string;
|
|
55
|
+
readonly issuer: string;
|
|
56
|
+
readonly issued_by_key: string;
|
|
57
|
+
readonly audience: {
|
|
58
|
+
readonly app_did: string;
|
|
59
|
+
readonly audience_set: AudienceSet;
|
|
60
|
+
readonly consumers?: readonly string[];
|
|
61
|
+
};
|
|
62
|
+
readonly scopes: readonly string[];
|
|
63
|
+
readonly allowed_methods: readonly string[];
|
|
64
|
+
readonly allowed_models?: readonly string[];
|
|
65
|
+
readonly budget: {
|
|
66
|
+
readonly unit: string;
|
|
67
|
+
readonly per_user_cap: number;
|
|
68
|
+
readonly per_user_window_seconds: number | null;
|
|
69
|
+
readonly per_day_total_cap: number;
|
|
70
|
+
readonly pool_cap_total: number | null;
|
|
71
|
+
};
|
|
72
|
+
readonly accounting_authority: {
|
|
73
|
+
readonly did: string;
|
|
74
|
+
readonly endpoint: string;
|
|
75
|
+
};
|
|
76
|
+
readonly not_before: string;
|
|
77
|
+
readonly not_after: string;
|
|
78
|
+
readonly issued_at: string;
|
|
79
|
+
readonly nonce: string;
|
|
80
|
+
readonly signature: {
|
|
81
|
+
readonly alg: "ed25519";
|
|
82
|
+
readonly key: string;
|
|
83
|
+
readonly value: string;
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
export interface SignedSponsorshipRevocation {
|
|
87
|
+
readonly "aithos-revocation": "0.1.0";
|
|
88
|
+
readonly mandate_id: string;
|
|
89
|
+
readonly mandate_kind: "sponsorship-mandate";
|
|
90
|
+
readonly issuer: string;
|
|
91
|
+
readonly issued_by_key: string;
|
|
92
|
+
readonly revoked_at: string;
|
|
93
|
+
readonly reason: string;
|
|
94
|
+
readonly signature: {
|
|
95
|
+
readonly alg: "ed25519";
|
|
96
|
+
readonly key: string;
|
|
97
|
+
readonly value: string;
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
export type AppCreditPackId = "app-credits-10k" | "app-credits-50k" | "app-credits-200k";
|
|
101
|
+
export interface CreateAppTopupSessionArgs {
|
|
102
|
+
/** Which app-credits pack to purchase. */
|
|
103
|
+
readonly packId: AppCreditPackId;
|
|
104
|
+
/** Where Stripe redirects after a successful payment. */
|
|
105
|
+
readonly successUrl: string;
|
|
106
|
+
/** Where Stripe redirects if the user cancels. */
|
|
107
|
+
readonly cancelUrl: string;
|
|
108
|
+
/** Abort signal to cancel the request. */
|
|
109
|
+
readonly signal?: AbortSignal;
|
|
110
|
+
}
|
|
111
|
+
export interface CreateAppTopupSessionResult {
|
|
112
|
+
readonly checkoutUrl: string;
|
|
113
|
+
readonly sessionId: string;
|
|
114
|
+
}
|
|
115
|
+
export interface AppsNamespaceDeps {
|
|
116
|
+
readonly auth: AithosAuth;
|
|
117
|
+
readonly appDid: string;
|
|
118
|
+
readonly endpoints: AithosSdkEndpoints;
|
|
119
|
+
readonly fetch: typeof fetch;
|
|
120
|
+
}
|
|
121
|
+
export declare class AppsNamespace {
|
|
122
|
+
#private;
|
|
123
|
+
constructor(deps: AppsNamespaceDeps);
|
|
124
|
+
/**
|
|
125
|
+
* Build and sign a `SponsorshipMandate` as the calling owner. The
|
|
126
|
+
* returned JSON is signed by the owner's `#public` sphere key, ready
|
|
127
|
+
* to be seeded into the authority's `aithos-app-sponsorships` table.
|
|
128
|
+
*
|
|
129
|
+
* V0.1 has no server endpoint — get the row into DDB via:
|
|
130
|
+
* 1. `aws dynamodb put-item --table-name aithos-app-sponsorships
|
|
131
|
+
* --item file://mandate.json` (raw), or
|
|
132
|
+
* 2. The ops bootstrap script in
|
|
133
|
+
* `innoesate/aithos/platform/scripts/seed-sponsorship.mjs`
|
|
134
|
+
* (planned for V0.2).
|
|
135
|
+
*
|
|
136
|
+
* Hash with `sponsorshipMandateHash()` from `@aithos/protocol-core`
|
|
137
|
+
* if you need to embed it in an envelope's `sponsorship.hash` field.
|
|
138
|
+
*/
|
|
139
|
+
createSponsorshipMandate(args: CreateSponsorshipMandateArgs): Promise<SignedSponsorshipMandate>;
|
|
140
|
+
/**
|
|
141
|
+
* Build and sign a §4.6 revocation document targeting a sponsorship
|
|
142
|
+
* mandate. Same upload caveat as `createSponsorshipMandate`.
|
|
143
|
+
*/
|
|
144
|
+
revokeSponsorshipMandate(mandate: SignedSponsorshipMandate, reason: string): Promise<SignedSponsorshipRevocation>;
|
|
145
|
+
/**
|
|
146
|
+
* Stripe Checkout session for an `app-credits-*` pack. The session is
|
|
147
|
+
* bound to the calling owner's DID (which is treated as the app's
|
|
148
|
+
* funding DID — Option A unified wallet, see plan §3.4).
|
|
149
|
+
*
|
|
150
|
+
* Same endpoint and auth pattern as `sdk.wallet.createTopupSession`,
|
|
151
|
+
* just with the app-credits pack id family.
|
|
152
|
+
*/
|
|
153
|
+
createAppTopupSession(args: CreateAppTopupSessionArgs): Promise<CreateAppTopupSessionResult>;
|
|
154
|
+
/**
|
|
155
|
+
* Build, sign, and PUBLISH a SponsorshipMandate to the authority's
|
|
156
|
+
* `aithos-app-sponsorships` table via `aithos.sponsorship_create`.
|
|
157
|
+
*
|
|
158
|
+
* Combines local signing (see {@link createSponsorshipMandate}) with the
|
|
159
|
+
* server upload step. After this resolves, the sponsorship is active —
|
|
160
|
+
* the next `sdk.compute.invokeBedrock` call targeting `args.audience.appDid`
|
|
161
|
+
* may be sponsored (subject to caps).
|
|
162
|
+
*
|
|
163
|
+
* Requires that the calling owner is the registered `owner_did` of
|
|
164
|
+
* `args.audience.appDid` in `aithos-auth-apps`; otherwise the server
|
|
165
|
+
* rejects with `-32042` "not the owner".
|
|
166
|
+
*/
|
|
167
|
+
publishSponsorship(args: CreateSponsorshipMandateArgs): Promise<{
|
|
168
|
+
mandate: SignedSponsorshipMandate;
|
|
169
|
+
sponsorshipId: string;
|
|
170
|
+
mandateHash: string;
|
|
171
|
+
status: "active";
|
|
172
|
+
createdAt: number;
|
|
173
|
+
}>;
|
|
174
|
+
/**
|
|
175
|
+
* Read the active sponsorship for an app. Open endpoint (no envelope
|
|
176
|
+
* required): the mandate is publicly signed and resolvable anyway.
|
|
177
|
+
*
|
|
178
|
+
* Returns `{ exists: false }` when no row exists for the app.
|
|
179
|
+
*/
|
|
180
|
+
getSponsorship(args: {
|
|
181
|
+
appDid: string;
|
|
182
|
+
signal?: AbortSignal;
|
|
183
|
+
}): Promise<{
|
|
184
|
+
exists: false;
|
|
185
|
+
} | {
|
|
186
|
+
exists: true;
|
|
187
|
+
sponsorshipId: string;
|
|
188
|
+
mandate: SignedSponsorshipMandate;
|
|
189
|
+
mandateHash: string;
|
|
190
|
+
status: "active" | "paused" | "depleted" | "expired" | "revoked";
|
|
191
|
+
poolConsumedLifetime: number;
|
|
192
|
+
createdAt: number;
|
|
193
|
+
lastUpdatedAt: number;
|
|
194
|
+
}>;
|
|
195
|
+
/**
|
|
196
|
+
* Revoke a published sponsorship by `app_did` + `sponsorship_id`. The
|
|
197
|
+
* row is marked `status: "revoked"` server-side; the routing cache is
|
|
198
|
+
* invalidated so the next compute call falls back to the user wallet.
|
|
199
|
+
*/
|
|
200
|
+
revokeSponsorship(args: {
|
|
201
|
+
appDid: string;
|
|
202
|
+
sponsorshipId: string;
|
|
203
|
+
reason: string;
|
|
204
|
+
signal?: AbortSignal;
|
|
205
|
+
}): Promise<{
|
|
206
|
+
status: "revoked";
|
|
207
|
+
}>;
|
|
208
|
+
/**
|
|
209
|
+
* Read the app's wallet balance (= the sponsor pool). Requires owner
|
|
210
|
+
* signature.
|
|
211
|
+
*/
|
|
212
|
+
getAppWalletBalance(args: {
|
|
213
|
+
appDid: string;
|
|
214
|
+
signal?: AbortSignal;
|
|
215
|
+
}): Promise<{
|
|
216
|
+
appDid: string;
|
|
217
|
+
exists: boolean;
|
|
218
|
+
balance: number;
|
|
219
|
+
balancePurchase: number;
|
|
220
|
+
balanceGrant: number;
|
|
221
|
+
dailySpent: number;
|
|
222
|
+
}>;
|
|
223
|
+
}
|
|
224
|
+
//# sourceMappingURL=apps.d.ts.map
|