@metamask-previews/snap-networks-utils 3.0.0-preview-fea83f42 → 3.0.0-preview-e8c01cec
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/dist/clients/security-alerts-api/SecurityAlertsApiClient.d.mts +1 -1
- package/dist/clients/security-alerts-api/SecurityAlertsApiClient.d.mts.map +1 -1
- package/dist/clients/security-alerts-api/SecurityAlertsApiClient.mjs +1 -0
- package/dist/clients/security-alerts-api/SecurityAlertsApiClient.mjs.map +1 -1
- package/package.json +2 -2
|
@@ -54,6 +54,6 @@ export declare class SecurityAlertsApiClient {
|
|
|
54
54
|
* @throws HttpError if the request fails, the API responds
|
|
55
55
|
* with a non-2xx status, or the response body cannot be parsed as JSON.
|
|
56
56
|
*/
|
|
57
|
-
scanTransaction(body: unknown): Promise<
|
|
57
|
+
scanTransaction(body: unknown): Promise<any>;
|
|
58
58
|
}
|
|
59
59
|
//# sourceMappingURL=SecurityAlertsApiClient.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SecurityAlertsApiClient.d.mts","sourceRoot":"","sources":["../../../src/clients/security-alerts-api/SecurityAlertsApiClient.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,2DAAuD;AAYlF;;GAEG;AACH,eAAO,MAAM,+BAA+B,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAGlE,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,8BAA8B,GAAG;IAC3C;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB,uEAAuE;IACvE,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IAChC;;;;OAIG;IACH,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,qBAAa,uBAAuB;;IAOlC;;;;;;;;;;OAUG;gBACS,EACV,OAAO,EACP,KAAK,EAAE,OAA0B,EACjC,MAAM,GACP,EAAE,8BAA8B;IAQjC;;;;;;;OAOG;
|
|
1
|
+
{"version":3,"file":"SecurityAlertsApiClient.d.mts","sourceRoot":"","sources":["../../../src/clients/security-alerts-api/SecurityAlertsApiClient.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,2DAAuD;AAYlF;;GAEG;AACH,eAAO,MAAM,+BAA+B,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAGlE,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,8BAA8B,GAAG;IAC3C;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB,uEAAuE;IACvE,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IAChC;;;;OAIG;IACH,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,qBAAa,uBAAuB;;IAOlC;;;;;;;;;;OAUG;gBACS,EACV,OAAO,EACP,KAAK,EAAE,OAA0B,EACjC,MAAM,GACP,EAAE,8BAA8B;IAQjC;;;;;;;OAOG;IAEG,eAAe,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC;CAyCnD"}
|
|
@@ -55,6 +55,7 @@ export class SecurityAlertsApiClient {
|
|
|
55
55
|
* @throws HttpError if the request fails, the API responds
|
|
56
56
|
* with a non-2xx status, or the response body cannot be parsed as JSON.
|
|
57
57
|
*/
|
|
58
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
58
59
|
async scanTransaction(body) {
|
|
59
60
|
const request = async () => {
|
|
60
61
|
const response = await this.#fetch(this.#scanUrl, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SecurityAlertsApiClient.mjs","sourceRoot":"","sources":["../../../src/clients/security-alerts-api/SecurityAlertsApiClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,8BAA8B;AAE/C,OAAO,EAAE,SAAS,EAAE,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AM,EAAE,CAAC,EACvD;oBACE,UAAU,EAAE,QAAQ,CAAC,MAAM;oBAC3B,YAAY,EAAE,eAAe,CAAC,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,aAAa,CAAC,CAAC;iBACpE,CACF,CAAC;YACJ,CAAC;YAED,OAAO,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QAC/B,CAAC,CAAC;QAEF,IAAI,CAAC;YACH,OAAO,MAAM,CAAC,IAAI,CAAC,OAAO;gBACxB,CAAC,CAAC,sBAAsB,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC;gBAC/C,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;QACjB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,YAAY,SAAS,EAAE,CAAC;gBAC/B,MAAM,KAAK,CAAC;YACd,CAAC;YAED,MAAM,IAAI,SAAS,CAAC,2BAA2B,EAAE;gBAC/C,KAAK,EACH,KAAK,YAAY,KAAK;oBACtB,KAAK,CAAC,IAAI,KAAK,oBAAoB,CAAC,OAAO;oBAC3C,KAAK,CAAC,KAAK,KAAK,SAAS;oBACvB,CAAC,CAAC,KAAK,CAAC,KAAK;oBACb,CAAC,CAAC,KAAK;aACZ,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF","sourcesContent":["import { assert } from '@metamask/superstruct';\n\nimport { HttpError } from '../../utils/errors';\nimport { FetchPolicyErrorName } from '../../utils/fetchPolicy/createFetchPolicy';\nimport type { FetchPolicy } from '../../utils/fetchPolicy/executeWithFetchPolicy';\nimport {\n executeWithFetchPolicy,\n parseRetryAfter,\n} from '../../utils/fetchPolicy/executeWithFetchPolicy';\nimport { UrlStruct } from '../../utils/urlStruct/urlStruct';\n\n/**\n * The timeout for a single scan request, in milliseconds.\n */\nconst REQUEST_TIMEOUT_MS = 10_000;\n\n/**\n * Headers sent with every Security Alerts API request.\n */\nexport const SECURITY_ALERTS_REQUEST_HEADERS: Record<string, string> = {\n 'Content-Type': 'application/json',\n accept: 'application/json',\n};\n\n/**\n * Options for a `SecurityAlertsApiClient` constructor.\n */\nexport type SecurityAlertsApiClientOptions = {\n /**\n * The full scan endpoint URL, e.g. `https://security-alerts.api.cx.metamask.io/tron/transaction/scan`.\n */\n scanUrl: string;\n /** The fetch implementation to use. Defaults to `globalThis.fetch`. */\n fetch?: typeof globalThis.fetch;\n /**\n * Optional fetch policy (see `createFetchPolicy`). When given, transient\n * failures are retried with backoff and a circuit breaker. Without one, the\n * request is made directly.\n */\n policy?: FetchPolicy;\n};\n\n/**\n * HTTP client for a Security Alerts API scan endpoint.\n *\n * Owns the request envelope shared by every chain — POSTing the JSON body,\n * wrapping request failures, non-2xx responses, and malformed JSON bodies as\n * {@link HttpError}, and parsing the JSON response — and nothing\n * else.\n *\n * The request body is a chain-specific Blockaid contract: the caller\n * supplies a typed body (e.g. checked with `satisfies` against a per-snap\n * body type) and is responsible for validating the parsed response payload.\n */\nexport class SecurityAlertsApiClient {\n readonly #fetch: typeof globalThis.fetch;\n\n readonly #scanUrl: string;\n\n readonly #policy?: FetchPolicy;\n\n /**\n * Creates a new SecurityAlertsApiClient.\n *\n * @param options - The client options.\n * @param options.scanUrl - The full scan endpoint URL. Validated once, so\n * an invalid URL fails fast at construction.\n * @param options.fetch - Optional fetch implementation; defaults to\n * `globalThis.fetch`.\n * @param options.policy - Optional fetch policy for retries and circuit\n * breaking.\n */\n constructor({\n scanUrl,\n fetch: fetchFn = globalThis.fetch,\n policy,\n }: SecurityAlertsApiClientOptions) {\n assert(scanUrl, UrlStruct);\n\n this.#fetch = fetchFn;\n this.#scanUrl = scanUrl;\n this.#policy = policy;\n }\n\n /**\n * Scans a transaction by posting the request body to the scan endpoint.\n *\n * @param body - The chain-specific scan request body.\n * @returns The parsed scan response.\n * @throws HttpError if the request fails, the API responds\n * with a non-2xx status, or the response body cannot be parsed as JSON.\n */\n async scanTransaction(body: unknown): Promise<
|
|
1
|
+
{"version":3,"file":"SecurityAlertsApiClient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BAAkB,CAAC;aAChD,CAAC,CAAC;YAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;gBACjB,MAAM,MAAM,CAAC,MAAM,CACjB,IAAI,SAAS,CAAC,uBAAuB,QAAQ,CAAC,MAAM,EAAE,CAAC,EACvD;oBACE,UAAU,EAAE,QAAQ,CAAC,MAAM;oBAC3B,YAAY,EAAE,eAAe,CAAC,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,aAAa,CAAC,CAAC;iBACpE,CACF,CAAC;YACJ,CAAC;YAED,OAAO,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QAC/B,CAAC,CAAC;QAEF,IAAI,CAAC;YACH,OAAO,MAAM,CAAC,IAAI,CAAC,OAAO;gBACxB,CAAC,CAAC,sBAAsB,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC;gBAC/C,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;QACjB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,YAAY,SAAS,EAAE,CAAC;gBAC/B,MAAM,KAAK,CAAC;YACd,CAAC;YAED,MAAM,IAAI,SAAS,CAAC,2BAA2B,EAAE;gBAC/C,KAAK,EACH,KAAK,YAAY,KAAK;oBACtB,KAAK,CAAC,IAAI,KAAK,oBAAoB,CAAC,OAAO;oBAC3C,KAAK,CAAC,KAAK,KAAK,SAAS;oBACvB,CAAC,CAAC,KAAK,CAAC,KAAK;oBACb,CAAC,CAAC,KAAK;aACZ,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF","sourcesContent":["import { assert } from '@metamask/superstruct';\n\nimport { HttpError } from '../../utils/errors';\nimport { FetchPolicyErrorName } from '../../utils/fetchPolicy/createFetchPolicy';\nimport type { FetchPolicy } from '../../utils/fetchPolicy/executeWithFetchPolicy';\nimport {\n executeWithFetchPolicy,\n parseRetryAfter,\n} from '../../utils/fetchPolicy/executeWithFetchPolicy';\nimport { UrlStruct } from '../../utils/urlStruct/urlStruct';\n\n/**\n * The timeout for a single scan request, in milliseconds.\n */\nconst REQUEST_TIMEOUT_MS = 10_000;\n\n/**\n * Headers sent with every Security Alerts API request.\n */\nexport const SECURITY_ALERTS_REQUEST_HEADERS: Record<string, string> = {\n 'Content-Type': 'application/json',\n accept: 'application/json',\n};\n\n/**\n * Options for a `SecurityAlertsApiClient` constructor.\n */\nexport type SecurityAlertsApiClientOptions = {\n /**\n * The full scan endpoint URL, e.g. `https://security-alerts.api.cx.metamask.io/tron/transaction/scan`.\n */\n scanUrl: string;\n /** The fetch implementation to use. Defaults to `globalThis.fetch`. */\n fetch?: typeof globalThis.fetch;\n /**\n * Optional fetch policy (see `createFetchPolicy`). When given, transient\n * failures are retried with backoff and a circuit breaker. Without one, the\n * request is made directly.\n */\n policy?: FetchPolicy;\n};\n\n/**\n * HTTP client for a Security Alerts API scan endpoint.\n *\n * Owns the request envelope shared by every chain — POSTing the JSON body,\n * wrapping request failures, non-2xx responses, and malformed JSON bodies as\n * {@link HttpError}, and parsing the JSON response — and nothing\n * else.\n *\n * The request body is a chain-specific Blockaid contract: the caller\n * supplies a typed body (e.g. checked with `satisfies` against a per-snap\n * body type) and is responsible for validating the parsed response payload.\n */\nexport class SecurityAlertsApiClient {\n readonly #fetch: typeof globalThis.fetch;\n\n readonly #scanUrl: string;\n\n readonly #policy?: FetchPolicy;\n\n /**\n * Creates a new SecurityAlertsApiClient.\n *\n * @param options - The client options.\n * @param options.scanUrl - The full scan endpoint URL. Validated once, so\n * an invalid URL fails fast at construction.\n * @param options.fetch - Optional fetch implementation; defaults to\n * `globalThis.fetch`.\n * @param options.policy - Optional fetch policy for retries and circuit\n * breaking.\n */\n constructor({\n scanUrl,\n fetch: fetchFn = globalThis.fetch,\n policy,\n }: SecurityAlertsApiClientOptions) {\n assert(scanUrl, UrlStruct);\n\n this.#fetch = fetchFn;\n this.#scanUrl = scanUrl;\n this.#policy = policy;\n }\n\n /**\n * Scans a transaction by posting the request body to the scan endpoint.\n *\n * @param body - The chain-specific scan request body.\n * @returns The parsed scan response.\n * @throws HttpError if the request fails, the API responds\n * with a non-2xx status, or the response body cannot be parsed as JSON.\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n async scanTransaction(body: unknown): Promise<any> {\n const request = async (): Promise<unknown> => {\n const response = await this.#fetch(this.#scanUrl, {\n headers: { ...SECURITY_ALERTS_REQUEST_HEADERS },\n method: 'POST',\n body: JSON.stringify(body),\n signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),\n });\n\n if (!response.ok) {\n throw Object.assign(\n new HttpError(`HTTP error! status: ${response.status}`),\n {\n httpStatus: response.status,\n retryAfterMs: parseRetryAfter(response.headers?.get('Retry-After')),\n },\n );\n }\n\n return await response.json();\n };\n\n try {\n return await (this.#policy\n ? executeWithFetchPolicy(this.#policy, request)\n : request());\n } catch (error) {\n if (error instanceof HttpError) {\n throw error;\n }\n\n throw new HttpError('Security Alerts API error', {\n cause:\n error instanceof Error &&\n error.name === FetchPolicyErrorName.Network &&\n error.cause !== undefined\n ? error.cause\n : error,\n });\n }\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/snap-networks-utils",
|
|
3
|
-
"version": "3.0.0-preview-
|
|
3
|
+
"version": "3.0.0-preview-e8c01cec",
|
|
4
4
|
"description": "Shared utilities for MetaMask network snaps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ethereum",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"test:watch": "jest --watch"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@metamask/assets-controller": "^
|
|
62
|
+
"@metamask/assets-controller": "^19.1.0",
|
|
63
63
|
"@metamask/base-data-service": "^2.1.0",
|
|
64
64
|
"@metamask/keyring-api": "^24.1.0",
|
|
65
65
|
"@metamask/keyring-internal-api": "^12.0.0",
|