@upcoming/bee-js 0.17.0 → 9.4.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/README.md +8 -3
- package/dist/cjs/bee.js +39 -14
- package/dist/cjs/feed/index.js +3 -0
- package/dist/cjs/manifest/manifest.js +26 -6
- package/dist/cjs/modules/rchash.js +15 -0
- package/dist/cjs/utils/bytes.js +3 -0
- package/dist/cjs/utils/duration.js +4 -0
- package/dist/cjs/utils/http.js +7 -0
- package/dist/cjs/utils/size.js +9 -0
- package/dist/cjs/utils/stamps.js +36 -36
- package/dist/cjs/utils/type.js +1 -0
- package/dist/cjs/utils/typed-bytes.js +8 -1
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/bee.js +39 -14
- package/dist/mjs/feed/index.js +6 -3
- package/dist/mjs/manifest/manifest.js +26 -5
- package/dist/mjs/modules/rchash.js +15 -0
- package/dist/mjs/utils/bytes.js +3 -0
- package/dist/mjs/utils/duration.js +4 -0
- package/dist/mjs/utils/http.js +7 -0
- package/dist/mjs/utils/size.js +9 -0
- package/dist/mjs/utils/stamps.js +19 -25
- package/dist/mjs/utils/type.js +1 -0
- package/dist/mjs/utils/typed-bytes.js +8 -1
- package/dist/types/bee.d.ts +27 -6
- package/dist/types/manifest/manifest.d.ts +1 -1
- package/dist/types/modules/rchash.d.ts +2 -0
- package/dist/types/types/debug.d.ts +2 -2
- package/dist/types/types/index.d.ts +4 -0
- package/dist/types/utils/bytes.d.ts +1 -0
- package/dist/types/utils/duration.d.ts +1 -0
- package/dist/types/utils/size.d.ts +3 -0
- package/dist/types/utils/stamps.d.ts +2 -2
- package/dist/types/utils/typed-bytes.d.ts +2 -1
- package/package.json +5 -7
package/dist/mjs/bee.js
CHANGED
|
@@ -21,6 +21,7 @@ import * as grantee from "./modules/grantee.js";
|
|
|
21
21
|
import * as gsoc from "./modules/gsoc.js";
|
|
22
22
|
import * as pinning from "./modules/pinning.js";
|
|
23
23
|
import * as pss from "./modules/pss.js";
|
|
24
|
+
import { rchash } from "./modules/rchash.js";
|
|
24
25
|
import * as status from "./modules/status.js";
|
|
25
26
|
import * as stewardship from "./modules/stewardship.js";
|
|
26
27
|
import * as tag from "./modules/tag.js";
|
|
@@ -58,6 +59,7 @@ export class Bee {
|
|
|
58
59
|
if (options?.signer) {
|
|
59
60
|
this.signer = new PrivateKey(options.signer);
|
|
60
61
|
}
|
|
62
|
+
this.network = options?.network ?? 'gnosis';
|
|
61
63
|
this.requestOptions = {
|
|
62
64
|
baseURL: this.url,
|
|
63
65
|
timeout: options?.timeout ?? 0,
|
|
@@ -836,6 +838,12 @@ export class Bee {
|
|
|
836
838
|
reference = new Reference(reference);
|
|
837
839
|
return postEnvelope(this.getRequestOptionsForCall(options), postageBatchId, reference);
|
|
838
840
|
}
|
|
841
|
+
/**
|
|
842
|
+
* Get reserve commitment hash duration seconds
|
|
843
|
+
*/
|
|
844
|
+
async rchash(depth, anchor1, anchor2, options) {
|
|
845
|
+
return rchash(this.getRequestOptionsForCall(options), depth, anchor1, anchor2);
|
|
846
|
+
}
|
|
839
847
|
/**
|
|
840
848
|
* Ping the Bee node to see if there is a live Bee node on the given URL.
|
|
841
849
|
*
|
|
@@ -1121,7 +1129,7 @@ export class Bee {
|
|
|
1121
1129
|
* @throws TypeError if non-integer value is passed to amount or depth
|
|
1122
1130
|
*
|
|
1123
1131
|
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
|
|
1124
|
-
* @see [Bee Debug API reference - `POST /stamps`](https://docs.ethswarm.org/
|
|
1132
|
+
* @see [Bee Debug API reference - `POST /stamps`](https://docs.ethswarm.org/api/#tag/Postage-Stamps/paths/~1stamps~1{amount}~1{depth}/post)
|
|
1125
1133
|
*/
|
|
1126
1134
|
async createPostageBatch(amount, depth, options, requestOptions) {
|
|
1127
1135
|
const amountString = asNumberString(amount, {
|
|
@@ -1135,7 +1143,7 @@ export class Bee {
|
|
|
1135
1143
|
throw new BeeArgumentError(`Depth has to be between ${STAMPS_DEPTH_MIN}..${STAMPS_DEPTH_MAX}`, depth);
|
|
1136
1144
|
}
|
|
1137
1145
|
const chainState = await this.getChainState();
|
|
1138
|
-
const minimumAmount = BigInt(chainState.currentPrice) * 17280n;
|
|
1146
|
+
const minimumAmount = BigInt(chainState.currentPrice) * 17280n + 1n;
|
|
1139
1147
|
if (BigInt(amountString) < minimumAmount) {
|
|
1140
1148
|
throw new BeeArgumentError(`Amount has to be at least ${minimumAmount} (1 day at current price ${chainState.currentPrice})`, amountString);
|
|
1141
1149
|
}
|
|
@@ -1147,7 +1155,7 @@ export class Bee {
|
|
|
1147
1155
|
}
|
|
1148
1156
|
async buyStorage(size, duration, options, requestOptions) {
|
|
1149
1157
|
const chainState = await this.getChainState(requestOptions);
|
|
1150
|
-
const amount = getAmountForDuration(duration, chainState.currentPrice);
|
|
1158
|
+
const amount = getAmountForDuration(duration, chainState.currentPrice, this.network === 'gnosis' ? 5 : 15);
|
|
1151
1159
|
const depth = getDepthForSize(size);
|
|
1152
1160
|
if (options) {
|
|
1153
1161
|
options = preparePostageBatchOptions(options);
|
|
@@ -1156,7 +1164,7 @@ export class Bee {
|
|
|
1156
1164
|
}
|
|
1157
1165
|
async getStorageCost(size, duration, options) {
|
|
1158
1166
|
const chainState = await this.getChainState(options);
|
|
1159
|
-
const amount = getAmountForDuration(duration, chainState.currentPrice);
|
|
1167
|
+
const amount = getAmountForDuration(duration, chainState.currentPrice, this.network === 'gnosis' ? 5 : 15);
|
|
1160
1168
|
const depth = getDepthForSize(size);
|
|
1161
1169
|
return getStampCost(depth, amount);
|
|
1162
1170
|
}
|
|
@@ -1167,19 +1175,19 @@ export class Bee {
|
|
|
1167
1175
|
if (delta <= 0) {
|
|
1168
1176
|
throw new BeeArgumentError('New depth has to be greater than the original depth', depth);
|
|
1169
1177
|
}
|
|
1170
|
-
await this.topUpBatch(batch.batchID, BigInt(batch.amount) * 2n ** BigInt(delta - 1), options);
|
|
1178
|
+
await this.topUpBatch(batch.batchID, BigInt(batch.amount) * 2n ** BigInt(delta - 1) + 1n, options);
|
|
1171
1179
|
return this.diluteBatch(batch.batchID, depth, options);
|
|
1172
1180
|
}
|
|
1173
1181
|
async extendStorageDuration(postageBatchId, duration, options) {
|
|
1174
1182
|
const batch = await this.getPostageBatch(postageBatchId, options);
|
|
1175
1183
|
const chainState = await this.getChainState(options);
|
|
1176
|
-
const amount = getAmountForDuration(duration, chainState.currentPrice);
|
|
1184
|
+
const amount = getAmountForDuration(duration, chainState.currentPrice, this.network === 'gnosis' ? 5 : 15);
|
|
1177
1185
|
return this.topUpBatch(batch.batchID, amount, options);
|
|
1178
1186
|
}
|
|
1179
1187
|
async getExtensionCost(postageBatchId, size, duration, options) {
|
|
1180
1188
|
const batch = await this.getPostageBatch(postageBatchId, options);
|
|
1181
1189
|
const chainState = await this.getChainState(options);
|
|
1182
|
-
const amount = getAmountForDuration(duration, chainState.currentPrice);
|
|
1190
|
+
const amount = getAmountForDuration(duration, chainState.currentPrice, this.network === 'gnosis' ? 5 : 15);
|
|
1183
1191
|
const depth = getDepthForSize(size);
|
|
1184
1192
|
const currentValue = getStampCost(batch.depth, batch.amount);
|
|
1185
1193
|
const newValue = getStampCost(depth, amount);
|
|
@@ -1199,7 +1207,7 @@ export class Bee {
|
|
|
1199
1207
|
async getDurationExtensionCost(postageBatchId, duration, options) {
|
|
1200
1208
|
const batch = await this.getPostageBatch(postageBatchId, options);
|
|
1201
1209
|
const chainState = await this.getChainState(options);
|
|
1202
|
-
const amount = getAmountForDuration(duration, chainState.currentPrice);
|
|
1210
|
+
const amount = getAmountForDuration(duration, chainState.currentPrice, this.network === 'gnosis' ? 5 : 15);
|
|
1203
1211
|
return getStampCost(batch.depth, amount);
|
|
1204
1212
|
}
|
|
1205
1213
|
/**
|
|
@@ -1213,7 +1221,7 @@ export class Bee {
|
|
|
1213
1221
|
* @param options Request options
|
|
1214
1222
|
*
|
|
1215
1223
|
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
|
|
1216
|
-
* @see [Bee Debug API reference - `PATCH /stamps/topup/${id}/${amount}`](https://docs.ethswarm.org/
|
|
1224
|
+
* @see [Bee Debug API reference - `PATCH /stamps/topup/${id}/${amount}`](https://docs.ethswarm.org/api/#tag/Postage-Stamps/paths/~1stamps~1topup~1{batch_id}~1{amount}/patch)
|
|
1217
1225
|
*/
|
|
1218
1226
|
async topUpBatch(postageBatchId, amount, options) {
|
|
1219
1227
|
postageBatchId = new BatchId(postageBatchId);
|
|
@@ -1235,7 +1243,7 @@ export class Bee {
|
|
|
1235
1243
|
* @param options Request options
|
|
1236
1244
|
*
|
|
1237
1245
|
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
|
|
1238
|
-
* @see [Bee Debug API reference - `PATCH /stamps/topup/${id}/${amount}`](https://docs.ethswarm.org/
|
|
1246
|
+
* @see [Bee Debug API reference - `PATCH /stamps/topup/${id}/${amount}`](https://docs.ethswarm.org/api/#tag/Postage-Stamps/paths/~1stamps~1dilute~1%7Bbatch_id%7D~1%7Bdepth%7D/patch)
|
|
1239
1247
|
*/
|
|
1240
1248
|
async diluteBatch(postageBatchId, depth, options) {
|
|
1241
1249
|
postageBatchId = new BatchId(postageBatchId);
|
|
@@ -1252,7 +1260,7 @@ export class Bee {
|
|
|
1252
1260
|
* @param postageBatchId Batch ID
|
|
1253
1261
|
*
|
|
1254
1262
|
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
|
|
1255
|
-
* @see [Bee Debug API reference - `GET /stamps/${id}`](https://docs.ethswarm.org/
|
|
1263
|
+
* @see [Bee Debug API reference - `GET /stamps/${id}`](https://docs.ethswarm.org/api/#tag/Postage-Stamps/paths/~1stamps~1%7Bbatch_id%7D/get)
|
|
1256
1264
|
*/
|
|
1257
1265
|
async getPostageBatch(postageBatchId, options) {
|
|
1258
1266
|
postageBatchId = new BatchId(postageBatchId);
|
|
@@ -1264,7 +1272,7 @@ export class Bee {
|
|
|
1264
1272
|
* @param postageBatchId Batch ID
|
|
1265
1273
|
*
|
|
1266
1274
|
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
|
|
1267
|
-
* @see [Bee Debug API reference - `GET /stamps/${id}/buckets`](https://docs.ethswarm.org/
|
|
1275
|
+
* @see [Bee Debug API reference - `GET /stamps/${id}/buckets`](https://docs.ethswarm.org/api/#tag/Postage-Stamps/paths/~1stamps~1%7Bbatch_id%7D~1buckets/get)
|
|
1268
1276
|
*/
|
|
1269
1277
|
async getPostageBatchBuckets(postageBatchId, options) {
|
|
1270
1278
|
postageBatchId = new BatchId(postageBatchId);
|
|
@@ -1274,15 +1282,32 @@ export class Bee {
|
|
|
1274
1282
|
* Return all postage batches that has the node available.
|
|
1275
1283
|
*
|
|
1276
1284
|
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
|
|
1277
|
-
* @see [Bee Debug API reference - `GET /stamps`](https://docs.ethswarm.org/
|
|
1285
|
+
* @see [Bee Debug API reference - `GET /stamps`](https://docs.ethswarm.org/api/#tag/Postage-Stamps/paths/~1stamps/get)
|
|
1286
|
+
* @deprecated Use `getPostageBatches` instead
|
|
1278
1287
|
*/
|
|
1279
1288
|
async getAllPostageBatch(options) {
|
|
1280
|
-
return stamps.getAllPostageBatches(this.getRequestOptionsForCall(options));
|
|
1289
|
+
return stamps.getAllPostageBatches(this.getRequestOptionsForCall(options)); // TODO: remove in June 2025
|
|
1281
1290
|
}
|
|
1282
1291
|
/**
|
|
1283
1292
|
* Return all globally available postage batches.
|
|
1293
|
+
* @deprecated Use `getGlobalPostageBatches` instead
|
|
1284
1294
|
*/
|
|
1285
1295
|
async getAllGlobalPostageBatch(options) {
|
|
1296
|
+
return stamps.getGlobalPostageBatches(this.getRequestOptionsForCall(options)); // TODO: remove in June 2025
|
|
1297
|
+
}
|
|
1298
|
+
/**
|
|
1299
|
+
* Return all postage batches that belong to the node.
|
|
1300
|
+
*
|
|
1301
|
+
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
|
|
1302
|
+
* @see [Bee Debug API reference - `GET /stamps`](https://docs.ethswarm.org/api/#tag/Postage-Stamps/paths/~1stamps/get)
|
|
1303
|
+
*/
|
|
1304
|
+
async getPostageBatches(options) {
|
|
1305
|
+
return stamps.getAllPostageBatches(this.getRequestOptionsForCall(options));
|
|
1306
|
+
}
|
|
1307
|
+
/**
|
|
1308
|
+
* Return all globally available postage batches.
|
|
1309
|
+
*/
|
|
1310
|
+
async getGlobalPostageBatches(options) {
|
|
1286
1311
|
return stamps.getGlobalPostageBatches(this.getRequestOptionsForCall(options));
|
|
1287
1312
|
}
|
|
1288
1313
|
/**
|
package/dist/mjs/feed/index.js
CHANGED
|
@@ -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 {
|
|
@@ -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
|
|
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
|
-
|
|
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
|
-
|
|
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;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Types } from 'cafe-utility';
|
|
2
|
+
import { http } from "../utils/http.js";
|
|
3
|
+
const RCHASH_ENDPOINT = 'rchash';
|
|
4
|
+
export async function rchash(requestOptions, depth, anchor1, anchor2) {
|
|
5
|
+
const response = await http(requestOptions, {
|
|
6
|
+
responseType: 'json',
|
|
7
|
+
url: `${RCHASH_ENDPOINT}/${depth}/${anchor1}/${anchor2}`
|
|
8
|
+
});
|
|
9
|
+
const body = Types.asObject(response.data, {
|
|
10
|
+
name: 'response.data'
|
|
11
|
+
});
|
|
12
|
+
return Types.asNumber(body.durationSeconds, {
|
|
13
|
+
name: 'durationSeconds'
|
|
14
|
+
});
|
|
15
|
+
}
|
package/dist/mjs/utils/bytes.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Dates } from 'cafe-utility';
|
|
1
2
|
export class Duration {
|
|
2
3
|
constructor(seconds) {
|
|
3
4
|
this.seconds = Math.ceil(seconds);
|
|
@@ -44,4 +45,7 @@ export class Duration {
|
|
|
44
45
|
toEndDate(startDate) {
|
|
45
46
|
return new Date((startDate ?? new Date()).getTime() + this.seconds * 1000);
|
|
46
47
|
}
|
|
48
|
+
represent() {
|
|
49
|
+
return Dates.secondsToHumanTime(this.seconds);
|
|
50
|
+
}
|
|
47
51
|
}
|
package/dist/mjs/utils/http.js
CHANGED
|
@@ -4,6 +4,13 @@ import { BeeResponseError } from "../index.js";
|
|
|
4
4
|
const {
|
|
5
5
|
AxiosError
|
|
6
6
|
} = axios;
|
|
7
|
+
const originalObjectKeys = Object.keys;
|
|
8
|
+
Object.keys = function (o) {
|
|
9
|
+
if (typeof Buffer !== 'undefined' && Buffer.isBuffer(o)) {
|
|
10
|
+
return ['axios_workaround_for_buffer'];
|
|
11
|
+
}
|
|
12
|
+
return originalObjectKeys(o);
|
|
13
|
+
};
|
|
7
14
|
const MAX_FAILED_ATTEMPTS = 100000;
|
|
8
15
|
const DELAY_FAST = 200;
|
|
9
16
|
const DELAY_SLOW = 1000;
|
package/dist/mjs/utils/size.js
CHANGED
|
@@ -16,6 +16,12 @@ export class Size {
|
|
|
16
16
|
static fromBytes(bytes) {
|
|
17
17
|
return new Size(bytes);
|
|
18
18
|
}
|
|
19
|
+
static fromKilobytes(kilobytes) {
|
|
20
|
+
return new Size(kilobytes * 1000);
|
|
21
|
+
}
|
|
22
|
+
static fromMegabytes(megabytes) {
|
|
23
|
+
return new Size(megabytes * 1000 * 1000);
|
|
24
|
+
}
|
|
19
25
|
static fromGigabytes(gigabytes) {
|
|
20
26
|
return new Size(gigabytes * 1000 * 1000 * 1000);
|
|
21
27
|
}
|
|
@@ -28,4 +34,7 @@ export class Size {
|
|
|
28
34
|
toFormattedString() {
|
|
29
35
|
return Numbers.convertBytes(this.bytes, 1000);
|
|
30
36
|
}
|
|
37
|
+
represent() {
|
|
38
|
+
return this.toFormattedString();
|
|
39
|
+
}
|
|
31
40
|
}
|
package/dist/mjs/utils/stamps.js
CHANGED
|
@@ -3,6 +3,7 @@ import { Bytes } from "./bytes.js";
|
|
|
3
3
|
import { Duration } from "./duration.js";
|
|
4
4
|
import { BZZ } from "./tokens.js";
|
|
5
5
|
import { asNumberString } from "./type.js";
|
|
6
|
+
const MAX_UTILIZATION = 0.9;
|
|
6
7
|
/**
|
|
7
8
|
* Utility function that calculates usage of postage batch based on its utilization, depth and bucket depth.
|
|
8
9
|
*
|
|
@@ -25,23 +26,9 @@ export function getStampTheoreticalBytes(depth) {
|
|
|
25
26
|
}
|
|
26
27
|
/**
|
|
27
28
|
* Based on https://docs.ethswarm.org/docs/learn/technology/contracts/postage-stamp/#effective-utilisation-table
|
|
29
|
+
* Optimised for encrypted, medium erasure coding
|
|
28
30
|
*/
|
|
29
|
-
const
|
|
30
|
-
22: 0.2867,
|
|
31
|
-
23: 0.4956,
|
|
32
|
-
24: 0.6433,
|
|
33
|
-
25: 0.7478,
|
|
34
|
-
26: 0.8217,
|
|
35
|
-
27: 0.8739,
|
|
36
|
-
28: 0.9108,
|
|
37
|
-
29: 0.9369,
|
|
38
|
-
30: 0.9554,
|
|
39
|
-
31: 0.9685,
|
|
40
|
-
32: 0.9777,
|
|
41
|
-
33: 0.9842,
|
|
42
|
-
34: 0.9889
|
|
43
|
-
};
|
|
44
|
-
const effectiveSizeBreakpoints = [[22, 4.93], [23, 17.03], [24, 44.21], [25, 102.78], [26, 225.87], [27, 480.44], [28, 1001.44], [29, 2060.27], [30, 4201.9], [31, 8519.02], [32, 17199.89], [33, 34628.46]];
|
|
31
|
+
const effectiveSizeBreakpoints = [[17, 0.00004089], [18, 0.00609], [19, 0.10249], [20, 0.62891], [21, 2.38], [22, 7.07], [23, 18.24], [24, 43.04], [25, 96.5], [26, 208.52], [27, 435.98], [28, 908.81], [29, 1870], [30, 3810], [31, 7730], [32, 15610], [33, 31430], [34, 63150]];
|
|
45
32
|
/**
|
|
46
33
|
* Utility function that calculates the effective size of a postage batch based on its depth.
|
|
47
34
|
*
|
|
@@ -51,15 +38,22 @@ const effectiveSizeBreakpoints = [[22, 4.93], [23, 17.03], [24, 44.21], [25, 102
|
|
|
51
38
|
* @returns {number} The effective size of the postage batch in bytes.
|
|
52
39
|
*/
|
|
53
40
|
export function getStampEffectiveBytes(depth) {
|
|
54
|
-
if (depth <
|
|
41
|
+
if (depth < 17) {
|
|
55
42
|
return 0;
|
|
56
43
|
}
|
|
57
|
-
const
|
|
58
|
-
|
|
44
|
+
const breakpoint = effectiveSizeBreakpoints.find(([d, size]) => {
|
|
45
|
+
if (depth === d) {
|
|
46
|
+
return size;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
if (breakpoint) {
|
|
50
|
+
return breakpoint[1] * 1000 * 1000 * 1000;
|
|
51
|
+
}
|
|
52
|
+
return Math.ceil(getStampTheoreticalBytes(depth) * MAX_UTILIZATION);
|
|
59
53
|
}
|
|
60
54
|
export function getStampEffectiveBytesBreakpoints() {
|
|
61
55
|
const map = new Map();
|
|
62
|
-
for (let i =
|
|
56
|
+
for (let i = 17; i < 35; i++) {
|
|
63
57
|
map.set(i, getStampEffectiveBytes(i));
|
|
64
58
|
}
|
|
65
59
|
return map;
|
|
@@ -77,7 +71,7 @@ export function getStampCost(depth, amount) {
|
|
|
77
71
|
*
|
|
78
72
|
* @returns {number} The TTL of the postage batch.
|
|
79
73
|
*/
|
|
80
|
-
export function getStampDuration(amount, pricePerBlock, blockTime
|
|
74
|
+
export function getStampDuration(amount, pricePerBlock, blockTime) {
|
|
81
75
|
const amountBigInt = BigInt(asNumberString(amount));
|
|
82
76
|
return Duration.fromSeconds(Number(amountBigInt * BigInt(blockTime) / BigInt(pricePerBlock)));
|
|
83
77
|
}
|
|
@@ -88,8 +82,8 @@ export function getStampDuration(amount, pricePerBlock, blockTime = 5) {
|
|
|
88
82
|
* @param pricePerBlock The price per block in PLUR.
|
|
89
83
|
* @param blockTime The block time in seconds.
|
|
90
84
|
*/
|
|
91
|
-
export function getAmountForDuration(duration, pricePerBlock, blockTime
|
|
92
|
-
return BigInt(duration.toSeconds()) / BigInt(blockTime) * BigInt(pricePerBlock);
|
|
85
|
+
export function getAmountForDuration(duration, pricePerBlock, blockTime) {
|
|
86
|
+
return BigInt(duration.toSeconds()) / BigInt(blockTime) * BigInt(pricePerBlock) + 1n;
|
|
93
87
|
}
|
|
94
88
|
/**
|
|
95
89
|
* Utility function that calculates the depth required for a postage batch to achieve the specified effective size
|
|
@@ -99,11 +93,11 @@ export function getAmountForDuration(duration, pricePerBlock, blockTime = 5) {
|
|
|
99
93
|
*/
|
|
100
94
|
export function getDepthForSize(size) {
|
|
101
95
|
for (const [depth, sizeBreakpoint] of effectiveSizeBreakpoints) {
|
|
102
|
-
if (size.
|
|
96
|
+
if (size.toBytes() <= sizeBreakpoint * 1000 * 1000 * 1000) {
|
|
103
97
|
return depth;
|
|
104
98
|
}
|
|
105
99
|
}
|
|
106
|
-
return
|
|
100
|
+
return 35;
|
|
107
101
|
}
|
|
108
102
|
export function convertEnvelopeToMarshaledStamp(envelope) {
|
|
109
103
|
return marshalStamp(envelope.signature, envelope.batchId.toUint8Array(), envelope.timestamp, envelope.index);
|
package/dist/mjs/utils/type.js
CHANGED
|
@@ -67,6 +67,7 @@ export function prepareUploadOptions(value, name = 'UploadOptions') {
|
|
|
67
67
|
act: Types.asOptional(x => Types.asBoolean(x, {
|
|
68
68
|
name: 'act'
|
|
69
69
|
}), object.act),
|
|
70
|
+
actHistoryAddress: Types.asOptional(x => new Reference(x), object.actHistoryAddress),
|
|
70
71
|
deferred: Types.asOptional(x => Types.asBoolean(x, {
|
|
71
72
|
name: 'deferred'
|
|
72
73
|
}), object.deferred),
|
|
@@ -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(
|
|
167
|
+
FeedIndex.MINUS_ONE = new FeedIndex(MAX_UINT64);
|
package/dist/types/bee.d.ts
CHANGED
|
@@ -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
|
|
@@ -475,6 +479,10 @@ export declare class Bee {
|
|
|
475
479
|
*/
|
|
476
480
|
makeSOCWriter(signer?: PrivateKey | Uint8Array | string, options?: BeeRequestOptions): SOCWriter;
|
|
477
481
|
createEnvelope(postageBatchId: BatchId | Uint8Array | string, reference: Reference | Uint8Array | string, options?: BeeRequestOptions): Promise<EnvelopeWithBatchId>;
|
|
482
|
+
/**
|
|
483
|
+
* Get reserve commitment hash duration seconds
|
|
484
|
+
*/
|
|
485
|
+
rchash(depth: number, anchor1: string, anchor2: string, options?: BeeRequestOptions): Promise<number>;
|
|
478
486
|
/**
|
|
479
487
|
* Ping the Bee node to see if there is a live Bee node on the given URL.
|
|
480
488
|
*
|
|
@@ -647,7 +655,7 @@ export declare class Bee {
|
|
|
647
655
|
* @throws TypeError if non-integer value is passed to amount or depth
|
|
648
656
|
*
|
|
649
657
|
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
|
|
650
|
-
* @see [Bee Debug API reference - `POST /stamps`](https://docs.ethswarm.org/
|
|
658
|
+
* @see [Bee Debug API reference - `POST /stamps`](https://docs.ethswarm.org/api/#tag/Postage-Stamps/paths/~1stamps~1{amount}~1{depth}/post)
|
|
651
659
|
*/
|
|
652
660
|
createPostageBatch(amount: NumberString | string | bigint, depth: number, options?: PostageBatchOptions, requestOptions?: BeeRequestOptions): Promise<BatchId>;
|
|
653
661
|
buyStorage(size: Size, duration: Duration, options?: PostageBatchOptions, requestOptions?: BeeRequestOptions): Promise<BatchId>;
|
|
@@ -668,7 +676,7 @@ export declare class Bee {
|
|
|
668
676
|
* @param options Request options
|
|
669
677
|
*
|
|
670
678
|
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
|
|
671
|
-
* @see [Bee Debug API reference - `PATCH /stamps/topup/${id}/${amount}`](https://docs.ethswarm.org/
|
|
679
|
+
* @see [Bee Debug API reference - `PATCH /stamps/topup/${id}/${amount}`](https://docs.ethswarm.org/api/#tag/Postage-Stamps/paths/~1stamps~1topup~1{batch_id}~1{amount}/patch)
|
|
672
680
|
*/
|
|
673
681
|
topUpBatch(postageBatchId: BatchId | Uint8Array | string, amount: NumberString | string | bigint, options?: BeeRequestOptions): Promise<BatchId>;
|
|
674
682
|
/**
|
|
@@ -683,7 +691,7 @@ export declare class Bee {
|
|
|
683
691
|
* @param options Request options
|
|
684
692
|
*
|
|
685
693
|
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
|
|
686
|
-
* @see [Bee Debug API reference - `PATCH /stamps/topup/${id}/${amount}`](https://docs.ethswarm.org/
|
|
694
|
+
* @see [Bee Debug API reference - `PATCH /stamps/topup/${id}/${amount}`](https://docs.ethswarm.org/api/#tag/Postage-Stamps/paths/~1stamps~1dilute~1%7Bbatch_id%7D~1%7Bdepth%7D/patch)
|
|
687
695
|
*/
|
|
688
696
|
diluteBatch(postageBatchId: BatchId | Uint8Array | string, depth: number, options?: BeeRequestOptions): Promise<BatchId>;
|
|
689
697
|
/**
|
|
@@ -692,7 +700,7 @@ export declare class Bee {
|
|
|
692
700
|
* @param postageBatchId Batch ID
|
|
693
701
|
*
|
|
694
702
|
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
|
|
695
|
-
* @see [Bee Debug API reference - `GET /stamps/${id}`](https://docs.ethswarm.org/
|
|
703
|
+
* @see [Bee Debug API reference - `GET /stamps/${id}`](https://docs.ethswarm.org/api/#tag/Postage-Stamps/paths/~1stamps~1%7Bbatch_id%7D/get)
|
|
696
704
|
*/
|
|
697
705
|
getPostageBatch(postageBatchId: BatchId | Uint8Array | string, options?: BeeRequestOptions): Promise<PostageBatch>;
|
|
698
706
|
/**
|
|
@@ -701,20 +709,33 @@ export declare class Bee {
|
|
|
701
709
|
* @param postageBatchId Batch ID
|
|
702
710
|
*
|
|
703
711
|
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
|
|
704
|
-
* @see [Bee Debug API reference - `GET /stamps/${id}/buckets`](https://docs.ethswarm.org/
|
|
712
|
+
* @see [Bee Debug API reference - `GET /stamps/${id}/buckets`](https://docs.ethswarm.org/api/#tag/Postage-Stamps/paths/~1stamps~1%7Bbatch_id%7D~1buckets/get)
|
|
705
713
|
*/
|
|
706
714
|
getPostageBatchBuckets(postageBatchId: BatchId | Uint8Array | string, options?: BeeRequestOptions): Promise<PostageBatchBuckets>;
|
|
707
715
|
/**
|
|
708
716
|
* Return all postage batches that has the node available.
|
|
709
717
|
*
|
|
710
718
|
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
|
|
711
|
-
* @see [Bee Debug API reference - `GET /stamps`](https://docs.ethswarm.org/
|
|
719
|
+
* @see [Bee Debug API reference - `GET /stamps`](https://docs.ethswarm.org/api/#tag/Postage-Stamps/paths/~1stamps/get)
|
|
720
|
+
* @deprecated Use `getPostageBatches` instead
|
|
712
721
|
*/
|
|
713
722
|
getAllPostageBatch(options?: BeeRequestOptions): Promise<PostageBatch[]>;
|
|
714
723
|
/**
|
|
715
724
|
* Return all globally available postage batches.
|
|
725
|
+
* @deprecated Use `getGlobalPostageBatches` instead
|
|
716
726
|
*/
|
|
717
727
|
getAllGlobalPostageBatch(options?: BeeRequestOptions): Promise<GlobalPostageBatch[]>;
|
|
728
|
+
/**
|
|
729
|
+
* Return all postage batches that belong to the node.
|
|
730
|
+
*
|
|
731
|
+
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
|
|
732
|
+
* @see [Bee Debug API reference - `GET /stamps`](https://docs.ethswarm.org/api/#tag/Postage-Stamps/paths/~1stamps/get)
|
|
733
|
+
*/
|
|
734
|
+
getPostageBatches(options?: BeeRequestOptions): Promise<PostageBatch[]>;
|
|
735
|
+
/**
|
|
736
|
+
* Return all globally available postage batches.
|
|
737
|
+
*/
|
|
738
|
+
getGlobalPostageBatches(options?: BeeRequestOptions): Promise<GlobalPostageBatch[]>;
|
|
718
739
|
/**
|
|
719
740
|
* Return lists of all current pending transactions that the Bee made
|
|
720
741
|
*/
|
|
@@ -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
|
*/
|
|
@@ -140,13 +140,13 @@ export interface NodeInfo {
|
|
|
140
140
|
/**
|
|
141
141
|
* Indicates whether the Bee node has its own deployed chequebook.
|
|
142
142
|
*
|
|
143
|
-
* @see [Bee docs - Chequebook](https://docs.ethswarm.org/docs/
|
|
143
|
+
* @see [Bee docs - Chequebook](https://docs.ethswarm.org/docs/references/glossary/#cheques--chequebook)
|
|
144
144
|
*/
|
|
145
145
|
chequebookEnabled: boolean;
|
|
146
146
|
/**
|
|
147
147
|
* Indicates whether SWAP is enabled for the Bee node.
|
|
148
148
|
*
|
|
149
|
-
* @see [Bee docs - SWAP](https://docs.ethswarm.org/docs/
|
|
149
|
+
* @see [Bee docs - SWAP](https://docs.ethswarm.org/docs/references/glossary/#swap)
|
|
150
150
|
*/
|
|
151
151
|
swapEnabled: boolean;
|
|
152
152
|
}
|
|
@@ -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;
|
|
@@ -9,8 +9,11 @@ export declare class Size {
|
|
|
9
9
|
private bytes;
|
|
10
10
|
private constructor();
|
|
11
11
|
static fromBytes(bytes: number): Size;
|
|
12
|
+
static fromKilobytes(kilobytes: number): Size;
|
|
13
|
+
static fromMegabytes(megabytes: number): Size;
|
|
12
14
|
static fromGigabytes(gigabytes: number): Size;
|
|
13
15
|
toBytes(): number;
|
|
14
16
|
toGigabytes(): number;
|
|
15
17
|
toFormattedString(): string;
|
|
18
|
+
represent(): string;
|
|
16
19
|
}
|