@waku/rln 0.1.6-f911bf8.0 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -0
- package/bundle/_virtual/utils.js +2 -2
- package/bundle/_virtual/utils2.js +2 -2
- package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/@noble/hashes/_sha2.js +1 -1
- package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/@noble/hashes/hmac.js +1 -1
- package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/@noble/hashes/pbkdf2.js +1 -1
- package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/@noble/hashes/scrypt.js +1 -1
- package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/@noble/hashes/sha256.js +1 -1
- package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/@noble/hashes/sha512.js +1 -1
- package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/@noble/hashes/utils.js +1 -1
- package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/random.js +1 -1
- package/bundle/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/utils.js +2 -2
- package/bundle/node_modules/@chainsafe/is-ip/lib/is-ip.js +12 -0
- package/bundle/node_modules/@chainsafe/is-ip/lib/parse.js +26 -0
- package/bundle/node_modules/@chainsafe/is-ip/lib/parser.js +202 -0
- package/bundle/node_modules/@ethersproject/bignumber/lib.esm/bignumber.js +1 -1
- package/bundle/node_modules/@multiformats/multiaddr/dist/src/constants.js +43 -0
- package/bundle/node_modules/@multiformats/multiaddr/dist/src/errors.js +17 -0
- package/bundle/node_modules/@multiformats/multiaddr/dist/src/registry.js +245 -0
- package/bundle/node_modules/@multiformats/multiaddr/dist/src/utils.js +191 -0
- package/bundle/node_modules/@multiformats/multiaddr/dist/src/validation.js +30 -0
- package/bundle/node_modules/debug/src/browser.js +1 -1
- package/bundle/node_modules/debug/src/common.js +1 -1
- package/bundle/node_modules/lodash/lodash.js +5 -5
- package/bundle/node_modules/multiformats/dist/src/bases/base.js +12 -9
- package/bundle/node_modules/multiformats/dist/src/bytes.js +19 -3
- package/bundle/node_modules/multiformats/dist/src/cid.js +371 -0
- package/bundle/node_modules/multiformats/dist/src/hashes/digest.js +62 -0
- package/bundle/node_modules/multiformats/dist/src/varint.js +15 -0
- package/bundle/node_modules/multiformats/dist/src/vendor/varint.js +78 -0
- package/bundle/node_modules/uint8arrays/dist/src/concat.js +20 -0
- package/bundle/node_modules/uint8arrays/dist/src/to-string.js +19 -0
- package/bundle/node_modules/uint8arrays/dist/src/util/as-uint8array.js +9 -0
- package/bundle/packages/core/dist/lib/connection_manager/connection_manager.js +1 -3
- package/bundle/packages/core/dist/lib/message/version_0.js +1 -4
- package/bundle/packages/proto/dist/generated/filter.js +2 -0
- package/bundle/packages/proto/dist/generated/filter_v2.js +2 -0
- package/bundle/packages/proto/dist/generated/light_push.js +2 -0
- package/bundle/packages/proto/dist/generated/message.js +2 -0
- package/bundle/packages/proto/dist/generated/metadata.js +2 -0
- package/bundle/packages/proto/dist/generated/peer_exchange.js +2 -0
- package/bundle/packages/proto/dist/generated/sds_message.js +2 -0
- package/bundle/packages/proto/dist/generated/store_v3.js +2 -0
- package/bundle/packages/proto/dist/generated/topic_only_message.js +2 -0
- package/bundle/packages/rln/dist/contract/rln_base_contract.js +2 -2
- package/bundle/packages/rln/dist/identity.js +1 -1
- package/bundle/packages/rln/dist/message.js +11 -0
- package/bundle/packages/rln/dist/utils/bytes.js +2 -6
- package/dist/.tsbuildinfo +1 -1
- package/dist/codec.test-utils.d.ts +1 -1
- package/dist/contract/rln_base_contract.d.ts +1 -1
- package/dist/contract/rln_base_contract.js +2 -2
- package/dist/contract/rln_base_contract.js.map +1 -1
- package/dist/contract/test-setup.d.ts +1 -1
- package/dist/identity.js +1 -1
- package/dist/identity.js.map +1 -1
- package/dist/keystore/credential_validation_generated.d.ts +0 -2
- package/dist/keystore/keystore_validation_generated.d.ts +0 -2
- package/dist/message.d.ts +5 -4
- package/dist/message.js +2 -0
- package/dist/message.js.map +1 -1
- package/dist/utils/bytes.js +2 -6
- package/dist/utils/bytes.js.map +1 -1
- package/package.json +93 -1
- package/src/contract/rln_base_contract.ts +2 -2
- package/src/identity.ts +1 -1
- package/src/message.ts +7 -4
- package/src/utils/bytes.ts +2 -6
- package/bundle/node_modules/@multiformats/multiaddr/dist/src/convert.js +0 -15
- package/bundle/node_modules/@multiformats/multiaddr/dist/src/multiaddr.js +0 -21
- package/bundle/node_modules/@multiformats/multiaddr/dist/src/protocols-table.js +0 -92
@@ -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 };
|
@@ -0,0 +1,191 @@
|
|
1
|
+
import { isIPv4 } from '../../../../@chainsafe/is-ip/lib/is-ip.js';
|
2
|
+
import { base32 } from '../../../../multiformats/dist/src/bases/base32.js';
|
3
|
+
import { bases } from '../../../../multiformats/dist/src/basics.js';
|
4
|
+
import { concat } from '../../../../uint8arrays/dist/src/concat.js';
|
5
|
+
import { fromString } from '../../../../uint8arrays/dist/src/from-string.js';
|
6
|
+
import { toString } from '../../../../uint8arrays/dist/src/to-string.js';
|
7
|
+
import { InvalidMultiaddrError } from './errors.js';
|
8
|
+
|
9
|
+
function bytesToString(base) {
|
10
|
+
return (buf) => {
|
11
|
+
return toString(buf, base);
|
12
|
+
};
|
13
|
+
}
|
14
|
+
function stringToBytes(base) {
|
15
|
+
return (buf) => {
|
16
|
+
return fromString(buf, base);
|
17
|
+
};
|
18
|
+
}
|
19
|
+
function bytes2port(buf) {
|
20
|
+
const view = new DataView(buf.buffer);
|
21
|
+
return view.getUint16(buf.byteOffset).toString();
|
22
|
+
}
|
23
|
+
function port2bytes(port) {
|
24
|
+
const buf = new ArrayBuffer(2);
|
25
|
+
const view = new DataView(buf);
|
26
|
+
view.setUint16(0, typeof port === 'string' ? parseInt(port) : port);
|
27
|
+
return new Uint8Array(buf);
|
28
|
+
}
|
29
|
+
function onion2bytes(str) {
|
30
|
+
const addr = str.split(':');
|
31
|
+
if (addr.length !== 2) {
|
32
|
+
throw new Error(`failed to parse onion addr: ["'${addr.join('", "')}'"]' does not contain a port number`);
|
33
|
+
}
|
34
|
+
if (addr[0].length !== 16) {
|
35
|
+
throw new Error(`failed to parse onion addr: ${addr[0]} not a Tor onion address.`);
|
36
|
+
}
|
37
|
+
// onion addresses do not include the multibase prefix, add it before decoding
|
38
|
+
const buf = fromString(addr[0], 'base32');
|
39
|
+
// onion port number
|
40
|
+
const port = parseInt(addr[1], 10);
|
41
|
+
if (port < 1 || port > 65536) {
|
42
|
+
throw new Error('Port number is not in range(1, 65536)');
|
43
|
+
}
|
44
|
+
const portBuf = port2bytes(port);
|
45
|
+
return concat([buf, portBuf], buf.length + portBuf.length);
|
46
|
+
}
|
47
|
+
function onion32bytes(str) {
|
48
|
+
const addr = str.split(':');
|
49
|
+
if (addr.length !== 2) {
|
50
|
+
throw new Error(`failed to parse onion addr: ["'${addr.join('", "')}'"]' does not contain a port number`);
|
51
|
+
}
|
52
|
+
if (addr[0].length !== 56) {
|
53
|
+
throw new Error(`failed to parse onion addr: ${addr[0]} not a Tor onion3 address.`);
|
54
|
+
}
|
55
|
+
// onion addresses do not include the multibase prefix, add it before decoding
|
56
|
+
const buf = base32.decode(`b${addr[0]}`);
|
57
|
+
// onion port number
|
58
|
+
const port = parseInt(addr[1], 10);
|
59
|
+
if (port < 1 || port > 65536) {
|
60
|
+
throw new Error('Port number is not in range(1, 65536)');
|
61
|
+
}
|
62
|
+
const portBuf = port2bytes(port);
|
63
|
+
return concat([buf, portBuf], buf.length + portBuf.length);
|
64
|
+
}
|
65
|
+
function bytes2onion(buf) {
|
66
|
+
const addrBytes = buf.subarray(0, buf.length - 2);
|
67
|
+
const portBytes = buf.subarray(buf.length - 2);
|
68
|
+
const addr = toString(addrBytes, 'base32');
|
69
|
+
const port = bytes2port(portBytes);
|
70
|
+
return `${addr}:${port}`;
|
71
|
+
}
|
72
|
+
// Copied from https://github.com/indutny/node-ip/blob/master/lib/ip.js#L7
|
73
|
+
// but with buf/offset args removed because we don't use them
|
74
|
+
const ip4ToBytes = function (ip) {
|
75
|
+
ip = ip.toString().trim();
|
76
|
+
const bytes = new Uint8Array(4);
|
77
|
+
ip.split(/\./g).forEach((byte, index) => {
|
78
|
+
const value = parseInt(byte, 10);
|
79
|
+
if (isNaN(value) || value < 0 || value > 0xff) {
|
80
|
+
throw new InvalidMultiaddrError('Invalid byte value in IP address');
|
81
|
+
}
|
82
|
+
bytes[index] = value;
|
83
|
+
});
|
84
|
+
return bytes;
|
85
|
+
};
|
86
|
+
// Copied from https://github.com/indutny/node-ip/blob/master/lib/ip.js#L7
|
87
|
+
// but with buf/offset args removed because we don't use them
|
88
|
+
const ip6ToBytes = function (ip) {
|
89
|
+
let offset = 0;
|
90
|
+
ip = ip.toString().trim();
|
91
|
+
const sections = ip.split(':', 8);
|
92
|
+
let i;
|
93
|
+
for (i = 0; i < sections.length; i++) {
|
94
|
+
const isv4 = isIPv4(sections[i]);
|
95
|
+
let v4Buffer;
|
96
|
+
if (isv4) {
|
97
|
+
v4Buffer = ip4ToBytes(sections[i]);
|
98
|
+
sections[i] = toString(v4Buffer.subarray(0, 2), 'base16');
|
99
|
+
}
|
100
|
+
if (v4Buffer != null && ++i < 8) {
|
101
|
+
sections.splice(i, 0, toString(v4Buffer.subarray(2, 4), 'base16'));
|
102
|
+
}
|
103
|
+
}
|
104
|
+
if (sections[0] === '') {
|
105
|
+
while (sections.length < 8) {
|
106
|
+
sections.unshift('0');
|
107
|
+
}
|
108
|
+
}
|
109
|
+
else if (sections[sections.length - 1] === '') {
|
110
|
+
while (sections.length < 8) {
|
111
|
+
sections.push('0');
|
112
|
+
}
|
113
|
+
}
|
114
|
+
else if (sections.length < 8) {
|
115
|
+
for (i = 0; i < sections.length && sections[i] !== ''; i++) { }
|
116
|
+
const argv = [i, 1];
|
117
|
+
for (i = 9 - sections.length; i > 0; i--) {
|
118
|
+
argv.push('0');
|
119
|
+
}
|
120
|
+
sections.splice.apply(sections, argv);
|
121
|
+
}
|
122
|
+
const bytes = new Uint8Array(offset + 16);
|
123
|
+
for (i = 0; i < sections.length; i++) {
|
124
|
+
if (sections[i] === '') {
|
125
|
+
sections[i] = '0';
|
126
|
+
}
|
127
|
+
const word = parseInt(sections[i], 16);
|
128
|
+
if (isNaN(word) || word < 0 || word > 0xffff) {
|
129
|
+
throw new InvalidMultiaddrError('Invalid byte value in IP address');
|
130
|
+
}
|
131
|
+
bytes[offset++] = (word >> 8) & 0xff;
|
132
|
+
bytes[offset++] = word & 0xff;
|
133
|
+
}
|
134
|
+
return bytes;
|
135
|
+
};
|
136
|
+
// Copied from https://github.com/indutny/node-ip/blob/master/lib/ip.js#L63
|
137
|
+
const ip4ToString = function (buf) {
|
138
|
+
if (buf.byteLength !== 4) {
|
139
|
+
throw new InvalidMultiaddrError('IPv4 address was incorrect length');
|
140
|
+
}
|
141
|
+
const result = [];
|
142
|
+
for (let i = 0; i < buf.byteLength; i++) {
|
143
|
+
result.push(buf[i]);
|
144
|
+
}
|
145
|
+
return result.join('.');
|
146
|
+
};
|
147
|
+
const ip6ToString = function (buf) {
|
148
|
+
if (buf.byteLength !== 16) {
|
149
|
+
throw new InvalidMultiaddrError('IPv6 address was incorrect length');
|
150
|
+
}
|
151
|
+
const result = [];
|
152
|
+
for (let i = 0; i < buf.byteLength; i += 2) {
|
153
|
+
const byte1 = buf[i];
|
154
|
+
const byte2 = buf[i + 1];
|
155
|
+
const tuple = `${byte1.toString(16).padStart(2, '0')}${byte2.toString(16).padStart(2, '0')}`;
|
156
|
+
result.push(tuple);
|
157
|
+
}
|
158
|
+
const ip = result.join(':');
|
159
|
+
try {
|
160
|
+
const url = new URL(`http://[${ip}]`);
|
161
|
+
return url.hostname.substring(1, url.hostname.length - 1);
|
162
|
+
}
|
163
|
+
catch {
|
164
|
+
throw new InvalidMultiaddrError(`Invalid IPv6 address "${ip}"`);
|
165
|
+
}
|
166
|
+
};
|
167
|
+
function ip6StringToValue(str) {
|
168
|
+
try {
|
169
|
+
const url = new URL(`http://[${str}]`);
|
170
|
+
return url.hostname.substring(1, url.hostname.length - 1);
|
171
|
+
}
|
172
|
+
catch {
|
173
|
+
throw new InvalidMultiaddrError(`Invalid IPv6 address "${str}"`);
|
174
|
+
}
|
175
|
+
}
|
176
|
+
const decoders = Object.values(bases).map((c) => c.decoder);
|
177
|
+
const anybaseDecoder = (function () {
|
178
|
+
let acc = decoders[0].or(decoders[1]);
|
179
|
+
decoders.slice(2).forEach((d) => (acc = acc.or(d)));
|
180
|
+
return acc;
|
181
|
+
})();
|
182
|
+
function mb2bytes(mbstr) {
|
183
|
+
return anybaseDecoder.decode(mbstr);
|
184
|
+
}
|
185
|
+
function bytes2mb(base) {
|
186
|
+
return (buf) => {
|
187
|
+
return base.encoder.encode(buf);
|
188
|
+
};
|
189
|
+
}
|
190
|
+
|
191
|
+
export { bytes2mb, bytes2onion, bytes2port, bytesToString, ip4ToBytes, ip4ToString, ip6StringToValue, ip6ToBytes, ip6ToString, mb2bytes, onion2bytes, onion32bytes, port2bytes, stringToBytes };
|
@@ -0,0 +1,30 @@
|
|
1
|
+
import { ValidationError } from './errors.js';
|
2
|
+
|
3
|
+
function integer(value) {
|
4
|
+
const int = parseInt(value);
|
5
|
+
if (int.toString() !== value) {
|
6
|
+
throw new ValidationError('Value must be an integer');
|
7
|
+
}
|
8
|
+
}
|
9
|
+
function positive(value) {
|
10
|
+
if (value < 0) {
|
11
|
+
throw new ValidationError('Value must be a positive integer, or zero');
|
12
|
+
}
|
13
|
+
}
|
14
|
+
function maxValue(max) {
|
15
|
+
return (value) => {
|
16
|
+
if (value > max) {
|
17
|
+
throw new ValidationError(`Value must be smaller than or equal to ${max}`);
|
18
|
+
}
|
19
|
+
};
|
20
|
+
}
|
21
|
+
function validate(...funcs) {
|
22
|
+
return (value) => {
|
23
|
+
for (const fn of funcs) {
|
24
|
+
fn(value);
|
25
|
+
}
|
26
|
+
};
|
27
|
+
}
|
28
|
+
const validatePort = validate(integer, positive, maxValue(65_535));
|
29
|
+
|
30
|
+
export { integer, maxValue, positive, validate, validatePort };
|
@@ -224,7 +224,7 @@ import { c as common } from './common.js';
|
|
224
224
|
function load() {
|
225
225
|
let r;
|
226
226
|
try {
|
227
|
-
r = exports.storage.getItem('debug');
|
227
|
+
r = exports.storage.getItem('debug') || exports.storage.getItem('DEBUG') ;
|
228
228
|
} catch (error) {
|
229
229
|
// Swallow
|
230
230
|
// XXX (@Qix-) should we be logging these?
|
@@ -4302,7 +4302,7 @@ lodash.exports;
|
|
4302
4302
|
return symbolToString ? symbolToString.call(value) : '';
|
4303
4303
|
}
|
4304
4304
|
var result = (value + '');
|
4305
|
-
return (result == '0' && (1 / value) == -
|
4305
|
+
return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
|
4306
4306
|
}
|
4307
4307
|
|
4308
4308
|
/**
|
@@ -6825,7 +6825,7 @@ lodash.exports;
|
|
6825
6825
|
return value;
|
6826
6826
|
}
|
6827
6827
|
var result = (value + '');
|
6828
|
-
return (result == '0' && (1 / value) == -
|
6828
|
+
return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
|
6829
6829
|
}
|
6830
6830
|
|
6831
6831
|
/**
|
@@ -12167,7 +12167,7 @@ lodash.exports;
|
|
12167
12167
|
* // => false
|
12168
12168
|
*/
|
12169
12169
|
function isSafeInteger(value) {
|
12170
|
-
return isInteger(value) && value >= -
|
12170
|
+
return isInteger(value) && value >= -MAX_SAFE_INTEGER && value <= MAX_SAFE_INTEGER;
|
12171
12171
|
}
|
12172
12172
|
|
12173
12173
|
/**
|
@@ -12434,7 +12434,7 @@ lodash.exports;
|
|
12434
12434
|
return value === 0 ? value : 0;
|
12435
12435
|
}
|
12436
12436
|
value = toNumber(value);
|
12437
|
-
if (value === INFINITY || value === -
|
12437
|
+
if (value === INFINITY || value === -INFINITY) {
|
12438
12438
|
var sign = (value < 0 ? -1 : 1);
|
12439
12439
|
return sign * MAX_INTEGER;
|
12440
12440
|
}
|
@@ -12603,7 +12603,7 @@ lodash.exports;
|
|
12603
12603
|
*/
|
12604
12604
|
function toSafeInteger(value) {
|
12605
12605
|
return value
|
12606
|
-
? baseClamp(toInteger(value), -
|
12606
|
+
? baseClamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER)
|
12607
12607
|
: (value === 0 ? value : 0);
|
12608
12608
|
}
|
12609
12609
|
|
@@ -80,7 +80,6 @@ class ComposedDecoder {
|
|
80
80
|
}
|
81
81
|
}
|
82
82
|
function or(left, right) {
|
83
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
84
83
|
return new ComposedDecoder({
|
85
84
|
...(left.decoders ?? { [left.prefix]: left }),
|
86
85
|
...(right.decoders ?? { [right.prefix]: right })
|
@@ -120,12 +119,7 @@ function baseX({ name, prefix, alphabet }) {
|
|
120
119
|
decode: (text) => coerce(decode(text))
|
121
120
|
});
|
122
121
|
}
|
123
|
-
function decode(string,
|
124
|
-
// Build the character lookup table:
|
125
|
-
const codes = {};
|
126
|
-
for (let i = 0; i < alphabet.length; ++i) {
|
127
|
-
codes[alphabet[i]] = i;
|
128
|
-
}
|
122
|
+
function decode(string, alphabetIdx, bitsPerChar, name) {
|
129
123
|
// Count the padding bytes:
|
130
124
|
let end = string.length;
|
131
125
|
while (string[end - 1] === '=') {
|
@@ -139,7 +133,7 @@ function decode(string, alphabet, bitsPerChar, name) {
|
|
139
133
|
let written = 0; // Next byte to write
|
140
134
|
for (let i = 0; i < end; ++i) {
|
141
135
|
// Read one character from the string:
|
142
|
-
const value =
|
136
|
+
const value = alphabetIdx[string[i]];
|
143
137
|
if (value === undefined) {
|
144
138
|
throw new SyntaxError(`Non-${name} character`);
|
145
139
|
}
|
@@ -186,10 +180,19 @@ function encode(data, alphabet, bitsPerChar) {
|
|
186
180
|
}
|
187
181
|
return out;
|
188
182
|
}
|
183
|
+
function createAlphabetIdx(alphabet) {
|
184
|
+
// Build the character lookup table:
|
185
|
+
const alphabetIdx = {};
|
186
|
+
for (let i = 0; i < alphabet.length; ++i) {
|
187
|
+
alphabetIdx[alphabet[i]] = i;
|
188
|
+
}
|
189
|
+
return alphabetIdx;
|
190
|
+
}
|
189
191
|
/**
|
190
192
|
* RFC4648 Factory
|
191
193
|
*/
|
192
194
|
function rfc4648({ name, prefix, bitsPerChar, alphabet }) {
|
195
|
+
const alphabetIdx = createAlphabetIdx(alphabet);
|
193
196
|
return from({
|
194
197
|
prefix,
|
195
198
|
name,
|
@@ -197,7 +200,7 @@ function rfc4648({ name, prefix, bitsPerChar, alphabet }) {
|
|
197
200
|
return encode(input, alphabet, bitsPerChar);
|
198
201
|
},
|
199
202
|
decode(input) {
|
200
|
-
return decode(input,
|
203
|
+
return decode(input, alphabetIdx, bitsPerChar, name);
|
201
204
|
}
|
202
205
|
});
|
203
206
|
}
|
@@ -1,8 +1,24 @@
|
|
1
|
+
function equals(aa, bb) {
|
2
|
+
if (aa === bb) {
|
3
|
+
return true;
|
4
|
+
}
|
5
|
+
if (aa.byteLength !== bb.byteLength) {
|
6
|
+
return false;
|
7
|
+
}
|
8
|
+
for (let ii = 0; ii < aa.byteLength; ii++) {
|
9
|
+
if (aa[ii] !== bb[ii]) {
|
10
|
+
return false;
|
11
|
+
}
|
12
|
+
}
|
13
|
+
return true;
|
14
|
+
}
|
1
15
|
function coerce(o) {
|
2
|
-
if (o instanceof Uint8Array && o.constructor.name === 'Uint8Array')
|
16
|
+
if (o instanceof Uint8Array && o.constructor.name === 'Uint8Array') {
|
3
17
|
return o;
|
4
|
-
|
18
|
+
}
|
19
|
+
if (o instanceof ArrayBuffer) {
|
5
20
|
return new Uint8Array(o);
|
21
|
+
}
|
6
22
|
if (ArrayBuffer.isView(o)) {
|
7
23
|
return new Uint8Array(o.buffer, o.byteOffset, o.byteLength);
|
8
24
|
}
|
@@ -15,4 +31,4 @@ function toString(b) {
|
|
15
31
|
return new TextDecoder().decode(b);
|
16
32
|
}
|
17
33
|
|
18
|
-
export { coerce, fromString, toString };
|
34
|
+
export { coerce, equals, fromString, toString };
|