@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.
Files changed (193) hide show
  1. package/dist/cjs/bee-debug.js +615 -0
  2. package/dist/cjs/bee.js +922 -0
  3. package/dist/cjs/chunk/bmt.js +55 -0
  4. package/dist/cjs/chunk/cac.js +56 -0
  5. package/dist/cjs/chunk/serialize.js +19 -0
  6. package/dist/cjs/chunk/signer.js +137 -0
  7. package/dist/cjs/chunk/soc.js +172 -0
  8. package/dist/cjs/chunk/span.js +29 -0
  9. package/dist/cjs/feed/index.js +184 -0
  10. package/dist/cjs/feed/json.js +41 -0
  11. package/dist/cjs/feed/topic.js +25 -0
  12. package/dist/cjs/feed/type.js +15 -0
  13. package/dist/cjs/index.js +35 -0
  14. package/dist/cjs/modules/bytes.js +74 -0
  15. package/dist/cjs/modules/bzz.js +131 -0
  16. package/dist/cjs/modules/chunk.js +58 -0
  17. package/dist/cjs/modules/debug/balance.js +77 -0
  18. package/dist/cjs/modules/debug/chequebook.js +167 -0
  19. package/dist/cjs/modules/debug/chunk.js +51 -0
  20. package/dist/cjs/modules/debug/connectivity.js +75 -0
  21. package/dist/cjs/modules/debug/settlements.js +45 -0
  22. package/dist/cjs/modules/debug/stamps.js +89 -0
  23. package/dist/cjs/modules/debug/states.js +47 -0
  24. package/dist/cjs/modules/debug/status.js +153 -0
  25. package/dist/cjs/modules/debug/tag.js +30 -0
  26. package/dist/cjs/modules/debug/transactions.js +81 -0
  27. package/dist/cjs/modules/feed.js +76 -0
  28. package/dist/cjs/modules/pinning.js +84 -0
  29. package/dist/cjs/modules/pss.js +55 -0
  30. package/dist/cjs/modules/soc.js +40 -0
  31. package/dist/cjs/modules/status.js +26 -0
  32. package/dist/cjs/modules/stewardship.js +41 -0
  33. package/dist/cjs/modules/tag.js +96 -0
  34. package/dist/cjs/package.json +8 -0
  35. package/dist/cjs/types/debug.js +9 -0
  36. package/dist/cjs/types/index.js +46 -0
  37. package/dist/cjs/types/ky-options.js +8 -0
  38. package/dist/cjs/types/ky-universal/common.js +8 -0
  39. package/dist/cjs/types/ky-universal/hooks.js +8 -0
  40. package/dist/cjs/types/ky-universal/retry.js +8 -0
  41. package/dist/cjs/utils/bytes.js +107 -0
  42. package/dist/cjs/utils/collection.browser.js +36 -0
  43. package/dist/cjs/utils/collection.js +70 -0
  44. package/dist/cjs/utils/collection.node.js +115 -0
  45. package/dist/cjs/utils/data.browser.js +78 -0
  46. package/dist/cjs/utils/data.js +60 -0
  47. package/dist/cjs/utils/error.js +50 -0
  48. package/dist/cjs/utils/eth.js +211 -0
  49. package/dist/cjs/utils/expose.js +44 -0
  50. package/dist/cjs/utils/file.js +49 -0
  51. package/dist/cjs/utils/hash.js +21 -0
  52. package/dist/cjs/utils/headers.js +59 -0
  53. package/dist/cjs/utils/hex.js +150 -0
  54. package/dist/cjs/utils/http.js +166 -0
  55. package/dist/cjs/utils/merge.js +34 -0
  56. package/dist/cjs/utils/pss.js +18 -0
  57. package/dist/cjs/utils/stamps.js +17 -0
  58. package/dist/cjs/utils/stream.js +146 -0
  59. package/dist/cjs/utils/tar.js +25 -0
  60. package/dist/cjs/utils/type.js +327 -0
  61. package/dist/cjs/utils/uint64.js +29 -0
  62. package/dist/cjs/utils/url.js +56 -0
  63. package/dist/index.browser.min.js +1 -1
  64. package/dist/index.browser.min.js.LICENSE.txt +12 -11
  65. package/dist/index.browser.min.js.map +1 -1
  66. package/dist/mjs/bee-debug.js +609 -0
  67. package/dist/mjs/bee.js +944 -0
  68. package/dist/mjs/chunk/bmt.js +56 -0
  69. package/dist/mjs/chunk/cac.js +52 -0
  70. package/dist/mjs/chunk/serialize.js +15 -0
  71. package/dist/mjs/chunk/signer.js +131 -0
  72. package/dist/mjs/chunk/soc.js +139 -0
  73. package/dist/mjs/chunk/span.js +28 -0
  74. package/dist/mjs/feed/index.js +145 -0
  75. package/dist/mjs/feed/json.js +27 -0
  76. package/dist/mjs/feed/topic.js +21 -0
  77. package/dist/mjs/feed/type.js +10 -0
  78. package/dist/mjs/index.js +7 -0
  79. package/dist/mjs/modules/bytes.js +59 -0
  80. package/dist/mjs/modules/bzz.js +122 -0
  81. package/dist/mjs/modules/chunk.js +45 -0
  82. package/dist/mjs/modules/debug/balance.js +57 -0
  83. package/dist/mjs/modules/debug/chequebook.js +150 -0
  84. package/dist/mjs/modules/debug/chunk.js +35 -0
  85. package/dist/mjs/modules/debug/connectivity.js +45 -0
  86. package/dist/mjs/modules/debug/settlements.js +29 -0
  87. package/dist/mjs/modules/debug/stamps.js +64 -0
  88. package/dist/mjs/modules/debug/states.js +31 -0
  89. package/dist/mjs/modules/debug/status.js +134 -0
  90. package/dist/mjs/modules/debug/tag.js +16 -0
  91. package/dist/mjs/modules/debug/transactions.js +63 -0
  92. package/dist/mjs/modules/feed.js +67 -0
  93. package/dist/mjs/modules/pinning.js +66 -0
  94. package/dist/mjs/modules/pss.js +40 -0
  95. package/dist/mjs/modules/soc.js +31 -0
  96. package/dist/mjs/modules/status.js +12 -0
  97. package/dist/mjs/modules/stewardship.js +24 -0
  98. package/dist/mjs/modules/tag.js +77 -0
  99. package/dist/mjs/package.json +8 -0
  100. package/dist/mjs/types/debug.js +7 -0
  101. package/dist/mjs/types/index.js +37 -0
  102. package/dist/mjs/types/ky-options.js +7 -0
  103. package/dist/mjs/types/ky-universal/common.js +7 -0
  104. package/dist/mjs/types/ky-universal/hooks.js +7 -0
  105. package/dist/mjs/types/ky-universal/retry.js +7 -0
  106. package/dist/mjs/utils/bytes.js +101 -0
  107. package/dist/mjs/utils/collection.browser.js +19 -0
  108. package/dist/mjs/utils/collection.js +64 -0
  109. package/dist/mjs/utils/collection.node.js +74 -0
  110. package/dist/mjs/utils/data.browser.js +73 -0
  111. package/dist/mjs/utils/data.js +43 -0
  112. package/dist/mjs/utils/error.js +56 -0
  113. package/dist/mjs/utils/eth.js +199 -0
  114. package/dist/mjs/utils/expose.js +9 -0
  115. package/dist/mjs/utils/file.js +36 -0
  116. package/dist/mjs/utils/hash.js +17 -0
  117. package/dist/mjs/utils/headers.js +58 -0
  118. package/dist/mjs/utils/hex.js +154 -0
  119. package/dist/mjs/utils/http.js +155 -0
  120. package/dist/mjs/utils/merge.js +36 -0
  121. package/dist/mjs/utils/pss.js +16 -0
  122. package/dist/mjs/utils/stamps.js +17 -0
  123. package/dist/mjs/utils/stream.js +156 -0
  124. package/dist/mjs/utils/tar.js +21 -0
  125. package/dist/mjs/utils/type.js +336 -0
  126. package/dist/mjs/utils/uint64.js +23 -0
  127. package/dist/mjs/utils/url.js +57 -0
  128. package/dist/{src → types}/bee-debug.d.ts +47 -1
  129. package/dist/{src → types}/bee.d.ts +0 -0
  130. package/dist/{src → types}/chunk/bmt.d.ts +0 -0
  131. package/dist/{src → types}/chunk/cac.d.ts +0 -0
  132. package/dist/{src → types}/chunk/serialize.d.ts +0 -0
  133. package/dist/{src → types}/chunk/signer.d.ts +0 -0
  134. package/dist/{src → types}/chunk/soc.d.ts +0 -0
  135. package/dist/{src → types}/chunk/span.d.ts +0 -0
  136. package/dist/{src → types}/feed/index.d.ts +0 -0
  137. package/dist/{src → types}/feed/json.d.ts +0 -0
  138. package/dist/{src → types}/feed/topic.d.ts +0 -0
  139. package/dist/{src → types}/feed/type.d.ts +0 -0
  140. package/dist/{src → types}/index.d.ts +0 -0
  141. package/dist/{src → types}/modules/bytes.d.ts +0 -0
  142. package/dist/{src → types}/modules/bzz.d.ts +0 -0
  143. package/dist/{src → types}/modules/chunk.d.ts +0 -0
  144. package/dist/{src → types}/modules/debug/balance.d.ts +0 -0
  145. package/dist/{src → types}/modules/debug/chequebook.d.ts +0 -0
  146. package/dist/{src → types}/modules/debug/chunk.d.ts +0 -0
  147. package/dist/{src → types}/modules/debug/connectivity.d.ts +0 -0
  148. package/dist/{src → types}/modules/debug/settlements.d.ts +0 -0
  149. package/dist/{src → types}/modules/debug/stamps.d.ts +0 -0
  150. package/dist/{src → types}/modules/debug/states.d.ts +0 -0
  151. package/dist/types/modules/debug/status.d.ts +72 -0
  152. package/dist/{src → types}/modules/debug/tag.d.ts +0 -0
  153. package/dist/{src → types}/modules/debug/transactions.d.ts +0 -0
  154. package/dist/{src → types}/modules/feed.d.ts +0 -0
  155. package/dist/{src → types}/modules/pinning.d.ts +0 -0
  156. package/dist/{src → types}/modules/pss.d.ts +0 -0
  157. package/dist/{src → types}/modules/soc.d.ts +0 -0
  158. package/dist/{src → types}/modules/status.d.ts +0 -0
  159. package/dist/{src → types}/modules/stewardship.d.ts +0 -0
  160. package/dist/{src → types}/modules/tag.d.ts +0 -0
  161. package/dist/{src → types}/types/debug.d.ts +8 -0
  162. package/dist/{src → types}/types/index.d.ts +3 -2
  163. package/dist/types/types/ky-options.d.ts +221 -0
  164. package/dist/types/types/ky-universal/common.d.ts +13 -0
  165. package/dist/types/types/ky-universal/hooks.d.ts +92 -0
  166. package/dist/types/types/ky-universal/retry.d.ts +38 -0
  167. package/dist/{src → types}/utils/bytes.d.ts +0 -0
  168. package/dist/types/utils/collection.browser.d.ts +15 -0
  169. package/dist/{src → types}/utils/collection.d.ts +0 -14
  170. package/dist/types/utils/collection.node.d.ts +15 -0
  171. package/dist/{src → types}/utils/data.browser.d.ts +0 -0
  172. package/dist/{src → types}/utils/data.d.ts +0 -0
  173. package/dist/{src → types}/utils/error.d.ts +0 -0
  174. package/dist/{src → types}/utils/eth.d.ts +0 -0
  175. package/dist/{src → types}/utils/expose.d.ts +2 -1
  176. package/dist/{src → types}/utils/file.d.ts +0 -0
  177. package/dist/{src → types}/utils/hash.d.ts +0 -0
  178. package/dist/{src → types}/utils/headers.d.ts +0 -0
  179. package/dist/{src → types}/utils/hex.d.ts +0 -0
  180. package/dist/{src → types}/utils/http.d.ts +0 -0
  181. package/dist/{src → types}/utils/merge.d.ts +0 -0
  182. package/dist/{src → types}/utils/pss.d.ts +0 -0
  183. package/dist/{src → types}/utils/stamps.d.ts +0 -0
  184. package/dist/{src → types}/utils/stream.d.ts +11 -8
  185. package/dist/{src → types}/utils/tar.d.ts +0 -0
  186. package/dist/{src → types}/utils/type.d.ts +0 -0
  187. package/dist/{src → types}/utils/uint64.d.ts +0 -0
  188. package/dist/{src → types}/utils/url.d.ts +0 -0
  189. package/package.json +55 -36
  190. package/dist/index.min.js +0 -3
  191. package/dist/index.min.js.LICENSE.txt +0 -50
  192. package/dist/index.min.js.map +0 -1
  193. 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,8 @@
1
+ {
2
+ "type": "module",
3
+ "browser": {
4
+ "stream": false,
5
+ "./utils/data.js": "./utils/data.browser.js",
6
+ "./utils/collection.node.js": "./utils/collection.browser.js"
7
+ }
8
+ }
@@ -0,0 +1,7 @@
1
+ export var BeeModes;
2
+
3
+ (function (BeeModes) {
4
+ BeeModes["FULL"] = "full";
5
+ BeeModes["LIGHT"] = "light";
6
+ BeeModes["DEV"] = "dev";
7
+ })(BeeModes || (BeeModes = {}));
@@ -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;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Types extracted from Ky as a backport for older Ky non-ESM version
3
+ *
4
+ * @author https://github.com/sindresorhus
5
+ * @licence MIT https://github.com/sindresorhus/ky/blob/main/license
6
+ */
7
+ export {};
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Types extracted from Ky as a backport for older Ky non-ESM version
3
+ *
4
+ * @author https://github.com/sindresorhus
5
+ * @licence MIT https://github.com/sindresorhus/ky/blob/main/license
6
+ */
7
+ export {};
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Types extracted from Ky as a backport for older Ky non-ESM version
3
+ *
4
+ * @author https://github.com/sindresorhus
5
+ * @licence MIT https://github.com/sindresorhus/ky/blob/main/license
6
+ */
7
+ export {};
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Types extracted from Ky as a backport for older Ky non-ESM version
3
+ *
4
+ * @author https://github.com/sindresorhus
5
+ * @licence MIT https://github.com/sindresorhus/ky/blob/main/license
6
+ */
7
+ export {};