@ethersphere/bee-js 12.3.2-upcoming.116 → 13.0.0-upcoming.gc013bdf

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 (268) hide show
  1. package/dist/cjs/api/balance.js +24 -0
  2. package/dist/cjs/api/batches.js +26 -0
  3. package/dist/cjs/{modules → api}/bytes.js +4 -29
  4. package/dist/cjs/{modules → api}/bzz.js +6 -34
  5. package/dist/cjs/{modules/debug → api}/chequebook.js +48 -87
  6. package/dist/cjs/api/chunk.js +43 -0
  7. package/dist/cjs/api/connectivity.js +86 -0
  8. package/dist/cjs/api/consumed.js +24 -0
  9. package/dist/cjs/{modules → api}/envelope.js +3 -2
  10. package/dist/cjs/api/feed.js +55 -0
  11. package/dist/cjs/api/grantee.js +62 -0
  12. package/dist/cjs/{modules/pinning.js → api/pin.js} +13 -34
  13. package/dist/cjs/api/pss.js +19 -0
  14. package/dist/cjs/api/redistributionstate.js +17 -0
  15. package/dist/cjs/{modules/debug/settlements.js → api/settlement.js} +3 -11
  16. package/dist/cjs/api/soc.js +34 -0
  17. package/dist/cjs/{modules/debug → api}/stake.js +15 -43
  18. package/dist/cjs/{modules/debug/stamps.js → api/stamp.js} +41 -57
  19. package/dist/cjs/api/status.js +67 -0
  20. package/dist/cjs/{modules → api}/stewardship.js +1 -6
  21. package/dist/cjs/api/tag.js +51 -0
  22. package/dist/cjs/{modules/debug/transactions.js → api/transaction.js} +10 -31
  23. package/dist/cjs/{modules/debug/states.js → api/wallet.js} +4 -36
  24. package/dist/cjs/bee.js +115 -1978
  25. package/dist/cjs/chunk/soc.js +23 -65
  26. package/dist/cjs/feed/identifier.js +3 -4
  27. package/dist/cjs/feed/index.js +20 -22
  28. package/dist/cjs/feed/retrievable.js +3 -3
  29. package/dist/cjs/index.js +18 -8
  30. package/dist/cjs/manifest/manifest.js +99 -335
  31. package/dist/cjs/modules/balance.js +86 -0
  32. package/dist/cjs/modules/cheque.js +92 -0
  33. package/dist/cjs/modules/chequebook.js +90 -0
  34. package/dist/cjs/modules/chunk.js +87 -53
  35. package/dist/cjs/modules/collection.js +145 -0
  36. package/dist/cjs/modules/connectivity.js +141 -0
  37. package/dist/cjs/modules/context.js +2 -0
  38. package/dist/cjs/modules/data.js +119 -0
  39. package/dist/cjs/modules/feed.js +94 -70
  40. package/dist/cjs/modules/file.js +113 -0
  41. package/dist/cjs/modules/grantee.js +86 -55
  42. package/dist/cjs/modules/messaging.js +248 -0
  43. package/dist/cjs/modules/pin.js +100 -0
  44. package/dist/cjs/modules/settlement.js +67 -0
  45. package/dist/cjs/modules/soc.js +39 -36
  46. package/dist/cjs/modules/stake.js +110 -0
  47. package/dist/cjs/modules/stamp.js +199 -0
  48. package/dist/cjs/modules/status.js +128 -20
  49. package/dist/cjs/modules/storage.js +191 -0
  50. package/dist/cjs/modules/tag.js +97 -71
  51. package/dist/cjs/modules/transaction.js +92 -0
  52. package/dist/cjs/modules/wallet.js +82 -0
  53. package/dist/cjs/types/schema/chequebook.js +5 -5
  54. package/dist/cjs/types/schema/connectivity.js +5 -5
  55. package/dist/cjs/types/schema/envelope.js +5 -5
  56. package/dist/cjs/types/schema/grantee.js +4 -4
  57. package/dist/cjs/types/schema/stake.js +2 -2
  58. package/dist/cjs/types/schema/stamps.js +4 -4
  59. package/dist/cjs/types/schema/states.js +2 -2
  60. package/dist/cjs/types/schema/transactions.js +3 -3
  61. package/dist/cjs/types/schema/upload.js +2 -2
  62. package/dist/cjs/utils/chunk-stream.browser.js +24 -16
  63. package/dist/cjs/utils/chunk-stream.js +17 -9
  64. package/dist/cjs/utils/constants.js +3 -3
  65. package/dist/cjs/utils/expose.js +4 -4
  66. package/dist/cjs/utils/headers.js +4 -4
  67. package/dist/cjs/utils/pss.js +2 -2
  68. package/dist/cjs/utils/resource-locator.js +2 -2
  69. package/dist/cjs/utils/schema.js +4 -4
  70. package/dist/cjs/utils/stamps.js +15 -130
  71. package/dist/index.browser.min.js +2 -1
  72. package/dist/index.browser.min.js.LICENSE.txt +3 -0
  73. package/dist/index.browser.min.js.map +1 -1
  74. package/dist/mjs/api/balance.js +20 -0
  75. package/dist/mjs/api/batches.js +22 -0
  76. package/dist/mjs/{modules → api}/bytes.js +2 -27
  77. package/dist/mjs/{modules → api}/bzz.js +2 -30
  78. package/dist/mjs/{modules/debug → api}/chequebook.js +50 -89
  79. package/dist/mjs/api/chunk.js +37 -0
  80. package/dist/mjs/api/connectivity.js +76 -0
  81. package/dist/mjs/api/consumed.js +20 -0
  82. package/dist/mjs/{modules → api}/envelope.js +3 -2
  83. package/dist/mjs/api/feed.js +52 -0
  84. package/dist/mjs/api/grantee.js +59 -0
  85. package/dist/mjs/{modules/pinning.js → api/pin.js} +14 -35
  86. package/dist/mjs/api/pss.js +18 -0
  87. package/dist/mjs/api/redistributionstate.js +14 -0
  88. package/dist/mjs/{modules/debug/settlements.js → api/settlement.js} +3 -11
  89. package/dist/mjs/api/soc.js +31 -0
  90. package/dist/mjs/{modules/debug → api}/stake.js +14 -41
  91. package/dist/mjs/{modules/debug/stamps.js → api/stamp.js} +37 -51
  92. package/dist/mjs/api/status.js +59 -0
  93. package/dist/mjs/{modules → api}/stewardship.js +1 -6
  94. package/dist/mjs/api/tag.js +49 -0
  95. package/dist/mjs/api/transaction.js +41 -0
  96. package/dist/mjs/api/wallet.js +38 -0
  97. package/dist/mjs/bee.js +115 -1965
  98. package/dist/mjs/chunk/soc.js +13 -51
  99. package/dist/mjs/feed/identifier.js +2 -3
  100. package/dist/mjs/feed/index.js +9 -11
  101. package/dist/mjs/feed/retrievable.js +2 -2
  102. package/dist/mjs/index.js +2 -5
  103. package/dist/mjs/manifest/manifest.js +97 -341
  104. package/dist/mjs/modules/balance.js +49 -0
  105. package/dist/mjs/modules/cheque.js +55 -0
  106. package/dist/mjs/modules/chequebook.js +65 -0
  107. package/dist/mjs/modules/chunk.js +52 -49
  108. package/dist/mjs/modules/collection.js +108 -0
  109. package/dist/mjs/modules/connectivity.js +102 -0
  110. package/dist/mjs/modules/context.js +1 -0
  111. package/dist/mjs/modules/data.js +82 -0
  112. package/dist/mjs/modules/feed.js +89 -67
  113. package/dist/mjs/modules/file.js +78 -0
  114. package/dist/mjs/modules/grantee.js +52 -55
  115. package/dist/mjs/modules/messaging.js +213 -0
  116. package/dist/mjs/modules/pin.js +63 -0
  117. package/dist/mjs/modules/settlement.js +30 -0
  118. package/dist/mjs/modules/soc.js +36 -34
  119. package/dist/mjs/modules/stake.js +76 -0
  120. package/dist/mjs/modules/stamp.js +170 -0
  121. package/dist/mjs/modules/status.js +98 -18
  122. package/dist/mjs/modules/storage.js +185 -0
  123. package/dist/mjs/modules/tag.js +61 -68
  124. package/dist/mjs/modules/transaction.js +58 -0
  125. package/dist/mjs/modules/wallet.js +45 -0
  126. package/dist/mjs/types/schema/chequebook.js +1 -1
  127. package/dist/mjs/types/schema/connectivity.js +1 -1
  128. package/dist/mjs/types/schema/envelope.js +5 -5
  129. package/dist/mjs/types/schema/grantee.js +1 -1
  130. package/dist/mjs/types/schema/stake.js +1 -1
  131. package/dist/mjs/types/schema/stamps.js +1 -1
  132. package/dist/mjs/types/schema/states.js +1 -1
  133. package/dist/mjs/types/schema/transactions.js +1 -1
  134. package/dist/mjs/types/schema/upload.js +1 -1
  135. package/dist/mjs/utils/chunk-stream.browser.js +28 -18
  136. package/dist/mjs/utils/chunk-stream.js +21 -11
  137. package/dist/mjs/utils/constants.js +1 -1
  138. package/dist/mjs/utils/expose.js +1 -1
  139. package/dist/mjs/utils/headers.js +1 -1
  140. package/dist/mjs/utils/pss.js +1 -1
  141. package/dist/mjs/utils/resource-locator.js +1 -1
  142. package/dist/mjs/utils/schema.js +1 -1
  143. package/dist/mjs/utils/stamps.js +5 -99
  144. package/dist/types/api/balance.d.ts +7 -0
  145. package/dist/types/api/batches.d.ts +7 -0
  146. package/dist/types/api/bytes.d.ts +11 -0
  147. package/dist/types/api/bzz.d.ts +12 -0
  148. package/dist/types/api/chequebook.d.ts +21 -0
  149. package/dist/types/api/chunk.d.ts +7 -0
  150. package/dist/types/api/connectivity.d.ts +22 -0
  151. package/dist/types/api/consumed.d.ts +7 -0
  152. package/dist/types/{modules → api}/envelope.d.ts +1 -1
  153. package/dist/types/api/feed.d.ts +40 -0
  154. package/dist/types/api/grantee.d.ts +11 -0
  155. package/dist/types/api/pin.d.ts +10 -0
  156. package/dist/types/api/pss.d.ts +6 -0
  157. package/dist/types/api/redistributionstate.d.ts +5 -0
  158. package/dist/types/api/settlement.d.ts +7 -0
  159. package/dist/types/api/soc.d.ts +6 -0
  160. package/dist/types/api/stake.d.ts +11 -0
  161. package/dist/types/api/stamp.d.ts +12 -0
  162. package/dist/types/api/status.d.ts +11 -0
  163. package/dist/types/api/stewardship.d.ts +7 -0
  164. package/dist/types/api/tag.d.ts +12 -0
  165. package/dist/types/api/transaction.d.ts +9 -0
  166. package/dist/types/api/wallet.d.ts +9 -0
  167. package/dist/types/bee.d.ts +71 -1199
  168. package/dist/types/chunk/soc.d.ts +3 -48
  169. package/dist/types/feed/identifier.d.ts +1 -1
  170. package/dist/types/feed/index.d.ts +2 -4
  171. package/dist/types/feed/retrievable.d.ts +1 -1
  172. package/dist/types/index.d.ts +17 -20
  173. package/dist/types/manifest/manifest.d.ts +25 -34
  174. package/dist/types/modules/balance.d.ts +38 -0
  175. package/dist/types/modules/cheque.d.ts +40 -0
  176. package/dist/types/modules/chequebook.d.ts +41 -0
  177. package/dist/types/modules/chunk.d.ts +30 -20
  178. package/dist/types/modules/collection.d.ts +77 -0
  179. package/dist/types/modules/connectivity.d.ts +74 -0
  180. package/dist/types/modules/context.d.ts +24 -0
  181. package/dist/types/modules/data.d.ts +55 -0
  182. package/dist/types/modules/feed.d.ts +47 -49
  183. package/dist/types/modules/file.d.ts +43 -0
  184. package/dist/types/modules/grantee.d.ts +40 -8
  185. package/dist/types/modules/messaging.d.ts +79 -0
  186. package/dist/types/modules/pin.d.ts +47 -0
  187. package/dist/types/modules/settlement.d.ts +25 -0
  188. package/dist/types/modules/soc.d.ts +23 -11
  189. package/dist/types/modules/stake.d.ts +55 -0
  190. package/dist/types/modules/stamp.d.ts +96 -0
  191. package/dist/types/modules/status.d.ts +66 -5
  192. package/dist/types/modules/storage.d.ts +107 -0
  193. package/dist/types/modules/tag.d.ts +44 -33
  194. package/dist/types/modules/transaction.d.ts +42 -0
  195. package/dist/types/modules/wallet.d.ts +35 -0
  196. package/dist/types/types/debug.d.ts +1 -1
  197. package/dist/types/types/index.d.ts +3 -12
  198. package/dist/types/types/schema/chequebook.d.ts +1 -1
  199. package/dist/types/types/schema/connectivity.d.ts +1 -1
  200. package/dist/types/types/schema/grantee.d.ts +1 -1
  201. package/dist/types/types/schema/stake.d.ts +1 -1
  202. package/dist/types/types/schema/stamps.d.ts +1 -1
  203. package/dist/types/types/schema/states.d.ts +1 -1
  204. package/dist/types/types/schema/transactions.d.ts +1 -1
  205. package/dist/types/types/schema/upload.d.ts +1 -1
  206. package/dist/types/utils/chunk-stream.browser.d.ts +1 -1
  207. package/dist/types/utils/chunk-stream.d.ts +2 -2
  208. package/dist/types/utils/constants.d.ts +1 -1
  209. package/dist/types/utils/expose.d.ts +1 -1
  210. package/dist/types/utils/headers.d.ts +1 -1
  211. package/dist/types/utils/pss.d.ts +1 -1
  212. package/dist/types/utils/resource-locator.d.ts +1 -1
  213. package/dist/types/utils/schema.d.ts +1 -1
  214. package/dist/types/utils/stamps.d.ts +2 -27
  215. package/dist/types/utils/tar-uploader.browser.d.ts +1 -1
  216. package/dist/types/utils/tar-uploader.d.ts +1 -1
  217. package/package.json +4 -2
  218. package/dist/cjs/chunk/bmt.js +0 -37
  219. package/dist/cjs/chunk/cac.js +0 -43
  220. package/dist/cjs/modules/debug/balance.js +0 -60
  221. package/dist/cjs/modules/debug/connectivity.js +0 -54
  222. package/dist/cjs/modules/debug/status.js +0 -104
  223. package/dist/cjs/modules/gsoc.js +0 -23
  224. package/dist/cjs/modules/pss.js +0 -48
  225. package/dist/cjs/stamper/stamper.js +0 -44
  226. package/dist/cjs/utils/bytes.js +0 -116
  227. package/dist/cjs/utils/cid.js +0 -37
  228. package/dist/cjs/utils/redundancy.js +0 -133
  229. package/dist/cjs/utils/typed-bytes.js +0 -186
  230. package/dist/mjs/chunk/bmt.js +0 -34
  231. package/dist/mjs/chunk/cac.js +0 -34
  232. package/dist/mjs/modules/debug/balance.js +0 -54
  233. package/dist/mjs/modules/debug/connectivity.js +0 -46
  234. package/dist/mjs/modules/debug/states.js +0 -68
  235. package/dist/mjs/modules/debug/status.js +0 -99
  236. package/dist/mjs/modules/debug/transactions.js +0 -62
  237. package/dist/mjs/modules/gsoc.js +0 -16
  238. package/dist/mjs/modules/pss.js +0 -43
  239. package/dist/mjs/stamper/stamper.js +0 -40
  240. package/dist/mjs/utils/bytes.js +0 -102
  241. package/dist/mjs/utils/cid.js +0 -32
  242. package/dist/mjs/utils/redundancy.js +0 -98
  243. package/dist/mjs/utils/typed-bytes.js +0 -167
  244. package/dist/types/chunk/bmt.d.ts +0 -16
  245. package/dist/types/chunk/cac.d.ts +0 -40
  246. package/dist/types/modules/bytes.d.ts +0 -35
  247. package/dist/types/modules/bzz.d.ts +0 -40
  248. package/dist/types/modules/debug/balance.d.ts +0 -28
  249. package/dist/types/modules/debug/chequebook.d.ts +0 -60
  250. package/dist/types/modules/debug/connectivity.d.ts +0 -9
  251. package/dist/types/modules/debug/settlements.d.ts +0 -15
  252. package/dist/types/modules/debug/stake.d.ts +0 -30
  253. package/dist/types/modules/debug/stamps.d.ts +0 -11
  254. package/dist/types/modules/debug/states.d.ts +0 -23
  255. package/dist/types/modules/debug/status.d.ts +0 -46
  256. package/dist/types/modules/debug/transactions.d.ts +0 -30
  257. package/dist/types/modules/gsoc.d.ts +0 -6
  258. package/dist/types/modules/pinning.d.ts +0 -30
  259. package/dist/types/modules/pss.d.ts +0 -22
  260. package/dist/types/modules/stewardship.d.ts +0 -10
  261. package/dist/types/stamper/stamper.d.ts +0 -15
  262. package/dist/types/utils/bytes.d.ts +0 -19
  263. package/dist/types/utils/cid.d.ts +0 -10
  264. package/dist/types/utils/redundancy.d.ts +0 -21
  265. package/dist/types/utils/typed-bytes.d.ts +0 -69
  266. /package/dist/cjs/{modules → api}/rchash.js +0 -0
  267. /package/dist/mjs/{modules → api}/rchash.js +0 -0
  268. /package/dist/types/{modules → api}/rchash.d.ts +0 -0
@@ -0,0 +1,107 @@
1
+ import { BatchId, TransactionId } from 'swarm-core';
2
+ import type { BeeRequestOptions, PostageBatchOptions, RedundancyLevel } from '../types';
3
+ import type { Duration } from '../utils/duration';
4
+ import type { Size } from '../utils/size';
5
+ import type { BZZ } from '../utils/tokens';
6
+ import type { BeeContext } from './context';
7
+ /**
8
+ * Ergonomic storage operations expressed in terms of size and duration.
9
+ *
10
+ * Accessed as `bee.storage`. Wraps the low-level `bee.stamp` operations.
11
+ */
12
+ export declare class Storage {
13
+ private readonly context;
14
+ constructor(context: BeeContext);
15
+ private get blockTime();
16
+ /**
17
+ * Creates a postage batch sized for a certain size and duration on the Swarm network.
18
+ *
19
+ * Use {@link getCost} to calculate the cost beforehand.
20
+ *
21
+ * @param size
22
+ * @param duration
23
+ * @param options
24
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
25
+ * @param encryption
26
+ * @param erasureCodeLevel
27
+ */
28
+ buy(size: Size, duration: Duration, options?: PostageBatchOptions, requestOptions?: BeeRequestOptions, encryption?: boolean, erasureCodeLevel?: RedundancyLevel): Promise<BatchId>;
29
+ /**
30
+ * Calculates the estimated BZZ cost for creating a postage batch for the given size and duration.
31
+ *
32
+ * @param size Size of the data to be stored.
33
+ * @param duration Duration for which the data should be stored.
34
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
35
+ * @param encryption Assume the future uploaded data is encrypted, which skews the capacity of the postage batch.
36
+ * @param erasureCodeLevel Assume the future uploaded data is erasure coded, which skews the capacity of the postage batch.
37
+ */
38
+ getCost(size: Size, duration: Duration, requestOptions?: BeeRequestOptions, encryption?: boolean, erasureCodeLevel?: RedundancyLevel): Promise<BZZ>;
39
+ /**
40
+ * Extends the storage of a postage batch by either increasing its size, duration or both.
41
+ *
42
+ * The size is ABSOLUTE, while the duration is RELATIVE to the current duration of the postage batch.
43
+ *
44
+ * @param postageBatchId Batch ID of the postage batch to extend.
45
+ * @param size Absolute size to extend the postage batch to.
46
+ * @param duration Relative duration to extend the postage batch by.
47
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
48
+ * @param encryption Assume the future uploaded data is encrypted, which skews the capacity of the postage batch.
49
+ * @param erasureCodeLevel Assume the future uploaded data is erasure coded, which skews the capacity of the postage batch.
50
+ */
51
+ extend(postageBatchId: BatchId | Uint8Array | string, size: Size, duration: Duration, requestOptions?: BeeRequestOptions, encryption?: boolean, erasureCodeLevel?: RedundancyLevel): Promise<BatchId | TransactionId>;
52
+ /**
53
+ * Extends the storage size of a postage batch by increasing its depth.
54
+ *
55
+ * @param postageBatchId
56
+ * @param size Absolute size to extend the postage batch to.
57
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
58
+ * @param encryption Assume the future uploaded data is encrypted, which skews the capacity of the postage batch.
59
+ * @param erasureCodeLevel Assume the future uploaded data is erasure coded, which skews the capacity of the postage batch.
60
+ */
61
+ extendSize(postageBatchId: BatchId | Uint8Array | string, size: Size, requestOptions?: BeeRequestOptions, encryption?: boolean, erasureCodeLevel?: RedundancyLevel): Promise<BatchId>;
62
+ /**
63
+ * Extends the duration of a postage batch.
64
+ *
65
+ * @param postageBatchId
66
+ * @param duration Relative duration to extend the postage batch by.
67
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
68
+ */
69
+ extendDuration(postageBatchId: BatchId | Uint8Array | string, duration: Duration, requestOptions?: BeeRequestOptions): Promise<BatchId>;
70
+ /**
71
+ * Calculates the cost of extending both the duration and the capacity of a postage batch.
72
+ *
73
+ * @param postageBatchId
74
+ * @param size Absolute size to extend the postage batch to.
75
+ * @param duration Relative duration to extend the postage batch by.
76
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
77
+ * @param encryption Assume the future uploaded data is encrypted, which skews the capacity of the postage batch.
78
+ * @param erasureCodeLevel Assume the future uploaded data is erasure coded, which skews the capacity of the postage batch.
79
+ */
80
+ getExtensionCost(postageBatchId: BatchId | Uint8Array | string, size: Size, duration: Duration, requestOptions?: BeeRequestOptions, encryption?: boolean, erasureCodeLevel?: RedundancyLevel): Promise<BZZ>;
81
+ /**
82
+ * Calculates the cost of extending the size of a postage batch.
83
+ *
84
+ * @param postageBatchId
85
+ * @param size
86
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
87
+ * @param encryption Assume the future uploaded data is encrypted, which skews the capacity of the postage batch.
88
+ * @param erasureCodeLevel Assume the future uploaded data is erasure coded, which skews the capacity of the postage batch.
89
+ */
90
+ getSizeExtensionCost(postageBatchId: BatchId | Uint8Array | string, size: Size, requestOptions?: BeeRequestOptions, encryption?: boolean, erasureCodeLevel?: RedundancyLevel): Promise<BZZ>;
91
+ /**
92
+ * Calculates the cost of extending the duration of a postage batch.
93
+ *
94
+ * @param postageBatchId
95
+ * @param duration
96
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
97
+ */
98
+ getDurationExtensionCost(postageBatchId: BatchId | Uint8Array | string, duration: Duration, requestOptions?: BeeRequestOptions): Promise<BZZ>;
99
+ /**
100
+ * Renames a storage. Convenience wrapper over `bee.stamp.updateLabel`.
101
+ *
102
+ * @param postageBatchId Batch ID of the postage batch to update.
103
+ * @param newLabel New name for the storage.
104
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
105
+ */
106
+ rename(postageBatchId: BatchId | Uint8Array | string, newLabel: string, requestOptions?: BeeRequestOptions): Promise<void>;
107
+ }
@@ -1,36 +1,47 @@
1
- import { BeeRequestOptions, Tag } from '../types';
2
- import { Reference } from '../utils/typed-bytes';
1
+ import { Reference } from 'swarm-core';
2
+ import type { AllTagsOptions, BeeRequestOptions, Tag as TagData } from '../types';
3
+ import type { BeeContext } from './context';
3
4
  /**
4
- * Create new tag on the Bee node
5
+ * Tag operations for tracking upload and synchronization progress.
5
6
  *
6
- * @param url Bee tag URL
7
+ * Accessed as `bee.tag`.
7
8
  */
8
- export declare function createTag(requestOptions: BeeRequestOptions): Promise<Tag>;
9
- /**
10
- * Retrieve tag information from Bee node
11
- *
12
- * @param url Bee tag URL
13
- * @param uid UID of tag to be retrieved
14
- */
15
- export declare function retrieveTag(requestOptions: BeeRequestOptions, uid: number): Promise<Tag>;
16
- /**
17
- * Get limited listing of all tags.
18
- *
19
- * @param url
20
- * @param offset
21
- * @param limit
22
- */
23
- export declare function getAllTags(requestOptions: BeeRequestOptions, offset?: number, limit?: number): Promise<Tag[]>;
24
- /**
25
- * Removes tag from the Bee node.
26
- * @param url
27
- * @param uid
28
- */
29
- export declare function deleteTag(requestOptions: BeeRequestOptions, uid: number): Promise<void>;
30
- /**
31
- * Updates tag
32
- * @param url
33
- * @param uid
34
- * @param reference
35
- */
36
- export declare function updateTag(requestOptions: BeeRequestOptions, uid: number, reference: Reference): Promise<void>;
9
+ export declare class Tag {
10
+ private readonly context;
11
+ constructor(context: BeeContext);
12
+ /**
13
+ * Creates a new tag which is meant for tracking upload and synchronization progress.
14
+ *
15
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
16
+ */
17
+ create(requestOptions?: BeeRequestOptions): Promise<TagData>;
18
+ /**
19
+ * Fetches all tags in a paginated manner.
20
+ *
21
+ * @param options Specify `limit` and `offset` to paginate through the tags.
22
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
23
+ */
24
+ getAll(options?: AllTagsOptions, requestOptions?: BeeRequestOptions): Promise<TagData[]>;
25
+ /**
26
+ * Retrieves tag information from the Bee node.
27
+ *
28
+ * @param tagUid UID or tag object to be retrieved
29
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
30
+ */
31
+ get(tagUid: number | TagData, requestOptions?: BeeRequestOptions): Promise<TagData>;
32
+ /**
33
+ * Deletes a tag.
34
+ *
35
+ * @param tagUid UID or tag object to be deleted
36
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
37
+ */
38
+ delete(tagUid: number | TagData, requestOptions?: BeeRequestOptions): Promise<void>;
39
+ /**
40
+ * Updates a tag's total chunks count.
41
+ *
42
+ * @param tagUid UID or tag object to be updated
43
+ * @param reference The root reference that contains all the chunks to be counted
44
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
45
+ */
46
+ update(tagUid: number | TagData, reference: Reference | string, requestOptions?: BeeRequestOptions): Promise<void>;
47
+ }
@@ -0,0 +1,42 @@
1
+ import { TransactionId } from 'swarm-core';
2
+ import type { BeeRequestOptions, NumberString, TransactionInfo } from '../types';
3
+ import type { BeeContext } from './context';
4
+ /**
5
+ * Pending transaction operations for the Bee node's `/transactions` queue.
6
+ *
7
+ * Accessed as `bee.transaction`.
8
+ */
9
+ export declare class Transaction {
10
+ private readonly context;
11
+ constructor(context: BeeContext);
12
+ /**
13
+ * Fetches the list of all current pending transactions for the Bee node.
14
+ *
15
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
16
+ */
17
+ getAll(requestOptions?: BeeRequestOptions): Promise<TransactionInfo[]>;
18
+ /**
19
+ * Fetches the transaction information for a specific pending transaction.
20
+ *
21
+ * @param transactionHash Hash of the transaction
22
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
23
+ */
24
+ get(transactionHash: TransactionId | Uint8Array | string, requestOptions?: BeeRequestOptions): Promise<TransactionInfo>;
25
+ /**
26
+ * Rebroadcasts an already created pending transaction.
27
+ *
28
+ * Mainly needed when the transaction falls off the mempool or is not incorporated into any block.
29
+ *
30
+ * @param transactionHash Hash of the transaction
31
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
32
+ */
33
+ rebroadcast(transactionHash: TransactionId | Uint8Array | string, requestOptions?: BeeRequestOptions): Promise<TransactionId>;
34
+ /**
35
+ * Cancels a currently pending transaction.
36
+ *
37
+ * @param transactionHash Hash of the transaction
38
+ * @param gasPrice Optional gas price
39
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
40
+ */
41
+ cancel(transactionHash: TransactionId | Uint8Array | string, gasPrice?: NumberString | string | bigint, requestOptions?: BeeRequestOptions): Promise<TransactionId>;
42
+ }
@@ -0,0 +1,35 @@
1
+ import { EthAddress, TransactionId } from 'swarm-core';
2
+ import type { BeeRequestOptions, NumberString, WalletBalance } from '../types';
3
+ import { BZZ, DAI } from '../utils/tokens';
4
+ import type { BeeContext } from './context';
5
+ /**
6
+ * Node wallet operations (balances and external withdrawals).
7
+ *
8
+ * Accessed as `bee.wallet`.
9
+ */
10
+ export declare class Wallet {
11
+ private readonly context;
12
+ constructor(context: BeeContext);
13
+ /**
14
+ * Gets DAI and BZZ balances of the Bee node wallet.
15
+ *
16
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
17
+ */
18
+ getBalance(requestOptions?: BeeRequestOptions): Promise<WalletBalance>;
19
+ /**
20
+ * Withdraws BZZ from the node wallet (not chequebook) to a whitelisted external wallet address.
21
+ *
22
+ * @param amount Amount of BZZ tokens to withdraw. If not providing a `BZZ` instance, the amount is denoted in PLUR.
23
+ * @param address
24
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
25
+ */
26
+ withdrawBZZ(amount: BZZ | NumberString | string | bigint, address: EthAddress | Uint8Array | string, requestOptions?: BeeRequestOptions): Promise<TransactionId>;
27
+ /**
28
+ * Withdraws DAI from the node wallet (not chequebook) to a whitelisted external wallet address.
29
+ *
30
+ * @param amount Amount of DAI tokens to withdraw. If not providing a `DAI` instance, the amount is denoted in wei.
31
+ * @param address
32
+ * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
33
+ */
34
+ withdrawDAI(amount: DAI | NumberString | string | bigint, address: EthAddress | Uint8Array | string, requestOptions?: BeeRequestOptions): Promise<TransactionId>;
35
+ }
@@ -1,5 +1,5 @@
1
+ import { EthAddress, PeerAddress, PublicKey, TransactionId } from 'swarm-core';
1
2
  import { BZZ, DAI } from '../utils/tokens';
2
- import { EthAddress, PeerAddress, PublicKey, TransactionId } from '../utils/typed-bytes';
3
3
  import { NumberString } from './index';
4
4
  export interface Settlements {
5
5
  peer: string;
@@ -1,12 +1,11 @@
1
+ import { BatchId, Bytes, EthAddress, Identifier, PrivateKey, PublicKey, Reference, Topic, TransactionId } from 'swarm-core';
1
2
  import { Optional } from 'cafe-utility';
2
3
  import type { SingleOwnerChunk } from '../chunk/soc';
3
4
  import type { FeedUploadOptions } from '../feed';
4
- import type { FeedPayloadResult, FeedReferenceResult, FeedUpdateOptions } from '../modules/feed';
5
- import { Bytes } from '../utils/bytes';
5
+ import type { FeedPayloadResult, FeedReferenceResult, FeedUpdateOptions } from '../api/feed';
6
6
  import { Duration } from '../utils/duration';
7
7
  import type { BeeError } from '../utils/error';
8
8
  import { Size } from '../utils/size';
9
- import { BatchId, EthAddress, Identifier, PrivateKey, PublicKey, Reference, Topic, TransactionId } from '../utils/typed-bytes';
10
9
  export * from './debug';
11
10
  export declare const SECTION_SIZE = 32;
12
11
  export declare const BRANCHES = 128;
@@ -516,15 +515,7 @@ export interface PostageBatchOptions {
516
515
  */
517
516
  waitForUsableTimeout?: number;
518
517
  }
519
- export interface Envelope {
520
- issuer: Uint8Array;
521
- index: Uint8Array;
522
- timestamp: Uint8Array;
523
- signature: Uint8Array;
524
- }
525
- export interface EnvelopeWithBatchId extends Envelope {
526
- batchId: BatchId;
527
- }
518
+ export type { Envelope, EnvelopeWithBatchId } from 'swarm-core';
528
519
  /**
529
520
  * With this type a number should be represented in a string
530
521
  */
@@ -1,6 +1,6 @@
1
+ import { EthAddress, TransactionId } from 'swarm-core';
1
2
  import { z } from 'zod';
2
3
  import { BZZ } from '../../utils/tokens';
3
- import { EthAddress, TransactionId } from '../../utils/typed-bytes';
4
4
  export declare const GetChequebookAddressResponse: z.ZodObject<{
5
5
  chequebookAddress: z.ZodPipe<z.ZodString, z.ZodTransform<EthAddress, string>>;
6
6
  }, z.core.$strip>;
@@ -1,5 +1,5 @@
1
+ import { EthAddress, PeerAddress, PublicKey } from 'swarm-core';
1
2
  import { z } from 'zod';
2
- import { EthAddress, PeerAddress, PublicKey } from '../../utils/typed-bytes';
3
3
  export declare const GetNodeAddressesResponse: z.ZodObject<{
4
4
  overlay: z.ZodPipe<z.ZodString, z.ZodTransform<PeerAddress, string>>;
5
5
  underlay: z.ZodArray<z.ZodString>;
@@ -1,5 +1,5 @@
1
+ import { PublicKey, Reference } from 'swarm-core';
1
2
  import { z } from 'zod';
2
- import { PublicKey, Reference } from '../../utils/typed-bytes';
3
3
  export declare const GetGranteesBodyResponse: z.ZodArray<z.ZodPipe<z.ZodString, z.ZodTransform<PublicKey, string>>>;
4
4
  export declare const GranteesResultBodyResponse: z.ZodObject<{
5
5
  ref: z.ZodPipe<z.ZodString, z.ZodTransform<Reference, string>>;
@@ -1,6 +1,6 @@
1
+ import { TransactionId } from 'swarm-core';
1
2
  import { z } from 'zod';
2
3
  import { BZZ, DAI } from '../../utils/tokens';
3
- import { TransactionId } from '../../utils/typed-bytes';
4
4
  export declare const GetStakeResponse: z.ZodObject<{
5
5
  stakedAmount: z.ZodPipe<z.ZodString, z.ZodTransform<BZZ, string>>;
6
6
  }, z.core.$strip>;
@@ -1,5 +1,5 @@
1
+ import { BatchId, EthAddress } from 'swarm-core';
1
2
  import { z } from 'zod';
2
- import { BatchId, EthAddress } from '../../utils/typed-bytes';
3
3
  export declare const RawPostageBatchSchema: z.ZodObject<{
4
4
  batchID: z.ZodString;
5
5
  utilization: z.ZodNumber;
@@ -1,6 +1,6 @@
1
+ import { TransactionId } from 'swarm-core';
1
2
  import { z } from 'zod';
2
3
  import { BZZ, DAI } from '../../utils/tokens';
3
- import { TransactionId } from '../../utils/typed-bytes';
4
4
  export declare const GetReserveStateResponse: z.ZodObject<{
5
5
  commitment: z.ZodNumber;
6
6
  radius: z.ZodNumber;
@@ -1,5 +1,5 @@
1
+ import { TransactionId } from 'swarm-core';
1
2
  import { z } from 'zod';
2
- import { TransactionId } from '../../utils/typed-bytes';
3
3
  export declare const GetAllTransactionsResponse: z.ZodObject<{
4
4
  pendingTransactions: z.ZodArray<z.ZodObject<{
5
5
  transactionHash: z.ZodPipe<z.ZodString, z.ZodTransform<TransactionId, string>>;
@@ -1,5 +1,5 @@
1
+ import { Reference } from 'swarm-core';
1
2
  import { z } from 'zod';
2
- import { Reference } from '../../utils/typed-bytes';
3
3
  export declare const UploadResultBody: z.ZodObject<{
4
4
  reference: z.ZodPipe<z.ZodString, z.ZodTransform<Reference, string>>;
5
5
  }, z.core.$strip>;
@@ -1,6 +1,6 @@
1
1
  import { Bee, BeeRequestOptions, UploadOptions, UploadResult } from '..';
2
- import { BatchId, Reference } from './typed-bytes';
3
2
  import { UploadProgress } from './upload-progress';
3
+ import { BatchId, Reference } from 'swarm-core';
4
4
  export declare function hashDirectory(_dir: string): Promise<void>;
5
5
  export declare function streamDirectory(_bee: Bee, _dir: string, _postageBatchId: BatchId | string | Uint8Array, _onUploadProgress?: (progress: UploadProgress) => void, _options?: UploadOptions, _requestOptions?: BeeRequestOptions): Promise<Reference>;
6
6
  export declare function streamFiles(bee: Bee, files: File[] | FileList, postageBatchId: BatchId, onUploadProgress?: (progress: UploadProgress) => void, options?: UploadOptions, requestOptions?: BeeRequestOptions): Promise<UploadResult>;
@@ -1,6 +1,6 @@
1
1
  import { Bee, BeeRequestOptions, CollectionUploadOptions, UploadOptions, UploadResult } from '..';
2
- import { BatchId } from './typed-bytes';
3
2
  import { UploadProgress } from './upload-progress';
4
- export declare function hashDirectory(dir: string): Promise<import("./typed-bytes").Reference>;
3
+ import { BatchId } from 'swarm-core';
4
+ export declare function hashDirectory(dir: string): Promise<import("swarm-core").Reference>;
5
5
  export declare function streamDirectory(bee: Bee, dir: string, postageBatchId: BatchId | string | Uint8Array, onUploadProgress?: (progress: UploadProgress) => void, options?: CollectionUploadOptions, requestOptions?: BeeRequestOptions): Promise<UploadResult>;
6
6
  export declare function streamFiles(_bee: Bee, _files: File[] | FileList, _postageBatchId: BatchId, _onUploadProgress?: (progress: UploadProgress) => void, _options?: UploadOptions, _requestOptions?: BeeRequestOptions): Promise<UploadResult>;
@@ -1,4 +1,4 @@
1
- import { BatchId, Topic } from './typed-bytes';
1
+ import { BatchId, Topic } from 'swarm-core';
2
2
  export declare const SWARM_GATEWAY_URL = "https://api.gateway.ethswarm.org";
3
3
  export declare const NULL_STAMP: BatchId;
4
4
  export declare const NULL_TOPIC: Topic;
@@ -1,5 +1,5 @@
1
1
  export { getCollectionSize, makeCollectionFromFileList } from './collection';
2
2
  export { getFolderSize } from './collection.node';
3
3
  export { makeMaxTarget } from './pss';
4
- export { approximateOverheadForRedundancyLevel, getRedundancyStat, getRedundancyStats } from './redundancy';
4
+ export { approximateOverheadForRedundancyLevel, getRedundancyStat, getRedundancyStats } from 'swarm-core';
5
5
  export { convertEnvelopeToMarshaledStamp, getAmountForDuration, getDepthForSize, getStampCost, getStampDuration, getStampEffectiveBytes, getStampEffectiveBytesBreakpoints, getStampTheoreticalBytes, getStampUsage, mapPostageBatch, unmapPostageBatch, } from './stamps';
@@ -1,4 +1,4 @@
1
+ import { BatchId } from 'swarm-core';
1
2
  import { EnvelopeWithBatchId, FileHeaders } from '../types';
2
- import { BatchId } from './typed-bytes';
3
3
  export declare function readFileHeaders(headers: Record<string, string>): FileHeaders;
4
4
  export declare function prepareRequestHeaders(stamp: BatchId | Uint8Array | string | EnvelopeWithBatchId | null, nullableOptions?: unknown): Record<string, string>;
@@ -1,4 +1,4 @@
1
- import { PeerAddress } from './typed-bytes';
1
+ import { PeerAddress } from 'swarm-core';
2
2
  /**
3
3
  * Utility function that for given strings/reference takes the most specific
4
4
  * target that Bee node will except.
@@ -1,4 +1,4 @@
1
- import { Reference } from './typed-bytes';
1
+ import { Reference } from 'swarm-core';
2
2
  export declare class ResourceLocator {
3
3
  private raw;
4
4
  constructor(raw: Reference | Uint8Array | string);
@@ -1,6 +1,6 @@
1
+ import { PublicKey, Reference } from 'swarm-core';
1
2
  import { z } from 'zod';
2
3
  import { type NumberString } from '../types';
3
- import { PublicKey, Reference } from './typed-bytes';
4
4
  export { HexStringSchema } from './hex-schema';
5
5
  export declare const BeeRequestOptionsSchema: z.ZodObject<{
6
6
  baseURL: z.ZodOptional<z.ZodString>;
@@ -1,34 +1,9 @@
1
1
  import { EnvelopeWithBatchId, NumberString, PostageBatch, RedundancyLevel } from '../types';
2
- import { Bytes } from './bytes';
3
2
  import { Duration } from './duration';
4
3
  import { Size } from './size';
5
4
  import { BZZ } from './tokens';
6
- /**
7
- * Utility function that calculates usage of postage batch based on its utilization, depth and bucket depth.
8
- *
9
- * For smaller depths (up to 20), this may provide less accurate results.
10
- *
11
- * @returns {number} A number between 0 and 1 representing the usage of the postage batch.
12
- */
13
- export declare function getStampUsage(utilization: number, depth: number, bucketDepth: number): number;
14
- /**
15
- * Utility function that calculates the theoritical maximum size of a postage batch based on its depth.
16
- *
17
- * For smaller depths (up to 22), this may provide less accurate results.
18
- *
19
- * @returns {number} The maximum theoretical size of the postage batch in bytes.
20
- */
21
- export declare function getStampTheoreticalBytes(depth: number): number;
22
- /**
23
- * Utility function that calculates the effective size of a postage batch based on its depth.
24
- *
25
- * Below 22 depth the effective size is 0
26
- * Above 34 it's always > 99%
27
- *
28
- * @returns {number} The effective size of the postage batch in bytes.
29
- */
30
- export declare function getStampEffectiveBytes(depth: number, encryption?: boolean, erasureCodeLevel?: RedundancyLevel): number;
31
- export declare function getStampEffectiveBytesBreakpoints(encryption: boolean, erasureCodeLevel?: RedundancyLevel): Map<number, number>;
5
+ import { Bytes, getStampEffectiveBytes, getStampEffectiveBytesBreakpoints, getStampTheoreticalBytes, getStampUsage } from 'swarm-core';
6
+ export { getStampEffectiveBytes, getStampEffectiveBytesBreakpoints, getStampTheoreticalBytes, getStampUsage };
32
7
  /**
33
8
  * Utility function that calculates the cost of a postage batch based on its depth and amount.
34
9
  */
@@ -1,3 +1,3 @@
1
+ import { BatchId } from 'swarm-core';
1
2
  import { BeeRequestOptions, Collection, CollectionUploadOptions } from '..';
2
- import { BatchId } from './typed-bytes';
3
3
  export declare function uploadTar(requestOptions: BeeRequestOptions, collection: Collection, postageBatchId: BatchId, options?: CollectionUploadOptions): Promise<import("./http").BeeResponse<unknown>>;
@@ -1,3 +1,3 @@
1
+ import { BatchId } from 'swarm-core';
1
2
  import { BeeRequestOptions, Collection, CollectionUploadOptions } from '..';
2
- import { BatchId } from './typed-bytes';
3
3
  export declare function uploadTar(requestOptions: BeeRequestOptions, collection: Collection, postageBatchId: BatchId, options?: CollectionUploadOptions): Promise<import("./http").BeeResponse<unknown>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ethersphere/bee-js",
3
- "version": "12.3.2-upcoming.116",
3
+ "version": "13.0.0-upcoming.gc013bdf",
4
4
  "description": "Javascript client for Bee",
5
5
  "keywords": [
6
6
  "bee",
@@ -63,13 +63,15 @@
63
63
  "test:browser": "TS_NODE_PROJECT=tsconfig.test.json jest --config jest.browser.config.js --runInBand --verbose --forceExit",
64
64
  "check": "tsc --project tsconfig.test.json",
65
65
  "lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\" && prettier --check \"src/**/*.ts\" \"test/**/*.ts\"",
66
- "depcheck": "depcheck ."
66
+ "depcheck": "depcheck .",
67
+ "codemod": "ts-node --project codemod/tsconfig.json codemod/index.ts"
67
68
  },
68
69
  "dependencies": {
69
70
  "cafe-utility": "^34.0.0",
70
71
  "debug": "^4.4.3",
71
72
  "isomorphic-ws": "^5.0.0",
72
73
  "semver": "^7.3.5",
74
+ "swarm-core": "npm:@upcoming/swarm-core@0.0.8",
73
75
  "ws": "^8.21.0",
74
76
  "zod": "^4.4.3"
75
77
  },
@@ -1,37 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.calculateChunkAddress = calculateChunkAddress;
4
- const cafe_utility_1 = require("cafe-utility");
5
- const error_1 = require("../utils/error");
6
- const typed_bytes_1 = require("../utils/typed-bytes");
7
- const MAX_CHUNK_PAYLOAD_SIZE = 4096;
8
- const SEGMENT_SIZE = 32;
9
- /**
10
- * Calculate a Binary Merkle Tree hash for a chunk
11
- *
12
- * The BMT chunk address is the hash of the 8 byte span and the root
13
- * hash of a binary Merkle tree (BMT) built on the 32-byte segments
14
- * of the underlying data.
15
- *
16
- * If the chunk content is less than 4k, the hash is calculated as
17
- * if the chunk was padded with all zeros up to 4096 bytes.
18
- *
19
- * @param chunkContent Chunk data including span and payload as well
20
- *
21
- * @returns the keccak256 hash in a byte array
22
- */
23
- function calculateChunkAddress(chunkContent) {
24
- const span = chunkContent.slice(0, typed_bytes_1.Span.LENGTH);
25
- const payload = chunkContent.slice(typed_bytes_1.Span.LENGTH);
26
- const rootHash = calculateBmtRootHash(payload);
27
- const chunkHash = cafe_utility_1.Binary.keccak256(cafe_utility_1.Binary.concatBytes(span, rootHash));
28
- return new typed_bytes_1.Reference(chunkHash);
29
- }
30
- function calculateBmtRootHash(payload) {
31
- if (payload.length > MAX_CHUNK_PAYLOAD_SIZE) {
32
- throw new error_1.BeeArgumentError(`payload size ${payload.length} exceeds maximum chunk payload size ${MAX_CHUNK_PAYLOAD_SIZE}`, payload);
33
- }
34
- const input = new Uint8Array(MAX_CHUNK_PAYLOAD_SIZE);
35
- input.set(payload);
36
- return cafe_utility_1.Binary.log2Reduce(cafe_utility_1.Binary.partition(input, SEGMENT_SIZE), (a, b) => cafe_utility_1.Binary.keccak256(cafe_utility_1.Binary.concatBytes(a, b)));
37
- }
@@ -1,43 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MAX_PAYLOAD_SIZE = exports.MIN_PAYLOAD_SIZE = void 0;
4
- exports.unmarshalContentAddressedChunk = unmarshalContentAddressedChunk;
5
- exports.makeContentAddressedChunk = makeContentAddressedChunk;
6
- const cafe_utility_1 = require("cafe-utility");
7
- const zod_1 = require("zod");
8
- const bytes_1 = require("../utils/bytes");
9
- const typed_bytes_1 = require("../utils/typed-bytes");
10
- const bmt_1 = require("./bmt");
11
- const soc_1 = require("./soc");
12
- exports.MIN_PAYLOAD_SIZE = 1;
13
- exports.MAX_PAYLOAD_SIZE = 4096;
14
- function unmarshalContentAddressedChunk(data) {
15
- data = new bytes_1.Bytes(data);
16
- return makeContentAddressedChunk(data.toUint8Array().slice(typed_bytes_1.Span.LENGTH), typed_bytes_1.Span.fromSlice(data.toUint8Array(), 0));
17
- }
18
- function makeContentAddressedChunk(rawPayload, span) {
19
- const asString = zod_1.z.string().safeParse(rawPayload);
20
- if (asString.success) {
21
- rawPayload = bytes_1.Bytes.fromUtf8(asString.data);
22
- }
23
- if (rawPayload.length < exports.MIN_PAYLOAD_SIZE || rawPayload.length > exports.MAX_PAYLOAD_SIZE) {
24
- throw new RangeError(`payload size ${rawPayload.length} exceeds limits [${exports.MIN_PAYLOAD_SIZE}, ${exports.MAX_PAYLOAD_SIZE}]`);
25
- }
26
- const typedSpan = span
27
- ? typeof span === 'bigint'
28
- ? typed_bytes_1.Span.fromBigInt(span)
29
- : span
30
- : typed_bytes_1.Span.fromBigInt(BigInt(rawPayload.length));
31
- const payload = new bytes_1.Bytes(rawPayload);
32
- const data = cafe_utility_1.Binary.concatBytes(typedSpan.toUint8Array(), payload.toUint8Array());
33
- const address = (0, bmt_1.calculateChunkAddress)(data);
34
- return {
35
- data,
36
- span: typedSpan,
37
- payload,
38
- address,
39
- toSingleOwnerChunk: (identifier, signer) => {
40
- return (0, soc_1.makeSingleOwnerChunk)(address, typedSpan, payload, identifier, signer);
41
- },
42
- };
43
- }