@metamask-previews/authenticated-user-storage 2.0.0-preview-1275d0fda → 2.0.0-preview-a4b03df12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +26 -1
  3. package/dist/authenticated-user-storage-method-action-types.cjs.map +1 -1
  4. package/dist/authenticated-user-storage-method-action-types.d.cts +26 -1
  5. package/dist/authenticated-user-storage-method-action-types.d.cts.map +1 -1
  6. package/dist/authenticated-user-storage-method-action-types.d.mts +26 -1
  7. package/dist/authenticated-user-storage-method-action-types.d.mts.map +1 -1
  8. package/dist/authenticated-user-storage-method-action-types.mjs.map +1 -1
  9. package/dist/authenticated-user-storage.cjs +64 -0
  10. package/dist/authenticated-user-storage.cjs.map +1 -1
  11. package/dist/authenticated-user-storage.d.cts +20 -1
  12. package/dist/authenticated-user-storage.d.cts.map +1 -1
  13. package/dist/authenticated-user-storage.d.mts +20 -1
  14. package/dist/authenticated-user-storage.d.mts.map +1 -1
  15. package/dist/authenticated-user-storage.mjs +65 -1
  16. package/dist/authenticated-user-storage.mjs.map +1 -1
  17. package/dist/index.cjs +3 -1
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.cts +3 -2
  20. package/dist/index.d.cts.map +1 -1
  21. package/dist/index.d.mts +3 -2
  22. package/dist/index.d.mts.map +1 -1
  23. package/dist/index.mjs +1 -0
  24. package/dist/index.mjs.map +1 -1
  25. package/dist/types.cjs.map +1 -1
  26. package/dist/types.d.cts +1 -0
  27. package/dist/types.d.cts.map +1 -1
  28. package/dist/types.d.mts +1 -0
  29. package/dist/types.d.mts.map +1 -1
  30. package/dist/types.mjs.map +1 -1
  31. package/dist/validators.cjs +53 -1
  32. package/dist/validators.cjs.map +1 -1
  33. package/dist/validators.d.cts +58 -0
  34. package/dist/validators.d.cts.map +1 -1
  35. package/dist/validators.d.mts +58 -0
  36. package/dist/validators.d.mts.map +1 -1
  37. package/dist/validators.mjs +51 -1
  38. package/dist/validators.mjs.map +1 -1
  39. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -7,6 +7,12 @@ 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 `getAssetsWatchlist` and `setAssetsWatchlist` methods to `AuthenticatedUserStorageService` for managing the authenticated user's assets-watchlist, along with corresponding messenger actions (`AuthenticatedUserStorageService:getAssetsWatchlist`, `AuthenticatedUserStorageService:setAssetsWatchlist`), the `AssetsWatchlistBlob` type, and the `ASSETS_WATCHLIST_MAX_ASSETS` constant ([#8836](https://github.com/MetaMask/core/pull/8836))
13
+ - `getAssetsWatchlist` returns the assets-watchlist blob or `null` on 404, mirroring `getNotificationPreferences`.
14
+ - `setAssetsWatchlist` writes the full blob and enforces a maximum of `ASSETS_WATCHLIST_MAX_ASSETS` (100) assets before sending the request, via a superstruct `size` constraint on the write-side schema.
15
+
10
16
  ## [2.0.0]
11
17
 
12
18
  ### Changed
package/README.md CHANGED
@@ -2,10 +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 two 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
+ - **Assets watchlist** -- mutable per-user list of CAIP-19 asset identifiers (get, set).
9
10
 
10
11
  ## Installation
11
12
 
@@ -109,6 +110,30 @@ const updated: NotificationPreferences = {
109
110
  await service.putNotificationPreferences(updated, 'extension');
110
111
  ```
111
112
 
113
+ ### Assets watchlist
114
+
115
+ The assets-watchlist is a mutable per-user singleton blob. The first call to `setAssetsWatchlist` creates the record; subsequent calls overwrite it. Each entry in `assets` 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.
116
+
117
+ The SDK enforces a maximum of `ASSETS_WATCHLIST_MAX_ASSETS` (100) entries on writes; oversized blobs throw a superstruct `StructError` before the request is sent.
118
+
119
+ ```typescript
120
+ import { ASSETS_WATCHLIST_MAX_ASSETS } from '@metamask/authenticated-user-storage';
121
+ import type { AssetsWatchlistBlob } from '@metamask/authenticated-user-storage';
122
+
123
+ // Retrieve the current assets-watchlist (returns null on the first read)
124
+ const watchlist = await service.getAssetsWatchlist();
125
+
126
+ // Create or update the assets-watchlist
127
+ const updated: AssetsWatchlistBlob = {
128
+ version: 1,
129
+ assets: [
130
+ 'eip155:1/erc20:0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
131
+ 'eip155:1/slip44:60',
132
+ ],
133
+ };
134
+ await service.setAssetsWatchlist(updated, 'extension');
135
+ ```
136
+
112
137
  ## Response validation
113
138
 
114
139
  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.
@@ -1 +1 @@
1
- {"version":3,"file":"authenticated-user-storage-method-action-types.cjs","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';\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 * Union of all AuthenticatedUserStorageService action types.\n */\nexport type AuthenticatedUserStorageServiceMethodActions =\n | AuthenticatedUserStorageServiceListDelegationsAction\n | AuthenticatedUserStorageServiceCreateDelegationAction\n | AuthenticatedUserStorageServiceRevokeDelegationAction\n | AuthenticatedUserStorageServiceGetNotificationPreferencesAction\n | AuthenticatedUserStorageServicePutNotificationPreferencesAction;\n"]}
1
+ {"version":3,"file":"authenticated-user-storage-method-action-types.cjs","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';\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 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 | AuthenticatedUserStorageServiceGetAssetsWatchlistAction\n | AuthenticatedUserStorageServiceSetAssetsWatchlistAction;\n"]}
@@ -51,8 +51,33 @@ export type AuthenticatedUserStorageServicePutNotificationPreferencesAction = {
51
51
  type: `AuthenticatedUserStorageService:putNotificationPreferences`;
52
52
  handler: AuthenticatedUserStorageService['putNotificationPreferences'];
53
53
  };
54
+ /**
55
+ * Returns the assets-watchlist for the authenticated user.
56
+ *
57
+ * @returns The assets-watchlist blob, or `null` if none has been set (404).
58
+ */
59
+ export type AuthenticatedUserStorageServiceGetAssetsWatchlistAction = {
60
+ type: `AuthenticatedUserStorageService:getAssetsWatchlist`;
61
+ handler: AuthenticatedUserStorageService['getAssetsWatchlist'];
62
+ };
63
+ /**
64
+ * Creates or updates the assets-watchlist for the authenticated user.
65
+ *
66
+ * @param blob - The full assets-watchlist blob. The `assets` array may
67
+ * contain at most `ASSETS_WATCHLIST_MAX_ASSETS` CAIP-19 asset identifiers;
68
+ * this is enforced by `assertAssetsWatchlistBlobForWrite` before the
69
+ * request is sent.
70
+ * @param clientType - Optional client type header.
71
+ * @throws A `StructError` from `@metamask/superstruct` if `blob` is
72
+ * structurally invalid or `assets` exceeds the cap; an `HttpError` from
73
+ * `@metamask/controller-utils` if the API responds with a non-2xx status.
74
+ */
75
+ export type AuthenticatedUserStorageServiceSetAssetsWatchlistAction = {
76
+ type: `AuthenticatedUserStorageService:setAssetsWatchlist`;
77
+ handler: AuthenticatedUserStorageService['setAssetsWatchlist'];
78
+ };
54
79
  /**
55
80
  * Union of all AuthenticatedUserStorageService action types.
56
81
  */
57
- export type AuthenticatedUserStorageServiceMethodActions = AuthenticatedUserStorageServiceListDelegationsAction | AuthenticatedUserStorageServiceCreateDelegationAction | AuthenticatedUserStorageServiceRevokeDelegationAction | AuthenticatedUserStorageServiceGetNotificationPreferencesAction | AuthenticatedUserStorageServicePutNotificationPreferencesAction;
82
+ export type AuthenticatedUserStorageServiceMethodActions = AuthenticatedUserStorageServiceListDelegationsAction | AuthenticatedUserStorageServiceCreateDelegationAction | AuthenticatedUserStorageServiceRevokeDelegationAction | AuthenticatedUserStorageServiceGetNotificationPreferencesAction | AuthenticatedUserStorageServicePutNotificationPreferencesAction | AuthenticatedUserStorageServiceGetAssetsWatchlistAction | AuthenticatedUserStorageServiceSetAssetsWatchlistAction;
58
83
  //# sourceMappingURL=authenticated-user-storage-method-action-types.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"authenticated-user-storage-method-action-types.d.cts","sourceRoot":"","sources":["../src/authenticated-user-storage-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,+BAA+B,EAAE,yCAAqC;AAEpF;;;;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;;GAEG;AACH,MAAM,MAAM,4CAA4C,GACpD,oDAAoD,GACpD,qDAAqD,GACrD,qDAAqD,GACrD,+DAA+D,GAC/D,+DAA+D,CAAC"}
1
+ {"version":3,"file":"authenticated-user-storage-method-action-types.d.cts","sourceRoot":"","sources":["../src/authenticated-user-storage-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,+BAA+B,EAAE,yCAAqC;AAEpF;;;;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;;;;GAIG;AACH,MAAM,MAAM,uDAAuD,GAAG;IACpE,IAAI,EAAE,oDAAoD,CAAC;IAC3D,OAAO,EAAE,+BAA+B,CAAC,oBAAoB,CAAC,CAAC;CAChE,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,uDAAuD,GAAG;IACpE,IAAI,EAAE,oDAAoD,CAAC;IAC3D,OAAO,EAAE,+BAA+B,CAAC,oBAAoB,CAAC,CAAC;CAChE,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,4CAA4C,GACpD,oDAAoD,GACpD,qDAAqD,GACrD,qDAAqD,GACrD,+DAA+D,GAC/D,+DAA+D,GAC/D,uDAAuD,GACvD,uDAAuD,CAAC"}
@@ -51,8 +51,33 @@ export type AuthenticatedUserStorageServicePutNotificationPreferencesAction = {
51
51
  type: `AuthenticatedUserStorageService:putNotificationPreferences`;
52
52
  handler: AuthenticatedUserStorageService['putNotificationPreferences'];
53
53
  };
54
+ /**
55
+ * Returns the assets-watchlist for the authenticated user.
56
+ *
57
+ * @returns The assets-watchlist blob, or `null` if none has been set (404).
58
+ */
59
+ export type AuthenticatedUserStorageServiceGetAssetsWatchlistAction = {
60
+ type: `AuthenticatedUserStorageService:getAssetsWatchlist`;
61
+ handler: AuthenticatedUserStorageService['getAssetsWatchlist'];
62
+ };
63
+ /**
64
+ * Creates or updates the assets-watchlist for the authenticated user.
65
+ *
66
+ * @param blob - The full assets-watchlist blob. The `assets` array may
67
+ * contain at most `ASSETS_WATCHLIST_MAX_ASSETS` CAIP-19 asset identifiers;
68
+ * this is enforced by `assertAssetsWatchlistBlobForWrite` before the
69
+ * request is sent.
70
+ * @param clientType - Optional client type header.
71
+ * @throws A `StructError` from `@metamask/superstruct` if `blob` is
72
+ * structurally invalid or `assets` exceeds the cap; an `HttpError` from
73
+ * `@metamask/controller-utils` if the API responds with a non-2xx status.
74
+ */
75
+ export type AuthenticatedUserStorageServiceSetAssetsWatchlistAction = {
76
+ type: `AuthenticatedUserStorageService:setAssetsWatchlist`;
77
+ handler: AuthenticatedUserStorageService['setAssetsWatchlist'];
78
+ };
54
79
  /**
55
80
  * Union of all AuthenticatedUserStorageService action types.
56
81
  */
57
- export type AuthenticatedUserStorageServiceMethodActions = AuthenticatedUserStorageServiceListDelegationsAction | AuthenticatedUserStorageServiceCreateDelegationAction | AuthenticatedUserStorageServiceRevokeDelegationAction | AuthenticatedUserStorageServiceGetNotificationPreferencesAction | AuthenticatedUserStorageServicePutNotificationPreferencesAction;
82
+ export type AuthenticatedUserStorageServiceMethodActions = AuthenticatedUserStorageServiceListDelegationsAction | AuthenticatedUserStorageServiceCreateDelegationAction | AuthenticatedUserStorageServiceRevokeDelegationAction | AuthenticatedUserStorageServiceGetNotificationPreferencesAction | AuthenticatedUserStorageServicePutNotificationPreferencesAction | AuthenticatedUserStorageServiceGetAssetsWatchlistAction | AuthenticatedUserStorageServiceSetAssetsWatchlistAction;
58
83
  //# sourceMappingURL=authenticated-user-storage-method-action-types.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"authenticated-user-storage-method-action-types.d.mts","sourceRoot":"","sources":["../src/authenticated-user-storage-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,+BAA+B,EAAE,yCAAqC;AAEpF;;;;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;;GAEG;AACH,MAAM,MAAM,4CAA4C,GACpD,oDAAoD,GACpD,qDAAqD,GACrD,qDAAqD,GACrD,+DAA+D,GAC/D,+DAA+D,CAAC"}
1
+ {"version":3,"file":"authenticated-user-storage-method-action-types.d.mts","sourceRoot":"","sources":["../src/authenticated-user-storage-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,+BAA+B,EAAE,yCAAqC;AAEpF;;;;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;;;;GAIG;AACH,MAAM,MAAM,uDAAuD,GAAG;IACpE,IAAI,EAAE,oDAAoD,CAAC;IAC3D,OAAO,EAAE,+BAA+B,CAAC,oBAAoB,CAAC,CAAC;CAChE,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,uDAAuD,GAAG;IACpE,IAAI,EAAE,oDAAoD,CAAC;IAC3D,OAAO,EAAE,+BAA+B,CAAC,oBAAoB,CAAC,CAAC;CAChE,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,4CAA4C,GACpD,oDAAoD,GACpD,qDAAqD,GACrD,qDAAqD,GACrD,+DAA+D,GAC/D,+DAA+D,GAC/D,uDAAuD,GACvD,uDAAuD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"authenticated-user-storage-method-action-types.mjs","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';\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 * Union of all AuthenticatedUserStorageService action types.\n */\nexport type AuthenticatedUserStorageServiceMethodActions =\n | AuthenticatedUserStorageServiceListDelegationsAction\n | AuthenticatedUserStorageServiceCreateDelegationAction\n | AuthenticatedUserStorageServiceRevokeDelegationAction\n | AuthenticatedUserStorageServiceGetNotificationPreferencesAction\n | AuthenticatedUserStorageServicePutNotificationPreferencesAction;\n"]}
1
+ {"version":3,"file":"authenticated-user-storage-method-action-types.mjs","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';\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 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 | AuthenticatedUserStorageServiceGetAssetsWatchlistAction\n | AuthenticatedUserStorageServiceSetAssetsWatchlistAction;\n"]}
@@ -40,6 +40,8 @@ const MESSENGER_EXPOSED_METHODS = [
40
40
  'revokeDelegation',
41
41
  'getNotificationPreferences',
42
42
  'putNotificationPreferences',
43
+ 'getAssetsWatchlist',
44
+ 'setAssetsWatchlist',
43
45
  ];
44
46
  // === SERVICE ===
45
47
  /**
@@ -202,6 +204,68 @@ class AuthenticatedUserStorageService extends base_data_service_1.BaseDataServic
202
204
  queryKey: [`${this.name}:getNotificationPreferences`],
203
205
  });
204
206
  }
207
+ /**
208
+ * Returns the assets-watchlist for the authenticated user.
209
+ *
210
+ * @returns The assets-watchlist blob, or `null` if none has been set (404).
211
+ */
212
+ async getAssetsWatchlist() {
213
+ const url = `${getAuthenticatedStorageUrl(__classPrivateFieldGet(this, _AuthenticatedUserStorageService_environment, "f"))}/assets-watchlist`;
214
+ const data = await this.fetchQuery({
215
+ queryKey: [`${this.name}:getAssetsWatchlist`],
216
+ queryFn: async () => {
217
+ const headers = await __classPrivateFieldGet(this, _AuthenticatedUserStorageService_instances, "m", _AuthenticatedUserStorageService_getHeaders).call(this);
218
+ const response = await fetch(url, { headers });
219
+ if (response.status === 404) {
220
+ return null;
221
+ }
222
+ if (!response.ok) {
223
+ throw new controller_utils_1.HttpError(response.status, `Failed to get assets watchlist: ${response.status}`);
224
+ }
225
+ return response.json();
226
+ },
227
+ });
228
+ if (data === null) {
229
+ return null;
230
+ }
231
+ (0, validators_1.assertAssetsWatchlistBlob)(data);
232
+ return data;
233
+ }
234
+ /**
235
+ * Creates or updates the assets-watchlist for the authenticated user.
236
+ *
237
+ * @param blob - The full assets-watchlist blob. The `assets` array may
238
+ * contain at most `ASSETS_WATCHLIST_MAX_ASSETS` CAIP-19 asset identifiers;
239
+ * this is enforced by `assertAssetsWatchlistBlobForWrite` before the
240
+ * request is sent.
241
+ * @param clientType - Optional client type header.
242
+ * @throws A `StructError` from `@metamask/superstruct` if `blob` is
243
+ * structurally invalid or `assets` exceeds the cap; an `HttpError` from
244
+ * `@metamask/controller-utils` if the API responds with a non-2xx status.
245
+ */
246
+ async setAssetsWatchlist(blob, clientType) {
247
+ (0, validators_1.assertAssetsWatchlistBlobForWrite)(blob);
248
+ const url = `${getAuthenticatedStorageUrl(__classPrivateFieldGet(this, _AuthenticatedUserStorageService_environment, "f"))}/assets-watchlist`;
249
+ await this.fetchQuery({
250
+ queryKey: [`${this.name}:setAssetsWatchlist`, blob],
251
+ staleTime: 0,
252
+ queryFn: async () => {
253
+ const headers = await __classPrivateFieldGet(this, _AuthenticatedUserStorageService_instances, "m", _AuthenticatedUserStorageService_getHeaders).call(this, clientType);
254
+ const response = await fetch(url, {
255
+ method: 'PUT',
256
+ headers,
257
+ body: JSON.stringify(blob),
258
+ });
259
+ if (!response.ok) {
260
+ throw new controller_utils_1.HttpError(response.status, `Failed to put assets watchlist: ${response.status}`);
261
+ }
262
+ return null;
263
+ },
264
+ });
265
+ await this.invalidateQueries({
266
+ queryKey: [`${this.name}:getAssetsWatchlist`],
267
+ });
268
+ }
205
269
  }
206
270
  exports.AuthenticatedUserStorageService = AuthenticatedUserStorageService;
207
271
  _AuthenticatedUserStorageService_environment = new WeakMap(), _AuthenticatedUserStorageService_instances = new WeakSet(), _AuthenticatedUserStorageService_getHeaders = async function _AuthenticatedUserStorageService_getHeaders(clientType) {
@@ -1 +1 @@
1
- {"version":3,"file":"authenticated-user-storage.cjs","sourceRoot":"","sources":["../src/authenticated-user-storage.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAKA,mEAA8D;AAE9D,iEAAuD;AAMvD,mCAA6C;AAO7C,iDAGsB;AAEtB,kBAAkB;AAElB;;;GAGG;AACU,QAAA,WAAW,GAAG,iCAAiC,CAAC;AAE7D;;;;;GAKG;AACH,SAAgB,0BAA0B,CAAC,WAAwB;IACjE,OAAO,GAAG,IAAA,0BAAoB,EAAC,WAAW,CAAC,SAAS,CAAC;AACvD,CAAC;AAFD,gEAEC;AAED,oBAAoB;AAEpB,MAAM,yBAAyB,GAAG;IAChC,iBAAiB;IACjB,kBAAkB;IAClB,kBAAkB;IAClB,4BAA4B;IAC5B,4BAA4B;CACpB,CAAC;AAoEX,kBAAkB;AAElB;;;;;GAKG;AACH,MAAa,+BAAgC,SAAQ,mCAGpD;IAGC;;;;;;;;OAQG;IACH,YAAY,EACV,SAAS,EACT,WAAW,EACX,aAAa,GAKd;QACC,KAAK,CAAC,EAAE,IAAI,EAAE,mBAAW,EAAE,SAAS,EAAE,aAAa,EAAE,CAAC,CAAC;;QApBhD,+DAA0B;QAqBjC,uBAAA,IAAI,gDAAgB,WAAW,MAAA,CAAC;QAEhC,IAAI,CAAC,SAAS,CAAC,4BAA4B,CACzC,IAAI,EACJ,yBAAyB,CAC1B,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,eAAe;QACnB,MAAM,GAAG,GAAG,GAAG,0BAA0B,CAAC,uBAAA,IAAI,oDAAa,CAAC,cAAc,CAAC;QAE3E,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC;YACjC,QAAQ,EAAE,CAAC,GAAG,IAAI,CAAC,IAAI,kBAAkB,CAAC;YAC1C,OAAO,EAAE,KAAK,IAAI,EAAE;gBAClB,MAAM,OAAO,GAAG,MAAM,uBAAA,IAAI,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E;oBAChC,MAAM,EAAE,KAAK;oBACb,OAAO;oBACP,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;iBAC5B,CAAC,CAAC;gBAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;oBACjB,MAAM,IAAI,4BAAS,CACjB,QAAQ,CAAC,MAAM,EACf,2CAA2C,QAAQ,CAAC,MAAM,EAAE,CAC7D,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,6BAA6B,CAAC;SACtD,CAAC,CAAC;IACL,CAAC;CAeF;AAvOD,0EAuOC;wKAbC,KAAK,sDAAa,UAAuB;IACvC,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAC3C,yCAAyC,CAC1C,CAAC;IACF,MAAM,OAAO,GAA2B;QACtC,cAAc,EAAE,kBAAkB;QAClC,aAAa,EAAE,UAAU,WAAW,EAAE;KACvC,CAAC;IACF,IAAI,UAAU,EAAE,CAAC;QACf,OAAO,CAAC,eAAe,CAAC,GAAG,UAAU,CAAC;IACxC,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC","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';\nimport type { Environment } from './env';\nimport { getUserStorageApiUrl } from './env';\nimport type {\n ClientType,\n DelegationResponse,\n DelegationSubmission,\n NotificationPreferences,\n} from './types';\nimport {\n assertDelegationResponseArray,\n assertNotificationPreferences,\n} from './validators';\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] 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 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.cjs","sourceRoot":"","sources":["../src/authenticated-user-storage.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAKA,mEAA8D;AAE9D,iEAAuD;AAMvD,mCAA6C;AAQ7C,iDAKsB;AAEtB,kBAAkB;AAElB;;;GAGG;AACU,QAAA,WAAW,GAAG,iCAAiC,CAAC;AAE7D;;;;;GAKG;AACH,SAAgB,0BAA0B,CAAC,WAAwB;IACjE,OAAO,GAAG,IAAA,0BAAoB,EAAC,WAAW,CAAC,SAAS,CAAC;AACvD,CAAC;A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esAction,\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';\nimport type { Environment } from './env';\nimport { getUserStorageApiUrl } from './env';\nimport type {\n AssetsWatchlistBlob,\n ClientType,\n DelegationResponse,\n DelegationSubmission,\n NotificationPreferences,\n} from './types';\nimport {\n assertAssetsWatchlistBlob,\n assertAssetsWatchlistBlobForWrite,\n assertDelegationResponseArray,\n assertNotificationPreferences,\n} from './validators';\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 '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 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)}/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)}/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"]}
@@ -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.cjs";
6
6
  import type { Environment } from "./env.cjs";
7
- import type { ClientType, DelegationResponse, DelegationSubmission, NotificationPreferences } from "./types.cjs";
7
+ import type { AssetsWatchlistBlob, ClientType, DelegationResponse, DelegationSubmission, NotificationPreferences } from "./types.cjs";
8
8
  /**
9
9
  * The name of the {@link AuthenticatedUserStorageService} service, used to
10
10
  * namespace the service's actions and events.
@@ -118,6 +118,25 @@ export declare class AuthenticatedUserStorageService extends BaseDataService<typ
118
118
  * @param clientType - Optional client type header.
119
119
  */
120
120
  putNotificationPreferences(prefs: NotificationPreferences, clientType?: ClientType): Promise<void>;
121
+ /**
122
+ * Returns the assets-watchlist for the authenticated user.
123
+ *
124
+ * @returns The assets-watchlist blob, or `null` if none has been set (404).
125
+ */
126
+ getAssetsWatchlist(): Promise<AssetsWatchlistBlob | null>;
127
+ /**
128
+ * Creates or updates the assets-watchlist for the authenticated user.
129
+ *
130
+ * @param blob - The full assets-watchlist blob. The `assets` array may
131
+ * contain at most `ASSETS_WATCHLIST_MAX_ASSETS` CAIP-19 asset identifiers;
132
+ * this is enforced by `assertAssetsWatchlistBlobForWrite` before the
133
+ * request is sent.
134
+ * @param clientType - Optional client type header.
135
+ * @throws A `StructError` from `@metamask/superstruct` if `blob` is
136
+ * structurally invalid or `assets` exceeds the cap; an `HttpError` from
137
+ * `@metamask/controller-utils` if the API responds with a non-2xx status.
138
+ */
139
+ setAssetsWatchlist(blob: AssetsWatchlistBlob, clientType?: ClientType): Promise<void>;
121
140
  }
122
141
  export {};
123
142
  //# sourceMappingURL=authenticated-user-storage.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"authenticated-user-storage.d.cts","sourceRoot":"","sources":["../src/authenticated-user-stor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AGG;AACH,MAAM,MAAM,iCAAiC,GAAG,SAAS,CACvD,OAAO,WAAW,EAClB,+BAA+B,GAAG,cAAc,EAChD,8BAA8B,GAAG,aAAa,CAC/C,CAAC;AAIF;;;;;GAKG;AACH,qBAAa,+BAAgC,SAAQ,eAAe,CAClE,OAAO,WAAW,EAClB,iCAAiC,CAClC;;IAGC;;;;;;;;OAQG;gBACS,EACV,SAAS,EACT,WAAW,EACX,aAAa,GACd,EAAE;QACD,SAAS,EAAE,iCAAiC,CAAC;QAC7C,WAAW,EAAE,WAAW,CAAC;QACzB,aAAa,CAAC,EAAE,0BAA0B,CAAC;KAC5C;IAUD;;;;OAIG;IACG,eAAe,IAAI,OAAO,CAAC,kBAAkB,EAAE,CAAC;IAwBtD;;;;;OAKG;IACG,gBAAgB,CACpB,UAAU,EAAE,oBAAoB,EAChC,UAAU,CAAC,EAAE,UAAU,GACtB,OAAO,CAAC,IAAI,CAAC;IAiChB;;;;OAIG;IACG,gBAAgB,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA6B7D;;;;;OAKG;IACG,0BAA0B,IAAI,OAAO,CAAC,uBAAuB,GAAG,IAAI,CAAC;IAgC3E;;;;;OAKG;IACG,0BAA0B,CAC9B,KAAK,EAAE,uBAAuB,EAC9B,UAAU,CAAC,EAAE,UAAU,GACtB,OAAO,CAAC,IAAI,CAAC;CA8CjB"}
1
+ {"version":3,"file":"authenticated-user-storage.d.cts","sourceRoot":"","sources":["../src/authenticated-user-storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,4BAA4B,EAC5B,oCAAoC,EACpC,kCAAkC,EACnC,oCAAoC;AACrC,OAAO,EAAE,eAAe,EAAE,oCAAoC;AAC9D,OAAO,KAAK,EAAE,0BAA0B,EAAE,mCAAmC;AAE7E,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAGrD,OAAO,KAAK,EAAE,4CAA4C,EAAE,6DAAyD;AACrH,OAAO,KAAK,E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AAE;QACD,SAAS,EAAE,iCAAiC,CAAC;QAC7C,WAAW,EAAE,WAAW,CAAC;QACzB,aAAa,CAAC,EAAE,0BAA0B,CAAC;KAC5C;IAUD;;;;OAIG;IACG,eAAe,IAAI,OAAO,CAAC,kBAAkB,EAAE,CAAC;IAwBtD;;;;;OAKG;IACG,gBAAgB,CACpB,UAAU,EAAE,oBAAoB,EAChC,UAAU,CAAC,EAAE,UAAU,GACtB,OAAO,CAAC,IAAI,CAAC;IAiChB;;;;OAIG;IACG,gBAAgB,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA6B7D;;;;;OAKG;IACG,0BAA0B,IAAI,OAAO,CAAC,uBAAuB,GAAG,IAAI,CAAC;IAgC3E;;;;;OAKG;IACG,0BAA0B,CAC9B,KAAK,EAAE,uBAAuB,EAC9B,UAAU,CAAC,EAAE,UAAU,GACtB,OAAO,CAAC,IAAI,CAAC;IAiChB;;;;OAIG;IACG,kBAAkB,IAAI,OAAO,CAAC,mBAAmB,GAAG,IAAI,CAAC;IAgC/D;;;;;;;;;;;OAWG;IACG,kBAAkB,CACtB,IAAI,EAAE,mBAAmB,EACzB,UAAU,CAAC,EAAE,UAAU,GACtB,OAAO,CAAC,IAAI,CAAC;CA6CjB"}
@@ -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.mjs";
6
6
  import type { Environment } from "./env.mjs";
7
- import type { ClientType, DelegationResponse, DelegationSubmission, NotificationPreferences } from "./types.mjs";
7
+ import type { AssetsWatchlistBlob, ClientType, DelegationResponse, DelegationSubmission, NotificationPreferences } from "./types.mjs";
8
8
  /**
9
9
  * The name of the {@link AuthenticatedUserStorageService} service, used to
10
10
  * namespace the service's actions and events.
@@ -118,6 +118,25 @@ export declare class AuthenticatedUserStorageService extends BaseDataService<typ
118
118
  * @param clientType - Optional client type header.
119
119
  */
120
120
  putNotificationPreferences(prefs: NotificationPreferences, clientType?: ClientType): Promise<void>;
121
+ /**
122
+ * Returns the assets-watchlist for the authenticated user.
123
+ *
124
+ * @returns The assets-watchlist blob, or `null` if none has been set (404).
125
+ */
126
+ getAssetsWatchlist(): Promise<AssetsWatchlistBlob | null>;
127
+ /**
128
+ * Creates or updates the assets-watchlist for the authenticated user.
129
+ *
130
+ * @param blob - The full assets-watchlist blob. The `assets` array may
131
+ * contain at most `ASSETS_WATCHLIST_MAX_ASSETS` CAIP-19 asset identifiers;
132
+ * this is enforced by `assertAssetsWatchlistBlobForWrite` before the
133
+ * request is sent.
134
+ * @param clientType - Optional client type header.
135
+ * @throws A `StructError` from `@metamask/superstruct` if `blob` is
136
+ * structurally invalid or `assets` exceeds the cap; an `HttpError` from
137
+ * `@metamask/controller-utils` if the API responds with a non-2xx status.
138
+ */
139
+ setAssetsWatchlist(blob: AssetsWatchlistBlob, clientType?: ClientType): Promise<void>;
121
140
  }
122
141
  export {};
123
142
  //# sourceMappingURL=authenticated-user-storage.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"authenticated-user-storage.d.mts","sourceRoot":"","sources":["../src/authenticated-user-storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,4BAA4B,EAC5B,oCAAoC,EACpC,kCAAkC,EACnC,oCAAoC;AACrC,OAAO,EAAE,eAAe,EAAE,oCAAoC;AAC9D,OAAO,KAAK,EAAE,0BAA0B,EAAE,mCAAmC;AAE7E,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAGrD,OAAO,KAAK,EAAE,4CAA4C,EAAE,6DAAyD;AACrH,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAc;AAEzC,OAAO,KAAK,EACV,UAAU,EACV,kBAAkB,EAClB,oBAAoB,EACpB,uBAAuB,EACxB,oBAAgB;AAQjB;;;GAGG;AACH,eAAO,MAAM,WAAW,oCAAoC,CAAC;AAE7D;;;;;GAKG;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;IACG,gBAAgB,CACpB,UAAU,EAAE,oBAAoB,EAChC,UAAU,CAAC,EAAE,UAAU,GACtB,OAAO,CAAC,IAAI,CAAC;IAiChB;;;;OAIG;IACG,gBAAgB,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA6B7D;;;;;OAKG;IACG,0BAA0B,IAAI,OAAO,CAAC,uBAAuB,GAAG,IAAI,CAAC;IAgC3E;;;;;OAKG;IACG,0BAA0B,CAC9B,KAAK,EAAE,uBAAuB,EAC9B,UAAU,CAAC,EAAE,UAAU,GACtB,OAAO,CAAC,IAAI,CAAC;CA8CjB"}
1
+ {"version":3,"file":"authenticated-user-storage.d.mts","sourceRoot":"","sources":["../src/authenticated-user-storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,4BAA4B,EAC5B,oCAAoC,EACpC,kCAAkC,EACnC,oCAAoC;AACrC,OAAO,EAAE,eAAe,EAAE,oCAAoC;AAC9D,OAAO,KAAK,EAAE,0BAA0B,EAAE,mCAAmC;AAE7E,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAGrD,OAAO,KAAK,EAAE,4CAA4C,EAAE,6DAAyD;AACrH,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAc;AAEzC,OAAO,KAAK,EACV,mBAAmB,EACnB,UAAU,EACV,kBAAkB,EAClB,oBAAoB,EACpB,uBAAuB,EACxB,oBAAgB;AAUjB;;;GAGG;AACH,eAAO,MAAM,WAAW,oCAAoC,CAAC;AAE7D;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,WAAW,EAAE,WAAW,GAAG,MAAM,CAE3E;AAcD;;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,EAA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IACG,0BAA0B,CAC9B,KAAK,EAAE,uBAAuB,EAC9B,UAAU,CAAC,EAAE,UAAU,GACtB,OAAO,CAAC,IAAI,CAAC;IAiChB;;;;OAIG;IACG,kBAAkB,IAAI,OAAO,CAAC,mBAAmB,GAAG,IAAI,CAAC;IAgC/D;;;;;;;;;;;OAWG;IACG,kBAAkB,CACtB,IAAI,EAAE,mBAAmB,EACzB,UAAU,CAAC,EAAE,UAAU,GACtB,OAAO,CAAC,IAAI,CAAC;CA6CjB"}
@@ -13,7 +13,7 @@ var _AuthenticatedUserStorageService_instances, _AuthenticatedUserStorageService
13
13
  import { BaseDataService } from "@metamask/base-data-service";
14
14
  import { HttpError } from "@metamask/controller-utils";
15
15
  import { getUserStorageApiUrl } from "./env.mjs";
16
- import { assertDelegationResponseArray, assertNotificationPreferences } from "./validators.mjs";
16
+ import { assertAssetsWatchlistBlob, assertAssetsWatchlistBlobForWrite, assertDelegationResponseArray, assertNotificationPreferences } from "./validators.mjs";
17
17
  // === GENERAL ===
18
18
  /**
19
19
  * The name of the {@link AuthenticatedUserStorageService} service, used to
@@ -36,6 +36,8 @@ const MESSENGER_EXPOSED_METHODS = [
36
36
  'revokeDelegation',
37
37
  'getNotificationPreferences',
38
38
  'putNotificationPreferences',
39
+ 'getAssetsWatchlist',
40
+ 'setAssetsWatchlist',
39
41
  ];
40
42
  // === SERVICE ===
41
43
  /**
@@ -198,6 +200,68 @@ export class AuthenticatedUserStorageService extends BaseDataService {
198
200
  queryKey: [`${this.name}:getNotificationPreferences`],
199
201
  });
200
202
  }
203
+ /**
204
+ * Returns the assets-watchlist for the authenticated user.
205
+ *
206
+ * @returns The assets-watchlist blob, or `null` if none has been set (404).
207
+ */
208
+ async getAssetsWatchlist() {
209
+ const url = `${getAuthenticatedStorageUrl(__classPrivateFieldGet(this, _AuthenticatedUserStorageService_environment, "f"))}/assets-watchlist`;
210
+ const data = await this.fetchQuery({
211
+ queryKey: [`${this.name}:getAssetsWatchlist`],
212
+ queryFn: async () => {
213
+ const headers = await __classPrivateFieldGet(this, _AuthenticatedUserStorageService_instances, "m", _AuthenticatedUserStorageService_getHeaders).call(this);
214
+ const response = await fetch(url, { headers });
215
+ if (response.status === 404) {
216
+ return null;
217
+ }
218
+ if (!response.ok) {
219
+ throw new HttpError(response.status, `Failed to get assets watchlist: ${response.status}`);
220
+ }
221
+ return response.json();
222
+ },
223
+ });
224
+ if (data === null) {
225
+ return null;
226
+ }
227
+ assertAssetsWatchlistBlob(data);
228
+ return data;
229
+ }
230
+ /**
231
+ * Creates or updates the assets-watchlist for the authenticated user.
232
+ *
233
+ * @param blob - The full assets-watchlist blob. The `assets` array may
234
+ * contain at most `ASSETS_WATCHLIST_MAX_ASSETS` CAIP-19 asset identifiers;
235
+ * this is enforced by `assertAssetsWatchlistBlobForWrite` before the
236
+ * request is sent.
237
+ * @param clientType - Optional client type header.
238
+ * @throws A `StructError` from `@metamask/superstruct` if `blob` is
239
+ * structurally invalid or `assets` exceeds the cap; an `HttpError` from
240
+ * `@metamask/controller-utils` if the API responds with a non-2xx status.
241
+ */
242
+ async setAssetsWatchlist(blob, clientType) {
243
+ assertAssetsWatchlistBlobForWrite(blob);
244
+ const url = `${getAuthenticatedStorageUrl(__classPrivateFieldGet(this, _AuthenticatedUserStorageService_environment, "f"))}/assets-watchlist`;
245
+ await this.fetchQuery({
246
+ queryKey: [`${this.name}:setAssetsWatchlist`, blob],
247
+ staleTime: 0,
248
+ queryFn: async () => {
249
+ const headers = await __classPrivateFieldGet(this, _AuthenticatedUserStorageService_instances, "m", _AuthenticatedUserStorageService_getHeaders).call(this, clientType);
250
+ const response = await fetch(url, {
251
+ method: 'PUT',
252
+ headers,
253
+ body: JSON.stringify(blob),
254
+ });
255
+ if (!response.ok) {
256
+ throw new HttpError(response.status, `Failed to put assets watchlist: ${response.status}`);
257
+ }
258
+ return null;
259
+ },
260
+ });
261
+ await this.invalidateQueries({
262
+ queryKey: [`${this.name}:getAssetsWatchlist`],
263
+ });
264
+ }
201
265
  }
202
266
  _AuthenticatedUserStorageService_environment = new WeakMap(), _AuthenticatedUserStorageService_instances = new WeakSet(), _AuthenticatedUserStorageService_getHeaders = async function _AuthenticatedUserStorageService_getHeaders(clientType) {
203
267
  const accessToken = await this.messenger.call('AuthenticationController:getBearerToken');