@ethersphere/bee-js 6.0.0-pre.0 → 6.0.0-pre.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -17
- package/dist/cjs/bee-debug.js +569 -0
- package/dist/cjs/bee.js +873 -0
- package/dist/cjs/chunk/bmt.js +55 -0
- package/dist/cjs/chunk/cac.js +56 -0
- package/dist/cjs/chunk/serialize.js +19 -0
- package/dist/cjs/chunk/signer.js +126 -0
- package/dist/cjs/chunk/soc.js +159 -0
- package/dist/cjs/chunk/span.js +29 -0
- package/dist/cjs/feed/identifier.js +35 -0
- package/dist/cjs/feed/index.js +116 -0
- package/dist/cjs/feed/json.js +28 -0
- package/dist/cjs/feed/retrievable.js +58 -0
- package/dist/cjs/feed/topic.js +25 -0
- package/dist/cjs/feed/type.js +15 -0
- package/dist/cjs/index.js +39 -0
- package/dist/cjs/modules/bytes.js +62 -0
- package/dist/cjs/modules/bzz.js +125 -0
- package/dist/cjs/modules/chunk.js +48 -0
- package/dist/cjs/modules/debug/balance.js +60 -0
- package/dist/cjs/modules/debug/chequebook.js +142 -0
- package/dist/cjs/modules/debug/chunk.js +38 -0
- package/dist/cjs/modules/debug/connectivity.js +54 -0
- package/dist/cjs/modules/debug/settlements.js +32 -0
- package/dist/cjs/modules/debug/stake.js +57 -0
- package/dist/cjs/modules/debug/stamps.js +68 -0
- package/dist/cjs/modules/debug/states.js +64 -0
- package/dist/cjs/modules/debug/status.js +148 -0
- package/dist/cjs/modules/debug/tag.js +19 -0
- package/dist/cjs/modules/debug/transactions.js +64 -0
- package/dist/cjs/modules/feed.js +66 -0
- package/dist/cjs/modules/pinning.js +63 -0
- package/dist/cjs/modules/pss.js +44 -0
- package/dist/cjs/modules/soc.js +32 -0
- package/dist/cjs/modules/status.js +15 -0
- package/dist/cjs/modules/stewardship.js +28 -0
- package/dist/cjs/modules/tag.js +77 -0
- package/dist/cjs/package.json +8 -0
- package/dist/cjs/types/debug.js +10 -0
- package/dist/cjs/types/index.js +51 -0
- package/dist/cjs/utils/bytes.js +121 -0
- package/dist/cjs/utils/collection.browser.js +23 -0
- package/dist/cjs/utils/collection.js +59 -0
- package/dist/cjs/utils/collection.node.js +71 -0
- package/dist/cjs/utils/data.browser.js +61 -0
- package/dist/cjs/utils/data.js +45 -0
- package/dist/cjs/utils/error.js +16 -0
- package/dist/cjs/utils/eth.js +199 -0
- package/dist/cjs/utils/expose.js +44 -0
- package/dist/cjs/utils/file.js +38 -0
- package/dist/cjs/utils/hash.js +21 -0
- package/dist/cjs/utils/headers.js +59 -0
- package/dist/cjs/utils/hex.js +150 -0
- package/dist/cjs/utils/http.js +30 -0
- package/dist/cjs/utils/pss.js +18 -0
- package/dist/cjs/utils/reference.js +36 -0
- package/dist/cjs/utils/stamps.js +17 -0
- package/dist/cjs/utils/stream.js +146 -0
- package/dist/cjs/utils/tar.js +25 -0
- package/dist/cjs/utils/type.js +434 -0
- package/dist/cjs/utils/uint64.js +29 -0
- package/dist/cjs/utils/url.js +56 -0
- package/dist/index.browser.min.js +3 -0
- package/dist/index.browser.min.js.LICENSE.txt +50 -0
- package/dist/index.browser.min.js.map +1 -0
- package/dist/{src → mjs}/bee-debug.js +101 -185
- package/dist/{src → mjs}/bee.js +81 -234
- package/dist/{src → mjs}/chunk/bmt.js +4 -10
- package/dist/{src → mjs}/chunk/cac.js +0 -3
- package/dist/{src → mjs}/chunk/signer.js +1 -18
- package/dist/{src → mjs}/chunk/soc.js +17 -29
- package/dist/{src → mjs}/chunk/span.js +2 -5
- package/dist/{src → mjs}/feed/identifier.js +0 -6
- package/dist/{src → mjs}/feed/index.js +24 -27
- package/dist/{src → mjs}/feed/json.js +2 -5
- package/dist/{src → mjs}/feed/retrievable.js +7 -21
- package/dist/{src → mjs}/feed/topic.js +0 -2
- package/dist/{src → mjs}/index.js +2 -2
- package/dist/{src → mjs}/modules/bytes.js +16 -19
- package/dist/{src → mjs}/modules/bzz.js +33 -40
- package/dist/{src → mjs}/modules/chunk.js +11 -13
- package/dist/mjs/modules/debug/balance.js +53 -0
- package/dist/mjs/modules/debug/chequebook.js +135 -0
- package/dist/{src → mjs}/modules/debug/chunk.js +10 -12
- package/dist/mjs/modules/debug/connectivity.js +45 -0
- package/dist/mjs/modules/debug/settlements.js +27 -0
- package/dist/mjs/modules/debug/stake.js +51 -0
- package/dist/mjs/modules/debug/stamps.js +61 -0
- package/dist/mjs/modules/debug/states.js +58 -0
- package/dist/{src → mjs}/modules/debug/status.js +46 -37
- package/dist/mjs/modules/debug/tag.js +15 -0
- package/dist/mjs/modules/debug/transactions.js +59 -0
- package/dist/{src → mjs}/modules/feed.js +15 -21
- package/dist/mjs/modules/pinning.js +56 -0
- package/dist/{src → mjs}/modules/pss.js +7 -9
- package/dist/{src → mjs}/modules/soc.js +6 -7
- package/dist/mjs/modules/status.js +11 -0
- package/dist/mjs/modules/stewardship.js +23 -0
- package/dist/mjs/modules/tag.js +72 -0
- package/dist/mjs/package.json +8 -0
- package/dist/{src → mjs}/types/debug.js +0 -1
- package/dist/{src → mjs}/types/index.js +0 -4
- package/dist/{src → mjs}/utils/bytes.js +8 -17
- package/dist/{src/utils/collection-browser.js → mjs/utils/collection.browser.js} +0 -1
- package/dist/{src → mjs}/utils/collection.js +0 -12
- package/dist/{src/utils/collection-node.js → mjs/utils/collection.node.js} +0 -13
- package/dist/{src → mjs}/utils/data.browser.js +2 -11
- package/dist/{src → mjs}/utils/data.js +0 -7
- package/dist/mjs/utils/error.js +11 -0
- package/dist/{src → mjs}/utils/eth.js +6 -28
- package/dist/{src → mjs}/utils/expose.js +1 -1
- package/dist/{src → mjs}/utils/file.js +4 -9
- package/dist/{src → mjs}/utils/hash.js +0 -1
- package/dist/{src → mjs}/utils/headers.js +5 -13
- package/dist/{src → mjs}/utils/hex.js +6 -25
- package/dist/mjs/utils/http.js +22 -0
- package/dist/{src → mjs}/utils/pss.js +0 -2
- package/dist/{src → mjs}/utils/reference.js +2 -5
- package/dist/{src → mjs}/utils/stream.js +3 -26
- package/dist/{src → mjs}/utils/tar.js +2 -5
- package/dist/{src → mjs}/utils/type.js +23 -80
- package/dist/{src → mjs}/utils/uint64.js +0 -1
- package/dist/{src → mjs}/utils/url.js +2 -10
- package/dist/types/bee-debug.d.ts +71 -46
- package/dist/types/bee.d.ts +34 -58
- package/dist/types/chunk/bmt.d.ts +1 -1
- package/dist/types/chunk/cac.d.ts +1 -1
- package/dist/types/chunk/soc.d.ts +9 -9
- package/dist/types/chunk/span.d.ts +1 -1
- package/dist/types/feed/index.d.ts +10 -10
- package/dist/types/feed/json.d.ts +2 -2
- package/dist/types/feed/retrievable.d.ts +2 -2
- package/dist/types/feed/type.d.ts +1 -1
- package/dist/types/index.d.ts +13 -2
- package/dist/types/modules/bytes.d.ts +5 -5
- package/dist/types/modules/bzz.d.ts +8 -8
- package/dist/types/modules/chunk.d.ts +4 -4
- package/dist/types/modules/debug/balance.d.ts +9 -9
- package/dist/types/modules/debug/chequebook.d.ts +17 -17
- package/dist/types/modules/debug/chunk.d.ts +5 -5
- package/dist/types/modules/debug/connectivity.d.ts +7 -7
- package/dist/types/modules/debug/settlements.d.ts +5 -5
- package/dist/types/modules/debug/stake.d.ts +21 -0
- package/dist/types/modules/debug/stamps.d.ts +7 -7
- package/dist/types/modules/debug/states.d.ts +7 -7
- package/dist/types/modules/debug/status.d.ts +21 -15
- package/dist/types/modules/debug/tag.d.ts +3 -3
- package/dist/types/modules/debug/transactions.d.ts +5 -5
- package/dist/types/modules/feed.d.ts +3 -3
- package/dist/types/modules/pinning.d.ts +7 -7
- package/dist/types/modules/pss.d.ts +3 -3
- package/dist/types/modules/soc.d.ts +2 -2
- package/dist/types/modules/status.d.ts +3 -3
- package/dist/types/modules/stewardship.d.ts +3 -3
- package/dist/types/modules/tag.d.ts +6 -6
- package/dist/types/types/debug.d.ts +35 -2
- package/dist/types/types/index.d.ts +45 -88
- package/dist/types/utils/error.d.ts +0 -26
- package/dist/types/utils/eth.d.ts +6 -6
- package/dist/types/utils/expose.d.ts +4 -7
- package/dist/types/utils/hash.d.ts +1 -1
- package/dist/types/utils/headers.d.ts +1 -1
- package/dist/types/utils/hex.d.ts +4 -4
- package/dist/types/utils/http.d.ts +12 -21
- package/dist/types/utils/stream.d.ts +1 -1
- package/dist/types/utils/type.d.ts +3 -2
- package/dist/types/utils/uint64.d.ts +1 -1
- package/package.json +59 -49
- package/dist/index.browser.js +0 -33
- package/dist/index.browser.js.map +0 -7
- package/dist/src/modules/debug/balance.js +0 -57
- package/dist/src/modules/debug/chequebook.js +0 -150
- package/dist/src/modules/debug/connectivity.js +0 -45
- package/dist/src/modules/debug/settlements.js +0 -29
- package/dist/src/modules/debug/stamps.js +0 -64
- package/dist/src/modules/debug/states.js +0 -46
- package/dist/src/modules/debug/tag.js +0 -16
- package/dist/src/modules/debug/transactions.js +0 -69
- package/dist/src/modules/pinning.js +0 -60
- package/dist/src/modules/status.js +0 -12
- package/dist/src/modules/stewardship.js +0 -24
- package/dist/src/modules/tag.js +0 -77
- package/dist/src/utils/error.js +0 -47
- package/dist/src/utils/http.js +0 -162
- package/dist/src/utils/merge.js +0 -36
- package/dist/src/utils/sleep.js +0 -8
- package/dist/types/utils/merge.d.ts +0 -8
- package/dist/types/utils/sleep.d.ts +0 -6
- /package/dist/{src → mjs}/chunk/serialize.js +0 -0
- /package/dist/{src → mjs}/feed/type.js +0 -0
- /package/dist/{src → mjs}/utils/stamps.js +0 -0
- /package/dist/types/utils/{collection-browser.d.ts → collection.browser.d.ts} +0 -0
- /package/dist/types/utils/{collection-node.d.ts → collection.node.d.ts} +0 -0
|
@@ -1,52 +1,66 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import getMajorSemver from 'semver/functions/major.js';
|
|
2
|
+
import { http } from "../../utils/http.js"; // Following lines bellow are automatically updated with GitHub Action when Bee version is updated
|
|
3
3
|
// so if you are changing anything about them change the `update_bee` action accordingly!
|
|
4
|
-
|
|
5
|
-
export const
|
|
6
|
-
export const
|
|
7
|
-
export const SUPPORTED_DEBUG_API_VERSION = '3.0.2';
|
|
4
|
+
export const SUPPORTED_BEE_VERSION_EXACT = '1.12.0-88c1d236';
|
|
5
|
+
export const SUPPORTED_API_VERSION = '4.0.0';
|
|
6
|
+
export const SUPPORTED_DEBUG_API_VERSION = '4.0.0';
|
|
8
7
|
export const SUPPORTED_BEE_VERSION = SUPPORTED_BEE_VERSION_EXACT.substring(0, SUPPORTED_BEE_VERSION_EXACT.indexOf('-'));
|
|
9
8
|
const NODE_INFO_URL = 'node';
|
|
10
9
|
const HEALTH_URL = 'health';
|
|
10
|
+
const READINESS_URL = 'readiness';
|
|
11
11
|
/**
|
|
12
12
|
* Get health of node
|
|
13
13
|
*
|
|
14
|
-
* @param
|
|
14
|
+
* @param kyOptions Ky Options for making requests
|
|
15
15
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const response = await http(ky, {
|
|
16
|
+
export async function getHealth(requestOptions) {
|
|
17
|
+
const response = await http(requestOptions, {
|
|
19
18
|
method: 'get',
|
|
20
|
-
|
|
19
|
+
url: HEALTH_URL,
|
|
21
20
|
responseType: 'json'
|
|
22
21
|
});
|
|
23
|
-
return response.
|
|
22
|
+
return response.data;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Get readiness of node
|
|
26
|
+
*
|
|
27
|
+
* @param kyOptions Ky Options for making requests
|
|
28
|
+
*/
|
|
29
|
+
export async function getReadiness(requestOptions) {
|
|
30
|
+
try {
|
|
31
|
+
const response = await http(requestOptions, {
|
|
32
|
+
method: 'get',
|
|
33
|
+
url: READINESS_URL
|
|
34
|
+
});
|
|
35
|
+
return response.status === 200;
|
|
36
|
+
} catch {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
24
39
|
}
|
|
25
40
|
/**
|
|
26
41
|
* Get information about Bee node
|
|
27
42
|
*
|
|
28
|
-
* @param
|
|
43
|
+
* @param kyOptions Ky Options for making requests
|
|
29
44
|
*/
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const response = await http(ky, {
|
|
45
|
+
export async function getNodeInfo(requestOptions) {
|
|
46
|
+
const response = await http(requestOptions, {
|
|
33
47
|
method: 'get',
|
|
34
|
-
|
|
48
|
+
url: NODE_INFO_URL,
|
|
35
49
|
responseType: 'json'
|
|
36
50
|
});
|
|
37
|
-
return response.
|
|
51
|
+
return response.data;
|
|
38
52
|
}
|
|
39
53
|
/**
|
|
40
54
|
* Connects to a node and checks if it is a supported Bee version by the bee-js
|
|
41
55
|
*
|
|
42
|
-
* @param
|
|
56
|
+
* @param kyOptions Ky Options for making requests
|
|
43
57
|
*
|
|
44
58
|
* @returns true if the Bee node version is supported
|
|
45
59
|
* @deprecated Use `isSupportedExactVersion` instead
|
|
46
60
|
*/
|
|
47
|
-
|
|
48
|
-
export async function isSupportedVersion(
|
|
49
|
-
return isSupportedExactVersion(
|
|
61
|
+
// TODO: Remove on break
|
|
62
|
+
export async function isSupportedVersion(requestOptions) {
|
|
63
|
+
return isSupportedExactVersion(requestOptions);
|
|
50
64
|
}
|
|
51
65
|
/**
|
|
52
66
|
* Connects to a node and checks if its version matches with the one that bee-js supports.
|
|
@@ -58,11 +72,10 @@ export async function isSupportedVersion(ky) {
|
|
|
58
72
|
*
|
|
59
73
|
* @param ky
|
|
60
74
|
*/
|
|
61
|
-
|
|
62
|
-
export async function isSupportedExactVersion(ky) {
|
|
75
|
+
export async function isSupportedExactVersion(requestOptions) {
|
|
63
76
|
const {
|
|
64
77
|
version
|
|
65
|
-
} = await getHealth(
|
|
78
|
+
} = await getHealth(requestOptions);
|
|
66
79
|
return version === SUPPORTED_BEE_VERSION_EXACT;
|
|
67
80
|
}
|
|
68
81
|
/**
|
|
@@ -73,11 +86,10 @@ export async function isSupportedExactVersion(ky) {
|
|
|
73
86
|
*
|
|
74
87
|
* @param ky
|
|
75
88
|
*/
|
|
76
|
-
|
|
77
|
-
export async function isSupportedMainApiVersion(ky) {
|
|
89
|
+
export async function isSupportedMainApiVersion(requestOptions) {
|
|
78
90
|
const {
|
|
79
91
|
apiVersion
|
|
80
|
-
} = await getHealth(
|
|
92
|
+
} = await getHealth(requestOptions);
|
|
81
93
|
return getMajorSemver(apiVersion) === getMajorSemver(SUPPORTED_API_VERSION);
|
|
82
94
|
}
|
|
83
95
|
/**
|
|
@@ -88,11 +100,10 @@ export async function isSupportedMainApiVersion(ky) {
|
|
|
88
100
|
*
|
|
89
101
|
* @param ky
|
|
90
102
|
*/
|
|
91
|
-
|
|
92
|
-
export async function isSupportedDebugApiVersion(ky) {
|
|
103
|
+
export async function isSupportedDebugApiVersion(requestOptions) {
|
|
93
104
|
const {
|
|
94
105
|
debugApiVersion
|
|
95
|
-
} = await getHealth(
|
|
106
|
+
} = await getHealth(requestOptions);
|
|
96
107
|
return getMajorSemver(debugApiVersion) === getMajorSemver(SUPPORTED_DEBUG_API_VERSION);
|
|
97
108
|
}
|
|
98
109
|
/**
|
|
@@ -102,12 +113,11 @@ export async function isSupportedDebugApiVersion(ky) {
|
|
|
102
113
|
*
|
|
103
114
|
* @param ky
|
|
104
115
|
*/
|
|
105
|
-
|
|
106
|
-
export async function isSupportedApiVersion(ky) {
|
|
116
|
+
export async function isSupportedApiVersion(requestOptions) {
|
|
107
117
|
const {
|
|
108
118
|
apiVersion,
|
|
109
119
|
debugApiVersion
|
|
110
|
-
} = await getHealth(
|
|
120
|
+
} = await getHealth(requestOptions);
|
|
111
121
|
return getMajorSemver(apiVersion) === getMajorSemver(SUPPORTED_API_VERSION) && getMajorSemver(debugApiVersion) === getMajorSemver(SUPPORTED_DEBUG_API_VERSION);
|
|
112
122
|
}
|
|
113
123
|
/**
|
|
@@ -116,13 +126,12 @@ export async function isSupportedApiVersion(ky) {
|
|
|
116
126
|
*
|
|
117
127
|
* @param ky
|
|
118
128
|
*/
|
|
119
|
-
|
|
120
|
-
export async function getVersions(ky) {
|
|
129
|
+
export async function getVersions(requestOptions) {
|
|
121
130
|
const {
|
|
122
131
|
version,
|
|
123
132
|
apiVersion,
|
|
124
133
|
debugApiVersion
|
|
125
|
-
} = await getHealth(
|
|
134
|
+
} = await getHealth(requestOptions);
|
|
126
135
|
return {
|
|
127
136
|
supportedBeeVersion: SUPPORTED_BEE_VERSION_EXACT,
|
|
128
137
|
supportedBeeApiVersion: SUPPORTED_API_VERSION,
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { http } from "../../utils/http.js";
|
|
2
|
+
const endpoint = 'tags';
|
|
3
|
+
/**
|
|
4
|
+
* Retrieve tag with extended information from Bee node
|
|
5
|
+
*
|
|
6
|
+
* @param kyOptions Ky Options for making requests
|
|
7
|
+
* @param uid UID of tag to be retrieved
|
|
8
|
+
*/
|
|
9
|
+
export async function retrieveExtendedTag(requestOptions, uid) {
|
|
10
|
+
const response = await http(requestOptions, {
|
|
11
|
+
url: `${endpoint}/${uid}`,
|
|
12
|
+
responseType: 'json'
|
|
13
|
+
});
|
|
14
|
+
return response.data;
|
|
15
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { http } from "../../utils/http.js";
|
|
2
|
+
const transactionsEndpoint = 'transactions';
|
|
3
|
+
/**
|
|
4
|
+
* Get list of all pending transactions
|
|
5
|
+
*
|
|
6
|
+
* @param ky Debug Ky instance
|
|
7
|
+
*/
|
|
8
|
+
export async function getAllTransactions(requestOptions) {
|
|
9
|
+
const response = await http(requestOptions, {
|
|
10
|
+
url: transactionsEndpoint,
|
|
11
|
+
responseType: 'json'
|
|
12
|
+
});
|
|
13
|
+
return response.data.pendingTransactions;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Get information for specific pending transactions
|
|
17
|
+
*
|
|
18
|
+
* @param ky Debug Ky instance
|
|
19
|
+
* @param transactionHash Hash of the transaction
|
|
20
|
+
*/
|
|
21
|
+
export async function getTransaction(requestOptions, transactionHash) {
|
|
22
|
+
const response = await http(requestOptions, {
|
|
23
|
+
url: `${transactionsEndpoint}/${transactionHash}`,
|
|
24
|
+
responseType: 'json'
|
|
25
|
+
});
|
|
26
|
+
return response.data;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Rebroadcast existing transaction
|
|
30
|
+
*
|
|
31
|
+
* @param ky Debug Ky instance
|
|
32
|
+
* @param transactionHash Hash of the transaction
|
|
33
|
+
*/
|
|
34
|
+
export async function rebroadcastTransaction(requestOptions, transactionHash) {
|
|
35
|
+
const response = await http(requestOptions, {
|
|
36
|
+
method: 'post',
|
|
37
|
+
url: `${transactionsEndpoint}/${transactionHash}`,
|
|
38
|
+
responseType: 'json'
|
|
39
|
+
});
|
|
40
|
+
return response.data.transactionHash;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Cancel existing transaction
|
|
44
|
+
*
|
|
45
|
+
* @param ky Debug Ky instance
|
|
46
|
+
* @param transactionHash Hash of the transaction
|
|
47
|
+
* @param gasPrice Optional gas price
|
|
48
|
+
*/
|
|
49
|
+
export async function cancelTransaction(requestOptions, transactionHash, gasPrice) {
|
|
50
|
+
const response = await http(requestOptions, {
|
|
51
|
+
method: 'delete',
|
|
52
|
+
headers: {
|
|
53
|
+
'gas-price': gasPrice
|
|
54
|
+
},
|
|
55
|
+
url: `${transactionsEndpoint}/${transactionHash}`,
|
|
56
|
+
responseType: 'json'
|
|
57
|
+
});
|
|
58
|
+
return response.data.transactionHash;
|
|
59
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { filterHeaders, http } from "../utils/http.js";
|
|
2
|
-
import { extractUploadHeaders } from "../utils/headers.js";
|
|
3
1
|
import { BeeError } from "../utils/error.js";
|
|
2
|
+
import { extractUploadHeaders } from "../utils/headers.js";
|
|
3
|
+
import { http } from "../utils/http.js";
|
|
4
4
|
const feedEndpoint = 'feeds';
|
|
5
5
|
/**
|
|
6
6
|
* Create an initial feed root manifest
|
|
@@ -11,30 +11,25 @@ const feedEndpoint = 'feeds';
|
|
|
11
11
|
* @param postageBatchId Postage BatchId to be used to create the Feed Manifest
|
|
12
12
|
* @param options Additional options, like type (default: 'sequence')
|
|
13
13
|
*/
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const response = await http(ky, {
|
|
14
|
+
export async function createFeedManifest(requestOptions, owner, topic, postageBatchId, options) {
|
|
15
|
+
const response = await http(requestOptions, {
|
|
17
16
|
method: 'post',
|
|
18
17
|
responseType: 'json',
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
url: `${feedEndpoint}/${owner}/${topic}`,
|
|
19
|
+
params: options,
|
|
21
20
|
headers: extractUploadHeaders(postageBatchId)
|
|
22
21
|
});
|
|
23
|
-
return response.
|
|
22
|
+
return response.data.reference;
|
|
24
23
|
}
|
|
25
|
-
|
|
26
24
|
function readFeedUpdateHeaders(headers) {
|
|
27
|
-
const feedIndex = headers
|
|
28
|
-
const feedIndexNext = headers
|
|
29
|
-
|
|
25
|
+
const feedIndex = headers['swarm-feed-index'];
|
|
26
|
+
const feedIndexNext = headers['swarm-feed-index-next'];
|
|
30
27
|
if (!feedIndex) {
|
|
31
28
|
throw new BeeError('Response did not contain expected swarm-feed-index!');
|
|
32
29
|
}
|
|
33
|
-
|
|
34
30
|
if (!feedIndexNext) {
|
|
35
31
|
throw new BeeError('Response did not contain expected swarm-feed-index-next!');
|
|
36
32
|
}
|
|
37
|
-
|
|
38
33
|
return {
|
|
39
34
|
feedIndex,
|
|
40
35
|
feedIndexNext
|
|
@@ -53,15 +48,14 @@ function readFeedUpdateHeaders(headers) {
|
|
|
53
48
|
* @param topic Topic in hex
|
|
54
49
|
* @param options Additional options, like index, at, type
|
|
55
50
|
*/
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
export async function fetchLatestFeedUpdate(ky, owner, topic, options) {
|
|
59
|
-
const response = await http(ky, {
|
|
51
|
+
export async function fetchLatestFeedUpdate(requestOptions, owner, topic, options) {
|
|
52
|
+
const response = await http(requestOptions, {
|
|
60
53
|
responseType: 'json',
|
|
61
|
-
|
|
62
|
-
|
|
54
|
+
url: `${feedEndpoint}/${owner}/${topic}`,
|
|
55
|
+
params: options
|
|
63
56
|
});
|
|
64
|
-
return {
|
|
57
|
+
return {
|
|
58
|
+
...response.data,
|
|
65
59
|
...readFeedUpdateHeaders(response.headers)
|
|
66
60
|
};
|
|
67
61
|
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { http } from "../utils/http.js";
|
|
2
|
+
const PINNING_ENDPOINT = 'pins';
|
|
3
|
+
/**
|
|
4
|
+
* Pin data with given reference
|
|
5
|
+
*
|
|
6
|
+
* @param kyOptions Ky Options for making requests
|
|
7
|
+
* @param reference Bee data reference
|
|
8
|
+
*/
|
|
9
|
+
export async function pin(requestOptions, reference) {
|
|
10
|
+
await http(requestOptions, {
|
|
11
|
+
method: 'post',
|
|
12
|
+
responseType: 'json',
|
|
13
|
+
url: `${PINNING_ENDPOINT}/${reference}`
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Unpin data with given reference
|
|
18
|
+
*
|
|
19
|
+
* @param kyOptions Ky Options for making requests
|
|
20
|
+
* @param reference Bee data reference
|
|
21
|
+
*/
|
|
22
|
+
export async function unpin(requestOptions, reference) {
|
|
23
|
+
await http(requestOptions, {
|
|
24
|
+
method: 'delete',
|
|
25
|
+
responseType: 'json',
|
|
26
|
+
url: `${PINNING_ENDPOINT}/${reference}`
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Get pin status for specific address.
|
|
31
|
+
*
|
|
32
|
+
* @param ky Ky instance
|
|
33
|
+
* @param reference
|
|
34
|
+
* @throws Error if given address is not pinned
|
|
35
|
+
*/
|
|
36
|
+
export async function getPin(requestOptions, reference) {
|
|
37
|
+
const response = await http(requestOptions, {
|
|
38
|
+
method: 'get',
|
|
39
|
+
responseType: 'json',
|
|
40
|
+
url: `${PINNING_ENDPOINT}/${reference}`
|
|
41
|
+
});
|
|
42
|
+
return response.data;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Get list of all pins
|
|
46
|
+
*
|
|
47
|
+
* @param ky Ky instance
|
|
48
|
+
*/
|
|
49
|
+
export async function getAllPins(requestOptions) {
|
|
50
|
+
const response = await http(requestOptions, {
|
|
51
|
+
method: 'get',
|
|
52
|
+
responseType: 'json',
|
|
53
|
+
url: `${PINNING_ENDPOINT}`
|
|
54
|
+
});
|
|
55
|
+
return response.data.references;
|
|
56
|
+
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import WebSocket from 'isomorphic-ws';
|
|
2
2
|
import { prepareData } from "../utils/data.js";
|
|
3
|
-
import { http } from "../utils/http.js";
|
|
4
3
|
import { extractUploadHeaders } from "../utils/headers.js";
|
|
4
|
+
import { http } from "../utils/http.js";
|
|
5
5
|
const endpoint = 'pss';
|
|
6
6
|
/**
|
|
7
7
|
* Send to recipient or target with Postal Service for Swarm
|
|
8
8
|
*
|
|
9
|
-
* @param
|
|
9
|
+
* @param kyOptions Ky Options for making requests
|
|
10
10
|
* @param topic Topic name
|
|
11
11
|
* @param target Target message address prefix
|
|
12
12
|
* @param data
|
|
@@ -14,14 +14,13 @@ const endpoint = 'pss';
|
|
|
14
14
|
* @param recipient Recipient public key
|
|
15
15
|
*
|
|
16
16
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
await http(ky, {
|
|
17
|
+
export async function send(requestOptions, topic, target, data, postageBatchId, recipient) {
|
|
18
|
+
await http(requestOptions, {
|
|
20
19
|
method: 'post',
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
url: `${endpoint}/send/${topic}/${target}`,
|
|
21
|
+
data: await prepareData(data),
|
|
23
22
|
responseType: 'json',
|
|
24
|
-
|
|
23
|
+
params: {
|
|
25
24
|
recipient
|
|
26
25
|
},
|
|
27
26
|
headers: extractUploadHeaders(postageBatchId)
|
|
@@ -33,7 +32,6 @@ export async function send(ky, topic, target, data, postageBatchId, recipient) {
|
|
|
33
32
|
* @param url Bee node URL
|
|
34
33
|
* @param topic Topic name
|
|
35
34
|
*/
|
|
36
|
-
|
|
37
35
|
export function subscribe(url, topic) {
|
|
38
36
|
const wsUrl = url.replace(/^http/i, 'ws');
|
|
39
37
|
return new WebSocket(`${wsUrl}/${endpoint}/subscribe/${topic}`);
|
|
@@ -12,20 +12,19 @@ const socEndpoint = 'soc';
|
|
|
12
12
|
* @param postageBatchId Postage BatchId that will be assigned to uploaded data
|
|
13
13
|
* @param options Additional options like tag, encryption, pinning
|
|
14
14
|
*/
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const response = await http(ky, {
|
|
15
|
+
export async function upload(requestOptions, owner, identifier, signature, data, postageBatchId, options) {
|
|
16
|
+
const response = await http(requestOptions, {
|
|
18
17
|
method: 'post',
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
url: `${socEndpoint}/${owner}/${identifier}`,
|
|
19
|
+
data,
|
|
21
20
|
headers: {
|
|
22
21
|
'content-type': 'application/octet-stream',
|
|
23
22
|
...extractUploadHeaders(postageBatchId, options)
|
|
24
23
|
},
|
|
25
24
|
responseType: 'json',
|
|
26
|
-
|
|
25
|
+
params: {
|
|
27
26
|
sig: signature
|
|
28
27
|
}
|
|
29
28
|
});
|
|
30
|
-
return response.
|
|
29
|
+
return response.data.reference;
|
|
31
30
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { http } from "../utils/http.js";
|
|
2
|
+
/**
|
|
3
|
+
* Ping the base bee URL. If connection was not successful throw error
|
|
4
|
+
*
|
|
5
|
+
* @param kyOptions Ky instance for given Bee class instance
|
|
6
|
+
*/
|
|
7
|
+
export async function checkConnection(requestOptions) {
|
|
8
|
+
await http(requestOptions, {
|
|
9
|
+
url: ''
|
|
10
|
+
});
|
|
11
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { http } from "../utils/http.js";
|
|
2
|
+
const stewardshipEndpoint = 'stewardship';
|
|
3
|
+
/**
|
|
4
|
+
* Reupload locally pinned data
|
|
5
|
+
* @param ky Ky instance
|
|
6
|
+
* @param reference
|
|
7
|
+
* @param options
|
|
8
|
+
* @throws BeeResponseError if not locally pinned or invalid data
|
|
9
|
+
*/
|
|
10
|
+
export async function reupload(requestOptions, reference) {
|
|
11
|
+
await http(requestOptions, {
|
|
12
|
+
method: 'put',
|
|
13
|
+
url: `${stewardshipEndpoint}/${reference}`
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
export async function isRetrievable(requestOptions, reference) {
|
|
17
|
+
const response = await http(requestOptions, {
|
|
18
|
+
method: 'get',
|
|
19
|
+
responseType: 'json',
|
|
20
|
+
url: `${stewardshipEndpoint}/${reference}`
|
|
21
|
+
});
|
|
22
|
+
return response.data.isRetrievable;
|
|
23
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { http } from "../utils/http.js";
|
|
2
|
+
const endpoint = 'tags';
|
|
3
|
+
/**
|
|
4
|
+
* Create new tag on the Bee node
|
|
5
|
+
*
|
|
6
|
+
* @param url Bee tag URL
|
|
7
|
+
*/
|
|
8
|
+
export async function createTag(requestOptions) {
|
|
9
|
+
const response = await http(requestOptions, {
|
|
10
|
+
method: 'post',
|
|
11
|
+
url: endpoint,
|
|
12
|
+
responseType: 'json'
|
|
13
|
+
});
|
|
14
|
+
return response.data;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Retrieve tag information from Bee node
|
|
18
|
+
*
|
|
19
|
+
* @param url Bee tag URL
|
|
20
|
+
* @param uid UID of tag to be retrieved
|
|
21
|
+
*/
|
|
22
|
+
export async function retrieveTag(requestOptions, uid) {
|
|
23
|
+
const response = await http(requestOptions, {
|
|
24
|
+
url: `${endpoint}/${uid}`,
|
|
25
|
+
responseType: 'json'
|
|
26
|
+
});
|
|
27
|
+
return response.data;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Get limited listing of all tags.
|
|
31
|
+
*
|
|
32
|
+
* @param url
|
|
33
|
+
* @param offset
|
|
34
|
+
* @param limit
|
|
35
|
+
*/
|
|
36
|
+
export async function getAllTags(requestOptions, offset, limit) {
|
|
37
|
+
const response = await http(requestOptions, {
|
|
38
|
+
url: endpoint,
|
|
39
|
+
params: {
|
|
40
|
+
offset,
|
|
41
|
+
limit
|
|
42
|
+
},
|
|
43
|
+
responseType: 'json'
|
|
44
|
+
});
|
|
45
|
+
return response.data.tags;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Removes tag from the Bee node.
|
|
49
|
+
* @param url
|
|
50
|
+
* @param uid
|
|
51
|
+
*/
|
|
52
|
+
export async function deleteTag(requestOptions, uid) {
|
|
53
|
+
await http(requestOptions, {
|
|
54
|
+
method: 'delete',
|
|
55
|
+
url: `${endpoint}/${uid}`
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Updates tag
|
|
60
|
+
* @param url
|
|
61
|
+
* @param uid
|
|
62
|
+
* @param reference
|
|
63
|
+
*/
|
|
64
|
+
export async function updateTag(requestOptions, uid, reference) {
|
|
65
|
+
await http(requestOptions, {
|
|
66
|
+
method: 'patch',
|
|
67
|
+
url: `${endpoint}/${uid}`,
|
|
68
|
+
data: {
|
|
69
|
+
reference
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
@@ -14,12 +14,10 @@ export const ENCRYPTED_REFERENCE_BYTES_LENGTH = 64;
|
|
|
14
14
|
/**
|
|
15
15
|
* Minimal depth that can be used for creation of postage batch
|
|
16
16
|
*/
|
|
17
|
-
|
|
18
17
|
export const STAMPS_DEPTH_MIN = 17;
|
|
19
18
|
/**
|
|
20
19
|
* Maximal depth that can be used for creation of postage batch
|
|
21
20
|
*/
|
|
22
|
-
|
|
23
21
|
export const STAMPS_DEPTH_MAX = 255;
|
|
24
22
|
export const TAGS_LIMIT_MIN = 1;
|
|
25
23
|
export const TAGS_LIMIT_MAX = 1000;
|
|
@@ -27,12 +25,10 @@ export const FEED_INDEX_HEX_LENGTH = 16;
|
|
|
27
25
|
/*********************************************************
|
|
28
26
|
* Writers and Readers interfaces
|
|
29
27
|
*/
|
|
30
|
-
|
|
31
28
|
export const TOPIC_BYTES_LENGTH = 32;
|
|
32
29
|
export const TOPIC_HEX_LENGTH = 64;
|
|
33
30
|
/*********************************************************
|
|
34
31
|
* Ethereum compatible signing interfaces and definitions
|
|
35
32
|
*/
|
|
36
|
-
|
|
37
33
|
export const SIGNATURE_HEX_LENGTH = 130;
|
|
38
34
|
export const SIGNATURE_BYTES_LENGTH = 65;
|
|
@@ -5,7 +5,6 @@ import { bytesToHex } from "./hex.js";
|
|
|
5
5
|
* @param b The byte array
|
|
6
6
|
* @param length The length of the byte array
|
|
7
7
|
*/
|
|
8
|
-
|
|
9
8
|
export function isBytes(b, length) {
|
|
10
9
|
return b instanceof Uint8Array && b.length === length;
|
|
11
10
|
}
|
|
@@ -15,12 +14,10 @@ export function isBytes(b, length) {
|
|
|
15
14
|
* @param offset
|
|
16
15
|
* @param length
|
|
17
16
|
*/
|
|
18
|
-
|
|
19
17
|
export function hasBytesAtOffset(data, offset, length) {
|
|
20
18
|
if (!(data instanceof Uint8Array)) {
|
|
21
19
|
throw new TypeError('Data has to an Uint8Array!');
|
|
22
20
|
}
|
|
23
|
-
|
|
24
21
|
const offsetBytes = data.slice(offset, offset + length);
|
|
25
22
|
return isBytes(offsetBytes, length);
|
|
26
23
|
}
|
|
@@ -30,7 +27,6 @@ export function hasBytesAtOffset(data, offset, length) {
|
|
|
30
27
|
* @param b The byte array
|
|
31
28
|
* @param length The specified length
|
|
32
29
|
*/
|
|
33
|
-
|
|
34
30
|
export function assertBytes(b, length) {
|
|
35
31
|
if (!isBytes(b, length)) {
|
|
36
32
|
throw new TypeError(`Parameter is not valid Bytes of length: ${length} !== ${b.length}`);
|
|
@@ -43,7 +39,6 @@ export function assertBytes(b, length) {
|
|
|
43
39
|
* @param min Minimum size of the array
|
|
44
40
|
* @param max Maximum size of the array
|
|
45
41
|
*/
|
|
46
|
-
|
|
47
42
|
export function isFlexBytes(b, min, max) {
|
|
48
43
|
return b instanceof Uint8Array && b.length >= min && b.length <= max;
|
|
49
44
|
}
|
|
@@ -54,7 +49,6 @@ export function isFlexBytes(b, min, max) {
|
|
|
54
49
|
* @param min Minimum size of the array
|
|
55
50
|
* @param max Maximum size of the array
|
|
56
51
|
*/
|
|
57
|
-
|
|
58
52
|
export function assertFlexBytes(b, min, max) {
|
|
59
53
|
if (!isFlexBytes(b, min, max)) {
|
|
60
54
|
throw new TypeError(`Parameter is not valid FlexBytes of min: ${min}, max: ${max}, length: ${b.length}`);
|
|
@@ -67,10 +61,9 @@ export function assertFlexBytes(b, min, max) {
|
|
|
67
61
|
* @param offset The offset to start from
|
|
68
62
|
* @param length The length of data to be returned
|
|
69
63
|
*/
|
|
70
|
-
|
|
71
64
|
export function bytesAtOffset(data, offset, length) {
|
|
72
|
-
const offsetBytes = data.slice(offset, offset + length);
|
|
73
|
-
|
|
65
|
+
const offsetBytes = data.slice(offset, offset + length);
|
|
66
|
+
// We are returning strongly typed Bytes so we have to verify that length is really what we claim
|
|
74
67
|
assertBytes(offsetBytes, length);
|
|
75
68
|
return offsetBytes;
|
|
76
69
|
}
|
|
@@ -82,9 +75,10 @@ export function bytesAtOffset(data, offset, length) {
|
|
|
82
75
|
* @param _min The minimum size of the data
|
|
83
76
|
* @param _max The maximum size of the data
|
|
84
77
|
*/
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
_min,
|
|
78
|
+
export function flexBytesAtOffset(data, offset,
|
|
79
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
80
|
+
_min,
|
|
81
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
88
82
|
_max) {
|
|
89
83
|
return data.slice(offset);
|
|
90
84
|
}
|
|
@@ -94,7 +88,6 @@ _max) {
|
|
|
94
88
|
* @param a Byte array to compare
|
|
95
89
|
* @param b Byte array to compare
|
|
96
90
|
*/
|
|
97
|
-
|
|
98
91
|
export function bytesEqual(a, b) {
|
|
99
92
|
return a.length === b.length && a.every((value, index) => value === b[index]);
|
|
100
93
|
}
|
|
@@ -103,15 +96,13 @@ export function bytesEqual(a, b) {
|
|
|
103
96
|
*
|
|
104
97
|
* @param length The length of data to be returned
|
|
105
98
|
*/
|
|
106
|
-
|
|
107
99
|
export function makeBytes(length) {
|
|
108
100
|
return new Uint8Array(length);
|
|
109
101
|
}
|
|
110
102
|
export function wrapBytesWithHelpers(data) {
|
|
111
|
-
return {
|
|
112
|
-
bytes: () => data,
|
|
103
|
+
return Object.assign(data, {
|
|
113
104
|
text: () => new TextDecoder('utf-8').decode(data),
|
|
114
105
|
json: () => JSON.parse(new TextDecoder('utf-8').decode(data)),
|
|
115
106
|
hex: () => bytesToHex(data)
|
|
116
|
-
};
|
|
107
|
+
});
|
|
117
108
|
}
|