@metamask-previews/eth-json-rpc-middleware 21.0.0-preview-c96ff8f → 21.0.0-preview-b289ac1c
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 +0 -3
- package/dist/block-cache.cjs +27 -15
- package/dist/block-cache.cjs.map +1 -1
- package/dist/block-cache.d.cts +3 -5
- package/dist/block-cache.d.cts.map +1 -1
- package/dist/block-cache.d.mts +3 -5
- package/dist/block-cache.d.mts.map +1 -1
- package/dist/block-cache.mjs +27 -15
- package/dist/block-cache.mjs.map +1 -1
- package/dist/block-ref-rewrite.cjs +8 -12
- package/dist/block-ref-rewrite.cjs.map +1 -1
- package/dist/block-ref-rewrite.d.cts +3 -3
- package/dist/block-ref-rewrite.d.cts.map +1 -1
- package/dist/block-ref-rewrite.d.mts +3 -3
- package/dist/block-ref-rewrite.d.mts.map +1 -1
- package/dist/block-ref-rewrite.mjs +8 -12
- package/dist/block-ref-rewrite.mjs.map +1 -1
- package/dist/block-ref.cjs +10 -17
- package/dist/block-ref.cjs.map +1 -1
- package/dist/block-ref.d.cts +3 -12
- package/dist/block-ref.d.cts.map +1 -1
- package/dist/block-ref.d.mts +3 -12
- package/dist/block-ref.d.mts.map +1 -1
- package/dist/block-ref.mjs +10 -17
- package/dist/block-ref.mjs.map +1 -1
- package/dist/block-tracker-inspector.cjs +25 -28
- package/dist/block-tracker-inspector.cjs.map +1 -1
- package/dist/block-tracker-inspector.d.cts +3 -3
- package/dist/block-tracker-inspector.d.cts.map +1 -1
- package/dist/block-tracker-inspector.d.mts +3 -3
- package/dist/block-tracker-inspector.d.mts.map +1 -1
- package/dist/block-tracker-inspector.mjs +25 -28
- package/dist/block-tracker-inspector.mjs.map +1 -1
- package/dist/fetch.cjs +12 -8
- package/dist/fetch.cjs.map +1 -1
- package/dist/fetch.d.cts +3 -5
- package/dist/fetch.d.cts.map +1 -1
- package/dist/fetch.d.mts +3 -5
- package/dist/fetch.d.mts.map +1 -1
- package/dist/fetch.mjs +12 -8
- package/dist/fetch.mjs.map +1 -1
- package/dist/inflight-cache.cjs +45 -61
- package/dist/inflight-cache.cjs.map +1 -1
- package/dist/inflight-cache.d.cts +3 -12
- package/dist/inflight-cache.d.cts.map +1 -1
- package/dist/inflight-cache.d.mts +3 -12
- package/dist/inflight-cache.d.mts.map +1 -1
- package/dist/inflight-cache.mjs +45 -61
- package/dist/inflight-cache.mjs.map +1 -1
- package/dist/methods/wallet-request-execution-permissions.cjs +9 -11
- package/dist/methods/wallet-request-execution-permissions.cjs.map +1 -1
- package/dist/methods/wallet-request-execution-permissions.d.cts +3 -5
- package/dist/methods/wallet-request-execution-permissions.d.cts.map +1 -1
- package/dist/methods/wallet-request-execution-permissions.d.mts +3 -5
- package/dist/methods/wallet-request-execution-permissions.d.mts.map +1 -1
- package/dist/methods/wallet-request-execution-permissions.mjs +7 -9
- package/dist/methods/wallet-request-execution-permissions.mjs.map +1 -1
- package/dist/methods/wallet-revoke-execution-permission.cjs +11 -14
- package/dist/methods/wallet-revoke-execution-permission.cjs.map +1 -1
- package/dist/methods/wallet-revoke-execution-permission.d.cts +5 -10
- package/dist/methods/wallet-revoke-execution-permission.d.cts.map +1 -1
- package/dist/methods/wallet-revoke-execution-permission.d.mts +5 -10
- package/dist/methods/wallet-revoke-execution-permission.d.mts.map +1 -1
- package/dist/methods/wallet-revoke-execution-permission.mjs +8 -11
- package/dist/methods/wallet-revoke-execution-permission.mjs.map +1 -1
- package/dist/providerAsMiddleware.cjs +1 -5
- package/dist/providerAsMiddleware.cjs.map +1 -1
- package/dist/providerAsMiddleware.d.cts +3 -5
- package/dist/providerAsMiddleware.d.cts.map +1 -1
- package/dist/providerAsMiddleware.d.mts +3 -5
- package/dist/providerAsMiddleware.d.mts.map +1 -1
- package/dist/providerAsMiddleware.mjs +0 -3
- package/dist/providerAsMiddleware.mjs.map +1 -1
- package/dist/retryOnEmpty.cjs +11 -8
- package/dist/retryOnEmpty.cjs.map +1 -1
- package/dist/retryOnEmpty.d.cts +3 -3
- package/dist/retryOnEmpty.d.cts.map +1 -1
- package/dist/retryOnEmpty.d.mts +3 -3
- package/dist/retryOnEmpty.d.mts.map +1 -1
- package/dist/retryOnEmpty.mjs +11 -8
- package/dist/retryOnEmpty.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +5 -0
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +5 -0
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/dist/utils/validation.cjs +2 -2
- package/dist/utils/validation.cjs.map +1 -1
- package/dist/utils/validation.d.cts +3 -6
- package/dist/utils/validation.d.cts.map +1 -1
- package/dist/utils/validation.d.mts +3 -6
- package/dist/utils/validation.d.mts.map +1 -1
- package/dist/utils/validation.mjs +2 -2
- package/dist/utils/validation.mjs.map +1 -1
- package/dist/wallet.cjs +92 -87
- package/dist/wallet.cjs.map +1 -1
- package/dist/wallet.d.cts +5 -8
- package/dist/wallet.d.cts.map +1 -1
- package/dist/wallet.d.mts +5 -8
- package/dist/wallet.d.mts.map +1 -1
- package/dist/wallet.mjs +93 -88
- package/dist/wallet.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet-revoke-execution-permission.cjs","sourceRoot":"","sources":["../../src/methods/wallet-revoke-execution-permission.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"wallet-revoke-execution-permission.cjs","sourceRoot":"","sources":["../../src/methods/wallet-revoke-execution-permission.ts"],"names":[],"mappings":";;;AAAA,qDAAiD;AAEjD,2CAKyB;AAEzB,wDAAqD;AAExC,QAAA,qCAAqC,GAAG,IAAA,cAAM,EAAC,EAAE,CAAC,CAAC;AAMnD,QAAA,4CAA4C,GAAG,IAAA,cAAM,EAAC;IACjE,iBAAiB,EAAE,uBAAe;CACnC,CAAC,CAAC;AAWI,KAAK,UAAU,+BAA+B,CACnD,GAAmB,EACnB,GAA2B,EAC3B,EACE,gCAAgC,GAGjC;IAED,IAAI,CAAC,gCAAgC,EAAE;QACrC,MAAM,sBAAS,CAAC,kBAAkB,CAChC,6DAA6D,CAC9D,CAAC;KACH;IAED,MAAM,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC;IAEvB,IAAA,2BAAc,EAAC,MAAM,EAAE,oDAA4C,CAAC,CAAC;IAErE,GAAG,CAAC,MAAM,GAAG,MAAM,gCAAgC,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AACnE,CAAC;AApBD,0EAoBC","sourcesContent":["import { rpcErrors } from '@metamask/rpc-errors';\nimport type { Infer } from '@metamask/superstruct';\nimport {\n type JsonRpcRequest,\n object,\n type PendingJsonRpcResponse,\n StrictHexStruct,\n} from '@metamask/utils';\n\nimport { validateParams } from '../utils/validation';\n\nexport const RevokeExecutionPermissionResultStruct = object({});\n\nexport type RevokeExecutionPermissionResult = Infer<\n typeof RevokeExecutionPermissionResultStruct\n>;\n\nexport const RevokeExecutionPermissionRequestParamsStruct = object({\n permissionContext: StrictHexStruct,\n});\n\nexport type RevokeExecutionPermissionRequestParams = Infer<\n typeof RevokeExecutionPermissionRequestParamsStruct\n>;\n\nexport type ProcessRevokeExecutionPermissionHook = (\n request: RevokeExecutionPermissionRequestParams,\n req: JsonRpcRequest,\n) => Promise<RevokeExecutionPermissionResult>;\n\nexport async function walletRevokeExecutionPermission(\n req: JsonRpcRequest,\n res: PendingJsonRpcResponse,\n {\n processRevokeExecutionPermission,\n }: {\n processRevokeExecutionPermission?: ProcessRevokeExecutionPermissionHook;\n },\n): Promise<void> {\n if (!processRevokeExecutionPermission) {\n throw rpcErrors.methodNotSupported(\n 'wallet_revokeExecutionPermission - no middleware configured',\n );\n }\n\n const { params } = req;\n\n validateParams(params, RevokeExecutionPermissionRequestParamsStruct);\n\n res.result = await processRevokeExecutionPermission(params, req);\n}\n"]}
|
|
@@ -1,18 +1,13 @@
|
|
|
1
|
-
import type { JsonRpcMiddleware } from "@metamask/json-rpc-engine/v2";
|
|
2
1
|
import type { Infer } from "@metamask/superstruct";
|
|
3
|
-
import type
|
|
4
|
-
|
|
5
|
-
import type { WalletMiddlewareContext } from "../wallet.cjs";
|
|
6
|
-
export declare const RevokeExecutionPermissionResultStruct: import("@metamask/superstruct").Struct<{}, {}>;
|
|
2
|
+
import { type JsonRpcRequest, type PendingJsonRpcResponse } from "@metamask/utils";
|
|
3
|
+
export declare const RevokeExecutionPermissionResultStruct: import("@metamask/superstruct").Struct<{}, unknown>;
|
|
7
4
|
export type RevokeExecutionPermissionResult = Infer<typeof RevokeExecutionPermissionResultStruct>;
|
|
8
5
|
export declare const RevokeExecutionPermissionRequestParamsStruct: import("@metamask/superstruct").Struct<{
|
|
9
6
|
permissionContext: `0x${string}`;
|
|
10
|
-
},
|
|
11
|
-
permissionContext: import("@metamask/superstruct").Struct<`0x${string}`, null>;
|
|
12
|
-
}>;
|
|
7
|
+
}, unknown>;
|
|
13
8
|
export type RevokeExecutionPermissionRequestParams = Infer<typeof RevokeExecutionPermissionRequestParamsStruct>;
|
|
14
9
|
export type ProcessRevokeExecutionPermissionHook = (request: RevokeExecutionPermissionRequestParams, req: JsonRpcRequest) => Promise<RevokeExecutionPermissionResult>;
|
|
15
|
-
export declare function
|
|
10
|
+
export declare function walletRevokeExecutionPermission(req: JsonRpcRequest, res: PendingJsonRpcResponse, { processRevokeExecutionPermission, }: {
|
|
16
11
|
processRevokeExecutionPermission?: ProcessRevokeExecutionPermissionHook;
|
|
17
|
-
}):
|
|
12
|
+
}): Promise<void>;
|
|
18
13
|
//# sourceMappingURL=wallet-revoke-execution-permission.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet-revoke-execution-permission.d.cts","sourceRoot":"","sources":["../../src/methods/wallet-revoke-execution-permission.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"wallet-revoke-execution-permission.d.cts","sourceRoot":"","sources":["../../src/methods/wallet-revoke-execution-permission.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AACnD,OAAO,EACL,KAAK,cAAc,EAEnB,KAAK,sBAAsB,EAE5B,wBAAwB;AAIzB,eAAO,MAAM,qCAAqC,qDAAa,CAAC;AAEhE,MAAM,MAAM,+BAA+B,GAAG,KAAK,CACjD,OAAO,qCAAqC,CAC7C,CAAC;AAEF,eAAO,MAAM,4CAA4C;;WAEvD,CAAC;AAEH,MAAM,MAAM,sCAAsC,GAAG,KAAK,CACxD,OAAO,4CAA4C,CACpD,CAAC;AAEF,MAAM,MAAM,oCAAoC,GAAG,CACjD,OAAO,EAAE,sCAAsC,EAC/C,GAAG,EAAE,cAAc,KAChB,OAAO,CAAC,+BAA+B,CAAC,CAAC;AAE9C,wBAAsB,+BAA+B,CACnD,GAAG,EAAE,cAAc,EACnB,GAAG,EAAE,sBAAsB,EAC3B,EACE,gCAAgC,GACjC,EAAE;IACD,gCAAgC,CAAC,EAAE,oCAAoC,CAAC;CACzE,GACA,OAAO,CAAC,IAAI,CAAC,CAYf"}
|
|
@@ -1,18 +1,13 @@
|
|
|
1
|
-
import type { JsonRpcMiddleware } from "@metamask/json-rpc-engine/v2";
|
|
2
1
|
import type { Infer } from "@metamask/superstruct";
|
|
3
|
-
import type
|
|
4
|
-
|
|
5
|
-
import type { WalletMiddlewareContext } from "../wallet.mjs";
|
|
6
|
-
export declare const RevokeExecutionPermissionResultStruct: import("@metamask/superstruct").Struct<{}, {}>;
|
|
2
|
+
import { type JsonRpcRequest, type PendingJsonRpcResponse } from "@metamask/utils";
|
|
3
|
+
export declare const RevokeExecutionPermissionResultStruct: import("@metamask/superstruct").Struct<{}, unknown>;
|
|
7
4
|
export type RevokeExecutionPermissionResult = Infer<typeof RevokeExecutionPermissionResultStruct>;
|
|
8
5
|
export declare const RevokeExecutionPermissionRequestParamsStruct: import("@metamask/superstruct").Struct<{
|
|
9
6
|
permissionContext: `0x${string}`;
|
|
10
|
-
},
|
|
11
|
-
permissionContext: import("@metamask/superstruct").Struct<`0x${string}`, null>;
|
|
12
|
-
}>;
|
|
7
|
+
}, unknown>;
|
|
13
8
|
export type RevokeExecutionPermissionRequestParams = Infer<typeof RevokeExecutionPermissionRequestParamsStruct>;
|
|
14
9
|
export type ProcessRevokeExecutionPermissionHook = (request: RevokeExecutionPermissionRequestParams, req: JsonRpcRequest) => Promise<RevokeExecutionPermissionResult>;
|
|
15
|
-
export declare function
|
|
10
|
+
export declare function walletRevokeExecutionPermission(req: JsonRpcRequest, res: PendingJsonRpcResponse, { processRevokeExecutionPermission, }: {
|
|
16
11
|
processRevokeExecutionPermission?: ProcessRevokeExecutionPermissionHook;
|
|
17
|
-
}):
|
|
12
|
+
}): Promise<void>;
|
|
18
13
|
//# sourceMappingURL=wallet-revoke-execution-permission.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet-revoke-execution-permission.d.mts","sourceRoot":"","sources":["../../src/methods/wallet-revoke-execution-permission.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"wallet-revoke-execution-permission.d.mts","sourceRoot":"","sources":["../../src/methods/wallet-revoke-execution-permission.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AACnD,OAAO,EACL,KAAK,cAAc,EAEnB,KAAK,sBAAsB,EAE5B,wBAAwB;AAIzB,eAAO,MAAM,qCAAqC,qDAAa,CAAC;AAEhE,MAAM,MAAM,+BAA+B,GAAG,KAAK,CACjD,OAAO,qCAAqC,CAC7C,CAAC;AAEF,eAAO,MAAM,4CAA4C;;WAEvD,CAAC;AAEH,MAAM,MAAM,sCAAsC,GAAG,KAAK,CACxD,OAAO,4CAA4C,CACpD,CAAC;AAEF,MAAM,MAAM,oCAAoC,GAAG,CACjD,OAAO,EAAE,sCAAsC,EAC/C,GAAG,EAAE,cAAc,KAChB,OAAO,CAAC,+BAA+B,CAAC,CAAC;AAE9C,wBAAsB,+BAA+B,CACnD,GAAG,EAAE,cAAc,EACnB,GAAG,EAAE,sBAAsB,EAC3B,EACE,gCAAgC,GACjC,EAAE;IACD,gCAAgC,CAAC,EAAE,oCAAoC,CAAC;CACzE,GACA,OAAO,CAAC,IAAI,CAAC,CAYf"}
|
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
import { rpcErrors } from "@metamask/rpc-errors";
|
|
2
|
-
import { object } from "@metamask/
|
|
3
|
-
import { StrictHexStruct } from "@metamask/utils";
|
|
2
|
+
import { object, StrictHexStruct } from "@metamask/utils";
|
|
4
3
|
import { validateParams } from "../utils/validation.mjs";
|
|
5
4
|
export const RevokeExecutionPermissionResultStruct = object({});
|
|
6
5
|
export const RevokeExecutionPermissionRequestParamsStruct = object({
|
|
7
6
|
permissionContext: StrictHexStruct,
|
|
8
7
|
});
|
|
9
|
-
export function
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return await processRevokeExecutionPermission(params, request);
|
|
17
|
-
};
|
|
8
|
+
export async function walletRevokeExecutionPermission(req, res, { processRevokeExecutionPermission, }) {
|
|
9
|
+
if (!processRevokeExecutionPermission) {
|
|
10
|
+
throw rpcErrors.methodNotSupported('wallet_revokeExecutionPermission - no middleware configured');
|
|
11
|
+
}
|
|
12
|
+
const { params } = req;
|
|
13
|
+
validateParams(params, RevokeExecutionPermissionRequestParamsStruct);
|
|
14
|
+
res.result = await processRevokeExecutionPermission(params, req);
|
|
18
15
|
}
|
|
19
16
|
//# sourceMappingURL=wallet-revoke-execution-permission.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet-revoke-execution-permission.mjs","sourceRoot":"","sources":["../../src/methods/wallet-revoke-execution-permission.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"wallet-revoke-execution-permission.mjs","sourceRoot":"","sources":["../../src/methods/wallet-revoke-execution-permission.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,6BAA6B;AAEjD,OAAO,EAEL,MAAM,EAEN,eAAe,EAChB,wBAAwB;AAEzB,OAAO,EAAE,cAAc,EAAE,gCAA4B;AAErD,MAAM,CAAC,MAAM,qCAAqC,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC;AAMhE,MAAM,CAAC,MAAM,4CAA4C,GAAG,MAAM,CAAC;IACjE,iBAAiB,EAAE,eAAe;CACnC,CAAC,CAAC;AAWH,MAAM,CAAC,KAAK,UAAU,+BAA+B,CACnD,GAAmB,EACnB,GAA2B,EAC3B,EACE,gCAAgC,GAGjC;IAED,IAAI,CAAC,gCAAgC,EAAE;QACrC,MAAM,SAAS,CAAC,kBAAkB,CAChC,6DAA6D,CAC9D,CAAC;KACH;IAED,MAAM,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC;IAEvB,cAAc,CAAC,MAAM,EAAE,4CAA4C,CAAC,CAAC;IAErE,GAAG,CAAC,MAAM,GAAG,MAAM,gCAAgC,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AACnE,CAAC","sourcesContent":["import { rpcErrors } from '@metamask/rpc-errors';\nimport type { Infer } from '@metamask/superstruct';\nimport {\n type JsonRpcRequest,\n object,\n type PendingJsonRpcResponse,\n StrictHexStruct,\n} from '@metamask/utils';\n\nimport { validateParams } from '../utils/validation';\n\nexport const RevokeExecutionPermissionResultStruct = object({});\n\nexport type RevokeExecutionPermissionResult = Infer<\n typeof RevokeExecutionPermissionResultStruct\n>;\n\nexport const RevokeExecutionPermissionRequestParamsStruct = object({\n permissionContext: StrictHexStruct,\n});\n\nexport type RevokeExecutionPermissionRequestParams = Infer<\n typeof RevokeExecutionPermissionRequestParamsStruct\n>;\n\nexport type ProcessRevokeExecutionPermissionHook = (\n request: RevokeExecutionPermissionRequestParams,\n req: JsonRpcRequest,\n) => Promise<RevokeExecutionPermissionResult>;\n\nexport async function walletRevokeExecutionPermission(\n req: JsonRpcRequest,\n res: PendingJsonRpcResponse,\n {\n processRevokeExecutionPermission,\n }: {\n processRevokeExecutionPermission?: ProcessRevokeExecutionPermissionHook;\n },\n): Promise<void> {\n if (!processRevokeExecutionPermission) {\n throw rpcErrors.methodNotSupported(\n 'wallet_revokeExecutionPermission - no middleware configured',\n );\n }\n\n const { params } = req;\n\n validateParams(params, RevokeExecutionPermissionRequestParamsStruct);\n\n res.result = await processRevokeExecutionPermission(params, req);\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.providerAsMiddleware = void 0;
|
|
4
4
|
const json_rpc_engine_1 = require("@metamask/json-rpc-engine");
|
|
5
5
|
function providerAsMiddleware(provider) {
|
|
6
6
|
return (0, json_rpc_engine_1.createAsyncMiddleware)(async (req, res) => {
|
|
@@ -8,8 +8,4 @@ function providerAsMiddleware(provider) {
|
|
|
8
8
|
});
|
|
9
9
|
}
|
|
10
10
|
exports.providerAsMiddleware = providerAsMiddleware;
|
|
11
|
-
function providerAsMiddlewareV2(provider) {
|
|
12
|
-
return async ({ request }) => provider.request(request);
|
|
13
|
-
}
|
|
14
|
-
exports.providerAsMiddlewareV2 = providerAsMiddlewareV2;
|
|
15
11
|
//# sourceMappingURL=providerAsMiddleware.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"providerAsMiddleware.cjs","sourceRoot":"","sources":["../src/providerAsMiddleware.ts"],"names":[],"mappings":";;;AACA,+DAGmC;
|
|
1
|
+
{"version":3,"file":"providerAsMiddleware.cjs","sourceRoot":"","sources":["../src/providerAsMiddleware.ts"],"names":[],"mappings":";;;AACA,+DAGmC;AAGnC,SAAgB,oBAAoB,CAClC,QAA0B;IAE1B,OAAO,IAAA,uCAAqB,EAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE;QAC9C,GAAG,CAAC,MAAM,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC3C,CAAC,CAAC,CAAC;AACL,CAAC;AAND,oDAMC","sourcesContent":["import type { InternalProvider } from '@metamask/eth-json-rpc-provider';\nimport {\n createAsyncMiddleware,\n type JsonRpcMiddleware,\n} from '@metamask/json-rpc-engine';\nimport type { Json, JsonRpcParams } from '@metamask/utils';\n\nexport function providerAsMiddleware(\n provider: InternalProvider,\n): JsonRpcMiddleware<JsonRpcParams, Json> {\n return createAsyncMiddleware(async (req, res) => {\n res.result = await provider.request(req);\n });\n}\n"]}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import type { InternalProvider } from "@metamask/eth-json-rpc-provider";
|
|
2
|
-
import { type JsonRpcMiddleware
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
export declare function providerAsMiddleware(provider: InternalProvider): LegacyJsonRpcMiddleware<JsonRpcParams, Json>;
|
|
6
|
-
export declare function providerAsMiddlewareV2(provider: InternalProvider): JsonRpcMiddleware<JsonRpcRequest, Json>;
|
|
2
|
+
import { type JsonRpcMiddleware } from "@metamask/json-rpc-engine";
|
|
3
|
+
import type { Json, JsonRpcParams } from "@metamask/utils";
|
|
4
|
+
export declare function providerAsMiddleware(provider: InternalProvider): JsonRpcMiddleware<JsonRpcParams, Json>;
|
|
7
5
|
//# sourceMappingURL=providerAsMiddleware.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"providerAsMiddleware.d.cts","sourceRoot":"","sources":["../src/providerAsMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,wCAAwC;AACxE,OAAO,EAEL,KAAK,iBAAiB,
|
|
1
|
+
{"version":3,"file":"providerAsMiddleware.d.cts","sourceRoot":"","sources":["../src/providerAsMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,wCAAwC;AACxE,OAAO,EAEL,KAAK,iBAAiB,EACvB,kCAAkC;AACnC,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,wBAAwB;AAE3D,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,gBAAgB,GACzB,iBAAiB,CAAC,aAAa,EAAE,IAAI,CAAC,CAIxC"}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import type { InternalProvider } from "@metamask/eth-json-rpc-provider";
|
|
2
|
-
import { type JsonRpcMiddleware
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
export declare function providerAsMiddleware(provider: InternalProvider): LegacyJsonRpcMiddleware<JsonRpcParams, Json>;
|
|
6
|
-
export declare function providerAsMiddlewareV2(provider: InternalProvider): JsonRpcMiddleware<JsonRpcRequest, Json>;
|
|
2
|
+
import { type JsonRpcMiddleware } from "@metamask/json-rpc-engine";
|
|
3
|
+
import type { Json, JsonRpcParams } from "@metamask/utils";
|
|
4
|
+
export declare function providerAsMiddleware(provider: InternalProvider): JsonRpcMiddleware<JsonRpcParams, Json>;
|
|
7
5
|
//# sourceMappingURL=providerAsMiddleware.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"providerAsMiddleware.d.mts","sourceRoot":"","sources":["../src/providerAsMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,wCAAwC;AACxE,OAAO,EAEL,KAAK,iBAAiB,
|
|
1
|
+
{"version":3,"file":"providerAsMiddleware.d.mts","sourceRoot":"","sources":["../src/providerAsMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,wCAAwC;AACxE,OAAO,EAEL,KAAK,iBAAiB,EACvB,kCAAkC;AACnC,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,wBAAwB;AAE3D,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,gBAAgB,GACzB,iBAAiB,CAAC,aAAa,EAAE,IAAI,CAAC,CAIxC"}
|
|
@@ -4,7 +4,4 @@ export function providerAsMiddleware(provider) {
|
|
|
4
4
|
res.result = await provider.request(req);
|
|
5
5
|
});
|
|
6
6
|
}
|
|
7
|
-
export function providerAsMiddlewareV2(provider) {
|
|
8
|
-
return async ({ request }) => provider.request(request);
|
|
9
|
-
}
|
|
10
7
|
//# sourceMappingURL=providerAsMiddleware.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"providerAsMiddleware.mjs","sourceRoot":"","sources":["../src/providerAsMiddleware.ts"],"names":[],"mappings":"AACA,OAAO,EACL,qBAAqB,EAEtB,kCAAkC;
|
|
1
|
+
{"version":3,"file":"providerAsMiddleware.mjs","sourceRoot":"","sources":["../src/providerAsMiddleware.ts"],"names":[],"mappings":"AACA,OAAO,EACL,qBAAqB,EAEtB,kCAAkC;AAGnC,MAAM,UAAU,oBAAoB,CAClC,QAA0B;IAE1B,OAAO,qBAAqB,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE;QAC9C,GAAG,CAAC,MAAM,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC3C,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { InternalProvider } from '@metamask/eth-json-rpc-provider';\nimport {\n createAsyncMiddleware,\n type JsonRpcMiddleware,\n} from '@metamask/json-rpc-engine';\nimport type { Json, JsonRpcParams } from '@metamask/utils';\n\nexport function providerAsMiddleware(\n provider: InternalProvider,\n): JsonRpcMiddleware<JsonRpcParams, Json> {\n return createAsyncMiddleware(async (req, res) => {\n res.result = await provider.request(req);\n });\n}\n"]}
|
package/dist/retryOnEmpty.cjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createRetryOnEmptyMiddleware = void 0;
|
|
4
|
-
const
|
|
4
|
+
const json_rpc_engine_1 = require("@metamask/json-rpc-engine");
|
|
5
|
+
const full_1 = require("klona/full");
|
|
5
6
|
const logging_utils_1 = require("./logging-utils.cjs");
|
|
6
7
|
const cache_1 = require("./utils/cache.cjs");
|
|
7
8
|
const error_1 = require("./utils/error.cjs");
|
|
@@ -31,15 +32,15 @@ function createRetryOnEmptyMiddleware({ provider, blockTracker, } = {}) {
|
|
|
31
32
|
if (!blockTracker) {
|
|
32
33
|
throw Error('RetryOnEmptyMiddleware - mandatory "blockTracker" option is missing.');
|
|
33
34
|
}
|
|
34
|
-
return async (
|
|
35
|
-
const blockRefIndex = (0, cache_1.blockTagParamIndex)(
|
|
35
|
+
return (0, json_rpc_engine_1.createAsyncMiddleware)(async (req, res, next) => {
|
|
36
|
+
const blockRefIndex = (0, cache_1.blockTagParamIndex)(req.method);
|
|
36
37
|
// skip if method does not include blockRef
|
|
37
38
|
if (blockRefIndex === undefined) {
|
|
38
39
|
return next();
|
|
39
40
|
}
|
|
40
41
|
// skip if not exact block references
|
|
41
|
-
let blockRef = Array.isArray(
|
|
42
|
-
?
|
|
42
|
+
let blockRef = Array.isArray(req.params) && req.params[blockRefIndex]
|
|
43
|
+
? req.params[blockRefIndex]
|
|
43
44
|
: undefined;
|
|
44
45
|
// omitted blockRef implies "latest"
|
|
45
46
|
if (blockRef === undefined) {
|
|
@@ -64,7 +65,7 @@ function createRetryOnEmptyMiddleware({ provider, blockTracker, } = {}) {
|
|
|
64
65
|
}
|
|
65
66
|
log('Requested block number %o is not higher than latest block number %o, trying request until non-empty response is received', blockRefNumber, latestBlockNumber);
|
|
66
67
|
// create child request with specific block-ref
|
|
67
|
-
const childRequest = (0,
|
|
68
|
+
const childRequest = (0, full_1.klona)(req);
|
|
68
69
|
// attempt child request until non-empty response is received
|
|
69
70
|
const childResult = await retry(10, async () => {
|
|
70
71
|
log('Performing request %o', childRequest);
|
|
@@ -78,8 +79,10 @@ function createRetryOnEmptyMiddleware({ provider, blockTracker, } = {}) {
|
|
|
78
79
|
return attemptResult;
|
|
79
80
|
});
|
|
80
81
|
log('Copying result %o', childResult);
|
|
81
|
-
|
|
82
|
-
|
|
82
|
+
// copy child result onto original response
|
|
83
|
+
res.result = childResult;
|
|
84
|
+
return undefined;
|
|
85
|
+
});
|
|
83
86
|
}
|
|
84
87
|
exports.createRetryOnEmptyMiddleware = createRetryOnEmptyMiddleware;
|
|
85
88
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retryOnEmpty.cjs","sourceRoot":"","sources":["../src/retryOnEmpty.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"retryOnEmpty.cjs","sourceRoot":"","sources":["../src/retryOnEmpty.ts"],"names":[],"mappings":"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","sourcesContent":["import type { PollingBlockTracker } from '@metamask/eth-block-tracker';\nimport type { InternalProvider } from '@metamask/eth-json-rpc-provider';\nimport type { JsonRpcMiddleware } from '@metamask/json-rpc-engine';\nimport { createAsyncMiddleware } from '@metamask/json-rpc-engine';\nimport type { Json, JsonRpcParams } from '@metamask/utils';\nimport { klona } from 'klona/full';\n\nimport { projectLogger, createModuleLogger } from './logging-utils';\nimport type { Block } from './types';\nimport { blockTagParamIndex } from './utils/cache';\nimport { isExecutionRevertedError } from './utils/error';\nimport { timeout } from './utils/timeout';\n\n//\n// RetryOnEmptyMiddleware will retry any request with an empty response that has\n// a numbered block reference at or lower than the blockTracker's latest block.\n// Its useful for dealing with load-balanced ethereum JSON RPC\n// nodes that are not always in sync with each other.\n//\n\nconst log = createModuleLogger(projectLogger, 'retry-on-empty');\n// empty values used to determine if a request should be retried\n// `<nil>` comes from https://github.com/ethereum/go-ethereum/issues/16925\nconst emptyValues = [null, '\\u003cnil\\u003e'];\n\n/**\n * Creates a middleware that retries requests with empty responses.\n *\n * @param options - The options for the middleware.\n * @param options.provider - The provider to use.\n * @param options.blockTracker - The block tracker to use.\n * @returns The middleware.\n */\nexport function createRetryOnEmptyMiddleware({\n provider,\n blockTracker,\n}: {\n provider?: InternalProvider;\n blockTracker?: PollingBlockTracker;\n} = {}): JsonRpcMiddleware<JsonRpcParams, Json> {\n if (!provider) {\n throw Error(\n 'RetryOnEmptyMiddleware - mandatory \"provider\" option is missing.',\n );\n }\n\n if (!blockTracker) {\n throw Error(\n 'RetryOnEmptyMiddleware - mandatory \"blockTracker\" option is missing.',\n );\n }\n\n return createAsyncMiddleware(async (req, res, next) => {\n const blockRefIndex: number | undefined = blockTagParamIndex(req.method);\n // skip if method does not include blockRef\n if (blockRefIndex === undefined) {\n return next();\n }\n // skip if not exact block references\n let blockRef: string | undefined =\n Array.isArray(req.params) && req.params[blockRefIndex]\n ? (req.params[blockRefIndex] as string)\n : undefined;\n // omitted blockRef implies \"latest\"\n if (blockRef === undefined) {\n blockRef = 'latest';\n }\n\n // skip if non-number block reference\n if (['latest', 'pending'].includes(blockRef)) {\n return next();\n }\n // skip if block refernce is not a valid number\n const blockRefNumber: number = Number.parseInt(blockRef.slice(2), 16);\n if (Number.isNaN(blockRefNumber)) {\n return next();\n }\n // lookup latest block\n const latestBlockNumberHex: string = await blockTracker.getLatestBlock();\n const latestBlockNumber: number = Number.parseInt(\n latestBlockNumberHex.slice(2),\n 16,\n );\n // skip if request block number is higher than current\n if (blockRefNumber > latestBlockNumber) {\n log(\n 'Requested block number %o is higher than latest block number %o, falling through to original request',\n blockRefNumber,\n latestBlockNumber,\n );\n return next();\n }\n\n log(\n 'Requested block number %o is not higher than latest block number %o, trying request until non-empty response is received',\n blockRefNumber,\n latestBlockNumber,\n );\n\n // create child request with specific block-ref\n const childRequest = klona(req);\n // attempt child request until non-empty response is received\n const childResult = await retry(10, async () => {\n log('Performing request %o', childRequest);\n const attemptResult = await provider.request<JsonRpcParams, Block>(\n childRequest,\n );\n log('Result is %o', attemptResult);\n // verify result\n const allEmptyValues: unknown[] = emptyValues;\n if (allEmptyValues.includes(attemptResult)) {\n throw new Error(\n `RetryOnEmptyMiddleware - empty result \"${JSON.stringify(\n attemptResult,\n )}\" for request \"${JSON.stringify(childRequest)}\"`,\n );\n }\n return attemptResult;\n });\n log('Copying result %o', childResult);\n // copy child result onto original response\n res.result = childResult;\n return undefined;\n });\n}\n\n/**\n * Retries an asynchronous function up to a maximum number of times.\n *\n * @param maxRetries - The maximum number of retries.\n * @param asyncFn - The asynchronous function to retry.\n * @returns The result of the asynchronous function.\n */\nasync function retry<Result>(\n maxRetries: number,\n asyncFn: () => Promise<Result>,\n): Promise<Result> {\n for (let index = 0; index < maxRetries; index++) {\n try {\n return await asyncFn();\n } catch (err: unknown) {\n if (isExecutionRevertedError(err)) {\n throw err as unknown;\n }\n log('(call %i) Request failed, waiting 1s to retry again...', index + 1);\n await timeout(1000);\n }\n }\n log('Retries exhausted');\n throw new Error('RetryOnEmptyMiddleware - retries exhausted');\n}\n"]}
|
package/dist/retryOnEmpty.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { PollingBlockTracker } from "@metamask/eth-block-tracker";
|
|
2
2
|
import type { InternalProvider } from "@metamask/eth-json-rpc-provider";
|
|
3
|
-
import type { JsonRpcMiddleware } from "@metamask/json-rpc-engine
|
|
4
|
-
import type { Json,
|
|
3
|
+
import type { JsonRpcMiddleware } from "@metamask/json-rpc-engine";
|
|
4
|
+
import type { Json, JsonRpcParams } from "@metamask/utils";
|
|
5
5
|
/**
|
|
6
6
|
* Creates a middleware that retries requests with empty responses.
|
|
7
7
|
*
|
|
@@ -13,5 +13,5 @@ import type { Json, JsonRpcRequest } from "@metamask/utils";
|
|
|
13
13
|
export declare function createRetryOnEmptyMiddleware({ provider, blockTracker, }?: {
|
|
14
14
|
provider?: InternalProvider;
|
|
15
15
|
blockTracker?: PollingBlockTracker;
|
|
16
|
-
}): JsonRpcMiddleware<
|
|
16
|
+
}): JsonRpcMiddleware<JsonRpcParams, Json>;
|
|
17
17
|
//# sourceMappingURL=retryOnEmpty.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retryOnEmpty.d.cts","sourceRoot":"","sources":["../src/retryOnEmpty.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,oCAAoC;AACvE,OAAO,KAAK,EAAE,gBAAgB,EAAE,wCAAwC;AACxE,OAAO,KAAK,EAAE,iBAAiB,EAAE,
|
|
1
|
+
{"version":3,"file":"retryOnEmpty.d.cts","sourceRoot":"","sources":["../src/retryOnEmpty.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,oCAAoC;AACvE,OAAO,KAAK,EAAE,gBAAgB,EAAE,wCAAwC;AACxE,OAAO,KAAK,EAAE,iBAAiB,EAAE,kCAAkC;AAEnE,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,wBAAwB;AAqB3D;;;;;;;GAOG;AACH,wBAAgB,4BAA4B,CAAC,EAC3C,QAAQ,EACR,YAAY,GACb,GAAE;IACD,QAAQ,CAAC,EAAE,gBAAgB,CAAC;IAC5B,YAAY,CAAC,EAAE,mBAAmB,CAAC;CAC/B,GAAG,iBAAiB,CAAC,aAAa,EAAE,IAAI,CAAC,CAqF9C"}
|
package/dist/retryOnEmpty.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { PollingBlockTracker } from "@metamask/eth-block-tracker";
|
|
2
2
|
import type { InternalProvider } from "@metamask/eth-json-rpc-provider";
|
|
3
|
-
import type { JsonRpcMiddleware } from "@metamask/json-rpc-engine
|
|
4
|
-
import type { Json,
|
|
3
|
+
import type { JsonRpcMiddleware } from "@metamask/json-rpc-engine";
|
|
4
|
+
import type { Json, JsonRpcParams } from "@metamask/utils";
|
|
5
5
|
/**
|
|
6
6
|
* Creates a middleware that retries requests with empty responses.
|
|
7
7
|
*
|
|
@@ -13,5 +13,5 @@ import type { Json, JsonRpcRequest } from "@metamask/utils";
|
|
|
13
13
|
export declare function createRetryOnEmptyMiddleware({ provider, blockTracker, }?: {
|
|
14
14
|
provider?: InternalProvider;
|
|
15
15
|
blockTracker?: PollingBlockTracker;
|
|
16
|
-
}): JsonRpcMiddleware<
|
|
16
|
+
}): JsonRpcMiddleware<JsonRpcParams, Json>;
|
|
17
17
|
//# sourceMappingURL=retryOnEmpty.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retryOnEmpty.d.mts","sourceRoot":"","sources":["../src/retryOnEmpty.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,oCAAoC;AACvE,OAAO,KAAK,EAAE,gBAAgB,EAAE,wCAAwC;AACxE,OAAO,KAAK,EAAE,iBAAiB,EAAE,
|
|
1
|
+
{"version":3,"file":"retryOnEmpty.d.mts","sourceRoot":"","sources":["../src/retryOnEmpty.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,oCAAoC;AACvE,OAAO,KAAK,EAAE,gBAAgB,EAAE,wCAAwC;AACxE,OAAO,KAAK,EAAE,iBAAiB,EAAE,kCAAkC;AAEnE,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,wBAAwB;AAqB3D;;;;;;;GAOG;AACH,wBAAgB,4BAA4B,CAAC,EAC3C,QAAQ,EACR,YAAY,GACb,GAAE;IACD,QAAQ,CAAC,EAAE,gBAAgB,CAAC;IAC5B,YAAY,CAAC,EAAE,mBAAmB,CAAC;CAC/B,GAAG,iBAAiB,CAAC,aAAa,EAAE,IAAI,CAAC,CAqF9C"}
|
package/dist/retryOnEmpty.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createAsyncMiddleware } from "@metamask/json-rpc-engine";
|
|
2
|
+
import { klona } from "klona/full";
|
|
2
3
|
import { projectLogger, createModuleLogger } from "./logging-utils.mjs";
|
|
3
4
|
import { blockTagParamIndex } from "./utils/cache.mjs";
|
|
4
5
|
import { isExecutionRevertedError } from "./utils/error.mjs";
|
|
@@ -28,15 +29,15 @@ export function createRetryOnEmptyMiddleware({ provider, blockTracker, } = {}) {
|
|
|
28
29
|
if (!blockTracker) {
|
|
29
30
|
throw Error('RetryOnEmptyMiddleware - mandatory "blockTracker" option is missing.');
|
|
30
31
|
}
|
|
31
|
-
return async (
|
|
32
|
-
const blockRefIndex = blockTagParamIndex(
|
|
32
|
+
return createAsyncMiddleware(async (req, res, next) => {
|
|
33
|
+
const blockRefIndex = blockTagParamIndex(req.method);
|
|
33
34
|
// skip if method does not include blockRef
|
|
34
35
|
if (blockRefIndex === undefined) {
|
|
35
36
|
return next();
|
|
36
37
|
}
|
|
37
38
|
// skip if not exact block references
|
|
38
|
-
let blockRef = Array.isArray(
|
|
39
|
-
?
|
|
39
|
+
let blockRef = Array.isArray(req.params) && req.params[blockRefIndex]
|
|
40
|
+
? req.params[blockRefIndex]
|
|
40
41
|
: undefined;
|
|
41
42
|
// omitted blockRef implies "latest"
|
|
42
43
|
if (blockRef === undefined) {
|
|
@@ -61,7 +62,7 @@ export function createRetryOnEmptyMiddleware({ provider, blockTracker, } = {}) {
|
|
|
61
62
|
}
|
|
62
63
|
log('Requested block number %o is not higher than latest block number %o, trying request until non-empty response is received', blockRefNumber, latestBlockNumber);
|
|
63
64
|
// create child request with specific block-ref
|
|
64
|
-
const childRequest = klona(
|
|
65
|
+
const childRequest = klona(req);
|
|
65
66
|
// attempt child request until non-empty response is received
|
|
66
67
|
const childResult = await retry(10, async () => {
|
|
67
68
|
log('Performing request %o', childRequest);
|
|
@@ -75,8 +76,10 @@ export function createRetryOnEmptyMiddleware({ provider, blockTracker, } = {}) {
|
|
|
75
76
|
return attemptResult;
|
|
76
77
|
});
|
|
77
78
|
log('Copying result %o', childResult);
|
|
78
|
-
|
|
79
|
-
|
|
79
|
+
// copy child result onto original response
|
|
80
|
+
res.result = childResult;
|
|
81
|
+
return undefined;
|
|
82
|
+
});
|
|
80
83
|
}
|
|
81
84
|
/**
|
|
82
85
|
* Retries an asynchronous function up to a maximum number of times.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retryOnEmpty.mjs","sourceRoot":"","sources":["../src/retryOnEmpty.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"retryOnEmpty.mjs","sourceRoot":"","sources":["../src/retryOnEmpty.ts"],"names":[],"mappings":"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","sourcesContent":["import type { PollingBlockTracker } from '@metamask/eth-block-tracker';\nimport type { InternalProvider } from '@metamask/eth-json-rpc-provider';\nimport type { JsonRpcMiddleware } from '@metamask/json-rpc-engine';\nimport { createAsyncMiddleware } from '@metamask/json-rpc-engine';\nimport type { Json, JsonRpcParams } from '@metamask/utils';\nimport { klona } from 'klona/full';\n\nimport { projectLogger, createModuleLogger } from './logging-utils';\nimport type { Block } from './types';\nimport { blockTagParamIndex } from './utils/cache';\nimport { isExecutionRevertedError } from './utils/error';\nimport { timeout } from './utils/timeout';\n\n//\n// RetryOnEmptyMiddleware will retry any request with an empty response that has\n// a numbered block reference at or lower than the blockTracker's latest block.\n// Its useful for dealing with load-balanced ethereum JSON RPC\n// nodes that are not always in sync with each other.\n//\n\nconst log = createModuleLogger(projectLogger, 'retry-on-empty');\n// empty values used to determine if a request should be retried\n// `<nil>` comes from https://github.com/ethereum/go-ethereum/issues/16925\nconst emptyValues = [null, '\\u003cnil\\u003e'];\n\n/**\n * Creates a middleware that retries requests with empty responses.\n *\n * @param options - The options for the middleware.\n * @param options.provider - The provider to use.\n * @param options.blockTracker - The block tracker to use.\n * @returns The middleware.\n */\nexport function createRetryOnEmptyMiddleware({\n provider,\n blockTracker,\n}: {\n provider?: InternalProvider;\n blockTracker?: PollingBlockTracker;\n} = {}): JsonRpcMiddleware<JsonRpcParams, Json> {\n if (!provider) {\n throw Error(\n 'RetryOnEmptyMiddleware - mandatory \"provider\" option is missing.',\n );\n }\n\n if (!blockTracker) {\n throw Error(\n 'RetryOnEmptyMiddleware - mandatory \"blockTracker\" option is missing.',\n );\n }\n\n return createAsyncMiddleware(async (req, res, next) => {\n const blockRefIndex: number | undefined = blockTagParamIndex(req.method);\n // skip if method does not include blockRef\n if (blockRefIndex === undefined) {\n return next();\n }\n // skip if not exact block references\n let blockRef: string | undefined =\n Array.isArray(req.params) && req.params[blockRefIndex]\n ? (req.params[blockRefIndex] as string)\n : undefined;\n // omitted blockRef implies \"latest\"\n if (blockRef === undefined) {\n blockRef = 'latest';\n }\n\n // skip if non-number block reference\n if (['latest', 'pending'].includes(blockRef)) {\n return next();\n }\n // skip if block refernce is not a valid number\n const blockRefNumber: number = Number.parseInt(blockRef.slice(2), 16);\n if (Number.isNaN(blockRefNumber)) {\n return next();\n }\n // lookup latest block\n const latestBlockNumberHex: string = await blockTracker.getLatestBlock();\n const latestBlockNumber: number = Number.parseInt(\n latestBlockNumberHex.slice(2),\n 16,\n );\n // skip if request block number is higher than current\n if (blockRefNumber > latestBlockNumber) {\n log(\n 'Requested block number %o is higher than latest block number %o, falling through to original request',\n blockRefNumber,\n latestBlockNumber,\n );\n return next();\n }\n\n log(\n 'Requested block number %o is not higher than latest block number %o, trying request until non-empty response is received',\n blockRefNumber,\n latestBlockNumber,\n );\n\n // create child request with specific block-ref\n const childRequest = klona(req);\n // attempt child request until non-empty response is received\n const childResult = await retry(10, async () => {\n log('Performing request %o', childRequest);\n const attemptResult = await provider.request<JsonRpcParams, Block>(\n childRequest,\n );\n log('Result is %o', attemptResult);\n // verify result\n const allEmptyValues: unknown[] = emptyValues;\n if (allEmptyValues.includes(attemptResult)) {\n throw new Error(\n `RetryOnEmptyMiddleware - empty result \"${JSON.stringify(\n attemptResult,\n )}\" for request \"${JSON.stringify(childRequest)}\"`,\n );\n }\n return attemptResult;\n });\n log('Copying result %o', childResult);\n // copy child result onto original response\n res.result = childResult;\n return undefined;\n });\n}\n\n/**\n * Retries an asynchronous function up to a maximum number of times.\n *\n * @param maxRetries - The maximum number of retries.\n * @param asyncFn - The asynchronous function to retry.\n * @returns The result of the asynchronous function.\n */\nasync function retry<Result>(\n maxRetries: number,\n asyncFn: () => Promise<Result>,\n): Promise<Result> {\n for (let index = 0; index < maxRetries; index++) {\n try {\n return await asyncFn();\n } catch (err: unknown) {\n if (isExecutionRevertedError(err)) {\n throw err as unknown;\n }\n log('(call %i) Request failed, waiting 1s to retry again...', index + 1);\n await timeout(1000);\n }\n }\n log('Retries exhausted');\n throw new Error('RetryOnEmptyMiddleware - retries exhausted');\n}\n"]}
|
package/dist/types.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n Json,\n JsonRpcParams,\n JsonRpcRequest,\n JsonRpcResponse,\n} from '@metamask/utils';\n\nexport type BlockData = string | string[];\n\nexport type Block = Record<string, BlockData>;\n\nexport type BlockCache = Record<string, Block>;\n\nexport type Cache = Record<number, BlockCache>;\n\n/**\n * A copy of the `AbstractRpcService` type in metamask/network-controller`, but\n * keeping only the `request` method.\n *\n * We cannot get `AbstractRpcService` directly from\n * `@metamask/network-controller` because relying on this package would create a\n * circular dependency.\n *\n * This type should be accurate as of `@metamask/network-controller` 24.x and\n * `@metamask/utils` 11.x.\n */\nexport type AbstractRpcServiceLike = {\n request: <Params extends JsonRpcParams, Result extends Json>(\n jsonRpcRequest: JsonRpcRequest<Params>,\n fetchOptions?: RequestInit,\n ) => Promise<JsonRpcResponse<Result | null>>;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { JsonRpcMiddleware } from '@metamask/json-rpc-engine';\nimport type {\n Json,\n JsonRpcParams,\n JsonRpcRequest,\n JsonRpcResponse,\n} from '@metamask/utils';\n\nexport type JsonRpcRequestToCache<Params extends JsonRpcParams> =\n JsonRpcRequest<Params> & {\n skipCache?: boolean;\n };\n\nexport type JsonRpcCacheMiddleware<\n Params extends JsonRpcParams,\n Result extends Json,\n> =\n JsonRpcMiddleware<Params, Result> extends (\n req: JsonRpcRequest<Params>,\n ...args: infer X\n ) => infer Y\n ? (req: JsonRpcRequestToCache<Params>, ...args: X) => Y\n : never;\n\nexport type BlockData = string | string[];\n\nexport type Block = Record<string, BlockData>;\n\nexport type BlockCache = Record<string, Block>;\n\nexport type Cache = Record<number, BlockCache>;\n\n/**\n * A copy of the `AbstractRpcService` type in metamask/network-controller`, but\n * keeping only the `request` method.\n *\n * We cannot get `AbstractRpcService` directly from\n * `@metamask/network-controller` because relying on this package would create a\n * circular dependency.\n *\n * This type should be accurate as of `@metamask/network-controller` 24.x and\n * `@metamask/utils` 11.x.\n */\nexport type AbstractRpcServiceLike = {\n request: <Params extends JsonRpcParams, Result extends Json>(\n jsonRpcRequest: JsonRpcRequest<Params>,\n fetchOptions?: RequestInit,\n ) => Promise<JsonRpcResponse<Result | null>>;\n};\n"]}
|
package/dist/types.d.cts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
+
import type { JsonRpcMiddleware } from "@metamask/json-rpc-engine";
|
|
1
2
|
import type { Json, JsonRpcParams, JsonRpcRequest, JsonRpcResponse } from "@metamask/utils";
|
|
3
|
+
export type JsonRpcRequestToCache<Params extends JsonRpcParams> = JsonRpcRequest<Params> & {
|
|
4
|
+
skipCache?: boolean;
|
|
5
|
+
};
|
|
6
|
+
export type JsonRpcCacheMiddleware<Params extends JsonRpcParams, Result extends Json> = JsonRpcMiddleware<Params, Result> extends (req: JsonRpcRequest<Params>, ...args: infer X) => infer Y ? (req: JsonRpcRequestToCache<Params>, ...args: X) => Y : never;
|
|
2
7
|
export type BlockData = string | string[];
|
|
3
8
|
export type Block = Record<string, BlockData>;
|
|
4
9
|
export type BlockCache = Record<string, Block>;
|
package/dist/types.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,IAAI,EACJ,aAAa,EACb,cAAc,EACd,eAAe,EAChB,wBAAwB;AAEzB,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC;AAE1C,MAAM,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;AAE9C,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AAE/C,MAAM,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;AAE/C;;;;;;;;;;GAUG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC,OAAO,EAAE,CAAC,MAAM,SAAS,aAAa,EAAE,MAAM,SAAS,IAAI,EACzD,cAAc,EAAE,cAAc,CAAC,MAAM,CAAC,EACtC,YAAY,CAAC,EAAE,WAAW,KACvB,OAAO,CAAC,eAAe,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC;CAC9C,CAAC"}
|
|
1
|
+
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,kCAAkC;AACnE,OAAO,KAAK,EACV,IAAI,EACJ,aAAa,EACb,cAAc,EACd,eAAe,EAChB,wBAAwB;AAEzB,MAAM,MAAM,qBAAqB,CAAC,MAAM,SAAS,aAAa,IAC5D,cAAc,CAAC,MAAM,CAAC,GAAG;IACvB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;AAEJ,MAAM,MAAM,sBAAsB,CAChC,MAAM,SAAS,aAAa,EAC5B,MAAM,SAAS,IAAI,IAEnB,iBAAiB,CAAC,MAAM,EAAE,MAAM,CAAC,SAAS,CACxC,GAAG,EAAE,cAAc,CAAC,MAAM,CAAC,EAC3B,GAAG,IAAI,EAAE,MAAM,CAAC,KACb,MAAM,CAAC,GACR,CAAC,GAAG,EAAE,qBAAqB,CAAC,MAAM,CAAC,EAAE,GAAG,IAAI,EAAE,CAAC,KAAK,CAAC,GACrD,KAAK,CAAC;AAEZ,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC;AAE1C,MAAM,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;AAE9C,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AAE/C,MAAM,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;AAE/C;;;;;;;;;;GAUG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC,OAAO,EAAE,CAAC,MAAM,SAAS,aAAa,EAAE,MAAM,SAAS,IAAI,EACzD,cAAc,EAAE,cAAc,CAAC,MAAM,CAAC,EACtC,YAAY,CAAC,EAAE,WAAW,KACvB,OAAO,CAAC,eAAe,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC;CAC9C,CAAC"}
|
package/dist/types.d.mts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
+
import type { JsonRpcMiddleware } from "@metamask/json-rpc-engine";
|
|
1
2
|
import type { Json, JsonRpcParams, JsonRpcRequest, JsonRpcResponse } from "@metamask/utils";
|
|
3
|
+
export type JsonRpcRequestToCache<Params extends JsonRpcParams> = JsonRpcRequest<Params> & {
|
|
4
|
+
skipCache?: boolean;
|
|
5
|
+
};
|
|
6
|
+
export type JsonRpcCacheMiddleware<Params extends JsonRpcParams, Result extends Json> = JsonRpcMiddleware<Params, Result> extends (req: JsonRpcRequest<Params>, ...args: infer X) => infer Y ? (req: JsonRpcRequestToCache<Params>, ...args: X) => Y : never;
|
|
2
7
|
export type BlockData = string | string[];
|
|
3
8
|
export type Block = Record<string, BlockData>;
|
|
4
9
|
export type BlockCache = Record<string, Block>;
|
package/dist/types.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,IAAI,EACJ,aAAa,EACb,cAAc,EACd,eAAe,EAChB,wBAAwB;AAEzB,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC;AAE1C,MAAM,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;AAE9C,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AAE/C,MAAM,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;AAE/C;;;;;;;;;;GAUG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC,OAAO,EAAE,CAAC,MAAM,SAAS,aAAa,EAAE,MAAM,SAAS,IAAI,EACzD,cAAc,EAAE,cAAc,CAAC,MAAM,CAAC,EACtC,YAAY,CAAC,EAAE,WAAW,KACvB,OAAO,CAAC,eAAe,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC;CAC9C,CAAC"}
|
|
1
|
+
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,kCAAkC;AACnE,OAAO,KAAK,EACV,IAAI,EACJ,aAAa,EACb,cAAc,EACd,eAAe,EAChB,wBAAwB;AAEzB,MAAM,MAAM,qBAAqB,CAAC,MAAM,SAAS,aAAa,IAC5D,cAAc,CAAC,MAAM,CAAC,GAAG;IACvB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;AAEJ,MAAM,MAAM,sBAAsB,CAChC,MAAM,SAAS,aAAa,EAC5B,MAAM,SAAS,IAAI,IAEnB,iBAAiB,CAAC,MAAM,EAAE,MAAM,CAAC,SAAS,CACxC,GAAG,EAAE,cAAc,CAAC,MAAM,CAAC,EAC3B,GAAG,IAAI,EAAE,MAAM,CAAC,KACb,MAAM,CAAC,GACR,CAAC,GAAG,EAAE,qBAAqB,CAAC,MAAM,CAAC,EAAE,GAAG,IAAI,EAAE,CAAC,KAAK,CAAC,GACrD,KAAK,CAAC;AAEZ,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC;AAE1C,MAAM,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;AAE9C,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AAE/C,MAAM,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;AAE/C;;;;;;;;;;GAUG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC,OAAO,EAAE,CAAC,MAAM,SAAS,aAAa,EAAE,MAAM,SAAS,IAAI,EACzD,cAAc,EAAE,cAAc,CAAC,MAAM,CAAC,EACtC,YAAY,CAAC,EAAE,WAAW,KACvB,OAAO,CAAC,eAAe,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC;CAC9C,CAAC"}
|
package/dist/types.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n Json,\n JsonRpcParams,\n JsonRpcRequest,\n JsonRpcResponse,\n} from '@metamask/utils';\n\nexport type BlockData = string | string[];\n\nexport type Block = Record<string, BlockData>;\n\nexport type BlockCache = Record<string, Block>;\n\nexport type Cache = Record<number, BlockCache>;\n\n/**\n * A copy of the `AbstractRpcService` type in metamask/network-controller`, but\n * keeping only the `request` method.\n *\n * We cannot get `AbstractRpcService` directly from\n * `@metamask/network-controller` because relying on this package would create a\n * circular dependency.\n *\n * This type should be accurate as of `@metamask/network-controller` 24.x and\n * `@metamask/utils` 11.x.\n */\nexport type AbstractRpcServiceLike = {\n request: <Params extends JsonRpcParams, Result extends Json>(\n jsonRpcRequest: JsonRpcRequest<Params>,\n fetchOptions?: RequestInit,\n ) => Promise<JsonRpcResponse<Result | null>>;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { JsonRpcMiddleware } from '@metamask/json-rpc-engine';\nimport type {\n Json,\n JsonRpcParams,\n JsonRpcRequest,\n JsonRpcResponse,\n} from '@metamask/utils';\n\nexport type JsonRpcRequestToCache<Params extends JsonRpcParams> =\n JsonRpcRequest<Params> & {\n skipCache?: boolean;\n };\n\nexport type JsonRpcCacheMiddleware<\n Params extends JsonRpcParams,\n Result extends Json,\n> =\n JsonRpcMiddleware<Params, Result> extends (\n req: JsonRpcRequest<Params>,\n ...args: infer X\n ) => infer Y\n ? (req: JsonRpcRequestToCache<Params>, ...args: X) => Y\n : never;\n\nexport type BlockData = string | string[];\n\nexport type Block = Record<string, BlockData>;\n\nexport type BlockCache = Record<string, Block>;\n\nexport type Cache = Record<number, BlockCache>;\n\n/**\n * A copy of the `AbstractRpcService` type in metamask/network-controller`, but\n * keeping only the `request` method.\n *\n * We cannot get `AbstractRpcService` directly from\n * `@metamask/network-controller` because relying on this package would create a\n * circular dependency.\n *\n * This type should be accurate as of `@metamask/network-controller` 24.x and\n * `@metamask/utils` 11.x.\n */\nexport type AbstractRpcServiceLike = {\n request: <Params extends JsonRpcParams, Result extends Json>(\n jsonRpcRequest: JsonRpcRequest<Params>,\n fetchOptions?: RequestInit,\n ) => Promise<JsonRpcResponse<Result | null>>;\n};\n"]}
|
|
@@ -3,13 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.resemblesAddress = exports.validateParams = exports.validateAndNormalizeKeyholder = void 0;
|
|
4
4
|
const rpc_errors_1 = require("@metamask/rpc-errors");
|
|
5
5
|
const superstruct_1 = require("@metamask/superstruct");
|
|
6
|
-
async function validateAndNormalizeKeyholder(address,
|
|
6
|
+
async function validateAndNormalizeKeyholder(address, req, { getAccounts }) {
|
|
7
7
|
if (typeof address === 'string' &&
|
|
8
8
|
address.length > 0 &&
|
|
9
9
|
resemblesAddress(address)) {
|
|
10
10
|
// Ensure that an "unauthorized" error is thrown if the requester
|
|
11
11
|
// does not have the `eth_accounts` permission.
|
|
12
|
-
const accounts = await getAccounts(
|
|
12
|
+
const accounts = await getAccounts(req);
|
|
13
13
|
const normalizedAccounts = accounts.map((_address) => _address.toLowerCase());
|
|
14
14
|
const normalizedAddress = address.toLowerCase();
|
|
15
15
|
if (normalizedAccounts.includes(normalizedAddress)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.cjs","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"validation.cjs","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":";;;AAAA,qDAAiE;AAEjE,uDAAiD;AAG1C,KAAK,UAAU,6BAA6B,CACjD,OAAY,EACZ,GAAmB,EACnB,EAAE,WAAW,EAA+D;IAE5E,IACE,OAAO,OAAO,KAAK,QAAQ;QAC3B,OAAO,CAAC,MAAM,GAAG,CAAC;QAClB,gBAAgB,CAAC,OAAO,CAAC,EACzB;QACA,iEAAiE;QACjE,+CAA+C;QAC/C,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,GAAG,CAAC,CAAC;QAExC,MAAM,kBAAkB,GAAa,QAAQ,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAC7D,QAAQ,CAAC,WAAW,EAAE,CACvB,CAAC;QAEF,MAAM,iBAAiB,GAAG,OAAO,CAAC,WAAW,EAAS,CAAC;QAEvD,IAAI,kBAAkB,CAAC,QAAQ,CAAC,iBAAiB,CAAC,EAAE;YAClD,OAAO,iBAAiB,CAAC;SAC1B;QAED,MAAM,2BAAc,CAAC,YAAY,EAAE,CAAC;KACrC;IAED,MAAM,sBAAS,CAAC,aAAa,CAAC;QAC5B,OAAO,EAAE,uDAAuD;KACjE,CAAC,CAAC;AACL,CAAC;AA9BD,sEA8BC;AAED,SAAgB,cAAc,CAC5B,KAA2B,EAC3B,MAA0B;IAE1B,MAAM,CAAC,KAAK,CAAC,GAAG,IAAA,sBAAQ,EAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAExC,IAAI,KAAK,EAAE;QACT,MAAM,sBAAS,CAAC,aAAa,CAC3B,qBAAqB,CAAC,KAAK,EAAE,gBAAgB,CAAC,CAC/C,CAAC;KACH;AACH,CAAC;AAXD,wCAWC;AAED,SAAgB,gBAAgB,CAAC,GAAW;IAC1C,0BAA0B;IAC1B,OAAO,GAAG,CAAC,MAAM,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AACnC,CAAC;AAHD,4CAGC;AAED,SAAS,qBAAqB,CAAC,KAAkB,EAAE,OAAe;IAChE,OAAO,GAAG,OAAO,OAAO,KAAK;SAC1B,QAAQ,EAAE;SACV,GAAG,CACF,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,OAAO,EAAE,CACxE;SACA,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;AAClB,CAAC","sourcesContent":["import { providerErrors, rpcErrors } from '@metamask/rpc-errors';\nimport type { Struct, StructError } from '@metamask/superstruct';\nimport { validate } from '@metamask/superstruct';\nimport type { Hex, JsonRpcRequest } from '@metamask/utils';\n\nexport async function validateAndNormalizeKeyholder(\n address: Hex,\n req: JsonRpcRequest,\n { getAccounts }: { getAccounts: (req: JsonRpcRequest) => Promise<string[]> },\n): Promise<Hex> {\n if (\n typeof address === 'string' &&\n address.length > 0 &&\n resemblesAddress(address)\n ) {\n // Ensure that an \"unauthorized\" error is thrown if the requester\n // does not have the `eth_accounts` permission.\n const accounts = await getAccounts(req);\n\n const normalizedAccounts: string[] = accounts.map((_address) =>\n _address.toLowerCase(),\n );\n\n const normalizedAddress = address.toLowerCase() as Hex;\n\n if (normalizedAccounts.includes(normalizedAddress)) {\n return normalizedAddress;\n }\n\n throw providerErrors.unauthorized();\n }\n\n throw rpcErrors.invalidParams({\n message: `Invalid parameters: must provide an Ethereum address.`,\n });\n}\n\nexport function validateParams<ParamsType>(\n value: unknown | ParamsType,\n struct: Struct<ParamsType>,\n): asserts value is ParamsType {\n const [error] = validate(value, struct);\n\n if (error) {\n throw rpcErrors.invalidParams(\n formatValidationError(error, `Invalid params`),\n );\n }\n}\n\nexport function resemblesAddress(str: string): boolean {\n // hex prefix 2 + 20 bytes\n return str.length === 2 + 20 * 2;\n}\n\nfunction formatValidationError(error: StructError, message: string): string {\n return `${message}\\n\\n${error\n .failures()\n .map(\n (f) => `${f.path.join(' > ')}${f.path.length ? ' - ' : ''}${f.message}`,\n )\n .join('\\n')}`;\n}\n"]}
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import type { MiddlewareContext } from "@metamask/json-rpc-engine/v2";
|
|
2
1
|
import type { Struct } from "@metamask/superstruct";
|
|
3
|
-
import type { Hex } from "@metamask/utils";
|
|
4
|
-
export declare function validateAndNormalizeKeyholder(address: Hex,
|
|
5
|
-
|
|
6
|
-
}>, { getAccounts }: {
|
|
7
|
-
getAccounts: (origin: string) => Promise<string[]>;
|
|
2
|
+
import type { Hex, JsonRpcRequest } from "@metamask/utils";
|
|
3
|
+
export declare function validateAndNormalizeKeyholder(address: Hex, req: JsonRpcRequest, { getAccounts }: {
|
|
4
|
+
getAccounts: (req: JsonRpcRequest) => Promise<string[]>;
|
|
8
5
|
}): Promise<Hex>;
|
|
9
6
|
export declare function validateParams<ParamsType>(value: unknown | ParamsType, struct: Struct<ParamsType>): asserts value is ParamsType;
|
|
10
7
|
export declare function resemblesAddress(str: string): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.d.cts","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"validation.d.cts","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAe,8BAA8B;AAEjE,OAAO,KAAK,EAAE,GAAG,EAAE,cAAc,EAAE,wBAAwB;AAE3D,wBAAsB,6BAA6B,CACjD,OAAO,EAAE,GAAG,EACZ,GAAG,EAAE,cAAc,EACnB,EAAE,WAAW,EAAE,EAAE;IAAE,WAAW,EAAE,CAAC,GAAG,EAAE,cAAc,KAAK,OAAO,CAAC,MAAM,EAAE,CAAC,CAAA;CAAE,GAC3E,OAAO,CAAC,GAAG,CAAC,CA0Bd;AAED,wBAAgB,cAAc,CAAC,UAAU,EACvC,KAAK,EAAE,OAAO,GAAG,UAAU,EAC3B,MAAM,EAAE,MAAM,CAAC,UAAU,CAAC,GACzB,OAAO,CAAC,KAAK,IAAI,UAAU,CAQ7B;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAGrD"}
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import type { MiddlewareContext } from "@metamask/json-rpc-engine/v2";
|
|
2
1
|
import type { Struct } from "@metamask/superstruct";
|
|
3
|
-
import type { Hex } from "@metamask/utils";
|
|
4
|
-
export declare function validateAndNormalizeKeyholder(address: Hex,
|
|
5
|
-
|
|
6
|
-
}>, { getAccounts }: {
|
|
7
|
-
getAccounts: (origin: string) => Promise<string[]>;
|
|
2
|
+
import type { Hex, JsonRpcRequest } from "@metamask/utils";
|
|
3
|
+
export declare function validateAndNormalizeKeyholder(address: Hex, req: JsonRpcRequest, { getAccounts }: {
|
|
4
|
+
getAccounts: (req: JsonRpcRequest) => Promise<string[]>;
|
|
8
5
|
}): Promise<Hex>;
|
|
9
6
|
export declare function validateParams<ParamsType>(value: unknown | ParamsType, struct: Struct<ParamsType>): asserts value is ParamsType;
|
|
10
7
|
export declare function resemblesAddress(str: string): boolean;
|