@aithos/sdk 0.1.0-alpha.42 → 0.1.0-alpha.43

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/dist/src/ethos.js CHANGED
@@ -485,38 +485,72 @@ export class EthosClient {
485
485
  * Publish height=1 for an owner whose Ethos identity exists on
486
486
  * `api.aithos.be` (provisioned by `auth.signUp()` in alpha.6+) but who
487
487
  * has no editions yet. Builds the manifest from the staged ADD
488
- * mutations on the public zone and POSTs `aithos.publish_ethos_edition`.
488
+ * mutations and POSTs `aithos.publish_ethos_edition`.
489
489
  *
490
- * Limitations of the alpha.7 cut:
491
- * - Public zone only. Staged mutations on circle/self are rejected
492
- * with `ethos_first_edition_public_only` those zones can be
493
- * populated in subsequent editions via the regular
494
- * `publishZoneEdit` path once the public zone has been seeded.
490
+ * Behaviour:
491
+ * - All three zones (public / circle / self) are supported at
492
+ * height=1 since `@aithos/protocol-client@>=0.1.0-alpha.14`. Circle
493
+ * and self sections are sealed via the same DEK + HKDF wrap
494
+ * machinery that the height>=2 path uses, so they're verifiable by
495
+ * the existing reader path with no special-casing.
496
+ * - If the caller staged only circle / self mutations (typical for
497
+ * an app like Linkedone that writes a personality section straight
498
+ * to `circle`), an `aithos-init` sentinel is auto-injected into
499
+ * the public zone. This preserves the invariant that every Ethos
500
+ * has a non-empty public zone at height=1 — which all resolution
501
+ * flows (handle lookup, public crawl) depend on.
495
502
  * - First-edition publishes don't accept update/delete mutations
496
503
  * (there's nothing to update or delete yet) — those are rejected
497
504
  * with `ethos_first_edition_invalid_op`.
505
+ * - The `ethos_first_edition_public_only` error code is no longer
506
+ * emitted; the bucket-and-auto-inject path replaces it.
498
507
  */
499
508
  async #publishFirstEditionOwner() {
500
509
  if (this.#actor.kind !== "owner") {
501
510
  // Defensive — caller already checked this branch.
502
511
  throw new AithosSDKError("ethos_invalid_actor", "expected owner actor");
503
512
  }
504
- // Validate the staged operation set. First edition = ADDs on public
505
- // zone only.
513
+ // Validate the staged operation set and bucket by zone. First
514
+ // edition = ADD mutations only; update / delete are rejected because
515
+ // there's no prior state to mutate.
506
516
  const publicAdds = [];
517
+ const circleAdds = [];
518
+ const selfAdds = [];
507
519
  for (const m of this.#mutations) {
508
520
  if (m.kind !== "add") {
509
521
  throw new AithosSDKError("ethos_first_edition_invalid_op", `first edition: cannot ${m.kind} a section before any edition exists; only addSection is supported on a fresh Ethos`, { data: { mutation: m } });
510
522
  }
511
- if (m.zone !== "public") {
512
- throw new AithosSDKError("ethos_first_edition_public_only", `first edition: only the "public" zone is supported on a fresh Ethos; "${m.zone}" sections can be added after the first publish`, { data: { zone: m.zone } });
513
- }
514
- publicAdds.push({ section: m.section });
515
- }
516
- if (publicAdds.length === 0) {
523
+ if (m.zone === "public")
524
+ publicAdds.push(m.section);
525
+ else if (m.zone === "circle")
526
+ circleAdds.push(m.section);
527
+ else if (m.zone === "self")
528
+ selfAdds.push(m.section);
529
+ }
530
+ if (publicAdds.length === 0 &&
531
+ circleAdds.length === 0 &&
532
+ selfAdds.length === 0) {
517
533
  // Should never reach here — publish() short-circuits on empty
518
534
  // mutations. Belt-and-braces in case the contract drifts.
519
- throw new AithosSDKError("ethos_first_edition_empty", "first edition: stage at least one public-zone section before publishing");
535
+ throw new AithosSDKError("ethos_first_edition_empty", "first edition: stage at least one section before publishing");
536
+ }
537
+ // Public zone invariant: every Ethos has a non-empty public zone at
538
+ // height=1. If the caller only staged encrypted-zone mutations
539
+ // (typical for apps like Linkedone that write straight to circle),
540
+ // auto-inject an `aithos-init` sentinel — identical in shape to
541
+ // what `ensureInitialized()` would produce if called explicitly.
542
+ if (publicAdds.length === 0) {
543
+ publicAdds.push({
544
+ id: "sec_" + randomHex(12),
545
+ title: "aithos-init",
546
+ body: "Ethos initialized.\n\n" +
547
+ "This section is a sentinel created by `EthosClient.publish()` " +
548
+ "to materialise the subject's first edition alongside the " +
549
+ "encrypted-zone content the caller staged. It is safe to delete " +
550
+ "or edit later — its only purpose is to satisfy the invariant " +
551
+ "that every Ethos has a non-empty public zone at height=1.",
552
+ gamma_ref: "gamma_none_" + randomHex(24),
553
+ });
520
554
  }
521
555
  const identity = this.#actor.signers._unsafeStoredIdentity();
522
556
  const browserId = browserIdentityFromStored(identity);
@@ -524,14 +558,27 @@ export class EthosClient {
524
558
  const built = buildSignedFirstEditionFromSections({
525
559
  identity: browserId,
526
560
  signedDidDoc: signedDoc,
527
- publicSections: publicAdds.map((a) => a.section),
561
+ publicSections: publicAdds,
562
+ ...(circleAdds.length > 0 ? { circleSections: circleAdds } : {}),
563
+ ...(selfAdds.length > 0 ? { selfSections: selfAdds } : {}),
528
564
  });
529
565
  const url = writeEndpoint();
566
+ const zonesPayload = {
567
+ public: { bytes_base64: bytesToBase64Padded(built.publicMarkdownBytes) },
568
+ };
569
+ if (built.circleBytes) {
570
+ zonesPayload.circle = {
571
+ bytes_base64: bytesToBase64Padded(built.circleBytes),
572
+ };
573
+ }
574
+ if (built.selfBytes) {
575
+ zonesPayload.self = {
576
+ bytes_base64: bytesToBase64Padded(built.selfBytes),
577
+ };
578
+ }
530
579
  const params = {
531
580
  manifest: built.manifest,
532
- zones: {
533
- public: { bytes_base64: bytesToBase64Padded(built.publicMarkdownBytes) },
534
- },
581
+ zones: zonesPayload,
535
582
  };
536
583
  const envelope = buildSignedEnvelope({
537
584
  iss: browserId.did,
@@ -575,11 +622,16 @@ export class EthosClient {
575
622
  // take the regular next-edition path.
576
623
  this.#ethosHasNoEditionYet = false;
577
624
  this.#afterPublish();
625
+ const zonesPublished = ["public"];
626
+ if (built.circleBytes)
627
+ zonesPublished.push("circle");
628
+ if (built.selfBytes)
629
+ zonesPublished.push("self");
578
630
  return {
579
631
  editionHeight: 1,
580
632
  manifestHash: "", // protocol-client surfaces this on later editions; not on first
581
633
  subjectDid: browserId.did,
582
- zonesPublished: ["public"],
634
+ zonesPublished,
583
635
  };
584
636
  }
585
637
  }
@@ -1,4 +1,4 @@
1
- export declare const VERSION = "0.1.0-alpha.42";
1
+ export declare const VERSION = "0.1.0-alpha.43";
2
2
  export { AithosSDK } from "./sdk.js";
3
3
  export type { AithosSDKConfig } from "./types.js";
4
4
  export { AithosSDKError } from "./types.js";
package/dist/src/index.js CHANGED
@@ -17,7 +17,7 @@
17
17
  // Public types specific to the SDK (`AithosSDKConfig`, `AithosSDKError`)
18
18
  // are exported from here. Endpoint config (`AithosSdkEndpoints`,
19
19
  // `DEFAULT_SDK_ENDPOINTS`) likewise.
20
- export const VERSION = "0.1.0-alpha.42";
20
+ export const VERSION = "0.1.0-alpha.43";
21
21
  export { AithosSDK } from "./sdk.js";
22
22
  export { AithosSDKError } from "./types.js";
23
23
  // Re-export protocol-client's JSON-RPC error type so consumers can
@@ -185,19 +185,142 @@ describe("EthosClient — fresh Ethos (no edition published yet)", () => {
185
185
  assert.equal(env.method, "aithos.publish_ethos_edition");
186
186
  assert.match(env.proof.verificationMethod, /#public$/);
187
187
  });
188
- it("publish() rejects circle/self mutations on first edition", async () => {
188
+ it("publish() accepts circle mutations on first edition with auto-injected public sentinel", async () => {
189
+ // Regression target: this used to throw `ethos_first_edition_public_only`.
190
+ // Since aithos-sdk@0.1.0-alpha.43 + protocol-client@0.1.0-alpha.14, the
191
+ // SDK auto-injects an `aithos-init` public section and seals the circle
192
+ // sections in the same height=1 manifest.
193
+ let publishBody = null;
189
194
  installFetchMock([
190
195
  {
191
196
  url: "/mcp/primitives/read",
192
197
  rpcMethod: "aithos.get_ethos_manifest",
193
198
  respond: noEditionYetResponse,
194
199
  },
200
+ {
201
+ url: "/mcp/primitives/write",
202
+ rpcMethod: "aithos.publish_ethos_edition",
203
+ respond: (call) => {
204
+ publishBody = call.body;
205
+ return publishOkResponse();
206
+ },
207
+ },
195
208
  ]);
196
209
  const auth = makeAuth();
197
210
  await signInAsAlice(auth);
198
211
  const me = makeNamespace(auth).me();
199
212
  me.zone("circle").addSection({ title: "Private", body: "..." });
200
- await assert.rejects(() => me.publish(), (e) => e instanceof AithosSDKError && e.code === "ethos_first_edition_public_only");
213
+ const r = await me.publish();
214
+ assert.equal(r.editionHeight, 1);
215
+ assert.deepEqual(r.zonesPublished, ["public", "circle"]);
216
+ const manifest = publishBody.params.manifest;
217
+ assert.equal(manifest.edition.height, 1);
218
+ assert.equal(manifest.edition.prev_hash, null);
219
+ // Auto-injected sentinel.
220
+ assert.deepEqual(manifest.zones.public.section_titles, ["aithos-init"]);
221
+ assert.equal(manifest.zones.public.encrypted, false);
222
+ // Sealed circle zone.
223
+ assert.deepEqual(manifest.zones.circle.section_titles, ["Private"]);
224
+ assert.equal(manifest.zones.circle.encrypted, true);
225
+ assert.ok(manifest.zones.circle.cipher, "circle cipher must be present");
226
+ // Both zones uploaded.
227
+ assert.ok(publishBody.params.zones.public?.bytes_base64);
228
+ assert.ok(publishBody.params.zones.circle?.bytes_base64);
229
+ assert.equal(publishBody.params.zones.self, undefined);
230
+ });
231
+ it("publish() preserves the caller's explicit public section when mixed with circle", async () => {
232
+ // When the caller stages BOTH a public and a circle add, the SDK
233
+ // must NOT inject a sentinel — the user's public section is enough.
234
+ let publishBody = null;
235
+ installFetchMock([
236
+ {
237
+ url: "/mcp/primitives/read",
238
+ rpcMethod: "aithos.get_ethos_manifest",
239
+ respond: noEditionYetResponse,
240
+ },
241
+ {
242
+ url: "/mcp/primitives/write",
243
+ rpcMethod: "aithos.publish_ethos_edition",
244
+ respond: (call) => {
245
+ publishBody = call.body;
246
+ return publishOkResponse();
247
+ },
248
+ },
249
+ ]);
250
+ const auth = makeAuth();
251
+ await signInAsAlice(auth);
252
+ const me = makeNamespace(auth).me();
253
+ me.zone("public").addSection({ title: "About", body: "Public bio." });
254
+ me.zone("circle").addSection({ title: "Notes", body: "Private notes." });
255
+ const r = await me.publish();
256
+ assert.deepEqual(r.zonesPublished, ["public", "circle"]);
257
+ const manifest = publishBody.params.manifest;
258
+ // No sentinel — the user's section is the public titles entry.
259
+ assert.deepEqual(manifest.zones.public.section_titles, ["About"]);
260
+ assert.deepEqual(manifest.zones.circle.section_titles, ["Notes"]);
261
+ });
262
+ it("publish() auto-injects public sentinel when only self mutations are staged", async () => {
263
+ let publishBody = null;
264
+ installFetchMock([
265
+ {
266
+ url: "/mcp/primitives/read",
267
+ rpcMethod: "aithos.get_ethos_manifest",
268
+ respond: noEditionYetResponse,
269
+ },
270
+ {
271
+ url: "/mcp/primitives/write",
272
+ rpcMethod: "aithos.publish_ethos_edition",
273
+ respond: (call) => {
274
+ publishBody = call.body;
275
+ return publishOkResponse();
276
+ },
277
+ },
278
+ ]);
279
+ const auth = makeAuth();
280
+ await signInAsAlice(auth);
281
+ const me = makeNamespace(auth).me();
282
+ me.zone("self").addSection({ title: "Journal", body: "Private." });
283
+ const r = await me.publish();
284
+ assert.deepEqual(r.zonesPublished, ["public", "self"]);
285
+ const manifest = publishBody.params.manifest;
286
+ assert.deepEqual(manifest.zones.public.section_titles, ["aithos-init"]);
287
+ assert.deepEqual(manifest.zones.self.section_titles, ["Journal"]);
288
+ assert.equal(manifest.zones.self.encrypted, true);
289
+ assert.equal(manifest.zones.circle, undefined);
290
+ });
291
+ it("publish() lands public + circle + self in a single height=1 edition", async () => {
292
+ let publishBody = null;
293
+ installFetchMock([
294
+ {
295
+ url: "/mcp/primitives/read",
296
+ rpcMethod: "aithos.get_ethos_manifest",
297
+ respond: noEditionYetResponse,
298
+ },
299
+ {
300
+ url: "/mcp/primitives/write",
301
+ rpcMethod: "aithos.publish_ethos_edition",
302
+ respond: (call) => {
303
+ publishBody = call.body;
304
+ return publishOkResponse();
305
+ },
306
+ },
307
+ ]);
308
+ const auth = makeAuth();
309
+ await signInAsAlice(auth);
310
+ const me = makeNamespace(auth).me();
311
+ me.zone("public").addSection({ title: "Bio", body: "Bio body." });
312
+ me.zone("circle").addSection({ title: "Circle", body: "Circle body." });
313
+ me.zone("self").addSection({ title: "Self", body: "Self body." });
314
+ const r = await me.publish();
315
+ assert.equal(r.editionHeight, 1);
316
+ assert.deepEqual(r.zonesPublished, ["public", "circle", "self"]);
317
+ const manifest = publishBody.params.manifest;
318
+ assert.deepEqual(manifest.zones.public.section_titles, ["Bio"]);
319
+ assert.deepEqual(manifest.zones.circle.section_titles, ["Circle"]);
320
+ assert.deepEqual(manifest.zones.self.section_titles, ["Self"]);
321
+ assert.ok(publishBody.params.zones.public?.bytes_base64);
322
+ assert.ok(publishBody.params.zones.circle?.bytes_base64);
323
+ assert.ok(publishBody.params.zones.self?.bytes_base64);
201
324
  });
202
325
  it("publish() rejects update/delete operations on a fresh Ethos", async () => {
203
326
  installFetchMock([
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aithos/sdk",
3
- "version": "0.1.0-alpha.42",
3
+ "version": "0.1.0-alpha.43",
4
4
  "description": "Aithos SDK — high-level TypeScript developer kit for building agentic apps on the Aithos protocol. Wraps @aithos/protocol-client and exposes the Aithos compute proxy and wallet (Stripe top-up) endpoints.",
5
5
  "keywords": [
6
6
  "aithos",
@@ -43,12 +43,21 @@
43
43
  "README.md",
44
44
  "LICENSE"
45
45
  ],
46
+ "scripts": {
47
+ "build": "tsc",
48
+ "build:test": "tsc -p tsconfig.test.json",
49
+ "check-types": "tsc --noEmit && tsc -p tsconfig.test.json --noEmit",
50
+ "test": "npm run clean && npm run build && npm run build:test && cd dist && node --test",
51
+ "test:watch": "cd dist && node --test --watch",
52
+ "clean": "rm -rf dist",
53
+ "prepublishOnly": "npm run clean && npm run build && npm test"
54
+ },
46
55
  "engines": {
47
56
  "node": ">=20"
48
57
  },
49
58
  "peerDependencies": {
50
- "@aithos/protocol-client": ">=0.1.0-alpha.13 <0.2.0",
51
59
  "@aithos/assets-crypto": ">=0.1.0-alpha.1 <0.2.0",
60
+ "@aithos/protocol-client": "^0.1.0-alpha.14",
52
61
  "react": "^18.0.0 || ^19.0.0"
53
62
  },
54
63
  "peerDependenciesMeta": {
@@ -60,7 +69,8 @@
60
69
  }
61
70
  },
62
71
  "devDependencies": {
63
- "@aithos/protocol-client": "^0.1.0-alpha.13",
72
+ "@aithos/assets-crypto": "^0.1.0-alpha.1",
73
+ "@aithos/protocol-client": "^0.1.0-alpha.14",
64
74
  "@types/node": "^24.12.2",
65
75
  "fake-indexeddb": "^6.2.5",
66
76
  "typescript": "^5.9.2"
@@ -68,13 +78,5 @@
68
78
  "publishConfig": {
69
79
  "access": "public",
70
80
  "tag": "alpha"
71
- },
72
- "scripts": {
73
- "build": "tsc",
74
- "build:test": "tsc -p tsconfig.test.json",
75
- "check-types": "tsc --noEmit && tsc -p tsconfig.test.json --noEmit",
76
- "test": "npm run clean && npm run build && npm run build:test && cd dist && node --test",
77
- "test:watch": "cd dist && node --test --watch",
78
- "clean": "rm -rf dist"
79
81
  }
80
- }
82
+ }