@metamask-previews/phishing-controller 13.1.0-preview-5a701133 → 14.0.0-preview-c20b7569
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 +14 -1
- package/dist/CacheManager.cjs +177 -0
- package/dist/CacheManager.cjs.map +1 -0
- package/dist/CacheManager.d.cts +104 -0
- package/dist/CacheManager.d.cts.map +1 -0
- package/dist/CacheManager.d.mts +104 -0
- package/dist/CacheManager.d.mts.map +1 -0
- package/dist/CacheManager.mjs +173 -0
- package/dist/CacheManager.mjs.map +1 -0
- package/dist/PhishingController.cjs +186 -8
- package/dist/PhishingController.cjs.map +1 -1
- package/dist/PhishingController.d.cts +41 -6
- package/dist/PhishingController.d.cts.map +1 -1
- package/dist/PhishingController.d.mts +41 -6
- package/dist/PhishingController.d.mts.map +1 -1
- package/dist/PhishingController.mjs +186 -8
- package/dist/PhishingController.mjs.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/tests/utils.cjs +79 -1
- package/dist/tests/utils.cjs.map +1 -1
- package/dist/tests/utils.d.cts +59 -0
- package/dist/tests/utils.d.cts.map +1 -1
- package/dist/tests/utils.d.mts +59 -0
- package/dist/tests/utils.d.mts.map +1 -1
- package/dist/tests/utils.mjs +75 -0
- package/dist/tests/utils.mjs.map +1 -1
- package/dist/types.cjs +35 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +68 -0
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +68 -0
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs +34 -0
- package/dist/types.mjs.map +1 -1
- package/dist/utils.cjs +54 -1
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +55 -0
- package/dist/utils.d.cts.map +1 -1
- package/dist/utils.d.mts +55 -0
- package/dist/utils.d.mts.map +1 -1
- package/dist/utils.mjs +50 -0
- package/dist/utils.mjs.map +1 -1
- package/package.json +5 -1
- package/dist/UrlScanCache.cjs +0 -127
- package/dist/UrlScanCache.cjs.map +0 -1
- package/dist/UrlScanCache.d.cts +0 -67
- package/dist/UrlScanCache.d.cts.map +0 -1
- package/dist/UrlScanCache.d.mts +0 -67
- package/dist/UrlScanCache.d.mts.map +0 -1
- package/dist/UrlScanCache.mjs +0 -123
- package/dist/UrlScanCache.mjs.map +0 -1
package/dist/tests/utils.mjs
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
import { TransactionStatus, TransactionType, SimulationTokenStandard } from "@metamask/transaction-controller";
|
1
2
|
/**
|
2
3
|
* Formats a hostname into a URL so we can parse it correctly
|
3
4
|
* and pass full URLs into the PhishingDetector class. Previously
|
@@ -17,4 +18,78 @@ export const formatHostnameToUrl = (hostname) => {
|
|
17
18
|
}
|
18
19
|
return url;
|
19
20
|
};
|
21
|
+
/**
|
22
|
+
* Test addresses for consistent use in tests
|
23
|
+
*/
|
24
|
+
export const TEST_ADDRESSES = {
|
25
|
+
MOCK_TOKEN_1: '0x1234567890123456789012345678901234567890',
|
26
|
+
USDC: '0xA0B86991c6218B36C1D19D4A2E9EB0CE3606EB48',
|
27
|
+
FROM_ADDRESS: '0x0987654321098765432109876543210987654321',
|
28
|
+
TO_ADDRESS: '0x1234567890123456789012345678901234567890',
|
29
|
+
};
|
30
|
+
/**
|
31
|
+
* Creates a mock token balance change object
|
32
|
+
*
|
33
|
+
* @param address - The address of the token
|
34
|
+
* @param options - The options for the token balance change
|
35
|
+
* @param options.difference - The difference in the token balance
|
36
|
+
* @param options.previousBalance - The previous balance of the token
|
37
|
+
* @param options.newBalance - The new balance of the token
|
38
|
+
* @param options.isDecrease - Whether the token balance is decreasing
|
39
|
+
* @param options.standard - The standard of the token
|
40
|
+
* @returns The mock token balance change object
|
41
|
+
*/
|
42
|
+
export const createMockTokenBalanceChange = (address, options = {}) => ({
|
43
|
+
address,
|
44
|
+
standard: options.standard ?? SimulationTokenStandard.erc20,
|
45
|
+
difference: options.difference ?? '0xde0b6b3a7640000',
|
46
|
+
previousBalance: options.previousBalance ?? '0x0',
|
47
|
+
newBalance: options.newBalance ?? '0xde0b6b3a7640000',
|
48
|
+
isDecrease: options.isDecrease ?? false,
|
49
|
+
});
|
50
|
+
/**
|
51
|
+
* Creates a mock transaction with token balance changes
|
52
|
+
*
|
53
|
+
* @param id - The transaction ID
|
54
|
+
* @param tokenAddresses - Array of token addresses to include in balance changes
|
55
|
+
* @param overrides - Partial transaction metadata to override defaults
|
56
|
+
* @returns The mock transaction metadata object
|
57
|
+
*/
|
58
|
+
export const createMockTransaction = (id, tokenAddresses = [], overrides = {}) => {
|
59
|
+
const simulationData = tokenAddresses.length > 0
|
60
|
+
? {
|
61
|
+
tokenBalanceChanges: tokenAddresses.map((address) => createMockTokenBalanceChange(address)),
|
62
|
+
}
|
63
|
+
: overrides.simulationData;
|
64
|
+
return {
|
65
|
+
txParams: {
|
66
|
+
from: TEST_ADDRESSES.FROM_ADDRESS,
|
67
|
+
to: TEST_ADDRESSES.TO_ADDRESS,
|
68
|
+
value: '0x0',
|
69
|
+
},
|
70
|
+
chainId: '0x1',
|
71
|
+
id,
|
72
|
+
networkClientId: 'mainnet',
|
73
|
+
status: TransactionStatus.unapproved,
|
74
|
+
time: Date.now(),
|
75
|
+
type: TransactionType.contractInteraction,
|
76
|
+
origin: 'https://metamask.io',
|
77
|
+
submittedTime: Date.now(),
|
78
|
+
simulationData,
|
79
|
+
...overrides,
|
80
|
+
};
|
81
|
+
};
|
82
|
+
/**
|
83
|
+
* Creates a mock state change payload for TransactionController
|
84
|
+
*
|
85
|
+
* @param transactions - The transactions to include in the state change payload.
|
86
|
+
* @returns A mock state change payload.
|
87
|
+
*/
|
88
|
+
export const createMockStateChangePayload = (transactions) => ({
|
89
|
+
transactions,
|
90
|
+
transactionBatches: [],
|
91
|
+
methodData: {},
|
92
|
+
lastFetchedBlockNumbers: {},
|
93
|
+
submitHistory: [],
|
94
|
+
});
|
20
95
|
//# sourceMappingURL=utils.mjs.map
|
package/dist/tests/utils.mjs.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../../src/tests/utils.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../../src/tests/utils.ts"],"names":[],"mappings":"AACA,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,uBAAuB,EACxB,yCAAyC;AAE1C;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,QAAgB,EAAU,EAAE;IAC9D,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,IAAI;QACF,GAAG,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC;KAC9B;IAAC,OAAO,CAAC,EAAE;QACV,GAAG,GAAG,IAAI,GAAG,CAAC,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;KACrD;IACD,OAAO,GAAG,CAAC;AACb,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,YAAY,EAAE,4CAA6D;IAC3E,IAAI,EAAE,4CAA6D;IACnE,YAAY,EAAE,4CAA6D;IAC3E,UAAU,EAAE,4CAA6D;CAC1E,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAC1C,OAAsB,EACtB,UAMI,EAAE,EACN,EAAE,CAAC,CAAC;IACJ,OAAO;IACP,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,uBAAuB,CAAC,KAAK;IAC3D,UAAU,EAAE,OAAO,CAAC,UAAU,IAAK,mBAAqC;IACxE,eAAe,EAAE,OAAO,CAAC,eAAe,IAAK,KAAuB;IACpE,UAAU,EAAE,OAAO,CAAC,UAAU,IAAK,mBAAqC;IACxE,UAAU,EAAE,OAAO,CAAC,UAAU,IAAI,KAAK;CACxC,CAAC,CAAC;AAEH;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,EAAU,EACV,iBAAkC,EAAE,EACpC,YAAsC,EAAE,EACvB,EAAE;IACnB,MAAM,cAAc,GAClB,cAAc,CAAC,MAAM,GAAG,CAAC;QACvB,CAAC,CAAC;YACE,mBAAmB,EAAE,cAAc,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAClD,4BAA4B,CAAC,OAAO,CAAC,CACtC;SACF;QACH,CAAC,CAAC,SAAS,CAAC,cAAc,CAAC;IAE/B,OAAO;QACL,QAAQ,EAAE;YACR,IAAI,EAAE,cAAc,CAAC,YAAY;YACjC,EAAE,EAAE,cAAc,CAAC,UAAU;YAC7B,KAAK,EAAE,KAAsB;SAC9B;QACD,OAAO,EAAE,KAAsB;QAC/B,EAAE;QACF,eAAe,EAAE,SAAS;QAC1B,MAAM,EAAE,iBAAiB,CAAC,UAAU;QACpC,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE;QAChB,IAAI,EAAE,eAAe,CAAC,mBAAmB;QACzC,MAAM,EAAE,qBAAqB;QAC7B,aAAa,EAAE,IAAI,CAAC,GAAG,EAAE;QACzB,cAAc;QACd,GAAG,SAAS;KACb,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAC1C,YAA+B,EAC/B,EAAE,CAAC,CAAC;IACJ,YAAY;IACZ,kBAAkB,EAAE,EAAE;IACtB,UAAU,EAAE,EAAE;IACd,uBAAuB,EAAE,EAAE;IAC3B,aAAa,EAAE,EAAE;CAClB,CAAC,CAAC","sourcesContent":["import type { TransactionMeta } from '@metamask/transaction-controller';\nimport {\n TransactionStatus,\n TransactionType,\n SimulationTokenStandard,\n} from '@metamask/transaction-controller';\n\n/**\n * Formats a hostname into a URL so we can parse it correctly\n * and pass full URLs into the PhishingDetector class. Previously\n * only hostnames were supported, but now only full URLs are\n * supported since we want to block IPFS CIDs.\n *\n * @param hostname - the hostname of the URL.\n * @returns the href property of a URL object.\n */\nexport const formatHostnameToUrl = (hostname: string): string => {\n let url = '';\n try {\n url = new URL(hostname).href;\n } catch (e) {\n url = new URL(['https://', hostname].join('')).href;\n }\n return url;\n};\n\n/**\n * Test addresses for consistent use in tests\n */\nexport const TEST_ADDRESSES = {\n MOCK_TOKEN_1: '0x1234567890123456789012345678901234567890' as `0x${string}`,\n USDC: '0xA0B86991c6218B36C1D19D4A2E9EB0CE3606EB48' as `0x${string}`,\n FROM_ADDRESS: '0x0987654321098765432109876543210987654321' as `0x${string}`,\n TO_ADDRESS: '0x1234567890123456789012345678901234567890' as `0x${string}`,\n};\n\n/**\n * Creates a mock token balance change object\n *\n * @param address - The address of the token\n * @param options - The options for the token balance change\n * @param options.difference - The difference in the token balance\n * @param options.previousBalance - The previous balance of the token\n * @param options.newBalance - The new balance of the token\n * @param options.isDecrease - Whether the token balance is decreasing\n * @param options.standard - The standard of the token\n * @returns The mock token balance change object\n */\nexport const createMockTokenBalanceChange = (\n address: `0x${string}`,\n options: {\n difference?: `0x${string}`;\n previousBalance?: `0x${string}`;\n newBalance?: `0x${string}`;\n isDecrease?: boolean;\n standard?: SimulationTokenStandard;\n } = {},\n) => ({\n address,\n standard: options.standard ?? SimulationTokenStandard.erc20,\n difference: options.difference ?? ('0xde0b6b3a7640000' as `0x${string}`),\n previousBalance: options.previousBalance ?? ('0x0' as `0x${string}`),\n newBalance: options.newBalance ?? ('0xde0b6b3a7640000' as `0x${string}`),\n isDecrease: options.isDecrease ?? false,\n});\n\n/**\n * Creates a mock transaction with token balance changes\n *\n * @param id - The transaction ID\n * @param tokenAddresses - Array of token addresses to include in balance changes\n * @param overrides - Partial transaction metadata to override defaults\n * @returns The mock transaction metadata object\n */\nexport const createMockTransaction = (\n id: string,\n tokenAddresses: `0x${string}`[] = [],\n overrides: Partial<TransactionMeta> = {},\n): TransactionMeta => {\n const simulationData =\n tokenAddresses.length > 0\n ? {\n tokenBalanceChanges: tokenAddresses.map((address) =>\n createMockTokenBalanceChange(address),\n ),\n }\n : overrides.simulationData;\n\n return {\n txParams: {\n from: TEST_ADDRESSES.FROM_ADDRESS,\n to: TEST_ADDRESSES.TO_ADDRESS,\n value: '0x0' as `0x${string}`,\n },\n chainId: '0x1' as `0x${string}`,\n id,\n networkClientId: 'mainnet',\n status: TransactionStatus.unapproved,\n time: Date.now(),\n type: TransactionType.contractInteraction,\n origin: 'https://metamask.io',\n submittedTime: Date.now(),\n simulationData,\n ...overrides,\n };\n};\n\n/**\n * Creates a mock state change payload for TransactionController\n *\n * @param transactions - The transactions to include in the state change payload.\n * @returns A mock state change payload.\n */\nexport const createMockStateChangePayload = (\n transactions: TransactionMeta[],\n) => ({\n transactions,\n transactionBatches: [],\n methodData: {},\n lastFetchedBlockNumbers: {},\n submitHistory: [],\n});\n"]}
|
package/dist/types.cjs
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.RecommendedAction = exports.PhishingDetectorResultType = void 0;
|
3
|
+
exports.DEFAULT_CHAIN_ID_TO_NAME = exports.TokenScanResultType = exports.RecommendedAction = exports.PhishingDetectorResultType = void 0;
|
4
4
|
/**
|
5
5
|
* The type of list in which the domain was found.
|
6
6
|
*/
|
@@ -60,4 +60,38 @@ var RecommendedAction;
|
|
60
60
|
*/
|
61
61
|
RecommendedAction["Verified"] = "VERIFIED";
|
62
62
|
})(RecommendedAction || (exports.RecommendedAction = RecommendedAction = {}));
|
63
|
+
/**
|
64
|
+
* Result type of a token scan
|
65
|
+
*/
|
66
|
+
var TokenScanResultType;
|
67
|
+
(function (TokenScanResultType) {
|
68
|
+
TokenScanResultType["Benign"] = "Benign";
|
69
|
+
TokenScanResultType["Warning"] = "Warning";
|
70
|
+
TokenScanResultType["Malicious"] = "Malicious";
|
71
|
+
TokenScanResultType["Spam"] = "Spam";
|
72
|
+
})(TokenScanResultType || (exports.TokenScanResultType = TokenScanResultType = {}));
|
73
|
+
exports.DEFAULT_CHAIN_ID_TO_NAME = {
|
74
|
+
'0x1': 'ethereum',
|
75
|
+
'0x89': 'polygon',
|
76
|
+
'0x38': 'bsc',
|
77
|
+
'0xa4b1': 'arbitrum',
|
78
|
+
'0xa86a': 'avalanche',
|
79
|
+
'0x2105': 'base',
|
80
|
+
'0xa': 'optimism',
|
81
|
+
'0x76adf1': 'zora',
|
82
|
+
'0xe708': 'linea',
|
83
|
+
'0x27bc86aa': 'degen',
|
84
|
+
'0x144': 'zksync',
|
85
|
+
'0x82750': 'scroll',
|
86
|
+
'0x13e31': 'blast',
|
87
|
+
'0x74c': 'soneium',
|
88
|
+
'0x79a': 'soneium-minato',
|
89
|
+
'0x14a34': 'base-sepolia',
|
90
|
+
'0xab5': 'abstract',
|
91
|
+
'0x849ea': 'zero-network',
|
92
|
+
'0x138de': 'berachain',
|
93
|
+
'0x82': 'unichain',
|
94
|
+
'0x7e4': 'ronin',
|
95
|
+
'0x127': 'hedera',
|
96
|
+
};
|
63
97
|
//# sourceMappingURL=types.cjs.map
|
package/dist/types.cjs.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAsCA;;GAEG;AACH,IAAY,0BA+BX;AA/BD,WAAY,0BAA0B;IACpC;;OAEG;IACH,yCAAW,CAAA;IACX;;OAEG;IACH,6CAAe,CAAA;IACf;;OAEG;IACH,qDAAuB,CAAA;IACvB;;OAEG;IACH,qDAAuB,CAAA;IACvB;;;OAGG;IACH,qDAAuB,CAAA;IACvB;;;OAGG;IACH,qDAAuB,CAAA;IACvB;;OAEG;IACH,qEAAuC,CAAA;AACzC,CAAC,EA/BW,0BAA0B,0CAA1B,0BAA0B,QA+BrC;AA8BD;;GAEG;AACH,IAAY,iBAkBX;AAlBD,WAAY,iBAAiB;IAC3B;;OAEG;IACH,kCAAa,CAAA;IACb;;OAEG;IACH,kCAAa,CAAA;IACb;;OAEG;IACH,oCAAe,CAAA;IACf;;;OAGG;IACH,0CAAqB,CAAA;AACvB,CAAC,EAlBW,iBAAiB,iCAAjB,iBAAiB,QAkB5B","sourcesContent":["/**\n * Represents the result of checking a domain.\n */\nexport type PhishingDetectorResult = {\n /**\n * The name of the configuration object in which the domain was found within\n * an allowlist, blocklist, or fuzzylist.\n */\n name?: string;\n /**\n * The version associated with the configuration object in which the domain\n * was found within an allowlist, blocklist, or fuzzylist.\n */\n version?: string;\n /**\n * Whether the domain is regarded as allowed (true) or not (false).\n */\n result: boolean;\n /**\n * A normalized version of the domain, which is only constructed if the domain\n * is found within a list.\n */\n match?: string;\n /**\n * Which type of list in which the domain was found.\n *\n * - \"allowlist\" means that the domain was found in the allowlist.\n * - \"blocklist\" means that the domain was found in the blocklist.\n * - \"fuzzy\" means that the domain was found in the fuzzylist.\n * - \"blacklist\" means that the domain was found in a blacklist of a legacy\n * configuration object.\n * - \"whitelist\" means that the domain was found in a whitelist of a legacy\n * configuration object.\n * - \"all\" means that the domain was not found in any list.\n */\n type: PhishingDetectorResultType;\n};\n\n/**\n * The type of list in which the domain was found.\n */\nexport enum PhishingDetectorResultType {\n /*\n * \"all\" means that the domain was not found in any list.\n */\n All = 'all',\n /*\n * \"fuzzy\" means that the domain was found in the fuzzylist.\n */\n Fuzzy = 'fuzzy',\n /*\n * \"blocklist\" means that the domain was found in the blocklist.\n */\n Blocklist = 'blocklist',\n /*\n * \"allowlist\" means that the domain was found in the allowlist.\n */\n Allowlist = 'allowlist',\n /*\n * \"blacklist\" means that the domain was found in a blacklist of a legacy\n * configuration object.\n */\n Blacklist = 'blacklist',\n /*\n * \"whitelist\" means that the domain was found in a whitelist of a legacy\n * configuration object.\n */\n Whitelist = 'whitelist',\n /*\n * \"c2DomainBlocklist\" means that the domain was found in the C2 domain blocklist.\n */\n C2DomainBlocklist = 'c2DomainBlocklist',\n}\n\n/**\n * PhishingDetectionScanResult represents the result of a phishing detection scan.\n */\nexport type PhishingDetectionScanResult = {\n /**\n * The hostname that was scanned.\n */\n hostname: string;\n /**\n * Indicates the warning level based on risk factors.\n *\n * - \"NONE\" means it is most likely safe.\n * - \"WARN\" means there is some risk.\n * - \"BLOCK\" means it is highly likely to be malicious.\n * - \"VERIFIED\" means it has been associated as an official domain of a\n * company or organization and/or a top Web3 domain.\n */\n recommendedAction: RecommendedAction;\n /**\n * An optional error message that exists if:\n * - The link requested is not a valid web URL.\n * - Failed to fetch the result from the phishing detector.\n *\n * Consumers can use the existence of this field to retry.\n */\n fetchError?: string;\n};\n\n/**\n * Indicates the warning level based on risk factors\n */\nexport enum RecommendedAction {\n /**\n * None means it is most likely safe\n */\n None = 'NONE',\n /**\n * Warn means there is some risk\n */\n Warn = 'WARN',\n /**\n * Block means it is highly likely to be malicious\n */\n Block = 'BLOCK',\n /**\n * Verified means it has been associated as an official domain of a\n * company or organization and/or a top Web3 domain.\n */\n Verified = 'VERIFIED',\n}\n"]}
|
1
|
+
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAsCA;;GAEG;AACH,IAAY,0BA+BX;AA/BD,WAAY,0BAA0B;IACpC;;OAEG;IACH,yCAAW,CAAA;IACX;;OAEG;IACH,6CAAe,CAAA;IACf;;OAEG;IACH,qDAAuB,CAAA;IACvB;;OAEG;IACH,qDAAuB,CAAA;IACvB;;;OAGG;IACH,qDAAuB,CAAA;IACvB;;;OAGG;IACH,qDAAuB,CAAA;IACvB;;OAEG;IACH,qEAAuC,CAAA;AACzC,CAAC,EA/BW,0BAA0B,0CAA1B,0BAA0B,QA+BrC;AA8BD;;GAEG;AACH,IAAY,iBAkBX;AAlBD,WAAY,iBAAiB;IAC3B;;OAEG;IACH,kCAAa,CAAA;IACb;;OAEG;IACH,kCAAa,CAAA;IACb;;OAEG;IACH,oCAAe,CAAA;IACf;;;OAGG;IACH,0CAAqB,CAAA;AACvB,CAAC,EAlBW,iBAAiB,iCAAjB,iBAAiB,QAkB5B;AAUD;;GAEG;AACH,IAAY,mBAKX;AALD,WAAY,mBAAmB;IAC7B,wCAAiB,CAAA;IACjB,0CAAmB,CAAA;IACnB,8CAAuB,CAAA;IACvB,oCAAa,CAAA;AACf,CAAC,EALW,mBAAmB,mCAAnB,mBAAmB,QAK9B;AAoCY,QAAA,wBAAwB,GAAG;IACtC,KAAK,EAAE,UAAU;IACjB,MAAM,EAAE,SAAS;IACjB,MAAM,EAAE,KAAK;IACb,QAAQ,EAAE,UAAU;IACpB,QAAQ,EAAE,WAAW;IACrB,QAAQ,EAAE,MAAM;IAChB,KAAK,EAAE,UAAU;IACjB,UAAU,EAAE,MAAM;IAClB,QAAQ,EAAE,OAAO;IACjB,YAAY,EAAE,OAAO;IACrB,OAAO,EAAE,QAAQ;IACjB,SAAS,EAAE,QAAQ;IACnB,SAAS,EAAE,OAAO;IAClB,OAAO,EAAE,SAAS;IAClB,OAAO,EAAE,gBAAgB;IACzB,SAAS,EAAE,cAAc;IACzB,OAAO,EAAE,UAAU;IACnB,SAAS,EAAE,cAAc;IACzB,SAAS,EAAE,WAAW;IACtB,MAAM,EAAE,UAAU;IAClB,OAAO,EAAE,OAAO;IAChB,OAAO,EAAE,QAAQ;CACT,CAAC","sourcesContent":["/**\n * Represents the result of checking a domain.\n */\nexport type PhishingDetectorResult = {\n /**\n * The name of the configuration object in which the domain was found within\n * an allowlist, blocklist, or fuzzylist.\n */\n name?: string;\n /**\n * The version associated with the configuration object in which the domain\n * was found within an allowlist, blocklist, or fuzzylist.\n */\n version?: string;\n /**\n * Whether the domain is regarded as allowed (true) or not (false).\n */\n result: boolean;\n /**\n * A normalized version of the domain, which is only constructed if the domain\n * is found within a list.\n */\n match?: string;\n /**\n * Which type of list in which the domain was found.\n *\n * - \"allowlist\" means that the domain was found in the allowlist.\n * - \"blocklist\" means that the domain was found in the blocklist.\n * - \"fuzzy\" means that the domain was found in the fuzzylist.\n * - \"blacklist\" means that the domain was found in a blacklist of a legacy\n * configuration object.\n * - \"whitelist\" means that the domain was found in a whitelist of a legacy\n * configuration object.\n * - \"all\" means that the domain was not found in any list.\n */\n type: PhishingDetectorResultType;\n};\n\n/**\n * The type of list in which the domain was found.\n */\nexport enum PhishingDetectorResultType {\n /*\n * \"all\" means that the domain was not found in any list.\n */\n All = 'all',\n /*\n * \"fuzzy\" means that the domain was found in the fuzzylist.\n */\n Fuzzy = 'fuzzy',\n /*\n * \"blocklist\" means that the domain was found in the blocklist.\n */\n Blocklist = 'blocklist',\n /*\n * \"allowlist\" means that the domain was found in the allowlist.\n */\n Allowlist = 'allowlist',\n /*\n * \"blacklist\" means that the domain was found in a blacklist of a legacy\n * configuration object.\n */\n Blacklist = 'blacklist',\n /*\n * \"whitelist\" means that the domain was found in a whitelist of a legacy\n * configuration object.\n */\n Whitelist = 'whitelist',\n /*\n * \"c2DomainBlocklist\" means that the domain was found in the C2 domain blocklist.\n */\n C2DomainBlocklist = 'c2DomainBlocklist',\n}\n\n/**\n * PhishingDetectionScanResult represents the result of a phishing detection scan.\n */\nexport type PhishingDetectionScanResult = {\n /**\n * The hostname that was scanned.\n */\n hostname: string;\n /**\n * Indicates the warning level based on risk factors.\n *\n * - \"NONE\" means it is most likely safe.\n * - \"WARN\" means there is some risk.\n * - \"BLOCK\" means it is highly likely to be malicious.\n * - \"VERIFIED\" means it has been associated as an official domain of a\n * company or organization and/or a top Web3 domain.\n */\n recommendedAction: RecommendedAction;\n /**\n * An optional error message that exists if:\n * - The link requested is not a valid web URL.\n * - Failed to fetch the result from the phishing detector.\n *\n * Consumers can use the existence of this field to retry.\n */\n fetchError?: string;\n};\n\n/**\n * Indicates the warning level based on risk factors\n */\nexport enum RecommendedAction {\n /**\n * None means it is most likely safe\n */\n None = 'NONE',\n /**\n * Warn means there is some risk\n */\n Warn = 'WARN',\n /**\n * Block means it is highly likely to be malicious\n */\n Block = 'BLOCK',\n /**\n * Verified means it has been associated as an official domain of a\n * company or organization and/or a top Web3 domain.\n */\n Verified = 'VERIFIED',\n}\n\n/**\n * Request for bulk token scan\n */\nexport type BulkTokenScanRequest = {\n chainId: string;\n tokens: string[];\n};\n\n/**\n * Result type of a token scan\n */\nexport enum TokenScanResultType {\n Benign = 'Benign',\n Warning = 'Warning',\n Malicious = 'Malicious',\n Spam = 'Spam',\n}\n\n/**\n * Result of a token scan\n */\nexport type TokenScanResult = {\n result_type: TokenScanResultType;\n chain: string;\n address: string;\n};\n\n/**\n * Response for bulk token scan requests\n */\nexport type BulkTokenScanResponse = Record<string, TokenScanResult>;\n\n/**\n * Token data stored in cache (excludes chain and address which are in the key)\n * For now, we only cache the result type, but we could add more data if needed in the future\n */\nexport type TokenScanCacheData = Omit<TokenScanResult, 'chain' | 'address'>;\n\n/**\n * API response from the bulk token scanning endpoint\n */\nexport type TokenScanApiResponse = {\n results: Record<\n string,\n {\n result_type: TokenScanResultType;\n chain?: string;\n address?: string;\n }\n >;\n};\n\nexport const DEFAULT_CHAIN_ID_TO_NAME = {\n '0x1': 'ethereum',\n '0x89': 'polygon',\n '0x38': 'bsc',\n '0xa4b1': 'arbitrum',\n '0xa86a': 'avalanche',\n '0x2105': 'base',\n '0xa': 'optimism',\n '0x76adf1': 'zora',\n '0xe708': 'linea',\n '0x27bc86aa': 'degen',\n '0x144': 'zksync',\n '0x82750': 'scroll',\n '0x13e31': 'blast',\n '0x74c': 'soneium',\n '0x79a': 'soneium-minato',\n '0x14a34': 'base-sepolia',\n '0xab5': 'abstract',\n '0x849ea': 'zero-network',\n '0x138de': 'berachain',\n '0x82': 'unichain',\n '0x7e4': 'ronin',\n '0x127': 'hedera',\n} as const;\n\nexport type ChainIdToNameMap = typeof DEFAULT_CHAIN_ID_TO_NAME;\n"]}
|
package/dist/types.d.cts
CHANGED
@@ -96,4 +96,72 @@ export declare enum RecommendedAction {
|
|
96
96
|
*/
|
97
97
|
Verified = "VERIFIED"
|
98
98
|
}
|
99
|
+
/**
|
100
|
+
* Request for bulk token scan
|
101
|
+
*/
|
102
|
+
export type BulkTokenScanRequest = {
|
103
|
+
chainId: string;
|
104
|
+
tokens: string[];
|
105
|
+
};
|
106
|
+
/**
|
107
|
+
* Result type of a token scan
|
108
|
+
*/
|
109
|
+
export declare enum TokenScanResultType {
|
110
|
+
Benign = "Benign",
|
111
|
+
Warning = "Warning",
|
112
|
+
Malicious = "Malicious",
|
113
|
+
Spam = "Spam"
|
114
|
+
}
|
115
|
+
/**
|
116
|
+
* Result of a token scan
|
117
|
+
*/
|
118
|
+
export type TokenScanResult = {
|
119
|
+
result_type: TokenScanResultType;
|
120
|
+
chain: string;
|
121
|
+
address: string;
|
122
|
+
};
|
123
|
+
/**
|
124
|
+
* Response for bulk token scan requests
|
125
|
+
*/
|
126
|
+
export type BulkTokenScanResponse = Record<string, TokenScanResult>;
|
127
|
+
/**
|
128
|
+
* Token data stored in cache (excludes chain and address which are in the key)
|
129
|
+
* For now, we only cache the result type, but we could add more data if needed in the future
|
130
|
+
*/
|
131
|
+
export type TokenScanCacheData = Omit<TokenScanResult, 'chain' | 'address'>;
|
132
|
+
/**
|
133
|
+
* API response from the bulk token scanning endpoint
|
134
|
+
*/
|
135
|
+
export type TokenScanApiResponse = {
|
136
|
+
results: Record<string, {
|
137
|
+
result_type: TokenScanResultType;
|
138
|
+
chain?: string;
|
139
|
+
address?: string;
|
140
|
+
}>;
|
141
|
+
};
|
142
|
+
export declare const DEFAULT_CHAIN_ID_TO_NAME: {
|
143
|
+
readonly '0x1': "ethereum";
|
144
|
+
readonly '0x89': "polygon";
|
145
|
+
readonly '0x38': "bsc";
|
146
|
+
readonly '0xa4b1': "arbitrum";
|
147
|
+
readonly '0xa86a': "avalanche";
|
148
|
+
readonly '0x2105': "base";
|
149
|
+
readonly '0xa': "optimism";
|
150
|
+
readonly '0x76adf1': "zora";
|
151
|
+
readonly '0xe708': "linea";
|
152
|
+
readonly '0x27bc86aa': "degen";
|
153
|
+
readonly '0x144': "zksync";
|
154
|
+
readonly '0x82750': "scroll";
|
155
|
+
readonly '0x13e31': "blast";
|
156
|
+
readonly '0x74c': "soneium";
|
157
|
+
readonly '0x79a': "soneium-minato";
|
158
|
+
readonly '0x14a34': "base-sepolia";
|
159
|
+
readonly '0xab5': "abstract";
|
160
|
+
readonly '0x849ea': "zero-network";
|
161
|
+
readonly '0x138de': "berachain";
|
162
|
+
readonly '0x82': "unichain";
|
163
|
+
readonly '0x7e4': "ronin";
|
164
|
+
readonly '0x127': "hedera";
|
165
|
+
};
|
166
|
+
export type ChainIdToNameMap = typeof DEFAULT_CHAIN_ID_TO_NAME;
|
99
167
|
//# sourceMappingURL=types.d.cts.map
|
package/dist/types.d.cts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,MAAM,EAAE,OAAO,CAAC;IAChB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;;;;;;;;OAWG;IACH,IAAI,EAAE,0BAA0B,CAAC;CAClC,CAAC;AAEF;;GAEG;AACH,oBAAY,0BAA0B;IAIpC,GAAG,QAAQ;IAIX,KAAK,UAAU;IAIf,SAAS,cAAc;IAIvB,SAAS,cAAc;IAKvB,SAAS,cAAc;IAKvB,SAAS,cAAc;IAIvB,iBAAiB,sBAAsB;CACxC;AAED;;GAEG;AACH,MAAM,MAAM,2BAA2B,GAAG;IACxC;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;;;;;OAQG;IACH,iBAAiB,EAAE,iBAAiB,CAAC;IACrC;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,MAAM,CAA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AAY,mBAAmB;IAC7B,MAAM,WAAW;IACjB,OAAO,YAAY;IACnB,SAAS,cAAc;IACvB,IAAI,SAAS;CACd;AAED;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,WAAW,EAAE,mBAAmB,CAAC;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;AAEpE;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG,IAAI,CAAC,eAAe,EAAE,OAAO,GAAG,SAAS,CAAC,CAAC;AAE5E;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,EAAE,MAAM,CACb,MAAM,EACN;QACE,WAAW,EAAE,mBAAmB,CAAC;QACjC,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,CACF,CAAC;CACH,CAAC;AAEF,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;CAuB3B,CAAC;AAEX,MAAM,MAAM,gBAAgB,GAAG,OAAO,wBAAwB,CAAC"}
|
package/dist/types.d.mts
CHANGED
@@ -96,4 +96,72 @@ export declare enum RecommendedAction {
|
|
96
96
|
*/
|
97
97
|
Verified = "VERIFIED"
|
98
98
|
}
|
99
|
+
/**
|
100
|
+
* Request for bulk token scan
|
101
|
+
*/
|
102
|
+
export type BulkTokenScanRequest = {
|
103
|
+
chainId: string;
|
104
|
+
tokens: string[];
|
105
|
+
};
|
106
|
+
/**
|
107
|
+
* Result type of a token scan
|
108
|
+
*/
|
109
|
+
export declare enum TokenScanResultType {
|
110
|
+
Benign = "Benign",
|
111
|
+
Warning = "Warning",
|
112
|
+
Malicious = "Malicious",
|
113
|
+
Spam = "Spam"
|
114
|
+
}
|
115
|
+
/**
|
116
|
+
* Result of a token scan
|
117
|
+
*/
|
118
|
+
export type TokenScanResult = {
|
119
|
+
result_type: TokenScanResultType;
|
120
|
+
chain: string;
|
121
|
+
address: string;
|
122
|
+
};
|
123
|
+
/**
|
124
|
+
* Response for bulk token scan requests
|
125
|
+
*/
|
126
|
+
export type BulkTokenScanResponse = Record<string, TokenScanResult>;
|
127
|
+
/**
|
128
|
+
* Token data stored in cache (excludes chain and address which are in the key)
|
129
|
+
* For now, we only cache the result type, but we could add more data if needed in the future
|
130
|
+
*/
|
131
|
+
export type TokenScanCacheData = Omit<TokenScanResult, 'chain' | 'address'>;
|
132
|
+
/**
|
133
|
+
* API response from the bulk token scanning endpoint
|
134
|
+
*/
|
135
|
+
export type TokenScanApiResponse = {
|
136
|
+
results: Record<string, {
|
137
|
+
result_type: TokenScanResultType;
|
138
|
+
chain?: string;
|
139
|
+
address?: string;
|
140
|
+
}>;
|
141
|
+
};
|
142
|
+
export declare const DEFAULT_CHAIN_ID_TO_NAME: {
|
143
|
+
readonly '0x1': "ethereum";
|
144
|
+
readonly '0x89': "polygon";
|
145
|
+
readonly '0x38': "bsc";
|
146
|
+
readonly '0xa4b1': "arbitrum";
|
147
|
+
readonly '0xa86a': "avalanche";
|
148
|
+
readonly '0x2105': "base";
|
149
|
+
readonly '0xa': "optimism";
|
150
|
+
readonly '0x76adf1': "zora";
|
151
|
+
readonly '0xe708': "linea";
|
152
|
+
readonly '0x27bc86aa': "degen";
|
153
|
+
readonly '0x144': "zksync";
|
154
|
+
readonly '0x82750': "scroll";
|
155
|
+
readonly '0x13e31': "blast";
|
156
|
+
readonly '0x74c': "soneium";
|
157
|
+
readonly '0x79a': "soneium-minato";
|
158
|
+
readonly '0x14a34': "base-sepolia";
|
159
|
+
readonly '0xab5': "abstract";
|
160
|
+
readonly '0x849ea': "zero-network";
|
161
|
+
readonly '0x138de': "berachain";
|
162
|
+
readonly '0x82': "unichain";
|
163
|
+
readonly '0x7e4': "ronin";
|
164
|
+
readonly '0x127': "hedera";
|
165
|
+
};
|
166
|
+
export type ChainIdToNameMap = typeof DEFAULT_CHAIN_ID_TO_NAME;
|
99
167
|
//# sourceMappingURL=types.d.mts.map
|
package/dist/types.d.mts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,MAAM,EAAE,OAAO,CAAC;IAChB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;;;;;;;;OAWG;IACH,IAAI,EAAE,0BAA0B,CAAC;CAClC,CAAC;AAEF;;GAEG;AACH,oBAAY,0BAA0B;IAIpC,GAAG,QAAQ;IAIX,KAAK,UAAU;IAIf,SAAS,cAAc;IAIvB,SAAS,cAAc;IAKvB,SAAS,cAAc;IAKvB,SAAS,cAAc;IAIvB,iBAAiB,sBAAsB;CACxC;AAED;;GAEG;AACH,MAAM,MAAM,2BAA2B,GAAG;IACxC;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;;;;;OAQG;IACH,iBAAiB,EAAE,iBAAiB,CAAC;IACrC;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;GAEG;AACH,oBAAY,iBAAiB;IAC3B;;OAEG;IACH,IAAI,SAAS;IACb;;OAEG;IACH,IAAI,SAAS;IACb;;OAEG;IACH,KAAK,UAAU;IACf;;;OAGG;IACH,QAAQ,aAAa;CACtB"}
|
1
|
+
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,OAAO,CAAC,EAA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I,CAAC,eAAe,EAAE,OAAO,GAAG,SAAS,CAAC,CAAC;AAE5E;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,EAAE,MAAM,CACb,MAAM,EACN;QACE,WAAW,EAAE,mBAAmB,CAAC;QACjC,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,CACF,CAAC;CACH,CAAC;AAEF,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;CAuB3B,CAAC;AAEX,MAAM,MAAM,gBAAgB,GAAG,OAAO,wBAAwB,CAAC"}
|
package/dist/types.mjs
CHANGED
@@ -57,4 +57,38 @@ export var RecommendedAction;
|
|
57
57
|
*/
|
58
58
|
RecommendedAction["Verified"] = "VERIFIED";
|
59
59
|
})(RecommendedAction || (RecommendedAction = {}));
|
60
|
+
/**
|
61
|
+
* Result type of a token scan
|
62
|
+
*/
|
63
|
+
export var TokenScanResultType;
|
64
|
+
(function (TokenScanResultType) {
|
65
|
+
TokenScanResultType["Benign"] = "Benign";
|
66
|
+
TokenScanResultType["Warning"] = "Warning";
|
67
|
+
TokenScanResultType["Malicious"] = "Malicious";
|
68
|
+
TokenScanResultType["Spam"] = "Spam";
|
69
|
+
})(TokenScanResultType || (TokenScanResultType = {}));
|
70
|
+
export const DEFAULT_CHAIN_ID_TO_NAME = {
|
71
|
+
'0x1': 'ethereum',
|
72
|
+
'0x89': 'polygon',
|
73
|
+
'0x38': 'bsc',
|
74
|
+
'0xa4b1': 'arbitrum',
|
75
|
+
'0xa86a': 'avalanche',
|
76
|
+
'0x2105': 'base',
|
77
|
+
'0xa': 'optimism',
|
78
|
+
'0x76adf1': 'zora',
|
79
|
+
'0xe708': 'linea',
|
80
|
+
'0x27bc86aa': 'degen',
|
81
|
+
'0x144': 'zksync',
|
82
|
+
'0x82750': 'scroll',
|
83
|
+
'0x13e31': 'blast',
|
84
|
+
'0x74c': 'soneium',
|
85
|
+
'0x79a': 'soneium-minato',
|
86
|
+
'0x14a34': 'base-sepolia',
|
87
|
+
'0xab5': 'abstract',
|
88
|
+
'0x849ea': 'zero-network',
|
89
|
+
'0x138de': 'berachain',
|
90
|
+
'0x82': 'unichain',
|
91
|
+
'0x7e4': 'ronin',
|
92
|
+
'0x127': 'hedera',
|
93
|
+
};
|
60
94
|
//# sourceMappingURL=types.mjs.map
|
package/dist/types.mjs.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAsCA;;GAEG;AACH,MAAM,CAAN,IAAY,0BA+BX;AA/BD,WAAY,0BAA0B;IACpC;;OAEG;IACH,yCAAW,CAAA;IACX;;OAEG;IACH,6CAAe,CAAA;IACf;;OAEG;IACH,qDAAuB,CAAA;IACvB;;OAEG;IACH,qDAAuB,CAAA;IACvB;;;OAGG;IACH,qDAAuB,CAAA;IACvB;;;OAGG;IACH,qDAAuB,CAAA;IACvB;;OAEG;IACH,qEAAuC,CAAA;AACzC,CAAC,EA/BW,0BAA0B,KAA1B,0BAA0B,QA+BrC;AA8BD;;GAEG;AACH,MAAM,CAAN,IAAY,iBAkBX;AAlBD,WAAY,iBAAiB;IAC3B;;OAEG;IACH,kCAAa,CAAA;IACb;;OAEG;IACH,kCAAa,CAAA;IACb;;OAEG;IACH,oCAAe,CAAA;IACf;;;OAGG;IACH,0CAAqB,CAAA;AACvB,CAAC,EAlBW,iBAAiB,KAAjB,iBAAiB,QAkB5B","sourcesContent":["/**\n * Represents the result of checking a domain.\n */\nexport type PhishingDetectorResult = {\n /**\n * The name of the configuration object in which the domain was found within\n * an allowlist, blocklist, or fuzzylist.\n */\n name?: string;\n /**\n * The version associated with the configuration object in which the domain\n * was found within an allowlist, blocklist, or fuzzylist.\n */\n version?: string;\n /**\n * Whether the domain is regarded as allowed (true) or not (false).\n */\n result: boolean;\n /**\n * A normalized version of the domain, which is only constructed if the domain\n * is found within a list.\n */\n match?: string;\n /**\n * Which type of list in which the domain was found.\n *\n * - \"allowlist\" means that the domain was found in the allowlist.\n * - \"blocklist\" means that the domain was found in the blocklist.\n * - \"fuzzy\" means that the domain was found in the fuzzylist.\n * - \"blacklist\" means that the domain was found in a blacklist of a legacy\n * configuration object.\n * - \"whitelist\" means that the domain was found in a whitelist of a legacy\n * configuration object.\n * - \"all\" means that the domain was not found in any list.\n */\n type: PhishingDetectorResultType;\n};\n\n/**\n * The type of list in which the domain was found.\n */\nexport enum PhishingDetectorResultType {\n /*\n * \"all\" means that the domain was not found in any list.\n */\n All = 'all',\n /*\n * \"fuzzy\" means that the domain was found in the fuzzylist.\n */\n Fuzzy = 'fuzzy',\n /*\n * \"blocklist\" means that the domain was found in the blocklist.\n */\n Blocklist = 'blocklist',\n /*\n * \"allowlist\" means that the domain was found in the allowlist.\n */\n Allowlist = 'allowlist',\n /*\n * \"blacklist\" means that the domain was found in a blacklist of a legacy\n * configuration object.\n */\n Blacklist = 'blacklist',\n /*\n * \"whitelist\" means that the domain was found in a whitelist of a legacy\n * configuration object.\n */\n Whitelist = 'whitelist',\n /*\n * \"c2DomainBlocklist\" means that the domain was found in the C2 domain blocklist.\n */\n C2DomainBlocklist = 'c2DomainBlocklist',\n}\n\n/**\n * PhishingDetectionScanResult represents the result of a phishing detection scan.\n */\nexport type PhishingDetectionScanResult = {\n /**\n * The hostname that was scanned.\n */\n hostname: string;\n /**\n * Indicates the warning level based on risk factors.\n *\n * - \"NONE\" means it is most likely safe.\n * - \"WARN\" means there is some risk.\n * - \"BLOCK\" means it is highly likely to be malicious.\n * - \"VERIFIED\" means it has been associated as an official domain of a\n * company or organization and/or a top Web3 domain.\n */\n recommendedAction: RecommendedAction;\n /**\n * An optional error message that exists if:\n * - The link requested is not a valid web URL.\n * - Failed to fetch the result from the phishing detector.\n *\n * Consumers can use the existence of this field to retry.\n */\n fetchError?: string;\n};\n\n/**\n * Indicates the warning level based on risk factors\n */\nexport enum RecommendedAction {\n /**\n * None means it is most likely safe\n */\n None = 'NONE',\n /**\n * Warn means there is some risk\n */\n Warn = 'WARN',\n /**\n * Block means it is highly likely to be malicious\n */\n Block = 'BLOCK',\n /**\n * Verified means it has been associated as an official domain of a\n * company or organization and/or a top Web3 domain.\n */\n Verified = 'VERIFIED',\n}\n"]}
|
1
|
+
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAsCA;;GAEG;AACH,MAAM,CAAN,IAAY,0BA+BX;AA/BD,WAAY,0BAA0B;IACpC;;OAEG;IACH,yCAAW,CAAA;IACX;;OAEG;IACH,6CAAe,CAAA;IACf;;OAEG;IACH,qDAAuB,CAAA;IACvB;;OAEG;IACH,qDAAuB,CAAA;IACvB;;;OAGG;IACH,qDAAuB,CAAA;IACvB;;;OAGG;IACH,qDAAuB,CAAA;IACvB;;OAEG;IACH,qEAAuC,CAAA;AACzC,CAAC,EA/BW,0BAA0B,KAA1B,0BAA0B,QA+BrC;AA8BD;;GAEG;AACH,MAAM,CAAN,IAAY,iBAkBX;AAlBD,WAAY,iBAAiB;IAC3B;;OAEG;IACH,kCAAa,CAAA;IACb;;OAEG;IACH,kCAAa,CAAA;IACb;;OAEG;IACH,oCAAe,CAAA;IACf;;;OAGG;IACH,0CAAqB,CAAA;AACvB,CAAC,EAlBW,iBAAiB,KAAjB,iBAAiB,QAkB5B;AAUD;;GAEG;AACH,MAAM,CAAN,IAAY,mBAKX;AALD,WAAY,mBAAmB;IAC7B,wCAAiB,CAAA;IACjB,0CAAmB,CAAA;IACnB,8CAAuB,CAAA;IACvB,oCAAa,CAAA;AACf,CAAC,EALW,mBAAmB,KAAnB,mBAAmB,QAK9B;AAoCD,MAAM,CAAC,MAAM,wBAAwB,GAAG;IACtC,KAAK,EAAE,UAAU;IACjB,MAAM,EAAE,SAAS;IACjB,MAAM,EAAE,KAAK;IACb,QAAQ,EAAE,UAAU;IACpB,QAAQ,EAAE,WAAW;IACrB,QAAQ,EAAE,MAAM;IAChB,KAAK,EAAE,UAAU;IACjB,UAAU,EAAE,MAAM;IAClB,QAAQ,EAAE,OAAO;IACjB,YAAY,EAAE,OAAO;IACrB,OAAO,EAAE,QAAQ;IACjB,SAAS,EAAE,QAAQ;IACnB,SAAS,EAAE,OAAO;IAClB,OAAO,EAAE,SAAS;IAClB,OAAO,EAAE,gBAAgB;IACzB,SAAS,EAAE,cAAc;IACzB,OAAO,EAAE,UAAU;IACnB,SAAS,EAAE,cAAc;IACzB,SAAS,EAAE,WAAW;IACtB,MAAM,EAAE,UAAU;IAClB,OAAO,EAAE,OAAO;IAChB,OAAO,EAAE,QAAQ;CACT,CAAC","sourcesContent":["/**\n * Represents the result of checking a domain.\n */\nexport type PhishingDetectorResult = {\n /**\n * The name of the configuration object in which the domain was found within\n * an allowlist, blocklist, or fuzzylist.\n */\n name?: string;\n /**\n * The version associated with the configuration object in which the domain\n * was found within an allowlist, blocklist, or fuzzylist.\n */\n version?: string;\n /**\n * Whether the domain is regarded as allowed (true) or not (false).\n */\n result: boolean;\n /**\n * A normalized version of the domain, which is only constructed if the domain\n * is found within a list.\n */\n match?: string;\n /**\n * Which type of list in which the domain was found.\n *\n * - \"allowlist\" means that the domain was found in the allowlist.\n * - \"blocklist\" means that the domain was found in the blocklist.\n * - \"fuzzy\" means that the domain was found in the fuzzylist.\n * - \"blacklist\" means that the domain was found in a blacklist of a legacy\n * configuration object.\n * - \"whitelist\" means that the domain was found in a whitelist of a legacy\n * configuration object.\n * - \"all\" means that the domain was not found in any list.\n */\n type: PhishingDetectorResultType;\n};\n\n/**\n * The type of list in which the domain was found.\n */\nexport enum PhishingDetectorResultType {\n /*\n * \"all\" means that the domain was not found in any list.\n */\n All = 'all',\n /*\n * \"fuzzy\" means that the domain was found in the fuzzylist.\n */\n Fuzzy = 'fuzzy',\n /*\n * \"blocklist\" means that the domain was found in the blocklist.\n */\n Blocklist = 'blocklist',\n /*\n * \"allowlist\" means that the domain was found in the allowlist.\n */\n Allowlist = 'allowlist',\n /*\n * \"blacklist\" means that the domain was found in a blacklist of a legacy\n * configuration object.\n */\n Blacklist = 'blacklist',\n /*\n * \"whitelist\" means that the domain was found in a whitelist of a legacy\n * configuration object.\n */\n Whitelist = 'whitelist',\n /*\n * \"c2DomainBlocklist\" means that the domain was found in the C2 domain blocklist.\n */\n C2DomainBlocklist = 'c2DomainBlocklist',\n}\n\n/**\n * PhishingDetectionScanResult represents the result of a phishing detection scan.\n */\nexport type PhishingDetectionScanResult = {\n /**\n * The hostname that was scanned.\n */\n hostname: string;\n /**\n * Indicates the warning level based on risk factors.\n *\n * - \"NONE\" means it is most likely safe.\n * - \"WARN\" means there is some risk.\n * - \"BLOCK\" means it is highly likely to be malicious.\n * - \"VERIFIED\" means it has been associated as an official domain of a\n * company or organization and/or a top Web3 domain.\n */\n recommendedAction: RecommendedAction;\n /**\n * An optional error message that exists if:\n * - The link requested is not a valid web URL.\n * - Failed to fetch the result from the phishing detector.\n *\n * Consumers can use the existence of this field to retry.\n */\n fetchError?: string;\n};\n\n/**\n * Indicates the warning level based on risk factors\n */\nexport enum RecommendedAction {\n /**\n * None means it is most likely safe\n */\n None = 'NONE',\n /**\n * Warn means there is some risk\n */\n Warn = 'WARN',\n /**\n * Block means it is highly likely to be malicious\n */\n Block = 'BLOCK',\n /**\n * Verified means it has been associated as an official domain of a\n * company or organization and/or a top Web3 domain.\n */\n Verified = 'VERIFIED',\n}\n\n/**\n * Request for bulk token scan\n */\nexport type BulkTokenScanRequest = {\n chainId: string;\n tokens: string[];\n};\n\n/**\n * Result type of a token scan\n */\nexport enum TokenScanResultType {\n Benign = 'Benign',\n Warning = 'Warning',\n Malicious = 'Malicious',\n Spam = 'Spam',\n}\n\n/**\n * Result of a token scan\n */\nexport type TokenScanResult = {\n result_type: TokenScanResultType;\n chain: string;\n address: string;\n};\n\n/**\n * Response for bulk token scan requests\n */\nexport type BulkTokenScanResponse = Record<string, TokenScanResult>;\n\n/**\n * Token data stored in cache (excludes chain and address which are in the key)\n * For now, we only cache the result type, but we could add more data if needed in the future\n */\nexport type TokenScanCacheData = Omit<TokenScanResult, 'chain' | 'address'>;\n\n/**\n * API response from the bulk token scanning endpoint\n */\nexport type TokenScanApiResponse = {\n results: Record<\n string,\n {\n result_type: TokenScanResultType;\n chain?: string;\n address?: string;\n }\n >;\n};\n\nexport const DEFAULT_CHAIN_ID_TO_NAME = {\n '0x1': 'ethereum',\n '0x89': 'polygon',\n '0x38': 'bsc',\n '0xa4b1': 'arbitrum',\n '0xa86a': 'avalanche',\n '0x2105': 'base',\n '0xa': 'optimism',\n '0x76adf1': 'zora',\n '0xe708': 'linea',\n '0x27bc86aa': 'degen',\n '0x144': 'zksync',\n '0x82750': 'scroll',\n '0x13e31': 'blast',\n '0x74c': 'soneium',\n '0x79a': 'soneium-minato',\n '0x14a34': 'base-sepolia',\n '0xab5': 'abstract',\n '0x849ea': 'zero-network',\n '0x138de': 'berachain',\n '0x82': 'unichain',\n '0x7e4': 'ronin',\n '0x127': 'hedera',\n} as const;\n\nexport type ChainIdToNameMap = typeof DEFAULT_CHAIN_ID_TO_NAME;\n"]}
|
package/dist/utils.cjs
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.generateParentDomains = exports.getHostnameFromWebUrl = exports.getHostnameFromUrl = exports.sha256Hash = exports.matchPartsAgainstList = exports.domainPartsToFuzzyForm = exports.domainPartsToDomain = exports.processConfigs = exports.getDefaultPhishingDetectorConfig = exports.processDomainList = exports.domainToParts = exports.validateConfig = exports.applyDiffs = exports.roundToNearestMinute = exports.fetchTimeNow = void 0;
|
3
|
+
exports.splitCacheHits = exports.resolveChainName = exports.buildCacheKey = exports.generateParentDomains = exports.getHostnameFromWebUrl = exports.getHostnameFromUrl = exports.sha256Hash = exports.matchPartsAgainstList = exports.domainPartsToFuzzyForm = exports.domainPartsToDomain = exports.processConfigs = exports.getDefaultPhishingDetectorConfig = exports.processDomainList = exports.domainToParts = exports.validateConfig = exports.applyDiffs = exports.roundToNearestMinute = exports.fetchTimeNow = void 0;
|
4
4
|
const utils_1 = require("@noble/hashes/utils");
|
5
5
|
const sha256_1 = require("ethereum-cryptography/sha256");
|
6
6
|
const PhishingController_1 = require("./PhishingController.cjs");
|
7
|
+
const types_1 = require("./types.cjs");
|
7
8
|
const DEFAULT_TOLERANCE = 3;
|
8
9
|
/**
|
9
10
|
* Fetches current epoch time in seconds.
|
@@ -313,4 +314,56 @@ const generateParentDomains = (sourceParts, limit = 5) => {
|
|
313
314
|
return domains;
|
314
315
|
};
|
315
316
|
exports.generateParentDomains = generateParentDomains;
|
317
|
+
/**
|
318
|
+
* Builds a cache key for a token scan result.
|
319
|
+
*
|
320
|
+
* @param chainId - The chain ID.
|
321
|
+
* @param address - The token address.
|
322
|
+
* @returns The cache key.
|
323
|
+
*/
|
324
|
+
const buildCacheKey = (chainId, address) => {
|
325
|
+
return `${chainId.toLowerCase()}:${address.toLowerCase()}`;
|
326
|
+
};
|
327
|
+
exports.buildCacheKey = buildCacheKey;
|
328
|
+
/**
|
329
|
+
* Resolves the chain name from a chain ID.
|
330
|
+
*
|
331
|
+
* @param chainId - The chain ID.
|
332
|
+
* @param mapping - The mapping of chain IDs to chain names.
|
333
|
+
* @returns The chain name.
|
334
|
+
*/
|
335
|
+
const resolveChainName = (chainId, mapping = types_1.DEFAULT_CHAIN_ID_TO_NAME) => {
|
336
|
+
return mapping[chainId.toLowerCase()] ?? null;
|
337
|
+
};
|
338
|
+
exports.resolveChainName = resolveChainName;
|
339
|
+
/**
|
340
|
+
* Split tokens into cached results and tokens that need to be fetched.
|
341
|
+
*
|
342
|
+
* @param cache - Cache-like object with get method.
|
343
|
+
* @param cache.get - Method to retrieve cached data by key.
|
344
|
+
* @param chainId - The chain ID.
|
345
|
+
* @param tokens - Array of token addresses.
|
346
|
+
* @returns Object containing cached results and tokens to fetch.
|
347
|
+
*/
|
348
|
+
const splitCacheHits = (cache, chainId, tokens) => {
|
349
|
+
const cachedResults = {};
|
350
|
+
const tokensToFetch = [];
|
351
|
+
for (const addr of tokens) {
|
352
|
+
const normalizedAddr = addr.toLowerCase();
|
353
|
+
const key = (0, exports.buildCacheKey)(chainId, normalizedAddr);
|
354
|
+
const hit = cache.get(key);
|
355
|
+
if (hit) {
|
356
|
+
cachedResults[normalizedAddr] = {
|
357
|
+
result_type: hit.result_type,
|
358
|
+
chain: chainId,
|
359
|
+
address: normalizedAddr,
|
360
|
+
};
|
361
|
+
}
|
362
|
+
else {
|
363
|
+
tokensToFetch.push(normalizedAddr);
|
364
|
+
}
|
365
|
+
}
|
366
|
+
return { cachedResults, tokensToFetch };
|
367
|
+
};
|
368
|
+
exports.splitCacheHits = splitCacheHits;
|
316
369
|
//# sourceMappingURL=utils.cjs.map
|
package/dist/utils.cjs.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA,+CAAiD;AACjD,yDAAsD;AAGtD,iEAAwE;AAMxE,MAAM,iBAAiB,GAAG,CAAC,CAAC;AAE5B;;;;GAIG;AACI,MAAM,YAAY,GAAG,GAAW,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;AAA3D,QAAA,YAAY,gBAA+C;AAExE;;;;;GAKG;AACH,SAAgB,oBAAoB,CAAC,aAAqB;IACxD,OAAO,IAAI,CAAC,KAAK,CAAC,aAAa,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC;AAC7C,CAAC;AAFD,oDAEC;AAED;;;;;GAKG;AACH,MAAM,mBAAmB,GAAG,CAC1B,aAAgC,EAClB,EAAE;IAChB,MAAM,WAAW,GAAG,aAAa,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC/C,OAAO;QACL,aAAa,CAAC,KAAK,CAAC,CAAC,EAAE,WAAW,CAAU;QAC5C,aAAa,CAAC,KAAK,CAAC,WAAW,GAAG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C;AAVW,QAAA,qBAAqB,yBAUhC;AAEF;;;;;;;;;;;;;;;GAeG;AACI,MAAM,qBAAqB,GAAG,CACnC,WAAqB,EACrB,KAAK,GAAG,CAAC,EACC,EAAE;IACZ,MAAM,OAAO,GAAa,EAAE,CAAC;IAE7B,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE;QAC5B,OAAO,OAAO,CAAC;KAChB;IAED,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE;QAC5B,uCAAuC;QACvC,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;KAC5C;SAAM;QACL,sFAAsF;QACtF,MAAM,UAAU,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACnD,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,WAAW,EAAE,CAAC,CAAC;QAEvC,2EAA2E;QAC3E,KACE,IAAI,CAAC,GAAG,WAAW,CAAC,MAAM,GAAG,CAAC,EAC9B,CAAC,IAAI,CAAC,IAAI,OAAO,CAAC,MAAM,GAAG,KAAK,EAChC,CAAC,EAAE,EACH;YACA,MAAM,MAAM,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAC9C,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC;SACpC;KACF;IAED,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AA9BW,QAAA,qBAAqB,yBA8BhC","sourcesContent":["import { bytesToHex } from '@noble/hashes/utils';\nimport { sha256 } from 'ethereum-cryptography/sha256';\n\nimport type { Hotlist, PhishingListState } from './PhishingController';\nimport { ListKeys, phishingListKeyNameMap } from './PhishingController';\nimport type {\n PhishingDetectorList,\n PhishingDetectorConfiguration,\n} from './PhishingDetector';\n\nconst DEFAULT_TOLERANCE = 3;\n\n/**\n * Fetches current epoch time in seconds.\n *\n * @returns the Date.now() time in seconds instead of miliseconds. backend files rely on timestamps in seconds since epoch.\n */\nexport const fetchTimeNow = (): number => Math.round(Date.now() / 1000);\n\n/**\n * Rounds a Unix timestamp down to the nearest minute.\n *\n * @param unixTimestamp - The Unix timestamp to be rounded.\n * @returns The rounded Unix timestamp.\n */\nexport function roundToNearestMinute(unixTimestamp: number): number {\n return Math.floor(unixTimestamp / 60) * 60;\n}\n\n/**\n * Split a string into two pieces, using the first period as the delimiter.\n *\n * @param stringToSplit - The string to split.\n * @returns An array of length two containing the beginning and end of the string.\n */\nconst splitStringByPeriod = <Start extends string, End extends string>(\n stringToSplit: `${Start}.${End}`,\n): [Start, End] => {\n const periodIndex = stringToSplit.indexOf('.');\n return [\n stringToSplit.slice(0, periodIndex) as Start,\n stringToSplit.slice(periodIndex + 1) as End,\n ];\n};\n\n/**\n * Determines which diffs are applicable to the listState, then applies those diffs.\n *\n * @param listState - the stalelist or the existing liststate that diffs will be applied to.\n * @param hotlistDiffs - the diffs to apply to the listState if valid.\n * @param listKey - the key associated with the input/output phishing list state.\n * @param recentlyAddedC2Domains - list of hashed C2 domains to add to the local c2 domain blocklist\n * @param recentlyRemovedC2Domains - list of hashed C2 domains to remove from the local c2 domain blocklist\n * @returns the new list state\n */\nexport const applyDiffs = (\n listState: PhishingListState,\n hotlistDiffs: Hotlist,\n listKey: ListKeys,\n recentlyAddedC2Domains: string[] = [],\n recentlyRemovedC2Domains: string[] = [],\n): PhishingListState => {\n // filter to remove diffs that were added before the lastUpdate time.\n // filter to remove diffs that aren't applicable to the specified list (by listKey).\n const diffsToApply = hotlistDiffs.filter(\n ({ timestamp, targetList }) =>\n timestamp > listState.lastUpdated &&\n splitStringByPeriod(targetList)[0] === listKey,\n );\n\n // the reason behind using latestDiffTimestamp as the lastUpdated time\n // is so that we can benefit server-side from memoization due to end client's\n // `GET /v1/diffSince/:timestamp` requests lining up with\n // our periodic updates (which create diffs at specific timestamps).\n let latestDiffTimestamp = listState.lastUpdated;\n\n const listSets = {\n allowlist: new Set(listState.allowlist),\n blocklist: new Set(listState.blocklist),\n fuzzylist: new Set(listState.fuzzylist),\n c2DomainBlocklist: new Set(listState.c2DomainBlocklist),\n };\n for (const { isRemoval, targetList, url, timestamp } of diffsToApply) {\n const targetListType = splitStringByPeriod(targetList)[1];\n if (timestamp > latestDiffTimestamp) {\n latestDiffTimestamp = timestamp;\n }\n if (isRemoval) {\n listSets[targetListType].delete(url);\n } else {\n listSets[targetListType].add(url);\n }\n }\n\n if (listKey === ListKeys.EthPhishingDetectConfig) {\n for (const hash of recentlyAddedC2Domains) {\n listSets.c2DomainBlocklist.add(hash);\n }\n for (const hash of recentlyRemovedC2Domains) {\n listSets.c2DomainBlocklist.delete(hash);\n }\n }\n\n return {\n c2DomainBlocklist: Array.from(listSets.c2DomainBlocklist),\n allowlist: Array.from(listSets.allowlist),\n blocklist: Array.from(listSets.blocklist),\n fuzzylist: Array.from(listSets.fuzzylist),\n version: listState.version,\n name: phishingListKeyNameMap[listKey],\n tolerance: listState.tolerance,\n lastUpdated: latestDiffTimestamp,\n };\n};\n\n/**\n * Validates the configuration object for the phishing detector.\n *\n * @param config - the configuration object to validate.\n * @throws an error if the configuration is invalid.\n */\nexport function validateConfig(\n config: unknown,\n): asserts config is PhishingListState {\n if (config === null || typeof config !== 'object') {\n throw new Error('Invalid config');\n }\n\n if ('tolerance' in config && !('fuzzylist' in config)) {\n throw new Error('Fuzzylist tolerance provided without fuzzylist');\n }\n\n if (\n 'name' in config &&\n (typeof config.name !== 'string' || config.name === '')\n ) {\n throw new Error(\"Invalid config parameter: 'name'\");\n }\n\n if (\n 'version' in config &&\n (!['number', 'string'].includes(typeof config.version) ||\n config.version === '')\n ) {\n throw new Error(\"Invalid config parameter: 'version'\");\n }\n}\n\n/**\n * Converts a domain string to a list of domain parts.\n *\n * @param domain - the domain string to convert.\n * @returns the list of domain parts.\n */\nexport const domainToParts = (domain: string) => {\n try {\n return domain.split('.').reverse();\n } catch (e) {\n throw new Error(JSON.stringify(domain));\n }\n};\n\n/**\n * Converts a list of domain strings to a list of domain parts.\n *\n * @param list - the list of domain strings to convert.\n * @returns the list of domain parts.\n */\nexport const processDomainList = (list: string[]) => {\n return list.map(domainToParts);\n};\n\n/**\n * Gets the default phishing detector configuration.\n *\n * @param override - the optional override for the configuration.\n * @param override.allowlist - the optional allowlist to override.\n * @param override.blocklist - the optional blocklist to override.\n * @param override.c2DomainBlocklist - the optional c2DomainBlocklist to override.\n * @param override.fuzzylist - the optional fuzzylist to override.\n * @param override.tolerance - the optional tolerance to override.\n * @returns the default phishing detector configuration.\n */\nexport const getDefaultPhishingDetectorConfig = ({\n allowlist = [],\n blocklist = [],\n fuzzylist = [],\n tolerance = DEFAULT_TOLERANCE,\n}: {\n allowlist?: string[];\n blocklist?: string[];\n c2DomainBlocklist?: string[];\n fuzzylist?: string[];\n tolerance?: number;\n}): PhishingDetectorConfiguration => ({\n allowlist: processDomainList(allowlist),\n blocklist: processDomainList(blocklist),\n fuzzylist: processDomainList(fuzzylist),\n tolerance,\n});\n\n/**\n * Processes the configurations for the phishing detector, filtering out any invalid configs.\n *\n * @param configs - The configurations to process.\n * @returns An array of processed and valid configurations.\n */\nexport const processConfigs = (\n configs: PhishingDetectorList[] = [],\n): PhishingDetectorConfiguration[] => {\n return configs\n .filter((config) => {\n try {\n validateConfig(config);\n return true;\n } catch (error) {\n console.error(error);\n return false;\n }\n })\n .map((config) => ({\n ...config,\n ...getDefaultPhishingDetectorConfig(config),\n }));\n};\n\n/**\n * Converts a list of domain parts to a domain string.\n *\n * @param domainParts - the list of domain parts.\n * @returns the domain string.\n */\nexport const domainPartsToDomain = (domainParts: string[]) => {\n return domainParts.slice().reverse().join('.');\n};\n\n/**\n * Converts a list of domain parts to a fuzzy form.\n *\n * @param domainParts - the list of domain parts.\n * @returns the fuzzy form of the domain.\n */\nexport const domainPartsToFuzzyForm = (domainParts: string[]) => {\n return domainParts.slice(1).reverse().join('.');\n};\n\n/**\n * Matches the target parts, ignoring extra subdomains on source.\n *\n * @param source - the source domain parts.\n * @param list - the list of domain parts to match against.\n * @returns the parts for the first found matching entry.\n */\nexport const matchPartsAgainstList = (source: string[], list: string[][]) => {\n return list.find((target) => {\n // target domain has more parts than source, fail\n if (target.length > source.length) {\n return false;\n }\n // source matches target or (is deeper subdomain)\n return target.every((part, index) => source[index] === part);\n });\n};\n\n/**\n * Generate the SHA-256 hash of a hostname.\n *\n * @param hostname - The hostname to hash.\n * @returns The SHA-256 hash of the hostname.\n */\nexport const sha256Hash = (hostname: string): string => {\n const hashBuffer = sha256(new TextEncoder().encode(hostname.toLowerCase()));\n return bytesToHex(hashBuffer);\n};\n\n/**\n * Extracts the hostname from a URL.\n *\n * @param url - The URL to extract the hostname from.\n * @returns The hostname extracted from the URL, or null if the URL is invalid.\n */\nexport const getHostnameFromUrl = (url: string): string | null => {\n let hostname;\n try {\n hostname = new URL(url).hostname;\n // above will not throw if 'http://.' is passed. in fact, any string with a dot will pass.\n if (!hostname || hostname.split('.').join('') === '') {\n return null;\n }\n } catch {\n return null;\n }\n return hostname;\n};\n\n/**\n * getHostnameFromWebUrl returns the hostname from a web URL.\n * It returns the hostname and a boolean indicating if the hostname is valid.\n *\n * @param url - The web URL to extract the hostname from.\n * @returns A tuple containing the extracted hostname and a boolean indicating if the hostname is valid.\n * @example\n * getHostnameFromWebUrl('https://example.com') // Returns: ['example.com', true]\n * getHostnameFromWebUrl('example.com') // Returns: ['', false]\n * getHostnameFromWebUrl('https://') // Returns: ['', false]\n * getHostnameFromWebUrl('') // Returns: ['', false]\n */\nexport const getHostnameFromWebUrl = (url: string): [string, boolean] => {\n if (\n !url.toLowerCase().startsWith('http://') &&\n !url.toLowerCase().startsWith('https://')\n ) {\n return ['', false];\n }\n\n const hostname = getHostnameFromUrl(url);\n return [hostname || '', Boolean(hostname)];\n};\n\n/**\n * Generates all possible parent domains up to a specified limit.\n *\n * @param sourceParts - The list of domain parts in normal order (e.g., ['evil', 'domain', 'co', 'uk']).\n * @param limit - The maximum number of parent domains to generate (default is 5).\n * @returns An array of parent domains starting from the base TLD to the most specific subdomain.\n * @example\n * generateParentDomains(['evil', 'domain', 'co', 'uk'], 5)\n * // Returns: ['co.uk', 'domain.co.uk', 'evil.domain.co.uk']\n *\n * generateParentDomains(['uk'], 5)\n * // Returns: ['uk']\n *\n * generateParentDomains(['sub', 'example', 'com'], 5)\n * // Returns: ['example.com', 'sub.example.com']\n */\nexport const generateParentDomains = (\n sourceParts: string[],\n limit = 5,\n): string[] => {\n const domains: string[] = [];\n\n if (sourceParts.length === 0) {\n return domains;\n }\n\n if (sourceParts.length === 1) {\n // Single-segment hostname (e.g., 'uk')\n domains.push(sourceParts[0].toLowerCase());\n } else {\n // Start with the base domain or TLD (last two labels, e.g., 'co.uk' or 'example.com')\n const baseDomain = sourceParts.slice(-2).join('.');\n domains.push(baseDomain.toLowerCase());\n\n // Iteratively add one subdomain level at a time, up to the specified limit\n for (\n let i = sourceParts.length - 3;\n i >= 0 && domains.length < limit;\n i--\n ) {\n const domain = sourceParts.slice(i).join('.');\n domains.push(domain.toLowerCase());\n }\n }\n\n return domains;\n};\n"]}
|
1
|
+
{"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA,+CAAiD;AACjD,yDAAsD;AAGtD,iEAAwE;AAKxE,uCAIiB;AAEjB,MAAM,iBAAiB,GAAG,CAAC,CAAC;AAE5B;;;;GAIG;AACI,MAAM,YAAY,GAAG,GAAW,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;AAA3D,QAAA,YAAY,gBAA+C;AAExE;;;;;GAKG;AACH,SAAgB,oBAAoB,CAAC,aAAqB;IACxD,OAAO,IAAI,CAAC,KAAK,CAAC,aAAa,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC;AAC7C,CAAC;AAFD,oDAEC;AAED;;;;;GAKG;A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;;GAMG;AACI,MAAM,aAAa,GAAG,CAAC,OAAe,EAAE,OAAe,EAAE,EAAE;IAChE,OAAO,GAAG,OAAO,CAAC,WAAW,EAAE,IAAI,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC;AAC7D,CAAC,CAAC;AAFW,QAAA,aAAa,iBAExB;AAEF;;;;;;GAMG;AACI,MAAM,gBAAgB,GAAG,CAC9B,OAAe,EACf,OAAO,GAAG,gCAAwB,EACnB,EAAE;IACjB,OAAO,OAAO,CAAC,OAAO,CAAC,WAAW,EAA0B,CAAC,IAAI,IAAI,CAAC;AACxE,CAAC,CAAC;AALW,QAAA,gBAAgB,oBAK3B;AAEF;;;;;;;;GAQG;AACI,MAAM,cAAc,GAAG,CAC5B,KAA+D,EAC/D,OAAe,EACf,MAAgB,EAIhB,EAAE;IACF,MAAM,aAAa,GAAoC,EAAE,CAAC;IAC1D,MAAM,aAAa,GAAa,EAAE,CAAC;IAEnC,KAAK,MAAM,IAAI,IAAI,MAAM,EAAE;QACzB,MAAM,cAAc,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;QAC1C,MAAM,GAAG,GAAG,IAAA,qBAAa,EAAC,OAAO,EAAE,cAAc,CAAC,CAAC;QACnD,MAAM,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC3B,IAAI,GAAG,EAAE;YACP,aAAa,CAAC,cAAc,CAAC,GAAG;gBAC9B,WAAW,EAAE,GAAG,CAAC,WAAW;gBAC5B,KAAK,EAAE,OAAO;gBACd,OAAO,EAAE,cAAc;aACxB,CAAC;SACH;aAAM;YACL,aAAa,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;SACpC;KACF;IAED,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,CAAC;AAC1C,CAAC,CAAC;AA3BW,QAAA,cAAc,kBA2BzB","sourcesContent":["import { bytesToHex } from '@noble/hashes/utils';\nimport { sha256 } from 'ethereum-cryptography/sha256';\n\nimport type { Hotlist, PhishingListState } from './PhishingController';\nimport { ListKeys, phishingListKeyNameMap } from './PhishingController';\nimport type {\n PhishingDetectorList,\n PhishingDetectorConfiguration,\n} from './PhishingDetector';\nimport {\n DEFAULT_CHAIN_ID_TO_NAME,\n type TokenScanCacheData,\n type TokenScanResult,\n} from './types';\n\nconst DEFAULT_TOLERANCE = 3;\n\n/**\n * Fetches current epoch time in seconds.\n *\n * @returns the Date.now() time in seconds instead of miliseconds. backend files rely on timestamps in seconds since epoch.\n */\nexport const fetchTimeNow = (): number => Math.round(Date.now() / 1000);\n\n/**\n * Rounds a Unix timestamp down to the nearest minute.\n *\n * @param unixTimestamp - The Unix timestamp to be rounded.\n * @returns The rounded Unix timestamp.\n */\nexport function roundToNearestMinute(unixTimestamp: number): number {\n return Math.floor(unixTimestamp / 60) * 60;\n}\n\n/**\n * Split a string into two pieces, using the first period as the delimiter.\n *\n * @param stringToSplit - The string to split.\n * @returns An array of length two containing the beginning and end of the string.\n */\nconst splitStringByPeriod = <Start extends string, End extends string>(\n stringToSplit: `${Start}.${End}`,\n): [Start, End] => {\n const periodIndex = stringToSplit.indexOf('.');\n return [\n stringToSplit.slice(0, periodIndex) as Start,\n stringToSplit.slice(periodIndex + 1) as End,\n ];\n};\n\n/**\n * Determines which diffs are applicable to the listState, then applies those diffs.\n *\n * @param listState - the stalelist or the existing liststate that diffs will be applied to.\n * @param hotlistDiffs - the diffs to apply to the listState if valid.\n * @param listKey - the key associated with the input/output phishing list state.\n * @param recentlyAddedC2Domains - list of hashed C2 domains to add to the local c2 domain blocklist\n * @param recentlyRemovedC2Domains - list of hashed C2 domains to remove from the local c2 domain blocklist\n * @returns the new list state\n */\nexport const applyDiffs = (\n listState: PhishingListState,\n hotlistDiffs: Hotlist,\n listKey: ListKeys,\n recentlyAddedC2Domains: string[] = [],\n recentlyRemovedC2Domains: string[] = [],\n): PhishingListState => {\n // filter to remove diffs that were added before the lastUpdate time.\n // filter to remove diffs that aren't applicable to the specified list (by listKey).\n const diffsToApply = hotlistDiffs.filter(\n ({ timestamp, targetList }) =>\n timestamp > listState.lastUpdated &&\n splitStringByPeriod(targetList)[0] === listKey,\n );\n\n // the reason behind using latestDiffTimestamp as the lastUpdated time\n // is so that we can benefit server-side from memoization due to end client's\n // `GET /v1/diffSince/:timestamp` requests lining up with\n // our periodic updates (which create diffs at specific timestamps).\n let latestDiffTimestamp = listState.lastUpdated;\n\n const listSets = {\n allowlist: new Set(listState.allowlist),\n blocklist: new Set(listState.blocklist),\n fuzzylist: new Set(listState.fuzzylist),\n c2DomainBlocklist: new Set(listState.c2DomainBlocklist),\n };\n for (const { isRemoval, targetList, url, timestamp } of diffsToApply) {\n const targetListType = splitStringByPeriod(targetList)[1];\n if (timestamp > latestDiffTimestamp) {\n latestDiffTimestamp = timestamp;\n }\n if (isRemoval) {\n listSets[targetListType].delete(url);\n } else {\n listSets[targetListType].add(url);\n }\n }\n\n if (listKey === ListKeys.EthPhishingDetectConfig) {\n for (const hash of recentlyAddedC2Domains) {\n listSets.c2DomainBlocklist.add(hash);\n }\n for (const hash of recentlyRemovedC2Domains) {\n listSets.c2DomainBlocklist.delete(hash);\n }\n }\n\n return {\n c2DomainBlocklist: Array.from(listSets.c2DomainBlocklist),\n allowlist: Array.from(listSets.allowlist),\n blocklist: Array.from(listSets.blocklist),\n fuzzylist: Array.from(listSets.fuzzylist),\n version: listState.version,\n name: phishingListKeyNameMap[listKey],\n tolerance: listState.tolerance,\n lastUpdated: latestDiffTimestamp,\n };\n};\n\n/**\n * Validates the configuration object for the phishing detector.\n *\n * @param config - the configuration object to validate.\n * @throws an error if the configuration is invalid.\n */\nexport function validateConfig(\n config: unknown,\n): asserts config is PhishingListState {\n if (config === null || typeof config !== 'object') {\n throw new Error('Invalid config');\n }\n\n if ('tolerance' in config && !('fuzzylist' in config)) {\n throw new Error('Fuzzylist tolerance provided without fuzzylist');\n }\n\n if (\n 'name' in config &&\n (typeof config.name !== 'string' || config.name === '')\n ) {\n throw new Error(\"Invalid config parameter: 'name'\");\n }\n\n if (\n 'version' in config &&\n (!['number', 'string'].includes(typeof config.version) ||\n config.version === '')\n ) {\n throw new Error(\"Invalid config parameter: 'version'\");\n }\n}\n\n/**\n * Converts a domain string to a list of domain parts.\n *\n * @param domain - the domain string to convert.\n * @returns the list of domain parts.\n */\nexport const domainToParts = (domain: string) => {\n try {\n return domain.split('.').reverse();\n } catch (e) {\n throw new Error(JSON.stringify(domain));\n }\n};\n\n/**\n * Converts a list of domain strings to a list of domain parts.\n *\n * @param list - the list of domain strings to convert.\n * @returns the list of domain parts.\n */\nexport const processDomainList = (list: string[]) => {\n return list.map(domainToParts);\n};\n\n/**\n * Gets the default phishing detector configuration.\n *\n * @param override - the optional override for the configuration.\n * @param override.allowlist - the optional allowlist to override.\n * @param override.blocklist - the optional blocklist to override.\n * @param override.c2DomainBlocklist - the optional c2DomainBlocklist to override.\n * @param override.fuzzylist - the optional fuzzylist to override.\n * @param override.tolerance - the optional tolerance to override.\n * @returns the default phishing detector configuration.\n */\nexport const getDefaultPhishingDetectorConfig = ({\n allowlist = [],\n blocklist = [],\n fuzzylist = [],\n tolerance = DEFAULT_TOLERANCE,\n}: {\n allowlist?: string[];\n blocklist?: string[];\n c2DomainBlocklist?: string[];\n fuzzylist?: string[];\n tolerance?: number;\n}): PhishingDetectorConfiguration => ({\n allowlist: processDomainList(allowlist),\n blocklist: processDomainList(blocklist),\n fuzzylist: processDomainList(fuzzylist),\n tolerance,\n});\n\n/**\n * Processes the configurations for the phishing detector, filtering out any invalid configs.\n *\n * @param configs - The configurations to process.\n * @returns An array of processed and valid configurations.\n */\nexport const processConfigs = (\n configs: PhishingDetectorList[] = [],\n): PhishingDetectorConfiguration[] => {\n return configs\n .filter((config) => {\n try {\n validateConfig(config);\n return true;\n } catch (error) {\n console.error(error);\n return false;\n }\n })\n .map((config) => ({\n ...config,\n ...getDefaultPhishingDetectorConfig(config),\n }));\n};\n\n/**\n * Converts a list of domain parts to a domain string.\n *\n * @param domainParts - the list of domain parts.\n * @returns the domain string.\n */\nexport const domainPartsToDomain = (domainParts: string[]) => {\n return domainParts.slice().reverse().join('.');\n};\n\n/**\n * Converts a list of domain parts to a fuzzy form.\n *\n * @param domainParts - the list of domain parts.\n * @returns the fuzzy form of the domain.\n */\nexport const domainPartsToFuzzyForm = (domainParts: string[]) => {\n return domainParts.slice(1).reverse().join('.');\n};\n\n/**\n * Matches the target parts, ignoring extra subdomains on source.\n *\n * @param source - the source domain parts.\n * @param list - the list of domain parts to match against.\n * @returns the parts for the first found matching entry.\n */\nexport const matchPartsAgainstList = (source: string[], list: string[][]) => {\n return list.find((target) => {\n // target domain has more parts than source, fail\n if (target.length > source.length) {\n return false;\n }\n // source matches target or (is deeper subdomain)\n return target.every((part, index) => source[index] === part);\n });\n};\n\n/**\n * Generate the SHA-256 hash of a hostname.\n *\n * @param hostname - The hostname to hash.\n * @returns The SHA-256 hash of the hostname.\n */\nexport const sha256Hash = (hostname: string): string => {\n const hashBuffer = sha256(new TextEncoder().encode(hostname.toLowerCase()));\n return bytesToHex(hashBuffer);\n};\n\n/**\n * Extracts the hostname from a URL.\n *\n * @param url - The URL to extract the hostname from.\n * @returns The hostname extracted from the URL, or null if the URL is invalid.\n */\nexport const getHostnameFromUrl = (url: string): string | null => {\n let hostname;\n try {\n hostname = new URL(url).hostname;\n // above will not throw if 'http://.' is passed. in fact, any string with a dot will pass.\n if (!hostname || hostname.split('.').join('') === '') {\n return null;\n }\n } catch {\n return null;\n }\n return hostname;\n};\n\n/**\n * getHostnameFromWebUrl returns the hostname from a web URL.\n * It returns the hostname and a boolean indicating if the hostname is valid.\n *\n * @param url - The web URL to extract the hostname from.\n * @returns A tuple containing the extracted hostname and a boolean indicating if the hostname is valid.\n * @example\n * getHostnameFromWebUrl('https://example.com') // Returns: ['example.com', true]\n * getHostnameFromWebUrl('example.com') // Returns: ['', false]\n * getHostnameFromWebUrl('https://') // Returns: ['', false]\n * getHostnameFromWebUrl('') // Returns: ['', false]\n */\nexport const getHostnameFromWebUrl = (url: string): [string, boolean] => {\n if (\n !url.toLowerCase().startsWith('http://') &&\n !url.toLowerCase().startsWith('https://')\n ) {\n return ['', false];\n }\n\n const hostname = getHostnameFromUrl(url);\n return [hostname || '', Boolean(hostname)];\n};\n\n/**\n * Generates all possible parent domains up to a specified limit.\n *\n * @param sourceParts - The list of domain parts in normal order (e.g., ['evil', 'domain', 'co', 'uk']).\n * @param limit - The maximum number of parent domains to generate (default is 5).\n * @returns An array of parent domains starting from the base TLD to the most specific subdomain.\n * @example\n * generateParentDomains(['evil', 'domain', 'co', 'uk'], 5)\n * // Returns: ['co.uk', 'domain.co.uk', 'evil.domain.co.uk']\n *\n * generateParentDomains(['uk'], 5)\n * // Returns: ['uk']\n *\n * generateParentDomains(['sub', 'example', 'com'], 5)\n * // Returns: ['example.com', 'sub.example.com']\n */\nexport const generateParentDomains = (\n sourceParts: string[],\n limit = 5,\n): string[] => {\n const domains: string[] = [];\n\n if (sourceParts.length === 0) {\n return domains;\n }\n\n if (sourceParts.length === 1) {\n // Single-segment hostname (e.g., 'uk')\n domains.push(sourceParts[0].toLowerCase());\n } else {\n // Start with the base domain or TLD (last two labels, e.g., 'co.uk' or 'example.com')\n const baseDomain = sourceParts.slice(-2).join('.');\n domains.push(baseDomain.toLowerCase());\n\n // Iteratively add one subdomain level at a time, up to the specified limit\n for (\n let i = sourceParts.length - 3;\n i >= 0 && domains.length < limit;\n i--\n ) {\n const domain = sourceParts.slice(i).join('.');\n domains.push(domain.toLowerCase());\n }\n }\n\n return domains;\n};\n\n/**\n * Builds a cache key for a token scan result.\n *\n * @param chainId - The chain ID.\n * @param address - The token address.\n * @returns The cache key.\n */\nexport const buildCacheKey = (chainId: string, address: string) => {\n return `${chainId.toLowerCase()}:${address.toLowerCase()}`;\n};\n\n/**\n * Resolves the chain name from a chain ID.\n *\n * @param chainId - The chain ID.\n * @param mapping - The mapping of chain IDs to chain names.\n * @returns The chain name.\n */\nexport const resolveChainName = (\n chainId: string,\n mapping = DEFAULT_CHAIN_ID_TO_NAME,\n): string | null => {\n return mapping[chainId.toLowerCase() as keyof typeof mapping] ?? null;\n};\n\n/**\n * Split tokens into cached results and tokens that need to be fetched.\n *\n * @param cache - Cache-like object with get method.\n * @param cache.get - Method to retrieve cached data by key.\n * @param chainId - The chain ID.\n * @param tokens - Array of token addresses.\n * @returns Object containing cached results and tokens to fetch.\n */\nexport const splitCacheHits = (\n cache: { get: (key: string) => TokenScanCacheData | undefined },\n chainId: string,\n tokens: string[],\n): {\n cachedResults: Record<string, TokenScanResult>;\n tokensToFetch: string[];\n} => {\n const cachedResults: Record<string, TokenScanResult> = {};\n const tokensToFetch: string[] = [];\n\n for (const addr of tokens) {\n const normalizedAddr = addr.toLowerCase();\n const key = buildCacheKey(chainId, normalizedAddr);\n const hit = cache.get(key);\n if (hit) {\n cachedResults[normalizedAddr] = {\n result_type: hit.result_type,\n chain: chainId,\n address: normalizedAddr,\n };\n } else {\n tokensToFetch.push(normalizedAddr);\n }\n }\n\n return { cachedResults, tokensToFetch };\n};\n"]}
|