@metamask-previews/compliance-controller 2.1.0-preview-3866c0ff1 → 2.1.0-preview-e3275932a

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.
Files changed (83) hide show
  1. package/CHANGELOG.md +0 -1
  2. package/dist/ComplianceController-method-action-types.cjs +7 -0
  3. package/dist/ComplianceController-method-action-types.cjs.map +1 -0
  4. package/dist/{ComplianceController-method-action-types.d.ts → ComplianceController-method-action-types.d.cts} +2 -2
  5. package/dist/ComplianceController-method-action-types.d.cts.map +1 -0
  6. package/dist/ComplianceController-method-action-types.d.mts +44 -0
  7. package/dist/ComplianceController-method-action-types.d.mts.map +1 -0
  8. package/dist/{ComplianceController-method-action-types.js → ComplianceController-method-action-types.mjs} +1 -1
  9. package/dist/ComplianceController-method-action-types.mjs.map +1 -0
  10. package/dist/ComplianceController.cjs +158 -0
  11. package/dist/ComplianceController.cjs.map +1 -0
  12. package/dist/{ComplianceController.d.ts → ComplianceController.d.cts} +7 -7
  13. package/dist/ComplianceController.d.cts.map +1 -0
  14. package/dist/ComplianceController.d.mts +112 -0
  15. package/dist/ComplianceController.d.mts.map +1 -0
  16. package/dist/{ComplianceController.js → ComplianceController.mjs} +3 -3
  17. package/dist/ComplianceController.mjs.map +1 -0
  18. package/dist/ComplianceService-method-action-types.cjs +7 -0
  19. package/dist/ComplianceService-method-action-types.cjs.map +1 -0
  20. package/dist/{ComplianceService-method-action-types.d.ts → ComplianceService-method-action-types.d.cts} +2 -2
  21. package/dist/ComplianceService-method-action-types.d.cts.map +1 -0
  22. package/dist/ComplianceService-method-action-types.d.mts +30 -0
  23. package/dist/ComplianceService-method-action-types.d.mts.map +1 -0
  24. package/dist/{ComplianceService-method-action-types.js → ComplianceService-method-action-types.mjs} +1 -1
  25. package/dist/ComplianceService-method-action-types.mjs.map +1 -0
  26. package/dist/ComplianceService.cjs +239 -0
  27. package/dist/ComplianceService.cjs.map +1 -0
  28. package/dist/{ComplianceService.d.ts → ComplianceService.d.cts} +6 -6
  29. package/dist/ComplianceService.d.cts.map +1 -0
  30. package/dist/ComplianceService.d.mts +184 -0
  31. package/dist/ComplianceService.d.mts.map +1 -0
  32. package/dist/{ComplianceService.js → ComplianceService.mjs} +48 -39
  33. package/dist/ComplianceService.mjs.map +1 -0
  34. package/dist/index.cjs +12 -0
  35. package/dist/{index.js.map → index.cjs.map} +1 -1
  36. package/dist/{index.d.ts → index.d.cts} +9 -9
  37. package/dist/index.d.cts.map +1 -0
  38. package/dist/index.d.mts +9 -0
  39. package/dist/index.d.mts.map +1 -0
  40. package/dist/index.mjs +4 -0
  41. package/dist/index.mjs.map +1 -0
  42. package/dist/selectors.cjs +27 -0
  43. package/dist/selectors.cjs.map +1 -0
  44. package/dist/{selectors.d.ts → selectors.d.cts} +4 -4
  45. package/dist/selectors.d.cts.map +1 -0
  46. package/dist/selectors.d.mts +20 -0
  47. package/dist/selectors.d.mts.map +1 -0
  48. package/dist/{selectors.js → selectors.mjs} +3 -3
  49. package/dist/selectors.mjs.map +1 -0
  50. package/dist/types.cjs +3 -0
  51. package/dist/types.cjs.map +1 -0
  52. package/dist/{types.d.ts → types.d.cts} +1 -1
  53. package/dist/types.d.cts.map +1 -0
  54. package/dist/types.d.mts +18 -0
  55. package/dist/types.d.mts.map +1 -0
  56. package/dist/types.mjs +2 -0
  57. package/dist/types.mjs.map +1 -0
  58. package/dist/utils.cjs +15 -0
  59. package/dist/utils.cjs.map +1 -0
  60. package/dist/{utils.d.ts → utils.d.cts} +2 -2
  61. package/dist/utils.d.cts.map +1 -0
  62. package/dist/utils.d.mts +3 -0
  63. package/dist/utils.d.mts.map +1 -0
  64. package/dist/{utils.js → utils.mjs} +2 -2
  65. package/dist/utils.mjs.map +1 -0
  66. package/package.json +16 -12
  67. package/dist/ComplianceController-method-action-types.d.ts.map +0 -1
  68. package/dist/ComplianceController-method-action-types.js.map +0 -1
  69. package/dist/ComplianceController.d.ts.map +0 -1
  70. package/dist/ComplianceController.js.map +0 -1
  71. package/dist/ComplianceService-method-action-types.d.ts.map +0 -1
  72. package/dist/ComplianceService-method-action-types.js.map +0 -1
  73. package/dist/ComplianceService.d.ts.map +0 -1
  74. package/dist/ComplianceService.js.map +0 -1
  75. package/dist/index.d.ts.map +0 -1
  76. package/dist/index.js +0 -4
  77. package/dist/selectors.d.ts.map +0 -1
  78. package/dist/selectors.js.map +0 -1
  79. package/dist/types.d.ts.map +0 -1
  80. package/dist/types.js +0 -2
  81. package/dist/types.js.map +0 -1
  82. package/dist/utils.d.ts.map +0 -1
  83. package/dist/utils.js.map +0 -1
@@ -0,0 +1,239 @@
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ 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");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ 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");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _a, _ComplianceService_messenger, _ComplianceService_fetch, _ComplianceService_complianceApiUrl, _ComplianceService_policy;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.ComplianceService = exports.serviceName = void 0;
16
+ const controller_utils_1 = require("@metamask/controller-utils");
17
+ const superstruct_1 = require("@metamask/superstruct");
18
+ // === GENERAL ===
19
+ /**
20
+ * The name of the {@link ComplianceService}, used to namespace the service's
21
+ * actions and events.
22
+ */
23
+ exports.serviceName = 'ComplianceService';
24
+ const COMPLIANCE_API_URLS = {
25
+ production: 'https://compliance.api.cx.metamask.io',
26
+ development: 'https://compliance.dev-api.cx.metamask.io',
27
+ };
28
+ // === MESSENGER ===
29
+ const MESSENGER_EXPOSED_METHODS = [
30
+ 'checkWalletCompliance',
31
+ 'checkWalletsCompliance',
32
+ ];
33
+ // === API RESPONSE SCHEMAS ===
34
+ /**
35
+ * Schema for the response from `GET /v1/wallet/:address`.
36
+ */
37
+ const WalletCheckResponseStruct = (0, superstruct_1.object)({
38
+ address: (0, superstruct_1.string)(),
39
+ blocked: (0, superstruct_1.boolean)(),
40
+ });
41
+ /**
42
+ * Schema for each item in the response from `POST /v1/wallet/batch`.
43
+ * Reuses the same shape as a single wallet check.
44
+ */
45
+ const BatchWalletCheckResponseItemStruct = WalletCheckResponseStruct;
46
+ // === SERVICE DEFINITION ===
47
+ /**
48
+ * `ComplianceService` communicates with the Compliance API to check whether
49
+ * wallet addresses are sanctioned under OFAC regulations.
50
+ *
51
+ * @example
52
+ *
53
+ * ``` ts
54
+ * import { Messenger } from '@metamask/messenger';
55
+ * import type {
56
+ * ComplianceServiceActions,
57
+ * ComplianceServiceEvents,
58
+ * } from '@metamask/compliance-controller';
59
+ * import { ComplianceService } from '@metamask/compliance-controller';
60
+ *
61
+ * const rootMessenger = new Messenger<
62
+ * 'Root',
63
+ * ComplianceServiceActions,
64
+ * ComplianceServiceEvents,
65
+ * >({ namespace: 'Root' });
66
+ * const serviceMessenger = new Messenger<
67
+ * 'ComplianceService',
68
+ * ComplianceServiceActions,
69
+ * ComplianceServiceEvents,
70
+ * typeof rootMessenger,
71
+ * >({
72
+ * namespace: 'ComplianceService',
73
+ * parent: rootMessenger,
74
+ * });
75
+ * new ComplianceService({
76
+ * messenger: serviceMessenger,
77
+ * fetch,
78
+ * apiUrl: 'https://compliance.api.cx.metamask.io',
79
+ * });
80
+ *
81
+ * // Check a single wallet
82
+ * const result = await rootMessenger.call(
83
+ * 'ComplianceService:checkWalletCompliance',
84
+ * '0x1234...',
85
+ * );
86
+ * // => { address: '0x1234...', blocked: false }
87
+ * ```
88
+ */
89
+ class ComplianceService {
90
+ /**
91
+ * Constructs a new ComplianceService object.
92
+ *
93
+ * @param args - The constructor arguments.
94
+ * @param args.messenger - The messenger suited for this service.
95
+ * @param args.fetch - A function that can be used to make an HTTP request.
96
+ * @param args.apiUrl - The explicit Compliance API URL.
97
+ * @param args.env - The fallback environment to use for the Compliance API
98
+ * when `apiUrl` is not provided.
99
+ * @param args.policyOptions - Options to pass to `createServicePolicy`, which
100
+ * is used to wrap each request. See {@link CreateServicePolicyOptions}.
101
+ */
102
+ constructor({ messenger, fetch: fetchFunction, apiUrl, env = 'production', policyOptions = {}, }) {
103
+ /**
104
+ * The messenger suited for this service.
105
+ */
106
+ _ComplianceService_messenger.set(this, void 0);
107
+ /**
108
+ * A function that can be used to make an HTTP request.
109
+ */
110
+ _ComplianceService_fetch.set(this, void 0);
111
+ /**
112
+ * The resolved base URL for the Compliance API.
113
+ */
114
+ _ComplianceService_complianceApiUrl.set(this, void 0);
115
+ /**
116
+ * The policy that wraps each request.
117
+ *
118
+ * @see {@link createServicePolicy}
119
+ */
120
+ _ComplianceService_policy.set(this, void 0);
121
+ this.name = exports.serviceName;
122
+ __classPrivateFieldSet(this, _ComplianceService_messenger, messenger, "f");
123
+ __classPrivateFieldSet(this, _ComplianceService_fetch, fetchFunction, "f");
124
+ __classPrivateFieldSet(this, _ComplianceService_complianceApiUrl, getComplianceApiUrl({ apiUrl, env }), "f");
125
+ __classPrivateFieldSet(this, _ComplianceService_policy, (0, controller_utils_1.createServicePolicy)(policyOptions), "f");
126
+ __classPrivateFieldGet(this, _ComplianceService_messenger, "f").registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
127
+ }
128
+ /**
129
+ * Registers a handler that will be called after a request returns a non-500
130
+ * response, causing a retry.
131
+ *
132
+ * @param listener - The handler to be called.
133
+ * @returns An object that can be used to unregister the handler.
134
+ * @see {@link createServicePolicy}
135
+ */
136
+ onRetry(listener) {
137
+ return __classPrivateFieldGet(this, _ComplianceService_policy, "f").onRetry(listener);
138
+ }
139
+ /**
140
+ * Registers a handler that will be called after a set number of retry rounds
141
+ * prove that requests to the API endpoint consistently return a 5xx response.
142
+ *
143
+ * @param listener - The handler to be called.
144
+ * @returns An object that can be used to unregister the handler.
145
+ * @see {@link createServicePolicy}
146
+ */
147
+ onBreak(listener) {
148
+ return __classPrivateFieldGet(this, _ComplianceService_policy, "f").onBreak(listener);
149
+ }
150
+ /**
151
+ * Registers a handler that will be called when the service is degraded due
152
+ * to slow responses or repeated failures.
153
+ *
154
+ * @param listener - The handler to be called.
155
+ * @returns An object that can be used to unregister the handler.
156
+ * @see {@link createServicePolicy}
157
+ */
158
+ onDegraded(listener) {
159
+ return __classPrivateFieldGet(this, _ComplianceService_policy, "f").onDegraded(listener);
160
+ }
161
+ /**
162
+ * Checks compliance status for a single wallet address.
163
+ *
164
+ * @param address - The wallet address to check.
165
+ * @returns The compliance status of the wallet.
166
+ */
167
+ async checkWalletCompliance(address) {
168
+ const response = await __classPrivateFieldGet(this, _ComplianceService_policy, "f").execute(async () => {
169
+ const url = new URL(`v1/wallet/${encodeURIComponent(address)}`, __classPrivateFieldGet(this, _ComplianceService_complianceApiUrl, "f"));
170
+ const localResponse = await __classPrivateFieldGet(this, _ComplianceService_fetch, "f").call(this, url);
171
+ if (!localResponse.ok) {
172
+ throw new controller_utils_1.HttpError(localResponse.status, `Fetching '${url.toString()}' failed with status '${localResponse.status}'`);
173
+ }
174
+ return localResponse;
175
+ });
176
+ const jsonResponse = await response.json();
177
+ return validateResponse(jsonResponse, WalletCheckResponseStruct, 'compliance wallet check API');
178
+ }
179
+ /**
180
+ * Checks compliance status for multiple wallet addresses in a single request.
181
+ *
182
+ * @param addresses - The wallet addresses to check.
183
+ * @returns The compliance statuses of the wallets.
184
+ */
185
+ async checkWalletsCompliance(addresses) {
186
+ const response = await __classPrivateFieldGet(this, _ComplianceService_policy, "f").execute(async () => {
187
+ const url = new URL('v1/wallet/batch', __classPrivateFieldGet(this, _ComplianceService_complianceApiUrl, "f"));
188
+ const localResponse = await __classPrivateFieldGet(this, _ComplianceService_fetch, "f").call(this, url, {
189
+ method: 'POST',
190
+ headers: { 'Content-Type': 'application/json' },
191
+ body: JSON.stringify(addresses),
192
+ });
193
+ if (!localResponse.ok) {
194
+ throw new controller_utils_1.HttpError(localResponse.status, `Fetching '${url.toString()}' failed with status '${localResponse.status}'`);
195
+ }
196
+ return localResponse;
197
+ });
198
+ const jsonResponse = await response.json();
199
+ return validateResponse(jsonResponse, (0, superstruct_1.array)(BatchWalletCheckResponseItemStruct), 'compliance batch check API');
200
+ }
201
+ }
202
+ exports.ComplianceService = ComplianceService;
203
+ _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
+ /**
224
+ * Validates an API response against a superstruct schema.
225
+ *
226
+ * @param data - The raw response data to validate.
227
+ * @param struct - The superstruct schema to validate against.
228
+ * @param struct.is - The type guard function from the schema.
229
+ * @param apiName - A human-readable name for the API, used in error messages.
230
+ * @returns The validated data.
231
+ * @throws If the data does not match the schema.
232
+ */
233
+ function validateResponse(data, struct, apiName) {
234
+ if (struct.is(data)) {
235
+ return data;
236
+ }
237
+ throw new Error(`Malformed response received from ${apiName}`);
238
+ }
239
+ //# sourceMappingURL=ComplianceService.cjs.map
@@ -0,0 +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,MAAM,kCAAkC,GAAG,yBAAyB,CAAC;AASrE,6BAA6B;AAE7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,MAAa,iBAAiB;IA8B5B;;;;;;;;;;;OAWG;IACH,YAAY,EACV,SAAS,EACT,KAAK,EAAE,aAAa,EACpB,MAAM,EACN,GAAG,GAAG,YAAY,EAClB,aAAa,GAAG,EAAE,GACO;QA1C3B;;WAEG;QACM,+CAES;QAElB;;WAEG;QACM,2CAAoE;QAE7E;;WAEG;QACM,sDAA0B;QAEnC;;;;WAIG;QACM,4CAAuB;QAqB9B,IAAI,CAAC,IAAI,GAAG,mBAAW,CAAC;QACxB,uBAAA,IAAI,gCAAc,SAAS,MAAA,CAAC;QAC5B,uBAAA,IAAI,4BAAU,aAAa,MAAA,CAAC;QAC5B,uBAAA,IAAI,uCAAqB,mBAAmB,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,MAAA,CAAC;QAC9D,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AAM,IAAI,KAAK,CAAC,+BAA+B,MAAM,EAAE,CAAC,CAAC;IAC3D,CAAC;IAED,IAAI,GAAG,CAAC,MAAM,IAAI,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.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,8 +1,8 @@
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';
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.cjs";
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.ts.map
184
+ //# sourceMappingURL=ComplianceService.d.cts.map
@@ -0,0 +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,oDAAmD;AAIjG;;;GAGG;AACH,eAAO,MAAM,WAAW,sBAAsB,CAAC;AAE/C;;GAEG;AACH,MAAM,MAAM,4BAA4B,GAAG,YAAY,GAAG,aAAa,CAAC;AAOxE,MAAM,MAAM,wBAAwB,GAAG;IACrC,SAAS,EAAE,0BAA0B,CAAC;IACtC,KAAK,EAAE,OAAO,KAAK,CAAC;IACpB;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,GAAG,CAAC,EAAE,4BAA4B,CAAC;IACnC,aAAa,CAAC,EAAE,0BAA0B,CAAC;CAC5C,CAAC;AASF;;GAEG;AACH,MAAM,MAAM,wBAAwB,GAAG,8BAA8B,CAAC;AAEtE;;GAEG;AACH,KAAK,cAAc,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AO,CAAC,mBAAmB,CAAC;IAwB1E;;;;;OAKG;IACG,sBAAsB,CAC1B,SAAS,EAAE,MAAM,EAAE,GAClB,OAAO,CAAC,4BAA4B,EAAE,CAAC;CAwB3C"}
@@ -0,0 +1,184 @@
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.mjs";
6
+ /**
7
+ * The name of the {@link ComplianceService}, used to namespace the service's
8
+ * actions and events.
9
+ */
10
+ export declare const serviceName = "ComplianceService";
11
+ /**
12
+ * The supported environments for the Compliance API.
13
+ */
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
+ /**
31
+ * Actions that {@link ComplianceService} exposes to other consumers.
32
+ */
33
+ export type ComplianceServiceActions = ComplianceServiceMethodActions;
34
+ /**
35
+ * Actions from other messengers that {@link ComplianceService} calls.
36
+ */
37
+ type AllowedActions = never;
38
+ /**
39
+ * Events that {@link ComplianceService} exposes to other consumers.
40
+ */
41
+ export type ComplianceServiceEvents = never;
42
+ /**
43
+ * Events from other messengers that {@link ComplianceService} subscribes to.
44
+ */
45
+ type AllowedEvents = never;
46
+ /**
47
+ * The messenger restricted to actions and events accessed by
48
+ * {@link ComplianceService}.
49
+ */
50
+ export type ComplianceServiceMessenger = Messenger<typeof serviceName, ComplianceServiceActions | AllowedActions, ComplianceServiceEvents | AllowedEvents>;
51
+ /**
52
+ * Schema for the response from `GET /v1/wallet/:address`.
53
+ */
54
+ declare const WalletCheckResponseStruct: import("@metamask/superstruct").Struct<{
55
+ address: string;
56
+ blocked: boolean;
57
+ }, {
58
+ address: import("@metamask/superstruct").Struct<string, null>;
59
+ blocked: import("@metamask/superstruct").Struct<boolean, null>;
60
+ }>;
61
+ /**
62
+ * The validated shape of a single wallet compliance check response.
63
+ */
64
+ type WalletCheckResponse = Infer<typeof WalletCheckResponseStruct>;
65
+ /**
66
+ * Schema for each item in the response from `POST /v1/wallet/batch`.
67
+ * Reuses the same shape as a single wallet check.
68
+ */
69
+ declare const BatchWalletCheckResponseItemStruct: import("@metamask/superstruct").Struct<{
70
+ address: string;
71
+ blocked: boolean;
72
+ }, {
73
+ address: import("@metamask/superstruct").Struct<string, null>;
74
+ blocked: import("@metamask/superstruct").Struct<boolean, null>;
75
+ }>;
76
+ /**
77
+ * The validated shape of a single item in a batch compliance check response.
78
+ */
79
+ type BatchWalletCheckResponseItem = Infer<typeof BatchWalletCheckResponseItemStruct>;
80
+ /**
81
+ * `ComplianceService` communicates with the Compliance API to check whether
82
+ * wallet addresses are sanctioned under OFAC regulations.
83
+ *
84
+ * @example
85
+ *
86
+ * ``` ts
87
+ * import { Messenger } from '@metamask/messenger';
88
+ * import type {
89
+ * ComplianceServiceActions,
90
+ * ComplianceServiceEvents,
91
+ * } from '@metamask/compliance-controller';
92
+ * import { ComplianceService } from '@metamask/compliance-controller';
93
+ *
94
+ * const rootMessenger = new Messenger<
95
+ * 'Root',
96
+ * ComplianceServiceActions,
97
+ * ComplianceServiceEvents,
98
+ * >({ namespace: 'Root' });
99
+ * const serviceMessenger = new Messenger<
100
+ * 'ComplianceService',
101
+ * ComplianceServiceActions,
102
+ * ComplianceServiceEvents,
103
+ * typeof rootMessenger,
104
+ * >({
105
+ * namespace: 'ComplianceService',
106
+ * parent: rootMessenger,
107
+ * });
108
+ * new ComplianceService({
109
+ * messenger: serviceMessenger,
110
+ * fetch,
111
+ * apiUrl: 'https://compliance.api.cx.metamask.io',
112
+ * });
113
+ *
114
+ * // Check a single wallet
115
+ * const result = await rootMessenger.call(
116
+ * 'ComplianceService:checkWalletCompliance',
117
+ * '0x1234...',
118
+ * );
119
+ * // => { address: '0x1234...', blocked: false }
120
+ * ```
121
+ */
122
+ export declare class ComplianceService {
123
+ #private;
124
+ /**
125
+ * The name of the service.
126
+ */
127
+ readonly name: typeof serviceName;
128
+ /**
129
+ * Constructs a new ComplianceService object.
130
+ *
131
+ * @param args - The constructor arguments.
132
+ * @param args.messenger - The messenger suited for this service.
133
+ * @param args.fetch - A function that can be used to make an HTTP request.
134
+ * @param args.apiUrl - The explicit Compliance API URL.
135
+ * @param args.env - The fallback environment to use for the Compliance API
136
+ * when `apiUrl` is not provided.
137
+ * @param args.policyOptions - Options to pass to `createServicePolicy`, which
138
+ * is used to wrap each request. See {@link CreateServicePolicyOptions}.
139
+ */
140
+ constructor({ messenger, fetch: fetchFunction, apiUrl, env, policyOptions, }: ComplianceServiceOptions);
141
+ /**
142
+ * Registers a handler that will be called after a request returns a non-500
143
+ * response, causing a retry.
144
+ *
145
+ * @param listener - The handler to be called.
146
+ * @returns An object that can be used to unregister the handler.
147
+ * @see {@link createServicePolicy}
148
+ */
149
+ onRetry(listener: Parameters<ServicePolicy['onRetry']>[0]): IDisposable;
150
+ /**
151
+ * Registers a handler that will be called after a set number of retry rounds
152
+ * prove that requests to the API endpoint consistently return a 5xx response.
153
+ *
154
+ * @param listener - The handler to be called.
155
+ * @returns An object that can be used to unregister the handler.
156
+ * @see {@link createServicePolicy}
157
+ */
158
+ onBreak(listener: Parameters<ServicePolicy['onBreak']>[0]): IDisposable;
159
+ /**
160
+ * Registers a handler that will be called when the service is degraded due
161
+ * to slow responses or repeated failures.
162
+ *
163
+ * @param listener - The handler to be called.
164
+ * @returns An object that can be used to unregister the handler.
165
+ * @see {@link createServicePolicy}
166
+ */
167
+ onDegraded(listener: Parameters<ServicePolicy['onDegraded']>[0]): IDisposable;
168
+ /**
169
+ * Checks compliance status for a single wallet address.
170
+ *
171
+ * @param address - The wallet address to check.
172
+ * @returns The compliance status of the wallet.
173
+ */
174
+ checkWalletCompliance(address: string): Promise<WalletCheckResponse>;
175
+ /**
176
+ * Checks compliance status for multiple wallet addresses in a single request.
177
+ *
178
+ * @param addresses - The wallet addresses to check.
179
+ * @returns The compliance statuses of the wallets.
180
+ */
181
+ checkWalletsCompliance(addresses: string[]): Promise<BatchWalletCheckResponseItem[]>;
182
+ }
183
+ export {};
184
+ //# sourceMappingURL=ComplianceService.d.mts.map
@@ -0,0 +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,oDAAmD;AAIjG;;;GAGG;AACH,eAAO,MAAM,WAAW,sBAAsB,CAAC;AAE/C;;GAEG;AACH,MAAM,MAAM,4BAA4B,GAAG,YAAY,GAAG,aAAa,CAAC;AAOxE,MAAM,MAAM,wBAAwB,GAAG;IACrC,SAAS,EAAE,0BAA0B,CAAC;IACtC,KAAK,EAAE,OAAO,KAAK,CAAC;IACpB;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,GAAG,CAAC,EAAE,4BAA4B,CAAC;IACnC,aAAa,CAAC,EAAE,0BAA0B,CAAC;CAC5C,CAAC;AASF;;GAEG;AACH,MAAM,MAAM,wBAAwB,GAAG,8BAA8B,CAAC;AAEtE;;GAEG;AACH,KAAK,cAAc,GAAG,KAAK,CAAC;AAE5B;;GAEG;AACH,MAAM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;IACG,sBAAsB,CAC1B,SAAS,EAAE,MAAM,EAAE,GAClB,OAAO,CAAC,4BAA4B,EAAE,CAAC;CAwB3C"}
@@ -1,5 +1,17 @@
1
- import { createServicePolicy, HttpError } from '@metamask/controller-utils';
2
- import { array, boolean, object, string } from '@metamask/superstruct';
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
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";
3
15
  // === GENERAL ===
4
16
  /**
5
17
  * The name of the {@link ComplianceService}, used to namespace the service's
@@ -72,28 +84,6 @@ const BatchWalletCheckResponseItemStruct = WalletCheckResponseStruct;
72
84
  * ```
73
85
  */
74
86
  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;
97
87
  /**
98
88
  * Constructs a new ComplianceService object.
99
89
  *
@@ -107,12 +97,30 @@ export class ComplianceService {
107
97
  * is used to wrap each request. See {@link CreateServicePolicyOptions}.
108
98
  */
109
99
  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);
110
118
  this.name = serviceName;
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);
119
+ __classPrivateFieldSet(this, _ComplianceService_messenger, messenger, "f");
120
+ __classPrivateFieldSet(this, _ComplianceService_fetch, fetchFunction, "f");
121
+ __classPrivateFieldSet(this, _ComplianceService_complianceApiUrl, getComplianceApiUrl({ apiUrl, env }), "f");
122
+ __classPrivateFieldSet(this, _ComplianceService_policy, createServicePolicy(policyOptions), "f");
123
+ __classPrivateFieldGet(this, _ComplianceService_messenger, "f").registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
116
124
  }
117
125
  /**
118
126
  * Registers a handler that will be called after a request returns a non-500
@@ -123,7 +131,7 @@ export class ComplianceService {
123
131
  * @see {@link createServicePolicy}
124
132
  */
125
133
  onRetry(listener) {
126
- return this.#policy.onRetry(listener);
134
+ return __classPrivateFieldGet(this, _ComplianceService_policy, "f").onRetry(listener);
127
135
  }
128
136
  /**
129
137
  * Registers a handler that will be called after a set number of retry rounds
@@ -134,7 +142,7 @@ export class ComplianceService {
134
142
  * @see {@link createServicePolicy}
135
143
  */
136
144
  onBreak(listener) {
137
- return this.#policy.onBreak(listener);
145
+ return __classPrivateFieldGet(this, _ComplianceService_policy, "f").onBreak(listener);
138
146
  }
139
147
  /**
140
148
  * Registers a handler that will be called when the service is degraded due
@@ -145,7 +153,7 @@ export class ComplianceService {
145
153
  * @see {@link createServicePolicy}
146
154
  */
147
155
  onDegraded(listener) {
148
- return this.#policy.onDegraded(listener);
156
+ return __classPrivateFieldGet(this, _ComplianceService_policy, "f").onDegraded(listener);
149
157
  }
150
158
  /**
151
159
  * Checks compliance status for a single wallet address.
@@ -154,9 +162,9 @@ export class ComplianceService {
154
162
  * @returns The compliance status of the wallet.
155
163
  */
156
164
  async checkWalletCompliance(address) {
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);
165
+ const response = await __classPrivateFieldGet(this, _ComplianceService_policy, "f").execute(async () => {
166
+ const url = new URL(`v1/wallet/${encodeURIComponent(address)}`, __classPrivateFieldGet(this, _ComplianceService_complianceApiUrl, "f"));
167
+ const localResponse = await __classPrivateFieldGet(this, _ComplianceService_fetch, "f").call(this, url);
160
168
  if (!localResponse.ok) {
161
169
  throw new HttpError(localResponse.status, `Fetching '${url.toString()}' failed with status '${localResponse.status}'`);
162
170
  }
@@ -172,9 +180,9 @@ export class ComplianceService {
172
180
  * @returns The compliance statuses of the wallets.
173
181
  */
174
182
  async checkWalletsCompliance(addresses) {
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, {
183
+ const response = await __classPrivateFieldGet(this, _ComplianceService_policy, "f").execute(async () => {
184
+ const url = new URL('v1/wallet/batch', __classPrivateFieldGet(this, _ComplianceService_complianceApiUrl, "f"));
185
+ const localResponse = await __classPrivateFieldGet(this, _ComplianceService_fetch, "f").call(this, url, {
178
186
  method: 'POST',
179
187
  headers: { 'Content-Type': 'application/json' },
180
188
  body: JSON.stringify(addresses),
@@ -188,6 +196,7 @@ export class ComplianceService {
188
196
  return validateResponse(jsonResponse, array(BatchWalletCheckResponseItemStruct), 'compliance batch check API');
189
197
  }
190
198
  }
199
+ _a = ComplianceService, _ComplianceService_messenger = new WeakMap(), _ComplianceService_fetch = new WeakMap(), _ComplianceService_complianceApiUrl = new WeakMap(), _ComplianceService_policy = new WeakMap();
191
200
  function getComplianceApiUrl({ apiUrl, env, }) {
192
201
  if (apiUrl === undefined) {
193
202
  return COMPLIANCE_API_URLS[env];
@@ -223,4 +232,4 @@ function validateResponse(data, struct, apiName) {
223
232
  }
224
233
  throw new Error(`Malformed response received from ${apiName}`);
225
234
  }
226
- //# sourceMappingURL=ComplianceService.js.map
235
+ //# sourceMappingURL=ComplianceService.mjs.map