@metamask-previews/multichain-api-middleware 4.0.3-preview-4f4c98e → 4.0.3-preview-5b293ee50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +0 -4
- package/dist/handlers/index.cjs +20 -0
- package/dist/handlers/index.cjs.map +1 -0
- package/dist/handlers/index.d.cts +25 -0
- package/dist/handlers/index.d.cts.map +1 -0
- package/dist/handlers/index.d.mts +25 -0
- package/dist/handlers/index.d.mts.map +1 -0
- package/dist/handlers/{index.js → index.mjs} +5 -5
- package/dist/handlers/index.mjs.map +1 -0
- package/dist/handlers/types.cjs +13 -0
- package/dist/handlers/types.cjs.map +1 -0
- package/dist/handlers/{types.d.ts → types.d.cts} +5 -5
- package/dist/handlers/types.d.cts.map +1 -0
- package/dist/handlers/types.d.mts +27 -0
- package/dist/handlers/types.d.mts.map +1 -0
- package/dist/handlers/{types.js → types.mjs} +2 -1
- package/dist/handlers/types.mjs.map +1 -0
- package/dist/handlers/wallet-createSession.cjs +179 -0
- package/dist/handlers/wallet-createSession.cjs.map +1 -0
- package/dist/handlers/{wallet-createSession.d.ts → wallet-createSession.d.cts} +9 -9
- package/dist/handlers/wallet-createSession.d.cts.map +1 -0
- package/dist/handlers/wallet-createSession.d.mts +70 -0
- package/dist/handlers/wallet-createSession.d.mts.map +1 -0
- package/dist/handlers/{wallet-createSession.js → wallet-createSession.mjs} +6 -6
- package/dist/handlers/wallet-createSession.mjs.map +1 -0
- package/dist/handlers/wallet-getSession.cjs +54 -0
- package/dist/handlers/wallet-getSession.cjs.map +1 -0
- package/dist/handlers/{wallet-getSession.d.ts → wallet-getSession.d.cts} +5 -5
- package/dist/handlers/wallet-getSession.d.cts.map +1 -0
- package/dist/handlers/wallet-getSession.d.mts +43 -0
- package/dist/handlers/wallet-getSession.d.mts.map +1 -0
- package/dist/handlers/{wallet-getSession.js → wallet-getSession.mjs} +2 -2
- package/dist/handlers/wallet-getSession.mjs.map +1 -0
- package/dist/handlers/wallet-invokeMethod.cjs +103 -0
- package/dist/handlers/wallet-invokeMethod.cjs.map +1 -0
- package/dist/handlers/{wallet-invokeMethod.d.ts → wallet-invokeMethod.d.cts} +7 -7
- package/dist/handlers/wallet-invokeMethod.d.cts.map +1 -0
- package/dist/handlers/wallet-invokeMethod.d.mts +57 -0
- package/dist/handlers/wallet-invokeMethod.d.mts.map +1 -0
- package/dist/handlers/{wallet-invokeMethod.js → wallet-invokeMethod.mjs} +4 -4
- package/dist/handlers/wallet-invokeMethod.mjs.map +1 -0
- package/dist/handlers/wallet-revokeSession.cjs +106 -0
- package/dist/handlers/wallet-revokeSession.cjs.map +1 -0
- package/dist/handlers/{wallet-revokeSession.d.ts → wallet-revokeSession.d.cts} +6 -6
- package/dist/handlers/wallet-revokeSession.d.cts.map +1 -0
- package/dist/handlers/wallet-revokeSession.d.mts +45 -0
- package/dist/handlers/wallet-revokeSession.d.mts.map +1 -0
- package/dist/handlers/{wallet-revokeSession.js → wallet-revokeSession.mjs} +5 -5
- package/dist/handlers/wallet-revokeSession.mjs.map +1 -0
- package/dist/index.cjs +14 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +7 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +7 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +6 -0
- package/dist/index.mjs.map +1 -0
- package/dist/middlewares/MultichainMiddlewareManager.cjs +110 -0
- package/dist/middlewares/MultichainMiddlewareManager.cjs.map +1 -0
- package/dist/middlewares/{MultichainMiddlewareManager.d.ts → MultichainMiddlewareManager.d.cts} +4 -4
- package/dist/middlewares/MultichainMiddlewareManager.d.cts.map +1 -0
- package/dist/middlewares/MultichainMiddlewareManager.d.mts +35 -0
- package/dist/middlewares/MultichainMiddlewareManager.d.mts.map +1 -0
- package/dist/middlewares/{MultichainMiddlewareManager.js → MultichainMiddlewareManager.mjs} +2 -2
- package/dist/middlewares/MultichainMiddlewareManager.mjs.map +1 -0
- package/dist/middlewares/MultichainSubscriptionManager.cjs +118 -0
- package/dist/middlewares/MultichainSubscriptionManager.cjs.map +1 -0
- package/dist/middlewares/{MultichainSubscriptionManager.d.ts → MultichainSubscriptionManager.d.cts} +6 -6
- package/dist/middlewares/MultichainSubscriptionManager.d.cts.map +1 -0
- package/dist/middlewares/MultichainSubscriptionManager.d.mts +49 -0
- package/dist/middlewares/MultichainSubscriptionManager.d.mts.map +1 -0
- package/dist/middlewares/{MultichainSubscriptionManager.js → MultichainSubscriptionManager.mjs} +13 -6
- package/dist/middlewares/MultichainSubscriptionManager.mjs.map +1 -0
- package/dist/middlewares/multichainMethodCallValidatorMiddleware.cjs +74 -0
- package/dist/middlewares/multichainMethodCallValidatorMiddleware.cjs.map +1 -0
- package/dist/middlewares/{multichainMethodCallValidatorMiddleware.d.ts → multichainMethodCallValidatorMiddleware.d.cts} +2 -2
- package/dist/middlewares/multichainMethodCallValidatorMiddleware.d.cts.map +1 -0
- package/dist/middlewares/multichainMethodCallValidatorMiddleware.d.mts +7 -0
- package/dist/middlewares/multichainMethodCallValidatorMiddleware.d.mts.map +1 -0
- package/dist/middlewares/{multichainMethodCallValidatorMiddleware.js → multichainMethodCallValidatorMiddleware.mjs} +15 -8
- package/dist/middlewares/multichainMethodCallValidatorMiddleware.mjs.map +1 -0
- package/package.json +17 -13
- package/dist/handlers/index.d.ts +0 -25
- package/dist/handlers/index.d.ts.map +0 -1
- package/dist/handlers/index.js.map +0 -1
- package/dist/handlers/types.d.ts.map +0 -1
- package/dist/handlers/types.js.map +0 -1
- package/dist/handlers/wallet-createSession.d.ts.map +0 -1
- package/dist/handlers/wallet-createSession.js.map +0 -1
- package/dist/handlers/wallet-getSession.d.ts.map +0 -1
- package/dist/handlers/wallet-getSession.js.map +0 -1
- package/dist/handlers/wallet-invokeMethod.d.ts.map +0 -1
- package/dist/handlers/wallet-invokeMethod.js.map +0 -1
- package/dist/handlers/wallet-revokeSession.d.ts.map +0 -1
- package/dist/handlers/wallet-revokeSession.js.map +0 -1
- package/dist/index.d.ts +0 -7
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -6
- package/dist/index.js.map +0 -1
- package/dist/middlewares/MultichainMiddlewareManager.d.ts.map +0 -1
- package/dist/middlewares/MultichainMiddlewareManager.js.map +0 -1
- package/dist/middlewares/MultichainSubscriptionManager.d.ts.map +0 -1
- package/dist/middlewares/MultichainSubscriptionManager.js.map +0 -1
- package/dist/middlewares/multichainMethodCallValidatorMiddleware.d.ts.map +0 -1
- package/dist/middlewares/multichainMethodCallValidatorMiddleware.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,10 +7,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
-
### Changed
|
|
11
|
-
|
|
12
|
-
- **BREAKING:** Bump minimum Node.js version to 22 ([#9168](https://github.com/MetaMask/core/pull/9168))
|
|
13
|
-
|
|
14
10
|
## [4.0.3]
|
|
15
11
|
|
|
16
12
|
### Changed
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"]}
|
|
@@ -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,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"}
|
|
@@ -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,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,7 +1,7 @@
|
|
|
1
|
-
import { walletCreateSessionHandler } from
|
|
2
|
-
import { walletGetSessionHandler } from
|
|
3
|
-
import { walletInvokeMethodHandler } from
|
|
4
|
-
import { walletRevokeSessionHandler } from
|
|
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
5
|
const MethodNames = {
|
|
6
6
|
WalletCreateSession: 'wallet_createSession',
|
|
7
7
|
WalletGetSession: 'wallet_getSession',
|
|
@@ -14,4 +14,4 @@ export const methodHandlers = {
|
|
|
14
14
|
[MethodNames.WalletInvokeMethod]: walletInvokeMethodHandler,
|
|
15
15
|
[MethodNames.WalletRevokeSession]: walletRevokeSessionHandler,
|
|
16
16
|
};
|
|
17
|
-
//# sourceMappingURL=index.
|
|
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,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"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../../src/handlers/types.ts"],"names":[],"mappings":";;;AAAA,mFAG6C;AAQ7C;;GAEG;AACH,IAAY,0BAGX;AAHD,WAAY,0BAA0B;IACpC,sEAAwC,CAAA;IACxC,4DAA8B,CAAA;AAChC,CAAC,EAHW,0BAA0B,0CAA1B,0BAA0B,QAGrC","sourcesContent":["import {\n Caip25CaveatType,\n Caip25CaveatValue,\n} from '@metamask/chain-agnostic-permission';\nimport type {\n GenericPermissionController,\n Caveat,\n} from '@metamask/permission-controller';\nimport type { MultichainRoutingService } from '@metamask/snaps-controllers';\nimport type { CaipAccountId, 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,7 +1,7 @@
|
|
|
1
|
-
import { Caip25CaveatType, Caip25CaveatValue } from
|
|
2
|
-
import type { GenericPermissionController, Caveat } from
|
|
3
|
-
import type { MultichainRoutingService } from
|
|
4
|
-
import type { CaipAccountId, Hex, Json } from
|
|
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
5
|
/**
|
|
6
6
|
* Multichain API notifications currently supported by/known to the wallet.
|
|
7
7
|
*/
|
|
@@ -24,4 +24,4 @@ export type GetCapabilitiesHook = {
|
|
|
24
24
|
address: string;
|
|
25
25
|
}) => Promise<Record<Hex, Record<string, Json>>>;
|
|
26
26
|
};
|
|
27
|
-
//# sourceMappingURL=types.d.
|
|
27
|
+
//# sourceMappingURL=types.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../../src/handlers/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EAClB,4CAA4C;AAC7C,OAAO,KAAK,EACV,2BAA2B,EAC3B,MAAM,EACP,wCAAwC;AACzC,OAAO,KAAK,EAAE,wBAAwB,EAAE,oCAAoC;AAC5E,OAAO,KAAK,EAAE,aAAa,EAAE,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"}
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../../src/handlers/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EAClB,4CAA4C;AAC7C,OAAO,KAAK,EACV,2BAA2B,EAC3B,MAAM,EACP,wCAAwC;AACzC,OAAO,KAAK,EAAE,wBAAwB,EAAE,oCAAoC;AAC5E,OAAO,KAAK,EAAE,aAAa,EAAE,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,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
|
*/
|
|
@@ -6,4 +7,4 @@ export var MultichainApiNotifications;
|
|
|
6
7
|
MultichainApiNotifications["sessionChanged"] = "wallet_sessionChanged";
|
|
7
8
|
MultichainApiNotifications["walletNotify"] = "wallet_notify";
|
|
8
9
|
})(MultichainApiNotifications || (MultichainApiNotifications = {}));
|
|
9
|
-
//# sourceMappingURL=types.
|
|
10
|
+
//# sourceMappingURL=types.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../../src/handlers/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAEjB,4CAA4C;AAQ7C;;GAEG;AACH,MAAM,CAAN,IAAY,0BAGX;AAHD,WAAY,0BAA0B;IACpC,sEAAwC,CAAA;IACxC,4DAA8B,CAAA;AAChC,CAAC,EAHW,0BAA0B,KAA1B,0BAA0B,QAGrC","sourcesContent":["import {\n Caip25CaveatType,\n Caip25CaveatValue,\n} from '@metamask/chain-agnostic-permission';\nimport type {\n GenericPermissionController,\n Caveat,\n} from '@metamask/permission-controller';\nimport type { MultichainRoutingService } from '@metamask/snaps-controllers';\nimport type { CaipAccountId, 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"]}
|
|
@@ -0,0 +1,179 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet-createSession.cjs","sourceRoot":"","sources":["../../src/handlers/wallet-createSession.ts"],"names":[],"mappings":";;;AACA,mFAc6C;AAM7C,iEAAoE;AAOpE,2EAAgE;AAKhE,qDAA+D;AAE/D,2CAIyB;AAezB,MAAM,oBAAoB,GAAG,yCAAyC,CAAC;AAyBvE;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,KAAK,UAAU,yBAAyB,CACtC,GAAgD,EAChD,GAAmC,EACnC,KAAgC,EAChC,GAA6B,EAC7B,KAA+B;IAE/B,IAAI,CAAC,IAAA,qBAAa,EAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;QAC/B,OAAO,GAAG,CAAC,IAAA,qCAAa,EAAC,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC;IACxD,CAAC;IACD,MAAM,EAAE,cAAc,EAAE,cAAc,EAAE,iBAAiB,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC;IAEzE,IAAI,iBAAiB,IAAI,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACrE,OAAO,GAAG,CAAC,IAAI,yBAAY,CAAC,IAAI,EAAE,qCAAqC,CAAC,CAAC,CAAC;IAC5E,CAAC;IAED,MAAM,yBAAyB,GAAG,MAAM,CAAC,WAAW,CAClD,MAAM,CAAC,OAAO,CAAC,iBAAiB,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CACvD,IAAA,uDAA2B,EAAC,GAAG,CAAC,CACjC,CACF,CAAC;IAEF,IAAI,CAAC;QACH,MAAM,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,GAC1D,IAAA,sDAA0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AAC;QAC7B,CAAC;QAED,MAAM,aAAa,GAAG,IAAA,4CAAgB,EAAC,yBAAyB,EAAE;YAChE,yBAAyB,EAAE,KAAK,CAAC,yBAAyB;YAC1D,4BAA4B,EAAE,KAAK,CAAC,4BAA4B;SACjE,CAAC,CAAC;QAEH,MAAM,yBAAyB,GAAG,MAAM,IAAA,gDAAoB,EAC1D,yBAAyB,EACzB;YACE,eAAe,EAAE,KAAK,CAAC,eAAe;SACvC,CACF,CAAC;QAEF,KAAK,CAAC,wBAAwB,EAAE,CAAC,yBAAyB,CAAC,CAAC;QAE5D,GAAG,CAAC,MAAM,GAAG;YACX,aAAa;YACb,iBAAiB,EAAE,yBAAyB;SAC7C,CAAC;QACF,OAAO,GAAG,EAAE,CAAC;IACf,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAUY,QAAA,0BAA0B,GAAG;IACxC,cAAc,EAAE,yBAAyB;IACzC,SAAS,EAAE;QACT,4BAA4B,EAAE,IAAI;QAClC,YAAY,EAAE,IAAI;QAClB,2BAA2B,EAAE,IAAI;QACjC,yBAAyB,EAAE,IAAI;QAC/B,sBAAsB,EAAE,IAAI;QAC5B,yBAAyB,EAAE,IAAI;QAC/B,4BAA4B,EAAE,IAAI;QAClC,eAAe,EAAE,IAAI;QACrB,wBAAwB,EAAE,IAAI;KAC/B;CACmC,CAAC","sourcesContent":["import type { AccountsController } from '@metamask/accounts-controller';\nimport {\n Caip25CaveatType,\n Caip25EndowmentPermissionName,\n bucketScopes,\n validateAndNormalizeScopes,\n getInternalScopesObject,\n getSessionScopes,\n getSessionProperties,\n getSupportedScopeObjects,\n isKnownSessionPropertyValue,\n getCaipAccountIdsFromScopesObjects,\n getAllScopesFromScopesObjects,\n setNonSCACaipAccountIdsInCaip25CaveatValue,\n isNamespaceInScopesObject,\n} from '@metamask/chain-agnostic-permission';\nimport type {\n Caip25Authorization,\n NormalizedScopesObject,\n Caip25CaveatValue,\n} from '@metamask/chain-agnostic-permission';\nimport { isEqualCaseInsensitive } from '@metamask/controller-utils';\nimport type {\n MethodHandler,\n JsonRpcEngineEndCallback,\n JsonRpcEngineNextCallback,\n} from '@metamask/json-rpc-engine';\nimport type { NetworkController } from '@metamask/network-controller';\nimport { invalidParams } from '@metamask/permission-controller';\nimport type {\n GenericPermissionController,\n RequestedPermissions,\n} from '@metamask/permission-controller';\nimport { JsonRpcError, rpcErrors } from '@metamask/rpc-errors';\nimport type { MultichainRoutingService } from '@metamask/snaps-controllers';\nimport {\n isPlainObject,\n KnownCaipNamespace,\n parseCaipAccountId,\n} from '@metamask/utils';\nimport type {\n CaipAccountId,\n Hex,\n Json,\n JsonRpcRequest,\n PendingJsonRpcResponse,\n} from '@metamask/utils';\n\nimport type {\n GetCapabilitiesHook,\n GetNonEvmSupportedMethodsHook,\n SortAccountIdsByLastSelectedHook,\n} from './types.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,11 +1,11 @@
|
|
|
1
|
-
import type { AccountsController } from
|
|
2
|
-
import type { Caip25Authorization, NormalizedScopesObject, Caip25CaveatValue } from
|
|
3
|
-
import type { MethodHandler, JsonRpcEngineEndCallback, JsonRpcEngineNextCallback } from
|
|
4
|
-
import type { NetworkController } from
|
|
5
|
-
import type { GenericPermissionController, RequestedPermissions } from
|
|
6
|
-
import type { MultichainRoutingService } from
|
|
7
|
-
import type { Json, JsonRpcRequest, PendingJsonRpcResponse } from
|
|
8
|
-
import type { GetCapabilitiesHook, GetNonEvmSupportedMethodsHook, SortAccountIdsByLastSelectedHook } from
|
|
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.cjs";
|
|
9
9
|
export type WalletCreateSessionHooks = GetNonEvmSupportedMethodsHook & SortAccountIdsByLastSelectedHook & GetCapabilitiesHook & {
|
|
10
10
|
listAccounts: AccountsController['listAccounts'];
|
|
11
11
|
findNetworkClientIdByChainId: NetworkController['findNetworkClientIdByChainId'];
|
|
@@ -67,4 +67,4 @@ export declare const walletCreateSessionHandler: {
|
|
|
67
67
|
};
|
|
68
68
|
};
|
|
69
69
|
export {};
|
|
70
|
-
//# sourceMappingURL=wallet-createSession.d.
|
|
70
|
+
//# sourceMappingURL=wallet-createSession.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet-createSession.d.cts","sourceRoot":"","sources":["../../src/handlers/wallet-createSession.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,sCAAsC;AAgBxE,OAAO,KAAK,EACV,mBAAmB,EACnB,sBAAsB,EACtB,iBAAiB,EAClB,4CAA4C;AAE7C,OAAO,KAAK,EACV,aAAa,EACb,wBAAwB,EACxB,yBAAyB,EAC1B,kCAA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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"}
|
|
@@ -0,0 +1,70 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet-createSession.d.mts","sourceRoot":"","sources":["../../src/handlers/wallet-createSession.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,sCAAsC;AAgBxE,OAAO,KAAK,EACV,mBAAmB,EACnB,sBAAsB,EACtB,iBAAiB,EAClB,4CAA4C;AAE7C,OAAO,KAAK,EACV,aAAa,EACb,wBAAwB,EACxB,yBAAyB,EAC1B,kCAAkC;AACnC,OAAO,KAAK,EAAE,iBAAiB,EAAE,qCAAqC;AAEtE,OAAO,KAAK,EACV,2BAA2B,EAC3B,oBAAoB,EACrB,wCAAwC;AAEzC,OAAO,KAAK,EAAE,w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ED,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,8 +1,8 @@
|
|
|
1
|
-
import { Caip25CaveatType, Caip25EndowmentPermissionName, bucketScopes, validateAndNormalizeScopes, getInternalScopesObject, getSessionScopes, getSessionProperties, getSupportedScopeObjects, isKnownSessionPropertyValue, getCaipAccountIdsFromScopesObjects, getAllScopesFromScopesObjects, setNonSCACaipAccountIdsInCaip25CaveatValue, isNamespaceInScopesObject
|
|
2
|
-
import { isEqualCaseInsensitive } from
|
|
3
|
-
import { invalidParams } from
|
|
4
|
-
import { JsonRpcError, rpcErrors } from
|
|
5
|
-
import { isPlainObject, KnownCaipNamespace, parseCaipAccountId
|
|
1
|
+
import { Caip25CaveatType, Caip25EndowmentPermissionName, bucketScopes, validateAndNormalizeScopes, getInternalScopesObject, getSessionScopes, getSessionProperties, getSupportedScopeObjects, isKnownSessionPropertyValue, getCaipAccountIdsFromScopesObjects, getAllScopesFromScopesObjects, setNonSCACaipAccountIdsInCaip25CaveatValue, isNamespaceInScopesObject } from "@metamask/chain-agnostic-permission";
|
|
2
|
+
import { isEqualCaseInsensitive } from "@metamask/controller-utils";
|
|
3
|
+
import { invalidParams } from "@metamask/permission-controller";
|
|
4
|
+
import { JsonRpcError, rpcErrors } from "@metamask/rpc-errors";
|
|
5
|
+
import { isPlainObject, KnownCaipNamespace, parseCaipAccountId } from "@metamask/utils";
|
|
6
6
|
const SOLANA_CAIP_CHAIN_ID = 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp';
|
|
7
7
|
/**
|
|
8
8
|
* Handler for the `wallet_createSession` RPC method which is responsible
|
|
@@ -173,4 +173,4 @@ export const walletCreateSessionHandler = {
|
|
|
173
173
|
trackSessionCreatedEvent: true,
|
|
174
174
|
},
|
|
175
175
|
};
|
|
176
|
-
//# sourceMappingURL=wallet-createSession.
|
|
176
|
+
//# sourceMappingURL=wallet-createSession.mjs.map
|