From 6c1caa1127e5217157fb623420ff012ee582f4d2 Mon Sep 17 00:00:00 2001 From: legobt <6wbvkn0j@anonaddy.me> Date: Wed, 23 Aug 2023 13:30:40 +0000 Subject: [PATCH 1/6] TEST: bump @metamask/rpc-errors to 5.1.1 patched with github.com/MetaMask/rpc-errors/pull/102 --- ...mask-rpc-errors-npm-5.1.1-dc76c26803.patch | 308 ++++++++++++++++++ package.json | 5 +- yarn.lock | 20 +- 3 files changed, 327 insertions(+), 6 deletions(-) create mode 100644 .yarn/patches/@metamask-rpc-errors-npm-5.1.1-dc76c26803.patch diff --git a/.yarn/patches/@metamask-rpc-errors-npm-5.1.1-dc76c26803.patch b/.yarn/patches/@metamask-rpc-errors-npm-5.1.1-dc76c26803.patch new file mode 100644 index 0000000..883ffdf --- /dev/null +++ b/.yarn/patches/@metamask-rpc-errors-npm-5.1.1-dc76c26803.patch @@ -0,0 +1,308 @@ +diff --git a/dist/classes.d.ts b/dist/classes.d.ts +index 46c2ef8eb999c0063594277974b29c8f239a6dcb..89b916c2c466ec4500a3c7c8f600fff28f9db2e5 100644 +--- a/dist/classes.d.ts ++++ b/dist/classes.d.ts +@@ -1,5 +1,5 @@ +-import { JsonRpcError as SerializedJsonRpcError } from '@metamask/utils'; +-import { DataWithOptionalCause } from './utils'; ++import type { JsonRpcError as SerializedJsonRpcError } from '@metamask/utils'; ++import type { DataWithOptionalCause, OptionalDataWithOptionalCause } from './utils'; + export type { SerializedJsonRpcError }; + /** + * Error subclass implementing JSON RPC 2.0 errors and Ethereum RPC errors +@@ -7,10 +7,10 @@ export type { SerializedJsonRpcError }; + * + * Permits any integer error code. + */ +-export declare class JsonRpcError extends Error { ++export declare class JsonRpcError extends Error { + code: number; +- data?: T; +- constructor(code: number, message: string, data?: T); ++ data?: Data; ++ constructor(code: number, message: string, data?: Data); + /** + * Get the error as JSON-serializable object. + * +@@ -29,7 +29,7 @@ export declare class JsonRpcError extends Error + * Error subclass implementing Ethereum Provider errors per EIP-1193. + * Permits integer error codes in the [ 1000 <= 4999 ] range. + */ +-export declare class EthereumProviderError extends JsonRpcError { ++export declare class EthereumProviderError extends JsonRpcError { + /** + * Create an Ethereum Provider JSON-RPC error. + * +@@ -38,5 +38,6 @@ export declare class EthereumProviderError exte + * @param message - The JSON-RPC error message. + * @param data - Optional data to include in the error. + */ +- constructor(code: number, message: string, data?: T); ++ constructor(code: number, message: string, data?: Data); + } ++//# sourceMappingURL=classes.d.ts.map +\ No newline at end of file +diff --git a/dist/classes.d.ts.map b/dist/classes.d.ts.map +new file mode 100644 +index 0000000000000000000000000000000000000000..f36c4e8b1201050b79f5d01cfdc4147e2e1018ba +--- /dev/null ++++ b/dist/classes.d.ts.map +@@ -0,0 +1 @@ ++{"version":3,"file":"classes.d.ts","sourceRoot":"","sources":["../../src/classes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,YAAY,IAAI,sBAAsB,EACvC,MAAM,iBAAiB,CAAC;AAIzB,OAAO,KAAK,EACV,qBAAqB,EACrB,6BAA6B,EAC9B,MAAM,SAAS,CAAC;AAGjB,YAAY,EAAE,sBAAsB,EAAE,CAAC;AAEvC;;;;;GAKG;AACH,qBAAa,YAAY,CACvB,IAAI,SAAS,6BAA6B,CAC1C,SAAQ,KAAK;IACN,IAAI,EAAE,MAAM,CAAC;IAEb,IAAI,CAAC,EAAE,IAAI,CAAC;gBAEP,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,IAAI;IAgBtD;;;;OAIG;IACH,SAAS,IAAI,sBAAsB;IAwBnC;;;;;OAKG;IACH,QAAQ,IAAI,MAAM;CAGnB;AAED;;;GAGG;AACH,qBAAa,qBAAqB,CAChC,IAAI,SAAS,qBAAqB,CAClC,SAAQ,YAAY,CAAC,IAAI,CAAC;IAC1B;;;;;;;OAOG;gBACS,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,IAAI;CASvD"} +\ No newline at end of file +diff --git a/dist/error-constants.d.ts b/dist/error-constants.d.ts +index 848a90179761b64ffda108768bd96d4e5d2c7a76..89f65a67f39d727d43fcc72a7c591533c42e08dc 100644 +--- a/dist/error-constants.d.ts ++++ b/dist/error-constants.d.ts +@@ -86,3 +86,4 @@ export declare const errorValues: { + message: string; + }; + }; ++//# sourceMappingURL=error-constants.d.ts.map +\ No newline at end of file +diff --git a/dist/error-constants.d.ts.map b/dist/error-constants.d.ts.map +new file mode 100644 +index 0000000000000000000000000000000000000000..8181d55d6612a9e172bd3c044da8f31ce7f6240b +--- /dev/null ++++ b/dist/error-constants.d.ts.map +@@ -0,0 +1 @@ ++{"version":3,"file":"error-constants.d.ts","sourceRoot":"","sources":["../../src/error-constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;CAqBtB,CAAC;AAGF,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmEvB,CAAC"} +\ No newline at end of file +diff --git a/dist/errors.d.ts b/dist/errors.d.ts +index b4653125ce748f7da32ced278cc60f726c3cb6ee..c866a51b1399069678b559d4e7e586550d3b43e8 100644 +--- a/dist/errors.d.ts ++++ b/dist/errors.d.ts +@@ -1,14 +1,14 @@ + import { JsonRpcError, EthereumProviderError } from './classes'; +-import { DataWithOptionalCause } from './utils'; +-type EthereumErrorOptions = { ++import type { DataWithOptionalCause, OptionalDataWithOptionalCause } from './utils'; ++type EthereumErrorOptions = { + message?: string; +- data?: T; ++ data?: Data; + }; +-type ServerErrorOptions = { ++type ServerErrorOptions = { + code: number; +-} & EthereumErrorOptions; +-type CustomErrorArg = ServerErrorOptions; +-type JsonRpcErrorsArg = EthereumErrorOptions | string; ++} & EthereumErrorOptions; ++type CustomErrorArg = ServerErrorOptions; ++type JsonRpcErrorsArg = EthereumErrorOptions | string; + export declare const rpcErrors: { + /** + * Get a JSON RPC 2.0 Parse (-32700) error. +@@ -16,35 +16,35 @@ export declare const rpcErrors: { + * @param arg - The error message or options bag. + * @returns An instance of the {@link JsonRpcError} class. + */ +- parse: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; ++ parse: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; + /** + * Get a JSON RPC 2.0 Invalid Request (-32600) error. + * + * @param arg - The error message or options bag. + * @returns An instance of the {@link JsonRpcError} class. + */ +- invalidRequest: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; ++ invalidRequest: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; + /** + * Get a JSON RPC 2.0 Invalid Params (-32602) error. + * + * @param arg - The error message or options bag. + * @returns An instance of the {@link JsonRpcError} class. + */ +- invalidParams: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; ++ invalidParams: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; + /** + * Get a JSON RPC 2.0 Method Not Found (-32601) error. + * + * @param arg - The error message or options bag. + * @returns An instance of the {@link JsonRpcError} class. + */ +- methodNotFound: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; ++ methodNotFound: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; + /** + * Get a JSON RPC 2.0 Internal (-32603) error. + * + * @param arg - The error message or options bag. + * @returns An instance of the {@link JsonRpcError} class. + */ +- internal: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; ++ internal: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; + /** + * Get a JSON RPC 2.0 Server error. + * Permits integer error codes in the [ -32099 <= -32005 ] range. +@@ -53,49 +53,49 @@ export declare const rpcErrors: { + * @param opts - The error options bag. + * @returns An instance of the {@link JsonRpcError} class. + */ +- server: (opts: ServerErrorOptions) => JsonRpcError; ++ server: (opts: ServerErrorOptions) => JsonRpcError; + /** + * Get an Ethereum JSON RPC Invalid Input (-32000) error. + * + * @param arg - The error message or options bag. + * @returns An instance of the {@link JsonRpcError} class. + */ +- invalidInput: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; ++ invalidInput: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; + /** + * Get an Ethereum JSON RPC Resource Not Found (-32001) error. + * + * @param arg - The error message or options bag. + * @returns An instance of the {@link JsonRpcError} class. + */ +- resourceNotFound: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; ++ resourceNotFound: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; + /** + * Get an Ethereum JSON RPC Resource Unavailable (-32002) error. + * + * @param arg - The error message or options bag. + * @returns An instance of the {@link JsonRpcError} class. + */ +- resourceUnavailable: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; ++ resourceUnavailable: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; + /** + * Get an Ethereum JSON RPC Transaction Rejected (-32003) error. + * + * @param arg - The error message or options bag. + * @returns An instance of the {@link JsonRpcError} class. + */ +- transactionRejected: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; ++ transactionRejected: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; + /** + * Get an Ethereum JSON RPC Method Not Supported (-32004) error. + * + * @param arg - The error message or options bag. + * @returns An instance of the {@link JsonRpcError} class. + */ +- methodNotSupported: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; ++ methodNotSupported: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; + /** + * Get an Ethereum JSON RPC Limit Exceeded (-32005) error. + * + * @param arg - The error message or options bag. + * @returns An instance of the {@link JsonRpcError} class. + */ +- limitExceeded: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; ++ limitExceeded: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; + }; + export declare const providerErrors: { + /** +@@ -104,41 +104,42 @@ export declare const providerErrors: { + * @param arg - The error message or options bag. + * @returns An instance of the {@link EthereumProviderError} class. + */ +- userRejectedRequest: (arg?: JsonRpcErrorsArg | undefined) => EthereumProviderError; ++ userRejectedRequest: (arg?: JsonRpcErrorsArg | undefined) => EthereumProviderError; + /** + * Get an Ethereum Provider Unauthorized (4100) error. + * + * @param arg - The error message or options bag. + * @returns An instance of the {@link EthereumProviderError} class. + */ +- unauthorized: (arg?: JsonRpcErrorsArg | undefined) => EthereumProviderError; ++ unauthorized: (arg?: JsonRpcErrorsArg | undefined) => EthereumProviderError; + /** + * Get an Ethereum Provider Unsupported Method (4200) error. + * + * @param arg - The error message or options bag. + * @returns An instance of the {@link EthereumProviderError} class. + */ +- unsupportedMethod: (arg?: JsonRpcErrorsArg | undefined) => EthereumProviderError; ++ unsupportedMethod: (arg?: JsonRpcErrorsArg | undefined) => EthereumProviderError; + /** + * Get an Ethereum Provider Not Connected (4900) error. + * + * @param arg - The error message or options bag. + * @returns An instance of the {@link EthereumProviderError} class. + */ +- disconnected: (arg?: JsonRpcErrorsArg | undefined) => EthereumProviderError; ++ disconnected: (arg?: JsonRpcErrorsArg | undefined) => EthereumProviderError; + /** + * Get an Ethereum Provider Chain Not Connected (4901) error. + * + * @param arg - The error message or options bag. + * @returns An instance of the {@link EthereumProviderError} class. + */ +- chainDisconnected: (arg?: JsonRpcErrorsArg | undefined) => EthereumProviderError; ++ chainDisconnected: (arg?: JsonRpcErrorsArg | undefined) => EthereumProviderError; + /** + * Get a custom Ethereum Provider error. + * + * @param opts - The error options bag. + * @returns An instance of the {@link EthereumProviderError} class. + */ +- custom: (opts: CustomErrorArg) => EthereumProviderError; ++ custom: (opts: CustomErrorArg) => EthereumProviderError; + }; + export {}; ++//# sourceMappingURL=errors.d.ts.map +\ No newline at end of file +diff --git a/dist/errors.d.ts.map b/dist/errors.d.ts.map +new file mode 100644 +index 0000000000000000000000000000000000000000..905ecf6db600e53223dd4924c369dfe6d6f0fc45 +--- /dev/null ++++ b/dist/errors.d.ts.map +@@ -0,0 +1 @@ ++{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAEhE,OAAO,KAAK,EAAE,qBAAqB,EAAE,6BAA6B,EAAE,MAAM,SAAS,CAAC;AAGpF,KAAK,oBAAoB,CAAC,IAAI,SAAS,6BAA6B,IAAI;IACtE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,IAAI,CAAC;CACb,CAAC;AAEF,KAAK,kBAAkB,CAAC,IAAI,SAAS,qBAAqB,IAAI;IAC5D,IAAI,EAAE,MAAM,CAAC;CACd,GAAG,oBAAoB,CAAC,IAAI,CAAC,CAAC;AAE/B,KAAK,cAAc,CAAC,IAAI,SAAS,qBAAqB,IACpD,kBAAkB,CAAC,IAAI,CAAC,CAAC;AAE3B,KAAK,gBAAgB,CAAC,IAAI,SAAS,6BAA6B,IAC5D,oBAAoB,CAAC,IAAI,CAAC,GAC1B,MAAM,CAAC;AAEX,eAAO,MAAM,SAAS;IACpB;;;;;OAKG;;IAIH;;;;;OAKG;;IAKH;;;;;OAKG;;IAKH;;;;;OAKG;;IAKH;;;;;OAKG;;IAKH;;;;;;;OAOG;;IAkBH;;;;;OAKG;;IAKH;;;;;OAKG;;IAKH;;;;;OAKG;;IAKH;;;;;OAKG;;IAKH;;;;;OAKG;;IAKH;;;;;OAKG;;CAIJ,CAAC;AAEF,eAAO,MAAM,cAAc;IACzB;;;;;OAKG;;IAOH;;;;;OAKG;;IAOH;;;;;OAKG;;IAOH;;;;;OAKG;;IAOH;;;;;OAKG;;IAOH;;;;;OAKG;;CAeJ,CAAC"} +\ No newline at end of file +diff --git a/dist/index.d.ts b/dist/index.d.ts +index 9a28c4a55898eb20b2bde225eb5ddb61f767faf1..aeec7abf5aa8efdc4bdc42f33a62585dbe85f755 100644 +--- a/dist/index.d.ts ++++ b/dist/index.d.ts +@@ -3,3 +3,4 @@ export { serializeCause, serializeError, getMessageFromCode } from './utils'; + export type { DataWithOptionalCause } from './utils'; + export { rpcErrors, providerErrors } from './errors'; + export { errorCodes } from './error-constants'; ++//# sourceMappingURL=index.d.ts.map +\ No newline at end of file +diff --git a/dist/index.d.ts.map b/dist/index.d.ts.map +new file mode 100644 +index 0000000000000000000000000000000000000000..de9a76f95d32507790e23214b6aac52a0ba8c36d +--- /dev/null ++++ b/dist/index.d.ts.map +@@ -0,0 +1 @@ ++{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAC7E,YAAY,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC"} +\ No newline at end of file +diff --git a/dist/utils.d.ts b/dist/utils.d.ts +index f2b6a97b759c7b451c7310813efe92c75a9a9552..708c96206646881a6a4e2ab8e4afec18af592135 100644 +--- a/dist/utils.d.ts ++++ b/dist/utils.d.ts +@@ -1,4 +1,4 @@ +-import { Json, JsonRpcError as SerializedJsonRpcError } from '@metamask/utils'; ++import type { Json, JsonRpcError as SerializedJsonRpcError } from '@metamask/utils'; + /** + * A data object, that must be either: + * +@@ -10,6 +10,13 @@ export type DataWithOptionalCause = Json | { + [key: string]: Json | unknown; + cause: unknown; + }; ++/** ++ * A data object, that must be either: ++ * ++ * - A valid DataWithOptionalCause value. ++ * - undefined. ++ */ ++export type OptionalDataWithOptionalCause = undefined | DataWithOptionalCause; + export declare const JSON_RPC_SERVER_ERROR_MESSAGE = "Unspecified server error."; + /** + * Gets the message for a given code, or a fallback message if the code has +@@ -54,3 +61,4 @@ export declare function serializeError(error: unknown, { fallbackError, shouldIn + * @returns A JSON-serializable object containing as much information about the original error as possible. + */ + export declare function serializeCause(error: unknown): Json; ++//# sourceMappingURL=utils.d.ts.map +\ No newline at end of file +diff --git a/dist/utils.d.ts.map b/dist/utils.d.ts.map +new file mode 100644 +index 0000000000000000000000000000000000000000..f22be5f27454e41a590ef1b462e131020ab45384 +--- /dev/null ++++ b/dist/utils.d.ts.map +@@ -0,0 +1 @@ ++{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,IAAI,EACJ,YAAY,IAAI,sBAAsB,EAEvC,MAAM,iBAAiB,CAAC;AAUzB;;;;;;GAMG;AACH,MAAM,MAAM,qBAAqB,GAC7B,IAAI,GACJ;IAIE,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC;IAC9B,KAAK,EAAE,OAAO,CAAC;CAChB,CAAC;AAEN;;;;;GAKG;AACH,MAAM,MAAM,6BAA6B,GAAG,SAAS,GAAG,qBAAqB,CAAC;AAU9E,eAAO,MAAM,6BAA6B,8BAA8B,CAAC;AAIzE;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,OAAO,EACb,eAAe,GAAE,MAAyB,GACzC,MAAM,CAaR;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,MAAM,CAEzD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,OAAO,EACd,EAAE,aAA8B,EAAE,kBAAyB,EAAE;;;CAAK,GACjE,sBAAsB,CAcxB;AA+CD;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAmBnD"} +\ No newline at end of file diff --git a/package.json b/package.json index 4ccd225..e4fac79 100644 --- a/package.json +++ b/package.json @@ -33,8 +33,11 @@ "test": "jest && jest-it-up", "test:watch": "jest --watch" }, + "resolutions": { + "@metamask/rpc-errors@^5.1.1": "patch:@metamask/rpc-errors@npm%3A5.1.1#./.yarn/patches/@metamask-rpc-errors-npm-5.1.1-dc76c26803.patch" + }, "dependencies": { - "@metamask/rpc-errors": "^5.0.0", + "@metamask/rpc-errors": "^5.1.1", "@metamask/safe-event-emitter": "^3.0.0", "@metamask/utils": "^7.0.0" }, diff --git a/yarn.lock b/yarn.lock index 4fe2005..ffa4901 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1027,7 +1027,7 @@ __metadata: "@metamask/eslint-config-jest": ^11.0.0 "@metamask/eslint-config-nodejs": ^11.0.1 "@metamask/eslint-config-typescript": ^11.0.0 - "@metamask/rpc-errors": ^5.0.0 + "@metamask/rpc-errors": ^5.1.1 "@metamask/safe-event-emitter": ^3.0.0 "@metamask/utils": ^7.0.0 "@types/jest": ^29.5.0 @@ -1054,13 +1054,23 @@ __metadata: languageName: unknown linkType: soft -"@metamask/rpc-errors@npm:^5.0.0": - version: 5.0.0 - resolution: "@metamask/rpc-errors@npm:5.0.0" +"@metamask/rpc-errors@npm:5.1.1": + version: 5.1.1 + resolution: "@metamask/rpc-errors@npm:5.1.1" + dependencies: + "@metamask/utils": ^5.0.0 + fast-safe-stringify: ^2.0.6 + checksum: ccd1b24da66af3ae63960b79c04b86efb8b96acb89ca6f7e0bbfe636d23ba5cddeba533c0692eafb87c44ec6f840085372d0f21b39e05df9a80700ff61538a30 + languageName: node + linkType: hard + +"@metamask/rpc-errors@patch:@metamask/rpc-errors@npm%3A5.1.1#./.yarn/patches/@metamask-rpc-errors-npm-5.1.1-dc76c26803.patch::locator=%40metamask%2Fjson-rpc-engine%40workspace%3A.": + version: 5.1.1 + resolution: "@metamask/rpc-errors@patch:@metamask/rpc-errors@npm%3A5.1.1#./.yarn/patches/@metamask-rpc-errors-npm-5.1.1-dc76c26803.patch::version=5.1.1&hash=a6bb84&locator=%40metamask%2Fjson-rpc-engine%40workspace%3A." dependencies: "@metamask/utils": ^5.0.0 fast-safe-stringify: ^2.0.6 - checksum: fbcb21ad1460883ee9d28f487d9cf5de7d3c6ac819024a1b6e5732d5da9a9f275f19fa0b4daa06dbd9b45d89c9e50ab9f281d597324e36d3324fbc9ebfdf0ba8 + checksum: 175ef18d37c32c9c133dfbf2da2ef3b21896f5a5b03e6b34b97410fcb3915b33b74cabe588a426ac6494c82c0c91425bbb19a51f507b5cd8b9783196c515ec7f languageName: node linkType: hard From 74426cd0d31c5e1587567c1b953c33c188b05981 Mon Sep 17 00:00:00 2001 From: legobt <6wbvkn0j@anonaddy.me> Date: Wed, 23 Aug 2023 13:54:58 +0000 Subject: [PATCH 2/6] rpc-errors 5a66807ab63583 --- ...mask-rpc-errors-npm-5.1.1-dc76c26803.patch | 56 +++++++++---------- yarn.lock | 4 +- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/.yarn/patches/@metamask-rpc-errors-npm-5.1.1-dc76c26803.patch b/.yarn/patches/@metamask-rpc-errors-npm-5.1.1-dc76c26803.patch index 883ffdf..7c2f915 100644 --- a/.yarn/patches/@metamask-rpc-errors-npm-5.1.1-dc76c26803.patch +++ b/.yarn/patches/@metamask-rpc-errors-npm-5.1.1-dc76c26803.patch @@ -1,12 +1,12 @@ diff --git a/dist/classes.d.ts b/dist/classes.d.ts -index 46c2ef8eb999c0063594277974b29c8f239a6dcb..89b916c2c466ec4500a3c7c8f600fff28f9db2e5 100644 +index 46c2ef8eb999c0063594277974b29c8f239a6dcb..562d75b6cd2e5b5fc8e0c68bc4e7a95e98476abf 100644 --- a/dist/classes.d.ts +++ b/dist/classes.d.ts @@ -1,5 +1,5 @@ -import { JsonRpcError as SerializedJsonRpcError } from '@metamask/utils'; -import { DataWithOptionalCause } from './utils'; +import type { JsonRpcError as SerializedJsonRpcError } from '@metamask/utils'; -+import type { DataWithOptionalCause, OptionalDataWithOptionalCause } from './utils'; ++import type { OptionalDataWithOptionalCause } from './utils'; export type { SerializedJsonRpcError }; /** * Error subclass implementing JSON RPC 2.0 errors and Ethereum RPC errors @@ -29,7 +29,7 @@ index 46c2ef8eb999c0063594277974b29c8f239a6dcb..89b916c2c466ec4500a3c7c8f600fff2 * Permits integer error codes in the [ 1000 <= 4999 ] range. */ -export declare class EthereumProviderError extends JsonRpcError { -+export declare class EthereumProviderError extends JsonRpcError { ++export declare class EthereumProviderError extends JsonRpcError { /** * Create an Ethereum Provider JSON-RPC error. * @@ -44,11 +44,11 @@ index 46c2ef8eb999c0063594277974b29c8f239a6dcb..89b916c2c466ec4500a3c7c8f600fff2 \ No newline at end of file diff --git a/dist/classes.d.ts.map b/dist/classes.d.ts.map new file mode 100644 -index 0000000000000000000000000000000000000000..f36c4e8b1201050b79f5d01cfdc4147e2e1018ba +index 0000000000000000000000000000000000000000..6746977563e055f4328f7928d6f7e681a41e2804 --- /dev/null +++ b/dist/classes.d.ts.map @@ -0,0 +1 @@ -+{"version":3,"file":"classes.d.ts","sourceRoot":"","sources":["../../src/classes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,YAAY,IAAI,sBAAsB,EACvC,MAAM,iBAAiB,CAAC;AAIzB,OAAO,KAAK,EACV,qBAAqB,EACrB,6BAA6B,EAC9B,MAAM,SAAS,CAAC;AAGjB,YAAY,EAAE,sBAAsB,EAAE,CAAC;AAEvC;;;;;GAKG;AACH,qBAAa,YAAY,CACvB,IAAI,SAAS,6BAA6B,CAC1C,SAAQ,KAAK;IACN,IAAI,EAAE,MAAM,CAAC;IAEb,IAAI,CAAC,EAAE,IAAI,CAAC;gBAEP,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,IAAI;IAgBtD;;;;OAIG;IACH,SAAS,IAAI,sBAAsB;IAwBnC;;;;;OAKG;IACH,QAAQ,IAAI,MAAM;CAGnB;AAED;;;GAGG;AACH,qBAAa,qBAAqB,CAChC,IAAI,SAAS,qBAAqB,CAClC,SAAQ,YAAY,CAAC,IAAI,CAAC;IAC1B;;;;;;;OAOG;gBACS,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,IAAI;CASvD"} ++{"version":3,"file":"classes.d.ts","sourceRoot":"","sources":["../../src/classes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,YAAY,IAAI,sBAAsB,EACvC,MAAM,iBAAiB,CAAC;AAIzB,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,SAAS,CAAC;AAG7D,YAAY,EAAE,sBAAsB,EAAE,CAAC;AAEvC;;;;;GAKG;AACH,qBAAa,YAAY,CACvB,IAAI,SAAS,6BAA6B,CAC1C,SAAQ,KAAK;IACN,IAAI,EAAE,MAAM,CAAC;IAEb,IAAI,CAAC,EAAE,IAAI,CAAC;gBAEP,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,IAAI;IAgBtD;;;;OAIG;IACH,SAAS,IAAI,sBAAsB;IAwBnC;;;;;OAKG;IACH,QAAQ,IAAI,MAAM;CAGnB;AAED;;;GAGG;AACH,qBAAa,qBAAqB,CAChC,IAAI,SAAS,6BAA6B,CAC1C,SAAQ,YAAY,CAAC,IAAI,CAAC;IAC1B;;;;;;;OAOG;gBACS,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,IAAI;CASvD"} \ No newline at end of file diff --git a/dist/error-constants.d.ts b/dist/error-constants.d.ts index 848a90179761b64ffda108768bd96d4e5d2c7a76..89f65a67f39d727d43fcc72a7c591533c42e08dc 100644 @@ -69,27 +69,27 @@ index 0000000000000000000000000000000000000000..8181d55d6612a9e172bd3c044da8f31c +{"version":3,"file":"error-constants.d.ts","sourceRoot":"","sources":["../../src/error-constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;CAqBtB,CAAC;AAGF,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmEvB,CAAC"} \ No newline at end of file diff --git a/dist/errors.d.ts b/dist/errors.d.ts -index b4653125ce748f7da32ced278cc60f726c3cb6ee..c866a51b1399069678b559d4e7e586550d3b43e8 100644 +index b4653125ce748f7da32ced278cc60f726c3cb6ee..3ccd0fd6aebb145d59f3477733928902d4948847 100644 --- a/dist/errors.d.ts +++ b/dist/errors.d.ts @@ -1,14 +1,14 @@ import { JsonRpcError, EthereumProviderError } from './classes'; -import { DataWithOptionalCause } from './utils'; -type EthereumErrorOptions = { -+import type { DataWithOptionalCause, OptionalDataWithOptionalCause } from './utils'; ++import type { OptionalDataWithOptionalCause } from './utils'; +type EthereumErrorOptions = { message?: string; - data?: T; + data?: Data; }; -type ServerErrorOptions = { -+type ServerErrorOptions = { ++type ServerErrorOptions = { code: number; -} & EthereumErrorOptions; -type CustomErrorArg = ServerErrorOptions; -type JsonRpcErrorsArg = EthereumErrorOptions | string; +} & EthereumErrorOptions; -+type CustomErrorArg = ServerErrorOptions; ++type CustomErrorArg = ServerErrorOptions; +type JsonRpcErrorsArg = EthereumErrorOptions | string; export declare const rpcErrors: { /** @@ -99,7 +99,7 @@ index b4653125ce748f7da32ced278cc60f726c3cb6ee..c866a51b1399069678b559d4e7e58655 * @returns An instance of the {@link JsonRpcError} class. */ - parse: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; -+ parse: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; ++ parse: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; /** * Get a JSON RPC 2.0 Invalid Request (-32600) error. * @@ -107,7 +107,7 @@ index b4653125ce748f7da32ced278cc60f726c3cb6ee..c866a51b1399069678b559d4e7e58655 * @returns An instance of the {@link JsonRpcError} class. */ - invalidRequest: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; -+ invalidRequest: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; ++ invalidRequest: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; /** * Get a JSON RPC 2.0 Invalid Params (-32602) error. * @@ -115,7 +115,7 @@ index b4653125ce748f7da32ced278cc60f726c3cb6ee..c866a51b1399069678b559d4e7e58655 * @returns An instance of the {@link JsonRpcError} class. */ - invalidParams: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; -+ invalidParams: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; ++ invalidParams: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; /** * Get a JSON RPC 2.0 Method Not Found (-32601) error. * @@ -123,7 +123,7 @@ index b4653125ce748f7da32ced278cc60f726c3cb6ee..c866a51b1399069678b559d4e7e58655 * @returns An instance of the {@link JsonRpcError} class. */ - methodNotFound: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; -+ methodNotFound: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; ++ methodNotFound: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; /** * Get a JSON RPC 2.0 Internal (-32603) error. * @@ -140,7 +140,7 @@ index b4653125ce748f7da32ced278cc60f726c3cb6ee..c866a51b1399069678b559d4e7e58655 * @returns An instance of the {@link JsonRpcError} class. */ - server: (opts: ServerErrorOptions) => JsonRpcError; -+ server: (opts: ServerErrorOptions) => JsonRpcError; ++ server: (opts: ServerErrorOptions) => JsonRpcError; /** * Get an Ethereum JSON RPC Invalid Input (-32000) error. * @@ -148,7 +148,7 @@ index b4653125ce748f7da32ced278cc60f726c3cb6ee..c866a51b1399069678b559d4e7e58655 * @returns An instance of the {@link JsonRpcError} class. */ - invalidInput: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; -+ invalidInput: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; ++ invalidInput: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; /** * Get an Ethereum JSON RPC Resource Not Found (-32001) error. * @@ -156,7 +156,7 @@ index b4653125ce748f7da32ced278cc60f726c3cb6ee..c866a51b1399069678b559d4e7e58655 * @returns An instance of the {@link JsonRpcError} class. */ - resourceNotFound: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; -+ resourceNotFound: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; ++ resourceNotFound: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; /** * Get an Ethereum JSON RPC Resource Unavailable (-32002) error. * @@ -164,7 +164,7 @@ index b4653125ce748f7da32ced278cc60f726c3cb6ee..c866a51b1399069678b559d4e7e58655 * @returns An instance of the {@link JsonRpcError} class. */ - resourceUnavailable: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; -+ resourceUnavailable: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; ++ resourceUnavailable: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; /** * Get an Ethereum JSON RPC Transaction Rejected (-32003) error. * @@ -172,7 +172,7 @@ index b4653125ce748f7da32ced278cc60f726c3cb6ee..c866a51b1399069678b559d4e7e58655 * @returns An instance of the {@link JsonRpcError} class. */ - transactionRejected: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; -+ transactionRejected: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; ++ transactionRejected: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; /** * Get an Ethereum JSON RPC Method Not Supported (-32004) error. * @@ -180,7 +180,7 @@ index b4653125ce748f7da32ced278cc60f726c3cb6ee..c866a51b1399069678b559d4e7e58655 * @returns An instance of the {@link JsonRpcError} class. */ - methodNotSupported: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; -+ methodNotSupported: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; ++ methodNotSupported: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; /** * Get an Ethereum JSON RPC Limit Exceeded (-32005) error. * @@ -188,7 +188,7 @@ index b4653125ce748f7da32ced278cc60f726c3cb6ee..c866a51b1399069678b559d4e7e58655 * @returns An instance of the {@link JsonRpcError} class. */ - limitExceeded: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; -+ limitExceeded: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; ++ limitExceeded: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; }; export declare const providerErrors: { /** @@ -197,7 +197,7 @@ index b4653125ce748f7da32ced278cc60f726c3cb6ee..c866a51b1399069678b559d4e7e58655 * @returns An instance of the {@link EthereumProviderError} class. */ - userRejectedRequest: (arg?: JsonRpcErrorsArg | undefined) => EthereumProviderError; -+ userRejectedRequest: (arg?: JsonRpcErrorsArg | undefined) => EthereumProviderError; ++ userRejectedRequest: (arg?: JsonRpcErrorsArg | undefined) => EthereumProviderError; /** * Get an Ethereum Provider Unauthorized (4100) error. * @@ -205,7 +205,7 @@ index b4653125ce748f7da32ced278cc60f726c3cb6ee..c866a51b1399069678b559d4e7e58655 * @returns An instance of the {@link EthereumProviderError} class. */ - unauthorized: (arg?: JsonRpcErrorsArg | undefined) => EthereumProviderError; -+ unauthorized: (arg?: JsonRpcErrorsArg | undefined) => EthereumProviderError; ++ unauthorized: (arg?: JsonRpcErrorsArg | undefined) => EthereumProviderError; /** * Get an Ethereum Provider Unsupported Method (4200) error. * @@ -213,7 +213,7 @@ index b4653125ce748f7da32ced278cc60f726c3cb6ee..c866a51b1399069678b559d4e7e58655 * @returns An instance of the {@link EthereumProviderError} class. */ - unsupportedMethod: (arg?: JsonRpcErrorsArg | undefined) => EthereumProviderError; -+ unsupportedMethod: (arg?: JsonRpcErrorsArg | undefined) => EthereumProviderError; ++ unsupportedMethod: (arg?: JsonRpcErrorsArg | undefined) => EthereumProviderError; /** * Get an Ethereum Provider Not Connected (4900) error. * @@ -221,7 +221,7 @@ index b4653125ce748f7da32ced278cc60f726c3cb6ee..c866a51b1399069678b559d4e7e58655 * @returns An instance of the {@link EthereumProviderError} class. */ - disconnected: (arg?: JsonRpcErrorsArg | undefined) => EthereumProviderError; -+ disconnected: (arg?: JsonRpcErrorsArg | undefined) => EthereumProviderError; ++ disconnected: (arg?: JsonRpcErrorsArg | undefined) => EthereumProviderError; /** * Get an Ethereum Provider Chain Not Connected (4901) error. * @@ -229,7 +229,7 @@ index b4653125ce748f7da32ced278cc60f726c3cb6ee..c866a51b1399069678b559d4e7e58655 * @returns An instance of the {@link EthereumProviderError} class. */ - chainDisconnected: (arg?: JsonRpcErrorsArg | undefined) => EthereumProviderError; -+ chainDisconnected: (arg?: JsonRpcErrorsArg | undefined) => EthereumProviderError; ++ chainDisconnected: (arg?: JsonRpcErrorsArg | undefined) => EthereumProviderError; /** * Get a custom Ethereum Provider error. * @@ -237,18 +237,18 @@ index b4653125ce748f7da32ced278cc60f726c3cb6ee..c866a51b1399069678b559d4e7e58655 * @returns An instance of the {@link EthereumProviderError} class. */ - custom: (opts: CustomErrorArg) => EthereumProviderError; -+ custom: (opts: CustomErrorArg) => EthereumProviderError; ++ custom: (opts: CustomErrorArg) => EthereumProviderError; }; export {}; +//# sourceMappingURL=errors.d.ts.map \ No newline at end of file diff --git a/dist/errors.d.ts.map b/dist/errors.d.ts.map new file mode 100644 -index 0000000000000000000000000000000000000000..905ecf6db600e53223dd4924c369dfe6d6f0fc45 +index 0000000000000000000000000000000000000000..732e427e35b0a1c7f4cab3e3e981ca69dd38c7cb --- /dev/null +++ b/dist/errors.d.ts.map @@ -0,0 +1 @@ -+{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAEhE,OAAO,KAAK,EAAE,qBAAqB,EAAE,6BAA6B,EAAE,MAAM,SAAS,CAAC;AAGpF,KAAK,oBAAoB,CAAC,IAAI,SAAS,6BAA6B,IAAI;IACtE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,IAAI,CAAC;CACb,CAAC;AAEF,KAAK,kBAAkB,CAAC,IAAI,SAAS,qBAAqB,IAAI;IAC5D,IAAI,EAAE,MAAM,CAAC;CACd,GAAG,oBAAoB,CAAC,IAAI,CAAC,CAAC;AAE/B,KAAK,cAAc,CAAC,IAAI,SAAS,qBAAqB,IACpD,kBAAkB,CAAC,IAAI,CAAC,CAAC;AAE3B,KAAK,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;;;OAKG;;IAKH;;;;;;;OAOG;;IAkBH;;;;;OAKG;;IAKH;;;;;OAKG;;IAKH;;;;;OAKG;;IAKH;;;;;OAKG;;IAKH;;;;;OAKG;;IAKH;;;;;OAKG;;CAIJ,CAAC;AAEF,eAAO,MAAM,cAAc;IACzB;;;;;OAKG;;IAOH;;;;;OAKG;;IAOH;;;;;OAKG;;IAOH;;;;;OAKG;;IAOH;;;;;OAKG;;IAOH;;;;;OAKG;;CAiBJ,CAAC"} \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts index 9a28c4a55898eb20b2bde225eb5ddb61f767faf1..aeec7abf5aa8efdc4bdc42f33a62585dbe85f755 100644 diff --git a/yarn.lock b/yarn.lock index ffa4901..6c4c01a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1066,11 +1066,11 @@ __metadata: "@metamask/rpc-errors@patch:@metamask/rpc-errors@npm%3A5.1.1#./.yarn/patches/@metamask-rpc-errors-npm-5.1.1-dc76c26803.patch::locator=%40metamask%2Fjson-rpc-engine%40workspace%3A.": version: 5.1.1 - resolution: "@metamask/rpc-errors@patch:@metamask/rpc-errors@npm%3A5.1.1#./.yarn/patches/@metamask-rpc-errors-npm-5.1.1-dc76c26803.patch::version=5.1.1&hash=a6bb84&locator=%40metamask%2Fjson-rpc-engine%40workspace%3A." + resolution: "@metamask/rpc-errors@patch:@metamask/rpc-errors@npm%3A5.1.1#./.yarn/patches/@metamask-rpc-errors-npm-5.1.1-dc76c26803.patch::version=5.1.1&hash=b699ed&locator=%40metamask%2Fjson-rpc-engine%40workspace%3A." dependencies: "@metamask/utils": ^5.0.0 fast-safe-stringify: ^2.0.6 - checksum: 175ef18d37c32c9c133dfbf2da2ef3b21896f5a5b03e6b34b97410fcb3915b33b74cabe588a426ac6494c82c0c91425bbb19a51f507b5cd8b9783196c515ec7f + checksum: 76d0e5c0e9c49c69881b56db3a5ab8d3240db1294089cd9daff14a145ae1dd014653ff48aa6976f6d4a79e2b9603726c221f07be6a36fae1165a11545eb82455 languageName: node linkType: hard From 04ba7b7e38793f267cfcfdd87b007c4da246db51 Mon Sep 17 00:00:00 2001 From: legobt <6wbvkn0j@anonaddy.me> Date: Wed, 23 Aug 2023 14:34:04 +0000 Subject: [PATCH 3/6] rpc-errors df1102a03e78e10197137146499ce2a631e6c22c --- ...mask-rpc-errors-npm-5.1.1-dc76c26803.patch | 176 ++++++------------ yarn.lock | 4 +- 2 files changed, 58 insertions(+), 122 deletions(-) diff --git a/.yarn/patches/@metamask-rpc-errors-npm-5.1.1-dc76c26803.patch b/.yarn/patches/@metamask-rpc-errors-npm-5.1.1-dc76c26803.patch index 7c2f915..3e1e779 100644 --- a/.yarn/patches/@metamask-rpc-errors-npm-5.1.1-dc76c26803.patch +++ b/.yarn/patches/@metamask-rpc-errors-npm-5.1.1-dc76c26803.patch @@ -1,96 +1,62 @@ diff --git a/dist/classes.d.ts b/dist/classes.d.ts -index 46c2ef8eb999c0063594277974b29c8f239a6dcb..562d75b6cd2e5b5fc8e0c68bc4e7a95e98476abf 100644 +index 46c2ef8eb999c0063594277974b29c8f239a6dcb..d9befc615d70c27607854fcb5b6dc595c1be226f 100644 --- a/dist/classes.d.ts +++ b/dist/classes.d.ts @@ -1,5 +1,5 @@ --import { JsonRpcError as SerializedJsonRpcError } from '@metamask/utils'; + import { JsonRpcError as SerializedJsonRpcError } from '@metamask/utils'; -import { DataWithOptionalCause } from './utils'; -+import type { JsonRpcError as SerializedJsonRpcError } from '@metamask/utils'; +import type { OptionalDataWithOptionalCause } from './utils'; export type { SerializedJsonRpcError }; /** * Error subclass implementing JSON RPC 2.0 errors and Ethereum RPC errors -@@ -7,10 +7,10 @@ export type { SerializedJsonRpcError }; +@@ -7,7 +7,7 @@ export type { SerializedJsonRpcError }; * * Permits any integer error code. */ -export declare class JsonRpcError extends Error { -+export declare class JsonRpcError extends Error { ++export declare class JsonRpcError extends Error { code: number; -- data?: T; -- constructor(code: number, message: string, data?: T); -+ data?: Data; -+ constructor(code: number, message: string, data?: Data); - /** - * Get the error as JSON-serializable object. - * + data?: T; + constructor(code: number, message: string, data?: T); @@ -29,7 +29,7 @@ export declare class JsonRpcError extends Error * Error subclass implementing Ethereum Provider errors per EIP-1193. * Permits integer error codes in the [ 1000 <= 4999 ] range. */ -export declare class EthereumProviderError extends JsonRpcError { -+export declare class EthereumProviderError extends JsonRpcError { ++export declare class EthereumProviderError extends JsonRpcError { /** * Create an Ethereum Provider JSON-RPC error. * -@@ -38,5 +38,6 @@ export declare class EthereumProviderError exte - * @param message - The JSON-RPC error message. - * @param data - Optional data to include in the error. - */ -- constructor(code: number, message: string, data?: T); -+ constructor(code: number, message: string, data?: Data); - } -+//# sourceMappingURL=classes.d.ts.map -\ No newline at end of file -diff --git a/dist/classes.d.ts.map b/dist/classes.d.ts.map -new file mode 100644 -index 0000000000000000000000000000000000000000..6746977563e055f4328f7928d6f7e681a41e2804 ---- /dev/null -+++ b/dist/classes.d.ts.map -@@ -0,0 +1 @@ -+{"version":3,"file":"classes.d.ts","sourceRoot":"","sources":["../../src/classes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,YAAY,IAAI,sBAAsB,EACvC,MAAM,iBAAiB,CAAC;AAIzB,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,SAAS,CAAC;AAG7D,YAAY,EAAE,sBAAsB,EAAE,CAAC;AAEvC;;;;;GAKG;AACH,qBAAa,YAAY,CACvB,IAAI,SAAS,6BAA6B,CAC1C,SAAQ,KAAK;IACN,IAAI,EAAE,MAAM,CAAC;IAEb,IAAI,CAAC,EAAE,IAAI,CAAC;gBAEP,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,IAAI;IAgBtD;;;;OAIG;IACH,SAAS,IAAI,sBAAsB;IAwBnC;;;;;OAKG;IACH,QAAQ,IAAI,MAAM;CAGnB;AAED;;;GAGG;AACH,qBAAa,qBAAqB,CAChC,IAAI,SAAS,6BAA6B,CAC1C,SAAQ,YAAY,CAAC,IAAI,CAAC;IAC1B;;;;;;;OAOG;gBACS,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,IAAI;CASvD"} -\ No newline at end of file -diff --git a/dist/error-constants.d.ts b/dist/error-constants.d.ts -index 848a90179761b64ffda108768bd96d4e5d2c7a76..89f65a67f39d727d43fcc72a7c591533c42e08dc 100644 ---- a/dist/error-constants.d.ts -+++ b/dist/error-constants.d.ts -@@ -86,3 +86,4 @@ export declare const errorValues: { - message: string; - }; - }; -+//# sourceMappingURL=error-constants.d.ts.map +diff --git a/dist/classes.js.map b/dist/classes.js.map +index 3ec85fd22f21a45e7537436251feb70f8156e585..574d6c312ac289cd4c22291a0d9c1d17123e44c4 100644 +--- a/dist/classes.js.map ++++ b/dist/classes.js.map +@@ -1 +1 @@ +-{"version":3,"file":"classes.js","sourceRoot":"","sources":["../src/classes.ts"],"names":[],"mappings":";;;;;;AAAA,2CAIyB;AACzB,8EAAgD;AAEhD,mCAAgE;AAIhE;;;;;GAKG;AACH,MAAa,YAA8C,SAAQ,KAAK;IAKtE,YAAY,IAAY,EAAE,OAAe,EAAE,IAAQ;QACjD,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE;YAC3B,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;SAC/C;QAED,IAAI,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;YAC3C,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;SAC1D;QAED,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,IAAI,KAAK,SAAS,EAAE;YACtB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;SAClB;IACH,CAAC;IAED;;;;OAIG;IACH,SAAS;QACP,MAAM,UAAU,GAA2B;YACzC,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,OA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S,CAAC;KAClB;IAED,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import {\n isPlainObject,\n Json,\n JsonRpcError as SerializedJsonRpcError,\n} from '@metamask/utils';\nimport safeStringify from 'fast-safe-stringify';\n\nimport { DataWithOptionalCause, serializeCause } from './utils';\n\nexport type { SerializedJsonRpcError };\n\n/**\n * Error subclass implementing JSON RPC 2.0 errors and Ethereum RPC errors\n * per EIP-1474.\n *\n * Permits any integer error code.\n */\nexport class JsonRpcError extends Error {\n public code: number;\n\n public data?: T;\n\n constructor(code: number, message: string, data?: T) {\n if (!Number.isInteger(code)) {\n throw new Error('\"code\" must be an integer.');\n }\n\n if (!message || typeof message !== 'string') {\n throw new Error('\"message\" must be a non-empty string.');\n }\n\n super(message);\n this.code = code;\n if (data !== undefined) {\n this.data = data;\n }\n }\n\n /**\n * Get the error as JSON-serializable object.\n *\n * @returns A plain object with all public class properties.\n */\n serialize(): SerializedJsonRpcError {\n const serialized: SerializedJsonRpcError = {\n code: this.code,\n message: this.message,\n };\n\n if (this.data !== undefined) {\n // `this.data` is not guaranteed to be a plain object, but this simplifies\n // the type guard below. We can safely cast it because we know it's a\n // JSON-serializable value.\n serialized.data = this.data as { [key: string]: Json };\n\n if (isPlainObject(this.data)) {\n serialized.data.cause = serializeCause(this.data.cause);\n }\n }\n\n if (this.stack) {\n serialized.stack = this.stack;\n }\n\n return serialized;\n }\n\n /**\n * Get a string representation of the serialized error, omitting any circular\n * references.\n *\n * @returns A string representation of the serialized error.\n */\n toString(): string {\n return safeStringify(this.serialize(), stringifyReplacer, 2);\n }\n}\n\n/**\n * Error subclass implementing Ethereum Provider errors per EIP-1193.\n * Permits integer error codes in the [ 1000 <= 4999 ] range.\n */\nexport class EthereumProviderError<\n T extends DataWithOptionalCause,\n> extends JsonRpcError {\n /**\n * Create an Ethereum Provider JSON-RPC error.\n *\n * @param code - The JSON-RPC error code. Must be an integer in the\n * `1000 <= n <= 4999` range.\n * @param message - The JSON-RPC error message.\n * @param data - Optional data to include in the error.\n */\n constructor(code: number, message: string, data?: T) {\n if (!isValidEthProviderCode(code)) {\n throw new Error(\n '\"code\" must be an integer such that: 1000 <= code <= 4999',\n );\n }\n\n super(code, message, data);\n }\n}\n\n/**\n * Check if the given code is a valid JSON-RPC error code.\n *\n * @param code - The code to check.\n * @returns Whether the code is valid.\n */\nfunction isValidEthProviderCode(code: number): boolean {\n return Number.isInteger(code) && code >= 1000 && code <= 4999;\n}\n\n/**\n * A JSON replacer function that omits circular references.\n *\n * @param _ - The key being replaced.\n * @param value - The value being replaced.\n * @returns The value to use in place of the original value.\n */\nfunction stringifyReplacer(_: unknown, value: unknown): unknown {\n if (value === '[Circular]') {\n return undefined;\n }\n\n return value;\n}\n"]} \ No newline at end of file -diff --git a/dist/error-constants.d.ts.map b/dist/error-constants.d.ts.map -new file mode 100644 -index 0000000000000000000000000000000000000000..8181d55d6612a9e172bd3c044da8f31ce7f6240b ---- /dev/null -+++ b/dist/error-constants.d.ts.map -@@ -0,0 +1 @@ -+{"version":3,"file":"error-constants.d.ts","sourceRoot":"","sources":["../../src/error-constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;CAqBtB,CAAC;AAGF,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmEvB,CAAC"} ++{"version":3,"file":"classes.js","sourceRoot":"","sources":["../src/classes.ts"],"names":[],"mappings":";;;;;;AAAA,2CAIyB;AACzB,8EAAgD;AAGhD,mCAAyC;AAIzC;;;;;GAKG;AACH,MAAa,YAEX,SAAQ,KAAK;IAKb,YAAY,IAAY,EAAE,OAAe,EAAE,IAAQ;QACjD,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE;YAC3B,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;SAC/C;QAED,IAAI,CAAC,OAAO,IAAI,OAA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IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;IAC7B,CAAC;CACF;AApBD,sDAoBC;AAED;;;;;GAKG;AACH,SAAS,sBAAsB,CAAC,IAAY;IAC1C,OAAO,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,CAAC;AAChE,CAAC;AAED;;;;;;GAMG;AACH,SAAS,iBAAiB,CAAC,CAAU,EAAE,KAAc;IACnD,IAAI,KAAK,KAAK,YAAY,EAAE;QAC1B,OAAO,SAAS,CAAC;KAClB;IAED,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import {\n isPlainObject,\n Json,\n JsonRpcError as SerializedJsonRpcError,\n} from '@metamask/utils';\nimport safeStringify from 'fast-safe-stringify';\n\nimport type { OptionalDataWithOptionalCause } from './utils';\nimport { serializeCause } from './utils';\n\nexport type { SerializedJsonRpcError };\n\n/**\n * Error subclass implementing JSON RPC 2.0 errors and Ethereum RPC errors\n * per EIP-1474.\n *\n * Permits any integer error code.\n */\nexport class JsonRpcError<\n T extends OptionalDataWithOptionalCause,\n> extends Error {\n public code: number;\n\n public data?: T;\n\n constructor(code: number, message: string, data?: T) {\n if (!Number.isInteger(code)) {\n throw new Error('\"code\" must be an integer.');\n }\n\n if (!message || typeof message !== 'string') {\n throw new Error('\"message\" must be a non-empty string.');\n }\n\n super(message);\n this.code = code;\n if (data !== undefined) {\n this.data = data;\n }\n }\n\n /**\n * Get the error as JSON-serializable object.\n *\n * @returns A plain object with all public class properties.\n */\n serialize(): SerializedJsonRpcError {\n const serialized: SerializedJsonRpcError = {\n code: this.code,\n message: this.message,\n };\n\n if (this.data !== undefined) {\n // `this.data` is not guaranteed to be a plain object, but this simplifies\n // the type guard below. We can safely cast it because we know it's a\n // JSON-serializable value.\n serialized.data = this.data as { [key: string]: Json };\n\n if (isPlainObject(this.data)) {\n serialized.data.cause = serializeCause(this.data.cause);\n }\n }\n\n if (this.stack) {\n serialized.stack = this.stack;\n }\n\n return serialized;\n }\n\n /**\n * Get a string representation of the serialized error, omitting any circular\n * references.\n *\n * @returns A string representation of the serialized error.\n */\n toString(): string {\n return safeStringify(this.serialize(), stringifyReplacer, 2);\n }\n}\n\n/**\n * Error subclass implementing Ethereum Provider errors per EIP-1193.\n * Permits integer error codes in the [ 1000 <= 4999 ] range.\n */\nexport class EthereumProviderError<\n T extends OptionalDataWithOptionalCause,\n> extends JsonRpcError {\n /**\n * Create an Ethereum Provider JSON-RPC error.\n *\n * @param code - The JSON-RPC error code. Must be an integer in the\n * `1000 <= n <= 4999` range.\n * @param message - The JSON-RPC error message.\n * @param data - Optional data to include in the error.\n */\n constructor(code: number, message: string, data?: T) {\n if (!isValidEthProviderCode(code)) {\n throw new Error(\n '\"code\" must be an integer such that: 1000 <= code <= 4999',\n );\n }\n\n super(code, message, data);\n }\n}\n\n/**\n * Check if the given code is a valid JSON-RPC error code.\n *\n * @param code - The code to check.\n * @returns Whether the code is valid.\n */\nfunction isValidEthProviderCode(code: number): boolean {\n return Number.isInteger(code) && code >= 1000 && code <= 4999;\n}\n\n/**\n * A JSON replacer function that omits circular references.\n *\n * @param _ - The key being replaced.\n * @param value - The value being replaced.\n * @returns The value to use in place of the original value.\n */\nfunction stringifyReplacer(_: unknown, value: unknown): unknown {\n if (value === '[Circular]') {\n return undefined;\n }\n\n return value;\n}\n"]} \ No newline at end of file diff --git a/dist/errors.d.ts b/dist/errors.d.ts -index b4653125ce748f7da32ced278cc60f726c3cb6ee..3ccd0fd6aebb145d59f3477733928902d4948847 100644 +index b4653125ce748f7da32ced278cc60f726c3cb6ee..cbe8abece705fcf13e977e9d107f23f55a18064d 100644 --- a/dist/errors.d.ts +++ b/dist/errors.d.ts @@ -1,14 +1,14 @@ import { JsonRpcError, EthereumProviderError } from './classes'; -import { DataWithOptionalCause } from './utils'; -type EthereumErrorOptions = { -+import type { OptionalDataWithOptionalCause } from './utils'; -+type EthereumErrorOptions = { ++import { OptionalDataWithOptionalCause } from './utils'; ++type EthereumErrorOptions = { message?: string; -- data?: T; -+ data?: Data; + data?: T; }; -type ServerErrorOptions = { -+type ServerErrorOptions = { ++type ServerErrorOptions = { code: number; --} & EthereumErrorOptions; + } & EthereumErrorOptions; -type CustomErrorArg = ServerErrorOptions; -type JsonRpcErrorsArg = EthereumErrorOptions | string; -+} & EthereumErrorOptions; -+type CustomErrorArg = ServerErrorOptions; -+type JsonRpcErrorsArg = EthereumErrorOptions | string; ++type CustomErrorArg = ServerErrorOptions; ++type JsonRpcErrorsArg = EthereumErrorOptions | string; export declare const rpcErrors: { /** * Get a JSON RPC 2.0 Parse (-32700) error. @@ -99,7 +65,7 @@ index b4653125ce748f7da32ced278cc60f726c3cb6ee..3ccd0fd6aebb145d59f3477733928902 * @returns An instance of the {@link JsonRpcError} class. */ - parse: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; -+ parse: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; ++ parse: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; /** * Get a JSON RPC 2.0 Invalid Request (-32600) error. * @@ -107,7 +73,7 @@ index b4653125ce748f7da32ced278cc60f726c3cb6ee..3ccd0fd6aebb145d59f3477733928902 * @returns An instance of the {@link JsonRpcError} class. */ - invalidRequest: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; -+ invalidRequest: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; ++ invalidRequest: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; /** * Get a JSON RPC 2.0 Invalid Params (-32602) error. * @@ -115,7 +81,7 @@ index b4653125ce748f7da32ced278cc60f726c3cb6ee..3ccd0fd6aebb145d59f3477733928902 * @returns An instance of the {@link JsonRpcError} class. */ - invalidParams: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; -+ invalidParams: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; ++ invalidParams: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; /** * Get a JSON RPC 2.0 Method Not Found (-32601) error. * @@ -123,7 +89,7 @@ index b4653125ce748f7da32ced278cc60f726c3cb6ee..3ccd0fd6aebb145d59f3477733928902 * @returns An instance of the {@link JsonRpcError} class. */ - methodNotFound: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; -+ methodNotFound: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; ++ methodNotFound: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; /** * Get a JSON RPC 2.0 Internal (-32603) error. * @@ -131,7 +97,7 @@ index b4653125ce748f7da32ced278cc60f726c3cb6ee..3ccd0fd6aebb145d59f3477733928902 * @returns An instance of the {@link JsonRpcError} class. */ - internal: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; -+ internal: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; ++ internal: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; /** * Get a JSON RPC 2.0 Server error. * Permits integer error codes in the [ -32099 <= -32005 ] range. @@ -140,7 +106,7 @@ index b4653125ce748f7da32ced278cc60f726c3cb6ee..3ccd0fd6aebb145d59f3477733928902 * @returns An instance of the {@link JsonRpcError} class. */ - server: (opts: ServerErrorOptions) => JsonRpcError; -+ server: (opts: ServerErrorOptions) => JsonRpcError; ++ server: (opts: ServerErrorOptions) => JsonRpcError; /** * Get an Ethereum JSON RPC Invalid Input (-32000) error. * @@ -148,7 +114,7 @@ index b4653125ce748f7da32ced278cc60f726c3cb6ee..3ccd0fd6aebb145d59f3477733928902 * @returns An instance of the {@link JsonRpcError} class. */ - invalidInput: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; -+ invalidInput: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; ++ invalidInput: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; /** * Get an Ethereum JSON RPC Resource Not Found (-32001) error. * @@ -156,7 +122,7 @@ index b4653125ce748f7da32ced278cc60f726c3cb6ee..3ccd0fd6aebb145d59f3477733928902 * @returns An instance of the {@link JsonRpcError} class. */ - resourceNotFound: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; -+ resourceNotFound: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; ++ resourceNotFound: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; /** * Get an Ethereum JSON RPC Resource Unavailable (-32002) error. * @@ -164,7 +130,7 @@ index b4653125ce748f7da32ced278cc60f726c3cb6ee..3ccd0fd6aebb145d59f3477733928902 * @returns An instance of the {@link JsonRpcError} class. */ - resourceUnavailable: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; -+ resourceUnavailable: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; ++ resourceUnavailable: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; /** * Get an Ethereum JSON RPC Transaction Rejected (-32003) error. * @@ -172,7 +138,7 @@ index b4653125ce748f7da32ced278cc60f726c3cb6ee..3ccd0fd6aebb145d59f3477733928902 * @returns An instance of the {@link JsonRpcError} class. */ - transactionRejected: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; -+ transactionRejected: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; ++ transactionRejected: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; /** * Get an Ethereum JSON RPC Method Not Supported (-32004) error. * @@ -180,7 +146,7 @@ index b4653125ce748f7da32ced278cc60f726c3cb6ee..3ccd0fd6aebb145d59f3477733928902 * @returns An instance of the {@link JsonRpcError} class. */ - methodNotSupported: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; -+ methodNotSupported: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; ++ methodNotSupported: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; /** * Get an Ethereum JSON RPC Limit Exceeded (-32005) error. * @@ -188,16 +154,16 @@ index b4653125ce748f7da32ced278cc60f726c3cb6ee..3ccd0fd6aebb145d59f3477733928902 * @returns An instance of the {@link JsonRpcError} class. */ - limitExceeded: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; -+ limitExceeded: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; ++ limitExceeded: (arg?: JsonRpcErrorsArg | undefined) => JsonRpcError; }; export declare const providerErrors: { /** -@@ -104,41 +104,42 @@ export declare const providerErrors: { +@@ -104,41 +104,41 @@ export declare const providerErrors: { * @param arg - The error message or options bag. * @returns An instance of the {@link EthereumProviderError} class. */ - userRejectedRequest: (arg?: JsonRpcErrorsArg | undefined) => EthereumProviderError; -+ userRejectedRequest: (arg?: JsonRpcErrorsArg | undefined) => EthereumProviderError; ++ userRejectedRequest: (arg?: JsonRpcErrorsArg | undefined) => EthereumProviderError; /** * Get an Ethereum Provider Unauthorized (4100) error. * @@ -205,7 +171,7 @@ index b4653125ce748f7da32ced278cc60f726c3cb6ee..3ccd0fd6aebb145d59f3477733928902 * @returns An instance of the {@link EthereumProviderError} class. */ - unauthorized: (arg?: JsonRpcErrorsArg | undefined) => EthereumProviderError; -+ unauthorized: (arg?: JsonRpcErrorsArg | undefined) => EthereumProviderError; ++ unauthorized: (arg?: JsonRpcErrorsArg | undefined) => EthereumProviderError; /** * Get an Ethereum Provider Unsupported Method (4200) error. * @@ -213,7 +179,7 @@ index b4653125ce748f7da32ced278cc60f726c3cb6ee..3ccd0fd6aebb145d59f3477733928902 * @returns An instance of the {@link EthereumProviderError} class. */ - unsupportedMethod: (arg?: JsonRpcErrorsArg | undefined) => EthereumProviderError; -+ unsupportedMethod: (arg?: JsonRpcErrorsArg | undefined) => EthereumProviderError; ++ unsupportedMethod: (arg?: JsonRpcErrorsArg | undefined) => EthereumProviderError; /** * Get an Ethereum Provider Not Connected (4900) error. * @@ -221,7 +187,7 @@ index b4653125ce748f7da32ced278cc60f726c3cb6ee..3ccd0fd6aebb145d59f3477733928902 * @returns An instance of the {@link EthereumProviderError} class. */ - disconnected: (arg?: JsonRpcErrorsArg | undefined) => EthereumProviderError; -+ disconnected: (arg?: JsonRpcErrorsArg | undefined) => EthereumProviderError; ++ disconnected: (arg?: JsonRpcErrorsArg | undefined) => EthereumProviderError; /** * Get an Ethereum Provider Chain Not Connected (4901) error. * @@ -229,7 +195,7 @@ index b4653125ce748f7da32ced278cc60f726c3cb6ee..3ccd0fd6aebb145d59f3477733928902 * @returns An instance of the {@link EthereumProviderError} class. */ - chainDisconnected: (arg?: JsonRpcErrorsArg | undefined) => EthereumProviderError; -+ chainDisconnected: (arg?: JsonRpcErrorsArg | undefined) => EthereumProviderError; ++ chainDisconnected: (arg?: JsonRpcErrorsArg | undefined) => EthereumProviderError; /** * Get a custom Ethereum Provider error. * @@ -237,47 +203,22 @@ index b4653125ce748f7da32ced278cc60f726c3cb6ee..3ccd0fd6aebb145d59f3477733928902 * @returns An instance of the {@link EthereumProviderError} class. */ - custom: (opts: CustomErrorArg) => EthereumProviderError; -+ custom: (opts: CustomErrorArg) => EthereumProviderError; ++ custom: (opts: CustomErrorArg) => EthereumProviderError; }; export {}; -+//# sourceMappingURL=errors.d.ts.map -\ No newline at end of file -diff --git a/dist/errors.d.ts.map b/dist/errors.d.ts.map -new file mode 100644 -index 0000000000000000000000000000000000000000..732e427e35b0a1c7f4cab3e3e981ca69dd38c7cb ---- /dev/null -+++ b/dist/errors.d.ts.map -@@ -0,0 +1 @@ -+{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAEhE,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,SAAS,CAAC;AAG7D,KAAK,oBAAoB,CAAC,IAAI,SAAS,6BAA6B,IAAI;IACtE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,IAAI,CAAC;CACb,CAAC;AAEF,KAAK,kBAAkB,CAAC,IAAI,SAAS,6BAA6B,IAAI;IACpE,IAAI,EAAE,MAAM,CAAC;CACd,GAAG,oBAAoB,CAAC,IAAI,CAAC,CAAC;AAE/B,KAAK,cAAc,CAAC,IAAI,SAAS,6BAA6B,IAC5D,kBAAkB,CAAC,IAAI,CAAC,CAAC;AAE3B,KAAK,gBAAgB,CAAC,IAAI,SAAS,6BAA6B,IAC5D,oBAAoB,CAAC,IAAI,CAAC,GAC1B,MAAM,CAAC;AAEX,eAAO,MAAM,SAAS;IACpB;;;;;OAKG;;IAKH;;;;;OAKG;;IAKH;;;;;OAKG;;IAKH;;;;;OAKG;;IAKH;;;;;OAKG;;IAKH;;;;;;;OAOG;;IAkBH;;;;;OAKG;;IAKH;;;;;OAKG;;IAKH;;;;;OAKG;;IAKH;;;;;OAKG;;IAKH;;;;;OAKG;;IAKH;;;;;OAKG;;CAIJ,CAAC;AAEF,eAAO,MAAM,cAAc;IACzB;;;;;OAKG;;IAOH;;;;;OAKG;;IAOH;;;;;OAKG;;IAOH;;;;;OAKG;;IAOH;;;;;OAKG;;IAOH;;;;;OAKG;;CAiBJ,CAAC"} -\ No newline at end of file -diff --git a/dist/index.d.ts b/dist/index.d.ts -index 9a28c4a55898eb20b2bde225eb5ddb61f767faf1..aeec7abf5aa8efdc4bdc42f33a62585dbe85f755 100644 ---- a/dist/index.d.ts -+++ b/dist/index.d.ts -@@ -3,3 +3,4 @@ export { serializeCause, serializeError, getMessageFromCode } from './utils'; - export type { DataWithOptionalCause } from './utils'; - export { rpcErrors, providerErrors } from './errors'; - export { errorCodes } from './error-constants'; -+//# sourceMappingURL=index.d.ts.map +diff --git a/dist/errors.js.map b/dist/errors.js.map +index 3ce4a37cef2de53f217b1573224090813e727bc8..d542732ea1cb5a3f8c8569405ef545edab1ebc12 100644 +--- a/dist/errors.js.map ++++ b/dist/errors.js.map +@@ -1 +1 @@ +-{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AAAA,uCAAgE;AAChE,uDAA+C;AAC/C,mCAAoE;AAiBvD,QAAA,SAAS,GAAG;IACvB;;;;;OAKG;IACH,KAAK,EAAE,CAAkC,GAAyB,EAAE,EAAE,CACpE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CACL,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,SAAS,SAAS,CAChB,GAAyB;IAEzB,IAAI,GAAG,EAAE;QACP,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;YAC3B,OAAO,CAAC,GAAG,CAAC,CAAC;SACd;aAAM,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;YACzD,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,GAAG,CAAC;YAE9B,IAAI,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;gBAC1C,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;aACjD;YACD,OAAO,CAAC,OAAO,IAAI,SAAS,EAAE,IAAI,CAAC,CAAC;SACrC;KACF;IAED,OAAO,EAAE,CAAC;AACZ,CAAC","sourcesContent":["import { JsonRpcError, EthereumProviderError } from './classes';\nimport { errorCodes } from './error-constants';\nimport { DataWithOptionalCause, getMessageFromCode } from './utils';\n\ntype EthereumErrorOptions = {\n message?: string;\n data?: T;\n};\n\ntype ServerErrorOptions = {\n code: number;\n} & EthereumErrorOptions;\n\ntype CustomErrorArg = ServerErrorOptions;\n\ntype JsonRpcErrorsArg =\n | EthereumErrorOptions\n | string;\n\nexport const rpcErrors = {\n /**\n * Get a JSON RPC 2.0 Parse (-32700) error.\n *\n * @param arg - The error message or options bag.\n * @returns An instance of the {@link JsonRpcError} class.\n */\n parse: (arg?: JsonRpcErrorsArg) =>\n getJsonRpcError(errorCodes.rpc.parse, arg),\n\n /**\n * Get a JSON RPC 2.0 Invalid Request (-32600) error.\n *\n * @param arg - The error message or options bag.\n * @returns An instance of the {@link JsonRpcError} class.\n */\n invalidRequest: (\n arg?: JsonRpcErrorsArg,\n ) => getJsonRpcError(errorCodes.rpc.invalidRequest, arg),\n\n /**\n * Get a JSON RPC 2.0 Invalid Params (-32602) error.\n *\n * @param arg - The error message or options bag.\n * @returns An instance of the {@link JsonRpcError} class.\n */\n invalidParams: (arg?: JsonRpcErrorsArg) =>\n getJsonRpcError(errorCodes.rpc.invalidParams, arg),\n\n /**\n * Get a JSON RPC 2.0 Method Not Found (-32601) error.\n *\n * @param arg - The error message or options bag.\n * @returns An instance of the {@link JsonRpcError} class.\n */\n methodNotFound: (\n arg?: JsonRpcErrorsArg,\n ) => getJsonRpcError(errorCodes.rpc.methodNotFound, arg),\n\n /**\n * Get a JSON RPC 2.0 Internal (-32603) error.\n *\n * @param arg - The error message or options bag.\n * @returns An instance of the {@link JsonRpcError} class.\n */\n internal: (arg?: JsonRpcErrorsArg) =>\n getJsonRpcError(errorCodes.rpc.internal, arg),\n\n /**\n * Get a JSON RPC 2.0 Server error.\n * Permits integer error codes in the [ -32099 <= -32005 ] range.\n * Codes -32000 through -32004 are reserved by EIP-1474.\n *\n * @param opts - The error options bag.\n * @returns An instance of the {@link JsonRpcError} class.\n */\n server: (opts: ServerErrorOptions) => {\n if (!opts || typeof opts !== 'object' || Array.isArray(opts)) {\n throw new Error(\n 'Ethereum RPC Server errors must provide single object argument.',\n );\n }\n const { code } = opts;\n if (!Number.isInteger(code) || code > -32005 || code < -32099) {\n throw new Error(\n '\"code\" must be an integer such that: -32099 <= code <= -32005',\n );\n }\n return getJsonRpcError(code, opts);\n },\n\n /**\n * Get an Ethereum JSON RPC Invalid Input (-32000) error.\n *\n * @param arg - The error message or options bag.\n * @returns An instance of the {@link JsonRpcError} class.\n */\n invalidInput: (arg?: JsonRpcErrorsArg) =>\n getJsonRpcError(errorCodes.rpc.invalidInput, arg),\n\n /**\n * Get an Ethereum JSON RPC Resource Not Found (-32001) error.\n *\n * @param arg - The error message or options bag.\n * @returns An instance of the {@link JsonRpcError} class.\n */\n resourceNotFound: (\n arg?: JsonRpcErrorsArg,\n ) => getJsonRpcError(errorCodes.rpc.resourceNotFound, arg),\n\n /**\n * Get an Ethereum JSON RPC Resource Unavailable (-32002) error.\n *\n * @param arg - The error message or options bag.\n * @returns An instance of the {@link JsonRpcError} class.\n */\n resourceUnavailable: (\n arg?: JsonRpcErrorsArg,\n ) => getJsonRpcError(errorCodes.rpc.resourceUnavailable, arg),\n\n /**\n * Get an Ethereum JSON RPC Transaction Rejected (-32003) error.\n *\n * @param arg - The error message or options bag.\n * @returns An instance of the {@link JsonRpcError} class.\n */\n transactionRejected: (\n arg?: JsonRpcErrorsArg,\n ) => getJsonRpcError(errorCodes.rpc.transactionRejected, arg),\n\n /**\n * Get an Ethereum JSON RPC Method Not Supported (-32004) error.\n *\n * @param arg - The error message or options bag.\n * @returns An instance of the {@link JsonRpcError} class.\n */\n methodNotSupported: (\n arg?: JsonRpcErrorsArg,\n ) => getJsonRpcError(errorCodes.rpc.methodNotSupported, arg),\n\n /**\n * Get an Ethereum JSON RPC Limit Exceeded (-32005) error.\n *\n * @param arg - The error message or options bag.\n * @returns An instance of the {@link JsonRpcError} class.\n */\n limitExceeded: (arg?: JsonRpcErrorsArg) =>\n getJsonRpcError(errorCodes.rpc.limitExceeded, arg),\n};\n\nexport const providerErrors = {\n /**\n * Get an Ethereum Provider User Rejected Request (4001) error.\n *\n * @param arg - The error message or options bag.\n * @returns An instance of the {@link EthereumProviderError} class.\n */\n userRejectedRequest: (\n arg?: JsonRpcErrorsArg,\n ) => {\n return getEthProviderError(errorCodes.provider.userRejectedRequest, arg);\n },\n\n /**\n * Get an Ethereum Provider Unauthorized (4100) error.\n *\n * @param arg - The error message or options bag.\n * @returns An instance of the {@link EthereumProviderError} class.\n */\n unauthorized: (\n arg?: JsonRpcErrorsArg,\n ) => {\n return getEthProviderError(errorCodes.provider.unauthorized, arg);\n },\n\n /**\n * Get an Ethereum Provider Unsupported Method (4200) error.\n *\n * @param arg - The error message or options bag.\n * @returns An instance of the {@link EthereumProviderError} class.\n */\n unsupportedMethod: (\n arg?: JsonRpcErrorsArg,\n ) => {\n return getEthProviderError(errorCodes.provider.unsupportedMethod, arg);\n },\n\n /**\n * Get an Ethereum Provider Not Connected (4900) error.\n *\n * @param arg - The error message or options bag.\n * @returns An instance of the {@link EthereumProviderError} class.\n */\n disconnected: (\n arg?: JsonRpcErrorsArg,\n ) => {\n return getEthProviderError(errorCodes.provider.disconnected, arg);\n },\n\n /**\n * Get an Ethereum Provider Chain Not Connected (4901) error.\n *\n * @param arg - The error message or options bag.\n * @returns An instance of the {@link EthereumProviderError} class.\n */\n chainDisconnected: (\n arg?: JsonRpcErrorsArg,\n ) => {\n return getEthProviderError(errorCodes.provider.chainDisconnected, arg);\n },\n\n /**\n * Get a custom Ethereum Provider error.\n *\n * @param opts - The error options bag.\n * @returns An instance of the {@link EthereumProviderError} class.\n */\n custom: (opts: CustomErrorArg) => {\n if (!opts || typeof opts !== 'object' || Array.isArray(opts)) {\n throw new Error(\n 'Ethereum Provider custom errors must provide single object argument.',\n );\n }\n\n const { code, message, data } = opts;\n\n if (!message || typeof message !== 'string') {\n throw new Error('\"message\" must be a nonempty string');\n }\n return new EthereumProviderError(code, message, data);\n },\n};\n\n/**\n * Get a generic JSON-RPC error class instance.\n *\n * @param code - The error code.\n * @param arg - The error message or options bag.\n * @returns An instance of the {@link JsonRpcError} class.\n */\nfunction getJsonRpcError(\n code: number,\n arg?: JsonRpcErrorsArg,\n): JsonRpcError {\n const [message, data] = parseOpts(arg);\n return new JsonRpcError(code, message ?? getMessageFromCode(code), data);\n}\n\n/**\n * Get an Ethereum Provider error class instance.\n *\n * @param code - The error code.\n * @param arg - The error message or options bag.\n * @returns An instance of the {@link EthereumProviderError} class.\n */\nfunction getEthProviderError(\n code: number,\n arg?: JsonRpcErrorsArg,\n): EthereumProviderError {\n const [message, data] = parseOpts(arg);\n return new EthereumProviderError(\n code,\n message ?? getMessageFromCode(code),\n data,\n );\n}\n\n/**\n * Get an error message and optional data from an options bag.\n *\n * @param arg - The error message or options bag.\n * @returns A tuple containing the error message and optional data.\n */\nfunction parseOpts(\n arg?: JsonRpcErrorsArg,\n): [message?: string | undefined, data?: T | undefined] {\n if (arg) {\n if (typeof arg === 'string') {\n return [arg];\n } else if (typeof arg === 'object' && !Array.isArray(arg)) {\n const { message, data } = arg;\n\n if (message && typeof message !== 'string') {\n throw new Error('Must specify string message.');\n }\n return [message ?? undefined, data];\n }\n }\n\n return [];\n}\n"]} \ No newline at end of file -diff --git a/dist/index.d.ts.map b/dist/index.d.ts.map -new file mode 100644 -index 0000000000000000000000000000000000000000..de9a76f95d32507790e23214b6aac52a0ba8c36d ---- /dev/null -+++ b/dist/index.d.ts.map -@@ -0,0 +1 @@ -+{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAC7E,YAAY,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC"} ++{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AAAA,uCAAgE;AAChE,uDAA+C;AAC/C,mCAA4E;AAkB/D,QAAA,SAAS,GAAG;IACvB;;;;;OAKG;IACH,KAAK,EAAE,CAA0C,GAAyB,EAAE,EAAE,CAC5E,eAAe,CAAC,4BAAU,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC;IAE5C;;;;;OAKG;IACH,cAAc,EAAE,CACd,GAAyB,EACzB,EAAE,CAAC,eAAe,CAAC,4BAAU,CAAC,GAAG,CAAC,cAAc,EAAE,GAAG,CAAC;IAExD;;;;;OAKG;IACH,aAAa,EAAE,CACb,GAAyB,EACzB,EAAE,CAAC,eAAe,CAAC,4BAAU,CAAC,GAAG,CAAC,aAAa,EAAE,GAAG,CAAC;IAEvD;;;;;OAKG;IACH,cAAc,EAAE,CACd,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QAAQ,EAAE;gBAC1C,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;aACjD;YACD,OAAO,CAAC,OAAO,IAAI,SAAS,EAAE,IAAI,CAAC,CAAC;SACrC;KACF;IAED,OAAO,EAAE,CAAC;AACZ,CAAC","sourcesContent":["import { JsonRpcError, EthereumProviderError } from './classes';\nimport { errorCodes } from './error-constants';\nimport { OptionalDataWithOptionalCause, getMessageFromCode } from './utils';\n\ntype EthereumErrorOptions = {\n message?: string;\n data?: T;\n};\n\ntype ServerErrorOptions = {\n code: number;\n} & EthereumErrorOptions;\n\ntype CustomErrorArg =\n ServerErrorOptions;\n\ntype JsonRpcErrorsArg =\n | EthereumErrorOptions\n | string;\n\nexport const rpcErrors = {\n /**\n * Get a JSON RPC 2.0 Parse (-32700) error.\n *\n * @param arg - The error message or options bag.\n * @returns An instance of the {@link JsonRpcError} class.\n */\n parse: (arg?: JsonRpcErrorsArg) =>\n getJsonRpcError(errorCodes.rpc.parse, arg),\n\n /**\n * Get a JSON RPC 2.0 Invalid Request (-32600) error.\n *\n * @param arg - The error message or options bag.\n * @returns An instance of the {@link JsonRpcError} class.\n */\n invalidRequest: (\n arg?: JsonRpcErrorsArg,\n ) => getJsonRpcError(errorCodes.rpc.invalidRequest, arg),\n\n /**\n * Get a JSON RPC 2.0 Invalid Params (-32602) error.\n *\n * @param arg - The error message or options bag.\n * @returns An instance of the {@link JsonRpcError} class.\n */\n invalidParams: (\n arg?: JsonRpcErrorsArg,\n ) => getJsonRpcError(errorCodes.rpc.invalidParams, arg),\n\n /**\n * Get a JSON RPC 2.0 Method Not Found (-32601) error.\n *\n * @param arg - The error message or options bag.\n * @returns An instance of the {@link JsonRpcError} class.\n */\n methodNotFound: (\n arg?: JsonRpcErrorsArg,\n ) => getJsonRpcError(errorCodes.rpc.methodNotFound, arg),\n\n /**\n * Get a JSON RPC 2.0 Internal (-32603) error.\n *\n * @param arg - The error message or options bag.\n * @returns An instance of the {@link JsonRpcError} class.\n */\n internal: (\n arg?: JsonRpcErrorsArg,\n ) => getJsonRpcError(errorCodes.rpc.internal, arg),\n\n /**\n * Get a JSON RPC 2.0 Server error.\n * Permits integer error codes in the [ -32099 <= -32005 ] range.\n * Codes -32000 through -32004 are reserved by EIP-1474.\n *\n * @param opts - The error options bag.\n * @returns An instance of the {@link JsonRpcError} class.\n */\n server: (\n opts: ServerErrorOptions,\n ) => {\n if (!opts || typeof opts !== 'object' || Array.isArray(opts)) {\n throw new Error(\n 'Ethereum RPC Server errors must provide single object argument.',\n );\n }\n const { code } = opts;\n if (!Number.isInteger(code) || code > -32005 || code < -32099) {\n throw new Error(\n '\"code\" must be an integer such that: -32099 <= code <= -32005',\n );\n }\n return getJsonRpcError(code, opts);\n },\n\n /**\n * Get an Ethereum JSON RPC Invalid Input (-32000) error.\n *\n * @param arg - The error message or options bag.\n * @returns An instance of the {@link JsonRpcError} class.\n */\n invalidInput: (\n arg?: JsonRpcErrorsArg,\n ) => getJsonRpcError(errorCodes.rpc.invalidInput, arg),\n\n /**\n * Get an Ethereum JSON RPC Resource Not Found (-32001) error.\n *\n * @param arg - The error message or options bag.\n * @returns An instance of the {@link JsonRpcError} class.\n */\n resourceNotFound: (\n arg?: JsonRpcErrorsArg,\n ) => getJsonRpcError(errorCodes.rpc.resourceNotFound, arg),\n\n /**\n * Get an Ethereum JSON RPC Resource Unavailable (-32002) error.\n *\n * @param arg - The error message or options bag.\n * @returns An instance of the {@link JsonRpcError} class.\n */\n resourceUnavailable: (\n arg?: JsonRpcErrorsArg,\n ) => getJsonRpcError(errorCodes.rpc.resourceUnavailable, arg),\n\n /**\n * Get an Ethereum JSON RPC Transaction Rejected (-32003) error.\n *\n * @param arg - The error message or options bag.\n * @returns An instance of the {@link JsonRpcError} class.\n */\n transactionRejected: (\n arg?: JsonRpcErrorsArg,\n ) => getJsonRpcError(errorCodes.rpc.transactionRejected, arg),\n\n /**\n * Get an Ethereum JSON RPC Method Not Supported (-32004) error.\n *\n * @param arg - The error message or options bag.\n * @returns An instance of the {@link JsonRpcError} class.\n */\n methodNotSupported: (\n arg?: JsonRpcErrorsArg,\n ) => getJsonRpcError(errorCodes.rpc.methodNotSupported, arg),\n\n /**\n * Get an Ethereum JSON RPC Limit Exceeded (-32005) error.\n *\n * @param arg - The error message or options bag.\n * @returns An instance of the {@link JsonRpcError} class.\n */\n limitExceeded: (\n arg?: JsonRpcErrorsArg,\n ) => getJsonRpcError(errorCodes.rpc.limitExceeded, arg),\n};\n\nexport const providerErrors = {\n /**\n * Get an Ethereum Provider User Rejected Request (4001) error.\n *\n * @param arg - The error message or options bag.\n * @returns An instance of the {@link EthereumProviderError} class.\n */\n userRejectedRequest: (\n arg?: JsonRpcErrorsArg,\n ) => {\n return getEthProviderError(errorCodes.provider.userRejectedRequest, arg);\n },\n\n /**\n * Get an Ethereum Provider Unauthorized (4100) error.\n *\n * @param arg - The error message or options bag.\n * @returns An instance of the {@link EthereumProviderError} class.\n */\n unauthorized: (\n arg?: JsonRpcErrorsArg,\n ) => {\n return getEthProviderError(errorCodes.provider.unauthorized, arg);\n },\n\n /**\n * Get an Ethereum Provider Unsupported Method (4200) error.\n *\n * @param arg - The error message or options bag.\n * @returns An instance of the {@link EthereumProviderError} class.\n */\n unsupportedMethod: (\n arg?: JsonRpcErrorsArg,\n ) => {\n return getEthProviderError(errorCodes.provider.unsupportedMethod, arg);\n },\n\n /**\n * Get an Ethereum Provider Not Connected (4900) error.\n *\n * @param arg - The error message or options bag.\n * @returns An instance of the {@link EthereumProviderError} class.\n */\n disconnected: (\n arg?: JsonRpcErrorsArg,\n ) => {\n return getEthProviderError(errorCodes.provider.disconnected, arg);\n },\n\n /**\n * Get an Ethereum Provider Chain Not Connected (4901) error.\n *\n * @param arg - The error message or options bag.\n * @returns An instance of the {@link EthereumProviderError} class.\n */\n chainDisconnected: (\n arg?: JsonRpcErrorsArg,\n ) => {\n return getEthProviderError(errorCodes.provider.chainDisconnected, arg);\n },\n\n /**\n * Get a custom Ethereum Provider error.\n *\n * @param opts - The error options bag.\n * @returns An instance of the {@link EthereumProviderError} class.\n */\n custom: (\n opts: CustomErrorArg,\n ) => {\n if (!opts || typeof opts !== 'object' || Array.isArray(opts)) {\n throw new Error(\n 'Ethereum Provider custom errors must provide single object argument.',\n );\n }\n\n const { code, message, data } = opts;\n\n if (!message || typeof message !== 'string') {\n throw new Error('\"message\" must be a nonempty string');\n }\n return new EthereumProviderError(code, message, data);\n },\n};\n\n/**\n * Get a generic JSON-RPC error class instance.\n *\n * @param code - The error code.\n * @param arg - The error message or options bag.\n * @returns An instance of the {@link JsonRpcError} class.\n */\nfunction getJsonRpcError(\n code: number,\n arg?: JsonRpcErrorsArg,\n): JsonRpcError {\n const [message, data] = parseOpts(arg);\n return new JsonRpcError(code, message ?? getMessageFromCode(code), data);\n}\n\n/**\n * Get an Ethereum Provider error class instance.\n *\n * @param code - The error code.\n * @param arg - The error message or options bag.\n * @returns An instance of the {@link EthereumProviderError} class.\n */\nfunction getEthProviderError(\n code: number,\n arg?: JsonRpcErrorsArg,\n): EthereumProviderError {\n const [message, data] = parseOpts(arg);\n return new EthereumProviderError(\n code,\n message ?? getMessageFromCode(code),\n data,\n );\n}\n\n/**\n * Get an error message and optional data from an options bag.\n *\n * @param arg - The error message or options bag.\n * @returns A tuple containing the error message and optional data.\n */\nfunction parseOpts(\n arg?: JsonRpcErrorsArg,\n): [message?: string | undefined, data?: T | undefined] {\n if (arg) {\n if (typeof arg === 'string') {\n return [arg];\n } else if (typeof arg === 'object' && !Array.isArray(arg)) {\n const { message, data } = arg;\n\n if (message && typeof message !== 'string') {\n throw new Error('Must specify string message.');\n }\n return [message ?? undefined, data];\n }\n }\n\n return [];\n}\n"]} \ No newline at end of file diff --git a/dist/utils.d.ts b/dist/utils.d.ts -index f2b6a97b759c7b451c7310813efe92c75a9a9552..708c96206646881a6a4e2ab8e4afec18af592135 100644 +index f2b6a97b759c7b451c7310813efe92c75a9a9552..89a147be8a0048b3ce109fb4e01382cb28416ab6 100644 --- a/dist/utils.d.ts +++ b/dist/utils.d.ts -@@ -1,4 +1,4 @@ --import { Json, JsonRpcError as SerializedJsonRpcError } from '@metamask/utils'; -+import type { Json, JsonRpcError as SerializedJsonRpcError } from '@metamask/utils'; - /** - * A data object, that must be either: - * @@ -10,6 +10,13 @@ export type DataWithOptionalCause = Json | { [key: string]: Json | unknown; cause: unknown; @@ -292,17 +233,12 @@ index f2b6a97b759c7b451c7310813efe92c75a9a9552..708c96206646881a6a4e2ab8e4afec18 export declare const JSON_RPC_SERVER_ERROR_MESSAGE = "Unspecified server error."; /** * Gets the message for a given code, or a fallback message if the code has -@@ -54,3 +61,4 @@ export declare function serializeError(error: unknown, { fallbackError, shouldIn - * @returns A JSON-serializable object containing as much information about the original error as possible. - */ - export declare function serializeCause(error: unknown): Json; -+//# sourceMappingURL=utils.d.ts.map +diff --git a/dist/utils.js.map b/dist/utils.js.map +index 88bf91546901530c281d73174775fdefb2068031..8c1dc24076ca458dc65e932dae4a697a2038ce5e 100644 +--- a/dist/utils.js.map ++++ b/dist/utils.js.map +@@ -1 +1 @@ +-{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA,2CAQyB;AAEzB,uDAA4D;AAmB5D,MAAM,mBAAmB,GAAG,4BAAU,CAAC,GAAG,CAAC,QAAQ,CAAC;AACpD,MAAM,gBAAgB,GACpB,6DAA6D,CAAC;AAChE,MAAM,cAAc,GAA2B;IAC7C,IAAI,EAAE,mBAAmB;IACzB,OAAO,EAAE,kBAAkB,CAAC,mBAAmB,CAAC;CACjD,CAAC;AAEW,QAAA,6BAA6B,GAAG,2BAA2B,CAAC;AAIzE;;;;;;;;;GASG;AACH,SAAgB,kBAAkB,CAChC,IAAa,EACb,kBAA0B,gBAAgB;IAE1C,IAAI,WAAW,CAAC,IAAI,CAAC,EAAE;QACrB,MAAM,UAAU,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;QAEnC,IAAI,IAAA,mBAAW,EAAC,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,\n isObject,\n isJsonRpcError,\n Json,\n JsonRpcError as SerializedJsonRpcError,\n RuntimeObject,\n} from '@metamask/utils';\n\nimport { errorCodes, errorValues } from './error-constants';\n\n/**\n * A data object, that must be either:\n *\n * - A JSON-serializable object.\n * - An object with a `cause` property that is an error-like value, and any\n * other properties that are JSON-serializable.\n */\nexport type DataWithOptionalCause =\n | Json\n | {\n // Unfortunately we can't use just `Json` here, because all properties of\n // an object with an index signature must be assignable to the index\n // signature's type. So we have to use `Json | unknown` instead.\n [key: string]: Json | unknown;\n cause: unknown;\n };\n\nconst FALLBACK_ERROR_CODE = errorCodes.rpc.internal;\nconst FALLBACK_MESSAGE =\n 'Unspecified error message. This is a bug, please report it.';\nconst FALLBACK_ERROR: SerializedJsonRpcError = {\n code: FALLBACK_ERROR_CODE,\n message: getMessageFromCode(FALLBACK_ERROR_CODE),\n};\n\nexport const JSON_RPC_SERVER_ERROR_MESSAGE = 'Unspecified server error.';\n\ntype ErrorValueKey = keyof typeof errorValues;\n\n/**\n * Gets the message for a given code, or a fallback message if the code has\n * no corresponding message.\n *\n * @param code - The error code.\n * @param fallbackMessage - The fallback message to use if the code has no\n * corresponding message.\n * @returns The message for the given code, or the fallback message if the code\n * has no corresponding message.\n */\nexport function getMessageFromCode(\n code: unknown,\n fallbackMessage: string = FALLBACK_MESSAGE,\n): string {\n if (isValidCode(code)) {\n const codeString = code.toString();\n\n if (hasProperty(errorValues, codeString)) {\n return errorValues[codeString as ErrorValueKey].message;\n }\n\n if (isJsonRpcServerError(code)) {\n return JSON_RPC_SERVER_ERROR_MESSAGE;\n }\n }\n return fallbackMessage;\n}\n\n/**\n * Returns whether the given code is valid.\n * A code is valid if it is an integer.\n *\n * @param code - The error code.\n * @returns Whether the given code is valid.\n */\nexport function isValidCode(code: unknown): code is number {\n return Number.isInteger(code);\n}\n\n/**\n * Serializes the given error to an Ethereum JSON RPC-compatible error object.\n * If the given error is not fully compatible, it will be preserved on the\n * returned object's data.cause property.\n *\n * @param error - The error to serialize.\n * @param options - Options bag.\n * @param options.fallbackError - The error to return if the given error is\n * not compatible. Should be a JSON serializable value.\n * @param options.shouldIncludeStack - Whether to include the error's stack\n * on the returned object.\n * @returns The serialized error.\n */\nexport function serializeError(\n error: unknown,\n { fallbackError = FALLBACK_ERROR, shouldIncludeStack = true } = {},\n): SerializedJsonRpcError {\n if (!isJsonRpcError(fallbackError)) {\n throw new Error(\n 'Must provide fallback error with integer number code and string message.',\n );\n }\n\n const serialized = buildError(error, fallbackError);\n\n if (!shouldIncludeStack) {\n delete serialized.stack;\n }\n\n return serialized;\n}\n\n/**\n * Construct a JSON-serializable object given an error and a JSON serializable `fallbackError`\n *\n * @param error - The error in question.\n * @param fallbackError - A JSON serializable fallback error.\n * @returns A JSON serializable error object.\n */\nfunction buildError(\n error: unknown,\n fallbackError: SerializedJsonRpcError,\n): SerializedJsonRpcError {\n // If an error specifies a `serialize` function, we call it and return the result.\n if (\n error &&\n typeof error === 'object' &&\n 'serialize' in error &&\n typeof error.serialize === 'function'\n ) {\n return error.serialize();\n }\n\n if (isJsonRpcError(error)) {\n return error;\n }\n\n // If the error does not match the JsonRpcError type, use the fallback error, but try to include the original error as `cause`.\n const cause = serializeCause(error);\n const fallbackWithCause = {\n ...fallbackError,\n data: { cause },\n };\n\n return fallbackWithCause;\n}\n\n/**\n * Check if the given code is a valid JSON-RPC server error code.\n *\n * @param code - The error code.\n * @returns Whether the given code is a valid JSON-RPC server error code.\n */\nfunction isJsonRpcServerError(code: number): boolean {\n return code >= -32099 && code <= -32000;\n}\n\n/**\n * Serializes an unknown error to be used as the `cause` in a fallback error.\n *\n * @param error - The unknown error.\n * @returns A JSON-serializable object containing as much information about the original error as possible.\n */\nexport function serializeCause(error: unknown): Json {\n if (Array.isArray(error)) {\n return error.map((entry) => {\n if (isValidJson(entry)) {\n return entry;\n } else if (isObject(entry)) {\n return serializeObject(entry);\n }\n return null;\n });\n } else if (isObject(error)) {\n return serializeObject(error);\n }\n\n if (isValidJson(error)) {\n return error;\n }\n\n return null;\n}\n\n/**\n * Extracts all JSON-serializable properties from an object.\n *\n * @param object - The object in question.\n * @returns An object containing all the JSON-serializable properties.\n */\nfunction serializeObject(object: RuntimeObject): Json {\n return Object.getOwnPropertyNames(object).reduce>(\n (acc, key) => {\n const value = object[key];\n if (isValidJson(value)) {\n acc[key] = value;\n }\n\n return acc;\n },\n {},\n );\n}\n"]} \ No newline at end of file -diff --git a/dist/utils.d.ts.map b/dist/utils.d.ts.map -new file mode 100644 -index 0000000000000000000000000000000000000000..f22be5f27454e41a590ef1b462e131020ab45384 ---- /dev/null -+++ b/dist/utils.d.ts.map -@@ -0,0 +1 @@ -+{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,IAAI,EACJ,YAAY,IAAI,sBAAsB,EAEvC,MAAM,iBAAiB,CAAC;AAUzB;;;;;;GAMG;AACH,MAAM,MAAM,qBAAqB,GAC7B,IAAI,GACJ;IAIE,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC;IAC9B,KAAK,EAAE,OAAO,CAAC;CAChB,CAAC;AAEN;;;;;GAKG;AACH,MAAM,MAAM,6BAA6B,GAAG,SAAS,GAAG,qBAAqB,CAAC;AAU9E,eAAO,MAAM,6BAA6B,8BAA8B,CAAC;AAIzE;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,OAAO,EACb,eAAe,GAAE,MAAyB,GACzC,MAAM,CAaR;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,MAAM,CAEzD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,OAAO,EACd,EAAE,aAA8B,EAAE,kBAAyB,EAAE;;;CAAK,GACjE,sBAAsB,CAcxB;AA+CD;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EA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C,EAAE;QAC1B,OAAO,eAAe,CAAC,KAAK,CAAC,CAAC;KAC/B;IAED,IAAI,IAAA,mBAAW,EAAC,KAAK,CAAC,EAAE;QACtB,OAAO,KAAK,CAAC;KACd;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAnBD,wCAmBC;AAED;;;;;GAKG;AACH,SAAS,eAAe,CAAC,MAAqB;IAC5C,OAAO,MAAM,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC,MAAM,CAC9C,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;QACX,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;QAC1B,IAAI,IAAA,mBAAW,EAAC,KAAK,CAAC,EAAE;YACtB,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;SAClB;QAED,OAAO,GAAG,CAAC;IACb,CAAC,EACD,EAAE,CACH,CAAC;AACJ,CAAC","sourcesContent":["import {\n hasProperty,\n isValidJson,\n isObject,\n isJsonRpcError,\n Json,\n JsonRpcError as SerializedJsonRpcError,\n RuntimeObject,\n} from '@metamask/utils';\n\nimport { errorCodes, errorValues } from './error-constants';\n\n/**\n * A data object, that must be either:\n *\n * - A JSON-serializable object.\n * - An object with a `cause` property that is an error-like value, and any\n * other properties that are JSON-serializable.\n */\nexport type DataWithOptionalCause =\n | Json\n | {\n // Unfortunately we can't use just `Json` here, because all properties of\n // an object with an index signature must be assignable to the index\n // signature's type. So we have to use `Json | unknown` instead.\n [key: string]: Json | unknown;\n cause: unknown;\n };\n\n/**\n * A data object, that must be either:\n *\n * - A valid DataWithOptionalCause value.\n * - undefined.\n */\nexport type OptionalDataWithOptionalCause = undefined | DataWithOptionalCause;\n\nconst FALLBACK_ERROR_CODE = errorCodes.rpc.internal;\nconst FALLBACK_MESSAGE =\n 'Unspecified error message. This is a bug, please report it.';\nconst FALLBACK_ERROR: SerializedJsonRpcError = {\n code: FALLBACK_ERROR_CODE,\n message: getMessageFromCode(FALLBACK_ERROR_CODE),\n};\n\nexport const JSON_RPC_SERVER_ERROR_MESSAGE = 'Unspecified server error.';\n\ntype ErrorValueKey = keyof typeof errorValues;\n\n/**\n * Gets the message for a given code, or a fallback message if the code has\n * no corresponding message.\n *\n * @param code - The error code.\n * @param fallbackMessage - The fallback message to use if the code has no\n * corresponding message.\n * @returns The message for the given code, or the fallback message if the code\n * has no corresponding message.\n */\nexport function getMessageFromCode(\n code: unknown,\n fallbackMessage: string = FALLBACK_MESSAGE,\n): string {\n if (isValidCode(code)) {\n const codeString = code.toString();\n\n if (hasProperty(errorValues, codeString)) {\n return errorValues[codeString as ErrorValueKey].message;\n }\n\n if (isJsonRpcServerError(code)) {\n return JSON_RPC_SERVER_ERROR_MESSAGE;\n }\n }\n return fallbackMessage;\n}\n\n/**\n * Returns whether the given code is valid.\n * A code is valid if it is an integer.\n *\n * @param code - The error code.\n * @returns Whether the given code is valid.\n */\nexport function isValidCode(code: unknown): code is number {\n return Number.isInteger(code);\n}\n\n/**\n * Serializes the given error to an Ethereum JSON RPC-compatible error object.\n * If the given error is not fully compatible, it will be preserved on the\n * returned object's data.cause property.\n *\n * @param error - The error to serialize.\n * @param options - Options bag.\n * @param options.fallbackError - The error to return if the given error is\n * not compatible. Should be a JSON serializable value.\n * @param options.shouldIncludeStack - Whether to include the error's stack\n * on the returned object.\n * @returns The serialized error.\n */\nexport function serializeError(\n error: unknown,\n { fallbackError = FALLBACK_ERROR, shouldIncludeStack = true } = {},\n): SerializedJsonRpcError {\n if (!isJsonRpcError(fallbackError)) {\n throw new Error(\n 'Must provide fallback error with integer number code and string message.',\n );\n }\n\n const serialized = buildError(error, fallbackError);\n\n if (!shouldIncludeStack) {\n delete serialized.stack;\n }\n\n return serialized;\n}\n\n/**\n * Construct a JSON-serializable object given an error and a JSON serializable `fallbackError`\n *\n * @param error - The error in question.\n * @param fallbackError - A JSON serializable fallback error.\n * @returns A JSON serializable error object.\n */\nfunction buildError(\n error: unknown,\n fallbackError: SerializedJsonRpcError,\n): SerializedJsonRpcError {\n // If an error specifies a `serialize` function, we call it and return the result.\n if (\n error &&\n typeof error === 'object' &&\n 'serialize' in error &&\n typeof error.serialize === 'function'\n ) {\n return error.serialize();\n }\n\n if (isJsonRpcError(error)) {\n return error;\n }\n\n // If the error does not match the JsonRpcError type, use the fallback error, but try to include the original error as `cause`.\n const cause = serializeCause(error);\n const fallbackWithCause = {\n ...fallbackError,\n data: { cause },\n };\n\n return fallbackWithCause;\n}\n\n/**\n * Check if the given code is a valid JSON-RPC server error code.\n *\n * @param code - The error code.\n * @returns Whether the given code is a valid JSON-RPC server error code.\n */\nfunction isJsonRpcServerError(code: number): boolean {\n return code >= -32099 && code <= -32000;\n}\n\n/**\n * Serializes an unknown error to be used as the `cause` in a fallback error.\n *\n * @param error - The unknown error.\n * @returns A JSON-serializable object containing as much information about the original error as possible.\n */\nexport function serializeCause(error: unknown): Json {\n if (Array.isArray(error)) {\n return error.map((entry) => {\n if (isValidJson(entry)) {\n return entry;\n } else if (isObject(entry)) {\n return serializeObject(entry);\n }\n return null;\n });\n } else if (isObject(error)) {\n return serializeObject(error);\n }\n\n if (isValidJson(error)) {\n return error;\n }\n\n return null;\n}\n\n/**\n * Extracts all JSON-serializable properties from an object.\n *\n * @param object - The object in question.\n * @returns An object containing all the JSON-serializable properties.\n */\nfunction serializeObject(object: RuntimeObject): Json {\n return Object.getOwnPropertyNames(object).reduce>(\n (acc, key) => {\n const value = object[key];\n if (isValidJson(value)) {\n acc[key] = value;\n }\n\n return acc;\n },\n {},\n );\n}\n"]} \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 6c4c01a..5d3161f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1066,11 +1066,11 @@ __metadata: "@metamask/rpc-errors@patch:@metamask/rpc-errors@npm%3A5.1.1#./.yarn/patches/@metamask-rpc-errors-npm-5.1.1-dc76c26803.patch::locator=%40metamask%2Fjson-rpc-engine%40workspace%3A.": version: 5.1.1 - resolution: "@metamask/rpc-errors@patch:@metamask/rpc-errors@npm%3A5.1.1#./.yarn/patches/@metamask-rpc-errors-npm-5.1.1-dc76c26803.patch::version=5.1.1&hash=b699ed&locator=%40metamask%2Fjson-rpc-engine%40workspace%3A." + resolution: "@metamask/rpc-errors@patch:@metamask/rpc-errors@npm%3A5.1.1#./.yarn/patches/@metamask-rpc-errors-npm-5.1.1-dc76c26803.patch::version=5.1.1&hash=83170c&locator=%40metamask%2Fjson-rpc-engine%40workspace%3A." dependencies: "@metamask/utils": ^5.0.0 fast-safe-stringify: ^2.0.6 - checksum: 76d0e5c0e9c49c69881b56db3a5ab8d3240db1294089cd9daff14a145ae1dd014653ff48aa6976f6d4a79e2b9603726c221f07be6a36fae1165a11545eb82455 + checksum: 48f72d7c9f2a977bdf37a5e48c5cbbe42884b79892d9c0286a28eb2f4975602c70b10e6fe8111208eaf59a7523947b977794e85462a833c0524bebafaf7de85d languageName: node linkType: hard From ccd5d5e57cebfcb5ea1e91436aacc63acb48c4b5 Mon Sep 17 00:00:00 2001 From: legobt <6wbvkn0j@anonaddy.me> Date: Mon, 28 Aug 2023 23:02:03 +0000 Subject: [PATCH 4/6] yarn dedupe --- yarn.lock | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/yarn.lock b/yarn.lock index 5d3161f..c6cc7a9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1117,14 +1117,14 @@ __metadata: languageName: node linkType: hard -"@noble/hashes@npm:1.3.0, @noble/hashes@npm:^1.3.0, @noble/hashes@npm:~1.3.0": +"@noble/hashes@npm:1.3.0": version: 1.3.0 resolution: "@noble/hashes@npm:1.3.0" checksum: d7ddb6d7c60f1ce1f87facbbef5b724cdea536fc9e7f59ae96e0fc9de96c8f1a2ae2bdedbce10f7dcc621338dfef8533daa73c873f2b5c87fa1a4e05a95c2e2e languageName: node linkType: hard -"@noble/hashes@npm:^1.3.1": +"@noble/hashes@npm:^1.3.0, @noble/hashes@npm:^1.3.1, @noble/hashes@npm:~1.3.0": version: 1.3.1 resolution: "@noble/hashes@npm:1.3.1" checksum: 7fdefc0f7a0c1ec27acc6ff88841793e3f93ec4ce6b8a6a12bfc0dd70ae6b7c4c82fe305fdfeda1735d5ad4a9eebe761e6693b3d355689c559e91242f4bc95b1 @@ -5673,14 +5673,14 @@ __metadata: languageName: node linkType: hard -"semver@npm:7.x, semver@npm:^7.3.2, semver@npm:^7.3.5, semver@npm:^7.3.7, semver@npm:^7.3.8": - version: 7.4.0 - resolution: "semver@npm:7.4.0" +"semver@npm:7.x, semver@npm:^7.3.2, semver@npm:^7.3.5, semver@npm:^7.3.7, semver@npm:^7.3.8, semver@npm:^7.5.4": + version: 7.5.4 + resolution: "semver@npm:7.5.4" dependencies: lru-cache: ^6.0.0 bin: semver: bin/semver.js - checksum: debf7f4d6fa36fdc5ef82bd7fc3603b6412165c8a3963a30be0c45a587be1a49e7681e80aa109da1875765741af24edc6e021cee1ba16ae96f649d06c5df296d + checksum: 12d8ad952fa353b0995bf180cdac205a4068b759a140e5d3c608317098b3575ac2f1e09182206bf2eb26120e1c0ed8fb92c48c592f6099680de56bb071423ca3 languageName: node linkType: hard @@ -5693,17 +5693,6 @@ __metadata: languageName: node linkType: hard -"semver@npm:^7.5.4": - version: 7.5.4 - resolution: "semver@npm:7.5.4" - dependencies: - lru-cache: ^6.0.0 - bin: - semver: bin/semver.js - checksum: 12d8ad952fa353b0995bf180cdac205a4068b759a140e5d3c608317098b3575ac2f1e09182206bf2eb26120e1c0ed8fb92c48c592f6099680de56bb071423ca3 - languageName: node - linkType: hard - "set-blocking@npm:^2.0.0": version: 2.0.0 resolution: "set-blocking@npm:2.0.0" From 8a2644dcd673b7de3c2cec0279080546d1e98dd3 Mon Sep 17 00:00:00 2001 From: legobt <6wbvkn0j@anonaddy.me> Date: Mon, 28 Aug 2023 22:37:34 +0000 Subject: [PATCH 5/6] deps: @metamask/utils@^7.0.0->^8.0.0 --- package.json | 2 +- yarn.lock | 80 +++++++++++++++------------------------------------- 2 files changed, 24 insertions(+), 58 deletions(-) diff --git a/package.json b/package.json index e4fac79..94ae9bf 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "dependencies": { "@metamask/rpc-errors": "^5.1.1", "@metamask/safe-event-emitter": "^3.0.0", - "@metamask/utils": "^7.0.0" + "@metamask/utils": "^8.0.0" }, "devDependencies": { "@lavamoat/allow-scripts": "^2.3.1", diff --git a/yarn.lock b/yarn.lock index c6cc7a9..e85e6cc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -419,33 +419,6 @@ __metadata: languageName: node linkType: hard -"@chainsafe/as-sha256@npm:^0.4.1": - version: 0.4.1 - resolution: "@chainsafe/as-sha256@npm:0.4.1" - checksum: 6d86975e648ecdafd366802278ac15b392b252e967f3681412ec48b5a3518b936cc5e977517499882b084991446d25787d98f8f585891943688cc81549a44e9a - languageName: node - linkType: hard - -"@chainsafe/persistent-merkle-tree@npm:^0.6.1": - version: 0.6.1 - resolution: "@chainsafe/persistent-merkle-tree@npm:0.6.1" - dependencies: - "@chainsafe/as-sha256": ^0.4.1 - "@noble/hashes": ^1.3.0 - checksum: 74614b8d40970dc930d5bf741619498b0bbbde5ff24ce45fce6ad122143aa77bf57249a28175b1b972cf56bff57d529a4258b7222ab4e60c1261119b5986c51b - languageName: node - linkType: hard - -"@chainsafe/ssz@npm:^0.11.1": - version: 0.11.1 - resolution: "@chainsafe/ssz@npm:0.11.1" - dependencies: - "@chainsafe/as-sha256": ^0.4.1 - "@chainsafe/persistent-merkle-tree": ^0.6.1 - checksum: e3c2928f9ab4a0544e645f0302b9535046d1e6e1d4b3bd1c3dd6bc8e6302fddad6036d65e7900d1446f285f496051da05fa14c1bde590b511d03033907175c8f - languageName: node - linkType: hard - "@cspotcode/source-map-support@npm:^0.8.0": version: 0.8.1 resolution: "@cspotcode/source-map-support@npm:0.8.1" @@ -508,13 +481,13 @@ __metadata: languageName: node linkType: hard -"@ethereumjs/common@npm:^3.1.2": - version: 3.1.2 - resolution: "@ethereumjs/common@npm:3.1.2" +"@ethereumjs/common@npm:^3.2.0": + version: 3.2.0 + resolution: "@ethereumjs/common@npm:3.2.0" dependencies: - "@ethereumjs/util": ^8.0.6 + "@ethereumjs/util": ^8.1.0 crc-32: ^1.2.0 - checksum: e80a8bc86476f1ce878bacb1915d91681671bb5303291cdcece26e456ac13a6158f0f59625cb02a1cfbdd7c9a7dc8b175f8d8f0fee596b3eb9dfb965465ad43d + checksum: cb9cc11f5c868cb577ba611cebf55046e509218bbb89b47ccce010776dafe8256d70f8f43fab238aec74cf71f62601cd5842bc03a83261200802de365732a14b languageName: node linkType: hard @@ -528,32 +501,25 @@ __metadata: linkType: hard "@ethereumjs/tx@npm:^4.1.2": - version: 4.1.2 - resolution: "@ethereumjs/tx@npm:4.1.2" + version: 4.2.0 + resolution: "@ethereumjs/tx@npm:4.2.0" dependencies: - "@chainsafe/ssz": ^0.11.1 - "@ethereumjs/common": ^3.1.2 + "@ethereumjs/common": ^3.2.0 "@ethereumjs/rlp": ^4.0.1 - "@ethereumjs/util": ^8.0.6 + "@ethereumjs/util": ^8.1.0 ethereum-cryptography: ^2.0.0 - peerDependencies: - c-kzg: ^1.0.8 - peerDependenciesMeta: - c-kzg: - optional: true - checksum: ad2fb692c3746cd5935b01c98b6b54046ae2a1fccff57ad2209e10446f3b279a204d7477accf05b27078445b14379314077769662142ac07117c45a5a1ea427f + checksum: 87a3f5f2452cfbf6712f8847525a80c213210ed453c211c793c5df801fe35ecef28bae17fadd222fcbdd94277478a47e52d2b916a90a6b30cda21f1e0cdaee42 languageName: node linkType: hard -"@ethereumjs/util@npm:^8.0.6": - version: 8.0.6 - resolution: "@ethereumjs/util@npm:8.0.6" +"@ethereumjs/util@npm:^8.1.0": + version: 8.1.0 + resolution: "@ethereumjs/util@npm:8.1.0" dependencies: - "@chainsafe/ssz": ^0.11.1 "@ethereumjs/rlp": ^4.0.1 ethereum-cryptography: ^2.0.0 micro-ftch: ^0.3.1 - checksum: 034e06cddec27417318434a1a7cd7a9dc0f0b447c1f54423c515d8809c9697386eee6429d0a1c13517a85c696e6fdba570b243d882e65764c274859606027015 + checksum: 9ae5dee8f12b0faf81cd83f06a41560e79b0ba96a48262771d897a510ecae605eb6d84f687da001ab8ccffd50f612ae50f988ef76e6312c752897f462f3ac08d languageName: node linkType: hard @@ -1029,7 +995,7 @@ __metadata: "@metamask/eslint-config-typescript": ^11.0.0 "@metamask/rpc-errors": ^5.1.1 "@metamask/safe-event-emitter": ^3.0.0 - "@metamask/utils": ^7.0.0 + "@metamask/utils": ^8.0.0 "@types/jest": ^29.5.0 "@types/node": ^18.15.11 "@typescript-eslint/eslint-plugin": ^5.43.0 @@ -1094,9 +1060,9 @@ __metadata: languageName: node linkType: hard -"@metamask/utils@npm:^7.0.0": - version: 7.0.0 - resolution: "@metamask/utils@npm:7.0.0" +"@metamask/utils@npm:^8.0.0": + version: 8.0.0 + resolution: "@metamask/utils@npm:8.0.0" dependencies: "@ethereumjs/tx": ^4.1.2 "@noble/hashes": ^1.3.1 @@ -1104,7 +1070,7 @@ __metadata: debug: ^4.3.4 semver: ^7.5.4 superstruct: ^1.0.3 - checksum: cd9fd46a323f655741c654ab07a0e35c07ce2be5d13f2defdd938d7f29b6e8e382782d83dac67bad7cffa38b3aa4fa9b3fb7c8ccca4d16b4d1fd68a39cbba183 + checksum: 01c956b150b454f648868cb08e850822d526fcf7d33dd04e156ed06d9b2829d0bd42a766f7bcc98c7b21d4990b00c6adb0474b23515a927131a460d50237eb52 languageName: node linkType: hard @@ -1124,10 +1090,10 @@ __metadata: languageName: node linkType: hard -"@noble/hashes@npm:^1.3.0, @noble/hashes@npm:^1.3.1, @noble/hashes@npm:~1.3.0": - version: 1.3.1 - resolution: "@noble/hashes@npm:1.3.1" - checksum: 7fdefc0f7a0c1ec27acc6ff88841793e3f93ec4ce6b8a6a12bfc0dd70ae6b7c4c82fe305fdfeda1735d5ad4a9eebe761e6693b3d355689c559e91242f4bc95b1 +"@noble/hashes@npm:^1.3.1, @noble/hashes@npm:~1.3.0": + version: 1.3.2 + resolution: "@noble/hashes@npm:1.3.2" + checksum: fe23536b436539d13f90e4b9be843cc63b1b17666a07634a2b1259dded6f490be3d050249e6af98076ea8f2ea0d56f578773c2197f2aa0eeaa5fba5bc18ba474 languageName: node linkType: hard From f9086d07b3a9b78aeb49d1e01c17c881a495f79b Mon Sep 17 00:00:00 2001 From: legobt <6wbvkn0j@anonaddy.me> Date: Wed, 30 Aug 2023 08:29:13 +0000 Subject: [PATCH 6/6] patch @metamask/utils a00dfc9d9bfcc3215161124d9b1f4dd6009e831c --- ...@metamask-utils-npm-8.0.0-7a3c3a899a.patch | 143 ++++++++++++++++++ package.json | 4 +- yarn.lock | 17 ++- 3 files changed, 155 insertions(+), 9 deletions(-) create mode 100644 .yarn/patches/@metamask-utils-npm-8.0.0-7a3c3a899a.patch diff --git a/.yarn/patches/@metamask-utils-npm-8.0.0-7a3c3a899a.patch b/.yarn/patches/@metamask-utils-npm-8.0.0-7a3c3a899a.patch new file mode 100644 index 0000000..a7cf28c --- /dev/null +++ b/.yarn/patches/@metamask-utils-npm-8.0.0-7a3c3a899a.patch @@ -0,0 +1,143 @@ +diff --git a/dist/cjs/json.js b/dist/cjs/json.js +index 17e5663cd237a88fcdb3728a16b5b1219113babe..8514b32d323d34838f927dc007704c3c58fbc1f6 100644 +--- a/dist/cjs/json.js ++++ b/dist/cjs/json.js +@@ -159,19 +159,21 @@ const JsonRpcErrorStruct = (0, _superstruct.object)({ + data: (0, _superstruct.optional)(JsonStruct), + stack: (0, _superstruct.optional)((0, _superstruct.string)()) + }); +-const JsonRpcParamsStruct = (0, _superstruct.optional)((0, _superstruct.union)([ ++const JsonRpcParamsStruct = (0, _superstruct.union)([ + (0, _superstruct.record)((0, _superstruct.string)(), JsonStruct), + (0, _superstruct.array)(JsonStruct) +-])); ++]); + const JsonRpcRequestStruct = (0, _superstruct.object)({ + id: JsonRpcIdStruct, + jsonrpc: JsonRpcVersionStruct, + method: (0, _superstruct.string)(), +- params: JsonRpcParamsStruct ++ params: (0, _superstruct.optional)(JsonRpcParamsStruct) ++}); ++const JsonRpcNotificationStruct = (0, _superstruct.object)({ ++ jsonrpc: JsonRpcVersionStruct, ++ method: (0, _superstruct.string)(), ++ params: (0, _superstruct.optional)(JsonRpcParamsStruct) + }); +-const JsonRpcNotificationStruct = (0, _superstruct.omit)(JsonRpcRequestStruct, [ +- 'id' +-]); + function isJsonRpcNotification(value) { + return (0, _superstruct.is)(value, JsonRpcNotificationStruct); + } +diff --git a/dist/cjs/json.js.map b/dist/cjs/json.js.map +index 26bea6e257cc0f2d36ca93f5652254ed85d8720f..9288c04dfb997d16ceaa68151736b87d770e2abd 100644 +--- a/dist/cjs/json.js.map ++++ b/dist/cjs/json.js.map +@@ -1 +1 @@ +-{"version":3,"sources":["../../src/json.ts"],"sourcesContent":["import type { Infer, Struct } from 'superstruct';\nimport {\n any,\n array,\n boolean,\n coerce,\n create,\n define,\n integer,\n is,\n lazy,\n literal,\n nullable,\n number,\n object,\n omit,\n optional,\n record,\n string,\n union,\n unknown,\n} from 'superstruct';\n\nimport type { AssertionErrorConstructor } from './assert';\nimport { assertStruct } from './assert';\n\n/**\n * Any JSON-compatible value.\n */\nexport type Json =\n | null\n | boolean\n | number\n | string\n | Json[]\n | { [prop: string]: Json };\n\n/**\n * A struct to check if the given value is finite number. Superstruct's\n * `number()` struct does not check if the value is finite.\n *\n * @returns A struct to check if the given value is finite number.\n */\nconst finiteNumber = () =>\n define('finite number', (value) => {\n return is(value, number()) && Number.isFinite(value);\n });\n\n/**\n * A struct to check if the given value is a valid JSON-serializable value.\n *\n * Note that this struct is unsafe. For safe validation, use {@link JsonStruct}.\n */\n// We cannot infer the type of the struct, because it is recursive.\nexport const UnsafeJsonStruct: Struct = union([\n literal(null),\n boolean(),\n finiteNumber(),\n string(),\n array(lazy(() => UnsafeJsonStruct)),\n record(\n string(),\n lazy(() => UnsafeJsonStruct),\n ),\n]);\n\n/**\n * A struct to check if the given value is a valid JSON-serializable value.\n *\n * This struct sanitizes the value before validating it, so that it is safe to\n * use with untrusted input.\n */\nexport const JsonStruct = coerce(UnsafeJsonStruct, any(), (value) => {\n assertStruct(value, UnsafeJsonStruct);\n return JSON.parse(\n JSON.stringify(value, (propKey, propValue) => {\n // Strip __proto__ and constructor properties to prevent prototype pollution.\n if (propKey === '__proto__' || propKey === 'constructor') {\n return undefined;\n }\n return propValue;\n }),\n );\n});\n\n/**\n * Check if the given value is a valid {@link Json} value, i.e., a value that is\n * serializable to JSON.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid {@link Json} value.\n */\nexport function isValidJson(value: unknown): value is Json {\n try {\n getSafeJson(value);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Validate and return sanitized JSON.\n *\n * Note:\n * This function uses sanitized JsonStruct for validation\n * that applies stringify and then parse of a value provided\n * to ensure that there are no getters which can have side effects\n * that can cause security issues.\n *\n * @param value - JSON structure to be processed.\n * @returns Sanitized JSON structure.\n */\nexport function getSafeJson(value: unknown): Type {\n return create(value, JsonStruct) as Type;\n}\n\n/**\n * Get the size of a JSON value in bytes. This also validates the value.\n *\n * @param value - The JSON value to get the size of.\n * @returns The size of the JSON value in bytes.\n */\nexport function getJsonSize(value: unknown): number {\n assertStruct(value, JsonStruct, 'Invalid JSON value');\n\n const json = JSON.stringify(value);\n return new TextEncoder().encode(json).byteLength;\n}\n\n/**\n * The string '2.0'.\n */\nexport const jsonrpc2 = '2.0' as const;\nexport const JsonRpcVersionStruct = literal(jsonrpc2);\n\n/**\n * A String specifying the version of the JSON-RPC protocol.\n * MUST be exactly \"2.0\".\n */\nexport type JsonRpcVersion2 = typeof jsonrpc2;\n\nexport const JsonRpcIdStruct = nullable(union([number(), string()]));\n\n/**\n * An identifier established by the Client that MUST contain a String, Number,\n * or NULL value if included. If it is not included it is assumed to be a\n * notification. The value SHOULD normally not be Null and Numbers SHOULD\n * NOT contain fractional parts.\n */\nexport type JsonRpcId = Infer;\n\nexport const JsonRpcErrorStruct = object({\n code: integer(),\n message: string(),\n data: optional(JsonStruct),\n stack: optional(string()),\n});\n\n/**\n * Mark a certain key of a type as optional.\n */\nexport type OptionalField<\n Type extends Record,\n Key extends keyof Type,\n> = Omit & Partial>;\n\n/**\n * A JSON-RPC error object.\n *\n * Note that TypeScript infers `unknown | undefined` as `unknown`, meaning that\n * the `data` field is not optional. To make it optional, we use the\n * `OptionalField` helper, to explicitly make it optional.\n */\nexport type JsonRpcError = OptionalField<\n Infer,\n 'data'\n>;\n\nexport const JsonRpcParamsStruct: Struct, null> =\n optional(union([record(string(), JsonStruct), array(JsonStruct)])) as any;\n\nexport type JsonRpcParams = Json[] | Record;\n\nexport const JsonRpcRequestStruct = object({\n id: JsonRpcIdStruct,\n jsonrpc: JsonRpcVersionStruct,\n method: string(),\n params: JsonRpcParamsStruct,\n});\n\nexport type InferWithParams<\n Type extends Struct,\n Params extends JsonRpcParams,\n> = Omit, 'params'> &\n (keyof Params extends undefined\n ? {\n params?: Params;\n }\n : {\n params: Params;\n });\n\n/**\n * A JSON-RPC request object.\n */\nexport type JsonRpcRequest =\n InferWithParams;\n\nexport const JsonRpcNotificationStruct = omit(JsonRpcRequestStruct, ['id']);\n\n/**\n * A JSON-RPC notification object.\n */\nexport type JsonRpcNotification =\n InferWithParams;\n\n/**\n * Check if the given value is a valid {@link JsonRpcNotification} object.\n *\n * @param value - The value to check.\n * @returns Whether the given value is a valid {@link JsonRpcNotification}\n * object.\n */\nexport function isJsonRpcNotification(\n value: unknown,\n): value is JsonRpcNotification {\n return is(value, JsonRpcNotificationStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcNotification} object.\n *\n * @param value - The value to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcNotification} object.\n */\nexport function assertIsJsonRpcNotification(\n value: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcNotification {\n assertStruct(\n value,\n JsonRpcNotificationStruct,\n 'Invalid JSON-RPC notification',\n ErrorWrapper,\n );\n}\n\n/**\n * Check if the given value is a valid {@link JsonRpcRequest} object.\n *\n * @param value - The value to check.\n * @returns Whether the given value is a valid {@link JsonRpcRequest} object.\n */\nexport function isJsonRpcRequest(value: unknown): value is JsonRpcRequest {\n return is(value, JsonRpcRequestStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcRequest} object.\n *\n * @param value - The JSON-RPC request or notification to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcRequest} object.\n */\nexport function assertIsJsonRpcRequest(\n value: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcRequest {\n assertStruct(\n value,\n JsonRpcRequestStruct,\n 'Invalid JSON-RPC request',\n ErrorWrapper,\n );\n}\n\nexport const PendingJsonRpcResponseStruct = object({\n id: JsonRpcIdStruct,\n jsonrpc: JsonRpcVersionStruct,\n result: optional(unknown()),\n error: optional(JsonRpcErrorStruct),\n});\n\n/**\n * A JSON-RPC response object that has not yet been resolved.\n */\nexport type PendingJsonRpcResponse = Omit<\n Infer,\n 'result'\n> & {\n result?: Result;\n};\n\nexport const JsonRpcSuccessStruct = object({\n id: JsonRpcIdStruct,\n jsonrpc: JsonRpcVersionStruct,\n result: JsonStruct,\n});\n\n/**\n * A successful JSON-RPC response object.\n */\nexport type JsonRpcSuccess = Omit<\n Infer,\n 'result'\n> & {\n result: Result;\n};\n\nexport const JsonRpcFailureStruct = object({\n id: JsonRpcIdStruct,\n jsonrpc: JsonRpcVersionStruct,\n error: JsonRpcErrorStruct as Struct,\n});\n\n/**\n * A failed JSON-RPC response object.\n */\nexport type JsonRpcFailure = Infer;\n\nexport const JsonRpcResponseStruct = union([\n JsonRpcSuccessStruct,\n JsonRpcFailureStruct,\n]);\n\n/**\n * A JSON-RPC response object. Must be checked to determine whether it's a\n * success or failure.\n *\n * @template Result - The type of the result.\n */\nexport type JsonRpcResponse =\n | JsonRpcSuccess\n | JsonRpcFailure;\n\n/**\n * Type guard to check whether specified JSON-RPC response is a\n * {@link PendingJsonRpcResponse}.\n *\n * @param response - The JSON-RPC response to check.\n * @returns Whether the specified JSON-RPC response is pending.\n */\nexport function isPendingJsonRpcResponse(\n response: unknown,\n): response is PendingJsonRpcResponse {\n return is(response, PendingJsonRpcResponseStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link PendingJsonRpcResponse} object.\n *\n * @param response - The JSON-RPC response to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link PendingJsonRpcResponse}\n * object.\n */\nexport function assertIsPendingJsonRpcResponse(\n response: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts response is PendingJsonRpcResponse {\n assertStruct(\n response,\n PendingJsonRpcResponseStruct,\n 'Invalid pending JSON-RPC response',\n ErrorWrapper,\n );\n}\n\n/**\n * Type guard to check if a value is a {@link JsonRpcResponse}.\n *\n * @param response - The object to check.\n * @returns Whether the object is a JsonRpcResponse.\n */\nexport function isJsonRpcResponse(\n response: unknown,\n): response is JsonRpcResponse {\n return is(response, JsonRpcResponseStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcResponse} object.\n *\n * @param value - The value to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcResponse} object.\n */\nexport function assertIsJsonRpcResponse(\n value: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcResponse {\n assertStruct(\n value,\n JsonRpcResponseStruct,\n 'Invalid JSON-RPC response',\n ErrorWrapper,\n );\n}\n\n/**\n * Check if the given value is a valid {@link JsonRpcSuccess} object.\n *\n * @param value - The value to check.\n * @returns Whether the given value is a valid {@link JsonRpcSuccess} object.\n */\nexport function isJsonRpcSuccess(\n value: unknown,\n): value is JsonRpcSuccess {\n return is(value, JsonRpcSuccessStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcSuccess} object.\n *\n * @param value - The value to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcSuccess} object.\n */\nexport function assertIsJsonRpcSuccess(\n value: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcSuccess {\n assertStruct(\n value,\n JsonRpcSuccessStruct,\n 'Invalid JSON-RPC success response',\n ErrorWrapper,\n );\n}\n\n/**\n * Check if the given value is a valid {@link JsonRpcFailure} object.\n *\n * @param value - The value to check.\n * @returns Whether the given value is a valid {@link JsonRpcFailure} object.\n */\nexport function isJsonRpcFailure(value: unknown): value is JsonRpcFailure {\n return is(value, JsonRpcFailureStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcFailure} object.\n *\n * @param value - The value to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcFailure} object.\n */\nexport function assertIsJsonRpcFailure(\n value: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcFailure {\n assertStruct(\n value,\n JsonRpcFailureStruct,\n 'Invalid JSON-RPC failure response',\n ErrorWrapper,\n );\n}\n\n/**\n * Check if the given value is a valid {@link JsonRpcError} object.\n *\n * @param value - The value to check.\n * @returns Whether the given value is a valid {@link JsonRpcError} object.\n */\nexport function isJsonRpcError(value: unknown): value is JsonRpcError {\n return is(value, JsonRpcErrorStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcError} object.\n *\n * @param value - The value to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcError} object.\n */\nexport function assertIsJsonRpcError(\n value: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcError {\n assertStruct(\n value,\n JsonRpcErrorStruct,\n 'Invalid JSON-RPC error',\n ErrorWrapper,\n );\n}\n\ntype JsonRpcValidatorOptions = {\n permitEmptyString?: boolean;\n permitFractions?: boolean;\n permitNull?: boolean;\n};\n\n/**\n * Gets a function for validating JSON-RPC request / response `id` values.\n *\n * By manipulating the options of this factory, you can control the behavior\n * of the resulting validator for some edge cases. This is useful because e.g.\n * `null` should sometimes but not always be permitted.\n *\n * Note that the empty string (`''`) is always permitted by the JSON-RPC\n * specification, but that kind of sucks and you may want to forbid it in some\n * instances anyway.\n *\n * For more details, see the\n * [JSON-RPC Specification](https://www.jsonrpc.org/specification).\n *\n * @param options - An options object.\n * @param options.permitEmptyString - Whether the empty string (i.e. `''`)\n * should be treated as a valid ID. Default: `true`\n * @param options.permitFractions - Whether fractional numbers (e.g. `1.2`)\n * should be treated as valid IDs. Default: `false`\n * @param options.permitNull - Whether `null` should be treated as a valid ID.\n * Default: `true`\n * @returns The JSON-RPC ID validator function.\n */\nexport function getJsonRpcIdValidator(options?: JsonRpcValidatorOptions) {\n const { permitEmptyString, permitFractions, permitNull } = {\n permitEmptyString: true,\n permitFractions: false,\n permitNull: true,\n ...options,\n };\n\n /**\n * Type guard for {@link JsonRpcId}.\n *\n * @param id - The JSON-RPC ID value to check.\n * @returns Whether the given ID is valid per the options given to the\n * factory.\n */\n const isValidJsonRpcId = (id: unknown): id is JsonRpcId => {\n return Boolean(\n (typeof id === 'number' && (permitFractions || Number.isInteger(id))) ||\n (typeof id === 'string' && (permitEmptyString || id.length > 0)) ||\n (permitNull && id === null),\n );\n };\n\n return isValidJsonRpcId;\n}\n"],"names":["UnsafeJsonStruct","JsonStruct","isValidJson","getSafeJson","getJsonSize","jsonrpc2","JsonRpcVersionStruct","JsonRpcIdStruct","JsonRpcErrorStruct","JsonRpcParamsStruct","JsonRpcRequestStruct","JsonRpcNotificationStruct","isJsonRpcNotification","assertIsJsonRpcNotification","isJsonRpcRequest","assertIsJsonRpcRequest","PendingJsonRpcResponseStruct","JsonRpcSuccessStruct","JsonRpcFailureStruct","JsonRpcResponseStruct","isPendingJsonRpcResponse","assertIsPendingJsonRpcResponse","isJsonRpcResponse","assertIsJsonRpcResponse","isJsonRpcSuccess","assertIsJsonRpcSuccess","isJsonRpcFailure","assertIsJsonRpcFailure","isJsonRpcError","assertIsJsonRpcError","getJsonRpcIdValidator","finiteNumber","define","value","is","number","Number","isFinite","union","literal","boolean","string","array","lazy","record","coerce","any","assertStruct","JSON","parse","stringify","propKey","propValue","undefined","create","json","TextEncoder","encode","byteLength","nullable","object","code","integer","message","data","optional","stack","id","jsonrpc","method","params","omit","ErrorWrapper","result","unknown","error","response","options","permitEmptyString","permitFractions","permitNull","isValidJsonRpcId","Boolean","isInteger","length"],"mappings":";;;;;;;;;;;IAsDaA,gBAAgB;eAAhBA;;IAkBAC,UAAU;eAAVA;;IAoBGC,WAAW;eAAXA;;IAqBAC,WAAW;eAAXA;;IAUAC,WAAW;eAAXA;;IAUHC,QAAQ;eAARA;;IACAC,oBAAoB;eAApBA;;IAQAC,eAAe;eAAfA;;IAUAC,kBAAkB;eAAlBA;;IA2BAC,mBAAmB;eAAnBA;;IAKAC,oBAAoB;eAApBA;;IAyBAC,yBAAyB;eAAzBA;;IAeGC,qBAAqB;eAArBA;;IAcAC,2BAA2B;eAA3BA;;IAmBAC,gBAAgB;eAAhBA;;IAYAC,sBAAsB;eAAtBA;;IAaHC,4BAA4B;eAA5BA;;IAiBAC,oBAAoB;eAApBA;;IAgBAC,oBAAoB;eAApBA;;IAWAC,qBAAqB;eAArBA;;IAsBGC,wBAAwB;eAAxBA;;IAeAC,8BAA8B;eAA9BA;;IAmBAC,iB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AASqB,qBACdI,KAAc,EACd,gEAAgE;AAChEuC,YAAwC;IAExCzB,IAAAA,oBAAY,EACVd,OACAzB,oBACA,0BACAgE;AAEJ;AA+BO,SAAS1C,sBAAsB+C,OAAiC;IACrE,MAAM,EAAEC,iBAAiB,EAAEC,eAAe,EAAEC,UAAU,EAAE,GAAG;QACzDF,mBAAmB;QACnBC,iBAAiB;QACjBC,YAAY;QACZ,GAAGH,OAAO;IACZ;IAEA;;;;;;GAMC,GACD,MAAMI,mBAAmB,CAACd;QACxB,OAAOe,QACL,AAAC,OAAOf,OAAO,YAAaY,CAAAA,mBAAmB3C,OAAO+C,SAAS,CAAChB,GAAE,KAC/D,OAAOA,OAAO,YAAaW,CAAAA,qBAAqBX,GAAGiB,MAAM,GAAG,CAAA,KAC5DJ,cAAcb,OAAO;IAE5B;IAEA,OAAOc;AACT"} +\ No newline at end of file ++{"version":3,"sources":["../../src/json.ts"],"sourcesContent":["import type { Infer, Struct } from 'superstruct';\nimport {\n any,\n array,\n boolean,\n coerce,\n create,\n define,\n integer,\n is,\n lazy,\n literal,\n nullable,\n number,\n object,\n optional,\n record,\n string,\n union,\n unknown,\n} from 'superstruct';\n\nimport type { AssertionErrorConstructor } from './assert';\nimport { assertStruct } from './assert';\n\n/**\n * Any JSON-compatible value.\n */\nexport type Json =\n | null\n | boolean\n | number\n | string\n | Json[]\n | { [prop: string]: Json };\n\n/**\n * A struct to check if the given value is finite number. Superstruct's\n * `number()` struct does not check if the value is finite.\n *\n * @returns A struct to check if the given value is finite number.\n */\nconst finiteNumber = () =>\n define('finite number', (value) => {\n return is(value, number()) && Number.isFinite(value);\n });\n\n/**\n * A struct to check if the given value is a valid JSON-serializable value.\n *\n * Note that this struct is unsafe. For safe validation, use {@link JsonStruct}.\n */\n// We cannot infer the type of the struct, because it is recursive.\nexport const UnsafeJsonStruct: Struct = union([\n literal(null),\n boolean(),\n finiteNumber(),\n string(),\n array(lazy(() => UnsafeJsonStruct)),\n record(\n string(),\n lazy(() => UnsafeJsonStruct),\n ),\n]);\n\n/**\n * A struct to check if the given value is a valid JSON-serializable value.\n *\n * This struct sanitizes the value before validating it, so that it is safe to\n * use with untrusted input.\n */\nexport const JsonStruct = coerce(UnsafeJsonStruct, any(), (value) => {\n assertStruct(value, UnsafeJsonStruct);\n return JSON.parse(\n JSON.stringify(value, (propKey, propValue) => {\n // Strip __proto__ and constructor properties to prevent prototype pollution.\n if (propKey === '__proto__' || propKey === 'constructor') {\n return undefined;\n }\n return propValue;\n }),\n );\n});\n\n/**\n * Check if the given value is a valid {@link Json} value, i.e., a value that is\n * serializable to JSON.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid {@link Json} value.\n */\nexport function isValidJson(value: unknown): value is Json {\n try {\n getSafeJson(value);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Validate and return sanitized JSON.\n *\n * Note:\n * This function uses sanitized JsonStruct for validation\n * that applies stringify and then parse of a value provided\n * to ensure that there are no getters which can have side effects\n * that can cause security issues.\n *\n * @param value - JSON structure to be processed.\n * @returns Sanitized JSON structure.\n */\nexport function getSafeJson(value: unknown): Type {\n return create(value, JsonStruct) as Type;\n}\n\n/**\n * Get the size of a JSON value in bytes. This also validates the value.\n *\n * @param value - The JSON value to get the size of.\n * @returns The size of the JSON value in bytes.\n */\nexport function getJsonSize(value: unknown): number {\n assertStruct(value, JsonStruct, 'Invalid JSON value');\n\n const json = JSON.stringify(value);\n return new TextEncoder().encode(json).byteLength;\n}\n\n/**\n * The string '2.0'.\n */\nexport const jsonrpc2 = '2.0' as const;\nexport const JsonRpcVersionStruct = literal(jsonrpc2);\n\n/**\n * A String specifying the version of the JSON-RPC protocol.\n * MUST be exactly \"2.0\".\n */\nexport type JsonRpcVersion2 = typeof jsonrpc2;\n\nexport const JsonRpcIdStruct = nullable(union([number(), string()]));\n\n/**\n * An identifier established by the Client that MUST contain a String, Number,\n * or NULL value if included. If it is not included it is assumed to be a\n * notification. The value SHOULD normally not be Null and Numbers SHOULD\n * NOT contain fractional parts.\n */\nexport type JsonRpcId = Infer;\n\nexport const JsonRpcErrorStruct = object({\n code: integer(),\n message: string(),\n data: optional(JsonStruct),\n stack: optional(string()),\n});\n\n/**\n * Mark a certain key of a type as optional.\n */\nexport type OptionalField<\n Type extends Record,\n Key extends keyof Type,\n> = Omit & Partial>;\n\n/**\n * A JSON-RPC error object.\n *\n * Note that TypeScript infers `unknown | undefined` as `unknown`, meaning that\n * the `data` field is not optional. To make it optional, we use the\n * `OptionalField` helper, to explicitly make it optional.\n */\nexport type JsonRpcError = OptionalField<\n Infer,\n 'data'\n>;\n\nexport const JsonRpcParamsStruct: Struct, null> =\n union([record(string(), JsonStruct), array(JsonStruct)]);\n\nexport type JsonRpcParams = Json[] | Record;\n\nexport const JsonRpcRequestStruct = object({\n id: JsonRpcIdStruct,\n jsonrpc: JsonRpcVersionStruct,\n method: string(),\n params: optional(JsonRpcParamsStruct),\n});\n\nexport type InferWithParams<\n Type extends Struct,\n Params extends JsonRpcParams,\n> = Omit, 'params'> & {\n params?: Exclude;\n};\n\n/**\n * A JSON-RPC request object.\n */\nexport type JsonRpcRequest =\n InferWithParams;\n\nexport const JsonRpcNotificationStruct = object({\n jsonrpc: JsonRpcVersionStruct,\n method: string(),\n params: optional(JsonRpcParamsStruct),\n});\n\n/**\n * A JSON-RPC notification object.\n */\nexport type JsonRpcNotification =\n InferWithParams;\n\n/**\n * Check if the given value is a valid {@link JsonRpcNotification} object.\n *\n * @param value - The value to check.\n * @returns Whether the given value is a valid {@link JsonRpcNotification}\n * object.\n */\nexport function isJsonRpcNotification(\n value: unknown,\n): value is JsonRpcNotification {\n return is(value, JsonRpcNotificationStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcNotification} object.\n *\n * @param value - The value to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcNotification} object.\n */\nexport function assertIsJsonRpcNotification(\n value: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcNotification {\n assertStruct(\n value,\n JsonRpcNotificationStruct,\n 'Invalid JSON-RPC notification',\n ErrorWrapper,\n );\n}\n\n/**\n * Check if the given value is a valid {@link JsonRpcRequest} object.\n *\n * @param value - The value to check.\n * @returns Whether the given value is a valid {@link JsonRpcRequest} object.\n */\nexport function isJsonRpcRequest(value: unknown): value is JsonRpcRequest {\n return is(value, JsonRpcRequestStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcRequest} object.\n *\n * @param value - The JSON-RPC request or notification to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcRequest} object.\n */\nexport function assertIsJsonRpcRequest(\n value: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcRequest {\n assertStruct(\n value,\n JsonRpcRequestStruct,\n 'Invalid JSON-RPC request',\n ErrorWrapper,\n );\n}\n\nexport const PendingJsonRpcResponseStruct = object({\n id: JsonRpcIdStruct,\n jsonrpc: JsonRpcVersionStruct,\n result: optional(unknown()),\n error: optional(JsonRpcErrorStruct),\n});\n\n/**\n * A JSON-RPC response object that has not yet been resolved.\n */\nexport type PendingJsonRpcResponse = Omit<\n Infer,\n 'result'\n> & {\n result?: Result;\n};\n\nexport const JsonRpcSuccessStruct = object({\n id: JsonRpcIdStruct,\n jsonrpc: JsonRpcVersionStruct,\n result: JsonStruct,\n});\n\n/**\n * A successful JSON-RPC response object.\n */\nexport type JsonRpcSuccess = Omit<\n Infer,\n 'result'\n> & {\n result: Result;\n};\n\nexport const JsonRpcFailureStruct = object({\n id: JsonRpcIdStruct,\n jsonrpc: JsonRpcVersionStruct,\n error: JsonRpcErrorStruct as Struct,\n});\n\n/**\n * A failed JSON-RPC response object.\n */\nexport type JsonRpcFailure = Infer;\n\nexport const JsonRpcResponseStruct = union([\n JsonRpcSuccessStruct,\n JsonRpcFailureStruct,\n]);\n\n/**\n * A JSON-RPC response object. Must be checked to determine whether it's a\n * success or failure.\n *\n * @template Result - The type of the result.\n */\nexport type JsonRpcResponse =\n | JsonRpcSuccess\n | JsonRpcFailure;\n\n/**\n * Type guard to check whether specified JSON-RPC response is a\n * {@link PendingJsonRpcResponse}.\n *\n * @param response - The JSON-RPC response to check.\n * @returns Whether the specified JSON-RPC response is pending.\n */\nexport function isPendingJsonRpcResponse(\n response: unknown,\n): response is PendingJsonRpcResponse {\n return is(response, PendingJsonRpcResponseStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link PendingJsonRpcResponse} object.\n *\n * @param response - The JSON-RPC response to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link PendingJsonRpcResponse}\n * object.\n */\nexport function assertIsPendingJsonRpcResponse(\n response: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts response is PendingJsonRpcResponse {\n assertStruct(\n response,\n PendingJsonRpcResponseStruct,\n 'Invalid pending JSON-RPC response',\n ErrorWrapper,\n );\n}\n\n/**\n * Type guard to check if a value is a {@link JsonRpcResponse}.\n *\n * @param response - The object to check.\n * @returns Whether the object is a JsonRpcResponse.\n */\nexport function isJsonRpcResponse(\n response: unknown,\n): response is JsonRpcResponse {\n return is(response, JsonRpcResponseStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcResponse} object.\n *\n * @param value - The value to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcResponse} object.\n */\nexport function assertIsJsonRpcResponse(\n value: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcResponse {\n assertStruct(\n value,\n JsonRpcResponseStruct,\n 'Invalid JSON-RPC response',\n ErrorWrapper,\n );\n}\n\n/**\n * Check if the given value is a valid {@link JsonRpcSuccess} object.\n *\n * @param value - The value to check.\n * @returns Whether the given value is a valid {@link JsonRpcSuccess} object.\n */\nexport function isJsonRpcSuccess(\n value: unknown,\n): value is JsonRpcSuccess {\n return is(value, JsonRpcSuccessStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcSuccess} object.\n *\n * @param value - The value to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcSuccess} object.\n */\nexport function assertIsJsonRpcSuccess(\n value: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcSuccess {\n assertStruct(\n value,\n JsonRpcSuccessStruct,\n 'Invalid JSON-RPC success response',\n ErrorWrapper,\n );\n}\n\n/**\n * Check if the given value is a valid {@link JsonRpcFailure} object.\n *\n * @param value - The value to check.\n * @returns Whether the given value is a valid {@link JsonRpcFailure} object.\n */\nexport function isJsonRpcFailure(value: unknown): value is JsonRpcFailure {\n return is(value, JsonRpcFailureStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcFailure} object.\n *\n * @param value - The value to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcFailure} object.\n */\nexport function assertIsJsonRpcFailure(\n value: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcFailure {\n assertStruct(\n value,\n JsonRpcFailureStruct,\n 'Invalid JSON-RPC failure response',\n ErrorWrapper,\n );\n}\n\n/**\n * Check if the given value is a valid {@link JsonRpcError} object.\n *\n * @param value - The value to check.\n * @returns Whether the given value is a valid {@link JsonRpcError} object.\n */\nexport function isJsonRpcError(value: unknown): value is JsonRpcError {\n return is(value, JsonRpcErrorStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcError} object.\n *\n * @param value - The value to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcError} object.\n */\nexport function assertIsJsonRpcError(\n value: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcError {\n assertStruct(\n value,\n JsonRpcErrorStruct,\n 'Invalid JSON-RPC error',\n ErrorWrapper,\n );\n}\n\ntype JsonRpcValidatorOptions = {\n permitEmptyString?: boolean;\n permitFractions?: boolean;\n permitNull?: boolean;\n};\n\n/**\n * Gets a function for validating JSON-RPC request / response `id` values.\n *\n * By manipulating the options of this factory, you can control the behavior\n * of the resulting validator for some edge cases. This is useful because e.g.\n * `null` should sometimes but not always be permitted.\n *\n * Note that the empty string (`''`) is always permitted by the JSON-RPC\n * specification, but that kind of sucks and you may want to forbid it in some\n * instances anyway.\n *\n * For more details, see the\n * [JSON-RPC Specification](https://www.jsonrpc.org/specification).\n *\n * @param options - An options object.\n * @param options.permitEmptyString - Whether the empty string (i.e. `''`)\n * should be treated as a valid ID. Default: `true`\n * @param options.permitFractions - Whether fractional numbers (e.g. `1.2`)\n * should be treated as valid IDs. Default: `false`\n * @param options.permitNull - Whether `null` should be treated as a valid ID.\n * Default: `true`\n * @returns The JSON-RPC ID validator function.\n */\nexport function getJsonRpcIdValidator(options?: JsonRpcValidatorOptions) {\n const { permitEmptyString, permitFractions, permitNull } = {\n permitEmptyString: true,\n permitFractions: false,\n permitNull: true,\n ...options,\n };\n\n /**\n * Type guard for {@link JsonRpcId}.\n *\n * @param id - The JSON-RPC ID value to check.\n * @returns Whether the given ID is valid per the options given to the\n * factory.\n */\n const isValidJsonRpcId = (id: unknown): id is JsonRpcId => {\n return Boolean(\n (typeof id === 'number' && (permitFractions || Number.isInteger(id))) ||\n (typeof id === 'string' && (permitEmptyString || id.length > 0)) ||\n (permitNull && id === null),\n );\n };\n\n return isValidJsonRpcId;\n}\n"],"names":["UnsafeJsonStruct","JsonStruct","isValidJson","getSafeJson","getJsonSize","jsonrpc2","JsonRpcVersionStruct","JsonRpcIdStruct","JsonRpcErrorStruct","JsonRpcParamsStruct","JsonRpcRequestStruct","JsonRpcNotificationStruct","isJsonRpcNotification","assertIsJsonRpcNotification","isJsonRpcRequest","assertIsJsonRpcRequest","PendingJsonRpcResponseStruct","JsonRpcSuccessStruct","JsonRpcFailureStruct","JsonRpcResponseStruct","isPendingJsonRpcResponse","assertIsPendingJsonRpcResponse","isJsonRpcResponse","assertIsJsonRpcResponse","isJsonRpcSuccess","assertIsJsonRpcSuccess","isJsonRpcFailure","assertIsJsonRpcFailure","isJsonRpcError","assertIsJsonRpcError","getJsonRpcIdValidator","finiteNumber","define","value","is","number","Number","isFinite","union","literal","boolean","string","array","lazy","record","coerce","any","assertStruct","JSON","parse","stringify","propKey","propValue","undefined","create","json","TextEncoder","encode","byteLength","nullable","object","code","integer","message","data","optional","stack","id","jsonrpc","method","params","ErrorWrapper","result","unknown","error","response","options","permitEmptyString","permitFractions","permitNull","isValidJsonRpcId","Boolean","isInteger","length"],"mappings":";;;;;;;;;;;IAqDaA,gBAAgB;eAAhBA;;IAkBAC,UAAU;eAAVA;;IAoBGC,WAAW;eAAXA;;IAqBAC,WAAW;eAAXA;;IAUAC,WAAW;eAAXA;;IAUHC,QAAQ;eAARA;;IACAC,oBAAoB;eAApBA;;IAQAC,eAAe;eAAfA;;IAUAC,kBAAkB;eAAlBA;;IA2BAC,mBAAmB;eAAnBA;;IAKAC,oBAAoB;eAApBA;;IAoBAC,yBAAyB;eAAzBA;;IAmBGC,qBAAqB;eAArBA;;IAcAC,2BAA2B;eAA3BA;;IAmBAC,gBAAgB;eAAhBA;;IAYAC,sBAAsB;eAAtBA;;IAaHC,4BAA4B;eAA5BA;;IAiBAC,oBAAoB;eAApBA;;IAgBAC,oBAAoB;eAApBA;;IAWAC,qBAA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ExCxB,IAAAA,oBAAY,EACVd,OACAf,sBACA,qCACAqD;AAEJ;AAQO,SAAS3C,eAAeK,KAAc;IAC3C,OAAOC,IAAAA,eAAE,EAACD,OAAOzB;AACnB;AAUO,SAASqB,qBACdI,KAAc,EACd,gEAAgE;AAChEsC,YAAwC;IAExCxB,IAAAA,oBAAY,EACVd,OACAzB,oBACA,0BACA+D;AAEJ;AA+BO,SAASzC,sBAAsB8C,OAAiC;IACrE,MAAM,EAAEC,iBAAiB,EAAEC,eAAe,EAAEC,UAAU,EAAE,GAAG;QACzDF,mBAAmB;QACnBC,iBAAiB;QACjBC,YAAY;QACZ,GAAGH,OAAO;IACZ;IAEA;;;;;;GAMC,GACD,MAAMI,mBAAmB,CAACb;QACxB,OAAOc,QACL,AAAC,OAAOd,OAAO,YAAaW,CAAAA,mBAAmB1C,OAAO8C,SAAS,CAACf,GAAE,KAC/D,OAAOA,OAAO,YAAaU,CAAAA,qBAAqBV,GAAGgB,MAAM,GAAG,CAAA,KAC5DJ,cAAcZ,OAAO;IAE5B;IAEA,OAAOa;AACT"} +\ No newline at end of file +diff --git a/dist/esm/json.js b/dist/esm/json.js +index 2c039cccf11893d2d88fc4fb666e7836c9a42325..9fde1cc048acf7ee6c5a9265efee68cd4e5c99be 100644 +--- a/dist/esm/json.js ++++ b/dist/esm/json.js +@@ -1,4 +1,4 @@ +-import { any, array, boolean, coerce, create, define, integer, is, lazy, literal, nullable, number, object, omit, optional, record, string, union, unknown } from 'superstruct'; ++import { any, array, boolean, coerce, create, define, integer, is, lazy, literal, nullable, number, object, optional, record, string, union, unknown } from 'superstruct'; + import { assertStruct } from './assert'; + /** + * A struct to check if the given value is finite number. Superstruct's +@@ -88,19 +88,21 @@ export const JsonRpcErrorStruct = object({ + data: optional(JsonStruct), + stack: optional(string()) + }); +-export const JsonRpcParamsStruct = optional(union([ ++export const JsonRpcParamsStruct = union([ + record(string(), JsonStruct), + array(JsonStruct) +-])); ++]); + export const JsonRpcRequestStruct = object({ + id: JsonRpcIdStruct, + jsonrpc: JsonRpcVersionStruct, + method: string(), +- params: JsonRpcParamsStruct ++ params: optional(JsonRpcParamsStruct) ++}); ++export const JsonRpcNotificationStruct = object({ ++ jsonrpc: JsonRpcVersionStruct, ++ method: string(), ++ params: optional(JsonRpcParamsStruct) + }); +-export const JsonRpcNotificationStruct = omit(JsonRpcRequestStruct, [ +- 'id' +-]); + /** + * Check if the given value is a valid {@link JsonRpcNotification} object. + * +diff --git a/dist/esm/json.js.map b/dist/esm/json.js.map +index ae3392c53e52a601e18ce8991dc6e4414a50123f..b573ffa47cd505108a64f591d599147ec52e11f6 100644 +--- a/dist/esm/json.js.map ++++ b/dist/esm/json.js.map +@@ -1 +1 @@ +-{"version":3,"sources":["../../src/json.ts"],"sourcesContent":["import type { Infer, Struct } from 'superstruct';\nimport {\n any,\n array,\n boolean,\n coerce,\n create,\n define,\n integer,\n is,\n lazy,\n literal,\n nullable,\n number,\n object,\n omit,\n optional,\n record,\n string,\n union,\n unknown,\n} from 'superstruct';\n\nimport type { AssertionErrorConstructor } from './assert';\nimport { assertStruct } from './assert';\n\n/**\n * Any JSON-compatible value.\n */\nexport type Json =\n | null\n | boolean\n | number\n | string\n | Json[]\n | { [prop: string]: Json };\n\n/**\n * A struct to check if the given value is finite number. Superstruct's\n * `number()` struct does not check if the value is finite.\n *\n * @returns A struct to check if the given value is finite number.\n */\nconst finiteNumber = () =>\n define('finite number', (value) => {\n return is(value, number()) && Number.isFinite(value);\n });\n\n/**\n * A struct to check if the given value is a valid JSON-serializable value.\n *\n * Note that this struct is unsafe. For safe validation, use {@link JsonStruct}.\n */\n// We cannot infer the type of the struct, because it is recursive.\nexport const UnsafeJsonStruct: Struct = union([\n literal(null),\n boolean(),\n finiteNumber(),\n string(),\n array(lazy(() => UnsafeJsonStruct)),\n record(\n string(),\n lazy(() => UnsafeJsonStruct),\n ),\n]);\n\n/**\n * A struct to check if the given value is a valid JSON-serializable value.\n *\n * This struct sanitizes the value before validating it, so that it is safe to\n * use with untrusted input.\n */\nexport const JsonStruct = coerce(UnsafeJsonStruct, any(), (value) => {\n assertStruct(value, UnsafeJsonStruct);\n return JSON.parse(\n JSON.stringify(value, (propKey, propValue) => {\n // Strip __proto__ and constructor properties to prevent prototype pollution.\n if (propKey === '__proto__' || propKey === 'constructor') {\n return undefined;\n }\n return propValue;\n }),\n );\n});\n\n/**\n * Check if the given value is a valid {@link Json} value, i.e., a value that is\n * serializable to JSON.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid {@link Json} value.\n */\nexport function isValidJson(value: unknown): value is Json {\n try {\n getSafeJson(value);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Validate and return sanitized JSON.\n *\n * Note:\n * This function uses sanitized JsonStruct for validation\n * that applies stringify and then parse of a value provided\n * to ensure that there are no getters which can have side effects\n * that can cause security issues.\n *\n * @param value - JSON structure to be processed.\n * @returns Sanitized JSON structure.\n */\nexport function getSafeJson(value: unknown): Type {\n return create(value, JsonStruct) as Type;\n}\n\n/**\n * Get the size of a JSON value in bytes. This also validates the value.\n *\n * @param value - The JSON value to get the size of.\n * @returns The size of the JSON value in bytes.\n */\nexport function getJsonSize(value: unknown): number {\n assertStruct(value, JsonStruct, 'Invalid JSON value');\n\n const json = JSON.stringify(value);\n return new TextEncoder().encode(json).byteLength;\n}\n\n/**\n * The string '2.0'.\n */\nexport const jsonrpc2 = '2.0' as const;\nexport const JsonRpcVersionStruct = literal(jsonrpc2);\n\n/**\n * A String specifying the version of the JSON-RPC protocol.\n * MUST be exactly \"2.0\".\n */\nexport type JsonRpcVersion2 = typeof jsonrpc2;\n\nexport const JsonRpcIdStruct = nullable(union([number(), string()]));\n\n/**\n * An identifier established by the Client that MUST contain a String, Number,\n * or NULL value if included. If it is not included it is assumed to be a\n * notification. The value SHOULD normally not be Null and Numbers SHOULD\n * NOT contain fractional parts.\n */\nexport type JsonRpcId = Infer;\n\nexport const JsonRpcErrorStruct = object({\n code: integer(),\n message: string(),\n data: optional(JsonStruct),\n stack: optional(string()),\n});\n\n/**\n * Mark a certain key of a type as optional.\n */\nexport type OptionalField<\n Type extends Record,\n Key extends keyof Type,\n> = Omit & Partial>;\n\n/**\n * A JSON-RPC error object.\n *\n * Note that TypeScript infers `unknown | undefined` as `unknown`, meaning that\n * the `data` field is not optional. To make it optional, we use the\n * `OptionalField` helper, to explicitly make it optional.\n */\nexport type JsonRpcError = OptionalField<\n Infer,\n 'data'\n>;\n\nexport const JsonRpcParamsStruct: Struct, null> =\n optional(union([record(string(), JsonStruct), array(JsonStruct)])) as any;\n\nexport type JsonRpcParams = Json[] | Record;\n\nexport const JsonRpcRequestStruct = object({\n id: JsonRpcIdStruct,\n jsonrpc: JsonRpcVersionStruct,\n method: string(),\n params: JsonRpcParamsStruct,\n});\n\nexport type InferWithParams<\n Type extends Struct,\n Params extends JsonRpcParams,\n> = Omit, 'params'> &\n (keyof Params extends undefined\n ? {\n params?: Params;\n }\n : {\n params: Params;\n });\n\n/**\n * A JSON-RPC request object.\n */\nexport type JsonRpcRequest =\n InferWithParams;\n\nexport const JsonRpcNotificationStruct = omit(JsonRpcRequestStruct, ['id']);\n\n/**\n * A JSON-RPC notification object.\n */\nexport type JsonRpcNotification =\n InferWithParams;\n\n/**\n * Check if the given value is a valid {@link JsonRpcNotification} object.\n *\n * @param value - The value to check.\n * @returns Whether the given value is a valid {@link JsonRpcNotification}\n * object.\n */\nexport function isJsonRpcNotification(\n value: unknown,\n): value is JsonRpcNotification {\n return is(value, JsonRpcNotificationStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcNotification} object.\n *\n * @param value - The value to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcNotification} object.\n */\nexport function assertIsJsonRpcNotification(\n value: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcNotification {\n assertStruct(\n value,\n JsonRpcNotificationStruct,\n 'Invalid JSON-RPC notification',\n ErrorWrapper,\n );\n}\n\n/**\n * Check if the given value is a valid {@link JsonRpcRequest} object.\n *\n * @param value - The value to check.\n * @returns Whether the given value is a valid {@link JsonRpcRequest} object.\n */\nexport function isJsonRpcRequest(value: unknown): value is JsonRpcRequest {\n return is(value, JsonRpcRequestStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcRequest} object.\n *\n * @param value - The JSON-RPC request or notification to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcRequest} object.\n */\nexport function assertIsJsonRpcRequest(\n value: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcRequest {\n assertStruct(\n value,\n JsonRpcRequestStruct,\n 'Invalid JSON-RPC request',\n ErrorWrapper,\n );\n}\n\nexport const PendingJsonRpcResponseStruct = object({\n id: JsonRpcIdStruct,\n jsonrpc: JsonRpcVersionStruct,\n result: optional(unknown()),\n error: optional(JsonRpcErrorStruct),\n});\n\n/**\n * A JSON-RPC response object that has not yet been resolved.\n */\nexport type PendingJsonRpcResponse = Omit<\n Infer,\n 'result'\n> & {\n result?: Result;\n};\n\nexport const JsonRpcSuccessStruct = object({\n id: JsonRpcIdStruct,\n jsonrpc: JsonRpcVersionStruct,\n result: JsonStruct,\n});\n\n/**\n * A successful JSON-RPC response object.\n */\nexport type JsonRpcSuccess = Omit<\n Infer,\n 'result'\n> & {\n result: Result;\n};\n\nexport const JsonRpcFailureStruct = object({\n id: JsonRpcIdStruct,\n jsonrpc: JsonRpcVersionStruct,\n error: JsonRpcErrorStruct as Struct,\n});\n\n/**\n * A failed JSON-RPC response object.\n */\nexport type JsonRpcFailure = Infer;\n\nexport const JsonRpcResponseStruct = union([\n JsonRpcSuccessStruct,\n JsonRpcFailureStruct,\n]);\n\n/**\n * A JSON-RPC response object. Must be checked to determine whether it's a\n * success or failure.\n *\n * @template Result - The type of the result.\n */\nexport type JsonRpcResponse =\n | JsonRpcSuccess\n | JsonRpcFailure;\n\n/**\n * Type guard to check whether specified JSON-RPC response is a\n * {@link PendingJsonRpcResponse}.\n *\n * @param response - The JSON-RPC response to check.\n * @returns Whether the specified JSON-RPC response is pending.\n */\nexport function isPendingJsonRpcResponse(\n response: unknown,\n): response is PendingJsonRpcResponse {\n return is(response, PendingJsonRpcResponseStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link PendingJsonRpcResponse} object.\n *\n * @param response - The JSON-RPC response to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link PendingJsonRpcResponse}\n * object.\n */\nexport function assertIsPendingJsonRpcResponse(\n response: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts response is PendingJsonRpcResponse {\n assertStruct(\n response,\n PendingJsonRpcResponseStruct,\n 'Invalid pending JSON-RPC response',\n ErrorWrapper,\n );\n}\n\n/**\n * Type guard to check if a value is a {@link JsonRpcResponse}.\n *\n * @param response - The object to check.\n * @returns Whether the object is a JsonRpcResponse.\n */\nexport function isJsonRpcResponse(\n response: unknown,\n): response is JsonRpcResponse {\n return is(response, JsonRpcResponseStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcResponse} object.\n *\n * @param value - The value to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcResponse} object.\n */\nexport function assertIsJsonRpcResponse(\n value: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcResponse {\n assertStruct(\n value,\n JsonRpcResponseStruct,\n 'Invalid JSON-RPC response',\n ErrorWrapper,\n );\n}\n\n/**\n * Check if the given value is a valid {@link JsonRpcSuccess} object.\n *\n * @param value - The value to check.\n * @returns Whether the given value is a valid {@link JsonRpcSuccess} object.\n */\nexport function isJsonRpcSuccess(\n value: unknown,\n): value is JsonRpcSuccess {\n return is(value, JsonRpcSuccessStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcSuccess} object.\n *\n * @param value - The value to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcSuccess} object.\n */\nexport function assertIsJsonRpcSuccess(\n value: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcSuccess {\n assertStruct(\n value,\n JsonRpcSuccessStruct,\n 'Invalid JSON-RPC success response',\n ErrorWrapper,\n );\n}\n\n/**\n * Check if the given value is a valid {@link JsonRpcFailure} object.\n *\n * @param value - The value to check.\n * @returns Whether the given value is a valid {@link JsonRpcFailure} object.\n */\nexport function isJsonRpcFailure(value: unknown): value is JsonRpcFailure {\n return is(value, JsonRpcFailureStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcFailure} object.\n *\n * @param value - The value to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcFailure} object.\n */\nexport function assertIsJsonRpcFailure(\n value: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcFailure {\n assertStruct(\n value,\n JsonRpcFailureStruct,\n 'Invalid JSON-RPC failure response',\n ErrorWrapper,\n );\n}\n\n/**\n * Check if the given value is a valid {@link JsonRpcError} object.\n *\n * @param value - The value to check.\n * @returns Whether the given value is a valid {@link JsonRpcError} object.\n */\nexport function isJsonRpcError(value: unknown): value is JsonRpcError {\n return is(value, JsonRpcErrorStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcError} object.\n *\n * @param value - The value to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcError} object.\n */\nexport function assertIsJsonRpcError(\n value: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcError {\n assertStruct(\n value,\n JsonRpcErrorStruct,\n 'Invalid JSON-RPC error',\n ErrorWrapper,\n );\n}\n\ntype JsonRpcValidatorOptions = {\n permitEmptyString?: boolean;\n permitFractions?: boolean;\n permitNull?: boolean;\n};\n\n/**\n * Gets a function for validating JSON-RPC request / response `id` values.\n *\n * By manipulating the options of this factory, you can control the behavior\n * of the resulting validator for some edge cases. This is useful because e.g.\n * `null` should sometimes but not always be permitted.\n *\n * Note that the empty string (`''`) is always permitted by the JSON-RPC\n * specification, but that kind of sucks and you may want to forbid it in some\n * instances anyway.\n *\n * For more details, see the\n * [JSON-RPC Specification](https://www.jsonrpc.org/specification).\n *\n * @param options - An options object.\n * @param options.permitEmptyString - Whether the empty string (i.e. `''`)\n * should be treated as a valid ID. Default: `true`\n * @param options.permitFractions - Whether fractional numbers (e.g. `1.2`)\n * should be treated as valid IDs. Default: `false`\n * @param options.permitNull - Whether `null` should be treated as a valid ID.\n * Default: `true`\n * @returns The JSON-RPC ID validator function.\n */\nexport function getJsonRpcIdValidator(options?: JsonRpcValidatorOptions) {\n const { permitEmptyString, permitFractions, permitNull } = {\n permitEmptyString: true,\n permitFractions: false,\n permitNull: true,\n ...options,\n };\n\n /**\n * Type guard for {@link JsonRpcId}.\n *\n * @param id - The JSON-RPC ID value to check.\n * @returns Whether the given ID is valid per the options given to the\n * factory.\n */\n const isValidJsonRpcId = (id: unknown): id is JsonRpcId => {\n return Boolean(\n (typeof id === 'number' && (permitFractions || Number.isInteger(id))) ||\n (typeof id === 'string' && (permitEmptyString || id.length > 0)) ||\n (permitNull && id === null),\n );\n };\n\n return isValidJsonRpcId;\n}\n"],"names":["any","array","boolean","coerce","create","define","integer","is","lazy","literal","nullable","number","object","omit","optional","record","string","union","unknown","assertStruct","finiteNumber","value","Number","isFinite","UnsafeJsonStruct","JsonStruct","JSON","parse","stringify","propKey","propValue","undefined","isValidJson","getSafeJson","getJsonSize","json","TextEncoder","encode","byteLength","jsonrpc2","JsonRpcVersionStruct","JsonRpcIdStruct","JsonRpcErrorStruct","code","message","data","stack","JsonRpcParamsStruct","JsonRpcRequestStruct","id","jsonrpc","method","params","JsonRpcNotificationStruct","isJsonRpcNotification","assertIsJsonRpcNotification","ErrorWrapper","isJsonRpcRequest","assertIsJsonRpcRequest","PendingJsonRpcResponseStruct","result","error","JsonRpcSuccessStruct","JsonRpcFailureStruct","JsonRpcResponseStruct","isPendingJsonRpcResponse","response","assertIsPendingJsonRpcResponse","isJsonRpcResponse","assertIsJsonRpcResponse","isJsonRpcSuccess","assertIsJsonRpcSuccess","isJsonRpcFailure","assertIsJsonRpcFailure","isJsonRpcError","assertIsJsonRpcError","getJsonRpcIdValidator","options","permitEmptyString","permitFractions","permitNull","isValidJsonRpcId","Boolean","isInteger","length"],"mappings":"AACA,SACEA,GAAG,EACHC,KAAK,EACLC,OAAO,EACPC,MAAM,EACNC,MAAM,EACNC,MAAM,EACNC,OAAO,EACPC,EAAE,EACFC,IAAI,EACJC,OAAO,EACPC,QAAQ,EACRC,MAAM,EACNC,MAAM,EACNC,IAAI,EACJC,QAAQ,EACRC,MAAM,EACNC,MAAM,EACNC,KAAK,EACLC,OAAO,QACF,cAAc;AAGrB,SAASC,YAAY,QAAQ,WAAW;AAaxC;;;;;CAKC,GACD,MAAMC,eAAe,IACnBf,OAAe,iBAAiB,CAACgB;QAC/B,OAAOd,GAAGc,OAAOV,aAAaW,OAAOC,QAAQ,CAACF;IAChD;AAEF;;;;CAIC,GACD,mEAAmE;AACnE,OAAO,MAAMG,mBAAiCP,MAAM;IAClDR,QAAQ;IACRP;IACAkB;IACAJ;IACAf,MAAMO,KAAK,IAAMgB;IACjBT,OACEC,UACAR,KAAK,IAAMgB;CAEd,EAAE;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AAOd,GAAGc,OAAOyC;AACnB;AAEA;;;;;;;CAOC,GACD,OAAO,SAASS,uBACdlD,KAAc,EACd,gEAAgE;AAChEmC,YAAwC;IAExCrC,aACEE,OACAyC,sBACA,qCACAN;AAEJ;AAEA;;;;;CAKC,GACD,OAAO,SAASgB,iBAAiBnD,KAAc;IAC7C,OAAOd,GAAGc,OAAO0C;AACnB;AAEA;;;;;;;CAOC,GACD,OAAO,SAASU,uBACdpD,KAAc,EACd,gEAAgE;AAChEmC,YAAwC;IAExCrC,aACEE,OACA0C,sBACA,qCACAP;AAEJ;AAEA;;;;;CAKC,GACD,OAAO,SAASkB,eAAerD,KAAc;IAC3C,OAAOd,GAAGc,OAAOqB;AACnB;AAEA;;;;;;;CAOC,GACD,OAAO,SAASiC,qBACdtD,KAAc,EACd,gEAAgE;AAChEmC,YAAwC;IAExCrC,aACEE,OACAqB,oBACA,0BACAc;AAEJ;AAQA;;;;;;;;;;;;;;;;;;;;;;CAsBC,GACD,OAAO,SAASoB,sBAAsBC,OAAiC;IACrE,MAAM,EAAEC,iBAAiB,EAAEC,eAAe,EAAEC,UAAU,EAAE,GAAG;QACzDF,mBAAmB;QACnBC,iBAAiB;QACjBC,YAAY;QACZ,GAAGH,OAAO;IACZ;IAEA;;;;;;GAMC,GACD,MAAMI,mBAAmB,CAAChC;QACxB,OAAOiC,QACL,AAAC,OAAOjC,OAAO,YAAa8B,CAAAA,mBAAmBzD,OAAO6D,SAAS,CAAClC,GAAE,KAC/D,OAAOA,OAAO,YAAa6B,CAAAA,qBAAqB7B,GAAGmC,MAAM,GAAG,CAAA,KAC5DJ,cAAc/B,OAAO;IAE5B;IAEA,OAAOgC;AACT"} +\ No newline at end of file ++{"version":3,"sources":["../../src/json.ts"],"sourcesContent":["import type { Infer, Struct } from 'superstruct';\nimport {\n any,\n array,\n boolean,\n coerce,\n create,\n define,\n integer,\n is,\n lazy,\n literal,\n nullable,\n number,\n object,\n optional,\n record,\n string,\n union,\n unknown,\n} from 'superstruct';\n\nimport type { AssertionErrorConstructor } from './assert';\nimport { assertStruct } from './assert';\n\n/**\n * Any JSON-compatible value.\n */\nexport type Json =\n | null\n | boolean\n | number\n | string\n | Json[]\n | { [prop: string]: Json };\n\n/**\n * A struct to check if the given value is finite number. Superstruct's\n * `number()` struct does not check if the value is finite.\n *\n * @returns A struct to check if the given value is finite number.\n */\nconst finiteNumber = () =>\n define('finite number', (value) => {\n return is(value, number()) && Number.isFinite(value);\n });\n\n/**\n * A struct to check if the given value is a valid JSON-serializable value.\n *\n * Note that this struct is unsafe. For safe validation, use {@link JsonStruct}.\n */\n// We cannot infer the type of the struct, because it is recursive.\nexport const UnsafeJsonStruct: Struct = union([\n literal(null),\n boolean(),\n finiteNumber(),\n string(),\n array(lazy(() => UnsafeJsonStruct)),\n record(\n string(),\n lazy(() => UnsafeJsonStruct),\n ),\n]);\n\n/**\n * A struct to check if the given value is a valid JSON-serializable value.\n *\n * This struct sanitizes the value before validating it, so that it is safe to\n * use with untrusted input.\n */\nexport const JsonStruct = coerce(UnsafeJsonStruct, any(), (value) => {\n assertStruct(value, UnsafeJsonStruct);\n return JSON.parse(\n JSON.stringify(value, (propKey, propValue) => {\n // Strip __proto__ and constructor properties to prevent prototype pollution.\n if (propKey === '__proto__' || propKey === 'constructor') {\n return undefined;\n }\n return propValue;\n }),\n );\n});\n\n/**\n * Check if the given value is a valid {@link Json} value, i.e., a value that is\n * serializable to JSON.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid {@link Json} value.\n */\nexport function isValidJson(value: unknown): value is Json {\n try {\n getSafeJson(value);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Validate and return sanitized JSON.\n *\n * Note:\n * This function uses sanitized JsonStruct for validation\n * that applies stringify and then parse of a value provided\n * to ensure that there are no getters which can have side effects\n * that can cause security issues.\n *\n * @param value - JSON structure to be processed.\n * @returns Sanitized JSON structure.\n */\nexport function getSafeJson(value: unknown): Type {\n return create(value, JsonStruct) as Type;\n}\n\n/**\n * Get the size of a JSON value in bytes. This also validates the value.\n *\n * @param value - The JSON value to get the size of.\n * @returns The size of the JSON value in bytes.\n */\nexport function getJsonSize(value: unknown): number {\n assertStruct(value, JsonStruct, 'Invalid JSON value');\n\n const json = JSON.stringify(value);\n return new TextEncoder().encode(json).byteLength;\n}\n\n/**\n * The string '2.0'.\n */\nexport const jsonrpc2 = '2.0' as const;\nexport const JsonRpcVersionStruct = literal(jsonrpc2);\n\n/**\n * A String specifying the version of the JSON-RPC protocol.\n * MUST be exactly \"2.0\".\n */\nexport type JsonRpcVersion2 = typeof jsonrpc2;\n\nexport const JsonRpcIdStruct = nullable(union([number(), string()]));\n\n/**\n * An identifier established by the Client that MUST contain a String, Number,\n * or NULL value if included. If it is not included it is assumed to be a\n * notification. The value SHOULD normally not be Null and Numbers SHOULD\n * NOT contain fractional parts.\n */\nexport type JsonRpcId = Infer;\n\nexport const JsonRpcErrorStruct = object({\n code: integer(),\n message: string(),\n data: optional(JsonStruct),\n stack: optional(string()),\n});\n\n/**\n * Mark a certain key of a type as optional.\n */\nexport type OptionalField<\n Type extends Record,\n Key extends keyof Type,\n> = Omit & Partial>;\n\n/**\n * A JSON-RPC error object.\n *\n * Note that TypeScript infers `unknown | undefined` as `unknown`, meaning that\n * the `data` field is not optional. To make it optional, we use the\n * `OptionalField` helper, to explicitly make it optional.\n */\nexport type JsonRpcError = OptionalField<\n Infer,\n 'data'\n>;\n\nexport const JsonRpcParamsStruct: Struct, null> =\n union([record(string(), JsonStruct), array(JsonStruct)]);\n\nexport type JsonRpcParams = Json[] | Record;\n\nexport const JsonRpcRequestStruct = object({\n id: JsonRpcIdStruct,\n jsonrpc: JsonRpcVersionStruct,\n method: string(),\n params: optional(JsonRpcParamsStruct),\n});\n\nexport type InferWithParams<\n Type extends Struct,\n Params extends JsonRpcParams,\n> = Omit, 'params'> & {\n params?: Exclude;\n};\n\n/**\n * A JSON-RPC request object.\n */\nexport type JsonRpcRequest =\n InferWithParams;\n\nexport const JsonRpcNotificationStruct = object({\n jsonrpc: JsonRpcVersionStruct,\n method: string(),\n params: optional(JsonRpcParamsStruct),\n});\n\n/**\n * A JSON-RPC notification object.\n */\nexport type JsonRpcNotification =\n InferWithParams;\n\n/**\n * Check if the given value is a valid {@link JsonRpcNotification} object.\n *\n * @param value - The value to check.\n * @returns Whether the given value is a valid {@link JsonRpcNotification}\n * object.\n */\nexport function isJsonRpcNotification(\n value: unknown,\n): value is JsonRpcNotification {\n return is(value, JsonRpcNotificationStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcNotification} object.\n *\n * @param value - The value to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcNotification} object.\n */\nexport function assertIsJsonRpcNotification(\n value: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcNotification {\n assertStruct(\n value,\n JsonRpcNotificationStruct,\n 'Invalid JSON-RPC notification',\n ErrorWrapper,\n );\n}\n\n/**\n * Check if the given value is a valid {@link JsonRpcRequest} object.\n *\n * @param value - The value to check.\n * @returns Whether the given value is a valid {@link JsonRpcRequest} object.\n */\nexport function isJsonRpcRequest(value: unknown): value is JsonRpcRequest {\n return is(value, JsonRpcRequestStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcRequest} object.\n *\n * @param value - The JSON-RPC request or notification to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcRequest} object.\n */\nexport function assertIsJsonRpcRequest(\n value: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcRequest {\n assertStruct(\n value,\n JsonRpcRequestStruct,\n 'Invalid JSON-RPC request',\n ErrorWrapper,\n );\n}\n\nexport const PendingJsonRpcResponseStruct = object({\n id: JsonRpcIdStruct,\n jsonrpc: JsonRpcVersionStruct,\n result: optional(unknown()),\n error: optional(JsonRpcErrorStruct),\n});\n\n/**\n * A JSON-RPC response object that has not yet been resolved.\n */\nexport type PendingJsonRpcResponse = Omit<\n Infer,\n 'result'\n> & {\n result?: Result;\n};\n\nexport const JsonRpcSuccessStruct = object({\n id: JsonRpcIdStruct,\n jsonrpc: JsonRpcVersionStruct,\n result: JsonStruct,\n});\n\n/**\n * A successful JSON-RPC response object.\n */\nexport type JsonRpcSuccess = Omit<\n Infer,\n 'result'\n> & {\n result: Result;\n};\n\nexport const JsonRpcFailureStruct = object({\n id: JsonRpcIdStruct,\n jsonrpc: JsonRpcVersionStruct,\n error: JsonRpcErrorStruct as Struct,\n});\n\n/**\n * A failed JSON-RPC response object.\n */\nexport type JsonRpcFailure = Infer;\n\nexport const JsonRpcResponseStruct = union([\n JsonRpcSuccessStruct,\n JsonRpcFailureStruct,\n]);\n\n/**\n * A JSON-RPC response object. Must be checked to determine whether it's a\n * success or failure.\n *\n * @template Result - The type of the result.\n */\nexport type JsonRpcResponse =\n | JsonRpcSuccess\n | JsonRpcFailure;\n\n/**\n * Type guard to check whether specified JSON-RPC response is a\n * {@link PendingJsonRpcResponse}.\n *\n * @param response - The JSON-RPC response to check.\n * @returns Whether the specified JSON-RPC response is pending.\n */\nexport function isPendingJsonRpcResponse(\n response: unknown,\n): response is PendingJsonRpcResponse {\n return is(response, PendingJsonRpcResponseStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link PendingJsonRpcResponse} object.\n *\n * @param response - The JSON-RPC response to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link PendingJsonRpcResponse}\n * object.\n */\nexport function assertIsPendingJsonRpcResponse(\n response: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts response is PendingJsonRpcResponse {\n assertStruct(\n response,\n PendingJsonRpcResponseStruct,\n 'Invalid pending JSON-RPC response',\n ErrorWrapper,\n );\n}\n\n/**\n * Type guard to check if a value is a {@link JsonRpcResponse}.\n *\n * @param response - The object to check.\n * @returns Whether the object is a JsonRpcResponse.\n */\nexport function isJsonRpcResponse(\n response: unknown,\n): response is JsonRpcResponse {\n return is(response, JsonRpcResponseStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcResponse} object.\n *\n * @param value - The value to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcResponse} object.\n */\nexport function assertIsJsonRpcResponse(\n value: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcResponse {\n assertStruct(\n value,\n JsonRpcResponseStruct,\n 'Invalid JSON-RPC response',\n ErrorWrapper,\n );\n}\n\n/**\n * Check if the given value is a valid {@link JsonRpcSuccess} object.\n *\n * @param value - The value to check.\n * @returns Whether the given value is a valid {@link JsonRpcSuccess} object.\n */\nexport function isJsonRpcSuccess(\n value: unknown,\n): value is JsonRpcSuccess {\n return is(value, JsonRpcSuccessStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcSuccess} object.\n *\n * @param value - The value to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcSuccess} object.\n */\nexport function assertIsJsonRpcSuccess(\n value: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcSuccess {\n assertStruct(\n value,\n JsonRpcSuccessStruct,\n 'Invalid JSON-RPC success response',\n ErrorWrapper,\n );\n}\n\n/**\n * Check if the given value is a valid {@link JsonRpcFailure} object.\n *\n * @param value - The value to check.\n * @returns Whether the given value is a valid {@link JsonRpcFailure} object.\n */\nexport function isJsonRpcFailure(value: unknown): value is JsonRpcFailure {\n return is(value, JsonRpcFailureStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcFailure} object.\n *\n * @param value - The value to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcFailure} object.\n */\nexport function assertIsJsonRpcFailure(\n value: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcFailure {\n assertStruct(\n value,\n JsonRpcFailureStruct,\n 'Invalid JSON-RPC failure response',\n ErrorWrapper,\n );\n}\n\n/**\n * Check if the given value is a valid {@link JsonRpcError} object.\n *\n * @param value - The value to check.\n * @returns Whether the given value is a valid {@link JsonRpcError} object.\n */\nexport function isJsonRpcError(value: unknown): value is JsonRpcError {\n return is(value, JsonRpcErrorStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcError} object.\n *\n * @param value - The value to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcError} object.\n */\nexport function assertIsJsonRpcError(\n value: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcError {\n assertStruct(\n value,\n JsonRpcErrorStruct,\n 'Invalid JSON-RPC error',\n ErrorWrapper,\n );\n}\n\ntype JsonRpcValidatorOptions = {\n permitEmptyString?: boolean;\n permitFractions?: boolean;\n permitNull?: boolean;\n};\n\n/**\n * Gets a function for validating JSON-RPC request / response `id` values.\n *\n * By manipulating the options of this factory, you can control the behavior\n * of the resulting validator for some edge cases. This is useful because e.g.\n * `null` should sometimes but not always be permitted.\n *\n * Note that the empty string (`''`) is always permitted by the JSON-RPC\n * specification, but that kind of sucks and you may want to forbid it in some\n * instances anyway.\n *\n * For more details, see the\n * [JSON-RPC Specification](https://www.jsonrpc.org/specification).\n *\n * @param options - An options object.\n * @param options.permitEmptyString - Whether the empty string (i.e. `''`)\n * should be treated as a valid ID. Default: `true`\n * @param options.permitFractions - Whether fractional numbers (e.g. `1.2`)\n * should be treated as valid IDs. Default: `false`\n * @param options.permitNull - Whether `null` should be treated as a valid ID.\n * Default: `true`\n * @returns The JSON-RPC ID validator function.\n */\nexport function getJsonRpcIdValidator(options?: JsonRpcValidatorOptions) {\n const { permitEmptyString, permitFractions, permitNull } = {\n permitEmptyString: true,\n permitFractions: false,\n permitNull: true,\n ...options,\n };\n\n /**\n * Type guard for {@link JsonRpcId}.\n *\n * @param id - The JSON-RPC ID value to check.\n * @returns Whether the given ID is valid per the options given to the\n * factory.\n */\n const isValidJsonRpcId = (id: unknown): id is JsonRpcId => {\n return Boolean(\n (typeof id === 'number' && (permitFractions || Number.isInteger(id))) ||\n (typeof id === 'string' && (permitEmptyString || id.length > 0)) ||\n (permitNull && id === null),\n );\n };\n\n return isValidJsonRpcId;\n}\n"],"names":["any","array","boolean","coerce","create","define","integer","is","lazy","literal","nullable","number","object","optional","record","string","union","unknown","assertStruct","finiteNumber","value","Number","isFinite","UnsafeJsonStruct","JsonStruct","JSON","parse","stringify","propKey","propValue","undefined","isValidJson","getSafeJson","getJsonSize","json","TextEncoder","encode","byteLength","jsonrpc2","JsonRpcVersionStruct","JsonRpcIdStruct","JsonRpcErrorStruct","code","message","data","stack","JsonRpcParamsStruct","JsonRpcRequestStruct","id","jsonrpc","method","params","JsonRpcNotificationStruct","isJsonRpcNotification","assertIsJsonRpcNotification","ErrorWrapper","isJsonRpcRequest","assertIsJsonRpcRequest","PendingJsonRpcResponseStruct","result","error","JsonRpcSuccessStruct","JsonRpcFailureStruct","JsonRpcResponseStruct","isPendingJsonRpcResponse","response","assertIsPendingJsonRpcResponse","isJsonRpcResponse","assertIsJsonRpcResponse","isJsonRpcSuccess","assertIsJsonRpcSuccess","isJsonRpcFailure","assertIsJsonRpcFailure","isJsonRpcError","assertIsJsonRpcError","getJsonRpcIdValidator","options","permitEmptyString","permitFractions","permitNull","isValidJsonRpcId","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O,SAASoB,sBAAsBC,OAAiC;IACrE,MAAM,EAAEC,iBAAiB,EAAEC,eAAe,EAAEC,UAAU,EAAE,GAAG;QACzDF,mBAAmB;QACnBC,iBAAiB;QACjBC,YAAY;QACZ,GAAGH,OAAO;IACZ;IAEA;;;;;;GAMC,GACD,MAAMI,mBAAmB,CAAChC;QACxB,OAAOiC,QACL,AAAC,OAAOjC,OAAO,YAAa8B,CAAAA,mBAAmBzD,OAAO6D,SAAS,CAAClC,GAAE,KAC/D,OAAOA,OAAO,YAAa6B,CAAAA,qBAAqB7B,GAAGmC,MAAM,GAAG,CAAA,KAC5DJ,cAAc/B,OAAO;IAE5B;IAEA,OAAOgC;AACT"} +\ No newline at end of file +diff --git a/dist/types/json.d.ts b/dist/types/json.d.ts +index 1533dcbb925903367f6cf082a4a54d5aa306caf9..ee9710954be90a7c6402b7510f481c7dfd5f57fb 100644 +--- a/dist/types/json.d.ts ++++ b/dist/types/json.d.ts +@@ -94,18 +94,16 @@ export declare const JsonRpcRequestStruct: Struct<{ + id: string | number | null; + method: string; + jsonrpc: "2.0"; +- params: Json[] | Record; ++ params?: Json[] | Record | undefined; + }, { + id: Struct; + jsonrpc: Struct<"2.0", "2.0">; + method: Struct; +- params: Struct, null>; ++ params: Struct | undefined, null>; + }>; +-export declare type InferWithParams, Params extends JsonRpcParams> = Omit, 'params'> & (keyof Params extends undefined ? { +- params?: Params; +-} : { +- params: Params; +-}); ++export declare type InferWithParams, Params extends JsonRpcParams> = Omit, 'params'> & { ++ params?: Exclude; ++}; + /** + * A JSON-RPC request object. + */ +@@ -113,13 +111,12 @@ export declare type JsonRpcRequest + export declare const JsonRpcNotificationStruct: Struct<{ + method: string; + jsonrpc: "2.0"; +- params: Json[] | Record; +-}, Omit<{ +- id: Struct; ++ params?: Json[] | Record | undefined; ++}, { + jsonrpc: Struct<"2.0", "2.0">; + method: Struct; +- params: Struct, null>; +-}, "id">>; ++ params: Struct | undefined, null>; ++}>; + /** + * A JSON-RPC notification object. + */ +diff --git a/dist/types/json.d.ts.map b/dist/types/json.d.ts.map +index b8af457fd46d71f4687d6164df970f05e392966e..e641675435aca9b6146116b9aa3709a7156e49da 100644 +--- a/dist/types/json.d.ts.map ++++ b/dist/types/json.d.ts.map +@@ -1 +1 @@ +-{"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../../src/json.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAuBjD,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAG1D;;GAEG;AACH,oBAAY,IAAI,GACZ,IAAI,GACJ,OAAO,GACP,MAAM,GACN,MAAM,GACN,IAAI,EAAE,GACN;IAAE,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC;AAa7B;;;;GAIG;AAEH,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,IAAI,CAUxC,CAAC;AAEH;;;;;GAKG;AACH,eAAO,MAAM,UAAU,uBAWrB,CAAC;AAEH;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,IAAI,CAOzD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,IAAI,SAAS,IAAI,GAAG,IAAI,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAE1E;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAKlD;AAED;;GAEG;AACH,eAAO,MAAM,QAAQ,OAAiB,CAAC;AACvC,eAAO,MAAM,oBAAoB,sBAAoB,CAAC;AAEtD;;;GAGG;AACH,oBAAY,eAAe,GAAG,OAAO,QAAQ,CAAC;AAE9C,eAAO,MAAM,eAAe,sCAAwC,CAAC;AAErE;;;;;GAKG;AACH,oBAAY,SAAS,GAAG,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AAEtD,eAAO,MAAM,kBA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ClC,KAAK,EAAE,OAAO,EAEd,YAAY,CAAC,EAAE,yBAAyB,GACvC,OAAO,CAAC,KAAK,IAAI,YAAY,CAO/B;AAED,aAAK,uBAAuB,GAAG;IAC7B,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,CAAC,EAAE,uBAAuB,QAevC,OAAO,kCAStC"} +\ No newline at end of file diff --git a/package.json b/package.json index 94ae9bf..c69d0d0 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,9 @@ "test:watch": "jest --watch" }, "resolutions": { - "@metamask/rpc-errors@^5.1.1": "patch:@metamask/rpc-errors@npm%3A5.1.1#./.yarn/patches/@metamask-rpc-errors-npm-5.1.1-dc76c26803.patch" + "@metamask/rpc-errors@^5.1.1": "patch:@metamask/rpc-errors@npm%3A5.1.1#./.yarn/patches/@metamask-rpc-errors-npm-5.1.1-dc76c26803.patch", + "@metamask/utils@^5.0.0": "patch:@metamask/utils@npm%3A8.0.0#./.yarn/patches/@metamask-utils-npm-8.0.0-7a3c3a899a.patch", + "@metamask/utils@^8.0.0": "patch:@metamask/utils@npm%3A8.0.0#./.yarn/patches/@metamask-utils-npm-8.0.0-7a3c3a899a.patch" }, "dependencies": { "@metamask/rpc-errors": "^5.1.1", diff --git a/yarn.lock b/yarn.lock index e85e6cc..7a41204 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1047,22 +1047,23 @@ __metadata: languageName: node linkType: hard -"@metamask/utils@npm:^5.0.0": - version: 5.0.2 - resolution: "@metamask/utils@npm:5.0.2" +"@metamask/utils@npm:8.0.0": + version: 8.0.0 + resolution: "@metamask/utils@npm:8.0.0" dependencies: "@ethereumjs/tx": ^4.1.2 + "@noble/hashes": ^1.3.1 "@types/debug": ^4.1.7 debug: ^4.3.4 - semver: ^7.3.8 + semver: ^7.5.4 superstruct: ^1.0.3 - checksum: eca82e42911b2840deb4f32f0f215c5ffd14d22d68afbbe92d3180e920e509e310777b15eab29def3448f3535b66596ceb4c23666ec846adacc8e1bb093ff882 + checksum: 01c956b150b454f648868cb08e850822d526fcf7d33dd04e156ed06d9b2829d0bd42a766f7bcc98c7b21d4990b00c6adb0474b23515a927131a460d50237eb52 languageName: node linkType: hard -"@metamask/utils@npm:^8.0.0": +"@metamask/utils@patch:@metamask/utils@npm%3A8.0.0#./.yarn/patches/@metamask-utils-npm-8.0.0-7a3c3a899a.patch::locator=%40metamask%2Fjson-rpc-engine%40workspace%3A.": version: 8.0.0 - resolution: "@metamask/utils@npm:8.0.0" + resolution: "@metamask/utils@patch:@metamask/utils@npm%3A8.0.0#./.yarn/patches/@metamask-utils-npm-8.0.0-7a3c3a899a.patch::version=8.0.0&hash=7d6832&locator=%40metamask%2Fjson-rpc-engine%40workspace%3A." dependencies: "@ethereumjs/tx": ^4.1.2 "@noble/hashes": ^1.3.1 @@ -1070,7 +1071,7 @@ __metadata: debug: ^4.3.4 semver: ^7.5.4 superstruct: ^1.0.3 - checksum: 01c956b150b454f648868cb08e850822d526fcf7d33dd04e156ed06d9b2829d0bd42a766f7bcc98c7b21d4990b00c6adb0474b23515a927131a460d50237eb52 + checksum: fbf08a009e72f2b4e15b664ea0c43d4ce178df4a6f5f6571dc26add6d90d183a24a1927be5891b151a515e5b16acaedbf50e611ce81a5f92b518fbb26e519258 languageName: node linkType: hard