@ethersphere/bee-js 9.0.2 → 9.1.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.
package/dist/mjs/bee.js CHANGED
@@ -58,6 +58,7 @@ export class Bee {
58
58
  if (options?.signer) {
59
59
  this.signer = new PrivateKey(options.signer);
60
60
  }
61
+ this.network = options?.network ?? 'gnosis';
61
62
  this.requestOptions = {
62
63
  baseURL: this.url,
63
64
  timeout: options?.timeout ?? 0,
@@ -1147,7 +1148,7 @@ export class Bee {
1147
1148
  }
1148
1149
  async buyStorage(size, duration, options, requestOptions) {
1149
1150
  const chainState = await this.getChainState(requestOptions);
1150
- const amount = getAmountForDuration(duration, chainState.currentPrice);
1151
+ const amount = getAmountForDuration(duration, chainState.currentPrice, this.network === 'gnosis' ? 5 : 15);
1151
1152
  const depth = getDepthForSize(size);
1152
1153
  if (options) {
1153
1154
  options = preparePostageBatchOptions(options);
@@ -1156,7 +1157,7 @@ export class Bee {
1156
1157
  }
1157
1158
  async getStorageCost(size, duration, options) {
1158
1159
  const chainState = await this.getChainState(options);
1159
- const amount = getAmountForDuration(duration, chainState.currentPrice);
1160
+ const amount = getAmountForDuration(duration, chainState.currentPrice, this.network === 'gnosis' ? 5 : 15);
1160
1161
  const depth = getDepthForSize(size);
1161
1162
  return getStampCost(depth, amount);
1162
1163
  }
@@ -1173,13 +1174,13 @@ export class Bee {
1173
1174
  async extendStorageDuration(postageBatchId, duration, options) {
1174
1175
  const batch = await this.getPostageBatch(postageBatchId, options);
1175
1176
  const chainState = await this.getChainState(options);
1176
- const amount = getAmountForDuration(duration, chainState.currentPrice);
1177
+ const amount = getAmountForDuration(duration, chainState.currentPrice, this.network === 'gnosis' ? 5 : 15);
1177
1178
  return this.topUpBatch(batch.batchID, amount, options);
1178
1179
  }
1179
1180
  async getExtensionCost(postageBatchId, size, duration, options) {
1180
1181
  const batch = await this.getPostageBatch(postageBatchId, options);
1181
1182
  const chainState = await this.getChainState(options);
1182
- const amount = getAmountForDuration(duration, chainState.currentPrice);
1183
+ const amount = getAmountForDuration(duration, chainState.currentPrice, this.network === 'gnosis' ? 5 : 15);
1183
1184
  const depth = getDepthForSize(size);
1184
1185
  const currentValue = getStampCost(batch.depth, batch.amount);
1185
1186
  const newValue = getStampCost(depth, amount);
@@ -1199,7 +1200,7 @@ export class Bee {
1199
1200
  async getDurationExtensionCost(postageBatchId, duration, options) {
1200
1201
  const batch = await this.getPostageBatch(postageBatchId, options);
1201
1202
  const chainState = await this.getChainState(options);
1202
- const amount = getAmountForDuration(duration, chainState.currentPrice);
1203
+ const amount = getAmountForDuration(duration, chainState.currentPrice, this.network === 'gnosis' ? 5 : 15);
1203
1204
  return getStampCost(batch.depth, amount);
1204
1205
  }
1205
1206
  /**
@@ -80,7 +80,8 @@ export function makeFeedReader(requestOptions, topic, owner) {
80
80
  const feedIndex = typeof options.index === 'number' ? FeedIndex.fromBigInt(BigInt(options.index)) : options.index;
81
81
  return {
82
82
  payload: update.payload,
83
- feedIndex
83
+ feedIndex,
84
+ feedIndexNext: feedIndex.next()
84
85
  };
85
86
  };
86
87
  const downloadPayload = async options => {
@@ -92,7 +93,8 @@ export function makeFeedReader(requestOptions, topic, owner) {
92
93
  const feedIndex = typeof options.index === 'number' ? FeedIndex.fromBigInt(BigInt(options.index)) : options.index;
93
94
  return {
94
95
  payload,
95
- feedIndex
96
+ feedIndex,
97
+ feedIndexNext: feedIndex.next()
96
98
  };
97
99
  };
98
100
  const downloadReference = async options => {
@@ -106,7 +108,8 @@ export function makeFeedReader(requestOptions, topic, owner) {
106
108
  });
107
109
  return {
108
110
  reference: new Reference(payload.payload.toUint8Array()),
109
- feedIndex: payload.feedIndex
111
+ feedIndex: payload.feedIndex,
112
+ feedIndexNext: payload.feedIndexNext ?? payload.feedIndex.next()
110
113
  };
111
114
  };
112
115
  return {
@@ -77,7 +77,7 @@ export function getStampCost(depth, amount) {
77
77
  *
78
78
  * @returns {number} The TTL of the postage batch.
79
79
  */
80
- export function getStampDuration(amount, pricePerBlock, blockTime = 5) {
80
+ export function getStampDuration(amount, pricePerBlock, blockTime) {
81
81
  const amountBigInt = BigInt(asNumberString(amount));
82
82
  return Duration.fromSeconds(Number(amountBigInt * BigInt(blockTime) / BigInt(pricePerBlock)));
83
83
  }
@@ -88,7 +88,7 @@ export function getStampDuration(amount, pricePerBlock, blockTime = 5) {
88
88
  * @param pricePerBlock The price per block in PLUR.
89
89
  * @param blockTime The block time in seconds.
90
90
  */
91
- export function getAmountForDuration(duration, pricePerBlock, blockTime = 5) {
91
+ export function getAmountForDuration(duration, pricePerBlock, blockTime) {
92
92
  return BigInt(duration.toSeconds()) / BigInt(blockTime) * BigInt(pricePerBlock);
93
93
  }
94
94
  /**
@@ -145,6 +145,7 @@ export class Topic extends Bytes {
145
145
  }
146
146
  }
147
147
  Topic.LENGTH = 32;
148
+ const MAX_UINT64 = new Uint8Array(8).fill(0xff, 0, 8);
148
149
  export class FeedIndex extends Bytes {
149
150
  constructor(bytes) {
150
151
  super(bytes, 8);
@@ -155,6 +156,12 @@ export class FeedIndex extends Bytes {
155
156
  toBigInt() {
156
157
  return Binary.uint64ToNumber(this.bytes, 'BE');
157
158
  }
159
+ next() {
160
+ if (Binary.equals(this.bytes, MAX_UINT64)) {
161
+ return FeedIndex.fromBigInt(0n);
162
+ }
163
+ return FeedIndex.fromBigInt(this.toBigInt() + 1n);
164
+ }
158
165
  }
159
166
  FeedIndex.LENGTH = 8;
160
- FeedIndex.MINUS_ONE = new FeedIndex(new Uint8Array(8).fill(0xff, 0, 8));
167
+ FeedIndex.MINUS_ONE = new FeedIndex(MAX_UINT64);
@@ -25,6 +25,10 @@ export declare class Bee {
25
25
  * Default Signer object used for signing operations, mainly Feeds.
26
26
  */
27
27
  readonly signer?: PrivateKey;
28
+ /**
29
+ * Network on which the Bee node is running
30
+ */
31
+ readonly network: 'gnosis' | 'sepolia';
28
32
  /**
29
33
  * Options for making requests
30
34
  * @private
@@ -37,6 +37,10 @@ export interface BeeOptions extends BeeRequestOptions {
37
37
  * Signer object or private key of the Signer in form of either hex string or Uint8Array that will be default signer for the instance.
38
38
  */
39
39
  signer?: PrivateKey | Uint8Array | string;
40
+ /**
41
+ * Default gnosis when unspecified.
42
+ */
43
+ network?: 'gnosis' | 'sepolia';
40
44
  }
41
45
  export interface GranteesResult {
42
46
  status: number;
@@ -40,7 +40,7 @@ export declare function getStampCost(depth: number, amount: NumberString | strin
40
40
  *
41
41
  * @returns {number} The TTL of the postage batch.
42
42
  */
43
- export declare function getStampDuration(amount: NumberString | string | bigint, pricePerBlock: number, blockTime?: number): Duration;
43
+ export declare function getStampDuration(amount: NumberString | string | bigint, pricePerBlock: number, blockTime: number): Duration;
44
44
  /**
45
45
  * Get the postage batch `amount` required for a given `duration`.
46
46
  *
@@ -48,7 +48,7 @@ export declare function getStampDuration(amount: NumberString | string | bigint,
48
48
  * @param pricePerBlock The price per block in PLUR.
49
49
  * @param blockTime The block time in seconds.
50
50
  */
51
- export declare function getAmountForDuration(duration: Duration, pricePerBlock: number, blockTime?: number): bigint;
51
+ export declare function getAmountForDuration(duration: Duration, pricePerBlock: number, blockTime: number): bigint;
52
52
  /**
53
53
  * Utility function that calculates the depth required for a postage batch to achieve the specified effective size
54
54
  *
@@ -35,7 +35,7 @@ export declare class TransactionId extends Bytes {
35
35
  export declare class Span extends Bytes {
36
36
  static readonly LENGTH = 8;
37
37
  constructor(bytes: Uint8Array | string | Bytes);
38
- static fromBigInt(number: bigint): FeedIndex;
38
+ static fromBigInt(number: bigint): Span;
39
39
  toBigInt(): bigint;
40
40
  static fromSlice(bytes: Uint8Array, start: number): Span;
41
41
  }
@@ -65,4 +65,5 @@ export declare class FeedIndex extends Bytes {
65
65
  constructor(bytes: Uint8Array | string | Bytes);
66
66
  static fromBigInt(number: bigint): FeedIndex;
67
67
  toBigInt(): bigint;
68
+ next(): FeedIndex;
68
69
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ethersphere/bee-js",
3
- "version": "9.0.2",
3
+ "version": "9.1.0",
4
4
  "description": "Javascript client for Bee",
5
5
  "keywords": [
6
6
  "bee",
@@ -56,13 +56,12 @@
56
56
  "build:types": "tsc --emitDeclarationOnly --declaration --outDir dist/types",
57
57
  "build:browser": "webpack --progress",
58
58
  "test": "jest --config=jest.config.ts --runInBand --verbose",
59
- "check:types": "tsc --project tsconfig.test.json",
60
- "lint": "eslint --fix \"src/**/*.ts\" \"test/**/*.ts\" && prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
61
- "lint:check": "eslint \"src/**/*.ts\" \"test/**/*.ts\" && prettier --check \"src/**/*.ts\" \"test/**/*.ts\"",
59
+ "check": "tsc --project tsconfig.test.json",
60
+ "lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\" && prettier --check \"src/**/*.ts\" \"test/**/*.ts\"",
62
61
  "depcheck": "depcheck ."
63
62
  },
64
63
  "dependencies": {
65
- "axios": "^0.28.1",
64
+ "axios": "^0.30.0",
66
65
  "cafe-utility": "^27.14.2",
67
66
  "isomorphic-ws": "^4.0.1",
68
67
  "semver": "^7.3.5",