@upcoming/bee-js 9.9.1 → 11.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/README.md +2 -2
  2. package/dist/cjs/bee.js +881 -370
  3. package/dist/cjs/chunk/bmt.js +1 -2
  4. package/dist/cjs/chunk/cac.js +27 -32
  5. package/dist/cjs/chunk/soc.js +39 -31
  6. package/dist/cjs/feed/identifier.js +1 -2
  7. package/dist/cjs/feed/index.js +29 -19
  8. package/dist/cjs/feed/retrievable.js +1 -2
  9. package/dist/cjs/index.js +17 -7
  10. package/dist/cjs/manifest/manifest.js +19 -2
  11. package/dist/cjs/modules/bytes.js +4 -5
  12. package/dist/cjs/modules/bzz.js +4 -5
  13. package/dist/cjs/modules/chunk.js +2 -3
  14. package/dist/cjs/modules/debug/balance.js +4 -5
  15. package/dist/cjs/modules/debug/chequebook.js +9 -10
  16. package/dist/cjs/modules/debug/connectivity.js +7 -8
  17. package/dist/cjs/modules/debug/settlements.js +2 -3
  18. package/dist/cjs/modules/debug/stake.js +6 -7
  19. package/dist/cjs/modules/debug/stamps.js +24 -60
  20. package/dist/cjs/modules/debug/states.js +6 -6
  21. package/dist/cjs/modules/debug/status.js +9 -9
  22. package/dist/cjs/modules/debug/transactions.js +4 -5
  23. package/dist/cjs/modules/envelope.js +1 -2
  24. package/dist/cjs/modules/feed.js +3 -4
  25. package/dist/cjs/modules/grantee.js +3 -4
  26. package/dist/cjs/modules/gsoc.js +2 -3
  27. package/dist/cjs/modules/pinning.js +4 -5
  28. package/dist/cjs/modules/pss.js +2 -3
  29. package/dist/cjs/modules/rchash.js +1 -2
  30. package/dist/cjs/modules/soc.js +1 -2
  31. package/dist/cjs/modules/status.js +2 -3
  32. package/dist/cjs/modules/stewardship.js +2 -3
  33. package/dist/cjs/modules/tag.js +5 -6
  34. package/dist/cjs/types/debug.js +3 -3
  35. package/dist/cjs/types/index.js +11 -6
  36. package/dist/cjs/utils/bytes.js +23 -3
  37. package/dist/cjs/utils/chunk-size.js +1 -2
  38. package/dist/cjs/utils/chunk-stream.browser.js +30 -6
  39. package/dist/cjs/utils/chunk-stream.js +3 -4
  40. package/dist/cjs/utils/cid.js +3 -3
  41. package/dist/cjs/utils/collection.browser.js +2 -3
  42. package/dist/cjs/utils/collection.js +5 -6
  43. package/dist/cjs/utils/collection.node.js +2 -3
  44. package/dist/cjs/utils/data.browser.js +1 -2
  45. package/dist/cjs/utils/data.js +1 -2
  46. package/dist/cjs/utils/duration.js +27 -1
  47. package/dist/cjs/utils/expose.js +4 -1
  48. package/dist/cjs/utils/file.js +2 -3
  49. package/dist/cjs/utils/headers.js +2 -3
  50. package/dist/cjs/utils/http.js +25 -5
  51. package/dist/cjs/utils/pss.js +1 -2
  52. package/dist/cjs/utils/redundancy.js +3 -4
  53. package/dist/cjs/utils/size.js +25 -0
  54. package/dist/cjs/utils/stamps.js +60 -11
  55. package/dist/cjs/utils/tar-uploader.browser.js +1 -2
  56. package/dist/cjs/utils/tar-uploader.js +1 -2
  57. package/dist/cjs/utils/tar-writer.browser.js +1 -2
  58. package/dist/cjs/utils/tar-writer.js +1 -2
  59. package/dist/cjs/utils/type.js +37 -25
  60. package/dist/cjs/utils/url.js +3 -4
  61. package/dist/cjs/utils/workaround.js +7 -5
  62. package/dist/index.browser.min.js +1 -1
  63. package/dist/index.browser.min.js.map +1 -1
  64. package/dist/mjs/bee.js +864 -366
  65. package/dist/mjs/chunk/cac.js +21 -30
  66. package/dist/mjs/chunk/soc.js +16 -17
  67. package/dist/mjs/feed/index.js +7 -6
  68. package/dist/mjs/manifest/manifest.js +19 -2
  69. package/dist/mjs/modules/debug/chequebook.js +2 -2
  70. package/dist/mjs/modules/debug/stamps.js +38 -93
  71. package/dist/mjs/modules/debug/states.js +3 -0
  72. package/dist/mjs/modules/debug/status.js +1 -1
  73. package/dist/mjs/types/index.js +8 -3
  74. package/dist/mjs/utils/bytes.js +19 -2
  75. package/dist/mjs/utils/chunk-stream.browser.js +29 -5
  76. package/dist/mjs/utils/duration.js +27 -1
  77. package/dist/mjs/utils/expose.js +1 -1
  78. package/dist/mjs/utils/http.js +25 -3
  79. package/dist/mjs/utils/size.js +25 -0
  80. package/dist/mjs/utils/stamps.js +48 -0
  81. package/dist/mjs/utils/type.js +8 -1
  82. package/dist/mjs/utils/workaround.js +5 -2
  83. package/dist/types/bee.d.ts +756 -252
  84. package/dist/types/chunk/cac.d.ts +27 -13
  85. package/dist/types/chunk/soc.d.ts +43 -11
  86. package/dist/types/index.d.ts +3 -0
  87. package/dist/types/modules/bzz.d.ts +0 -1
  88. package/dist/types/modules/debug/stamps.d.ts +2 -2
  89. package/dist/types/modules/debug/status.d.ts +1 -1
  90. package/dist/types/modules/gsoc.d.ts +0 -1
  91. package/dist/types/modules/pss.d.ts +0 -1
  92. package/dist/types/types/debug.d.ts +2 -1
  93. package/dist/types/types/index.d.ts +53 -6
  94. package/dist/types/utils/constants.d.ts +3 -3
  95. package/dist/types/utils/duration.d.ts +24 -0
  96. package/dist/types/utils/error.d.ts +2 -2
  97. package/dist/types/utils/expose.d.ts +1 -1
  98. package/dist/types/utils/size.d.ts +23 -0
  99. package/dist/types/utils/stamps.d.ts +15 -1
  100. package/dist/types/utils/tar.browser.d.ts +1 -1
  101. package/dist/types/utils/tar.d.ts +0 -1
  102. package/dist/types/utils/type.d.ts +0 -1
  103. package/package.json +10 -13
@@ -1,26 +1,40 @@
1
1
  import { Bytes } from '../utils/bytes';
2
- import { Reference, Span } from '../utils/typed-bytes';
2
+ import { Identifier, PrivateKey, Reference, Span } from '../utils/typed-bytes';
3
+ import { SingleOwnerChunk } from './soc';
3
4
  export declare const MIN_PAYLOAD_SIZE = 1;
4
5
  export declare const MAX_PAYLOAD_SIZE = 4096;
5
6
  /**
6
- * General chunk interface for Swarm
7
+ * Content Addressed Chunk (CAC) is the immutable building block of Swarm,
8
+ * holding at most 4096 bytes of payload.
7
9
  *
8
- * It stores the serialized data and provides functions to access
9
- * the fields of a chunk.
10
+ * - `span` indicates the size of the `payload` in bytes.
11
+ * - `payload` contains the actual data or the body of the chunk.
12
+ * - `data` contains the full chunk data - `span` and `payload`.
13
+ * - `address` is the Swarm hash (or reference) of the chunk.
10
14
  *
11
- * It also provides an address function to calculate the address of
12
- * the chunk that is required for the Chunk API.
15
+ * The `toSingleOwnerChunk` method allows converting the CAC into a Single Owner Chunk (SOC).
13
16
  */
14
17
  export interface Chunk {
18
+ /**
19
+ * Contains the full chunk data - `span` + `payload`.
20
+ */
15
21
  readonly data: Uint8Array;
22
+ /**
23
+ * Indicates the size of the `payload` in bytes.
24
+ */
16
25
  span: Span;
26
+ /**
27
+ * Contains the actual data or the body of the chunk.
28
+ */
17
29
  payload: Bytes;
30
+ /**
31
+ * The Swarm hash (or reference) of the chunk.
32
+ */
18
33
  address: Reference;
34
+ /**
35
+ * Converts the CAC into a Single Owner Chunk (SOC).
36
+ */
37
+ toSingleOwnerChunk: (identifier: Identifier | Uint8Array | string, signer: PrivateKey | Uint8Array | string) => SingleOwnerChunk;
19
38
  }
20
- /**
21
- * Creates a content addressed chunk and verifies the payload size.
22
- *
23
- * @param payloadBytes the data to be stored in the chunk
24
- */
25
- export declare function makeContentAddressedChunk(payloadBytes: Uint8Array | string): Chunk;
26
- export declare function asContentAddressedChunk(chunkBytes: Uint8Array): Chunk;
39
+ export declare function unmarshalContentAddressedChunk(data: Bytes | Uint8Array): Chunk;
40
+ export declare function makeContentAddressedChunk(rawPayload: Bytes | Uint8Array | string, span?: Span | bigint): Chunk;
@@ -1,29 +1,61 @@
1
1
  import { BeeRequestOptions, UploadOptions, UploadResult } from '../types';
2
2
  import { Bytes } from '../utils/bytes';
3
- import { BatchId, EthAddress, Identifier, PrivateKey, Reference, Signature } from '../utils/typed-bytes';
3
+ import { BatchId, EthAddress, Identifier, PrivateKey, Reference, Signature, Span } from '../utils/typed-bytes';
4
4
  import { Chunk } from './cac';
5
5
  /**
6
- * With single owner chunks, a user can assign arbitrary data to an
7
- * address and attest chunk integrity with their digital signature.
6
+ * Single Owner Chunk (SOC) is a chunk type where the address is determined by the owner and an arbitrary identifier.
7
+ * Its integrity is attested by the owner's digital signature.
8
8
  *
9
- * This interface extends the Chunk interface so it has the same
10
- * properties, but the address calculation is based on the identifier
11
- * and the owner of the chunk.
9
+ * Similar to Content Addressed Chunks (CAC), SOCs have a maximum payload size of 4096 bytes.
10
+ *
11
+ * - `span` indicates the size of the `payload` in bytes.
12
+ * - `payload` contains the actual data or the body of the chunk.
13
+ * - `data` contains the full chunk data - `span` and `payload`.
14
+ * - `address` is the Swarm hash (or reference) of the chunk.
15
+ * - `identifier` is an arbitrary identifier selected by the uploader.
16
+ * - `signature` is the digital signature of the owner over the identifier and the underlying CAC address.
17
+ * - `owner` is the Ethereum address of the chunk owner.
12
18
  */
13
- export interface SingleOwnerChunk extends Chunk {
19
+ export interface SingleOwnerChunk {
20
+ /**
21
+ * Contains the full chunk data - `span` + `payload`.
22
+ */
23
+ readonly data: Uint8Array;
24
+ /**
25
+ * Indicates the size of the `payload` in bytes.
26
+ */
27
+ span: Span;
28
+ /**
29
+ * Contains the actual data or the body of the chunk.
30
+ */
31
+ payload: Bytes;
32
+ /**
33
+ * The Swarm hash (or reference) of the chunk.
34
+ */
35
+ address: Reference;
36
+ /**
37
+ * An arbitrary identifier selected by the uploader.
38
+ */
14
39
  identifier: Identifier;
40
+ /**
41
+ * The digital signature of the owner over the identifier and the underlying CAC address.
42
+ */
15
43
  signature: Signature;
44
+ /**
45
+ * The Ethereum address of the chunk owner.
46
+ */
16
47
  owner: EthAddress;
17
48
  }
18
49
  /**
19
- * Verifies if the data is a valid single owner chunk
50
+ * Unmarshals arbitrary data into a Single Owner Chunk.
51
+ * Throws an error if the data is not a valid SOC.
20
52
  *
21
53
  * @param data The chunk data
22
54
  * @param address The address of the single owner chunk
23
55
  *
24
56
  * @returns a single owner chunk or throws error
25
57
  */
26
- export declare function makeSingleOwnerChunkFromData(data: Bytes | Uint8Array, address: Reference | Uint8Array | string): SingleOwnerChunk;
58
+ export declare function unmarshalSingleOwnerChunk(data: Bytes | Uint8Array, address: Reference | Uint8Array | string): SingleOwnerChunk;
27
59
  export declare function makeSOCAddress(identifier: Identifier, address: EthAddress): Reference;
28
60
  /**
29
61
  * Creates a single owner chunk object
@@ -32,7 +64,7 @@ export declare function makeSOCAddress(identifier: Identifier, address: EthAddre
32
64
  * @param identifier The identifier of the chunk
33
65
  * @param signer The signer interface for signing the chunk
34
66
  */
35
- export declare function makeSingleOwnerChunk(chunk: Chunk, identifier: Identifier | Uint8Array | string, signer: PrivateKey | Uint8Array | string): SingleOwnerChunk;
67
+ export declare function makeSingleOwnerChunk(address: Reference, span: Span, payload: Bytes, identifier: Identifier | Uint8Array | string, signer: PrivateKey | Uint8Array | string): SingleOwnerChunk;
36
68
  /**
37
69
  * Helper function to upload a chunk.
38
70
  *
@@ -55,7 +87,7 @@ export declare function uploadSingleOwnerChunk(requestOptions: BeeRequestOptions
55
87
  * @param options
56
88
  */
57
89
  export declare function uploadSingleOwnerChunkData(requestOptions: BeeRequestOptions, signer: PrivateKey | Uint8Array | string, stamp: BatchId | Uint8Array | string, identifier: Identifier | Uint8Array | string, data: Uint8Array, options?: UploadOptions): Promise<UploadResult>;
58
- export declare function uploadSingleOwnerChunkWithWrappedChunk(requestOptions: BeeRequestOptions, signer: PrivateKey | Uint8Array | string, stamp: BatchId | Uint8Array | string, identifier: Identifier | Uint8Array | string, rootChunk: Uint8Array, options?: UploadOptions): Promise<UploadResult>;
90
+ export declare function uploadSingleOwnerChunkWithWrappedChunk(requestOptions: BeeRequestOptions, signer: PrivateKey | Uint8Array | string, stamp: BatchId | Uint8Array | string, identifier: Identifier | Uint8Array | string, wrappedChunk: Chunk, options?: UploadOptions): Promise<UploadResult>;
59
91
  /**
60
92
  * Helper function to download SOC.
61
93
  *
@@ -2,6 +2,8 @@ import { Bee } from './bee';
2
2
  import { BeeDev } from './bee-dev';
3
3
  import { Stamper } from './stamper/stamper';
4
4
  export { MerkleTree } from 'cafe-utility';
5
+ export type { Chunk } from './chunk/cac';
6
+ export type { SingleOwnerChunk } from './chunk/soc';
5
7
  export { MantarayNode } from './manifest/manifest';
6
8
  export { SUPPORTED_BEE_VERSION, SUPPORTED_BEE_VERSION_EXACT } from './modules/debug/status';
7
9
  export * from './types';
@@ -13,6 +15,7 @@ export * as Utils from './utils/expose';
13
15
  export { Size } from './utils/size';
14
16
  export * from './utils/tokens';
15
17
  export * from './utils/typed-bytes';
18
+ export type { UploadProgress } from './utils/upload-progress';
16
19
  export { Bee, BeeDev, Stamper };
17
20
  declare global {
18
21
  interface Window {
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { Readable } from 'stream';
3
2
  import { BeeRequestOptions, Collection, CollectionUploadOptions, DownloadOptions, FileData, FileUploadOptions, UploadResult } from '../types';
4
3
  import { Bytes } from '../utils/bytes';
@@ -1,8 +1,8 @@
1
- import type { BeeRequestOptions, GlobalPostageBatch, NumberString, PostageBatch, PostageBatchBuckets, PostageBatchOptions } from '../../types';
1
+ import type { BeeRequestOptions, GlobalPostageBatch, NumberString, PostageBatch, PostageBatchBuckets, PostageBatchOptions, RedundancyLevel } from '../../types';
2
2
  import { BatchId } from '../../utils/typed-bytes';
3
3
  export declare function getGlobalPostageBatches(requestOptions: BeeRequestOptions): Promise<GlobalPostageBatch[]>;
4
4
  export declare function getAllPostageBatches(requestOptions: BeeRequestOptions): Promise<PostageBatch[]>;
5
- export declare function getPostageBatch(requestOptions: BeeRequestOptions, postageBatchId: BatchId): Promise<PostageBatch>;
5
+ export declare function getPostageBatch(requestOptions: BeeRequestOptions, postageBatchId: BatchId, encryption?: boolean, erasureCodeLevel?: RedundancyLevel): Promise<PostageBatch>;
6
6
  export declare function getPostageBatchBuckets(requestOptions: BeeRequestOptions, postageBatchId: BatchId): Promise<PostageBatchBuckets>;
7
7
  export declare function createPostageBatch(requestOptions: BeeRequestOptions, amount: NumberString, depth: number, options?: PostageBatchOptions): Promise<BatchId>;
8
8
  export declare function topUpBatch(requestOptions: BeeRequestOptions, id: BatchId, amount: NumberString): Promise<BatchId>;
@@ -1,7 +1,7 @@
1
1
  import { BeeRequestOptions } from '../../index';
2
2
  import type { DebugStatus, Health, NodeInfo, Readiness } from '../../types/debug';
3
3
  import { BeeVersions } from '../../types/debug';
4
- export declare const SUPPORTED_BEE_VERSION_EXACT = "2.6.0-d0aa8b93";
4
+ export declare const SUPPORTED_BEE_VERSION_EXACT = "2.7.0-6ddf9b45";
5
5
  export declare const SUPPORTED_BEE_VERSION: string;
6
6
  export declare const SUPPORTED_API_VERSION = "7.3.0";
7
7
  export declare function getDebugStatus(requestOptions: BeeRequestOptions): Promise<DebugStatus>;
@@ -1,4 +1,3 @@
1
- /// <reference types="ws" />
2
1
  import WebSocket from 'isomorphic-ws';
3
2
  import { BeeRequestOptions, UploadOptions } from '..';
4
3
  import { SingleOwnerChunk } from '../chunk/soc';
@@ -1,4 +1,3 @@
1
- /// <reference types="ws" />
2
1
  import WebSocket from 'isomorphic-ws';
3
2
  import type { BeeRequestOptions } from '../types';
4
3
  import { BatchId, PublicKey, Topic } from '../utils/typed-bytes';
@@ -23,7 +23,7 @@ export interface Peer {
23
23
  fullNode?: boolean;
24
24
  }
25
25
  export interface ChequebookAddressResponse {
26
- chequebookAddress: string;
26
+ chequebookAddress: EthAddress;
27
27
  }
28
28
  export interface ChequebookBalanceResponse {
29
29
  totalBalance: BZZ;
@@ -212,6 +212,7 @@ export interface ReserveState {
212
212
  radius: number;
213
213
  storageRadius: number;
214
214
  commitment: number;
215
+ reserveCapacityDoubling: number;
215
216
  }
216
217
  export interface ChainState {
217
218
  chainTip: number;
@@ -13,16 +13,24 @@ export declare const BRANCHES = 128;
13
13
  export declare const CHUNK_SIZE: number;
14
14
  export declare const PSS_TARGET_HEX_LENGTH_MAX = 4;
15
15
  /**
16
- * Minimal depth that can be used for creation of postage batch
16
+ * Minimum postage batch depth.
17
17
  */
18
18
  export declare const STAMPS_DEPTH_MIN = 17;
19
19
  /**
20
- * Maximal depth that can be used for creation of postage batch
20
+ * Maximum postage batch depth.
21
21
  */
22
22
  export declare const STAMPS_DEPTH_MAX = 255;
23
+ /**
24
+ * Minimum tags API page size.
25
+ */
23
26
  export declare const TAGS_LIMIT_MIN = 1;
27
+ /**
28
+ * Maximum tags API page size.
29
+ */
24
30
  export declare const TAGS_LIMIT_MAX = 1000;
25
- export declare const FEED_INDEX_HEX_LENGTH = 16;
31
+ /**
32
+ * Behavior of the HTTP client, such as `timeout`, additional `headers`, custom `httpAgent`, etc.
33
+ */
26
34
  export type BeeRequestOptions = {
27
35
  baseURL?: string;
28
36
  timeout?: number;
@@ -31,14 +39,31 @@ export type BeeRequestOptions = {
31
39
  httpAgent?: unknown;
32
40
  httpsAgent?: unknown;
33
41
  endlesslyRetry?: boolean;
42
+ signal?: AbortSignal;
34
43
  };
44
+ /**
45
+ * Options for the Bee client which affect all method calls *(unless overridden in the method call itself)*.
46
+ *
47
+ * Extends `BeeRequestOptions`, which allows configuring the HTTP client behavior,
48
+ * such as `timeout`, additional `headers`, custom `httpAgent`, etc.
49
+ */
35
50
  export interface BeeOptions extends BeeRequestOptions {
36
51
  /**
37
- * Signer object or private key of the Signer in form of either hex string or Uint8Array that will be default signer for the instance.
52
+ * Default signer (a private key) used for signing.
53
+ *
54
+ * Mainly used in single-owner chunk (SOC) related operations, and consequently in feeds.
55
+ *
56
+ * If not provided, methods such as `makeFeedWriter` and `makeSOCWriter`
57
+ * must be provided with a private key in their respective function calls.
38
58
  */
39
59
  signer?: PrivateKey | Uint8Array | string;
40
60
  /**
41
- * Default gnosis when unspecified.
61
+ * Network on which the Bee node is running.
62
+ *
63
+ * This is currently used to determine block time for postage batch time-to-live (TTL) calculations.
64
+ * The block time for `gnosis` is `5` seconds, and for `sepolia` it is `15` seconds.
65
+ *
66
+ * Default value is `gnosis`.
42
67
  */
43
68
  network?: 'gnosis' | 'sepolia';
44
69
  }
@@ -146,14 +171,20 @@ export declare enum RedundancyStrategy {
146
171
  export interface DownloadOptions {
147
172
  /**
148
173
  * Specify the retrieve strategy on redundant data.
174
+ *
175
+ * Only applicable for erasure coded data.
149
176
  */
150
177
  redundancyStrategy?: RedundancyStrategy;
151
178
  /**
152
179
  * Specify if the retrieve strategies (chunk prefetching on redundant data) are used in a fallback cascade. The default is true.
180
+ *
181
+ * Only applicable for erasure coded data.
153
182
  */
154
183
  fallback?: boolean;
155
184
  /**
156
185
  * Specify the timeout for chunk retrieval. The default is 30 seconds.
186
+ *
187
+ * This is not the timeout for the whole download operation, but rather for each chunk retrieval.
157
188
  */
158
189
  timeoutMs?: number;
159
190
  actPublisher?: PublicKey | Uint8Array | string;
@@ -200,7 +231,11 @@ export interface UploadHeaders {
200
231
  'swarm-postage-batch-id'?: string;
201
232
  }
202
233
  /**
203
- * Object that contains infromation about progress of upload of data to network.
234
+ * Object that contains information about upload progress of data to network.
235
+ *
236
+ * The total amount of chunks is represented by `split` property.
237
+ *
238
+ * The actual progress of the upload can be tracked by the `seen + synced` properties.
204
239
  *
205
240
  * @see [Bee docs - Syncing / Tags](https://docs.ethswarm.org/docs/develop/access-the-swarm/syncing)
206
241
  */
@@ -273,6 +308,7 @@ export interface PssSubscription {
273
308
  export interface PssMessageHandler {
274
309
  onMessage: (message: Bytes, subscription: PssSubscription) => void;
275
310
  onError: (error: BeeError, subscription: PssSubscription) => void;
311
+ onClose: (subscription: PssSubscription) => void;
276
312
  }
277
313
  export interface GsocSubscription {
278
314
  readonly address: EthAddress;
@@ -281,6 +317,7 @@ export interface GsocSubscription {
281
317
  export interface GsocMessageHandler {
282
318
  onMessage: (message: Bytes, subscription: GsocSubscription) => void;
283
319
  onError: (error: BeeError, subscription: GsocSubscription) => void;
320
+ onClose: (subscription: GsocSubscription) => void;
284
321
  }
285
322
  export interface ReferenceResponse {
286
323
  reference: Reference;
@@ -414,6 +451,16 @@ export interface PostageBatch {
414
451
  * Theoretical size in bytes
415
452
  */
416
453
  theoreticalSize: Size;
454
+ /**
455
+ * Calculates the effective size of data that can be uploaded with this postage batch
456
+ * based on whether encryption is used and the desired redundancy level.
457
+ */
458
+ calculateSize(encryption: boolean, redundancyLevel: RedundancyLevel): Size;
459
+ /**
460
+ * Calculates the remaining size of data that can be uploaded with this postage batch
461
+ * based on whether encryption is used and the desired redundancy level.
462
+ */
463
+ calculateRemainingSize(encryption: boolean, redundancyLevel: RedundancyLevel): Size;
417
464
  }
418
465
  export interface BatchBucket {
419
466
  bucketID: number;
@@ -2,6 +2,6 @@ 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;
5
+ export declare const NULL_ADDRESS: Uint8Array<ArrayBuffer>;
6
+ export declare const NULL_IDENTIFIER: Uint8Array<ArrayBuffer>;
7
+ export declare const NULL_OWNER: Uint8Array<ArrayBuffer>;
@@ -9,6 +9,30 @@ export declare class Duration {
9
9
  static fromWeeks(weeks: number): Duration;
10
10
  static fromYears(years: number): Duration;
11
11
  static fromEndDate(endDate: Date, startDate?: Date): Duration;
12
+ /**
13
+ * Parses a duration string and returns a `Duration` instance.
14
+ *
15
+ * Case insensitive. E.g. both `"28h"` and `"1D"` are valid.
16
+ *
17
+ * Whitespaces are ignored. E.g. both `"5 d"` and `"2weeks"` are valid.
18
+ *
19
+ * Decimal numbers are supported. E.g. `"1.5h"` is valid.
20
+ *
21
+ * Supported units:
22
+ *
23
+ * - ms, milli, millis, millisecond, milliseconds
24
+ * - s, sec, second, seconds
25
+ * - m, min, minute, minutes
26
+ * - h, hour, hours
27
+ * - d, day, days
28
+ * - w, week, weeks
29
+ * - month, months
30
+ * - y, year, years
31
+ *
32
+ * @param duration - A string representing a duration
33
+ * @returns a `Duration` instance
34
+ */
35
+ static parseFromString(duration: string): Duration;
12
36
  toSeconds(): number;
13
37
  toHours(): number;
14
38
  toDays(): number;
@@ -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?: unknown;
11
+ responseBody?: unknown | undefined;
12
12
  status?: number | undefined;
13
13
  statusText?: string | undefined;
14
- constructor(method: string, url: string, message: string, responseBody?: unknown, status?: number | undefined, statusText?: string | undefined);
14
+ constructor(method: string, url: string, message: string, responseBody?: unknown | undefined, status?: number | undefined, statusText?: string | undefined);
15
15
  }
@@ -2,4 +2,4 @@ export { getCollectionSize, makeCollectionFromFileList } from './collection';
2
2
  export { getFolderSize } from './collection.node';
3
3
  export { makeMaxTarget } from './pss';
4
4
  export { approximateOverheadForRedundancyLevel, getRedundancyStat, getRedundancyStats } from './redundancy';
5
- export { getAmountForDuration, getDepthForSize, getStampCost, getStampDuration, getStampEffectiveBytes, getStampEffectiveBytesBreakpoints, getStampTheoreticalBytes, getStampUsage, } from './stamps';
5
+ export { convertEnvelopeToMarshaledStamp, getAmountForDuration, getDepthForSize, getStampCost, getStampDuration, getStampEffectiveBytes, getStampEffectiveBytesBreakpoints, getStampTheoreticalBytes, getStampUsage, mapPostageBatch, unmapPostageBatch, } from './stamps';
@@ -12,6 +12,29 @@ export declare class Size {
12
12
  static fromKilobytes(kilobytes: number): Size;
13
13
  static fromMegabytes(megabytes: number): Size;
14
14
  static fromGigabytes(gigabytes: number): Size;
15
+ /**
16
+ * Parses a size string and returns a `Size` instance.
17
+ *
18
+ * Case insensitive. E.g. both `"28MB"` and `"1gb"` are valid.
19
+ *
20
+ * Whitespaces are ignored. E.g. both `"512 kb"` and `"2megabytes"` are valid.
21
+ *
22
+ * Decimal numbers are supported. E.g. `"1.5gb"` is valid.
23
+ *
24
+ * Uses 1000 as the base for conversions. E.g. 1kb = 1000 bytes.
25
+ * This is consistent with the effective stamp utilization table.
26
+ *
27
+ * Supported units:
28
+ * - b, byte, bytes
29
+ * - kb, kilobyte, kilobytes
30
+ * - mb, megabyte, megabytes
31
+ * - gb, gigabyte, gigabytes
32
+ * - tb, terabyte, terabytes
33
+ *
34
+ * @param size - A string representing a size
35
+ * @returns a `Size` instance
36
+ */
37
+ static parseFromString(size: string): Size;
15
38
  toBytes(): number;
16
39
  toGigabytes(): number;
17
40
  toFormattedString(): string;
@@ -1,4 +1,4 @@
1
- import { EnvelopeWithBatchId, NumberString, RedundancyLevel } from '../types';
1
+ import { EnvelopeWithBatchId, NumberString, PostageBatch, RedundancyLevel } from '../types';
2
2
  import { Bytes } from './bytes';
3
3
  import { Duration } from './duration';
4
4
  import { Size } from './size';
@@ -58,3 +58,17 @@ export declare function getAmountForDuration(duration: Duration, pricePerBlock:
58
58
  export declare function getDepthForSize(size: Size, encryption?: boolean, erasureCodeLevel?: RedundancyLevel): number;
59
59
  export declare function convertEnvelopeToMarshaledStamp(envelope: EnvelopeWithBatchId): Bytes;
60
60
  export declare function marshalStamp(signature: Uint8Array, batchId: Uint8Array, timestamp: Uint8Array, index: Uint8Array): Bytes;
61
+ export interface RawPostageBatch {
62
+ batchID: string;
63
+ utilization: number;
64
+ usable: boolean;
65
+ label: string;
66
+ depth: number;
67
+ amount: string;
68
+ bucketDepth: number;
69
+ blockNumber: number;
70
+ immutableFlag: boolean;
71
+ batchTTL: number;
72
+ }
73
+ export declare function mapPostageBatch(raw: RawPostageBatch, encryption?: boolean, erasureCodeLevel?: RedundancyLevel): PostageBatch;
74
+ export declare function unmapPostageBatch(batch: PostageBatch): RawPostageBatch;
@@ -1,7 +1,7 @@
1
1
  export declare class TarStream {
2
2
  pieces: Uint8Array[];
3
3
  currentFileSize: number;
4
- get output(): Uint8Array;
4
+ get output(): Uint8Array<ArrayBufferLike>;
5
5
  beginFile(path: string, size: number): void;
6
6
  appendFile(data: Uint8Array): Promise<void>;
7
7
  endFile(): Promise<void>;
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { PassThrough } from 'stream';
3
2
  export declare class TarStream {
4
3
  output: PassThrough;
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import * as stream from 'stream';
3
2
  import { AllTagsOptions, BeeRequestOptions, CollectionUploadOptions, DownloadOptions, FileUploadOptions, GsocMessageHandler, NumberString, PostageBatchOptions, PssMessageHandler, RedundantUploadOptions, Tag, TransactionOptions, UploadOptions } from '../types';
4
3
  export declare function isReadable(value: unknown): value is stream.Readable;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@upcoming/bee-js",
3
- "version": "9.9.1",
3
+ "version": "11.1.0",
4
4
  "description": "Javascript client for Bee",
5
5
  "keywords": [
6
6
  "bee",
@@ -50,19 +50,19 @@
50
50
  "dist"
51
51
  ],
52
52
  "scripts": {
53
- "prepublishOnly": "cross-env NODE_ENV=production npm run build",
53
+ "prepublishOnly": "NODE_ENV=production npm run build",
54
54
  "build": "rimraf dist && npm run build:node && npm run build:types && npm run build:browser",
55
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/",
56
56
  "build:types": "tsc --emitDeclarationOnly --declaration --outDir dist/types",
57
57
  "build:browser": "webpack --progress",
58
- "test": "jest --config=jest.config.ts --runInBand --verbose --forceExit",
58
+ "test": "TS_NODE_PROJECT=tsconfig.test.json jest --runInBand --verbose --forceExit",
59
59
  "check": "tsc --project tsconfig.test.json",
60
60
  "lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\" && prettier --check \"src/**/*.ts\" \"test/**/*.ts\"",
61
61
  "depcheck": "depcheck ."
62
62
  },
63
63
  "dependencies": {
64
- "axios": "^0.30.0",
65
- "cafe-utility": "^31.0.0",
64
+ "axios": "^0.30.2",
65
+ "cafe-utility": "^33.6.1",
66
66
  "debug": "^4.4.1",
67
67
  "isomorphic-ws": "^4.0.1",
68
68
  "semver": "^7.3.5",
@@ -77,10 +77,8 @@
77
77
  "@babel/preset-typescript": "^7.18.6",
78
78
  "@commitlint/cli": "^17.0.2",
79
79
  "@commitlint/config-conventional": "^17.4.2",
80
- "@jest/types": "^29.6.3",
81
- "@naholyr/cross-env": "^1.0.0",
82
80
  "@types/debug": "^4.1.12",
83
- "@types/jest": "^29.5.13",
81
+ "@types/jest": "^30.0.0",
84
82
  "@types/node": "^18.11.11",
85
83
  "@types/semver": "^7.3.9",
86
84
  "@types/ws": "^8.5.3",
@@ -88,20 +86,19 @@
88
86
  "@typescript-eslint/parser": "^5.46.0",
89
87
  "babel-loader": "^9.1.0",
90
88
  "babel-plugin-add-import-extension": "^1.6.0",
91
- "cross-env": "^7.0.3",
92
89
  "depcheck": "^1.4.7",
93
90
  "eslint": "^8.13.0",
94
91
  "eslint-config-prettier": "^8.5.0",
95
92
  "eslint-plugin-prettier": "^4.0.0",
96
93
  "eslint-plugin-unused-imports": "^2.0.0",
97
94
  "husky": "^8.0.1",
98
- "jest": "^29.7.0",
95
+ "jest": "^30.2.0",
99
96
  "prettier": "^2.6.2",
100
97
  "rimraf": "^3.0.2",
101
98
  "terser-webpack-plugin": "^5.3.1",
102
- "ts-jest": "^29.2.5",
103
- "ts-node": "^10.9.1",
104
- "typescript": "^4.9.5",
99
+ "ts-jest": "^29.4.6",
100
+ "ts-node": "^10.9.2",
101
+ "typescript": "^5.9.3",
105
102
  "webpack": "^5.75.0",
106
103
  "webpack-cli": "^5.0.1"
107
104
  }