@upcoming/bee-js 10.1.2 → 12.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/README.md +2 -2
- package/dist/cjs/bee.js +105 -12
- package/dist/cjs/chunk/bmt.js +1 -2
- package/dist/cjs/chunk/cac.js +27 -32
- package/dist/cjs/chunk/soc.js +39 -31
- package/dist/cjs/feed/identifier.js +1 -2
- package/dist/cjs/feed/index.js +29 -19
- package/dist/cjs/feed/retrievable.js +1 -2
- package/dist/cjs/index.js +17 -7
- package/dist/cjs/manifest/manifest.js +19 -2
- package/dist/cjs/modules/bytes.js +4 -5
- package/dist/cjs/modules/bzz.js +4 -5
- package/dist/cjs/modules/chunk.js +2 -3
- package/dist/cjs/modules/debug/balance.js +4 -5
- package/dist/cjs/modules/debug/chequebook.js +8 -9
- package/dist/cjs/modules/debug/connectivity.js +7 -8
- package/dist/cjs/modules/debug/settlements.js +2 -3
- package/dist/cjs/modules/debug/stake.js +6 -7
- package/dist/cjs/modules/debug/stamps.js +23 -77
- package/dist/cjs/modules/debug/states.js +6 -6
- package/dist/cjs/modules/debug/status.js +9 -9
- package/dist/cjs/modules/debug/transactions.js +4 -5
- package/dist/cjs/modules/envelope.js +1 -2
- package/dist/cjs/modules/feed.js +3 -4
- package/dist/cjs/modules/grantee.js +3 -4
- package/dist/cjs/modules/gsoc.js +2 -3
- package/dist/cjs/modules/pinning.js +4 -5
- package/dist/cjs/modules/pss.js +2 -3
- package/dist/cjs/modules/rchash.js +1 -2
- package/dist/cjs/modules/soc.js +1 -2
- package/dist/cjs/modules/status.js +2 -3
- package/dist/cjs/modules/stewardship.js +2 -3
- package/dist/cjs/modules/tag.js +5 -6
- package/dist/cjs/types/debug.js +3 -3
- package/dist/cjs/types/index.js +2 -2
- package/dist/cjs/utils/bytes.js +2 -2
- package/dist/cjs/utils/chunk-size.js +1 -2
- package/dist/cjs/utils/chunk-stream.browser.js +30 -6
- package/dist/cjs/utils/chunk-stream.js +3 -4
- package/dist/cjs/utils/cid.js +3 -3
- package/dist/cjs/utils/collection.browser.js +2 -3
- package/dist/cjs/utils/collection.js +5 -6
- package/dist/cjs/utils/collection.node.js +2 -3
- package/dist/cjs/utils/data.browser.js +1 -2
- package/dist/cjs/utils/data.js +1 -2
- package/dist/cjs/utils/expose.js +4 -1
- package/dist/cjs/utils/file.js +2 -3
- package/dist/cjs/utils/headers.js +2 -3
- package/dist/cjs/utils/http.js +25 -5
- package/dist/cjs/utils/pss.js +1 -2
- package/dist/cjs/utils/redundancy.js +3 -4
- package/dist/cjs/utils/stamps.js +60 -11
- package/dist/cjs/utils/tar-uploader.browser.js +1 -2
- package/dist/cjs/utils/tar-uploader.js +1 -2
- package/dist/cjs/utils/tar-writer.browser.js +1 -2
- package/dist/cjs/utils/tar-writer.js +1 -2
- package/dist/cjs/utils/type.js +35 -25
- package/dist/cjs/utils/url.js +3 -4
- package/dist/cjs/utils/workaround.js +7 -5
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/bee.js +93 -9
- 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/manifest/manifest.js +19 -2
- package/dist/mjs/modules/debug/stamps.js +37 -110
- package/dist/mjs/modules/debug/states.js +3 -0
- package/dist/mjs/modules/debug/status.js +1 -1
- package/dist/mjs/utils/chunk-stream.browser.js +29 -5
- package/dist/mjs/utils/expose.js +1 -1
- package/dist/mjs/utils/http.js +25 -3
- package/dist/mjs/utils/stamps.js +48 -0
- package/dist/mjs/utils/type.js +2 -1
- package/dist/mjs/utils/workaround.js +5 -2
- package/dist/types/bee.d.ts +67 -4
- package/dist/types/chunk/cac.d.ts +27 -13
- package/dist/types/chunk/soc.d.ts +43 -11
- package/dist/types/index.d.ts +3 -0
- package/dist/types/modules/bzz.d.ts +0 -1
- package/dist/types/modules/debug/status.d.ts +1 -1
- package/dist/types/modules/gsoc.d.ts +0 -1
- package/dist/types/modules/pss.d.ts +0 -1
- package/dist/types/types/debug.d.ts +1 -0
- package/dist/types/types/index.d.ts +1 -0
- package/dist/types/utils/constants.d.ts +3 -3
- package/dist/types/utils/error.d.ts +2 -2
- package/dist/types/utils/expose.d.ts +1 -1
- package/dist/types/utils/stamps.d.ts +15 -1
- package/dist/types/utils/tar-uploader.browser.d.ts +1 -1
- package/dist/types/utils/tar-uploader.d.ts +1 -1
- package/dist/types/utils/tar.browser.d.ts +1 -1
- package/dist/types/utils/tar.d.ts +0 -1
- package/dist/types/utils/type.d.ts +0 -1
- package/package.json +10 -13
package/dist/mjs/utils/http.js
CHANGED
|
@@ -10,6 +10,7 @@ const MAX_FAILED_ATTEMPTS = 100000;
|
|
|
10
10
|
const DELAY_FAST = 200;
|
|
11
11
|
const DELAY_SLOW = 1000;
|
|
12
12
|
const DELAY_THRESHOLD = Dates.minutes(1) / DELAY_FAST;
|
|
13
|
+
const ABORT_ERROR_MESSAGE = 'Request aborted';
|
|
13
14
|
export const DEFAULT_HTTP_CONFIG = {
|
|
14
15
|
headers: {
|
|
15
16
|
accept: 'application/json, text/plain, */*'
|
|
@@ -17,6 +18,11 @@ export const DEFAULT_HTTP_CONFIG = {
|
|
|
17
18
|
maxBodyLength: Infinity,
|
|
18
19
|
maxContentLength: Infinity
|
|
19
20
|
};
|
|
21
|
+
function throwIfAborted(signal, config, responseData, responseStatus) {
|
|
22
|
+
if (signal?.aborted) {
|
|
23
|
+
throw new BeeResponseError(config.method || 'get', config.url || '<unknown>', ABORT_ERROR_MESSAGE, responseData, responseStatus, 'ERR_CANCELED');
|
|
24
|
+
}
|
|
25
|
+
}
|
|
20
26
|
/**
|
|
21
27
|
* Main function to make HTTP requests.
|
|
22
28
|
* @param options User defined settings
|
|
@@ -24,9 +30,11 @@ export const DEFAULT_HTTP_CONFIG = {
|
|
|
24
30
|
*/
|
|
25
31
|
export async function http(options, config) {
|
|
26
32
|
const requestConfig = Objects.deepMerge3(DEFAULT_HTTP_CONFIG, config, options);
|
|
27
|
-
if (
|
|
28
|
-
requestConfig.
|
|
33
|
+
if (options.signal) {
|
|
34
|
+
requestConfig.signal = options.signal;
|
|
35
|
+
throwIfAborted(options.signal, config);
|
|
29
36
|
}
|
|
37
|
+
maybeReplaceBodyBuffers(requestConfig);
|
|
30
38
|
if (requestConfig.params) {
|
|
31
39
|
const keys = Object.keys(requestConfig.params);
|
|
32
40
|
for (const key of keys) {
|
|
@@ -38,6 +46,7 @@ export async function http(options, config) {
|
|
|
38
46
|
}
|
|
39
47
|
let failedAttempts = 0;
|
|
40
48
|
while (failedAttempts < MAX_FAILED_ATTEMPTS) {
|
|
49
|
+
throwIfAborted(options.signal, config);
|
|
41
50
|
try {
|
|
42
51
|
debug(`${requestConfig.method || 'get'} ${Strings.joinUrl([requestConfig.baseURL, requestConfig.url])}`, {
|
|
43
52
|
headers: {
|
|
@@ -50,11 +59,16 @@ export async function http(options, config) {
|
|
|
50
59
|
return response;
|
|
51
60
|
} catch (e) {
|
|
52
61
|
if (e instanceof AxiosError) {
|
|
62
|
+
if (e.code === 'ERR_CANCELED') {
|
|
63
|
+
throwIfAborted({
|
|
64
|
+
aborted: true
|
|
65
|
+
}, config, e.response?.data, e.response?.status);
|
|
66
|
+
}
|
|
53
67
|
if (e.code === 'ECONNABORTED' && options.endlesslyRetry) {
|
|
54
68
|
failedAttempts++;
|
|
55
69
|
await System.sleepMillis(failedAttempts < DELAY_THRESHOLD ? DELAY_FAST : DELAY_SLOW);
|
|
56
70
|
} else {
|
|
57
|
-
throw new BeeResponseError(config.method || 'get', config.url || '<unknown>', e.message, e.response?.data, e.response?.status, e.
|
|
71
|
+
throw new BeeResponseError(config.method || 'get', config.url || '<unknown>', e.message, e.response?.data, e.response?.status, e.response?.statusText);
|
|
58
72
|
}
|
|
59
73
|
} else {
|
|
60
74
|
throw e;
|
|
@@ -74,4 +88,12 @@ function maybeRunOnRequestHook(options, requestConfig) {
|
|
|
74
88
|
params: requestConfig.params
|
|
75
89
|
});
|
|
76
90
|
}
|
|
91
|
+
}
|
|
92
|
+
function maybeReplaceBodyBuffers(config) {
|
|
93
|
+
if (config.data && config.data instanceof Uint8Array) {
|
|
94
|
+
config.data = config.data.buffer.slice(config.data.byteOffset, config.data.byteOffset + config.data.byteLength);
|
|
95
|
+
}
|
|
96
|
+
if (config.data && typeof Buffer !== 'undefined' && Buffer.isBuffer(config.data)) {
|
|
97
|
+
config.data = config.data.buffer.slice(config.data.byteOffset, config.data.byteOffset + config.data.byteLength);
|
|
98
|
+
}
|
|
77
99
|
}
|
package/dist/mjs/utils/stamps.js
CHANGED
|
@@ -2,8 +2,11 @@ import { Binary } from 'cafe-utility';
|
|
|
2
2
|
import { capacityBreakpoints } from "../types/index.js";
|
|
3
3
|
import { Bytes, parseSizeToBytes } from "./bytes.js";
|
|
4
4
|
import { Duration } from "./duration.js";
|
|
5
|
+
import { Size } from "./size.js";
|
|
5
6
|
import { BZZ } from "./tokens.js";
|
|
6
7
|
import { asNumberString } from "./type.js";
|
|
8
|
+
import { BatchId } from "./typed-bytes.js";
|
|
9
|
+
import { normalizeBatchTTL } from "./workaround.js";
|
|
7
10
|
const MAX_UTILIZATION = 0.9;
|
|
8
11
|
/**
|
|
9
12
|
* Utility function that calculates usage of postage batch based on its utilization, depth and bucket depth.
|
|
@@ -137,4 +140,49 @@ export function marshalStamp(signature, batchId, timestamp, index) {
|
|
|
137
140
|
throw Error('invalid index length');
|
|
138
141
|
}
|
|
139
142
|
return new Bytes(Binary.concatBytes(batchId, index, timestamp, signature));
|
|
143
|
+
}
|
|
144
|
+
export function mapPostageBatch(raw, encryption, erasureCodeLevel) {
|
|
145
|
+
const usage = getStampUsage(raw.utilization, raw.depth, raw.bucketDepth);
|
|
146
|
+
const batchTTL = normalizeBatchTTL(raw.batchTTL);
|
|
147
|
+
const duration = Duration.fromSeconds(batchTTL);
|
|
148
|
+
const effectiveBytes = getStampEffectiveBytes(raw.depth, encryption, erasureCodeLevel);
|
|
149
|
+
return {
|
|
150
|
+
batchID: new BatchId(raw.batchID),
|
|
151
|
+
utilization: raw.utilization,
|
|
152
|
+
usable: raw.usable,
|
|
153
|
+
label: raw.label,
|
|
154
|
+
depth: raw.depth,
|
|
155
|
+
amount: asNumberString(raw.amount),
|
|
156
|
+
bucketDepth: raw.bucketDepth,
|
|
157
|
+
blockNumber: raw.blockNumber,
|
|
158
|
+
immutableFlag: raw.immutableFlag,
|
|
159
|
+
usage,
|
|
160
|
+
usageText: `${Math.round(usage * 100)}%`,
|
|
161
|
+
size: Size.fromBytes(effectiveBytes),
|
|
162
|
+
remainingSize: Size.fromBytes(Math.ceil(effectiveBytes * (1 - usage))),
|
|
163
|
+
theoreticalSize: Size.fromBytes(getStampTheoreticalBytes(raw.depth)),
|
|
164
|
+
duration,
|
|
165
|
+
calculateSize(encryption, redundancyLevel) {
|
|
166
|
+
const effectiveBytes = getStampEffectiveBytes(raw.depth, encryption, redundancyLevel);
|
|
167
|
+
return Size.fromBytes(effectiveBytes);
|
|
168
|
+
},
|
|
169
|
+
calculateRemainingSize(encryption, redundancyLevel) {
|
|
170
|
+
const effectiveBytes = getStampEffectiveBytes(raw.depth, encryption, redundancyLevel);
|
|
171
|
+
return Size.fromBytes(Math.ceil(effectiveBytes * (1 - this.usage)));
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
export function unmapPostageBatch(batch) {
|
|
176
|
+
return {
|
|
177
|
+
batchID: batch.batchID.toHex(),
|
|
178
|
+
utilization: batch.utilization,
|
|
179
|
+
usable: batch.usable,
|
|
180
|
+
label: batch.label,
|
|
181
|
+
depth: batch.depth,
|
|
182
|
+
amount: batch.amount,
|
|
183
|
+
bucketDepth: batch.bucketDepth,
|
|
184
|
+
blockNumber: batch.blockNumber,
|
|
185
|
+
immutableFlag: batch.immutableFlag,
|
|
186
|
+
batchTTL: batch.duration.toSeconds()
|
|
187
|
+
};
|
|
140
188
|
}
|
package/dist/mjs/utils/type.js
CHANGED
|
@@ -34,7 +34,8 @@ export function prepareBeeRequestOptions(value) {
|
|
|
34
34
|
httpsAgent: object.httpsAgent,
|
|
35
35
|
endlesslyRetry: Types.asOptional(x => Types.asBoolean(x, {
|
|
36
36
|
name: 'endlesslyRetry'
|
|
37
|
-
}), object.endlesslyRetry)
|
|
37
|
+
}), object.endlesslyRetry),
|
|
38
|
+
signal: object.signal
|
|
38
39
|
};
|
|
39
40
|
}
|
|
40
41
|
export function prepareDownloadOptions(value) {
|
|
@@ -6,8 +6,11 @@ export function normalizeBatchTTL(batchTTL) {
|
|
|
6
6
|
if (batchTTL < 1) {
|
|
7
7
|
return 1;
|
|
8
8
|
}
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
// Cap `batchTTL` (represents seconds) to 100 years.
|
|
10
|
+
// We can assume `storagePrice` is invalid (e.g. 1).
|
|
11
|
+
// This is needed to prevent Date objects breaking.
|
|
12
|
+
if (batchTTL > 3155695200) {
|
|
13
|
+
return 3155695200;
|
|
11
14
|
}
|
|
12
15
|
return batchTTL;
|
|
13
16
|
}
|
package/dist/types/bee.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import { Readable } from 'stream';
|
|
3
2
|
import { Chunk } from './chunk/cac';
|
|
3
|
+
import { SingleOwnerChunk } from './chunk/soc';
|
|
4
4
|
import { FeedPayloadResult } from './modules/feed';
|
|
5
5
|
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
6
|
import { AllTagsOptions, Collection, PostageBatchOptions, TransactionOptions, UploadResult } from './types';
|
|
@@ -8,7 +8,7 @@ import { Bytes } from './utils/bytes';
|
|
|
8
8
|
import { Duration } from './utils/duration';
|
|
9
9
|
import { Size } from './utils/size';
|
|
10
10
|
import { BZZ, DAI } from './utils/tokens';
|
|
11
|
-
import { BatchId, EthAddress, FeedIndex, Identifier, PeerAddress, PrivateKey, PublicKey, Reference, Topic, TransactionId } from './utils/typed-bytes';
|
|
11
|
+
import { BatchId, EthAddress, FeedIndex, Identifier, PeerAddress, PrivateKey, PublicKey, Reference, Span, Topic, TransactionId } from './utils/typed-bytes';
|
|
12
12
|
import { UploadProgress } from './utils/upload-progress';
|
|
13
13
|
/**
|
|
14
14
|
* The main component that abstracts operations available on the Bee API.
|
|
@@ -123,7 +123,7 @@ export declare class Bee {
|
|
|
123
123
|
* Chunks uploaded with this method should be retrieved with the {@link downloadChunk} method.
|
|
124
124
|
*
|
|
125
125
|
* @param stamp Postage Batch ID or an Envelope created with the {@link createEnvelope} method.
|
|
126
|
-
* @param data Raw chunk to be uploaded
|
|
126
|
+
* @param data Raw chunk to be uploaded (Content Addressed Chunk or Single Owner Chunk)
|
|
127
127
|
* @param options Additional options like tag, encryption, pinning, content-type and request options
|
|
128
128
|
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
129
129
|
*
|
|
@@ -131,7 +131,7 @@ export declare class Bee {
|
|
|
131
131
|
* @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/develop/access-the-swarm/upload-and-download)
|
|
132
132
|
* @see [Bee API reference - `POST /chunks`](https://docs.ethswarm.org/api/#tag/Chunk/paths/~1chunks/post)
|
|
133
133
|
*/
|
|
134
|
-
uploadChunk(stamp: EnvelopeWithBatchId | BatchId | Uint8Array | string, data: Uint8Array | Chunk, options?: UploadOptions, requestOptions?: BeeRequestOptions): Promise<UploadResult>;
|
|
134
|
+
uploadChunk(stamp: EnvelopeWithBatchId | BatchId | Uint8Array | string, data: Uint8Array | Chunk | SingleOwnerChunk, options?: UploadOptions, requestOptions?: BeeRequestOptions): Promise<UploadResult>;
|
|
135
135
|
/**
|
|
136
136
|
* Downloads a chunk as a `Uint8Array`.
|
|
137
137
|
*
|
|
@@ -608,6 +608,57 @@ export declare class Bee {
|
|
|
608
608
|
*/
|
|
609
609
|
makeFeedWriter(topic: Topic | Uint8Array | string, signer?: PrivateKey | Uint8Array | string, requestOptions?: BeeRequestOptions): FeedWriter;
|
|
610
610
|
fetchLatestFeedUpdate(topic: Topic | Uint8Array | string, owner: EthAddress | Uint8Array | string, requestOptions?: BeeRequestOptions): Promise<FeedPayloadResult>;
|
|
611
|
+
/**
|
|
612
|
+
* Creates a Content Addressed Chunk.
|
|
613
|
+
*
|
|
614
|
+
* To be uploaded with the {@link uploadChunk} method.
|
|
615
|
+
*
|
|
616
|
+
* Payload size must be between 1 and 4096 bytes.
|
|
617
|
+
*
|
|
618
|
+
* @param rawPayload Data to be stored in the chunk. If the data is a string, it will be converted to UTF-8 bytes.
|
|
619
|
+
* @param span Optional span for the chunk. If not provided, it will be set to the length of the payload.
|
|
620
|
+
*/
|
|
621
|
+
makeContentAddressedChunk(rawPayload: Bytes | Uint8Array | string, span?: Span | bigint): Chunk;
|
|
622
|
+
/**
|
|
623
|
+
* Attempts to unmarshal arbitrary data into a Content Addressed Chunk.
|
|
624
|
+
* Throws an error if the data is not a valid CAC.
|
|
625
|
+
*
|
|
626
|
+
* @param data The chunk data (`span` and `payload`)
|
|
627
|
+
*/
|
|
628
|
+
unmarshalContentAddressedChunk(data: Bytes | Uint8Array): Chunk;
|
|
629
|
+
/**
|
|
630
|
+
* Creates a Single Owner Chunk.
|
|
631
|
+
*
|
|
632
|
+
* To be uploaded with the {@link uploadChunk} method.
|
|
633
|
+
*
|
|
634
|
+
* Identical to chaining `makeContentAddressedChunk` and `toSingleOwnerChunk`.
|
|
635
|
+
*
|
|
636
|
+
* Payload size must be between 1 and 4096 bytes.
|
|
637
|
+
*
|
|
638
|
+
* @param address Address of the Content Addressed Chunk
|
|
639
|
+
* @param span Span of the Content Addressed Chunk
|
|
640
|
+
* @param payload Payload of the Content Addressed Chunk
|
|
641
|
+
* @param identifier The identifier of the chunk
|
|
642
|
+
* @param signer The signer interface for signing the chunk
|
|
643
|
+
*/
|
|
644
|
+
makeSingleOwnerChunk(address: Reference, span: Span, payload: Bytes, identifier: Identifier | Uint8Array | string, signer: PrivateKey | Uint8Array | string): SingleOwnerChunk;
|
|
645
|
+
/**
|
|
646
|
+
* Calculates the address of a Single Owner Chunk based on its identifier and owner address.
|
|
647
|
+
*
|
|
648
|
+
* @param identifier
|
|
649
|
+
* @param address
|
|
650
|
+
*/
|
|
651
|
+
calculateSingleOwnerChunkAddress(identifier: Identifier, address: EthAddress): Reference;
|
|
652
|
+
/**
|
|
653
|
+
* Attempts to unmarshal arbitrary data into a Single Owner Chunk.
|
|
654
|
+
* Throws an error if the data is not a valid SOC.
|
|
655
|
+
*
|
|
656
|
+
* @param data The chunk data
|
|
657
|
+
* @param address The address of the single owner chunk
|
|
658
|
+
*
|
|
659
|
+
* @returns a single owner chunk or throws error
|
|
660
|
+
*/
|
|
661
|
+
unmarshalSingleOwnerChunk(data: Bytes | Uint8Array, address: Reference | Uint8Array | string): SingleOwnerChunk;
|
|
611
662
|
/**
|
|
612
663
|
* Returns an object for reading single owner chunks
|
|
613
664
|
*
|
|
@@ -1103,6 +1154,18 @@ export declare class Bee {
|
|
|
1103
1154
|
* @returns
|
|
1104
1155
|
*/
|
|
1105
1156
|
getDurationExtensionCost(postageBatchId: BatchId | Uint8Array | string, duration: Duration, requestOptions?: BeeRequestOptions): Promise<BZZ>;
|
|
1157
|
+
/**
|
|
1158
|
+
* Calculates the `amount` and expected duration extension for topping up a postage batch with a given BZZ value.
|
|
1159
|
+
*
|
|
1160
|
+
* @param postageBatchId
|
|
1161
|
+
* @param bzz The amount of BZZ to spend on the top-up.
|
|
1162
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
1163
|
+
* @returns An object with `amount` (to pass to {@link topUpBatch}) and `duration` (the expected TTL extension).
|
|
1164
|
+
*/
|
|
1165
|
+
calculateTopUpForBzz(postageBatchId: BatchId | Uint8Array | string, bzz: BZZ, requestOptions?: BeeRequestOptions): Promise<{
|
|
1166
|
+
amount: bigint;
|
|
1167
|
+
duration: Duration;
|
|
1168
|
+
}>;
|
|
1106
1169
|
/**
|
|
1107
1170
|
* Increases the duration of a postage batch by increasing its amount.
|
|
1108
1171
|
*
|
|
@@ -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';
|
|
@@ -13,6 +15,7 @@ export * as Utils from './utils/expose';
|
|
|
13
15
|
export { Size } from './utils/size';
|
|
14
16
|
export * from './utils/tokens';
|
|
15
17
|
export * from './utils/typed-bytes';
|
|
18
|
+
export type { UploadProgress } from './utils/upload-progress';
|
|
16
19
|
export { Bee, BeeDev, Stamper };
|
|
17
20
|
declare global {
|
|
18
21
|
interface Window {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BeeRequestOptions } from '../../index';
|
|
2
2
|
import type { DebugStatus, Health, NodeInfo, Readiness } from '../../types/debug';
|
|
3
3
|
import { BeeVersions } from '../../types/debug';
|
|
4
|
-
export declare const SUPPORTED_BEE_VERSION_EXACT = "2.
|
|
4
|
+
export declare const SUPPORTED_BEE_VERSION_EXACT = "2.7.0-6ddf9b45";
|
|
5
5
|
export declare const SUPPORTED_BEE_VERSION: string;
|
|
6
6
|
export declare const SUPPORTED_API_VERSION = "7.3.0";
|
|
7
7
|
export declare function getDebugStatus(requestOptions: BeeRequestOptions): Promise<DebugStatus>;
|
|
@@ -2,6 +2,6 @@ import { BatchId, Topic } from './typed-bytes';
|
|
|
2
2
|
export declare const SWARM_GATEWAY_URL = "https://api.gateway.ethswarm.org";
|
|
3
3
|
export declare const NULL_STAMP: BatchId;
|
|
4
4
|
export declare const NULL_TOPIC: Topic;
|
|
5
|
-
export declare const NULL_ADDRESS: Uint8Array
|
|
6
|
-
export declare const NULL_IDENTIFIER: Uint8Array
|
|
7
|
-
export declare const NULL_OWNER: Uint8Array
|
|
5
|
+
export declare const NULL_ADDRESS: Uint8Array<ArrayBuffer>;
|
|
6
|
+
export declare const NULL_IDENTIFIER: Uint8Array<ArrayBuffer>;
|
|
7
|
+
export declare const NULL_OWNER: Uint8Array<ArrayBuffer>;
|
|
@@ -8,8 +8,8 @@ export declare class BeeArgumentError extends BeeError {
|
|
|
8
8
|
export declare class BeeResponseError extends BeeError {
|
|
9
9
|
method: string;
|
|
10
10
|
url: string;
|
|
11
|
-
responseBody?: unknown;
|
|
11
|
+
responseBody?: unknown | undefined;
|
|
12
12
|
status?: number | undefined;
|
|
13
13
|
statusText?: string | undefined;
|
|
14
|
-
constructor(method: string, url: string, message: string, responseBody?: unknown, status?: number | undefined, statusText?: string | undefined);
|
|
14
|
+
constructor(method: string, url: string, message: string, responseBody?: unknown | undefined, status?: number | undefined, statusText?: string | undefined);
|
|
15
15
|
}
|
|
@@ -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 { convertEnvelopeToMarshaledStamp, 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;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { BeeRequestOptions, Collection, CollectionUploadOptions } from '..';
|
|
2
2
|
import { BatchId } from './typed-bytes';
|
|
3
|
-
export declare function uploadTar(requestOptions: BeeRequestOptions, collection: Collection, postageBatchId: BatchId, options?: CollectionUploadOptions): Promise<import("axios").AxiosResponse<unknown, any>>;
|
|
3
|
+
export declare function uploadTar(requestOptions: BeeRequestOptions, collection: Collection, postageBatchId: BatchId, options?: CollectionUploadOptions): Promise<import("axios").AxiosResponse<unknown, any, {}>>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { BeeRequestOptions, Collection, CollectionUploadOptions } from '..';
|
|
2
2
|
import { BatchId } from './typed-bytes';
|
|
3
|
-
export declare function uploadTar(requestOptions: BeeRequestOptions, collection: Collection, postageBatchId: BatchId, options?: CollectionUploadOptions): Promise<import("axios").AxiosResponse<unknown, any>>;
|
|
3
|
+
export declare function uploadTar(requestOptions: BeeRequestOptions, collection: Collection, postageBatchId: BatchId, options?: CollectionUploadOptions): Promise<import("axios").AxiosResponse<unknown, any, {}>>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare class TarStream {
|
|
2
2
|
pieces: Uint8Array[];
|
|
3
3
|
currentFileSize: number;
|
|
4
|
-
get output(): Uint8Array
|
|
4
|
+
get output(): Uint8Array<ArrayBufferLike>;
|
|
5
5
|
beginFile(path: string, size: number): void;
|
|
6
6
|
appendFile(data: Uint8Array): Promise<void>;
|
|
7
7
|
endFile(): Promise<void>;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import * as stream from 'stream';
|
|
3
2
|
import { AllTagsOptions, BeeRequestOptions, CollectionUploadOptions, DownloadOptions, FileUploadOptions, GsocMessageHandler, NumberString, PostageBatchOptions, PssMessageHandler, RedundantUploadOptions, Tag, TransactionOptions, UploadOptions } from '../types';
|
|
4
3
|
export declare function isReadable(value: unknown): value is stream.Readable;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@upcoming/bee-js",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "12.0.0",
|
|
4
4
|
"description": "Javascript client for Bee",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bee",
|
|
@@ -50,19 +50,19 @@
|
|
|
50
50
|
"dist"
|
|
51
51
|
],
|
|
52
52
|
"scripts": {
|
|
53
|
-
"prepublishOnly": "
|
|
53
|
+
"prepublishOnly": "NODE_ENV=production npm run build",
|
|
54
54
|
"build": "rimraf dist && npm run build:node && npm run build:types && npm run build:browser",
|
|
55
55
|
"build:node": "tsc -p tsconfig.json && tsc -p tsconfig-mjs.json && ./build-fixup && babel --plugins \"babel-plugin-add-import-extension\" --out-dir dist/mjs/ dist/mjs/",
|
|
56
56
|
"build:types": "tsc --emitDeclarationOnly --declaration --outDir dist/types",
|
|
57
57
|
"build:browser": "webpack --progress",
|
|
58
|
-
"test": "
|
|
58
|
+
"test": "TS_NODE_PROJECT=tsconfig.test.json jest --runInBand --verbose --forceExit",
|
|
59
59
|
"check": "tsc --project tsconfig.test.json",
|
|
60
60
|
"lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\" && prettier --check \"src/**/*.ts\" \"test/**/*.ts\"",
|
|
61
61
|
"depcheck": "depcheck ."
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"axios": "^
|
|
65
|
-
"cafe-utility": "^
|
|
64
|
+
"axios": "^1.15.1",
|
|
65
|
+
"cafe-utility": "^33.6.1",
|
|
66
66
|
"debug": "^4.4.1",
|
|
67
67
|
"isomorphic-ws": "^4.0.1",
|
|
68
68
|
"semver": "^7.3.5",
|
|
@@ -77,10 +77,8 @@
|
|
|
77
77
|
"@babel/preset-typescript": "^7.18.6",
|
|
78
78
|
"@commitlint/cli": "^17.0.2",
|
|
79
79
|
"@commitlint/config-conventional": "^17.4.2",
|
|
80
|
-
"@jest/types": "^29.6.3",
|
|
81
|
-
"@naholyr/cross-env": "^1.0.0",
|
|
82
80
|
"@types/debug": "^4.1.12",
|
|
83
|
-
"@types/jest": "^
|
|
81
|
+
"@types/jest": "^30.0.0",
|
|
84
82
|
"@types/node": "^18.11.11",
|
|
85
83
|
"@types/semver": "^7.3.9",
|
|
86
84
|
"@types/ws": "^8.5.3",
|
|
@@ -88,20 +86,19 @@
|
|
|
88
86
|
"@typescript-eslint/parser": "^5.46.0",
|
|
89
87
|
"babel-loader": "^9.1.0",
|
|
90
88
|
"babel-plugin-add-import-extension": "^1.6.0",
|
|
91
|
-
"cross-env": "^7.0.3",
|
|
92
89
|
"depcheck": "^1.4.7",
|
|
93
90
|
"eslint": "^8.13.0",
|
|
94
91
|
"eslint-config-prettier": "^8.5.0",
|
|
95
92
|
"eslint-plugin-prettier": "^4.0.0",
|
|
96
93
|
"eslint-plugin-unused-imports": "^2.0.0",
|
|
97
94
|
"husky": "^8.0.1",
|
|
98
|
-
"jest": "^
|
|
95
|
+
"jest": "^30.2.0",
|
|
99
96
|
"prettier": "^2.6.2",
|
|
100
97
|
"rimraf": "^3.0.2",
|
|
101
98
|
"terser-webpack-plugin": "^5.3.1",
|
|
102
|
-
"ts-jest": "^29.
|
|
103
|
-
"ts-node": "^10.9.
|
|
104
|
-
"typescript": "^
|
|
99
|
+
"ts-jest": "^29.4.6",
|
|
100
|
+
"ts-node": "^10.9.2",
|
|
101
|
+
"typescript": "^5.9.3",
|
|
105
102
|
"webpack": "^5.75.0",
|
|
106
103
|
"webpack-cli": "^5.0.1"
|
|
107
104
|
}
|