@metamask-previews/multichain-api-middleware 4.0.3-preview-3e34650c2 → 4.0.3-preview-4f4c98e

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 (105) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/handlers/index.d.ts +25 -0
  3. package/dist/handlers/index.d.ts.map +1 -0
  4. package/dist/handlers/{index.mjs → index.js} +5 -5
  5. package/dist/handlers/index.js.map +1 -0
  6. package/dist/handlers/{types.d.cts → types.d.ts} +5 -5
  7. package/dist/handlers/types.d.ts.map +1 -0
  8. package/dist/handlers/{types.mjs → types.js} +1 -2
  9. package/dist/handlers/types.js.map +1 -0
  10. package/dist/handlers/{wallet-createSession.d.cts → wallet-createSession.d.ts} +9 -9
  11. package/dist/handlers/wallet-createSession.d.ts.map +1 -0
  12. package/dist/handlers/{wallet-createSession.mjs → wallet-createSession.js} +6 -6
  13. package/dist/handlers/wallet-createSession.js.map +1 -0
  14. package/dist/handlers/{wallet-getSession.d.mts → wallet-getSession.d.ts} +5 -5
  15. package/dist/handlers/wallet-getSession.d.ts.map +1 -0
  16. package/dist/handlers/{wallet-getSession.mjs → wallet-getSession.js} +2 -2
  17. package/dist/handlers/wallet-getSession.js.map +1 -0
  18. package/dist/handlers/{wallet-invokeMethod.d.mts → wallet-invokeMethod.d.ts} +7 -7
  19. package/dist/handlers/wallet-invokeMethod.d.ts.map +1 -0
  20. package/dist/handlers/{wallet-invokeMethod.mjs → wallet-invokeMethod.js} +4 -4
  21. package/dist/handlers/wallet-invokeMethod.js.map +1 -0
  22. package/dist/handlers/{wallet-revokeSession.d.mts → wallet-revokeSession.d.ts} +6 -6
  23. package/dist/handlers/wallet-revokeSession.d.ts.map +1 -0
  24. package/dist/handlers/{wallet-revokeSession.mjs → wallet-revokeSession.js} +5 -5
  25. package/dist/handlers/wallet-revokeSession.js.map +1 -0
  26. package/dist/index.d.ts +7 -0
  27. package/dist/index.d.ts.map +1 -0
  28. package/dist/index.js +6 -0
  29. package/dist/index.js.map +1 -0
  30. package/dist/middlewares/{MultichainMiddlewareManager.d.cts → MultichainMiddlewareManager.d.ts} +4 -4
  31. package/dist/middlewares/MultichainMiddlewareManager.d.ts.map +1 -0
  32. package/dist/middlewares/{MultichainMiddlewareManager.mjs → MultichainMiddlewareManager.js} +2 -2
  33. package/dist/middlewares/MultichainMiddlewareManager.js.map +1 -0
  34. package/dist/middlewares/{MultichainSubscriptionManager.d.cts → MultichainSubscriptionManager.d.ts} +6 -6
  35. package/dist/middlewares/MultichainSubscriptionManager.d.ts.map +1 -0
  36. package/dist/middlewares/{MultichainSubscriptionManager.mjs → MultichainSubscriptionManager.js} +6 -13
  37. package/dist/middlewares/MultichainSubscriptionManager.js.map +1 -0
  38. package/dist/middlewares/{multichainMethodCallValidatorMiddleware.d.cts → multichainMethodCallValidatorMiddleware.d.ts} +2 -2
  39. package/dist/middlewares/multichainMethodCallValidatorMiddleware.d.ts.map +1 -0
  40. package/dist/middlewares/{multichainMethodCallValidatorMiddleware.mjs → multichainMethodCallValidatorMiddleware.js} +8 -15
  41. package/dist/middlewares/multichainMethodCallValidatorMiddleware.js.map +1 -0
  42. package/package.json +13 -17
  43. package/dist/handlers/index.cjs +0 -20
  44. package/dist/handlers/index.cjs.map +0 -1
  45. package/dist/handlers/index.d.cts +0 -25
  46. package/dist/handlers/index.d.cts.map +0 -1
  47. package/dist/handlers/index.d.mts +0 -25
  48. package/dist/handlers/index.d.mts.map +0 -1
  49. package/dist/handlers/index.mjs.map +0 -1
  50. package/dist/handlers/types.cjs +0 -13
  51. package/dist/handlers/types.cjs.map +0 -1
  52. package/dist/handlers/types.d.cts.map +0 -1
  53. package/dist/handlers/types.d.mts +0 -27
  54. package/dist/handlers/types.d.mts.map +0 -1
  55. package/dist/handlers/types.mjs.map +0 -1
  56. package/dist/handlers/wallet-createSession.cjs +0 -179
  57. package/dist/handlers/wallet-createSession.cjs.map +0 -1
  58. package/dist/handlers/wallet-createSession.d.cts.map +0 -1
  59. package/dist/handlers/wallet-createSession.d.mts +0 -70
  60. package/dist/handlers/wallet-createSession.d.mts.map +0 -1
  61. package/dist/handlers/wallet-createSession.mjs.map +0 -1
  62. package/dist/handlers/wallet-getSession.cjs +0 -54
  63. package/dist/handlers/wallet-getSession.cjs.map +0 -1
  64. package/dist/handlers/wallet-getSession.d.cts +0 -43
  65. package/dist/handlers/wallet-getSession.d.cts.map +0 -1
  66. package/dist/handlers/wallet-getSession.d.mts.map +0 -1
  67. package/dist/handlers/wallet-getSession.mjs.map +0 -1
  68. package/dist/handlers/wallet-invokeMethod.cjs +0 -103
  69. package/dist/handlers/wallet-invokeMethod.cjs.map +0 -1
  70. package/dist/handlers/wallet-invokeMethod.d.cts +0 -57
  71. package/dist/handlers/wallet-invokeMethod.d.cts.map +0 -1
  72. package/dist/handlers/wallet-invokeMethod.d.mts.map +0 -1
  73. package/dist/handlers/wallet-invokeMethod.mjs.map +0 -1
  74. package/dist/handlers/wallet-revokeSession.cjs +0 -106
  75. package/dist/handlers/wallet-revokeSession.cjs.map +0 -1
  76. package/dist/handlers/wallet-revokeSession.d.cts +0 -45
  77. package/dist/handlers/wallet-revokeSession.d.cts.map +0 -1
  78. package/dist/handlers/wallet-revokeSession.d.mts.map +0 -1
  79. package/dist/handlers/wallet-revokeSession.mjs.map +0 -1
  80. package/dist/index.cjs +0 -14
  81. package/dist/index.cjs.map +0 -1
  82. package/dist/index.d.cts +0 -7
  83. package/dist/index.d.cts.map +0 -1
  84. package/dist/index.d.mts +0 -7
  85. package/dist/index.d.mts.map +0 -1
  86. package/dist/index.mjs +0 -6
  87. package/dist/index.mjs.map +0 -1
  88. package/dist/middlewares/MultichainMiddlewareManager.cjs +0 -110
  89. package/dist/middlewares/MultichainMiddlewareManager.cjs.map +0 -1
  90. package/dist/middlewares/MultichainMiddlewareManager.d.cts.map +0 -1
  91. package/dist/middlewares/MultichainMiddlewareManager.d.mts +0 -35
  92. package/dist/middlewares/MultichainMiddlewareManager.d.mts.map +0 -1
  93. package/dist/middlewares/MultichainMiddlewareManager.mjs.map +0 -1
  94. package/dist/middlewares/MultichainSubscriptionManager.cjs +0 -118
  95. package/dist/middlewares/MultichainSubscriptionManager.cjs.map +0 -1
  96. package/dist/middlewares/MultichainSubscriptionManager.d.cts.map +0 -1
  97. package/dist/middlewares/MultichainSubscriptionManager.d.mts +0 -49
  98. package/dist/middlewares/MultichainSubscriptionManager.d.mts.map +0 -1
  99. package/dist/middlewares/MultichainSubscriptionManager.mjs.map +0 -1
  100. package/dist/middlewares/multichainMethodCallValidatorMiddleware.cjs +0 -74
  101. package/dist/middlewares/multichainMethodCallValidatorMiddleware.cjs.map +0 -1
  102. package/dist/middlewares/multichainMethodCallValidatorMiddleware.d.cts.map +0 -1
  103. package/dist/middlewares/multichainMethodCallValidatorMiddleware.d.mts +0 -7
  104. package/dist/middlewares/multichainMethodCallValidatorMiddleware.d.mts.map +0 -1
  105. package/dist/middlewares/multichainMethodCallValidatorMiddleware.mjs.map +0 -1
@@ -1,17 +1,10 @@
1
- function $importDefault(module) {
2
- if (module?.__esModule) {
3
- return module.default;
4
- }
5
- return module;
6
- }
7
- import { MultiChainOpenRPCDocument } from "@metamask/api-specs";
8
- import { createAsyncMiddleware } from "@metamask/json-rpc-engine";
9
- import { rpcErrors } from "@metamask/rpc-errors";
10
- import { isObject } from "@metamask/utils";
11
- import $dereferenceDocument from "@open-rpc/schema-utils-js/build/dereference-document.js";
12
- const dereferenceDocument = $importDefault($dereferenceDocument);
13
- import { makeCustomResolver } from "@open-rpc/schema-utils-js/build/parse-open-rpc-document.js";
14
- import { Validator } from "jsonschema";
1
+ import { MultiChainOpenRPCDocument } from '@metamask/api-specs';
2
+ import { createAsyncMiddleware } from '@metamask/json-rpc-engine';
3
+ import { rpcErrors } from '@metamask/rpc-errors';
4
+ import { isObject } from '@metamask/utils';
5
+ import { dereferenceDocument } from '@open-rpc/schema-utils-js';
6
+ import { makeCustomResolver } from '@open-rpc/schema-utils-js/build/parse-open-rpc-document.js';
7
+ import { Validator } from 'jsonschema';
15
8
  const transformError = (error, param, got) => {
16
9
  // if there is a path, add it to the message
17
10
  const message = `${param.name}${error.path.length > 0 ? `.${error.path.join('.')}` : ''} ${error.message}`;
@@ -72,4 +65,4 @@ export const multichainMethodCallValidatorMiddleware = createAsyncMiddleware(asy
72
65
  }
73
66
  return await next();
74
67
  });
75
- //# sourceMappingURL=multichainMethodCallValidatorMiddleware.mjs.map
68
+ //# sourceMappingURL=multichainMethodCallValidatorMiddleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"multichainMethodCallValidatorMiddleware.js","sourceRoot":"","sources":["../../src/middlewares/multichainMethodCallValidatorMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAQ3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,4DAA4D,CAAC;AAEhG,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,MAAM,cAAc,GAAG,CACrB,KAAsB,EACtB,KAA8B,EAC9B,GAAY,EACZ,EAAE;IACF,4CAA4C;IAC5C,MAAM,OAAO,GAAG,GAAG,KAAK,CAAC,IAAI,GAC3B,KAAK,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,EACvD,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;IAEpB,OAAO,SAAS,CAAC,aAAa,CAAC;QAC7B,OAAO;QACP,IAAI,EAAE;YACJ,KAAK,EA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;SACrB,CAAC,CAAC;QACH,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;YAClB,MAAM,CAAC,IAAI,CACT,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;gBACzB,OAAO,cAAc,CAAC,CAAC,EAAE,CAAC,EAAE,YAAY,CAAiB,CAAC;YAC5D,CAAC,CAAC,CACH,CAAC;QACJ,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,uCAAuC,GAAG,qBAAqB,CAC1E,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE;IACjC,MAAM,MAAM,GAAG,MAAM,6BAA6B,CAChD,OAAO,CAAC,MAAM,EACd,OAAO,CAAC,MAAM,CACf,CAAC;IACF,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtB,MAAM,SAAS,CAAC,aAAa,CAAiB,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;IAClE,CAAC;IACD,OAAO,MAAM,IAAI,EAAE,CAAC;AACtB,CAAC,CACF,CAAC","sourcesContent":["import { MultiChainOpenRPCDocument } from '@metamask/api-specs';\nimport { createAsyncMiddleware } from '@metamask/json-rpc-engine';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport { isObject } from '@metamask/utils';\nimport type { JsonRpcError, JsonRpcParams } from '@metamask/utils';\nimport type {\n ContentDescriptorObject,\n MethodObject,\n OpenrpcDocument,\n ReferenceObject,\n} from '@open-rpc/meta-schema';\nimport { dereferenceDocument } from '@open-rpc/schema-utils-js';\nimport { makeCustomResolver } from '@open-rpc/schema-utils-js/build/parse-open-rpc-document.js';\nimport type { Schema, ValidationError } from 'jsonschema';\nimport { Validator } from 'jsonschema';\n\nconst transformError = (\n error: ValidationError,\n param: ContentDescriptorObject,\n got: unknown,\n) => {\n // if there is a path, add it to the message\n const message = `${param.name}${\n error.path.length > 0 ? `.${error.path.join('.')}` : ''\n } ${error.message}`;\n\n return rpcErrors.invalidParams({\n message,\n data: {\n param: param.name,\n path: error.path,\n schema: error.schema,\n got,\n },\n });\n};\n\nconst v = new Validator();\n\nconst dereffedPromise = dereferenceDocument(\n MultiChainOpenRPCDocument as unknown as OpenrpcDocument,\n makeCustomResolver({}),\n);\n\n/**\n * Helper that utilizes the Multichain method specifications from `@metamask/api-specs`\n * to validate the params of a Multichain request.\n *\n * @param method - The request's method.\n * @param params - The request's optional JsonRpcParams object.\n * @returns an array of error objects for each validation error or an empty array if no errors.\n */\nconst multichainMethodCallValidator = async (\n method: string,\n params: JsonRpcParams | undefined,\n) => {\n const dereffed = await dereffedPromise;\n\n const methodToCheck = dereffed.methods.find(\n (m: MethodObject | ReferenceObject) => (m as MethodObject).name === method,\n ) as MethodObject | undefined;\n\n if (\n !methodToCheck ||\n !isObject(methodToCheck) ||\n !('params' in methodToCheck)\n ) {\n return [rpcErrors.methodNotFound({ data: { method } })] as JsonRpcError[];\n }\n\n const errors: JsonRpcError[] = [];\n for (const param of methodToCheck.params) {\n if (!isObject(params)) {\n return [rpcErrors.invalidParams()] as JsonRpcError[];\n }\n const p = param as ContentDescriptorObject;\n const paramToCheck = params[p.name];\n\n const result = v.validate(paramToCheck, p.schema as unknown as Schema, {\n required: p.required,\n });\n if (result.errors) {\n errors.push(\n ...result.errors.map((e) => {\n return transformError(e, p, paramToCheck) as JsonRpcError;\n }),\n );\n }\n }\n return errors;\n};\n\n/**\n * Middleware that validates the params of a Multichain method request\n * using the specifications from `@metamask/api-specs`.\n */\nexport const multichainMethodCallValidatorMiddleware = createAsyncMiddleware(\n async (request, _response, next) => {\n const errors = await multichainMethodCallValidator(\n request.method,\n request.params,\n );\n if (errors.length > 0) {\n throw rpcErrors.invalidParams<JsonRpcError[]>({ data: errors });\n }\n return await next();\n },\n);\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/multichain-api-middleware",
3
- "version": "4.0.3-preview-3e34650c2",
3
+ "version": "4.0.3-preview-4f4c98e",
4
4
  "description": "JSON-RPC methods and middleware to support the MetaMask Multichain API",
5
5
  "keywords": [
6
6
  "Ethereum",
@@ -18,19 +18,12 @@
18
18
  "files": [
19
19
  "dist/"
20
20
  ],
21
+ "type": "module",
21
22
  "sideEffects": false,
22
- "main": "./dist/index.cjs",
23
- "types": "./dist/index.d.cts",
24
23
  "exports": {
25
24
  ".": {
26
- "import": {
27
- "types": "./dist/index.d.mts",
28
- "default": "./dist/index.mjs"
29
- },
30
- "require": {
31
- "types": "./dist/index.d.cts",
32
- "default": "./dist/index.cjs"
33
- }
25
+ "types": "./dist/index.d.ts",
26
+ "default": "./dist/index.js"
34
27
  },
35
28
  "./package.json": "./package.json"
36
29
  },
@@ -39,9 +32,11 @@
39
32
  "registry": "https://registry.npmjs.org/"
40
33
  },
41
34
  "scripts": {
42
- "build": "ts-bridge --project tsconfig.build.json --verbose --clean --no-references",
43
- "build:all": "ts-bridge --project tsconfig.build.json --verbose --clean",
35
+ "build": "tsc --project tsconfig.build.json",
36
+ "build:all": "tsc --build tsconfig.build.json --verbose",
37
+ "build:clean": "yarn build:only-clean && yarn build",
44
38
  "build:docs": "typedoc",
39
+ "build:only-clean": "rimraf './dist' './tsconfig.build.tsbuildinfo'",
45
40
  "changelog:update": "../../scripts/update-changelog.sh @metamask/multichain-api-middleware",
46
41
  "changelog:validate": "../../scripts/validate-changelog.sh @metamask/multichain-api-middleware",
47
42
  "lint:tsconfigs": "tsx ../../scripts/lint-tsconfigs/lint-tsconfigs.mts",
@@ -71,18 +66,19 @@
71
66
  "@metamask/auto-changelog": "^6.1.0",
72
67
  "@metamask/eth-json-rpc-filters": "^9.0.0",
73
68
  "@metamask/multichain-transactions-controller": "^7.1.2",
74
- "@metamask/safe-event-emitter": "^3.0.0",
75
- "@ts-bridge/cli": "^0.6.4",
69
+ "@metamask/safe-event-emitter": "^3.1.3",
76
70
  "@types/jest": "^30.0.0",
71
+ "@typescript/native": "npm:typescript@^7.0.2",
77
72
  "deepmerge": "^4.2.2",
78
73
  "jest": "^30.4.2",
74
+ "rimraf": "^5.0.5",
79
75
  "ts-jest": "^29.4.11",
80
76
  "tsx": "^4.20.5",
81
77
  "typedoc": "^0.25.13",
82
78
  "typedoc-plugin-missing-exports": "^2.0.0",
83
- "typescript": "~5.3.3"
79
+ "typescript": "npm:@typescript/typescript6@^6.0.2"
84
80
  },
85
81
  "engines": {
86
- "node": "^18.18 || >=20"
82
+ "node": "^22.14.0 || ^24"
87
83
  }
88
84
  }
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.methodHandlers = void 0;
4
- const wallet_createSession_js_1 = require("./wallet-createSession.cjs");
5
- const wallet_getSession_js_1 = require("./wallet-getSession.cjs");
6
- const wallet_invokeMethod_js_1 = require("./wallet-invokeMethod.cjs");
7
- const wallet_revokeSession_js_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_js_1.walletCreateSessionHandler,
16
- [MethodNames.WalletGetSession]: wallet_getSession_js_1.walletGetSessionHandler,
17
- [MethodNames.WalletInvokeMethod]: wallet_invokeMethod_js_1.walletInvokeMethodHandler,
18
- [MethodNames.WalletRevokeSession]: wallet_revokeSession_js_1.walletRevokeSessionHandler,
19
- };
20
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/handlers/index.ts"],"names":[],"mappings":";;;AAGA,wEAAuE;AAEvE,kEAAiE;AAEjE,sEAAqE;AAErE,wEAAuE;AASvE,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,oDAA0B;IAC7D,CAAC,WAAW,CAAC,gBAAgB,CAAC,EAAE,8CAAuB;IACvD,CAAC,WAAW,CAAC,kBAAkB,CAAC,EAAE,kDAAyB;IAC3D,CAAC,WAAW,CAAC,mBAAmB,CAAC,EAAE,oDAA0B;CAC9D,CAAC","sourcesContent":["import type { UnionToIntersection } from '@metamask/json-rpc-engine/v2';\n\nimport type { WalletCreateSessionHooks } from './wallet-createSession.js';\nimport { walletCreateSessionHandler } from './wallet-createSession.js';\nimport type { WalletGetSessionHooks } from './wallet-getSession.js';\nimport { walletGetSessionHandler } from './wallet-getSession.js';\nimport type { WalletInvokeMethodHooks } from './wallet-invokeMethod.js';\nimport { walletInvokeMethodHandler } from './wallet-invokeMethod.js';\nimport type { WalletRevokeSessionHooks } from './wallet-revokeSession.js';\nimport { walletRevokeSessionHandler } from './wallet-revokeSession.js';\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,25 +0,0 @@
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
@@ -1 +0,0 @@
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,mCAAkC;AAC1E,OAAO,EAAE,0BAA0B,EAAE,mCAAkC;AACvE,OAAO,KAAK,EAAE,qBAAqB,EAAE,gCAA+B;AACpE,OAAO,EAAE,uBAAuB,EAAE,gCAA+B;AACjE,OAAO,KAAK,EAAE,uBAAuB,EAAE,kCAAiC;AACxE,OAAO,EAAE,yBAAyB,EAAE,kCAAiC;AACrE,OAAO,KAAK,EAAE,wBAAwB,EAAE,mCAAkC;AAC1E,OAAO,EAAE,0BAA0B,EAAE,mCAAkC;AAEvE,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"}
@@ -1,25 +0,0 @@
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
@@ -1 +0,0 @@
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,mCAAkC;AAC1E,OAAO,EAAE,0BAA0B,EAAE,mCAAkC;AACvE,OAAO,KAAK,EAAE,qBAAqB,EAAE,gCAA+B;AACpE,OAAO,EAAE,uBAAuB,EAAE,gCAA+B;AACjE,OAAO,KAAK,EAAE,uBAAuB,EAAE,kCAAiC;AACxE,OAAO,EAAE,yBAAyB,EAAE,kCAAiC;AACrE,OAAO,KAAK,EAAE,wBAAwB,EAAE,mCAAkC;AAC1E,OAAO,EAAE,0BAA0B,EAAE,mCAAkC;AAEvE,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"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/handlers/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,0BAA0B,EAAE,mCAAkC;AAEvE,OAAO,EAAE,uBAAuB,EAAE,gCAA+B;AAEjE,OAAO,EAAE,yBAAyB,EAAE,kCAAiC;AAErE,OAAO,EAAE,0BAA0B,EAAE,mCAAkC;AASvE,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.js';\nimport { walletCreateSessionHandler } from './wallet-createSession.js';\nimport type { WalletGetSessionHooks } from './wallet-getSession.js';\nimport { walletGetSessionHandler } from './wallet-getSession.js';\nimport type { WalletInvokeMethodHooks } from './wallet-invokeMethod.js';\nimport { walletInvokeMethodHandler } from './wallet-invokeMethod.js';\nimport type { WalletRevokeSessionHooks } from './wallet-revokeSession.js';\nimport { walletRevokeSessionHandler } from './wallet-revokeSession.js';\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,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MultichainApiNotifications = void 0;
4
- const chain_agnostic_permission_1 = require("@metamask/chain-agnostic-permission");
5
- /**
6
- * Multichain API notifications currently supported by/known to the wallet.
7
- */
8
- var MultichainApiNotifications;
9
- (function (MultichainApiNotifications) {
10
- MultichainApiNotifications["sessionChanged"] = "wallet_sessionChanged";
11
- MultichainApiNotifications["walletNotify"] = "wallet_notify";
12
- })(MultichainApiNotifications || (exports.MultichainApiNotifications = MultichainApiNotifications = {}));
13
- //# sourceMappingURL=types.cjs.map
@@ -1 +0,0 @@
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, Hex, Json } 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: {\n address: string;\n }) => Promise<Record<Hex, Record<string, Json>>>;\n};\n"]}
@@ -1 +0,0 @@
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,GAAG,EAAE,IAAI,EAAE,wBAAwB;AAEhE;;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;QACxB,OAAO,EAAE,MAAM,CAAC;KACjB,KAAK,OAAO,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;CAClD,CAAC"}
@@ -1,27 +0,0 @@
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, Hex, Json } from "@metamask/utils";
5
- /**
6
- * Multichain API notifications currently supported by/known to the wallet.
7
- */
8
- export declare enum MultichainApiNotifications {
9
- sessionChanged = "wallet_sessionChanged",
10
- walletNotify = "wallet_notify"
11
- }
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[];
21
- };
22
- export type GetCapabilitiesHook = {
23
- getCapabilities: (params: {
24
- address: string;
25
- }) => Promise<Record<Hex, Record<string, Json>>>;
26
- };
27
- //# sourceMappingURL=types.d.mts.map
@@ -1 +0,0 @@
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,GAAG,EAAE,IAAI,EAAE,wBAAwB;AAEhE;;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;QACxB,OAAO,EAAE,MAAM,CAAC;KACjB,KAAK,OAAO,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;CAClD,CAAC"}
@@ -1 +0,0 @@
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, Hex, Json } 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: {\n address: string;\n }) => Promise<Record<Hex, Record<string, Json>>>;\n};\n"]}
@@ -1,179 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.walletCreateSessionHandler = void 0;
4
- const chain_agnostic_permission_1 = require("@metamask/chain-agnostic-permission");
5
- const controller_utils_1 = require("@metamask/controller-utils");
6
- const permission_controller_1 = require("@metamask/permission-controller");
7
- const rpc_errors_1 = require("@metamask/rpc-errors");
8
- const utils_1 = require("@metamask/utils");
9
- const SOLANA_CAIP_CHAIN_ID = 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp';
10
- /**
11
- * Handler for the `wallet_createSession` RPC method which is responsible
12
- * for prompting for approval and granting a CAIP-25 permission.
13
- *
14
- * This implementation primarily deviates from the CAIP-25 handler
15
- * specification by treating all scopes as optional regardless of
16
- * if they were specified in `requiredScopes` or `optionalScopes`.
17
- * Additionally, provided scopes, methods, notifications, and
18
- * account values that are invalid/malformed are ignored rather than
19
- * causing an error to be returned.
20
- *
21
- * @param req - The request object.
22
- * @param res - The response object.
23
- * @param _next - The next middleware function.
24
- * @param end - The end function.
25
- * @param hooks - The hooks object.
26
- * @param hooks.listAccounts - The hook that returns an array of the wallet's evm accounts.
27
- * @param hooks.findNetworkClientIdByChainId - The hook that returns the networkClientId for a chainId.
28
- * @param hooks.requestPermissionsForOrigin - The hook that approves and grants requested permissions.
29
- * @param hooks.getNonEvmSupportedMethods - The hook that returns the supported methods for a non EVM scope.
30
- * @param hooks.isNonEvmScopeSupported - The hook that returns true if a non EVM scope is supported.
31
- * @param hooks.getNonEvmAccountAddresses - The hook that returns a list of CaipAccountIds that are supported for a CaipChainId.
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
- * @param hooks.trackSessionCreatedEvent - An optional hook for platform specific logic to run.
35
- * @returns A promise with wallet_createSession handler
36
- */
37
- async function handleWalletCreateSession(req, res, _next, end, hooks) {
38
- if (!(0, utils_1.isPlainObject)(req.params)) {
39
- return end((0, permission_controller_1.invalidParams)({ data: { request: req } }));
40
- }
41
- const { requiredScopes, optionalScopes, sessionProperties } = req.params;
42
- if (sessionProperties && Object.keys(sessionProperties).length === 0) {
43
- return end(new rpc_errors_1.JsonRpcError(5302, 'Invalid sessionProperties requested'));
44
- }
45
- const filteredSessionProperties = Object.fromEntries(Object.entries(sessionProperties ?? {}).filter(([key]) => (0, chain_agnostic_permission_1.isKnownSessionPropertyValue)(key)));
46
- try {
47
- const { normalizedRequiredScopes, normalizedOptionalScopes } = (0, chain_agnostic_permission_1.validateAndNormalizeScopes)(requiredScopes || {}, optionalScopes || {});
48
- const requiredScopesWithSupportedMethodsAndNotifications = (0, chain_agnostic_permission_1.getSupportedScopeObjects)(normalizedRequiredScopes, {
49
- getNonEvmSupportedMethods: hooks.getNonEvmSupportedMethods,
50
- });
51
- const optionalScopesWithSupportedMethodsAndNotifications = (0, chain_agnostic_permission_1.getSupportedScopeObjects)(normalizedOptionalScopes, {
52
- getNonEvmSupportedMethods: hooks.getNonEvmSupportedMethods,
53
- });
54
- const networkClientExistsForChainId = (chainId) => {
55
- try {
56
- hooks.findNetworkClientIdByChainId(chainId);
57
- return true;
58
- }
59
- catch {
60
- return false;
61
- }
62
- };
63
- // if solana is a requested scope but not supported, we add a promptToCreateSolanaAccount flag to request
64
- const isSolanaRequested = (0, chain_agnostic_permission_1.isNamespaceInScopesObject)(requiredScopesWithSupportedMethodsAndNotifications, utils_1.KnownCaipNamespace.Solana) ||
65
- (0, chain_agnostic_permission_1.isNamespaceInScopesObject)(optionalScopesWithSupportedMethodsAndNotifications, utils_1.KnownCaipNamespace.Solana);
66
- let promptToCreateSolanaAccount = false;
67
- if (isSolanaRequested) {
68
- const supportedSolanaAccounts = hooks.getNonEvmAccountAddresses(SOLANA_CAIP_CHAIN_ID);
69
- promptToCreateSolanaAccount = supportedSolanaAccounts.length === 0;
70
- }
71
- const { supportedScopes: supportedRequiredScopes } = (0, chain_agnostic_permission_1.bucketScopes)(requiredScopesWithSupportedMethodsAndNotifications, {
72
- isEvmChainIdSupported: networkClientExistsForChainId,
73
- isEvmChainIdSupportable: () => false, // intended for future usage with eip3085 scopedProperties
74
- getNonEvmSupportedMethods: hooks.getNonEvmSupportedMethods,
75
- isNonEvmScopeSupported: hooks.isNonEvmScopeSupported,
76
- });
77
- const { supportedScopes: supportedOptionalScopes } = (0, chain_agnostic_permission_1.bucketScopes)(optionalScopesWithSupportedMethodsAndNotifications, {
78
- isEvmChainIdSupported: networkClientExistsForChainId,
79
- isEvmChainIdSupportable: () => false, // intended for future usage with eip3085 scopedProperties
80
- getNonEvmSupportedMethods: hooks.getNonEvmSupportedMethods,
81
- isNonEvmScopeSupported: hooks.isNonEvmScopeSupported,
82
- });
83
- const allRequestedAccountAddresses = (0, chain_agnostic_permission_1.getCaipAccountIdsFromScopesObjects)([
84
- supportedRequiredScopes,
85
- supportedOptionalScopes,
86
- ]);
87
- const allSupportedRequestedCaipChainIds = (0, chain_agnostic_permission_1.getAllScopesFromScopesObjects)([
88
- supportedRequiredScopes,
89
- supportedOptionalScopes,
90
- ]);
91
- const existingEvmAddresses = hooks
92
- .listAccounts()
93
- .map((account) => account.address);
94
- const supportedRequestedAccountAddresses = allRequestedAccountAddresses.filter((requestedAccountAddress) => {
95
- const { address, chain: { namespace }, chainId: caipChainId, } = (0, utils_1.parseCaipAccountId)(requestedAccountAddress);
96
- if (namespace === utils_1.KnownCaipNamespace.Eip155.toString()) {
97
- return existingEvmAddresses.some((existingEvmAddress) => {
98
- return (0, controller_utils_1.isEqualCaseInsensitive)(address, existingEvmAddress);
99
- });
100
- }
101
- // If the namespace is not eip155 (EVM) we do a case sensitive check
102
- return hooks
103
- .getNonEvmAccountAddresses(caipChainId)
104
- .some((existingCaipAddress) => {
105
- return requestedAccountAddress === existingCaipAddress;
106
- });
107
- });
108
- const requestedCaip25CaveatValue = {
109
- requiredScopes: (0, chain_agnostic_permission_1.getInternalScopesObject)(supportedRequiredScopes),
110
- optionalScopes: (0, chain_agnostic_permission_1.getInternalScopesObject)(supportedOptionalScopes),
111
- isMultichainOrigin: true,
112
- sessionProperties: filteredSessionProperties,
113
- };
114
- const requestedCaip25CaveatValueWithSupportedAccounts = (0, chain_agnostic_permission_1.setNonSCACaipAccountIdsInCaip25CaveatValue)(requestedCaip25CaveatValue, supportedRequestedAccountAddresses);
115
- // if `promptToCreateSolanaAccount` is true and there are no other valid scopes requested,
116
- // we add a `wallet` scope to the request in order to get passed the CAIP-25 caveat validator.
117
- // This is very hacky but is necessary because the solana opt-in flow breaks key assumptions
118
- // of the CAIP-25 permission specification - namely that we can have valid requests with no scopes.
119
- if (allSupportedRequestedCaipChainIds.length === 0) {
120
- if (promptToCreateSolanaAccount) {
121
- requestedCaip25CaveatValueWithSupportedAccounts.optionalScopes[utils_1.KnownCaipNamespace.Wallet] = {
122
- accounts: [],
123
- };
124
- }
125
- else {
126
- // if solana is not requested and there are no supported scopes, we return an error
127
- return end(new rpc_errors_1.JsonRpcError(5100, 'Requested scopes are not supported'));
128
- }
129
- }
130
- const [grantedPermissions] = await hooks.requestPermissionsForOrigin({
131
- [chain_agnostic_permission_1.Caip25EndowmentPermissionName]: {
132
- caveats: [
133
- {
134
- type: chain_agnostic_permission_1.Caip25CaveatType,
135
- value: requestedCaip25CaveatValueWithSupportedAccounts,
136
- },
137
- ],
138
- },
139
- }, {
140
- metadata: { promptToCreateSolanaAccount },
141
- });
142
- const approvedCaip25Permission = grantedPermissions[chain_agnostic_permission_1.Caip25EndowmentPermissionName];
143
- const approvedCaip25CaveatValue = approvedCaip25Permission?.caveats?.find((caveat) => caveat.type === chain_agnostic_permission_1.Caip25CaveatType)?.value;
144
- if (!approvedCaip25CaveatValue) {
145
- throw rpc_errors_1.rpcErrors.internal();
146
- }
147
- const sessionScopes = (0, chain_agnostic_permission_1.getSessionScopes)(approvedCaip25CaveatValue, {
148
- getNonEvmSupportedMethods: hooks.getNonEvmSupportedMethods,
149
- sortAccountIdsByLastSelected: hooks.sortAccountIdsByLastSelected,
150
- });
151
- const approvedSessionProperties = await (0, chain_agnostic_permission_1.getSessionProperties)(approvedCaip25CaveatValue, {
152
- getCapabilities: hooks.getCapabilities,
153
- });
154
- hooks.trackSessionCreatedEvent?.(approvedCaip25CaveatValue);
155
- res.result = {
156
- sessionScopes,
157
- sessionProperties: approvedSessionProperties,
158
- };
159
- return end();
160
- }
161
- catch (err) {
162
- return end(err);
163
- }
164
- }
165
- exports.walletCreateSessionHandler = {
166
- implementation: handleWalletCreateSession,
167
- hookNames: {
168
- findNetworkClientIdByChainId: true,
169
- listAccounts: true,
170
- requestPermissionsForOrigin: true,
171
- getNonEvmSupportedMethods: true,
172
- isNonEvmScopeSupported: true,
173
- getNonEvmAccountAddresses: true,
174
- sortAccountIdsByLastSelected: true,
175
- getCapabilities: true,
176
- trackSessionCreatedEvent: true,
177
- },
178
- };
179
- //# sourceMappingURL=wallet-createSession.cjs.map
@@ -1 +0,0 @@
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,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'@metamask/accounts-controller';\nimport {\n Caip25CaveatType,\n Caip25EndowmentPermissionName,\n bucketScopes,\n validateAndNormalizeScopes,\n getInternalScopesObject,\n getSessionScopes,\n getSessionProperties,\n getSupportedScopeObjects,\n isKnownSessionPropertyValue,\n getCaipAccountIdsFromScopesObjects,\n getAllScopesFromScopesObjects,\n setNonSCACaipAccountIdsInCaip25CaveatValue,\n isNamespaceInScopesObject,\n} from '@metamask/chain-agnostic-permission';\nimport type {\n Caip25Authorization,\n NormalizedScopesObject,\n Caip25CaveatValue,\n} from '@metamask/chain-agnostic-permission';\nimport { isEqualCaseInsensitive } from '@metamask/controller-utils';\nimport type {\n MethodHandler,\n JsonRpcEngineEndCallback,\n JsonRpcEngineNextCallback,\n} from '@metamask/json-rpc-engine';\nimport type { NetworkController } from '@metamask/network-controller';\nimport { invalidParams } from '@metamask/permission-controller';\nimport type {\n GenericPermissionController,\n RequestedPermissions,\n} from '@metamask/permission-controller';\nimport { JsonRpcError, rpcErrors } from '@metamask/rpc-errors';\nimport type { MultichainRoutingService } from '@metamask/snaps-controllers';\nimport {\n isPlainObject,\n KnownCaipNamespace,\n parseCaipAccountId,\n} from '@metamask/utils';\nimport type {\n CaipAccountId,\n Hex,\n Json,\n JsonRpcRequest,\n PendingJsonRpcResponse,\n} from '@metamask/utils';\n\nimport type {\n GetCapabilitiesHook,\n GetNonEvmSupportedMethodsHook,\n SortAccountIdsByLastSelectedHook,\n} from './types.js';\n\nconst SOLANA_CAIP_CHAIN_ID = 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp';\n\nexport type WalletCreateSessionHooks = GetNonEvmSupportedMethodsHook &\n SortAccountIdsByLastSelectedHook &\n GetCapabilitiesHook & {\n listAccounts: AccountsController['listAccounts'];\n findNetworkClientIdByChainId: NetworkController['findNetworkClientIdByChainId'];\n requestPermissionsForOrigin: (\n requestedPermissions: RequestedPermissions,\n metadata?: Record<string, Json>,\n ) => ReturnType<GenericPermissionController['requestPermissions']>;\n isNonEvmScopeSupported: MultichainRoutingService['isSupportedScope'];\n getNonEvmAccountAddresses: MultichainRoutingService['getSupportedAccounts'];\n trackSessionCreatedEvent:\n | ((approvedCaip25CaveatValue: Caip25CaveatValue) => void)\n | null;\n };\n\ntype Params = Caip25Authorization;\n\ntype Result = {\n sessionScopes: NormalizedScopesObject;\n sessionProperties?: Record<string, Json>;\n};\n\n/**\n * Handler for the `wallet_createSession` RPC method which is responsible\n * for prompting for approval and granting a CAIP-25 permission.\n *\n * This implementation primarily deviates from the CAIP-25 handler\n * specification by treating all scopes as optional regardless of\n * if they were specified in `requiredScopes` or `optionalScopes`.\n * Additionally, provided scopes, methods, notifications, and\n * account values that are invalid/malformed are ignored rather than\n * causing an error to be returned.\n *\n * @param req - The request object.\n * @param res - The response object.\n * @param _next - The next middleware function.\n * @param end - The end function.\n * @param hooks - The hooks object.\n * @param hooks.listAccounts - The hook that returns an array of the wallet's evm accounts.\n * @param hooks.findNetworkClientIdByChainId - The hook that returns the networkClientId for a chainId.\n * @param hooks.requestPermissionsForOrigin - The hook that approves and grants requested permissions.\n * @param hooks.getNonEvmSupportedMethods - The hook that returns the supported methods for a non EVM scope.\n * @param hooks.isNonEvmScopeSupported - The hook that returns true if a non EVM scope is supported.\n * @param hooks.getNonEvmAccountAddresses - The hook that returns a list of CaipAccountIds that are supported for a CaipChainId.\n * @param hooks.sortAccountIdsByLastSelected - A function that accepts an array of CaipAccountId and returns an array of CaipAccountId sorted by last selected.\n * @param hooks.getCapabilities - A function that returns the capabilities for a given address.\n * @param hooks.trackSessionCreatedEvent - An optional hook for platform specific logic to run.\n * @returns A promise with wallet_createSession handler\n */\nasync function handleWalletCreateSession(\n req: JsonRpcRequest<Params> & { origin: string },\n res: PendingJsonRpcResponse<Result>,\n _next: JsonRpcEngineNextCallback,\n end: JsonRpcEngineEndCallback,\n hooks: WalletCreateSessionHooks,\n): Promise<void> {\n if (!isPlainObject(req.params)) {\n return end(invalidParams({ data: { request: req } }));\n }\n const { requiredScopes, optionalScopes, sessionProperties } = req.params;\n\n if (sessionProperties && Object.keys(sessionProperties).length === 0) {\n return end(new JsonRpcError(5302, 'Invalid sessionProperties requested'));\n }\n\n const filteredSessionProperties = Object.fromEntries(\n Object.entries(sessionProperties ?? {}).filter(([key]) =>\n isKnownSessionPropertyValue(key),\n ),\n );\n\n try {\n const { normalizedRequiredScopes, normalizedOptionalScopes } =\n validateAndNormalizeScopes(requiredScopes || {}, optionalScopes || {});\n\n const requiredScopesWithSupportedMethodsAndNotifications =\n getSupportedScopeObjects(normalizedRequiredScopes, {\n getNonEvmSupportedMethods: hooks.getNonEvmSupportedMethods,\n });\n const optionalScopesWithSupportedMethodsAndNotifications =\n getSupportedScopeObjects(normalizedOptionalScopes, {\n getNonEvmSupportedMethods: hooks.getNonEvmSupportedMethods,\n });\n\n const networkClientExistsForChainId = (chainId: Hex) => {\n try {\n hooks.findNetworkClientIdByChainId(chainId);\n return true;\n } catch {\n return false;\n }\n };\n\n // if solana is a requested scope but not supported, we add a promptToCreateSolanaAccount flag to request\n const isSolanaRequested =\n isNamespaceInScopesObject(\n requiredScopesWithSupportedMethodsAndNotifications,\n KnownCaipNamespace.Solana,\n ) ||\n isNamespaceInScopesObject(\n optionalScopesWithSupportedMethodsAndNotifications,\n KnownCaipNamespace.Solana,\n );\n\n let promptToCreateSolanaAccount = false;\n if (isSolanaRequested) {\n const supportedSolanaAccounts =\n hooks.getNonEvmAccountAddresses(SOLANA_CAIP_CHAIN_ID);\n promptToCreateSolanaAccount = supportedSolanaAccounts.length === 0;\n }\n\n const { supportedScopes: supportedRequiredScopes } = bucketScopes(\n requiredScopesWithSupportedMethodsAndNotifications,\n {\n isEvmChainIdSupported: networkClientExistsForChainId,\n isEvmChainIdSupportable: () => false, // intended for future usage with eip3085 scopedProperties\n getNonEvmSupportedMethods: hooks.getNonEvmSupportedMethods,\n isNonEvmScopeSupported: hooks.isNonEvmScopeSupported,\n },\n );\n\n const { supportedScopes: supportedOptionalScopes } = bucketScopes(\n optionalScopesWithSupportedMethodsAndNotifications,\n {\n isEvmChainIdSupported: networkClientExistsForChainId,\n isEvmChainIdSupportable: () => false, // intended for future usage with eip3085 scopedProperties\n getNonEvmSupportedMethods: hooks.getNonEvmSupportedMethods,\n isNonEvmScopeSupported: hooks.isNonEvmScopeSupported,\n },\n );\n\n const allRequestedAccountAddresses = getCaipAccountIdsFromScopesObjects([\n supportedRequiredScopes,\n supportedOptionalScopes,\n ]);\n\n const allSupportedRequestedCaipChainIds = getAllScopesFromScopesObjects([\n supportedRequiredScopes,\n supportedOptionalScopes,\n ]);\n\n const existingEvmAddresses = hooks\n .listAccounts()\n .map((account) => account.address);\n\n const supportedRequestedAccountAddresses =\n allRequestedAccountAddresses.filter(\n (requestedAccountAddress: CaipAccountId) => {\n const {\n address,\n chain: { namespace },\n chainId: caipChainId,\n } = parseCaipAccountId(requestedAccountAddress);\n if (namespace === KnownCaipNamespace.Eip155.toString()) {\n return existingEvmAddresses.some((existingEvmAddress) => {\n return isEqualCaseInsensitive(address, existingEvmAddress);\n });\n }\n\n // If the namespace is not eip155 (EVM) we do a case sensitive check\n return hooks\n .getNonEvmAccountAddresses(caipChainId)\n .some((existingCaipAddress) => {\n return requestedAccountAddress === existingCaipAddress;\n });\n },\n );\n\n const requestedCaip25CaveatValue = {\n requiredScopes: getInternalScopesObject(supportedRequiredScopes),\n optionalScopes: getInternalScopesObject(supportedOptionalScopes),\n isMultichainOrigin: true,\n sessionProperties: filteredSessionProperties,\n };\n\n const requestedCaip25CaveatValueWithSupportedAccounts =\n setNonSCACaipAccountIdsInCaip25CaveatValue(\n requestedCaip25CaveatValue,\n supportedRequestedAccountAddresses,\n );\n\n // if `promptToCreateSolanaAccount` is true and there are no other valid scopes requested,\n // we add a `wallet` scope to the request in order to get passed the CAIP-25 caveat validator.\n // This is very hacky but is necessary because the solana opt-in flow breaks key assumptions\n // of the CAIP-25 permission specification - namely that we can have valid requests with no scopes.\n if (allSupportedRequestedCaipChainIds.length === 0) {\n if (promptToCreateSolanaAccount) {\n requestedCaip25CaveatValueWithSupportedAccounts.optionalScopes[\n KnownCaipNamespace.Wallet\n ] = {\n accounts: [],\n };\n } else {\n // if solana is not requested and there are no supported scopes, we return an error\n return end(\n new JsonRpcError(5100, 'Requested scopes are not supported'),\n );\n }\n }\n\n const [grantedPermissions] = await hooks.requestPermissionsForOrigin(\n {\n [Caip25EndowmentPermissionName]: {\n caveats: [\n {\n type: Caip25CaveatType,\n value: requestedCaip25CaveatValueWithSupportedAccounts,\n },\n ],\n },\n },\n {\n metadata: { promptToCreateSolanaAccount },\n },\n );\n\n const approvedCaip25Permission =\n grantedPermissions[Caip25EndowmentPermissionName];\n const approvedCaip25CaveatValue = approvedCaip25Permission?.caveats?.find(\n (caveat) => caveat.type === Caip25CaveatType,\n )?.value as Caip25CaveatValue;\n if (!approvedCaip25CaveatValue) {\n throw rpcErrors.internal();\n }\n\n const sessionScopes = getSessionScopes(approvedCaip25CaveatValue, {\n getNonEvmSupportedMethods: hooks.getNonEvmSupportedMethods,\n sortAccountIdsByLastSelected: hooks.sortAccountIdsByLastSelected,\n });\n\n const approvedSessionProperties = await getSessionProperties(\n approvedCaip25CaveatValue,\n {\n getCapabilities: hooks.getCapabilities,\n },\n );\n\n hooks.trackSessionCreatedEvent?.(approvedCaip25CaveatValue);\n\n res.result = {\n sessionScopes,\n sessionProperties: approvedSessionProperties,\n };\n return end();\n } catch (err) {\n return end(err);\n }\n}\n\nexport type WalletCreateSessionHandler = MethodHandler<\n WalletCreateSessionHooks,\n never,\n Params,\n Result,\n { origin: string }\n>;\n\nexport const walletCreateSessionHandler = {\n implementation: handleWalletCreateSession,\n hookNames: {\n findNetworkClientIdByChainId: true,\n listAccounts: true,\n requestPermissionsForOrigin: true,\n getNonEvmSupportedMethods: true,\n isNonEvmScopeSupported: true,\n getNonEvmAccountAddresses: true,\n sortAccountIdsByLastSelected: true,\n getCapabilities: true,\n trackSessionCreatedEvent: true,\n },\n} satisfies WalletCreateSessionHandler;\n"]}
@@ -1 +0,0 @@
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,oBAAmB;AAIpB,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,70 +0,0 @@
1
- import type { AccountsController } from "@metamask/accounts-controller";
2
- import type { Caip25Authorization, NormalizedScopesObject, Caip25CaveatValue } from "@metamask/chain-agnostic-permission";
3
- import type { MethodHandler, JsonRpcEngineEndCallback, JsonRpcEngineNextCallback } from "@metamask/json-rpc-engine";
4
- import type { NetworkController } from "@metamask/network-controller";
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 { GetCapabilitiesHook, GetNonEvmSupportedMethodsHook, SortAccountIdsByLastSelectedHook } from "./types.mjs";
9
- export type WalletCreateSessionHooks = GetNonEvmSupportedMethodsHook & SortAccountIdsByLastSelectedHook & GetCapabilitiesHook & {
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
- };
22
- /**
23
- * Handler for the `wallet_createSession` RPC method which is responsible
24
- * for prompting for approval and granting a CAIP-25 permission.
25
- *
26
- * This implementation primarily deviates from the CAIP-25 handler
27
- * specification by treating all scopes as optional regardless of
28
- * if they were specified in `requiredScopes` or `optionalScopes`.
29
- * Additionally, provided scopes, methods, notifications, and
30
- * account values that are invalid/malformed are ignored rather than
31
- * causing an error to be returned.
32
- *
33
- * @param req - The request object.
34
- * @param res - The response object.
35
- * @param _next - The next middleware function.
36
- * @param end - The end function.
37
- * @param hooks - The hooks object.
38
- * @param hooks.listAccounts - The hook that returns an array of the wallet's evm accounts.
39
- * @param hooks.findNetworkClientIdByChainId - The hook that returns the networkClientId for a chainId.
40
- * @param hooks.requestPermissionsForOrigin - The hook that approves and grants requested permissions.
41
- * @param hooks.getNonEvmSupportedMethods - The hook that returns the supported methods for a non EVM scope.
42
- * @param hooks.isNonEvmScopeSupported - The hook that returns true if a non EVM scope is supported.
43
- * @param hooks.getNonEvmAccountAddresses - The hook that returns a list of CaipAccountIds that are supported for a CaipChainId.
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
- * @param hooks.trackSessionCreatedEvent - An optional hook for platform specific logic to run.
47
- * @returns A promise with wallet_createSession handler
48
- */
49
- declare function handleWalletCreateSession(req: JsonRpcRequest<Params> & {
50
- origin: string;
51
- }, res: PendingJsonRpcResponse<Result>, _next: JsonRpcEngineNextCallback, end: JsonRpcEngineEndCallback, hooks: WalletCreateSessionHooks): Promise<void>;
52
- export type WalletCreateSessionHandler = MethodHandler<WalletCreateSessionHooks, never, Params, Result, {
53
- origin: string;
54
- }>;
55
- export declare const walletCreateSessionHandler: {
56
- implementation: typeof handleWalletCreateSession;
57
- hookNames: {
58
- findNetworkClientIdByChainId: true;
59
- listAccounts: true;
60
- requestPermissionsForOrigin: true;
61
- getNonEvmSupportedMethods: true;
62
- isNonEvmScopeSupported: true;
63
- getNonEvmAccountAddresses: true;
64
- sortAccountIdsByLastSelected: true;
65
- getCapabilities: true;
66
- trackSessionCreatedEvent: true;
67
- };
68
- };
69
- export {};
70
- //# sourceMappingURL=wallet-createSession.d.mts.map
@@ -1 +0,0 @@
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,oBAAmB;AAIpB,MAAM,MAAM,wBAAwB,GAAG,6BAA6B,GAClE,gCAAgC,GAChC,mBAAmB,GAAG;IACpB,YAAY,EAAE,kBAAkB,CAAC,cAAc,CAAC,CAAC;IACjD,4BAA4B,EAA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