@storacha/clawracha 0.3.8 → 0.3.10

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.
@@ -8,14 +8,10 @@
8
8
  */
9
9
  import type { CID } from "multiformats/cid";
10
10
  import type { BlockFetcher, ValueView } from "@storacha/ucn/pail/api";
11
- import type { DecryptionConfig, EncryptedClient } from "@storacha/encrypt-upload-client/types";
12
- import type { Signer } from "@ucanto/interface";
13
11
  export declare function applyRemoteChanges(changedPaths: string[], entries: Map<string, CID>, workspace: string, options?: {
14
12
  gateway?: string;
15
13
  blocks?: BlockFetcher;
16
14
  current?: ValueView;
17
- encryptedClient?: EncryptedClient;
18
- decryptionConfig?: DecryptionConfig;
19
- agent?: Signer;
15
+ decrypt?: (cid: CID) => Promise<Uint8Array>;
20
16
  }): Promise<void>;
21
17
  //# sourceMappingURL=remote.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"remote.d.ts","sourceRoot":"","sources":["../../src/handlers/remote.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EAChB,MAAM,uCAAuC,CAAC;AAG/C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAwBhD,wBAAsB,kBAAkB,CACtC,YAAY,EAAE,MAAM,EAAE,EACtB,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,EACzB,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE;IACR,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,OAAO,CAAC,EAAE,SAAS,CAAC;IACpB,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,GACA,OAAO,CAAC,IAAI,CAAC,CA2Df"}
1
+ {"version":3,"file":"remote.d.ts","sourceRoot":"","sources":["../../src/handlers/remote.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AA+BtE,wBAAsB,kBAAkB,CACtC,YAAY,EAAE,MAAM,EAAE,EACtB,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,EACzB,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE;IACR,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,OAAO,CAAC,EAAE,SAAS,CAAC;IACpB,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;CAC7C,GACA,OAAO,CAAC,IAAI,CAAC,CA6Cf"}
@@ -9,7 +9,6 @@
9
9
  import * as fs from "node:fs/promises";
10
10
  import * as path from "node:path";
11
11
  import * as mdsync from "../mdsync/index.js";
12
- import { makeDecryptFn } from "../utils/crypto.js";
13
12
  const DEFAULT_GATEWAY = "https://storacha.link";
14
13
  const isMarkdown = (filePath) => filePath.endsWith(".md");
15
14
  /** Drain a ReadableStream into a single Uint8Array. */
@@ -33,7 +32,6 @@ async function drainStream(stream) {
33
32
  }
34
33
  export async function applyRemoteChanges(changedPaths, entries, workspace, options) {
35
34
  const gateway = options?.gateway ?? DEFAULT_GATEWAY;
36
- const isEncrypted = !!(options?.encryptedClient && options?.decryptionConfig);
37
35
  for (const relativePath of changedPaths) {
38
36
  const cid = entries.get(relativePath);
39
37
  const fullPath = path.join(workspace, relativePath);
@@ -52,20 +50,14 @@ export async function applyRemoteChanges(changedPaths, entries, workspace, optio
52
50
  options?.current) {
53
51
  // Markdown: resolve via mdsync CRDT merge.
54
52
  // For single-device, unencrypted blocks are stored locally.
55
- // TODO: For multi-device private spaces, add decrypt layer to resolveValue.
56
- const decrypt = isEncrypted
57
- ? makeDecryptFn(options.encryptedClient, options.decryptionConfig, options.agent)
58
- : undefined;
59
- const content = await mdsync.get(options.blocks, options.current, relativePath, decrypt);
53
+ const content = await mdsync.get(options.blocks, options.current, relativePath, options.decrypt);
60
54
  if (content != null) {
61
55
  await fs.mkdir(path.dirname(fullPath), { recursive: true });
62
56
  await fs.writeFile(fullPath, content);
63
57
  }
64
58
  }
65
- else if (isEncrypted) {
66
- // Private space: retrieve and decrypt via EncryptedClient
67
- const { stream } = await options.encryptedClient.retrieveAndDecryptFile(cid, options.decryptionConfig);
68
- const bytes = await drainStream(stream);
59
+ else if (options?.decrypt) {
60
+ const bytes = await options.decrypt(cid);
69
61
  await fs.mkdir(path.dirname(fullPath), { recursive: true });
70
62
  await fs.writeFile(fullPath, bytes);
71
63
  }
package/dist/sync.d.ts CHANGED
@@ -54,10 +54,6 @@ export declare class SyncEngine {
54
54
  * Get current pail entries as map.
55
55
  */
56
56
  getPailEntries(): Promise<PailEntries>;
57
- /**
58
- * Apply remote changes to local filesystem.
59
- */
60
- private applyRemoteChanges;
61
57
  /**
62
58
  * Mark the engine as stopped.
63
59
  */
@@ -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,EAEV,YAAY,EACb,MAAM,kBAAkB,CAAC;AAS1B,OAAO,EAAqB,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AA4BxE,qBAAa,UAAU;IACrB,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,MAAM,CAAsB;IACpC,OAAO,CAAC,KAAK,CAAiD;IAC9D,OAAO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CAAC,MAAM,CAAC;YAMrB,gBAAgB;IAkC9B;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC;QACvB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;QACpB,SAAS,EAAE;YAAE,KAAK,EAAE,MAAM,CAAA;SAAE,EAAE,CAAC;QAC/B,QAAQ,EAAE,MAAM,EAAE,CAAC;QACnB,UAAU,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,GAAG,EAAE,MAAM,CAAC;YAAC,KAAK,CAAC,EAAE,MAAM,CAAA;SAAE,EAAE,CAAC;QAC5D,OAAO,EAAE,OAAO,CAAC;KAClB,CAAC;IAkBI,MAAM,IAAI,OAAO,CAAC,SAAS,CAAC;IAW5B,iBAAiB,IAAI,OAAO,CAAC,MAAM,CAAC;YAM5B,WAAW;CAK1B"}
package/dist/sync.js CHANGED
@@ -19,7 +19,7 @@ import { makeTempCar } from "./utils/tempcar.js";
19
19
  import { createStorachaClient } from "./utils/client.js";
20
20
  import { decodeDelegation, encodeDelegation } from "./utils/delegation.js";
21
21
  import { extract } from "@storacha/client/delegation";
22
- import { makeEncryptionConfig, makeDecryptionConfig, getEncryptedClient, delegatePlanningDelegationToKMS, } from "./utils/crypto.js";
22
+ import { makeEncryptionConfig, makeDecryptionConfig, getEncryptedClient, delegatePlanningDelegationToKMS, makeDecryptFn, } from "./utils/crypto.js";
23
23
  export class SyncEngine {
24
24
  workspace;
25
25
  blocks;
@@ -183,7 +183,13 @@ export class SyncEngine {
183
183
  const afterEntries = await this.getPailEntries();
184
184
  const remoteChanges = diffRemoteChanges(beforeEntries, afterEntries);
185
185
  if (remoteChanges.length > 0) {
186
- await this.applyRemoteChanges(remoteChanges, afterEntries);
186
+ await applyRemoteChanges(remoteChanges, afterEntries, this.workspace, {
187
+ blocks: this.blocks,
188
+ current: this.current ?? undefined,
189
+ decrypt: this.decryptionConfig && this.encryptedClient
190
+ ? makeDecryptFn(this.encryptedClient, this.decryptionConfig, name.agent)
191
+ : undefined,
192
+ });
187
193
  }
188
194
  this.lastSync = Date.now();
189
195
  }
@@ -219,17 +225,6 @@ export class SyncEngine {
219
225
  }
220
226
  return entries;
221
227
  }
222
- /**
223
- * Apply remote changes to local filesystem.
224
- */
225
- async applyRemoteChanges(changedPaths, entries) {
226
- await applyRemoteChanges(changedPaths, entries, this.workspace, {
227
- blocks: this.blocks,
228
- current: this.current ?? undefined,
229
- encryptedClient: this.encryptedClient,
230
- decryptionConfig: this.decryptionConfig,
231
- });
232
- }
233
228
  /**
234
229
  * Mark the engine as stopped.
235
230
  */
@@ -274,9 +269,9 @@ export class SyncEngine {
274
269
  await applyRemoteChanges(allPaths, entries, this.workspace, {
275
270
  blocks: this.blocks,
276
271
  current: this.current ?? undefined,
277
- encryptedClient: this.encryptedClient,
278
- decryptionConfig: this.decryptionConfig,
279
- agent: name.agent,
272
+ decrypt: this.decryptionConfig && this.encryptedClient
273
+ ? makeDecryptFn(this.encryptedClient, this.decryptionConfig, name.agent)
274
+ : undefined,
280
275
  });
281
276
  }
282
277
  this.lastSync = Date.now();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storacha/clawracha",
3
- "version": "0.3.8",
3
+ "version": "0.3.10",
4
4
  "description": "OpenClaw plugin for Storacha workspace sync via UCN Pail",
5
5
  "type": "module",
6
6
  "files": [