@ethersphere/bee-js 6.2.0 → 6.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.
@@ -1,9 +1,9 @@
1
1
  export { getCollectionSize } from "./collection.js";
2
2
  export { getFolderSize } from "./collection.node.js";
3
- export { isBytes, assertBytes, isFlexBytes, assertFlexBytes, bytesAtOffset, flexBytesAtOffset, bytesEqual } from "./bytes.js";
4
- export { makeHexString, hexToBytes, bytesToHex, intToHex, isHexString, assertHexString, assertPrefixedHexString } from "./hex.js";
5
- export { makeEthAddress, makeHexEthAddress, isHexEthAddress, ethToSwarmAddress, toLittleEndian, fromLittleEndian, makeEthereumWalletSigner } from "./eth.js";
6
- export { readableWebToNode, readableNodeToWeb, isReadableStream, isNodeReadable, normalizeToReadableStream, isReadable } from "./stream.js";
3
+ export { assertBytes, assertFlexBytes, bytesAtOffset, bytesEqual, flexBytesAtOffset, isBytes, isFlexBytes } from "./bytes.js";
4
+ export { assertHexString, assertPrefixedHexString, bytesToHex, hexToBytes, intToHex, isHexString, makeHexString } from "./hex.js";
5
+ export { ethToSwarmAddress, fromLittleEndian, isHexEthAddress, makeEthAddress, makeEthereumWalletSigner, makeHexEthAddress, toLittleEndian } from "./eth.js";
6
+ export { isNodeReadable, isReadable, isReadableStream, normalizeToReadableStream, readableNodeToWeb, readableWebToNode } from "./stream.js";
7
7
  export { keccak256Hash } from "./hash.js";
8
8
  export { makeMaxTarget } from "./pss.js";
9
- export { getStampUsage } from "./stamps.js";
9
+ export { getStampCostInBzz, getStampCostInPlur, getStampMaximumCapacityBytes, getStampTtlSeconds, getStampUsage } from "./stamps.js";
@@ -1,17 +1,47 @@
1
1
  /**
2
2
  * Utility function that calculates usage of postage batch based on its utilization, depth and bucket depth.
3
3
  *
4
- * Be aware for small depths (17, 18) this does not provide that much information as the provided set of distinct values
5
- * is small.
4
+ * For smaller depths (up to 20), this may provide less accurate results.
6
5
  *
7
- * @param utilization
8
- * @param depth
9
- * @param bucketDepth
6
+ * @returns {number} A number between 0 and 1 representing the usage of the postage batch.
10
7
  */
11
- export function getStampUsage({
12
- utilization,
13
- depth,
14
- bucketDepth
15
- }) {
8
+ export function getStampUsage(utilization, depth, bucketDepth) {
16
9
  return utilization / Math.pow(2, depth - bucketDepth);
10
+ }
11
+ /**
12
+ * Utility function that calculates the theoritical maximum capacity of a postage batch based on its depth.
13
+ *
14
+ * For smaller depths (up to 20), this may provide less accurate results.
15
+ *
16
+ * @returns {number} The maximum capacity of the postage batch in bytes.
17
+ */
18
+ export function getStampMaximumCapacityBytes(depth) {
19
+ return 2 ** depth * 4096;
20
+ }
21
+ /**
22
+ * Utility function that calculates the cost of a postage batch based on its depth and amount.
23
+ *
24
+ * @returns {number} The cost of the postage batch in PLUR (10000000000000000 [1e16] PLUR = 1 BZZ)
25
+ */
26
+ export function getStampCostInPlur(depth, amount) {
27
+ return 2 ** depth * amount;
28
+ }
29
+ /**
30
+ * Utility function that calculates the cost of a postage batch based on its depth and amount.
31
+ *
32
+ * @returns {number} The cost of the postage batch in BZZ (1 BZZ = 10000000000000000 [1e16] PLUR)
33
+ */
34
+ export function getStampCostInBzz(depth, amount) {
35
+ const BZZ_UNIT = 10 ** 16;
36
+ return getStampCostInPlur(depth, amount) / BZZ_UNIT;
37
+ }
38
+ /**
39
+ * Utility function that calculates the TTL of a postage batch based on its amount, price per block and block time.
40
+ *
41
+ * For more accurate results, get the price per block and block time from the Bee node or the blockchain.
42
+ *
43
+ * @returns {number} The TTL of the postage batch in seconds.
44
+ */
45
+ export function getStampTtlSeconds(amount, pricePerBlock = 24000, blockTime = 5) {
46
+ return amount * blockTime / pricePerBlock;
17
47
  }
@@ -1,9 +1,9 @@
1
1
  export { getCollectionSize } from './collection';
2
2
  export { getFolderSize } from './collection.node';
3
- export { Bytes, FlexBytes, isBytes, assertBytes, isFlexBytes, assertFlexBytes, bytesAtOffset, flexBytesAtOffset, bytesEqual, } from './bytes';
4
- export { HexString, PrefixedHexString, makeHexString, hexToBytes, bytesToHex, intToHex, isHexString, assertHexString, assertPrefixedHexString, } from './hex';
5
- export { EthAddress, makeEthAddress, makeHexEthAddress, isHexEthAddress, ethToSwarmAddress, toLittleEndian, fromLittleEndian, makeEthereumWalletSigner, } from './eth';
6
- export { readableWebToNode, readableNodeToWeb, isReadableStream, isNodeReadable, normalizeToReadableStream, isReadable, } from './stream';
3
+ export { Bytes, FlexBytes, assertBytes, assertFlexBytes, bytesAtOffset, bytesEqual, flexBytesAtOffset, isBytes, isFlexBytes, } from './bytes';
4
+ export { HexString, PrefixedHexString, assertHexString, assertPrefixedHexString, bytesToHex, hexToBytes, intToHex, isHexString, makeHexString, } from './hex';
5
+ export { EthAddress, ethToSwarmAddress, fromLittleEndian, isHexEthAddress, makeEthAddress, makeEthereumWalletSigner, makeHexEthAddress, toLittleEndian, } from './eth';
6
+ export { isNodeReadable, isReadable, isReadableStream, normalizeToReadableStream, readableNodeToWeb, readableWebToNode, } from './stream';
7
7
  export { keccak256Hash } from './hash';
8
8
  export { makeMaxTarget } from './pss';
9
- export { getStampUsage } from './stamps';
9
+ export { getStampCostInBzz, getStampCostInPlur, getStampMaximumCapacityBytes, getStampTtlSeconds, getStampUsage, } from './stamps';
@@ -1,12 +1,36 @@
1
- import { PostageBatch } from '../types';
2
1
  /**
3
2
  * Utility function that calculates usage of postage batch based on its utilization, depth and bucket depth.
4
3
  *
5
- * Be aware for small depths (17, 18) this does not provide that much information as the provided set of distinct values
6
- * is small.
4
+ * For smaller depths (up to 20), this may provide less accurate results.
7
5
  *
8
- * @param utilization
9
- * @param depth
10
- * @param bucketDepth
6
+ * @returns {number} A number between 0 and 1 representing the usage of the postage batch.
11
7
  */
12
- export declare function getStampUsage({ utilization, depth, bucketDepth }: PostageBatch): number;
8
+ export declare function getStampUsage(utilization: number, depth: number, bucketDepth: number): number;
9
+ /**
10
+ * Utility function that calculates the theoritical maximum capacity of a postage batch based on its depth.
11
+ *
12
+ * For smaller depths (up to 20), this may provide less accurate results.
13
+ *
14
+ * @returns {number} The maximum capacity of the postage batch in bytes.
15
+ */
16
+ export declare function getStampMaximumCapacityBytes(depth: number): number;
17
+ /**
18
+ * Utility function that calculates the cost of a postage batch based on its depth and amount.
19
+ *
20
+ * @returns {number} The cost of the postage batch in PLUR (10000000000000000 [1e16] PLUR = 1 BZZ)
21
+ */
22
+ export declare function getStampCostInPlur(depth: number, amount: number): number;
23
+ /**
24
+ * Utility function that calculates the cost of a postage batch based on its depth and amount.
25
+ *
26
+ * @returns {number} The cost of the postage batch in BZZ (1 BZZ = 10000000000000000 [1e16] PLUR)
27
+ */
28
+ export declare function getStampCostInBzz(depth: number, amount: number): number;
29
+ /**
30
+ * Utility function that calculates the TTL of a postage batch based on its amount, price per block and block time.
31
+ *
32
+ * For more accurate results, get the price per block and block time from the Bee node or the blockchain.
33
+ *
34
+ * @returns {number} The TTL of the postage batch in seconds.
35
+ */
36
+ export declare function getStampTtlSeconds(amount: number, pricePerBlock?: number, blockTime?: number): number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ethersphere/bee-js",
3
- "version": "6.2.0",
3
+ "version": "6.3.0",
4
4
  "description": "Javascript client for Bee",
5
5
  "keywords": [
6
6
  "bee",