@ethersphere/bee-js 8.3.1 → 9.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +192 -50
- package/dist/cjs/bee-dev.js +78 -0
- package/dist/cjs/bee.js +341 -417
- package/dist/cjs/chunk/bmt.js +15 -32
- package/dist/cjs/chunk/cac.js +26 -36
- package/dist/cjs/chunk/soc.js +56 -51
- package/dist/cjs/feed/identifier.js +3 -28
- package/dist/cjs/feed/index.js +95 -44
- package/dist/cjs/feed/retrievable.js +11 -22
- package/dist/cjs/index.js +17 -1
- package/dist/cjs/manifest/manifest.js +369 -0
- package/dist/cjs/modules/bytes.js +24 -12
- package/dist/cjs/modules/bzz.js +24 -34
- package/dist/cjs/modules/chunk.js +13 -7
- package/dist/cjs/modules/debug/balance.js +29 -4
- package/dist/cjs/modules/debug/chequebook.js +60 -16
- package/dist/cjs/modules/debug/connectivity.js +82 -4
- package/dist/cjs/modules/debug/settlements.js +22 -2
- package/dist/cjs/modules/debug/stake.js +29 -11
- package/dist/cjs/modules/debug/stamps.js +88 -7
- package/dist/cjs/modules/debug/states.js +25 -3
- package/dist/cjs/modules/debug/status.js +45 -47
- package/dist/cjs/modules/debug/transactions.js +27 -5
- package/dist/cjs/modules/envelope.js +8 -6
- package/dist/cjs/modules/feed.js +25 -10
- package/dist/cjs/modules/grantee.js +18 -12
- package/dist/cjs/modules/gsoc.js +24 -0
- package/dist/cjs/modules/pinning.js +13 -2
- package/dist/cjs/modules/pss.js +9 -3
- package/dist/cjs/modules/soc.js +9 -4
- package/dist/cjs/modules/stewardship.js +7 -3
- package/dist/cjs/modules/tag.js +35 -3
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/stamper/stamper.js +43 -0
- package/dist/cjs/types/debug.js +16 -1
- package/dist/cjs/types/index.js +2 -24
- package/dist/cjs/utils/bytes.js +67 -115
- package/dist/cjs/utils/chunk-size.js +17 -0
- package/dist/cjs/utils/chunk-stream.browser.js +85 -0
- package/dist/cjs/utils/chunk-stream.js +84 -0
- package/dist/cjs/utils/cid.js +5 -6
- package/dist/cjs/utils/collection.browser.js +2 -2
- package/dist/cjs/utils/collection.js +3 -2
- package/dist/cjs/utils/collection.node.js +0 -2
- package/dist/cjs/utils/constants.js +7 -3
- package/dist/cjs/utils/data.browser.js +6 -3
- package/dist/cjs/utils/data.js +8 -4
- package/dist/cjs/utils/duration.js +51 -0
- package/dist/cjs/utils/expose.js +11 -40
- package/dist/cjs/utils/headers.js +79 -52
- package/dist/cjs/utils/http.js +34 -10
- package/dist/cjs/utils/mime.js +78 -0
- package/dist/cjs/utils/pss.js +3 -4
- package/dist/cjs/utils/redundancy.js +18 -14
- package/dist/cjs/utils/resource-locator.js +17 -0
- package/dist/cjs/utils/size.js +35 -0
- package/dist/cjs/utils/stamps.js +67 -51
- package/dist/cjs/utils/tar-uploader.browser.js +2 -2
- package/dist/cjs/utils/tar-uploader.js +2 -2
- package/dist/cjs/utils/tokens.js +144 -0
- package/dist/cjs/utils/type.js +142 -350
- package/dist/cjs/utils/typed-bytes.js +179 -0
- package/dist/cjs/utils/upload-progress.js +2 -0
- package/dist/cjs/utils/url.js +0 -4
- package/dist/cjs/utils/workaround.js +27 -0
- package/dist/index.browser.min.js +1 -2
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/bee-dev.js +98 -0
- package/dist/mjs/bee.js +367 -411
- package/dist/mjs/chunk/bmt.js +13 -29
- package/dist/mjs/chunk/cac.js +26 -34
- package/dist/mjs/chunk/soc.js +57 -53
- package/dist/mjs/feed/identifier.js +3 -26
- package/dist/mjs/feed/index.js +98 -51
- package/dist/mjs/feed/retrievable.js +12 -23
- package/dist/mjs/index.js +10 -1
- package/dist/mjs/manifest/manifest.js +371 -0
- package/dist/mjs/modules/bytes.js +27 -15
- package/dist/mjs/modules/bzz.js +25 -32
- package/dist/mjs/modules/chunk.js +16 -8
- package/dist/mjs/modules/debug/balance.js +61 -4
- package/dist/mjs/modules/debug/chequebook.js +116 -16
- package/dist/mjs/modules/debug/connectivity.js +144 -3
- package/dist/mjs/modules/debug/settlements.js +46 -2
- package/dist/mjs/modules/debug/stake.js +69 -11
- package/dist/mjs/modules/debug/stamps.js +184 -7
- package/dist/mjs/modules/debug/states.js +55 -3
- package/dist/mjs/modules/debug/status.js +97 -45
- package/dist/mjs/modules/debug/transactions.js +61 -5
- package/dist/mjs/modules/envelope.js +11 -9
- package/dist/mjs/modules/feed.js +26 -10
- package/dist/mjs/modules/grantee.js +35 -13
- package/dist/mjs/modules/gsoc.js +16 -0
- package/dist/mjs/modules/pinning.js +23 -2
- package/dist/mjs/modules/pss.js +10 -4
- package/dist/mjs/modules/soc.js +10 -5
- package/dist/mjs/modules/stewardship.js +14 -4
- package/dist/mjs/modules/tag.js +93 -3
- package/dist/mjs/package.json +2 -1
- package/dist/mjs/stamper/stamper.js +39 -0
- package/dist/mjs/types/debug.js +15 -1
- package/dist/mjs/types/index.js +2 -24
- package/dist/mjs/utils/bytes.js +63 -104
- package/dist/mjs/utils/chunk-size.js +13 -0
- package/dist/mjs/utils/chunk-stream.browser.js +85 -0
- package/dist/mjs/utils/chunk-stream.js +87 -0
- package/dist/mjs/utils/cid.js +5 -6
- package/dist/mjs/utils/collection.browser.js +2 -2
- package/dist/mjs/utils/collection.js +2 -2
- package/dist/mjs/utils/collection.node.js +0 -2
- package/dist/mjs/utils/constants.js +6 -2
- package/dist/mjs/utils/data.browser.js +9 -3
- package/dist/mjs/utils/data.js +12 -4
- package/dist/mjs/utils/duration.js +47 -0
- package/dist/mjs/utils/expose.js +2 -7
- package/dist/mjs/utils/headers.js +73 -48
- package/dist/mjs/utils/http.js +33 -11
- package/dist/mjs/utils/mime.js +75 -0
- package/dist/mjs/utils/pss.js +3 -4
- package/dist/mjs/utils/redundancy.js +18 -8
- package/dist/mjs/utils/resource-locator.js +13 -0
- package/dist/mjs/utils/size.js +31 -0
- package/dist/mjs/utils/stamps.js +47 -44
- package/dist/mjs/utils/tar-uploader.browser.js +2 -2
- package/dist/mjs/utils/tar-uploader.js +2 -2
- package/dist/mjs/utils/tokens.js +139 -0
- package/dist/mjs/utils/type.js +216 -310
- package/dist/mjs/utils/typed-bytes.js +160 -0
- package/dist/mjs/utils/upload-progress.js +1 -0
- package/dist/mjs/utils/url.js +0 -4
- package/dist/mjs/utils/workaround.js +22 -0
- package/dist/types/bee-dev.d.ts +5 -0
- package/dist/types/bee.d.ts +88 -165
- package/dist/types/chunk/bmt.d.ts +2 -2
- package/dist/types/chunk/cac.d.ts +7 -24
- package/dist/types/chunk/soc.d.ts +15 -15
- package/dist/types/feed/identifier.d.ts +2 -4
- package/dist/types/feed/index.d.ts +14 -18
- package/dist/types/feed/retrievable.d.ts +3 -4
- package/dist/types/index.d.ts +28 -1
- package/dist/types/manifest/manifest.d.ts +106 -0
- package/dist/types/modules/bytes.d.ts +8 -5
- package/dist/types/modules/bzz.d.ts +8 -10
- package/dist/types/modules/chunk.d.ts +4 -3
- package/dist/types/modules/debug/balance.d.ts +3 -2
- package/dist/types/modules/debug/chequebook.d.ts +7 -6
- package/dist/types/modules/debug/connectivity.d.ts +5 -3
- package/dist/types/modules/debug/settlements.d.ts +2 -1
- package/dist/types/modules/debug/stake.d.ts +4 -2
- package/dist/types/modules/debug/stamps.d.ts +5 -4
- package/dist/types/modules/debug/status.d.ts +6 -25
- package/dist/types/modules/debug/transactions.d.ts +5 -4
- package/dist/types/modules/envelope.d.ts +3 -2
- package/dist/types/modules/feed.d.ts +20 -16
- package/dist/types/modules/grantee.d.ts +7 -6
- package/dist/types/modules/gsoc.d.ts +7 -0
- package/dist/types/modules/pinning.d.ts +2 -4
- package/dist/types/modules/pss.d.ts +4 -3
- package/dist/types/modules/soc.d.ts +3 -2
- package/dist/types/modules/stewardship.d.ts +4 -4
- package/dist/types/modules/tag.d.ts +2 -1
- package/dist/types/stamper/stamper.d.ts +15 -0
- package/dist/types/types/debug.d.ts +63 -115
- package/dist/types/types/index.d.ts +103 -204
- package/dist/types/utils/bytes.d.ts +16 -90
- package/dist/types/utils/chunk-size.d.ts +1 -0
- package/dist/types/utils/chunk-stream.browser.d.ts +6 -0
- package/dist/types/utils/chunk-stream.d.ts +6 -0
- package/dist/types/utils/cid.d.ts +3 -2
- package/dist/types/utils/collection.browser.d.ts +2 -2
- package/dist/types/utils/collection.d.ts +2 -1
- package/dist/types/utils/collection.node.d.ts +0 -1
- package/dist/types/utils/constants.d.ts +4 -1
- package/dist/types/utils/duration.d.ts +17 -0
- package/dist/types/utils/error.d.ts +2 -2
- package/dist/types/utils/expose.d.ts +2 -7
- package/dist/types/utils/headers.d.ts +3 -4
- package/dist/types/utils/mime.d.ts +1 -0
- package/dist/types/utils/pss.d.ts +2 -2
- package/dist/types/utils/resource-locator.d.ts +6 -0
- package/dist/types/utils/size.d.ts +16 -0
- package/dist/types/utils/stamps.d.ts +27 -33
- package/dist/types/utils/tar-uploader.browser.d.ts +3 -4
- package/dist/types/utils/tar-uploader.d.ts +3 -4
- package/dist/types/utils/tokens.d.ts +77 -0
- package/dist/types/utils/type.d.ts +20 -52
- package/dist/types/utils/typed-bytes.d.ts +68 -0
- package/dist/types/utils/upload-progress.d.ts +4 -0
- package/dist/types/utils/workaround.d.ts +2 -0
- package/package.json +11 -17
- package/dist/cjs/chunk/signer.js +0 -126
- package/dist/cjs/chunk/span.js +0 -25
- package/dist/cjs/feed/json.js +0 -28
- package/dist/cjs/feed/topic.js +0 -25
- package/dist/cjs/feed/type.js +0 -15
- package/dist/cjs/modules/debug/chunk.js +0 -21
- package/dist/cjs/modules/debug/tag.js +0 -19
- package/dist/cjs/utils/eth.js +0 -216
- package/dist/cjs/utils/hash.js +0 -21
- package/dist/cjs/utils/hex.js +0 -150
- package/dist/cjs/utils/reference.js +0 -36
- package/dist/index.browser.min.js.LICENSE.txt +0 -8
- package/dist/mjs/chunk/signer.js +0 -114
- package/dist/mjs/chunk/span.js +0 -21
- package/dist/mjs/feed/json.js +0 -26
- package/dist/mjs/feed/topic.js +0 -19
- package/dist/mjs/feed/type.js +0 -10
- package/dist/mjs/modules/debug/chunk.js +0 -17
- package/dist/mjs/modules/debug/tag.js +0 -15
- package/dist/mjs/utils/eth.js +0 -192
- package/dist/mjs/utils/hash.js +0 -16
- package/dist/mjs/utils/hex.js +0 -135
- package/dist/mjs/utils/reference.js +0 -29
- package/dist/types/chunk/signer.d.ts +0 -31
- package/dist/types/chunk/span.d.ts +0 -10
- package/dist/types/feed/json.d.ts +0 -4
- package/dist/types/feed/topic.d.ts +0 -3
- package/dist/types/feed/type.d.ts +0 -6
- package/dist/types/modules/debug/chunk.d.ts +0 -10
- package/dist/types/modules/debug/tag.d.ts +0 -8
- package/dist/types/utils/eth.d.ts +0 -67
- package/dist/types/utils/hash.d.ts +0 -9
- package/dist/types/utils/hex.d.ts +0 -86
- package/dist/types/utils/reference.d.ts +0 -2
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Duration = void 0;
|
|
4
|
+
class Duration {
|
|
5
|
+
constructor(seconds) {
|
|
6
|
+
this.seconds = Math.ceil(seconds);
|
|
7
|
+
if (seconds <= 0) {
|
|
8
|
+
throw Error('Duration must be greater than 0');
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
static fromMilliseconds(milliseconds) {
|
|
12
|
+
return new Duration(milliseconds / 1000);
|
|
13
|
+
}
|
|
14
|
+
static fromSeconds(seconds) {
|
|
15
|
+
return new Duration(seconds);
|
|
16
|
+
}
|
|
17
|
+
static fromHours(hours) {
|
|
18
|
+
return new Duration(hours * 60 * 60);
|
|
19
|
+
}
|
|
20
|
+
static fromDays(days) {
|
|
21
|
+
return new Duration(days * 24 * 60 * 60);
|
|
22
|
+
}
|
|
23
|
+
static fromWeeks(weeks) {
|
|
24
|
+
return new Duration(weeks * 7 * 24 * 60 * 60);
|
|
25
|
+
}
|
|
26
|
+
static fromYears(years) {
|
|
27
|
+
return new Duration(years * 365 * 24 * 60 * 60);
|
|
28
|
+
}
|
|
29
|
+
static fromEndDate(endDate, startDate) {
|
|
30
|
+
return new Duration((endDate.getTime() - (startDate ?? new Date()).getTime()) / 1000);
|
|
31
|
+
}
|
|
32
|
+
toSeconds() {
|
|
33
|
+
return this.seconds;
|
|
34
|
+
}
|
|
35
|
+
toHours() {
|
|
36
|
+
return this.seconds / 60 / 60;
|
|
37
|
+
}
|
|
38
|
+
toDays() {
|
|
39
|
+
return this.seconds / 24 / 60 / 60;
|
|
40
|
+
}
|
|
41
|
+
toWeeks() {
|
|
42
|
+
return this.seconds / 7 / 24 / 60 / 60;
|
|
43
|
+
}
|
|
44
|
+
toYears() {
|
|
45
|
+
return this.seconds / 365 / 24 / 60 / 60;
|
|
46
|
+
}
|
|
47
|
+
toEndDate(startDate) {
|
|
48
|
+
return new Date((startDate ?? new Date()).getTime() + this.seconds * 1000);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.Duration = Duration;
|
package/dist/cjs/utils/expose.js
CHANGED
|
@@ -1,52 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getStampUsage = exports.getStampTheoreticalBytes = exports.getStampEffectiveBytesBreakpoints = exports.getStampEffectiveBytes = exports.getStampDuration = exports.getStampCost = exports.getDepthForSize = exports.getAmountForDuration = exports.getRedundancyStats = exports.getRedundancyStat = exports.approximateOverheadForRedundancyLevel = exports.makeMaxTarget = exports.getFolderSize = exports.makeCollectionFromFileList = exports.getCollectionSize = void 0;
|
|
4
4
|
var collection_1 = require("./collection");
|
|
5
5
|
Object.defineProperty(exports, "getCollectionSize", { enumerable: true, get: function () { return collection_1.getCollectionSize; } });
|
|
6
|
+
Object.defineProperty(exports, "makeCollectionFromFileList", { enumerable: true, get: function () { return collection_1.makeCollectionFromFileList; } });
|
|
6
7
|
var collection_node_1 = require("./collection.node");
|
|
7
8
|
Object.defineProperty(exports, "getFolderSize", { enumerable: true, get: function () { return collection_node_1.getFolderSize; } });
|
|
8
|
-
var bytes_1 = require("./bytes");
|
|
9
|
-
Object.defineProperty(exports, "assertBytes", { enumerable: true, get: function () { return bytes_1.assertBytes; } });
|
|
10
|
-
Object.defineProperty(exports, "assertFlexBytes", { enumerable: true, get: function () { return bytes_1.assertFlexBytes; } });
|
|
11
|
-
Object.defineProperty(exports, "bytesAtOffset", { enumerable: true, get: function () { return bytes_1.bytesAtOffset; } });
|
|
12
|
-
Object.defineProperty(exports, "bytesEqual", { enumerable: true, get: function () { return bytes_1.bytesEqual; } });
|
|
13
|
-
Object.defineProperty(exports, "flexBytesAtOffset", { enumerable: true, get: function () { return bytes_1.flexBytesAtOffset; } });
|
|
14
|
-
Object.defineProperty(exports, "isBytes", { enumerable: true, get: function () { return bytes_1.isBytes; } });
|
|
15
|
-
Object.defineProperty(exports, "isFlexBytes", { enumerable: true, get: function () { return bytes_1.isFlexBytes; } });
|
|
16
|
-
var hex_1 = require("./hex");
|
|
17
|
-
Object.defineProperty(exports, "assertHexString", { enumerable: true, get: function () { return hex_1.assertHexString; } });
|
|
18
|
-
Object.defineProperty(exports, "assertPrefixedHexString", { enumerable: true, get: function () { return hex_1.assertPrefixedHexString; } });
|
|
19
|
-
Object.defineProperty(exports, "bytesToHex", { enumerable: true, get: function () { return hex_1.bytesToHex; } });
|
|
20
|
-
Object.defineProperty(exports, "hexToBytes", { enumerable: true, get: function () { return hex_1.hexToBytes; } });
|
|
21
|
-
Object.defineProperty(exports, "intToHex", { enumerable: true, get: function () { return hex_1.intToHex; } });
|
|
22
|
-
Object.defineProperty(exports, "isHexString", { enumerable: true, get: function () { return hex_1.isHexString; } });
|
|
23
|
-
Object.defineProperty(exports, "makeHexString", { enumerable: true, get: function () { return hex_1.makeHexString; } });
|
|
24
|
-
var eth_1 = require("./eth");
|
|
25
|
-
Object.defineProperty(exports, "capitalizeAddressERC55", { enumerable: true, get: function () { return eth_1.capitalizeAddressERC55; } });
|
|
26
|
-
Object.defineProperty(exports, "ethToSwarmAddress", { enumerable: true, get: function () { return eth_1.ethToSwarmAddress; } });
|
|
27
|
-
Object.defineProperty(exports, "fromLittleEndian", { enumerable: true, get: function () { return eth_1.fromLittleEndian; } });
|
|
28
|
-
Object.defineProperty(exports, "isHexEthAddress", { enumerable: true, get: function () { return eth_1.isHexEthAddress; } });
|
|
29
|
-
Object.defineProperty(exports, "makeEthAddress", { enumerable: true, get: function () { return eth_1.makeEthAddress; } });
|
|
30
|
-
Object.defineProperty(exports, "makeEthereumWalletSigner", { enumerable: true, get: function () { return eth_1.makeEthereumWalletSigner; } });
|
|
31
|
-
Object.defineProperty(exports, "makeHexEthAddress", { enumerable: true, get: function () { return eth_1.makeHexEthAddress; } });
|
|
32
|
-
Object.defineProperty(exports, "toLittleEndian", { enumerable: true, get: function () { return eth_1.toLittleEndian; } });
|
|
33
|
-
var hash_1 = require("./hash");
|
|
34
|
-
Object.defineProperty(exports, "keccak256Hash", { enumerable: true, get: function () { return hash_1.keccak256Hash; } });
|
|
35
9
|
var pss_1 = require("./pss");
|
|
36
10
|
Object.defineProperty(exports, "makeMaxTarget", { enumerable: true, get: function () { return pss_1.makeMaxTarget; } });
|
|
37
|
-
var stamps_1 = require("./stamps");
|
|
38
|
-
Object.defineProperty(exports, "getAmountForTtl", { enumerable: true, get: function () { return stamps_1.getAmountForTtl; } });
|
|
39
|
-
Object.defineProperty(exports, "getDepthForCapacity", { enumerable: true, get: function () { return stamps_1.getDepthForCapacity; } });
|
|
40
|
-
Object.defineProperty(exports, "getStampCostInBzz", { enumerable: true, get: function () { return stamps_1.getStampCostInBzz; } });
|
|
41
|
-
Object.defineProperty(exports, "getStampCostInPlur", { enumerable: true, get: function () { return stamps_1.getStampCostInPlur; } });
|
|
42
|
-
Object.defineProperty(exports, "getStampEffectiveBytes", { enumerable: true, get: function () { return stamps_1.getStampEffectiveBytes; } });
|
|
43
|
-
Object.defineProperty(exports, "getStampMaximumCapacityBytes", { enumerable: true, get: function () { return stamps_1.getStampMaximumCapacityBytes; } });
|
|
44
|
-
Object.defineProperty(exports, "getStampTtlSeconds", { enumerable: true, get: function () { return stamps_1.getStampTtlSeconds; } });
|
|
45
|
-
Object.defineProperty(exports, "getStampUsage", { enumerable: true, get: function () { return stamps_1.getStampUsage; } });
|
|
46
11
|
var redundancy_1 = require("./redundancy");
|
|
47
12
|
Object.defineProperty(exports, "approximateOverheadForRedundancyLevel", { enumerable: true, get: function () { return redundancy_1.approximateOverheadForRedundancyLevel; } });
|
|
48
13
|
Object.defineProperty(exports, "getRedundancyStat", { enumerable: true, get: function () { return redundancy_1.getRedundancyStat; } });
|
|
49
14
|
Object.defineProperty(exports, "getRedundancyStats", { enumerable: true, get: function () { return redundancy_1.getRedundancyStats; } });
|
|
50
|
-
var
|
|
51
|
-
Object.defineProperty(exports, "
|
|
52
|
-
Object.defineProperty(exports, "
|
|
15
|
+
var stamps_1 = require("./stamps");
|
|
16
|
+
Object.defineProperty(exports, "getAmountForDuration", { enumerable: true, get: function () { return stamps_1.getAmountForDuration; } });
|
|
17
|
+
Object.defineProperty(exports, "getDepthForSize", { enumerable: true, get: function () { return stamps_1.getDepthForSize; } });
|
|
18
|
+
Object.defineProperty(exports, "getStampCost", { enumerable: true, get: function () { return stamps_1.getStampCost; } });
|
|
19
|
+
Object.defineProperty(exports, "getStampDuration", { enumerable: true, get: function () { return stamps_1.getStampDuration; } });
|
|
20
|
+
Object.defineProperty(exports, "getStampEffectiveBytes", { enumerable: true, get: function () { return stamps_1.getStampEffectiveBytes; } });
|
|
21
|
+
Object.defineProperty(exports, "getStampEffectiveBytesBreakpoints", { enumerable: true, get: function () { return stamps_1.getStampEffectiveBytesBreakpoints; } });
|
|
22
|
+
Object.defineProperty(exports, "getStampTheoreticalBytes", { enumerable: true, get: function () { return stamps_1.getStampTheoreticalBytes; } });
|
|
23
|
+
Object.defineProperty(exports, "getStampUsage", { enumerable: true, get: function () { return stamps_1.getStampUsage; } });
|
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.prepareRequestHeaders = exports.readFileHeaders = void 0;
|
|
4
4
|
const cafe_utility_1 = require("cafe-utility");
|
|
5
5
|
const error_1 = require("./error");
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
const stamps_1 = require("./stamps");
|
|
7
|
+
const typed_bytes_1 = require("./typed-bytes");
|
|
8
|
+
function readFileHeaders(headers) {
|
|
9
|
+
const name = readContentDispositionFilename(headers['content-disposition']);
|
|
10
|
+
const tagUid = readTagUid(headers['swarm-tag-uid']);
|
|
11
|
+
const contentType = headers['content-type'] || undefined;
|
|
12
|
+
return {
|
|
13
|
+
name,
|
|
14
|
+
tagUid,
|
|
15
|
+
contentType,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
exports.readFileHeaders = readFileHeaders;
|
|
14
19
|
function readContentDispositionFilename(header) {
|
|
15
20
|
if (!header) {
|
|
16
21
|
throw new error_1.BeeError('missing content-disposition header');
|
|
@@ -29,65 +34,87 @@ function readTagUid(header) {
|
|
|
29
34
|
}
|
|
30
35
|
return parseInt(header, 10);
|
|
31
36
|
}
|
|
32
|
-
function
|
|
33
|
-
const name = readContentDispositionFilename(headers['content-disposition']);
|
|
34
|
-
const tagUid = readTagUid(headers['swarm-tag-uid']);
|
|
35
|
-
const contentType = headers['content-type'] || undefined;
|
|
36
|
-
return {
|
|
37
|
-
name,
|
|
38
|
-
tagUid,
|
|
39
|
-
contentType,
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
exports.readFileHeaders = readFileHeaders;
|
|
43
|
-
function extractUploadHeaders(stamp, options) {
|
|
44
|
-
if (!stamp) {
|
|
45
|
-
throw new error_1.BeeError('Stamp has to be specified!');
|
|
46
|
-
}
|
|
37
|
+
function prepareRequestHeaders(stamp, nullableOptions) {
|
|
47
38
|
const headers = {};
|
|
48
|
-
if (stamp
|
|
49
|
-
headers['swarm-postage-stamp'] =
|
|
39
|
+
if (isEnvelopeWithBatchId(stamp)) {
|
|
40
|
+
headers['swarm-postage-stamp'] = (0, stamps_1.convertEnvelopeToMarshaledStamp)(stamp).toHex();
|
|
50
41
|
}
|
|
51
|
-
else {
|
|
52
|
-
|
|
42
|
+
else if (stamp) {
|
|
43
|
+
stamp = new typed_bytes_1.BatchId(stamp);
|
|
44
|
+
headers['swarm-postage-batch-id'] = stamp.toHex();
|
|
53
45
|
}
|
|
54
|
-
if (
|
|
46
|
+
if (!nullableOptions) {
|
|
47
|
+
return headers;
|
|
48
|
+
}
|
|
49
|
+
const options = cafe_utility_1.Types.asObject(nullableOptions);
|
|
50
|
+
if (options.size) {
|
|
51
|
+
headers['content-length'] = String(options.size);
|
|
52
|
+
}
|
|
53
|
+
if (options.contentType) {
|
|
54
|
+
headers['content-type'] = String(options.contentType);
|
|
55
|
+
}
|
|
56
|
+
if (options.redundancyLevel) {
|
|
57
|
+
headers['swarm-redundancy-level'] = String(options.redundancyLevel);
|
|
58
|
+
}
|
|
59
|
+
if (cafe_utility_1.Types.isBoolean(options.act)) {
|
|
55
60
|
headers['swarm-act'] = String(options.act);
|
|
56
61
|
}
|
|
57
|
-
if (options
|
|
62
|
+
if (cafe_utility_1.Types.isBoolean(options.pin)) {
|
|
58
63
|
headers['swarm-pin'] = String(options.pin);
|
|
59
64
|
}
|
|
60
|
-
if (options
|
|
61
|
-
headers['swarm-encrypt'] =
|
|
65
|
+
if (cafe_utility_1.Types.isBoolean(options.encrypt)) {
|
|
66
|
+
headers['swarm-encrypt'] = options.encrypt.toString();
|
|
62
67
|
}
|
|
63
|
-
if (options
|
|
68
|
+
if (options.tag) {
|
|
64
69
|
headers['swarm-tag'] = String(options.tag);
|
|
65
70
|
}
|
|
66
|
-
if (
|
|
71
|
+
if (cafe_utility_1.Types.isBoolean(options.deferred)) {
|
|
67
72
|
headers['swarm-deferred-upload'] = options.deferred.toString();
|
|
68
73
|
}
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
exports.extractUploadHeaders = extractUploadHeaders;
|
|
72
|
-
function extractRedundantUploadHeaders(postageBatchId, options) {
|
|
73
|
-
const headers = extractUploadHeaders(postageBatchId, options);
|
|
74
|
-
if (options?.redundancyLevel) {
|
|
75
|
-
headers['swarm-redundancy-level'] = String(options.redundancyLevel);
|
|
76
|
-
}
|
|
77
|
-
return headers;
|
|
78
|
-
}
|
|
79
|
-
exports.extractRedundantUploadHeaders = extractRedundantUploadHeaders;
|
|
80
|
-
function extractDownloadHeaders(options) {
|
|
81
|
-
const headers = {};
|
|
82
|
-
if (options?.redundancyStrategy) {
|
|
74
|
+
if (options.redundancyStrategy) {
|
|
83
75
|
headers['swarm-redundancy-strategy'] = String(options.redundancyStrategy);
|
|
84
76
|
}
|
|
85
|
-
if (options
|
|
86
|
-
headers['swarm-redundancy-fallback-mode'] =
|
|
77
|
+
if (cafe_utility_1.Types.isBoolean(options.fallback)) {
|
|
78
|
+
headers['swarm-redundancy-fallback-mode'] = options.fallback.toString();
|
|
87
79
|
}
|
|
88
|
-
if (options
|
|
80
|
+
if (options.timeoutMs) {
|
|
89
81
|
headers['swarm-chunk-retrieval-timeout'] = String(options.timeoutMs);
|
|
90
82
|
}
|
|
83
|
+
if (options.indexDocument) {
|
|
84
|
+
headers['swarm-index-document'] = String(options.indexDocument);
|
|
85
|
+
}
|
|
86
|
+
if (options.errorDocument) {
|
|
87
|
+
headers['swarm-error-document'] = String(options.errorDocument);
|
|
88
|
+
}
|
|
89
|
+
if (options.actPublisher) {
|
|
90
|
+
headers['swarm-act-publisher'] = new typed_bytes_1.PublicKey(options.actPublisher).toCompressedHex();
|
|
91
|
+
}
|
|
92
|
+
if (options.actHistoryAddress) {
|
|
93
|
+
headers['swarm-act-history-address'] = new typed_bytes_1.Reference(options.actHistoryAddress).toHex();
|
|
94
|
+
}
|
|
95
|
+
if (options.actTimestamp) {
|
|
96
|
+
headers['swarm-act-timestamp'] = String(options.actTimestamp);
|
|
97
|
+
}
|
|
98
|
+
if (options.actPublisher || options.actHistoryAddress || options.actTimestamp) {
|
|
99
|
+
headers['swarm-act'] = 'true';
|
|
100
|
+
}
|
|
101
|
+
if (options.gasPrice) {
|
|
102
|
+
headers['gas-price'] = String(options.gasPrice);
|
|
103
|
+
}
|
|
104
|
+
if (options.gasLimit) {
|
|
105
|
+
headers['gas-limit'] = String(options.gasLimit);
|
|
106
|
+
}
|
|
91
107
|
return headers;
|
|
92
108
|
}
|
|
93
|
-
exports.
|
|
109
|
+
exports.prepareRequestHeaders = prepareRequestHeaders;
|
|
110
|
+
function isEnvelopeWithBatchId(value) {
|
|
111
|
+
if (!cafe_utility_1.Types.isObject(value)) {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
const envelope = value;
|
|
115
|
+
return (envelope.issuer !== undefined &&
|
|
116
|
+
envelope.index !== undefined &&
|
|
117
|
+
envelope.signature !== undefined &&
|
|
118
|
+
envelope.timestamp !== undefined &&
|
|
119
|
+
envelope.batchId !== undefined);
|
|
120
|
+
}
|
package/dist/cjs/utils/http.js
CHANGED
|
@@ -8,6 +8,10 @@ const axios_1 = __importDefault(require("axios"));
|
|
|
8
8
|
const cafe_utility_1 = require("cafe-utility");
|
|
9
9
|
const index_1 = require("../index");
|
|
10
10
|
const { AxiosError } = axios_1.default;
|
|
11
|
+
const MAX_FAILED_ATTEMPTS = 100000;
|
|
12
|
+
const DELAY_FAST = 200;
|
|
13
|
+
const DELAY_SLOW = 1000;
|
|
14
|
+
const DELAY_THRESHOLD = cafe_utility_1.Dates.minutes(1) / DELAY_FAST;
|
|
11
15
|
exports.DEFAULT_HTTP_CONFIG = {
|
|
12
16
|
headers: {
|
|
13
17
|
accept: 'application/json, text/plain, */*',
|
|
@@ -21,19 +25,39 @@ exports.DEFAULT_HTTP_CONFIG = {
|
|
|
21
25
|
* @param config Internal settings and/or Bee settings
|
|
22
26
|
*/
|
|
23
27
|
async function http(options, config) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
const requestConfig = cafe_utility_1.Objects.deepMerge3(exports.DEFAULT_HTTP_CONFIG, config, options);
|
|
29
|
+
if (requestConfig.params) {
|
|
30
|
+
const keys = Object.keys(requestConfig.params);
|
|
31
|
+
for (const key of keys) {
|
|
32
|
+
const value = requestConfig.params[key];
|
|
33
|
+
if (value === undefined) {
|
|
34
|
+
delete requestConfig.params[key];
|
|
35
|
+
}
|
|
36
|
+
}
|
|
30
37
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
38
|
+
let failedAttempts = 0;
|
|
39
|
+
while (failedAttempts < MAX_FAILED_ATTEMPTS) {
|
|
40
|
+
try {
|
|
41
|
+
maybeRunOnRequestHook(options, requestConfig);
|
|
42
|
+
const response = await (0, axios_1.default)(requestConfig);
|
|
43
|
+
return response;
|
|
44
|
+
}
|
|
45
|
+
catch (e) {
|
|
46
|
+
if (e instanceof AxiosError) {
|
|
47
|
+
if (e.code === 'ECONNABORTED' && options.endlesslyRetry) {
|
|
48
|
+
failedAttempts++;
|
|
49
|
+
await cafe_utility_1.System.sleepMillis(failedAttempts < DELAY_THRESHOLD ? DELAY_FAST : DELAY_SLOW);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
throw new index_1.BeeResponseError(config.method || 'get', config.url || '<unknown>', e.message, e.response?.data, e.response?.status, e.code);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
throw e;
|
|
57
|
+
}
|
|
34
58
|
}
|
|
35
|
-
throw e;
|
|
36
59
|
}
|
|
60
|
+
throw Error('Max number of failed attempts reached');
|
|
37
61
|
}
|
|
38
62
|
exports.http = http;
|
|
39
63
|
function maybeRunOnRequestHook(options, requestConfig) {
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mimes = void 0;
|
|
4
|
+
exports.mimes = {
|
|
5
|
+
aac: 'audio/aac',
|
|
6
|
+
abw: 'application/x-abiword',
|
|
7
|
+
ai: 'application/postscript',
|
|
8
|
+
arc: 'application/octet-stream',
|
|
9
|
+
avi: 'video/x-msvideo',
|
|
10
|
+
azw: 'application/vnd.amazon.ebook',
|
|
11
|
+
bin: 'application/octet-stream',
|
|
12
|
+
bz: 'application/x-bzip',
|
|
13
|
+
bz2: 'application/x-bzip2',
|
|
14
|
+
csh: 'application/x-csh',
|
|
15
|
+
css: 'text/css',
|
|
16
|
+
csv: 'text/csv',
|
|
17
|
+
doc: 'application/msword',
|
|
18
|
+
dll: 'application/octet-stream',
|
|
19
|
+
dmg: 'application/x-apple-diskimage',
|
|
20
|
+
eot: 'application/vnd.ms-fontobject',
|
|
21
|
+
epub: 'application/epub+zip',
|
|
22
|
+
gif: 'image/gif',
|
|
23
|
+
htm: 'text/html',
|
|
24
|
+
html: 'text/html',
|
|
25
|
+
ico: 'image/x-icon',
|
|
26
|
+
ics: 'text/calendar',
|
|
27
|
+
jar: 'application/java-archive',
|
|
28
|
+
jpeg: 'image/jpeg',
|
|
29
|
+
jpg: 'image/jpeg',
|
|
30
|
+
js: 'application/javascript',
|
|
31
|
+
json: 'application/json',
|
|
32
|
+
mid: 'audio/midi',
|
|
33
|
+
midi: 'audio/midi',
|
|
34
|
+
mp2: 'audio/mpeg',
|
|
35
|
+
mp3: 'audio/mpeg',
|
|
36
|
+
mp4: 'video/mp4',
|
|
37
|
+
mpa: 'video/mpeg',
|
|
38
|
+
mpe: 'video/mpeg',
|
|
39
|
+
mpeg: 'video/mpeg',
|
|
40
|
+
mpkg: 'application/vnd.apple.installer+xml',
|
|
41
|
+
odp: 'application/vnd.oasis.opendocument.presentation',
|
|
42
|
+
ods: 'application/vnd.oasis.opendocument.spreadsheet',
|
|
43
|
+
odt: 'application/vnd.oasis.opendocument.text',
|
|
44
|
+
oga: 'audio/ogg',
|
|
45
|
+
ogv: 'video/ogg',
|
|
46
|
+
ogx: 'application/ogg',
|
|
47
|
+
otf: 'font/otf',
|
|
48
|
+
png: 'image/png',
|
|
49
|
+
pdf: 'application/pdf',
|
|
50
|
+
ppt: 'application/vnd.ms-powerpoint',
|
|
51
|
+
rar: 'application/x-rar-compressed',
|
|
52
|
+
rtf: 'application/rtf',
|
|
53
|
+
sh: 'application/x-sh',
|
|
54
|
+
svg: 'image/svg+xml',
|
|
55
|
+
swf: 'application/x-shockwave-flash',
|
|
56
|
+
tar: 'application/x-tar',
|
|
57
|
+
tif: 'image/tiff',
|
|
58
|
+
tiff: 'image/tiff',
|
|
59
|
+
ts: 'application/typescript',
|
|
60
|
+
ttf: 'font/ttf',
|
|
61
|
+
txt: 'text/plain',
|
|
62
|
+
vsd: 'application/vnd.visio',
|
|
63
|
+
wav: 'audio/x-wav',
|
|
64
|
+
weba: 'audio/webm',
|
|
65
|
+
webm: 'video/webm',
|
|
66
|
+
webp: 'image/webp',
|
|
67
|
+
woff: 'font/woff',
|
|
68
|
+
woff2: 'font/woff2',
|
|
69
|
+
xhtml: 'application/xhtml+xml',
|
|
70
|
+
xls: 'application/vnd.ms-excel',
|
|
71
|
+
xlsx: 'application/vnd.ms-excel',
|
|
72
|
+
xml: 'application/xml',
|
|
73
|
+
xul: 'application/vnd.mozilla.xul+xml',
|
|
74
|
+
zip: 'application/zip',
|
|
75
|
+
'3gp': 'video/3gpp',
|
|
76
|
+
'3gp2': 'video/3gpp2',
|
|
77
|
+
'7z': 'application/x-7z-compressed',
|
|
78
|
+
};
|
package/dist/cjs/utils/pss.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.makeMaxTarget = void 0;
|
|
4
4
|
const types_1 = require("../types");
|
|
5
|
+
const typed_bytes_1 = require("./typed-bytes");
|
|
5
6
|
/**
|
|
6
7
|
* Utility function that for given strings/reference takes the most specific
|
|
7
8
|
* target that Bee node will except.
|
|
@@ -10,9 +11,7 @@ const types_1 = require("../types");
|
|
|
10
11
|
* @see [Bee docs - PSS](https://docs.ethswarm.org/docs/develop/tools-and-features/pss)
|
|
11
12
|
*/
|
|
12
13
|
function makeMaxTarget(target) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
return target.slice(0, types_1.PSS_TARGET_HEX_LENGTH_MAX);
|
|
14
|
+
target = new typed_bytes_1.PeerAddress(target);
|
|
15
|
+
return target.toHex().slice(0, types_1.PSS_TARGET_HEX_LENGTH_MAX);
|
|
17
16
|
}
|
|
18
17
|
exports.makeMaxTarget = makeMaxTarget;
|
|
@@ -40,12 +40,6 @@ const encParanoidTable = [
|
|
|
40
40
|
[18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],
|
|
41
41
|
[88, 85, 82, 79, 76, 72, 69, 66, 62, 59, 55, 51, 48, 44, 39, 35, 30, 24],
|
|
42
42
|
];
|
|
43
|
-
const tables = {
|
|
44
|
-
[__1.RedundancyLevel.MEDIUM]: [mediumTable, encMediumTable],
|
|
45
|
-
[__1.RedundancyLevel.STRONG]: [strongTable, encStrongTable],
|
|
46
|
-
[__1.RedundancyLevel.INSANE]: [insaneTable, encInsaneTable],
|
|
47
|
-
[__1.RedundancyLevel.PARANOID]: [paranoidTable, encParanoidTable],
|
|
48
|
-
};
|
|
49
43
|
/**
|
|
50
44
|
* Returns an approximate multiplier for the overhead of a given redundancy level.
|
|
51
45
|
* Redundancy level is a tradeoff between storage overhead and fault tolerance.
|
|
@@ -53,14 +47,10 @@ const tables = {
|
|
|
53
47
|
* redundancy level.
|
|
54
48
|
*/
|
|
55
49
|
function approximateOverheadForRedundancyLevel(chunks, level, encrypted) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
: level === __1.RedundancyLevel.INSANE
|
|
61
|
-
? tables[__1.RedundancyLevel.INSANE]
|
|
62
|
-
: tables[__1.RedundancyLevel.PARANOID];
|
|
63
|
-
const table = encrypted ? tableType[1] : tableType[0];
|
|
50
|
+
if (level === __1.RedundancyLevel.OFF) {
|
|
51
|
+
return 0;
|
|
52
|
+
}
|
|
53
|
+
const table = selectTable(level, encrypted);
|
|
64
54
|
const [supportedChunks, parities] = table;
|
|
65
55
|
for (let i = 0; i < supportedChunks.length; i++) {
|
|
66
56
|
if (chunks >= supportedChunks[i]) {
|
|
@@ -70,6 +60,20 @@ function approximateOverheadForRedundancyLevel(chunks, level, encrypted) {
|
|
|
70
60
|
return parities[parities.length - 1] / supportedChunks[supportedChunks.length - 1];
|
|
71
61
|
}
|
|
72
62
|
exports.approximateOverheadForRedundancyLevel = approximateOverheadForRedundancyLevel;
|
|
63
|
+
function selectTable(level, encrypted) {
|
|
64
|
+
switch (level) {
|
|
65
|
+
case __1.RedundancyLevel.MEDIUM:
|
|
66
|
+
return encrypted ? encMediumTable : mediumTable;
|
|
67
|
+
case __1.RedundancyLevel.STRONG:
|
|
68
|
+
return encrypted ? encStrongTable : strongTable;
|
|
69
|
+
case __1.RedundancyLevel.INSANE:
|
|
70
|
+
return encrypted ? encInsaneTable : insaneTable;
|
|
71
|
+
case __1.RedundancyLevel.PARANOID:
|
|
72
|
+
return encrypted ? encParanoidTable : paranoidTable;
|
|
73
|
+
default:
|
|
74
|
+
throw new Error(`Unknown redundancy level ${level}`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
73
77
|
const medium = {
|
|
74
78
|
label: 'medium',
|
|
75
79
|
value: __1.RedundancyLevel.MEDIUM,
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ResourceLocator = void 0;
|
|
4
|
+
const cafe_utility_1 = require("cafe-utility");
|
|
5
|
+
const typed_bytes_1 = require("./typed-bytes");
|
|
6
|
+
class ResourceLocator {
|
|
7
|
+
constructor(raw) {
|
|
8
|
+
this.raw = raw;
|
|
9
|
+
}
|
|
10
|
+
toString() {
|
|
11
|
+
if (cafe_utility_1.Types.isString(this.raw) && this.raw.includes('.eth')) {
|
|
12
|
+
return this.raw;
|
|
13
|
+
}
|
|
14
|
+
return new typed_bytes_1.Reference(this.raw).toHex();
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.ResourceLocator = ResourceLocator;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Size = void 0;
|
|
4
|
+
const cafe_utility_1 = require("cafe-utility");
|
|
5
|
+
/**
|
|
6
|
+
* Represents a size in bytes.
|
|
7
|
+
*
|
|
8
|
+
* Uses 1000 instead of 1024 for converting between units.
|
|
9
|
+
* This is to stay consistent with the Swarm papers
|
|
10
|
+
* on theoretical and effective storage capacity.
|
|
11
|
+
*/
|
|
12
|
+
class Size {
|
|
13
|
+
constructor(bytes) {
|
|
14
|
+
this.bytes = Math.ceil(bytes);
|
|
15
|
+
if (bytes < 0) {
|
|
16
|
+
throw Error('Size must be at least 0');
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
static fromBytes(bytes) {
|
|
20
|
+
return new Size(bytes);
|
|
21
|
+
}
|
|
22
|
+
static fromGigabytes(gigabytes) {
|
|
23
|
+
return new Size(gigabytes * 1000 * 1000 * 1000);
|
|
24
|
+
}
|
|
25
|
+
toBytes() {
|
|
26
|
+
return this.bytes;
|
|
27
|
+
}
|
|
28
|
+
toGigabytes() {
|
|
29
|
+
return this.bytes / 1000 / 1000 / 1000;
|
|
30
|
+
}
|
|
31
|
+
toFormattedString() {
|
|
32
|
+
return cafe_utility_1.Numbers.convertBytes(this.bytes, 1000);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.Size = Size;
|