@ethersphere/bee-js 6.0.0-pre.0 → 6.0.0-pre.2

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/README.md +18 -17
  2. package/dist/cjs/bee-debug.js +569 -0
  3. package/dist/cjs/bee.js +873 -0
  4. package/dist/cjs/chunk/bmt.js +55 -0
  5. package/dist/cjs/chunk/cac.js +56 -0
  6. package/dist/cjs/chunk/serialize.js +19 -0
  7. package/dist/cjs/chunk/signer.js +126 -0
  8. package/dist/cjs/chunk/soc.js +159 -0
  9. package/dist/cjs/chunk/span.js +29 -0
  10. package/dist/cjs/feed/identifier.js +35 -0
  11. package/dist/cjs/feed/index.js +116 -0
  12. package/dist/cjs/feed/json.js +28 -0
  13. package/dist/cjs/feed/retrievable.js +58 -0
  14. package/dist/cjs/feed/topic.js +25 -0
  15. package/dist/cjs/feed/type.js +15 -0
  16. package/dist/cjs/index.js +39 -0
  17. package/dist/cjs/modules/bytes.js +61 -0
  18. package/dist/cjs/modules/bzz.js +125 -0
  19. package/dist/cjs/modules/chunk.js +48 -0
  20. package/dist/cjs/modules/debug/balance.js +60 -0
  21. package/dist/cjs/modules/debug/chequebook.js +142 -0
  22. package/dist/cjs/modules/debug/chunk.js +38 -0
  23. package/dist/cjs/modules/debug/connectivity.js +54 -0
  24. package/dist/cjs/modules/debug/settlements.js +32 -0
  25. package/dist/cjs/modules/debug/stake.js +57 -0
  26. package/dist/cjs/modules/debug/stamps.js +68 -0
  27. package/dist/cjs/modules/debug/states.js +64 -0
  28. package/dist/cjs/modules/debug/status.js +148 -0
  29. package/dist/cjs/modules/debug/tag.js +19 -0
  30. package/dist/cjs/modules/debug/transactions.js +64 -0
  31. package/dist/cjs/modules/feed.js +66 -0
  32. package/dist/cjs/modules/pinning.js +63 -0
  33. package/dist/cjs/modules/pss.js +43 -0
  34. package/dist/cjs/modules/soc.js +32 -0
  35. package/dist/cjs/modules/status.js +15 -0
  36. package/dist/cjs/modules/stewardship.js +28 -0
  37. package/dist/cjs/modules/tag.js +77 -0
  38. package/dist/cjs/package.json +8 -0
  39. package/dist/cjs/types/debug.js +10 -0
  40. package/dist/cjs/types/index.js +51 -0
  41. package/dist/cjs/utils/bytes.js +121 -0
  42. package/dist/cjs/utils/collection.browser.js +23 -0
  43. package/dist/cjs/utils/collection.js +59 -0
  44. package/dist/cjs/utils/collection.node.js +71 -0
  45. package/dist/cjs/utils/data.browser.js +61 -0
  46. package/dist/cjs/utils/data.js +45 -0
  47. package/dist/cjs/utils/error.js +16 -0
  48. package/dist/cjs/utils/eth.js +199 -0
  49. package/dist/cjs/utils/expose.js +44 -0
  50. package/dist/cjs/utils/file.js +38 -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 +30 -0
  55. package/dist/cjs/utils/pss.js +18 -0
  56. package/dist/cjs/utils/reference.js +36 -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 +434 -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 +3 -0
  64. package/dist/index.browser.min.js.LICENSE.txt +50 -0
  65. package/dist/index.browser.min.js.map +1 -0
  66. package/dist/{src → mjs}/bee-debug.js +101 -185
  67. package/dist/{src → mjs}/bee.js +81 -234
  68. package/dist/{src → mjs}/chunk/bmt.js +4 -10
  69. package/dist/{src → mjs}/chunk/cac.js +0 -3
  70. package/dist/{src → mjs}/chunk/signer.js +1 -18
  71. package/dist/{src → mjs}/chunk/soc.js +17 -29
  72. package/dist/{src → mjs}/chunk/span.js +2 -5
  73. package/dist/{src → mjs}/feed/identifier.js +0 -6
  74. package/dist/{src → mjs}/feed/index.js +24 -27
  75. package/dist/{src → mjs}/feed/json.js +2 -5
  76. package/dist/{src → mjs}/feed/retrievable.js +7 -21
  77. package/dist/{src → mjs}/feed/topic.js +0 -2
  78. package/dist/{src → mjs}/index.js +2 -2
  79. package/dist/{src → mjs}/modules/bytes.js +16 -20
  80. package/dist/{src → mjs}/modules/bzz.js +33 -40
  81. package/dist/{src → mjs}/modules/chunk.js +11 -13
  82. package/dist/mjs/modules/debug/balance.js +53 -0
  83. package/dist/mjs/modules/debug/chequebook.js +135 -0
  84. package/dist/{src → mjs}/modules/debug/chunk.js +10 -12
  85. package/dist/mjs/modules/debug/connectivity.js +45 -0
  86. package/dist/mjs/modules/debug/settlements.js +27 -0
  87. package/dist/mjs/modules/debug/stake.js +51 -0
  88. package/dist/mjs/modules/debug/stamps.js +61 -0
  89. package/dist/mjs/modules/debug/states.js +58 -0
  90. package/dist/{src → mjs}/modules/debug/status.js +46 -37
  91. package/dist/mjs/modules/debug/tag.js +15 -0
  92. package/dist/mjs/modules/debug/transactions.js +59 -0
  93. package/dist/{src → mjs}/modules/feed.js +15 -21
  94. package/dist/mjs/modules/pinning.js +56 -0
  95. package/dist/{src → mjs}/modules/pss.js +7 -10
  96. package/dist/{src → mjs}/modules/soc.js +6 -7
  97. package/dist/mjs/modules/status.js +11 -0
  98. package/dist/mjs/modules/stewardship.js +23 -0
  99. package/dist/mjs/modules/tag.js +72 -0
  100. package/dist/mjs/package.json +8 -0
  101. package/dist/{src → mjs}/types/debug.js +0 -1
  102. package/dist/{src → mjs}/types/index.js +0 -4
  103. package/dist/{src → mjs}/utils/bytes.js +8 -17
  104. package/dist/{src/utils/collection-browser.js → mjs/utils/collection.browser.js} +0 -1
  105. package/dist/{src → mjs}/utils/collection.js +0 -12
  106. package/dist/{src/utils/collection-node.js → mjs/utils/collection.node.js} +0 -13
  107. package/dist/{src → mjs}/utils/data.browser.js +2 -11
  108. package/dist/{src → mjs}/utils/data.js +0 -7
  109. package/dist/mjs/utils/error.js +11 -0
  110. package/dist/{src → mjs}/utils/eth.js +6 -28
  111. package/dist/{src → mjs}/utils/expose.js +1 -1
  112. package/dist/{src → mjs}/utils/file.js +4 -9
  113. package/dist/{src → mjs}/utils/hash.js +0 -1
  114. package/dist/{src → mjs}/utils/headers.js +5 -13
  115. package/dist/{src → mjs}/utils/hex.js +6 -25
  116. package/dist/mjs/utils/http.js +22 -0
  117. package/dist/{src → mjs}/utils/pss.js +0 -2
  118. package/dist/{src → mjs}/utils/reference.js +2 -5
  119. package/dist/{src → mjs}/utils/stream.js +3 -26
  120. package/dist/{src → mjs}/utils/tar.js +2 -5
  121. package/dist/{src → mjs}/utils/type.js +23 -80
  122. package/dist/{src → mjs}/utils/uint64.js +0 -1
  123. package/dist/{src → mjs}/utils/url.js +2 -10
  124. package/dist/types/bee-debug.d.ts +71 -46
  125. package/dist/types/bee.d.ts +34 -58
  126. package/dist/types/chunk/bmt.d.ts +1 -1
  127. package/dist/types/chunk/cac.d.ts +1 -1
  128. package/dist/types/chunk/soc.d.ts +9 -9
  129. package/dist/types/chunk/span.d.ts +1 -1
  130. package/dist/types/feed/index.d.ts +10 -10
  131. package/dist/types/feed/json.d.ts +2 -2
  132. package/dist/types/feed/retrievable.d.ts +2 -2
  133. package/dist/types/feed/type.d.ts +1 -1
  134. package/dist/types/index.d.ts +13 -2
  135. package/dist/types/modules/bytes.d.ts +5 -5
  136. package/dist/types/modules/bzz.d.ts +8 -8
  137. package/dist/types/modules/chunk.d.ts +4 -4
  138. package/dist/types/modules/debug/balance.d.ts +9 -9
  139. package/dist/types/modules/debug/chequebook.d.ts +17 -17
  140. package/dist/types/modules/debug/chunk.d.ts +5 -5
  141. package/dist/types/modules/debug/connectivity.d.ts +7 -7
  142. package/dist/types/modules/debug/settlements.d.ts +5 -5
  143. package/dist/types/modules/debug/stake.d.ts +21 -0
  144. package/dist/types/modules/debug/stamps.d.ts +7 -7
  145. package/dist/types/modules/debug/states.d.ts +7 -7
  146. package/dist/types/modules/debug/status.d.ts +21 -15
  147. package/dist/types/modules/debug/tag.d.ts +3 -3
  148. package/dist/types/modules/debug/transactions.d.ts +5 -5
  149. package/dist/types/modules/feed.d.ts +3 -3
  150. package/dist/types/modules/pinning.d.ts +7 -7
  151. package/dist/types/modules/pss.d.ts +3 -3
  152. package/dist/types/modules/soc.d.ts +2 -2
  153. package/dist/types/modules/status.d.ts +3 -3
  154. package/dist/types/modules/stewardship.d.ts +3 -3
  155. package/dist/types/modules/tag.d.ts +6 -6
  156. package/dist/types/types/debug.d.ts +35 -2
  157. package/dist/types/types/index.d.ts +45 -88
  158. package/dist/types/utils/error.d.ts +0 -26
  159. package/dist/types/utils/eth.d.ts +6 -6
  160. package/dist/types/utils/expose.d.ts +4 -7
  161. package/dist/types/utils/hash.d.ts +1 -1
  162. package/dist/types/utils/headers.d.ts +1 -1
  163. package/dist/types/utils/hex.d.ts +4 -4
  164. package/dist/types/utils/http.d.ts +12 -21
  165. package/dist/types/utils/stream.d.ts +1 -1
  166. package/dist/types/utils/type.d.ts +3 -2
  167. package/dist/types/utils/uint64.d.ts +1 -1
  168. package/package.json +59 -49
  169. package/dist/index.browser.js +0 -33
  170. package/dist/index.browser.js.map +0 -7
  171. package/dist/src/modules/debug/balance.js +0 -57
  172. package/dist/src/modules/debug/chequebook.js +0 -150
  173. package/dist/src/modules/debug/connectivity.js +0 -45
  174. package/dist/src/modules/debug/settlements.js +0 -29
  175. package/dist/src/modules/debug/stamps.js +0 -64
  176. package/dist/src/modules/debug/states.js +0 -46
  177. package/dist/src/modules/debug/tag.js +0 -16
  178. package/dist/src/modules/debug/transactions.js +0 -69
  179. package/dist/src/modules/pinning.js +0 -60
  180. package/dist/src/modules/status.js +0 -12
  181. package/dist/src/modules/stewardship.js +0 -24
  182. package/dist/src/modules/tag.js +0 -77
  183. package/dist/src/utils/error.js +0 -47
  184. package/dist/src/utils/http.js +0 -162
  185. package/dist/src/utils/merge.js +0 -36
  186. package/dist/src/utils/sleep.js +0 -8
  187. package/dist/types/utils/merge.d.ts +0 -8
  188. package/dist/types/utils/sleep.d.ts +0 -6
  189. /package/dist/{src → mjs}/chunk/serialize.js +0 -0
  190. /package/dist/{src → mjs}/feed/type.js +0 -0
  191. /package/dist/{src → mjs}/utils/stamps.js +0 -0
  192. /package/dist/types/utils/{collection-browser.d.ts → collection.browser.d.ts} +0 -0
  193. /package/dist/types/utils/{collection-node.d.ts → collection.node.d.ts} +0 -0
@@ -1,13 +1,11 @@
1
+ import { wrapBytesWithHelpers } from "../utils/bytes.js";
2
+ import { assertCollection } from "../utils/collection.js";
1
3
  import { extractUploadHeaders, readFileHeaders } from "../utils/headers.js";
2
4
  import { http } from "../utils/http.js";
3
- import { prepareData } from "../utils/data.js";
4
- import { makeTar } from "../utils/tar.js";
5
- import { assertCollection } from "../utils/collection.js";
6
- import { wrapBytesWithHelpers } from "../utils/bytes.js";
7
5
  import { isReadable } from "../utils/stream.js";
6
+ import { makeTar } from "../utils/tar.js";
8
7
  import { makeTagUid } from "../utils/type.js";
9
8
  const bzzEndpoint = 'bzz';
10
-
11
9
  function extractFileUploadHeaders(postageBatchId, options) {
12
10
  const headers = extractUploadHeaders(postageBatchId, options);
13
11
  if (options?.size) headers['content-length'] = String(options.size);
@@ -23,69 +21,66 @@ function extractFileUploadHeaders(postageBatchId, options) {
23
21
  * @param name Name that will be attached to the uploaded file. Wraps the data into manifest with set index document.
24
22
  * @param options
25
23
  */
26
-
27
-
28
- export async function uploadFile(ky, data, postageBatchId, name, options) {
24
+ export async function uploadFile(requestOptions, data, postageBatchId, name, options) {
29
25
  if (isReadable(data) && !options?.contentType) {
30
26
  if (!options) options = {};
31
27
  options.contentType = 'application/octet-stream';
32
28
  }
33
-
34
- const response = await http(ky, {
29
+ const response = await http(requestOptions, {
35
30
  method: 'post',
36
- path: bzzEndpoint,
37
- body: await prepareData(data),
38
- headers: { ...extractFileUploadHeaders(postageBatchId, options)
31
+ url: bzzEndpoint,
32
+ data,
33
+ headers: {
34
+ ...extractFileUploadHeaders(postageBatchId, options)
39
35
  },
40
- searchParams: {
36
+ params: {
41
37
  name
42
38
  },
43
39
  responseType: 'json'
44
40
  });
45
41
  return {
46
- reference: response.parsedData.reference,
47
- tagUid: makeTagUid(response.headers.get('swarm-tag'))
42
+ reference: response.data.reference,
43
+ tagUid: makeTagUid(response.headers['swarm-tag'])
48
44
  };
49
45
  }
50
46
  /**
51
47
  * Download single file as a buffer
52
48
  *
53
- * @param ky Ky instance for given Bee class instance
49
+ * @param kyOptions Ky Options for making requests
54
50
  * @param hash Bee file or collection hash
55
51
  * @param path If hash is collection then this defines path to a single file in the collection
56
52
  */
57
-
58
- export async function downloadFile(ky, hash, path = '') {
59
- const response = await http(ky, {
53
+ export async function downloadFile(requestOptions, hash, path = '') {
54
+ const response = await http(requestOptions, {
60
55
  method: 'GET',
61
56
  responseType: 'arraybuffer',
62
- path: `${bzzEndpoint}/${hash}/${path}`
57
+ url: `${bzzEndpoint}/${hash}/${path}`
63
58
  });
64
- const file = { ...readFileHeaders(response.headers),
65
- data: wrapBytesWithHelpers(new Uint8Array(response.parsedData))
59
+ const file = {
60
+ ...readFileHeaders(response.headers),
61
+ data: wrapBytesWithHelpers(new Uint8Array(response.data))
66
62
  };
67
63
  return file;
68
64
  }
69
65
  /**
70
66
  * Download single file as a readable stream
71
67
  *
72
- * @param ky Ky instance for given Bee class instance
68
+ * @param kyOptions Ky Options for making requests
73
69
  * @param hash Bee file or collection hash
74
70
  * @param path If hash is collection then this defines path to a single file in the collection
75
71
  */
76
-
77
- export async function downloadFileReadable(ky, hash, path = '') {
78
- const response = await http(ky, {
72
+ export async function downloadFileReadable(requestOptions, hash, path = '') {
73
+ const response = await http(requestOptions, {
79
74
  method: 'GET',
80
75
  responseType: 'stream',
81
- path: `${bzzEndpoint}/${hash}/${path}`
76
+ url: `${bzzEndpoint}/${hash}/${path}`
82
77
  });
83
- const file = { ...readFileHeaders(response.headers),
84
- data: response.parsedData
78
+ const file = {
79
+ ...readFileHeaders(response.headers),
80
+ data: response.data
85
81
  };
86
82
  return file;
87
83
  }
88
-
89
84
  function extractCollectionUploadHeaders(postageBatchId, options) {
90
85
  const headers = extractUploadHeaders(postageBatchId, options);
91
86
  if (options?.indexDocument) headers['swarm-index-document'] = options.indexDocument;
@@ -94,20 +89,18 @@ function extractCollectionUploadHeaders(postageBatchId, options) {
94
89
  }
95
90
  /**
96
91
  * Upload collection
97
- * @param ky Ky instance for given Bee class instance
92
+ * @param kyOptions Ky Options for making requests
98
93
  * @param collection Collection of Uint8Array buffers to upload
99
94
  * @param postageBatchId Postage BatchId that will be assigned to uploaded data
100
95
  * @param options
101
96
  */
102
-
103
-
104
- export async function uploadCollection(ky, collection, postageBatchId, options) {
97
+ export async function uploadCollection(requestOptions, collection, postageBatchId, options) {
105
98
  assertCollection(collection);
106
99
  const tarData = makeTar(collection);
107
- const response = await http(ky, {
100
+ const response = await http(requestOptions, {
108
101
  method: 'post',
109
- path: bzzEndpoint,
110
- body: tarData,
102
+ url: bzzEndpoint,
103
+ data: tarData,
111
104
  responseType: 'json',
112
105
  headers: {
113
106
  'content-type': 'application/x-tar',
@@ -116,7 +109,7 @@ export async function uploadCollection(ky, collection, postageBatchId, options)
116
109
  }
117
110
  });
118
111
  return {
119
- reference: response.parsedData.reference,
120
- tagUid: makeTagUid(response.headers.get('swarm-tag'))
112
+ reference: response.data.reference,
113
+ tagUid: makeTagUid(response.headers['swarm-tag'])
121
114
  };
122
115
  }
@@ -1,6 +1,6 @@
1
+ import { wrapBytesWithHelpers } from "../utils/bytes.js";
1
2
  import { extractUploadHeaders } from "../utils/headers.js";
2
3
  import { http } from "../utils/http.js";
3
- import { wrapBytesWithHelpers } from "../utils/bytes.js";
4
4
  const endpoint = 'chunks';
5
5
  /**
6
6
  * Upload chunk to a Bee node
@@ -14,32 +14,30 @@ const endpoint = 'chunks';
14
14
  * @param postageBatchId Postage BatchId that will be assigned to uploaded data
15
15
  * @param options Additional options like tag, encryption, pinning
16
16
  */
17
-
18
- export async function upload(ky, data, postageBatchId, options) {
19
- const response = await http(ky, {
17
+ export async function upload(requestOptions, data, postageBatchId, options) {
18
+ const response = await http(requestOptions, {
20
19
  method: 'post',
21
- path: `${endpoint}`,
22
- body: data,
20
+ url: `${endpoint}`,
21
+ data,
23
22
  headers: {
24
23
  'content-type': 'application/octet-stream',
25
24
  ...extractUploadHeaders(postageBatchId, options)
26
25
  },
27
26
  responseType: 'json'
28
27
  });
29
- return response.parsedData.reference;
28
+ return response.data.reference;
30
29
  }
31
30
  /**
32
31
  * Download chunk data as a byte array
33
32
  *
34
- * @param ky Ky instance for given Bee class instance
33
+ * @param kyOptions Ky Options for making requests
35
34
  * @param hash Bee content reference
36
35
  *
37
36
  */
38
-
39
- export async function download(ky, hash) {
40
- const response = await http(ky, {
37
+ export async function download(requestOptions, hash) {
38
+ const response = await http(requestOptions, {
41
39
  responseType: 'arraybuffer',
42
- path: `${endpoint}/${hash}`
40
+ url: `${endpoint}/${hash}`
43
41
  });
44
- return wrapBytesWithHelpers(new Uint8Array(response.parsedData));
42
+ return wrapBytesWithHelpers(new Uint8Array(response.data));
45
43
  }
@@ -0,0 +1,53 @@
1
+ import { http } from "../../utils/http.js";
2
+ const balancesEndpoint = 'balances';
3
+ const consumedEndpoint = 'consumed';
4
+ /**
5
+ * Get the balances with all known peers including prepaid services
6
+ *
7
+ * @param kyOptions Ky Options for making requests
8
+ */
9
+ export async function getAllBalances(requestOptions) {
10
+ const response = await http(requestOptions, {
11
+ url: 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 kyOptions Ky Options for making requests
20
+ * @param address Swarm address of peer
21
+ */
22
+ export async function getPeerBalance(requestOptions, address) {
23
+ const response = await http(requestOptions, {
24
+ url: `${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 kyOptions Ky Options for making requests
33
+ */
34
+ export async function getPastDueConsumptionBalances(requestOptions) {
35
+ const response = await http(requestOptions, {
36
+ url: 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 kyOptions Ky Options for making requests
45
+ * @param address Swarm address of peer
46
+ */
47
+ export async function getPastDueConsumptionPeerBalance(requestOptions, address) {
48
+ const response = await http(requestOptions, {
49
+ url: `${consumedEndpoint}/${address}`,
50
+ responseType: 'json'
51
+ });
52
+ return response.data;
53
+ }
@@ -0,0 +1,135 @@
1
+ import { http } from "../../utils/http.js";
2
+ const chequebookEndpoint = 'chequebook';
3
+ /**
4
+ * Get the address of the chequebook contract used
5
+ *
6
+ * @param kyOptions Ky Options for making requests
7
+ */
8
+ export async function getChequebookAddress(requestOptions) {
9
+ const response = await http(requestOptions, {
10
+ url: chequebookEndpoint + '/address',
11
+ responseType: 'json'
12
+ });
13
+ return response.data;
14
+ }
15
+ /**
16
+ * Get the balance of the chequebook
17
+ *
18
+ * @param kyOptions Ky Options for making requests
19
+ */
20
+ export async function getChequebookBalance(requestOptions) {
21
+ const response = await http(requestOptions, {
22
+ url: chequebookEndpoint + '/balance',
23
+ responseType: 'json'
24
+ });
25
+ return response.data;
26
+ }
27
+ /**
28
+ * Get last cashout action for the peer
29
+ *
30
+ * @param kyOptions Ky Options for making requests
31
+ * @param peer Swarm address of peer
32
+ */
33
+ export async function getLastCashoutAction(requestOptions, peer) {
34
+ const response = await http(requestOptions, {
35
+ url: chequebookEndpoint + `/cashout/${peer}`,
36
+ responseType: 'json'
37
+ });
38
+ return response.data;
39
+ }
40
+ /**
41
+ * Cashout the last cheque for the peer
42
+ *
43
+ * @param kyOptions Ky Options for making requests
44
+ * @param peer Swarm address of peer
45
+ * @param options
46
+ */
47
+ export async function cashoutLastCheque(requestOptions, 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(requestOptions, {
56
+ method: 'post',
57
+ url: 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 kyOptions Ky Options for making requests
67
+ * @param peer Swarm address of peer
68
+ */
69
+ export async function getLastChequesForPeer(requestOptions, peer) {
70
+ const response = await http(requestOptions, {
71
+ url: chequebookEndpoint + `/cheque/${peer}`,
72
+ responseType: 'json'
73
+ });
74
+ return response.data;
75
+ }
76
+ /**
77
+ * Get last cheques for all peers
78
+ *
79
+ * @param kyOptions Ky Options for making requests
80
+ */
81
+ export async function getLastCheques(requestOptions) {
82
+ const response = await http(requestOptions, {
83
+ url: chequebookEndpoint + '/cheque',
84
+ responseType: 'json'
85
+ });
86
+ return response.data;
87
+ }
88
+ /**
89
+ * Deposit tokens from overlay address into chequebook
90
+ *
91
+ * @param kyOptions Ky Options for making requests
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(requestOptions, amount, gasPrice) {
97
+ const headers = {};
98
+ if (gasPrice) {
99
+ headers['gas-price'] = gasPrice.toString();
100
+ }
101
+ const response = await http(requestOptions, {
102
+ method: 'post',
103
+ url: chequebookEndpoint + '/deposit',
104
+ responseType: 'json',
105
+ params: {
106
+ amount: amount.toString(10)
107
+ },
108
+ headers
109
+ });
110
+ return response.data.transactionHash;
111
+ }
112
+ /**
113
+ * Withdraw tokens from the chequebook to the overlay address
114
+ *
115
+ * @param kyOptions Ky Options for making requests
116
+ * @param amount Amount of tokens to withdraw
117
+ * @param gasPrice Gas Price in WEI for the transaction call
118
+ * @return string Hash of the transaction
119
+ */
120
+ export async function withdrawTokens(requestOptions, amount, gasPrice) {
121
+ const headers = {};
122
+ if (gasPrice) {
123
+ headers['gas-price'] = gasPrice.toString();
124
+ }
125
+ const response = await http(requestOptions, {
126
+ method: 'post',
127
+ url: chequebookEndpoint + '/withdraw',
128
+ responseType: 'json',
129
+ params: {
130
+ amount: amount.toString(10)
131
+ },
132
+ headers
133
+ });
134
+ return response.data.transactionHash;
135
+ }
@@ -3,33 +3,31 @@ const endpoint = 'chunks';
3
3
  /**
4
4
  * Check if chunk at address exists locally
5
5
  *
6
- * @param ky Ky debug instance
6
+ * @param kyOptions Ky Options for making requests
7
7
  * @param address Swarm address of chunk
8
8
  *
9
9
  * @returns BeeGenericResponse if chunk is found or throws an exception
10
10
  */
11
-
12
- export async function checkIfChunkExistsLocally(ky, address) {
13
- const response = await http(ky, {
14
- path: endpoint + `/${address}`,
11
+ export async function checkIfChunkExistsLocally(requestOptions, address) {
12
+ const response = await http(requestOptions, {
13
+ url: `${endpoint}/${address}`,
15
14
  responseType: 'json'
16
15
  });
17
- return response.parsedData;
16
+ return response.data;
18
17
  }
19
18
  /**
20
19
  * Delete a chunk from local storage
21
20
  *
22
- * @param ky Ky debug instance
21
+ * @param kyOptions Ky Options for making requests
23
22
  * @param address Swarm address of chunk
24
23
  *
25
24
  * @returns BeeGenericResponse if chunk was deleted or throws an exception
26
25
  */
27
-
28
- export async function deleteChunkFromLocalStorage(ky, address) {
29
- const response = await http(ky, {
26
+ export async function deleteChunkFromLocalStorage(requestOptions, address) {
27
+ const response = await http(requestOptions, {
30
28
  method: 'delete',
31
- path: endpoint + `/${address}`,
29
+ url: `${endpoint}/${address}`,
32
30
  responseType: 'json'
33
31
  });
34
- return response.parsedData;
32
+ return response.data;
35
33
  }
@@ -0,0 +1,45 @@
1
+ import { http } from "../../utils/http.js";
2
+ export async function getNodeAddresses(requestOptions) {
3
+ const response = await http(requestOptions, {
4
+ url: 'addresses',
5
+ responseType: 'json'
6
+ });
7
+ return response.data;
8
+ }
9
+ export async function getPeers(requestOptions) {
10
+ const response = await http(requestOptions, {
11
+ url: 'peers',
12
+ responseType: 'json'
13
+ });
14
+ return response.data.peers;
15
+ }
16
+ export async function getBlocklist(requestOptions) {
17
+ const response = await http(requestOptions, {
18
+ url: 'blocklist',
19
+ responseType: 'json'
20
+ });
21
+ return response.data.peers;
22
+ }
23
+ export async function removePeer(requestOptions, peer) {
24
+ const response = await http(requestOptions, {
25
+ url: `peers/${peer}`,
26
+ responseType: 'json',
27
+ method: 'DELETE'
28
+ });
29
+ return response.data;
30
+ }
31
+ export async function getTopology(requestOptions) {
32
+ const response = await http(requestOptions, {
33
+ url: `topology`,
34
+ responseType: 'json'
35
+ });
36
+ return response.data;
37
+ }
38
+ export async function pingPeer(requestOptions, peer) {
39
+ const response = await http(requestOptions, {
40
+ url: `pingpong/${peer}`,
41
+ responseType: 'json',
42
+ method: 'POST'
43
+ });
44
+ return response.data;
45
+ }
@@ -0,0 +1,27 @@
1
+ import { http } from "../../utils/http.js";
2
+ const settlementsEndpoint = 'settlements';
3
+ /**
4
+ * Get amount of sent and received from settlements with a peer
5
+ *
6
+ * @param kyOptions Ky Options for making requests
7
+ * @param peer Swarm address of peer
8
+ */
9
+ export async function getSettlements(requestOptions, peer) {
10
+ const response = await http(requestOptions, {
11
+ url: `${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 kyOptions Ky Options for making requests
20
+ */
21
+ export async function getAllSettlements(requestOptions) {
22
+ const response = await http(requestOptions, {
23
+ url: settlementsEndpoint,
24
+ responseType: 'json'
25
+ });
26
+ return response.data;
27
+ }
@@ -0,0 +1,51 @@
1
+ import { http } from "../../utils/http.js";
2
+ const STAKE_ENDPOINT = 'stake';
3
+ const REDISTRIBUTION_ENDPOINT = 'redistributionstate';
4
+ /**
5
+ * Gets the staked amount
6
+ *
7
+ * @param kyOptions Ky Options for making requests
8
+ */
9
+ export async function getStake(requestOptions) {
10
+ const response = await http(requestOptions, {
11
+ method: 'get',
12
+ responseType: 'json',
13
+ url: `${STAKE_ENDPOINT}`
14
+ });
15
+ return response.data.stakedAmount.toString();
16
+ }
17
+ /**
18
+ * Stake given amount of tokens.
19
+ *
20
+ * @param ky
21
+ * @param amount
22
+ * @param options
23
+ */
24
+ export async function stake(requestOptions, amount, options) {
25
+ const headers = {};
26
+ if (options?.gasPrice) {
27
+ headers['gas-price'] = options.gasPrice.toString();
28
+ }
29
+ if (options?.gasLimit) {
30
+ headers['gas-limit'] = options.gasLimit.toString();
31
+ }
32
+ await http(requestOptions, {
33
+ method: 'post',
34
+ responseType: 'json',
35
+ url: `${STAKE_ENDPOINT}/${amount}`,
36
+ headers
37
+ });
38
+ }
39
+ /**
40
+ * Get current status of node in redistribution game
41
+ *
42
+ * @param kyOptions Ky Options for making requests
43
+ */
44
+ export async function getRedistributionState(requestOptions) {
45
+ const response = await http(requestOptions, {
46
+ method: 'get',
47
+ responseType: 'json',
48
+ url: REDISTRIBUTION_ENDPOINT
49
+ });
50
+ return response.data;
51
+ }
@@ -0,0 +1,61 @@
1
+ import { http } from "../../utils/http.js";
2
+ const STAMPS_ENDPOINT = 'stamps';
3
+ export async function getAllPostageBatches(requestOptions) {
4
+ const response = await http(requestOptions, {
5
+ method: 'get',
6
+ url: `${STAMPS_ENDPOINT}`,
7
+ responseType: 'json'
8
+ });
9
+ return response.data.stamps;
10
+ }
11
+ export async function getPostageBatch(requestOptions, postageBatchId) {
12
+ const response = await http(requestOptions, {
13
+ method: 'get',
14
+ url: `${STAMPS_ENDPOINT}/${postageBatchId}`,
15
+ responseType: 'json'
16
+ });
17
+ return response.data;
18
+ }
19
+ export async function getPostageBatchBuckets(requestOptions, postageBatchId) {
20
+ const response = await http(requestOptions, {
21
+ method: 'get',
22
+ url: `${STAMPS_ENDPOINT}/${postageBatchId}/buckets`,
23
+ responseType: 'json'
24
+ });
25
+ return response.data;
26
+ }
27
+ export async function createPostageBatch(requestOptions, 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(requestOptions, {
36
+ method: 'post',
37
+ url: `${STAMPS_ENDPOINT}/${amount}/${depth}`,
38
+ responseType: 'json',
39
+ params: {
40
+ label: options?.label
41
+ },
42
+ headers
43
+ });
44
+ return response.data.batchID;
45
+ }
46
+ export async function topUpBatch(requestOptions, id, amount) {
47
+ const response = await http(requestOptions, {
48
+ method: 'patch',
49
+ url: `${STAMPS_ENDPOINT}/topup/${id}/${amount}`,
50
+ responseType: 'json'
51
+ });
52
+ return response.data.batchID;
53
+ }
54
+ export async function diluteBatch(requestOptions, id, depth) {
55
+ const response = await http(requestOptions, {
56
+ method: 'patch',
57
+ url: `${STAMPS_ENDPOINT}/dilute/${id}/${depth}`,
58
+ responseType: 'json'
59
+ });
60
+ return response.data.batchID;
61
+ }
@@ -0,0 +1,58 @@
1
+ import { http } from "../../utils/http.js";
2
+ const RESERVE_STATE_ENDPOINT = 'reservestate';
3
+ const WALLET_ENDPOINT = 'wallet';
4
+ const CHAIN_STATE_ENDPOINT = 'chainstate';
5
+ /**
6
+ * Get state of reserve
7
+ *
8
+ * @param kyOptions Ky Options for making requests
9
+ */
10
+ export async function getReserveState(requestOptions) {
11
+ const response = await http(requestOptions, {
12
+ method: 'get',
13
+ url: `${RESERVE_STATE_ENDPOINT}`,
14
+ responseType: 'json'
15
+ });
16
+ return response.data;
17
+ }
18
+ /**
19
+ * Get state of reserve
20
+ *
21
+ * @param kyOptions Ky Options for making requests
22
+ */
23
+ export async function getChainState(requestOptions) {
24
+ const response = await http(requestOptions, {
25
+ method: 'get',
26
+ url: `${CHAIN_STATE_ENDPOINT}`,
27
+ responseType: 'json'
28
+ });
29
+ return response.data;
30
+ }
31
+ /**
32
+ * Get wallet balances for xDai and BZZ of the node
33
+ *
34
+ * @param kyOptions Ky Options for making requests
35
+ */
36
+ export async function getWalletBalance(requestOptions) {
37
+ const response = await http(requestOptions, {
38
+ method: 'get',
39
+ url: `${WALLET_ENDPOINT}`,
40
+ responseType: 'json'
41
+ });
42
+ return mapWalletProperties(response.data);
43
+ }
44
+ /**
45
+ * TODO: Remove on next break
46
+ * @param data
47
+ */
48
+ function mapWalletProperties(data) {
49
+ return {
50
+ // @ts-ignore: Needed for backward compatibility mapping
51
+ bzz: data.bzzBalance,
52
+ // @ts-ignore: Needed for backward compatibility mapping
53
+ xDai: data.nativeTokenBalance,
54
+ // @ts-ignore: Needed for backward compatibility mapping
55
+ contractAddress: data.chequebookContractAddress,
56
+ ...data
57
+ };
58
+ }