@waku/rln 0.1.6-f911bf8.0 → 0.1.7-7a9850d.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 (60) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/bundle/node_modules/@chainsafe/is-ip/lib/is-ip.js +12 -0
  3. package/bundle/node_modules/@chainsafe/is-ip/lib/parse.js +26 -0
  4. package/bundle/node_modules/@chainsafe/is-ip/lib/parser.js +202 -0
  5. package/bundle/node_modules/@ethersproject/bignumber/lib.esm/bignumber.js +1 -1
  6. package/bundle/node_modules/@multiformats/multiaddr/dist/src/constants.js +43 -0
  7. package/bundle/node_modules/@multiformats/multiaddr/dist/src/errors.js +17 -0
  8. package/bundle/node_modules/@multiformats/multiaddr/dist/src/registry.js +245 -0
  9. package/bundle/node_modules/@multiformats/multiaddr/dist/src/utils.js +191 -0
  10. package/bundle/node_modules/@multiformats/multiaddr/dist/src/validation.js +30 -0
  11. package/bundle/node_modules/debug/src/browser.js +1 -1
  12. package/bundle/node_modules/debug/src/common.js +1 -1
  13. package/bundle/node_modules/lodash/lodash.js +5 -5
  14. package/bundle/node_modules/multiformats/dist/src/bases/base.js +12 -9
  15. package/bundle/node_modules/multiformats/dist/src/bytes.js +19 -3
  16. package/bundle/node_modules/multiformats/dist/src/cid.js +371 -0
  17. package/bundle/node_modules/multiformats/dist/src/hashes/digest.js +62 -0
  18. package/bundle/node_modules/multiformats/dist/src/varint.js +15 -0
  19. package/bundle/node_modules/multiformats/dist/src/vendor/varint.js +78 -0
  20. package/bundle/node_modules/uint8arrays/dist/src/concat.js +20 -0
  21. package/bundle/node_modules/uint8arrays/dist/src/to-string.js +19 -0
  22. package/bundle/node_modules/uint8arrays/dist/src/util/as-uint8array.js +9 -0
  23. package/bundle/packages/core/dist/lib/connection_manager/connection_manager.js +1 -3
  24. package/bundle/packages/core/dist/lib/message/version_0.js +1 -4
  25. package/bundle/packages/proto/dist/generated/filter.js +2 -0
  26. package/bundle/packages/proto/dist/generated/filter_v2.js +2 -0
  27. package/bundle/packages/proto/dist/generated/light_push.js +2 -0
  28. package/bundle/packages/proto/dist/generated/message.js +2 -0
  29. package/bundle/packages/proto/dist/generated/metadata.js +2 -0
  30. package/bundle/packages/proto/dist/generated/peer_exchange.js +2 -0
  31. package/bundle/packages/proto/dist/generated/sds_message.js +2 -0
  32. package/bundle/packages/proto/dist/generated/store_v3.js +2 -0
  33. package/bundle/packages/proto/dist/generated/topic_only_message.js +2 -0
  34. package/bundle/packages/rln/dist/contract/rln_base_contract.js +2 -2
  35. package/bundle/packages/rln/dist/identity.js +1 -1
  36. package/bundle/packages/rln/dist/message.js +11 -0
  37. package/bundle/packages/rln/dist/utils/bytes.js +2 -6
  38. package/dist/.tsbuildinfo +1 -1
  39. package/dist/codec.test-utils.d.ts +1 -1
  40. package/dist/contract/rln_base_contract.d.ts +1 -1
  41. package/dist/contract/rln_base_contract.js +2 -2
  42. package/dist/contract/rln_base_contract.js.map +1 -1
  43. package/dist/contract/test-setup.d.ts +1 -1
  44. package/dist/identity.js +1 -1
  45. package/dist/identity.js.map +1 -1
  46. package/dist/keystore/credential_validation_generated.d.ts +0 -2
  47. package/dist/keystore/keystore_validation_generated.d.ts +0 -2
  48. package/dist/message.d.ts +5 -4
  49. package/dist/message.js +2 -0
  50. package/dist/message.js.map +1 -1
  51. package/dist/utils/bytes.js +2 -6
  52. package/dist/utils/bytes.js.map +1 -1
  53. package/package.json +1 -1
  54. package/src/contract/rln_base_contract.ts +2 -2
  55. package/src/identity.ts +1 -1
  56. package/src/message.ts +7 -4
  57. package/src/utils/bytes.ts +2 -6
  58. package/bundle/node_modules/@multiformats/multiaddr/dist/src/convert.js +0 -15
  59. package/bundle/node_modules/@multiformats/multiaddr/dist/src/multiaddr.js +0 -21
  60. package/bundle/node_modules/@multiformats/multiaddr/dist/src/protocols-table.js +0 -92
package/CHANGELOG.md CHANGED
@@ -1,5 +1,34 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.1.6](https://github.com/waku-org/js-waku/compare/rln-v0.1.5...rln-v0.1.6) (2025-06-23)
4
+
5
+
6
+ ### ⚠ BREAKING CHANGES
7
+
8
+ * upgrade libp2p, nodejs and typescript ([#2401](https://github.com/waku-org/js-waku/issues/2401))
9
+ * re-work messaging parts and sharding ([#2399](https://github.com/waku-org/js-waku/issues/2399))
10
+
11
+ ### Features
12
+
13
+ * Re-work messaging parts and sharding ([#2399](https://github.com/waku-org/js-waku/issues/2399)) ([1905558](https://github.com/waku-org/js-waku/commit/1905558753a7bf61c3dd27d6892d0f561d4c57c6))
14
+ * Refine work with membership info and other meta information ([#2341](https://github.com/waku-org/js-waku/issues/2341)) ([3b23bce](https://github.com/waku-org/js-waku/commit/3b23bceb9de5a0c250788ffb824367eabafe3728))
15
+
16
+
17
+ ### Miscellaneous Chores
18
+
19
+ * Upgrade libp2p, nodejs and typescript ([#2401](https://github.com/waku-org/js-waku/issues/2401)) ([fcc6496](https://github.com/waku-org/js-waku/commit/fcc6496fef914c56f6a4d2d17c494c8b94caea3c))
20
+
21
+
22
+ ### Dependencies
23
+
24
+ * The following workspace dependencies were updated
25
+ * dependencies
26
+ * @waku/core bumped from ^0.0.35 to ^0.0.36
27
+ * @waku/utils bumped from ^0.0.23 to ^0.0.24
28
+ * devDependencies
29
+ * @waku/interfaces bumped from 0.0.30 to 0.0.31
30
+ * @waku/message-encryption bumped from ^0.0.33 to ^0.0.34
31
+
3
32
  ## [0.1.5](https://github.com/waku-org/js-waku/compare/rln-v0.1.4...rln-v0.1.5) (2025-04-23)
4
33
 
5
34
 
@@ -0,0 +1,12 @@
1
+ import { parseIPv4, parseIPv6 } from './parse.js';
2
+
3
+ /** Check if `input` is IPv4. */
4
+ function isIPv4(input) {
5
+ return Boolean(parseIPv4(input));
6
+ }
7
+ /** Check if `input` is IPv6. */
8
+ function isIPv6(input) {
9
+ return Boolean(parseIPv6(input));
10
+ }
11
+
12
+ export { isIPv4, isIPv6 };
@@ -0,0 +1,26 @@
1
+ import { Parser } from './parser.js';
2
+
3
+ // See https://stackoverflow.com/questions/166132/maximum-length-of-the-textual-representation-of-an-ipv6-address
4
+ const MAX_IPV6_LENGTH = 45;
5
+ const MAX_IPV4_LENGTH = 15;
6
+ const parser = new Parser();
7
+ /** Parse `input` into IPv4 bytes. */
8
+ function parseIPv4(input) {
9
+ if (input.length > MAX_IPV4_LENGTH) {
10
+ return undefined;
11
+ }
12
+ return parser.new(input).parseWith(() => parser.readIPv4Addr());
13
+ }
14
+ /** Parse `input` into IPv6 bytes. */
15
+ function parseIPv6(input) {
16
+ // strip zone index if it is present
17
+ if (input.includes("%")) {
18
+ input = input.split("%")[0];
19
+ }
20
+ if (input.length > MAX_IPV6_LENGTH) {
21
+ return undefined;
22
+ }
23
+ return parser.new(input).parseWith(() => parser.readIPv6Addr());
24
+ }
25
+
26
+ export { parseIPv4, parseIPv6 };
@@ -0,0 +1,202 @@
1
+ /* eslint-disable @typescript-eslint/no-unsafe-return */
2
+ class Parser {
3
+ index = 0;
4
+ input = "";
5
+ new(input) {
6
+ this.index = 0;
7
+ this.input = input;
8
+ return this;
9
+ }
10
+ /** Run a parser, and restore the pre-parse state if it fails. */
11
+ readAtomically(fn) {
12
+ const index = this.index;
13
+ const result = fn();
14
+ if (result === undefined) {
15
+ this.index = index;
16
+ }
17
+ return result;
18
+ }
19
+ /** Run a parser, but fail if the entire input wasn't consumed. Doesn't run atomically. */
20
+ parseWith(fn) {
21
+ const result = fn();
22
+ if (this.index !== this.input.length) {
23
+ return undefined;
24
+ }
25
+ return result;
26
+ }
27
+ /** Peek the next character from the input */
28
+ peekChar() {
29
+ if (this.index >= this.input.length) {
30
+ return undefined;
31
+ }
32
+ return this.input[this.index];
33
+ }
34
+ /** Read the next character from the input */
35
+ readChar() {
36
+ if (this.index >= this.input.length) {
37
+ return undefined;
38
+ }
39
+ return this.input[this.index++];
40
+ }
41
+ /** Read the next character from the input if it matches the target. */
42
+ readGivenChar(target) {
43
+ return this.readAtomically(() => {
44
+ const char = this.readChar();
45
+ if (char !== target) {
46
+ return undefined;
47
+ }
48
+ return char;
49
+ });
50
+ }
51
+ /**
52
+ * Helper for reading separators in an indexed loop. Reads the separator
53
+ * character iff index > 0, then runs the parser. When used in a loop,
54
+ * the separator character will only be read on index > 0 (see
55
+ * readIPv4Addr for an example)
56
+ */
57
+ readSeparator(sep, index, inner) {
58
+ return this.readAtomically(() => {
59
+ if (index > 0) {
60
+ if (this.readGivenChar(sep) === undefined) {
61
+ return undefined;
62
+ }
63
+ }
64
+ return inner();
65
+ });
66
+ }
67
+ /**
68
+ * Read a number off the front of the input in the given radix, stopping
69
+ * at the first non-digit character or eof. Fails if the number has more
70
+ * digits than max_digits or if there is no number.
71
+ */
72
+ readNumber(radix, maxDigits, allowZeroPrefix, maxBytes) {
73
+ return this.readAtomically(() => {
74
+ let result = 0;
75
+ let digitCount = 0;
76
+ const leadingChar = this.peekChar();
77
+ if (leadingChar === undefined) {
78
+ return undefined;
79
+ }
80
+ const hasLeadingZero = leadingChar === "0";
81
+ const maxValue = 2 ** (8 * maxBytes) - 1;
82
+ // eslint-disable-next-line no-constant-condition
83
+ while (true) {
84
+ const digit = this.readAtomically(() => {
85
+ const char = this.readChar();
86
+ if (char === undefined) {
87
+ return undefined;
88
+ }
89
+ const num = Number.parseInt(char, radix);
90
+ if (Number.isNaN(num)) {
91
+ return undefined;
92
+ }
93
+ return num;
94
+ });
95
+ if (digit === undefined) {
96
+ break;
97
+ }
98
+ result *= radix;
99
+ result += digit;
100
+ if (result > maxValue) {
101
+ return undefined;
102
+ }
103
+ digitCount += 1;
104
+ if (maxDigits !== undefined) {
105
+ if (digitCount > maxDigits) {
106
+ return undefined;
107
+ }
108
+ }
109
+ }
110
+ if (digitCount === 0) {
111
+ return undefined;
112
+ }
113
+ else if (!allowZeroPrefix && hasLeadingZero && digitCount > 1) {
114
+ return undefined;
115
+ }
116
+ else {
117
+ return result;
118
+ }
119
+ });
120
+ }
121
+ /** Read an IPv4 address. */
122
+ readIPv4Addr() {
123
+ return this.readAtomically(() => {
124
+ const out = new Uint8Array(4);
125
+ for (let i = 0; i < out.length; i++) {
126
+ const ix = this.readSeparator(".", i, () => this.readNumber(10, 3, false, 1));
127
+ if (ix === undefined) {
128
+ return undefined;
129
+ }
130
+ out[i] = ix;
131
+ }
132
+ return out;
133
+ });
134
+ }
135
+ /** Read an IPv6 Address. */
136
+ readIPv6Addr() {
137
+ /**
138
+ * Read a chunk of an IPv6 address into `groups`. Returns the number
139
+ * of groups read, along with a bool indicating if an embedded
140
+ * trailing IPv4 address was read. Specifically, read a series of
141
+ * colon-separated IPv6 groups (0x0000 - 0xFFFF), with an optional
142
+ * trailing embedded IPv4 address.
143
+ */
144
+ const readGroups = (groups) => {
145
+ for (let i = 0; i < groups.length / 2; i++) {
146
+ const ix = i * 2;
147
+ // Try to read a trailing embedded IPv4 address. There must be at least 4 groups left.
148
+ if (i < groups.length - 3) {
149
+ const ipv4 = this.readSeparator(":", i, () => this.readIPv4Addr());
150
+ if (ipv4 !== undefined) {
151
+ groups[ix] = ipv4[0];
152
+ groups[ix + 1] = ipv4[1];
153
+ groups[ix + 2] = ipv4[2];
154
+ groups[ix + 3] = ipv4[3];
155
+ return [ix + 4, true];
156
+ }
157
+ }
158
+ const group = this.readSeparator(":", i, () => this.readNumber(16, 4, true, 2));
159
+ if (group === undefined) {
160
+ return [ix, false];
161
+ }
162
+ groups[ix] = group >> 8;
163
+ groups[ix + 1] = group & 255;
164
+ }
165
+ return [groups.length, false];
166
+ };
167
+ return this.readAtomically(() => {
168
+ // Read the front part of the address; either the whole thing, or up to the first ::
169
+ const head = new Uint8Array(16);
170
+ const [headSize, headIp4] = readGroups(head);
171
+ if (headSize === 16) {
172
+ return head;
173
+ }
174
+ // IPv4 part is not allowed before `::`
175
+ if (headIp4) {
176
+ return undefined;
177
+ }
178
+ // Read `::` if previous code parsed less than 8 groups.
179
+ // `::` indicates one or more groups of 16 bits of zeros.
180
+ if (this.readGivenChar(":") === undefined) {
181
+ return undefined;
182
+ }
183
+ if (this.readGivenChar(":") === undefined) {
184
+ return undefined;
185
+ }
186
+ // Read the back part of the address. The :: must contain at least one
187
+ // set of zeroes, so our max length is 7.
188
+ const tail = new Uint8Array(14);
189
+ const limit = 16 - (headSize + 2);
190
+ const [tailSize] = readGroups(tail.subarray(0, limit));
191
+ // Concat the head and tail of the IP address
192
+ head.set(tail.subarray(0, tailSize), 16 - tailSize);
193
+ return head;
194
+ });
195
+ }
196
+ /** Read an IP Address, either IPv4 or IPv6. */
197
+ readIPAddr() {
198
+ return this.readIPv4Addr() ?? this.readIPv6Addr();
199
+ }
200
+ }
201
+
202
+ export { Parser };
@@ -181,7 +181,7 @@ class BigNumber {
181
181
  if (value % 1) {
182
182
  throwFault("underflow", "BigNumber.from", value);
183
183
  }
184
- if (value >= MAX_SAFE || value <= -9007199254740991) {
184
+ if (value >= MAX_SAFE || value <= -MAX_SAFE) {
185
185
  throwFault("overflow", "BigNumber.from", value);
186
186
  }
187
187
  return BigNumber.from(String(value));
@@ -0,0 +1,43 @@
1
+ // the values here come from https://github.com/multiformats/multiaddr/blob/master/protocols.csv
2
+ const CODE_IP4 = 4;
3
+ const CODE_TCP = 6;
4
+ const CODE_UDP = 273;
5
+ const CODE_DCCP = 33;
6
+ const CODE_IP6 = 41;
7
+ const CODE_IP6ZONE = 42;
8
+ const CODE_IPCIDR = 43;
9
+ const CODE_DNS = 53;
10
+ const CODE_DNS4 = 54;
11
+ const CODE_DNS6 = 55;
12
+ const CODE_DNSADDR = 56;
13
+ const CODE_SCTP = 132;
14
+ const CODE_UDT = 301;
15
+ const CODE_UTP = 302;
16
+ const CODE_UNIX = 400;
17
+ const CODE_P2P = 421; // also IPFS
18
+ const CODE_ONION = 444;
19
+ const CODE_ONION3 = 445;
20
+ const CODE_GARLIC64 = 446;
21
+ const CODE_GARLIC32 = 447;
22
+ const CODE_TLS = 448;
23
+ const CODE_SNI = 449;
24
+ const CODE_NOISE = 454;
25
+ const CODE_QUIC = 460;
26
+ const CODE_QUIC_V1 = 461;
27
+ const CODE_WEBTRANSPORT = 465;
28
+ const CODE_CERTHASH = 466;
29
+ const CODE_HTTP = 480;
30
+ const CODE_HTTP_PATH = 481;
31
+ const CODE_HTTPS = 443;
32
+ const CODE_WS = 477;
33
+ const CODE_WSS = 478;
34
+ const CODE_P2P_WEBSOCKET_STAR = 479;
35
+ const CODE_P2P_STARDUST = 277;
36
+ const CODE_P2P_WEBRTC_STAR = 275;
37
+ const CODE_P2P_WEBRTC_DIRECT = 276;
38
+ const CODE_WEBRTC_DIRECT = 280;
39
+ const CODE_WEBRTC = 281;
40
+ const CODE_P2P_CIRCUIT = 290;
41
+ const CODE_MEMORY = 777;
42
+
43
+ export { CODE_CERTHASH, CODE_DCCP, CODE_DNS, CODE_DNS4, CODE_DNS6, CODE_DNSADDR, CODE_GARLIC32, CODE_GARLIC64, CODE_HTTP, CODE_HTTPS, CODE_HTTP_PATH, CODE_IP4, CODE_IP6, CODE_IP6ZONE, CODE_IPCIDR, CODE_MEMORY, CODE_NOISE, CODE_ONION, CODE_ONION3, CODE_P2P, CODE_P2P_CIRCUIT, CODE_P2P_STARDUST, CODE_P2P_WEBRTC_DIRECT, CODE_P2P_WEBRTC_STAR, CODE_P2P_WEBSOCKET_STAR, CODE_QUIC, CODE_QUIC_V1, CODE_SCTP, CODE_SNI, CODE_TCP, CODE_TLS, CODE_UDP, CODE_UDT, CODE_UNIX, CODE_UTP, CODE_WEBRTC, CODE_WEBRTC_DIRECT, CODE_WEBTRANSPORT, CODE_WS, CODE_WSS };
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Thrown when an invalid multiaddr is encountered
3
+ */
4
+ class InvalidMultiaddrError extends Error {
5
+ static name = 'InvalidMultiaddrError';
6
+ name = 'InvalidMultiaddrError';
7
+ }
8
+ class ValidationError extends Error {
9
+ static name = 'ValidationError';
10
+ name = 'ValidationError';
11
+ }
12
+ class UnknownProtocolError extends Error {
13
+ static name = 'UnknownProtocolError';
14
+ name = 'UnknownProtocolError';
15
+ }
16
+
17
+ export { InvalidMultiaddrError, UnknownProtocolError, ValidationError };
@@ -0,0 +1,245 @@
1
+ import { isIPv4, isIPv6 } from '../../../../@chainsafe/is-ip/lib/is-ip.js';
2
+ import { CID } from '../../../../multiformats/dist/src/cid.js';
3
+ import { base64url } from '../../../../multiformats/dist/src/bases/base64.js';
4
+ import { CODE_IP4, CODE_TCP, CODE_UDP, CODE_DCCP, CODE_IP6, CODE_IP6ZONE, CODE_IPCIDR, CODE_DNS, CODE_DNS4, CODE_DNS6, CODE_DNSADDR, CODE_SCTP, CODE_UDT, CODE_UTP, CODE_UNIX, CODE_P2P, CODE_ONION, CODE_ONION3, CODE_GARLIC64, CODE_GARLIC32, CODE_TLS, CODE_SNI, CODE_NOISE, CODE_QUIC, CODE_QUIC_V1, CODE_WEBTRANSPORT, CODE_CERTHASH, CODE_HTTP, CODE_HTTP_PATH, CODE_HTTPS, CODE_WS, CODE_WSS, CODE_P2P_WEBSOCKET_STAR, CODE_P2P_STARDUST, CODE_P2P_WEBRTC_STAR, CODE_P2P_WEBRTC_DIRECT, CODE_WEBRTC_DIRECT, CODE_WEBRTC, CODE_P2P_CIRCUIT, CODE_MEMORY } from './constants.js';
5
+ import { ValidationError, UnknownProtocolError } from './errors.js';
6
+ import { ip4ToString, ip4ToBytes, bytes2port, port2bytes, ip6StringToValue, ip6ToString, ip6ToBytes, stringToBytes, bytesToString, onion2bytes, bytes2onion, onion32bytes, mb2bytes, bytes2mb } from './utils.js';
7
+ import { validatePort } from './validation.js';
8
+
9
+ const V = -1;
10
+ class Registry {
11
+ protocolsByCode = new Map();
12
+ protocolsByName = new Map();
13
+ getProtocol(key) {
14
+ let codec;
15
+ if (typeof key === 'string') {
16
+ codec = this.protocolsByName.get(key);
17
+ }
18
+ else {
19
+ codec = this.protocolsByCode.get(key);
20
+ }
21
+ if (codec == null) {
22
+ throw new UnknownProtocolError(`Protocol ${key} was unknown`);
23
+ }
24
+ return codec;
25
+ }
26
+ addProtocol(codec) {
27
+ this.protocolsByCode.set(codec.code, codec);
28
+ this.protocolsByName.set(codec.name, codec);
29
+ codec.aliases?.forEach(alias => {
30
+ this.protocolsByName.set(alias, codec);
31
+ });
32
+ }
33
+ removeProtocol(code) {
34
+ const codec = this.protocolsByCode.get(code);
35
+ if (codec == null) {
36
+ return;
37
+ }
38
+ this.protocolsByCode.delete(codec.code);
39
+ this.protocolsByName.delete(codec.name);
40
+ codec.aliases?.forEach(alias => {
41
+ this.protocolsByName.delete(alias);
42
+ });
43
+ }
44
+ }
45
+ const registry = new Registry();
46
+ const codecs = [{
47
+ code: CODE_IP4,
48
+ name: 'ip4',
49
+ size: 32,
50
+ valueToBytes: ip4ToBytes,
51
+ bytesToValue: ip4ToString,
52
+ validate: (value) => {
53
+ if (!isIPv4(value)) {
54
+ throw new ValidationError(`Invalid IPv4 address "${value}"`);
55
+ }
56
+ }
57
+ }, {
58
+ code: CODE_TCP,
59
+ name: 'tcp',
60
+ size: 16,
61
+ valueToBytes: port2bytes,
62
+ bytesToValue: bytes2port,
63
+ validate: validatePort
64
+ }, {
65
+ code: CODE_UDP,
66
+ name: 'udp',
67
+ size: 16,
68
+ valueToBytes: port2bytes,
69
+ bytesToValue: bytes2port,
70
+ validate: validatePort
71
+ }, {
72
+ code: CODE_DCCP,
73
+ name: 'dccp',
74
+ size: 16,
75
+ valueToBytes: port2bytes,
76
+ bytesToValue: bytes2port,
77
+ validate: validatePort
78
+ }, {
79
+ code: CODE_IP6,
80
+ name: 'ip6',
81
+ size: 128,
82
+ valueToBytes: ip6ToBytes,
83
+ bytesToValue: ip6ToString,
84
+ stringToValue: ip6StringToValue,
85
+ validate: (value) => {
86
+ if (!isIPv6(value)) {
87
+ throw new ValidationError(`Invalid IPv6 address "${value}"`);
88
+ }
89
+ }
90
+ }, {
91
+ code: CODE_IP6ZONE,
92
+ name: 'ip6zone',
93
+ size: V
94
+ }, {
95
+ code: CODE_IPCIDR,
96
+ name: 'ipcidr',
97
+ size: 8,
98
+ bytesToValue: bytesToString('base10'),
99
+ valueToBytes: stringToBytes('base10')
100
+ }, {
101
+ code: CODE_DNS,
102
+ name: 'dns',
103
+ size: V,
104
+ resolvable: true
105
+ }, {
106
+ code: CODE_DNS4,
107
+ name: 'dns4',
108
+ size: V,
109
+ resolvable: true
110
+ }, {
111
+ code: CODE_DNS6,
112
+ name: 'dns6',
113
+ size: V,
114
+ resolvable: true
115
+ }, {
116
+ code: CODE_DNSADDR,
117
+ name: 'dnsaddr',
118
+ size: V,
119
+ resolvable: true
120
+ }, {
121
+ code: CODE_SCTP,
122
+ name: 'sctp',
123
+ size: 16,
124
+ valueToBytes: port2bytes,
125
+ bytesToValue: bytes2port,
126
+ validate: validatePort
127
+ }, {
128
+ code: CODE_UDT,
129
+ name: 'udt'
130
+ }, {
131
+ code: CODE_UTP,
132
+ name: 'utp'
133
+ }, {
134
+ code: CODE_UNIX,
135
+ name: 'unix',
136
+ size: V,
137
+ path: true,
138
+ stringToValue: (str) => decodeURIComponent(str),
139
+ valueToString: (val) => encodeURIComponent(val)
140
+ }, {
141
+ code: CODE_P2P,
142
+ name: 'p2p',
143
+ aliases: ['ipfs'],
144
+ size: V,
145
+ bytesToValue: bytesToString('base58btc'),
146
+ valueToBytes: (val) => {
147
+ if (val.startsWith('Q') || val.startsWith('1')) {
148
+ return stringToBytes('base58btc')(val);
149
+ }
150
+ return CID.parse(val).multihash.bytes;
151
+ }
152
+ }, {
153
+ code: CODE_ONION,
154
+ name: 'onion',
155
+ size: 96,
156
+ bytesToValue: bytes2onion,
157
+ valueToBytes: onion2bytes
158
+ }, {
159
+ code: CODE_ONION3,
160
+ name: 'onion3',
161
+ size: 296,
162
+ bytesToValue: bytes2onion,
163
+ valueToBytes: onion32bytes
164
+ }, {
165
+ code: CODE_GARLIC64,
166
+ name: 'garlic64',
167
+ size: V
168
+ }, {
169
+ code: CODE_GARLIC32,
170
+ name: 'garlic32',
171
+ size: V
172
+ }, {
173
+ code: CODE_TLS,
174
+ name: 'tls'
175
+ }, {
176
+ code: CODE_SNI,
177
+ name: 'sni',
178
+ size: V
179
+ }, {
180
+ code: CODE_NOISE,
181
+ name: 'noise'
182
+ }, {
183
+ code: CODE_QUIC,
184
+ name: 'quic'
185
+ }, {
186
+ code: CODE_QUIC_V1,
187
+ name: 'quic-v1'
188
+ }, {
189
+ code: CODE_WEBTRANSPORT,
190
+ name: 'webtransport'
191
+ }, {
192
+ code: CODE_CERTHASH,
193
+ name: 'certhash',
194
+ size: V,
195
+ bytesToValue: bytes2mb(base64url),
196
+ valueToBytes: mb2bytes
197
+ }, {
198
+ code: CODE_HTTP,
199
+ name: 'http'
200
+ }, {
201
+ code: CODE_HTTP_PATH,
202
+ name: 'http-path',
203
+ size: V,
204
+ stringToValue: (str) => `/${decodeURIComponent(str)}`,
205
+ valueToString: (val) => encodeURIComponent(val.substring(1))
206
+ }, {
207
+ code: CODE_HTTPS,
208
+ name: 'https'
209
+ }, {
210
+ code: CODE_WS,
211
+ name: 'ws'
212
+ }, {
213
+ code: CODE_WSS,
214
+ name: 'wss'
215
+ }, {
216
+ code: CODE_P2P_WEBSOCKET_STAR,
217
+ name: 'p2p-websocket-star'
218
+ }, {
219
+ code: CODE_P2P_STARDUST,
220
+ name: 'p2p-stardust'
221
+ }, {
222
+ code: CODE_P2P_WEBRTC_STAR,
223
+ name: 'p2p-webrtc-star'
224
+ }, {
225
+ code: CODE_P2P_WEBRTC_DIRECT,
226
+ name: 'p2p-webrtc-direct'
227
+ }, {
228
+ code: CODE_WEBRTC_DIRECT,
229
+ name: 'webrtc-direct'
230
+ }, {
231
+ code: CODE_WEBRTC,
232
+ name: 'webrtc'
233
+ }, {
234
+ code: CODE_P2P_CIRCUIT,
235
+ name: 'p2p-circuit'
236
+ }, {
237
+ code: CODE_MEMORY,
238
+ name: 'memory',
239
+ size: V
240
+ }];
241
+ codecs.forEach(codec => {
242
+ registry.addProtocol(codec);
243
+ });
244
+
245
+ export { V, registry };