@ethersphere/bee-js 8.1.0 → 8.2.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.
Files changed (37) hide show
  1. package/dist/cjs/bee.js +19 -6
  2. package/dist/cjs/chunk/soc.js +4 -6
  3. package/dist/cjs/modules/bytes.js +18 -1
  4. package/dist/cjs/modules/chunk.js +4 -4
  5. package/dist/cjs/modules/envelope.js +23 -0
  6. package/dist/cjs/modules/feed.js +2 -2
  7. package/dist/cjs/modules/soc.js +2 -2
  8. package/dist/cjs/utils/expose.js +3 -1
  9. package/dist/cjs/utils/headers.js +11 -6
  10. package/dist/cjs/utils/stamps.js +22 -1
  11. package/dist/cjs/utils/type.js +1 -5
  12. package/dist/index.browser.min.js +1 -1
  13. package/dist/index.browser.min.js.map +1 -1
  14. package/dist/mjs/bee.js +19 -6
  15. package/dist/mjs/chunk/soc.js +4 -6
  16. package/dist/mjs/modules/bytes.js +16 -0
  17. package/dist/mjs/modules/chunk.js +4 -4
  18. package/dist/mjs/modules/envelope.js +33 -0
  19. package/dist/mjs/modules/feed.js +2 -2
  20. package/dist/mjs/modules/soc.js +2 -2
  21. package/dist/mjs/utils/expose.js +3 -1
  22. package/dist/mjs/utils/headers.js +10 -6
  23. package/dist/mjs/utils/stamps.js +19 -0
  24. package/dist/mjs/utils/type.js +0 -3
  25. package/dist/types/bee.d.ts +10 -3
  26. package/dist/types/chunk/soc.d.ts +2 -2
  27. package/dist/types/modules/bytes.d.ts +8 -1
  28. package/dist/types/modules/chunk.d.ts +3 -3
  29. package/dist/types/modules/envelope.d.ts +2 -0
  30. package/dist/types/modules/feed.d.ts +1 -1
  31. package/dist/types/modules/soc.d.ts +1 -1
  32. package/dist/types/types/index.d.ts +10 -1
  33. package/dist/types/utils/expose.d.ts +6 -3
  34. package/dist/types/utils/headers.d.ts +1 -1
  35. package/dist/types/utils/stamps.d.ts +3 -1
  36. package/dist/types/utils/type.d.ts +0 -1
  37. package/package.json +2 -2
package/dist/mjs/bee.js CHANGED
@@ -20,6 +20,7 @@ import * as states from "./modules/debug/states.js";
20
20
  import * as debugStatus from "./modules/debug/status.js";
21
21
  import * as debugTag from "./modules/debug/tag.js";
22
22
  import * as transactions from "./modules/debug/transactions.js";
23
+ import { postEnvelope } from "./modules/envelope.js";
23
24
  import { createFeedManifest } from "./modules/feed.js";
24
25
  import * as grantee from "./modules/grantee.js";
25
26
  import * as pinning from "./modules/pinning.js";
@@ -84,6 +85,16 @@ export class Bee {
84
85
  }
85
86
  return bytes.upload(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, options);
86
87
  }
88
+ /**
89
+ * Requests content length for a `/bytes` reference
90
+ *
91
+ * @see [Bee API reference - `HEAD /bytes/`](https://docs.ethswarm.org/api/#tag/Bytes/paths/~1bytes~1%7Breference%7D/head)
92
+ */
93
+ async probeData(reference, options) {
94
+ assertRequestOptions(options);
95
+ assertReferenceOrEns(reference);
96
+ return bytes.head(this.getRequestOptionsForCall(options), reference);
97
+ }
87
98
  /**
88
99
  * Download data as a byte array
89
100
  *
@@ -125,8 +136,7 @@ export class Bee {
125
136
  * @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/develop/access-the-swarm/upload-and-download)
126
137
  * @see [Bee API reference - `POST /chunks`](https://docs.ethswarm.org/api/#tag/Chunk/paths/~1chunks/post)
127
138
  */
128
- async uploadChunk(postageBatchId, data, options, requestOptions) {
129
- assertBatchId(postageBatchId);
139
+ async uploadChunk(stamp, data, options, requestOptions) {
130
140
  assertRequestOptions(requestOptions);
131
141
  if (!(data instanceof Uint8Array)) {
132
142
  throw new TypeError('Data has to be Uint8Array instance!');
@@ -140,7 +150,7 @@ export class Bee {
140
150
  if (options) {
141
151
  assertUploadOptions(options);
142
152
  }
143
- return chunk.upload(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, options);
153
+ return chunk.upload(this.getRequestOptionsForCall(requestOptions), data, stamp, options);
144
154
  }
145
155
  /**
146
156
  * Download chunk as a byte array
@@ -698,13 +708,12 @@ export class Bee {
698
708
  * @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/develop/tools-and-features/feeds)
699
709
  * @see [Bee API reference - `POST /feeds`](https://docs.ethswarm.org/api/#tag/Feed/paths/~1feeds~1{owner}~1{topic}/post)
700
710
  */
701
- async createFeedManifest(postageBatchId, type, topic, owner, options) {
711
+ async createFeedManifest(stamp, type, topic, owner, options) {
702
712
  assertRequestOptions(options);
703
713
  assertFeedType(type);
704
- assertBatchId(postageBatchId);
705
714
  const canonicalTopic = makeTopic(topic);
706
715
  const canonicalOwner = makeHexEthAddress(owner);
707
- const reference = await createFeedManifest(this.getRequestOptionsForCall(options), canonicalOwner, canonicalTopic, postageBatchId);
716
+ const reference = await createFeedManifest(this.getRequestOptionsForCall(options), canonicalOwner, canonicalTopic, stamp);
708
717
  return addCidConversionFunction({
709
718
  reference
710
719
  }, ReferenceType.FEED);
@@ -853,6 +862,10 @@ export class Bee {
853
862
  upload: uploadSingleOwnerChunkData.bind(null, this.getRequestOptionsForCall(options), canonicalSigner)
854
863
  };
855
864
  }
865
+ async createEnvelope(postageBatchId, reference, options) {
866
+ assertRequestOptions(options);
867
+ return postEnvelope(this.getRequestOptionsForCall(options), postageBatchId, reference);
868
+ }
856
869
  /**
857
870
  * Ping the Bee node to see if there is a live Bee node on the given URL.
858
871
  *
@@ -5,7 +5,6 @@ import { bytesAtOffset, bytesEqual, flexBytesAtOffset } from "../utils/bytes.js"
5
5
  import { BeeError } from "../utils/error.js";
6
6
  import { keccak256Hash } from "../utils/hash.js";
7
7
  import { bytesToHex } from "../utils/hex.js";
8
- import { assertAddress } from "../utils/type.js";
9
8
  import { bmtHash } from "./bmt.js";
10
9
  import { MAX_PAYLOAD_SIZE, MIN_PAYLOAD_SIZE, assertValidChunkData, makeContentAddressedChunk } from "./cac.js";
11
10
  import { recoverAddress, sign } from "./signer.js";
@@ -90,12 +89,12 @@ export async function makeSingleOwnerChunk(chunk, identifier, signer) {
90
89
  * @param postageBatchId Postage BatchId that will be assigned to uploaded data
91
90
  * @param options Upload options
92
91
  */
93
- export async function uploadSingleOwnerChunk(requestOptions, chunk, postageBatchId, options) {
92
+ export async function uploadSingleOwnerChunk(requestOptions, chunk, stamp, options) {
94
93
  const owner = bytesToHex(chunk.owner());
95
94
  const identifier = bytesToHex(chunk.identifier());
96
95
  const signature = bytesToHex(chunk.signature());
97
96
  const data = Binary.concatBytes(chunk.span(), chunk.payload());
98
- return socAPI.upload(requestOptions, owner, identifier, signature, data, postageBatchId, options);
97
+ return socAPI.upload(requestOptions, owner, identifier, signature, data, stamp, options);
99
98
  }
100
99
  /**
101
100
  * Helper function to create and upload SOC.
@@ -107,11 +106,10 @@ export async function uploadSingleOwnerChunk(requestOptions, chunk, postageBatch
107
106
  * @param data The chunk data
108
107
  * @param options
109
108
  */
110
- export async function uploadSingleOwnerChunkData(requestOptions, signer, postageBatchId, identifier, data, options) {
111
- assertAddress(postageBatchId);
109
+ export async function uploadSingleOwnerChunkData(requestOptions, signer, stamp, identifier, data, options) {
112
110
  const cac = makeContentAddressedChunk(data);
113
111
  const soc = await makeSingleOwnerChunk(cac, identifier, signer);
114
- return uploadSingleOwnerChunk(requestOptions, soc, postageBatchId, options);
112
+ return uploadSingleOwnerChunk(requestOptions, soc, stamp, options);
115
113
  }
116
114
  /**
117
115
  * Helper function to download SOC.
@@ -28,6 +28,22 @@ export async function upload(requestOptions, data, postageBatchId, options) {
28
28
  historyAddress: response.headers['swarm-act-history-address'] || ''
29
29
  };
30
30
  }
31
+ /**
32
+ * Requests content length for a reference
33
+ *
34
+ * @param requestOptions Options for making requests
35
+ * @param hash Bee content reference
36
+ */
37
+ export async function head(requestOptions, hash) {
38
+ const response = await http(requestOptions, {
39
+ url: `${endpoint}/${hash}`,
40
+ method: 'head',
41
+ responseType: 'json'
42
+ });
43
+ return {
44
+ contentLength: parseInt(response.headers['content-length'])
45
+ };
46
+ }
31
47
  /**
32
48
  * Download data as a byte array
33
49
  *
@@ -11,18 +11,18 @@ const endpoint = 'chunks';
11
11
  * Upload expects the chuck data to be set accordingly.
12
12
  *
13
13
  * @param requestOptions Options for making requests
14
- * @param data Chunk data to be uploaded
15
- * @param postageBatchId Postage BatchId that will be assigned to uploaded data
14
+ * @param data Chunk data to be uploaded
15
+ * @param stamp BatchId or marshaled stamp to be used for the upload
16
16
  * @param options Additional options like tag, encryption, pinning
17
17
  */
18
- export async function upload(requestOptions, data, postageBatchId, options) {
18
+ export async function upload(requestOptions, data, stamp, options) {
19
19
  const response = await http(requestOptions, {
20
20
  method: 'post',
21
21
  url: `${endpoint}`,
22
22
  data,
23
23
  headers: {
24
24
  'content-type': 'application/octet-stream',
25
- ...extractUploadHeaders(postageBatchId, options)
25
+ ...extractUploadHeaders(stamp, options)
26
26
  },
27
27
  responseType: 'json'
28
28
  });
@@ -0,0 +1,33 @@
1
+ import { Binary, Types } from 'cafe-utility';
2
+ import { http } from "../utils/http.js";
3
+ const ENVELOPE_ENDPOINT = 'envelope';
4
+ export async function postEnvelope(requestOptions, postageBatchId, reference) {
5
+ const {
6
+ data
7
+ } = await http(requestOptions, {
8
+ method: 'post',
9
+ responseType: 'json',
10
+ url: `${ENVELOPE_ENDPOINT}/${reference}`,
11
+ headers: {
12
+ 'swarm-postage-batch-id': postageBatchId
13
+ }
14
+ });
15
+ return {
16
+ issuer: Binary.hexToUint8Array(Types.asHexString(data.issuer, {
17
+ name: 'issuer',
18
+ byteLength: 20
19
+ })),
20
+ index: Binary.hexToUint8Array(Types.asHexString(data.index, {
21
+ name: 'index',
22
+ byteLength: 8
23
+ })),
24
+ timestamp: Binary.hexToUint8Array(Types.asHexString(data.timestamp, {
25
+ name: 'timestamp',
26
+ byteLength: 8
27
+ })),
28
+ signature: Binary.hexToUint8Array(Types.asHexString(data.signature, {
29
+ name: 'signature',
30
+ byteLength: 65
31
+ }))
32
+ };
33
+ }
@@ -11,12 +11,12 @@ const feedEndpoint = 'feeds';
11
11
  * @param postageBatchId Postage BatchId to be used to create the Feed Manifest
12
12
  * @param options Additional options, like type (default: 'sequence')
13
13
  */
14
- export async function createFeedManifest(requestOptions, owner, topic, postageBatchId) {
14
+ export async function createFeedManifest(requestOptions, owner, topic, stamp) {
15
15
  const response = await http(requestOptions, {
16
16
  method: 'post',
17
17
  responseType: 'json',
18
18
  url: `${feedEndpoint}/${owner}/${topic}`,
19
- headers: extractUploadHeaders(postageBatchId)
19
+ headers: extractUploadHeaders(stamp)
20
20
  });
21
21
  return response.data.reference;
22
22
  }
@@ -13,14 +13,14 @@ const socEndpoint = 'soc';
13
13
  * @param postageBatchId Postage BatchId that will be assigned to uploaded data
14
14
  * @param options Additional options like tag, encryption, pinning
15
15
  */
16
- export async function upload(requestOptions, owner, identifier, signature, data, postageBatchId, options) {
16
+ export async function upload(requestOptions, owner, identifier, signature, data, stamp, options) {
17
17
  const response = await http(requestOptions, {
18
18
  method: 'post',
19
19
  url: `${socEndpoint}/${owner}/${identifier}`,
20
20
  data,
21
21
  headers: {
22
22
  'content-type': 'application/octet-stream',
23
- ...extractUploadHeaders(postageBatchId, options)
23
+ ...extractUploadHeaders(stamp, options)
24
24
  },
25
25
  responseType: 'json',
26
26
  params: {
@@ -6,4 +6,6 @@ export { capitalizeAddressERC55, ethToSwarmAddress, fromLittleEndian, isHexEthAd
6
6
  export { keccak256Hash } from "./hash.js";
7
7
  export { makeMaxTarget } from "./pss.js";
8
8
  export { getAmountForTtl, getDepthForCapacity, getStampCostInBzz, getStampCostInPlur, getStampEffectiveBytes, getStampMaximumCapacityBytes, getStampTtlSeconds, getStampUsage } from "./stamps.js";
9
- export { approximateOverheadForRedundancyLevel, getRedundancyStat, getRedundancyStats } from "./redundancy.js";
9
+ export { approximateOverheadForRedundancyLevel, getRedundancyStat, getRedundancyStats } from "./redundancy.js";
10
+ export const NULL_STAMP = '0000000000000000000000000000000000000000000000000000000000000000';
11
+ export const NULL_TOPIC = '0000000000000000000000000000000000000000000000000000000000000000';
@@ -1,3 +1,4 @@
1
+ import { Binary } from 'cafe-utility';
1
2
  import { BeeError } from "./error.js";
2
3
  /**
3
4
  * Read the filename from the content-disposition header
@@ -35,13 +36,16 @@ export function readFileHeaders(headers) {
35
36
  contentType
36
37
  };
37
38
  }
38
- export function extractUploadHeaders(postageBatchId, options) {
39
- if (!postageBatchId) {
40
- throw new BeeError('Postage BatchID has to be specified!');
39
+ export function extractUploadHeaders(stamp, options) {
40
+ if (!stamp) {
41
+ throw new BeeError('Stamp has to be specified!');
42
+ }
43
+ const headers = {};
44
+ if (stamp instanceof Uint8Array) {
45
+ headers['swarm-postage-stamp'] = Binary.uint8ArrayToHex(stamp);
46
+ } else {
47
+ headers['swarm-postage-batch-id'] = stamp;
41
48
  }
42
- const headers = {
43
- 'swarm-postage-batch-id': postageBatchId
44
- };
45
49
  if (options?.act) {
46
50
  headers['swarm-act'] = String(options.act);
47
51
  }
@@ -1,3 +1,4 @@
1
+ import { Binary } from 'cafe-utility';
1
2
  /**
2
3
  * Utility function that calculates usage of postage batch based on its utilization, depth and bucket depth.
3
4
  *
@@ -100,4 +101,22 @@ export function getAmountForTtl(days) {
100
101
  */
101
102
  export function getDepthForCapacity(gigabytes) {
102
103
  return gigabytes <= 1 ? 18 : Math.ceil(Math.log2(Math.ceil(gigabytes)) + 18);
104
+ }
105
+ export function convertEnvelopeToMarshaledStamp(batchID, envelope) {
106
+ return marshalStamp(envelope.signature, Binary.hexToUint8Array(batchID), envelope.timestamp, envelope.index);
107
+ }
108
+ export function marshalStamp(signature, batchID, timestamp, index) {
109
+ if (signature.length !== 65) {
110
+ throw Error('invalid signature length');
111
+ }
112
+ if (batchID.length !== 32) {
113
+ throw Error('invalid batch ID length');
114
+ }
115
+ if (timestamp.length !== 8) {
116
+ throw Error('invalid timestamp length');
117
+ }
118
+ if (index.length !== 8) {
119
+ throw Error('invalid index length');
120
+ }
121
+ return Binary.concatBytes(batchID, index, timestamp, signature);
103
122
  }
@@ -7,9 +7,6 @@ import { assertHexString, assertPrefixedHexString, isHexString } from "./hex.js"
7
7
  export function isReadable(obj) {
8
8
  return typeof Readable !== 'undefined' && obj instanceof Readable;
9
9
  }
10
- export function isUint8Array(obj) {
11
- return obj instanceof Uint8Array;
12
- }
13
10
  export function isInteger(value) {
14
11
  return typeof value === 'string' && /^-?(0|[1-9][0-9]*)$/g.test(value) || typeof value === 'number' && value > Number.MIN_SAFE_INTEGER && value < Number.MAX_SAFE_INTEGER && Number.isInteger(value);
15
12
  }
@@ -2,7 +2,7 @@
2
2
  import { Readable } from 'stream';
3
3
  import { Index, IndexBytes } from './feed';
4
4
  import { FeedType } from './feed/type';
5
- import type { Address, AddressPrefix, AllSettlements, AnyJson, BalanceResponse, BatchId, BeeOptions, BeeRequestOptions, BeeVersions, ChainState, ChequebookAddressResponse, ChequebookBalanceResponse, CollectionUploadOptions, Data, DebugStatus, ExtendedTag, FeedReader, FeedWriter, FileData, FileUploadOptions, GetGranteesResult, GranteesResult, Health, JsonFeedOptions, LastCashoutActionResponse, LastChequesForPeerResponse, LastChequesResponse, NodeAddresses, NodeInfo, NumberString, Peer, PeerBalance, Pin, PingResponse, PostageBatch, PostageBatchBuckets, PssMessageHandler, PssSubscription, PublicKey, RedistributionState, Reference, RemovePeerResponse, ReserveState, SOCReader, SOCWriter, Settlements, Signer, Tag, Topic, Topology, TransactionHash, TransactionInfo, UploadOptions, UploadRedundancyOptions, UploadResultWithCid, WalletBalance } from './types';
5
+ import type { Address, AddressPrefix, AllSettlements, AnyJson, BalanceResponse, BatchId, BeeOptions, BeeRequestOptions, BeeVersions, ChainState, ChequebookAddressResponse, ChequebookBalanceResponse, CollectionUploadOptions, Data, DebugStatus, Envelope, ExtendedTag, FeedReader, FeedWriter, FileData, FileUploadOptions, GetGranteesResult, GranteesResult, Health, JsonFeedOptions, LastCashoutActionResponse, LastChequesForPeerResponse, LastChequesResponse, NodeAddresses, NodeInfo, NumberString, Peer, PeerBalance, Pin, PingResponse, PostageBatch, PostageBatchBuckets, PssMessageHandler, PssSubscription, PublicKey, RedistributionState, Reference, ReferenceInformation, RemovePeerResponse, ReserveState, SOCReader, SOCWriter, Settlements, Signer, Tag, Topic, Topology, TransactionHash, TransactionInfo, UploadOptions, UploadRedundancyOptions, UploadResultWithCid, WalletBalance } from './types';
6
6
  import { AllTagsOptions, CashoutOptions, Collection, FeedManifestResult, PostageBatchOptions, ReferenceCidOrEns, ReferenceOrEns, TransactionOptions, UploadResult } from './types';
7
7
  import { EthAddress } from './utils/eth';
8
8
  /**
@@ -42,6 +42,12 @@ export declare class Bee {
42
42
  * @see [Bee API reference - `POST /bytes`](https://docs.ethswarm.org/api/#tag/Bytes/paths/~1bytes/post)
43
43
  */
44
44
  uploadData(postageBatchId: string | BatchId, data: string | Uint8Array, options?: UploadOptions & UploadRedundancyOptions, requestOptions?: BeeRequestOptions): Promise<UploadResult>;
45
+ /**
46
+ * Requests content length for a `/bytes` reference
47
+ *
48
+ * @see [Bee API reference - `HEAD /bytes/`](https://docs.ethswarm.org/api/#tag/Bytes/paths/~1bytes~1%7Breference%7D/head)
49
+ */
50
+ probeData(reference: ReferenceOrEns | string, options?: BeeRequestOptions): Promise<ReferenceInformation>;
45
51
  /**
46
52
  * Download data as a byte array
47
53
  *
@@ -75,7 +81,7 @@ export declare class Bee {
75
81
  * @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/develop/access-the-swarm/upload-and-download)
76
82
  * @see [Bee API reference - `POST /chunks`](https://docs.ethswarm.org/api/#tag/Chunk/paths/~1chunks/post)
77
83
  */
78
- uploadChunk(postageBatchId: string | BatchId, data: Uint8Array, options?: UploadOptions, requestOptions?: BeeRequestOptions): Promise<UploadResult>;
84
+ uploadChunk(stamp: BatchId | Uint8Array | string, data: Uint8Array, options?: UploadOptions, requestOptions?: BeeRequestOptions): Promise<UploadResult>;
79
85
  /**
80
86
  * Download chunk as a byte array
81
87
  *
@@ -423,7 +429,7 @@ export declare class Bee {
423
429
  * @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/develop/tools-and-features/feeds)
424
430
  * @see [Bee API reference - `POST /feeds`](https://docs.ethswarm.org/api/#tag/Feed/paths/~1feeds~1{owner}~1{topic}/post)
425
431
  */
426
- createFeedManifest(postageBatchId: string | BatchId, type: FeedType, topic: Topic | Uint8Array | string, owner: EthAddress | Uint8Array | string, options?: BeeRequestOptions): Promise<FeedManifestResult>;
432
+ createFeedManifest(stamp: BatchId | Uint8Array | string, type: FeedType, topic: Topic | Uint8Array | string, owner: EthAddress | Uint8Array | string, options?: BeeRequestOptions): Promise<FeedManifestResult>;
427
433
  /**
428
434
  * Make a new feed reader for downloading feed updates.
429
435
  *
@@ -510,6 +516,7 @@ export declare class Bee {
510
516
  * @see [Bee docs - Chunk Types](https://docs.ethswarm.org/docs/develop/tools-and-features/chunk-types#single-owner-chunks)
511
517
  */
512
518
  makeSOCWriter(signer?: Signer | Uint8Array | string, options?: BeeRequestOptions): SOCWriter;
519
+ createEnvelope(postageBatchId: BatchId, reference: Reference, options?: BeeRequestOptions): Promise<Envelope>;
513
520
  /**
514
521
  * Ping the Bee node to see if there is a live Bee node on the given URL.
515
522
  *
@@ -44,7 +44,7 @@ export declare function makeSingleOwnerChunk(chunk: Chunk, identifier: Identifie
44
44
  * @param postageBatchId Postage BatchId that will be assigned to uploaded data
45
45
  * @param options Upload options
46
46
  */
47
- export declare function uploadSingleOwnerChunk(requestOptions: BeeRequestOptions, chunk: SingleOwnerChunk, postageBatchId: BatchId, options?: UploadOptions): Promise<UploadResult>;
47
+ export declare function uploadSingleOwnerChunk(requestOptions: BeeRequestOptions, chunk: SingleOwnerChunk, stamp: BatchId | Uint8Array | string, options?: UploadOptions): Promise<UploadResult>;
48
48
  /**
49
49
  * Helper function to create and upload SOC.
50
50
  *
@@ -55,7 +55,7 @@ export declare function uploadSingleOwnerChunk(requestOptions: BeeRequestOptions
55
55
  * @param data The chunk data
56
56
  * @param options
57
57
  */
58
- export declare function uploadSingleOwnerChunkData(requestOptions: BeeRequestOptions, signer: Signer, postageBatchId: BatchId | string, identifier: Identifier, data: Uint8Array, options?: UploadOptions): Promise<UploadResult>;
58
+ export declare function uploadSingleOwnerChunkData(requestOptions: BeeRequestOptions, signer: Signer, stamp: BatchId | Uint8Array | string, identifier: Identifier, data: Uint8Array, options?: UploadOptions): Promise<UploadResult>;
59
59
  /**
60
60
  * Helper function to download SOC.
61
61
  *
@@ -1,4 +1,4 @@
1
- import type { BatchId, BeeRequestOptions, Data, DownloadRedundancyOptions, ReferenceOrEns, UploadOptions, UploadRedundancyOptions } from '../types';
1
+ import type { BatchId, BeeRequestOptions, Data, DownloadRedundancyOptions, ReferenceInformation, ReferenceOrEns, UploadOptions, UploadRedundancyOptions } from '../types';
2
2
  import { UploadResult } from '../types';
3
3
  /**
4
4
  * Upload data to a Bee node
@@ -9,6 +9,13 @@ import { UploadResult } from '../types';
9
9
  * @param options Additional options like tag, encryption, pinning
10
10
  */
11
11
  export declare function upload(requestOptions: BeeRequestOptions, data: string | Uint8Array, postageBatchId: BatchId, options?: UploadOptions & UploadRedundancyOptions): Promise<UploadResult>;
12
+ /**
13
+ * Requests content length for a reference
14
+ *
15
+ * @param requestOptions Options for making requests
16
+ * @param hash Bee content reference
17
+ */
18
+ export declare function head(requestOptions: BeeRequestOptions, hash: ReferenceOrEns): Promise<ReferenceInformation>;
12
19
  /**
13
20
  * Download data as a byte array
14
21
  *
@@ -7,11 +7,11 @@ import type { BatchId, BeeRequestOptions, Data, ReferenceOrEns, UploadOptions, U
7
7
  * Upload expects the chuck data to be set accordingly.
8
8
  *
9
9
  * @param requestOptions Options for making requests
10
- * @param data Chunk data to be uploaded
11
- * @param postageBatchId Postage BatchId that will be assigned to uploaded data
10
+ * @param data Chunk data to be uploaded
11
+ * @param stamp BatchId or marshaled stamp to be used for the upload
12
12
  * @param options Additional options like tag, encryption, pinning
13
13
  */
14
- export declare function upload(requestOptions: BeeRequestOptions, data: Uint8Array, postageBatchId: BatchId, options?: UploadOptions): Promise<UploadResult>;
14
+ export declare function upload(requestOptions: BeeRequestOptions, data: Uint8Array, stamp: BatchId | Uint8Array | string, options?: UploadOptions): Promise<UploadResult>;
15
15
  /**
16
16
  * Download chunk data as a byte array
17
17
  *
@@ -0,0 +1,2 @@
1
+ import type { BatchId, BeeRequestOptions, Envelope, Reference } from '../types';
2
+ export declare function postEnvelope(requestOptions: BeeRequestOptions, postageBatchId: BatchId, reference: Reference): Promise<Envelope>;
@@ -38,7 +38,7 @@ export interface FetchFeedUpdateResponse extends ReferenceResponse, FeedUpdateHe
38
38
  * @param postageBatchId Postage BatchId to be used to create the Feed Manifest
39
39
  * @param options Additional options, like type (default: 'sequence')
40
40
  */
41
- export declare function createFeedManifest(requestOptions: BeeRequestOptions, owner: HexEthAddress, topic: Topic, postageBatchId: BatchId): Promise<Reference>;
41
+ export declare function createFeedManifest(requestOptions: BeeRequestOptions, owner: HexEthAddress, topic: Topic, stamp: BatchId | Uint8Array | string): Promise<Reference>;
42
42
  /**
43
43
  * Find and retrieve feed update
44
44
  *
@@ -10,4 +10,4 @@ import { BatchId, BeeRequestOptions, UploadOptions, UploadResult } from '../type
10
10
  * @param postageBatchId Postage BatchId that will be assigned to uploaded data
11
11
  * @param options Additional options like tag, encryption, pinning
12
12
  */
13
- export declare function upload(requestOptions: BeeRequestOptions, owner: string, identifier: string, signature: string, data: Uint8Array, postageBatchId: BatchId, options?: UploadOptions): Promise<UploadResult>;
13
+ export declare function upload(requestOptions: BeeRequestOptions, owner: string, identifier: string, signature: string, data: Uint8Array, stamp: BatchId | Uint8Array | string, options?: UploadOptions): Promise<UploadResult>;
@@ -295,6 +295,9 @@ export interface FileData<T> extends FileHeaders {
295
295
  export interface Pin {
296
296
  reference: string;
297
297
  }
298
+ export interface ReferenceInformation {
299
+ contentLength: number;
300
+ }
298
301
  /**
299
302
  * Helper interface that adds utility functions
300
303
  * to work more conveniently with bytes in normal
@@ -446,7 +449,7 @@ export interface SOCWriter extends SOCReader {
446
449
  * @param data The chunk payload data
447
450
  * @param options Upload options
448
451
  */
449
- upload: (postageBatchId: string | BatchId, identifier: Identifier, data: Uint8Array, options?: UploadOptions) => Promise<UploadResult>;
452
+ upload: (stamp: BatchId | Uint8Array | string, identifier: Identifier, data: Uint8Array, options?: UploadOptions) => Promise<UploadResult>;
450
453
  }
451
454
  /**
452
455
  * Interface representing Postage stamp batch.
@@ -519,6 +522,12 @@ export interface PostageBatchOptions {
519
522
  */
520
523
  waitForUsableTimeout?: number;
521
524
  }
525
+ export interface Envelope {
526
+ issuer: Uint8Array;
527
+ index: Uint8Array;
528
+ timestamp: Uint8Array;
529
+ signature: Uint8Array;
530
+ }
522
531
  /**
523
532
  * With this type a number should be represented in a string
524
533
  */
@@ -1,9 +1,12 @@
1
+ import { BatchId, Topic } from '..';
1
2
  export { getCollectionSize } from './collection';
2
3
  export { getFolderSize } from './collection.node';
3
- export { Bytes, FlexBytes, assertBytes, assertFlexBytes, bytesAtOffset, bytesEqual, flexBytesAtOffset, isBytes, isFlexBytes, } from './bytes';
4
- export { HexString, PrefixedHexString, assertHexString, assertPrefixedHexString, bytesToHex, hexToBytes, intToHex, isHexString, makeHexString, } from './hex';
5
- export { EthAddress, capitalizeAddressERC55, ethToSwarmAddress, fromLittleEndian, isHexEthAddress, makeEthAddress, makeEthereumWalletSigner, makeHexEthAddress, toLittleEndian, } from './eth';
4
+ export { assertBytes, assertFlexBytes, Bytes, bytesAtOffset, bytesEqual, FlexBytes, flexBytesAtOffset, isBytes, isFlexBytes, } from './bytes';
5
+ export { assertHexString, assertPrefixedHexString, bytesToHex, HexString, hexToBytes, intToHex, isHexString, makeHexString, PrefixedHexString, } from './hex';
6
+ export { capitalizeAddressERC55, EthAddress, ethToSwarmAddress, fromLittleEndian, isHexEthAddress, makeEthAddress, makeEthereumWalletSigner, makeHexEthAddress, toLittleEndian, } from './eth';
6
7
  export { keccak256Hash } from './hash';
7
8
  export { makeMaxTarget } from './pss';
8
9
  export { getAmountForTtl, getDepthForCapacity, getStampCostInBzz, getStampCostInPlur, getStampEffectiveBytes, getStampMaximumCapacityBytes, getStampTtlSeconds, getStampUsage, } from './stamps';
9
10
  export { approximateOverheadForRedundancyLevel, getRedundancyStat, getRedundancyStats } from './redundancy';
11
+ export declare const NULL_STAMP: BatchId;
12
+ export declare const NULL_TOPIC: Topic;
@@ -1,5 +1,5 @@
1
1
  import { BatchId, DownloadRedundancyOptions, FileHeaders, UploadOptions, UploadRedundancyOptions } from '../types';
2
2
  export declare function readFileHeaders(headers: Record<string, string>): FileHeaders;
3
- export declare function extractUploadHeaders(postageBatchId: BatchId, options?: UploadOptions): Record<string, string>;
3
+ export declare function extractUploadHeaders(stamp: BatchId | Uint8Array | string, options?: UploadOptions): Record<string, string>;
4
4
  export declare function extractRedundantUploadHeaders(postageBatchId: BatchId, options?: UploadOptions & UploadRedundancyOptions): Record<string, string>;
5
5
  export declare function extractDownloadHeaders(options?: DownloadRedundancyOptions): Record<string, string>;
@@ -1,4 +1,4 @@
1
- import { NumberString } from '../types';
1
+ import { BatchId, Envelope, NumberString } from '../types';
2
2
  /**
3
3
  * Utility function that calculates usage of postage batch based on its utilization, depth and bucket depth.
4
4
  *
@@ -62,3 +62,5 @@ export declare function getAmountForTtl(days: number): NumberString;
62
62
  * @returns {number} The calculated depth necessary to achieve the specified capacity.
63
63
  */
64
64
  export declare function getDepthForCapacity(gigabytes: number): number;
65
+ export declare function convertEnvelopeToMarshaledStamp(batchID: BatchId, envelope: Envelope): Uint8Array;
66
+ export declare function marshalStamp(signature: Uint8Array, batchID: Uint8Array, timestamp: Uint8Array, index: Uint8Array): Uint8Array;
@@ -3,7 +3,6 @@ import { ReferenceType } from '@ethersphere/swarm-cid';
3
3
  import { Readable } from 'stream';
4
4
  import { Address, AddressPrefix, AllTagsOptions, BatchId, BeeRequestOptions, CashoutOptions, CollectionUploadOptions, FileUploadOptions, NumberString, PostageBatchOptions, PssMessageHandler, PublicKey, Reference, ReferenceOrEns, Tag, TransactionHash, TransactionOptions, UploadOptions } from '../types';
5
5
  export declare function isReadable(obj: unknown): obj is Readable;
6
- export declare function isUint8Array(obj: unknown): obj is Uint8Array;
7
6
  export declare function isInteger(value: unknown): value is number | NumberString;
8
7
  export declare function isObject(value: unknown): value is Record<string, unknown>;
9
8
  export declare function isStrictlyObject(value: unknown): value is Record<string, unknown>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ethersphere/bee-js",
3
- "version": "8.1.0",
3
+ "version": "8.2.0",
4
4
  "description": "Javascript client for Bee",
5
5
  "keywords": [
6
6
  "bee",
@@ -63,7 +63,7 @@
63
63
  "dependencies": {
64
64
  "@ethersphere/swarm-cid": "^0.1.0",
65
65
  "axios": "^0.28.1",
66
- "cafe-utility": "^21.3.1",
66
+ "cafe-utility": "^23.7.0",
67
67
  "elliptic": "^6.5.4",
68
68
  "isomorphic-ws": "^4.0.1",
69
69
  "js-sha3": "^0.8.0",