@ethersphere/bee-js 8.3.1 → 9.0.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 (224) hide show
  1. package/README.md +192 -50
  2. package/dist/cjs/bee-dev.js +78 -0
  3. package/dist/cjs/bee.js +341 -417
  4. package/dist/cjs/chunk/bmt.js +15 -32
  5. package/dist/cjs/chunk/cac.js +26 -36
  6. package/dist/cjs/chunk/soc.js +56 -51
  7. package/dist/cjs/feed/identifier.js +3 -28
  8. package/dist/cjs/feed/index.js +95 -44
  9. package/dist/cjs/feed/retrievable.js +11 -22
  10. package/dist/cjs/index.js +17 -1
  11. package/dist/cjs/manifest/manifest.js +369 -0
  12. package/dist/cjs/modules/bytes.js +24 -12
  13. package/dist/cjs/modules/bzz.js +24 -34
  14. package/dist/cjs/modules/chunk.js +13 -7
  15. package/dist/cjs/modules/debug/balance.js +29 -4
  16. package/dist/cjs/modules/debug/chequebook.js +60 -16
  17. package/dist/cjs/modules/debug/connectivity.js +82 -4
  18. package/dist/cjs/modules/debug/settlements.js +22 -2
  19. package/dist/cjs/modules/debug/stake.js +29 -11
  20. package/dist/cjs/modules/debug/stamps.js +88 -7
  21. package/dist/cjs/modules/debug/states.js +25 -3
  22. package/dist/cjs/modules/debug/status.js +45 -47
  23. package/dist/cjs/modules/debug/transactions.js +27 -5
  24. package/dist/cjs/modules/envelope.js +8 -6
  25. package/dist/cjs/modules/feed.js +25 -10
  26. package/dist/cjs/modules/grantee.js +18 -12
  27. package/dist/cjs/modules/gsoc.js +24 -0
  28. package/dist/cjs/modules/pinning.js +13 -2
  29. package/dist/cjs/modules/pss.js +9 -3
  30. package/dist/cjs/modules/soc.js +9 -4
  31. package/dist/cjs/modules/stewardship.js +7 -3
  32. package/dist/cjs/modules/tag.js +35 -3
  33. package/dist/cjs/package.json +1 -0
  34. package/dist/cjs/stamper/stamper.js +43 -0
  35. package/dist/cjs/types/debug.js +16 -1
  36. package/dist/cjs/types/index.js +2 -24
  37. package/dist/cjs/utils/bytes.js +67 -115
  38. package/dist/cjs/utils/chunk-size.js +17 -0
  39. package/dist/cjs/utils/chunk-stream.browser.js +85 -0
  40. package/dist/cjs/utils/chunk-stream.js +84 -0
  41. package/dist/cjs/utils/cid.js +5 -6
  42. package/dist/cjs/utils/collection.browser.js +2 -2
  43. package/dist/cjs/utils/collection.js +3 -2
  44. package/dist/cjs/utils/collection.node.js +0 -2
  45. package/dist/cjs/utils/constants.js +7 -3
  46. package/dist/cjs/utils/data.browser.js +6 -3
  47. package/dist/cjs/utils/data.js +8 -4
  48. package/dist/cjs/utils/duration.js +51 -0
  49. package/dist/cjs/utils/expose.js +11 -40
  50. package/dist/cjs/utils/headers.js +79 -52
  51. package/dist/cjs/utils/http.js +34 -10
  52. package/dist/cjs/utils/mime.js +78 -0
  53. package/dist/cjs/utils/pss.js +3 -4
  54. package/dist/cjs/utils/redundancy.js +18 -14
  55. package/dist/cjs/utils/resource-locator.js +17 -0
  56. package/dist/cjs/utils/size.js +35 -0
  57. package/dist/cjs/utils/stamps.js +67 -51
  58. package/dist/cjs/utils/tar-uploader.browser.js +2 -2
  59. package/dist/cjs/utils/tar-uploader.js +2 -2
  60. package/dist/cjs/utils/tokens.js +144 -0
  61. package/dist/cjs/utils/type.js +142 -350
  62. package/dist/cjs/utils/typed-bytes.js +179 -0
  63. package/dist/cjs/utils/upload-progress.js +2 -0
  64. package/dist/cjs/utils/url.js +0 -4
  65. package/dist/cjs/utils/workaround.js +27 -0
  66. package/dist/index.browser.min.js +1 -2
  67. package/dist/index.browser.min.js.map +1 -1
  68. package/dist/mjs/bee-dev.js +98 -0
  69. package/dist/mjs/bee.js +367 -411
  70. package/dist/mjs/chunk/bmt.js +13 -29
  71. package/dist/mjs/chunk/cac.js +26 -34
  72. package/dist/mjs/chunk/soc.js +57 -53
  73. package/dist/mjs/feed/identifier.js +3 -26
  74. package/dist/mjs/feed/index.js +98 -51
  75. package/dist/mjs/feed/retrievable.js +12 -23
  76. package/dist/mjs/index.js +10 -1
  77. package/dist/mjs/manifest/manifest.js +371 -0
  78. package/dist/mjs/modules/bytes.js +27 -15
  79. package/dist/mjs/modules/bzz.js +25 -32
  80. package/dist/mjs/modules/chunk.js +16 -8
  81. package/dist/mjs/modules/debug/balance.js +61 -4
  82. package/dist/mjs/modules/debug/chequebook.js +116 -16
  83. package/dist/mjs/modules/debug/connectivity.js +144 -3
  84. package/dist/mjs/modules/debug/settlements.js +46 -2
  85. package/dist/mjs/modules/debug/stake.js +69 -11
  86. package/dist/mjs/modules/debug/stamps.js +184 -7
  87. package/dist/mjs/modules/debug/states.js +55 -3
  88. package/dist/mjs/modules/debug/status.js +97 -45
  89. package/dist/mjs/modules/debug/transactions.js +61 -5
  90. package/dist/mjs/modules/envelope.js +11 -9
  91. package/dist/mjs/modules/feed.js +26 -10
  92. package/dist/mjs/modules/grantee.js +35 -13
  93. package/dist/mjs/modules/gsoc.js +16 -0
  94. package/dist/mjs/modules/pinning.js +23 -2
  95. package/dist/mjs/modules/pss.js +10 -4
  96. package/dist/mjs/modules/soc.js +10 -5
  97. package/dist/mjs/modules/stewardship.js +14 -4
  98. package/dist/mjs/modules/tag.js +93 -3
  99. package/dist/mjs/package.json +2 -1
  100. package/dist/mjs/stamper/stamper.js +39 -0
  101. package/dist/mjs/types/debug.js +15 -1
  102. package/dist/mjs/types/index.js +2 -24
  103. package/dist/mjs/utils/bytes.js +63 -104
  104. package/dist/mjs/utils/chunk-size.js +13 -0
  105. package/dist/mjs/utils/chunk-stream.browser.js +85 -0
  106. package/dist/mjs/utils/chunk-stream.js +87 -0
  107. package/dist/mjs/utils/cid.js +5 -6
  108. package/dist/mjs/utils/collection.browser.js +2 -2
  109. package/dist/mjs/utils/collection.js +2 -2
  110. package/dist/mjs/utils/collection.node.js +0 -2
  111. package/dist/mjs/utils/constants.js +6 -2
  112. package/dist/mjs/utils/data.browser.js +9 -3
  113. package/dist/mjs/utils/data.js +12 -4
  114. package/dist/mjs/utils/duration.js +47 -0
  115. package/dist/mjs/utils/expose.js +2 -7
  116. package/dist/mjs/utils/headers.js +73 -48
  117. package/dist/mjs/utils/http.js +33 -11
  118. package/dist/mjs/utils/mime.js +75 -0
  119. package/dist/mjs/utils/pss.js +3 -4
  120. package/dist/mjs/utils/redundancy.js +18 -8
  121. package/dist/mjs/utils/resource-locator.js +13 -0
  122. package/dist/mjs/utils/size.js +31 -0
  123. package/dist/mjs/utils/stamps.js +47 -44
  124. package/dist/mjs/utils/tar-uploader.browser.js +2 -2
  125. package/dist/mjs/utils/tar-uploader.js +2 -2
  126. package/dist/mjs/utils/tokens.js +139 -0
  127. package/dist/mjs/utils/type.js +216 -310
  128. package/dist/mjs/utils/typed-bytes.js +160 -0
  129. package/dist/mjs/utils/upload-progress.js +1 -0
  130. package/dist/mjs/utils/url.js +0 -4
  131. package/dist/mjs/utils/workaround.js +22 -0
  132. package/dist/types/bee-dev.d.ts +5 -0
  133. package/dist/types/bee.d.ts +88 -165
  134. package/dist/types/chunk/bmt.d.ts +2 -2
  135. package/dist/types/chunk/cac.d.ts +7 -24
  136. package/dist/types/chunk/soc.d.ts +15 -15
  137. package/dist/types/feed/identifier.d.ts +2 -4
  138. package/dist/types/feed/index.d.ts +14 -18
  139. package/dist/types/feed/retrievable.d.ts +3 -4
  140. package/dist/types/index.d.ts +28 -1
  141. package/dist/types/manifest/manifest.d.ts +106 -0
  142. package/dist/types/modules/bytes.d.ts +8 -5
  143. package/dist/types/modules/bzz.d.ts +8 -10
  144. package/dist/types/modules/chunk.d.ts +4 -3
  145. package/dist/types/modules/debug/balance.d.ts +3 -2
  146. package/dist/types/modules/debug/chequebook.d.ts +7 -6
  147. package/dist/types/modules/debug/connectivity.d.ts +5 -3
  148. package/dist/types/modules/debug/settlements.d.ts +2 -1
  149. package/dist/types/modules/debug/stake.d.ts +4 -2
  150. package/dist/types/modules/debug/stamps.d.ts +5 -4
  151. package/dist/types/modules/debug/status.d.ts +6 -25
  152. package/dist/types/modules/debug/transactions.d.ts +5 -4
  153. package/dist/types/modules/envelope.d.ts +3 -2
  154. package/dist/types/modules/feed.d.ts +20 -16
  155. package/dist/types/modules/grantee.d.ts +7 -6
  156. package/dist/types/modules/gsoc.d.ts +7 -0
  157. package/dist/types/modules/pinning.d.ts +2 -4
  158. package/dist/types/modules/pss.d.ts +4 -3
  159. package/dist/types/modules/soc.d.ts +3 -2
  160. package/dist/types/modules/stewardship.d.ts +4 -4
  161. package/dist/types/modules/tag.d.ts +2 -1
  162. package/dist/types/stamper/stamper.d.ts +15 -0
  163. package/dist/types/types/debug.d.ts +63 -115
  164. package/dist/types/types/index.d.ts +103 -204
  165. package/dist/types/utils/bytes.d.ts +16 -90
  166. package/dist/types/utils/chunk-size.d.ts +1 -0
  167. package/dist/types/utils/chunk-stream.browser.d.ts +6 -0
  168. package/dist/types/utils/chunk-stream.d.ts +6 -0
  169. package/dist/types/utils/cid.d.ts +3 -2
  170. package/dist/types/utils/collection.browser.d.ts +2 -2
  171. package/dist/types/utils/collection.d.ts +2 -1
  172. package/dist/types/utils/collection.node.d.ts +0 -1
  173. package/dist/types/utils/constants.d.ts +4 -1
  174. package/dist/types/utils/duration.d.ts +17 -0
  175. package/dist/types/utils/error.d.ts +2 -2
  176. package/dist/types/utils/expose.d.ts +2 -7
  177. package/dist/types/utils/headers.d.ts +3 -4
  178. package/dist/types/utils/mime.d.ts +1 -0
  179. package/dist/types/utils/pss.d.ts +2 -2
  180. package/dist/types/utils/resource-locator.d.ts +6 -0
  181. package/dist/types/utils/size.d.ts +16 -0
  182. package/dist/types/utils/stamps.d.ts +27 -33
  183. package/dist/types/utils/tar-uploader.browser.d.ts +3 -4
  184. package/dist/types/utils/tar-uploader.d.ts +3 -4
  185. package/dist/types/utils/tokens.d.ts +77 -0
  186. package/dist/types/utils/type.d.ts +20 -52
  187. package/dist/types/utils/typed-bytes.d.ts +68 -0
  188. package/dist/types/utils/upload-progress.d.ts +4 -0
  189. package/dist/types/utils/workaround.d.ts +2 -0
  190. package/package.json +11 -17
  191. package/dist/cjs/chunk/signer.js +0 -126
  192. package/dist/cjs/chunk/span.js +0 -25
  193. package/dist/cjs/feed/json.js +0 -28
  194. package/dist/cjs/feed/topic.js +0 -25
  195. package/dist/cjs/feed/type.js +0 -15
  196. package/dist/cjs/modules/debug/chunk.js +0 -21
  197. package/dist/cjs/modules/debug/tag.js +0 -19
  198. package/dist/cjs/utils/eth.js +0 -216
  199. package/dist/cjs/utils/hash.js +0 -21
  200. package/dist/cjs/utils/hex.js +0 -150
  201. package/dist/cjs/utils/reference.js +0 -36
  202. package/dist/index.browser.min.js.LICENSE.txt +0 -8
  203. package/dist/mjs/chunk/signer.js +0 -114
  204. package/dist/mjs/chunk/span.js +0 -21
  205. package/dist/mjs/feed/json.js +0 -26
  206. package/dist/mjs/feed/topic.js +0 -19
  207. package/dist/mjs/feed/type.js +0 -10
  208. package/dist/mjs/modules/debug/chunk.js +0 -17
  209. package/dist/mjs/modules/debug/tag.js +0 -15
  210. package/dist/mjs/utils/eth.js +0 -192
  211. package/dist/mjs/utils/hash.js +0 -16
  212. package/dist/mjs/utils/hex.js +0 -135
  213. package/dist/mjs/utils/reference.js +0 -29
  214. package/dist/types/chunk/signer.d.ts +0 -31
  215. package/dist/types/chunk/span.d.ts +0 -10
  216. package/dist/types/feed/json.d.ts +0 -4
  217. package/dist/types/feed/topic.d.ts +0 -3
  218. package/dist/types/feed/type.d.ts +0 -6
  219. package/dist/types/modules/debug/chunk.d.ts +0 -10
  220. package/dist/types/modules/debug/tag.d.ts +0 -8
  221. package/dist/types/utils/eth.d.ts +0 -67
  222. package/dist/types/utils/hash.d.ts +0 -9
  223. package/dist/types/utils/hex.d.ts +0 -86
  224. package/dist/types/utils/reference.d.ts +0 -2
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.marshalStamp = exports.convertEnvelopeToMarshaledStamp = exports.getDepthForCapacity = exports.getAmountForTtl = exports.getStampTtlSeconds = exports.getStampCostInBzz = exports.getStampCostInPlur = exports.getStampEffectiveBytes = exports.getStampMaximumCapacityBytes = exports.getStampUsage = void 0;
3
+ exports.marshalStamp = exports.convertEnvelopeToMarshaledStamp = exports.getDepthForSize = exports.getAmountForDuration = exports.getStampDuration = exports.getStampCost = exports.getStampEffectiveBytesBreakpoints = exports.getStampEffectiveBytes = exports.getStampTheoreticalBytes = exports.getStampUsage = void 0;
4
4
  const cafe_utility_1 = require("cafe-utility");
5
+ const bytes_1 = require("./bytes");
6
+ const duration_1 = require("./duration");
7
+ const tokens_1 = require("./tokens");
8
+ const type_1 = require("./type");
5
9
  /**
6
10
  * Utility function that calculates usage of postage batch based on its utilization, depth and bucket depth.
7
11
  *
@@ -14,16 +18,16 @@ function getStampUsage(utilization, depth, bucketDepth) {
14
18
  }
15
19
  exports.getStampUsage = getStampUsage;
16
20
  /**
17
- * Utility function that calculates the theoritical maximum capacity of a postage batch based on its depth.
21
+ * Utility function that calculates the theoritical maximum size of a postage batch based on its depth.
18
22
  *
19
- * For smaller depths (up to 20), this may provide less accurate results.
23
+ * For smaller depths (up to 22), this may provide less accurate results.
20
24
  *
21
- * @returns {number} The maximum capacity of the postage batch in bytes.
25
+ * @returns {number} The maximum theoretical size of the postage batch in bytes.
22
26
  */
23
- function getStampMaximumCapacityBytes(depth) {
24
- return 2 ** depth * 4096;
27
+ function getStampTheoreticalBytes(depth) {
28
+ return 4096 * 2 ** depth;
25
29
  }
26
- exports.getStampMaximumCapacityBytes = getStampMaximumCapacityBytes;
30
+ exports.getStampTheoreticalBytes = getStampTheoreticalBytes;
27
31
  /**
28
32
  * Based on https://docs.ethswarm.org/docs/learn/technology/contracts/postage-stamp/#effective-utilisation-table
29
33
  */
@@ -42,86 +46,98 @@ const utilisationRateMap = {
42
46
  33: 0.9842,
43
47
  34: 0.9889,
44
48
  };
49
+ const effectiveSizeBreakpoints = [
50
+ [22, 4.93],
51
+ [23, 17.03],
52
+ [24, 44.21],
53
+ [25, 102.78],
54
+ [26, 225.87],
55
+ [27, 480.44],
56
+ [28, 1001.44],
57
+ [29, 2060.27],
58
+ [30, 4201.9],
59
+ [31, 8519.02],
60
+ [32, 17199.89],
61
+ [33, 34628.46],
62
+ ];
45
63
  /**
46
- * Utility function that calculates the effective volume of a postage batch based on its depth.
64
+ * Utility function that calculates the effective size of a postage batch based on its depth.
47
65
  *
48
- * Below 22 depth the effective volume is 0
66
+ * Below 22 depth the effective size is 0
49
67
  * Above 34 it's always > 99%
50
68
  *
51
- * @returns {number} The effective volume of the postage batch in bytes.
69
+ * @returns {number} The effective size of the postage batch in bytes.
52
70
  */
53
71
  function getStampEffectiveBytes(depth) {
54
72
  if (depth < 22) {
55
73
  return 0;
56
74
  }
57
75
  const utilRate = utilisationRateMap[depth] ?? 0.99;
58
- return getStampMaximumCapacityBytes(depth) * utilRate;
76
+ return Math.ceil(getStampTheoreticalBytes(depth) * utilRate);
59
77
  }
60
78
  exports.getStampEffectiveBytes = getStampEffectiveBytes;
61
- /**
62
- * Utility function that calculates the cost of a postage batch based on its depth and amount.
63
- *
64
- * @returns {number} The cost of the postage batch in PLUR (10000000000000000 [1e16] PLUR = 1 BZZ)
65
- */
66
- function getStampCostInPlur(depth, amount) {
67
- return 2 ** depth * amount;
79
+ function getStampEffectiveBytesBreakpoints() {
80
+ const map = new Map();
81
+ for (let i = 22; i < 35; i++) {
82
+ map.set(i, getStampEffectiveBytes(i));
83
+ }
84
+ return map;
68
85
  }
69
- exports.getStampCostInPlur = getStampCostInPlur;
86
+ exports.getStampEffectiveBytesBreakpoints = getStampEffectiveBytesBreakpoints;
70
87
  /**
71
88
  * Utility function that calculates the cost of a postage batch based on its depth and amount.
72
- *
73
- * @returns {number} The cost of the postage batch in BZZ (1 BZZ = 10000000000000000 [1e16] PLUR)
74
89
  */
75
- function getStampCostInBzz(depth, amount) {
76
- const BZZ_UNIT = 10 ** 16;
77
- return getStampCostInPlur(depth, amount) / BZZ_UNIT;
90
+ function getStampCost(depth, amount) {
91
+ return tokens_1.BZZ.fromPLUR(2n ** BigInt(depth) * BigInt(amount));
78
92
  }
79
- exports.getStampCostInBzz = getStampCostInBzz;
93
+ exports.getStampCost = getStampCost;
80
94
  /**
81
95
  * Utility function that calculates the TTL of a postage batch based on its amount, price per block and block time.
82
96
  *
83
97
  * For more accurate results, get the price per block and block time from the Bee node or the blockchain.
84
98
  *
85
- * @returns {number} The TTL of the postage batch in seconds.
99
+ * @returns {number} The TTL of the postage batch.
86
100
  */
87
- function getStampTtlSeconds(amount, pricePerBlock = 24000, blockTime = 5) {
88
- return (amount * blockTime) / pricePerBlock;
101
+ function getStampDuration(amount, pricePerBlock, blockTime = 5) {
102
+ const amountBigInt = BigInt((0, type_1.asNumberString)(amount));
103
+ return duration_1.Duration.fromSeconds(Number((amountBigInt * BigInt(blockTime)) / BigInt(pricePerBlock)));
89
104
  }
90
- exports.getStampTtlSeconds = getStampTtlSeconds;
105
+ exports.getStampDuration = getStampDuration;
91
106
  /**
92
- * Utility function that calculates the amount of tokens required to maintain a given Time To Live (TTL) for a postage batch.
93
- *
94
- * This function estimates the required amount based on the provided TTL in days.
107
+ * Get the postage batch `amount` required for a given `duration`.
95
108
  *
96
- * @param {number} days - The Time To Live (TTL) in days.
97
- * @returns {NumberString} The estimated amount of tokens needed for the specified TTL.
109
+ * @param duration A duration object representing the duration of the storage.
110
+ * @param pricePerBlock The price per block in PLUR.
111
+ * @param blockTime The block time in seconds.
98
112
  */
99
- function getAmountForTtl(days) {
100
- // 414720000 = (24 * 60 * 60 * 24_000) / 5
101
- return ((days <= 0 ? 1 : days) * 414720000).toString();
113
+ function getAmountForDuration(duration, pricePerBlock, blockTime = 5) {
114
+ return (BigInt(duration.toSeconds()) / BigInt(blockTime)) * BigInt(pricePerBlock);
102
115
  }
103
- exports.getAmountForTtl = getAmountForTtl;
116
+ exports.getAmountForDuration = getAmountForDuration;
104
117
  /**
105
- * Utility function that calculates the depth required for a postage batch to achieve the specified capacity in gigabytes.
118
+ * Utility function that calculates the depth required for a postage batch to achieve the specified effective size
106
119
  *
107
- * The depth is determined based on the given gigabytes, and the result is adjusted to a minimum depth of 18.
108
- *
109
- * @param {number} gigabytes - The desired capacity of the postage batch in gigabytes.
110
- * @returns {number} The calculated depth necessary to achieve the specified capacity.
120
+ * @param size The effective size of the postage batch
121
+ * @returns
111
122
  */
112
- function getDepthForCapacity(gigabytes) {
113
- return gigabytes <= 1 ? 18 : Math.ceil(Math.log2(Math.ceil(gigabytes)) + 18);
123
+ function getDepthForSize(size) {
124
+ for (const [depth, sizeBreakpoint] of effectiveSizeBreakpoints) {
125
+ if (size.toGigabytes() <= sizeBreakpoint) {
126
+ return depth;
127
+ }
128
+ }
129
+ return 34;
114
130
  }
115
- exports.getDepthForCapacity = getDepthForCapacity;
116
- function convertEnvelopeToMarshaledStamp(batchID, envelope) {
117
- return marshalStamp(envelope.signature, cafe_utility_1.Binary.hexToUint8Array(batchID), envelope.timestamp, envelope.index);
131
+ exports.getDepthForSize = getDepthForSize;
132
+ function convertEnvelopeToMarshaledStamp(envelope) {
133
+ return marshalStamp(envelope.signature, envelope.batchId.toUint8Array(), envelope.timestamp, envelope.index);
118
134
  }
119
135
  exports.convertEnvelopeToMarshaledStamp = convertEnvelopeToMarshaledStamp;
120
- function marshalStamp(signature, batchID, timestamp, index) {
136
+ function marshalStamp(signature, batchId, timestamp, index) {
121
137
  if (signature.length !== 65) {
122
138
  throw Error('invalid signature length');
123
139
  }
124
- if (batchID.length !== 32) {
140
+ if (batchId.length !== 32) {
125
141
  throw Error('invalid batch ID length');
126
142
  }
127
143
  if (timestamp.length !== 8) {
@@ -130,6 +146,6 @@ function marshalStamp(signature, batchID, timestamp, index) {
130
146
  if (index.length !== 8) {
131
147
  throw Error('invalid index length');
132
148
  }
133
- return cafe_utility_1.Binary.concatBytes(batchID, index, timestamp, signature);
149
+ return new bytes_1.Bytes(cafe_utility_1.Binary.concatBytes(batchId, index, timestamp, signature));
134
150
  }
135
151
  exports.marshalStamp = marshalStamp;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.uploadTar = void 0;
4
- const bzz_1 = require("../modules/bzz");
4
+ const headers_1 = require("./headers");
5
5
  const http_1 = require("./http");
6
6
  const tar_1 = require("./tar");
7
7
  const tar_writer_1 = require("./tar-writer");
@@ -18,7 +18,7 @@ async function uploadTar(requestOptions, collection, postageBatchId, options) {
18
18
  headers: {
19
19
  'content-type': 'application/x-tar',
20
20
  'swarm-collection': 'true',
21
- ...(0, bzz_1.extractCollectionUploadHeaders)(postageBatchId, options),
21
+ ...(0, headers_1.prepareRequestHeaders)(postageBatchId, options),
22
22
  },
23
23
  });
24
24
  return response;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.uploadTar = void 0;
4
- const bzz_1 = require("../modules/bzz");
4
+ const headers_1 = require("./headers");
5
5
  const http_1 = require("./http");
6
6
  const tar_1 = require("./tar");
7
7
  const tar_writer_1 = require("./tar-writer");
@@ -16,7 +16,7 @@ async function uploadTar(requestOptions, collection, postageBatchId, options) {
16
16
  headers: {
17
17
  'content-type': 'application/x-tar',
18
18
  'swarm-collection': 'true',
19
- ...(0, bzz_1.extractCollectionUploadHeaders)(postageBatchId, options),
19
+ ...(0, headers_1.prepareRequestHeaders)(postageBatchId, options),
20
20
  },
21
21
  });
22
22
  await (0, tar_writer_1.writeTar)(collection, tarStream);
@@ -0,0 +1,144 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DAI = exports.BZZ = void 0;
4
+ const cafe_utility_1 = require("cafe-utility");
5
+ class BZZ {
6
+ constructor(state) {
7
+ this.state = state;
8
+ }
9
+ static fromDecimalString(string) {
10
+ return new BZZ(cafe_utility_1.FixedPointNumber.fromDecimalString(string, BZZ.DIGITS));
11
+ }
12
+ static fromPLUR(plur) {
13
+ return new BZZ(new cafe_utility_1.FixedPointNumber(plur, BZZ.DIGITS));
14
+ }
15
+ toPLURString() {
16
+ return this.state.toString();
17
+ }
18
+ toPLURBigInt() {
19
+ return this.state.value;
20
+ }
21
+ toDecimalString() {
22
+ return this.state.toDecimalString();
23
+ }
24
+ toSignificantDigits(digits) {
25
+ return this.toDecimalString().slice(0, this.toDecimalString().indexOf('.') + digits + 1);
26
+ }
27
+ /**
28
+ * Does not mutate the current BZZ instance.
29
+ *
30
+ * @param other BZZ instance, or amount in PLUR
31
+ * @returns New BZZ instance
32
+ */
33
+ plus(other) {
34
+ return new BZZ(this.state.add(other instanceof BZZ ? other.state : new cafe_utility_1.FixedPointNumber(other, BZZ.DIGITS)));
35
+ }
36
+ /**
37
+ * Does not mutate the current BZZ instance.
38
+ *
39
+ * @param other BZZ instance, or amount in PLUR
40
+ * @returns New BZZ instance
41
+ */
42
+ minus(other) {
43
+ return new BZZ(this.state.subtract(other instanceof BZZ ? other.state : new cafe_utility_1.FixedPointNumber(other, BZZ.DIGITS)));
44
+ }
45
+ /**
46
+ * Does not mutate the current BZZ instance.
47
+ *
48
+ * @param other Divisor
49
+ * @returns New BZZ instance
50
+ */
51
+ divide(other) {
52
+ return new BZZ(this.state.divmod(other)[0]);
53
+ }
54
+ gt(other) {
55
+ return this.state.compare(other.state) === 1;
56
+ }
57
+ gte(other) {
58
+ return this.state.compare(other.state) !== -1;
59
+ }
60
+ lt(other) {
61
+ return this.state.compare(other.state) === -1;
62
+ }
63
+ lte(other) {
64
+ return this.state.compare(other.state) !== 1;
65
+ }
66
+ eq(other) {
67
+ return this.state.compare(other.state) === 0;
68
+ }
69
+ exchangeToDAI(daiPerBzz) {
70
+ return DAI.fromWei(this.state.exchange('*', new cafe_utility_1.FixedPointNumber(daiPerBzz.toWeiBigInt(), DAI.DIGITS), DAI.DIGITS).value);
71
+ }
72
+ }
73
+ exports.BZZ = BZZ;
74
+ BZZ.DIGITS = 16;
75
+ class DAI {
76
+ constructor(state) {
77
+ this.state = state;
78
+ }
79
+ static fromDecimalString(string) {
80
+ return new DAI(cafe_utility_1.FixedPointNumber.fromDecimalString(string, DAI.DIGITS));
81
+ }
82
+ static fromWei(wei) {
83
+ return new DAI(new cafe_utility_1.FixedPointNumber(wei, DAI.DIGITS));
84
+ }
85
+ toWeiString() {
86
+ return this.state.toString();
87
+ }
88
+ toWeiBigInt() {
89
+ return this.state.value;
90
+ }
91
+ toDecimalString() {
92
+ return this.state.toDecimalString();
93
+ }
94
+ toSignificantDigits(digits) {
95
+ return this.toDecimalString().slice(0, this.toDecimalString().indexOf('.') + digits + 1);
96
+ }
97
+ /**
98
+ * Does not mutate the current DAI instance.
99
+ *
100
+ * @param other DAI instance, or amount in PLUR
101
+ * @returns New DAI instance
102
+ */
103
+ plus(other) {
104
+ return new DAI(this.state.add(other instanceof DAI ? other.state : new cafe_utility_1.FixedPointNumber(other, DAI.DIGITS)));
105
+ }
106
+ /**
107
+ * Does not mutate the current DAI instance.
108
+ *
109
+ * @param other DAI instance, or amount in PLUR
110
+ * @returns New DAI instance
111
+ */
112
+ minus(other) {
113
+ return new DAI(this.state.subtract(other instanceof DAI ? other.state : new cafe_utility_1.FixedPointNumber(other, DAI.DIGITS)));
114
+ }
115
+ /**
116
+ * Does not mutate the current DAI instance.
117
+ *
118
+ * @param other Divisor
119
+ * @returns New DAI instance
120
+ */
121
+ divide(other) {
122
+ return new DAI(this.state.divmod(other)[0]);
123
+ }
124
+ gt(other) {
125
+ return this.state.compare(other.state) === 1;
126
+ }
127
+ gte(other) {
128
+ return this.state.compare(other.state) !== -1;
129
+ }
130
+ lt(other) {
131
+ return this.state.compare(other.state) === -1;
132
+ }
133
+ lte(other) {
134
+ return this.state.compare(other.state) !== 1;
135
+ }
136
+ eq(other) {
137
+ return this.state.compare(other.state) === 0;
138
+ }
139
+ exchangeToBZZ(daiPerBzz) {
140
+ return BZZ.fromPLUR(this.state.exchange('/', new cafe_utility_1.FixedPointNumber(daiPerBzz.toWeiBigInt(), DAI.DIGITS), BZZ.DIGITS).value);
141
+ }
142
+ }
143
+ exports.DAI = DAI;
144
+ DAI.DIGITS = 18;