@metamask/profile-sync-controller 0.0.0 → 0.1.1
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 +19 -1
- package/dist/chunk-2XGRQBXI.mjs +70 -0
- package/dist/chunk-2XGRQBXI.mjs.map +1 -0
- package/dist/chunk-32HAX3MW.mjs +224 -0
- package/dist/chunk-32HAX3MW.mjs.map +1 -0
- package/dist/chunk-5SXXO4MV.js +70 -0
- package/dist/chunk-5SXXO4MV.js.map +1 -0
- package/dist/chunk-5TOWF6UW.mjs +11 -0
- package/dist/chunk-5TOWF6UW.mjs.map +1 -0
- package/dist/chunk-6P6CUKKI.mjs +30 -0
- package/dist/chunk-6P6CUKKI.mjs.map +1 -0
- package/dist/chunk-76VRE4BI.mjs +18 -0
- package/dist/chunk-76VRE4BI.mjs.map +1 -0
- package/dist/chunk-AARMY5TW.mjs +86 -0
- package/dist/chunk-AARMY5TW.mjs.map +1 -0
- package/dist/chunk-AK7OTIWA.js +11 -0
- package/dist/chunk-AK7OTIWA.js.map +1 -0
- package/dist/chunk-AUFUOKJW.mjs +25 -0
- package/dist/chunk-AUFUOKJW.mjs.map +1 -0
- package/dist/{chunk-OF3TQWGX.js → chunk-AVOOINGJ.js} +34 -34
- package/dist/chunk-AVOOINGJ.js.map +1 -0
- package/dist/{chunk-CZ7YK35S.mjs → chunk-AXWK4Y23.mjs} +7 -5
- package/dist/{chunk-CZ7YK35S.mjs.map → chunk-AXWK4Y23.mjs.map} +1 -1
- package/dist/{chunk-UMKBFFZ5.mjs → chunk-B5DBQDB3.mjs} +13 -4
- package/dist/chunk-B5DBQDB3.mjs.map +1 -0
- package/dist/chunk-B6CSNLGE.js +25 -0
- package/dist/chunk-B6CSNLGE.js.map +1 -0
- package/dist/{chunk-NRH6O4QZ.js → chunk-BOET676P.js} +45 -14
- package/dist/chunk-BOET676P.js.map +1 -0
- package/dist/{chunk-2FZSWVHT.mjs → chunk-CAIIVJAO.mjs} +1 -1
- package/dist/chunk-CAIIVJAO.mjs.map +1 -0
- package/dist/chunk-ELHJSRS2.js +98 -0
- package/dist/chunk-ELHJSRS2.js.map +1 -0
- package/dist/chunk-FCT2LIGH.mjs +106 -0
- package/dist/chunk-FCT2LIGH.mjs.map +1 -0
- package/dist/chunk-FQ5SDMRE.mjs +77 -0
- package/dist/chunk-FQ5SDMRE.mjs.map +1 -0
- package/dist/chunk-H25EBXG5.mjs +58 -0
- package/dist/chunk-H25EBXG5.mjs.map +1 -0
- package/dist/chunk-H4TDS65R.js +81 -0
- package/dist/chunk-H4TDS65R.js.map +1 -0
- package/dist/{chunk-Z4BLTVTB.js → chunk-IGY2S5BC.js} +9 -3
- package/dist/chunk-IPSBQ3MS.js +30 -0
- package/dist/chunk-IPSBQ3MS.js.map +1 -0
- package/dist/{chunk-4NGEEDGV.mjs → chunk-JLDFMYAH.mjs} +9 -9
- package/dist/chunk-JLDFMYAH.mjs.map +1 -0
- package/dist/chunk-K5UKU454.mjs +158 -0
- package/dist/chunk-K5UKU454.mjs.map +1 -0
- package/dist/chunk-KBCXN3YW.mjs +98 -0
- package/dist/chunk-KBCXN3YW.mjs.map +1 -0
- package/dist/chunk-LSVRA3X2.mjs +81 -0
- package/dist/chunk-LSVRA3X2.mjs.map +1 -0
- package/dist/{chunk-GQLHSQGZ.js → chunk-MBTBE4P5.js} +9 -2
- package/dist/chunk-MBTBE4P5.js.map +1 -0
- package/dist/chunk-NLHLVVOO.js +106 -0
- package/dist/chunk-NLHLVVOO.js.map +1 -0
- package/dist/{chunk-VZXD5DCQ.js → chunk-P4DUDLMY.js} +36 -27
- package/dist/chunk-P4DUDLMY.js.map +1 -0
- package/dist/{chunk-6X6I3HZU.js → chunk-P52TG263.js} +28 -26
- package/dist/chunk-P52TG263.js.map +1 -0
- package/dist/{chunk-CFST6GWE.js → chunk-PBRUOBEQ.js} +1 -1
- package/dist/chunk-PBRUOBEQ.js.map +1 -0
- package/dist/chunk-PCOIRDTO.js +18 -0
- package/dist/chunk-PCOIRDTO.js.map +1 -0
- package/dist/chunk-PTR4DAX6.js +79 -0
- package/dist/chunk-PTR4DAX6.js.map +1 -0
- package/dist/chunk-Q5WIUNX5.js +126 -0
- package/dist/chunk-Q5WIUNX5.js.map +1 -0
- package/dist/chunk-RX5R6BUI.js +86 -0
- package/dist/chunk-RX5R6BUI.js.map +1 -0
- package/dist/chunk-SMKTWM6I.js +77 -0
- package/dist/chunk-SMKTWM6I.js.map +1 -0
- package/dist/chunk-T3FNDVE3.js +158 -0
- package/dist/chunk-T3FNDVE3.js.map +1 -0
- package/dist/{chunk-BHVT2QEA.mjs → chunk-TFFQFIJV.mjs} +8 -1
- package/dist/chunk-TFFQFIJV.mjs.map +1 -0
- package/dist/chunk-TGFMKARH.mjs +274 -0
- package/dist/chunk-TGFMKARH.mjs.map +1 -0
- package/dist/{chunk-XUI43LEZ.mjs → chunk-U5UIDVOO.mjs} +7 -1
- package/dist/chunk-UAXWZN5J.js +58 -0
- package/dist/chunk-UAXWZN5J.js.map +1 -0
- package/dist/{chunk-CYGZ4WLJ.mjs → chunk-WB6MUIML.mjs} +36 -5
- package/dist/chunk-WB6MUIML.mjs.map +1 -0
- package/dist/chunk-WJCKQLKK.mjs +79 -0
- package/dist/chunk-WJCKQLKK.mjs.map +1 -0
- package/dist/{chunk-VXPVURGH.mjs → chunk-Y46NMA3V.mjs} +9 -9
- package/dist/chunk-Y46NMA3V.mjs.map +1 -0
- package/dist/chunk-YASNOFBV.js +274 -0
- package/dist/chunk-YASNOFBV.js.map +1 -0
- package/dist/chunk-YUXN5GSW.js +224 -0
- package/dist/chunk-YUXN5GSW.js.map +1 -0
- package/dist/controllers/authentication/AuthenticationController.js +24 -0
- package/dist/controllers/authentication/AuthenticationController.mjs +24 -0
- package/dist/controllers/authentication/auth-snap-requests.js +10 -0
- package/dist/controllers/authentication/auth-snap-requests.mjs +10 -0
- package/dist/controllers/authentication/index.js +28 -0
- package/dist/controllers/authentication/index.js.map +1 -0
- package/dist/controllers/authentication/index.mjs +28 -0
- package/dist/controllers/authentication/index.mjs.map +1 -0
- package/dist/controllers/authentication/services.js +32 -0
- package/dist/controllers/authentication/services.js.map +1 -0
- package/dist/controllers/authentication/services.mjs +32 -0
- package/dist/controllers/authentication/services.mjs.map +1 -0
- package/dist/controllers/index.js +34 -0
- package/dist/controllers/index.js.map +1 -0
- package/dist/controllers/index.mjs +34 -0
- package/dist/controllers/index.mjs.map +1 -0
- package/dist/controllers/user-storage/UserStorageController.js +29 -0
- package/dist/controllers/user-storage/UserStorageController.js.map +1 -0
- package/dist/controllers/user-storage/UserStorageController.mjs +29 -0
- package/dist/controllers/user-storage/UserStorageController.mjs.map +1 -0
- package/dist/controllers/user-storage/encryption/cache.js +13 -0
- package/dist/controllers/user-storage/encryption/cache.js.map +1 -0
- package/dist/controllers/user-storage/encryption/cache.mjs +13 -0
- package/dist/controllers/user-storage/encryption/cache.mjs.map +1 -0
- package/dist/controllers/user-storage/encryption/encryption.js +12 -0
- package/dist/controllers/user-storage/encryption/encryption.js.map +1 -0
- package/dist/controllers/user-storage/encryption/encryption.mjs +12 -0
- package/dist/controllers/user-storage/encryption/encryption.mjs.map +1 -0
- package/dist/controllers/user-storage/encryption/index.js +16 -0
- package/dist/controllers/user-storage/encryption/index.js.map +1 -0
- package/dist/controllers/user-storage/encryption/index.mjs +16 -0
- package/dist/controllers/user-storage/encryption/index.mjs.map +1 -0
- package/dist/controllers/user-storage/encryption/utils.js +12 -0
- package/dist/controllers/user-storage/encryption/utils.js.map +1 -0
- package/dist/controllers/user-storage/encryption/utils.mjs +12 -0
- package/dist/controllers/user-storage/encryption/utils.mjs.map +1 -0
- package/dist/controllers/user-storage/index.js +38 -0
- package/dist/controllers/user-storage/index.js.map +1 -0
- package/dist/controllers/user-storage/index.mjs +38 -0
- package/dist/controllers/user-storage/index.mjs.map +1 -0
- package/dist/controllers/user-storage/schema.js +14 -0
- package/dist/controllers/user-storage/schema.js.map +1 -0
- package/dist/controllers/user-storage/schema.mjs +14 -0
- package/dist/controllers/user-storage/schema.mjs.map +1 -0
- package/dist/controllers/user-storage/services.js +31 -0
- package/dist/controllers/user-storage/services.js.map +1 -0
- package/dist/controllers/user-storage/services.mjs +31 -0
- package/dist/controllers/user-storage/services.mjs.map +1 -0
- package/dist/index.js +31 -62
- package/dist/index.mjs +32 -63
- package/dist/sdk/authentication-jwt-bearer/flow-siwe.js +7 -8
- package/dist/sdk/authentication-jwt-bearer/flow-siwe.mjs +6 -7
- package/dist/sdk/authentication-jwt-bearer/flow-srp.js +7 -8
- package/dist/sdk/authentication-jwt-bearer/flow-srp.mjs +6 -7
- package/dist/sdk/authentication-jwt-bearer/services.js +10 -6
- package/dist/sdk/authentication-jwt-bearer/services.mjs +11 -7
- package/dist/sdk/authentication-jwt-bearer/types.js +3 -3
- package/dist/sdk/authentication-jwt-bearer/types.mjs +2 -2
- package/dist/sdk/authentication.js +9 -10
- package/dist/sdk/authentication.mjs +8 -9
- package/dist/sdk/encryption.js +5 -3
- package/dist/sdk/encryption.mjs +4 -2
- package/dist/sdk/env.js +5 -3
- package/dist/sdk/env.mjs +4 -2
- package/dist/sdk/errors.js +5 -3
- package/dist/sdk/errors.mjs +4 -2
- package/dist/sdk/index.js +18 -13
- package/dist/sdk/index.mjs +17 -12
- package/dist/sdk/user-storage.js +6 -6
- package/dist/sdk/user-storage.mjs +5 -5
- package/dist/sdk/utils/eip-6963-metamask-provider.js +1 -1
- package/dist/sdk/utils/eip-6963-metamask-provider.mjs +1 -1
- package/dist/sdk/utils/messaging-signing-snap-requests.js +1 -1
- package/dist/sdk/utils/messaging-signing-snap-requests.mjs +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/controllers/authentication/AuthenticationController.d.ts +74 -0
- package/dist/types/controllers/authentication/AuthenticationController.d.ts.map +1 -0
- package/dist/types/controllers/authentication/__fixtures__/index.d.ts +2 -0
- package/dist/types/controllers/authentication/__fixtures__/index.d.ts.map +1 -0
- package/dist/types/controllers/authentication/__fixtures__/mockResponses.d.ts +23 -0
- package/dist/types/controllers/authentication/__fixtures__/mockResponses.d.ts.map +1 -0
- package/dist/types/controllers/authentication/__fixtures__/mockServices.d.ts +10 -0
- package/dist/types/controllers/authentication/__fixtures__/mockServices.d.ts.map +1 -0
- package/dist/types/controllers/authentication/auth-snap-requests.d.ts +17 -0
- package/dist/types/controllers/authentication/auth-snap-requests.d.ts.map +1 -0
- package/dist/types/controllers/authentication/index.d.ts +5 -0
- package/dist/types/controllers/authentication/index.d.ts.map +1 -0
- package/dist/types/controllers/authentication/services.d.ts +69 -0
- package/dist/types/controllers/authentication/services.d.ts.map +1 -0
- package/dist/types/controllers/index.d.ts +3 -0
- package/dist/types/controllers/index.d.ts.map +1 -0
- package/dist/types/controllers/user-storage/UserStorageController.d.ts +85 -0
- package/dist/types/controllers/user-storage/UserStorageController.d.ts.map +1 -0
- package/dist/types/controllers/user-storage/__fixtures__/index.d.ts +3 -0
- package/dist/types/controllers/user-storage/__fixtures__/index.d.ts.map +1 -0
- package/dist/types/controllers/user-storage/__fixtures__/mockResponses.d.ts +13 -0
- package/dist/types/controllers/user-storage/__fixtures__/mockResponses.d.ts.map +1 -0
- package/dist/types/controllers/user-storage/__fixtures__/mockServices.d.ts +9 -0
- package/dist/types/controllers/user-storage/__fixtures__/mockServices.d.ts.map +1 -0
- package/dist/types/controllers/user-storage/__fixtures__/mockStorage.d.ts +5 -0
- package/dist/types/controllers/user-storage/__fixtures__/mockStorage.d.ts.map +1 -0
- package/dist/types/controllers/user-storage/encryption/cache.d.ts +31 -0
- package/dist/types/controllers/user-storage/encryption/cache.d.ts.map +1 -0
- package/dist/types/controllers/user-storage/encryption/encryption.d.ts +26 -0
- package/dist/types/controllers/user-storage/encryption/encryption.d.ts.map +1 -0
- package/dist/types/controllers/user-storage/encryption/index.d.ts +5 -0
- package/dist/types/controllers/user-storage/encryption/index.d.ts.map +1 -0
- package/dist/types/controllers/user-storage/encryption/utils.d.ts +4 -0
- package/dist/types/controllers/user-storage/encryption/utils.d.ts.map +1 -0
- package/dist/types/controllers/user-storage/index.d.ts +6 -0
- package/dist/types/controllers/user-storage/index.d.ts.map +1 -0
- package/dist/types/controllers/user-storage/schema.d.ts +22 -0
- package/dist/types/controllers/user-storage/schema.d.ts.map +1 -0
- package/dist/types/controllers/user-storage/services.d.ts +30 -0
- package/dist/types/controllers/user-storage/services.d.ts.map +1 -0
- package/dist/types/index.d.ts +3 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/sdk/__fixtures__/mock-auth.d.ts +3 -0
- package/dist/types/sdk/__fixtures__/mock-auth.d.ts.map +1 -1
- package/dist/types/sdk/__fixtures__/mock-userstorage.d.ts.map +1 -1
- package/dist/types/sdk/__fixtures__/test-utils.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-jwt-bearer/services.d.ts +20 -2
- package/dist/types/sdk/authentication-jwt-bearer/services.d.ts.map +1 -1
- package/dist/types/sdk/authentication-jwt-bearer/types.d.ts +9 -2
- package/dist/types/sdk/authentication-jwt-bearer/types.d.ts.map +1 -1
- package/dist/types/sdk/authentication.d.ts +2 -1
- package/dist/types/sdk/authentication.d.ts.map +1 -1
- package/dist/types/sdk/encryption.d.ts +2 -2
- package/dist/types/sdk/encryption.d.ts.map +1 -1
- package/dist/types/sdk/env.d.ts +9 -2
- package/dist/types/sdk/env.d.ts.map +1 -1
- package/dist/types/sdk/errors.d.ts +3 -0
- package/dist/types/sdk/errors.d.ts.map +1 -1
- package/dist/types/sdk/user-storage.d.ts.map +1 -1
- package/package.json +15 -2
- package/dist/chunk-2FZSWVHT.mjs.map +0 -1
- package/dist/chunk-4NGEEDGV.mjs.map +0 -1
- package/dist/chunk-6X6I3HZU.js.map +0 -1
- package/dist/chunk-BARZBXO7.js +0 -7
- package/dist/chunk-BARZBXO7.js.map +0 -1
- package/dist/chunk-BHVT2QEA.mjs.map +0 -1
- package/dist/chunk-CFST6GWE.js.map +0 -1
- package/dist/chunk-CYGZ4WLJ.mjs.map +0 -1
- package/dist/chunk-DEATIRII.js +0 -1
- package/dist/chunk-GQLHSQGZ.js.map +0 -1
- package/dist/chunk-GVMIXMYB.mjs +0 -67
- package/dist/chunk-GVMIXMYB.mjs.map +0 -1
- package/dist/chunk-KHFPE566.js +0 -49
- package/dist/chunk-KHFPE566.js.map +0 -1
- package/dist/chunk-KKRIOEXD.mjs +0 -7
- package/dist/chunk-KKRIOEXD.mjs.map +0 -1
- package/dist/chunk-MKJYSWME.mjs +0 -1
- package/dist/chunk-NRH6O4QZ.js.map +0 -1
- package/dist/chunk-OF3TQWGX.js.map +0 -1
- package/dist/chunk-UMKBFFZ5.mjs.map +0 -1
- package/dist/chunk-UVJVONBF.js +0 -126
- package/dist/chunk-UVJVONBF.js.map +0 -1
- package/dist/chunk-VHUU4HEY.js +0 -67
- package/dist/chunk-VHUU4HEY.js.map +0 -1
- package/dist/chunk-VXPVURGH.mjs.map +0 -1
- package/dist/chunk-VZXD5DCQ.js.map +0 -1
- package/dist/chunk-WJRV2JCX.mjs +0 -49
- package/dist/chunk-WJRV2JCX.mjs.map +0 -1
- package/dist/sdk/authentication-jwt-bearer/constants.js +0 -8
- package/dist/sdk/authentication-jwt-bearer/constants.mjs +0 -8
- package/dist/types/sdk/authentication-jwt-bearer/constants.d.ts +0 -2
- package/dist/types/sdk/authentication-jwt-bearer/constants.d.ts.map +0 -1
- /package/dist/{chunk-DEATIRII.js.map → chunk-IGY2S5BC.js.map} +0 -0
- /package/dist/{chunk-MKJYSWME.mjs.map → chunk-U5UIDVOO.mjs.map} +0 -0
- /package/dist/{chunk-Z4BLTVTB.js.map → controllers/authentication/AuthenticationController.js.map} +0 -0
- /package/dist/{chunk-XUI43LEZ.mjs.map → controllers/authentication/AuthenticationController.mjs.map} +0 -0
- /package/dist/{sdk/authentication-jwt-bearer/constants.js.map → controllers/authentication/auth-snap-requests.js.map} +0 -0
- /package/dist/{sdk/authentication-jwt-bearer/constants.mjs.map → controllers/authentication/auth-snap-requests.mjs.map} +0 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _chunkYUXN5GSWjs = require('./chunk-YUXN5GSW.js');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
var _chunkELHJSRS2js = require('./chunk-ELHJSRS2.js');
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
var _chunkIGY2S5BCjs = require('./chunk-IGY2S5BC.js');
|
|
13
|
+
|
|
14
|
+
// src/controllers/authentication/index.ts
|
|
15
|
+
var authentication_exports = {};
|
|
16
|
+
_chunkIGY2S5BCjs.__export.call(void 0, authentication_exports, {
|
|
17
|
+
Controller: () => _chunkYUXN5GSWjs.AuthenticationController,
|
|
18
|
+
Mocks: () => fixtures_exports,
|
|
19
|
+
defaultState: () => _chunkYUXN5GSWjs.defaultState
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// src/controllers/authentication/__fixtures__/index.ts
|
|
23
|
+
var fixtures_exports = {};
|
|
24
|
+
_chunkIGY2S5BCjs.__export.call(void 0, fixtures_exports, {
|
|
25
|
+
MOCK_ACCESS_TOKEN: () => MOCK_ACCESS_TOKEN,
|
|
26
|
+
MOCK_JWT: () => MOCK_JWT,
|
|
27
|
+
MOCK_LOGIN_RESPONSE: () => MOCK_LOGIN_RESPONSE,
|
|
28
|
+
MOCK_NONCE: () => MOCK_NONCE,
|
|
29
|
+
MOCK_NONCE_RESPONSE: () => MOCK_NONCE_RESPONSE,
|
|
30
|
+
MOCK_OATH_TOKEN_RESPONSE: () => MOCK_OATH_TOKEN_RESPONSE,
|
|
31
|
+
getMockAuthAccessTokenResponse: () => getMockAuthAccessTokenResponse,
|
|
32
|
+
getMockAuthLoginResponse: () => getMockAuthLoginResponse,
|
|
33
|
+
getMockAuthNonceResponse: () => getMockAuthNonceResponse
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// src/controllers/authentication/__fixtures__/mockResponses.ts
|
|
37
|
+
var MOCK_NONCE = "4cbfqzoQpcNxVImGv";
|
|
38
|
+
var MOCK_NONCE_RESPONSE = {
|
|
39
|
+
nonce: MOCK_NONCE
|
|
40
|
+
};
|
|
41
|
+
var getMockAuthNonceResponse = () => {
|
|
42
|
+
return {
|
|
43
|
+
url: _chunkELHJSRS2js.AUTH_NONCE_ENDPOINT,
|
|
44
|
+
requestMethod: "GET",
|
|
45
|
+
response: MOCK_NONCE_RESPONSE
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
var MOCK_JWT = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c";
|
|
49
|
+
var MOCK_LOGIN_RESPONSE = {
|
|
50
|
+
token: MOCK_JWT,
|
|
51
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
52
|
+
expires_in: (/* @__PURE__ */ new Date()).toString(),
|
|
53
|
+
profile: {
|
|
54
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
55
|
+
identifier_id: "MOCK_IDENTIFIER",
|
|
56
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
57
|
+
profile_id: "MOCK_PROFILE_ID"
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
var getMockAuthLoginResponse = () => {
|
|
61
|
+
return {
|
|
62
|
+
url: _chunkELHJSRS2js.AUTH_LOGIN_ENDPOINT,
|
|
63
|
+
requestMethod: "POST",
|
|
64
|
+
response: MOCK_LOGIN_RESPONSE
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
var MOCK_ACCESS_TOKEN = `MOCK_ACCESS_TOKEN-${MOCK_JWT}`;
|
|
68
|
+
var MOCK_OATH_TOKEN_RESPONSE = {
|
|
69
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
70
|
+
access_token: MOCK_ACCESS_TOKEN,
|
|
71
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
72
|
+
expires_in: (/* @__PURE__ */ new Date()).getTime()
|
|
73
|
+
};
|
|
74
|
+
var getMockAuthAccessTokenResponse = () => {
|
|
75
|
+
return {
|
|
76
|
+
url: _chunkELHJSRS2js.OIDC_TOKENS_ENDPOINT,
|
|
77
|
+
requestMethod: "POST",
|
|
78
|
+
response: MOCK_OATH_TOKEN_RESPONSE
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
exports.fixtures_exports = fixtures_exports; exports.authentication_exports = authentication_exports;
|
|
86
|
+
//# sourceMappingURL=chunk-RX5R6BUI.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/controllers/authentication/index.ts","../src/controllers/authentication/__fixtures__/index.ts","../src/controllers/authentication/__fixtures__/mockResponses.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACiBO,IAAM,aAAa;AACnB,IAAM,sBAAqC;AAAA,EAChD,OAAO;AACT;AAEO,IAAM,2BAA2B,MAAM;AAC5C,SAAO;AAAA,IACL,KAAK;AAAA,IACL,eAAe;AAAA,IACf,UAAU;AAAA,EACZ;AACF;AAEO,IAAM,WACX;AACK,IAAM,sBAAqC;AAAA,EAChD,OAAO;AAAA;AAAA,EAEP,aAAY,oBAAI,KAAK,GAAE,SAAS;AAAA,EAChC,SAAS;AAAA;AAAA,IAEP,eAAe;AAAA;AAAA,IAEf,YAAY;AAAA,EACd;AACF;AAEO,IAAM,2BAA2B,MAAM;AAC5C,SAAO;AAAA,IACL,KAAK;AAAA,IACL,eAAe;AAAA,IACf,UAAU;AAAA,EACZ;AACF;AAEO,IAAM,oBAAoB,qBAAqB,QAAQ;AACvD,IAAM,2BAA+C;AAAA;AAAA,EAE1D,cAAc;AAAA;AAAA,EAEd,aAAY,oBAAI,KAAK,GAAE,QAAQ;AACjC;AAEO,IAAM,iCAAiC,MAAM;AAClD,SAAO;AAAA,IACL,KAAK;AAAA,IACL,eAAe;AAAA,IACf,UAAU;AAAA,EACZ;AACF","sourcesContent":["import Controller from './AuthenticationController';\n\nexport { Controller };\nexport * from './AuthenticationController';\nexport * as Mocks from './__fixtures__';\n","export * from './mockResponses';\n","import type {\n LoginResponse,\n NonceResponse,\n OAuthTokenResponse,\n} from '../services';\nimport {\n AUTH_LOGIN_ENDPOINT,\n AUTH_NONCE_ENDPOINT,\n OIDC_TOKENS_ENDPOINT,\n} from '../services';\n\ntype MockResponse = {\n url: string;\n requestMethod: 'GET' | 'POST' | 'PUT';\n response: unknown;\n};\n\nexport const MOCK_NONCE = '4cbfqzoQpcNxVImGv';\nexport const MOCK_NONCE_RESPONSE: NonceResponse = {\n nonce: MOCK_NONCE,\n};\n\nexport const getMockAuthNonceResponse = () => {\n return {\n url: AUTH_NONCE_ENDPOINT,\n requestMethod: 'GET',\n response: MOCK_NONCE_RESPONSE,\n } satisfies MockResponse;\n};\n\nexport const MOCK_JWT =\n 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c';\nexport const MOCK_LOGIN_RESPONSE: LoginResponse = {\n token: MOCK_JWT,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n expires_in: new Date().toString(),\n profile: {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n identifier_id: 'MOCK_IDENTIFIER',\n // eslint-disable-next-line @typescript-eslint/naming-convention\n profile_id: 'MOCK_PROFILE_ID',\n },\n};\n\nexport const getMockAuthLoginResponse = () => {\n return {\n url: AUTH_LOGIN_ENDPOINT,\n requestMethod: 'POST',\n response: MOCK_LOGIN_RESPONSE,\n } satisfies MockResponse;\n};\n\nexport const MOCK_ACCESS_TOKEN = `MOCK_ACCESS_TOKEN-${MOCK_JWT}`;\nexport const MOCK_OATH_TOKEN_RESPONSE: OAuthTokenResponse = {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n access_token: MOCK_ACCESS_TOKEN,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n expires_in: new Date().getTime(),\n};\n\nexport const getMockAuthAccessTokenResponse = () => {\n return {\n url: OIDC_TOKENS_ENDPOINT,\n requestMethod: 'POST',\n response: MOCK_OATH_TOKEN_RESPONSE,\n } satisfies MockResponse;\n};\n"]}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/sdk/env.ts
|
|
2
|
+
var Env = /* @__PURE__ */ ((Env2) => {
|
|
3
|
+
Env2["DEV"] = "dev";
|
|
4
|
+
Env2["UAT"] = "uat";
|
|
5
|
+
Env2["PRD"] = "prd";
|
|
6
|
+
return Env2;
|
|
7
|
+
})(Env || {});
|
|
8
|
+
var Platform = /* @__PURE__ */ ((Platform2) => {
|
|
9
|
+
Platform2["MOBILE"] = "mobile";
|
|
10
|
+
Platform2["EXTENSION"] = "extension";
|
|
11
|
+
Platform2["PORTFOLIO"] = "portfolio";
|
|
12
|
+
Platform2["INFURA"] = "infura";
|
|
13
|
+
return Platform2;
|
|
14
|
+
})(Platform || {});
|
|
15
|
+
var ENV_URLS = {
|
|
16
|
+
dev: {
|
|
17
|
+
authApiUrl: "https://authentication.dev-api.cx.metamask.io",
|
|
18
|
+
oidcApiUrl: "https://oidc.dev-api.cx.metamask.io",
|
|
19
|
+
userStorageApiUrl: "https://user-storage.dev-api.cx.metamask.io"
|
|
20
|
+
},
|
|
21
|
+
uat: {
|
|
22
|
+
authApiUrl: "https://authentication.uat-api.cx.metamask.io",
|
|
23
|
+
oidcApiUrl: "https://oidc.uat-api.cx.metamask.io",
|
|
24
|
+
userStorageApiUrl: "https://user-storage.uat-api.cx.metamask.io"
|
|
25
|
+
},
|
|
26
|
+
prd: {
|
|
27
|
+
authApiUrl: "https://authentication.api.cx.metamask.io",
|
|
28
|
+
oidcApiUrl: "https://oidc.api.cx.metamask.io",
|
|
29
|
+
userStorageApiUrl: "https://user-storage.api.cx.metamask.io"
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
function getEnvUrls(env) {
|
|
33
|
+
if (!ENV_URLS[env]) {
|
|
34
|
+
throw new Error("invalid environment configuration");
|
|
35
|
+
}
|
|
36
|
+
return ENV_URLS[env];
|
|
37
|
+
}
|
|
38
|
+
function getOidcClientId(env, platform) {
|
|
39
|
+
const clientIds = {
|
|
40
|
+
["dev" /* DEV */]: {
|
|
41
|
+
["portfolio" /* PORTFOLIO */]: "c7ca94a0-5d52-4635-9502-1a50a9c410cc",
|
|
42
|
+
["mobile" /* MOBILE */]: "e83c7cc9-267d-4fb4-8fec-f0e3bbe5ae8e",
|
|
43
|
+
["extension" /* EXTENSION */]: "f1a963d7-50dc-4cb5-8d81-f1f3654f0df3",
|
|
44
|
+
["infura" /* INFURA */]: "bd887006-0d55-481a-a395-5ff9a0dc52c9"
|
|
45
|
+
},
|
|
46
|
+
["uat" /* UAT */]: {
|
|
47
|
+
["portfolio" /* PORTFOLIO */]: "8f2dd4ac-db07-4819-9ba5-1ee0ec1b56d1",
|
|
48
|
+
["mobile" /* MOBILE */]: "c3cfdcd2-51d6-4fae-ad2c-ff238c8fef53",
|
|
49
|
+
["extension" /* EXTENSION */]: "a9de167c-c9a6-43d8-af39-d301fd44c485",
|
|
50
|
+
["infura" /* INFURA */]: "01929890-7002-4c97-9913-8f6c09a6d674"
|
|
51
|
+
},
|
|
52
|
+
["prd" /* PRD */]: {
|
|
53
|
+
["portfolio" /* PORTFOLIO */]: "35e1cd62-49c5-4be8-8b6e-a5212f2d2cfb",
|
|
54
|
+
["mobile" /* MOBILE */]: "75fa62a3-9ca0-4b91-9fe5-76bec86b0257",
|
|
55
|
+
["extension" /* EXTENSION */]: "1132f10a-b4e5-4390-a5f2-d9c6022db564",
|
|
56
|
+
["infura" /* INFURA */]: ""
|
|
57
|
+
// unset
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
if (!clientIds[env]) {
|
|
61
|
+
throw new Error(`invalid env ${env}: cannot determine oidc client id`);
|
|
62
|
+
}
|
|
63
|
+
if (!clientIds[env][platform]) {
|
|
64
|
+
throw new Error(
|
|
65
|
+
`invalid env ${env} and platform ${platform} combination: cannot determine oidc client id`
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
return clientIds[env][platform];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
exports.Env = Env; exports.Platform = Platform; exports.getEnvUrls = getEnvUrls; exports.getOidcClientId = getOidcClientId;
|
|
77
|
+
//# sourceMappingURL=chunk-SMKTWM6I.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/sdk/env.ts"],"names":["Env","Platform"],"mappings":";AAAO,IAAK,MAAL,kBAAKA,SAAL;AACL,EAAAA,KAAA,SAAM;AACN,EAAAA,KAAA,SAAM;AACN,EAAAA,KAAA,SAAM;AAHI,SAAAA;AAAA,GAAA;AAML,IAAK,WAAL,kBAAKC,cAAL;AACL,EAAAA,UAAA,YAAS;AACT,EAAAA,UAAA,eAAY;AACZ,EAAAA,UAAA,eAAY;AACZ,EAAAA,UAAA,YAAS;AAJC,SAAAA;AAAA,GAAA;AAaZ,IAAM,WAAsC;AAAA,EAC1C,KAAK;AAAA,IACH,YAAY;AAAA,IACZ,YAAY;AAAA,IACZ,mBAAmB;AAAA,EACrB;AAAA,EACA,KAAK;AAAA,IACH,YAAY;AAAA,IACZ,YAAY;AAAA,IACZ,mBAAmB;AAAA,EACrB;AAAA,EACA,KAAK;AAAA,IACH,YAAY;AAAA,IACZ,YAAY;AAAA,IACZ,mBAAmB;AAAA,EACrB;AACF;AASO,SAAS,WAAW,KAAwB;AACjD,MAAI,CAAC,SAAS,GAAG,GAAG;AAClB,UAAM,IAAI,MAAM,mCAAmC;AAAA,EACrD;AACA,SAAO,SAAS,GAAG;AACrB;AASO,SAAS,gBAAgB,KAAU,UAA4B;AACpE,QAAM,YAAY;AAAA,IAChB,CAAC,eAAO,GAAG;AAAA,MACT,CAAC,2BAAkB,GAAG;AAAA,MACtB,CAAC,qBAAe,GAAG;AAAA,MACnB,CAAC,2BAAkB,GAAG;AAAA,MACtB,CAAC,qBAAe,GAAG;AAAA,IACrB;AAAA,IACA,CAAC,eAAO,GAAG;AAAA,MACT,CAAC,2BAAkB,GAAG;AAAA,MACtB,CAAC,qBAAe,GAAG;AAAA,MACnB,CAAC,2BAAkB,GAAG;AAAA,MACtB,CAAC,qBAAe,GAAG;AAAA,IACrB;AAAA,IACA,CAAC,eAAO,GAAG;AAAA,MACT,CAAC,2BAAkB,GAAG;AAAA,MACtB,CAAC,qBAAe,GAAG;AAAA,MACnB,CAAC,2BAAkB,GAAG;AAAA,MACtB,CAAC,qBAAe,GAAG;AAAA;AAAA,IACrB;AAAA,EACF;AAEA,MAAI,CAAC,UAAU,GAAG,GAAG;AACnB,UAAM,IAAI,MAAM,eAAe,GAAG,mCAAmC;AAAA,EACvE;AAEA,MAAI,CAAC,UAAU,GAAG,EAAE,QAAQ,GAAG;AAC7B,UAAM,IAAI;AAAA,MACR,eAAe,GAAG,iBAAiB,QAAQ;AAAA,IAC7C;AAAA,EACF;AAEA,SAAO,UAAU,GAAG,EAAE,QAAQ;AAChC","sourcesContent":["export enum Env {\n DEV = 'dev',\n UAT = 'uat',\n PRD = 'prd',\n}\n\nexport enum Platform {\n MOBILE = 'mobile',\n EXTENSION = 'extension',\n PORTFOLIO = 'portfolio',\n INFURA = 'infura',\n}\n\ntype EnvUrlsEntry = {\n authApiUrl: string;\n oidcApiUrl: string;\n userStorageApiUrl: string;\n};\n\nconst ENV_URLS: Record<Env, EnvUrlsEntry> = {\n dev: {\n authApiUrl: 'https://authentication.dev-api.cx.metamask.io',\n oidcApiUrl: 'https://oidc.dev-api.cx.metamask.io',\n userStorageApiUrl: 'https://user-storage.dev-api.cx.metamask.io',\n },\n uat: {\n authApiUrl: 'https://authentication.uat-api.cx.metamask.io',\n oidcApiUrl: 'https://oidc.uat-api.cx.metamask.io',\n userStorageApiUrl: 'https://user-storage.uat-api.cx.metamask.io',\n },\n prd: {\n authApiUrl: 'https://authentication.api.cx.metamask.io',\n oidcApiUrl: 'https://oidc.api.cx.metamask.io',\n userStorageApiUrl: 'https://user-storage.api.cx.metamask.io',\n },\n};\n\n/**\n * Validates and returns correct environment endpoints\n *\n * @param env - environment field\n * @returns the correct environment url\n * @throws on invalid environment passed\n */\nexport function getEnvUrls(env: Env): EnvUrlsEntry {\n if (!ENV_URLS[env]) {\n throw new Error('invalid environment configuration');\n }\n return ENV_URLS[env];\n}\n\n/**\n * Returns the valid OIDC Client ID (used during authorization)\n *\n * @param env - environment field\n * @param platform - platform field\n * @returns the OIDC client id for the environment\n */\nexport function getOidcClientId(env: Env, platform: Platform): string {\n const clientIds = {\n [Env.DEV]: {\n [Platform.PORTFOLIO]: 'c7ca94a0-5d52-4635-9502-1a50a9c410cc',\n [Platform.MOBILE]: 'e83c7cc9-267d-4fb4-8fec-f0e3bbe5ae8e',\n [Platform.EXTENSION]: 'f1a963d7-50dc-4cb5-8d81-f1f3654f0df3',\n [Platform.INFURA]: 'bd887006-0d55-481a-a395-5ff9a0dc52c9',\n },\n [Env.UAT]: {\n [Platform.PORTFOLIO]: '8f2dd4ac-db07-4819-9ba5-1ee0ec1b56d1',\n [Platform.MOBILE]: 'c3cfdcd2-51d6-4fae-ad2c-ff238c8fef53',\n [Platform.EXTENSION]: 'a9de167c-c9a6-43d8-af39-d301fd44c485',\n [Platform.INFURA]: '01929890-7002-4c97-9913-8f6c09a6d674',\n },\n [Env.PRD]: {\n [Platform.PORTFOLIO]: '35e1cd62-49c5-4be8-8b6e-a5212f2d2cfb',\n [Platform.MOBILE]: '75fa62a3-9ca0-4b91-9fe5-76bec86b0257',\n [Platform.EXTENSION]: '1132f10a-b4e5-4390-a5f2-d9c6022db564',\n [Platform.INFURA]: '', // unset\n },\n };\n\n if (!clientIds[env]) {\n throw new Error(`invalid env ${env}: cannot determine oidc client id`);\n }\n\n if (!clientIds[env][platform]) {\n throw new Error(\n `invalid env ${env} and platform ${platform} combination: cannot determine oidc client id`,\n );\n }\n\n return clientIds[env][platform];\n}\n"]}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
var _chunkUAXWZN5Jjs = require('./chunk-UAXWZN5J.js');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
var _chunkPCOIRDTOjs = require('./chunk-PCOIRDTO.js');
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
var _chunkIGY2S5BCjs = require('./chunk-IGY2S5BC.js');
|
|
15
|
+
|
|
16
|
+
// src/controllers/user-storage/encryption/encryption.ts
|
|
17
|
+
var _aes = require('@noble/ciphers/aes');
|
|
18
|
+
var _webcrypto = require('@noble/ciphers/webcrypto');
|
|
19
|
+
var _scrypt = require('@noble/hashes/scrypt');
|
|
20
|
+
var _sha256 = require('@noble/hashes/sha256');
|
|
21
|
+
var _utils = require('@noble/hashes/utils');
|
|
22
|
+
var ALGORITHM_NONCE_SIZE = 12;
|
|
23
|
+
var ALGORITHM_KEY_SIZE = 16;
|
|
24
|
+
var SCRYPT_SALT_SIZE = 16;
|
|
25
|
+
var SCRYPT_N = 2 ** 17;
|
|
26
|
+
var SCRYPT_r = 8;
|
|
27
|
+
var SCRYPT_p = 1;
|
|
28
|
+
var _encryptStringV1, encryptStringV1_fn, _decryptStringV1, decryptStringV1_fn, _encrypt, encrypt_fn, _decrypt, decrypt_fn, _getOrGenerateScryptKey, getOrGenerateScryptKey_fn;
|
|
29
|
+
var EncryptorDecryptor = class {
|
|
30
|
+
constructor() {
|
|
31
|
+
_chunkIGY2S5BCjs.__privateAdd.call(void 0, this, _encryptStringV1);
|
|
32
|
+
_chunkIGY2S5BCjs.__privateAdd.call(void 0, this, _decryptStringV1);
|
|
33
|
+
_chunkIGY2S5BCjs.__privateAdd.call(void 0, this, _encrypt);
|
|
34
|
+
_chunkIGY2S5BCjs.__privateAdd.call(void 0, this, _decrypt);
|
|
35
|
+
_chunkIGY2S5BCjs.__privateAdd.call(void 0, this, _getOrGenerateScryptKey);
|
|
36
|
+
}
|
|
37
|
+
encryptString(plaintext, password) {
|
|
38
|
+
try {
|
|
39
|
+
return _chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _encryptStringV1, encryptStringV1_fn).call(this, plaintext, password);
|
|
40
|
+
} catch (e) {
|
|
41
|
+
const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);
|
|
42
|
+
throw new Error(`Unable to encrypt string - ${errorMessage}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
decryptString(encryptedDataStr, password) {
|
|
46
|
+
try {
|
|
47
|
+
const encryptedData = JSON.parse(encryptedDataStr);
|
|
48
|
+
if (encryptedData.v === "1") {
|
|
49
|
+
if (encryptedData.t === "scrypt") {
|
|
50
|
+
return _chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _decryptStringV1, decryptStringV1_fn).call(this, encryptedData, password);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
throw new Error(
|
|
54
|
+
`Unsupported encrypted data payload - ${encryptedDataStr}`
|
|
55
|
+
);
|
|
56
|
+
} catch (e) {
|
|
57
|
+
const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);
|
|
58
|
+
throw new Error(`Unable to decrypt string - ${errorMessage}`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
_encryptStringV1 = new WeakSet();
|
|
63
|
+
encryptStringV1_fn = function(plaintext, password) {
|
|
64
|
+
const { key, salt } = _chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _getOrGenerateScryptKey, getOrGenerateScryptKey_fn).call(this, password, {
|
|
65
|
+
N: SCRYPT_N,
|
|
66
|
+
r: SCRYPT_r,
|
|
67
|
+
p: SCRYPT_p,
|
|
68
|
+
dkLen: ALGORITHM_KEY_SIZE
|
|
69
|
+
});
|
|
70
|
+
const plaintextRaw = _utils.utf8ToBytes.call(void 0, plaintext);
|
|
71
|
+
const ciphertextAndNonceAndSalt = _utils.concatBytes.call(void 0,
|
|
72
|
+
salt,
|
|
73
|
+
_chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _encrypt, encrypt_fn).call(this, plaintextRaw, key)
|
|
74
|
+
);
|
|
75
|
+
const encryptedData = _chunkPCOIRDTOjs.byteArrayToBase64.call(void 0, ciphertextAndNonceAndSalt);
|
|
76
|
+
const encryptedPayload = {
|
|
77
|
+
v: "1",
|
|
78
|
+
t: "scrypt",
|
|
79
|
+
d: encryptedData,
|
|
80
|
+
o: {
|
|
81
|
+
N: SCRYPT_N,
|
|
82
|
+
r: SCRYPT_r,
|
|
83
|
+
p: SCRYPT_p,
|
|
84
|
+
dkLen: ALGORITHM_KEY_SIZE
|
|
85
|
+
},
|
|
86
|
+
saltLen: SCRYPT_SALT_SIZE
|
|
87
|
+
};
|
|
88
|
+
return JSON.stringify(encryptedPayload);
|
|
89
|
+
};
|
|
90
|
+
_decryptStringV1 = new WeakSet();
|
|
91
|
+
decryptStringV1_fn = function(data, password) {
|
|
92
|
+
const { o, d: base64CiphertextAndNonceAndSalt, saltLen } = data;
|
|
93
|
+
const ciphertextAndNonceAndSalt = _chunkPCOIRDTOjs.base64ToByteArray.call(void 0,
|
|
94
|
+
base64CiphertextAndNonceAndSalt
|
|
95
|
+
);
|
|
96
|
+
const salt = ciphertextAndNonceAndSalt.slice(0, saltLen);
|
|
97
|
+
const ciphertextAndNonce = ciphertextAndNonceAndSalt.slice(
|
|
98
|
+
saltLen,
|
|
99
|
+
ciphertextAndNonceAndSalt.length
|
|
100
|
+
);
|
|
101
|
+
const { key } = _chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _getOrGenerateScryptKey, getOrGenerateScryptKey_fn).call(this, password, {
|
|
102
|
+
N: o.N,
|
|
103
|
+
r: o.r,
|
|
104
|
+
p: o.p,
|
|
105
|
+
dkLen: o.dkLen
|
|
106
|
+
}, salt);
|
|
107
|
+
return _chunkPCOIRDTOjs.bytesToUtf8.call(void 0, _chunkIGY2S5BCjs.__privateMethod.call(void 0, this, _decrypt, decrypt_fn).call(this, ciphertextAndNonce, key));
|
|
108
|
+
};
|
|
109
|
+
_encrypt = new WeakSet();
|
|
110
|
+
encrypt_fn = function(plaintext, key) {
|
|
111
|
+
const nonce = _webcrypto.randomBytes.call(void 0, ALGORITHM_NONCE_SIZE);
|
|
112
|
+
const ciphertext = _aes.gcm.call(void 0, key, nonce).encrypt(plaintext);
|
|
113
|
+
return _utils.concatBytes.call(void 0, nonce, ciphertext);
|
|
114
|
+
};
|
|
115
|
+
_decrypt = new WeakSet();
|
|
116
|
+
decrypt_fn = function(ciphertextAndNonce, key) {
|
|
117
|
+
const nonce = ciphertextAndNonce.slice(0, ALGORITHM_NONCE_SIZE);
|
|
118
|
+
const ciphertext = ciphertextAndNonce.slice(
|
|
119
|
+
ALGORITHM_NONCE_SIZE,
|
|
120
|
+
ciphertextAndNonce.length
|
|
121
|
+
);
|
|
122
|
+
return _aes.gcm.call(void 0, key, nonce).decrypt(ciphertext);
|
|
123
|
+
};
|
|
124
|
+
_getOrGenerateScryptKey = new WeakSet();
|
|
125
|
+
getOrGenerateScryptKey_fn = function(password, o, salt) {
|
|
126
|
+
const hashedPassword = createSHA256Hash(password);
|
|
127
|
+
const cachedKey = salt ? _chunkUAXWZN5Jjs.getCachedKeyBySalt.call(void 0, hashedPassword, salt) : _chunkUAXWZN5Jjs.getAnyCachedKey.call(void 0, hashedPassword);
|
|
128
|
+
if (cachedKey) {
|
|
129
|
+
return {
|
|
130
|
+
key: cachedKey.key,
|
|
131
|
+
salt: cachedKey.salt
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
const newSalt = salt ?? _webcrypto.randomBytes.call(void 0, SCRYPT_SALT_SIZE);
|
|
135
|
+
const newKey = _scrypt.scrypt.call(void 0, password, newSalt, {
|
|
136
|
+
N: o.N,
|
|
137
|
+
r: o.r,
|
|
138
|
+
p: o.p,
|
|
139
|
+
dkLen: o.dkLen
|
|
140
|
+
});
|
|
141
|
+
_chunkUAXWZN5Jjs.setCachedKey.call(void 0, hashedPassword, newSalt, newKey);
|
|
142
|
+
return {
|
|
143
|
+
key: newKey,
|
|
144
|
+
salt: newSalt
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
var encryption = new EncryptorDecryptor();
|
|
148
|
+
var encryption_default = encryption;
|
|
149
|
+
function createSHA256Hash(data) {
|
|
150
|
+
const hashedData = _sha256.sha256.call(void 0, data);
|
|
151
|
+
return _utils.bytesToHex.call(void 0, hashedData);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
exports.encryption_default = encryption_default; exports.createSHA256Hash = createSHA256Hash;
|
|
158
|
+
//# sourceMappingURL=chunk-T3FNDVE3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/controllers/user-storage/encryption/encryption.ts"],"names":[],"mappings":"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","sourcesContent":["import { gcm } from '@noble/ciphers/aes';\nimport { randomBytes } from '@noble/ciphers/webcrypto';\nimport { scrypt } from '@noble/hashes/scrypt';\nimport { sha256 } from '@noble/hashes/sha256';\nimport { utf8ToBytes, concatBytes, bytesToHex } from '@noble/hashes/utils';\n\nimport { getAnyCachedKey, getCachedKeyBySalt, setCachedKey } from './cache';\nimport { base64ToByteArray, byteArrayToBase64, bytesToUtf8 } from './utils';\n\nexport type EncryptedPayload = {\n // version\n v: '1';\n\n // key derivation function algorithm - scrypt\n t: 'scrypt';\n\n // data\n d: string;\n\n // encryption options - scrypt\n o: {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n N: number;\n r: number;\n p: number;\n dkLen: number;\n };\n\n // Salt options\n saltLen: number;\n};\n\n// Nonce/Key Sizes\nconst ALGORITHM_NONCE_SIZE = 12; // 12 bytes\nconst ALGORITHM_KEY_SIZE = 16; // 16 bytes\n\n// Scrypt settings\n// see: https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html#scrypt\nconst SCRYPT_SALT_SIZE = 16; // 16 bytes\nconst SCRYPT_N = 2 ** 17; // CPU/memory cost parameter (must be a power of 2, > 1)\n// eslint-disable-next-line @typescript-eslint/naming-convention\nconst SCRYPT_r = 8; // Block size parameter\n// eslint-disable-next-line @typescript-eslint/naming-convention\nconst SCRYPT_p = 1; // Parallelization parameter\n\nclass EncryptorDecryptor {\n encryptString(plaintext: string, password: string): string {\n try {\n return this.#encryptStringV1(plaintext, password);\n } catch (e) {\n const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);\n throw new Error(`Unable to encrypt string - ${errorMessage}`);\n }\n }\n\n decryptString(encryptedDataStr: string, password: string): string {\n try {\n const encryptedData: EncryptedPayload = JSON.parse(encryptedDataStr);\n if (encryptedData.v === '1') {\n if (encryptedData.t === 'scrypt') {\n return this.#decryptStringV1(encryptedData, password);\n }\n }\n throw new Error(\n `Unsupported encrypted data payload - ${encryptedDataStr}`,\n );\n } catch (e) {\n const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);\n throw new Error(`Unable to decrypt string - ${errorMessage}`);\n }\n }\n\n #encryptStringV1(plaintext: string, password: string): string {\n const { key, salt } = this.#getOrGenerateScryptKey(password, {\n N: SCRYPT_N,\n r: SCRYPT_r,\n p: SCRYPT_p,\n dkLen: ALGORITHM_KEY_SIZE,\n });\n\n // Encrypt and prepend salt.\n const plaintextRaw = utf8ToBytes(plaintext);\n const ciphertextAndNonceAndSalt = concatBytes(\n salt,\n this.#encrypt(plaintextRaw, key),\n );\n\n // Convert to Base64\n const encryptedData = byteArrayToBase64(ciphertextAndNonceAndSalt);\n\n const encryptedPayload: EncryptedPayload = {\n v: '1',\n t: 'scrypt',\n d: encryptedData,\n o: {\n N: SCRYPT_N,\n r: SCRYPT_r,\n p: SCRYPT_p,\n dkLen: ALGORITHM_KEY_SIZE,\n },\n saltLen: SCRYPT_SALT_SIZE,\n };\n\n return JSON.stringify(encryptedPayload);\n }\n\n #decryptStringV1(data: EncryptedPayload, password: string): string {\n const { o, d: base64CiphertextAndNonceAndSalt, saltLen } = data;\n\n // Decode the base64.\n const ciphertextAndNonceAndSalt = base64ToByteArray(\n base64CiphertextAndNonceAndSalt,\n );\n\n // Create buffers of salt and ciphertextAndNonce.\n const salt = ciphertextAndNonceAndSalt.slice(0, saltLen);\n const ciphertextAndNonce = ciphertextAndNonceAndSalt.slice(\n saltLen,\n ciphertextAndNonceAndSalt.length,\n );\n\n // Derive the key.\n const { key } = this.#getOrGenerateScryptKey(\n password,\n {\n N: o.N,\n r: o.r,\n p: o.p,\n dkLen: o.dkLen,\n },\n salt,\n );\n\n // Decrypt and return result.\n return bytesToUtf8(this.#decrypt(ciphertextAndNonce, key));\n }\n\n #encrypt(plaintext: Uint8Array, key: Uint8Array): Uint8Array {\n const nonce = randomBytes(ALGORITHM_NONCE_SIZE);\n\n // Encrypt and prepend nonce.\n const ciphertext = gcm(key, nonce).encrypt(plaintext);\n\n return concatBytes(nonce, ciphertext);\n }\n\n #decrypt(ciphertextAndNonce: Uint8Array, key: Uint8Array): Uint8Array {\n // Create buffers of nonce and ciphertext.\n const nonce = ciphertextAndNonce.slice(0, ALGORITHM_NONCE_SIZE);\n const ciphertext = ciphertextAndNonce.slice(\n ALGORITHM_NONCE_SIZE,\n ciphertextAndNonce.length,\n );\n\n // Decrypt and return result.\n return gcm(key, nonce).decrypt(ciphertext);\n }\n\n #getOrGenerateScryptKey(\n password: string,\n o: EncryptedPayload['o'],\n salt?: Uint8Array,\n ) {\n const hashedPassword = createSHA256Hash(password);\n const cachedKey = salt\n ? getCachedKeyBySalt(hashedPassword, salt)\n : getAnyCachedKey(hashedPassword);\n\n if (cachedKey) {\n return {\n key: cachedKey.key,\n salt: cachedKey.salt,\n };\n }\n\n const newSalt = salt ?? randomBytes(SCRYPT_SALT_SIZE);\n const newKey = scrypt(password, newSalt, {\n N: o.N,\n r: o.r,\n p: o.p,\n dkLen: o.dkLen,\n });\n setCachedKey(hashedPassword, newSalt, newKey);\n\n return {\n key: newKey,\n salt: newSalt,\n };\n }\n}\n\nconst encryption = new EncryptorDecryptor();\nexport default encryption;\n\n/**\n * Receive a SHA256 hash from a given string\n * @param data - input\n * @returns sha256 hash\n */\nexport function createSHA256Hash(data: string): string {\n const hashedData = sha256(data);\n return bytesToHex(hashedData);\n}\n"]}
|
|
@@ -11,6 +11,12 @@ var SignInError = class extends Error {
|
|
|
11
11
|
this.name = "SignInError";
|
|
12
12
|
}
|
|
13
13
|
};
|
|
14
|
+
var PairError = class extends Error {
|
|
15
|
+
constructor(message) {
|
|
16
|
+
super(message);
|
|
17
|
+
this.name = "PairError";
|
|
18
|
+
}
|
|
19
|
+
};
|
|
14
20
|
var UserStorageError = class extends Error {
|
|
15
21
|
constructor(message) {
|
|
16
22
|
super(message);
|
|
@@ -39,9 +45,10 @@ var NotFoundError = class extends Error {
|
|
|
39
45
|
export {
|
|
40
46
|
NonceRetrievalError,
|
|
41
47
|
SignInError,
|
|
48
|
+
PairError,
|
|
42
49
|
UserStorageError,
|
|
43
50
|
ValidationError,
|
|
44
51
|
UnsupportedAuthTypeError,
|
|
45
52
|
NotFoundError
|
|
46
53
|
};
|
|
47
|
-
//# sourceMappingURL=chunk-
|
|
54
|
+
//# sourceMappingURL=chunk-TFFQFIJV.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/sdk/errors.ts"],"sourcesContent":["export class NonceRetrievalError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'NonceRetrievalError';\n }\n}\n\nexport class SignInError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'SignInError';\n }\n}\n\nexport class PairError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'PairError';\n }\n}\n\nexport class UserStorageError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'UserStorageError';\n }\n}\n\nexport class ValidationError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'ValidationError';\n }\n}\n\nexport class UnsupportedAuthTypeError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'UnsupportedAuthTypeError';\n }\n}\n\nexport class NotFoundError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'NotFoundError';\n }\n}\n"],"mappings":";AAAO,IAAM,sBAAN,cAAkC,MAAM;AAAA,EAC7C,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,cAAN,cAA0B,MAAM;AAAA,EACrC,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,YAAN,cAAwB,MAAM;AAAA,EACnC,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,mBAAN,cAA+B,MAAM;AAAA,EAC1C,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,kBAAN,cAA8B,MAAM;AAAA,EACzC,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,2BAAN,cAAuC,MAAM;AAAA,EAClD,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,gBAAN,cAA4B,MAAM;AAAA,EACvC,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;","names":[]}
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createSnapSignMessageRequest
|
|
3
|
+
} from "./chunk-6P6CUKKI.mjs";
|
|
4
|
+
import {
|
|
5
|
+
getUserStorage,
|
|
6
|
+
upsertUserStorage
|
|
7
|
+
} from "./chunk-2XGRQBXI.mjs";
|
|
8
|
+
import {
|
|
9
|
+
createSHA256Hash
|
|
10
|
+
} from "./chunk-K5UKU454.mjs";
|
|
11
|
+
import {
|
|
12
|
+
__privateAdd,
|
|
13
|
+
__privateGet,
|
|
14
|
+
__privateMethod
|
|
15
|
+
} from "./chunk-U5UIDVOO.mjs";
|
|
16
|
+
|
|
17
|
+
// src/controllers/user-storage/UserStorageController.ts
|
|
18
|
+
import { BaseController } from "@metamask/base-controller";
|
|
19
|
+
var controllerName = "UserStorageController";
|
|
20
|
+
var defaultState = {
|
|
21
|
+
isProfileSyncingEnabled: true,
|
|
22
|
+
isProfileSyncingUpdateLoading: false
|
|
23
|
+
};
|
|
24
|
+
var metadata = {
|
|
25
|
+
isProfileSyncingEnabled: {
|
|
26
|
+
persist: true,
|
|
27
|
+
anonymous: true
|
|
28
|
+
},
|
|
29
|
+
isProfileSyncingUpdateLoading: {
|
|
30
|
+
persist: false,
|
|
31
|
+
anonymous: false
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
var _auth, _notificationServices, _registerMessageHandlers, registerMessageHandlers_fn, _assertProfileSyncingEnabled, assertProfileSyncingEnabled_fn, _getStorageKeyAndBearerToken, getStorageKeyAndBearerToken_fn, _createStorageKey, createStorageKey_fn, _snapSignMessage, snapSignMessage_fn, _setIsProfileSyncingUpdateLoading, setIsProfileSyncingUpdateLoading_fn;
|
|
35
|
+
var UserStorageController = class extends BaseController {
|
|
36
|
+
constructor(params) {
|
|
37
|
+
super({
|
|
38
|
+
messenger: params.messenger,
|
|
39
|
+
metadata,
|
|
40
|
+
name: controllerName,
|
|
41
|
+
state: { ...defaultState, ...params.state }
|
|
42
|
+
});
|
|
43
|
+
/**
|
|
44
|
+
* Constructor helper for registering this controller's messaging system
|
|
45
|
+
* actions.
|
|
46
|
+
*/
|
|
47
|
+
__privateAdd(this, _registerMessageHandlers);
|
|
48
|
+
__privateAdd(this, _assertProfileSyncingEnabled);
|
|
49
|
+
/**
|
|
50
|
+
* Utility to get the bearer token and storage key
|
|
51
|
+
*/
|
|
52
|
+
__privateAdd(this, _getStorageKeyAndBearerToken);
|
|
53
|
+
/**
|
|
54
|
+
* Rather than storing the storage key, we can compute the storage key when needed.
|
|
55
|
+
*
|
|
56
|
+
* @returns the storage key
|
|
57
|
+
*/
|
|
58
|
+
__privateAdd(this, _createStorageKey);
|
|
59
|
+
/**
|
|
60
|
+
* Signs a specific message using an underlying auth snap.
|
|
61
|
+
*
|
|
62
|
+
* @param message - A specific tagged message to sign.
|
|
63
|
+
* @returns A Signature created by the snap.
|
|
64
|
+
*/
|
|
65
|
+
__privateAdd(this, _snapSignMessage);
|
|
66
|
+
__privateAdd(this, _setIsProfileSyncingUpdateLoading);
|
|
67
|
+
__privateAdd(this, _auth, {
|
|
68
|
+
getBearerToken: async () => {
|
|
69
|
+
return await this.messagingSystem.call(
|
|
70
|
+
"AuthenticationController:getBearerToken"
|
|
71
|
+
);
|
|
72
|
+
},
|
|
73
|
+
getProfileId: async () => {
|
|
74
|
+
const sessionProfile = await this.messagingSystem.call(
|
|
75
|
+
"AuthenticationController:getSessionProfile"
|
|
76
|
+
);
|
|
77
|
+
return sessionProfile?.profileId;
|
|
78
|
+
},
|
|
79
|
+
isAuthEnabled: () => {
|
|
80
|
+
return this.messagingSystem.call("AuthenticationController:isSignedIn");
|
|
81
|
+
},
|
|
82
|
+
signIn: async () => {
|
|
83
|
+
return await this.messagingSystem.call(
|
|
84
|
+
"AuthenticationController:performSignIn"
|
|
85
|
+
);
|
|
86
|
+
},
|
|
87
|
+
signOut: async () => {
|
|
88
|
+
return this.messagingSystem.call(
|
|
89
|
+
"AuthenticationController:performSignOut"
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
__privateAdd(this, _notificationServices, {
|
|
94
|
+
disableNotificationServices: async () => {
|
|
95
|
+
return await this.messagingSystem.call(
|
|
96
|
+
"NotificationServicesController:disableNotificationServices"
|
|
97
|
+
);
|
|
98
|
+
},
|
|
99
|
+
selectIsNotificationServicesEnabled: async () => {
|
|
100
|
+
return this.messagingSystem.call(
|
|
101
|
+
"NotificationServicesController:selectIsNotificationServicesEnabled"
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
this.getMetaMetricsState = params.getMetaMetricsState;
|
|
106
|
+
__privateMethod(this, _registerMessageHandlers, registerMessageHandlers_fn).call(this);
|
|
107
|
+
}
|
|
108
|
+
async enableProfileSyncing() {
|
|
109
|
+
try {
|
|
110
|
+
__privateMethod(this, _setIsProfileSyncingUpdateLoading, setIsProfileSyncingUpdateLoading_fn).call(this, true);
|
|
111
|
+
const authEnabled = __privateGet(this, _auth).isAuthEnabled();
|
|
112
|
+
if (!authEnabled) {
|
|
113
|
+
await __privateGet(this, _auth).signIn();
|
|
114
|
+
}
|
|
115
|
+
this.update((state) => {
|
|
116
|
+
state.isProfileSyncingEnabled = true;
|
|
117
|
+
});
|
|
118
|
+
__privateMethod(this, _setIsProfileSyncingUpdateLoading, setIsProfileSyncingUpdateLoading_fn).call(this, false);
|
|
119
|
+
} catch (e) {
|
|
120
|
+
__privateMethod(this, _setIsProfileSyncingUpdateLoading, setIsProfileSyncingUpdateLoading_fn).call(this, false);
|
|
121
|
+
const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);
|
|
122
|
+
throw new Error(
|
|
123
|
+
`${controllerName} - failed to enable profile syncing - ${errorMessage}`
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
async setIsProfileSyncingEnabled(isProfileSyncingEnabled) {
|
|
128
|
+
this.update((state) => {
|
|
129
|
+
state.isProfileSyncingEnabled = isProfileSyncingEnabled;
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
async disableProfileSyncing() {
|
|
133
|
+
const isAlreadyDisabled = !this.state.isProfileSyncingEnabled;
|
|
134
|
+
if (isAlreadyDisabled) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
try {
|
|
138
|
+
__privateMethod(this, _setIsProfileSyncingUpdateLoading, setIsProfileSyncingUpdateLoading_fn).call(this, true);
|
|
139
|
+
const isNotificationServicesEnabled = await __privateGet(this, _notificationServices).selectIsNotificationServicesEnabled();
|
|
140
|
+
if (isNotificationServicesEnabled) {
|
|
141
|
+
await __privateGet(this, _notificationServices).disableNotificationServices();
|
|
142
|
+
}
|
|
143
|
+
const isMetaMetricsParticipation = this.getMetaMetricsState();
|
|
144
|
+
if (!isMetaMetricsParticipation) {
|
|
145
|
+
this.messagingSystem.call("AuthenticationController:performSignOut");
|
|
146
|
+
}
|
|
147
|
+
__privateMethod(this, _setIsProfileSyncingUpdateLoading, setIsProfileSyncingUpdateLoading_fn).call(this, false);
|
|
148
|
+
this.update((state) => {
|
|
149
|
+
state.isProfileSyncingEnabled = false;
|
|
150
|
+
});
|
|
151
|
+
} catch (e) {
|
|
152
|
+
__privateMethod(this, _setIsProfileSyncingUpdateLoading, setIsProfileSyncingUpdateLoading_fn).call(this, false);
|
|
153
|
+
const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);
|
|
154
|
+
throw new Error(
|
|
155
|
+
`${controllerName} - failed to disable profile syncing - ${errorMessage}`
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Allows retrieval of stored data. Data stored is string formatted.
|
|
161
|
+
* Developers can extend the entry path and entry name through the `schema.ts` file.
|
|
162
|
+
*
|
|
163
|
+
* @param entryKey - entry key that matches schema
|
|
164
|
+
* @returns the decrypted string contents found from user storage (or null if not found)
|
|
165
|
+
*/
|
|
166
|
+
async performGetStorage(entryKey) {
|
|
167
|
+
__privateMethod(this, _assertProfileSyncingEnabled, assertProfileSyncingEnabled_fn).call(this);
|
|
168
|
+
const { bearerToken, storageKey } = await __privateMethod(this, _getStorageKeyAndBearerToken, getStorageKeyAndBearerToken_fn).call(this);
|
|
169
|
+
const result = await getUserStorage({
|
|
170
|
+
entryKey,
|
|
171
|
+
bearerToken,
|
|
172
|
+
storageKey
|
|
173
|
+
});
|
|
174
|
+
return result;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Allows storage of user data. Data stored must be string formatted.
|
|
178
|
+
* Developers can extend the entry path and entry name through the `schema.ts` file.
|
|
179
|
+
*
|
|
180
|
+
* @param entryKey - entry key that matches schema
|
|
181
|
+
* @param value - The string data you want to store.
|
|
182
|
+
* @returns nothing. NOTE that an error is thrown if fails to store data.
|
|
183
|
+
*/
|
|
184
|
+
async performSetStorage(entryKey, value) {
|
|
185
|
+
__privateMethod(this, _assertProfileSyncingEnabled, assertProfileSyncingEnabled_fn).call(this);
|
|
186
|
+
const { bearerToken, storageKey } = await __privateMethod(this, _getStorageKeyAndBearerToken, getStorageKeyAndBearerToken_fn).call(this);
|
|
187
|
+
await upsertUserStorage(value, {
|
|
188
|
+
entryKey,
|
|
189
|
+
bearerToken,
|
|
190
|
+
storageKey
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Retrieves the storage key, for internal use only!
|
|
195
|
+
*
|
|
196
|
+
* @returns the storage key
|
|
197
|
+
*/
|
|
198
|
+
async getStorageKey() {
|
|
199
|
+
__privateMethod(this, _assertProfileSyncingEnabled, assertProfileSyncingEnabled_fn).call(this);
|
|
200
|
+
const storageKey = await __privateMethod(this, _createStorageKey, createStorageKey_fn).call(this);
|
|
201
|
+
return storageKey;
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
_auth = new WeakMap();
|
|
205
|
+
_notificationServices = new WeakMap();
|
|
206
|
+
_registerMessageHandlers = new WeakSet();
|
|
207
|
+
registerMessageHandlers_fn = function() {
|
|
208
|
+
this.messagingSystem.registerActionHandler(
|
|
209
|
+
"UserStorageController:performGetStorage",
|
|
210
|
+
this.performGetStorage.bind(this)
|
|
211
|
+
);
|
|
212
|
+
this.messagingSystem.registerActionHandler(
|
|
213
|
+
"UserStorageController:performSetStorage",
|
|
214
|
+
this.performSetStorage.bind(this)
|
|
215
|
+
);
|
|
216
|
+
this.messagingSystem.registerActionHandler(
|
|
217
|
+
"UserStorageController:getStorageKey",
|
|
218
|
+
this.getStorageKey.bind(this)
|
|
219
|
+
);
|
|
220
|
+
this.messagingSystem.registerActionHandler(
|
|
221
|
+
"UserStorageController:enableProfileSyncing",
|
|
222
|
+
this.enableProfileSyncing.bind(this)
|
|
223
|
+
);
|
|
224
|
+
this.messagingSystem.registerActionHandler(
|
|
225
|
+
"UserStorageController:disableProfileSyncing",
|
|
226
|
+
this.disableProfileSyncing.bind(this)
|
|
227
|
+
);
|
|
228
|
+
};
|
|
229
|
+
_assertProfileSyncingEnabled = new WeakSet();
|
|
230
|
+
assertProfileSyncingEnabled_fn = function() {
|
|
231
|
+
if (!this.state.isProfileSyncingEnabled) {
|
|
232
|
+
throw new Error(
|
|
233
|
+
`${controllerName}: Unable to call method, user is not authenticated`
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
_getStorageKeyAndBearerToken = new WeakSet();
|
|
238
|
+
getStorageKeyAndBearerToken_fn = async function() {
|
|
239
|
+
const bearerToken = await __privateGet(this, _auth).getBearerToken();
|
|
240
|
+
if (!bearerToken) {
|
|
241
|
+
throw new Error("UserStorageController - unable to get bearer token");
|
|
242
|
+
}
|
|
243
|
+
const storageKey = await __privateMethod(this, _createStorageKey, createStorageKey_fn).call(this);
|
|
244
|
+
return { bearerToken, storageKey };
|
|
245
|
+
};
|
|
246
|
+
_createStorageKey = new WeakSet();
|
|
247
|
+
createStorageKey_fn = async function() {
|
|
248
|
+
const id = await __privateGet(this, _auth).getProfileId();
|
|
249
|
+
if (!id) {
|
|
250
|
+
throw new Error("UserStorageController - unable to create storage key");
|
|
251
|
+
}
|
|
252
|
+
const storageKeySignature = await __privateMethod(this, _snapSignMessage, snapSignMessage_fn).call(this, `metamask:${id}`);
|
|
253
|
+
const storageKey = createSHA256Hash(storageKeySignature);
|
|
254
|
+
return storageKey;
|
|
255
|
+
};
|
|
256
|
+
_snapSignMessage = new WeakSet();
|
|
257
|
+
snapSignMessage_fn = function(message) {
|
|
258
|
+
return this.messagingSystem.call(
|
|
259
|
+
"SnapController:handleRequest",
|
|
260
|
+
createSnapSignMessageRequest(message)
|
|
261
|
+
);
|
|
262
|
+
};
|
|
263
|
+
_setIsProfileSyncingUpdateLoading = new WeakSet();
|
|
264
|
+
setIsProfileSyncingUpdateLoading_fn = function(isProfileSyncingUpdateLoading) {
|
|
265
|
+
this.update((state) => {
|
|
266
|
+
state.isProfileSyncingUpdateLoading = isProfileSyncingUpdateLoading;
|
|
267
|
+
});
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
export {
|
|
271
|
+
defaultState,
|
|
272
|
+
UserStorageController
|
|
273
|
+
};
|
|
274
|
+
//# sourceMappingURL=chunk-TGFMKARH.mjs.map
|