@upcoming/bee-js 9.9.1 → 11.1.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 (103) hide show
  1. package/README.md +2 -2
  2. package/dist/cjs/bee.js +881 -370
  3. package/dist/cjs/chunk/bmt.js +1 -2
  4. package/dist/cjs/chunk/cac.js +27 -32
  5. package/dist/cjs/chunk/soc.js +39 -31
  6. package/dist/cjs/feed/identifier.js +1 -2
  7. package/dist/cjs/feed/index.js +29 -19
  8. package/dist/cjs/feed/retrievable.js +1 -2
  9. package/dist/cjs/index.js +17 -7
  10. package/dist/cjs/manifest/manifest.js +19 -2
  11. package/dist/cjs/modules/bytes.js +4 -5
  12. package/dist/cjs/modules/bzz.js +4 -5
  13. package/dist/cjs/modules/chunk.js +2 -3
  14. package/dist/cjs/modules/debug/balance.js +4 -5
  15. package/dist/cjs/modules/debug/chequebook.js +9 -10
  16. package/dist/cjs/modules/debug/connectivity.js +7 -8
  17. package/dist/cjs/modules/debug/settlements.js +2 -3
  18. package/dist/cjs/modules/debug/stake.js +6 -7
  19. package/dist/cjs/modules/debug/stamps.js +24 -60
  20. package/dist/cjs/modules/debug/states.js +6 -6
  21. package/dist/cjs/modules/debug/status.js +9 -9
  22. package/dist/cjs/modules/debug/transactions.js +4 -5
  23. package/dist/cjs/modules/envelope.js +1 -2
  24. package/dist/cjs/modules/feed.js +3 -4
  25. package/dist/cjs/modules/grantee.js +3 -4
  26. package/dist/cjs/modules/gsoc.js +2 -3
  27. package/dist/cjs/modules/pinning.js +4 -5
  28. package/dist/cjs/modules/pss.js +2 -3
  29. package/dist/cjs/modules/rchash.js +1 -2
  30. package/dist/cjs/modules/soc.js +1 -2
  31. package/dist/cjs/modules/status.js +2 -3
  32. package/dist/cjs/modules/stewardship.js +2 -3
  33. package/dist/cjs/modules/tag.js +5 -6
  34. package/dist/cjs/types/debug.js +3 -3
  35. package/dist/cjs/types/index.js +11 -6
  36. package/dist/cjs/utils/bytes.js +23 -3
  37. package/dist/cjs/utils/chunk-size.js +1 -2
  38. package/dist/cjs/utils/chunk-stream.browser.js +30 -6
  39. package/dist/cjs/utils/chunk-stream.js +3 -4
  40. package/dist/cjs/utils/cid.js +3 -3
  41. package/dist/cjs/utils/collection.browser.js +2 -3
  42. package/dist/cjs/utils/collection.js +5 -6
  43. package/dist/cjs/utils/collection.node.js +2 -3
  44. package/dist/cjs/utils/data.browser.js +1 -2
  45. package/dist/cjs/utils/data.js +1 -2
  46. package/dist/cjs/utils/duration.js +27 -1
  47. package/dist/cjs/utils/expose.js +4 -1
  48. package/dist/cjs/utils/file.js +2 -3
  49. package/dist/cjs/utils/headers.js +2 -3
  50. package/dist/cjs/utils/http.js +25 -5
  51. package/dist/cjs/utils/pss.js +1 -2
  52. package/dist/cjs/utils/redundancy.js +3 -4
  53. package/dist/cjs/utils/size.js +25 -0
  54. package/dist/cjs/utils/stamps.js +60 -11
  55. package/dist/cjs/utils/tar-uploader.browser.js +1 -2
  56. package/dist/cjs/utils/tar-uploader.js +1 -2
  57. package/dist/cjs/utils/tar-writer.browser.js +1 -2
  58. package/dist/cjs/utils/tar-writer.js +1 -2
  59. package/dist/cjs/utils/type.js +37 -25
  60. package/dist/cjs/utils/url.js +3 -4
  61. package/dist/cjs/utils/workaround.js +7 -5
  62. package/dist/index.browser.min.js +1 -1
  63. package/dist/index.browser.min.js.map +1 -1
  64. package/dist/mjs/bee.js +864 -366
  65. package/dist/mjs/chunk/cac.js +21 -30
  66. package/dist/mjs/chunk/soc.js +16 -17
  67. package/dist/mjs/feed/index.js +7 -6
  68. package/dist/mjs/manifest/manifest.js +19 -2
  69. package/dist/mjs/modules/debug/chequebook.js +2 -2
  70. package/dist/mjs/modules/debug/stamps.js +38 -93
  71. package/dist/mjs/modules/debug/states.js +3 -0
  72. package/dist/mjs/modules/debug/status.js +1 -1
  73. package/dist/mjs/types/index.js +8 -3
  74. package/dist/mjs/utils/bytes.js +19 -2
  75. package/dist/mjs/utils/chunk-stream.browser.js +29 -5
  76. package/dist/mjs/utils/duration.js +27 -1
  77. package/dist/mjs/utils/expose.js +1 -1
  78. package/dist/mjs/utils/http.js +25 -3
  79. package/dist/mjs/utils/size.js +25 -0
  80. package/dist/mjs/utils/stamps.js +48 -0
  81. package/dist/mjs/utils/type.js +8 -1
  82. package/dist/mjs/utils/workaround.js +5 -2
  83. package/dist/types/bee.d.ts +756 -252
  84. package/dist/types/chunk/cac.d.ts +27 -13
  85. package/dist/types/chunk/soc.d.ts +43 -11
  86. package/dist/types/index.d.ts +3 -0
  87. package/dist/types/modules/bzz.d.ts +0 -1
  88. package/dist/types/modules/debug/stamps.d.ts +2 -2
  89. package/dist/types/modules/debug/status.d.ts +1 -1
  90. package/dist/types/modules/gsoc.d.ts +0 -1
  91. package/dist/types/modules/pss.d.ts +0 -1
  92. package/dist/types/types/debug.d.ts +2 -1
  93. package/dist/types/types/index.d.ts +53 -6
  94. package/dist/types/utils/constants.d.ts +3 -3
  95. package/dist/types/utils/duration.d.ts +24 -0
  96. package/dist/types/utils/error.d.ts +2 -2
  97. package/dist/types/utils/expose.d.ts +1 -1
  98. package/dist/types/utils/size.d.ts +23 -0
  99. package/dist/types/utils/stamps.d.ts +15 -1
  100. package/dist/types/utils/tar.browser.d.ts +1 -1
  101. package/dist/types/utils/tar.d.ts +0 -1
  102. package/dist/types/utils/type.d.ts +0 -1
  103. package/package.json +10 -13
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.calculateChunkAddress = void 0;
3
+ exports.calculateChunkAddress = calculateChunkAddress;
4
4
  const cafe_utility_1 = require("cafe-utility");
5
5
  const error_1 = require("../utils/error");
6
6
  const typed_bytes_1 = require("../utils/typed-bytes");
@@ -27,7 +27,6 @@ function calculateChunkAddress(chunkContent) {
27
27
  const chunkHash = cafe_utility_1.Binary.keccak256(cafe_utility_1.Binary.concatBytes(span, rootHash));
28
28
  return new typed_bytes_1.Reference(chunkHash);
29
29
  }
30
- exports.calculateChunkAddress = calculateChunkAddress;
31
30
  function calculateBmtRootHash(payload) {
32
31
  if (payload.length > MAX_CHUNK_PAYLOAD_SIZE) {
33
32
  throw new error_1.BeeArgumentError(`payload size ${payload.length} exceeds maximum chunk payload size ${MAX_CHUNK_PAYLOAD_SIZE}`, payload);
@@ -1,46 +1,41 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.asContentAddressedChunk = exports.makeContentAddressedChunk = exports.MAX_PAYLOAD_SIZE = exports.MIN_PAYLOAD_SIZE = void 0;
3
+ exports.MAX_PAYLOAD_SIZE = exports.MIN_PAYLOAD_SIZE = void 0;
4
+ exports.unmarshalContentAddressedChunk = unmarshalContentAddressedChunk;
5
+ exports.makeContentAddressedChunk = makeContentAddressedChunk;
4
6
  const cafe_utility_1 = require("cafe-utility");
5
7
  const bytes_1 = require("../utils/bytes");
6
8
  const typed_bytes_1 = require("../utils/typed-bytes");
7
9
  const bmt_1 = require("./bmt");
10
+ const soc_1 = require("./soc");
8
11
  exports.MIN_PAYLOAD_SIZE = 1;
9
12
  exports.MAX_PAYLOAD_SIZE = 4096;
10
- const ENCODER = new TextEncoder();
11
- /**
12
- * Creates a content addressed chunk and verifies the payload size.
13
- *
14
- * @param payloadBytes the data to be stored in the chunk
15
- */
16
- function makeContentAddressedChunk(payloadBytes) {
17
- if (!(payloadBytes instanceof Uint8Array)) {
18
- payloadBytes = ENCODER.encode(payloadBytes);
19
- }
20
- if (payloadBytes.length < exports.MIN_PAYLOAD_SIZE || payloadBytes.length > exports.MAX_PAYLOAD_SIZE) {
21
- throw new RangeError(`payload size ${payloadBytes.length} exceeds limits [${exports.MIN_PAYLOAD_SIZE}, ${exports.MAX_PAYLOAD_SIZE}]`);
22
- }
23
- const span = typed_bytes_1.Span.fromBigInt(BigInt(payloadBytes.length));
24
- const data = cafe_utility_1.Binary.concatBytes(span.toUint8Array(), payloadBytes);
25
- return {
26
- data,
27
- span,
28
- payload: bytes_1.Bytes.fromSlice(data, typed_bytes_1.Span.LENGTH),
29
- address: (0, bmt_1.calculateChunkAddress)(data),
30
- };
13
+ function unmarshalContentAddressedChunk(data) {
14
+ data = new bytes_1.Bytes(data);
15
+ return makeContentAddressedChunk(data.toUint8Array().slice(typed_bytes_1.Span.LENGTH), typed_bytes_1.Span.fromSlice(data.toUint8Array(), 0));
31
16
  }
32
- exports.makeContentAddressedChunk = makeContentAddressedChunk;
33
- function asContentAddressedChunk(chunkBytes) {
34
- if (chunkBytes.length < exports.MIN_PAYLOAD_SIZE + typed_bytes_1.Span.LENGTH || chunkBytes.length > exports.MAX_PAYLOAD_SIZE + typed_bytes_1.Span.LENGTH) {
35
- throw new RangeError(`chunk size ${chunkBytes.length} exceeds limits [${exports.MIN_PAYLOAD_SIZE + typed_bytes_1.Span.LENGTH}, ${typed_bytes_1.Span.LENGTH}]`);
17
+ function makeContentAddressedChunk(rawPayload, span) {
18
+ if (cafe_utility_1.Types.isString(rawPayload)) {
19
+ rawPayload = bytes_1.Bytes.fromUtf8(rawPayload);
20
+ }
21
+ if (rawPayload.length < exports.MIN_PAYLOAD_SIZE || rawPayload.length > exports.MAX_PAYLOAD_SIZE) {
22
+ throw new RangeError(`payload size ${rawPayload.length} exceeds limits [${exports.MIN_PAYLOAD_SIZE}, ${exports.MAX_PAYLOAD_SIZE}]`);
36
23
  }
37
- const span = typed_bytes_1.Span.fromSlice(chunkBytes, 0);
38
- const data = cafe_utility_1.Binary.concatBytes(span.toUint8Array(), chunkBytes.slice(typed_bytes_1.Span.LENGTH));
24
+ const typedSpan = span
25
+ ? typeof span === 'bigint'
26
+ ? typed_bytes_1.Span.fromBigInt(span)
27
+ : span
28
+ : typed_bytes_1.Span.fromBigInt(BigInt(rawPayload.length));
29
+ const payload = new bytes_1.Bytes(rawPayload);
30
+ const data = cafe_utility_1.Binary.concatBytes(typedSpan.toUint8Array(), payload.toUint8Array());
31
+ const address = (0, bmt_1.calculateChunkAddress)(data);
39
32
  return {
40
33
  data,
41
- span,
42
- payload: bytes_1.Bytes.fromSlice(data, typed_bytes_1.Span.LENGTH),
43
- address: (0, bmt_1.calculateChunkAddress)(data),
34
+ span: typedSpan,
35
+ payload,
36
+ address,
37
+ toSingleOwnerChunk: (identifier, signer) => {
38
+ return (0, soc_1.makeSingleOwnerChunk)(address, typedSpan, payload, identifier, signer);
39
+ },
44
40
  };
45
41
  }
46
- exports.asContentAddressedChunk = asContentAddressedChunk;
@@ -15,15 +15,31 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.downloadSingleOwnerChunk = exports.uploadSingleOwnerChunkWithWrappedChunk = exports.uploadSingleOwnerChunkData = exports.uploadSingleOwnerChunk = exports.makeSingleOwnerChunk = exports.makeSOCAddress = exports.makeSingleOwnerChunkFromData = void 0;
36
+ exports.unmarshalSingleOwnerChunk = unmarshalSingleOwnerChunk;
37
+ exports.makeSOCAddress = makeSOCAddress;
38
+ exports.makeSingleOwnerChunk = makeSingleOwnerChunk;
39
+ exports.uploadSingleOwnerChunk = uploadSingleOwnerChunk;
40
+ exports.uploadSingleOwnerChunkData = uploadSingleOwnerChunkData;
41
+ exports.uploadSingleOwnerChunkWithWrappedChunk = uploadSingleOwnerChunkWithWrappedChunk;
42
+ exports.downloadSingleOwnerChunk = downloadSingleOwnerChunk;
27
43
  const cafe_utility_1 = require("cafe-utility");
28
44
  const chunkAPI = __importStar(require("../modules/chunk"));
29
45
  const socAPI = __importStar(require("../modules/soc"));
@@ -33,8 +49,8 @@ const typed_bytes_1 = require("../utils/typed-bytes");
33
49
  const bmt_1 = require("./bmt");
34
50
  const cac_1 = require("./cac");
35
51
  const SOC_SIGNATURE_OFFSET = typed_bytes_1.Identifier.LENGTH;
36
- const SOC_SPAN_OFFSET = SOC_SIGNATURE_OFFSET + typed_bytes_1.Signature.LENGTH;
37
- const SOC_PAYLOAD_OFFSET = SOC_SPAN_OFFSET + typed_bytes_1.Span.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;
38
54
  function recoverChunkOwner(data) {
39
55
  const cacData = data.slice(SOC_SPAN_OFFSET);
40
56
  const chunkAddress = (0, bmt_1.calculateChunkAddress)(cacData);
@@ -45,21 +61,22 @@ function recoverChunkOwner(data) {
45
61
  return ownerAddress;
46
62
  }
47
63
  /**
48
- * Verifies if the data is a valid single owner chunk
64
+ * Unmarshals arbitrary data into a Single Owner Chunk.
65
+ * Throws an error if the data is not a valid SOC.
49
66
  *
50
67
  * @param data The chunk data
51
68
  * @param address The address of the single owner chunk
52
69
  *
53
70
  * @returns a single owner chunk or throws error
54
71
  */
55
- function makeSingleOwnerChunkFromData(data, address) {
72
+ function unmarshalSingleOwnerChunk(data, address) {
56
73
  data = data instanceof bytes_1.Bytes ? data.toUint8Array() : data;
57
74
  address = new typed_bytes_1.Reference(address);
58
75
  const ownerAddress = recoverChunkOwner(data);
59
76
  const identifier = bytes_1.Bytes.fromSlice(data, 0, typed_bytes_1.Identifier.LENGTH);
60
77
  const socAddress = new typed_bytes_1.Reference(cafe_utility_1.Binary.keccak256(cafe_utility_1.Binary.concatBytes(identifier.toUint8Array(), ownerAddress.toUint8Array())));
61
78
  if (!cafe_utility_1.Binary.equals(address.toUint8Array(), socAddress.toUint8Array())) {
62
- throw new error_1.BeeError('SOC Data does not match given address!');
79
+ throw new error_1.BeeError('SOC data does not match given address!');
63
80
  }
64
81
  const signature = typed_bytes_1.Signature.fromSlice(data, SOC_SIGNATURE_OFFSET);
65
82
  const span = typed_bytes_1.Span.fromSlice(data, SOC_SPAN_OFFSET);
@@ -74,11 +91,9 @@ function makeSingleOwnerChunkFromData(data, address) {
74
91
  owner: ownerAddress,
75
92
  };
76
93
  }
77
- exports.makeSingleOwnerChunkFromData = makeSingleOwnerChunkFromData;
78
94
  function makeSOCAddress(identifier, address) {
79
95
  return new typed_bytes_1.Reference(cafe_utility_1.Binary.keccak256(cafe_utility_1.Binary.concatBytes(identifier.toUint8Array(), address.toUint8Array())));
80
96
  }
81
- exports.makeSOCAddress = makeSOCAddress;
82
97
  /**
83
98
  * Creates a single owner chunk object
84
99
  *
@@ -86,25 +101,22 @@ exports.makeSOCAddress = makeSOCAddress;
86
101
  * @param identifier The identifier of the chunk
87
102
  * @param signer The signer interface for signing the chunk
88
103
  */
89
- function makeSingleOwnerChunk(chunk, identifier, signer) {
104
+ function makeSingleOwnerChunk(address, span, payload, identifier, signer) {
90
105
  identifier = new typed_bytes_1.Identifier(identifier);
91
106
  signer = new typed_bytes_1.PrivateKey(signer);
92
- const address = makeSOCAddress(identifier, signer.publicKey().address());
93
- const signature = signer.sign(cafe_utility_1.Binary.concatBytes(identifier.toUint8Array(), chunk.address.toUint8Array()));
94
- const data = cafe_utility_1.Binary.concatBytes(identifier.toUint8Array(), signature.toUint8Array(), chunk.data);
95
- const span = typed_bytes_1.Span.fromSlice(chunk.data, 0);
96
- const payload = bytes_1.Bytes.fromSlice(chunk.data, typed_bytes_1.Span.LENGTH);
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());
97
110
  return {
98
111
  data,
99
112
  identifier,
100
113
  signature,
101
114
  span,
102
115
  payload,
103
- address,
116
+ address: socAddress,
104
117
  owner: signer.publicKey().address(),
105
118
  };
106
119
  }
107
- exports.makeSingleOwnerChunk = makeSingleOwnerChunk;
108
120
  /**
109
121
  * Helper function to upload a chunk.
110
122
  *
@@ -119,7 +131,6 @@ async function uploadSingleOwnerChunk(requestOptions, chunk, stamp, options) {
119
131
  const data = cafe_utility_1.Binary.concatBytes(chunk.span.toUint8Array(), chunk.payload.toUint8Array());
120
132
  return socAPI.upload(requestOptions, chunk.owner, chunk.identifier, chunk.signature, data, stamp, options);
121
133
  }
122
- exports.uploadSingleOwnerChunk = uploadSingleOwnerChunk;
123
134
  /**
124
135
  * Helper function to create and upload SOC.
125
136
  *
@@ -134,17 +145,15 @@ async function uploadSingleOwnerChunkData(requestOptions, signer, stamp, identif
134
145
  signer = new typed_bytes_1.PrivateKey(signer);
135
146
  identifier = new typed_bytes_1.Identifier(identifier);
136
147
  const cac = (0, cac_1.makeContentAddressedChunk)(data);
137
- const soc = makeSingleOwnerChunk(cac, identifier, signer);
148
+ const soc = cac.toSingleOwnerChunk(identifier, signer);
138
149
  return uploadSingleOwnerChunk(requestOptions, soc, stamp, options);
139
150
  }
140
- exports.uploadSingleOwnerChunkData = uploadSingleOwnerChunkData;
141
- async function uploadSingleOwnerChunkWithWrappedChunk(requestOptions, signer, stamp, identifier, rootChunk, options) {
151
+ async function uploadSingleOwnerChunkWithWrappedChunk(requestOptions, signer, stamp, identifier, wrappedChunk, options) {
142
152
  signer = new typed_bytes_1.PrivateKey(signer);
143
153
  identifier = new typed_bytes_1.Identifier(identifier);
144
- const soc = makeSingleOwnerChunk((0, cac_1.asContentAddressedChunk)(rootChunk), identifier, signer);
154
+ const soc = wrappedChunk.toSingleOwnerChunk(identifier, signer);
145
155
  return uploadSingleOwnerChunk(requestOptions, soc, stamp, options);
146
156
  }
147
- exports.uploadSingleOwnerChunkWithWrappedChunk = uploadSingleOwnerChunkWithWrappedChunk;
148
157
  /**
149
158
  * Helper function to download SOC.
150
159
  *
@@ -157,6 +166,5 @@ async function downloadSingleOwnerChunk(requestOptions, ownerAddress, identifier
157
166
  ownerAddress = new typed_bytes_1.EthAddress(ownerAddress);
158
167
  const address = makeSOCAddress(identifier, ownerAddress);
159
168
  const cac = await chunkAPI.download(requestOptions, address.toHex());
160
- return makeSingleOwnerChunkFromData(cac, address);
169
+ return unmarshalSingleOwnerChunk(cac, address);
161
170
  }
162
- exports.downloadSingleOwnerChunk = downloadSingleOwnerChunk;
@@ -1,10 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.makeFeedIdentifier = void 0;
3
+ exports.makeFeedIdentifier = makeFeedIdentifier;
4
4
  const cafe_utility_1 = require("cafe-utility");
5
5
  const typed_bytes_1 = require("../utils/typed-bytes");
6
6
  function makeFeedIdentifier(topic, index) {
7
7
  index = typeof index === 'number' ? typed_bytes_1.FeedIndex.fromBigInt(BigInt(index)) : index;
8
8
  return new typed_bytes_1.Identifier(cafe_utility_1.Binary.keccak256(cafe_utility_1.Binary.concatBytes(topic.toUint8Array(), index.toUint8Array())));
9
9
  }
10
- exports.makeFeedIdentifier = makeFeedIdentifier;
@@ -15,15 +15,32 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.makeFeedWriter = exports.makeFeedReader = exports.downloadFeedUpdateAsCAC = exports.downloadFeedUpdate = exports.getFeedUpdateChunkReference = exports.updateFeedWithPayload = exports.updateFeedWithReference = exports.findNextIndex = void 0;
36
+ exports.findNextIndex = findNextIndex;
37
+ exports.updateFeedWithReference = updateFeedWithReference;
38
+ exports.updateFeedWithPayload = updateFeedWithPayload;
39
+ exports.getFeedUpdateChunkReference = getFeedUpdateChunkReference;
40
+ exports.downloadFeedUpdate = downloadFeedUpdate;
41
+ exports.downloadFeedUpdateAsCAC = downloadFeedUpdateAsCAC;
42
+ exports.makeFeedReader = makeFeedReader;
43
+ exports.makeFeedWriter = makeFeedWriter;
27
44
  const cafe_utility_1 = require("cafe-utility");
28
45
  const cac_1 = require("../chunk/cac");
29
46
  const soc_1 = require("../chunk/soc");
@@ -53,7 +70,6 @@ async function findNextIndex(requestOptions, owner, topic) {
53
70
  throw e;
54
71
  }
55
72
  }
56
- exports.findNextIndex = findNextIndex;
57
73
  async function updateFeedWithReference(requestOptions, signer, topic, reference, postageBatchId, options) {
58
74
  reference = new typed_bytes_1.Reference(reference);
59
75
  const nextIndex = options?.index ?? (await findNextIndex(requestOptions, signer.publicKey().address(), topic));
@@ -63,28 +79,25 @@ async function updateFeedWithReference(requestOptions, signer, topic, reference,
63
79
  const payloadBytes = cafe_utility_1.Binary.concatBytes(timestamp, reference.toUint8Array());
64
80
  return (0, soc_1.uploadSingleOwnerChunkData)(requestOptions, signer, postageBatchId, identifier, payloadBytes, options);
65
81
  }
66
- exports.updateFeedWithReference = updateFeedWithReference;
67
82
  async function updateFeedWithPayload(requestOptions, signer, topic, data, postageBatchId, options) {
68
83
  const nextIndex = options?.index ?? (await findNextIndex(requestOptions, signer.publicKey().address(), topic));
69
84
  const identifier = (0, identifier_1.makeFeedIdentifier)(topic, nextIndex);
70
85
  if (data.length > 4096) {
71
86
  const uploadResult = await bytes.upload(requestOptions, data, postageBatchId, options);
72
- const rootChunk = await chunkAPI.download(requestOptions, uploadResult.reference);
87
+ const rootChunk = (0, cac_1.unmarshalContentAddressedChunk)(await chunkAPI.download(requestOptions, uploadResult.reference));
73
88
  return (0, soc_1.uploadSingleOwnerChunkWithWrappedChunk)(requestOptions, signer, postageBatchId, identifier, rootChunk, options);
74
89
  }
75
90
  return (0, soc_1.uploadSingleOwnerChunkData)(requestOptions, signer, postageBatchId, identifier, cafe_utility_1.Types.isString(data) ? bytes_1.Bytes.fromUtf8(data).toUint8Array() : data, options);
76
91
  }
77
- exports.updateFeedWithPayload = updateFeedWithPayload;
78
92
  function getFeedUpdateChunkReference(owner, topic, index) {
79
93
  const identifier = (0, identifier_1.makeFeedIdentifier)(topic, index);
80
94
  return new typed_bytes_1.Reference(cafe_utility_1.Binary.keccak256(cafe_utility_1.Binary.concatBytes(identifier.toUint8Array(), owner.toUint8Array())));
81
95
  }
82
- exports.getFeedUpdateChunkReference = getFeedUpdateChunkReference;
83
96
  async function downloadFeedUpdate(requestOptions, owner, topic, index, hasTimestamp = false) {
84
97
  index = typeof index === 'number' ? typed_bytes_1.FeedIndex.fromBigInt(BigInt(index)) : index;
85
98
  const address = getFeedUpdateChunkReference(owner, topic, index);
86
99
  const data = await chunkAPI.download(requestOptions, address.toHex());
87
- const soc = (0, soc_1.makeSingleOwnerChunkFromData)(data, address);
100
+ const soc = (0, soc_1.unmarshalSingleOwnerChunk)(data, address);
88
101
  let timestamp = cafe_utility_1.Optional.empty();
89
102
  if (hasTimestamp) {
90
103
  const timestampBytes = bytes_1.Bytes.fromSlice(soc.payload.toUint8Array(), TIMESTAMP_PAYLOAD_OFFSET, TIMESTAMP_PAYLOAD_SIZE);
@@ -95,14 +108,13 @@ async function downloadFeedUpdate(requestOptions, owner, topic, index, hasTimest
95
108
  payload: new bytes_1.Bytes(soc.payload.offset(hasTimestamp ? REFERENCE_PAYLOAD_OFFSET : 0)),
96
109
  };
97
110
  }
98
- exports.downloadFeedUpdate = downloadFeedUpdate;
99
111
  async function downloadFeedUpdateAsCAC(requestOptions, owner, topic, index) {
100
112
  index = typeof index === 'number' ? typed_bytes_1.FeedIndex.fromBigInt(BigInt(index)) : index;
101
113
  const address = getFeedUpdateChunkReference(owner, topic, index);
102
114
  const data = await chunkAPI.download(requestOptions, address);
103
- return (0, cac_1.asContentAddressedChunk)(data.slice(typed_bytes_1.Identifier.LENGTH + typed_bytes_1.Signature.LENGTH));
115
+ const soc = (0, soc_1.unmarshalSingleOwnerChunk)(data, address);
116
+ return (0, cac_1.makeContentAddressedChunk)(soc.payload, soc.span);
104
117
  }
105
- exports.downloadFeedUpdateAsCAC = downloadFeedUpdateAsCAC;
106
118
  function makeFeedReader(requestOptions, topic, owner) {
107
119
  // TODO: remove after enough time has passed in deprecated version
108
120
  const download = async (options) => {
@@ -152,7 +164,6 @@ function makeFeedReader(requestOptions, topic, owner) {
152
164
  topic,
153
165
  };
154
166
  }
155
- exports.makeFeedReader = makeFeedReader;
156
167
  function makeFeedWriter(requestOptions, topic, signer) {
157
168
  const upload = async (postageBatchId, reference, options) => {
158
169
  return updateFeedWithReference(requestOptions, signer, topic, reference, postageBatchId, options);
@@ -167,4 +178,3 @@ function makeFeedWriter(requestOptions, topic, signer) {
167
178
  uploadPayload,
168
179
  };
169
180
  }
170
- exports.makeFeedWriter = makeFeedWriter;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.areAllSequentialFeedsUpdateRetrievable = void 0;
3
+ exports.areAllSequentialFeedsUpdateRetrievable = areAllSequentialFeedsUpdateRetrievable;
4
4
  const cafe_utility_1 = require("cafe-utility");
5
5
  const typed_bytes_1 = require("../utils/typed-bytes");
6
6
  const index_1 = require("./index");
@@ -44,4 +44,3 @@ async function areAllSequentialFeedsUpdateRetrievable(bee, owner, topic, index,
44
44
  const chunkRetrievablePromises = getAllSequenceUpdateReferences(owner, topic, index).map(async (reference) => isChunkRetrievable(bee, reference, options, requestOptions));
45
45
  return (await Promise.all(chunkRetrievablePromises)).every(result => result);
46
46
  }
47
- exports.areAllSequentialFeedsUpdateRetrievable = areAllSequentialFeedsUpdateRetrievable;
package/dist/cjs/index.js CHANGED
@@ -18,13 +18,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
18
18
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
19
19
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
20
20
  };
21
- var __importStar = (this && this.__importStar) || function (mod) {
22
- if (mod && mod.__esModule) return mod;
23
- var result = {};
24
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
25
- __setModuleDefault(result, mod);
26
- return result;
27
- };
21
+ var __importStar = (this && this.__importStar) || (function () {
22
+ var ownKeys = function(o) {
23
+ ownKeys = Object.getOwnPropertyNames || function (o) {
24
+ var ar = [];
25
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
26
+ return ar;
27
+ };
28
+ return ownKeys(o);
29
+ };
30
+ return function (mod) {
31
+ if (mod && mod.__esModule) return mod;
32
+ var result = {};
33
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
34
+ __setModuleDefault(result, mod);
35
+ return result;
36
+ };
37
+ })();
28
38
  Object.defineProperty(exports, "__esModule", { value: true });
29
39
  exports.Stamper = exports.BeeDev = 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;
30
40
  const bee_1 = require("./bee");
@@ -316,7 +316,17 @@ class MantarayNode {
316
316
  */
317
317
  async saveRecursively(bee, postageBatchId, options, requestOptions) {
318
318
  for (const fork of this.forks.values()) {
319
- await fork.node.saveRecursively(bee, postageBatchId, options, requestOptions);
319
+ const uploadResult = await fork.node.saveRecursively(bee, postageBatchId, options, requestOptions);
320
+ if (options?.act) {
321
+ let historyAddress;
322
+ uploadResult.historyAddress.ifPresent(ref => (historyAddress = ref));
323
+ if (historyAddress) {
324
+ if (!fork.node.metadata) {
325
+ fork.node.metadata = {};
326
+ }
327
+ fork.node.metadata['swarm-act-history-address'] = historyAddress.toHex();
328
+ }
329
+ }
320
330
  }
321
331
  const result = await bee.uploadData(postageBatchId, await this.marshal(), options, requestOptions);
322
332
  this.selfAddress = result.reference.toUint8Array();
@@ -330,7 +340,14 @@ class MantarayNode {
330
340
  if (!fork.node.selfAddress) {
331
341
  throw Error('MantarayNode#loadRecursively fork.node.selfAddress is not set');
332
342
  }
333
- const node = await MantarayNode.unmarshal(bee, fork.node.selfAddress, options, requestOptions);
343
+ let downloadOptions = options;
344
+ if (fork.node.metadata && fork.node.metadata['swarm-act-history-address']) {
345
+ downloadOptions = {
346
+ ...options,
347
+ actHistoryAddress: fork.node.metadata['swarm-act-history-address'],
348
+ };
349
+ }
350
+ const node = await MantarayNode.unmarshal(bee, fork.node.selfAddress, downloadOptions, requestOptions);
334
351
  fork.node.targetAddress = node.targetAddress;
335
352
  fork.node.forks = node.forks;
336
353
  fork.node.path = fork.prefix;
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.downloadReadable = exports.download = exports.head = exports.upload = void 0;
3
+ exports.upload = upload;
4
+ exports.head = head;
5
+ exports.download = download;
6
+ exports.downloadReadable = downloadReadable;
4
7
  const cafe_utility_1 = require("cafe-utility");
5
8
  const bytes_1 = require("../utils/bytes");
6
9
  const headers_1 = require("../utils/headers");
@@ -36,7 +39,6 @@ async function upload(requestOptions, data, postageBatchId, options) {
36
39
  : cafe_utility_1.Optional.empty(),
37
40
  };
38
41
  }
39
- exports.upload = upload;
40
42
  /**
41
43
  * Requests content length for a reference
42
44
  *
@@ -54,7 +56,6 @@ async function head(requestOptions, reference) {
54
56
  contentLength: parseInt(response.headers['content-length']),
55
57
  };
56
58
  }
57
- exports.head = head;
58
59
  /**
59
60
  * Download data as a byte array
60
61
  *
@@ -72,7 +73,6 @@ async function download(requestOptions, resource, options) {
72
73
  });
73
74
  return new bytes_1.Bytes(response.data);
74
75
  }
75
- exports.download = download;
76
76
  /**
77
77
  * Download data as a readable stream
78
78
  *
@@ -90,4 +90,3 @@ async function downloadReadable(requestOptions, resource, options) {
90
90
  });
91
91
  return response.data;
92
92
  }
93
- exports.downloadReadable = downloadReadable;
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.uploadCollection = exports.downloadFileReadable = exports.downloadFile = exports.uploadFile = void 0;
3
+ exports.uploadFile = uploadFile;
4
+ exports.downloadFile = downloadFile;
5
+ exports.downloadFileReadable = downloadFileReadable;
6
+ exports.uploadCollection = uploadCollection;
4
7
  const cafe_utility_1 = require("cafe-utility");
5
8
  const bytes_1 = require("../utils/bytes");
6
9
  const collection_1 = require("../utils/collection");
@@ -43,7 +46,6 @@ async function uploadFile(requestOptions, data, postageBatchId, name, options) {
43
46
  : cafe_utility_1.Optional.empty(),
44
47
  };
45
48
  }
46
- exports.uploadFile = uploadFile;
47
49
  /**
48
50
  * Download single file as a buffer
49
51
  *
@@ -64,7 +66,6 @@ async function downloadFile(requestOptions, resource, path = '', options) {
64
66
  };
65
67
  return file;
66
68
  }
67
- exports.downloadFile = downloadFile;
68
69
  /**
69
70
  * Download single file as a readable stream
70
71
  *
@@ -86,7 +87,6 @@ async function downloadFileReadable(requestOptions, reference, path = '', option
86
87
  };
87
88
  return file;
88
89
  }
89
- exports.downloadFileReadable = downloadFileReadable;
90
90
  /*******************************************************************************************************************/
91
91
  // Collections
92
92
  /**
@@ -108,4 +108,3 @@ async function uploadCollection(requestOptions, collection, postageBatchId, opti
108
108
  : cafe_utility_1.Optional.empty(),
109
109
  };
110
110
  }
111
- exports.uploadCollection = uploadCollection;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.download = exports.upload = void 0;
3
+ exports.upload = upload;
4
+ exports.download = download;
4
5
  const cafe_utility_1 = require("cafe-utility");
5
6
  const headers_1 = require("../utils/headers");
6
7
  const http_1 = require("../utils/http");
@@ -39,7 +40,6 @@ async function upload(requestOptions, data, stamp, options) {
39
40
  : cafe_utility_1.Optional.empty(),
40
41
  };
41
42
  }
42
- exports.upload = upload;
43
43
  /**
44
44
  * Download chunk data as a byte array
45
45
  *
@@ -56,4 +56,3 @@ async function download(requestOptions, reference, options) {
56
56
  });
57
57
  return new Uint8Array(response.data);
58
58
  }
59
- exports.download = download;
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getPastDueConsumptionPeerBalance = exports.getPastDueConsumptionBalances = exports.getPeerBalance = exports.getAllBalances = void 0;
3
+ exports.getAllBalances = getAllBalances;
4
+ exports.getPeerBalance = getPeerBalance;
5
+ exports.getPastDueConsumptionBalances = getPastDueConsumptionBalances;
6
+ exports.getPastDueConsumptionPeerBalance = getPastDueConsumptionPeerBalance;
4
7
  const cafe_utility_1 = require("cafe-utility");
5
8
  const http_1 = require("../../utils/http");
6
9
  const tokens_1 = require("../../utils/tokens");
@@ -26,7 +29,6 @@ async function getAllBalances(requestOptions) {
26
29
  })),
27
30
  };
28
31
  }
29
- exports.getAllBalances = getAllBalances;
30
32
  /**
31
33
  * Get the balances with a specific peer including prepaid services
32
34
  *
@@ -44,7 +46,6 @@ async function getPeerBalance(requestOptions, address) {
44
46
  balance: tokens_1.BZZ.fromPLUR((0, type_1.asNumberString)(body.balance, { name: 'balance' })),
45
47
  };
46
48
  }
47
- exports.getPeerBalance = getPeerBalance;
48
49
  /**
49
50
  * Get the past due consumption balances with all known peers
50
51
  *
@@ -64,7 +65,6 @@ async function getPastDueConsumptionBalances(requestOptions) {
64
65
  })),
65
66
  };
66
67
  }
67
- exports.getPastDueConsumptionBalances = getPastDueConsumptionBalances;
68
68
  /**
69
69
  * Get the past due consumption balance with a specific peer
70
70
  *
@@ -82,4 +82,3 @@ async function getPastDueConsumptionPeerBalance(requestOptions, address) {
82
82
  balance: tokens_1.BZZ.fromPLUR((0, type_1.asNumberString)(body.balance, { name: 'balance' })),
83
83
  };
84
84
  }
85
- exports.getPastDueConsumptionPeerBalance = getPastDueConsumptionPeerBalance;