@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.
- package/LICENSE +24 -22
- package/dist/cjs/modules/debug/status.js +1 -1
- package/dist/cjs/utils/data.browser.js +6 -10
- package/dist/cjs/utils/data.js +4 -6
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/bee-debug.js +294 -189
- package/dist/mjs/bee.js +316 -237
- package/dist/mjs/chunk/signer.js +46 -12
- package/dist/mjs/chunk/soc.js +71 -31
- package/dist/mjs/chunk/span.js +1 -1
- package/dist/mjs/feed/index.js +86 -42
- package/dist/mjs/feed/json.js +46 -10
- package/dist/mjs/index.js +2 -1
- package/dist/mjs/modules/bytes.js +61 -24
- package/dist/mjs/modules/bzz.js +96 -58
- package/dist/mjs/modules/chunk.js +51 -16
- package/dist/mjs/modules/debug/balance.js +60 -20
- package/dist/mjs/modules/debug/chequebook.js +115 -67
- package/dist/mjs/modules/debug/chunk.js +47 -11
- package/dist/mjs/modules/debug/connectivity.js +76 -32
- package/dist/mjs/modules/debug/settlements.js +46 -10
- package/dist/mjs/modules/debug/stamps.js +91 -47
- package/dist/mjs/modules/debug/states.js +48 -12
- package/dist/mjs/modules/debug/status.js +98 -50
- package/dist/mjs/modules/debug/tag.js +39 -5
- package/dist/mjs/modules/debug/transactions.js +65 -25
- package/dist/mjs/modules/feed.js +50 -16
- package/dist/mjs/modules/pinning.js +67 -27
- package/dist/mjs/modules/pss.js +44 -10
- package/dist/mjs/modules/soc.js +47 -14
- package/dist/mjs/modules/status.js +37 -3
- package/dist/mjs/modules/stewardship.js +46 -10
- package/dist/mjs/modules/tag.js +73 -31
- package/dist/mjs/utils/collection.browser.js +41 -4
- package/dist/mjs/utils/collection.js +45 -11
- package/dist/mjs/utils/collection.node.js +137 -42
- package/dist/mjs/utils/data.browser.js +88 -53
- package/dist/mjs/utils/data.js +57 -22
- package/dist/mjs/utils/error.js +0 -9
- package/dist/mjs/utils/eth.js +68 -32
- package/dist/mjs/utils/file.js +42 -8
- package/dist/mjs/utils/headers.js +4 -4
- package/dist/mjs/utils/http.js +110 -64
- package/dist/mjs/utils/merge.js +2 -2
- package/dist/mjs/utils/stream.js +0 -4
- package/dist/mjs/utils/type.js +6 -6
- package/dist/types/modules/debug/status.d.ts +1 -1
- package/dist/types/types/debug.d.ts +19 -0
- package/dist/types/utils/data.browser.d.ts +0 -1
- package/dist/types/utils/data.d.ts +2 -2
- package/package.json +14 -13
package/dist/mjs/chunk/signer.js
CHANGED
|
@@ -1,4 +1,36 @@
|
|
|
1
|
-
|
|
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
|
|
118
|
-
|
|
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
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
153
|
+
if (typeof result === 'string') {
|
|
154
|
+
const hexString = makeHexString(result, SIGNATURE_HEX_LENGTH);
|
|
155
|
+
return hexToBytes(hexString);
|
|
156
|
+
}
|
|
124
157
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
158
|
+
if (result instanceof Uint8Array) {
|
|
159
|
+
assertBytes(result, SIGNATURE_BYTES_LENGTH);
|
|
160
|
+
return result;
|
|
161
|
+
}
|
|
129
162
|
|
|
130
|
-
|
|
163
|
+
throw new TypeError('Invalid output of sign function!');
|
|
164
|
+
});
|
|
131
165
|
}
|
package/dist/mjs/chunk/soc.js
CHANGED
|
@@ -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
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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
|
}
|
package/dist/mjs/chunk/span.js
CHANGED
|
@@ -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
|
|
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
|
*
|
package/dist/mjs/feed/index.js
CHANGED
|
@@ -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
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
|
|
64
|
-
|
|
100
|
+
throw e;
|
|
101
|
+
}
|
|
102
|
+
});
|
|
65
103
|
}
|
|
66
|
-
export
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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 =
|
|
100
|
-
|
|
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 =
|
|
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, {
|
|
181
|
+
return updateFeed(ky, signer, topic, canonicalReference, postageBatchId, Object.assign(Object.assign({}, options), {
|
|
138
182
|
type
|
|
139
|
-
});
|
|
140
|
-
};
|
|
183
|
+
}));
|
|
184
|
+
});
|
|
141
185
|
|
|
142
|
-
return {
|
|
186
|
+
return Object.assign(Object.assign({}, makeFeedReader(ky, type, topic, makeHexEthAddress(signer.address))), {
|
|
143
187
|
upload
|
|
144
|
-
};
|
|
188
|
+
});
|
|
145
189
|
}
|
package/dist/mjs/feed/json.js
CHANGED
|
@@ -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
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
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
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
}
|