@ethersphere/bee-js 10.2.0 → 10.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/cjs/bee.js +75 -5
- package/dist/cjs/chunk/cac.js +26 -31
- package/dist/cjs/chunk/soc.js +17 -18
- package/dist/cjs/feed/index.js +4 -3
- package/dist/cjs/modules/debug/stamps.js +16 -69
- package/dist/cjs/utils/expose.js +3 -1
- package/dist/cjs/utils/stamps.js +51 -1
- package/dist/cjs/utils/workaround.js +5 -2
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/bee.js +76 -8
- package/dist/mjs/chunk/cac.js +21 -30
- package/dist/mjs/chunk/soc.js +16 -17
- package/dist/mjs/feed/index.js +7 -6
- package/dist/mjs/modules/debug/stamps.js +37 -110
- package/dist/mjs/utils/expose.js +1 -1
- package/dist/mjs/utils/stamps.js +48 -0
- package/dist/mjs/utils/workaround.js +5 -2
- package/dist/types/bee.d.ts +58 -3
- package/dist/types/chunk/cac.d.ts +27 -13
- package/dist/types/chunk/soc.d.ts +43 -11
- package/dist/types/index.d.ts +2 -0
- package/dist/types/utils/expose.d.ts +1 -1
- package/dist/types/utils/stamps.d.ts +15 -1
- package/package.json +2 -2
package/dist/types/bee.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Readable } from 'stream';
|
|
3
3
|
import { Chunk } from './chunk/cac';
|
|
4
|
+
import { SingleOwnerChunk } from './chunk/soc';
|
|
4
5
|
import { FeedPayloadResult } from './modules/feed';
|
|
5
6
|
import type { AllSettlements, BalanceResponse, BeeOptions, BeeRequestOptions, BeeVersions, ChainState, ChequebookAddressResponse, ChequebookBalanceResponse, CollectionUploadOptions, DebugStatus, DownloadOptions, EnvelopeWithBatchId, FeedReader, FeedWriter, FileData, FileUploadOptions, GetGranteesResult, GlobalPostageBatch, GranteesResult, GsocMessageHandler, GsocSubscription, Health, LastCashoutActionResponse, LastChequesForPeerResponse, LastChequesResponse, NodeAddresses, NodeInfo, NumberString, Peer, PeerBalance, Pin, PingResponse, PostageBatch, PostageBatchBuckets, PssMessageHandler, PssSubscription, Readiness, RedistributionState, RedundancyLevel, RedundantUploadOptions, ReferenceInformation, RemovePeerResponse, ReserveState, SOCReader, SOCWriter, Settlements, Tag, Topology, TransactionInfo, UploadOptions, WalletBalance } from './types';
|
|
6
7
|
import { AllTagsOptions, Collection, PostageBatchOptions, TransactionOptions, UploadResult } from './types';
|
|
@@ -8,7 +9,7 @@ import { Bytes } from './utils/bytes';
|
|
|
8
9
|
import { Duration } from './utils/duration';
|
|
9
10
|
import { Size } from './utils/size';
|
|
10
11
|
import { BZZ, DAI } from './utils/tokens';
|
|
11
|
-
import { BatchId, EthAddress, FeedIndex, Identifier, PeerAddress, PrivateKey, PublicKey, Reference, Topic, TransactionId } from './utils/typed-bytes';
|
|
12
|
+
import { BatchId, EthAddress, FeedIndex, Identifier, PeerAddress, PrivateKey, PublicKey, Reference, Span, Topic, TransactionId } from './utils/typed-bytes';
|
|
12
13
|
import { UploadProgress } from './utils/upload-progress';
|
|
13
14
|
/**
|
|
14
15
|
* The main component that abstracts operations available on the Bee API.
|
|
@@ -123,7 +124,7 @@ export declare class Bee {
|
|
|
123
124
|
* Chunks uploaded with this method should be retrieved with the {@link downloadChunk} method.
|
|
124
125
|
*
|
|
125
126
|
* @param stamp Postage Batch ID or an Envelope created with the {@link createEnvelope} method.
|
|
126
|
-
* @param data Raw chunk to be uploaded
|
|
127
|
+
* @param data Raw chunk to be uploaded (Content Addressed Chunk or Single Owner Chunk)
|
|
127
128
|
* @param options Additional options like tag, encryption, pinning, content-type and request options
|
|
128
129
|
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
129
130
|
*
|
|
@@ -131,7 +132,7 @@ export declare class Bee {
|
|
|
131
132
|
* @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/develop/access-the-swarm/upload-and-download)
|
|
132
133
|
* @see [Bee API reference - `POST /chunks`](https://docs.ethswarm.org/api/#tag/Chunk/paths/~1chunks/post)
|
|
133
134
|
*/
|
|
134
|
-
uploadChunk(stamp: EnvelopeWithBatchId | BatchId | Uint8Array | string, data: Uint8Array | Chunk, options?: UploadOptions, requestOptions?: BeeRequestOptions): Promise<UploadResult>;
|
|
135
|
+
uploadChunk(stamp: EnvelopeWithBatchId | BatchId | Uint8Array | string, data: Uint8Array | Chunk | SingleOwnerChunk, options?: UploadOptions, requestOptions?: BeeRequestOptions): Promise<UploadResult>;
|
|
135
136
|
/**
|
|
136
137
|
* Downloads a chunk as a `Uint8Array`.
|
|
137
138
|
*
|
|
@@ -608,6 +609,60 @@ export declare class Bee {
|
|
|
608
609
|
*/
|
|
609
610
|
makeFeedWriter(topic: Topic | Uint8Array | string, signer?: PrivateKey | Uint8Array | string, requestOptions?: BeeRequestOptions): FeedWriter;
|
|
610
611
|
fetchLatestFeedUpdate(topic: Topic | Uint8Array | string, owner: EthAddress | Uint8Array | string, requestOptions?: BeeRequestOptions): Promise<FeedPayloadResult>;
|
|
612
|
+
/**
|
|
613
|
+
* Creates a Content Addressed Chunk.
|
|
614
|
+
*
|
|
615
|
+
* To be uploaded with the {@link uploadChunk} method.
|
|
616
|
+
*
|
|
617
|
+
* Payload size must be between 1 and 4096 bytes.
|
|
618
|
+
*
|
|
619
|
+
* @param rawPayload Data to be stored in the chunk. If the data is a string, it will be converted to UTF-8 bytes.
|
|
620
|
+
* @param span Optional span for the chunk. If not provided, it will be set to the length of the payload.
|
|
621
|
+
*
|
|
622
|
+
* @example
|
|
623
|
+
*
|
|
624
|
+
*/
|
|
625
|
+
makeContentAddressedChunk(rawPayload: Bytes | Uint8Array | string, span?: Span | bigint): Chunk;
|
|
626
|
+
/**
|
|
627
|
+
* Attempts to unmarshal arbitrary data into a Content Addressed Chunk.
|
|
628
|
+
* Throws an error if the data is not a valid CAC.
|
|
629
|
+
*
|
|
630
|
+
* @param data The chunk data (`span` and `payload`)
|
|
631
|
+
*/
|
|
632
|
+
unmarshalContentAddressedChunk(data: Bytes | Uint8Array): Chunk;
|
|
633
|
+
/**
|
|
634
|
+
* Creates a Single Owner Chunk.
|
|
635
|
+
*
|
|
636
|
+
* To be uploaded with the {@link uploadChunk} method.
|
|
637
|
+
*
|
|
638
|
+
* Identical to chaining `makeContentAddressedChunk` and `toSingleOwnerChunk`.
|
|
639
|
+
*
|
|
640
|
+
* Payload size must be between 1 and 4096 bytes.
|
|
641
|
+
*
|
|
642
|
+
* @param address Address of the Content Addressed Chunk
|
|
643
|
+
* @param span Span of the Content Addressed Chunk
|
|
644
|
+
* @param payload Payload of the Content Addressed Chunk
|
|
645
|
+
* @param identifier The identifier of the chunk
|
|
646
|
+
* @param signer The signer interface for signing the chunk
|
|
647
|
+
*/
|
|
648
|
+
makeSingleOwnerChunk(address: Reference, span: Span, payload: Bytes, identifier: Identifier | Uint8Array | string, signer: PrivateKey | Uint8Array | string): SingleOwnerChunk;
|
|
649
|
+
/**
|
|
650
|
+
* Calculates the address of a Single Owner Chunk based on its identifier and owner address.
|
|
651
|
+
*
|
|
652
|
+
* @param identifier
|
|
653
|
+
* @param address
|
|
654
|
+
*/
|
|
655
|
+
calculateSingleOwnerChunkAddress(identifier: Identifier, address: EthAddress): Reference;
|
|
656
|
+
/**
|
|
657
|
+
* Attempts to unmarshal arbitrary data into a Single Owner Chunk.
|
|
658
|
+
* Throws an error if the data is not a valid SOC.
|
|
659
|
+
*
|
|
660
|
+
* @param data The chunk data
|
|
661
|
+
* @param address The address of the single owner chunk
|
|
662
|
+
*
|
|
663
|
+
* @returns a single owner chunk or throws error
|
|
664
|
+
*/
|
|
665
|
+
unmarshalSingleOwnerChunk(data: Bytes | Uint8Array, address: Reference | Uint8Array | string): SingleOwnerChunk;
|
|
611
666
|
/**
|
|
612
667
|
* Returns an object for reading single owner chunks
|
|
613
668
|
*
|
|
@@ -1,26 +1,40 @@
|
|
|
1
1
|
import { Bytes } from '../utils/bytes';
|
|
2
|
-
import { Reference, Span } from '../utils/typed-bytes';
|
|
2
|
+
import { Identifier, PrivateKey, Reference, Span } from '../utils/typed-bytes';
|
|
3
|
+
import { SingleOwnerChunk } from './soc';
|
|
3
4
|
export declare const MIN_PAYLOAD_SIZE = 1;
|
|
4
5
|
export declare const MAX_PAYLOAD_SIZE = 4096;
|
|
5
6
|
/**
|
|
6
|
-
*
|
|
7
|
+
* Content Addressed Chunk (CAC) is the immutable building block of Swarm,
|
|
8
|
+
* holding at most 4096 bytes of payload.
|
|
7
9
|
*
|
|
8
|
-
*
|
|
9
|
-
* the
|
|
10
|
+
* - `span` indicates the size of the `payload` in bytes.
|
|
11
|
+
* - `payload` contains the actual data or the body of the chunk.
|
|
12
|
+
* - `data` contains the full chunk data - `span` and `payload`.
|
|
13
|
+
* - `address` is the Swarm hash (or reference) of the chunk.
|
|
10
14
|
*
|
|
11
|
-
*
|
|
12
|
-
* the chunk that is required for the Chunk API.
|
|
15
|
+
* The `toSingleOwnerChunk` method allows converting the CAC into a Single Owner Chunk (SOC).
|
|
13
16
|
*/
|
|
14
17
|
export interface Chunk {
|
|
18
|
+
/**
|
|
19
|
+
* Contains the full chunk data - `span` + `payload`.
|
|
20
|
+
*/
|
|
15
21
|
readonly data: Uint8Array;
|
|
22
|
+
/**
|
|
23
|
+
* Indicates the size of the `payload` in bytes.
|
|
24
|
+
*/
|
|
16
25
|
span: Span;
|
|
26
|
+
/**
|
|
27
|
+
* Contains the actual data or the body of the chunk.
|
|
28
|
+
*/
|
|
17
29
|
payload: Bytes;
|
|
30
|
+
/**
|
|
31
|
+
* The Swarm hash (or reference) of the chunk.
|
|
32
|
+
*/
|
|
18
33
|
address: Reference;
|
|
34
|
+
/**
|
|
35
|
+
* Converts the CAC into a Single Owner Chunk (SOC).
|
|
36
|
+
*/
|
|
37
|
+
toSingleOwnerChunk: (identifier: Identifier | Uint8Array | string, signer: PrivateKey | Uint8Array | string) => SingleOwnerChunk;
|
|
19
38
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
*
|
|
23
|
-
* @param payloadBytes the data to be stored in the chunk
|
|
24
|
-
*/
|
|
25
|
-
export declare function makeContentAddressedChunk(payloadBytes: Uint8Array | string): Chunk;
|
|
26
|
-
export declare function asContentAddressedChunk(chunkBytes: Uint8Array): Chunk;
|
|
39
|
+
export declare function unmarshalContentAddressedChunk(data: Bytes | Uint8Array): Chunk;
|
|
40
|
+
export declare function makeContentAddressedChunk(rawPayload: Bytes | Uint8Array | string, span?: Span | bigint): Chunk;
|
|
@@ -1,29 +1,61 @@
|
|
|
1
1
|
import { BeeRequestOptions, UploadOptions, UploadResult } from '../types';
|
|
2
2
|
import { Bytes } from '../utils/bytes';
|
|
3
|
-
import { BatchId, EthAddress, Identifier, PrivateKey, Reference, Signature } from '../utils/typed-bytes';
|
|
3
|
+
import { BatchId, EthAddress, Identifier, PrivateKey, Reference, Signature, Span } from '../utils/typed-bytes';
|
|
4
4
|
import { Chunk } from './cac';
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* Single Owner Chunk (SOC) is a chunk type where the address is determined by the owner and an arbitrary identifier.
|
|
7
|
+
* Its integrity is attested by the owner's digital signature.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
9
|
+
* Similar to Content Addressed Chunks (CAC), SOCs have a maximum payload size of 4096 bytes.
|
|
10
|
+
*
|
|
11
|
+
* - `span` indicates the size of the `payload` in bytes.
|
|
12
|
+
* - `payload` contains the actual data or the body of the chunk.
|
|
13
|
+
* - `data` contains the full chunk data - `span` and `payload`.
|
|
14
|
+
* - `address` is the Swarm hash (or reference) of the chunk.
|
|
15
|
+
* - `identifier` is an arbitrary identifier selected by the uploader.
|
|
16
|
+
* - `signature` is the digital signature of the owner over the identifier and the underlying CAC address.
|
|
17
|
+
* - `owner` is the Ethereum address of the chunk owner.
|
|
12
18
|
*/
|
|
13
|
-
export interface SingleOwnerChunk
|
|
19
|
+
export interface SingleOwnerChunk {
|
|
20
|
+
/**
|
|
21
|
+
* Contains the full chunk data - `span` + `payload`.
|
|
22
|
+
*/
|
|
23
|
+
readonly data: Uint8Array;
|
|
24
|
+
/**
|
|
25
|
+
* Indicates the size of the `payload` in bytes.
|
|
26
|
+
*/
|
|
27
|
+
span: Span;
|
|
28
|
+
/**
|
|
29
|
+
* Contains the actual data or the body of the chunk.
|
|
30
|
+
*/
|
|
31
|
+
payload: Bytes;
|
|
32
|
+
/**
|
|
33
|
+
* The Swarm hash (or reference) of the chunk.
|
|
34
|
+
*/
|
|
35
|
+
address: Reference;
|
|
36
|
+
/**
|
|
37
|
+
* An arbitrary identifier selected by the uploader.
|
|
38
|
+
*/
|
|
14
39
|
identifier: Identifier;
|
|
40
|
+
/**
|
|
41
|
+
* The digital signature of the owner over the identifier and the underlying CAC address.
|
|
42
|
+
*/
|
|
15
43
|
signature: Signature;
|
|
44
|
+
/**
|
|
45
|
+
* The Ethereum address of the chunk owner.
|
|
46
|
+
*/
|
|
16
47
|
owner: EthAddress;
|
|
17
48
|
}
|
|
18
49
|
/**
|
|
19
|
-
*
|
|
50
|
+
* Unmarshals arbitrary data into a Single Owner Chunk.
|
|
51
|
+
* Throws an error if the data is not a valid SOC.
|
|
20
52
|
*
|
|
21
53
|
* @param data The chunk data
|
|
22
54
|
* @param address The address of the single owner chunk
|
|
23
55
|
*
|
|
24
56
|
* @returns a single owner chunk or throws error
|
|
25
57
|
*/
|
|
26
|
-
export declare function
|
|
58
|
+
export declare function unmarshalSingleOwnerChunk(data: Bytes | Uint8Array, address: Reference | Uint8Array | string): SingleOwnerChunk;
|
|
27
59
|
export declare function makeSOCAddress(identifier: Identifier, address: EthAddress): Reference;
|
|
28
60
|
/**
|
|
29
61
|
* Creates a single owner chunk object
|
|
@@ -32,7 +64,7 @@ export declare function makeSOCAddress(identifier: Identifier, address: EthAddre
|
|
|
32
64
|
* @param identifier The identifier of the chunk
|
|
33
65
|
* @param signer The signer interface for signing the chunk
|
|
34
66
|
*/
|
|
35
|
-
export declare function makeSingleOwnerChunk(
|
|
67
|
+
export declare function makeSingleOwnerChunk(address: Reference, span: Span, payload: Bytes, identifier: Identifier | Uint8Array | string, signer: PrivateKey | Uint8Array | string): SingleOwnerChunk;
|
|
36
68
|
/**
|
|
37
69
|
* Helper function to upload a chunk.
|
|
38
70
|
*
|
|
@@ -55,7 +87,7 @@ export declare function uploadSingleOwnerChunk(requestOptions: BeeRequestOptions
|
|
|
55
87
|
* @param options
|
|
56
88
|
*/
|
|
57
89
|
export declare function uploadSingleOwnerChunkData(requestOptions: BeeRequestOptions, signer: PrivateKey | Uint8Array | string, stamp: BatchId | Uint8Array | string, identifier: Identifier | Uint8Array | string, data: Uint8Array, options?: UploadOptions): Promise<UploadResult>;
|
|
58
|
-
export declare function uploadSingleOwnerChunkWithWrappedChunk(requestOptions: BeeRequestOptions, signer: PrivateKey | Uint8Array | string, stamp: BatchId | Uint8Array | string, identifier: Identifier | Uint8Array | string,
|
|
90
|
+
export declare function uploadSingleOwnerChunkWithWrappedChunk(requestOptions: BeeRequestOptions, signer: PrivateKey | Uint8Array | string, stamp: BatchId | Uint8Array | string, identifier: Identifier | Uint8Array | string, wrappedChunk: Chunk, options?: UploadOptions): Promise<UploadResult>;
|
|
59
91
|
/**
|
|
60
92
|
* Helper function to download SOC.
|
|
61
93
|
*
|
package/dist/types/index.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ import { Bee } from './bee';
|
|
|
2
2
|
import { BeeDev } from './bee-dev';
|
|
3
3
|
import { Stamper } from './stamper/stamper';
|
|
4
4
|
export { MerkleTree } from 'cafe-utility';
|
|
5
|
+
export type { Chunk } from './chunk/cac';
|
|
6
|
+
export type { SingleOwnerChunk } from './chunk/soc';
|
|
5
7
|
export { MantarayNode } from './manifest/manifest';
|
|
6
8
|
export { SUPPORTED_BEE_VERSION, SUPPORTED_BEE_VERSION_EXACT } from './modules/debug/status';
|
|
7
9
|
export * from './types';
|
|
@@ -2,4 +2,4 @@ export { getCollectionSize, makeCollectionFromFileList } from './collection';
|
|
|
2
2
|
export { getFolderSize } from './collection.node';
|
|
3
3
|
export { makeMaxTarget } from './pss';
|
|
4
4
|
export { approximateOverheadForRedundancyLevel, getRedundancyStat, getRedundancyStats } from './redundancy';
|
|
5
|
-
export { getAmountForDuration, getDepthForSize, getStampCost, getStampDuration, getStampEffectiveBytes, getStampEffectiveBytesBreakpoints, getStampTheoreticalBytes, getStampUsage, } from './stamps';
|
|
5
|
+
export { getAmountForDuration, getDepthForSize, getStampCost, getStampDuration, getStampEffectiveBytes, getStampEffectiveBytesBreakpoints, getStampTheoreticalBytes, getStampUsage, mapPostageBatch, unmapPostageBatch, } from './stamps';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EnvelopeWithBatchId, NumberString, RedundancyLevel } from '../types';
|
|
1
|
+
import { EnvelopeWithBatchId, NumberString, PostageBatch, RedundancyLevel } from '../types';
|
|
2
2
|
import { Bytes } from './bytes';
|
|
3
3
|
import { Duration } from './duration';
|
|
4
4
|
import { Size } from './size';
|
|
@@ -58,3 +58,17 @@ export declare function getAmountForDuration(duration: Duration, pricePerBlock:
|
|
|
58
58
|
export declare function getDepthForSize(size: Size, encryption?: boolean, erasureCodeLevel?: RedundancyLevel): number;
|
|
59
59
|
export declare function convertEnvelopeToMarshaledStamp(envelope: EnvelopeWithBatchId): Bytes;
|
|
60
60
|
export declare function marshalStamp(signature: Uint8Array, batchId: Uint8Array, timestamp: Uint8Array, index: Uint8Array): Bytes;
|
|
61
|
+
export interface RawPostageBatch {
|
|
62
|
+
batchID: string;
|
|
63
|
+
utilization: number;
|
|
64
|
+
usable: boolean;
|
|
65
|
+
label: string;
|
|
66
|
+
depth: number;
|
|
67
|
+
amount: string;
|
|
68
|
+
bucketDepth: number;
|
|
69
|
+
blockNumber: number;
|
|
70
|
+
immutableFlag: boolean;
|
|
71
|
+
batchTTL: number;
|
|
72
|
+
}
|
|
73
|
+
export declare function mapPostageBatch(raw: RawPostageBatch, encryption?: boolean, erasureCodeLevel?: RedundancyLevel): PostageBatch;
|
|
74
|
+
export declare function unmapPostageBatch(batch: PostageBatch): RawPostageBatch;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ethersphere/bee-js",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.4.0",
|
|
4
4
|
"description": "Javascript client for Bee",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bee",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
64
|
"axios": "^0.30.0",
|
|
65
|
-
"cafe-utility": "^
|
|
65
|
+
"cafe-utility": "^33.3.4",
|
|
66
66
|
"debug": "^4.4.1",
|
|
67
67
|
"isomorphic-ws": "^4.0.1",
|
|
68
68
|
"semver": "^7.3.5",
|