@metamask-previews/multichain-api-middleware 4.0.3-preview-3866c0ff1 → 4.0.3-preview-e3275932a
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +0 -4
- package/dist/handlers/index.cjs +20 -0
- package/dist/handlers/index.cjs.map +1 -0
- package/dist/handlers/index.d.cts +25 -0
- package/dist/handlers/index.d.cts.map +1 -0
- package/dist/handlers/index.d.mts +25 -0
- package/dist/handlers/index.d.mts.map +1 -0
- package/dist/handlers/{index.js → index.mjs} +5 -5
- package/dist/handlers/index.mjs.map +1 -0
- package/dist/handlers/types.cjs +13 -0
- package/dist/handlers/types.cjs.map +1 -0
- package/dist/handlers/{types.d.ts → types.d.cts} +5 -5
- package/dist/handlers/types.d.cts.map +1 -0
- package/dist/handlers/types.d.mts +27 -0
- package/dist/handlers/types.d.mts.map +1 -0
- package/dist/handlers/{types.js → types.mjs} +2 -1
- package/dist/handlers/types.mjs.map +1 -0
- package/dist/handlers/wallet-createSession.cjs +179 -0
- package/dist/handlers/wallet-createSession.cjs.map +1 -0
- package/dist/handlers/{wallet-createSession.d.ts → wallet-createSession.d.cts} +9 -9
- package/dist/handlers/wallet-createSession.d.cts.map +1 -0
- package/dist/handlers/wallet-createSession.d.mts +70 -0
- package/dist/handlers/wallet-createSession.d.mts.map +1 -0
- package/dist/handlers/{wallet-createSession.js → wallet-createSession.mjs} +6 -6
- package/dist/handlers/wallet-createSession.mjs.map +1 -0
- package/dist/handlers/wallet-getSession.cjs +54 -0
- package/dist/handlers/wallet-getSession.cjs.map +1 -0
- package/dist/handlers/{wallet-getSession.d.ts → wallet-getSession.d.cts} +5 -5
- package/dist/handlers/wallet-getSession.d.cts.map +1 -0
- package/dist/handlers/wallet-getSession.d.mts +43 -0
- package/dist/handlers/wallet-getSession.d.mts.map +1 -0
- package/dist/handlers/{wallet-getSession.js → wallet-getSession.mjs} +2 -2
- package/dist/handlers/wallet-getSession.mjs.map +1 -0
- package/dist/handlers/wallet-invokeMethod.cjs +103 -0
- package/dist/handlers/wallet-invokeMethod.cjs.map +1 -0
- package/dist/handlers/{wallet-invokeMethod.d.ts → wallet-invokeMethod.d.cts} +7 -7
- package/dist/handlers/wallet-invokeMethod.d.cts.map +1 -0
- package/dist/handlers/wallet-invokeMethod.d.mts +57 -0
- package/dist/handlers/wallet-invokeMethod.d.mts.map +1 -0
- package/dist/handlers/{wallet-invokeMethod.js → wallet-invokeMethod.mjs} +4 -4
- package/dist/handlers/wallet-invokeMethod.mjs.map +1 -0
- package/dist/handlers/wallet-revokeSession.cjs +106 -0
- package/dist/handlers/wallet-revokeSession.cjs.map +1 -0
- package/dist/handlers/{wallet-revokeSession.d.ts → wallet-revokeSession.d.cts} +6 -6
- package/dist/handlers/wallet-revokeSession.d.cts.map +1 -0
- package/dist/handlers/wallet-revokeSession.d.mts +45 -0
- package/dist/handlers/wallet-revokeSession.d.mts.map +1 -0
- package/dist/handlers/{wallet-revokeSession.js → wallet-revokeSession.mjs} +5 -5
- package/dist/handlers/wallet-revokeSession.mjs.map +1 -0
- package/dist/index.cjs +14 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +7 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +7 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +6 -0
- package/dist/index.mjs.map +1 -0
- package/dist/middlewares/MultichainMiddlewareManager.cjs +110 -0
- package/dist/middlewares/MultichainMiddlewareManager.cjs.map +1 -0
- package/dist/middlewares/{MultichainMiddlewareManager.d.ts → MultichainMiddlewareManager.d.cts} +4 -4
- package/dist/middlewares/MultichainMiddlewareManager.d.cts.map +1 -0
- package/dist/middlewares/MultichainMiddlewareManager.d.mts +35 -0
- package/dist/middlewares/MultichainMiddlewareManager.d.mts.map +1 -0
- package/dist/middlewares/MultichainMiddlewareManager.mjs +106 -0
- package/dist/middlewares/MultichainMiddlewareManager.mjs.map +1 -0
- package/dist/middlewares/MultichainSubscriptionManager.cjs +118 -0
- package/dist/middlewares/MultichainSubscriptionManager.cjs.map +1 -0
- package/dist/middlewares/{MultichainSubscriptionManager.d.ts → MultichainSubscriptionManager.d.cts} +6 -6
- package/dist/middlewares/MultichainSubscriptionManager.d.cts.map +1 -0
- package/dist/middlewares/MultichainSubscriptionManager.d.mts +49 -0
- package/dist/middlewares/MultichainSubscriptionManager.d.mts.map +1 -0
- package/dist/middlewares/MultichainSubscriptionManager.mjs +118 -0
- package/dist/middlewares/MultichainSubscriptionManager.mjs.map +1 -0
- package/dist/middlewares/multichainMethodCallValidatorMiddleware.cjs +74 -0
- package/dist/middlewares/multichainMethodCallValidatorMiddleware.cjs.map +1 -0
- package/dist/middlewares/{multichainMethodCallValidatorMiddleware.d.ts → multichainMethodCallValidatorMiddleware.d.cts} +2 -2
- package/dist/middlewares/multichainMethodCallValidatorMiddleware.d.cts.map +1 -0
- package/dist/middlewares/multichainMethodCallValidatorMiddleware.d.mts +7 -0
- package/dist/middlewares/multichainMethodCallValidatorMiddleware.d.mts.map +1 -0
- package/dist/middlewares/{multichainMethodCallValidatorMiddleware.js → multichainMethodCallValidatorMiddleware.mjs} +15 -8
- package/dist/middlewares/multichainMethodCallValidatorMiddleware.mjs.map +1 -0
- package/package.json +17 -13
- package/dist/handlers/index.d.ts +0 -25
- package/dist/handlers/index.d.ts.map +0 -1
- package/dist/handlers/index.js.map +0 -1
- package/dist/handlers/types.d.ts.map +0 -1
- package/dist/handlers/types.js.map +0 -1
- package/dist/handlers/wallet-createSession.d.ts.map +0 -1
- package/dist/handlers/wallet-createSession.js.map +0 -1
- package/dist/handlers/wallet-getSession.d.ts.map +0 -1
- package/dist/handlers/wallet-getSession.js.map +0 -1
- package/dist/handlers/wallet-invokeMethod.d.ts.map +0 -1
- package/dist/handlers/wallet-invokeMethod.js.map +0 -1
- package/dist/handlers/wallet-revokeSession.d.ts.map +0 -1
- package/dist/handlers/wallet-revokeSession.js.map +0 -1
- package/dist/index.d.ts +0 -7
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -6
- package/dist/index.js.map +0 -1
- package/dist/middlewares/MultichainMiddlewareManager.d.ts.map +0 -1
- package/dist/middlewares/MultichainMiddlewareManager.js +0 -93
- package/dist/middlewares/MultichainMiddlewareManager.js.map +0 -1
- package/dist/middlewares/MultichainSubscriptionManager.d.ts.map +0 -1
- package/dist/middlewares/MultichainSubscriptionManager.js +0 -100
- package/dist/middlewares/MultichainSubscriptionManager.js.map +0 -1
- package/dist/middlewares/multichainMethodCallValidatorMiddleware.d.ts.map +0 -1
- package/dist/middlewares/multichainMethodCallValidatorMiddleware.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet-createSession.mjs","sourceRoot":"","sources":["../../src/handlers/wallet-createSession.ts"],"names":[],"mappings":"AACA,OAAO,EACL,gBAAgB,EAChB,6BAA6B,EAC7B,YAAY,EACZ,0BAA0B,EAC1B,uBAAuB,EACvB,gBAAgB,EAChB,oBAAoB,EACpB,wBAAwB,EACxB,2BAA2B,EAC3B,kCAAkC,EAClC,6BAA6B,EAC7B,0CAA0C,EAC1C,yBAAyB,EAC1B,4CAA4C;AAM7C,OAAO,EAAE,sBAAsB,EAAE,mCAAmC;AAOpE,OAAO,EAAE,aAAa,EAAE,wCAAwC;AAKhE,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,6BAA6B;AAE/D,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,kBAAkB,EACnB,wBAAwB;AAezB,MAAM,oBAAoB,GAAG,yCAAyC,CAAC;AAyBvE;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,KAAK,UAAU,yBAAyB,CACtC,GAAgD,EAChD,GAAmC,EACnC,KAAgC,EAChC,GAA6B,EAC7B,KAA+B;IAE/B,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;QAC/B,OAAO,GAAG,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,E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AAI;QAClB,2BAA2B,EAAE,IAAI;QACjC,yBAAyB,EAAE,IAAI;QAC/B,sBAAsB,EAAE,IAAI;QAC5B,yBAAyB,EAAE,IAAI;QAC/B,4BAA4B,EAAE,IAAI;QAClC,eAAe,EAAE,IAAI;QACrB,wBAAwB,EAAE,IAAI;KAC/B;CACmC,CAAC","sourcesContent":["import type { AccountsController } from '@metamask/accounts-controller';\nimport {\n Caip25CaveatType,\n Caip25EndowmentPermissionName,\n bucketScopes,\n validateAndNormalizeScopes,\n getInternalScopesObject,\n getSessionScopes,\n getSessionProperties,\n getSupportedScopeObjects,\n isKnownSessionPropertyValue,\n getCaipAccountIdsFromScopesObjects,\n getAllScopesFromScopesObjects,\n setNonSCACaipAccountIdsInCaip25CaveatValue,\n isNamespaceInScopesObject,\n} from '@metamask/chain-agnostic-permission';\nimport type {\n Caip25Authorization,\n NormalizedScopesObject,\n Caip25CaveatValue,\n} from '@metamask/chain-agnostic-permission';\nimport { isEqualCaseInsensitive } from '@metamask/controller-utils';\nimport type {\n MethodHandler,\n JsonRpcEngineEndCallback,\n JsonRpcEngineNextCallback,\n} from '@metamask/json-rpc-engine';\nimport type { NetworkController } from '@metamask/network-controller';\nimport { invalidParams } from '@metamask/permission-controller';\nimport type {\n GenericPermissionController,\n RequestedPermissions,\n} from '@metamask/permission-controller';\nimport { JsonRpcError, rpcErrors } from '@metamask/rpc-errors';\nimport type { MultichainRoutingService } from '@metamask/snaps-controllers';\nimport {\n isPlainObject,\n KnownCaipNamespace,\n parseCaipAccountId,\n} from '@metamask/utils';\nimport type {\n CaipAccountId,\n Hex,\n Json,\n JsonRpcRequest,\n PendingJsonRpcResponse,\n} from '@metamask/utils';\n\nimport type {\n GetCapabilitiesHook,\n GetNonEvmSupportedMethodsHook,\n SortAccountIdsByLastSelectedHook,\n} from './types.js';\n\nconst SOLANA_CAIP_CHAIN_ID = 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp';\n\nexport type WalletCreateSessionHooks = GetNonEvmSupportedMethodsHook &\n SortAccountIdsByLastSelectedHook &\n GetCapabilitiesHook & {\n listAccounts: AccountsController['listAccounts'];\n findNetworkClientIdByChainId: NetworkController['findNetworkClientIdByChainId'];\n requestPermissionsForOrigin: (\n requestedPermissions: RequestedPermissions,\n metadata?: Record<string, Json>,\n ) => ReturnType<GenericPermissionController['requestPermissions']>;\n isNonEvmScopeSupported: MultichainRoutingService['isSupportedScope'];\n getNonEvmAccountAddresses: MultichainRoutingService['getSupportedAccounts'];\n trackSessionCreatedEvent:\n | ((approvedCaip25CaveatValue: Caip25CaveatValue) => void)\n | null;\n };\n\ntype Params = Caip25Authorization;\n\ntype Result = {\n sessionScopes: NormalizedScopesObject;\n sessionProperties?: Record<string, Json>;\n};\n\n/**\n * Handler for the `wallet_createSession` RPC method which is responsible\n * for prompting for approval and granting a CAIP-25 permission.\n *\n * This implementation primarily deviates from the CAIP-25 handler\n * specification by treating all scopes as optional regardless of\n * if they were specified in `requiredScopes` or `optionalScopes`.\n * Additionally, provided scopes, methods, notifications, and\n * account values that are invalid/malformed are ignored rather than\n * causing an error to be returned.\n *\n * @param req - The request object.\n * @param res - The response object.\n * @param _next - The next middleware function.\n * @param end - The end function.\n * @param hooks - The hooks object.\n * @param hooks.listAccounts - The hook that returns an array of the wallet's evm accounts.\n * @param hooks.findNetworkClientIdByChainId - The hook that returns the networkClientId for a chainId.\n * @param hooks.requestPermissionsForOrigin - The hook that approves and grants requested permissions.\n * @param hooks.getNonEvmSupportedMethods - The hook that returns the supported methods for a non EVM scope.\n * @param hooks.isNonEvmScopeSupported - The hook that returns true if a non EVM scope is supported.\n * @param hooks.getNonEvmAccountAddresses - The hook that returns a list of CaipAccountIds that are supported for a CaipChainId.\n * @param hooks.sortAccountIdsByLastSelected - A function that accepts an array of CaipAccountId and returns an array of CaipAccountId sorted by last selected.\n * @param hooks.getCapabilities - A function that returns the capabilities for a given address.\n * @param hooks.trackSessionCreatedEvent - An optional hook for platform specific logic to run.\n * @returns A promise with wallet_createSession handler\n */\nasync function handleWalletCreateSession(\n req: JsonRpcRequest<Params> & { origin: string },\n res: PendingJsonRpcResponse<Result>,\n _next: JsonRpcEngineNextCallback,\n end: JsonRpcEngineEndCallback,\n hooks: WalletCreateSessionHooks,\n): Promise<void> {\n if (!isPlainObject(req.params)) {\n return end(invalidParams({ data: { request: req } }));\n }\n const { requiredScopes, optionalScopes, sessionProperties } = req.params;\n\n if (sessionProperties && Object.keys(sessionProperties).length === 0) {\n return end(new JsonRpcError(5302, 'Invalid sessionProperties requested'));\n }\n\n const filteredSessionProperties = Object.fromEntries(\n Object.entries(sessionProperties ?? {}).filter(([key]) =>\n isKnownSessionPropertyValue(key),\n ),\n );\n\n try {\n const { normalizedRequiredScopes, normalizedOptionalScopes } =\n validateAndNormalizeScopes(requiredScopes || {}, optionalScopes || {});\n\n const requiredScopesWithSupportedMethodsAndNotifications =\n getSupportedScopeObjects(normalizedRequiredScopes, {\n getNonEvmSupportedMethods: hooks.getNonEvmSupportedMethods,\n });\n const optionalScopesWithSupportedMethodsAndNotifications =\n getSupportedScopeObjects(normalizedOptionalScopes, {\n getNonEvmSupportedMethods: hooks.getNonEvmSupportedMethods,\n });\n\n const networkClientExistsForChainId = (chainId: Hex) => {\n try {\n hooks.findNetworkClientIdByChainId(chainId);\n return true;\n } catch {\n return false;\n }\n };\n\n // if solana is a requested scope but not supported, we add a promptToCreateSolanaAccount flag to request\n const isSolanaRequested =\n isNamespaceInScopesObject(\n requiredScopesWithSupportedMethodsAndNotifications,\n KnownCaipNamespace.Solana,\n ) ||\n isNamespaceInScopesObject(\n optionalScopesWithSupportedMethodsAndNotifications,\n KnownCaipNamespace.Solana,\n );\n\n let promptToCreateSolanaAccount = false;\n if (isSolanaRequested) {\n const supportedSolanaAccounts =\n hooks.getNonEvmAccountAddresses(SOLANA_CAIP_CHAIN_ID);\n promptToCreateSolanaAccount = supportedSolanaAccounts.length === 0;\n }\n\n const { supportedScopes: supportedRequiredScopes } = bucketScopes(\n requiredScopesWithSupportedMethodsAndNotifications,\n {\n isEvmChainIdSupported: networkClientExistsForChainId,\n isEvmChainIdSupportable: () => false, // intended for future usage with eip3085 scopedProperties\n getNonEvmSupportedMethods: hooks.getNonEvmSupportedMethods,\n isNonEvmScopeSupported: hooks.isNonEvmScopeSupported,\n },\n );\n\n const { supportedScopes: supportedOptionalScopes } = bucketScopes(\n optionalScopesWithSupportedMethodsAndNotifications,\n {\n isEvmChainIdSupported: networkClientExistsForChainId,\n isEvmChainIdSupportable: () => false, // intended for future usage with eip3085 scopedProperties\n getNonEvmSupportedMethods: hooks.getNonEvmSupportedMethods,\n isNonEvmScopeSupported: hooks.isNonEvmScopeSupported,\n },\n );\n\n const allRequestedAccountAddresses = getCaipAccountIdsFromScopesObjects([\n supportedRequiredScopes,\n supportedOptionalScopes,\n ]);\n\n const allSupportedRequestedCaipChainIds = getAllScopesFromScopesObjects([\n supportedRequiredScopes,\n supportedOptionalScopes,\n ]);\n\n const existingEvmAddresses = hooks\n .listAccounts()\n .map((account) => account.address);\n\n const supportedRequestedAccountAddresses =\n allRequestedAccountAddresses.filter(\n (requestedAccountAddress: CaipAccountId) => {\n const {\n address,\n chain: { namespace },\n chainId: caipChainId,\n } = parseCaipAccountId(requestedAccountAddress);\n if (namespace === KnownCaipNamespace.Eip155.toString()) {\n return existingEvmAddresses.some((existingEvmAddress) => {\n return isEqualCaseInsensitive(address, existingEvmAddress);\n });\n }\n\n // If the namespace is not eip155 (EVM) we do a case sensitive check\n return hooks\n .getNonEvmAccountAddresses(caipChainId)\n .some((existingCaipAddress) => {\n return requestedAccountAddress === existingCaipAddress;\n });\n },\n );\n\n const requestedCaip25CaveatValue = {\n requiredScopes: getInternalScopesObject(supportedRequiredScopes),\n optionalScopes: getInternalScopesObject(supportedOptionalScopes),\n isMultichainOrigin: true,\n sessionProperties: filteredSessionProperties,\n };\n\n const requestedCaip25CaveatValueWithSupportedAccounts =\n setNonSCACaipAccountIdsInCaip25CaveatValue(\n requestedCaip25CaveatValue,\n supportedRequestedAccountAddresses,\n );\n\n // if `promptToCreateSolanaAccount` is true and there are no other valid scopes requested,\n // we add a `wallet` scope to the request in order to get passed the CAIP-25 caveat validator.\n // This is very hacky but is necessary because the solana opt-in flow breaks key assumptions\n // of the CAIP-25 permission specification - namely that we can have valid requests with no scopes.\n if (allSupportedRequestedCaipChainIds.length === 0) {\n if (promptToCreateSolanaAccount) {\n requestedCaip25CaveatValueWithSupportedAccounts.optionalScopes[\n KnownCaipNamespace.Wallet\n ] = {\n accounts: [],\n };\n } else {\n // if solana is not requested and there are no supported scopes, we return an error\n return end(\n new JsonRpcError(5100, 'Requested scopes are not supported'),\n );\n }\n }\n\n const [grantedPermissions] = await hooks.requestPermissionsForOrigin(\n {\n [Caip25EndowmentPermissionName]: {\n caveats: [\n {\n type: Caip25CaveatType,\n value: requestedCaip25CaveatValueWithSupportedAccounts,\n },\n ],\n },\n },\n {\n metadata: { promptToCreateSolanaAccount },\n },\n );\n\n const approvedCaip25Permission =\n grantedPermissions[Caip25EndowmentPermissionName];\n const approvedCaip25CaveatValue = approvedCaip25Permission?.caveats?.find(\n (caveat) => caveat.type === Caip25CaveatType,\n )?.value as Caip25CaveatValue;\n if (!approvedCaip25CaveatValue) {\n throw rpcErrors.internal();\n }\n\n const sessionScopes = getSessionScopes(approvedCaip25CaveatValue, {\n getNonEvmSupportedMethods: hooks.getNonEvmSupportedMethods,\n sortAccountIdsByLastSelected: hooks.sortAccountIdsByLastSelected,\n });\n\n const approvedSessionProperties = await getSessionProperties(\n approvedCaip25CaveatValue,\n {\n getCapabilities: hooks.getCapabilities,\n },\n );\n\n hooks.trackSessionCreatedEvent?.(approvedCaip25CaveatValue);\n\n res.result = {\n sessionScopes,\n sessionProperties: approvedSessionProperties,\n };\n return end();\n } catch (err) {\n return end(err);\n }\n}\n\nexport type WalletCreateSessionHandler = MethodHandler<\n WalletCreateSessionHooks,\n never,\n Params,\n Result,\n { origin: string }\n>;\n\nexport const walletCreateSessionHandler = {\n implementation: handleWalletCreateSession,\n hookNames: {\n findNetworkClientIdByChainId: true,\n listAccounts: true,\n requestPermissionsForOrigin: true,\n getNonEvmSupportedMethods: true,\n isNonEvmScopeSupported: true,\n getNonEvmAccountAddresses: true,\n sortAccountIdsByLastSelected: true,\n getCapabilities: true,\n trackSessionCreatedEvent: true,\n },\n} satisfies WalletCreateSessionHandler;\n"]}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.walletGetSessionHandler = void 0;
|
|
4
|
+
const chain_agnostic_permission_1 = require("@metamask/chain-agnostic-permission");
|
|
5
|
+
/**
|
|
6
|
+
* Handler for the `wallet_getSession` RPC method as specified by [CAIP-312](https://chainagnostic.org/CAIPs/caip-312).
|
|
7
|
+
* The implementation below deviates from the linked spec in that it ignores the `sessionId` param entirely,
|
|
8
|
+
* and that an empty object is returned for the `sessionScopes` result rather than throwing an error if there
|
|
9
|
+
* is no active session for the origin.
|
|
10
|
+
*
|
|
11
|
+
* @param _request - The request object.
|
|
12
|
+
* @param response - The response object.
|
|
13
|
+
* @param _next - The next middleware function. Unused.
|
|
14
|
+
* @param end - The end function.
|
|
15
|
+
* @param hooks - The hooks object.
|
|
16
|
+
* @param hooks.getCaveatForOrigin - Function to retrieve a caveat for the origin.
|
|
17
|
+
* @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.
|
|
18
|
+
* @param hooks.sortAccountIdsByLastSelected - A function that accepts an array of CaipAccountId and returns an array of CaipAccountId sorted by corresponding last selected account in the wallet.
|
|
19
|
+
* @param hooks.getCapabilities - A function that returns the capabilities for a given address.
|
|
20
|
+
* @returns Nothing.
|
|
21
|
+
*/
|
|
22
|
+
async function handleWalletGetSession(_request, response, _next, end, hooks) {
|
|
23
|
+
let caveat;
|
|
24
|
+
try {
|
|
25
|
+
caveat = hooks.getCaveatForOrigin(chain_agnostic_permission_1.Caip25EndowmentPermissionName, chain_agnostic_permission_1.Caip25CaveatType);
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
// noop
|
|
29
|
+
}
|
|
30
|
+
if (!caveat) {
|
|
31
|
+
response.result = { sessionScopes: {}, sessionProperties: {} };
|
|
32
|
+
return end();
|
|
33
|
+
}
|
|
34
|
+
response.result = {
|
|
35
|
+
sessionScopes: (0, chain_agnostic_permission_1.getSessionScopes)(caveat.value, {
|
|
36
|
+
getNonEvmSupportedMethods: hooks.getNonEvmSupportedMethods,
|
|
37
|
+
sortAccountIdsByLastSelected: hooks.sortAccountIdsByLastSelected,
|
|
38
|
+
}),
|
|
39
|
+
sessionProperties: await (0, chain_agnostic_permission_1.getSessionProperties)(caveat.value, {
|
|
40
|
+
getCapabilities: hooks.getCapabilities,
|
|
41
|
+
}),
|
|
42
|
+
};
|
|
43
|
+
return end();
|
|
44
|
+
}
|
|
45
|
+
exports.walletGetSessionHandler = {
|
|
46
|
+
implementation: handleWalletGetSession,
|
|
47
|
+
hookNames: {
|
|
48
|
+
getCaveatForOrigin: true,
|
|
49
|
+
getNonEvmSupportedMethods: true,
|
|
50
|
+
sortAccountIdsByLastSelected: true,
|
|
51
|
+
getCapabilities: true,
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
//# sourceMappingURL=wallet-getSession.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet-getSession.cjs","sourceRoot":"","sources":["../../src/handlers/wallet-getSession.ts"],"names":[],"mappings":";;;AACA,mFAK6C;AA+B7C;;;;;;;;;;;;;;;;GAgBG;AACH,KAAK,UAAU,sBAAsB,CACnC,QAA6C,EAC7C,QAAwD,EACxD,KAAgC,EAChC,GAA6B,EAC7B,KAA4B;IAE5B,IAAI,MAAgC,CAAC;IACrC,IAAI,CAAC;QACH,MAAM,GAAG,KAAK,CAAC,kBAAkB,CAC/B,yDAA6B,EAC7B,4CAAgB,CACW,CAAC;IAChC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO;IACT,CAAC;IAED,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,QAAQ,CAAC,MAAM,GAAG,EAAE,aAAa,EAAE,EAAE,EAAE,iBAAiB,EAAE,EAAE,EAAE,CAAC;QAC/D,OAAO,GAAG,EAAE,CAAC;IACf,CAAC;IAED,QAAQ,CAAC,MAAM,GAAG;QAChB,aAAa,EAAE,IAAA,4CAAgB,EAAC,MAAM,CAAC,KAAK,EAAE;YAC5C,yBAAyB,EAAE,KAAK,CAAC,yBAAyB;YAC1D,4BAA4B,EAAE,KAAK,CAAC,4BAA4B;SACjE,CAAC;QACF,iBAAiB,EAAE,MAAM,IAAA,gDAAoB,EAAC,MAAM,CAAC,KAAK,EAAE;YAC1D,eAAe,EAAE,KAAK,CAAC,eAAe;SACvC,CAAC;KACH,CAAC;IACF,OAAO,GAAG,EAAE,CAAC;AACf,CAAC;AAUY,QAAA,uBAAuB,GAAG;IACrC,cAAc,EAAE,sBAAsB;IACtC,SAAS,EAAE;QACT,kBAAkB,EAAE,IAAI;QACxB,yBAAyB,EAAE,IAAI;QAC/B,4BAA4B,EAAE,IAAI;QAClC,eAAe,EAAE,IAAI;KACtB;CACgC,CAAC","sourcesContent":["import type { NormalizedScopesObject } from '@metamask/chain-agnostic-permission';\nimport {\n Caip25CaveatType,\n Caip25EndowmentPermissionName,\n getSessionProperties,\n getSessionScopes,\n} from '@metamask/chain-agnostic-permission';\nimport type {\n JsonRpcEngineEndCallback,\n JsonRpcEngineNextCallback,\n MethodHandler,\n} from '@metamask/json-rpc-engine';\nimport type {\n Json,\n JsonRpcParams,\n JsonRpcRequest,\n PendingJsonRpcResponse,\n} from '@metamask/utils';\n\nimport type {\n Caip25Caveat,\n GetCapabilitiesHook,\n GetCaveatForOriginHook,\n GetNonEvmSupportedMethodsHook,\n SortAccountIdsByLastSelectedHook,\n} from './types.js';\n\ntype WalletGetSessionResult = {\n sessionScopes: NormalizedScopesObject;\n sessionProperties: Record<string, Json>;\n};\n\nexport type WalletGetSessionHooks = GetCaveatForOriginHook &\n GetNonEvmSupportedMethodsHook &\n SortAccountIdsByLastSelectedHook &\n GetCapabilitiesHook;\n\n/**\n * Handler for the `wallet_getSession` RPC method as specified by [CAIP-312](https://chainagnostic.org/CAIPs/caip-312).\n * The implementation below deviates from the linked spec in that it ignores the `sessionId` param entirely,\n * and that an empty object is returned for the `sessionScopes` result rather than throwing an error if there\n * is no active session for the origin.\n *\n * @param _request - The request object.\n * @param response - The response object.\n * @param _next - The next middleware function. Unused.\n * @param end - The end function.\n * @param hooks - The hooks object.\n * @param hooks.getCaveatForOrigin - Function to retrieve a caveat for the origin.\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n * @param hooks.sortAccountIdsByLastSelected - A function that accepts an array of CaipAccountId and returns an array of CaipAccountId sorted by corresponding last selected account in the wallet.\n * @param hooks.getCapabilities - A function that returns the capabilities for a given address.\n * @returns Nothing.\n */\nasync function handleWalletGetSession(\n _request: JsonRpcRequest & { origin: string },\n response: PendingJsonRpcResponse<WalletGetSessionResult>,\n _next: JsonRpcEngineNextCallback,\n end: JsonRpcEngineEndCallback,\n hooks: WalletGetSessionHooks,\n) {\n let caveat: Caip25Caveat | undefined;\n try {\n caveat = hooks.getCaveatForOrigin(\n Caip25EndowmentPermissionName,\n Caip25CaveatType,\n ) as Caip25Caveat | undefined;\n } catch {\n // noop\n }\n\n if (!caveat) {\n response.result = { sessionScopes: {}, sessionProperties: {} };\n return end();\n }\n\n response.result = {\n sessionScopes: getSessionScopes(caveat.value, {\n getNonEvmSupportedMethods: hooks.getNonEvmSupportedMethods,\n sortAccountIdsByLastSelected: hooks.sortAccountIdsByLastSelected,\n }),\n sessionProperties: await getSessionProperties(caveat.value, {\n getCapabilities: hooks.getCapabilities,\n }),\n };\n return end();\n}\n\nexport type WalletGetSessionHandler = MethodHandler<\n WalletGetSessionHooks,\n never,\n JsonRpcParams,\n WalletGetSessionResult,\n { origin: string }\n>;\n\nexport const walletGetSessionHandler = {\n implementation: handleWalletGetSession,\n hookNames: {\n getCaveatForOrigin: true,\n getNonEvmSupportedMethods: true,\n sortAccountIdsByLastSelected: true,\n getCapabilities: true,\n },\n} satisfies WalletGetSessionHandler;\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { NormalizedScopesObject } from
|
|
2
|
-
import type { JsonRpcEngineEndCallback, JsonRpcEngineNextCallback, MethodHandler } from
|
|
3
|
-
import type { Json, JsonRpcParams, JsonRpcRequest, PendingJsonRpcResponse } from
|
|
4
|
-
import type { GetCapabilitiesHook, GetCaveatForOriginHook, GetNonEvmSupportedMethodsHook, SortAccountIdsByLastSelectedHook } from
|
|
1
|
+
import type { NormalizedScopesObject } from "@metamask/chain-agnostic-permission";
|
|
2
|
+
import type { JsonRpcEngineEndCallback, JsonRpcEngineNextCallback, MethodHandler } from "@metamask/json-rpc-engine";
|
|
3
|
+
import type { Json, JsonRpcParams, JsonRpcRequest, PendingJsonRpcResponse } from "@metamask/utils";
|
|
4
|
+
import type { GetCapabilitiesHook, GetCaveatForOriginHook, GetNonEvmSupportedMethodsHook, SortAccountIdsByLastSelectedHook } from "./types.cjs";
|
|
5
5
|
type WalletGetSessionResult = {
|
|
6
6
|
sessionScopes: NormalizedScopesObject;
|
|
7
7
|
sessionProperties: Record<string, Json>;
|
|
@@ -40,4 +40,4 @@ export declare const walletGetSessionHandler: {
|
|
|
40
40
|
};
|
|
41
41
|
};
|
|
42
42
|
export {};
|
|
43
|
-
//# sourceMappingURL=wallet-getSession.d.
|
|
43
|
+
//# sourceMappingURL=wallet-getSession.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet-getSession.d.cts","sourceRoot":"","sources":["../../src/handlers/wallet-getSession.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,4CAA4C;AAOlF,OAAO,KAAK,EACV,wBAAwB,EACxB,yBAAyB,EACzB,aAAa,EACd,kCAAkC;AACnC,OAAO,KAAK,EACV,IAAI,EACJ,aAAa,EACb,cAAc,EACd,sBAAsB,EACvB,wBAAwB;AAEzB,OAAO,KAAK,EAEV,mBAAmB,EACnB,sBAAsB,EACtB,6BAA6B,EAC7B,gCAAgC,EACjC,oBAAmB;AAEpB,KAAK,sBAAsB,GAAG;IAC5B,aAAa,EAAE,sBAAsB,CAAC;IACtC,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;CACzC,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG,sBAAsB,GACxD,6BAA6B,GAC7B,gCAAgC,GAChC,mBAAmB,CAAC;AAEtB;;;;;;;;;;;;;;;;GAgBG;AACH,iBAAe,sBAAsB,CACnC,QAAQ,EAAE,cAAc,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,EAC7C,QAAQ,EAAE,sBAAsB,CAAC,sBAAsB,CAAC,EACxD,KAAK,EAAE,yBAAyB,EAChC,GAAG,EAAE,wBAAwB,EAC7B,KAAK,EAAE,qBAAqB,iBA2B7B;AAED,MAAM,MAAM,uBAAuB,GAAG,aAAa,CACjD,qBAAqB,EACrB,KAAK,EACL,aAAa,EACb,sBAAsB,EACtB;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CACnB,CAAC;AAEF,eAAO,MAAM,uBAAuB;;;;;;;;CAQD,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { NormalizedScopesObject } from "@metamask/chain-agnostic-permission";
|
|
2
|
+
import type { JsonRpcEngineEndCallback, JsonRpcEngineNextCallback, MethodHandler } from "@metamask/json-rpc-engine";
|
|
3
|
+
import type { Json, JsonRpcParams, JsonRpcRequest, PendingJsonRpcResponse } from "@metamask/utils";
|
|
4
|
+
import type { GetCapabilitiesHook, GetCaveatForOriginHook, GetNonEvmSupportedMethodsHook, SortAccountIdsByLastSelectedHook } from "./types.mjs";
|
|
5
|
+
type WalletGetSessionResult = {
|
|
6
|
+
sessionScopes: NormalizedScopesObject;
|
|
7
|
+
sessionProperties: Record<string, Json>;
|
|
8
|
+
};
|
|
9
|
+
export type WalletGetSessionHooks = GetCaveatForOriginHook & GetNonEvmSupportedMethodsHook & SortAccountIdsByLastSelectedHook & GetCapabilitiesHook;
|
|
10
|
+
/**
|
|
11
|
+
* Handler for the `wallet_getSession` RPC method as specified by [CAIP-312](https://chainagnostic.org/CAIPs/caip-312).
|
|
12
|
+
* The implementation below deviates from the linked spec in that it ignores the `sessionId` param entirely,
|
|
13
|
+
* and that an empty object is returned for the `sessionScopes` result rather than throwing an error if there
|
|
14
|
+
* is no active session for the origin.
|
|
15
|
+
*
|
|
16
|
+
* @param _request - The request object.
|
|
17
|
+
* @param response - The response object.
|
|
18
|
+
* @param _next - The next middleware function. Unused.
|
|
19
|
+
* @param end - The end function.
|
|
20
|
+
* @param hooks - The hooks object.
|
|
21
|
+
* @param hooks.getCaveatForOrigin - Function to retrieve a caveat for the origin.
|
|
22
|
+
* @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.
|
|
23
|
+
* @param hooks.sortAccountIdsByLastSelected - A function that accepts an array of CaipAccountId and returns an array of CaipAccountId sorted by corresponding last selected account in the wallet.
|
|
24
|
+
* @param hooks.getCapabilities - A function that returns the capabilities for a given address.
|
|
25
|
+
* @returns Nothing.
|
|
26
|
+
*/
|
|
27
|
+
declare function handleWalletGetSession(_request: JsonRpcRequest & {
|
|
28
|
+
origin: string;
|
|
29
|
+
}, response: PendingJsonRpcResponse<WalletGetSessionResult>, _next: JsonRpcEngineNextCallback, end: JsonRpcEngineEndCallback, hooks: WalletGetSessionHooks): Promise<void>;
|
|
30
|
+
export type WalletGetSessionHandler = MethodHandler<WalletGetSessionHooks, never, JsonRpcParams, WalletGetSessionResult, {
|
|
31
|
+
origin: string;
|
|
32
|
+
}>;
|
|
33
|
+
export declare const walletGetSessionHandler: {
|
|
34
|
+
implementation: typeof handleWalletGetSession;
|
|
35
|
+
hookNames: {
|
|
36
|
+
getCaveatForOrigin: true;
|
|
37
|
+
getNonEvmSupportedMethods: true;
|
|
38
|
+
sortAccountIdsByLastSelected: true;
|
|
39
|
+
getCapabilities: true;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
export {};
|
|
43
|
+
//# sourceMappingURL=wallet-getSession.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet-getSession.d.mts","sourceRoot":"","sources":["../../src/handlers/wallet-getSession.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,4CAA4C;AAOlF,OAAO,KAAK,EACV,wBAAwB,EACxB,yBAAyB,EACzB,aAAa,EACd,kCAAkC;AACnC,OAAO,KAAK,EACV,IAAI,EACJ,aAAa,EACb,cAAc,EACd,sBAAsB,EACvB,wBAAwB;AAEzB,OAAO,KAAK,EAEV,mBAAmB,EACnB,sBAAsB,EACtB,6BAA6B,EAC7B,gCAAgC,EACjC,oBAAmB;AAEpB,KAAK,sBAAsB,GAAG;IAC5B,aAAa,EAAE,sBAAsB,CAAC;IACtC,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;CACzC,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG,sBAAsB,GACxD,6BAA6B,GAC7B,gCAAgC,GAChC,mBAAmB,CAAC;AAEtB;;;;;;;;;;;;;;;;GAgBG;AACH,iBAAe,sBAAsB,CACnC,QAAQ,EAAE,cAAc,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,EAC7C,QAAQ,EAAE,sBAAsB,CAAC,sBAAsB,CAAC,EACxD,KAAK,EAAE,yBAAyB,EAChC,GAAG,EAAE,wBAAwB,EAC7B,KAAK,EAAE,qBAAqB,iBA2B7B;AAED,MAAM,MAAM,uBAAuB,GAAG,aAAa,CACjD,qBAAqB,EACrB,KAAK,EACL,aAAa,EACb,sBAAsB,EACtB;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CACnB,CAAC;AAEF,eAAO,MAAM,uBAAuB;;;;;;;;CAQD,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Caip25CaveatType, Caip25EndowmentPermissionName, getSessionProperties, getSessionScopes
|
|
1
|
+
import { Caip25CaveatType, Caip25EndowmentPermissionName, getSessionProperties, getSessionScopes } from "@metamask/chain-agnostic-permission";
|
|
2
2
|
/**
|
|
3
3
|
* Handler for the `wallet_getSession` RPC method as specified by [CAIP-312](https://chainagnostic.org/CAIPs/caip-312).
|
|
4
4
|
* The implementation below deviates from the linked spec in that it ignores the `sessionId` param entirely,
|
|
@@ -48,4 +48,4 @@ export const walletGetSessionHandler = {
|
|
|
48
48
|
getCapabilities: true,
|
|
49
49
|
},
|
|
50
50
|
};
|
|
51
|
-
//# sourceMappingURL=wallet-getSession.
|
|
51
|
+
//# sourceMappingURL=wallet-getSession.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet-getSession.mjs","sourceRoot":"","sources":["../../src/handlers/wallet-getSession.ts"],"names":[],"mappings":"AACA,OAAO,EACL,gBAAgB,EAChB,6BAA6B,EAC7B,oBAAoB,EACpB,gBAAgB,EACjB,4CAA4C;AA+B7C;;;;;;;;;;;;;;;;GAgBG;AACH,KAAK,UAAU,sBAAsB,CACnC,QAA6C,EAC7C,QAAwD,EACxD,KAAgC,EAChC,GAA6B,EAC7B,KAA4B;IAE5B,IAAI,MAAgC,CAAC;IACrC,IAAI,CAAC;QACH,MAAM,GAAG,KAAK,CAAC,kBAAkB,CAC/B,6BAA6B,EAC7B,gBAAgB,CACW,CAAC;IAChC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO;IACT,CAAC;IAED,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,QAAQ,CAAC,MAAM,GAAG,EAAE,aAAa,EAAE,EAAE,EAAE,iBAAiB,EAAE,EAAE,EAAE,CAAC;QAC/D,OAAO,GAAG,EAAE,CAAC;IACf,CAAC;IAED,QAAQ,CAAC,MAAM,GAAG;QAChB,aAAa,EAAE,gBAAgB,CAAC,MAAM,CAAC,KAAK,EAAE;YAC5C,yBAAyB,EAAE,KAAK,CAAC,yBAAyB;YAC1D,4BAA4B,EAAE,KAAK,CAAC,4BAA4B;SACjE,CAAC;QACF,iBAAiB,EAAE,MAAM,oBAAoB,CAAC,MAAM,CAAC,KAAK,EAAE;YAC1D,eAAe,EAAE,KAAK,CAAC,eAAe;SACvC,CAAC;KACH,CAAC;IACF,OAAO,GAAG,EAAE,CAAC;AACf,CAAC;AAUD,MAAM,CAAC,MAAM,uBAAuB,GAAG;IACrC,cAAc,EAAE,sBAAsB;IACtC,SAAS,EAAE;QACT,kBAAkB,EAAE,IAAI;QACxB,yBAAyB,EAAE,IAAI;QAC/B,4BAA4B,EAAE,IAAI;QAClC,eAAe,EAAE,IAAI;KACtB;CACgC,CAAC","sourcesContent":["import type { NormalizedScopesObject } from '@metamask/chain-agnostic-permission';\nimport {\n Caip25CaveatType,\n Caip25EndowmentPermissionName,\n getSessionProperties,\n getSessionScopes,\n} from '@metamask/chain-agnostic-permission';\nimport type {\n JsonRpcEngineEndCallback,\n JsonRpcEngineNextCallback,\n MethodHandler,\n} from '@metamask/json-rpc-engine';\nimport type {\n Json,\n JsonRpcParams,\n JsonRpcRequest,\n PendingJsonRpcResponse,\n} from '@metamask/utils';\n\nimport type {\n Caip25Caveat,\n GetCapabilitiesHook,\n GetCaveatForOriginHook,\n GetNonEvmSupportedMethodsHook,\n SortAccountIdsByLastSelectedHook,\n} from './types.js';\n\ntype WalletGetSessionResult = {\n sessionScopes: NormalizedScopesObject;\n sessionProperties: Record<string, Json>;\n};\n\nexport type WalletGetSessionHooks = GetCaveatForOriginHook &\n GetNonEvmSupportedMethodsHook &\n SortAccountIdsByLastSelectedHook &\n GetCapabilitiesHook;\n\n/**\n * Handler for the `wallet_getSession` RPC method as specified by [CAIP-312](https://chainagnostic.org/CAIPs/caip-312).\n * The implementation below deviates from the linked spec in that it ignores the `sessionId` param entirely,\n * and that an empty object is returned for the `sessionScopes` result rather than throwing an error if there\n * is no active session for the origin.\n *\n * @param _request - The request object.\n * @param response - The response object.\n * @param _next - The next middleware function. Unused.\n * @param end - The end function.\n * @param hooks - The hooks object.\n * @param hooks.getCaveatForOrigin - Function to retrieve a caveat for the origin.\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n * @param hooks.sortAccountIdsByLastSelected - A function that accepts an array of CaipAccountId and returns an array of CaipAccountId sorted by corresponding last selected account in the wallet.\n * @param hooks.getCapabilities - A function that returns the capabilities for a given address.\n * @returns Nothing.\n */\nasync function handleWalletGetSession(\n _request: JsonRpcRequest & { origin: string },\n response: PendingJsonRpcResponse<WalletGetSessionResult>,\n _next: JsonRpcEngineNextCallback,\n end: JsonRpcEngineEndCallback,\n hooks: WalletGetSessionHooks,\n) {\n let caveat: Caip25Caveat | undefined;\n try {\n caveat = hooks.getCaveatForOrigin(\n Caip25EndowmentPermissionName,\n Caip25CaveatType,\n ) as Caip25Caveat | undefined;\n } catch {\n // noop\n }\n\n if (!caveat) {\n response.result = { sessionScopes: {}, sessionProperties: {} };\n return end();\n }\n\n response.result = {\n sessionScopes: getSessionScopes(caveat.value, {\n getNonEvmSupportedMethods: hooks.getNonEvmSupportedMethods,\n sortAccountIdsByLastSelected: hooks.sortAccountIdsByLastSelected,\n }),\n sessionProperties: await getSessionProperties(caveat.value, {\n getCapabilities: hooks.getCapabilities,\n }),\n };\n return end();\n}\n\nexport type WalletGetSessionHandler = MethodHandler<\n WalletGetSessionHooks,\n never,\n JsonRpcParams,\n WalletGetSessionResult,\n { origin: string }\n>;\n\nexport const walletGetSessionHandler = {\n implementation: handleWalletGetSession,\n hookNames: {\n getCaveatForOrigin: true,\n getNonEvmSupportedMethods: true,\n sortAccountIdsByLastSelected: true,\n getCapabilities: true,\n },\n} satisfies WalletGetSessionHandler;\n"]}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.walletInvokeMethodHandler = void 0;
|
|
4
|
+
const chain_agnostic_permission_1 = require("@metamask/chain-agnostic-permission");
|
|
5
|
+
const rpc_errors_1 = require("@metamask/rpc-errors");
|
|
6
|
+
const utils_1 = require("@metamask/utils");
|
|
7
|
+
/**
|
|
8
|
+
* Handler for the `wallet_invokeMethod` RPC method as specified by [CAIP-27](https://chainagnostic.org/CAIPs/caip-27).
|
|
9
|
+
* The implementation below deviates from the linked spec in that it ignores the `sessionId` param
|
|
10
|
+
* and instead uses the singular session for the origin if available.
|
|
11
|
+
*
|
|
12
|
+
* @param request - The request object.
|
|
13
|
+
* @param response - The response object. Unused.
|
|
14
|
+
* @param next - The next middleware function.
|
|
15
|
+
* @param end - The end function.
|
|
16
|
+
* @param hooks - The hooks object.
|
|
17
|
+
* @param hooks.getCaveatForOrigin - the hook for getting a caveat from a permission for an origin.
|
|
18
|
+
* @param hooks.findNetworkClientIdByChainId - the hook for finding the networkClientId for a chainId.
|
|
19
|
+
* @param hooks.getSelectedNetworkClientId - the hook for getting the current globally selected networkClientId.
|
|
20
|
+
* @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.
|
|
21
|
+
* @param hooks.sortAccountIdsByLastSelected - A function that sorts accounts by their last selected order.
|
|
22
|
+
* @param hooks.handleNonEvmRequestForOrigin - A function that sends a request to the MultichainRouter for processing.
|
|
23
|
+
* @returns Nothing.
|
|
24
|
+
*/
|
|
25
|
+
async function handleWalletInvokeMethod(request, response, next, end, hooks) {
|
|
26
|
+
if (!(0, utils_1.isObject)(request.params)) {
|
|
27
|
+
return end(rpc_errors_1.rpcErrors.invalidParams({ data: { request } }));
|
|
28
|
+
}
|
|
29
|
+
const { scope, request: wrappedRequest } = request.params;
|
|
30
|
+
(0, chain_agnostic_permission_1.assertIsInternalScopeString)(scope);
|
|
31
|
+
let caveat;
|
|
32
|
+
try {
|
|
33
|
+
caveat = hooks.getCaveatForOrigin(chain_agnostic_permission_1.Caip25EndowmentPermissionName, chain_agnostic_permission_1.Caip25CaveatType);
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
// noop
|
|
37
|
+
}
|
|
38
|
+
if (!caveat) {
|
|
39
|
+
return end(rpc_errors_1.providerErrors.unauthorized());
|
|
40
|
+
}
|
|
41
|
+
const scopeObject = (0, chain_agnostic_permission_1.getSessionScopes)(caveat.value, {
|
|
42
|
+
getNonEvmSupportedMethods: hooks.getNonEvmSupportedMethods,
|
|
43
|
+
sortAccountIdsByLastSelected: hooks.sortAccountIdsByLastSelected,
|
|
44
|
+
})[scope];
|
|
45
|
+
if (!scopeObject?.methods?.includes(wrappedRequest.method)) {
|
|
46
|
+
return end(rpc_errors_1.providerErrors.unauthorized());
|
|
47
|
+
}
|
|
48
|
+
const { namespace, reference } = (0, chain_agnostic_permission_1.parseScopeString)(scope);
|
|
49
|
+
const isEvmRequest = (namespace === utils_1.KnownCaipNamespace.Wallet &&
|
|
50
|
+
(!reference || reference === utils_1.KnownCaipNamespace.Eip155)) ||
|
|
51
|
+
namespace === utils_1.KnownCaipNamespace.Eip155;
|
|
52
|
+
const unwrappedRequest = {
|
|
53
|
+
...request,
|
|
54
|
+
scope,
|
|
55
|
+
method: wrappedRequest.method,
|
|
56
|
+
params: wrappedRequest.params,
|
|
57
|
+
};
|
|
58
|
+
if (isEvmRequest) {
|
|
59
|
+
let networkClientId;
|
|
60
|
+
if (namespace === utils_1.KnownCaipNamespace.Wallet) {
|
|
61
|
+
networkClientId = hooks.getSelectedNetworkClientId();
|
|
62
|
+
}
|
|
63
|
+
else if (namespace === utils_1.KnownCaipNamespace.Eip155) {
|
|
64
|
+
if (reference) {
|
|
65
|
+
networkClientId = hooks.findNetworkClientIdByChainId((0, utils_1.numberToHex)(parseInt(reference, 10)));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (!networkClientId) {
|
|
69
|
+
console.error('failed to resolve network client for wallet_invokeMethod', request);
|
|
70
|
+
return end(rpc_errors_1.rpcErrors.internal());
|
|
71
|
+
}
|
|
72
|
+
Object.assign(request, {
|
|
73
|
+
...unwrappedRequest,
|
|
74
|
+
networkClientId,
|
|
75
|
+
});
|
|
76
|
+
return next();
|
|
77
|
+
}
|
|
78
|
+
try {
|
|
79
|
+
response.result = await hooks.handleNonEvmRequestForOrigin({
|
|
80
|
+
connectedAddresses: scopeObject.accounts,
|
|
81
|
+
// Type assertion: We know that scope is not "wallet" by now because it
|
|
82
|
+
// is already being handled above.
|
|
83
|
+
scope: scope,
|
|
84
|
+
request: unwrappedRequest,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
catch (err) {
|
|
88
|
+
return end(err);
|
|
89
|
+
}
|
|
90
|
+
return end();
|
|
91
|
+
}
|
|
92
|
+
exports.walletInvokeMethodHandler = {
|
|
93
|
+
implementation: handleWalletInvokeMethod,
|
|
94
|
+
hookNames: {
|
|
95
|
+
getCaveatForOrigin: true,
|
|
96
|
+
findNetworkClientIdByChainId: true,
|
|
97
|
+
getSelectedNetworkClientId: true,
|
|
98
|
+
getNonEvmSupportedMethods: true,
|
|
99
|
+
sortAccountIdsByLastSelected: true,
|
|
100
|
+
handleNonEvmRequestForOrigin: true,
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
//# sourceMappingURL=wallet-invokeMethod.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet-invokeMethod.cjs","sourceRoot":"","sources":["../../src/handlers/wallet-invokeMethod.ts"],"names":[],"mappings":";;;AACA,mFAM6C;AAU7C,qDAAiE;AAEjE,2CAA4E;AAsC5E;;;;;;;;;;;;;;;;;GAiBG;AACH,KAAK,UAAU,wBAAwB,CACrC,OAAkC,EAClC,QAAsC,EACtC,IAA+B,EAC/B,GAA6B,EAC7B,KAA8B;IAE9B,IAAI,CAAC,IAAA,gBAAQ,EAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAC9B,OAAO,G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,IAAI;QAClC,0BAA0B,EAAE,IAAI;QAChC,yBAAyB,EAAE,IAAI;QAC/B,4BAA4B,EAAE,IAAI;QAClC,4BAA4B,EAAE,IAAI;KACnC;CACkC,CAAC","sourcesContent":["import type { ExternalScopeString } from '@metamask/chain-agnostic-permission';\nimport {\n Caip25CaveatType,\n Caip25EndowmentPermissionName,\n assertIsInternalScopeString,\n getSessionScopes,\n parseScopeString,\n} from '@metamask/chain-agnostic-permission';\nimport type {\n JsonRpcEngineEndCallback,\n JsonRpcEngineNextCallback,\n MethodHandler,\n} from '@metamask/json-rpc-engine';\nimport type {\n NetworkClientId,\n NetworkController,\n} from '@metamask/network-controller';\nimport { providerErrors, rpcErrors } from '@metamask/rpc-errors';\nimport type { MultichainRoutingService } from '@metamask/snaps-controllers';\nimport { isObject, KnownCaipNamespace, numberToHex } from '@metamask/utils';\nimport type {\n CaipAccountId,\n CaipChainId,\n Json,\n JsonRpcRequest,\n PendingJsonRpcResponse,\n} from '@metamask/utils';\n\nimport type {\n Caip25Caveat,\n GetCaveatForOriginHook,\n GetNonEvmSupportedMethodsHook,\n SortAccountIdsByLastSelectedHook,\n} from './types.js';\n\nexport type WalletInvokeMethodParams = {\n scope: ExternalScopeString;\n request: Pick<JsonRpcRequest, 'method' | 'params'>;\n};\n\nexport type WalletInvokeMethodRequest =\n JsonRpcRequest<WalletInvokeMethodParams> & {\n origin: string;\n };\n\nexport type WalletInvokeMethodHooks = GetCaveatForOriginHook &\n GetNonEvmSupportedMethodsHook &\n SortAccountIdsByLastSelectedHook & {\n findNetworkClientIdByChainId: NetworkController['findNetworkClientIdByChainId'];\n getSelectedNetworkClientId: () => NetworkClientId;\n handleNonEvmRequestForOrigin: (params: {\n connectedAddresses: CaipAccountId[];\n scope: CaipChainId;\n request: JsonRpcRequest;\n }) => ReturnType<MultichainRoutingService['handleRequest']>;\n };\n\n/**\n * Handler for the `wallet_invokeMethod` RPC method as specified by [CAIP-27](https://chainagnostic.org/CAIPs/caip-27).\n * The implementation below deviates from the linked spec in that it ignores the `sessionId` param\n * and instead uses the singular session for the origin if available.\n *\n * @param request - The request object.\n * @param response - The response object. Unused.\n * @param next - The next middleware function.\n * @param end - The end function.\n * @param hooks - The hooks object.\n * @param hooks.getCaveatForOrigin - the hook for getting a caveat from a permission for an origin.\n * @param hooks.findNetworkClientIdByChainId - the hook for finding the networkClientId for a chainId.\n * @param hooks.getSelectedNetworkClientId - the hook for getting the current globally selected networkClientId.\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n * @param hooks.sortAccountIdsByLastSelected - A function that sorts accounts by their last selected order.\n * @param hooks.handleNonEvmRequestForOrigin - A function that sends a request to the MultichainRouter for processing.\n * @returns Nothing.\n */\nasync function handleWalletInvokeMethod(\n request: WalletInvokeMethodRequest,\n response: PendingJsonRpcResponse<Json>,\n next: JsonRpcEngineNextCallback,\n end: JsonRpcEngineEndCallback,\n hooks: WalletInvokeMethodHooks,\n) {\n if (!isObject(request.params)) {\n return end(rpcErrors.invalidParams({ data: { request } }));\n }\n\n const { scope, request: wrappedRequest } = request.params;\n assertIsInternalScopeString(scope);\n\n let caveat: Caip25Caveat | undefined;\n try {\n caveat = hooks.getCaveatForOrigin(\n Caip25EndowmentPermissionName,\n Caip25CaveatType,\n ) as Caip25Caveat | undefined;\n } catch {\n // noop\n }\n if (!caveat) {\n return end(providerErrors.unauthorized());\n }\n\n const scopeObject = getSessionScopes(caveat.value, {\n getNonEvmSupportedMethods: hooks.getNonEvmSupportedMethods,\n sortAccountIdsByLastSelected: hooks.sortAccountIdsByLastSelected,\n })[scope];\n\n if (!scopeObject?.methods?.includes(wrappedRequest.method)) {\n return end(providerErrors.unauthorized());\n }\n\n const { namespace, reference } = parseScopeString(scope);\n\n const isEvmRequest =\n (namespace === KnownCaipNamespace.Wallet &&\n (!reference || reference === KnownCaipNamespace.Eip155)) ||\n namespace === KnownCaipNamespace.Eip155;\n\n const unwrappedRequest = {\n ...request,\n scope,\n method: wrappedRequest.method,\n params: wrappedRequest.params,\n };\n\n if (isEvmRequest) {\n let networkClientId;\n if (namespace === KnownCaipNamespace.Wallet) {\n networkClientId = hooks.getSelectedNetworkClientId();\n } else if (namespace === KnownCaipNamespace.Eip155) {\n if (reference) {\n networkClientId = hooks.findNetworkClientIdByChainId(\n numberToHex(parseInt(reference, 10)),\n );\n }\n }\n\n if (!networkClientId) {\n console.error(\n 'failed to resolve network client for wallet_invokeMethod',\n request,\n );\n return end(rpcErrors.internal());\n }\n\n Object.assign(request, {\n ...unwrappedRequest,\n networkClientId,\n });\n return next();\n }\n\n try {\n response.result = await hooks.handleNonEvmRequestForOrigin({\n connectedAddresses: scopeObject.accounts,\n // Type assertion: We know that scope is not \"wallet\" by now because it\n // is already being handled above.\n scope: scope as CaipChainId,\n request: unwrappedRequest,\n });\n } catch (err) {\n return end(err as Error);\n }\n return end();\n}\n\nexport type WalletInvokeMethodHandler = MethodHandler<\n WalletInvokeMethodHooks,\n never,\n WalletInvokeMethodParams,\n Json,\n { origin: string }\n>;\n\nexport const walletInvokeMethodHandler = {\n implementation: handleWalletInvokeMethod,\n hookNames: {\n getCaveatForOrigin: true,\n findNetworkClientIdByChainId: true,\n getSelectedNetworkClientId: true,\n getNonEvmSupportedMethods: true,\n sortAccountIdsByLastSelected: true,\n handleNonEvmRequestForOrigin: true,\n },\n} satisfies WalletInvokeMethodHandler;\n"]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { ExternalScopeString } from
|
|
2
|
-
import type { JsonRpcEngineEndCallback, JsonRpcEngineNextCallback, MethodHandler } from
|
|
3
|
-
import type { NetworkClientId, NetworkController } from
|
|
4
|
-
import type { MultichainRoutingService } from
|
|
5
|
-
import type { CaipAccountId, CaipChainId, Json, JsonRpcRequest, PendingJsonRpcResponse } from
|
|
6
|
-
import type { GetCaveatForOriginHook, GetNonEvmSupportedMethodsHook, SortAccountIdsByLastSelectedHook } from
|
|
1
|
+
import type { ExternalScopeString } from "@metamask/chain-agnostic-permission";
|
|
2
|
+
import type { JsonRpcEngineEndCallback, JsonRpcEngineNextCallback, MethodHandler } from "@metamask/json-rpc-engine";
|
|
3
|
+
import type { NetworkClientId, NetworkController } from "@metamask/network-controller";
|
|
4
|
+
import type { MultichainRoutingService } from "@metamask/snaps-controllers";
|
|
5
|
+
import type { CaipAccountId, CaipChainId, Json, JsonRpcRequest, PendingJsonRpcResponse } from "@metamask/utils";
|
|
6
|
+
import type { GetCaveatForOriginHook, GetNonEvmSupportedMethodsHook, SortAccountIdsByLastSelectedHook } from "./types.cjs";
|
|
7
7
|
export type WalletInvokeMethodParams = {
|
|
8
8
|
scope: ExternalScopeString;
|
|
9
9
|
request: Pick<JsonRpcRequest, 'method' | 'params'>;
|
|
@@ -54,4 +54,4 @@ export declare const walletInvokeMethodHandler: {
|
|
|
54
54
|
};
|
|
55
55
|
};
|
|
56
56
|
export {};
|
|
57
|
-
//# sourceMappingURL=wallet-invokeMethod.d.
|
|
57
|
+
//# sourceMappingURL=wallet-invokeMethod.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet-invokeMethod.d.cts","sourceRoot":"","sources":["../../src/handlers/wallet-invokeMethod.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,4CAA4C;AAQ/E,OAAO,KAAK,EACV,wBAAwB,EACxB,yBAAyB,EACzB,aAAa,EACd,kCAAkC;AACnC,OAAO,KAAK,EACV,eAAe,EACf,iBAAiB,EAClB,qCAAqC;AAEtC,OAAO,KAAK,EAAE,wBAAwB,EAAE,oCAAoC;AAE5E,OAAO,KAAK,EACV,aAAa,EACb,WAAW,EACX,IAAI,EACJ,cAAc,EACd,sBAAsB,EACvB,wBAAwB;AAEzB,OAAO,KAAK,EAEV,sBAAsB,EACtB,6BAA6B,EAC7B,gCAAgC,EACjC,oBAAmB;AAEpB,MAAM,MAAM,wBAAwB,GAAG;IACrC,KAAK,EAAE,mBAAmB,CAAC;IAC3B,OAAO,EAAE,IAAI,CAAC,cAAc,EAAE,QAAQ,GAAG,QAAQ,CAAC,CAAC;CACpD,CAAC;AAEF,MAAM,MAAM,yBAAyB,GACnC,cAAc,CAAC,wBAAwB,CAAC,GAAG;IACzC,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEJ,MAAM,MAAM,uBAAuB,GAAG,sBAAsB,GAC1D,6BAA6B,GAC7B,gCAAgC,GAAG;IACjC,4BAA4B,EAAE,iBAAiB,CAAC,8BAA8B,CAAC,CAAC;IAChF,0BAA0B,EAAE,MAAM,eAAe,CAAC;IAClD,4BAA4B,EAAE,CAAC,MAAM,EAAE;QACrC,kBAAkB,EAAE,aAAa,EAAE,CAAC;QACpC,KAAK,EAAE,WAAW,CAAC;QACnB,OAAO,EAAE,cAAc,CAAC;KACzB,KAAK,UAAU,CAAC,wBAAwB,CAAC,eAAe,CAAC,CAAC,CAAC;CAC7D,CAAC;AAEJ;;;;;;;;;;;;;;;;;GAiBG;AACH,iBAAe,wBAAwB,CACrC,OAAO,EAAE,yBAAyB,EAClC,QAAQ,EAAE,sBAAsB,CAAC,IAAI,CAAC,EACtC,IAAI,EAAE,yBAAyB,EAC/B,GAAG,EAAE,wBAAwB,EAC7B,KAAK,EAAE,uBAAuB,iBAoF/B;AAED,MAAM,MAAM,yBAAyB,GAAG,aAAa,CACnD,uBAAuB,EACvB,KAAK,EACL,wBAAwB,EACxB,IAAI,EACJ;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CACnB,CAAC;AAEF,eAAO,MAAM,yBAAyB;;;;;;;;;;CAUD,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { ExternalScopeString } from "@metamask/chain-agnostic-permission";
|
|
2
|
+
import type { JsonRpcEngineEndCallback, JsonRpcEngineNextCallback, MethodHandler } from "@metamask/json-rpc-engine";
|
|
3
|
+
import type { NetworkClientId, NetworkController } from "@metamask/network-controller";
|
|
4
|
+
import type { MultichainRoutingService } from "@metamask/snaps-controllers";
|
|
5
|
+
import type { CaipAccountId, CaipChainId, Json, JsonRpcRequest, PendingJsonRpcResponse } from "@metamask/utils";
|
|
6
|
+
import type { GetCaveatForOriginHook, GetNonEvmSupportedMethodsHook, SortAccountIdsByLastSelectedHook } from "./types.mjs";
|
|
7
|
+
export type WalletInvokeMethodParams = {
|
|
8
|
+
scope: ExternalScopeString;
|
|
9
|
+
request: Pick<JsonRpcRequest, 'method' | 'params'>;
|
|
10
|
+
};
|
|
11
|
+
export type WalletInvokeMethodRequest = JsonRpcRequest<WalletInvokeMethodParams> & {
|
|
12
|
+
origin: string;
|
|
13
|
+
};
|
|
14
|
+
export type WalletInvokeMethodHooks = GetCaveatForOriginHook & GetNonEvmSupportedMethodsHook & SortAccountIdsByLastSelectedHook & {
|
|
15
|
+
findNetworkClientIdByChainId: NetworkController['findNetworkClientIdByChainId'];
|
|
16
|
+
getSelectedNetworkClientId: () => NetworkClientId;
|
|
17
|
+
handleNonEvmRequestForOrigin: (params: {
|
|
18
|
+
connectedAddresses: CaipAccountId[];
|
|
19
|
+
scope: CaipChainId;
|
|
20
|
+
request: JsonRpcRequest;
|
|
21
|
+
}) => ReturnType<MultichainRoutingService['handleRequest']>;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Handler for the `wallet_invokeMethod` RPC method as specified by [CAIP-27](https://chainagnostic.org/CAIPs/caip-27).
|
|
25
|
+
* The implementation below deviates from the linked spec in that it ignores the `sessionId` param
|
|
26
|
+
* and instead uses the singular session for the origin if available.
|
|
27
|
+
*
|
|
28
|
+
* @param request - The request object.
|
|
29
|
+
* @param response - The response object. Unused.
|
|
30
|
+
* @param next - The next middleware function.
|
|
31
|
+
* @param end - The end function.
|
|
32
|
+
* @param hooks - The hooks object.
|
|
33
|
+
* @param hooks.getCaveatForOrigin - the hook for getting a caveat from a permission for an origin.
|
|
34
|
+
* @param hooks.findNetworkClientIdByChainId - the hook for finding the networkClientId for a chainId.
|
|
35
|
+
* @param hooks.getSelectedNetworkClientId - the hook for getting the current globally selected networkClientId.
|
|
36
|
+
* @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.
|
|
37
|
+
* @param hooks.sortAccountIdsByLastSelected - A function that sorts accounts by their last selected order.
|
|
38
|
+
* @param hooks.handleNonEvmRequestForOrigin - A function that sends a request to the MultichainRouter for processing.
|
|
39
|
+
* @returns Nothing.
|
|
40
|
+
*/
|
|
41
|
+
declare function handleWalletInvokeMethod(request: WalletInvokeMethodRequest, response: PendingJsonRpcResponse<Json>, next: JsonRpcEngineNextCallback, end: JsonRpcEngineEndCallback, hooks: WalletInvokeMethodHooks): Promise<void>;
|
|
42
|
+
export type WalletInvokeMethodHandler = MethodHandler<WalletInvokeMethodHooks, never, WalletInvokeMethodParams, Json, {
|
|
43
|
+
origin: string;
|
|
44
|
+
}>;
|
|
45
|
+
export declare const walletInvokeMethodHandler: {
|
|
46
|
+
implementation: typeof handleWalletInvokeMethod;
|
|
47
|
+
hookNames: {
|
|
48
|
+
getCaveatForOrigin: true;
|
|
49
|
+
findNetworkClientIdByChainId: true;
|
|
50
|
+
getSelectedNetworkClientId: true;
|
|
51
|
+
getNonEvmSupportedMethods: true;
|
|
52
|
+
sortAccountIdsByLastSelected: true;
|
|
53
|
+
handleNonEvmRequestForOrigin: true;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
export {};
|
|
57
|
+
//# sourceMappingURL=wallet-invokeMethod.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet-invokeMethod.d.mts","sourceRoot":"","sources":["../../src/handlers/wallet-invokeMethod.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,4CAA4C;AAQ/E,OAAO,KAAK,EACV,wBAAwB,EACxB,yBAAyB,EACzB,aAAa,EACd,kCAAkC;AACnC,OAAO,KAAK,EACV,eAAe,EACf,iBAAiB,EAClB,qCAAqC;AAEtC,OAAO,KAAK,EAAE,wBAAwB,EAAE,o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C"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Caip25CaveatType, Caip25EndowmentPermissionName, assertIsInternalScopeString, getSessionScopes, parseScopeString
|
|
2
|
-
import { providerErrors, rpcErrors } from
|
|
3
|
-
import { isObject, KnownCaipNamespace, numberToHex } from
|
|
1
|
+
import { Caip25CaveatType, Caip25EndowmentPermissionName, assertIsInternalScopeString, getSessionScopes, parseScopeString } from "@metamask/chain-agnostic-permission";
|
|
2
|
+
import { providerErrors, rpcErrors } from "@metamask/rpc-errors";
|
|
3
|
+
import { isObject, KnownCaipNamespace, numberToHex } from "@metamask/utils";
|
|
4
4
|
/**
|
|
5
5
|
* Handler for the `wallet_invokeMethod` RPC method as specified by [CAIP-27](https://chainagnostic.org/CAIPs/caip-27).
|
|
6
6
|
* The implementation below deviates from the linked spec in that it ignores the `sessionId` param
|
|
@@ -97,4 +97,4 @@ export const walletInvokeMethodHandler = {
|
|
|
97
97
|
handleNonEvmRequestForOrigin: true,
|
|
98
98
|
},
|
|
99
99
|
};
|
|
100
|
-
//# sourceMappingURL=wallet-invokeMethod.
|
|
100
|
+
//# sourceMappingURL=wallet-invokeMethod.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet-invokeMethod.mjs","sourceRoot":"","sources":["../../src/handlers/wallet-invokeMethod.ts"],"names":[],"mappings":"AACA,OAAO,EACL,gBAAgB,EAChB,6BAA6B,EAC7B,2BAA2B,EAC3B,gBAAgB,EAChB,gBAAgB,EACjB,4CAA4C;AAU7C,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,6BAA6B;AAEjE,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,WAAW,EAAE,wBAAwB;AAsC5E;;;;;;;;;;;;;;;;;GAiBG;AACH,KAAK,UAAU,wBAAwB,CACrC,OAAkC,EAClC,QAAsC,EACtC,IAA+B,EAC/B,GAA6B,EAC7B,KAA8B;IAE9B,IAAI,CAAC,QAAQ,CAAC,OAAO,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,IAAI;QACxB,4BAA4B,EAAE,IAAI;QAClC,0BAA0B,EAAE,IAAI;QAChC,yBAAyB,EAAE,IAAI;QAC/B,4BAA4B,EAAE,IAAI;QAClC,4BAA4B,EAAE,IAAI;KACnC;CACkC,CAAC","sourcesContent":["import type { ExternalScopeString } from '@metamask/chain-agnostic-permission';\nimport {\n Caip25CaveatType,\n Caip25EndowmentPermissionName,\n assertIsInternalScopeString,\n getSessionScopes,\n parseScopeString,\n} from '@metamask/chain-agnostic-permission';\nimport type {\n JsonRpcEngineEndCallback,\n JsonRpcEngineNextCallback,\n MethodHandler,\n} from '@metamask/json-rpc-engine';\nimport type {\n NetworkClientId,\n NetworkController,\n} from '@metamask/network-controller';\nimport { providerErrors, rpcErrors } from '@metamask/rpc-errors';\nimport type { MultichainRoutingService } from '@metamask/snaps-controllers';\nimport { isObject, KnownCaipNamespace, numberToHex } from '@metamask/utils';\nimport type {\n CaipAccountId,\n CaipChainId,\n Json,\n JsonRpcRequest,\n PendingJsonRpcResponse,\n} from '@metamask/utils';\n\nimport type {\n Caip25Caveat,\n GetCaveatForOriginHook,\n GetNonEvmSupportedMethodsHook,\n SortAccountIdsByLastSelectedHook,\n} from './types.js';\n\nexport type WalletInvokeMethodParams = {\n scope: ExternalScopeString;\n request: Pick<JsonRpcRequest, 'method' | 'params'>;\n};\n\nexport type WalletInvokeMethodRequest =\n JsonRpcRequest<WalletInvokeMethodParams> & {\n origin: string;\n };\n\nexport type WalletInvokeMethodHooks = GetCaveatForOriginHook &\n GetNonEvmSupportedMethodsHook &\n SortAccountIdsByLastSelectedHook & {\n findNetworkClientIdByChainId: NetworkController['findNetworkClientIdByChainId'];\n getSelectedNetworkClientId: () => NetworkClientId;\n handleNonEvmRequestForOrigin: (params: {\n connectedAddresses: CaipAccountId[];\n scope: CaipChainId;\n request: JsonRpcRequest;\n }) => ReturnType<MultichainRoutingService['handleRequest']>;\n };\n\n/**\n * Handler for the `wallet_invokeMethod` RPC method as specified by [CAIP-27](https://chainagnostic.org/CAIPs/caip-27).\n * The implementation below deviates from the linked spec in that it ignores the `sessionId` param\n * and instead uses the singular session for the origin if available.\n *\n * @param request - The request object.\n * @param response - The response object. Unused.\n * @param next - The next middleware function.\n * @param end - The end function.\n * @param hooks - The hooks object.\n * @param hooks.getCaveatForOrigin - the hook for getting a caveat from a permission for an origin.\n * @param hooks.findNetworkClientIdByChainId - the hook for finding the networkClientId for a chainId.\n * @param hooks.getSelectedNetworkClientId - the hook for getting the current globally selected networkClientId.\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n * @param hooks.sortAccountIdsByLastSelected - A function that sorts accounts by their last selected order.\n * @param hooks.handleNonEvmRequestForOrigin - A function that sends a request to the MultichainRouter for processing.\n * @returns Nothing.\n */\nasync function handleWalletInvokeMethod(\n request: WalletInvokeMethodRequest,\n response: PendingJsonRpcResponse<Json>,\n next: JsonRpcEngineNextCallback,\n end: JsonRpcEngineEndCallback,\n hooks: WalletInvokeMethodHooks,\n) {\n if (!isObject(request.params)) {\n return end(rpcErrors.invalidParams({ data: { request } }));\n }\n\n const { scope, request: wrappedRequest } = request.params;\n assertIsInternalScopeString(scope);\n\n let caveat: Caip25Caveat | undefined;\n try {\n caveat = hooks.getCaveatForOrigin(\n Caip25EndowmentPermissionName,\n Caip25CaveatType,\n ) as Caip25Caveat | undefined;\n } catch {\n // noop\n }\n if (!caveat) {\n return end(providerErrors.unauthorized());\n }\n\n const scopeObject = getSessionScopes(caveat.value, {\n getNonEvmSupportedMethods: hooks.getNonEvmSupportedMethods,\n sortAccountIdsByLastSelected: hooks.sortAccountIdsByLastSelected,\n })[scope];\n\n if (!scopeObject?.methods?.includes(wrappedRequest.method)) {\n return end(providerErrors.unauthorized());\n }\n\n const { namespace, reference } = parseScopeString(scope);\n\n const isEvmRequest =\n (namespace === KnownCaipNamespace.Wallet &&\n (!reference || reference === KnownCaipNamespace.Eip155)) ||\n namespace === KnownCaipNamespace.Eip155;\n\n const unwrappedRequest = {\n ...request,\n scope,\n method: wrappedRequest.method,\n params: wrappedRequest.params,\n };\n\n if (isEvmRequest) {\n let networkClientId;\n if (namespace === KnownCaipNamespace.Wallet) {\n networkClientId = hooks.getSelectedNetworkClientId();\n } else if (namespace === KnownCaipNamespace.Eip155) {\n if (reference) {\n networkClientId = hooks.findNetworkClientIdByChainId(\n numberToHex(parseInt(reference, 10)),\n );\n }\n }\n\n if (!networkClientId) {\n console.error(\n 'failed to resolve network client for wallet_invokeMethod',\n request,\n );\n return end(rpcErrors.internal());\n }\n\n Object.assign(request, {\n ...unwrappedRequest,\n networkClientId,\n });\n return next();\n }\n\n try {\n response.result = await hooks.handleNonEvmRequestForOrigin({\n connectedAddresses: scopeObject.accounts,\n // Type assertion: We know that scope is not \"wallet\" by now because it\n // is already being handled above.\n scope: scope as CaipChainId,\n request: unwrappedRequest,\n });\n } catch (err) {\n return end(err as Error);\n }\n return end();\n}\n\nexport type WalletInvokeMethodHandler = MethodHandler<\n WalletInvokeMethodHooks,\n never,\n WalletInvokeMethodParams,\n Json,\n { origin: string }\n>;\n\nexport const walletInvokeMethodHandler = {\n implementation: handleWalletInvokeMethod,\n hookNames: {\n getCaveatForOrigin: true,\n findNetworkClientIdByChainId: true,\n getSelectedNetworkClientId: true,\n getNonEvmSupportedMethods: true,\n sortAccountIdsByLastSelected: true,\n handleNonEvmRequestForOrigin: true,\n },\n} satisfies WalletInvokeMethodHandler;\n"]}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.walletRevokeSessionHandler = void 0;
|
|
4
|
+
const chain_agnostic_permission_1 = require("@metamask/chain-agnostic-permission");
|
|
5
|
+
const permission_controller_1 = require("@metamask/permission-controller");
|
|
6
|
+
const rpc_errors_1 = require("@metamask/rpc-errors");
|
|
7
|
+
const utils_1 = require("@metamask/utils");
|
|
8
|
+
/**
|
|
9
|
+
* Check whether the given error is a permission error.
|
|
10
|
+
*
|
|
11
|
+
* @param error - The error to check.
|
|
12
|
+
* @returns Whether the error is a permission error.
|
|
13
|
+
*/
|
|
14
|
+
function isPermissionError(error) {
|
|
15
|
+
if (!(0, utils_1.isObject)(error) ||
|
|
16
|
+
!('name' in error) ||
|
|
17
|
+
typeof error.name !== 'string') {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
return [
|
|
21
|
+
permission_controller_1.UnrecognizedSubjectError.name,
|
|
22
|
+
permission_controller_1.PermissionDoesNotExistError.name,
|
|
23
|
+
].includes(error.name);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Revokes specific session scopes from an existing caveat.
|
|
27
|
+
* Fully revokes permission if no accounts remain permitted after iterating through scopes.
|
|
28
|
+
*
|
|
29
|
+
* @param scopes - Array of scope strings to remove from the caveat.
|
|
30
|
+
* @param hooks - The hooks object.
|
|
31
|
+
* @param hooks.revokePermissionForOrigin - The hook for revoking a permission for an origin function.
|
|
32
|
+
* @param hooks.updateCaveat - The hook used to conditionally update the caveat rather than fully revoke the permission.
|
|
33
|
+
* @param hooks.getCaveatForOrigin - The hook to fetch an existing caveat for the origin of the request.
|
|
34
|
+
*/
|
|
35
|
+
function partialRevokePermissions(scopes, hooks) {
|
|
36
|
+
const caveat = hooks.getCaveatForOrigin(chain_agnostic_permission_1.Caip25EndowmentPermissionName, chain_agnostic_permission_1.Caip25CaveatType);
|
|
37
|
+
if (!caveat) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
let updatedCaveatValue = caveat.value;
|
|
41
|
+
for (const scopeString of scopes) {
|
|
42
|
+
const result = chain_agnostic_permission_1.Caip25CaveatMutators[chain_agnostic_permission_1.Caip25CaveatType].removeScope(updatedCaveatValue, scopeString);
|
|
43
|
+
// If operation is a Noop, it means a scope was passed that was not present in the permission, so we proceed with the loop
|
|
44
|
+
if (result.operation === permission_controller_1.CaveatMutatorOperation.Noop) {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
updatedCaveatValue = result?.value ?? {
|
|
48
|
+
requiredScopes: {},
|
|
49
|
+
optionalScopes: {},
|
|
50
|
+
sessionProperties: {},
|
|
51
|
+
isMultichainOrigin: true,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
const caipAccountIds = (0, chain_agnostic_permission_1.getCaipAccountIdsFromCaip25CaveatValue)(updatedCaveatValue);
|
|
55
|
+
// We fully revoke permission if no accounts are left after scope removal loop.
|
|
56
|
+
if (!caipAccountIds.length) {
|
|
57
|
+
hooks.revokePermissionForOrigin(chain_agnostic_permission_1.Caip25EndowmentPermissionName);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
hooks.updateCaveat(chain_agnostic_permission_1.Caip25EndowmentPermissionName, chain_agnostic_permission_1.Caip25CaveatType, updatedCaveatValue);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Handler for the `wallet_revokeSession` RPC method as specified by [CAIP-285](https://chainagnostic.org/CAIPs/caip-285).
|
|
65
|
+
* The implementation below deviates from the linked spec in that it ignores the `sessionId` param
|
|
66
|
+
* and instead revokes the singular session for the origin if available. Additionally,
|
|
67
|
+
* the handler also does not return an error if there is currently no active session and instead
|
|
68
|
+
* returns true which is the same result returned if an active session was actually revoked.
|
|
69
|
+
*
|
|
70
|
+
* @param request - The JSON-RPC request object. Unused.
|
|
71
|
+
* @param response - The JSON-RPC response object.
|
|
72
|
+
* @param _next - The next middleware function. Unused.
|
|
73
|
+
* @param end - The end callback function.
|
|
74
|
+
* @param hooks - The hooks object.
|
|
75
|
+
* @param hooks.revokePermissionForOrigin - The hook for revoking a permission for an origin function.
|
|
76
|
+
* @param hooks.updateCaveat - The hook used to conditionally update the caveat rather than fully revoke the permission.
|
|
77
|
+
* @param hooks.getCaveatForOrigin - The hook to fetch an existing caveat for the origin of the request.
|
|
78
|
+
* @returns Nothing.
|
|
79
|
+
*/
|
|
80
|
+
async function handleWalletRevokeSession(request, response, _next, end, hooks) {
|
|
81
|
+
try {
|
|
82
|
+
if (request.params?.scopes?.length) {
|
|
83
|
+
partialRevokePermissions(request.params.scopes, hooks);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
hooks.revokePermissionForOrigin(chain_agnostic_permission_1.Caip25EndowmentPermissionName);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
catch (err) {
|
|
90
|
+
if (!isPermissionError(err)) {
|
|
91
|
+
console.error(err);
|
|
92
|
+
return end(rpc_errors_1.rpcErrors.internal());
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
response.result = true;
|
|
96
|
+
return end();
|
|
97
|
+
}
|
|
98
|
+
exports.walletRevokeSessionHandler = {
|
|
99
|
+
implementation: handleWalletRevokeSession,
|
|
100
|
+
hookNames: {
|
|
101
|
+
revokePermissionForOrigin: true,
|
|
102
|
+
updateCaveat: true,
|
|
103
|
+
getCaveatForOrigin: true,
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
//# sourceMappingURL=wallet-revokeSession.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet-revokeSession.cjs","sourceRoot":"","sources":["../../src/handlers/wallet-revokeSession.ts"],"names":[],"mappings":";;;AAAA,mFAK6C;AAO7C,2EAKyC;AACzC,qDAAiD;AACjD,2CAA2C;AAsB3C;;;;;GAKG;AACH,SAAS,iBAAiB,CAAC,KAAc;IACvC,IACE,CAAC,IAAA,gBAAQ,EAAC,KAAK,CAAC;QAChB,CAAC,CAAC,MAAM,IAAI,KAAK,CAAC;QAClB,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,EAC9B,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO;QACL,gDAAwB,CAAC,IAAI;QAC7B,mDAA2B,CAAC,IAAI;KACjC,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AACzB,CAAC;AAED;;;;;;;;;GASG;AACH,SAAS,wBA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AAK,CAAC,CAAC;QACzD,CAAC;aAAM,CAAC;YACN,KAAK,CAAC,yBAAyB,CAAC,yDAA6B,CAAC,CAAC;QACjE,CAAC;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,EAAE,CAAC;YAC5B,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YACnB,OAAO,GAAG,CAAC,sBAAS,CAAC,QAAQ,EAAE,CAAC,CAAC;QACnC,CAAC;IACH,CAAC;IAED,QAAQ,CAAC,MAAM,GAAG,IAAI,CAAC;IACvB,OAAO,GAAG,EAAE,CAAC;AACf,CAAC;AAUY,QAAA,0BAA0B,GAAG;IACxC,cAAc,EAAE,yBAAyB;IACzC,SAAS,EAAE;QACT,yBAAyB,EAAE,IAAI;QAC/B,YAAY,EAAE,IAAI;QAClB,kBAAkB,EAAE,IAAI;KACzB;CACmC,CAAC","sourcesContent":["import {\n Caip25CaveatMutators,\n Caip25CaveatType,\n Caip25EndowmentPermissionName,\n getCaipAccountIdsFromCaip25CaveatValue,\n} from '@metamask/chain-agnostic-permission';\nimport type { Caip25CaveatValue } from '@metamask/chain-agnostic-permission';\nimport type {\n JsonRpcEngineEndCallback,\n JsonRpcEngineNextCallback,\n MethodHandler,\n} from '@metamask/json-rpc-engine';\nimport {\n CaveatMutatorOperation,\n GenericPermissionController,\n PermissionDoesNotExistError,\n UnrecognizedSubjectError,\n} from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport { isObject } from '@metamask/utils';\nimport type {\n Json,\n JsonRpcRequest,\n PendingJsonRpcResponse,\n} from '@metamask/utils';\n\nimport type { Caip25Caveat, GetCaveatForOriginHook } from './types.js';\n\nexport type WalletRevokeSessionHooks = GetCaveatForOriginHook & {\n revokePermissionForOrigin: (\n permissionName: string,\n ) => ReturnType<GenericPermissionController['revokePermissions']>;\n updateCaveat: (\n target: string,\n caveatType: string,\n caveatValue: Caip25CaveatValue,\n ) => ReturnType<GenericPermissionController['updateCaveat']>;\n};\n\ntype WalletRevokeSessionParams = { scopes?: string[] };\n\n/**\n * Check whether the given error is a permission error.\n *\n * @param error - The error to check.\n * @returns Whether the error is a permission error.\n */\nfunction isPermissionError(error: unknown) {\n if (\n !isObject(error) ||\n !('name' in error) ||\n typeof error.name !== 'string'\n ) {\n return false;\n }\n\n return [\n UnrecognizedSubjectError.name,\n PermissionDoesNotExistError.name,\n ].includes(error.name);\n}\n\n/**\n * Revokes specific session scopes from an existing caveat.\n * Fully revokes permission if no accounts remain permitted after iterating through scopes.\n *\n * @param scopes - Array of scope strings to remove from the caveat.\n * @param hooks - The hooks object.\n * @param hooks.revokePermissionForOrigin - The hook for revoking a permission for an origin function.\n * @param hooks.updateCaveat - The hook used to conditionally update the caveat rather than fully revoke the permission.\n * @param hooks.getCaveatForOrigin - The hook to fetch an existing caveat for the origin of the request.\n */\nfunction partialRevokePermissions(\n scopes: string[],\n hooks: WalletRevokeSessionHooks,\n) {\n const caveat = hooks.getCaveatForOrigin(\n Caip25EndowmentPermissionName,\n Caip25CaveatType,\n ) as Caip25Caveat | undefined;\n if (!caveat) {\n return;\n }\n\n let updatedCaveatValue = caveat.value;\n\n for (const scopeString of scopes) {\n const result = Caip25CaveatMutators[Caip25CaveatType].removeScope(\n updatedCaveatValue,\n scopeString,\n );\n\n // If operation is a Noop, it means a scope was passed that was not present in the permission, so we proceed with the loop\n if (result.operation === CaveatMutatorOperation.Noop) {\n continue;\n }\n\n updatedCaveatValue = result?.value ?? {\n requiredScopes: {},\n optionalScopes: {},\n sessionProperties: {},\n isMultichainOrigin: true,\n };\n }\n\n const caipAccountIds =\n getCaipAccountIdsFromCaip25CaveatValue(updatedCaveatValue);\n\n // We fully revoke permission if no accounts are left after scope removal loop.\n if (!caipAccountIds.length) {\n hooks.revokePermissionForOrigin(Caip25EndowmentPermissionName);\n } else {\n hooks.updateCaveat(\n Caip25EndowmentPermissionName,\n Caip25CaveatType,\n updatedCaveatValue,\n );\n }\n}\n\n/**\n * Handler for the `wallet_revokeSession` RPC method as specified by [CAIP-285](https://chainagnostic.org/CAIPs/caip-285).\n * The implementation below deviates from the linked spec in that it ignores the `sessionId` param\n * and instead revokes the singular session for the origin if available. Additionally,\n * the handler also does not return an error if there is currently no active session and instead\n * returns true which is the same result returned if an active session was actually revoked.\n *\n * @param request - The JSON-RPC request object. Unused.\n * @param response - The JSON-RPC response object.\n * @param _next - The next middleware function. Unused.\n * @param end - The end callback function.\n * @param hooks - The hooks object.\n * @param hooks.revokePermissionForOrigin - The hook for revoking a permission for an origin function.\n * @param hooks.updateCaveat - The hook used to conditionally update the caveat rather than fully revoke the permission.\n * @param hooks.getCaveatForOrigin - The hook to fetch an existing caveat for the origin of the request.\n * @returns Nothing.\n */\nasync function handleWalletRevokeSession(\n request: JsonRpcRequest<WalletRevokeSessionParams> & { origin: string },\n response: PendingJsonRpcResponse<Json>,\n _next: JsonRpcEngineNextCallback,\n end: JsonRpcEngineEndCallback,\n hooks: WalletRevokeSessionHooks,\n) {\n try {\n if (request.params?.scopes?.length) {\n partialRevokePermissions(request.params.scopes, hooks);\n } else {\n hooks.revokePermissionForOrigin(Caip25EndowmentPermissionName);\n }\n } catch (err) {\n if (!isPermissionError(err)) {\n console.error(err);\n return end(rpcErrors.internal());\n }\n }\n\n response.result = true;\n return end();\n}\n\nexport type WalletRevokeSessionHandler = MethodHandler<\n WalletRevokeSessionHooks,\n never,\n WalletRevokeSessionParams,\n Json,\n { origin: string }\n>;\n\nexport const walletRevokeSessionHandler = {\n implementation: handleWalletRevokeSession,\n hookNames: {\n revokePermissionForOrigin: true,\n updateCaveat: true,\n getCaveatForOrigin: true,\n },\n} satisfies WalletRevokeSessionHandler;\n"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { Caip25CaveatValue } from
|
|
2
|
-
import type { JsonRpcEngineEndCallback, JsonRpcEngineNextCallback, MethodHandler } from
|
|
3
|
-
import { GenericPermissionController } from
|
|
4
|
-
import type { Json, JsonRpcRequest, PendingJsonRpcResponse } from
|
|
5
|
-
import type { GetCaveatForOriginHook } from
|
|
1
|
+
import type { Caip25CaveatValue } from "@metamask/chain-agnostic-permission";
|
|
2
|
+
import type { JsonRpcEngineEndCallback, JsonRpcEngineNextCallback, MethodHandler } from "@metamask/json-rpc-engine";
|
|
3
|
+
import { GenericPermissionController } from "@metamask/permission-controller";
|
|
4
|
+
import type { Json, JsonRpcRequest, PendingJsonRpcResponse } from "@metamask/utils";
|
|
5
|
+
import type { GetCaveatForOriginHook } from "./types.cjs";
|
|
6
6
|
export type WalletRevokeSessionHooks = GetCaveatForOriginHook & {
|
|
7
7
|
revokePermissionForOrigin: (permissionName: string) => ReturnType<GenericPermissionController['revokePermissions']>;
|
|
8
8
|
updateCaveat: (target: string, caveatType: string, caveatValue: Caip25CaveatValue) => ReturnType<GenericPermissionController['updateCaveat']>;
|
|
@@ -42,4 +42,4 @@ export declare const walletRevokeSessionHandler: {
|
|
|
42
42
|
};
|
|
43
43
|
};
|
|
44
44
|
export {};
|
|
45
|
-
//# sourceMappingURL=wallet-revokeSession.d.
|
|
45
|
+
//# sourceMappingURL=wallet-revokeSession.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet-revokeSession.d.cts","sourceRoot":"","sources":["../../src/handlers/wallet-revokeSession.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,iBAAiB,EAAE,4CAA4C;AAC7E,OAAO,KAAK,EACV,wBAAwB,EACxB,yBAAyB,EACzB,aAAa,EACd,kCAAkC;AACnC,OAAO,EAEL,2BAA2B,EAG5B,wCAAwC;AAGzC,OAAO,KAAK,EACV,IAAI,EACJ,cAAc,EACd,sBAAsB,EACvB,wBAAwB;AAEzB,OAAO,KAAK,EAAgB,sBAAsB,EAAE,oBAAmB;AAEvE,MAAM,MAAM,wBAAwB,GAAG,sBAAsB,GAAG;IAC9D,yBAAyB,EAAE,CACzB,cAAc,EAAE,M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