Skip to content

Commit

Permalink
Tor v3 support
Browse files Browse the repository at this point in the history
  • Loading branch information
Duddino committed Jul 7, 2023
1 parent 9f0cc81 commit 79f5da8
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions scripts/masternode.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,19 @@ export default class Masternode {
*/
let bytes;
if (ip.endsWith('.onion')) {
bytes = [
0xfd,
0x87,
0xd8,
0x7e,
0xeb,
0x43,
...base32
.decode(ip.slice(0, -6))
.split('')
.map((c) => c.charCodeAt(0)),
];
console.log(bytes);
if (bytes.length !== 16) {
throw new Error('Invalid tor address');
const onionBytes = base32
.decode(ip.slice(0, -6))
.split('')
.map((c) => c.charCodeAt(0));
switch (onionBytes.length) {
case 10:
bytes = [0xfd, 0x87, 0xd8, 0x7e, 0xeb, 0x43, ...onionBytes];
break;
case 35:
bytes = [0x04, 32, ...onionBytes.slice(0, 32)];
break;
default:
throw new Error('Invalid onion address');
}
} else {
const address = ip.includes('.')
Expand All @@ -108,8 +106,10 @@ export default class Masternode {
bytes = address.toUnsignedByteArray();
}
const res =
bytesToHex([...new Array(16 - bytes.length).fill(0), ...bytes]) +
bytesToHex(Masternode._numToBytes(port, 2, false));
bytesToHex([
...new Array(Math.max(16 - bytes.length, 0)).fill(0),
...bytes,
]) + bytesToHex(Masternode._numToBytes(port, 2, false));
return res;
}

Expand Down

0 comments on commit 79f5da8

Please sign in to comment.