@aithos/sdk 0.1.0-alpha.4 → 0.1.0-alpha.41
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 +211 -7
- package/dist/src/apps.d.ts +155 -0
- package/dist/src/apps.js +288 -0
- package/dist/src/assets.d.ts +207 -0
- package/dist/src/assets.js +533 -0
- package/dist/src/auth-api.d.ts +138 -0
- package/dist/src/auth-api.js +168 -0
- package/dist/src/auth.d.ts +536 -119
- package/dist/src/auth.js +1207 -152
- package/dist/src/compute.d.ts +251 -9
- package/dist/src/compute.js +293 -16
- 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 +153 -0
- package/dist/src/data.js +670 -0
- package/dist/src/endpoints.d.ts +9 -0
- package/dist/src/endpoints.js +5 -0
- package/dist/src/ethos.d.ts +202 -1
- package/dist/src/ethos.js +821 -16
- package/dist/src/index.d.ts +18 -6
- package/dist/src/index.js +39 -6
- package/dist/src/internal/delegate-bundle.d.ts +18 -0
- package/dist/src/internal/delegate-bundle.js +94 -0
- package/dist/src/internal/delegate-state.d.ts +45 -0
- package/dist/src/internal/delegate-state.js +120 -0
- package/dist/src/internal/envelope.d.ts +77 -0
- package/dist/src/internal/envelope.js +154 -0
- package/dist/src/internal/owner-signers.d.ts +78 -0
- package/dist/src/internal/owner-signers.js +179 -0
- package/dist/src/internal/protocol-client-bridge.d.ts +8 -0
- package/dist/src/internal/protocol-client-bridge.js +20 -0
- package/dist/src/internal/recovery-file.d.ts +29 -0
- package/dist/src/internal/recovery-file.js +98 -0
- package/dist/src/internal/signer.d.ts +59 -0
- package/dist/src/internal/signer.js +86 -0
- package/dist/src/key-store.d.ts +128 -0
- package/dist/src/key-store.js +244 -0
- package/dist/src/mandates.d.ts +163 -1
- package/dist/src/mandates.js +286 -8
- 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 +28 -0
- package/dist/src/react/index.js +30 -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/sdk.d.ts +46 -3
- package/dist/src/sdk.js +49 -23
- package/dist/src/wallet.d.ts +4 -6
- package/dist/src/wallet.js +18 -8
- package/dist/src/web.d.ts +279 -0
- package/dist/src/web.js +186 -0
- package/dist/test/auth-j3.test.d.ts +2 -0
- package/dist/test/auth-j3.test.js +391 -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 +26 -11
- package/dist/test/endpoints.test.js +20 -1
- 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 +248 -0
- package/dist/test/ethos.test.d.ts +2 -0
- package/dist/test/ethos.test.js +219 -0
- package/dist/test/key-store.test.d.ts +2 -0
- package/dist/test/key-store.test.js +161 -0
- package/dist/test/mandates-compute.test.d.ts +2 -0
- package/dist/test/mandates-compute.test.js +256 -0
- package/dist/test/mandates.test.d.ts +2 -0
- package/dist/test/mandates.test.js +93 -0
- package/dist/test/sdk.test.js +70 -30
- package/dist/test/signer.test.d.ts +2 -0
- package/dist/test/signer.test.js +117 -0
- package/dist/test/signup-bootstrap.test.d.ts +2 -0
- package/dist/test/signup-bootstrap.test.js +311 -0
- package/dist/test/wallet.test.js +20 -9
- package/dist/test/web.test.d.ts +2 -0
- package/dist/test/web.test.js +270 -0
- package/package.json +18 -3
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `sdk.assets` — high-level API for the Aithos assets sub-protocol PDS.
|
|
3
|
+
*
|
|
4
|
+
* Stores binary content (images, PDFs, audio, video) owned by a
|
|
5
|
+
* subject, encrypted client-side under per-asset AMKs (Asset Master
|
|
6
|
+
* Keys), accessible to authorized apps via signed mandates (v0.2).
|
|
7
|
+
*
|
|
8
|
+
* const assets = sdk.assets;
|
|
9
|
+
* const avatar = await assets.upload({
|
|
10
|
+
* bytes: pngBuffer,
|
|
11
|
+
* mediaType: "image/png",
|
|
12
|
+
* attachTo: { ethos: { zone: "public", sectionId: "sec_identity" } },
|
|
13
|
+
* });
|
|
14
|
+
* // avatar.url is a stable CloudFront URL (public asset)
|
|
15
|
+
*
|
|
16
|
+
* const cv = await assets.upload({
|
|
17
|
+
* bytes: pdfBuffer,
|
|
18
|
+
* mediaType: "application/pdf",
|
|
19
|
+
* attachTo: { ethos: { zone: "circle", sectionId: "sec_career_docs" } },
|
|
20
|
+
* });
|
|
21
|
+
* // cv is private: stored encrypted, fetched via short-lived presigned URL.
|
|
22
|
+
*
|
|
23
|
+
* const bytes = await assets.fetch(cv.urn);
|
|
24
|
+
* // decrypted plaintext returned to the caller
|
|
25
|
+
*
|
|
26
|
+
* The module wires:
|
|
27
|
+
* - AMK generation + wrap (via @aithos/assets-crypto)
|
|
28
|
+
* - Bytes encryption with the canonical nonce-prefix on-disk layout
|
|
29
|
+
* - RecipientResolver (v0.2-ethos: maps {zone} → recipient set)
|
|
30
|
+
* - Direct S3 PUT against the presigned URL returned by init_upload
|
|
31
|
+
* - In-memory AMK cache (per asset URN) for sub-second re-fetches
|
|
32
|
+
* - Signed envelope JSON-RPC dispatch to /mcp/primitives/{read,write}
|
|
33
|
+
*
|
|
34
|
+
* Spec ref: spec/assets/ in the aithos-protocol repo.
|
|
35
|
+
*/
|
|
36
|
+
import { type AssetMetadata, type AssetReference } from "@aithos/assets-crypto";
|
|
37
|
+
export interface CreateAssetsClientArgs {
|
|
38
|
+
/** Base URL of the deployed assets PDS. */
|
|
39
|
+
readonly pdsUrl: string;
|
|
40
|
+
/** Subject DID. */
|
|
41
|
+
readonly did: string;
|
|
42
|
+
/** Ed25519 sphere seed (32 bytes). */
|
|
43
|
+
readonly sphereSeed: Uint8Array;
|
|
44
|
+
/** Verification method URL within the DID document (e.g. `<did>#<multibase>` for did:key). */
|
|
45
|
+
readonly verificationMethod: string;
|
|
46
|
+
/** Optional fetch implementation. Defaults to globalThis.fetch. */
|
|
47
|
+
readonly fetch?: typeof fetch;
|
|
48
|
+
/**
|
|
49
|
+
* Optional override for the recipient resolver. By default the SDK
|
|
50
|
+
* uses a "self-only" resolver that maps every private upload to the
|
|
51
|
+
* subject's own X25519 sphere key. Apps that already orchestrate
|
|
52
|
+
* grantees explicitly may pass a custom resolver.
|
|
53
|
+
*/
|
|
54
|
+
readonly recipientResolver?: RecipientResolver;
|
|
55
|
+
}
|
|
56
|
+
export interface AttachedContext {
|
|
57
|
+
readonly ethos?: {
|
|
58
|
+
readonly zone: "public" | "circle" | "self";
|
|
59
|
+
readonly sectionId?: string;
|
|
60
|
+
};
|
|
61
|
+
readonly data?: {
|
|
62
|
+
readonly collectionUrn: string;
|
|
63
|
+
readonly recordId?: string;
|
|
64
|
+
readonly field?: string;
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
export interface AssetUploadInput {
|
|
68
|
+
readonly bytes: Uint8Array;
|
|
69
|
+
readonly mediaType: string;
|
|
70
|
+
readonly attachTo?: AttachedContext;
|
|
71
|
+
/**
|
|
72
|
+
* OPTIONAL — force a regime. Defaults to "auto":
|
|
73
|
+
* - ethos.zone === "public" → public
|
|
74
|
+
* - anything else → private
|
|
75
|
+
*/
|
|
76
|
+
readonly regime?: "auto" | "public" | "private";
|
|
77
|
+
/** OPTIONAL — strict forward secrecy at AMK rotation time. */
|
|
78
|
+
readonly forwardSecrecy?: "best_effort" | "strict";
|
|
79
|
+
}
|
|
80
|
+
export interface AssetUploadResult {
|
|
81
|
+
readonly urn: string;
|
|
82
|
+
readonly assetId: string;
|
|
83
|
+
readonly mediaType: string;
|
|
84
|
+
readonly sizeBytes: number;
|
|
85
|
+
readonly sha256OfPlaintext: string;
|
|
86
|
+
readonly encrypted: boolean;
|
|
87
|
+
/**
|
|
88
|
+
* Stable URL for public assets (CloudFront-served). Absent for
|
|
89
|
+
* private assets — fetch them via {@link AssetsClient.fetch}.
|
|
90
|
+
*/
|
|
91
|
+
readonly url?: string;
|
|
92
|
+
/** Whether this URN was returned by intra-subject dedup (existing asset). */
|
|
93
|
+
readonly dedupHit: boolean;
|
|
94
|
+
}
|
|
95
|
+
export interface AssetFetchResult {
|
|
96
|
+
readonly urn: string;
|
|
97
|
+
readonly mediaType: string;
|
|
98
|
+
readonly sizeBytes: number;
|
|
99
|
+
readonly bytes: Uint8Array;
|
|
100
|
+
readonly sha256OfPlaintext: string;
|
|
101
|
+
}
|
|
102
|
+
export interface AssetBrief {
|
|
103
|
+
readonly urn: string;
|
|
104
|
+
readonly assetId: string;
|
|
105
|
+
readonly mediaType: string;
|
|
106
|
+
readonly sizeBytes: number;
|
|
107
|
+
readonly sha256OfPlaintext: string;
|
|
108
|
+
readonly encrypted: boolean;
|
|
109
|
+
readonly state: "ACTIVE" | "ORPHANED" | "TOMBSTONED";
|
|
110
|
+
readonly referenceCount: number;
|
|
111
|
+
readonly createdAt: string;
|
|
112
|
+
readonly modifiedAt: string;
|
|
113
|
+
}
|
|
114
|
+
export interface ListAssetsOpts {
|
|
115
|
+
readonly filter?: {
|
|
116
|
+
readonly mediaTypePrefix?: string;
|
|
117
|
+
readonly sizeBytes?: {
|
|
118
|
+
gte?: number;
|
|
119
|
+
lte?: number;
|
|
120
|
+
};
|
|
121
|
+
readonly createdAfter?: string;
|
|
122
|
+
readonly createdBefore?: string;
|
|
123
|
+
};
|
|
124
|
+
readonly limit?: number;
|
|
125
|
+
readonly cursor?: string;
|
|
126
|
+
readonly order?: "newest" | "oldest";
|
|
127
|
+
readonly includeOrphaned?: boolean;
|
|
128
|
+
readonly includeTombstoned?: boolean;
|
|
129
|
+
}
|
|
130
|
+
export interface ThumbnailUploadInput extends AssetUploadInput {
|
|
131
|
+
/** Long-edge sizes to produce (e.g. [64, 256]). */
|
|
132
|
+
readonly sizes: readonly number[];
|
|
133
|
+
/**
|
|
134
|
+
* Downscaler. The SDK does NOT bundle an image library; callers pass
|
|
135
|
+
* a function that takes the original bytes and a target size and
|
|
136
|
+
* returns downscaled bytes. Typical implementations: `pica` in the
|
|
137
|
+
* browser, `sharp` in Node.
|
|
138
|
+
*/
|
|
139
|
+
readonly downscale: (bytes: Uint8Array, targetLongEdge: number) => Promise<Uint8Array>;
|
|
140
|
+
}
|
|
141
|
+
export interface ThumbnailUploadResult {
|
|
142
|
+
readonly primary: AssetUploadResult;
|
|
143
|
+
readonly thumbnails: readonly {
|
|
144
|
+
size: number;
|
|
145
|
+
result: AssetUploadResult;
|
|
146
|
+
}[];
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Maps an attaching context to the set of recipients whose wraps the
|
|
150
|
+
* AMK must carry. The v0.1 default returns the subject's own X25519
|
|
151
|
+
* sphere key derived from the SDK's seed.
|
|
152
|
+
*
|
|
153
|
+
* v0.2 will introduce an Ethos-aware resolver that inspects the
|
|
154
|
+
* current manifest's `zones.<z>.cipher.wraps[]` (or, in v0.3, the
|
|
155
|
+
* per-section wraps) to mirror grantees on attached assets.
|
|
156
|
+
*/
|
|
157
|
+
export interface RecipientResolver {
|
|
158
|
+
resolve(input: {
|
|
159
|
+
subjectDid: string;
|
|
160
|
+
context: AttachedContext | undefined;
|
|
161
|
+
}): Promise<RecipientSet>;
|
|
162
|
+
}
|
|
163
|
+
export interface RecipientSet {
|
|
164
|
+
readonly recipients: ReadonlyArray<{
|
|
165
|
+
readonly didUrl: string;
|
|
166
|
+
readonly x25519PublicKey: Uint8Array;
|
|
167
|
+
}>;
|
|
168
|
+
}
|
|
169
|
+
export declare function createAssetsClient(args: CreateAssetsClientArgs): AssetsClient;
|
|
170
|
+
export declare class AssetsClient {
|
|
171
|
+
#private;
|
|
172
|
+
constructor(args: CreateAssetsClientArgs);
|
|
173
|
+
upload(input: AssetUploadInput): Promise<AssetUploadResult>;
|
|
174
|
+
/**
|
|
175
|
+
* Upload a primary asset plus one or more thumbnails (downscaled
|
|
176
|
+
* client-side). Convenience method for the Deep avatar use case and
|
|
177
|
+
* any UI that displays the same asset at multiple resolutions.
|
|
178
|
+
*
|
|
179
|
+
* The thumbnails are attached to the same context as the primary
|
|
180
|
+
* and uploaded in parallel. They carry the {@link AssetReference}
|
|
181
|
+
* role `"thumbnail"` when referenced from a section (see
|
|
182
|
+
* spec/assets/03-asset-descriptors.md §3.2.3).
|
|
183
|
+
*/
|
|
184
|
+
uploadWithThumbnails(input: ThumbnailUploadInput): Promise<ThumbnailUploadResult>;
|
|
185
|
+
fetch(urn: string): Promise<AssetFetchResult>;
|
|
186
|
+
head(urn: string): Promise<AssetMetadata>;
|
|
187
|
+
list(opts?: ListAssetsOpts): Promise<{
|
|
188
|
+
items: AssetBrief[];
|
|
189
|
+
nextCursor?: string;
|
|
190
|
+
}>;
|
|
191
|
+
ref(urn: string, reference: AssetReference): Promise<{
|
|
192
|
+
referenceCount: number;
|
|
193
|
+
gammaRef: string;
|
|
194
|
+
}>;
|
|
195
|
+
unref(urn: string, reference: AssetReference): Promise<{
|
|
196
|
+
referenceCount: number;
|
|
197
|
+
gammaRef: string;
|
|
198
|
+
}>;
|
|
199
|
+
listReferences(urn: string): Promise<AssetReference[]>;
|
|
200
|
+
delete(urn: string): Promise<{
|
|
201
|
+
tombstonedAt: string;
|
|
202
|
+
gammaRef: string;
|
|
203
|
+
}>;
|
|
204
|
+
/** Zero in-memory AMK cache. Useful at user logout. */
|
|
205
|
+
reset(): void;
|
|
206
|
+
}
|
|
207
|
+
//# sourceMappingURL=assets.d.ts.map
|