@metamask-previews/phishing-controller 13.1.0-preview-8ccfcb37 → 14.0.0-preview-a5441fae
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 +8 -1
- package/dist/PhishingController.cjs +56 -2
- package/dist/PhishingController.cjs.map +1 -1
- package/dist/PhishingController.d.cts +10 -1
- package/dist/PhishingController.d.cts.map +1 -1
- package/dist/PhishingController.d.mts +10 -1
- package/dist/PhishingController.d.mts.map +1 -1
- package/dist/PhishingController.mjs +56 -2
- package/dist/PhishingController.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/package.json +5 -1
package/dist/tests/utils.d.mts
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
import type { TransactionMeta } from "@metamask/transaction-controller";
|
2
|
+
import { SimulationTokenStandard } from "@metamask/transaction-controller";
|
1
3
|
/**
|
2
4
|
* Formats a hostname into a URL so we can parse it correctly
|
3
5
|
* and pass full URLs into the PhishingDetector class. Previously
|
@@ -8,4 +10,61 @@
|
|
8
10
|
* @returns the href property of a URL object.
|
9
11
|
*/
|
10
12
|
export declare const formatHostnameToUrl: (hostname: string) => string;
|
13
|
+
/**
|
14
|
+
* Test addresses for consistent use in tests
|
15
|
+
*/
|
16
|
+
export declare const TEST_ADDRESSES: {
|
17
|
+
MOCK_TOKEN_1: `0x${string}`;
|
18
|
+
USDC: `0x${string}`;
|
19
|
+
FROM_ADDRESS: `0x${string}`;
|
20
|
+
TO_ADDRESS: `0x${string}`;
|
21
|
+
};
|
22
|
+
/**
|
23
|
+
* Creates a mock token balance change object
|
24
|
+
*
|
25
|
+
* @param address - The address of the token
|
26
|
+
* @param options - The options for the token balance change
|
27
|
+
* @param options.difference - The difference in the token balance
|
28
|
+
* @param options.previousBalance - The previous balance of the token
|
29
|
+
* @param options.newBalance - The new balance of the token
|
30
|
+
* @param options.isDecrease - Whether the token balance is decreasing
|
31
|
+
* @param options.standard - The standard of the token
|
32
|
+
* @returns The mock token balance change object
|
33
|
+
*/
|
34
|
+
export declare const createMockTokenBalanceChange: (address: `0x${string}`, options?: {
|
35
|
+
difference?: `0x${string}`;
|
36
|
+
previousBalance?: `0x${string}`;
|
37
|
+
newBalance?: `0x${string}`;
|
38
|
+
isDecrease?: boolean;
|
39
|
+
standard?: SimulationTokenStandard;
|
40
|
+
}) => {
|
41
|
+
address: `0x${string}`;
|
42
|
+
standard: SimulationTokenStandard;
|
43
|
+
difference: `0x${string}`;
|
44
|
+
previousBalance: `0x${string}`;
|
45
|
+
newBalance: `0x${string}`;
|
46
|
+
isDecrease: boolean;
|
47
|
+
};
|
48
|
+
/**
|
49
|
+
* Creates a mock transaction with token balance changes
|
50
|
+
*
|
51
|
+
* @param id - The transaction ID
|
52
|
+
* @param tokenAddresses - Array of token addresses to include in balance changes
|
53
|
+
* @param overrides - Partial transaction metadata to override defaults
|
54
|
+
* @returns The mock transaction metadata object
|
55
|
+
*/
|
56
|
+
export declare const createMockTransaction: (id: string, tokenAddresses?: `0x${string}`[], overrides?: Partial<TransactionMeta>) => TransactionMeta;
|
57
|
+
/**
|
58
|
+
* Creates a mock state change payload for TransactionController
|
59
|
+
*
|
60
|
+
* @param transactions - The transactions to include in the state change payload.
|
61
|
+
* @returns A mock state change payload.
|
62
|
+
*/
|
63
|
+
export declare const createMockStateChangePayload: (transactions: TransactionMeta[]) => {
|
64
|
+
transactions: TransactionMeta[];
|
65
|
+
transactionBatches: never[];
|
66
|
+
methodData: {};
|
67
|
+
lastFetchedBlockNumbers: {};
|
68
|
+
submitHistory: never[];
|
69
|
+
};
|
11
70
|
//# sourceMappingURL=utils.d.mts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"utils.d.mts","sourceRoot":"","sources":["../../src/tests/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,eAAO,MAAM,mBAAmB,aAAc,MAAM,KAAG,MAQtD,CAAC"}
|
1
|
+
{"version":3,"file":"utils.d.mts","sourceRoot":"","sources":["../../src/tests/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,yCAAyC;AACxE,OAAO,EAGL,uBAAuB,EACxB,yCAAyC;AAE1C;;;;;;;;GAQG;AACH,eAAO,MAAM,mBAAmB,aAAc,MAAM,KAAG,MAQtD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,cAAc;;;;;CAK1B,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,4BAA4B,YAC9B,KAAK,MAAM,EAAE,YACb;IACP,UAAU,CAAC,EAAE,KAAK,MAAM,EAAE,CAAC;IAC3B,eAAe,CAAC,EAAE,KAAK,MAAM,EAAE,CAAC;IAChC,UAAU,CAAC,EAAE,KAAK,MAAM,EAAE,CAAC;IAC3B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,QAAQ,CAAC,EAAE,uBAAuB,CAAC;CACpC;;;;;;;CAQD,CAAC;AAEH;;;;;;;GAOG;AACH,eAAO,MAAM,qBAAqB,OAC5B,MAAM,mBACM,KAAK,MAAM,EAAE,EAAE,cACpB,QAAQ,eAAe,CAAC,KAClC,eA2BF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,4BAA4B,iBACzB,eAAe,EAAE;;;;;;CAO/B,CAAC"}
|
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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AAE,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/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@metamask-previews/phishing-controller",
|
3
|
-
"version": "
|
3
|
+
"version": "14.0.0-preview-a5441fae",
|
4
4
|
"description": "Maintains a periodically updated list of approved and unapproved website origins",
|
5
5
|
"keywords": [
|
6
6
|
"MetaMask",
|
@@ -57,6 +57,7 @@
|
|
57
57
|
},
|
58
58
|
"devDependencies": {
|
59
59
|
"@metamask/auto-changelog": "^3.4.4",
|
60
|
+
"@metamask/transaction-controller": "^60.4.0",
|
60
61
|
"@types/jest": "^27.4.1",
|
61
62
|
"deepmerge": "^4.2.2",
|
62
63
|
"jest": "^27.5.1",
|
@@ -67,6 +68,9 @@
|
|
67
68
|
"typedoc-plugin-missing-exports": "^2.0.0",
|
68
69
|
"typescript": "~5.2.2"
|
69
70
|
},
|
71
|
+
"peerDependencies": {
|
72
|
+
"@metamask/transaction-controller": "^60.4.0"
|
73
|
+
},
|
70
74
|
"engines": {
|
71
75
|
"node": "^18.18 || >=20"
|
72
76
|
},
|