@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
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ENCRYPTED_REFERENCE_BYTES_LENGTH, ENCRYPTED_REFERENCE_HEX_LENGTH, REFERENCE_BYTES_LENGTH, REFERENCE_HEX_LENGTH } from "../types/index.js";
|
|
2
|
+
import { bytesAtOffset, hasBytesAtOffset } from "./bytes.js";
|
|
3
|
+
import { hexToBytes, makeHexString } from "./hex.js";
|
|
4
|
+
export function makeBytesReference(reference, offset = 0) {
|
|
5
|
+
if (typeof reference === 'string') {
|
|
6
|
+
if (offset) {
|
|
7
|
+
throw new Error('Offset property can be set only for UintArray reference!');
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
try {
|
|
11
|
+
// Non-encrypted chunk hex string reference
|
|
12
|
+
const hexReference = makeHexString(reference, REFERENCE_HEX_LENGTH);
|
|
13
|
+
return hexToBytes(hexReference);
|
|
14
|
+
} catch (e) {
|
|
15
|
+
if (!(e instanceof TypeError)) {
|
|
16
|
+
throw e;
|
|
17
|
+
} // Encrypted chunk hex string reference
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
const hexReference = makeHexString(reference, ENCRYPTED_REFERENCE_HEX_LENGTH);
|
|
21
|
+
return hexToBytes(hexReference);
|
|
22
|
+
}
|
|
23
|
+
} else if (reference instanceof Uint8Array) {
|
|
24
|
+
if (hasBytesAtOffset(reference, offset, ENCRYPTED_REFERENCE_BYTES_LENGTH)) {
|
|
25
|
+
return bytesAtOffset(reference, offset, ENCRYPTED_REFERENCE_BYTES_LENGTH);
|
|
26
|
+
} else if (hasBytesAtOffset(reference, offset, REFERENCE_BYTES_LENGTH)) {
|
|
27
|
+
return bytesAtOffset(reference, offset, REFERENCE_BYTES_LENGTH);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
throw new TypeError('invalid chunk reference');
|
|
32
|
+
}
|
package/dist/mjs/utils/type.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ADDRESS_HEX_LENGTH, BATCH_ID_HEX_LENGTH, ENCRYPTED_REFERENCE_HEX_LENGTH, PUBKEY_HEX_LENGTH, REFERENCE_HEX_LENGTH, TAGS_LIMIT_MAX, TAGS_LIMIT_MIN, PSS_TARGET_HEX_LENGTH_MAX } from "../types/index.js";
|
|
2
2
|
import { BeeArgumentError } from "./error.js";
|
|
3
3
|
import { isFile } from "./file.js";
|
|
4
|
-
import { assertHexString, assertPrefixedHexString } from "./hex.js";
|
|
4
|
+
import { assertHexString, assertPrefixedHexString, isHexString } from "./hex.js";
|
|
5
5
|
import { isReadable } from "./stream.js";
|
|
6
6
|
export function isUint8Array(obj) {
|
|
7
7
|
return obj instanceof Uint8Array;
|
|
@@ -58,6 +58,43 @@ export function assertReference(value) {
|
|
|
58
58
|
assertHexString(value, ENCRYPTED_REFERENCE_HEX_LENGTH);
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
|
+
export function assertReferenceOrEns(value) {
|
|
62
|
+
if (typeof value !== 'string') {
|
|
63
|
+
throw new TypeError('ReferenceOrEns has to be a string!');
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (isHexString(value)) {
|
|
67
|
+
assertReference(value);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* a.asdf - VALID
|
|
72
|
+
* test.eth - VALID
|
|
73
|
+
* ADAM.ETH - VALID
|
|
74
|
+
* ADAM UHLIR.ETH - INVALID
|
|
75
|
+
* test.whatever.eth - VALID
|
|
76
|
+
* -adg.ets - INVALID
|
|
77
|
+
* adg-.ets - INVALID
|
|
78
|
+
* as-a.com - VALID
|
|
79
|
+
* ethswarm.org - VALID
|
|
80
|
+
* http://asdf.asf - INVALID
|
|
81
|
+
* řš+ýí.šě+ř.čě - VALID
|
|
82
|
+
* tsg.asg?asg - INVALID
|
|
83
|
+
* tsg.asg:1599 - INVALID
|
|
84
|
+
* ethswarm.something- - INVALID
|
|
85
|
+
* ethswarm.-something - INVALID
|
|
86
|
+
* ethswarm.some-thing - VALID
|
|
87
|
+
*/
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
const DOMAIN_REGEX = /^(?:(?!-)[^.\/?:\s]{1,63}(?<!-)\.)+(?!-)[^.\/?:\s]{2,63}(?<!-)$/; // We are doing best-effort validation of domain here. The proper way would be to do validation using IDNA UTS64 standard
|
|
91
|
+
// but that would give us high penalty to our dependencies as the library (idna-uts46-hx) that does this validation and translation
|
|
92
|
+
// adds 160kB minified size which is significant. We expects that full validation will be done on Bee side.
|
|
93
|
+
|
|
94
|
+
if (!DOMAIN_REGEX.test(value)) {
|
|
95
|
+
throw new TypeError('ReferenceOrEns is not valid Reference, but also not valid ENS domain.');
|
|
96
|
+
}
|
|
97
|
+
}
|
|
61
98
|
export function assertAddress(value) {
|
|
62
99
|
assertHexString(value, ADDRESS_HEX_LENGTH, 'Address');
|
|
63
100
|
}
|
package/dist/types/bee.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { Index, IndexBytes } from './feed';
|
|
1
2
|
import { FeedType } from './feed/type';
|
|
2
3
|
import { EthAddress } from './utils/eth';
|
|
3
|
-
import { AllTagsOptions, Collection, Readable, RequestOptions, UploadResult } from './types';
|
|
4
|
+
import { AllTagsOptions, Collection, Readable, ReferenceOrEns, RequestOptions, UploadResult } from './types';
|
|
4
5
|
import type { Tag, FileData, Reference, UploadOptions, PublicKey, AddressPrefix, PssMessageHandler, PssSubscription, CollectionUploadOptions, FileUploadOptions, Data, Signer, FeedReader, FeedWriter, SOCWriter, SOCReader, Topic, BeeOptions, JsonFeedOptions, AnyJson, Pin, BatchId } from './types';
|
|
5
6
|
/**
|
|
6
7
|
* The main component that abstracts operations available on the main Bee API.
|
|
@@ -42,21 +43,25 @@ export declare class Bee {
|
|
|
42
43
|
/**
|
|
43
44
|
* Download data as a byte array
|
|
44
45
|
*
|
|
45
|
-
* @param reference Bee data reference
|
|
46
|
+
* @param reference Bee data reference in hex string (either 64 or 128 chars long) or ENS domain.
|
|
46
47
|
* @param options Options that affects the request behavior
|
|
48
|
+
* @throws TypeError if some of the input parameters is not expected type
|
|
49
|
+
* @throws BeeArgumentError if there is passed ENS domain with invalid unicode characters
|
|
47
50
|
* @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/access-the-swarm/upload-and-download)
|
|
48
51
|
* @see [Bee API reference - `GET /bytes`](https://docs.ethswarm.org/api/#tag/Bytes/paths/~1bytes~1{reference}/get)
|
|
49
52
|
*/
|
|
50
|
-
downloadData(reference:
|
|
53
|
+
downloadData(reference: ReferenceOrEns | string, options?: RequestOptions): Promise<Data>;
|
|
51
54
|
/**
|
|
52
55
|
* Download data as a Readable stream
|
|
53
56
|
*
|
|
54
|
-
* @param reference Bee data reference
|
|
57
|
+
* @param reference Bee data reference in hex string (either 64 or 128 chars long) or ENS domain.
|
|
55
58
|
* @param options Options that affects the request behavior
|
|
59
|
+
* @throws TypeError if some of the input parameters is not expected type
|
|
60
|
+
* @throws BeeArgumentError if there is passed ENS domain with invalid unicode characters
|
|
56
61
|
* @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/access-the-swarm/upload-and-download)
|
|
57
62
|
* @see [Bee API reference - `GET /bytes`](https://docs.ethswarm.org/api/#tag/Bytes/paths/~1bytes~1{reference}/get)
|
|
58
63
|
*/
|
|
59
|
-
downloadReadableData(reference:
|
|
64
|
+
downloadReadableData(reference: ReferenceOrEns | string, options?: RequestOptions): Promise<ReadableStream<Uint8Array>>;
|
|
60
65
|
/**
|
|
61
66
|
* Upload chunk to a Bee node
|
|
62
67
|
*
|
|
@@ -72,12 +77,14 @@ export declare class Bee {
|
|
|
72
77
|
/**
|
|
73
78
|
* Download chunk as a byte array
|
|
74
79
|
*
|
|
75
|
-
* @param reference Bee chunk reference
|
|
80
|
+
* @param reference Bee chunk reference in hex string (either 64 or 128 chars long) or ENS domain.
|
|
76
81
|
* @param options Options that affects the request behavior
|
|
82
|
+
* @throws TypeError if some of the input parameters is not expected type
|
|
83
|
+
* @throws BeeArgumentError if there is passed ENS domain with invalid unicode characters
|
|
77
84
|
* @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/access-the-swarm/upload-and-download)
|
|
78
85
|
* @see [Bee API reference - `GET /chunks`](https://docs.ethswarm.org/api/#tag/Chunk/paths/~1chunks~1{reference}/get)
|
|
79
86
|
*/
|
|
80
|
-
downloadChunk(reference:
|
|
87
|
+
downloadChunk(reference: ReferenceOrEns | string, options?: RequestOptions): Promise<Data>;
|
|
81
88
|
/**
|
|
82
89
|
* Upload single file to a Bee node.
|
|
83
90
|
*
|
|
@@ -98,26 +105,29 @@ export declare class Bee {
|
|
|
98
105
|
/**
|
|
99
106
|
* Download single file.
|
|
100
107
|
*
|
|
101
|
-
* @param reference Bee file reference
|
|
108
|
+
* @param reference Bee file reference in hex string (either 64 or 128 chars long) or ENS domain.
|
|
102
109
|
* @param path If reference points to manifest, then this parameter defines path to the file
|
|
103
110
|
* @param options Options that affects the request behavior
|
|
104
|
-
*
|
|
111
|
+
* @throws TypeError if some of the input parameters is not expected type
|
|
112
|
+
* @throws BeeArgumentError if there is passed ENS domain with invalid unicode characters
|
|
105
113
|
* @see Data
|
|
106
114
|
* @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/access-the-swarm/upload-and-download)
|
|
107
115
|
* @see [Bee API reference - `GET /bzz`](https://docs.ethswarm.org/api/#tag/Collection/paths/~1bzz~1{reference}~1{path}/get)
|
|
108
116
|
*/
|
|
109
|
-
downloadFile(reference:
|
|
117
|
+
downloadFile(reference: ReferenceOrEns | string, path?: string, options?: RequestOptions): Promise<FileData<Data>>;
|
|
110
118
|
/**
|
|
111
119
|
* Download single file as a readable stream
|
|
112
120
|
*
|
|
113
|
-
* @param reference
|
|
121
|
+
* @param reference Bee file reference in hex string (either 64 or 128 chars long) or ENS domain.
|
|
114
122
|
* @param path If reference points to manifest / collections, then this parameter defines path to the file
|
|
115
123
|
* @param options Options that affects the request behavior
|
|
124
|
+
* @throws TypeError if some of the input parameters is not expected type
|
|
125
|
+
* @throws BeeArgumentError if there is passed ENS domain with invalid unicode characters
|
|
116
126
|
*
|
|
117
127
|
* @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/access-the-swarm/upload-and-download)
|
|
118
128
|
* @see [Bee API reference - `GET /bzz`](https://docs.ethswarm.org/api/#tag/Collection/paths/~1bzz~1{reference}~1{path}/get)
|
|
119
129
|
*/
|
|
120
|
-
downloadReadableFile(reference:
|
|
130
|
+
downloadReadableFile(reference: ReferenceOrEns | string, path?: string, options?: RequestOptions): Promise<FileData<ReadableStream<Uint8Array>>>;
|
|
121
131
|
/**
|
|
122
132
|
* Upload collection of files to a Bee node
|
|
123
133
|
*
|
|
@@ -272,9 +282,10 @@ export declare class Bee {
|
|
|
272
282
|
*
|
|
273
283
|
* **Warning! Not allowed when node is in Gateway mode!**
|
|
274
284
|
*
|
|
275
|
-
* @param reference Bee data reference
|
|
285
|
+
* @param reference Bee data reference in hex string (either 64 or 128 chars long) or ENS domain.
|
|
276
286
|
* @param options Options that affects the request behavior
|
|
277
|
-
* @throws TypeError if
|
|
287
|
+
* @throws TypeError if some of the input parameters is not expected type
|
|
288
|
+
* @throws BeeArgumentError if there is passed ENS domain with invalid unicode characters
|
|
278
289
|
*
|
|
279
290
|
* @see [Bee docs - Pinning](https://docs.ethswarm.org/docs/access-the-swarm/pinning)
|
|
280
291
|
*/
|
|
@@ -282,23 +293,42 @@ export declare class Bee {
|
|
|
282
293
|
/**
|
|
283
294
|
* Instructs the Bee node to reupload a locally pinned data into the network.
|
|
284
295
|
*
|
|
285
|
-
* @param reference
|
|
296
|
+
* @param reference Bee data reference to be re-uploaded in hex string (either 64 or 128 chars long) or ENS domain.
|
|
286
297
|
* @param options Options that affects the request behavior
|
|
287
298
|
* @throws BeeArgumentError if the reference is not locally pinned
|
|
288
|
-
* @throws TypeError if
|
|
299
|
+
* @throws TypeError if some of the input parameters is not expected type
|
|
300
|
+
* @throws BeeArgumentError if there is passed ENS domain with invalid unicode characters
|
|
289
301
|
*
|
|
290
302
|
* @see [Bee API reference - `PUT /stewardship`](https://docs.ethswarm.org/api/#tag/Stewardship/paths/~1stewardship~1{reference}/put)
|
|
291
303
|
*/
|
|
292
|
-
reuploadPinnedData(reference:
|
|
304
|
+
reuploadPinnedData(reference: ReferenceOrEns | string, options?: RequestOptions): Promise<void>;
|
|
293
305
|
/**
|
|
294
306
|
* Checks if content specified by reference is retrievable from the network.
|
|
295
307
|
*
|
|
296
|
-
* @param reference
|
|
308
|
+
* @param reference Bee data reference to be checked in hex string (either 64 or 128 chars long) or ENS domain.
|
|
297
309
|
* @param options Options that affects the request behavior
|
|
310
|
+
* @throws TypeError if some of the input parameters is not expected type
|
|
311
|
+
* @throws BeeArgumentError if there is passed ENS domain with invalid unicode characters
|
|
298
312
|
*
|
|
299
313
|
* @see [Bee API reference - `GET /stewardship`](https://docs.ethswarm.org/api/#tag/Stewardship/paths/~1stewardship~1{reference}/get)
|
|
300
314
|
*/
|
|
301
|
-
isReferenceRetrievable(reference:
|
|
315
|
+
isReferenceRetrievable(reference: ReferenceOrEns | string, options?: RequestOptions): Promise<boolean>;
|
|
316
|
+
/**
|
|
317
|
+
* Functions that validates if feed is retrievable in the network.
|
|
318
|
+
*
|
|
319
|
+
* If no index is passed then it check for "latest" update, which is a weaker guarantee as nobody can be really
|
|
320
|
+
* sure what is the "latest" update.
|
|
321
|
+
*
|
|
322
|
+
* If index is passed then it validates all previous sequence index chunks if they are available as they are required
|
|
323
|
+
* to correctly resolve the feed upto the given index update.
|
|
324
|
+
*
|
|
325
|
+
* @param type
|
|
326
|
+
* @param owner
|
|
327
|
+
* @param topic
|
|
328
|
+
* @param index
|
|
329
|
+
* @param options
|
|
330
|
+
*/
|
|
331
|
+
isFeedRetrievable(type: FeedType, owner: EthAddress | Uint8Array | string, topic: Topic | Uint8Array | string, index?: Index | number | IndexBytes | string, options?: RequestOptions): Promise<boolean>;
|
|
302
332
|
/**
|
|
303
333
|
* Send data to recipient or target with Postal Service for Swarm.
|
|
304
334
|
*
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { BrandedType } from '../types';
|
|
1
|
+
import { BrandedType, PlainBytesReference } from '../types';
|
|
2
2
|
import { Bytes, FlexBytes } from '../utils/bytes';
|
|
3
3
|
export declare const MIN_PAYLOAD_SIZE = 1;
|
|
4
4
|
export declare const MAX_PAYLOAD_SIZE = 4096;
|
|
5
|
-
export declare type ChunkAddress = Bytes<32>;
|
|
6
5
|
/**
|
|
7
6
|
* General chunk interface for Swarm
|
|
8
7
|
*
|
|
@@ -16,7 +15,7 @@ export interface Chunk {
|
|
|
16
15
|
readonly data: Uint8Array;
|
|
17
16
|
span(): Bytes<8>;
|
|
18
17
|
payload(): FlexBytes<1, 4096>;
|
|
19
|
-
address():
|
|
18
|
+
address(): PlainBytesReference;
|
|
20
19
|
}
|
|
21
20
|
declare type ValidChunkData = BrandedType<Uint8Array, 'ValidChunkData'>;
|
|
22
21
|
/**
|
|
@@ -31,7 +30,7 @@ export declare function makeContentAddressedChunk(payloadBytes: Uint8Array): Chu
|
|
|
31
30
|
* @param data The chunk data
|
|
32
31
|
* @param chunkAddress The address of the chunk
|
|
33
32
|
*/
|
|
34
|
-
export declare function isValidChunkData(data: unknown, chunkAddress:
|
|
33
|
+
export declare function isValidChunkData(data: unknown, chunkAddress: PlainBytesReference): data is ValidChunkData;
|
|
35
34
|
/**
|
|
36
35
|
* Asserts if data are representing given address of its chunk.
|
|
37
36
|
*
|
|
@@ -40,5 +39,5 @@ export declare function isValidChunkData(data: unknown, chunkAddress: ChunkAddre
|
|
|
40
39
|
*
|
|
41
40
|
* @returns a valid content addressed chunk or throws error
|
|
42
41
|
*/
|
|
43
|
-
export declare function assertValidChunkData(data: unknown, chunkAddress:
|
|
42
|
+
export declare function assertValidChunkData(data: unknown, chunkAddress: PlainBytesReference): asserts data is ValidChunkData;
|
|
44
43
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Bytes } from '../utils/bytes';
|
|
2
|
-
import { Chunk
|
|
3
|
-
import { UploadOptions, Signature, Signer, BatchId, Reference, Ky } from '../types';
|
|
2
|
+
import { Chunk } from './cac';
|
|
3
|
+
import { UploadOptions, Signature, Signer, BatchId, Reference, Ky, PlainBytesReference } from '../types';
|
|
4
4
|
import { EthAddress } from '../utils/eth';
|
|
5
5
|
export declare type Identifier = Bytes<32>;
|
|
6
6
|
/**
|
|
@@ -24,8 +24,8 @@ export interface SingleOwnerChunk extends Chunk {
|
|
|
24
24
|
*
|
|
25
25
|
* @returns a single owner chunk or throws error
|
|
26
26
|
*/
|
|
27
|
-
export declare function makeSingleOwnerChunkFromData(data: Uint8Array, address:
|
|
28
|
-
export declare function makeSOCAddress(identifier: Identifier, address: EthAddress):
|
|
27
|
+
export declare function makeSingleOwnerChunkFromData(data: Uint8Array, address: PlainBytesReference): SingleOwnerChunk;
|
|
28
|
+
export declare function makeSOCAddress(identifier: Identifier, address: EthAddress): PlainBytesReference;
|
|
29
29
|
/**
|
|
30
30
|
* Creates a single owner chunk object
|
|
31
31
|
*
|
|
@@ -1,35 +1,28 @@
|
|
|
1
|
-
import { Identifier } from '../chunk/soc';
|
|
2
1
|
import { FeedUpdateOptions } from '../modules/feed';
|
|
3
|
-
import {
|
|
2
|
+
import { BatchId, BytesReference, FEED_INDEX_HEX_LENGTH, FeedReader, FeedWriter, Ky, PlainBytesReference, Reference, Signer, Topic, UploadOptions } from '../types';
|
|
4
3
|
import { Bytes } from '../utils/bytes';
|
|
5
4
|
import { HexString } from '../utils/hex';
|
|
6
5
|
import { EthAddress, HexEthAddress } from '../utils/eth';
|
|
7
6
|
import type { FeedType } from './type';
|
|
8
|
-
declare const INDEX_HEX_LENGTH = 16;
|
|
9
7
|
export interface Epoch {
|
|
10
8
|
time: number;
|
|
11
9
|
level: number;
|
|
12
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Bytes of Feed's Index.
|
|
13
|
+
* For Sequential Feeds this is numeric value in big-endian.
|
|
14
|
+
*/
|
|
13
15
|
export declare type IndexBytes = Bytes<8>;
|
|
14
16
|
export declare type Index = number | Epoch | IndexBytes | string;
|
|
15
17
|
export interface FeedUploadOptions extends UploadOptions, FeedUpdateOptions {
|
|
16
18
|
}
|
|
17
|
-
declare type PlainChunkReference = Bytes<32>;
|
|
18
|
-
declare type EncryptedChunkReference = Bytes<64>;
|
|
19
|
-
export declare type ChunkReference = PlainChunkReference | EncryptedChunkReference;
|
|
20
19
|
export interface FeedUpdate {
|
|
21
20
|
timestamp: number;
|
|
22
|
-
reference:
|
|
21
|
+
reference: BytesReference;
|
|
23
22
|
}
|
|
24
|
-
export declare function
|
|
25
|
-
export declare function
|
|
26
|
-
export declare function
|
|
27
|
-
export declare function makeFeedIdentifier(topic: Topic, index: Index): Identifier;
|
|
28
|
-
export declare function uploadFeedUpdate(ky: Ky, signer: Signer, topic: Topic, index: Index, reference: ChunkReference, postageBatchId: BatchId, options?: FeedUploadOptions): Promise<Reference>;
|
|
29
|
-
export declare function findNextIndex(ky: Ky, owner: HexEthAddress, topic: Topic, options?: FeedUpdateOptions): Promise<HexString<typeof INDEX_HEX_LENGTH>>;
|
|
30
|
-
export declare function updateFeed(ky: Ky, signer: Signer, topic: Topic, reference: ChunkReference, postageBatchId: BatchId, options?: FeedUploadOptions): Promise<Reference>;
|
|
31
|
-
export declare function verifyChunkReference(data: Uint8Array): ChunkReference;
|
|
23
|
+
export declare function findNextIndex(ky: Ky, owner: HexEthAddress, topic: Topic, options?: FeedUpdateOptions): Promise<HexString<typeof FEED_INDEX_HEX_LENGTH>>;
|
|
24
|
+
export declare function updateFeed(ky: Ky, signer: Signer, topic: Topic, reference: BytesReference, postageBatchId: BatchId, options?: FeedUploadOptions, index?: Index): Promise<Reference>;
|
|
25
|
+
export declare function getFeedUpdateChunkReference(owner: EthAddress, topic: Topic, index: Index): PlainBytesReference;
|
|
32
26
|
export declare function downloadFeedUpdate(ky: Ky, owner: EthAddress, topic: Topic, index: Index): Promise<FeedUpdate>;
|
|
33
27
|
export declare function makeFeedReader(ky: Ky, type: FeedType, topic: Topic, owner: HexEthAddress): FeedReader;
|
|
34
28
|
export declare function makeFeedWriter(ky: Ky, type: FeedType, topic: Topic, signer: Signer): FeedWriter;
|
|
35
|
-
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Bee } from '../bee';
|
|
2
|
+
import { EthAddress } from '../utils/eth';
|
|
3
|
+
import { RequestOptions, Topic } from '../types';
|
|
4
|
+
import { Index } from './index';
|
|
5
|
+
export declare function areAllSequentialFeedsUpdateRetrievable(bee: Bee, owner: EthAddress, topic: Topic, index: Index, options?: RequestOptions): Promise<boolean>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BatchId, Data, Ky,
|
|
1
|
+
import type { BatchId, Data, Ky, ReferenceOrEns, UploadOptions } from '../types';
|
|
2
2
|
import { UploadResult } from '../types';
|
|
3
3
|
/**
|
|
4
4
|
* Upload data to a Bee node
|
|
@@ -15,11 +15,11 @@ export declare function upload(ky: Ky, data: string | Uint8Array, postageBatchId
|
|
|
15
15
|
* @param ky
|
|
16
16
|
* @param hash Bee content reference
|
|
17
17
|
*/
|
|
18
|
-
export declare function download(ky: Ky, hash:
|
|
18
|
+
export declare function download(ky: Ky, hash: ReferenceOrEns): Promise<Data>;
|
|
19
19
|
/**
|
|
20
20
|
* Download data as a readable stream
|
|
21
21
|
*
|
|
22
22
|
* @param ky
|
|
23
23
|
* @param hash Bee content reference
|
|
24
24
|
*/
|
|
25
|
-
export declare function downloadReadable(ky: Ky, hash:
|
|
25
|
+
export declare function downloadReadable(ky: Ky, hash: ReferenceOrEns): Promise<ReadableStream<Uint8Array>>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BatchId, Collection, CollectionUploadOptions, Data, FileData, FileUploadOptions, Ky, Readable, UploadResult } from '../types';
|
|
1
|
+
import { BatchId, Collection, CollectionUploadOptions, Data, FileData, FileUploadOptions, Ky, Readable, ReferenceOrEns, UploadResult } from '../types';
|
|
2
2
|
/**
|
|
3
3
|
* Upload single file
|
|
4
4
|
*
|
|
@@ -16,7 +16,7 @@ export declare function uploadFile(ky: Ky, data: string | Uint8Array | Readable
|
|
|
16
16
|
* @param hash Bee file or collection hash
|
|
17
17
|
* @param path If hash is collection then this defines path to a single file in the collection
|
|
18
18
|
*/
|
|
19
|
-
export declare function downloadFile(ky: Ky, hash:
|
|
19
|
+
export declare function downloadFile(ky: Ky, hash: ReferenceOrEns, path?: string): Promise<FileData<Data>>;
|
|
20
20
|
/**
|
|
21
21
|
* Download single file as a readable stream
|
|
22
22
|
*
|
|
@@ -24,7 +24,7 @@ export declare function downloadFile(ky: Ky, hash: string, path?: string): Promi
|
|
|
24
24
|
* @param hash Bee file or collection hash
|
|
25
25
|
* @param path If hash is collection then this defines path to a single file in the collection
|
|
26
26
|
*/
|
|
27
|
-
export declare function downloadFileReadable(ky: Ky, hash:
|
|
27
|
+
export declare function downloadFileReadable(ky: Ky, hash: ReferenceOrEns, path?: string): Promise<FileData<ReadableStream<Uint8Array>>>;
|
|
28
28
|
/**
|
|
29
29
|
* Upload collection
|
|
30
30
|
* @param ky Ky instance for given Bee class instance
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BatchId, Data, Ky, Reference, UploadOptions } from '../types';
|
|
1
|
+
import type { BatchId, Data, Ky, Reference, ReferenceOrEns, UploadOptions } from '../types';
|
|
2
2
|
/**
|
|
3
3
|
* Upload chunk to a Bee node
|
|
4
4
|
*
|
|
@@ -19,4 +19,4 @@ export declare function upload(ky: Ky, data: Uint8Array, postageBatchId: BatchId
|
|
|
19
19
|
* @param hash Bee content reference
|
|
20
20
|
*
|
|
21
21
|
*/
|
|
22
|
-
export declare function download(ky: Ky, hash:
|
|
22
|
+
export declare function download(ky: Ky, hash: ReferenceOrEns): Promise<Data>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { Health, NodeInfo } from '../../types/debug';
|
|
2
2
|
import { Ky } from '../../types';
|
|
3
3
|
import { BeeVersions } from '../../types/debug';
|
|
4
|
-
export declare const SUPPORTED_BEE_VERSION_EXACT = "1.
|
|
5
|
-
export declare const SUPPORTED_API_VERSION = "3.0.
|
|
6
|
-
export declare const SUPPORTED_DEBUG_API_VERSION = "2.0.
|
|
4
|
+
export declare const SUPPORTED_BEE_VERSION_EXACT = "1.6.0-6ceadd35";
|
|
5
|
+
export declare const SUPPORTED_API_VERSION = "3.0.1";
|
|
6
|
+
export declare const SUPPORTED_DEBUG_API_VERSION = "2.0.1";
|
|
7
7
|
export declare const SUPPORTED_BEE_VERSION: string;
|
|
8
8
|
/**
|
|
9
9
|
* Get health of node
|
|
@@ -13,9 +13,20 @@ export interface FeedUpdateOptions {
|
|
|
13
13
|
* Can be 'epoch' or 'sequence' (default: 'sequence')
|
|
14
14
|
*/
|
|
15
15
|
type?: FeedType;
|
|
16
|
+
/**
|
|
17
|
+
* Fetch specific previous Feed's update (default fetches latest update)
|
|
18
|
+
*/
|
|
19
|
+
index?: string;
|
|
16
20
|
}
|
|
17
21
|
interface FeedUpdateHeaders {
|
|
22
|
+
/**
|
|
23
|
+
* The current feed's index
|
|
24
|
+
*/
|
|
18
25
|
feedIndex: string;
|
|
26
|
+
/**
|
|
27
|
+
* The feed's index for next update.
|
|
28
|
+
* Only set for the latest update. If update is fetched using previous index, then this is an empty string.
|
|
29
|
+
*/
|
|
19
30
|
feedIndexNext: string;
|
|
20
31
|
}
|
|
21
32
|
export interface FetchFeedUpdateResponse extends ReferenceResponse, FeedUpdateHeaders {
|
|
@@ -43,5 +54,5 @@ export declare function createFeedManifest(ky: Ky, owner: HexEthAddress, topic:
|
|
|
43
54
|
* @param topic Topic in hex
|
|
44
55
|
* @param options Additional options, like index, at, type
|
|
45
56
|
*/
|
|
46
|
-
export declare function
|
|
57
|
+
export declare function fetchLatestFeedUpdate(ky: Ky, owner: HexEthAddress, topic: Topic, options?: FeedUpdateOptions): Promise<FetchFeedUpdateResponse>;
|
|
47
58
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Ky,
|
|
1
|
+
import type { Ky, ReferenceOrEns } from '../types';
|
|
2
2
|
/**
|
|
3
3
|
* Reupload locally pinned data
|
|
4
4
|
* @param ky Ky instance
|
|
@@ -6,5 +6,5 @@ import type { Ky, Reference } from '../types';
|
|
|
6
6
|
* @param options
|
|
7
7
|
* @throws BeeResponseError if not locally pinned or invalid data
|
|
8
8
|
*/
|
|
9
|
-
export declare function reupload(ky: Ky, reference:
|
|
10
|
-
export declare function isRetrievable(ky: Ky, reference:
|
|
9
|
+
export declare function reupload(ky: Ky, reference: ReferenceOrEns): Promise<void>;
|
|
10
|
+
export declare function isRetrievable(ky: Ky, reference: ReferenceOrEns): Promise<boolean>;
|
|
@@ -139,8 +139,27 @@ export declare enum BeeModes {
|
|
|
139
139
|
* Information about Bee node and its configuration
|
|
140
140
|
*/
|
|
141
141
|
export interface NodeInfo {
|
|
142
|
+
/**
|
|
143
|
+
* Indicates whether the node is in a Gateway mode.
|
|
144
|
+
* Gateway mode is a restricted mode where some features are not available.
|
|
145
|
+
*/
|
|
142
146
|
gatewayMode: boolean;
|
|
147
|
+
/**
|
|
148
|
+
* Indicates in what mode Bee is running.
|
|
149
|
+
*/
|
|
143
150
|
beeMode: BeeModes;
|
|
151
|
+
/**
|
|
152
|
+
* Indicates whether the Bee node has its own deployed chequebook.
|
|
153
|
+
*
|
|
154
|
+
* @see [Bee docs - Chequebook](https://docs.ethswarm.org/docs/introduction/terminology#cheques--chequebook)
|
|
155
|
+
*/
|
|
156
|
+
chequebookEnabled: boolean;
|
|
157
|
+
/**
|
|
158
|
+
* Indicates whether SWAP is enabled for the Bee node.
|
|
159
|
+
*
|
|
160
|
+
* @see [Bee docs - SWAP](https://docs.ethswarm.org/docs/introduction/terminology#swap)
|
|
161
|
+
*/
|
|
162
|
+
swapEnabled: boolean;
|
|
144
163
|
}
|
|
145
164
|
/**
|
|
146
165
|
* Information about Bee node and its configuration
|
|
@@ -188,10 +207,8 @@ export interface PingResponse {
|
|
|
188
207
|
}
|
|
189
208
|
export interface ReserveState {
|
|
190
209
|
radius: number;
|
|
210
|
+
commitment: number;
|
|
191
211
|
storageRadius: number;
|
|
192
|
-
available: number;
|
|
193
|
-
outer: NumberString;
|
|
194
|
-
inner: NumberString;
|
|
195
212
|
}
|
|
196
213
|
export interface ChainState {
|
|
197
214
|
block: number;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type { Identifier, SingleOwnerChunk } from '../chunk/soc';
|
|
3
|
-
import type {
|
|
3
|
+
import type { FeedUploadOptions } from '../feed';
|
|
4
4
|
import type { FeedType } from '../feed/type';
|
|
5
5
|
import type { FeedUpdateOptions, FetchFeedUpdateResponse } from '../modules/feed';
|
|
6
6
|
import type { Bytes } from '../utils/bytes';
|
|
@@ -39,6 +39,7 @@ export declare const STAMPS_DEPTH_MIN = 17;
|
|
|
39
39
|
export declare const STAMPS_DEPTH_MAX = 255;
|
|
40
40
|
export declare const TAGS_LIMIT_MIN = 1;
|
|
41
41
|
export declare const TAGS_LIMIT_MAX = 1000;
|
|
42
|
+
export declare const FEED_INDEX_HEX_LENGTH = 16;
|
|
42
43
|
/**
|
|
43
44
|
* Generic reference that can be either non-encrypted reference which is a hex string of length 64 or encrypted
|
|
44
45
|
* reference which is a hex string of length 128.
|
|
@@ -48,6 +49,14 @@ export declare const TAGS_LIMIT_MAX = 1000;
|
|
|
48
49
|
* @see [Bee docs - Store with Encryption](https://docs.ethswarm.org/docs/access-the-swarm/store-with-encryption)
|
|
49
50
|
*/
|
|
50
51
|
export declare type Reference = HexString<typeof REFERENCE_HEX_LENGTH> | HexString<typeof ENCRYPTED_REFERENCE_HEX_LENGTH>;
|
|
52
|
+
/**
|
|
53
|
+
* Type that represents either Swarm's reference in hex string or ESN domain (something.eth).
|
|
54
|
+
* This is the type used on all the download functions.
|
|
55
|
+
*/
|
|
56
|
+
export declare type ReferenceOrEns = Reference | string;
|
|
57
|
+
export declare type PlainBytesReference = Bytes<typeof REFERENCE_BYTES_LENGTH>;
|
|
58
|
+
export declare type EncryptedBytesReference = Bytes<typeof ENCRYPTED_REFERENCE_BYTES_LENGTH>;
|
|
59
|
+
export declare type BytesReference = PlainBytesReference | EncryptedBytesReference;
|
|
51
60
|
export declare type PublicKey = HexString<typeof PUBKEY_HEX_LENGTH>;
|
|
52
61
|
export declare type Address = HexString<typeof ADDRESS_HEX_LENGTH>;
|
|
53
62
|
/**
|
|
@@ -356,7 +365,7 @@ export interface FeedWriter extends FeedReader {
|
|
|
356
365
|
*
|
|
357
366
|
* @returns Reference that points at Single Owner Chunk that contains the new update and pointer to the updated chunk reference.
|
|
358
367
|
*/
|
|
359
|
-
upload(postageBatchId: string | BatchId, reference:
|
|
368
|
+
upload(postageBatchId: string | BatchId, reference: BytesReference | Reference, options?: FeedUploadOptions): Promise<Reference>;
|
|
360
369
|
}
|
|
361
370
|
/**
|
|
362
371
|
* Interface for downloading single owner chunks
|
|
@@ -28,6 +28,13 @@ export interface FlexBytes<Min extends number, Max extends number> extends Uint8
|
|
|
28
28
|
* @param length The length of the byte array
|
|
29
29
|
*/
|
|
30
30
|
export declare function isBytes<Length extends number>(b: unknown, length: Length): b is Bytes<Length>;
|
|
31
|
+
/**
|
|
32
|
+
* Function that verifies if passed data are Bytes and if the array has "length" number of bytes under given offset.
|
|
33
|
+
* @param data
|
|
34
|
+
* @param offset
|
|
35
|
+
* @param length
|
|
36
|
+
*/
|
|
37
|
+
export declare function hasBytesAtOffset(data: unknown, offset: number, length: number): boolean;
|
|
31
38
|
/**
|
|
32
39
|
* Verifies if a byte array has a certain length
|
|
33
40
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Data } from 'ws';
|
|
2
|
-
import
|
|
2
|
+
import BlobPolyfill from 'fetch-blob';
|
|
3
3
|
import { Readable } from '../types';
|
|
4
4
|
/**
|
|
5
5
|
* Prepare data for valid input for node-fetch.
|
|
@@ -10,4 +10,4 @@ import { Readable } from '../types';
|
|
|
10
10
|
* @param data any string, ArrayBuffer, Uint8Array or Readable
|
|
11
11
|
*/
|
|
12
12
|
export declare function prepareData(data: string | ArrayBuffer | Uint8Array | Readable): Promise<Blob | ReadableStream<Uint8Array> | never>;
|
|
13
|
-
export declare function prepareWebsocketData(data: Data |
|
|
13
|
+
export declare function prepareWebsocketData(data: Data | BlobPolyfill): Promise<Uint8Array> | never;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Address, AddressPrefix, AllTagsOptions, BatchId, CollectionUploadOptions, FileUploadOptions, NumberString, PssMessageHandler, PublicKey, Readable, Reference, Tag, UploadOptions, TransactionHash, RequestOptions, PostageBatchOptions, CashoutOptions } from '../types';
|
|
1
|
+
import { Address, AddressPrefix, AllTagsOptions, BatchId, CollectionUploadOptions, FileUploadOptions, NumberString, PssMessageHandler, PublicKey, Readable, Reference, Tag, UploadOptions, TransactionHash, RequestOptions, PostageBatchOptions, CashoutOptions, ReferenceOrEns } from '../types';
|
|
2
2
|
export declare function isUint8Array(obj: unknown): obj is Uint8Array;
|
|
3
3
|
export declare function isInteger(value: unknown): value is number | NumberString;
|
|
4
4
|
export declare function isObject(value: unknown): value is Record<string, unknown>;
|
|
@@ -23,6 +23,7 @@ export declare function assertBoolean(value: unknown, name?: string): asserts va
|
|
|
23
23
|
export declare function assertInteger(value: unknown, name?: string): asserts value is number | NumberString;
|
|
24
24
|
export declare function assertNonNegativeInteger(value: unknown, name?: string): asserts value is number | NumberString;
|
|
25
25
|
export declare function assertReference(value: unknown): asserts value is Reference;
|
|
26
|
+
export declare function assertReferenceOrEns(value: unknown): asserts value is ReferenceOrEns;
|
|
26
27
|
export declare function assertAddress(value: unknown): asserts value is Address;
|
|
27
28
|
export declare function assertBatchId(value: unknown): asserts value is BatchId;
|
|
28
29
|
export declare function assertRequestOptions(value: unknown, name?: string): asserts value is RequestOptions;
|