@ethersphere/bee-js 4.0.0 → 4.1.1

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.
@@ -37,13 +37,14 @@ import * as settlements from "./modules/debug/settlements.js";
37
37
  import * as status from "./modules/debug/status.js";
38
38
  import * as transactions from "./modules/debug/transactions.js";
39
39
  import * as states from "./modules/debug/states.js";
40
- import { BeeArgumentError } from "./utils/error.js";
40
+ import { BeeArgumentError, BeeError } from "./utils/error.js";
41
41
  import { assertBeeUrl, stripLastSlash } from "./utils/url.js";
42
- import { assertAddress, assertBatchId, assertBoolean, assertCashoutOptions, assertNonNegativeInteger, assertRequestOptions, assertTransactionHash, isTag } from "./utils/type.js";
42
+ import { assertAddress, assertBatchId, assertCashoutOptions, assertNonNegativeInteger, assertPositiveInteger, assertPostageBatchOptions, assertRequestOptions, assertTransactionHash, isTag } from "./utils/type.js";
43
43
  import { STAMPS_DEPTH_MAX, STAMPS_DEPTH_MIN } from "./types/index.js";
44
44
  import * as tag from "./modules/debug/tag.js";
45
45
  import * as stamps from "./modules/debug/stamps.js";
46
46
  import { makeDefaultKy, wrapRequestClosure, wrapResponseClosure } from "./utils/http.js";
47
+ import { sleep } from "./utils/sleep.js";
47
48
  export class BeeDebug {
48
49
  constructor(url, options) {
49
50
  var _a;
@@ -501,6 +502,19 @@ export class BeeDebug {
501
502
  return states.getChainState(this.getKy(options));
502
503
  });
503
504
  }
505
+ /**
506
+ * Get wallet balances for xDai and BZZ of the Bee node
507
+ *
508
+ * @param options
509
+ */
510
+
511
+
512
+ getWalletBalance(options) {
513
+ return __awaiter(this, void 0, void 0, function* () {
514
+ assertRequestOptions(options);
515
+ return states.getWalletBalance(this.getKy(options));
516
+ });
517
+ }
504
518
  /**
505
519
  * Creates new postage batch from the funds that the node has available in its Ethereum account.
506
520
  *
@@ -522,8 +536,8 @@ export class BeeDebug {
522
536
 
523
537
  createPostageBatch(amount, depth, options) {
524
538
  return __awaiter(this, void 0, void 0, function* () {
525
- assertRequestOptions(options);
526
- assertNonNegativeInteger(amount);
539
+ assertPostageBatchOptions(options);
540
+ assertPositiveInteger(amount);
527
541
  assertNonNegativeInteger(depth);
528
542
 
529
543
  if (depth < STAMPS_DEPTH_MIN) {
@@ -534,15 +548,13 @@ export class BeeDebug {
534
548
  throw new BeeArgumentError(`Depth has to be at most ${STAMPS_DEPTH_MAX}`, depth);
535
549
  }
536
550
 
537
- if (options === null || options === void 0 ? void 0 : options.gasPrice) {
538
- assertNonNegativeInteger(options.gasPrice);
539
- }
551
+ const stamp = yield stamps.createPostageBatch(this.getKy(options), amount, depth, options);
540
552
 
541
- if ((options === null || options === void 0 ? void 0 : options.immutableFlag) !== undefined) {
542
- assertBoolean(options.immutableFlag);
553
+ if (options === null || options === void 0 ? void 0 : options.waitForUsable) {
554
+ yield this.waitForUsablePostageStamp(stamp, options === null || options === void 0 ? void 0 : options.waitForUsableTimeout);
543
555
  }
544
556
 
545
- return stamps.createPostageBatch(this.getKy(options), amount, depth, options);
557
+ return stamp;
546
558
  });
547
559
  }
548
560
  /**
@@ -703,6 +715,24 @@ export class BeeDebug {
703
715
  });
704
716
  }
705
717
 
718
+ waitForUsablePostageStamp(id, timeout = 120000) {
719
+ return __awaiter(this, void 0, void 0, function* () {
720
+ const TIME_STEP = 1500;
721
+
722
+ for (let time = 0; time < timeout; time += TIME_STEP) {
723
+ const stamp = yield this.getPostageBatch(id);
724
+
725
+ if (stamp.usable) {
726
+ return;
727
+ }
728
+
729
+ yield sleep(TIME_STEP);
730
+ }
731
+
732
+ throw new BeeError('Timeout on waiting for postage stamp to become usable');
733
+ });
734
+ }
735
+
706
736
  getKy(options) {
707
737
  if (!options) {
708
738
  return this.ky;
package/dist/mjs/bee.js CHANGED
@@ -50,14 +50,15 @@ import { createFeedManifest } from "./modules/feed.js";
50
50
  import { assertBeeUrl, stripLastSlash } from "./utils/url.js";
51
51
  import { makeEthAddress, makeHexEthAddress } from "./utils/eth.js";
52
52
  import { wrapBytesWithHelpers } from "./utils/bytes.js";
53
- import { assertAddressPrefix, assertAllTagsOptions, assertBatchId, assertCollectionUploadOptions, assertData, assertFileData, assertFileUploadOptions, assertPssMessageHandler, assertPublicKey, assertReference, assertReferenceOrEns, assertRequestOptions, assertUploadOptions, makeTagUid } from "./utils/type.js";
54
- import { setJsonData, getJsonData } from "./feed/json.js";
55
- import { makeCollectionFromFileList, assertCollection } from "./utils/collection.js";
53
+ import { addCidConversionFunction, assertAddressPrefix, assertAllTagsOptions, assertBatchId, assertCollectionUploadOptions, assertData, assertFileData, assertFileUploadOptions, assertPssMessageHandler, assertPublicKey, assertReference, assertReferenceOrEns, assertRequestOptions, assertUploadOptions, makeReferenceOrEns, makeTagUid } from "./utils/type.js";
54
+ import { getJsonData, setJsonData } from "./feed/json.js";
55
+ import { assertCollection, makeCollectionFromFileList } from "./utils/collection.js";
56
56
  import { makeCollectionFromFS } from "./utils/collection.node.js";
57
57
  import { CHUNK_SIZE, SPAN_SIZE } from "./types/index.js";
58
58
  import { makeDefaultKy, wrapRequestClosure, wrapResponseClosure } from "./utils/http.js";
59
59
  import { isReadable } from "./utils/stream.js";
60
60
  import { areAllSequentialFeedsUpdateRetrievable } from "./feed/retrievable.js";
61
+ import { ReferenceType } from '@ethersphere/swarm-cid';
61
62
  /**
62
63
  * The main component that abstracts operations available on the main Bee API.
63
64
  *
@@ -254,21 +255,21 @@ export class Bee {
254
255
  const fileOptions = Object.assign({
255
256
  contentType
256
257
  }, options);
257
- return bzz.uploadFile(this.getKy(options), fileData, postageBatchId, fileName, fileOptions);
258
+ return addCidConversionFunction(yield bzz.uploadFile(this.getKy(options), fileData, postageBatchId, fileName, fileOptions), ReferenceType.MANIFEST);
258
259
  } else if (isReadable(data) && (options === null || options === void 0 ? void 0 : options.tag) && !options.size) {
259
260
  // TODO: Needed until https://github.com/ethersphere/bee/issues/2317 is resolved
260
261
  const result = yield bzz.uploadFile(this.getKy(options), data, postageBatchId, name, options);
261
262
  yield this.updateTag(options.tag, result.reference);
262
- return result;
263
+ return addCidConversionFunction(result, ReferenceType.MANIFEST);
263
264
  } else {
264
- return bzz.uploadFile(this.getKy(options), data, postageBatchId, name, options);
265
+ return addCidConversionFunction(yield bzz.uploadFile(this.getKy(options), data, postageBatchId, name, options), ReferenceType.MANIFEST);
265
266
  }
266
267
  });
267
268
  }
268
269
  /**
269
270
  * Download single file.
270
271
  *
271
- * @param reference Bee file reference in hex string (either 64 or 128 chars long) or ENS domain.
272
+ * @param reference Bee file reference in hex string (either 64 or 128 chars long), ENS domain or Swarm CID.
272
273
  * @param path If reference points to manifest, then this parameter defines path to the file
273
274
  * @param options Options that affects the request behavior
274
275
  * @throws TypeError if some of the input parameters is not expected type
@@ -282,14 +283,14 @@ export class Bee {
282
283
  downloadFile(reference, path = '', options) {
283
284
  return __awaiter(this, void 0, void 0, function* () {
284
285
  assertRequestOptions(options);
285
- assertReferenceOrEns(reference);
286
+ reference = makeReferenceOrEns(reference, ReferenceType.MANIFEST);
286
287
  return bzz.downloadFile(this.getKy(options), reference, path);
287
288
  });
288
289
  }
289
290
  /**
290
291
  * Download single file as a readable stream
291
292
  *
292
- * @param reference Bee file reference in hex string (either 64 or 128 chars long) or ENS domain.
293
+ * @param reference Bee file reference in hex string (either 64 or 128 chars long), ENS domain or Swarm CID.
293
294
  * @param path If reference points to manifest / collections, then this parameter defines path to the file
294
295
  * @param options Options that affects the request behavior
295
296
  * @throws TypeError if some of the input parameters is not expected type
@@ -303,7 +304,7 @@ export class Bee {
303
304
  downloadReadableFile(reference, path = '', options) {
304
305
  return __awaiter(this, void 0, void 0, function* () {
305
306
  assertRequestOptions(options);
306
- assertReferenceOrEns(reference);
307
+ reference = makeReferenceOrEns(reference, ReferenceType.MANIFEST);
307
308
  return bzz.downloadFileReadable(this.getKy(options), reference, path);
308
309
  });
309
310
  }
@@ -330,7 +331,7 @@ export class Bee {
330
331
  assertBatchId(postageBatchId);
331
332
  if (options) assertCollectionUploadOptions(options);
332
333
  const data = yield makeCollectionFromFileList(fileList);
333
- return bzz.uploadCollection(this.getKy(options), data, postageBatchId, options);
334
+ return addCidConversionFunction(yield bzz.uploadCollection(this.getKy(options), data, postageBatchId, options), ReferenceType.MANIFEST);
334
335
  });
335
336
  }
336
337
  /**
@@ -350,7 +351,7 @@ export class Bee {
350
351
  assertBatchId(postageBatchId);
351
352
  assertCollection(collection);
352
353
  if (options) assertCollectionUploadOptions(options);
353
- return bzz.uploadCollection(this.ky, collection, postageBatchId, options);
354
+ return addCidConversionFunction(yield bzz.uploadCollection(this.ky, collection, postageBatchId, options), ReferenceType.MANIFEST);
354
355
  });
355
356
  }
356
357
  /**
@@ -376,7 +377,7 @@ export class Bee {
376
377
  assertBatchId(postageBatchId);
377
378
  if (options) assertCollectionUploadOptions(options);
378
379
  const data = yield makeCollectionFromFS(dir);
379
- return bzz.uploadCollection(this.getKy(options), data, postageBatchId, options);
380
+ return addCidConversionFunction(yield bzz.uploadCollection(this.getKy(options), data, postageBatchId, options), ReferenceType.MANIFEST);
380
381
  });
381
382
  }
382
383
  /**
@@ -832,6 +833,7 @@ export class Bee {
832
833
  *
833
834
  * @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/dapps-on-swarm/feeds)
834
835
  * @see [Bee API reference - `POST /feeds`](https://docs.ethswarm.org/api/#tag/Feed/paths/~1feeds~1{owner}~1{topic}/post)
836
+ * TODO: Once breaking add support for Feed CID
835
837
  */
836
838
 
837
839
 
@@ -32,6 +32,7 @@ var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, gene
32
32
 
33
33
  import { http } from "../../utils/http.js";
34
34
  const RESERVE_STATE_ENDPOINT = 'reservestate';
35
+ const WALLET_ENDPOINT = 'wallet';
35
36
  const CHAIN_STATE_ENDPOINT = 'chainstate';
36
37
  /**
37
38
  * Get state of reserve
@@ -64,4 +65,20 @@ export function getChainState(ky) {
64
65
  });
65
66
  return response.data;
66
67
  });
68
+ }
69
+ /**
70
+ * Get wallet balances for xDai and BZZ of the node
71
+ *
72
+ * @param ky Ky debug instance
73
+ */
74
+
75
+ export function getWalletBalance(ky) {
76
+ return __awaiter(this, void 0, void 0, function* () {
77
+ const response = yield http(ky, {
78
+ method: 'get',
79
+ path: `${WALLET_ENDPOINT}`,
80
+ responseType: 'json'
81
+ });
82
+ return response.data;
83
+ });
67
84
  }
@@ -191,6 +191,13 @@ export function http(ky, config) {
191
191
  } else if (isHttpRequestError(e)) {
192
192
  throw new BeeRequestError(e.message, config);
193
193
  } else {
194
+ // Node 18 has native `fetch` implementation called Undici. Errors from this implementation have top level generic
195
+ // message "fetch failed" with the more specific error placed into `cause` property. Instead of "fetch failed" we
196
+ // expose the underlying problem.
197
+ if (e.cause) {
198
+ throw new BeeError(e.cause.message);
199
+ }
200
+
194
201
  throw new BeeError(e.message);
195
202
  }
196
203
  }
@@ -0,0 +1,43 @@
1
+ var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) {
3
+ return value instanceof P ? value : new P(function (resolve) {
4
+ resolve(value);
5
+ });
6
+ }
7
+
8
+ return new (P || (P = Promise))(function (resolve, reject) {
9
+ function fulfilled(value) {
10
+ try {
11
+ step(generator.next(value));
12
+ } catch (e) {
13
+ reject(e);
14
+ }
15
+ }
16
+
17
+ function rejected(value) {
18
+ try {
19
+ step(generator["throw"](value));
20
+ } catch (e) {
21
+ reject(e);
22
+ }
23
+ }
24
+
25
+ function step(result) {
26
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
27
+ }
28
+
29
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
30
+ });
31
+ };
32
+ /**
33
+ * Sleep for N miliseconds
34
+ *
35
+ * @param ms Number of miliseconds to sleep
36
+ */
37
+
38
+
39
+ export function sleep(ms) {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ return new Promise(resolve => setTimeout(() => resolve(), ms));
42
+ });
43
+ }
@@ -1,8 +1,9 @@
1
1
  import { ADDRESS_HEX_LENGTH, BATCH_ID_HEX_LENGTH, ENCRYPTED_REFERENCE_HEX_LENGTH, PUBKEY_HEX_LENGTH, REFERENCE_HEX_LENGTH, TAGS_LIMIT_MAX, TAGS_LIMIT_MIN, PSS_TARGET_HEX_LENGTH_MAX } from "../types/index.js";
2
- import { BeeArgumentError } from "./error.js";
2
+ import { BeeArgumentError, BeeError } from "./error.js";
3
3
  import { isFile } from "./file.js";
4
4
  import { assertHexString, assertPrefixedHexString, isHexString } from "./hex.js";
5
5
  import { isReadable } from "./stream.js";
6
+ import { decodeCid, encodeReference } from '@ethersphere/swarm-cid';
6
7
  export function isUint8Array(obj) {
7
8
  return obj instanceof Uint8Array;
8
9
  }
@@ -51,6 +52,10 @@ export function assertNonNegativeInteger(value, name = 'Value') {
51
52
  assertInteger(value, name);
52
53
  if (Number(value) < 0) throw new BeeArgumentError(`${name} has to be bigger or equal to zero`, value);
53
54
  }
55
+ export function assertPositiveInteger(value, name = 'Value') {
56
+ assertInteger(value, name);
57
+ if (Number(value) <= 0) throw new BeeArgumentError(`${name} has to be bigger then zero`, value);
58
+ }
54
59
  export function assertReference(value) {
55
60
  try {
56
61
  assertHexString(value, REFERENCE_HEX_LENGTH);
@@ -84,10 +89,24 @@ export function assertReferenceOrEns(value) {
84
89
  * ethswarm.something- - INVALID
85
90
  * ethswarm.-something - INVALID
86
91
  * ethswarm.some-thing - VALID
92
+ *
93
+ * The idea of this regex is to match strings that are 1 to 63 characters long and do not start or end with dash character
94
+ *
95
+ * This part matches 2-63 character string that does not start or end with -
96
+ * [^-.\/?:\s][^.\/?:\s]{0,61}[^-.\/?:\s] <regexp1>
97
+ *
98
+ * For 1 character long string we use the part after |
99
+ * [^-.\/?:\s] <regexp2>
100
+ *
101
+ * This is terminated in a group with . character an repeated at least once
102
+ * (<regexp1>|<regexp2>\.)+
103
+ *
104
+ * This covers everything but top level domain which is 2 to 63 characters long so we can just use the <regexp2> again
105
+ * ^(<regexp1>|<regexp2>\.)+<regexp1>$
87
106
  */
88
107
 
89
108
 
90
- const DOMAIN_REGEX = /^(?:(?!-)[^.\/?:\s]{1,63}(?<!-)\.)+(?!-)[^.\/?:\s]{2,63}(?<!-)$/; // We are doing best-effort validation of domain here. The proper way would be to do validation using IDNA UTS64 standard
109
+ const DOMAIN_REGEX = /^(?:(?:[^-.\/?:\s][^.\/?:\s]{0,61}[^-.\/?:\s]|[^-.\/?:\s]{1,2})\.)+[^-.\/?:\s][^.\/?:\s]{0,61}[^-.\/?:\s]$/; // We are doing best-effort validation of domain here. The proper way would be to do validation using IDNA UTS64 standard
91
110
  // but that would give us high penalty to our dependencies as the library (idna-uts46-hx) that does this validation and translation
92
111
  // adds 160kB minified size which is significant. We expects that full validation will be done on Bee side.
93
112
 
@@ -95,6 +114,49 @@ export function assertReferenceOrEns(value) {
95
114
  throw new TypeError('ReferenceOrEns is not valid Reference, but also not valid ENS domain.');
96
115
  }
97
116
  }
117
+ /**
118
+ * Function that mainly converts Swarm CID into hex encoded Swarm Reference
119
+ *
120
+ * @param value
121
+ * @param expectedCidType
122
+ */
123
+
124
+ export function makeReferenceOrEns(value, expectedCidType) {
125
+ var _a;
126
+
127
+ if (typeof value !== 'string') {
128
+ throw new TypeError('ReferenceCidOrEns has to be a string!');
129
+ }
130
+
131
+ try {
132
+ const result = decodeCid(value);
133
+
134
+ if (result.type !== expectedCidType) {
135
+ throw new BeeError(`CID was expected to be of type ${expectedCidType}, but got instead ${(_a = result.type) !== null && _a !== void 0 ? _a : 'non-Swarm CID'}`);
136
+ }
137
+
138
+ return result.reference;
139
+ } catch (e) {
140
+ if (e instanceof BeeError) throw e;
141
+ }
142
+
143
+ assertReferenceOrEns(value);
144
+ return value;
145
+ }
146
+ /**
147
+ * Function that adds getter which converts the reference into CID base32 encoded string.
148
+ * @param result
149
+ * @param cidType Type as described in the @ethersphere/swarm-cids-js -> ReferenceType
150
+ */
151
+
152
+ export function addCidConversionFunction(result, cidType) {
153
+ return Object.assign(Object.assign({}, result), {
154
+ get cid() {
155
+ return encodeReference(result.reference, cidType).toString();
156
+ }
157
+
158
+ });
159
+ }
98
160
  export function assertAddress(value) {
99
161
  assertHexString(value, ADDRESS_HEX_LENGTH, 'Address');
100
162
  }
@@ -258,6 +320,14 @@ export function assertPostageBatchOptions(value) {
258
320
  if ((options === null || options === void 0 ? void 0 : options.immutableFlag) !== undefined) {
259
321
  assertBoolean(options.immutableFlag);
260
322
  }
323
+
324
+ if ((options === null || options === void 0 ? void 0 : options.waitForUsable) !== undefined) {
325
+ assertBoolean(options.waitForUsable);
326
+ }
327
+
328
+ if ((options === null || options === void 0 ? void 0 : options.waitForUsableTimeout) !== undefined) {
329
+ assertNonNegativeInteger(options.waitForUsableTimeout, 'options.waitForUsableTimeout');
330
+ }
261
331
  }
262
332
  export function assertCashoutOptions(value) {
263
333
  if (value === undefined) {
@@ -1,4 +1,4 @@
1
- import type { Address, Peer, BalanceResponse, PeerBalance, ChequebookAddressResponse, ChequebookBalanceResponse, LastChequesResponse, LastChequesForPeerResponse, LastCashoutActionResponse, Settlements, AllSettlements, RemovePeerResponse, Topology, PingResponse, Health, NodeAddresses, ReserveState, ChainState, NumberString, ExtendedTag, PostageBatchBuckets, PostageBatch, TransactionInfo, TransactionHash, NodeInfo, BeeVersions } from './types';
1
+ import type { Address, Peer, BalanceResponse, PeerBalance, ChequebookAddressResponse, ChequebookBalanceResponse, LastChequesResponse, LastChequesForPeerResponse, LastCashoutActionResponse, Settlements, AllSettlements, RemovePeerResponse, Topology, PingResponse, Health, NodeAddresses, ReserveState, ChainState, NumberString, ExtendedTag, PostageBatchBuckets, PostageBatch, TransactionInfo, TransactionHash, NodeInfo, BeeVersions, WalletBalance } from './types';
2
2
  import { BatchId, BeeOptions, CashoutOptions, PostageBatchOptions, RequestOptions, Tag } from './types';
3
3
  export declare class BeeDebug {
4
4
  /**
@@ -181,6 +181,12 @@ export declare class BeeDebug {
181
181
  * Get chain state
182
182
  */
183
183
  getChainState(options?: RequestOptions): Promise<ChainState>;
184
+ /**
185
+ * Get wallet balances for xDai and BZZ of the Bee node
186
+ *
187
+ * @param options
188
+ */
189
+ getWalletBalance(options?: RequestOptions): Promise<WalletBalance>;
184
190
  /**
185
191
  * Creates new postage batch from the funds that the node has available in its Ethereum account.
186
192
  *
@@ -279,5 +285,6 @@ export declare class BeeDebug {
279
285
  * @param gasPrice
280
286
  */
281
287
  cancelPendingTransaction(transactionHash: TransactionHash | string, gasPrice?: NumberString, options?: RequestOptions): Promise<TransactionHash>;
288
+ private waitForUsablePostageStamp;
282
289
  private getKy;
283
290
  }
@@ -1,8 +1,8 @@
1
1
  import { Index, IndexBytes } from './feed';
2
2
  import { FeedType } from './feed/type';
3
3
  import { EthAddress } from './utils/eth';
4
- import { AllTagsOptions, Collection, Readable, ReferenceOrEns, RequestOptions, UploadResult } from './types';
5
- import type { Tag, FileData, Reference, UploadOptions, PublicKey, AddressPrefix, PssMessageHandler, PssSubscription, CollectionUploadOptions, FileUploadOptions, Data, Signer, FeedReader, FeedWriter, SOCWriter, SOCReader, Topic, BeeOptions, JsonFeedOptions, AnyJson, Pin, BatchId } from './types';
4
+ import type { AddressPrefix, AnyJson, BatchId, BeeOptions, CollectionUploadOptions, Data, FeedReader, FeedWriter, FileData, FileUploadOptions, JsonFeedOptions, Pin, PssMessageHandler, PssSubscription, PublicKey, Reference, Signer, SOCReader, SOCWriter, Tag, Topic, UploadOptions, UploadResultWithCid } from './types';
5
+ import { AllTagsOptions, Collection, Readable, ReferenceCidOrEns, ReferenceOrEns, RequestOptions, UploadResult } from './types';
6
6
  /**
7
7
  * The main component that abstracts operations available on the main Bee API.
8
8
  *
@@ -101,11 +101,11 @@ export declare class Bee {
101
101
  * @see [Bee API reference - `POST /bzz`](https://docs.ethswarm.org/api/#tag/File/paths/~1bzz/post)
102
102
  * @returns reference is a content hash of the file
103
103
  */
104
- uploadFile(postageBatchId: string | BatchId, data: string | Uint8Array | Readable | File, name?: string, options?: FileUploadOptions): Promise<UploadResult>;
104
+ uploadFile(postageBatchId: string | BatchId, data: string | Uint8Array | Readable | File, name?: string, options?: FileUploadOptions): Promise<UploadResultWithCid>;
105
105
  /**
106
106
  * Download single file.
107
107
  *
108
- * @param reference Bee file reference in hex string (either 64 or 128 chars long) or ENS domain.
108
+ * @param reference Bee file reference in hex string (either 64 or 128 chars long), ENS domain or Swarm CID.
109
109
  * @param path If reference points to manifest, then this parameter defines path to the file
110
110
  * @param options Options that affects the request behavior
111
111
  * @throws TypeError if some of the input parameters is not expected type
@@ -114,11 +114,11 @@ export declare class Bee {
114
114
  * @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/access-the-swarm/upload-and-download)
115
115
  * @see [Bee API reference - `GET /bzz`](https://docs.ethswarm.org/api/#tag/Collection/paths/~1bzz~1{reference}~1{path}/get)
116
116
  */
117
- downloadFile(reference: ReferenceOrEns | string, path?: string, options?: RequestOptions): Promise<FileData<Data>>;
117
+ downloadFile(reference: ReferenceCidOrEns | string, path?: string, options?: RequestOptions): Promise<FileData<Data>>;
118
118
  /**
119
119
  * Download single file as a readable stream
120
120
  *
121
- * @param reference Bee file reference in hex string (either 64 or 128 chars long) or ENS domain.
121
+ * @param reference Bee file reference in hex string (either 64 or 128 chars long), ENS domain or Swarm CID.
122
122
  * @param path If reference points to manifest / collections, then this parameter defines path to the file
123
123
  * @param options Options that affects the request behavior
124
124
  * @throws TypeError if some of the input parameters is not expected type
@@ -127,7 +127,7 @@ export declare class Bee {
127
127
  * @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/access-the-swarm/upload-and-download)
128
128
  * @see [Bee API reference - `GET /bzz`](https://docs.ethswarm.org/api/#tag/Collection/paths/~1bzz~1{reference}~1{path}/get)
129
129
  */
130
- downloadReadableFile(reference: ReferenceOrEns | string, path?: string, options?: RequestOptions): Promise<FileData<ReadableStream<Uint8Array>>>;
130
+ downloadReadableFile(reference: ReferenceCidOrEns | string, path?: string, options?: RequestOptions): Promise<FileData<ReadableStream<Uint8Array>>>;
131
131
  /**
132
132
  * Upload collection of files to a Bee node
133
133
  *
@@ -144,7 +144,7 @@ export declare class Bee {
144
144
  * @see [Bee docs - Upload directory](https://docs.ethswarm.org/docs/access-the-swarm/upload-a-directory/)
145
145
  * @see [Bee API reference - `POST /bzz`](https://docs.ethswarm.org/api/#tag/Collection/paths/~1bzz/post)
146
146
  */
147
- uploadFiles(postageBatchId: string | BatchId, fileList: FileList | File[], options?: CollectionUploadOptions): Promise<UploadResult>;
147
+ uploadFiles(postageBatchId: string | BatchId, fileList: FileList | File[], options?: CollectionUploadOptions): Promise<UploadResultWithCid>;
148
148
  /**
149
149
  * Upload Collection that you can assembly yourself.
150
150
  *
@@ -155,7 +155,7 @@ export declare class Bee {
155
155
  * @param collection
156
156
  * @param options Collections and request options
157
157
  */
158
- uploadCollection(postageBatchId: string | BatchId, collection: Collection<Uint8Array | Readable>, options?: CollectionUploadOptions): Promise<UploadResult>;
158
+ uploadCollection(postageBatchId: string | BatchId, collection: Collection<Uint8Array | Readable>, options?: CollectionUploadOptions): Promise<UploadResultWithCid>;
159
159
  /**
160
160
  * Upload collection of files.
161
161
  *
@@ -172,7 +172,7 @@ export declare class Bee {
172
172
  * @see [Bee docs - Upload directory](https://docs.ethswarm.org/docs/access-the-swarm/upload-a-directory/)
173
173
  * @see [Bee API reference - `POST /bzz`](https://docs.ethswarm.org/api/#tag/Collection/paths/~1bzz/post)
174
174
  */
175
- uploadFilesFromDirectory(postageBatchId: string | BatchId, dir: string, options?: CollectionUploadOptions): Promise<UploadResult>;
175
+ uploadFilesFromDirectory(postageBatchId: string | BatchId, dir: string, options?: CollectionUploadOptions): Promise<UploadResultWithCid>;
176
176
  /**
177
177
  * Create a new Tag which is meant for tracking progres of syncing data across network.
178
178
  *
@@ -411,6 +411,7 @@ export declare class Bee {
411
411
  *
412
412
  * @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/dapps-on-swarm/feeds)
413
413
  * @see [Bee API reference - `POST /feeds`](https://docs.ethswarm.org/api/#tag/Feed/paths/~1feeds~1{owner}~1{topic}/post)
414
+ * TODO: Once breaking add support for Feed CID
414
415
  */
415
416
  createFeedManifest(postageBatchId: string | BatchId, type: FeedType, topic: Topic | Uint8Array | string, owner: EthAddress | Uint8Array | string, options?: RequestOptions): Promise<Reference>;
416
417
  /**
@@ -1,4 +1,4 @@
1
- import { ChainState, Ky, ReserveState } from '../../types';
1
+ import { ChainState, Ky, ReserveState, WalletBalance } from '../../types';
2
2
  /**
3
3
  * Get state of reserve
4
4
  *
@@ -11,3 +11,9 @@ export declare function getReserveState(ky: Ky): Promise<ReserveState>;
11
11
  * @param ky Ky debug instance
12
12
  */
13
13
  export declare function getChainState(ky: Ky): Promise<ChainState>;
14
+ /**
15
+ * Get wallet balances for xDai and BZZ of the node
16
+ *
17
+ * @param ky Ky debug instance
18
+ */
19
+ export declare function getWalletBalance(ky: Ky): Promise<WalletBalance>;
@@ -215,3 +215,21 @@ export interface ChainState {
215
215
  totalAmount: NumberString;
216
216
  currentPrice: NumberString;
217
217
  }
218
+ export interface WalletBalance {
219
+ /**
220
+ * Balance of BZZ tokens
221
+ */
222
+ bzz: NumberString;
223
+ /**
224
+ * Balance of xDai
225
+ */
226
+ xDai: NumberString;
227
+ /**
228
+ * Chain network ID to which the Bee node is connected
229
+ */
230
+ chainID: number;
231
+ /**
232
+ * Chequebook contract address
233
+ */
234
+ contractAddress: string;
235
+ }
@@ -51,9 +51,12 @@ export declare const FEED_INDEX_HEX_LENGTH = 16;
51
51
  export declare type Reference = HexString<typeof REFERENCE_HEX_LENGTH> | HexString<typeof ENCRYPTED_REFERENCE_HEX_LENGTH>;
52
52
  /**
53
53
  * Type that represents either Swarm's reference in hex string or ESN domain (something.eth).
54
- * This is the type used on all the download functions.
55
54
  */
56
55
  export declare type ReferenceOrEns = Reference | string;
56
+ /**
57
+ * Type that represents either Swarm's reference in hex string, ESN domain (something.eth) or CID using one of the Swarm's codecs.
58
+ */
59
+ export declare type ReferenceCidOrEns = ReferenceOrEns | string;
57
60
  export declare type PlainBytesReference = Bytes<typeof REFERENCE_BYTES_LENGTH>;
58
61
  export declare type EncryptedBytesReference = Bytes<typeof ENCRYPTED_REFERENCE_BYTES_LENGTH>;
59
62
  export declare type BytesReference = PlainBytesReference | EncryptedBytesReference;
@@ -120,6 +123,9 @@ export interface BeeOptions extends RequestOptions {
120
123
  */
121
124
  onResponse?: HookCallback<BeeResponse>;
122
125
  }
126
+ export interface UploadResultWithCid extends UploadResult {
127
+ cid: string;
128
+ }
123
129
  /**
124
130
  * Result of upload calls.
125
131
  */
@@ -450,6 +456,22 @@ export interface PostageBatchOptions extends RequestOptions {
450
456
  */
451
457
  gasPrice?: NumberString;
452
458
  immutableFlag?: boolean;
459
+ /**
460
+ * The returned Promise will await until the purchased Postage Batch is usable.
461
+ * In other word, it has to have enough block confirmations that Bee pronounce it usable.
462
+ * If turned on, this significantly prolong the creation of postage batch!
463
+ * If you plan to use the stamp right away for some action with Bee (like uploading using this stamp) it is
464
+ * highly recommended to use this option, otherwise you might get errors "stamp not usable" from Bee.
465
+ *
466
+ * In next breaking release this option will be turned on by default.
467
+ * @default false
468
+ */
469
+ waitForUsable?: boolean;
470
+ /**
471
+ * When waiting for the postage stamp to become usable, this specify the timeout for the waiting.
472
+ * Default: 120s
473
+ */
474
+ waitForUsableTimeout?: number;
453
475
  }
454
476
  /**
455
477
  * With this type a number should be represented in a string
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Sleep for N miliseconds
3
+ *
4
+ * @param ms Number of miliseconds to sleep
5
+ */
6
+ export declare function sleep(ms: number): Promise<void>;
@@ -1,4 +1,5 @@
1
- import { Address, AddressPrefix, AllTagsOptions, BatchId, CollectionUploadOptions, FileUploadOptions, NumberString, PssMessageHandler, PublicKey, Readable, Reference, Tag, UploadOptions, TransactionHash, RequestOptions, PostageBatchOptions, CashoutOptions, ReferenceOrEns } from '../types';
1
+ import { Address, AddressPrefix, AllTagsOptions, BatchId, CollectionUploadOptions, FileUploadOptions, NumberString, PssMessageHandler, PublicKey, Readable, Reference, Tag, UploadOptions, TransactionHash, RequestOptions, PostageBatchOptions, CashoutOptions, ReferenceOrEns, UploadResult, UploadResultWithCid } from '../types';
2
+ import { ReferenceType } from '@ethersphere/swarm-cid';
2
3
  export declare function isUint8Array(obj: unknown): obj is Uint8Array;
3
4
  export declare function isInteger(value: unknown): value is number | NumberString;
4
5
  export declare function isObject(value: unknown): value is Record<string, unknown>;
@@ -22,8 +23,22 @@ export declare function assertStrictlyObject(value: unknown, name?: string): ass
22
23
  export declare function assertBoolean(value: unknown, name?: string): asserts value is boolean;
23
24
  export declare function assertInteger(value: unknown, name?: string): asserts value is number | NumberString;
24
25
  export declare function assertNonNegativeInteger(value: unknown, name?: string): asserts value is number | NumberString;
26
+ export declare function assertPositiveInteger(value: unknown, name?: string): asserts value is number | NumberString;
25
27
  export declare function assertReference(value: unknown): asserts value is Reference;
26
28
  export declare function assertReferenceOrEns(value: unknown): asserts value is ReferenceOrEns;
29
+ /**
30
+ * Function that mainly converts Swarm CID into hex encoded Swarm Reference
31
+ *
32
+ * @param value
33
+ * @param expectedCidType
34
+ */
35
+ export declare function makeReferenceOrEns(value: unknown, expectedCidType: ReferenceType): ReferenceOrEns;
36
+ /**
37
+ * Function that adds getter which converts the reference into CID base32 encoded string.
38
+ * @param result
39
+ * @param cidType Type as described in the @ethersphere/swarm-cids-js -> ReferenceType
40
+ */
41
+ export declare function addCidConversionFunction(result: UploadResult, cidType: ReferenceType): UploadResultWithCid;
27
42
  export declare function assertAddress(value: unknown): asserts value is Address;
28
43
  export declare function assertBatchId(value: unknown): asserts value is BatchId;
29
44
  export declare function assertRequestOptions(value: unknown, name?: string): asserts value is RequestOptions;