@ethersphere/bee-js 9.1.0 → 9.1.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.
package/dist/mjs/bee.js CHANGED
@@ -1136,7 +1136,7 @@ export class Bee {
1136
1136
  throw new BeeArgumentError(`Depth has to be between ${STAMPS_DEPTH_MIN}..${STAMPS_DEPTH_MAX}`, depth);
1137
1137
  }
1138
1138
  const chainState = await this.getChainState();
1139
- const minimumAmount = BigInt(chainState.currentPrice) * 17280n;
1139
+ const minimumAmount = BigInt(chainState.currentPrice) * 17280n + 1n;
1140
1140
  if (BigInt(amountString) < minimumAmount) {
1141
1141
  throw new BeeArgumentError(`Amount has to be at least ${minimumAmount} (1 day at current price ${chainState.currentPrice})`, amountString);
1142
1142
  }
@@ -1168,7 +1168,7 @@ export class Bee {
1168
1168
  if (delta <= 0) {
1169
1169
  throw new BeeArgumentError('New depth has to be greater than the original depth', depth);
1170
1170
  }
1171
- await this.topUpBatch(batch.batchID, BigInt(batch.amount) * 2n ** BigInt(delta - 1), options);
1171
+ await this.topUpBatch(batch.batchID, BigInt(batch.amount) * 2n ** BigInt(delta - 1) + 1n, options);
1172
1172
  return this.diluteBatch(batch.batchID, depth, options);
1173
1173
  }
1174
1174
  async extendStorageDuration(postageBatchId, duration, options) {
@@ -17,6 +17,22 @@ export class Fork {
17
17
  }
18
18
  static split(a, b) {
19
19
  const commonPart = Binary.commonPrefix(a.prefix, b.prefix);
20
+ if (commonPart.length === a.prefix.length) {
21
+ const remainingB = b.prefix.slice(commonPart.length);
22
+ b.node.path = b.prefix.slice(commonPart.length);
23
+ b.prefix = b.prefix.slice(commonPart.length);
24
+ b.node.parent = a.node;
25
+ a.node.forks.set(remainingB[0], b);
26
+ return a;
27
+ }
28
+ if (commonPart.length === b.prefix.length) {
29
+ const remainingA = a.prefix.slice(commonPart.length);
30
+ a.node.path = a.prefix.slice(commonPart.length);
31
+ a.prefix = a.prefix.slice(commonPart.length);
32
+ a.node.parent = b.node;
33
+ b.node.forks.set(remainingA[0], a);
34
+ return b;
35
+ }
20
36
  const node = new MantarayNode({
21
37
  path: commonPart
22
38
  });
@@ -57,14 +73,14 @@ export class Fork {
57
73
  const prefixLength = Binary.uint8ToNumber(reader.read(1));
58
74
  const prefix = reader.read(prefixLength);
59
75
  reader.read(30 - prefixLength);
60
- const targetAddress = reader.read(32);
76
+ const selfAddress = reader.read(32);
61
77
  let metadata = undefined;
62
78
  if (isType(type, TYPE_WITH_METADATA)) {
63
79
  const metadataLength = Binary.uint16ToNumber(reader.read(2), 'BE');
64
80
  metadata = JSON.parse(DECODER.decode(reader.read(metadataLength)));
65
81
  }
66
82
  return new Fork(prefix, new MantarayNode({
67
- targetAddress,
83
+ selfAddress,
68
84
  metadata,
69
85
  path: prefix
70
86
  }));
@@ -176,15 +192,16 @@ export class MantarayNode {
176
192
  * Do not forget calling `loadRecursively` on the returned node to load the entire tree.
177
193
  */
178
194
  static async unmarshal(bee, reference, options, requestOptions) {
195
+ reference = new Reference(reference);
179
196
  const data = (await bee.downloadData(reference, options, requestOptions)).toUint8Array();
180
- return this.unmarshalFromData(data);
197
+ return this.unmarshalFromData(data, reference.toUint8Array());
181
198
  }
182
199
  /**
183
200
  * Unmarshals a MantarayNode from the given data.
184
201
  *
185
202
  * Do not forget calling `loadRecursively` on the returned node to load the entire tree.
186
203
  */
187
- static unmarshalFromData(data) {
204
+ static unmarshalFromData(data, selfAddress) {
188
205
  const obfuscationKey = data.subarray(0, 32);
189
206
  const decrypted = Binary.xorCypher(data.subarray(32), obfuscationKey);
190
207
  const reader = new Uint8ArrayReader(decrypted);
@@ -195,6 +212,7 @@ export class MantarayNode {
195
212
  const targetAddressLength = Binary.uint8ToNumber(reader.read(1));
196
213
  const targetAddress = targetAddressLength === 0 ? NULL_ADDRESS : reader.read(targetAddressLength);
197
214
  const node = new MantarayNode({
215
+ selfAddress,
198
216
  targetAddress,
199
217
  obfuscationKey
200
218
  });
@@ -293,7 +311,10 @@ export class MantarayNode {
293
311
  */
294
312
  async loadRecursively(bee, options, requestOptions) {
295
313
  for (const fork of this.forks.values()) {
296
- const node = await MantarayNode.unmarshal(bee, fork.node.targetAddress, options, requestOptions);
314
+ if (!fork.node.selfAddress) {
315
+ throw Error('MantarayNode#loadRecursively fork.node.selfAddress is not set');
316
+ }
317
+ const node = await MantarayNode.unmarshal(bee, fork.node.selfAddress, options, requestOptions);
297
318
  fork.node.targetAddress = node.targetAddress;
298
319
  fork.node.forks = node.forks;
299
320
  fork.node.path = fork.prefix;
@@ -89,7 +89,7 @@ export function getStampDuration(amount, pricePerBlock, blockTime) {
89
89
  * @param blockTime The block time in seconds.
90
90
  */
91
91
  export function getAmountForDuration(duration, pricePerBlock, blockTime) {
92
- return BigInt(duration.toSeconds()) / BigInt(blockTime) * BigInt(pricePerBlock);
92
+ return BigInt(duration.toSeconds()) / BigInt(blockTime) * BigInt(pricePerBlock) + 1n;
93
93
  }
94
94
  /**
95
95
  * Utility function that calculates the depth required for a postage batch to achieve the specified effective size
@@ -60,7 +60,7 @@ export declare class MantarayNode {
60
60
  *
61
61
  * Do not forget calling `loadRecursively` on the returned node to load the entire tree.
62
62
  */
63
- static unmarshalFromData(data: Uint8Array): MantarayNode;
63
+ static unmarshalFromData(data: Uint8Array, selfAddress: Uint8Array): MantarayNode;
64
64
  /**
65
65
  * Adds a fork to the node.
66
66
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ethersphere/bee-js",
3
- "version": "9.1.0",
3
+ "version": "9.1.2",
4
4
  "description": "Javascript client for Bee",
5
5
  "keywords": [
6
6
  "bee",
@@ -94,7 +94,6 @@
94
94
  "eslint-plugin-unused-imports": "^2.0.0",
95
95
  "husky": "^8.0.1",
96
96
  "jest": "^29.7.0",
97
- "jest-puppeteer": "^11.0.0",
98
97
  "prettier": "^2.6.2",
99
98
  "rimraf": "^3.0.2",
100
99
  "terser-webpack-plugin": "^5.3.1",