@ethersphere/bee-js 3.4.0-pre.0 → 4.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 (43) hide show
  1. package/LICENSE +24 -22
  2. package/README.md +0 -8
  3. package/dist/cjs/bee.js +71 -18
  4. package/dist/cjs/feed/identifier.js +35 -0
  5. package/dist/cjs/feed/index.js +34 -90
  6. package/dist/cjs/feed/retrievable.js +72 -0
  7. package/dist/cjs/modules/debug/status.js +3 -3
  8. package/dist/cjs/modules/feed.js +3 -3
  9. package/dist/cjs/types/index.js +2 -1
  10. package/dist/cjs/utils/bytes.js +15 -1
  11. package/dist/cjs/utils/reference.js +36 -0
  12. package/dist/cjs/utils/type.js +36 -1
  13. package/dist/index.browser.min.js +1 -1
  14. package/dist/index.browser.min.js.map +1 -1
  15. package/dist/mjs/bee.js +77 -19
  16. package/dist/mjs/chunk/cac.js +1 -1
  17. package/dist/mjs/feed/identifier.js +35 -0
  18. package/dist/mjs/feed/index.js +39 -94
  19. package/dist/mjs/feed/retrievable.js +105 -0
  20. package/dist/mjs/modules/debug/status.js +3 -3
  21. package/dist/mjs/modules/feed.js +1 -1
  22. package/dist/mjs/types/index.js +1 -0
  23. package/dist/mjs/utils/bytes.js +15 -0
  24. package/dist/mjs/utils/reference.js +32 -0
  25. package/dist/mjs/utils/type.js +38 -1
  26. package/dist/types/bee.d.ts +49 -19
  27. package/dist/types/chunk/cac.d.ts +4 -5
  28. package/dist/types/chunk/soc.d.ts +4 -4
  29. package/dist/types/feed/identifier.d.ts +4 -0
  30. package/dist/types/feed/index.d.ts +9 -16
  31. package/dist/types/feed/retrievable.d.ts +5 -0
  32. package/dist/types/modules/bytes.d.ts +3 -3
  33. package/dist/types/modules/bzz.d.ts +3 -3
  34. package/dist/types/modules/chunk.d.ts +2 -2
  35. package/dist/types/modules/debug/status.d.ts +3 -3
  36. package/dist/types/modules/feed.d.ts +12 -1
  37. package/dist/types/modules/stewardship.d.ts +3 -3
  38. package/dist/types/types/debug.d.ts +20 -3
  39. package/dist/types/types/index.d.ts +11 -2
  40. package/dist/types/utils/bytes.d.ts +7 -0
  41. package/dist/types/utils/reference.d.ts +2 -0
  42. package/dist/types/utils/type.d.ts +2 -1
  43. package/package.json +22 -23
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makeBytesReference = void 0;
4
+ const types_1 = require("../types");
5
+ const bytes_1 = require("./bytes");
6
+ const hex_1 = require("./hex");
7
+ function makeBytesReference(reference, offset = 0) {
8
+ if (typeof reference === 'string') {
9
+ if (offset) {
10
+ throw new Error('Offset property can be set only for UintArray reference!');
11
+ }
12
+ try {
13
+ // Non-encrypted chunk hex string reference
14
+ const hexReference = (0, hex_1.makeHexString)(reference, types_1.REFERENCE_HEX_LENGTH);
15
+ return (0, hex_1.hexToBytes)(hexReference);
16
+ }
17
+ catch (e) {
18
+ if (!(e instanceof TypeError)) {
19
+ throw e;
20
+ }
21
+ // Encrypted chunk hex string reference
22
+ const hexReference = (0, hex_1.makeHexString)(reference, types_1.ENCRYPTED_REFERENCE_HEX_LENGTH);
23
+ return (0, hex_1.hexToBytes)(hexReference);
24
+ }
25
+ }
26
+ else if (reference instanceof Uint8Array) {
27
+ if ((0, bytes_1.hasBytesAtOffset)(reference, offset, types_1.ENCRYPTED_REFERENCE_BYTES_LENGTH)) {
28
+ return (0, bytes_1.bytesAtOffset)(reference, offset, types_1.ENCRYPTED_REFERENCE_BYTES_LENGTH);
29
+ }
30
+ else if ((0, bytes_1.hasBytesAtOffset)(reference, offset, types_1.REFERENCE_BYTES_LENGTH)) {
31
+ return (0, bytes_1.bytesAtOffset)(reference, offset, types_1.REFERENCE_BYTES_LENGTH);
32
+ }
33
+ }
34
+ throw new TypeError('invalid chunk reference');
35
+ }
36
+ exports.makeBytesReference = makeBytesReference;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.assertTransactionHash = exports.makeTagUid = exports.assertAllTagsOptions = exports.assertFileData = exports.assertData = exports.assertCashoutOptions = exports.assertPostageBatchOptions = exports.assertPublicKey = exports.assertPssMessageHandler = exports.assertAddressPrefix = exports.assertTag = exports.isTag = exports.assertCollectionUploadOptions = exports.assertFileUploadOptions = exports.assertUploadOptions = exports.assertRequestOptions = exports.assertBatchId = exports.assertAddress = exports.assertReference = exports.assertNonNegativeInteger = exports.assertInteger = exports.assertBoolean = exports.assertStrictlyObject = exports.isError = exports.isStrictlyObject = exports.isObject = exports.isInteger = exports.isUint8Array = void 0;
3
+ exports.assertTransactionHash = exports.makeTagUid = exports.assertAllTagsOptions = exports.assertFileData = exports.assertData = exports.assertCashoutOptions = exports.assertPostageBatchOptions = exports.assertPublicKey = exports.assertPssMessageHandler = exports.assertAddressPrefix = exports.assertTag = exports.isTag = exports.assertCollectionUploadOptions = exports.assertFileUploadOptions = exports.assertUploadOptions = exports.assertRequestOptions = exports.assertBatchId = exports.assertAddress = exports.assertReferenceOrEns = exports.assertReference = exports.assertNonNegativeInteger = exports.assertInteger = exports.assertBoolean = exports.assertStrictlyObject = exports.isError = exports.isStrictlyObject = exports.isObject = exports.isInteger = exports.isUint8Array = void 0;
4
4
  const types_1 = require("../types");
5
5
  const error_1 = require("./error");
6
6
  const file_1 = require("./file");
@@ -77,6 +77,41 @@ function assertReference(value) {
77
77
  }
78
78
  }
79
79
  exports.assertReference = assertReference;
80
+ function assertReferenceOrEns(value) {
81
+ if (typeof value !== 'string') {
82
+ throw new TypeError('ReferenceOrEns has to be a string!');
83
+ }
84
+ if ((0, hex_1.isHexString)(value)) {
85
+ assertReference(value);
86
+ return;
87
+ }
88
+ /**
89
+ * a.asdf - VALID
90
+ * test.eth - VALID
91
+ * ADAM.ETH - VALID
92
+ * ADAM UHLIR.ETH - INVALID
93
+ * test.whatever.eth - VALID
94
+ * -adg.ets - INVALID
95
+ * adg-.ets - INVALID
96
+ * as-a.com - VALID
97
+ * ethswarm.org - VALID
98
+ * http://asdf.asf - INVALID
99
+ * řš+ýí.šě+ř.čě - VALID
100
+ * tsg.asg?asg - INVALID
101
+ * tsg.asg:1599 - INVALID
102
+ * ethswarm.something- - INVALID
103
+ * ethswarm.-something - INVALID
104
+ * ethswarm.some-thing - VALID
105
+ */
106
+ const DOMAIN_REGEX = /^(?:(?!-)[^.\/?:\s]{1,63}(?<!-)\.)+(?!-)[^.\/?:\s]{2,63}(?<!-)$/;
107
+ // We are doing best-effort validation of domain here. The proper way would be to do validation using IDNA UTS64 standard
108
+ // but that would give us high penalty to our dependencies as the library (idna-uts46-hx) that does this validation and translation
109
+ // adds 160kB minified size which is significant. We expects that full validation will be done on Bee side.
110
+ if (!DOMAIN_REGEX.test(value)) {
111
+ throw new TypeError('ReferenceOrEns is not valid Reference, but also not valid ENS domain.');
112
+ }
113
+ }
114
+ exports.assertReferenceOrEns = assertReferenceOrEns;
80
115
  function assertAddress(value) {
81
116
  (0, hex_1.assertHexString)(value, types_1.ADDRESS_HEX_LENGTH, 'Address');
82
117
  }