@metamask-previews/authenticated-user-storage 4.1.0-preview-e80304db4 → 4.1.0-preview-eb6c0745c

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 CHANGED
@@ -7,20 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
- ### Added
11
-
12
- - Add support for Node.js 26 ([#10981](https://github.com/MetaMask/core/pull/10981))
13
- - Add `getUserAssets`, `setUserAssets`, `importTokens`, `hideTokens`, and `clearUserAssets` methods to `AuthenticatedUserStorageService` for managing the authenticated user's custom tokens, along with corresponding messenger actions (`AuthenticatedUserStorageService:getUserAssets`, `AuthenticatedUserStorageService:setUserAssets`, `AuthenticatedUserStorageService:importTokens`, `AuthenticatedUserStorageService:hideTokens`, `AuthenticatedUserStorageService:clearUserAssets`) and the `UserAssetsBlob` type ([#10233](https://github.com/MetaMask/core/pull/10233))
14
- - Backed by the new `GET`/`PUT /api/v1/preferences/custom-tokens` API endpoints; `getUserAssets` returns the blob or `null` on 404, mirroring `getAssetsWatchlist`.
15
- - Every write is normalized: entries are de-duplicated (order-preserving) and conflicts between `importedAssets` and `hiddenAssets` are resolved "fail-open" — an identifier present in both lists stays in `importedAssets` (the user's intent to import wins) and is removed from `hiddenAssets`.
16
- - `importTokens`/`hideTokens` are high-level wrappers that fetch the current blob, merge with deduplication and mutual exclusivity, persist, and return the resolved blob.
17
- - `clearUserAssets` wipes the blob by persisting empty lists, giving users a clean slate.
18
- - Writes enforce that every entry is a CAIP-19 asset identifier and that each list holds at most `USER_ASSETS_MAX_ASSETS` (100) entries, mirroring the API's server-side cap, throwing a superstruct `StructError` before the request is sent.
19
-
20
10
  ### Changed
21
11
 
22
12
  - Bump `@metamask/base-data-service` from `^2.0.0` to `^2.1.0` ([#10502](https://github.com/MetaMask/core/pull/10502))
23
- - Bump `@metamask/utils` from `^12.0.0` to `^12.0.2` ([#11107](https://github.com/MetaMask/core/pull/11107), [#11474](https://github.com/MetaMask/core/pull/11474))
24
13
 
25
14
  ## [4.1.0]
26
15
 
package/README.md CHANGED
@@ -2,12 +2,11 @@
2
2
 
3
3
  A TypeScript SDK for MetaMask's Authenticated User Storage API. Unlike E2EE user-storage, authenticated user storage holds **structured JSON** scoped to the authenticated user. The server can read and validate the contents, which allows other backend services to consume the data (e.g. delegation execution, notification delivery).
4
4
 
5
- The SDK currently supports four domains:
5
+ The SDK currently supports three domains:
6
6
 
7
7
  - **Delegations** -- immutable, EIP-712 signed delegation records (list, create, revoke).
8
8
  - **Notification Preferences** -- mutable per-user notification settings (get, put).
9
9
  - **Assets watchlist** -- mutable per-user list of CAIP-19 asset identifiers (get, set).
10
- - **User assets (custom tokens)** -- mutable per-user record of imported and hidden tokens (get, set, import, hide).
11
10
 
12
11
  ## Installation
13
12
 
@@ -155,50 +154,6 @@ const updated: AssetsWatchlistBlob = {
155
154
  await service.setAssetsWatchlist(updated, 'extension');
156
155
  ```
157
156
 
158
- ### User assets (custom tokens)
159
-
160
- The user-assets blob is a mutable per-user singleton blob recording which custom tokens the user chose to import and which they chose to hide. The first call to `setUserAssets` creates the record; subsequent calls overwrite it. Each entry of `importedAssets` and `hiddenAssets` is a [CAIP-19](https://chainagnostic.org/CAIPs/caip-19) asset identifier (e.g. `eip155:1/erc20:0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48`). The blob carries an explicit `version: 1` literal so the shape can evolve without breaking existing consumers. It is stored at the `GET`/`PUT /api/v1/preferences/custom-tokens` endpoints of the user-storage API, which enforce a server-side cap of 100 entries per list; writes mirror that cap with `USER_ASSETS_MAX_ASSETS`.
161
-
162
- The two lists are mutually exclusive by contract: a given identifier may appear in at most one of them. Every write is normalized before the request is sent — entries are de-duplicated (order-preserving) and conflicts are resolved "fail-open": an identifier present in both lists stays in `importedAssets` (the user's intent to import wins) and is removed from `hiddenAssets`, so a write is never rejected because of a conflict. On writes, every entry must be a valid CAIP-19 asset identifier; malformed blobs throw a superstruct `StructError` before the request is sent.
163
-
164
- Most consumers should not read-modify-write the blob themselves. The high-level `importTokens` and `hideTokens` methods fetch the current blob (creating a fresh one if none exists yet), apply the merge with deduplication and mutual exclusivity, persist the result, and return the resolved blob:
165
-
166
- ```typescript
167
- import type { UserAssetsBlob } from '@metamask/authenticated-user-storage';
168
-
169
- // Retrieve the current user-assets blob (returns null on the first read)
170
- const userAssets: UserAssetsBlob | null = await service.getUserAssets();
171
-
172
- // Import custom tokens (de-duplicated; removes them from hiddenAssets)
173
- const imported: UserAssetsBlob = await service.importTokens(
174
- [
175
- 'eip155:1/erc20:0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
176
- 'eip155:8453/erc20:0x833589fcd6edb6e08f4c7c32d4f71b54bda02913',
177
- ],
178
- 'extension',
179
- );
180
-
181
- // Hide tokens (de-duplicated; removes them from importedAssets)
182
- const hidden: UserAssetsBlob = await service.hideTokens([
183
- 'eip155:10/erc20:0xa0b86991c6218b36c1d19d4a2e9eb0ce36000000',
184
- ]);
185
-
186
- // Low-level: replace the whole blob (still normalized and validated)
187
- await service.setUserAssets(
188
- {
189
- version: 1,
190
- importedAssets: [
191
- 'eip155:1/erc20:0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
192
- ],
193
- hiddenAssets: [],
194
- },
195
- 'extension',
196
- );
197
-
198
- // Wipe all custom tokens (clean slate: both lists empty)
199
- await service.clearUserAssets();
200
- ```
201
-
202
157
  ## Response validation
203
158
 
204
159
  All API responses are validated at runtime using [`@metamask/superstruct`](https://github.com/MetaMask/superstruct) schemas before being returned to callers. If the server returns data that doesn't match the expected shape, the SDK throws with details about the structural mismatch rather than silently returning malformed data.
@@ -119,71 +119,8 @@ export type AuthenticatedUserStorageServiceSetAssetsWatchlistAction = {
119
119
  type: `AuthenticatedUserStorageService:setAssetsWatchlist`;
120
120
  handler: AuthenticatedUserStorageService['setAssetsWatchlist'];
121
121
  };
122
- /**
123
- * Returns the user-assets (custom tokens) blob for the authenticated user.
124
- *
125
- * @returns The user-assets blob, or `null` if none has been set (404).
126
- */
127
- export type AuthenticatedUserStorageServiceGetUserAssetsAction = {
128
- type: `AuthenticatedUserStorageService:getUserAssets`;
129
- handler: AuthenticatedUserStorageService['getUserAssets'];
130
- };
131
- /**
132
- * Creates or updates the user-assets (custom tokens) blob for the
133
- * authenticated user. The blob is normalized (de-duplicated, conflicts
134
- * resolved fail-open in favor of `importedAssets`) before it is sent.
135
- *
136
- * @param blob - The full user-assets blob, with CAIP-19 asset identifiers.
137
- * @param clientType - Optional client type header.
138
- * @throws A `StructError` if `blob` is structurally invalid; an `HttpError`
139
- * if the API responds with a non-2xx status.
140
- */
141
- export type AuthenticatedUserStorageServiceSetUserAssetsAction = {
142
- type: `AuthenticatedUserStorageService:setUserAssets`;
143
- handler: AuthenticatedUserStorageService['setUserAssets'];
144
- };
145
- /**
146
- * Imports custom tokens: adds the given identifiers to `importedAssets`
147
- * (de-duplicated, order preserved) and removes them from `hiddenAssets`.
148
- * Creates a fresh blob if none exists yet.
149
- *
150
- * @param ids - The CAIP-19 asset identifiers of the tokens to import.
151
- * @param clientType - Optional client type header.
152
- * @returns The resolved user-assets blob that was persisted.
153
- * @throws A `StructError` if any entry of `ids` is not a CAIP-19 asset
154
- * identifier; an `HttpError` if the API responds with a non-2xx status.
155
- */
156
- export type AuthenticatedUserStorageServiceImportTokensAction = {
157
- type: `AuthenticatedUserStorageService:importTokens`;
158
- handler: AuthenticatedUserStorageService['importTokens'];
159
- };
160
- /**
161
- * Hides custom tokens: adds the given identifiers to `hiddenAssets`
162
- * (de-duplicated, order preserved) and removes them from
163
- * `importedAssets`. Creates a fresh blob if none exists yet.
164
- *
165
- * @param ids - The CAIP-19 asset identifiers of the tokens to hide.
166
- * @param clientType - Optional client type header.
167
- * @returns The resolved user-assets blob that was persisted.
168
- * @throws A `StructError` if any entry of `ids` is not a CAIP-19 asset
169
- * identifier; an `HttpError` if the API responds with a non-2xx status.
170
- */
171
- export type AuthenticatedUserStorageServiceHideTokensAction = {
172
- type: `AuthenticatedUserStorageService:hideTokens`;
173
- handler: AuthenticatedUserStorageService['hideTokens'];
174
- };
175
- /**
176
- * Wipes the user's custom tokens, restoring a clean slate (empty lists).
177
- *
178
- * @param clientType - Optional client type header.
179
- * @throws An `HttpError` if the API responds with a non-2xx status.
180
- */
181
- export type AuthenticatedUserStorageServiceClearUserAssetsAction = {
182
- type: `AuthenticatedUserStorageService:clearUserAssets`;
183
- handler: AuthenticatedUserStorageService['clearUserAssets'];
184
- };
185
122
  /**
186
123
  * Union of all AuthenticatedUserStorageService action types.
187
124
  */
188
- export type AuthenticatedUserStorageServiceMethodActions = AuthenticatedUserStorageServiceListDelegationsAction | AuthenticatedUserStorageServiceCreateDelegationAction | AuthenticatedUserStorageServiceRevokeDelegationAction | AuthenticatedUserStorageServiceGetNotificationPreferencesAction | AuthenticatedUserStorageServicePutNotificationPreferencesAction | AuthenticatedUserStorageServiceGetMarketingConsentAction | AuthenticatedUserStorageServicePutMarketingConsentAction | AuthenticatedUserStorageServiceGetIdentitySharingConsentAction | AuthenticatedUserStorageServicePutIdentitySharingConsentAction | AuthenticatedUserStorageServiceGetAssetsWatchlistAction | AuthenticatedUserStorageServiceSetAssetsWatchlistAction | AuthenticatedUserStorageServiceGetUserAssetsAction | AuthenticatedUserStorageServiceSetUserAssetsAction | AuthenticatedUserStorageServiceImportTokensAction | AuthenticatedUserStorageServiceHideTokensAction | AuthenticatedUserStorageServiceClearUserAssetsAction;
125
+ export type AuthenticatedUserStorageServiceMethodActions = AuthenticatedUserStorageServiceListDelegationsAction | AuthenticatedUserStorageServiceCreateDelegationAction | AuthenticatedUserStorageServiceRevokeDelegationAction | AuthenticatedUserStorageServiceGetNotificationPreferencesAction | AuthenticatedUserStorageServicePutNotificationPreferencesAction | AuthenticatedUserStorageServiceGetMarketingConsentAction | AuthenticatedUserStorageServicePutMarketingConsentAction | AuthenticatedUserStorageServiceGetIdentitySharingConsentAction | AuthenticatedUserStorageServicePutIdentitySharingConsentAction | AuthenticatedUserStorageServiceGetAssetsWatchlistAction | AuthenticatedUserStorageServiceSetAssetsWatchlistAction;
189
126
  //# sourceMappingURL=authenticated-user-storage-method-action-types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"authenticated-user-storage-method-action-types.d.ts","sourceRoot":"","sources":["../src/authenticated-user-storage-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,iCAAiC,CAAC;AAEvF;;;;GAIG;AACH,MAAM,MAAM,oDAAoD,GAAG;IACjE,IAAI,EAAE,iDAAiD,CAAC;IACxD,OAAO,EAAE,+BAA+B,CAAC,iBAAiB,CAAC,CAAC;CAC7D,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,qDAAqD,GAAG;IAClE,IAAI,EAAE,kDAAkD,CAAC;IACzD,OAAO,EAAE,+BAA+B,CAAC,kBAAkB,CAAC,CAAC;CAC9D,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,qDAAqD,GAAG;IAClE,IAAI,EAAE,kDAAkD,CAAC;IACzD,OAAO,EAAE,+BAA+B,CAAC,kBAAkB,CAAC,CAAC;CAC9D,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,+DAA+D,GAAG;IAC5E,IAAI,EAAE,4DAA4D,CAAC;IACnE,OAAO,EAAE,+BAA+B,CAAC,4BAA4B,CAAC,CAAC;CACxE,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,+DAA+D,GAAG;IAC5E,IAAI,EAAE,4DAA4D,CAAC;IACnE,OAAO,EAAE,+BAA+B,CAAC,4BAA4B,CAAC,CAAC;CACxE,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,wDAAwD,GAAG;IACrE,IAAI,EAAE,qDAAqD,CAAC;IAC5D,OAAO,EAAE,+BAA+B,CAAC,qBAAqB,CAAC,CAAC;CACjE,CAAC;AAEF;;;;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IAC5D,IAAI,EAAE,4CAA4C,CAAC;IACnD,OAAO,EAAE,+BAA+B,CAAC,YAAY,CAAC,CAAC;CACxD,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,oDAAoD,GAAG;IACjE,IAAI,EAAE,iDAAiD,CAAC;IACxD,OAAO,EAAE,+BAA+B,CAAC,iBAAiB,CAAC,CAAC;CAC7D,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,4CAA4C,GACpD,oDAAoD,GACpD,qDAAqD,GACrD,qDAAqD,GACrD,+DAA+D,GAC/D,+DAA+D,GAC/D,wDAAwD,GACxD,wDAAwD,GACxD,8DAA8D,GAC9D,8DAA8D,GAC9D,uDAAuD,GACvD,uDAAuD,GACvD,kDAAkD,GAClD,kDAAkD,GAClD,iDAAiD,GACjD,+CAA+C,GAC/C,oDAAoD,CAAC"}
1
+ {"version":3,"file":"authenticated-user-storage-method-action-types.d.ts","sourceRoot":"","sources":["../src/authenticated-user-storage-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,iCAAiC,CAAC;AAEvF;;;;GAIG;AACH,MAAM,MAAM,oDAAoD,GAAG;IACjE,IAAI,EAAE,iDAAiD,CAAC;IACxD,OAAO,EAAE,+BAA+B,CAAC,iBAAiB,CAAC,CAAC;CAC7D,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,qDAAqD,GAAG;IAClE,IAAI,EAAE,kDAAkD,CAAC;IACzD,OAAO,EAAE,+BAA+B,CAAC,kBAAkB,CAAC,CAAC;CAC9D,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,qDAAqD,GAAG;IAClE,IAAI,EAAE,kDAAkD,CAAC;IACzD,OAAO,EAAE,+BAA+B,CAAC,kBAAkB,CAAC,CAAC;CAC9D,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,+DAA+D,GAAG;IAC5E,IAAI,EAAE,4DAA4D,CAAC;IACnE,OAAO,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ACxD,8DAA8D,GAC9D,8DAA8D,GAC9D,uDAAuD,GACvD,uDAAuD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"authenticated-user-storage-method-action-types.js","sourceRoot":"","sources":["../src/authenticated-user-storage-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { AuthenticatedUserStorageService } from './authenticated-user-storage.js';\n\n/**\n * Returns all delegation records belonging to the authenticated user.\n *\n * @returns An array of delegation records, or an empty array if none exist.\n */\nexport type AuthenticatedUserStorageServiceListDelegationsAction = {\n type: `AuthenticatedUserStorageService:listDelegations`;\n handler: AuthenticatedUserStorageService['listDelegations'];\n};\n\n/**\n * Stores a signed delegation record for the authenticated user.\n *\n * @param submission - The signed delegation and its metadata.\n * @param clientType - Optional client type header.\n */\nexport type AuthenticatedUserStorageServiceCreateDelegationAction = {\n type: `AuthenticatedUserStorageService:createDelegation`;\n handler: AuthenticatedUserStorageService['createDelegation'];\n};\n\n/**\n * Revokes (deletes) a delegation record.\n *\n * @param delegationHash - The unique hash identifying the delegation.\n */\nexport type AuthenticatedUserStorageServiceRevokeDelegationAction = {\n type: `AuthenticatedUserStorageService:revokeDelegation`;\n handler: AuthenticatedUserStorageService['revokeDelegation'];\n};\n\n/**\n * Returns the notification preferences for the authenticated user.\n *\n * @returns The notification preferences object, or `null` if none have been\n * set (404).\n */\nexport type AuthenticatedUserStorageServiceGetNotificationPreferencesAction = {\n type: `AuthenticatedUserStorageService:getNotificationPreferences`;\n handler: AuthenticatedUserStorageService['getNotificationPreferences'];\n};\n\n/**\n * Creates or updates the notification preferences for the authenticated user.\n *\n * @param prefs - The full notification preferences object.\n * @param clientType - Optional client type header.\n */\nexport type AuthenticatedUserStorageServicePutNotificationPreferencesAction = {\n type: `AuthenticatedUserStorageService:putNotificationPreferences`;\n handler: AuthenticatedUserStorageService['putNotificationPreferences'];\n};\n\n/**\n * Returns the marketing consent for the authenticated user.\n *\n * @returns The marketing consent object, or `null` if none has been\n * set (404).\n */\nexport type AuthenticatedUserStorageServiceGetMarketingConsentAction = {\n type: `AuthenticatedUserStorageService:getMarketingConsent`;\n handler: AuthenticatedUserStorageService['getMarketingConsent'];\n};\n\n/**\n * Creates or updates the marketing consent for the authenticated user.\n *\n * @param consent - The full marketing consent object.\n * @param clientType - Optional client type header.\n */\nexport type AuthenticatedUserStorageServicePutMarketingConsentAction = {\n type: `AuthenticatedUserStorageService:putMarketingConsent`;\n handler: AuthenticatedUserStorageService['putMarketingConsent'];\n};\n\n/**\n * Returns the identity-sharing consent for the authenticated user.\n *\n * @returns The granted-audience map, or `null` if none has been set (404).\n */\nexport type AuthenticatedUserStorageServiceGetIdentitySharingConsentAction = {\n type: `AuthenticatedUserStorageService:getIdentitySharingConsent`;\n handler: AuthenticatedUserStorageService['getIdentitySharingConsent'];\n};\n\n/**\n * Grants or revokes identity-sharing consent for a single audience.\n * Other audiences on the profile are left unchanged.\n *\n * @param write - The audience and whether it is granted.\n * @param clientType - Optional client type header.\n * @throws A `StructError` from `@metamask/superstruct` if `write` is\n * invalid; an `HttpError` from `@metamask/controller-utils` if the API\n * responds with a non-2xx status.\n */\nexport type AuthenticatedUserStorageServicePutIdentitySharingConsentAction = {\n type: `AuthenticatedUserStorageService:putIdentitySharingConsent`;\n handler: AuthenticatedUserStorageService['putIdentitySharingConsent'];\n};\n\n/**\n * Returns the assets-watchlist for the authenticated user.\n *\n * @returns The assets-watchlist blob, or `null` if none has been set (404).\n */\nexport type AuthenticatedUserStorageServiceGetAssetsWatchlistAction = {\n type: `AuthenticatedUserStorageService:getAssetsWatchlist`;\n handler: AuthenticatedUserStorageService['getAssetsWatchlist'];\n};\n\n/**\n * Creates or updates the assets-watchlist for the authenticated user.\n *\n * @param blob - The full assets-watchlist blob. The `assets` array may\n * contain at most `ASSETS_WATCHLIST_MAX_ASSETS` CAIP-19 asset identifiers;\n * this is enforced by `assertAssetsWatchlistBlobForWrite` before the\n * request is sent.\n * @param clientType - Optional client type header.\n * @throws A `StructError` from `@metamask/superstruct` if `blob` is\n * structurally invalid or `assets` exceeds the cap; an `HttpError` from\n * `@metamask/controller-utils` if the API responds with a non-2xx status.\n */\nexport type AuthenticatedUserStorageServiceSetAssetsWatchlistAction = {\n type: `AuthenticatedUserStorageService:setAssetsWatchlist`;\n handler: AuthenticatedUserStorageService['setAssetsWatchlist'];\n};\n\n/**\n * Returns the user-assets (custom tokens) blob for the authenticated user.\n *\n * @returns The user-assets blob, or `null` if none has been set (404).\n */\nexport type AuthenticatedUserStorageServiceGetUserAssetsAction = {\n type: `AuthenticatedUserStorageService:getUserAssets`;\n handler: AuthenticatedUserStorageService['getUserAssets'];\n};\n\n/**\n * Creates or updates the user-assets (custom tokens) blob for the\n * authenticated user. The blob is normalized (de-duplicated, conflicts\n * resolved fail-open in favor of `importedAssets`) before it is sent.\n *\n * @param blob - The full user-assets blob, with CAIP-19 asset identifiers.\n * @param clientType - Optional client type header.\n * @throws A `StructError` if `blob` is structurally invalid; an `HttpError`\n * if the API responds with a non-2xx status.\n */\nexport type AuthenticatedUserStorageServiceSetUserAssetsAction = {\n type: `AuthenticatedUserStorageService:setUserAssets`;\n handler: AuthenticatedUserStorageService['setUserAssets'];\n};\n\n/**\n * Imports custom tokens: adds the given identifiers to `importedAssets`\n * (de-duplicated, order preserved) and removes them from `hiddenAssets`.\n * Creates a fresh blob if none exists yet.\n *\n * @param ids - The CAIP-19 asset identifiers of the tokens to import.\n * @param clientType - Optional client type header.\n * @returns The resolved user-assets blob that was persisted.\n * @throws A `StructError` if any entry of `ids` is not a CAIP-19 asset\n * identifier; an `HttpError` if the API responds with a non-2xx status.\n */\nexport type AuthenticatedUserStorageServiceImportTokensAction = {\n type: `AuthenticatedUserStorageService:importTokens`;\n handler: AuthenticatedUserStorageService['importTokens'];\n};\n\n/**\n * Hides custom tokens: adds the given identifiers to `hiddenAssets`\n * (de-duplicated, order preserved) and removes them from\n * `importedAssets`. Creates a fresh blob if none exists yet.\n *\n * @param ids - The CAIP-19 asset identifiers of the tokens to hide.\n * @param clientType - Optional client type header.\n * @returns The resolved user-assets blob that was persisted.\n * @throws A `StructError` if any entry of `ids` is not a CAIP-19 asset\n * identifier; an `HttpError` if the API responds with a non-2xx status.\n */\nexport type AuthenticatedUserStorageServiceHideTokensAction = {\n type: `AuthenticatedUserStorageService:hideTokens`;\n handler: AuthenticatedUserStorageService['hideTokens'];\n};\n\n/**\n * Wipes the user's custom tokens, restoring a clean slate (empty lists).\n *\n * @param clientType - Optional client type header.\n * @throws An `HttpError` if the API responds with a non-2xx status.\n */\nexport type AuthenticatedUserStorageServiceClearUserAssetsAction = {\n type: `AuthenticatedUserStorageService:clearUserAssets`;\n handler: AuthenticatedUserStorageService['clearUserAssets'];\n};\n\n/**\n * Union of all AuthenticatedUserStorageService action types.\n */\nexport type AuthenticatedUserStorageServiceMethodActions =\n | AuthenticatedUserStorageServiceListDelegationsAction\n | AuthenticatedUserStorageServiceCreateDelegationAction\n | AuthenticatedUserStorageServiceRevokeDelegationAction\n | AuthenticatedUserStorageServiceGetNotificationPreferencesAction\n | AuthenticatedUserStorageServicePutNotificationPreferencesAction\n | AuthenticatedUserStorageServiceGetMarketingConsentAction\n | AuthenticatedUserStorageServicePutMarketingConsentAction\n | AuthenticatedUserStorageServiceGetIdentitySharingConsentAction\n | AuthenticatedUserStorageServicePutIdentitySharingConsentAction\n | AuthenticatedUserStorageServiceGetAssetsWatchlistAction\n | AuthenticatedUserStorageServiceSetAssetsWatchlistAction\n | AuthenticatedUserStorageServiceGetUserAssetsAction\n | AuthenticatedUserStorageServiceSetUserAssetsAction\n | AuthenticatedUserStorageServiceImportTokensAction\n | AuthenticatedUserStorageServiceHideTokensAction\n | AuthenticatedUserStorageServiceClearUserAssetsAction;\n"]}
1
+ {"version":3,"file":"authenticated-user-storage-method-action-types.js","sourceRoot":"","sources":["../src/authenticated-user-storage-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { AuthenticatedUserStorageService } from './authenticated-user-storage.js';\n\n/**\n * Returns all delegation records belonging to the authenticated user.\n *\n * @returns An array of delegation records, or an empty array if none exist.\n */\nexport type AuthenticatedUserStorageServiceListDelegationsAction = {\n type: `AuthenticatedUserStorageService:listDelegations`;\n handler: AuthenticatedUserStorageService['listDelegations'];\n};\n\n/**\n * Stores a signed delegation record for the authenticated user.\n *\n * @param submission - The signed delegation and its metadata.\n * @param clientType - Optional client type header.\n */\nexport type AuthenticatedUserStorageServiceCreateDelegationAction = {\n type: `AuthenticatedUserStorageService:createDelegation`;\n handler: AuthenticatedUserStorageService['createDelegation'];\n};\n\n/**\n * Revokes (deletes) a delegation record.\n *\n * @param delegationHash - The unique hash identifying the delegation.\n */\nexport type AuthenticatedUserStorageServiceRevokeDelegationAction = {\n type: `AuthenticatedUserStorageService:revokeDelegation`;\n handler: AuthenticatedUserStorageService['revokeDelegation'];\n};\n\n/**\n * Returns the notification preferences for the authenticated user.\n *\n * @returns The notification preferences object, or `null` if none have been\n * set (404).\n */\nexport type AuthenticatedUserStorageServiceGetNotificationPreferencesAction = {\n type: `AuthenticatedUserStorageService:getNotificationPreferences`;\n handler: AuthenticatedUserStorageService['getNotificationPreferences'];\n};\n\n/**\n * Creates or updates the notification preferences for the authenticated user.\n *\n * @param prefs - The full notification preferences object.\n * @param clientType - Optional client type header.\n */\nexport type AuthenticatedUserStorageServicePutNotificationPreferencesAction = {\n type: `AuthenticatedUserStorageService:putNotificationPreferences`;\n handler: AuthenticatedUserStorageService['putNotificationPreferences'];\n};\n\n/**\n * Returns the marketing consent for the authenticated user.\n *\n * @returns The marketing consent object, or `null` if none has been\n * set (404).\n */\nexport type AuthenticatedUserStorageServiceGetMarketingConsentAction = {\n type: `AuthenticatedUserStorageService:getMarketingConsent`;\n handler: AuthenticatedUserStorageService['getMarketingConsent'];\n};\n\n/**\n * Creates or updates the marketing consent for the authenticated user.\n *\n * @param consent - The full marketing consent object.\n * @param clientType - Optional client type header.\n */\nexport type AuthenticatedUserStorageServicePutMarketingConsentAction = {\n type: `AuthenticatedUserStorageService:putMarketingConsent`;\n handler: AuthenticatedUserStorageService['putMarketingConsent'];\n};\n\n/**\n * Returns the identity-sharing consent for the authenticated user.\n *\n * @returns The granted-audience map, or `null` if none has been set (404).\n */\nexport type AuthenticatedUserStorageServiceGetIdentitySharingConsentAction = {\n type: `AuthenticatedUserStorageService:getIdentitySharingConsent`;\n handler: AuthenticatedUserStorageService['getIdentitySharingConsent'];\n};\n\n/**\n * Grants or revokes identity-sharing consent for a single audience.\n * Other audiences on the profile are left unchanged.\n *\n * @param write - The audience and whether it is granted.\n * @param clientType - Optional client type header.\n * @throws A `StructError` from `@metamask/superstruct` if `write` is\n * invalid; an `HttpError` from `@metamask/controller-utils` if the API\n * responds with a non-2xx status.\n */\nexport type AuthenticatedUserStorageServicePutIdentitySharingConsentAction = {\n type: `AuthenticatedUserStorageService:putIdentitySharingConsent`;\n handler: AuthenticatedUserStorageService['putIdentitySharingConsent'];\n};\n\n/**\n * Returns the assets-watchlist for the authenticated user.\n *\n * @returns The assets-watchlist blob, or `null` if none has been set (404).\n */\nexport type AuthenticatedUserStorageServiceGetAssetsWatchlistAction = {\n type: `AuthenticatedUserStorageService:getAssetsWatchlist`;\n handler: AuthenticatedUserStorageService['getAssetsWatchlist'];\n};\n\n/**\n * Creates or updates the assets-watchlist for the authenticated user.\n *\n * @param blob - The full assets-watchlist blob. The `assets` array may\n * contain at most `ASSETS_WATCHLIST_MAX_ASSETS` CAIP-19 asset identifiers;\n * this is enforced by `assertAssetsWatchlistBlobForWrite` before the\n * request is sent.\n * @param clientType - Optional client type header.\n * @throws A `StructError` from `@metamask/superstruct` if `blob` is\n * structurally invalid or `assets` exceeds the cap; an `HttpError` from\n * `@metamask/controller-utils` if the API responds with a non-2xx status.\n */\nexport type AuthenticatedUserStorageServiceSetAssetsWatchlistAction = {\n type: `AuthenticatedUserStorageService:setAssetsWatchlist`;\n handler: AuthenticatedUserStorageService['setAssetsWatchlist'];\n};\n\n/**\n * Union of all AuthenticatedUserStorageService action types.\n */\nexport type AuthenticatedUserStorageServiceMethodActions =\n | AuthenticatedUserStorageServiceListDelegationsAction\n | AuthenticatedUserStorageServiceCreateDelegationAction\n | AuthenticatedUserStorageServiceRevokeDelegationAction\n | AuthenticatedUserStorageServiceGetNotificationPreferencesAction\n | AuthenticatedUserStorageServicePutNotificationPreferencesAction\n | AuthenticatedUserStorageServiceGetMarketingConsentAction\n | AuthenticatedUserStorageServicePutMarketingConsentAction\n | AuthenticatedUserStorageServiceGetIdentitySharingConsentAction\n | AuthenticatedUserStorageServicePutIdentitySharingConsentAction\n | AuthenticatedUserStorageServiceGetAssetsWatchlistAction\n | AuthenticatedUserStorageServiceSetAssetsWatchlistAction;\n"]}
@@ -4,7 +4,7 @@ import type { CreateServicePolicyOptions } from '@metamask/controller-utils';
4
4
  import type { Messenger } from '@metamask/messenger';
5
5
  import type { AuthenticatedUserStorageServiceMethodActions } from './authenticated-user-storage-method-action-types.js';
6
6
  import type { Environment } from './env.js';
7
- import type { AssetsWatchlistBlob, ClientType, DelegationResponse, DelegationSubmission, IdentitySharingConsent, IdentitySharingConsentWrite, MarketingConsent, NotificationPreferences, UserAssetsBlob } from './types.js';
7
+ import type { AssetsWatchlistBlob, ClientType, DelegationResponse, DelegationSubmission, IdentitySharingConsent, IdentitySharingConsentWrite, MarketingConsent, NotificationPreferences } from './types.js';
8
8
  /**
9
9
  * The name of the {@link AuthenticatedUserStorageService} service, used to
10
10
  * namespace the service's actions and events.
@@ -168,54 +168,6 @@ export declare class AuthenticatedUserStorageService extends BaseDataService<typ
168
168
  * `@metamask/controller-utils` if the API responds with a non-2xx status.
169
169
  */
170
170
  setAssetsWatchlist(blob: AssetsWatchlistBlob, clientType?: ClientType): Promise<void>;
171
- /**
172
- * Returns the user-assets (custom tokens) blob for the authenticated user.
173
- *
174
- * @returns The user-assets blob, or `null` if none has been set (404).
175
- */
176
- getUserAssets(): Promise<UserAssetsBlob | null>;
177
- /**
178
- * Creates or updates the user-assets (custom tokens) blob for the
179
- * authenticated user. The blob is normalized (de-duplicated, conflicts
180
- * resolved fail-open in favor of `importedAssets`) before it is sent.
181
- *
182
- * @param blob - The full user-assets blob, with CAIP-19 asset identifiers.
183
- * @param clientType - Optional client type header.
184
- * @throws A `StructError` if `blob` is structurally invalid; an `HttpError`
185
- * if the API responds with a non-2xx status.
186
- */
187
- setUserAssets(blob: UserAssetsBlob, clientType?: ClientType): Promise<void>;
188
- /**
189
- * Imports custom tokens: adds the given identifiers to `importedAssets`
190
- * (de-duplicated, order preserved) and removes them from `hiddenAssets`.
191
- * Creates a fresh blob if none exists yet.
192
- *
193
- * @param ids - The CAIP-19 asset identifiers of the tokens to import.
194
- * @param clientType - Optional client type header.
195
- * @returns The resolved user-assets blob that was persisted.
196
- * @throws A `StructError` if any entry of `ids` is not a CAIP-19 asset
197
- * identifier; an `HttpError` if the API responds with a non-2xx status.
198
- */
199
- importTokens(ids: string[], clientType?: ClientType): Promise<UserAssetsBlob>;
200
- /**
201
- * Hides custom tokens: adds the given identifiers to `hiddenAssets`
202
- * (de-duplicated, order preserved) and removes them from
203
- * `importedAssets`. Creates a fresh blob if none exists yet.
204
- *
205
- * @param ids - The CAIP-19 asset identifiers of the tokens to hide.
206
- * @param clientType - Optional client type header.
207
- * @returns The resolved user-assets blob that was persisted.
208
- * @throws A `StructError` if any entry of `ids` is not a CAIP-19 asset
209
- * identifier; an `HttpError` if the API responds with a non-2xx status.
210
- */
211
- hideTokens(ids: string[], clientType?: ClientType): Promise<UserAssetsBlob>;
212
- /**
213
- * Wipes the user's custom tokens, restoring a clean slate (empty lists).
214
- *
215
- * @param clientType - Optional client type header.
216
- * @throws An `HttpError` if the API responds with a non-2xx status.
217
- */
218
- clearUserAssets(clientType?: ClientType): Promise<void>;
219
171
  }
220
172
  export {};
221
173
  //# sourceMappingURL=authenticated-user-storage.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"authenticated-user-storage.d.ts","sourceRoot":"","sources":["../src/authenticated-user-storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,4BAA4B,EAC5B,oCAAoC,EACpC,kCAAkC,EACnC,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAC;AAE7E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAGrD,OAAO,KAAK,EAAE,4CAA4C,EAAE,MAAM,qDAAqD,CAAC;AACxH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE5C,OAAO,KAAK,EACV,mBAAmB,EACnB,UAAU,EACV,kBAAkB,EAClB,oBAAoB,EACpB,sBAAsB,EACtB,2BAA2B,EAC3B,gBAAgB,EAChB,uBAAuB,EACvB,cAAc,EACf,MAAM,YAAY,CAAC;AAkBpB;;;GAGG;AACH,eAAO,MAAM,WAAW,oCAAoC,CAAC;AAE7D;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,WAAW,EAAE,WAAW,GAAG,MAAM,CAE3E;AAuBD;;GAEG;AACH,MAAM,MAAM,+CAA+C,GACzD,kCAAkC,CAAC,OAAO,WAAW,CAAC,CAAC;AAEzD;;;GAGG;AACH,MAAM,MAAM,+BAA+B,GACvC,4CAA4C,GAC5C,+CAA+C,CAAC;AAEpD;;;GAGG;AACH,KAAK,4CAA4C,GAAG;IAClD,IAAI,EAAE,yCAAyC,CAAC;IAChD,OAAO,EAAE,CAAC,eAAe,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;CACxD,CAAC;AAEF;;;GAGG;AACH,KAAK,cAAc,GAAG,4CAA4C,CAAC;AAEnE;;GAEG;AACH,MAAM,MAAM,yCAAyC,GACnD,4BAA4B,CAAC,OAAO,WAAW,CAAC,CAAC;AA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CACvB,OAAO,EAAE,gBAAgB,EACzB,UAAU,CAAC,EAAE,UAAU,GACtB,OAAO,CAAC,IAAI,CAAC,CA+Bf;IAED;;;;OAIG;IACG,yBAAyB,IAAI,OAAO,CAAC,sBAAsB,GAAG,IAAI,CAAC,CA8BxE;IAED;;;;;;;;;OASG;IACG,yBAAyB,CAC7B,KAAK,EAAE,2BAA2B,EAClC,UAAU,CAAC,EAAE,UAAU,GACtB,OAAO,CAAC,IAAI,CAAC,CAiCf;IAED;;;;OAIG;IACG,kBAAkB,IAAI,OAAO,CAAC,mBAAmB,GAAG,IAAI,CAAC,CA8B9D;IAED;;;;;;;;;;;OAWG;IACG,kBAAkB,CACtB,IAAI,EAAE,mBAAmB,EACzB,UAAU,CAAC,EAAE,UAAU,GACtB,OAAO,CAAC,IAAI,CAAC,CA8Bf;IAED;;;;OAIG;IACG,aAAa,IAAI,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CA8BpD;IAED;;;;;;;;;OASG;IACG,aAAa,CACjB,IAAI,EAAE,cAAc,EACpB,UAAU,CAAC,EAAE,UAAU,GACtB,OAAO,CAAC,IAAI,CAAC,CAoCf;IAED;;;;;;;;;;OAUG;IACG,YAAY,CAChB,GAAG,EAAE,MAAM,EAAE,EACb,UAAU,CAAC,EAAE,UAAU,GACtB,OAAO,CAAC,cAAc,CAAC,CAwBzB;IAED;;;;;;;;;;OAUG;IACG,UAAU,CACd,GAAG,EAAE,MAAM,EAAE,EACb,UAAU,CAAC,EAAE,UAAU,GACtB,OAAO,CAAC,cAAc,CAAC,CAwBzB;IAED;;;;;OAKG;IACG,eAAe,CAAC,UAAU,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAK5D;CAeF"}
1
+ {"version":3,"file":"authenticated-user-storage.d.ts","sourceRoot":"","sources":["../src/authenticated-user-storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,4BAA4B,EAC5B,oCAAoC,EACpC,kCAAkC,EACnC,MAAM,6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AED;;;;;;;;;OASG;IACG,yBAAyB,CAC7B,KAAK,EAAE,2BAA2B,EAClC,UAAU,CAAC,EAAE,UAAU,GACtB,OAAO,CAAC,IAAI,CAAC,CAiCf;IAED;;;;OAIG;IACG,kBAAkB,IAAI,OAAO,CAAC,mBAAmB,GAAG,IAAI,CAAC,CA8B9D;IAED;;;;;;;;;;;OAWG;IACG,kBAAkB,CACtB,IAAI,EAAE,mBAAmB,EACzB,UAAU,CAAC,EAAE,UAAU,GACtB,OAAO,CAAC,IAAI,CAAC,CA8Bf;CAeF"}
@@ -1,7 +1,7 @@
1
1
  import { BaseDataService } from '@metamask/base-data-service';
2
2
  import { HttpError } from '@metamask/controller-utils';
3
3
  import { getUserStorageApiUrl } from './env.js';
4
- import { assertAssetsWatchlistBlob, assertAssetsWatchlistBlobForWrite, assertDelegationResponseArray, assertIdentitySharingConsent, assertIdentitySharingConsentForWrite, assertMarketingConsent, assertNotificationPreferences, assertUserAssetIds, assertUserAssetsBlob, assertUserAssetsBlobForWrite, assertUserAssetsBlobNormalized, normalizeUserAssetsBlob, } from './validators.js';
4
+ import { assertAssetsWatchlistBlob, assertAssetsWatchlistBlobForWrite, assertDelegationResponseArray, assertIdentitySharingConsent, assertIdentitySharingConsentForWrite, assertMarketingConsent, assertNotificationPreferences, } from './validators.js';
5
5
  // === GENERAL ===
6
6
  /**
7
7
  * The name of the {@link AuthenticatedUserStorageService} service, used to
@@ -30,11 +30,6 @@ const MESSENGER_EXPOSED_METHODS = [
30
30
  'putIdentitySharingConsent',
31
31
  'getAssetsWatchlist',
32
32
  'setAssetsWatchlist',
33
- 'getUserAssets',
34
- 'setUserAssets',
35
- 'importTokens',
36
- 'hideTokens',
37
- 'clearUserAssets',
38
33
  ];
39
34
  // === SERVICE ===
40
35
  /**
@@ -380,145 +375,6 @@ export class AuthenticatedUserStorageService extends BaseDataService {
380
375
  queryKey: [`${this.name}:getAssetsWatchlist`],
381
376
  });
382
377
  }
383
- /**
384
- * Returns the user-assets (custom tokens) blob for the authenticated user.
385
- *
386
- * @returns The user-assets blob, or `null` if none has been set (404).
387
- */
388
- async getUserAssets() {
389
- const url = `${getAuthenticatedStorageUrl(this.#environment)}/preferences/custom-tokens`;
390
- const data = await this.fetchQuery({
391
- queryKey: [`${this.name}:getUserAssets`],
392
- queryFn: async () => {
393
- const headers = await this.#getHeaders();
394
- const response = await fetch(url, { headers });
395
- if (response.status === 404) {
396
- return null;
397
- }
398
- if (!response.ok) {
399
- throw new HttpError(response.status, `Failed to get user assets: ${response.status}`);
400
- }
401
- return response.json();
402
- },
403
- });
404
- if (data === null) {
405
- return null;
406
- }
407
- assertUserAssetsBlob(data);
408
- return data;
409
- }
410
- /**
411
- * Creates or updates the user-assets (custom tokens) blob for the
412
- * authenticated user. The blob is normalized (de-duplicated, conflicts
413
- * resolved fail-open in favor of `importedAssets`) before it is sent.
414
- *
415
- * @param blob - The full user-assets blob, with CAIP-19 asset identifiers.
416
- * @param clientType - Optional client type header.
417
- * @throws A `StructError` if `blob` is structurally invalid; an `HttpError`
418
- * if the API responds with a non-2xx status.
419
- */
420
- async setUserAssets(blob, clientType) {
421
- assertUserAssetsBlobForWrite(blob);
422
- const normalizedBlob = normalizeUserAssetsBlob(blob);
423
- // Cannot reject user input: normalization already resolved conflicts.
424
- assertUserAssetsBlobNormalized(normalizedBlob);
425
- const url = `${getAuthenticatedStorageUrl(this.#environment)}/preferences/custom-tokens`;
426
- await this.fetchQuery({
427
- queryKey: [
428
- `${this.name}:setUserAssets`,
429
- normalizedBlob,
430
- ],
431
- staleTime: 0,
432
- queryFn: async () => {
433
- const headers = await this.#getHeaders(clientType);
434
- const response = await fetch(url, {
435
- method: 'PUT',
436
- headers,
437
- body: JSON.stringify(normalizedBlob),
438
- });
439
- if (!response.ok) {
440
- throw new HttpError(response.status, `Failed to put user assets: ${response.status}`);
441
- }
442
- return null;
443
- },
444
- });
445
- await this.invalidateQueries({
446
- queryKey: [`${this.name}:getUserAssets`],
447
- });
448
- }
449
- /**
450
- * Imports custom tokens: adds the given identifiers to `importedAssets`
451
- * (de-duplicated, order preserved) and removes them from `hiddenAssets`.
452
- * Creates a fresh blob if none exists yet.
453
- *
454
- * @param ids - The CAIP-19 asset identifiers of the tokens to import.
455
- * @param clientType - Optional client type header.
456
- * @returns The resolved user-assets blob that was persisted.
457
- * @throws A `StructError` if any entry of `ids` is not a CAIP-19 asset
458
- * identifier; an `HttpError` if the API responds with a non-2xx status.
459
- */
460
- async importTokens(ids, clientType) {
461
- assertUserAssetIds(ids);
462
- const currentBlob = (await this.getUserAssets()) ?? {
463
- version: 1,
464
- importedAssets: [],
465
- hiddenAssets: [],
466
- };
467
- const importedAssets = new Set(currentBlob.importedAssets);
468
- const hiddenAssets = new Set(currentBlob.hiddenAssets);
469
- for (const assetId of ids) {
470
- importedAssets.add(assetId);
471
- hiddenAssets.delete(assetId);
472
- }
473
- const nextBlob = normalizeUserAssetsBlob({
474
- version: 1,
475
- importedAssets: [...importedAssets],
476
- hiddenAssets: [...hiddenAssets],
477
- });
478
- await this.setUserAssets(nextBlob, clientType);
479
- return nextBlob;
480
- }
481
- /**
482
- * Hides custom tokens: adds the given identifiers to `hiddenAssets`
483
- * (de-duplicated, order preserved) and removes them from
484
- * `importedAssets`. Creates a fresh blob if none exists yet.
485
- *
486
- * @param ids - The CAIP-19 asset identifiers of the tokens to hide.
487
- * @param clientType - Optional client type header.
488
- * @returns The resolved user-assets blob that was persisted.
489
- * @throws A `StructError` if any entry of `ids` is not a CAIP-19 asset
490
- * identifier; an `HttpError` if the API responds with a non-2xx status.
491
- */
492
- async hideTokens(ids, clientType) {
493
- assertUserAssetIds(ids);
494
- const currentBlob = (await this.getUserAssets()) ?? {
495
- version: 1,
496
- importedAssets: [],
497
- hiddenAssets: [],
498
- };
499
- const importedAssets = new Set(currentBlob.importedAssets);
500
- const hiddenAssets = new Set(currentBlob.hiddenAssets);
501
- for (const assetId of ids) {
502
- hiddenAssets.add(assetId);
503
- importedAssets.delete(assetId);
504
- }
505
- const nextBlob = normalizeUserAssetsBlob({
506
- version: 1,
507
- importedAssets: [...importedAssets],
508
- hiddenAssets: [...hiddenAssets],
509
- });
510
- await this.setUserAssets(nextBlob, clientType);
511
- return nextBlob;
512
- }
513
- /**
514
- * Wipes the user's custom tokens, restoring a clean slate (empty lists).
515
- *
516
- * @param clientType - Optional client type header.
517
- * @throws An `HttpError` if the API responds with a non-2xx status.
518
- */
519
- async clearUserAssets(clientType) {
520
- await this.setUserAssets({ version: 1, importedAssets: [], hiddenAssets: [] }, clientType);
521
- }
522
378
  async #getHeaders(clientType) {
523
379
  const accessToken = await this.messenger.call('AuthenticationController:getBearerToken');
524
380
  const headers = {
@@ -1 +1 @@
1
- {"version":3,"file":"authenticated-user-storage.js","sourceRoot":"","sources":["../src/authenticated-user-storage.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAE9D,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAMvD,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAYhD,OAAO,EACL,yBAAyB,EACzB,iCAAiC,EACjC,6BAA6B,EAC7B,4BAA4B,EAC5B,oCAAoC,EACpC,sBAAsB,EACtB,6BAA6B,EAC7B,kBAAkB,EAClB,oBAAoB,EACpB,4BAA4B,EAC5B,8BAA8B,EAC9B,uBAAuB,GACxB,MAAM,iBAAiB,CAAC;AAEzB,kBAAkB;AAElB;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,iCAAiC,CAAC;AAE7D;;;;;GAKG;AACH,MAAM,UAAU,0BAA0B,CAAC,WAAwB;IACjE,OAAO,GAAG,oBAAoB,CAAC,WAAW,CAAC,SAAS,CAAC;AACvD,CAAC;AAED,oBAAoB;AAEpB,MAAM,yBAAyB,GAAG;IAChC,iBAAiB;IACjB,kBAAkB;IAClB,kBAAkB;IAClB,4BAA4B;IAC5B,4BAA4B;IAC5B,qBAAqB;IACrB,qBAAqB;I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G,IAAI,GAAG,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC;QAC3D,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;QACvD,KAAK,MAAM,OAAO,IAAI,GAAG,EAAE,CAAC;YAC1B,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YAC1B,cAAc,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACjC,CAAC;QAED,MAAM,QAAQ,GAAG,uBAAuB,CAAC;YACvC,OAAO,EAAE,CAAC;YACV,cAAc,EAAE,CAAC,GAAG,cAAc,CAAC;YACnC,YAAY,EAAE,CAAC,GAAG,YAAY,CAAC;SAChC,CAAC,CAAC;QAEH,MAAM,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;QAC/C,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,eAAe,CAAC,UAAuB;QAC3C,MAAM,IAAI,CAAC,aAAa,CACtB,EAAE,OAAO,EAAE,CAAC,EAAE,cAAc,EAAE,EAAE,EAAE,YAAY,EAAE,EAAE,EAAE,EACpD,UAAU,CACX,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,UAAuB;QACvC,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAC3C,yCAAyC,CAC1C,CAAC;QACF,MAAM,OAAO,GAA2B;YACtC,cAAc,EAAE,kBAAkB;YAClC,aAAa,EAAE,UAAU,WAAW,EAAE;SACvC,CAAC;QACF,IAAI,UAAU,EAAE,CAAC;YACf,OAAO,CAAC,eAAe,CAAC,GAAG,UAAU,CAAC;QACxC,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;CACF","sourcesContent":["import type {\n DataServiceCacheUpdatedEvent,\n DataServiceGranularCacheUpdatedEvent,\n DataServiceInvalidateQueriesAction,\n} from '@metamask/base-data-service';\nimport { BaseDataService } from '@metamask/base-data-service';\nimport type { CreateServicePolicyOptions } from '@metamask/controller-utils';\nimport { HttpError } from '@metamask/controller-utils';\nimport type { Messenger } from '@metamask/messenger';\nimport type { Json } from '@metamask/utils';\n\nimport type { AuthenticatedUserStorageServiceMethodActions } from './authenticated-user-storage-method-action-types.js';\nimport type { Environment } from './env.js';\nimport { getUserStorageApiUrl } from './env.js';\nimport type {\n AssetsWatchlistBlob,\n ClientType,\n DelegationResponse,\n DelegationSubmission,\n IdentitySharingConsent,\n IdentitySharingConsentWrite,\n MarketingConsent,\n NotificationPreferences,\n UserAssetsBlob,\n} from './types.js';\nimport {\n assertAssetsWatchlistBlob,\n assertAssetsWatchlistBlobForWrite,\n assertDelegationResponseArray,\n assertIdentitySharingConsent,\n assertIdentitySharingConsentForWrite,\n assertMarketingConsent,\n assertNotificationPreferences,\n assertUserAssetIds,\n assertUserAssetsBlob,\n assertUserAssetsBlobForWrite,\n assertUserAssetsBlobNormalized,\n normalizeUserAssetsBlob,\n} from './validators.js';\n\n// === GENERAL ===\n\n/**\n * The name of the {@link AuthenticatedUserStorageService} service, used to\n * namespace the service's actions and events.\n */\nexport const serviceName = 'AuthenticatedUserStorageService';\n\n/**\n * Builds the versioned API base URL for a given environment.\n *\n * @param environment - The target environment.\n * @returns The base URL including the `/api/v1` path segment.\n */\nexport function getAuthenticatedStorageUrl(environment: Environment): string {\n return `${getUserStorageApiUrl(environment)}/api/v1`;\n}\n\n// === MESSENGER ===\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'listDelegations',\n 'createDelegation',\n 'revokeDelegation',\n 'getNotificationPreferences',\n 'putNotificationPreferences',\n 'getMarketingConsent',\n 'putMarketingConsent',\n 'getIdentitySharingConsent',\n 'putIdentitySharingConsent',\n 'getAssetsWatchlist',\n 'setAssetsWatchlist',\n 'getUserAssets',\n 'setUserAssets',\n 'importTokens',\n 'hideTokens',\n 'clearUserAssets',\n] as const;\n\n/**\n * Invalidates cached queries for {@link AuthenticatedUserStorageService}.\n */\nexport type AuthenticatedUserStorageInvalidateQueriesAction =\n DataServiceInvalidateQueriesAction<typeof serviceName>;\n\n/**\n * Actions that {@link AuthenticatedUserStorageService} exposes to other\n * consumers.\n */\nexport type AuthenticatedUserStorageActions =\n | AuthenticatedUserStorageServiceMethodActions\n | AuthenticatedUserStorageInvalidateQueriesAction;\n\n/**\n * Retrieves a bearer token from the `AuthenticationController`, logging in the\n * user if necessary.\n */\ntype AuthenticationControllerGetBearerTokenAction = {\n type: 'AuthenticationController:getBearerToken';\n handler: (entropySourceId?: string) => Promise<string>;\n};\n\n/**\n * Actions from other messengers that {@link AuthenticatedUserStorageService}\n * calls.\n */\ntype AllowedActions = AuthenticationControllerGetBearerTokenAction;\n\n/**\n * Published when {@link AuthenticatedUserStorageService}'s cache is updated.\n */\nexport type AuthenticatedUserStorageCacheUpdatedEvent =\n DataServiceCacheUpdatedEvent<typeof serviceName>;\n\n/**\n * Published when a key within {@link AuthenticatedUserStorageService}'s cache\n * is updated.\n */\nexport type AuthenticatedUserStorageGranularCacheUpdatedEvent =\n DataServiceGranularCacheUpdatedEvent<typeof serviceName>;\n\n/**\n * Events that {@link AuthenticatedUserStorageService} exposes to other\n * consumers.\n */\nexport type AuthenticatedUserStorageEvents =\n | AuthenticatedUserStorageCacheUpdatedEvent\n | AuthenticatedUserStorageGranularCacheUpdatedEvent;\n\n/**\n * Events from other messengers that\n * {@link AuthenticatedUserStorageService} subscribes to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger which is restricted to actions and events accessed by\n * {@link AuthenticatedUserStorageService}.\n */\nexport type AuthenticatedUserStorageMessenger = Messenger<\n typeof serviceName,\n AuthenticatedUserStorageActions | AllowedActions,\n AuthenticatedUserStorageEvents | AllowedEvents\n>;\n\n// === SERVICE ===\n\n/**\n * Data service wrapping authenticated user-storage API endpoints.\n *\n * Provides methods for managing delegations and notification preferences\n * for the authenticated user.\n */\nexport class AuthenticatedUserStorageService extends BaseDataService<\n typeof serviceName,\n AuthenticatedUserStorageMessenger\n> {\n readonly #environment: Environment;\n\n /**\n * Constructs a new AuthenticatedUserStorageService.\n *\n * @param args - The constructor arguments.\n * @param args.messenger - The messenger suited for this service.\n * @param args.environment - The target environment (dev, uat, prod).\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 environment,\n policyOptions,\n }: {\n messenger: AuthenticatedUserStorageMessenger;\n environment: Environment;\n policyOptions?: CreateServicePolicyOptions;\n }) {\n super({ name: serviceName, messenger, policyOptions });\n this.#environment = environment;\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Returns all delegation records belonging to the authenticated user.\n *\n * @returns An array of delegation records, or an empty array if none exist.\n */\n async listDelegations(): Promise<DelegationResponse[]> {\n const url = `${getAuthenticatedStorageUrl(this.#environment)}/delegations`;\n\n const data = await this.fetchQuery({\n queryKey: [`${this.name}:listDelegations`],\n queryFn: async () => {\n const headers = await this.#getHeaders();\n const response = await fetch(url, { headers });\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `Failed to list delegations: ${response.status}`,\n );\n }\n\n return response.json();\n },\n });\n\n assertDelegationResponseArray(data);\n return data;\n }\n\n /**\n * Stores a signed delegation record for the authenticated user.\n *\n * @param submission - The signed delegation and its metadata.\n * @param clientType - Optional client type header.\n */\n async createDelegation(\n submission: DelegationSubmission,\n clientType?: ClientType,\n ): Promise<void> {\n const url = `${getAuthenticatedStorageUrl(this.#environment)}/delegations`;\n\n await this.fetchQuery({\n queryKey: [\n `${this.name}:createDelegation`,\n submission.metadata.delegationHash,\n ],\n staleTime: 0,\n queryFn: async () => {\n const headers = await this.#getHeaders(clientType);\n const response = await fetch(url, {\n method: 'POST',\n headers,\n body: JSON.stringify(submission),\n });\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `Failed to create delegation: ${response.status}`,\n );\n }\n\n return null;\n },\n });\n\n await this.invalidateQueries({\n queryKey: [`${this.name}:listDelegations`],\n });\n }\n\n /**\n * Revokes (deletes) a delegation record.\n *\n * @param delegationHash - The unique hash identifying the delegation.\n */\n async revokeDelegation(delegationHash: string): Promise<void> {\n const url = `${getAuthenticatedStorageUrl(this.#environment)}/delegations/${encodeURIComponent(delegationHash)}`;\n\n await this.fetchQuery({\n queryKey: [`${this.name}:revokeDelegation`, delegationHash],\n staleTime: 0,\n queryFn: async () => {\n const headers = await this.#getHeaders();\n const response = await fetch(url, {\n method: 'DELETE',\n headers,\n });\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `Failed to revoke delegation: ${response.status}`,\n );\n }\n\n return null;\n },\n });\n\n await this.invalidateQueries({\n queryKey: [`${this.name}:listDelegations`],\n });\n }\n\n /**\n * Returns the notification preferences for the authenticated user.\n *\n * @returns The notification preferences object, or `null` if none have been\n * set (404).\n */\n async getNotificationPreferences(): Promise<NotificationPreferences | null> {\n const url = `${getAuthenticatedStorageUrl(this.#environment)}/preferences/notifications`;\n\n const data = await this.fetchQuery({\n queryKey: [`${this.name}:getNotificationPreferences`],\n queryFn: async () => {\n const headers = await this.#getHeaders();\n const response = await fetch(url, { headers });\n\n if (response.status === 404) {\n return null;\n }\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `Failed to get notification preferences: ${response.status}`,\n );\n }\n\n return response.json();\n },\n });\n\n if (data === null) {\n return null;\n }\n\n assertNotificationPreferences(data);\n return data;\n }\n\n /**\n * Creates or updates the notification preferences for the authenticated user.\n *\n * @param prefs - The full notification preferences object.\n * @param clientType - Optional client type header.\n */\n async putNotificationPreferences(\n prefs: NotificationPreferences,\n clientType?: ClientType,\n ): Promise<void> {\n const url = `${getAuthenticatedStorageUrl(this.#environment)}/preferences/notifications`;\n\n await this.fetchQuery({\n queryKey: [\n `${this.name}:putNotificationPreferences`,\n prefs as unknown as Json,\n ],\n staleTime: 0,\n queryFn: async () => {\n const headers = await this.#getHeaders(clientType);\n const response = await fetch(url, {\n method: 'PUT',\n headers,\n body: JSON.stringify(prefs),\n });\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `Failed to put notification preferences: ${response.status}`,\n );\n }\n\n return null;\n },\n });\n\n await this.invalidateQueries({\n queryKey: [`${this.name}:getNotificationPreferences`],\n });\n }\n\n /**\n * Returns the marketing consent for the authenticated user.\n *\n * @returns The marketing consent object, or `null` if none has been\n * set (404).\n */\n async getMarketingConsent(): Promise<MarketingConsent | null> {\n const url = `${getAuthenticatedStorageUrl(this.#environment)}/preferences/marketing-consent`;\n\n const data = await this.fetchQuery({\n queryKey: [`${this.name}:getMarketingConsent`],\n queryFn: async () => {\n const headers = await this.#getHeaders();\n const response = await fetch(url, { headers });\n\n if (response.status === 404) {\n return null;\n }\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `Failed to get marketing consent: ${response.status}`,\n );\n }\n\n return response.json();\n },\n });\n\n if (data === null) {\n return null;\n }\n\n assertMarketingConsent(data);\n return data;\n }\n\n /**\n * Creates or updates the marketing consent for the authenticated user.\n *\n * @param consent - The full marketing consent object.\n * @param clientType - Optional client type header.\n */\n async putMarketingConsent(\n consent: MarketingConsent,\n clientType?: ClientType,\n ): Promise<void> {\n const url = `${getAuthenticatedStorageUrl(this.#environment)}/preferences/marketing-consent`;\n\n await this.fetchQuery({\n queryKey: [\n `${this.name}:putMarketingConsent`,\n consent as unknown as Json,\n ],\n staleTime: 0,\n queryFn: async () => {\n const headers = await this.#getHeaders(clientType);\n const response = await fetch(url, {\n method: 'PUT',\n headers,\n body: JSON.stringify(consent),\n });\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `Failed to put marketing consent: ${response.status}`,\n );\n }\n\n return null;\n },\n });\n\n await this.invalidateQueries({\n queryKey: [`${this.name}:getMarketingConsent`],\n });\n }\n\n /**\n * Returns the identity-sharing consent for the authenticated user.\n *\n * @returns The granted-audience map, or `null` if none has been set (404).\n */\n async getIdentitySharingConsent(): Promise<IdentitySharingConsent | null> {\n const url = `${getAuthenticatedStorageUrl(this.#environment)}/preferences/identity-sharing-consent`;\n\n const data = await this.fetchQuery({\n queryKey: [`${this.name}:getIdentitySharingConsent`],\n queryFn: async () => {\n const headers = await this.#getHeaders();\n const response = await fetch(url, { headers });\n\n if (response.status === 404) {\n return null;\n }\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `Failed to get identity-sharing consent: ${response.status}`,\n );\n }\n\n return response.json();\n },\n });\n\n if (data === null) {\n return null;\n }\n\n assertIdentitySharingConsent(data);\n return data;\n }\n\n /**\n * Grants or revokes identity-sharing consent for a single audience.\n * Other audiences on the profile are left unchanged.\n *\n * @param write - The audience and whether it is granted.\n * @param clientType - Optional client type header.\n * @throws A `StructError` from `@metamask/superstruct` if `write` is\n * invalid; an `HttpError` from `@metamask/controller-utils` if the API\n * responds with a non-2xx status.\n */\n async putIdentitySharingConsent(\n write: IdentitySharingConsentWrite,\n clientType?: ClientType,\n ): Promise<void> {\n assertIdentitySharingConsentForWrite(write);\n\n const url = `${getAuthenticatedStorageUrl(this.#environment)}/preferences/identity-sharing-consent`;\n\n await this.fetchQuery({\n queryKey: [\n `${this.name}:putIdentitySharingConsent`,\n write as unknown as Json,\n ],\n staleTime: 0,\n queryFn: async () => {\n const headers = await this.#getHeaders(clientType);\n const response = await fetch(url, {\n method: 'PUT',\n headers,\n body: JSON.stringify(write),\n });\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `Failed to put identity-sharing consent: ${response.status}`,\n );\n }\n\n return null;\n },\n });\n\n await this.invalidateQueries({\n queryKey: [`${this.name}:getIdentitySharingConsent`],\n });\n }\n\n /**\n * Returns the assets-watchlist for the authenticated user.\n *\n * @returns The assets-watchlist blob, or `null` if none has been set (404).\n */\n async getAssetsWatchlist(): Promise<AssetsWatchlistBlob | null> {\n const url = `${getAuthenticatedStorageUrl(this.#environment)}/preferences/assets-watchlist`;\n\n const data = await this.fetchQuery({\n queryKey: [`${this.name}:getAssetsWatchlist`],\n queryFn: async () => {\n const headers = await this.#getHeaders();\n const response = await fetch(url, { headers });\n\n if (response.status === 404) {\n return null;\n }\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `Failed to get assets watchlist: ${response.status}`,\n );\n }\n\n return response.json();\n },\n });\n\n if (data === null) {\n return null;\n }\n\n assertAssetsWatchlistBlob(data);\n return data;\n }\n\n /**\n * Creates or updates the assets-watchlist for the authenticated user.\n *\n * @param blob - The full assets-watchlist blob. The `assets` array may\n * contain at most `ASSETS_WATCHLIST_MAX_ASSETS` CAIP-19 asset identifiers;\n * this is enforced by `assertAssetsWatchlistBlobForWrite` before the\n * request is sent.\n * @param clientType - Optional client type header.\n * @throws A `StructError` from `@metamask/superstruct` if `blob` is\n * structurally invalid or `assets` exceeds the cap; an `HttpError` from\n * `@metamask/controller-utils` if the API responds with a non-2xx status.\n */\n async setAssetsWatchlist(\n blob: AssetsWatchlistBlob,\n clientType?: ClientType,\n ): Promise<void> {\n assertAssetsWatchlistBlobForWrite(blob);\n\n const url = `${getAuthenticatedStorageUrl(this.#environment)}/preferences/assets-watchlist`;\n\n await this.fetchQuery({\n queryKey: [`${this.name}:setAssetsWatchlist`, blob as unknown as Json],\n staleTime: 0,\n queryFn: async () => {\n const headers = await this.#getHeaders(clientType);\n const response = await fetch(url, {\n method: 'PUT',\n headers,\n body: JSON.stringify(blob),\n });\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `Failed to put assets watchlist: ${response.status}`,\n );\n }\n\n return null;\n },\n });\n\n await this.invalidateQueries({\n queryKey: [`${this.name}:getAssetsWatchlist`],\n });\n }\n\n /**\n * Returns the user-assets (custom tokens) blob for the authenticated user.\n *\n * @returns The user-assets blob, or `null` if none has been set (404).\n */\n async getUserAssets(): Promise<UserAssetsBlob | null> {\n const url = `${getAuthenticatedStorageUrl(this.#environment)}/preferences/custom-tokens`;\n\n const data = await this.fetchQuery({\n queryKey: [`${this.name}:getUserAssets`],\n queryFn: async () => {\n const headers = await this.#getHeaders();\n const response = await fetch(url, { headers });\n\n if (response.status === 404) {\n return null;\n }\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `Failed to get user assets: ${response.status}`,\n );\n }\n\n return response.json();\n },\n });\n\n if (data === null) {\n return null;\n }\n\n assertUserAssetsBlob(data);\n return data;\n }\n\n /**\n * Creates or updates the user-assets (custom tokens) blob for the\n * authenticated user. The blob is normalized (de-duplicated, conflicts\n * resolved fail-open in favor of `importedAssets`) before it is sent.\n *\n * @param blob - The full user-assets blob, with CAIP-19 asset identifiers.\n * @param clientType - Optional client type header.\n * @throws A `StructError` if `blob` is structurally invalid; an `HttpError`\n * if the API responds with a non-2xx status.\n */\n async setUserAssets(\n blob: UserAssetsBlob,\n clientType?: ClientType,\n ): Promise<void> {\n assertUserAssetsBlobForWrite(blob);\n const normalizedBlob = normalizeUserAssetsBlob(blob);\n // Cannot reject user input: normalization already resolved conflicts.\n assertUserAssetsBlobNormalized(normalizedBlob);\n\n const url = `${getAuthenticatedStorageUrl(this.#environment)}/preferences/custom-tokens`;\n\n await this.fetchQuery({\n queryKey: [\n `${this.name}:setUserAssets`,\n normalizedBlob as unknown as Json,\n ],\n staleTime: 0,\n queryFn: async () => {\n const headers = await this.#getHeaders(clientType);\n const response = await fetch(url, {\n method: 'PUT',\n headers,\n body: JSON.stringify(normalizedBlob),\n });\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `Failed to put user assets: ${response.status}`,\n );\n }\n\n return null;\n },\n });\n\n await this.invalidateQueries({\n queryKey: [`${this.name}:getUserAssets`],\n });\n }\n\n /**\n * Imports custom tokens: adds the given identifiers to `importedAssets`\n * (de-duplicated, order preserved) and removes them from `hiddenAssets`.\n * Creates a fresh blob if none exists yet.\n *\n * @param ids - The CAIP-19 asset identifiers of the tokens to import.\n * @param clientType - Optional client type header.\n * @returns The resolved user-assets blob that was persisted.\n * @throws A `StructError` if any entry of `ids` is not a CAIP-19 asset\n * identifier; an `HttpError` if the API responds with a non-2xx status.\n */\n async importTokens(\n ids: string[],\n clientType?: ClientType,\n ): Promise<UserAssetsBlob> {\n assertUserAssetIds(ids);\n\n const currentBlob: UserAssetsBlob = (await this.getUserAssets()) ?? {\n version: 1,\n importedAssets: [],\n hiddenAssets: [],\n };\n\n const importedAssets = new Set(currentBlob.importedAssets);\n const hiddenAssets = new Set(currentBlob.hiddenAssets);\n for (const assetId of ids) {\n importedAssets.add(assetId);\n hiddenAssets.delete(assetId);\n }\n\n const nextBlob = normalizeUserAssetsBlob({\n version: 1,\n importedAssets: [...importedAssets],\n hiddenAssets: [...hiddenAssets],\n });\n\n await this.setUserAssets(nextBlob, clientType);\n return nextBlob;\n }\n\n /**\n * Hides custom tokens: adds the given identifiers to `hiddenAssets`\n * (de-duplicated, order preserved) and removes them from\n * `importedAssets`. Creates a fresh blob if none exists yet.\n *\n * @param ids - The CAIP-19 asset identifiers of the tokens to hide.\n * @param clientType - Optional client type header.\n * @returns The resolved user-assets blob that was persisted.\n * @throws A `StructError` if any entry of `ids` is not a CAIP-19 asset\n * identifier; an `HttpError` if the API responds with a non-2xx status.\n */\n async hideTokens(\n ids: string[],\n clientType?: ClientType,\n ): Promise<UserAssetsBlob> {\n assertUserAssetIds(ids);\n\n const currentBlob: UserAssetsBlob = (await this.getUserAssets()) ?? {\n version: 1,\n importedAssets: [],\n hiddenAssets: [],\n };\n\n const importedAssets = new Set(currentBlob.importedAssets);\n const hiddenAssets = new Set(currentBlob.hiddenAssets);\n for (const assetId of ids) {\n hiddenAssets.add(assetId);\n importedAssets.delete(assetId);\n }\n\n const nextBlob = normalizeUserAssetsBlob({\n version: 1,\n importedAssets: [...importedAssets],\n hiddenAssets: [...hiddenAssets],\n });\n\n await this.setUserAssets(nextBlob, clientType);\n return nextBlob;\n }\n\n /**\n * Wipes the user's custom tokens, restoring a clean slate (empty lists).\n *\n * @param clientType - Optional client type header.\n * @throws An `HttpError` if the API responds with a non-2xx status.\n */\n async clearUserAssets(clientType?: ClientType): Promise<void> {\n await this.setUserAssets(\n { version: 1, importedAssets: [], hiddenAssets: [] },\n clientType,\n );\n }\n\n async #getHeaders(clientType?: ClientType): Promise<Record<string, string>> {\n const accessToken = await this.messenger.call(\n 'AuthenticationController:getBearerToken',\n );\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${accessToken}`,\n };\n if (clientType) {\n headers['X-Client-Type'] = clientType;\n }\n return headers;\n }\n}\n"]}
1
+ {"version":3,"file":"authenticated-user-storage.js","sourceRoot":"","sources":["../src/authenticated-user-storage.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAE9D,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAMvD,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAWhD,OAAO,EACL,yBAAyB,EACzB,iCAAiC,EACjC,6BAA6B,EAC7B,4BAA4B,EAC5B,oCAAoC,EACpC,sBAAsB,EACtB,6BAA6B,GAC9B,MAAM,iBAAiB,CAAC;AAEzB,kBAAkB;AAElB;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,iCAAiC,CAAC;AAE7D;;;;;GAKG;AACH,MAAM,UAAU,0BAA0B,CAAC,WAAwB;IACjE,OAAO,GAAG,oBAAoB,CAAC,WAAW,CAAC,SAAS,CAAC;AACvD,CAAC;AAED,oBAAoB;AAEpB,MAAM,yBAAyB,GAAG;IAChC,iBAAiB;IACjB,kBAAkB;IAClB,kBAAkB;IAClB,4BAA4B;IAC5B,4BAA4B;IAC5B,qBAAqB;IACrB,qBAAqB;IACrB,2BAA2B;IAC3B,2BAA2B;IAC3B,oBAAoB;IACpB,oBAAoB;CACZ,CAAC;AAoEX,kBAAkB;AAElB;;;;;GAKG;AACH,MAAM,OAAO,+BAAgC,SAAQ,eAGpD;IACU,YAAY,CAAc;IAEnC;;;;;;;;OAQG;IACH,YAAY,EACV,SAAS,EACT,WAAW,EACX,aAAa,GAKd;QACC,KAAK,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,SAAS,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,MAAM,EACf,mCAAmC,QAAQ,CAAC,MAAM,EAAE,CACrD,CAAC;gBACJ,CAAC;gBAED,OAAO,IAAI,CAAC;YACd,CAAC;SACF,CAAC,CAAC;QAEH,MAAM,IAAI,CAAC,iBAAiB,CAAC;YAC3B,QAAQ,EAAE,CAAC,GAAG,IAAI,CAAC,IAAI,qBAAqB,CAAC;SAC9C,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,UAAuB;QACvC,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAC3C,yCAAyC,CAC1C,CAAC;QACF,MAAM,OAAO,GAA2B;YACtC,cAAc,EAAE,kBAAkB;YAClC,aAAa,EAAE,UAAU,WAAW,EAAE;SACvC,CAAC;QACF,IAAI,UAAU,EAAE,CAAC;YACf,OAAO,CAAC,eAAe,CAAC,GAAG,UAAU,CAAC;QACxC,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;CACF","sourcesContent":["import type {\n DataServiceCacheUpdatedEvent,\n DataServiceGranularCacheUpdatedEvent,\n DataServiceInvalidateQueriesAction,\n} from '@metamask/base-data-service';\nimport { BaseDataService } from '@metamask/base-data-service';\nimport type { CreateServicePolicyOptions } from '@metamask/controller-utils';\nimport { HttpError } from '@metamask/controller-utils';\nimport type { Messenger } from '@metamask/messenger';\nimport type { Json } from '@metamask/utils';\n\nimport type { AuthenticatedUserStorageServiceMethodActions } from './authenticated-user-storage-method-action-types.js';\nimport type { Environment } from './env.js';\nimport { getUserStorageApiUrl } from './env.js';\nimport type {\n AssetsWatchlistBlob,\n ClientType,\n DelegationResponse,\n DelegationSubmission,\n IdentitySharingConsent,\n IdentitySharingConsentWrite,\n MarketingConsent,\n NotificationPreferences,\n} from './types.js';\nimport {\n assertAssetsWatchlistBlob,\n assertAssetsWatchlistBlobForWrite,\n assertDelegationResponseArray,\n assertIdentitySharingConsent,\n assertIdentitySharingConsentForWrite,\n assertMarketingConsent,\n assertNotificationPreferences,\n} from './validators.js';\n\n// === GENERAL ===\n\n/**\n * The name of the {@link AuthenticatedUserStorageService} service, used to\n * namespace the service's actions and events.\n */\nexport const serviceName = 'AuthenticatedUserStorageService';\n\n/**\n * Builds the versioned API base URL for a given environment.\n *\n * @param environment - The target environment.\n * @returns The base URL including the `/api/v1` path segment.\n */\nexport function getAuthenticatedStorageUrl(environment: Environment): string {\n return `${getUserStorageApiUrl(environment)}/api/v1`;\n}\n\n// === MESSENGER ===\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'listDelegations',\n 'createDelegation',\n 'revokeDelegation',\n 'getNotificationPreferences',\n 'putNotificationPreferences',\n 'getMarketingConsent',\n 'putMarketingConsent',\n 'getIdentitySharingConsent',\n 'putIdentitySharingConsent',\n 'getAssetsWatchlist',\n 'setAssetsWatchlist',\n] as const;\n\n/**\n * Invalidates cached queries for {@link AuthenticatedUserStorageService}.\n */\nexport type AuthenticatedUserStorageInvalidateQueriesAction =\n DataServiceInvalidateQueriesAction<typeof serviceName>;\n\n/**\n * Actions that {@link AuthenticatedUserStorageService} exposes to other\n * consumers.\n */\nexport type AuthenticatedUserStorageActions =\n | AuthenticatedUserStorageServiceMethodActions\n | AuthenticatedUserStorageInvalidateQueriesAction;\n\n/**\n * Retrieves a bearer token from the `AuthenticationController`, logging in the\n * user if necessary.\n */\ntype AuthenticationControllerGetBearerTokenAction = {\n type: 'AuthenticationController:getBearerToken';\n handler: (entropySourceId?: string) => Promise<string>;\n};\n\n/**\n * Actions from other messengers that {@link AuthenticatedUserStorageService}\n * calls.\n */\ntype AllowedActions = AuthenticationControllerGetBearerTokenAction;\n\n/**\n * Published when {@link AuthenticatedUserStorageService}'s cache is updated.\n */\nexport type AuthenticatedUserStorageCacheUpdatedEvent =\n DataServiceCacheUpdatedEvent<typeof serviceName>;\n\n/**\n * Published when a key within {@link AuthenticatedUserStorageService}'s cache\n * is updated.\n */\nexport type AuthenticatedUserStorageGranularCacheUpdatedEvent =\n DataServiceGranularCacheUpdatedEvent<typeof serviceName>;\n\n/**\n * Events that {@link AuthenticatedUserStorageService} exposes to other\n * consumers.\n */\nexport type AuthenticatedUserStorageEvents =\n | AuthenticatedUserStorageCacheUpdatedEvent\n | AuthenticatedUserStorageGranularCacheUpdatedEvent;\n\n/**\n * Events from other messengers that\n * {@link AuthenticatedUserStorageService} subscribes to.\n */\ntype AllowedEvents = never;\n\n/**\n * The messenger which is restricted to actions and events accessed by\n * {@link AuthenticatedUserStorageService}.\n */\nexport type AuthenticatedUserStorageMessenger = Messenger<\n typeof serviceName,\n AuthenticatedUserStorageActions | AllowedActions,\n AuthenticatedUserStorageEvents | AllowedEvents\n>;\n\n// === SERVICE ===\n\n/**\n * Data service wrapping authenticated user-storage API endpoints.\n *\n * Provides methods for managing delegations and notification preferences\n * for the authenticated user.\n */\nexport class AuthenticatedUserStorageService extends BaseDataService<\n typeof serviceName,\n AuthenticatedUserStorageMessenger\n> {\n readonly #environment: Environment;\n\n /**\n * Constructs a new AuthenticatedUserStorageService.\n *\n * @param args - The constructor arguments.\n * @param args.messenger - The messenger suited for this service.\n * @param args.environment - The target environment (dev, uat, prod).\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 environment,\n policyOptions,\n }: {\n messenger: AuthenticatedUserStorageMessenger;\n environment: Environment;\n policyOptions?: CreateServicePolicyOptions;\n }) {\n super({ name: serviceName, messenger, policyOptions });\n this.#environment = environment;\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Returns all delegation records belonging to the authenticated user.\n *\n * @returns An array of delegation records, or an empty array if none exist.\n */\n async listDelegations(): Promise<DelegationResponse[]> {\n const url = `${getAuthenticatedStorageUrl(this.#environment)}/delegations`;\n\n const data = await this.fetchQuery({\n queryKey: [`${this.name}:listDelegations`],\n queryFn: async () => {\n const headers = await this.#getHeaders();\n const response = await fetch(url, { headers });\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `Failed to list delegations: ${response.status}`,\n );\n }\n\n return response.json();\n },\n });\n\n assertDelegationResponseArray(data);\n return data;\n }\n\n /**\n * Stores a signed delegation record for the authenticated user.\n *\n * @param submission - The signed delegation and its metadata.\n * @param clientType - Optional client type header.\n */\n async createDelegation(\n submission: DelegationSubmission,\n clientType?: ClientType,\n ): Promise<void> {\n const url = `${getAuthenticatedStorageUrl(this.#environment)}/delegations`;\n\n await this.fetchQuery({\n queryKey: [\n `${this.name}:createDelegation`,\n submission.metadata.delegationHash,\n ],\n staleTime: 0,\n queryFn: async () => {\n const headers = await this.#getHeaders(clientType);\n const response = await fetch(url, {\n method: 'POST',\n headers,\n body: JSON.stringify(submission),\n });\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `Failed to create delegation: ${response.status}`,\n );\n }\n\n return null;\n },\n });\n\n await this.invalidateQueries({\n queryKey: [`${this.name}:listDelegations`],\n });\n }\n\n /**\n * Revokes (deletes) a delegation record.\n *\n * @param delegationHash - The unique hash identifying the delegation.\n */\n async revokeDelegation(delegationHash: string): Promise<void> {\n const url = `${getAuthenticatedStorageUrl(this.#environment)}/delegations/${encodeURIComponent(delegationHash)}`;\n\n await this.fetchQuery({\n queryKey: [`${this.name}:revokeDelegation`, delegationHash],\n staleTime: 0,\n queryFn: async () => {\n const headers = await this.#getHeaders();\n const response = await fetch(url, {\n method: 'DELETE',\n headers,\n });\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `Failed to revoke delegation: ${response.status}`,\n );\n }\n\n return null;\n },\n });\n\n await this.invalidateQueries({\n queryKey: [`${this.name}:listDelegations`],\n });\n }\n\n /**\n * Returns the notification preferences for the authenticated user.\n *\n * @returns The notification preferences object, or `null` if none have been\n * set (404).\n */\n async getNotificationPreferences(): Promise<NotificationPreferences | null> {\n const url = `${getAuthenticatedStorageUrl(this.#environment)}/preferences/notifications`;\n\n const data = await this.fetchQuery({\n queryKey: [`${this.name}:getNotificationPreferences`],\n queryFn: async () => {\n const headers = await this.#getHeaders();\n const response = await fetch(url, { headers });\n\n if (response.status === 404) {\n return null;\n }\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `Failed to get notification preferences: ${response.status}`,\n );\n }\n\n return response.json();\n },\n });\n\n if (data === null) {\n return null;\n }\n\n assertNotificationPreferences(data);\n return data;\n }\n\n /**\n * Creates or updates the notification preferences for the authenticated user.\n *\n * @param prefs - The full notification preferences object.\n * @param clientType - Optional client type header.\n */\n async putNotificationPreferences(\n prefs: NotificationPreferences,\n clientType?: ClientType,\n ): Promise<void> {\n const url = `${getAuthenticatedStorageUrl(this.#environment)}/preferences/notifications`;\n\n await this.fetchQuery({\n queryKey: [\n `${this.name}:putNotificationPreferences`,\n prefs as unknown as Json,\n ],\n staleTime: 0,\n queryFn: async () => {\n const headers = await this.#getHeaders(clientType);\n const response = await fetch(url, {\n method: 'PUT',\n headers,\n body: JSON.stringify(prefs),\n });\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `Failed to put notification preferences: ${response.status}`,\n );\n }\n\n return null;\n },\n });\n\n await this.invalidateQueries({\n queryKey: [`${this.name}:getNotificationPreferences`],\n });\n }\n\n /**\n * Returns the marketing consent for the authenticated user.\n *\n * @returns The marketing consent object, or `null` if none has been\n * set (404).\n */\n async getMarketingConsent(): Promise<MarketingConsent | null> {\n const url = `${getAuthenticatedStorageUrl(this.#environment)}/preferences/marketing-consent`;\n\n const data = await this.fetchQuery({\n queryKey: [`${this.name}:getMarketingConsent`],\n queryFn: async () => {\n const headers = await this.#getHeaders();\n const response = await fetch(url, { headers });\n\n if (response.status === 404) {\n return null;\n }\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `Failed to get marketing consent: ${response.status}`,\n );\n }\n\n return response.json();\n },\n });\n\n if (data === null) {\n return null;\n }\n\n assertMarketingConsent(data);\n return data;\n }\n\n /**\n * Creates or updates the marketing consent for the authenticated user.\n *\n * @param consent - The full marketing consent object.\n * @param clientType - Optional client type header.\n */\n async putMarketingConsent(\n consent: MarketingConsent,\n clientType?: ClientType,\n ): Promise<void> {\n const url = `${getAuthenticatedStorageUrl(this.#environment)}/preferences/marketing-consent`;\n\n await this.fetchQuery({\n queryKey: [\n `${this.name}:putMarketingConsent`,\n consent as unknown as Json,\n ],\n staleTime: 0,\n queryFn: async () => {\n const headers = await this.#getHeaders(clientType);\n const response = await fetch(url, {\n method: 'PUT',\n headers,\n body: JSON.stringify(consent),\n });\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `Failed to put marketing consent: ${response.status}`,\n );\n }\n\n return null;\n },\n });\n\n await this.invalidateQueries({\n queryKey: [`${this.name}:getMarketingConsent`],\n });\n }\n\n /**\n * Returns the identity-sharing consent for the authenticated user.\n *\n * @returns The granted-audience map, or `null` if none has been set (404).\n */\n async getIdentitySharingConsent(): Promise<IdentitySharingConsent | null> {\n const url = `${getAuthenticatedStorageUrl(this.#environment)}/preferences/identity-sharing-consent`;\n\n const data = await this.fetchQuery({\n queryKey: [`${this.name}:getIdentitySharingConsent`],\n queryFn: async () => {\n const headers = await this.#getHeaders();\n const response = await fetch(url, { headers });\n\n if (response.status === 404) {\n return null;\n }\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `Failed to get identity-sharing consent: ${response.status}`,\n );\n }\n\n return response.json();\n },\n });\n\n if (data === null) {\n return null;\n }\n\n assertIdentitySharingConsent(data);\n return data;\n }\n\n /**\n * Grants or revokes identity-sharing consent for a single audience.\n * Other audiences on the profile are left unchanged.\n *\n * @param write - The audience and whether it is granted.\n * @param clientType - Optional client type header.\n * @throws A `StructError` from `@metamask/superstruct` if `write` is\n * invalid; an `HttpError` from `@metamask/controller-utils` if the API\n * responds with a non-2xx status.\n */\n async putIdentitySharingConsent(\n write: IdentitySharingConsentWrite,\n clientType?: ClientType,\n ): Promise<void> {\n assertIdentitySharingConsentForWrite(write);\n\n const url = `${getAuthenticatedStorageUrl(this.#environment)}/preferences/identity-sharing-consent`;\n\n await this.fetchQuery({\n queryKey: [\n `${this.name}:putIdentitySharingConsent`,\n write as unknown as Json,\n ],\n staleTime: 0,\n queryFn: async () => {\n const headers = await this.#getHeaders(clientType);\n const response = await fetch(url, {\n method: 'PUT',\n headers,\n body: JSON.stringify(write),\n });\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `Failed to put identity-sharing consent: ${response.status}`,\n );\n }\n\n return null;\n },\n });\n\n await this.invalidateQueries({\n queryKey: [`${this.name}:getIdentitySharingConsent`],\n });\n }\n\n /**\n * Returns the assets-watchlist for the authenticated user.\n *\n * @returns The assets-watchlist blob, or `null` if none has been set (404).\n */\n async getAssetsWatchlist(): Promise<AssetsWatchlistBlob | null> {\n const url = `${getAuthenticatedStorageUrl(this.#environment)}/preferences/assets-watchlist`;\n\n const data = await this.fetchQuery({\n queryKey: [`${this.name}:getAssetsWatchlist`],\n queryFn: async () => {\n const headers = await this.#getHeaders();\n const response = await fetch(url, { headers });\n\n if (response.status === 404) {\n return null;\n }\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `Failed to get assets watchlist: ${response.status}`,\n );\n }\n\n return response.json();\n },\n });\n\n if (data === null) {\n return null;\n }\n\n assertAssetsWatchlistBlob(data);\n return data;\n }\n\n /**\n * Creates or updates the assets-watchlist for the authenticated user.\n *\n * @param blob - The full assets-watchlist blob. The `assets` array may\n * contain at most `ASSETS_WATCHLIST_MAX_ASSETS` CAIP-19 asset identifiers;\n * this is enforced by `assertAssetsWatchlistBlobForWrite` before the\n * request is sent.\n * @param clientType - Optional client type header.\n * @throws A `StructError` from `@metamask/superstruct` if `blob` is\n * structurally invalid or `assets` exceeds the cap; an `HttpError` from\n * `@metamask/controller-utils` if the API responds with a non-2xx status.\n */\n async setAssetsWatchlist(\n blob: AssetsWatchlistBlob,\n clientType?: ClientType,\n ): Promise<void> {\n assertAssetsWatchlistBlobForWrite(blob);\n\n const url = `${getAuthenticatedStorageUrl(this.#environment)}/preferences/assets-watchlist`;\n\n await this.fetchQuery({\n queryKey: [`${this.name}:setAssetsWatchlist`, blob as unknown as Json],\n staleTime: 0,\n queryFn: async () => {\n const headers = await this.#getHeaders(clientType);\n const response = await fetch(url, {\n method: 'PUT',\n headers,\n body: JSON.stringify(blob),\n });\n\n if (!response.ok) {\n throw new HttpError(\n response.status,\n `Failed to put assets watchlist: ${response.status}`,\n );\n }\n\n return null;\n },\n });\n\n await this.invalidateQueries({\n queryKey: [`${this.name}:getAssetsWatchlist`],\n });\n }\n\n async #getHeaders(clientType?: ClientType): Promise<Record<string, string>> {\n const accessToken = await this.messenger.call(\n 'AuthenticationController:getBearerToken',\n );\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${accessToken}`,\n };\n if (clientType) {\n headers['X-Client-Type'] = clientType;\n }\n return headers;\n }\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  export { getAuthenticatedStorageUrl, AuthenticatedUserStorageService, } from './authenticated-user-storage.js';
2
- export { ASSETS_WATCHLIST_MAX_ASSETS, DEFAULT_AGENTIC_CLI_PREFERENCES, DEFAULT_PRICE_ALERT_PREFERENCES, USER_ASSETS_MAX_ASSETS, } from './validators.js';
2
+ export { ASSETS_WATCHLIST_MAX_ASSETS, DEFAULT_AGENTIC_CLI_PREFERENCES, DEFAULT_PRICE_ALERT_PREFERENCES, } from './validators.js';
3
3
  export type { AuthenticatedUserStorageActions, AuthenticatedUserStorageCacheUpdatedEvent, AuthenticatedUserStorageEvents, AuthenticatedUserStorageGranularCacheUpdatedEvent, AuthenticatedUserStorageInvalidateQueriesAction, AuthenticatedUserStorageMessenger, } from './authenticated-user-storage.js';
4
- export type { AuthenticatedUserStorageServiceListDelegationsAction, AuthenticatedUserStorageServiceCreateDelegationAction, AuthenticatedUserStorageServiceRevokeDelegationAction, AuthenticatedUserStorageServiceGetNotificationPreferencesAction, AuthenticatedUserStorageServicePutNotificationPreferencesAction, AuthenticatedUserStorageServiceGetMarketingConsentAction, AuthenticatedUserStorageServicePutMarketingConsentAction, AuthenticatedUserStorageServiceGetIdentitySharingConsentAction, AuthenticatedUserStorageServicePutIdentitySharingConsentAction, AuthenticatedUserStorageServiceGetAssetsWatchlistAction, AuthenticatedUserStorageServiceSetAssetsWatchlistAction, AuthenticatedUserStorageServiceGetUserAssetsAction, AuthenticatedUserStorageServiceSetUserAssetsAction, AuthenticatedUserStorageServiceImportTokensAction, AuthenticatedUserStorageServiceHideTokensAction, AuthenticatedUserStorageServiceClearUserAssetsAction, } from './authenticated-user-storage-method-action-types.js';
4
+ export type { AuthenticatedUserStorageServiceListDelegationsAction, AuthenticatedUserStorageServiceCreateDelegationAction, AuthenticatedUserStorageServiceRevokeDelegationAction, AuthenticatedUserStorageServiceGetNotificationPreferencesAction, AuthenticatedUserStorageServicePutNotificationPreferencesAction, AuthenticatedUserStorageServiceGetMarketingConsentAction, AuthenticatedUserStorageServicePutMarketingConsentAction, AuthenticatedUserStorageServiceGetIdentitySharingConsentAction, AuthenticatedUserStorageServicePutIdentitySharingConsentAction, AuthenticatedUserStorageServiceGetAssetsWatchlistAction, AuthenticatedUserStorageServiceSetAssetsWatchlistAction, } from './authenticated-user-storage-method-action-types.js';
5
5
  export { getUserStorageApiUrl } from './env.js';
6
6
  export type { Environment } from './env.js';
7
- export type { Caveat, SignedDelegation, DelegationMetadata, DelegationSubmission, DelegationResponse, WalletActivityAccount, WalletActivityPreference, MarketingConsent, IdentitySharingAudience, IdentitySharingConsent, IdentitySharingConsentWrite, MarketingPreference, PerpsWatchlistExchange, PerpsWatchlistMarkets, PerpsPreference, SocialAIPreference, AgenticCliPreference, PriceAlertPreference, NotificationPreferences, AssetsWatchlistBlob, UserAssetsBlob, ClientType, } from './types.js';
7
+ export type { Caveat, SignedDelegation, DelegationMetadata, DelegationSubmission, DelegationResponse, WalletActivityAccount, WalletActivityPreference, MarketingConsent, IdentitySharingAudience, IdentitySharingConsent, IdentitySharingConsentWrite, MarketingPreference, PerpsWatchlistExchange, PerpsWatchlistMarkets, PerpsPreference, SocialAIPreference, AgenticCliPreference, PriceAlertPreference, NotificationPreferences, AssetsWatchlistBlob, ClientType, } from './types.js';
8
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0BAA0B,EAC1B,+BAA+B,GAChC,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,2BAA2B,EAC3B,+BAA+B,EAC/B,+BAA+B,EAC/B,sBAAsB,GACvB,MAAM,iBAAiB,CAAC;AACzB,YAAY,EACV,+BAA+B,EAC/B,yCAAyC,EACzC,8BAA8B,EAC9B,iDAAiD,EACjD,+CAA+C,EAC/C,iCAAiC,GAClC,MAAM,iCAAiC,CAAC;AACzC,YAAY,EACV,oDAAoD,EACpD,qDAAqD,EACrD,qDAAqD,EACrD,+DAA+D,EAC/D,+DAA+D,EAC/D,wDAAwD,EACxD,wDAAwD,EACxD,8DAA8D,EAC9D,8DAA8D,EAC9D,uDAAuD,EACvD,uDAAuD,EACvD,kDAAkD,EAClD,kDAAkD,EAClD,iDAAiD,EACjD,+CAA+C,EAC/C,oDAAoD,GACrD,MAAM,qDAAqD,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAChD,YAAY,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAC5C,YAAY,EACV,MAAM,EACN,gBAAgB,EAChB,kBAAkB,EAClB,oBAAoB,EACpB,kBAAkB,EAClB,qBAAqB,EACrB,wBAAwB,EACxB,gBAAgB,EAChB,uBAAuB,EACvB,sBAAsB,EACtB,2BAA2B,EAC3B,mBAAmB,EACnB,sBAAsB,EACtB,qBAAqB,EACrB,eAAe,EACf,kBAAkB,EAClB,oBAAoB,EACpB,oBAAoB,EACpB,uBAAuB,EACvB,mBAAmB,EACnB,cAAc,EACd,UAAU,GACX,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0BAA0B,EAC1B,+BAA+B,GAChC,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,2BAA2B,EAC3B,+BAA+B,EAC/B,+BAA+B,GAChC,MAAM,iBAAiB,CAAC;AACzB,YAAY,EACV,+BAA+B,EAC/B,yCAAyC,EACzC,8BAA8B,EAC9B,iDAAiD,EACjD,+CAA+C,EAC/C,iCAAiC,GAClC,MAAM,iCAAiC,CAAC;AACzC,YAAY,EACV,oDAAoD,EACpD,qDAAqD,EACrD,qDAAqD,EACrD,+DAA+D,EAC/D,+DAA+D,EAC/D,wDAAwD,EACxD,wDAAwD,EACxD,8DAA8D,EAC9D,8DAA8D,EAC9D,uDAAuD,EACvD,uDAAuD,GACxD,MAAM,qDAAqD,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAChD,YAAY,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAC5C,YAAY,EACV,MAAM,EACN,gBAAgB,EAChB,kBAAkB,EAClB,oBAAoB,EACpB,kBAAkB,EAClB,qBAAqB,EACrB,wBAAwB,EACxB,gBAAgB,EAChB,uBAAuB,EACvB,sBAAsB,EACtB,2BAA2B,EAC3B,mBAAmB,EACnB,sBAAsB,EACtB,qBAAqB,EACrB,eAAe,EACf,kBAAkB,EAClB,oBAAoB,EACpB,oBAAoB,EACpB,uBAAuB,EACvB,mBAAmB,EACnB,UAAU,GACX,MAAM,YAAY,CAAC"}
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  export { getAuthenticatedStorageUrl, AuthenticatedUserStorageService, } from './authenticated-user-storage.js';
2
- export { ASSETS_WATCHLIST_MAX_ASSETS, DEFAULT_AGENTIC_CLI_PREFERENCES, DEFAULT_PRICE_ALERT_PREFERENCES, USER_ASSETS_MAX_ASSETS, } from './validators.js';
2
+ export { ASSETS_WATCHLIST_MAX_ASSETS, DEFAULT_AGENTIC_CLI_PREFERENCES, DEFAULT_PRICE_ALERT_PREFERENCES, } from './validators.js';
3
3
  export { getUserStorageApiUrl } from './env.js';
4
4
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0BAA0B,EAC1B,+BAA+B,GAChC,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,2BAA2B,EAC3B,+BAA+B,EAC/B,+BAA+B,EAC/B,sBAAsB,GACvB,MAAM,iBAAiB,CAAC;AA2BzB,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC","sourcesContent":["export {\n getAuthenticatedStorageUrl,\n AuthenticatedUserStorageService,\n} from './authenticated-user-storage.js';\nexport {\n ASSETS_WATCHLIST_MAX_ASSETS,\n DEFAULT_AGENTIC_CLI_PREFERENCES,\n DEFAULT_PRICE_ALERT_PREFERENCES,\n USER_ASSETS_MAX_ASSETS,\n} from './validators.js';\nexport type {\n AuthenticatedUserStorageActions,\n AuthenticatedUserStorageCacheUpdatedEvent,\n AuthenticatedUserStorageEvents,\n AuthenticatedUserStorageGranularCacheUpdatedEvent,\n AuthenticatedUserStorageInvalidateQueriesAction,\n AuthenticatedUserStorageMessenger,\n} from './authenticated-user-storage.js';\nexport type {\n AuthenticatedUserStorageServiceListDelegationsAction,\n AuthenticatedUserStorageServiceCreateDelegationAction,\n AuthenticatedUserStorageServiceRevokeDelegationAction,\n AuthenticatedUserStorageServiceGetNotificationPreferencesAction,\n AuthenticatedUserStorageServicePutNotificationPreferencesAction,\n AuthenticatedUserStorageServiceGetMarketingConsentAction,\n AuthenticatedUserStorageServicePutMarketingConsentAction,\n AuthenticatedUserStorageServiceGetIdentitySharingConsentAction,\n AuthenticatedUserStorageServicePutIdentitySharingConsentAction,\n AuthenticatedUserStorageServiceGetAssetsWatchlistAction,\n AuthenticatedUserStorageServiceSetAssetsWatchlistAction,\n AuthenticatedUserStorageServiceGetUserAssetsAction,\n AuthenticatedUserStorageServiceSetUserAssetsAction,\n AuthenticatedUserStorageServiceImportTokensAction,\n AuthenticatedUserStorageServiceHideTokensAction,\n AuthenticatedUserStorageServiceClearUserAssetsAction,\n} from './authenticated-user-storage-method-action-types.js';\nexport { getUserStorageApiUrl } from './env.js';\nexport type { Environment } from './env.js';\nexport type {\n Caveat,\n SignedDelegation,\n DelegationMetadata,\n DelegationSubmission,\n DelegationResponse,\n WalletActivityAccount,\n WalletActivityPreference,\n MarketingConsent,\n IdentitySharingAudience,\n IdentitySharingConsent,\n IdentitySharingConsentWrite,\n MarketingPreference,\n PerpsWatchlistExchange,\n PerpsWatchlistMarkets,\n PerpsPreference,\n SocialAIPreference,\n AgenticCliPreference,\n PriceAlertPreference,\n NotificationPreferences,\n AssetsWatchlistBlob,\n UserAssetsBlob,\n ClientType,\n} from './types.js';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0BAA0B,EAC1B,+BAA+B,GAChC,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,2BAA2B,EAC3B,+BAA+B,EAC/B,+BAA+B,GAChC,MAAM,iBAAiB,CAAC;AAsBzB,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC","sourcesContent":["export {\n getAuthenticatedStorageUrl,\n AuthenticatedUserStorageService,\n} from './authenticated-user-storage.js';\nexport {\n ASSETS_WATCHLIST_MAX_ASSETS,\n DEFAULT_AGENTIC_CLI_PREFERENCES,\n DEFAULT_PRICE_ALERT_PREFERENCES,\n} from './validators.js';\nexport type {\n AuthenticatedUserStorageActions,\n AuthenticatedUserStorageCacheUpdatedEvent,\n AuthenticatedUserStorageEvents,\n AuthenticatedUserStorageGranularCacheUpdatedEvent,\n AuthenticatedUserStorageInvalidateQueriesAction,\n AuthenticatedUserStorageMessenger,\n} from './authenticated-user-storage.js';\nexport type {\n AuthenticatedUserStorageServiceListDelegationsAction,\n AuthenticatedUserStorageServiceCreateDelegationAction,\n AuthenticatedUserStorageServiceRevokeDelegationAction,\n AuthenticatedUserStorageServiceGetNotificationPreferencesAction,\n AuthenticatedUserStorageServicePutNotificationPreferencesAction,\n AuthenticatedUserStorageServiceGetMarketingConsentAction,\n AuthenticatedUserStorageServicePutMarketingConsentAction,\n AuthenticatedUserStorageServiceGetIdentitySharingConsentAction,\n AuthenticatedUserStorageServicePutIdentitySharingConsentAction,\n AuthenticatedUserStorageServiceGetAssetsWatchlistAction,\n AuthenticatedUserStorageServiceSetAssetsWatchlistAction,\n} from './authenticated-user-storage-method-action-types.js';\nexport { getUserStorageApiUrl } from './env.js';\nexport type { Environment } from './env.js';\nexport type {\n Caveat,\n SignedDelegation,\n DelegationMetadata,\n DelegationSubmission,\n DelegationResponse,\n WalletActivityAccount,\n WalletActivityPreference,\n MarketingConsent,\n IdentitySharingAudience,\n IdentitySharingConsent,\n IdentitySharingConsentWrite,\n MarketingPreference,\n PerpsWatchlistExchange,\n PerpsWatchlistMarkets,\n PerpsPreference,\n SocialAIPreference,\n AgenticCliPreference,\n PriceAlertPreference,\n NotificationPreferences,\n AssetsWatchlistBlob,\n ClientType,\n} from './types.js';\n"]}
package/dist/types.d.ts CHANGED
@@ -120,7 +120,6 @@ export type IdentitySharingConsentWrite = {
120
120
  granted: boolean;
121
121
  };
122
122
  export type { AssetsWatchlistBlob } from './validators.js';
123
- export type { UserAssetsBlob } from './validators.js';
124
123
  /** The type of client making the request. */
125
124
  export type ClientType = 'extension' | 'mobile' | 'portfolio';
126
125
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAM3C,gDAAgD;AAChD,MAAM,MAAM,MAAM,GAAG;IACnB,6DAA6D;IAC7D,QAAQ,EAAE,GAAG,CAAC;IACd,8CAA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,GAAG,QAAQ,GAAG,WAAW,CAAC"}
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Hex } from '@metamask/utils';\n\n// ---------------------------------------------------------------------------\n// Delegations\n// ---------------------------------------------------------------------------\n\n/** A single caveat attached to a delegation. */\nexport type Caveat = {\n /** Address of the caveat enforcer contract (0x-prefixed). */\n enforcer: Hex;\n /** ABI-encoded caveat terms (0x-prefixed). */\n terms: Hex;\n /** ABI-encoded caveat arguments (0x-prefixed). */\n args: Hex;\n};\n\n/** An EIP-712 signed delegation. */\nexport type SignedDelegation = {\n /** Address the delegation is granted to (0x-prefixed). */\n delegate: Hex;\n /** Address granting the delegation (0x-prefixed). */\n delegator: Hex;\n /** Root authority or parent delegation hash (0x-prefixed). */\n authority: Hex;\n /** Caveats restricting how the delegation may be used. */\n caveats: Caveat[];\n /** Unique salt to prevent replay (0x-prefixed). */\n salt: Hex;\n /** EIP-712 signature over the delegation (0x-prefixed). */\n signature: Hex;\n};\n\n/** Metadata associated with a delegation. */\nexport type DelegationMetadata = {\n /** Keccak-256 hash uniquely identifying the delegation (0x-prefixed). */\n delegationHash: Hex;\n /** Chain ID in hex format (0x-prefixed). */\n chainIdHex: Hex;\n /** Token allowance in hex format (0x-prefixed). */\n allowance: Hex;\n /** Symbol of the token (e.g. \"USDC\"). */\n tokenSymbol: string;\n /** Token contract address (0x-prefixed). */\n tokenAddress: Hex;\n /** Type of delegation. */\n type: string;\n};\n\n/** Request body for submitting a new delegation. */\nexport type DelegationSubmission = {\n signedDelegation: SignedDelegation;\n metadata: DelegationMetadata;\n};\n\n/** A stored delegation record returned by the API. */\nexport type DelegationResponse = {\n signedDelegation: SignedDelegation;\n metadata: DelegationMetadata;\n};\n\n// ---------------------------------------------------------------------------\n// Preferences\n// ---------------------------------------------------------------------------\n\n/** Wallet activity tracking for a single address. */\nexport type WalletActivityAccount = {\n /** Wallet address to track activity for (0x-prefixed). */\n address: Hex;\n enabled: boolean;\n};\n\nexport type AgenticCliPreference = {\n inAppNotificationsEnabled: boolean;\n pushNotificationsEnabled: boolean;\n};\n\nexport type WalletActivityPreference = {\n inAppNotificationsEnabled: boolean;\n pushNotificationsEnabled: boolean;\n accounts: WalletActivityAccount[];\n};\n\nexport type MarketingPreference = {\n inAppNotificationsEnabled: boolean;\n pushNotificationsEnabled: boolean;\n};\n\nexport type PerpsWatchlistExchange = {\n testnet: string[];\n mainnet: string[];\n};\n\nexport type PerpsWatchlistMarkets = {\n hyperliquid: PerpsWatchlistExchange;\n};\n\nexport type PerpsPreference = {\n inAppNotificationsEnabled: boolean;\n pushNotificationsEnabled: boolean;\n watchlistMarkets?: PerpsWatchlistMarkets;\n};\n\nexport type SocialAIPreference = {\n inAppNotificationsEnabled: boolean;\n pushNotificationsEnabled: boolean;\n txAmountLimit?: number;\n mutedTraderProfileIds: string[];\n};\n\nexport type PriceAlertPreference = {\n inAppNotificationsEnabled: boolean;\n pushNotificationsEnabled: boolean;\n};\n\n/**\n * Notification preferences for the authenticated user.\n */\nexport type NotificationPreferences = {\n walletActivity: WalletActivityPreference;\n marketing: MarketingPreference;\n perps: PerpsPreference;\n socialAI: SocialAIPreference;\n agenticCli: AgenticCliPreference;\n priceAlerts: PriceAlertPreference;\n};\n\n// ---------------------------------------------------------------------------\n// Marketing consent\n// ---------------------------------------------------------------------------\n\n/** Marketing consent for the authenticated user (master toggle). */\nexport type MarketingConsent = {\n marketingConsentEnabled: boolean;\n};\n\n// ---------------------------------------------------------------------------\n// Identity-sharing consent\n// ---------------------------------------------------------------------------\n\n/** Partner audience that may receive verified identity claims. */\nexport type IdentitySharingAudience = 'kyc' | 'iron';\n\n/**\n * Granted identity-sharing audiences for the authenticated user.\n * Only granted keys are present; a missing key is not granted.\n */\nexport type IdentitySharingConsent = {\n kyc?: boolean;\n iron?: boolean;\n};\n\n/** Body for granting or revoking a single identity-sharing audience. */\nexport type IdentitySharingConsentWrite = {\n audience: IdentitySharingAudience;\n granted: boolean;\n};\n\n// ---------------------------------------------------------------------------\n// Assets watchlist\n// ---------------------------------------------------------------------------\n\n// `AssetsWatchlistBlob` is inferred from `AssetsWatchlistBlobSchema` in\n// `./validators` and re-exported here so the public type surface remains in\n// `./types`. Keeping the runtime schema and the static type co-located in\n// one file keeps the two in lock-step.\nexport type { AssetsWatchlistBlob } from './validators.js';\n\n// ---------------------------------------------------------------------------\n// User assets (custom tokens)\n// ---------------------------------------------------------------------------\n\n// Re-exported from './validators' so the public type surface stays in './types'.\nexport type { UserAssetsBlob } from './validators.js';\n\n// ---------------------------------------------------------------------------\n// Shared\n// ---------------------------------------------------------------------------\n\n/** The type of client making the request. */\nexport type ClientType = 'extension' | 'mobile' | 'portfolio';\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Hex } from '@metamask/utils';\n\n// ---------------------------------------------------------------------------\n// Delegations\n// ---------------------------------------------------------------------------\n\n/** A single caveat attached to a delegation. */\nexport type Caveat = {\n /** Address of the caveat enforcer contract (0x-prefixed). */\n enforcer: Hex;\n /** ABI-encoded caveat terms (0x-prefixed). */\n terms: Hex;\n /** ABI-encoded caveat arguments (0x-prefixed). */\n args: Hex;\n};\n\n/** An EIP-712 signed delegation. */\nexport type SignedDelegation = {\n /** Address the delegation is granted to (0x-prefixed). */\n delegate: Hex;\n /** Address granting the delegation (0x-prefixed). */\n delegator: Hex;\n /** Root authority or parent delegation hash (0x-prefixed). */\n authority: Hex;\n /** Caveats restricting how the delegation may be used. */\n caveats: Caveat[];\n /** Unique salt to prevent replay (0x-prefixed). */\n salt: Hex;\n /** EIP-712 signature over the delegation (0x-prefixed). */\n signature: Hex;\n};\n\n/** Metadata associated with a delegation. */\nexport type DelegationMetadata = {\n /** Keccak-256 hash uniquely identifying the delegation (0x-prefixed). */\n delegationHash: Hex;\n /** Chain ID in hex format (0x-prefixed). */\n chainIdHex: Hex;\n /** Token allowance in hex format (0x-prefixed). */\n allowance: Hex;\n /** Symbol of the token (e.g. \"USDC\"). */\n tokenSymbol: string;\n /** Token contract address (0x-prefixed). */\n tokenAddress: Hex;\n /** Type of delegation. */\n type: string;\n};\n\n/** Request body for submitting a new delegation. */\nexport type DelegationSubmission = {\n signedDelegation: SignedDelegation;\n metadata: DelegationMetadata;\n};\n\n/** A stored delegation record returned by the API. */\nexport type DelegationResponse = {\n signedDelegation: SignedDelegation;\n metadata: DelegationMetadata;\n};\n\n// ---------------------------------------------------------------------------\n// Preferences\n// ---------------------------------------------------------------------------\n\n/** Wallet activity tracking for a single address. */\nexport type WalletActivityAccount = {\n /** Wallet address to track activity for (0x-prefixed). */\n address: Hex;\n enabled: boolean;\n};\n\nexport type AgenticCliPreference = {\n inAppNotificationsEnabled: boolean;\n pushNotificationsEnabled: boolean;\n};\n\nexport type WalletActivityPreference = {\n inAppNotificationsEnabled: boolean;\n pushNotificationsEnabled: boolean;\n accounts: WalletActivityAccount[];\n};\n\nexport type MarketingPreference = {\n inAppNotificationsEnabled: boolean;\n pushNotificationsEnabled: boolean;\n};\n\nexport type PerpsWatchlistExchange = {\n testnet: string[];\n mainnet: string[];\n};\n\nexport type PerpsWatchlistMarkets = {\n hyperliquid: PerpsWatchlistExchange;\n};\n\nexport type PerpsPreference = {\n inAppNotificationsEnabled: boolean;\n pushNotificationsEnabled: boolean;\n watchlistMarkets?: PerpsWatchlistMarkets;\n};\n\nexport type SocialAIPreference = {\n inAppNotificationsEnabled: boolean;\n pushNotificationsEnabled: boolean;\n txAmountLimit?: number;\n mutedTraderProfileIds: string[];\n};\n\nexport type PriceAlertPreference = {\n inAppNotificationsEnabled: boolean;\n pushNotificationsEnabled: boolean;\n};\n\n/**\n * Notification preferences for the authenticated user.\n */\nexport type NotificationPreferences = {\n walletActivity: WalletActivityPreference;\n marketing: MarketingPreference;\n perps: PerpsPreference;\n socialAI: SocialAIPreference;\n agenticCli: AgenticCliPreference;\n priceAlerts: PriceAlertPreference;\n};\n\n// ---------------------------------------------------------------------------\n// Marketing consent\n// ---------------------------------------------------------------------------\n\n/** Marketing consent for the authenticated user (master toggle). */\nexport type MarketingConsent = {\n marketingConsentEnabled: boolean;\n};\n\n// ---------------------------------------------------------------------------\n// Identity-sharing consent\n// ---------------------------------------------------------------------------\n\n/** Partner audience that may receive verified identity claims. */\nexport type IdentitySharingAudience = 'kyc' | 'iron';\n\n/**\n * Granted identity-sharing audiences for the authenticated user.\n * Only granted keys are present; a missing key is not granted.\n */\nexport type IdentitySharingConsent = {\n kyc?: boolean;\n iron?: boolean;\n};\n\n/** Body for granting or revoking a single identity-sharing audience. */\nexport type IdentitySharingConsentWrite = {\n audience: IdentitySharingAudience;\n granted: boolean;\n};\n\n// ---------------------------------------------------------------------------\n// Assets watchlist\n// ---------------------------------------------------------------------------\n\n// `AssetsWatchlistBlob` is inferred from `AssetsWatchlistBlobSchema` in\n// `./validators` and re-exported here so the public type surface remains in\n// `./types`. Keeping the runtime schema and the static type co-located in\n// one file keeps the two in lock-step.\nexport type { AssetsWatchlistBlob } from './validators.js';\n\n// ---------------------------------------------------------------------------\n// Shared\n// ---------------------------------------------------------------------------\n\n/** The type of client making the request. */\nexport type ClientType = 'extension' | 'mobile' | 'portfolio';\n"]}
@@ -103,69 +103,5 @@ export declare function assertAssetsWatchlistBlob(data: unknown): asserts data i
103
103
  * (including the size constraint).
104
104
  */
105
105
  export declare function assertAssetsWatchlistBlobForWrite(data: unknown): asserts data is AssetsWatchlistBlob;
106
- /**
107
- * The shape we accept on the way **in** from the server. Lenient by design:
108
- * a malformed payload throws, but a well-formed payload whose entries are
109
- * not valid CAIP-19 asset identifiers is still considered valid so we don't
110
- * reject existing server-side data.
111
- */
112
- declare const UserAssetsBlobSchema: import("@metamask/superstruct").Struct<{
113
- version: 1;
114
- importedAssets: string[];
115
- hiddenAssets: string[];
116
- }, {
117
- version: import("@metamask/superstruct").Struct<1, 1>;
118
- importedAssets: import("@metamask/superstruct").Struct<string[], import("@metamask/superstruct").Struct<string, null>>;
119
- hiddenAssets: import("@metamask/superstruct").Struct<string[], import("@metamask/superstruct").Struct<string, null>>;
120
- }>;
121
- /**
122
- * The maximum number of entries per list (`importedAssets`/`hiddenAssets`)
123
- * accepted on writes, mirroring the custom-tokens API's server-side cap.
124
- */
125
- export declare const USER_ASSETS_MAX_ASSETS = 100;
126
- /**
127
- * The authenticated user's custom tokens: mutually exclusive lists of
128
- * CAIP-19 asset identifiers the user chose to import or hide.
129
- */
130
- export type UserAssetsBlob = Infer<typeof UserAssetsBlobSchema>;
131
- /**
132
- * Asserts that the given value is a `UserAssetsBlob` (lenient read side).
133
- *
134
- * @param data - The value to validate.
135
- * @throws If the value does not match the expected schema.
136
- */
137
- export declare function assertUserAssetsBlob(data: unknown): asserts data is UserAssetsBlob;
138
- /**
139
- * Asserts that the given value is a `UserAssetsBlob` safe to write, with
140
- * CAIP-19 asset identifiers in both lists.
141
- *
142
- * @param data - The value to validate.
143
- * @throws A `StructError` if the value does not match the expected schema.
144
- */
145
- export declare function assertUserAssetsBlobForWrite(data: unknown): asserts data is UserAssetsBlob;
146
- /**
147
- * Asserts that a normalized `UserAssetsBlob` is safe to send: structurally
148
- * valid and mutually exclusive (no identifier in both lists).
149
- *
150
- * @param blob - The normalized blob to validate.
151
- * @throws A `StructError` if the blob is invalid or contains a conflict.
152
- */
153
- export declare function assertUserAssetsBlobNormalized(blob: UserAssetsBlob): void;
154
- /**
155
- * Asserts that every entry is a CAIP-19 asset identifier.
156
- *
157
- * @param ids - The identifiers to validate.
158
- * @throws A `StructError` if any entry is invalid.
159
- */
160
- export declare function assertUserAssetIds(ids: string[]): void;
161
- /**
162
- * Normalizes a `UserAssetsBlob` for persistence: de-duplicates both lists
163
- * (order-preserving) and resolves conflicts fail-open — an identifier in
164
- * both lists stays in `importedAssets` and is dropped from `hiddenAssets`.
165
- *
166
- * @param blob - The blob to normalize.
167
- * @returns A new, normalized blob; the input is not mutated.
168
- */
169
- export declare function normalizeUserAssetsBlob(blob: UserAssetsBlob): UserAssetsBlob;
170
106
  export {};
171
107
  //# sourceMappingURL=validators.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../src/validators.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAkBnD,OAAO,KAAK,EACV,oBAAoB,EACpB,kBAAkB,EAClB,sBAAsB,EACtB,2BAA2B,EAC3B,gBAAgB,EAChB,uBAAuB,EACvB,oBAAoB,EACrB,MAAM,YAAY,CAAC;AA8GpB;;;GAGG;AACH,eAAO,MAAM,+BAA+B,EAAE,oBAG7C,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,+BAA+B,EAAE,oBAG7C,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,MAAM,CAAC;AAE/C;;;;;GAKG;AACH,QAAA,MAAM,yBAAyB;;;;;;EAG7B,CAAC;AAgBH;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,mBAAmB,GAAG,KAAK,CAAC,OAAO,yBAAyB,CAAC,CAAC;AAE1E;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAC3C,IAAI,EAAE,OAAO,GACZ,OAAO,CAAC,IAAI,IAAI,kBAAkB,EAAE,CAEtC;AAED;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAC3C,IAAI,EAAE,OAAO,GACZ,OAAO,CAAC,IAAI,IAAI,uBAAuB,CAEzC;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,OAAO,GACZ,OAAO,CAAC,IAAI,IAAI,gBAAgB,CAElC;AAED;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAC1C,IAAI,EAAE,OAAO,GACZ,OAAO,CAAC,IAAI,IAAI,sBAAsB,CAExC;AAED;;;;;;;GAOG;AACH,wBAAgB,oCAAoC,CAClD,IAAI,EAAE,OAAO,GACZ,OAAO,CAAC,IAAI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C,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,+BAA+B,EAAE,oBAG7C,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,MAAM,CAAC;AAE/C;;;;;GAKG;AACH,QAAA,MAAM,yBAAyB;;;;;;EAG7B,CAAC;AAgBH;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,mBAAmB,GAAG,KAAK,CAAC,OAAO,yBAAyB,CAAC,CAAC;AAE1E;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAC3C,IAAI,EAAE,OAAO,GACZ,OAAO,CAAC,IAAI,IAAI,kBAAkB,EAAE,CAEtC;AAED;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAC3C,IAAI,EAAE,OAAO,GACZ,OAAO,CAAC,IAAI,IAAI,uBAAuB,CAEzC;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,OAAO,GACZ,OAAO,CAAC,IAAI,IAAI,gBAAgB,CAElC;AAED;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAC1C,IAAI,EAAE,OAAO,GACZ,OAAO,CAAC,IAAI,IAAI,sBAAsB,CAExC;AAED;;;;;;;GAOG;AACH,wBAAgB,oCAAoC,CAClD,IAAI,EAAE,OAAO,GACZ,OAAO,CAAC,IAAI,IAAI,2BAA2B,CAE7C;AAED;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CACvC,IAAI,EAAE,OAAO,GACZ,OAAO,CAAC,IAAI,IAAI,mBAAmB,CAErC;AAED;;;;;;;;;GASG;AACH,wBAAgB,iCAAiC,CAC/C,IAAI,EAAE,OAAO,GACZ,OAAO,CAAC,IAAI,IAAI,mBAAmB,CAErC"}
@@ -1,5 +1,4 @@
1
- import { array, assert, assign, boolean, enums, literal, number, optional, pattern, refine, size, string, type, } from '@metamask/superstruct';
2
- import { CaipAssetTypeStruct } from '@metamask/utils';
1
+ import { array, assert, assign, boolean, enums, literal, number, optional, pattern, size, string, type, } from '@metamask/superstruct';
3
2
  /**
4
3
  * Matches a 0x-prefixed hex string with zero or more hex digits.
5
4
  * Unlike `StrictHexStruct` from `@metamask/utils` (which requires at least
@@ -203,87 +202,4 @@ export function assertAssetsWatchlistBlob(data) {
203
202
  export function assertAssetsWatchlistBlobForWrite(data) {
204
203
  assert(data, AssetsWatchlistBlobWriteSchema);
205
204
  }
206
- // ---------------------------------------------------------------------------
207
- // User assets (custom tokens)
208
- // ---------------------------------------------------------------------------
209
- /**
210
- * The shape we accept on the way **in** from the server. Lenient by design:
211
- * a malformed payload throws, but a well-formed payload whose entries are
212
- * not valid CAIP-19 asset identifiers is still considered valid so we don't
213
- * reject existing server-side data.
214
- */
215
- const UserAssetsBlobSchema = type({
216
- version: literal(1),
217
- importedAssets: array(string()),
218
- hiddenAssets: array(string()),
219
- });
220
- /**
221
- * The maximum number of entries per list (`importedAssets`/`hiddenAssets`)
222
- * accepted on writes, mirroring the custom-tokens API's server-side cap.
223
- */
224
- export const USER_ASSETS_MAX_ASSETS = 100;
225
- /** Write-side schema: CAIP-19 entries, capped per list. */
226
- const UserAssetsBlobWriteSchema = type({
227
- version: literal(1),
228
- importedAssets: size(array(CaipAssetTypeStruct), 0, USER_ASSETS_MAX_ASSETS),
229
- hiddenAssets: size(array(CaipAssetTypeStruct), 0, USER_ASSETS_MAX_ASSETS),
230
- });
231
- /**
232
- * Normalized write schema: additionally enforces mutual exclusivity — no
233
- * identifier may appear in both lists. Applied to the normalized blob only,
234
- * so it can never reject user input; normalization resolves conflicts first.
235
- */
236
- const UserAssetsBlobNormalizedWriteSchema = refine(UserAssetsBlobWriteSchema, 'MutuallyExclusiveUserAssets', (blob) => blob.hiddenAssets.every((assetId) => !blob.importedAssets.includes(assetId)) || 'An identifier may not appear in both importedAssets and hiddenAssets');
237
- /**
238
- * Asserts that the given value is a `UserAssetsBlob` (lenient read side).
239
- *
240
- * @param data - The value to validate.
241
- * @throws If the value does not match the expected schema.
242
- */
243
- export function assertUserAssetsBlob(data) {
244
- assert(data, UserAssetsBlobSchema);
245
- }
246
- /**
247
- * Asserts that the given value is a `UserAssetsBlob` safe to write, with
248
- * CAIP-19 asset identifiers in both lists.
249
- *
250
- * @param data - The value to validate.
251
- * @throws A `StructError` if the value does not match the expected schema.
252
- */
253
- export function assertUserAssetsBlobForWrite(data) {
254
- assert(data, UserAssetsBlobWriteSchema);
255
- }
256
- /**
257
- * Asserts that a normalized `UserAssetsBlob` is safe to send: structurally
258
- * valid and mutually exclusive (no identifier in both lists).
259
- *
260
- * @param blob - The normalized blob to validate.
261
- * @throws A `StructError` if the blob is invalid or contains a conflict.
262
- */
263
- export function assertUserAssetsBlobNormalized(blob) {
264
- assert(blob, UserAssetsBlobNormalizedWriteSchema);
265
- }
266
- /**
267
- * Asserts that every entry is a CAIP-19 asset identifier.
268
- *
269
- * @param ids - The identifiers to validate.
270
- * @throws A `StructError` if any entry is invalid.
271
- */
272
- export function assertUserAssetIds(ids) {
273
- assert(ids, array(CaipAssetTypeStruct));
274
- }
275
- /**
276
- * Normalizes a `UserAssetsBlob` for persistence: de-duplicates both lists
277
- * (order-preserving) and resolves conflicts fail-open — an identifier in
278
- * both lists stays in `importedAssets` and is dropped from `hiddenAssets`.
279
- *
280
- * @param blob - The blob to normalize.
281
- * @returns A new, normalized blob; the input is not mutated.
282
- */
283
- export function normalizeUserAssetsBlob(blob) {
284
- const importedAssets = [...new Set(blob.importedAssets)];
285
- const importedAssetIds = new Set(importedAssets);
286
- const hiddenAssets = [...new Set(blob.hiddenAssets)].filter((assetId) => !importedAssetIds.has(assetId));
287
- return { version: 1, importedAssets, hiddenAssets };
288
- }
289
205
  //# sourceMappingURL=validators.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"validators.js","sourceRoot":"","sources":["../src/validators.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,EACL,MAAM,EACN,MAAM,EACN,OAAO,EACP,KAAK,EACL,OAAO,EACP,MAAM,EACN,QAAQ,EACR,OAAO,EACP,MAAM,EACN,IAAI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metamask/superstruct';\nimport {\n array,\n assert,\n assign,\n boolean,\n enums,\n literal,\n number,\n optional,\n pattern,\n refine,\n size,\n string,\n type,\n} from '@metamask/superstruct';\nimport { CaipAssetTypeStruct } from '@metamask/utils';\n\nimport type {\n AgenticCliPreference,\n DelegationResponse,\n IdentitySharingConsent,\n IdentitySharingConsentWrite,\n MarketingConsent,\n NotificationPreferences,\n PriceAlertPreference,\n} from './types.js';\n\n/**\n * Matches a 0x-prefixed hex string with zero or more hex digits.\n * Unlike `StrictHexStruct` from `@metamask/utils` (which requires at least\n * one digit after the prefix), this also accepts `\"0x\"` — the standard\n * encoding for empty bytes that the delegation API returns.\n */\nconst HexDataStruct = pattern(string(), /^0x[0-9a-f]*$/iu);\n\nconst CaveatSchema = type({\n enforcer: HexDataStruct,\n terms: HexDataStruct,\n args: HexDataStruct,\n});\n\nconst SignedDelegationSchema = type({\n delegate: HexDataStruct,\n delegator: HexDataStruct,\n authority: HexDataStruct,\n caveats: array(CaveatSchema),\n salt: HexDataStruct,\n signature: HexDataStruct,\n});\n\nconst DelegationMetadataSchema = type({\n delegationHash: HexDataStruct,\n chainIdHex: HexDataStruct,\n allowance: HexDataStruct,\n tokenSymbol: string(),\n tokenAddress: HexDataStruct,\n type: string(),\n});\n\nconst DelegationResponseSchema = type({\n signedDelegation: SignedDelegationSchema,\n metadata: DelegationMetadataSchema,\n});\n\nconst WalletActivityAccountSchema = type({\n address: HexDataStruct,\n enabled: boolean(),\n});\n\nconst WalletActivityPreferenceSchema = type({\n inAppNotificationsEnabled: boolean(),\n pushNotificationsEnabled: boolean(),\n accounts: array(WalletActivityAccountSchema),\n});\n\nconst MarketingPreferenceSchema = type({\n inAppNotificationsEnabled: boolean(),\n pushNotificationsEnabled: boolean(),\n});\n\nconst PerpsWatchlistExchangeSchema = type({\n testnet: array(string()),\n mainnet: array(string()),\n});\n\nconst PerpsWatchlistMarketsSchema = type({\n hyperliquid: PerpsWatchlistExchangeSchema,\n});\n\nconst PerpsPreferenceSchema = type({\n inAppNotificationsEnabled: boolean(),\n pushNotificationsEnabled: boolean(),\n watchlistMarkets: optional(PerpsWatchlistMarketsSchema),\n});\n\nconst SocialAIPreferenceSchema = type({\n inAppNotificationsEnabled: boolean(),\n pushNotificationsEnabled: boolean(),\n txAmountLimit: optional(number()),\n mutedTraderProfileIds: array(string()),\n});\n\nconst AgenticCliPreferenceSchema = type({\n inAppNotificationsEnabled: boolean(),\n pushNotificationsEnabled: boolean(),\n});\n\nconst PriceAlertPreferenceSchema = type({\n inAppNotificationsEnabled: boolean(),\n pushNotificationsEnabled: boolean(),\n});\n\nconst NotificationPreferencesSchema = type({\n walletActivity: WalletActivityPreferenceSchema,\n marketing: MarketingPreferenceSchema,\n perps: PerpsPreferenceSchema,\n socialAI: SocialAIPreferenceSchema,\n agenticCli: AgenticCliPreferenceSchema,\n priceAlerts: PriceAlertPreferenceSchema,\n});\n\nconst MarketingConsentSchema = type({\n marketingConsentEnabled: boolean(),\n});\n\nconst IdentitySharingConsentSchema = type({\n kyc: optional(boolean()),\n iron: optional(boolean()),\n});\n\nconst IdentitySharingConsentWriteSchema = type({\n audience: enums(['kyc', 'iron']),\n granted: boolean(),\n});\n\n/**\n * Default Agentic CLI notification preferences for consumers building a\n * fresh `NotificationPreferences` object.\n */\nexport const DEFAULT_AGENTIC_CLI_PREFERENCES: AgenticCliPreference = {\n inAppNotificationsEnabled: true,\n pushNotificationsEnabled: true,\n};\n\n/**\n * Default price-alert notification preferences for consumers building a\n * fresh `NotificationPreferences` object.\n */\nexport const DEFAULT_PRICE_ALERT_PREFERENCES: PriceAlertPreference = {\n inAppNotificationsEnabled: true,\n pushNotificationsEnabled: true,\n};\n\n/**\n * Maximum number of entries allowed in an assets-watchlist on write. Reads\n * are lenient: a server payload exceeding this size will still validate as\n * an `AssetsWatchlistBlob`. Encoded into\n * {@link AssetsWatchlistBlobWriteSchema}.\n */\nexport const ASSETS_WATCHLIST_MAX_ASSETS = 100;\n\n/**\n * The shape we accept on the way **in** from the server. Lenient by design:\n * a malformed payload throws, but a well-formed payload with more than\n * {@link ASSETS_WATCHLIST_MAX_ASSETS} assets is still considered valid so we\n * don't reject existing server-side data.\n */\nconst AssetsWatchlistBlobSchema = type({\n version: literal(1),\n assets: array(string()),\n});\n\n/**\n * The shape we accept on the way **out** to the server. Extends\n * {@link AssetsWatchlistBlobSchema} with a hard cap on `assets.length`.\n * Validation failures throw a `StructError`, e.g.\n * `\"At path: assets -- Expected a array with a length between \\`0\\` and\n * \\`100\\` but received one with a length of \\`N\\`\"`.\n */\nconst AssetsWatchlistBlobWriteSchema = assign(\n AssetsWatchlistBlobSchema,\n type({\n assets: size(array(string()), 0, ASSETS_WATCHLIST_MAX_ASSETS),\n }),\n);\n\n/**\n * The authenticated user's assets-watchlist: a mutable per-user singleton\n * blob.\n *\n * Each entry is a CAIP-19 asset identifier\n * (e.g. `eip155:1/erc20:0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48`).\n *\n * The `version` literal is carried inside the blob (not in the URL) so the\n * schema can evolve in a backwards-compatible way; bumping the version\n * indicates a different `assets` element shape.\n *\n * Inferred from {@link AssetsWatchlistBlobSchema} so the runtime schema and\n * the static type stay in lock-step. The size constraint on writes is\n * enforced by {@link AssetsWatchlistBlobWriteSchema} and is not encoded in\n * this static type (TypeScript cannot express \"array of length ≤ N\").\n */\nexport type AssetsWatchlistBlob = Infer<typeof AssetsWatchlistBlobSchema>;\n\n/**\n * Asserts that the given value is a valid `DelegationResponse[]`.\n *\n * @param data - The unknown value to validate.\n * @throws If the value does not match the expected schema.\n */\nexport function assertDelegationResponseArray(\n data: unknown,\n): asserts data is DelegationResponse[] {\n assert(data, array(DelegationResponseSchema));\n}\n\n/**\n * Asserts that the given value is a valid `NotificationPreferences`.\n *\n * @param data - The unknown value to validate.\n * @throws If the value does not match the expected schema.\n */\nexport function assertNotificationPreferences(\n data: unknown,\n): asserts data is NotificationPreferences {\n assert(data, NotificationPreferencesSchema);\n}\n\n/**\n * Asserts that the given value is a valid `MarketingConsent`.\n *\n * @param data - The unknown value to validate.\n * @throws If the value does not match the expected schema.\n */\nexport function assertMarketingConsent(\n data: unknown,\n): asserts data is MarketingConsent {\n assert(data, MarketingConsentSchema);\n}\n\n/**\n * Asserts that the given value is a valid `IdentitySharingConsent`.\n *\n * @param data - The unknown value to validate.\n * @throws If the value does not match the expected schema.\n */\nexport function assertIdentitySharingConsent(\n data: unknown,\n): asserts data is IdentitySharingConsent {\n assert(data, IdentitySharingConsentSchema);\n}\n\n/**\n * Asserts that the given value is a valid `IdentitySharingConsentWrite`\n * before it is sent to the API.\n *\n * @param data - The unknown value to validate.\n * @throws A `StructError` if `audience` is not `kyc` or `iron`, or if\n * `granted` is missing or not a boolean.\n */\nexport function assertIdentitySharingConsentForWrite(\n data: unknown,\n): asserts data is IdentitySharingConsentWrite {\n assert(data, IdentitySharingConsentWriteSchema);\n}\n\n/**\n * Asserts that the given value is a valid `AssetsWatchlistBlob` (read-side,\n * lenient).\n *\n * @param data - The unknown value to validate.\n * @throws If the value does not match the expected schema.\n */\nexport function assertAssetsWatchlistBlob(\n data: unknown,\n): asserts data is AssetsWatchlistBlob {\n assert(data, AssetsWatchlistBlobSchema);\n}\n\n/**\n * Asserts that the given value is a valid `AssetsWatchlistBlob` for\n * **writes**. In addition to the structural checks performed by\n * {@link assertAssetsWatchlistBlob}, this enforces that `assets` contains at\n * most {@link ASSETS_WATCHLIST_MAX_ASSETS} entries.\n *\n * @param data - The unknown value to validate.\n * @throws A `StructError` if the value does not match the expected schema\n * (including the size constraint).\n */\nexport function assertAssetsWatchlistBlobForWrite(\n data: unknown,\n): asserts data is AssetsWatchlistBlob {\n assert(data, AssetsWatchlistBlobWriteSchema);\n}\n\n// ---------------------------------------------------------------------------\n// User assets (custom tokens)\n// ---------------------------------------------------------------------------\n\n/**\n * The shape we accept on the way **in** from the server. Lenient by design:\n * a malformed payload throws, but a well-formed payload whose entries are\n * not valid CAIP-19 asset identifiers is still considered valid so we don't\n * reject existing server-side data.\n */\nconst UserAssetsBlobSchema = type({\n version: literal(1),\n importedAssets: array(string()),\n hiddenAssets: array(string()),\n});\n\n/**\n * The maximum number of entries per list (`importedAssets`/`hiddenAssets`)\n * accepted on writes, mirroring the custom-tokens API's server-side cap.\n */\nexport const USER_ASSETS_MAX_ASSETS = 100;\n\n/** Write-side schema: CAIP-19 entries, capped per list. */\nconst UserAssetsBlobWriteSchema = type({\n version: literal(1),\n importedAssets: size(array(CaipAssetTypeStruct), 0, USER_ASSETS_MAX_ASSETS),\n hiddenAssets: size(array(CaipAssetTypeStruct), 0, USER_ASSETS_MAX_ASSETS),\n});\n\n/**\n * Normalized write schema: additionally enforces mutual exclusivity — no\n * identifier may appear in both lists. Applied to the normalized blob only,\n * so it can never reject user input; normalization resolves conflicts first.\n */\nconst UserAssetsBlobNormalizedWriteSchema = refine(\n UserAssetsBlobWriteSchema,\n 'MutuallyExclusiveUserAssets',\n (blob) =>\n blob.hiddenAssets.every(\n (assetId) => !blob.importedAssets.includes(assetId),\n ) || 'An identifier may not appear in both importedAssets and hiddenAssets',\n);\n\n/**\n * The authenticated user's custom tokens: mutually exclusive lists of\n * CAIP-19 asset identifiers the user chose to import or hide.\n */\nexport type UserAssetsBlob = Infer<typeof UserAssetsBlobSchema>;\n\n/**\n * Asserts that the given value is a `UserAssetsBlob` (lenient read side).\n *\n * @param data - The value to validate.\n * @throws If the value does not match the expected schema.\n */\nexport function assertUserAssetsBlob(\n data: unknown,\n): asserts data is UserAssetsBlob {\n assert(data, UserAssetsBlobSchema);\n}\n\n/**\n * Asserts that the given value is a `UserAssetsBlob` safe to write, with\n * CAIP-19 asset identifiers in both lists.\n *\n * @param data - The value to validate.\n * @throws A `StructError` if the value does not match the expected schema.\n */\nexport function assertUserAssetsBlobForWrite(\n data: unknown,\n): asserts data is UserAssetsBlob {\n assert(data, UserAssetsBlobWriteSchema);\n}\n\n/**\n * Asserts that a normalized `UserAssetsBlob` is safe to send: structurally\n * valid and mutually exclusive (no identifier in both lists).\n *\n * @param blob - The normalized blob to validate.\n * @throws A `StructError` if the blob is invalid or contains a conflict.\n */\nexport function assertUserAssetsBlobNormalized(blob: UserAssetsBlob): void {\n assert(blob, UserAssetsBlobNormalizedWriteSchema);\n}\n\n/**\n * Asserts that every entry is a CAIP-19 asset identifier.\n *\n * @param ids - The identifiers to validate.\n * @throws A `StructError` if any entry is invalid.\n */\nexport function assertUserAssetIds(ids: string[]): void {\n assert(ids, array(CaipAssetTypeStruct));\n}\n\n/**\n * Normalizes a `UserAssetsBlob` for persistence: de-duplicates both lists\n * (order-preserving) and resolves conflicts fail-open — an identifier in\n * both lists stays in `importedAssets` and is dropped from `hiddenAssets`.\n *\n * @param blob - The blob to normalize.\n * @returns A new, normalized blob; the input is not mutated.\n */\nexport function normalizeUserAssetsBlob(blob: UserAssetsBlob): UserAssetsBlob {\n const importedAssets = [...new Set(blob.importedAssets)];\n const importedAssetIds = new Set(importedAssets);\n const hiddenAssets = [...new Set(blob.hiddenAssets)].filter(\n (assetId) => !importedAssetIds.has(assetId),\n );\n return { version: 1, importedAssets, hiddenAssets };\n}\n"]}
1
+ {"version":3,"file":"validators.js","sourceRoot":"","sources":["../src/validators.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,EACL,MAAM,EACN,MAAM,EACN,OAAO,EACP,KAAK,EACL,OAAO,EACP,MAAM,EACN,QAAQ,EACR,OAAO,EACP,IAAI,EACJ,MAAM,EACN,IAAI,GACL,MAAM,uBAAuB,CAAC;AAY/B;;;;;GAKG;AACH,MAAM,aAAa,GAAG,OAAO,CAAC,MAAM,EAAE,EAAE,iBAAiB,CAAC,CAAC;AAE3D,MAAM,YAAY,GAAG,IAAI,CAAC;IACxB,QAAQ,EAAE,aAAa;IACvB,KAAK,EAAE,aAAa;IACpB,IAAI,EAAE,aAAa;CACpB,CAAC,CAAC;AAEH,MAAM,sBAAsB,GAAG,IAAI,CAAC;IAClC,QAAQ,EAAE,aAAa;IACvB,SAAS,EAAE,aAAa;IACxB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IAAI,EAAE,yBAAyB,CAAC,CAAC;AAC1C,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,iCAAiC,CAC/C,IAAa;IAEb,MAAM,CAAC,IAAI,EAAE,8BAA8B,CAAC,CAAC;AAC/C,CAAC","sourcesContent":["import type { Infer } from '@metamask/superstruct';\nimport {\n array,\n assert,\n assign,\n boolean,\n enums,\n literal,\n number,\n optional,\n pattern,\n size,\n string,\n type,\n} from '@metamask/superstruct';\n\nimport type {\n AgenticCliPreference,\n DelegationResponse,\n IdentitySharingConsent,\n IdentitySharingConsentWrite,\n MarketingConsent,\n NotificationPreferences,\n PriceAlertPreference,\n} from './types.js';\n\n/**\n * Matches a 0x-prefixed hex string with zero or more hex digits.\n * Unlike `StrictHexStruct` from `@metamask/utils` (which requires at least\n * one digit after the prefix), this also accepts `\"0x\"` — the standard\n * encoding for empty bytes that the delegation API returns.\n */\nconst HexDataStruct = pattern(string(), /^0x[0-9a-f]*$/iu);\n\nconst CaveatSchema = type({\n enforcer: HexDataStruct,\n terms: HexDataStruct,\n args: HexDataStruct,\n});\n\nconst SignedDelegationSchema = type({\n delegate: HexDataStruct,\n delegator: HexDataStruct,\n authority: HexDataStruct,\n caveats: array(CaveatSchema),\n salt: HexDataStruct,\n signature: HexDataStruct,\n});\n\nconst DelegationMetadataSchema = type({\n delegationHash: HexDataStruct,\n chainIdHex: HexDataStruct,\n allowance: HexDataStruct,\n tokenSymbol: string(),\n tokenAddress: HexDataStruct,\n type: string(),\n});\n\nconst DelegationResponseSchema = type({\n signedDelegation: SignedDelegationSchema,\n metadata: DelegationMetadataSchema,\n});\n\nconst WalletActivityAccountSchema = type({\n address: HexDataStruct,\n enabled: boolean(),\n});\n\nconst WalletActivityPreferenceSchema = type({\n inAppNotificationsEnabled: boolean(),\n pushNotificationsEnabled: boolean(),\n accounts: array(WalletActivityAccountSchema),\n});\n\nconst MarketingPreferenceSchema = type({\n inAppNotificationsEnabled: boolean(),\n pushNotificationsEnabled: boolean(),\n});\n\nconst PerpsWatchlistExchangeSchema = type({\n testnet: array(string()),\n mainnet: array(string()),\n});\n\nconst PerpsWatchlistMarketsSchema = type({\n hyperliquid: PerpsWatchlistExchangeSchema,\n});\n\nconst PerpsPreferenceSchema = type({\n inAppNotificationsEnabled: boolean(),\n pushNotificationsEnabled: boolean(),\n watchlistMarkets: optional(PerpsWatchlistMarketsSchema),\n});\n\nconst SocialAIPreferenceSchema = type({\n inAppNotificationsEnabled: boolean(),\n pushNotificationsEnabled: boolean(),\n txAmountLimit: optional(number()),\n mutedTraderProfileIds: array(string()),\n});\n\nconst AgenticCliPreferenceSchema = type({\n inAppNotificationsEnabled: boolean(),\n pushNotificationsEnabled: boolean(),\n});\n\nconst PriceAlertPreferenceSchema = type({\n inAppNotificationsEnabled: boolean(),\n pushNotificationsEnabled: boolean(),\n});\n\nconst NotificationPreferencesSchema = type({\n walletActivity: WalletActivityPreferenceSchema,\n marketing: MarketingPreferenceSchema,\n perps: PerpsPreferenceSchema,\n socialAI: SocialAIPreferenceSchema,\n agenticCli: AgenticCliPreferenceSchema,\n priceAlerts: PriceAlertPreferenceSchema,\n});\n\nconst MarketingConsentSchema = type({\n marketingConsentEnabled: boolean(),\n});\n\nconst IdentitySharingConsentSchema = type({\n kyc: optional(boolean()),\n iron: optional(boolean()),\n});\n\nconst IdentitySharingConsentWriteSchema = type({\n audience: enums(['kyc', 'iron']),\n granted: boolean(),\n});\n\n/**\n * Default Agentic CLI notification preferences for consumers building a\n * fresh `NotificationPreferences` object.\n */\nexport const DEFAULT_AGENTIC_CLI_PREFERENCES: AgenticCliPreference = {\n inAppNotificationsEnabled: true,\n pushNotificationsEnabled: true,\n};\n\n/**\n * Default price-alert notification preferences for consumers building a\n * fresh `NotificationPreferences` object.\n */\nexport const DEFAULT_PRICE_ALERT_PREFERENCES: PriceAlertPreference = {\n inAppNotificationsEnabled: true,\n pushNotificationsEnabled: true,\n};\n\n/**\n * Maximum number of entries allowed in an assets-watchlist on write. Reads\n * are lenient: a server payload exceeding this size will still validate as\n * an `AssetsWatchlistBlob`. Encoded into\n * {@link AssetsWatchlistBlobWriteSchema}.\n */\nexport const ASSETS_WATCHLIST_MAX_ASSETS = 100;\n\n/**\n * The shape we accept on the way **in** from the server. Lenient by design:\n * a malformed payload throws, but a well-formed payload with more than\n * {@link ASSETS_WATCHLIST_MAX_ASSETS} assets is still considered valid so we\n * don't reject existing server-side data.\n */\nconst AssetsWatchlistBlobSchema = type({\n version: literal(1),\n assets: array(string()),\n});\n\n/**\n * The shape we accept on the way **out** to the server. Extends\n * {@link AssetsWatchlistBlobSchema} with a hard cap on `assets.length`.\n * Validation failures throw a `StructError`, e.g.\n * `\"At path: assets -- Expected a array with a length between \\`0\\` and\n * \\`100\\` but received one with a length of \\`N\\`\"`.\n */\nconst AssetsWatchlistBlobWriteSchema = assign(\n AssetsWatchlistBlobSchema,\n type({\n assets: size(array(string()), 0, ASSETS_WATCHLIST_MAX_ASSETS),\n }),\n);\n\n/**\n * The authenticated user's assets-watchlist: a mutable per-user singleton\n * blob.\n *\n * Each entry is a CAIP-19 asset identifier\n * (e.g. `eip155:1/erc20:0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48`).\n *\n * The `version` literal is carried inside the blob (not in the URL) so the\n * schema can evolve in a backwards-compatible way; bumping the version\n * indicates a different `assets` element shape.\n *\n * Inferred from {@link AssetsWatchlistBlobSchema} so the runtime schema and\n * the static type stay in lock-step. The size constraint on writes is\n * enforced by {@link AssetsWatchlistBlobWriteSchema} and is not encoded in\n * this static type (TypeScript cannot express \"array of length ≤ N\").\n */\nexport type AssetsWatchlistBlob = Infer<typeof AssetsWatchlistBlobSchema>;\n\n/**\n * Asserts that the given value is a valid `DelegationResponse[]`.\n *\n * @param data - The unknown value to validate.\n * @throws If the value does not match the expected schema.\n */\nexport function assertDelegationResponseArray(\n data: unknown,\n): asserts data is DelegationResponse[] {\n assert(data, array(DelegationResponseSchema));\n}\n\n/**\n * Asserts that the given value is a valid `NotificationPreferences`.\n *\n * @param data - The unknown value to validate.\n * @throws If the value does not match the expected schema.\n */\nexport function assertNotificationPreferences(\n data: unknown,\n): asserts data is NotificationPreferences {\n assert(data, NotificationPreferencesSchema);\n}\n\n/**\n * Asserts that the given value is a valid `MarketingConsent`.\n *\n * @param data - The unknown value to validate.\n * @throws If the value does not match the expected schema.\n */\nexport function assertMarketingConsent(\n data: unknown,\n): asserts data is MarketingConsent {\n assert(data, MarketingConsentSchema);\n}\n\n/**\n * Asserts that the given value is a valid `IdentitySharingConsent`.\n *\n * @param data - The unknown value to validate.\n * @throws If the value does not match the expected schema.\n */\nexport function assertIdentitySharingConsent(\n data: unknown,\n): asserts data is IdentitySharingConsent {\n assert(data, IdentitySharingConsentSchema);\n}\n\n/**\n * Asserts that the given value is a valid `IdentitySharingConsentWrite`\n * before it is sent to the API.\n *\n * @param data - The unknown value to validate.\n * @throws A `StructError` if `audience` is not `kyc` or `iron`, or if\n * `granted` is missing or not a boolean.\n */\nexport function assertIdentitySharingConsentForWrite(\n data: unknown,\n): asserts data is IdentitySharingConsentWrite {\n assert(data, IdentitySharingConsentWriteSchema);\n}\n\n/**\n * Asserts that the given value is a valid `AssetsWatchlistBlob` (read-side,\n * lenient).\n *\n * @param data - The unknown value to validate.\n * @throws If the value does not match the expected schema.\n */\nexport function assertAssetsWatchlistBlob(\n data: unknown,\n): asserts data is AssetsWatchlistBlob {\n assert(data, AssetsWatchlistBlobSchema);\n}\n\n/**\n * Asserts that the given value is a valid `AssetsWatchlistBlob` for\n * **writes**. In addition to the structural checks performed by\n * {@link assertAssetsWatchlistBlob}, this enforces that `assets` contains at\n * most {@link ASSETS_WATCHLIST_MAX_ASSETS} entries.\n *\n * @param data - The unknown value to validate.\n * @throws A `StructError` if the value does not match the expected schema\n * (including the size constraint).\n */\nexport function assertAssetsWatchlistBlobForWrite(\n data: unknown,\n): asserts data is AssetsWatchlistBlob {\n assert(data, AssetsWatchlistBlobWriteSchema);\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/authenticated-user-storage",
3
- "version": "4.1.0-preview-e80304db4",
3
+ "version": "4.1.0-preview-eb6c0745c",
4
4
  "description": "SDK for authenticated (non-encrypted) user storage endpoints",
5
5
  "keywords": [
6
6
  "Ethereum",
@@ -32,43 +32,44 @@
32
32
  "registry": "https://registry.npmjs.org/"
33
33
  },
34
34
  "scripts": {
35
- "allow-scripts": "yarn workspace @metamask/core-monorepo run allow-scripts",
36
35
  "build": "tsc --project tsconfig.build.json",
37
36
  "build:all": "tsc --build tsconfig.build.json --verbose",
38
37
  "build:clean": "yarn build:only-clean && yarn build",
39
38
  "build:docs": "typedoc",
40
39
  "build:only-clean": "rimraf './dist' './tsconfig.build.tsbuildinfo'",
41
40
  "changelog:update": "../../scripts/update-changelog.sh @metamask/authenticated-user-storage",
42
- "changelog:validate": "../../scripts/validate-changelog.sh",
43
- "lint:tsconfigs": "node --import ../../scripts/resolver/register.ts ../../scripts/lint-tsconfigs/lint-tsconfigs.ts",
44
- "lint:tsconfigs:fix": "node --import ../../scripts/resolver/register.ts ../../scripts/lint-tsconfigs/lint-tsconfigs.ts --fix",
45
- "messenger-action-types:check": "node --import ../../scripts/resolver/register.ts ../../packages/messenger-cli/src/cli.ts --formatter oxfmt --esm --check",
46
- "messenger-action-types:generate": "node --import ../../scripts/resolver/register.ts ../../packages/messenger-cli/src/cli.ts --formatter oxfmt --esm --generate",
41
+ "changelog:validate": "../../scripts/validate-changelog.sh @metamask/authenticated-user-storage",
42
+ "lint:tsconfigs": "node --import ../../scripts/resolver/register.ts --experimental-transform-types ../../scripts/lint-tsconfigs/lint-tsconfigs.ts",
43
+ "lint:tsconfigs:fix": "node --import ../../scripts/resolver/register.ts --experimental-transform-types ../../scripts/lint-tsconfigs/lint-tsconfigs.ts --fix",
44
+ "messenger-action-types:check": "node --import ../../scripts/resolver/register.ts --experimental-transform-types ../../packages/messenger-cli/src/cli.ts --formatter oxfmt --esm --check",
45
+ "messenger-action-types:generate": "node --import ../../scripts/resolver/register.ts --experimental-transform-types ../../packages/messenger-cli/src/cli.ts --formatter oxfmt --esm --generate",
47
46
  "since-latest-release": "../../scripts/since-latest-release.sh",
48
- "test": "vitest",
49
- "test:clean": "vitest --clearCache",
50
- "test:coverage": "vitest --coverage",
51
- "test:verbose": "vitest --reporter=verbose",
52
- "test:watch": "vitest --watch"
47
+ "test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
48
+ "test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",
49
+ "test:verbose": "NODE_OPTIONS=--experimental-vm-modules jest --verbose",
50
+ "test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
53
51
  },
54
52
  "dependencies": {
55
53
  "@metamask/base-data-service": "^2.1.0",
56
54
  "@metamask/controller-utils": "^13.0.0",
57
55
  "@metamask/messenger": "^3.0.0",
58
56
  "@metamask/superstruct": "^3.4.1",
59
- "@metamask/utils": "^12.0.2"
57
+ "@metamask/utils": "^12.0.0"
60
58
  },
61
59
  "devDependencies": {
62
- "@metamask/auto-changelog": "^7.1.0",
60
+ "@metamask/auto-changelog": "^6.2.1",
61
+ "@types/jest": "^30.0.0",
63
62
  "@typescript/native": "npm:typescript@^7.0.2",
64
- "nock": "^15.0.5",
63
+ "deepmerge": "^4.3.1",
64
+ "jest": "^30.5.2",
65
+ "nock": "^13.5.6",
65
66
  "rimraf": "^6.1.3",
67
+ "ts-jest": "^29.4.14",
66
68
  "typedoc": "^0.28.20",
67
69
  "typedoc-plugin-missing-exports": "^4.1.4",
68
- "typescript": "npm:@typescript/typescript6@^6.0.2",
69
- "vitest": "5.0.3"
70
+ "typescript": "npm:@typescript/typescript6@^6.0.2"
70
71
  },
71
72
  "engines": {
72
- "node": "^22.14.0 || ^24 || ^26"
73
+ "node": "^22.14.0 || ^24"
73
74
  }
74
75
  }