@ethersphere/bee-js 3.2.0 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/bee-debug.js +615 -0
- package/dist/cjs/bee.js +922 -0
- package/dist/cjs/chunk/bmt.js +50 -0
- package/dist/cjs/chunk/cac.js +56 -0
- package/dist/cjs/chunk/serialize.js +19 -0
- package/dist/cjs/chunk/signer.js +132 -0
- package/dist/cjs/chunk/soc.js +172 -0
- package/dist/cjs/chunk/span.js +29 -0
- package/dist/cjs/feed/index.js +184 -0
- package/dist/cjs/feed/json.js +41 -0
- package/dist/cjs/feed/topic.js +25 -0
- package/dist/cjs/feed/type.js +15 -0
- package/dist/cjs/index.js +35 -0
- package/dist/cjs/modules/bytes.js +74 -0
- package/dist/cjs/modules/bzz.js +131 -0
- package/dist/cjs/modules/chunk.js +58 -0
- package/dist/cjs/modules/debug/balance.js +77 -0
- package/dist/cjs/modules/debug/chequebook.js +167 -0
- package/dist/cjs/modules/debug/chunk.js +51 -0
- package/dist/cjs/modules/debug/connectivity.js +75 -0
- package/dist/cjs/modules/debug/settlements.js +45 -0
- package/dist/cjs/modules/debug/stamps.js +89 -0
- package/dist/cjs/modules/debug/states.js +47 -0
- package/dist/cjs/modules/debug/status.js +153 -0
- package/dist/cjs/modules/debug/tag.js +30 -0
- package/dist/cjs/modules/debug/transactions.js +81 -0
- package/dist/cjs/modules/feed.js +76 -0
- package/dist/cjs/modules/pinning.js +84 -0
- package/dist/cjs/modules/pss.js +55 -0
- package/dist/cjs/modules/soc.js +40 -0
- package/dist/cjs/modules/status.js +26 -0
- package/dist/cjs/modules/stewardship.js +41 -0
- package/dist/cjs/modules/tag.js +96 -0
- package/dist/cjs/package.json +7 -0
- package/dist/cjs/types/debug.js +9 -0
- package/dist/cjs/types/index.js +46 -0
- package/dist/cjs/utils/bytes.js +107 -0
- package/dist/cjs/utils/collection.browser.js +36 -0
- package/dist/cjs/utils/collection.js +70 -0
- package/dist/cjs/utils/collection.node.js +115 -0
- package/dist/cjs/utils/data.browser.js +78 -0
- package/dist/cjs/utils/data.js +60 -0
- package/dist/cjs/utils/error.js +50 -0
- package/dist/cjs/utils/eth.js +206 -0
- package/dist/cjs/utils/expose.js +44 -0
- package/dist/cjs/utils/file.js +49 -0
- package/dist/cjs/utils/hash.js +16 -0
- package/dist/cjs/utils/headers.js +59 -0
- package/dist/cjs/utils/hex.js +150 -0
- package/dist/cjs/utils/http.js +166 -0
- package/dist/cjs/utils/merge.js +34 -0
- package/dist/cjs/utils/pss.js +18 -0
- package/dist/cjs/utils/stamps.js +17 -0
- package/dist/cjs/utils/stream.js +137 -0
- package/dist/cjs/utils/tar.js +25 -0
- package/dist/cjs/utils/type.js +327 -0
- package/dist/cjs/utils/uint64.js +29 -0
- package/dist/cjs/utils/url.js +56 -0
- package/dist/index.js +28326 -0
- package/dist/index.js.map +1 -0
- package/dist/mjs/bee-debug.js +509 -0
- package/dist/mjs/bee.js +845 -0
- package/dist/mjs/chunk/bmt.js +46 -0
- package/dist/mjs/chunk/cac.js +50 -0
- package/dist/mjs/chunk/serialize.js +15 -0
- package/dist/mjs/chunk/signer.js +112 -0
- package/dist/mjs/chunk/soc.js +127 -0
- package/dist/mjs/chunk/span.js +25 -0
- package/dist/mjs/feed/index.js +136 -0
- package/dist/mjs/feed/json.js +23 -0
- package/dist/mjs/feed/topic.js +20 -0
- package/dist/mjs/feed/type.js +10 -0
- package/dist/mjs/index.js +7 -0
- package/dist/mjs/modules/bytes.js +56 -0
- package/dist/mjs/modules/bzz.js +119 -0
- package/dist/mjs/modules/chunk.js +43 -0
- package/dist/mjs/modules/debug/balance.js +53 -0
- package/dist/mjs/modules/debug/chequebook.js +131 -0
- package/dist/mjs/modules/debug/chunk.js +33 -0
- package/dist/mjs/modules/debug/connectivity.js +45 -0
- package/dist/mjs/modules/debug/settlements.js +27 -0
- package/dist/mjs/modules/debug/stamps.js +59 -0
- package/dist/mjs/modules/debug/states.js +29 -0
- package/dist/mjs/modules/debug/status.js +114 -0
- package/dist/mjs/modules/debug/tag.js +15 -0
- package/dist/mjs/modules/debug/transactions.js +57 -0
- package/dist/mjs/modules/feed.js +61 -0
- package/dist/mjs/modules/pinning.js +60 -0
- package/dist/mjs/modules/pss.js +36 -0
- package/dist/mjs/modules/soc.js +28 -0
- package/dist/mjs/modules/status.js +11 -0
- package/dist/mjs/modules/stewardship.js +23 -0
- package/dist/mjs/modules/tag.js +69 -0
- package/dist/mjs/package.json +7 -0
- package/dist/mjs/types/debug.js +6 -0
- package/dist/mjs/types/index.js +33 -0
- package/dist/mjs/utils/bytes.js +95 -0
- package/dist/mjs/utils/collection.browser.js +18 -0
- package/dist/mjs/utils/collection.js +52 -0
- package/dist/mjs/utils/collection.node.js +63 -0
- package/dist/mjs/utils/data.browser.js +57 -0
- package/dist/mjs/utils/data.js +39 -0
- package/dist/mjs/utils/error.js +48 -0
- package/dist/mjs/utils/eth.js +184 -0
- package/dist/mjs/utils/expose.js +9 -0
- package/dist/mjs/utils/file.js +33 -0
- package/dist/mjs/utils/hash.js +12 -0
- package/dist/mjs/utils/headers.js +54 -0
- package/dist/mjs/utils/hex.js +139 -0
- package/dist/mjs/utils/http.js +136 -0
- package/dist/mjs/utils/merge.js +30 -0
- package/dist/mjs/utils/pss.js +14 -0
- package/dist/mjs/utils/stamps.js +13 -0
- package/dist/mjs/utils/stream.js +131 -0
- package/dist/mjs/utils/tar.js +18 -0
- package/dist/mjs/utils/type.js +296 -0
- package/dist/mjs/utils/uint64.js +23 -0
- package/dist/mjs/utils/url.js +50 -0
- package/dist/{src → types}/bee-debug.d.ts +47 -1
- package/dist/{src → types}/bee.d.ts +0 -0
- package/dist/{src → types}/chunk/bmt.d.ts +0 -0
- package/dist/{src → types}/chunk/cac.d.ts +0 -0
- package/dist/{src → types}/chunk/serialize.d.ts +0 -0
- package/dist/{src → types}/chunk/signer.d.ts +0 -0
- package/dist/{src → types}/chunk/soc.d.ts +0 -0
- package/dist/{src → types}/chunk/span.d.ts +0 -0
- package/dist/{src → types}/feed/index.d.ts +0 -0
- package/dist/{src → types}/feed/json.d.ts +0 -0
- package/dist/{src → types}/feed/topic.d.ts +0 -0
- package/dist/{src → types}/feed/type.d.ts +0 -0
- package/dist/{src → types}/index.d.ts +0 -0
- package/dist/{src → types}/modules/bytes.d.ts +0 -0
- package/dist/{src → types}/modules/bzz.d.ts +0 -0
- package/dist/{src → types}/modules/chunk.d.ts +0 -0
- package/dist/{src → types}/modules/debug/balance.d.ts +0 -0
- package/dist/{src → types}/modules/debug/chequebook.d.ts +0 -0
- package/dist/{src → types}/modules/debug/chunk.d.ts +0 -0
- package/dist/{src → types}/modules/debug/connectivity.d.ts +0 -0
- package/dist/{src → types}/modules/debug/settlements.d.ts +0 -0
- package/dist/{src → types}/modules/debug/stamps.d.ts +0 -0
- package/dist/{src → types}/modules/debug/states.d.ts +0 -0
- package/dist/types/modules/debug/status.d.ts +72 -0
- package/dist/{src → types}/modules/debug/tag.d.ts +0 -0
- package/dist/{src → types}/modules/debug/transactions.d.ts +0 -0
- package/dist/{src → types}/modules/feed.d.ts +0 -0
- package/dist/{src → types}/modules/pinning.d.ts +0 -0
- package/dist/{src → types}/modules/pss.d.ts +0 -0
- package/dist/{src → types}/modules/soc.d.ts +0 -0
- package/dist/{src → types}/modules/status.d.ts +0 -0
- package/dist/{src → types}/modules/stewardship.d.ts +0 -0
- package/dist/{src → types}/modules/tag.d.ts +0 -0
- package/dist/{src → types}/types/debug.d.ts +8 -0
- package/dist/{src → types}/types/index.d.ts +1 -0
- package/dist/{src → types}/utils/bytes.d.ts +0 -0
- package/dist/types/utils/collection.browser.d.ts +15 -0
- package/dist/{src → types}/utils/collection.d.ts +0 -14
- package/dist/types/utils/collection.node.d.ts +15 -0
- package/dist/{src → types}/utils/data.browser.d.ts +0 -0
- package/dist/{src → types}/utils/data.d.ts +0 -0
- package/dist/{src → types}/utils/error.d.ts +0 -0
- package/dist/{src → types}/utils/eth.d.ts +0 -0
- package/dist/{src → types}/utils/expose.d.ts +2 -1
- package/dist/{src → types}/utils/file.d.ts +0 -0
- package/dist/{src → types}/utils/hash.d.ts +0 -0
- package/dist/{src → types}/utils/headers.d.ts +0 -0
- package/dist/{src → types}/utils/hex.d.ts +0 -0
- package/dist/{src → types}/utils/http.d.ts +0 -0
- package/dist/{src → types}/utils/merge.d.ts +0 -0
- package/dist/{src → types}/utils/pss.d.ts +0 -0
- package/dist/{src → types}/utils/stamps.d.ts +0 -0
- package/dist/{src → types}/utils/stream.d.ts +0 -0
- package/dist/{src → types}/utils/tar.d.ts +0 -0
- package/dist/{src → types}/utils/type.d.ts +0 -0
- package/dist/{src → types}/utils/uint64.d.ts +0 -0
- package/dist/{src → types}/utils/url.d.ts +0 -0
- package/package.json +39 -23
- package/dist/index.browser.min.js +0 -3
- package/dist/index.browser.min.js.LICENSE.txt +0 -59
- package/dist/index.browser.min.js.map +0 -1
- package/dist/index.min.js +0 -3
- package/dist/index.min.js.LICENSE.txt +0 -50
- package/dist/index.min.js.map +0 -1
- package/dist/src/modules/debug/status.d.ts +0 -24
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { http } from '../../utils/http';
|
|
2
|
+
const transactionsEndpoint = 'transactions';
|
|
3
|
+
/**
|
|
4
|
+
* Get list of all pending transactions
|
|
5
|
+
*
|
|
6
|
+
* @param ky Debug Ky instance
|
|
7
|
+
*/
|
|
8
|
+
export async function getAllTransactions(ky) {
|
|
9
|
+
const response = await http(ky, {
|
|
10
|
+
path: transactionsEndpoint,
|
|
11
|
+
responseType: 'json',
|
|
12
|
+
});
|
|
13
|
+
return response.data.pendingTransactions;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Get information for specific pending transactions
|
|
17
|
+
*
|
|
18
|
+
* @param ky Debug Ky instance
|
|
19
|
+
* @param transactionHash Hash of the transaction
|
|
20
|
+
*/
|
|
21
|
+
export async function getTransaction(ky, transactionHash) {
|
|
22
|
+
const response = await http(ky, {
|
|
23
|
+
path: `${transactionsEndpoint}/${transactionHash}`,
|
|
24
|
+
responseType: 'json',
|
|
25
|
+
});
|
|
26
|
+
return response.data;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Rebroadcast existing transaction
|
|
30
|
+
*
|
|
31
|
+
* @param ky Debug Ky instance
|
|
32
|
+
* @param transactionHash Hash of the transaction
|
|
33
|
+
*/
|
|
34
|
+
export async function rebroadcastTransaction(ky, transactionHash) {
|
|
35
|
+
const response = await http(ky, {
|
|
36
|
+
method: 'post',
|
|
37
|
+
path: `${transactionsEndpoint}/${transactionHash}`,
|
|
38
|
+
responseType: 'json',
|
|
39
|
+
});
|
|
40
|
+
return response.data.transactionHash;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Cancel existing transaction
|
|
44
|
+
*
|
|
45
|
+
* @param ky Debug Ky instance
|
|
46
|
+
* @param transactionHash Hash of the transaction
|
|
47
|
+
* @param gasPrice Optional gas price
|
|
48
|
+
*/
|
|
49
|
+
export async function cancelTransaction(ky, transactionHash, gasPrice) {
|
|
50
|
+
const response = await http(ky, {
|
|
51
|
+
method: 'delete',
|
|
52
|
+
headers: { 'gas-price': gasPrice },
|
|
53
|
+
path: `${transactionsEndpoint}/${transactionHash}`,
|
|
54
|
+
responseType: 'json',
|
|
55
|
+
});
|
|
56
|
+
return response.data.transactionHash;
|
|
57
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { filterHeaders, http } from '../utils/http';
|
|
2
|
+
import { extractUploadHeaders } from '../utils/headers';
|
|
3
|
+
import { BeeError } from '../utils/error';
|
|
4
|
+
const feedEndpoint = 'feeds';
|
|
5
|
+
/**
|
|
6
|
+
* Create an initial feed root manifest
|
|
7
|
+
*
|
|
8
|
+
* @param ky Ky instance
|
|
9
|
+
* @param owner Owner's ethereum address in hex
|
|
10
|
+
* @param topic Topic in hex
|
|
11
|
+
* @param postageBatchId Postage BatchId to be used to create the Feed Manifest
|
|
12
|
+
* @param options Additional options, like type (default: 'sequence')
|
|
13
|
+
*/
|
|
14
|
+
export async function createFeedManifest(ky, owner, topic, postageBatchId, options) {
|
|
15
|
+
const response = await http(ky, {
|
|
16
|
+
method: 'post',
|
|
17
|
+
responseType: 'json',
|
|
18
|
+
path: `${feedEndpoint}/${owner}/${topic}`,
|
|
19
|
+
searchParams: filterHeaders(options),
|
|
20
|
+
headers: extractUploadHeaders(postageBatchId),
|
|
21
|
+
});
|
|
22
|
+
return response.data.reference;
|
|
23
|
+
}
|
|
24
|
+
function readFeedUpdateHeaders(headers) {
|
|
25
|
+
const feedIndex = headers.get('swarm-feed-index');
|
|
26
|
+
const feedIndexNext = headers.get('swarm-feed-index-next');
|
|
27
|
+
if (!feedIndex) {
|
|
28
|
+
throw new BeeError('Response did not contain expected swarm-feed-index!');
|
|
29
|
+
}
|
|
30
|
+
if (!feedIndexNext) {
|
|
31
|
+
throw new BeeError('Response did not contain expected swarm-feed-index-next!');
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
feedIndex,
|
|
35
|
+
feedIndexNext,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Find and retrieve feed update
|
|
40
|
+
*
|
|
41
|
+
* The feed consists of updates. This endpoint looks up an
|
|
42
|
+
* update that matches the provided parameters and returns
|
|
43
|
+
* the reference it contains along with its index and the
|
|
44
|
+
* index of the subsequent update.
|
|
45
|
+
*
|
|
46
|
+
* @param ky Ky instance
|
|
47
|
+
* @param owner Owner's ethereum address in hex
|
|
48
|
+
* @param topic Topic in hex
|
|
49
|
+
* @param options Additional options, like index, at, type
|
|
50
|
+
*/
|
|
51
|
+
export async function fetchFeedUpdate(ky, owner, topic, options) {
|
|
52
|
+
const response = await http(ky, {
|
|
53
|
+
responseType: 'json',
|
|
54
|
+
path: `${feedEndpoint}/${owner}/${topic}`,
|
|
55
|
+
searchParams: filterHeaders(options),
|
|
56
|
+
});
|
|
57
|
+
return {
|
|
58
|
+
...response.data,
|
|
59
|
+
...readFeedUpdateHeaders(response.headers),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { http } from '../utils/http';
|
|
2
|
+
const PINNING_ENDPOINT = 'pins';
|
|
3
|
+
/**
|
|
4
|
+
* Pin data with given reference
|
|
5
|
+
*
|
|
6
|
+
* @param ky Ky instance for given Bee class instance
|
|
7
|
+
* @param reference Bee data reference
|
|
8
|
+
*/
|
|
9
|
+
export async function pin(ky, reference) {
|
|
10
|
+
await http(ky, {
|
|
11
|
+
method: 'post',
|
|
12
|
+
responseType: 'json',
|
|
13
|
+
path: `${PINNING_ENDPOINT}/${reference}`,
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Unpin data with given reference
|
|
18
|
+
*
|
|
19
|
+
* @param ky Ky instance for given Bee class instance
|
|
20
|
+
* @param reference Bee data reference
|
|
21
|
+
*/
|
|
22
|
+
export async function unpin(ky, reference) {
|
|
23
|
+
await http(ky, {
|
|
24
|
+
method: 'delete',
|
|
25
|
+
responseType: 'json',
|
|
26
|
+
path: `${PINNING_ENDPOINT}/${reference}`,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Get pin status for specific address.
|
|
31
|
+
*
|
|
32
|
+
* @param ky Ky instance
|
|
33
|
+
* @param reference
|
|
34
|
+
* @throws Error if given address is not pinned
|
|
35
|
+
*/
|
|
36
|
+
export async function getPin(ky, reference) {
|
|
37
|
+
const response = await http(ky, {
|
|
38
|
+
method: 'get',
|
|
39
|
+
responseType: 'json',
|
|
40
|
+
path: `${PINNING_ENDPOINT}/${reference}`,
|
|
41
|
+
});
|
|
42
|
+
return response.data;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Get list of all pins
|
|
46
|
+
*
|
|
47
|
+
* @param ky Ky instance
|
|
48
|
+
*/
|
|
49
|
+
export async function getAllPins(ky) {
|
|
50
|
+
const response = await http(ky, {
|
|
51
|
+
method: 'get',
|
|
52
|
+
responseType: 'json',
|
|
53
|
+
path: `${PINNING_ENDPOINT}`,
|
|
54
|
+
});
|
|
55
|
+
const result = response.data.references;
|
|
56
|
+
if (result === null) {
|
|
57
|
+
return [];
|
|
58
|
+
}
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import WebSocket from 'isomorphic-ws';
|
|
2
|
+
import { prepareData } from '../utils/data';
|
|
3
|
+
import { http } from '../utils/http';
|
|
4
|
+
import { extractUploadHeaders } from '../utils/headers';
|
|
5
|
+
const endpoint = 'pss';
|
|
6
|
+
/**
|
|
7
|
+
* Send to recipient or target with Postal Service for Swarm
|
|
8
|
+
*
|
|
9
|
+
* @param ky Ky instance for given Bee class instance
|
|
10
|
+
* @param topic Topic name
|
|
11
|
+
* @param target Target message address prefix
|
|
12
|
+
* @param data
|
|
13
|
+
* @param postageBatchId Postage BatchId that will be assigned to sent message
|
|
14
|
+
* @param recipient Recipient public key
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
export async function send(ky, topic, target, data, postageBatchId, recipient) {
|
|
18
|
+
await http(ky, {
|
|
19
|
+
method: 'post',
|
|
20
|
+
path: `${endpoint}/send/${topic}/${target}`,
|
|
21
|
+
body: await prepareData(data),
|
|
22
|
+
responseType: 'json',
|
|
23
|
+
searchParams: { recipient },
|
|
24
|
+
headers: extractUploadHeaders(postageBatchId),
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Subscribe for messages on the given topic
|
|
29
|
+
*
|
|
30
|
+
* @param url Bee node URL
|
|
31
|
+
* @param topic Topic name
|
|
32
|
+
*/
|
|
33
|
+
export function subscribe(url, topic) {
|
|
34
|
+
const wsUrl = url.replace(/^http/i, 'ws');
|
|
35
|
+
return new WebSocket(`${wsUrl}/${endpoint}/subscribe/${topic}`);
|
|
36
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { extractUploadHeaders } from '../utils/headers';
|
|
2
|
+
import { http } from '../utils/http';
|
|
3
|
+
const socEndpoint = 'soc';
|
|
4
|
+
/**
|
|
5
|
+
* Upload single owner chunk (SOC) to a Bee node
|
|
6
|
+
*
|
|
7
|
+
* @param ky Ky instance
|
|
8
|
+
* @param owner Owner's ethereum address in hex
|
|
9
|
+
* @param identifier Arbitrary identifier in hex
|
|
10
|
+
* @param signature Signature in hex
|
|
11
|
+
* @param data Content addressed chunk data to be uploaded
|
|
12
|
+
* @param postageBatchId Postage BatchId that will be assigned to uploaded data
|
|
13
|
+
* @param options Additional options like tag, encryption, pinning
|
|
14
|
+
*/
|
|
15
|
+
export async function upload(ky, owner, identifier, signature, data, postageBatchId, options) {
|
|
16
|
+
const response = await http(ky, {
|
|
17
|
+
method: 'post',
|
|
18
|
+
path: `${socEndpoint}/${owner}/${identifier}`,
|
|
19
|
+
body: data,
|
|
20
|
+
headers: {
|
|
21
|
+
'content-type': 'application/octet-stream',
|
|
22
|
+
...extractUploadHeaders(postageBatchId, options),
|
|
23
|
+
},
|
|
24
|
+
responseType: 'json',
|
|
25
|
+
searchParams: { sig: signature },
|
|
26
|
+
});
|
|
27
|
+
return response.data.reference;
|
|
28
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { http } from '../utils/http';
|
|
2
|
+
/**
|
|
3
|
+
* Ping the base bee URL. If connection was not successful throw error
|
|
4
|
+
*
|
|
5
|
+
* @param ky Ky instance for given Bee class instance
|
|
6
|
+
*/
|
|
7
|
+
export async function checkConnection(ky) {
|
|
8
|
+
await http(ky, {
|
|
9
|
+
path: '',
|
|
10
|
+
});
|
|
11
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { http } from '../utils/http';
|
|
2
|
+
const stewardshipEndpoint = 'stewardship';
|
|
3
|
+
/**
|
|
4
|
+
* Reupload locally pinned data
|
|
5
|
+
* @param ky Ky instance
|
|
6
|
+
* @param reference
|
|
7
|
+
* @param options
|
|
8
|
+
* @throws BeeResponseError if not locally pinned or invalid data
|
|
9
|
+
*/
|
|
10
|
+
export async function reupload(ky, reference) {
|
|
11
|
+
await http(ky, {
|
|
12
|
+
method: 'put',
|
|
13
|
+
path: `${stewardshipEndpoint}/${reference}`,
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
export async function isRetrievable(ky, reference) {
|
|
17
|
+
const response = await http(ky, {
|
|
18
|
+
method: 'get',
|
|
19
|
+
responseType: 'json',
|
|
20
|
+
path: `${stewardshipEndpoint}/${reference}`,
|
|
21
|
+
});
|
|
22
|
+
return response.data.isRetrievable;
|
|
23
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { http } from '../utils/http';
|
|
2
|
+
const endpoint = 'tags';
|
|
3
|
+
/**
|
|
4
|
+
* Create new tag on the Bee node
|
|
5
|
+
*
|
|
6
|
+
* @param url Bee tag URL
|
|
7
|
+
*/
|
|
8
|
+
export async function createTag(ky) {
|
|
9
|
+
const response = await http(ky, {
|
|
10
|
+
method: 'post',
|
|
11
|
+
path: endpoint,
|
|
12
|
+
responseType: 'json',
|
|
13
|
+
});
|
|
14
|
+
return response.data;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Retrieve tag information from Bee node
|
|
18
|
+
*
|
|
19
|
+
* @param url Bee tag URL
|
|
20
|
+
* @param uid UID of tag to be retrieved
|
|
21
|
+
*/
|
|
22
|
+
export async function retrieveTag(ky, uid) {
|
|
23
|
+
const response = await http(ky, {
|
|
24
|
+
path: `${endpoint}/${uid}`,
|
|
25
|
+
responseType: 'json',
|
|
26
|
+
});
|
|
27
|
+
return response.data;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Get limited listing of all tags.
|
|
31
|
+
*
|
|
32
|
+
* @param url
|
|
33
|
+
* @param offset
|
|
34
|
+
* @param limit
|
|
35
|
+
*/
|
|
36
|
+
export async function getAllTags(ky, offset, limit) {
|
|
37
|
+
const response = await http(ky, {
|
|
38
|
+
path: `${endpoint}`,
|
|
39
|
+
searchParams: { offset, limit },
|
|
40
|
+
responseType: 'json',
|
|
41
|
+
});
|
|
42
|
+
return response.data.tags;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Removes tag from the Bee node.
|
|
46
|
+
* @param url
|
|
47
|
+
* @param uid
|
|
48
|
+
*/
|
|
49
|
+
export async function deleteTag(ky, uid) {
|
|
50
|
+
await http(ky, {
|
|
51
|
+
method: 'delete',
|
|
52
|
+
path: `${endpoint}/${uid}`,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Updates tag
|
|
57
|
+
* @param url
|
|
58
|
+
* @param uid
|
|
59
|
+
* @param reference
|
|
60
|
+
*/
|
|
61
|
+
export async function updateTag(ky, uid, reference) {
|
|
62
|
+
await http(ky, {
|
|
63
|
+
method: 'patch',
|
|
64
|
+
path: `${endpoint}/${uid}`,
|
|
65
|
+
json: {
|
|
66
|
+
reference,
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export * from './debug';
|
|
2
|
+
export const SPAN_SIZE = 8;
|
|
3
|
+
export const SECTION_SIZE = 32;
|
|
4
|
+
export const BRANCHES = 128;
|
|
5
|
+
export const CHUNK_SIZE = SECTION_SIZE * BRANCHES;
|
|
6
|
+
export const ADDRESS_HEX_LENGTH = 64;
|
|
7
|
+
export const PSS_TARGET_HEX_LENGTH_MAX = 6;
|
|
8
|
+
export const PUBKEY_HEX_LENGTH = 66;
|
|
9
|
+
export const BATCH_ID_HEX_LENGTH = 64;
|
|
10
|
+
export const REFERENCE_HEX_LENGTH = 64;
|
|
11
|
+
export const ENCRYPTED_REFERENCE_HEX_LENGTH = 128;
|
|
12
|
+
export const REFERENCE_BYTES_LENGTH = 32;
|
|
13
|
+
export const ENCRYPTED_REFERENCE_BYTES_LENGTH = 64;
|
|
14
|
+
/**
|
|
15
|
+
* Minimal depth that can be used for creation of postage batch
|
|
16
|
+
*/
|
|
17
|
+
export const STAMPS_DEPTH_MIN = 17;
|
|
18
|
+
/**
|
|
19
|
+
* Maximal depth that can be used for creation of postage batch
|
|
20
|
+
*/
|
|
21
|
+
export const STAMPS_DEPTH_MAX = 255;
|
|
22
|
+
export const TAGS_LIMIT_MIN = 1;
|
|
23
|
+
export const TAGS_LIMIT_MAX = 1000;
|
|
24
|
+
/*********************************************************
|
|
25
|
+
* Writers and Readers interfaces
|
|
26
|
+
*/
|
|
27
|
+
export const TOPIC_BYTES_LENGTH = 32;
|
|
28
|
+
export const TOPIC_HEX_LENGTH = 64;
|
|
29
|
+
/*********************************************************
|
|
30
|
+
* Ethereum compatible signing interfaces and definitions
|
|
31
|
+
*/
|
|
32
|
+
export const SIGNATURE_HEX_LENGTH = 130;
|
|
33
|
+
export const SIGNATURE_BYTES_LENGTH = 65;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { bytesToHex } from './hex';
|
|
2
|
+
/**
|
|
3
|
+
* Type guard for `Bytes<T>` type
|
|
4
|
+
*
|
|
5
|
+
* @param b The byte array
|
|
6
|
+
* @param length The length of the byte array
|
|
7
|
+
*/
|
|
8
|
+
export function isBytes(b, length) {
|
|
9
|
+
return b instanceof Uint8Array && b.length === length;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Verifies if a byte array has a certain length
|
|
13
|
+
*
|
|
14
|
+
* @param b The byte array
|
|
15
|
+
* @param length The specified length
|
|
16
|
+
*/
|
|
17
|
+
export function assertBytes(b, length) {
|
|
18
|
+
if (!isBytes(b, length)) {
|
|
19
|
+
throw new TypeError(`Parameter is not valid Bytes of length: ${length} !== ${b.length}`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Type guard for FlexBytes<Min,Max> type
|
|
24
|
+
*
|
|
25
|
+
* @param b The byte array
|
|
26
|
+
* @param min Minimum size of the array
|
|
27
|
+
* @param max Maximum size of the array
|
|
28
|
+
*/
|
|
29
|
+
export function isFlexBytes(b, min, max) {
|
|
30
|
+
return b instanceof Uint8Array && b.length >= min && b.length <= max;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Verifies if a byte array has a certain length between min and max
|
|
34
|
+
*
|
|
35
|
+
* @param b The byte array
|
|
36
|
+
* @param min Minimum size of the array
|
|
37
|
+
* @param max Maximum size of the array
|
|
38
|
+
*/
|
|
39
|
+
export function assertFlexBytes(b, min, max) {
|
|
40
|
+
if (!isFlexBytes(b, min, max)) {
|
|
41
|
+
throw new TypeError(`Parameter is not valid FlexBytes of min: ${min}, max: ${max}, length: ${b.length}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Return `length` bytes starting from `offset`
|
|
46
|
+
*
|
|
47
|
+
* @param data The original data
|
|
48
|
+
* @param offset The offset to start from
|
|
49
|
+
* @param length The length of data to be returned
|
|
50
|
+
*/
|
|
51
|
+
export function bytesAtOffset(data, offset, length) {
|
|
52
|
+
const offsetBytes = data.slice(offset, offset + length);
|
|
53
|
+
// We are returning strongly typed Bytes so we have to verify that length is really what we claim
|
|
54
|
+
assertBytes(offsetBytes, length);
|
|
55
|
+
return offsetBytes;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Return flex bytes starting from `offset`
|
|
59
|
+
*
|
|
60
|
+
* @param data The original data
|
|
61
|
+
* @param offset The offset to start from
|
|
62
|
+
* @param _min The minimum size of the data
|
|
63
|
+
* @param _max The maximum size of the data
|
|
64
|
+
*/
|
|
65
|
+
export function flexBytesAtOffset(data, offset,
|
|
66
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
67
|
+
_min,
|
|
68
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
69
|
+
_max) {
|
|
70
|
+
return data.slice(offset);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Returns true if two byte arrays are equal
|
|
74
|
+
*
|
|
75
|
+
* @param a Byte array to compare
|
|
76
|
+
* @param b Byte array to compare
|
|
77
|
+
*/
|
|
78
|
+
export function bytesEqual(a, b) {
|
|
79
|
+
return a.length === b.length && a.every((value, index) => value === b[index]);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Returns a new byte array filled with zeroes with the specified length
|
|
83
|
+
*
|
|
84
|
+
* @param length The length of data to be returned
|
|
85
|
+
*/
|
|
86
|
+
export function makeBytes(length) {
|
|
87
|
+
return new Uint8Array(length);
|
|
88
|
+
}
|
|
89
|
+
export function wrapBytesWithHelpers(data) {
|
|
90
|
+
return Object.assign(data, {
|
|
91
|
+
text: () => new TextDecoder('utf-8').decode(data),
|
|
92
|
+
json: () => JSON.parse(new TextDecoder('utf-8').decode(data)),
|
|
93
|
+
hex: () => bytesToHex(data),
|
|
94
|
+
});
|
|
95
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates array in the format of Collection with data loaded from directory on filesystem.
|
|
3
|
+
* The function loads all the data into memory!
|
|
4
|
+
*
|
|
5
|
+
* @param dir path to the directory
|
|
6
|
+
*/
|
|
7
|
+
export async function makeCollectionFromFS(dir) {
|
|
8
|
+
throw new Error('Creating Collection from File System is not supported in browsers!');
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Calculate folder size recursively
|
|
12
|
+
*
|
|
13
|
+
* @param dir the path to the folder to check
|
|
14
|
+
* @returns size in bytes
|
|
15
|
+
*/
|
|
16
|
+
export async function getFolderSize(dir) {
|
|
17
|
+
throw new Error('Creating Collection from File System is not supported in browsers!');
|
|
18
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { BeeArgumentError } from './error';
|
|
2
|
+
import { fileArrayBuffer } from './file';
|
|
3
|
+
import { isUint8Array } from './type';
|
|
4
|
+
export function isCollection(data) {
|
|
5
|
+
if (!Array.isArray(data)) {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
return data.every(entry => typeof entry === 'object' && entry.data && entry.path && isUint8Array(entry.data));
|
|
9
|
+
}
|
|
10
|
+
export function assertCollection(data) {
|
|
11
|
+
if (!isCollection(data)) {
|
|
12
|
+
throw new BeeArgumentError('invalid collection', data);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function makeFilePath(file) {
|
|
16
|
+
if (file.webkitRelativePath && file.webkitRelativePath !== '') {
|
|
17
|
+
return file.webkitRelativePath.replace(/.*?\//i, '');
|
|
18
|
+
}
|
|
19
|
+
if (file.name) {
|
|
20
|
+
return file.name;
|
|
21
|
+
}
|
|
22
|
+
throw new TypeError('file is not valid File object');
|
|
23
|
+
}
|
|
24
|
+
export async function makeCollectionFromFileList(fileList) {
|
|
25
|
+
const collection = [];
|
|
26
|
+
for (let i = 0; i < fileList.length; i++) {
|
|
27
|
+
const file = fileList[i];
|
|
28
|
+
if (file) {
|
|
29
|
+
collection.push({
|
|
30
|
+
path: makeFilePath(file),
|
|
31
|
+
data: new Uint8Array(await fileArrayBuffer(file)),
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return collection;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Calculate cumulative size of files
|
|
39
|
+
*
|
|
40
|
+
* @param fileList list of files to check
|
|
41
|
+
* @returns size in bytes
|
|
42
|
+
*/
|
|
43
|
+
export function getCollectionSize(fileList) {
|
|
44
|
+
let sum = 0;
|
|
45
|
+
for (let i = 0; i < fileList.length; i++) {
|
|
46
|
+
const file = fileList[i];
|
|
47
|
+
if (file) {
|
|
48
|
+
sum += file.size;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return sum;
|
|
52
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
/**
|
|
4
|
+
* Creates array in the format of Collection with data loaded from directory on filesystem.
|
|
5
|
+
* The function loads all the data into memory!
|
|
6
|
+
*
|
|
7
|
+
* @param dir path to the directory
|
|
8
|
+
*/
|
|
9
|
+
export async function makeCollectionFromFS(dir) {
|
|
10
|
+
if (typeof dir !== 'string') {
|
|
11
|
+
throw new TypeError('dir has to be string!');
|
|
12
|
+
}
|
|
13
|
+
if (dir === '') {
|
|
14
|
+
throw new TypeError('dir must not be empty string!');
|
|
15
|
+
}
|
|
16
|
+
return buildCollectionRelative(dir, '');
|
|
17
|
+
}
|
|
18
|
+
async function buildCollectionRelative(dir, relativePath) {
|
|
19
|
+
// Handles case when the dir is not existing or it is a file ==> throws an error
|
|
20
|
+
const dirname = path.join(dir, relativePath);
|
|
21
|
+
const entries = await fs.promises.opendir(dirname);
|
|
22
|
+
let collection = [];
|
|
23
|
+
for await (const entry of entries) {
|
|
24
|
+
const fullPath = path.join(dir, relativePath, entry.name);
|
|
25
|
+
const entryPath = path.join(relativePath, entry.name);
|
|
26
|
+
if (entry.isFile()) {
|
|
27
|
+
collection.push({
|
|
28
|
+
path: entryPath,
|
|
29
|
+
data: new Uint8Array(await fs.promises.readFile(fullPath)),
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
else if (entry.isDirectory()) {
|
|
33
|
+
collection = [...(await buildCollectionRelative(dir, entryPath)), ...collection];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return collection;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Calculate folder size recursively
|
|
40
|
+
*
|
|
41
|
+
* @param dir the path to the folder to check
|
|
42
|
+
* @returns size in bytes
|
|
43
|
+
*/
|
|
44
|
+
export async function getFolderSize(dir) {
|
|
45
|
+
if (typeof dir !== 'string') {
|
|
46
|
+
throw new TypeError('dir has to be string!');
|
|
47
|
+
}
|
|
48
|
+
if (dir === '') {
|
|
49
|
+
throw new TypeError('dir must not be empty string!');
|
|
50
|
+
}
|
|
51
|
+
const entries = await fs.promises.opendir(dir);
|
|
52
|
+
let size = 0;
|
|
53
|
+
for await (const entry of entries) {
|
|
54
|
+
if (entry.isFile()) {
|
|
55
|
+
const stats = await fs.promises.stat(path.join(dir, entry.name));
|
|
56
|
+
size += stats.size;
|
|
57
|
+
}
|
|
58
|
+
else if (entry.isDirectory()) {
|
|
59
|
+
size += await getFolderSize(path.join(dir, entry.name));
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return size;
|
|
63
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { isNodeReadable, isReadableStream } from './stream';
|
|
2
|
+
import Blob from 'cross-blob';
|
|
3
|
+
/**
|
|
4
|
+
* Validates input and converts to Uint8Array
|
|
5
|
+
*
|
|
6
|
+
* @param data any string, ArrayBuffer or Uint8Array
|
|
7
|
+
*/
|
|
8
|
+
export async function prepareData(data) {
|
|
9
|
+
if (typeof data === 'string')
|
|
10
|
+
return new Blob([data], { type: 'text/plain' });
|
|
11
|
+
if (data instanceof Uint8Array || data instanceof ArrayBuffer) {
|
|
12
|
+
return new Blob([data], { type: 'application/octet-stream' });
|
|
13
|
+
}
|
|
14
|
+
if (data instanceof Blob) {
|
|
15
|
+
return data;
|
|
16
|
+
}
|
|
17
|
+
// Currently it is not possible to stream requests from browsers
|
|
18
|
+
// there are already first experiments on this field (Chromium)
|
|
19
|
+
// but till it is fully implemented across browsers-land we have to
|
|
20
|
+
// buffer the data before sending the requests.
|
|
21
|
+
if (isNodeReadable(data)) {
|
|
22
|
+
return new Promise(resolve => {
|
|
23
|
+
const buffers = [];
|
|
24
|
+
data.on('data', d => {
|
|
25
|
+
buffers.push(d);
|
|
26
|
+
});
|
|
27
|
+
data.on('end', () => {
|
|
28
|
+
resolve(new Blob(buffers, { type: 'application/octet-stream' }));
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
if (isReadableStream(data)) {
|
|
33
|
+
return new Promise(async (resolve) => {
|
|
34
|
+
const reader = data.getReader();
|
|
35
|
+
const buffers = [];
|
|
36
|
+
let done, value;
|
|
37
|
+
do {
|
|
38
|
+
;
|
|
39
|
+
({ done, value } = await reader.read());
|
|
40
|
+
if (!done) {
|
|
41
|
+
buffers.push(value);
|
|
42
|
+
}
|
|
43
|
+
} while (!done);
|
|
44
|
+
resolve(new Blob(buffers, { type: 'application/octet-stream' }));
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
throw new TypeError('unknown data type');
|
|
48
|
+
}
|
|
49
|
+
export async function prepareWebsocketData(data) {
|
|
50
|
+
if (typeof data === 'string')
|
|
51
|
+
return new TextEncoder().encode(data);
|
|
52
|
+
if (data instanceof ArrayBuffer)
|
|
53
|
+
return new Uint8Array(data);
|
|
54
|
+
if (data instanceof Blob)
|
|
55
|
+
return new Uint8Array(await new Response(data).arrayBuffer());
|
|
56
|
+
throw new TypeError('unknown websocket data type');
|
|
57
|
+
}
|