@metamask-previews/compliance-controller 2.1.0-preview-c61613ed2 → 2.1.0-preview-3866c0ff1
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 +1 -0
- package/dist/{ComplianceController-method-action-types.d.mts → ComplianceController-method-action-types.d.ts} +2 -2
- package/dist/ComplianceController-method-action-types.d.ts.map +1 -0
- package/dist/{ComplianceController-method-action-types.mjs → ComplianceController-method-action-types.js} +1 -1
- package/dist/ComplianceController-method-action-types.js.map +1 -0
- package/dist/{ComplianceController.d.cts → ComplianceController.d.ts} +7 -7
- package/dist/ComplianceController.d.ts.map +1 -0
- package/dist/{ComplianceController.mjs → ComplianceController.js} +3 -3
- package/dist/ComplianceController.js.map +1 -0
- package/dist/{ComplianceService-method-action-types.d.cts → ComplianceService-method-action-types.d.ts} +2 -2
- package/dist/ComplianceService-method-action-types.d.ts.map +1 -0
- package/dist/{ComplianceService-method-action-types.mjs → ComplianceService-method-action-types.js} +1 -1
- package/dist/ComplianceService-method-action-types.js.map +1 -0
- package/dist/{ComplianceService.d.mts → ComplianceService.d.ts} +6 -6
- package/dist/ComplianceService.d.ts.map +1 -0
- package/dist/{ComplianceService.mjs → ComplianceService.js} +39 -48
- package/dist/ComplianceService.js.map +1 -0
- package/dist/{index.d.cts → index.d.ts} +9 -9
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/{index.cjs.map → index.js.map} +1 -1
- package/dist/{selectors.d.mts → selectors.d.ts} +4 -4
- package/dist/selectors.d.ts.map +1 -0
- package/dist/{selectors.mjs → selectors.js} +3 -3
- package/dist/selectors.js.map +1 -0
- package/dist/{types.d.cts → types.d.ts} +1 -1
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/{utils.d.cts → utils.d.ts} +2 -2
- package/dist/utils.d.ts.map +1 -0
- package/dist/{utils.mjs → utils.js} +2 -2
- package/dist/utils.js.map +1 -0
- package/package.json +12 -16
- package/dist/ComplianceController-method-action-types.cjs +0 -7
- package/dist/ComplianceController-method-action-types.cjs.map +0 -1
- package/dist/ComplianceController-method-action-types.d.cts +0 -44
- package/dist/ComplianceController-method-action-types.d.cts.map +0 -1
- package/dist/ComplianceController-method-action-types.d.mts.map +0 -1
- package/dist/ComplianceController-method-action-types.mjs.map +0 -1
- package/dist/ComplianceController.cjs +0 -158
- package/dist/ComplianceController.cjs.map +0 -1
- package/dist/ComplianceController.d.cts.map +0 -1
- package/dist/ComplianceController.d.mts +0 -112
- package/dist/ComplianceController.d.mts.map +0 -1
- package/dist/ComplianceController.mjs.map +0 -1
- package/dist/ComplianceService-method-action-types.cjs +0 -7
- package/dist/ComplianceService-method-action-types.cjs.map +0 -1
- package/dist/ComplianceService-method-action-types.d.cts.map +0 -1
- package/dist/ComplianceService-method-action-types.d.mts +0 -30
- package/dist/ComplianceService-method-action-types.d.mts.map +0 -1
- package/dist/ComplianceService-method-action-types.mjs.map +0 -1
- package/dist/ComplianceService.cjs +0 -239
- package/dist/ComplianceService.cjs.map +0 -1
- package/dist/ComplianceService.d.cts +0 -184
- package/dist/ComplianceService.d.cts.map +0 -1
- package/dist/ComplianceService.d.mts.map +0 -1
- package/dist/ComplianceService.mjs.map +0 -1
- package/dist/index.cjs +0 -12
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.mts +0 -9
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs +0 -4
- package/dist/index.mjs.map +0 -1
- package/dist/selectors.cjs +0 -27
- package/dist/selectors.cjs.map +0 -1
- package/dist/selectors.d.cts +0 -20
- package/dist/selectors.d.cts.map +0 -1
- package/dist/selectors.d.mts.map +0 -1
- package/dist/selectors.mjs.map +0 -1
- package/dist/types.cjs +0 -3
- package/dist/types.cjs.map +0 -1
- package/dist/types.d.cts.map +0 -1
- package/dist/types.d.mts +0 -18
- package/dist/types.d.mts.map +0 -1
- package/dist/types.mjs +0 -2
- package/dist/types.mjs.map +0 -1
- package/dist/utils.cjs +0 -15
- package/dist/utils.cjs.map +0 -1
- 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.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
9
9
|
|
|
10
10
|
### Changed
|
|
11
11
|
|
|
12
|
+
- **BREAKING:** Bump minimum Node.js version to 22 ([#9168](https://github.com/MetaMask/core/pull/9168))
|
|
12
13
|
- Bump `@metamask/utils` from `^11.9.0` to `^11.11.0` ([#9074](https://github.com/MetaMask/core/pull/9074))
|
|
13
14
|
- Bump `@metamask/controller-utils` from `^12.1.0` to `^12.3.0` ([#9058](https://github.com/MetaMask/core/pull/9058), [#9083](https://github.com/MetaMask/core/pull/9083), [#9218](https://github.com/MetaMask/core/pull/9218))
|
|
14
15
|
- Bump `@metamask/messenger` from `^1.2.0` to `^2.0.0` ([#9392](https://github.com/MetaMask/core/pull/9392))
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* This file is auto generated.
|
|
3
3
|
* Do not edit manually.
|
|
4
4
|
*/
|
|
5
|
-
import type { ComplianceController } from
|
|
5
|
+
import type { ComplianceController } from './ComplianceController.js';
|
|
6
6
|
/**
|
|
7
7
|
* Checks compliance status for a single wallet address via the API and
|
|
8
8
|
* persists the result to state. If the API call fails and a previously
|
|
@@ -41,4 +41,4 @@ export type ComplianceControllerClearComplianceStateAction = {
|
|
|
41
41
|
* Union of all ComplianceController action types.
|
|
42
42
|
*/
|
|
43
43
|
export type ComplianceControllerMethodActions = ComplianceControllerCheckWalletComplianceAction | ComplianceControllerCheckWalletsComplianceAction | ComplianceControllerClearComplianceStateAction;
|
|
44
|
-
//# sourceMappingURL=ComplianceController-method-action-types.d.
|
|
44
|
+
//# sourceMappingURL=ComplianceController-method-action-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ComplianceController-method-action-types.d.ts","sourceRoot":"","sources":["../src/ComplianceController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEtE;;;;;;;;GAQG;AACH,MAAM,MAAM,+CAA+C,GAAG;IAC5D,IAAI,EAAE,4CAA4C,CAAC;IACnD,OAAO,EAAE,oBAAoB,CAAC,uBAAuB,CAAC,CAAC;CACxD,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,MAAM,gDAAgD,GAAG;IAC7D,IAAI,EAAE,6CAA6C,CAAC;IACpD,OAAO,EAAE,oBAAoB,CAAC,wBAAwB,CAAC,CAAC;CACzD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,8CAA8C,GAAG;IAC3D,IAAI,EAAE,2CAA2C,CAAC;IAClD,OAAO,EAAE,oBAAoB,CAAC,sBAAsB,CAAC,CAAC;CACvD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,iCAAiC,GACzC,+CAA+C,GAC/C,gDAAgD,GAChD,8CAA8C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ComplianceController-method-action-types.js","sourceRoot":"","sources":["../src/ComplianceController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { ComplianceController } from './ComplianceController.js';\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 */\nexport type ComplianceControllerCheckWalletComplianceAction = {\n type: `ComplianceController:checkWalletCompliance`;\n handler: ComplianceController['checkWalletCompliance'];\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 */\nexport type ComplianceControllerCheckWalletsComplianceAction = {\n type: `ComplianceController:checkWalletsCompliance`;\n handler: ComplianceController['checkWalletsCompliance'];\n};\n\n/**\n * Clears all compliance data from state.\n */\nexport type ComplianceControllerClearComplianceStateAction = {\n type: `ComplianceController:clearComplianceState`;\n handler: ComplianceController['clearComplianceState'];\n};\n\n/**\n * Union of all ComplianceController action types.\n */\nexport type ComplianceControllerMethodActions =\n | ComplianceControllerCheckWalletComplianceAction\n | ComplianceControllerCheckWalletsComplianceAction\n | ComplianceControllerClearComplianceStateAction;\n"]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { ControllerGetStateAction, ControllerStateChangeEvent } from
|
|
2
|
-
import { BaseController } from
|
|
3
|
-
import type { Messenger } from
|
|
4
|
-
import type { ComplianceControllerMethodActions } from
|
|
5
|
-
import type { ComplianceServiceCheckWalletComplianceAction, ComplianceServiceCheckWalletsComplianceAction } from
|
|
6
|
-
import type { WalletComplianceStatus } from
|
|
1
|
+
import type { ControllerGetStateAction, ControllerStateChangeEvent } from '@metamask/base-controller';
|
|
2
|
+
import { BaseController } from '@metamask/base-controller';
|
|
3
|
+
import type { Messenger } from '@metamask/messenger';
|
|
4
|
+
import type { ComplianceControllerMethodActions } from './ComplianceController-method-action-types.js';
|
|
5
|
+
import type { ComplianceServiceCheckWalletComplianceAction, ComplianceServiceCheckWalletsComplianceAction } from './ComplianceService-method-action-types.js';
|
|
6
|
+
import type { WalletComplianceStatus } from './types.js';
|
|
7
7
|
/**
|
|
8
8
|
* The name of the {@link ComplianceController}, used to namespace the
|
|
9
9
|
* controller's actions and events and to namespace the controller's state data
|
|
@@ -109,4 +109,4 @@ export declare class ComplianceController extends BaseController<typeof controll
|
|
|
109
109
|
clearComplianceState(): void;
|
|
110
110
|
}
|
|
111
111
|
export {};
|
|
112
|
-
//# sourceMappingURL=ComplianceController.d.
|
|
112
|
+
//# sourceMappingURL=ComplianceController.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ComplianceController.d.ts","sourceRoot":"","sources":["../src/ComplianceController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAErD,OAAO,KAAK,EAAE,iCAAiC,EAAE,MAAM,+CAA+C,CAAC;AACvG,OAAO,KAAK,EACV,4CAA4C,EAC5C,6CAA6C,EAC9C,MAAM,4CAA4C,CAAC;AACpD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAKzD;;;;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,IAAI,CAAC;CAC9B,CAAC;AAoBF;;;;;;;GAOG;AACH,wBAAgB,mCAAmC,IAAI,yBAAyB,CAK/E;AAUD;;GAEG;AACH,MAAM,MAAM,kCAAkC,GAAG,wBAAwB,CACvE,OAAO,cAAc,EACrB,yBAAyB,CAC1B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,2BAA2B,GACnC,kCAAkC,GAClC,iCAAiC,CAAC;AAEtC;;GAEG;AACH,KAAK,cAAc,GACf,4CAA4C,GAC5C,6CAA6C,CAAC;AAElD;;GAEG;AACH,MAAM,MAAM,oCAAoC,GAAG,0BAA0B,CAC3E,OAAO,cAAc,EACrB,yBAAyB,CAC1B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,0BAA0B,GAAG,oCAAoC,CAAC;AAE9E;;GAEG;AACH,KAAK,aAAa,GAAG,KAAK,CAAC;AAE3B;;;GAGG;AACH,MAAM,MAAM,6BAA6B,GAAG,SAAS,CACnD,OAAO,cAAc,EACrB,2BAA2B,GAAG,cAAc,EAC5C,0BAA0B,GAAG,aAAa,CAC3C,CAAC;AAIF;;;;;GAKG;AACH,qBAAa,oBAAqB,SAAQ,cAAc,CACtD,OAAO,cAAc,EACrB,yBAAyB,EACzB,6BAA6B,CAC9B;IACC;;;;;;;OAOG;IACH,YAAY,EACV,SAAS,EACT,KAAK,GACN,EAAE;QACD,SAAS,EAAE,6BAA6B,CAAC;QACzC,KAAK,CAAC,EAAE,OAAO,CAAC,yBAAyB,CAAC,CAAC;KAC5C,EAeA;IAED;;;;;;;;OAQG;IACG,qBAAqB,CACzB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,sBAAsB,CAAC,CA8BjC;IAED;;;;;;;;;OASG;IACG,sBAAsB,CAC1B,SAAS,EAAE,MAAM,EAAE,GAClB,OAAO,CAAC,sBAAsB,EAAE,CAAC,CAuCnC;IAED;;OAEG;IACH,oBAAoB,IAAI,IAAI,CAK3B;CACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { BaseController } from
|
|
2
|
-
import { getWalletComplianceStatus } from
|
|
1
|
+
import { BaseController } from '@metamask/base-controller';
|
|
2
|
+
import { getWalletComplianceStatus } from './utils.js';
|
|
3
3
|
// === GENERAL ===
|
|
4
4
|
/**
|
|
5
5
|
* The name of the {@link ComplianceController}, used to namespace the
|
|
@@ -150,4 +150,4 @@ export class ComplianceController extends BaseController {
|
|
|
150
150
|
});
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
|
-
//# sourceMappingURL=ComplianceController.
|
|
153
|
+
//# sourceMappingURL=ComplianceController.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ComplianceController.js","sourceRoot":"","sources":["../src/ComplianceController.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AAI,GAAG,GAAG,CAAC,EAAE,GAAG,GAAG,QAAQ,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE,CAAC;oBAC/C,MAAM,aAAa,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;oBACrC,UAAU,CAAC,yBAAyB,CAAC,aAAa,CAAC,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC;gBACtE,CAAC;gBACD,UAAU,CAAC,aAAa,GAAG,GAAG,CAAC;YACjC,CAAC,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,yBAAyB,CACvB,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","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.js';\nimport type {\n ComplianceServiceCheckWalletComplianceAction,\n ComplianceServiceCheckWalletsComplianceAction,\n} from './ComplianceService-method-action-types.js';\nimport type { WalletComplianceStatus } from './types.js';\nimport { getWalletComplianceStatus } from './utils.js';\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"]}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* This file is auto generated.
|
|
3
3
|
* Do not edit manually.
|
|
4
4
|
*/
|
|
5
|
-
import type { ComplianceService } from
|
|
5
|
+
import type { ComplianceService } from './ComplianceService.js';
|
|
6
6
|
/**
|
|
7
7
|
* Checks compliance status for a single wallet address.
|
|
8
8
|
*
|
|
@@ -27,4 +27,4 @@ export type ComplianceServiceCheckWalletsComplianceAction = {
|
|
|
27
27
|
* Union of all ComplianceService action types.
|
|
28
28
|
*/
|
|
29
29
|
export type ComplianceServiceMethodActions = ComplianceServiceCheckWalletComplianceAction | ComplianceServiceCheckWalletsComplianceAction;
|
|
30
|
-
//# sourceMappingURL=ComplianceService-method-action-types.d.
|
|
30
|
+
//# sourceMappingURL=ComplianceService-method-action-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ComplianceService-method-action-types.d.ts","sourceRoot":"","sources":["../src/ComplianceService-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAEhE;;;;;GAKG;AACH,MAAM,MAAM,4CAA4C,GAAG;IACzD,IAAI,EAAE,yCAAyC,CAAC;IAChD,OAAO,EAAE,iBAAiB,CAAC,uBAAuB,CAAC,CAAC;CACrD,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,6CAA6C,GAAG;IAC1D,IAAI,EAAE,0CAA0C,CAAC;IACjD,OAAO,EAAE,iBAAiB,CAAC,wBAAwB,CAAC,CAAC;CACtD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,8BAA8B,GACtC,4CAA4C,GAC5C,6CAA6C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ComplianceService-method-action-types.js","sourceRoot":"","sources":["../src/ComplianceService-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { ComplianceService } from './ComplianceService.js';\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 */\nexport type ComplianceServiceCheckWalletComplianceAction = {\n type: `ComplianceService:checkWalletCompliance`;\n handler: ComplianceService['checkWalletCompliance'];\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 */\nexport type ComplianceServiceCheckWalletsComplianceAction = {\n type: `ComplianceService:checkWalletsCompliance`;\n handler: ComplianceService['checkWalletsCompliance'];\n};\n\n/**\n * Union of all ComplianceService action types.\n */\nexport type ComplianceServiceMethodActions =\n | ComplianceServiceCheckWalletComplianceAction\n | ComplianceServiceCheckWalletsComplianceAction;\n"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { CreateServicePolicyOptions, ServicePolicy } from
|
|
2
|
-
import type { Messenger } from
|
|
3
|
-
import type { Infer } from
|
|
4
|
-
import type { IDisposable } from
|
|
5
|
-
import type { ComplianceServiceMethodActions } from
|
|
1
|
+
import type { CreateServicePolicyOptions, ServicePolicy } from '@metamask/controller-utils';
|
|
2
|
+
import type { Messenger } from '@metamask/messenger';
|
|
3
|
+
import type { Infer } from '@metamask/superstruct';
|
|
4
|
+
import type { IDisposable } from 'cockatiel';
|
|
5
|
+
import type { ComplianceServiceMethodActions } from './ComplianceService-method-action-types.js';
|
|
6
6
|
/**
|
|
7
7
|
* The name of the {@link ComplianceService}, used to namespace the service's
|
|
8
8
|
* actions and events.
|
|
@@ -181,4 +181,4 @@ export declare class ComplianceService {
|
|
|
181
181
|
checkWalletsCompliance(addresses: string[]): Promise<BatchWalletCheckResponseItem[]>;
|
|
182
182
|
}
|
|
183
183
|
export {};
|
|
184
|
-
//# sourceMappingURL=ComplianceService.d.
|
|
184
|
+
//# sourceMappingURL=ComplianceService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ComplianceService.d.ts","sourceRoot":"","sources":["../src/ComplianceService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,0BAA0B,EAC1B,aAAa,EACd,MAAM,4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AC1C,CAAC;AAIF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,qBAAa,iBAAiB;;IAC5B;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,OAAO,WAAW,CAAC;IA0BlC;;;;;;;;;;;OAWG;IACH,YAAY,EACV,SAAS,EACT,KAAK,EAAE,aAAa,EACpB,MAAM,EACN,GAAkB,EAClB,aAAkB,GACnB,EAAE,wBAAwB,EAW1B;IAED;;;;;;;OAOG;IACH,OAAO,CAAC,QAAQ,EAAE,UAAU,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,WAAW,CAEtE;IAED;;;;;;;OAOG;IACH,OAAO,CAAC,QAAQ,EAAE,UAAU,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,WAAW,CAEtE;IAED;;;;;;;OAOG;IACH,UAAU,CACR,QAAQ,EAAE,UAAU,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,GACnD,WAAW,CAEb;IAED;;;;;OAKG;IACG,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAsBzE;IAED;;;;;OAKG;IACG,sBAAsB,CAC1B,SAAS,EAAE,MAAM,EAAE,GAClB,OAAO,CAAC,4BAA4B,EAAE,CAAC,CAuBzC;CACF"}
|
|
@@ -1,17 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
-
};
|
|
7
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
-
};
|
|
12
|
-
var _a, _ComplianceService_messenger, _ComplianceService_fetch, _ComplianceService_complianceApiUrl, _ComplianceService_policy;
|
|
13
|
-
import { createServicePolicy, HttpError } from "@metamask/controller-utils";
|
|
14
|
-
import { array, boolean, object, string } from "@metamask/superstruct";
|
|
1
|
+
import { createServicePolicy, HttpError } from '@metamask/controller-utils';
|
|
2
|
+
import { array, boolean, object, string } from '@metamask/superstruct';
|
|
15
3
|
// === GENERAL ===
|
|
16
4
|
/**
|
|
17
5
|
* The name of the {@link ComplianceService}, used to namespace the service's
|
|
@@ -84,6 +72,28 @@ const BatchWalletCheckResponseItemStruct = WalletCheckResponseStruct;
|
|
|
84
72
|
* ```
|
|
85
73
|
*/
|
|
86
74
|
export class ComplianceService {
|
|
75
|
+
/**
|
|
76
|
+
* The name of the service.
|
|
77
|
+
*/
|
|
78
|
+
name;
|
|
79
|
+
/**
|
|
80
|
+
* The messenger suited for this service.
|
|
81
|
+
*/
|
|
82
|
+
#messenger;
|
|
83
|
+
/**
|
|
84
|
+
* A function that can be used to make an HTTP request.
|
|
85
|
+
*/
|
|
86
|
+
#fetch;
|
|
87
|
+
/**
|
|
88
|
+
* The resolved base URL for the Compliance API.
|
|
89
|
+
*/
|
|
90
|
+
#complianceApiUrl;
|
|
91
|
+
/**
|
|
92
|
+
* The policy that wraps each request.
|
|
93
|
+
*
|
|
94
|
+
* @see {@link createServicePolicy}
|
|
95
|
+
*/
|
|
96
|
+
#policy;
|
|
87
97
|
/**
|
|
88
98
|
* Constructs a new ComplianceService object.
|
|
89
99
|
*
|
|
@@ -97,30 +107,12 @@ export class ComplianceService {
|
|
|
97
107
|
* is used to wrap each request. See {@link CreateServicePolicyOptions}.
|
|
98
108
|
*/
|
|
99
109
|
constructor({ messenger, fetch: fetchFunction, apiUrl, env = 'production', policyOptions = {}, }) {
|
|
100
|
-
/**
|
|
101
|
-
* The messenger suited for this service.
|
|
102
|
-
*/
|
|
103
|
-
_ComplianceService_messenger.set(this, void 0);
|
|
104
|
-
/**
|
|
105
|
-
* A function that can be used to make an HTTP request.
|
|
106
|
-
*/
|
|
107
|
-
_ComplianceService_fetch.set(this, void 0);
|
|
108
|
-
/**
|
|
109
|
-
* The resolved base URL for the Compliance API.
|
|
110
|
-
*/
|
|
111
|
-
_ComplianceService_complianceApiUrl.set(this, void 0);
|
|
112
|
-
/**
|
|
113
|
-
* The policy that wraps each request.
|
|
114
|
-
*
|
|
115
|
-
* @see {@link createServicePolicy}
|
|
116
|
-
*/
|
|
117
|
-
_ComplianceService_policy.set(this, void 0);
|
|
118
110
|
this.name = serviceName;
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
111
|
+
this.#messenger = messenger;
|
|
112
|
+
this.#fetch = fetchFunction;
|
|
113
|
+
this.#complianceApiUrl = getComplianceApiUrl({ apiUrl, env });
|
|
114
|
+
this.#policy = createServicePolicy(policyOptions);
|
|
115
|
+
this.#messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
124
116
|
}
|
|
125
117
|
/**
|
|
126
118
|
* Registers a handler that will be called after a request returns a non-500
|
|
@@ -131,7 +123,7 @@ export class ComplianceService {
|
|
|
131
123
|
* @see {@link createServicePolicy}
|
|
132
124
|
*/
|
|
133
125
|
onRetry(listener) {
|
|
134
|
-
return
|
|
126
|
+
return this.#policy.onRetry(listener);
|
|
135
127
|
}
|
|
136
128
|
/**
|
|
137
129
|
* Registers a handler that will be called after a set number of retry rounds
|
|
@@ -142,7 +134,7 @@ export class ComplianceService {
|
|
|
142
134
|
* @see {@link createServicePolicy}
|
|
143
135
|
*/
|
|
144
136
|
onBreak(listener) {
|
|
145
|
-
return
|
|
137
|
+
return this.#policy.onBreak(listener);
|
|
146
138
|
}
|
|
147
139
|
/**
|
|
148
140
|
* Registers a handler that will be called when the service is degraded due
|
|
@@ -153,7 +145,7 @@ export class ComplianceService {
|
|
|
153
145
|
* @see {@link createServicePolicy}
|
|
154
146
|
*/
|
|
155
147
|
onDegraded(listener) {
|
|
156
|
-
return
|
|
148
|
+
return this.#policy.onDegraded(listener);
|
|
157
149
|
}
|
|
158
150
|
/**
|
|
159
151
|
* Checks compliance status for a single wallet address.
|
|
@@ -162,9 +154,9 @@ export class ComplianceService {
|
|
|
162
154
|
* @returns The compliance status of the wallet.
|
|
163
155
|
*/
|
|
164
156
|
async checkWalletCompliance(address) {
|
|
165
|
-
const response = await
|
|
166
|
-
const url = new URL(`v1/wallet/${encodeURIComponent(address)}`,
|
|
167
|
-
const localResponse = await
|
|
157
|
+
const response = await this.#policy.execute(async () => {
|
|
158
|
+
const url = new URL(`v1/wallet/${encodeURIComponent(address)}`, this.#complianceApiUrl);
|
|
159
|
+
const localResponse = await this.#fetch(url);
|
|
168
160
|
if (!localResponse.ok) {
|
|
169
161
|
throw new HttpError(localResponse.status, `Fetching '${url.toString()}' failed with status '${localResponse.status}'`);
|
|
170
162
|
}
|
|
@@ -180,9 +172,9 @@ export class ComplianceService {
|
|
|
180
172
|
* @returns The compliance statuses of the wallets.
|
|
181
173
|
*/
|
|
182
174
|
async checkWalletsCompliance(addresses) {
|
|
183
|
-
const response = await
|
|
184
|
-
const url = new URL('v1/wallet/batch',
|
|
185
|
-
const localResponse = await
|
|
175
|
+
const response = await this.#policy.execute(async () => {
|
|
176
|
+
const url = new URL('v1/wallet/batch', this.#complianceApiUrl);
|
|
177
|
+
const localResponse = await this.#fetch(url, {
|
|
186
178
|
method: 'POST',
|
|
187
179
|
headers: { 'Content-Type': 'application/json' },
|
|
188
180
|
body: JSON.stringify(addresses),
|
|
@@ -196,7 +188,6 @@ export class ComplianceService {
|
|
|
196
188
|
return validateResponse(jsonResponse, array(BatchWalletCheckResponseItemStruct), 'compliance batch check API');
|
|
197
189
|
}
|
|
198
190
|
}
|
|
199
|
-
_a = ComplianceService, _ComplianceService_messenger = new WeakMap(), _ComplianceService_fetch = new WeakMap(), _ComplianceService_complianceApiUrl = new WeakMap(), _ComplianceService_policy = new WeakMap();
|
|
200
191
|
function getComplianceApiUrl({ apiUrl, env, }) {
|
|
201
192
|
if (apiUrl === undefined) {
|
|
202
193
|
return COMPLIANCE_API_URLS[env];
|
|
@@ -232,4 +223,4 @@ function validateResponse(data, struct, apiName) {
|
|
|
232
223
|
}
|
|
233
224
|
throw new Error(`Malformed response received from ${apiName}`);
|
|
234
225
|
}
|
|
235
|
-
//# sourceMappingURL=ComplianceService.
|
|
226
|
+
//# sourceMappingURL=ComplianceService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ComplianceService.js","sourceRoot":"","sources":["../src/ComplianceService.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAG5E,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAKvE,kBAAkB;AAElB;;;GAGG;AACH,MAAM,CAAC,MAAM,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,MAAM,CAAC;IACvC,OAAO,EAAE,MAAM,EAAE;IACjB,OAAO,EAAE,OAAO,EAAE;CACnB,CAAC,CAAC;AAOH;;;GAGG;AACH,MAAM,kCAAkC,GAAG,yBAAyB,CAAC;AASrE,6BAA6B;AAE7B;;;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\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.js';\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,9 +1,9 @@
|
|
|
1
|
-
export type { ComplianceServiceActions, ComplianceServiceEnvironment, ComplianceServiceEvents, ComplianceServiceMessenger, ComplianceServiceOptions, } from
|
|
2
|
-
export type { ComplianceServiceCheckWalletComplianceAction, ComplianceServiceCheckWalletsComplianceAction, } from
|
|
3
|
-
export { ComplianceService } from
|
|
4
|
-
export type { ComplianceControllerActions, ComplianceControllerEvents, ComplianceControllerGetStateAction, ComplianceControllerMessenger, ComplianceControllerState, ComplianceControllerStateChangeEvent, } from
|
|
5
|
-
export type { ComplianceControllerCheckWalletComplianceAction, ComplianceControllerCheckWalletsComplianceAction, ComplianceControllerClearComplianceStateAction, } from
|
|
6
|
-
export { ComplianceController, getDefaultComplianceControllerState, } from
|
|
7
|
-
export { selectAreAnyWalletsBlocked, selectIsWalletBlocked, } from
|
|
8
|
-
export type { WalletComplianceStatus } from
|
|
9
|
-
//# sourceMappingURL=index.d.
|
|
1
|
+
export type { ComplianceServiceActions, ComplianceServiceEnvironment, ComplianceServiceEvents, ComplianceServiceMessenger, ComplianceServiceOptions, } from './ComplianceService.js';
|
|
2
|
+
export type { ComplianceServiceCheckWalletComplianceAction, ComplianceServiceCheckWalletsComplianceAction, } from './ComplianceService-method-action-types.js';
|
|
3
|
+
export { ComplianceService } from './ComplianceService.js';
|
|
4
|
+
export type { ComplianceControllerActions, ComplianceControllerEvents, ComplianceControllerGetStateAction, ComplianceControllerMessenger, ComplianceControllerState, ComplianceControllerStateChangeEvent, } from './ComplianceController.js';
|
|
5
|
+
export type { ComplianceControllerCheckWalletComplianceAction, ComplianceControllerCheckWalletsComplianceAction, ComplianceControllerClearComplianceStateAction, } from './ComplianceController-method-action-types.js';
|
|
6
|
+
export { ComplianceController, getDefaultComplianceControllerState, } from './ComplianceController.js';
|
|
7
|
+
export { selectAreAnyWalletsBlocked, selectIsWalletBlocked, } from './selectors.js';
|
|
8
|
+
export type { WalletComplianceStatus } from './types.js';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,wBAAwB,EACxB,4BAA4B,EAC5B,uBAAuB,EACvB,0BAA0B,EAC1B,wBAAwB,GACzB,MAAM,wBAAwB,CAAC;AAChC,YAAY,EACV,4CAA4C,EAC5C,6CAA6C,GAC9C,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,YAAY,EACV,2BAA2B,EAC3B,0BAA0B,EAC1B,kCAAkC,EAClC,6BAA6B,EAC7B,yBAAyB,EACzB,oCAAoC,GACrC,MAAM,2BAA2B,CAAC;AACnC,YAAY,EACV,+CAA+C,EAC/C,gDAAgD,EAChD,8CAA8C,GAC/C,MAAM,+CAA+C,CAAC;AACvD,OAAO,EACL,oBAAoB,EACpB,mCAAmC,GACpC,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,0BAA0B,EAC1B,qBAAqB,GACtB,MAAM,gBAAgB,CAAC;AACxB,YAAY,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { ComplianceService } from './ComplianceService.js';
|
|
2
|
+
export { ComplianceController, getDefaultComplianceControllerState, } from './ComplianceController.js';
|
|
3
|
+
export { selectAreAnyWalletsBlocked, selectIsWalletBlocked, } from './selectors.js';
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAc3D,OAAO,EACL,oBAAoB,EACpB,mCAAmC,GACpC,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,0BAA0B,EAC1B,qBAAqB,GACtB,MAAM,gBAAgB,CAAC","sourcesContent":["export type {\n ComplianceServiceActions,\n ComplianceServiceEnvironment,\n ComplianceServiceEvents,\n ComplianceServiceMessenger,\n ComplianceServiceOptions,\n} from './ComplianceService.js';\nexport type {\n ComplianceServiceCheckWalletComplianceAction,\n ComplianceServiceCheckWalletsComplianceAction,\n} from './ComplianceService-method-action-types.js';\nexport { ComplianceService } from './ComplianceService.js';\nexport type {\n ComplianceControllerActions,\n ComplianceControllerEvents,\n ComplianceControllerGetStateAction,\n ComplianceControllerMessenger,\n ComplianceControllerState,\n ComplianceControllerStateChangeEvent,\n} from './ComplianceController.js';\nexport type {\n ComplianceControllerCheckWalletComplianceAction,\n ComplianceControllerCheckWalletsComplianceAction,\n ComplianceControllerClearComplianceStateAction,\n} from './ComplianceController-method-action-types.js';\nexport {\n ComplianceController,\n getDefaultComplianceControllerState,\n} from './ComplianceController.js';\nexport {\n selectAreAnyWalletsBlocked,\n selectIsWalletBlocked,\n} from './selectors.js';\nexport type { WalletComplianceStatus } from './types.js';\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ComplianceControllerState } from
|
|
1
|
+
import type { ComplianceControllerState } from './ComplianceController.js';
|
|
2
2
|
/**
|
|
3
3
|
* Creates a selector that returns whether a wallet address is blocked, based
|
|
4
4
|
* on the per-address compliance status cache.
|
|
@@ -7,7 +7,7 @@ import type { ComplianceControllerState } from "./ComplianceController.mjs";
|
|
|
7
7
|
* @returns A selector that takes `ComplianceControllerState` and returns
|
|
8
8
|
* `true` if the wallet is blocked, `false` otherwise.
|
|
9
9
|
*/
|
|
10
|
-
export declare const selectIsWalletBlocked: (address: string) => (state: ComplianceControllerState) => boolean;
|
|
10
|
+
export declare const selectIsWalletBlocked: (address: string) => ((state: ComplianceControllerState) => boolean);
|
|
11
11
|
/**
|
|
12
12
|
* Creates a selector that returns whether any wallet address is blocked, based
|
|
13
13
|
* on the per-address compliance status cache.
|
|
@@ -16,5 +16,5 @@ export declare const selectIsWalletBlocked: (address: string) => (state: Complia
|
|
|
16
16
|
* @returns A selector that takes `ComplianceControllerState` and returns
|
|
17
17
|
* `true` if any wallet is blocked, `false` otherwise.
|
|
18
18
|
*/
|
|
19
|
-
export declare const selectAreAnyWalletsBlocked: (addresses: string[]) => (state: ComplianceControllerState) => boolean;
|
|
20
|
-
//# sourceMappingURL=selectors.d.
|
|
19
|
+
export declare const selectAreAnyWalletsBlocked: (addresses: string[]) => ((state: ComplianceControllerState) => boolean);
|
|
20
|
+
//# sourceMappingURL=selectors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selectors.d.ts","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AAQ3E;;;;;;;GAOG;AACH,eAAO,MAAM,qBAAqB,YACvB,MAAM,KACd,CAAC,CAAC,KAAK,EAAE,yBAAyB,KAAK,OAAO,CAK9C,CAAC;AAEJ;;;;;;;GAOG;AACH,eAAO,MAAM,0BAA0B,cAC1B,MAAM,EAAE,KAClB,CAAC,CAAC,KAAK,EAAE,yBAAyB,KAAK,OAAO,CAK9C,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { createSelector } from
|
|
2
|
-
import { getWalletComplianceStatus } from
|
|
1
|
+
import { createSelector } from 'reselect';
|
|
2
|
+
import { getWalletComplianceStatus } from './utils.js';
|
|
3
3
|
const selectWalletComplianceStatusMap = (state) => state.walletComplianceStatusMap;
|
|
4
4
|
/**
|
|
5
5
|
* Creates a selector that returns whether a wallet address is blocked, based
|
|
@@ -19,4 +19,4 @@ export const selectIsWalletBlocked = (address) => createSelector([selectWalletCo
|
|
|
19
19
|
* `true` if any wallet is blocked, `false` otherwise.
|
|
20
20
|
*/
|
|
21
21
|
export const selectAreAnyWalletsBlocked = (addresses) => createSelector([selectWalletComplianceStatusMap], (statusMap) => addresses.some((address) => getWalletComplianceStatus(statusMap, address)?.blocked));
|
|
22
|
-
//# sourceMappingURL=selectors.
|
|
22
|
+
//# sourceMappingURL=selectors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selectors.js","sourceRoot":"","sources":["../src/selectors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAG1C,OAAO,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAEvD,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,CACrB,yBAAyB,CAAC,SAAS,EAAE,OAAO,CAAC,EAAE,OAAO,IAAI,KAAK,CAClE,CAAC;AAEJ;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,CACxC,SAAmB,EAC8B,EAAE,CACnD,cAAc,CAAC,CAAC,+BAA+B,CAAC,EAAE,CAAC,SAAS,EAAW,EAAE,CACvE,SAAS,CAAC,IAAI,CACZ,CAAC,OAAO,EAAE,EAAE,CAAC,yBAAyB,CAAC,SAAS,EAAE,OAAO,CAAC,EAAE,OAAO,CACpE,CACF,CAAC","sourcesContent":["import { createSelector } from 'reselect';\n\nimport type { ComplianceControllerState } from './ComplianceController.js';\nimport { getWalletComplianceStatus } from './utils.js';\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 =>\n getWalletComplianceStatus(statusMap, address)?.blocked ?? false,\n );\n\n/**\n * Creates a selector that returns whether any wallet address is blocked, based\n * on the per-address compliance status cache.\n *\n * @param addresses - The wallet addresses to check.\n * @returns A selector that takes `ComplianceControllerState` and returns\n * `true` if any wallet is blocked, `false` otherwise.\n */\nexport const selectAreAnyWalletsBlocked = (\n addresses: string[],\n): ((state: ComplianceControllerState) => boolean) =>\n createSelector([selectWalletComplianceStatusMap], (statusMap): boolean =>\n addresses.some(\n (address) => getWalletComplianceStatus(statusMap, address)?.blocked,\n ),\n );\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;IAEjB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * The result of checking a single wallet address for compliance.\n */\nexport type WalletComplianceStatus = {\n /**\n * The wallet address that was checked.\n */\n address: string;\n\n /**\n * Whether the wallet address is blocked.\n */\n blocked: boolean;\n\n /**\n * The date/time (in ISO-8601 format) when this check was performed.\n */\n checkedAt: string;\n};\n"]}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { WalletComplianceStatus } from
|
|
1
|
+
import type { WalletComplianceStatus } from './types.js';
|
|
2
2
|
export declare const getWalletComplianceStatus: (statusMap: Record<string, WalletComplianceStatus>, address: string) => WalletComplianceStatus | undefined;
|
|
3
|
-
//# sourceMappingURL=utils.d.
|
|
3
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAEzD,eAAO,MAAM,yBAAyB,cACzB,MAAM,CAAC,MAAM,EAAE,sBAAsB,CAAC,WACxC,MAAM,KACd,sBAAsB,GAAG,SAc3B,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isEqualCaseInsensitive, isValidHexAddress } from
|
|
1
|
+
import { isEqualCaseInsensitive, isValidHexAddress, } from '@metamask/controller-utils';
|
|
2
2
|
export const getWalletComplianceStatus = (statusMap, address) => {
|
|
3
3
|
const exactMatch = statusMap[address];
|
|
4
4
|
if (exactMatch || !isValidHexAddress(address, { allowNonPrefixed: false })) {
|
|
@@ -8,4 +8,4 @@ export const getWalletComplianceStatus = (statusMap, address) => {
|
|
|
8
8
|
isEqualCaseInsensitive(cachedAddress, address));
|
|
9
9
|
return matchingAddress ? statusMap[matchingAddress] : undefined;
|
|
10
10
|
};
|
|
11
|
-
//# sourceMappingURL=utils.
|
|
11
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,iBAAiB,GAClB,MAAM,4BAA4B,CAAC;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.js';\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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/compliance-controller",
|
|
3
|
-
"version": "2.1.0-preview-
|
|
3
|
+
"version": "2.1.0-preview-3866c0ff1",
|
|
4
4
|
"description": "Manages OFAC compliance checks for wallet addresses",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ethereum",
|
|
@@ -18,19 +18,12 @@
|
|
|
18
18
|
"files": [
|
|
19
19
|
"dist/"
|
|
20
20
|
],
|
|
21
|
+
"type": "module",
|
|
21
22
|
"sideEffects": false,
|
|
22
|
-
"main": "./dist/index.cjs",
|
|
23
|
-
"types": "./dist/index.d.cts",
|
|
24
23
|
"exports": {
|
|
25
24
|
".": {
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
"default": "./dist/index.mjs"
|
|
29
|
-
},
|
|
30
|
-
"require": {
|
|
31
|
-
"types": "./dist/index.d.cts",
|
|
32
|
-
"default": "./dist/index.cjs"
|
|
33
|
-
}
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"default": "./dist/index.js"
|
|
34
27
|
},
|
|
35
28
|
"./package.json": "./package.json"
|
|
36
29
|
},
|
|
@@ -39,9 +32,11 @@
|
|
|
39
32
|
"registry": "https://registry.npmjs.org/"
|
|
40
33
|
},
|
|
41
34
|
"scripts": {
|
|
42
|
-
"build": "
|
|
43
|
-
"build:all": "
|
|
35
|
+
"build": "tsc --project tsconfig.build.json",
|
|
36
|
+
"build:all": "tsc --build tsconfig.build.json --verbose",
|
|
37
|
+
"build:clean": "yarn build:only-clean && yarn build",
|
|
44
38
|
"build:docs": "typedoc",
|
|
39
|
+
"build:only-clean": "rimraf './dist' './tsconfig.build.tsbuildinfo'",
|
|
45
40
|
"changelog:update": "../../scripts/update-changelog.sh @metamask/compliance-controller",
|
|
46
41
|
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/compliance-controller",
|
|
47
42
|
"lint:tsconfigs": "tsx ../../scripts/lint-tsconfigs/lint-tsconfigs.mts",
|
|
@@ -64,18 +59,19 @@
|
|
|
64
59
|
},
|
|
65
60
|
"devDependencies": {
|
|
66
61
|
"@metamask/auto-changelog": "^6.1.0",
|
|
67
|
-
"@ts-bridge/cli": "^0.6.4",
|
|
68
62
|
"@types/jest": "^30.0.0",
|
|
63
|
+
"@typescript/native": "npm:typescript@^7.0.2",
|
|
69
64
|
"deepmerge": "^4.2.2",
|
|
70
65
|
"jest": "^30.4.2",
|
|
71
66
|
"nock": "^13.3.1",
|
|
67
|
+
"rimraf": "^5.0.5",
|
|
72
68
|
"ts-jest": "^29.4.11",
|
|
73
69
|
"tsx": "^4.20.5",
|
|
74
70
|
"typedoc": "^0.25.13",
|
|
75
71
|
"typedoc-plugin-missing-exports": "^2.0.0",
|
|
76
|
-
"typescript": "
|
|
72
|
+
"typescript": "npm:@typescript/typescript6@^6.0.2"
|
|
77
73
|
},
|
|
78
74
|
"engines": {
|
|
79
|
-
"node": "^
|
|
75
|
+
"node": "^22.14.0 || ^24"
|
|
80
76
|
}
|
|
81
77
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ComplianceController-method-action-types.cjs","sourceRoot":"","sources":["../src/ComplianceController-method-action-types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { ComplianceController } from './ComplianceController.js';\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 */\nexport type ComplianceControllerCheckWalletComplianceAction = {\n type: `ComplianceController:checkWalletCompliance`;\n handler: ComplianceController['checkWalletCompliance'];\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 */\nexport type ComplianceControllerCheckWalletsComplianceAction = {\n type: `ComplianceController:checkWalletsCompliance`;\n handler: ComplianceController['checkWalletsCompliance'];\n};\n\n/**\n * Clears all compliance data from state.\n */\nexport type ComplianceControllerClearComplianceStateAction = {\n type: `ComplianceController:clearComplianceState`;\n handler: ComplianceController['clearComplianceState'];\n};\n\n/**\n * Union of all ComplianceController action types.\n */\nexport type ComplianceControllerMethodActions =\n | ComplianceControllerCheckWalletComplianceAction\n | ComplianceControllerCheckWalletsComplianceAction\n | ComplianceControllerClearComplianceStateAction;\n"]}
|