@ethersphere/bee-js 12.3.2-upcoming.116 → 13.0.0-upcoming.gc013bdf
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.
- package/dist/cjs/api/balance.js +24 -0
- package/dist/cjs/api/batches.js +26 -0
- package/dist/cjs/{modules → api}/bytes.js +4 -29
- package/dist/cjs/{modules → api}/bzz.js +6 -34
- package/dist/cjs/{modules/debug → api}/chequebook.js +48 -87
- package/dist/cjs/api/chunk.js +43 -0
- package/dist/cjs/api/connectivity.js +86 -0
- package/dist/cjs/api/consumed.js +24 -0
- package/dist/cjs/{modules → api}/envelope.js +3 -2
- package/dist/cjs/api/feed.js +55 -0
- package/dist/cjs/api/grantee.js +62 -0
- package/dist/cjs/{modules/pinning.js → api/pin.js} +13 -34
- package/dist/cjs/api/pss.js +19 -0
- package/dist/cjs/api/redistributionstate.js +17 -0
- package/dist/cjs/{modules/debug/settlements.js → api/settlement.js} +3 -11
- package/dist/cjs/api/soc.js +34 -0
- package/dist/cjs/{modules/debug → api}/stake.js +15 -43
- package/dist/cjs/{modules/debug/stamps.js → api/stamp.js} +41 -57
- package/dist/cjs/api/status.js +67 -0
- package/dist/cjs/{modules → api}/stewardship.js +1 -6
- package/dist/cjs/api/tag.js +51 -0
- package/dist/cjs/{modules/debug/transactions.js → api/transaction.js} +10 -31
- package/dist/cjs/{modules/debug/states.js → api/wallet.js} +4 -36
- package/dist/cjs/bee.js +115 -1978
- package/dist/cjs/chunk/soc.js +23 -65
- package/dist/cjs/feed/identifier.js +3 -4
- package/dist/cjs/feed/index.js +20 -22
- package/dist/cjs/feed/retrievable.js +3 -3
- package/dist/cjs/index.js +18 -8
- package/dist/cjs/manifest/manifest.js +99 -335
- package/dist/cjs/modules/balance.js +86 -0
- package/dist/cjs/modules/cheque.js +92 -0
- package/dist/cjs/modules/chequebook.js +90 -0
- package/dist/cjs/modules/chunk.js +87 -53
- package/dist/cjs/modules/collection.js +145 -0
- package/dist/cjs/modules/connectivity.js +141 -0
- package/dist/cjs/modules/context.js +2 -0
- package/dist/cjs/modules/data.js +119 -0
- package/dist/cjs/modules/feed.js +94 -70
- package/dist/cjs/modules/file.js +113 -0
- package/dist/cjs/modules/grantee.js +86 -55
- package/dist/cjs/modules/messaging.js +248 -0
- package/dist/cjs/modules/pin.js +100 -0
- package/dist/cjs/modules/settlement.js +67 -0
- package/dist/cjs/modules/soc.js +39 -36
- package/dist/cjs/modules/stake.js +110 -0
- package/dist/cjs/modules/stamp.js +199 -0
- package/dist/cjs/modules/status.js +128 -20
- package/dist/cjs/modules/storage.js +191 -0
- package/dist/cjs/modules/tag.js +97 -71
- package/dist/cjs/modules/transaction.js +92 -0
- package/dist/cjs/modules/wallet.js +82 -0
- package/dist/cjs/types/schema/chequebook.js +5 -5
- package/dist/cjs/types/schema/connectivity.js +5 -5
- package/dist/cjs/types/schema/envelope.js +5 -5
- package/dist/cjs/types/schema/grantee.js +4 -4
- package/dist/cjs/types/schema/stake.js +2 -2
- package/dist/cjs/types/schema/stamps.js +4 -4
- package/dist/cjs/types/schema/states.js +2 -2
- package/dist/cjs/types/schema/transactions.js +3 -3
- package/dist/cjs/types/schema/upload.js +2 -2
- package/dist/cjs/utils/chunk-stream.browser.js +24 -16
- package/dist/cjs/utils/chunk-stream.js +17 -9
- package/dist/cjs/utils/constants.js +3 -3
- package/dist/cjs/utils/expose.js +4 -4
- package/dist/cjs/utils/headers.js +4 -4
- package/dist/cjs/utils/pss.js +2 -2
- package/dist/cjs/utils/resource-locator.js +2 -2
- package/dist/cjs/utils/schema.js +4 -4
- package/dist/cjs/utils/stamps.js +15 -130
- package/dist/index.browser.min.js +2 -1
- package/dist/index.browser.min.js.LICENSE.txt +3 -0
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/api/balance.js +20 -0
- package/dist/mjs/api/batches.js +22 -0
- package/dist/mjs/{modules → api}/bytes.js +2 -27
- package/dist/mjs/{modules → api}/bzz.js +2 -30
- package/dist/mjs/{modules/debug → api}/chequebook.js +50 -89
- package/dist/mjs/api/chunk.js +37 -0
- package/dist/mjs/api/connectivity.js +76 -0
- package/dist/mjs/api/consumed.js +20 -0
- package/dist/mjs/{modules → api}/envelope.js +3 -2
- package/dist/mjs/api/feed.js +52 -0
- package/dist/mjs/api/grantee.js +59 -0
- package/dist/mjs/{modules/pinning.js → api/pin.js} +14 -35
- package/dist/mjs/api/pss.js +18 -0
- package/dist/mjs/api/redistributionstate.js +14 -0
- package/dist/mjs/{modules/debug/settlements.js → api/settlement.js} +3 -11
- package/dist/mjs/api/soc.js +31 -0
- package/dist/mjs/{modules/debug → api}/stake.js +14 -41
- package/dist/mjs/{modules/debug/stamps.js → api/stamp.js} +37 -51
- package/dist/mjs/api/status.js +59 -0
- package/dist/mjs/{modules → api}/stewardship.js +1 -6
- package/dist/mjs/api/tag.js +49 -0
- package/dist/mjs/api/transaction.js +41 -0
- package/dist/mjs/api/wallet.js +38 -0
- package/dist/mjs/bee.js +115 -1965
- package/dist/mjs/chunk/soc.js +13 -51
- package/dist/mjs/feed/identifier.js +2 -3
- package/dist/mjs/feed/index.js +9 -11
- package/dist/mjs/feed/retrievable.js +2 -2
- package/dist/mjs/index.js +2 -5
- package/dist/mjs/manifest/manifest.js +97 -341
- package/dist/mjs/modules/balance.js +49 -0
- package/dist/mjs/modules/cheque.js +55 -0
- package/dist/mjs/modules/chequebook.js +65 -0
- package/dist/mjs/modules/chunk.js +52 -49
- package/dist/mjs/modules/collection.js +108 -0
- package/dist/mjs/modules/connectivity.js +102 -0
- package/dist/mjs/modules/context.js +1 -0
- package/dist/mjs/modules/data.js +82 -0
- package/dist/mjs/modules/feed.js +89 -67
- package/dist/mjs/modules/file.js +78 -0
- package/dist/mjs/modules/grantee.js +52 -55
- package/dist/mjs/modules/messaging.js +213 -0
- package/dist/mjs/modules/pin.js +63 -0
- package/dist/mjs/modules/settlement.js +30 -0
- package/dist/mjs/modules/soc.js +36 -34
- package/dist/mjs/modules/stake.js +76 -0
- package/dist/mjs/modules/stamp.js +170 -0
- package/dist/mjs/modules/status.js +98 -18
- package/dist/mjs/modules/storage.js +185 -0
- package/dist/mjs/modules/tag.js +61 -68
- package/dist/mjs/modules/transaction.js +58 -0
- package/dist/mjs/modules/wallet.js +45 -0
- package/dist/mjs/types/schema/chequebook.js +1 -1
- package/dist/mjs/types/schema/connectivity.js +1 -1
- package/dist/mjs/types/schema/envelope.js +5 -5
- package/dist/mjs/types/schema/grantee.js +1 -1
- package/dist/mjs/types/schema/stake.js +1 -1
- package/dist/mjs/types/schema/stamps.js +1 -1
- package/dist/mjs/types/schema/states.js +1 -1
- package/dist/mjs/types/schema/transactions.js +1 -1
- package/dist/mjs/types/schema/upload.js +1 -1
- package/dist/mjs/utils/chunk-stream.browser.js +28 -18
- package/dist/mjs/utils/chunk-stream.js +21 -11
- package/dist/mjs/utils/constants.js +1 -1
- package/dist/mjs/utils/expose.js +1 -1
- package/dist/mjs/utils/headers.js +1 -1
- package/dist/mjs/utils/pss.js +1 -1
- package/dist/mjs/utils/resource-locator.js +1 -1
- package/dist/mjs/utils/schema.js +1 -1
- package/dist/mjs/utils/stamps.js +5 -99
- package/dist/types/api/balance.d.ts +7 -0
- package/dist/types/api/batches.d.ts +7 -0
- package/dist/types/api/bytes.d.ts +11 -0
- package/dist/types/api/bzz.d.ts +12 -0
- package/dist/types/api/chequebook.d.ts +21 -0
- package/dist/types/api/chunk.d.ts +7 -0
- package/dist/types/api/connectivity.d.ts +22 -0
- package/dist/types/api/consumed.d.ts +7 -0
- package/dist/types/{modules → api}/envelope.d.ts +1 -1
- package/dist/types/api/feed.d.ts +40 -0
- package/dist/types/api/grantee.d.ts +11 -0
- package/dist/types/api/pin.d.ts +10 -0
- package/dist/types/api/pss.d.ts +6 -0
- package/dist/types/api/redistributionstate.d.ts +5 -0
- package/dist/types/api/settlement.d.ts +7 -0
- package/dist/types/api/soc.d.ts +6 -0
- package/dist/types/api/stake.d.ts +11 -0
- package/dist/types/api/stamp.d.ts +12 -0
- package/dist/types/api/status.d.ts +11 -0
- package/dist/types/api/stewardship.d.ts +7 -0
- package/dist/types/api/tag.d.ts +12 -0
- package/dist/types/api/transaction.d.ts +9 -0
- package/dist/types/api/wallet.d.ts +9 -0
- package/dist/types/bee.d.ts +71 -1199
- package/dist/types/chunk/soc.d.ts +3 -48
- package/dist/types/feed/identifier.d.ts +1 -1
- package/dist/types/feed/index.d.ts +2 -4
- package/dist/types/feed/retrievable.d.ts +1 -1
- package/dist/types/index.d.ts +17 -20
- package/dist/types/manifest/manifest.d.ts +25 -34
- package/dist/types/modules/balance.d.ts +38 -0
- package/dist/types/modules/cheque.d.ts +40 -0
- package/dist/types/modules/chequebook.d.ts +41 -0
- package/dist/types/modules/chunk.d.ts +30 -20
- package/dist/types/modules/collection.d.ts +77 -0
- package/dist/types/modules/connectivity.d.ts +74 -0
- package/dist/types/modules/context.d.ts +24 -0
- package/dist/types/modules/data.d.ts +55 -0
- package/dist/types/modules/feed.d.ts +47 -49
- package/dist/types/modules/file.d.ts +43 -0
- package/dist/types/modules/grantee.d.ts +40 -8
- package/dist/types/modules/messaging.d.ts +79 -0
- package/dist/types/modules/pin.d.ts +47 -0
- package/dist/types/modules/settlement.d.ts +25 -0
- package/dist/types/modules/soc.d.ts +23 -11
- package/dist/types/modules/stake.d.ts +55 -0
- package/dist/types/modules/stamp.d.ts +96 -0
- package/dist/types/modules/status.d.ts +66 -5
- package/dist/types/modules/storage.d.ts +107 -0
- package/dist/types/modules/tag.d.ts +44 -33
- package/dist/types/modules/transaction.d.ts +42 -0
- package/dist/types/modules/wallet.d.ts +35 -0
- package/dist/types/types/debug.d.ts +1 -1
- package/dist/types/types/index.d.ts +3 -12
- package/dist/types/types/schema/chequebook.d.ts +1 -1
- package/dist/types/types/schema/connectivity.d.ts +1 -1
- package/dist/types/types/schema/grantee.d.ts +1 -1
- package/dist/types/types/schema/stake.d.ts +1 -1
- package/dist/types/types/schema/stamps.d.ts +1 -1
- package/dist/types/types/schema/states.d.ts +1 -1
- package/dist/types/types/schema/transactions.d.ts +1 -1
- package/dist/types/types/schema/upload.d.ts +1 -1
- package/dist/types/utils/chunk-stream.browser.d.ts +1 -1
- package/dist/types/utils/chunk-stream.d.ts +2 -2
- package/dist/types/utils/constants.d.ts +1 -1
- package/dist/types/utils/expose.d.ts +1 -1
- package/dist/types/utils/headers.d.ts +1 -1
- package/dist/types/utils/pss.d.ts +1 -1
- package/dist/types/utils/resource-locator.d.ts +1 -1
- package/dist/types/utils/schema.d.ts +1 -1
- package/dist/types/utils/stamps.d.ts +2 -27
- package/dist/types/utils/tar-uploader.browser.d.ts +1 -1
- package/dist/types/utils/tar-uploader.d.ts +1 -1
- package/package.json +4 -2
- package/dist/cjs/chunk/bmt.js +0 -37
- package/dist/cjs/chunk/cac.js +0 -43
- package/dist/cjs/modules/debug/balance.js +0 -60
- package/dist/cjs/modules/debug/connectivity.js +0 -54
- package/dist/cjs/modules/debug/status.js +0 -104
- package/dist/cjs/modules/gsoc.js +0 -23
- package/dist/cjs/modules/pss.js +0 -48
- package/dist/cjs/stamper/stamper.js +0 -44
- package/dist/cjs/utils/bytes.js +0 -116
- package/dist/cjs/utils/cid.js +0 -37
- package/dist/cjs/utils/redundancy.js +0 -133
- package/dist/cjs/utils/typed-bytes.js +0 -186
- package/dist/mjs/chunk/bmt.js +0 -34
- package/dist/mjs/chunk/cac.js +0 -34
- package/dist/mjs/modules/debug/balance.js +0 -54
- package/dist/mjs/modules/debug/connectivity.js +0 -46
- package/dist/mjs/modules/debug/states.js +0 -68
- package/dist/mjs/modules/debug/status.js +0 -99
- package/dist/mjs/modules/debug/transactions.js +0 -62
- package/dist/mjs/modules/gsoc.js +0 -16
- package/dist/mjs/modules/pss.js +0 -43
- package/dist/mjs/stamper/stamper.js +0 -40
- package/dist/mjs/utils/bytes.js +0 -102
- package/dist/mjs/utils/cid.js +0 -32
- package/dist/mjs/utils/redundancy.js +0 -98
- package/dist/mjs/utils/typed-bytes.js +0 -167
- package/dist/types/chunk/bmt.d.ts +0 -16
- package/dist/types/chunk/cac.d.ts +0 -40
- package/dist/types/modules/bytes.d.ts +0 -35
- package/dist/types/modules/bzz.d.ts +0 -40
- package/dist/types/modules/debug/balance.d.ts +0 -28
- package/dist/types/modules/debug/chequebook.d.ts +0 -60
- package/dist/types/modules/debug/connectivity.d.ts +0 -9
- package/dist/types/modules/debug/settlements.d.ts +0 -15
- package/dist/types/modules/debug/stake.d.ts +0 -30
- package/dist/types/modules/debug/stamps.d.ts +0 -11
- package/dist/types/modules/debug/states.d.ts +0 -23
- package/dist/types/modules/debug/status.d.ts +0 -46
- package/dist/types/modules/debug/transactions.d.ts +0 -30
- package/dist/types/modules/gsoc.d.ts +0 -6
- package/dist/types/modules/pinning.d.ts +0 -30
- package/dist/types/modules/pss.d.ts +0 -22
- package/dist/types/modules/stewardship.d.ts +0 -10
- package/dist/types/stamper/stamper.d.ts +0 -15
- package/dist/types/utils/bytes.d.ts +0 -19
- package/dist/types/utils/cid.d.ts +0 -10
- package/dist/types/utils/redundancy.d.ts +0 -21
- package/dist/types/utils/typed-bytes.d.ts +0 -69
- /package/dist/cjs/{modules → api}/rchash.js +0 -0
- /package/dist/mjs/{modules → api}/rchash.js +0 -0
- /package/dist/types/{modules → api}/rchash.d.ts +0 -0
package/dist/cjs/bee.js
CHANGED
|
@@ -1,81 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
3
|
exports.Bee = void 0;
|
|
37
4
|
const cafe_utility_1 = require("cafe-utility");
|
|
38
|
-
const
|
|
39
|
-
const
|
|
5
|
+
const swarm_core_1 = require("swarm-core");
|
|
6
|
+
const envelope_1 = require("./api/envelope");
|
|
7
|
+
const rchash_1 = require("./api/rchash");
|
|
40
8
|
const soc_1 = require("./chunk/soc");
|
|
41
|
-
const
|
|
42
|
-
const
|
|
43
|
-
const
|
|
44
|
-
const
|
|
45
|
-
const
|
|
46
|
-
const
|
|
47
|
-
const
|
|
48
|
-
const
|
|
49
|
-
const
|
|
50
|
-
const
|
|
51
|
-
const
|
|
52
|
-
const
|
|
53
|
-
const
|
|
54
|
-
const
|
|
55
|
-
const
|
|
56
|
-
const
|
|
57
|
-
const
|
|
58
|
-
const
|
|
59
|
-
const
|
|
60
|
-
const
|
|
61
|
-
const
|
|
62
|
-
const status = __importStar(require("./modules/status"));
|
|
63
|
-
const stewardship = __importStar(require("./modules/stewardship"));
|
|
64
|
-
const tag = __importStar(require("./modules/tag"));
|
|
65
|
-
const types_1 = require("./types");
|
|
66
|
-
const bytes_1 = require("./utils/bytes");
|
|
67
|
-
const chunk_stream_1 = require("./utils/chunk-stream");
|
|
68
|
-
const collection_1 = require("./utils/collection");
|
|
69
|
-
const collection_node_1 = require("./utils/collection.node");
|
|
70
|
-
const data_1 = require("./utils/data");
|
|
71
|
-
const error_1 = require("./utils/error");
|
|
72
|
-
const file_1 = require("./utils/file");
|
|
73
|
-
const resource_locator_1 = require("./utils/resource-locator");
|
|
9
|
+
const balance_1 = require("./modules/balance");
|
|
10
|
+
const cheque_1 = require("./modules/cheque");
|
|
11
|
+
const chequebook_1 = require("./modules/chequebook");
|
|
12
|
+
const chunk_1 = require("./modules/chunk");
|
|
13
|
+
const collection_1 = require("./modules/collection");
|
|
14
|
+
const connectivity_1 = require("./modules/connectivity");
|
|
15
|
+
const data_1 = require("./modules/data");
|
|
16
|
+
const feed_1 = require("./modules/feed");
|
|
17
|
+
const file_1 = require("./modules/file");
|
|
18
|
+
const grantee_1 = require("./modules/grantee");
|
|
19
|
+
const messaging_1 = require("./modules/messaging");
|
|
20
|
+
const pin_1 = require("./modules/pin");
|
|
21
|
+
const settlement_1 = require("./modules/settlement");
|
|
22
|
+
const soc_2 = require("./modules/soc");
|
|
23
|
+
const stake_1 = require("./modules/stake");
|
|
24
|
+
const stamp_1 = require("./modules/stamp");
|
|
25
|
+
const status_1 = require("./modules/status");
|
|
26
|
+
const storage_1 = require("./modules/storage");
|
|
27
|
+
const tag_1 = require("./modules/tag");
|
|
28
|
+
const transaction_1 = require("./modules/transaction");
|
|
29
|
+
const wallet_1 = require("./modules/wallet");
|
|
74
30
|
const schema_1 = require("./utils/schema");
|
|
75
|
-
const stamps_1 = require("./utils/stamps");
|
|
76
|
-
const tokens_1 = require("./utils/tokens");
|
|
77
|
-
const type_1 = require("./utils/type");
|
|
78
|
-
const typed_bytes_1 = require("./utils/typed-bytes");
|
|
79
31
|
const url_1 = require("./utils/url");
|
|
80
32
|
/**
|
|
81
33
|
* The main component that abstracts operations available on the Bee API.
|
|
@@ -97,7 +49,7 @@ class Bee {
|
|
|
97
49
|
(0, url_1.assertBeeUrl)(url);
|
|
98
50
|
this.url = (0, url_1.stripLastSlash)(url);
|
|
99
51
|
if (options?.signer) {
|
|
100
|
-
this.signer = new
|
|
52
|
+
this.signer = new swarm_core_1.PrivateKey(options.signer);
|
|
101
53
|
}
|
|
102
54
|
this.network = options?.network ?? 'gnosis';
|
|
103
55
|
this.requestOptions = {
|
|
@@ -108,1959 +60,144 @@ class Bee {
|
|
|
108
60
|
httpAgent: options?.httpAgent,
|
|
109
61
|
httpsAgent: options?.httpsAgent,
|
|
110
62
|
};
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
* @param options Additional options like tag, encryption, pinning, content-type and request options.
|
|
120
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
121
|
-
*
|
|
122
|
-
* @returns reference is a content hash of the data
|
|
123
|
-
*
|
|
124
|
-
* @see [Bee API reference - `POST /bytes`](https://docs.ethswarm.org/api/#tag/Bytes/paths/~1bytes/post)
|
|
125
|
-
* @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/develop/access-the-swarm/upload-and-download)
|
|
126
|
-
*/
|
|
127
|
-
async uploadData(postageBatchId, data, options, requestOptions) {
|
|
128
|
-
postageBatchId = new typed_bytes_1.BatchId(postageBatchId);
|
|
129
|
-
(0, type_1.assertData)(data);
|
|
130
|
-
if (options) {
|
|
131
|
-
options = schema_1.RedundantUploadOptionsSchema.parse(options);
|
|
132
|
-
}
|
|
133
|
-
return bytes.upload(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, options);
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Fetches content length for a `/bytes` reference.
|
|
137
|
-
*
|
|
138
|
-
* @param reference
|
|
139
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
140
|
-
*
|
|
141
|
-
* @see [Bee API reference - `HEAD /bytes/{reference}`](https://docs.ethswarm.org/api/#tag/Bytes/paths/~1bytes~1%7Breference%7D/head)
|
|
142
|
-
*/
|
|
143
|
-
async probeData(reference, requestOptions) {
|
|
144
|
-
reference = new typed_bytes_1.Reference(reference);
|
|
145
|
-
return bytes.head(this.getRequestOptionsForCall(requestOptions), reference);
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* Downloads raw data through the `GET /bytes/{reference}` endpoint.
|
|
149
|
-
*
|
|
150
|
-
* This method may be used to download data that was uploaded with the {@link uploadData} method.
|
|
151
|
-
*
|
|
152
|
-
* For downloading files or using the `GET /bzz/{reference}/` endpoint, use the {@link downloadFile} method instead.
|
|
153
|
-
* For downloading chunks or using the `GET /chunks/{reference} endpoint, use the `downloadChunk` method instead.
|
|
154
|
-
*
|
|
155
|
-
* @param resource Swarm reference, Swarm CID, or ENS domain.
|
|
156
|
-
* @param options Options that affects the request behavior
|
|
157
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
158
|
-
*
|
|
159
|
-
* @throws TypeError if some of the input parameters is not expected type
|
|
160
|
-
* @throws BeeArgumentError if there is passed ENS domain with invalid unicode characters
|
|
161
|
-
*
|
|
162
|
-
* @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/develop/access-the-swarm/upload-and-download)
|
|
163
|
-
* @see [Bee API reference - `GET /bytes`](https://docs.ethswarm.org/api/#tag/Bytes/paths/~1bytes~1{reference}/get)
|
|
164
|
-
*/
|
|
165
|
-
async downloadData(resource, options, requestOptions) {
|
|
166
|
-
if (options) {
|
|
167
|
-
options = schema_1.DownloadOptionsSchema.parse(options);
|
|
168
|
-
}
|
|
169
|
-
return bytes.download(this.getRequestOptionsForCall(requestOptions), new resource_locator_1.ResourceLocator(resource), options);
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Download raw data through the `GET /bytes/{reference}` endpoint.
|
|
173
|
-
*
|
|
174
|
-
* This method may be used to download data that was uploaded with the {@link uploadData} method.
|
|
175
|
-
*
|
|
176
|
-
* Only tested in Node.js environment.
|
|
177
|
-
*
|
|
178
|
-
* @param resource Swarm reference, Swarm CID, or ENS domain.
|
|
179
|
-
* @param options Options that affects the request behavior.
|
|
180
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
181
|
-
*
|
|
182
|
-
* @returns ReadableStream of Uint8Array
|
|
183
|
-
*
|
|
184
|
-
* @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/develop/access-the-swarm/upload-and-download)
|
|
185
|
-
* @see [Bee API reference - `GET /bytes`](https://docs.ethswarm.org/api/#tag/Bytes/paths/~1bytes~1{reference}/get)
|
|
186
|
-
*/
|
|
187
|
-
async downloadReadableData(resource, options, requestOptions) {
|
|
188
|
-
if (options) {
|
|
189
|
-
options = schema_1.DownloadOptionsSchema.parse(options);
|
|
190
|
-
}
|
|
191
|
-
return bytes.downloadReadable(this.getRequestOptionsForCall(requestOptions), new resource_locator_1.ResourceLocator(resource), options);
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* Uploads a chunk to the network.
|
|
195
|
-
*
|
|
196
|
-
* Chunks uploaded with this method should be retrieved with the {@link downloadChunk} method.
|
|
197
|
-
*
|
|
198
|
-
* @param stamp Postage Batch ID or an Envelope created with the {@link createEnvelope} method.
|
|
199
|
-
* @param data Raw chunk to be uploaded (Content Addressed Chunk or Single Owner Chunk)
|
|
200
|
-
* @param options Additional options like tag, encryption, pinning, content-type and request options
|
|
201
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
202
|
-
*
|
|
203
|
-
* @returns reference is a content hash of the data
|
|
204
|
-
* @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/develop/access-the-swarm/upload-and-download)
|
|
205
|
-
* @see [Bee API reference - `POST /chunks`](https://docs.ethswarm.org/api/#tag/Chunk/paths/~1chunks/post)
|
|
206
|
-
*/
|
|
207
|
-
async uploadChunk(stamp, data, options, requestOptions) {
|
|
208
|
-
const isSOC = 'identifier' in data && 'signature' in data && 'owner' in data;
|
|
209
|
-
data = data instanceof Uint8Array ? data : data.data;
|
|
210
|
-
if (options) {
|
|
211
|
-
options = schema_1.UploadOptionsSchema.parse(options);
|
|
212
|
-
}
|
|
213
|
-
if (data.length < typed_bytes_1.Span.LENGTH) {
|
|
214
|
-
throw new error_1.BeeArgumentError(`Chunk has to have size of at least ${typed_bytes_1.Span.LENGTH}.`, data);
|
|
215
|
-
}
|
|
216
|
-
if (!isSOC && data.length > types_1.CHUNK_SIZE + typed_bytes_1.Span.LENGTH) {
|
|
217
|
-
throw new error_1.BeeArgumentError(`Content Addressed Chunk must not exceed ${types_1.CHUNK_SIZE + typed_bytes_1.Span.LENGTH} bytes.`, data);
|
|
218
|
-
}
|
|
219
|
-
if (isSOC && data.length > types_1.CHUNK_SIZE + typed_bytes_1.Span.LENGTH + typed_bytes_1.Signature.LENGTH + typed_bytes_1.Identifier.LENGTH) {
|
|
220
|
-
throw new error_1.BeeArgumentError(`Single Owner Chunk must not exceed ${types_1.CHUNK_SIZE + typed_bytes_1.Span.LENGTH + typed_bytes_1.Signature.LENGTH + typed_bytes_1.Identifier.LENGTH} bytes.`, data);
|
|
221
|
-
}
|
|
222
|
-
return chunk.upload(this.getRequestOptionsForCall(requestOptions), data, stamp, options);
|
|
223
|
-
}
|
|
224
|
-
/**
|
|
225
|
-
* Downloads a chunk as a `Uint8Array`.
|
|
226
|
-
*
|
|
227
|
-
* May be used to download chunks uploaded with the {@link uploadChunk} method.
|
|
228
|
-
*
|
|
229
|
-
* Use {@link downloadData} method to download raw data uploaded with the {@link uploadData} method.
|
|
230
|
-
* Use {@link downloadFile} method to download files uploaded with the {@link uploadFile} method.
|
|
231
|
-
*
|
|
232
|
-
* @param reference Bee chunk reference in hex string (either 64 or 128 chars long) or ENS domain.
|
|
233
|
-
* @param options Options that affects the request behavior
|
|
234
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
235
|
-
*
|
|
236
|
-
* @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/develop/access-the-swarm/upload-and-download)
|
|
237
|
-
* @see [Bee API reference - `GET /chunks`](https://docs.ethswarm.org/api/#tag/Chunk/paths/~1chunks~1{address}/get)
|
|
238
|
-
*/
|
|
239
|
-
async downloadChunk(reference, options, requestOptions) {
|
|
240
|
-
reference = new typed_bytes_1.Reference(reference);
|
|
241
|
-
if (options) {
|
|
242
|
-
options = schema_1.DownloadOptionsSchema.parse(options);
|
|
243
|
-
}
|
|
244
|
-
return chunk.download(this.getRequestOptionsForCall(requestOptions), reference, options);
|
|
245
|
-
}
|
|
246
|
-
/**
|
|
247
|
-
* Create a grantees list from the given array of public keys.
|
|
248
|
-
*
|
|
249
|
-
* The grantees list can be obtained with the {@link getGrantees} method.
|
|
250
|
-
*
|
|
251
|
-
* @param postageBatchId - The ID of the postage batch.
|
|
252
|
-
* @param grantees - An array of public keys representing the grantees.
|
|
253
|
-
* @param requestOptions - Optional request options.
|
|
254
|
-
* @returns A promise that resolves to a `GranteesResult` object.
|
|
255
|
-
*/
|
|
256
|
-
async createGrantees(postageBatchId, grantees, requestOptions) {
|
|
257
|
-
postageBatchId = new typed_bytes_1.BatchId(postageBatchId);
|
|
258
|
-
grantees = grantees.map(x => new typed_bytes_1.PublicKey(x));
|
|
259
|
-
return grantee.createGrantees(this.getRequestOptionsForCall(requestOptions), postageBatchId, grantees);
|
|
260
|
-
}
|
|
261
|
-
/**
|
|
262
|
-
* Retrieves the grantees for a given reference.
|
|
263
|
-
*
|
|
264
|
-
* @param reference - The reference.
|
|
265
|
-
* @param requestOptions - Optional request options.
|
|
266
|
-
* @returns A promise that resolves to a `GetGranteesResult` object.
|
|
267
|
-
*/
|
|
268
|
-
async getGrantees(reference, requestOptions) {
|
|
269
|
-
reference = new typed_bytes_1.Reference(reference);
|
|
270
|
-
return grantee.getGrantees(reference, this.getRequestOptionsForCall(requestOptions));
|
|
271
|
-
}
|
|
272
|
-
/**
|
|
273
|
-
* Updates the grantees of a specific reference and history.
|
|
274
|
-
*
|
|
275
|
-
* @param reference - The reference.
|
|
276
|
-
* @param history - The history.
|
|
277
|
-
* @param postageBatchId - The ID of the postage batch.
|
|
278
|
-
* @param grantees - The grantees.
|
|
279
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
280
|
-
* @returns A Promise that resolves to to a `GranteesResult` object.
|
|
281
|
-
*/
|
|
282
|
-
async patchGrantees(postageBatchId, reference, history, grantees, requestOptions) {
|
|
283
|
-
postageBatchId = new typed_bytes_1.BatchId(postageBatchId);
|
|
284
|
-
reference = new typed_bytes_1.Reference(reference);
|
|
285
|
-
history = new typed_bytes_1.Reference(history);
|
|
286
|
-
const publicKeys = {
|
|
287
|
-
add: grantees.add?.map(x => new typed_bytes_1.PublicKey(x)) ?? [],
|
|
288
|
-
revoke: grantees.revoke?.map(x => new typed_bytes_1.PublicKey(x)) ?? [],
|
|
63
|
+
// Facade handed to each module (namespace) class, exposing only the shared
|
|
64
|
+
// state and helpers they need — without widening the public `bee.` surface.
|
|
65
|
+
const context = {
|
|
66
|
+
getRequestOptionsForCall: requestOptions => this.getRequestOptionsForCall(requestOptions),
|
|
67
|
+
url: this.url,
|
|
68
|
+
signer: this.signer,
|
|
69
|
+
network: this.network,
|
|
70
|
+
bee: this,
|
|
289
71
|
};
|
|
290
|
-
|
|
72
|
+
this.balance = new balance_1.Balance(context);
|
|
73
|
+
this.settlement = new settlement_1.Settlement(context);
|
|
74
|
+
this.transaction = new transaction_1.Transaction(context);
|
|
75
|
+
this.stake = new stake_1.Stake(context);
|
|
76
|
+
this.connectivity = new connectivity_1.Connectivity(context);
|
|
77
|
+
this.status = new status_1.Status(context);
|
|
78
|
+
this.wallet = new wallet_1.Wallet(context);
|
|
79
|
+
this.stamp = new stamp_1.Stamp(context);
|
|
80
|
+
this.storage = new storage_1.Storage(context);
|
|
81
|
+
this.chequebook = new chequebook_1.Chequebook(context);
|
|
82
|
+
this.cheque = new cheque_1.Cheque(context);
|
|
83
|
+
this.tag = new tag_1.Tag(context);
|
|
84
|
+
this.pin = new pin_1.Pin(context);
|
|
85
|
+
this.grantee = new grantee_1.Grantee(context);
|
|
86
|
+
this.messaging = new messaging_1.Messaging(context);
|
|
87
|
+
this.feed = new feed_1.Feed(context);
|
|
88
|
+
this.soc = new soc_2.Soc(context);
|
|
89
|
+
this.data = new data_1.Data(context);
|
|
90
|
+
this.chunk = new chunk_1.Chunk(context);
|
|
91
|
+
this.file = new file_1.File(context);
|
|
92
|
+
this.collection = new collection_1.Collection(context);
|
|
291
93
|
}
|
|
292
94
|
/**
|
|
293
|
-
*
|
|
294
|
-
*
|
|
295
|
-
* To download the file, use the {@link downloadFile} method.
|
|
296
|
-
*
|
|
297
|
-
* Use {@link uploadData} method to upload raw data that can be downloaded with the {@link downloadData} method.
|
|
298
|
-
* Use {@link uploadChunk} method to upload chunks that can be downloaded with the {@link downloadChunk} method.
|
|
299
|
-
*
|
|
300
|
-
* @param postageBatchId Postage BatchId to be used to upload the data with
|
|
301
|
-
* @param data Data or file to be uploaded
|
|
302
|
-
* @param name Optional name of the uploaded file
|
|
303
|
-
* @param options Additional options like tag, encryption, pinning, content-type and request options
|
|
304
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
95
|
+
* Creates a Content Addressed Chunk.
|
|
305
96
|
*
|
|
306
|
-
*
|
|
307
|
-
* @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/develop/access-the-swarm/upload-and-download)
|
|
308
|
-
* @see [Bee API reference - `POST /bzz`](https://docs.ethswarm.org/api/#tag/BZZ/paths/~1bzz/post)
|
|
309
|
-
* @returns reference is a content hash of the file
|
|
310
|
-
*/
|
|
311
|
-
async uploadFile(postageBatchId, data, name, options, requestOptions) {
|
|
312
|
-
postageBatchId = new typed_bytes_1.BatchId(postageBatchId);
|
|
313
|
-
(0, type_1.assertFileData)(data);
|
|
314
|
-
if (options) {
|
|
315
|
-
options = schema_1.FileUploadOptionsSchema.parse(options);
|
|
316
|
-
}
|
|
317
|
-
if (name && typeof name !== 'string') {
|
|
318
|
-
throw new TypeError('name has to be string or undefined!');
|
|
319
|
-
}
|
|
320
|
-
if ((0, file_1.isFile)(data)) {
|
|
321
|
-
const fileData = await (0, file_1.fileArrayBuffer)(data);
|
|
322
|
-
const fileName = name ?? data.name;
|
|
323
|
-
const contentType = data.type;
|
|
324
|
-
const fileOptions = { ...options, contentType };
|
|
325
|
-
return bzz.uploadFile(this.getRequestOptionsForCall(requestOptions), fileData, postageBatchId, fileName, fileOptions);
|
|
326
|
-
}
|
|
327
|
-
else {
|
|
328
|
-
return bzz.uploadFile(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, name, options);
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
/**
|
|
332
|
-
* Downloads a single file.
|
|
97
|
+
* To be uploaded with the {@link uploadChunk} method.
|
|
333
98
|
*
|
|
334
|
-
*
|
|
335
|
-
* @param path If reference points to manifest, then this parameter defines path to the file
|
|
336
|
-
* @param options Options that affects the request behavior
|
|
337
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
99
|
+
* Payload size must be between 1 and 4096 bytes.
|
|
338
100
|
*
|
|
339
|
-
* @
|
|
340
|
-
* @
|
|
101
|
+
* @param rawPayload Data to be stored in the chunk. If the data is a string, it will be converted to UTF-8 bytes.
|
|
102
|
+
* @param span Optional span for the chunk. If not provided, it will be set to the length of the payload.
|
|
341
103
|
*/
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
options = schema_1.DownloadOptionsSchema.parse(options);
|
|
345
|
-
}
|
|
346
|
-
return bzz.downloadFile(this.getRequestOptionsForCall(requestOptions), new resource_locator_1.ResourceLocator(resource), path, options);
|
|
104
|
+
makeContentAddressedChunk(rawPayload, span) {
|
|
105
|
+
return (0, swarm_core_1.makeContentAddressedChunk)(rawPayload, span);
|
|
347
106
|
}
|
|
348
107
|
/**
|
|
349
|
-
*
|
|
350
|
-
*
|
|
351
|
-
* @param reference Bee file reference in hex string (either 64 or 128 chars long), ENS domain or Swarm CID.
|
|
352
|
-
* @param path If reference points to manifest / collections, then this parameter defines path to the file
|
|
353
|
-
* @param options Options that affects the request behavior
|
|
354
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
108
|
+
* Attempts to unmarshal arbitrary data into a Content Addressed Chunk.
|
|
109
|
+
* Throws an error if the data is not a valid CAC.
|
|
355
110
|
*
|
|
356
|
-
* @
|
|
357
|
-
* @see [Bee API reference - `GET /bzz`](https://docs.ethswarm.org/api/#tag/BZZ/paths/~1bzz~1%7Breference%7D~1%7Bpath%7D/get)
|
|
111
|
+
* @param data The chunk data (`span` and `payload`)
|
|
358
112
|
*/
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
if (options) {
|
|
362
|
-
options = schema_1.DownloadOptionsSchema.parse(options);
|
|
363
|
-
}
|
|
364
|
-
return bzz.downloadFileReadable(this.getRequestOptionsForCall(requestOptions), reference, path, options);
|
|
113
|
+
unmarshalContentAddressedChunk(data) {
|
|
114
|
+
return (0, swarm_core_1.unmarshalContentAddressedChunk)(data);
|
|
365
115
|
}
|
|
366
116
|
/**
|
|
367
|
-
*
|
|
368
|
-
*
|
|
369
|
-
* Uses the FileList API from the browser.
|
|
370
|
-
*
|
|
371
|
-
* The returned `UploadResult.tag` might be undefined if called in CORS-enabled environment.
|
|
372
|
-
* This will be fixed upon next Bee release. https://github.com/ethersphere/bee-js/issues/406
|
|
373
|
-
*
|
|
374
|
-
* @param postageBatchId Postage BatchId to be used to upload the data with
|
|
375
|
-
* @param fileList list of files to be uploaded
|
|
376
|
-
* @param options Additional options like tag, encryption, pinning and request options
|
|
377
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
117
|
+
* Creates a Single Owner Chunk.
|
|
378
118
|
*
|
|
379
|
-
*
|
|
380
|
-
* @see [Bee docs - Upload directory](https://docs.ethswarm.org/docs/develop/access-the-swarm/upload-and-download#upload-a-directory)
|
|
381
|
-
* @see [Bee API reference - `POST /bzz`](https://docs.ethswarm.org/api/#tag/BZZ/paths/~1bzz/post)
|
|
382
|
-
*/
|
|
383
|
-
async uploadFiles(postageBatchId, fileList, options, requestOptions) {
|
|
384
|
-
postageBatchId = new typed_bytes_1.BatchId(postageBatchId);
|
|
385
|
-
if (options) {
|
|
386
|
-
options = schema_1.CollectionUploadOptionsSchema.parse(options);
|
|
387
|
-
}
|
|
388
|
-
const data = (0, collection_1.makeCollectionFromFileList)(fileList);
|
|
389
|
-
return bzz.uploadCollection(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, options);
|
|
390
|
-
}
|
|
391
|
-
/**
|
|
392
|
-
* Hashes a directory locally and returns the root hash (Swarm reference).
|
|
119
|
+
* To be uploaded with the {@link uploadChunk} method.
|
|
393
120
|
*
|
|
394
|
-
*
|
|
395
|
-
* For example, metadata may have different casing, or the order of metadata may differ.
|
|
396
|
-
* Such small differences will result in different Swarm references.
|
|
121
|
+
* Identical to chaining `makeContentAddressedChunk` and `toSingleOwnerChunk`.
|
|
397
122
|
*
|
|
398
|
-
*
|
|
123
|
+
* Payload size must be between 1 and 4096 bytes.
|
|
399
124
|
*
|
|
400
|
-
* @param
|
|
401
|
-
* @
|
|
125
|
+
* @param address Address of the Content Addressed Chunk
|
|
126
|
+
* @param span Span of the Content Addressed Chunk
|
|
127
|
+
* @param payload Payload of the Content Addressed Chunk
|
|
128
|
+
* @param identifier The identifier of the chunk
|
|
129
|
+
* @param signer The signer interface for signing the chunk
|
|
402
130
|
*/
|
|
403
|
-
|
|
404
|
-
return (0,
|
|
131
|
+
makeSingleOwnerChunk(address, span, payload, identifier, signer) {
|
|
132
|
+
return (0, soc_1.makeSingleOwnerChunk)(address, span, payload, identifier, signer);
|
|
405
133
|
}
|
|
406
134
|
/**
|
|
407
|
-
*
|
|
408
|
-
* this method streams the directory contents directly to the Bee node, which supports arbitrary directory sizes,
|
|
409
|
-
* but may be slower due to uploading chunks one by one.
|
|
410
|
-
*
|
|
411
|
-
* Options such as encryption, erasure coding and ACT are not yet available for this method.
|
|
412
|
-
*
|
|
413
|
-
* Only intended for the Node.js environment.
|
|
135
|
+
* Calculates the address of a Single Owner Chunk based on its identifier and owner address.
|
|
414
136
|
*
|
|
415
|
-
* @param
|
|
416
|
-
* @param
|
|
417
|
-
* @param onUploadProgress
|
|
418
|
-
* @param options
|
|
419
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
420
|
-
* @returns
|
|
137
|
+
* @param identifier
|
|
138
|
+
* @param address
|
|
421
139
|
*/
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
return (0, chunk_stream_1.streamDirectory)(this, dir, postageBatchId, onUploadProgress, options, this.getRequestOptionsForCall(requestOptions));
|
|
140
|
+
calculateSingleOwnerChunkAddress(identifier, address) {
|
|
141
|
+
return (0, soc_1.makeSOCAddress)(identifier, address);
|
|
425
142
|
}
|
|
426
143
|
/**
|
|
427
|
-
*
|
|
428
|
-
*
|
|
429
|
-
* but may be slower due to uploading chunks one by one.
|
|
430
|
-
*
|
|
431
|
-
* Options such as encryption, erasure coding and ACT are not yet available for this method.
|
|
144
|
+
* Attempts to unmarshal arbitrary data into a Single Owner Chunk.
|
|
145
|
+
* Throws an error if the data is not a valid SOC.
|
|
432
146
|
*
|
|
433
|
-
*
|
|
147
|
+
* @param data The chunk data
|
|
148
|
+
* @param address The address of the single owner chunk
|
|
434
149
|
*
|
|
435
|
-
* @
|
|
436
|
-
* @param files
|
|
437
|
-
* @param onUploadProgress
|
|
438
|
-
* @param options
|
|
439
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
440
|
-
* @returns
|
|
150
|
+
* @returns a single owner chunk or throws error
|
|
441
151
|
*/
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
return (0, chunk_stream_1.streamFiles)(this, files, postageBatchId, onUploadProgress, options, this.getRequestOptionsForCall(requestOptions));
|
|
152
|
+
unmarshalSingleOwnerChunk(data, address) {
|
|
153
|
+
return (0, soc_1.unmarshalSingleOwnerChunk)(data, address);
|
|
445
154
|
}
|
|
446
155
|
/**
|
|
447
|
-
*
|
|
156
|
+
* Creates the postage batch signature for a specific chunk address.
|
|
448
157
|
*
|
|
449
|
-
*
|
|
450
|
-
*
|
|
158
|
+
* This is for advanced usage, where a pre-signed chunk can be uploaded
|
|
159
|
+
* through a different Bee node.
|
|
451
160
|
*
|
|
452
161
|
* @param postageBatchId
|
|
453
|
-
* @param
|
|
454
|
-
* @param options Collections and request options
|
|
455
|
-
*/
|
|
456
|
-
async uploadCollection(postageBatchId, collection, options, requestOptions) {
|
|
457
|
-
postageBatchId = new typed_bytes_1.BatchId(postageBatchId);
|
|
458
|
-
(0, collection_1.assertCollection)(collection);
|
|
459
|
-
if (options) {
|
|
460
|
-
options = schema_1.CollectionUploadOptionsSchema.parse(options);
|
|
461
|
-
}
|
|
462
|
-
return bzz.uploadCollection(this.getRequestOptionsForCall(requestOptions), collection, postageBatchId, options);
|
|
463
|
-
}
|
|
464
|
-
/**
|
|
465
|
-
* Upload collection of files.
|
|
466
|
-
*
|
|
467
|
-
* Available only in Node.js as it uses the `fs` module.
|
|
468
|
-
*
|
|
469
|
-
* The returned `UploadResult.tag` might be undefined if called in CORS-enabled environment.
|
|
470
|
-
* This will be fixed upon next Bee release. https://github.com/ethersphere/bee-js/issues/406
|
|
471
|
-
*
|
|
472
|
-
* @param postageBatchId Postage BatchId to be used to upload the data with
|
|
473
|
-
* @param dir the path of the files to be uploaded
|
|
474
|
-
* @param options Additional options like tag, encryption, pinning and request options
|
|
475
|
-
*
|
|
476
|
-
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
|
|
477
|
-
* @see [Bee docs - Upload directory](https://docs.ethswarm.org/docs/develop/access-the-swarm/upload-and-download#upload-a-directory)
|
|
478
|
-
* @see [Bee API reference - `POST /bzz`](https://docs.ethswarm.org/api/#tag/BZZ/paths/~1bzz/post)
|
|
479
|
-
*/
|
|
480
|
-
async uploadFilesFromDirectory(postageBatchId, dir, options, requestOptions) {
|
|
481
|
-
postageBatchId = new typed_bytes_1.BatchId(postageBatchId);
|
|
482
|
-
if (options) {
|
|
483
|
-
options = schema_1.CollectionUploadOptionsSchema.parse(options);
|
|
484
|
-
}
|
|
485
|
-
const data = await (0, collection_node_1.makeCollectionFromFS)(dir);
|
|
486
|
-
return bzz.uploadCollection(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, options);
|
|
487
|
-
}
|
|
488
|
-
/**
|
|
489
|
-
* Creates a new Tag which is meant for tracking upload and synchronization progress.
|
|
490
|
-
*
|
|
491
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
492
|
-
*
|
|
493
|
-
* @see [Bee docs - Syncing / Tags](https://docs.ethswarm.org/docs/develop/access-the-swarm/syncing)
|
|
494
|
-
* @see [Bee API reference - `POST /tags`](https://docs.ethswarm.org/api/#tag/Tag/paths/~1tags/post)
|
|
495
|
-
*/
|
|
496
|
-
async createTag(requestOptions) {
|
|
497
|
-
return tag.createTag(this.getRequestOptionsForCall(requestOptions));
|
|
498
|
-
}
|
|
499
|
-
/**
|
|
500
|
-
* Fetches all tags in a paginated manner.
|
|
501
|
-
*
|
|
502
|
-
* The listing is limited by options.limit. So you have to iterate using options.offset to get all tags.
|
|
503
|
-
*
|
|
504
|
-
* @param options Specify `limit` and `offset` to paginate through the tags.
|
|
505
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
506
|
-
*
|
|
507
|
-
* @see [Bee docs - Syncing / Tags](https://docs.ethswarm.org/docs/develop/access-the-swarm/syncing)
|
|
508
|
-
* @see [Bee API reference - `GET /tags`](https://docs.ethswarm.org/api/#tag/Tag/paths/~1tags/get)
|
|
509
|
-
*/
|
|
510
|
-
async getAllTags(options, requestOptions) {
|
|
511
|
-
if (options) {
|
|
512
|
-
options = schema_1.AllTagsOptionsSchema.parse(options);
|
|
513
|
-
}
|
|
514
|
-
return tag.getAllTags(this.getRequestOptionsForCall(requestOptions), options?.offset, options?.limit);
|
|
515
|
-
}
|
|
516
|
-
/**
|
|
517
|
-
* Retrieves tag information from Bee node.
|
|
518
|
-
*
|
|
519
|
-
* @param tagUid UID or tag object to be retrieved
|
|
520
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
521
|
-
*
|
|
522
|
-
* @see [Bee docs - Syncing / Tags](https://docs.ethswarm.org/docs/develop/access-the-swarm/syncing)
|
|
523
|
-
* @see [Bee API reference - `GET /tags/{uid}`](https://docs.ethswarm.org/api/#tag/Tag/paths/~1tags~1{uid}/get)
|
|
524
|
-
*
|
|
525
|
-
*/
|
|
526
|
-
async retrieveTag(tagUid, requestOptions) {
|
|
527
|
-
tagUid = (0, type_1.makeTagUid)(tagUid);
|
|
528
|
-
return tag.retrieveTag(this.getRequestOptionsForCall(requestOptions), tagUid);
|
|
529
|
-
}
|
|
530
|
-
/**
|
|
531
|
-
* Deletes Tag.
|
|
532
|
-
*
|
|
533
|
-
* @param tagUid UID or tag object to be retrieved
|
|
534
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
535
|
-
*
|
|
536
|
-
* @see [Bee docs - Syncing / Tags](https://docs.ethswarm.org/docs/develop/access-the-swarm/syncing)
|
|
537
|
-
* @see [Bee API reference - `DELETE /tags/{uid}`](https://docs.ethswarm.org/api/#tag/Tag/paths/~1tags~1{uid}/delete)
|
|
538
|
-
*/
|
|
539
|
-
async deleteTag(tagUid, requestOptions) {
|
|
540
|
-
tagUid = (0, type_1.makeTagUid)(tagUid);
|
|
541
|
-
return tag.deleteTag(this.getRequestOptionsForCall(requestOptions), tagUid);
|
|
542
|
-
}
|
|
543
|
-
/**
|
|
544
|
-
* Update tag's total chunks count.
|
|
545
|
-
*
|
|
546
|
-
* This is important if you are uploading individual chunks with a tag. Then upon finishing the final root chunk,
|
|
547
|
-
* you can use this method to update the total chunks count for the tag.
|
|
548
|
-
*
|
|
549
|
-
* @param tagUid UID or tag object to be retrieved
|
|
550
|
-
* @param reference The root reference that contains all the chunks to be counted
|
|
551
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
552
|
-
*
|
|
553
|
-
* @see [Bee docs - Syncing / Tags](https://docs.ethswarm.org/docs/develop/access-the-swarm/syncing)
|
|
554
|
-
* @see [Bee API reference - `PATCH /tags/{uid}`](https://docs.ethswarm.org/api/#tag/Tag/paths/~1tags~1{uid}/patch)
|
|
555
|
-
*/
|
|
556
|
-
async updateTag(tagUid, reference, requestOptions) {
|
|
557
|
-
reference = new typed_bytes_1.Reference(reference);
|
|
558
|
-
tagUid = (0, type_1.makeTagUid)(tagUid);
|
|
559
|
-
return tag.updateTag(this.getRequestOptionsForCall(requestOptions), tagUid, reference);
|
|
560
|
-
}
|
|
561
|
-
/**
|
|
562
|
-
* Pins local data with given reference.
|
|
563
|
-
*
|
|
564
|
-
* @param reference Data reference
|
|
565
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
566
|
-
*
|
|
567
|
-
* @see [Bee docs - Pinning](https://docs.ethswarm.org/docs/develop/access-the-swarm/pinning)
|
|
568
|
-
*/
|
|
569
|
-
async pin(reference, requestOptions) {
|
|
570
|
-
reference = new typed_bytes_1.Reference(reference);
|
|
571
|
-
return pinning.pin(this.getRequestOptionsForCall(requestOptions), reference);
|
|
572
|
-
}
|
|
573
|
-
/**
|
|
574
|
-
* Unpins local data with given reference.
|
|
575
|
-
*
|
|
576
|
-
* @param reference Data reference
|
|
577
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
578
|
-
*
|
|
579
|
-
* @see [Bee docs - Pinning](https://docs.ethswarm.org/docs/develop/access-the-swarm/pinning)
|
|
580
|
-
*/
|
|
581
|
-
async unpin(reference, requestOptions) {
|
|
582
|
-
reference = new typed_bytes_1.Reference(reference);
|
|
583
|
-
return pinning.unpin(this.getRequestOptionsForCall(requestOptions), reference);
|
|
584
|
-
}
|
|
585
|
-
/**
|
|
586
|
-
* Gets list of all locally pinned references.
|
|
587
|
-
*
|
|
588
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
589
|
-
*
|
|
590
|
-
* @see [Bee docs - Pinning](https://docs.ethswarm.org/docs/develop/access-the-swarm/pinning)
|
|
591
|
-
*/
|
|
592
|
-
async getAllPins(requestOptions) {
|
|
593
|
-
return pinning.getAllPins(this.getRequestOptionsForCall(requestOptions));
|
|
594
|
-
}
|
|
595
|
-
/**
|
|
596
|
-
* Get pinning status of chunk with given reference
|
|
597
|
-
*
|
|
598
|
-
* @param reference Bee data reference in hex string (either 64 or 128 chars long) or ENS domain.
|
|
599
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
600
|
-
*
|
|
601
|
-
* @see [Bee docs - Pinning](https://docs.ethswarm.org/docs/develop/access-the-swarm/pinning)
|
|
602
|
-
*/
|
|
603
|
-
async getPin(reference, requestOptions) {
|
|
604
|
-
reference = new typed_bytes_1.Reference(reference);
|
|
605
|
-
return pinning.getPin(this.getRequestOptionsForCall(requestOptions), reference);
|
|
606
|
-
}
|
|
607
|
-
/**
|
|
608
|
-
* Instructs the Bee node to reupload a locally pinned data into the network.
|
|
609
|
-
*
|
|
610
|
-
* @param postageBatchId Postage Batch ID that will be used to re-upload the data.
|
|
611
|
-
* @param reference Bee data reference to be re-uploaded in hex string (either 64 or 128 chars long) or ENS domain.
|
|
612
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
613
|
-
*
|
|
614
|
-
* @see [Bee API reference - `PUT /stewardship`](https://docs.ethswarm.org/api/#tag/Stewardship/paths/~1stewardship~1{reference}/put)
|
|
615
|
-
*/
|
|
616
|
-
async reuploadPinnedData(postageBatchId, reference, requestOptions) {
|
|
617
|
-
postageBatchId = new typed_bytes_1.BatchId(postageBatchId);
|
|
618
|
-
reference = new typed_bytes_1.Reference(reference);
|
|
619
|
-
await stewardship.reupload(this.getRequestOptionsForCall(requestOptions), postageBatchId, reference);
|
|
620
|
-
}
|
|
621
|
-
/**
|
|
622
|
-
* Checks if content specified by reference is retrievable from the network.
|
|
623
|
-
*
|
|
624
|
-
* @param reference Bee data reference to be checked in hex string (either 64 or 128 chars long) or ENS domain.
|
|
162
|
+
* @param reference
|
|
625
163
|
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
626
164
|
*
|
|
627
|
-
* @
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
reference = new typed_bytes_1.Reference(reference);
|
|
631
|
-
return stewardship.isRetrievable(this.getRequestOptionsForCall(requestOptions), reference);
|
|
632
|
-
}
|
|
633
|
-
/**
|
|
634
|
-
* Functions that validate if feed is retrievable in the network.
|
|
635
|
-
*
|
|
636
|
-
* If no index is passed then it check for "latest" update, which is a weaker guarantee as nobody can be really
|
|
637
|
-
* sure what is the "latest" update.
|
|
638
|
-
*
|
|
639
|
-
* If index is passed then it validates all previous sequence index chunks if they are available as they are required
|
|
640
|
-
* to correctly resolve the feed upto the given index update.
|
|
165
|
+
* @example
|
|
166
|
+
* const envelope = await bee.createEnvelope(batchId, chunk.address)
|
|
167
|
+
* await bee.chunk.upload(envelope, chunk)
|
|
641
168
|
*
|
|
642
|
-
* @
|
|
643
|
-
* @param owner
|
|
644
|
-
* @param topic
|
|
645
|
-
* @param index
|
|
646
|
-
* @param options
|
|
647
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
169
|
+
* @returns
|
|
648
170
|
*/
|
|
649
|
-
async
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
options = schema_1.DownloadOptionsSchema.parse(options);
|
|
654
|
-
}
|
|
655
|
-
if (!index) {
|
|
656
|
-
try {
|
|
657
|
-
await this.makeFeedReader(topic, owner, requestOptions).download();
|
|
658
|
-
return true;
|
|
659
|
-
}
|
|
660
|
-
catch (e) {
|
|
661
|
-
const status = cafe_utility_1.Objects.getDeep(e, 'status');
|
|
662
|
-
if (status === 404 || status === 500) {
|
|
663
|
-
return false;
|
|
664
|
-
}
|
|
665
|
-
throw e;
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
return (0, retrievable_1.areAllSequentialFeedsUpdateRetrievable)(this, owner, topic, index, options, this.getRequestOptionsForCall(requestOptions));
|
|
171
|
+
async createEnvelope(postageBatchId, reference, requestOptions) {
|
|
172
|
+
postageBatchId = new swarm_core_1.BatchId(postageBatchId);
|
|
173
|
+
reference = new swarm_core_1.Reference(reference);
|
|
174
|
+
return (0, envelope_1.postEnvelope)(this.getRequestOptionsForCall(requestOptions), postageBatchId, reference);
|
|
669
175
|
}
|
|
670
176
|
/**
|
|
671
|
-
*
|
|
177
|
+
* Gets reserve commitment hash duration seconds.
|
|
672
178
|
*
|
|
673
|
-
*
|
|
674
|
-
*
|
|
675
|
-
* most likely for setting up an encrypted communication
|
|
676
|
-
* channel by sending an one-off message.
|
|
179
|
+
* To be able to participe in the storage incentives and not get frozen, this should
|
|
180
|
+
* ideally run under 5 minutes.
|
|
677
181
|
*
|
|
678
|
-
*
|
|
182
|
+
* This is a CPU intensice operation, as roughly 2^22 chunks are hashed in the process.
|
|
679
183
|
*
|
|
680
|
-
* @param postageBatchId Postage BatchId that will be assigned to sent message
|
|
681
|
-
* @param topic Topic name
|
|
682
|
-
* @param target Target message address prefix. Has a limit on length. Recommend to use `Utils.Pss.makeMaxTarget()` to get the most specific target that Bee node will accept.
|
|
683
|
-
* @param data Message to be sent
|
|
684
|
-
* @param recipient Recipient public key
|
|
685
184
|
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
686
185
|
*
|
|
687
|
-
* @
|
|
688
|
-
*
|
|
186
|
+
* @example
|
|
187
|
+
* const addresses = await bee.connectivity.getNodeAddresses()
|
|
188
|
+
* const topology = await bee.connectivity.getTopology()
|
|
189
|
+
* const result = await bee.rchash(topology.depth, addresses.overlay.toHex(), addresses.overlay.toHex())
|
|
190
|
+
* // result is a number of seconds
|
|
689
191
|
*/
|
|
690
|
-
async
|
|
691
|
-
|
|
692
|
-
(0, type_1.assertData)(data);
|
|
693
|
-
if (recipient) {
|
|
694
|
-
recipient = new typed_bytes_1.PublicKey(recipient);
|
|
695
|
-
return pss.send(this.getRequestOptionsForCall(requestOptions), topic, target, data, postageBatchId, recipient);
|
|
696
|
-
}
|
|
697
|
-
else {
|
|
698
|
-
return pss.send(this.getRequestOptionsForCall(requestOptions), topic, target, data, postageBatchId);
|
|
699
|
-
}
|
|
192
|
+
async rchash(depth, anchor1, anchor2, requestOptions) {
|
|
193
|
+
return (0, rchash_1.rchash)(this.getRequestOptionsForCall(requestOptions), depth, anchor1, anchor2);
|
|
700
194
|
}
|
|
701
195
|
/**
|
|
702
|
-
*
|
|
703
|
-
*
|
|
704
|
-
* **Warning! Only full nodes can accept PSS messages.**
|
|
196
|
+
* Merges per-call request options with the instance defaults.
|
|
705
197
|
*
|
|
706
|
-
*
|
|
707
|
-
*
|
|
708
|
-
*
|
|
709
|
-
* @returns Subscription to a given topic
|
|
710
|
-
*
|
|
711
|
-
* @see [Bee docs - PSS](https://docs.ethswarm.org/docs/develop/tools-and-features/pss)
|
|
712
|
-
* @see [Bee API reference - `GET /pss`](https://docs.ethswarm.org/api/#tag/Postal-Service-for-Swarm/paths/~1pss~1subscribe~1{topic}/get)
|
|
198
|
+
* Stays `protected`; module namespaces reach it only through the {@link BeeContext}
|
|
199
|
+
* facade they are constructed with, so it never widens the public `bee.` surface.
|
|
713
200
|
*/
|
|
714
|
-
pssSubscribe(topic, handler) {
|
|
715
|
-
handler = schema_1.PssMessageHandlerSchema.parse(handler);
|
|
716
|
-
const ws = pss.subscribe(this.url, topic, this.requestOptions.headers);
|
|
717
|
-
let cancelled = false;
|
|
718
|
-
const cancel = () => {
|
|
719
|
-
if (!cancelled) {
|
|
720
|
-
cancelled = true;
|
|
721
|
-
if (ws.terminate) {
|
|
722
|
-
ws.terminate();
|
|
723
|
-
}
|
|
724
|
-
else {
|
|
725
|
-
ws.close();
|
|
726
|
-
}
|
|
727
|
-
}
|
|
728
|
-
};
|
|
729
|
-
const subscription = {
|
|
730
|
-
topic,
|
|
731
|
-
cancel,
|
|
732
|
-
};
|
|
733
|
-
ws.onmessage = async (event) => {
|
|
734
|
-
const data = await (0, data_1.prepareWebsocketData)(event.data);
|
|
735
|
-
if (data.length) {
|
|
736
|
-
handler.onMessage(new bytes_1.Bytes(data), subscription);
|
|
737
|
-
}
|
|
738
|
-
};
|
|
739
|
-
ws.onerror = event => {
|
|
740
|
-
if (!cancelled) {
|
|
741
|
-
handler.onError(new error_1.BeeError(event.message), subscription);
|
|
742
|
-
}
|
|
743
|
-
};
|
|
744
|
-
ws.onclose = () => {
|
|
745
|
-
handler.onClose(subscription);
|
|
746
|
-
};
|
|
747
|
-
return subscription;
|
|
748
|
-
}
|
|
749
|
-
/**
|
|
750
|
-
* Receives message using the Postal Service for Swarm.
|
|
751
|
-
*
|
|
752
|
-
* This is a helper function to wait for exactly one message to
|
|
753
|
-
* arrive and then cancel the subscription. Additionally a
|
|
754
|
-
* timeout can be provided for the message to arrive or else
|
|
755
|
-
* an error will be thrown.
|
|
756
|
-
*
|
|
757
|
-
* **Warning! Only full nodes can accept PSS messages.**
|
|
758
|
-
*
|
|
759
|
-
* @param topic Topic name
|
|
760
|
-
* @param timeoutMsec Timeout in milliseconds
|
|
761
|
-
*
|
|
762
|
-
* @returns Message in byte array
|
|
763
|
-
*
|
|
764
|
-
* @see [Bee docs - PSS](https://docs.ethswarm.org/docs/develop/tools-and-features/pss)
|
|
765
|
-
* @see [Bee API reference - `GET /pss`](https://docs.ethswarm.org/api/#tag/Postal-Service-for-Swarm/paths/~1pss~1subscribe~1{topic}/get)
|
|
766
|
-
*/
|
|
767
|
-
async pssReceive(topic, timeoutMsec = 0) {
|
|
768
|
-
if (typeof timeoutMsec !== 'number') {
|
|
769
|
-
throw new TypeError('timeoutMsc parameter has to be a number!');
|
|
770
|
-
}
|
|
771
|
-
return new Promise((resolve, reject) => {
|
|
772
|
-
let timeout;
|
|
773
|
-
const subscription = this.pssSubscribe(topic, {
|
|
774
|
-
onError: error => {
|
|
775
|
-
clearTimeout(timeout);
|
|
776
|
-
subscription.cancel();
|
|
777
|
-
reject(error.message);
|
|
778
|
-
},
|
|
779
|
-
onMessage: message => {
|
|
780
|
-
clearTimeout(timeout);
|
|
781
|
-
subscription.cancel();
|
|
782
|
-
resolve(message);
|
|
783
|
-
},
|
|
784
|
-
onClose: () => {
|
|
785
|
-
clearTimeout(timeout);
|
|
786
|
-
subscription.cancel();
|
|
787
|
-
},
|
|
788
|
-
});
|
|
789
|
-
if (timeoutMsec > 0) {
|
|
790
|
-
timeout = setTimeout(() => {
|
|
791
|
-
subscription.cancel();
|
|
792
|
-
reject(new error_1.BeeError('pssReceive timeout'));
|
|
793
|
-
}, timeoutMsec);
|
|
794
|
-
}
|
|
795
|
-
});
|
|
796
|
-
}
|
|
797
|
-
/**
|
|
798
|
-
* Mines the signer (a private key) to be used to send GSOC messages to the specific target overlay address.
|
|
799
|
-
*
|
|
800
|
-
* Use {@link gsocSend} to send GSOC messages with the mined signer.
|
|
801
|
-
*
|
|
802
|
-
* Use {@link gsocSubscribe} to subscribe to GSOC messages for the specified owner (of the signer) and identifier.
|
|
803
|
-
*
|
|
804
|
-
* See {@link gsocSend} or {@link gsocSubscribe} for concrete examples of usage.
|
|
805
|
-
*
|
|
806
|
-
* **Warning! Only full nodes can accept GSOC messages.**
|
|
807
|
-
*
|
|
808
|
-
* @param targetOverlay
|
|
809
|
-
* @param identifier
|
|
810
|
-
* @param proximity
|
|
811
|
-
* @returns
|
|
812
|
-
*/
|
|
813
|
-
gsocMine(targetOverlay, identifier, proximity = 12) {
|
|
814
|
-
targetOverlay = new typed_bytes_1.PeerAddress(targetOverlay);
|
|
815
|
-
identifier = new typed_bytes_1.Identifier(identifier);
|
|
816
|
-
const start = 0xb33n;
|
|
817
|
-
for (let i = 0n; i < 0xffffn; i++) {
|
|
818
|
-
const signer = new typed_bytes_1.PrivateKey(cafe_utility_1.Binary.numberToUint256(start + i, 'BE'));
|
|
819
|
-
const socAddress = (0, soc_1.makeSOCAddress)(identifier, signer.publicKey().address());
|
|
820
|
-
// TODO: test the significance of the hardcoded 256
|
|
821
|
-
const actualProximity = 256 - cafe_utility_1.Binary.proximity(socAddress.toUint8Array(), targetOverlay.toUint8Array());
|
|
822
|
-
if (actualProximity <= 256 - proximity) {
|
|
823
|
-
return signer;
|
|
824
|
-
}
|
|
825
|
-
}
|
|
826
|
-
throw Error('Could not mine a valid signer');
|
|
827
|
-
}
|
|
828
|
-
/**
|
|
829
|
-
* Sends a GSOC message with the specified signer and identifier.
|
|
830
|
-
*
|
|
831
|
-
* Use {@link gsocMine} to mine a signer for the target overlay address.
|
|
832
|
-
*
|
|
833
|
-
* Use {@link gsocSubscribe} to subscribe to GSOC messages for the specified owner (of the signer) and identifier.
|
|
834
|
-
*
|
|
835
|
-
* **Warning! Only full nodes can accept GSOC messages.**
|
|
836
|
-
*
|
|
837
|
-
* @param postageBatchId
|
|
838
|
-
* @param signer
|
|
839
|
-
* @param identifier
|
|
840
|
-
* @param data
|
|
841
|
-
* @param options
|
|
842
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
843
|
-
* @returns
|
|
844
|
-
*
|
|
845
|
-
* @example
|
|
846
|
-
* const identifier = NULL_IDENTIFIER
|
|
847
|
-
* const overlay = '0x1234567890123456789012345678901234567890'
|
|
848
|
-
* const signer = bee.gsocMine(overlay, identifier)
|
|
849
|
-
* await bee.gsocSend(postageBatchId, signer, identifier, 'GSOC!')
|
|
850
|
-
*/
|
|
851
|
-
async gsocSend(postageBatchId, signer, identifier, data, options, requestOptions) {
|
|
852
|
-
postageBatchId = new typed_bytes_1.BatchId(postageBatchId);
|
|
853
|
-
signer = new typed_bytes_1.PrivateKey(signer);
|
|
854
|
-
identifier = new typed_bytes_1.Identifier(identifier);
|
|
855
|
-
const cac = (0, cac_1.makeContentAddressedChunk)(data);
|
|
856
|
-
const soc = cac.toSingleOwnerChunk(identifier, signer);
|
|
857
|
-
return gsoc.send(this.getRequestOptionsForCall(requestOptions), soc, postageBatchId, options);
|
|
858
|
-
}
|
|
859
|
-
/**
|
|
860
|
-
* Subscribes to GSOC messages for the specified owner (of the signer) and identifier.
|
|
861
|
-
*
|
|
862
|
-
* Use {@link gsocMine} to mine a signer for the target overlay address.
|
|
863
|
-
*
|
|
864
|
-
* Use {@link gsocSend} to send GSOC messages with the mined signer.
|
|
865
|
-
*
|
|
866
|
-
* **Warning! Only full nodes can accept GSOC messages.**
|
|
867
|
-
*
|
|
868
|
-
* @param address
|
|
869
|
-
* @param identifier
|
|
870
|
-
* @param handler
|
|
871
|
-
* @returns
|
|
872
|
-
*
|
|
873
|
-
* @example
|
|
874
|
-
* const identifier = NULL_IDENTIFIER
|
|
875
|
-
* const { overlay } = await bee.getNodeAddresses()
|
|
876
|
-
* const signer = bee.gsocMine(overlay, identifier)
|
|
877
|
-
*
|
|
878
|
-
* const subscription = bee.gsocSubscribe(signer.publicKey().address(), identifier, {
|
|
879
|
-
* onMessage(message) {
|
|
880
|
-
* // handle
|
|
881
|
-
* },
|
|
882
|
-
* onError(error) {
|
|
883
|
-
* // handle
|
|
884
|
-
* },
|
|
885
|
-
* onClose() {
|
|
886
|
-
* // handle
|
|
887
|
-
* }
|
|
888
|
-
* })
|
|
889
|
-
*/
|
|
890
|
-
gsocSubscribe(address, identifier, handler) {
|
|
891
|
-
address = new typed_bytes_1.EthAddress(address);
|
|
892
|
-
identifier = new typed_bytes_1.Identifier(identifier);
|
|
893
|
-
handler = schema_1.GsocMessageHandlerSchema.parse(handler);
|
|
894
|
-
const socAddress = (0, soc_1.makeSOCAddress)(identifier, address);
|
|
895
|
-
const ws = gsoc.subscribe(this.url, socAddress, this.requestOptions.headers);
|
|
896
|
-
let cancelled = false;
|
|
897
|
-
const cancel = () => {
|
|
898
|
-
if (!cancelled) {
|
|
899
|
-
cancelled = true;
|
|
900
|
-
if (ws.terminate) {
|
|
901
|
-
ws.terminate();
|
|
902
|
-
}
|
|
903
|
-
else {
|
|
904
|
-
ws.close();
|
|
905
|
-
}
|
|
906
|
-
}
|
|
907
|
-
};
|
|
908
|
-
const subscription = {
|
|
909
|
-
address,
|
|
910
|
-
cancel,
|
|
911
|
-
};
|
|
912
|
-
ws.onmessage = async (event) => {
|
|
913
|
-
const data = await (0, data_1.prepareWebsocketData)(event.data);
|
|
914
|
-
if (data.length) {
|
|
915
|
-
handler.onMessage(new bytes_1.Bytes(data), subscription);
|
|
916
|
-
}
|
|
917
|
-
};
|
|
918
|
-
ws.onerror = event => {
|
|
919
|
-
if (!cancelled) {
|
|
920
|
-
handler.onError(new error_1.BeeError(event.message), subscription);
|
|
921
|
-
}
|
|
922
|
-
};
|
|
923
|
-
ws.onclose = () => {
|
|
924
|
-
handler.onClose(subscription);
|
|
925
|
-
};
|
|
926
|
-
return subscription;
|
|
927
|
-
}
|
|
928
|
-
/**
|
|
929
|
-
* Creates a feed manifest chunk and returns the reference to it.
|
|
930
|
-
*
|
|
931
|
-
* Feed manifest chunks allow for a feed to be able to be resolved through `/bzz` endpoint.
|
|
932
|
-
*
|
|
933
|
-
* @param postageBatchId Postage BatchId to be used to create the Feed Manifest
|
|
934
|
-
* @param topic Topic in hex or bytes
|
|
935
|
-
* @param owner Owner's ethereum address in hex or bytes
|
|
936
|
-
* @param options Options that affects the request behavior
|
|
937
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
938
|
-
*
|
|
939
|
-
* @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/develop/tools-and-features/feeds)
|
|
940
|
-
* @see [Bee API reference - `POST /feeds`](https://docs.ethswarm.org/api/#tag/Feed/paths/~1feeds~1{owner}~1{topic}/post)
|
|
941
|
-
*/
|
|
942
|
-
async createFeedManifest(postageBatchId, topic, owner, options, requestOptions) {
|
|
943
|
-
postageBatchId = new typed_bytes_1.BatchId(postageBatchId);
|
|
944
|
-
topic = new typed_bytes_1.Topic(topic);
|
|
945
|
-
owner = new typed_bytes_1.EthAddress(owner);
|
|
946
|
-
if (options) {
|
|
947
|
-
options = schema_1.UploadOptionsSchema.parse(options);
|
|
948
|
-
}
|
|
949
|
-
return (0, feed_2.createFeedManifest)(this.getRequestOptionsForCall(requestOptions), owner, topic, postageBatchId, options);
|
|
950
|
-
}
|
|
951
|
-
/**
|
|
952
|
-
* Makes a new feed reader for downloading feed updates.
|
|
953
|
-
*
|
|
954
|
-
* @param topic Topic in hex or bytes
|
|
955
|
-
* @param owner Owner's ethereum address in hex or bytes
|
|
956
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
957
|
-
*
|
|
958
|
-
* @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/develop/tools-and-features/feeds)
|
|
959
|
-
*/
|
|
960
|
-
makeFeedReader(topic, owner, requestOptions) {
|
|
961
|
-
topic = new typed_bytes_1.Topic(topic);
|
|
962
|
-
owner = new typed_bytes_1.EthAddress(owner);
|
|
963
|
-
return (0, feed_1.makeFeedReader)(this.getRequestOptionsForCall(requestOptions), topic, owner);
|
|
964
|
-
}
|
|
965
|
-
/**
|
|
966
|
-
* Makes a new feed writer for updating feeds
|
|
967
|
-
*
|
|
968
|
-
* @param topic Topic in hex or bytes
|
|
969
|
-
* @param signer The signer's private key or a Signer instance that can sign data
|
|
970
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
971
|
-
*
|
|
972
|
-
* @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/develop/tools-and-features/feeds)
|
|
973
|
-
*/
|
|
974
|
-
makeFeedWriter(topic, signer, requestOptions) {
|
|
975
|
-
topic = new typed_bytes_1.Topic(topic);
|
|
976
|
-
signer = signer ? new typed_bytes_1.PrivateKey(signer) : this.signer;
|
|
977
|
-
if (!signer) {
|
|
978
|
-
throw Error('No signer provided');
|
|
979
|
-
}
|
|
980
|
-
return (0, feed_1.makeFeedWriter)(this.getRequestOptionsForCall(requestOptions), topic, signer);
|
|
981
|
-
}
|
|
982
|
-
async fetchLatestFeedUpdate(topic, owner, requestOptions) {
|
|
983
|
-
topic = new typed_bytes_1.Topic(topic);
|
|
984
|
-
owner = new typed_bytes_1.EthAddress(owner);
|
|
985
|
-
return (0, feed_2.fetchLatestFeedUpdate)(this.getRequestOptionsForCall(requestOptions), owner, topic);
|
|
986
|
-
}
|
|
987
|
-
/**
|
|
988
|
-
* Creates a Content Addressed Chunk.
|
|
989
|
-
*
|
|
990
|
-
* To be uploaded with the {@link uploadChunk} method.
|
|
991
|
-
*
|
|
992
|
-
* Payload size must be between 1 and 4096 bytes.
|
|
993
|
-
*
|
|
994
|
-
* @param rawPayload Data to be stored in the chunk. If the data is a string, it will be converted to UTF-8 bytes.
|
|
995
|
-
* @param span Optional span for the chunk. If not provided, it will be set to the length of the payload.
|
|
996
|
-
*/
|
|
997
|
-
makeContentAddressedChunk(rawPayload, span) {
|
|
998
|
-
return (0, cac_1.makeContentAddressedChunk)(rawPayload, span);
|
|
999
|
-
}
|
|
1000
|
-
/**
|
|
1001
|
-
* Attempts to unmarshal arbitrary data into a Content Addressed Chunk.
|
|
1002
|
-
* Throws an error if the data is not a valid CAC.
|
|
1003
|
-
*
|
|
1004
|
-
* @param data The chunk data (`span` and `payload`)
|
|
1005
|
-
*/
|
|
1006
|
-
unmarshalContentAddressedChunk(data) {
|
|
1007
|
-
return (0, cac_1.unmarshalContentAddressedChunk)(data);
|
|
1008
|
-
}
|
|
1009
|
-
/**
|
|
1010
|
-
* Creates a Single Owner Chunk.
|
|
1011
|
-
*
|
|
1012
|
-
* To be uploaded with the {@link uploadChunk} method.
|
|
1013
|
-
*
|
|
1014
|
-
* Identical to chaining `makeContentAddressedChunk` and `toSingleOwnerChunk`.
|
|
1015
|
-
*
|
|
1016
|
-
* Payload size must be between 1 and 4096 bytes.
|
|
1017
|
-
*
|
|
1018
|
-
* @param address Address of the Content Addressed Chunk
|
|
1019
|
-
* @param span Span of the Content Addressed Chunk
|
|
1020
|
-
* @param payload Payload of the Content Addressed Chunk
|
|
1021
|
-
* @param identifier The identifier of the chunk
|
|
1022
|
-
* @param signer The signer interface for signing the chunk
|
|
1023
|
-
*/
|
|
1024
|
-
makeSingleOwnerChunk(address, span, payload, identifier, signer) {
|
|
1025
|
-
return (0, soc_1.makeSingleOwnerChunk)(address, span, payload, identifier, signer);
|
|
1026
|
-
}
|
|
1027
|
-
/**
|
|
1028
|
-
* Calculates the address of a Single Owner Chunk based on its identifier and owner address.
|
|
1029
|
-
*
|
|
1030
|
-
* @param identifier
|
|
1031
|
-
* @param address
|
|
1032
|
-
*/
|
|
1033
|
-
calculateSingleOwnerChunkAddress(identifier, address) {
|
|
1034
|
-
return (0, soc_1.makeSOCAddress)(identifier, address);
|
|
1035
|
-
}
|
|
1036
|
-
/**
|
|
1037
|
-
* Attempts to unmarshal arbitrary data into a Single Owner Chunk.
|
|
1038
|
-
* Throws an error if the data is not a valid SOC.
|
|
1039
|
-
*
|
|
1040
|
-
* @param data The chunk data
|
|
1041
|
-
* @param address The address of the single owner chunk
|
|
1042
|
-
*
|
|
1043
|
-
* @returns a single owner chunk or throws error
|
|
1044
|
-
*/
|
|
1045
|
-
unmarshalSingleOwnerChunk(data, address) {
|
|
1046
|
-
return (0, soc_1.unmarshalSingleOwnerChunk)(data, address);
|
|
1047
|
-
}
|
|
1048
|
-
/**
|
|
1049
|
-
* Returns an object for reading single owner chunks
|
|
1050
|
-
*
|
|
1051
|
-
* @param ownerAddress The ethereum address of the owner
|
|
1052
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1053
|
-
* @see [Bee docs - Chunk Types](https://docs.ethswarm.org/docs/develop/tools-and-features/chunk-types#single-owner-chunks)
|
|
1054
|
-
*/
|
|
1055
|
-
makeSOCReader(ownerAddress, requestOptions) {
|
|
1056
|
-
ownerAddress = new typed_bytes_1.EthAddress(ownerAddress);
|
|
1057
|
-
return {
|
|
1058
|
-
owner: ownerAddress,
|
|
1059
|
-
download: soc_1.downloadSingleOwnerChunk.bind(null, this.getRequestOptionsForCall(requestOptions), ownerAddress),
|
|
1060
|
-
};
|
|
1061
|
-
}
|
|
1062
|
-
/**
|
|
1063
|
-
* Returns an object for reading and writing single owner chunks
|
|
1064
|
-
*
|
|
1065
|
-
* @param signer The signer's private key or a Signer instance that can sign data
|
|
1066
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1067
|
-
* @see [Bee docs - Chunk Types](https://docs.ethswarm.org/docs/develop/tools-and-features/chunk-types#single-owner-chunks)
|
|
1068
|
-
*/
|
|
1069
|
-
makeSOCWriter(signer, requestOptions) {
|
|
1070
|
-
signer = signer ? new typed_bytes_1.PrivateKey(signer) : this.signer;
|
|
1071
|
-
if (!signer) {
|
|
1072
|
-
throw Error('No signer provided');
|
|
1073
|
-
}
|
|
1074
|
-
return {
|
|
1075
|
-
...this.makeSOCReader(signer.publicKey().address(), requestOptions),
|
|
1076
|
-
upload: soc_1.uploadSingleOwnerChunkData.bind(null, this.getRequestOptionsForCall(requestOptions), signer),
|
|
1077
|
-
};
|
|
1078
|
-
}
|
|
1079
|
-
/**
|
|
1080
|
-
* Creates the postage batch signature for a specific chunk address.
|
|
1081
|
-
*
|
|
1082
|
-
* This is for advanced usage, where a pre-signed chunk can be uploaded
|
|
1083
|
-
* through a different Bee node.
|
|
1084
|
-
*
|
|
1085
|
-
* @param postageBatchId
|
|
1086
|
-
* @param reference
|
|
1087
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1088
|
-
*
|
|
1089
|
-
* @example
|
|
1090
|
-
* const envelope = await bee.createEnvelope(batchId, chunk.address)
|
|
1091
|
-
* await bee.uploadChunk(envelope, chunk)
|
|
1092
|
-
*
|
|
1093
|
-
* @returns
|
|
1094
|
-
*/
|
|
1095
|
-
async createEnvelope(postageBatchId, reference, requestOptions) {
|
|
1096
|
-
postageBatchId = new typed_bytes_1.BatchId(postageBatchId);
|
|
1097
|
-
reference = new typed_bytes_1.Reference(reference);
|
|
1098
|
-
return (0, envelope_1.postEnvelope)(this.getRequestOptionsForCall(requestOptions), postageBatchId, reference);
|
|
1099
|
-
}
|
|
1100
|
-
/**
|
|
1101
|
-
* Gets reserve commitment hash duration seconds.
|
|
1102
|
-
*
|
|
1103
|
-
* To be able to participe in the storage incentives and not get frozen, this should
|
|
1104
|
-
* ideally run under 5 minutes.
|
|
1105
|
-
*
|
|
1106
|
-
* This is a CPU intensice operation, as roughly 2^22 chunks are hashed in the process.
|
|
1107
|
-
*
|
|
1108
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1109
|
-
*
|
|
1110
|
-
* @example
|
|
1111
|
-
* const addresses = await bee.getNodeAddresses()
|
|
1112
|
-
* const topology = await bee.getTopology()
|
|
1113
|
-
* const result = await bee.rchash(topology.depth, addresses.overlay.toHex(), addresses.overlay.toHex())
|
|
1114
|
-
* // result is a number of seconds
|
|
1115
|
-
*/
|
|
1116
|
-
async rchash(depth, anchor1, anchor2, requestOptions) {
|
|
1117
|
-
return (0, rchash_1.rchash)(this.getRequestOptionsForCall(requestOptions), depth, anchor1, anchor2);
|
|
1118
|
-
}
|
|
1119
|
-
/**
|
|
1120
|
-
* Pings the Bee node to see if there is a live Bee node on the given URL.
|
|
1121
|
-
*
|
|
1122
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1123
|
-
* @throws If connection was not successful throw error
|
|
1124
|
-
*/
|
|
1125
|
-
async checkConnection(requestOptions) {
|
|
1126
|
-
return status.checkConnection(this.getRequestOptionsForCall(requestOptions));
|
|
1127
|
-
}
|
|
1128
|
-
/**
|
|
1129
|
-
* Pings the Bee node to see if there is a live Bee node on the given URL.
|
|
1130
|
-
*
|
|
1131
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1132
|
-
* @returns true if successful, false on error
|
|
1133
|
-
*/
|
|
1134
|
-
async isConnected(requestOptions) {
|
|
1135
|
-
try {
|
|
1136
|
-
await status.checkConnection(this.getRequestOptionsForCall(requestOptions));
|
|
1137
|
-
}
|
|
1138
|
-
catch (e) {
|
|
1139
|
-
return false;
|
|
1140
|
-
}
|
|
1141
|
-
return true;
|
|
1142
|
-
}
|
|
1143
|
-
/**
|
|
1144
|
-
* Checks the `/gateway` endpoint to see if the remote API is a gateway.
|
|
1145
|
-
*
|
|
1146
|
-
* Do note that this is not a standard way to check for gateway nodes,
|
|
1147
|
-
* but some of the gateway tooling expose this endpoint.
|
|
1148
|
-
*
|
|
1149
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1150
|
-
*/
|
|
1151
|
-
async isGateway(requestOptions) {
|
|
1152
|
-
return status.isGateway(this.getRequestOptionsForCall(requestOptions));
|
|
1153
|
-
}
|
|
1154
|
-
/**
|
|
1155
|
-
* Fetches the overlay, underlay, Ethereum, and other addresses of the Bee node.
|
|
1156
|
-
*
|
|
1157
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1158
|
-
* @returns
|
|
1159
|
-
*/
|
|
1160
|
-
async getNodeAddresses(requestOptions) {
|
|
1161
|
-
return connectivity.getNodeAddresses(this.getRequestOptionsForCall(requestOptions));
|
|
1162
|
-
}
|
|
1163
|
-
/**
|
|
1164
|
-
* Fetches the list of blocked peers for this node.
|
|
1165
|
-
*
|
|
1166
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1167
|
-
* @returns
|
|
1168
|
-
*/
|
|
1169
|
-
async getBlocklist(requestOptions) {
|
|
1170
|
-
return connectivity.getBlocklist(this.getRequestOptionsForCall(requestOptions));
|
|
1171
|
-
}
|
|
1172
|
-
/**
|
|
1173
|
-
* Gets list of peers for this node.
|
|
1174
|
-
*
|
|
1175
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1176
|
-
*/
|
|
1177
|
-
async getPeers(requestOptions) {
|
|
1178
|
-
return connectivity.getPeers(this.getRequestOptionsForCall(requestOptions));
|
|
1179
|
-
}
|
|
1180
|
-
/**
|
|
1181
|
-
* Disconnects from a specific peer.
|
|
1182
|
-
*
|
|
1183
|
-
* @param peer Overlay address of the peer to be removed.
|
|
1184
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1185
|
-
* @returns
|
|
1186
|
-
*/
|
|
1187
|
-
async removePeer(peer, requestOptions) {
|
|
1188
|
-
peer = new typed_bytes_1.PeerAddress(peer);
|
|
1189
|
-
return connectivity.removePeer(this.getRequestOptionsForCall(requestOptions), peer);
|
|
1190
|
-
}
|
|
1191
|
-
/**
|
|
1192
|
-
* Fetches topology and connectivity information of the Bee node.
|
|
1193
|
-
*
|
|
1194
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1195
|
-
* @returns
|
|
1196
|
-
*/
|
|
1197
|
-
async getTopology(requestOptions) {
|
|
1198
|
-
return connectivity.getTopology(this.getRequestOptionsForCall(requestOptions));
|
|
1199
|
-
}
|
|
1200
|
-
/**
|
|
1201
|
-
* Pings a specific peer to check its availability.
|
|
1202
|
-
*
|
|
1203
|
-
* @param peer Overlay address of the peer to be pinged.
|
|
1204
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1205
|
-
* @returns
|
|
1206
|
-
*/
|
|
1207
|
-
async pingPeer(peer, requestOptions) {
|
|
1208
|
-
peer = new typed_bytes_1.PeerAddress(peer);
|
|
1209
|
-
return connectivity.pingPeer(this.getRequestOptionsForCall(requestOptions), peer);
|
|
1210
|
-
}
|
|
1211
|
-
/**
|
|
1212
|
-
* Gets the SWAP balances with all known peers including prepaid services.
|
|
1213
|
-
*
|
|
1214
|
-
* This is related to the bandwidth incentives and the chequebook.
|
|
1215
|
-
*
|
|
1216
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1217
|
-
*/
|
|
1218
|
-
async getAllBalances(requestOptions) {
|
|
1219
|
-
return balance.getAllBalances(this.getRequestOptionsForCall(requestOptions));
|
|
1220
|
-
}
|
|
1221
|
-
/**
|
|
1222
|
-
* Gets the SWAP balances for a specific peer including prepaid services.
|
|
1223
|
-
*
|
|
1224
|
-
* @param address Swarm address of peer
|
|
1225
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1226
|
-
*/
|
|
1227
|
-
async getPeerBalance(address, requestOptions) {
|
|
1228
|
-
address = new typed_bytes_1.PeerAddress(address);
|
|
1229
|
-
return balance.getPeerBalance(this.getRequestOptionsForCall(requestOptions), address);
|
|
1230
|
-
}
|
|
1231
|
-
/**
|
|
1232
|
-
* Gets the past due consumption balances for all known peers.
|
|
1233
|
-
*
|
|
1234
|
-
* This is related to the bandwidth incentives and the chequebook.
|
|
1235
|
-
*
|
|
1236
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1237
|
-
*/
|
|
1238
|
-
async getPastDueConsumptionBalances(requestOptions) {
|
|
1239
|
-
return balance.getPastDueConsumptionBalances(this.getRequestOptionsForCall(requestOptions));
|
|
1240
|
-
}
|
|
1241
|
-
/**
|
|
1242
|
-
* Gets the past due consumption balance for a specific peer.
|
|
1243
|
-
*
|
|
1244
|
-
* This is related to the bandwidth incentives and the chequebook.
|
|
1245
|
-
*
|
|
1246
|
-
* @param address Swarm address of peer
|
|
1247
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1248
|
-
*/
|
|
1249
|
-
async getPastDueConsumptionPeerBalance(address, requestOptions) {
|
|
1250
|
-
address = new typed_bytes_1.PeerAddress(address);
|
|
1251
|
-
return balance.getPastDueConsumptionPeerBalance(this.getRequestOptionsForCall(requestOptions), address);
|
|
1252
|
-
}
|
|
1253
|
-
/**
|
|
1254
|
-
* Gets the address of the deloyed chequebook.
|
|
1255
|
-
*
|
|
1256
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1257
|
-
*/
|
|
1258
|
-
async getChequebookAddress(requestOptions) {
|
|
1259
|
-
return chequebook.getChequebookAddress(this.getRequestOptionsForCall(requestOptions));
|
|
1260
|
-
}
|
|
1261
|
-
/**
|
|
1262
|
-
* Gets the balance of the chequebook.
|
|
1263
|
-
*
|
|
1264
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1265
|
-
*/
|
|
1266
|
-
async getChequebookBalance(requestOptions) {
|
|
1267
|
-
return chequebook.getChequebookBalance(this.getRequestOptionsForCall(requestOptions));
|
|
1268
|
-
}
|
|
1269
|
-
/**
|
|
1270
|
-
* Gets the last cheques for all peers.
|
|
1271
|
-
*
|
|
1272
|
-
* This is related to the bandwidth incentives and the chequebook.
|
|
1273
|
-
*
|
|
1274
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1275
|
-
*/
|
|
1276
|
-
async getLastCheques(requestOptions) {
|
|
1277
|
-
return chequebook.getLastCheques(this.getRequestOptionsForCall(requestOptions));
|
|
1278
|
-
}
|
|
1279
|
-
/**
|
|
1280
|
-
* Gets the last cheques for a specific peer.
|
|
1281
|
-
*
|
|
1282
|
-
* This is related to the bandwidth incentives and the chequebook.
|
|
1283
|
-
*
|
|
1284
|
-
* @param address Overlay address of peer.
|
|
1285
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1286
|
-
*/
|
|
1287
|
-
async getLastChequesForPeer(address, requestOptions) {
|
|
1288
|
-
address = new typed_bytes_1.PeerAddress(address);
|
|
1289
|
-
return chequebook.getLastChequesForPeer(this.getRequestOptionsForCall(requestOptions), address);
|
|
1290
|
-
}
|
|
1291
|
-
/**
|
|
1292
|
-
* Gets the last cashout action for a specific peer.
|
|
1293
|
-
*
|
|
1294
|
-
* This is related to the bandwidth incentives and the chequebook.
|
|
1295
|
-
*
|
|
1296
|
-
* @param address Overlay address of peer.
|
|
1297
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1298
|
-
*/
|
|
1299
|
-
async getLastCashoutAction(address, requestOptions) {
|
|
1300
|
-
address = new typed_bytes_1.PeerAddress(address);
|
|
1301
|
-
return chequebook.getLastCashoutAction(this.getRequestOptionsForCall(requestOptions), address);
|
|
1302
|
-
}
|
|
1303
|
-
/**
|
|
1304
|
-
* Cashes out the last cheque for a specific peer.
|
|
1305
|
-
*
|
|
1306
|
-
* This is related to the bandwidth incentives and the chequebook.
|
|
1307
|
-
*
|
|
1308
|
-
* @param address Swarm address of peer
|
|
1309
|
-
* @param options
|
|
1310
|
-
* @param options.gasPrice Gas price for the cashout transaction in WEI
|
|
1311
|
-
* @param options.gasLimit Gas limit for the cashout transaction in WEI
|
|
1312
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1313
|
-
*/
|
|
1314
|
-
async cashoutLastCheque(address, options, requestOptions) {
|
|
1315
|
-
address = new typed_bytes_1.PeerAddress(address);
|
|
1316
|
-
if (options) {
|
|
1317
|
-
options = schema_1.TransactionOptionsSchema.parse(options);
|
|
1318
|
-
}
|
|
1319
|
-
return chequebook.cashoutLastCheque(this.getRequestOptionsForCall(requestOptions), address, options);
|
|
1320
|
-
}
|
|
1321
|
-
/**
|
|
1322
|
-
* Deposits tokens from the node wallet into the chequebook.
|
|
1323
|
-
*
|
|
1324
|
-
* @param amount Amount of tokens to deposit (must be positive integer)
|
|
1325
|
-
* @param gasPrice Gas Price in WEI for the transaction call
|
|
1326
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1327
|
-
*
|
|
1328
|
-
* @return string Hash of the transaction
|
|
1329
|
-
* @deprecated Use `depositBZZToChequebook` instead.
|
|
1330
|
-
*/
|
|
1331
|
-
async depositTokens(amount, gasPrice, requestOptions) {
|
|
1332
|
-
return this.depositBZZToChequebook(amount, gasPrice, requestOptions);
|
|
1333
|
-
}
|
|
1334
|
-
/**
|
|
1335
|
-
* Deposits tokens from the node wallet into the chequebook.
|
|
1336
|
-
*
|
|
1337
|
-
* @param amount Amount of tokens to deposit (must be positive integer)
|
|
1338
|
-
* @param gasPrice Gas Price in WEI for the transaction call
|
|
1339
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1340
|
-
*
|
|
1341
|
-
* @return string Hash of the transaction
|
|
1342
|
-
*/
|
|
1343
|
-
async depositBZZToChequebook(amount, gasPrice, requestOptions) {
|
|
1344
|
-
const amountString = amount instanceof tokens_1.BZZ ? amount.toPLURString() : (0, type_1.asNumberString)(amount, { min: 1n, name: 'amount' });
|
|
1345
|
-
let gasPriceString;
|
|
1346
|
-
if (gasPrice) {
|
|
1347
|
-
gasPriceString = (0, type_1.asNumberString)(amount, { min: 0n, name: 'gasPrice' });
|
|
1348
|
-
}
|
|
1349
|
-
return chequebook.depositTokens(this.getRequestOptionsForCall(requestOptions), amountString, gasPriceString);
|
|
1350
|
-
}
|
|
1351
|
-
/**
|
|
1352
|
-
* Withdraws tokens from the chequebook to the node wallet.
|
|
1353
|
-
*
|
|
1354
|
-
* @param amount Amount of tokens to withdraw (must be positive integer)
|
|
1355
|
-
* @param gasPrice Gas Price in WEI for the transaction call
|
|
1356
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1357
|
-
*
|
|
1358
|
-
* @return string Hash of the transaction
|
|
1359
|
-
* @deprecated Use `withdrawBZZFromChequebook` instead.
|
|
1360
|
-
*/
|
|
1361
|
-
async withdrawTokens(amount, gasPrice, requestOptions) {
|
|
1362
|
-
return this.withdrawBZZFromChequebook(amount, gasPrice, requestOptions);
|
|
1363
|
-
}
|
|
1364
|
-
/**
|
|
1365
|
-
* Withdraws tokens from the chequebook to the node wallet.
|
|
1366
|
-
*
|
|
1367
|
-
* @param amount Amount of BZZ tokens to withdraw. If not providing a `BZZ` instance, the amount is denoted in PLUR.
|
|
1368
|
-
* @param gasPrice Gas Price in WEI for the transaction call.
|
|
1369
|
-
* @return Transaction ID
|
|
1370
|
-
*/
|
|
1371
|
-
async withdrawBZZFromChequebook(amount, gasPrice, requestOptions) {
|
|
1372
|
-
// TODO: check BZZ in tests
|
|
1373
|
-
const amountString = amount instanceof tokens_1.BZZ ? amount.toPLURString() : (0, type_1.asNumberString)(amount, { min: 1n, name: 'amount' });
|
|
1374
|
-
let gasPriceString;
|
|
1375
|
-
if (gasPrice) {
|
|
1376
|
-
gasPriceString = (0, type_1.asNumberString)(amount, { min: 0n, name: 'gasPrice' });
|
|
1377
|
-
}
|
|
1378
|
-
return chequebook.withdrawTokens(this.getRequestOptionsForCall(requestOptions), amountString, gasPriceString);
|
|
1379
|
-
}
|
|
1380
|
-
/**
|
|
1381
|
-
* Withdraws BZZ from the node wallet (not chequebook) to a whitelisted external wallet address.
|
|
1382
|
-
*
|
|
1383
|
-
* @param amount Amount of BZZ tokens to withdraw. If not providing a `BZZ` instance, the amount is denoted in PLUR.
|
|
1384
|
-
* @param address
|
|
1385
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1386
|
-
* @return Transaction ID
|
|
1387
|
-
*/
|
|
1388
|
-
async withdrawBZZToExternalWallet(amount, address, requestOptions) {
|
|
1389
|
-
amount = amount instanceof tokens_1.BZZ ? amount : tokens_1.BZZ.fromPLUR(amount);
|
|
1390
|
-
address = new typed_bytes_1.EthAddress(address);
|
|
1391
|
-
return states.withdrawBZZ(this.getRequestOptionsForCall(requestOptions), amount, address);
|
|
1392
|
-
}
|
|
1393
|
-
/**
|
|
1394
|
-
* Withdraws DAI from the node wallet (not chequebook) to a whitelisted external wallet address.
|
|
1395
|
-
*
|
|
1396
|
-
* @param amount Amount of DAI tokens to withdraw. If not providing a `DAI` instance, the amount is denoted in wei.
|
|
1397
|
-
* @param address
|
|
1398
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1399
|
-
* @return Transaction ID
|
|
1400
|
-
*/
|
|
1401
|
-
async withdrawDAIToExternalWallet(amount, address, requestOptions) {
|
|
1402
|
-
amount = amount instanceof tokens_1.DAI ? amount : tokens_1.DAI.fromWei(amount);
|
|
1403
|
-
address = new typed_bytes_1.EthAddress(address);
|
|
1404
|
-
return states.withdrawDAI(this.getRequestOptionsForCall(requestOptions), amount, address);
|
|
1405
|
-
}
|
|
1406
|
-
/**
|
|
1407
|
-
* Gets the amount of sent and received micropayments from settlements with a peer.
|
|
1408
|
-
*
|
|
1409
|
-
* This is related to the bandwidth incentives and the chequebook.
|
|
1410
|
-
*
|
|
1411
|
-
* @param address Swarm address of peer
|
|
1412
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1413
|
-
*/
|
|
1414
|
-
async getSettlements(address, requestOptions) {
|
|
1415
|
-
address = new typed_bytes_1.PeerAddress(address);
|
|
1416
|
-
return settlements.getSettlements(this.getRequestOptionsForCall(requestOptions), address);
|
|
1417
|
-
}
|
|
1418
|
-
/**
|
|
1419
|
-
* Gets settlements with all known peers and total amount sent or received.
|
|
1420
|
-
*
|
|
1421
|
-
* This is related to the bandwidth incentives and the chequebook.
|
|
1422
|
-
*
|
|
1423
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1424
|
-
*/
|
|
1425
|
-
async getAllSettlements(requestOptions) {
|
|
1426
|
-
return settlements.getAllSettlements(this.getRequestOptionsForCall(requestOptions));
|
|
1427
|
-
}
|
|
1428
|
-
/**
|
|
1429
|
-
* Gets the general status of the node.
|
|
1430
|
-
*
|
|
1431
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1432
|
-
*/
|
|
1433
|
-
async getStatus(requestOptions) {
|
|
1434
|
-
return debugStatus.getDebugStatus(this.getRequestOptionsForCall(requestOptions));
|
|
1435
|
-
}
|
|
1436
|
-
/**
|
|
1437
|
-
* Gets the health of the node.
|
|
1438
|
-
*
|
|
1439
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1440
|
-
*/
|
|
1441
|
-
async getHealth(requestOptions) {
|
|
1442
|
-
return debugStatus.getHealth(this.getRequestOptionsForCall(requestOptions));
|
|
1443
|
-
}
|
|
1444
|
-
/**
|
|
1445
|
-
* Gets the readiness status of the node.
|
|
1446
|
-
*
|
|
1447
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1448
|
-
*/
|
|
1449
|
-
async getReadiness(requestOptions) {
|
|
1450
|
-
return debugStatus.getReadiness(this.getRequestOptionsForCall(requestOptions));
|
|
1451
|
-
}
|
|
1452
|
-
/**
|
|
1453
|
-
* Get mode information of node.
|
|
1454
|
-
*
|
|
1455
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1456
|
-
*/
|
|
1457
|
-
async getNodeInfo(requestOptions) {
|
|
1458
|
-
return debugStatus.getNodeInfo(this.getRequestOptionsForCall(requestOptions));
|
|
1459
|
-
}
|
|
1460
|
-
/**
|
|
1461
|
-
* Connects to a node and checks if its version matches with the one that bee-js supports.
|
|
1462
|
-
*
|
|
1463
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1464
|
-
*/
|
|
1465
|
-
async isSupportedExactVersion(requestOptions) {
|
|
1466
|
-
return debugStatus.isSupportedExactVersion(this.getRequestOptionsForCall(requestOptions));
|
|
1467
|
-
}
|
|
1468
|
-
/**
|
|
1469
|
-
*
|
|
1470
|
-
* Connects to a node and checks if its Main API version matches with the one that bee-js supports.
|
|
1471
|
-
*
|
|
1472
|
-
* This should be the main way how to check compatibility for your app and Bee node.
|
|
1473
|
-
*
|
|
1474
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1475
|
-
*/
|
|
1476
|
-
async isSupportedApiVersion(requestOptions) {
|
|
1477
|
-
return debugStatus.isSupportedApiVersion(this.getRequestOptionsForCall(requestOptions));
|
|
1478
|
-
}
|
|
1479
|
-
/**
|
|
1480
|
-
* Returns object with all versions specified by the connected Bee node (properties prefixed with `bee*`)
|
|
1481
|
-
* and versions that bee-js supports (properties prefixed with `supported*`).
|
|
1482
|
-
*
|
|
1483
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1484
|
-
*/
|
|
1485
|
-
async getVersions(requestOptions) {
|
|
1486
|
-
return debugStatus.getVersions(this.getRequestOptionsForCall(requestOptions));
|
|
1487
|
-
}
|
|
1488
|
-
/**
|
|
1489
|
-
* Get reserve state.
|
|
1490
|
-
*
|
|
1491
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1492
|
-
*/
|
|
1493
|
-
async getReserveState(requestOptions) {
|
|
1494
|
-
return states.getReserveState(this.getRequestOptionsForCall(requestOptions));
|
|
1495
|
-
}
|
|
1496
|
-
/**
|
|
1497
|
-
* Gets chain state.
|
|
1498
|
-
*
|
|
1499
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1500
|
-
*/
|
|
1501
|
-
async getChainState(requestOptions) {
|
|
1502
|
-
return states.getChainState(this.getRequestOptionsForCall(requestOptions));
|
|
1503
|
-
}
|
|
1504
|
-
/**
|
|
1505
|
-
* Gets DAI and BZZ balances of the Bee node wallet.
|
|
1506
|
-
*
|
|
1507
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1508
|
-
*/
|
|
1509
|
-
async getWalletBalance(requestOptions) {
|
|
1510
|
-
return states.getWalletBalance(this.getRequestOptionsForCall(requestOptions));
|
|
1511
|
-
}
|
|
1512
|
-
/**
|
|
1513
|
-
* Creates a new postage batch, spending BZZ tokens from the node wallet.
|
|
1514
|
-
*
|
|
1515
|
-
* Use {@link buyStorage} for a more convenient way to create postage batch.
|
|
1516
|
-
*
|
|
1517
|
-
* For better understanding what each parameter means and what the optimal values are, see
|
|
1518
|
-
* [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction#keep-your-data-alive).
|
|
1519
|
-
*
|
|
1520
|
-
* @param amount TTL parameter - 1 day at the minimum of 24,000 storage price requires an amount of 414,720,000.
|
|
1521
|
-
* @param depth Capacity parameter - 17..255 - depth 17 provides 512MB of theoretical capacity, 18 provides 1GB, 19 provides 2GB, etc.
|
|
1522
|
-
* @param options Options for creation of postage batch
|
|
1523
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1524
|
-
*
|
|
1525
|
-
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
|
|
1526
|
-
* @see [Bee Debug API reference - `POST /stamps`](https://docs.ethswarm.org/api/#tag/Postage-Stamps/paths/~1stamps~1{amount}~1{depth}/post)
|
|
1527
|
-
*/
|
|
1528
|
-
async createPostageBatch(amount, depth, options, requestOptions) {
|
|
1529
|
-
const amountString = (0, type_1.asNumberString)(amount, { min: 0n, name: 'amount' });
|
|
1530
|
-
if (options) {
|
|
1531
|
-
options = schema_1.PostageBatchOptionsSchema.parse(options);
|
|
1532
|
-
}
|
|
1533
|
-
if (depth < types_1.STAMPS_DEPTH_MIN || depth > types_1.STAMPS_DEPTH_MAX) {
|
|
1534
|
-
throw new error_1.BeeArgumentError(`Depth has to be between ${types_1.STAMPS_DEPTH_MIN}..${types_1.STAMPS_DEPTH_MAX}`, depth);
|
|
1535
|
-
}
|
|
1536
|
-
const chainState = await this.getChainState();
|
|
1537
|
-
const minimumAmount = BigInt(chainState.currentPrice) * 17280n + 1n;
|
|
1538
|
-
if (BigInt(amountString) < minimumAmount) {
|
|
1539
|
-
throw new error_1.BeeArgumentError(`Amount has to be at least ${minimumAmount} (1 day at current price ${chainState.currentPrice})`, amountString);
|
|
1540
|
-
}
|
|
1541
|
-
const stamp = await stamps.createPostageBatch(this.getRequestOptionsForCall(requestOptions), amountString, depth, options);
|
|
1542
|
-
if (options?.waitForUsable !== false) {
|
|
1543
|
-
await this.waitForUsablePostageStamp(stamp, options?.waitForUsableTimeout);
|
|
1544
|
-
}
|
|
1545
|
-
return stamp;
|
|
1546
|
-
}
|
|
1547
|
-
/**
|
|
1548
|
-
* A more convenient method to create a postage batch, which is analogous
|
|
1549
|
-
* to buying storage for a certain size and duration on the Swarm network.
|
|
1550
|
-
*
|
|
1551
|
-
* Use {@link getStorageCost} to calculate the cost of creating a postage batch.
|
|
1552
|
-
*
|
|
1553
|
-
* For the low level API, use {@link createPostageBatch}.
|
|
1554
|
-
*
|
|
1555
|
-
* @example const batchId = await bee.buyStorage(Size.fromGigabytes(8), Duration.fromDays(31))
|
|
1556
|
-
|
|
1557
|
-
* @param size
|
|
1558
|
-
* @param duration
|
|
1559
|
-
* @param options
|
|
1560
|
-
* @param requestOptions
|
|
1561
|
-
* @param encryption
|
|
1562
|
-
* @param erasureCodeLevel
|
|
1563
|
-
* @returns
|
|
1564
|
-
*/
|
|
1565
|
-
async buyStorage(size, duration, options, requestOptions, encryption, erasureCodeLevel) {
|
|
1566
|
-
const chainState = await this.getChainState(requestOptions);
|
|
1567
|
-
const amount = (0, stamps_1.getAmountForDuration)(duration, chainState.currentPrice, this.network === 'gnosis' ? 5 : 15);
|
|
1568
|
-
const depth = (0, stamps_1.getDepthForSize)(size, encryption, erasureCodeLevel);
|
|
1569
|
-
if (options) {
|
|
1570
|
-
options = schema_1.PostageBatchOptionsSchema.parse(options);
|
|
1571
|
-
}
|
|
1572
|
-
return this.createPostageBatch(amount, depth, options, requestOptions);
|
|
1573
|
-
}
|
|
1574
|
-
/**
|
|
1575
|
-
* Calculates the estimated BZZ cost for creating a postage batch for the given size and duration.
|
|
1576
|
-
*
|
|
1577
|
-
* Use {@link buyStorage} to create a postage batch with the calculated cost.
|
|
1578
|
-
*
|
|
1579
|
-
* @example const bzz = await bee.getStorageCost(Size.fromGigabytes(1), Duration.fromDays(30))
|
|
1580
|
-
*
|
|
1581
|
-
* @param size Size of the data to be stored.
|
|
1582
|
-
* @param duration Duration for which the data should be stored.
|
|
1583
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1584
|
-
* @param encryption Assume the future uploaded data is encrypted, which skews the capacity of the postage batch.
|
|
1585
|
-
* @param erasureCodeLevel Assume the future uploaded data is erasure coded, which skews the capacity of the postage batch.
|
|
1586
|
-
* @returns
|
|
1587
|
-
*/
|
|
1588
|
-
async getStorageCost(size, duration, requestOptions, encryption, erasureCodeLevel) {
|
|
1589
|
-
const chainState = await this.getChainState(requestOptions);
|
|
1590
|
-
const amount = (0, stamps_1.getAmountForDuration)(duration, chainState.currentPrice, this.network === 'gnosis' ? 5 : 15);
|
|
1591
|
-
const depth = (0, stamps_1.getDepthForSize)(size, encryption, erasureCodeLevel);
|
|
1592
|
-
return (0, stamps_1.getStampCost)(depth, amount);
|
|
1593
|
-
}
|
|
1594
|
-
/**
|
|
1595
|
-
* Extends the storage of a postage batch by either increasing its size, duration or both.
|
|
1596
|
-
*
|
|
1597
|
-
* The size is ABSOLUTE, while the duration is RELATIVE to the current duration of the postage batch.
|
|
1598
|
-
*
|
|
1599
|
-
* Use {@link getExtensionCost} to calculate the cost of extending the storage.
|
|
1600
|
-
*
|
|
1601
|
-
* @example
|
|
1602
|
-
* // Increases the size to 8GB (unless it is already at 8GB or higher)
|
|
1603
|
-
* // and extends the duration by 30 days (regardless of the current duration).
|
|
1604
|
-
* await bee.extendStorage(batchId, Size.fromGigabytes(8), Duration.fromDays(30))
|
|
1605
|
-
*
|
|
1606
|
-
* @example
|
|
1607
|
-
* // To increase the duration to a desired date, pass a second parameter to `Duration.fromEndDate`.
|
|
1608
|
-
* // With the second parameter, the duration is set to the difference between the current end date and the desired end date.
|
|
1609
|
-
* const oneMonth = new Date(Date.now() + Dates.days(31))
|
|
1610
|
-
* const batch = await bee.getPostageBatch(batchId)
|
|
1611
|
-
* await bee.extendStorage(batchId, Size.fromGigabytes(8), Duration.fromEndDate(oneMonth, batch.duration.toEndDate()))
|
|
1612
|
-
*
|
|
1613
|
-
* @param postageBatchId Batch ID of the postage batch to extend.
|
|
1614
|
-
* @param size Absolute size to extend the postage batch to.
|
|
1615
|
-
* @param duration Relative duration to extend the postage batch by.
|
|
1616
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1617
|
-
* @param encryption Assume the future uploaded data is encrypted, which skews the capacity of the postage batch.
|
|
1618
|
-
* @param erasureCodeLevel Assume the future uploaded data is erasure coded, which skews the capacity of the postage batch.
|
|
1619
|
-
* @returns
|
|
1620
|
-
*/
|
|
1621
|
-
async extendStorage(postageBatchId, size, duration, requestOptions, encryption, erasureCodeLevel) {
|
|
1622
|
-
const batch = await this.getPostageBatch(postageBatchId, requestOptions);
|
|
1623
|
-
const depth = (0, stamps_1.getDepthForSize)(size, encryption, erasureCodeLevel);
|
|
1624
|
-
const chainState = await this.getChainState(requestOptions);
|
|
1625
|
-
const depthDelta = depth - batch.depth;
|
|
1626
|
-
const multiplier = depthDelta <= 0 ? 1n : 2n ** BigInt(depthDelta);
|
|
1627
|
-
const blockTime = this.network === 'gnosis' ? 5 : 15;
|
|
1628
|
-
const additionalAmount = (0, stamps_1.getAmountForDuration)(duration, chainState.currentPrice, blockTime);
|
|
1629
|
-
const currentAmount = (0, stamps_1.getAmountForDuration)(batch.duration, chainState.currentPrice, blockTime);
|
|
1630
|
-
const targetAmount = duration.isZero()
|
|
1631
|
-
? currentAmount * multiplier
|
|
1632
|
-
: (currentAmount + additionalAmount) * multiplier;
|
|
1633
|
-
const amountDelta = targetAmount - currentAmount;
|
|
1634
|
-
let transactionId;
|
|
1635
|
-
if (amountDelta > 0n) {
|
|
1636
|
-
transactionId = await this.topUpBatch(batch.batchID, amountDelta, requestOptions);
|
|
1637
|
-
}
|
|
1638
|
-
if (depthDelta > 0) {
|
|
1639
|
-
return this.diluteBatch(batch.batchID, depth, requestOptions);
|
|
1640
|
-
}
|
|
1641
|
-
if (!transactionId) {
|
|
1642
|
-
throw new Error('Nothing to extend, both size and duration are already sufficient');
|
|
1643
|
-
}
|
|
1644
|
-
return transactionId;
|
|
1645
|
-
}
|
|
1646
|
-
/**
|
|
1647
|
-
* Extends the storage size of a postage batch by increasing its depth.
|
|
1648
|
-
*
|
|
1649
|
-
* Use {@link getSizeExtensionCost} to calculate the cost of extending the size.
|
|
1650
|
-
* Use {@link extendStorage} to extend both size and duration.
|
|
1651
|
-
*
|
|
1652
|
-
* @param postageBatchId
|
|
1653
|
-
* @param size Absolute size to extend the postage batch to.
|
|
1654
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1655
|
-
* @param encryption Assume the future uploaded data is encrypted, which skews the capacity of the postage batch.
|
|
1656
|
-
* @param erasureCodeLevel Assume the future uploaded data is erasure coded, which skews the capacity of the postage batch.
|
|
1657
|
-
* @returns
|
|
1658
|
-
*/
|
|
1659
|
-
async extendStorageSize(postageBatchId, size, requestOptions, encryption, erasureCodeLevel) {
|
|
1660
|
-
const chainState = await this.getChainState(requestOptions);
|
|
1661
|
-
const batch = await this.getPostageBatch(postageBatchId, requestOptions);
|
|
1662
|
-
const depth = (0, stamps_1.getDepthForSize)(size, encryption, erasureCodeLevel);
|
|
1663
|
-
const delta = depth - batch.depth;
|
|
1664
|
-
if (delta <= 0) {
|
|
1665
|
-
throw new error_1.BeeArgumentError('New depth has to be greater than the original depth', depth);
|
|
1666
|
-
}
|
|
1667
|
-
const currentAmount = (0, stamps_1.getAmountForDuration)(batch.duration, chainState.currentPrice, this.network === 'gnosis' ? 5 : 15);
|
|
1668
|
-
await this.topUpBatch(batch.batchID, currentAmount * (2n ** BigInt(delta) - 1n) + 1n, requestOptions);
|
|
1669
|
-
return this.diluteBatch(batch.batchID, depth, requestOptions);
|
|
1670
|
-
}
|
|
1671
|
-
/**
|
|
1672
|
-
* Extends the duration of a postage batch.
|
|
1673
|
-
*
|
|
1674
|
-
* Use {@link getDurationExtensionCost} to calculate the cost of extending the duration.
|
|
1675
|
-
* Use {@link extendStorage} to extend both size and duration.
|
|
1676
|
-
*
|
|
1677
|
-
* @param postageBatchId
|
|
1678
|
-
* @param duration Relative duration to extend the postage batch by.
|
|
1679
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1680
|
-
* @returns
|
|
1681
|
-
*/
|
|
1682
|
-
async extendStorageDuration(postageBatchId, duration, requestOptions) {
|
|
1683
|
-
const batch = await this.getPostageBatch(postageBatchId, requestOptions);
|
|
1684
|
-
const chainState = await this.getChainState(requestOptions);
|
|
1685
|
-
const amount = (0, stamps_1.getAmountForDuration)(duration, chainState.currentPrice, this.network === 'gnosis' ? 5 : 15);
|
|
1686
|
-
return this.topUpBatch(batch.batchID, amount, requestOptions);
|
|
1687
|
-
}
|
|
1688
|
-
/**
|
|
1689
|
-
* Calculates the cost of extending both the duration and the capacity of a postage batch.
|
|
1690
|
-
*
|
|
1691
|
-
* The size is ABSOLUTE, while the duration is RELATIVE to the current duration of the postage batch.
|
|
1692
|
-
*
|
|
1693
|
-
* Use {@link extendStorage} to extend the the duration and capacity of a postage batch.
|
|
1694
|
-
*
|
|
1695
|
-
* @param postageBatchId
|
|
1696
|
-
* @param size Absolute size to extend the postage batch to.
|
|
1697
|
-
* @param duration Relative duration to extend the postage batch by.
|
|
1698
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1699
|
-
* @param encryption Assume the future uploaded data is encrypted, which skews the capacity of the postage batch.
|
|
1700
|
-
* @param erasureCodeLevel Assume the future uploaded data is erasure coded, which skews the capacity of the postage batch.
|
|
1701
|
-
* @returns
|
|
1702
|
-
*/
|
|
1703
|
-
async getExtensionCost(postageBatchId, size, duration, requestOptions, encryption, erasureCodeLevel) {
|
|
1704
|
-
const batch = await this.getPostageBatch(postageBatchId, requestOptions);
|
|
1705
|
-
const chainState = await this.getChainState(requestOptions);
|
|
1706
|
-
const blockTime = this.network === 'gnosis' ? 5 : 15;
|
|
1707
|
-
const amount = duration.isZero() ? 0n : (0, stamps_1.getAmountForDuration)(duration, chainState.currentPrice, blockTime);
|
|
1708
|
-
const depth = (0, stamps_1.getDepthForSize)(size, encryption, erasureCodeLevel);
|
|
1709
|
-
const currentAmount = (0, stamps_1.getAmountForDuration)(batch.duration, chainState.currentPrice, blockTime);
|
|
1710
|
-
const currentCost = (0, stamps_1.getStampCost)(batch.depth, currentAmount);
|
|
1711
|
-
const newCost = (0, stamps_1.getStampCost)(Math.max(batch.depth, depth), currentAmount + amount);
|
|
1712
|
-
return newCost.minus(currentCost);
|
|
1713
|
-
}
|
|
1714
|
-
/**
|
|
1715
|
-
* Calculates the cost of extending the size of a postage batch.
|
|
1716
|
-
*
|
|
1717
|
-
* The size is ABSOLUTE, so if the postage batch already equals or is greater than the given size,
|
|
1718
|
-
* the cost will be zero.
|
|
1719
|
-
*
|
|
1720
|
-
* Use {@link extendStorageSize} to extend the size of a postage batch.
|
|
1721
|
-
*
|
|
1722
|
-
* Use {@link getExtensionCost} to get the cost of extending both size and duration.
|
|
1723
|
-
* Use {@link getDurationExtensionCost} to get the cost of extending only the duration.
|
|
1724
|
-
*
|
|
1725
|
-
* @param postageBatchId
|
|
1726
|
-
* @param size
|
|
1727
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1728
|
-
* @param encryption Assume the future uploaded data is encrypted, which skews the capacity of the postage batch.
|
|
1729
|
-
* @param erasureCodeLevel Assume the future uploaded data is erasure coded, which skews the capacity of the postage batch.
|
|
1730
|
-
* @returns
|
|
1731
|
-
*/
|
|
1732
|
-
async getSizeExtensionCost(postageBatchId, size, requestOptions, encryption, erasureCodeLevel) {
|
|
1733
|
-
const batch = await this.getPostageBatch(postageBatchId, requestOptions);
|
|
1734
|
-
const chainState = await this.getChainState(requestOptions);
|
|
1735
|
-
const depth = (0, stamps_1.getDepthForSize)(size, encryption, erasureCodeLevel);
|
|
1736
|
-
const delta = depth - batch.depth;
|
|
1737
|
-
if (delta <= 0) {
|
|
1738
|
-
throw new error_1.BeeArgumentError('New depth has to be greater than the original depth', depth);
|
|
1739
|
-
}
|
|
1740
|
-
const currentAmount = (0, stamps_1.getAmountForDuration)(batch.duration, chainState.currentPrice, this.network === 'gnosis' ? 5 : 15);
|
|
1741
|
-
const currentCost = (0, stamps_1.getStampCost)(batch.depth, currentAmount);
|
|
1742
|
-
const newCost = (0, stamps_1.getStampCost)(depth, currentAmount);
|
|
1743
|
-
return newCost.minus(currentCost);
|
|
1744
|
-
}
|
|
1745
|
-
/**
|
|
1746
|
-
* Calculates the cost of extending the duration of a postage batch.
|
|
1747
|
-
*
|
|
1748
|
-
* The duration is RELATIVE to the current duration of the postage batch,
|
|
1749
|
-
* e.g. specifying `Duration.fromDays(30)` will extend the current duration by 30 days,
|
|
1750
|
-
* regardless of the current duration.
|
|
1751
|
-
*
|
|
1752
|
-
* Use {@link extendStorageDuration} to extend the duration of a postage batch.
|
|
1753
|
-
*
|
|
1754
|
-
* Use {@link getExtensionCost} to get the cost of extending both size and duration.
|
|
1755
|
-
* Use {@link getSizeExtensionCost} to get the cost of extending only the size.
|
|
1756
|
-
*
|
|
1757
|
-
* @param postageBatchId
|
|
1758
|
-
* @param duration
|
|
1759
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1760
|
-
* @returns
|
|
1761
|
-
*/
|
|
1762
|
-
async getDurationExtensionCost(postageBatchId, duration, requestOptions) {
|
|
1763
|
-
const batch = await this.getPostageBatch(postageBatchId, requestOptions);
|
|
1764
|
-
const chainState = await this.getChainState(requestOptions);
|
|
1765
|
-
const amount = (0, stamps_1.getAmountForDuration)(duration, chainState.currentPrice, this.network === 'gnosis' ? 5 : 15);
|
|
1766
|
-
return (0, stamps_1.getStampCost)(batch.depth, amount);
|
|
1767
|
-
}
|
|
1768
|
-
/**
|
|
1769
|
-
* Updates the label of a certain postage batch.
|
|
1770
|
-
*
|
|
1771
|
-
* @param postageBatchId Batch ID of the postage batch to update.
|
|
1772
|
-
* @param label New label for the postage batch.
|
|
1773
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1774
|
-
*/
|
|
1775
|
-
async updatePostageBatchLabel(postageBatchId, label, requestOptions) {
|
|
1776
|
-
postageBatchId = new typed_bytes_1.BatchId(postageBatchId);
|
|
1777
|
-
return stamps.updatePostageBatchLabel(this.getRequestOptionsForCall(requestOptions), postageBatchId, label);
|
|
1778
|
-
}
|
|
1779
|
-
/**
|
|
1780
|
-
* Renames a storage. This is a convenience method that calls {@link updatePostageBatchLabel}.
|
|
1781
|
-
*
|
|
1782
|
-
* @param postageBatchId Batch ID of the postage batch to update.
|
|
1783
|
-
* @param newName New name for the storage.
|
|
1784
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1785
|
-
*/
|
|
1786
|
-
async renameStorage(postageBatchId, newLabel, requestOptions) {
|
|
1787
|
-
return this.updatePostageBatchLabel(postageBatchId, newLabel, requestOptions);
|
|
1788
|
-
}
|
|
1789
|
-
/**
|
|
1790
|
-
* Calculates the `amount` and expected duration extension for topping up a postage batch with a given BZZ value.
|
|
1791
|
-
*
|
|
1792
|
-
* @param depth Depth of the postage batch to top up.
|
|
1793
|
-
* @param bzz The amount of BZZ to spend on the top-up.
|
|
1794
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1795
|
-
* @returns An object with `amount` (to pass to {@link topUpBatch}) and `duration` (the expected TTL extension).
|
|
1796
|
-
*/
|
|
1797
|
-
async calculateTopUpForBzz(depth, bzz, requestOptions) {
|
|
1798
|
-
const chainState = await this.getChainState(requestOptions);
|
|
1799
|
-
const blockTime = this.network === 'gnosis' ? 5 : 15;
|
|
1800
|
-
const amount = bzz.toPLURBigInt() / 2n ** BigInt(depth);
|
|
1801
|
-
const duration = (0, stamps_1.getStampDuration)(amount, chainState.currentPrice, blockTime);
|
|
1802
|
-
return { amount, duration };
|
|
1803
|
-
}
|
|
1804
|
-
/**
|
|
1805
|
-
* Increases the duration of a postage batch by increasing its amount.
|
|
1806
|
-
*
|
|
1807
|
-
* For a more convenient way to extend the postage batch, refer to the methods below.
|
|
1808
|
-
*
|
|
1809
|
-
* Use {@link getDurationExtensionCost}, {@link getSizeExtensionCost} or {@link getExtensionCost}
|
|
1810
|
-
* to calculate the costs of extending the postage batch properties.
|
|
1811
|
-
*
|
|
1812
|
-
* Use {@link extendStorageDuration}, {@link extendStorageSize} or {@link extendStorage}
|
|
1813
|
-
* to extend the postage batch properties.
|
|
1814
|
-
*
|
|
1815
|
-
* For better understanding what each parameter means and what are the optimal values please see
|
|
1816
|
-
* [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive).
|
|
1817
|
-
*
|
|
1818
|
-
* @param postageBatchId Batch ID
|
|
1819
|
-
* @param amount Amount to be added to the batch
|
|
1820
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1821
|
-
*
|
|
1822
|
-
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
|
|
1823
|
-
* @see [Bee Debug API reference - `PATCH /stamps/topup/${id}/${amount}`](https://docs.ethswarm.org/api/#tag/Postage-Stamps/paths/~1stamps~1topup~1{batch_id}~1{amount}/patch)
|
|
1824
|
-
*/
|
|
1825
|
-
async topUpBatch(postageBatchId, amount, requestOptions) {
|
|
1826
|
-
postageBatchId = new typed_bytes_1.BatchId(postageBatchId);
|
|
1827
|
-
const amountString = (0, type_1.asNumberString)(amount, { min: 1n, name: 'amount' });
|
|
1828
|
-
return stamps.topUpBatch(this.getRequestOptionsForCall(requestOptions), postageBatchId, amountString);
|
|
1829
|
-
}
|
|
1830
|
-
/**
|
|
1831
|
-
* Dilutes a postage batch to extend its capacity by increasing its depth.
|
|
1832
|
-
*
|
|
1833
|
-
* This is a free operation, as for every depth increase, the capacity is doubled,
|
|
1834
|
-
* but the amount (duration) is halved.
|
|
1835
|
-
*
|
|
1836
|
-
* To increase the capacity of the postage batch while retaining the same amount (duration),
|
|
1837
|
-
* you need to top up the postage batch first using {@link topUpBatch}.
|
|
1838
|
-
*
|
|
1839
|
-
* For a more convenient way to extend the postage batch, refer to the methods below.
|
|
1840
|
-
*
|
|
1841
|
-
* Use {@link getDurationExtensionCost}, {@link getSizeExtensionCost} or {@link getExtensionCost}
|
|
1842
|
-
* to calculate the costs of extending the postage batch properties.
|
|
1843
|
-
*
|
|
1844
|
-
* Use {@link extendStorageDuration}, {@link extendStorageSize} or {@link extendStorage}
|
|
1845
|
-
* to extend the postage batch properties.
|
|
1846
|
-
*
|
|
1847
|
-
* For better understanding what each parameter means and what are the optimal values please see
|
|
1848
|
-
* [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive).
|
|
1849
|
-
*
|
|
1850
|
-
* @param postageBatchId Batch ID
|
|
1851
|
-
* @param depth Amount to be added to the batch
|
|
1852
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1853
|
-
*
|
|
1854
|
-
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
|
|
1855
|
-
* @see [Bee Debug API reference - `PATCH /stamps/topup/${id}/${amount}`](https://docs.ethswarm.org/api/#tag/Postage-Stamps/paths/~1stamps~1dilute~1%7Bbatch_id%7D~1%7Bdepth%7D/patch)
|
|
1856
|
-
*/
|
|
1857
|
-
async diluteBatch(postageBatchId, depth, requestOptions) {
|
|
1858
|
-
postageBatchId = new typed_bytes_1.BatchId(postageBatchId);
|
|
1859
|
-
depth = zod_1.z.number().int().min(18).max(255).parse(depth);
|
|
1860
|
-
return stamps.diluteBatch(this.getRequestOptionsForCall(requestOptions), postageBatchId, depth);
|
|
1861
|
-
}
|
|
1862
|
-
/**
|
|
1863
|
-
* Returns details for specific postage batch.
|
|
1864
|
-
*
|
|
1865
|
-
* @param postageBatchId Batch ID
|
|
1866
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1867
|
-
* @param encryption Assume that uploads with this postage batch are encrypted, which skews the capacity.
|
|
1868
|
-
* @param erasureCodeLevel Assume that uploads with this postage batch are erasure coded, which skews the capacity.
|
|
1869
|
-
*
|
|
1870
|
-
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
|
|
1871
|
-
* @see [Bee Debug API reference - `GET /stamps/${id}`](https://docs.ethswarm.org/api/#tag/Postage-Stamps/paths/~1stamps~1%7Bbatch_id%7D/get)
|
|
1872
|
-
*/
|
|
1873
|
-
async getPostageBatch(postageBatchId, requestOptions, encryption, erasureCodeLevel) {
|
|
1874
|
-
postageBatchId = new typed_bytes_1.BatchId(postageBatchId);
|
|
1875
|
-
return stamps.getPostageBatch(this.getRequestOptionsForCall(requestOptions), postageBatchId, encryption, erasureCodeLevel);
|
|
1876
|
-
}
|
|
1877
|
-
/**
|
|
1878
|
-
* Returns details for specific globally available postage batch.
|
|
1879
|
-
*
|
|
1880
|
-
* @param postageBatchId Batch ID
|
|
1881
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1882
|
-
*/
|
|
1883
|
-
async getGlobalPostageBatch(postageBatchId, requestOptions) {
|
|
1884
|
-
postageBatchId = new typed_bytes_1.BatchId(postageBatchId);
|
|
1885
|
-
return stamps.getGlobalPostageBatch(this.getRequestOptionsForCall(requestOptions), postageBatchId);
|
|
1886
|
-
}
|
|
1887
|
-
/**
|
|
1888
|
-
* Return detailed information related to buckets for specific postage batch.
|
|
1889
|
-
*
|
|
1890
|
-
* @param postageBatchId Batch ID
|
|
1891
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1892
|
-
*
|
|
1893
|
-
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
|
|
1894
|
-
* @see [Bee Debug API reference - `GET /stamps/${id}/buckets`](https://docs.ethswarm.org/api/#tag/Postage-Stamps/paths/~1stamps~1%7Bbatch_id%7D~1buckets/get)
|
|
1895
|
-
*/
|
|
1896
|
-
async getPostageBatchBuckets(postageBatchId, requestOptions) {
|
|
1897
|
-
postageBatchId = new typed_bytes_1.BatchId(postageBatchId);
|
|
1898
|
-
return stamps.getPostageBatchBuckets(this.getRequestOptionsForCall(requestOptions), postageBatchId);
|
|
1899
|
-
}
|
|
1900
|
-
/**
|
|
1901
|
-
* Returns all postage batches that belongs to the node.
|
|
1902
|
-
*
|
|
1903
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1904
|
-
*
|
|
1905
|
-
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
|
|
1906
|
-
* @see [Bee Debug API reference - `GET /stamps`](https://docs.ethswarm.org/api/#tag/Postage-Stamps/paths/~1stamps/get)
|
|
1907
|
-
* @deprecated Use `getPostageBatches` instead
|
|
1908
|
-
*/
|
|
1909
|
-
async getAllPostageBatch(requestOptions) {
|
|
1910
|
-
return stamps.getAllPostageBatches(this.getRequestOptionsForCall(requestOptions)); // TODO: remove in June 2025
|
|
1911
|
-
}
|
|
1912
|
-
/**
|
|
1913
|
-
* Returns all postage batches that are globally available on the Swarm network.
|
|
1914
|
-
*
|
|
1915
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1916
|
-
*
|
|
1917
|
-
* @deprecated Use `getGlobalPostageBatches` instead
|
|
1918
|
-
*/
|
|
1919
|
-
async getAllGlobalPostageBatch(requestOptions) {
|
|
1920
|
-
return stamps.getGlobalPostageBatches(this.getRequestOptionsForCall(requestOptions)); // TODO: remove in June 2025
|
|
1921
|
-
}
|
|
1922
|
-
/**
|
|
1923
|
-
* Returns all postage batches that belong to the node.
|
|
1924
|
-
*
|
|
1925
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1926
|
-
*
|
|
1927
|
-
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
|
|
1928
|
-
* @see [Bee Debug API reference - `GET /stamps`](https://docs.ethswarm.org/api/#tag/Postage-Stamps/paths/~1stamps/get)
|
|
1929
|
-
*/
|
|
1930
|
-
async getPostageBatches(requestOptions) {
|
|
1931
|
-
return stamps.getAllPostageBatches(this.getRequestOptionsForCall(requestOptions));
|
|
1932
|
-
}
|
|
1933
|
-
/**
|
|
1934
|
-
* Returns all globally available postage batches.
|
|
1935
|
-
*
|
|
1936
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1937
|
-
*/
|
|
1938
|
-
async getGlobalPostageBatches(requestOptions) {
|
|
1939
|
-
return stamps.getGlobalPostageBatches(this.getRequestOptionsForCall(requestOptions));
|
|
1940
|
-
}
|
|
1941
|
-
/**
|
|
1942
|
-
* Fetches the list of all current pending transactions for the Bee node.
|
|
1943
|
-
*
|
|
1944
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1945
|
-
*/
|
|
1946
|
-
async getAllPendingTransactions(requestOptions) {
|
|
1947
|
-
return transactions.getAllTransactions(this.getRequestOptionsForCall(requestOptions));
|
|
1948
|
-
}
|
|
1949
|
-
/**
|
|
1950
|
-
* Fetches the transaction information for a specific transaction.
|
|
1951
|
-
*
|
|
1952
|
-
* @param transactionHash
|
|
1953
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1954
|
-
*/
|
|
1955
|
-
async getPendingTransaction(transactionHash, requestOptions) {
|
|
1956
|
-
transactionHash = new typed_bytes_1.TransactionId(transactionHash);
|
|
1957
|
-
return transactions.getTransaction(this.getRequestOptionsForCall(requestOptions), transactionHash);
|
|
1958
|
-
}
|
|
1959
|
-
/**
|
|
1960
|
-
* Rebroadcasts already created transaction.
|
|
1961
|
-
*
|
|
1962
|
-
* This is mainly needed when the transaction falls off mempool or is not incorporated into any block.
|
|
1963
|
-
*
|
|
1964
|
-
* @param transactionHash
|
|
1965
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1966
|
-
*/
|
|
1967
|
-
async rebroadcastPendingTransaction(transactionHash, requestOptions) {
|
|
1968
|
-
transactionHash = new typed_bytes_1.TransactionId(transactionHash);
|
|
1969
|
-
return transactions.rebroadcastTransaction(this.getRequestOptionsForCall(requestOptions), transactionHash);
|
|
1970
|
-
}
|
|
1971
|
-
/**
|
|
1972
|
-
* Cancels a currently pending transaction.
|
|
1973
|
-
*
|
|
1974
|
-
* @param transactionHash
|
|
1975
|
-
* @param gasPrice
|
|
1976
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1977
|
-
*/
|
|
1978
|
-
async cancelPendingTransaction(transactionHash, gasPrice, requestOptions) {
|
|
1979
|
-
transactionHash = new typed_bytes_1.TransactionId(transactionHash);
|
|
1980
|
-
let gasPriceString;
|
|
1981
|
-
if (gasPrice) {
|
|
1982
|
-
gasPriceString = (0, type_1.asNumberString)(gasPrice, { min: 0n, name: 'gasPrice' });
|
|
1983
|
-
}
|
|
1984
|
-
return transactions.cancelTransaction(this.getRequestOptionsForCall(requestOptions), transactionHash, gasPriceString);
|
|
1985
|
-
}
|
|
1986
|
-
/**
|
|
1987
|
-
* Gets the amount of staked BZZ.
|
|
1988
|
-
*
|
|
1989
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1990
|
-
*/
|
|
1991
|
-
async getStake(requestOptions) {
|
|
1992
|
-
return stake.getStake(this.getRequestOptionsForCall(requestOptions));
|
|
1993
|
-
}
|
|
1994
|
-
/**
|
|
1995
|
-
* Gets the amount of withdrawable staked BZZ.
|
|
1996
|
-
*
|
|
1997
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1998
|
-
*/
|
|
1999
|
-
async getWithdrawableStake(requestOptions) {
|
|
2000
|
-
return stake.getWithdrawableStake(this.getRequestOptionsForCall(requestOptions));
|
|
2001
|
-
}
|
|
2002
|
-
/**
|
|
2003
|
-
* Withdraws all surplus staked BZZ to the node wallet.
|
|
2004
|
-
*
|
|
2005
|
-
* Use the {@link getWithdrawableStake} method to check how much surplus stake is available.
|
|
2006
|
-
*
|
|
2007
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
2008
|
-
*/
|
|
2009
|
-
async withdrawSurplusStake(requestOptions) {
|
|
2010
|
-
return stake.withdrawSurplusStake(this.getRequestOptionsForCall(requestOptions));
|
|
2011
|
-
}
|
|
2012
|
-
/**
|
|
2013
|
-
* Withdraws all staked BZZ to the node wallet.
|
|
2014
|
-
*
|
|
2015
|
-
* **Only available when the staking contract is paused and is in the process of being migrated to a new contract!**
|
|
2016
|
-
*
|
|
2017
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
2018
|
-
*/
|
|
2019
|
-
async migrateStake(requestOptions) {
|
|
2020
|
-
return stake.migrateStake(this.getRequestOptionsForCall(requestOptions));
|
|
2021
|
-
}
|
|
2022
|
-
/**
|
|
2023
|
-
* Stakes the given amount of BZZ. Initial deposit must be at least 10 BZZ.
|
|
2024
|
-
*
|
|
2025
|
-
* Be aware that staked BZZ tokens can **not** be withdrawn.
|
|
2026
|
-
*
|
|
2027
|
-
* @param amount Amount of BZZ tokens to be staked. If not providing a `BZZ` instance, the amount is denoted in PLUR.
|
|
2028
|
-
* @param options
|
|
2029
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
2030
|
-
*/
|
|
2031
|
-
async depositStake(amount, options, requestOptions) {
|
|
2032
|
-
const amountString = amount instanceof tokens_1.BZZ ? amount.toPLURString() : (0, type_1.asNumberString)(amount, { min: 1n, name: 'amount' });
|
|
2033
|
-
if (options) {
|
|
2034
|
-
options = schema_1.TransactionOptionsSchema.parse(options);
|
|
2035
|
-
}
|
|
2036
|
-
return stake.stake(this.getRequestOptionsForCall(requestOptions), amountString, options);
|
|
2037
|
-
}
|
|
2038
|
-
/**
|
|
2039
|
-
* Gets current status of node in redistribution game.
|
|
2040
|
-
*
|
|
2041
|
-
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
2042
|
-
*
|
|
2043
|
-
* @see [Bee API reference - `GET /redistributionstate`](https://docs.ethswarm.org/api/#tag/RedistributionState/paths/~1redistributionstate/get)
|
|
2044
|
-
*/
|
|
2045
|
-
async getRedistributionState(requestOptions) {
|
|
2046
|
-
return stake.getRedistributionState(this.getRequestOptionsForCall(requestOptions));
|
|
2047
|
-
}
|
|
2048
|
-
async waitForUsablePostageStamp(id, timeout = 240000) {
|
|
2049
|
-
const TIME_STEP = 3000;
|
|
2050
|
-
for (let time = 0; time < timeout; time += TIME_STEP) {
|
|
2051
|
-
try {
|
|
2052
|
-
const stamp = await this.getPostageBatch(id);
|
|
2053
|
-
if (stamp.usable) {
|
|
2054
|
-
return;
|
|
2055
|
-
}
|
|
2056
|
-
}
|
|
2057
|
-
catch (error) {
|
|
2058
|
-
// ignore error
|
|
2059
|
-
}
|
|
2060
|
-
await cafe_utility_1.System.sleepMillis(TIME_STEP);
|
|
2061
|
-
}
|
|
2062
|
-
throw new error_1.BeeError('Timeout on waiting for postage stamp to become usable');
|
|
2063
|
-
}
|
|
2064
201
|
getRequestOptionsForCall(requestOptions) {
|
|
2065
202
|
if (requestOptions) {
|
|
2066
203
|
requestOptions = schema_1.BeeRequestOptionsSchema.parse(requestOptions);
|