@storacha/clawracha 0.2.2 → 0.3.0

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.
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Encryption helpers for private spaces.
3
+ * Uses @storacha/encrypt-upload-client with KMS-based key management.
4
+ */
5
+ import { createGenericKMSAdapter } from "@storacha/encrypt-upload-client/factories.node";
6
+ import { create as createEncryptedClient } from "@storacha/encrypt-upload-client";
7
+ import { encryptFile, encryptedBlockStream } from "@storacha/encrypt-upload-client/utils/encrypt";
8
+ const KMS_SERVICE_URL = "https://kms.storacha.network";
9
+ const KMS_SERVICE_DID = "did:web:kms.storacha.network";
10
+ let cachedAdapter = null;
11
+ export function getKMSCryptoAdapter() {
12
+ if (cachedAdapter)
13
+ return cachedAdapter;
14
+ cachedAdapter = createGenericKMSAdapter(KMS_SERVICE_URL, KMS_SERVICE_DID);
15
+ return cachedAdapter;
16
+ }
17
+ export async function getEncryptedClient(storachaClient) {
18
+ const cryptoAdapter = getKMSCryptoAdapter();
19
+ return createEncryptedClient({
20
+ storachaClient,
21
+ cryptoAdapter,
22
+ });
23
+ }
24
+ export function makeEncryptionConfig(issuer, spaceDID, proofs) {
25
+ return {
26
+ issuer: issuer,
27
+ spaceDID,
28
+ proofs,
29
+ };
30
+ }
31
+ export function makeDecryptionConfig(spaceDID, decryptDelegation, proofs) {
32
+ return {
33
+ spaceDID,
34
+ decryptDelegation,
35
+ proofs,
36
+ };
37
+ }
38
+ /**
39
+ * Encrypt a BlobLike and return a block stream
40
+ * (UnixFS-encoded encrypted content + metadata block appended).
41
+ */
42
+ export async function encryptToBlockStream(file, encryptionConfig) {
43
+ const adapter = getKMSCryptoAdapter();
44
+ const payload = await encryptFile(adapter, file, encryptionConfig);
45
+ return encryptedBlockStream(payload, adapter);
46
+ }
47
+ /**
48
+ * Wrap raw bytes as a BlobLike for encryption.
49
+ */
50
+ export function bytesToBlobLike(bytes) {
51
+ return {
52
+ stream: () => new ReadableStream({
53
+ start(controller) {
54
+ controller.enqueue(bytes);
55
+ controller.close();
56
+ },
57
+ }),
58
+ };
59
+ }
60
+ /**
61
+ * Drain a ReadableStream into a single Uint8Array.
62
+ */
63
+ async function drainStream(stream) {
64
+ const reader = stream.getReader();
65
+ const chunks = [];
66
+ while (true) {
67
+ const { done, value } = await reader.read();
68
+ if (done)
69
+ break;
70
+ chunks.push(value);
71
+ }
72
+ const totalLength = chunks.reduce((sum, c) => sum + c.length, 0);
73
+ const result = new Uint8Array(totalLength);
74
+ let offset = 0;
75
+ for (const chunk of chunks) {
76
+ result.set(chunk, offset);
77
+ offset += chunk.length;
78
+ }
79
+ return result;
80
+ }
81
+ /**
82
+ * Create a decrypt function for mdsync resolveValue.
83
+ * Fetches encrypted content by CID via EncryptedClient and returns decrypted bytes.
84
+ */
85
+ export function makeDecryptFn(encryptedClient, decryptionConfig) {
86
+ return async (cid) => {
87
+ const { stream } = await encryptedClient.retrieveAndDecryptFile(cid, decryptionConfig);
88
+ return drainStream(stream);
89
+ };
90
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storacha/clawracha",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "description": "OpenClaw plugin for Storacha workspace sync via UCN Pail",
5
5
  "type": "module",
6
6
  "files": [
@@ -29,9 +29,11 @@
29
29
  "@ipld/car": "^5.2.0",
30
30
  "@ipld/dag-cbor": "^9.2.5",
31
31
  "@storacha/client": "^2.0.4",
32
- "@storacha/md-merge": "0.7.0",
32
+ "@storacha/encrypt-upload-client": "1.1.76-rc.0",
33
+ "@storacha/md-merge": "0.9.0",
33
34
  "@storacha/ucn": "1.1.1-rc.3",
34
35
  "@storacha/upload-client": "^1.3.9",
36
+ "@ucanto/core": "^10.4.6",
35
37
  "@ucanto/interface": "^11.0.1",
36
38
  "@web3-storage/pail": "0.6.3-rc.3",
37
39
  "carstream": "^2.3.0",