@metamask-previews/multichain-api-middleware 3.1.5-preview-2226dd478 → 3.1.5-preview-53326764b

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 CHANGED
@@ -7,16 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
- ### Added
11
-
12
- - Add `MULTICHAIN_API.md`, a reference for the Multichain API: `wallet_createSession` and the other session methods, supported methods per namespace, error codes, and divergences from the current CAIP-25 spec ([#9258](https://github.com/MetaMask/core/pull/9258))
13
-
14
10
  ### Changed
15
11
 
16
- - **BREAKING:** The `wallet_getSession` and `wallet_createSession` handlers now require a `getCapabilities` hook (`(params: { address: string }) => unknown`) ([#9294](https://github.com/MetaMask/core/pull/9294))
17
- - `WalletGetSessionHooks` and `WalletCreateSessionHooks` now include this hook, which must be provided when wiring up the handlers.
18
- - The `wallet_getSession` and `wallet_createSession` handlers now derive the returned `sessionProperties` via `getSessionProperties`, hydrating the persisted session properties with a `capabilities` record built from the `getCapabilities` hook for each permitted EVM account ([#9294](https://github.com/MetaMask/core/pull/9294))
19
- - `wallet_getSession` now always includes a `sessionProperties` field in its result (an empty object when there is no active session).
20
12
  - Bump `@metamask/accounts-controller` from `^39.0.2` to `^39.0.3` ([#9231](https://github.com/MetaMask/core/pull/9231))
21
13
 
22
14
  ## [3.1.5]
package/README.md CHANGED
@@ -2,14 +2,6 @@
2
2
 
3
3
  JSON-RPC methods and middleware to support the the [MetaMask Multichain API](https://github.com/MetaMask/metamask-improvement-proposals/blob/main/MIPs/mip-5.md).
4
4
 
5
- ## Documentation
6
-
7
- See [`MULTICHAIN_API.md`](./MULTICHAIN_API.md) for a readable, wallet-side
8
- reference of the Multichain API as implemented here: `wallet_createSession` inputs
9
- and outputs, supported methods per namespace, error codes, and how MetaMask
10
- currently diverges from the latest CAIP-25. The machine-readable schema lives in
11
- [`@metamask/api-specs`](https://github.com/MetaMask/api-specs).
12
-
13
5
  ## Installation
14
6
 
15
7
  `yarn add @metamask/multichain-api-middleware`
@@ -1 +1 @@
1
- {"version":3,"file":"types.cjs","sourceRoot":"","sources":["../../src/handlers/types.ts"],"names":[],"mappings":";;;AAAA,mFAG6C;AAQ7C;;GAEG;AACH,IAAY,0BAGX;AAHD,WAAY,0BAA0B;IACpC,sEAAwC,CAAA;IACxC,4DAA8B,CAAA;AAChC,CAAC,EAHW,0BAA0B,0CAA1B,0BAA0B,QAGrC","sourcesContent":["import {\n Caip25CaveatType,\n Caip25CaveatValue,\n} from '@metamask/chain-agnostic-permission';\nimport type {\n GenericPermissionController,\n Caveat,\n} from '@metamask/permission-controller';\nimport type { MultichainRoutingService } from '@metamask/snaps-controllers';\nimport type { CaipAccountId } from '@metamask/utils';\n\n/**\n * Multichain API notifications currently supported by/known to the wallet.\n */\nexport enum MultichainApiNotifications {\n sessionChanged = 'wallet_sessionChanged',\n walletNotify = 'wallet_notify',\n}\n\nexport type Caip25Caveat = Caveat<typeof Caip25CaveatType, Caip25CaveatValue>;\n\nexport type GetCaveatForOriginHook = {\n getCaveatForOrigin: (\n endowmentPermissionName: string,\n caveatType: string,\n ) => ReturnType<GenericPermissionController['getCaveat']>;\n};\n\nexport type GetNonEvmSupportedMethodsHook = {\n getNonEvmSupportedMethods: MultichainRoutingService['getSupportedMethods'];\n};\n\nexport type SortAccountIdsByLastSelectedHook = {\n sortAccountIdsByLastSelected: (accounts: CaipAccountId[]) => CaipAccountId[];\n};\n\nexport type GetCapabilitiesHook = {\n getCapabilities: (params: { address: string }) => unknown;\n};\n"]}
1
+ {"version":3,"file":"types.cjs","sourceRoot":"","sources":["../../src/handlers/types.ts"],"names":[],"mappings":";;;AAAA,mFAG6C;AAQ7C;;GAEG;AACH,IAAY,0BAGX;AAHD,WAAY,0BAA0B;IACpC,sEAAwC,CAAA;IACxC,4DAA8B,CAAA;AAChC,CAAC,EAHW,0BAA0B,0CAA1B,0BAA0B,QAGrC","sourcesContent":["import {\n Caip25CaveatType,\n Caip25CaveatValue,\n} from '@metamask/chain-agnostic-permission';\nimport type {\n GenericPermissionController,\n Caveat,\n} from '@metamask/permission-controller';\nimport type { MultichainRoutingService } from '@metamask/snaps-controllers';\nimport type { CaipAccountId } from '@metamask/utils';\n\n/**\n * Multichain API notifications currently supported by/known to the wallet.\n */\nexport enum MultichainApiNotifications {\n sessionChanged = 'wallet_sessionChanged',\n walletNotify = 'wallet_notify',\n}\n\nexport type Caip25Caveat = Caveat<typeof Caip25CaveatType, Caip25CaveatValue>;\n\nexport type GetCaveatForOriginHook = {\n getCaveatForOrigin: (\n endowmentPermissionName: string,\n caveatType: string,\n ) => ReturnType<GenericPermissionController['getCaveat']>;\n};\n\nexport type GetNonEvmSupportedMethodsHook = {\n getNonEvmSupportedMethods: MultichainRoutingService['getSupportedMethods'];\n};\n\nexport type SortAccountIdsByLastSelectedHook = {\n sortAccountIdsByLastSelected: (accounts: CaipAccountId[]) => CaipAccountId[];\n};\n"]}
@@ -19,9 +19,4 @@ export type GetNonEvmSupportedMethodsHook = {
19
19
  export type SortAccountIdsByLastSelectedHook = {
20
20
  sortAccountIdsByLastSelected: (accounts: CaipAccountId[]) => CaipAccountId[];
21
21
  };
22
- export type GetCapabilitiesHook = {
23
- getCapabilities: (params: {
24
- address: string;
25
- }) => unknown;
26
- };
27
22
  //# sourceMappingURL=types.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../../src/handlers/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EAClB,4CAA4C;AAC7C,OAAO,KAAK,EACV,2BAA2B,EAC3B,MAAM,EACP,wCAAwC;AACzC,OAAO,KAAK,EAAE,wBAAwB,EAAE,oCAAoC;AAC5E,OAAO,KAAK,EAAE,aAAa,EAAE,wBAAwB;AAErD;;GAEG;AACH,oBAAY,0BAA0B;IACpC,cAAc,0BAA0B;IACxC,YAAY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CAAC;CAC3D,CAAC;AAEF,MAAM,MAAM,6BAA6B,GAAG;IAC1C,yBAAyB,EAAE,wBAAwB,CAAC,qBAAqB,CAAC,CAAC;CAC5E,CAAC;AAEF,MAAM,MAAM,gCAAgC,GAAG;IAC7C,4BAA4B,EAAE,CAAC,QAAQ,EAAE,aAAa,EAAE,KAAK,aAAa,EAAE,CAAC;CAC9E,CAAC"}
@@ -19,9 +19,4 @@ export type GetNonEvmSupportedMethodsHook = {
19
19
  export type SortAccountIdsByLastSelectedHook = {
20
20
  sortAccountIdsByLastSelected: (accounts: CaipAccountId[]) => CaipAccountId[];
21
21
  };
22
- export type GetCapabilitiesHook = {
23
- getCapabilities: (params: {
24
- address: string;
25
- }) => unknown;
26
- };
27
22
  //# sourceMappingURL=types.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../../src/handlers/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EAClB,4CAA4C;AAC7C,OAAO,KAAK,EACV,2BAA2B,EAC3B,MAAM,EACP,wCAAwC;AACzC,OAAO,KAAK,EAAE,wBAAwB,EAAE,oCAAoC;AAC5E,OAAO,KAAK,EAAE,aAAa,EAAE,wBAAwB;AAErD;;GAEG;AACH,oBAAY,0BAA0B;IACpC,cAAc,0BAA0B;IACxC,YAAY,kBAAkB;CAC/B;AAED,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,OAAO,gBAAgB,EAAE,iBAAiB,CAAC,CAAC;AAE9E,MAAM,MAAM,sBAAsB,GAAG;IACnC,kBAAkB,EAAE,CAClB,uBAAuB,EAAE,MAAM,EAC/B,UAAU,EAAE,MAAM,KACf,UAAU,CAAC,2BAA2B,CAAC,WAAW,CAAC,CAAC,CAAC;CAC3D,CAAC;AAEF,MAAM,MAAM,6BAA6B,GAAG;IAC1C,yBAAyB,EAAE,wBAAwB,CAAC,qBAAqB,CAAC,CAAC;CAC5E,CAAC;AAEF,MAAM,MAAM,gCAAgC,GAAG;IAC7C,4BAA4B,EAAE,CAAC,QAAQ,EAAE,aAAa,EAAE,KAAK,aAAa,EAAE,CAAC;CAC9E,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,eAAe,EAAE,CAAC,MAAM,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC;CAC3D,CAAC"}
1
+ {"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../../src/handlers/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EAClB,4CAA4C;AAC7C,OAAO,KAAK,EACV,2BAA2B,EAC3B,MAAM,EACP,wCAAwC;AACzC,OAAO,KAAK,EAAE,wBAAwB,EAAE,oCAAoC;AAC5E,OAAO,KAAK,EAAE,aAAa,EAAE,wBAAwB;AAErD;;GAEG;AACH,oBAAY,0BAA0B;IACpC,cAAc,0BAA0B;IACxC,YAAY,kBAAkB;CAC/B;AAED,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,OAAO,gBAAgB,EAAE,iBAAiB,CAAC,CAAC;AAE9E,MAAM,MAAM,sBAAsB,GAAG;IACnC,kBAAkB,EAAE,CAClB,uBAAuB,EAAE,MAAM,EAC/B,UAAU,EAAE,MAAM,KACf,UAAU,CAAC,2BAA2B,CAAC,WAAW,CAAC,CAAC,CAAC;CAC3D,CAAC;AAEF,MAAM,MAAM,6BAA6B,GAAG;IAC1C,yBAAyB,EAAE,wBAAwB,CAAC,qBAAqB,CAAC,CAAC;CAC5E,CAAC;AAEF,MAAM,MAAM,gCAAgC,GAAG;IAC7C,4BAA4B,EAAE,CAAC,QAAQ,EAAE,aAAa,EAAE,KAAK,aAAa,EAAE,CAAC;CAC9E,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.mjs","sourceRoot":"","sources":["../../src/handlers/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAEjB,4CAA4C;AAQ7C;;GAEG;AACH,MAAM,CAAN,IAAY,0BAGX;AAHD,WAAY,0BAA0B;IACpC,sEAAwC,CAAA;IACxC,4DAA8B,CAAA;AAChC,CAAC,EAHW,0BAA0B,KAA1B,0BAA0B,QAGrC","sourcesContent":["import {\n Caip25CaveatType,\n Caip25CaveatValue,\n} from '@metamask/chain-agnostic-permission';\nimport type {\n GenericPermissionController,\n Caveat,\n} from '@metamask/permission-controller';\nimport type { MultichainRoutingService } from '@metamask/snaps-controllers';\nimport type { CaipAccountId } from '@metamask/utils';\n\n/**\n * Multichain API notifications currently supported by/known to the wallet.\n */\nexport enum MultichainApiNotifications {\n sessionChanged = 'wallet_sessionChanged',\n walletNotify = 'wallet_notify',\n}\n\nexport type Caip25Caveat = Caveat<typeof Caip25CaveatType, Caip25CaveatValue>;\n\nexport type GetCaveatForOriginHook = {\n getCaveatForOrigin: (\n endowmentPermissionName: string,\n caveatType: string,\n ) => ReturnType<GenericPermissionController['getCaveat']>;\n};\n\nexport type GetNonEvmSupportedMethodsHook = {\n getNonEvmSupportedMethods: MultichainRoutingService['getSupportedMethods'];\n};\n\nexport type SortAccountIdsByLastSelectedHook = {\n sortAccountIdsByLastSelected: (accounts: CaipAccountId[]) => CaipAccountId[];\n};\n\nexport type GetCapabilitiesHook = {\n getCapabilities: (params: { address: string }) => unknown;\n};\n"]}
1
+ {"version":3,"file":"types.mjs","sourceRoot":"","sources":["../../src/handlers/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAEjB,4CAA4C;AAQ7C;;GAEG;AACH,MAAM,CAAN,IAAY,0BAGX;AAHD,WAAY,0BAA0B;IACpC,sEAAwC,CAAA;IACxC,4DAA8B,CAAA;AAChC,CAAC,EAHW,0BAA0B,KAA1B,0BAA0B,QAGrC","sourcesContent":["import {\n Caip25CaveatType,\n Caip25CaveatValue,\n} from '@metamask/chain-agnostic-permission';\nimport type {\n GenericPermissionController,\n Caveat,\n} from '@metamask/permission-controller';\nimport type { MultichainRoutingService } from '@metamask/snaps-controllers';\nimport type { CaipAccountId } from '@metamask/utils';\n\n/**\n * Multichain API notifications currently supported by/known to the wallet.\n */\nexport enum MultichainApiNotifications {\n sessionChanged = 'wallet_sessionChanged',\n walletNotify = 'wallet_notify',\n}\n\nexport type Caip25Caveat = Caveat<typeof Caip25CaveatType, Caip25CaveatValue>;\n\nexport type GetCaveatForOriginHook = {\n getCaveatForOrigin: (\n endowmentPermissionName: string,\n caveatType: string,\n ) => ReturnType<GenericPermissionController['getCaveat']>;\n};\n\nexport type GetNonEvmSupportedMethodsHook = {\n getNonEvmSupportedMethods: MultichainRoutingService['getSupportedMethods'];\n};\n\nexport type SortAccountIdsByLastSelectedHook = {\n sortAccountIdsByLastSelected: (accounts: CaipAccountId[]) => CaipAccountId[];\n};\n"]}
@@ -30,7 +30,6 @@ const SOLANA_CAIP_CHAIN_ID = 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp';
30
30
  * @param hooks.isNonEvmScopeSupported - The hook that returns true if a non EVM scope is supported.
31
31
  * @param hooks.getNonEvmAccountAddresses - The hook that returns a list of CaipAccountIds that are supported for a CaipChainId.
32
32
  * @param hooks.sortAccountIdsByLastSelected - A function that accepts an array of CaipAccountId and returns an array of CaipAccountId sorted by last selected.
33
- * @param hooks.getCapabilities - A function that returns the capabilities for a given address.
34
33
  * @param hooks.trackSessionCreatedEvent - An optional hook for platform specific logic to run.
35
34
  * @returns A promise with wallet_createSession handler
36
35
  */
@@ -148,9 +147,7 @@ async function handleWalletCreateSession(req, res, _next, end, hooks) {
148
147
  getNonEvmSupportedMethods: hooks.getNonEvmSupportedMethods,
149
148
  sortAccountIdsByLastSelected: hooks.sortAccountIdsByLastSelected,
150
149
  });
151
- const approvedSessionProperties = (0, chain_agnostic_permission_1.getSessionProperties)(approvedCaip25CaveatValue, {
152
- getCapabilities: hooks.getCapabilities,
153
- });
150
+ const { sessionProperties: approvedSessionProperties = {} } = approvedCaip25CaveatValue;
154
151
  hooks.trackSessionCreatedEvent?.(approvedCaip25CaveatValue);
155
152
  res.result = {
156
153
  sessionScopes,
@@ -172,7 +169,6 @@ exports.walletCreateSessionHandler = {
172
169
  isNonEvmScopeSupported: true,
173
170
  getNonEvmAccountAddresses: true,
174
171
  sortAccountIdsByLastSelected: true,
175
- getCapabilities: true,
176
172
  trackSessionCreatedEvent: true,
177
173
  },
178
174
  };
@@ -1 +1 @@
1
- {"version":3,"file":"wallet-createSession.cjs","sourceRoot":"","sources":["../../src/handlers/wallet-createSession.ts"],"names":[],"mappings":";;;AACA,mFAc6C;AAM7C,iEAAoE;AAOpE,2EAAgE;AAKhE,qDAA+D;AAE/D,2CAIyB;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,IAAA,qBAAa,EAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;QAC/B,OAAO,GAAG,CAAC,IAAA,qCAAa,EAAC,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC;IACxD,CAAC;IACD,MAAM,EAAE,cAAc,EAAE,cAAc,EAAE,iBAAiB,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC;IAEzE,IAAI,iBAAiB,IAAI,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACrE,OAAO,GAAG,CAAC,IAAI,yBAAY,CAAC,IAAI,EAAE,qCAAqC,CAAC,CAAC,CAAC;IAC5E,CAAC;IAED,MAAM,yBAAyB,GAAG,MAAM,CAAC,WAAW,CAClD,MAAM,CAAC,OAAO,CAAC,iBAAiB,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CACvD,IAAA,uDAA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KAAK,4CAAgB,CAC7C,EAAE,KAA0B,CAAC;QAC9B,IAAI,CAAC,yBAAyB,EAAE,CAAC;YAC/B,MAAM,sBAAS,CAAC,QAAQ,EAAE,CAAC;QAC7B,CAAC;QAED,MAAM,aAAa,GAAG,IAAA,4CAAgB,EAAC,yBAAyB,EAAE;YAChE,yBAAyB,EAAE,KAAK,CAAC,yBAAyB;YAC1D,4BAA4B,EAAE,KAAK,CAAC,4BAA4B;SACjE,CAAC,CAAC;QAEH,MAAM,yBAAyB,GAAG,IAAA,gDAAoB,EACpD,yBAAyB,EACzB;YACE,eAAe,EAAE,KAAK,CAAC,eAAe;SACvC,CACsB,CAAC;QAE1B,KAAK,CAAC,wBAAwB,EAAE,CAAC,yBAAyB,CAAC,CAAC;QAE5D,GAAG,CAAC,MAAM,GAAG;YACX,aAAa;YACb,iBAAiB,EAAE,yBAAyB;SAC7C,CAAC;QACF,OAAO,GAAG,EAAE,CAAC;IACf,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAUY,QAAA,0BAA0B,GAAG;IACxC,cAAc,EAAE,yBAAyB;IACzC,SAAS,EAAE;QACT,4BAA4B,EAAE,IAAI;QAClC,YAAY,EAAE,IAAI;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';\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 = getSessionProperties(\n approvedCaip25CaveatValue,\n {\n getCapabilities: hooks.getCapabilities,\n },\n ) as Record<string, Json>;\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"]}
1
+ {"version":3,"file":"wallet-createSession.cjs","sourceRoot":"","sources":["../../src/handlers/wallet-createSession.ts"],"names":[],"mappings":";;;AACA,mFAa6C;AAM7C,iEAAoE;AAOpE,2EAAgE;AAKhE,qDAA+D;AAE/D,2CAIyB;AAczB,MAAM,oBAAoB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,yBAAyB,CAAC,CAAC;QAE5D,GAAG,CAAC,MAAM,GAAG;YACX,aAAa;YACb,iBAAiB,EAAE,yBAAyB;SAC7C,CAAC;QACF,OAAO,GAAG,EAAE,CAAC;IACf,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAUY,QAAA,0BAA0B,GAAG;IACxC,cAAc,EAAE,yBAAyB;IACzC,SAAS,EAAE;QACT,4BAA4B,EAAE,IAAI;QAClC,YAAY,EAAE,IAAI;QAClB,2BAA2B,EAAE,IAAI;QACjC,yBAAyB,EAAE,IAAI;QAC/B,sBAAsB,EAAE,IAAI;QAC5B,yBAAyB,EAAE,IAAI;QAC/B,4BAA4B,EAAE,IAAI;QAClC,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 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 GetNonEvmSupportedMethodsHook,\n SortAccountIdsByLastSelectedHook,\n} from './types';\n\nconst SOLANA_CAIP_CHAIN_ID = 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp';\n\nexport type WalletCreateSessionHooks = GetNonEvmSupportedMethodsHook &\n SortAccountIdsByLastSelectedHook & {\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.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 { sessionProperties: approvedSessionProperties = {} } =\n approvedCaip25CaveatValue;\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 trackSessionCreatedEvent: true,\n },\n} satisfies WalletCreateSessionHandler;\n"]}
@@ -5,8 +5,8 @@ import type { NetworkController } from "@metamask/network-controller";
5
5
  import type { GenericPermissionController, RequestedPermissions } from "@metamask/permission-controller";
6
6
  import type { MultichainRoutingService } from "@metamask/snaps-controllers";
7
7
  import type { Json, JsonRpcRequest, PendingJsonRpcResponse } from "@metamask/utils";
8
- import type { GetCapabilitiesHook, GetNonEvmSupportedMethodsHook, SortAccountIdsByLastSelectedHook } from "./types.cjs";
9
- export type WalletCreateSessionHooks = GetNonEvmSupportedMethodsHook & SortAccountIdsByLastSelectedHook & GetCapabilitiesHook & {
8
+ import type { GetNonEvmSupportedMethodsHook, SortAccountIdsByLastSelectedHook } from "./types.cjs";
9
+ export type WalletCreateSessionHooks = GetNonEvmSupportedMethodsHook & SortAccountIdsByLastSelectedHook & {
10
10
  listAccounts: AccountsController['listAccounts'];
11
11
  findNetworkClientIdByChainId: NetworkController['findNetworkClientIdByChainId'];
12
12
  requestPermissionsForOrigin: (requestedPermissions: RequestedPermissions, metadata?: Record<string, Json>) => ReturnType<GenericPermissionController['requestPermissions']>;
@@ -42,7 +42,6 @@ type Result = {
42
42
  * @param hooks.isNonEvmScopeSupported - The hook that returns true if a non EVM scope is supported.
43
43
  * @param hooks.getNonEvmAccountAddresses - The hook that returns a list of CaipAccountIds that are supported for a CaipChainId.
44
44
  * @param hooks.sortAccountIdsByLastSelected - A function that accepts an array of CaipAccountId and returns an array of CaipAccountId sorted by last selected.
45
- * @param hooks.getCapabilities - A function that returns the capabilities for a given address.
46
45
  * @param hooks.trackSessionCreatedEvent - An optional hook for platform specific logic to run.
47
46
  * @returns A promise with wallet_createSession handler
48
47
  */
@@ -62,7 +61,6 @@ export declare const walletCreateSessionHandler: {
62
61
  isNonEvmScopeSupported: true;
63
62
  getNonEvmAccountAddresses: true;
64
63
  sortAccountIdsByLastSelected: true;
65
- getCapabilities: true;
66
64
  trackSessionCreatedEvent: true;
67
65
  };
68
66
  };
@@ -1 +1 @@
1
- {"version":3,"file":"wallet-createSession.d.cts","sourceRoot":"","sources":["../../src/handlers/wallet-createSession.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,sCAAsC;AAgBxE,OAAO,KAAK,EACV,mBAAmB,EACnB,sBAAsB,EACtB,iBAAiB,EAClB,4CAA4C;AAE7C,OAAO,KAAK,EACV,aAAa,EACb,wBAAwB,EACxB,yBAAyB,EAC1B,kCAAkC;AACnC,OAAO,KAAK,EAAE,iBAAiB,EAAE,qCAAqC;AAEtE,OAAO,KAAK,EACV,2BAA2B,EAC3B,oBAAoB,EACrB,wCAAwC;AAEzC,OAAO,KAAK,EAAE,wBAAwB,EAAE,oCAAoC;AAM5E,OAAO,KAAK,EAGV,IAAI,EACJ,cAAc,EACd,sBAAsB,EACvB,wBAAwB;AAEzB,OAAO,KAAK,EACV,mBAAmB,EACnB,6BAA6B,EAC7B,gCAAgC,EACjC,oBAAgB;AAIjB,MAAM,MAAM,wBAAwB,GAAG,6BAA6B,GAClE,gCAAgC,GAChC,mBAAmB,GAAG;IACpB,YAAY,EAAE,kBAAkB,CAAC,cAAc,CAAC,CAAC;IACjD,4BAA4B,EAAE,iBAAiB,CAAC,8BAA8B,CAAC,CAAC;IAChF,2BAA2B,EAAE,CAC3B,oBAAoB,EAAE,oBAAoB,EAC1C,QAAQ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D,GAAG,EAAE,sBAAsB,CAAC,MAAM,CAAC,EACnC,KAAK,EAAE,yBAAyB,EAChC,GAAG,EAAE,wBAAwB,EAC7B,KAAK,EAAE,wBAAwB,GAC9B,OAAO,CAAC,IAAI,CAAC,CA4Lf;AAED,MAAM,MAAM,0BAA0B,GAAG,aAAa,CACpD,wBAAwB,EACxB,KAAK,EACL,MAAM,EACN,MAAM,EACN;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CACnB,CAAC;AAEF,eAAO,MAAM,0BAA0B;;;;;;;;;;;;CAYD,CAAC"}
@@ -5,8 +5,8 @@ import type { NetworkController } from "@metamask/network-controller";
5
5
  import type { GenericPermissionController, RequestedPermissions } from "@metamask/permission-controller";
6
6
  import type { MultichainRoutingService } from "@metamask/snaps-controllers";
7
7
  import type { Json, JsonRpcRequest, PendingJsonRpcResponse } from "@metamask/utils";
8
- import type { GetCapabilitiesHook, GetNonEvmSupportedMethodsHook, SortAccountIdsByLastSelectedHook } from "./types.mjs";
9
- export type WalletCreateSessionHooks = GetNonEvmSupportedMethodsHook & SortAccountIdsByLastSelectedHook & GetCapabilitiesHook & {
8
+ import type { GetNonEvmSupportedMethodsHook, SortAccountIdsByLastSelectedHook } from "./types.mjs";
9
+ export type WalletCreateSessionHooks = GetNonEvmSupportedMethodsHook & SortAccountIdsByLastSelectedHook & {
10
10
  listAccounts: AccountsController['listAccounts'];
11
11
  findNetworkClientIdByChainId: NetworkController['findNetworkClientIdByChainId'];
12
12
  requestPermissionsForOrigin: (requestedPermissions: RequestedPermissions, metadata?: Record<string, Json>) => ReturnType<GenericPermissionController['requestPermissions']>;
@@ -42,7 +42,6 @@ type Result = {
42
42
  * @param hooks.isNonEvmScopeSupported - The hook that returns true if a non EVM scope is supported.
43
43
  * @param hooks.getNonEvmAccountAddresses - The hook that returns a list of CaipAccountIds that are supported for a CaipChainId.
44
44
  * @param hooks.sortAccountIdsByLastSelected - A function that accepts an array of CaipAccountId and returns an array of CaipAccountId sorted by last selected.
45
- * @param hooks.getCapabilities - A function that returns the capabilities for a given address.
46
45
  * @param hooks.trackSessionCreatedEvent - An optional hook for platform specific logic to run.
47
46
  * @returns A promise with wallet_createSession handler
48
47
  */
@@ -62,7 +61,6 @@ export declare const walletCreateSessionHandler: {
62
61
  isNonEvmScopeSupported: true;
63
62
  getNonEvmAccountAddresses: true;
64
63
  sortAccountIdsByLastSelected: true;
65
- getCapabilities: true;
66
64
  trackSessionCreatedEvent: true;
67
65
  };
68
66
  };
@@ -1 +1 @@
1
- {"version":3,"file":"wallet-createSession.d.mts","sourceRoot":"","sources":["../../src/handlers/wallet-createSession.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,sCAAsC;AAgBxE,OAAO,KAAK,EACV,mBAAmB,EACnB,sBAAsB,EACtB,iBAAiB,EAClB,4CAA4C;AAE7C,OAAO,KAAK,EACV,aAAa,EACb,wBAAwB,EACxB,yBAAyB,EAC1B,kCAAkC;AACnC,OAAO,KAAK,EAAE,iBAAiB,EAAE,qCAAqC;AAEtE,OAAO,KAAK,EACV,2BAA2B,EAC3B,oBAAoB,EACrB,wCAAwC;AAEzC,OAAO,KAAK,EAAE,wBAAwB,EAAE,oCAAoC;AAM5E,OAAO,KAAK,EAGV,IAAI,EACJ,cAAc,EACd,sBAAsB,EACvB,wBAAwB;AAEzB,OAAO,KAAK,EACV,mBAAmB,EACnB,6BAA6B,EAC7B,gCAAgC,EACjC,oBAAgB;AAIjB,MAAM,MAAM,wBAAwB,GAAG,6BAA6B,GAClE,gCAAgC,GAChC,mBAAmB,GAAG;IACpB,YAAY,EAAE,kBAAkB,CAAC,cAAc,CAAC,CAAC;IACjD,4BAA4B,EAAE,iBAAiB,CAAC,8BAA8B,CAAC,CAAC;IAChF,2BAA2B,EAAE,CAC3B,oBAAoB,EAAE,oBAAoB,EAC1C,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,KAC5B,UAAU,CAAC,2BAA2B,CAAC,oBAAoB,CAAC,CAAC,CAAC;IACnE,sBAAsB,EAAE,wBAAwB,CAAC,kBAAkB,CAAC,CAAC;IACrE,yBAAyB,EAAE,wBAAwB,CAAC,sBAAsB,CAAC,CAAC;IAC5E,wBAAwB,EACpB,CAAC,CAAC,yBAAyB,EAAE,iBAAiB,KAAK,IAAI,CAAC,GACxD,IAAI,CAAC;CACV,CAAC;AAEJ,KAAK,MAAM,GAAG,mBAAmB,CAAC;AAElC,KAAK,MAAM,GAAG;IACZ,aAAa,EAAE,sBAAsB,CAAC;IACtC,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;CAC1C,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,iBAAe,yBAAyB,CACtC,GAAG,EAAE,cAAc,CAAC,MAAM,CAAC,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,EAChD,GAAG,EAAE,sBAAsB,CAAC,MAAM,CAAC,EACnC,KAAK,EAAE,yBAAyB,EAChC,GAAG,EAAE,wBAAwB,EAC7B,KAAK,EAAE,wBAAwB,GAC9B,OAAO,CAAC,IAAI,CAAC,CAgMf;AAED,MAAM,MAAM,0BAA0B,GAAG,aAAa,CACpD,wBAAwB,EACxB,KAAK,EACL,MAAM,EACN,MAAM,EACN;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CACnB,CAAC;AAEF,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;CAaD,CAAC"}
1
+ {"version":3,"file":"wallet-createSession.d.mts","sourceRoot":"","sources":["../../src/handlers/wallet-createSession.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,sCAAsC;AAexE,OAAO,KAAK,EACV,mBAAmB,EACnB,sBAAsB,EACtB,iBAAiB,EAClB,4CAA4C;AAE7C,OAAO,KAAK,EACV,aAAa,EACb,wBAAwB,EACxB,yBAAyB,EAC1B,kCAAkC;AACnC,OAAO,KAAK,EAAE,i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AE,wBAAwB,EAC7B,KAAK,EAAE,wBAAwB,GAC9B,OAAO,CAAC,IAAI,CAAC,CA4Lf;AAED,MAAM,MAAM,0BAA0B,GAAG,aAAa,CACpD,wBAAwB,EACxB,KAAK,EACL,MAAM,EACN,MAAM,EACN;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CACnB,CAAC;AAEF,eAAO,MAAM,0BAA0B;;;;;;;;;;;;CAYD,CAAC"}
@@ -1,4 +1,4 @@
1
- import { Caip25CaveatType, Caip25EndowmentPermissionName, bucketScopes, validateAndNormalizeScopes, getInternalScopesObject, getSessionScopes, getSessionProperties, getSupportedScopeObjects, isKnownSessionPropertyValue, getCaipAccountIdsFromScopesObjects, getAllScopesFromScopesObjects, setNonSCACaipAccountIdsInCaip25CaveatValue, isNamespaceInScopesObject } from "@metamask/chain-agnostic-permission";
1
+ import { Caip25CaveatType, Caip25EndowmentPermissionName, bucketScopes, validateAndNormalizeScopes, getInternalScopesObject, getSessionScopes, getSupportedScopeObjects, isKnownSessionPropertyValue, getCaipAccountIdsFromScopesObjects, getAllScopesFromScopesObjects, setNonSCACaipAccountIdsInCaip25CaveatValue, isNamespaceInScopesObject } from "@metamask/chain-agnostic-permission";
2
2
  import { isEqualCaseInsensitive } from "@metamask/controller-utils";
3
3
  import { invalidParams } from "@metamask/permission-controller";
4
4
  import { JsonRpcError, rpcErrors } from "@metamask/rpc-errors";
@@ -27,7 +27,6 @@ const SOLANA_CAIP_CHAIN_ID = 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp';
27
27
  * @param hooks.isNonEvmScopeSupported - The hook that returns true if a non EVM scope is supported.
28
28
  * @param hooks.getNonEvmAccountAddresses - The hook that returns a list of CaipAccountIds that are supported for a CaipChainId.
29
29
  * @param hooks.sortAccountIdsByLastSelected - A function that accepts an array of CaipAccountId and returns an array of CaipAccountId sorted by last selected.
30
- * @param hooks.getCapabilities - A function that returns the capabilities for a given address.
31
30
  * @param hooks.trackSessionCreatedEvent - An optional hook for platform specific logic to run.
32
31
  * @returns A promise with wallet_createSession handler
33
32
  */
@@ -145,9 +144,7 @@ async function handleWalletCreateSession(req, res, _next, end, hooks) {
145
144
  getNonEvmSupportedMethods: hooks.getNonEvmSupportedMethods,
146
145
  sortAccountIdsByLastSelected: hooks.sortAccountIdsByLastSelected,
147
146
  });
148
- const approvedSessionProperties = getSessionProperties(approvedCaip25CaveatValue, {
149
- getCapabilities: hooks.getCapabilities,
150
- });
147
+ const { sessionProperties: approvedSessionProperties = {} } = approvedCaip25CaveatValue;
151
148
  hooks.trackSessionCreatedEvent?.(approvedCaip25CaveatValue);
152
149
  res.result = {
153
150
  sessionScopes,
@@ -169,7 +166,6 @@ export const walletCreateSessionHandler = {
169
166
  isNonEvmScopeSupported: true,
170
167
  getNonEvmAccountAddresses: true,
171
168
  sortAccountIdsByLastSelected: true,
172
- getCapabilities: true,
173
169
  trackSessionCreatedEvent: true,
174
170
  },
175
171
  };
@@ -1 +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,G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AG,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAUD,MAAM,CAAC,MAAM,0BAA0B,GAAG;IACxC,cAAc,EAAE,yBAAyB;IACzC,SAAS,EAAE;QACT,4BAA4B,EAAE,IAAI;QAClC,YAAY,EAAE,IAAI;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';\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 = getSessionProperties(\n approvedCaip25CaveatValue,\n {\n getCapabilities: hooks.getCapabilities,\n },\n ) as Record<string, Json>;\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"]}
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,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;AAczB,MAAM,oBAAoB,GAAG,yCAAyC,CAAC;AAwBvE;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;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,EAAE,OAAO,EAAE,GAAG,EAAE,EAA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BAAsB,EAAE,IAAI;QAC5B,yBAAyB,EAAE,IAAI;QAC/B,4BAA4B,EAAE,IAAI;QAClC,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 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 GetNonEvmSupportedMethodsHook,\n SortAccountIdsByLastSelectedHook,\n} from './types';\n\nconst SOLANA_CAIP_CHAIN_ID = 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp';\n\nexport type WalletCreateSessionHooks = GetNonEvmSupportedMethodsHook &\n SortAccountIdsByLastSelectedHook & {\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.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 { sessionProperties: approvedSessionProperties = {} } =\n approvedCaip25CaveatValue;\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 trackSessionCreatedEvent: true,\n },\n} satisfies WalletCreateSessionHandler;\n"]}
@@ -16,7 +16,6 @@ const chain_agnostic_permission_1 = require("@metamask/chain-agnostic-permission
16
16
  * @param hooks.getCaveatForOrigin - Function to retrieve a caveat for the origin.
17
17
  * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.
18
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
19
  * @returns Nothing.
21
20
  */
22
21
  async function handleWalletGetSession(_request, response, _next, end, hooks) {
@@ -28,7 +27,7 @@ async function handleWalletGetSession(_request, response, _next, end, hooks) {
28
27
  // noop
29
28
  }
30
29
  if (!caveat) {
31
- response.result = { sessionScopes: {}, sessionProperties: {} };
30
+ response.result = { sessionScopes: {} };
32
31
  return end();
33
32
  }
34
33
  response.result = {
@@ -36,9 +35,6 @@ async function handleWalletGetSession(_request, response, _next, end, hooks) {
36
35
  getNonEvmSupportedMethods: hooks.getNonEvmSupportedMethods,
37
36
  sortAccountIdsByLastSelected: hooks.sortAccountIdsByLastSelected,
38
37
  }),
39
- sessionProperties: (0, chain_agnostic_permission_1.getSessionProperties)(caveat.value, {
40
- getCapabilities: hooks.getCapabilities,
41
- }),
42
38
  };
43
39
  return end();
44
40
  }
@@ -48,7 +44,6 @@ exports.walletGetSessionHandler = {
48
44
  getCaveatForOrigin: true,
49
45
  getNonEvmSupportedMethods: true,
50
46
  sortAccountIdsByLastSelected: true,
51
- getCapabilities: true,
52
47
  },
53
48
  };
54
49
  //# sourceMappingURL=wallet-getSession.cjs.map
@@ -1 +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,IAAA,gDAAoB,EAAC,MAAM,CAAC,KAAK,EAAE;YACpD,eAAe,EAAE,KAAK,CAAC,eAAe;SACvC,CAAyB;KAC3B,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';\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: getSessionProperties(caveat.value, {\n getCapabilities: hooks.getCapabilities,\n }) as Record<string, Json>,\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
+ {"version":3,"file":"wallet-getSession.cjs","sourceRoot":"","sources":["../../src/handlers/wallet-getSession.ts"],"names":[],"mappings":";;;AACA,mFAI6C;AAyB7C;;;;;;;;;;;;;;;GAeG;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,CAAC;QACxC,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;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;KACnC;CACgC,CAAC","sourcesContent":["import type { NormalizedScopesObject } from '@metamask/chain-agnostic-permission';\nimport {\n Caip25CaveatType,\n Caip25EndowmentPermissionName,\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 JsonRpcParams,\n JsonRpcRequest,\n PendingJsonRpcResponse,\n} from '@metamask/utils';\n\nimport type {\n Caip25Caveat,\n GetCaveatForOriginHook,\n GetNonEvmSupportedMethodsHook,\n SortAccountIdsByLastSelectedHook,\n} from './types';\n\ntype WalletGetSessionResult = { sessionScopes: NormalizedScopesObject };\n\nexport type WalletGetSessionHooks = GetCaveatForOriginHook &\n GetNonEvmSupportedMethodsHook &\n SortAccountIdsByLastSelectedHook;\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 * @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: {} };\n return end();\n }\n\n response.result = {\n sessionScopes: getSessionScopes(caveat.value, {\n getNonEvmSupportedMethods: hooks.getNonEvmSupportedMethods,\n sortAccountIdsByLastSelected: hooks.sortAccountIdsByLastSelected,\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 },\n} satisfies WalletGetSessionHandler;\n"]}
@@ -1,12 +1,11 @@
1
1
  import type { NormalizedScopesObject } from "@metamask/chain-agnostic-permission";
2
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";
3
+ import type { JsonRpcParams, JsonRpcRequest, PendingJsonRpcResponse } from "@metamask/utils";
4
+ import type { GetCaveatForOriginHook, GetNonEvmSupportedMethodsHook, SortAccountIdsByLastSelectedHook } from "./types.cjs";
5
5
  type WalletGetSessionResult = {
6
6
  sessionScopes: NormalizedScopesObject;
7
- sessionProperties: Record<string, Json>;
8
7
  };
9
- export type WalletGetSessionHooks = GetCaveatForOriginHook & GetNonEvmSupportedMethodsHook & SortAccountIdsByLastSelectedHook & GetCapabilitiesHook;
8
+ export type WalletGetSessionHooks = GetCaveatForOriginHook & GetNonEvmSupportedMethodsHook & SortAccountIdsByLastSelectedHook;
10
9
  /**
11
10
  * Handler for the `wallet_getSession` RPC method as specified by [CAIP-312](https://chainagnostic.org/CAIPs/caip-312).
12
11
  * The implementation below deviates from the linked spec in that it ignores the `sessionId` param entirely,
@@ -21,7 +20,6 @@ export type WalletGetSessionHooks = GetCaveatForOriginHook & GetNonEvmSupportedM
21
20
  * @param hooks.getCaveatForOrigin - Function to retrieve a caveat for the origin.
22
21
  * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.
23
22
  * @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
23
  * @returns Nothing.
26
24
  */
27
25
  declare function handleWalletGetSession(_request: JsonRpcRequest & {
@@ -36,7 +34,6 @@ export declare const walletGetSessionHandler: {
36
34
  getCaveatForOrigin: true;
37
35
  getNonEvmSupportedMethods: true;
38
36
  sortAccountIdsByLastSelected: true;
39
- getCapabilities: true;
40
37
  };
41
38
  };
42
39
  export {};
@@ -1 +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,oBAAgB;AAEjB,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;;;;;;;;;;;;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BAAqB,EACrB,KAAK,EACL,aAAa,EACb,sBAAsB,EACtB;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CACnB,CAAC;AAEF,eAAO,MAAM,uBAAuB;;;;;;;CAOD,CAAC"}
@@ -1,12 +1,11 @@
1
1
  import type { NormalizedScopesObject } from "@metamask/chain-agnostic-permission";
2
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";
3
+ import type { JsonRpcParams, JsonRpcRequest, PendingJsonRpcResponse } from "@metamask/utils";
4
+ import type { GetCaveatForOriginHook, GetNonEvmSupportedMethodsHook, SortAccountIdsByLastSelectedHook } from "./types.mjs";
5
5
  type WalletGetSessionResult = {
6
6
  sessionScopes: NormalizedScopesObject;
7
- sessionProperties: Record<string, Json>;
8
7
  };
9
- export type WalletGetSessionHooks = GetCaveatForOriginHook & GetNonEvmSupportedMethodsHook & SortAccountIdsByLastSelectedHook & GetCapabilitiesHook;
8
+ export type WalletGetSessionHooks = GetCaveatForOriginHook & GetNonEvmSupportedMethodsHook & SortAccountIdsByLastSelectedHook;
10
9
  /**
11
10
  * Handler for the `wallet_getSession` RPC method as specified by [CAIP-312](https://chainagnostic.org/CAIPs/caip-312).
12
11
  * The implementation below deviates from the linked spec in that it ignores the `sessionId` param entirely,
@@ -21,7 +20,6 @@ export type WalletGetSessionHooks = GetCaveatForOriginHook & GetNonEvmSupportedM
21
20
  * @param hooks.getCaveatForOrigin - Function to retrieve a caveat for the origin.
22
21
  * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.
23
22
  * @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
23
  * @returns Nothing.
26
24
  */
27
25
  declare function handleWalletGetSession(_request: JsonRpcRequest & {
@@ -36,7 +34,6 @@ export declare const walletGetSessionHandler: {
36
34
  getCaveatForOrigin: true;
37
35
  getNonEvmSupportedMethods: true;
38
36
  sortAccountIdsByLastSelected: true;
39
- getCapabilities: true;
40
37
  };
41
38
  };
42
39
  export {};
@@ -1 +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,oBAAgB;AAEjB,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
+ {"version":3,"file":"wallet-getSession.d.mts","sourceRoot":"","sources":["../../src/handlers/wallet-getSession.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,4CAA4C;AAMlF,OAAO,KAAK,EACV,wBAAwB,EACxB,yBAAyB,EACzB,aAAa,EACd,kCAAkC;AACnC,OAAO,KAAK,EACV,aAAa,EACb,cAAc,EACd,sBAAsB,EACvB,wBAAwB;AAEzB,OAAO,KAAK,EAEV,sBAAsB,EACtB,6BAA6B,EAC7B,gCAAgC,EACjC,oBAAgB;AAEjB,KAAK,sBAAsB,GAAG;IAAE,aAAa,EAAE,sBAAsB,CAAA;CAAE,CAAC;AAExE,MAAM,MAAM,qBAAqB,GAAG,sBAAsB,GACxD,6BAA6B,GAC7B,gCAAgC,CAAC;AAEnC;;;;;;;;;;;;;;;GAeG;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,iBAwB7B;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;;;;;;;CAOD,CAAC"}
@@ -1,4 +1,4 @@
1
- import { Caip25CaveatType, Caip25EndowmentPermissionName, getSessionProperties, getSessionScopes } from "@metamask/chain-agnostic-permission";
1
+ import { Caip25CaveatType, Caip25EndowmentPermissionName, 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,
@@ -13,7 +13,6 @@ import { Caip25CaveatType, Caip25EndowmentPermissionName, getSessionProperties,
13
13
  * @param hooks.getCaveatForOrigin - Function to retrieve a caveat for the origin.
14
14
  * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.
15
15
  * @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.
16
- * @param hooks.getCapabilities - A function that returns the capabilities for a given address.
17
16
  * @returns Nothing.
18
17
  */
19
18
  async function handleWalletGetSession(_request, response, _next, end, hooks) {
@@ -25,7 +24,7 @@ async function handleWalletGetSession(_request, response, _next, end, hooks) {
25
24
  // noop
26
25
  }
27
26
  if (!caveat) {
28
- response.result = { sessionScopes: {}, sessionProperties: {} };
27
+ response.result = { sessionScopes: {} };
29
28
  return end();
30
29
  }
31
30
  response.result = {
@@ -33,9 +32,6 @@ async function handleWalletGetSession(_request, response, _next, end, hooks) {
33
32
  getNonEvmSupportedMethods: hooks.getNonEvmSupportedMethods,
34
33
  sortAccountIdsByLastSelected: hooks.sortAccountIdsByLastSelected,
35
34
  }),
36
- sessionProperties: getSessionProperties(caveat.value, {
37
- getCapabilities: hooks.getCapabilities,
38
- }),
39
35
  };
40
36
  return end();
41
37
  }
@@ -45,7 +41,6 @@ export const walletGetSessionHandler = {
45
41
  getCaveatForOrigin: true,
46
42
  getNonEvmSupportedMethods: true,
47
43
  sortAccountIdsByLastSelected: true,
48
- getCapabilities: true,
49
44
  },
50
45
  };
51
46
  //# sourceMappingURL=wallet-getSession.mjs.map
@@ -1 +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,oBAAoB,CAAC,MAAM,CAAC,KAAK,EAAE;YACpD,eAAe,EAAE,KAAK,CAAC,eAAe;SACvC,CAAyB;KAC3B,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';\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: getSessionProperties(caveat.value, {\n getCapabilities: hooks.getCapabilities,\n }) as Record<string, Json>,\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
+ {"version":3,"file":"wallet-getSession.mjs","sourceRoot":"","sources":["../../src/handlers/wallet-getSession.ts"],"names":[],"mappings":"AACA,OAAO,EACL,gBAAgB,EAChB,6BAA6B,EAC7B,gBAAgB,EACjB,4CAA4C;AAyB7C;;;;;;;;;;;;;;;GAeG;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,CAAC;QACxC,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;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;KACnC;CACgC,CAAC","sourcesContent":["import type { NormalizedScopesObject } from '@metamask/chain-agnostic-permission';\nimport {\n Caip25CaveatType,\n Caip25EndowmentPermissionName,\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 JsonRpcParams,\n JsonRpcRequest,\n PendingJsonRpcResponse,\n} from '@metamask/utils';\n\nimport type {\n Caip25Caveat,\n GetCaveatForOriginHook,\n GetNonEvmSupportedMethodsHook,\n SortAccountIdsByLastSelectedHook,\n} from './types';\n\ntype WalletGetSessionResult = { sessionScopes: NormalizedScopesObject };\n\nexport type WalletGetSessionHooks = GetCaveatForOriginHook &\n GetNonEvmSupportedMethodsHook &\n SortAccountIdsByLastSelectedHook;\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 * @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: {} };\n return end();\n }\n\n response.result = {\n sessionScopes: getSessionScopes(caveat.value, {\n getNonEvmSupportedMethods: hooks.getNonEvmSupportedMethods,\n sortAccountIdsByLastSelected: hooks.sortAccountIdsByLastSelected,\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 },\n} satisfies WalletGetSessionHandler;\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/multichain-api-middleware",
3
- "version": "3.1.5-preview-2226dd478",
3
+ "version": "3.1.5-preview-53326764b",
4
4
  "description": "JSON-RPC methods and middleware to support the MetaMask Multichain API",
5
5
  "keywords": [
6
6
  "Ethereum",