@ethersphere/bee-js 8.3.1 → 9.0.2
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 +192 -50
- package/dist/cjs/bee-dev.js +78 -0
- package/dist/cjs/bee.js +341 -417
- package/dist/cjs/chunk/bmt.js +15 -32
- package/dist/cjs/chunk/cac.js +26 -36
- package/dist/cjs/chunk/soc.js +56 -51
- package/dist/cjs/feed/identifier.js +3 -28
- package/dist/cjs/feed/index.js +95 -44
- package/dist/cjs/feed/retrievable.js +11 -22
- package/dist/cjs/index.js +17 -1
- package/dist/cjs/manifest/manifest.js +369 -0
- package/dist/cjs/modules/bytes.js +24 -12
- package/dist/cjs/modules/bzz.js +24 -34
- package/dist/cjs/modules/chunk.js +13 -7
- package/dist/cjs/modules/debug/balance.js +29 -4
- package/dist/cjs/modules/debug/chequebook.js +60 -16
- package/dist/cjs/modules/debug/connectivity.js +82 -4
- package/dist/cjs/modules/debug/settlements.js +22 -2
- package/dist/cjs/modules/debug/stake.js +29 -11
- package/dist/cjs/modules/debug/stamps.js +88 -7
- package/dist/cjs/modules/debug/states.js +25 -3
- package/dist/cjs/modules/debug/status.js +45 -47
- package/dist/cjs/modules/debug/transactions.js +27 -5
- package/dist/cjs/modules/envelope.js +8 -6
- package/dist/cjs/modules/feed.js +25 -10
- package/dist/cjs/modules/grantee.js +18 -12
- package/dist/cjs/modules/gsoc.js +24 -0
- package/dist/cjs/modules/pinning.js +13 -2
- package/dist/cjs/modules/pss.js +9 -3
- package/dist/cjs/modules/soc.js +9 -4
- package/dist/cjs/modules/stewardship.js +7 -3
- package/dist/cjs/modules/tag.js +35 -3
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/stamper/stamper.js +43 -0
- package/dist/cjs/types/debug.js +16 -1
- package/dist/cjs/types/index.js +2 -24
- package/dist/cjs/utils/bytes.js +67 -115
- package/dist/cjs/utils/chunk-size.js +17 -0
- package/dist/cjs/utils/chunk-stream.browser.js +85 -0
- package/dist/cjs/utils/chunk-stream.js +84 -0
- package/dist/cjs/utils/cid.js +5 -6
- package/dist/cjs/utils/collection.browser.js +2 -2
- package/dist/cjs/utils/collection.js +3 -2
- package/dist/cjs/utils/collection.node.js +0 -2
- package/dist/cjs/utils/constants.js +7 -3
- package/dist/cjs/utils/data.browser.js +6 -3
- package/dist/cjs/utils/data.js +8 -4
- package/dist/cjs/utils/duration.js +51 -0
- package/dist/cjs/utils/expose.js +11 -40
- package/dist/cjs/utils/headers.js +79 -52
- package/dist/cjs/utils/http.js +34 -10
- package/dist/cjs/utils/mime.js +78 -0
- package/dist/cjs/utils/pss.js +3 -4
- package/dist/cjs/utils/redundancy.js +18 -14
- package/dist/cjs/utils/resource-locator.js +17 -0
- package/dist/cjs/utils/size.js +35 -0
- package/dist/cjs/utils/stamps.js +67 -51
- package/dist/cjs/utils/tar-uploader.browser.js +2 -2
- package/dist/cjs/utils/tar-uploader.js +2 -2
- package/dist/cjs/utils/tokens.js +144 -0
- package/dist/cjs/utils/type.js +142 -350
- package/dist/cjs/utils/typed-bytes.js +179 -0
- package/dist/cjs/utils/upload-progress.js +2 -0
- package/dist/cjs/utils/url.js +0 -4
- package/dist/cjs/utils/workaround.js +27 -0
- package/dist/index.browser.min.js +1 -2
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/bee-dev.js +98 -0
- package/dist/mjs/bee.js +367 -411
- package/dist/mjs/chunk/bmt.js +13 -29
- package/dist/mjs/chunk/cac.js +26 -34
- package/dist/mjs/chunk/soc.js +57 -53
- package/dist/mjs/feed/identifier.js +3 -26
- package/dist/mjs/feed/index.js +98 -51
- package/dist/mjs/feed/retrievable.js +12 -23
- package/dist/mjs/index.js +10 -1
- package/dist/mjs/manifest/manifest.js +371 -0
- package/dist/mjs/modules/bytes.js +27 -15
- package/dist/mjs/modules/bzz.js +25 -32
- package/dist/mjs/modules/chunk.js +16 -8
- package/dist/mjs/modules/debug/balance.js +61 -4
- package/dist/mjs/modules/debug/chequebook.js +116 -16
- package/dist/mjs/modules/debug/connectivity.js +144 -3
- package/dist/mjs/modules/debug/settlements.js +46 -2
- package/dist/mjs/modules/debug/stake.js +69 -11
- package/dist/mjs/modules/debug/stamps.js +184 -7
- package/dist/mjs/modules/debug/states.js +55 -3
- package/dist/mjs/modules/debug/status.js +97 -45
- package/dist/mjs/modules/debug/transactions.js +61 -5
- package/dist/mjs/modules/envelope.js +11 -9
- package/dist/mjs/modules/feed.js +26 -10
- package/dist/mjs/modules/grantee.js +35 -13
- package/dist/mjs/modules/gsoc.js +16 -0
- package/dist/mjs/modules/pinning.js +23 -2
- package/dist/mjs/modules/pss.js +10 -4
- package/dist/mjs/modules/soc.js +10 -5
- package/dist/mjs/modules/stewardship.js +14 -4
- package/dist/mjs/modules/tag.js +93 -3
- package/dist/mjs/package.json +2 -1
- package/dist/mjs/stamper/stamper.js +39 -0
- package/dist/mjs/types/debug.js +15 -1
- package/dist/mjs/types/index.js +2 -24
- package/dist/mjs/utils/bytes.js +63 -104
- package/dist/mjs/utils/chunk-size.js +13 -0
- package/dist/mjs/utils/chunk-stream.browser.js +85 -0
- package/dist/mjs/utils/chunk-stream.js +87 -0
- package/dist/mjs/utils/cid.js +5 -6
- package/dist/mjs/utils/collection.browser.js +2 -2
- package/dist/mjs/utils/collection.js +2 -2
- package/dist/mjs/utils/collection.node.js +0 -2
- package/dist/mjs/utils/constants.js +6 -2
- package/dist/mjs/utils/data.browser.js +9 -3
- package/dist/mjs/utils/data.js +12 -4
- package/dist/mjs/utils/duration.js +47 -0
- package/dist/mjs/utils/expose.js +2 -7
- package/dist/mjs/utils/headers.js +73 -48
- package/dist/mjs/utils/http.js +33 -11
- package/dist/mjs/utils/mime.js +75 -0
- package/dist/mjs/utils/pss.js +3 -4
- package/dist/mjs/utils/redundancy.js +18 -8
- package/dist/mjs/utils/resource-locator.js +13 -0
- package/dist/mjs/utils/size.js +31 -0
- package/dist/mjs/utils/stamps.js +47 -44
- package/dist/mjs/utils/tar-uploader.browser.js +2 -2
- package/dist/mjs/utils/tar-uploader.js +2 -2
- package/dist/mjs/utils/tokens.js +139 -0
- package/dist/mjs/utils/type.js +216 -310
- package/dist/mjs/utils/typed-bytes.js +160 -0
- package/dist/mjs/utils/upload-progress.js +1 -0
- package/dist/mjs/utils/url.js +0 -4
- package/dist/mjs/utils/workaround.js +22 -0
- package/dist/types/bee-dev.d.ts +5 -0
- package/dist/types/bee.d.ts +88 -165
- package/dist/types/chunk/bmt.d.ts +2 -2
- package/dist/types/chunk/cac.d.ts +7 -24
- package/dist/types/chunk/soc.d.ts +15 -15
- package/dist/types/feed/identifier.d.ts +2 -4
- package/dist/types/feed/index.d.ts +14 -18
- package/dist/types/feed/retrievable.d.ts +3 -4
- package/dist/types/index.d.ts +28 -1
- package/dist/types/manifest/manifest.d.ts +106 -0
- package/dist/types/modules/bytes.d.ts +8 -5
- package/dist/types/modules/bzz.d.ts +8 -10
- package/dist/types/modules/chunk.d.ts +4 -3
- package/dist/types/modules/debug/balance.d.ts +3 -2
- package/dist/types/modules/debug/chequebook.d.ts +7 -6
- package/dist/types/modules/debug/connectivity.d.ts +5 -3
- package/dist/types/modules/debug/settlements.d.ts +2 -1
- package/dist/types/modules/debug/stake.d.ts +4 -2
- package/dist/types/modules/debug/stamps.d.ts +5 -4
- package/dist/types/modules/debug/status.d.ts +6 -25
- package/dist/types/modules/debug/transactions.d.ts +5 -4
- package/dist/types/modules/envelope.d.ts +3 -2
- package/dist/types/modules/feed.d.ts +20 -16
- package/dist/types/modules/grantee.d.ts +7 -6
- package/dist/types/modules/gsoc.d.ts +7 -0
- package/dist/types/modules/pinning.d.ts +2 -4
- package/dist/types/modules/pss.d.ts +4 -3
- package/dist/types/modules/soc.d.ts +3 -2
- package/dist/types/modules/stewardship.d.ts +4 -4
- package/dist/types/modules/tag.d.ts +2 -1
- package/dist/types/stamper/stamper.d.ts +15 -0
- package/dist/types/types/debug.d.ts +63 -115
- package/dist/types/types/index.d.ts +103 -204
- package/dist/types/utils/bytes.d.ts +16 -90
- package/dist/types/utils/chunk-size.d.ts +1 -0
- package/dist/types/utils/chunk-stream.browser.d.ts +6 -0
- package/dist/types/utils/chunk-stream.d.ts +6 -0
- package/dist/types/utils/cid.d.ts +3 -2
- package/dist/types/utils/collection.browser.d.ts +2 -2
- package/dist/types/utils/collection.d.ts +2 -1
- package/dist/types/utils/collection.node.d.ts +0 -1
- package/dist/types/utils/constants.d.ts +4 -1
- package/dist/types/utils/duration.d.ts +17 -0
- package/dist/types/utils/error.d.ts +2 -2
- package/dist/types/utils/expose.d.ts +2 -7
- package/dist/types/utils/headers.d.ts +3 -4
- package/dist/types/utils/mime.d.ts +1 -0
- package/dist/types/utils/pss.d.ts +2 -2
- package/dist/types/utils/resource-locator.d.ts +6 -0
- package/dist/types/utils/size.d.ts +16 -0
- package/dist/types/utils/stamps.d.ts +27 -33
- package/dist/types/utils/tar-uploader.browser.d.ts +3 -4
- package/dist/types/utils/tar-uploader.d.ts +3 -4
- package/dist/types/utils/tokens.d.ts +77 -0
- package/dist/types/utils/type.d.ts +20 -52
- package/dist/types/utils/typed-bytes.d.ts +68 -0
- package/dist/types/utils/upload-progress.d.ts +4 -0
- package/dist/types/utils/workaround.d.ts +2 -0
- package/package.json +11 -17
- package/dist/cjs/chunk/signer.js +0 -126
- package/dist/cjs/chunk/span.js +0 -25
- package/dist/cjs/feed/json.js +0 -28
- package/dist/cjs/feed/topic.js +0 -25
- package/dist/cjs/feed/type.js +0 -15
- package/dist/cjs/modules/debug/chunk.js +0 -21
- package/dist/cjs/modules/debug/tag.js +0 -19
- package/dist/cjs/utils/eth.js +0 -216
- package/dist/cjs/utils/hash.js +0 -21
- package/dist/cjs/utils/hex.js +0 -150
- package/dist/cjs/utils/reference.js +0 -36
- package/dist/index.browser.min.js.LICENSE.txt +0 -8
- package/dist/mjs/chunk/signer.js +0 -114
- package/dist/mjs/chunk/span.js +0 -21
- package/dist/mjs/feed/json.js +0 -26
- package/dist/mjs/feed/topic.js +0 -19
- package/dist/mjs/feed/type.js +0 -10
- package/dist/mjs/modules/debug/chunk.js +0 -17
- package/dist/mjs/modules/debug/tag.js +0 -15
- package/dist/mjs/utils/eth.js +0 -192
- package/dist/mjs/utils/hash.js +0 -16
- package/dist/mjs/utils/hex.js +0 -135
- package/dist/mjs/utils/reference.js +0 -29
- package/dist/types/chunk/signer.d.ts +0 -31
- package/dist/types/chunk/span.d.ts +0 -10
- package/dist/types/feed/json.d.ts +0 -4
- package/dist/types/feed/topic.d.ts +0 -3
- package/dist/types/feed/type.d.ts +0 -6
- package/dist/types/modules/debug/chunk.d.ts +0 -10
- package/dist/types/modules/debug/tag.d.ts +0 -8
- package/dist/types/utils/eth.d.ts +0 -67
- package/dist/types/utils/hash.d.ts +0 -9
- package/dist/types/utils/hex.d.ts +0 -86
- package/dist/types/utils/reference.d.ts +0 -2
package/dist/mjs/modules/feed.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import { Types } from 'cafe-utility';
|
|
2
|
+
import { Bytes } from "../utils/bytes.js";
|
|
1
3
|
import { BeeError } from "../utils/error.js";
|
|
2
|
-
import {
|
|
4
|
+
import { prepareRequestHeaders } from "../utils/headers.js";
|
|
3
5
|
import { http } from "../utils/http.js";
|
|
6
|
+
import { FeedIndex, Reference } from "../utils/typed-bytes.js";
|
|
4
7
|
const feedEndpoint = 'feeds';
|
|
5
8
|
/**
|
|
6
9
|
* Create an initial feed root manifest
|
|
@@ -11,14 +14,17 @@ const feedEndpoint = 'feeds';
|
|
|
11
14
|
* @param postageBatchId Postage BatchId to be used to create the Feed Manifest
|
|
12
15
|
* @param options Additional options, like type (default: 'sequence')
|
|
13
16
|
*/
|
|
14
|
-
export async function createFeedManifest(requestOptions, owner, topic, stamp) {
|
|
17
|
+
export async function createFeedManifest(requestOptions, owner, topic, stamp, options) {
|
|
15
18
|
const response = await http(requestOptions, {
|
|
16
19
|
method: 'post',
|
|
17
20
|
responseType: 'json',
|
|
18
21
|
url: `${feedEndpoint}/${owner}/${topic}`,
|
|
19
|
-
headers:
|
|
22
|
+
headers: prepareRequestHeaders(stamp, options)
|
|
20
23
|
});
|
|
21
|
-
|
|
24
|
+
const body = Types.asObject(response.data, {
|
|
25
|
+
name: 'response.data'
|
|
26
|
+
});
|
|
27
|
+
return new Reference(Types.asHexString(body.reference));
|
|
22
28
|
}
|
|
23
29
|
function readFeedUpdateHeaders(headers) {
|
|
24
30
|
const feedIndex = headers['swarm-feed-index'];
|
|
@@ -30,8 +36,8 @@ function readFeedUpdateHeaders(headers) {
|
|
|
30
36
|
throw new BeeError('Response did not contain expected swarm-feed-index-next!');
|
|
31
37
|
}
|
|
32
38
|
return {
|
|
33
|
-
feedIndex,
|
|
34
|
-
feedIndexNext
|
|
39
|
+
feedIndex: new FeedIndex(feedIndex),
|
|
40
|
+
feedIndexNext: new FeedIndex(feedIndexNext)
|
|
35
41
|
};
|
|
36
42
|
}
|
|
37
43
|
/**
|
|
@@ -43,18 +49,28 @@ function readFeedUpdateHeaders(headers) {
|
|
|
43
49
|
* index of the subsequent update.
|
|
44
50
|
*
|
|
45
51
|
* @param requestOptions Options for making requests
|
|
46
|
-
* @param owner Owner's ethereum address
|
|
47
|
-
* @param topic Topic
|
|
52
|
+
* @param owner Owner's ethereum address
|
|
53
|
+
* @param topic Topic
|
|
48
54
|
* @param options Additional options, like index, at, type
|
|
49
55
|
*/
|
|
50
56
|
export async function fetchLatestFeedUpdate(requestOptions, owner, topic, options) {
|
|
51
57
|
const response = await http(requestOptions, {
|
|
52
|
-
responseType: '
|
|
58
|
+
responseType: 'arraybuffer',
|
|
53
59
|
url: `${feedEndpoint}/${owner}/${topic}`,
|
|
54
60
|
params: options
|
|
55
61
|
});
|
|
56
62
|
return {
|
|
57
|
-
|
|
63
|
+
payload: new Bytes(response.data),
|
|
58
64
|
...readFeedUpdateHeaders(response.headers)
|
|
59
65
|
};
|
|
66
|
+
}
|
|
67
|
+
export async function probeFeed(requestOptions, owner, topic) {
|
|
68
|
+
const response = await http(requestOptions, {
|
|
69
|
+
responseType: 'arraybuffer',
|
|
70
|
+
url: `${feedEndpoint}/${owner}/${topic}`,
|
|
71
|
+
params: {
|
|
72
|
+
'Swarm-Only-Root-Chunk': true
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
return readFeedUpdateHeaders(response.headers);
|
|
60
76
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Types } from 'cafe-utility';
|
|
2
|
+
import { prepareRequestHeaders } from "../utils/headers.js";
|
|
2
3
|
import { http } from "../utils/http.js";
|
|
4
|
+
import { PublicKey, Reference } from "../utils/typed-bytes.js";
|
|
3
5
|
const granteeEndpoint = 'grantee';
|
|
4
6
|
export async function getGrantees(reference, requestOptions) {
|
|
5
7
|
const response = await http(requestOptions, {
|
|
@@ -7,10 +9,15 @@ export async function getGrantees(reference, requestOptions) {
|
|
|
7
9
|
url: `${granteeEndpoint}/${reference}`,
|
|
8
10
|
responseType: 'json'
|
|
9
11
|
});
|
|
12
|
+
const body = Types.asArray(response.data, {
|
|
13
|
+
name: 'response.data'
|
|
14
|
+
}).map(x => new PublicKey(Types.asString(x, {
|
|
15
|
+
name: 'grantee'
|
|
16
|
+
})));
|
|
10
17
|
return {
|
|
11
18
|
status: response.status,
|
|
12
19
|
statusText: response.statusText,
|
|
13
|
-
|
|
20
|
+
grantees: body
|
|
14
21
|
};
|
|
15
22
|
}
|
|
16
23
|
export async function createGrantees(requestOptions, postageBatchId, grantees) {
|
|
@@ -18,35 +25,50 @@ export async function createGrantees(requestOptions, postageBatchId, grantees) {
|
|
|
18
25
|
method: 'post',
|
|
19
26
|
url: granteeEndpoint,
|
|
20
27
|
data: {
|
|
21
|
-
grantees
|
|
22
|
-
},
|
|
23
|
-
headers: {
|
|
24
|
-
...extractRedundantUploadHeaders(postageBatchId)
|
|
28
|
+
grantees: grantees.map(x => x.toCompressedHex())
|
|
25
29
|
},
|
|
30
|
+
headers: prepareRequestHeaders(postageBatchId),
|
|
26
31
|
responseType: 'json'
|
|
27
32
|
});
|
|
33
|
+
const body = Types.asObject(response.data, {
|
|
34
|
+
name: 'response.data'
|
|
35
|
+
});
|
|
28
36
|
return {
|
|
29
37
|
status: response.status,
|
|
30
38
|
statusText: response.statusText,
|
|
31
|
-
ref:
|
|
32
|
-
|
|
39
|
+
ref: new Reference(Types.asString(body.ref, {
|
|
40
|
+
name: 'ref'
|
|
41
|
+
})),
|
|
42
|
+
historyref: new Reference(Types.asString(body.historyref, {
|
|
43
|
+
name: 'historyref'
|
|
44
|
+
}))
|
|
33
45
|
};
|
|
34
46
|
}
|
|
35
47
|
export async function patchGrantees(postageBatchId, reference, historyRef, grantees, requestOptions) {
|
|
36
48
|
const response = await http(requestOptions, {
|
|
37
49
|
method: 'patch',
|
|
38
50
|
url: `${granteeEndpoint}/${reference}`,
|
|
39
|
-
data:
|
|
51
|
+
data: {
|
|
52
|
+
add: grantees.add?.map(x => x.toCompressedHex()),
|
|
53
|
+
revoke: grantees.revoke?.map(x => x.toCompressedHex())
|
|
54
|
+
},
|
|
40
55
|
headers: {
|
|
41
|
-
...
|
|
42
|
-
'swarm-act-history-address': historyRef
|
|
56
|
+
...prepareRequestHeaders(postageBatchId),
|
|
57
|
+
'swarm-act-history-address': historyRef.toHex()
|
|
43
58
|
},
|
|
44
59
|
responseType: 'json'
|
|
45
60
|
});
|
|
61
|
+
const body = Types.asObject(response.data, {
|
|
62
|
+
name: 'response.data'
|
|
63
|
+
});
|
|
46
64
|
return {
|
|
47
65
|
status: response.status,
|
|
48
66
|
statusText: response.statusText,
|
|
49
|
-
ref:
|
|
50
|
-
|
|
67
|
+
ref: new Reference(Types.asString(body.ref, {
|
|
68
|
+
name: 'ref'
|
|
69
|
+
})),
|
|
70
|
+
historyref: new Reference(Types.asString(body.historyref, {
|
|
71
|
+
name: 'historyref'
|
|
72
|
+
}))
|
|
51
73
|
};
|
|
52
74
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { System } from 'cafe-utility';
|
|
2
|
+
import WebSocket from 'isomorphic-ws';
|
|
3
|
+
import { uploadSingleOwnerChunk } from "../chunk/soc.js";
|
|
4
|
+
const endpoint = 'gsoc';
|
|
5
|
+
export async function send(requestOptions, soc, stamp, options) {
|
|
6
|
+
return uploadSingleOwnerChunk(requestOptions, soc, stamp, options);
|
|
7
|
+
}
|
|
8
|
+
export function subscribe(url, reference, headers) {
|
|
9
|
+
const wsUrl = url.replace(/^http/i, 'ws');
|
|
10
|
+
if (System.whereAmI() === 'browser') {
|
|
11
|
+
return new WebSocket(`${wsUrl}/${endpoint}/subscribe/${reference.toHex()}`);
|
|
12
|
+
}
|
|
13
|
+
return new WebSocket(`${wsUrl}/${endpoint}/subscribe/${reference.toHex()}`, {
|
|
14
|
+
headers
|
|
15
|
+
});
|
|
16
|
+
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { Types } from 'cafe-utility';
|
|
1
2
|
import { http } from "../utils/http.js";
|
|
3
|
+
import { Reference } from "../utils/typed-bytes.js";
|
|
2
4
|
const PINNING_ENDPOINT = 'pins';
|
|
3
5
|
/**
|
|
4
6
|
* Pin data with given reference
|
|
@@ -39,7 +41,14 @@ export async function getPin(requestOptions, reference) {
|
|
|
39
41
|
responseType: 'json',
|
|
40
42
|
url: `${PINNING_ENDPOINT}/${reference}`
|
|
41
43
|
});
|
|
42
|
-
|
|
44
|
+
const body = Types.asObject(response.data, {
|
|
45
|
+
name: 'response.data'
|
|
46
|
+
});
|
|
47
|
+
return {
|
|
48
|
+
reference: new Reference(Types.asString(body.reference, {
|
|
49
|
+
name: 'reference'
|
|
50
|
+
}))
|
|
51
|
+
};
|
|
43
52
|
}
|
|
44
53
|
/**
|
|
45
54
|
* Get list of all pins
|
|
@@ -52,5 +61,17 @@ export async function getAllPins(requestOptions) {
|
|
|
52
61
|
responseType: 'json',
|
|
53
62
|
url: `${PINNING_ENDPOINT}`
|
|
54
63
|
});
|
|
55
|
-
|
|
64
|
+
const body = Types.asObject(response.data, {
|
|
65
|
+
name: 'response.data'
|
|
66
|
+
});
|
|
67
|
+
// TODO: https://github.com/ethersphere/bee/issues/4964
|
|
68
|
+
if (body.references === null) {
|
|
69
|
+
return [];
|
|
70
|
+
}
|
|
71
|
+
const references = Types.asArray(body.references, {
|
|
72
|
+
name: 'references'
|
|
73
|
+
}).map(x => Types.asString(x, {
|
|
74
|
+
name: 'reference'
|
|
75
|
+
}));
|
|
76
|
+
return references.map(x => new Reference(x));
|
|
56
77
|
}
|
package/dist/mjs/modules/pss.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { System } from 'cafe-utility';
|
|
1
2
|
import WebSocket from 'isomorphic-ws';
|
|
2
|
-
import {
|
|
3
|
+
import { prepareRequestHeaders } from "../utils/headers.js";
|
|
3
4
|
import { http } from "../utils/http.js";
|
|
4
5
|
const endpoint = 'pss';
|
|
5
6
|
/**
|
|
@@ -22,7 +23,7 @@ export async function send(requestOptions, topic, target, data, postageBatchId,
|
|
|
22
23
|
params: {
|
|
23
24
|
recipient
|
|
24
25
|
},
|
|
25
|
-
headers:
|
|
26
|
+
headers: prepareRequestHeaders(postageBatchId)
|
|
26
27
|
});
|
|
27
28
|
}
|
|
28
29
|
/**
|
|
@@ -31,7 +32,12 @@ export async function send(requestOptions, topic, target, data, postageBatchId,
|
|
|
31
32
|
* @param url Bee node URL
|
|
32
33
|
* @param topic Topic name
|
|
33
34
|
*/
|
|
34
|
-
export function subscribe(url, topic) {
|
|
35
|
+
export function subscribe(url, topic, headers) {
|
|
35
36
|
const wsUrl = url.replace(/^http/i, 'ws');
|
|
36
|
-
|
|
37
|
+
if (System.whereAmI() === 'browser') {
|
|
38
|
+
return new WebSocket(`${wsUrl}/${endpoint}/subscribe/${topic.toHex()}`);
|
|
39
|
+
}
|
|
40
|
+
return new WebSocket(`${wsUrl}/${endpoint}/subscribe/${topic.toHex()}`, {
|
|
41
|
+
headers
|
|
42
|
+
});
|
|
37
43
|
}
|
package/dist/mjs/modules/soc.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Optional, Types } from 'cafe-utility';
|
|
2
|
+
import { prepareRequestHeaders } from "../utils/headers.js";
|
|
2
3
|
import { http } from "../utils/http.js";
|
|
3
4
|
import { makeTagUid } from "../utils/type.js";
|
|
5
|
+
import { Reference } from "../utils/typed-bytes.js";
|
|
4
6
|
const socEndpoint = 'soc';
|
|
5
7
|
/**
|
|
6
8
|
* Upload single owner chunk (SOC) to a Bee node
|
|
@@ -20,16 +22,19 @@ export async function upload(requestOptions, owner, identifier, signature, data,
|
|
|
20
22
|
data,
|
|
21
23
|
headers: {
|
|
22
24
|
'content-type': 'application/octet-stream',
|
|
23
|
-
...
|
|
25
|
+
...prepareRequestHeaders(stamp, options)
|
|
24
26
|
},
|
|
25
27
|
responseType: 'json',
|
|
26
28
|
params: {
|
|
27
|
-
sig: signature
|
|
29
|
+
sig: signature.toHex()
|
|
28
30
|
}
|
|
29
31
|
});
|
|
32
|
+
const body = Types.asObject(response.data, {
|
|
33
|
+
name: 'response.data'
|
|
34
|
+
});
|
|
30
35
|
return {
|
|
31
|
-
reference:
|
|
36
|
+
reference: new Reference(Types.asHexString(body.reference)),
|
|
32
37
|
tagUid: response.headers['swarm-tag'] ? makeTagUid(response.headers['swarm-tag']) : undefined,
|
|
33
|
-
historyAddress: response.headers['swarm-act-history-address']
|
|
38
|
+
historyAddress: response.headers['swarm-act-history-address'] ? Optional.of(new Reference(response.headers['swarm-act-history-address'])) : Optional.empty()
|
|
34
39
|
};
|
|
35
40
|
}
|
|
@@ -1,23 +1,33 @@
|
|
|
1
|
+
import { Types } from 'cafe-utility';
|
|
1
2
|
import { http } from "../utils/http.js";
|
|
3
|
+
import { Reference } from "../utils/typed-bytes.js";
|
|
2
4
|
const stewardshipEndpoint = 'stewardship';
|
|
3
5
|
/**
|
|
4
6
|
* Reupload locally pinned data
|
|
5
7
|
* @param requestOptions Options for making requests
|
|
6
8
|
* @param reference
|
|
7
|
-
* @param options
|
|
8
9
|
* @throws BeeResponseError if not locally pinned or invalid data
|
|
9
10
|
*/
|
|
10
|
-
export async function reupload(requestOptions, reference) {
|
|
11
|
+
export async function reupload(requestOptions, stamp, reference) {
|
|
11
12
|
await http(requestOptions, {
|
|
12
13
|
method: 'put',
|
|
13
|
-
url: `${stewardshipEndpoint}/${reference}
|
|
14
|
+
url: `${stewardshipEndpoint}/${reference}`,
|
|
15
|
+
headers: {
|
|
16
|
+
'swarm-postage-batch-id': stamp.toHex()
|
|
17
|
+
}
|
|
14
18
|
});
|
|
15
19
|
}
|
|
16
20
|
export async function isRetrievable(requestOptions, reference) {
|
|
21
|
+
reference = new Reference(reference);
|
|
17
22
|
const response = await http(requestOptions, {
|
|
18
23
|
method: 'get',
|
|
19
24
|
responseType: 'json',
|
|
20
25
|
url: `${stewardshipEndpoint}/${reference}`
|
|
21
26
|
});
|
|
22
|
-
|
|
27
|
+
const body = Types.asObject(response.data, {
|
|
28
|
+
name: 'response.data'
|
|
29
|
+
});
|
|
30
|
+
return Types.asBoolean(body.isRetrievable, {
|
|
31
|
+
name: 'isRetrievable'
|
|
32
|
+
});
|
|
23
33
|
}
|
package/dist/mjs/modules/tag.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Types } from 'cafe-utility';
|
|
1
2
|
import { http } from "../utils/http.js";
|
|
2
3
|
const endpoint = 'tags';
|
|
3
4
|
/**
|
|
@@ -11,7 +12,35 @@ export async function createTag(requestOptions) {
|
|
|
11
12
|
url: endpoint,
|
|
12
13
|
responseType: 'json'
|
|
13
14
|
});
|
|
14
|
-
|
|
15
|
+
const body = Types.asObject(response.data, {
|
|
16
|
+
name: 'response.data'
|
|
17
|
+
});
|
|
18
|
+
return {
|
|
19
|
+
address: Types.asEmptiableString(body.address, {
|
|
20
|
+
name: 'address'
|
|
21
|
+
}),
|
|
22
|
+
seen: Types.asNumber(body.seen, {
|
|
23
|
+
name: 'seen'
|
|
24
|
+
}),
|
|
25
|
+
sent: Types.asNumber(body.sent, {
|
|
26
|
+
name: 'sent'
|
|
27
|
+
}),
|
|
28
|
+
split: Types.asNumber(body.split, {
|
|
29
|
+
name: 'split'
|
|
30
|
+
}),
|
|
31
|
+
startedAt: Types.asString(body.startedAt, {
|
|
32
|
+
name: 'startedAt'
|
|
33
|
+
}),
|
|
34
|
+
stored: Types.asNumber(body.stored, {
|
|
35
|
+
name: 'stored'
|
|
36
|
+
}),
|
|
37
|
+
synced: Types.asNumber(body.synced, {
|
|
38
|
+
name: 'synced'
|
|
39
|
+
}),
|
|
40
|
+
uid: Types.asNumber(body.uid, {
|
|
41
|
+
name: 'uid'
|
|
42
|
+
})
|
|
43
|
+
};
|
|
15
44
|
}
|
|
16
45
|
/**
|
|
17
46
|
* Retrieve tag information from Bee node
|
|
@@ -24,7 +53,35 @@ export async function retrieveTag(requestOptions, uid) {
|
|
|
24
53
|
url: `${endpoint}/${uid}`,
|
|
25
54
|
responseType: 'json'
|
|
26
55
|
});
|
|
27
|
-
|
|
56
|
+
const body = Types.asObject(response.data, {
|
|
57
|
+
name: 'response.data'
|
|
58
|
+
});
|
|
59
|
+
return {
|
|
60
|
+
address: Types.asEmptiableString(body.address, {
|
|
61
|
+
name: 'address'
|
|
62
|
+
}),
|
|
63
|
+
seen: Types.asNumber(body.seen, {
|
|
64
|
+
name: 'seen'
|
|
65
|
+
}),
|
|
66
|
+
sent: Types.asNumber(body.sent, {
|
|
67
|
+
name: 'sent'
|
|
68
|
+
}),
|
|
69
|
+
split: Types.asNumber(body.split, {
|
|
70
|
+
name: 'split'
|
|
71
|
+
}),
|
|
72
|
+
startedAt: Types.asString(body.startedAt, {
|
|
73
|
+
name: 'startedAt'
|
|
74
|
+
}),
|
|
75
|
+
stored: Types.asNumber(body.stored, {
|
|
76
|
+
name: 'stored'
|
|
77
|
+
}),
|
|
78
|
+
synced: Types.asNumber(body.synced, {
|
|
79
|
+
name: 'synced'
|
|
80
|
+
}),
|
|
81
|
+
uid: Types.asNumber(body.uid, {
|
|
82
|
+
name: 'uid'
|
|
83
|
+
})
|
|
84
|
+
};
|
|
28
85
|
}
|
|
29
86
|
/**
|
|
30
87
|
* Get limited listing of all tags.
|
|
@@ -42,7 +99,40 @@ export async function getAllTags(requestOptions, offset, limit) {
|
|
|
42
99
|
},
|
|
43
100
|
responseType: 'json'
|
|
44
101
|
});
|
|
45
|
-
|
|
102
|
+
const body = Types.asObject(response.data, {
|
|
103
|
+
name: 'response.data'
|
|
104
|
+
});
|
|
105
|
+
const tags = Types.asArray(body.tags, {
|
|
106
|
+
name: 'tags'
|
|
107
|
+
}).map(x => Types.asObject(x, {
|
|
108
|
+
name: 'tag'
|
|
109
|
+
}));
|
|
110
|
+
return tags.map(x => ({
|
|
111
|
+
address: Types.asEmptiableString(x.address, {
|
|
112
|
+
name: 'address'
|
|
113
|
+
}),
|
|
114
|
+
seen: Types.asNumber(x.seen, {
|
|
115
|
+
name: 'seen'
|
|
116
|
+
}),
|
|
117
|
+
sent: Types.asNumber(x.sent, {
|
|
118
|
+
name: 'sent'
|
|
119
|
+
}),
|
|
120
|
+
split: Types.asNumber(x.split, {
|
|
121
|
+
name: 'split'
|
|
122
|
+
}),
|
|
123
|
+
startedAt: Types.asString(x.startedAt, {
|
|
124
|
+
name: 'startedAt'
|
|
125
|
+
}),
|
|
126
|
+
stored: Types.asNumber(x.stored, {
|
|
127
|
+
name: 'stored'
|
|
128
|
+
}),
|
|
129
|
+
synced: Types.asNumber(x.synced, {
|
|
130
|
+
name: 'synced'
|
|
131
|
+
}),
|
|
132
|
+
uid: Types.asNumber(x.uid, {
|
|
133
|
+
name: 'uid'
|
|
134
|
+
})
|
|
135
|
+
}));
|
|
46
136
|
}
|
|
47
137
|
/**
|
|
48
138
|
* Removes tag from the Bee node.
|
package/dist/mjs/package.json
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
"fs": false,
|
|
6
6
|
"./utils/tar.js": "./utils/tar.browser.js",
|
|
7
7
|
"./utils/tar-writer.js": "./utils/tar-writer.browser.js",
|
|
8
|
-
|
|
8
|
+
"./utils/tar-uploader.js": "./utils/tar-uploader.browser.js",
|
|
9
|
+
"./utils/chunk-stream.js": "./utils/chunk-stream.browser.js",
|
|
9
10
|
"./utils/data.js": "./utils/data.browser.js",
|
|
10
11
|
"./utils/collection.node.js": "./utils/collection.browser.js"
|
|
11
12
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Binary } from 'cafe-utility';
|
|
2
|
+
import { BatchId, PrivateKey } from "../utils/typed-bytes.js";
|
|
3
|
+
export class Stamper {
|
|
4
|
+
constructor(signer, batchId, buckets, depth) {
|
|
5
|
+
this.signer = new PrivateKey(signer);
|
|
6
|
+
this.batchId = new BatchId(batchId);
|
|
7
|
+
this.buckets = buckets;
|
|
8
|
+
this.depth = depth;
|
|
9
|
+
this.maxSlot = 2 ** (this.depth - 16);
|
|
10
|
+
}
|
|
11
|
+
static fromBlank(signer, batchId, depth) {
|
|
12
|
+
return new Stamper(signer, batchId, new Uint32Array(65536), depth);
|
|
13
|
+
}
|
|
14
|
+
static fromState(signer, batchId, buckets, depth) {
|
|
15
|
+
return new Stamper(signer, batchId, buckets, depth);
|
|
16
|
+
}
|
|
17
|
+
stamp(chunk) {
|
|
18
|
+
const address = chunk.hash();
|
|
19
|
+
const bucket = Binary.uint16ToNumber(address, 'BE');
|
|
20
|
+
const height = this.buckets[bucket];
|
|
21
|
+
if (height >= this.maxSlot) {
|
|
22
|
+
throw Error('Bucket is full');
|
|
23
|
+
}
|
|
24
|
+
this.buckets[bucket]++;
|
|
25
|
+
const index = Binary.concatBytes(Binary.numberToUint32(bucket, 'BE'), Binary.numberToUint32(height, 'BE'));
|
|
26
|
+
const timestamp = Binary.numberToUint64(BigInt(Date.now()), 'BE');
|
|
27
|
+
const signature = this.signer.sign(Binary.concatBytes(address, this.batchId.toUint8Array(), index, timestamp));
|
|
28
|
+
return {
|
|
29
|
+
batchId: this.batchId,
|
|
30
|
+
index,
|
|
31
|
+
issuer: this.signer.publicKey().address().toUint8Array(),
|
|
32
|
+
signature: signature.toUint8Array(),
|
|
33
|
+
timestamp
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
getState() {
|
|
37
|
+
return this.buckets;
|
|
38
|
+
}
|
|
39
|
+
}
|
package/dist/mjs/types/debug.js
CHANGED
|
@@ -4,4 +4,18 @@ export var BeeModes;
|
|
|
4
4
|
BeeModes["LIGHT"] = "light";
|
|
5
5
|
BeeModes["ULTRA_LIGHT"] = "ultra-light";
|
|
6
6
|
BeeModes["DEV"] = "dev";
|
|
7
|
-
})(BeeModes || (BeeModes = {}));
|
|
7
|
+
})(BeeModes || (BeeModes = {}));
|
|
8
|
+
export function toBeeMode(value) {
|
|
9
|
+
switch (value) {
|
|
10
|
+
case 'full':
|
|
11
|
+
return BeeModes.FULL;
|
|
12
|
+
case 'light':
|
|
13
|
+
return BeeModes.LIGHT;
|
|
14
|
+
case 'ultra-light':
|
|
15
|
+
return BeeModes.ULTRA_LIGHT;
|
|
16
|
+
case 'dev':
|
|
17
|
+
return BeeModes.DEV;
|
|
18
|
+
default:
|
|
19
|
+
throw new Error(`Unknown Bee mode: ${value}`);
|
|
20
|
+
}
|
|
21
|
+
}
|
package/dist/mjs/types/index.js
CHANGED
|
@@ -1,24 +1,12 @@
|
|
|
1
1
|
export * from "./debug.js";
|
|
2
|
-
export const SPAN_SIZE = 8;
|
|
3
2
|
export const SECTION_SIZE = 32;
|
|
4
3
|
export const BRANCHES = 128;
|
|
5
4
|
export const CHUNK_SIZE = SECTION_SIZE * BRANCHES;
|
|
6
|
-
export const
|
|
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;
|
|
5
|
+
export const PSS_TARGET_HEX_LENGTH_MAX = 4;
|
|
14
6
|
/**
|
|
15
7
|
* Minimal depth that can be used for creation of postage batch
|
|
16
8
|
*/
|
|
17
9
|
export const STAMPS_DEPTH_MIN = 17;
|
|
18
|
-
/**
|
|
19
|
-
* Minimal amount that can be used for creation of postage batch
|
|
20
|
-
*/
|
|
21
|
-
export const STAMPS_AMOUNT_MIN = 24000 * 24 * 60 * 12;
|
|
22
10
|
/**
|
|
23
11
|
* Maximal depth that can be used for creation of postage batch
|
|
24
12
|
*/
|
|
@@ -54,14 +42,4 @@ export var RedundancyStrategy;
|
|
|
54
42
|
RedundancyStrategy[RedundancyStrategy["DATA"] = 1] = "DATA";
|
|
55
43
|
RedundancyStrategy[RedundancyStrategy["PROX"] = 2] = "PROX";
|
|
56
44
|
RedundancyStrategy[RedundancyStrategy["RACE"] = 3] = "RACE";
|
|
57
|
-
})(RedundancyStrategy || (RedundancyStrategy = {}));
|
|
58
|
-
/*********************************************************
|
|
59
|
-
* Writers and Readers interfaces
|
|
60
|
-
*/
|
|
61
|
-
export const TOPIC_BYTES_LENGTH = 32;
|
|
62
|
-
export const TOPIC_HEX_LENGTH = 64;
|
|
63
|
-
/*********************************************************
|
|
64
|
-
* Ethereum compatible signing interfaces and definitions
|
|
65
|
-
*/
|
|
66
|
-
export const SIGNATURE_HEX_LENGTH = 130;
|
|
67
|
-
export const SIGNATURE_BYTES_LENGTH = 65;
|
|
45
|
+
})(RedundancyStrategy || (RedundancyStrategy = {}));
|