mirror of
https://github.com/pezkuwichain/phishing.git
synced 2026-06-17 21:41:05 +00:00
feat: add tldts dependency for improved hostname parsing (#5128)
This commit is contained in:
@@ -24,6 +24,7 @@
|
|||||||
"@polkadot/util": "^13.5.1",
|
"@polkadot/util": "^13.5.1",
|
||||||
"@polkadot/util-crypto": "^13.5.1",
|
"@polkadot/util-crypto": "^13.5.1",
|
||||||
"@polkadot/x-fetch": "^13.5.1",
|
"@polkadot/x-fetch": "^13.5.1",
|
||||||
|
"tldts": "^7.0.8",
|
||||||
"tslib": "^2.8.1"
|
"tslib": "^2.8.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
import type { AddressList, HostList } from './types.js';
|
import type { AddressList, HostList } from './types.js';
|
||||||
|
|
||||||
|
import { parse } from 'tldts';
|
||||||
|
|
||||||
import { u8aEq } from '@polkadot/util';
|
import { u8aEq } from '@polkadot/util';
|
||||||
import { decodeAddress } from '@polkadot/util-crypto';
|
import { decodeAddress } from '@polkadot/util-crypto';
|
||||||
|
|
||||||
@@ -37,21 +39,26 @@ const cacheAddr: CacheAddrList = {
|
|||||||
const cacheHost: Record<string, CacheHostList> = {};
|
const cacheHost: Record<string, CacheHostList> = {};
|
||||||
|
|
||||||
function splitHostParts (host: string): string[] {
|
function splitHostParts (host: string): string[] {
|
||||||
return host
|
const parsed = parse(host, { allowPrivateDomains: true });
|
||||||
// split domain
|
|
||||||
|
if (!parsed.hostname) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return parsed.hostname
|
||||||
|
.replace(/\.$/, '') // remove trailing dot
|
||||||
.split('.')
|
.split('.')
|
||||||
// reverse order
|
|
||||||
.reverse();
|
.reverse();
|
||||||
}
|
}
|
||||||
|
|
||||||
function extractHostParts (host: string): string[] {
|
function extractHostParts (host: string): string[] {
|
||||||
return splitHostParts(
|
const parsed = parse(host, { allowPrivateDomains: true });
|
||||||
host
|
|
||||||
// remove protocol
|
if (!parsed.hostname) {
|
||||||
.replace(/https:\/\/|http:\/\/|wss:\/\/|ws:\/\//, '')
|
return [];
|
||||||
// get the domain-only part
|
}
|
||||||
.split('/')[0]
|
|
||||||
);
|
return splitHostParts(parsed.hostname);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function retrieveAddrCache (allowCached = true): Promise<CacheAddrList> {
|
async function retrieveAddrCache (allowCached = true): Promise<CacheAddrList> {
|
||||||
|
|||||||
@@ -508,6 +508,7 @@ __metadata:
|
|||||||
"@polkadot/x-fetch": "npm:^13.5.1"
|
"@polkadot/x-fetch": "npm:^13.5.1"
|
||||||
"@types/js-yaml": "npm:^4.0.9"
|
"@types/js-yaml": "npm:^4.0.9"
|
||||||
js-yaml: "npm:^4.1.0"
|
js-yaml: "npm:^4.1.0"
|
||||||
|
tldts: "npm:^7.0.8"
|
||||||
tslib: "npm:^2.8.1"
|
tslib: "npm:^2.8.1"
|
||||||
languageName: unknown
|
languageName: unknown
|
||||||
linkType: soft
|
linkType: soft
|
||||||
@@ -8985,6 +8986,24 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
"tldts-core@npm:^7.0.8":
|
||||||
|
version: 7.0.8
|
||||||
|
resolution: "tldts-core@npm:7.0.8"
|
||||||
|
checksum: 10/a43d1a485ef460fd897bcfc618c4bc57e33f59a97526a08cffa8d8e3447abee82c9ec3bc652c2aebd8faf4a4f10cabd63211f9e955af4fca20258b2dba42bae9
|
||||||
|
languageName: node
|
||||||
|
linkType: hard
|
||||||
|
|
||||||
|
"tldts@npm:^7.0.8":
|
||||||
|
version: 7.0.8
|
||||||
|
resolution: "tldts@npm:7.0.8"
|
||||||
|
dependencies:
|
||||||
|
tldts-core: "npm:^7.0.8"
|
||||||
|
bin:
|
||||||
|
tldts: bin/cli.js
|
||||||
|
checksum: 10/b3cf1c0d78c982e99618eccacd628e5af1b4ef3700d6fb182eba78eda5dbb944fb4a154be220cc60342ab2c52de52876ef632df00e8cb2d1ceef01c833ef9e7c
|
||||||
|
languageName: node
|
||||||
|
linkType: hard
|
||||||
|
|
||||||
"tmp@npm:^0.0.33":
|
"tmp@npm:^0.0.33":
|
||||||
version: 0.0.33
|
version: 0.0.33
|
||||||
resolution: "tmp@npm:0.0.33"
|
resolution: "tmp@npm:0.0.33"
|
||||||
|
|||||||
Reference in New Issue
Block a user