@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,32 +1,21 @@
1
- import type { Identifier, SingleOwnerChunk } from '../chunk/soc';
1
+ import { Optional } from 'cafe-utility';
2
+ import type { SingleOwnerChunk } from '../chunk/soc';
2
3
  import type { FeedUploadOptions } from '../feed';
3
- import type { FeedType } from '../feed/type';
4
- import type { FeedUpdateOptions, FetchFeedUpdateResponse } from '../modules/feed';
5
- import type { Bytes } from '../utils/bytes';
4
+ import type { FeedPayloadResult, FeedReferenceResult, FeedUpdateOptions } from '../modules/feed';
5
+ import { Bytes } from '../utils/bytes';
6
+ import { Duration } from '../utils/duration';
6
7
  import type { BeeError } from '../utils/error';
7
- import type { EthAddress, HexEthAddress } from '../utils/eth';
8
- import type { HexString } from '../utils/hex';
8
+ import { Size } from '../utils/size';
9
+ import { BatchId, EthAddress, Identifier, PrivateKey, PublicKey, Reference, Topic, TransactionId } from '../utils/typed-bytes';
9
10
  export * from './debug';
10
- export declare const SPAN_SIZE = 8;
11
11
  export declare const SECTION_SIZE = 32;
12
12
  export declare const BRANCHES = 128;
13
13
  export declare const CHUNK_SIZE: number;
14
- export declare const ADDRESS_HEX_LENGTH = 64;
15
- export declare const PSS_TARGET_HEX_LENGTH_MAX = 6;
16
- export declare const PUBKEY_HEX_LENGTH = 66;
17
- export declare const BATCH_ID_HEX_LENGTH = 64;
18
- export declare const REFERENCE_HEX_LENGTH = 64;
19
- export declare const ENCRYPTED_REFERENCE_HEX_LENGTH = 128;
20
- export declare const REFERENCE_BYTES_LENGTH = 32;
21
- export declare const ENCRYPTED_REFERENCE_BYTES_LENGTH = 64;
14
+ export declare const PSS_TARGET_HEX_LENGTH_MAX = 4;
22
15
  /**
23
16
  * Minimal depth that can be used for creation of postage batch
24
17
  */
25
18
  export declare const STAMPS_DEPTH_MIN = 17;
26
- /**
27
- * Minimal amount that can be used for creation of postage batch
28
- */
29
- export declare const STAMPS_AMOUNT_MIN: number;
30
19
  /**
31
20
  * Maximal depth that can be used for creation of postage batch
32
21
  */
@@ -34,50 +23,20 @@ export declare const STAMPS_DEPTH_MAX = 255;
34
23
  export declare const TAGS_LIMIT_MIN = 1;
35
24
  export declare const TAGS_LIMIT_MAX = 1000;
36
25
  export declare const FEED_INDEX_HEX_LENGTH = 16;
37
- /**
38
- * Generic reference that can be either non-encrypted reference which is a hex string of length 64 or encrypted
39
- * reference which is a hex string of length 128.
40
- *
41
- * Encrypted reference consists of two parts. The reference address itself (like non-encrypted reference) and decryption key.
42
- *
43
- * @see [Bee docs - Store with Encryption](https://docs.ethswarm.org/docs/develop/access-the-swarm/store-with-encryption)
44
- */
45
- export type Reference = HexString<typeof REFERENCE_HEX_LENGTH> | HexString<typeof ENCRYPTED_REFERENCE_HEX_LENGTH>;
46
- /**
47
- * Type that represents either Swarm's reference in hex string or ESN domain (something.eth).
48
- */
49
- export type ReferenceOrEns = Reference | string;
50
- /**
51
- * Type that represents either Swarm's reference in hex string, ESN domain (something.eth) or CID using one of the Swarm's codecs.
52
- */
53
- export type ReferenceCidOrEns = ReferenceOrEns | string;
54
- export type PlainBytesReference = Bytes<typeof REFERENCE_BYTES_LENGTH>;
55
- export type EncryptedBytesReference = Bytes<typeof ENCRYPTED_REFERENCE_BYTES_LENGTH>;
56
- export type BytesReference = PlainBytesReference | EncryptedBytesReference;
57
- export type PublicKey = HexString<typeof PUBKEY_HEX_LENGTH>;
58
- export type Address = HexString<typeof ADDRESS_HEX_LENGTH>;
59
- /**
60
- * BatchId is result of keccak256 hash so 64 hex string without prefix.
61
- */
62
- export type BatchId = HexString<typeof BATCH_ID_HEX_LENGTH>;
63
- /**
64
- * AddressPrefix is an HexString of length equal or smaller then ADDRESS_HEX_LENGTH.
65
- * It represents PSS Address Prefix that is used to define address neighborhood that will receive the PSS message.
66
- */
67
- export type AddressPrefix = HexString;
68
26
  export type BeeRequestOptions = {
69
27
  baseURL?: string;
70
- timeout?: number | false;
28
+ timeout?: number;
71
29
  headers?: Record<string, string>;
72
30
  onRequest?: (request: BeeRequest) => void;
73
- httpAgent?: any;
74
- httpsAgent?: any;
31
+ httpAgent?: unknown;
32
+ httpsAgent?: unknown;
33
+ endlesslyRetry?: boolean;
75
34
  };
76
35
  export interface BeeOptions extends BeeRequestOptions {
77
36
  /**
78
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.
79
38
  */
80
- signer?: Signer | Uint8Array | string;
39
+ signer?: PrivateKey | Uint8Array | string;
81
40
  }
82
41
  export interface GranteesResult {
83
42
  status: number;
@@ -88,15 +47,7 @@ export interface GranteesResult {
88
47
  export interface GetGranteesResult {
89
48
  status: number;
90
49
  statusText: string;
91
- data: string[];
92
- }
93
- export interface UploadResultWithCid extends UploadResult {
94
- /**
95
- * Function that converts the reference into Swarm CIDs
96
- *
97
- * @throws TypeError if the reference is encrypted reference (eq. 128 chars long) which is not supported in CID
98
- */
99
- cid: () => string;
50
+ grantees: PublicKey[];
100
51
  }
101
52
  /**
102
53
  * Result of upload calls.
@@ -113,13 +64,14 @@ export interface UploadResult {
113
64
  /**
114
65
  * History address of the uploaded data with ACT.
115
66
  */
116
- historyAddress: string;
67
+ historyAddress: Optional<Reference>;
117
68
  }
118
69
  export interface UploadOptions {
119
70
  /**
120
71
  * If set to true, an ACT will be created for the uploaded data.
121
72
  */
122
73
  act?: boolean;
74
+ actHistoryAddress?: Reference | Uint8Array | string;
123
75
  /**
124
76
  * Will pin the data locally in the Bee node as well.
125
77
  *
@@ -168,7 +120,7 @@ export declare enum RedundancyLevel {
168
120
  INSANE = 3,
169
121
  PARANOID = 4
170
122
  }
171
- export interface UploadRedundancyOptions {
123
+ export interface RedundantUploadOptions extends UploadOptions {
172
124
  redundancyLevel?: RedundancyLevel;
173
125
  }
174
126
  /**
@@ -187,7 +139,7 @@ export declare enum RedundancyStrategy {
187
139
  PROX = 2,
188
140
  RACE = 3
189
141
  }
190
- export interface DownloadRedundancyOptions {
142
+ export interface DownloadOptions {
191
143
  /**
192
144
  * Specify the retrieve strategy on redundant data.
193
145
  */
@@ -200,6 +152,9 @@ export interface DownloadRedundancyOptions {
200
152
  * Specify the timeout for chunk retrieval. The default is 30 seconds.
201
153
  */
202
154
  timeoutMs?: number;
155
+ actPublisher?: PublicKey | Uint8Array | string;
156
+ actHistoryAddress?: Reference | Uint8Array | string;
157
+ actTimestamp?: string | number;
203
158
  }
204
159
  export interface FileUploadOptions extends UploadOptions {
205
160
  /**
@@ -214,6 +169,7 @@ export interface FileUploadOptions extends UploadOptions {
214
169
  * @see [Bee API reference - `POST /bzz`](https://docs.ethswarm.org/api/#tag/BZZ/paths/~1bzz/post)
215
170
  */
216
171
  contentType?: string;
172
+ redundancyLevel?: RedundancyLevel;
217
173
  }
218
174
  export interface CollectionUploadOptions extends UploadOptions {
219
175
  /**
@@ -230,6 +186,7 @@ export interface CollectionUploadOptions extends UploadOptions {
230
186
  * @see [Bee API reference - `POST /bzz`](https://docs.ethswarm.org/api/#tag/BZZ/paths/~1bzz/post)
231
187
  */
232
188
  errorDocument?: string;
189
+ redundancyLevel?: RedundancyLevel;
233
190
  }
234
191
  export interface UploadHeaders {
235
192
  'swarm-act'?: string;
@@ -244,37 +201,13 @@ export interface UploadHeaders {
244
201
  * @see [Bee docs - Syncing / Tags](https://docs.ethswarm.org/docs/develop/access-the-swarm/syncing)
245
202
  */
246
203
  export interface Tag {
247
- /**
248
- * Number of chunks created by the splitter.
249
- */
250
204
  split: number;
251
- /**
252
- * Number of chunks that are already uploaded with same reference and same postage batch. These don't need to be synced again.
253
- */
254
205
  seen: number;
255
- /**
256
- * Number of chunks that were stored locally as they lie in the uploader node's neighborhood. This is only applicable for full nodes.
257
- */
258
206
  stored: number;
259
- /**
260
- * Number of chunks sent on the network to peers as a part of the upload. Chunks could be sent multiple times because of failures or replication.
261
- */
262
207
  sent: number;
263
- /**
264
- * Number of chunks that were pushed with a valid receipt. The receipt will also show if they were stored at the correct depth.
265
- */
266
208
  synced: number;
267
- /**
268
- * Unique identifier
269
- */
270
209
  uid: number;
271
- /**
272
- * Swarm hash of the uploaded data
273
- */
274
210
  address: string;
275
- /**
276
- * When the upload process started
277
- */
278
211
  startedAt: string;
279
212
  }
280
213
  export interface AllTagsOptions {
@@ -290,7 +223,7 @@ export interface FileData<T> extends FileHeaders {
290
223
  data: T;
291
224
  }
292
225
  export interface Pin {
293
- reference: string;
226
+ reference: Reference;
294
227
  }
295
228
  export interface ReferenceInformation {
296
229
  contentLength: number;
@@ -310,7 +243,7 @@ export interface Data extends Uint8Array {
310
243
  /**
311
244
  * Converts the binary data into hex-string.
312
245
  */
313
- hex(): HexString;
246
+ hex(): string;
314
247
  /**
315
248
  * Converts the binary data into string which is then parsed into JSON.
316
249
  */
@@ -330,16 +263,20 @@ export interface CollectionEntry {
330
263
  */
331
264
  export type Collection = Array<CollectionEntry>;
332
265
  export interface PssSubscription {
333
- readonly topic: string;
266
+ readonly topic: Topic;
334
267
  cancel: () => void;
335
268
  }
336
269
  export interface PssMessageHandler {
337
- onMessage: (message: Data, subscription: PssSubscription) => void;
270
+ onMessage: (message: Bytes, subscription: PssSubscription) => void;
338
271
  onError: (error: BeeError, subscription: PssSubscription) => void;
339
272
  }
340
- export interface BeeGenericResponse {
341
- message: string;
342
- code: number;
273
+ export interface GsocSubscription {
274
+ readonly address: EthAddress;
275
+ cancel: () => void;
276
+ }
277
+ export interface GsocMessageHandler {
278
+ onMessage: (message: Bytes, subscription: GsocSubscription) => void;
279
+ onError: (error: BeeError, subscription: GsocSubscription) => void;
343
280
  }
344
281
  export interface ReferenceResponse {
345
282
  reference: Reference;
@@ -358,53 +295,24 @@ export interface BeeResponse {
358
295
  statusText?: string;
359
296
  request: BeeRequest;
360
297
  }
361
- /*********************************************************
362
- * Writers and Readers interfaces
363
- */
364
- export declare const TOPIC_BYTES_LENGTH = 32;
365
- export declare const TOPIC_HEX_LENGTH = 64;
366
- /**
367
- * Hex string of length 64 chars without prefix that specifies topics for feed.
368
- */
369
- export type Topic = HexString<typeof TOPIC_HEX_LENGTH>;
370
- /**
371
- * Result of upload calls.
372
- */
373
- export interface FeedManifestResult {
374
- /**
375
- * Reference of the uploaded data
376
- */
377
- reference: Reference;
378
- /**
379
- * Function that converts the reference into Swarm Feed CID.
380
- */
381
- cid: () => string;
382
- }
383
298
  /**
384
299
  * FeedReader is an interface for downloading feed updates
385
300
  */
386
301
  export interface FeedReader {
387
- readonly type: FeedType;
388
- readonly owner: HexEthAddress;
302
+ readonly owner: EthAddress;
389
303
  readonly topic: Topic;
390
304
  /**
391
- * Download the latest feed update
305
+ * @deprecated Use `downloadReference` or `downloadPayload` instead to disambiguate how the data should be interpreted.
392
306
  */
393
- download(options?: FeedUpdateOptions): Promise<FetchFeedUpdateResponse>;
394
- }
395
- export interface JsonFeedOptions {
307
+ download(options?: FeedUpdateOptions): Promise<FeedPayloadResult>;
396
308
  /**
397
- * Valid only for `get` action, where either this `address` or `signer` has
398
- * to be specified.
309
+ * Downloads the feed update (latest if no index is specified) and returns it as a reference.
399
310
  */
400
- address?: EthAddress | Uint8Array | string;
311
+ downloadReference(options?: FeedUpdateOptions): Promise<FeedReferenceResult>;
401
312
  /**
402
- * Custom Signer object or private key in either binary or hex form.
403
- * This required for `set` action, and optional for `get` although
404
- * if not specified for `get` then `address` option has to be specified.
313
+ * Downloads the feed update (latest if no index is specified) and returns it as a payload.
405
314
  */
406
- signer?: Signer | Uint8Array | string;
407
- type?: FeedType;
315
+ downloadPayload(options?: FeedUpdateOptions): Promise<FeedPayloadResult>;
408
316
  }
409
317
  /**
410
318
  * FeedWriter is an interface for updating feeds
@@ -413,25 +321,29 @@ export interface FeedWriter extends FeedReader {
413
321
  /**
414
322
  * Upload a new feed update
415
323
  *
324
+ * @deprecated Use `uploadReference` or `uploadPayload` instead to disambiguate how the data should be interpreted.
325
+ *
416
326
  * @param postageBatchId Postage BatchId to be used to upload the data with
417
327
  * @param reference The reference to be stored in the new update
418
328
  * @param options Additional options like `at`
419
329
  *
420
330
  * @returns UpdateResult that points at Single Owner Chunk that contains the new update and pointer to the updated chunk reference.
421
331
  */
422
- upload(postageBatchId: string | BatchId, reference: BytesReference | Reference, options?: FeedUploadOptions): Promise<UploadResult>;
332
+ upload(postageBatchId: string | BatchId, reference: Reference | string | Uint8Array, options?: FeedUploadOptions): Promise<UploadResult>;
333
+ uploadReference(postageBatchId: string | BatchId, reference: Reference | string | Uint8Array, options?: FeedUploadOptions): Promise<UploadResult>;
334
+ uploadPayload(postageBatchId: string | BatchId, payload: Uint8Array | string, options?: FeedUploadOptions): Promise<UploadResult>;
423
335
  }
424
336
  /**
425
337
  * Interface for downloading single owner chunks
426
338
  */
427
339
  export interface SOCReader {
428
- readonly owner: HexEthAddress;
340
+ readonly owner: EthAddress;
429
341
  /**
430
342
  * Downloads a single owner chunk
431
343
  *
432
344
  * @param identifier The identifier of the chunk
433
345
  */
434
- download: (identifier: Identifier) => Promise<SingleOwnerChunk>;
346
+ download: (identifier: Identifier | Uint8Array | string) => Promise<SingleOwnerChunk>;
435
347
  }
436
348
  /**
437
349
  * Interface for downloading and uploading single owner chunks
@@ -444,26 +356,60 @@ export interface SOCWriter extends SOCReader {
444
356
  * @param data The chunk payload data
445
357
  * @param options Upload options
446
358
  */
447
- upload: (stamp: BatchId | Uint8Array | string, identifier: Identifier, data: Uint8Array, options?: UploadOptions) => Promise<UploadResult>;
359
+ upload: (stamp: BatchId | Uint8Array | string, identifier: Identifier | Uint8Array | string, data: Uint8Array, options?: UploadOptions) => Promise<UploadResult>;
360
+ }
361
+ export interface GlobalPostageBatch {
362
+ batchID: BatchId;
363
+ value: NumberString;
364
+ start: number;
365
+ owner: EthAddress;
366
+ depth: number;
367
+ bucketDepth: number;
368
+ immutable: boolean;
369
+ batchTTL: number;
448
370
  }
449
- /**
450
- * Interface representing Postage stamp batch.
451
- */
452
371
  export interface PostageBatch {
453
372
  batchID: BatchId;
373
+ /**
374
+ * Represents how much of the batch is used up.
375
+ *
376
+ * Max utilization = `2 ** (depth - bucketDepth)`
377
+ *
378
+ * Since the smallest depth is 17, and one batch has 65,536 buckets, and one chunk is 4,096 bytes,
379
+ * the 512MB theoretical max size for the smallest stamp comes from `2 * 65536 * 4096 = 512MB`
380
+ */
454
381
  utilization: number;
455
382
  usable: boolean;
456
- label: '' | string;
383
+ label: string;
457
384
  depth: number;
458
- amount: string;
385
+ amount: NumberString;
459
386
  bucketDepth: number;
460
387
  blockNumber: number;
461
388
  immutableFlag: boolean;
462
389
  /**
463
- * The time (in seconds) remaining until the batch expires; -1 signals that the batch never expires; 0 signals that the batch has already expired.
390
+ * Estimated time until the batch expires
464
391
  */
465
- batchTTL: number;
466
- exists: boolean;
392
+ duration: Duration;
393
+ /**
394
+ * A floating point number from 0 to 1, where 0 is no usage, 1 is full usage.
395
+ */
396
+ usage: number;
397
+ /**
398
+ * Human readable usage text, like "50%" or "100%", no fractions
399
+ */
400
+ usageText: string;
401
+ /**
402
+ * Effective size
403
+ */
404
+ size: Size;
405
+ /**
406
+ * Estimated remaining size
407
+ */
408
+ remainingSize: Size;
409
+ /**
410
+ * Theoretical size in bytes
411
+ */
412
+ theoreticalSize: Size;
467
413
  }
468
414
  export interface BatchBucket {
469
415
  bucketID: number;
@@ -473,12 +419,11 @@ export interface PostageBatchBuckets {
473
419
  depth: number;
474
420
  bucketDepth: number;
475
421
  bucketUpperBound: number;
476
- buckets?: BatchBucket[];
422
+ buckets: BatchBucket[];
477
423
  }
478
- export type TransactionHash = BrandedString<'TransactionHash'>;
479
424
  export interface TransactionInfo {
480
- transactionHash: TransactionHash;
481
- to: HexEthAddress;
425
+ transactionHash: TransactionId;
426
+ to: string;
482
427
  nonce: number;
483
428
  gasPrice: NumberString;
484
429
  gasLimit: number;
@@ -498,7 +443,10 @@ export interface PostageBatchOptions {
498
443
  /**
499
444
  * Sets gas price in Wei for the transaction that creates the postage batch
500
445
  */
501
- gasPrice?: NumberString;
446
+ gasPrice?: NumberString | string | bigint;
447
+ /**
448
+ * Controls whether data can be overwritten that was uploaded with this postage batch.
449
+ */
502
450
  immutableFlag?: boolean;
503
451
  /**
504
452
  * The returned Promise will await until the purchased Postage Batch is usable.
@@ -523,61 +471,12 @@ export interface Envelope {
523
471
  timestamp: Uint8Array;
524
472
  signature: Uint8Array;
525
473
  }
474
+ export interface EnvelopeWithBatchId extends Envelope {
475
+ batchId: BatchId;
476
+ }
526
477
  /**
527
478
  * With this type a number should be represented in a string
528
479
  */
529
- export type NumberString = FlavoredType<string, 'NumberString'>;
530
- /*********************************************************
531
- * Ethereum compatible signing interfaces and definitions
532
- */
533
- export declare const SIGNATURE_HEX_LENGTH = 130;
534
- export declare const SIGNATURE_BYTES_LENGTH = 65;
535
- export type Signature = Bytes<typeof SIGNATURE_BYTES_LENGTH>;
536
- export type PrivateKeyBytes = Bytes<32>;
537
- /**
538
- * Signing function that takes digest in Uint8Array to be signed that has helpers to convert it
539
- * conveniently into other types like hex-string (non prefix).
540
- * Result of the signing can be returned either in Uint8Array or hex string form.
541
- *
542
- * @see Data
543
- */
544
- type SyncSigner = (digest: Data) => Signature | HexString<typeof SIGNATURE_HEX_LENGTH> | string;
545
- type AsyncSigner = (digest: Data) => Promise<Signature | HexString<typeof SIGNATURE_HEX_LENGTH> | string>;
546
- /**
547
- * Interface for implementing Ethereum compatible signing.
548
- *
549
- * In order to be compatible with Ethereum and its signing method `personal_sign`, the data
550
- * that are passed to sign() function should be prefixed with: `\x19Ethereum Signed Message:\n${data.length}`, hashed
551
- * and only then signed.
552
- * If you are wrapping another signer tool/library (like Metamask or some other Ethereum wallet), you might not have
553
- * to do this prefixing manually if you use the `personal_sign` method. Check documentation of the tool!
554
- * If you are writing your own storage for keys, then you have to prefix the data manually otherwise the Bee node
555
- * will reject the chunks signed by you!
556
- *
557
- * For example see the hashWithEthereumPrefix() function.
558
- *
559
- * @property sign The sign function that can be sync or async. This function takes non-prefixed data. See above.
560
- * @property address The ethereum address of the signer in bytes.
561
- * @see hashWithEthereumPrefix
562
- */
563
- export type Signer = {
564
- sign: SyncSigner | AsyncSigner;
565
- address: EthAddress;
480
+ export type NumberString = string & {
481
+ __numberString: never;
566
482
  };
567
- /**
568
- * These type are used to create new nominal types
569
- *
570
- * See https://spin.atomicobject.com/2018/01/15/typescript-flexible-nominal-typing/
571
- */
572
- export type BrandedType<Type, Name> = Type & {
573
- __tag__: Name;
574
- };
575
- export type BrandedString<Name> = BrandedType<string, Name>;
576
- export type FlavoredType<Type, Name> = Type & {
577
- __tag__?: Name;
578
- };
579
- export type AnyJson = boolean | number | string | null | JsonArray | JsonMap;
580
- interface JsonMap {
581
- [key: string]: AnyJson;
582
- }
583
- type JsonArray = Array<AnyJson>;
@@ -1,91 +1,17 @@
1
- /**
2
- * Helper type for dealing with fixed size byte arrays.
3
- *
4
- * It changes the type of `length` property of `Uint8Array` to the
5
- * generic `Length` type parameter which is runtime compatible with
6
- * the original, because it extends from the `number` type.
7
- */
8
- import { Data } from '../types';
9
- export interface Bytes<Length extends number> extends Uint8Array {
10
- readonly length: Length;
1
+ export declare class Bytes {
2
+ protected readonly bytes: Uint8Array;
3
+ readonly length: number;
4
+ constructor(bytes: Uint8Array | ArrayBuffer | string | Bytes, byteLength?: number | number[]);
5
+ static keccak256(bytes: Uint8Array | ArrayBuffer | string | Bytes): Bytes;
6
+ static fromUtf8(utf8: string): Bytes;
7
+ static fromSlice(bytes: Uint8Array, start: number, length?: number): Bytes;
8
+ offset(index: number): Uint8Array;
9
+ toUint8Array(): Uint8Array;
10
+ toHex(): string;
11
+ toBase64(): string;
12
+ toBase32(): string;
13
+ toString(): string;
14
+ toUtf8(): string;
15
+ toJSON(): unknown;
16
+ equals(other: Bytes | Uint8Array | string): boolean;
11
17
  }
12
- /**
13
- * Helper type for dealing with flexible sized byte arrays.
14
- *
15
- * The actual min and and max values are not stored in runtime, they
16
- * are only there to differentiate the type from the Uint8Array at
17
- * compile time.
18
- * @see BrandedType
19
- */
20
- export interface FlexBytes<Min extends number, Max extends number> extends Uint8Array {
21
- readonly __min__: Min;
22
- readonly __max__: Max;
23
- }
24
- /**
25
- * Type guard for `Bytes<T>` type
26
- *
27
- * @param b The byte array
28
- * @param length The length of the byte array
29
- */
30
- export declare function isBytes<Length extends number>(b: unknown, length: Length): b is Bytes<Length>;
31
- /**
32
- * Function that verifies if passed data are Bytes and if the array has "length" number of bytes under given offset.
33
- * @param data
34
- * @param offset
35
- * @param length
36
- */
37
- export declare function hasBytesAtOffset(data: unknown, offset: number, length: number): boolean;
38
- /**
39
- * Verifies if a byte array has a certain length
40
- *
41
- * @param b The byte array
42
- * @param length The specified length
43
- */
44
- export declare function assertBytes<Length extends number>(b: unknown, length: Length): asserts b is Bytes<Length>;
45
- /**
46
- * Type guard for FlexBytes<Min,Max> type
47
- *
48
- * @param b The byte array
49
- * @param min Minimum size of the array
50
- * @param max Maximum size of the array
51
- */
52
- export declare function isFlexBytes<Min extends number, Max extends number = Min>(b: unknown, min: Min, max: Max): b is FlexBytes<Min, Max>;
53
- /**
54
- * Verifies if a byte array has a certain length between min and max
55
- *
56
- * @param b The byte array
57
- * @param min Minimum size of the array
58
- * @param max Maximum size of the array
59
- */
60
- export declare function assertFlexBytes<Min extends number, Max extends number = Min>(b: unknown, min: Min, max: Max): asserts b is FlexBytes<Min, Max>;
61
- /**
62
- * Return `length` bytes starting from `offset`
63
- *
64
- * @param data The original data
65
- * @param offset The offset to start from
66
- * @param length The length of data to be returned
67
- */
68
- export declare function bytesAtOffset<Length extends number>(data: Uint8Array, offset: number, length: Length): Bytes<Length>;
69
- /**
70
- * Return flex bytes starting from `offset`
71
- *
72
- * @param data The original data
73
- * @param offset The offset to start from
74
- * @param _min The minimum size of the data
75
- * @param _max The maximum size of the data
76
- */
77
- export declare function flexBytesAtOffset<Min extends number, Max extends number>(data: Uint8Array, offset: number, _min: Min, _max: Max): FlexBytes<Min, Max>;
78
- /**
79
- * Returns true if two byte arrays are equal
80
- *
81
- * @param a Byte array to compare
82
- * @param b Byte array to compare
83
- */
84
- export declare function bytesEqual(a: Uint8Array, b: Uint8Array): boolean;
85
- /**
86
- * Returns a new byte array filled with zeroes with the specified length
87
- *
88
- * @param length The length of data to be returned
89
- */
90
- export declare function makeBytes<Length extends number>(length: Length): Bytes<Length>;
91
- export declare function wrapBytesWithHelpers(data: Uint8Array): Data;
@@ -0,0 +1 @@
1
+ export declare function totalChunks(fileSize: number): number;
@@ -0,0 +1,6 @@
1
+ import { Bee, BeeRequestOptions, UploadOptions, UploadResult } from '..';
2
+ import { BatchId, Reference } from './typed-bytes';
3
+ import { UploadProgress } from './upload-progress';
4
+ export declare function hashDirectory(_dir: string): Promise<void>;
5
+ export declare function streamDirectory(_bee: Bee, _dir: string, _postageBatchId: BatchId | string | Uint8Array, _onUploadProgress?: (progress: UploadProgress) => void, _options?: UploadOptions, _requestOptions?: BeeRequestOptions): Promise<Reference>;
6
+ export declare function streamFiles(bee: Bee, files: File[] | FileList, postageBatchId: BatchId, onUploadProgress?: (progress: UploadProgress) => void, options?: UploadOptions, requestOptions?: BeeRequestOptions): Promise<UploadResult>;
@@ -0,0 +1,6 @@
1
+ import { Bee, BeeRequestOptions, UploadOptions, UploadResult } from '..';
2
+ import { BatchId } from './typed-bytes';
3
+ import { UploadProgress } from './upload-progress';
4
+ export declare function hashDirectory(dir: string): Promise<import("./typed-bytes").Reference>;
5
+ export declare function streamDirectory(bee: Bee, dir: string, postageBatchId: BatchId | string | Uint8Array, onUploadProgress?: (progress: UploadProgress) => void, options?: UploadOptions, requestOptions?: BeeRequestOptions): Promise<UploadResult>;
6
+ export declare function streamFiles(_bee: Bee, _files: File[] | FileList, _postageBatchId: BatchId, _onUploadProgress?: (progress: UploadProgress) => void, _options?: UploadOptions, _requestOptions?: BeeRequestOptions): Promise<UploadResult>;
@@ -1,9 +1,10 @@
1
- import { Reference } from '..';
1
+ import { Bytes } from './bytes';
2
+ import { Reference } from './typed-bytes';
2
3
  export declare const SWARM_MANIFEST_CODEC = 250;
3
4
  export declare const SWARM_FEED_CODEC = 251;
4
5
  export type DecodedCID = {
5
6
  type: 'feed' | 'manifest';
6
7
  reference: Reference;
7
8
  };
8
- export declare function convertReferenceToCid(reference: Reference | string, type: 'feed' | 'manifest'): string;
9
+ export declare function convertReferenceToCid(reference: string | Uint8Array | Bytes, type: 'feed' | 'manifest'): string;
9
10
  export declare function convertCidToReference(cid: string): DecodedCID;
@@ -5,11 +5,11 @@ import { Collection } from '../types';
5
5
  *
6
6
  * @param dir path to the directory
7
7
  */
8
- export declare function makeCollectionFromFS(dir: string): Promise<Collection>;
8
+ export declare function makeCollectionFromFS(_dir: string): Promise<Collection>;
9
9
  /**
10
10
  * Calculate folder size recursively
11
11
  *
12
12
  * @param dir the path to the folder to check
13
13
  * @returns size in bytes
14
14
  */
15
- export declare function getFolderSize(dir: string): Promise<number>;
15
+ export declare function getFolderSize(_dir: string): Promise<number>;
@@ -1,7 +1,8 @@
1
1
  import { Collection } from '../types';
2
2
  export declare function isCollection(data: unknown): data is Collection;
3
3
  export declare function assertCollection(data: unknown): asserts data is Collection;
4
- export declare function makeCollectionFromFileList(fileList: FileList | File[]): Promise<Collection>;
4
+ export declare function makeFilePath(file: File): string;
5
+ export declare function makeCollectionFromFileList(fileList: FileList | File[]): Collection;
5
6
  /**
6
7
  * Calculate cumulative size of files
7
8
  *