@ethersphere/bee-js 5.1.1 → 5.1.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 +14 -6
- package/dist/223.index.browser.min.js +3 -0
- package/dist/223.index.browser.min.js.LICENSE.txt +1 -0
- package/dist/223.index.browser.min.js.map +1 -0
- package/dist/cjs/bee-debug.js +208 -312
- package/dist/cjs/bee.js +258 -353
- package/dist/cjs/chunk/signer.js +11 -22
- package/dist/cjs/chunk/soc.js +33 -50
- package/dist/cjs/chunk/span.js +1 -1
- package/dist/cjs/feed/index.js +50 -65
- package/dist/cjs/feed/json.js +8 -21
- package/dist/cjs/feed/retrievable.js +14 -27
- package/dist/cjs/modules/bytes.js +25 -37
- package/dist/cjs/modules/bzz.js +63 -68
- package/dist/cjs/modules/chunk.js +17 -27
- package/dist/cjs/modules/debug/balance.js +24 -41
- package/dist/cjs/modules/debug/chequebook.js +71 -96
- package/dist/cjs/modules/debug/chunk.js +13 -26
- package/dist/cjs/modules/debug/connectivity.js +32 -53
- package/dist/cjs/modules/debug/settlements.js +12 -25
- package/dist/cjs/modules/debug/stake.js +20 -33
- package/dist/cjs/modules/debug/stamps.js +45 -66
- package/dist/cjs/modules/debug/states.js +27 -40
- package/dist/cjs/modules/debug/status.js +53 -80
- package/dist/cjs/modules/debug/tag.js +6 -17
- package/dist/cjs/modules/debug/transactions.js +23 -40
- package/dist/cjs/modules/feed.js +17 -27
- package/dist/cjs/modules/pinning.js +24 -41
- package/dist/cjs/modules/pss.js +9 -20
- package/dist/cjs/modules/soc.js +12 -20
- package/dist/cjs/modules/status.js +4 -15
- package/dist/cjs/modules/stewardship.js +10 -23
- package/dist/cjs/modules/tag.js +28 -47
- package/dist/cjs/utils/collection.browser.js +4 -17
- package/dist/cjs/utils/collection.js +11 -22
- package/dist/cjs/utils/collection.node.js +42 -86
- package/dist/cjs/utils/data.browser.js +46 -59
- package/dist/cjs/utils/data.js +22 -35
- package/dist/cjs/utils/eth.js +31 -43
- package/dist/cjs/utils/file.js +9 -20
- package/dist/cjs/utils/headers.js +4 -4
- package/dist/cjs/utils/http.js +78 -93
- package/dist/cjs/utils/merge.js +1 -1
- package/dist/cjs/utils/sleep.js +2 -13
- package/dist/cjs/utils/type.js +14 -12
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.LICENSE.txt +1 -3
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/bee-debug.js +209 -450
- package/dist/mjs/bee.js +256 -491
- package/dist/mjs/chunk/bmt.js +4 -10
- package/dist/mjs/chunk/cac.js +0 -3
- package/dist/mjs/chunk/signer.js +12 -63
- package/dist/mjs/chunk/soc.js +33 -85
- package/dist/mjs/chunk/span.js +3 -6
- package/dist/mjs/feed/identifier.js +0 -6
- package/dist/mjs/feed/index.js +53 -97
- package/dist/mjs/feed/json.js +10 -49
- package/dist/mjs/feed/retrievable.js +13 -64
- package/dist/mjs/feed/topic.js +0 -2
- package/dist/mjs/index.js +1 -2
- package/dist/mjs/modules/bytes.js +25 -65
- package/dist/mjs/modules/bzz.js +64 -108
- package/dist/mjs/modules/chunk.js +17 -54
- package/dist/mjs/modules/debug/balance.js +24 -68
- package/dist/mjs/modules/debug/chequebook.js +75 -138
- package/dist/mjs/modules/debug/chunk.js +13 -51
- package/dist/mjs/modules/debug/connectivity.js +32 -76
- package/dist/mjs/modules/debug/settlements.js +12 -50
- package/dist/mjs/modules/debug/stake.js +20 -61
- package/dist/mjs/modules/debug/stamps.js +47 -94
- package/dist/mjs/modules/debug/states.js +25 -66
- package/dist/mjs/modules/debug/status.js +66 -125
- package/dist/mjs/modules/debug/tag.js +6 -41
- package/dist/mjs/modules/debug/transactions.js +25 -69
- package/dist/mjs/modules/feed.js +17 -57
- package/dist/mjs/modules/pinning.js +24 -68
- package/dist/mjs/modules/pss.js +11 -47
- package/dist/mjs/modules/soc.js +14 -48
- package/dist/mjs/modules/status.js +4 -39
- package/dist/mjs/modules/stewardship.js +10 -47
- package/dist/mjs/modules/tag.js +31 -78
- package/dist/mjs/types/debug.js +0 -1
- package/dist/mjs/types/index.js +0 -4
- package/dist/mjs/utils/bytes.js +6 -14
- package/dist/mjs/utils/collection.browser.js +4 -42
- package/dist/mjs/utils/collection.js +11 -57
- package/dist/mjs/utils/collection.node.js +42 -150
- package/dist/mjs/utils/data.browser.js +49 -94
- package/dist/mjs/utils/data.js +19 -62
- package/dist/mjs/utils/error.js +0 -5
- package/dist/mjs/utils/eth.js +37 -95
- package/dist/mjs/utils/file.js +11 -50
- package/dist/mjs/utils/hash.js +0 -1
- package/dist/mjs/utils/headers.js +6 -14
- package/dist/mjs/utils/hex.js +6 -25
- package/dist/mjs/utils/http.js +80 -138
- package/dist/mjs/utils/merge.js +3 -7
- package/dist/mjs/utils/pss.js +0 -2
- package/dist/mjs/utils/reference.js +2 -5
- package/dist/mjs/utils/sleep.js +2 -37
- package/dist/mjs/utils/stream.js +0 -23
- package/dist/mjs/utils/tar.js +2 -5
- package/dist/mjs/utils/type.js +18 -82
- package/dist/mjs/utils/uint64.js +0 -1
- package/dist/mjs/utils/url.js +2 -10
- package/dist/types/bee-debug.d.ts +2 -2
- package/dist/types/bee.d.ts +2 -26
- package/dist/types/chunk/cac.d.ts +1 -1
- package/dist/types/chunk/soc.d.ts +8 -7
- package/dist/types/feed/index.d.ts +9 -8
- package/dist/types/feed/type.d.ts +1 -1
- package/dist/types/modules/bytes.d.ts +6 -5
- package/dist/types/modules/bzz.d.ts +9 -8
- package/dist/types/modules/chunk.d.ts +5 -4
- package/dist/types/modules/debug/balance.d.ts +10 -9
- package/dist/types/modules/debug/chequebook.d.ts +18 -17
- package/dist/types/modules/debug/chunk.d.ts +6 -5
- package/dist/types/modules/debug/connectivity.d.ts +8 -7
- package/dist/types/modules/debug/settlements.d.ts +6 -5
- package/dist/types/modules/debug/stake.d.ts +5 -4
- package/dist/types/modules/debug/stamps.d.ts +8 -7
- package/dist/types/modules/debug/states.d.ts +8 -7
- package/dist/types/modules/debug/status.d.ts +15 -15
- package/dist/types/modules/debug/tag.d.ts +4 -3
- package/dist/types/modules/debug/transactions.d.ts +6 -5
- package/dist/types/modules/feed.d.ts +4 -3
- package/dist/types/modules/pinning.d.ts +8 -7
- package/dist/types/modules/pss.d.ts +4 -3
- package/dist/types/modules/soc.d.ts +3 -2
- package/dist/types/modules/status.d.ts +3 -3
- package/dist/types/modules/stewardship.d.ts +4 -3
- package/dist/types/modules/tag.d.ts +7 -6
- package/dist/types/types/debug.d.ts +1 -1
- package/dist/types/types/index.d.ts +30 -34
- package/dist/types/utils/eth.d.ts +3 -3
- package/dist/types/utils/hex.d.ts +2 -2
- package/dist/types/utils/http.d.ts +6 -6
- package/package.json +34 -39
- package/dist/cjs/types/ky-options.js +0 -8
- package/dist/cjs/types/ky-universal/common.js +0 -8
- package/dist/cjs/types/ky-universal/hooks.js +0 -8
- package/dist/cjs/types/ky-universal/retry.js +0 -8
- package/dist/mjs/types/ky-options.js +0 -7
- package/dist/mjs/types/ky-universal/common.js +0 -7
- package/dist/mjs/types/ky-universal/hooks.js +0 -7
- package/dist/mjs/types/ky-universal/retry.js +0 -7
- package/dist/types/types/ky-options.d.ts +0 -221
- package/dist/types/types/ky-universal/common.d.ts +0 -13
- package/dist/types/types/ky-universal/hooks.d.ts +0 -92
- package/dist/types/types/ky-universal/retry.d.ts +0 -38
package/dist/cjs/chunk/signer.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -120,18 +111,16 @@ function makeSigner(signer) {
|
|
|
120
111
|
return signer;
|
|
121
112
|
}
|
|
122
113
|
exports.makeSigner = makeSigner;
|
|
123
|
-
function sign(signer, data) {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
throw new TypeError('Invalid output of sign function!');
|
|
135
|
-
});
|
|
114
|
+
async function sign(signer, data) {
|
|
115
|
+
const result = await signer.sign((0, bytes_1.wrapBytesWithHelpers)(data));
|
|
116
|
+
if (typeof result === 'string') {
|
|
117
|
+
const hexString = (0, hex_1.makeHexString)(result, types_1.SIGNATURE_HEX_LENGTH);
|
|
118
|
+
return (0, hex_1.hexToBytes)(hexString);
|
|
119
|
+
}
|
|
120
|
+
if (result instanceof Uint8Array) {
|
|
121
|
+
(0, bytes_1.assertBytes)(result, types_1.SIGNATURE_BYTES_LENGTH);
|
|
122
|
+
return result;
|
|
123
|
+
}
|
|
124
|
+
throw new TypeError('Invalid output of sign function!');
|
|
136
125
|
}
|
|
137
126
|
exports.sign = sign;
|
package/dist/cjs/chunk/soc.js
CHANGED
|
@@ -22,15 +22,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
26
|
exports.downloadSingleOwnerChunk = exports.uploadSingleOwnerChunkData = exports.uploadSingleOwnerChunk = exports.makeSingleOwnerChunk = exports.makeSOCAddress = exports.makeSingleOwnerChunkFromData = void 0;
|
|
36
27
|
const bytes_1 = require("../utils/bytes");
|
|
@@ -100,24 +91,22 @@ exports.makeSOCAddress = makeSOCAddress;
|
|
|
100
91
|
* @param identifier The identifier of the chunk
|
|
101
92
|
* @param signer The singer interface for signing the chunk
|
|
102
93
|
*/
|
|
103
|
-
function makeSingleOwnerChunk(chunk, identifier, signer) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
};
|
|
120
|
-
});
|
|
94
|
+
async function makeSingleOwnerChunk(chunk, identifier, signer) {
|
|
95
|
+
const chunkAddress = chunk.address();
|
|
96
|
+
(0, cac_1.assertValidChunkData)(chunk.data, chunkAddress);
|
|
97
|
+
const digest = (0, hash_1.keccak256Hash)(identifier, chunkAddress);
|
|
98
|
+
const signature = await (0, signer_1.sign)(signer, digest);
|
|
99
|
+
const data = (0, serialize_1.serializeBytes)(identifier, signature, chunk.span(), chunk.payload());
|
|
100
|
+
const address = makeSOCAddress(identifier, signer.address);
|
|
101
|
+
return {
|
|
102
|
+
data,
|
|
103
|
+
identifier: () => identifier,
|
|
104
|
+
signature: () => signature,
|
|
105
|
+
span: () => chunk.span(),
|
|
106
|
+
payload: () => chunk.payload(),
|
|
107
|
+
address: () => address,
|
|
108
|
+
owner: () => signer.address,
|
|
109
|
+
};
|
|
121
110
|
}
|
|
122
111
|
exports.makeSingleOwnerChunk = makeSingleOwnerChunk;
|
|
123
112
|
/**
|
|
@@ -125,38 +114,34 @@ exports.makeSingleOwnerChunk = makeSingleOwnerChunk;
|
|
|
125
114
|
*
|
|
126
115
|
* It uses the Chunk API and calculates the address before uploading.
|
|
127
116
|
*
|
|
128
|
-
* @param
|
|
117
|
+
* @param kyOptions Ky Options for making requests
|
|
129
118
|
* @param chunk A chunk object
|
|
130
119
|
* @param postageBatchId Postage BatchId that will be assigned to uploaded data
|
|
131
120
|
* @param options Upload options
|
|
132
121
|
*/
|
|
133
|
-
function uploadSingleOwnerChunk(
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
return socAPI.upload(ky, owner, identifier, signature, data, postageBatchId, options);
|
|
140
|
-
});
|
|
122
|
+
async function uploadSingleOwnerChunk(kyOptions, chunk, postageBatchId, options) {
|
|
123
|
+
const owner = (0, hex_1.bytesToHex)(chunk.owner());
|
|
124
|
+
const identifier = (0, hex_1.bytesToHex)(chunk.identifier());
|
|
125
|
+
const signature = (0, hex_1.bytesToHex)(chunk.signature());
|
|
126
|
+
const data = (0, serialize_1.serializeBytes)(chunk.span(), chunk.payload());
|
|
127
|
+
return socAPI.upload(kyOptions, owner, identifier, signature, data, postageBatchId, options);
|
|
141
128
|
}
|
|
142
129
|
exports.uploadSingleOwnerChunk = uploadSingleOwnerChunk;
|
|
143
130
|
/**
|
|
144
131
|
* Helper function to create and upload SOC.
|
|
145
132
|
*
|
|
146
|
-
* @param
|
|
133
|
+
* @param kyOptions Ky Options for making requests
|
|
147
134
|
* @param signer The singer interface for signing the chunk
|
|
148
135
|
* @param postageBatchId
|
|
149
136
|
* @param identifier The identifier of the chunk
|
|
150
137
|
* @param data The chunk data
|
|
151
138
|
* @param options
|
|
152
139
|
*/
|
|
153
|
-
function uploadSingleOwnerChunkData(
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
return uploadSingleOwnerChunk(ky, soc, postageBatchId, options);
|
|
159
|
-
});
|
|
140
|
+
async function uploadSingleOwnerChunkData(kyOptions, signer, postageBatchId, identifier, data, options) {
|
|
141
|
+
(0, type_1.assertAddress)(postageBatchId);
|
|
142
|
+
const cac = (0, cac_1.makeContentAddressedChunk)(data);
|
|
143
|
+
const soc = await makeSingleOwnerChunk(cac, identifier, signer);
|
|
144
|
+
return uploadSingleOwnerChunk(kyOptions, soc, postageBatchId, options);
|
|
160
145
|
}
|
|
161
146
|
exports.uploadSingleOwnerChunkData = uploadSingleOwnerChunkData;
|
|
162
147
|
/**
|
|
@@ -166,11 +151,9 @@ exports.uploadSingleOwnerChunkData = uploadSingleOwnerChunkData;
|
|
|
166
151
|
* @param ownerAddress The singer interface for signing the chunk
|
|
167
152
|
* @param identifier The identifier of the chunk
|
|
168
153
|
*/
|
|
169
|
-
function downloadSingleOwnerChunk(
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
return makeSingleOwnerChunkFromData(data, address);
|
|
174
|
-
});
|
|
154
|
+
async function downloadSingleOwnerChunk(kyOptions, ownerAddress, identifier) {
|
|
155
|
+
const address = makeSOCAddress(identifier, ownerAddress);
|
|
156
|
+
const data = await chunkAPI.download(kyOptions, (0, hex_1.bytesToHex)(address));
|
|
157
|
+
return makeSingleOwnerChunkFromData(data, address);
|
|
175
158
|
}
|
|
176
159
|
exports.downloadSingleOwnerChunk = downloadSingleOwnerChunk;
|
package/dist/cjs/chunk/span.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.makeSpan = exports.SPAN_SIZE = void 0;
|
|
|
4
4
|
const error_1 = require("../utils/error");
|
|
5
5
|
exports.SPAN_SIZE = 8;
|
|
6
6
|
// we limit the maximum span size in 32 bits to avoid BigInt compatibility issues
|
|
7
|
-
const MAX_SPAN_LENGTH =
|
|
7
|
+
const MAX_SPAN_LENGTH = 2 ** 32 - 1;
|
|
8
8
|
/**
|
|
9
9
|
* Create a span for storing the length of the chunk
|
|
10
10
|
*
|
package/dist/cjs/feed/index.js
CHANGED
|
@@ -22,15 +22,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
26
|
exports.makeFeedWriter = exports.makeFeedReader = exports.downloadFeedUpdate = exports.getFeedUpdateChunkReference = exports.updateFeed = exports.findNextIndex = void 0;
|
|
36
27
|
const hash_1 = require("../utils/hash");
|
|
@@ -50,32 +41,27 @@ const reference_1 = require("../utils/reference");
|
|
|
50
41
|
const TIMESTAMP_PAYLOAD_OFFSET = 0;
|
|
51
42
|
const TIMESTAMP_PAYLOAD_SIZE = 8;
|
|
52
43
|
const REFERENCE_PAYLOAD_OFFSET = TIMESTAMP_PAYLOAD_SIZE;
|
|
53
|
-
function findNextIndex(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return (0, hex_1.bytesToHex)((0, bytes_1.makeBytes)(8));
|
|
62
|
-
}
|
|
63
|
-
throw e;
|
|
44
|
+
async function findNextIndex(kyOptions, owner, topic, options) {
|
|
45
|
+
try {
|
|
46
|
+
const feedUpdate = await (0, feed_1.fetchLatestFeedUpdate)(kyOptions, owner, topic, options);
|
|
47
|
+
return (0, hex_1.makeHexString)(feedUpdate.feedIndexNext, types_1.FEED_INDEX_HEX_LENGTH);
|
|
48
|
+
}
|
|
49
|
+
catch (e) {
|
|
50
|
+
if (e instanceof error_1.BeeResponseError && e.status === 404) {
|
|
51
|
+
return (0, hex_1.bytesToHex)((0, bytes_1.makeBytes)(8));
|
|
64
52
|
}
|
|
65
|
-
|
|
53
|
+
throw e;
|
|
54
|
+
}
|
|
66
55
|
}
|
|
67
56
|
exports.findNextIndex = findNextIndex;
|
|
68
|
-
function updateFeed(
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
const payloadBytes = (0, serialize_1.serializeBytes)(timestamp, reference);
|
|
77
|
-
return (0, soc_1.uploadSingleOwnerChunkData)(ky, signer, postageBatchId, identifier, payloadBytes, options);
|
|
78
|
-
});
|
|
57
|
+
async function updateFeed(kyOptions, signer, topic, reference, postageBatchId, options, index = 'latest') {
|
|
58
|
+
const ownerHex = (0, eth_1.makeHexEthAddress)(signer.address);
|
|
59
|
+
const nextIndex = index === 'latest' ? await findNextIndex(kyOptions, ownerHex, topic, options) : index;
|
|
60
|
+
const identifier = (0, identifier_1.makeFeedIdentifier)(topic, nextIndex);
|
|
61
|
+
const at = options?.at ?? Date.now() / 1000.0;
|
|
62
|
+
const timestamp = (0, uint64_1.writeUint64BigEndian)(at);
|
|
63
|
+
const payloadBytes = (0, serialize_1.serializeBytes)(timestamp, reference);
|
|
64
|
+
return (0, soc_1.uploadSingleOwnerChunkData)(kyOptions, signer, postageBatchId, identifier, payloadBytes, options);
|
|
79
65
|
}
|
|
80
66
|
exports.updateFeed = updateFeed;
|
|
81
67
|
function getFeedUpdateChunkReference(owner, topic, index) {
|
|
@@ -83,50 +69,49 @@ function getFeedUpdateChunkReference(owner, topic, index) {
|
|
|
83
69
|
return (0, hash_1.keccak256Hash)(identifier, owner);
|
|
84
70
|
}
|
|
85
71
|
exports.getFeedUpdateChunkReference = getFeedUpdateChunkReference;
|
|
86
|
-
function downloadFeedUpdate(
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
};
|
|
100
|
-
});
|
|
72
|
+
async function downloadFeedUpdate(kyOptions, owner, topic, index) {
|
|
73
|
+
const address = getFeedUpdateChunkReference(owner, topic, index);
|
|
74
|
+
const addressHex = (0, hex_1.bytesToHex)(address);
|
|
75
|
+
const data = await chunkAPI.download(kyOptions, addressHex);
|
|
76
|
+
const soc = (0, soc_1.makeSingleOwnerChunkFromData)(data, address);
|
|
77
|
+
const payload = soc.payload();
|
|
78
|
+
const timestampBytes = (0, bytes_1.bytesAtOffset)(payload, TIMESTAMP_PAYLOAD_OFFSET, TIMESTAMP_PAYLOAD_SIZE);
|
|
79
|
+
const timestamp = (0, uint64_1.readUint64BigEndian)(timestampBytes);
|
|
80
|
+
const reference = (0, reference_1.makeBytesReference)(payload, REFERENCE_PAYLOAD_OFFSET);
|
|
81
|
+
return {
|
|
82
|
+
timestamp,
|
|
83
|
+
reference,
|
|
84
|
+
};
|
|
101
85
|
}
|
|
102
86
|
exports.downloadFeedUpdate = downloadFeedUpdate;
|
|
103
|
-
function makeFeedReader(
|
|
87
|
+
function makeFeedReader(kyOptions, type, topic, owner) {
|
|
104
88
|
return {
|
|
105
89
|
type,
|
|
106
90
|
owner,
|
|
107
91
|
topic,
|
|
108
|
-
download(options) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
};
|
|
119
|
-
});
|
|
92
|
+
async download(options) {
|
|
93
|
+
if (!options?.index) {
|
|
94
|
+
return (0, feed_1.fetchLatestFeedUpdate)(kyOptions, owner, topic, { ...options, type });
|
|
95
|
+
}
|
|
96
|
+
const update = await downloadFeedUpdate(kyOptions, (0, hex_1.hexToBytes)(owner), topic, options.index);
|
|
97
|
+
return {
|
|
98
|
+
reference: (0, hex_1.bytesToHex)(update.reference),
|
|
99
|
+
feedIndex: options.index,
|
|
100
|
+
feedIndexNext: '',
|
|
101
|
+
};
|
|
120
102
|
},
|
|
121
103
|
};
|
|
122
104
|
}
|
|
123
105
|
exports.makeFeedReader = makeFeedReader;
|
|
124
|
-
function makeFeedWriter(
|
|
125
|
-
const upload = (postageBatchId, reference, options) =>
|
|
106
|
+
function makeFeedWriter(kyOptions, type, topic, signer) {
|
|
107
|
+
const upload = async (postageBatchId, reference, options) => {
|
|
126
108
|
(0, type_1.assertAddress)(postageBatchId);
|
|
127
109
|
const canonicalReference = (0, reference_1.makeBytesReference)(reference);
|
|
128
|
-
return updateFeed(
|
|
129
|
-
}
|
|
130
|
-
return
|
|
110
|
+
return updateFeed(kyOptions, signer, topic, canonicalReference, postageBatchId, { ...options, type });
|
|
111
|
+
};
|
|
112
|
+
return {
|
|
113
|
+
...makeFeedReader(kyOptions, type, topic, (0, eth_1.makeHexEthAddress)(signer.address)),
|
|
114
|
+
upload,
|
|
115
|
+
};
|
|
131
116
|
}
|
|
132
117
|
exports.makeFeedWriter = makeFeedWriter;
|
package/dist/cjs/feed/json.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.setJsonData = exports.getJsonData = void 0;
|
|
13
4
|
const type_1 = require("../utils/type");
|
|
@@ -23,19 +14,15 @@ function serializeJson(data) {
|
|
|
23
14
|
throw e;
|
|
24
15
|
}
|
|
25
16
|
}
|
|
26
|
-
function getJsonData(bee, reader) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return retrievedData.json();
|
|
31
|
-
});
|
|
17
|
+
async function getJsonData(bee, reader) {
|
|
18
|
+
const feedUpdate = await reader.download();
|
|
19
|
+
const retrievedData = await bee.downloadData(feedUpdate.reference);
|
|
20
|
+
return retrievedData.json();
|
|
32
21
|
}
|
|
33
22
|
exports.getJsonData = getJsonData;
|
|
34
|
-
function setJsonData(bee, writer, postageBatchId, data, options) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return writer.upload(postageBatchId, reference);
|
|
39
|
-
});
|
|
23
|
+
async function setJsonData(bee, writer, postageBatchId, data, options) {
|
|
24
|
+
const serializedData = serializeJson(data);
|
|
25
|
+
const { reference } = await bee.uploadData(postageBatchId, serializedData, options);
|
|
26
|
+
return writer.upload(postageBatchId, reference);
|
|
40
27
|
}
|
|
41
28
|
exports.setJsonData = setJsonData;
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.areAllSequentialFeedsUpdateRetrievable = void 0;
|
|
13
4
|
const index_1 = require("./index");
|
|
@@ -33,20 +24,18 @@ function makeNumericIndex(index) {
|
|
|
33
24
|
* @param ref
|
|
34
25
|
* @param options
|
|
35
26
|
*/
|
|
36
|
-
function isChunkRetrievable(bee, ref, options) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
return false;
|
|
46
|
-
}
|
|
47
|
-
throw e;
|
|
27
|
+
async function isChunkRetrievable(bee, ref, options) {
|
|
28
|
+
try {
|
|
29
|
+
await bee.downloadChunk(ref, options);
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
catch (e) {
|
|
33
|
+
const err = e;
|
|
34
|
+
if (err.status === 404) {
|
|
35
|
+
return false;
|
|
48
36
|
}
|
|
49
|
-
|
|
37
|
+
throw e;
|
|
38
|
+
}
|
|
50
39
|
}
|
|
51
40
|
/**
|
|
52
41
|
* Creates array of references for all sequence updates chunk up to the given index.
|
|
@@ -63,10 +52,8 @@ function getAllSequenceUpdateReferences(owner, topic, index) {
|
|
|
63
52
|
}
|
|
64
53
|
return updateReferences;
|
|
65
54
|
}
|
|
66
|
-
function areAllSequentialFeedsUpdateRetrievable(bee, owner, topic, index, options) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return (yield Promise.all(chunkRetrievablePromises)).every(result => result);
|
|
70
|
-
});
|
|
55
|
+
async function areAllSequentialFeedsUpdateRetrievable(bee, owner, topic, index, options) {
|
|
56
|
+
const chunkRetrievablePromises = getAllSequenceUpdateReferences(owner, topic, index).map(async (ref) => isChunkRetrievable(bee, ref, options));
|
|
57
|
+
return (await Promise.all(chunkRetrievablePromises)).every(result => result);
|
|
71
58
|
}
|
|
72
59
|
exports.areAllSequentialFeedsUpdateRetrievable = areAllSequentialFeedsUpdateRetrievable;
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.downloadReadable = exports.download = exports.upload = void 0;
|
|
13
4
|
const data_1 = require("../utils/data");
|
|
@@ -19,25 +10,26 @@ const endpoint = 'bytes';
|
|
|
19
10
|
/**
|
|
20
11
|
* Upload data to a Bee node
|
|
21
12
|
*
|
|
22
|
-
* @param
|
|
13
|
+
* @param kyOptions Ky Options for making requests
|
|
23
14
|
* @param data Data to be uploaded
|
|
24
15
|
* @param postageBatchId Postage BatchId that will be assigned to uploaded data
|
|
25
16
|
* @param options Additional options like tag, encryption, pinning
|
|
26
17
|
*/
|
|
27
|
-
function upload(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
reference: response.data.reference,
|
|
38
|
-
tagUid: (0, type_1.makeTagUid)(response.headers.get('swarm-tag')),
|
|
39
|
-
};
|
|
18
|
+
async function upload(kyOptions, data, postageBatchId, options) {
|
|
19
|
+
const response = await (0, http_1.http)(kyOptions, {
|
|
20
|
+
path: endpoint,
|
|
21
|
+
method: 'post',
|
|
22
|
+
responseType: 'json',
|
|
23
|
+
body: await (0, data_1.prepareData)(data),
|
|
24
|
+
headers: {
|
|
25
|
+
'content-type': 'application/octet-stream',
|
|
26
|
+
...(0, headers_1.extractUploadHeaders)(postageBatchId, options),
|
|
27
|
+
},
|
|
40
28
|
});
|
|
29
|
+
return {
|
|
30
|
+
reference: response.parsedData.reference,
|
|
31
|
+
tagUid: (0, type_1.makeTagUid)(response.headers.get('swarm-tag')),
|
|
32
|
+
};
|
|
41
33
|
}
|
|
42
34
|
exports.upload = upload;
|
|
43
35
|
/**
|
|
@@ -46,14 +38,12 @@ exports.upload = upload;
|
|
|
46
38
|
* @param ky
|
|
47
39
|
* @param hash Bee content reference
|
|
48
40
|
*/
|
|
49
|
-
function download(
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
path: `${endpoint}/${hash}`,
|
|
54
|
-
});
|
|
55
|
-
return (0, bytes_1.wrapBytesWithHelpers)(new Uint8Array(response.data));
|
|
41
|
+
async function download(kyOptions, hash) {
|
|
42
|
+
const response = await (0, http_1.http)(kyOptions, {
|
|
43
|
+
responseType: 'arraybuffer',
|
|
44
|
+
path: `${endpoint}/${hash}`,
|
|
56
45
|
});
|
|
46
|
+
return (0, bytes_1.wrapBytesWithHelpers)(new Uint8Array(response.parsedData));
|
|
57
47
|
}
|
|
58
48
|
exports.download = download;
|
|
59
49
|
/**
|
|
@@ -62,13 +52,11 @@ exports.download = download;
|
|
|
62
52
|
* @param ky
|
|
63
53
|
* @param hash Bee content reference
|
|
64
54
|
*/
|
|
65
|
-
function downloadReadable(
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
path: `${endpoint}/${hash}`,
|
|
70
|
-
});
|
|
71
|
-
return response.data;
|
|
55
|
+
async function downloadReadable(kyOptions, hash) {
|
|
56
|
+
const response = await (0, http_1.http)(kyOptions, {
|
|
57
|
+
responseType: 'stream',
|
|
58
|
+
path: `${endpoint}/${hash}`,
|
|
72
59
|
});
|
|
60
|
+
return response.parsedData;
|
|
73
61
|
}
|
|
74
62
|
exports.downloadReadable = downloadReadable;
|