@metamask/profile-sync-controller 0.1.4 → 0.2.0

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 (78) hide show
  1. package/CHANGELOG.md +29 -1
  2. package/dist/{chunk-5SXXO4MV.js → chunk-3TE6M5TV.js} +10 -8
  3. package/dist/chunk-3TE6M5TV.js.map +1 -0
  4. package/dist/{chunk-CSFHMILK.js → chunk-77LSWSGB.js} +8 -8
  5. package/dist/{chunk-CSFHMILK.js.map → chunk-77LSWSGB.js.map} +1 -1
  6. package/dist/{chunk-RT2GRG4S.mjs → chunk-7KMONAQI.mjs} +3 -3
  7. package/dist/{chunk-2XGRQBXI.mjs → chunk-FU7PSGFP.mjs} +10 -8
  8. package/dist/chunk-FU7PSGFP.mjs.map +1 -0
  9. package/dist/{chunk-P52TG263.js → chunk-FUPEFLXB.js} +18 -24
  10. package/dist/chunk-FUPEFLXB.js.map +1 -0
  11. package/dist/chunk-ILIZJQ6X.mjs +40 -0
  12. package/dist/chunk-ILIZJQ6X.mjs.map +1 -0
  13. package/dist/{chunk-3SNLHEYU.mjs → chunk-IQECLCH4.mjs} +5 -5
  14. package/dist/{chunk-3SNLHEYU.mjs.map → chunk-IQECLCH4.mjs.map} +1 -1
  15. package/dist/{chunk-TUMNNWY6.mjs → chunk-LNSB4L7K.mjs} +8 -8
  16. package/dist/chunk-LNSB4L7K.mjs.map +1 -0
  17. package/dist/{chunk-AXWK4Y23.mjs → chunk-NPH5AHLH.mjs} +19 -25
  18. package/dist/chunk-NPH5AHLH.mjs.map +1 -0
  19. package/dist/{chunk-3DMUUTKC.js → chunk-PSR2V3R4.js} +6 -6
  20. package/dist/{chunk-DDOYG42A.js → chunk-R2S3HIDN.js} +10 -10
  21. package/dist/chunk-R2S3HIDN.js.map +1 -0
  22. package/dist/chunk-SLHAVOTE.js +40 -0
  23. package/dist/chunk-SLHAVOTE.js.map +1 -0
  24. package/dist/{chunk-JFVONPMM.mjs → chunk-VYZPOR47.mjs} +15 -1
  25. package/dist/chunk-VYZPOR47.mjs.map +1 -0
  26. package/dist/{chunk-KUTU3NNS.js → chunk-XSSIP3PJ.js} +15 -1
  27. package/dist/chunk-XSSIP3PJ.js.map +1 -0
  28. package/dist/controllers/authentication/AuthenticationController.js +8 -3
  29. package/dist/controllers/authentication/AuthenticationController.mjs +8 -3
  30. package/dist/controllers/authentication/index.js +8 -3
  31. package/dist/controllers/authentication/index.mjs +8 -3
  32. package/dist/controllers/authentication/services.js +8 -3
  33. package/dist/controllers/authentication/services.mjs +8 -3
  34. package/dist/controllers/index.js +12 -12
  35. package/dist/controllers/index.mjs +11 -11
  36. package/dist/controllers/user-storage/UserStorageController.js +11 -11
  37. package/dist/controllers/user-storage/UserStorageController.mjs +10 -10
  38. package/dist/controllers/user-storage/index.js +15 -15
  39. package/dist/controllers/user-storage/index.mjs +14 -14
  40. package/dist/controllers/user-storage/schema.js +4 -2
  41. package/dist/controllers/user-storage/schema.mjs +7 -5
  42. package/dist/controllers/user-storage/services.js +10 -10
  43. package/dist/controllers/user-storage/services.mjs +9 -9
  44. package/dist/index.js +12 -12
  45. package/dist/index.mjs +11 -11
  46. package/dist/sdk/authentication.js +2 -2
  47. package/dist/sdk/authentication.mjs +1 -1
  48. package/dist/sdk/index.js +9 -4
  49. package/dist/sdk/index.mjs +8 -3
  50. package/dist/sdk/user-storage.js +7 -2
  51. package/dist/sdk/user-storage.mjs +6 -1
  52. package/dist/tsconfig.build.tsbuildinfo +1 -1
  53. package/dist/types/controllers/user-storage/UserStorageController.d.ts +6 -6
  54. package/dist/types/controllers/user-storage/UserStorageController.d.ts.map +1 -1
  55. package/dist/types/controllers/user-storage/schema.d.ts +18 -10
  56. package/dist/types/controllers/user-storage/schema.d.ts.map +1 -1
  57. package/dist/types/controllers/user-storage/services.d.ts +2 -2
  58. package/dist/types/controllers/user-storage/services.d.ts.map +1 -1
  59. package/dist/types/sdk/__fixtures__/mock-userstorage.d.ts.map +1 -1
  60. package/dist/types/sdk/authentication.d.ts +1 -0
  61. package/dist/types/sdk/authentication.d.ts.map +1 -1
  62. package/dist/types/sdk/user-storage.d.ts +4 -3
  63. package/dist/types/sdk/user-storage.d.ts.map +1 -1
  64. package/package.json +11 -10
  65. package/dist/chunk-2XGRQBXI.mjs.map +0 -1
  66. package/dist/chunk-5SXXO4MV.js.map +0 -1
  67. package/dist/chunk-AUFUOKJW.mjs +0 -25
  68. package/dist/chunk-AUFUOKJW.mjs.map +0 -1
  69. package/dist/chunk-AXWK4Y23.mjs.map +0 -1
  70. package/dist/chunk-B6CSNLGE.js +0 -25
  71. package/dist/chunk-B6CSNLGE.js.map +0 -1
  72. package/dist/chunk-DDOYG42A.js.map +0 -1
  73. package/dist/chunk-JFVONPMM.mjs.map +0 -1
  74. package/dist/chunk-KUTU3NNS.js.map +0 -1
  75. package/dist/chunk-P52TG263.js.map +0 -1
  76. package/dist/chunk-TUMNNWY6.mjs.map +0 -1
  77. /package/dist/{chunk-RT2GRG4S.mjs.map → chunk-7KMONAQI.mjs.map} +0 -0
  78. /package/dist/{chunk-3DMUUTKC.js.map → chunk-PSR2V3R4.js.map} +0 -0
@@ -1,3 +1,6 @@
1
+ import {
2
+ createEntryPath
3
+ } from "./chunk-ILIZJQ6X.mjs";
1
4
  import {
2
5
  createSHA256Hash,
3
6
  encryption_default
@@ -7,8 +10,7 @@ import {
7
10
  } from "./chunk-FQ5SDMRE.mjs";
8
11
  import {
9
12
  NotFoundError,
10
- UserStorageError,
11
- ValidationError
13
+ UserStorageError
12
14
  } from "./chunk-TFFQFIJV.mjs";
13
15
  import {
14
16
  __privateAdd,
@@ -16,7 +18,7 @@ import {
16
18
  } from "./chunk-U5UIDVOO.mjs";
17
19
 
18
20
  // src/sdk/user-storage.ts
19
- var STORAGE_URL = (env, feature, entry) => `${getEnvUrls(env).userStorageApiUrl}/api/v1/userstorage/${feature}/${entry}`;
21
+ var STORAGE_URL = (env, encryptedPath) => `${getEnvUrls(env).userStorageApiUrl}/api/v1/userstorage/${encryptedPath}`;
20
22
  var _upsertUserStorage, upsertUserStorage_fn, _getUserStorage, getUserStorage_fn, _createEntryKey, createEntryKey_fn, _getAuthorizationHeader, getAuthorizationHeader_fn;
21
23
  var UserStorage = class {
22
24
  constructor(config, options) {
@@ -30,17 +32,11 @@ var UserStorage = class {
30
32
  this.config = config;
31
33
  this.options = options;
32
34
  }
33
- async setItem(feature, key, value) {
34
- if (!feature.trim() || !key.trim()) {
35
- throw new ValidationError("feature or key cannot be empty strings");
36
- }
37
- await __privateMethod(this, _upsertUserStorage, upsertUserStorage_fn).call(this, feature, key, value);
35
+ async setItem(path, value) {
36
+ await __privateMethod(this, _upsertUserStorage, upsertUserStorage_fn).call(this, path, value);
38
37
  }
39
- async getItem(feature, key) {
40
- if (!feature.trim() || !key.trim()) {
41
- throw new ValidationError("feature or key cannot be empty strings");
42
- }
43
- return __privateMethod(this, _getUserStorage, getUserStorage_fn).call(this, feature, key);
38
+ async getItem(path) {
39
+ return __privateMethod(this, _getUserStorage, getUserStorage_fn).call(this, path);
44
40
  }
45
41
  async getStorageKey() {
46
42
  const storageKey = await this.options.storage?.getStorageKey();
@@ -57,14 +53,13 @@ var UserStorage = class {
57
53
  }
58
54
  };
59
55
  _upsertUserStorage = new WeakSet();
60
- upsertUserStorage_fn = async function(feature, key, data) {
56
+ upsertUserStorage_fn = async function(path, data) {
61
57
  try {
62
58
  const headers = await __privateMethod(this, _getAuthorizationHeader, getAuthorizationHeader_fn).call(this);
63
59
  const storageKey = await this.getStorageKey();
64
60
  const encryptedData = encryption_default.encryptString(data, storageKey);
65
- const url = new URL(
66
- STORAGE_URL(this.env, feature, __privateMethod(this, _createEntryKey, createEntryKey_fn).call(this, key, storageKey))
67
- );
61
+ const encryptedPath = createEntryPath(path, storageKey);
62
+ const url = new URL(STORAGE_URL(this.env, encryptedPath));
68
63
  const response = await fetch(url.toString(), {
69
64
  method: "PUT",
70
65
  headers: {
@@ -85,18 +80,17 @@ upsertUserStorage_fn = async function(feature, key, data) {
85
80
  } catch (e) {
86
81
  const errorMessage = e instanceof Error ? e.message : JSON.stringify(e ?? "");
87
82
  throw new UserStorageError(
88
- `failed to upsert user storage for feature '${feature}' and key '${key}'. ${errorMessage}`
83
+ `failed to upsert user storage for path '${path}'. ${errorMessage}`
89
84
  );
90
85
  }
91
86
  };
92
87
  _getUserStorage = new WeakSet();
93
- getUserStorage_fn = async function(feature, key) {
88
+ getUserStorage_fn = async function(path) {
94
89
  try {
95
90
  const headers = await __privateMethod(this, _getAuthorizationHeader, getAuthorizationHeader_fn).call(this);
96
91
  const storageKey = await this.getStorageKey();
97
- const url = new URL(
98
- STORAGE_URL(this.env, feature, __privateMethod(this, _createEntryKey, createEntryKey_fn).call(this, key, storageKey))
99
- );
92
+ const encryptedPath = createEntryPath(path, storageKey);
93
+ const url = new URL(STORAGE_URL(this.env, encryptedPath));
100
94
  const response = await fetch(url.toString(), {
101
95
  headers: {
102
96
  "Content-Type": "application/json",
@@ -105,7 +99,7 @@ getUserStorage_fn = async function(feature, key) {
105
99
  });
106
100
  if (response.status === 404) {
107
101
  throw new NotFoundError(
108
- `feature/key set not found for feature '${feature}' and key '${key}'.`
102
+ `feature/key set not found for path '${path}'.`
109
103
  );
110
104
  }
111
105
  if (!response.ok) {
@@ -122,7 +116,7 @@ getUserStorage_fn = async function(feature, key) {
122
116
  }
123
117
  const errorMessage = e instanceof Error ? e.message : JSON.stringify(e ?? "");
124
118
  throw new UserStorageError(
125
- `failed to get user storage for feature '${feature}' and key '${key}'. ${errorMessage}`
119
+ `failed to get user storage for path '${path}'. ${errorMessage}`
126
120
  );
127
121
  }
128
122
  };
@@ -141,4 +135,4 @@ export {
141
135
  STORAGE_URL,
142
136
  UserStorage
143
137
  };
144
- //# sourceMappingURL=chunk-AXWK4Y23.mjs.map
138
+ //# sourceMappingURL=chunk-NPH5AHLH.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/sdk/user-storage.ts"],"sourcesContent":["import type { UserStoragePath } from '../controllers/user-storage/schema';\nimport { createEntryPath } from '../controllers/user-storage/schema';\nimport type { IBaseAuth } from './authentication-jwt-bearer/types';\nimport encryption, { createSHA256Hash } from './encryption';\nimport type { Env } from './env';\nimport { getEnvUrls } from './env';\nimport { NotFoundError, UserStorageError } from './errors';\n\nexport const STORAGE_URL = (env: Env, encryptedPath: string) =>\n `${getEnvUrls(env).userStorageApiUrl}/api/v1/userstorage/${encryptedPath}`;\n\nexport type UserStorageConfig = {\n env: Env;\n auth: Pick<IBaseAuth, 'getAccessToken' | 'getUserProfile' | 'signMessage'>;\n};\n\nexport type StorageOptions = {\n getStorageKey: () => Promise<string | null>;\n setStorageKey: (val: string) => Promise<void>;\n};\n\nexport type UserStorageOptions = {\n storage?: StorageOptions;\n};\n\ntype ErrorMessage = {\n message: string;\n error: string;\n};\n\nexport class UserStorage {\n protected config: UserStorageConfig;\n\n protected options: UserStorageOptions;\n\n protected env: Env;\n\n constructor(config: UserStorageConfig, options: UserStorageOptions) {\n this.env = config.env;\n this.config = config;\n this.options = options;\n }\n\n async setItem(path: UserStoragePath, value: string): Promise<void> {\n await this.#upsertUserStorage(path, value);\n }\n\n async getItem(path: UserStoragePath): Promise<string> {\n return this.#getUserStorage(path);\n }\n\n async getStorageKey(): Promise<string> {\n const storageKey = await this.options.storage?.getStorageKey();\n if (storageKey) {\n return storageKey;\n }\n\n const userProfile = await this.config.auth.getUserProfile();\n const storageKeySignature = await this.config.auth.signMessage(\n `metamask:${userProfile.profileId}`,\n );\n const hashedStorageKeySignature = createSHA256Hash(storageKeySignature);\n await this.options.storage?.setStorageKey(hashedStorageKeySignature);\n return hashedStorageKeySignature;\n }\n\n async #upsertUserStorage(path: UserStoragePath, data: string): Promise<void> {\n try {\n const headers = await this.#getAuthorizationHeader();\n const storageKey = await this.getStorageKey();\n const encryptedData = encryption.encryptString(data, storageKey);\n const encryptedPath = createEntryPath(path, storageKey);\n\n const url = new URL(STORAGE_URL(this.env, encryptedPath));\n\n const response = await fetch(url.toString(), {\n method: 'PUT',\n headers: {\n 'Content-Type': 'application/json',\n ...headers,\n },\n body: JSON.stringify({ data: encryptedData }),\n });\n\n if (!response.ok) {\n const responseBody: ErrorMessage = await response.json().catch(() => ({\n message: 'unknown',\n error: 'unknown',\n }));\n throw new Error(\n `HTTP error message: ${responseBody.message}, error: ${responseBody.error}`,\n );\n }\n } catch (e) {\n /* istanbul ignore next */\n const errorMessage =\n e instanceof Error ? e.message : JSON.stringify(e ?? '');\n throw new UserStorageError(\n `failed to upsert user storage for path '${path}'. ${errorMessage}`,\n );\n }\n }\n\n async #getUserStorage(path: UserStoragePath): Promise<string> {\n try {\n const headers = await this.#getAuthorizationHeader();\n const storageKey = await this.getStorageKey();\n const encryptedPath = createEntryPath(path, storageKey);\n\n const url = new URL(STORAGE_URL(this.env, encryptedPath));\n\n const response = await fetch(url.toString(), {\n headers: {\n 'Content-Type': 'application/json',\n ...headers,\n },\n });\n\n if (response.status === 404) {\n throw new NotFoundError(\n `feature/key set not found for path '${path}'.`,\n );\n }\n\n if (!response.ok) {\n const responseBody = (await response.json()) as ErrorMessage;\n throw new Error(\n `HTTP error message: ${responseBody.message}, error: ${responseBody.error}`,\n );\n }\n\n const { Data: encryptedData } = await response.json();\n return encryption.decryptString(encryptedData, storageKey);\n } catch (e) {\n if (e instanceof NotFoundError) {\n throw e;\n }\n\n /* istanbul ignore next */\n const errorMessage =\n e instanceof Error ? e.message : JSON.stringify(e ?? '');\n\n throw new UserStorageError(\n `failed to get user storage for path '${path}'. ${errorMessage}`,\n );\n }\n }\n\n #createEntryKey(key: string, storageKey: string): string {\n const hashedKey = createSHA256Hash(key + storageKey);\n return hashedKey;\n }\n\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n async #getAuthorizationHeader(): Promise<{ Authorization: string }> {\n const accessToken = await this.config.auth.getAccessToken();\n return { Authorization: `Bearer ${accessToken}` };\n }\n}\n"],"mappings":";;;;;;;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AAa,eAAe;AAC9B,YAAM;AAAA,IACR;AAGA,UAAM,eACJ,aAAa,QAAQ,EAAE,UAAU,KAAK,UAAU,KAAK,EAAE;AAEzD,UAAM,IAAI;AAAA,MACR,wCAAwC,IAAI,MAAM,YAAY;AAAA,IAChE;AAAA,EACF;AACF;AAEA;AAAA,oBAAe,SAAC,KAAa,YAA4B;AACvD,QAAM,YAAY,iBAAiB,MAAM,UAAU;AACnD,SAAO;AACT;AAIM;AAAA,4BAAuB,iBAAuC;AAClE,QAAM,cAAc,MAAM,KAAK,OAAO,KAAK,eAAe;AAC1D,SAAO,EAAE,eAAe,UAAU,WAAW,GAAG;AAClD;","names":[]}
@@ -1,6 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkKUTU3NNSjs = require('./chunk-KUTU3NNS.js');
3
+ var _chunkXSSIP3PJjs = require('./chunk-XSSIP3PJ.js');
4
4
 
5
5
 
6
6
  var _chunkG4NU4KP7js = require('./chunk-G4NU4KP7.js');
@@ -20,7 +20,7 @@ var _chunkPQ5T4GHYjs = require('./chunk-PQ5T4GHY.js');
20
20
 
21
21
 
22
22
 
23
- var _chunkP52TG263js = require('./chunk-P52TG263.js');
23
+ var _chunkFUPEFLXBjs = require('./chunk-FUPEFLXB.js');
24
24
 
25
25
 
26
26
 
@@ -50,7 +50,7 @@ _chunkIGY2S5BCjs.__export.call(void 0, sdk_exports, {
50
50
  AuthType: () => _chunkPBRUOBEQjs.AuthType,
51
51
  Encryption: () => _chunkP4DUDLMYjs.Encryption,
52
52
  Env: () => _chunkSMKTWM6Ijs.Env,
53
- JwtBearerAuth: () => _chunkKUTU3NNSjs.JwtBearerAuth,
53
+ JwtBearerAuth: () => _chunkXSSIP3PJjs.JwtBearerAuth,
54
54
  MESSAGE_SIGNING_SNAP: () => _chunkPQ5T4GHYjs.MESSAGE_SIGNING_SNAP,
55
55
  NonceRetrievalError: () => _chunkMBTBE4P5js.NonceRetrievalError,
56
56
  NotFoundError: () => _chunkMBTBE4P5js.NotFoundError,
@@ -59,10 +59,10 @@ _chunkIGY2S5BCjs.__export.call(void 0, sdk_exports, {
59
59
  SIWEJwtBearerAuth: () => _chunkG4NU4KP7js.SIWEJwtBearerAuth,
60
60
  SNAP_ORIGIN: () => _chunkPQ5T4GHYjs.SNAP_ORIGIN,
61
61
  SRPJwtBearerAuth: () => _chunkVD2IGTS3js.SRPJwtBearerAuth,
62
- STORAGE_URL: () => _chunkP52TG263js.STORAGE_URL,
62
+ STORAGE_URL: () => _chunkFUPEFLXBjs.STORAGE_URL,
63
63
  SignInError: () => _chunkMBTBE4P5js.SignInError,
64
64
  UnsupportedAuthTypeError: () => _chunkMBTBE4P5js.UnsupportedAuthTypeError,
65
- UserStorage: () => _chunkP52TG263js.UserStorage,
65
+ UserStorage: () => _chunkFUPEFLXBjs.UserStorage,
66
66
  UserStorageError: () => _chunkMBTBE4P5js.UserStorageError,
67
67
  ValidationError: () => _chunkMBTBE4P5js.ValidationError,
68
68
  connectSnap: () => _chunkPQ5T4GHYjs.connectSnap,
@@ -76,4 +76,4 @@ _chunkIGY2S5BCjs.__export.call(void 0, sdk_exports, {
76
76
 
77
77
 
78
78
  exports.sdk_exports = sdk_exports;
79
- //# sourceMappingURL=chunk-3DMUUTKC.js.map
79
+ //# sourceMappingURL=chunk-PSR2V3R4.js.map
@@ -4,7 +4,7 @@ var _chunkYHGWG3EQjs = require('./chunk-YHGWG3EQ.js');
4
4
 
5
5
 
6
6
 
7
- var _chunk5SXXO4MVjs = require('./chunk-5SXXO4MV.js');
7
+ var _chunk3TE6M5TVjs = require('./chunk-3TE6M5TV.js');
8
8
 
9
9
 
10
10
  var _chunkT3FNDVE3js = require('./chunk-T3FNDVE3.js');
@@ -161,14 +161,14 @@ var UserStorageController = class extends _basecontroller.BaseController {
161
161
  * Allows retrieval of stored data. Data stored is string formatted.
162
162
  * Developers can extend the entry path and entry name through the `schema.ts` file.
163
163
  *
164
- * @param entryKey - entry key that matches schema
164
+ * @param path - string in the form of `${feature}.${key}` that matches schema
165
165
  * @returns the decrypted string contents found from user storage (or null if not found)
166
166
  */
167
- async performGetStorage(entryKey) {
167
+ async performGetStorage(path) {
168
168
  _chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _assertProfileSyncingEnabled, assertProfileSyncingEnabled_fn).call(this);
169
169
  const { bearerToken, storageKey } = await _chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _getStorageKeyAndBearerToken, getStorageKeyAndBearerToken_fn).call(this);
170
- const result = await _chunk5SXXO4MVjs.getUserStorage.call(void 0, {
171
- entryKey,
170
+ const result = await _chunk3TE6M5TVjs.getUserStorage.call(void 0, {
171
+ path,
172
172
  bearerToken,
173
173
  storageKey
174
174
  });
@@ -178,15 +178,15 @@ var UserStorageController = class extends _basecontroller.BaseController {
178
178
  * Allows storage of user data. Data stored must be string formatted.
179
179
  * Developers can extend the entry path and entry name through the `schema.ts` file.
180
180
  *
181
- * @param entryKey - entry key that matches schema
181
+ * @param path - string in the form of `${feature}.${key}` that matches schema
182
182
  * @param value - The string data you want to store.
183
183
  * @returns nothing. NOTE that an error is thrown if fails to store data.
184
184
  */
185
- async performSetStorage(entryKey, value) {
185
+ async performSetStorage(path, value) {
186
186
  _chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _assertProfileSyncingEnabled, assertProfileSyncingEnabled_fn).call(this);
187
187
  const { bearerToken, storageKey } = await _chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _getStorageKeyAndBearerToken, getStorageKeyAndBearerToken_fn).call(this);
188
- await _chunk5SXXO4MVjs.upsertUserStorage.call(void 0, value, {
189
- entryKey,
188
+ await _chunk3TE6M5TVjs.upsertUserStorage.call(void 0, value, {
189
+ path,
190
190
  bearerToken,
191
191
  storageKey
192
192
  });
@@ -278,4 +278,4 @@ setIsProfileSyncingUpdateLoading_fn = function(isProfileSyncingUpdateLoading) {
278
278
 
279
279
 
280
280
  exports.defaultState = defaultState; exports.UserStorageController = UserStorageController;
281
- //# sourceMappingURL=chunk-DDOYG42A.js.map
281
+ //# sourceMappingURL=chunk-R2S3HIDN.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/controllers/user-storage/UserStorageController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAIA,SAAS,sBAAsB;AA4B/B,IAAM,iBAAiB;AAchB,IAAM,eAA2C;AAAA,EACtD,yBAAyB;AAAA,EACzB,+BAA+B;AACjC;AAEA,IAAM,WAAsD;AAAA,EAC1D,yBAAyB;AAAA,IACvB,SAAS;AAAA,IACT,WAAW;AAAA,EACb;AAAA,EACA,+BAA+B;AAAA,IAC7B,SAAS;AAAA,IACT,WAAW;AAAA,EACb;AACF;AA5DA;AAsHA,IAAqB,wBAArB,cAAmD,eAIjD;AAAA,EA2CA,YAAY,QAIT;AACD,UAAM;AAAA,MACJ,WAAW,OAAO;AAAA,MAClB;AAAA,MACA,MAAM;AAAA,MACN,OAAO,EAAE,GAAG,cAAc,GAAG,OAAO,MAAM;AAAA,IAC5C,CAAC;AAUH;AAAA;AAAA;AAAA;AAAA;AAyJA;AAWA;AAAA;AAAA;AAAA,uBAAM;AAkBN;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAM;AAmBN;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAM;AAeN;AAtRA,8BAAQ;AAAA,MACN,gBAAgB,YAAY;AAC1B,eAAO,MAAM,KAAK,gBAAgB;AAAA,UAChC;AAAA,QACF;AAAA,MACF;AAAA,MACA,cAAc,YAAY;AACxB,cAAM,iBAAiB,MAAM,KAAK,gBAAgB;AAAA,UAChD;AAAA,QACF;AACA,eAAO,gBAAgB;AAAA,MACzB;AAAA,MACA,eAAe,MAAM;AACnB,eAAO,KAAK,gBAAgB,KAAK,qCAAqC;AAAA,MACxE;AAAA,MACA,QAAQ,YAAY;AAClB,eAAO,MAAM,KAAK,gBAAgB;AAAA,UAChC;AAAA,QACF;AAAA,MACF;AAAA,MACA,SAAS,YAAY;AACnB,e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erMessenger,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { HandleSnapRequest } from '@metamask/snaps-controllers';\n\nimport { createSnapSignMessageRequest } from '../authentication/auth-snap-requests';\nimport type {\n AuthenticationControllerGetBearerToken,\n AuthenticationControllerGetSessionProfile,\n AuthenticationControllerIsSignedIn,\n AuthenticationControllerPerformSignIn,\n AuthenticationControllerPerformSignOut,\n} from '../authentication/AuthenticationController';\nimport { createSHA256Hash } from './encryption';\nimport type { UserStoragePath } from './schema';\nimport { getUserStorage, upsertUserStorage } from './services';\n\n// TODO: fix external dependencies\nexport declare type NotificationServicesControllerDisableNotificationServices =\n {\n type: `NotificationServicesController:disableNotificationServices`;\n handler: () => Promise<void>;\n };\n\nexport declare type NotificationServicesControllerSelectIsNotificationServicesEnabled =\n {\n type: `NotificationServicesController:selectIsNotificationServicesEnabled`;\n handler: () => boolean;\n };\n\nconst controllerName = 'UserStorageController';\n\n// State\nexport type UserStorageControllerState = {\n /**\n * Condition used by UI and to determine if we can use some of the User Storage methods.\n */\n isProfileSyncingEnabled: boolean | null;\n /**\n * Loading state for the profile syncing update\n */\n isProfileSyncingUpdateLoading: boolean;\n};\n\nexport const defaultState: UserStorageControllerState = {\n isProfileSyncingEnabled: true,\n isProfileSyncingUpdateLoading: false,\n};\n\nconst metadata: StateMetadata<UserStorageControllerState> = {\n isProfileSyncingEnabled: {\n persist: true,\n anonymous: true,\n },\n isProfileSyncingUpdateLoading: {\n persist: false,\n anonymous: false,\n },\n};\n\n// Messenger Actions\ntype CreateActionsObj<Controller extends keyof UserStorageController> = {\n [K in Controller]: {\n type: `${typeof controllerName}:${K}`;\n handler: UserStorageController[K];\n };\n};\ntype ActionsObj = CreateActionsObj<\n | 'performGetStorage'\n | 'performSetStorage'\n | 'getStorageKey'\n | 'enableProfileSyncing'\n | 'disableProfileSyncing'\n>;\nexport type Actions = ActionsObj[keyof ActionsObj];\nexport type UserStorageControllerPerformGetStorage =\n ActionsObj['performGetStorage'];\nexport type UserStorageControllerPerformSetStorage =\n ActionsObj['performSetStorage'];\nexport type UserStorageControllerGetStorageKey = ActionsObj['getStorageKey'];\nexport type UserStorageControllerEnableProfileSyncing =\n ActionsObj['enableProfileSyncing'];\nexport type UserStorageControllerDisableProfileSyncing =\n ActionsObj['disableProfileSyncing'];\n\n// Allowed Actions\nexport type AllowedActions =\n // Snap Requests\n | HandleSnapRequest\n // Auth Requests\n | AuthenticationControllerGetBearerToken\n | AuthenticationControllerGetSessionProfile\n | AuthenticationControllerPerformSignIn\n | AuthenticationControllerIsSignedIn\n | AuthenticationControllerPerformSignOut\n // Metamask Notifications\n | NotificationServicesControllerDisableNotificationServices\n | NotificationServicesControllerSelectIsNotificationServicesEnabled;\n\n// Messenger\nexport type UserStorageControllerMessenger = RestrictedControllerMessenger<\n typeof controllerName,\n Actions | AllowedActions,\n never,\n AllowedActions['type'],\n never\n>;\n\n/**\n * Reusable controller that allows any team to store synchronized data for a given user.\n * These can be settings shared cross MetaMask clients, or data we want to persist when uninstalling/reinstalling.\n *\n * NOTE:\n * - data stored on UserStorage is FULLY encrypted, with the only keys stored/managed on the client.\n * - No one can access this data unless they are have the SRP and are able to run the signing snap.\n */\nexport default class UserStorageController extends BaseController<\n typeof controllerName,\n UserStorageControllerState,\n UserStorageControllerMessenger\n> {\n #auth = {\n getBearerToken: async () => {\n return await this.messagingSystem.call(\n 'AuthenticationController:getBearerToken',\n );\n },\n getProfileId: async () => {\n const sessionProfile = await this.messagingSystem.call(\n 'AuthenticationController:getSessionProfile',\n );\n return sessionProfile?.profileId;\n },\n isAuthEnabled: () => {\n return this.messagingSystem.call('AuthenticationController:isSignedIn');\n },\n signIn: async () => {\n return await this.messagingSystem.call(\n 'AuthenticationController:performSignIn',\n );\n },\n signOut: async () => {\n return this.messagingSystem.call(\n 'AuthenticationController:performSignOut',\n );\n },\n };\n\n #notificationServices = {\n disableNotificationServices: async () => {\n return await this.messagingSystem.call(\n 'NotificationServicesController:disableNotificationServices',\n );\n },\n selectIsNotificationServicesEnabled: async () => {\n return this.messagingSystem.call(\n 'NotificationServicesController:selectIsNotificationServicesEnabled',\n );\n },\n };\n\n getMetaMetricsState: () => boolean;\n\n constructor(params: {\n messenger: UserStorageControllerMessenger;\n state?: UserStorageControllerState;\n getMetaMetricsState: () => boolean;\n }) {\n super({\n messenger: params.messenger,\n metadata,\n name: controllerName,\n state: { ...defaultState, ...params.state },\n });\n\n this.getMetaMetricsState = params.getMetaMetricsState;\n this.#registerMessageHandlers();\n }\n\n /**\n * Constructor helper for registering this controller's messaging system\n * actions.\n */\n #registerMessageHandlers(): void {\n this.messagingSystem.registerActionHandler(\n 'UserStorageController:performGetStorage',\n this.performGetStorage.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'UserStorageController:performSetStorage',\n this.performSetStorage.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'UserStorageController:getStorageKey',\n this.getStorageKey.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'UserStorageController:enableProfileSyncing',\n this.enableProfileSyncing.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'UserStorageController:disableProfileSyncing',\n this.disableProfileSyncing.bind(this),\n );\n }\n\n public async enableProfileSyncing(): Promise<void> {\n try {\n this.#setIsProfileSyncingUpdateLoading(true);\n\n const authEnabled = this.#auth.isAuthEnabled();\n if (!authEnabled) {\n await this.#auth.signIn();\n }\n\n this.update((state) => {\n state.isProfileSyncingEnabled = true;\n });\n\n this.#setIsProfileSyncingUpdateLoading(false);\n } catch (e) {\n this.#setIsProfileSyncingUpdateLoading(false);\n const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);\n throw new Error(\n `${controllerName} - failed to enable profile syncing - ${errorMessage}`,\n );\n }\n }\n\n public async setIsProfileSyncingEnabled(\n isProfileSyncingEnabled: boolean,\n ): Promise<void> {\n this.update((state) => {\n state.isProfileSyncingEnabled = isProfileSyncingEnabled;\n });\n }\n\n public async disableProfileSyncing(): Promise<void> {\n const isAlreadyDisabled = !this.state.isProfileSyncingEnabled;\n if (isAlreadyDisabled) {\n return;\n }\n\n try {\n this.#setIsProfileSyncingUpdateLoading(true);\n\n const isNotificationServicesEnabled =\n await this.#notificationServices.selectIsNotificationServicesEnabled();\n\n if (isNotificationServicesEnabled) {\n await this.#notificationServices.disableNotificationServices();\n }\n\n const isMetaMetricsParticipation = this.getMetaMetricsState();\n\n if (!isMetaMetricsParticipation) {\n this.messagingSystem.call('AuthenticationController:performSignOut');\n }\n\n this.#setIsProfileSyncingUpdateLoading(false);\n\n this.update((state) => {\n state.isProfileSyncingEnabled = false;\n });\n } catch (e) {\n this.#setIsProfileSyncingUpdateLoading(false);\n const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);\n throw new Error(\n `${controllerName} - failed to disable profile syncing - ${errorMessage}`,\n );\n }\n }\n\n /**\n * Allows retrieval of stored data. Data stored is string formatted.\n * Developers can extend the entry path and entry name through the `schema.ts` file.\n *\n * @param path - string in the form of `${feature}.${key}` that matches schema\n * @returns the decrypted string contents found from user storage (or null if not found)\n */\n public async performGetStorage(\n path: UserStoragePath,\n ): Promise<string | null> {\n this.#assertProfileSyncingEnabled();\n\n const { bearerToken, storageKey } =\n await this.#getStorageKeyAndBearerToken();\n\n const result = await getUserStorage({\n path,\n bearerToken,\n storageKey,\n });\n\n return result;\n }\n\n /**\n * Allows storage of user data. Data stored must be string formatted.\n * Developers can extend the entry path and entry name through the `schema.ts` file.\n *\n * @param path - string in the form of `${feature}.${key}` that matches schema\n * @param value - The string data you want to store.\n * @returns nothing. NOTE that an error is thrown if fails to store data.\n */\n public async performSetStorage(\n path: UserStoragePath,\n value: string,\n ): Promise<void> {\n this.#assertProfileSyncingEnabled();\n\n const { bearerToken, storageKey } =\n await this.#getStorageKeyAndBearerToken();\n\n await upsertUserStorage(value, {\n path,\n bearerToken,\n storageKey,\n });\n }\n\n /**\n * Retrieves the storage key, for internal use only!\n *\n * @returns the storage key\n */\n public async getStorageKey(): Promise<string> {\n this.#assertProfileSyncingEnabled();\n const storageKey = await this.#createStorageKey();\n return storageKey;\n }\n\n #assertProfileSyncingEnabled(): void {\n if (!this.state.isProfileSyncingEnabled) {\n throw new Error(\n `${controllerName}: Unable to call method, user is not authenticated`,\n );\n }\n }\n\n /**\n * Utility to get the bearer token and storage key\n */\n async #getStorageKeyAndBearerToken(): Promise<{\n bearerToken: string;\n storageKey: string;\n }> {\n const bearerToken = await this.#auth.getBearerToken();\n if (!bearerToken) {\n throw new Error('UserStorageController - unable to get bearer token');\n }\n const storageKey = await this.#createStorageKey();\n\n return { bearerToken, storageKey };\n }\n\n /**\n * Rather than storing the storage key, we can compute the storage key when needed.\n *\n * @returns the storage key\n */\n async #createStorageKey(): Promise<string> {\n const id: string = await this.#auth.getProfileId();\n if (!id) {\n throw new Error('UserStorageController - unable to create storage key');\n }\n\n const storageKeySignature = await this.#snapSignMessage(`metamask:${id}`);\n const storageKey = createSHA256Hash(storageKeySignature);\n return storageKey;\n }\n\n #_snapSignMessageCache: Record<`metamask:${string}`, string> = {};\n\n /**\n * Signs a specific message using an underlying auth snap.\n *\n * @param message - A specific tagged message to sign.\n * @returns A Signature created by the snap.\n */\n async #snapSignMessage(message: `metamask:${string}`): Promise<string> {\n if (this.#_snapSignMessageCache[message]) {\n return this.#_snapSignMessageCache[message];\n }\n\n const result = (await this.messagingSystem.call(\n 'SnapController:handleRequest',\n createSnapSignMessageRequest(message),\n )) as string;\n\n this.#_snapSignMessageCache[message] = result;\n\n return result;\n }\n\n #setIsProfileSyncingUpdateLoading(\n isProfileSyncingUpdateLoading: boolean,\n ): void {\n this.update((state) => {\n state.isProfileSyncingUpdateLoading = isProfileSyncingUpdateLoading;\n });\n }\n}\n"]}
@@ -0,0 +1,40 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkT3FNDVE3js = require('./chunk-T3FNDVE3.js');
4
+
5
+ // src/controllers/user-storage/schema.ts
6
+ var USER_STORAGE_SCHEMA = {
7
+ notifications: ["notificationSettings"]
8
+ };
9
+ var getFeatureAndKeyFromPath = (path) => {
10
+ const pathRegex = /^\w+\.\w+$/u;
11
+ if (!pathRegex.test(path)) {
12
+ throw new Error(
13
+ `user-storage - path is not in the correct format. Correct format: 'feature.key'`
14
+ );
15
+ }
16
+ const [feature, key] = path.split(".");
17
+ if (!(feature in USER_STORAGE_SCHEMA)) {
18
+ throw new Error(`user-storage - invalid feature provided: ${feature}`);
19
+ }
20
+ const validFeature = USER_STORAGE_SCHEMA[feature];
21
+ if (!validFeature.includes(key)) {
22
+ const validKeys = USER_STORAGE_SCHEMA[feature].join(", ");
23
+ throw new Error(
24
+ `user-storage - invalid key provided for this feature: ${key}. Valid keys: ${validKeys}`
25
+ );
26
+ }
27
+ return { feature, key };
28
+ };
29
+ function createEntryPath(path, storageKey) {
30
+ const { feature, key } = getFeatureAndKeyFromPath(path);
31
+ const hashedKey = _chunkT3FNDVE3js.createSHA256Hash.call(void 0, key + storageKey);
32
+ return `/${feature}/${hashedKey}`;
33
+ }
34
+
35
+
36
+
37
+
38
+
39
+ exports.USER_STORAGE_SCHEMA = USER_STORAGE_SCHEMA; exports.getFeatureAndKeyFromPath = getFeatureAndKeyFromPath; exports.createEntryPath = createEntryPath;
40
+ //# sourceMappingURL=chunk-SLHAVOTE.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/controllers/user-storage/schema.ts"],"names":[],"mappings":";;;;;AAOO,IAAM,sBAAsB;AAAA,EACjC,eAAe,CAAC,sBAAsB;AACxC;AAgBO,IAAM,2BAA2B,CACtC,SAC6B;AAC7B,QAAM,YAAY;AAElB,MAAI,CAAC,UAAU,KAAK,IAAI,GAAG;AACzB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,QAAM,CAAC,SAAS,GAAG,IAAI,KAAK,MAAM,GAAG;AAKrC,MAAI,EAAE,WAAW,sBAAsB;AACrC,UAAM,IAAI,MAAM,4CAA4C,OAAO,EAAE;AAAA,EACvE;AAEA,QAAM,eAAe,oBAAoB,OAAO;AAEhD,MAAI,CAAC,aAAa,SAAS,GAAG,GAAG;AAC/B,UAAM,YAAY,oBAAoB,OAAO,EAAE,KAAK,IAAI;AAExD,UAAM,IAAI;AAAA,MACR,yDAAyD,GAAG,iBAAiB,SAAS;AAAA,IACxF;AAAA,EACF;AAEA,SAAO,EAAE,SAAS,IAAI;AACxB;AAWO,SAAS,gBACd,MACA,YACQ;AACR,QAAM,EAAE,SAAS,IAAI,IAAI,yBAAyB,IAAI;AACtD,QAAM,YAAY,iBAAiB,MAAM,UAAU;AAEnD,SAAO,IAAI,OAAO,IAAI,SAAS;AACjC","sourcesContent":["import { createSHA256Hash } from './encryption';\n\n/**\n * The User Storage Endpoint requires a feature name and a namespace key.\n * Developers can provide additional features and keys by extending these types below.\n */\n\nexport const USER_STORAGE_SCHEMA = {\n notifications: ['notificationSettings'],\n} as const;\n\ntype UserStorageSchema = typeof USER_STORAGE_SCHEMA;\ntype UserStorageFeatures = keyof UserStorageSchema;\ntype UserStorageFeatureKeys<Feature extends UserStorageFeatures> =\n UserStorageSchema[Feature][number];\n\ntype UserStorageFeatureAndKey = {\n feature: UserStorageFeatures;\n key: UserStorageFeatureKeys<UserStorageFeatures>;\n};\n\nexport type UserStoragePath = {\n [K in keyof UserStorageSchema]: `${K}.${UserStorageSchema[K][number]}`;\n}[keyof UserStorageSchema];\n\nexport const getFeatureAndKeyFromPath = (\n path: UserStoragePath,\n): UserStorageFeatureAndKey => {\n const pathRegex = /^\\w+\\.\\w+$/u;\n\n if (!pathRegex.test(path)) {\n throw new Error(\n `user-storage - path is not in the correct format. Correct format: 'feature.key'`,\n );\n }\n\n const [feature, key] = path.split('.') as [\n UserStorageFeatures,\n UserStorageFeatureKeys<UserStorageFeatures>,\n ];\n\n if (!(feature in USER_STORAGE_SCHEMA)) {\n throw new Error(`user-storage - invalid feature provided: ${feature}`);\n }\n\n const validFeature = USER_STORAGE_SCHEMA[feature] as readonly string[];\n\n if (!validFeature.includes(key)) {\n const validKeys = USER_STORAGE_SCHEMA[feature].join(', ');\n\n throw new Error(\n `user-storage - invalid key provided for this feature: ${key}. Valid keys: ${validKeys}`,\n );\n }\n\n return { feature, key };\n};\n\n/**\n * Constructs a unique entry path for a user.\n * This can be done due to the uniqueness of the storage key (no users will share the same storage key).\n * The users entry is a unique hash that cannot be reversed.\n *\n * @param path - string in the form of `${feature}.${key}` that matches schema\n * @param storageKey - users storage key\n * @returns path to store entry\n */\nexport function createEntryPath(\n path: UserStoragePath,\n storageKey: string,\n): string {\n const { feature, key } = getFeatureAndKeyFromPath(path);\n const hashedKey = createSHA256Hash(key + storageKey);\n\n return `/${feature}/${hashedKey}`;\n}\n"]}
@@ -8,6 +8,12 @@ import {
8
8
  getNonce,
9
9
  pairIdentifiers
10
10
  } from "./chunk-WB6MUIML.mjs";
11
+ import {
12
+ getMetaMaskProviderEIP6963
13
+ } from "./chunk-5XSXZTED.mjs";
14
+ import {
15
+ connectSnap
16
+ } from "./chunk-5EBUFNAN.mjs";
11
17
  import {
12
18
  PairError,
13
19
  UnsupportedAuthTypeError
@@ -42,6 +48,14 @@ var JwtBearerAuth = class {
42
48
  async getAccessToken() {
43
49
  return await __privateGet(this, _sdk).getAccessToken();
44
50
  }
51
+ async connectSnap() {
52
+ const provider = await getMetaMaskProviderEIP6963();
53
+ if (!provider) {
54
+ throw new Error("failed to get MetaMaskProviderEIP6963 provider");
55
+ }
56
+ const res = await connectSnap(provider);
57
+ return res;
58
+ }
45
59
  async getUserProfile() {
46
60
  return await __privateGet(this, _sdk).getUserProfile();
47
61
  }
@@ -103,4 +117,4 @@ assertSIWE_fn = function(type, sdk) {
103
117
  export {
104
118
  JwtBearerAuth
105
119
  };
106
- //# sourceMappingURL=chunk-JFVONPMM.mjs.map
120
+ //# sourceMappingURL=chunk-VYZPOR47.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/sdk/authentication.ts"],"sourcesContent":["import { SIWEJwtBearerAuth } from './authentication-jwt-bearer/flow-siwe';\nimport { SRPJwtBearerAuth } from './authentication-jwt-bearer/flow-srp';\nimport {\n getNonce,\n pairIdentifiers,\n} from './authentication-jwt-bearer/services';\nimport type { UserProfile, Pair } from './authentication-jwt-bearer/types';\nimport { AuthType } from './authentication-jwt-bearer/types';\nimport type { Env } from './env';\nimport { PairError, UnsupportedAuthTypeError } from './errors';\nimport { getMetaMaskProviderEIP6963 } from './utils/eip-6963-metamask-provider';\nimport { connectSnap } from './utils/messaging-signing-snap-requests';\n\n// Computing the Classes, so we only get back the public methods for the interface.\n// TODO: Either fix this lint violation or explain why it's necessary to ignore.\n// eslint-disable-next-line @typescript-eslint/naming-convention\ntype Compute<T> = T extends infer U ? { [K in keyof U]: U[K] } : never;\ntype SIWEInterface = Compute<SIWEJwtBearerAuth>;\ntype SRPInterface = Compute<SRPJwtBearerAuth>;\n\ntype SiweParams = ConstructorParameters<typeof SIWEJwtBearerAuth>;\ntype SRPParams = ConstructorParameters<typeof SRPJwtBearerAuth>;\ntype JwtBearerAuthParams = SiweParams | SRPParams;\n\nexport class JwtBearerAuth implements SIWEInterface, SRPInterface {\n #type: AuthType;\n\n #env: Env;\n\n #sdk: SIWEJwtBearerAuth | SRPJwtBearerAuth;\n\n constructor(...args: JwtBearerAuthParams) {\n this.#type = args[0].type;\n this.#env = args[0].env;\n\n if (args[0].type === AuthType.SRP) {\n this.#sdk = new SRPJwtBearerAuth(args[0], args[1]);\n return;\n }\n\n if (args[0].type === AuthType.SiWE) {\n this.#sdk = new SIWEJwtBearerAuth(args[0], args[1]);\n return;\n }\n\n throw new UnsupportedAuthTypeError('unsupported auth type');\n }\n\n async getAccessToken(): Promise<string> {\n return await this.#sdk.getAccessToken();\n }\n\n async connectSnap(): Promise<string> {\n const provider = await getMetaMaskProviderEIP6963();\n if (!provider) {\n throw new Error('failed to get MetaMaskProviderEIP6963 provider');\n }\n const res = await connectSnap(provider);\n return res;\n }\n\n async getUserProfile(): Promise<UserProfile> {\n return await this.#sdk.getUserProfile();\n }\n\n async getIdentifier(): Promise<string> {\n return await this.#sdk.getIdentifier();\n }\n\n async signMessage(message: string): Promise<string> {\n return await this.#sdk.signMessage(message);\n }\n\n async pairIdentifiers(pairing: Pair[]): Promise<void> {\n const profile = await this.getUserProfile();\n const n = await getNonce(profile.profileId, this.#env);\n\n const logins = await Promise.all(\n pairing.map(async (p) => {\n try {\n const raw = `metamask:${n.nonce}:${p.identifier}`;\n const sig = await p.signMessage(raw);\n return {\n signature: sig,\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n raw_message: raw,\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n encrypted_storage_key: p.encryptedStorageKey,\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n identifier_type: p.identifierType,\n };\n } catch (e) {\n /* istanbul ignore next */\n const errorMessage =\n e instanceof Error ? e.message : JSON.stringify(e ?? '');\n throw new PairError(\n `failed to sign pairing message: ${errorMessage}`,\n );\n }\n }),\n );\n\n const accessToken = await this.getAccessToken();\n await pairIdentifiers(n.nonce, logins, accessToken, this.#env);\n }\n\n prepare(signer: {\n address: string;\n chainId: number;\n signMessage: (message: string) => Promise<string>;\n domain: string;\n }): void {\n this.#assertSIWE(this.#type, this.#sdk);\n this.#sdk.prepare(signer);\n }\n\n #assertSIWE(\n type: AuthType,\n sdk: SIWEJwtBearerAuth | SRPJwtBearerAuth,\n ): asserts sdk is SIWEJwtBearerAuth {\n if (type === AuthType.SiWE) {\n return;\n }\n\n throw new UnsupportedAuthTypeError(\n 'This method is only available via SIWE auth type',\n );\n }\n}\n\nexport { SIWEJwtBearerAuth } from './authentication-jwt-bearer/flow-siwe';\nexport { SRPJwtBearerAuth } from './authentication-jwt-bearer/flow-srp';\nexport * from './authentication-jwt-bearer/types';\n"],"mappings":";;;;;;;;;;;;;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,EAAE,UAAU;AAC/C,gBAAM,MAAM,MAAM,EAAE,YAAY,GAAG;AACnC,iBAAO;AAAA,YACL,WAAW;AAAA;AAAA;AAAA,YAGX,aAAa;AAAA;AAAA;AAAA,YAGb,uBAAuB,EAAE;AAAA;AAAA;AAAA,YAGzB,iBAAiB,EAAE;AAAA,UACrB;AAAA,QACF,SAAS,GAAG;AAEV,gBAAM,eACJ,aAAa,QAAQ,EAAE,UAAU,KAAK,UAAU,KAAK,EAAE;AACzD,gBAAM,IAAI;AAAA,YACR,mCAAmC,YAAY;AAAA,UACjD;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAEA,UAAM,cAAc,MAAM,KAAK,eAAe;AAC9C,UAAM,gBAAgB,EAAE,OAAO,QAAQ,aAAa,mBAAK,KAAI;AAAA,EAC/D;AAAA,EAEA,QAAQ,QAKC;AACP,0BAAK,4BAAL,WAAiB,mBAAK,QAAO,mBAAK;AAClC,uBAAK,MAAK,QAAQ,MAAM;AAAA,EAC1B;AAcF;AA1GE;AAEA;AAEA;AA0FA;AAAA,gBAAW,SACT,MACA,KACkC;AAClC,MAAI,4BAAwB;AAC1B;AAAA,EACF;AAEA,QAAM,IAAI;AAAA,IACR;AAAA,EACF;AACF;","names":[]}
@@ -10,6 +10,12 @@ var _chunkVD2IGTS3js = require('./chunk-VD2IGTS3.js');
10
10
  var _chunkBOET676Pjs = require('./chunk-BOET676P.js');
11
11
 
12
12
 
13
+ var _chunkRG4II6WHjs = require('./chunk-RG4II6WH.js');
14
+
15
+
16
+ var _chunkPQ5T4GHYjs = require('./chunk-PQ5T4GHY.js');
17
+
18
+
13
19
 
14
20
  var _chunkMBTBE4P5js = require('./chunk-MBTBE4P5.js');
15
21
 
@@ -42,6 +48,14 @@ var JwtBearerAuth = class {
42
48
  async getAccessToken() {
43
49
  return await _chunkIGY2S5BCjs.__privateGet.call(void 0, this, _sdk).getAccessToken();
44
50
  }
51
+ async connectSnap() {
52
+ const provider = await _chunkRG4II6WHjs.getMetaMaskProviderEIP6963.call(void 0, );
53
+ if (!provider) {
54
+ throw new Error("failed to get MetaMaskProviderEIP6963 provider");
55
+ }
56
+ const res = await _chunkPQ5T4GHYjs.connectSnap.call(void 0, provider);
57
+ return res;
58
+ }
45
59
  async getUserProfile() {
46
60
  return await _chunkIGY2S5BCjs.__privateGet.call(void 0, this, _sdk).getUserProfile();
47
61
  }
@@ -103,4 +117,4 @@ assertSIWE_fn = function(type, sdk) {
103
117
 
104
118
 
105
119
  exports.JwtBearerAuth = JwtBearerAuth;
106
- //# sourceMappingURL=chunk-KUTU3NNS.js.map
120
+ //# sourceMappingURL=chunk-XSSIP3PJ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/sdk/authentication.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAwBO,IAAM,gBAAN,MAA2D;AAAA,EAOhE,eAAe,MAA2B;AAwF1C;AA9FA;AAEA;AAEA;AAGE,uBAAK,OAAQ,KAAK,CAAC,EAAE;AACrB,uBAAK,MAAO,KAAK,CAAC,EAAE;AAEpB,QAAI,KAAK,CAAC,EAAE,0BAAuB;AACjC,yBAAK,MAAO,IAAI,iBAAiB,KAAK,CAAC,GAAG,KAAK,CAAC,CAAC;AACjD;AAAA,IACF;AAEA,QAAI,KAAK,CAAC,EAAE,4BAAwB;AAClC,yBAAK,MAAO,IAAI,kBAAkB,KAAK,CAAC,GAAG,KAAK,CAAC,CAAC;AAClD;AAAA,IACF;AAEA,UAAM,IAAI,yBAAyB,uBAAuB;AAAA,EAC5D;AAAA,EAEA,MAAM,iBAAkC;AACtC,WAAO,MAAM,mBAAK,MAAK,eAAe;AAAA,EACxC;AAAA,EAEA,MAAM,cAA+B;AACnC,UAAM,WAAW,MAAM,2BAA2B;AAClD,QAAI,CAAC,UAAU;AACb,YAAM,IAAI,MAAM,gDAAgD;AAAA,IAClE;AACA,UAAM,MAAM,MAAM,YAAY,QAAQ;AACtC,WAAO;AAAA,EACT;A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AA,IACR;AAAA,EACF;AACF","sourcesContent":["import { SIWEJwtBearerAuth } from './authentication-jwt-bearer/flow-siwe';\nimport { SRPJwtBearerAuth } from './authentication-jwt-bearer/flow-srp';\nimport {\n getNonce,\n pairIdentifiers,\n} from './authentication-jwt-bearer/services';\nimport type { UserProfile, Pair } from './authentication-jwt-bearer/types';\nimport { AuthType } from './authentication-jwt-bearer/types';\nimport type { Env } from './env';\nimport { PairError, UnsupportedAuthTypeError } from './errors';\nimport { getMetaMaskProviderEIP6963 } from './utils/eip-6963-metamask-provider';\nimport { connectSnap } from './utils/messaging-signing-snap-requests';\n\n// Computing the Classes, so we only get back the public methods for the interface.\n// TODO: Either fix this lint violation or explain why it's necessary to ignore.\n// eslint-disable-next-line @typescript-eslint/naming-convention\ntype Compute<T> = T extends infer U ? { [K in keyof U]: U[K] } : never;\ntype SIWEInterface = Compute<SIWEJwtBearerAuth>;\ntype SRPInterface = Compute<SRPJwtBearerAuth>;\n\ntype SiweParams = ConstructorParameters<typeof SIWEJwtBearerAuth>;\ntype SRPParams = ConstructorParameters<typeof SRPJwtBearerAuth>;\ntype JwtBearerAuthParams = SiweParams | SRPParams;\n\nexport class JwtBearerAuth implements SIWEInterface, SRPInterface {\n #type: AuthType;\n\n #env: Env;\n\n #sdk: SIWEJwtBearerAuth | SRPJwtBearerAuth;\n\n constructor(...args: JwtBearerAuthParams) {\n this.#type = args[0].type;\n this.#env = args[0].env;\n\n if (args[0].type === AuthType.SRP) {\n this.#sdk = new SRPJwtBearerAuth(args[0], args[1]);\n return;\n }\n\n if (args[0].type === AuthType.SiWE) {\n this.#sdk = new SIWEJwtBearerAuth(args[0], args[1]);\n return;\n }\n\n throw new UnsupportedAuthTypeError('unsupported auth type');\n }\n\n async getAccessToken(): Promise<string> {\n return await this.#sdk.getAccessToken();\n }\n\n async connectSnap(): Promise<string> {\n const provider = await getMetaMaskProviderEIP6963();\n if (!provider) {\n throw new Error('failed to get MetaMaskProviderEIP6963 provider');\n }\n const res = await connectSnap(provider);\n return res;\n }\n\n async getUserProfile(): Promise<UserProfile> {\n return await this.#sdk.getUserProfile();\n }\n\n async getIdentifier(): Promise<string> {\n return await this.#sdk.getIdentifier();\n }\n\n async signMessage(message: string): Promise<string> {\n return await this.#sdk.signMessage(message);\n }\n\n async pairIdentifiers(pairing: Pair[]): Promise<void> {\n const profile = await this.getUserProfile();\n const n = await getNonce(profile.profileId, this.#env);\n\n const logins = await Promise.all(\n pairing.map(async (p) => {\n try {\n const raw = `metamask:${n.nonce}:${p.identifier}`;\n const sig = await p.signMessage(raw);\n return {\n signature: sig,\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n raw_message: raw,\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n encrypted_storage_key: p.encryptedStorageKey,\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n identifier_type: p.identifierType,\n };\n } catch (e) {\n /* istanbul ignore next */\n const errorMessage =\n e instanceof Error ? e.message : JSON.stringify(e ?? '');\n throw new PairError(\n `failed to sign pairing message: ${errorMessage}`,\n );\n }\n }),\n );\n\n const accessToken = await this.getAccessToken();\n await pairIdentifiers(n.nonce, logins, accessToken, this.#env);\n }\n\n prepare(signer: {\n address: string;\n chainId: number;\n signMessage: (message: string) => Promise<string>;\n domain: string;\n }): void {\n this.#assertSIWE(this.#type, this.#sdk);\n this.#sdk.prepare(signer);\n }\n\n #assertSIWE(\n type: AuthType,\n sdk: SIWEJwtBearerAuth | SRPJwtBearerAuth,\n ): asserts sdk is SIWEJwtBearerAuth {\n if (type === AuthType.SiWE) {\n return;\n }\n\n throw new UnsupportedAuthTypeError(\n 'This method is only available via SIWE auth type',\n );\n }\n}\n\nexport { SIWEJwtBearerAuth } from './authentication-jwt-bearer/flow-siwe';\nexport { SRPJwtBearerAuth } from './authentication-jwt-bearer/flow-srp';\nexport * from './authentication-jwt-bearer/types';\n"]}
@@ -4,8 +4,8 @@
4
4
  var _chunkDHKZ2NEFjs = require('../../chunk-DHKZ2NEF.js');
5
5
  require('../../chunk-5C53GKTU.js');
6
6
  require('../../chunk-YHGWG3EQ.js');
7
- require('../../chunk-3DMUUTKC.js');
8
- require('../../chunk-KUTU3NNS.js');
7
+ require('../../chunk-PSR2V3R4.js');
8
+ require('../../chunk-XSSIP3PJ.js');
9
9
  require('../../chunk-G4NU4KP7.js');
10
10
  require('../../chunk-VD2IGTS3.js');
11
11
  require('../../chunk-BOET676P.js');
@@ -13,7 +13,12 @@ require('../../chunk-PBRUOBEQ.js');
13
13
  require('../../chunk-RG4II6WH.js');
14
14
  require('../../chunk-PQ5T4GHY.js');
15
15
  require('../../chunk-DRB2MN4T.js');
16
- require('../../chunk-P52TG263.js');
16
+ require('../../chunk-FUPEFLXB.js');
17
+ require('../../chunk-SLHAVOTE.js');
18
+ require('../../chunk-AK7OTIWA.js');
19
+ require('../../chunk-T3FNDVE3.js');
20
+ require('../../chunk-UAXWZN5J.js');
21
+ require('../../chunk-PCOIRDTO.js');
17
22
  require('../../chunk-P4DUDLMY.js');
18
23
  require('../../chunk-SMKTWM6I.js');
19
24
  require('../../chunk-MBTBE4P5.js');
@@ -4,8 +4,8 @@ import {
4
4
  } from "../../chunk-Y7P3UH26.mjs";
5
5
  import "../../chunk-7SW3CC66.mjs";
6
6
  import "../../chunk-NMIF3LSX.mjs";
7
- import "../../chunk-RT2GRG4S.mjs";
8
- import "../../chunk-JFVONPMM.mjs";
7
+ import "../../chunk-7KMONAQI.mjs";
8
+ import "../../chunk-VYZPOR47.mjs";
9
9
  import "../../chunk-BDO3VJEU.mjs";
10
10
  import "../../chunk-DRD22DR5.mjs";
11
11
  import "../../chunk-WB6MUIML.mjs";
@@ -13,7 +13,12 @@ import "../../chunk-CAIIVJAO.mjs";
13
13
  import "../../chunk-5XSXZTED.mjs";
14
14
  import "../../chunk-5EBUFNAN.mjs";
15
15
  import "../../chunk-QDGLIUUS.mjs";
16
- import "../../chunk-AXWK4Y23.mjs";
16
+ import "../../chunk-NPH5AHLH.mjs";
17
+ import "../../chunk-ILIZJQ6X.mjs";
18
+ import "../../chunk-5TOWF6UW.mjs";
19
+ import "../../chunk-K5UKU454.mjs";
20
+ import "../../chunk-H25EBXG5.mjs";
21
+ import "../../chunk-76VRE4BI.mjs";
17
22
  import "../../chunk-B5DBQDB3.mjs";
18
23
  import "../../chunk-FQ5SDMRE.mjs";
19
24
  import "../../chunk-TFFQFIJV.mjs";
@@ -7,8 +7,8 @@ var _chunkBXPL7ZFXjs = require('../../chunk-BXPL7ZFX.js');
7
7
  var _chunkDHKZ2NEFjs = require('../../chunk-DHKZ2NEF.js');
8
8
  require('../../chunk-5C53GKTU.js');
9
9
  require('../../chunk-YHGWG3EQ.js');
10
- require('../../chunk-3DMUUTKC.js');
11
- require('../../chunk-KUTU3NNS.js');
10
+ require('../../chunk-PSR2V3R4.js');
11
+ require('../../chunk-XSSIP3PJ.js');
12
12
  require('../../chunk-G4NU4KP7.js');
13
13
  require('../../chunk-VD2IGTS3.js');
14
14
  require('../../chunk-BOET676P.js');
@@ -16,7 +16,12 @@ require('../../chunk-PBRUOBEQ.js');
16
16
  require('../../chunk-RG4II6WH.js');
17
17
  require('../../chunk-PQ5T4GHY.js');
18
18
  require('../../chunk-DRB2MN4T.js');
19
- require('../../chunk-P52TG263.js');
19
+ require('../../chunk-FUPEFLXB.js');
20
+ require('../../chunk-SLHAVOTE.js');
21
+ require('../../chunk-AK7OTIWA.js');
22
+ require('../../chunk-T3FNDVE3.js');
23
+ require('../../chunk-UAXWZN5J.js');
24
+ require('../../chunk-PCOIRDTO.js');
20
25
  require('../../chunk-P4DUDLMY.js');
21
26
  require('../../chunk-SMKTWM6I.js');
22
27
  require('../../chunk-MBTBE4P5.js');
@@ -7,8 +7,8 @@ import {
7
7
  } from "../../chunk-Y7P3UH26.mjs";
8
8
  import "../../chunk-7SW3CC66.mjs";
9
9
  import "../../chunk-NMIF3LSX.mjs";
10
- import "../../chunk-RT2GRG4S.mjs";
11
- import "../../chunk-JFVONPMM.mjs";
10
+ import "../../chunk-7KMONAQI.mjs";
11
+ import "../../chunk-VYZPOR47.mjs";
12
12
  import "../../chunk-BDO3VJEU.mjs";
13
13
  import "../../chunk-DRD22DR5.mjs";
14
14
  import "../../chunk-WB6MUIML.mjs";
@@ -16,7 +16,12 @@ import "../../chunk-CAIIVJAO.mjs";
16
16
  import "../../chunk-5XSXZTED.mjs";
17
17
  import "../../chunk-5EBUFNAN.mjs";
18
18
  import "../../chunk-QDGLIUUS.mjs";
19
- import "../../chunk-AXWK4Y23.mjs";
19
+ import "../../chunk-NPH5AHLH.mjs";
20
+ import "../../chunk-ILIZJQ6X.mjs";
21
+ import "../../chunk-5TOWF6UW.mjs";
22
+ import "../../chunk-K5UKU454.mjs";
23
+ import "../../chunk-H25EBXG5.mjs";
24
+ import "../../chunk-76VRE4BI.mjs";
20
25
  import "../../chunk-B5DBQDB3.mjs";
21
26
  import "../../chunk-FQ5SDMRE.mjs";
22
27
  import "../../chunk-TFFQFIJV.mjs";
@@ -7,8 +7,8 @@
7
7
 
8
8
 
9
9
  var _chunk5C53GKTUjs = require('../../chunk-5C53GKTU.js');
10
- require('../../chunk-3DMUUTKC.js');
11
- require('../../chunk-KUTU3NNS.js');
10
+ require('../../chunk-PSR2V3R4.js');
11
+ require('../../chunk-XSSIP3PJ.js');
12
12
  require('../../chunk-G4NU4KP7.js');
13
13
  require('../../chunk-VD2IGTS3.js');
14
14
  require('../../chunk-BOET676P.js');
@@ -16,7 +16,12 @@ require('../../chunk-PBRUOBEQ.js');
16
16
  require('../../chunk-RG4II6WH.js');
17
17
  require('../../chunk-PQ5T4GHY.js');
18
18
  require('../../chunk-DRB2MN4T.js');
19
- require('../../chunk-P52TG263.js');
19
+ require('../../chunk-FUPEFLXB.js');
20
+ require('../../chunk-SLHAVOTE.js');
21
+ require('../../chunk-AK7OTIWA.js');
22
+ require('../../chunk-T3FNDVE3.js');
23
+ require('../../chunk-UAXWZN5J.js');
24
+ require('../../chunk-PCOIRDTO.js');
20
25
  require('../../chunk-P4DUDLMY.js');
21
26
  require('../../chunk-SMKTWM6I.js');
22
27
  require('../../chunk-MBTBE4P5.js');
@@ -7,8 +7,8 @@ import {
7
7
  getNonce,
8
8
  login
9
9
  } from "../../chunk-7SW3CC66.mjs";
10
- import "../../chunk-RT2GRG4S.mjs";
11
- import "../../chunk-JFVONPMM.mjs";
10
+ import "../../chunk-7KMONAQI.mjs";
11
+ import "../../chunk-VYZPOR47.mjs";
12
12
  import "../../chunk-BDO3VJEU.mjs";
13
13
  import "../../chunk-DRD22DR5.mjs";
14
14
  import "../../chunk-WB6MUIML.mjs";
@@ -16,7 +16,12 @@ import "../../chunk-CAIIVJAO.mjs";
16
16
  import "../../chunk-5XSXZTED.mjs";
17
17
  import "../../chunk-5EBUFNAN.mjs";
18
18
  import "../../chunk-QDGLIUUS.mjs";
19
- import "../../chunk-AXWK4Y23.mjs";
19
+ import "../../chunk-NPH5AHLH.mjs";
20
+ import "../../chunk-ILIZJQ6X.mjs";
21
+ import "../../chunk-5TOWF6UW.mjs";
22
+ import "../../chunk-K5UKU454.mjs";
23
+ import "../../chunk-H25EBXG5.mjs";
24
+ import "../../chunk-76VRE4BI.mjs";
20
25
  import "../../chunk-B5DBQDB3.mjs";
21
26
  import "../../chunk-FQ5SDMRE.mjs";
22
27
  import "../../chunk-TFFQFIJV.mjs";
@@ -5,17 +5,12 @@ require('../chunk-DHKZ2NEF.js');
5
5
  require('../chunk-5C53GKTU.js');
6
6
 
7
7
 
8
- var _chunkCSFHMILKjs = require('../chunk-CSFHMILK.js');
9
- require('../chunk-DDOYG42A.js');
8
+ var _chunk77LSWSGBjs = require('../chunk-77LSWSGB.js');
9
+ require('../chunk-R2S3HIDN.js');
10
10
  require('../chunk-YHGWG3EQ.js');
11
- require('../chunk-5SXXO4MV.js');
12
- require('../chunk-B6CSNLGE.js');
13
- require('../chunk-AK7OTIWA.js');
14
- require('../chunk-T3FNDVE3.js');
15
- require('../chunk-UAXWZN5J.js');
16
- require('../chunk-PCOIRDTO.js');
17
- require('../chunk-3DMUUTKC.js');
18
- require('../chunk-KUTU3NNS.js');
11
+ require('../chunk-3TE6M5TV.js');
12
+ require('../chunk-PSR2V3R4.js');
13
+ require('../chunk-XSSIP3PJ.js');
19
14
  require('../chunk-G4NU4KP7.js');
20
15
  require('../chunk-VD2IGTS3.js');
21
16
  require('../chunk-BOET676P.js');
@@ -23,7 +18,12 @@ require('../chunk-PBRUOBEQ.js');
23
18
  require('../chunk-RG4II6WH.js');
24
19
  require('../chunk-PQ5T4GHY.js');
25
20
  require('../chunk-DRB2MN4T.js');
26
- require('../chunk-P52TG263.js');
21
+ require('../chunk-FUPEFLXB.js');
22
+ require('../chunk-SLHAVOTE.js');
23
+ require('../chunk-AK7OTIWA.js');
24
+ require('../chunk-T3FNDVE3.js');
25
+ require('../chunk-UAXWZN5J.js');
26
+ require('../chunk-PCOIRDTO.js');
27
27
  require('../chunk-P4DUDLMY.js');
28
28
  require('../chunk-SMKTWM6I.js');
29
29
  require('../chunk-MBTBE4P5.js');
@@ -31,5 +31,5 @@ require('../chunk-IGY2S5BC.js');
31
31
 
32
32
 
33
33
 
34
- exports.Authentication = _chunkBXPL7ZFXjs.authentication_exports; exports.UserStorage = _chunkCSFHMILKjs.user_storage_exports;
34
+ exports.Authentication = _chunkBXPL7ZFXjs.authentication_exports; exports.UserStorage = _chunk77LSWSGBjs.user_storage_exports;
35
35
  //# sourceMappingURL=index.js.map