@metamask-previews/multichain-api-middleware 2.0.0-preview-95a687acf → 3.0.0-preview-53e60e1a5

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.
Files changed (58) hide show
  1. package/CHANGELOG.md +31 -5
  2. package/dist/handlers/index.cjs +20 -0
  3. package/dist/handlers/index.cjs.map +1 -0
  4. package/dist/handlers/index.d.cts +25 -0
  5. package/dist/handlers/index.d.cts.map +1 -0
  6. package/dist/handlers/index.d.mts +25 -0
  7. package/dist/handlers/index.d.mts.map +1 -0
  8. package/dist/handlers/index.mjs +17 -0
  9. package/dist/handlers/index.mjs.map +1 -0
  10. package/dist/handlers/types.cjs +1 -0
  11. package/dist/handlers/types.cjs.map +1 -1
  12. package/dist/handlers/types.d.cts +13 -9
  13. package/dist/handlers/types.d.cts.map +1 -1
  14. package/dist/handlers/types.d.mts +13 -9
  15. package/dist/handlers/types.d.mts.map +1 -1
  16. package/dist/handlers/types.mjs +1 -0
  17. package/dist/handlers/types.mjs.map +1 -1
  18. package/dist/handlers/wallet-createSession.cjs +5 -6
  19. package/dist/handlers/wallet-createSession.cjs.map +1 -1
  20. package/dist/handlers/wallet-createSession.d.cts +35 -32
  21. package/dist/handlers/wallet-createSession.d.cts.map +1 -1
  22. package/dist/handlers/wallet-createSession.d.mts +35 -32
  23. package/dist/handlers/wallet-createSession.d.mts.map +1 -1
  24. package/dist/handlers/wallet-createSession.mjs +4 -5
  25. package/dist/handlers/wallet-createSession.mjs.map +1 -1
  26. package/dist/handlers/wallet-getSession.cjs +4 -5
  27. package/dist/handlers/wallet-getSession.cjs.map +1 -1
  28. package/dist/handlers/wallet-getSession.d.cts +18 -19
  29. package/dist/handlers/wallet-getSession.d.cts.map +1 -1
  30. package/dist/handlers/wallet-getSession.d.mts +18 -19
  31. package/dist/handlers/wallet-getSession.d.mts.map +1 -1
  32. package/dist/handlers/wallet-getSession.mjs +3 -4
  33. package/dist/handlers/wallet-getSession.mjs.map +1 -1
  34. package/dist/handlers/wallet-invokeMethod.cjs +7 -5
  35. package/dist/handlers/wallet-invokeMethod.cjs.map +1 -1
  36. package/dist/handlers/wallet-invokeMethod.d.cts +32 -31
  37. package/dist/handlers/wallet-invokeMethod.d.cts.map +1 -1
  38. package/dist/handlers/wallet-invokeMethod.d.mts +32 -31
  39. package/dist/handlers/wallet-invokeMethod.d.mts.map +1 -1
  40. package/dist/handlers/wallet-invokeMethod.mjs +7 -5
  41. package/dist/handlers/wallet-invokeMethod.mjs.map +1 -1
  42. package/dist/handlers/wallet-revokeSession.cjs +9 -6
  43. package/dist/handlers/wallet-revokeSession.cjs.map +1 -1
  44. package/dist/handlers/wallet-revokeSession.d.cts +22 -14
  45. package/dist/handlers/wallet-revokeSession.d.cts.map +1 -1
  46. package/dist/handlers/wallet-revokeSession.d.mts +22 -14
  47. package/dist/handlers/wallet-revokeSession.d.mts.map +1 -1
  48. package/dist/handlers/wallet-revokeSession.mjs +8 -5
  49. package/dist/handlers/wallet-revokeSession.mjs.map +1 -1
  50. package/dist/index.cjs +3 -9
  51. package/dist/index.cjs.map +1 -1
  52. package/dist/index.d.cts +2 -4
  53. package/dist/index.d.cts.map +1 -1
  54. package/dist/index.d.mts +2 -4
  55. package/dist/index.d.mts.map +1 -1
  56. package/dist/index.mjs +1 -4
  57. package/dist/index.mjs.map +1 -1
  58. package/package.json +6 -4
package/CHANGELOG.md CHANGED
@@ -9,12 +9,37 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
9
9
 
10
10
  ### Changed
11
11
 
12
- - Bump `@metamask/json-rpc-engine` from `^10.2.3` to `^10.2.4` ([#8317](https://github.com/MetaMask/core/pull/8317))
12
+ - Bump `@metamask/multichain-transactions-controller` from `^7.0.4` to `^7.1.0` ([#8665](https://github.com/MetaMask/core/pull/8665))
13
+ - Bump `@metamask/accounts-controller` from `^37.2.0` to `^38.0.0` ([#8665](https://github.com/MetaMask/core/pull/8665))
14
+
15
+ ## [3.0.0]
16
+
17
+ ### Added
18
+
19
+ - Add `MethodHandlerHooks` type, the intersection of all method handler hook types ([#8583](https://github.com/MetaMask/core/pull/8583))
20
+ - Consumers can use this to type the hooks object passed to `createMethodMiddleware` without restating each handler's hooks individually.
21
+
22
+ ### Changed
23
+
24
+ - **BREAKING:** Consolidate method handlers into a single `methodHandlers` export ([#8583](https://github.com/MetaMask/core/pull/8583))
25
+ - The individual handler exports have been removed. They can still be accessed as properties on the `methodHandlers` export.
26
+ - The new handlers follow the format expected by `createMethodMiddleware` from `@metamask/json-rpc-engine@10.3.0`.
27
+ - The hook types have been updated to cohere with their corresponding MetaMask controller methods.
28
+ - **BREAKING:** Make `trackSessionCreatedEvent` hook required in `wallet_createSession` handler ([#8583](https://github.com/MetaMask/core/pull/8583))
29
+ - If the hook is not required, `null` can be passed instead.
30
+ - Bump `@metamask/json-rpc-engine` from `^10.2.3` to `^10.3.0` ([#8317](https://github.com/MetaMask/core/pull/8317), [#8661](https://github.com/MetaMask/core/pull/8661))
13
31
  - Bump `@metamask/network-controller` from `^30.0.0` to `^30.1.0` ([#8317](https://github.com/MetaMask/core/pull/8317), [#8636](https://github.com/MetaMask/core/pull/8636))
14
- - Bump `@metamask/permission-controller` from `^12.2.1` to `^12.3.0` ([#8317](https://github.com/MetaMask/core/pull/8317))
32
+ - Bump `@metamask/permission-controller` from `^12.2.1` to `^13.0.0` ([#8317](https://github.com/MetaMask/core/pull/8317), [#8661](https://github.com/MetaMask/core/pull/8661))
15
33
  - Bump `@metamask/multichain-transactions-controller` from `^7.0.3` to `^7.0.4` ([#8325](https://github.com/MetaMask/core/pull/8325))
16
34
  - Bump `@metamask/controller-utils` from `^11.19.0` to `^11.20.0` ([#8344](https://github.com/MetaMask/core/pull/8344))
17
35
 
36
+ ### Fixed
37
+
38
+ - `wallet_invokeMethod` fails early with an `invalidParams` error when the `params` object is not an object ([#8583](https://github.com/MetaMask/core/pull/8583))
39
+ - Previously it would fail with a less specific error.
40
+ - `wallet_revokeSession` now returns `true` when no active session exists and specific scopes are requested, consistent with its full-revoke behavior ([#8583](https://github.com/MetaMask/core/pull/8583))
41
+ - Previously it would return an internal error.
42
+
18
43
  ## [2.0.0]
19
44
 
20
45
  ### Added
@@ -114,7 +139,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
114
139
  ### Changed
115
140
 
116
141
  - Add partial permission revoke into `wallet_revokeSession` ([#6668](https://github.com/MetaMask/core/pull/6668))
117
- - Bump `@metamask/chain-agnostic-permission` from `1.0.0` to `1.1.1` ([#6241](https://github.com/MetaMask/core/pull/6241), [#6345](https://github.com/MetaMask/core/pull/6241))
142
+ - Bump `@metamask/chain-agnostic-permission` from `1.0.0` to `1.1.1` ([#6241](https://github.com/MetaMask/core/pull/6241), [#6345](https://github.com/MetaMask/core/pull/6345))
118
143
  - Bump `@metamask/controller-utils` from `^11.10.0` to `^11.14.0` ([#6069](https://github.com/MetaMask/core/pull/6069), [#6303](https://github.com/MetaMask/core/pull/6303), [#6620](https://github.com/MetaMask/core/pull/6620), [#6629](https://github.com/MetaMask/core/pull/6629))
119
144
  - Bump `@metamask/network-controller` from `^24.0.0` to `^24.2.0` ([#6148](https://github.com/MetaMask/core/pull/6148), [#6303](https://github.com/MetaMask/core/pull/6303), [#6678](https://github.com/MetaMask/core/pull/6678))
120
145
  - Bump `@metamask/utils` from `^11.2.0` to `^11.4.2` ([#6054](https://github.com/MetaMask/core/pull/6054))
@@ -146,7 +171,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
146
171
 
147
172
  ### Changed
148
173
 
149
- - Bump `@metamask/chain-agnostic-permission` to `^0.7.0` ([#5715](https://github.com/MetaMask/core/pull/5715),[#5760](https://github.com/MetaMask/core/pull/5760), [#5818](https://github.com/MetaMask/core/pull/5818))
174
+ - Bump `@metamask/chain-agnostic-permission` to `^0.7.0` ([#5715](https://github.com/MetaMask/core/pull/5715), [#5760](https://github.com/MetaMask/core/pull/5760), [#5818](https://github.com/MetaMask/core/pull/5818))
150
175
  - Bump `@metamask/api-specs` to `^0.14.0` ([#5817](https://github.com/MetaMask/core/pull/5817))
151
176
  - Bump `@metamask/controller-utils` to `^11.9.0` ([#5765](https://github.com/MetaMask/core/pull/5765), [#5812](https://github.com/MetaMask/core/pull/5812))
152
177
  - Bump `@metamask/network-controller` to `^23.5.0` ([#5765](https://github.com/MetaMask/core/pull/5765), [#5812](https://github.com/MetaMask/core/pull/5812))
@@ -180,7 +205,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
180
205
 
181
206
  - Initial release
182
207
 
183
- [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/multichain-api-middleware@2.0.0...HEAD
208
+ [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/multichain-api-middleware@3.0.0...HEAD
209
+ [3.0.0]: https://github.com/MetaMask/core/compare/@metamask/multichain-api-middleware@2.0.0...@metamask/multichain-api-middleware@3.0.0
184
210
  [2.0.0]: https://github.com/MetaMask/core/compare/@metamask/multichain-api-middleware@1.2.7...@metamask/multichain-api-middleware@2.0.0
185
211
  [1.2.7]: https://github.com/MetaMask/core/compare/@metamask/multichain-api-middleware@1.2.6...@metamask/multichain-api-middleware@1.2.7
186
212
  [1.2.6]: https://github.com/MetaMask/core/compare/@metamask/multichain-api-middleware@1.2.5...@metamask/multichain-api-middleware@1.2.6
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.methodHandlers = void 0;
4
+ const wallet_createSession_1 = require("./wallet-createSession.cjs");
5
+ const wallet_getSession_1 = require("./wallet-getSession.cjs");
6
+ const wallet_invokeMethod_1 = require("./wallet-invokeMethod.cjs");
7
+ const wallet_revokeSession_1 = require("./wallet-revokeSession.cjs");
8
+ const MethodNames = {
9
+ WalletCreateSession: 'wallet_createSession',
10
+ WalletGetSession: 'wallet_getSession',
11
+ WalletInvokeMethod: 'wallet_invokeMethod',
12
+ WalletRevokeSession: 'wallet_revokeSession',
13
+ };
14
+ exports.methodHandlers = {
15
+ [MethodNames.WalletCreateSession]: wallet_createSession_1.walletCreateSessionHandler,
16
+ [MethodNames.WalletGetSession]: wallet_getSession_1.walletGetSessionHandler,
17
+ [MethodNames.WalletInvokeMethod]: wallet_invokeMethod_1.walletInvokeMethodHandler,
18
+ [MethodNames.WalletRevokeSession]: wallet_revokeSession_1.walletRevokeSessionHandler,
19
+ };
20
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/handlers/index.ts"],"names":[],"mappings":";;;AAGA,qEAAoE;AAEpE,+DAA8D;AAE9D,mEAAkE;AAElE,qEAAoE;AASpE,MAAM,WAAW,GAAG;IAClB,mBAAmB,EAAE,sBAAsB;IAC3C,gBAAgB,EAAE,mBAAmB;IACrC,kBAAkB,EAAE,qBAAqB;IACzC,mBAAmB,EAAE,sBAAsB;CACnC,CAAC;AASE,QAAA,cAAc,GAA6B;IACtD,CAAC,WAAW,CAAC,mBAAmB,CAAC,EAAE,iDAA0B;IAC7D,CAAC,WAAW,CAAC,gBAAgB,CAAC,EAAE,2CAAuB;IACvD,CAAC,WAAW,CAAC,kBAAkB,CAAC,EAAE,+CAAyB;IAC3D,CAAC,WAAW,CAAC,mBAAmB,CAAC,EAAE,iDAA0B;CAC9D,CAAC","sourcesContent":["import type { UnionToIntersection } from '@metamask/json-rpc-engine/v2';\n\nimport type { WalletCreateSessionHooks } from './wallet-createSession';\nimport { walletCreateSessionHandler } from './wallet-createSession';\nimport type { WalletGetSessionHooks } from './wallet-getSession';\nimport { walletGetSessionHandler } from './wallet-getSession';\nimport type { WalletInvokeMethodHooks } from './wallet-invokeMethod';\nimport { walletInvokeMethodHandler } from './wallet-invokeMethod';\nimport type { WalletRevokeSessionHooks } from './wallet-revokeSession';\nimport { walletRevokeSessionHandler } from './wallet-revokeSession';\n\nexport type MethodHandlerHooks = UnionToIntersection<\n | WalletCreateSessionHooks\n | WalletGetSessionHooks\n | WalletInvokeMethodHooks\n | WalletRevokeSessionHooks\n>;\n\nconst MethodNames = {\n WalletCreateSession: 'wallet_createSession',\n WalletGetSession: 'wallet_getSession',\n WalletInvokeMethod: 'wallet_invokeMethod',\n WalletRevokeSession: 'wallet_revokeSession',\n} as const;\n\ntype MethodHandlers = {\n [MethodNames.WalletCreateSession]: typeof walletCreateSessionHandler;\n [MethodNames.WalletGetSession]: typeof walletGetSessionHandler;\n [MethodNames.WalletInvokeMethod]: typeof walletInvokeMethodHandler;\n [MethodNames.WalletRevokeSession]: typeof walletRevokeSessionHandler;\n};\n\nexport const methodHandlers: Readonly<MethodHandlers> = {\n [MethodNames.WalletCreateSession]: walletCreateSessionHandler,\n [MethodNames.WalletGetSession]: walletGetSessionHandler,\n [MethodNames.WalletInvokeMethod]: walletInvokeMethodHandler,\n [MethodNames.WalletRevokeSession]: walletRevokeSessionHandler,\n};\n"]}
@@ -0,0 +1,25 @@
1
+ import type { UnionToIntersection } from "@metamask/json-rpc-engine/v2";
2
+ import type { WalletCreateSessionHooks } from "./wallet-createSession.cjs";
3
+ import { walletCreateSessionHandler } from "./wallet-createSession.cjs";
4
+ import type { WalletGetSessionHooks } from "./wallet-getSession.cjs";
5
+ import { walletGetSessionHandler } from "./wallet-getSession.cjs";
6
+ import type { WalletInvokeMethodHooks } from "./wallet-invokeMethod.cjs";
7
+ import { walletInvokeMethodHandler } from "./wallet-invokeMethod.cjs";
8
+ import type { WalletRevokeSessionHooks } from "./wallet-revokeSession.cjs";
9
+ import { walletRevokeSessionHandler } from "./wallet-revokeSession.cjs";
10
+ export type MethodHandlerHooks = UnionToIntersection<WalletCreateSessionHooks | WalletGetSessionHooks | WalletInvokeMethodHooks | WalletRevokeSessionHooks>;
11
+ declare const MethodNames: {
12
+ readonly WalletCreateSession: "wallet_createSession";
13
+ readonly WalletGetSession: "wallet_getSession";
14
+ readonly WalletInvokeMethod: "wallet_invokeMethod";
15
+ readonly WalletRevokeSession: "wallet_revokeSession";
16
+ };
17
+ type MethodHandlers = {
18
+ [MethodNames.WalletCreateSession]: typeof walletCreateSessionHandler;
19
+ [MethodNames.WalletGetSession]: typeof walletGetSessionHandler;
20
+ [MethodNames.WalletInvokeMethod]: typeof walletInvokeMethodHandler;
21
+ [MethodNames.WalletRevokeSession]: typeof walletRevokeSessionHandler;
22
+ };
23
+ export declare const methodHandlers: Readonly<MethodHandlers>;
24
+ export {};
25
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../src/handlers/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,qCAAqC;AAExE,OAAO,KAAK,EAAE,wBAAwB,EAAE,mCAA+B;AACvE,OAAO,EAAE,0BAA0B,EAAE,mCAA+B;AACpE,OAAO,KAAK,EAAE,qBAAqB,EAAE,gCAA4B;AACjE,OAAO,EAAE,uBAAuB,EAAE,gCAA4B;AAC9D,OAAO,KAAK,EAAE,uBAAuB,EAAE,kCAA8B;AACrE,OAAO,EAAE,yBAAyB,EAAE,kCAA8B;AAClE,OAAO,KAAK,EAAE,wBAAwB,EAAE,mCAA+B;AACvE,OAAO,EAAE,0BAA0B,EAAE,mCAA+B;AAEpE,MAAM,MAAM,kBAAkB,GAAG,mBAAmB,CAChD,wBAAwB,GACxB,qBAAqB,GACrB,uBAAuB,GACvB,wBAAwB,CAC3B,CAAC;AAEF,QAAA,MAAM,WAAW;;;;;CAKP,CAAC;AAEX,KAAK,cAAc,GAAG;IACpB,CAAC,WAAW,CAAC,mBAAmB,CAAC,EAAE,OAAO,0BAA0B,CAAC;IACrE,CAAC,WAAW,CAAC,gBAAgB,CAAC,EAAE,OAAO,uBAAuB,CAAC;IAC/D,CAAC,WAAW,CAAC,kBAAkB,CAAC,EAAE,OAAO,yBAAyB,CAAC;IACnE,CAAC,WAAW,CAAC,mBAAmB,CAAC,EAAE,OAAO,0BAA0B,CAAC;CACtE,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,QAAQ,CAAC,cAAc,CAKnD,CAAC"}
@@ -0,0 +1,25 @@
1
+ import type { UnionToIntersection } from "@metamask/json-rpc-engine/v2";
2
+ import type { WalletCreateSessionHooks } from "./wallet-createSession.mjs";
3
+ import { walletCreateSessionHandler } from "./wallet-createSession.mjs";
4
+ import type { WalletGetSessionHooks } from "./wallet-getSession.mjs";
5
+ import { walletGetSessionHandler } from "./wallet-getSession.mjs";
6
+ import type { WalletInvokeMethodHooks } from "./wallet-invokeMethod.mjs";
7
+ import { walletInvokeMethodHandler } from "./wallet-invokeMethod.mjs";
8
+ import type { WalletRevokeSessionHooks } from "./wallet-revokeSession.mjs";
9
+ import { walletRevokeSessionHandler } from "./wallet-revokeSession.mjs";
10
+ export type MethodHandlerHooks = UnionToIntersection<WalletCreateSessionHooks | WalletGetSessionHooks | WalletInvokeMethodHooks | WalletRevokeSessionHooks>;
11
+ declare const MethodNames: {
12
+ readonly WalletCreateSession: "wallet_createSession";
13
+ readonly WalletGetSession: "wallet_getSession";
14
+ readonly WalletInvokeMethod: "wallet_invokeMethod";
15
+ readonly WalletRevokeSession: "wallet_revokeSession";
16
+ };
17
+ type MethodHandlers = {
18
+ [MethodNames.WalletCreateSession]: typeof walletCreateSessionHandler;
19
+ [MethodNames.WalletGetSession]: typeof walletGetSessionHandler;
20
+ [MethodNames.WalletInvokeMethod]: typeof walletInvokeMethodHandler;
21
+ [MethodNames.WalletRevokeSession]: typeof walletRevokeSessionHandler;
22
+ };
23
+ export declare const methodHandlers: Readonly<MethodHandlers>;
24
+ export {};
25
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/handlers/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,qCAAqC;AAExE,OAAO,KAAK,EAAE,wBAAwB,EAAE,mCAA+B;AACvE,OAAO,EAAE,0BAA0B,EAAE,mCAA+B;AACpE,OAAO,KAAK,EAAE,qBAAqB,EAAE,gCAA4B;AACjE,OAAO,EAAE,uBAAuB,EAAE,gCAA4B;AAC9D,OAAO,KAAK,EAAE,uBAAuB,EAAE,kCAA8B;AACrE,OAAO,EAAE,yBAAyB,EAAE,kCAA8B;AAClE,OAAO,KAAK,EAAE,wBAAwB,EAAE,mCAA+B;AACvE,OAAO,EAAE,0BAA0B,EAAE,mCAA+B;AAEpE,MAAM,MAAM,kBAAkB,GAAG,mBAAmB,CAChD,wBAAwB,GACxB,qBAAqB,GACrB,uBAAuB,GACvB,wBAAwB,CAC3B,CAAC;AAEF,QAAA,MAAM,WAAW;;;;;CAKP,CAAC;AAEX,KAAK,cAAc,GAAG;IACpB,CAAC,WAAW,CAAC,mBAAmB,CAAC,EAAE,OAAO,0BAA0B,CAAC;IACrE,CAAC,WAAW,CAAC,gBAAgB,CAAC,EAAE,OAAO,uBAAuB,CAAC;IAC/D,CAAC,WAAW,CAAC,kBAAkB,CAAC,EAAE,OAAO,yBAAyB,CAAC;IACnE,CAAC,WAAW,CAAC,mBAAmB,CAAC,EAAE,OAAO,0BAA0B,CAAC;CACtE,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,QAAQ,CAAC,cAAc,CAKnD,CAAC"}
@@ -0,0 +1,17 @@
1
+ import { walletCreateSessionHandler } from "./wallet-createSession.mjs";
2
+ import { walletGetSessionHandler } from "./wallet-getSession.mjs";
3
+ import { walletInvokeMethodHandler } from "./wallet-invokeMethod.mjs";
4
+ import { walletRevokeSessionHandler } from "./wallet-revokeSession.mjs";
5
+ const MethodNames = {
6
+ WalletCreateSession: 'wallet_createSession',
7
+ WalletGetSession: 'wallet_getSession',
8
+ WalletInvokeMethod: 'wallet_invokeMethod',
9
+ WalletRevokeSession: 'wallet_revokeSession',
10
+ };
11
+ export const methodHandlers = {
12
+ [MethodNames.WalletCreateSession]: walletCreateSessionHandler,
13
+ [MethodNames.WalletGetSession]: walletGetSessionHandler,
14
+ [MethodNames.WalletInvokeMethod]: walletInvokeMethodHandler,
15
+ [MethodNames.WalletRevokeSession]: walletRevokeSessionHandler,
16
+ };
17
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/handlers/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,0BAA0B,EAAE,mCAA+B;AAEpE,OAAO,EAAE,uBAAuB,EAAE,gCAA4B;AAE9D,OAAO,EAAE,yBAAyB,EAAE,kCAA8B;AAElE,OAAO,EAAE,0BAA0B,EAAE,mCAA+B;AASpE,MAAM,WAAW,GAAG;IAClB,mBAAmB,EAAE,sBAAsB;IAC3C,gBAAgB,EAAE,mBAAmB;IACrC,kBAAkB,EAAE,qBAAqB;IACzC,mBAAmB,EAAE,sBAAsB;CACnC,CAAC;AASX,MAAM,CAAC,MAAM,cAAc,GAA6B;IACtD,CAAC,WAAW,CAAC,mBAAmB,CAAC,EAAE,0BAA0B;IAC7D,CAAC,WAAW,CAAC,gBAAgB,CAAC,EAAE,uBAAuB;IACvD,CAAC,WAAW,CAAC,kBAAkB,CAAC,EAAE,yBAAyB;IAC3D,CAAC,WAAW,CAAC,mBAAmB,CAAC,EAAE,0BAA0B;CAC9D,CAAC","sourcesContent":["import type { UnionToIntersection } from '@metamask/json-rpc-engine/v2';\n\nimport type { WalletCreateSessionHooks } from './wallet-createSession';\nimport { walletCreateSessionHandler } from './wallet-createSession';\nimport type { WalletGetSessionHooks } from './wallet-getSession';\nimport { walletGetSessionHandler } from './wallet-getSession';\nimport type { WalletInvokeMethodHooks } from './wallet-invokeMethod';\nimport { walletInvokeMethodHandler } from './wallet-invokeMethod';\nimport type { WalletRevokeSessionHooks } from './wallet-revokeSession';\nimport { walletRevokeSessionHandler } from './wallet-revokeSession';\n\nexport type MethodHandlerHooks = UnionToIntersection<\n | WalletCreateSessionHooks\n | WalletGetSessionHooks\n | WalletInvokeMethodHooks\n | WalletRevokeSessionHooks\n>;\n\nconst MethodNames = {\n WalletCreateSession: 'wallet_createSession',\n WalletGetSession: 'wallet_getSession',\n WalletInvokeMethod: 'wallet_invokeMethod',\n WalletRevokeSession: 'wallet_revokeSession',\n} as const;\n\ntype MethodHandlers = {\n [MethodNames.WalletCreateSession]: typeof walletCreateSessionHandler;\n [MethodNames.WalletGetSession]: typeof walletGetSessionHandler;\n [MethodNames.WalletInvokeMethod]: typeof walletInvokeMethodHandler;\n [MethodNames.WalletRevokeSession]: typeof walletRevokeSessionHandler;\n};\n\nexport const methodHandlers: Readonly<MethodHandlers> = {\n [MethodNames.WalletCreateSession]: walletCreateSessionHandler,\n [MethodNames.WalletGetSession]: walletGetSessionHandler,\n [MethodNames.WalletInvokeMethod]: walletInvokeMethodHandler,\n [MethodNames.WalletRevokeSession]: walletRevokeSessionHandler,\n};\n"]}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MultichainApiNotifications = void 0;
4
+ const chain_agnostic_permission_1 = require("@metamask/chain-agnostic-permission");
4
5
  /**
5
6
  * Multichain API notifications currently supported by/known to the wallet.
6
7
  */
@@ -1 +1 @@
1
- {"version":3,"file":"types.cjs","sourceRoot":"","sources":["../../src/handlers/types.ts"],"names":[],"mappings":";;;AAWA;;GAEG;AACH,IAAY,0BAGX;AAHD,WAAY,0BAA0B;IACpC,sEAAwC,CAAA;IACxC,4DAA8B,CAAA;AAChC,CAAC,EAHW,0BAA0B,0CAA1B,0BAA0B,QAGrC","sourcesContent":["import type {\n Caip25CaveatType,\n Caip25CaveatValue,\n} from '@metamask/chain-agnostic-permission';\nimport type {\n Caveat,\n CaveatSpecificationConstraint,\n PermissionController,\n PermissionSpecificationConstraint,\n} from '@metamask/permission-controller';\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}\ntype AbstractPermissionController = PermissionController<\n PermissionSpecificationConstraint,\n CaveatSpecificationConstraint\n>;\n\nexport type GrantedPermissions = Awaited<\n ReturnType<AbstractPermissionController['requestPermissions']>\n>[0];\n\nexport type WalletRevokeSessionHooks = {\n revokePermissionForOrigin: (permissionName: string) => void;\n updateCaveat: (\n target: string,\n caveatType: string,\n caveatValue: Caip25CaveatValue,\n ) => void;\n getCaveatForOrigin: (\n endowmentPermissionName: string,\n caveatType: string,\n ) => Caveat<typeof Caip25CaveatType, Caip25CaveatValue>;\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"]}
@@ -1,5 +1,7 @@
1
- import type { Caip25CaveatType, Caip25CaveatValue } from "@metamask/chain-agnostic-permission";
2
- import type { Caveat, CaveatSpecificationConstraint, PermissionController, PermissionSpecificationConstraint } from "@metamask/permission-controller";
1
+ import { Caip25CaveatType, Caip25CaveatValue } from "@metamask/chain-agnostic-permission";
2
+ import type { GenericPermissionController, Caveat } from "@metamask/permission-controller";
3
+ import type { MultichainRoutingService } from "@metamask/snaps-controllers";
4
+ import type { CaipAccountId } from "@metamask/utils";
3
5
  /**
4
6
  * Multichain API notifications currently supported by/known to the wallet.
5
7
  */
@@ -7,12 +9,14 @@ export declare enum MultichainApiNotifications {
7
9
  sessionChanged = "wallet_sessionChanged",
8
10
  walletNotify = "wallet_notify"
9
11
  }
10
- type AbstractPermissionController = PermissionController<PermissionSpecificationConstraint, CaveatSpecificationConstraint>;
11
- export type GrantedPermissions = Awaited<ReturnType<AbstractPermissionController['requestPermissions']>>[0];
12
- export type WalletRevokeSessionHooks = {
13
- revokePermissionForOrigin: (permissionName: string) => void;
14
- updateCaveat: (target: string, caveatType: string, caveatValue: Caip25CaveatValue) => void;
15
- getCaveatForOrigin: (endowmentPermissionName: string, caveatType: string) => Caveat<typeof Caip25CaveatType, Caip25CaveatValue>;
12
+ export type Caip25Caveat = Caveat<typeof Caip25CaveatType, Caip25CaveatValue>;
13
+ export type GetCaveatForOriginHook = {
14
+ getCaveatForOrigin: (endowmentPermissionName: string, caveatType: string) => ReturnType<GenericPermissionController['getCaveat']>;
15
+ };
16
+ export type GetNonEvmSupportedMethodsHook = {
17
+ getNonEvmSupportedMethods: MultichainRoutingService['getSupportedMethods'];
18
+ };
19
+ export type SortAccountIdsByLastSelectedHook = {
20
+ sortAccountIdsByLastSelected: (accounts: CaipAccountId[]) => CaipAccountId[];
16
21
  };
17
- export {};
18
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,KAAK,EACV,gBAAgB,EAChB,iBAAiB,EAClB,4CAA4C;AAC7C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M,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,5 +1,7 @@
1
- import type { Caip25CaveatType, Caip25CaveatValue } from "@metamask/chain-agnostic-permission";
2
- import type { Caveat, CaveatSpecificationConstraint, PermissionController, PermissionSpecificationConstraint } from "@metamask/permission-controller";
1
+ import { Caip25CaveatType, Caip25CaveatValue } from "@metamask/chain-agnostic-permission";
2
+ import type { GenericPermissionController, Caveat } from "@metamask/permission-controller";
3
+ import type { MultichainRoutingService } from "@metamask/snaps-controllers";
4
+ import type { CaipAccountId } from "@metamask/utils";
3
5
  /**
4
6
  * Multichain API notifications currently supported by/known to the wallet.
5
7
  */
@@ -7,12 +9,14 @@ export declare enum MultichainApiNotifications {
7
9
  sessionChanged = "wallet_sessionChanged",
8
10
  walletNotify = "wallet_notify"
9
11
  }
10
- type AbstractPermissionController = PermissionController<PermissionSpecificationConstraint, CaveatSpecificationConstraint>;
11
- export type GrantedPermissions = Awaited<ReturnType<AbstractPermissionController['requestPermissions']>>[0];
12
- export type WalletRevokeSessionHooks = {
13
- revokePermissionForOrigin: (permissionName: string) => void;
14
- updateCaveat: (target: string, caveatType: string, caveatValue: Caip25CaveatValue) => void;
15
- getCaveatForOrigin: (endowmentPermissionName: string, caveatType: string) => Caveat<typeof Caip25CaveatType, Caip25CaveatValue>;
12
+ export type Caip25Caveat = Caveat<typeof Caip25CaveatType, Caip25CaveatValue>;
13
+ export type GetCaveatForOriginHook = {
14
+ getCaveatForOrigin: (endowmentPermissionName: string, caveatType: string) => ReturnType<GenericPermissionController['getCaveat']>;
15
+ };
16
+ export type GetNonEvmSupportedMethodsHook = {
17
+ getNonEvmSupportedMethods: MultichainRoutingService['getSupportedMethods'];
18
+ };
19
+ export type SortAccountIdsByLastSelectedHook = {
20
+ sortAccountIdsByLastSelected: (accounts: CaipAccountId[]) => CaipAccountId[];
16
21
  };
17
- export {};
18
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,KAAK,EACV,gBAAgB,EAChB,iBAAiB,EAClB,4CAA4C;AAC7C,OAAO,KAAK,EACV,MAAM,EACN,6BAA6B,EAC7B,oBAAoB,EACpB,iCAAiC,EAClC,wCAAwC;AAEzC;;GAEG;AACH,oBAAY,0BAA0B;IACpC,cAAc,0BAA0B;IACxC,YAAY,kBAAkB;CAC/B;AACD,KAAK,4BAA4B,GAAG,oBAAoB,CACtD,iCAAiC,EACjC,6BAA6B,CAC9B,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,OAAO,CACtC,UAAU,CAAC,4BAA4B,CAAC,oBAAoB,CAAC,CAAC,CAC/D,CAAC,CAAC,CAAC,CAAC;AAEL,MAAM,MAAM,wBAAwB,GAAG;IACrC,yBAAyB,EAAE,CAAC,cAAc,EAAE,MAAM,KAAK,IAAI,CAAC;IAC5D,YAAY,EAAE,CACZ,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,iBAAiB,KAC3B,IAAI,CAAC;IACV,kBAAkB,EAAE,CAClB,uBAAuB,EAAE,MAAM,EAC/B,UAAU,EAAE,MAAM,KACf,MAAM,CAAC,OAAO,gBAAgB,EAAE,iBAAiB,CAAC,CAAC;CACzD,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,3 +1,4 @@
1
+ import { Caip25CaveatType } from "@metamask/chain-agnostic-permission";
1
2
  /**
2
3
  * Multichain API notifications currently supported by/known to the wallet.
3
4
  */
@@ -1 +1 @@
1
- {"version":3,"file":"types.mjs","sourceRoot":"","sources":["../../src/handlers/types.ts"],"names":[],"mappings":"AAWA;;GAEG;AACH,MAAM,CAAN,IAAY,0BAGX;AAHD,WAAY,0BAA0B;IACpC,sEAAwC,CAAA;IACxC,4DAA8B,CAAA;AAChC,CAAC,EAHW,0BAA0B,KAA1B,0BAA0B,QAGrC","sourcesContent":["import type {\n Caip25CaveatType,\n Caip25CaveatValue,\n} from '@metamask/chain-agnostic-permission';\nimport type {\n Caveat,\n CaveatSpecificationConstraint,\n PermissionController,\n PermissionSpecificationConstraint,\n} from '@metamask/permission-controller';\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}\ntype AbstractPermissionController = PermissionController<\n PermissionSpecificationConstraint,\n CaveatSpecificationConstraint\n>;\n\nexport type GrantedPermissions = Awaited<\n ReturnType<AbstractPermissionController['requestPermissions']>\n>[0];\n\nexport type WalletRevokeSessionHooks = {\n revokePermissionForOrigin: (permissionName: string) => void;\n updateCaveat: (\n target: string,\n caveatType: string,\n caveatValue: Caip25CaveatValue,\n ) => void;\n getCaveatForOrigin: (\n endowmentPermissionName: string,\n caveatType: string,\n ) => Caveat<typeof Caip25CaveatType, Caip25CaveatValue>;\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"]}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.walletCreateSession = void 0;
3
+ exports.walletCreateSessionHandler = void 0;
4
4
  const chain_agnostic_permission_1 = require("@metamask/chain-agnostic-permission");
5
5
  const controller_utils_1 = require("@metamask/controller-utils");
6
6
  const permission_controller_1 = require("@metamask/permission-controller");
@@ -30,10 +30,10 @@ 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.trackSessionCreatedEvent - An optional hook for platform specific logic to run. Can be undefined.
33
+ * @param hooks.trackSessionCreatedEvent - An optional hook for platform specific logic to run.
34
34
  * @returns A promise with wallet_createSession handler
35
35
  */
36
- async function walletCreateSessionHandler(req, res, _next, end, hooks) {
36
+ async function handleWalletCreateSession(req, res, _next, end, hooks) {
37
37
  if (!(0, utils_1.isPlainObject)(req.params)) {
38
38
  return end((0, permission_controller_1.invalidParams)({ data: { request: req } }));
39
39
  }
@@ -159,9 +159,8 @@ async function walletCreateSessionHandler(req, res, _next, end, hooks) {
159
159
  return end(err);
160
160
  }
161
161
  }
162
- exports.walletCreateSession = {
163
- methodNames: ['wallet_createSession'],
164
- implementation: walletCreateSessionHandler,
162
+ exports.walletCreateSessionHandler = {
163
+ implementation: handleWalletCreateSession,
165
164
  hookNames: {
166
165
  findNetworkClientIdByChainId: true,
167
166
  listAccounts: true,
@@ -1 +1 @@
1
- {"version":3,"file":"wallet-createS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AAK,CAAC,4BAA4B;SACjE,CAAC,CAAC;QAEH,MAAM,EAAE,iBAAiB,EAAE,yBAAyB,GAAG,EAAE,EAAE,GACzD,yBAAyB,CAAC;QAE5B,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;AAEY,QAAA,mBAAmB,GAAG;IACjC,WAAW,EAAE,CAAC,sBAAsB,CAAC;IACrC,cAAc,EAAE,0BAA0B;IAC1C,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;CACF,CAAC","sourcesContent":["import {\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 JsonRpcEngineEndCallback,\n JsonRpcEngineNextCallback,\n} from '@metamask/json-rpc-engine';\nimport type { NetworkController } from '@metamask/network-controller';\nimport { invalidParams } from '@metamask/permission-controller';\nimport type { RequestedPermissions } from '@metamask/permission-controller';\nimport { JsonRpcError, rpcErrors } from '@metamask/rpc-errors';\nimport {\n isPlainObject,\n KnownCaipNamespace,\n parseCaipAccountId,\n} from '@metamask/utils';\nimport type {\n CaipAccountId,\n CaipChainId,\n Hex,\n Json,\n JsonRpcRequest,\n JsonRpcSuccess,\n} from '@metamask/utils';\n\nimport type { GrantedPermissions } from './types';\n\nconst SOLANA_CAIP_CHAIN_ID = 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp';\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. Can be undefined.\n * @returns A promise with wallet_createSession handler\n */\nasync function walletCreateSessionHandler(\n req: JsonRpcRequest<Caip25Authorization> & { origin: string },\n res: JsonRpcSuccess<{\n sessionScopes: NormalizedScopesObject;\n sessionProperties?: Record<string, Json>;\n }>,\n _next: JsonRpcEngineNextCallback,\n end: JsonRpcEngineEndCallback,\n hooks: {\n listAccounts: () => { address: string }[];\n findNetworkClientIdByChainId: NetworkController['findNetworkClientIdByChainId'];\n requestPermissionsForOrigin: (\n requestedPermissions: RequestedPermissions,\n metadata?: Record<string, Json>,\n ) => Promise<[GrantedPermissions]>;\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n isNonEvmScopeSupported: (scope: CaipChainId) => boolean;\n getNonEvmAccountAddresses: (scope: CaipChainId) => CaipAccountId[];\n sortAccountIdsByLastSelected: (\n accounts: CaipAccountId[],\n ) => CaipAccountId[];\n trackSessionCreatedEvent?: (\n approvedCaip25CaveatValue: Caip25CaveatValue,\n ) => void;\n },\n) {\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 const walletCreateSession = {\n methodNames: ['wallet_createSession'],\n implementation: walletCreateSessionHandler,\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};\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,GAAG,yCAAyC,CAAC;AAwBvE;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;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,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CAAC,yDAA6B,CAAC,CAAC;QACpD,MAAM,yBAAyB,GAAG,wBAAwB,EAAE,OAAO,EAAE,IAAI,CACvE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,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,EAAE,iBAAiB,EAAE,yBAAyB,GAAG,EAAE,EAAE,GACzD,yBAAyB,CAAC;QAE5B,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,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"]}
@@ -1,9 +1,24 @@
1
+ import type { AccountsController } from "@metamask/accounts-controller";
1
2
  import type { Caip25Authorization, NormalizedScopesObject, Caip25CaveatValue } from "@metamask/chain-agnostic-permission";
2
- import type { JsonRpcEngineEndCallback, JsonRpcEngineNextCallback } from "@metamask/json-rpc-engine";
3
+ import type { MethodHandler, JsonRpcEngineEndCallback, JsonRpcEngineNextCallback } from "@metamask/json-rpc-engine";
3
4
  import type { NetworkController } from "@metamask/network-controller";
4
- import type { RequestedPermissions } from "@metamask/permission-controller";
5
- import type { CaipAccountId, CaipChainId, Json, JsonRpcRequest, JsonRpcSuccess } from "@metamask/utils";
6
- import type { GrantedPermissions } from "./types.cjs";
5
+ import type { GenericPermissionController, RequestedPermissions } from "@metamask/permission-controller";
6
+ import type { MultichainRoutingService } from "@metamask/snaps-controllers";
7
+ import type { Json, JsonRpcRequest, PendingJsonRpcResponse } from "@metamask/utils";
8
+ import type { GetNonEvmSupportedMethodsHook, SortAccountIdsByLastSelectedHook } from "./types.cjs";
9
+ export type WalletCreateSessionHooks = GetNonEvmSupportedMethodsHook & SortAccountIdsByLastSelectedHook & {
10
+ listAccounts: AccountsController['listAccounts'];
11
+ findNetworkClientIdByChainId: NetworkController['findNetworkClientIdByChainId'];
12
+ requestPermissionsForOrigin: (requestedPermissions: RequestedPermissions, metadata?: Record<string, Json>) => ReturnType<GenericPermissionController['requestPermissions']>;
13
+ isNonEvmScopeSupported: MultichainRoutingService['isSupportedScope'];
14
+ getNonEvmAccountAddresses: MultichainRoutingService['getSupportedAccounts'];
15
+ trackSessionCreatedEvent: ((approvedCaip25CaveatValue: Caip25CaveatValue) => void) | null;
16
+ };
17
+ type Params = Caip25Authorization;
18
+ type Result = {
19
+ sessionScopes: NormalizedScopesObject;
20
+ sessionProperties?: Record<string, Json>;
21
+ };
7
22
  /**
8
23
  * Handler for the `wallet_createSession` RPC method which is responsible
9
24
  * for prompting for approval and granting a CAIP-25 permission.
@@ -27,38 +42,26 @@ import type { GrantedPermissions } from "./types.cjs";
27
42
  * @param hooks.isNonEvmScopeSupported - The hook that returns true if a non EVM scope is supported.
28
43
  * @param hooks.getNonEvmAccountAddresses - The hook that returns a list of CaipAccountIds that are supported for a CaipChainId.
29
44
  * @param hooks.sortAccountIdsByLastSelected - A function that accepts an array of CaipAccountId and returns an array of CaipAccountId sorted by last selected.
30
- * @param hooks.trackSessionCreatedEvent - An optional hook for platform specific logic to run. Can be undefined.
45
+ * @param hooks.trackSessionCreatedEvent - An optional hook for platform specific logic to run.
31
46
  * @returns A promise with wallet_createSession handler
32
47
  */
33
- declare function walletCreateSessionHandler(req: JsonRpcRequest<Caip25Authorization> & {
48
+ declare function handleWalletCreateSession(req: JsonRpcRequest<Params> & {
34
49
  origin: string;
35
- }, res: JsonRpcSuccess<{
36
- sessionScopes: NormalizedScopesObject;
37
- sessionProperties?: Record<string, Json>;
38
- }>, _next: JsonRpcEngineNextCallback, end: JsonRpcEngineEndCallback, hooks: {
39
- listAccounts: () => {
40
- address: string;
41
- }[];
42
- findNetworkClientIdByChainId: NetworkController['findNetworkClientIdByChainId'];
43
- requestPermissionsForOrigin: (requestedPermissions: RequestedPermissions, metadata?: Record<string, Json>) => Promise<[GrantedPermissions]>;
44
- getNonEvmSupportedMethods: (scope: CaipChainId) => string[];
45
- isNonEvmScopeSupported: (scope: CaipChainId) => boolean;
46
- getNonEvmAccountAddresses: (scope: CaipChainId) => CaipAccountId[];
47
- sortAccountIdsByLastSelected: (accounts: CaipAccountId[]) => CaipAccountId[];
48
- trackSessionCreatedEvent?: (approvedCaip25CaveatValue: Caip25CaveatValue) => void;
49
- }): Promise<void>;
50
- export declare const walletCreateSession: {
51
- methodNames: string[];
52
- implementation: typeof walletCreateSessionHandler;
50
+ }, res: PendingJsonRpcResponse<Result>, _next: JsonRpcEngineNextCallback, end: JsonRpcEngineEndCallback, hooks: WalletCreateSessionHooks): Promise<void>;
51
+ export type WalletCreateSessionHandler = MethodHandler<WalletCreateSessionHooks, never, Params, Result, {
52
+ origin: string;
53
+ }>;
54
+ export declare const walletCreateSessionHandler: {
55
+ implementation: typeof handleWalletCreateSession;
53
56
  hookNames: {
54
- findNetworkClientIdByChainId: boolean;
55
- listAccounts: boolean;
56
- requestPermissionsForOrigin: boolean;
57
- getNonEvmSupportedMethods: boolean;
58
- isNonEvmScopeSupported: boolean;
59
- getNonEvmAccountAddresses: boolean;
60
- sortAccountIdsByLastSelected: boolean;
61
- trackSessionCreatedEvent: boolean;
57
+ findNetworkClientIdByChainId: true;
58
+ listAccounts: true;
59
+ requestPermissionsForOrigin: true;
60
+ getNonEvmSupportedMethods: true;
61
+ isNonEvmScopeSupported: true;
62
+ getNonEvmAccountAddresses: true;
63
+ sortAccountIdsByLastSelected: true;
64
+ trackSessionCreatedEvent: true;
62
65
  };
63
66
  };
64
67
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"wallet-createSession.d.cts","sourceRoot":"","sources":["../../src/handlers/wallet-createSession.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EACV,mBAAmB,EACnB,sBAAsB,EACtB,iBAAiB,EAClB,4CAA4C;AAE7C,OAAO,KAAK,EACV,wBAAwB,EACxB,yBAAyB,EAC1B,kCAAkC;AACnC,OAAO,KAAK,EAAE,iBAAiB,EAAE,qCAAqC;AAEtE,OAAO,KAAK,EAAE,oBAAoB,EAAE,wCAAwC;AAO5E,OAAO,KAAK,EACV,aAAa,EACb,WAAW,EAEX,IAAI,EACJ,cAAc,EACd,cAAc,EACf,wBAAwB;AAEzB,OAAO,KAAK,EAAE,kBAAkB,EAAE,oBAAgB;AAIlD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,iBAAe,0BAA0B,CACvC,GAAG,EAAE,cAAc,CAAC,mBAAmB,CAAC,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,EAC7D,GAAG,EAAE,cAAc,CAAC;IAClB,aAAa,EAAE,sBAAsB,CAAC;IACtC,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;CAC1C,CAAC,EACF,KAAK,EAAE,yBAAyB,EAChC,GAAG,EAAE,wBAAwB,EAC7B,KAAK,EAAE;IACL,YAAY,EAAE,MAAM;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAC1C,4BAA4B,EAAE,iBAAiB,CAAC,8BAA8B,CAAC,CAAC;IAChF,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