@hashtree/core 0.1.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.
Files changed (138) hide show
  1. package/LICENSE +21 -0
  2. package/dist/bep52.d.ts +179 -0
  3. package/dist/bep52.d.ts.map +1 -0
  4. package/dist/bep52.js +384 -0
  5. package/dist/bep52.js.map +1 -0
  6. package/dist/builder.d.ts +137 -0
  7. package/dist/builder.d.ts.map +1 -0
  8. package/dist/builder.js +281 -0
  9. package/dist/builder.js.map +1 -0
  10. package/dist/codec.d.ts +37 -0
  11. package/dist/codec.d.ts.map +1 -0
  12. package/dist/codec.js +109 -0
  13. package/dist/codec.js.map +1 -0
  14. package/dist/crypto.d.ts +92 -0
  15. package/dist/crypto.d.ts.map +1 -0
  16. package/dist/crypto.js +212 -0
  17. package/dist/crypto.js.map +1 -0
  18. package/dist/encrypted.d.ts +114 -0
  19. package/dist/encrypted.d.ts.map +1 -0
  20. package/dist/encrypted.js +446 -0
  21. package/dist/encrypted.js.map +1 -0
  22. package/dist/hash.d.ts +14 -0
  23. package/dist/hash.d.ts.map +1 -0
  24. package/dist/hash.js +27 -0
  25. package/dist/hash.js.map +1 -0
  26. package/dist/hashtree.d.ts +237 -0
  27. package/dist/hashtree.d.ts.map +1 -0
  28. package/dist/hashtree.js +557 -0
  29. package/dist/hashtree.js.map +1 -0
  30. package/dist/index.d.ts +27 -0
  31. package/dist/index.d.ts.map +1 -0
  32. package/dist/index.js +44 -0
  33. package/dist/index.js.map +1 -0
  34. package/dist/nhash.d.ts +94 -0
  35. package/dist/nhash.d.ts.map +1 -0
  36. package/dist/nhash.js +293 -0
  37. package/dist/nhash.js.map +1 -0
  38. package/dist/resolver/index.d.ts +5 -0
  39. package/dist/resolver/index.d.ts.map +1 -0
  40. package/dist/resolver/index.js +5 -0
  41. package/dist/resolver/index.js.map +1 -0
  42. package/dist/resolver/nostr.d.ts +82 -0
  43. package/dist/resolver/nostr.d.ts.map +1 -0
  44. package/dist/resolver/nostr.js +868 -0
  45. package/dist/resolver/nostr.js.map +1 -0
  46. package/dist/store/blossom.d.ts +100 -0
  47. package/dist/store/blossom.d.ts.map +1 -0
  48. package/dist/store/blossom.js +355 -0
  49. package/dist/store/blossom.js.map +1 -0
  50. package/dist/store/dexie.d.ts +44 -0
  51. package/dist/store/dexie.d.ts.map +1 -0
  52. package/dist/store/dexie.js +196 -0
  53. package/dist/store/dexie.js.map +1 -0
  54. package/dist/store/fallback.d.ts +40 -0
  55. package/dist/store/fallback.d.ts.map +1 -0
  56. package/dist/store/fallback.js +71 -0
  57. package/dist/store/fallback.js.map +1 -0
  58. package/dist/store/index.d.ts +6 -0
  59. package/dist/store/index.d.ts.map +1 -0
  60. package/dist/store/index.js +6 -0
  61. package/dist/store/index.js.map +1 -0
  62. package/dist/store/memory.d.ts +29 -0
  63. package/dist/store/memory.d.ts.map +1 -0
  64. package/dist/store/memory.js +66 -0
  65. package/dist/store/memory.js.map +1 -0
  66. package/dist/store/opfs.d.ts +56 -0
  67. package/dist/store/opfs.d.ts.map +1 -0
  68. package/dist/store/opfs.js +200 -0
  69. package/dist/store/opfs.js.map +1 -0
  70. package/dist/streaming.d.ts +74 -0
  71. package/dist/streaming.d.ts.map +1 -0
  72. package/dist/streaming.js +199 -0
  73. package/dist/streaming.js.map +1 -0
  74. package/dist/tree/create.d.ts +35 -0
  75. package/dist/tree/create.d.ts.map +1 -0
  76. package/dist/tree/create.js +90 -0
  77. package/dist/tree/create.js.map +1 -0
  78. package/dist/tree/edit.d.ts +28 -0
  79. package/dist/tree/edit.d.ts.map +1 -0
  80. package/dist/tree/edit.js +115 -0
  81. package/dist/tree/edit.js.map +1 -0
  82. package/dist/tree/editEncrypted.d.ts +46 -0
  83. package/dist/tree/editEncrypted.d.ts.map +1 -0
  84. package/dist/tree/editEncrypted.js +225 -0
  85. package/dist/tree/editEncrypted.js.map +1 -0
  86. package/dist/tree/index.d.ts +7 -0
  87. package/dist/tree/index.d.ts.map +1 -0
  88. package/dist/tree/index.js +7 -0
  89. package/dist/tree/index.js.map +1 -0
  90. package/dist/tree/read.d.ts +75 -0
  91. package/dist/tree/read.d.ts.map +1 -0
  92. package/dist/tree/read.js +389 -0
  93. package/dist/tree/read.js.map +1 -0
  94. package/dist/tree/writeAt.d.ts +44 -0
  95. package/dist/tree/writeAt.d.ts.map +1 -0
  96. package/dist/tree/writeAt.js +282 -0
  97. package/dist/tree/writeAt.js.map +1 -0
  98. package/dist/types.d.ts +274 -0
  99. package/dist/types.d.ts.map +1 -0
  100. package/dist/types.js +47 -0
  101. package/dist/types.js.map +1 -0
  102. package/dist/verify.d.ts +12 -0
  103. package/dist/verify.d.ts.map +1 -0
  104. package/dist/verify.js +32 -0
  105. package/dist/verify.js.map +1 -0
  106. package/dist/visibility.d.ts +50 -0
  107. package/dist/visibility.d.ts.map +1 -0
  108. package/dist/visibility.js +111 -0
  109. package/dist/visibility.js.map +1 -0
  110. package/dist/webrtc/index.d.ts +4 -0
  111. package/dist/webrtc/index.d.ts.map +1 -0
  112. package/dist/webrtc/index.js +4 -0
  113. package/dist/webrtc/index.js.map +1 -0
  114. package/dist/webrtc/lruCache.d.ts +20 -0
  115. package/dist/webrtc/lruCache.d.ts.map +1 -0
  116. package/dist/webrtc/lruCache.js +59 -0
  117. package/dist/webrtc/lruCache.js.map +1 -0
  118. package/dist/webrtc/peer.d.ts +122 -0
  119. package/dist/webrtc/peer.d.ts.map +1 -0
  120. package/dist/webrtc/peer.js +583 -0
  121. package/dist/webrtc/peer.js.map +1 -0
  122. package/dist/webrtc/protocol.d.ts +76 -0
  123. package/dist/webrtc/protocol.d.ts.map +1 -0
  124. package/dist/webrtc/protocol.js +167 -0
  125. package/dist/webrtc/protocol.js.map +1 -0
  126. package/dist/webrtc/store.d.ts +190 -0
  127. package/dist/webrtc/store.d.ts.map +1 -0
  128. package/dist/webrtc/store.js +1043 -0
  129. package/dist/webrtc/store.js.map +1 -0
  130. package/dist/webrtc/types.d.ts +196 -0
  131. package/dist/webrtc/types.d.ts.map +1 -0
  132. package/dist/webrtc/types.js +46 -0
  133. package/dist/webrtc/types.js.map +1 -0
  134. package/dist/worker/protocol.d.ts +493 -0
  135. package/dist/worker/protocol.d.ts.map +1 -0
  136. package/dist/worker/protocol.js +15 -0
  137. package/dist/worker/protocol.js.map +1 -0
  138. package/package.json +59 -0
@@ -0,0 +1,115 @@
1
+ /**
2
+ * Tree editing operations
3
+ */
4
+ import { cid, LinkType } from '../types.js';
5
+ import { putDirectory } from './create.js';
6
+ import { listDirectory, resolvePath } from './read.js';
7
+ /**
8
+ * Add or update an entry in a directory
9
+ * @returns New root hash
10
+ */
11
+ export async function setEntry(config, rootHash, path, name, entryCid, size, type = LinkType.Blob, meta) {
12
+ const { store } = config;
13
+ const dirHash = await resolvePathArray(store, rootHash, path);
14
+ if (!dirHash) {
15
+ throw new Error(`Path not found: ${path.join('/')}`);
16
+ }
17
+ const entries = await listDirectory(store, dirHash);
18
+ const newEntries = entries
19
+ .filter(e => e.name !== name)
20
+ .map(e => ({ name: e.name, cid: e.cid, size: e.size, type: e.type, meta: e.meta }));
21
+ newEntries.push({ name, cid: entryCid, size, type, meta });
22
+ const newDirHash = await putDirectory(config, newEntries);
23
+ return rebuildPath(config, rootHash, path, newDirHash);
24
+ }
25
+ /**
26
+ * Remove an entry from a directory
27
+ * @returns New root hash
28
+ */
29
+ export async function removeEntry(config, rootHash, path, name) {
30
+ const { store } = config;
31
+ const dirHash = await resolvePathArray(store, rootHash, path);
32
+ if (!dirHash) {
33
+ throw new Error(`Path not found: ${path.join('/')}`);
34
+ }
35
+ const entries = await listDirectory(store, dirHash);
36
+ const newEntries = entries
37
+ .filter(e => e.name !== name)
38
+ .map(e => ({ name: e.name, cid: e.cid, size: e.size, type: e.type, meta: e.meta }));
39
+ const newDirHash = await putDirectory(config, newEntries);
40
+ return rebuildPath(config, rootHash, path, newDirHash);
41
+ }
42
+ /**
43
+ * Rename an entry in a directory
44
+ * @returns New root hash
45
+ */
46
+ export async function renameEntry(config, rootHash, path, oldName, newName) {
47
+ if (oldName === newName)
48
+ return rootHash;
49
+ const { store } = config;
50
+ const dirHash = await resolvePathArray(store, rootHash, path);
51
+ if (!dirHash) {
52
+ throw new Error(`Path not found: ${path.join('/')}`);
53
+ }
54
+ const entries = await listDirectory(store, dirHash);
55
+ const entry = entries.find(e => e.name === oldName);
56
+ if (!entry) {
57
+ throw new Error(`Entry not found: ${oldName}`);
58
+ }
59
+ const newEntries = entries
60
+ .filter(e => e.name !== oldName)
61
+ .map(e => ({ name: e.name, cid: e.cid, size: e.size, type: e.type, meta: e.meta }));
62
+ newEntries.push({ name: newName, cid: entry.cid, size: entry.size, type: entry.type, meta: entry.meta });
63
+ const newDirHash = await putDirectory(config, newEntries);
64
+ return rebuildPath(config, rootHash, path, newDirHash);
65
+ }
66
+ /**
67
+ * Move an entry to a different directory
68
+ * @returns New root hash
69
+ */
70
+ export async function moveEntry(config, rootHash, sourcePath, name, targetPath) {
71
+ const { store } = config;
72
+ const sourceDirHash = await resolvePathArray(store, rootHash, sourcePath);
73
+ if (!sourceDirHash) {
74
+ throw new Error(`Source path not found: ${sourcePath.join('/')}`);
75
+ }
76
+ const sourceEntries = await listDirectory(store, sourceDirHash);
77
+ const entry = sourceEntries.find(e => e.name === name);
78
+ if (!entry) {
79
+ throw new Error(`Entry not found: ${name}`);
80
+ }
81
+ // Remove from source
82
+ let newRoot = await removeEntry(config, rootHash, sourcePath, name);
83
+ // Add to target (preserving CID with encryption key)
84
+ newRoot = await setEntry(config, newRoot, targetPath, name, entry.cid, entry.size, entry.type);
85
+ return newRoot;
86
+ }
87
+ async function resolvePathArray(store, rootHash, path) {
88
+ if (path.length === 0)
89
+ return rootHash;
90
+ return resolvePath(store, rootHash, path.join('/'));
91
+ }
92
+ async function rebuildPath(config, rootHash, path, newChildHash) {
93
+ if (path.length === 0) {
94
+ return newChildHash;
95
+ }
96
+ const { store } = config;
97
+ let childHash = newChildHash;
98
+ const parts = [...path];
99
+ while (parts.length > 0) {
100
+ const childName = parts.pop();
101
+ const parentHash = parts.length === 0
102
+ ? rootHash
103
+ : await resolvePathArray(store, rootHash, parts);
104
+ if (!parentHash) {
105
+ throw new Error(`Parent path not found: ${parts.join('/')}`);
106
+ }
107
+ const parentEntries = await listDirectory(store, parentHash);
108
+ const newParentEntries = parentEntries.map(e => e.name === childName
109
+ ? { name: e.name, cid: cid(childHash), size: e.size, type: e.type, meta: e.meta }
110
+ : { name: e.name, cid: e.cid, size: e.size, type: e.type, meta: e.meta });
111
+ childHash = await putDirectory(config, newParentEntries);
112
+ }
113
+ return childHash;
114
+ }
115
+ //# sourceMappingURL=edit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"edit.js","sourceRoot":"","sources":["../../src/tree/edit.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAoB,GAAG,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAoC,MAAM,aAAa,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAIvD;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAC5B,MAAkB,EAClB,QAAc,EACd,IAAc,EACd,IAAY,EACZ,QAAa,EACb,IAAY,EACZ,OAAiB,QAAQ,CAAC,IAAI,EAC9B,IAA8B;IAE9B,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC;IACzB,MAAM,OAAO,GAAG,MAAM,gBAAgB,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;IAC9D,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,mBAAmB,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACvD,CAAC;IAED,MAAM,OAAO,GAAG,MAAM,aAAa,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IACpD,MAAM,UAAU,GAAe,OAAO;SACn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MAAM,IAAI,KAAK,CAAC,0BAA0B,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAC/D,CAAC;QAED,MAAM,aAAa,GAAG,MAAM,aAAa,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;QAC7D,MAAM,gBAAgB,GAAe,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CACzD,CAAC,CAAC,IAAI,KAAK,SAAS;YAClB,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE;YACjF,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAC3E,CAAC;QAEF,SAAS,GAAG,MAAM,YAAY,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IAC3D,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Encrypted tree editing operations
3
+ *
4
+ * All operations take a root key and return new hash + key.
5
+ * Keys are propagated through the tree structure.
6
+ */
7
+ import { Hash, LinkType } from '../types.js';
8
+ export { LinkType };
9
+ import { type EncryptionKey } from '../crypto.js';
10
+ import { type EncryptedTreeConfig } from '../encrypted.js';
11
+ export interface EncryptedEditConfig extends EncryptedTreeConfig {
12
+ }
13
+ /**
14
+ * Result of an encrypted edit operation
15
+ */
16
+ export interface EncryptedEditResult {
17
+ hash: Hash;
18
+ key: EncryptionKey;
19
+ }
20
+ /**
21
+ * Add or update an entry in an encrypted directory
22
+ * @param config - Tree configuration
23
+ * @param rootHash - Current root hash
24
+ * @param rootKey - Current root key
25
+ * @param path - Path to the directory containing the entry
26
+ * @param name - Name of the entry to add/update
27
+ * @param hash - Hash of the entry content
28
+ * @param size - Size of the entry content
29
+ * @param key - Encryption key of the entry (for encrypted content)
30
+ * @param type - LinkType of the entry (Blob, File, or Dir)
31
+ * @returns New root hash and key
32
+ */
33
+ export declare function setEntryEncrypted(config: EncryptedEditConfig, rootHash: Hash, rootKey: EncryptionKey, path: string[], name: string, hash: Hash, size: number, key?: EncryptionKey, type?: LinkType, meta?: Record<string, unknown>): Promise<EncryptedEditResult>;
34
+ /**
35
+ * Remove an entry from an encrypted directory
36
+ */
37
+ export declare function removeEntryEncrypted(config: EncryptedEditConfig, rootHash: Hash, rootKey: EncryptionKey, path: string[], name: string): Promise<EncryptedEditResult>;
38
+ /**
39
+ * Rename an entry in an encrypted directory
40
+ */
41
+ export declare function renameEntryEncrypted(config: EncryptedEditConfig, rootHash: Hash, rootKey: EncryptionKey, path: string[], oldName: string, newName: string): Promise<EncryptedEditResult>;
42
+ /**
43
+ * Move an entry from one directory to another in an encrypted tree
44
+ */
45
+ export declare function moveEntryEncrypted(config: EncryptedEditConfig, rootHash: Hash, rootKey: EncryptionKey, sourcePath: string[], name: string, targetPath: string[]): Promise<EncryptedEditResult>;
46
+ //# sourceMappingURL=editEncrypted.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"editEncrypted.d.ts","sourceRoot":"","sources":["../../src/tree/editEncrypted.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAS,IAAI,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,CAAC;AACpB,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAIL,KAAK,mBAAmB,EACzB,MAAM,iBAAiB,CAAC;AAEzB,MAAM,WAAW,mBAAoB,SAAQ,mBAAmB;CAAG;A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
+ * Keys are propagated through the tree structure.
6
+ */
7
+ import { LinkType } from '../types.js';
8
+ export { LinkType };
9
+ import { putDirectoryEncrypted, listDirectoryEncrypted, } from '../encrypted.js';
10
+ /**
11
+ * Resolve a path and collect keys along the way
12
+ */
13
+ async function resolvePathAndCollectKeys(store, rootHash, rootKey, path) {
14
+ const pathKeys = [];
15
+ let currentHash = rootHash;
16
+ let currentKey = rootKey;
17
+ for (const segment of path) {
18
+ const entries = await listDirectoryEncrypted(store, currentHash, currentKey);
19
+ const entry = entries.find(e => e.name === segment);
20
+ if (!entry || !entry.key) {
21
+ return null;
22
+ }
23
+ pathKeys.push(entry.key);
24
+ currentHash = entry.hash;
25
+ currentKey = entry.key;
26
+ }
27
+ return { dirHash: currentHash, dirKey: currentKey, pathKeys };
28
+ }
29
+ /**
30
+ * Add or update an entry in an encrypted directory
31
+ * @param config - Tree configuration
32
+ * @param rootHash - Current root hash
33
+ * @param rootKey - Current root key
34
+ * @param path - Path to the directory containing the entry
35
+ * @param name - Name of the entry to add/update
36
+ * @param hash - Hash of the entry content
37
+ * @param size - Size of the entry content
38
+ * @param key - Encryption key of the entry (for encrypted content)
39
+ * @param type - LinkType of the entry (Blob, File, or Dir)
40
+ * @returns New root hash and key
41
+ */
42
+ export async function setEntryEncrypted(config, rootHash, rootKey, path, name, hash, size, key, type = LinkType.Blob, meta) {
43
+ const { store } = config;
44
+ // Navigate to the target directory and collect keys
45
+ const resolved = await resolvePathAndCollectKeys(store, rootHash, rootKey, path);
46
+ if (!resolved) {
47
+ throw new Error(`Path not found: ${path.join('/')}`);
48
+ }
49
+ const { dirHash, dirKey, pathKeys } = resolved;
50
+ // List current entries
51
+ const entries = await listDirectoryEncrypted(store, dirHash, dirKey);
52
+ // Filter out existing entry and add new one
53
+ const newEntries = entries
54
+ .filter(e => e.name !== name)
55
+ .map(e => ({
56
+ name: e.name,
57
+ hash: e.hash,
58
+ size: e.size,
59
+ key: e.key,
60
+ type: e.type,
61
+ meta: e.meta,
62
+ }));
63
+ newEntries.push({ name, hash, size, key, type, meta });
64
+ // Create new encrypted directory
65
+ const newDir = await putDirectoryEncrypted(config, newEntries);
66
+ // Rebuild the path with new directory
67
+ return rebuildPathEncrypted(config, rootHash, rootKey, path, pathKeys, newDir.hash, newDir.key);
68
+ }
69
+ /**
70
+ * Remove an entry from an encrypted directory
71
+ */
72
+ export async function removeEntryEncrypted(config, rootHash, rootKey, path, name) {
73
+ const { store } = config;
74
+ const resolved = await resolvePathAndCollectKeys(store, rootHash, rootKey, path);
75
+ if (!resolved) {
76
+ throw new Error(`Path not found: ${path.join('/')}`);
77
+ }
78
+ const { dirHash, dirKey, pathKeys } = resolved;
79
+ const entries = await listDirectoryEncrypted(store, dirHash, dirKey);
80
+ const newEntries = entries
81
+ .filter(e => e.name !== name)
82
+ .map(e => ({
83
+ name: e.name,
84
+ hash: e.hash,
85
+ size: e.size,
86
+ key: e.key,
87
+ type: e.type,
88
+ meta: e.meta,
89
+ }));
90
+ const newDir = await putDirectoryEncrypted(config, newEntries);
91
+ return rebuildPathEncrypted(config, rootHash, rootKey, path, pathKeys, newDir.hash, newDir.key);
92
+ }
93
+ /**
94
+ * Rename an entry in an encrypted directory
95
+ */
96
+ export async function renameEntryEncrypted(config, rootHash, rootKey, path, oldName, newName) {
97
+ if (oldName === newName) {
98
+ return { hash: rootHash, key: rootKey };
99
+ }
100
+ const { store } = config;
101
+ const resolved = await resolvePathAndCollectKeys(store, rootHash, rootKey, path);
102
+ if (!resolved) {
103
+ throw new Error(`Path not found: ${path.join('/')}`);
104
+ }
105
+ const { dirHash, dirKey, pathKeys } = resolved;
106
+ const entries = await listDirectoryEncrypted(store, dirHash, dirKey);
107
+ const entry = entries.find(e => e.name === oldName);
108
+ if (!entry) {
109
+ throw new Error(`Entry not found: ${oldName}`);
110
+ }
111
+ const newEntries = entries
112
+ .filter(e => e.name !== oldName)
113
+ .map(e => ({
114
+ name: e.name,
115
+ hash: e.hash,
116
+ size: e.size,
117
+ key: e.key,
118
+ type: e.type,
119
+ meta: e.meta,
120
+ }));
121
+ newEntries.push({
122
+ name: newName,
123
+ hash: entry.hash,
124
+ size: entry.size,
125
+ key: entry.key,
126
+ type: entry.type,
127
+ meta: entry.meta,
128
+ });
129
+ const newDir = await putDirectoryEncrypted(config, newEntries);
130
+ return rebuildPathEncrypted(config, rootHash, rootKey, path, pathKeys, newDir.hash, newDir.key);
131
+ }
132
+ /**
133
+ * Move an entry from one directory to another in an encrypted tree
134
+ */
135
+ export async function moveEntryEncrypted(config, rootHash, rootKey, sourcePath, name, targetPath) {
136
+ const { store } = config;
137
+ // Resolve source directory
138
+ const sourceResolved = await resolvePathAndCollectKeys(store, rootHash, rootKey, sourcePath);
139
+ if (!sourceResolved) {
140
+ throw new Error(`Source path not found: ${sourcePath.join('/')}`);
141
+ }
142
+ // Get the entry to move
143
+ const sourceEntries = await listDirectoryEncrypted(store, sourceResolved.dirHash, sourceResolved.dirKey);
144
+ const entryToMove = sourceEntries.find(e => e.name === name);
145
+ if (!entryToMove) {
146
+ throw new Error(`Entry not found: ${name}`);
147
+ }
148
+ // Remove from source
149
+ const afterRemove = await removeEntryEncrypted(config, rootHash, rootKey, sourcePath, name);
150
+ // Resolve target directory in the modified tree
151
+ const targetResolved = await resolvePathAndCollectKeys(store, afterRemove.hash, afterRemove.key, targetPath);
152
+ if (!targetResolved) {
153
+ throw new Error(`Target path not found: ${targetPath.join('/')}`);
154
+ }
155
+ // Add to target
156
+ const targetEntries = await listDirectoryEncrypted(store, targetResolved.dirHash, targetResolved.dirKey);
157
+ // Check for name collision
158
+ if (targetEntries.some(e => e.name === name)) {
159
+ throw new Error(`Entry already exists in target: ${name}`);
160
+ }
161
+ const newTargetEntries = targetEntries.map(e => ({
162
+ name: e.name,
163
+ hash: e.hash,
164
+ size: e.size,
165
+ key: e.key,
166
+ type: e.type,
167
+ meta: e.meta,
168
+ }));
169
+ newTargetEntries.push({
170
+ name: entryToMove.name,
171
+ hash: entryToMove.hash,
172
+ size: entryToMove.size,
173
+ key: entryToMove.key,
174
+ type: entryToMove.type,
175
+ meta: entryToMove.meta,
176
+ });
177
+ const newTargetDir = await putDirectoryEncrypted(config, newTargetEntries);
178
+ return rebuildPathEncrypted(config, afterRemove.hash, afterRemove.key, targetPath, targetResolved.pathKeys, newTargetDir.hash, newTargetDir.key);
179
+ }
180
+ /**
181
+ * Rebuild the path from a modified child up to the root
182
+ */
183
+ async function rebuildPathEncrypted(config, rootHash, rootKey, path, pathKeys, newChildHash, newChildKey) {
184
+ if (path.length === 0) {
185
+ return { hash: newChildHash, key: newChildKey };
186
+ }
187
+ const { store } = config;
188
+ let childHash = newChildHash;
189
+ let childKey = newChildKey;
190
+ const parts = [...path];
191
+ while (parts.length > 0) {
192
+ const childName = parts.pop();
193
+ // Get parent directory
194
+ let parentHash;
195
+ let parentKey;
196
+ if (parts.length === 0) {
197
+ parentHash = rootHash;
198
+ parentKey = rootKey;
199
+ }
200
+ else {
201
+ // Use collected pathKeys to find the parent
202
+ parentHash = rootHash;
203
+ parentKey = rootKey;
204
+ for (let i = 0; i < parts.length; i++) {
205
+ const entries = await listDirectoryEncrypted(store, parentHash, parentKey);
206
+ const entry = entries.find(e => e.name === parts[i]);
207
+ if (!entry || !entry.key) {
208
+ throw new Error(`Parent path not found: ${parts.join('/')}`);
209
+ }
210
+ parentHash = entry.hash;
211
+ parentKey = pathKeys[i] ?? entry.key;
212
+ }
213
+ }
214
+ // Get parent entries and update the child
215
+ const parentEntries = await listDirectoryEncrypted(store, parentHash, parentKey);
216
+ const newParentEntries = parentEntries.map(e => e.name === childName
217
+ ? { name: e.name, hash: childHash, size: e.size, key: childKey, type: e.type, meta: e.meta }
218
+ : { name: e.name, hash: e.hash, size: e.size, key: e.key, type: e.type, meta: e.meta });
219
+ const newParent = await putDirectoryEncrypted(config, newParentEntries);
220
+ childHash = newParent.hash;
221
+ childKey = newParent.key;
222
+ }
223
+ return { hash: childHash, key: childKey };
224
+ }
225
+ //# sourceMappingURL=editEncrypted.js.map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I,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CACzF,CAAC;QAEF,MAAM,SAAS,GAAG,MAAM,qBAAqB,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;QACxE,SAAS,GAAG,SAAS,CAAC,IAAI,CAAC;QAC3B,QAAQ,GAAG,SAAS,CAAC,GAAG,CAAC;IAC3B,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC;AAC5C,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Tree operations - create, read, edit
3
+ */
4
+ export * from './create.js';
5
+ export * from './read.js';
6
+ export * from './edit.js';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tree/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Tree operations - create, read, edit
3
+ */
4
+ export * from './create.js';
5
+ export * from './read.js';
6
+ export * from './edit.js';
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tree/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC"}
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Tree reading operations
3
+ */
4
+ import { Store, Hash, TreeNode, LinkType, CID } from '../types.js';
5
+ export interface TreeEntry {
6
+ name: string;
7
+ cid: CID;
8
+ size: number;
9
+ type: LinkType;
10
+ meta?: Record<string, unknown>;
11
+ }
12
+ /**
13
+ * Get raw data by hash
14
+ */
15
+ export declare function getBlob(store: Store, hash: Hash): Promise<Uint8Array | null>;
16
+ /**
17
+ * Get and decode a tree node
18
+ */
19
+ export declare function getTreeNode(store: Store, hash: Hash): Promise<TreeNode | null>;
20
+ /**
21
+ * Get the type of a chunk by hash: File, Dir, or Blob
22
+ */
23
+ export declare function getType(store: Store, hash: Hash): Promise<LinkType>;
24
+ /**
25
+ * Check if hash points to a directory (tree with named links)
26
+ */
27
+ export declare function isDirectory(store: Store, hash: Hash): Promise<boolean>;
28
+ /**
29
+ * Read a complete file (reassemble chunks if needed)
30
+ */
31
+ export declare function readFile(store: Store, hash: Hash): Promise<Uint8Array | null>;
32
+ export interface StreamOptions {
33
+ /** Byte offset to start streaming from (default: 0) */
34
+ offset?: number;
35
+ /** Number of chunks to prefetch ahead (default: 1 = no prefetch) */
36
+ prefetch?: number;
37
+ }
38
+ /**
39
+ * Read a file with streaming
40
+ * Supports prefetching for better network performance
41
+ */
42
+ export declare function readFileStream(store: Store, hash: Hash, options?: StreamOptions): AsyncGenerator<Uint8Array>;
43
+ /**
44
+ * Read a range of bytes from a file
45
+ */
46
+ export declare function readFileRange(store: Store, hash: Hash, start: number, end?: number): Promise<Uint8Array | null>;
47
+ /**
48
+ * List directory entries
49
+ *
50
+ * Handles both small directories (single node) and large directories
51
+ * (chunked by bytes like files - reassembled then decoded).
52
+ */
53
+ export declare function listDirectory(store: Store, hash: Hash): Promise<TreeEntry[]>;
54
+ /**
55
+ * Resolve a path within a tree
56
+ *
57
+ * Handles chunked directories (reassembles bytes to get the full TreeNode).
58
+ */
59
+ export declare function resolvePath(store: Store, rootHash: Hash, path: string): Promise<Hash | null>;
60
+ /**
61
+ * Get total size of a tree
62
+ */
63
+ export declare function getSize(store: Store, hash: Hash): Promise<number>;
64
+ /**
65
+ * Walk entire tree depth-first
66
+ *
67
+ * Handles chunked directories (reassembles bytes to get the full TreeNode).
68
+ */
69
+ export declare function walk(store: Store, hash: Hash, path?: string): AsyncGenerator<{
70
+ path: string;
71
+ hash: Hash;
72
+ type: LinkType;
73
+ size?: number;
74
+ }>;
75
+ //# sourceMappingURL=read.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../../src/tree/read.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAS,GAAG,EAAO,MAAM,aAAa,CAAC;AAG/E,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,GAAG,CAAC;IACT,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,QAAQ,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChC;AAED;;GAEG;AACH,wBAAsB,OAAO,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAElF;AAED;;GAEG;AACH,wBAAsB,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAIpF;AAED;;GAEG;AACH,wBAAsB,OAAO,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,QAAQ,CAAC,CAKzE;AAED;;GAEG;AACH,wBAAsB,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,CAM5E;AAED;;GAEG;AACH,wBAAsB,QAAQ,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAWnF;AAkCD,MAAM,WAAW,aAAa;IAC5B,uDAAuD;IACvD,MAAM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