@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.
Files changed (201) hide show
  1. package/README.md +104 -103
  2. package/dist/cjs/api/bytes.js +3 -4
  3. package/dist/cjs/api/bzz.js +5 -6
  4. package/dist/cjs/api/chunk.js +3 -3
  5. package/dist/cjs/api/envelope.js +3 -2
  6. package/dist/cjs/api/feed.js +4 -5
  7. package/dist/cjs/api/pin.js +2 -2
  8. package/dist/cjs/api/soc.js +2 -2
  9. package/dist/cjs/bee.js +18 -19
  10. package/dist/cjs/chunk/soc.js +21 -63
  11. package/dist/cjs/feed/identifier.js +3 -4
  12. package/dist/cjs/feed/index.js +17 -19
  13. package/dist/cjs/feed/retrievable.js +2 -2
  14. package/dist/cjs/index.js +18 -8
  15. package/dist/cjs/manifest/manifest.js +97 -333
  16. package/dist/cjs/modules/balance.js +3 -3
  17. package/dist/cjs/modules/cheque.js +4 -4
  18. package/dist/cjs/modules/chunk.js +8 -8
  19. package/dist/cjs/modules/collection.js +6 -6
  20. package/dist/cjs/modules/connectivity.js +3 -3
  21. package/dist/cjs/modules/data.js +6 -6
  22. package/dist/cjs/modules/feed.js +10 -10
  23. package/dist/cjs/modules/file.js +3 -3
  24. package/dist/cjs/modules/grantee.js +9 -9
  25. package/dist/cjs/modules/messaging.js +15 -17
  26. package/dist/cjs/modules/pin.js +6 -6
  27. package/dist/cjs/modules/settlement.js +2 -2
  28. package/dist/cjs/modules/soc.js +3 -3
  29. package/dist/cjs/modules/stamp.js +7 -7
  30. package/dist/cjs/modules/tag.js +2 -2
  31. package/dist/cjs/modules/transaction.js +4 -4
  32. package/dist/cjs/modules/wallet.js +3 -3
  33. package/dist/cjs/types/schema/chequebook.js +5 -5
  34. package/dist/cjs/types/schema/connectivity.js +5 -5
  35. package/dist/cjs/types/schema/envelope.js +5 -5
  36. package/dist/cjs/types/schema/grantee.js +4 -4
  37. package/dist/cjs/types/schema/stake.js +2 -2
  38. package/dist/cjs/types/schema/stamps.js +4 -4
  39. package/dist/cjs/types/schema/states.js +2 -2
  40. package/dist/cjs/types/schema/transactions.js +3 -3
  41. package/dist/cjs/types/schema/upload.js +2 -2
  42. package/dist/cjs/utils/chunk-stream.browser.js +24 -16
  43. package/dist/cjs/utils/chunk-stream.js +17 -9
  44. package/dist/cjs/utils/constants.js +3 -3
  45. package/dist/cjs/utils/expose.js +4 -4
  46. package/dist/cjs/utils/headers.js +4 -4
  47. package/dist/cjs/utils/http.js +3 -1
  48. package/dist/cjs/utils/pss.js +2 -2
  49. package/dist/cjs/utils/resource-locator.js +2 -2
  50. package/dist/cjs/utils/schema.js +4 -4
  51. package/dist/cjs/utils/stamps.js +15 -130
  52. package/dist/cjs/utils/type.js +2 -2
  53. package/dist/codemod/index.js +141 -0
  54. package/dist/codemod/transforms/v13.js +524 -0
  55. package/dist/index.browser.min.js +2 -1
  56. package/dist/index.browser.min.js.LICENSE.txt +3 -0
  57. package/dist/index.browser.min.js.map +1 -1
  58. package/dist/mjs/api/bytes.js +1 -2
  59. package/dist/mjs/api/bzz.js +1 -2
  60. package/dist/mjs/api/chunk.js +1 -1
  61. package/dist/mjs/api/envelope.js +3 -2
  62. package/dist/mjs/api/feed.js +1 -2
  63. package/dist/mjs/api/pin.js +1 -1
  64. package/dist/mjs/api/soc.js +1 -1
  65. package/dist/mjs/bee.js +13 -14
  66. package/dist/mjs/chunk/soc.js +11 -49
  67. package/dist/mjs/feed/identifier.js +2 -3
  68. package/dist/mjs/feed/index.js +6 -8
  69. package/dist/mjs/feed/retrievable.js +1 -1
  70. package/dist/mjs/index.js +2 -5
  71. package/dist/mjs/manifest/manifest.js +95 -339
  72. package/dist/mjs/modules/balance.js +1 -1
  73. package/dist/mjs/modules/cheque.js +1 -1
  74. package/dist/mjs/modules/chunk.js +1 -1
  75. package/dist/mjs/modules/collection.js +1 -1
  76. package/dist/mjs/modules/connectivity.js +1 -1
  77. package/dist/mjs/modules/data.js +3 -3
  78. package/dist/mjs/modules/feed.js +1 -1
  79. package/dist/mjs/modules/file.js +1 -1
  80. package/dist/mjs/modules/grantee.js +1 -1
  81. package/dist/mjs/modules/messaging.js +3 -5
  82. package/dist/mjs/modules/pin.js +1 -1
  83. package/dist/mjs/modules/settlement.js +1 -1
  84. package/dist/mjs/modules/soc.js +1 -1
  85. package/dist/mjs/modules/stamp.js +1 -1
  86. package/dist/mjs/modules/tag.js +1 -1
  87. package/dist/mjs/modules/transaction.js +1 -1
  88. package/dist/mjs/modules/wallet.js +1 -1
  89. package/dist/mjs/types/schema/chequebook.js +1 -1
  90. package/dist/mjs/types/schema/connectivity.js +1 -1
  91. package/dist/mjs/types/schema/envelope.js +5 -5
  92. package/dist/mjs/types/schema/grantee.js +1 -1
  93. package/dist/mjs/types/schema/stake.js +1 -1
  94. package/dist/mjs/types/schema/stamps.js +1 -1
  95. package/dist/mjs/types/schema/states.js +1 -1
  96. package/dist/mjs/types/schema/transactions.js +1 -1
  97. package/dist/mjs/types/schema/upload.js +1 -1
  98. package/dist/mjs/utils/chunk-stream.browser.js +28 -18
  99. package/dist/mjs/utils/chunk-stream.js +21 -11
  100. package/dist/mjs/utils/constants.js +1 -1
  101. package/dist/mjs/utils/expose.js +1 -1
  102. package/dist/mjs/utils/headers.js +1 -1
  103. package/dist/mjs/utils/http.js +6 -1
  104. package/dist/mjs/utils/pss.js +1 -1
  105. package/dist/mjs/utils/resource-locator.js +1 -1
  106. package/dist/mjs/utils/schema.js +1 -1
  107. package/dist/mjs/utils/stamps.js +5 -99
  108. package/dist/mjs/utils/type.js +2 -2
  109. package/dist/types/api/balance.d.ts +1 -1
  110. package/dist/types/api/batches.d.ts +1 -1
  111. package/dist/types/api/bytes.d.ts +3 -3
  112. package/dist/types/api/bzz.d.ts +1 -2
  113. package/dist/types/api/chequebook.d.ts +1 -1
  114. package/dist/types/api/chunk.d.ts +1 -1
  115. package/dist/types/api/connectivity.d.ts +1 -1
  116. package/dist/types/api/consumed.d.ts +1 -1
  117. package/dist/types/api/envelope.d.ts +1 -1
  118. package/dist/types/api/feed.d.ts +1 -2
  119. package/dist/types/api/grantee.d.ts +1 -1
  120. package/dist/types/api/pin.d.ts +1 -1
  121. package/dist/types/api/pss.d.ts +1 -1
  122. package/dist/types/api/settlement.d.ts +1 -1
  123. package/dist/types/api/soc.d.ts +1 -1
  124. package/dist/types/api/stake.d.ts +1 -1
  125. package/dist/types/api/stamp.d.ts +1 -1
  126. package/dist/types/api/stewardship.d.ts +1 -1
  127. package/dist/types/api/tag.d.ts +1 -1
  128. package/dist/types/api/transaction.d.ts +1 -1
  129. package/dist/types/api/wallet.d.ts +1 -1
  130. package/dist/types/bee.d.ts +11 -13
  131. package/dist/types/chunk/soc.d.ts +3 -48
  132. package/dist/types/feed/identifier.d.ts +1 -1
  133. package/dist/types/feed/index.d.ts +1 -3
  134. package/dist/types/feed/retrievable.d.ts +1 -1
  135. package/dist/types/index.d.ts +17 -20
  136. package/dist/types/manifest/manifest.d.ts +24 -33
  137. package/dist/types/modules/balance.d.ts +1 -1
  138. package/dist/types/modules/cheque.d.ts +1 -1
  139. package/dist/types/modules/chequebook.d.ts +1 -1
  140. package/dist/types/modules/chunk.d.ts +1 -2
  141. package/dist/types/modules/collection.d.ts +2 -2
  142. package/dist/types/modules/connectivity.d.ts +1 -1
  143. package/dist/types/modules/context.d.ts +1 -1
  144. package/dist/types/modules/data.d.ts +3 -3
  145. package/dist/types/modules/feed.d.ts +1 -1
  146. package/dist/types/modules/file.d.ts +1 -2
  147. package/dist/types/modules/grantee.d.ts +1 -1
  148. package/dist/types/modules/messaging.d.ts +1 -2
  149. package/dist/types/modules/pin.d.ts +1 -1
  150. package/dist/types/modules/settlement.d.ts +1 -1
  151. package/dist/types/modules/soc.d.ts +1 -1
  152. package/dist/types/modules/stake.d.ts +1 -1
  153. package/dist/types/modules/stamp.d.ts +1 -1
  154. package/dist/types/modules/storage.d.ts +1 -1
  155. package/dist/types/modules/tag.d.ts +1 -1
  156. package/dist/types/modules/transaction.d.ts +1 -1
  157. package/dist/types/modules/wallet.d.ts +1 -1
  158. package/dist/types/types/debug.d.ts +1 -1
  159. package/dist/types/types/index.d.ts +2 -11
  160. package/dist/types/types/schema/chequebook.d.ts +1 -1
  161. package/dist/types/types/schema/connectivity.d.ts +1 -1
  162. package/dist/types/types/schema/grantee.d.ts +1 -1
  163. package/dist/types/types/schema/stake.d.ts +1 -1
  164. package/dist/types/types/schema/stamps.d.ts +1 -1
  165. package/dist/types/types/schema/states.d.ts +1 -1
  166. package/dist/types/types/schema/transactions.d.ts +1 -1
  167. package/dist/types/types/schema/upload.d.ts +1 -1
  168. package/dist/types/utils/chunk-stream.browser.d.ts +1 -1
  169. package/dist/types/utils/chunk-stream.d.ts +2 -2
  170. package/dist/types/utils/constants.d.ts +1 -1
  171. package/dist/types/utils/expose.d.ts +1 -1
  172. package/dist/types/utils/headers.d.ts +1 -1
  173. package/dist/types/utils/pss.d.ts +1 -1
  174. package/dist/types/utils/resource-locator.d.ts +1 -1
  175. package/dist/types/utils/schema.d.ts +1 -1
  176. package/dist/types/utils/stamps.d.ts +2 -27
  177. package/dist/types/utils/tar-uploader.browser.d.ts +1 -1
  178. package/dist/types/utils/tar-uploader.d.ts +1 -1
  179. package/dist/types/utils/type.d.ts +1 -1
  180. package/package.json +7 -2
  181. package/dist/cjs/chunk/bmt.js +0 -37
  182. package/dist/cjs/chunk/cac.js +0 -43
  183. package/dist/cjs/stamper/stamper.js +0 -44
  184. package/dist/cjs/utils/bytes.js +0 -116
  185. package/dist/cjs/utils/cid.js +0 -37
  186. package/dist/cjs/utils/redundancy.js +0 -133
  187. package/dist/cjs/utils/typed-bytes.js +0 -186
  188. package/dist/mjs/chunk/bmt.js +0 -34
  189. package/dist/mjs/chunk/cac.js +0 -34
  190. package/dist/mjs/stamper/stamper.js +0 -40
  191. package/dist/mjs/utils/bytes.js +0 -102
  192. package/dist/mjs/utils/cid.js +0 -32
  193. package/dist/mjs/utils/redundancy.js +0 -98
  194. package/dist/mjs/utils/typed-bytes.js +0 -167
  195. package/dist/types/chunk/bmt.d.ts +0 -16
  196. package/dist/types/chunk/cac.d.ts +0 -40
  197. package/dist/types/stamper/stamper.d.ts +0 -15
  198. package/dist/types/utils/bytes.d.ts +0 -19
  199. package/dist/types/utils/cid.d.ts +0 -10
  200. package/dist/types/utils/redundancy.d.ts +0 -21
  201. 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 cac_1 = require("./chunk/cac");
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 soc_2 = require("./modules/soc");
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 rchash_1 = require("./api/rchash");
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 typed_bytes_1.PrivateKey(options.signer);
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, cac_1.makeContentAddressedChunk)(rawPayload, span);
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, cac_1.unmarshalContentAddressedChunk)(data);
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 typed_bytes_1.BatchId(postageBatchId);
174
- reference = new typed_bytes_1.Reference(reference);
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
  /**
@@ -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 cafe_utility_1 = require("cafe-utility");
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
- data = data instanceof bytes_1.Bytes ? data.toUint8Array() : data;
74
- address = new typed_bytes_1.Reference(address);
75
- const ownerAddress = recoverChunkOwner(data);
76
- const identifier = bytes_1.Bytes.fromSlice(data, 0, typed_bytes_1.Identifier.LENGTH);
77
- const socAddress = new typed_bytes_1.Reference(cafe_utility_1.Binary.keccak256(cafe_utility_1.Binary.concatBytes(identifier.toUint8Array(), ownerAddress.toUint8Array())));
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 typed_bytes_1.Identifier(identifier);
106
- signer = new typed_bytes_1.PrivateKey(signer);
107
- const socAddress = makeSOCAddress(identifier, signer.publicKey().address());
108
- const signature = signer.sign(cafe_utility_1.Binary.concatBytes(identifier.toUint8Array(), address.toUint8Array()));
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 = cafe_utility_1.Binary.concatBytes(chunk.span.toUint8Array(), chunk.payload.toUint8Array());
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 typed_bytes_1.PrivateKey(signer);
146
- identifier = new typed_bytes_1.Identifier(identifier);
147
- const cac = (0, cac_1.makeContentAddressedChunk)(data);
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 typed_bytes_1.PrivateKey(signer);
153
- identifier = new typed_bytes_1.Identifier(identifier);
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 typed_bytes_1.Identifier(identifier);
166
- ownerAddress = new typed_bytes_1.EthAddress(ownerAddress);
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 cafe_utility_1 = require("cafe-utility");
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' ? typed_bytes_1.FeedIndex.fromBigInt(BigInt(index)) : index;
8
- return new typed_bytes_1.Identifier(cafe_utility_1.Binary.keccak256(cafe_utility_1.Binary.concatBytes(topic.toUint8Array(), index.toUint8Array())));
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
  }
@@ -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 cac_1 = require("../chunk/cac");
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 typed_bytes_1.FeedIndex.fromBigInt(0n);
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 typed_bytes_1.Reference(reference);
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 = cafe_utility_1.Binary.numberToUint64(BigInt(Math.floor(at)), 'BE');
80
- const payloadBytes = cafe_utility_1.Binary.concatBytes(timestamp, reference.toUint8Array());
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, cac_1.unmarshalContentAddressedChunk)(await chunkAPI.download(requestOptions, uploadResult.reference));
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 ? bytes_1.Bytes.fromUtf8(dataString.data).toUint8Array() : data, options);
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 typed_bytes_1.Reference(cafe_utility_1.Binary.keccak256(cafe_utility_1.Binary.concatBytes(identifier.toUint8Array(), owner.toUint8Array())));
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' ? typed_bytes_1.FeedIndex.fromBigInt(BigInt(index)) : index;
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 = bytes_1.Bytes.fromSlice(soc.payload.toUint8Array(), TIMESTAMP_PAYLOAD_OFFSET, TIMESTAMP_PAYLOAD_SIZE);
106
- timestamp = cafe_utility_1.Optional.of(Number(cafe_utility_1.Binary.uint64ToNumber(timestampBytes.toUint8Array(), 'BE')));
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 bytes_1.Bytes(soc.payload.offset(hasTimestamp ? REFERENCE_PAYLOAD_OFFSET : 0)),
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' ? typed_bytes_1.FeedIndex.fromBigInt(BigInt(index)) : index;
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, cac_1.makeContentAddressedChunk)(soc.payload, soc.span);
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' ? typed_bytes_1.FeedIndex.fromBigInt(BigInt(options.index)) : options.index;
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' ? typed_bytes_1.FeedIndex.fromBigInt(BigInt(options.index)) : options.index;
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 typed_bytes_1.Reference(payload.payload.toUint8Array()),
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, typed_bytes_1.FeedIndex.fromBigInt(i)));
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.Bee = exports.Size = exports.Utils = exports.Duration = exports.Bytes = exports.SUPPORTED_BEE_VERSION_EXACT = exports.SUPPORTED_BEE_VERSION = exports.MantarayNode = exports.MerkleTree = void 0;
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
- const stamper_1 = require("./stamper/stamper");
43
- Object.defineProperty(exports, "Stamper", { enumerable: true, get: function () { return stamper_1.Stamper; } });
44
- var cafe_utility_1 = require("cafe-utility");
45
- Object.defineProperty(exports, "MerkleTree", { enumerable: true, get: function () { return cafe_utility_1.MerkleTree; } });
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);