@storacha/clawracha 0.0.8 → 0.0.9

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.
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,OAAO,KAAK,EACV,iBAAiB,EAGlB,MAAM,qBAAqB,CAAC;AAwC7B;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,GAAG,EAAE,iBAAiB,QAyepD"}
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,OAAO,KAAK,EACV,iBAAiB,EAGlB,MAAM,qBAAqB,CAAC;AAyC7B;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,GAAG,EAAE,iBAAiB,QAyepD"}
package/dist/plugin.js CHANGED
@@ -10,6 +10,7 @@ import * as fs from "node:fs/promises";
10
10
  import * as path from "node:path";
11
11
  import { extract as extractDelegation } from "@storacha/client/delegation";
12
12
  import { SyncEngine } from "./sync.js";
13
+ import { decodeDelegation, encodeDelegation } from "./utils/delegation.js";
13
14
  import { FileWatcher } from "./watcher.js";
14
15
  import { createStorachaClient } from "./utils/client.js";
15
16
  // Global state
@@ -232,7 +233,7 @@ export default function plugin(api) {
232
233
  };
233
234
  }
234
235
  // Validate delegation
235
- const bytes = Buffer.from(b64, "base64");
236
+ const bytes = decodeDelegation(b64);
236
237
  const { ok: delegation, error } = await extractDelegation(bytes);
237
238
  if (!delegation) {
238
239
  return { text: `Invalid delegation: ${error}` };
@@ -291,13 +292,13 @@ export default function plugin(api) {
291
292
  };
292
293
  }
293
294
  // Validate upload delegation
294
- const uploadBytes = Buffer.from(uploadB64, "base64");
295
+ const uploadBytes = decodeDelegation(uploadB64);
295
296
  const { ok: uploadDelegation, error: uploadErr } = await extractDelegation(uploadBytes);
296
297
  if (!uploadDelegation) {
297
298
  return { text: `Invalid upload delegation: ${uploadErr}` };
298
299
  }
299
300
  // Validate name delegation
300
- const nameBytes = Buffer.from(nameB64, "base64");
301
+ const nameBytes = decodeDelegation(nameB64);
301
302
  const { ok: nameDelegation, error: nameErr } = await extractDelegation(nameBytes);
302
303
  if (!nameDelegation) {
303
304
  return { text: `Invalid name delegation: ${nameErr}` };
@@ -383,7 +384,7 @@ export default function plugin(api) {
383
384
  ]);
384
385
  const { ok: archiveBytes } = await uploadDelegation.archive();
385
386
  if (archiveBytes) {
386
- const b64 = Buffer.from(archiveBytes).toString("base64");
387
+ const b64 = encodeDelegation(archiveBytes);
387
388
  results.push("**Upload delegation:**\n```\n" + b64 + "\n```");
388
389
  }
389
390
  }
@@ -401,11 +402,11 @@ export default function plugin(api) {
401
402
  const agent = Agent.parse(config.agentKey);
402
403
  let name;
403
404
  if (config.nameArchive) {
404
- const archiveBytes = Buffer.from(config.nameArchive, "base64");
405
+ const archiveBytes = decodeDelegation(config.nameArchive);
405
406
  name = await Name.extract(agent, archiveBytes);
406
407
  }
407
408
  else {
408
- const nameBytes = Buffer.from(config.nameDelegation, "base64");
409
+ const nameBytes = decodeDelegation(config.nameDelegation);
409
410
  const { ok: nameDel } = await extractDelegation(nameBytes);
410
411
  if (!nameDel) {
411
412
  results.push("\u274c Failed to extract name delegation.");
@@ -418,7 +419,7 @@ export default function plugin(api) {
418
419
  const nameDel = await name.grant(targetDID);
419
420
  const { ok: archiveBytes } = await nameDel.archive();
420
421
  if (archiveBytes) {
421
- const b64 = Buffer.from(archiveBytes).toString("base64");
422
+ const b64 = encodeDelegation(archiveBytes);
422
423
  results.push("**Name delegation:**\n```\n" + b64 + "\n```");
423
424
  }
424
425
  }
@@ -1 +1 @@
1
- {"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../src/sync.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAOH,OAAO,KAAK,EACV,SAAS,EACT,UAAU,EAE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O,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAG1C,qBAAa,UAAU;IACrB,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,MAAM,CAAsB;IACpC,OAAO,CAAC,IAAI,CAAyB;IACrC,OAAO,CAAC,OAAO,CAA0B;IACzC,OAAO,CAAC,UAAU,CAAgB;IAClC,OAAO,CAAC,OAAO,CAA4B;IAC3C,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,QAAQ,CAAuB;IACvC,OAAO,CAAC,cAAc,CAAS;gBAEnB,cAAc,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;IAMrD;;OAEG;IACG,IAAI,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAgC/C;;OAEG;IACG,cAAc,CAAC,OAAO,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAe1D;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAkD3B;;OAEG;YACW,iBAAiB;IAc/B;;OAEG;IACG,cAAc,IAAI,OAAO,CAAC,WAAW,CAAC;IAc5C;;OAEG;YACW,kBAAkB;IAWhC;;;OAGG;IACG,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;IA0B7B,MAAM,IAAI,OAAO,CAAC,SAAS,CAAC;IAW5B,iBAAiB,IAAI,OAAO,CAAC,MAAM,CAAC;YAM5B,WAAW;CAK1B"}
package/dist/sync.js CHANGED
@@ -16,6 +16,7 @@ import { applyRemoteChanges } from "./handlers/remote.js";
16
16
  import { processChanges } from "./handlers/process.js";
17
17
  import { diffRemoteChanges } from "./utils/differ.js";
18
18
  import { makeTempCar } from "./utils/tempcar.js";
19
+ import { decodeDelegation, encodeDelegation } from "./utils/delegation.js";
19
20
  export class SyncEngine {
20
21
  workspace;
21
22
  blocks;
@@ -38,13 +39,13 @@ export class SyncEngine {
38
39
  const agent = Agent.parse(config.agentKey);
39
40
  if (config.nameArchive) {
40
41
  // Restore from previously saved archive (has full state)
41
- const archiveBytes = Buffer.from(config.nameArchive, "base64");
42
+ const archiveBytes = decodeDelegation(config.nameArchive);
42
43
  this.name = await Name.extract(agent, archiveBytes);
43
44
  }
44
45
  else if (config.nameDelegation) {
45
46
  // Reconstruct from delegation (granted by another device)
46
47
  const { extract } = await import("@storacha/client/delegation");
47
- const nameBytes = Buffer.from(config.nameDelegation, "base64");
48
+ const nameBytes = decodeDelegation(config.nameDelegation);
48
49
  const { ok: delegation } = await extract(nameBytes);
49
50
  if (!delegation)
50
51
  throw new Error("Failed to extract name delegation");
@@ -205,7 +206,7 @@ export class SyncEngine {
205
206
  if (!this.name)
206
207
  throw new Error("Sync engine not initialized");
207
208
  const bytes = await this.name.archive();
208
- return Buffer.from(bytes).toString("base64");
209
+ return encodeDelegation(bytes);
209
210
  }
210
211
  async storeBlocks(blocks) {
211
212
  for (const block of blocks) {
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/utils/client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE/C;;;GAGG;AACH,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,YAAY,GACnB,OAAO,CAAC,MAAM,CAAC,CA8BjB"}
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/utils/client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE/C;;;GAGG;AACH,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,YAAY,GACnB,OAAO,CAAC,MAAM,CAAC,CA8BjB"}
@@ -8,6 +8,7 @@ import { Agent as PailAgent } from "@storacha/ucn/pail";
8
8
  import { create as createClient } from "@storacha/client";
9
9
  import { StoreMemory } from "@storacha/client/stores/memory";
10
10
  import { extract } from "@storacha/client/delegation";
11
+ import { decodeDelegation } from "./delegation.js";
11
12
  /**
12
13
  * Build a Storacha Client from device config.
13
14
  * Requires agentKey and uploadDelegation to be present.
@@ -22,7 +23,7 @@ export async function createStorachaClient(config) {
22
23
  store: new StoreMemory(),
23
24
  });
24
25
  // Import the upload delegation (space → agent)
25
- const uploadBytes = Buffer.from(config.uploadDelegation, "base64");
26
+ const uploadBytes = decodeDelegation(config.uploadDelegation);
26
27
  const { ok: uploadDelegation, error: uploadErr } = await extract(uploadBytes);
27
28
  if (!uploadDelegation) {
28
29
  throw new Error(`Failed to extract upload delegation: ${uploadErr}`);
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Delegation encoding/decoding utilities.
3
+ *
4
+ * Delegations are serialized as CIDv1 with the CAR codec (0x0202)
5
+ * and identity multihash, encoded as base64. This matches the format
6
+ * used by the Storacha CLI (`storacha delegation create --base64`).
7
+ */
8
+ /**
9
+ * Encode delegation archive bytes as a CID string (base64).
10
+ * archive bytes → CIDv1(CAR, identity) → base64 string
11
+ */
12
+ export declare function encodeDelegation(archiveBytes: Uint8Array): string;
13
+ /**
14
+ * Decode a delegation CID string back to archive bytes.
15
+ * base64 string → CID → identity multihash digest → bytes
16
+ */
17
+ export declare function decodeDelegation(encoded: string): Uint8Array;
18
+ //# sourceMappingURL=delegation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delegation.d.ts","sourceRoot":"","sources":["../../src/utils/delegation.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AASH;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,UAAU,GAAG,MAAM,CAGjE;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,UAAU,CAQ5D"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Delegation encoding/decoding utilities.
3
+ *
4
+ * Delegations are serialized as CIDv1 with the CAR codec (0x0202)
5
+ * and identity multihash, encoded as base64. This matches the format
6
+ * used by the Storacha CLI (`storacha delegation create --base64`).
7
+ */
8
+ import { CID } from "multiformats/cid";
9
+ import { base64 } from "multiformats/bases/base64";
10
+ import { identity } from "multiformats/hashes/identity";
11
+ /** CAR codec code (multicodec 0x0202) */
12
+ const CAR_CODE = 0x0202;
13
+ /**
14
+ * Encode delegation archive bytes as a CID string (base64).
15
+ * archive bytes → CIDv1(CAR, identity) → base64 string
16
+ */
17
+ export function encodeDelegation(archiveBytes) {
18
+ const cid = CID.createV1(CAR_CODE, identity.digest(archiveBytes));
19
+ return cid.toString(base64);
20
+ }
21
+ /**
22
+ * Decode a delegation CID string back to archive bytes.
23
+ * base64 string → CID → identity multihash digest → bytes
24
+ */
25
+ export function decodeDelegation(encoded) {
26
+ const cid = CID.parse(encoded, base64);
27
+ if (cid.multihash.code !== identity.code) {
28
+ throw new Error("Invalid delegation encoding: expected identity multihash");
29
+ }
30
+ return cid.multihash.digest;
31
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storacha/clawracha",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "description": "OpenClaw plugin for Storacha workspace sync via UCN Pail",
5
5
  "type": "module",
6
6
  "files": [