@ethersphere/bee-js 13.0.0-upcoming.gcfb9756 → 13.0.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/README.md +104 -103
- package/dist/cjs/api/bytes.js +3 -4
- package/dist/cjs/api/bzz.js +5 -6
- package/dist/cjs/api/chunk.js +3 -3
- package/dist/cjs/api/envelope.js +3 -2
- package/dist/cjs/api/feed.js +4 -5
- package/dist/cjs/api/pin.js +2 -2
- package/dist/cjs/api/soc.js +2 -2
- package/dist/cjs/bee.js +18 -19
- package/dist/cjs/chunk/soc.js +21 -63
- package/dist/cjs/feed/identifier.js +3 -4
- package/dist/cjs/feed/index.js +17 -19
- package/dist/cjs/feed/retrievable.js +2 -2
- package/dist/cjs/index.js +18 -8
- package/dist/cjs/manifest/manifest.js +97 -333
- package/dist/cjs/modules/balance.js +3 -3
- package/dist/cjs/modules/cheque.js +4 -4
- package/dist/cjs/modules/chunk.js +8 -8
- package/dist/cjs/modules/collection.js +6 -6
- package/dist/cjs/modules/connectivity.js +3 -3
- package/dist/cjs/modules/data.js +6 -6
- package/dist/cjs/modules/feed.js +10 -10
- package/dist/cjs/modules/file.js +3 -3
- package/dist/cjs/modules/grantee.js +9 -9
- package/dist/cjs/modules/messaging.js +15 -17
- package/dist/cjs/modules/pin.js +6 -6
- package/dist/cjs/modules/settlement.js +2 -2
- package/dist/cjs/modules/soc.js +3 -3
- package/dist/cjs/modules/stamp.js +7 -7
- package/dist/cjs/modules/tag.js +2 -2
- package/dist/cjs/modules/transaction.js +4 -4
- package/dist/cjs/modules/wallet.js +3 -3
- package/dist/cjs/types/schema/chequebook.js +5 -5
- package/dist/cjs/types/schema/connectivity.js +5 -5
- package/dist/cjs/types/schema/envelope.js +5 -5
- package/dist/cjs/types/schema/grantee.js +4 -4
- package/dist/cjs/types/schema/stake.js +2 -2
- package/dist/cjs/types/schema/stamps.js +4 -4
- package/dist/cjs/types/schema/states.js +2 -2
- package/dist/cjs/types/schema/transactions.js +3 -3
- package/dist/cjs/types/schema/upload.js +2 -2
- package/dist/cjs/utils/chunk-stream.browser.js +24 -16
- package/dist/cjs/utils/chunk-stream.js +17 -9
- package/dist/cjs/utils/constants.js +3 -3
- package/dist/cjs/utils/expose.js +4 -4
- package/dist/cjs/utils/headers.js +4 -4
- package/dist/cjs/utils/http.js +3 -1
- package/dist/cjs/utils/pss.js +2 -2
- package/dist/cjs/utils/resource-locator.js +2 -2
- package/dist/cjs/utils/schema.js +4 -4
- package/dist/cjs/utils/stamps.js +15 -130
- package/dist/cjs/utils/type.js +2 -2
- package/dist/codemod/index.js +141 -0
- package/dist/codemod/transforms/v13.js +524 -0
- package/dist/index.browser.min.js +2 -1
- package/dist/index.browser.min.js.LICENSE.txt +3 -0
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/api/bytes.js +1 -2
- package/dist/mjs/api/bzz.js +1 -2
- package/dist/mjs/api/chunk.js +1 -1
- package/dist/mjs/api/envelope.js +3 -2
- package/dist/mjs/api/feed.js +1 -2
- package/dist/mjs/api/pin.js +1 -1
- package/dist/mjs/api/soc.js +1 -1
- package/dist/mjs/bee.js +13 -14
- package/dist/mjs/chunk/soc.js +11 -49
- package/dist/mjs/feed/identifier.js +2 -3
- package/dist/mjs/feed/index.js +6 -8
- package/dist/mjs/feed/retrievable.js +1 -1
- package/dist/mjs/index.js +2 -5
- package/dist/mjs/manifest/manifest.js +95 -339
- package/dist/mjs/modules/balance.js +1 -1
- package/dist/mjs/modules/cheque.js +1 -1
- package/dist/mjs/modules/chunk.js +1 -1
- package/dist/mjs/modules/collection.js +1 -1
- package/dist/mjs/modules/connectivity.js +1 -1
- package/dist/mjs/modules/data.js +3 -3
- package/dist/mjs/modules/feed.js +1 -1
- package/dist/mjs/modules/file.js +1 -1
- package/dist/mjs/modules/grantee.js +1 -1
- package/dist/mjs/modules/messaging.js +3 -5
- package/dist/mjs/modules/pin.js +1 -1
- package/dist/mjs/modules/settlement.js +1 -1
- package/dist/mjs/modules/soc.js +1 -1
- package/dist/mjs/modules/stamp.js +1 -1
- package/dist/mjs/modules/tag.js +1 -1
- package/dist/mjs/modules/transaction.js +1 -1
- package/dist/mjs/modules/wallet.js +1 -1
- package/dist/mjs/types/schema/chequebook.js +1 -1
- package/dist/mjs/types/schema/connectivity.js +1 -1
- package/dist/mjs/types/schema/envelope.js +5 -5
- package/dist/mjs/types/schema/grantee.js +1 -1
- package/dist/mjs/types/schema/stake.js +1 -1
- package/dist/mjs/types/schema/stamps.js +1 -1
- package/dist/mjs/types/schema/states.js +1 -1
- package/dist/mjs/types/schema/transactions.js +1 -1
- package/dist/mjs/types/schema/upload.js +1 -1
- package/dist/mjs/utils/chunk-stream.browser.js +28 -18
- package/dist/mjs/utils/chunk-stream.js +21 -11
- package/dist/mjs/utils/constants.js +1 -1
- package/dist/mjs/utils/expose.js +1 -1
- package/dist/mjs/utils/headers.js +1 -1
- package/dist/mjs/utils/http.js +6 -1
- package/dist/mjs/utils/pss.js +1 -1
- package/dist/mjs/utils/resource-locator.js +1 -1
- package/dist/mjs/utils/schema.js +1 -1
- package/dist/mjs/utils/stamps.js +5 -99
- package/dist/mjs/utils/type.js +2 -2
- package/dist/types/api/balance.d.ts +1 -1
- package/dist/types/api/batches.d.ts +1 -1
- package/dist/types/api/bytes.d.ts +3 -3
- package/dist/types/api/bzz.d.ts +1 -2
- package/dist/types/api/chequebook.d.ts +1 -1
- package/dist/types/api/chunk.d.ts +1 -1
- package/dist/types/api/connectivity.d.ts +1 -1
- package/dist/types/api/consumed.d.ts +1 -1
- package/dist/types/api/envelope.d.ts +1 -1
- package/dist/types/api/feed.d.ts +1 -2
- package/dist/types/api/grantee.d.ts +1 -1
- package/dist/types/api/pin.d.ts +1 -1
- package/dist/types/api/pss.d.ts +1 -1
- package/dist/types/api/settlement.d.ts +1 -1
- package/dist/types/api/soc.d.ts +1 -1
- package/dist/types/api/stake.d.ts +1 -1
- package/dist/types/api/stamp.d.ts +1 -1
- package/dist/types/api/stewardship.d.ts +1 -1
- package/dist/types/api/tag.d.ts +1 -1
- package/dist/types/api/transaction.d.ts +1 -1
- package/dist/types/api/wallet.d.ts +1 -1
- package/dist/types/bee.d.ts +11 -13
- package/dist/types/chunk/soc.d.ts +3 -48
- package/dist/types/feed/identifier.d.ts +1 -1
- package/dist/types/feed/index.d.ts +1 -3
- package/dist/types/feed/retrievable.d.ts +1 -1
- package/dist/types/index.d.ts +17 -20
- package/dist/types/manifest/manifest.d.ts +24 -33
- package/dist/types/modules/balance.d.ts +1 -1
- package/dist/types/modules/cheque.d.ts +1 -1
- package/dist/types/modules/chequebook.d.ts +1 -1
- package/dist/types/modules/chunk.d.ts +1 -2
- package/dist/types/modules/collection.d.ts +2 -2
- package/dist/types/modules/connectivity.d.ts +1 -1
- package/dist/types/modules/context.d.ts +1 -1
- package/dist/types/modules/data.d.ts +3 -3
- package/dist/types/modules/feed.d.ts +1 -1
- package/dist/types/modules/file.d.ts +1 -2
- package/dist/types/modules/grantee.d.ts +1 -1
- package/dist/types/modules/messaging.d.ts +1 -2
- package/dist/types/modules/pin.d.ts +1 -1
- package/dist/types/modules/settlement.d.ts +1 -1
- package/dist/types/modules/soc.d.ts +1 -1
- package/dist/types/modules/stake.d.ts +1 -1
- package/dist/types/modules/stamp.d.ts +1 -1
- package/dist/types/modules/storage.d.ts +1 -1
- package/dist/types/modules/tag.d.ts +1 -1
- package/dist/types/modules/transaction.d.ts +1 -1
- package/dist/types/modules/wallet.d.ts +1 -1
- package/dist/types/types/debug.d.ts +1 -1
- package/dist/types/types/index.d.ts +2 -11
- package/dist/types/types/schema/chequebook.d.ts +1 -1
- package/dist/types/types/schema/connectivity.d.ts +1 -1
- package/dist/types/types/schema/grantee.d.ts +1 -1
- package/dist/types/types/schema/stake.d.ts +1 -1
- package/dist/types/types/schema/stamps.d.ts +1 -1
- package/dist/types/types/schema/states.d.ts +1 -1
- package/dist/types/types/schema/transactions.d.ts +1 -1
- package/dist/types/types/schema/upload.d.ts +1 -1
- package/dist/types/utils/chunk-stream.browser.d.ts +1 -1
- package/dist/types/utils/chunk-stream.d.ts +2 -2
- package/dist/types/utils/constants.d.ts +1 -1
- package/dist/types/utils/expose.d.ts +1 -1
- package/dist/types/utils/headers.d.ts +1 -1
- package/dist/types/utils/pss.d.ts +1 -1
- package/dist/types/utils/resource-locator.d.ts +1 -1
- package/dist/types/utils/schema.d.ts +1 -1
- package/dist/types/utils/stamps.d.ts +2 -27
- package/dist/types/utils/tar-uploader.browser.d.ts +1 -1
- package/dist/types/utils/tar-uploader.d.ts +1 -1
- package/dist/types/utils/type.d.ts +1 -1
- package/package.json +7 -2
- package/dist/cjs/chunk/bmt.js +0 -37
- package/dist/cjs/chunk/cac.js +0 -43
- package/dist/cjs/stamper/stamper.js +0 -44
- package/dist/cjs/utils/bytes.js +0 -116
- package/dist/cjs/utils/cid.js +0 -37
- package/dist/cjs/utils/redundancy.js +0 -133
- package/dist/cjs/utils/typed-bytes.js +0 -186
- package/dist/mjs/chunk/bmt.js +0 -34
- package/dist/mjs/chunk/cac.js +0 -34
- package/dist/mjs/stamper/stamper.js +0 -40
- package/dist/mjs/utils/bytes.js +0 -102
- package/dist/mjs/utils/cid.js +0 -32
- package/dist/mjs/utils/redundancy.js +0 -98
- package/dist/mjs/utils/typed-bytes.js +0 -167
- package/dist/types/chunk/bmt.d.ts +0 -16
- package/dist/types/chunk/cac.d.ts +0 -40
- package/dist/types/stamper/stamper.d.ts +0 -15
- package/dist/types/utils/bytes.d.ts +0 -19
- package/dist/types/utils/cid.d.ts +0 -10
- package/dist/types/utils/redundancy.d.ts +0 -21
- package/dist/types/utils/typed-bytes.d.ts +0 -69
package/dist/cjs/bee.js
CHANGED
|
@@ -2,33 +2,32 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Bee = void 0;
|
|
4
4
|
const cafe_utility_1 = require("cafe-utility");
|
|
5
|
-
const
|
|
5
|
+
const core_sdk_1 = require("@ethersphere/core-sdk");
|
|
6
|
+
const envelope_1 = require("./api/envelope");
|
|
7
|
+
const rchash_1 = require("./api/rchash");
|
|
6
8
|
const soc_1 = require("./chunk/soc");
|
|
7
9
|
const balance_1 = require("./modules/balance");
|
|
8
10
|
const cheque_1 = require("./modules/cheque");
|
|
9
11
|
const chequebook_1 = require("./modules/chequebook");
|
|
10
|
-
const connectivity_1 = require("./modules/connectivity");
|
|
11
|
-
const settlement_1 = require("./modules/settlement");
|
|
12
|
-
const stake_1 = require("./modules/stake");
|
|
13
|
-
const stamp_1 = require("./modules/stamp");
|
|
14
|
-
const storage_1 = require("./modules/storage");
|
|
15
|
-
const status_1 = require("./modules/status");
|
|
16
|
-
const wallet_1 = require("./modules/wallet");
|
|
17
|
-
const transaction_1 = require("./modules/transaction");
|
|
18
|
-
const envelope_1 = require("./api/envelope");
|
|
19
12
|
const chunk_1 = require("./modules/chunk");
|
|
20
13
|
const collection_1 = require("./modules/collection");
|
|
14
|
+
const connectivity_1 = require("./modules/connectivity");
|
|
21
15
|
const data_1 = require("./modules/data");
|
|
22
|
-
const file_1 = require("./modules/file");
|
|
23
16
|
const feed_1 = require("./modules/feed");
|
|
24
|
-
const
|
|
17
|
+
const file_1 = require("./modules/file");
|
|
25
18
|
const grantee_1 = require("./modules/grantee");
|
|
26
19
|
const messaging_1 = require("./modules/messaging");
|
|
27
20
|
const pin_1 = require("./modules/pin");
|
|
28
|
-
const
|
|
21
|
+
const settlement_1 = require("./modules/settlement");
|
|
22
|
+
const soc_2 = require("./modules/soc");
|
|
23
|
+
const stake_1 = require("./modules/stake");
|
|
24
|
+
const stamp_1 = require("./modules/stamp");
|
|
25
|
+
const status_1 = require("./modules/status");
|
|
26
|
+
const storage_1 = require("./modules/storage");
|
|
29
27
|
const tag_1 = require("./modules/tag");
|
|
28
|
+
const transaction_1 = require("./modules/transaction");
|
|
29
|
+
const wallet_1 = require("./modules/wallet");
|
|
30
30
|
const schema_1 = require("./utils/schema");
|
|
31
|
-
const typed_bytes_1 = require("./utils/typed-bytes");
|
|
32
31
|
const url_1 = require("./utils/url");
|
|
33
32
|
/**
|
|
34
33
|
* The main component that abstracts operations available on the Bee API.
|
|
@@ -50,7 +49,7 @@ class Bee {
|
|
|
50
49
|
(0, url_1.assertBeeUrl)(url);
|
|
51
50
|
this.url = (0, url_1.stripLastSlash)(url);
|
|
52
51
|
if (options?.signer) {
|
|
53
|
-
this.signer = new
|
|
52
|
+
this.signer = new core_sdk_1.PrivateKey(options.signer);
|
|
54
53
|
}
|
|
55
54
|
this.network = options?.network ?? 'gnosis';
|
|
56
55
|
this.requestOptions = {
|
|
@@ -103,7 +102,7 @@ class Bee {
|
|
|
103
102
|
* @param span Optional span for the chunk. If not provided, it will be set to the length of the payload.
|
|
104
103
|
*/
|
|
105
104
|
makeContentAddressedChunk(rawPayload, span) {
|
|
106
|
-
return (0,
|
|
105
|
+
return (0, core_sdk_1.makeContentAddressedChunk)(rawPayload, span);
|
|
107
106
|
}
|
|
108
107
|
/**
|
|
109
108
|
* Attempts to unmarshal arbitrary data into a Content Addressed Chunk.
|
|
@@ -112,7 +111,7 @@ class Bee {
|
|
|
112
111
|
* @param data The chunk data (`span` and `payload`)
|
|
113
112
|
*/
|
|
114
113
|
unmarshalContentAddressedChunk(data) {
|
|
115
|
-
return (0,
|
|
114
|
+
return (0, core_sdk_1.unmarshalContentAddressedChunk)(data);
|
|
116
115
|
}
|
|
117
116
|
/**
|
|
118
117
|
* Creates a Single Owner Chunk.
|
|
@@ -170,8 +169,8 @@ class Bee {
|
|
|
170
169
|
* @returns
|
|
171
170
|
*/
|
|
172
171
|
async createEnvelope(postageBatchId, reference, requestOptions) {
|
|
173
|
-
postageBatchId = new
|
|
174
|
-
reference = new
|
|
172
|
+
postageBatchId = new core_sdk_1.BatchId(postageBatchId);
|
|
173
|
+
reference = new core_sdk_1.Reference(reference);
|
|
175
174
|
return (0, envelope_1.postEnvelope)(this.getRequestOptionsForCall(requestOptions), postageBatchId, reference);
|
|
176
175
|
}
|
|
177
176
|
/**
|
package/dist/cjs/chunk/soc.js
CHANGED
|
@@ -33,33 +33,18 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.makeSOCAddress = void 0;
|
|
36
37
|
exports.unmarshalSingleOwnerChunk = unmarshalSingleOwnerChunk;
|
|
37
|
-
exports.makeSOCAddress = makeSOCAddress;
|
|
38
38
|
exports.makeSingleOwnerChunk = makeSingleOwnerChunk;
|
|
39
39
|
exports.uploadSingleOwnerChunk = uploadSingleOwnerChunk;
|
|
40
40
|
exports.uploadSingleOwnerChunkData = uploadSingleOwnerChunkData;
|
|
41
41
|
exports.uploadSingleOwnerChunkWithWrappedChunk = uploadSingleOwnerChunkWithWrappedChunk;
|
|
42
42
|
exports.downloadSingleOwnerChunk = downloadSingleOwnerChunk;
|
|
43
|
-
const
|
|
43
|
+
const core_sdk_1 = require("@ethersphere/core-sdk");
|
|
44
|
+
Object.defineProperty(exports, "makeSOCAddress", { enumerable: true, get: function () { return core_sdk_1.makeSOCAddress; } });
|
|
44
45
|
const chunkAPI = __importStar(require("../api/chunk"));
|
|
45
46
|
const socAPI = __importStar(require("../api/soc"));
|
|
46
|
-
const bytes_1 = require("../utils/bytes");
|
|
47
47
|
const error_1 = require("../utils/error");
|
|
48
|
-
const typed_bytes_1 = require("../utils/typed-bytes");
|
|
49
|
-
const bmt_1 = require("./bmt");
|
|
50
|
-
const cac_1 = require("./cac");
|
|
51
|
-
const SOC_SIGNATURE_OFFSET = typed_bytes_1.Identifier.LENGTH;
|
|
52
|
-
const SOC_SPAN_OFFSET = typed_bytes_1.Identifier.LENGTH + typed_bytes_1.Signature.LENGTH;
|
|
53
|
-
const SOC_PAYLOAD_OFFSET = typed_bytes_1.Identifier.LENGTH + typed_bytes_1.Signature.LENGTH + typed_bytes_1.Span.LENGTH;
|
|
54
|
-
function recoverChunkOwner(data) {
|
|
55
|
-
const cacData = data.slice(SOC_SPAN_OFFSET);
|
|
56
|
-
const chunkAddress = (0, bmt_1.calculateChunkAddress)(cacData);
|
|
57
|
-
const signature = typed_bytes_1.Signature.fromSlice(data, SOC_SIGNATURE_OFFSET);
|
|
58
|
-
const identifier = bytes_1.Bytes.fromSlice(data, 0, typed_bytes_1.Identifier.LENGTH);
|
|
59
|
-
const digest = cafe_utility_1.Binary.concatBytes(identifier.toUint8Array(), chunkAddress.toUint8Array());
|
|
60
|
-
const ownerAddress = signature.recoverPublicKey(digest).address();
|
|
61
|
-
return ownerAddress;
|
|
62
|
-
}
|
|
63
48
|
/**
|
|
64
49
|
* Unmarshals arbitrary data into a Single Owner Chunk.
|
|
65
50
|
* Throws an error if the data is not a valid SOC.
|
|
@@ -70,29 +55,12 @@ function recoverChunkOwner(data) {
|
|
|
70
55
|
* @returns a single owner chunk or throws error
|
|
71
56
|
*/
|
|
72
57
|
function unmarshalSingleOwnerChunk(data, address) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
if (!cafe_utility_1.Binary.equals(address.toUint8Array(), socAddress.toUint8Array())) {
|
|
79
|
-
throw new error_1.BeeError('SOC data does not match given address!');
|
|
58
|
+
try {
|
|
59
|
+
return (0, core_sdk_1.unmarshalSingleOwnerChunk)(data, address);
|
|
60
|
+
}
|
|
61
|
+
catch (e) {
|
|
62
|
+
throw new error_1.BeeError(e.message);
|
|
80
63
|
}
|
|
81
|
-
const signature = typed_bytes_1.Signature.fromSlice(data, SOC_SIGNATURE_OFFSET);
|
|
82
|
-
const span = typed_bytes_1.Span.fromSlice(data, SOC_SPAN_OFFSET);
|
|
83
|
-
const payload = bytes_1.Bytes.fromSlice(data, SOC_PAYLOAD_OFFSET);
|
|
84
|
-
return {
|
|
85
|
-
data,
|
|
86
|
-
identifier,
|
|
87
|
-
signature,
|
|
88
|
-
span,
|
|
89
|
-
payload,
|
|
90
|
-
address: socAddress,
|
|
91
|
-
owner: ownerAddress,
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
function makeSOCAddress(identifier, address) {
|
|
95
|
-
return new typed_bytes_1.Reference(cafe_utility_1.Binary.keccak256(cafe_utility_1.Binary.concatBytes(identifier.toUint8Array(), address.toUint8Array())));
|
|
96
64
|
}
|
|
97
65
|
/**
|
|
98
66
|
* Creates a single owner chunk object
|
|
@@ -102,20 +70,10 @@ function makeSOCAddress(identifier, address) {
|
|
|
102
70
|
* @param signer The signer interface for signing the chunk
|
|
103
71
|
*/
|
|
104
72
|
function makeSingleOwnerChunk(address, span, payload, identifier, signer) {
|
|
105
|
-
identifier = new
|
|
106
|
-
signer = new
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
const data = cafe_utility_1.Binary.concatBytes(identifier.toUint8Array(), signature.toUint8Array(), span.toUint8Array(), payload.toUint8Array());
|
|
110
|
-
return {
|
|
111
|
-
data,
|
|
112
|
-
identifier,
|
|
113
|
-
signature,
|
|
114
|
-
span,
|
|
115
|
-
payload,
|
|
116
|
-
address: socAddress,
|
|
117
|
-
owner: signer.publicKey().address(),
|
|
118
|
-
};
|
|
73
|
+
identifier = new core_sdk_1.Identifier(identifier);
|
|
74
|
+
signer = new core_sdk_1.PrivateKey(signer);
|
|
75
|
+
const wrappedChunk = { data: core_sdk_1.Bytes.concat(span.toUint8Array(), payload.toUint8Array()), span, payload, address };
|
|
76
|
+
return (0, core_sdk_1.makeSingleOwnerChunk)(wrappedChunk, identifier, signer.toBigInt());
|
|
119
77
|
}
|
|
120
78
|
/**
|
|
121
79
|
* Helper function to upload a chunk.
|
|
@@ -128,7 +86,7 @@ function makeSingleOwnerChunk(address, span, payload, identifier, signer) {
|
|
|
128
86
|
* @param options Upload options
|
|
129
87
|
*/
|
|
130
88
|
async function uploadSingleOwnerChunk(requestOptions, chunk, stamp, options) {
|
|
131
|
-
const data =
|
|
89
|
+
const data = core_sdk_1.Bytes.concat(chunk.span.toUint8Array(), chunk.payload.toUint8Array());
|
|
132
90
|
return socAPI.upload(requestOptions, chunk.owner, chunk.identifier, chunk.signature, data, stamp, options);
|
|
133
91
|
}
|
|
134
92
|
/**
|
|
@@ -142,15 +100,15 @@ async function uploadSingleOwnerChunk(requestOptions, chunk, stamp, options) {
|
|
|
142
100
|
* @param options
|
|
143
101
|
*/
|
|
144
102
|
async function uploadSingleOwnerChunkData(requestOptions, signer, stamp, identifier, data, options) {
|
|
145
|
-
signer = new
|
|
146
|
-
identifier = new
|
|
147
|
-
const cac = (0,
|
|
103
|
+
signer = new core_sdk_1.PrivateKey(signer);
|
|
104
|
+
identifier = new core_sdk_1.Identifier(identifier);
|
|
105
|
+
const cac = (0, core_sdk_1.makeContentAddressedChunk)(data);
|
|
148
106
|
const soc = cac.toSingleOwnerChunk(identifier, signer);
|
|
149
107
|
return uploadSingleOwnerChunk(requestOptions, soc, stamp, options);
|
|
150
108
|
}
|
|
151
109
|
async function uploadSingleOwnerChunkWithWrappedChunk(requestOptions, signer, stamp, identifier, wrappedChunk, options) {
|
|
152
|
-
signer = new
|
|
153
|
-
identifier = new
|
|
110
|
+
signer = new core_sdk_1.PrivateKey(signer);
|
|
111
|
+
identifier = new core_sdk_1.Identifier(identifier);
|
|
154
112
|
const soc = wrappedChunk.toSingleOwnerChunk(identifier, signer);
|
|
155
113
|
return uploadSingleOwnerChunk(requestOptions, soc, stamp, options);
|
|
156
114
|
}
|
|
@@ -162,9 +120,9 @@ async function uploadSingleOwnerChunkWithWrappedChunk(requestOptions, signer, st
|
|
|
162
120
|
* @param identifier The identifier of the chunk
|
|
163
121
|
*/
|
|
164
122
|
async function downloadSingleOwnerChunk(requestOptions, ownerAddress, identifier) {
|
|
165
|
-
identifier = new
|
|
166
|
-
ownerAddress = new
|
|
167
|
-
const address = makeSOCAddress(identifier, ownerAddress);
|
|
123
|
+
identifier = new core_sdk_1.Identifier(identifier);
|
|
124
|
+
ownerAddress = new core_sdk_1.EthAddress(ownerAddress);
|
|
125
|
+
const address = (0, core_sdk_1.makeSOCAddress)(identifier, ownerAddress);
|
|
168
126
|
const cac = await chunkAPI.download(requestOptions, address.toHex());
|
|
169
127
|
return unmarshalSingleOwnerChunk(cac, address);
|
|
170
128
|
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.makeFeedIdentifier = makeFeedIdentifier;
|
|
4
|
-
const
|
|
5
|
-
const typed_bytes_1 = require("../utils/typed-bytes");
|
|
4
|
+
const core_sdk_1 = require("@ethersphere/core-sdk");
|
|
6
5
|
function makeFeedIdentifier(topic, index) {
|
|
7
|
-
index = typeof index === 'number' ?
|
|
8
|
-
return new
|
|
6
|
+
index = typeof index === 'number' ? core_sdk_1.FeedIndex.fromBigInt(BigInt(index)) : index;
|
|
7
|
+
return new core_sdk_1.Identifier((0, core_sdk_1.keccak256)(core_sdk_1.Bytes.concat(topic.toUint8Array(), index.toUint8Array())));
|
|
9
8
|
}
|
package/dist/cjs/feed/index.js
CHANGED
|
@@ -43,15 +43,13 @@ exports.makeFeedReader = makeFeedReader;
|
|
|
43
43
|
exports.makeFeedWriter = makeFeedWriter;
|
|
44
44
|
const cafe_utility_1 = require("cafe-utility");
|
|
45
45
|
const zod_1 = require("zod");
|
|
46
|
-
const
|
|
46
|
+
const core_sdk_1 = require("@ethersphere/core-sdk");
|
|
47
47
|
const soc_1 = require("../chunk/soc");
|
|
48
48
|
const bytes = __importStar(require("../api/bytes"));
|
|
49
49
|
const chunkAPI = __importStar(require("../api/chunk"));
|
|
50
50
|
const feed_1 = require("../api/feed");
|
|
51
|
-
const bytes_1 = require("../utils/bytes");
|
|
52
51
|
const error_1 = require("../utils/error");
|
|
53
52
|
const resource_locator_1 = require("../utils/resource-locator");
|
|
54
|
-
const typed_bytes_1 = require("../utils/typed-bytes");
|
|
55
53
|
const identifier_1 = require("./identifier");
|
|
56
54
|
const TIMESTAMP_PAYLOAD_OFFSET = 0;
|
|
57
55
|
const TIMESTAMP_PAYLOAD_SIZE = 8;
|
|
@@ -66,18 +64,18 @@ async function findNextIndex(requestOptions, owner, topic) {
|
|
|
66
64
|
}
|
|
67
65
|
catch (e) {
|
|
68
66
|
if (e instanceof error_1.BeeResponseError) {
|
|
69
|
-
return
|
|
67
|
+
return core_sdk_1.FeedIndex.fromBigInt(0n);
|
|
70
68
|
}
|
|
71
69
|
throw e;
|
|
72
70
|
}
|
|
73
71
|
}
|
|
74
72
|
async function updateFeedWithReference(requestOptions, signer, topic, reference, postageBatchId, options) {
|
|
75
|
-
reference = new
|
|
73
|
+
reference = new core_sdk_1.Reference(reference);
|
|
76
74
|
const nextIndex = options?.index ?? (await findNextIndex(requestOptions, signer.publicKey().address(), topic));
|
|
77
75
|
const identifier = (0, identifier_1.makeFeedIdentifier)(topic, nextIndex);
|
|
78
76
|
const at = options?.at ?? Date.now() / 1000.0;
|
|
79
|
-
const timestamp =
|
|
80
|
-
const payloadBytes =
|
|
77
|
+
const timestamp = (0, core_sdk_1.numberToUint64)(BigInt(Math.floor(at)), 'BE');
|
|
78
|
+
const payloadBytes = core_sdk_1.Bytes.concat(timestamp, reference.toUint8Array());
|
|
81
79
|
return (0, soc_1.uploadSingleOwnerChunkData)(requestOptions, signer, postageBatchId, identifier, payloadBytes, options);
|
|
82
80
|
}
|
|
83
81
|
async function updateFeedWithPayload(requestOptions, signer, topic, data, postageBatchId, options) {
|
|
@@ -85,37 +83,37 @@ async function updateFeedWithPayload(requestOptions, signer, topic, data, postag
|
|
|
85
83
|
const identifier = (0, identifier_1.makeFeedIdentifier)(topic, nextIndex);
|
|
86
84
|
if (data.length > 4096) {
|
|
87
85
|
const uploadResult = await bytes.upload(requestOptions, data, postageBatchId, options);
|
|
88
|
-
const rootChunk = (0,
|
|
86
|
+
const rootChunk = (0, core_sdk_1.unmarshalContentAddressedChunk)(await chunkAPI.download(requestOptions, uploadResult.reference));
|
|
89
87
|
return (0, soc_1.uploadSingleOwnerChunkWithWrappedChunk)(requestOptions, signer, postageBatchId, identifier, rootChunk, options);
|
|
90
88
|
}
|
|
91
89
|
const dataString = zod_1.z.string().safeParse(data);
|
|
92
|
-
return (0, soc_1.uploadSingleOwnerChunkData)(requestOptions, signer, postageBatchId, identifier, dataString.success ?
|
|
90
|
+
return (0, soc_1.uploadSingleOwnerChunkData)(requestOptions, signer, postageBatchId, identifier, dataString.success ? core_sdk_1.Bytes.fromUtf8(dataString.data).toUint8Array() : data, options);
|
|
93
91
|
}
|
|
94
92
|
function getFeedUpdateChunkReference(owner, topic, index) {
|
|
95
93
|
const identifier = (0, identifier_1.makeFeedIdentifier)(topic, index);
|
|
96
|
-
return new
|
|
94
|
+
return new core_sdk_1.Reference((0, core_sdk_1.keccak256)(core_sdk_1.Bytes.concat(identifier.toUint8Array(), owner.toUint8Array())));
|
|
97
95
|
}
|
|
98
96
|
async function downloadFeedUpdate(requestOptions, owner, topic, index, hasTimestamp = false) {
|
|
99
|
-
index = typeof index === 'number' ?
|
|
97
|
+
index = typeof index === 'number' ? core_sdk_1.FeedIndex.fromBigInt(BigInt(index)) : index;
|
|
100
98
|
const address = getFeedUpdateChunkReference(owner, topic, index);
|
|
101
99
|
const data = await chunkAPI.download(requestOptions, address.toHex());
|
|
102
100
|
const soc = (0, soc_1.unmarshalSingleOwnerChunk)(data, address);
|
|
103
101
|
let timestamp = cafe_utility_1.Optional.empty();
|
|
104
102
|
if (hasTimestamp) {
|
|
105
|
-
const timestampBytes =
|
|
106
|
-
timestamp = cafe_utility_1.Optional.of(Number(
|
|
103
|
+
const timestampBytes = core_sdk_1.Bytes.fromSlice(soc.payload.toUint8Array(), TIMESTAMP_PAYLOAD_OFFSET, TIMESTAMP_PAYLOAD_SIZE);
|
|
104
|
+
timestamp = cafe_utility_1.Optional.of(Number((0, core_sdk_1.uint64ToNumber)(timestampBytes.toUint8Array(), 'BE')));
|
|
107
105
|
}
|
|
108
106
|
return {
|
|
109
107
|
timestamp,
|
|
110
|
-
payload: new
|
|
108
|
+
payload: new core_sdk_1.Bytes(soc.payload.offset(hasTimestamp ? REFERENCE_PAYLOAD_OFFSET : 0)),
|
|
111
109
|
};
|
|
112
110
|
}
|
|
113
111
|
async function downloadFeedUpdateAsCAC(requestOptions, owner, topic, index) {
|
|
114
|
-
index = typeof index === 'number' ?
|
|
112
|
+
index = typeof index === 'number' ? core_sdk_1.FeedIndex.fromBigInt(BigInt(index)) : index;
|
|
115
113
|
const address = getFeedUpdateChunkReference(owner, topic, index);
|
|
116
114
|
const data = await chunkAPI.download(requestOptions, address);
|
|
117
115
|
const soc = (0, soc_1.unmarshalSingleOwnerChunk)(data, address);
|
|
118
|
-
return (0,
|
|
116
|
+
return (0, core_sdk_1.makeContentAddressedChunk)(soc.payload, soc.span);
|
|
119
117
|
}
|
|
120
118
|
function makeFeedReader(requestOptions, topic, owner) {
|
|
121
119
|
// TODO: remove after enough time has passed in deprecated version
|
|
@@ -124,7 +122,7 @@ function makeFeedReader(requestOptions, topic, owner) {
|
|
|
124
122
|
return (0, feed_1.fetchLatestFeedUpdate)(requestOptions, owner, topic);
|
|
125
123
|
}
|
|
126
124
|
const update = await downloadFeedUpdate(requestOptions, owner, topic, options.index, options.hasTimestamp ?? true);
|
|
127
|
-
const feedIndex = typeof options.index === 'number' ?
|
|
125
|
+
const feedIndex = typeof options.index === 'number' ? core_sdk_1.FeedIndex.fromBigInt(BigInt(options.index)) : options.index;
|
|
128
126
|
return {
|
|
129
127
|
payload: update.payload,
|
|
130
128
|
feedIndex,
|
|
@@ -139,7 +137,7 @@ function makeFeedReader(requestOptions, topic, owner) {
|
|
|
139
137
|
const payload = cac.span.toBigInt() <= 4096n
|
|
140
138
|
? cac.payload
|
|
141
139
|
: await bytes.download(requestOptions, new resource_locator_1.ResourceLocator(cac.address));
|
|
142
|
-
const feedIndex = typeof options.index === 'number' ?
|
|
140
|
+
const feedIndex = typeof options.index === 'number' ? core_sdk_1.FeedIndex.fromBigInt(BigInt(options.index)) : options.index;
|
|
143
141
|
return {
|
|
144
142
|
payload,
|
|
145
143
|
feedIndex,
|
|
@@ -153,7 +151,7 @@ function makeFeedReader(requestOptions, topic, owner) {
|
|
|
153
151
|
}
|
|
154
152
|
const payload = await download({ ...options, index: index });
|
|
155
153
|
return {
|
|
156
|
-
reference: new
|
|
154
|
+
reference: new core_sdk_1.Reference(payload.payload.toUint8Array()),
|
|
157
155
|
feedIndex: payload.feedIndex,
|
|
158
156
|
feedIndexNext: payload.feedIndexNext ?? payload.feedIndex.next(),
|
|
159
157
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.areAllSequentialFeedsUpdateRetrievable = areAllSequentialFeedsUpdateRetrievable;
|
|
4
|
+
const core_sdk_1 = require("@ethersphere/core-sdk");
|
|
4
5
|
const cafe_utility_1 = require("cafe-utility");
|
|
5
|
-
const typed_bytes_1 = require("../utils/typed-bytes");
|
|
6
6
|
const index_1 = require("./index");
|
|
7
7
|
/**
|
|
8
8
|
* Function that checks if a chunk is retrievable by actually downloading it.
|
|
@@ -36,7 +36,7 @@ function getAllSequenceUpdateReferences(owner, topic, index) {
|
|
|
36
36
|
const count = index.toBigInt();
|
|
37
37
|
const updateReferences = [];
|
|
38
38
|
for (let i = 0n; i <= count; i++) {
|
|
39
|
-
updateReferences.push((0, index_1.getFeedUpdateChunkReference)(owner, topic,
|
|
39
|
+
updateReferences.push((0, index_1.getFeedUpdateChunkReference)(owner, topic, core_sdk_1.FeedIndex.fromBigInt(i)));
|
|
40
40
|
}
|
|
41
41
|
return updateReferences;
|
|
42
42
|
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -36,21 +36,32 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
36
36
|
};
|
|
37
37
|
})();
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.Stamper = exports.
|
|
39
|
+
exports.Bee = exports.Size = exports.Utils = exports.Duration = exports.SUPPORTED_BEE_VERSION_EXACT = exports.SUPPORTED_BEE_VERSION = exports.MantarayNode = exports.TransactionId = exports.Topic = exports.Stamper = exports.Span = exports.Signature = exports.Reference = exports.PublicKey = exports.PrivateKey = exports.PeerAddress = exports.Identifier = exports.FeedIndex = exports.EthAddress = exports.ChunkSplitter = exports.ChunkBuilder = exports.Bytes = exports.BatchId = void 0;
|
|
40
40
|
const bee_1 = require("./bee");
|
|
41
41
|
Object.defineProperty(exports, "Bee", { enumerable: true, get: function () { return bee_1.Bee; } });
|
|
42
|
-
|
|
43
|
-
Object.defineProperty(exports, "
|
|
44
|
-
|
|
45
|
-
Object.defineProperty(exports, "
|
|
42
|
+
var core_sdk_1 = require("@ethersphere/core-sdk");
|
|
43
|
+
Object.defineProperty(exports, "BatchId", { enumerable: true, get: function () { return core_sdk_1.BatchId; } });
|
|
44
|
+
Object.defineProperty(exports, "Bytes", { enumerable: true, get: function () { return core_sdk_1.Bytes; } });
|
|
45
|
+
Object.defineProperty(exports, "ChunkBuilder", { enumerable: true, get: function () { return core_sdk_1.ChunkBuilder; } });
|
|
46
|
+
Object.defineProperty(exports, "ChunkSplitter", { enumerable: true, get: function () { return core_sdk_1.ChunkSplitter; } });
|
|
47
|
+
Object.defineProperty(exports, "EthAddress", { enumerable: true, get: function () { return core_sdk_1.EthAddress; } });
|
|
48
|
+
Object.defineProperty(exports, "FeedIndex", { enumerable: true, get: function () { return core_sdk_1.FeedIndex; } });
|
|
49
|
+
Object.defineProperty(exports, "Identifier", { enumerable: true, get: function () { return core_sdk_1.Identifier; } });
|
|
50
|
+
Object.defineProperty(exports, "PeerAddress", { enumerable: true, get: function () { return core_sdk_1.PeerAddress; } });
|
|
51
|
+
Object.defineProperty(exports, "PrivateKey", { enumerable: true, get: function () { return core_sdk_1.PrivateKey; } });
|
|
52
|
+
Object.defineProperty(exports, "PublicKey", { enumerable: true, get: function () { return core_sdk_1.PublicKey; } });
|
|
53
|
+
Object.defineProperty(exports, "Reference", { enumerable: true, get: function () { return core_sdk_1.Reference; } });
|
|
54
|
+
Object.defineProperty(exports, "Signature", { enumerable: true, get: function () { return core_sdk_1.Signature; } });
|
|
55
|
+
Object.defineProperty(exports, "Span", { enumerable: true, get: function () { return core_sdk_1.Span; } });
|
|
56
|
+
Object.defineProperty(exports, "Stamper", { enumerable: true, get: function () { return core_sdk_1.Stamper; } });
|
|
57
|
+
Object.defineProperty(exports, "Topic", { enumerable: true, get: function () { return core_sdk_1.Topic; } });
|
|
58
|
+
Object.defineProperty(exports, "TransactionId", { enumerable: true, get: function () { return core_sdk_1.TransactionId; } });
|
|
46
59
|
var manifest_1 = require("./manifest/manifest");
|
|
47
60
|
Object.defineProperty(exports, "MantarayNode", { enumerable: true, get: function () { return manifest_1.MantarayNode; } });
|
|
48
61
|
var version_1 = require("./version");
|
|
49
62
|
Object.defineProperty(exports, "SUPPORTED_BEE_VERSION", { enumerable: true, get: function () { return version_1.SUPPORTED_BEE_VERSION; } });
|
|
50
63
|
Object.defineProperty(exports, "SUPPORTED_BEE_VERSION_EXACT", { enumerable: true, get: function () { return version_1.SUPPORTED_BEE_VERSION_EXACT; } });
|
|
51
64
|
__exportStar(require("./types"), exports);
|
|
52
|
-
var bytes_1 = require("./utils/bytes");
|
|
53
|
-
Object.defineProperty(exports, "Bytes", { enumerable: true, get: function () { return bytes_1.Bytes; } });
|
|
54
65
|
__exportStar(require("./utils/constants"), exports);
|
|
55
66
|
var duration_1 = require("./utils/duration");
|
|
56
67
|
Object.defineProperty(exports, "Duration", { enumerable: true, get: function () { return duration_1.Duration; } });
|
|
@@ -59,4 +70,3 @@ exports.Utils = __importStar(require("./utils/expose"));
|
|
|
59
70
|
var size_1 = require("./utils/size");
|
|
60
71
|
Object.defineProperty(exports, "Size", { enumerable: true, get: function () { return size_1.Size; } });
|
|
61
72
|
__exportStar(require("./utils/tokens"), exports);
|
|
62
|
-
__exportStar(require("./utils/typed-bytes"), exports);
|