@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
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getAllBalances = getAllBalances;
|
|
4
|
-
exports.getPeerBalance = getPeerBalance;
|
|
5
|
-
exports.getPastDueConsumptionBalances = getPastDueConsumptionBalances;
|
|
6
|
-
exports.getPastDueConsumptionPeerBalance = getPastDueConsumptionPeerBalance;
|
|
7
|
-
const balance_1 = require("../../types/schema/balance");
|
|
8
|
-
const http_1 = require("../../utils/http");
|
|
9
|
-
const balancesEndpoint = 'balances';
|
|
10
|
-
const consumedEndpoint = 'consumed';
|
|
11
|
-
/**
|
|
12
|
-
* Get the balances with all known peers including prepaid services
|
|
13
|
-
*
|
|
14
|
-
* @param requestOptions Options for making requests
|
|
15
|
-
*/
|
|
16
|
-
async function getAllBalances(requestOptions) {
|
|
17
|
-
const response = await (0, http_1.http)(requestOptions, {
|
|
18
|
-
url: balancesEndpoint,
|
|
19
|
-
responseType: 'json',
|
|
20
|
-
});
|
|
21
|
-
return balance_1.GetAllBalancesResponse.parse(response.data);
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Get the balances with a specific peer including prepaid services
|
|
25
|
-
*
|
|
26
|
-
* @param requestOptions Options for making requests
|
|
27
|
-
* @param address Swarm address of peer
|
|
28
|
-
*/
|
|
29
|
-
async function getPeerBalance(requestOptions, address) {
|
|
30
|
-
const response = await (0, http_1.http)(requestOptions, {
|
|
31
|
-
url: `${balancesEndpoint}/${address}`,
|
|
32
|
-
responseType: 'json',
|
|
33
|
-
});
|
|
34
|
-
return balance_1.GetPeerBalanceResponse.parse(response.data);
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Get the past due consumption balances with all known peers
|
|
38
|
-
*
|
|
39
|
-
* @param requestOptions Options for making requests
|
|
40
|
-
*/
|
|
41
|
-
async function getPastDueConsumptionBalances(requestOptions) {
|
|
42
|
-
const response = await (0, http_1.http)(requestOptions, {
|
|
43
|
-
url: consumedEndpoint,
|
|
44
|
-
responseType: 'json',
|
|
45
|
-
});
|
|
46
|
-
return balance_1.GetAllBalancesResponse.parse(response.data);
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Get the past due consumption balance with a specific peer
|
|
50
|
-
*
|
|
51
|
-
* @param requestOptions Options for making requests
|
|
52
|
-
* @param address Swarm address of peer
|
|
53
|
-
*/
|
|
54
|
-
async function getPastDueConsumptionPeerBalance(requestOptions, address) {
|
|
55
|
-
const response = await (0, http_1.http)(requestOptions, {
|
|
56
|
-
url: `${consumedEndpoint}/${address}`,
|
|
57
|
-
responseType: 'json',
|
|
58
|
-
});
|
|
59
|
-
return balance_1.GetPeerBalanceResponse.parse(response.data);
|
|
60
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getNodeAddresses = getNodeAddresses;
|
|
4
|
-
exports.getPeers = getPeers;
|
|
5
|
-
exports.getBlocklist = getBlocklist;
|
|
6
|
-
exports.removePeer = removePeer;
|
|
7
|
-
exports.getTopology = getTopology;
|
|
8
|
-
exports.pingPeer = pingPeer;
|
|
9
|
-
const connectivity_1 = require("../../types/schema/connectivity");
|
|
10
|
-
const http_1 = require("../../utils/http");
|
|
11
|
-
async function getNodeAddresses(requestOptions) {
|
|
12
|
-
const response = await (0, http_1.http)(requestOptions, {
|
|
13
|
-
url: 'addresses',
|
|
14
|
-
responseType: 'json',
|
|
15
|
-
});
|
|
16
|
-
return connectivity_1.GetNodeAddressesResponse.parse(response.data);
|
|
17
|
-
}
|
|
18
|
-
async function getPeers(requestOptions) {
|
|
19
|
-
const response = await (0, http_1.http)(requestOptions, {
|
|
20
|
-
url: 'peers',
|
|
21
|
-
responseType: 'json',
|
|
22
|
-
});
|
|
23
|
-
return connectivity_1.GetPeersResponse.parse(response.data).peers;
|
|
24
|
-
}
|
|
25
|
-
async function getBlocklist(requestOptions) {
|
|
26
|
-
const response = await (0, http_1.http)(requestOptions, {
|
|
27
|
-
url: 'blocklist',
|
|
28
|
-
responseType: 'json',
|
|
29
|
-
});
|
|
30
|
-
return connectivity_1.GetBlocklistResponse.parse(response.data).peers;
|
|
31
|
-
}
|
|
32
|
-
async function removePeer(requestOptions, peer) {
|
|
33
|
-
const response = await (0, http_1.http)(requestOptions, {
|
|
34
|
-
url: `peers/${peer}`,
|
|
35
|
-
responseType: 'json',
|
|
36
|
-
method: 'DELETE',
|
|
37
|
-
});
|
|
38
|
-
return response.data;
|
|
39
|
-
}
|
|
40
|
-
async function getTopology(requestOptions) {
|
|
41
|
-
const response = await (0, http_1.http)(requestOptions, {
|
|
42
|
-
url: `topology`,
|
|
43
|
-
responseType: 'json',
|
|
44
|
-
});
|
|
45
|
-
return connectivity_1.GetTopologyResponse.parse(response.data);
|
|
46
|
-
}
|
|
47
|
-
async function pingPeer(requestOptions, peer) {
|
|
48
|
-
const response = await (0, http_1.http)(requestOptions, {
|
|
49
|
-
url: `pingpong/${peer}`,
|
|
50
|
-
responseType: 'json',
|
|
51
|
-
method: 'POST',
|
|
52
|
-
});
|
|
53
|
-
return response.data;
|
|
54
|
-
}
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getDebugStatus = getDebugStatus;
|
|
7
|
-
exports.getHealth = getHealth;
|
|
8
|
-
exports.getReadiness = getReadiness;
|
|
9
|
-
exports.getNodeInfo = getNodeInfo;
|
|
10
|
-
exports.isSupportedExactVersion = isSupportedExactVersion;
|
|
11
|
-
exports.isSupportedApiVersion = isSupportedApiVersion;
|
|
12
|
-
exports.getVersions = getVersions;
|
|
13
|
-
const major_js_1 = __importDefault(require("semver/functions/major.js"));
|
|
14
|
-
const status_1 = require("../../types/schema/status");
|
|
15
|
-
const http_1 = require("../../utils/http");
|
|
16
|
-
const version_1 = require("../../version");
|
|
17
|
-
const NODE_INFO_URL = 'node';
|
|
18
|
-
const STATUS_URL = 'status';
|
|
19
|
-
const HEALTH_URL = 'health';
|
|
20
|
-
const READINESS_URL = 'readiness';
|
|
21
|
-
async function getDebugStatus(requestOptions) {
|
|
22
|
-
const response = await (0, http_1.http)(requestOptions, {
|
|
23
|
-
method: 'get',
|
|
24
|
-
url: STATUS_URL,
|
|
25
|
-
responseType: 'json',
|
|
26
|
-
});
|
|
27
|
-
return status_1.GetDebugStatusResponse.parse(response.data);
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Get health of node
|
|
31
|
-
*
|
|
32
|
-
* @param requestOptions Options for making requests
|
|
33
|
-
*/
|
|
34
|
-
async function getHealth(requestOptions) {
|
|
35
|
-
const response = await (0, http_1.http)(requestOptions, {
|
|
36
|
-
method: 'get',
|
|
37
|
-
url: HEALTH_URL,
|
|
38
|
-
responseType: 'json',
|
|
39
|
-
});
|
|
40
|
-
return status_1.GetHealthResponse.parse(response.data);
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Get readiness of node
|
|
44
|
-
*
|
|
45
|
-
* @param requestOptions Options for making requests
|
|
46
|
-
*/
|
|
47
|
-
async function getReadiness(requestOptions) {
|
|
48
|
-
const response = await (0, http_1.http)(requestOptions, {
|
|
49
|
-
method: 'get',
|
|
50
|
-
url: READINESS_URL,
|
|
51
|
-
});
|
|
52
|
-
return status_1.GetReadinessResponse.parse(response.data);
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Get information about Bee node
|
|
56
|
-
*
|
|
57
|
-
* @param requestOptions Options for making requests
|
|
58
|
-
*/
|
|
59
|
-
async function getNodeInfo(requestOptions) {
|
|
60
|
-
const response = await (0, http_1.http)(requestOptions, {
|
|
61
|
-
method: 'get',
|
|
62
|
-
url: NODE_INFO_URL,
|
|
63
|
-
responseType: 'json',
|
|
64
|
-
});
|
|
65
|
-
return status_1.GetNodeInfoResponse.parse(response.data);
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Connects to a node and checks if its version matches with the one that bee-js supports.
|
|
69
|
-
*
|
|
70
|
-
* This is the most strict version check and most probably you will
|
|
71
|
-
* want to use the relaxed API-versions check `isSupportedApiVersion`.
|
|
72
|
-
*
|
|
73
|
-
* @param requestOptions Options for making requests
|
|
74
|
-
*/
|
|
75
|
-
async function isSupportedExactVersion(requestOptions) {
|
|
76
|
-
const { version } = await getHealth(requestOptions);
|
|
77
|
-
return version === version_1.SUPPORTED_BEE_VERSION_EXACT;
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Connects to a node and checks if its Main API versions matches with the one that bee-js supports.
|
|
81
|
-
*
|
|
82
|
-
* This should be the main way how to check compatibility for your app and Bee node.
|
|
83
|
-
*
|
|
84
|
-
* @param requestOptions Options for making requests
|
|
85
|
-
*/
|
|
86
|
-
async function isSupportedApiVersion(requestOptions) {
|
|
87
|
-
const { apiVersion } = await getHealth(requestOptions);
|
|
88
|
-
return (0, major_js_1.default)(apiVersion) === (0, major_js_1.default)(version_1.SUPPORTED_API_VERSION);
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Returns object with all versions specified by the connected Bee node (properties prefixed with `bee*`)
|
|
92
|
-
* and versions that bee-js supports (properties prefixed with `supported*`).
|
|
93
|
-
*
|
|
94
|
-
* @param requestOptions Options for making requests
|
|
95
|
-
*/
|
|
96
|
-
async function getVersions(requestOptions) {
|
|
97
|
-
const { version, apiVersion } = await getHealth(requestOptions);
|
|
98
|
-
return {
|
|
99
|
-
supportedBeeVersion: version_1.SUPPORTED_BEE_VERSION_EXACT,
|
|
100
|
-
supportedBeeApiVersion: version_1.SUPPORTED_API_VERSION,
|
|
101
|
-
beeVersion: version,
|
|
102
|
-
beeApiVersion: apiVersion,
|
|
103
|
-
};
|
|
104
|
-
}
|
package/dist/cjs/modules/gsoc.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.send = send;
|
|
7
|
-
exports.subscribe = subscribe;
|
|
8
|
-
const cafe_utility_1 = require("cafe-utility");
|
|
9
|
-
const isomorphic_ws_1 = __importDefault(require("isomorphic-ws"));
|
|
10
|
-
const soc_1 = require("../chunk/soc");
|
|
11
|
-
const endpoint = 'gsoc';
|
|
12
|
-
async function send(requestOptions, soc, stamp, options) {
|
|
13
|
-
return (0, soc_1.uploadSingleOwnerChunk)(requestOptions, soc, stamp, options);
|
|
14
|
-
}
|
|
15
|
-
function subscribe(url, reference, headers) {
|
|
16
|
-
const wsUrl = url.replace(/^http/i, 'ws');
|
|
17
|
-
if (cafe_utility_1.System.whereAmI() === 'browser') {
|
|
18
|
-
return new isomorphic_ws_1.default(`${wsUrl}/${endpoint}/subscribe/${reference.toHex()}`);
|
|
19
|
-
}
|
|
20
|
-
return new isomorphic_ws_1.default(`${wsUrl}/${endpoint}/subscribe/${reference.toHex()}`, {
|
|
21
|
-
headers,
|
|
22
|
-
});
|
|
23
|
-
}
|
package/dist/cjs/modules/pss.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.send = send;
|
|
7
|
-
exports.subscribe = subscribe;
|
|
8
|
-
const cafe_utility_1 = require("cafe-utility");
|
|
9
|
-
const isomorphic_ws_1 = __importDefault(require("isomorphic-ws"));
|
|
10
|
-
const headers_1 = require("../utils/headers");
|
|
11
|
-
const http_1 = require("../utils/http");
|
|
12
|
-
const endpoint = 'pss';
|
|
13
|
-
/**
|
|
14
|
-
* Send to recipient or target with Postal Service for Swarm
|
|
15
|
-
*
|
|
16
|
-
* @param requestOptions Options for making requests
|
|
17
|
-
* @param topic Topic name
|
|
18
|
-
* @param target Target message address prefix
|
|
19
|
-
* @param data
|
|
20
|
-
* @param postageBatchId Postage BatchId that will be assigned to sent message
|
|
21
|
-
* @param recipient Recipient public key
|
|
22
|
-
*
|
|
23
|
-
*/
|
|
24
|
-
async function send(requestOptions, topic, target, data, postageBatchId, recipient) {
|
|
25
|
-
await (0, http_1.http)(requestOptions, {
|
|
26
|
-
method: 'post',
|
|
27
|
-
url: `${endpoint}/send/${topic}/${target}`,
|
|
28
|
-
data,
|
|
29
|
-
responseType: 'json',
|
|
30
|
-
params: { recipient },
|
|
31
|
-
headers: (0, headers_1.prepareRequestHeaders)(postageBatchId),
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Subscribe for messages on the given topic
|
|
36
|
-
*
|
|
37
|
-
* @param url Bee node URL
|
|
38
|
-
* @param topic Topic name
|
|
39
|
-
*/
|
|
40
|
-
function subscribe(url, topic, headers) {
|
|
41
|
-
const wsUrl = url.replace(/^http/i, 'ws');
|
|
42
|
-
if (cafe_utility_1.System.whereAmI() === 'browser') {
|
|
43
|
-
return new isomorphic_ws_1.default(`${wsUrl}/${endpoint}/subscribe/${topic.toHex()}`);
|
|
44
|
-
}
|
|
45
|
-
return new isomorphic_ws_1.default(`${wsUrl}/${endpoint}/subscribe/${topic.toHex()}`, {
|
|
46
|
-
headers,
|
|
47
|
-
});
|
|
48
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Stamper = void 0;
|
|
4
|
-
const cafe_utility_1 = require("cafe-utility");
|
|
5
|
-
const typed_bytes_1 = require("../utils/typed-bytes");
|
|
6
|
-
class Stamper {
|
|
7
|
-
constructor(signer, batchId, buckets, depth) {
|
|
8
|
-
this.signer = new typed_bytes_1.PrivateKey(signer);
|
|
9
|
-
this.batchId = new typed_bytes_1.BatchId(batchId);
|
|
10
|
-
this.buckets = buckets;
|
|
11
|
-
this.depth = depth;
|
|
12
|
-
this.maxSlot = 2 ** (this.depth - 16);
|
|
13
|
-
}
|
|
14
|
-
static fromBlank(signer, batchId, depth) {
|
|
15
|
-
return new Stamper(signer, batchId, new Uint32Array(65536), depth);
|
|
16
|
-
}
|
|
17
|
-
static fromState(signer, batchId, buckets, depth) {
|
|
18
|
-
return new Stamper(signer, batchId, buckets, depth);
|
|
19
|
-
}
|
|
20
|
-
stamp(chunk) {
|
|
21
|
-
const address = chunk.hash();
|
|
22
|
-
const bucket = cafe_utility_1.Binary.uint16ToNumber(address, 'BE');
|
|
23
|
-
const height = this.buckets[bucket];
|
|
24
|
-
if (height >= this.maxSlot) {
|
|
25
|
-
throw Error('Bucket is full');
|
|
26
|
-
}
|
|
27
|
-
this.buckets[bucket]++;
|
|
28
|
-
const index = cafe_utility_1.Binary.concatBytes(cafe_utility_1.Binary.numberToUint32(bucket, 'BE'), cafe_utility_1.Binary.numberToUint32(height, 'BE'));
|
|
29
|
-
const currentTimeNs = BigInt(Date.now()) * 1000000n; // Bee uses unix timestamp in nanoseconds
|
|
30
|
-
const timestamp = cafe_utility_1.Binary.numberToUint64(currentTimeNs, 'BE');
|
|
31
|
-
const signature = this.signer.sign(cafe_utility_1.Binary.concatBytes(address, this.batchId.toUint8Array(), index, timestamp));
|
|
32
|
-
return {
|
|
33
|
-
batchId: this.batchId,
|
|
34
|
-
index,
|
|
35
|
-
issuer: this.signer.publicKey().address().toUint8Array(),
|
|
36
|
-
signature: signature.toUint8Array(),
|
|
37
|
-
timestamp,
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
getState() {
|
|
41
|
-
return this.buckets;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
exports.Stamper = Stamper;
|
package/dist/cjs/utils/bytes.js
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Bytes = void 0;
|
|
7
|
-
exports.parseSizeToBytes = parseSizeToBytes;
|
|
8
|
-
const cafe_utility_1 = require("cafe-utility");
|
|
9
|
-
const debug_1 = __importDefault(require("debug"));
|
|
10
|
-
const zod_1 = require("zod");
|
|
11
|
-
const hex_schema_1 = require("./hex-schema");
|
|
12
|
-
const debug = (0, debug_1.default)('bee-js:bytes');
|
|
13
|
-
const DECODER = new TextDecoder();
|
|
14
|
-
const ENCODER = new TextEncoder();
|
|
15
|
-
class Bytes {
|
|
16
|
-
constructor(bytes, byteLength) {
|
|
17
|
-
if (!bytes) {
|
|
18
|
-
throw Error(`Bytes#constructor: constructor parameter is falsy: ${bytes}`);
|
|
19
|
-
}
|
|
20
|
-
if (bytes instanceof Bytes) {
|
|
21
|
-
this.bytes = bytes.bytes;
|
|
22
|
-
}
|
|
23
|
-
else if (typeof bytes === 'string') {
|
|
24
|
-
this.bytes = cafe_utility_1.Binary.hexToUint8Array(hex_schema_1.HexStringSchema.parse(bytes));
|
|
25
|
-
}
|
|
26
|
-
else if (bytes instanceof ArrayBuffer) {
|
|
27
|
-
this.bytes = new Uint8Array(bytes);
|
|
28
|
-
}
|
|
29
|
-
else if (bytes instanceof Uint8Array) {
|
|
30
|
-
this.bytes = bytes;
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
const unknownInput = bytes;
|
|
34
|
-
const toHex = cafe_utility_1.Objects.getDeep(unknownInput, 'toHex');
|
|
35
|
-
if (zod_1.z.function().safeParse(toHex).success) {
|
|
36
|
-
const hex = toHex.call(unknownInput);
|
|
37
|
-
this.bytes = cafe_utility_1.Binary.hexToUint8Array(hex_schema_1.HexStringSchema.parse(hex));
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
debug('bytes', bytes);
|
|
41
|
-
throw new Error(`Bytes#constructor: unsupported type: ${typeof bytes}`);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
this.length = this.bytes.length;
|
|
45
|
-
if (byteLength) {
|
|
46
|
-
if (Array.isArray(byteLength)) {
|
|
47
|
-
if (!byteLength.includes(this.length)) {
|
|
48
|
-
throw new Error(`Bytes#checkByteLength: bytes length is ${this.length} but expected ${byteLength.join(' or ')}`);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
else if (this.length !== byteLength) {
|
|
52
|
-
throw new Error(`Bytes#checkByteLength: bytes length is ${this.length} but expected ${byteLength}`);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
static keccak256(bytes) {
|
|
57
|
-
return new Bytes(cafe_utility_1.Binary.keccak256(new Bytes(bytes).toUint8Array()));
|
|
58
|
-
}
|
|
59
|
-
static fromUtf8(utf8) {
|
|
60
|
-
return new Bytes(ENCODER.encode(utf8));
|
|
61
|
-
}
|
|
62
|
-
static fromSlice(bytes, start, length) {
|
|
63
|
-
if (length === undefined) {
|
|
64
|
-
return new Bytes(bytes.slice(start));
|
|
65
|
-
}
|
|
66
|
-
return new Bytes(bytes.slice(start, start + length));
|
|
67
|
-
}
|
|
68
|
-
offset(index) {
|
|
69
|
-
return new Uint8Array(this.bytes.slice(index));
|
|
70
|
-
}
|
|
71
|
-
toUint8Array() {
|
|
72
|
-
return new Uint8Array(this.bytes);
|
|
73
|
-
}
|
|
74
|
-
toHex() {
|
|
75
|
-
return cafe_utility_1.Binary.uint8ArrayToHex(this.bytes);
|
|
76
|
-
}
|
|
77
|
-
toBase64() {
|
|
78
|
-
return cafe_utility_1.Binary.uint8ArrayToBase64(this.bytes);
|
|
79
|
-
}
|
|
80
|
-
toBase32() {
|
|
81
|
-
return cafe_utility_1.Binary.uint8ArrayToBase32(this.bytes);
|
|
82
|
-
}
|
|
83
|
-
toString() {
|
|
84
|
-
return this.toHex();
|
|
85
|
-
}
|
|
86
|
-
toUtf8() {
|
|
87
|
-
return DECODER.decode(this.bytes);
|
|
88
|
-
}
|
|
89
|
-
toJSON() {
|
|
90
|
-
return JSON.parse(this.toUtf8());
|
|
91
|
-
}
|
|
92
|
-
equals(other) {
|
|
93
|
-
return this.toHex() === new Bytes(other).toHex();
|
|
94
|
-
}
|
|
95
|
-
represent() {
|
|
96
|
-
return this.toHex();
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
exports.Bytes = Bytes;
|
|
100
|
-
function parseSizeToBytes(sizeStr) {
|
|
101
|
-
const units = {
|
|
102
|
-
B: 1,
|
|
103
|
-
kB: 1000,
|
|
104
|
-
MB: 1000 ** 2,
|
|
105
|
-
GB: 1000 ** 3,
|
|
106
|
-
TB: 1000 ** 4,
|
|
107
|
-
PB: 1000 ** 5,
|
|
108
|
-
};
|
|
109
|
-
const match = sizeStr.match(/^([\d.]+)\s*(B|kB|MB|GB|TB|PB)$/);
|
|
110
|
-
if (!match) {
|
|
111
|
-
throw new Error(`Invalid size format: ${sizeStr}`);
|
|
112
|
-
}
|
|
113
|
-
const value = parseFloat(match[1]);
|
|
114
|
-
const unit = match[2];
|
|
115
|
-
return Math.ceil(value * units[unit]);
|
|
116
|
-
}
|
package/dist/cjs/utils/cid.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SWARM_FEED_CODEC = exports.SWARM_MANIFEST_CODEC = void 0;
|
|
4
|
-
exports.convertReferenceToCid = convertReferenceToCid;
|
|
5
|
-
exports.convertCidToReference = convertCidToReference;
|
|
6
|
-
const cafe_utility_1 = require("cafe-utility");
|
|
7
|
-
const typed_bytes_1 = require("./typed-bytes");
|
|
8
|
-
exports.SWARM_MANIFEST_CODEC = 0xfa;
|
|
9
|
-
exports.SWARM_FEED_CODEC = 0xfb;
|
|
10
|
-
const CODEC_TABLE = {
|
|
11
|
-
[exports.SWARM_MANIFEST_CODEC]: 'manifest',
|
|
12
|
-
[exports.SWARM_FEED_CODEC]: 'feed',
|
|
13
|
-
};
|
|
14
|
-
function convertReferenceToCid(reference, type) {
|
|
15
|
-
reference = new typed_bytes_1.Reference(reference);
|
|
16
|
-
const base32 = 'b';
|
|
17
|
-
const version = new Uint8Array([1]);
|
|
18
|
-
const codec = new Uint8Array([type === 'feed' ? exports.SWARM_FEED_CODEC : exports.SWARM_MANIFEST_CODEC]);
|
|
19
|
-
const unknown = new Uint8Array([1]);
|
|
20
|
-
const sha256 = new Uint8Array([27]);
|
|
21
|
-
const size = new Uint8Array([32]);
|
|
22
|
-
const header = cafe_utility_1.Binary.uint8ArrayToBase32(cafe_utility_1.Binary.concatBytes(version, codec, unknown, sha256, size)).replace(/\=+$/, '');
|
|
23
|
-
const hash = reference.toBase32().replace(/\=+$/, '');
|
|
24
|
-
return `${base32}${header}${hash}`.toLowerCase();
|
|
25
|
-
}
|
|
26
|
-
function convertCidToReference(cid) {
|
|
27
|
-
const bytes = cafe_utility_1.Binary.base32ToUint8Array(cid.toUpperCase().slice(1));
|
|
28
|
-
const codec = bytes[1];
|
|
29
|
-
if (!CODEC_TABLE[codec]) {
|
|
30
|
-
throw new Error('Unknown codec');
|
|
31
|
-
}
|
|
32
|
-
const reference = new typed_bytes_1.Reference(bytes.slice(-32));
|
|
33
|
-
return {
|
|
34
|
-
type: CODEC_TABLE[codec],
|
|
35
|
-
reference,
|
|
36
|
-
};
|
|
37
|
-
}
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.approximateOverheadForRedundancyLevel = approximateOverheadForRedundancyLevel;
|
|
4
|
-
exports.getRedundancyStats = getRedundancyStats;
|
|
5
|
-
exports.getRedundancyStat = getRedundancyStat;
|
|
6
|
-
const __1 = require("..");
|
|
7
|
-
const mediumTable = [
|
|
8
|
-
[94, 68, 46, 28, 14, 5, 1],
|
|
9
|
-
[9, 8, 7, 6, 5, 4, 3],
|
|
10
|
-
];
|
|
11
|
-
const encMediumTable = [
|
|
12
|
-
[47, 34, 23, 14, 7, 2],
|
|
13
|
-
[9, 8, 7, 6, 5, 4],
|
|
14
|
-
];
|
|
15
|
-
const strongTable = [
|
|
16
|
-
[104, 95, 86, 77, 69, 61, 53, 46, 39, 32, 26, 20, 15, 10, 6, 3, 1],
|
|
17
|
-
[21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5],
|
|
18
|
-
];
|
|
19
|
-
const encStrongTable = [
|
|
20
|
-
[52, 47, 43, 38, 34, 30, 26, 23, 19, 16, 13, 10, 7, 5, 3, 1],
|
|
21
|
-
[21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6],
|
|
22
|
-
];
|
|
23
|
-
const insaneTable = [
|
|
24
|
-
[92, 87, 82, 77, 73, 68, 63, 59, 54, 50, 45, 41, 37, 33, 29, 26, 22, 19, 16, 13, 10, 8, 5, 3, 2, 1],
|
|
25
|
-
[31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6],
|
|
26
|
-
];
|
|
27
|
-
const encInsaneTable = [
|
|
28
|
-
[46, 43, 41, 38, 36, 34, 31, 29, 27, 25, 22, 20, 18, 16, 14, 13, 11, 9, 8, 6, 5, 4, 2, 1],
|
|
29
|
-
[31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 7],
|
|
30
|
-
];
|
|
31
|
-
const paranoidTable = [
|
|
32
|
-
[
|
|
33
|
-
37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9,
|
|
34
|
-
8, 7, 6, 5, 4, 3, 2, 1,
|
|
35
|
-
],
|
|
36
|
-
[
|
|
37
|
-
90, 88, 87, 85, 84, 82, 81, 79, 77, 76, 74, 72, 71, 69, 67, 66, 64, 62, 60, 59, 57, 55, 53, 51, 49, 48, 46, 44, 41,
|
|
38
|
-
39, 37, 35, 32, 30, 27, 24, 20,
|
|
39
|
-
],
|
|
40
|
-
];
|
|
41
|
-
const encParanoidTable = [
|
|
42
|
-
[18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1],
|
|
43
|
-
[88, 85, 82, 79, 76, 72, 69, 66, 62, 59, 55, 51, 48, 44, 39, 35, 30, 24],
|
|
44
|
-
];
|
|
45
|
-
/**
|
|
46
|
-
* Returns an approximate multiplier for the overhead of a given redundancy level.
|
|
47
|
-
* Redundancy level is a tradeoff between storage overhead and fault tolerance.
|
|
48
|
-
* Use this number to estimate the amount of chunks that will be stored for a given
|
|
49
|
-
* redundancy level.
|
|
50
|
-
*/
|
|
51
|
-
function approximateOverheadForRedundancyLevel(chunks, level, encrypted) {
|
|
52
|
-
if (level === __1.RedundancyLevel.OFF) {
|
|
53
|
-
return 0;
|
|
54
|
-
}
|
|
55
|
-
const table = selectTable(level, encrypted);
|
|
56
|
-
const [supportedChunks, parities] = table;
|
|
57
|
-
for (let i = 0; i < supportedChunks.length; i++) {
|
|
58
|
-
if (chunks >= supportedChunks[i]) {
|
|
59
|
-
return parities[i] / supportedChunks[i];
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
return parities[parities.length - 1] / supportedChunks[supportedChunks.length - 1];
|
|
63
|
-
}
|
|
64
|
-
function selectTable(level, encrypted) {
|
|
65
|
-
switch (level) {
|
|
66
|
-
case __1.RedundancyLevel.MEDIUM:
|
|
67
|
-
return encrypted ? encMediumTable : mediumTable;
|
|
68
|
-
case __1.RedundancyLevel.STRONG:
|
|
69
|
-
return encrypted ? encStrongTable : strongTable;
|
|
70
|
-
case __1.RedundancyLevel.INSANE:
|
|
71
|
-
return encrypted ? encInsaneTable : insaneTable;
|
|
72
|
-
case __1.RedundancyLevel.PARANOID:
|
|
73
|
-
return encrypted ? encParanoidTable : paranoidTable;
|
|
74
|
-
default:
|
|
75
|
-
throw new Error(`Unknown redundancy level ${level}`);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
const medium = {
|
|
79
|
-
label: 'medium',
|
|
80
|
-
value: __1.RedundancyLevel.MEDIUM,
|
|
81
|
-
errorTolerance: 0.01,
|
|
82
|
-
};
|
|
83
|
-
const strong = {
|
|
84
|
-
label: 'strong',
|
|
85
|
-
value: __1.RedundancyLevel.STRONG,
|
|
86
|
-
errorTolerance: 0.05,
|
|
87
|
-
};
|
|
88
|
-
const insane = {
|
|
89
|
-
label: 'insane',
|
|
90
|
-
value: __1.RedundancyLevel.INSANE,
|
|
91
|
-
errorTolerance: 0.1,
|
|
92
|
-
};
|
|
93
|
-
const paranoid = {
|
|
94
|
-
label: 'paranoid',
|
|
95
|
-
value: __1.RedundancyLevel.PARANOID,
|
|
96
|
-
errorTolerance: 0.5,
|
|
97
|
-
};
|
|
98
|
-
function getRedundancyStats() {
|
|
99
|
-
return {
|
|
100
|
-
medium,
|
|
101
|
-
strong,
|
|
102
|
-
insane,
|
|
103
|
-
paranoid,
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
function getRedundancyStat(level) {
|
|
107
|
-
if (typeof level === 'string') {
|
|
108
|
-
switch (level.toLowerCase()) {
|
|
109
|
-
case 'medium':
|
|
110
|
-
return medium;
|
|
111
|
-
case 'strong':
|
|
112
|
-
return strong;
|
|
113
|
-
case 'insane':
|
|
114
|
-
return insane;
|
|
115
|
-
case 'paranoid':
|
|
116
|
-
return paranoid;
|
|
117
|
-
default:
|
|
118
|
-
throw new Error(`Unknown redundancy level '${level}'`);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
switch (level) {
|
|
122
|
-
case __1.RedundancyLevel.MEDIUM:
|
|
123
|
-
return medium;
|
|
124
|
-
case __1.RedundancyLevel.STRONG:
|
|
125
|
-
return strong;
|
|
126
|
-
case __1.RedundancyLevel.INSANE:
|
|
127
|
-
return insane;
|
|
128
|
-
case __1.RedundancyLevel.PARANOID:
|
|
129
|
-
return paranoid;
|
|
130
|
-
default:
|
|
131
|
-
throw new Error(`Unknown redundancy level '${level}'`);
|
|
132
|
-
}
|
|
133
|
-
}
|