@ethersphere/bee-js 3.2.0 → 3.3.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 (183) 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 +50 -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 +132 -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 +7 -0
  35. package/dist/cjs/types/debug.js +9 -0
  36. package/dist/cjs/types/index.js +46 -0
  37. package/dist/cjs/utils/bytes.js +107 -0
  38. package/dist/cjs/utils/collection.browser.js +36 -0
  39. package/dist/cjs/utils/collection.js +70 -0
  40. package/dist/cjs/utils/collection.node.js +115 -0
  41. package/dist/cjs/utils/data.browser.js +78 -0
  42. package/dist/cjs/utils/data.js +60 -0
  43. package/dist/cjs/utils/error.js +50 -0
  44. package/dist/cjs/utils/eth.js +206 -0
  45. package/dist/cjs/utils/expose.js +44 -0
  46. package/dist/cjs/utils/file.js +49 -0
  47. package/dist/cjs/utils/hash.js +16 -0
  48. package/dist/cjs/utils/headers.js +59 -0
  49. package/dist/cjs/utils/hex.js +150 -0
  50. package/dist/cjs/utils/http.js +166 -0
  51. package/dist/cjs/utils/merge.js +34 -0
  52. package/dist/cjs/utils/pss.js +18 -0
  53. package/dist/cjs/utils/stamps.js +17 -0
  54. package/dist/cjs/utils/stream.js +137 -0
  55. package/dist/cjs/utils/tar.js +25 -0
  56. package/dist/cjs/utils/type.js +327 -0
  57. package/dist/cjs/utils/uint64.js +29 -0
  58. package/dist/cjs/utils/url.js +56 -0
  59. package/dist/index.js +28326 -0
  60. package/dist/index.js.map +1 -0
  61. package/dist/mjs/bee-debug.js +509 -0
  62. package/dist/mjs/bee.js +845 -0
  63. package/dist/mjs/chunk/bmt.js +46 -0
  64. package/dist/mjs/chunk/cac.js +50 -0
  65. package/dist/mjs/chunk/serialize.js +15 -0
  66. package/dist/mjs/chunk/signer.js +112 -0
  67. package/dist/mjs/chunk/soc.js +127 -0
  68. package/dist/mjs/chunk/span.js +25 -0
  69. package/dist/mjs/feed/index.js +136 -0
  70. package/dist/mjs/feed/json.js +23 -0
  71. package/dist/mjs/feed/topic.js +20 -0
  72. package/dist/mjs/feed/type.js +10 -0
  73. package/dist/mjs/index.js +7 -0
  74. package/dist/mjs/modules/bytes.js +56 -0
  75. package/dist/mjs/modules/bzz.js +119 -0
  76. package/dist/mjs/modules/chunk.js +43 -0
  77. package/dist/mjs/modules/debug/balance.js +53 -0
  78. package/dist/mjs/modules/debug/chequebook.js +131 -0
  79. package/dist/mjs/modules/debug/chunk.js +33 -0
  80. package/dist/mjs/modules/debug/connectivity.js +45 -0
  81. package/dist/mjs/modules/debug/settlements.js +27 -0
  82. package/dist/mjs/modules/debug/stamps.js +59 -0
  83. package/dist/mjs/modules/debug/states.js +29 -0
  84. package/dist/mjs/modules/debug/status.js +114 -0
  85. package/dist/mjs/modules/debug/tag.js +15 -0
  86. package/dist/mjs/modules/debug/transactions.js +57 -0
  87. package/dist/mjs/modules/feed.js +61 -0
  88. package/dist/mjs/modules/pinning.js +60 -0
  89. package/dist/mjs/modules/pss.js +36 -0
  90. package/dist/mjs/modules/soc.js +28 -0
  91. package/dist/mjs/modules/status.js +11 -0
  92. package/dist/mjs/modules/stewardship.js +23 -0
  93. package/dist/mjs/modules/tag.js +69 -0
  94. package/dist/mjs/package.json +7 -0
  95. package/dist/mjs/types/debug.js +6 -0
  96. package/dist/mjs/types/index.js +33 -0
  97. package/dist/mjs/utils/bytes.js +95 -0
  98. package/dist/mjs/utils/collection.browser.js +18 -0
  99. package/dist/mjs/utils/collection.js +52 -0
  100. package/dist/mjs/utils/collection.node.js +63 -0
  101. package/dist/mjs/utils/data.browser.js +57 -0
  102. package/dist/mjs/utils/data.js +39 -0
  103. package/dist/mjs/utils/error.js +48 -0
  104. package/dist/mjs/utils/eth.js +184 -0
  105. package/dist/mjs/utils/expose.js +9 -0
  106. package/dist/mjs/utils/file.js +33 -0
  107. package/dist/mjs/utils/hash.js +12 -0
  108. package/dist/mjs/utils/headers.js +54 -0
  109. package/dist/mjs/utils/hex.js +139 -0
  110. package/dist/mjs/utils/http.js +136 -0
  111. package/dist/mjs/utils/merge.js +30 -0
  112. package/dist/mjs/utils/pss.js +14 -0
  113. package/dist/mjs/utils/stamps.js +13 -0
  114. package/dist/mjs/utils/stream.js +131 -0
  115. package/dist/mjs/utils/tar.js +18 -0
  116. package/dist/mjs/utils/type.js +296 -0
  117. package/dist/mjs/utils/uint64.js +23 -0
  118. package/dist/mjs/utils/url.js +50 -0
  119. package/dist/{src → types}/bee-debug.d.ts +47 -1
  120. package/dist/{src → types}/bee.d.ts +0 -0
  121. package/dist/{src → types}/chunk/bmt.d.ts +0 -0
  122. package/dist/{src → types}/chunk/cac.d.ts +0 -0
  123. package/dist/{src → types}/chunk/serialize.d.ts +0 -0
  124. package/dist/{src → types}/chunk/signer.d.ts +0 -0
  125. package/dist/{src → types}/chunk/soc.d.ts +0 -0
  126. package/dist/{src → types}/chunk/span.d.ts +0 -0
  127. package/dist/{src → types}/feed/index.d.ts +0 -0
  128. package/dist/{src → types}/feed/json.d.ts +0 -0
  129. package/dist/{src → types}/feed/topic.d.ts +0 -0
  130. package/dist/{src → types}/feed/type.d.ts +0 -0
  131. package/dist/{src → types}/index.d.ts +0 -0
  132. package/dist/{src → types}/modules/bytes.d.ts +0 -0
  133. package/dist/{src → types}/modules/bzz.d.ts +0 -0
  134. package/dist/{src → types}/modules/chunk.d.ts +0 -0
  135. package/dist/{src → types}/modules/debug/balance.d.ts +0 -0
  136. package/dist/{src → types}/modules/debug/chequebook.d.ts +0 -0
  137. package/dist/{src → types}/modules/debug/chunk.d.ts +0 -0
  138. package/dist/{src → types}/modules/debug/connectivity.d.ts +0 -0
  139. package/dist/{src → types}/modules/debug/settlements.d.ts +0 -0
  140. package/dist/{src → types}/modules/debug/stamps.d.ts +0 -0
  141. package/dist/{src → types}/modules/debug/states.d.ts +0 -0
  142. package/dist/types/modules/debug/status.d.ts +72 -0
  143. package/dist/{src → types}/modules/debug/tag.d.ts +0 -0
  144. package/dist/{src → types}/modules/debug/transactions.d.ts +0 -0
  145. package/dist/{src → types}/modules/feed.d.ts +0 -0
  146. package/dist/{src → types}/modules/pinning.d.ts +0 -0
  147. package/dist/{src → types}/modules/pss.d.ts +0 -0
  148. package/dist/{src → types}/modules/soc.d.ts +0 -0
  149. package/dist/{src → types}/modules/status.d.ts +0 -0
  150. package/dist/{src → types}/modules/stewardship.d.ts +0 -0
  151. package/dist/{src → types}/modules/tag.d.ts +0 -0
  152. package/dist/{src → types}/types/debug.d.ts +8 -0
  153. package/dist/{src → types}/types/index.d.ts +1 -0
  154. package/dist/{src → types}/utils/bytes.d.ts +0 -0
  155. package/dist/types/utils/collection.browser.d.ts +15 -0
  156. package/dist/{src → types}/utils/collection.d.ts +0 -14
  157. package/dist/types/utils/collection.node.d.ts +15 -0
  158. package/dist/{src → types}/utils/data.browser.d.ts +0 -0
  159. package/dist/{src → types}/utils/data.d.ts +0 -0
  160. package/dist/{src → types}/utils/error.d.ts +0 -0
  161. package/dist/{src → types}/utils/eth.d.ts +0 -0
  162. package/dist/{src → types}/utils/expose.d.ts +2 -1
  163. package/dist/{src → types}/utils/file.d.ts +0 -0
  164. package/dist/{src → types}/utils/hash.d.ts +0 -0
  165. package/dist/{src → types}/utils/headers.d.ts +0 -0
  166. package/dist/{src → types}/utils/hex.d.ts +0 -0
  167. package/dist/{src → types}/utils/http.d.ts +0 -0
  168. package/dist/{src → types}/utils/merge.d.ts +0 -0
  169. package/dist/{src → types}/utils/pss.d.ts +0 -0
  170. package/dist/{src → types}/utils/stamps.d.ts +0 -0
  171. package/dist/{src → types}/utils/stream.d.ts +0 -0
  172. package/dist/{src → types}/utils/tar.d.ts +0 -0
  173. package/dist/{src → types}/utils/type.d.ts +0 -0
  174. package/dist/{src → types}/utils/uint64.d.ts +0 -0
  175. package/dist/{src → types}/utils/url.d.ts +0 -0
  176. package/package.json +39 -23
  177. package/dist/index.browser.min.js +0 -3
  178. package/dist/index.browser.min.js.LICENSE.txt +0 -59
  179. package/dist/index.browser.min.js.map +0 -1
  180. package/dist/index.min.js +0 -3
  181. package/dist/index.min.js.LICENSE.txt +0 -50
  182. package/dist/index.min.js.map +0 -1
  183. package/dist/src/modules/debug/status.d.ts +0 -24
@@ -0,0 +1,119 @@
1
+ import { extractUploadHeaders, readFileHeaders } from '../utils/headers';
2
+ import { http } from '../utils/http';
3
+ import { prepareData } from '../utils/data';
4
+ import { makeTar } from '../utils/tar';
5
+ import { assertCollection } from '../utils/collection';
6
+ import { wrapBytesWithHelpers } from '../utils/bytes';
7
+ import { isReadable } from '../utils/stream';
8
+ import { makeTagUid } from '../utils/type';
9
+ const bzzEndpoint = 'bzz';
10
+ function extractFileUploadHeaders(postageBatchId, options) {
11
+ const headers = extractUploadHeaders(postageBatchId, options);
12
+ if (options?.size)
13
+ headers['content-length'] = String(options.size);
14
+ if (options?.contentType)
15
+ headers['content-type'] = options.contentType;
16
+ return headers;
17
+ }
18
+ /**
19
+ * Upload single file
20
+ *
21
+ * @param ky
22
+ * @param data Files data
23
+ * @param postageBatchId Postage BatchId that will be assigned to uploaded data
24
+ * @param name Name that will be attached to the uploaded file. Wraps the data into manifest with set index document.
25
+ * @param options
26
+ */
27
+ export async function uploadFile(ky, data, postageBatchId, name, options) {
28
+ if (isReadable(data) && !options?.contentType) {
29
+ if (!options)
30
+ options = {};
31
+ options.contentType = 'application/octet-stream';
32
+ }
33
+ const response = await http(ky, {
34
+ method: 'post',
35
+ path: bzzEndpoint,
36
+ body: await prepareData(data),
37
+ headers: {
38
+ ...extractFileUploadHeaders(postageBatchId, options),
39
+ },
40
+ searchParams: { name },
41
+ responseType: 'json',
42
+ });
43
+ return {
44
+ reference: response.data.reference,
45
+ tagUid: makeTagUid(response.headers.get('swarm-tag')),
46
+ };
47
+ }
48
+ /**
49
+ * Download single file as a buffer
50
+ *
51
+ * @param ky Ky instance for given Bee class instance
52
+ * @param hash Bee file or collection hash
53
+ * @param path If hash is collection then this defines path to a single file in the collection
54
+ */
55
+ export async function downloadFile(ky, hash, path = '') {
56
+ const response = await http(ky, {
57
+ method: 'GET',
58
+ responseType: 'arraybuffer',
59
+ path: `${bzzEndpoint}/${hash}/${path}`,
60
+ });
61
+ const file = {
62
+ ...readFileHeaders(response.headers),
63
+ data: wrapBytesWithHelpers(new Uint8Array(response.data)),
64
+ };
65
+ return file;
66
+ }
67
+ /**
68
+ * Download single file as a readable stream
69
+ *
70
+ * @param ky Ky instance for given Bee class instance
71
+ * @param hash Bee file or collection hash
72
+ * @param path If hash is collection then this defines path to a single file in the collection
73
+ */
74
+ export async function downloadFileReadable(ky, hash, path = '') {
75
+ const response = await http(ky, {
76
+ method: 'GET',
77
+ responseType: 'stream',
78
+ path: `${bzzEndpoint}/${hash}/${path}`,
79
+ });
80
+ const file = {
81
+ ...readFileHeaders(response.headers),
82
+ data: response.data,
83
+ };
84
+ return file;
85
+ }
86
+ function extractCollectionUploadHeaders(postageBatchId, options) {
87
+ const headers = extractUploadHeaders(postageBatchId, options);
88
+ if (options?.indexDocument)
89
+ headers['swarm-index-document'] = options.indexDocument;
90
+ if (options?.errorDocument)
91
+ headers['swarm-error-document'] = options.errorDocument;
92
+ return headers;
93
+ }
94
+ /**
95
+ * Upload collection
96
+ * @param ky Ky instance for given Bee class instance
97
+ * @param collection Collection of Uint8Array buffers to upload
98
+ * @param postageBatchId Postage BatchId that will be assigned to uploaded data
99
+ * @param options
100
+ */
101
+ export async function uploadCollection(ky, collection, postageBatchId, options) {
102
+ assertCollection(collection);
103
+ const tarData = makeTar(collection);
104
+ const response = await http(ky, {
105
+ method: 'post',
106
+ path: bzzEndpoint,
107
+ body: tarData,
108
+ responseType: 'json',
109
+ headers: {
110
+ 'content-type': 'application/x-tar',
111
+ 'swarm-collection': 'true',
112
+ ...extractCollectionUploadHeaders(postageBatchId, options),
113
+ },
114
+ });
115
+ return {
116
+ reference: response.data.reference,
117
+ tagUid: makeTagUid(response.headers.get('swarm-tag')),
118
+ };
119
+ }
@@ -0,0 +1,43 @@
1
+ import { extractUploadHeaders } from '../utils/headers';
2
+ import { http } from '../utils/http';
3
+ import { wrapBytesWithHelpers } from '../utils/bytes';
4
+ const endpoint = 'chunks';
5
+ /**
6
+ * Upload chunk to a Bee node
7
+ *
8
+ * The chunk data consists of 8 byte span and up to 4096 bytes of payload data.
9
+ * The span stores the length of the payload in uint64 little endian encoding.
10
+ * Upload expects the chuck data to be set accordingly.
11
+ *
12
+ * @param ky Ky instance
13
+ * @param data Chunk data to be uploaded
14
+ * @param postageBatchId Postage BatchId that will be assigned to uploaded data
15
+ * @param options Additional options like tag, encryption, pinning
16
+ */
17
+ export async function upload(ky, data, postageBatchId, options) {
18
+ const response = await http(ky, {
19
+ method: 'post',
20
+ path: `${endpoint}`,
21
+ body: data,
22
+ headers: {
23
+ 'content-type': 'application/octet-stream',
24
+ ...extractUploadHeaders(postageBatchId, options),
25
+ },
26
+ responseType: 'json',
27
+ });
28
+ return response.data.reference;
29
+ }
30
+ /**
31
+ * Download chunk data as a byte array
32
+ *
33
+ * @param ky Ky instance for given Bee class instance
34
+ * @param hash Bee content reference
35
+ *
36
+ */
37
+ export async function download(ky, hash) {
38
+ const response = await http(ky, {
39
+ responseType: 'arraybuffer',
40
+ path: `${endpoint}/${hash}`,
41
+ });
42
+ return wrapBytesWithHelpers(new Uint8Array(response.data));
43
+ }
@@ -0,0 +1,53 @@
1
+ import { http } from '../../utils/http';
2
+ const balancesEndpoint = 'balances';
3
+ const consumedEndpoint = 'consumed';
4
+ /**
5
+ * Get the balances with all known peers including prepaid services
6
+ *
7
+ * @param ky Ky debug instance
8
+ */
9
+ export async function getAllBalances(ky) {
10
+ const response = await http(ky, {
11
+ path: balancesEndpoint,
12
+ responseType: 'json',
13
+ });
14
+ return response.data;
15
+ }
16
+ /**
17
+ * Get the balances with a specific peer including prepaid services
18
+ *
19
+ * @param ky Ky debug instance
20
+ * @param address Swarm address of peer
21
+ */
22
+ export async function getPeerBalance(ky, address) {
23
+ const response = await http(ky, {
24
+ path: `${balancesEndpoint}/${address}`,
25
+ responseType: 'json',
26
+ });
27
+ return response.data;
28
+ }
29
+ /**
30
+ * Get the past due consumption balances with all known peers
31
+ *
32
+ * @param ky Ky debug instance
33
+ */
34
+ export async function getPastDueConsumptionBalances(ky) {
35
+ const response = await http(ky, {
36
+ path: consumedEndpoint,
37
+ responseType: 'json',
38
+ });
39
+ return response.data;
40
+ }
41
+ /**
42
+ * Get the past due consumption balance with a specific peer
43
+ *
44
+ * @param ky Ky debug instance
45
+ * @param address Swarm address of peer
46
+ */
47
+ export async function getPastDueConsumptionPeerBalance(ky, address) {
48
+ const response = await http(ky, {
49
+ path: `${consumedEndpoint}/${address}`,
50
+ responseType: 'json',
51
+ });
52
+ return response.data;
53
+ }
@@ -0,0 +1,131 @@
1
+ import { http } from '../../utils/http';
2
+ const chequebookEndpoint = 'chequebook';
3
+ /**
4
+ * Get the address of the chequebook contract used
5
+ *
6
+ * @param ky Ky debug instance
7
+ */
8
+ export async function getChequebookAddress(ky) {
9
+ const response = await http(ky, {
10
+ path: chequebookEndpoint + '/address',
11
+ responseType: 'json',
12
+ });
13
+ return response.data;
14
+ }
15
+ /**
16
+ * Get the balance of the chequebook
17
+ *
18
+ * @param ky Ky debug instance
19
+ */
20
+ export async function getChequebookBalance(ky) {
21
+ const response = await http(ky, {
22
+ path: chequebookEndpoint + '/balance',
23
+ responseType: 'json',
24
+ });
25
+ return response.data;
26
+ }
27
+ /**
28
+ * Get last cashout action for the peer
29
+ *
30
+ * @param ky Ky debug instance
31
+ * @param peer Swarm address of peer
32
+ */
33
+ export async function getLastCashoutAction(ky, peer) {
34
+ const response = await http(ky, {
35
+ path: chequebookEndpoint + `/cashout/${peer}`,
36
+ responseType: 'json',
37
+ });
38
+ return response.data;
39
+ }
40
+ /**
41
+ * Cashout the last cheque for the peer
42
+ *
43
+ * @param ky Ky debug instance
44
+ * @param peer Swarm address of peer
45
+ * @param options
46
+ */
47
+ export async function cashoutLastCheque(ky, peer, options) {
48
+ const headers = {};
49
+ if (options?.gasPrice) {
50
+ headers['gas-price'] = options.gasPrice.toString();
51
+ }
52
+ if (options?.gasLimit) {
53
+ headers['gas-limit'] = options.gasLimit.toString();
54
+ }
55
+ const response = await http(ky, {
56
+ method: 'post',
57
+ path: chequebookEndpoint + `/cashout/${peer}`,
58
+ responseType: 'json',
59
+ headers,
60
+ });
61
+ return response.data.transactionHash;
62
+ }
63
+ /**
64
+ * Get last cheques for the peer
65
+ *
66
+ * @param ky Ky debug instance
67
+ * @param peer Swarm address of peer
68
+ */
69
+ export async function getLastChequesForPeer(ky, peer) {
70
+ const response = await http(ky, {
71
+ path: chequebookEndpoint + `/cheque/${peer}`,
72
+ responseType: 'json',
73
+ });
74
+ return response.data;
75
+ }
76
+ /**
77
+ * Get last cheques for all peers
78
+ *
79
+ * @param ky Ky debug instance
80
+ */
81
+ export async function getLastCheques(ky) {
82
+ const response = await http(ky, {
83
+ path: chequebookEndpoint + '/cheque',
84
+ responseType: 'json',
85
+ });
86
+ return response.data;
87
+ }
88
+ /**
89
+ * Deposit tokens from overlay address into chequebook
90
+ *
91
+ * @param ky Ky debug instance
92
+ * @param amount Amount of tokens to deposit
93
+ * @param gasPrice Gas Price in WEI for the transaction call
94
+ * @return string Hash of the transaction
95
+ */
96
+ export async function depositTokens(ky, amount, gasPrice) {
97
+ const headers = {};
98
+ if (gasPrice) {
99
+ headers['gas-price'] = gasPrice.toString();
100
+ }
101
+ const response = await http(ky, {
102
+ method: 'post',
103
+ path: chequebookEndpoint + '/deposit',
104
+ responseType: 'json',
105
+ searchParams: { amount: amount.toString(10) },
106
+ headers,
107
+ });
108
+ return response.data.transactionHash;
109
+ }
110
+ /**
111
+ * Withdraw tokens from the chequebook to the overlay address
112
+ *
113
+ * @param ky Ky debug instance
114
+ * @param amount Amount of tokens to withdraw
115
+ * @param gasPrice Gas Price in WEI for the transaction call
116
+ * @return string Hash of the transaction
117
+ */
118
+ export async function withdrawTokens(ky, amount, gasPrice) {
119
+ const headers = {};
120
+ if (gasPrice) {
121
+ headers['gas-price'] = gasPrice.toString();
122
+ }
123
+ const response = await http(ky, {
124
+ method: 'post',
125
+ path: chequebookEndpoint + '/withdraw',
126
+ responseType: 'json',
127
+ searchParams: { amount: amount.toString(10) },
128
+ headers,
129
+ });
130
+ return response.data.transactionHash;
131
+ }
@@ -0,0 +1,33 @@
1
+ import { http } from '../../utils/http';
2
+ const endpoint = 'chunks';
3
+ /**
4
+ * Check if chunk at address exists locally
5
+ *
6
+ * @param ky Ky debug instance
7
+ * @param address Swarm address of chunk
8
+ *
9
+ * @returns BeeGenericResponse if chunk is found or throws an exception
10
+ */
11
+ export async function checkIfChunkExistsLocally(ky, address) {
12
+ const response = await http(ky, {
13
+ path: endpoint + `/${address}`,
14
+ responseType: 'json',
15
+ });
16
+ return response.data;
17
+ }
18
+ /**
19
+ * Delete a chunk from local storage
20
+ *
21
+ * @param ky Ky debug instance
22
+ * @param address Swarm address of chunk
23
+ *
24
+ * @returns BeeGenericResponse if chunk was deleted or throws an exception
25
+ */
26
+ export async function deleteChunkFromLocalStorage(ky, address) {
27
+ const response = await http(ky, {
28
+ method: 'delete',
29
+ path: endpoint + `/${address}`,
30
+ responseType: 'json',
31
+ });
32
+ return response.data;
33
+ }
@@ -0,0 +1,45 @@
1
+ import { http } from '../../utils/http';
2
+ export async function getNodeAddresses(ky) {
3
+ const response = await http(ky, {
4
+ path: 'addresses',
5
+ responseType: 'json',
6
+ });
7
+ return response.data;
8
+ }
9
+ export async function getPeers(ky) {
10
+ const response = await http(ky, {
11
+ path: 'peers',
12
+ responseType: 'json',
13
+ });
14
+ return response.data.peers || [];
15
+ }
16
+ export async function getBlocklist(ky) {
17
+ const response = await http(ky, {
18
+ path: 'blocklist',
19
+ responseType: 'json',
20
+ });
21
+ return response.data.peers || [];
22
+ }
23
+ export async function removePeer(ky, peer) {
24
+ const response = await http(ky, {
25
+ path: `peers/${peer}`,
26
+ responseType: 'json',
27
+ method: 'DELETE',
28
+ });
29
+ return response.data;
30
+ }
31
+ export async function getTopology(ky) {
32
+ const response = await http(ky, {
33
+ path: `topology`,
34
+ responseType: 'json',
35
+ });
36
+ return response.data;
37
+ }
38
+ export async function pingPeer(ky, peer) {
39
+ const response = await http(ky, {
40
+ path: `pingpong/${peer}`,
41
+ responseType: 'json',
42
+ method: 'POST',
43
+ });
44
+ return response.data;
45
+ }
@@ -0,0 +1,27 @@
1
+ import { http } from '../../utils/http';
2
+ const settlementsEndpoint = 'settlements';
3
+ /**
4
+ * Get amount of sent and received from settlements with a peer
5
+ *
6
+ * @param ky Ky debug instance
7
+ * @param peer Swarm address of peer
8
+ */
9
+ export async function getSettlements(ky, peer) {
10
+ const response = await http(ky, {
11
+ path: `${settlementsEndpoint}/${peer}`,
12
+ responseType: 'json',
13
+ });
14
+ return response.data;
15
+ }
16
+ /**
17
+ * Get settlements with all known peers and total amount sent or received
18
+ *
19
+ * @param ky Ky debug instance
20
+ */
21
+ export async function getAllSettlements(ky) {
22
+ const response = await http(ky, {
23
+ path: settlementsEndpoint,
24
+ responseType: 'json',
25
+ });
26
+ return response.data;
27
+ }
@@ -0,0 +1,59 @@
1
+ import { http } from '../../utils/http';
2
+ const STAMPS_ENDPOINT = 'stamps';
3
+ export async function getAllPostageBatches(ky) {
4
+ const response = await http(ky, {
5
+ method: 'get',
6
+ path: `${STAMPS_ENDPOINT}`,
7
+ responseType: 'json',
8
+ });
9
+ return response.data.stamps || [];
10
+ }
11
+ export async function getPostageBatch(ky, postageBatchId) {
12
+ const response = await http(ky, {
13
+ method: 'get',
14
+ path: `${STAMPS_ENDPOINT}/${postageBatchId}`,
15
+ responseType: 'json',
16
+ });
17
+ return response.data;
18
+ }
19
+ export async function getPostageBatchBuckets(ky, postageBatchId) {
20
+ const response = await http(ky, {
21
+ method: 'get',
22
+ path: `${STAMPS_ENDPOINT}/${postageBatchId}/buckets`,
23
+ responseType: 'json',
24
+ });
25
+ return response.data;
26
+ }
27
+ export async function createPostageBatch(ky, amount, depth, options) {
28
+ const headers = {};
29
+ if (options?.gasPrice) {
30
+ headers['gas-price'] = options.gasPrice.toString();
31
+ }
32
+ if (options?.immutableFlag !== undefined) {
33
+ headers.immutable = String(options.immutableFlag);
34
+ }
35
+ const response = await http(ky, {
36
+ method: 'post',
37
+ path: `${STAMPS_ENDPOINT}/${amount}/${depth}`,
38
+ responseType: 'json',
39
+ searchParams: { label: options?.label },
40
+ headers,
41
+ });
42
+ return response.data.batchID;
43
+ }
44
+ export async function topUpBatch(ky, id, amount) {
45
+ const response = await http(ky, {
46
+ method: 'patch',
47
+ path: `${STAMPS_ENDPOINT}/topup/${id}/${amount}`,
48
+ responseType: 'json',
49
+ });
50
+ return response.data.batchID;
51
+ }
52
+ export async function diluteBatch(ky, id, depth) {
53
+ const response = await http(ky, {
54
+ method: 'patch',
55
+ path: `${STAMPS_ENDPOINT}/dilute/${id}/${depth}`,
56
+ responseType: 'json',
57
+ });
58
+ return response.data.batchID;
59
+ }
@@ -0,0 +1,29 @@
1
+ import { http } from '../../utils/http';
2
+ const RESERVE_STATE_ENDPOINT = 'reservestate';
3
+ const CHAIN_STATE_ENDPOINT = 'chainstate';
4
+ /**
5
+ * Get state of reserve
6
+ *
7
+ * @param ky Ky debug instance
8
+ */
9
+ export async function getReserveState(ky) {
10
+ const response = await http(ky, {
11
+ method: 'get',
12
+ path: `${RESERVE_STATE_ENDPOINT}`,
13
+ responseType: 'json',
14
+ });
15
+ return response.data;
16
+ }
17
+ /**
18
+ * Get state of reserve
19
+ *
20
+ * @param ky Ky debug instance
21
+ */
22
+ export async function getChainState(ky) {
23
+ const response = await http(ky, {
24
+ method: 'get',
25
+ path: `${CHAIN_STATE_ENDPOINT}`,
26
+ responseType: 'json',
27
+ });
28
+ return response.data;
29
+ }
@@ -0,0 +1,114 @@
1
+ import { http } from '../../utils/http';
2
+ import getMajorSemver from 'semver/functions/major';
3
+ // Following lines bellow are automatically updated with GitHub Action when Bee version is updated
4
+ // so if you are changing anything about them change the `update_bee` action accordingly!
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
+ export async function getHealth(ky) {
17
+ const response = await http(ky, {
18
+ method: 'get',
19
+ path: HEALTH_URL,
20
+ responseType: 'json',
21
+ });
22
+ return response.data;
23
+ }
24
+ /**
25
+ * Get information about Bee node
26
+ *
27
+ * @param ky Ky debug instance
28
+ */
29
+ export async function getNodeInfo(ky) {
30
+ const response = await http(ky, {
31
+ method: 'get',
32
+ path: NODE_INFO_URL,
33
+ responseType: 'json',
34
+ });
35
+ return response.data;
36
+ }
37
+ /**
38
+ * Connects to a node and checks if it is a supported Bee version by the bee-js
39
+ *
40
+ * @param ky Ky debug instance
41
+ *
42
+ * @returns true if the Bee node version is supported
43
+ * @deprecated Use `isSupportedExactVersion` instead
44
+ */
45
+ export async function isSupportedVersion(ky) {
46
+ return isSupportedExactVersion(ky);
47
+ }
48
+ /**
49
+ * Connects to a node and checks if its version matches with the one that bee-js supports.
50
+ *
51
+ * Be aware that this is the most strict version check and most probably
52
+ * you will want to use more relaxed API-versions based checks like
53
+ * `isSupportedApiVersion`, `isSupportedMainApiVersion` or `isSupportedDebugApiVersion`
54
+ * based on your use-case.
55
+ *
56
+ * @param ky
57
+ */
58
+ export async function isSupportedExactVersion(ky) {
59
+ const { version } = await getHealth(ky);
60
+ return version === SUPPORTED_BEE_VERSION_EXACT;
61
+ }
62
+ /**
63
+ * Connects to a node and checks if its main's API version matches with the one that bee-js supports.
64
+ *
65
+ * This is useful if you are not using `BeeDebug` class (for anything else then this check)
66
+ * and want to make sure about compatibility.
67
+ *
68
+ * @param ky
69
+ */
70
+ export async function isSupportedMainApiVersion(ky) {
71
+ const { apiVersion } = await getHealth(ky);
72
+ return getMajorSemver(apiVersion) === getMajorSemver(SUPPORTED_API_VERSION);
73
+ }
74
+ /**
75
+ * Connects to a node and checks if its Debug API version matches with the one that bee-js supports.
76
+ *
77
+ * This is useful if you are not using `Bee` class in your application and want to make sure
78
+ * about compatibility.
79
+ *
80
+ * @param ky
81
+ */
82
+ export async function isSupportedDebugApiVersion(ky) {
83
+ const { debugApiVersion } = await getHealth(ky);
84
+ return getMajorSemver(debugApiVersion) === getMajorSemver(SUPPORTED_DEBUG_API_VERSION);
85
+ }
86
+ /**
87
+ * Connects to a node and checks if its Main and Debug API versions matches with the one that bee-js supports.
88
+ *
89
+ * This should be the main way how to check compatibility for your app and Bee node.
90
+ *
91
+ * @param ky
92
+ */
93
+ export async function isSupportedApiVersion(ky) {
94
+ const { apiVersion, debugApiVersion } = await getHealth(ky);
95
+ return (getMajorSemver(apiVersion) === getMajorSemver(SUPPORTED_API_VERSION) &&
96
+ getMajorSemver(debugApiVersion) === getMajorSemver(SUPPORTED_DEBUG_API_VERSION));
97
+ }
98
+ /**
99
+ * Returns object with all versions specified by the connected Bee node (properties prefixed with `bee*`)
100
+ * and versions that bee-js supports (properties prefixed with `supported*`).
101
+ *
102
+ * @param ky
103
+ */
104
+ export async function getVersions(ky) {
105
+ const { version, apiVersion, debugApiVersion } = await getHealth(ky);
106
+ return {
107
+ supportedBeeVersion: SUPPORTED_BEE_VERSION_EXACT,
108
+ supportedBeeApiVersion: SUPPORTED_API_VERSION,
109
+ supportedBeeDebugApiVersion: SUPPORTED_DEBUG_API_VERSION,
110
+ beeVersion: version,
111
+ beeApiVersion: apiVersion,
112
+ beeDebugApiVersion: debugApiVersion,
113
+ };
114
+ }
@@ -0,0 +1,15 @@
1
+ import { http } from '../../utils/http';
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
+ export async function retrieveExtendedTag(ky, uid) {
10
+ const response = await http(ky, {
11
+ path: `${endpoint}/${uid}`,
12
+ responseType: 'json',
13
+ });
14
+ return response.data;
15
+ }