@metamask/multichain-api-middleware 0.1.1 → 0.2.0
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 +14 -1
- package/dist/handlers/types.cjs.map +1 -1
- package/dist/handlers/types.d.cts +4 -0
- package/dist/handlers/types.d.cts.map +1 -1
- package/dist/handlers/types.d.mts +4 -0
- package/dist/handlers/types.d.mts.map +1 -1
- package/dist/handlers/types.mjs.map +1 -1
- package/dist/handlers/wallet-createSession.cjs +150 -0
- package/dist/handlers/wallet-createSession.cjs.map +1 -0
- package/dist/handlers/wallet-createSession.d.cts +62 -0
- package/dist/handlers/wallet-createSession.d.cts.map +1 -0
- package/dist/handlers/wallet-createSession.d.mts +62 -0
- package/dist/handlers/wallet-createSession.d.mts.map +1 -0
- package/dist/handlers/wallet-createSession.mjs +147 -0
- package/dist/handlers/wallet-createSession.mjs.map +1 -0
- package/dist/index.cjs +3 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -3
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.2.0]
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Add `wallet_createSession` handler ([#5647](https://github.com/MetaMask/core/pull/5647))
|
|
15
|
+
- Add `Caip25Errors` from `@metamask/chain-agnostic-permission` package ([#5566](https://github.com/MetaMask/core/pull/5566))
|
|
16
|
+
|
|
17
|
+
### Changed
|
|
18
|
+
|
|
19
|
+
- Bump `@metamask/chain-agnostic-permission` to `^0.4.0` ([#5674](https://github.com/MetaMask/core/pull/5674))
|
|
20
|
+
- Bump `@metamask/network-controller` to `^23.2.0` ([#5583](https://github.com/MetaMask/core/pull/5583))
|
|
21
|
+
|
|
10
22
|
## [0.1.1]
|
|
11
23
|
|
|
12
24
|
### Added
|
|
@@ -24,6 +36,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
24
36
|
|
|
25
37
|
- Initial release
|
|
26
38
|
|
|
27
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/multichain-api-middleware@0.
|
|
39
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/multichain-api-middleware@0.2.0...HEAD
|
|
40
|
+
[0.2.0]: https://github.com/MetaMask/core/compare/@metamask/multichain-api-middleware@0.1.1...@metamask/multichain-api-middleware@0.2.0
|
|
28
41
|
[0.1.1]: https://github.com/MetaMask/core/compare/@metamask/multichain-api-middleware@0.1.0...@metamask/multichain-api-middleware@0.1.1
|
|
29
42
|
[0.1.0]: https://github.com/MetaMask/core/releases/tag/@metamask/multichain-api-middleware@0.1.0
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../../src/handlers/types.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../../src/handlers/types.ts"],"names":[],"mappings":";;;AAMA;;GAEG;AACH,IAAY,0BAGX;AAHD,WAAY,0BAA0B;IACpC,sEAAwC,CAAA;IACxC,4DAA8B,CAAA;AAChC,CAAC,EAHW,0BAA0B,0CAA1B,0BAA0B,QAGrC","sourcesContent":["import type {\n CaveatSpecificationConstraint,\n PermissionController,\n PermissionSpecificationConstraint,\n} from '@metamask/permission-controller';\n\n/**\n * Multichain API notifications currently supported by/known to the wallet.\n */\nexport enum MultichainApiNotifications {\n sessionChanged = 'wallet_sessionChanged',\n walletNotify = 'wallet_notify',\n}\ntype AbstractPermissionController = PermissionController<\n PermissionSpecificationConstraint,\n CaveatSpecificationConstraint\n>;\n\nexport type GrantedPermissions = Awaited<\n ReturnType<AbstractPermissionController['requestPermissions']>\n>[0];\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { CaveatSpecificationConstraint, PermissionController, PermissionSpecificationConstraint } from "@metamask/permission-controller";
|
|
1
2
|
/**
|
|
2
3
|
* Multichain API notifications currently supported by/known to the wallet.
|
|
3
4
|
*/
|
|
@@ -5,4 +6,7 @@ export declare enum MultichainApiNotifications {
|
|
|
5
6
|
sessionChanged = "wallet_sessionChanged",
|
|
6
7
|
walletNotify = "wallet_notify"
|
|
7
8
|
}
|
|
9
|
+
type AbstractPermissionController = PermissionController<PermissionSpecificationConstraint, CaveatSpecificationConstraint>;
|
|
10
|
+
export type GrantedPermissions = Awaited<ReturnType<AbstractPermissionController['requestPermissions']>>[0];
|
|
11
|
+
export {};
|
|
8
12
|
//# sourceMappingURL=types.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../../src/handlers/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,oBAAY,0BAA0B;IACpC,cAAc,0BAA0B;IACxC,YAAY,kBAAkB;CAC/B"}
|
|
1
|
+
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../../src/handlers/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,6BAA6B,EAC7B,oBAAoB,EACpB,iCAAiC,EAClC,wCAAwC;AAEzC;;GAEG;AACH,oBAAY,0BAA0B;IACpC,cAAc,0BAA0B;IACxC,YAAY,kBAAkB;CAC/B;AACD,KAAK,4BAA4B,GAAG,oBAAoB,CACtD,iCAAiC,EACjC,6BAA6B,CAC9B,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,OAAO,CACtC,UAAU,CAAC,4BAA4B,CAAC,oBAAoB,CAAC,CAAC,CAC/D,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { CaveatSpecificationConstraint, PermissionController, PermissionSpecificationConstraint } from "@metamask/permission-controller";
|
|
1
2
|
/**
|
|
2
3
|
* Multichain API notifications currently supported by/known to the wallet.
|
|
3
4
|
*/
|
|
@@ -5,4 +6,7 @@ export declare enum MultichainApiNotifications {
|
|
|
5
6
|
sessionChanged = "wallet_sessionChanged",
|
|
6
7
|
walletNotify = "wallet_notify"
|
|
7
8
|
}
|
|
9
|
+
type AbstractPermissionController = PermissionController<PermissionSpecificationConstraint, CaveatSpecificationConstraint>;
|
|
10
|
+
export type GrantedPermissions = Awaited<ReturnType<AbstractPermissionController['requestPermissions']>>[0];
|
|
11
|
+
export {};
|
|
8
12
|
//# sourceMappingURL=types.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../../src/handlers/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,oBAAY,0BAA0B;IACpC,cAAc,0BAA0B;IACxC,YAAY,kBAAkB;CAC/B"}
|
|
1
|
+
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../../src/handlers/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,6BAA6B,EAC7B,oBAAoB,EACpB,iCAAiC,EAClC,wCAAwC;AAEzC;;GAEG;AACH,oBAAY,0BAA0B;IACpC,cAAc,0BAA0B;IACxC,YAAY,kBAAkB;CAC/B;AACD,KAAK,4BAA4B,GAAG,oBAAoB,CACtD,iCAAiC,EACjC,6BAA6B,CAC9B,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,OAAO,CACtC,UAAU,CAAC,4BAA4B,CAAC,oBAAoB,CAAC,CAAC,CAC/D,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../../src/handlers/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../../src/handlers/types.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,MAAM,CAAN,IAAY,0BAGX;AAHD,WAAY,0BAA0B;IACpC,sEAAwC,CAAA;IACxC,4DAA8B,CAAA;AAChC,CAAC,EAHW,0BAA0B,KAA1B,0BAA0B,QAGrC","sourcesContent":["import type {\n CaveatSpecificationConstraint,\n PermissionController,\n PermissionSpecificationConstraint,\n} from '@metamask/permission-controller';\n\n/**\n * Multichain API notifications currently supported by/known to the wallet.\n */\nexport enum MultichainApiNotifications {\n sessionChanged = 'wallet_sessionChanged',\n walletNotify = 'wallet_notify',\n}\ntype AbstractPermissionController = PermissionController<\n PermissionSpecificationConstraint,\n CaveatSpecificationConstraint\n>;\n\nexport type GrantedPermissions = Awaited<\n ReturnType<AbstractPermissionController['requestPermissions']>\n>[0];\n"]}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.walletCreateSession = 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
|
+
/**
|
|
10
|
+
* Handler for the `wallet_createSession` RPC method which is responsible
|
|
11
|
+
* for prompting for approval and granting a CAIP-25 permission.
|
|
12
|
+
*
|
|
13
|
+
* This implementation primarily deviates from the CAIP-25 handler
|
|
14
|
+
* specification by treating all scopes as optional regardless of
|
|
15
|
+
* if they were specified in `requiredScopes` or `optionalScopes`.
|
|
16
|
+
* Additionally, provided scopes, methods, notifications, and
|
|
17
|
+
* account values that are invalid/malformed are ignored rather than
|
|
18
|
+
* causing an error to be returned.
|
|
19
|
+
*
|
|
20
|
+
* @param req - The request object.
|
|
21
|
+
* @param res - The response object.
|
|
22
|
+
* @param _next - The next middleware function.
|
|
23
|
+
* @param end - The end function.
|
|
24
|
+
* @param hooks - The hooks object.
|
|
25
|
+
* @param hooks.listAccounts - The hook that returns an array of the wallet's evm accounts.
|
|
26
|
+
* @param hooks.findNetworkClientIdByChainId - The hook that returns the networkClientId for a chainId.
|
|
27
|
+
* @param hooks.requestPermissionsForOrigin - The hook that approves and grants requested permissions.
|
|
28
|
+
* @param hooks.getNonEvmSupportedMethods - The hook that returns the supported methods for a non EVM scope.
|
|
29
|
+
* @param hooks.isNonEvmScopeSupported - The hook that returns true if a non EVM scope is supported.
|
|
30
|
+
* @param hooks.getNonEvmAccountAddresses - The hook that returns a list of CaipAccountIds that are supported for a CaipChainId.
|
|
31
|
+
* @param hooks.trackSessionCreatedEvent - An optional hook for platform specific logic to run. Can be undefined.
|
|
32
|
+
* @returns A promise with wallet_createSession handler
|
|
33
|
+
*/
|
|
34
|
+
async function walletCreateSessionHandler(req, res, _next, end, hooks) {
|
|
35
|
+
if (!(0, utils_1.isPlainObject)(req.params)) {
|
|
36
|
+
return end((0, permission_controller_1.invalidParams)({ data: { request: req } }));
|
|
37
|
+
}
|
|
38
|
+
const { requiredScopes, optionalScopes, sessionProperties } = req.params;
|
|
39
|
+
if (sessionProperties && Object.keys(sessionProperties).length === 0) {
|
|
40
|
+
return end(new rpc_errors_1.JsonRpcError(5302, 'Invalid sessionProperties requested'));
|
|
41
|
+
}
|
|
42
|
+
const filteredSessionProperties = Object.fromEntries(Object.entries(sessionProperties ?? {}).filter(([key]) => (0, chain_agnostic_permission_1.isKnownSessionPropertyValue)(key)));
|
|
43
|
+
try {
|
|
44
|
+
const { normalizedRequiredScopes, normalizedOptionalScopes } = (0, chain_agnostic_permission_1.validateAndNormalizeScopes)(requiredScopes || {}, optionalScopes || {});
|
|
45
|
+
const requiredScopesWithSupportedMethodsAndNotifications = (0, chain_agnostic_permission_1.getSupportedScopeObjects)(normalizedRequiredScopes, {
|
|
46
|
+
getNonEvmSupportedMethods: hooks.getNonEvmSupportedMethods,
|
|
47
|
+
});
|
|
48
|
+
const optionalScopesWithSupportedMethodsAndNotifications = (0, chain_agnostic_permission_1.getSupportedScopeObjects)(normalizedOptionalScopes, {
|
|
49
|
+
getNonEvmSupportedMethods: hooks.getNonEvmSupportedMethods,
|
|
50
|
+
});
|
|
51
|
+
const networkClientExistsForChainId = (chainId) => {
|
|
52
|
+
try {
|
|
53
|
+
hooks.findNetworkClientIdByChainId(chainId);
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
const { supportedScopes: supportedRequiredScopes } = (0, chain_agnostic_permission_1.bucketScopes)(requiredScopesWithSupportedMethodsAndNotifications, {
|
|
61
|
+
isEvmChainIdSupported: networkClientExistsForChainId,
|
|
62
|
+
isEvmChainIdSupportable: () => false,
|
|
63
|
+
getNonEvmSupportedMethods: hooks.getNonEvmSupportedMethods,
|
|
64
|
+
isNonEvmScopeSupported: hooks.isNonEvmScopeSupported,
|
|
65
|
+
});
|
|
66
|
+
const { supportedScopes: supportedOptionalScopes } = (0, chain_agnostic_permission_1.bucketScopes)(optionalScopesWithSupportedMethodsAndNotifications, {
|
|
67
|
+
isEvmChainIdSupported: networkClientExistsForChainId,
|
|
68
|
+
isEvmChainIdSupportable: () => false,
|
|
69
|
+
getNonEvmSupportedMethods: hooks.getNonEvmSupportedMethods,
|
|
70
|
+
isNonEvmScopeSupported: hooks.isNonEvmScopeSupported,
|
|
71
|
+
});
|
|
72
|
+
const allRequestedAccountAddresses = (0, chain_agnostic_permission_1.getCaipAccountIdsFromScopesObjects)([
|
|
73
|
+
supportedRequiredScopes,
|
|
74
|
+
supportedOptionalScopes,
|
|
75
|
+
]);
|
|
76
|
+
const allSupportedRequestedCaipChainIds = (0, chain_agnostic_permission_1.getAllScopesFromScopesObjects)([
|
|
77
|
+
supportedRequiredScopes,
|
|
78
|
+
supportedOptionalScopes,
|
|
79
|
+
]);
|
|
80
|
+
if (allSupportedRequestedCaipChainIds.length === 0) {
|
|
81
|
+
return end(new rpc_errors_1.JsonRpcError(5100, 'Requested scopes are not supported'));
|
|
82
|
+
}
|
|
83
|
+
const existingEvmAddresses = hooks
|
|
84
|
+
.listAccounts()
|
|
85
|
+
.map((account) => account.address);
|
|
86
|
+
const supportedRequestedAccountAddresses = allRequestedAccountAddresses.filter((requestedAccountAddress) => {
|
|
87
|
+
const { address, chain: { namespace }, chainId: caipChainId, } = (0, utils_1.parseCaipAccountId)(requestedAccountAddress);
|
|
88
|
+
if (namespace === utils_1.KnownCaipNamespace.Eip155.toString()) {
|
|
89
|
+
return existingEvmAddresses.some((existingEvmAddress) => {
|
|
90
|
+
return (0, controller_utils_1.isEqualCaseInsensitive)(address, existingEvmAddress);
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
// If the namespace is not eip155 (EVM) we do a case sensitive check
|
|
94
|
+
return hooks
|
|
95
|
+
.getNonEvmAccountAddresses(caipChainId)
|
|
96
|
+
.some((existingCaipAddress) => {
|
|
97
|
+
return requestedAccountAddress === existingCaipAddress;
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
const requestedCaip25CaveatValue = {
|
|
101
|
+
requiredScopes: (0, chain_agnostic_permission_1.getInternalScopesObject)(supportedRequiredScopes),
|
|
102
|
+
optionalScopes: (0, chain_agnostic_permission_1.getInternalScopesObject)(supportedOptionalScopes),
|
|
103
|
+
isMultichainOrigin: true,
|
|
104
|
+
sessionProperties: filteredSessionProperties,
|
|
105
|
+
};
|
|
106
|
+
const requestedCaip25CaveatValueWithSupportedAccounts = (0, chain_agnostic_permission_1.setPermittedAccounts)(requestedCaip25CaveatValue, supportedRequestedAccountAddresses);
|
|
107
|
+
const [grantedPermissions] = await hooks.requestPermissionsForOrigin({
|
|
108
|
+
[chain_agnostic_permission_1.Caip25EndowmentPermissionName]: {
|
|
109
|
+
caveats: [
|
|
110
|
+
{
|
|
111
|
+
type: chain_agnostic_permission_1.Caip25CaveatType,
|
|
112
|
+
value: requestedCaip25CaveatValueWithSupportedAccounts,
|
|
113
|
+
},
|
|
114
|
+
],
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
const approvedCaip25Permission = grantedPermissions[chain_agnostic_permission_1.Caip25EndowmentPermissionName];
|
|
118
|
+
const approvedCaip25CaveatValue = approvedCaip25Permission?.caveats?.find((caveat) => caveat.type === chain_agnostic_permission_1.Caip25CaveatType)?.value;
|
|
119
|
+
if (!approvedCaip25CaveatValue) {
|
|
120
|
+
throw rpc_errors_1.rpcErrors.internal();
|
|
121
|
+
}
|
|
122
|
+
const sessionScopes = (0, chain_agnostic_permission_1.getSessionScopes)(approvedCaip25CaveatValue, {
|
|
123
|
+
getNonEvmSupportedMethods: hooks.getNonEvmSupportedMethods,
|
|
124
|
+
});
|
|
125
|
+
const { sessionProperties: approvedSessionProperties = {} } = approvedCaip25CaveatValue;
|
|
126
|
+
hooks.trackSessionCreatedEvent?.(approvedCaip25CaveatValue);
|
|
127
|
+
res.result = {
|
|
128
|
+
sessionScopes,
|
|
129
|
+
sessionProperties: approvedSessionProperties,
|
|
130
|
+
};
|
|
131
|
+
return end();
|
|
132
|
+
}
|
|
133
|
+
catch (err) {
|
|
134
|
+
return end(err);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
exports.walletCreateSession = {
|
|
138
|
+
methodNames: ['wallet_createSession'],
|
|
139
|
+
implementation: walletCreateSessionHandler,
|
|
140
|
+
hookNames: {
|
|
141
|
+
findNetworkClientIdByChainId: true,
|
|
142
|
+
listAccounts: true,
|
|
143
|
+
requestPermissionsForOrigin: true,
|
|
144
|
+
getNonEvmSupportedMethods: true,
|
|
145
|
+
isNonEvmScopeSupported: true,
|
|
146
|
+
getNonEvmAccountAddresses: true,
|
|
147
|
+
trackSessionCreatedEvent: true,
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
//# sourceMappingURL=wallet-createSession.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"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AAC,yDAA6B,CAAC,CAAC;QACpD,MAAM,yBAAyB,GAAG,wBAAwB,EAAE,OAAO,EAAE,IAAI,CACvE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,4CAAgB,CAC7C,EAAE,KAA0B,CAAC;QAC9B,IAAI,CAAC,yBAAyB,EAAE;YAC9B,MAAM,sBAAS,CAAC,QAAQ,EAAE,CAAC;SAC5B;QAED,MAAM,aAAa,GAAG,IAAA,4CAAgB,EAAC,yBAAyB,EAAE;YAChE,yBAAyB,EAAE,KAAK,CAAC,yBAAyB;SAC3D,CAAC,CAAC;QAEH,MAAM,EAAE,iBAAiB,EAAE,yBAAyB,GAAG,EAAE,EAAE,GACzD,yBAAyB,CAAC;QAE5B,KAAK,CAAC,wBAAwB,EAAE,CAAC,yBAAyB,CAAC,CAAC;QAE5D,GAAG,CAAC,MAAM,GAAG;YACX,aAAa;YACb,iBAAiB,EAAE,yBAAyB;SAC7C,CAAC;QACF,OAAO,GAAG,EAAE,CAAC;KACd;IAAC,OAAO,GAAG,EAAE;QACZ,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC;KACjB;AACH,CAAC;AAEY,QAAA,mBAAmB,GAAG;IACjC,WAAW,EAAE,CAAC,sBAAsB,CAAC;IACrC,cAAc,EAAE,0BAA0B;IAC1C,SAAS,EAAE;QACT,4BAA4B,EAAE,IAAI;QAClC,YAAY,EAAE,IAAI;QAClB,2BAA2B,EAAE,IAAI;QACjC,yBAAyB,EAAE,IAAI;QAC/B,sBAAsB,EAAE,IAAI;QAC5B,yBAAyB,EAAE,IAAI;QAC/B,wBAAwB,EAAE,IAAI;KAC/B;CACF,CAAC","sourcesContent":["import {\n Caip25CaveatType,\n Caip25EndowmentPermissionName,\n bucketScopes,\n validateAndNormalizeScopes,\n type Caip25Authorization,\n getInternalScopesObject,\n getSessionScopes,\n type NormalizedScopesObject,\n getSupportedScopeObjects,\n type Caip25CaveatValue,\n isKnownSessionPropertyValue,\n getCaipAccountIdsFromScopesObjects,\n getAllScopesFromScopesObjects,\n setPermittedAccounts,\n} from '@metamask/chain-agnostic-permission';\nimport { isEqualCaseInsensitive } from '@metamask/controller-utils';\nimport type {\n JsonRpcEngineEndCallback,\n JsonRpcEngineNextCallback,\n} from '@metamask/json-rpc-engine';\nimport type { NetworkController } from '@metamask/network-controller';\nimport {\n invalidParams,\n type RequestedPermissions,\n} from '@metamask/permission-controller';\nimport { JsonRpcError, rpcErrors } from '@metamask/rpc-errors';\nimport {\n type CaipAccountId,\n type CaipChainId,\n type Hex,\n isPlainObject,\n type Json,\n type JsonRpcRequest,\n type JsonRpcSuccess,\n KnownCaipNamespace,\n parseCaipAccountId,\n} from '@metamask/utils';\n\nimport type { GrantedPermissions } from './types';\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.trackSessionCreatedEvent - An optional hook for platform specific logic to run. Can be undefined.\n * @returns A promise with wallet_createSession handler\n */\nasync function walletCreateSessionHandler(\n req: JsonRpcRequest<Caip25Authorization> & { origin: string },\n res: JsonRpcSuccess<{\n sessionScopes: NormalizedScopesObject;\n sessionProperties?: Record<string, Json>;\n }>,\n _next: JsonRpcEngineNextCallback,\n end: JsonRpcEngineEndCallback,\n hooks: {\n listAccounts: () => { address: string }[];\n findNetworkClientIdByChainId: NetworkController['findNetworkClientIdByChainId'];\n requestPermissionsForOrigin: (\n requestedPermissions: RequestedPermissions,\n metadata?: Record<string, Json>,\n ) => Promise<[GrantedPermissions]>;\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n isNonEvmScopeSupported: (scope: CaipChainId) => boolean;\n getNonEvmAccountAddresses: (scope: CaipChainId) => CaipAccountId[];\n trackSessionCreatedEvent?: (\n approvedCaip25CaveatValue: Caip25CaveatValue,\n ) => void;\n },\n) {\n if (!isPlainObject(req.params)) {\n return end(invalidParams({ data: { request: req } }));\n }\n const { requiredScopes, optionalScopes, sessionProperties } = req.params;\n\n if (sessionProperties && Object.keys(sessionProperties).length === 0) {\n return end(new JsonRpcError(5302, 'Invalid sessionProperties requested'));\n }\n\n const filteredSessionProperties = Object.fromEntries(\n Object.entries(sessionProperties ?? {}).filter(([key]) =>\n isKnownSessionPropertyValue(key),\n ),\n );\n\n try {\n const { normalizedRequiredScopes, normalizedOptionalScopes } =\n validateAndNormalizeScopes(requiredScopes || {}, optionalScopes || {});\n\n const requiredScopesWithSupportedMethodsAndNotifications =\n getSupportedScopeObjects(normalizedRequiredScopes, {\n getNonEvmSupportedMethods: hooks.getNonEvmSupportedMethods,\n });\n const optionalScopesWithSupportedMethodsAndNotifications =\n getSupportedScopeObjects(normalizedOptionalScopes, {\n getNonEvmSupportedMethods: hooks.getNonEvmSupportedMethods,\n });\n\n const networkClientExistsForChainId = (chainId: Hex) => {\n try {\n hooks.findNetworkClientIdByChainId(chainId);\n return true;\n } catch {\n return false;\n }\n };\n\n 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 if (allSupportedRequestedCaipChainIds.length === 0) {\n return end(new JsonRpcError(5100, 'Requested scopes are not supported'));\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 setPermittedAccounts(\n requestedCaip25CaveatValue,\n supportedRequestedAccountAddresses,\n );\n\n const [grantedPermissions] = await hooks.requestPermissionsForOrigin({\n [Caip25EndowmentPermissionName]: {\n caveats: [\n {\n type: Caip25CaveatType,\n value: requestedCaip25CaveatValueWithSupportedAccounts,\n },\n ],\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 });\n\n const { sessionProperties: approvedSessionProperties = {} } =\n approvedCaip25CaveatValue;\n\n hooks.trackSessionCreatedEvent?.(approvedCaip25CaveatValue);\n\n res.result = {\n sessionScopes,\n sessionProperties: approvedSessionProperties,\n };\n return end();\n } catch (err) {\n return end(err);\n }\n}\n\nexport const walletCreateSession = {\n methodNames: ['wallet_createSession'],\n implementation: walletCreateSessionHandler,\n hookNames: {\n findNetworkClientIdByChainId: true,\n listAccounts: true,\n requestPermissionsForOrigin: true,\n getNonEvmSupportedMethods: true,\n isNonEvmScopeSupported: true,\n getNonEvmAccountAddresses: true,\n trackSessionCreatedEvent: true,\n },\n};\n"]}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { type Caip25Authorization, type NormalizedScopesObject, type Caip25CaveatValue } from "@metamask/chain-agnostic-permission";
|
|
2
|
+
import type { JsonRpcEngineEndCallback, JsonRpcEngineNextCallback } from "@metamask/json-rpc-engine";
|
|
3
|
+
import type { NetworkController } from "@metamask/network-controller";
|
|
4
|
+
import { type RequestedPermissions } from "@metamask/permission-controller";
|
|
5
|
+
import { type CaipAccountId, type CaipChainId, type Json, type JsonRpcRequest, type JsonRpcSuccess } from "@metamask/utils";
|
|
6
|
+
import type { GrantedPermissions } from "./types.cjs";
|
|
7
|
+
/**
|
|
8
|
+
* Handler for the `wallet_createSession` RPC method which is responsible
|
|
9
|
+
* for prompting for approval and granting a CAIP-25 permission.
|
|
10
|
+
*
|
|
11
|
+
* This implementation primarily deviates from the CAIP-25 handler
|
|
12
|
+
* specification by treating all scopes as optional regardless of
|
|
13
|
+
* if they were specified in `requiredScopes` or `optionalScopes`.
|
|
14
|
+
* Additionally, provided scopes, methods, notifications, and
|
|
15
|
+
* account values that are invalid/malformed are ignored rather than
|
|
16
|
+
* causing an error to be returned.
|
|
17
|
+
*
|
|
18
|
+
* @param req - The request object.
|
|
19
|
+
* @param res - The response object.
|
|
20
|
+
* @param _next - The next middleware function.
|
|
21
|
+
* @param end - The end function.
|
|
22
|
+
* @param hooks - The hooks object.
|
|
23
|
+
* @param hooks.listAccounts - The hook that returns an array of the wallet's evm accounts.
|
|
24
|
+
* @param hooks.findNetworkClientIdByChainId - The hook that returns the networkClientId for a chainId.
|
|
25
|
+
* @param hooks.requestPermissionsForOrigin - The hook that approves and grants requested permissions.
|
|
26
|
+
* @param hooks.getNonEvmSupportedMethods - The hook that returns the supported methods for a non EVM scope.
|
|
27
|
+
* @param hooks.isNonEvmScopeSupported - The hook that returns true if a non EVM scope is supported.
|
|
28
|
+
* @param hooks.getNonEvmAccountAddresses - The hook that returns a list of CaipAccountIds that are supported for a CaipChainId.
|
|
29
|
+
* @param hooks.trackSessionCreatedEvent - An optional hook for platform specific logic to run. Can be undefined.
|
|
30
|
+
* @returns A promise with wallet_createSession handler
|
|
31
|
+
*/
|
|
32
|
+
declare function walletCreateSessionHandler(req: JsonRpcRequest<Caip25Authorization> & {
|
|
33
|
+
origin: string;
|
|
34
|
+
}, res: JsonRpcSuccess<{
|
|
35
|
+
sessionScopes: NormalizedScopesObject;
|
|
36
|
+
sessionProperties?: Record<string, Json>;
|
|
37
|
+
}>, _next: JsonRpcEngineNextCallback, end: JsonRpcEngineEndCallback, hooks: {
|
|
38
|
+
listAccounts: () => {
|
|
39
|
+
address: string;
|
|
40
|
+
}[];
|
|
41
|
+
findNetworkClientIdByChainId: NetworkController['findNetworkClientIdByChainId'];
|
|
42
|
+
requestPermissionsForOrigin: (requestedPermissions: RequestedPermissions, metadata?: Record<string, Json>) => Promise<[GrantedPermissions]>;
|
|
43
|
+
getNonEvmSupportedMethods: (scope: CaipChainId) => string[];
|
|
44
|
+
isNonEvmScopeSupported: (scope: CaipChainId) => boolean;
|
|
45
|
+
getNonEvmAccountAddresses: (scope: CaipChainId) => CaipAccountId[];
|
|
46
|
+
trackSessionCreatedEvent?: (approvedCaip25CaveatValue: Caip25CaveatValue) => void;
|
|
47
|
+
}): Promise<void>;
|
|
48
|
+
export declare const walletCreateSession: {
|
|
49
|
+
methodNames: string[];
|
|
50
|
+
implementation: typeof walletCreateSessionHandler;
|
|
51
|
+
hookNames: {
|
|
52
|
+
findNetworkClientIdByChainId: boolean;
|
|
53
|
+
listAccounts: boolean;
|
|
54
|
+
requestPermissionsForOrigin: boolean;
|
|
55
|
+
getNonEvmSupportedMethods: boolean;
|
|
56
|
+
isNonEvmScopeSupported: boolean;
|
|
57
|
+
getNonEvmAccountAddresses: boolean;
|
|
58
|
+
trackSessionCreatedEvent: boolean;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
export {};
|
|
62
|
+
//# 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,EAKL,KAAK,mBAAmB,EAGxB,KAAK,sBAAsB,EAE3B,KAAK,iBAAiB,EAKvB,4CAA4C;AAE7C,OAAO,KAAK,EACV,wBAAwB,EACxB,yBAAyB,EAC1B,kCAAkC;AACnC,OAAO,KAAK,EAAE,iBAAiB,EAAE,qCAAqC;AACtE,OAAO,EAEL,KAAK,oBAAoB,EAC1B,wCAAwC;AAEzC,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,WAAW,EAGhB,KAAK,IAAI,EACT,KAAK,cAAc,EACnB,KAAK,cAAc,EAGpB,wBAAwB;AAEzB,OAAO,KAAK,EAAE,kBAAkB,EAAE,oBAAgB;AAElD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,iBAAe,0BAA0B,CACvC,GAAG,EAAE,cAAc,CAAC,mBAAmB,CAAC,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,EAC7D,GAAG,EAAE,cAAc,CAAC;IAClB,aAAa,EAAE,sBAAsB,CAAC;IACtC,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;CAC1C,CAAC,EACF,KAAK,EAAE,yBAAyB,EAChC,GAAG,EAAE,wBAAwB,EAC7B,KAAK,EAAE;IACL,YAAY,EAAE,MAAM;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAC1C,4BAA4B,EAAE,iBAAiB,CAAC,8BAA8B,CAAC,CAAC;IAChF,2BAA2B,EAAE,CAC3B,oBAAoB,EAAE,oBAAoB,EAC1C,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,KAC5B,OAAO,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC;IACnC,yBAAyB,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,MAAM,EAAE,CAAC;IAC5D,sBAAsB,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,OAAO,CAAC;IACxD,yBAAyB,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,aAAa,EAAE,CAAC;IACnE,wBAAwB,CAAC,EAAE,CACzB,yBAAyB,EAAE,iBAAiB,KACzC,IAAI,CAAC;CACX,iBAsJF;AAED,eAAO,MAAM,mBAAmB;;;;;;;;;;;;CAY/B,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { type Caip25Authorization, type NormalizedScopesObject, type Caip25CaveatValue } from "@metamask/chain-agnostic-permission";
|
|
2
|
+
import type { JsonRpcEngineEndCallback, JsonRpcEngineNextCallback } from "@metamask/json-rpc-engine";
|
|
3
|
+
import type { NetworkController } from "@metamask/network-controller";
|
|
4
|
+
import { type RequestedPermissions } from "@metamask/permission-controller";
|
|
5
|
+
import { type CaipAccountId, type CaipChainId, type Json, type JsonRpcRequest, type JsonRpcSuccess } from "@metamask/utils";
|
|
6
|
+
import type { GrantedPermissions } from "./types.mjs";
|
|
7
|
+
/**
|
|
8
|
+
* Handler for the `wallet_createSession` RPC method which is responsible
|
|
9
|
+
* for prompting for approval and granting a CAIP-25 permission.
|
|
10
|
+
*
|
|
11
|
+
* This implementation primarily deviates from the CAIP-25 handler
|
|
12
|
+
* specification by treating all scopes as optional regardless of
|
|
13
|
+
* if they were specified in `requiredScopes` or `optionalScopes`.
|
|
14
|
+
* Additionally, provided scopes, methods, notifications, and
|
|
15
|
+
* account values that are invalid/malformed are ignored rather than
|
|
16
|
+
* causing an error to be returned.
|
|
17
|
+
*
|
|
18
|
+
* @param req - The request object.
|
|
19
|
+
* @param res - The response object.
|
|
20
|
+
* @param _next - The next middleware function.
|
|
21
|
+
* @param end - The end function.
|
|
22
|
+
* @param hooks - The hooks object.
|
|
23
|
+
* @param hooks.listAccounts - The hook that returns an array of the wallet's evm accounts.
|
|
24
|
+
* @param hooks.findNetworkClientIdByChainId - The hook that returns the networkClientId for a chainId.
|
|
25
|
+
* @param hooks.requestPermissionsForOrigin - The hook that approves and grants requested permissions.
|
|
26
|
+
* @param hooks.getNonEvmSupportedMethods - The hook that returns the supported methods for a non EVM scope.
|
|
27
|
+
* @param hooks.isNonEvmScopeSupported - The hook that returns true if a non EVM scope is supported.
|
|
28
|
+
* @param hooks.getNonEvmAccountAddresses - The hook that returns a list of CaipAccountIds that are supported for a CaipChainId.
|
|
29
|
+
* @param hooks.trackSessionCreatedEvent - An optional hook for platform specific logic to run. Can be undefined.
|
|
30
|
+
* @returns A promise with wallet_createSession handler
|
|
31
|
+
*/
|
|
32
|
+
declare function walletCreateSessionHandler(req: JsonRpcRequest<Caip25Authorization> & {
|
|
33
|
+
origin: string;
|
|
34
|
+
}, res: JsonRpcSuccess<{
|
|
35
|
+
sessionScopes: NormalizedScopesObject;
|
|
36
|
+
sessionProperties?: Record<string, Json>;
|
|
37
|
+
}>, _next: JsonRpcEngineNextCallback, end: JsonRpcEngineEndCallback, hooks: {
|
|
38
|
+
listAccounts: () => {
|
|
39
|
+
address: string;
|
|
40
|
+
}[];
|
|
41
|
+
findNetworkClientIdByChainId: NetworkController['findNetworkClientIdByChainId'];
|
|
42
|
+
requestPermissionsForOrigin: (requestedPermissions: RequestedPermissions, metadata?: Record<string, Json>) => Promise<[GrantedPermissions]>;
|
|
43
|
+
getNonEvmSupportedMethods: (scope: CaipChainId) => string[];
|
|
44
|
+
isNonEvmScopeSupported: (scope: CaipChainId) => boolean;
|
|
45
|
+
getNonEvmAccountAddresses: (scope: CaipChainId) => CaipAccountId[];
|
|
46
|
+
trackSessionCreatedEvent?: (approvedCaip25CaveatValue: Caip25CaveatValue) => void;
|
|
47
|
+
}): Promise<void>;
|
|
48
|
+
export declare const walletCreateSession: {
|
|
49
|
+
methodNames: string[];
|
|
50
|
+
implementation: typeof walletCreateSessionHandler;
|
|
51
|
+
hookNames: {
|
|
52
|
+
findNetworkClientIdByChainId: boolean;
|
|
53
|
+
listAccounts: boolean;
|
|
54
|
+
requestPermissionsForOrigin: boolean;
|
|
55
|
+
getNonEvmSupportedMethods: boolean;
|
|
56
|
+
isNonEvmScopeSupported: boolean;
|
|
57
|
+
getNonEvmAccountAddresses: boolean;
|
|
58
|
+
trackSessionCreatedEvent: boolean;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
export {};
|
|
62
|
+
//# 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,EAKL,KAAK,mBAAmB,EAGxB,KAAK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E,wBAAwB,CAAC,EAAE,CACzB,yBAAyB,EAAE,iBAAiB,KACzC,IAAI,CAAC;CACX,iBAsJF;AAED,eAAO,MAAM,mBAAmB;;;;;;;;;;;;CAY/B,CAAC"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { Caip25CaveatType, Caip25EndowmentPermissionName, bucketScopes, validateAndNormalizeScopes, getInternalScopesObject, getSessionScopes, getSupportedScopeObjects, isKnownSessionPropertyValue, getCaipAccountIdsFromScopesObjects, getAllScopesFromScopesObjects, setPermittedAccounts } 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
|
+
/**
|
|
7
|
+
* Handler for the `wallet_createSession` RPC method which is responsible
|
|
8
|
+
* for prompting for approval and granting a CAIP-25 permission.
|
|
9
|
+
*
|
|
10
|
+
* This implementation primarily deviates from the CAIP-25 handler
|
|
11
|
+
* specification by treating all scopes as optional regardless of
|
|
12
|
+
* if they were specified in `requiredScopes` or `optionalScopes`.
|
|
13
|
+
* Additionally, provided scopes, methods, notifications, and
|
|
14
|
+
* account values that are invalid/malformed are ignored rather than
|
|
15
|
+
* causing an error to be returned.
|
|
16
|
+
*
|
|
17
|
+
* @param req - The request object.
|
|
18
|
+
* @param res - The response object.
|
|
19
|
+
* @param _next - The next middleware function.
|
|
20
|
+
* @param end - The end function.
|
|
21
|
+
* @param hooks - The hooks object.
|
|
22
|
+
* @param hooks.listAccounts - The hook that returns an array of the wallet's evm accounts.
|
|
23
|
+
* @param hooks.findNetworkClientIdByChainId - The hook that returns the networkClientId for a chainId.
|
|
24
|
+
* @param hooks.requestPermissionsForOrigin - The hook that approves and grants requested permissions.
|
|
25
|
+
* @param hooks.getNonEvmSupportedMethods - The hook that returns the supported methods for a non EVM scope.
|
|
26
|
+
* @param hooks.isNonEvmScopeSupported - The hook that returns true if a non EVM scope is supported.
|
|
27
|
+
* @param hooks.getNonEvmAccountAddresses - The hook that returns a list of CaipAccountIds that are supported for a CaipChainId.
|
|
28
|
+
* @param hooks.trackSessionCreatedEvent - An optional hook for platform specific logic to run. Can be undefined.
|
|
29
|
+
* @returns A promise with wallet_createSession handler
|
|
30
|
+
*/
|
|
31
|
+
async function walletCreateSessionHandler(req, res, _next, end, hooks) {
|
|
32
|
+
if (!isPlainObject(req.params)) {
|
|
33
|
+
return end(invalidParams({ data: { request: req } }));
|
|
34
|
+
}
|
|
35
|
+
const { requiredScopes, optionalScopes, sessionProperties } = req.params;
|
|
36
|
+
if (sessionProperties && Object.keys(sessionProperties).length === 0) {
|
|
37
|
+
return end(new JsonRpcError(5302, 'Invalid sessionProperties requested'));
|
|
38
|
+
}
|
|
39
|
+
const filteredSessionProperties = Object.fromEntries(Object.entries(sessionProperties ?? {}).filter(([key]) => isKnownSessionPropertyValue(key)));
|
|
40
|
+
try {
|
|
41
|
+
const { normalizedRequiredScopes, normalizedOptionalScopes } = validateAndNormalizeScopes(requiredScopes || {}, optionalScopes || {});
|
|
42
|
+
const requiredScopesWithSupportedMethodsAndNotifications = getSupportedScopeObjects(normalizedRequiredScopes, {
|
|
43
|
+
getNonEvmSupportedMethods: hooks.getNonEvmSupportedMethods,
|
|
44
|
+
});
|
|
45
|
+
const optionalScopesWithSupportedMethodsAndNotifications = getSupportedScopeObjects(normalizedOptionalScopes, {
|
|
46
|
+
getNonEvmSupportedMethods: hooks.getNonEvmSupportedMethods,
|
|
47
|
+
});
|
|
48
|
+
const networkClientExistsForChainId = (chainId) => {
|
|
49
|
+
try {
|
|
50
|
+
hooks.findNetworkClientIdByChainId(chainId);
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
const { supportedScopes: supportedRequiredScopes } = bucketScopes(requiredScopesWithSupportedMethodsAndNotifications, {
|
|
58
|
+
isEvmChainIdSupported: networkClientExistsForChainId,
|
|
59
|
+
isEvmChainIdSupportable: () => false,
|
|
60
|
+
getNonEvmSupportedMethods: hooks.getNonEvmSupportedMethods,
|
|
61
|
+
isNonEvmScopeSupported: hooks.isNonEvmScopeSupported,
|
|
62
|
+
});
|
|
63
|
+
const { supportedScopes: supportedOptionalScopes } = bucketScopes(optionalScopesWithSupportedMethodsAndNotifications, {
|
|
64
|
+
isEvmChainIdSupported: networkClientExistsForChainId,
|
|
65
|
+
isEvmChainIdSupportable: () => false,
|
|
66
|
+
getNonEvmSupportedMethods: hooks.getNonEvmSupportedMethods,
|
|
67
|
+
isNonEvmScopeSupported: hooks.isNonEvmScopeSupported,
|
|
68
|
+
});
|
|
69
|
+
const allRequestedAccountAddresses = getCaipAccountIdsFromScopesObjects([
|
|
70
|
+
supportedRequiredScopes,
|
|
71
|
+
supportedOptionalScopes,
|
|
72
|
+
]);
|
|
73
|
+
const allSupportedRequestedCaipChainIds = getAllScopesFromScopesObjects([
|
|
74
|
+
supportedRequiredScopes,
|
|
75
|
+
supportedOptionalScopes,
|
|
76
|
+
]);
|
|
77
|
+
if (allSupportedRequestedCaipChainIds.length === 0) {
|
|
78
|
+
return end(new JsonRpcError(5100, 'Requested scopes are not supported'));
|
|
79
|
+
}
|
|
80
|
+
const existingEvmAddresses = hooks
|
|
81
|
+
.listAccounts()
|
|
82
|
+
.map((account) => account.address);
|
|
83
|
+
const supportedRequestedAccountAddresses = allRequestedAccountAddresses.filter((requestedAccountAddress) => {
|
|
84
|
+
const { address, chain: { namespace }, chainId: caipChainId, } = parseCaipAccountId(requestedAccountAddress);
|
|
85
|
+
if (namespace === KnownCaipNamespace.Eip155.toString()) {
|
|
86
|
+
return existingEvmAddresses.some((existingEvmAddress) => {
|
|
87
|
+
return isEqualCaseInsensitive(address, existingEvmAddress);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
// If the namespace is not eip155 (EVM) we do a case sensitive check
|
|
91
|
+
return hooks
|
|
92
|
+
.getNonEvmAccountAddresses(caipChainId)
|
|
93
|
+
.some((existingCaipAddress) => {
|
|
94
|
+
return requestedAccountAddress === existingCaipAddress;
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
const requestedCaip25CaveatValue = {
|
|
98
|
+
requiredScopes: getInternalScopesObject(supportedRequiredScopes),
|
|
99
|
+
optionalScopes: getInternalScopesObject(supportedOptionalScopes),
|
|
100
|
+
isMultichainOrigin: true,
|
|
101
|
+
sessionProperties: filteredSessionProperties,
|
|
102
|
+
};
|
|
103
|
+
const requestedCaip25CaveatValueWithSupportedAccounts = setPermittedAccounts(requestedCaip25CaveatValue, supportedRequestedAccountAddresses);
|
|
104
|
+
const [grantedPermissions] = await hooks.requestPermissionsForOrigin({
|
|
105
|
+
[Caip25EndowmentPermissionName]: {
|
|
106
|
+
caveats: [
|
|
107
|
+
{
|
|
108
|
+
type: Caip25CaveatType,
|
|
109
|
+
value: requestedCaip25CaveatValueWithSupportedAccounts,
|
|
110
|
+
},
|
|
111
|
+
],
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
const approvedCaip25Permission = grantedPermissions[Caip25EndowmentPermissionName];
|
|
115
|
+
const approvedCaip25CaveatValue = approvedCaip25Permission?.caveats?.find((caveat) => caveat.type === Caip25CaveatType)?.value;
|
|
116
|
+
if (!approvedCaip25CaveatValue) {
|
|
117
|
+
throw rpcErrors.internal();
|
|
118
|
+
}
|
|
119
|
+
const sessionScopes = getSessionScopes(approvedCaip25CaveatValue, {
|
|
120
|
+
getNonEvmSupportedMethods: hooks.getNonEvmSupportedMethods,
|
|
121
|
+
});
|
|
122
|
+
const { sessionProperties: approvedSessionProperties = {} } = approvedCaip25CaveatValue;
|
|
123
|
+
hooks.trackSessionCreatedEvent?.(approvedCaip25CaveatValue);
|
|
124
|
+
res.result = {
|
|
125
|
+
sessionScopes,
|
|
126
|
+
sessionProperties: approvedSessionProperties,
|
|
127
|
+
};
|
|
128
|
+
return end();
|
|
129
|
+
}
|
|
130
|
+
catch (err) {
|
|
131
|
+
return end(err);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
export const walletCreateSession = {
|
|
135
|
+
methodNames: ['wallet_createSession'],
|
|
136
|
+
implementation: walletCreateSessionHandler,
|
|
137
|
+
hookNames: {
|
|
138
|
+
findNetworkClientIdByChainId: true,
|
|
139
|
+
listAccounts: true,
|
|
140
|
+
requestPermissionsForOrigin: true,
|
|
141
|
+
getNonEvmSupportedMethods: true,
|
|
142
|
+
isNonEvmScopeSupported: true,
|
|
143
|
+
getNonEvmAccountAddresses: true,
|
|
144
|
+
trackSessionCreatedEvent: true,
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
//# sourceMappingURL=wallet-createSession.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet-createSession.mjs","sourceRoot":"","sources":["../../src/handlers/wallet-createSession.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,6BAA6B,EAC7B,YAAY,EACZ,0BAA0B,EAE1B,uBAAuB,EACvB,gBAAgB,EAEhB,wBAAwB,EAExB,2BAA2B,EAC3B,kCAAkC,EAClC,6BAA6B,EAC7B,oBAAoB,EACrB,4CAA4C;AAC7C,OAAO,EAAE,sBAAsB,EAAE,mCAAmC;AAMpE,OAAO,EACL,aAAa,EAEd,wCAAwC;AACzC,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,6BAA6B;AAC/D,OAAO,EAIL,aAAa,EAIb,kBAAkB,EAClB,kBAAkB,EACnB,wBAAwB;AAIzB;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,KAAK,UAAU,0BAA0B,CACvC,GAA6D,EAC7D,GAGE,EACF,KAAgC,EAChC,GAA6B,EAC7B,KAaC;IAED,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,MAAM,CAAC,EA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,GACzD,yBAAyB,CAAC;QAE5B,KAAK,CAAC,wBAAwB,EAAE,CAAC,yBAAyB,CAAC,CAAC;QAE5D,GAAG,CAAC,MAAM,GAAG;YACX,aAAa;YACb,iBAAiB,EAAE,yBAAyB;SAC7C,CAAC;QACF,OAAO,GAAG,EAAE,CAAC;KACd;IAAC,OAAO,GAAG,EAAE;QACZ,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC;KACjB;AACH,CAAC;AAED,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,WAAW,EAAE,CAAC,sBAAsB,CAAC;IACrC,cAAc,EAAE,0BAA0B;IAC1C,SAAS,EAAE;QACT,4BAA4B,EAAE,IAAI;QAClC,YAAY,EAAE,IAAI;QAClB,2BAA2B,EAAE,IAAI;QACjC,yBAAyB,EAAE,IAAI;QAC/B,sBAAsB,EAAE,IAAI;QAC5B,yBAAyB,EAAE,IAAI;QAC/B,wBAAwB,EAAE,IAAI;KAC/B;CACF,CAAC","sourcesContent":["import {\n Caip25CaveatType,\n Caip25EndowmentPermissionName,\n bucketScopes,\n validateAndNormalizeScopes,\n type Caip25Authorization,\n getInternalScopesObject,\n getSessionScopes,\n type NormalizedScopesObject,\n getSupportedScopeObjects,\n type Caip25CaveatValue,\n isKnownSessionPropertyValue,\n getCaipAccountIdsFromScopesObjects,\n getAllScopesFromScopesObjects,\n setPermittedAccounts,\n} from '@metamask/chain-agnostic-permission';\nimport { isEqualCaseInsensitive } from '@metamask/controller-utils';\nimport type {\n JsonRpcEngineEndCallback,\n JsonRpcEngineNextCallback,\n} from '@metamask/json-rpc-engine';\nimport type { NetworkController } from '@metamask/network-controller';\nimport {\n invalidParams,\n type RequestedPermissions,\n} from '@metamask/permission-controller';\nimport { JsonRpcError, rpcErrors } from '@metamask/rpc-errors';\nimport {\n type CaipAccountId,\n type CaipChainId,\n type Hex,\n isPlainObject,\n type Json,\n type JsonRpcRequest,\n type JsonRpcSuccess,\n KnownCaipNamespace,\n parseCaipAccountId,\n} from '@metamask/utils';\n\nimport type { GrantedPermissions } from './types';\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.trackSessionCreatedEvent - An optional hook for platform specific logic to run. Can be undefined.\n * @returns A promise with wallet_createSession handler\n */\nasync function walletCreateSessionHandler(\n req: JsonRpcRequest<Caip25Authorization> & { origin: string },\n res: JsonRpcSuccess<{\n sessionScopes: NormalizedScopesObject;\n sessionProperties?: Record<string, Json>;\n }>,\n _next: JsonRpcEngineNextCallback,\n end: JsonRpcEngineEndCallback,\n hooks: {\n listAccounts: () => { address: string }[];\n findNetworkClientIdByChainId: NetworkController['findNetworkClientIdByChainId'];\n requestPermissionsForOrigin: (\n requestedPermissions: RequestedPermissions,\n metadata?: Record<string, Json>,\n ) => Promise<[GrantedPermissions]>;\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n isNonEvmScopeSupported: (scope: CaipChainId) => boolean;\n getNonEvmAccountAddresses: (scope: CaipChainId) => CaipAccountId[];\n trackSessionCreatedEvent?: (\n approvedCaip25CaveatValue: Caip25CaveatValue,\n ) => void;\n },\n) {\n if (!isPlainObject(req.params)) {\n return end(invalidParams({ data: { request: req } }));\n }\n const { requiredScopes, optionalScopes, sessionProperties } = req.params;\n\n if (sessionProperties && Object.keys(sessionProperties).length === 0) {\n return end(new JsonRpcError(5302, 'Invalid sessionProperties requested'));\n }\n\n const filteredSessionProperties = Object.fromEntries(\n Object.entries(sessionProperties ?? {}).filter(([key]) =>\n isKnownSessionPropertyValue(key),\n ),\n );\n\n try {\n const { normalizedRequiredScopes, normalizedOptionalScopes } =\n validateAndNormalizeScopes(requiredScopes || {}, optionalScopes || {});\n\n const requiredScopesWithSupportedMethodsAndNotifications =\n getSupportedScopeObjects(normalizedRequiredScopes, {\n getNonEvmSupportedMethods: hooks.getNonEvmSupportedMethods,\n });\n const optionalScopesWithSupportedMethodsAndNotifications =\n getSupportedScopeObjects(normalizedOptionalScopes, {\n getNonEvmSupportedMethods: hooks.getNonEvmSupportedMethods,\n });\n\n const networkClientExistsForChainId = (chainId: Hex) => {\n try {\n hooks.findNetworkClientIdByChainId(chainId);\n return true;\n } catch {\n return false;\n }\n };\n\n 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 if (allSupportedRequestedCaipChainIds.length === 0) {\n return end(new JsonRpcError(5100, 'Requested scopes are not supported'));\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 setPermittedAccounts(\n requestedCaip25CaveatValue,\n supportedRequestedAccountAddresses,\n );\n\n const [grantedPermissions] = await hooks.requestPermissionsForOrigin({\n [Caip25EndowmentPermissionName]: {\n caveats: [\n {\n type: Caip25CaveatType,\n value: requestedCaip25CaveatValueWithSupportedAccounts,\n },\n ],\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 });\n\n const { sessionProperties: approvedSessionProperties = {} } =\n approvedCaip25CaveatValue;\n\n hooks.trackSessionCreatedEvent?.(approvedCaip25CaveatValue);\n\n res.result = {\n sessionScopes,\n sessionProperties: approvedSessionProperties,\n };\n return end();\n } catch (err) {\n return end(err);\n }\n}\n\nexport const walletCreateSession = {\n methodNames: ['wallet_createSession'],\n implementation: walletCreateSessionHandler,\n hookNames: {\n findNetworkClientIdByChainId: true,\n listAccounts: true,\n requestPermissionsForOrigin: true,\n getNonEvmSupportedMethods: true,\n isNonEvmScopeSupported: true,\n getNonEvmAccountAddresses: true,\n trackSessionCreatedEvent: true,\n },\n};\n"]}
|
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MultichainApiNotifications = exports.MultichainSubscriptionManager = exports.MultichainMiddlewareManager = exports.multichainMethodCallValidatorMiddleware = exports.walletRevokeSession = exports.walletInvokeMethod = exports.walletGetSession = void 0;
|
|
3
|
+
exports.MultichainApiNotifications = exports.MultichainSubscriptionManager = exports.MultichainMiddlewareManager = exports.multichainMethodCallValidatorMiddleware = exports.walletRevokeSession = exports.walletInvokeMethod = exports.walletGetSession = exports.walletCreateSession = void 0;
|
|
4
|
+
var wallet_createSession_1 = require("./handlers/wallet-createSession.cjs");
|
|
5
|
+
Object.defineProperty(exports, "walletCreateSession", { enumerable: true, get: function () { return wallet_createSession_1.walletCreateSession; } });
|
|
4
6
|
var wallet_getSession_1 = require("./handlers/wallet-getSession.cjs");
|
|
5
7
|
Object.defineProperty(exports, "walletGetSession", { enumerable: true, get: function () { return wallet_getSession_1.walletGetSession; } });
|
|
6
8
|
var wallet_invokeMethod_1 = require("./handlers/wallet-invokeMethod.cjs");
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,sEAAgE;AAAvD,qHAAA,gBAAgB,OAAA;AACzB,0EAAoE;AAA3D,yHAAA,kBAAkB,OAAA;AAC3B,4EAAsE;AAA7D,2HAAA,mBAAmB,OAAA;AAE5B,qHAAgH;AAAvG,kKAAA,uCAAuC,OAAA;AAChD,6FAAwF;AAA/E,0IAAA,2BAA2B,OAAA;AACpC,iGAA4F;AAAnF,8IAAA,6BAA6B,OAAA;AACtC,8CAA8D;AAArD,mHAAA,0BAA0B,OAAA","sourcesContent":["export { walletGetSession } from './handlers/wallet-getSession';\nexport { walletInvokeMethod } from './handlers/wallet-invokeMethod';\nexport { walletRevokeSession } from './handlers/wallet-revokeSession';\n\nexport { multichainMethodCallValidatorMiddleware } from './middlewares/multichainMethodCallValidatorMiddleware';\nexport { MultichainMiddlewareManager } from './middlewares/MultichainMiddlewareManager';\nexport { MultichainSubscriptionManager } from './middlewares/MultichainSubscriptionManager';\nexport { MultichainApiNotifications } from './handlers/types';\n"]}
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,4EAAsE;AAA7D,2HAAA,mBAAmB,OAAA;AAC5B,sEAAgE;AAAvD,qHAAA,gBAAgB,OAAA;AACzB,0EAAoE;AAA3D,yHAAA,kBAAkB,OAAA;AAC3B,4EAAsE;AAA7D,2HAAA,mBAAmB,OAAA;AAE5B,qHAAgH;AAAvG,kKAAA,uCAAuC,OAAA;AAChD,6FAAwF;AAA/E,0IAAA,2BAA2B,OAAA;AACpC,iGAA4F;AAAnF,8IAAA,6BAA6B,OAAA;AACtC,8CAA8D;AAArD,mHAAA,0BAA0B,OAAA","sourcesContent":["export { walletCreateSession } from './handlers/wallet-createSession';\nexport { walletGetSession } from './handlers/wallet-getSession';\nexport { walletInvokeMethod } from './handlers/wallet-invokeMethod';\nexport { walletRevokeSession } from './handlers/wallet-revokeSession';\n\nexport { multichainMethodCallValidatorMiddleware } from './middlewares/multichainMethodCallValidatorMiddleware';\nexport { MultichainMiddlewareManager } from './middlewares/MultichainMiddlewareManager';\nexport { MultichainSubscriptionManager } from './middlewares/MultichainSubscriptionManager';\nexport { MultichainApiNotifications } from './handlers/types';\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { walletCreateSession } from "./handlers/wallet-createSession.cjs";
|
|
1
2
|
export { walletGetSession } from "./handlers/wallet-getSession.cjs";
|
|
2
3
|
export { walletInvokeMethod } from "./handlers/wallet-invokeMethod.cjs";
|
|
3
4
|
export { walletRevokeSession } from "./handlers/wallet-revokeSession.cjs";
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,yCAAqC;AAChE,OAAO,EAAE,kBAAkB,EAAE,2CAAuC;AACpE,OAAO,EAAE,mBAAmB,EAAE,4CAAwC;AAEtE,OAAO,EAAE,uCAAuC,EAAE,kEAA8D;AAChH,OAAO,EAAE,2BAA2B,EAAE,sDAAkD;AACxF,OAAO,EAAE,6BAA6B,EAAE,wDAAoD;AAC5F,OAAO,EAAE,0BAA0B,EAAE,6BAAyB"}
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,4CAAwC;AACtE,OAAO,EAAE,gBAAgB,EAAE,yCAAqC;AAChE,OAAO,EAAE,kBAAkB,EAAE,2CAAuC;AACpE,OAAO,EAAE,mBAAmB,EAAE,4CAAwC;AAEtE,OAAO,EAAE,uCAAuC,EAAE,kEAA8D;AAChH,OAAO,EAAE,2BAA2B,EAAE,sDAAkD;AACxF,OAAO,EAAE,6BAA6B,EAAE,wDAAoD;AAC5F,OAAO,EAAE,0BAA0B,EAAE,6BAAyB"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { walletCreateSession } from "./handlers/wallet-createSession.mjs";
|
|
1
2
|
export { walletGetSession } from "./handlers/wallet-getSession.mjs";
|
|
2
3
|
export { walletInvokeMethod } from "./handlers/wallet-invokeMethod.mjs";
|
|
3
4
|
export { walletRevokeSession } from "./handlers/wallet-revokeSession.mjs";
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,yCAAqC;AAChE,OAAO,EAAE,kBAAkB,EAAE,2CAAuC;AACpE,OAAO,EAAE,mBAAmB,EAAE,4CAAwC;AAEtE,OAAO,EAAE,uCAAuC,EAAE,kEAA8D;AAChH,OAAO,EAAE,2BAA2B,EAAE,sDAAkD;AACxF,OAAO,EAAE,6BAA6B,EAAE,wDAAoD;AAC5F,OAAO,EAAE,0BAA0B,EAAE,6BAAyB"}
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,4CAAwC;AACtE,OAAO,EAAE,gBAAgB,EAAE,yCAAqC;AAChE,OAAO,EAAE,kBAAkB,EAAE,2CAAuC;AACpE,OAAO,EAAE,mBAAmB,EAAE,4CAAwC;AAEtE,OAAO,EAAE,uCAAuC,EAAE,kEAA8D;AAChH,OAAO,EAAE,2BAA2B,EAAE,sDAAkD;AACxF,OAAO,EAAE,6BAA6B,EAAE,wDAAoD;AAC5F,OAAO,EAAE,0BAA0B,EAAE,6BAAyB"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { walletCreateSession } from "./handlers/wallet-createSession.mjs";
|
|
1
2
|
export { walletGetSession } from "./handlers/wallet-getSession.mjs";
|
|
2
3
|
export { walletInvokeMethod } from "./handlers/wallet-invokeMethod.mjs";
|
|
3
4
|
export { walletRevokeSession } from "./handlers/wallet-revokeSession.mjs";
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,yCAAqC;AAChE,OAAO,EAAE,kBAAkB,EAAE,2CAAuC;AACpE,OAAO,EAAE,mBAAmB,EAAE,4CAAwC;AAEtE,OAAO,EAAE,uCAAuC,EAAE,kEAA8D;AAChH,OAAO,EAAE,2BAA2B,EAAE,sDAAkD;AACxF,OAAO,EAAE,6BAA6B,EAAE,wDAAoD;AAC5F,OAAO,EAAE,0BAA0B,EAAE,6BAAyB","sourcesContent":["export { walletGetSession } from './handlers/wallet-getSession';\nexport { walletInvokeMethod } from './handlers/wallet-invokeMethod';\nexport { walletRevokeSession } from './handlers/wallet-revokeSession';\n\nexport { multichainMethodCallValidatorMiddleware } from './middlewares/multichainMethodCallValidatorMiddleware';\nexport { MultichainMiddlewareManager } from './middlewares/MultichainMiddlewareManager';\nexport { MultichainSubscriptionManager } from './middlewares/MultichainSubscriptionManager';\nexport { MultichainApiNotifications } from './handlers/types';\n"]}
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,4CAAwC;AACtE,OAAO,EAAE,gBAAgB,EAAE,yCAAqC;AAChE,OAAO,EAAE,kBAAkB,EAAE,2CAAuC;AACpE,OAAO,EAAE,mBAAmB,EAAE,4CAAwC;AAEtE,OAAO,EAAE,uCAAuC,EAAE,kEAA8D;AAChH,OAAO,EAAE,2BAA2B,EAAE,sDAAkD;AACxF,OAAO,EAAE,6BAA6B,EAAE,wDAAoD;AAC5F,OAAO,EAAE,0BAA0B,EAAE,6BAAyB","sourcesContent":["export { walletCreateSession } from './handlers/wallet-createSession';\nexport { walletGetSession } from './handlers/wallet-getSession';\nexport { walletInvokeMethod } from './handlers/wallet-invokeMethod';\nexport { walletRevokeSession } from './handlers/wallet-revokeSession';\n\nexport { multichainMethodCallValidatorMiddleware } from './middlewares/multichainMethodCallValidatorMiddleware';\nexport { MultichainMiddlewareManager } from './middlewares/MultichainMiddlewareManager';\nexport { MultichainSubscriptionManager } from './middlewares/MultichainSubscriptionManager';\nexport { MultichainApiNotifications } from './handlers/types';\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/multichain-api-middleware",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "JSON-RPC methods and middleware to support the MetaMask Multichain API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -48,9 +48,10 @@
|
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"@metamask/api-specs": "^0.10.12",
|
|
51
|
-
"@metamask/chain-agnostic-permission": "^0.
|
|
51
|
+
"@metamask/chain-agnostic-permission": "^0.4.0",
|
|
52
|
+
"@metamask/controller-utils": "^11.7.0",
|
|
52
53
|
"@metamask/json-rpc-engine": "^10.0.3",
|
|
53
|
-
"@metamask/network-controller": "^23.
|
|
54
|
+
"@metamask/network-controller": "^23.2.0",
|
|
54
55
|
"@metamask/permission-controller": "^11.0.6",
|
|
55
56
|
"@metamask/rpc-errors": "^7.0.2",
|
|
56
57
|
"@metamask/utils": "^11.2.0",
|
|
@@ -61,6 +62,7 @@
|
|
|
61
62
|
"devDependencies": {
|
|
62
63
|
"@metamask/auto-changelog": "^3.4.4",
|
|
63
64
|
"@metamask/eth-json-rpc-filters": "^9.0.0",
|
|
65
|
+
"@metamask/multichain-transactions-controller": "^0.9.0",
|
|
64
66
|
"@metamask/safe-event-emitter": "^3.0.0",
|
|
65
67
|
"@types/jest": "^27.4.1",
|
|
66
68
|
"deepmerge": "^4.2.2",
|