@ethersphere/bee-js 3.3.4 → 4.1.0
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 +3 -22
- package/dist/cjs/{bee-debug.js → src/bee-debug.js} +31 -8
- package/dist/cjs/{bee.js → src/bee.js} +79 -24
- package/dist/cjs/{chunk → src/chunk}/bmt.js +0 -0
- package/dist/cjs/{chunk → src/chunk}/cac.js +0 -0
- package/dist/cjs/{chunk → src/chunk}/serialize.js +0 -0
- package/dist/cjs/{chunk → src/chunk}/signer.js +0 -0
- package/dist/cjs/{chunk → src/chunk}/soc.js +0 -0
- package/dist/cjs/{chunk → src/chunk}/span.js +0 -0
- package/dist/cjs/src/feed/identifier.js +35 -0
- package/dist/cjs/{feed → src/feed}/index.js +34 -90
- package/dist/cjs/{feed → src/feed}/json.js +0 -0
- package/dist/cjs/src/feed/retrievable.js +72 -0
- package/dist/cjs/{feed → src/feed}/topic.js +0 -0
- package/dist/cjs/{feed → src/feed}/type.js +0 -0
- package/dist/cjs/{index.js → src/index.js} +0 -0
- package/dist/cjs/{modules → src/modules}/bytes.js +0 -0
- package/dist/cjs/{modules → src/modules}/bzz.js +0 -0
- package/dist/cjs/{modules → src/modules}/chunk.js +0 -0
- package/dist/cjs/{modules → src/modules}/debug/balance.js +0 -0
- package/dist/cjs/{modules → src/modules}/debug/chequebook.js +0 -0
- package/dist/cjs/{modules → src/modules}/debug/chunk.js +0 -0
- package/dist/cjs/{modules → src/modules}/debug/connectivity.js +0 -0
- package/dist/cjs/{modules → src/modules}/debug/settlements.js +0 -0
- package/dist/cjs/{modules → src/modules}/debug/stamps.js +0 -0
- package/dist/cjs/{modules → src/modules}/debug/states.js +18 -1
- package/dist/cjs/{modules → src/modules}/debug/status.js +3 -3
- package/dist/cjs/{modules → src/modules}/debug/tag.js +0 -0
- package/dist/cjs/{modules → src/modules}/debug/transactions.js +0 -0
- package/dist/cjs/{modules → src/modules}/feed.js +3 -3
- package/dist/cjs/{modules → src/modules}/pinning.js +0 -0
- package/dist/cjs/{modules → src/modules}/pss.js +0 -0
- package/dist/cjs/{modules → src/modules}/soc.js +0 -0
- package/dist/cjs/{modules → src/modules}/status.js +0 -0
- package/dist/cjs/{modules → src/modules}/stewardship.js +0 -0
- package/dist/cjs/{modules → src/modules}/tag.js +0 -0
- package/dist/cjs/{types → src/types}/debug.js +0 -0
- package/dist/cjs/{types → src/types}/index.js +2 -1
- package/dist/cjs/{types → src/types}/ky-options.js +0 -0
- package/dist/cjs/{types → src/types}/ky-universal/common.js +0 -0
- package/dist/cjs/{types → src/types}/ky-universal/hooks.js +0 -0
- package/dist/cjs/{types → src/types}/ky-universal/retry.js +0 -0
- package/dist/cjs/{utils → src/utils}/bytes.js +15 -1
- package/dist/cjs/{utils → src/utils}/collection.browser.js +0 -0
- package/dist/cjs/{utils → src/utils}/collection.js +0 -0
- package/dist/cjs/{utils → src/utils}/collection.node.js +0 -0
- package/dist/cjs/{utils → src/utils}/data.browser.js +0 -0
- package/dist/cjs/{utils → src/utils}/data.js +0 -0
- package/dist/cjs/{utils → src/utils}/error.js +0 -0
- package/dist/cjs/{utils → src/utils}/eth.js +0 -0
- package/dist/cjs/{utils → src/utils}/expose.js +0 -0
- package/dist/cjs/{utils → src/utils}/file.js +0 -0
- package/dist/cjs/{utils → src/utils}/hash.js +0 -0
- package/dist/cjs/{utils → src/utils}/headers.js +0 -0
- package/dist/cjs/{utils → src/utils}/hex.js +0 -0
- package/dist/cjs/{utils → src/utils}/http.js +6 -0
- package/dist/cjs/{utils → src/utils}/merge.js +0 -0
- package/dist/cjs/{utils → src/utils}/pss.js +0 -0
- package/dist/cjs/src/utils/reference.js +36 -0
- package/dist/cjs/{utils → src/utils}/stamps.js +0 -0
- package/dist/cjs/{utils → src/utils}/stream.js +0 -0
- package/dist/cjs/{utils → src/utils}/tar.js +0 -0
- package/dist/cjs/{utils → src/utils}/type.js +100 -1
- package/dist/cjs/{utils → src/utils}/uint64.js +0 -0
- package/dist/cjs/{utils → src/utils}/url.js +0 -0
- package/dist/cjs/test/utils.js +419 -0
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/{bee-debug.js → src/bee-debug.js} +40 -10
- package/dist/mjs/{bee.js → src/bee.js} +87 -27
- package/dist/mjs/{chunk → src/chunk}/bmt.js +0 -0
- package/dist/mjs/{chunk → src/chunk}/cac.js +1 -1
- package/dist/mjs/{chunk → src/chunk}/serialize.js +0 -0
- package/dist/mjs/{chunk → src/chunk}/signer.js +0 -0
- package/dist/mjs/{chunk → src/chunk}/soc.js +0 -0
- package/dist/mjs/{chunk → src/chunk}/span.js +0 -0
- package/dist/mjs/src/feed/identifier.js +35 -0
- package/dist/mjs/{feed → src/feed}/index.js +39 -94
- package/dist/mjs/{feed → src/feed}/json.js +0 -0
- package/dist/mjs/src/feed/retrievable.js +105 -0
- package/dist/mjs/{feed → src/feed}/topic.js +0 -0
- package/dist/mjs/{feed → src/feed}/type.js +0 -0
- package/dist/mjs/{index.js → src/index.js} +0 -0
- package/dist/mjs/{modules → src/modules}/bytes.js +0 -0
- package/dist/mjs/{modules → src/modules}/bzz.js +0 -0
- package/dist/mjs/{modules → src/modules}/chunk.js +0 -0
- package/dist/mjs/{modules → src/modules}/debug/balance.js +0 -0
- package/dist/mjs/{modules → src/modules}/debug/chequebook.js +0 -0
- package/dist/mjs/{modules → src/modules}/debug/chunk.js +0 -0
- package/dist/mjs/{modules → src/modules}/debug/connectivity.js +0 -0
- package/dist/mjs/{modules → src/modules}/debug/settlements.js +0 -0
- package/dist/mjs/{modules → src/modules}/debug/stamps.js +0 -0
- package/dist/mjs/{modules → src/modules}/debug/states.js +17 -0
- package/dist/mjs/{modules → src/modules}/debug/status.js +3 -3
- package/dist/mjs/{modules → src/modules}/debug/tag.js +0 -0
- package/dist/mjs/{modules → src/modules}/debug/transactions.js +0 -0
- package/dist/mjs/{modules → src/modules}/feed.js +1 -1
- package/dist/mjs/{modules → src/modules}/pinning.js +0 -0
- package/dist/mjs/{modules → src/modules}/pss.js +0 -0
- package/dist/mjs/{modules → src/modules}/soc.js +0 -0
- package/dist/mjs/{modules → src/modules}/status.js +0 -0
- package/dist/mjs/{modules → src/modules}/stewardship.js +0 -0
- package/dist/mjs/{modules → src/modules}/tag.js +0 -0
- package/dist/mjs/{types → src/types}/debug.js +0 -0
- package/dist/mjs/{types → src/types}/index.js +1 -0
- package/dist/mjs/{types → src/types}/ky-options.js +0 -0
- package/dist/mjs/{types → src/types}/ky-universal/common.js +0 -0
- package/dist/mjs/{types → src/types}/ky-universal/hooks.js +0 -0
- package/dist/mjs/{types → src/types}/ky-universal/retry.js +0 -0
- package/dist/mjs/{utils → src/utils}/bytes.js +15 -0
- package/dist/mjs/{utils → src/utils}/collection.browser.js +0 -0
- package/dist/mjs/{utils → src/utils}/collection.js +0 -0
- package/dist/mjs/{utils → src/utils}/collection.node.js +0 -0
- package/dist/mjs/{utils → src/utils}/data.browser.js +0 -0
- package/dist/mjs/{utils → src/utils}/data.js +0 -0
- package/dist/mjs/{utils → src/utils}/error.js +0 -0
- package/dist/mjs/{utils → src/utils}/eth.js +0 -0
- package/dist/mjs/{utils → src/utils}/expose.js +0 -0
- package/dist/mjs/{utils → src/utils}/file.js +0 -0
- package/dist/mjs/{utils → src/utils}/hash.js +0 -0
- package/dist/mjs/{utils → src/utils}/headers.js +0 -0
- package/dist/mjs/{utils → src/utils}/hex.js +0 -0
- package/dist/mjs/{utils → src/utils}/http.js +7 -0
- package/dist/mjs/{utils → src/utils}/merge.js +0 -0
- package/dist/mjs/{utils → src/utils}/pss.js +0 -0
- package/dist/mjs/src/utils/reference.js +32 -0
- package/dist/mjs/{utils → src/utils}/stamps.js +0 -0
- package/dist/mjs/{utils → src/utils}/stream.js +0 -0
- package/dist/mjs/{utils → src/utils}/tar.js +0 -0
- package/dist/mjs/{utils → src/utils}/type.js +109 -2
- package/dist/mjs/{utils → src/utils}/uint64.js +0 -0
- package/dist/mjs/{utils → src/utils}/url.js +0 -0
- package/dist/mjs/test/utils.js +458 -0
- package/dist/types/{bee-debug.d.ts → src/bee-debug.d.ts} +8 -1
- package/dist/types/{bee.d.ts → src/bee.d.ts} +55 -24
- package/dist/types/{chunk → src/chunk}/bmt.d.ts +0 -0
- package/dist/types/{chunk → src/chunk}/cac.d.ts +4 -5
- package/dist/types/{chunk → src/chunk}/serialize.d.ts +0 -0
- package/dist/types/{chunk → src/chunk}/signer.d.ts +0 -0
- package/dist/types/{chunk → src/chunk}/soc.d.ts +4 -4
- package/dist/types/{chunk → src/chunk}/span.d.ts +0 -0
- package/dist/types/src/feed/identifier.d.ts +4 -0
- package/dist/types/src/feed/index.d.ts +28 -0
- package/dist/types/{feed → src/feed}/json.d.ts +0 -0
- package/dist/types/src/feed/retrievable.d.ts +5 -0
- package/dist/types/{feed → src/feed}/topic.d.ts +0 -0
- package/dist/types/{feed → src/feed}/type.d.ts +0 -0
- package/dist/types/{index.d.ts → src/index.d.ts} +0 -0
- package/dist/types/{modules → src/modules}/bytes.d.ts +3 -3
- package/dist/types/{modules → src/modules}/bzz.d.ts +3 -3
- package/dist/types/{modules → src/modules}/chunk.d.ts +2 -2
- package/dist/types/{modules → src/modules}/debug/balance.d.ts +0 -0
- package/dist/types/{modules → src/modules}/debug/chequebook.d.ts +0 -0
- package/dist/types/{modules → src/modules}/debug/chunk.d.ts +0 -0
- package/dist/types/{modules → src/modules}/debug/connectivity.d.ts +0 -0
- package/dist/types/{modules → src/modules}/debug/settlements.d.ts +0 -0
- package/dist/types/{modules → src/modules}/debug/stamps.d.ts +0 -0
- package/dist/types/{modules → src/modules}/debug/states.d.ts +7 -1
- package/dist/types/{modules → src/modules}/debug/status.d.ts +3 -3
- package/dist/types/{modules → src/modules}/debug/tag.d.ts +0 -0
- package/dist/types/{modules → src/modules}/debug/transactions.d.ts +0 -0
- package/dist/types/{modules → src/modules}/feed.d.ts +12 -1
- package/dist/types/{modules → src/modules}/pinning.d.ts +0 -0
- package/dist/types/{modules → src/modules}/pss.d.ts +0 -0
- package/dist/types/{modules → src/modules}/soc.d.ts +0 -0
- package/dist/types/{modules → src/modules}/status.d.ts +0 -0
- package/dist/types/{modules → src/modules}/stewardship.d.ts +3 -3
- package/dist/types/{modules → src/modules}/tag.d.ts +0 -0
- package/dist/types/{types → src/types}/debug.d.ts +19 -3
- package/dist/types/{types → src/types}/index.d.ts +33 -2
- package/dist/types/{types → src/types}/ky-options.d.ts +0 -0
- package/dist/types/{types → src/types}/ky-universal/common.d.ts +0 -0
- package/dist/types/{types → src/types}/ky-universal/hooks.d.ts +0 -0
- package/dist/types/{types → src/types}/ky-universal/retry.d.ts +0 -0
- package/dist/types/{utils → src/utils}/bytes.d.ts +7 -0
- package/dist/types/{utils → src/utils}/collection.browser.d.ts +0 -0
- package/dist/types/{utils → src/utils}/collection.d.ts +0 -0
- package/dist/types/{utils → src/utils}/collection.node.d.ts +0 -0
- package/dist/types/{utils → src/utils}/data.browser.d.ts +0 -0
- package/dist/types/{utils → src/utils}/data.d.ts +0 -0
- package/dist/types/{utils → src/utils}/error.d.ts +0 -0
- package/dist/types/{utils → src/utils}/eth.d.ts +0 -0
- package/dist/types/{utils → src/utils}/expose.d.ts +0 -0
- package/dist/types/{utils → src/utils}/file.d.ts +0 -0
- package/dist/types/{utils → src/utils}/hash.d.ts +0 -0
- package/dist/types/{utils → src/utils}/headers.d.ts +0 -0
- package/dist/types/{utils → src/utils}/hex.d.ts +0 -0
- package/dist/types/{utils → src/utils}/http.d.ts +0 -0
- package/dist/types/{utils → src/utils}/merge.d.ts +0 -0
- package/dist/types/{utils → src/utils}/pss.d.ts +0 -0
- package/dist/types/src/utils/reference.d.ts +2 -0
- package/dist/types/{utils → src/utils}/stamps.d.ts +0 -0
- package/dist/types/{utils → src/utils}/stream.d.ts +0 -0
- package/dist/types/{utils → src/utils}/tar.d.ts +0 -0
- package/dist/types/{utils → src/utils}/type.d.ts +17 -1
- package/dist/types/{utils → src/utils}/uint64.d.ts +0 -0
- package/dist/types/{utils → src/utils}/url.d.ts +0 -0
- package/dist/types/test/utils.d.ts +119 -0
- package/package.json +24 -24
- package/dist/types/feed/index.d.ts +0 -35
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) {
|
|
3
|
+
return value instanceof P ? value : new P(function (resolve) {
|
|
4
|
+
resolve(value);
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
9
|
+
function fulfilled(value) {
|
|
10
|
+
try {
|
|
11
|
+
step(generator.next(value));
|
|
12
|
+
} catch (e) {
|
|
13
|
+
reject(e);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function rejected(value) {
|
|
18
|
+
try {
|
|
19
|
+
step(generator["throw"](value));
|
|
20
|
+
} catch (e) {
|
|
21
|
+
reject(e);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function step(result) {
|
|
26
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
import { getFeedUpdateChunkReference } from "./index.js";
|
|
34
|
+
import { readUint64BigEndian } from "../utils/uint64.js";
|
|
35
|
+
import { bytesToHex } from "../utils/hex.js";
|
|
36
|
+
|
|
37
|
+
function makeNumericIndex(index) {
|
|
38
|
+
if (index instanceof Uint8Array) {
|
|
39
|
+
return readUint64BigEndian(index);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (typeof index === 'string') {
|
|
43
|
+
return parseInt(index);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (typeof index === 'number') {
|
|
47
|
+
return index;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
throw new TypeError('Unknown type of index!');
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Function that checks if a chunk is retrievable by actually downloading it.
|
|
54
|
+
* The /stewardship/{reference} endpoint does not support verification of chunks, but only manifest's references.
|
|
55
|
+
*
|
|
56
|
+
* @param bee
|
|
57
|
+
* @param ref
|
|
58
|
+
* @param options
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
function isChunkRetrievable(bee, ref, options) {
|
|
63
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
try {
|
|
65
|
+
yield bee.downloadChunk(ref, options);
|
|
66
|
+
return true;
|
|
67
|
+
} catch (e) {
|
|
68
|
+
const err = e;
|
|
69
|
+
|
|
70
|
+
if (err.status === 404) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
throw e;
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Creates array of references for all sequence updates chunk up to the given index.
|
|
80
|
+
*
|
|
81
|
+
* @param owner
|
|
82
|
+
* @param topic
|
|
83
|
+
* @param index
|
|
84
|
+
*/
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
function getAllSequenceUpdateReferences(owner, topic, index) {
|
|
88
|
+
const numIndex = makeNumericIndex(index);
|
|
89
|
+
const updateReferences = new Array(numIndex + 1);
|
|
90
|
+
|
|
91
|
+
for (let i = 0; i <= numIndex; i++) {
|
|
92
|
+
updateReferences[i] = bytesToHex(getFeedUpdateChunkReference(owner, topic, i));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return updateReferences;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function areAllSequentialFeedsUpdateRetrievable(bee, owner, topic, index, options) {
|
|
99
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
100
|
+
const chunkRetrievablePromises = getAllSequenceUpdateReferences(owner, topic, index).map(ref => __awaiter(this, void 0, void 0, function* () {
|
|
101
|
+
return isChunkRetrievable(bee, ref, options);
|
|
102
|
+
}));
|
|
103
|
+
return (yield Promise.all(chunkRetrievablePromises)).every(result => result);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -32,6 +32,7 @@ var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, gene
|
|
|
32
32
|
|
|
33
33
|
import { http } from "../../utils/http.js";
|
|
34
34
|
const RESERVE_STATE_ENDPOINT = 'reservestate';
|
|
35
|
+
const WALLET_ENDPOINT = 'wallet';
|
|
35
36
|
const CHAIN_STATE_ENDPOINT = 'chainstate';
|
|
36
37
|
/**
|
|
37
38
|
* Get state of reserve
|
|
@@ -64,4 +65,20 @@ export function getChainState(ky) {
|
|
|
64
65
|
});
|
|
65
66
|
return response.data;
|
|
66
67
|
});
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Get wallet balances for xDai and BZZ of the node
|
|
71
|
+
*
|
|
72
|
+
* @param ky Ky debug instance
|
|
73
|
+
*/
|
|
74
|
+
|
|
75
|
+
export function getWalletBalance(ky) {
|
|
76
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
const response = yield http(ky, {
|
|
78
|
+
method: 'get',
|
|
79
|
+
path: `${WALLET_ENDPOINT}`,
|
|
80
|
+
responseType: 'json'
|
|
81
|
+
});
|
|
82
|
+
return response.data;
|
|
83
|
+
});
|
|
67
84
|
}
|
|
@@ -34,9 +34,9 @@ import { http } from "../../utils/http.js";
|
|
|
34
34
|
import getMajorSemver from 'semver/functions/major.js'; // Following lines bellow are automatically updated with GitHub Action when Bee version is updated
|
|
35
35
|
// so if you are changing anything about them change the `update_bee` action accordingly!
|
|
36
36
|
|
|
37
|
-
export const SUPPORTED_BEE_VERSION_EXACT = '1.
|
|
38
|
-
export const SUPPORTED_API_VERSION = '3.0.
|
|
39
|
-
export const SUPPORTED_DEBUG_API_VERSION = '2.0.
|
|
37
|
+
export const SUPPORTED_BEE_VERSION_EXACT = '1.6.0-6ceadd35';
|
|
38
|
+
export const SUPPORTED_API_VERSION = '3.0.1';
|
|
39
|
+
export const SUPPORTED_DEBUG_API_VERSION = '2.0.1';
|
|
40
40
|
export const SUPPORTED_BEE_VERSION = SUPPORTED_BEE_VERSION_EXACT.substring(0, SUPPORTED_BEE_VERSION_EXACT.indexOf('-'));
|
|
41
41
|
const NODE_INFO_URL = 'node';
|
|
42
42
|
const HEALTH_URL = 'health';
|
|
File without changes
|
|
File without changes
|
|
@@ -89,7 +89,7 @@ function readFeedUpdateHeaders(headers) {
|
|
|
89
89
|
*/
|
|
90
90
|
|
|
91
91
|
|
|
92
|
-
export function
|
|
92
|
+
export function fetchLatestFeedUpdate(ky, owner, topic, options) {
|
|
93
93
|
return __awaiter(this, void 0, void 0, function* () {
|
|
94
94
|
const response = yield http(ky, {
|
|
95
95
|
responseType: 'json',
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -23,6 +23,7 @@ export const STAMPS_DEPTH_MIN = 17;
|
|
|
23
23
|
export const STAMPS_DEPTH_MAX = 255;
|
|
24
24
|
export const TAGS_LIMIT_MIN = 1;
|
|
25
25
|
export const TAGS_LIMIT_MAX = 1000;
|
|
26
|
+
export const FEED_INDEX_HEX_LENGTH = 16;
|
|
26
27
|
/*********************************************************
|
|
27
28
|
* Writers and Readers interfaces
|
|
28
29
|
*/
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -9,6 +9,21 @@ import { bytesToHex } from "./hex.js";
|
|
|
9
9
|
export function isBytes(b, length) {
|
|
10
10
|
return b instanceof Uint8Array && b.length === length;
|
|
11
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* Function that verifies if passed data are Bytes and if the array has "length" number of bytes under given offset.
|
|
14
|
+
* @param data
|
|
15
|
+
* @param offset
|
|
16
|
+
* @param length
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
export function hasBytesAtOffset(data, offset, length) {
|
|
20
|
+
if (!(data instanceof Uint8Array)) {
|
|
21
|
+
throw new TypeError('Data has to an Uint8Array!');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const offsetBytes = data.slice(offset, offset + length);
|
|
25
|
+
return isBytes(offsetBytes, length);
|
|
26
|
+
}
|
|
12
27
|
/**
|
|
13
28
|
* Verifies if a byte array has a certain length
|
|
14
29
|
*
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -191,6 +191,13 @@ export function http(ky, config) {
|
|
|
191
191
|
} else if (isHttpRequestError(e)) {
|
|
192
192
|
throw new BeeRequestError(e.message, config);
|
|
193
193
|
} else {
|
|
194
|
+
// Node 18 has native `fetch` implementation called Undici. Errors from this implementation have top level generic
|
|
195
|
+
// message "fetch failed" with the more specific error placed into `cause` property. Instead of "fetch failed" we
|
|
196
|
+
// expose the underlying problem.
|
|
197
|
+
if (e.cause) {
|
|
198
|
+
throw new BeeError(e.cause.message);
|
|
199
|
+
}
|
|
200
|
+
|
|
194
201
|
throw new BeeError(e.message);
|
|
195
202
|
}
|
|
196
203
|
}
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ENCRYPTED_REFERENCE_BYTES_LENGTH, ENCRYPTED_REFERENCE_HEX_LENGTH, REFERENCE_BYTES_LENGTH, REFERENCE_HEX_LENGTH } from "../types/index.js";
|
|
2
|
+
import { bytesAtOffset, hasBytesAtOffset } from "./bytes.js";
|
|
3
|
+
import { hexToBytes, makeHexString } from "./hex.js";
|
|
4
|
+
export function makeBytesReference(reference, offset = 0) {
|
|
5
|
+
if (typeof reference === 'string') {
|
|
6
|
+
if (offset) {
|
|
7
|
+
throw new Error('Offset property can be set only for UintArray reference!');
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
try {
|
|
11
|
+
// Non-encrypted chunk hex string reference
|
|
12
|
+
const hexReference = makeHexString(reference, REFERENCE_HEX_LENGTH);
|
|
13
|
+
return hexToBytes(hexReference);
|
|
14
|
+
} catch (e) {
|
|
15
|
+
if (!(e instanceof TypeError)) {
|
|
16
|
+
throw e;
|
|
17
|
+
} // Encrypted chunk hex string reference
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
const hexReference = makeHexString(reference, ENCRYPTED_REFERENCE_HEX_LENGTH);
|
|
21
|
+
return hexToBytes(hexReference);
|
|
22
|
+
}
|
|
23
|
+
} else if (reference instanceof Uint8Array) {
|
|
24
|
+
if (hasBytesAtOffset(reference, offset, ENCRYPTED_REFERENCE_BYTES_LENGTH)) {
|
|
25
|
+
return bytesAtOffset(reference, offset, ENCRYPTED_REFERENCE_BYTES_LENGTH);
|
|
26
|
+
} else if (hasBytesAtOffset(reference, offset, REFERENCE_BYTES_LENGTH)) {
|
|
27
|
+
return bytesAtOffset(reference, offset, REFERENCE_BYTES_LENGTH);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
throw new TypeError('invalid chunk reference');
|
|
32
|
+
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { ADDRESS_HEX_LENGTH, BATCH_ID_HEX_LENGTH, ENCRYPTED_REFERENCE_HEX_LENGTH, PUBKEY_HEX_LENGTH, REFERENCE_HEX_LENGTH, TAGS_LIMIT_MAX, TAGS_LIMIT_MIN, PSS_TARGET_HEX_LENGTH_MAX } from "../types/index.js";
|
|
2
|
-
import { BeeArgumentError } from "./error.js";
|
|
2
|
+
import { BeeArgumentError, BeeError } from "./error.js";
|
|
3
3
|
import { isFile } from "./file.js";
|
|
4
|
-
import { assertHexString, assertPrefixedHexString } from "./hex.js";
|
|
4
|
+
import { assertHexString, assertPrefixedHexString, isHexString } from "./hex.js";
|
|
5
5
|
import { isReadable } from "./stream.js";
|
|
6
|
+
import { decodeCid, encodeReference } from '@ethersphere/swarm-cid';
|
|
6
7
|
export function isUint8Array(obj) {
|
|
7
8
|
return obj instanceof Uint8Array;
|
|
8
9
|
}
|
|
@@ -51,6 +52,10 @@ export function assertNonNegativeInteger(value, name = 'Value') {
|
|
|
51
52
|
assertInteger(value, name);
|
|
52
53
|
if (Number(value) < 0) throw new BeeArgumentError(`${name} has to be bigger or equal to zero`, value);
|
|
53
54
|
}
|
|
55
|
+
export function assertPositiveInteger(value, name = 'Value') {
|
|
56
|
+
assertInteger(value, name);
|
|
57
|
+
if (Number(value) <= 0) throw new BeeArgumentError(`${name} has to be bigger then zero`, value);
|
|
58
|
+
}
|
|
54
59
|
export function assertReference(value) {
|
|
55
60
|
try {
|
|
56
61
|
assertHexString(value, REFERENCE_HEX_LENGTH);
|
|
@@ -58,6 +63,100 @@ export function assertReference(value) {
|
|
|
58
63
|
assertHexString(value, ENCRYPTED_REFERENCE_HEX_LENGTH);
|
|
59
64
|
}
|
|
60
65
|
}
|
|
66
|
+
export function assertReferenceOrEns(value) {
|
|
67
|
+
if (typeof value !== 'string') {
|
|
68
|
+
throw new TypeError('ReferenceOrEns has to be a string!');
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (isHexString(value)) {
|
|
72
|
+
assertReference(value);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* a.asdf - VALID
|
|
77
|
+
* test.eth - VALID
|
|
78
|
+
* ADAM.ETH - VALID
|
|
79
|
+
* ADAM UHLIR.ETH - INVALID
|
|
80
|
+
* test.whatever.eth - VALID
|
|
81
|
+
* -adg.ets - INVALID
|
|
82
|
+
* adg-.ets - INVALID
|
|
83
|
+
* as-a.com - VALID
|
|
84
|
+
* ethswarm.org - VALID
|
|
85
|
+
* http://asdf.asf - INVALID
|
|
86
|
+
* řš+ýí.šě+ř.čě - VALID
|
|
87
|
+
* tsg.asg?asg - INVALID
|
|
88
|
+
* tsg.asg:1599 - INVALID
|
|
89
|
+
* ethswarm.something- - INVALID
|
|
90
|
+
* ethswarm.-something - INVALID
|
|
91
|
+
* ethswarm.some-thing - VALID
|
|
92
|
+
*
|
|
93
|
+
* The idea of this regex is to match strings that are 1 to 63 characters long and do not start or end with dash character
|
|
94
|
+
*
|
|
95
|
+
* This part matches 2-63 character string that does not start or end with -
|
|
96
|
+
* [^-.\/?:\s][^.\/?:\s]{0,61}[^-.\/?:\s] <regexp1>
|
|
97
|
+
*
|
|
98
|
+
* For 1 character long string we use the part after |
|
|
99
|
+
* [^-.\/?:\s] <regexp2>
|
|
100
|
+
*
|
|
101
|
+
* This is terminated in a group with . character an repeated at least once
|
|
102
|
+
* (<regexp1>|<regexp2>\.)+
|
|
103
|
+
*
|
|
104
|
+
* This covers everything but top level domain which is 2 to 63 characters long so we can just use the <regexp2> again
|
|
105
|
+
* ^(<regexp1>|<regexp2>\.)+<regexp1>$
|
|
106
|
+
*/
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
const DOMAIN_REGEX = /^(?:(?:[^-.\/?:\s][^.\/?:\s]{0,61}[^-.\/?:\s]|[^-.\/?:\s]{1,2})\.)+[^-.\/?:\s][^.\/?:\s]{0,61}[^-.\/?:\s]$/; // We are doing best-effort validation of domain here. The proper way would be to do validation using IDNA UTS64 standard
|
|
110
|
+
// but that would give us high penalty to our dependencies as the library (idna-uts46-hx) that does this validation and translation
|
|
111
|
+
// adds 160kB minified size which is significant. We expects that full validation will be done on Bee side.
|
|
112
|
+
|
|
113
|
+
if (!DOMAIN_REGEX.test(value)) {
|
|
114
|
+
throw new TypeError('ReferenceOrEns is not valid Reference, but also not valid ENS domain.');
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Function that mainly converts Swarm CID into hex encoded Swarm Reference
|
|
119
|
+
*
|
|
120
|
+
* @param value
|
|
121
|
+
* @param expectedCidType
|
|
122
|
+
*/
|
|
123
|
+
|
|
124
|
+
export function makeReferenceOrEns(value, expectedCidType) {
|
|
125
|
+
var _a;
|
|
126
|
+
|
|
127
|
+
if (typeof value !== 'string') {
|
|
128
|
+
throw new TypeError('ReferenceCidOrEns has to be a string!');
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
try {
|
|
132
|
+
const result = decodeCid(value);
|
|
133
|
+
|
|
134
|
+
if (result.type !== expectedCidType) {
|
|
135
|
+
throw new BeeError(`CID was expected to be of type ${expectedCidType}, but got instead ${(_a = result.type) !== null && _a !== void 0 ? _a : 'non-Swarm CID'}`);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return result.reference;
|
|
139
|
+
} catch (e) {
|
|
140
|
+
if (e instanceof BeeError) throw e;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
assertReferenceOrEns(value);
|
|
144
|
+
return value;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Function that adds getter which converts the reference into CID base32 encoded string.
|
|
148
|
+
* @param result
|
|
149
|
+
* @param cidType Type as described in the @ethersphere/swarm-cids-js -> ReferenceType
|
|
150
|
+
*/
|
|
151
|
+
|
|
152
|
+
export function addCidConversionFunction(result, cidType) {
|
|
153
|
+
return Object.assign(Object.assign({}, result), {
|
|
154
|
+
get cid() {
|
|
155
|
+
return encodeReference(result.reference, cidType).toString();
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
});
|
|
159
|
+
}
|
|
61
160
|
export function assertAddress(value) {
|
|
62
161
|
assertHexString(value, ADDRESS_HEX_LENGTH, 'Address');
|
|
63
162
|
}
|
|
@@ -221,6 +320,14 @@ export function assertPostageBatchOptions(value) {
|
|
|
221
320
|
if ((options === null || options === void 0 ? void 0 : options.immutableFlag) !== undefined) {
|
|
222
321
|
assertBoolean(options.immutableFlag);
|
|
223
322
|
}
|
|
323
|
+
|
|
324
|
+
if ((options === null || options === void 0 ? void 0 : options.waitForUsable) !== undefined) {
|
|
325
|
+
assertBoolean(options.waitForUsable);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
if ((options === null || options === void 0 ? void 0 : options.waitForUsableTimeout) !== undefined) {
|
|
329
|
+
assertNonNegativeInteger(options.waitForUsableTimeout, 'options.waitForUsableTimeout');
|
|
330
|
+
}
|
|
224
331
|
}
|
|
225
332
|
export function assertCashoutOptions(value) {
|
|
226
333
|
if (value === undefined) {
|
|
File without changes
|
|
File without changes
|