@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,59 @@
1
+ import { prepareData } from "../utils/data.js";
2
+ import { extractUploadHeaders } from "../utils/headers.js";
3
+ import { http } from "../utils/http.js";
4
+ import { wrapBytesWithHelpers } from "../utils/bytes.js";
5
+ import { makeTagUid } from "../utils/type.js";
6
+ const endpoint = 'bytes';
7
+ /**
8
+ * Upload data to a Bee node
9
+ *
10
+ * @param ky Ky instance
11
+ * @param data 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, data, postageBatchId, options) {
17
+ const response = await http(ky, {
18
+ path: endpoint,
19
+ method: 'post',
20
+ responseType: 'json',
21
+ body: await prepareData(data),
22
+ headers: {
23
+ 'content-type': 'application/octet-stream',
24
+ ...extractUploadHeaders(postageBatchId, options)
25
+ }
26
+ });
27
+ return {
28
+ reference: response.data.reference,
29
+ tagUid: makeTagUid(response.headers.get('swarm-tag'))
30
+ };
31
+ }
32
+ /**
33
+ * Download data as a byte array
34
+ *
35
+ * @param ky
36
+ * @param hash Bee content reference
37
+ */
38
+
39
+ export async function download(ky, hash) {
40
+ const response = await http(ky, {
41
+ responseType: 'arraybuffer',
42
+ path: `${endpoint}/${hash}`
43
+ });
44
+ return wrapBytesWithHelpers(new Uint8Array(response.data));
45
+ }
46
+ /**
47
+ * Download data as a readable stream
48
+ *
49
+ * @param ky
50
+ * @param hash Bee content reference
51
+ */
52
+
53
+ export async function downloadReadable(ky, hash) {
54
+ const response = await http(ky, {
55
+ responseType: 'stream',
56
+ path: `${endpoint}/${hash}`
57
+ });
58
+ return response.data;
59
+ }
@@ -0,0 +1,122 @@
1
+ import { extractUploadHeaders, readFileHeaders } from "../utils/headers.js";
2
+ 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
+ import { isReadable } from "../utils/stream.js";
8
+ import { makeTagUid } from "../utils/type.js";
9
+ const bzzEndpoint = 'bzz';
10
+
11
+ function extractFileUploadHeaders(postageBatchId, options) {
12
+ const headers = extractUploadHeaders(postageBatchId, options);
13
+ if (options?.size) headers['content-length'] = String(options.size);
14
+ if (options?.contentType) headers['content-type'] = options.contentType;
15
+ return headers;
16
+ }
17
+ /**
18
+ * Upload single file
19
+ *
20
+ * @param ky
21
+ * @param data Files data
22
+ * @param postageBatchId Postage BatchId that will be assigned to uploaded data
23
+ * @param name Name that will be attached to the uploaded file. Wraps the data into manifest with set index document.
24
+ * @param options
25
+ */
26
+
27
+
28
+ export async function uploadFile(ky, data, postageBatchId, name, options) {
29
+ if (isReadable(data) && !options?.contentType) {
30
+ if (!options) options = {};
31
+ options.contentType = 'application/octet-stream';
32
+ }
33
+
34
+ const response = await http(ky, {
35
+ method: 'post',
36
+ path: bzzEndpoint,
37
+ body: await prepareData(data),
38
+ headers: { ...extractFileUploadHeaders(postageBatchId, options)
39
+ },
40
+ searchParams: {
41
+ name
42
+ },
43
+ responseType: 'json'
44
+ });
45
+ return {
46
+ reference: response.data.reference,
47
+ tagUid: makeTagUid(response.headers.get('swarm-tag'))
48
+ };
49
+ }
50
+ /**
51
+ * Download single file as a buffer
52
+ *
53
+ * @param ky Ky instance for given Bee class instance
54
+ * @param hash Bee file or collection hash
55
+ * @param path If hash is collection then this defines path to a single file in the collection
56
+ */
57
+
58
+ export async function downloadFile(ky, hash, path = '') {
59
+ const response = await http(ky, {
60
+ method: 'GET',
61
+ responseType: 'arraybuffer',
62
+ path: `${bzzEndpoint}/${hash}/${path}`
63
+ });
64
+ const file = { ...readFileHeaders(response.headers),
65
+ data: wrapBytesWithHelpers(new Uint8Array(response.data))
66
+ };
67
+ return file;
68
+ }
69
+ /**
70
+ * Download single file as a readable stream
71
+ *
72
+ * @param ky Ky instance for given Bee class instance
73
+ * @param hash Bee file or collection hash
74
+ * @param path If hash is collection then this defines path to a single file in the collection
75
+ */
76
+
77
+ export async function downloadFileReadable(ky, hash, path = '') {
78
+ const response = await http(ky, {
79
+ method: 'GET',
80
+ responseType: 'stream',
81
+ path: `${bzzEndpoint}/${hash}/${path}`
82
+ });
83
+ const file = { ...readFileHeaders(response.headers),
84
+ data: response.data
85
+ };
86
+ return file;
87
+ }
88
+
89
+ function extractCollectionUploadHeaders(postageBatchId, options) {
90
+ const headers = extractUploadHeaders(postageBatchId, options);
91
+ if (options?.indexDocument) headers['swarm-index-document'] = options.indexDocument;
92
+ if (options?.errorDocument) headers['swarm-error-document'] = options.errorDocument;
93
+ return headers;
94
+ }
95
+ /**
96
+ * Upload collection
97
+ * @param ky Ky instance for given Bee class instance
98
+ * @param collection Collection of Uint8Array buffers to upload
99
+ * @param postageBatchId Postage BatchId that will be assigned to uploaded data
100
+ * @param options
101
+ */
102
+
103
+
104
+ export async function uploadCollection(ky, collection, postageBatchId, options) {
105
+ assertCollection(collection);
106
+ const tarData = makeTar(collection);
107
+ const response = await http(ky, {
108
+ method: 'post',
109
+ path: bzzEndpoint,
110
+ body: tarData,
111
+ responseType: 'json',
112
+ headers: {
113
+ 'content-type': 'application/x-tar',
114
+ 'swarm-collection': 'true',
115
+ ...extractCollectionUploadHeaders(postageBatchId, options)
116
+ }
117
+ });
118
+ return {
119
+ reference: response.data.reference,
120
+ tagUid: makeTagUid(response.headers.get('swarm-tag'))
121
+ };
122
+ }
@@ -0,0 +1,45 @@
1
+ import { extractUploadHeaders } from "../utils/headers.js";
2
+ import { http } from "../utils/http.js";
3
+ import { wrapBytesWithHelpers } from "../utils/bytes.js";
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
+
18
+ export async function upload(ky, data, postageBatchId, options) {
19
+ const response = await http(ky, {
20
+ method: 'post',
21
+ path: `${endpoint}`,
22
+ body: data,
23
+ headers: {
24
+ 'content-type': 'application/octet-stream',
25
+ ...extractUploadHeaders(postageBatchId, options)
26
+ },
27
+ responseType: 'json'
28
+ });
29
+ return response.data.reference;
30
+ }
31
+ /**
32
+ * Download chunk data as a byte array
33
+ *
34
+ * @param ky Ky instance for given Bee class instance
35
+ * @param hash Bee content reference
36
+ *
37
+ */
38
+
39
+ export async function download(ky, hash) {
40
+ const response = await http(ky, {
41
+ responseType: 'arraybuffer',
42
+ path: `${endpoint}/${hash}`
43
+ });
44
+ return wrapBytesWithHelpers(new Uint8Array(response.data));
45
+ }
@@ -0,0 +1,57 @@
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 ky Ky debug instance
8
+ */
9
+
10
+ export async function getAllBalances(ky) {
11
+ const response = await http(ky, {
12
+ path: balancesEndpoint,
13
+ responseType: 'json'
14
+ });
15
+ return response.data;
16
+ }
17
+ /**
18
+ * Get the balances with a specific peer including prepaid services
19
+ *
20
+ * @param ky Ky debug instance
21
+ * @param address Swarm address of peer
22
+ */
23
+
24
+ export async function getPeerBalance(ky, address) {
25
+ const response = await http(ky, {
26
+ path: `${balancesEndpoint}/${address}`,
27
+ responseType: 'json'
28
+ });
29
+ return response.data;
30
+ }
31
+ /**
32
+ * Get the past due consumption balances with all known peers
33
+ *
34
+ * @param ky Ky debug instance
35
+ */
36
+
37
+ export async function getPastDueConsumptionBalances(ky) {
38
+ const response = await http(ky, {
39
+ path: consumedEndpoint,
40
+ responseType: 'json'
41
+ });
42
+ return response.data;
43
+ }
44
+ /**
45
+ * Get the past due consumption balance with a specific peer
46
+ *
47
+ * @param ky Ky debug instance
48
+ * @param address Swarm address of peer
49
+ */
50
+
51
+ export async function getPastDueConsumptionPeerBalance(ky, address) {
52
+ const response = await http(ky, {
53
+ path: `${consumedEndpoint}/${address}`,
54
+ responseType: 'json'
55
+ });
56
+ return response.data;
57
+ }
@@ -0,0 +1,150 @@
1
+ import { http } from "../../utils/http.js";
2
+ const chequebookEndpoint = 'chequebook';
3
+ /**
4
+ * Get the address of the chequebook contract used
5
+ *
6
+ * @param ky Ky debug instance
7
+ */
8
+
9
+ export async function getChequebookAddress(ky) {
10
+ const response = await http(ky, {
11
+ path: chequebookEndpoint + '/address',
12
+ responseType: 'json'
13
+ });
14
+ return response.data;
15
+ }
16
+ /**
17
+ * Get the balance of the chequebook
18
+ *
19
+ * @param ky Ky debug instance
20
+ */
21
+
22
+ export async function getChequebookBalance(ky) {
23
+ const response = await http(ky, {
24
+ path: chequebookEndpoint + '/balance',
25
+ responseType: 'json'
26
+ });
27
+ return response.data;
28
+ }
29
+ /**
30
+ * Get last cashout action for the peer
31
+ *
32
+ * @param ky Ky debug instance
33
+ * @param peer Swarm address of peer
34
+ */
35
+
36
+ export async function getLastCashoutAction(ky, peer) {
37
+ const response = await http(ky, {
38
+ path: chequebookEndpoint + `/cashout/${peer}`,
39
+ responseType: 'json'
40
+ });
41
+ return response.data;
42
+ }
43
+ /**
44
+ * Cashout the last cheque for the peer
45
+ *
46
+ * @param ky Ky debug instance
47
+ * @param peer Swarm address of peer
48
+ * @param options
49
+ */
50
+
51
+ export async function cashoutLastCheque(ky, peer, options) {
52
+ const headers = {};
53
+
54
+ if (options?.gasPrice) {
55
+ headers['gas-price'] = options.gasPrice.toString();
56
+ }
57
+
58
+ if (options?.gasLimit) {
59
+ headers['gas-limit'] = options.gasLimit.toString();
60
+ }
61
+
62
+ const response = await http(ky, {
63
+ method: 'post',
64
+ path: chequebookEndpoint + `/cashout/${peer}`,
65
+ responseType: 'json',
66
+ headers
67
+ });
68
+ return response.data.transactionHash;
69
+ }
70
+ /**
71
+ * Get last cheques for the peer
72
+ *
73
+ * @param ky Ky debug instance
74
+ * @param peer Swarm address of peer
75
+ */
76
+
77
+ export async function getLastChequesForPeer(ky, peer) {
78
+ const response = await http(ky, {
79
+ path: chequebookEndpoint + `/cheque/${peer}`,
80
+ responseType: 'json'
81
+ });
82
+ return response.data;
83
+ }
84
+ /**
85
+ * Get last cheques for all peers
86
+ *
87
+ * @param ky Ky debug instance
88
+ */
89
+
90
+ export async function getLastCheques(ky) {
91
+ const response = await http(ky, {
92
+ path: chequebookEndpoint + '/cheque',
93
+ responseType: 'json'
94
+ });
95
+ return response.data;
96
+ }
97
+ /**
98
+ * Deposit tokens from overlay address into chequebook
99
+ *
100
+ * @param ky Ky debug instance
101
+ * @param amount Amount of tokens to deposit
102
+ * @param gasPrice Gas Price in WEI for the transaction call
103
+ * @return string Hash of the transaction
104
+ */
105
+
106
+ export async function depositTokens(ky, amount, gasPrice) {
107
+ const headers = {};
108
+
109
+ if (gasPrice) {
110
+ headers['gas-price'] = gasPrice.toString();
111
+ }
112
+
113
+ const response = await http(ky, {
114
+ method: 'post',
115
+ path: chequebookEndpoint + '/deposit',
116
+ responseType: 'json',
117
+ searchParams: {
118
+ amount: amount.toString(10)
119
+ },
120
+ headers
121
+ });
122
+ return response.data.transactionHash;
123
+ }
124
+ /**
125
+ * Withdraw tokens from the chequebook to the overlay address
126
+ *
127
+ * @param ky Ky debug instance
128
+ * @param amount Amount of tokens to withdraw
129
+ * @param gasPrice Gas Price in WEI for the transaction call
130
+ * @return string Hash of the transaction
131
+ */
132
+
133
+ export async function withdrawTokens(ky, amount, gasPrice) {
134
+ const headers = {};
135
+
136
+ if (gasPrice) {
137
+ headers['gas-price'] = gasPrice.toString();
138
+ }
139
+
140
+ const response = await http(ky, {
141
+ method: 'post',
142
+ path: chequebookEndpoint + '/withdraw',
143
+ responseType: 'json',
144
+ searchParams: {
145
+ amount: amount.toString(10)
146
+ },
147
+ headers
148
+ });
149
+ return response.data.transactionHash;
150
+ }
@@ -0,0 +1,35 @@
1
+ import { http } from "../../utils/http.js";
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
+
12
+ export async function checkIfChunkExistsLocally(ky, address) {
13
+ const response = await http(ky, {
14
+ path: endpoint + `/${address}`,
15
+ responseType: 'json'
16
+ });
17
+ return response.data;
18
+ }
19
+ /**
20
+ * Delete a chunk from local storage
21
+ *
22
+ * @param ky Ky debug instance
23
+ * @param address Swarm address of chunk
24
+ *
25
+ * @returns BeeGenericResponse if chunk was deleted or throws an exception
26
+ */
27
+
28
+ export async function deleteChunkFromLocalStorage(ky, address) {
29
+ const response = await http(ky, {
30
+ method: 'delete',
31
+ path: endpoint + `/${address}`,
32
+ responseType: 'json'
33
+ });
34
+ return response.data;
35
+ }
@@ -0,0 +1,45 @@
1
+ import { http } from "../../utils/http.js";
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,29 @@
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 ky Ky debug instance
7
+ * @param peer Swarm address of peer
8
+ */
9
+
10
+ export async function getSettlements(ky, peer) {
11
+ const response = await http(ky, {
12
+ path: `${settlementsEndpoint}/${peer}`,
13
+ responseType: 'json'
14
+ });
15
+ return response.data;
16
+ }
17
+ /**
18
+ * Get settlements with all known peers and total amount sent or received
19
+ *
20
+ * @param ky Ky debug instance
21
+ */
22
+
23
+ export async function getAllSettlements(ky) {
24
+ const response = await http(ky, {
25
+ path: settlementsEndpoint,
26
+ responseType: 'json'
27
+ });
28
+ return response.data;
29
+ }
@@ -0,0 +1,64 @@
1
+ import { http } from "../../utils/http.js";
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
+
30
+ if (options?.gasPrice) {
31
+ headers['gas-price'] = options.gasPrice.toString();
32
+ }
33
+
34
+ if (options?.immutableFlag !== undefined) {
35
+ headers.immutable = String(options.immutableFlag);
36
+ }
37
+
38
+ const response = await http(ky, {
39
+ method: 'post',
40
+ path: `${STAMPS_ENDPOINT}/${amount}/${depth}`,
41
+ responseType: 'json',
42
+ searchParams: {
43
+ label: options?.label
44
+ },
45
+ headers
46
+ });
47
+ return response.data.batchID;
48
+ }
49
+ export async function topUpBatch(ky, id, amount) {
50
+ const response = await http(ky, {
51
+ method: 'patch',
52
+ path: `${STAMPS_ENDPOINT}/topup/${id}/${amount}`,
53
+ responseType: 'json'
54
+ });
55
+ return response.data.batchID;
56
+ }
57
+ export async function diluteBatch(ky, id, depth) {
58
+ const response = await http(ky, {
59
+ method: 'patch',
60
+ path: `${STAMPS_ENDPOINT}/dilute/${id}/${depth}`,
61
+ responseType: 'json'
62
+ });
63
+ return response.data.batchID;
64
+ }
@@ -0,0 +1,31 @@
1
+ import { http } from "../../utils/http.js";
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
+
10
+ export async function getReserveState(ky) {
11
+ const response = await http(ky, {
12
+ method: 'get',
13
+ path: `${RESERVE_STATE_ENDPOINT}`,
14
+ responseType: 'json'
15
+ });
16
+ return response.data;
17
+ }
18
+ /**
19
+ * Get state of reserve
20
+ *
21
+ * @param ky Ky debug instance
22
+ */
23
+
24
+ export async function getChainState(ky) {
25
+ const response = await http(ky, {
26
+ method: 'get',
27
+ path: `${CHAIN_STATE_ENDPOINT}`,
28
+ responseType: 'json'
29
+ });
30
+ return response.data;
31
+ }