@ethersphere/bee-js 6.0.0-pre.0 → 6.0.0-pre.10
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 +18 -17
- package/dist/cjs/bee-debug.js +572 -0
- package/dist/cjs/bee.js +876 -0
- package/dist/cjs/chunk/bmt.js +55 -0
- package/dist/cjs/chunk/cac.js +56 -0
- package/dist/cjs/chunk/serialize.js +19 -0
- package/dist/cjs/chunk/signer.js +126 -0
- package/dist/cjs/chunk/soc.js +159 -0
- package/dist/cjs/chunk/span.js +29 -0
- package/dist/cjs/feed/identifier.js +35 -0
- package/dist/cjs/feed/index.js +116 -0
- package/dist/cjs/feed/json.js +28 -0
- package/dist/cjs/feed/retrievable.js +58 -0
- package/dist/cjs/feed/topic.js +25 -0
- package/dist/cjs/feed/type.js +15 -0
- package/dist/cjs/index.js +39 -0
- package/dist/cjs/modules/bytes.js +61 -0
- package/dist/cjs/modules/bzz.js +125 -0
- package/dist/cjs/modules/chunk.js +48 -0
- package/dist/cjs/modules/debug/balance.js +60 -0
- package/dist/cjs/modules/debug/chequebook.js +142 -0
- package/dist/cjs/modules/debug/chunk.js +38 -0
- package/dist/cjs/modules/debug/connectivity.js +54 -0
- package/dist/cjs/modules/debug/settlements.js +32 -0
- package/dist/cjs/modules/debug/stake.js +57 -0
- package/dist/cjs/modules/debug/stamps.js +68 -0
- package/dist/cjs/modules/debug/states.js +64 -0
- package/dist/cjs/modules/debug/status.js +148 -0
- package/dist/cjs/modules/debug/tag.js +19 -0
- package/dist/cjs/modules/debug/transactions.js +64 -0
- package/dist/cjs/modules/feed.js +66 -0
- package/dist/cjs/modules/pinning.js +63 -0
- package/dist/cjs/modules/pss.js +43 -0
- package/dist/cjs/modules/soc.js +32 -0
- package/dist/cjs/modules/status.js +15 -0
- package/dist/cjs/modules/stewardship.js +28 -0
- package/dist/cjs/modules/tag.js +77 -0
- package/dist/cjs/package.json +8 -0
- package/dist/cjs/types/debug.js +10 -0
- package/dist/cjs/types/index.js +51 -0
- package/dist/cjs/utils/bytes.js +121 -0
- package/dist/cjs/utils/collection.browser.js +23 -0
- package/dist/cjs/utils/collection.js +59 -0
- package/dist/cjs/utils/collection.node.js +71 -0
- package/dist/cjs/utils/data.browser.js +61 -0
- package/dist/cjs/utils/data.js +45 -0
- package/dist/cjs/utils/error.js +16 -0
- package/dist/cjs/utils/eth.js +199 -0
- package/dist/cjs/utils/expose.js +44 -0
- package/dist/cjs/utils/file.js +38 -0
- package/dist/cjs/utils/hash.js +21 -0
- package/dist/cjs/utils/headers.js +59 -0
- package/dist/cjs/utils/hex.js +150 -0
- package/dist/cjs/utils/http.js +40 -0
- package/dist/cjs/utils/pss.js +18 -0
- package/dist/cjs/utils/reference.js +36 -0
- package/dist/cjs/utils/stamps.js +17 -0
- package/dist/cjs/utils/stream.js +146 -0
- package/dist/cjs/utils/tar.js +25 -0
- package/dist/cjs/utils/type.js +434 -0
- package/dist/cjs/utils/uint64.js +29 -0
- package/dist/cjs/utils/url.js +56 -0
- package/dist/index.browser.min.js +3 -0
- package/dist/index.browser.min.js.LICENSE.txt +50 -0
- package/dist/index.browser.min.js.map +1 -0
- package/dist/{src → mjs}/bee-debug.js +102 -183
- package/dist/{src → mjs}/bee.js +82 -232
- package/dist/{src → mjs}/chunk/bmt.js +4 -10
- package/dist/{src → mjs}/chunk/cac.js +0 -3
- package/dist/{src → mjs}/chunk/signer.js +1 -18
- package/dist/{src → mjs}/chunk/soc.js +17 -29
- package/dist/{src → mjs}/chunk/span.js +2 -5
- package/dist/{src → mjs}/feed/identifier.js +0 -6
- package/dist/{src → mjs}/feed/index.js +24 -27
- package/dist/{src → mjs}/feed/json.js +2 -5
- package/dist/{src → mjs}/feed/retrievable.js +7 -21
- package/dist/{src → mjs}/feed/topic.js +0 -2
- package/dist/{src → mjs}/index.js +2 -2
- package/dist/{src → mjs}/modules/bytes.js +16 -20
- package/dist/{src → mjs}/modules/bzz.js +33 -40
- package/dist/{src → mjs}/modules/chunk.js +11 -13
- package/dist/mjs/modules/debug/balance.js +53 -0
- package/dist/mjs/modules/debug/chequebook.js +135 -0
- package/dist/{src → mjs}/modules/debug/chunk.js +10 -12
- package/dist/mjs/modules/debug/connectivity.js +45 -0
- package/dist/mjs/modules/debug/settlements.js +27 -0
- package/dist/mjs/modules/debug/stake.js +51 -0
- package/dist/mjs/modules/debug/stamps.js +61 -0
- package/dist/mjs/modules/debug/states.js +58 -0
- package/dist/{src → mjs}/modules/debug/status.js +46 -37
- package/dist/mjs/modules/debug/tag.js +15 -0
- package/dist/mjs/modules/debug/transactions.js +59 -0
- package/dist/{src → mjs}/modules/feed.js +15 -21
- package/dist/mjs/modules/pinning.js +56 -0
- package/dist/{src → mjs}/modules/pss.js +7 -10
- package/dist/{src → mjs}/modules/soc.js +6 -7
- package/dist/mjs/modules/status.js +11 -0
- package/dist/mjs/modules/stewardship.js +23 -0
- package/dist/mjs/modules/tag.js +72 -0
- package/dist/mjs/package.json +8 -0
- package/dist/{src → mjs}/types/debug.js +0 -1
- package/dist/{src → mjs}/types/index.js +0 -4
- package/dist/{src → mjs}/utils/bytes.js +8 -17
- package/dist/{src/utils/collection-browser.js → mjs/utils/collection.browser.js} +0 -1
- package/dist/{src → mjs}/utils/collection.js +0 -12
- package/dist/{src/utils/collection-node.js → mjs/utils/collection.node.js} +0 -13
- package/dist/{src → mjs}/utils/data.browser.js +2 -11
- package/dist/{src → mjs}/utils/data.js +0 -7
- package/dist/mjs/utils/error.js +11 -0
- package/dist/{src → mjs}/utils/eth.js +6 -28
- package/dist/{src → mjs}/utils/expose.js +1 -1
- package/dist/{src → mjs}/utils/file.js +4 -9
- package/dist/{src → mjs}/utils/hash.js +0 -1
- package/dist/{src → mjs}/utils/headers.js +5 -13
- package/dist/{src → mjs}/utils/hex.js +6 -25
- package/dist/mjs/utils/http.js +34 -0
- package/dist/{src → mjs}/utils/pss.js +0 -2
- package/dist/{src → mjs}/utils/reference.js +2 -5
- package/dist/{src → mjs}/utils/stream.js +3 -26
- package/dist/{src → mjs}/utils/tar.js +3 -6
- package/dist/{src → mjs}/utils/type.js +23 -80
- package/dist/{src → mjs}/utils/uint64.js +0 -1
- package/dist/{src → mjs}/utils/url.js +2 -10
- package/dist/types/bee-debug.d.ts +71 -46
- package/dist/types/bee.d.ts +34 -58
- package/dist/types/chunk/bmt.d.ts +1 -1
- package/dist/types/chunk/cac.d.ts +1 -1
- package/dist/types/chunk/soc.d.ts +9 -9
- package/dist/types/chunk/span.d.ts +1 -1
- package/dist/types/feed/index.d.ts +10 -10
- package/dist/types/feed/json.d.ts +2 -2
- package/dist/types/feed/retrievable.d.ts +2 -2
- package/dist/types/feed/type.d.ts +1 -1
- package/dist/types/index.d.ts +13 -2
- package/dist/types/modules/bytes.d.ts +5 -5
- package/dist/types/modules/bzz.d.ts +8 -8
- package/dist/types/modules/chunk.d.ts +4 -4
- package/dist/types/modules/debug/balance.d.ts +9 -9
- package/dist/types/modules/debug/chequebook.d.ts +17 -17
- package/dist/types/modules/debug/chunk.d.ts +5 -5
- package/dist/types/modules/debug/connectivity.d.ts +7 -7
- package/dist/types/modules/debug/settlements.d.ts +5 -5
- package/dist/types/modules/debug/stake.d.ts +21 -0
- package/dist/types/modules/debug/stamps.d.ts +7 -7
- package/dist/types/modules/debug/states.d.ts +7 -7
- package/dist/types/modules/debug/status.d.ts +21 -15
- package/dist/types/modules/debug/tag.d.ts +3 -3
- package/dist/types/modules/debug/transactions.d.ts +5 -5
- package/dist/types/modules/feed.d.ts +3 -3
- package/dist/types/modules/pinning.d.ts +7 -7
- package/dist/types/modules/pss.d.ts +3 -3
- package/dist/types/modules/soc.d.ts +2 -2
- package/dist/types/modules/status.d.ts +3 -3
- package/dist/types/modules/stewardship.d.ts +3 -3
- package/dist/types/modules/tag.d.ts +6 -6
- package/dist/types/types/debug.d.ts +35 -2
- package/dist/types/types/index.d.ts +48 -89
- package/dist/types/utils/error.d.ts +0 -26
- package/dist/types/utils/eth.d.ts +6 -6
- package/dist/types/utils/expose.d.ts +4 -7
- package/dist/types/utils/hash.d.ts +1 -1
- package/dist/types/utils/headers.d.ts +1 -1
- package/dist/types/utils/hex.d.ts +4 -4
- package/dist/types/utils/http.d.ts +11 -21
- package/dist/types/utils/stream.d.ts +1 -1
- package/dist/types/utils/type.d.ts +3 -2
- package/dist/types/utils/uint64.d.ts +1 -1
- package/package.json +59 -52
- package/dist/index.browser.js +0 -33
- package/dist/index.browser.js.map +0 -7
- package/dist/src/modules/debug/balance.js +0 -57
- package/dist/src/modules/debug/chequebook.js +0 -150
- package/dist/src/modules/debug/connectivity.js +0 -45
- package/dist/src/modules/debug/settlements.js +0 -29
- package/dist/src/modules/debug/stamps.js +0 -64
- package/dist/src/modules/debug/states.js +0 -46
- package/dist/src/modules/debug/tag.js +0 -16
- package/dist/src/modules/debug/transactions.js +0 -69
- package/dist/src/modules/pinning.js +0 -60
- package/dist/src/modules/status.js +0 -12
- package/dist/src/modules/stewardship.js +0 -24
- package/dist/src/modules/tag.js +0 -77
- package/dist/src/utils/error.js +0 -47
- package/dist/src/utils/http.js +0 -162
- package/dist/src/utils/merge.js +0 -36
- package/dist/src/utils/sleep.js +0 -8
- package/dist/types/utils/merge.d.ts +0 -8
- package/dist/types/utils/sleep.d.ts +0 -6
- /package/dist/{src → mjs}/chunk/serialize.js +0 -0
- /package/dist/{src → mjs}/feed/type.js +0 -0
- /package/dist/{src → mjs}/utils/stamps.js +0 -0
- /package/dist/types/utils/{collection-browser.d.ts → collection.browser.d.ts} +0 -0
- /package/dist/types/utils/{collection-node.d.ts → collection.node.d.ts} +0 -0
|
@@ -23,7 +23,6 @@ const HASH_SIZE = 32;
|
|
|
23
23
|
*
|
|
24
24
|
* @returns the keccak256 hash in a byte array
|
|
25
25
|
*/
|
|
26
|
-
|
|
27
26
|
export function bmtHash(chunkContent) {
|
|
28
27
|
const span = chunkContent.slice(0, 8);
|
|
29
28
|
const payload = chunkContent.slice(8);
|
|
@@ -32,25 +31,20 @@ export function bmtHash(chunkContent) {
|
|
|
32
31
|
const chunkHash = keccak256Hash(chunkHashInput);
|
|
33
32
|
return chunkHash;
|
|
34
33
|
}
|
|
35
|
-
|
|
36
34
|
function bmtRootHash(payload) {
|
|
37
35
|
if (payload.length > MAX_CHUNK_PAYLOAD_SIZE) {
|
|
38
36
|
throw new BeeArgumentError('invalid data length', payload);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
}
|
|
38
|
+
// create an input buffer padded with zeros
|
|
42
39
|
let input = new Uint8Array([...payload, ...new Uint8Array(MAX_CHUNK_PAYLOAD_SIZE - payload.length)]);
|
|
43
|
-
|
|
44
40
|
while (input.length !== HASH_SIZE) {
|
|
45
|
-
const output = new Uint8Array(input.length / 2);
|
|
46
|
-
|
|
41
|
+
const output = new Uint8Array(input.length / 2);
|
|
42
|
+
// in each round we hash the segment pairs together
|
|
47
43
|
for (let offset = 0; offset < input.length; offset += SEGMENT_PAIR_SIZE) {
|
|
48
44
|
const hashNumbers = keccak256.array(input.slice(offset, offset + SEGMENT_PAIR_SIZE));
|
|
49
45
|
output.set(hashNumbers, offset / 2);
|
|
50
46
|
}
|
|
51
|
-
|
|
52
47
|
input = output;
|
|
53
48
|
}
|
|
54
|
-
|
|
55
49
|
return input;
|
|
56
50
|
}
|
|
@@ -12,7 +12,6 @@ const CAC_PAYLOAD_OFFSET = CAC_SPAN_OFFSET + SPAN_SIZE;
|
|
|
12
12
|
*
|
|
13
13
|
* @param payloadBytes the data to be stored in the chunk
|
|
14
14
|
*/
|
|
15
|
-
|
|
16
15
|
export function makeContentAddressedChunk(payloadBytes) {
|
|
17
16
|
const span = makeSpan(payloadBytes.length);
|
|
18
17
|
assertFlexBytes(payloadBytes, MIN_PAYLOAD_SIZE, MAX_PAYLOAD_SIZE);
|
|
@@ -30,7 +29,6 @@ export function makeContentAddressedChunk(payloadBytes) {
|
|
|
30
29
|
* @param data The chunk data
|
|
31
30
|
* @param chunkAddress The address of the chunk
|
|
32
31
|
*/
|
|
33
|
-
|
|
34
32
|
export function isValidChunkData(data, chunkAddress) {
|
|
35
33
|
if (!(data instanceof Uint8Array)) return false;
|
|
36
34
|
const address = bmtHash(data);
|
|
@@ -44,7 +42,6 @@ export function isValidChunkData(data, chunkAddress) {
|
|
|
44
42
|
*
|
|
45
43
|
* @returns a valid content addressed chunk or throws error
|
|
46
44
|
*/
|
|
47
|
-
|
|
48
45
|
export function assertValidChunkData(data, chunkAddress) {
|
|
49
46
|
if (!isValidChunkData(data, chunkAddress)) {
|
|
50
47
|
throw new BeeError('Address of content address chunk does not match given data!');
|
|
@@ -10,7 +10,6 @@ import { hexToBytes, makeHexString } from "../utils/hex.js";
|
|
|
10
10
|
import { SIGNATURE_BYTES_LENGTH, SIGNATURE_HEX_LENGTH } from "../types/index.js";
|
|
11
11
|
import { isStrictlyObject } from "../utils/type.js";
|
|
12
12
|
const UNCOMPRESSED_RECOVERY_ID = 27;
|
|
13
|
-
|
|
14
13
|
function hashWithEthereumPrefix(data) {
|
|
15
14
|
const ethereumSignedMessagePrefix = `\x19Ethereum Signed Message:\n${data.length}`;
|
|
16
15
|
const prefixBytes = new TextEncoder().encode(ethereumSignedMessagePrefix);
|
|
@@ -23,8 +22,6 @@ function hashWithEthereumPrefix(data) {
|
|
|
23
22
|
* @param data The data to be signed
|
|
24
23
|
* @param privateKey The private key used for signing the data
|
|
25
24
|
*/
|
|
26
|
-
|
|
27
|
-
|
|
28
25
|
export function defaultSign(data, privateKey) {
|
|
29
26
|
const curve = new ec('secp256k1');
|
|
30
27
|
const keyPair = curve.keyFromPrivate(privateKey);
|
|
@@ -33,15 +30,12 @@ export function defaultSign(data, privateKey) {
|
|
|
33
30
|
canonical: true,
|
|
34
31
|
pers: undefined
|
|
35
32
|
});
|
|
36
|
-
|
|
37
33
|
if (sigRaw.recoveryParam === null) {
|
|
38
34
|
throw new BeeError('signDigest recovery param was null');
|
|
39
35
|
}
|
|
40
|
-
|
|
41
36
|
const signature = new Uint8Array([...sigRaw.r.toArray('be', 32), ...sigRaw.s.toArray('be', 32), sigRaw.recoveryParam + UNCOMPRESSED_RECOVERY_ID]);
|
|
42
37
|
return signature;
|
|
43
38
|
}
|
|
44
|
-
|
|
45
39
|
function publicKeyToAddress(pubKey) {
|
|
46
40
|
const pubBytes = pubKey.encode('array', false);
|
|
47
41
|
return keccak256Hash(pubBytes.slice(1)).slice(12);
|
|
@@ -57,8 +51,6 @@ function publicKeyToAddress(pubKey) {
|
|
|
57
51
|
*
|
|
58
52
|
* @returns the recovered address
|
|
59
53
|
*/
|
|
60
|
-
|
|
61
|
-
|
|
62
54
|
export function recoverAddress(signature, digest) {
|
|
63
55
|
const curve = new ec('secp256k1');
|
|
64
56
|
const sig = {
|
|
@@ -75,13 +67,12 @@ export function recoverAddress(signature, digest) {
|
|
|
75
67
|
*
|
|
76
68
|
* @param privateKey The private key
|
|
77
69
|
*/
|
|
78
|
-
|
|
79
70
|
export function makePrivateKeySigner(privateKey) {
|
|
80
71
|
const curve = new ec('secp256k1');
|
|
81
72
|
const keyPair = curve.keyFromPrivate(privateKey);
|
|
82
73
|
const address = publicKeyToAddress(keyPair.getPublic());
|
|
83
74
|
return {
|
|
84
|
-
sign: digest => defaultSign(digest
|
|
75
|
+
sign: digest => defaultSign(digest, privateKey),
|
|
85
76
|
address
|
|
86
77
|
};
|
|
87
78
|
}
|
|
@@ -89,13 +80,10 @@ export function assertSigner(signer) {
|
|
|
89
80
|
if (!isStrictlyObject(signer)) {
|
|
90
81
|
throw new TypeError('Signer must be an object!');
|
|
91
82
|
}
|
|
92
|
-
|
|
93
83
|
const typedSigner = signer;
|
|
94
|
-
|
|
95
84
|
if (!isBytes(typedSigner.address, 20)) {
|
|
96
85
|
throw new TypeError("Signer's address must be Uint8Array with 20 bytes!");
|
|
97
86
|
}
|
|
98
|
-
|
|
99
87
|
if (typeof typedSigner.sign !== 'function') {
|
|
100
88
|
throw new TypeError('Signer sign property needs to be function!');
|
|
101
89
|
}
|
|
@@ -104,28 +92,23 @@ export function makeSigner(signer) {
|
|
|
104
92
|
if (typeof signer === 'string') {
|
|
105
93
|
const hexKey = makeHexString(signer, 64);
|
|
106
94
|
const keyBytes = hexToBytes(hexKey); // HexString is verified for 64 length => 32 is guaranteed
|
|
107
|
-
|
|
108
95
|
return makePrivateKeySigner(keyBytes);
|
|
109
96
|
} else if (signer instanceof Uint8Array) {
|
|
110
97
|
assertBytes(signer, 32);
|
|
111
98
|
return makePrivateKeySigner(signer);
|
|
112
99
|
}
|
|
113
|
-
|
|
114
100
|
assertSigner(signer);
|
|
115
101
|
return signer;
|
|
116
102
|
}
|
|
117
103
|
export async function sign(signer, data) {
|
|
118
104
|
const result = await signer.sign(wrapBytesWithHelpers(data));
|
|
119
|
-
|
|
120
105
|
if (typeof result === 'string') {
|
|
121
106
|
const hexString = makeHexString(result, SIGNATURE_HEX_LENGTH);
|
|
122
107
|
return hexToBytes(hexString);
|
|
123
108
|
}
|
|
124
|
-
|
|
125
109
|
if (result instanceof Uint8Array) {
|
|
126
110
|
assertBytes(result, SIGNATURE_BYTES_LENGTH);
|
|
127
111
|
return result;
|
|
128
112
|
}
|
|
129
|
-
|
|
130
113
|
throw new TypeError('Invalid output of sign function!');
|
|
131
114
|
}
|
|
@@ -1,22 +1,21 @@
|
|
|
1
|
+
import * as chunkAPI from "../modules/chunk.js";
|
|
2
|
+
import * as socAPI from "../modules/soc.js";
|
|
1
3
|
import { bytesAtOffset, bytesEqual, flexBytesAtOffset } from "../utils/bytes.js";
|
|
2
|
-
import { bmtHash } from "./bmt.js";
|
|
3
|
-
import { recoverAddress, sign } from "./signer.js";
|
|
4
|
-
import { keccak256Hash } from "../utils/hash.js";
|
|
5
|
-
import { SPAN_SIZE } from "./span.js";
|
|
6
|
-
import { serializeBytes } from "./serialize.js";
|
|
7
4
|
import { BeeError } from "../utils/error.js";
|
|
8
|
-
import {
|
|
5
|
+
import { keccak256Hash } from "../utils/hash.js";
|
|
9
6
|
import { bytesToHex } from "../utils/hex.js";
|
|
10
|
-
import * as socAPI from "../modules/soc.js";
|
|
11
|
-
import * as chunkAPI from "../modules/chunk.js";
|
|
12
7
|
import { assertAddress } from "../utils/type.js";
|
|
8
|
+
import { bmtHash } from "./bmt.js";
|
|
9
|
+
import { assertValidChunkData, makeContentAddressedChunk, MAX_PAYLOAD_SIZE, MIN_PAYLOAD_SIZE } from "./cac.js";
|
|
10
|
+
import { serializeBytes } from "./serialize.js";
|
|
11
|
+
import { recoverAddress, sign } from "./signer.js";
|
|
12
|
+
import { SPAN_SIZE } from "./span.js";
|
|
13
13
|
const IDENTIFIER_SIZE = 32;
|
|
14
14
|
const SIGNATURE_SIZE = 65;
|
|
15
15
|
const SOC_IDENTIFIER_OFFSET = 0;
|
|
16
16
|
const SOC_SIGNATURE_OFFSET = SOC_IDENTIFIER_OFFSET + IDENTIFIER_SIZE;
|
|
17
17
|
const SOC_SPAN_OFFSET = SOC_SIGNATURE_OFFSET + SIGNATURE_SIZE;
|
|
18
18
|
const SOC_PAYLOAD_OFFSET = SOC_SPAN_OFFSET + SPAN_SIZE;
|
|
19
|
-
|
|
20
19
|
function recoverChunkOwner(data) {
|
|
21
20
|
const cacData = data.slice(SOC_SPAN_OFFSET);
|
|
22
21
|
const chunkAddress = bmtHash(cacData);
|
|
@@ -34,23 +33,16 @@ function recoverChunkOwner(data) {
|
|
|
34
33
|
*
|
|
35
34
|
* @returns a single owner chunk or throws error
|
|
36
35
|
*/
|
|
37
|
-
|
|
38
|
-
|
|
39
36
|
export function makeSingleOwnerChunkFromData(data, address) {
|
|
40
37
|
const ownerAddress = recoverChunkOwner(data);
|
|
41
38
|
const identifier = bytesAtOffset(data, SOC_IDENTIFIER_OFFSET, IDENTIFIER_SIZE);
|
|
42
39
|
const socAddress = keccak256Hash(identifier, ownerAddress);
|
|
43
|
-
|
|
44
40
|
if (!bytesEqual(address, socAddress)) {
|
|
45
41
|
throw new BeeError('SOC Data does not match given address!');
|
|
46
42
|
}
|
|
47
|
-
|
|
48
43
|
const signature = () => bytesAtOffset(data, SOC_SIGNATURE_OFFSET, SIGNATURE_SIZE);
|
|
49
|
-
|
|
50
44
|
const span = () => bytesAtOffset(data, SOC_SPAN_OFFSET, SPAN_SIZE);
|
|
51
|
-
|
|
52
45
|
const payload = () => flexBytesAtOffset(data, SOC_PAYLOAD_OFFSET, MIN_PAYLOAD_SIZE, MAX_PAYLOAD_SIZE);
|
|
53
|
-
|
|
54
46
|
return {
|
|
55
47
|
data,
|
|
56
48
|
identifier: () => identifier,
|
|
@@ -71,7 +63,6 @@ export function makeSOCAddress(identifier, address) {
|
|
|
71
63
|
* @param identifier The identifier of the chunk
|
|
72
64
|
* @param signer The singer interface for signing the chunk
|
|
73
65
|
*/
|
|
74
|
-
|
|
75
66
|
export async function makeSingleOwnerChunk(chunk, identifier, signer) {
|
|
76
67
|
const chunkAddress = chunk.address();
|
|
77
68
|
assertValidChunkData(chunk.data, chunkAddress);
|
|
@@ -94,35 +85,33 @@ export async function makeSingleOwnerChunk(chunk, identifier, signer) {
|
|
|
94
85
|
*
|
|
95
86
|
* It uses the Chunk API and calculates the address before uploading.
|
|
96
87
|
*
|
|
97
|
-
* @param
|
|
88
|
+
* @param kyOptions Ky Options for making requests
|
|
98
89
|
* @param chunk A chunk object
|
|
99
90
|
* @param postageBatchId Postage BatchId that will be assigned to uploaded data
|
|
100
91
|
* @param options Upload options
|
|
101
92
|
*/
|
|
102
|
-
|
|
103
|
-
export async function uploadSingleOwnerChunk(ky, chunk, postageBatchId, options) {
|
|
93
|
+
export async function uploadSingleOwnerChunk(requestOptions, chunk, postageBatchId, options) {
|
|
104
94
|
const owner = bytesToHex(chunk.owner());
|
|
105
95
|
const identifier = bytesToHex(chunk.identifier());
|
|
106
96
|
const signature = bytesToHex(chunk.signature());
|
|
107
97
|
const data = serializeBytes(chunk.span(), chunk.payload());
|
|
108
|
-
return socAPI.upload(
|
|
98
|
+
return socAPI.upload(requestOptions, owner, identifier, signature, data, postageBatchId, options);
|
|
109
99
|
}
|
|
110
100
|
/**
|
|
111
101
|
* Helper function to create and upload SOC.
|
|
112
102
|
*
|
|
113
|
-
* @param
|
|
103
|
+
* @param kyOptions Ky Options for making requests
|
|
114
104
|
* @param signer The singer interface for signing the chunk
|
|
115
105
|
* @param postageBatchId
|
|
116
106
|
* @param identifier The identifier of the chunk
|
|
117
107
|
* @param data The chunk data
|
|
118
108
|
* @param options
|
|
119
109
|
*/
|
|
120
|
-
|
|
121
|
-
export async function uploadSingleOwnerChunkData(ky, signer, postageBatchId, identifier, data, options) {
|
|
110
|
+
export async function uploadSingleOwnerChunkData(requestOptions, signer, postageBatchId, identifier, data, options) {
|
|
122
111
|
assertAddress(postageBatchId);
|
|
123
112
|
const cac = makeContentAddressedChunk(data);
|
|
124
113
|
const soc = await makeSingleOwnerChunk(cac, identifier, signer);
|
|
125
|
-
return uploadSingleOwnerChunk(
|
|
114
|
+
return uploadSingleOwnerChunk(requestOptions, soc, postageBatchId, options);
|
|
126
115
|
}
|
|
127
116
|
/**
|
|
128
117
|
* Helper function to download SOC.
|
|
@@ -131,9 +120,8 @@ export async function uploadSingleOwnerChunkData(ky, signer, postageBatchId, ide
|
|
|
131
120
|
* @param ownerAddress The singer interface for signing the chunk
|
|
132
121
|
* @param identifier The identifier of the chunk
|
|
133
122
|
*/
|
|
134
|
-
|
|
135
|
-
export async function downloadSingleOwnerChunk(ky, ownerAddress, identifier) {
|
|
123
|
+
export async function downloadSingleOwnerChunk(requestOptions, ownerAddress, identifier) {
|
|
136
124
|
const address = makeSOCAddress(identifier, ownerAddress);
|
|
137
|
-
const data = await chunkAPI.download(
|
|
138
|
-
return makeSingleOwnerChunkFromData(data
|
|
125
|
+
const data = await chunkAPI.download(requestOptions, bytesToHex(address));
|
|
126
|
+
return makeSingleOwnerChunkFromData(data, address);
|
|
139
127
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BeeArgumentError } from "../utils/error.js";
|
|
2
|
-
export const SPAN_SIZE = 8;
|
|
3
|
-
|
|
2
|
+
export const SPAN_SIZE = 8;
|
|
3
|
+
// we limit the maximum span size in 32 bits to avoid BigInt compatibility issues
|
|
4
4
|
const MAX_SPAN_LENGTH = 2 ** 32 - 1;
|
|
5
5
|
/**
|
|
6
6
|
* Create a span for storing the length of the chunk
|
|
@@ -9,16 +9,13 @@ const MAX_SPAN_LENGTH = 2 ** 32 - 1;
|
|
|
9
9
|
*
|
|
10
10
|
* @param length The length of the span
|
|
11
11
|
*/
|
|
12
|
-
|
|
13
12
|
export function makeSpan(length) {
|
|
14
13
|
if (length <= 0) {
|
|
15
14
|
throw new BeeArgumentError('invalid length for span', length);
|
|
16
15
|
}
|
|
17
|
-
|
|
18
16
|
if (length > MAX_SPAN_LENGTH) {
|
|
19
17
|
throw new BeeArgumentError('invalid length (> MAX_SPAN_LENGTH)', length);
|
|
20
18
|
}
|
|
21
|
-
|
|
22
19
|
const span = new Uint8Array(SPAN_SIZE);
|
|
23
20
|
const dataView = new DataView(span.buffer);
|
|
24
21
|
const littleEndian = true;
|
|
@@ -2,25 +2,20 @@ import { FEED_INDEX_HEX_LENGTH } from "../types/index.js";
|
|
|
2
2
|
import { keccak256Hash } from "../utils/hash.js";
|
|
3
3
|
import { hexToBytes, makeHexString } from "../utils/hex.js";
|
|
4
4
|
import { writeUint64BigEndian } from "../utils/uint64.js";
|
|
5
|
-
|
|
6
5
|
function isEpoch(epoch) {
|
|
7
6
|
return typeof epoch === 'object' && epoch !== null && 'time' in epoch && 'level' in epoch;
|
|
8
7
|
}
|
|
9
|
-
|
|
10
8
|
function hashFeedIdentifier(topic, index) {
|
|
11
9
|
return keccak256Hash(hexToBytes(topic), index);
|
|
12
10
|
}
|
|
13
|
-
|
|
14
11
|
function makeSequentialFeedIdentifier(topic, index) {
|
|
15
12
|
const indexBytes = writeUint64BigEndian(index);
|
|
16
13
|
return hashFeedIdentifier(topic, indexBytes);
|
|
17
14
|
}
|
|
18
|
-
|
|
19
15
|
function makeFeedIndexBytes(s) {
|
|
20
16
|
const hex = makeHexString(s, FEED_INDEX_HEX_LENGTH);
|
|
21
17
|
return hexToBytes(hex);
|
|
22
18
|
}
|
|
23
|
-
|
|
24
19
|
export function makeFeedIdentifier(topic, index) {
|
|
25
20
|
if (typeof index === 'number') {
|
|
26
21
|
return makeSequentialFeedIdentifier(topic, index);
|
|
@@ -30,6 +25,5 @@ export function makeFeedIdentifier(topic, index) {
|
|
|
30
25
|
} else if (isEpoch(index)) {
|
|
31
26
|
throw new TypeError('epoch is not yet implemented');
|
|
32
27
|
}
|
|
33
|
-
|
|
34
28
|
return hashFeedIdentifier(topic, index);
|
|
35
29
|
}
|
|
@@ -1,50 +1,48 @@
|
|
|
1
|
-
import { keccak256Hash } from "../utils/hash.js";
|
|
2
1
|
import { serializeBytes } from "../chunk/serialize.js";
|
|
3
|
-
import { fetchLatestFeedUpdate } from "../modules/feed.js";
|
|
4
2
|
import { makeSingleOwnerChunkFromData, uploadSingleOwnerChunkData } from "../chunk/soc.js";
|
|
3
|
+
import * as chunkAPI from "../modules/chunk.js";
|
|
4
|
+
import { fetchLatestFeedUpdate } from "../modules/feed.js";
|
|
5
5
|
import { FEED_INDEX_HEX_LENGTH } from "../types/index.js";
|
|
6
6
|
import { bytesAtOffset, makeBytes } from "../utils/bytes.js";
|
|
7
|
-
import { BeeResponseError } from "../utils/error.js";
|
|
8
|
-
import { bytesToHex, hexToBytes, makeHexString } from "../utils/hex.js";
|
|
9
|
-
import { readUint64BigEndian, writeUint64BigEndian } from "../utils/uint64.js";
|
|
10
|
-
import * as chunkAPI from "../modules/chunk.js";
|
|
11
7
|
import { makeHexEthAddress } from "../utils/eth.js";
|
|
8
|
+
import { keccak256Hash } from "../utils/hash.js";
|
|
9
|
+
import { bytesToHex, hexToBytes, makeHexString } from "../utils/hex.js";
|
|
10
|
+
import { makeBytesReference } from "../utils/reference.js";
|
|
12
11
|
import { assertAddress } from "../utils/type.js";
|
|
12
|
+
import { readUint64BigEndian, writeUint64BigEndian } from "../utils/uint64.js";
|
|
13
13
|
import { makeFeedIdentifier } from "./identifier.js";
|
|
14
|
-
import { makeBytesReference } from "../utils/reference.js";
|
|
15
14
|
const TIMESTAMP_PAYLOAD_OFFSET = 0;
|
|
16
15
|
const TIMESTAMP_PAYLOAD_SIZE = 8;
|
|
17
16
|
const REFERENCE_PAYLOAD_OFFSET = TIMESTAMP_PAYLOAD_SIZE;
|
|
18
|
-
export async function findNextIndex(
|
|
17
|
+
export async function findNextIndex(requestOptions, owner, topic, options) {
|
|
19
18
|
try {
|
|
20
|
-
const feedUpdate = await fetchLatestFeedUpdate(
|
|
19
|
+
const feedUpdate = await fetchLatestFeedUpdate(requestOptions, owner, topic, options);
|
|
21
20
|
return makeHexString(feedUpdate.feedIndexNext, FEED_INDEX_HEX_LENGTH);
|
|
22
21
|
} catch (e) {
|
|
23
|
-
if (e
|
|
22
|
+
if (e?.response?.status === 404) {
|
|
24
23
|
return bytesToHex(makeBytes(8));
|
|
25
24
|
}
|
|
26
|
-
|
|
27
25
|
throw e;
|
|
28
26
|
}
|
|
29
27
|
}
|
|
30
|
-
export async function updateFeed(
|
|
28
|
+
export async function updateFeed(requestOptions, signer, topic, reference, postageBatchId, options, index = 'latest') {
|
|
31
29
|
const ownerHex = makeHexEthAddress(signer.address);
|
|
32
|
-
const nextIndex = index === 'latest' ? await findNextIndex(
|
|
30
|
+
const nextIndex = index === 'latest' ? await findNextIndex(requestOptions, ownerHex, topic, options) : index;
|
|
33
31
|
const identifier = makeFeedIdentifier(topic, nextIndex);
|
|
34
32
|
const at = options?.at ?? Date.now() / 1000.0;
|
|
35
33
|
const timestamp = writeUint64BigEndian(at);
|
|
36
34
|
const payloadBytes = serializeBytes(timestamp, reference);
|
|
37
|
-
return uploadSingleOwnerChunkData(
|
|
35
|
+
return uploadSingleOwnerChunkData(requestOptions, signer, postageBatchId, identifier, payloadBytes, options);
|
|
38
36
|
}
|
|
39
37
|
export function getFeedUpdateChunkReference(owner, topic, index) {
|
|
40
38
|
const identifier = makeFeedIdentifier(topic, index);
|
|
41
39
|
return keccak256Hash(identifier, owner);
|
|
42
40
|
}
|
|
43
|
-
export async function downloadFeedUpdate(
|
|
41
|
+
export async function downloadFeedUpdate(requestOptions, owner, topic, index) {
|
|
44
42
|
const address = getFeedUpdateChunkReference(owner, topic, index);
|
|
45
43
|
const addressHex = bytesToHex(address);
|
|
46
|
-
const data = await chunkAPI.download(
|
|
47
|
-
const soc = makeSingleOwnerChunkFromData(data
|
|
44
|
+
const data = await chunkAPI.download(requestOptions, addressHex);
|
|
45
|
+
const soc = makeSingleOwnerChunkFromData(data, address);
|
|
48
46
|
const payload = soc.payload();
|
|
49
47
|
const timestampBytes = bytesAtOffset(payload, TIMESTAMP_PAYLOAD_OFFSET, TIMESTAMP_PAYLOAD_SIZE);
|
|
50
48
|
const timestamp = readUint64BigEndian(timestampBytes);
|
|
@@ -54,39 +52,38 @@ export async function downloadFeedUpdate(ky, owner, topic, index) {
|
|
|
54
52
|
reference
|
|
55
53
|
};
|
|
56
54
|
}
|
|
57
|
-
export function makeFeedReader(
|
|
55
|
+
export function makeFeedReader(requestOptions, type, topic, owner) {
|
|
58
56
|
return {
|
|
59
57
|
type,
|
|
60
58
|
owner,
|
|
61
59
|
topic,
|
|
62
|
-
|
|
63
60
|
async download(options) {
|
|
64
61
|
if (!options?.index) {
|
|
65
|
-
return fetchLatestFeedUpdate(
|
|
62
|
+
return fetchLatestFeedUpdate(requestOptions, owner, topic, {
|
|
63
|
+
...options,
|
|
66
64
|
type
|
|
67
65
|
});
|
|
68
66
|
}
|
|
69
|
-
|
|
70
|
-
const update = await downloadFeedUpdate(ky, hexToBytes(owner), topic, options.index);
|
|
67
|
+
const update = await downloadFeedUpdate(requestOptions, hexToBytes(owner), topic, options.index);
|
|
71
68
|
return {
|
|
72
69
|
reference: bytesToHex(update.reference),
|
|
73
70
|
feedIndex: options.index,
|
|
74
71
|
feedIndexNext: ''
|
|
75
72
|
};
|
|
76
73
|
}
|
|
77
|
-
|
|
78
74
|
};
|
|
79
75
|
}
|
|
80
|
-
export function makeFeedWriter(
|
|
76
|
+
export function makeFeedWriter(requestOptions, type, topic, signer) {
|
|
81
77
|
const upload = async (postageBatchId, reference, options) => {
|
|
82
78
|
assertAddress(postageBatchId);
|
|
83
79
|
const canonicalReference = makeBytesReference(reference);
|
|
84
|
-
return updateFeed(
|
|
80
|
+
return updateFeed(requestOptions, signer, topic, canonicalReference, postageBatchId, {
|
|
81
|
+
...options,
|
|
85
82
|
type
|
|
86
83
|
});
|
|
87
84
|
};
|
|
88
|
-
|
|
89
|
-
|
|
85
|
+
return {
|
|
86
|
+
...makeFeedReader(requestOptions, type, topic, makeHexEthAddress(signer.address)),
|
|
90
87
|
upload
|
|
91
88
|
};
|
|
92
89
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { isError } from "../utils/type.js";
|
|
2
|
-
|
|
3
2
|
function serializeJson(data) {
|
|
4
3
|
try {
|
|
5
4
|
const jsonString = JSON.stringify(data);
|
|
@@ -8,20 +7,18 @@ function serializeJson(data) {
|
|
|
8
7
|
if (isError(e)) {
|
|
9
8
|
e.message = `JsonFeed: ${e.message}`;
|
|
10
9
|
}
|
|
11
|
-
|
|
12
10
|
throw e;
|
|
13
11
|
}
|
|
14
12
|
}
|
|
15
|
-
|
|
16
13
|
export async function getJsonData(bee, reader) {
|
|
17
14
|
const feedUpdate = await reader.download();
|
|
18
15
|
const retrievedData = await bee.downloadData(feedUpdate.reference);
|
|
19
16
|
return retrievedData.json();
|
|
20
17
|
}
|
|
21
|
-
export async function setJsonData(bee, writer, postageBatchId, data, options) {
|
|
18
|
+
export async function setJsonData(bee, writer, postageBatchId, data, options, requestOptions) {
|
|
22
19
|
const serializedData = serializeJson(data);
|
|
23
20
|
const {
|
|
24
21
|
reference
|
|
25
|
-
} = await bee.uploadData(postageBatchId, serializedData, options);
|
|
22
|
+
} = await bee.uploadData(postageBatchId, serializedData, options, requestOptions);
|
|
26
23
|
return writer.upload(postageBatchId, reference);
|
|
27
24
|
}
|
|
@@ -1,20 +1,16 @@
|
|
|
1
|
-
import { getFeedUpdateChunkReference } from "./index.js";
|
|
2
|
-
import { readUint64BigEndian } from "../utils/uint64.js";
|
|
3
1
|
import { bytesToHex } from "../utils/hex.js";
|
|
4
|
-
|
|
2
|
+
import { readUint64BigEndian } from "../utils/uint64.js";
|
|
3
|
+
import { getFeedUpdateChunkReference } from "./index.js";
|
|
5
4
|
function makeNumericIndex(index) {
|
|
6
5
|
if (index instanceof Uint8Array) {
|
|
7
6
|
return readUint64BigEndian(index);
|
|
8
7
|
}
|
|
9
|
-
|
|
10
8
|
if (typeof index === 'string') {
|
|
11
9
|
return parseInt(index);
|
|
12
10
|
}
|
|
13
|
-
|
|
14
11
|
if (typeof index === 'number') {
|
|
15
12
|
return index;
|
|
16
13
|
}
|
|
17
|
-
|
|
18
14
|
throw new TypeError('Unknown type of index!');
|
|
19
15
|
}
|
|
20
16
|
/**
|
|
@@ -25,19 +21,14 @@ function makeNumericIndex(index) {
|
|
|
25
21
|
* @param ref
|
|
26
22
|
* @param options
|
|
27
23
|
*/
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
async function isChunkRetrievable(bee, ref, options) {
|
|
24
|
+
async function isChunkRetrievable(bee, ref, requestOptions) {
|
|
31
25
|
try {
|
|
32
|
-
await bee.downloadChunk(ref,
|
|
26
|
+
await bee.downloadChunk(ref, requestOptions);
|
|
33
27
|
return true;
|
|
34
28
|
} catch (e) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (err.status === 404) {
|
|
29
|
+
if (e?.response?.status === 404) {
|
|
38
30
|
return false;
|
|
39
31
|
}
|
|
40
|
-
|
|
41
32
|
throw e;
|
|
42
33
|
}
|
|
43
34
|
}
|
|
@@ -48,20 +39,15 @@ async function isChunkRetrievable(bee, ref, options) {
|
|
|
48
39
|
* @param topic
|
|
49
40
|
* @param index
|
|
50
41
|
*/
|
|
51
|
-
|
|
52
|
-
|
|
53
42
|
function getAllSequenceUpdateReferences(owner, topic, index) {
|
|
54
43
|
const numIndex = makeNumericIndex(index);
|
|
55
44
|
const updateReferences = new Array(numIndex + 1);
|
|
56
|
-
|
|
57
45
|
for (let i = 0; i <= numIndex; i++) {
|
|
58
46
|
updateReferences[i] = bytesToHex(getFeedUpdateChunkReference(owner, topic, i));
|
|
59
47
|
}
|
|
60
|
-
|
|
61
48
|
return updateReferences;
|
|
62
49
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const chunkRetrievablePromises = getAllSequenceUpdateReferences(owner, topic, index).map(async ref => isChunkRetrievable(bee, ref, options));
|
|
50
|
+
export async function areAllSequentialFeedsUpdateRetrievable(bee, owner, topic, index, requestOptions) {
|
|
51
|
+
const chunkRetrievablePromises = getAllSequenceUpdateReferences(owner, topic, index).map(async ref => isChunkRetrievable(bee, ref, requestOptions));
|
|
66
52
|
return (await Promise.all(chunkRetrievablePromises)).every(result => result);
|
|
67
53
|
}
|
|
@@ -9,13 +9,11 @@ export function makeTopic(topic) {
|
|
|
9
9
|
assertBytes(topic, TOPIC_BYTES_LENGTH);
|
|
10
10
|
return bytesToHex(topic, TOPIC_HEX_LENGTH);
|
|
11
11
|
}
|
|
12
|
-
|
|
13
12
|
throw new TypeError('invalid topic');
|
|
14
13
|
}
|
|
15
14
|
export function makeTopicFromString(s) {
|
|
16
15
|
if (typeof s !== 'string') {
|
|
17
16
|
throw new TypeError('topic has to be string!');
|
|
18
17
|
}
|
|
19
|
-
|
|
20
18
|
return bytesToHex(keccak256Hash(s), TOPIC_HEX_LENGTH);
|
|
21
19
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Bee } from "./bee.js";
|
|
2
2
|
import { BeeDebug } from "./bee-debug.js";
|
|
3
|
-
export
|
|
3
|
+
export { SUPPORTED_BEE_VERSION, SUPPORTED_BEE_VERSION_EXACT } from "./modules/debug/status.js";
|
|
4
4
|
export * from "./types/index.js";
|
|
5
5
|
export * from "./utils/error.js";
|
|
6
|
-
export
|
|
6
|
+
export * as Utils from "./utils/expose.js";
|
|
7
7
|
export { Bee, BeeDebug };
|
|
@@ -1,32 +1,30 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { wrapBytesWithHelpers } from "../utils/bytes.js";
|
|
2
2
|
import { extractUploadHeaders } from "../utils/headers.js";
|
|
3
3
|
import { http } from "../utils/http.js";
|
|
4
|
-
import { wrapBytesWithHelpers } from "../utils/bytes.js";
|
|
5
4
|
import { makeTagUid } from "../utils/type.js";
|
|
6
5
|
const endpoint = 'bytes';
|
|
7
6
|
/**
|
|
8
7
|
* Upload data to a Bee node
|
|
9
8
|
*
|
|
10
|
-
* @param
|
|
9
|
+
* @param kyOptions Ky Options for making requests
|
|
11
10
|
* @param data Data to be uploaded
|
|
12
11
|
* @param postageBatchId Postage BatchId that will be assigned to uploaded data
|
|
13
12
|
* @param options Additional options like tag, encryption, pinning
|
|
14
13
|
*/
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
path: endpoint,
|
|
14
|
+
export async function upload(requestOptions, data, postageBatchId, options) {
|
|
15
|
+
const response = await http(requestOptions, {
|
|
16
|
+
url: endpoint,
|
|
19
17
|
method: 'post',
|
|
20
18
|
responseType: 'json',
|
|
21
|
-
|
|
19
|
+
data,
|
|
22
20
|
headers: {
|
|
23
21
|
'content-type': 'application/octet-stream',
|
|
24
22
|
...extractUploadHeaders(postageBatchId, options)
|
|
25
23
|
}
|
|
26
24
|
});
|
|
27
25
|
return {
|
|
28
|
-
reference: response.
|
|
29
|
-
tagUid: makeTagUid(response.headers
|
|
26
|
+
reference: response.data.reference,
|
|
27
|
+
tagUid: makeTagUid(response.headers['swarm-tag'])
|
|
30
28
|
};
|
|
31
29
|
}
|
|
32
30
|
/**
|
|
@@ -35,13 +33,12 @@ export async function upload(ky, data, postageBatchId, options) {
|
|
|
35
33
|
* @param ky
|
|
36
34
|
* @param hash Bee content reference
|
|
37
35
|
*/
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const response = await http(ky, {
|
|
36
|
+
export async function download(requestOptions, hash) {
|
|
37
|
+
const response = await http(requestOptions, {
|
|
41
38
|
responseType: 'arraybuffer',
|
|
42
|
-
|
|
39
|
+
url: `${endpoint}/${hash}`
|
|
43
40
|
});
|
|
44
|
-
return wrapBytesWithHelpers(new Uint8Array(response.
|
|
41
|
+
return wrapBytesWithHelpers(new Uint8Array(response.data));
|
|
45
42
|
}
|
|
46
43
|
/**
|
|
47
44
|
* Download data as a readable stream
|
|
@@ -49,11 +46,10 @@ export async function download(ky, hash) {
|
|
|
49
46
|
* @param ky
|
|
50
47
|
* @param hash Bee content reference
|
|
51
48
|
*/
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const response = await http(ky, {
|
|
49
|
+
export async function downloadReadable(requestOptions, hash) {
|
|
50
|
+
const response = await http(requestOptions, {
|
|
55
51
|
responseType: 'stream',
|
|
56
|
-
|
|
52
|
+
url: `${endpoint}/${hash}`
|
|
57
53
|
});
|
|
58
|
-
return response.
|
|
54
|
+
return response.data;
|
|
59
55
|
}
|