@metamask/multichain-api-middleware 0.1.0 → 0.1.1
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 +13 -1
- package/dist/handlers/types.cjs +12 -0
- package/dist/handlers/types.cjs.map +1 -0
- package/dist/handlers/types.d.cts +8 -0
- package/dist/handlers/types.d.cts.map +1 -0
- package/dist/handlers/types.d.mts +8 -0
- package/dist/handlers/types.d.mts.map +1 -0
- package/dist/handlers/types.mjs +9 -0
- package/dist/handlers/types.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/dist/middlewares/MultichainSubscriptionManager.cjs +2 -1
- package/dist/middlewares/MultichainSubscriptionManager.cjs.map +1 -1
- package/dist/middlewares/MultichainSubscriptionManager.d.cts.map +1 -1
- package/dist/middlewares/MultichainSubscriptionManager.d.mts.map +1 -1
- package/dist/middlewares/MultichainSubscriptionManager.mjs +2 -1
- package/dist/middlewares/MultichainSubscriptionManager.mjs.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -7,11 +7,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.1.1]
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Add `MultichainApiNotifications` enum to standardize notification method names ([#5491](https://github.com/MetaMask/core/pull/5491))
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
|
|
18
|
+
- Bump `@metamask/network-controller` to `^23.1.0` ([#5507](https://github.com/MetaMask/core/pull/5507), [#5518](https://github.com/MetaMask/core/pull/5518))
|
|
19
|
+
- Bump `@metamask/chain-agnostic-permission` to `^0.2.0` ([#5518](https://github.com/MetaMask/core/pull/5518))
|
|
20
|
+
|
|
10
21
|
## [0.1.0]
|
|
11
22
|
|
|
12
23
|
### Added
|
|
13
24
|
|
|
14
25
|
- Initial release
|
|
15
26
|
|
|
16
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/multichain-api-middleware@0.1.
|
|
27
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/multichain-api-middleware@0.1.1...HEAD
|
|
28
|
+
[0.1.1]: https://github.com/MetaMask/core/compare/@metamask/multichain-api-middleware@0.1.0...@metamask/multichain-api-middleware@0.1.1
|
|
17
29
|
[0.1.0]: https://github.com/MetaMask/core/releases/tag/@metamask/multichain-api-middleware@0.1.0
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MultichainApiNotifications = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Multichain API notifications currently supported by/known to the wallet.
|
|
6
|
+
*/
|
|
7
|
+
var MultichainApiNotifications;
|
|
8
|
+
(function (MultichainApiNotifications) {
|
|
9
|
+
MultichainApiNotifications["sessionChanged"] = "wallet_sessionChanged";
|
|
10
|
+
MultichainApiNotifications["walletNotify"] = "wallet_notify";
|
|
11
|
+
})(MultichainApiNotifications || (exports.MultichainApiNotifications = MultichainApiNotifications = {}));
|
|
12
|
+
//# sourceMappingURL=types.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../../src/handlers/types.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,IAAY,0BAGX;AAHD,WAAY,0BAA0B;IACpC,sEAAwC,CAAA;IACxC,4DAA8B,CAAA;AAChC,CAAC,EAHW,0BAA0B,0CAA1B,0BAA0B,QAGrC","sourcesContent":["/**\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"]}
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Multichain API notifications currently supported by/known to the wallet.
|
|
3
|
+
*/
|
|
4
|
+
export var MultichainApiNotifications;
|
|
5
|
+
(function (MultichainApiNotifications) {
|
|
6
|
+
MultichainApiNotifications["sessionChanged"] = "wallet_sessionChanged";
|
|
7
|
+
MultichainApiNotifications["walletNotify"] = "wallet_notify";
|
|
8
|
+
})(MultichainApiNotifications || (MultichainApiNotifications = {}));
|
|
9
|
+
//# sourceMappingURL=types.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../../src/handlers/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAN,IAAY,0BAGX;AAHD,WAAY,0BAA0B;IACpC,sEAAwC,CAAA;IACxC,4DAA8B,CAAA;AAChC,CAAC,EAHW,0BAA0B,KAA1B,0BAA0B,QAGrC","sourcesContent":["/**\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"]}
|
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
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 = void 0;
|
|
4
4
|
var wallet_getSession_1 = require("./handlers/wallet-getSession.cjs");
|
|
5
5
|
Object.defineProperty(exports, "walletGetSession", { enumerable: true, get: function () { return wallet_getSession_1.walletGetSession; } });
|
|
6
6
|
var wallet_invokeMethod_1 = require("./handlers/wallet-invokeMethod.cjs");
|
|
@@ -13,4 +13,6 @@ var MultichainMiddlewareManager_1 = require("./middlewares/MultichainMiddlewareM
|
|
|
13
13
|
Object.defineProperty(exports, "MultichainMiddlewareManager", { enumerable: true, get: function () { return MultichainMiddlewareManager_1.MultichainMiddlewareManager; } });
|
|
14
14
|
var MultichainSubscriptionManager_1 = require("./middlewares/MultichainSubscriptionManager.cjs");
|
|
15
15
|
Object.defineProperty(exports, "MultichainSubscriptionManager", { enumerable: true, get: function () { return MultichainSubscriptionManager_1.MultichainSubscriptionManager; } });
|
|
16
|
+
var types_1 = require("./handlers/types.cjs");
|
|
17
|
+
Object.defineProperty(exports, "MultichainApiNotifications", { enumerable: true, get: function () { return types_1.MultichainApiNotifications; } });
|
|
16
18
|
//# sourceMappingURL=index.cjs.map
|
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","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';\n"]}
|
|
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"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -4,4 +4,5 @@ export { walletRevokeSession } from "./handlers/wallet-revokeSession.cjs";
|
|
|
4
4
|
export { multichainMethodCallValidatorMiddleware } from "./middlewares/multichainMethodCallValidatorMiddleware.cjs";
|
|
5
5
|
export { MultichainMiddlewareManager } from "./middlewares/MultichainMiddlewareManager.cjs";
|
|
6
6
|
export { MultichainSubscriptionManager } from "./middlewares/MultichainSubscriptionManager.cjs";
|
|
7
|
+
export { MultichainApiNotifications } from "./handlers/types.cjs";
|
|
7
8
|
//# sourceMappingURL=index.d.cts.map
|
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"}
|
|
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"}
|
package/dist/index.d.mts
CHANGED
|
@@ -4,4 +4,5 @@ export { walletRevokeSession } from "./handlers/wallet-revokeSession.mjs";
|
|
|
4
4
|
export { multichainMethodCallValidatorMiddleware } from "./middlewares/multichainMethodCallValidatorMiddleware.mjs";
|
|
5
5
|
export { MultichainMiddlewareManager } from "./middlewares/MultichainMiddlewareManager.mjs";
|
|
6
6
|
export { MultichainSubscriptionManager } from "./middlewares/MultichainSubscriptionManager.mjs";
|
|
7
|
+
export { MultichainApiNotifications } from "./handlers/types.mjs";
|
|
7
8
|
//# sourceMappingURL=index.d.mts.map
|
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"}
|
|
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"}
|
package/dist/index.mjs
CHANGED
|
@@ -4,4 +4,5 @@ export { walletRevokeSession } from "./handlers/wallet-revokeSession.mjs";
|
|
|
4
4
|
export { multichainMethodCallValidatorMiddleware } from "./middlewares/multichainMethodCallValidatorMiddleware.mjs";
|
|
5
5
|
export { MultichainMiddlewareManager } from "./middlewares/MultichainMiddlewareManager.mjs";
|
|
6
6
|
export { MultichainSubscriptionManager } from "./middlewares/MultichainSubscriptionManager.mjs";
|
|
7
|
+
export { MultichainApiNotifications } from "./handlers/types.mjs";
|
|
7
8
|
//# sourceMappingURL=index.mjs.map
|
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","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';\n"]}
|
|
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"]}
|
|
@@ -20,6 +20,7 @@ const controller_utils_1 = require("@metamask/controller-utils");
|
|
|
20
20
|
const subscriptionManager_1 = __importDefault(require("@metamask/eth-json-rpc-filters/subscriptionManager.js"));
|
|
21
21
|
const safe_event_emitter_1 = __importDefault(require("@metamask/safe-event-emitter"));
|
|
22
22
|
const utils_1 = require("@metamask/utils");
|
|
23
|
+
const types_1 = require("../handlers/types.cjs");
|
|
23
24
|
/**
|
|
24
25
|
* A helper that facilates the lifecycle of a SubscriptionManager instance that
|
|
25
26
|
* is meant to handle subscriptons for only one specific scope, origin, and tabId combination.
|
|
@@ -43,7 +44,7 @@ class MultichainSubscriptionManager extends safe_event_emitter_1.default {
|
|
|
43
44
|
}
|
|
44
45
|
notify({ scope, origin, tabId }, { method, params }) {
|
|
45
46
|
this.emit('notification', origin, tabId, {
|
|
46
|
-
method:
|
|
47
|
+
method: types_1.MultichainApiNotifications.walletNotify,
|
|
47
48
|
params: {
|
|
48
49
|
scope,
|
|
49
50
|
notification: { method, params },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MultichainSubscriptionManager.cjs","sourceRoot":"","sources":["../../src/middlewares/MultichainSubscriptionManager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AACA,iEAAmD;AACnD,gHAA2F;AAE3F,sFAA4D;AAE5D,2CAAmD;
|
|
1
|
+
{"version":3,"file":"MultichainSubscriptionManager.cjs","sourceRoot":"","sources":["../../src/middlewares/MultichainSubscriptionManager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AACA,iEAAmD;AACnD,gHAA2F;AAE3F,sFAA4D;AAE5D,2CAAmD;AAGnD,iDAA+D;AA+B/D;;;GAGG;AACH,MAAa,6BAA8B,SAAQ,4BAAgB;IAOjE;;;;;;OAMG;IACH,YAAY,OAA6C;QACvD,KAAK,EAAE,CAAC;;QAdD,8EAAiF;QAEjF,sEAAiE;QAE1E,uDAAsC,EAAE,EAAC;QAWvC,uBAAA,IAAI,+DAAiC,OAAO,CAAC,4BAA4B,MAAA,CAAC;QA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,CAAC,CAAC,iBAAiB,EAAE,EAAE;QACpD,OAAO,CACL,iBAAiB,CAAC,KAAK,KAAK,KAAK;YACjC,iBAAiB,CAAC,MAAM,KAAK,MAAM;YACnC,iBAAiB,CAAC,KAAK,KAAK,KAAK,CAClC,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,2HAEwB,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAqB;IAClE,uBAAA,IAAI,gDAAkB,uBAAA,IAAI,oDAAe,CAAC,MAAM,CAAC,CAAC,iBAAiB,EAAE,EAAE;QACrE,OAAO,CACL,iBAAiB,CAAC,KAAK,KAAK,KAAK;YACjC,iBAAiB,CAAC,MAAM,KAAK,MAAM;YACnC,iBAAiB,CAAC,KAAK,KAAK,KAAK,CAClC,CAAC;IACJ,CAAC,CAAC,MAAA,CAAC;AACL,CAAC,mGAuCY,iBAAoC;IAC/C,iBAAiB,CAAC,mBAAmB,CAAC,OAAO,EAAE,EAAE,CAAC;IAElD,uBAAA,IAAI,wGAAyB,MAA7B,IAAI,EAA0B,iBAAiB,CAAC,CAAC;AACnD,CAAC","sourcesContent":["import type { ExternalScopeString } from '@metamask/chain-agnostic-permission';\nimport { toHex } from '@metamask/controller-utils';\nimport createSubscriptionManager from '@metamask/eth-json-rpc-filters/subscriptionManager';\nimport type { NetworkController } from '@metamask/network-controller';\nimport SafeEventEmitter from '@metamask/safe-event-emitter';\nimport type { CaipChainId, Hex } from '@metamask/utils';\nimport { parseCaipChainId } from '@metamask/utils';\n\nimport type { ExtendedJsonRpcMiddleware } from './MultichainMiddlewareManager';\nimport { MultichainApiNotifications } from '../handlers/types';\n\nexport type SubscriptionManager = {\n events: SafeEventEmitter;\n destroy?: () => void;\n middleware: ExtendedJsonRpcMiddleware;\n};\n\ntype SubscriptionNotificationEvent = {\n jsonrpc: '2.0';\n method: 'eth_subscription';\n params: {\n subscription: Hex;\n result: unknown;\n };\n};\n\ntype SubscriptionKey = {\n scope: ExternalScopeString;\n origin: string;\n tabId?: number;\n};\ntype SubscriptionEntry = SubscriptionKey & {\n subscriptionManager: SubscriptionManager;\n};\n\ntype MultichainSubscriptionManagerOptions = {\n findNetworkClientIdByChainId: NetworkController['findNetworkClientIdByChainId'];\n getNetworkClientById: NetworkController['getNetworkClientById'];\n};\n\n/**\n * A helper that facilates the lifecycle of a SubscriptionManager instance that\n * is meant to handle subscriptons for only one specific scope, origin, and tabId combination.\n */\nexport class MultichainSubscriptionManager extends SafeEventEmitter {\n readonly #findNetworkClientIdByChainId: NetworkController['findNetworkClientIdByChainId'];\n\n readonly #getNetworkClientById: NetworkController['getNetworkClientById'];\n\n #subscriptions: SubscriptionEntry[] = [];\n\n /**\n * Construct a MultichainSubscriptionManager.\n *\n * @param options - The controller options.\n * @param options.findNetworkClientIdByChainId - The hook to get the networkClientId from a chainId.\n * @param options.getNetworkClientById - The hook to get the network client instance by its networkClientId.\n */\n constructor(options: MultichainSubscriptionManagerOptions) {\n super();\n this.#findNetworkClientIdByChainId = options.findNetworkClientIdByChainId;\n this.#getNetworkClientById = options.getNetworkClientById;\n }\n\n notify(\n { scope, origin, tabId }: SubscriptionKey,\n { method, params }: SubscriptionNotificationEvent,\n ) {\n this.emit('notification', origin, tabId, {\n method: MultichainApiNotifications.walletNotify,\n params: {\n scope,\n notification: { method, params },\n },\n });\n }\n\n #getSubscriptionEntry({\n scope,\n origin,\n tabId,\n }: SubscriptionKey): SubscriptionEntry | undefined {\n return this.#subscriptions.find((subscriptionEntry) => {\n return (\n subscriptionEntry.scope === scope &&\n subscriptionEntry.origin === origin &&\n subscriptionEntry.tabId === tabId\n );\n });\n }\n\n #removeSubscriptionEntry({ scope, origin, tabId }: SubscriptionEntry) {\n this.#subscriptions = this.#subscriptions.filter((subscriptionEntry) => {\n return (\n subscriptionEntry.scope !== scope ||\n subscriptionEntry.origin !== origin ||\n subscriptionEntry.tabId !== tabId\n );\n });\n }\n\n subscribe(subscriptionKey: SubscriptionKey) {\n const subscriptionEntry = this.#getSubscriptionEntry(subscriptionKey);\n if (subscriptionEntry) {\n return subscriptionEntry.subscriptionManager;\n }\n\n const networkClientId = this.#findNetworkClientIdByChainId(\n toHex(parseCaipChainId(subscriptionKey.scope as CaipChainId).reference),\n );\n const networkClient = this.#getNetworkClientById(networkClientId);\n const subscriptionManager = createSubscriptionManager({\n blockTracker: networkClient.blockTracker,\n provider: networkClient.provider,\n });\n\n subscriptionManager.events.on(\n 'notification',\n (message: SubscriptionNotificationEvent) => {\n this.notify(subscriptionKey, message);\n },\n );\n\n const newSubscriptionManagerEntry = {\n ...subscriptionKey,\n subscriptionManager,\n };\n subscriptionManager.destroy = subscriptionManager.middleware.destroy;\n subscriptionManager.middleware.destroy = this.#unsubscribe.bind(\n this,\n newSubscriptionManagerEntry,\n );\n\n this.#subscriptions.push(newSubscriptionManagerEntry);\n\n return subscriptionManager;\n }\n\n #unsubscribe(subscriptionEntry: SubscriptionEntry) {\n subscriptionEntry.subscriptionManager.destroy?.();\n\n this.#removeSubscriptionEntry(subscriptionEntry);\n }\n\n unsubscribeByScope(scope: ExternalScopeString) {\n this.#subscriptions.forEach((subscriptionEntry) => {\n if (subscriptionEntry.scope === scope) {\n this.#unsubscribe(subscriptionEntry);\n }\n });\n }\n\n unsubscribeByScopeAndOrigin(scope: ExternalScopeString, origin: string) {\n this.#subscriptions.forEach((subscriptionEntry) => {\n if (\n subscriptionEntry.scope === scope &&\n subscriptionEntry.origin === origin\n ) {\n this.#unsubscribe(subscriptionEntry);\n }\n });\n }\n\n unsubscribeByOriginAndTabId(origin: string, tabId?: number) {\n this.#subscriptions.forEach((subscriptionEntry) => {\n if (\n subscriptionEntry.origin === origin &&\n subscriptionEntry.tabId === tabId\n ) {\n this.#unsubscribe(subscriptionEntry);\n }\n });\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MultichainSubscriptionManager.d.cts","sourceRoot":"","sources":["../../src/middlewares/MultichainSubscriptionManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,4CAA4C;AAG/E,OAAO,KAAK,EAAE,iBAAiB,EAAE,qCAAqC;AACtE,OAAO,gBAAgB,qCAAqC;AAC5D,OAAO,KAAK,EAAe,GAAG,EAAE,wBAAwB;AAGxD,OAAO,KAAK,EAAE,yBAAyB,EAAE,0CAAsC;
|
|
1
|
+
{"version":3,"file":"MultichainSubscriptionManager.d.cts","sourceRoot":"","sources":["../../src/middlewares/MultichainSubscriptionManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,4CAA4C;AAG/E,OAAO,KAAK,EAAE,iBAAiB,EAAE,qCAAqC;AACtE,OAAO,gBAAgB,qCAAqC;AAC5D,OAAO,KAAK,EAAe,GAAG,EAAE,wBAAwB;AAGxD,OAAO,KAAK,EAAE,yBAAyB,EAAE,0CAAsC;AAG/E,MAAM,MAAM,mBAAmB,GAAG;IAChC,MAAM,EAAE,gBAAgB,CAAC;IACzB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,UAAU,EAAE,yBAAyB,CAAC;CACvC,CAAC;AAEF,KAAK,6BAA6B,GAAG;IACnC,OAAO,EAAE,KAAK,CAAC;IACf,MAAM,EAAE,kBAAkB,CAAC;IAC3B,MAAM,EAAE;QACN,YAAY,EAAE,GAAG,CAAC;QAClB,MAAM,EAAE,OAAO,CAAC;KACjB,CAAC;CACH,CAAC;AAEF,KAAK,eAAe,GAAG;IACrB,KAAK,EAAE,mBAAmB,CAAC;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAKF,KAAK,oCAAoC,GAAG;IAC1C,4BAA4B,EAAE,iBAAiB,CAAC,8BAA8B,CAAC,CAAC;IAChF,oBAAoB,EAAE,iBAAiB,CAAC,sBAAsB,CAAC,CAAC;CACjE,CAAC;AAEF;;;GAGG;AACH,qBAAa,6BAA8B,SAAQ,gBAAgB;;IAOjE;;;;;;OAMG;gBACS,OAAO,EAAE,oCAAoC;IAMzD,MAAM,CACJ,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,eAAe,EACzC,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,6BAA6B;IAmCnD,SAAS,CAAC,eAAe,EAAE,eAAe;IA2C1C,kBAAkB,CAAC,KAAK,EAAE,mBAAmB;IAQ7C,2BAA2B,CAAC,KAAK,EAAE,mBAAmB,EAAE,MAAM,EAAE,MAAM;IAWtE,2BAA2B,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM;CAU3D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MultichainSubscriptionManager.d.mts","sourceRoot":"","sources":["../../src/middlewares/MultichainSubscriptionManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,4CAA4C;AAG/E,OAAO,KAAK,EAAE,iBAAiB,EAAE,qCAAqC;AACtE,OAAO,gBAAgB,qCAAqC;AAC5D,OAAO,KAAK,EAAe,GAAG,EAAE,wBAAwB;AAGxD,OAAO,KAAK,EAAE,yBAAyB,EAAE,0CAAsC;
|
|
1
|
+
{"version":3,"file":"MultichainSubscriptionManager.d.mts","sourceRoot":"","sources":["../../src/middlewares/MultichainSubscriptionManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,4CAA4C;AAG/E,OAAO,KAAK,EAAE,iBAAiB,EAAE,qCAAqC;AACtE,OAAO,gBAAgB,qCAAqC;AAC5D,OAAO,KAAK,EAAe,GAAG,EAAE,wBAAwB;AAGxD,OAAO,KAAK,EAAE,yBAAyB,EAAE,0CAAsC;AAG/E,MAAM,MAAM,mBAAmB,GAAG;IAChC,MAAM,EAAE,gBAAgB,CAAC;IACzB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,UAAU,EAAE,yBAAyB,CAAC;CACvC,CAAC;AAEF,KAAK,6BAA6B,GAAG;IACnC,OAAO,EAAE,KAAK,CAAC;IACf,MAAM,EAAE,kBAAkB,CAAC;IAC3B,MAAM,EAAE;QACN,YAAY,EAAE,GAAG,CAAC;QAClB,MAAM,EAAE,OAAO,CAAC;KACjB,CAAC;CACH,CAAC;AAEF,KAAK,eAAe,GAAG;IACrB,KAAK,EAAE,mBAAmB,CAAC;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAKF,KAAK,oCAAoC,GAAG;IAC1C,4BAA4B,EAAE,iBAAiB,CAAC,8BAA8B,CAAC,CAAC;IAChF,oBAAoB,EAAE,iBAAiB,CAAC,sBAAsB,CAAC,CAAC;CACjE,CAAC;AAEF;;;GAGG;AACH,qBAAa,6BAA8B,SAAQ,gBAAgB;;IAOjE;;;;;;OAMG;gBACS,OAAO,EAAE,oCAAoC;IAMzD,MAAM,CACJ,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,eAAe,EACzC,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,6BAA6B;IAmCnD,SAAS,CAAC,eAAe,EAAE,eAAe;IA2C1C,kBAAkB,CAAC,KAAK,EAAE,mBAAmB;IAQ7C,2BAA2B,CAAC,KAAK,EAAE,mBAAmB,EAAE,MAAM,EAAE,MAAM;IAWtE,2BAA2B,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM;CAU3D"}
|
|
@@ -21,6 +21,7 @@ import $createSubscriptionManager from "@metamask/eth-json-rpc-filters/subscript
|
|
|
21
21
|
const createSubscriptionManager = $importDefault($createSubscriptionManager);
|
|
22
22
|
import SafeEventEmitter from "@metamask/safe-event-emitter";
|
|
23
23
|
import { parseCaipChainId } from "@metamask/utils";
|
|
24
|
+
import { MultichainApiNotifications } from "../handlers/types.mjs";
|
|
24
25
|
/**
|
|
25
26
|
* A helper that facilates the lifecycle of a SubscriptionManager instance that
|
|
26
27
|
* is meant to handle subscriptons for only one specific scope, origin, and tabId combination.
|
|
@@ -44,7 +45,7 @@ export class MultichainSubscriptionManager extends SafeEventEmitter {
|
|
|
44
45
|
}
|
|
45
46
|
notify({ scope, origin, tabId }, { method, params }) {
|
|
46
47
|
this.emit('notification', origin, tabId, {
|
|
47
|
-
method:
|
|
48
|
+
method: MultichainApiNotifications.walletNotify,
|
|
48
49
|
params: {
|
|
49
50
|
scope,
|
|
50
51
|
notification: { method, params },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MultichainSubscriptionManager.mjs","sourceRoot":"","sources":["../../src/middlewares/MultichainSubscriptionManager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AACA,OAAO,EAAE,KAAK,EAAE,mCAAmC;AACnD,OAAO,0BAAyB,8DAA2D;;AAE3F,OAAO,gBAAgB,qCAAqC;AAE5D,OAAO,EAAE,gBAAgB,EAAE,wBAAwB;
|
|
1
|
+
{"version":3,"file":"MultichainSubscriptionManager.mjs","sourceRoot":"","sources":["../../src/middlewares/MultichainSubscriptionManager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AACA,OAAO,EAAE,KAAK,EAAE,mCAAmC;AACnD,OAAO,0BAAyB,8DAA2D;;AAE3F,OAAO,gBAAgB,qCAAqC;AAE5D,OAAO,EAAE,gBAAgB,EAAE,wBAAwB;AAGnD,OAAO,EAAE,0BAA0B,EAAE,8BAA0B;AA+B/D;;;GAGG;AACH,MAAM,OAAO,6BAA8B,SAAQ,gBAAgB;IAOjE;;;;;;OAMG;IACH,YAAY,OAA6C;QACvD,KAAK,EAAE,CAAC;;QAdD,8EAAiF;QAEjF,sEAAiE;QAE1E,uDAAsC,EAAE,EAAC;QAWvC,uBAAA,IAAI,+DAAiC,OAAO,CAAC,4BAA4B,MAAA,CAAC;QAC1E,uBAAA,IAAI,uDAAyB,OAAO,CAAC,oBAAoB,MAAA,CAAC;IAC5D,CAAC;IAED,MAAM,CACJ,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAA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ClC,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,2HAEwB,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAqB;IAClE,uBAAA,IAAI,gDAAkB,uBAAA,IAAI,oDAAe,CAAC,MAAM,CAAC,CAAC,iBAAiB,EAAE,EAAE;QACrE,OAAO,CACL,iBAAiB,CAAC,KAAK,KAAK,KAAK;YACjC,iBAAiB,CAAC,MAAM,KAAK,MAAM;YACnC,iBAAiB,CAAC,KAAK,KAAK,KAAK,CAClC,CAAC;IACJ,CAAC,CAAC,MAAA,CAAC;AACL,CAAC,mGAuCY,iBAAoC;IAC/C,iBAAiB,CAAC,mBAAmB,CAAC,OAAO,EAAE,EAAE,CAAC;IAElD,uBAAA,IAAI,wGAAyB,MAA7B,IAAI,EAA0B,iBAAiB,CAAC,CAAC;AACnD,CAAC","sourcesContent":["import type { ExternalScopeString } from '@metamask/chain-agnostic-permission';\nimport { toHex } from '@metamask/controller-utils';\nimport createSubscriptionManager from '@metamask/eth-json-rpc-filters/subscriptionManager';\nimport type { NetworkController } from '@metamask/network-controller';\nimport SafeEventEmitter from '@metamask/safe-event-emitter';\nimport type { CaipChainId, Hex } from '@metamask/utils';\nimport { parseCaipChainId } from '@metamask/utils';\n\nimport type { ExtendedJsonRpcMiddleware } from './MultichainMiddlewareManager';\nimport { MultichainApiNotifications } from '../handlers/types';\n\nexport type SubscriptionManager = {\n events: SafeEventEmitter;\n destroy?: () => void;\n middleware: ExtendedJsonRpcMiddleware;\n};\n\ntype SubscriptionNotificationEvent = {\n jsonrpc: '2.0';\n method: 'eth_subscription';\n params: {\n subscription: Hex;\n result: unknown;\n };\n};\n\ntype SubscriptionKey = {\n scope: ExternalScopeString;\n origin: string;\n tabId?: number;\n};\ntype SubscriptionEntry = SubscriptionKey & {\n subscriptionManager: SubscriptionManager;\n};\n\ntype MultichainSubscriptionManagerOptions = {\n findNetworkClientIdByChainId: NetworkController['findNetworkClientIdByChainId'];\n getNetworkClientById: NetworkController['getNetworkClientById'];\n};\n\n/**\n * A helper that facilates the lifecycle of a SubscriptionManager instance that\n * is meant to handle subscriptons for only one specific scope, origin, and tabId combination.\n */\nexport class MultichainSubscriptionManager extends SafeEventEmitter {\n readonly #findNetworkClientIdByChainId: NetworkController['findNetworkClientIdByChainId'];\n\n readonly #getNetworkClientById: NetworkController['getNetworkClientById'];\n\n #subscriptions: SubscriptionEntry[] = [];\n\n /**\n * Construct a MultichainSubscriptionManager.\n *\n * @param options - The controller options.\n * @param options.findNetworkClientIdByChainId - The hook to get the networkClientId from a chainId.\n * @param options.getNetworkClientById - The hook to get the network client instance by its networkClientId.\n */\n constructor(options: MultichainSubscriptionManagerOptions) {\n super();\n this.#findNetworkClientIdByChainId = options.findNetworkClientIdByChainId;\n this.#getNetworkClientById = options.getNetworkClientById;\n }\n\n notify(\n { scope, origin, tabId }: SubscriptionKey,\n { method, params }: SubscriptionNotificationEvent,\n ) {\n this.emit('notification', origin, tabId, {\n method: MultichainApiNotifications.walletNotify,\n params: {\n scope,\n notification: { method, params },\n },\n });\n }\n\n #getSubscriptionEntry({\n scope,\n origin,\n tabId,\n }: SubscriptionKey): SubscriptionEntry | undefined {\n return this.#subscriptions.find((subscriptionEntry) => {\n return (\n subscriptionEntry.scope === scope &&\n subscriptionEntry.origin === origin &&\n subscriptionEntry.tabId === tabId\n );\n });\n }\n\n #removeSubscriptionEntry({ scope, origin, tabId }: SubscriptionEntry) {\n this.#subscriptions = this.#subscriptions.filter((subscriptionEntry) => {\n return (\n subscriptionEntry.scope !== scope ||\n subscriptionEntry.origin !== origin ||\n subscriptionEntry.tabId !== tabId\n );\n });\n }\n\n subscribe(subscriptionKey: SubscriptionKey) {\n const subscriptionEntry = this.#getSubscriptionEntry(subscriptionKey);\n if (subscriptionEntry) {\n return subscriptionEntry.subscriptionManager;\n }\n\n const networkClientId = this.#findNetworkClientIdByChainId(\n toHex(parseCaipChainId(subscriptionKey.scope as CaipChainId).reference),\n );\n const networkClient = this.#getNetworkClientById(networkClientId);\n const subscriptionManager = createSubscriptionManager({\n blockTracker: networkClient.blockTracker,\n provider: networkClient.provider,\n });\n\n subscriptionManager.events.on(\n 'notification',\n (message: SubscriptionNotificationEvent) => {\n this.notify(subscriptionKey, message);\n },\n );\n\n const newSubscriptionManagerEntry = {\n ...subscriptionKey,\n subscriptionManager,\n };\n subscriptionManager.destroy = subscriptionManager.middleware.destroy;\n subscriptionManager.middleware.destroy = this.#unsubscribe.bind(\n this,\n newSubscriptionManagerEntry,\n );\n\n this.#subscriptions.push(newSubscriptionManagerEntry);\n\n return subscriptionManager;\n }\n\n #unsubscribe(subscriptionEntry: SubscriptionEntry) {\n subscriptionEntry.subscriptionManager.destroy?.();\n\n this.#removeSubscriptionEntry(subscriptionEntry);\n }\n\n unsubscribeByScope(scope: ExternalScopeString) {\n this.#subscriptions.forEach((subscriptionEntry) => {\n if (subscriptionEntry.scope === scope) {\n this.#unsubscribe(subscriptionEntry);\n }\n });\n }\n\n unsubscribeByScopeAndOrigin(scope: ExternalScopeString, origin: string) {\n this.#subscriptions.forEach((subscriptionEntry) => {\n if (\n subscriptionEntry.scope === scope &&\n subscriptionEntry.origin === origin\n ) {\n this.#unsubscribe(subscriptionEntry);\n }\n });\n }\n\n unsubscribeByOriginAndTabId(origin: string, tabId?: number) {\n this.#subscriptions.forEach((subscriptionEntry) => {\n if (\n subscriptionEntry.origin === origin &&\n subscriptionEntry.tabId === tabId\n ) {\n this.#unsubscribe(subscriptionEntry);\n }\n });\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/multichain-api-middleware",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "JSON-RPC methods and middleware to support the MetaMask Multichain API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -48,9 +48,9 @@
|
|
|
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.2.0",
|
|
52
52
|
"@metamask/json-rpc-engine": "^10.0.3",
|
|
53
|
-
"@metamask/network-controller": "^
|
|
53
|
+
"@metamask/network-controller": "^23.1.0",
|
|
54
54
|
"@metamask/permission-controller": "^11.0.6",
|
|
55
55
|
"@metamask/rpc-errors": "^7.0.2",
|
|
56
56
|
"@metamask/utils": "^11.2.0",
|