@metamask-previews/compliance-controller 2.0.1-preview-d3514bcb5 → 2.0.1-preview-838d6b234
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +0 -9
- package/README.md +5 -2
- package/dist/ComplianceController.cjs +3 -4
- package/dist/ComplianceController.cjs.map +1 -1
- package/dist/ComplianceController.d.cts.map +1 -1
- package/dist/ComplianceController.d.mts.map +1 -1
- package/dist/ComplianceController.mjs +3 -4
- package/dist/ComplianceController.mjs.map +1 -1
- package/dist/ComplianceService.cjs +7 -27
- package/dist/ComplianceService.cjs.map +1 -1
- package/dist/ComplianceService.d.cts +9 -20
- package/dist/ComplianceService.d.cts.map +1 -1
- package/dist/ComplianceService.d.mts +9 -20
- package/dist/ComplianceService.d.mts.map +1 -1
- package/dist/ComplianceService.mjs +7 -27
- package/dist/ComplianceService.mjs.map +1 -1
- package/dist/index.cjs +1 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/selectors.cjs +2 -13
- package/dist/selectors.cjs.map +1 -1
- package/dist/selectors.d.cts +0 -9
- package/dist/selectors.d.cts.map +1 -1
- package/dist/selectors.d.mts +0 -9
- package/dist/selectors.d.mts.map +1 -1
- package/dist/selectors.mjs +1 -11
- package/dist/selectors.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/utils.cjs +0 -15
- package/dist/utils.cjs.map +0 -1
- package/dist/utils.d.cts +0 -3
- package/dist/utils.d.cts.map +0 -1
- package/dist/utils.d.mts +0 -3
- package/dist/utils.d.mts.map +0 -1
- package/dist/utils.mjs +0 -11
- package/dist/utils.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,19 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
-
### Added
|
|
11
|
-
|
|
12
|
-
- Add `ComplianceService` support for an explicit Compliance API URL ([#8820](https://github.com/MetaMask/core/pull/8820)).
|
|
13
|
-
- Add `selectAreAnyWalletsBlocked` ([#8820](https://github.com/MetaMask/core/pull/8820)).
|
|
14
|
-
|
|
15
10
|
### Changed
|
|
16
11
|
|
|
17
12
|
- Bump `@metamask/controller-utils` from `^12.0.0` to `^12.1.0` ([#8774](https://github.com/MetaMask/core/pull/8774))
|
|
18
13
|
|
|
19
|
-
### Fixed
|
|
20
|
-
|
|
21
|
-
- Match EVM address casing consistently when reading cached wallet compliance statuses ([#8820](https://github.com/MetaMask/core/pull/8820)).
|
|
22
|
-
|
|
23
14
|
## [2.0.1]
|
|
24
15
|
|
|
25
16
|
### Changed
|
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ Manages OFAC compliance checks for wallet addresses by interfacing with the Comp
|
|
|
7
7
|
This package provides:
|
|
8
8
|
|
|
9
9
|
- **`ComplianceService`** — A data service that communicates with the Compliance API to check whether wallet addresses are sanctioned under OFAC regulations.
|
|
10
|
-
- **`ComplianceController`** — A controller that manages compliance state, caching wallet compliance results.
|
|
10
|
+
- **`ComplianceController`** — A controller that manages compliance state, caching wallet compliance results and blocked wallet lists.
|
|
11
11
|
|
|
12
12
|
## Installation
|
|
13
13
|
|
|
@@ -47,7 +47,7 @@ const serviceMessenger = new Messenger({
|
|
|
47
47
|
new ComplianceService({
|
|
48
48
|
messenger: serviceMessenger,
|
|
49
49
|
fetch,
|
|
50
|
-
|
|
50
|
+
env: 'production',
|
|
51
51
|
});
|
|
52
52
|
|
|
53
53
|
// Create controller messenger and controller
|
|
@@ -70,6 +70,9 @@ await rootMessenger.call('ComplianceController:checkWalletsCompliance', [
|
|
|
70
70
|
'0x1234...',
|
|
71
71
|
'0x5678...',
|
|
72
72
|
]);
|
|
73
|
+
|
|
74
|
+
// Fetch the full blocked wallets list
|
|
75
|
+
await rootMessenger.call('ComplianceController:updateBlockedWallets');
|
|
73
76
|
```
|
|
74
77
|
|
|
75
78
|
## Contributing
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ComplianceController = exports.getDefaultComplianceControllerState = exports.controllerName = void 0;
|
|
4
4
|
const base_controller_1 = require("@metamask/base-controller");
|
|
5
|
-
const utils_1 = require("./utils.cjs");
|
|
6
5
|
// === GENERAL ===
|
|
7
6
|
/**
|
|
8
7
|
* The name of the {@link ComplianceController}, used to namespace the
|
|
@@ -101,7 +100,7 @@ class ComplianceController extends base_controller_1.BaseController {
|
|
|
101
100
|
return status;
|
|
102
101
|
}
|
|
103
102
|
catch (error) {
|
|
104
|
-
const cached =
|
|
103
|
+
const cached = this.state.walletComplianceStatusMap[address];
|
|
105
104
|
if (cached) {
|
|
106
105
|
return cached;
|
|
107
106
|
}
|
|
@@ -137,8 +136,8 @@ class ComplianceController extends base_controller_1.BaseController {
|
|
|
137
136
|
return statuses;
|
|
138
137
|
}
|
|
139
138
|
catch (error) {
|
|
140
|
-
const cachedStatuses = addresses.map((address) =>
|
|
141
|
-
if (cachedStatuses.every(
|
|
139
|
+
const cachedStatuses = addresses.map((address) => this.state.walletComplianceStatusMap[address]);
|
|
140
|
+
if (cachedStatuses.every(Boolean)) {
|
|
142
141
|
return cachedStatuses;
|
|
143
142
|
}
|
|
144
143
|
throw error;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComplianceController.cjs","sourceRoot":"","sources":["../src/ComplianceController.ts"],"names":[],"mappings":";;;AAKA,+DAA2D;AAS3D,uCAAoD;AAEpD,kBAAkB;AAElB;;;;GAIG;AACU,QAAA,cAAc,GAAG,sBAAsB,CAAC;AAqBrD;;GAEG;AACH,MAAM,4BAA4B,GAAG;IACnC,yBAAyB,EAAE;QACzB,sBAAsB,EAAE,KAAK;QAC7B,kBAAkB,EA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CAAC,CAAC;YAEH,OAAO,QAAQ,CAAC;QAClB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,cAAc,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAC/C,IAAA,iCAAyB,EACvB,IAAI,CAAC,KAAK,CAAC,yBAAyB,EACpC,OAAO,CACR,CACF,CAAC;YACF,IACE,cAAc,CAAC,KAAK,CAAC,CAAC,MAAM,EAAoC,EAAE,CAChE,OAAO,CAAC,MAAM,CAAC,CAChB,EACD,CAAC;gBACD,OAAO,cAAc,CAAC;YACxB,CAAC;YACD,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;IAED;;OAEG;IACH,oBAAoB;QAClB,IAAI,CAAC,MAAM,CAAC,CAAC,UAAU,EAAE,EAAE;YACzB,UAAU,CAAC,yBAAyB,GAAG,EAAE,CAAC;YAC1C,UAAU,CAAC,aAAa,GAAG,IAAI,CAAC;QAClC,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AA7ID,oDA6IC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\n\nimport type { ComplianceControllerMethodActions } from './ComplianceController-method-action-types';\nimport type {\n ComplianceServiceCheckWalletComplianceAction,\n ComplianceServiceCheckWalletsComplianceAction,\n} from './ComplianceService-method-action-types';\nimport type { WalletComplianceStatus } from './types';\nimport { getWalletComplianceStatus } from './utils';\n\n// === GENERAL ===\n\n/**\n * The name of the {@link ComplianceController}, used to namespace the\n * controller's actions and events and to namespace the controller's state data\n * when composed with other controllers.\n */\nexport const controllerName = 'ComplianceController';\n\n// === STATE ===\n\n/**\n * Describes the shape of the state object for {@link ComplianceController}.\n */\nexport type ComplianceControllerState = {\n /**\n * A map of wallet addresses to their compliance check results, used as a\n * fallback cache when the API is unavailable.\n */\n walletComplianceStatusMap: Record<string, WalletComplianceStatus>;\n\n /**\n * The date/time (in ISO-8601 format) when the last compliance check was\n * performed, or `null` if no checks have been performed yet.\n */\n lastCheckedAt: string | null;\n};\n\n/**\n * The metadata for each property in {@link ComplianceControllerState}.\n */\nconst complianceControllerMetadata = {\n walletComplianceStatusMap: {\n includeInDebugSnapshot: false,\n includeInStateLogs: false,\n persist: true,\n usedInUi: true,\n },\n lastCheckedAt: {\n includeInDebugSnapshot: false,\n includeInStateLogs: true,\n persist: true,\n usedInUi: false,\n },\n} satisfies StateMetadata<ComplianceControllerState>;\n\n/**\n * Constructs the default {@link ComplianceController} state. This allows\n * consumers to provide a partial state object when initializing the controller\n * and also helps in constructing complete state objects for this controller in\n * tests.\n *\n * @returns The default {@link ComplianceController} state.\n */\nexport function getDefaultComplianceControllerState(): ComplianceControllerState {\n return {\n walletComplianceStatusMap: {},\n lastCheckedAt: null,\n };\n}\n\n// === MESSENGER ===\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'checkWalletCompliance',\n 'checkWalletsCompliance',\n 'clearComplianceState',\n] as const;\n\n/**\n * Retrieves the state of the {@link ComplianceController}.\n */\nexport type ComplianceControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n ComplianceControllerState\n>;\n\n/**\n * Actions that {@link ComplianceController} exposes to other consumers.\n */\nexport type ComplianceControllerActions =\n | ComplianceControllerGetStateAction\n | ComplianceControllerMethodActions;\n\n/**\n * Actions from other messengers that {@link ComplianceController} calls.\n */\ntype AllowedActions =\n | ComplianceServiceCheckWalletComplianceAction\n | ComplianceServiceCheckWalletsComplianceAction;\n\n/**\n * Published when the state of {@link ComplianceController} changes.\n */\nexport type ComplianceControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n ComplianceControllerState\n>;\n\n/**\n * Events that {@link ComplianceController} exposes to other consumers.\n */\nexport type ComplianceControllerEvents = ComplianceControllerStateChangeEvent;\n\n/**\n * Events from other messengers that {@link ComplianceController} subscribes to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger restricted to actions and events accessed by\n * {@link ComplianceController}.\n */\nexport type ComplianceControllerMessenger = Messenger<\n typeof controllerName,\n ComplianceControllerActions | AllowedActions,\n ComplianceControllerEvents | AllowedEvents\n>;\n\n// === CONTROLLER DEFINITION ===\n\n/**\n * `ComplianceController` manages OFAC compliance state for wallet addresses.\n * It performs on-demand compliance checks via the API and caches results\n * per address in state. Cached results serve as a fallback if the API is\n * unavailable for a subsequent check on the same address.\n */\nexport class ComplianceController extends BaseController<\n typeof controllerName,\n ComplianceControllerState,\n ComplianceControllerMessenger\n> {\n /**\n * Constructs a new {@link ComplianceController}.\n *\n * @param args - The constructor arguments.\n * @param args.messenger - The messenger suited for this controller.\n * @param args.state - The desired state with which to init this\n * controller. Missing properties will be filled in with defaults.\n */\n constructor({\n messenger,\n state,\n }: {\n messenger: ComplianceControllerMessenger;\n state?: Partial<ComplianceControllerState>;\n }) {\n super({\n messenger,\n metadata: complianceControllerMetadata,\n name: controllerName,\n state: {\n ...getDefaultComplianceControllerState(),\n ...state,\n },\n });\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Checks compliance status for a single wallet address via the API and\n * persists the result to state. If the API call fails and a previously\n * cached result exists for the address, the cached result is returned as a\n * fallback. If no cached result exists, the error is re-thrown.\n *\n * @param address - The wallet address to check.\n * @returns The compliance status of the wallet.\n */\n async checkWalletCompliance(\n address: string,\n ): Promise<WalletComplianceStatus> {\n try {\n const result = await this.messenger.call(\n 'ComplianceService:checkWalletCompliance',\n address,\n );\n\n const now = new Date().toISOString();\n const status: WalletComplianceStatus = {\n address: result.address,\n blocked: result.blocked,\n checkedAt: now,\n };\n\n this.update((draftState) => {\n draftState.walletComplianceStatusMap[address] = status;\n draftState.lastCheckedAt = now;\n });\n\n return status;\n } catch (error) {\n const cached = getWalletComplianceStatus(\n this.state.walletComplianceStatusMap,\n address,\n );\n if (cached) {\n return cached;\n }\n throw error;\n }\n }\n\n /**\n * Checks compliance status for multiple wallet addresses via the API and\n * persists the results to state. If the API call fails and every requested\n * address has a previously cached result, those cached results are returned\n * as a fallback. If any address lacks a cached result, the error is\n * re-thrown.\n *\n * @param addresses - The wallet addresses to check.\n * @returns The compliance statuses of the wallets.\n */\n async checkWalletsCompliance(\n addresses: string[],\n ): Promise<WalletComplianceStatus[]> {\n try {\n const results = await this.messenger.call(\n 'ComplianceService:checkWalletsCompliance',\n addresses,\n );\n\n const now = new Date().toISOString();\n const statuses: WalletComplianceStatus[] = results.map((result) => ({\n address: result.address,\n blocked: result.blocked,\n checkedAt: now,\n }));\n\n this.update((draftState) => {\n for (let idx = 0; idx < statuses.length; idx++) {\n const callerAddress = addresses[idx];\n draftState.walletComplianceStatusMap[callerAddress] = statuses[idx];\n }\n draftState.lastCheckedAt = now;\n });\n\n return statuses;\n } catch (error) {\n const cachedStatuses = addresses.map((address) =>\n getWalletComplianceStatus(\n this.state.walletComplianceStatusMap,\n address,\n ),\n );\n if (\n cachedStatuses.every((status): status is WalletComplianceStatus =>\n Boolean(status),\n )\n ) {\n return cachedStatuses;\n }\n throw error;\n }\n }\n\n /**\n * Clears all compliance data from state.\n */\n clearComplianceState(): void {\n this.update((draftState) => {\n draftState.walletComplianceStatusMap = {};\n draftState.lastCheckedAt = null;\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ComplianceController.cjs","sourceRoot":"","sources":["../src/ComplianceController.ts"],"names":[],"mappings":";;;AAKA,+DAA2D;AAU3D,kBAAkB;AAElB;;;;GAIG;AACU,QAAA,cAAc,GAAG,sBAAsB,CAAC;AAqBrD;;GAEG;AACH,MAAM,4BAA4B,GAAG;IACnC,yBAAyB,EAAE;QACzB,sBAAsB,EAAE,KAAK;QAC7B,kBAAkB,EAAE,KAAK;QACzB,OAAO,EAAE,IAAI;QACb,QAAQ,EAAE,IAAI;KACf;IACD,aAAa,EAAE;QACb,sBAAsB,EAAE,KAAK;QAC7B,kBAAkB,EAAE,IAAI;QACxB,OAA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AI,CAAC,KAAK,CAAC,yBAAyB,CAAC,OAAO,CAAC,CAC3D,CAAC;YACF,IAAI,cAAc,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;gBAClC,OAAO,cAAc,CAAC;YACxB,CAAC;YACD,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;IAED;;OAEG;IACH,oBAAoB;QAClB,IAAI,CAAC,MAAM,CAAC,CAAC,UAAU,EAAE,EAAE;YACzB,UAAU,CAAC,yBAAyB,GAAG,EAAE,CAAC;YAC1C,UAAU,CAAC,aAAa,GAAG,IAAI,CAAC;QAClC,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAnID,oDAmIC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\n\nimport type { ComplianceControllerMethodActions } from './ComplianceController-method-action-types';\nimport type {\n ComplianceServiceCheckWalletComplianceAction,\n ComplianceServiceCheckWalletsComplianceAction,\n} from './ComplianceService-method-action-types';\nimport type { WalletComplianceStatus } from './types';\n\n// === GENERAL ===\n\n/**\n * The name of the {@link ComplianceController}, used to namespace the\n * controller's actions and events and to namespace the controller's state data\n * when composed with other controllers.\n */\nexport const controllerName = 'ComplianceController';\n\n// === STATE ===\n\n/**\n * Describes the shape of the state object for {@link ComplianceController}.\n */\nexport type ComplianceControllerState = {\n /**\n * A map of wallet addresses to their compliance check results, used as a\n * fallback cache when the API is unavailable.\n */\n walletComplianceStatusMap: Record<string, WalletComplianceStatus>;\n\n /**\n * The date/time (in ISO-8601 format) when the last compliance check was\n * performed, or `null` if no checks have been performed yet.\n */\n lastCheckedAt: string | null;\n};\n\n/**\n * The metadata for each property in {@link ComplianceControllerState}.\n */\nconst complianceControllerMetadata = {\n walletComplianceStatusMap: {\n includeInDebugSnapshot: false,\n includeInStateLogs: false,\n persist: true,\n usedInUi: true,\n },\n lastCheckedAt: {\n includeInDebugSnapshot: false,\n includeInStateLogs: true,\n persist: true,\n usedInUi: false,\n },\n} satisfies StateMetadata<ComplianceControllerState>;\n\n/**\n * Constructs the default {@link ComplianceController} state. This allows\n * consumers to provide a partial state object when initializing the controller\n * and also helps in constructing complete state objects for this controller in\n * tests.\n *\n * @returns The default {@link ComplianceController} state.\n */\nexport function getDefaultComplianceControllerState(): ComplianceControllerState {\n return {\n walletComplianceStatusMap: {},\n lastCheckedAt: null,\n };\n}\n\n// === MESSENGER ===\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'checkWalletCompliance',\n 'checkWalletsCompliance',\n 'clearComplianceState',\n] as const;\n\n/**\n * Retrieves the state of the {@link ComplianceController}.\n */\nexport type ComplianceControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n ComplianceControllerState\n>;\n\n/**\n * Actions that {@link ComplianceController} exposes to other consumers.\n */\nexport type ComplianceControllerActions =\n | ComplianceControllerGetStateAction\n | ComplianceControllerMethodActions;\n\n/**\n * Actions from other messengers that {@link ComplianceController} calls.\n */\ntype AllowedActions =\n | ComplianceServiceCheckWalletComplianceAction\n | ComplianceServiceCheckWalletsComplianceAction;\n\n/**\n * Published when the state of {@link ComplianceController} changes.\n */\nexport type ComplianceControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n ComplianceControllerState\n>;\n\n/**\n * Events that {@link ComplianceController} exposes to other consumers.\n */\nexport type ComplianceControllerEvents = ComplianceControllerStateChangeEvent;\n\n/**\n * Events from other messengers that {@link ComplianceController} subscribes to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger restricted to actions and events accessed by\n * {@link ComplianceController}.\n */\nexport type ComplianceControllerMessenger = Messenger<\n typeof controllerName,\n ComplianceControllerActions | AllowedActions,\n ComplianceControllerEvents | AllowedEvents\n>;\n\n// === CONTROLLER DEFINITION ===\n\n/**\n * `ComplianceController` manages OFAC compliance state for wallet addresses.\n * It performs on-demand compliance checks via the API and caches results\n * per address in state. Cached results serve as a fallback if the API is\n * unavailable for a subsequent check on the same address.\n */\nexport class ComplianceController extends BaseController<\n typeof controllerName,\n ComplianceControllerState,\n ComplianceControllerMessenger\n> {\n /**\n * Constructs a new {@link ComplianceController}.\n *\n * @param args - The constructor arguments.\n * @param args.messenger - The messenger suited for this controller.\n * @param args.state - The desired state with which to init this\n * controller. Missing properties will be filled in with defaults.\n */\n constructor({\n messenger,\n state,\n }: {\n messenger: ComplianceControllerMessenger;\n state?: Partial<ComplianceControllerState>;\n }) {\n super({\n messenger,\n metadata: complianceControllerMetadata,\n name: controllerName,\n state: {\n ...getDefaultComplianceControllerState(),\n ...state,\n },\n });\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Checks compliance status for a single wallet address via the API and\n * persists the result to state. If the API call fails and a previously\n * cached result exists for the address, the cached result is returned as a\n * fallback. If no cached result exists, the error is re-thrown.\n *\n * @param address - The wallet address to check.\n * @returns The compliance status of the wallet.\n */\n async checkWalletCompliance(\n address: string,\n ): Promise<WalletComplianceStatus> {\n try {\n const result = await this.messenger.call(\n 'ComplianceService:checkWalletCompliance',\n address,\n );\n\n const now = new Date().toISOString();\n const status: WalletComplianceStatus = {\n address: result.address,\n blocked: result.blocked,\n checkedAt: now,\n };\n\n this.update((draftState) => {\n draftState.walletComplianceStatusMap[address] = status;\n draftState.lastCheckedAt = now;\n });\n\n return status;\n } catch (error) {\n const cached = this.state.walletComplianceStatusMap[address];\n if (cached) {\n return cached;\n }\n throw error;\n }\n }\n\n /**\n * Checks compliance status for multiple wallet addresses via the API and\n * persists the results to state. If the API call fails and every requested\n * address has a previously cached result, those cached results are returned\n * as a fallback. If any address lacks a cached result, the error is\n * re-thrown.\n *\n * @param addresses - The wallet addresses to check.\n * @returns The compliance statuses of the wallets.\n */\n async checkWalletsCompliance(\n addresses: string[],\n ): Promise<WalletComplianceStatus[]> {\n try {\n const results = await this.messenger.call(\n 'ComplianceService:checkWalletsCompliance',\n addresses,\n );\n\n const now = new Date().toISOString();\n const statuses: WalletComplianceStatus[] = results.map((result) => ({\n address: result.address,\n blocked: result.blocked,\n checkedAt: now,\n }));\n\n this.update((draftState) => {\n for (let idx = 0; idx < statuses.length; idx++) {\n const callerAddress = addresses[idx];\n draftState.walletComplianceStatusMap[callerAddress] = statuses[idx];\n }\n draftState.lastCheckedAt = now;\n });\n\n return statuses;\n } catch (error) {\n const cachedStatuses = addresses.map(\n (address) => this.state.walletComplianceStatusMap[address],\n );\n if (cachedStatuses.every(Boolean)) {\n return cachedStatuses;\n }\n throw error;\n }\n }\n\n /**\n * Clears all compliance data from state.\n */\n clearComplianceState(): void {\n this.update((draftState) => {\n draftState.walletComplianceStatusMap = {};\n draftState.lastCheckedAt = null;\n });\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComplianceController.d.cts","sourceRoot":"","sources":["../src/ComplianceController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAErD,OAAO,KAAK,EAAE,iCAAiC,EAAE,uDAAmD;AACpG,OAAO,KAAK,EACV,4CAA4C,EAC5C,6CAA6C,EAC9C,oDAAgD;AACjD,OAAO,KAAK,EAAE,sBAAsB,EAAE,oBAAgB;
|
|
1
|
+
{"version":3,"file":"ComplianceController.d.cts","sourceRoot":"","sources":["../src/ComplianceController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAErD,OAAO,KAAK,EAAE,iCAAiC,EAAE,uDAAmD;AACpG,OAAO,KAAK,EACV,4CAA4C,EAC5C,6CAA6C,EAC9C,oDAAgD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,CACzB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,sBAAsB,CAAC;IA6BlC;;;;;;;;;OASG;IACG,sBAAsB,CAC1B,SAAS,EAAE,MAAM,EAAE,GAClB,OAAO,CAAC,sBAAsB,EAAE,CAAC;IAkCpC;;OAEG;IACH,oBAAoB,IAAI,IAAI;CAM7B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComplianceController.d.mts","sourceRoot":"","sources":["../src/ComplianceController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAErD,OAAO,KAAK,EAAE,iCAAiC,EAAE,uDAAmD;AACpG,OAAO,KAAK,EACV,4CAA4C,EAC5C,6CAA6C,EAC9C,oDAAgD;AACjD,OAAO,KAAK,EAAE,sBAAsB,EAAE,oBAAgB;
|
|
1
|
+
{"version":3,"file":"ComplianceController.d.mts","sourceRoot":"","sources":["../src/ComplianceController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAErD,OAAO,KAAK,EAAE,iCAAiC,EAAE,uDAAmD;AACpG,OAAO,KAAK,EACV,4CAA4C,EAC5C,6CAA6C,EAC9C,oDAAgD;AACjD,OAAO,KAAK,EAAE,sBAAsB,EAAE,oBAAgB;AAItD;;;;GAIG;AACH,eAAO,MAAM,cAAc,yBAAyB,CAAC;AAIrD;;GAEG;AACH,MAAM,MAAM,yBAAyB,GAAG;IACtC;;;OAGG;IACH,yBAAyB,EAAE,MAAM,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC;IAElE;;;OAGG;IACH,aAAa,EAAE,MAAM,GAAG,IAA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ller";
|
|
2
|
-
import { getWalletComplianceStatus } from "./utils.mjs";
|
|
3
2
|
// === GENERAL ===
|
|
4
3
|
/**
|
|
5
4
|
* The name of the {@link ComplianceController}, used to namespace the
|
|
@@ -97,7 +96,7 @@ export class ComplianceController extends BaseController {
|
|
|
97
96
|
return status;
|
|
98
97
|
}
|
|
99
98
|
catch (error) {
|
|
100
|
-
const cached =
|
|
99
|
+
const cached = this.state.walletComplianceStatusMap[address];
|
|
101
100
|
if (cached) {
|
|
102
101
|
return cached;
|
|
103
102
|
}
|
|
@@ -133,8 +132,8 @@ export class ComplianceController extends BaseController {
|
|
|
133
132
|
return statuses;
|
|
134
133
|
}
|
|
135
134
|
catch (error) {
|
|
136
|
-
const cachedStatuses = addresses.map((address) =>
|
|
137
|
-
if (cachedStatuses.every(
|
|
135
|
+
const cachedStatuses = addresses.map((address) => this.state.walletComplianceStatusMap[address]);
|
|
136
|
+
if (cachedStatuses.every(Boolean)) {
|
|
138
137
|
return cachedStatuses;
|
|
139
138
|
}
|
|
140
139
|
throw error;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComplianceController.mjs","sourceRoot":"","sources":["../src/ComplianceController.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAS3D,OAAO,EAAE,yBAAyB,EAAE,oBAAgB;AAEpD,kBAAkB;AAElB;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,sBAAsB,CAAC;AAqBrD;;GAEG;AACH,MAAM,4BAA4B,GAAG;IACnC,yBAAyB,EAAE;QACzB,sBAAsB,EAAE,KAAK;QAC7B,kBAAkB,EAAE,KAAK;QACzB,OAAO,EAAE,IAAI;QACb,QAAQ,EAAE,IAAI;KACf;IACD,aAAa,EAAE;QACb,sBAAsB,EAAE,KAAK;QAC7B,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,QAAQ,EAAE,KAAK;KAChB;CACiD,CAAC;AAErD;;;;;;;G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ACF,CAAC;YACF,IACE,cAAc,CAAC,KAAK,CAAC,CAAC,MAAM,EAAoC,EAAE,CAChE,OAAO,CAAC,MAAM,CAAC,CAChB,EACD,CAAC;gBACD,OAAO,cAAc,CAAC;YACxB,CAAC;YACD,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;IAED;;OAEG;IACH,oBAAoB;QAClB,IAAI,CAAC,MAAM,CAAC,CAAC,UAAU,EAAE,EAAE;YACzB,UAAU,CAAC,yBAAyB,GAAG,EAAE,CAAC;YAC1C,UAAU,CAAC,aAAa,GAAG,IAAI,CAAC;QAClC,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\n\nimport type { ComplianceControllerMethodActions } from './ComplianceController-method-action-types';\nimport type {\n ComplianceServiceCheckWalletComplianceAction,\n ComplianceServiceCheckWalletsComplianceAction,\n} from './ComplianceService-method-action-types';\nimport type { WalletComplianceStatus } from './types';\nimport { getWalletComplianceStatus } from './utils';\n\n// === GENERAL ===\n\n/**\n * The name of the {@link ComplianceController}, used to namespace the\n * controller's actions and events and to namespace the controller's state data\n * when composed with other controllers.\n */\nexport const controllerName = 'ComplianceController';\n\n// === STATE ===\n\n/**\n * Describes the shape of the state object for {@link ComplianceController}.\n */\nexport type ComplianceControllerState = {\n /**\n * A map of wallet addresses to their compliance check results, used as a\n * fallback cache when the API is unavailable.\n */\n walletComplianceStatusMap: Record<string, WalletComplianceStatus>;\n\n /**\n * The date/time (in ISO-8601 format) when the last compliance check was\n * performed, or `null` if no checks have been performed yet.\n */\n lastCheckedAt: string | null;\n};\n\n/**\n * The metadata for each property in {@link ComplianceControllerState}.\n */\nconst complianceControllerMetadata = {\n walletComplianceStatusMap: {\n includeInDebugSnapshot: false,\n includeInStateLogs: false,\n persist: true,\n usedInUi: true,\n },\n lastCheckedAt: {\n includeInDebugSnapshot: false,\n includeInStateLogs: true,\n persist: true,\n usedInUi: false,\n },\n} satisfies StateMetadata<ComplianceControllerState>;\n\n/**\n * Constructs the default {@link ComplianceController} state. This allows\n * consumers to provide a partial state object when initializing the controller\n * and also helps in constructing complete state objects for this controller in\n * tests.\n *\n * @returns The default {@link ComplianceController} state.\n */\nexport function getDefaultComplianceControllerState(): ComplianceControllerState {\n return {\n walletComplianceStatusMap: {},\n lastCheckedAt: null,\n };\n}\n\n// === MESSENGER ===\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'checkWalletCompliance',\n 'checkWalletsCompliance',\n 'clearComplianceState',\n] as const;\n\n/**\n * Retrieves the state of the {@link ComplianceController}.\n */\nexport type ComplianceControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n ComplianceControllerState\n>;\n\n/**\n * Actions that {@link ComplianceController} exposes to other consumers.\n */\nexport type ComplianceControllerActions =\n | ComplianceControllerGetStateAction\n | ComplianceControllerMethodActions;\n\n/**\n * Actions from other messengers that {@link ComplianceController} calls.\n */\ntype AllowedActions =\n | ComplianceServiceCheckWalletComplianceAction\n | ComplianceServiceCheckWalletsComplianceAction;\n\n/**\n * Published when the state of {@link ComplianceController} changes.\n */\nexport type ComplianceControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n ComplianceControllerState\n>;\n\n/**\n * Events that {@link ComplianceController} exposes to other consumers.\n */\nexport type ComplianceControllerEvents = ComplianceControllerStateChangeEvent;\n\n/**\n * Events from other messengers that {@link ComplianceController} subscribes to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger restricted to actions and events accessed by\n * {@link ComplianceController}.\n */\nexport type ComplianceControllerMessenger = Messenger<\n typeof controllerName,\n ComplianceControllerActions | AllowedActions,\n ComplianceControllerEvents | AllowedEvents\n>;\n\n// === CONTROLLER DEFINITION ===\n\n/**\n * `ComplianceController` manages OFAC compliance state for wallet addresses.\n * It performs on-demand compliance checks via the API and caches results\n * per address in state. Cached results serve as a fallback if the API is\n * unavailable for a subsequent check on the same address.\n */\nexport class ComplianceController extends BaseController<\n typeof controllerName,\n ComplianceControllerState,\n ComplianceControllerMessenger\n> {\n /**\n * Constructs a new {@link ComplianceController}.\n *\n * @param args - The constructor arguments.\n * @param args.messenger - The messenger suited for this controller.\n * @param args.state - The desired state with which to init this\n * controller. Missing properties will be filled in with defaults.\n */\n constructor({\n messenger,\n state,\n }: {\n messenger: ComplianceControllerMessenger;\n state?: Partial<ComplianceControllerState>;\n }) {\n super({\n messenger,\n metadata: complianceControllerMetadata,\n name: controllerName,\n state: {\n ...getDefaultComplianceControllerState(),\n ...state,\n },\n });\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Checks compliance status for a single wallet address via the API and\n * persists the result to state. If the API call fails and a previously\n * cached result exists for the address, the cached result is returned as a\n * fallback. If no cached result exists, the error is re-thrown.\n *\n * @param address - The wallet address to check.\n * @returns The compliance status of the wallet.\n */\n async checkWalletCompliance(\n address: string,\n ): Promise<WalletComplianceStatus> {\n try {\n const result = await this.messenger.call(\n 'ComplianceService:checkWalletCompliance',\n address,\n );\n\n const now = new Date().toISOString();\n const status: WalletComplianceStatus = {\n address: result.address,\n blocked: result.blocked,\n checkedAt: now,\n };\n\n this.update((draftState) => {\n draftState.walletComplianceStatusMap[address] = status;\n draftState.lastCheckedAt = now;\n });\n\n return status;\n } catch (error) {\n const cached = getWalletComplianceStatus(\n this.state.walletComplianceStatusMap,\n address,\n );\n if (cached) {\n return cached;\n }\n throw error;\n }\n }\n\n /**\n * Checks compliance status for multiple wallet addresses via the API and\n * persists the results to state. If the API call fails and every requested\n * address has a previously cached result, those cached results are returned\n * as a fallback. If any address lacks a cached result, the error is\n * re-thrown.\n *\n * @param addresses - The wallet addresses to check.\n * @returns The compliance statuses of the wallets.\n */\n async checkWalletsCompliance(\n addresses: string[],\n ): Promise<WalletComplianceStatus[]> {\n try {\n const results = await this.messenger.call(\n 'ComplianceService:checkWalletsCompliance',\n addresses,\n );\n\n const now = new Date().toISOString();\n const statuses: WalletComplianceStatus[] = results.map((result) => ({\n address: result.address,\n blocked: result.blocked,\n checkedAt: now,\n }));\n\n this.update((draftState) => {\n for (let idx = 0; idx < statuses.length; idx++) {\n const callerAddress = addresses[idx];\n draftState.walletComplianceStatusMap[callerAddress] = statuses[idx];\n }\n draftState.lastCheckedAt = now;\n });\n\n return statuses;\n } catch (error) {\n const cachedStatuses = addresses.map((address) =>\n getWalletComplianceStatus(\n this.state.walletComplianceStatusMap,\n address,\n ),\n );\n if (\n cachedStatuses.every((status): status is WalletComplianceStatus =>\n Boolean(status),\n )\n ) {\n return cachedStatuses;\n }\n throw error;\n }\n }\n\n /**\n * Clears all compliance data from state.\n */\n clearComplianceState(): void {\n this.update((draftState) => {\n draftState.walletComplianceStatusMap = {};\n draftState.lastCheckedAt = null;\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ComplianceController.mjs","sourceRoot":"","sources":["../src/ComplianceController.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAU3D,kBAAkB;AAElB;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,sBAAsB,CAAC;AAqBrD;;GAEG;AACH,MAAM,4BAA4B,GAAG;IACnC,yBAAyB,EAAE;QACzB,sBAAsB,EAAE,KAAK;QAC7B,kBAAkB,EAAE,KAAK;QACzB,OAAO,EAAE,IAAI;QACb,QAAQ,EAAE,IAAI;KACf;IACD,aAAa,EAAE;QACb,sBAAsB,EAAE,KAAK;QAC7B,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,QAAQ,EAAE,KAAK;KAChB;CACiD,CAAC;AAErD;;;;;;;GAOG;AACH,MAAM,UAAU,mCAAmC;IACjD,OAAO;QACL,yBAAyB,EAAE,EAAE;QAC7B,aAAa,EAAE,IAAI;KACpB,CAAC;AACJ,CAAC;AAED,oBAAoB;AAEpB,MA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IACH,oBAAoB;QAClB,IAAI,CAAC,MAAM,CAAC,CAAC,UAAU,EAAE,EAAE;YACzB,UAAU,CAAC,yBAAyB,GAAG,EAAE,CAAC;YAC1C,UAAU,CAAC,aAAa,GAAG,IAAI,CAAC;QAClC,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\n\nimport type { ComplianceControllerMethodActions } from './ComplianceController-method-action-types';\nimport type {\n ComplianceServiceCheckWalletComplianceAction,\n ComplianceServiceCheckWalletsComplianceAction,\n} from './ComplianceService-method-action-types';\nimport type { WalletComplianceStatus } from './types';\n\n// === GENERAL ===\n\n/**\n * The name of the {@link ComplianceController}, used to namespace the\n * controller's actions and events and to namespace the controller's state data\n * when composed with other controllers.\n */\nexport const controllerName = 'ComplianceController';\n\n// === STATE ===\n\n/**\n * Describes the shape of the state object for {@link ComplianceController}.\n */\nexport type ComplianceControllerState = {\n /**\n * A map of wallet addresses to their compliance check results, used as a\n * fallback cache when the API is unavailable.\n */\n walletComplianceStatusMap: Record<string, WalletComplianceStatus>;\n\n /**\n * The date/time (in ISO-8601 format) when the last compliance check was\n * performed, or `null` if no checks have been performed yet.\n */\n lastCheckedAt: string | null;\n};\n\n/**\n * The metadata for each property in {@link ComplianceControllerState}.\n */\nconst complianceControllerMetadata = {\n walletComplianceStatusMap: {\n includeInDebugSnapshot: false,\n includeInStateLogs: false,\n persist: true,\n usedInUi: true,\n },\n lastCheckedAt: {\n includeInDebugSnapshot: false,\n includeInStateLogs: true,\n persist: true,\n usedInUi: false,\n },\n} satisfies StateMetadata<ComplianceControllerState>;\n\n/**\n * Constructs the default {@link ComplianceController} state. This allows\n * consumers to provide a partial state object when initializing the controller\n * and also helps in constructing complete state objects for this controller in\n * tests.\n *\n * @returns The default {@link ComplianceController} state.\n */\nexport function getDefaultComplianceControllerState(): ComplianceControllerState {\n return {\n walletComplianceStatusMap: {},\n lastCheckedAt: null,\n };\n}\n\n// === MESSENGER ===\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'checkWalletCompliance',\n 'checkWalletsCompliance',\n 'clearComplianceState',\n] as const;\n\n/**\n * Retrieves the state of the {@link ComplianceController}.\n */\nexport type ComplianceControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n ComplianceControllerState\n>;\n\n/**\n * Actions that {@link ComplianceController} exposes to other consumers.\n */\nexport type ComplianceControllerActions =\n | ComplianceControllerGetStateAction\n | ComplianceControllerMethodActions;\n\n/**\n * Actions from other messengers that {@link ComplianceController} calls.\n */\ntype AllowedActions =\n | ComplianceServiceCheckWalletComplianceAction\n | ComplianceServiceCheckWalletsComplianceAction;\n\n/**\n * Published when the state of {@link ComplianceController} changes.\n */\nexport type ComplianceControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n ComplianceControllerState\n>;\n\n/**\n * Events that {@link ComplianceController} exposes to other consumers.\n */\nexport type ComplianceControllerEvents = ComplianceControllerStateChangeEvent;\n\n/**\n * Events from other messengers that {@link ComplianceController} subscribes to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger restricted to actions and events accessed by\n * {@link ComplianceController}.\n */\nexport type ComplianceControllerMessenger = Messenger<\n typeof controllerName,\n ComplianceControllerActions | AllowedActions,\n ComplianceControllerEvents | AllowedEvents\n>;\n\n// === CONTROLLER DEFINITION ===\n\n/**\n * `ComplianceController` manages OFAC compliance state for wallet addresses.\n * It performs on-demand compliance checks via the API and caches results\n * per address in state. Cached results serve as a fallback if the API is\n * unavailable for a subsequent check on the same address.\n */\nexport class ComplianceController extends BaseController<\n typeof controllerName,\n ComplianceControllerState,\n ComplianceControllerMessenger\n> {\n /**\n * Constructs a new {@link ComplianceController}.\n *\n * @param args - The constructor arguments.\n * @param args.messenger - The messenger suited for this controller.\n * @param args.state - The desired state with which to init this\n * controller. Missing properties will be filled in with defaults.\n */\n constructor({\n messenger,\n state,\n }: {\n messenger: ComplianceControllerMessenger;\n state?: Partial<ComplianceControllerState>;\n }) {\n super({\n messenger,\n metadata: complianceControllerMetadata,\n name: controllerName,\n state: {\n ...getDefaultComplianceControllerState(),\n ...state,\n },\n });\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Checks compliance status for a single wallet address via the API and\n * persists the result to state. If the API call fails and a previously\n * cached result exists for the address, the cached result is returned as a\n * fallback. If no cached result exists, the error is re-thrown.\n *\n * @param address - The wallet address to check.\n * @returns The compliance status of the wallet.\n */\n async checkWalletCompliance(\n address: string,\n ): Promise<WalletComplianceStatus> {\n try {\n const result = await this.messenger.call(\n 'ComplianceService:checkWalletCompliance',\n address,\n );\n\n const now = new Date().toISOString();\n const status: WalletComplianceStatus = {\n address: result.address,\n blocked: result.blocked,\n checkedAt: now,\n };\n\n this.update((draftState) => {\n draftState.walletComplianceStatusMap[address] = status;\n draftState.lastCheckedAt = now;\n });\n\n return status;\n } catch (error) {\n const cached = this.state.walletComplianceStatusMap[address];\n if (cached) {\n return cached;\n }\n throw error;\n }\n }\n\n /**\n * Checks compliance status for multiple wallet addresses via the API and\n * persists the results to state. If the API call fails and every requested\n * address has a previously cached result, those cached results are returned\n * as a fallback. If any address lacks a cached result, the error is\n * re-thrown.\n *\n * @param addresses - The wallet addresses to check.\n * @returns The compliance statuses of the wallets.\n */\n async checkWalletsCompliance(\n addresses: string[],\n ): Promise<WalletComplianceStatus[]> {\n try {\n const results = await this.messenger.call(\n 'ComplianceService:checkWalletsCompliance',\n addresses,\n );\n\n const now = new Date().toISOString();\n const statuses: WalletComplianceStatus[] = results.map((result) => ({\n address: result.address,\n blocked: result.blocked,\n checkedAt: now,\n }));\n\n this.update((draftState) => {\n for (let idx = 0; idx < statuses.length; idx++) {\n const callerAddress = addresses[idx];\n draftState.walletComplianceStatusMap[callerAddress] = statuses[idx];\n }\n draftState.lastCheckedAt = now;\n });\n\n return statuses;\n } catch (error) {\n const cachedStatuses = addresses.map(\n (address) => this.state.walletComplianceStatusMap[address],\n );\n if (cachedStatuses.every(Boolean)) {\n return cachedStatuses;\n }\n throw error;\n }\n }\n\n /**\n * Clears all compliance data from state.\n */\n clearComplianceState(): void {\n this.update((draftState) => {\n draftState.walletComplianceStatusMap = {};\n draftState.lastCheckedAt = null;\n });\n }\n}\n"]}
|
|
@@ -75,7 +75,7 @@ const BatchWalletCheckResponseItemStruct = WalletCheckResponseStruct;
|
|
|
75
75
|
* new ComplianceService({
|
|
76
76
|
* messenger: serviceMessenger,
|
|
77
77
|
* fetch,
|
|
78
|
-
*
|
|
78
|
+
* env: 'production',
|
|
79
79
|
* });
|
|
80
80
|
*
|
|
81
81
|
* // Check a single wallet
|
|
@@ -93,13 +93,12 @@ class ComplianceService {
|
|
|
93
93
|
* @param args - The constructor arguments.
|
|
94
94
|
* @param args.messenger - The messenger suited for this service.
|
|
95
95
|
* @param args.fetch - A function that can be used to make an HTTP request.
|
|
96
|
-
* @param args.
|
|
97
|
-
*
|
|
98
|
-
* when `apiUrl` is not provided.
|
|
96
|
+
* @param args.env - The environment to use for the Compliance API. Determines
|
|
97
|
+
* the base URL.
|
|
99
98
|
* @param args.policyOptions - Options to pass to `createServicePolicy`, which
|
|
100
99
|
* is used to wrap each request. See {@link CreateServicePolicyOptions}.
|
|
101
100
|
*/
|
|
102
|
-
constructor({ messenger, fetch: fetchFunction,
|
|
101
|
+
constructor({ messenger, fetch: fetchFunction, env, policyOptions = {}, }) {
|
|
103
102
|
/**
|
|
104
103
|
* The messenger suited for this service.
|
|
105
104
|
*/
|
|
@@ -121,7 +120,7 @@ class ComplianceService {
|
|
|
121
120
|
this.name = exports.serviceName;
|
|
122
121
|
__classPrivateFieldSet(this, _ComplianceService_messenger, messenger, "f");
|
|
123
122
|
__classPrivateFieldSet(this, _ComplianceService_fetch, fetchFunction, "f");
|
|
124
|
-
__classPrivateFieldSet(this, _ComplianceService_complianceApiUrl,
|
|
123
|
+
__classPrivateFieldSet(this, _ComplianceService_complianceApiUrl, COMPLIANCE_API_URLS[env], "f");
|
|
125
124
|
__classPrivateFieldSet(this, _ComplianceService_policy, (0, controller_utils_1.createServicePolicy)(policyOptions), "f");
|
|
126
125
|
__classPrivateFieldGet(this, _ComplianceService_messenger, "f").registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
127
126
|
}
|
|
@@ -166,7 +165,7 @@ class ComplianceService {
|
|
|
166
165
|
*/
|
|
167
166
|
async checkWalletCompliance(address) {
|
|
168
167
|
const response = await __classPrivateFieldGet(this, _ComplianceService_policy, "f").execute(async () => {
|
|
169
|
-
const url = new URL(
|
|
168
|
+
const url = new URL(`/v1/wallet/${encodeURIComponent(address)}`, __classPrivateFieldGet(this, _ComplianceService_complianceApiUrl, "f"));
|
|
170
169
|
const localResponse = await __classPrivateFieldGet(this, _ComplianceService_fetch, "f").call(this, url);
|
|
171
170
|
if (!localResponse.ok) {
|
|
172
171
|
throw new controller_utils_1.HttpError(localResponse.status, `Fetching '${url.toString()}' failed with status '${localResponse.status}'`);
|
|
@@ -184,7 +183,7 @@ class ComplianceService {
|
|
|
184
183
|
*/
|
|
185
184
|
async checkWalletsCompliance(addresses) {
|
|
186
185
|
const response = await __classPrivateFieldGet(this, _ComplianceService_policy, "f").execute(async () => {
|
|
187
|
-
const url = new URL('v1/wallet/batch', __classPrivateFieldGet(this, _ComplianceService_complianceApiUrl, "f"));
|
|
186
|
+
const url = new URL('/v1/wallet/batch', __classPrivateFieldGet(this, _ComplianceService_complianceApiUrl, "f"));
|
|
188
187
|
const localResponse = await __classPrivateFieldGet(this, _ComplianceService_fetch, "f").call(this, url, {
|
|
189
188
|
method: 'POST',
|
|
190
189
|
headers: { 'Content-Type': 'application/json' },
|
|
@@ -201,25 +200,6 @@ class ComplianceService {
|
|
|
201
200
|
}
|
|
202
201
|
exports.ComplianceService = ComplianceService;
|
|
203
202
|
_a = ComplianceService, _ComplianceService_messenger = new WeakMap(), _ComplianceService_fetch = new WeakMap(), _ComplianceService_complianceApiUrl = new WeakMap(), _ComplianceService_policy = new WeakMap();
|
|
204
|
-
function getComplianceApiUrl({ apiUrl, env, }) {
|
|
205
|
-
if (apiUrl === undefined) {
|
|
206
|
-
return COMPLIANCE_API_URLS[env];
|
|
207
|
-
}
|
|
208
|
-
let url;
|
|
209
|
-
try {
|
|
210
|
-
url = new URL(apiUrl);
|
|
211
|
-
}
|
|
212
|
-
catch {
|
|
213
|
-
throw new Error(`Invalid Compliance API URL: ${apiUrl}`);
|
|
214
|
-
}
|
|
215
|
-
if (url.search || url.hash) {
|
|
216
|
-
throw new Error(`Invalid Compliance API URL: ${apiUrl}. Query strings and fragments are not supported.`);
|
|
217
|
-
}
|
|
218
|
-
if (!url.pathname.endsWith('/')) {
|
|
219
|
-
url.pathname = `${url.pathname}/`;
|
|
220
|
-
}
|
|
221
|
-
return url.href;
|
|
222
|
-
}
|
|
223
203
|
/**
|
|
224
204
|
* Validates an API response against a superstruct schema.
|
|
225
205
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComplianceService.cjs","sourceRoot":"","sources":["../src/ComplianceService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAIA,iEAA4E;AAG5E,uDAAuE;AAKvE,kBAAkB;AAElB;;;GAGG;AACU,QAAA,WAAW,GAAG,mBAAmB,CAAC;AAO/C,MAAM,mBAAmB,GAAiD;IACxE,UAAU,EAAE,uCAAuC;IACnD,WAAW,EAAE,2CAA2C;CACzD,CAAC;AAkBF,oBAAoB;AAEpB,MAAM,yBAAyB,GAAG;IAChC,uBAAuB;IACvB,wBAAwB;CAChB,CAAC;AAgCX,+BAA+B;AAE/B;;GAEG;AACH,MAAM,yBAAyB,GAAG,IAAA,oBAAM,EAAC;IACvC,OAAO,EAAE,IAAA,oBAAM,GAAE;IACjB,OAAO,EAAE,IAAA,qBAAO,GAAE;CACnB,CAAC,CAAC;AAOH;;;GAGG;AACH,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oC,OAAO,EAAE,CAAC,CAAC;AACjE,CAAC","sourcesContent":["import type {\n CreateServicePolicyOptions,\n ServicePolicy,\n} from '@metamask/controller-utils';\nimport { createServicePolicy, HttpError } from '@metamask/controller-utils';\nimport type { Messenger } from '@metamask/messenger';\nimport type { Infer } from '@metamask/superstruct';\nimport { array, boolean, object, string } from '@metamask/superstruct';\nimport type { IDisposable } from 'cockatiel';\n\nimport type { ComplianceServiceMethodActions } from './ComplianceService-method-action-types';\n\n// === GENERAL ===\n\n/**\n * The name of the {@link ComplianceService}, used to namespace the service's\n * actions and events.\n */\nexport const serviceName = 'ComplianceService';\n\n/**\n * The supported environments for the Compliance API.\n */\nexport type ComplianceServiceEnvironment = 'production' | 'development';\n\nconst COMPLIANCE_API_URLS: Record<ComplianceServiceEnvironment, string> = {\n production: 'https://compliance.api.cx.metamask.io',\n development: 'https://compliance.dev-api.cx.metamask.io',\n};\n\nexport type ComplianceServiceOptions = {\n messenger: ComplianceServiceMessenger;\n fetch: typeof fetch;\n /**\n * Explicit Compliance API URL. Prefer this for application builds so API\n * endpoints can be managed by build configuration. Path components are\n * preserved as a base path for Compliance API routes.\n */\n apiUrl?: string;\n /**\n * Fallback environment used when `apiUrl` is not provided.\n */\n env?: ComplianceServiceEnvironment;\n policyOptions?: CreateServicePolicyOptions;\n};\n\n// === MESSENGER ===\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'checkWalletCompliance',\n 'checkWalletsCompliance',\n] as const;\n\n/**\n * Actions that {@link ComplianceService} exposes to other consumers.\n */\nexport type ComplianceServiceActions = ComplianceServiceMethodActions;\n\n/**\n * Actions from other messengers that {@link ComplianceService} calls.\n */\ntype AllowedActions = never;\n\n/**\n * Events that {@link ComplianceService} exposes to other consumers.\n */\nexport type ComplianceServiceEvents = never;\n\n/**\n * Events from other messengers that {@link ComplianceService} subscribes to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger restricted to actions and events accessed by\n * {@link ComplianceService}.\n */\nexport type ComplianceServiceMessenger = Messenger<\n typeof serviceName,\n ComplianceServiceActions | AllowedActions,\n ComplianceServiceEvents | AllowedEvents\n>;\n\n// === API RESPONSE SCHEMAS ===\n\n/**\n * Schema for the response from `GET /v1/wallet/:address`.\n */\nconst WalletCheckResponseStruct = object({\n address: string(),\n blocked: boolean(),\n});\n\n/**\n * The validated shape of a single wallet compliance check response.\n */\ntype WalletCheckResponse = Infer<typeof WalletCheckResponseStruct>;\n\n/**\n * Schema for each item in the response from `POST /v1/wallet/batch`.\n * Reuses the same shape as a single wallet check.\n */\nconst BatchWalletCheckResponseItemStruct = WalletCheckResponseStruct;\n\n/**\n * The validated shape of a single item in a batch compliance check response.\n */\ntype BatchWalletCheckResponseItem = Infer<\n typeof BatchWalletCheckResponseItemStruct\n>;\n\n// === SERVICE DEFINITION ===\n\n/**\n * `ComplianceService` communicates with the Compliance API to check whether\n * wallet addresses are sanctioned under OFAC regulations.\n *\n * @example\n *\n * ``` ts\n * import { Messenger } from '@metamask/messenger';\n * import type {\n * ComplianceServiceActions,\n * ComplianceServiceEvents,\n * } from '@metamask/compliance-controller';\n * import { ComplianceService } from '@metamask/compliance-controller';\n *\n * const rootMessenger = new Messenger<\n * 'Root',\n * ComplianceServiceActions,\n * ComplianceServiceEvents,\n * >({ namespace: 'Root' });\n * const serviceMessenger = new Messenger<\n * 'ComplianceService',\n * ComplianceServiceActions,\n * ComplianceServiceEvents,\n * typeof rootMessenger,\n * >({\n * namespace: 'ComplianceService',\n * parent: rootMessenger,\n * });\n * new ComplianceService({\n * messenger: serviceMessenger,\n * fetch,\n * apiUrl: 'https://compliance.api.cx.metamask.io',\n * });\n *\n * // Check a single wallet\n * const result = await rootMessenger.call(\n * 'ComplianceService:checkWalletCompliance',\n * '0x1234...',\n * );\n * // => { address: '0x1234...', blocked: false }\n * ```\n */\nexport class ComplianceService {\n /**\n * The name of the service.\n */\n readonly name: typeof serviceName;\n\n /**\n * The messenger suited for this service.\n */\n readonly #messenger: ConstructorParameters<\n typeof ComplianceService\n >[0]['messenger'];\n\n /**\n * A function that can be used to make an HTTP request.\n */\n readonly #fetch: ConstructorParameters<typeof ComplianceService>[0]['fetch'];\n\n /**\n * The resolved base URL for the Compliance API.\n */\n readonly #complianceApiUrl: string;\n\n /**\n * The policy that wraps each request.\n *\n * @see {@link createServicePolicy}\n */\n readonly #policy: ServicePolicy;\n\n /**\n * Constructs a new ComplianceService object.\n *\n * @param args - The constructor arguments.\n * @param args.messenger - The messenger suited for this service.\n * @param args.fetch - A function that can be used to make an HTTP request.\n * @param args.apiUrl - The explicit Compliance API URL.\n * @param args.env - The fallback environment to use for the Compliance API\n * when `apiUrl` is not provided.\n * @param args.policyOptions - Options to pass to `createServicePolicy`, which\n * is used to wrap each request. See {@link CreateServicePolicyOptions}.\n */\n constructor({\n messenger,\n fetch: fetchFunction,\n apiUrl,\n env = 'production',\n policyOptions = {},\n }: ComplianceServiceOptions) {\n this.name = serviceName;\n this.#messenger = messenger;\n this.#fetch = fetchFunction;\n this.#complianceApiUrl = getComplianceApiUrl({ apiUrl, env });\n this.#policy = createServicePolicy(policyOptions);\n\n this.#messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Registers a handler that will be called after a request returns a non-500\n * response, causing a retry.\n *\n * @param listener - The handler to be called.\n * @returns An object that can be used to unregister the handler.\n * @see {@link createServicePolicy}\n */\n onRetry(listener: Parameters<ServicePolicy['onRetry']>[0]): IDisposable {\n return this.#policy.onRetry(listener);\n }\n\n /**\n * Registers a handler that will be called after a set number of retry rounds\n * prove that requests to the API endpoint consistently return a 5xx response.\n *\n * @param listener - The handler to be called.\n * @returns An object that can be used to unregister the handler.\n * @see {@link createServicePolicy}\n */\n onBreak(listener: Parameters<ServicePolicy['onBreak']>[0]): IDisposable {\n return this.#policy.onBreak(listener);\n }\n\n /**\n * Registers a handler that will be called when the service is degraded due\n * to slow responses or repeated failures.\n *\n * @param listener - The handler to be called.\n * @returns An object that can be used to unregister the handler.\n * @see {@link createServicePolicy}\n */\n onDegraded(\n listener: Parameters<ServicePolicy['onDegraded']>[0],\n ): IDisposable {\n return this.#policy.onDegraded(listener);\n }\n\n /**\n * Checks compliance status for a single wallet address.\n *\n * @param address - The wallet address to check.\n * @returns The compliance status of the wallet.\n */\n async checkWalletCompliance(address: string): Promise<WalletCheckResponse> {\n const response = await this.#policy.execute(async () => {\n const url = new URL(\n `v1/wallet/${encodeURIComponent(address)}`,\n this.#complianceApiUrl,\n );\n const localResponse = await this.#fetch(url);\n if (!localResponse.ok) {\n throw new HttpError(\n localResponse.status,\n `Fetching '${url.toString()}' failed with status '${localResponse.status}'`,\n );\n }\n return localResponse;\n });\n const jsonResponse: unknown = await response.json();\n\n return validateResponse(\n jsonResponse,\n WalletCheckResponseStruct,\n 'compliance wallet check API',\n );\n }\n\n /**\n * Checks compliance status for multiple wallet addresses in a single request.\n *\n * @param addresses - The wallet addresses to check.\n * @returns The compliance statuses of the wallets.\n */\n async checkWalletsCompliance(\n addresses: string[],\n ): Promise<BatchWalletCheckResponseItem[]> {\n const response = await this.#policy.execute(async () => {\n const url = new URL('v1/wallet/batch', this.#complianceApiUrl);\n const localResponse = await this.#fetch(url, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify(addresses),\n });\n if (!localResponse.ok) {\n throw new HttpError(\n localResponse.status,\n `Fetching '${url.toString()}' failed with status '${localResponse.status}'`,\n );\n }\n return localResponse;\n });\n const jsonResponse: unknown = await response.json();\n\n return validateResponse(\n jsonResponse,\n array(BatchWalletCheckResponseItemStruct),\n 'compliance batch check API',\n );\n }\n}\n\nfunction getComplianceApiUrl({\n apiUrl,\n env,\n}: {\n apiUrl?: string;\n env: ComplianceServiceEnvironment;\n}): string {\n if (apiUrl === undefined) {\n return COMPLIANCE_API_URLS[env];\n }\n\n let url: URL;\n try {\n url = new URL(apiUrl);\n } catch {\n throw new Error(`Invalid Compliance API URL: ${apiUrl}`);\n }\n\n if (url.search || url.hash) {\n throw new Error(\n `Invalid Compliance API URL: ${apiUrl}. Query strings and fragments are not supported.`,\n );\n }\n if (!url.pathname.endsWith('/')) {\n url.pathname = `${url.pathname}/`;\n }\n return url.href;\n}\n\n/**\n * Validates an API response against a superstruct schema.\n *\n * @param data - The raw response data to validate.\n * @param struct - The superstruct schema to validate against.\n * @param struct.is - The type guard function from the schema.\n * @param apiName - A human-readable name for the API, used in error messages.\n * @returns The validated data.\n * @throws If the data does not match the schema.\n */\nfunction validateResponse<Response>(\n data: unknown,\n struct: { is: (value: unknown) => value is Response },\n apiName: string,\n): Response {\n if (struct.is(data)) {\n return data;\n }\n throw new Error(`Malformed response received from ${apiName}`);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ComplianceService.cjs","sourceRoot":"","sources":["../src/ComplianceService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAIA,iEAA4E;AAG5E,uDAAuE;AAKvE,kBAAkB;AAElB;;;GAGG;AACU,QAAA,WAAW,GAAG,mBAAmB,CAAC;AAO/C,MAAM,mBAAmB,GAAiD;IACxE,UAAU,EAAE,uCAAuC;IACnD,WAAW,EAAE,2CAA2C;CACzD,CAAC;AAEF,oBAAoB;AAEpB,MAAM,yBAAyB,GAAG;IAChC,uBAAuB;IACvB,wBAAwB;CAChB,CAAC;AAgCX,+BAA+B;AAE/B;;GAEG;AACH,MAAM,yBAAyB,GAAG,IAAA,oBAAM,EAAC;IACvC,OAAO,EAAE,IAAA,oBAAM,GAAE;IACjB,OAAO,EAAE,IAAA,qBAAO,GAAE;CACnB,CAAC,CAAC;AAOH;;;GAGG;AACH,MAAM,kCAAkC,GAAG,yBAAyB,CAAC;AASrE,6BAA6B;AAE7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,MAAa,iBAAiB;IA8B5B;;;;;;;;;;OAUG;IACH,YAAY,EACV,SAAS,EACT,KAAK,EAAE,aAAa,EACpB,GAAG,EACH,aAAa,GAAG,EAAE,GAMnB;QA7CD;;W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C;CACF;AApKD,8CAoKC;;AAED;;;;;;;;;GASG;AACH,SAAS,gBAAgB,CACvB,IAAa,EACb,MAAqD,EACrD,OAAe;IAEf,IAAI,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QACpB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,oCAAoC,OAAO,EAAE,CAAC,CAAC;AACjE,CAAC","sourcesContent":["import type {\n CreateServicePolicyOptions,\n ServicePolicy,\n} from '@metamask/controller-utils';\nimport { createServicePolicy, HttpError } from '@metamask/controller-utils';\nimport type { Messenger } from '@metamask/messenger';\nimport type { Infer } from '@metamask/superstruct';\nimport { array, boolean, object, string } from '@metamask/superstruct';\nimport type { IDisposable } from 'cockatiel';\n\nimport type { ComplianceServiceMethodActions } from './ComplianceService-method-action-types';\n\n// === GENERAL ===\n\n/**\n * The name of the {@link ComplianceService}, used to namespace the service's\n * actions and events.\n */\nexport const serviceName = 'ComplianceService';\n\n/**\n * The supported environments for the Compliance API.\n */\nexport type ComplianceServiceEnvironment = 'production' | 'development';\n\nconst COMPLIANCE_API_URLS: Record<ComplianceServiceEnvironment, string> = {\n production: 'https://compliance.api.cx.metamask.io',\n development: 'https://compliance.dev-api.cx.metamask.io',\n};\n\n// === MESSENGER ===\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'checkWalletCompliance',\n 'checkWalletsCompliance',\n] as const;\n\n/**\n * Actions that {@link ComplianceService} exposes to other consumers.\n */\nexport type ComplianceServiceActions = ComplianceServiceMethodActions;\n\n/**\n * Actions from other messengers that {@link ComplianceService} calls.\n */\ntype AllowedActions = never;\n\n/**\n * Events that {@link ComplianceService} exposes to other consumers.\n */\nexport type ComplianceServiceEvents = never;\n\n/**\n * Events from other messengers that {@link ComplianceService} subscribes to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger restricted to actions and events accessed by\n * {@link ComplianceService}.\n */\nexport type ComplianceServiceMessenger = Messenger<\n typeof serviceName,\n ComplianceServiceActions | AllowedActions,\n ComplianceServiceEvents | AllowedEvents\n>;\n\n// === API RESPONSE SCHEMAS ===\n\n/**\n * Schema for the response from `GET /v1/wallet/:address`.\n */\nconst WalletCheckResponseStruct = object({\n address: string(),\n blocked: boolean(),\n});\n\n/**\n * The validated shape of a single wallet compliance check response.\n */\ntype WalletCheckResponse = Infer<typeof WalletCheckResponseStruct>;\n\n/**\n * Schema for each item in the response from `POST /v1/wallet/batch`.\n * Reuses the same shape as a single wallet check.\n */\nconst BatchWalletCheckResponseItemStruct = WalletCheckResponseStruct;\n\n/**\n * The validated shape of a single item in a batch compliance check response.\n */\ntype BatchWalletCheckResponseItem = Infer<\n typeof BatchWalletCheckResponseItemStruct\n>;\n\n// === SERVICE DEFINITION ===\n\n/**\n * `ComplianceService` communicates with the Compliance API to check whether\n * wallet addresses are sanctioned under OFAC regulations.\n *\n * @example\n *\n * ``` ts\n * import { Messenger } from '@metamask/messenger';\n * import type {\n * ComplianceServiceActions,\n * ComplianceServiceEvents,\n * } from '@metamask/compliance-controller';\n * import { ComplianceService } from '@metamask/compliance-controller';\n *\n * const rootMessenger = new Messenger<\n * 'Root',\n * ComplianceServiceActions,\n * ComplianceServiceEvents,\n * >({ namespace: 'Root' });\n * const serviceMessenger = new Messenger<\n * 'ComplianceService',\n * ComplianceServiceActions,\n * ComplianceServiceEvents,\n * typeof rootMessenger,\n * >({\n * namespace: 'ComplianceService',\n * parent: rootMessenger,\n * });\n * new ComplianceService({\n * messenger: serviceMessenger,\n * fetch,\n * env: 'production',\n * });\n *\n * // Check a single wallet\n * const result = await rootMessenger.call(\n * 'ComplianceService:checkWalletCompliance',\n * '0x1234...',\n * );\n * // => { address: '0x1234...', blocked: false }\n * ```\n */\nexport class ComplianceService {\n /**\n * The name of the service.\n */\n readonly name: typeof serviceName;\n\n /**\n * The messenger suited for this service.\n */\n readonly #messenger: ConstructorParameters<\n typeof ComplianceService\n >[0]['messenger'];\n\n /**\n * A function that can be used to make an HTTP request.\n */\n readonly #fetch: ConstructorParameters<typeof ComplianceService>[0]['fetch'];\n\n /**\n * The resolved base URL for the Compliance API.\n */\n readonly #complianceApiUrl: string;\n\n /**\n * The policy that wraps each request.\n *\n * @see {@link createServicePolicy}\n */\n readonly #policy: ServicePolicy;\n\n /**\n * Constructs a new ComplianceService object.\n *\n * @param args - The constructor arguments.\n * @param args.messenger - The messenger suited for this service.\n * @param args.fetch - A function that can be used to make an HTTP request.\n * @param args.env - The environment to use for the Compliance API. Determines\n * the base URL.\n * @param args.policyOptions - Options to pass to `createServicePolicy`, which\n * is used to wrap each request. See {@link CreateServicePolicyOptions}.\n */\n constructor({\n messenger,\n fetch: fetchFunction,\n env,\n policyOptions = {},\n }: {\n messenger: ComplianceServiceMessenger;\n fetch: typeof fetch;\n env: ComplianceServiceEnvironment;\n policyOptions?: CreateServicePolicyOptions;\n }) {\n this.name = serviceName;\n this.#messenger = messenger;\n this.#fetch = fetchFunction;\n this.#complianceApiUrl = COMPLIANCE_API_URLS[env];\n this.#policy = createServicePolicy(policyOptions);\n\n this.#messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Registers a handler that will be called after a request returns a non-500\n * response, causing a retry.\n *\n * @param listener - The handler to be called.\n * @returns An object that can be used to unregister the handler.\n * @see {@link createServicePolicy}\n */\n onRetry(listener: Parameters<ServicePolicy['onRetry']>[0]): IDisposable {\n return this.#policy.onRetry(listener);\n }\n\n /**\n * Registers a handler that will be called after a set number of retry rounds\n * prove that requests to the API endpoint consistently return a 5xx response.\n *\n * @param listener - The handler to be called.\n * @returns An object that can be used to unregister the handler.\n * @see {@link createServicePolicy}\n */\n onBreak(listener: Parameters<ServicePolicy['onBreak']>[0]): IDisposable {\n return this.#policy.onBreak(listener);\n }\n\n /**\n * Registers a handler that will be called when the service is degraded due\n * to slow responses or repeated failures.\n *\n * @param listener - The handler to be called.\n * @returns An object that can be used to unregister the handler.\n * @see {@link createServicePolicy}\n */\n onDegraded(\n listener: Parameters<ServicePolicy['onDegraded']>[0],\n ): IDisposable {\n return this.#policy.onDegraded(listener);\n }\n\n /**\n * Checks compliance status for a single wallet address.\n *\n * @param address - The wallet address to check.\n * @returns The compliance status of the wallet.\n */\n async checkWalletCompliance(address: string): Promise<WalletCheckResponse> {\n const response = await this.#policy.execute(async () => {\n const url = new URL(\n `/v1/wallet/${encodeURIComponent(address)}`,\n this.#complianceApiUrl,\n );\n const localResponse = await this.#fetch(url);\n if (!localResponse.ok) {\n throw new HttpError(\n localResponse.status,\n `Fetching '${url.toString()}' failed with status '${localResponse.status}'`,\n );\n }\n return localResponse;\n });\n const jsonResponse: unknown = await response.json();\n\n return validateResponse(\n jsonResponse,\n WalletCheckResponseStruct,\n 'compliance wallet check API',\n );\n }\n\n /**\n * Checks compliance status for multiple wallet addresses in a single request.\n *\n * @param addresses - The wallet addresses to check.\n * @returns The compliance statuses of the wallets.\n */\n async checkWalletsCompliance(\n addresses: string[],\n ): Promise<BatchWalletCheckResponseItem[]> {\n const response = await this.#policy.execute(async () => {\n const url = new URL('/v1/wallet/batch', this.#complianceApiUrl);\n const localResponse = await this.#fetch(url, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify(addresses),\n });\n if (!localResponse.ok) {\n throw new HttpError(\n localResponse.status,\n `Fetching '${url.toString()}' failed with status '${localResponse.status}'`,\n );\n }\n return localResponse;\n });\n const jsonResponse: unknown = await response.json();\n\n return validateResponse(\n jsonResponse,\n array(BatchWalletCheckResponseItemStruct),\n 'compliance batch check API',\n );\n }\n}\n\n/**\n * Validates an API response against a superstruct schema.\n *\n * @param data - The raw response data to validate.\n * @param struct - The superstruct schema to validate against.\n * @param struct.is - The type guard function from the schema.\n * @param apiName - A human-readable name for the API, used in error messages.\n * @returns The validated data.\n * @throws If the data does not match the schema.\n */\nfunction validateResponse<Response>(\n data: unknown,\n struct: { is: (value: unknown) => value is Response },\n apiName: string,\n): Response {\n if (struct.is(data)) {\n return data;\n }\n throw new Error(`Malformed response received from ${apiName}`);\n}\n"]}
|
|
@@ -12,21 +12,6 @@ export declare const serviceName = "ComplianceService";
|
|
|
12
12
|
* The supported environments for the Compliance API.
|
|
13
13
|
*/
|
|
14
14
|
export type ComplianceServiceEnvironment = 'production' | 'development';
|
|
15
|
-
export type ComplianceServiceOptions = {
|
|
16
|
-
messenger: ComplianceServiceMessenger;
|
|
17
|
-
fetch: typeof fetch;
|
|
18
|
-
/**
|
|
19
|
-
* Explicit Compliance API URL. Prefer this for application builds so API
|
|
20
|
-
* endpoints can be managed by build configuration. Path components are
|
|
21
|
-
* preserved as a base path for Compliance API routes.
|
|
22
|
-
*/
|
|
23
|
-
apiUrl?: string;
|
|
24
|
-
/**
|
|
25
|
-
* Fallback environment used when `apiUrl` is not provided.
|
|
26
|
-
*/
|
|
27
|
-
env?: ComplianceServiceEnvironment;
|
|
28
|
-
policyOptions?: CreateServicePolicyOptions;
|
|
29
|
-
};
|
|
30
15
|
/**
|
|
31
16
|
* Actions that {@link ComplianceService} exposes to other consumers.
|
|
32
17
|
*/
|
|
@@ -108,7 +93,7 @@ type BatchWalletCheckResponseItem = Infer<typeof BatchWalletCheckResponseItemStr
|
|
|
108
93
|
* new ComplianceService({
|
|
109
94
|
* messenger: serviceMessenger,
|
|
110
95
|
* fetch,
|
|
111
|
-
*
|
|
96
|
+
* env: 'production',
|
|
112
97
|
* });
|
|
113
98
|
*
|
|
114
99
|
* // Check a single wallet
|
|
@@ -131,13 +116,17 @@ export declare class ComplianceService {
|
|
|
131
116
|
* @param args - The constructor arguments.
|
|
132
117
|
* @param args.messenger - The messenger suited for this service.
|
|
133
118
|
* @param args.fetch - A function that can be used to make an HTTP request.
|
|
134
|
-
* @param args.
|
|
135
|
-
*
|
|
136
|
-
* when `apiUrl` is not provided.
|
|
119
|
+
* @param args.env - The environment to use for the Compliance API. Determines
|
|
120
|
+
* the base URL.
|
|
137
121
|
* @param args.policyOptions - Options to pass to `createServicePolicy`, which
|
|
138
122
|
* is used to wrap each request. See {@link CreateServicePolicyOptions}.
|
|
139
123
|
*/
|
|
140
|
-
constructor({ messenger, fetch: fetchFunction,
|
|
124
|
+
constructor({ messenger, fetch: fetchFunction, env, policyOptions, }: {
|
|
125
|
+
messenger: ComplianceServiceMessenger;
|
|
126
|
+
fetch: typeof fetch;
|
|
127
|
+
env: ComplianceServiceEnvironment;
|
|
128
|
+
policyOptions?: CreateServicePolicyOptions;
|
|
129
|
+
});
|
|
141
130
|
/**
|
|
142
131
|
* Registers a handler that will be called after a request returns a non-500
|
|
143
132
|
* response, causing a retry.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComplianceService.d.cts","sourceRoot":"","sources":["../src/ComplianceService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,0BAA0B,EAC1B,aAAa,EACd,mCAAmC;AAEpC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AAEnD,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB;AAE7C,OAAO,KAAK,EAAE,8BAA8B,EAAE,oDAAgD;AAI9F;;;GAGG;AACH,eAAO,MAAM,WAAW,sBAAsB,CAAC;AAE/C;;GAEG;AACH,MAAM,MAAM,4BAA4B,GAAG,YAAY,GAAG,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"ComplianceService.d.cts","sourceRoot":"","sources":["../src/ComplianceService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,0BAA0B,EAC1B,aAAa,EACd,mCAAmC;AAEpC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AAEnD,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB;AAE7C,OAAO,KAAK,EAAE,8BAA8B,EAAE,oDAAgD;AAI9F;;;GAGG;AACH,eAAO,MAAM,WAAW,sBAAsB,CAAC;AAE/C;;GAEG;AACH,MAAM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AE,UAAU,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,WAAW;IAIvE;;;;;;;OAOG;IACH,UAAU,CACR,QAAQ,EAAE,UAAU,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,GACnD,WAAW;IAId;;;;;OAKG;IACG,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAwB1E;;;;;OAKG;IACG,sBAAsB,CAC1B,SAAS,EAAE,MAAM,EAAE,GAClB,OAAO,CAAC,4BAA4B,EAAE,CAAC;CAwB3C"}
|
|
@@ -12,21 +12,6 @@ export declare const serviceName = "ComplianceService";
|
|
|
12
12
|
* The supported environments for the Compliance API.
|
|
13
13
|
*/
|
|
14
14
|
export type ComplianceServiceEnvironment = 'production' | 'development';
|
|
15
|
-
export type ComplianceServiceOptions = {
|
|
16
|
-
messenger: ComplianceServiceMessenger;
|
|
17
|
-
fetch: typeof fetch;
|
|
18
|
-
/**
|
|
19
|
-
* Explicit Compliance API URL. Prefer this for application builds so API
|
|
20
|
-
* endpoints can be managed by build configuration. Path components are
|
|
21
|
-
* preserved as a base path for Compliance API routes.
|
|
22
|
-
*/
|
|
23
|
-
apiUrl?: string;
|
|
24
|
-
/**
|
|
25
|
-
* Fallback environment used when `apiUrl` is not provided.
|
|
26
|
-
*/
|
|
27
|
-
env?: ComplianceServiceEnvironment;
|
|
28
|
-
policyOptions?: CreateServicePolicyOptions;
|
|
29
|
-
};
|
|
30
15
|
/**
|
|
31
16
|
* Actions that {@link ComplianceService} exposes to other consumers.
|
|
32
17
|
*/
|
|
@@ -108,7 +93,7 @@ type BatchWalletCheckResponseItem = Infer<typeof BatchWalletCheckResponseItemStr
|
|
|
108
93
|
* new ComplianceService({
|
|
109
94
|
* messenger: serviceMessenger,
|
|
110
95
|
* fetch,
|
|
111
|
-
*
|
|
96
|
+
* env: 'production',
|
|
112
97
|
* });
|
|
113
98
|
*
|
|
114
99
|
* // Check a single wallet
|
|
@@ -131,13 +116,17 @@ export declare class ComplianceService {
|
|
|
131
116
|
* @param args - The constructor arguments.
|
|
132
117
|
* @param args.messenger - The messenger suited for this service.
|
|
133
118
|
* @param args.fetch - A function that can be used to make an HTTP request.
|
|
134
|
-
* @param args.
|
|
135
|
-
*
|
|
136
|
-
* when `apiUrl` is not provided.
|
|
119
|
+
* @param args.env - The environment to use for the Compliance API. Determines
|
|
120
|
+
* the base URL.
|
|
137
121
|
* @param args.policyOptions - Options to pass to `createServicePolicy`, which
|
|
138
122
|
* is used to wrap each request. See {@link CreateServicePolicyOptions}.
|
|
139
123
|
*/
|
|
140
|
-
constructor({ messenger, fetch: fetchFunction,
|
|
124
|
+
constructor({ messenger, fetch: fetchFunction, env, policyOptions, }: {
|
|
125
|
+
messenger: ComplianceServiceMessenger;
|
|
126
|
+
fetch: typeof fetch;
|
|
127
|
+
env: ComplianceServiceEnvironment;
|
|
128
|
+
policyOptions?: CreateServicePolicyOptions;
|
|
129
|
+
});
|
|
141
130
|
/**
|
|
142
131
|
* Registers a handler that will be called after a request returns a non-500
|
|
143
132
|
* response, causing a retry.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComplianceService.d.mts","sourceRoot":"","sources":["../src/ComplianceService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,0BAA0B,EAC1B,aAAa,EACd,mCAAmC;AAEpC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AAEnD,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB;AAE7C,OAAO,KAAK,EAAE,8BAA8B,EAAE,oDAAgD;AAI9F;;;GAGG;AACH,eAAO,MAAM,WAAW,sBAAsB,CAAC;AAE/C;;GAEG;AACH,MAAM,MAAM,4BAA4B,GAAG,YAAY,GAAG,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"ComplianceService.d.mts","sourceR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AE,aAAa,EACpB,GAAG,EACH,aAAkB,GACnB,EAAE;QACD,SAAS,EAAE,0BAA0B,CAAC;QACtC,KAAK,EAAE,OAAO,KAAK,CAAC;QACpB,GAAG,EAAE,4BAA4B,CAAC;QAClC,aAAa,CAAC,EAAE,0BAA0B,CAAC;KAC5C;IAaD;;;;;;;OAOG;IACH,OAAO,CAAC,QAAQ,EAAE,UAAU,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,WAAW;IAIvE;;;;;;;OAOG;IACH,OAAO,CAAC,QAAQ,EAAE,UAAU,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,WAAW;IAIvE;;;;;;;OAOG;IACH,UAAU,CACR,QAAQ,EAAE,UAAU,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,GACnD,WAAW;IAId;;;;;OAKG;IACG,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAwB1E;;;;;OAKG;IACG,sBAAsB,CAC1B,SAAS,EAAE,MAAM,EAAE,GAClB,OAAO,CAAC,4BAA4B,EAAE,CAAC;CAwB3C"}
|
|
@@ -72,7 +72,7 @@ const BatchWalletCheckResponseItemStruct = WalletCheckResponseStruct;
|
|
|
72
72
|
* new ComplianceService({
|
|
73
73
|
* messenger: serviceMessenger,
|
|
74
74
|
* fetch,
|
|
75
|
-
*
|
|
75
|
+
* env: 'production',
|
|
76
76
|
* });
|
|
77
77
|
*
|
|
78
78
|
* // Check a single wallet
|
|
@@ -90,13 +90,12 @@ export class ComplianceService {
|
|
|
90
90
|
* @param args - The constructor arguments.
|
|
91
91
|
* @param args.messenger - The messenger suited for this service.
|
|
92
92
|
* @param args.fetch - A function that can be used to make an HTTP request.
|
|
93
|
-
* @param args.
|
|
94
|
-
*
|
|
95
|
-
* when `apiUrl` is not provided.
|
|
93
|
+
* @param args.env - The environment to use for the Compliance API. Determines
|
|
94
|
+
* the base URL.
|
|
96
95
|
* @param args.policyOptions - Options to pass to `createServicePolicy`, which
|
|
97
96
|
* is used to wrap each request. See {@link CreateServicePolicyOptions}.
|
|
98
97
|
*/
|
|
99
|
-
constructor({ messenger, fetch: fetchFunction,
|
|
98
|
+
constructor({ messenger, fetch: fetchFunction, env, policyOptions = {}, }) {
|
|
100
99
|
/**
|
|
101
100
|
* The messenger suited for this service.
|
|
102
101
|
*/
|
|
@@ -118,7 +117,7 @@ export class ComplianceService {
|
|
|
118
117
|
this.name = serviceName;
|
|
119
118
|
__classPrivateFieldSet(this, _ComplianceService_messenger, messenger, "f");
|
|
120
119
|
__classPrivateFieldSet(this, _ComplianceService_fetch, fetchFunction, "f");
|
|
121
|
-
__classPrivateFieldSet(this, _ComplianceService_complianceApiUrl,
|
|
120
|
+
__classPrivateFieldSet(this, _ComplianceService_complianceApiUrl, COMPLIANCE_API_URLS[env], "f");
|
|
122
121
|
__classPrivateFieldSet(this, _ComplianceService_policy, createServicePolicy(policyOptions), "f");
|
|
123
122
|
__classPrivateFieldGet(this, _ComplianceService_messenger, "f").registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
124
123
|
}
|
|
@@ -163,7 +162,7 @@ export class ComplianceService {
|
|
|
163
162
|
*/
|
|
164
163
|
async checkWalletCompliance(address) {
|
|
165
164
|
const response = await __classPrivateFieldGet(this, _ComplianceService_policy, "f").execute(async () => {
|
|
166
|
-
const url = new URL(
|
|
165
|
+
const url = new URL(`/v1/wallet/${encodeURIComponent(address)}`, __classPrivateFieldGet(this, _ComplianceService_complianceApiUrl, "f"));
|
|
167
166
|
const localResponse = await __classPrivateFieldGet(this, _ComplianceService_fetch, "f").call(this, url);
|
|
168
167
|
if (!localResponse.ok) {
|
|
169
168
|
throw new HttpError(localResponse.status, `Fetching '${url.toString()}' failed with status '${localResponse.status}'`);
|
|
@@ -181,7 +180,7 @@ export class ComplianceService {
|
|
|
181
180
|
*/
|
|
182
181
|
async checkWalletsCompliance(addresses) {
|
|
183
182
|
const response = await __classPrivateFieldGet(this, _ComplianceService_policy, "f").execute(async () => {
|
|
184
|
-
const url = new URL('v1/wallet/batch', __classPrivateFieldGet(this, _ComplianceService_complianceApiUrl, "f"));
|
|
183
|
+
const url = new URL('/v1/wallet/batch', __classPrivateFieldGet(this, _ComplianceService_complianceApiUrl, "f"));
|
|
185
184
|
const localResponse = await __classPrivateFieldGet(this, _ComplianceService_fetch, "f").call(this, url, {
|
|
186
185
|
method: 'POST',
|
|
187
186
|
headers: { 'Content-Type': 'application/json' },
|
|
@@ -197,25 +196,6 @@ export class ComplianceService {
|
|
|
197
196
|
}
|
|
198
197
|
}
|
|
199
198
|
_a = ComplianceService, _ComplianceService_messenger = new WeakMap(), _ComplianceService_fetch = new WeakMap(), _ComplianceService_complianceApiUrl = new WeakMap(), _ComplianceService_policy = new WeakMap();
|
|
200
|
-
function getComplianceApiUrl({ apiUrl, env, }) {
|
|
201
|
-
if (apiUrl === undefined) {
|
|
202
|
-
return COMPLIANCE_API_URLS[env];
|
|
203
|
-
}
|
|
204
|
-
let url;
|
|
205
|
-
try {
|
|
206
|
-
url = new URL(apiUrl);
|
|
207
|
-
}
|
|
208
|
-
catch {
|
|
209
|
-
throw new Error(`Invalid Compliance API URL: ${apiUrl}`);
|
|
210
|
-
}
|
|
211
|
-
if (url.search || url.hash) {
|
|
212
|
-
throw new Error(`Invalid Compliance API URL: ${apiUrl}. Query strings and fragments are not supported.`);
|
|
213
|
-
}
|
|
214
|
-
if (!url.pathname.endsWith('/')) {
|
|
215
|
-
url.pathname = `${url.pathname}/`;
|
|
216
|
-
}
|
|
217
|
-
return url.href;
|
|
218
|
-
}
|
|
219
199
|
/**
|
|
220
200
|
* Validates an API response against a superstruct schema.
|
|
221
201
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComplianceService.mjs","sourceRoot":"","sources":["../src/ComplianceService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAIA,O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GAAG,CAAC,IAAI,EAAE,CAAC;QAC3B,MAAM,IAAI,KAAK,CACb,+BAA+B,MAAM,kDAAkD,CACxF,CAAC;IACJ,CAAC;IACD,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAChC,GAAG,CAAC,QAAQ,GAAG,GAAG,GAAG,CAAC,QAAQ,GAAG,CAAC;IACpC,CAAC;IACD,OAAO,GAAG,CAAC,IAAI,CAAC;AAClB,CAAC;AAED;;;;;;;;;GASG;AACH,SAAS,gBAAgB,CACvB,IAAa,EACb,MAAqD,EACrD,OAAe;IAEf,IAAI,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QACpB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,oCAAoC,OAAO,EAAE,CAAC,CAAC;AACjE,CAAC","sourcesContent":["import type {\n CreateServicePolicyOptions,\n ServicePolicy,\n} from '@metamask/controller-utils';\nimport { createServicePolicy, HttpError } from '@metamask/controller-utils';\nimport type { Messenger } from '@metamask/messenger';\nimport type { Infer } from '@metamask/superstruct';\nimport { array, boolean, object, string } from '@metamask/superstruct';\nimport type { IDisposable } from 'cockatiel';\n\nimport type { ComplianceServiceMethodActions } from './ComplianceService-method-action-types';\n\n// === GENERAL ===\n\n/**\n * The name of the {@link ComplianceService}, used to namespace the service's\n * actions and events.\n */\nexport const serviceName = 'ComplianceService';\n\n/**\n * The supported environments for the Compliance API.\n */\nexport type ComplianceServiceEnvironment = 'production' | 'development';\n\nconst COMPLIANCE_API_URLS: Record<ComplianceServiceEnvironment, string> = {\n production: 'https://compliance.api.cx.metamask.io',\n development: 'https://compliance.dev-api.cx.metamask.io',\n};\n\nexport type ComplianceServiceOptions = {\n messenger: ComplianceServiceMessenger;\n fetch: typeof fetch;\n /**\n * Explicit Compliance API URL. Prefer this for application builds so API\n * endpoints can be managed by build configuration. Path components are\n * preserved as a base path for Compliance API routes.\n */\n apiUrl?: string;\n /**\n * Fallback environment used when `apiUrl` is not provided.\n */\n env?: ComplianceServiceEnvironment;\n policyOptions?: CreateServicePolicyOptions;\n};\n\n// === MESSENGER ===\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'checkWalletCompliance',\n 'checkWalletsCompliance',\n] as const;\n\n/**\n * Actions that {@link ComplianceService} exposes to other consumers.\n */\nexport type ComplianceServiceActions = ComplianceServiceMethodActions;\n\n/**\n * Actions from other messengers that {@link ComplianceService} calls.\n */\ntype AllowedActions = never;\n\n/**\n * Events that {@link ComplianceService} exposes to other consumers.\n */\nexport type ComplianceServiceEvents = never;\n\n/**\n * Events from other messengers that {@link ComplianceService} subscribes to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger restricted to actions and events accessed by\n * {@link ComplianceService}.\n */\nexport type ComplianceServiceMessenger = Messenger<\n typeof serviceName,\n ComplianceServiceActions | AllowedActions,\n ComplianceServiceEvents | AllowedEvents\n>;\n\n// === API RESPONSE SCHEMAS ===\n\n/**\n * Schema for the response from `GET /v1/wallet/:address`.\n */\nconst WalletCheckResponseStruct = object({\n address: string(),\n blocked: boolean(),\n});\n\n/**\n * The validated shape of a single wallet compliance check response.\n */\ntype WalletCheckResponse = Infer<typeof WalletCheckResponseStruct>;\n\n/**\n * Schema for each item in the response from `POST /v1/wallet/batch`.\n * Reuses the same shape as a single wallet check.\n */\nconst BatchWalletCheckResponseItemStruct = WalletCheckResponseStruct;\n\n/**\n * The validated shape of a single item in a batch compliance check response.\n */\ntype BatchWalletCheckResponseItem = Infer<\n typeof BatchWalletCheckResponseItemStruct\n>;\n\n// === SERVICE DEFINITION ===\n\n/**\n * `ComplianceService` communicates with the Compliance API to check whether\n * wallet addresses are sanctioned under OFAC regulations.\n *\n * @example\n *\n * ``` ts\n * import { Messenger } from '@metamask/messenger';\n * import type {\n * ComplianceServiceActions,\n * ComplianceServiceEvents,\n * } from '@metamask/compliance-controller';\n * import { ComplianceService } from '@metamask/compliance-controller';\n *\n * const rootMessenger = new Messenger<\n * 'Root',\n * ComplianceServiceActions,\n * ComplianceServiceEvents,\n * >({ namespace: 'Root' });\n * const serviceMessenger = new Messenger<\n * 'ComplianceService',\n * ComplianceServiceActions,\n * ComplianceServiceEvents,\n * typeof rootMessenger,\n * >({\n * namespace: 'ComplianceService',\n * parent: rootMessenger,\n * });\n * new ComplianceService({\n * messenger: serviceMessenger,\n * fetch,\n * apiUrl: 'https://compliance.api.cx.metamask.io',\n * });\n *\n * // Check a single wallet\n * const result = await rootMessenger.call(\n * 'ComplianceService:checkWalletCompliance',\n * '0x1234...',\n * );\n * // => { address: '0x1234...', blocked: false }\n * ```\n */\nexport class ComplianceService {\n /**\n * The name of the service.\n */\n readonly name: typeof serviceName;\n\n /**\n * The messenger suited for this service.\n */\n readonly #messenger: ConstructorParameters<\n typeof ComplianceService\n >[0]['messenger'];\n\n /**\n * A function that can be used to make an HTTP request.\n */\n readonly #fetch: ConstructorParameters<typeof ComplianceService>[0]['fetch'];\n\n /**\n * The resolved base URL for the Compliance API.\n */\n readonly #complianceApiUrl: string;\n\n /**\n * The policy that wraps each request.\n *\n * @see {@link createServicePolicy}\n */\n readonly #policy: ServicePolicy;\n\n /**\n * Constructs a new ComplianceService object.\n *\n * @param args - The constructor arguments.\n * @param args.messenger - The messenger suited for this service.\n * @param args.fetch - A function that can be used to make an HTTP request.\n * @param args.apiUrl - The explicit Compliance API URL.\n * @param args.env - The fallback environment to use for the Compliance API\n * when `apiUrl` is not provided.\n * @param args.policyOptions - Options to pass to `createServicePolicy`, which\n * is used to wrap each request. See {@link CreateServicePolicyOptions}.\n */\n constructor({\n messenger,\n fetch: fetchFunction,\n apiUrl,\n env = 'production',\n policyOptions = {},\n }: ComplianceServiceOptions) {\n this.name = serviceName;\n this.#messenger = messenger;\n this.#fetch = fetchFunction;\n this.#complianceApiUrl = getComplianceApiUrl({ apiUrl, env });\n this.#policy = createServicePolicy(policyOptions);\n\n this.#messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Registers a handler that will be called after a request returns a non-500\n * response, causing a retry.\n *\n * @param listener - The handler to be called.\n * @returns An object that can be used to unregister the handler.\n * @see {@link createServicePolicy}\n */\n onRetry(listener: Parameters<ServicePolicy['onRetry']>[0]): IDisposable {\n return this.#policy.onRetry(listener);\n }\n\n /**\n * Registers a handler that will be called after a set number of retry rounds\n * prove that requests to the API endpoint consistently return a 5xx response.\n *\n * @param listener - The handler to be called.\n * @returns An object that can be used to unregister the handler.\n * @see {@link createServicePolicy}\n */\n onBreak(listener: Parameters<ServicePolicy['onBreak']>[0]): IDisposable {\n return this.#policy.onBreak(listener);\n }\n\n /**\n * Registers a handler that will be called when the service is degraded due\n * to slow responses or repeated failures.\n *\n * @param listener - The handler to be called.\n * @returns An object that can be used to unregister the handler.\n * @see {@link createServicePolicy}\n */\n onDegraded(\n listener: Parameters<ServicePolicy['onDegraded']>[0],\n ): IDisposable {\n return this.#policy.onDegraded(listener);\n }\n\n /**\n * Checks compliance status for a single wallet address.\n *\n * @param address - The wallet address to check.\n * @returns The compliance status of the wallet.\n */\n async checkWalletCompliance(address: string): Promise<WalletCheckResponse> {\n const response = await this.#policy.execute(async () => {\n const url = new URL(\n `v1/wallet/${encodeURIComponent(address)}`,\n this.#complianceApiUrl,\n );\n const localResponse = await this.#fetch(url);\n if (!localResponse.ok) {\n throw new HttpError(\n localResponse.status,\n `Fetching '${url.toString()}' failed with status '${localResponse.status}'`,\n );\n }\n return localResponse;\n });\n const jsonResponse: unknown = await response.json();\n\n return validateResponse(\n jsonResponse,\n WalletCheckResponseStruct,\n 'compliance wallet check API',\n );\n }\n\n /**\n * Checks compliance status for multiple wallet addresses in a single request.\n *\n * @param addresses - The wallet addresses to check.\n * @returns The compliance statuses of the wallets.\n */\n async checkWalletsCompliance(\n addresses: string[],\n ): Promise<BatchWalletCheckResponseItem[]> {\n const response = await this.#policy.execute(async () => {\n const url = new URL('v1/wallet/batch', this.#complianceApiUrl);\n const localResponse = await this.#fetch(url, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify(addresses),\n });\n if (!localResponse.ok) {\n throw new HttpError(\n localResponse.status,\n `Fetching '${url.toString()}' failed with status '${localResponse.status}'`,\n );\n }\n return localResponse;\n });\n const jsonResponse: unknown = await response.json();\n\n return validateResponse(\n jsonResponse,\n array(BatchWalletCheckResponseItemStruct),\n 'compliance batch check API',\n );\n }\n}\n\nfunction getComplianceApiUrl({\n apiUrl,\n env,\n}: {\n apiUrl?: string;\n env: ComplianceServiceEnvironment;\n}): string {\n if (apiUrl === undefined) {\n return COMPLIANCE_API_URLS[env];\n }\n\n let url: URL;\n try {\n url = new URL(apiUrl);\n } catch {\n throw new Error(`Invalid Compliance API URL: ${apiUrl}`);\n }\n\n if (url.search || url.hash) {\n throw new Error(\n `Invalid Compliance API URL: ${apiUrl}. Query strings and fragments are not supported.`,\n );\n }\n if (!url.pathname.endsWith('/')) {\n url.pathname = `${url.pathname}/`;\n }\n return url.href;\n}\n\n/**\n * Validates an API response against a superstruct schema.\n *\n * @param data - The raw response data to validate.\n * @param struct - The superstruct schema to validate against.\n * @param struct.is - The type guard function from the schema.\n * @param apiName - A human-readable name for the API, used in error messages.\n * @returns The validated data.\n * @throws If the data does not match the schema.\n */\nfunction validateResponse<Response>(\n data: unknown,\n struct: { is: (value: unknown) => value is Response },\n apiName: string,\n): Response {\n if (struct.is(data)) {\n return data;\n }\n throw new Error(`Malformed response received from ${apiName}`);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ComplianceService.mjs","sourceRoot":"","sources":["../src/ComplianceService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAIA,OAAO,EAAE,mBAAmB,EAAE,SAAS,EAAE,mCAAmC;AAG5E,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,8BAA8B;AAKvE,kBAAkB;AAElB;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,mBAAm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gCAAO,MAAX,IAAI,EAAQ,GAAG,EAAE;gBAC3C,MAAM,EAAE,MAAM;gBACd,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;gBAC/C,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC;aAChC,CAAC,CAAC;YACH,IAAI,CAAC,aAAa,CAAC,EAAE,EAAE,CAAC;gBACtB,MAAM,IAAI,SAAS,CACjB,aAAa,CAAC,MAAM,EACpB,aAAa,GAAG,CAAC,QAAQ,EAAE,yBAAyB,aAAa,CAAC,MAAM,GAAG,CAC5E,CAAC;YACJ,CAAC;YACD,OAAO,aAAa,CAAC;QACvB,CAAC,CAAC,CAAC;QACH,MAAM,YAAY,GAAY,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QAEpD,OAAO,gBAAgB,CACrB,YAAY,EACZ,KAAK,CAAC,kCAAkC,CAAC,EACzC,4BAA4B,CAC7B,CAAC;IACJ,CAAC;CACF;;AAED;;;;;;;;;GASG;AACH,SAAS,gBAAgB,CACvB,IAAa,EACb,MAAqD,EACrD,OAAe;IAEf,IAAI,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QACpB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,oCAAoC,OAAO,EAAE,CAAC,CAAC;AACjE,CAAC","sourcesContent":["import type {\n CreateServicePolicyOptions,\n ServicePolicy,\n} from '@metamask/controller-utils';\nimport { createServicePolicy, HttpError } from '@metamask/controller-utils';\nimport type { Messenger } from '@metamask/messenger';\nimport type { Infer } from '@metamask/superstruct';\nimport { array, boolean, object, string } from '@metamask/superstruct';\nimport type { IDisposable } from 'cockatiel';\n\nimport type { ComplianceServiceMethodActions } from './ComplianceService-method-action-types';\n\n// === GENERAL ===\n\n/**\n * The name of the {@link ComplianceService}, used to namespace the service's\n * actions and events.\n */\nexport const serviceName = 'ComplianceService';\n\n/**\n * The supported environments for the Compliance API.\n */\nexport type ComplianceServiceEnvironment = 'production' | 'development';\n\nconst COMPLIANCE_API_URLS: Record<ComplianceServiceEnvironment, string> = {\n production: 'https://compliance.api.cx.metamask.io',\n development: 'https://compliance.dev-api.cx.metamask.io',\n};\n\n// === MESSENGER ===\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'checkWalletCompliance',\n 'checkWalletsCompliance',\n] as const;\n\n/**\n * Actions that {@link ComplianceService} exposes to other consumers.\n */\nexport type ComplianceServiceActions = ComplianceServiceMethodActions;\n\n/**\n * Actions from other messengers that {@link ComplianceService} calls.\n */\ntype AllowedActions = never;\n\n/**\n * Events that {@link ComplianceService} exposes to other consumers.\n */\nexport type ComplianceServiceEvents = never;\n\n/**\n * Events from other messengers that {@link ComplianceService} subscribes to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger restricted to actions and events accessed by\n * {@link ComplianceService}.\n */\nexport type ComplianceServiceMessenger = Messenger<\n typeof serviceName,\n ComplianceServiceActions | AllowedActions,\n ComplianceServiceEvents | AllowedEvents\n>;\n\n// === API RESPONSE SCHEMAS ===\n\n/**\n * Schema for the response from `GET /v1/wallet/:address`.\n */\nconst WalletCheckResponseStruct = object({\n address: string(),\n blocked: boolean(),\n});\n\n/**\n * The validated shape of a single wallet compliance check response.\n */\ntype WalletCheckResponse = Infer<typeof WalletCheckResponseStruct>;\n\n/**\n * Schema for each item in the response from `POST /v1/wallet/batch`.\n * Reuses the same shape as a single wallet check.\n */\nconst BatchWalletCheckResponseItemStruct = WalletCheckResponseStruct;\n\n/**\n * The validated shape of a single item in a batch compliance check response.\n */\ntype BatchWalletCheckResponseItem = Infer<\n typeof BatchWalletCheckResponseItemStruct\n>;\n\n// === SERVICE DEFINITION ===\n\n/**\n * `ComplianceService` communicates with the Compliance API to check whether\n * wallet addresses are sanctioned under OFAC regulations.\n *\n * @example\n *\n * ``` ts\n * import { Messenger } from '@metamask/messenger';\n * import type {\n * ComplianceServiceActions,\n * ComplianceServiceEvents,\n * } from '@metamask/compliance-controller';\n * import { ComplianceService } from '@metamask/compliance-controller';\n *\n * const rootMessenger = new Messenger<\n * 'Root',\n * ComplianceServiceActions,\n * ComplianceServiceEvents,\n * >({ namespace: 'Root' });\n * const serviceMessenger = new Messenger<\n * 'ComplianceService',\n * ComplianceServiceActions,\n * ComplianceServiceEvents,\n * typeof rootMessenger,\n * >({\n * namespace: 'ComplianceService',\n * parent: rootMessenger,\n * });\n * new ComplianceService({\n * messenger: serviceMessenger,\n * fetch,\n * env: 'production',\n * });\n *\n * // Check a single wallet\n * const result = await rootMessenger.call(\n * 'ComplianceService:checkWalletCompliance',\n * '0x1234...',\n * );\n * // => { address: '0x1234...', blocked: false }\n * ```\n */\nexport class ComplianceService {\n /**\n * The name of the service.\n */\n readonly name: typeof serviceName;\n\n /**\n * The messenger suited for this service.\n */\n readonly #messenger: ConstructorParameters<\n typeof ComplianceService\n >[0]['messenger'];\n\n /**\n * A function that can be used to make an HTTP request.\n */\n readonly #fetch: ConstructorParameters<typeof ComplianceService>[0]['fetch'];\n\n /**\n * The resolved base URL for the Compliance API.\n */\n readonly #complianceApiUrl: string;\n\n /**\n * The policy that wraps each request.\n *\n * @see {@link createServicePolicy}\n */\n readonly #policy: ServicePolicy;\n\n /**\n * Constructs a new ComplianceService object.\n *\n * @param args - The constructor arguments.\n * @param args.messenger - The messenger suited for this service.\n * @param args.fetch - A function that can be used to make an HTTP request.\n * @param args.env - The environment to use for the Compliance API. Determines\n * the base URL.\n * @param args.policyOptions - Options to pass to `createServicePolicy`, which\n * is used to wrap each request. See {@link CreateServicePolicyOptions}.\n */\n constructor({\n messenger,\n fetch: fetchFunction,\n env,\n policyOptions = {},\n }: {\n messenger: ComplianceServiceMessenger;\n fetch: typeof fetch;\n env: ComplianceServiceEnvironment;\n policyOptions?: CreateServicePolicyOptions;\n }) {\n this.name = serviceName;\n this.#messenger = messenger;\n this.#fetch = fetchFunction;\n this.#complianceApiUrl = COMPLIANCE_API_URLS[env];\n this.#policy = createServicePolicy(policyOptions);\n\n this.#messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Registers a handler that will be called after a request returns a non-500\n * response, causing a retry.\n *\n * @param listener - The handler to be called.\n * @returns An object that can be used to unregister the handler.\n * @see {@link createServicePolicy}\n */\n onRetry(listener: Parameters<ServicePolicy['onRetry']>[0]): IDisposable {\n return this.#policy.onRetry(listener);\n }\n\n /**\n * Registers a handler that will be called after a set number of retry rounds\n * prove that requests to the API endpoint consistently return a 5xx response.\n *\n * @param listener - The handler to be called.\n * @returns An object that can be used to unregister the handler.\n * @see {@link createServicePolicy}\n */\n onBreak(listener: Parameters<ServicePolicy['onBreak']>[0]): IDisposable {\n return this.#policy.onBreak(listener);\n }\n\n /**\n * Registers a handler that will be called when the service is degraded due\n * to slow responses or repeated failures.\n *\n * @param listener - The handler to be called.\n * @returns An object that can be used to unregister the handler.\n * @see {@link createServicePolicy}\n */\n onDegraded(\n listener: Parameters<ServicePolicy['onDegraded']>[0],\n ): IDisposable {\n return this.#policy.onDegraded(listener);\n }\n\n /**\n * Checks compliance status for a single wallet address.\n *\n * @param address - The wallet address to check.\n * @returns The compliance status of the wallet.\n */\n async checkWalletCompliance(address: string): Promise<WalletCheckResponse> {\n const response = await this.#policy.execute(async () => {\n const url = new URL(\n `/v1/wallet/${encodeURIComponent(address)}`,\n this.#complianceApiUrl,\n );\n const localResponse = await this.#fetch(url);\n if (!localResponse.ok) {\n throw new HttpError(\n localResponse.status,\n `Fetching '${url.toString()}' failed with status '${localResponse.status}'`,\n );\n }\n return localResponse;\n });\n const jsonResponse: unknown = await response.json();\n\n return validateResponse(\n jsonResponse,\n WalletCheckResponseStruct,\n 'compliance wallet check API',\n );\n }\n\n /**\n * Checks compliance status for multiple wallet addresses in a single request.\n *\n * @param addresses - The wallet addresses to check.\n * @returns The compliance statuses of the wallets.\n */\n async checkWalletsCompliance(\n addresses: string[],\n ): Promise<BatchWalletCheckResponseItem[]> {\n const response = await this.#policy.execute(async () => {\n const url = new URL('/v1/wallet/batch', this.#complianceApiUrl);\n const localResponse = await this.#fetch(url, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify(addresses),\n });\n if (!localResponse.ok) {\n throw new HttpError(\n localResponse.status,\n `Fetching '${url.toString()}' failed with status '${localResponse.status}'`,\n );\n }\n return localResponse;\n });\n const jsonResponse: unknown = await response.json();\n\n return validateResponse(\n jsonResponse,\n array(BatchWalletCheckResponseItemStruct),\n 'compliance batch check API',\n );\n }\n}\n\n/**\n * Validates an API response against a superstruct schema.\n *\n * @param data - The raw response data to validate.\n * @param struct - The superstruct schema to validate against.\n * @param struct.is - The type guard function from the schema.\n * @param apiName - A human-readable name for the API, used in error messages.\n * @returns The validated data.\n * @throws If the data does not match the schema.\n */\nfunction validateResponse<Response>(\n data: unknown,\n struct: { is: (value: unknown) => value is Response },\n apiName: string,\n): Response {\n if (struct.is(data)) {\n return data;\n }\n throw new Error(`Malformed response received from ${apiName}`);\n}\n"]}
|
package/dist/index.cjs
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.selectIsWalletBlocked = exports.
|
|
3
|
+
exports.selectIsWalletBlocked = exports.getDefaultComplianceControllerState = exports.ComplianceController = exports.ComplianceService = void 0;
|
|
4
4
|
var ComplianceService_1 = require("./ComplianceService.cjs");
|
|
5
5
|
Object.defineProperty(exports, "ComplianceService", { enumerable: true, get: function () { return ComplianceService_1.ComplianceService; } });
|
|
6
6
|
var ComplianceController_1 = require("./ComplianceController.cjs");
|
|
7
7
|
Object.defineProperty(exports, "ComplianceController", { enumerable: true, get: function () { return ComplianceController_1.ComplianceController; } });
|
|
8
8
|
Object.defineProperty(exports, "getDefaultComplianceControllerState", { enumerable: true, get: function () { return ComplianceController_1.getDefaultComplianceControllerState; } });
|
|
9
9
|
var selectors_1 = require("./selectors.cjs");
|
|
10
|
-
Object.defineProperty(exports, "selectAreAnyWalletsBlocked", { enumerable: true, get: function () { return selectors_1.selectAreAnyWalletsBlocked; } });
|
|
11
10
|
Object.defineProperty(exports, "selectIsWalletBlocked", { enumerable: true, get: function () { return selectors_1.selectIsWalletBlocked; } });
|
|
12
11
|
//# 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":";;;
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAUA,6DAAwD;AAA/C,sHAAA,iBAAiB,OAAA;AAc1B,mEAGgC;AAF9B,4HAAA,oBAAoB,OAAA;AACpB,2IAAA,mCAAmC,OAAA;AAErC,6CAAoD;AAA3C,kHAAA,qBAAqB,OAAA","sourcesContent":["export type {\n ComplianceServiceActions,\n ComplianceServiceEnvironment,\n ComplianceServiceEvents,\n ComplianceServiceMessenger,\n} from './ComplianceService';\nexport type {\n ComplianceServiceCheckWalletComplianceAction,\n ComplianceServiceCheckWalletsComplianceAction,\n} from './ComplianceService-method-action-types';\nexport { ComplianceService } from './ComplianceService';\nexport type {\n ComplianceControllerActions,\n ComplianceControllerEvents,\n ComplianceControllerGetStateAction,\n ComplianceControllerMessenger,\n ComplianceControllerState,\n ComplianceControllerStateChangeEvent,\n} from './ComplianceController';\nexport type {\n ComplianceControllerCheckWalletComplianceAction,\n ComplianceControllerCheckWalletsComplianceAction,\n ComplianceControllerClearComplianceStateAction,\n} from './ComplianceController-method-action-types';\nexport {\n ComplianceController,\n getDefaultComplianceControllerState,\n} from './ComplianceController';\nexport { selectIsWalletBlocked } from './selectors';\nexport type { WalletComplianceStatus } from './types';\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export type { ComplianceServiceActions, ComplianceServiceEnvironment, ComplianceServiceEvents, ComplianceServiceMessenger,
|
|
1
|
+
export type { ComplianceServiceActions, ComplianceServiceEnvironment, ComplianceServiceEvents, ComplianceServiceMessenger, } from "./ComplianceService.cjs";
|
|
2
2
|
export type { ComplianceServiceCheckWalletComplianceAction, ComplianceServiceCheckWalletsComplianceAction, } from "./ComplianceService-method-action-types.cjs";
|
|
3
3
|
export { ComplianceService } from "./ComplianceService.cjs";
|
|
4
4
|
export type { ComplianceControllerActions, ComplianceControllerEvents, ComplianceControllerGetStateAction, ComplianceControllerMessenger, ComplianceControllerState, ComplianceControllerStateChangeEvent, } from "./ComplianceController.cjs";
|
|
5
5
|
export type { ComplianceControllerCheckWalletComplianceAction, ComplianceControllerCheckWalletsComplianceAction, ComplianceControllerClearComplianceStateAction, } from "./ComplianceController-method-action-types.cjs";
|
|
6
6
|
export { ComplianceController, getDefaultComplianceControllerState, } from "./ComplianceController.cjs";
|
|
7
|
-
export {
|
|
7
|
+
export { selectIsWalletBlocked } from "./selectors.cjs";
|
|
8
8
|
export type { WalletComplianceStatus } from "./types.cjs";
|
|
9
9
|
//# 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,YAAY,EACV,wBAAwB,EACxB,4BAA4B,EAC5B,uBAAuB,EACvB,0BAA0B,
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,wBAAwB,EACxB,4BAA4B,EAC5B,uBAAuB,EACvB,0BAA0B,GAC3B,gCAA4B;AAC7B,YAAY,EACV,4CAA4C,EAC5C,6CAA6C,GAC9C,oDAAgD;AACjD,OAAO,EAAE,iBAAiB,EAAE,gCAA4B;AACxD,YAAY,EACV,2BAA2B,EAC3B,0BAA0B,EAC1B,kCAAkC,EAClC,6BAA6B,EAC7B,yBAAyB,EACzB,oCAAoC,GACrC,mCAA+B;AAChC,YAAY,EACV,+CAA+C,EAC/C,gDAAgD,EAChD,8CAA8C,GAC/C,uDAAmD;AACpD,OAAO,EACL,oBAAoB,EACpB,mCAAmC,GACpC,mCAA+B;AAChC,OAAO,EAAE,qBAAqB,EAAE,wBAAoB;AACpD,YAAY,EAAE,sBAAsB,EAAE,oBAAgB"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export type { ComplianceServiceActions, ComplianceServiceEnvironment, ComplianceServiceEvents, ComplianceServiceMessenger,
|
|
1
|
+
export type { ComplianceServiceActions, ComplianceServiceEnvironment, ComplianceServiceEvents, ComplianceServiceMessenger, } from "./ComplianceService.mjs";
|
|
2
2
|
export type { ComplianceServiceCheckWalletComplianceAction, ComplianceServiceCheckWalletsComplianceAction, } from "./ComplianceService-method-action-types.mjs";
|
|
3
3
|
export { ComplianceService } from "./ComplianceService.mjs";
|
|
4
4
|
export type { ComplianceControllerActions, ComplianceControllerEvents, ComplianceControllerGetStateAction, ComplianceControllerMessenger, ComplianceControllerState, ComplianceControllerStateChangeEvent, } from "./ComplianceController.mjs";
|
|
5
5
|
export type { ComplianceControllerCheckWalletComplianceAction, ComplianceControllerCheckWalletsComplianceAction, ComplianceControllerClearComplianceStateAction, } from "./ComplianceController-method-action-types.mjs";
|
|
6
6
|
export { ComplianceController, getDefaultComplianceControllerState, } from "./ComplianceController.mjs";
|
|
7
|
-
export {
|
|
7
|
+
export { selectIsWalletBlocked } from "./selectors.mjs";
|
|
8
8
|
export type { WalletComplianceStatus } from "./types.mjs";
|
|
9
9
|
//# 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,YAAY,EACV,wBAAwB,EACxB,4BAA4B,EAC5B,uBAAuB,EACvB,0BAA0B,
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,wBAAwB,EACxB,4BAA4B,EAC5B,uBAAuB,EACvB,0BAA0B,GAC3B,gCAA4B;AAC7B,YAAY,EACV,4CAA4C,EAC5C,6CAA6C,GAC9C,oDAAgD;AACjD,OAAO,EAAE,iBAAiB,EAAE,gCAA4B;AACxD,YAAY,EACV,2BAA2B,EAC3B,0BAA0B,EAC1B,kCAAkC,EAClC,6BAA6B,EAC7B,yBAAyB,EACzB,oCAAoC,GACrC,mCAA+B;AAChC,YAAY,EACV,+CAA+C,EAC/C,gDAAgD,EAChD,8CAA8C,GAC/C,uDAAmD;AACpD,OAAO,EACL,oBAAoB,EACpB,mCAAmC,GACpC,mCAA+B;AAChC,OAAO,EAAE,qBAAqB,EAAE,wBAAoB;AACpD,YAAY,EAAE,sBAAsB,EAAE,oBAAgB"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { ComplianceService } from "./ComplianceService.mjs";
|
|
2
2
|
export { ComplianceController, getDefaultComplianceControllerState } from "./ComplianceController.mjs";
|
|
3
|
-
export {
|
|
3
|
+
export { selectIsWalletBlocked } from "./selectors.mjs";
|
|
4
4
|
//# 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":"
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,iBAAiB,EAAE,gCAA4B;AAcxD,OAAO,EACL,oBAAoB,EACpB,mCAAmC,EACpC,mCAA+B;AAChC,OAAO,EAAE,qBAAqB,EAAE,wBAAoB","sourcesContent":["export type {\n ComplianceServiceActions,\n ComplianceServiceEnvironment,\n ComplianceServiceEvents,\n ComplianceServiceMessenger,\n} from './ComplianceService';\nexport type {\n ComplianceServiceCheckWalletComplianceAction,\n ComplianceServiceCheckWalletsComplianceAction,\n} from './ComplianceService-method-action-types';\nexport { ComplianceService } from './ComplianceService';\nexport type {\n ComplianceControllerActions,\n ComplianceControllerEvents,\n ComplianceControllerGetStateAction,\n ComplianceControllerMessenger,\n ComplianceControllerState,\n ComplianceControllerStateChangeEvent,\n} from './ComplianceController';\nexport type {\n ComplianceControllerCheckWalletComplianceAction,\n ComplianceControllerCheckWalletsComplianceAction,\n ComplianceControllerClearComplianceStateAction,\n} from './ComplianceController-method-action-types';\nexport {\n ComplianceController,\n getDefaultComplianceControllerState,\n} from './ComplianceController';\nexport { selectIsWalletBlocked } from './selectors';\nexport type { WalletComplianceStatus } from './types';\n"]}
|
package/dist/selectors.cjs
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.selectIsWalletBlocked = void 0;
|
|
4
4
|
const reselect_1 = require("reselect");
|
|
5
|
-
const utils_1 = require("./utils.cjs");
|
|
6
5
|
const selectWalletComplianceStatusMap = (state) => state.walletComplianceStatusMap;
|
|
7
6
|
/**
|
|
8
7
|
* Creates a selector that returns whether a wallet address is blocked, based
|
|
@@ -12,16 +11,6 @@ const selectWalletComplianceStatusMap = (state) => state.walletComplianceStatusM
|
|
|
12
11
|
* @returns A selector that takes `ComplianceControllerState` and returns
|
|
13
12
|
* `true` if the wallet is blocked, `false` otherwise.
|
|
14
13
|
*/
|
|
15
|
-
const selectIsWalletBlocked = (address) => (0, reselect_1.createSelector)([selectWalletComplianceStatusMap], (statusMap) =>
|
|
14
|
+
const selectIsWalletBlocked = (address) => (0, reselect_1.createSelector)([selectWalletComplianceStatusMap], (statusMap) => statusMap[address]?.blocked ?? false);
|
|
16
15
|
exports.selectIsWalletBlocked = selectIsWalletBlocked;
|
|
17
|
-
/**
|
|
18
|
-
* Creates a selector that returns whether any wallet address is blocked, based
|
|
19
|
-
* on the per-address compliance status cache.
|
|
20
|
-
*
|
|
21
|
-
* @param addresses - The wallet addresses to check.
|
|
22
|
-
* @returns A selector that takes `ComplianceControllerState` and returns
|
|
23
|
-
* `true` if any wallet is blocked, `false` otherwise.
|
|
24
|
-
*/
|
|
25
|
-
const selectAreAnyWalletsBlocked = (addresses) => (0, reselect_1.createSelector)([selectWalletComplianceStatusMap], (statusMap) => addresses.some((address) => (0, utils_1.getWalletComplianceStatus)(statusMap, address)?.blocked));
|
|
26
|
-
exports.selectAreAnyWalletsBlocked = selectAreAnyWalletsBlocked;
|
|
27
16
|
//# sourceMappingURL=selectors.cjs.map
|
package/dist/selectors.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selectors.cjs","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":";;;AAAA,uCAA0C;
|
|
1
|
+
{"version":3,"file":"selectors.cjs","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":";;;AAAA,uCAA0C;AAI1C,MAAM,+BAA+B,GAAG,CACtC,KAAgC,EACwB,EAAE,CAC1D,KAAK,CAAC,yBAAyB,CAAC;AAElC;;;;;;;GAOG;AACI,MAAM,qBAAqB,GAAG,CACnC,OAAe,EACkC,EAAE,CACnD,IAAA,yBAAc,EACZ,CAAC,+BAA+B,CAAC,EACjC,CAAC,SAAS,EAAW,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,OAAO,IAAI,KAAK,CAC7D,CAAC;AANS,QAAA,qBAAqB,yBAM9B","sourcesContent":["import { createSelector } from 'reselect';\n\nimport type { ComplianceControllerState } from './ComplianceController';\n\nconst selectWalletComplianceStatusMap = (\n state: ComplianceControllerState,\n): ComplianceControllerState['walletComplianceStatusMap'] =>\n state.walletComplianceStatusMap;\n\n/**\n * Creates a selector that returns whether a wallet address is blocked, based\n * on the per-address compliance status cache.\n *\n * @param address - The wallet address to check.\n * @returns A selector that takes `ComplianceControllerState` and returns\n * `true` if the wallet is blocked, `false` otherwise.\n */\nexport const selectIsWalletBlocked = (\n address: string,\n): ((state: ComplianceControllerState) => boolean) =>\n createSelector(\n [selectWalletComplianceStatusMap],\n (statusMap): boolean => statusMap[address]?.blocked ?? false,\n );\n"]}
|
package/dist/selectors.d.cts
CHANGED
|
@@ -8,13 +8,4 @@ import type { ComplianceControllerState } from "./ComplianceController.cjs";
|
|
|
8
8
|
* `true` if the wallet is blocked, `false` otherwise.
|
|
9
9
|
*/
|
|
10
10
|
export declare const selectIsWalletBlocked: (address: string) => (state: ComplianceControllerState) => boolean;
|
|
11
|
-
/**
|
|
12
|
-
* Creates a selector that returns whether any wallet address is blocked, based
|
|
13
|
-
* on the per-address compliance status cache.
|
|
14
|
-
*
|
|
15
|
-
* @param addresses - The wallet addresses to check.
|
|
16
|
-
* @returns A selector that takes `ComplianceControllerState` and returns
|
|
17
|
-
* `true` if any wallet is blocked, `false` otherwise.
|
|
18
|
-
*/
|
|
19
|
-
export declare const selectAreAnyWalletsBlocked: (addresses: string[]) => (state: ComplianceControllerState) => boolean;
|
|
20
11
|
//# sourceMappingURL=selectors.d.cts.map
|
package/dist/selectors.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selectors.d.cts","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,yBAAyB,EAAE,mCAA+B;
|
|
1
|
+
{"version":3,"file":"selectors.d.cts","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,yBAAyB,EAAE,mCAA+B;AAOxE;;;;;;;GAOG;AACH,eAAO,MAAM,qBAAqB,YACvB,MAAM,aACL,yBAAyB,KAAK,OAIvC,CAAC"}
|
package/dist/selectors.d.mts
CHANGED
|
@@ -8,13 +8,4 @@ import type { ComplianceControllerState } from "./ComplianceController.mjs";
|
|
|
8
8
|
* `true` if the wallet is blocked, `false` otherwise.
|
|
9
9
|
*/
|
|
10
10
|
export declare const selectIsWalletBlocked: (address: string) => (state: ComplianceControllerState) => boolean;
|
|
11
|
-
/**
|
|
12
|
-
* Creates a selector that returns whether any wallet address is blocked, based
|
|
13
|
-
* on the per-address compliance status cache.
|
|
14
|
-
*
|
|
15
|
-
* @param addresses - The wallet addresses to check.
|
|
16
|
-
* @returns A selector that takes `ComplianceControllerState` and returns
|
|
17
|
-
* `true` if any wallet is blocked, `false` otherwise.
|
|
18
|
-
*/
|
|
19
|
-
export declare const selectAreAnyWalletsBlocked: (addresses: string[]) => (state: ComplianceControllerState) => boolean;
|
|
20
11
|
//# sourceMappingURL=selectors.d.mts.map
|
package/dist/selectors.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selectors.d.mts","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,yBAAyB,EAAE,mCAA+B;
|
|
1
|
+
{"version":3,"file":"selectors.d.mts","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,yBAAyB,EAAE,mCAA+B;AAOxE;;;;;;;GAOG;AACH,eAAO,MAAM,qBAAqB,YACvB,MAAM,aACL,yBAAyB,KAAK,OAIvC,CAAC"}
|
package/dist/selectors.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { createSelector } from "reselect";
|
|
2
|
-
import { getWalletComplianceStatus } from "./utils.mjs";
|
|
3
2
|
const selectWalletComplianceStatusMap = (state) => state.walletComplianceStatusMap;
|
|
4
3
|
/**
|
|
5
4
|
* Creates a selector that returns whether a wallet address is blocked, based
|
|
@@ -9,14 +8,5 @@ const selectWalletComplianceStatusMap = (state) => state.walletComplianceStatusM
|
|
|
9
8
|
* @returns A selector that takes `ComplianceControllerState` and returns
|
|
10
9
|
* `true` if the wallet is blocked, `false` otherwise.
|
|
11
10
|
*/
|
|
12
|
-
export const selectIsWalletBlocked = (address) => createSelector([selectWalletComplianceStatusMap], (statusMap) =>
|
|
13
|
-
/**
|
|
14
|
-
* Creates a selector that returns whether any wallet address is blocked, based
|
|
15
|
-
* on the per-address compliance status cache.
|
|
16
|
-
*
|
|
17
|
-
* @param addresses - The wallet addresses to check.
|
|
18
|
-
* @returns A selector that takes `ComplianceControllerState` and returns
|
|
19
|
-
* `true` if any wallet is blocked, `false` otherwise.
|
|
20
|
-
*/
|
|
21
|
-
export const selectAreAnyWalletsBlocked = (addresses) => createSelector([selectWalletComplianceStatusMap], (statusMap) => addresses.some((address) => getWalletComplianceStatus(statusMap, address)?.blocked));
|
|
11
|
+
export const selectIsWalletBlocked = (address) => createSelector([selectWalletComplianceStatusMap], (statusMap) => statusMap[address]?.blocked ?? false);
|
|
22
12
|
//# sourceMappingURL=selectors.mjs.map
|
package/dist/selectors.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selectors.mjs","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,iBAAiB;
|
|
1
|
+
{"version":3,"file":"selectors.mjs","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,iBAAiB;AAI1C,MAAM,+BAA+B,GAAG,CACtC,KAAgC,EACwB,EAAE,CAC1D,KAAK,CAAC,yBAAyB,CAAC;AAElC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,OAAe,EACkC,EAAE,CACnD,cAAc,CACZ,CAAC,+BAA+B,CAAC,EACjC,CAAC,SAAS,EAAW,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,OAAO,IAAI,KAAK,CAC7D,CAAC","sourcesContent":["import { createSelector } from 'reselect';\n\nimport type { ComplianceControllerState } from './ComplianceController';\n\nconst selectWalletComplianceStatusMap = (\n state: ComplianceControllerState,\n): ComplianceControllerState['walletComplianceStatusMap'] =>\n state.walletComplianceStatusMap;\n\n/**\n * Creates a selector that returns whether a wallet address is blocked, based\n * on the per-address compliance status cache.\n *\n * @param address - The wallet address to check.\n * @returns A selector that takes `ComplianceControllerState` and returns\n * `true` if the wallet is blocked, `false` otherwise.\n */\nexport const selectIsWalletBlocked = (\n address: string,\n): ((state: ComplianceControllerState) => boolean) =>\n createSelector(\n [selectWalletComplianceStatusMap],\n (statusMap): boolean => statusMap[address]?.blocked ?? false,\n );\n"]}
|
package/package.json
CHANGED
package/dist/utils.cjs
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getWalletComplianceStatus = void 0;
|
|
4
|
-
const controller_utils_1 = require("@metamask/controller-utils");
|
|
5
|
-
const getWalletComplianceStatus = (statusMap, address) => {
|
|
6
|
-
const exactMatch = statusMap[address];
|
|
7
|
-
if (exactMatch || !(0, controller_utils_1.isValidHexAddress)(address, { allowNonPrefixed: false })) {
|
|
8
|
-
return exactMatch;
|
|
9
|
-
}
|
|
10
|
-
const matchingAddress = Object.keys(statusMap).find((cachedAddress) => (0, controller_utils_1.isValidHexAddress)(cachedAddress, { allowNonPrefixed: false }) &&
|
|
11
|
-
(0, controller_utils_1.isEqualCaseInsensitive)(cachedAddress, address));
|
|
12
|
-
return matchingAddress ? statusMap[matchingAddress] : undefined;
|
|
13
|
-
};
|
|
14
|
-
exports.getWalletComplianceStatus = getWalletComplianceStatus;
|
|
15
|
-
//# sourceMappingURL=utils.cjs.map
|
package/dist/utils.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA,iEAGoC;AAI7B,MAAM,yBAAyB,GAAG,CACvC,SAAiD,EACjD,OAAe,EACqB,EAAE;IACtC,MAAM,UAAU,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC;IAEtC,IAAI,UAAU,IAAI,CAAC,IAAA,oCAAiB,EAAC,OAAO,EAAE,EAAE,gBAAgB,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;QAC3E,OAAO,UAAU,CAAC;IACpB,CAAC;IAED,MAAM,eAAe,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,CACjD,CAAC,aAAa,EAAE,EAAE,CAChB,IAAA,oCAAiB,EAAC,aAAa,EAAE,EAAE,gBAAgB,EAAE,KAAK,EAAE,CAAC;QAC7D,IAAA,yCAAsB,EAAC,aAAa,EAAE,OAAO,CAAC,CACjD,CAAC;IAEF,OAAO,eAAe,CAAC,CAAC,CAAC,SAAS,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAClE,CAAC,CAAC;AAjBW,QAAA,yBAAyB,6BAiBpC","sourcesContent":["import {\n isEqualCaseInsensitive,\n isValidHexAddress,\n} from '@metamask/controller-utils';\n\nimport type { WalletComplianceStatus } from './types';\n\nexport const getWalletComplianceStatus = (\n statusMap: Record<string, WalletComplianceStatus>,\n address: string,\n): WalletComplianceStatus | undefined => {\n const exactMatch = statusMap[address];\n\n if (exactMatch || !isValidHexAddress(address, { allowNonPrefixed: false })) {\n return exactMatch;\n }\n\n const matchingAddress = Object.keys(statusMap).find(\n (cachedAddress) =>\n isValidHexAddress(cachedAddress, { allowNonPrefixed: false }) &&\n isEqualCaseInsensitive(cachedAddress, address),\n );\n\n return matchingAddress ? statusMap[matchingAddress] : undefined;\n};\n"]}
|
package/dist/utils.d.cts
DELETED
package/dist/utils.d.cts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.cts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,sBAAsB,EAAE,oBAAgB;AAEtD,eAAO,MAAM,yBAAyB,cACzB,OAAO,MAAM,EAAE,sBAAsB,CAAC,WACxC,MAAM,KACd,sBAAsB,GAAG,SAc3B,CAAC"}
|
package/dist/utils.d.mts
DELETED
package/dist/utils.d.mts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.mts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,sBAAsB,EAAE,oBAAgB;AAEtD,eAAO,MAAM,yBAAyB,cACzB,OAAO,MAAM,EAAE,sBAAsB,CAAC,WACxC,MAAM,KACd,sBAAsB,GAAG,SAc3B,CAAC"}
|
package/dist/utils.mjs
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { isEqualCaseInsensitive, isValidHexAddress } from "@metamask/controller-utils";
|
|
2
|
-
export const getWalletComplianceStatus = (statusMap, address) => {
|
|
3
|
-
const exactMatch = statusMap[address];
|
|
4
|
-
if (exactMatch || !isValidHexAddress(address, { allowNonPrefixed: false })) {
|
|
5
|
-
return exactMatch;
|
|
6
|
-
}
|
|
7
|
-
const matchingAddress = Object.keys(statusMap).find((cachedAddress) => isValidHexAddress(cachedAddress, { allowNonPrefixed: false }) &&
|
|
8
|
-
isEqualCaseInsensitive(cachedAddress, address));
|
|
9
|
-
return matchingAddress ? statusMap[matchingAddress] : undefined;
|
|
10
|
-
};
|
|
11
|
-
//# sourceMappingURL=utils.mjs.map
|
package/dist/utils.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,iBAAiB,EAClB,mCAAmC;AAIpC,MAAM,CAAC,MAAM,yBAAyB,GAAG,CACvC,SAAiD,EACjD,OAAe,EACqB,EAAE;IACtC,MAAM,UAAU,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC;IAEtC,IAAI,UAAU,IAAI,CAAC,iBAAiB,CAAC,OAAO,EAAE,EAAE,gBAAgB,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;QAC3E,OAAO,UAAU,CAAC;IACpB,CAAC;IAED,MAAM,eAAe,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,CACjD,CAAC,aAAa,EAAE,EAAE,CAChB,iBAAiB,CAAC,aAAa,EAAE,EAAE,gBAAgB,EAAE,KAAK,EAAE,CAAC;QAC7D,sBAAsB,CAAC,aAAa,EAAE,OAAO,CAAC,CACjD,CAAC;IAEF,OAAO,eAAe,CAAC,CAAC,CAAC,SAAS,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAClE,CAAC,CAAC","sourcesContent":["import {\n isEqualCaseInsensitive,\n isValidHexAddress,\n} from '@metamask/controller-utils';\n\nimport type { WalletComplianceStatus } from './types';\n\nexport const getWalletComplianceStatus = (\n statusMap: Record<string, WalletComplianceStatus>,\n address: string,\n): WalletComplianceStatus | undefined => {\n const exactMatch = statusMap[address];\n\n if (exactMatch || !isValidHexAddress(address, { allowNonPrefixed: false })) {\n return exactMatch;\n }\n\n const matchingAddress = Object.keys(statusMap).find(\n (cachedAddress) =>\n isValidHexAddress(cachedAddress, { allowNonPrefixed: false }) &&\n isEqualCaseInsensitive(cachedAddress, address),\n );\n\n return matchingAddress ? statusMap[matchingAddress] : undefined;\n};\n"]}
|