@upcoming/bee-js 0.12.0 → 0.14.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/cjs/bee.js +9 -0
- package/dist/cjs/chunk/cac.js +15 -1
- package/dist/cjs/chunk/soc.js +8 -1
- package/dist/cjs/feed/index.js +21 -3
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/bee.js +9 -0
- package/dist/mjs/chunk/cac.js +13 -0
- package/dist/mjs/chunk/soc.js +7 -1
- package/dist/mjs/feed/index.js +19 -4
- package/dist/types/bee.d.ts +1 -0
- package/dist/types/chunk/cac.d.ts +1 -0
- package/dist/types/chunk/soc.d.ts +1 -0
- package/dist/types/feed/index.d.ts +2 -0
- package/package.json +1 -1
package/dist/cjs/bee.js
CHANGED
|
@@ -1190,6 +1190,15 @@ class Bee {
|
|
|
1190
1190
|
const amount = (0, stamps_1.getAmountForDuration)(duration, chainState.currentPrice);
|
|
1191
1191
|
return this.topUpBatch(batch.batchID, amount, options);
|
|
1192
1192
|
}
|
|
1193
|
+
async getExtensionCost(postageBatchId, gigabytes, duration, options) {
|
|
1194
|
+
const batch = await this.getPostageBatch(postageBatchId, options);
|
|
1195
|
+
const chainState = await this.getChainState(options);
|
|
1196
|
+
const amount = (0, stamps_1.getAmountForDuration)(duration, chainState.currentPrice);
|
|
1197
|
+
const depth = (0, stamps_1.getDepthForSize)(gigabytes);
|
|
1198
|
+
const currentValue = (0, stamps_1.getStampCost)(batch.depth, batch.amount);
|
|
1199
|
+
const newValue = (0, stamps_1.getStampCost)(depth, amount);
|
|
1200
|
+
return newValue.minus(currentValue);
|
|
1201
|
+
}
|
|
1193
1202
|
async getSizeExtensionCost(postageBatchId, gigabytes, options) {
|
|
1194
1203
|
const batch = await this.getPostageBatch(postageBatchId, options);
|
|
1195
1204
|
const depth = (0, stamps_1.getDepthForSize)(gigabytes);
|
package/dist/cjs/chunk/cac.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.makeContentAddressedChunk = exports.MAX_PAYLOAD_SIZE = exports.MIN_PAYLOAD_SIZE = void 0;
|
|
3
|
+
exports.asContentAddressedChunk = exports.makeContentAddressedChunk = exports.MAX_PAYLOAD_SIZE = exports.MIN_PAYLOAD_SIZE = void 0;
|
|
4
4
|
const cafe_utility_1 = require("cafe-utility");
|
|
5
5
|
const bytes_1 = require("../utils/bytes");
|
|
6
6
|
const typed_bytes_1 = require("../utils/typed-bytes");
|
|
@@ -30,3 +30,17 @@ function makeContentAddressedChunk(payloadBytes) {
|
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
32
|
exports.makeContentAddressedChunk = makeContentAddressedChunk;
|
|
33
|
+
function asContentAddressedChunk(chunkBytes) {
|
|
34
|
+
if (chunkBytes.length < exports.MIN_PAYLOAD_SIZE + typed_bytes_1.Span.LENGTH || chunkBytes.length > exports.MAX_PAYLOAD_SIZE + typed_bytes_1.Span.LENGTH) {
|
|
35
|
+
throw new RangeError(`chunk size ${chunkBytes.length} exceeds limits [${exports.MIN_PAYLOAD_SIZE + typed_bytes_1.Span.LENGTH}, ${typed_bytes_1.Span.LENGTH}]`);
|
|
36
|
+
}
|
|
37
|
+
const span = typed_bytes_1.Span.fromSlice(chunkBytes, 0);
|
|
38
|
+
const data = cafe_utility_1.Binary.concatBytes(span.toUint8Array(), chunkBytes.slice(typed_bytes_1.Span.LENGTH));
|
|
39
|
+
return {
|
|
40
|
+
data,
|
|
41
|
+
span,
|
|
42
|
+
payload: bytes_1.Bytes.fromSlice(data, typed_bytes_1.Span.LENGTH),
|
|
43
|
+
address: (0, bmt_1.calculateChunkAddress)(data),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
exports.asContentAddressedChunk = asContentAddressedChunk;
|
package/dist/cjs/chunk/soc.js
CHANGED
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.downloadSingleOwnerChunk = exports.uploadSingleOwnerChunkData = exports.uploadSingleOwnerChunk = exports.makeSingleOwnerChunk = exports.makeSOCAddress = exports.makeSingleOwnerChunkFromData = void 0;
|
|
26
|
+
exports.downloadSingleOwnerChunk = exports.uploadSingleOwnerChunkWithWrappedChunk = exports.uploadSingleOwnerChunkData = exports.uploadSingleOwnerChunk = exports.makeSingleOwnerChunk = exports.makeSOCAddress = exports.makeSingleOwnerChunkFromData = void 0;
|
|
27
27
|
const cafe_utility_1 = require("cafe-utility");
|
|
28
28
|
const chunkAPI = __importStar(require("../modules/chunk"));
|
|
29
29
|
const socAPI = __importStar(require("../modules/soc"));
|
|
@@ -138,6 +138,13 @@ async function uploadSingleOwnerChunkData(requestOptions, signer, stamp, identif
|
|
|
138
138
|
return uploadSingleOwnerChunk(requestOptions, soc, stamp, options);
|
|
139
139
|
}
|
|
140
140
|
exports.uploadSingleOwnerChunkData = uploadSingleOwnerChunkData;
|
|
141
|
+
async function uploadSingleOwnerChunkWithWrappedChunk(requestOptions, signer, stamp, identifier, rootChunk, options) {
|
|
142
|
+
signer = new typed_bytes_1.PrivateKey(signer);
|
|
143
|
+
identifier = new typed_bytes_1.Identifier(identifier);
|
|
144
|
+
const soc = makeSingleOwnerChunk((0, cac_1.asContentAddressedChunk)(rootChunk), identifier, signer);
|
|
145
|
+
return uploadSingleOwnerChunk(requestOptions, soc, stamp, options);
|
|
146
|
+
}
|
|
147
|
+
exports.uploadSingleOwnerChunkWithWrappedChunk = uploadSingleOwnerChunkWithWrappedChunk;
|
|
141
148
|
/**
|
|
142
149
|
* Helper function to download SOC.
|
|
143
150
|
*
|
package/dist/cjs/feed/index.js
CHANGED
|
@@ -23,13 +23,16 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.makeFeedWriter = exports.makeFeedReader = exports.downloadFeedUpdate = exports.getFeedUpdateChunkReference = exports.updateFeedWithPayload = exports.updateFeedWithReference = exports.findNextIndex = void 0;
|
|
26
|
+
exports.makeFeedWriter = exports.makeFeedReader = exports.downloadFeedUpdateAsCAC = exports.downloadFeedUpdate = exports.getFeedUpdateChunkReference = exports.updateFeedWithPayload = exports.updateFeedWithReference = exports.findNextIndex = void 0;
|
|
27
27
|
const cafe_utility_1 = require("cafe-utility");
|
|
28
|
+
const cac_1 = require("../chunk/cac");
|
|
28
29
|
const soc_1 = require("../chunk/soc");
|
|
30
|
+
const bytes = __importStar(require("../modules/bytes"));
|
|
29
31
|
const chunkAPI = __importStar(require("../modules/chunk"));
|
|
30
32
|
const feed_1 = require("../modules/feed");
|
|
31
33
|
const bytes_1 = require("../utils/bytes");
|
|
32
34
|
const error_1 = require("../utils/error");
|
|
35
|
+
const resource_locator_1 = require("../utils/resource-locator");
|
|
33
36
|
const typed_bytes_1 = require("../utils/typed-bytes");
|
|
34
37
|
const identifier_1 = require("./identifier");
|
|
35
38
|
const TIMESTAMP_PAYLOAD_OFFSET = 0;
|
|
@@ -64,6 +67,11 @@ exports.updateFeedWithReference = updateFeedWithReference;
|
|
|
64
67
|
async function updateFeedWithPayload(requestOptions, signer, topic, data, postageBatchId, options) {
|
|
65
68
|
const nextIndex = options?.index ?? (await findNextIndex(requestOptions, signer.publicKey().address(), topic));
|
|
66
69
|
const identifier = (0, identifier_1.makeFeedIdentifier)(topic, nextIndex);
|
|
70
|
+
if (data.length > 4096) {
|
|
71
|
+
const uploadResult = await bytes.upload(requestOptions, data, postageBatchId, options);
|
|
72
|
+
const rootChunk = await chunkAPI.download(requestOptions, uploadResult.reference);
|
|
73
|
+
return (0, soc_1.uploadSingleOwnerChunkWithWrappedChunk)(requestOptions, signer, postageBatchId, identifier, rootChunk, options);
|
|
74
|
+
}
|
|
67
75
|
return (0, soc_1.uploadSingleOwnerChunkData)(requestOptions, signer, postageBatchId, identifier, cafe_utility_1.Types.isString(data) ? bytes_1.Bytes.fromUtf8(data).toUint8Array() : data, options);
|
|
68
76
|
}
|
|
69
77
|
exports.updateFeedWithPayload = updateFeedWithPayload;
|
|
@@ -88,6 +96,13 @@ async function downloadFeedUpdate(requestOptions, owner, topic, index, hasTimest
|
|
|
88
96
|
};
|
|
89
97
|
}
|
|
90
98
|
exports.downloadFeedUpdate = downloadFeedUpdate;
|
|
99
|
+
async function downloadFeedUpdateAsCAC(requestOptions, owner, topic, index) {
|
|
100
|
+
index = typeof index === 'number' ? typed_bytes_1.FeedIndex.fromBigInt(BigInt(index)) : index;
|
|
101
|
+
const address = getFeedUpdateChunkReference(owner, topic, index);
|
|
102
|
+
const data = await chunkAPI.download(requestOptions, address);
|
|
103
|
+
return (0, cac_1.asContentAddressedChunk)(data.slice(typed_bytes_1.Identifier.LENGTH + typed_bytes_1.Signature.LENGTH));
|
|
104
|
+
}
|
|
105
|
+
exports.downloadFeedUpdateAsCAC = downloadFeedUpdateAsCAC;
|
|
91
106
|
function makeFeedReader(requestOptions, topic, owner) {
|
|
92
107
|
// TODO: remove after enough time has passed in deprecated version
|
|
93
108
|
const download = async (options) => {
|
|
@@ -105,10 +120,13 @@ function makeFeedReader(requestOptions, topic, owner) {
|
|
|
105
120
|
if (options?.index === undefined) {
|
|
106
121
|
return (0, feed_1.fetchLatestFeedUpdate)(requestOptions, owner, topic);
|
|
107
122
|
}
|
|
108
|
-
const
|
|
123
|
+
const cac = await downloadFeedUpdateAsCAC(requestOptions, owner, topic, options.index);
|
|
124
|
+
const payload = cac.span.toBigInt() <= 4096n
|
|
125
|
+
? cac.payload
|
|
126
|
+
: await bytes.download(requestOptions, new resource_locator_1.ResourceLocator(cac.address));
|
|
109
127
|
const feedIndex = typeof options.index === 'number' ? typed_bytes_1.FeedIndex.fromBigInt(BigInt(options.index)) : options.index;
|
|
110
128
|
return {
|
|
111
|
-
payload
|
|
129
|
+
payload,
|
|
112
130
|
feedIndex,
|
|
113
131
|
};
|
|
114
132
|
};
|