@ethersphere/bee-js 3.3.4 → 4.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/README.md +3 -22
- package/dist/cjs/{bee-debug.js → src/bee-debug.js} +31 -8
- package/dist/cjs/{bee.js → src/bee.js} +79 -24
- package/dist/cjs/{chunk → src/chunk}/bmt.js +0 -0
- package/dist/cjs/{chunk → src/chunk}/cac.js +0 -0
- package/dist/cjs/{chunk → src/chunk}/serialize.js +0 -0
- package/dist/cjs/{chunk → src/chunk}/signer.js +0 -0
- package/dist/cjs/{chunk → src/chunk}/soc.js +0 -0
- package/dist/cjs/{chunk → src/chunk}/span.js +0 -0
- package/dist/cjs/src/feed/identifier.js +35 -0
- package/dist/cjs/{feed → src/feed}/index.js +34 -90
- package/dist/cjs/{feed → src/feed}/json.js +0 -0
- package/dist/cjs/src/feed/retrievable.js +72 -0
- package/dist/cjs/{feed → src/feed}/topic.js +0 -0
- package/dist/cjs/{feed → src/feed}/type.js +0 -0
- package/dist/cjs/{index.js → src/index.js} +0 -0
- package/dist/cjs/{modules → src/modules}/bytes.js +0 -0
- package/dist/cjs/{modules → src/modules}/bzz.js +0 -0
- package/dist/cjs/{modules → src/modules}/chunk.js +0 -0
- package/dist/cjs/{modules → src/modules}/debug/balance.js +0 -0
- package/dist/cjs/{modules → src/modules}/debug/chequebook.js +0 -0
- package/dist/cjs/{modules → src/modules}/debug/chunk.js +0 -0
- package/dist/cjs/{modules → src/modules}/debug/connectivity.js +0 -0
- package/dist/cjs/{modules → src/modules}/debug/settlements.js +0 -0
- package/dist/cjs/{modules → src/modules}/debug/stamps.js +0 -0
- package/dist/cjs/{modules → src/modules}/debug/states.js +18 -1
- package/dist/cjs/{modules → src/modules}/debug/status.js +3 -3
- package/dist/cjs/{modules → src/modules}/debug/tag.js +0 -0
- package/dist/cjs/{modules → src/modules}/debug/transactions.js +0 -0
- package/dist/cjs/{modules → src/modules}/feed.js +3 -3
- package/dist/cjs/{modules → src/modules}/pinning.js +0 -0
- package/dist/cjs/{modules → src/modules}/pss.js +0 -0
- package/dist/cjs/{modules → src/modules}/soc.js +0 -0
- package/dist/cjs/{modules → src/modules}/status.js +0 -0
- package/dist/cjs/{modules → src/modules}/stewardship.js +0 -0
- package/dist/cjs/{modules → src/modules}/tag.js +0 -0
- package/dist/cjs/{types → src/types}/debug.js +0 -0
- package/dist/cjs/{types → src/types}/index.js +2 -1
- package/dist/cjs/{types → src/types}/ky-options.js +0 -0
- package/dist/cjs/{types → src/types}/ky-universal/common.js +0 -0
- package/dist/cjs/{types → src/types}/ky-universal/hooks.js +0 -0
- package/dist/cjs/{types → src/types}/ky-universal/retry.js +0 -0
- package/dist/cjs/{utils → src/utils}/bytes.js +15 -1
- package/dist/cjs/{utils → src/utils}/collection.browser.js +0 -0
- package/dist/cjs/{utils → src/utils}/collection.js +0 -0
- package/dist/cjs/{utils → src/utils}/collection.node.js +0 -0
- package/dist/cjs/{utils → src/utils}/data.browser.js +0 -0
- package/dist/cjs/{utils → src/utils}/data.js +0 -0
- package/dist/cjs/{utils → src/utils}/error.js +0 -0
- package/dist/cjs/{utils → src/utils}/eth.js +0 -0
- package/dist/cjs/{utils → src/utils}/expose.js +0 -0
- package/dist/cjs/{utils → src/utils}/file.js +0 -0
- package/dist/cjs/{utils → src/utils}/hash.js +0 -0
- package/dist/cjs/{utils → src/utils}/headers.js +0 -0
- package/dist/cjs/{utils → src/utils}/hex.js +0 -0
- package/dist/cjs/{utils → src/utils}/http.js +6 -0
- package/dist/cjs/{utils → src/utils}/merge.js +0 -0
- package/dist/cjs/{utils → src/utils}/pss.js +0 -0
- package/dist/cjs/src/utils/reference.js +36 -0
- package/dist/cjs/{utils → src/utils}/stamps.js +0 -0
- package/dist/cjs/{utils → src/utils}/stream.js +0 -0
- package/dist/cjs/{utils → src/utils}/tar.js +0 -0
- package/dist/cjs/{utils → src/utils}/type.js +100 -1
- package/dist/cjs/{utils → src/utils}/uint64.js +0 -0
- package/dist/cjs/{utils → src/utils}/url.js +0 -0
- package/dist/cjs/test/utils.js +419 -0
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/{bee-debug.js → src/bee-debug.js} +40 -10
- package/dist/mjs/{bee.js → src/bee.js} +87 -27
- package/dist/mjs/{chunk → src/chunk}/bmt.js +0 -0
- package/dist/mjs/{chunk → src/chunk}/cac.js +1 -1
- package/dist/mjs/{chunk → src/chunk}/serialize.js +0 -0
- package/dist/mjs/{chunk → src/chunk}/signer.js +0 -0
- package/dist/mjs/{chunk → src/chunk}/soc.js +0 -0
- package/dist/mjs/{chunk → src/chunk}/span.js +0 -0
- package/dist/mjs/src/feed/identifier.js +35 -0
- package/dist/mjs/{feed → src/feed}/index.js +39 -94
- package/dist/mjs/{feed → src/feed}/json.js +0 -0
- package/dist/mjs/src/feed/retrievable.js +105 -0
- package/dist/mjs/{feed → src/feed}/topic.js +0 -0
- package/dist/mjs/{feed → src/feed}/type.js +0 -0
- package/dist/mjs/{index.js → src/index.js} +0 -0
- package/dist/mjs/{modules → src/modules}/bytes.js +0 -0
- package/dist/mjs/{modules → src/modules}/bzz.js +0 -0
- package/dist/mjs/{modules → src/modules}/chunk.js +0 -0
- package/dist/mjs/{modules → src/modules}/debug/balance.js +0 -0
- package/dist/mjs/{modules → src/modules}/debug/chequebook.js +0 -0
- package/dist/mjs/{modules → src/modules}/debug/chunk.js +0 -0
- package/dist/mjs/{modules → src/modules}/debug/connectivity.js +0 -0
- package/dist/mjs/{modules → src/modules}/debug/settlements.js +0 -0
- package/dist/mjs/{modules → src/modules}/debug/stamps.js +0 -0
- package/dist/mjs/{modules → src/modules}/debug/states.js +17 -0
- package/dist/mjs/{modules → src/modules}/debug/status.js +3 -3
- package/dist/mjs/{modules → src/modules}/debug/tag.js +0 -0
- package/dist/mjs/{modules → src/modules}/debug/transactions.js +0 -0
- package/dist/mjs/{modules → src/modules}/feed.js +1 -1
- package/dist/mjs/{modules → src/modules}/pinning.js +0 -0
- package/dist/mjs/{modules → src/modules}/pss.js +0 -0
- package/dist/mjs/{modules → src/modules}/soc.js +0 -0
- package/dist/mjs/{modules → src/modules}/status.js +0 -0
- package/dist/mjs/{modules → src/modules}/stewardship.js +0 -0
- package/dist/mjs/{modules → src/modules}/tag.js +0 -0
- package/dist/mjs/{types → src/types}/debug.js +0 -0
- package/dist/mjs/{types → src/types}/index.js +1 -0
- package/dist/mjs/{types → src/types}/ky-options.js +0 -0
- package/dist/mjs/{types → src/types}/ky-universal/common.js +0 -0
- package/dist/mjs/{types → src/types}/ky-universal/hooks.js +0 -0
- package/dist/mjs/{types → src/types}/ky-universal/retry.js +0 -0
- package/dist/mjs/{utils → src/utils}/bytes.js +15 -0
- package/dist/mjs/{utils → src/utils}/collection.browser.js +0 -0
- package/dist/mjs/{utils → src/utils}/collection.js +0 -0
- package/dist/mjs/{utils → src/utils}/collection.node.js +0 -0
- package/dist/mjs/{utils → src/utils}/data.browser.js +0 -0
- package/dist/mjs/{utils → src/utils}/data.js +0 -0
- package/dist/mjs/{utils → src/utils}/error.js +0 -0
- package/dist/mjs/{utils → src/utils}/eth.js +0 -0
- package/dist/mjs/{utils → src/utils}/expose.js +0 -0
- package/dist/mjs/{utils → src/utils}/file.js +0 -0
- package/dist/mjs/{utils → src/utils}/hash.js +0 -0
- package/dist/mjs/{utils → src/utils}/headers.js +0 -0
- package/dist/mjs/{utils → src/utils}/hex.js +0 -0
- package/dist/mjs/{utils → src/utils}/http.js +7 -0
- package/dist/mjs/{utils → src/utils}/merge.js +0 -0
- package/dist/mjs/{utils → src/utils}/pss.js +0 -0
- package/dist/mjs/src/utils/reference.js +32 -0
- package/dist/mjs/{utils → src/utils}/stamps.js +0 -0
- package/dist/mjs/{utils → src/utils}/stream.js +0 -0
- package/dist/mjs/{utils → src/utils}/tar.js +0 -0
- package/dist/mjs/{utils → src/utils}/type.js +109 -2
- package/dist/mjs/{utils → src/utils}/uint64.js +0 -0
- package/dist/mjs/{utils → src/utils}/url.js +0 -0
- package/dist/mjs/test/utils.js +458 -0
- package/dist/types/{bee-debug.d.ts → src/bee-debug.d.ts} +8 -1
- package/dist/types/{bee.d.ts → src/bee.d.ts} +55 -24
- package/dist/types/{chunk → src/chunk}/bmt.d.ts +0 -0
- package/dist/types/{chunk → src/chunk}/cac.d.ts +4 -5
- package/dist/types/{chunk → src/chunk}/serialize.d.ts +0 -0
- package/dist/types/{chunk → src/chunk}/signer.d.ts +0 -0
- package/dist/types/{chunk → src/chunk}/soc.d.ts +4 -4
- package/dist/types/{chunk → src/chunk}/span.d.ts +0 -0
- package/dist/types/src/feed/identifier.d.ts +4 -0
- package/dist/types/src/feed/index.d.ts +28 -0
- package/dist/types/{feed → src/feed}/json.d.ts +0 -0
- package/dist/types/src/feed/retrievable.d.ts +5 -0
- package/dist/types/{feed → src/feed}/topic.d.ts +0 -0
- package/dist/types/{feed → src/feed}/type.d.ts +0 -0
- package/dist/types/{index.d.ts → src/index.d.ts} +0 -0
- package/dist/types/{modules → src/modules}/bytes.d.ts +3 -3
- package/dist/types/{modules → src/modules}/bzz.d.ts +3 -3
- package/dist/types/{modules → src/modules}/chunk.d.ts +2 -2
- package/dist/types/{modules → src/modules}/debug/balance.d.ts +0 -0
- package/dist/types/{modules → src/modules}/debug/chequebook.d.ts +0 -0
- package/dist/types/{modules → src/modules}/debug/chunk.d.ts +0 -0
- package/dist/types/{modules → src/modules}/debug/connectivity.d.ts +0 -0
- package/dist/types/{modules → src/modules}/debug/settlements.d.ts +0 -0
- package/dist/types/{modules → src/modules}/debug/stamps.d.ts +0 -0
- package/dist/types/{modules → src/modules}/debug/states.d.ts +7 -1
- package/dist/types/{modules → src/modules}/debug/status.d.ts +3 -3
- package/dist/types/{modules → src/modules}/debug/tag.d.ts +0 -0
- package/dist/types/{modules → src/modules}/debug/transactions.d.ts +0 -0
- package/dist/types/{modules → src/modules}/feed.d.ts +12 -1
- package/dist/types/{modules → src/modules}/pinning.d.ts +0 -0
- package/dist/types/{modules → src/modules}/pss.d.ts +0 -0
- package/dist/types/{modules → src/modules}/soc.d.ts +0 -0
- package/dist/types/{modules → src/modules}/status.d.ts +0 -0
- package/dist/types/{modules → src/modules}/stewardship.d.ts +3 -3
- package/dist/types/{modules → src/modules}/tag.d.ts +0 -0
- package/dist/types/{types → src/types}/debug.d.ts +19 -3
- package/dist/types/{types → src/types}/index.d.ts +33 -2
- package/dist/types/{types → src/types}/ky-options.d.ts +0 -0
- package/dist/types/{types → src/types}/ky-universal/common.d.ts +0 -0
- package/dist/types/{types → src/types}/ky-universal/hooks.d.ts +0 -0
- package/dist/types/{types → src/types}/ky-universal/retry.d.ts +0 -0
- package/dist/types/{utils → src/utils}/bytes.d.ts +7 -0
- package/dist/types/{utils → src/utils}/collection.browser.d.ts +0 -0
- package/dist/types/{utils → src/utils}/collection.d.ts +0 -0
- package/dist/types/{utils → src/utils}/collection.node.d.ts +0 -0
- package/dist/types/{utils → src/utils}/data.browser.d.ts +0 -0
- package/dist/types/{utils → src/utils}/data.d.ts +0 -0
- package/dist/types/{utils → src/utils}/error.d.ts +0 -0
- package/dist/types/{utils → src/utils}/eth.d.ts +0 -0
- package/dist/types/{utils → src/utils}/expose.d.ts +0 -0
- package/dist/types/{utils → src/utils}/file.d.ts +0 -0
- package/dist/types/{utils → src/utils}/hash.d.ts +0 -0
- package/dist/types/{utils → src/utils}/headers.d.ts +0 -0
- package/dist/types/{utils → src/utils}/hex.d.ts +0 -0
- package/dist/types/{utils → src/utils}/http.d.ts +0 -0
- package/dist/types/{utils → src/utils}/merge.d.ts +0 -0
- package/dist/types/{utils → src/utils}/pss.d.ts +0 -0
- package/dist/types/src/utils/reference.d.ts +2 -0
- package/dist/types/{utils → src/utils}/stamps.d.ts +0 -0
- package/dist/types/{utils → src/utils}/stream.d.ts +0 -0
- package/dist/types/{utils → src/utils}/tar.d.ts +0 -0
- package/dist/types/{utils → src/utils}/type.d.ts +17 -1
- package/dist/types/{utils → src/utils}/uint64.d.ts +0 -0
- package/dist/types/{utils → src/utils}/url.d.ts +0 -0
- package/dist/types/test/utils.d.ts +119 -0
- package/package.json +24 -24
- package/dist/types/feed/index.d.ts +0 -35
|
@@ -37,13 +37,14 @@ import * as settlements from "./modules/debug/settlements.js";
|
|
|
37
37
|
import * as status from "./modules/debug/status.js";
|
|
38
38
|
import * as transactions from "./modules/debug/transactions.js";
|
|
39
39
|
import * as states from "./modules/debug/states.js";
|
|
40
|
-
import { BeeArgumentError } from "./utils/error.js";
|
|
40
|
+
import { BeeArgumentError, BeeError } from "./utils/error.js";
|
|
41
41
|
import { assertBeeUrl, stripLastSlash } from "./utils/url.js";
|
|
42
|
-
import { assertAddress, assertBatchId,
|
|
42
|
+
import { assertAddress, assertBatchId, assertCashoutOptions, assertNonNegativeInteger, assertPositiveInteger, assertPostageBatchOptions, assertRequestOptions, assertTransactionHash, isTag } from "./utils/type.js";
|
|
43
43
|
import { STAMPS_DEPTH_MAX, STAMPS_DEPTH_MIN } from "./types/index.js";
|
|
44
44
|
import * as tag from "./modules/debug/tag.js";
|
|
45
45
|
import * as stamps from "./modules/debug/stamps.js";
|
|
46
46
|
import { makeDefaultKy, wrapRequestClosure, wrapResponseClosure } from "./utils/http.js";
|
|
47
|
+
import { sleep } from "../test/utils.js";
|
|
47
48
|
export class BeeDebug {
|
|
48
49
|
constructor(url, options) {
|
|
49
50
|
var _a;
|
|
@@ -501,6 +502,19 @@ export class BeeDebug {
|
|
|
501
502
|
return states.getChainState(this.getKy(options));
|
|
502
503
|
});
|
|
503
504
|
}
|
|
505
|
+
/**
|
|
506
|
+
* Get wallet balances for xDai and BZZ of the Bee node
|
|
507
|
+
*
|
|
508
|
+
* @param options
|
|
509
|
+
*/
|
|
510
|
+
|
|
511
|
+
|
|
512
|
+
getWalletBalance(options) {
|
|
513
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
514
|
+
assertRequestOptions(options);
|
|
515
|
+
return states.getWalletBalance(this.getKy(options));
|
|
516
|
+
});
|
|
517
|
+
}
|
|
504
518
|
/**
|
|
505
519
|
* Creates new postage batch from the funds that the node has available in its Ethereum account.
|
|
506
520
|
*
|
|
@@ -522,8 +536,8 @@ export class BeeDebug {
|
|
|
522
536
|
|
|
523
537
|
createPostageBatch(amount, depth, options) {
|
|
524
538
|
return __awaiter(this, void 0, void 0, function* () {
|
|
525
|
-
|
|
526
|
-
|
|
539
|
+
assertPostageBatchOptions(options);
|
|
540
|
+
assertPositiveInteger(amount);
|
|
527
541
|
assertNonNegativeInteger(depth);
|
|
528
542
|
|
|
529
543
|
if (depth < STAMPS_DEPTH_MIN) {
|
|
@@ -534,15 +548,13 @@ export class BeeDebug {
|
|
|
534
548
|
throw new BeeArgumentError(`Depth has to be at most ${STAMPS_DEPTH_MAX}`, depth);
|
|
535
549
|
}
|
|
536
550
|
|
|
537
|
-
|
|
538
|
-
assertNonNegativeInteger(options.gasPrice);
|
|
539
|
-
}
|
|
551
|
+
const stamp = yield stamps.createPostageBatch(this.getKy(options), amount, depth, options);
|
|
540
552
|
|
|
541
|
-
if (
|
|
542
|
-
|
|
553
|
+
if (options === null || options === void 0 ? void 0 : options.waitForUsable) {
|
|
554
|
+
yield this.waitForUsablePostageStamp(stamp, options === null || options === void 0 ? void 0 : options.waitForUsableTimeout);
|
|
543
555
|
}
|
|
544
556
|
|
|
545
|
-
return
|
|
557
|
+
return stamp;
|
|
546
558
|
});
|
|
547
559
|
}
|
|
548
560
|
/**
|
|
@@ -703,6 +715,24 @@ export class BeeDebug {
|
|
|
703
715
|
});
|
|
704
716
|
}
|
|
705
717
|
|
|
718
|
+
waitForUsablePostageStamp(id, timeout = 120000) {
|
|
719
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
720
|
+
const TIME_STEP = 1500;
|
|
721
|
+
|
|
722
|
+
for (let time = 0; time < timeout; time += TIME_STEP) {
|
|
723
|
+
const stamp = yield this.getPostageBatch(id);
|
|
724
|
+
|
|
725
|
+
if (stamp.usable) {
|
|
726
|
+
return;
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
yield sleep(TIME_STEP);
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
throw new BeeError('Timeout on waiting for postage stamp to become usable');
|
|
733
|
+
});
|
|
734
|
+
}
|
|
735
|
+
|
|
706
736
|
getKy(options) {
|
|
707
737
|
if (!options) {
|
|
708
738
|
return this.ky;
|
|
@@ -50,13 +50,15 @@ 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";
|
|
54
|
-
import {
|
|
55
|
-
import {
|
|
53
|
+
import { addCidConversionFunction, assertAddressPrefix, assertAllTagsOptions, assertBatchId, assertCollectionUploadOptions, assertData, assertFileData, assertFileUploadOptions, assertPssMessageHandler, assertPublicKey, assertReference, assertReferenceOrEns, assertRequestOptions, assertUploadOptions, makeReferenceOrEns, makeTagUid } from "./utils/type.js";
|
|
54
|
+
import { getJsonData, setJsonData } from "./feed/json.js";
|
|
55
|
+
import { assertCollection, makeCollectionFromFileList } 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";
|
|
61
|
+
import { ReferenceType } from '@ethersphere/swarm-cid';
|
|
60
62
|
/**
|
|
61
63
|
* The main component that abstracts operations available on the main Bee API.
|
|
62
64
|
*
|
|
@@ -131,8 +133,10 @@ export class Bee {
|
|
|
131
133
|
/**
|
|
132
134
|
* Download data as a byte array
|
|
133
135
|
*
|
|
134
|
-
* @param reference Bee data reference
|
|
136
|
+
* @param reference Bee data reference in hex string (either 64 or 128 chars long) or ENS domain.
|
|
135
137
|
* @param options Options that affects the request behavior
|
|
138
|
+
* @throws TypeError if some of the input parameters is not expected type
|
|
139
|
+
* @throws BeeArgumentError if there is passed ENS domain with invalid unicode characters
|
|
136
140
|
* @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/access-the-swarm/upload-and-download)
|
|
137
141
|
* @see [Bee API reference - `GET /bytes`](https://docs.ethswarm.org/api/#tag/Bytes/paths/~1bytes~1{reference}/get)
|
|
138
142
|
*/
|
|
@@ -141,15 +145,17 @@ export class Bee {
|
|
|
141
145
|
downloadData(reference, options) {
|
|
142
146
|
return __awaiter(this, void 0, void 0, function* () {
|
|
143
147
|
assertRequestOptions(options);
|
|
144
|
-
|
|
148
|
+
assertReferenceOrEns(reference);
|
|
145
149
|
return bytes.download(this.getKy(options), reference);
|
|
146
150
|
});
|
|
147
151
|
}
|
|
148
152
|
/**
|
|
149
153
|
* Download data as a Readable stream
|
|
150
154
|
*
|
|
151
|
-
* @param reference Bee data reference
|
|
155
|
+
* @param reference Bee data reference in hex string (either 64 or 128 chars long) or ENS domain.
|
|
152
156
|
* @param options Options that affects the request behavior
|
|
157
|
+
* @throws TypeError if some of the input parameters is not expected type
|
|
158
|
+
* @throws BeeArgumentError if there is passed ENS domain with invalid unicode characters
|
|
153
159
|
* @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/access-the-swarm/upload-and-download)
|
|
154
160
|
* @see [Bee API reference - `GET /bytes`](https://docs.ethswarm.org/api/#tag/Bytes/paths/~1bytes~1{reference}/get)
|
|
155
161
|
*/
|
|
@@ -158,7 +164,7 @@ export class Bee {
|
|
|
158
164
|
downloadReadableData(reference, options) {
|
|
159
165
|
return __awaiter(this, void 0, void 0, function* () {
|
|
160
166
|
assertRequestOptions(options);
|
|
161
|
-
|
|
167
|
+
assertReferenceOrEns(reference);
|
|
162
168
|
return bytes.downloadReadable(this.getKy(options), reference);
|
|
163
169
|
});
|
|
164
170
|
}
|
|
@@ -198,8 +204,10 @@ export class Bee {
|
|
|
198
204
|
/**
|
|
199
205
|
* Download chunk as a byte array
|
|
200
206
|
*
|
|
201
|
-
* @param reference Bee chunk reference
|
|
207
|
+
* @param reference Bee chunk reference in hex string (either 64 or 128 chars long) or ENS domain.
|
|
202
208
|
* @param options Options that affects the request behavior
|
|
209
|
+
* @throws TypeError if some of the input parameters is not expected type
|
|
210
|
+
* @throws BeeArgumentError if there is passed ENS domain with invalid unicode characters
|
|
203
211
|
* @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/access-the-swarm/upload-and-download)
|
|
204
212
|
* @see [Bee API reference - `GET /chunks`](https://docs.ethswarm.org/api/#tag/Chunk/paths/~1chunks~1{reference}/get)
|
|
205
213
|
*/
|
|
@@ -208,7 +216,7 @@ export class Bee {
|
|
|
208
216
|
downloadChunk(reference, options) {
|
|
209
217
|
return __awaiter(this, void 0, void 0, function* () {
|
|
210
218
|
assertRequestOptions(options);
|
|
211
|
-
|
|
219
|
+
assertReferenceOrEns(reference);
|
|
212
220
|
return chunk.download(this.getKy(options), reference);
|
|
213
221
|
});
|
|
214
222
|
}
|
|
@@ -247,24 +255,25 @@ export class Bee {
|
|
|
247
255
|
const fileOptions = Object.assign({
|
|
248
256
|
contentType
|
|
249
257
|
}, options);
|
|
250
|
-
return bzz.uploadFile(this.getKy(options), fileData, postageBatchId, fileName, fileOptions);
|
|
258
|
+
return addCidConversionFunction(yield bzz.uploadFile(this.getKy(options), fileData, postageBatchId, fileName, fileOptions), ReferenceType.MANIFEST);
|
|
251
259
|
} else if (isReadable(data) && (options === null || options === void 0 ? void 0 : options.tag) && !options.size) {
|
|
252
260
|
// TODO: Needed until https://github.com/ethersphere/bee/issues/2317 is resolved
|
|
253
261
|
const result = yield bzz.uploadFile(this.getKy(options), data, postageBatchId, name, options);
|
|
254
262
|
yield this.updateTag(options.tag, result.reference);
|
|
255
|
-
return result;
|
|
263
|
+
return addCidConversionFunction(result, ReferenceType.MANIFEST);
|
|
256
264
|
} else {
|
|
257
|
-
return bzz.uploadFile(this.getKy(options), data, postageBatchId, name, options);
|
|
265
|
+
return addCidConversionFunction(yield bzz.uploadFile(this.getKy(options), data, postageBatchId, name, options), ReferenceType.MANIFEST);
|
|
258
266
|
}
|
|
259
267
|
});
|
|
260
268
|
}
|
|
261
269
|
/**
|
|
262
270
|
* Download single file.
|
|
263
271
|
*
|
|
264
|
-
* @param reference Bee file reference
|
|
272
|
+
* @param reference Bee file reference in hex string (either 64 or 128 chars long), ENS domain or Swarm CID.
|
|
265
273
|
* @param path If reference points to manifest, then this parameter defines path to the file
|
|
266
274
|
* @param options Options that affects the request behavior
|
|
267
|
-
*
|
|
275
|
+
* @throws TypeError if some of the input parameters is not expected type
|
|
276
|
+
* @throws BeeArgumentError if there is passed ENS domain with invalid unicode characters
|
|
268
277
|
* @see Data
|
|
269
278
|
* @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/access-the-swarm/upload-and-download)
|
|
270
279
|
* @see [Bee API reference - `GET /bzz`](https://docs.ethswarm.org/api/#tag/Collection/paths/~1bzz~1{reference}~1{path}/get)
|
|
@@ -274,16 +283,18 @@ export class Bee {
|
|
|
274
283
|
downloadFile(reference, path = '', options) {
|
|
275
284
|
return __awaiter(this, void 0, void 0, function* () {
|
|
276
285
|
assertRequestOptions(options);
|
|
277
|
-
|
|
286
|
+
reference = makeReferenceOrEns(reference, ReferenceType.MANIFEST);
|
|
278
287
|
return bzz.downloadFile(this.getKy(options), reference, path);
|
|
279
288
|
});
|
|
280
289
|
}
|
|
281
290
|
/**
|
|
282
291
|
* Download single file as a readable stream
|
|
283
292
|
*
|
|
284
|
-
* @param reference
|
|
293
|
+
* @param reference Bee file reference in hex string (either 64 or 128 chars long), ENS domain or Swarm CID.
|
|
285
294
|
* @param path If reference points to manifest / collections, then this parameter defines path to the file
|
|
286
295
|
* @param options Options that affects the request behavior
|
|
296
|
+
* @throws TypeError if some of the input parameters is not expected type
|
|
297
|
+
* @throws BeeArgumentError if there is passed ENS domain with invalid unicode characters
|
|
287
298
|
*
|
|
288
299
|
* @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/access-the-swarm/upload-and-download)
|
|
289
300
|
* @see [Bee API reference - `GET /bzz`](https://docs.ethswarm.org/api/#tag/Collection/paths/~1bzz~1{reference}~1{path}/get)
|
|
@@ -293,7 +304,7 @@ export class Bee {
|
|
|
293
304
|
downloadReadableFile(reference, path = '', options) {
|
|
294
305
|
return __awaiter(this, void 0, void 0, function* () {
|
|
295
306
|
assertRequestOptions(options);
|
|
296
|
-
|
|
307
|
+
reference = makeReferenceOrEns(reference, ReferenceType.MANIFEST);
|
|
297
308
|
return bzz.downloadFileReadable(this.getKy(options), reference, path);
|
|
298
309
|
});
|
|
299
310
|
}
|
|
@@ -320,7 +331,7 @@ export class Bee {
|
|
|
320
331
|
assertBatchId(postageBatchId);
|
|
321
332
|
if (options) assertCollectionUploadOptions(options);
|
|
322
333
|
const data = yield makeCollectionFromFileList(fileList);
|
|
323
|
-
return bzz.uploadCollection(this.getKy(options), data, postageBatchId, options);
|
|
334
|
+
return addCidConversionFunction(yield bzz.uploadCollection(this.getKy(options), data, postageBatchId, options), ReferenceType.MANIFEST);
|
|
324
335
|
});
|
|
325
336
|
}
|
|
326
337
|
/**
|
|
@@ -340,7 +351,7 @@ export class Bee {
|
|
|
340
351
|
assertBatchId(postageBatchId);
|
|
341
352
|
assertCollection(collection);
|
|
342
353
|
if (options) assertCollectionUploadOptions(options);
|
|
343
|
-
return bzz.uploadCollection(this.ky, collection, postageBatchId, options);
|
|
354
|
+
return addCidConversionFunction(yield bzz.uploadCollection(this.ky, collection, postageBatchId, options), ReferenceType.MANIFEST);
|
|
344
355
|
});
|
|
345
356
|
}
|
|
346
357
|
/**
|
|
@@ -366,7 +377,7 @@ export class Bee {
|
|
|
366
377
|
assertBatchId(postageBatchId);
|
|
367
378
|
if (options) assertCollectionUploadOptions(options);
|
|
368
379
|
const data = yield makeCollectionFromFS(dir);
|
|
369
|
-
return bzz.uploadCollection(this.getKy(options), data, postageBatchId, options);
|
|
380
|
+
return addCidConversionFunction(yield bzz.uploadCollection(this.getKy(options), data, postageBatchId, options), ReferenceType.MANIFEST);
|
|
370
381
|
});
|
|
371
382
|
}
|
|
372
383
|
/**
|
|
@@ -541,9 +552,10 @@ export class Bee {
|
|
|
541
552
|
*
|
|
542
553
|
* **Warning! Not allowed when node is in Gateway mode!**
|
|
543
554
|
*
|
|
544
|
-
* @param reference Bee data reference
|
|
555
|
+
* @param reference Bee data reference in hex string (either 64 or 128 chars long) or ENS domain.
|
|
545
556
|
* @param options Options that affects the request behavior
|
|
546
|
-
* @throws TypeError if
|
|
557
|
+
* @throws TypeError if some of the input parameters is not expected type
|
|
558
|
+
* @throws BeeArgumentError if there is passed ENS domain with invalid unicode characters
|
|
547
559
|
*
|
|
548
560
|
* @see [Bee docs - Pinning](https://docs.ethswarm.org/docs/access-the-swarm/pinning)
|
|
549
561
|
*/
|
|
@@ -559,10 +571,11 @@ export class Bee {
|
|
|
559
571
|
/**
|
|
560
572
|
* Instructs the Bee node to reupload a locally pinned data into the network.
|
|
561
573
|
*
|
|
562
|
-
* @param reference
|
|
574
|
+
* @param reference Bee data reference to be re-uploaded in hex string (either 64 or 128 chars long) or ENS domain.
|
|
563
575
|
* @param options Options that affects the request behavior
|
|
564
576
|
* @throws BeeArgumentError if the reference is not locally pinned
|
|
565
|
-
* @throws TypeError if
|
|
577
|
+
* @throws TypeError if some of the input parameters is not expected type
|
|
578
|
+
* @throws BeeArgumentError if there is passed ENS domain with invalid unicode characters
|
|
566
579
|
*
|
|
567
580
|
* @see [Bee API reference - `PUT /stewardship`](https://docs.ethswarm.org/api/#tag/Stewardship/paths/~1stewardship~1{reference}/put)
|
|
568
581
|
*/
|
|
@@ -571,15 +584,17 @@ export class Bee {
|
|
|
571
584
|
reuploadPinnedData(reference, options) {
|
|
572
585
|
return __awaiter(this, void 0, void 0, function* () {
|
|
573
586
|
assertRequestOptions(options);
|
|
574
|
-
|
|
587
|
+
assertReferenceOrEns(reference);
|
|
575
588
|
yield stewardship.reupload(this.getKy(options), reference);
|
|
576
589
|
});
|
|
577
590
|
}
|
|
578
591
|
/**
|
|
579
592
|
* Checks if content specified by reference is retrievable from the network.
|
|
580
593
|
*
|
|
581
|
-
* @param reference
|
|
594
|
+
* @param reference Bee data reference to be checked in hex string (either 64 or 128 chars long) or ENS domain.
|
|
582
595
|
* @param options Options that affects the request behavior
|
|
596
|
+
* @throws TypeError if some of the input parameters is not expected type
|
|
597
|
+
* @throws BeeArgumentError if there is passed ENS domain with invalid unicode characters
|
|
583
598
|
*
|
|
584
599
|
* @see [Bee API reference - `GET /stewardship`](https://docs.ethswarm.org/api/#tag/Stewardship/paths/~1stewardship~1{reference}/get)
|
|
585
600
|
*/
|
|
@@ -588,10 +603,54 @@ export class Bee {
|
|
|
588
603
|
isReferenceRetrievable(reference, options) {
|
|
589
604
|
return __awaiter(this, void 0, void 0, function* () {
|
|
590
605
|
assertRequestOptions(options);
|
|
591
|
-
|
|
606
|
+
assertReferenceOrEns(reference);
|
|
592
607
|
return stewardship.isRetrievable(this.getKy(options), reference);
|
|
593
608
|
});
|
|
594
609
|
}
|
|
610
|
+
/**
|
|
611
|
+
* Functions that validates if feed is retrievable in the network.
|
|
612
|
+
*
|
|
613
|
+
* If no index is passed then it check for "latest" update, which is a weaker guarantee as nobody can be really
|
|
614
|
+
* sure what is the "latest" update.
|
|
615
|
+
*
|
|
616
|
+
* If index is passed then it validates all previous sequence index chunks if they are available as they are required
|
|
617
|
+
* to correctly resolve the feed upto the given index update.
|
|
618
|
+
*
|
|
619
|
+
* @param type
|
|
620
|
+
* @param owner
|
|
621
|
+
* @param topic
|
|
622
|
+
* @param index
|
|
623
|
+
* @param options
|
|
624
|
+
*/
|
|
625
|
+
|
|
626
|
+
|
|
627
|
+
isFeedRetrievable(type, owner, topic, index, options) {
|
|
628
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
629
|
+
const canonicalOwner = makeEthAddress(owner);
|
|
630
|
+
const canonicalTopic = makeTopic(topic);
|
|
631
|
+
|
|
632
|
+
if (!index) {
|
|
633
|
+
try {
|
|
634
|
+
yield this.makeFeedReader(type, canonicalTopic, canonicalOwner).download();
|
|
635
|
+
return true;
|
|
636
|
+
} catch (e) {
|
|
637
|
+
const err = e; // Only if the error is "not-found" then we return false otherwise we re-throw the error
|
|
638
|
+
|
|
639
|
+
if ((err === null || err === void 0 ? void 0 : err.status) === 404) {
|
|
640
|
+
return false;
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
throw e;
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
if (type !== 'sequence') {
|
|
648
|
+
throw new BeeError('Only Sequence type of Feeds is supported at the moment');
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
return areAllSequentialFeedsUpdateRetrievable(this, canonicalOwner, canonicalTopic, index, options);
|
|
652
|
+
});
|
|
653
|
+
}
|
|
595
654
|
/**
|
|
596
655
|
* Send data to recipient or target with Postal Service for Swarm.
|
|
597
656
|
*
|
|
@@ -774,6 +833,7 @@ export class Bee {
|
|
|
774
833
|
*
|
|
775
834
|
* @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/dapps-on-swarm/feeds)
|
|
776
835
|
* @see [Bee API reference - `POST /feeds`](https://docs.ethswarm.org/api/#tag/Feed/paths/~1feeds~1{owner}~1{topic}/post)
|
|
836
|
+
* TODO: Once breaking add support for Feed CID
|
|
777
837
|
*/
|
|
778
838
|
|
|
779
839
|
|
|
File without changes
|
|
@@ -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;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -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
|
+
}
|
|
@@ -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
|
}));
|
|
File without changes
|