@metamask-previews/phishing-controller 18.3.1-preview-cf24e3cc8 → 18.3.1-preview-2da314d6d
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 +11 -0
- package/dist/SecurityAlertsApiService-method-action-types.d.ts +35 -0
- package/dist/SecurityAlertsApiService-method-action-types.d.ts.map +1 -0
- package/dist/SecurityAlertsApiService-method-action-types.js +6 -0
- package/dist/SecurityAlertsApiService-method-action-types.js.map +1 -0
- package/dist/SecurityAlertsApiService.d.ts +67 -0
- package/dist/SecurityAlertsApiService.d.ts.map +1 -0
- package/dist/SecurityAlertsApiService.js +124 -0
- package/dist/SecurityAlertsApiService.js.map +1 -0
- package/dist/approval-dashboard.d.ts +569 -0
- package/dist/approval-dashboard.d.ts.map +1 -0
- package/dist/approval-dashboard.js +203 -0
- package/dist/approval-dashboard.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/package.json +4 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Add `SecurityAlertsApiService`, a data service for the Security Alerts API, with a `getApprovalDashboard` method and `SecurityAlertsApiService:getApprovalDashboard` messenger action for the multi-chain approval inventory (`POST /approvals/dashboard`) ([#11628](https://github.com/MetaMask/core/pull/11628))
|
|
13
|
+
- Takes `{ address, chainIds, forceFresh? }`; `chainIds` are hex strings (at most 20 distinct) and are sent to the API as decimal numbers.
|
|
14
|
+
- Validates the response against schema major `0` and passes unknown fields through. Unknown chain statuses become `failed` + `unverified`; unknown risk verdicts become `unknown`.
|
|
15
|
+
- Rejects with `ApprovalDashboardError` (`code`, `retryable`, `httpStatus`) on invalid input, HTTP/network failure, timeout, open circuit, or an invalid/incompatible response; it never resolves to an empty inventory on failure.
|
|
16
|
+
- Identical concurrent calls share one HTTP request, bounded by a 15-second timeout.
|
|
17
|
+
- Constructor accepts `messenger`, `fetch`, `baseUrl`, and `policyOptions` (retries are off by default).
|
|
18
|
+
- Export `SecurityAlertsApiService`, its messenger, action, event, and options types, `ApprovalDashboardError`, and the `ApprovalDashboardRequest`, `ApprovalDashboardResponse`, `ApprovalDashboardRecord`, `ApprovalDashboardChainResult` and `ApprovalDashboardErrorCode` types.
|
|
19
|
+
- Add `@metamask/base-data-service` `^2.1.0`, `@metamask/superstruct` `^3.4.1` and `@metamask/utils` `^12.0.2` dependencies ([#11628](https://github.com/MetaMask/core/pull/11628))
|
|
20
|
+
|
|
10
21
|
### Changed
|
|
11
22
|
|
|
12
23
|
- Bump `@metamask/transaction-controller` from `^74.0.0` to `^74.2.0` ([#11579](https://github.com/MetaMask/core/pull/11579), [#11605](https://github.com/MetaMask/core/pull/11605))
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is auto generated.
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
*/
|
|
5
|
+
import type { SecurityAlertsApiService } from './SecurityAlertsApiService.js';
|
|
6
|
+
/**
|
|
7
|
+
* Get the normalized multi-chain token approval inventory for an account
|
|
8
|
+
* (`POST /approvals/dashboard`).
|
|
9
|
+
*
|
|
10
|
+
* Failures are never reported as an empty inventory: the call rejects with
|
|
11
|
+
* an `ApprovalDashboardError`. A resolved response carries per-chain status
|
|
12
|
+
* and completeness in `chainResults`; a chain that is not `verified` must
|
|
13
|
+
* not be shown as having no approvals.
|
|
14
|
+
*
|
|
15
|
+
* There is no per-call cancellation: identical concurrent calls share one
|
|
16
|
+
* request, bounded by a 15-second timeout. Callers that no longer need a
|
|
17
|
+
* response (e.g. after an account or network switch) should discard it.
|
|
18
|
+
*
|
|
19
|
+
* @param request - The dashboard request.
|
|
20
|
+
* @param request.address - The EVM account address.
|
|
21
|
+
* @param request.chainIds - Hex chain IDs (e.g. `'0x1'`); at most 20
|
|
22
|
+
* distinct.
|
|
23
|
+
* @param request.forceFresh - Ask the server to bypass the allowance cache.
|
|
24
|
+
* The server may throttle this; see `freshness.forced` on the response.
|
|
25
|
+
* @returns The validated approval inventory.
|
|
26
|
+
*/
|
|
27
|
+
export type SecurityAlertsApiServiceGetApprovalDashboardAction = {
|
|
28
|
+
type: `SecurityAlertsApiService:getApprovalDashboard`;
|
|
29
|
+
handler: SecurityAlertsApiService['getApprovalDashboard'];
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Union of all SecurityAlertsApiService action types.
|
|
33
|
+
*/
|
|
34
|
+
export type SecurityAlertsApiServiceMethodActions = SecurityAlertsApiServiceGetApprovalDashboardAction;
|
|
35
|
+
//# sourceMappingURL=SecurityAlertsApiService-method-action-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SecurityAlertsApiService-method-action-types.d.ts","sourceRoot":"","sources":["../src/SecurityAlertsApiService-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAE9E;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,MAAM,kDAAkD,GAAG;IAC/D,IAAI,EAAE,+CAA+C,CAAC;IACtD,OAAO,EAAE,wBAAwB,CAAC,sBAAsB,CAAC,CAAC;CAC3D,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,qCAAqC,GAC/C,kDAAkD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SecurityAlertsApiService-method-action-types.js","sourceRoot":"","sources":["../src/SecurityAlertsApiService-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { SecurityAlertsApiService } from './SecurityAlertsApiService.js';\n\n/**\n * Get the normalized multi-chain token approval inventory for an account\n * (`POST /approvals/dashboard`).\n *\n * Failures are never reported as an empty inventory: the call rejects with\n * an `ApprovalDashboardError`. A resolved response carries per-chain status\n * and completeness in `chainResults`; a chain that is not `verified` must\n * not be shown as having no approvals.\n *\n * There is no per-call cancellation: identical concurrent calls share one\n * request, bounded by a 15-second timeout. Callers that no longer need a\n * response (e.g. after an account or network switch) should discard it.\n *\n * @param request - The dashboard request.\n * @param request.address - The EVM account address.\n * @param request.chainIds - Hex chain IDs (e.g. `'0x1'`); at most 20\n * distinct.\n * @param request.forceFresh - Ask the server to bypass the allowance cache.\n * The server may throttle this; see `freshness.forced` on the response.\n * @returns The validated approval inventory.\n */\nexport type SecurityAlertsApiServiceGetApprovalDashboardAction = {\n type: `SecurityAlertsApiService:getApprovalDashboard`;\n handler: SecurityAlertsApiService['getApprovalDashboard'];\n};\n\n/**\n * Union of all SecurityAlertsApiService action types.\n */\nexport type SecurityAlertsApiServiceMethodActions =\n SecurityAlertsApiServiceGetApprovalDashboardAction;\n"]}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { BaseDataService } from '@metamask/base-data-service';
|
|
2
|
+
import type { CreateServicePolicyOptions, DataServiceCacheUpdatedEvent, DataServiceGranularCacheUpdatedEvent, DataServiceInvalidateQueriesAction } from '@metamask/base-data-service';
|
|
3
|
+
import type { Messenger } from '@metamask/messenger';
|
|
4
|
+
import type { ApprovalDashboardRequest, ApprovalDashboardResponse } from './approval-dashboard.js';
|
|
5
|
+
import type { SecurityAlertsApiServiceMethodActions } from './SecurityAlertsApiService-method-action-types.js';
|
|
6
|
+
export declare const serviceName = "SecurityAlertsApiService";
|
|
7
|
+
export declare const APPROVAL_DASHBOARD_ENDPOINT = "/approvals/dashboard";
|
|
8
|
+
/** Per-attempt deadline. SAA bounds its own upstream work at 8 seconds. */
|
|
9
|
+
export declare const APPROVAL_DASHBOARD_TIMEOUT_MS = 15000;
|
|
10
|
+
export type SecurityAlertsApiServiceActions = SecurityAlertsApiServiceMethodActions | DataServiceInvalidateQueriesAction<typeof serviceName>;
|
|
11
|
+
export type SecurityAlertsApiServiceEvents = DataServiceCacheUpdatedEvent<typeof serviceName> | DataServiceGranularCacheUpdatedEvent<typeof serviceName>;
|
|
12
|
+
export type SecurityAlertsApiServiceMessenger = Messenger<typeof serviceName, SecurityAlertsApiServiceActions, SecurityAlertsApiServiceEvents>;
|
|
13
|
+
export type SecurityAlertsApiServiceOptions = {
|
|
14
|
+
/** The messenger suited for this service. */
|
|
15
|
+
messenger: SecurityAlertsApiServiceMessenger;
|
|
16
|
+
/** The `fetch` function to use for requests. Defaults to the global `fetch`. */
|
|
17
|
+
fetch?: typeof fetch;
|
|
18
|
+
/** Security Alerts API base URL. Defaults to production. */
|
|
19
|
+
baseUrl?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Options to pass to `createServicePolicy`. Retries are disabled by default
|
|
22
|
+
* (`maxRetries: 0`); when enabled, only errors with `retryable: true` are
|
|
23
|
+
* retried.
|
|
24
|
+
*/
|
|
25
|
+
policyOptions?: CreateServicePolicyOptions;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Data service for the MetaMask Security Alerts API
|
|
29
|
+
* (`security-alerts.api.cx.metamask.io`).
|
|
30
|
+
*/
|
|
31
|
+
export declare class SecurityAlertsApiService extends BaseDataService<typeof serviceName, SecurityAlertsApiServiceMessenger> {
|
|
32
|
+
#private;
|
|
33
|
+
/**
|
|
34
|
+
* Constructs a new SecurityAlertsApiService.
|
|
35
|
+
*
|
|
36
|
+
* @param options - The constructor options. See
|
|
37
|
+
* {@link SecurityAlertsApiServiceOptions}.
|
|
38
|
+
* @param options.messenger - The messenger suited for this service.
|
|
39
|
+
* @param options.fetch - The `fetch` function to use for requests.
|
|
40
|
+
* @param options.baseUrl - The Security Alerts API base URL.
|
|
41
|
+
* @param options.policyOptions - Options to pass to `createServicePolicy`.
|
|
42
|
+
*/
|
|
43
|
+
constructor({ messenger, fetch: fetchFunction, baseUrl, policyOptions, }: SecurityAlertsApiServiceOptions);
|
|
44
|
+
/**
|
|
45
|
+
* Get the normalized multi-chain token approval inventory for an account
|
|
46
|
+
* (`POST /approvals/dashboard`).
|
|
47
|
+
*
|
|
48
|
+
* Failures are never reported as an empty inventory: the call rejects with
|
|
49
|
+
* an `ApprovalDashboardError`. A resolved response carries per-chain status
|
|
50
|
+
* and completeness in `chainResults`; a chain that is not `verified` must
|
|
51
|
+
* not be shown as having no approvals.
|
|
52
|
+
*
|
|
53
|
+
* There is no per-call cancellation: identical concurrent calls share one
|
|
54
|
+
* request, bounded by a 15-second timeout. Callers that no longer need a
|
|
55
|
+
* response (e.g. after an account or network switch) should discard it.
|
|
56
|
+
*
|
|
57
|
+
* @param request - The dashboard request.
|
|
58
|
+
* @param request.address - The EVM account address.
|
|
59
|
+
* @param request.chainIds - Hex chain IDs (e.g. `'0x1'`); at most 20
|
|
60
|
+
* distinct.
|
|
61
|
+
* @param request.forceFresh - Ask the server to bypass the allowance cache.
|
|
62
|
+
* The server may throttle this; see `freshness.forced` on the response.
|
|
63
|
+
* @returns The validated approval inventory.
|
|
64
|
+
*/
|
|
65
|
+
getApprovalDashboard(request: ApprovalDashboardRequest): Promise<ApprovalDashboardResponse>;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=SecurityAlertsApiService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SecurityAlertsApiService.d.ts","sourceRoot":"","sources":["../src/SecurityAlertsApiService.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EAGhB,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EACV,0BAA0B,EAC1B,4BAA4B,EAC5B,oCAAoC,EACpC,kCAAkC,EACnC,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AASrD,OAAO,KAAK,EACV,wBAAwB,EACxB,yBAAyB,EAC1B,MAAM,yBAAyB,CAAC;AAEjC,OAAO,KAAK,EAAE,qCAAqC,EAAE,MAAM,mDAAmD,CAAC;AAE/G,eAAO,MAAM,WAAW,6BAA6B,CAAC;AAEtD,eAAO,MAAM,2BAA2B,yBAAyB,CAAC;AAElE,2EAA2E;AAC3E,eAAO,MAAM,6BAA6B,QAAS,CAAC;AAIpD,MAAM,MAAM,+BAA+B,GACvC,qCAAqC,GACrC,kCAAkC,CAAC,OAAO,WAAW,CAAC,CAAC;AAE3D,MAAM,MAAM,8BAA8B,GACtC,4BAA4B,CAAC,OAAO,WAAW,CAAC,GAChD,oCAAoC,CAAC,OAAO,WAAW,CAAC,CAAC;AAE7D,MAAM,MAAM,iCAAiC,GAAG,SAAS,CACvD,OAAO,WAAW,EAClB,+BAA+B,EAC/B,8BAA8B,CAC/B,CAAC;AAEF,MAAM,MAAM,+BAA+B,GAAG;IAC5C,6CAA6C;IAC7C,SAAS,EAAE,iCAAiC,CAAC;IAC7C,gFAAgF;IAChF,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IACrB,4DAA4D;IAC5D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,aAAa,CAAC,EAAE,0BAA0B,CAAC;CAC5C,CAAC;AAEF;;;GAGG;AACH,qBAAa,wBAAyB,SAAQ,eAAe,CAC3D,OAAO,WAAW,EAClB,iCAAiC,CAClC;;IAKC;;;;;;;;;OASG;IACH,YAAY,EACV,SAAS,EACT,KAAK,EAAE,aAAgC,EACvC,OAAkC,EAClC,aAAkB,GACnB,EAAE,+BAA+B,EAoBjC;IAED;;;;;;;;;;;;;;;;;;;;OAoBG;IACG,oBAAoB,CACxB,OAAO,EAAE,wBAAwB,GAChC,OAAO,CAAC,yBAAyB,CAAC,CAuBpC;CAqEF"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { BaseDataService, BrokenCircuitError, handleWhen, } from '@metamask/base-data-service';
|
|
2
|
+
import { ApprovalDashboardError, buildApprovalDashboardRequestBody, invalidApprovalDashboardResponse, parseApprovalDashboardResponse, } from './approval-dashboard.js';
|
|
3
|
+
import { SECURITY_ALERTS_BASE_URL } from './PhishingController.js';
|
|
4
|
+
export const serviceName = 'SecurityAlertsApiService';
|
|
5
|
+
export const APPROVAL_DASHBOARD_ENDPOINT = '/approvals/dashboard';
|
|
6
|
+
/** Per-attempt deadline. SAA bounds its own upstream work at 8 seconds. */
|
|
7
|
+
export const APPROVAL_DASHBOARD_TIMEOUT_MS = 15_000;
|
|
8
|
+
const MESSENGER_EXPOSED_METHODS = ['getApprovalDashboard'];
|
|
9
|
+
/**
|
|
10
|
+
* Data service for the MetaMask Security Alerts API
|
|
11
|
+
* (`security-alerts.api.cx.metamask.io`).
|
|
12
|
+
*/
|
|
13
|
+
export class SecurityAlertsApiService extends BaseDataService {
|
|
14
|
+
#fetch;
|
|
15
|
+
#baseUrl;
|
|
16
|
+
/**
|
|
17
|
+
* Constructs a new SecurityAlertsApiService.
|
|
18
|
+
*
|
|
19
|
+
* @param options - The constructor options. See
|
|
20
|
+
* {@link SecurityAlertsApiServiceOptions}.
|
|
21
|
+
* @param options.messenger - The messenger suited for this service.
|
|
22
|
+
* @param options.fetch - The `fetch` function to use for requests.
|
|
23
|
+
* @param options.baseUrl - The Security Alerts API base URL.
|
|
24
|
+
* @param options.policyOptions - Options to pass to `createServicePolicy`.
|
|
25
|
+
*/
|
|
26
|
+
constructor({ messenger, fetch: fetchFunction = globalThis.fetch, baseUrl = SECURITY_ALERTS_BASE_URL, policyOptions = {}, }) {
|
|
27
|
+
super({
|
|
28
|
+
name: serviceName,
|
|
29
|
+
messenger,
|
|
30
|
+
policyOptions: {
|
|
31
|
+
maxRetries: 0,
|
|
32
|
+
retryFilterPolicy: handleWhen((error) => error instanceof ApprovalDashboardError && error.retryable),
|
|
33
|
+
...policyOptions,
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
this.#fetch = fetchFunction;
|
|
37
|
+
this.#baseUrl = baseUrl;
|
|
38
|
+
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Get the normalized multi-chain token approval inventory for an account
|
|
42
|
+
* (`POST /approvals/dashboard`).
|
|
43
|
+
*
|
|
44
|
+
* Failures are never reported as an empty inventory: the call rejects with
|
|
45
|
+
* an `ApprovalDashboardError`. A resolved response carries per-chain status
|
|
46
|
+
* and completeness in `chainResults`; a chain that is not `verified` must
|
|
47
|
+
* not be shown as having no approvals.
|
|
48
|
+
*
|
|
49
|
+
* There is no per-call cancellation: identical concurrent calls share one
|
|
50
|
+
* request, bounded by a 15-second timeout. Callers that no longer need a
|
|
51
|
+
* response (e.g. after an account or network switch) should discard it.
|
|
52
|
+
*
|
|
53
|
+
* @param request - The dashboard request.
|
|
54
|
+
* @param request.address - The EVM account address.
|
|
55
|
+
* @param request.chainIds - Hex chain IDs (e.g. `'0x1'`); at most 20
|
|
56
|
+
* distinct.
|
|
57
|
+
* @param request.forceFresh - Ask the server to bypass the allowance cache.
|
|
58
|
+
* The server may throttle this; see `freshness.forced` on the response.
|
|
59
|
+
* @returns The validated approval inventory.
|
|
60
|
+
*/
|
|
61
|
+
async getApprovalDashboard(request) {
|
|
62
|
+
const body = buildApprovalDashboardRequestBody(request);
|
|
63
|
+
const response = await this.fetchQuery({
|
|
64
|
+
queryKey: [`${this.name}:getApprovalDashboard`, body],
|
|
65
|
+
staleTime: 0,
|
|
66
|
+
queryFn: async () => parseApprovalDashboardResponse(await this.#postApprovalDashboard(body), body),
|
|
67
|
+
}).catch((error) => {
|
|
68
|
+
if (error instanceof BrokenCircuitError) {
|
|
69
|
+
throw new ApprovalDashboardError('service_unavailable', 'Security Alerts API is temporarily unavailable', { retryable: true, cause: error });
|
|
70
|
+
}
|
|
71
|
+
throw error;
|
|
72
|
+
});
|
|
73
|
+
return response;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* POST the request body, enforcing the per-attempt deadline.
|
|
77
|
+
*
|
|
78
|
+
* @param body - The SAA request body.
|
|
79
|
+
* @returns The parsed JSON body.
|
|
80
|
+
*/
|
|
81
|
+
async #postApprovalDashboard(body) {
|
|
82
|
+
// A timer rather than `AbortSignal.timeout`, which React Native lacks.
|
|
83
|
+
const controller = new AbortController();
|
|
84
|
+
const timer = setTimeout(() => controller.abort(), APPROVAL_DASHBOARD_TIMEOUT_MS);
|
|
85
|
+
const transportError = (error) => controller.signal.aborted
|
|
86
|
+
? new ApprovalDashboardError('timeout', `Approval dashboard request timed out after ${APPROVAL_DASHBOARD_TIMEOUT_MS}ms`, { retryable: true, cause: error })
|
|
87
|
+
: new ApprovalDashboardError('network_error', 'Approval dashboard request failed', { retryable: true, cause: error });
|
|
88
|
+
try {
|
|
89
|
+
let response;
|
|
90
|
+
try {
|
|
91
|
+
response = await this.#fetch(`${this.#baseUrl}${APPROVAL_DASHBOARD_ENDPOINT}`, {
|
|
92
|
+
method: 'POST',
|
|
93
|
+
headers: {
|
|
94
|
+
Accept: 'application/json',
|
|
95
|
+
'Content-Type': 'application/json',
|
|
96
|
+
},
|
|
97
|
+
body: JSON.stringify(body),
|
|
98
|
+
signal: controller.signal,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
throw transportError(error);
|
|
103
|
+
}
|
|
104
|
+
if (!response.ok) {
|
|
105
|
+
throw new ApprovalDashboardError('http_error', `Approval dashboard request failed: ${response.status} ${response.statusText}`, {
|
|
106
|
+
httpStatus: response.status,
|
|
107
|
+
retryable: response.status === 429 || response.status >= 500,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
try {
|
|
111
|
+
return await response.json();
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
throw controller.signal.aborted
|
|
115
|
+
? transportError(error)
|
|
116
|
+
: invalidApprovalDashboardResponse('body is not valid JSON', error);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
finally {
|
|
120
|
+
clearTimeout(timer);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=SecurityAlertsApiService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SecurityAlertsApiService.js","sourceRoot":"","sources":["../src/SecurityAlertsApiService.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,UAAU,GACX,MAAM,6BAA6B,CAAC;AAUrC,OAAO,EACL,sBAAsB,EACtB,iCAAiC,EACjC,gCAAgC,EAChC,8BAA8B,GAC/B,MAAM,yBAAyB,CAAC;AAKjC,OAAO,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AAGnE,MAAM,CAAC,MAAM,WAAW,GAAG,0BAA0B,CAAC;AAEtD,MAAM,CAAC,MAAM,2BAA2B,GAAG,sBAAsB,CAAC;AAElE,2EAA2E;AAC3E,MAAM,CAAC,MAAM,6BAA6B,GAAG,MAAM,CAAC;AAEpD,MAAM,yBAAyB,GAAG,CAAC,sBAAsB,CAAU,CAAC;AA+BpE;;;GAGG;AACH,MAAM,OAAO,wBAAyB,SAAQ,eAG7C;IACU,MAAM,CAAe;IAErB,QAAQ,CAAS;IAE1B;;;;;;;;;OASG;IACH,YAAY,EACV,SAAS,EACT,KAAK,EAAE,aAAa,GAAG,UAAU,CAAC,KAAK,EACvC,OAAO,GAAG,wBAAwB,EAClC,aAAa,GAAG,EAAE,GACc;QAChC,KAAK,CAAC;YACJ,IAAI,EAAE,WAAW;YACjB,SAAS;YACT,aAAa,EAAE;gBACb,UAAU,EAAE,CAAC;gBACb,iBAAiB,EAAE,UAAU,CAC3B,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,YAAY,sBAAsB,IAAI,KAAK,CAAC,SAAS,CACtE;gBACD,GAAG,aAAa;aACjB;SACF,CAAC,CAAC;QAEH,IAAI,CAAC,MAAM,GAAG,aAAa,CAAC;QAC5B,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC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C;QACH,CAAC;gBAAS,CAAC;YACT,YAAY,CAAC,KAAK,CAAC,CAAC;QACtB,CAAC;IACH,CAAC;CACF","sourcesContent":["import {\n BaseDataService,\n BrokenCircuitError,\n handleWhen,\n} from '@metamask/base-data-service';\nimport type {\n CreateServicePolicyOptions,\n DataServiceCacheUpdatedEvent,\n DataServiceGranularCacheUpdatedEvent,\n DataServiceInvalidateQueriesAction,\n} from '@metamask/base-data-service';\nimport type { Messenger } from '@metamask/messenger';\nimport type { Json } from '@metamask/utils';\n\nimport {\n ApprovalDashboardError,\n buildApprovalDashboardRequestBody,\n invalidApprovalDashboardResponse,\n parseApprovalDashboardResponse,\n} from './approval-dashboard.js';\nimport type {\n ApprovalDashboardRequest,\n ApprovalDashboardResponse,\n} from './approval-dashboard.js';\nimport { SECURITY_ALERTS_BASE_URL } from './PhishingController.js';\nimport type { SecurityAlertsApiServiceMethodActions } from './SecurityAlertsApiService-method-action-types.js';\n\nexport const serviceName = 'SecurityAlertsApiService';\n\nexport const APPROVAL_DASHBOARD_ENDPOINT = '/approvals/dashboard';\n\n/** Per-attempt deadline. SAA bounds its own upstream work at 8 seconds. */\nexport const APPROVAL_DASHBOARD_TIMEOUT_MS = 15_000;\n\nconst MESSENGER_EXPOSED_METHODS = ['getApprovalDashboard'] as const;\n\nexport type SecurityAlertsApiServiceActions =\n | SecurityAlertsApiServiceMethodActions\n | DataServiceInvalidateQueriesAction<typeof serviceName>;\n\nexport type SecurityAlertsApiServiceEvents =\n | DataServiceCacheUpdatedEvent<typeof serviceName>\n | DataServiceGranularCacheUpdatedEvent<typeof serviceName>;\n\nexport type SecurityAlertsApiServiceMessenger = Messenger<\n typeof serviceName,\n SecurityAlertsApiServiceActions,\n SecurityAlertsApiServiceEvents\n>;\n\nexport type SecurityAlertsApiServiceOptions = {\n /** The messenger suited for this service. */\n messenger: SecurityAlertsApiServiceMessenger;\n /** The `fetch` function to use for requests. Defaults to the global `fetch`. */\n fetch?: typeof fetch;\n /** Security Alerts API base URL. Defaults to production. */\n baseUrl?: string;\n /**\n * Options to pass to `createServicePolicy`. Retries are disabled by default\n * (`maxRetries: 0`); when enabled, only errors with `retryable: true` are\n * retried.\n */\n policyOptions?: CreateServicePolicyOptions;\n};\n\n/**\n * Data service for the MetaMask Security Alerts API\n * (`security-alerts.api.cx.metamask.io`).\n */\nexport class SecurityAlertsApiService extends BaseDataService<\n typeof serviceName,\n SecurityAlertsApiServiceMessenger\n> {\n readonly #fetch: typeof fetch;\n\n readonly #baseUrl: string;\n\n /**\n * Constructs a new SecurityAlertsApiService.\n *\n * @param options - The constructor options. See\n * {@link SecurityAlertsApiServiceOptions}.\n * @param options.messenger - The messenger suited for this service.\n * @param options.fetch - The `fetch` function to use for requests.\n * @param options.baseUrl - The Security Alerts API base URL.\n * @param options.policyOptions - Options to pass to `createServicePolicy`.\n */\n constructor({\n messenger,\n fetch: fetchFunction = globalThis.fetch,\n baseUrl = SECURITY_ALERTS_BASE_URL,\n policyOptions = {},\n }: SecurityAlertsApiServiceOptions) {\n super({\n name: serviceName,\n messenger,\n policyOptions: {\n maxRetries: 0,\n retryFilterPolicy: handleWhen(\n (error) => error instanceof ApprovalDashboardError && error.retryable,\n ),\n ...policyOptions,\n },\n });\n\n this.#fetch = fetchFunction;\n this.#baseUrl = baseUrl;\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Get the normalized multi-chain token approval inventory for an account\n * (`POST /approvals/dashboard`).\n *\n * Failures are never reported as an empty inventory: the call rejects with\n * an `ApprovalDashboardError`. A resolved response carries per-chain status\n * and completeness in `chainResults`; a chain that is not `verified` must\n * not be shown as having no approvals.\n *\n * There is no per-call cancellation: identical concurrent calls share one\n * request, bounded by a 15-second timeout. Callers that no longer need a\n * response (e.g. after an account or network switch) should discard it.\n *\n * @param request - The dashboard request.\n * @param request.address - The EVM account address.\n * @param request.chainIds - Hex chain IDs (e.g. `'0x1'`); at most 20\n * distinct.\n * @param request.forceFresh - Ask the server to bypass the allowance cache.\n * The server may throttle this; see `freshness.forced` on the response.\n * @returns The validated approval inventory.\n */\n async getApprovalDashboard(\n request: ApprovalDashboardRequest,\n ): Promise<ApprovalDashboardResponse> {\n const body = buildApprovalDashboardRequestBody(request);\n\n const response = await this.fetchQuery({\n queryKey: [`${this.name}:getApprovalDashboard`, body],\n staleTime: 0,\n queryFn: async (): Promise<Json> =>\n parseApprovalDashboardResponse(\n await this.#postApprovalDashboard(body),\n body,\n ),\n }).catch((error: unknown) => {\n if (error instanceof BrokenCircuitError) {\n throw new ApprovalDashboardError(\n 'service_unavailable',\n 'Security Alerts API is temporarily unavailable',\n { retryable: true, cause: error },\n );\n }\n throw error;\n });\n\n return response as ApprovalDashboardResponse;\n }\n\n /**\n * POST the request body, enforcing the per-attempt deadline.\n *\n * @param body - The SAA request body.\n * @returns The parsed JSON body.\n */\n async #postApprovalDashboard(body: object): Promise<unknown> {\n // A timer rather than `AbortSignal.timeout`, which React Native lacks.\n const controller = new AbortController();\n const timer = setTimeout(\n () => controller.abort(),\n APPROVAL_DASHBOARD_TIMEOUT_MS,\n );\n const transportError = (error: unknown): ApprovalDashboardError =>\n controller.signal.aborted\n ? new ApprovalDashboardError(\n 'timeout',\n `Approval dashboard request timed out after ${APPROVAL_DASHBOARD_TIMEOUT_MS}ms`,\n { retryable: true, cause: error },\n )\n : new ApprovalDashboardError(\n 'network_error',\n 'Approval dashboard request failed',\n { retryable: true, cause: error },\n );\n\n try {\n let response: Response;\n try {\n response = await this.#fetch(\n `${this.#baseUrl}${APPROVAL_DASHBOARD_ENDPOINT}`,\n {\n method: 'POST',\n headers: {\n Accept: 'application/json',\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(body),\n signal: controller.signal,\n },\n );\n } catch (error) {\n throw transportError(error);\n }\n\n if (!response.ok) {\n throw new ApprovalDashboardError(\n 'http_error',\n `Approval dashboard request failed: ${response.status} ${response.statusText}`,\n {\n httpStatus: response.status,\n retryable: response.status === 429 || response.status >= 500,\n },\n );\n }\n\n try {\n return await response.json();\n } catch (error) {\n throw controller.signal.aborted\n ? transportError(error)\n : invalidApprovalDashboardResponse('body is not valid JSON', error);\n }\n } finally {\n clearTimeout(timer);\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,569 @@
|
|
|
1
|
+
import type { Infer } from '@metamask/superstruct';
|
|
2
|
+
/** Maximum number of distinct chain IDs per request (SAA limit). */
|
|
3
|
+
export declare const APPROVAL_DASHBOARD_MAX_CHAIN_IDS = 20;
|
|
4
|
+
declare const RecordStruct: import("@metamask/superstruct").Struct<{
|
|
5
|
+
id: string;
|
|
6
|
+
account: string;
|
|
7
|
+
chainId: number;
|
|
8
|
+
standard: "erc1155" | "erc20" | "erc721";
|
|
9
|
+
approvalKind: "allowance" | "operator";
|
|
10
|
+
tokenId: string | null;
|
|
11
|
+
token: {
|
|
12
|
+
address: string;
|
|
13
|
+
name: string;
|
|
14
|
+
symbol: string;
|
|
15
|
+
decimals: number | null;
|
|
16
|
+
logo: string | null;
|
|
17
|
+
metadataStatus: "complete" | "partial";
|
|
18
|
+
};
|
|
19
|
+
spender: {
|
|
20
|
+
address: string;
|
|
21
|
+
label: string | null;
|
|
22
|
+
labelSource: string | null;
|
|
23
|
+
};
|
|
24
|
+
allowance: {
|
|
25
|
+
raw: string;
|
|
26
|
+
isUnlimited: boolean;
|
|
27
|
+
};
|
|
28
|
+
exposure: {
|
|
29
|
+
amountUsd: string;
|
|
30
|
+
basis: "allowance" | "balance";
|
|
31
|
+
priceSource: string;
|
|
32
|
+
observedAt: string;
|
|
33
|
+
} | null;
|
|
34
|
+
exposureUnavailableReason?: string | undefined;
|
|
35
|
+
risk: {
|
|
36
|
+
verdict: "benign" | "error" | "malicious" | "unknown" | "warning";
|
|
37
|
+
features: {
|
|
38
|
+
type: string;
|
|
39
|
+
description?: string | undefined;
|
|
40
|
+
}[];
|
|
41
|
+
source: string | null;
|
|
42
|
+
assessedAt: string | null;
|
|
43
|
+
};
|
|
44
|
+
freshness: {
|
|
45
|
+
observedAt: string;
|
|
46
|
+
indexedThroughBlock: number | null;
|
|
47
|
+
observedBlock: number | null;
|
|
48
|
+
};
|
|
49
|
+
}, {
|
|
50
|
+
/** Server-assigned stable ID. Never recomputed by the client. */
|
|
51
|
+
id: import("@metamask/superstruct").Struct<string, null>;
|
|
52
|
+
account: import("@metamask/superstruct").Struct<string, null>;
|
|
53
|
+
/** Decimal chain ID, as returned by SAA. */
|
|
54
|
+
chainId: import("@metamask/superstruct").Struct<number, null>;
|
|
55
|
+
standard: import("@metamask/superstruct").Struct<"erc1155" | "erc20" | "erc721", {
|
|
56
|
+
erc1155: "erc1155";
|
|
57
|
+
erc20: "erc20";
|
|
58
|
+
erc721: "erc721";
|
|
59
|
+
}>;
|
|
60
|
+
approvalKind: import("@metamask/superstruct").Struct<"allowance" | "operator", {
|
|
61
|
+
allowance: "allowance";
|
|
62
|
+
operator: "operator";
|
|
63
|
+
}>;
|
|
64
|
+
tokenId: import("@metamask/superstruct").Struct<string | null, null>;
|
|
65
|
+
token: import("@metamask/superstruct").Struct<{
|
|
66
|
+
address: string;
|
|
67
|
+
name: string;
|
|
68
|
+
symbol: string;
|
|
69
|
+
decimals: number | null;
|
|
70
|
+
logo: string | null;
|
|
71
|
+
metadataStatus: "complete" | "partial";
|
|
72
|
+
}, {
|
|
73
|
+
address: import("@metamask/superstruct").Struct<string, null>;
|
|
74
|
+
name: import("@metamask/superstruct").Struct<string, null>;
|
|
75
|
+
symbol: import("@metamask/superstruct").Struct<string, null>;
|
|
76
|
+
decimals: import("@metamask/superstruct").Struct<number | null, null>;
|
|
77
|
+
logo: import("@metamask/superstruct").Struct<string | null, null>;
|
|
78
|
+
metadataStatus: import("@metamask/superstruct").Struct<"complete" | "partial", {
|
|
79
|
+
complete: "complete";
|
|
80
|
+
partial: "partial";
|
|
81
|
+
}>;
|
|
82
|
+
}>;
|
|
83
|
+
spender: import("@metamask/superstruct").Struct<{
|
|
84
|
+
address: string;
|
|
85
|
+
label: string | null;
|
|
86
|
+
labelSource: string | null;
|
|
87
|
+
}, {
|
|
88
|
+
address: import("@metamask/superstruct").Struct<string, null>;
|
|
89
|
+
label: import("@metamask/superstruct").Struct<string | null, null>;
|
|
90
|
+
labelSource: import("@metamask/superstruct").Struct<string | null, null>;
|
|
91
|
+
}>;
|
|
92
|
+
allowance: import("@metamask/superstruct").Struct<{
|
|
93
|
+
raw: string;
|
|
94
|
+
isUnlimited: boolean;
|
|
95
|
+
}, {
|
|
96
|
+
/** Canonical decimal integer string. */
|
|
97
|
+
raw: import("@metamask/superstruct").Struct<string, null>;
|
|
98
|
+
isUnlimited: import("@metamask/superstruct").Struct<boolean, null>;
|
|
99
|
+
}>;
|
|
100
|
+
/** Not summable across spenders; `null` when valuation is unavailable. */
|
|
101
|
+
exposure: import("@metamask/superstruct").Struct<{
|
|
102
|
+
amountUsd: string;
|
|
103
|
+
basis: "allowance" | "balance";
|
|
104
|
+
priceSource: string;
|
|
105
|
+
observedAt: string;
|
|
106
|
+
} | null, {
|
|
107
|
+
amountUsd: import("@metamask/superstruct").Struct<string, null>;
|
|
108
|
+
basis: import("@metamask/superstruct").Struct<"allowance" | "balance", {
|
|
109
|
+
allowance: "allowance";
|
|
110
|
+
balance: "balance";
|
|
111
|
+
}>;
|
|
112
|
+
priceSource: import("@metamask/superstruct").Struct<string, null>;
|
|
113
|
+
/** Calculation time, not the age of the underlying balance or price. */
|
|
114
|
+
observedAt: import("@metamask/superstruct").Struct<string, null>;
|
|
115
|
+
}>;
|
|
116
|
+
/** Explains a null exposure. Absence does not imply exposure is available. */
|
|
117
|
+
exposureUnavailableReason: import("@metamask/superstruct").Struct<string | undefined, null>;
|
|
118
|
+
risk: import("@metamask/superstruct").Struct<{
|
|
119
|
+
verdict: "benign" | "error" | "malicious" | "unknown" | "warning";
|
|
120
|
+
features: {
|
|
121
|
+
type: string;
|
|
122
|
+
description?: string | undefined;
|
|
123
|
+
}[];
|
|
124
|
+
source: string | null;
|
|
125
|
+
assessedAt: string | null;
|
|
126
|
+
}, {
|
|
127
|
+
/** `unknown` must not be treated as benign. */
|
|
128
|
+
verdict: import("@metamask/superstruct").Struct<"benign" | "error" | "malicious" | "unknown" | "warning", {
|
|
129
|
+
benign: "benign";
|
|
130
|
+
error: "error";
|
|
131
|
+
malicious: "malicious";
|
|
132
|
+
unknown: "unknown";
|
|
133
|
+
warning: "warning";
|
|
134
|
+
}>;
|
|
135
|
+
features: import("@metamask/superstruct").Struct<{
|
|
136
|
+
type: string;
|
|
137
|
+
description?: string | undefined;
|
|
138
|
+
}[], import("@metamask/superstruct").Struct<{
|
|
139
|
+
type: string;
|
|
140
|
+
description?: string | undefined;
|
|
141
|
+
}, {
|
|
142
|
+
type: import("@metamask/superstruct").Struct<string, null>;
|
|
143
|
+
description: import("@metamask/superstruct").Struct<string | undefined, null>;
|
|
144
|
+
}>>;
|
|
145
|
+
source: import("@metamask/superstruct").Struct<string | null, null>;
|
|
146
|
+
assessedAt: import("@metamask/superstruct").Struct<string | null, null>;
|
|
147
|
+
}>;
|
|
148
|
+
freshness: import("@metamask/superstruct").Struct<{
|
|
149
|
+
observedAt: string;
|
|
150
|
+
indexedThroughBlock: number | null;
|
|
151
|
+
observedBlock: number | null;
|
|
152
|
+
}, {
|
|
153
|
+
/** Request-generation time, not an on-chain observation time. */
|
|
154
|
+
observedAt: import("@metamask/superstruct").Struct<string, null>;
|
|
155
|
+
indexedThroughBlock: import("@metamask/superstruct").Struct<number | null, null>;
|
|
156
|
+
observedBlock: import("@metamask/superstruct").Struct<number | null, null>;
|
|
157
|
+
}>;
|
|
158
|
+
}>;
|
|
159
|
+
declare const ChainResultStruct: import("@metamask/superstruct").Struct<{
|
|
160
|
+
chainId: number;
|
|
161
|
+
status: "failed" | "success" | "timeout" | "unsupported";
|
|
162
|
+
completeness: "unverified" | "verified";
|
|
163
|
+
recordCount: number;
|
|
164
|
+
retryable: boolean;
|
|
165
|
+
errorCode?: string | undefined;
|
|
166
|
+
note?: string | undefined;
|
|
167
|
+
}, {
|
|
168
|
+
chainId: import("@metamask/superstruct").Struct<number, null>;
|
|
169
|
+
status: import("@metamask/superstruct").Struct<"failed" | "success" | "timeout" | "unsupported", {
|
|
170
|
+
failed: "failed";
|
|
171
|
+
success: "success";
|
|
172
|
+
timeout: "timeout";
|
|
173
|
+
unsupported: "unsupported";
|
|
174
|
+
}>;
|
|
175
|
+
/** `unverified` must not be rendered as "no approvals". */
|
|
176
|
+
completeness: import("@metamask/superstruct").Struct<"unverified" | "verified", {
|
|
177
|
+
unverified: "unverified";
|
|
178
|
+
verified: "verified";
|
|
179
|
+
}>;
|
|
180
|
+
recordCount: import("@metamask/superstruct").Struct<number, null>;
|
|
181
|
+
/** Whether retrying may produce a more complete result. */
|
|
182
|
+
retryable: import("@metamask/superstruct").Struct<boolean, null>;
|
|
183
|
+
errorCode: import("@metamask/superstruct").Struct<string | undefined, null>;
|
|
184
|
+
note: import("@metamask/superstruct").Struct<string | undefined, null>;
|
|
185
|
+
}>;
|
|
186
|
+
declare const ResponseStruct: import("@metamask/superstruct").Struct<{
|
|
187
|
+
account: string;
|
|
188
|
+
records: {
|
|
189
|
+
id: string;
|
|
190
|
+
account: string;
|
|
191
|
+
chainId: number;
|
|
192
|
+
standard: "erc1155" | "erc20" | "erc721";
|
|
193
|
+
approvalKind: "allowance" | "operator";
|
|
194
|
+
tokenId: string | null;
|
|
195
|
+
token: {
|
|
196
|
+
address: string;
|
|
197
|
+
name: string;
|
|
198
|
+
symbol: string;
|
|
199
|
+
decimals: number | null;
|
|
200
|
+
logo: string | null;
|
|
201
|
+
metadataStatus: "complete" | "partial";
|
|
202
|
+
};
|
|
203
|
+
spender: {
|
|
204
|
+
address: string;
|
|
205
|
+
label: string | null;
|
|
206
|
+
labelSource: string | null;
|
|
207
|
+
};
|
|
208
|
+
allowance: {
|
|
209
|
+
raw: string;
|
|
210
|
+
isUnlimited: boolean;
|
|
211
|
+
};
|
|
212
|
+
exposure: {
|
|
213
|
+
amountUsd: string;
|
|
214
|
+
basis: "allowance" | "balance";
|
|
215
|
+
priceSource: string;
|
|
216
|
+
observedAt: string;
|
|
217
|
+
} | null;
|
|
218
|
+
exposureUnavailableReason?: string | undefined;
|
|
219
|
+
risk: {
|
|
220
|
+
verdict: "benign" | "error" | "malicious" | "unknown" | "warning";
|
|
221
|
+
features: {
|
|
222
|
+
type: string;
|
|
223
|
+
description?: string | undefined;
|
|
224
|
+
}[];
|
|
225
|
+
source: string | null;
|
|
226
|
+
assessedAt: string | null;
|
|
227
|
+
};
|
|
228
|
+
freshness: {
|
|
229
|
+
observedAt: string;
|
|
230
|
+
indexedThroughBlock: number | null;
|
|
231
|
+
observedBlock: number | null;
|
|
232
|
+
};
|
|
233
|
+
}[];
|
|
234
|
+
chainResults: {
|
|
235
|
+
chainId: number;
|
|
236
|
+
status: "failed" | "success" | "timeout" | "unsupported";
|
|
237
|
+
completeness: "unverified" | "verified";
|
|
238
|
+
recordCount: number;
|
|
239
|
+
retryable: boolean;
|
|
240
|
+
errorCode?: string | undefined;
|
|
241
|
+
note?: string | undefined;
|
|
242
|
+
}[];
|
|
243
|
+
generatedAt: string;
|
|
244
|
+
freshness: {
|
|
245
|
+
forced: boolean;
|
|
246
|
+
maxStalenessMs: number;
|
|
247
|
+
};
|
|
248
|
+
schemaVersion: string;
|
|
249
|
+
}, {
|
|
250
|
+
/** Lowercased account address, matching the requested address. */
|
|
251
|
+
account: import("@metamask/superstruct").Struct<string, null>;
|
|
252
|
+
records: import("@metamask/superstruct").Struct<{
|
|
253
|
+
id: string;
|
|
254
|
+
account: string;
|
|
255
|
+
chainId: number;
|
|
256
|
+
standard: "erc1155" | "erc20" | "erc721";
|
|
257
|
+
approvalKind: "allowance" | "operator";
|
|
258
|
+
tokenId: string | null;
|
|
259
|
+
token: {
|
|
260
|
+
address: string;
|
|
261
|
+
name: string;
|
|
262
|
+
symbol: string;
|
|
263
|
+
decimals: number | null;
|
|
264
|
+
logo: string | null;
|
|
265
|
+
metadataStatus: "complete" | "partial";
|
|
266
|
+
};
|
|
267
|
+
spender: {
|
|
268
|
+
address: string;
|
|
269
|
+
label: string | null;
|
|
270
|
+
labelSource: string | null;
|
|
271
|
+
};
|
|
272
|
+
allowance: {
|
|
273
|
+
raw: string;
|
|
274
|
+
isUnlimited: boolean;
|
|
275
|
+
};
|
|
276
|
+
exposure: {
|
|
277
|
+
amountUsd: string;
|
|
278
|
+
basis: "allowance" | "balance";
|
|
279
|
+
priceSource: string;
|
|
280
|
+
observedAt: string;
|
|
281
|
+
} | null;
|
|
282
|
+
exposureUnavailableReason?: string | undefined;
|
|
283
|
+
risk: {
|
|
284
|
+
verdict: "benign" | "error" | "malicious" | "unknown" | "warning";
|
|
285
|
+
features: {
|
|
286
|
+
type: string;
|
|
287
|
+
description?: string | undefined;
|
|
288
|
+
}[];
|
|
289
|
+
source: string | null;
|
|
290
|
+
assessedAt: string | null;
|
|
291
|
+
};
|
|
292
|
+
freshness: {
|
|
293
|
+
observedAt: string;
|
|
294
|
+
indexedThroughBlock: number | null;
|
|
295
|
+
observedBlock: number | null;
|
|
296
|
+
};
|
|
297
|
+
}[], import("@metamask/superstruct").Struct<{
|
|
298
|
+
id: string;
|
|
299
|
+
account: string;
|
|
300
|
+
chainId: number;
|
|
301
|
+
standard: "erc1155" | "erc20" | "erc721";
|
|
302
|
+
approvalKind: "allowance" | "operator";
|
|
303
|
+
tokenId: string | null;
|
|
304
|
+
token: {
|
|
305
|
+
address: string;
|
|
306
|
+
name: string;
|
|
307
|
+
symbol: string;
|
|
308
|
+
decimals: number | null;
|
|
309
|
+
logo: string | null;
|
|
310
|
+
metadataStatus: "complete" | "partial";
|
|
311
|
+
};
|
|
312
|
+
spender: {
|
|
313
|
+
address: string;
|
|
314
|
+
label: string | null;
|
|
315
|
+
labelSource: string | null;
|
|
316
|
+
};
|
|
317
|
+
allowance: {
|
|
318
|
+
raw: string;
|
|
319
|
+
isUnlimited: boolean;
|
|
320
|
+
};
|
|
321
|
+
exposure: {
|
|
322
|
+
amountUsd: string;
|
|
323
|
+
basis: "allowance" | "balance";
|
|
324
|
+
priceSource: string;
|
|
325
|
+
observedAt: string;
|
|
326
|
+
} | null;
|
|
327
|
+
exposureUnavailableReason?: string | undefined;
|
|
328
|
+
risk: {
|
|
329
|
+
verdict: "benign" | "error" | "malicious" | "unknown" | "warning";
|
|
330
|
+
features: {
|
|
331
|
+
type: string;
|
|
332
|
+
description?: string | undefined;
|
|
333
|
+
}[];
|
|
334
|
+
source: string | null;
|
|
335
|
+
assessedAt: string | null;
|
|
336
|
+
};
|
|
337
|
+
freshness: {
|
|
338
|
+
observedAt: string;
|
|
339
|
+
indexedThroughBlock: number | null;
|
|
340
|
+
observedBlock: number | null;
|
|
341
|
+
};
|
|
342
|
+
}, {
|
|
343
|
+
/** Server-assigned stable ID. Never recomputed by the client. */
|
|
344
|
+
id: import("@metamask/superstruct").Struct<string, null>;
|
|
345
|
+
account: import("@metamask/superstruct").Struct<string, null>;
|
|
346
|
+
/** Decimal chain ID, as returned by SAA. */
|
|
347
|
+
chainId: import("@metamask/superstruct").Struct<number, null>;
|
|
348
|
+
standard: import("@metamask/superstruct").Struct<"erc1155" | "erc20" | "erc721", {
|
|
349
|
+
erc1155: "erc1155";
|
|
350
|
+
erc20: "erc20";
|
|
351
|
+
erc721: "erc721";
|
|
352
|
+
}>;
|
|
353
|
+
approvalKind: import("@metamask/superstruct").Struct<"allowance" | "operator", {
|
|
354
|
+
allowance: "allowance";
|
|
355
|
+
operator: "operator";
|
|
356
|
+
}>;
|
|
357
|
+
tokenId: import("@metamask/superstruct").Struct<string | null, null>;
|
|
358
|
+
token: import("@metamask/superstruct").Struct<{
|
|
359
|
+
address: string;
|
|
360
|
+
name: string;
|
|
361
|
+
symbol: string;
|
|
362
|
+
decimals: number | null;
|
|
363
|
+
logo: string | null;
|
|
364
|
+
metadataStatus: "complete" | "partial";
|
|
365
|
+
}, {
|
|
366
|
+
address: import("@metamask/superstruct").Struct<string, null>;
|
|
367
|
+
name: import("@metamask/superstruct").Struct<string, null>;
|
|
368
|
+
symbol: import("@metamask/superstruct").Struct<string, null>;
|
|
369
|
+
decimals: import("@metamask/superstruct").Struct<number | null, null>;
|
|
370
|
+
logo: import("@metamask/superstruct").Struct<string | null, null>;
|
|
371
|
+
metadataStatus: import("@metamask/superstruct").Struct<"complete" | "partial", {
|
|
372
|
+
complete: "complete";
|
|
373
|
+
partial: "partial";
|
|
374
|
+
}>;
|
|
375
|
+
}>;
|
|
376
|
+
spender: import("@metamask/superstruct").Struct<{
|
|
377
|
+
address: string;
|
|
378
|
+
label: string | null;
|
|
379
|
+
labelSource: string | null;
|
|
380
|
+
}, {
|
|
381
|
+
address: import("@metamask/superstruct").Struct<string, null>;
|
|
382
|
+
label: import("@metamask/superstruct").Struct<string | null, null>;
|
|
383
|
+
labelSource: import("@metamask/superstruct").Struct<string | null, null>;
|
|
384
|
+
}>;
|
|
385
|
+
allowance: import("@metamask/superstruct").Struct<{
|
|
386
|
+
raw: string;
|
|
387
|
+
isUnlimited: boolean;
|
|
388
|
+
}, {
|
|
389
|
+
/** Canonical decimal integer string. */
|
|
390
|
+
raw: import("@metamask/superstruct").Struct<string, null>;
|
|
391
|
+
isUnlimited: import("@metamask/superstruct").Struct<boolean, null>;
|
|
392
|
+
}>;
|
|
393
|
+
/** Not summable across spenders; `null` when valuation is unavailable. */
|
|
394
|
+
exposure: import("@metamask/superstruct").Struct<{
|
|
395
|
+
amountUsd: string;
|
|
396
|
+
basis: "allowance" | "balance";
|
|
397
|
+
priceSource: string;
|
|
398
|
+
observedAt: string;
|
|
399
|
+
} | null, {
|
|
400
|
+
amountUsd: import("@metamask/superstruct").Struct<string, null>;
|
|
401
|
+
basis: import("@metamask/superstruct").Struct<"allowance" | "balance", {
|
|
402
|
+
allowance: "allowance";
|
|
403
|
+
balance: "balance";
|
|
404
|
+
}>;
|
|
405
|
+
priceSource: import("@metamask/superstruct").Struct<string, null>;
|
|
406
|
+
/** Calculation time, not the age of the underlying balance or price. */
|
|
407
|
+
observedAt: import("@metamask/superstruct").Struct<string, null>;
|
|
408
|
+
}>;
|
|
409
|
+
/** Explains a null exposure. Absence does not imply exposure is available. */
|
|
410
|
+
exposureUnavailableReason: import("@metamask/superstruct").Struct<string | undefined, null>;
|
|
411
|
+
risk: import("@metamask/superstruct").Struct<{
|
|
412
|
+
verdict: "benign" | "error" | "malicious" | "unknown" | "warning";
|
|
413
|
+
features: {
|
|
414
|
+
type: string;
|
|
415
|
+
description?: string | undefined;
|
|
416
|
+
}[];
|
|
417
|
+
source: string | null;
|
|
418
|
+
assessedAt: string | null;
|
|
419
|
+
}, {
|
|
420
|
+
/** `unknown` must not be treated as benign. */
|
|
421
|
+
verdict: import("@metamask/superstruct").Struct<"benign" | "error" | "malicious" | "unknown" | "warning", {
|
|
422
|
+
benign: "benign";
|
|
423
|
+
error: "error";
|
|
424
|
+
malicious: "malicious";
|
|
425
|
+
unknown: "unknown";
|
|
426
|
+
warning: "warning";
|
|
427
|
+
}>;
|
|
428
|
+
features: import("@metamask/superstruct").Struct<{
|
|
429
|
+
type: string;
|
|
430
|
+
description?: string | undefined;
|
|
431
|
+
}[], import("@metamask/superstruct").Struct<{
|
|
432
|
+
type: string;
|
|
433
|
+
description?: string | undefined;
|
|
434
|
+
}, {
|
|
435
|
+
type: import("@metamask/superstruct").Struct<string, null>;
|
|
436
|
+
description: import("@metamask/superstruct").Struct<string | undefined, null>;
|
|
437
|
+
}>>;
|
|
438
|
+
source: import("@metamask/superstruct").Struct<string | null, null>;
|
|
439
|
+
assessedAt: import("@metamask/superstruct").Struct<string | null, null>;
|
|
440
|
+
}>;
|
|
441
|
+
freshness: import("@metamask/superstruct").Struct<{
|
|
442
|
+
observedAt: string;
|
|
443
|
+
indexedThroughBlock: number | null;
|
|
444
|
+
observedBlock: number | null;
|
|
445
|
+
}, {
|
|
446
|
+
/** Request-generation time, not an on-chain observation time. */
|
|
447
|
+
observedAt: import("@metamask/superstruct").Struct<string, null>;
|
|
448
|
+
indexedThroughBlock: import("@metamask/superstruct").Struct<number | null, null>;
|
|
449
|
+
observedBlock: import("@metamask/superstruct").Struct<number | null, null>;
|
|
450
|
+
}>;
|
|
451
|
+
}>>;
|
|
452
|
+
/** Exactly one entry per requested chain. */
|
|
453
|
+
chainResults: import("@metamask/superstruct").Struct<{
|
|
454
|
+
chainId: number;
|
|
455
|
+
status: "failed" | "success" | "timeout" | "unsupported";
|
|
456
|
+
completeness: "unverified" | "verified";
|
|
457
|
+
recordCount: number;
|
|
458
|
+
retryable: boolean;
|
|
459
|
+
errorCode?: string | undefined;
|
|
460
|
+
note?: string | undefined;
|
|
461
|
+
}[], import("@metamask/superstruct").Struct<{
|
|
462
|
+
chainId: number;
|
|
463
|
+
status: "failed" | "success" | "timeout" | "unsupported";
|
|
464
|
+
completeness: "unverified" | "verified";
|
|
465
|
+
recordCount: number;
|
|
466
|
+
retryable: boolean;
|
|
467
|
+
errorCode?: string | undefined;
|
|
468
|
+
note?: string | undefined;
|
|
469
|
+
}, {
|
|
470
|
+
chainId: import("@metamask/superstruct").Struct<number, null>;
|
|
471
|
+
status: import("@metamask/superstruct").Struct<"failed" | "success" | "timeout" | "unsupported", {
|
|
472
|
+
failed: "failed";
|
|
473
|
+
success: "success";
|
|
474
|
+
timeout: "timeout";
|
|
475
|
+
unsupported: "unsupported";
|
|
476
|
+
}>;
|
|
477
|
+
/** `unverified` must not be rendered as "no approvals". */
|
|
478
|
+
completeness: import("@metamask/superstruct").Struct<"unverified" | "verified", {
|
|
479
|
+
unverified: "unverified";
|
|
480
|
+
verified: "verified";
|
|
481
|
+
}>;
|
|
482
|
+
recordCount: import("@metamask/superstruct").Struct<number, null>;
|
|
483
|
+
/** Whether retrying may produce a more complete result. */
|
|
484
|
+
retryable: import("@metamask/superstruct").Struct<boolean, null>;
|
|
485
|
+
errorCode: import("@metamask/superstruct").Struct<string | undefined, null>;
|
|
486
|
+
note: import("@metamask/superstruct").Struct<string | undefined, null>;
|
|
487
|
+
}>>;
|
|
488
|
+
generatedAt: import("@metamask/superstruct").Struct<string, null>;
|
|
489
|
+
freshness: import("@metamask/superstruct").Struct<{
|
|
490
|
+
forced: boolean;
|
|
491
|
+
maxStalenessMs: number;
|
|
492
|
+
}, {
|
|
493
|
+
/** Whether the allowance cache was actually bypassed. */
|
|
494
|
+
forced: import("@metamask/superstruct").Struct<boolean, null>;
|
|
495
|
+
/** Allowance-path cache-age budget, in milliseconds. */
|
|
496
|
+
maxStalenessMs: import("@metamask/superstruct").Struct<number, null>;
|
|
497
|
+
}>;
|
|
498
|
+
schemaVersion: import("@metamask/superstruct").Struct<string, null>;
|
|
499
|
+
}>;
|
|
500
|
+
export type ApprovalDashboardRecord = Infer<typeof RecordStruct>;
|
|
501
|
+
export type ApprovalDashboardChainResult = Infer<typeof ChainResultStruct>;
|
|
502
|
+
export type ApprovalDashboardResponse = Infer<typeof ResponseStruct>;
|
|
503
|
+
export type ApprovalDashboardRequest = {
|
|
504
|
+
/** EVM account address (`0x` + 40 hex characters, any case). */
|
|
505
|
+
address: string;
|
|
506
|
+
/**
|
|
507
|
+
* Hex chain IDs (e.g. `'0x1'`). Duplicates are removed; at most 20
|
|
508
|
+
* distinct chains.
|
|
509
|
+
*/
|
|
510
|
+
chainIds: string[];
|
|
511
|
+
/**
|
|
512
|
+
* Ask SAA to bypass the allowance response cache. The server may throttle
|
|
513
|
+
* it; check `freshness.forced` on the response.
|
|
514
|
+
*/
|
|
515
|
+
forceFresh?: boolean;
|
|
516
|
+
};
|
|
517
|
+
export type ApprovalDashboardErrorCode = 'invalid_request' | 'http_error' | 'network_error' | 'timeout' | 'invalid_response' | 'incompatible_schema' | 'service_unavailable';
|
|
518
|
+
/**
|
|
519
|
+
* Thrown by `SecurityAlertsApiService:getApprovalDashboard` for any failure. A failed call never
|
|
520
|
+
* resolves to an empty inventory.
|
|
521
|
+
*/
|
|
522
|
+
export declare class ApprovalDashboardError extends Error {
|
|
523
|
+
readonly code: ApprovalDashboardErrorCode;
|
|
524
|
+
/** Whether retrying the same request may succeed. */
|
|
525
|
+
readonly retryable: boolean;
|
|
526
|
+
/** HTTP status, for `http_error` only. */
|
|
527
|
+
readonly httpStatus?: number;
|
|
528
|
+
constructor(code: ApprovalDashboardErrorCode, message: string, options?: {
|
|
529
|
+
retryable?: boolean;
|
|
530
|
+
httpStatus?: number;
|
|
531
|
+
cause?: unknown;
|
|
532
|
+
});
|
|
533
|
+
}
|
|
534
|
+
/**
|
|
535
|
+
* Validate the request and convert hex chain IDs to the decimal integers SAA
|
|
536
|
+
* expects.
|
|
537
|
+
*
|
|
538
|
+
* @param request - The public request.
|
|
539
|
+
* @returns The SAA request body.
|
|
540
|
+
*/
|
|
541
|
+
export declare function buildApprovalDashboardRequestBody(request: ApprovalDashboardRequest): {
|
|
542
|
+
address: string;
|
|
543
|
+
chainIds: number[];
|
|
544
|
+
forceFresh: boolean;
|
|
545
|
+
};
|
|
546
|
+
/**
|
|
547
|
+
* Build an `invalid_response` error.
|
|
548
|
+
*
|
|
549
|
+
* @param message - What was wrong with the response.
|
|
550
|
+
* @param cause - The underlying error, if any.
|
|
551
|
+
* @returns The error.
|
|
552
|
+
*/
|
|
553
|
+
export declare function invalidApprovalDashboardResponse(message: string, cause?: unknown): ApprovalDashboardError;
|
|
554
|
+
/**
|
|
555
|
+
* Validate an SAA response body against the contract and the request it
|
|
556
|
+
* answers, applying the contract's fallbacks.
|
|
557
|
+
*
|
|
558
|
+
* @param body - The parsed JSON body.
|
|
559
|
+
* @param request - The SAA request body that produced it.
|
|
560
|
+
* @param request.address - The lowercased requested address.
|
|
561
|
+
* @param request.chainIds - The requested decimal chain IDs.
|
|
562
|
+
* @returns The validated response.
|
|
563
|
+
*/
|
|
564
|
+
export declare function parseApprovalDashboardResponse(body: unknown, request: {
|
|
565
|
+
address: string;
|
|
566
|
+
chainIds: number[];
|
|
567
|
+
}): ApprovalDashboardResponse;
|
|
568
|
+
export {};
|
|
569
|
+
//# sourceMappingURL=approval-dashboard.d.ts.map
|
|
@@ -0,0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,CAAC,EAAE,OAAO,GACd,sBAAsB,CAMxB;AAED;;;;;;;;;GASG;AACH,wBAAgB,8BAA8B,CAC5C,IAAI,EAAE,OAAO,EACb,OAAO,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,EAAE,CAAA;CAAE,GAC/C,yBAAyB,CA4C3B"}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { isSafeChainId, isValidHexAddress } from '@metamask/controller-utils';
|
|
2
|
+
import { array, boolean, coerce, enums, integer, is, nullable, optional, pattern, refine, string, type, validate, } from '@metamask/superstruct';
|
|
3
|
+
/** Maximum number of distinct chain IDs per request (SAA limit). */
|
|
4
|
+
export const APPROVAL_DASHBOARD_MAX_CHAIN_IDS = 20;
|
|
5
|
+
/** Schema major this client understands; any minor/patch is accepted. */
|
|
6
|
+
const SUPPORTED_SCHEMA_MAJOR = 0;
|
|
7
|
+
const RISK_VERDICTS = [
|
|
8
|
+
'malicious',
|
|
9
|
+
'warning',
|
|
10
|
+
'benign',
|
|
11
|
+
'unknown',
|
|
12
|
+
'error',
|
|
13
|
+
];
|
|
14
|
+
const CHAIN_STATUSES = ['success', 'unsupported', 'failed', 'timeout'];
|
|
15
|
+
const HEX_CHAIN_ID_REGEX = /^0x[0-9a-fA-F]+$/u;
|
|
16
|
+
const SCHEMA_VERSION_REGEX = /^(\d+)\.\d+\.\d+/u;
|
|
17
|
+
const NonNegativeIntegerStruct = refine(integer(), 'NonNegativeInteger', (value) => value >= 0 || 'Expected a nonnegative integer');
|
|
18
|
+
const ChainIdStruct = refine(integer(), 'ChainId', (value) => value > 0 || 'Expected a positive integer');
|
|
19
|
+
const NonEmptyStringStruct = refine(string(), 'NonEmptyString', (value) => value.length > 0 || 'Expected a non-empty string');
|
|
20
|
+
// `type()` structs accept and pass through unknown fields, per the contract's
|
|
21
|
+
// compatibility rule. The only coercions are the two fallbacks the contract
|
|
22
|
+
// defines: unknown risk verdict -> `unknown`, and unknown chain status ->
|
|
23
|
+
// `failed` + `unverified`.
|
|
24
|
+
const RecordStruct = type({
|
|
25
|
+
/** Server-assigned stable ID. Never recomputed by the client. */
|
|
26
|
+
id: NonEmptyStringStruct,
|
|
27
|
+
account: string(),
|
|
28
|
+
/** Decimal chain ID, as returned by SAA. */
|
|
29
|
+
chainId: ChainIdStruct,
|
|
30
|
+
standard: enums(['erc20', 'erc721', 'erc1155']),
|
|
31
|
+
approvalKind: enums(['allowance', 'operator']),
|
|
32
|
+
tokenId: nullable(string()),
|
|
33
|
+
token: type({
|
|
34
|
+
address: string(),
|
|
35
|
+
name: string(),
|
|
36
|
+
symbol: string(),
|
|
37
|
+
decimals: nullable(NonNegativeIntegerStruct),
|
|
38
|
+
logo: nullable(string()),
|
|
39
|
+
metadataStatus: enums(['complete', 'partial']),
|
|
40
|
+
}),
|
|
41
|
+
spender: type({
|
|
42
|
+
address: string(),
|
|
43
|
+
label: nullable(string()),
|
|
44
|
+
labelSource: nullable(string()),
|
|
45
|
+
}),
|
|
46
|
+
allowance: type({
|
|
47
|
+
/** Canonical decimal integer string. */
|
|
48
|
+
raw: pattern(string(), /^\d+$/u),
|
|
49
|
+
isUnlimited: boolean(),
|
|
50
|
+
}),
|
|
51
|
+
/** Not summable across spenders; `null` when valuation is unavailable. */
|
|
52
|
+
exposure: nullable(type({
|
|
53
|
+
amountUsd: pattern(string(), /^\d+(?:\.\d+)?$/u),
|
|
54
|
+
basis: enums(['allowance', 'balance']),
|
|
55
|
+
priceSource: string(),
|
|
56
|
+
/** Calculation time, not the age of the underlying balance or price. */
|
|
57
|
+
observedAt: NonEmptyStringStruct,
|
|
58
|
+
})),
|
|
59
|
+
/** Explains a null exposure. Absence does not imply exposure is available. */
|
|
60
|
+
exposureUnavailableReason: optional(string()),
|
|
61
|
+
risk: type({
|
|
62
|
+
/** `unknown` must not be treated as benign. */
|
|
63
|
+
verdict: coerce(enums(RISK_VERDICTS), string(), (verdict) => is(verdict, enums(RISK_VERDICTS)) ? verdict : 'unknown'),
|
|
64
|
+
features: array(type({ type: string(), description: optional(string()) })),
|
|
65
|
+
source: nullable(string()),
|
|
66
|
+
assessedAt: nullable(string()),
|
|
67
|
+
}),
|
|
68
|
+
freshness: type({
|
|
69
|
+
/** Request-generation time, not an on-chain observation time. */
|
|
70
|
+
observedAt: NonEmptyStringStruct,
|
|
71
|
+
indexedThroughBlock: nullable(NonNegativeIntegerStruct),
|
|
72
|
+
observedBlock: nullable(NonNegativeIntegerStruct),
|
|
73
|
+
}),
|
|
74
|
+
});
|
|
75
|
+
const ChainResultStruct = coerce(type({
|
|
76
|
+
chainId: ChainIdStruct,
|
|
77
|
+
status: enums(CHAIN_STATUSES),
|
|
78
|
+
/** `unverified` must not be rendered as "no approvals". */
|
|
79
|
+
completeness: enums(['verified', 'unverified']),
|
|
80
|
+
recordCount: NonNegativeIntegerStruct,
|
|
81
|
+
/** Whether retrying may produce a more complete result. */
|
|
82
|
+
retryable: boolean(),
|
|
83
|
+
errorCode: optional(string()),
|
|
84
|
+
note: optional(string()),
|
|
85
|
+
}), type({ status: string() }), (result) => is(result.status, enums(CHAIN_STATUSES))
|
|
86
|
+
? result
|
|
87
|
+
: { ...result, status: 'failed', completeness: 'unverified' });
|
|
88
|
+
const ResponseStruct = type({
|
|
89
|
+
/** Lowercased account address, matching the requested address. */
|
|
90
|
+
account: string(),
|
|
91
|
+
records: array(RecordStruct),
|
|
92
|
+
/** Exactly one entry per requested chain. */
|
|
93
|
+
chainResults: array(ChainResultStruct),
|
|
94
|
+
generatedAt: NonEmptyStringStruct,
|
|
95
|
+
freshness: type({
|
|
96
|
+
/** Whether the allowance cache was actually bypassed. */
|
|
97
|
+
forced: boolean(),
|
|
98
|
+
/** Allowance-path cache-age budget, in milliseconds. */
|
|
99
|
+
maxStalenessMs: NonNegativeIntegerStruct,
|
|
100
|
+
}),
|
|
101
|
+
schemaVersion: string(),
|
|
102
|
+
});
|
|
103
|
+
/**
|
|
104
|
+
* Thrown by `SecurityAlertsApiService:getApprovalDashboard` for any failure. A failed call never
|
|
105
|
+
* resolves to an empty inventory.
|
|
106
|
+
*/
|
|
107
|
+
export class ApprovalDashboardError extends Error {
|
|
108
|
+
code;
|
|
109
|
+
/** Whether retrying the same request may succeed. */
|
|
110
|
+
retryable;
|
|
111
|
+
/** HTTP status, for `http_error` only. */
|
|
112
|
+
httpStatus;
|
|
113
|
+
constructor(code, message, options = {}) {
|
|
114
|
+
super(message, { cause: options.cause });
|
|
115
|
+
this.name = 'ApprovalDashboardError';
|
|
116
|
+
this.code = code;
|
|
117
|
+
this.retryable = options.retryable ?? false;
|
|
118
|
+
this.httpStatus = options.httpStatus;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Validate the request and convert hex chain IDs to the decimal integers SAA
|
|
123
|
+
* expects.
|
|
124
|
+
*
|
|
125
|
+
* @param request - The public request.
|
|
126
|
+
* @returns The SAA request body.
|
|
127
|
+
*/
|
|
128
|
+
export function buildApprovalDashboardRequestBody(request) {
|
|
129
|
+
if (!isValidHexAddress(request.address, { allowNonPrefixed: false })) {
|
|
130
|
+
throw new ApprovalDashboardError('invalid_request', 'address must be 0x followed by 40 hex characters');
|
|
131
|
+
}
|
|
132
|
+
const chainIds = new Set();
|
|
133
|
+
for (const chainId of request.chainIds) {
|
|
134
|
+
if (!HEX_CHAIN_ID_REGEX.test(chainId) ||
|
|
135
|
+
!isSafeChainId(chainId)) {
|
|
136
|
+
throw new ApprovalDashboardError('invalid_request', `Invalid hex chain ID: ${chainId}`);
|
|
137
|
+
}
|
|
138
|
+
chainIds.add(Number(chainId));
|
|
139
|
+
if (chainIds.size > APPROVAL_DASHBOARD_MAX_CHAIN_IDS) {
|
|
140
|
+
throw new ApprovalDashboardError('invalid_request', `chainIds cannot contain more than ${APPROVAL_DASHBOARD_MAX_CHAIN_IDS} distinct chains`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (chainIds.size === 0) {
|
|
144
|
+
throw new ApprovalDashboardError('invalid_request', 'chainIds must not be empty');
|
|
145
|
+
}
|
|
146
|
+
return {
|
|
147
|
+
address: request.address.toLowerCase(),
|
|
148
|
+
chainIds: [...chainIds],
|
|
149
|
+
forceFresh: request.forceFresh ?? false,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Build an `invalid_response` error.
|
|
154
|
+
*
|
|
155
|
+
* @param message - What was wrong with the response.
|
|
156
|
+
* @param cause - The underlying error, if any.
|
|
157
|
+
* @returns The error.
|
|
158
|
+
*/
|
|
159
|
+
export function invalidApprovalDashboardResponse(message, cause) {
|
|
160
|
+
return new ApprovalDashboardError('invalid_response', `Invalid approval dashboard response: ${message}`, { cause });
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Validate an SAA response body against the contract and the request it
|
|
164
|
+
* answers, applying the contract's fallbacks.
|
|
165
|
+
*
|
|
166
|
+
* @param body - The parsed JSON body.
|
|
167
|
+
* @param request - The SAA request body that produced it.
|
|
168
|
+
* @param request.address - The lowercased requested address.
|
|
169
|
+
* @param request.chainIds - The requested decimal chain IDs.
|
|
170
|
+
* @returns The validated response.
|
|
171
|
+
*/
|
|
172
|
+
export function parseApprovalDashboardResponse(body, request) {
|
|
173
|
+
// Check the schema major first so a breaking change is reported as such
|
|
174
|
+
// rather than as a field-level validation failure.
|
|
175
|
+
const version = is(body, type({ schemaVersion: string() }))
|
|
176
|
+
? SCHEMA_VERSION_REGEX.exec(body.schemaVersion)
|
|
177
|
+
: null;
|
|
178
|
+
if (!version) {
|
|
179
|
+
throw invalidApprovalDashboardResponse('missing or malformed schemaVersion');
|
|
180
|
+
}
|
|
181
|
+
if (Number(version[1]) !== SUPPORTED_SCHEMA_MAJOR) {
|
|
182
|
+
throw new ApprovalDashboardError('incompatible_schema', `Unsupported approval dashboard schema version ${version[0]}`);
|
|
183
|
+
}
|
|
184
|
+
const [error, response] = validate(body, ResponseStruct, { coerce: true });
|
|
185
|
+
if (error) {
|
|
186
|
+
throw invalidApprovalDashboardResponse(error.message, error);
|
|
187
|
+
}
|
|
188
|
+
const answered = response.chainResults.map(({ chainId }) => chainId);
|
|
189
|
+
if (answered.length !== request.chainIds.length ||
|
|
190
|
+
!request.chainIds.every((chainId) => answered.includes(chainId))) {
|
|
191
|
+
throw invalidApprovalDashboardResponse('chainResults do not match the requested chains');
|
|
192
|
+
}
|
|
193
|
+
for (const record of [response, ...response.records]) {
|
|
194
|
+
if (record.account.toLowerCase() !== request.address) {
|
|
195
|
+
throw invalidApprovalDashboardResponse('account does not match the requested address');
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if (response.records.some(({ chainId }) => !answered.includes(chainId))) {
|
|
199
|
+
throw invalidApprovalDashboardResponse('record for an unrequested chain');
|
|
200
|
+
}
|
|
201
|
+
return response;
|
|
202
|
+
}
|
|
203
|
+
//# sourceMappingURL=approval-dashboard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"approval-dashboard.js","sourceRoot":"","sources":["../src/approval-dashboard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC9E,OAAO,EACL,KAAK,EACL,OAAO,EACP,MAAM,EACN,KAAK,EACL,OAAO,EACP,EAAE,EACF,QAAQ,EACR,QAAQ,EACR,OAAO,EACP,MAAM,EACN,MAAM,EACN,IAAI,EACJ,QAAQ,GACT,MAAM,uBAAuB,CAAC;AAG/B,oEAAoE;AACpE,MAAM,CAAC,MAAM,gCAAgC,GAAG,EAAE,CAAC;AAEnD,yEAAyE;AACzE,MAAM,sBAAsB,GAAG,CAAC,CAAC;AAEjC,MAAM,aAAa,GAAG;IACpB,WAAW;IACX,SAAS;IACT,QAAQ;IACR,SAAS;IACT,OAAO;CACC,CAAC;AACX,MAAM,cAAc,GAAG,CAAC,SAAS,EAAE,aAAa,EAAE,QAAQ,EAAE,SAAS,CAAU,CAAC;AAEhF,MAAM,kBAAkB,G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AE,CAAC;QACV,MAAM,gCAAgC,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAC/D,CAAC;IAED,MAAM,QAAQ,GAAG,QAAQ,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC;IACrE,IACE,QAAQ,CAAC,MAAM,KAAK,OAAO,CAAC,QAAQ,CAAC,MAAM;QAC3C,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,EAChE,CAAC;QACD,MAAM,gCAAgC,CACpC,gDAAgD,CACjD,CAAC;IACJ,CAAC;IACD,KAAK,MAAM,MAAM,IAAI,CAAC,QAAQ,EAAE,GAAG,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;QACrD,IAAI,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE,KAAK,OAAO,CAAC,OAAO,EAAE,CAAC;YACrD,MAAM,gCAAgC,CACpC,8CAA8C,CAC/C,CAAC;QACJ,CAAC;IACH,CAAC;IACD,IAAI,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC;QACxE,MAAM,gCAAgC,CAAC,iCAAiC,CAAC,CAAC;IAC5E,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["import { isSafeChainId, isValidHexAddress } from '@metamask/controller-utils';\nimport {\n array,\n boolean,\n coerce,\n enums,\n integer,\n is,\n nullable,\n optional,\n pattern,\n refine,\n string,\n type,\n validate,\n} from '@metamask/superstruct';\nimport type { Infer } from '@metamask/superstruct';\n\n/** Maximum number of distinct chain IDs per request (SAA limit). */\nexport const APPROVAL_DASHBOARD_MAX_CHAIN_IDS = 20;\n\n/** Schema major this client understands; any minor/patch is accepted. */\nconst SUPPORTED_SCHEMA_MAJOR = 0;\n\nconst RISK_VERDICTS = [\n 'malicious',\n 'warning',\n 'benign',\n 'unknown',\n 'error',\n] as const;\nconst CHAIN_STATUSES = ['success', 'unsupported', 'failed', 'timeout'] as const;\n\nconst HEX_CHAIN_ID_REGEX = /^0x[0-9a-fA-F]+$/u;\nconst SCHEMA_VERSION_REGEX = /^(\\d+)\\.\\d+\\.\\d+/u;\n\nconst NonNegativeIntegerStruct = refine(\n integer(),\n 'NonNegativeInteger',\n (value) => value >= 0 || 'Expected a nonnegative integer',\n);\nconst ChainIdStruct = refine(\n integer(),\n 'ChainId',\n (value) => value > 0 || 'Expected a positive integer',\n);\nconst NonEmptyStringStruct = refine(\n string(),\n 'NonEmptyString',\n (value) => value.length > 0 || 'Expected a non-empty string',\n);\n\n// `type()` structs accept and pass through unknown fields, per the contract's\n// compatibility rule. The only coercions are the two fallbacks the contract\n// defines: unknown risk verdict -> `unknown`, and unknown chain status ->\n// `failed` + `unverified`.\nconst RecordStruct = type({\n /** Server-assigned stable ID. Never recomputed by the client. */\n id: NonEmptyStringStruct,\n account: string(),\n /** Decimal chain ID, as returned by SAA. */\n chainId: ChainIdStruct,\n standard: enums(['erc20', 'erc721', 'erc1155']),\n approvalKind: enums(['allowance', 'operator']),\n tokenId: nullable(string()),\n token: type({\n address: string(),\n name: string(),\n symbol: string(),\n decimals: nullable(NonNegativeIntegerStruct),\n logo: nullable(string()),\n metadataStatus: enums(['complete', 'partial']),\n }),\n spender: type({\n address: string(),\n label: nullable(string()),\n labelSource: nullable(string()),\n }),\n allowance: type({\n /** Canonical decimal integer string. */\n raw: pattern(string(), /^\\d+$/u),\n isUnlimited: boolean(),\n }),\n /** Not summable across spenders; `null` when valuation is unavailable. */\n exposure: nullable(\n type({\n amountUsd: pattern(string(), /^\\d+(?:\\.\\d+)?$/u),\n basis: enums(['allowance', 'balance']),\n priceSource: string(),\n /** Calculation time, not the age of the underlying balance or price. */\n observedAt: NonEmptyStringStruct,\n }),\n ),\n /** Explains a null exposure. Absence does not imply exposure is available. */\n exposureUnavailableReason: optional(string()),\n risk: type({\n /** `unknown` must not be treated as benign. */\n verdict: coerce(enums(RISK_VERDICTS), string(), (verdict) =>\n is(verdict, enums(RISK_VERDICTS)) ? verdict : 'unknown',\n ),\n features: array(type({ type: string(), description: optional(string()) })),\n source: nullable(string()),\n assessedAt: nullable(string()),\n }),\n freshness: type({\n /** Request-generation time, not an on-chain observation time. */\n observedAt: NonEmptyStringStruct,\n indexedThroughBlock: nullable(NonNegativeIntegerStruct),\n observedBlock: nullable(NonNegativeIntegerStruct),\n }),\n});\n\nconst ChainResultStruct = coerce(\n type({\n chainId: ChainIdStruct,\n status: enums(CHAIN_STATUSES),\n /** `unverified` must not be rendered as \"no approvals\". */\n completeness: enums(['verified', 'unverified']),\n recordCount: NonNegativeIntegerStruct,\n /** Whether retrying may produce a more complete result. */\n retryable: boolean(),\n errorCode: optional(string()),\n note: optional(string()),\n }),\n type({ status: string() }),\n (result) =>\n is(result.status, enums(CHAIN_STATUSES))\n ? result\n : { ...result, status: 'failed', completeness: 'unverified' },\n);\n\nconst ResponseStruct = type({\n /** Lowercased account address, matching the requested address. */\n account: string(),\n records: array(RecordStruct),\n /** Exactly one entry per requested chain. */\n chainResults: array(ChainResultStruct),\n generatedAt: NonEmptyStringStruct,\n freshness: type({\n /** Whether the allowance cache was actually bypassed. */\n forced: boolean(),\n /** Allowance-path cache-age budget, in milliseconds. */\n maxStalenessMs: NonNegativeIntegerStruct,\n }),\n schemaVersion: string(),\n});\n\nexport type ApprovalDashboardRecord = Infer<typeof RecordStruct>;\nexport type ApprovalDashboardChainResult = Infer<typeof ChainResultStruct>;\nexport type ApprovalDashboardResponse = Infer<typeof ResponseStruct>;\n\nexport type ApprovalDashboardRequest = {\n /** EVM account address (`0x` + 40 hex characters, any case). */\n address: string;\n /**\n * Hex chain IDs (e.g. `'0x1'`). Duplicates are removed; at most 20\n * distinct chains.\n */\n chainIds: string[];\n /**\n * Ask SAA to bypass the allowance response cache. The server may throttle\n * it; check `freshness.forced` on the response.\n */\n forceFresh?: boolean;\n};\n\nexport type ApprovalDashboardErrorCode =\n | 'invalid_request'\n | 'http_error'\n | 'network_error'\n | 'timeout'\n | 'invalid_response'\n | 'incompatible_schema'\n | 'service_unavailable';\n\n/**\n * Thrown by `SecurityAlertsApiService:getApprovalDashboard` for any failure. A failed call never\n * resolves to an empty inventory.\n */\nexport class ApprovalDashboardError extends Error {\n readonly code: ApprovalDashboardErrorCode;\n\n /** Whether retrying the same request may succeed. */\n readonly retryable: boolean;\n\n /** HTTP status, for `http_error` only. */\n readonly httpStatus?: number;\n\n constructor(\n code: ApprovalDashboardErrorCode,\n message: string,\n options: { retryable?: boolean; httpStatus?: number; cause?: unknown } = {},\n ) {\n super(message, { cause: options.cause });\n this.name = 'ApprovalDashboardError';\n this.code = code;\n this.retryable = options.retryable ?? false;\n this.httpStatus = options.httpStatus;\n }\n}\n\n/**\n * Validate the request and convert hex chain IDs to the decimal integers SAA\n * expects.\n *\n * @param request - The public request.\n * @returns The SAA request body.\n */\nexport function buildApprovalDashboardRequestBody(\n request: ApprovalDashboardRequest,\n): {\n address: string;\n chainIds: number[];\n forceFresh: boolean;\n} {\n if (!isValidHexAddress(request.address, { allowNonPrefixed: false })) {\n throw new ApprovalDashboardError(\n 'invalid_request',\n 'address must be 0x followed by 40 hex characters',\n );\n }\n\n const chainIds = new Set<number>();\n for (const chainId of request.chainIds) {\n if (\n !HEX_CHAIN_ID_REGEX.test(chainId) ||\n !isSafeChainId(chainId as `0x${string}`)\n ) {\n throw new ApprovalDashboardError(\n 'invalid_request',\n `Invalid hex chain ID: ${chainId}`,\n );\n }\n chainIds.add(Number(chainId));\n if (chainIds.size > APPROVAL_DASHBOARD_MAX_CHAIN_IDS) {\n throw new ApprovalDashboardError(\n 'invalid_request',\n `chainIds cannot contain more than ${APPROVAL_DASHBOARD_MAX_CHAIN_IDS} distinct chains`,\n );\n }\n }\n if (chainIds.size === 0) {\n throw new ApprovalDashboardError(\n 'invalid_request',\n 'chainIds must not be empty',\n );\n }\n\n return {\n address: request.address.toLowerCase(),\n chainIds: [...chainIds],\n forceFresh: request.forceFresh ?? false,\n };\n}\n\n/**\n * Build an `invalid_response` error.\n *\n * @param message - What was wrong with the response.\n * @param cause - The underlying error, if any.\n * @returns The error.\n */\nexport function invalidApprovalDashboardResponse(\n message: string,\n cause?: unknown,\n): ApprovalDashboardError {\n return new ApprovalDashboardError(\n 'invalid_response',\n `Invalid approval dashboard response: ${message}`,\n { cause },\n );\n}\n\n/**\n * Validate an SAA response body against the contract and the request it\n * answers, applying the contract's fallbacks.\n *\n * @param body - The parsed JSON body.\n * @param request - The SAA request body that produced it.\n * @param request.address - The lowercased requested address.\n * @param request.chainIds - The requested decimal chain IDs.\n * @returns The validated response.\n */\nexport function parseApprovalDashboardResponse(\n body: unknown,\n request: { address: string; chainIds: number[] },\n): ApprovalDashboardResponse {\n // Check the schema major first so a breaking change is reported as such\n // rather than as a field-level validation failure.\n const version = is(body, type({ schemaVersion: string() }))\n ? SCHEMA_VERSION_REGEX.exec(body.schemaVersion)\n : null;\n if (!version) {\n throw invalidApprovalDashboardResponse(\n 'missing or malformed schemaVersion',\n );\n }\n if (Number(version[1]) !== SUPPORTED_SCHEMA_MAJOR) {\n throw new ApprovalDashboardError(\n 'incompatible_schema',\n `Unsupported approval dashboard schema version ${version[0]}`,\n );\n }\n\n const [error, response] = validate(body, ResponseStruct, { coerce: true });\n if (error) {\n throw invalidApprovalDashboardResponse(error.message, error);\n }\n\n const answered = response.chainResults.map(({ chainId }) => chainId);\n if (\n answered.length !== request.chainIds.length ||\n !request.chainIds.every((chainId) => answered.includes(chainId))\n ) {\n throw invalidApprovalDashboardResponse(\n 'chainResults do not match the requested chains',\n );\n }\n for (const record of [response, ...response.records]) {\n if (record.account.toLowerCase() !== request.address) {\n throw invalidApprovalDashboardResponse(\n 'account does not match the requested address',\n );\n }\n }\n if (response.records.some(({ chainId }) => !answered.includes(chainId))) {\n throw invalidApprovalDashboardResponse('record for an unrequested chain');\n }\n\n return response;\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
export * from './PhishingController.js';
|
|
2
2
|
export { findSimilarAddresses } from './address-poisoning.js';
|
|
3
|
+
export { ApprovalDashboardError } from './approval-dashboard.js';
|
|
4
|
+
export { SecurityAlertsApiService } from './SecurityAlertsApiService.js';
|
|
5
|
+
export type { SecurityAlertsApiServiceActions, SecurityAlertsApiServiceEvents, SecurityAlertsApiServiceMessenger, SecurityAlertsApiServiceOptions, } from './SecurityAlertsApiService.js';
|
|
6
|
+
export type { SecurityAlertsApiServiceGetApprovalDashboardAction } from './SecurityAlertsApiService-method-action-types.js';
|
|
7
|
+
export type { ApprovalDashboardChainResult, ApprovalDashboardErrorCode, ApprovalDashboardRecord, ApprovalDashboardRequest, ApprovalDashboardResponse, } from './approval-dashboard.js';
|
|
3
8
|
export type { LegacyPhishingDetectorList, PhishingDetectorList, FuzzyTolerance, PhishingDetectorOptions, PhishingDetectorConfiguration, } from './PhishingDetector.js';
|
|
4
9
|
export { PhishingDetector } from './PhishingDetector.js';
|
|
5
10
|
export type { PhishingDetectionScanResult, AddressScanResult, BulkTokenScanResponse, SimilarAddressMatch, SimilarityOptions, ApprovalsResponse, Approval, Allowance, ApprovalAsset, Exposure, Spender, ApprovalFeature, } from './types.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,YAAY,EACV,0BAA0B,EAC1B,oBAAoB,EACpB,cAAc,EACd,uBAAuB,EACvB,6BAA6B,GAC9B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,gBA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C3C,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACtB,iBAAiB,EACjB,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,YAAY,EACV,wCAAwC,EACxC,kCAAkC,EAClC,wCAAwC,EACxC,8BAA8B,EAC9B,+BAA+B,EAC/B,oCAAoC,EACpC,sCAAsC,EACtC,mCAAmC,EACnC,oCAAoC,EACpC,6CAA6C,GAC9C,MAAM,6CAA6C,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export * from './PhishingController.js';
|
|
2
2
|
export { findSimilarAddresses } from './address-poisoning.js';
|
|
3
|
+
export { ApprovalDashboardError } from './approval-dashboard.js';
|
|
4
|
+
export { SecurityAlertsApiService } from './SecurityAlertsApiService.js';
|
|
3
5
|
export { PhishingDetector } from './PhishingDetector.js';
|
|
4
6
|
export { TokenScanResultType } from './types.js';
|
|
5
7
|
export { PhishingDetectorResultType, RecommendedAction, AddressScanResultType, ApprovalResultType, ApprovalFeatureType, } from './types.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAsBzE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAgBzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EACL,0BAA0B,EAC1B,iBAAiB,EACjB,qBAAqB,EACrB,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,0CAA0C,EAC1C,gCAAgC,EAChC,6BAA6B,EAC7B,oCAAoC,GACrC,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,yBAAyB,EACzB,+BAA+B,EAC/B,+BAA+B,GAChC,MAAM,mCAAmC,CAAC;AAK3C,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACtB,iBAAiB,EACjB,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,qBAAqB,CAAC","sourcesContent":["export * from './PhishingController.js';\nexport { findSimilarAddresses } from './address-poisoning.js';\nexport { ApprovalDashboardError } from './approval-dashboard.js';\nexport { SecurityAlertsApiService } from './SecurityAlertsApiService.js';\nexport type {\n SecurityAlertsApiServiceActions,\n SecurityAlertsApiServiceEvents,\n SecurityAlertsApiServiceMessenger,\n SecurityAlertsApiServiceOptions,\n} from './SecurityAlertsApiService.js';\nexport type { SecurityAlertsApiServiceGetApprovalDashboardAction } from './SecurityAlertsApiService-method-action-types.js';\nexport type {\n ApprovalDashboardChainResult,\n ApprovalDashboardErrorCode,\n ApprovalDashboardRecord,\n ApprovalDashboardRequest,\n ApprovalDashboardResponse,\n} from './approval-dashboard.js';\nexport type {\n LegacyPhishingDetectorList,\n PhishingDetectorList,\n FuzzyTolerance,\n PhishingDetectorOptions,\n PhishingDetectorConfiguration,\n} from './PhishingDetector.js';\nexport { PhishingDetector } from './PhishingDetector.js';\nexport type {\n PhishingDetectionScanResult,\n AddressScanResult,\n BulkTokenScanResponse,\n SimilarAddressMatch,\n SimilarityOptions,\n ApprovalsResponse,\n Approval,\n Allowance,\n ApprovalAsset,\n Exposure,\n Spender,\n ApprovalFeature,\n} from './types.js';\nexport type { TokenScanCacheData } from './types.js';\nexport { TokenScanResultType } from './types.js';\nexport {\n PhishingDetectorResultType,\n RecommendedAction,\n AddressScanResultType,\n ApprovalResultType,\n ApprovalFeatureType,\n} from './types.js';\nexport type { CacheEntry } from './CacheManager.js';\nexport {\n PHISHING_DETECTION_PATH_BASED_ROOT_DOMAINS,\n getPhishingDetectionScanUrlParam,\n isAddressScanSupportedChainId,\n isPhishingDetectionPathBasedHostname,\n} from './utils.js';\nexport {\n extractSignatureAddresses,\n DEFAULT_MAX_SIGNATURE_ADDRESSES,\n MAX_SIGNATURE_ADDRESSES_CEILING,\n} from './signature-address-extraction.js';\nexport type {\n ExtractedSignatureAddresses,\n ExtractSignatureAddressesOptions,\n} from './signature-address-extraction.js';\nexport {\n REQUEST_SOURCE_HEADER,\n UNKNOWN_REQUEST_SOURCE,\n RequestSourceFlow,\n RequestSourcePlatform,\n buildRequestSource,\n} from './request-source.js';\nexport type { RequestSource } from './request-source.js';\n\nexport type {\n PhishingControllerMaybeUpdateStateAction,\n PhishingControllerTestOriginAction,\n PhishingControllerIsBlockedRequestAction,\n PhishingControllerBypassAction,\n PhishingControllerScanUrlAction,\n PhishingControllerBulkScanUrlsAction,\n PhishingControllerBulkScanTokensAction,\n PhishingControllerScanAddressAction,\n PhishingControllerGetApprovalsAction,\n PhishingControllerCheckAddressPoisoningAction,\n} from './PhishingController-method-action-types.js';\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/phishing-controller",
|
|
3
|
-
"version": "18.3.1-preview-
|
|
3
|
+
"version": "18.3.1-preview-2da314d6d",
|
|
4
4
|
"description": "Maintains a periodically updated list of approved and unapproved website origins",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ethereum",
|
|
@@ -54,9 +54,12 @@
|
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@metamask/address-book-controller": "^8.0.0",
|
|
56
56
|
"@metamask/base-controller": "^10.1.0",
|
|
57
|
+
"@metamask/base-data-service": "^2.1.0",
|
|
57
58
|
"@metamask/controller-utils": "^13.0.0",
|
|
58
59
|
"@metamask/messenger": "^3.0.0",
|
|
60
|
+
"@metamask/superstruct": "^3.4.1",
|
|
59
61
|
"@metamask/transaction-controller": "^74.2.0",
|
|
62
|
+
"@metamask/utils": "^12.0.2",
|
|
60
63
|
"@noble/hashes": "^1.8.0",
|
|
61
64
|
"@types/punycode": "^2.1.4",
|
|
62
65
|
"ethereum-cryptography": "^3.2.0",
|