diff --git a/package.json b/package.json index 2f595f5e1..cbe9d3c87 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,6 @@ "test:watch": "jest --watch" }, "dependencies": { - "@metamask/providers": "^16.0.0", "@metamask/snaps-sdk": "^3.1.1", "@metamask/utils": "^8.3.0", "@types/uuid": "^9.0.1", diff --git a/src/KeyringSnapRpcClient.ts b/src/KeyringSnapRpcClient.ts index e1309c371..abb43e1c3 100644 --- a/src/KeyringSnapRpcClient.ts +++ b/src/KeyringSnapRpcClient.ts @@ -1,9 +1,9 @@ -import type { MetaMaskInpageProvider } from '@metamask/providers'; import type { Json } from '@metamask/utils'; import type { JsonRpcRequest } from './JsonRpcRequest'; import type { Sender } from './KeyringClient'; import { KeyringClient } from './KeyringClient'; +import type { BaseProvider } from './providers'; /** * Implementation of the `Sender` interface that can be used to send requests @@ -12,15 +12,15 @@ import { KeyringClient } from './KeyringClient'; export class SnapRpcSender implements Sender { #origin: string; - #provider: MetaMaskInpageProvider; + #provider: BaseProvider; /** * Create a new instance of `SnapRpcSender`. * * @param origin - The caller's origin. - * @param provider - The `MetaMaskInpageProvider` instance to use. + * @param provider - The provider instance to use. */ - constructor(origin: string, provider: MetaMaskInpageProvider) { + constructor(origin: string, provider: BaseProvider) { this.#origin = origin; this.#provider = provider; } @@ -51,9 +51,9 @@ export class KeyringSnapRpcClient extends KeyringClient { * Create a new instance of `KeyringSnapRpcClient`. * * @param origin - Caller's origin. - * @param provider - The `MetaMaskInpageProvider` instance to use. + * @param provider - The provider instance to use. */ - constructor(origin: string, provider: MetaMaskInpageProvider) { + constructor(origin: string, provider: BaseProvider) { super(new SnapRpcSender(origin, provider)); } } diff --git a/src/providers.ts b/src/providers.ts new file mode 100644 index 000000000..253b88420 --- /dev/null +++ b/src/providers.ts @@ -0,0 +1,28 @@ +export type Maybe = Partial | null | undefined; + +export type RequestArguments = { + /** The RPC method to request. */ + method: string; + + /** The params of the RPC method, if any. */ + params?: unknown[] | Record; +}; + +/** + * We do re-declare locally the minimum interface from @metamask/providers here. This way this avoid + * depending on it "globally" and thus ease incompatible versions (this generally clash with + * the @metamask/snaps-sdk and @metamask/keyring-api packages! + */ +export type BaseProvider = { + /** + * Submits an RPC request for the given method, with the given params. + * Resolves with the result of the method call, or rejects on error. + * + * @param args - The RPC request arguments. + * @param args.method - The RPC method name. + * @param args.params - The parameters for the RPC method. + * @returns A Promise that resolves with the result of the RPC method, + * or rejects if an error is encountered. + */ + request(args: RequestArguments): Promise>; +}; diff --git a/yarn.lock b/yarn.lock index f4b976f4c..046a5308b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1059,7 +1059,6 @@ __metadata: "@metamask/eslint-config-jest": ^12.1.0 "@metamask/eslint-config-nodejs": ^12.1.0 "@metamask/eslint-config-typescript": ^12.1.0 - "@metamask/providers": ^16.0.0 "@metamask/snaps-sdk": ^3.1.1 "@metamask/utils": ^8.3.0 "@types/jest": ^28.1.6 @@ -1121,26 +1120,6 @@ __metadata: languageName: node linkType: hard -"@metamask/providers@npm:^16.0.0": - version: 16.0.0 - resolution: "@metamask/providers@npm:16.0.0" - dependencies: - "@metamask/json-rpc-engine": ^7.3.2 - "@metamask/json-rpc-middleware-stream": ^6.0.2 - "@metamask/object-multiplex": ^2.0.0 - "@metamask/rpc-errors": ^6.2.1 - "@metamask/safe-event-emitter": ^3.0.0 - "@metamask/utils": ^8.3.0 - detect-browser: ^5.2.0 - extension-port-stream: ^3.0.0 - fast-deep-equal: ^3.1.3 - is-stream: ^2.0.0 - readable-stream: ^3.6.2 - webextension-polyfill: ^0.10.0 - checksum: cdc06796111edbf01e9aa8498170f7ffa3c68a4c0f66a629e3b0f7d37ee60eb32d83ee12f285c3d974d971c6af16a3fba531fb5733f5fa9412a18e1d3f648539 - languageName: node - linkType: hard - "@metamask/rpc-errors@npm:^6.2.1": version: 6.2.1 resolution: "@metamask/rpc-errors@npm:6.2.1"