@ethersphere/bee-js 3.3.2 → 3.3.4

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 (52) hide show
  1. package/LICENSE +24 -22
  2. package/dist/cjs/modules/debug/status.js +1 -1
  3. package/dist/cjs/utils/data.browser.js +6 -10
  4. package/dist/cjs/utils/data.js +4 -6
  5. package/dist/index.browser.min.js +1 -1
  6. package/dist/index.browser.min.js.map +1 -1
  7. package/dist/mjs/bee-debug.js +294 -189
  8. package/dist/mjs/bee.js +316 -237
  9. package/dist/mjs/chunk/signer.js +46 -12
  10. package/dist/mjs/chunk/soc.js +71 -31
  11. package/dist/mjs/chunk/span.js +1 -1
  12. package/dist/mjs/feed/index.js +86 -42
  13. package/dist/mjs/feed/json.js +46 -10
  14. package/dist/mjs/index.js +2 -1
  15. package/dist/mjs/modules/bytes.js +61 -24
  16. package/dist/mjs/modules/bzz.js +96 -58
  17. package/dist/mjs/modules/chunk.js +51 -16
  18. package/dist/mjs/modules/debug/balance.js +60 -20
  19. package/dist/mjs/modules/debug/chequebook.js +115 -67
  20. package/dist/mjs/modules/debug/chunk.js +47 -11
  21. package/dist/mjs/modules/debug/connectivity.js +76 -32
  22. package/dist/mjs/modules/debug/settlements.js +46 -10
  23. package/dist/mjs/modules/debug/stamps.js +91 -47
  24. package/dist/mjs/modules/debug/states.js +48 -12
  25. package/dist/mjs/modules/debug/status.js +98 -50
  26. package/dist/mjs/modules/debug/tag.js +39 -5
  27. package/dist/mjs/modules/debug/transactions.js +65 -25
  28. package/dist/mjs/modules/feed.js +50 -16
  29. package/dist/mjs/modules/pinning.js +67 -27
  30. package/dist/mjs/modules/pss.js +44 -10
  31. package/dist/mjs/modules/soc.js +47 -14
  32. package/dist/mjs/modules/status.js +37 -3
  33. package/dist/mjs/modules/stewardship.js +46 -10
  34. package/dist/mjs/modules/tag.js +73 -31
  35. package/dist/mjs/utils/collection.browser.js +41 -4
  36. package/dist/mjs/utils/collection.js +45 -11
  37. package/dist/mjs/utils/collection.node.js +137 -42
  38. package/dist/mjs/utils/data.browser.js +88 -53
  39. package/dist/mjs/utils/data.js +57 -22
  40. package/dist/mjs/utils/error.js +0 -9
  41. package/dist/mjs/utils/eth.js +68 -32
  42. package/dist/mjs/utils/file.js +42 -8
  43. package/dist/mjs/utils/headers.js +4 -4
  44. package/dist/mjs/utils/http.js +110 -64
  45. package/dist/mjs/utils/merge.js +2 -2
  46. package/dist/mjs/utils/stream.js +0 -4
  47. package/dist/mjs/utils/type.js +6 -6
  48. package/dist/types/modules/debug/status.d.ts +1 -1
  49. package/dist/types/types/debug.d.ts +19 -0
  50. package/dist/types/utils/data.browser.d.ts +0 -1
  51. package/dist/types/utils/data.d.ts +2 -2
  52. package/package.json +14 -13
@@ -1,4 +1,36 @@
1
- // For ESM compatibility
1
+ var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) {
3
+ return value instanceof P ? value : new P(function (resolve) {
4
+ resolve(value);
5
+ });
6
+ }
7
+
8
+ return new (P || (P = Promise))(function (resolve, reject) {
9
+ function fulfilled(value) {
10
+ try {
11
+ step(generator.next(value));
12
+ } catch (e) {
13
+ reject(e);
14
+ }
15
+ }
16
+
17
+ function rejected(value) {
18
+ try {
19
+ step(generator["throw"](value));
20
+ } catch (e) {
21
+ reject(e);
22
+ }
23
+ }
24
+
25
+ function step(result) {
26
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
27
+ }
28
+
29
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
30
+ });
31
+ }; // For ESM compatibility
32
+
33
+
2
34
  import pkg from 'elliptic';
3
35
  const {
4
36
  ec
@@ -114,18 +146,20 @@ export function makeSigner(signer) {
114
146
  assertSigner(signer);
115
147
  return signer;
116
148
  }
117
- export async function sign(signer, data) {
118
- const result = await signer.sign(wrapBytesWithHelpers(data));
149
+ export function sign(signer, data) {
150
+ return __awaiter(this, void 0, void 0, function* () {
151
+ const result = yield signer.sign(wrapBytesWithHelpers(data));
119
152
 
120
- if (typeof result === 'string') {
121
- const hexString = makeHexString(result, SIGNATURE_HEX_LENGTH);
122
- return hexToBytes(hexString);
123
- }
153
+ if (typeof result === 'string') {
154
+ const hexString = makeHexString(result, SIGNATURE_HEX_LENGTH);
155
+ return hexToBytes(hexString);
156
+ }
124
157
 
125
- if (result instanceof Uint8Array) {
126
- assertBytes(result, SIGNATURE_BYTES_LENGTH);
127
- return result;
128
- }
158
+ if (result instanceof Uint8Array) {
159
+ assertBytes(result, SIGNATURE_BYTES_LENGTH);
160
+ return result;
161
+ }
129
162
 
130
- throw new TypeError('Invalid output of sign function!');
163
+ throw new TypeError('Invalid output of sign function!');
164
+ });
131
165
  }
@@ -1,3 +1,35 @@
1
+ var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) {
3
+ return value instanceof P ? value : new P(function (resolve) {
4
+ resolve(value);
5
+ });
6
+ }
7
+
8
+ return new (P || (P = Promise))(function (resolve, reject) {
9
+ function fulfilled(value) {
10
+ try {
11
+ step(generator.next(value));
12
+ } catch (e) {
13
+ reject(e);
14
+ }
15
+ }
16
+
17
+ function rejected(value) {
18
+ try {
19
+ step(generator["throw"](value));
20
+ } catch (e) {
21
+ reject(e);
22
+ }
23
+ }
24
+
25
+ function step(result) {
26
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
27
+ }
28
+
29
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
30
+ });
31
+ };
32
+
1
33
  import { bytesAtOffset, bytesEqual, flexBytesAtOffset } from "../utils/bytes.js";
2
34
  import { bmtHash } from "./bmt.js";
3
35
  import { recoverAddress, sign } from "./signer.js";
@@ -72,22 +104,24 @@ export function makeSOCAddress(identifier, address) {
72
104
  * @param signer The singer interface for signing the chunk
73
105
  */
74
106
 
75
- export async function makeSingleOwnerChunk(chunk, identifier, signer) {
76
- const chunkAddress = chunk.address();
77
- assertValidChunkData(chunk.data, chunkAddress);
78
- const digest = keccak256Hash(identifier, chunkAddress);
79
- const signature = await sign(signer, digest);
80
- const data = serializeBytes(identifier, signature, chunk.span(), chunk.payload());
81
- const address = makeSOCAddress(identifier, signer.address);
82
- return {
83
- data,
84
- identifier: () => identifier,
85
- signature: () => signature,
86
- span: () => chunk.span(),
87
- payload: () => chunk.payload(),
88
- address: () => address,
89
- owner: () => signer.address
90
- };
107
+ export function makeSingleOwnerChunk(chunk, identifier, signer) {
108
+ return __awaiter(this, void 0, void 0, function* () {
109
+ const chunkAddress = chunk.address();
110
+ assertValidChunkData(chunk.data, chunkAddress);
111
+ const digest = keccak256Hash(identifier, chunkAddress);
112
+ const signature = yield sign(signer, digest);
113
+ const data = serializeBytes(identifier, signature, chunk.span(), chunk.payload());
114
+ const address = makeSOCAddress(identifier, signer.address);
115
+ return {
116
+ data,
117
+ identifier: () => identifier,
118
+ signature: () => signature,
119
+ span: () => chunk.span(),
120
+ payload: () => chunk.payload(),
121
+ address: () => address,
122
+ owner: () => signer.address
123
+ };
124
+ });
91
125
  }
92
126
  /**
93
127
  * Helper function to upload a chunk.
@@ -100,12 +134,14 @@ export async function makeSingleOwnerChunk(chunk, identifier, signer) {
100
134
  * @param options Upload options
101
135
  */
102
136
 
103
- export async function uploadSingleOwnerChunk(ky, chunk, postageBatchId, options) {
104
- const owner = bytesToHex(chunk.owner());
105
- const identifier = bytesToHex(chunk.identifier());
106
- const signature = bytesToHex(chunk.signature());
107
- const data = serializeBytes(chunk.span(), chunk.payload());
108
- return socAPI.upload(ky, owner, identifier, signature, data, postageBatchId, options);
137
+ export function uploadSingleOwnerChunk(ky, chunk, postageBatchId, options) {
138
+ return __awaiter(this, void 0, void 0, function* () {
139
+ const owner = bytesToHex(chunk.owner());
140
+ const identifier = bytesToHex(chunk.identifier());
141
+ const signature = bytesToHex(chunk.signature());
142
+ const data = serializeBytes(chunk.span(), chunk.payload());
143
+ return socAPI.upload(ky, owner, identifier, signature, data, postageBatchId, options);
144
+ });
109
145
  }
110
146
  /**
111
147
  * Helper function to create and upload SOC.
@@ -118,11 +154,13 @@ export async function uploadSingleOwnerChunk(ky, chunk, postageBatchId, options)
118
154
  * @param options
119
155
  */
120
156
 
121
- export async function uploadSingleOwnerChunkData(ky, signer, postageBatchId, identifier, data, options) {
122
- assertAddress(postageBatchId);
123
- const cac = makeContentAddressedChunk(data);
124
- const soc = await makeSingleOwnerChunk(cac, identifier, signer);
125
- return uploadSingleOwnerChunk(ky, soc, postageBatchId, options);
157
+ export function uploadSingleOwnerChunkData(ky, signer, postageBatchId, identifier, data, options) {
158
+ return __awaiter(this, void 0, void 0, function* () {
159
+ assertAddress(postageBatchId);
160
+ const cac = makeContentAddressedChunk(data);
161
+ const soc = yield makeSingleOwnerChunk(cac, identifier, signer);
162
+ return uploadSingleOwnerChunk(ky, soc, postageBatchId, options);
163
+ });
126
164
  }
127
165
  /**
128
166
  * Helper function to download SOC.
@@ -132,8 +170,10 @@ export async function uploadSingleOwnerChunkData(ky, signer, postageBatchId, ide
132
170
  * @param identifier The identifier of the chunk
133
171
  */
134
172
 
135
- export async function downloadSingleOwnerChunk(ky, ownerAddress, identifier) {
136
- const address = makeSOCAddress(identifier, ownerAddress);
137
- const data = await chunkAPI.download(ky, bytesToHex(address));
138
- return makeSingleOwnerChunkFromData(data, address);
173
+ export function downloadSingleOwnerChunk(ky, ownerAddress, identifier) {
174
+ return __awaiter(this, void 0, void 0, function* () {
175
+ const address = makeSOCAddress(identifier, ownerAddress);
176
+ const data = yield chunkAPI.download(ky, bytesToHex(address));
177
+ return makeSingleOwnerChunkFromData(data, address);
178
+ });
139
179
  }
@@ -1,7 +1,7 @@
1
1
  import { BeeArgumentError } from "../utils/error.js";
2
2
  export const SPAN_SIZE = 8; // we limit the maximum span size in 32 bits to avoid BigInt compatibility issues
3
3
 
4
- const MAX_SPAN_LENGTH = 2 ** 32 - 1;
4
+ const MAX_SPAN_LENGTH = Math.pow(2, 32) - 1;
5
5
  /**
6
6
  * Create a span for storing the length of the chunk
7
7
  *
@@ -1,3 +1,35 @@
1
+ var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) {
3
+ return value instanceof P ? value : new P(function (resolve) {
4
+ resolve(value);
5
+ });
6
+ }
7
+
8
+ return new (P || (P = Promise))(function (resolve, reject) {
9
+ function fulfilled(value) {
10
+ try {
11
+ step(generator.next(value));
12
+ } catch (e) {
13
+ reject(e);
14
+ }
15
+ }
16
+
17
+ function rejected(value) {
18
+ try {
19
+ step(generator["throw"](value));
20
+ } catch (e) {
21
+ reject(e);
22
+ }
23
+ }
24
+
25
+ function step(result) {
26
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
27
+ }
28
+
29
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
30
+ });
31
+ };
32
+
1
33
  import { keccak256Hash } from "../utils/hash.js";
2
34
  import { serializeBytes } from "../chunk/serialize.js";
3
35
  import { uploadSingleOwnerChunkData, makeSingleOwnerChunkFromData } from "../chunk/soc.js";
@@ -44,29 +76,37 @@ export function makeFeedIdentifier(topic, index) {
44
76
 
45
77
  return hashFeedIdentifier(topic, index);
46
78
  }
47
- export async function uploadFeedUpdate(ky, signer, topic, index, reference, postageBatchId, options) {
48
- const identifier = makeFeedIdentifier(topic, index);
49
- const at = options?.at ?? Date.now() / 1000.0;
50
- const timestamp = writeUint64BigEndian(at);
51
- const payloadBytes = serializeBytes(timestamp, reference);
52
- return uploadSingleOwnerChunkData(ky, signer, postageBatchId, identifier, payloadBytes, options);
79
+ export function uploadFeedUpdate(ky, signer, topic, index, reference, postageBatchId, options) {
80
+ var _a;
81
+
82
+ return __awaiter(this, void 0, void 0, function* () {
83
+ const identifier = makeFeedIdentifier(topic, index);
84
+ const at = (_a = options === null || options === void 0 ? void 0 : options.at) !== null && _a !== void 0 ? _a : Date.now() / 1000.0;
85
+ const timestamp = writeUint64BigEndian(at);
86
+ const payloadBytes = serializeBytes(timestamp, reference);
87
+ return uploadSingleOwnerChunkData(ky, signer, postageBatchId, identifier, payloadBytes, options);
88
+ });
53
89
  }
54
- export async function findNextIndex(ky, owner, topic, options) {
55
- try {
56
- const feedUpdate = await fetchFeedUpdate(ky, owner, topic, options);
57
- return makeHexString(feedUpdate.feedIndexNext, INDEX_HEX_LENGTH);
58
- } catch (e) {
59
- if (e instanceof BeeResponseError && e.status === 404) {
60
- return bytesToHex(makeBytes(8));
61
- }
90
+ export function findNextIndex(ky, owner, topic, options) {
91
+ return __awaiter(this, void 0, void 0, function* () {
92
+ try {
93
+ const feedUpdate = yield fetchFeedUpdate(ky, owner, topic, options);
94
+ return makeHexString(feedUpdate.feedIndexNext, INDEX_HEX_LENGTH);
95
+ } catch (e) {
96
+ if (e instanceof BeeResponseError && e.status === 404) {
97
+ return bytesToHex(makeBytes(8));
98
+ }
62
99
 
63
- throw e;
64
- }
100
+ throw e;
101
+ }
102
+ });
65
103
  }
66
- export async function updateFeed(ky, signer, topic, reference, postageBatchId, options) {
67
- const ownerHex = makeHexEthAddress(signer.address);
68
- const nextIndex = await findNextIndex(ky, ownerHex, topic, options);
69
- return uploadFeedUpdate(ky, signer, topic, nextIndex, reference, postageBatchId, options);
104
+ export function updateFeed(ky, signer, topic, reference, postageBatchId, options) {
105
+ return __awaiter(this, void 0, void 0, function* () {
106
+ const ownerHex = makeHexEthAddress(signer.address);
107
+ const nextIndex = yield findNextIndex(ky, ownerHex, topic, options);
108
+ return uploadFeedUpdate(ky, signer, topic, nextIndex, reference, postageBatchId, options);
109
+ });
70
110
  }
71
111
 
72
112
  function verifyChunkReferenceAtOffset(offset, data) {
@@ -80,24 +120,28 @@ function verifyChunkReferenceAtOffset(offset, data) {
80
120
  export function verifyChunkReference(data) {
81
121
  return verifyChunkReferenceAtOffset(0, data);
82
122
  }
83
- export async function downloadFeedUpdate(ky, owner, topic, index) {
84
- const identifier = makeFeedIdentifier(topic, index);
85
- const address = keccak256Hash(identifier, owner);
86
- const addressHex = bytesToHex(address);
87
- const data = await chunkAPI.download(ky, addressHex);
88
- const soc = makeSingleOwnerChunkFromData(data, address);
89
- const payload = soc.payload();
90
- const timestampBytes = bytesAtOffset(payload, TIMESTAMP_PAYLOAD_OFFSET, TIMESTAMP_PAYLOAD_SIZE);
91
- const timestamp = readUint64BigEndian(timestampBytes);
92
- const reference = verifyChunkReferenceAtOffset(REFERENCE_PAYLOAD_OFFSET, payload);
93
- return {
94
- timestamp,
95
- reference
96
- };
123
+ export function downloadFeedUpdate(ky, owner, topic, index) {
124
+ return __awaiter(this, void 0, void 0, function* () {
125
+ const identifier = makeFeedIdentifier(topic, index);
126
+ const address = keccak256Hash(identifier, owner);
127
+ const addressHex = bytesToHex(address);
128
+ const data = yield chunkAPI.download(ky, addressHex);
129
+ const soc = makeSingleOwnerChunkFromData(data, address);
130
+ const payload = soc.payload();
131
+ const timestampBytes = bytesAtOffset(payload, TIMESTAMP_PAYLOAD_OFFSET, TIMESTAMP_PAYLOAD_SIZE);
132
+ const timestamp = readUint64BigEndian(timestampBytes);
133
+ const reference = verifyChunkReferenceAtOffset(REFERENCE_PAYLOAD_OFFSET, payload);
134
+ return {
135
+ timestamp,
136
+ reference
137
+ };
138
+ });
97
139
  }
98
140
  export function makeFeedReader(ky, type, topic, owner) {
99
- const download = async options => fetchFeedUpdate(ky, owner, topic, { ...options,
100
- type
141
+ const download = options => __awaiter(this, void 0, void 0, function* () {
142
+ return fetchFeedUpdate(ky, owner, topic, Object.assign(Object.assign({}, options), {
143
+ type
144
+ }));
101
145
  });
102
146
 
103
147
  return {
@@ -131,15 +175,15 @@ function makeChunkReference(reference) {
131
175
  }
132
176
 
133
177
  export function makeFeedWriter(ky, type, topic, signer) {
134
- const upload = async (postageBatchId, reference, options) => {
178
+ const upload = (postageBatchId, reference, options) => __awaiter(this, void 0, void 0, function* () {
135
179
  assertAddress(postageBatchId);
136
180
  const canonicalReference = makeChunkReference(reference);
137
- return updateFeed(ky, signer, topic, canonicalReference, postageBatchId, { ...options,
181
+ return updateFeed(ky, signer, topic, canonicalReference, postageBatchId, Object.assign(Object.assign({}, options), {
138
182
  type
139
- });
140
- };
183
+ }));
184
+ });
141
185
 
142
- return { ...makeFeedReader(ky, type, topic, makeHexEthAddress(signer.address)),
186
+ return Object.assign(Object.assign({}, makeFeedReader(ky, type, topic, makeHexEthAddress(signer.address))), {
143
187
  upload
144
- };
188
+ });
145
189
  }
@@ -1,3 +1,35 @@
1
+ var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) {
3
+ return value instanceof P ? value : new P(function (resolve) {
4
+ resolve(value);
5
+ });
6
+ }
7
+
8
+ return new (P || (P = Promise))(function (resolve, reject) {
9
+ function fulfilled(value) {
10
+ try {
11
+ step(generator.next(value));
12
+ } catch (e) {
13
+ reject(e);
14
+ }
15
+ }
16
+
17
+ function rejected(value) {
18
+ try {
19
+ step(generator["throw"](value));
20
+ } catch (e) {
21
+ reject(e);
22
+ }
23
+ }
24
+
25
+ function step(result) {
26
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
27
+ }
28
+
29
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
30
+ });
31
+ };
32
+
1
33
  import { isError } from "../utils/type.js";
2
34
 
3
35
  function serializeJson(data) {
@@ -13,15 +45,19 @@ function serializeJson(data) {
13
45
  }
14
46
  }
15
47
 
16
- export async function getJsonData(bee, reader) {
17
- const feedUpdate = await reader.download();
18
- const retrievedData = await bee.downloadData(feedUpdate.reference);
19
- return retrievedData.json();
48
+ export function getJsonData(bee, reader) {
49
+ return __awaiter(this, void 0, void 0, function* () {
50
+ const feedUpdate = yield reader.download();
51
+ const retrievedData = yield bee.downloadData(feedUpdate.reference);
52
+ return retrievedData.json();
53
+ });
20
54
  }
21
- export async function setJsonData(bee, writer, postageBatchId, data, options) {
22
- const serializedData = serializeJson(data);
23
- const {
24
- reference
25
- } = await bee.uploadData(postageBatchId, serializedData, options);
26
- return writer.upload(postageBatchId, reference);
55
+ export function setJsonData(bee, writer, postageBatchId, data, options) {
56
+ return __awaiter(this, void 0, void 0, function* () {
57
+ const serializedData = serializeJson(data);
58
+ const {
59
+ reference
60
+ } = yield bee.uploadData(postageBatchId, serializedData, options);
61
+ return writer.upload(postageBatchId, reference);
62
+ });
27
63
  }
package/dist/mjs/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { Bee } from "./bee.js";
2
2
  import { BeeDebug } from "./bee-debug.js";
3
- export * as Utils from "./utils/expose.js";
3
+ import * as Utils_1 from "./utils/expose.js";
4
+ export { Utils_1 as Utils };
4
5
  export * from "./types/index.js";
5
6
  export * from "./utils/error.js";
6
7
  export { SUPPORTED_BEE_VERSION, SUPPORTED_BEE_VERSION_EXACT } from "./modules/debug/status.js";
@@ -1,3 +1,35 @@
1
+ var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) {
3
+ return value instanceof P ? value : new P(function (resolve) {
4
+ resolve(value);
5
+ });
6
+ }
7
+
8
+ return new (P || (P = Promise))(function (resolve, reject) {
9
+ function fulfilled(value) {
10
+ try {
11
+ step(generator.next(value));
12
+ } catch (e) {
13
+ reject(e);
14
+ }
15
+ }
16
+
17
+ function rejected(value) {
18
+ try {
19
+ step(generator["throw"](value));
20
+ } catch (e) {
21
+ reject(e);
22
+ }
23
+ }
24
+
25
+ function step(result) {
26
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
27
+ }
28
+
29
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
30
+ });
31
+ };
32
+
1
33
  import { prepareData } from "../utils/data.js";
2
34
  import { extractUploadHeaders } from "../utils/headers.js";
3
35
  import { http } from "../utils/http.js";
@@ -13,21 +45,22 @@ const endpoint = 'bytes';
13
45
  * @param options Additional options like tag, encryption, pinning
14
46
  */
15
47
 
16
- export async function upload(ky, data, postageBatchId, options) {
17
- const response = await http(ky, {
18
- path: endpoint,
19
- method: 'post',
20
- responseType: 'json',
21
- body: await prepareData(data),
22
- headers: {
23
- 'content-type': 'application/octet-stream',
24
- ...extractUploadHeaders(postageBatchId, options)
25
- }
48
+ export function upload(ky, data, postageBatchId, options) {
49
+ return __awaiter(this, void 0, void 0, function* () {
50
+ const response = yield http(ky, {
51
+ path: endpoint,
52
+ method: 'post',
53
+ responseType: 'json',
54
+ body: yield prepareData(data),
55
+ headers: Object.assign({
56
+ 'content-type': 'application/octet-stream'
57
+ }, extractUploadHeaders(postageBatchId, options))
58
+ });
59
+ return {
60
+ reference: response.data.reference,
61
+ tagUid: makeTagUid(response.headers.get('swarm-tag'))
62
+ };
26
63
  });
27
- return {
28
- reference: response.data.reference,
29
- tagUid: makeTagUid(response.headers.get('swarm-tag'))
30
- };
31
64
  }
32
65
  /**
33
66
  * Download data as a byte array
@@ -36,12 +69,14 @@ export async function upload(ky, data, postageBatchId, options) {
36
69
  * @param hash Bee content reference
37
70
  */
38
71
 
39
- export async function download(ky, hash) {
40
- const response = await http(ky, {
41
- responseType: 'arraybuffer',
42
- path: `${endpoint}/${hash}`
72
+ export function download(ky, hash) {
73
+ return __awaiter(this, void 0, void 0, function* () {
74
+ const response = yield http(ky, {
75
+ responseType: 'arraybuffer',
76
+ path: `${endpoint}/${hash}`
77
+ });
78
+ return wrapBytesWithHelpers(new Uint8Array(response.data));
43
79
  });
44
- return wrapBytesWithHelpers(new Uint8Array(response.data));
45
80
  }
46
81
  /**
47
82
  * Download data as a readable stream
@@ -50,10 +85,12 @@ export async function download(ky, hash) {
50
85
  * @param hash Bee content reference
51
86
  */
52
87
 
53
- export async function downloadReadable(ky, hash) {
54
- const response = await http(ky, {
55
- responseType: 'stream',
56
- path: `${endpoint}/${hash}`
88
+ export function downloadReadable(ky, hash) {
89
+ return __awaiter(this, void 0, void 0, function* () {
90
+ const response = yield http(ky, {
91
+ responseType: 'stream',
92
+ path: `${endpoint}/${hash}`
93
+ });
94
+ return response.data;
57
95
  });
58
- return response.data;
59
96
  }