@ethersphere/bee-js 3.3.3 → 4.0.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/LICENSE +24 -22
- package/README.md +0 -8
- package/dist/cjs/bee.js +71 -18
- package/dist/cjs/feed/identifier.js +35 -0
- package/dist/cjs/feed/index.js +34 -90
- package/dist/cjs/feed/retrievable.js +72 -0
- package/dist/cjs/modules/debug/status.js +3 -3
- package/dist/cjs/modules/feed.js +3 -3
- package/dist/cjs/types/index.js +2 -1
- package/dist/cjs/utils/bytes.js +15 -1
- package/dist/cjs/utils/data.browser.js +6 -10
- package/dist/cjs/utils/data.js +4 -6
- package/dist/cjs/utils/reference.js +36 -0
- package/dist/cjs/utils/type.js +36 -1
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/bee.js +77 -19
- package/dist/mjs/chunk/cac.js +1 -1
- package/dist/mjs/feed/identifier.js +35 -0
- package/dist/mjs/feed/index.js +39 -94
- package/dist/mjs/feed/retrievable.js +105 -0
- package/dist/mjs/modules/debug/status.js +3 -3
- package/dist/mjs/modules/feed.js +1 -1
- package/dist/mjs/types/index.js +1 -0
- package/dist/mjs/utils/bytes.js +15 -0
- package/dist/mjs/utils/data.browser.js +0 -1
- package/dist/mjs/utils/data.js +4 -5
- package/dist/mjs/utils/reference.js +32 -0
- package/dist/mjs/utils/type.js +38 -1
- package/dist/types/bee.d.ts +49 -19
- package/dist/types/chunk/cac.d.ts +4 -5
- package/dist/types/chunk/soc.d.ts +4 -4
- package/dist/types/feed/identifier.d.ts +4 -0
- package/dist/types/feed/index.d.ts +9 -16
- package/dist/types/feed/retrievable.d.ts +5 -0
- package/dist/types/modules/bytes.d.ts +3 -3
- package/dist/types/modules/bzz.d.ts +3 -3
- package/dist/types/modules/chunk.d.ts +2 -2
- package/dist/types/modules/debug/status.d.ts +3 -3
- package/dist/types/modules/feed.d.ts +12 -1
- package/dist/types/modules/stewardship.d.ts +3 -3
- package/dist/types/types/debug.d.ts +20 -3
- package/dist/types/types/index.d.ts +11 -2
- package/dist/types/utils/bytes.d.ts +7 -0
- package/dist/types/utils/data.browser.d.ts +0 -1
- package/dist/types/utils/data.d.ts +2 -2
- package/dist/types/utils/reference.d.ts +2 -0
- package/dist/types/utils/type.d.ts +2 -1
- package/package.json +33 -33
package/dist/mjs/bee.js
CHANGED
|
@@ -50,13 +50,14 @@ import { createFeedManifest } from "./modules/feed.js";
|
|
|
50
50
|
import { assertBeeUrl, stripLastSlash } from "./utils/url.js";
|
|
51
51
|
import { makeEthAddress, makeHexEthAddress } from "./utils/eth.js";
|
|
52
52
|
import { wrapBytesWithHelpers } from "./utils/bytes.js";
|
|
53
|
-
import { assertAddressPrefix, assertAllTagsOptions, assertBatchId, assertCollectionUploadOptions, assertData, assertFileData, assertFileUploadOptions, assertPssMessageHandler, assertPublicKey, assertReference, assertRequestOptions, assertUploadOptions, makeTagUid } from "./utils/type.js";
|
|
53
|
+
import { assertAddressPrefix, assertAllTagsOptions, assertBatchId, assertCollectionUploadOptions, assertData, assertFileData, assertFileUploadOptions, assertPssMessageHandler, assertPublicKey, assertReference, assertReferenceOrEns, assertRequestOptions, assertUploadOptions, makeTagUid } from "./utils/type.js";
|
|
54
54
|
import { setJsonData, getJsonData } from "./feed/json.js";
|
|
55
55
|
import { makeCollectionFromFileList, assertCollection } from "./utils/collection.js";
|
|
56
56
|
import { makeCollectionFromFS } from "./utils/collection.node.js";
|
|
57
57
|
import { CHUNK_SIZE, SPAN_SIZE } from "./types/index.js";
|
|
58
58
|
import { makeDefaultKy, wrapRequestClosure, wrapResponseClosure } from "./utils/http.js";
|
|
59
59
|
import { isReadable } from "./utils/stream.js";
|
|
60
|
+
import { areAllSequentialFeedsUpdateRetrievable } from "./feed/retrievable.js";
|
|
60
61
|
/**
|
|
61
62
|
* The main component that abstracts operations available on the main Bee API.
|
|
62
63
|
*
|
|
@@ -131,8 +132,10 @@ export class Bee {
|
|
|
131
132
|
/**
|
|
132
133
|
* Download data as a byte array
|
|
133
134
|
*
|
|
134
|
-
* @param reference Bee data reference
|
|
135
|
+
* @param reference Bee data reference in hex string (either 64 or 128 chars long) or ENS domain.
|
|
135
136
|
* @param options Options that affects the request behavior
|
|
137
|
+
* @throws TypeError if some of the input parameters is not expected type
|
|
138
|
+
* @throws BeeArgumentError if there is passed ENS domain with invalid unicode characters
|
|
136
139
|
* @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/access-the-swarm/upload-and-download)
|
|
137
140
|
* @see [Bee API reference - `GET /bytes`](https://docs.ethswarm.org/api/#tag/Bytes/paths/~1bytes~1{reference}/get)
|
|
138
141
|
*/
|
|
@@ -141,15 +144,17 @@ export class Bee {
|
|
|
141
144
|
downloadData(reference, options) {
|
|
142
145
|
return __awaiter(this, void 0, void 0, function* () {
|
|
143
146
|
assertRequestOptions(options);
|
|
144
|
-
|
|
147
|
+
assertReferenceOrEns(reference);
|
|
145
148
|
return bytes.download(this.getKy(options), reference);
|
|
146
149
|
});
|
|
147
150
|
}
|
|
148
151
|
/**
|
|
149
152
|
* Download data as a Readable stream
|
|
150
153
|
*
|
|
151
|
-
* @param reference Bee data reference
|
|
154
|
+
* @param reference Bee data reference in hex string (either 64 or 128 chars long) or ENS domain.
|
|
152
155
|
* @param options Options that affects the request behavior
|
|
156
|
+
* @throws TypeError if some of the input parameters is not expected type
|
|
157
|
+
* @throws BeeArgumentError if there is passed ENS domain with invalid unicode characters
|
|
153
158
|
* @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/access-the-swarm/upload-and-download)
|
|
154
159
|
* @see [Bee API reference - `GET /bytes`](https://docs.ethswarm.org/api/#tag/Bytes/paths/~1bytes~1{reference}/get)
|
|
155
160
|
*/
|
|
@@ -158,7 +163,7 @@ export class Bee {
|
|
|
158
163
|
downloadReadableData(reference, options) {
|
|
159
164
|
return __awaiter(this, void 0, void 0, function* () {
|
|
160
165
|
assertRequestOptions(options);
|
|
161
|
-
|
|
166
|
+
assertReferenceOrEns(reference);
|
|
162
167
|
return bytes.downloadReadable(this.getKy(options), reference);
|
|
163
168
|
});
|
|
164
169
|
}
|
|
@@ -198,8 +203,10 @@ export class Bee {
|
|
|
198
203
|
/**
|
|
199
204
|
* Download chunk as a byte array
|
|
200
205
|
*
|
|
201
|
-
* @param reference Bee chunk reference
|
|
206
|
+
* @param reference Bee chunk reference in hex string (either 64 or 128 chars long) or ENS domain.
|
|
202
207
|
* @param options Options that affects the request behavior
|
|
208
|
+
* @throws TypeError if some of the input parameters is not expected type
|
|
209
|
+
* @throws BeeArgumentError if there is passed ENS domain with invalid unicode characters
|
|
203
210
|
* @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/access-the-swarm/upload-and-download)
|
|
204
211
|
* @see [Bee API reference - `GET /chunks`](https://docs.ethswarm.org/api/#tag/Chunk/paths/~1chunks~1{reference}/get)
|
|
205
212
|
*/
|
|
@@ -208,7 +215,7 @@ export class Bee {
|
|
|
208
215
|
downloadChunk(reference, options) {
|
|
209
216
|
return __awaiter(this, void 0, void 0, function* () {
|
|
210
217
|
assertRequestOptions(options);
|
|
211
|
-
|
|
218
|
+
assertReferenceOrEns(reference);
|
|
212
219
|
return chunk.download(this.getKy(options), reference);
|
|
213
220
|
});
|
|
214
221
|
}
|
|
@@ -261,10 +268,11 @@ export class Bee {
|
|
|
261
268
|
/**
|
|
262
269
|
* Download single file.
|
|
263
270
|
*
|
|
264
|
-
* @param reference Bee file reference
|
|
271
|
+
* @param reference Bee file reference in hex string (either 64 or 128 chars long) or ENS domain.
|
|
265
272
|
* @param path If reference points to manifest, then this parameter defines path to the file
|
|
266
273
|
* @param options Options that affects the request behavior
|
|
267
|
-
*
|
|
274
|
+
* @throws TypeError if some of the input parameters is not expected type
|
|
275
|
+
* @throws BeeArgumentError if there is passed ENS domain with invalid unicode characters
|
|
268
276
|
* @see Data
|
|
269
277
|
* @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/access-the-swarm/upload-and-download)
|
|
270
278
|
* @see [Bee API reference - `GET /bzz`](https://docs.ethswarm.org/api/#tag/Collection/paths/~1bzz~1{reference}~1{path}/get)
|
|
@@ -274,16 +282,18 @@ export class Bee {
|
|
|
274
282
|
downloadFile(reference, path = '', options) {
|
|
275
283
|
return __awaiter(this, void 0, void 0, function* () {
|
|
276
284
|
assertRequestOptions(options);
|
|
277
|
-
|
|
285
|
+
assertReferenceOrEns(reference);
|
|
278
286
|
return bzz.downloadFile(this.getKy(options), reference, path);
|
|
279
287
|
});
|
|
280
288
|
}
|
|
281
289
|
/**
|
|
282
290
|
* Download single file as a readable stream
|
|
283
291
|
*
|
|
284
|
-
* @param reference
|
|
292
|
+
* @param reference Bee file reference in hex string (either 64 or 128 chars long) or ENS domain.
|
|
285
293
|
* @param path If reference points to manifest / collections, then this parameter defines path to the file
|
|
286
294
|
* @param options Options that affects the request behavior
|
|
295
|
+
* @throws TypeError if some of the input parameters is not expected type
|
|
296
|
+
* @throws BeeArgumentError if there is passed ENS domain with invalid unicode characters
|
|
287
297
|
*
|
|
288
298
|
* @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/access-the-swarm/upload-and-download)
|
|
289
299
|
* @see [Bee API reference - `GET /bzz`](https://docs.ethswarm.org/api/#tag/Collection/paths/~1bzz~1{reference}~1{path}/get)
|
|
@@ -293,7 +303,7 @@ export class Bee {
|
|
|
293
303
|
downloadReadableFile(reference, path = '', options) {
|
|
294
304
|
return __awaiter(this, void 0, void 0, function* () {
|
|
295
305
|
assertRequestOptions(options);
|
|
296
|
-
|
|
306
|
+
assertReferenceOrEns(reference);
|
|
297
307
|
return bzz.downloadFileReadable(this.getKy(options), reference, path);
|
|
298
308
|
});
|
|
299
309
|
}
|
|
@@ -541,9 +551,10 @@ export class Bee {
|
|
|
541
551
|
*
|
|
542
552
|
* **Warning! Not allowed when node is in Gateway mode!**
|
|
543
553
|
*
|
|
544
|
-
* @param reference Bee data reference
|
|
554
|
+
* @param reference Bee data reference in hex string (either 64 or 128 chars long) or ENS domain.
|
|
545
555
|
* @param options Options that affects the request behavior
|
|
546
|
-
* @throws TypeError if
|
|
556
|
+
* @throws TypeError if some of the input parameters is not expected type
|
|
557
|
+
* @throws BeeArgumentError if there is passed ENS domain with invalid unicode characters
|
|
547
558
|
*
|
|
548
559
|
* @see [Bee docs - Pinning](https://docs.ethswarm.org/docs/access-the-swarm/pinning)
|
|
549
560
|
*/
|
|
@@ -559,10 +570,11 @@ export class Bee {
|
|
|
559
570
|
/**
|
|
560
571
|
* Instructs the Bee node to reupload a locally pinned data into the network.
|
|
561
572
|
*
|
|
562
|
-
* @param reference
|
|
573
|
+
* @param reference Bee data reference to be re-uploaded in hex string (either 64 or 128 chars long) or ENS domain.
|
|
563
574
|
* @param options Options that affects the request behavior
|
|
564
575
|
* @throws BeeArgumentError if the reference is not locally pinned
|
|
565
|
-
* @throws TypeError if
|
|
576
|
+
* @throws TypeError if some of the input parameters is not expected type
|
|
577
|
+
* @throws BeeArgumentError if there is passed ENS domain with invalid unicode characters
|
|
566
578
|
*
|
|
567
579
|
* @see [Bee API reference - `PUT /stewardship`](https://docs.ethswarm.org/api/#tag/Stewardship/paths/~1stewardship~1{reference}/put)
|
|
568
580
|
*/
|
|
@@ -571,15 +583,17 @@ export class Bee {
|
|
|
571
583
|
reuploadPinnedData(reference, options) {
|
|
572
584
|
return __awaiter(this, void 0, void 0, function* () {
|
|
573
585
|
assertRequestOptions(options);
|
|
574
|
-
|
|
586
|
+
assertReferenceOrEns(reference);
|
|
575
587
|
yield stewardship.reupload(this.getKy(options), reference);
|
|
576
588
|
});
|
|
577
589
|
}
|
|
578
590
|
/**
|
|
579
591
|
* Checks if content specified by reference is retrievable from the network.
|
|
580
592
|
*
|
|
581
|
-
* @param reference
|
|
593
|
+
* @param reference Bee data reference to be checked in hex string (either 64 or 128 chars long) or ENS domain.
|
|
582
594
|
* @param options Options that affects the request behavior
|
|
595
|
+
* @throws TypeError if some of the input parameters is not expected type
|
|
596
|
+
* @throws BeeArgumentError if there is passed ENS domain with invalid unicode characters
|
|
583
597
|
*
|
|
584
598
|
* @see [Bee API reference - `GET /stewardship`](https://docs.ethswarm.org/api/#tag/Stewardship/paths/~1stewardship~1{reference}/get)
|
|
585
599
|
*/
|
|
@@ -588,10 +602,54 @@ export class Bee {
|
|
|
588
602
|
isReferenceRetrievable(reference, options) {
|
|
589
603
|
return __awaiter(this, void 0, void 0, function* () {
|
|
590
604
|
assertRequestOptions(options);
|
|
591
|
-
|
|
605
|
+
assertReferenceOrEns(reference);
|
|
592
606
|
return stewardship.isRetrievable(this.getKy(options), reference);
|
|
593
607
|
});
|
|
594
608
|
}
|
|
609
|
+
/**
|
|
610
|
+
* Functions that validates if feed is retrievable in the network.
|
|
611
|
+
*
|
|
612
|
+
* If no index is passed then it check for "latest" update, which is a weaker guarantee as nobody can be really
|
|
613
|
+
* sure what is the "latest" update.
|
|
614
|
+
*
|
|
615
|
+
* If index is passed then it validates all previous sequence index chunks if they are available as they are required
|
|
616
|
+
* to correctly resolve the feed upto the given index update.
|
|
617
|
+
*
|
|
618
|
+
* @param type
|
|
619
|
+
* @param owner
|
|
620
|
+
* @param topic
|
|
621
|
+
* @param index
|
|
622
|
+
* @param options
|
|
623
|
+
*/
|
|
624
|
+
|
|
625
|
+
|
|
626
|
+
isFeedRetrievable(type, owner, topic, index, options) {
|
|
627
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
628
|
+
const canonicalOwner = makeEthAddress(owner);
|
|
629
|
+
const canonicalTopic = makeTopic(topic);
|
|
630
|
+
|
|
631
|
+
if (!index) {
|
|
632
|
+
try {
|
|
633
|
+
yield this.makeFeedReader(type, canonicalTopic, canonicalOwner).download();
|
|
634
|
+
return true;
|
|
635
|
+
} catch (e) {
|
|
636
|
+
const err = e; // Only if the error is "not-found" then we return false otherwise we re-throw the error
|
|
637
|
+
|
|
638
|
+
if ((err === null || err === void 0 ? void 0 : err.status) === 404) {
|
|
639
|
+
return false;
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
throw e;
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
if (type !== 'sequence') {
|
|
647
|
+
throw new BeeError('Only Sequence type of Feeds is supported at the moment');
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
return areAllSequentialFeedsUpdateRetrievable(this, canonicalOwner, canonicalTopic, index, options);
|
|
651
|
+
});
|
|
652
|
+
}
|
|
595
653
|
/**
|
|
596
654
|
* Send data to recipient or target with Postal Service for Swarm.
|
|
597
655
|
*
|
package/dist/mjs/chunk/cac.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BeeError } from "../utils/error.js";
|
|
2
2
|
import { bmtHash } from "./bmt.js";
|
|
3
|
-
import { bytesEqual, flexBytesAtOffset
|
|
3
|
+
import { assertFlexBytes, bytesEqual, flexBytesAtOffset } from "../utils/bytes.js";
|
|
4
4
|
import { serializeBytes } from "./serialize.js";
|
|
5
5
|
import { makeSpan, SPAN_SIZE } from "./span.js";
|
|
6
6
|
export const MIN_PAYLOAD_SIZE = 1;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { FEED_INDEX_HEX_LENGTH } from "../types/index.js";
|
|
2
|
+
import { keccak256Hash } from "../utils/hash.js";
|
|
3
|
+
import { hexToBytes, makeHexString } from "../utils/hex.js";
|
|
4
|
+
import { writeUint64BigEndian } from "../utils/uint64.js";
|
|
5
|
+
|
|
6
|
+
function isEpoch(epoch) {
|
|
7
|
+
return typeof epoch === 'object' && epoch !== null && 'time' in epoch && 'level' in epoch;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function hashFeedIdentifier(topic, index) {
|
|
11
|
+
return keccak256Hash(hexToBytes(topic), index);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function makeSequentialFeedIdentifier(topic, index) {
|
|
15
|
+
const indexBytes = writeUint64BigEndian(index);
|
|
16
|
+
return hashFeedIdentifier(topic, indexBytes);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function makeFeedIndexBytes(s) {
|
|
20
|
+
const hex = makeHexString(s, FEED_INDEX_HEX_LENGTH);
|
|
21
|
+
return hexToBytes(hex);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function makeFeedIdentifier(topic, index) {
|
|
25
|
+
if (typeof index === 'number') {
|
|
26
|
+
return makeSequentialFeedIdentifier(topic, index);
|
|
27
|
+
} else if (typeof index === 'string') {
|
|
28
|
+
const indexBytes = makeFeedIndexBytes(index);
|
|
29
|
+
return hashFeedIdentifier(topic, indexBytes);
|
|
30
|
+
} else if (isEpoch(index)) {
|
|
31
|
+
throw new TypeError('epoch is not yet implemented');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return hashFeedIdentifier(topic, index);
|
|
35
|
+
}
|
package/dist/mjs/feed/index.js
CHANGED
|
@@ -32,66 +32,26 @@ var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, gene
|
|
|
32
32
|
|
|
33
33
|
import { keccak256Hash } from "../utils/hash.js";
|
|
34
34
|
import { serializeBytes } from "../chunk/serialize.js";
|
|
35
|
-
import {
|
|
36
|
-
import {
|
|
37
|
-
import {
|
|
38
|
-
import {
|
|
35
|
+
import { fetchLatestFeedUpdate } from "../modules/feed.js";
|
|
36
|
+
import { makeSingleOwnerChunkFromData, uploadSingleOwnerChunkData } from "../chunk/soc.js";
|
|
37
|
+
import { FEED_INDEX_HEX_LENGTH } from "../types/index.js";
|
|
38
|
+
import { bytesAtOffset, makeBytes } from "../utils/bytes.js";
|
|
39
39
|
import { BeeResponseError } from "../utils/error.js";
|
|
40
40
|
import { bytesToHex, hexToBytes, makeHexString } from "../utils/hex.js";
|
|
41
41
|
import { readUint64BigEndian, writeUint64BigEndian } from "../utils/uint64.js";
|
|
42
42
|
import * as chunkAPI from "../modules/chunk.js";
|
|
43
43
|
import { makeHexEthAddress } from "../utils/eth.js";
|
|
44
44
|
import { assertAddress } from "../utils/type.js";
|
|
45
|
+
import { makeFeedIdentifier } from "./identifier.js";
|
|
46
|
+
import { makeBytesReference } from "../utils/reference.js";
|
|
45
47
|
const TIMESTAMP_PAYLOAD_OFFSET = 0;
|
|
46
48
|
const TIMESTAMP_PAYLOAD_SIZE = 8;
|
|
47
49
|
const REFERENCE_PAYLOAD_OFFSET = TIMESTAMP_PAYLOAD_SIZE;
|
|
48
|
-
const REFERENCE_PAYLOAD_MIN_SIZE = 32;
|
|
49
|
-
const REFERENCE_PAYLOAD_MAX_SIZE = 64;
|
|
50
|
-
const INDEX_HEX_LENGTH = 16;
|
|
51
|
-
export function isEpoch(epoch) {
|
|
52
|
-
return typeof epoch === 'object' && epoch !== null && 'time' in epoch && 'level' in epoch;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function hashFeedIdentifier(topic, index) {
|
|
56
|
-
return keccak256Hash(hexToBytes(topic), index);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export function makeSequentialFeedIdentifier(topic, index) {
|
|
60
|
-
const indexBytes = writeUint64BigEndian(index);
|
|
61
|
-
return hashFeedIdentifier(topic, indexBytes);
|
|
62
|
-
}
|
|
63
|
-
export function makeFeedIndexBytes(s) {
|
|
64
|
-
const hex = makeHexString(s, INDEX_HEX_LENGTH);
|
|
65
|
-
return hexToBytes(hex);
|
|
66
|
-
}
|
|
67
|
-
export function makeFeedIdentifier(topic, index) {
|
|
68
|
-
if (typeof index === 'number') {
|
|
69
|
-
return makeSequentialFeedIdentifier(topic, index);
|
|
70
|
-
} else if (typeof index === 'string') {
|
|
71
|
-
const indexBytes = makeFeedIndexBytes(index);
|
|
72
|
-
return hashFeedIdentifier(topic, indexBytes);
|
|
73
|
-
} else if (isEpoch(index)) {
|
|
74
|
-
throw new TypeError('epoch is not yet implemented');
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return hashFeedIdentifier(topic, index);
|
|
78
|
-
}
|
|
79
|
-
export function uploadFeedUpdate(ky, signer, topic, index, reference, postageBatchId, options) {
|
|
80
|
-
var _a;
|
|
81
|
-
|
|
82
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
-
const identifier = makeFeedIdentifier(topic, index);
|
|
84
|
-
const at = (_a = options === null || options === void 0 ? void 0 : options.at) !== null && _a !== void 0 ? _a : Date.now() / 1000.0;
|
|
85
|
-
const timestamp = writeUint64BigEndian(at);
|
|
86
|
-
const payloadBytes = serializeBytes(timestamp, reference);
|
|
87
|
-
return uploadSingleOwnerChunkData(ky, signer, postageBatchId, identifier, payloadBytes, options);
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
50
|
export function findNextIndex(ky, owner, topic, options) {
|
|
91
51
|
return __awaiter(this, void 0, void 0, function* () {
|
|
92
52
|
try {
|
|
93
|
-
const feedUpdate = yield
|
|
94
|
-
return makeHexString(feedUpdate.feedIndexNext,
|
|
53
|
+
const feedUpdate = yield fetchLatestFeedUpdate(ky, owner, topic, options);
|
|
54
|
+
return makeHexString(feedUpdate.feedIndexNext, FEED_INDEX_HEX_LENGTH);
|
|
95
55
|
} catch (e) {
|
|
96
56
|
if (e instanceof BeeResponseError && e.status === 404) {
|
|
97
57
|
return bytesToHex(makeBytes(8));
|
|
@@ -101,36 +61,33 @@ export function findNextIndex(ky, owner, topic, options) {
|
|
|
101
61
|
}
|
|
102
62
|
});
|
|
103
63
|
}
|
|
104
|
-
export function updateFeed(ky, signer, topic, reference, postageBatchId, options) {
|
|
64
|
+
export function updateFeed(ky, signer, topic, reference, postageBatchId, options, index = 'latest') {
|
|
65
|
+
var _a;
|
|
66
|
+
|
|
105
67
|
return __awaiter(this, void 0, void 0, function* () {
|
|
106
68
|
const ownerHex = makeHexEthAddress(signer.address);
|
|
107
|
-
const nextIndex = yield findNextIndex(ky, ownerHex, topic, options);
|
|
108
|
-
|
|
69
|
+
const nextIndex = index === 'latest' ? yield findNextIndex(ky, ownerHex, topic, options) : index;
|
|
70
|
+
const identifier = makeFeedIdentifier(topic, nextIndex);
|
|
71
|
+
const at = (_a = options === null || options === void 0 ? void 0 : options.at) !== null && _a !== void 0 ? _a : Date.now() / 1000.0;
|
|
72
|
+
const timestamp = writeUint64BigEndian(at);
|
|
73
|
+
const payloadBytes = serializeBytes(timestamp, reference);
|
|
74
|
+
return uploadSingleOwnerChunkData(ky, signer, postageBatchId, identifier, payloadBytes, options);
|
|
109
75
|
});
|
|
110
76
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
return bytesAtOffset(data, offset, REFERENCE_PAYLOAD_MAX_SIZE);
|
|
115
|
-
} catch (e) {
|
|
116
|
-
return bytesAtOffset(data, offset, REFERENCE_PAYLOAD_MIN_SIZE);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
export function verifyChunkReference(data) {
|
|
121
|
-
return verifyChunkReferenceAtOffset(0, data);
|
|
77
|
+
export function getFeedUpdateChunkReference(owner, topic, index) {
|
|
78
|
+
const identifier = makeFeedIdentifier(topic, index);
|
|
79
|
+
return keccak256Hash(identifier, owner);
|
|
122
80
|
}
|
|
123
81
|
export function downloadFeedUpdate(ky, owner, topic, index) {
|
|
124
82
|
return __awaiter(this, void 0, void 0, function* () {
|
|
125
|
-
const
|
|
126
|
-
const address = keccak256Hash(identifier, owner);
|
|
83
|
+
const address = getFeedUpdateChunkReference(owner, topic, index);
|
|
127
84
|
const addressHex = bytesToHex(address);
|
|
128
85
|
const data = yield chunkAPI.download(ky, addressHex);
|
|
129
86
|
const soc = makeSingleOwnerChunkFromData(data, address);
|
|
130
87
|
const payload = soc.payload();
|
|
131
88
|
const timestampBytes = bytesAtOffset(payload, TIMESTAMP_PAYLOAD_OFFSET, TIMESTAMP_PAYLOAD_SIZE);
|
|
132
89
|
const timestamp = readUint64BigEndian(timestampBytes);
|
|
133
|
-
const reference =
|
|
90
|
+
const reference = makeBytesReference(payload, REFERENCE_PAYLOAD_OFFSET);
|
|
134
91
|
return {
|
|
135
92
|
timestamp,
|
|
136
93
|
reference
|
|
@@ -138,46 +95,34 @@ export function downloadFeedUpdate(ky, owner, topic, index) {
|
|
|
138
95
|
});
|
|
139
96
|
}
|
|
140
97
|
export function makeFeedReader(ky, type, topic, owner) {
|
|
141
|
-
const download = options => __awaiter(this, void 0, void 0, function* () {
|
|
142
|
-
return fetchFeedUpdate(ky, owner, topic, Object.assign(Object.assign({}, options), {
|
|
143
|
-
type
|
|
144
|
-
}));
|
|
145
|
-
});
|
|
146
|
-
|
|
147
98
|
return {
|
|
148
99
|
type,
|
|
149
100
|
owner,
|
|
150
101
|
topic,
|
|
151
|
-
download
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
function makeChunkReference(reference) {
|
|
156
|
-
if (typeof reference === 'string') {
|
|
157
|
-
try {
|
|
158
|
-
// Non-encrypted chunk hex string reference
|
|
159
|
-
const hexReference = makeHexString(reference, REFERENCE_HEX_LENGTH);
|
|
160
|
-
return hexToBytes(hexReference);
|
|
161
|
-
} catch (e) {
|
|
162
|
-
if (!(e instanceof TypeError)) {
|
|
163
|
-
throw e;
|
|
164
|
-
} // Encrypted chunk hex string reference
|
|
165
|
-
|
|
166
102
|
|
|
167
|
-
|
|
168
|
-
return
|
|
103
|
+
download(options) {
|
|
104
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
105
|
+
if (!(options === null || options === void 0 ? void 0 : options.index)) {
|
|
106
|
+
return fetchLatestFeedUpdate(ky, owner, topic, Object.assign(Object.assign({}, options), {
|
|
107
|
+
type
|
|
108
|
+
}));
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const update = yield downloadFeedUpdate(ky, hexToBytes(owner), topic, options.index);
|
|
112
|
+
return {
|
|
113
|
+
reference: bytesToHex(update.reference),
|
|
114
|
+
feedIndex: options.index,
|
|
115
|
+
feedIndexNext: ''
|
|
116
|
+
};
|
|
117
|
+
});
|
|
169
118
|
}
|
|
170
|
-
} else if (reference instanceof Uint8Array) {
|
|
171
|
-
return verifyChunkReference(reference);
|
|
172
|
-
}
|
|
173
119
|
|
|
174
|
-
|
|
120
|
+
};
|
|
175
121
|
}
|
|
176
|
-
|
|
177
122
|
export function makeFeedWriter(ky, type, topic, signer) {
|
|
178
123
|
const upload = (postageBatchId, reference, options) => __awaiter(this, void 0, void 0, function* () {
|
|
179
124
|
assertAddress(postageBatchId);
|
|
180
|
-
const canonicalReference =
|
|
125
|
+
const canonicalReference = makeBytesReference(reference);
|
|
181
126
|
return updateFeed(ky, signer, topic, canonicalReference, postageBatchId, Object.assign(Object.assign({}, options), {
|
|
182
127
|
type
|
|
183
128
|
}));
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) {
|
|
3
|
+
return value instanceof P ? value : new P(function (resolve) {
|
|
4
|
+
resolve(value);
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
9
|
+
function fulfilled(value) {
|
|
10
|
+
try {
|
|
11
|
+
step(generator.next(value));
|
|
12
|
+
} catch (e) {
|
|
13
|
+
reject(e);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function rejected(value) {
|
|
18
|
+
try {
|
|
19
|
+
step(generator["throw"](value));
|
|
20
|
+
} catch (e) {
|
|
21
|
+
reject(e);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function step(result) {
|
|
26
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
import { getFeedUpdateChunkReference } from "./index.js";
|
|
34
|
+
import { readUint64BigEndian } from "../utils/uint64.js";
|
|
35
|
+
import { bytesToHex } from "../utils/hex.js";
|
|
36
|
+
|
|
37
|
+
function makeNumericIndex(index) {
|
|
38
|
+
if (index instanceof Uint8Array) {
|
|
39
|
+
return readUint64BigEndian(index);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (typeof index === 'string') {
|
|
43
|
+
return parseInt(index);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (typeof index === 'number') {
|
|
47
|
+
return index;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
throw new TypeError('Unknown type of index!');
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Function that checks if a chunk is retrievable by actually downloading it.
|
|
54
|
+
* The /stewardship/{reference} endpoint does not support verification of chunks, but only manifest's references.
|
|
55
|
+
*
|
|
56
|
+
* @param bee
|
|
57
|
+
* @param ref
|
|
58
|
+
* @param options
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
function isChunkRetrievable(bee, ref, options) {
|
|
63
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
try {
|
|
65
|
+
yield bee.downloadChunk(ref, options);
|
|
66
|
+
return true;
|
|
67
|
+
} catch (e) {
|
|
68
|
+
const err = e;
|
|
69
|
+
|
|
70
|
+
if (err.status === 404) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
throw e;
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Creates array of references for all sequence updates chunk up to the given index.
|
|
80
|
+
*
|
|
81
|
+
* @param owner
|
|
82
|
+
* @param topic
|
|
83
|
+
* @param index
|
|
84
|
+
*/
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
function getAllSequenceUpdateReferences(owner, topic, index) {
|
|
88
|
+
const numIndex = makeNumericIndex(index);
|
|
89
|
+
const updateReferences = new Array(numIndex + 1);
|
|
90
|
+
|
|
91
|
+
for (let i = 0; i <= numIndex; i++) {
|
|
92
|
+
updateReferences[i] = bytesToHex(getFeedUpdateChunkReference(owner, topic, i));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return updateReferences;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function areAllSequentialFeedsUpdateRetrievable(bee, owner, topic, index, options) {
|
|
99
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
100
|
+
const chunkRetrievablePromises = getAllSequenceUpdateReferences(owner, topic, index).map(ref => __awaiter(this, void 0, void 0, function* () {
|
|
101
|
+
return isChunkRetrievable(bee, ref, options);
|
|
102
|
+
}));
|
|
103
|
+
return (yield Promise.all(chunkRetrievablePromises)).every(result => result);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
@@ -34,9 +34,9 @@ import { http } from "../../utils/http.js";
|
|
|
34
34
|
import getMajorSemver from 'semver/functions/major.js'; // Following lines bellow are automatically updated with GitHub Action when Bee version is updated
|
|
35
35
|
// so if you are changing anything about them change the `update_bee` action accordingly!
|
|
36
36
|
|
|
37
|
-
export const SUPPORTED_BEE_VERSION_EXACT = '1.
|
|
38
|
-
export const SUPPORTED_API_VERSION = '3.0.
|
|
39
|
-
export const SUPPORTED_DEBUG_API_VERSION = '2.0.
|
|
37
|
+
export const SUPPORTED_BEE_VERSION_EXACT = '1.6.0-6ceadd35';
|
|
38
|
+
export const SUPPORTED_API_VERSION = '3.0.1';
|
|
39
|
+
export const SUPPORTED_DEBUG_API_VERSION = '2.0.1';
|
|
40
40
|
export const SUPPORTED_BEE_VERSION = SUPPORTED_BEE_VERSION_EXACT.substring(0, SUPPORTED_BEE_VERSION_EXACT.indexOf('-'));
|
|
41
41
|
const NODE_INFO_URL = 'node';
|
|
42
42
|
const HEALTH_URL = 'health';
|
package/dist/mjs/modules/feed.js
CHANGED
|
@@ -89,7 +89,7 @@ function readFeedUpdateHeaders(headers) {
|
|
|
89
89
|
*/
|
|
90
90
|
|
|
91
91
|
|
|
92
|
-
export function
|
|
92
|
+
export function fetchLatestFeedUpdate(ky, owner, topic, options) {
|
|
93
93
|
return __awaiter(this, void 0, void 0, function* () {
|
|
94
94
|
const response = yield http(ky, {
|
|
95
95
|
responseType: 'json',
|
package/dist/mjs/types/index.js
CHANGED
|
@@ -23,6 +23,7 @@ export const STAMPS_DEPTH_MIN = 17;
|
|
|
23
23
|
export const STAMPS_DEPTH_MAX = 255;
|
|
24
24
|
export const TAGS_LIMIT_MIN = 1;
|
|
25
25
|
export const TAGS_LIMIT_MAX = 1000;
|
|
26
|
+
export const FEED_INDEX_HEX_LENGTH = 16;
|
|
26
27
|
/*********************************************************
|
|
27
28
|
* Writers and Readers interfaces
|
|
28
29
|
*/
|
package/dist/mjs/utils/bytes.js
CHANGED
|
@@ -9,6 +9,21 @@ import { bytesToHex } from "./hex.js";
|
|
|
9
9
|
export function isBytes(b, length) {
|
|
10
10
|
return b instanceof Uint8Array && b.length === length;
|
|
11
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* Function that verifies if passed data are Bytes and if the array has "length" number of bytes under given offset.
|
|
14
|
+
* @param data
|
|
15
|
+
* @param offset
|
|
16
|
+
* @param length
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
export function hasBytesAtOffset(data, offset, length) {
|
|
20
|
+
if (!(data instanceof Uint8Array)) {
|
|
21
|
+
throw new TypeError('Data has to an Uint8Array!');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const offsetBytes = data.slice(offset, offset + length);
|
|
25
|
+
return isBytes(offsetBytes, length);
|
|
26
|
+
}
|
|
12
27
|
/**
|
|
13
28
|
* Verifies if a byte array has a certain length
|
|
14
29
|
*
|
package/dist/mjs/utils/data.js
CHANGED
|
@@ -30,7 +30,7 @@ var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, gene
|
|
|
30
30
|
});
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
-
import
|
|
33
|
+
import BlobPolyfill from 'fetch-blob';
|
|
34
34
|
import { isNodeReadable, isReadableStream, readableWebToNode } from "./stream.js";
|
|
35
35
|
/**
|
|
36
36
|
* Prepare data for valid input for node-fetch.
|
|
@@ -43,17 +43,17 @@ import { isNodeReadable, isReadableStream, readableWebToNode } from "./stream.js
|
|
|
43
43
|
|
|
44
44
|
export function prepareData(data) {
|
|
45
45
|
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
-
if (typeof data === 'string') return new
|
|
46
|
+
if (typeof data === 'string') return new BlobPolyfill([data], {
|
|
47
47
|
type: 'text/plain'
|
|
48
48
|
});
|
|
49
49
|
|
|
50
50
|
if (data instanceof Uint8Array || data instanceof ArrayBuffer) {
|
|
51
|
-
return new
|
|
51
|
+
return new BlobPolyfill([data], {
|
|
52
52
|
type: 'application/octet-stream'
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
if (data instanceof
|
|
56
|
+
if (data instanceof BlobPolyfill || isNodeReadable(data)) return data;
|
|
57
57
|
|
|
58
58
|
if (isReadableStream(data)) {
|
|
59
59
|
return readableWebToNode(data);
|
|
@@ -72,7 +72,6 @@ export function prepareWebsocketData(data) {
|
|
|
72
72
|
if (typeof data === 'string') return new TextEncoder().encode(data);
|
|
73
73
|
if (data instanceof Buffer) return new Uint8Array(data);
|
|
74
74
|
if (data instanceof ArrayBuffer) return new Uint8Array(data);
|
|
75
|
-
if (data instanceof Blob) return new Uint8Array(yield new Response(data).arrayBuffer());
|
|
76
75
|
if (isBufferArray(data)) return new Uint8Array(Buffer.concat(data));
|
|
77
76
|
throw new TypeError('unknown websocket data type');
|
|
78
77
|
});
|