@ethersphere/bee-js 13.0.0-upcoming.gcfb9756 → 13.0.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 (201) hide show
  1. package/README.md +104 -103
  2. package/dist/cjs/api/bytes.js +3 -4
  3. package/dist/cjs/api/bzz.js +5 -6
  4. package/dist/cjs/api/chunk.js +3 -3
  5. package/dist/cjs/api/envelope.js +3 -2
  6. package/dist/cjs/api/feed.js +4 -5
  7. package/dist/cjs/api/pin.js +2 -2
  8. package/dist/cjs/api/soc.js +2 -2
  9. package/dist/cjs/bee.js +18 -19
  10. package/dist/cjs/chunk/soc.js +21 -63
  11. package/dist/cjs/feed/identifier.js +3 -4
  12. package/dist/cjs/feed/index.js +17 -19
  13. package/dist/cjs/feed/retrievable.js +2 -2
  14. package/dist/cjs/index.js +18 -8
  15. package/dist/cjs/manifest/manifest.js +97 -333
  16. package/dist/cjs/modules/balance.js +3 -3
  17. package/dist/cjs/modules/cheque.js +4 -4
  18. package/dist/cjs/modules/chunk.js +8 -8
  19. package/dist/cjs/modules/collection.js +6 -6
  20. package/dist/cjs/modules/connectivity.js +3 -3
  21. package/dist/cjs/modules/data.js +6 -6
  22. package/dist/cjs/modules/feed.js +10 -10
  23. package/dist/cjs/modules/file.js +3 -3
  24. package/dist/cjs/modules/grantee.js +9 -9
  25. package/dist/cjs/modules/messaging.js +15 -17
  26. package/dist/cjs/modules/pin.js +6 -6
  27. package/dist/cjs/modules/settlement.js +2 -2
  28. package/dist/cjs/modules/soc.js +3 -3
  29. package/dist/cjs/modules/stamp.js +7 -7
  30. package/dist/cjs/modules/tag.js +2 -2
  31. package/dist/cjs/modules/transaction.js +4 -4
  32. package/dist/cjs/modules/wallet.js +3 -3
  33. package/dist/cjs/types/schema/chequebook.js +5 -5
  34. package/dist/cjs/types/schema/connectivity.js +5 -5
  35. package/dist/cjs/types/schema/envelope.js +5 -5
  36. package/dist/cjs/types/schema/grantee.js +4 -4
  37. package/dist/cjs/types/schema/stake.js +2 -2
  38. package/dist/cjs/types/schema/stamps.js +4 -4
  39. package/dist/cjs/types/schema/states.js +2 -2
  40. package/dist/cjs/types/schema/transactions.js +3 -3
  41. package/dist/cjs/types/schema/upload.js +2 -2
  42. package/dist/cjs/utils/chunk-stream.browser.js +24 -16
  43. package/dist/cjs/utils/chunk-stream.js +17 -9
  44. package/dist/cjs/utils/constants.js +3 -3
  45. package/dist/cjs/utils/expose.js +4 -4
  46. package/dist/cjs/utils/headers.js +4 -4
  47. package/dist/cjs/utils/http.js +3 -1
  48. package/dist/cjs/utils/pss.js +2 -2
  49. package/dist/cjs/utils/resource-locator.js +2 -2
  50. package/dist/cjs/utils/schema.js +4 -4
  51. package/dist/cjs/utils/stamps.js +15 -130
  52. package/dist/cjs/utils/type.js +2 -2
  53. package/dist/codemod/index.js +141 -0
  54. package/dist/codemod/transforms/v13.js +524 -0
  55. package/dist/index.browser.min.js +2 -1
  56. package/dist/index.browser.min.js.LICENSE.txt +3 -0
  57. package/dist/index.browser.min.js.map +1 -1
  58. package/dist/mjs/api/bytes.js +1 -2
  59. package/dist/mjs/api/bzz.js +1 -2
  60. package/dist/mjs/api/chunk.js +1 -1
  61. package/dist/mjs/api/envelope.js +3 -2
  62. package/dist/mjs/api/feed.js +1 -2
  63. package/dist/mjs/api/pin.js +1 -1
  64. package/dist/mjs/api/soc.js +1 -1
  65. package/dist/mjs/bee.js +13 -14
  66. package/dist/mjs/chunk/soc.js +11 -49
  67. package/dist/mjs/feed/identifier.js +2 -3
  68. package/dist/mjs/feed/index.js +6 -8
  69. package/dist/mjs/feed/retrievable.js +1 -1
  70. package/dist/mjs/index.js +2 -5
  71. package/dist/mjs/manifest/manifest.js +95 -339
  72. package/dist/mjs/modules/balance.js +1 -1
  73. package/dist/mjs/modules/cheque.js +1 -1
  74. package/dist/mjs/modules/chunk.js +1 -1
  75. package/dist/mjs/modules/collection.js +1 -1
  76. package/dist/mjs/modules/connectivity.js +1 -1
  77. package/dist/mjs/modules/data.js +3 -3
  78. package/dist/mjs/modules/feed.js +1 -1
  79. package/dist/mjs/modules/file.js +1 -1
  80. package/dist/mjs/modules/grantee.js +1 -1
  81. package/dist/mjs/modules/messaging.js +3 -5
  82. package/dist/mjs/modules/pin.js +1 -1
  83. package/dist/mjs/modules/settlement.js +1 -1
  84. package/dist/mjs/modules/soc.js +1 -1
  85. package/dist/mjs/modules/stamp.js +1 -1
  86. package/dist/mjs/modules/tag.js +1 -1
  87. package/dist/mjs/modules/transaction.js +1 -1
  88. package/dist/mjs/modules/wallet.js +1 -1
  89. package/dist/mjs/types/schema/chequebook.js +1 -1
  90. package/dist/mjs/types/schema/connectivity.js +1 -1
  91. package/dist/mjs/types/schema/envelope.js +5 -5
  92. package/dist/mjs/types/schema/grantee.js +1 -1
  93. package/dist/mjs/types/schema/stake.js +1 -1
  94. package/dist/mjs/types/schema/stamps.js +1 -1
  95. package/dist/mjs/types/schema/states.js +1 -1
  96. package/dist/mjs/types/schema/transactions.js +1 -1
  97. package/dist/mjs/types/schema/upload.js +1 -1
  98. package/dist/mjs/utils/chunk-stream.browser.js +28 -18
  99. package/dist/mjs/utils/chunk-stream.js +21 -11
  100. package/dist/mjs/utils/constants.js +1 -1
  101. package/dist/mjs/utils/expose.js +1 -1
  102. package/dist/mjs/utils/headers.js +1 -1
  103. package/dist/mjs/utils/http.js +6 -1
  104. package/dist/mjs/utils/pss.js +1 -1
  105. package/dist/mjs/utils/resource-locator.js +1 -1
  106. package/dist/mjs/utils/schema.js +1 -1
  107. package/dist/mjs/utils/stamps.js +5 -99
  108. package/dist/mjs/utils/type.js +2 -2
  109. package/dist/types/api/balance.d.ts +1 -1
  110. package/dist/types/api/batches.d.ts +1 -1
  111. package/dist/types/api/bytes.d.ts +3 -3
  112. package/dist/types/api/bzz.d.ts +1 -2
  113. package/dist/types/api/chequebook.d.ts +1 -1
  114. package/dist/types/api/chunk.d.ts +1 -1
  115. package/dist/types/api/connectivity.d.ts +1 -1
  116. package/dist/types/api/consumed.d.ts +1 -1
  117. package/dist/types/api/envelope.d.ts +1 -1
  118. package/dist/types/api/feed.d.ts +1 -2
  119. package/dist/types/api/grantee.d.ts +1 -1
  120. package/dist/types/api/pin.d.ts +1 -1
  121. package/dist/types/api/pss.d.ts +1 -1
  122. package/dist/types/api/settlement.d.ts +1 -1
  123. package/dist/types/api/soc.d.ts +1 -1
  124. package/dist/types/api/stake.d.ts +1 -1
  125. package/dist/types/api/stamp.d.ts +1 -1
  126. package/dist/types/api/stewardship.d.ts +1 -1
  127. package/dist/types/api/tag.d.ts +1 -1
  128. package/dist/types/api/transaction.d.ts +1 -1
  129. package/dist/types/api/wallet.d.ts +1 -1
  130. package/dist/types/bee.d.ts +11 -13
  131. package/dist/types/chunk/soc.d.ts +3 -48
  132. package/dist/types/feed/identifier.d.ts +1 -1
  133. package/dist/types/feed/index.d.ts +1 -3
  134. package/dist/types/feed/retrievable.d.ts +1 -1
  135. package/dist/types/index.d.ts +17 -20
  136. package/dist/types/manifest/manifest.d.ts +24 -33
  137. package/dist/types/modules/balance.d.ts +1 -1
  138. package/dist/types/modules/cheque.d.ts +1 -1
  139. package/dist/types/modules/chequebook.d.ts +1 -1
  140. package/dist/types/modules/chunk.d.ts +1 -2
  141. package/dist/types/modules/collection.d.ts +2 -2
  142. package/dist/types/modules/connectivity.d.ts +1 -1
  143. package/dist/types/modules/context.d.ts +1 -1
  144. package/dist/types/modules/data.d.ts +3 -3
  145. package/dist/types/modules/feed.d.ts +1 -1
  146. package/dist/types/modules/file.d.ts +1 -2
  147. package/dist/types/modules/grantee.d.ts +1 -1
  148. package/dist/types/modules/messaging.d.ts +1 -2
  149. package/dist/types/modules/pin.d.ts +1 -1
  150. package/dist/types/modules/settlement.d.ts +1 -1
  151. package/dist/types/modules/soc.d.ts +1 -1
  152. package/dist/types/modules/stake.d.ts +1 -1
  153. package/dist/types/modules/stamp.d.ts +1 -1
  154. package/dist/types/modules/storage.d.ts +1 -1
  155. package/dist/types/modules/tag.d.ts +1 -1
  156. package/dist/types/modules/transaction.d.ts +1 -1
  157. package/dist/types/modules/wallet.d.ts +1 -1
  158. package/dist/types/types/debug.d.ts +1 -1
  159. package/dist/types/types/index.d.ts +2 -11
  160. package/dist/types/types/schema/chequebook.d.ts +1 -1
  161. package/dist/types/types/schema/connectivity.d.ts +1 -1
  162. package/dist/types/types/schema/grantee.d.ts +1 -1
  163. package/dist/types/types/schema/stake.d.ts +1 -1
  164. package/dist/types/types/schema/stamps.d.ts +1 -1
  165. package/dist/types/types/schema/states.d.ts +1 -1
  166. package/dist/types/types/schema/transactions.d.ts +1 -1
  167. package/dist/types/types/schema/upload.d.ts +1 -1
  168. package/dist/types/utils/chunk-stream.browser.d.ts +1 -1
  169. package/dist/types/utils/chunk-stream.d.ts +2 -2
  170. package/dist/types/utils/constants.d.ts +1 -1
  171. package/dist/types/utils/expose.d.ts +1 -1
  172. package/dist/types/utils/headers.d.ts +1 -1
  173. package/dist/types/utils/pss.d.ts +1 -1
  174. package/dist/types/utils/resource-locator.d.ts +1 -1
  175. package/dist/types/utils/schema.d.ts +1 -1
  176. package/dist/types/utils/stamps.d.ts +2 -27
  177. package/dist/types/utils/tar-uploader.browser.d.ts +1 -1
  178. package/dist/types/utils/tar-uploader.d.ts +1 -1
  179. package/dist/types/utils/type.d.ts +1 -1
  180. package/package.json +7 -2
  181. package/dist/cjs/chunk/bmt.js +0 -37
  182. package/dist/cjs/chunk/cac.js +0 -43
  183. package/dist/cjs/stamper/stamper.js +0 -44
  184. package/dist/cjs/utils/bytes.js +0 -116
  185. package/dist/cjs/utils/cid.js +0 -37
  186. package/dist/cjs/utils/redundancy.js +0 -133
  187. package/dist/cjs/utils/typed-bytes.js +0 -186
  188. package/dist/mjs/chunk/bmt.js +0 -34
  189. package/dist/mjs/chunk/cac.js +0 -34
  190. package/dist/mjs/stamper/stamper.js +0 -40
  191. package/dist/mjs/utils/bytes.js +0 -102
  192. package/dist/mjs/utils/cid.js +0 -32
  193. package/dist/mjs/utils/redundancy.js +0 -98
  194. package/dist/mjs/utils/typed-bytes.js +0 -167
  195. package/dist/types/chunk/bmt.d.ts +0 -16
  196. package/dist/types/chunk/cac.d.ts +0 -40
  197. package/dist/types/stamper/stamper.d.ts +0 -15
  198. package/dist/types/utils/bytes.d.ts +0 -19
  199. package/dist/types/utils/cid.d.ts +0 -10
  200. package/dist/types/utils/redundancy.d.ts +0 -21
  201. package/dist/types/utils/typed-bytes.d.ts +0 -69
@@ -1,5 +1,5 @@
1
+ import { EthAddress, PrivateKey } from '@ethersphere/core-sdk';
1
2
  import { downloadSingleOwnerChunk, uploadSingleOwnerChunkData } from "../chunk/soc.js";
2
- import { EthAddress, PrivateKey } from "../utils/typed-bytes.js";
3
3
  /**
4
4
  * Single owner chunk (SOC) reader/writer operations.
5
5
  *
@@ -1,3 +1,4 @@
1
+ import { BatchId } from '@ethersphere/core-sdk';
1
2
  import { System } from 'cafe-utility';
2
3
  import { z } from 'zod';
3
4
  import { STAMPS_DEPTH_MAX, STAMPS_DEPTH_MIN } from "../types/index.js";
@@ -5,7 +6,6 @@ import { BeeArgumentError, BeeError } from "../utils/error.js";
5
6
  import { PostageBatchOptionsSchema } from "../utils/schema.js";
6
7
  import { getStampDuration } from "../utils/stamps.js";
7
8
  import { asNumberString } from "../utils/type.js";
8
- import { BatchId } from "../utils/typed-bytes.js";
9
9
  import * as stampApi from "../api/stamp.js";
10
10
  import * as batchesApi from "../api/batches.js";
11
11
  /**
@@ -1,7 +1,7 @@
1
+ import { Reference } from '@ethersphere/core-sdk';
1
2
  import * as api from "../api/tag.js";
2
3
  import { AllTagsOptionsSchema } from "../utils/schema.js";
3
4
  import { makeTagUid } from "../utils/type.js";
4
- import { Reference } from "../utils/typed-bytes.js";
5
5
  /**
6
6
  * Tag operations for tracking upload and synchronization progress.
7
7
  *
@@ -1,5 +1,5 @@
1
+ import { TransactionId } from '@ethersphere/core-sdk';
1
2
  import { asNumberString } from "../utils/type.js";
2
- import { TransactionId } from "../utils/typed-bytes.js";
3
3
  import * as api from "../api/transaction.js";
4
4
  /**
5
5
  * Pending transaction operations for the Bee node's `/transactions` queue.
@@ -1,5 +1,5 @@
1
+ import { EthAddress } from '@ethersphere/core-sdk';
1
2
  import { BZZ, DAI } from "../utils/tokens.js";
2
- import { EthAddress } from "../utils/typed-bytes.js";
3
3
  import * as api from "../api/wallet.js";
4
4
  /**
5
5
  * Node wallet operations (balances and external withdrawals).
@@ -1,7 +1,7 @@
1
+ import { EthAddress, TransactionId } from '@ethersphere/core-sdk';
1
2
  import { z } from 'zod';
2
3
  import { BZZ } from "../../utils/tokens.js";
3
4
  import { asNumberString } from "../../utils/type.js";
4
- import { EthAddress, TransactionId } from "../../utils/typed-bytes.js";
5
5
  const ChequeSchema = z.object({
6
6
  beneficiary: z.string().transform(s => new EthAddress(s)),
7
7
  chequebook: z.string().transform(s => new EthAddress(s)),
@@ -1,5 +1,5 @@
1
+ import { EthAddress, PeerAddress, PublicKey } from '@ethersphere/core-sdk';
1
2
  import { z } from 'zod';
2
- import { EthAddress, PeerAddress, PublicKey } from "../../utils/typed-bytes.js";
3
3
  const PeerSchema = z.object({
4
4
  address: z.string(),
5
5
  fullNode: z.boolean()
@@ -1,8 +1,8 @@
1
- import { Binary } from 'cafe-utility';
2
1
  import { z } from 'zod';
2
+ import { hexToUint8Array } from '@ethersphere/core-sdk';
3
3
  export const PostEnvelopeBodyResponse = z.object({
4
- issuer: z.string().transform(s => Binary.hexToUint8Array(s)),
5
- index: z.string().transform(s => Binary.hexToUint8Array(s)),
6
- timestamp: z.string().transform(s => Binary.hexToUint8Array(s)),
7
- signature: z.string().transform(s => Binary.hexToUint8Array(s))
4
+ issuer: z.string().transform(s => hexToUint8Array(s)),
5
+ index: z.string().transform(s => hexToUint8Array(s)),
6
+ timestamp: z.string().transform(s => hexToUint8Array(s)),
7
+ signature: z.string().transform(s => hexToUint8Array(s))
8
8
  });
@@ -1,5 +1,5 @@
1
+ import { PublicKey, Reference } from '@ethersphere/core-sdk';
1
2
  import { z } from 'zod';
2
- import { PublicKey, Reference } from "../../utils/typed-bytes.js";
3
3
  export const GetGranteesBodyResponse = z.array(z.string().transform(s => new PublicKey(s)));
4
4
  export const GranteesResultBodyResponse = z.object({
5
5
  ref: z.string().transform(s => new Reference(s)),
@@ -1,7 +1,7 @@
1
+ import { TransactionId } from '@ethersphere/core-sdk';
1
2
  import { z } from 'zod';
2
3
  import { BZZ, DAI } from "../../utils/tokens.js";
3
4
  import { asNumberString } from "../../utils/type.js";
4
- import { TransactionId } from "../../utils/typed-bytes.js";
5
5
  export const GetStakeResponse = z.object({
6
6
  stakedAmount: z.string().transform(s => BZZ.fromPLUR(asNumberString(s, {
7
7
  name: 'stakedAmount'
@@ -1,6 +1,6 @@
1
+ import { BatchId, EthAddress } from '@ethersphere/core-sdk';
1
2
  import { z } from 'zod';
2
3
  import { asNumberString } from "../../utils/type.js";
3
- import { BatchId, EthAddress } from "../../utils/typed-bytes.js";
4
4
  export const RawPostageBatchSchema = z.object({
5
5
  batchID: z.string(),
6
6
  utilization: z.number(),
@@ -1,7 +1,7 @@
1
+ import { TransactionId } from '@ethersphere/core-sdk';
1
2
  import { z } from 'zod';
2
3
  import { BZZ, DAI } from "../../utils/tokens.js";
3
4
  import { asNumberString } from "../../utils/type.js";
4
- import { TransactionId } from "../../utils/typed-bytes.js";
5
5
  import { normalizeCurrentPrice } from "../../utils/workaround.js";
6
6
  export const GetReserveStateResponse = z.object({
7
7
  commitment: z.number(),
@@ -1,6 +1,6 @@
1
+ import { TransactionId } from '@ethersphere/core-sdk';
1
2
  import { z } from 'zod';
2
3
  import { asNumberString } from "../../utils/type.js";
3
- import { TransactionId } from "../../utils/typed-bytes.js";
4
4
  const TransactionInfoSchema = z.object({
5
5
  transactionHash: z.string().transform(s => new TransactionId(s)),
6
6
  to: z.string(),
@@ -1,5 +1,5 @@
1
+ import { Reference } from '@ethersphere/core-sdk';
1
2
  import { z } from 'zod';
2
- import { Reference } from "../../utils/typed-bytes.js";
3
3
  export const UploadResultBody = z.object({
4
4
  reference: z.string().transform(s => new Reference(s))
5
5
  });
@@ -1,10 +1,10 @@
1
- import { AsyncQueue, MerkleTree, Strings } from 'cafe-utility';
1
+ import { AsyncQueue, Strings } from 'cafe-utility';
2
2
  import { NULL_ADDRESS } from "../index.js";
3
3
  import { MantarayNode } from "../manifest/manifest.js";
4
4
  import { totalChunks } from "./chunk-size.js";
5
5
  import { makeFilePath } from "./collection.js";
6
6
  import { mimes } from "./mime.js";
7
- import { BatchId } from "./typed-bytes.js";
7
+ import { BatchId, ChunkSplitter } from '@ethersphere/core-sdk';
8
8
  export async function hashDirectory(_dir) {
9
9
  throw new Error('Hashing directories is not supported in browsers!');
10
10
  }
@@ -23,24 +23,30 @@ export async function streamFiles(bee, files, postageBatchId, onUploadProgress,
23
23
  total += totalChunks(file.size);
24
24
  }
25
25
  postageBatchId = new BatchId(postageBatchId);
26
- async function onChunk(chunk) {
27
- await queue.enqueue(async () => {
26
+ async function uploadAndTrack(chunk) {
27
+ if (signal?.aborted) {
28
+ return;
29
+ }
30
+ try {
31
+ await bee.chunk.upload(postageBatchId, chunk.build(), options, requestOptions);
32
+ onUploadProgress?.({
33
+ total,
34
+ processed: ++processed
35
+ });
36
+ } catch (err) {
28
37
  if (signal?.aborted) {
29
38
  return;
30
39
  }
31
- try {
32
- await bee.chunk.upload(postageBatchId, chunk.build(), options, requestOptions);
33
- onUploadProgress?.({
34
- total,
35
- processed: ++processed
36
- });
37
- } catch (err) {
38
- if (signal?.aborted) {
39
- return;
40
- }
41
- throw err;
42
- }
43
- });
40
+ throw err;
41
+ }
42
+ }
43
+ async function onBatch(batch) {
44
+ for (const {
45
+ chunk
46
+ } of batch) {
47
+ await queue.enqueue(async () => uploadAndTrack(chunk));
48
+ }
49
+ return [];
44
50
  }
45
51
  const mantaray = new MantarayNode();
46
52
  for (const file of files) {
@@ -48,7 +54,7 @@ export async function streamFiles(bee, files, postageBatchId, onUploadProgress,
48
54
  throw new Error('Request aborted');
49
55
  }
50
56
  const rootChunk = await new Promise((resolve, reject) => {
51
- const tree = new MerkleTree(onChunk);
57
+ const tree = new ChunkSplitter(onBatch);
52
58
  let offset = 0;
53
59
  const reader = new FileReader();
54
60
  reader.onerror = () => {
@@ -60,7 +66,11 @@ export async function streamFiles(bee, files, postageBatchId, onUploadProgress,
60
66
  return;
61
67
  }
62
68
  if (offset >= file.size) {
69
+ // ChunkSplitter's onBatch only sees chunks once they're referenced
70
+ // by a parent - the root chunk returned by finalize() is never
71
+ // passed to it, so it has to be uploaded here explicitly.
63
72
  const rootChunk = await tree.finalize();
73
+ await queue.enqueue(async () => uploadAndTrack(rootChunk));
64
74
  resolve(rootChunk);
65
75
  return;
66
76
  }
@@ -1,16 +1,16 @@
1
- import { AsyncQueue, MerkleTree, Strings } from 'cafe-utility';
1
+ import { AsyncQueue, Strings } from 'cafe-utility';
2
2
  import { createReadStream } from 'fs';
3
3
  import { NULL_ADDRESS } from "../index.js";
4
4
  import { MantarayNode } from "../manifest/manifest.js";
5
5
  import { totalChunks } from "./chunk-size.js";
6
6
  import { makeCollectionFromFS } from "./collection.node.js";
7
7
  import { mimes } from "./mime.js";
8
- import { BatchId } from "./typed-bytes.js";
8
+ import { BatchId, ChunkSplitter } from '@ethersphere/core-sdk';
9
9
  export async function hashDirectory(dir) {
10
10
  const files = await makeCollectionFromFS(dir);
11
11
  const mantaray = new MantarayNode();
12
12
  for (const file of files) {
13
- const tree = new MerkleTree(MerkleTree.NOOP);
13
+ const tree = new ChunkSplitter(ChunkSplitter.NOOP);
14
14
  if (!file.fsPath) {
15
15
  throw Error('File does not have fsPath, which should never happen in node. Please report this issue.');
16
16
  }
@@ -40,26 +40,36 @@ export async function streamDirectory(bee, dir, postageBatchId, onUploadProgress
40
40
  total += totalChunks(file.size);
41
41
  }
42
42
  let hasIndexHtml = false;
43
- async function onChunk(chunk) {
44
- await queue.enqueue(async () => {
45
- await bee.chunk.upload(postageBatchId, chunk.build(), options, requestOptions);
46
- onUploadProgress?.({
47
- total,
48
- processed: ++processed
49
- });
43
+ async function uploadAndTrack(chunk) {
44
+ await bee.chunk.upload(postageBatchId, chunk.build(), options, requestOptions);
45
+ onUploadProgress?.({
46
+ total,
47
+ processed: ++processed
50
48
  });
51
49
  }
50
+ async function onBatch(batch) {
51
+ for (const {
52
+ chunk
53
+ } of batch) {
54
+ await queue.enqueue(async () => uploadAndTrack(chunk));
55
+ }
56
+ return [];
57
+ }
52
58
  const mantaray = new MantarayNode();
53
59
  for (const file of files) {
54
60
  if (!file.fsPath) {
55
61
  throw Error('File does not have fsPath, which should never happen in node. Please report this issue.');
56
62
  }
57
63
  const readStream = createReadStream(file.fsPath);
58
- const tree = new MerkleTree(onChunk);
64
+ const tree = new ChunkSplitter(onBatch);
59
65
  for await (const data of readStream) {
60
66
  await tree.append(data);
61
67
  }
68
+ // ChunkSplitter's onBatch only sees chunks once they're referenced by a
69
+ // parent - the root chunk returned by finalize() is never passed to it,
70
+ // so it has to be uploaded here explicitly.
62
71
  const rootChunk = await tree.finalize();
72
+ await queue.enqueue(async () => uploadAndTrack(rootChunk));
63
73
  await queue.drain();
64
74
  const {
65
75
  filename,
@@ -1,4 +1,4 @@
1
- import { BatchId, Topic } from "./typed-bytes.js";
1
+ import { BatchId, Topic } from '@ethersphere/core-sdk';
2
2
  export const SWARM_GATEWAY_URL = 'https://api.gateway.ethswarm.org';
3
3
  export const NULL_STAMP = new BatchId('0000000000000000000000000000000000000000000000000000000000000000');
4
4
  export const NULL_TOPIC = new Topic('0000000000000000000000000000000000000000000000000000000000000000');
@@ -1,5 +1,5 @@
1
1
  export { getCollectionSize, makeCollectionFromFileList } from "./collection.js";
2
2
  export { getFolderSize } from "./collection.node.js";
3
3
  export { makeMaxTarget } from "./pss.js";
4
- export { approximateOverheadForRedundancyLevel, getRedundancyStat, getRedundancyStats } from "./redundancy.js";
4
+ export { approximateOverheadForRedundancyLevel, getRedundancyStat, getRedundancyStats } from '@ethersphere/core-sdk';
5
5
  export { convertEnvelopeToMarshaledStamp, getAmountForDuration, getDepthForSize, getStampCost, getStampDuration, getStampEffectiveBytes, getStampEffectiveBytesBreakpoints, getStampTheoreticalBytes, getStampUsage, mapPostageBatch, unmapPostageBatch } from "./stamps.js";
@@ -1,7 +1,7 @@
1
+ import { BatchId, PublicKey, Reference } from '@ethersphere/core-sdk';
1
2
  import { z } from 'zod';
2
3
  import { BeeError } from "./error.js";
3
4
  import { convertEnvelopeToMarshaledStamp } from "./stamps.js";
4
- import { BatchId, PublicKey, Reference } from "./typed-bytes.js";
5
5
  export function readFileHeaders(headers) {
6
6
  const name = readContentDispositionFilename(headers['content-disposition']);
7
7
  const tagUid = readTagUid(headers['swarm-tag-uid']);
@@ -17,7 +17,12 @@ export const DEFAULT_HTTP_CONFIG = {
17
17
  * @param config Internal settings and/or Bee settings
18
18
  */
19
19
  export async function http(options, config) {
20
- const requestConfig = Objects.deepMerge3(DEFAULT_HTTP_CONFIG, config, options);
20
+ const rawData = config.data;
21
+ const requestConfig = Objects.deepMerge3(DEFAULT_HTTP_CONFIG, {
22
+ ...config,
23
+ data: undefined
24
+ }, options);
25
+ requestConfig.data = rawData;
21
26
  if (options.signal) {
22
27
  requestConfig.signal = options.signal;
23
28
  }
@@ -1,5 +1,5 @@
1
+ import { PeerAddress } from '@ethersphere/core-sdk';
1
2
  import { PSS_TARGET_HEX_LENGTH_MAX } from "../types/index.js";
2
- import { PeerAddress } from "./typed-bytes.js";
3
3
  /**
4
4
  * Utility function that for given strings/reference takes the most specific
5
5
  * target that Bee node will except.
@@ -1,5 +1,5 @@
1
+ import { Reference } from '@ethersphere/core-sdk';
1
2
  import { z } from 'zod';
2
- import { Reference } from "./typed-bytes.js";
3
3
  export class ResourceLocator {
4
4
  constructor(raw) {
5
5
  this.raw = raw;
@@ -1,6 +1,6 @@
1
+ import { PublicKey, Reference } from '@ethersphere/core-sdk';
1
2
  import { z } from 'zod';
2
3
  import { TAGS_LIMIT_MAX, TAGS_LIMIT_MIN } from "../types/index.js";
3
- import { PublicKey, Reference } from "./typed-bytes.js";
4
4
  export { HexStringSchema } from "./hex-schema.js";
5
5
  const fnField = z.any().refine(v => z.function().safeParse(v).success, 'expected a function');
6
6
  const integerStringField = z.any().transform(v => {
@@ -1,76 +1,10 @@
1
- import { Binary } from 'cafe-utility';
2
- import { capacityBreakpoints } from "../types/index.js";
3
- import { Bytes, parseSizeToBytes } from "./bytes.js";
4
1
  import { Duration } from "./duration.js";
5
2
  import { Size } from "./size.js";
6
3
  import { BZZ } from "./tokens.js";
7
4
  import { asNumberString } from "./type.js";
8
- import { BatchId } from "./typed-bytes.js";
9
5
  import { normalizeBatchTTL } from "./workaround.js";
10
- const MAX_UTILIZATION = 0.9;
11
- /**
12
- * Utility function that calculates usage of postage batch based on its utilization, depth and bucket depth.
13
- *
14
- * For smaller depths (up to 20), this may provide less accurate results.
15
- *
16
- * @returns {number} A number between 0 and 1 representing the usage of the postage batch.
17
- */
18
- export function getStampUsage(utilization, depth, bucketDepth) {
19
- return utilization / Math.pow(2, depth - bucketDepth);
20
- }
21
- /**
22
- * Utility function that calculates the theoritical maximum size of a postage batch based on its depth.
23
- *
24
- * For smaller depths (up to 22), this may provide less accurate results.
25
- *
26
- * @returns {number} The maximum theoretical size of the postage batch in bytes.
27
- */
28
- export function getStampTheoreticalBytes(depth) {
29
- return 4096 * 2 ** depth;
30
- }
31
- /**
32
- * Based on https://docs.ethswarm.org/docs/learn/technology/contracts/postage-stamp/#effective-utilisation-table
33
- * Optimised for encrypted, medium erasure coding
34
- */
35
- const effectiveSizeBreakpoints = [[17, 0.00004089], [18, 0.00609], [19, 0.10249], [20, 0.62891], [21, 2.38], [22, 7.07], [23, 18.24], [24, 43.04], [25, 96.5], [26, 208.52], [27, 435.98], [28, 908.81], [29, 1870], [30, 3810], [31, 7730], [32, 15610], [33, 31430], [34, 63150]];
36
- /**
37
- * Utility function that calculates the effective size of a postage batch based on its depth.
38
- *
39
- * Below 22 depth the effective size is 0
40
- * Above 34 it's always > 99%
41
- *
42
- * @returns {number} The effective size of the postage batch in bytes.
43
- */
44
- export function getStampEffectiveBytes(depth, encryption, erasureCodeLevel) {
45
- if (depth < 17) {
46
- return 0;
47
- }
48
- if (encryption !== undefined && erasureCodeLevel !== undefined) {
49
- const encryptionKey = encryption ? 'ENCRYPTION_ON' : 'ENCRYPTION_OFF';
50
- const breakpoints = capacityBreakpoints[encryptionKey][erasureCodeLevel];
51
- const entry = breakpoints.find(item => item.batchDepth === depth);
52
- if (entry?.effectiveVolume) {
53
- return parseSizeToBytes(entry.effectiveVolume);
54
- }
55
- } else {
56
- const breakpoint = effectiveSizeBreakpoints.find(([d, size]) => {
57
- if (depth === d) {
58
- return size;
59
- }
60
- });
61
- if (breakpoint) {
62
- return breakpoint[1] * 1000 * 1000 * 1000;
63
- }
64
- }
65
- return Math.ceil(getStampTheoreticalBytes(depth) * MAX_UTILIZATION);
66
- }
67
- export function getStampEffectiveBytesBreakpoints(encryption, erasureCodeLevel) {
68
- const map = new Map();
69
- for (let i = 17; i < 35; i++) {
70
- map.set(i, getStampEffectiveBytes(i, encryption, erasureCodeLevel));
71
- }
72
- return map;
73
- }
6
+ import { BatchId, convertEnvelopeToMarshaledStamp as coreConvertEnvelopeToMarshaledStamp, getDepthForSize as coreGetDepthForSize, getStampEffectiveBytes, getStampEffectiveBytesBreakpoints, getStampTheoreticalBytes, getStampUsage, marshalStamp as coreMarshalStamp } from '@ethersphere/core-sdk';
7
+ export { getStampEffectiveBytes, getStampEffectiveBytesBreakpoints, getStampTheoreticalBytes, getStampUsage };
74
8
  /**
75
9
  * Utility function that calculates the cost of a postage batch based on its depth and amount.
76
10
  */
@@ -105,41 +39,13 @@ export function getAmountForDuration(duration, pricePerBlock, blockTime) {
105
39
  * @returns
106
40
  */
107
41
  export function getDepthForSize(size, encryption, erasureCodeLevel) {
108
- if (encryption !== undefined && erasureCodeLevel !== undefined) {
109
- const encryptionKey = encryption ? 'ENCRYPTION_ON' : 'ENCRYPTION_OFF';
110
- const breakpoints = capacityBreakpoints[encryptionKey][erasureCodeLevel];
111
- const entry = breakpoints.find(item => {
112
- return size.toBytes() <= parseSizeToBytes(item.effectiveVolume);
113
- });
114
- if (entry?.effectiveVolume) {
115
- return entry.batchDepth;
116
- }
117
- } else {
118
- for (const [depth, sizeBreakpoint] of effectiveSizeBreakpoints) {
119
- if (size.toBytes() <= sizeBreakpoint * 1000 * 1000 * 1000) {
120
- return depth;
121
- }
122
- }
123
- }
124
- return 35;
42
+ return coreGetDepthForSize(size.toBytes(), encryption, erasureCodeLevel);
125
43
  }
126
44
  export function convertEnvelopeToMarshaledStamp(envelope) {
127
- return marshalStamp(envelope.signature, envelope.batchId.toUint8Array(), envelope.timestamp, envelope.index);
45
+ return coreConvertEnvelopeToMarshaledStamp(envelope);
128
46
  }
129
47
  export function marshalStamp(signature, batchId, timestamp, index) {
130
- if (signature.length !== 65) {
131
- throw Error('invalid signature length');
132
- }
133
- if (batchId.length !== 32) {
134
- throw Error('invalid batch ID length');
135
- }
136
- if (timestamp.length !== 8) {
137
- throw Error('invalid timestamp length');
138
- }
139
- if (index.length !== 8) {
140
- throw Error('invalid index length');
141
- }
142
- return new Bytes(Binary.concatBytes(batchId, index, timestamp, signature));
48
+ return coreMarshalStamp(signature, batchId, timestamp, index);
143
49
  }
144
50
  export function mapPostageBatch(raw, encryption, erasureCodeLevel) {
145
51
  const batchTTL = normalizeBatchTTL(raw.batchTTL);
@@ -28,8 +28,8 @@ export function isTag(value) {
28
28
  * @throws TypeError if not valid
29
29
  */
30
30
  export function assertData(value) {
31
- if (typeof value !== 'string' && !(value instanceof Uint8Array)) {
32
- throw new TypeError('Data must be either string or Uint8Array!');
31
+ if (typeof value !== 'string' && !(value instanceof Uint8Array) && !(value instanceof Blob) && !isReadable(value)) {
32
+ throw new TypeError('Data must be either string, Uint8Array, Blob or Readable!');
33
33
  }
34
34
  }
35
35
  /**
@@ -1,5 +1,5 @@
1
+ import { PeerAddress } from '@ethersphere/core-sdk';
1
2
  import type { BalanceResponse, BeeRequestOptions, PeerBalance } from '../types';
2
- import { PeerAddress } from '../utils/typed-bytes';
3
3
  /**
4
4
  * Raw HTTP calls for the `/balances` endpoint.
5
5
  */
@@ -1,5 +1,5 @@
1
+ import { BatchId } from '@ethersphere/core-sdk';
1
2
  import type { BeeRequestOptions, GlobalPostageBatch } from '../types';
2
- import { BatchId } from '../utils/typed-bytes';
3
3
  /**
4
4
  * Raw HTTP calls for the `/batches` endpoint.
5
5
  */
@@ -1,12 +1,12 @@
1
+ import { BatchId, Bytes, Reference } from '@ethersphere/core-sdk';
2
+ import { Readable } from 'stream';
1
3
  import type { BeeRequestOptions, DownloadOptions, RedundantUploadOptions, ReferenceInformation } from '../types';
2
4
  import { UploadResult } from '../types';
3
- import { Bytes } from '../utils/bytes';
4
5
  import { ResourceLocator } from '../utils/resource-locator';
5
- import { BatchId, Reference } from '../utils/typed-bytes';
6
6
  /**
7
7
  * Raw HTTP calls for the `/bytes` endpoint.
8
8
  */
9
- export declare function upload(requestOptions: BeeRequestOptions, data: string | Uint8Array, postageBatchId: BatchId, options?: RedundantUploadOptions): Promise<UploadResult>;
9
+ export declare function upload(requestOptions: BeeRequestOptions, data: string | Uint8Array | Blob | Readable, postageBatchId: BatchId, options?: RedundantUploadOptions): Promise<UploadResult>;
10
10
  export declare function head(requestOptions: BeeRequestOptions, reference: Reference): Promise<ReferenceInformation>;
11
11
  export declare function download(requestOptions: BeeRequestOptions, resource: ResourceLocator, options?: DownloadOptions): Promise<Bytes>;
12
12
  export declare function downloadReadable(requestOptions: BeeRequestOptions, resource: ResourceLocator, options?: DownloadOptions): Promise<ReadableStream<Uint8Array>>;
@@ -1,8 +1,7 @@
1
+ import { BatchId, Bytes, Reference } from '@ethersphere/core-sdk';
1
2
  import { Readable } from 'stream';
2
3
  import { BeeRequestOptions, Collection, CollectionUploadOptions, DownloadOptions, FileData, FileUploadOptions, UploadResult } from '../types';
3
- import { Bytes } from '../utils/bytes';
4
4
  import { ResourceLocator } from '../utils/resource-locator';
5
- import { BatchId, Reference } from '../utils/typed-bytes';
6
5
  /**
7
6
  * Raw HTTP calls for the `/bzz` endpoint.
8
7
  */
@@ -1,5 +1,5 @@
1
+ import { PeerAddress, TransactionId } from '@ethersphere/core-sdk';
1
2
  import type { BeeRequestOptions, ChequebookAddressResponse, ChequebookBalanceResponse, LastCashoutActionResponse, LastChequesForPeerResponse, LastChequesResponse, TransactionOptions } from '../types';
2
- import { PeerAddress, TransactionId } from '../utils/typed-bytes';
3
3
  /**
4
4
  * Raw HTTP calls for the `/chequebook` endpoint (chequebook + cheque operations).
5
5
  */
@@ -1,5 +1,5 @@
1
+ import { BatchId, Reference } from '@ethersphere/core-sdk';
1
2
  import type { BeeRequestOptions, DownloadOptions, EnvelopeWithBatchId, UploadOptions, UploadResult } from '../types';
2
- import { BatchId, Reference } from '../utils/typed-bytes';
3
3
  /**
4
4
  * Raw HTTP calls for the `/chunks` endpoint.
5
5
  */
@@ -1,6 +1,6 @@
1
+ import { PeerAddress } from '@ethersphere/core-sdk';
1
2
  import type { BeeRequestOptions, Peer, PingResponse, RemovePeerResponse, Topology } from '../types';
2
3
  import { NodeAddresses } from '../types/debug';
3
- import { PeerAddress } from '../utils/typed-bytes';
4
4
  /**
5
5
  * Raw HTTP calls for the connectivity endpoints (`/addresses`, `/peers`, `/topology`, `/blocklist`, `/pingpong`, etc.).
6
6
  */
@@ -1,5 +1,5 @@
1
+ import { PeerAddress } from '@ethersphere/core-sdk';
1
2
  import type { BalanceResponse, BeeRequestOptions, PeerBalance } from '../types';
2
- import { PeerAddress } from '../utils/typed-bytes';
3
3
  /**
4
4
  * Raw HTTP calls for the `/consumed` endpoint.
5
5
  */
@@ -1,3 +1,3 @@
1
+ import { BatchId, Reference } from '@ethersphere/core-sdk';
1
2
  import type { BeeRequestOptions, EnvelopeWithBatchId } from '../types';
2
- import { BatchId, Reference } from '../utils/typed-bytes';
3
3
  export declare function postEnvelope(requestOptions: BeeRequestOptions, postageBatchId: BatchId, reference: Reference): Promise<EnvelopeWithBatchId>;
@@ -1,6 +1,5 @@
1
+ import { BatchId, Bytes, EthAddress, FeedIndex, Reference, Topic } from '@ethersphere/core-sdk';
1
2
  import type { BeeRequestOptions, UploadOptions } from '../types';
2
- import { Bytes } from '../utils/bytes';
3
- import { BatchId, EthAddress, FeedIndex, Reference, Topic } from '../utils/typed-bytes';
4
3
  /**
5
4
  * Raw HTTP calls for the `/feeds` endpoint.
6
5
  */
@@ -1,5 +1,5 @@
1
+ import { BatchId, PublicKey, Reference } from '@ethersphere/core-sdk';
1
2
  import type { BeeRequestOptions, GetGranteesResult, GranteesResult } from '../types';
2
- import { BatchId, PublicKey, Reference } from '../utils/typed-bytes';
3
3
  /** Creates grantees for a postage batch. */
4
4
  export declare function createGrantees(requestOptions: BeeRequestOptions, batchId: BatchId, publicKeys: PublicKey[]): Promise<GranteesResult>;
5
5
  /** Retrieves the grantees for a given reference. */
@@ -1,5 +1,5 @@
1
+ import { Reference } from '@ethersphere/core-sdk';
1
2
  import type { BeeRequestOptions, Pin as PinData } from '../types';
2
- import { Reference } from '../utils/typed-bytes';
3
3
  /** Pins local data with the given reference. */
4
4
  export declare function pin(requestOptions: BeeRequestOptions, reference: Reference): Promise<void>;
5
5
  /** Unpins local data with the given reference. */
@@ -1,5 +1,5 @@
1
+ import { BatchId, PublicKey, Topic } from '@ethersphere/core-sdk';
1
2
  import type { BeeRequestOptions } from '../types';
2
- import { BatchId, PublicKey, Topic } from '../utils/typed-bytes';
3
3
  /**
4
4
  * Sends a message with the Postal Service for Swarm through the `POST /pss/send` endpoint.
5
5
  */
@@ -1,5 +1,5 @@
1
+ import { PeerAddress } from '@ethersphere/core-sdk';
1
2
  import type { AllSettlements, BeeRequestOptions, Settlements } from '../types';
2
- import { PeerAddress } from '../utils/typed-bytes';
3
3
  /**
4
4
  * Raw HTTP calls for the `/settlements` endpoint.
5
5
  */
@@ -1,5 +1,5 @@
1
+ import { BatchId, EthAddress, Identifier, Signature } from '@ethersphere/core-sdk';
1
2
  import type { BeeRequestOptions, UploadOptions, UploadResult } from '../types';
2
- import { BatchId, EthAddress, Identifier, Signature } from '../utils/typed-bytes';
3
3
  /**
4
4
  * Raw HTTP calls for the `/soc` endpoint.
5
5
  */
@@ -1,6 +1,6 @@
1
+ import { TransactionId } from '@ethersphere/core-sdk';
1
2
  import type { BeeRequestOptions, TransactionOptions } from '../types';
2
3
  import { BZZ } from '../utils/tokens';
3
- import { TransactionId } from '../utils/typed-bytes';
4
4
  /**
5
5
  * Raw HTTP calls for the `/stake` endpoint.
6
6
  */
@@ -1,5 +1,5 @@
1
+ import { BatchId } from '@ethersphere/core-sdk';
1
2
  import type { BeeRequestOptions, NumberString, PostageBatch, PostageBatchBuckets, RedundancyLevel } from '../types';
2
- import { BatchId } from '../utils/typed-bytes';
3
3
  /**
4
4
  * Raw HTTP calls for the `/stamps` endpoint.
5
5
  */