@ethersphere/bee-js 8.3.1 → 9.0.2

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 (224) hide show
  1. package/README.md +192 -50
  2. package/dist/cjs/bee-dev.js +78 -0
  3. package/dist/cjs/bee.js +341 -417
  4. package/dist/cjs/chunk/bmt.js +15 -32
  5. package/dist/cjs/chunk/cac.js +26 -36
  6. package/dist/cjs/chunk/soc.js +56 -51
  7. package/dist/cjs/feed/identifier.js +3 -28
  8. package/dist/cjs/feed/index.js +95 -44
  9. package/dist/cjs/feed/retrievable.js +11 -22
  10. package/dist/cjs/index.js +17 -1
  11. package/dist/cjs/manifest/manifest.js +369 -0
  12. package/dist/cjs/modules/bytes.js +24 -12
  13. package/dist/cjs/modules/bzz.js +24 -34
  14. package/dist/cjs/modules/chunk.js +13 -7
  15. package/dist/cjs/modules/debug/balance.js +29 -4
  16. package/dist/cjs/modules/debug/chequebook.js +60 -16
  17. package/dist/cjs/modules/debug/connectivity.js +82 -4
  18. package/dist/cjs/modules/debug/settlements.js +22 -2
  19. package/dist/cjs/modules/debug/stake.js +29 -11
  20. package/dist/cjs/modules/debug/stamps.js +88 -7
  21. package/dist/cjs/modules/debug/states.js +25 -3
  22. package/dist/cjs/modules/debug/status.js +45 -47
  23. package/dist/cjs/modules/debug/transactions.js +27 -5
  24. package/dist/cjs/modules/envelope.js +8 -6
  25. package/dist/cjs/modules/feed.js +25 -10
  26. package/dist/cjs/modules/grantee.js +18 -12
  27. package/dist/cjs/modules/gsoc.js +24 -0
  28. package/dist/cjs/modules/pinning.js +13 -2
  29. package/dist/cjs/modules/pss.js +9 -3
  30. package/dist/cjs/modules/soc.js +9 -4
  31. package/dist/cjs/modules/stewardship.js +7 -3
  32. package/dist/cjs/modules/tag.js +35 -3
  33. package/dist/cjs/package.json +1 -0
  34. package/dist/cjs/stamper/stamper.js +43 -0
  35. package/dist/cjs/types/debug.js +16 -1
  36. package/dist/cjs/types/index.js +2 -24
  37. package/dist/cjs/utils/bytes.js +67 -115
  38. package/dist/cjs/utils/chunk-size.js +17 -0
  39. package/dist/cjs/utils/chunk-stream.browser.js +85 -0
  40. package/dist/cjs/utils/chunk-stream.js +84 -0
  41. package/dist/cjs/utils/cid.js +5 -6
  42. package/dist/cjs/utils/collection.browser.js +2 -2
  43. package/dist/cjs/utils/collection.js +3 -2
  44. package/dist/cjs/utils/collection.node.js +0 -2
  45. package/dist/cjs/utils/constants.js +7 -3
  46. package/dist/cjs/utils/data.browser.js +6 -3
  47. package/dist/cjs/utils/data.js +8 -4
  48. package/dist/cjs/utils/duration.js +51 -0
  49. package/dist/cjs/utils/expose.js +11 -40
  50. package/dist/cjs/utils/headers.js +79 -52
  51. package/dist/cjs/utils/http.js +34 -10
  52. package/dist/cjs/utils/mime.js +78 -0
  53. package/dist/cjs/utils/pss.js +3 -4
  54. package/dist/cjs/utils/redundancy.js +18 -14
  55. package/dist/cjs/utils/resource-locator.js +17 -0
  56. package/dist/cjs/utils/size.js +35 -0
  57. package/dist/cjs/utils/stamps.js +67 -51
  58. package/dist/cjs/utils/tar-uploader.browser.js +2 -2
  59. package/dist/cjs/utils/tar-uploader.js +2 -2
  60. package/dist/cjs/utils/tokens.js +144 -0
  61. package/dist/cjs/utils/type.js +142 -350
  62. package/dist/cjs/utils/typed-bytes.js +179 -0
  63. package/dist/cjs/utils/upload-progress.js +2 -0
  64. package/dist/cjs/utils/url.js +0 -4
  65. package/dist/cjs/utils/workaround.js +27 -0
  66. package/dist/index.browser.min.js +1 -2
  67. package/dist/index.browser.min.js.map +1 -1
  68. package/dist/mjs/bee-dev.js +98 -0
  69. package/dist/mjs/bee.js +367 -411
  70. package/dist/mjs/chunk/bmt.js +13 -29
  71. package/dist/mjs/chunk/cac.js +26 -34
  72. package/dist/mjs/chunk/soc.js +57 -53
  73. package/dist/mjs/feed/identifier.js +3 -26
  74. package/dist/mjs/feed/index.js +98 -51
  75. package/dist/mjs/feed/retrievable.js +12 -23
  76. package/dist/mjs/index.js +10 -1
  77. package/dist/mjs/manifest/manifest.js +371 -0
  78. package/dist/mjs/modules/bytes.js +27 -15
  79. package/dist/mjs/modules/bzz.js +25 -32
  80. package/dist/mjs/modules/chunk.js +16 -8
  81. package/dist/mjs/modules/debug/balance.js +61 -4
  82. package/dist/mjs/modules/debug/chequebook.js +116 -16
  83. package/dist/mjs/modules/debug/connectivity.js +144 -3
  84. package/dist/mjs/modules/debug/settlements.js +46 -2
  85. package/dist/mjs/modules/debug/stake.js +69 -11
  86. package/dist/mjs/modules/debug/stamps.js +184 -7
  87. package/dist/mjs/modules/debug/states.js +55 -3
  88. package/dist/mjs/modules/debug/status.js +97 -45
  89. package/dist/mjs/modules/debug/transactions.js +61 -5
  90. package/dist/mjs/modules/envelope.js +11 -9
  91. package/dist/mjs/modules/feed.js +26 -10
  92. package/dist/mjs/modules/grantee.js +35 -13
  93. package/dist/mjs/modules/gsoc.js +16 -0
  94. package/dist/mjs/modules/pinning.js +23 -2
  95. package/dist/mjs/modules/pss.js +10 -4
  96. package/dist/mjs/modules/soc.js +10 -5
  97. package/dist/mjs/modules/stewardship.js +14 -4
  98. package/dist/mjs/modules/tag.js +93 -3
  99. package/dist/mjs/package.json +2 -1
  100. package/dist/mjs/stamper/stamper.js +39 -0
  101. package/dist/mjs/types/debug.js +15 -1
  102. package/dist/mjs/types/index.js +2 -24
  103. package/dist/mjs/utils/bytes.js +63 -104
  104. package/dist/mjs/utils/chunk-size.js +13 -0
  105. package/dist/mjs/utils/chunk-stream.browser.js +85 -0
  106. package/dist/mjs/utils/chunk-stream.js +87 -0
  107. package/dist/mjs/utils/cid.js +5 -6
  108. package/dist/mjs/utils/collection.browser.js +2 -2
  109. package/dist/mjs/utils/collection.js +2 -2
  110. package/dist/mjs/utils/collection.node.js +0 -2
  111. package/dist/mjs/utils/constants.js +6 -2
  112. package/dist/mjs/utils/data.browser.js +9 -3
  113. package/dist/mjs/utils/data.js +12 -4
  114. package/dist/mjs/utils/duration.js +47 -0
  115. package/dist/mjs/utils/expose.js +2 -7
  116. package/dist/mjs/utils/headers.js +73 -48
  117. package/dist/mjs/utils/http.js +33 -11
  118. package/dist/mjs/utils/mime.js +75 -0
  119. package/dist/mjs/utils/pss.js +3 -4
  120. package/dist/mjs/utils/redundancy.js +18 -8
  121. package/dist/mjs/utils/resource-locator.js +13 -0
  122. package/dist/mjs/utils/size.js +31 -0
  123. package/dist/mjs/utils/stamps.js +47 -44
  124. package/dist/mjs/utils/tar-uploader.browser.js +2 -2
  125. package/dist/mjs/utils/tar-uploader.js +2 -2
  126. package/dist/mjs/utils/tokens.js +139 -0
  127. package/dist/mjs/utils/type.js +216 -310
  128. package/dist/mjs/utils/typed-bytes.js +160 -0
  129. package/dist/mjs/utils/upload-progress.js +1 -0
  130. package/dist/mjs/utils/url.js +0 -4
  131. package/dist/mjs/utils/workaround.js +22 -0
  132. package/dist/types/bee-dev.d.ts +5 -0
  133. package/dist/types/bee.d.ts +88 -165
  134. package/dist/types/chunk/bmt.d.ts +2 -2
  135. package/dist/types/chunk/cac.d.ts +7 -24
  136. package/dist/types/chunk/soc.d.ts +15 -15
  137. package/dist/types/feed/identifier.d.ts +2 -4
  138. package/dist/types/feed/index.d.ts +14 -18
  139. package/dist/types/feed/retrievable.d.ts +3 -4
  140. package/dist/types/index.d.ts +28 -1
  141. package/dist/types/manifest/manifest.d.ts +106 -0
  142. package/dist/types/modules/bytes.d.ts +8 -5
  143. package/dist/types/modules/bzz.d.ts +8 -10
  144. package/dist/types/modules/chunk.d.ts +4 -3
  145. package/dist/types/modules/debug/balance.d.ts +3 -2
  146. package/dist/types/modules/debug/chequebook.d.ts +7 -6
  147. package/dist/types/modules/debug/connectivity.d.ts +5 -3
  148. package/dist/types/modules/debug/settlements.d.ts +2 -1
  149. package/dist/types/modules/debug/stake.d.ts +4 -2
  150. package/dist/types/modules/debug/stamps.d.ts +5 -4
  151. package/dist/types/modules/debug/status.d.ts +6 -25
  152. package/dist/types/modules/debug/transactions.d.ts +5 -4
  153. package/dist/types/modules/envelope.d.ts +3 -2
  154. package/dist/types/modules/feed.d.ts +20 -16
  155. package/dist/types/modules/grantee.d.ts +7 -6
  156. package/dist/types/modules/gsoc.d.ts +7 -0
  157. package/dist/types/modules/pinning.d.ts +2 -4
  158. package/dist/types/modules/pss.d.ts +4 -3
  159. package/dist/types/modules/soc.d.ts +3 -2
  160. package/dist/types/modules/stewardship.d.ts +4 -4
  161. package/dist/types/modules/tag.d.ts +2 -1
  162. package/dist/types/stamper/stamper.d.ts +15 -0
  163. package/dist/types/types/debug.d.ts +63 -115
  164. package/dist/types/types/index.d.ts +103 -204
  165. package/dist/types/utils/bytes.d.ts +16 -90
  166. package/dist/types/utils/chunk-size.d.ts +1 -0
  167. package/dist/types/utils/chunk-stream.browser.d.ts +6 -0
  168. package/dist/types/utils/chunk-stream.d.ts +6 -0
  169. package/dist/types/utils/cid.d.ts +3 -2
  170. package/dist/types/utils/collection.browser.d.ts +2 -2
  171. package/dist/types/utils/collection.d.ts +2 -1
  172. package/dist/types/utils/collection.node.d.ts +0 -1
  173. package/dist/types/utils/constants.d.ts +4 -1
  174. package/dist/types/utils/duration.d.ts +17 -0
  175. package/dist/types/utils/error.d.ts +2 -2
  176. package/dist/types/utils/expose.d.ts +2 -7
  177. package/dist/types/utils/headers.d.ts +3 -4
  178. package/dist/types/utils/mime.d.ts +1 -0
  179. package/dist/types/utils/pss.d.ts +2 -2
  180. package/dist/types/utils/resource-locator.d.ts +6 -0
  181. package/dist/types/utils/size.d.ts +16 -0
  182. package/dist/types/utils/stamps.d.ts +27 -33
  183. package/dist/types/utils/tar-uploader.browser.d.ts +3 -4
  184. package/dist/types/utils/tar-uploader.d.ts +3 -4
  185. package/dist/types/utils/tokens.d.ts +77 -0
  186. package/dist/types/utils/type.d.ts +20 -52
  187. package/dist/types/utils/typed-bytes.d.ts +68 -0
  188. package/dist/types/utils/upload-progress.d.ts +4 -0
  189. package/dist/types/utils/workaround.d.ts +2 -0
  190. package/package.json +11 -17
  191. package/dist/cjs/chunk/signer.js +0 -126
  192. package/dist/cjs/chunk/span.js +0 -25
  193. package/dist/cjs/feed/json.js +0 -28
  194. package/dist/cjs/feed/topic.js +0 -25
  195. package/dist/cjs/feed/type.js +0 -15
  196. package/dist/cjs/modules/debug/chunk.js +0 -21
  197. package/dist/cjs/modules/debug/tag.js +0 -19
  198. package/dist/cjs/utils/eth.js +0 -216
  199. package/dist/cjs/utils/hash.js +0 -21
  200. package/dist/cjs/utils/hex.js +0 -150
  201. package/dist/cjs/utils/reference.js +0 -36
  202. package/dist/index.browser.min.js.LICENSE.txt +0 -8
  203. package/dist/mjs/chunk/signer.js +0 -114
  204. package/dist/mjs/chunk/span.js +0 -21
  205. package/dist/mjs/feed/json.js +0 -26
  206. package/dist/mjs/feed/topic.js +0 -19
  207. package/dist/mjs/feed/type.js +0 -10
  208. package/dist/mjs/modules/debug/chunk.js +0 -17
  209. package/dist/mjs/modules/debug/tag.js +0 -15
  210. package/dist/mjs/utils/eth.js +0 -192
  211. package/dist/mjs/utils/hash.js +0 -16
  212. package/dist/mjs/utils/hex.js +0 -135
  213. package/dist/mjs/utils/reference.js +0 -29
  214. package/dist/types/chunk/signer.d.ts +0 -31
  215. package/dist/types/chunk/span.d.ts +0 -10
  216. package/dist/types/feed/json.d.ts +0 -4
  217. package/dist/types/feed/topic.d.ts +0 -3
  218. package/dist/types/feed/type.d.ts +0 -6
  219. package/dist/types/modules/debug/chunk.d.ts +0 -10
  220. package/dist/types/modules/debug/tag.d.ts +0 -8
  221. package/dist/types/utils/eth.d.ts +0 -67
  222. package/dist/types/utils/hash.d.ts +0 -9
  223. package/dist/types/utils/hex.d.ts +0 -86
  224. package/dist/types/utils/reference.d.ts +0 -2
@@ -1,7 +1,6 @@
1
1
  import { Collection } from '../types';
2
2
  /**
3
3
  * Creates array in the format of Collection with data loaded from directory on filesystem.
4
- * The function loads all the data into memory!
5
4
  *
6
5
  * @param dir path to the directory
7
6
  */
@@ -1,4 +1,7 @@
1
- import { BatchId, Topic } from '..';
1
+ import { BatchId, Topic } from './typed-bytes';
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;
5
+ export declare const NULL_ADDRESS: Uint8Array;
6
+ export declare const NULL_IDENTIFIER: Uint8Array;
7
+ export declare const NULL_OWNER: Uint8Array;
@@ -0,0 +1,17 @@
1
+ export declare class Duration {
2
+ private seconds;
3
+ private constructor();
4
+ static fromMilliseconds(milliseconds: number): Duration;
5
+ static fromSeconds(seconds: number): Duration;
6
+ static fromHours(hours: number): Duration;
7
+ static fromDays(days: number): Duration;
8
+ static fromWeeks(weeks: number): Duration;
9
+ static fromYears(years: number): Duration;
10
+ static fromEndDate(endDate: Date, startDate?: Date): Duration;
11
+ toSeconds(): number;
12
+ toHours(): number;
13
+ toDays(): number;
14
+ toWeeks(): number;
15
+ toYears(): number;
16
+ toEndDate(startDate?: Date): Date;
17
+ }
@@ -8,8 +8,8 @@ export declare class BeeArgumentError extends BeeError {
8
8
  export declare class BeeResponseError extends BeeError {
9
9
  method: string;
10
10
  url: string;
11
- responseBody?: any;
11
+ responseBody?: unknown;
12
12
  status?: number | undefined;
13
13
  statusText?: string | undefined;
14
- constructor(method: string, url: string, message: string, responseBody?: any, status?: number | undefined, statusText?: string | undefined);
14
+ constructor(method: string, url: string, message: string, responseBody?: unknown, status?: number | undefined, statusText?: string | undefined);
15
15
  }
@@ -1,10 +1,5 @@
1
- export { getCollectionSize } from './collection';
1
+ export { getCollectionSize, makeCollectionFromFileList } from './collection';
2
2
  export { getFolderSize } from './collection.node';
3
- export { Bytes, FlexBytes, assertBytes, assertFlexBytes, bytesAtOffset, bytesEqual, flexBytesAtOffset, isBytes, isFlexBytes, } from './bytes';
4
- export { HexString, PrefixedHexString, assertHexString, assertPrefixedHexString, bytesToHex, hexToBytes, intToHex, isHexString, makeHexString, } from './hex';
5
- export { EthAddress, capitalizeAddressERC55, ethToSwarmAddress, fromLittleEndian, isHexEthAddress, makeEthAddress, makeEthereumWalletSigner, makeHexEthAddress, toLittleEndian, } from './eth';
6
- export { keccak256Hash } from './hash';
7
3
  export { makeMaxTarget } from './pss';
8
- export { getAmountForTtl, getDepthForCapacity, getStampCostInBzz, getStampCostInPlur, getStampEffectiveBytes, getStampMaximumCapacityBytes, getStampTtlSeconds, getStampUsage, } from './stamps';
9
4
  export { approximateOverheadForRedundancyLevel, getRedundancyStat, getRedundancyStats } from './redundancy';
10
- export { convertCidToReference, convertReferenceToCid } from './cid';
5
+ export { getAmountForDuration, getDepthForSize, getStampCost, getStampDuration, getStampEffectiveBytes, getStampEffectiveBytesBreakpoints, getStampTheoreticalBytes, getStampUsage, } from './stamps';
@@ -1,5 +1,4 @@
1
- import { BatchId, DownloadRedundancyOptions, FileHeaders, UploadOptions, UploadRedundancyOptions } from '../types';
1
+ import { EnvelopeWithBatchId, FileHeaders } from '../types';
2
+ import { BatchId } from './typed-bytes';
2
3
  export declare function readFileHeaders(headers: Record<string, string>): FileHeaders;
3
- export declare function extractUploadHeaders(stamp: BatchId | Uint8Array | string, options?: UploadOptions): Record<string, string>;
4
- export declare function extractRedundantUploadHeaders(postageBatchId: BatchId, options?: UploadOptions & UploadRedundancyOptions): Record<string, string>;
5
- export declare function extractDownloadHeaders(options?: DownloadRedundancyOptions): Record<string, string>;
4
+ export declare function prepareRequestHeaders(stamp: BatchId | Uint8Array | string | EnvelopeWithBatchId | null, nullableOptions?: unknown): Record<string, string>;
@@ -0,0 +1 @@
1
+ export declare const mimes: Record<string, string>;
@@ -1,4 +1,4 @@
1
- import { AddressPrefix } from '../types';
1
+ import { PeerAddress } from './typed-bytes';
2
2
  /**
3
3
  * Utility function that for given strings/reference takes the most specific
4
4
  * target that Bee node will except.
@@ -6,4 +6,4 @@ import { AddressPrefix } from '../types';
6
6
  * @param target is a non-prefixed hex string Bee address
7
7
  * @see [Bee docs - PSS](https://docs.ethswarm.org/docs/develop/tools-and-features/pss)
8
8
  */
9
- export declare function makeMaxTarget(target: string): AddressPrefix;
9
+ export declare function makeMaxTarget(target: PeerAddress | Uint8Array | string): string;
@@ -0,0 +1,6 @@
1
+ import { Reference } from './typed-bytes';
2
+ export declare class ResourceLocator {
3
+ private raw;
4
+ constructor(raw: Reference | Uint8Array | string);
5
+ toString(): string;
6
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Represents a size in bytes.
3
+ *
4
+ * Uses 1000 instead of 1024 for converting between units.
5
+ * This is to stay consistent with the Swarm papers
6
+ * on theoretical and effective storage capacity.
7
+ */
8
+ export declare class Size {
9
+ private bytes;
10
+ private constructor();
11
+ static fromBytes(bytes: number): Size;
12
+ static fromGigabytes(gigabytes: number): Size;
13
+ toBytes(): number;
14
+ toGigabytes(): number;
15
+ toFormattedString(): string;
16
+ }
@@ -1,4 +1,8 @@
1
- import { BatchId, Envelope, NumberString } from '../types';
1
+ import { EnvelopeWithBatchId, NumberString } from '../types';
2
+ import { Bytes } from './bytes';
3
+ import { Duration } from './duration';
4
+ import { Size } from './size';
5
+ import { BZZ } from './tokens';
2
6
  /**
3
7
  * Utility function that calculates usage of postage batch based on its utilization, depth and bucket depth.
4
8
  *
@@ -8,59 +12,49 @@ import { BatchId, Envelope, NumberString } from '../types';
8
12
  */
9
13
  export declare function getStampUsage(utilization: number, depth: number, bucketDepth: number): number;
10
14
  /**
11
- * Utility function that calculates the theoritical maximum capacity of a postage batch based on its depth.
15
+ * Utility function that calculates the theoritical maximum size of a postage batch based on its depth.
12
16
  *
13
- * For smaller depths (up to 20), this may provide less accurate results.
17
+ * For smaller depths (up to 22), this may provide less accurate results.
14
18
  *
15
- * @returns {number} The maximum capacity of the postage batch in bytes.
19
+ * @returns {number} The maximum theoretical size of the postage batch in bytes.
16
20
  */
17
- export declare function getStampMaximumCapacityBytes(depth: number): number;
21
+ export declare function getStampTheoreticalBytes(depth: number): number;
18
22
  /**
19
- * Utility function that calculates the effective volume of a postage batch based on its depth.
23
+ * Utility function that calculates the effective size of a postage batch based on its depth.
20
24
  *
21
- * Below 22 depth the effective volume is 0
25
+ * Below 22 depth the effective size is 0
22
26
  * Above 34 it's always > 99%
23
27
  *
24
- * @returns {number} The effective volume of the postage batch in bytes.
28
+ * @returns {number} The effective size of the postage batch in bytes.
25
29
  */
26
30
  export declare function getStampEffectiveBytes(depth: number): number;
31
+ export declare function getStampEffectiveBytesBreakpoints(): Map<number, number>;
27
32
  /**
28
33
  * Utility function that calculates the cost of a postage batch based on its depth and amount.
29
- *
30
- * @returns {number} The cost of the postage batch in PLUR (10000000000000000 [1e16] PLUR = 1 BZZ)
31
- */
32
- export declare function getStampCostInPlur(depth: number, amount: number): number;
33
- /**
34
- * Utility function that calculates the cost of a postage batch based on its depth and amount.
35
- *
36
- * @returns {number} The cost of the postage batch in BZZ (1 BZZ = 10000000000000000 [1e16] PLUR)
37
34
  */
38
- export declare function getStampCostInBzz(depth: number, amount: number): number;
35
+ export declare function getStampCost(depth: number, amount: NumberString | string | bigint): BZZ;
39
36
  /**
40
37
  * Utility function that calculates the TTL of a postage batch based on its amount, price per block and block time.
41
38
  *
42
39
  * For more accurate results, get the price per block and block time from the Bee node or the blockchain.
43
40
  *
44
- * @returns {number} The TTL of the postage batch in seconds.
41
+ * @returns {number} The TTL of the postage batch.
45
42
  */
46
- export declare function getStampTtlSeconds(amount: number, pricePerBlock?: number, blockTime?: number): number;
43
+ export declare function getStampDuration(amount: NumberString | string | bigint, pricePerBlock: number, blockTime?: number): Duration;
47
44
  /**
48
- * Utility function that calculates the amount of tokens required to maintain a given Time To Live (TTL) for a postage batch.
45
+ * Get the postage batch `amount` required for a given `duration`.
49
46
  *
50
- * This function estimates the required amount based on the provided TTL in days.
51
- *
52
- * @param {number} days - The Time To Live (TTL) in days.
53
- * @returns {NumberString} The estimated amount of tokens needed for the specified TTL.
47
+ * @param duration A duration object representing the duration of the storage.
48
+ * @param pricePerBlock The price per block in PLUR.
49
+ * @param blockTime The block time in seconds.
54
50
  */
55
- export declare function getAmountForTtl(days: number): NumberString;
51
+ export declare function getAmountForDuration(duration: Duration, pricePerBlock: number, blockTime?: number): bigint;
56
52
  /**
57
- * Utility function that calculates the depth required for a postage batch to achieve the specified capacity in gigabytes.
58
- *
59
- * The depth is determined based on the given gigabytes, and the result is adjusted to a minimum depth of 18.
53
+ * Utility function that calculates the depth required for a postage batch to achieve the specified effective size
60
54
  *
61
- * @param {number} gigabytes - The desired capacity of the postage batch in gigabytes.
62
- * @returns {number} The calculated depth necessary to achieve the specified capacity.
55
+ * @param size The effective size of the postage batch
56
+ * @returns
63
57
  */
64
- export declare function getDepthForCapacity(gigabytes: number): number;
65
- export declare function convertEnvelopeToMarshaledStamp(batchID: BatchId, envelope: Envelope): Uint8Array;
66
- export declare function marshalStamp(signature: Uint8Array, batchID: Uint8Array, timestamp: Uint8Array, index: Uint8Array): Uint8Array;
58
+ export declare function getDepthForSize(size: Size): number;
59
+ export declare function convertEnvelopeToMarshaledStamp(envelope: EnvelopeWithBatchId): Bytes;
60
+ export declare function marshalStamp(signature: Uint8Array, batchId: Uint8Array, timestamp: Uint8Array, index: Uint8Array): Bytes;
@@ -1,4 +1,3 @@
1
- import { BatchId, BeeRequestOptions, Collection, CollectionUploadOptions, Reference, UploadRedundancyOptions } from '..';
2
- export declare function uploadTar(requestOptions: BeeRequestOptions, collection: Collection, postageBatchId: BatchId, options?: CollectionUploadOptions & UploadRedundancyOptions): Promise<import("axios").AxiosResponse<{
3
- reference: Reference;
4
- }, any>>;
1
+ import { BeeRequestOptions, Collection, CollectionUploadOptions } from '..';
2
+ import { BatchId } from './typed-bytes';
3
+ export declare function uploadTar(requestOptions: BeeRequestOptions, collection: Collection, postageBatchId: BatchId, options?: CollectionUploadOptions): Promise<import("axios").AxiosResponse<unknown, any>>;
@@ -1,4 +1,3 @@
1
- import { BatchId, BeeRequestOptions, Collection, CollectionUploadOptions, Reference, UploadRedundancyOptions } from '..';
2
- export declare function uploadTar(requestOptions: BeeRequestOptions, collection: Collection, postageBatchId: BatchId, options?: CollectionUploadOptions & UploadRedundancyOptions): Promise<import("axios").AxiosResponse<{
3
- reference: Reference;
4
- }, any>>;
1
+ import { BeeRequestOptions, Collection, CollectionUploadOptions } from '..';
2
+ import { BatchId } from './typed-bytes';
3
+ export declare function uploadTar(requestOptions: BeeRequestOptions, collection: Collection, postageBatchId: BatchId, options?: CollectionUploadOptions): Promise<import("axios").AxiosResponse<unknown, any>>;
@@ -0,0 +1,77 @@
1
+ import { NumberString } from '..';
2
+ export declare class BZZ {
3
+ static readonly DIGITS = 16;
4
+ private state;
5
+ private constructor();
6
+ static fromDecimalString(string: string): BZZ;
7
+ static fromPLUR(plur: NumberString | string | bigint): BZZ;
8
+ toPLURString(): string;
9
+ toPLURBigInt(): bigint;
10
+ toDecimalString(): string;
11
+ toSignificantDigits(digits: number): string;
12
+ /**
13
+ * Does not mutate the current BZZ instance.
14
+ *
15
+ * @param other BZZ instance, or amount in PLUR
16
+ * @returns New BZZ instance
17
+ */
18
+ plus(other: BZZ | NumberString | string | bigint): BZZ;
19
+ /**
20
+ * Does not mutate the current BZZ instance.
21
+ *
22
+ * @param other BZZ instance, or amount in PLUR
23
+ * @returns New BZZ instance
24
+ */
25
+ minus(other: BZZ | NumberString | string | bigint): BZZ;
26
+ /**
27
+ * Does not mutate the current BZZ instance.
28
+ *
29
+ * @param other Divisor
30
+ * @returns New BZZ instance
31
+ */
32
+ divide(other: bigint): BZZ;
33
+ gt(other: BZZ): boolean;
34
+ gte(other: BZZ): boolean;
35
+ lt(other: BZZ): boolean;
36
+ lte(other: BZZ): boolean;
37
+ eq(other: BZZ): boolean;
38
+ exchangeToDAI(daiPerBzz: DAI): DAI;
39
+ }
40
+ export declare class DAI {
41
+ static readonly DIGITS = 18;
42
+ private state;
43
+ private constructor();
44
+ static fromDecimalString(string: string): DAI;
45
+ static fromWei(wei: NumberString | string | bigint): DAI;
46
+ toWeiString(): string;
47
+ toWeiBigInt(): bigint;
48
+ toDecimalString(): string;
49
+ toSignificantDigits(digits: number): string;
50
+ /**
51
+ * Does not mutate the current DAI instance.
52
+ *
53
+ * @param other DAI instance, or amount in PLUR
54
+ * @returns New DAI instance
55
+ */
56
+ plus(other: DAI | NumberString | string | bigint): DAI;
57
+ /**
58
+ * Does not mutate the current DAI instance.
59
+ *
60
+ * @param other DAI instance, or amount in PLUR
61
+ * @returns New DAI instance
62
+ */
63
+ minus(other: DAI | NumberString | string | bigint): DAI;
64
+ /**
65
+ * Does not mutate the current DAI instance.
66
+ *
67
+ * @param other Divisor
68
+ * @returns New DAI instance
69
+ */
70
+ divide(other: bigint): DAI;
71
+ gt(other: DAI): boolean;
72
+ gte(other: DAI): boolean;
73
+ lt(other: DAI): boolean;
74
+ lte(other: DAI): boolean;
75
+ eq(other: DAI): boolean;
76
+ exchangeToBZZ(daiPerBzz: DAI): BZZ;
77
+ }
@@ -1,54 +1,23 @@
1
1
  /// <reference types="node" />
2
- import { Readable } from 'stream';
3
- import { Address, AddressPrefix, AllTagsOptions, BatchId, BeeRequestOptions, CashoutOptions, CollectionUploadOptions, FileUploadOptions, NumberString, PostageBatchOptions, PssMessageHandler, PublicKey, Reference, ReferenceOrEns, Tag, TransactionHash, TransactionOptions, UploadOptions } from '../types';
4
- export declare function isReadable(obj: unknown): obj is Readable;
5
- export declare function isInteger(value: unknown): value is number | NumberString;
6
- export declare function isObject(value: unknown): value is Record<string, unknown>;
7
- export declare function isStrictlyObject(value: unknown): value is Record<string, unknown>;
8
- /**
9
- * Asserts if object is Error
10
- *
11
- * @param e
12
- */
13
- export declare function isError(e: unknown): e is Error;
14
- export declare function assertStrictlyObject(value: unknown, name?: string): asserts value is object;
15
- export declare function assertBoolean(value: unknown, name?: string): asserts value is boolean;
16
- export declare function assertInteger(value: unknown, name?: string): asserts value is number | NumberString;
17
- export declare function assertNonNegativeInteger(value: unknown, name?: string): asserts value is number | NumberString;
18
- export declare function assertPositiveInteger(value: unknown, name?: string): asserts value is number | NumberString;
19
- export declare function assertReference(value: unknown): asserts value is Reference;
20
- export declare function assertReferenceOrEns(value: unknown): asserts value is ReferenceOrEns;
21
- /**
22
- * Function that mainly converts Swarm CID into hex encoded Swarm Reference
23
- *
24
- * @param value
25
- * @param expectedCidType
26
- */
27
- export declare function makeReferenceOrEns(value: unknown, expectedCidType: 'feed' | 'manifest'): ReferenceOrEns;
28
- /**
29
- * Function that adds getter which converts the reference into CID base32 encoded string.
30
- * @param result
31
- * @param cidType feed or manifest
32
- */
33
- export declare function addCidConversionFunction<T extends {
34
- reference: string;
35
- }>(result: T, cidType: 'feed' | 'manifest'): T & {
36
- cid: () => string;
37
- };
38
- export declare function assertAddress(value: unknown): asserts value is Address;
39
- export declare function assertBatchId(value: unknown): asserts value is BatchId;
40
- export declare function assertRequestOptions(value: unknown, name?: string): asserts value is BeeRequestOptions;
41
- export declare function assertUploadOptions(value: unknown, name?: string): asserts value is UploadOptions;
42
- export declare function assertFileUploadOptions(value: unknown): asserts value is FileUploadOptions;
43
- export declare function assertCollectionUploadOptions(value: unknown): asserts value is CollectionUploadOptions;
2
+ import * as stream from 'stream';
3
+ import { AllTagsOptions, BeeRequestOptions, CollectionUploadOptions, DownloadOptions, FileUploadOptions, GsocMessageHandler, NumberString, PostageBatchOptions, PssMessageHandler, RedundantUploadOptions, Tag, TransactionOptions, UploadOptions } from '../types';
4
+ export declare function isReadable(value: unknown): value is stream.Readable;
5
+ export declare function asNumberString(value: unknown, options?: {
6
+ name?: string;
7
+ min?: bigint;
8
+ max?: bigint;
9
+ }): NumberString;
10
+ export declare function prepareBeeRequestOptions(value: unknown): BeeRequestOptions;
11
+ export declare function prepareDownloadOptions(value: unknown): DownloadOptions;
12
+ export declare function prepareUploadOptions(value: unknown, name?: string): UploadOptions;
13
+ export declare function prepareRedundantUploadOptions(value: unknown, name?: string): RedundantUploadOptions;
14
+ export declare function prepareFileUploadOptions(value: unknown): FileUploadOptions;
15
+ export declare function prepareCollectionUploadOptions(value: unknown): CollectionUploadOptions;
44
16
  export declare function isTag(value: unknown): value is Tag;
45
- export declare function assertTag(value: unknown): asserts value is Tag;
46
- export declare function assertAddressPrefix(value: unknown): asserts value is AddressPrefix;
47
- export declare function assertPssMessageHandler(value: unknown): asserts value is PssMessageHandler;
48
- export declare function assertPublicKey(value: unknown): asserts value is PublicKey;
49
- export declare function assertPostageBatchOptions(value: unknown): asserts value is PostageBatchOptions;
50
- export declare function assertTransactionOptions(value: unknown, name?: string): asserts value is TransactionOptions;
51
- export declare function assertCashoutOptions(value: unknown): asserts value is CashoutOptions;
17
+ export declare function preparePssMessageHandler(value: unknown): PssMessageHandler;
18
+ export declare function prepareGsocMessageHandler(value: unknown): GsocMessageHandler;
19
+ export declare function preparePostageBatchOptions(value: unknown): PostageBatchOptions;
20
+ export declare function prepareTransactionOptions(value: unknown, name?: string): TransactionOptions;
52
21
  /**
53
22
  * Check whether the given parameter is valid data to upload
54
23
  * @param value
@@ -60,15 +29,14 @@ export declare function assertData(value: unknown): asserts value is string | Ui
60
29
  * @param value
61
30
  * @throws TypeError if not valid
62
31
  */
63
- export declare function assertFileData(value: unknown): asserts value is string | Uint8Array | Readable | File;
32
+ export declare function assertFileData(value: unknown): asserts value is string | Uint8Array | stream.Readable | File;
64
33
  /**
65
34
  * Checks whether optional options for AllTags query are valid
66
35
  * @param options
67
36
  */
68
- export declare function assertAllTagsOptions(entry: unknown): asserts entry is AllTagsOptions;
37
+ export declare function prepareAllTagsOptions(value: unknown): AllTagsOptions;
69
38
  /**
70
39
  * Utility functions that return Tag UID
71
40
  * @param tagUid
72
41
  */
73
42
  export declare function makeTagUid(tagUid: number | Tag | string | null | undefined): number;
74
- export declare function assertTransactionHash(transactionHash: unknown): asserts transactionHash is TransactionHash;
@@ -0,0 +1,68 @@
1
+ import { Bytes } from './bytes';
2
+ export declare class PrivateKey extends Bytes {
3
+ static readonly LENGTH = 32;
4
+ constructor(bytes: Uint8Array | string | Bytes);
5
+ publicKey(): PublicKey;
6
+ sign(data: Uint8Array | string): Signature;
7
+ }
8
+ export declare class PublicKey extends Bytes {
9
+ static readonly LENGTH = 64;
10
+ constructor(bytes: Uint8Array | string | Bytes);
11
+ address(): EthAddress;
12
+ toCompressedUint8Array(): Uint8Array;
13
+ toCompressedHex(): string;
14
+ }
15
+ export declare class EthAddress extends Bytes {
16
+ static readonly LENGTH = 20;
17
+ constructor(bytes: Uint8Array | string | Bytes);
18
+ toChecksum(): string;
19
+ }
20
+ export declare class Identifier extends Bytes {
21
+ static readonly LENGTH = 32;
22
+ constructor(bytes: Uint8Array | string | Bytes);
23
+ static fromString(value: string): Identifier;
24
+ }
25
+ export declare class Reference extends Bytes {
26
+ static readonly LENGTH = 32;
27
+ constructor(bytes: Uint8Array | string | Bytes);
28
+ toCid(type: 'feed' | 'manifest'): string;
29
+ static isValid(value: string): boolean;
30
+ }
31
+ export declare class TransactionId extends Bytes {
32
+ static readonly LENGTH = 32;
33
+ constructor(bytes: Uint8Array | string | Bytes);
34
+ }
35
+ export declare class Span extends Bytes {
36
+ static readonly LENGTH = 8;
37
+ constructor(bytes: Uint8Array | string | Bytes);
38
+ static fromBigInt(number: bigint): FeedIndex;
39
+ toBigInt(): bigint;
40
+ static fromSlice(bytes: Uint8Array, start: number): Span;
41
+ }
42
+ export declare class PeerAddress extends Bytes {
43
+ static readonly LENGTH = 32;
44
+ constructor(bytes: Uint8Array | string | Bytes);
45
+ }
46
+ export declare class BatchId extends Bytes {
47
+ static readonly LENGTH = 32;
48
+ constructor(bytes: Uint8Array | string | Bytes);
49
+ }
50
+ export declare class Signature extends Bytes {
51
+ static readonly LENGTH = 65;
52
+ constructor(bytes: Uint8Array | string | Bytes);
53
+ static fromSlice(bytes: Uint8Array, start: number): Signature;
54
+ recoverPublicKey(digest: Uint8Array | string): PublicKey;
55
+ isValid(digest: Uint8Array | string, expectedAddress: EthAddress | Uint8Array | string): boolean;
56
+ }
57
+ export declare class Topic extends Bytes {
58
+ static readonly LENGTH = 32;
59
+ constructor(bytes: Uint8Array | string | Bytes);
60
+ static fromString(value: string): Topic;
61
+ }
62
+ export declare class FeedIndex extends Bytes {
63
+ static readonly LENGTH = 8;
64
+ static readonly MINUS_ONE: FeedIndex;
65
+ constructor(bytes: Uint8Array | string | Bytes);
66
+ static fromBigInt(number: bigint): FeedIndex;
67
+ toBigInt(): bigint;
68
+ }
@@ -0,0 +1,4 @@
1
+ export interface UploadProgress {
2
+ total: number;
3
+ processed: number;
4
+ }
@@ -0,0 +1,2 @@
1
+ export declare function normalizeBatchTTL(batchTTL: number): number;
2
+ export declare function normalizeCurrentPrice(currentPrice: number): number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ethersphere/bee-js",
3
- "version": "8.3.1",
3
+ "version": "9.0.2",
4
4
  "description": "Javascript client for Bee",
5
5
  "keywords": [
6
6
  "bee",
@@ -31,16 +31,20 @@
31
31
  "types": "./dist/types/index.d.ts"
32
32
  }
33
33
  },
34
+ "engines": {
35
+ "bee": "2.4.0-390a402e",
36
+ "beeApiVersion": "7.2.0"
37
+ },
34
38
  "types": "dist/types/index.d.ts",
35
39
  "browser": {
36
40
  "stream": false,
37
41
  "fs": false,
38
- "./src/utils/data.ts": "./src/utils/data.browser.ts",
39
42
  "./dist/cjs/utils/data.js": "./dist/cjs/utils/data.browser.js",
40
43
  "./dist/mjs/utils/data.js": "./dist/mjs/utils/data.browser.js",
44
+ "./dist/cjs/utils/chunk-stream.js": "./dist/cjs/utils/chunk-stream.browser.js",
45
+ "./dist/mjs/utils/chunk-stream.js": "./dist/mjs/utils/chunk-stream.browser.js",
41
46
  "./dist/cjs/utils/collection.node.js": "./dist/cjs/utils/collection.browser.js",
42
- "./dist/mjs/utils/collection.node.js": "./dist/mjs/utils/collection.browser.js",
43
- "./src/utils/collection.node.ts": "./src/utils/collection.browser.ts"
47
+ "./dist/mjs/utils/collection.node.js": "./dist/mjs/utils/collection.browser.js"
44
48
  },
45
49
  "files": [
46
50
  "dist"
@@ -51,21 +55,16 @@
51
55
  "build:node": "tsc -p tsconfig.json && tsc -p tsconfig-mjs.json && ./build-fixup && babel --plugins \"babel-plugin-add-import-extension\" --out-dir dist/mjs/ dist/mjs/",
52
56
  "build:types": "tsc --emitDeclarationOnly --declaration --outDir dist/types",
53
57
  "build:browser": "webpack --progress",
54
- "mock-ci": "npm run lint:check && npm run check:types && npm run test",
55
58
  "test": "jest --config=jest.config.ts --runInBand --verbose",
56
- "test:coverage": "jest --config=jest.config.ts --coverage",
57
59
  "check:types": "tsc --project tsconfig.test.json",
58
60
  "lint": "eslint --fix \"src/**/*.ts\" \"test/**/*.ts\" && prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
59
61
  "lint:check": "eslint \"src/**/*.ts\" \"test/**/*.ts\" && prettier --check \"src/**/*.ts\" \"test/**/*.ts\"",
60
- "depcheck": "depcheck .",
61
- "bee": "npx @fairdatasociety/fdp-play@3.2.0 start --detach --fresh"
62
+ "depcheck": "depcheck ."
62
63
  },
63
64
  "dependencies": {
64
65
  "axios": "^0.28.1",
65
- "cafe-utility": "^23.10.0",
66
- "elliptic": "^6.5.4",
66
+ "cafe-utility": "^27.14.2",
67
67
  "isomorphic-ws": "^4.0.1",
68
- "js-sha3": "^0.8.0",
69
68
  "semver": "^7.3.5",
70
69
  "ws": "^8.7.0"
71
70
  },
@@ -80,7 +79,6 @@
80
79
  "@commitlint/config-conventional": "^17.4.2",
81
80
  "@jest/types": "^29.6.3",
82
81
  "@naholyr/cross-env": "^1.0.0",
83
- "@types/elliptic": "^6.4.14",
84
82
  "@types/jest": "^29.5.13",
85
83
  "@types/node": "^18.11.11",
86
84
  "@types/semver": "^7.3.9",
@@ -97,7 +95,7 @@
97
95
  "eslint-plugin-unused-imports": "^2.0.0",
98
96
  "husky": "^8.0.1",
99
97
  "jest": "^29.7.0",
100
- "nock": "^13.3.0",
98
+ "jest-puppeteer": "^11.0.0",
101
99
  "prettier": "^2.6.2",
102
100
  "rimraf": "^3.0.2",
103
101
  "terser-webpack-plugin": "^5.3.1",
@@ -106,9 +104,5 @@
106
104
  "typescript": "^4.9.5",
107
105
  "webpack": "^5.75.0",
108
106
  "webpack-cli": "^5.0.1"
109
- },
110
- "engines": {
111
- "bee": "2.2.0-06a0aca7",
112
- "beeApiVersion": "7.1.0"
113
107
  }
114
108
  }