@metamask/profile-sync-controller 0.1.3 → 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.
- package/CHANGELOG.md +47 -1
- package/dist/{chunk-5SXXO4MV.js → chunk-3TE6M5TV.js} +10 -8
- package/dist/chunk-3TE6M5TV.js.map +1 -0
- package/dist/{chunk-H4TDS65R.js → chunk-77LSWSGB.js} +8 -8
- package/dist/{chunk-H4TDS65R.js.map → chunk-77LSWSGB.js.map} +1 -1
- package/dist/{chunk-WJCKQLKK.mjs → chunk-7KMONAQI.mjs} +5 -5
- package/dist/{chunk-JLDFMYAH.mjs → chunk-BDO3VJEU.mjs} +5 -2
- package/dist/chunk-BDO3VJEU.mjs.map +1 -0
- package/dist/{chunk-FRVMGTOY.js → chunk-BXPL7ZFX.js} +4 -4
- package/dist/{chunk-GWBBZZVV.js → chunk-DHKZ2NEF.js} +23 -12
- package/dist/chunk-DHKZ2NEF.js.map +1 -0
- package/dist/chunk-DRB2MN4T.js +16 -0
- package/dist/chunk-DRB2MN4T.js.map +1 -0
- package/dist/{chunk-Y46NMA3V.mjs → chunk-DRD22DR5.mjs} +5 -2
- package/dist/chunk-DRD22DR5.mjs.map +1 -0
- package/dist/{chunk-2XGRQBXI.mjs → chunk-FU7PSGFP.mjs} +10 -8
- package/dist/chunk-FU7PSGFP.mjs.map +1 -0
- package/dist/{chunk-P52TG263.js → chunk-FUPEFLXB.js} +18 -24
- package/dist/chunk-FUPEFLXB.js.map +1 -0
- package/dist/{chunk-Q5WIUNX5.js → chunk-G4NU4KP7.js} +5 -2
- package/dist/chunk-G4NU4KP7.js.map +1 -0
- package/dist/chunk-ILIZJQ6X.mjs +40 -0
- package/dist/chunk-ILIZJQ6X.mjs.map +1 -0
- package/dist/{chunk-LSVRA3X2.mjs → chunk-IQECLCH4.mjs} +5 -5
- package/dist/{chunk-LSVRA3X2.mjs.map → chunk-IQECLCH4.mjs.map} +1 -1
- package/dist/{chunk-KKB3U6KO.mjs → chunk-LDEIUP6J.mjs} +2 -2
- package/dist/{chunk-TGFMKARH.mjs → chunk-LNSB4L7K.mjs} +19 -12
- package/dist/chunk-LNSB4L7K.mjs.map +1 -0
- package/dist/{chunk-6P6CUKKI.mjs → chunk-NMIF3LSX.mjs} +3 -4
- package/dist/chunk-NMIF3LSX.mjs.map +1 -0
- package/dist/{chunk-AXWK4Y23.mjs → chunk-NPH5AHLH.mjs} +19 -25
- package/dist/chunk-NPH5AHLH.mjs.map +1 -0
- package/dist/{chunk-PTR4DAX6.js → chunk-PSR2V3R4.js} +10 -10
- package/dist/chunk-QDGLIUUS.mjs +16 -0
- package/dist/chunk-QDGLIUUS.mjs.map +1 -0
- package/dist/{chunk-YASNOFBV.js → chunk-R2S3HIDN.js} +22 -15
- package/dist/chunk-R2S3HIDN.js.map +1 -0
- package/dist/chunk-SLHAVOTE.js +40 -0
- package/dist/chunk-SLHAVOTE.js.map +1 -0
- package/dist/{chunk-AVOOINGJ.js → chunk-VD2IGTS3.js} +5 -2
- package/dist/chunk-VD2IGTS3.js.map +1 -0
- package/dist/{chunk-FCT2LIGH.mjs → chunk-VYZPOR47.mjs} +17 -3
- package/dist/chunk-VYZPOR47.mjs.map +1 -0
- package/dist/{chunk-NLHLVVOO.js → chunk-XSSIP3PJ.js} +19 -5
- package/dist/chunk-XSSIP3PJ.js.map +1 -0
- package/dist/{chunk-QU3RCIV3.mjs → chunk-Y7P3UH26.mjs} +21 -10
- package/dist/chunk-Y7P3UH26.mjs.map +1 -0
- package/dist/{chunk-IPSBQ3MS.js → chunk-YHGWG3EQ.js} +3 -4
- package/dist/chunk-YHGWG3EQ.js.map +1 -0
- package/dist/controllers/authentication/AuthenticationController.js +14 -8
- package/dist/controllers/authentication/AuthenticationController.mjs +13 -7
- package/dist/controllers/authentication/auth-snap-requests.js +2 -2
- package/dist/controllers/authentication/auth-snap-requests.mjs +1 -1
- package/dist/controllers/authentication/index.js +15 -9
- package/dist/controllers/authentication/index.mjs +14 -8
- package/dist/controllers/authentication/services.js +11 -5
- package/dist/controllers/authentication/services.mjs +11 -5
- package/dist/controllers/index.js +18 -17
- package/dist/controllers/index.mjs +17 -16
- package/dist/controllers/user-storage/UserStorageController.js +15 -14
- package/dist/controllers/user-storage/UserStorageController.mjs +14 -13
- package/dist/controllers/user-storage/index.js +16 -15
- package/dist/controllers/user-storage/index.mjs +15 -14
- package/dist/controllers/user-storage/schema.js +4 -2
- package/dist/controllers/user-storage/schema.mjs +7 -5
- package/dist/controllers/user-storage/services.js +13 -12
- package/dist/controllers/user-storage/services.mjs +12 -11
- package/dist/index.js +18 -17
- package/dist/index.mjs +17 -16
- package/dist/sdk/authentication-jwt-bearer/flow-siwe.js +3 -2
- package/dist/sdk/authentication-jwt-bearer/flow-siwe.mjs +2 -1
- package/dist/sdk/authentication-jwt-bearer/flow-srp.js +3 -2
- package/dist/sdk/authentication-jwt-bearer/flow-srp.mjs +2 -1
- package/dist/sdk/authentication.js +5 -4
- package/dist/sdk/authentication.mjs +4 -3
- package/dist/sdk/index.js +12 -6
- package/dist/sdk/index.mjs +11 -5
- package/dist/sdk/user-storage.js +7 -2
- package/dist/sdk/user-storage.mjs +6 -1
- package/dist/sdk/utils/validate-login-response.js +8 -0
- package/dist/sdk/utils/validate-login-response.js.map +1 -0
- package/dist/sdk/utils/validate-login-response.mjs +8 -0
- package/dist/sdk/utils/validate-login-response.mjs.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/controllers/authentication/AuthenticationController.d.ts +1 -2
- package/dist/types/controllers/authentication/AuthenticationController.d.ts.map +1 -1
- package/dist/types/controllers/authentication/auth-snap-requests.d.ts.map +1 -1
- package/dist/types/controllers/user-storage/UserStorageController.d.ts +6 -6
- package/dist/types/controllers/user-storage/UserStorageController.d.ts.map +1 -1
- package/dist/types/controllers/user-storage/schema.d.ts +18 -10
- package/dist/types/controllers/user-storage/schema.d.ts.map +1 -1
- package/dist/types/controllers/user-storage/services.d.ts +2 -2
- package/dist/types/controllers/user-storage/services.d.ts.map +1 -1
- package/dist/types/sdk/__fixtures__/mock-userstorage.d.ts.map +1 -1
- package/dist/types/sdk/authentication-jwt-bearer/flow-siwe.d.ts.map +1 -1
- package/dist/types/sdk/authentication-jwt-bearer/flow-srp.d.ts.map +1 -1
- package/dist/types/sdk/authentication.d.ts +1 -0
- package/dist/types/sdk/authentication.d.ts.map +1 -1
- package/dist/types/sdk/user-storage.d.ts +4 -3
- package/dist/types/sdk/user-storage.d.ts.map +1 -1
- package/dist/types/sdk/utils/validate-login-response.d.ts +10 -0
- package/dist/types/sdk/utils/validate-login-response.d.ts.map +1 -0
- package/package.json +11 -11
- package/dist/chunk-2XGRQBXI.mjs.map +0 -1
- package/dist/chunk-5SXXO4MV.js.map +0 -1
- package/dist/chunk-6P6CUKKI.mjs.map +0 -1
- package/dist/chunk-AUFUOKJW.mjs +0 -25
- package/dist/chunk-AUFUOKJW.mjs.map +0 -1
- package/dist/chunk-AVOOINGJ.js.map +0 -1
- package/dist/chunk-AXWK4Y23.mjs.map +0 -1
- package/dist/chunk-B6CSNLGE.js +0 -25
- package/dist/chunk-B6CSNLGE.js.map +0 -1
- package/dist/chunk-FCT2LIGH.mjs.map +0 -1
- package/dist/chunk-GWBBZZVV.js.map +0 -1
- package/dist/chunk-IPSBQ3MS.js.map +0 -1
- package/dist/chunk-JLDFMYAH.mjs.map +0 -1
- package/dist/chunk-NLHLVVOO.js.map +0 -1
- package/dist/chunk-P52TG263.js.map +0 -1
- package/dist/chunk-Q5WIUNX5.js.map +0 -1
- package/dist/chunk-QU3RCIV3.mjs.map +0 -1
- package/dist/chunk-TGFMKARH.mjs.map +0 -1
- package/dist/chunk-Y46NMA3V.mjs.map +0 -1
- package/dist/chunk-YASNOFBV.js.map +0 -1
- /package/dist/{chunk-WJCKQLKK.mjs.map → chunk-7KMONAQI.mjs.map} +0 -0
- /package/dist/{chunk-FRVMGTOY.js.map → chunk-BXPL7ZFX.js.map} +0 -0
- /package/dist/{chunk-KKB3U6KO.mjs.map → chunk-LDEIUP6J.mjs.map} +0 -0
- /package/dist/{chunk-PTR4DAX6.js.map → chunk-PSR2V3R4.js.map} +0 -0
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
+
var _chunkSLHAVOTEjs = require('./chunk-SLHAVOTE.js');
|
|
4
|
+
|
|
5
|
+
|
|
3
6
|
|
|
4
7
|
var _chunkP4DUDLMYjs = require('./chunk-P4DUDLMY.js');
|
|
5
8
|
|
|
@@ -8,7 +11,6 @@ var _chunkSMKTWM6Ijs = require('./chunk-SMKTWM6I.js');
|
|
|
8
11
|
|
|
9
12
|
|
|
10
13
|
|
|
11
|
-
|
|
12
14
|
var _chunkMBTBE4P5js = require('./chunk-MBTBE4P5.js');
|
|
13
15
|
|
|
14
16
|
|
|
@@ -16,7 +18,7 @@ var _chunkMBTBE4P5js = require('./chunk-MBTBE4P5.js');
|
|
|
16
18
|
var _chunkIGY2S5BCjs = require('./chunk-IGY2S5BC.js');
|
|
17
19
|
|
|
18
20
|
// src/sdk/user-storage.ts
|
|
19
|
-
var STORAGE_URL = (env,
|
|
21
|
+
var STORAGE_URL = (env, encryptedPath) => `${_chunkSMKTWM6Ijs.getEnvUrls.call(void 0, 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(
|
|
34
|
-
|
|
35
|
-
throw new (0, _chunkMBTBE4P5js.ValidationError)("feature or key cannot be empty strings");
|
|
36
|
-
}
|
|
37
|
-
await _chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _upsertUserStorage, upsertUserStorage_fn).call(this, feature, key, value);
|
|
35
|
+
async setItem(path, value) {
|
|
36
|
+
await _chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _upsertUserStorage, upsertUserStorage_fn).call(this, path, value);
|
|
38
37
|
}
|
|
39
|
-
async getItem(
|
|
40
|
-
|
|
41
|
-
throw new (0, _chunkMBTBE4P5js.ValidationError)("feature or key cannot be empty strings");
|
|
42
|
-
}
|
|
43
|
-
return _chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _getUserStorage, getUserStorage_fn).call(this, feature, key);
|
|
38
|
+
async getItem(path) {
|
|
39
|
+
return _chunkIGY2S5BCjs.__privateMethod.call(void 0, 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(
|
|
56
|
+
upsertUserStorage_fn = async function(path, data) {
|
|
61
57
|
try {
|
|
62
58
|
const headers = await _chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _getAuthorizationHeader, getAuthorizationHeader_fn).call(this);
|
|
63
59
|
const storageKey = await this.getStorageKey();
|
|
64
60
|
const encryptedData = _chunkP4DUDLMYjs.encryption_default.encryptString(data, storageKey);
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
);
|
|
61
|
+
const encryptedPath = _chunkSLHAVOTEjs.createEntryPath.call(void 0, 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 (0, _chunkMBTBE4P5js.UserStorageError)(
|
|
88
|
-
`failed to upsert user storage for
|
|
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(
|
|
88
|
+
getUserStorage_fn = async function(path) {
|
|
94
89
|
try {
|
|
95
90
|
const headers = await _chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _getAuthorizationHeader, getAuthorizationHeader_fn).call(this);
|
|
96
91
|
const storageKey = await this.getStorageKey();
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
);
|
|
92
|
+
const encryptedPath = _chunkSLHAVOTEjs.createEntryPath.call(void 0, 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 (0, _chunkMBTBE4P5js.NotFoundError)(
|
|
108
|
-
`feature/key set not found for
|
|
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 (0, _chunkMBTBE4P5js.UserStorageError)(
|
|
125
|
-
`failed to get user storage for
|
|
119
|
+
`failed to get user storage for path '${path}'. ${errorMessage}`
|
|
126
120
|
);
|
|
127
121
|
}
|
|
128
122
|
};
|
|
@@ -141,4 +135,4 @@ getAuthorizationHeader_fn = async function() {
|
|
|
141
135
|
|
|
142
136
|
|
|
143
137
|
exports.STORAGE_URL = STORAGE_URL; exports.UserStorage = UserStorage;
|
|
144
|
-
//# sourceMappingURL=chunk-
|
|
138
|
+
//# sourceMappingURL=chunk-FUPEFLXB.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/sdk/user-storage.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAQO,IAAM,cAAc,CAAC,KAAU,kBACpC,GAAG,WAAW,GAAG,EAAE,iBAAiB,uBAAuB,aAAa;AAT1E;AA8BO,IAAM,cAAN,MAAkB;AAAA,EAOvB,YAAY,QAA2B,SAA6B;AA6BpE,uBAAM;AAqCN,uBAAM;AA6CN;AAOA;AAAA;AAAA,uBAAM;AArHJ,SAAK,MAAM,OAAO;AAClB,SAAK,SAAS;AACd,SAAK,UAAU;AAAA,EACjB;AAAA,EAEA,MAAM,QAAQ,MAAuB,OAA8B;AACjE,UAAM,sBAAK,0CAAL,WAAwB,MAAM;AAAA,EACtC;AAAA,EAEA,MAAM,QAAQ,MAAwC;AACpD,WAAO,sBAAK,oCAAL,WAAqB;AAAA,EAC9B;AAAA,EAEA,MAAM,gBAAiC;AACrC,UAAM,aAAa,MAAM,KAAK,QAAQ,SAAS,cAAc;AAC7D,QAAI,YAAY;AACd,aAAO;AAAA,IACT;AAEA,UAAM,cAAc,MAAM,KAAK,OAAO,KAAK,eAAe;AAC1D,UAAM,sBAAsB,MAAM,KAAK,OAAO,KAAK;AAAA,MACjD,YAAY,YAAY,SAAS;AAAA,IACnC;AACA,UAAM,4BAA4B,iBAAiB,mBAAmB;AACtE,UAAM,KAAK,QAAQ,SAAS,cAAc,yBAAyB;AACnE,WAAO;AAAA,EACT;AA+FF;AA7FQ;AAAA,uBAAkB,eAAC,MAAuB,MAA6B;AAC3E,MAAI;AACF,UAAM,UAAU,MAAM,sBAAK,oDAAL;AACtB,UAAM,aAAa,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QAAI,CAAC,SAAS,IAAI;AAChB,YAAM,eAAgB,MAAM,SAAS,KAAK;AAC1C,YAAM,IAAI;AAAA,QACR,uBAAuB,aAAa,OAAO,YAAY,aAAa,KAAK;AAAA,MAC3E;AAAA,IACF;AAEA,UAAM,EAAE,MAAM,cAAc,IAAI,MAAM,SAAS,KAAK;AACpD,WAAO,mBAAW,cAAc,eAAe,UAAU;AAAA,EAC3D,SAAS,GAAG;AACV,QAAI,aAAa,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","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"]}
|
|
@@ -6,6 +6,9 @@
|
|
|
6
6
|
var _chunkBOET676Pjs = require('./chunk-BOET676P.js');
|
|
7
7
|
|
|
8
8
|
|
|
9
|
+
var _chunkDRB2MN4Tjs = require('./chunk-DRB2MN4T.js');
|
|
10
|
+
|
|
11
|
+
|
|
9
12
|
var _chunkMBTBE4P5js = require('./chunk-MBTBE4P5.js');
|
|
10
13
|
|
|
11
14
|
|
|
@@ -64,7 +67,7 @@ _signer = new WeakMap();
|
|
|
64
67
|
_getAuthSession = new WeakSet();
|
|
65
68
|
getAuthSession_fn = async function() {
|
|
66
69
|
const auth = await _chunkIGY2S5BCjs.__privateGet.call(void 0, this, _options).storage.getLoginResponse();
|
|
67
|
-
if (!auth) {
|
|
70
|
+
if (!_chunkDRB2MN4Tjs.validateLoginResponse.call(void 0, auth)) {
|
|
68
71
|
return null;
|
|
69
72
|
}
|
|
70
73
|
const currentTime = Date.now();
|
|
@@ -123,4 +126,4 @@ assertSigner_fn = function(signer) {
|
|
|
123
126
|
|
|
124
127
|
|
|
125
128
|
exports.SIWEJwtBearerAuth = SIWEJwtBearerAuth;
|
|
126
|
-
//# sourceMappingURL=chunk-
|
|
129
|
+
//# sourceMappingURL=chunk-G4NU4KP7.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/sdk/authentication-jwt-bearer/flow-siwe.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,SAAS,mBAAmB;AAA5B;AAkCO,IAAM,oBAAN,MAA6C;AAAA,EAOlD,YACE,QACA,SACA;AAwCF;AAAA,uBAAM;AAgBN,uBAAM;AAmCN;AAcA;AAlHA;AAEA;AAEA;AAME,uBAAK,SAAU;AACf,uBAAK,UAAW;AAAA,EAClB;AAAA,EAEA,MAAM,iBAAkC;AACtC,UAAM,UAAU,MAAM,sBAAK,oCAAL;AACtB,QAAI,SAAS;AACX,aAAO,QAAQ,MAAM;AAAA,IACvB;AAEA,UAAM,gBAAgB,MAAM,sBAAK,kBAAL;AAC5B,WAAO,cAAc,MAAM;AAAA,EAC7B;AAAA,EAEA,MAAM,iBAAuC;AAC3C,UAAM,UAAU,MAAM,sBAAK,oCAAL;AACtB,QAAI,SAAS;AACX,aAAO,QAAQ;AAAA,IACjB;AAEA,UAAM,gBAAgB,MAAM,sBAAK,kBAAL;AAC5B,WAAO,cAAc;AAAA,EACvB;AAAA,EAEA,MAAM,gBAAiC;AACrC,0BAAK,gCAAL,WAAmB,mBAAK;AACxB,WAAO,mBAAK,SAAQ;AAAA,EACtB;AAAA,EAEA,MAAM,YAAY,SAAkC;AAClD,0BAAK,gCAAL,WAAmB,mBAAK;AACxB,WAAO,MAAM,mBAAK,SAAQ,YAAY,OAAO;AAAA,EAC/C;AAAA,EAEA,QAAQ,QAAmC;AACzC,uBAAK,SAAU;AAAA,EACjB;AA2EF;AAzHE;AAEA;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AAAA,EACnC,CAAC,EAAE,eAAe;AACpB;AAEA;AAAA,kBAAa,SACX,QAC6C;AAC7C,MAAI,CAAC,QAAQ;AACX,UAAM,IAAI,gBAAgB,6CAA6C;AAAA,EACzE;AACF","sourcesContent":["import { SiweMessage } from 'siwe';\n\nimport { ValidationError } from '../errors';\nimport { validateLoginResponse } from '../utils/validate-login-response';\nimport {\n SIWE_LOGIN_URL,\n authenticate,\n authorizeOIDC,\n getNonce,\n} from './services';\nimport type {\n AuthConfig,\n AuthStorageOptions,\n AuthType,\n IBaseAuth,\n LoginResponse,\n UserProfile,\n} from './types';\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\ntype JwtBearerAuth_SIWE_Options = {\n storage: AuthStorageOptions;\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\ntype JwtBearerAuth_SIWE_Signer = {\n address: string;\n chainId: number;\n signMessage: (message: string) => Promise<string>;\n domain: string;\n};\n\nexport class SIWEJwtBearerAuth implements IBaseAuth {\n #config: AuthConfig;\n\n #options: JwtBearerAuth_SIWE_Options;\n\n #signer: JwtBearerAuth_SIWE_Signer | undefined;\n\n constructor(\n config: AuthConfig & { type: AuthType.SiWE },\n options: JwtBearerAuth_SIWE_Options,\n ) {\n this.#config = config;\n this.#options = options;\n }\n\n async getAccessToken(): Promise<string> {\n const session = await this.#getAuthSession();\n if (session) {\n return session.token.accessToken;\n }\n\n const loginResponse = await this.#login();\n return loginResponse.token.accessToken;\n }\n\n async getUserProfile(): Promise<UserProfile> {\n const session = await this.#getAuthSession();\n if (session) {\n return session.profile;\n }\n\n const loginResponse = await this.#login();\n return loginResponse.profile;\n }\n\n async getIdentifier(): Promise<string> {\n this.#assertSigner(this.#signer);\n return this.#signer.address;\n }\n\n async signMessage(message: string): Promise<string> {\n this.#assertSigner(this.#signer);\n return await this.#signer.signMessage(message);\n }\n\n prepare(signer: JwtBearerAuth_SIWE_Signer) {\n this.#signer = signer;\n }\n\n // convert expiresIn from seconds to milliseconds and use 90% of expiresIn\n async #getAuthSession(): Promise<LoginResponse | null> {\n const auth = await this.#options.storage.getLoginResponse();\n if (!validateLoginResponse(auth)) {\n return null;\n }\n\n const currentTime = Date.now();\n const sessionAge = currentTime - auth.token.obtainedAt;\n const refreshThreshold = auth.token.expiresIn * 1000 * 0.9;\n\n if (sessionAge < refreshThreshold) {\n return auth;\n }\n return null;\n }\n\n async #login(): Promise<LoginResponse> {\n this.#assertSigner(this.#signer);\n\n // Nonce\n const address = await this.getIdentifier();\n const nonceRes = await getNonce(address, this.#config.env);\n const rawMessage = this.#createSiWELoginRawMessage(nonceRes.nonce);\n const signature = await this.signMessage(rawMessage);\n\n // Authenticate\n const authResponse = await authenticate(\n rawMessage,\n signature,\n this.#config.type,\n this.#config.env,\n );\n\n // Authorize\n const tokenResponse = await authorizeOIDC(\n authResponse.token,\n this.#config.env,\n this.#config.platform,\n );\n\n // Save\n const result: LoginResponse = {\n profile: authResponse.profile,\n token: tokenResponse,\n };\n\n await this.#options.storage.setLoginResponse(result);\n\n return result;\n }\n\n #createSiWELoginRawMessage(nonce: string): string {\n this.#assertSigner(this.#signer);\n\n return new SiweMessage({\n domain: this.#signer?.domain,\n address: this.#signer?.address,\n uri: SIWE_LOGIN_URL(this.#config.env),\n version: '1',\n chainId: this.#signer?.chainId,\n nonce,\n issuedAt: new Date().toISOString(),\n }).prepareMessage();\n }\n\n #assertSigner(\n signer?: JwtBearerAuth_SIWE_Signer,\n ): asserts signer is JwtBearerAuth_SIWE_Signer {\n if (!signer) {\n throw new ValidationError(`you must call 'prepare()' before logging in`);\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createSHA256Hash
|
|
3
|
+
} from "./chunk-K5UKU454.mjs";
|
|
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 = createSHA256Hash(key + storageKey);
|
|
32
|
+
return `/${feature}/${hashedKey}`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export {
|
|
36
|
+
USER_STORAGE_SCHEMA,
|
|
37
|
+
getFeatureAndKeyFromPath,
|
|
38
|
+
createEntryPath
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=chunk-ILIZJQ6X.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/controllers/user-storage/schema.ts"],"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"],"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;","names":[]}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
UserStorageController,
|
|
3
3
|
defaultState
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-LNSB4L7K.mjs";
|
|
5
5
|
import {
|
|
6
6
|
USER_STORAGE_ENDPOINT
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-FU7PSGFP.mjs";
|
|
8
8
|
import {
|
|
9
9
|
createEntryPath
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-ILIZJQ6X.mjs";
|
|
11
11
|
import {
|
|
12
12
|
encryption_default as encryption_default2
|
|
13
13
|
} from "./chunk-5TOWF6UW.mjs";
|
|
@@ -52,7 +52,7 @@ var MOCK_ENCRYPTED_STORAGE_DATA = encryption_default2.encryptString(
|
|
|
52
52
|
|
|
53
53
|
// src/controllers/user-storage/__fixtures__/mockResponses.ts
|
|
54
54
|
var MOCK_USER_STORAGE_NOTIFICATIONS_ENDPOINT = `${USER_STORAGE_ENDPOINT}${createEntryPath(
|
|
55
|
-
"notificationSettings",
|
|
55
|
+
"notifications.notificationSettings",
|
|
56
56
|
MOCK_STORAGE_KEY
|
|
57
57
|
)}`;
|
|
58
58
|
var MOCK_GET_USER_STORAGE_RESPONSE = {
|
|
@@ -78,4 +78,4 @@ export {
|
|
|
78
78
|
fixtures_exports,
|
|
79
79
|
user_storage_exports
|
|
80
80
|
};
|
|
81
|
-
//# sourceMappingURL=chunk-
|
|
81
|
+
//# sourceMappingURL=chunk-IQECLCH4.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/controllers/user-storage/index.ts","../src/controllers/user-storage/__fixtures__/index.ts","../src/controllers/user-storage/__fixtures__/mockStorage.ts","../src/controllers/user-storage/__fixtures__/mockResponses.ts"],"sourcesContent":["import Controller from './UserStorageController';\n\nexport { Controller };\nexport * from './UserStorageController';\nexport * from './encryption';\nexport * as Mocks from './__fixtures__';\n","export * from './mockResponses';\nexport * from './mockStorage';\n","import encryption, { createSHA256Hash } from '../encryption';\n\nexport const MOCK_STORAGE_KEY_SIGNATURE = 'mockStorageKey';\nexport const MOCK_STORAGE_KEY = createSHA256Hash(MOCK_STORAGE_KEY_SIGNATURE);\nexport const MOCK_STORAGE_DATA = JSON.stringify({ hello: 'world' });\nexport const MOCK_ENCRYPTED_STORAGE_DATA = encryption.encryptString(\n MOCK_STORAGE_DATA,\n MOCK_STORAGE_KEY,\n);\n","import { createEntryPath } from '../schema';\nimport type { GetUserStorageResponse } from '../services';\nimport { USER_STORAGE_ENDPOINT } from '../services';\nimport { MOCK_ENCRYPTED_STORAGE_DATA, MOCK_STORAGE_KEY } from './mockStorage';\n\ntype MockResponse = {\n url: string;\n requestMethod: 'GET' | 'POST' | 'PUT';\n response: unknown;\n};\n\nexport const MOCK_USER_STORAGE_NOTIFICATIONS_ENDPOINT = `${USER_STORAGE_ENDPOINT}${createEntryPath(\n 'notificationSettings',\n MOCK_STORAGE_KEY,\n)}`;\n\nconst MOCK_GET_USER_STORAGE_RESPONSE: GetUserStorageResponse = {\n HashedKey: 'HASHED_KEY',\n Data: MOCK_ENCRYPTED_STORAGE_DATA,\n};\n\nexport const getMockUserStorageGetResponse = () => {\n return {\n url: MOCK_USER_STORAGE_NOTIFICATIONS_ENDPOINT,\n requestMethod: 'GET',\n response: MOCK_GET_USER_STORAGE_RESPONSE,\n } satisfies MockResponse;\n};\n\nexport const getMockUserStoragePutResponse = () => {\n return {\n url: MOCK_USER_STORAGE_NOTIFICATIONS_ENDPOINT,\n requestMethod: 'PUT',\n response: null,\n } satisfies MockResponse;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEO,IAAM,6BAA6B;AACnC,IAAM,mBAAmB,iBAAiB,0BAA0B;AACpE,IAAM,oBAAoB,KAAK,UAAU,EAAE,OAAO,QAAQ,CAAC;AAC3D,IAAM,8BAA8BA,oBAAW;AAAA,EACpD;AAAA,EACA;AACF;;;ACGO,IAAM,2CAA2C,GAAG,qBAAqB,GAAG;AAAA,EACjF;AAAA,EACA;AACF,CAAC;AAED,IAAM,iCAAyD;AAAA,EAC7D,WAAW;AAAA,EACX,MAAM;AACR;AAEO,IAAM,gCAAgC,MAAM;AACjD,SAAO;AAAA,IACL,KAAK;AAAA,IACL,eAAe;AAAA,IACf,UAAU;AAAA,EACZ;AACF;AAEO,IAAM,gCAAgC,MAAM;AACjD,SAAO;AAAA,IACL,KAAK;AAAA,IACL,eAAe;AAAA,IACf,UAAU;AAAA,EACZ;AACF;","names":["encryption_default"]}
|
|
1
|
+
{"version":3,"sources":["../src/controllers/user-storage/index.ts","../src/controllers/user-storage/__fixtures__/index.ts","../src/controllers/user-storage/__fixtures__/mockStorage.ts","../src/controllers/user-storage/__fixtures__/mockResponses.ts"],"sourcesContent":["import Controller from './UserStorageController';\n\nexport { Controller };\nexport * from './UserStorageController';\nexport * from './encryption';\nexport * as Mocks from './__fixtures__';\n","export * from './mockResponses';\nexport * from './mockStorage';\n","import encryption, { createSHA256Hash } from '../encryption';\n\nexport const MOCK_STORAGE_KEY_SIGNATURE = 'mockStorageKey';\nexport const MOCK_STORAGE_KEY = createSHA256Hash(MOCK_STORAGE_KEY_SIGNATURE);\nexport const MOCK_STORAGE_DATA = JSON.stringify({ hello: 'world' });\nexport const MOCK_ENCRYPTED_STORAGE_DATA = encryption.encryptString(\n MOCK_STORAGE_DATA,\n MOCK_STORAGE_KEY,\n);\n","import { createEntryPath } from '../schema';\nimport type { GetUserStorageResponse } from '../services';\nimport { USER_STORAGE_ENDPOINT } from '../services';\nimport { MOCK_ENCRYPTED_STORAGE_DATA, MOCK_STORAGE_KEY } from './mockStorage';\n\ntype MockResponse = {\n url: string;\n requestMethod: 'GET' | 'POST' | 'PUT';\n response: unknown;\n};\n\nexport const MOCK_USER_STORAGE_NOTIFICATIONS_ENDPOINT = `${USER_STORAGE_ENDPOINT}${createEntryPath(\n 'notifications.notificationSettings',\n MOCK_STORAGE_KEY,\n)}`;\n\nconst MOCK_GET_USER_STORAGE_RESPONSE: GetUserStorageResponse = {\n HashedKey: 'HASHED_KEY',\n Data: MOCK_ENCRYPTED_STORAGE_DATA,\n};\n\nexport const getMockUserStorageGetResponse = () => {\n return {\n url: MOCK_USER_STORAGE_NOTIFICATIONS_ENDPOINT,\n requestMethod: 'GET',\n response: MOCK_GET_USER_STORAGE_RESPONSE,\n } satisfies MockResponse;\n};\n\nexport const getMockUserStoragePutResponse = () => {\n return {\n url: MOCK_USER_STORAGE_NOTIFICATIONS_ENDPOINT,\n requestMethod: 'PUT',\n response: null,\n } satisfies MockResponse;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEO,IAAM,6BAA6B;AACnC,IAAM,mBAAmB,iBAAiB,0BAA0B;AACpE,IAAM,oBAAoB,KAAK,UAAU,EAAE,OAAO,QAAQ,CAAC;AAC3D,IAAM,8BAA8BA,oBAAW;AAAA,EACpD;AAAA,EACA;AACF;;;ACGO,IAAM,2CAA2C,GAAG,qBAAqB,GAAG;AAAA,EACjF;AAAA,EACA;AACF,CAAC;AAED,IAAM,iCAAyD;AAAA,EAC7D,WAAW;AAAA,EACX,MAAM;AACR;AAEO,IAAM,gCAAgC,MAAM;AACjD,SAAO;AAAA,IACL,KAAK;AAAA,IACL,eAAe;AAAA,IACf,UAAU;AAAA,EACZ;AACF;AAEO,IAAM,gCAAgC,MAAM;AACjD,SAAO;AAAA,IACL,KAAK;AAAA,IACL,eAAe;AAAA,IACf,UAAU;AAAA,EACZ;AACF;","names":["encryption_default"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AuthenticationController,
|
|
3
3
|
defaultState
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-Y7P3UH26.mjs";
|
|
5
5
|
import {
|
|
6
6
|
AUTH_LOGIN_ENDPOINT,
|
|
7
7
|
AUTH_NONCE_ENDPOINT,
|
|
@@ -83,4 +83,4 @@ export {
|
|
|
83
83
|
fixtures_exports,
|
|
84
84
|
authentication_exports
|
|
85
85
|
};
|
|
86
|
-
//# sourceMappingURL=chunk-
|
|
86
|
+
//# sourceMappingURL=chunk-LDEIUP6J.mjs.map
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createSnapSignMessageRequest
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-NMIF3LSX.mjs";
|
|
4
4
|
import {
|
|
5
5
|
getUserStorage,
|
|
6
6
|
upsertUserStorage
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-FU7PSGFP.mjs";
|
|
8
8
|
import {
|
|
9
9
|
createSHA256Hash
|
|
10
10
|
} from "./chunk-K5UKU454.mjs";
|
|
@@ -31,7 +31,7 @@ var metadata = {
|
|
|
31
31
|
anonymous: false
|
|
32
32
|
}
|
|
33
33
|
};
|
|
34
|
-
var _auth, _notificationServices, _registerMessageHandlers, registerMessageHandlers_fn, _assertProfileSyncingEnabled, assertProfileSyncingEnabled_fn, _getStorageKeyAndBearerToken, getStorageKeyAndBearerToken_fn, _createStorageKey, createStorageKey_fn, _snapSignMessage, snapSignMessage_fn, _setIsProfileSyncingUpdateLoading, setIsProfileSyncingUpdateLoading_fn;
|
|
34
|
+
var _auth, _notificationServices, _registerMessageHandlers, registerMessageHandlers_fn, _assertProfileSyncingEnabled, assertProfileSyncingEnabled_fn, _getStorageKeyAndBearerToken, getStorageKeyAndBearerToken_fn, _createStorageKey, createStorageKey_fn, __snapSignMessageCache, _snapSignMessage, snapSignMessage_fn, _setIsProfileSyncingUpdateLoading, setIsProfileSyncingUpdateLoading_fn;
|
|
35
35
|
var UserStorageController = class extends BaseController {
|
|
36
36
|
constructor(params) {
|
|
37
37
|
super({
|
|
@@ -102,6 +102,7 @@ var UserStorageController = class extends BaseController {
|
|
|
102
102
|
);
|
|
103
103
|
}
|
|
104
104
|
});
|
|
105
|
+
__privateAdd(this, __snapSignMessageCache, {});
|
|
105
106
|
this.getMetaMetricsState = params.getMetaMetricsState;
|
|
106
107
|
__privateMethod(this, _registerMessageHandlers, registerMessageHandlers_fn).call(this);
|
|
107
108
|
}
|
|
@@ -160,14 +161,14 @@ var UserStorageController = class extends BaseController {
|
|
|
160
161
|
* Allows retrieval of stored data. Data stored is string formatted.
|
|
161
162
|
* Developers can extend the entry path and entry name through the `schema.ts` file.
|
|
162
163
|
*
|
|
163
|
-
* @param
|
|
164
|
+
* @param path - string in the form of `${feature}.${key}` that matches schema
|
|
164
165
|
* @returns the decrypted string contents found from user storage (or null if not found)
|
|
165
166
|
*/
|
|
166
|
-
async performGetStorage(
|
|
167
|
+
async performGetStorage(path) {
|
|
167
168
|
__privateMethod(this, _assertProfileSyncingEnabled, assertProfileSyncingEnabled_fn).call(this);
|
|
168
169
|
const { bearerToken, storageKey } = await __privateMethod(this, _getStorageKeyAndBearerToken, getStorageKeyAndBearerToken_fn).call(this);
|
|
169
170
|
const result = await getUserStorage({
|
|
170
|
-
|
|
171
|
+
path,
|
|
171
172
|
bearerToken,
|
|
172
173
|
storageKey
|
|
173
174
|
});
|
|
@@ -177,15 +178,15 @@ var UserStorageController = class extends BaseController {
|
|
|
177
178
|
* Allows storage of user data. Data stored must be string formatted.
|
|
178
179
|
* Developers can extend the entry path and entry name through the `schema.ts` file.
|
|
179
180
|
*
|
|
180
|
-
* @param
|
|
181
|
+
* @param path - string in the form of `${feature}.${key}` that matches schema
|
|
181
182
|
* @param value - The string data you want to store.
|
|
182
183
|
* @returns nothing. NOTE that an error is thrown if fails to store data.
|
|
183
184
|
*/
|
|
184
|
-
async performSetStorage(
|
|
185
|
+
async performSetStorage(path, value) {
|
|
185
186
|
__privateMethod(this, _assertProfileSyncingEnabled, assertProfileSyncingEnabled_fn).call(this);
|
|
186
187
|
const { bearerToken, storageKey } = await __privateMethod(this, _getStorageKeyAndBearerToken, getStorageKeyAndBearerToken_fn).call(this);
|
|
187
188
|
await upsertUserStorage(value, {
|
|
188
|
-
|
|
189
|
+
path,
|
|
189
190
|
bearerToken,
|
|
190
191
|
storageKey
|
|
191
192
|
});
|
|
@@ -253,12 +254,18 @@ createStorageKey_fn = async function() {
|
|
|
253
254
|
const storageKey = createSHA256Hash(storageKeySignature);
|
|
254
255
|
return storageKey;
|
|
255
256
|
};
|
|
257
|
+
__snapSignMessageCache = new WeakMap();
|
|
256
258
|
_snapSignMessage = new WeakSet();
|
|
257
|
-
snapSignMessage_fn = function(message) {
|
|
258
|
-
|
|
259
|
+
snapSignMessage_fn = async function(message) {
|
|
260
|
+
if (__privateGet(this, __snapSignMessageCache)[message]) {
|
|
261
|
+
return __privateGet(this, __snapSignMessageCache)[message];
|
|
262
|
+
}
|
|
263
|
+
const result = await this.messagingSystem.call(
|
|
259
264
|
"SnapController:handleRequest",
|
|
260
265
|
createSnapSignMessageRequest(message)
|
|
261
266
|
);
|
|
267
|
+
__privateGet(this, __snapSignMessageCache)[message] = result;
|
|
268
|
+
return result;
|
|
262
269
|
};
|
|
263
270
|
_setIsProfileSyncingUpdateLoading = new WeakSet();
|
|
264
271
|
setIsProfileSyncingUpdateLoading_fn = function(isProfileSyncingUpdateLoading) {
|
|
@@ -271,4 +278,4 @@ export {
|
|
|
271
278
|
defaultState,
|
|
272
279
|
UserStorageController
|
|
273
280
|
};
|
|
274
|
-
//# sourceMappingURL=chunk-
|
|
281
|
+
//# sourceMappingURL=chunk-LNSB4L7K.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/controllers/user-storage/UserStorageController.ts"],"sourcesContent":["import type {\n RestrictedControllerMessenger,\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"],"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,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O;AAAA,EAC5C;AAEA,QAAM,SAAU,MAAM,KAAK,gBAAgB;AAAA,IACzC;AAAA,IACA,6BAA6B,OAAO;AAAA,EACtC;AAEA,qBAAK,wBAAuB,OAAO,IAAI;AAEvC,SAAO;AACT;AAEA;AAAA,sCAAiC,SAC/B,+BACM;AACN,OAAK,OAAO,CAAC,UAAU;AACrB,UAAM,gCAAgC;AAAA,EACxC,CAAC;AACH;","names":[]}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
// src/controllers/authentication/auth-snap-requests.ts
|
|
2
|
-
import { HandlerType } from "@metamask/snaps-utils";
|
|
3
2
|
var snapId = "npm:@metamask/message-signing-snap";
|
|
4
3
|
function createSnapPublicKeyRequest() {
|
|
5
4
|
return {
|
|
6
5
|
snapId,
|
|
7
6
|
origin: "",
|
|
8
|
-
handler:
|
|
7
|
+
handler: "onRpcRequest",
|
|
9
8
|
request: {
|
|
10
9
|
method: "getPublicKey"
|
|
11
10
|
}
|
|
@@ -15,7 +14,7 @@ function createSnapSignMessageRequest(message) {
|
|
|
15
14
|
return {
|
|
16
15
|
snapId,
|
|
17
16
|
origin: "",
|
|
18
|
-
handler:
|
|
17
|
+
handler: "onRpcRequest",
|
|
19
18
|
request: {
|
|
20
19
|
method: "signMessage",
|
|
21
20
|
params: { message }
|
|
@@ -27,4 +26,4 @@ export {
|
|
|
27
26
|
createSnapPublicKeyRequest,
|
|
28
27
|
createSnapSignMessageRequest
|
|
29
28
|
};
|
|
30
|
-
//# sourceMappingURL=chunk-
|
|
29
|
+
//# sourceMappingURL=chunk-NMIF3LSX.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/controllers/authentication/auth-snap-requests.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { HandleSnapRequest } from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\n\ntype SnapRPCRequest = Parameters<HandleSnapRequest['handler']>[0];\n\nconst snapId = 'npm:@metamask/message-signing-snap' as SnapId;\n\n/**\n * Constructs Request to Message Signing Snap to get Public Key\n *\n * @returns Snap Public Key Request\n */\nexport function createSnapPublicKeyRequest(): SnapRPCRequest {\n return {\n snapId,\n origin: '',\n handler: 'onRpcRequest' as any,\n request: {\n method: 'getPublicKey',\n },\n };\n}\n\n/**\n * Constructs Request to get Message Signing Snap to sign a message.\n *\n * @param message - message to sign\n * @returns Snap Sign Message Request\n */\nexport function createSnapSignMessageRequest(\n message: `metamask:${string}`,\n): SnapRPCRequest {\n return {\n snapId,\n origin: '',\n handler: 'onRpcRequest' as any,\n request: {\n method: 'signMessage',\n params: { message },\n },\n };\n}\n"],"mappings":";AAMA,IAAM,SAAS;AAOR,SAAS,6BAA6C;AAC3D,SAAO;AAAA,IACL;AAAA,IACA,QAAQ;AAAA,IACR,SAAS;AAAA,IACT,SAAS;AAAA,MACP,QAAQ;AAAA,IACV;AAAA,EACF;AACF;AAQO,SAAS,6BACd,SACgB;AAChB,SAAO;AAAA,IACL;AAAA,IACA,QAAQ;AAAA,IACR,SAAS;AAAA,IACT,SAAS;AAAA,MACP,QAAQ;AAAA,MACR,QAAQ,EAAE,QAAQ;AAAA,IACpB;AAAA,EACF;AACF;","names":[]}
|
|
@@ -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,
|
|
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(
|
|
34
|
-
|
|
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(
|
|
40
|
-
|
|
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(
|
|
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
|
|
66
|
-
|
|
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
|
|
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(
|
|
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
|
|
98
|
-
|
|
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
|
|
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
|
|
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-
|
|
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":";;;;;;;;;;;;;;;;;;;;AAQO,IAAM,cAAc,CAAC,KAAU,kBACpC,GAAG,WAAW,GAAG,EAAE,iBAAiB,uBAAuB,aAAa;AAT1E;AA8BO,IAAM,cAAN,MAAkB;AAAA,EAOvB,YAAY,QAA2B,SAA6B;AA6BpE,uBAAM;AAqCN,uBAAM;AA6CN;AAOA;AAAA;AAAA,uBAAM;AArHJ,SAAK,MAAM,OAAO;AAClB,SAAK,SAAS;AACd,SAAK,UAAU;AAAA,EACjB;AAAA,EAEA,MAAM,QAAQ,MAAuB,OAA8B;AACjE,UAAM,sBAAK,0CAAL,WAAwB,MAAM;AAAA,EACtC;AAAA,EAEA,MAAM,QAAQ,MAAwC;AACpD,WAAO,sBAAK,oCAAL,WAAqB;AAAA,EAC9B;AAAA,EAEA,MAAM,gBAAiC;AACrC,UAAM,aAAa,MAAM,KAAK,QAAQ,SAAS,cAAc;AAC7D,QAAI,YAAY;AACd,aAAO;AAAA,IACT;AAEA,UAAM,cAAc,MAAM,KAAK,OAAO,KAAK,eAAe;AAC1D,UAAM,sBAAsB,MAAM,KAAK,OAAO,KAAK;AAAA,MACjD,YAAY,YAAY,SAAS;AAAA,IACnC;AACA,UAAM,4BAA4B,iBAAiB,mBAAmB;AACtE,UAAM,KAAK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