@ethersphere/bee-js 3.2.0 → 3.3.2-pre.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/dist/cjs/bee-debug.js +615 -0
- package/dist/cjs/bee.js +922 -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 +137 -0
- package/dist/cjs/chunk/soc.js +172 -0
- package/dist/cjs/chunk/span.js +29 -0
- package/dist/cjs/feed/index.js +184 -0
- package/dist/cjs/feed/json.js +41 -0
- package/dist/cjs/feed/topic.js +25 -0
- package/dist/cjs/feed/type.js +15 -0
- package/dist/cjs/index.js +35 -0
- package/dist/cjs/modules/bytes.js +74 -0
- package/dist/cjs/modules/bzz.js +131 -0
- package/dist/cjs/modules/chunk.js +58 -0
- package/dist/cjs/modules/debug/balance.js +77 -0
- package/dist/cjs/modules/debug/chequebook.js +167 -0
- package/dist/cjs/modules/debug/chunk.js +51 -0
- package/dist/cjs/modules/debug/connectivity.js +75 -0
- package/dist/cjs/modules/debug/settlements.js +45 -0
- package/dist/cjs/modules/debug/stamps.js +89 -0
- package/dist/cjs/modules/debug/states.js +47 -0
- package/dist/cjs/modules/debug/status.js +153 -0
- package/dist/cjs/modules/debug/tag.js +30 -0
- package/dist/cjs/modules/debug/transactions.js +81 -0
- package/dist/cjs/modules/feed.js +76 -0
- package/dist/cjs/modules/pinning.js +84 -0
- package/dist/cjs/modules/pss.js +55 -0
- package/dist/cjs/modules/soc.js +40 -0
- package/dist/cjs/modules/status.js +26 -0
- package/dist/cjs/modules/stewardship.js +41 -0
- package/dist/cjs/modules/tag.js +96 -0
- package/dist/cjs/package.json +8 -0
- package/dist/cjs/types/debug.js +9 -0
- package/dist/cjs/types/index.js +46 -0
- package/dist/cjs/types/ky-options.js +8 -0
- package/dist/cjs/types/ky-universal/common.js +8 -0
- package/dist/cjs/types/ky-universal/hooks.js +8 -0
- package/dist/cjs/types/ky-universal/retry.js +8 -0
- package/dist/cjs/utils/bytes.js +107 -0
- package/dist/cjs/utils/collection.browser.js +36 -0
- package/dist/cjs/utils/collection.js +70 -0
- package/dist/cjs/utils/collection.node.js +115 -0
- package/dist/cjs/utils/data.browser.js +78 -0
- package/dist/cjs/utils/data.js +60 -0
- package/dist/cjs/utils/error.js +50 -0
- package/dist/cjs/utils/eth.js +211 -0
- package/dist/cjs/utils/expose.js +44 -0
- package/dist/cjs/utils/file.js +49 -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 +166 -0
- package/dist/cjs/utils/merge.js +34 -0
- package/dist/cjs/utils/pss.js +18 -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 +327 -0
- package/dist/cjs/utils/uint64.js +29 -0
- package/dist/cjs/utils/url.js +56 -0
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.LICENSE.txt +12 -11
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/bee-debug.js +609 -0
- package/dist/mjs/bee.js +944 -0
- package/dist/mjs/chunk/bmt.js +56 -0
- package/dist/mjs/chunk/cac.js +52 -0
- package/dist/mjs/chunk/serialize.js +15 -0
- package/dist/mjs/chunk/signer.js +131 -0
- package/dist/mjs/chunk/soc.js +139 -0
- package/dist/mjs/chunk/span.js +28 -0
- package/dist/mjs/feed/index.js +145 -0
- package/dist/mjs/feed/json.js +27 -0
- package/dist/mjs/feed/topic.js +21 -0
- package/dist/mjs/feed/type.js +10 -0
- package/dist/mjs/index.js +7 -0
- package/dist/mjs/modules/bytes.js +59 -0
- package/dist/mjs/modules/bzz.js +122 -0
- package/dist/mjs/modules/chunk.js +45 -0
- package/dist/mjs/modules/debug/balance.js +57 -0
- package/dist/mjs/modules/debug/chequebook.js +150 -0
- package/dist/mjs/modules/debug/chunk.js +35 -0
- package/dist/mjs/modules/debug/connectivity.js +45 -0
- package/dist/mjs/modules/debug/settlements.js +29 -0
- package/dist/mjs/modules/debug/stamps.js +64 -0
- package/dist/mjs/modules/debug/states.js +31 -0
- package/dist/mjs/modules/debug/status.js +134 -0
- package/dist/mjs/modules/debug/tag.js +16 -0
- package/dist/mjs/modules/debug/transactions.js +63 -0
- package/dist/mjs/modules/feed.js +67 -0
- package/dist/mjs/modules/pinning.js +66 -0
- package/dist/mjs/modules/pss.js +40 -0
- package/dist/mjs/modules/soc.js +31 -0
- package/dist/mjs/modules/status.js +12 -0
- package/dist/mjs/modules/stewardship.js +24 -0
- package/dist/mjs/modules/tag.js +77 -0
- package/dist/mjs/package.json +8 -0
- package/dist/mjs/types/debug.js +7 -0
- package/dist/mjs/types/index.js +37 -0
- package/dist/mjs/types/ky-options.js +7 -0
- package/dist/mjs/types/ky-universal/common.js +7 -0
- package/dist/mjs/types/ky-universal/hooks.js +7 -0
- package/dist/mjs/types/ky-universal/retry.js +7 -0
- package/dist/mjs/utils/bytes.js +101 -0
- package/dist/mjs/utils/collection.browser.js +19 -0
- package/dist/mjs/utils/collection.js +64 -0
- package/dist/mjs/utils/collection.node.js +74 -0
- package/dist/mjs/utils/data.browser.js +73 -0
- package/dist/mjs/utils/data.js +43 -0
- package/dist/mjs/utils/error.js +56 -0
- package/dist/mjs/utils/eth.js +199 -0
- package/dist/mjs/utils/expose.js +9 -0
- package/dist/mjs/utils/file.js +36 -0
- package/dist/mjs/utils/hash.js +17 -0
- package/dist/mjs/utils/headers.js +58 -0
- package/dist/mjs/utils/hex.js +154 -0
- package/dist/mjs/utils/http.js +155 -0
- package/dist/mjs/utils/merge.js +36 -0
- package/dist/mjs/utils/pss.js +16 -0
- package/dist/mjs/utils/stamps.js +17 -0
- package/dist/mjs/utils/stream.js +156 -0
- package/dist/mjs/utils/tar.js +21 -0
- package/dist/mjs/utils/type.js +336 -0
- package/dist/mjs/utils/uint64.js +23 -0
- package/dist/mjs/utils/url.js +57 -0
- package/dist/{src → types}/bee-debug.d.ts +47 -1
- package/dist/{src → types}/bee.d.ts +0 -0
- package/dist/{src → types}/chunk/bmt.d.ts +0 -0
- package/dist/{src → types}/chunk/cac.d.ts +0 -0
- package/dist/{src → types}/chunk/serialize.d.ts +0 -0
- package/dist/{src → types}/chunk/signer.d.ts +0 -0
- package/dist/{src → types}/chunk/soc.d.ts +0 -0
- package/dist/{src → types}/chunk/span.d.ts +0 -0
- package/dist/{src → types}/feed/index.d.ts +0 -0
- package/dist/{src → types}/feed/json.d.ts +0 -0
- package/dist/{src → types}/feed/topic.d.ts +0 -0
- package/dist/{src → types}/feed/type.d.ts +0 -0
- package/dist/{src → types}/index.d.ts +0 -0
- package/dist/{src → types}/modules/bytes.d.ts +0 -0
- package/dist/{src → types}/modules/bzz.d.ts +0 -0
- package/dist/{src → types}/modules/chunk.d.ts +0 -0
- package/dist/{src → types}/modules/debug/balance.d.ts +0 -0
- package/dist/{src → types}/modules/debug/chequebook.d.ts +0 -0
- package/dist/{src → types}/modules/debug/chunk.d.ts +0 -0
- package/dist/{src → types}/modules/debug/connectivity.d.ts +0 -0
- package/dist/{src → types}/modules/debug/settlements.d.ts +0 -0
- package/dist/{src → types}/modules/debug/stamps.d.ts +0 -0
- package/dist/{src → types}/modules/debug/states.d.ts +0 -0
- package/dist/types/modules/debug/status.d.ts +72 -0
- package/dist/{src → types}/modules/debug/tag.d.ts +0 -0
- package/dist/{src → types}/modules/debug/transactions.d.ts +0 -0
- package/dist/{src → types}/modules/feed.d.ts +0 -0
- package/dist/{src → types}/modules/pinning.d.ts +0 -0
- package/dist/{src → types}/modules/pss.d.ts +0 -0
- package/dist/{src → types}/modules/soc.d.ts +0 -0
- package/dist/{src → types}/modules/status.d.ts +0 -0
- package/dist/{src → types}/modules/stewardship.d.ts +0 -0
- package/dist/{src → types}/modules/tag.d.ts +0 -0
- package/dist/{src → types}/types/debug.d.ts +8 -0
- package/dist/{src → types}/types/index.d.ts +3 -2
- package/dist/types/types/ky-options.d.ts +221 -0
- package/dist/types/types/ky-universal/common.d.ts +13 -0
- package/dist/types/types/ky-universal/hooks.d.ts +92 -0
- package/dist/types/types/ky-universal/retry.d.ts +38 -0
- package/dist/{src → types}/utils/bytes.d.ts +0 -0
- package/dist/types/utils/collection.browser.d.ts +15 -0
- package/dist/{src → types}/utils/collection.d.ts +0 -14
- package/dist/types/utils/collection.node.d.ts +15 -0
- package/dist/{src → types}/utils/data.browser.d.ts +0 -0
- package/dist/{src → types}/utils/data.d.ts +0 -0
- package/dist/{src → types}/utils/error.d.ts +0 -0
- package/dist/{src → types}/utils/eth.d.ts +0 -0
- package/dist/{src → types}/utils/expose.d.ts +2 -1
- package/dist/{src → types}/utils/file.d.ts +0 -0
- package/dist/{src → types}/utils/hash.d.ts +0 -0
- package/dist/{src → types}/utils/headers.d.ts +0 -0
- package/dist/{src → types}/utils/hex.d.ts +0 -0
- package/dist/{src → types}/utils/http.d.ts +0 -0
- package/dist/{src → types}/utils/merge.d.ts +0 -0
- package/dist/{src → types}/utils/pss.d.ts +0 -0
- package/dist/{src → types}/utils/stamps.d.ts +0 -0
- package/dist/{src → types}/utils/stream.d.ts +11 -8
- package/dist/{src → types}/utils/tar.d.ts +0 -0
- package/dist/{src → types}/utils/type.d.ts +0 -0
- package/dist/{src → types}/utils/uint64.d.ts +0 -0
- package/dist/{src → types}/utils/url.d.ts +0 -0
- package/package.json +55 -36
- package/dist/index.min.js +0 -3
- package/dist/index.min.js.LICENSE.txt +0 -50
- package/dist/index.min.js.map +0 -1
- package/dist/src/modules/debug/status.d.ts +0 -24
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { http } from "../../utils/http.js";
|
|
2
|
+
import getMajorSemver from 'semver/functions/major.js'; // Following lines bellow are automatically updated with GitHub Action when Bee version is updated
|
|
3
|
+
// so if you are changing anything about them change the `update_bee` action accordingly!
|
|
4
|
+
|
|
5
|
+
export const SUPPORTED_BEE_VERSION_EXACT = '1.4.3-1213e063';
|
|
6
|
+
export const SUPPORTED_API_VERSION = '2.0.0';
|
|
7
|
+
export const SUPPORTED_DEBUG_API_VERSION = '1.2.1';
|
|
8
|
+
export const SUPPORTED_BEE_VERSION = SUPPORTED_BEE_VERSION_EXACT.substring(0, SUPPORTED_BEE_VERSION_EXACT.indexOf('-'));
|
|
9
|
+
const NODE_INFO_URL = 'node';
|
|
10
|
+
const HEALTH_URL = 'health';
|
|
11
|
+
/**
|
|
12
|
+
* Get health of node
|
|
13
|
+
*
|
|
14
|
+
* @param ky Ky debug instance
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export async function getHealth(ky) {
|
|
18
|
+
const response = await http(ky, {
|
|
19
|
+
method: 'get',
|
|
20
|
+
path: HEALTH_URL,
|
|
21
|
+
responseType: 'json'
|
|
22
|
+
});
|
|
23
|
+
return response.data;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Get information about Bee node
|
|
27
|
+
*
|
|
28
|
+
* @param ky Ky debug instance
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
export async function getNodeInfo(ky) {
|
|
32
|
+
const response = await http(ky, {
|
|
33
|
+
method: 'get',
|
|
34
|
+
path: NODE_INFO_URL,
|
|
35
|
+
responseType: 'json'
|
|
36
|
+
});
|
|
37
|
+
return response.data;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Connects to a node and checks if it is a supported Bee version by the bee-js
|
|
41
|
+
*
|
|
42
|
+
* @param ky Ky debug instance
|
|
43
|
+
*
|
|
44
|
+
* @returns true if the Bee node version is supported
|
|
45
|
+
* @deprecated Use `isSupportedExactVersion` instead
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
export async function isSupportedVersion(ky) {
|
|
49
|
+
return isSupportedExactVersion(ky);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Connects to a node and checks if its version matches with the one that bee-js supports.
|
|
53
|
+
*
|
|
54
|
+
* Be aware that this is the most strict version check and most probably
|
|
55
|
+
* you will want to use more relaxed API-versions based checks like
|
|
56
|
+
* `isSupportedApiVersion`, `isSupportedMainApiVersion` or `isSupportedDebugApiVersion`
|
|
57
|
+
* based on your use-case.
|
|
58
|
+
*
|
|
59
|
+
* @param ky
|
|
60
|
+
*/
|
|
61
|
+
|
|
62
|
+
export async function isSupportedExactVersion(ky) {
|
|
63
|
+
const {
|
|
64
|
+
version
|
|
65
|
+
} = await getHealth(ky);
|
|
66
|
+
return version === SUPPORTED_BEE_VERSION_EXACT;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Connects to a node and checks if its main's API version matches with the one that bee-js supports.
|
|
70
|
+
*
|
|
71
|
+
* This is useful if you are not using `BeeDebug` class (for anything else then this check)
|
|
72
|
+
* and want to make sure about compatibility.
|
|
73
|
+
*
|
|
74
|
+
* @param ky
|
|
75
|
+
*/
|
|
76
|
+
|
|
77
|
+
export async function isSupportedMainApiVersion(ky) {
|
|
78
|
+
const {
|
|
79
|
+
apiVersion
|
|
80
|
+
} = await getHealth(ky);
|
|
81
|
+
return getMajorSemver(apiVersion) === getMajorSemver(SUPPORTED_API_VERSION);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Connects to a node and checks if its Debug API version matches with the one that bee-js supports.
|
|
85
|
+
*
|
|
86
|
+
* This is useful if you are not using `Bee` class in your application and want to make sure
|
|
87
|
+
* about compatibility.
|
|
88
|
+
*
|
|
89
|
+
* @param ky
|
|
90
|
+
*/
|
|
91
|
+
|
|
92
|
+
export async function isSupportedDebugApiVersion(ky) {
|
|
93
|
+
const {
|
|
94
|
+
debugApiVersion
|
|
95
|
+
} = await getHealth(ky);
|
|
96
|
+
return getMajorSemver(debugApiVersion) === getMajorSemver(SUPPORTED_DEBUG_API_VERSION);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Connects to a node and checks if its Main and Debug API versions matches with the one that bee-js supports.
|
|
100
|
+
*
|
|
101
|
+
* This should be the main way how to check compatibility for your app and Bee node.
|
|
102
|
+
*
|
|
103
|
+
* @param ky
|
|
104
|
+
*/
|
|
105
|
+
|
|
106
|
+
export async function isSupportedApiVersion(ky) {
|
|
107
|
+
const {
|
|
108
|
+
apiVersion,
|
|
109
|
+
debugApiVersion
|
|
110
|
+
} = await getHealth(ky);
|
|
111
|
+
return getMajorSemver(apiVersion) === getMajorSemver(SUPPORTED_API_VERSION) && getMajorSemver(debugApiVersion) === getMajorSemver(SUPPORTED_DEBUG_API_VERSION);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Returns object with all versions specified by the connected Bee node (properties prefixed with `bee*`)
|
|
115
|
+
* and versions that bee-js supports (properties prefixed with `supported*`).
|
|
116
|
+
*
|
|
117
|
+
* @param ky
|
|
118
|
+
*/
|
|
119
|
+
|
|
120
|
+
export async function getVersions(ky) {
|
|
121
|
+
const {
|
|
122
|
+
version,
|
|
123
|
+
apiVersion,
|
|
124
|
+
debugApiVersion
|
|
125
|
+
} = await getHealth(ky);
|
|
126
|
+
return {
|
|
127
|
+
supportedBeeVersion: SUPPORTED_BEE_VERSION_EXACT,
|
|
128
|
+
supportedBeeApiVersion: SUPPORTED_API_VERSION,
|
|
129
|
+
supportedBeeDebugApiVersion: SUPPORTED_DEBUG_API_VERSION,
|
|
130
|
+
beeVersion: version,
|
|
131
|
+
beeApiVersion: apiVersion,
|
|
132
|
+
beeDebugApiVersion: debugApiVersion
|
|
133
|
+
};
|
|
134
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { http } from "../../utils/http.js";
|
|
2
|
+
const endpoint = 'tags';
|
|
3
|
+
/**
|
|
4
|
+
* Retrieve tag with extended information from Bee node
|
|
5
|
+
*
|
|
6
|
+
* @param ky Ky debug instance
|
|
7
|
+
* @param uid UID of tag to be retrieved
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export async function retrieveExtendedTag(ky, uid) {
|
|
11
|
+
const response = await http(ky, {
|
|
12
|
+
path: `${endpoint}/${uid}`,
|
|
13
|
+
responseType: 'json'
|
|
14
|
+
});
|
|
15
|
+
return response.data;
|
|
16
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
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
|
+
|
|
9
|
+
export async function getAllTransactions(ky) {
|
|
10
|
+
const response = await http(ky, {
|
|
11
|
+
path: transactionsEndpoint,
|
|
12
|
+
responseType: 'json'
|
|
13
|
+
});
|
|
14
|
+
return response.data.pendingTransactions;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Get information for specific pending transactions
|
|
18
|
+
*
|
|
19
|
+
* @param ky Debug Ky instance
|
|
20
|
+
* @param transactionHash Hash of the transaction
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
export async function getTransaction(ky, transactionHash) {
|
|
24
|
+
const response = await http(ky, {
|
|
25
|
+
path: `${transactionsEndpoint}/${transactionHash}`,
|
|
26
|
+
responseType: 'json'
|
|
27
|
+
});
|
|
28
|
+
return response.data;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Rebroadcast existing transaction
|
|
32
|
+
*
|
|
33
|
+
* @param ky Debug Ky instance
|
|
34
|
+
* @param transactionHash Hash of the transaction
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
export async function rebroadcastTransaction(ky, transactionHash) {
|
|
38
|
+
const response = await http(ky, {
|
|
39
|
+
method: 'post',
|
|
40
|
+
path: `${transactionsEndpoint}/${transactionHash}`,
|
|
41
|
+
responseType: 'json'
|
|
42
|
+
});
|
|
43
|
+
return response.data.transactionHash;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Cancel existing transaction
|
|
47
|
+
*
|
|
48
|
+
* @param ky Debug Ky instance
|
|
49
|
+
* @param transactionHash Hash of the transaction
|
|
50
|
+
* @param gasPrice Optional gas price
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
export async function cancelTransaction(ky, transactionHash, gasPrice) {
|
|
54
|
+
const response = await http(ky, {
|
|
55
|
+
method: 'delete',
|
|
56
|
+
headers: {
|
|
57
|
+
'gas-price': gasPrice
|
|
58
|
+
},
|
|
59
|
+
path: `${transactionsEndpoint}/${transactionHash}`,
|
|
60
|
+
responseType: 'json'
|
|
61
|
+
});
|
|
62
|
+
return response.data.transactionHash;
|
|
63
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { filterHeaders, http } from "../utils/http.js";
|
|
2
|
+
import { extractUploadHeaders } from "../utils/headers.js";
|
|
3
|
+
import { BeeError } from "../utils/error.js";
|
|
4
|
+
const feedEndpoint = 'feeds';
|
|
5
|
+
/**
|
|
6
|
+
* Create an initial feed root manifest
|
|
7
|
+
*
|
|
8
|
+
* @param ky Ky instance
|
|
9
|
+
* @param owner Owner's ethereum address in hex
|
|
10
|
+
* @param topic Topic in hex
|
|
11
|
+
* @param postageBatchId Postage BatchId to be used to create the Feed Manifest
|
|
12
|
+
* @param options Additional options, like type (default: 'sequence')
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export async function createFeedManifest(ky, owner, topic, postageBatchId, options) {
|
|
16
|
+
const response = await http(ky, {
|
|
17
|
+
method: 'post',
|
|
18
|
+
responseType: 'json',
|
|
19
|
+
path: `${feedEndpoint}/${owner}/${topic}`,
|
|
20
|
+
searchParams: filterHeaders(options),
|
|
21
|
+
headers: extractUploadHeaders(postageBatchId)
|
|
22
|
+
});
|
|
23
|
+
return response.data.reference;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function readFeedUpdateHeaders(headers) {
|
|
27
|
+
const feedIndex = headers.get('swarm-feed-index');
|
|
28
|
+
const feedIndexNext = headers.get('swarm-feed-index-next');
|
|
29
|
+
|
|
30
|
+
if (!feedIndex) {
|
|
31
|
+
throw new BeeError('Response did not contain expected swarm-feed-index!');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (!feedIndexNext) {
|
|
35
|
+
throw new BeeError('Response did not contain expected swarm-feed-index-next!');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
feedIndex,
|
|
40
|
+
feedIndexNext
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Find and retrieve feed update
|
|
45
|
+
*
|
|
46
|
+
* The feed consists of updates. This endpoint looks up an
|
|
47
|
+
* update that matches the provided parameters and returns
|
|
48
|
+
* the reference it contains along with its index and the
|
|
49
|
+
* index of the subsequent update.
|
|
50
|
+
*
|
|
51
|
+
* @param ky Ky instance
|
|
52
|
+
* @param owner Owner's ethereum address in hex
|
|
53
|
+
* @param topic Topic in hex
|
|
54
|
+
* @param options Additional options, like index, at, type
|
|
55
|
+
*/
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
export async function fetchFeedUpdate(ky, owner, topic, options) {
|
|
59
|
+
const response = await http(ky, {
|
|
60
|
+
responseType: 'json',
|
|
61
|
+
path: `${feedEndpoint}/${owner}/${topic}`,
|
|
62
|
+
searchParams: filterHeaders(options)
|
|
63
|
+
});
|
|
64
|
+
return { ...response.data,
|
|
65
|
+
...readFeedUpdateHeaders(response.headers)
|
|
66
|
+
};
|
|
67
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { http } from "../utils/http.js";
|
|
2
|
+
const PINNING_ENDPOINT = 'pins';
|
|
3
|
+
/**
|
|
4
|
+
* Pin data with given reference
|
|
5
|
+
*
|
|
6
|
+
* @param ky Ky instance for given Bee class instance
|
|
7
|
+
* @param reference Bee data reference
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export async function pin(ky, reference) {
|
|
11
|
+
await http(ky, {
|
|
12
|
+
method: 'post',
|
|
13
|
+
responseType: 'json',
|
|
14
|
+
path: `${PINNING_ENDPOINT}/${reference}`
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Unpin data with given reference
|
|
19
|
+
*
|
|
20
|
+
* @param ky Ky instance for given Bee class instance
|
|
21
|
+
* @param reference Bee data reference
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
export async function unpin(ky, reference) {
|
|
25
|
+
await http(ky, {
|
|
26
|
+
method: 'delete',
|
|
27
|
+
responseType: 'json',
|
|
28
|
+
path: `${PINNING_ENDPOINT}/${reference}`
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Get pin status for specific address.
|
|
33
|
+
*
|
|
34
|
+
* @param ky Ky instance
|
|
35
|
+
* @param reference
|
|
36
|
+
* @throws Error if given address is not pinned
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
export async function getPin(ky, reference) {
|
|
40
|
+
const response = await http(ky, {
|
|
41
|
+
method: 'get',
|
|
42
|
+
responseType: 'json',
|
|
43
|
+
path: `${PINNING_ENDPOINT}/${reference}`
|
|
44
|
+
});
|
|
45
|
+
return response.data;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Get list of all pins
|
|
49
|
+
*
|
|
50
|
+
* @param ky Ky instance
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
export async function getAllPins(ky) {
|
|
54
|
+
const response = await http(ky, {
|
|
55
|
+
method: 'get',
|
|
56
|
+
responseType: 'json',
|
|
57
|
+
path: `${PINNING_ENDPOINT}`
|
|
58
|
+
});
|
|
59
|
+
const result = response.data.references;
|
|
60
|
+
|
|
61
|
+
if (result === null) {
|
|
62
|
+
return [];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import WebSocket from 'isomorphic-ws';
|
|
2
|
+
import { prepareData } from "../utils/data.js";
|
|
3
|
+
import { http } from "../utils/http.js";
|
|
4
|
+
import { extractUploadHeaders } from "../utils/headers.js";
|
|
5
|
+
const endpoint = 'pss';
|
|
6
|
+
/**
|
|
7
|
+
* Send to recipient or target with Postal Service for Swarm
|
|
8
|
+
*
|
|
9
|
+
* @param ky Ky instance for given Bee class instance
|
|
10
|
+
* @param topic Topic name
|
|
11
|
+
* @param target Target message address prefix
|
|
12
|
+
* @param data
|
|
13
|
+
* @param postageBatchId Postage BatchId that will be assigned to sent message
|
|
14
|
+
* @param recipient Recipient public key
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
export async function send(ky, topic, target, data, postageBatchId, recipient) {
|
|
19
|
+
await http(ky, {
|
|
20
|
+
method: 'post',
|
|
21
|
+
path: `${endpoint}/send/${topic}/${target}`,
|
|
22
|
+
body: await prepareData(data),
|
|
23
|
+
responseType: 'json',
|
|
24
|
+
searchParams: {
|
|
25
|
+
recipient
|
|
26
|
+
},
|
|
27
|
+
headers: extractUploadHeaders(postageBatchId)
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Subscribe for messages on the given topic
|
|
32
|
+
*
|
|
33
|
+
* @param url Bee node URL
|
|
34
|
+
* @param topic Topic name
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
export function subscribe(url, topic) {
|
|
38
|
+
const wsUrl = url.replace(/^http/i, 'ws');
|
|
39
|
+
return new WebSocket(`${wsUrl}/${endpoint}/subscribe/${topic}`);
|
|
40
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { extractUploadHeaders } from "../utils/headers.js";
|
|
2
|
+
import { http } from "../utils/http.js";
|
|
3
|
+
const socEndpoint = 'soc';
|
|
4
|
+
/**
|
|
5
|
+
* Upload single owner chunk (SOC) to a Bee node
|
|
6
|
+
*
|
|
7
|
+
* @param ky Ky instance
|
|
8
|
+
* @param owner Owner's ethereum address in hex
|
|
9
|
+
* @param identifier Arbitrary identifier in hex
|
|
10
|
+
* @param signature Signature in hex
|
|
11
|
+
* @param data Content addressed chunk data to be uploaded
|
|
12
|
+
* @param postageBatchId Postage BatchId that will be assigned to uploaded data
|
|
13
|
+
* @param options Additional options like tag, encryption, pinning
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
export async function upload(ky, owner, identifier, signature, data, postageBatchId, options) {
|
|
17
|
+
const response = await http(ky, {
|
|
18
|
+
method: 'post',
|
|
19
|
+
path: `${socEndpoint}/${owner}/${identifier}`,
|
|
20
|
+
body: data,
|
|
21
|
+
headers: {
|
|
22
|
+
'content-type': 'application/octet-stream',
|
|
23
|
+
...extractUploadHeaders(postageBatchId, options)
|
|
24
|
+
},
|
|
25
|
+
responseType: 'json',
|
|
26
|
+
searchParams: {
|
|
27
|
+
sig: signature
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
return response.data.reference;
|
|
31
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { http } from "../utils/http.js";
|
|
2
|
+
/**
|
|
3
|
+
* Ping the base bee URL. If connection was not successful throw error
|
|
4
|
+
*
|
|
5
|
+
* @param ky Ky instance for given Bee class instance
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export async function checkConnection(ky) {
|
|
9
|
+
await http(ky, {
|
|
10
|
+
path: ''
|
|
11
|
+
});
|
|
12
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
|
|
11
|
+
export async function reupload(ky, reference) {
|
|
12
|
+
await http(ky, {
|
|
13
|
+
method: 'put',
|
|
14
|
+
path: `${stewardshipEndpoint}/${reference}`
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
export async function isRetrievable(ky, reference) {
|
|
18
|
+
const response = await http(ky, {
|
|
19
|
+
method: 'get',
|
|
20
|
+
responseType: 'json',
|
|
21
|
+
path: `${stewardshipEndpoint}/${reference}`
|
|
22
|
+
});
|
|
23
|
+
return response.data.isRetrievable;
|
|
24
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
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
|
+
|
|
9
|
+
export async function createTag(ky) {
|
|
10
|
+
const response = await http(ky, {
|
|
11
|
+
method: 'post',
|
|
12
|
+
path: endpoint,
|
|
13
|
+
responseType: 'json'
|
|
14
|
+
});
|
|
15
|
+
return response.data;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Retrieve tag information from Bee node
|
|
19
|
+
*
|
|
20
|
+
* @param url Bee tag URL
|
|
21
|
+
* @param uid UID of tag to be retrieved
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
export async function retrieveTag(ky, uid) {
|
|
25
|
+
const response = await http(ky, {
|
|
26
|
+
path: `${endpoint}/${uid}`,
|
|
27
|
+
responseType: 'json'
|
|
28
|
+
});
|
|
29
|
+
return response.data;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Get limited listing of all tags.
|
|
33
|
+
*
|
|
34
|
+
* @param url
|
|
35
|
+
* @param offset
|
|
36
|
+
* @param limit
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
export async function getAllTags(ky, offset, limit) {
|
|
40
|
+
const response = await http(ky, {
|
|
41
|
+
path: `${endpoint}`,
|
|
42
|
+
searchParams: {
|
|
43
|
+
offset,
|
|
44
|
+
limit
|
|
45
|
+
},
|
|
46
|
+
responseType: 'json'
|
|
47
|
+
});
|
|
48
|
+
return response.data.tags;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Removes tag from the Bee node.
|
|
52
|
+
* @param url
|
|
53
|
+
* @param uid
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
export async function deleteTag(ky, uid) {
|
|
57
|
+
await http(ky, {
|
|
58
|
+
method: 'delete',
|
|
59
|
+
path: `${endpoint}/${uid}`
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Updates tag
|
|
64
|
+
* @param url
|
|
65
|
+
* @param uid
|
|
66
|
+
* @param reference
|
|
67
|
+
*/
|
|
68
|
+
|
|
69
|
+
export async function updateTag(ky, uid, reference) {
|
|
70
|
+
await http(ky, {
|
|
71
|
+
method: 'patch',
|
|
72
|
+
path: `${endpoint}/${uid}`,
|
|
73
|
+
json: {
|
|
74
|
+
reference
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export * from "./debug.js";
|
|
2
|
+
export const SPAN_SIZE = 8;
|
|
3
|
+
export const SECTION_SIZE = 32;
|
|
4
|
+
export const BRANCHES = 128;
|
|
5
|
+
export const CHUNK_SIZE = SECTION_SIZE * BRANCHES;
|
|
6
|
+
export const ADDRESS_HEX_LENGTH = 64;
|
|
7
|
+
export const PSS_TARGET_HEX_LENGTH_MAX = 6;
|
|
8
|
+
export const PUBKEY_HEX_LENGTH = 66;
|
|
9
|
+
export const BATCH_ID_HEX_LENGTH = 64;
|
|
10
|
+
export const REFERENCE_HEX_LENGTH = 64;
|
|
11
|
+
export const ENCRYPTED_REFERENCE_HEX_LENGTH = 128;
|
|
12
|
+
export const REFERENCE_BYTES_LENGTH = 32;
|
|
13
|
+
export const ENCRYPTED_REFERENCE_BYTES_LENGTH = 64;
|
|
14
|
+
/**
|
|
15
|
+
* Minimal depth that can be used for creation of postage batch
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
export const STAMPS_DEPTH_MIN = 17;
|
|
19
|
+
/**
|
|
20
|
+
* Maximal depth that can be used for creation of postage batch
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
export const STAMPS_DEPTH_MAX = 255;
|
|
24
|
+
export const TAGS_LIMIT_MIN = 1;
|
|
25
|
+
export const TAGS_LIMIT_MAX = 1000;
|
|
26
|
+
/*********************************************************
|
|
27
|
+
* Writers and Readers interfaces
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
export const TOPIC_BYTES_LENGTH = 32;
|
|
31
|
+
export const TOPIC_HEX_LENGTH = 64;
|
|
32
|
+
/*********************************************************
|
|
33
|
+
* Ethereum compatible signing interfaces and definitions
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
export const SIGNATURE_HEX_LENGTH = 130;
|
|
37
|
+
export const SIGNATURE_BYTES_LENGTH = 65;
|