@metamask/profile-sync-controller 0.0.0 → 0.1.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 +8 -1
- package/dist/chunk-26CCETCM.mjs +70 -0
- package/dist/chunk-2MVOZPBN.js +98 -0
- package/dist/chunk-2MVOZPBN.js.map +1 -0
- package/dist/chunk-3FJQHCCQ.mjs +106 -0
- package/dist/chunk-3FJQHCCQ.mjs.map +1 -0
- package/dist/chunk-4OMJ7A6A.js +77 -0
- package/dist/chunk-4OMJ7A6A.js.map +1 -0
- package/dist/chunk-6P6CUKKI.mjs +30 -0
- package/dist/chunk-6P6CUKKI.mjs.map +1 -0
- package/dist/{chunk-OF3TQWGX.js → chunk-6TK7544L.js} +34 -34
- package/dist/chunk-6TK7544L.js.map +1 -0
- package/dist/chunk-76VRE4BI.mjs +18 -0
- package/dist/chunk-76VRE4BI.mjs.map +1 -0
- package/dist/chunk-772MKTIO.mjs +25 -0
- package/dist/chunk-772MKTIO.mjs.map +1 -0
- package/dist/chunk-7FCK4BY3.js +25 -0
- package/dist/chunk-7FCK4BY3.js.map +1 -0
- package/dist/{chunk-CYGZ4WLJ.mjs → chunk-7VMXBDXN.mjs} +36 -5
- package/dist/chunk-7VMXBDXN.mjs.map +1 -0
- package/dist/chunk-ARWL2LBB.js +273 -0
- package/dist/chunk-ARWL2LBB.js.map +1 -0
- package/dist/chunk-BFE6TB7Y.mjs +11 -0
- package/dist/chunk-BFE6TB7Y.mjs.map +1 -0
- package/dist/chunk-BVM4HBM4.js +112 -0
- package/dist/chunk-BVM4HBM4.js.map +1 -0
- package/dist/chunk-DHHBHLVN.mjs +70 -0
- package/dist/chunk-DHHBHLVN.mjs.map +1 -0
- package/dist/chunk-DLXLU44Z.js +106 -0
- package/dist/chunk-DLXLU44Z.js.map +1 -0
- package/dist/chunk-GJJT2CAL.js +3342 -0
- package/dist/chunk-GJJT2CAL.js.map +1 -0
- package/dist/{chunk-VZXD5DCQ.js → chunk-GLDUXN2T.js} +36 -27
- package/dist/chunk-GLDUXN2T.js.map +1 -0
- package/dist/chunk-GLS4QZF6.mjs +77 -0
- package/dist/chunk-GLS4QZF6.mjs.map +1 -0
- package/dist/chunk-H25EBXG5.mjs +58 -0
- package/dist/chunk-H25EBXG5.mjs.map +1 -0
- package/dist/chunk-IPSBQ3MS.js +30 -0
- package/dist/chunk-IPSBQ3MS.js.map +1 -0
- package/dist/chunk-IZHWP5VW.mjs +79 -0
- package/dist/chunk-IZHWP5VW.mjs.map +1 -0
- package/dist/chunk-JAGWB4JI.mjs +102 -0
- package/dist/chunk-JAGWB4JI.mjs.map +1 -0
- package/dist/chunk-JMU3OVPK.mjs +3342 -0
- package/dist/chunk-JMU3OVPK.mjs.map +1 -0
- package/dist/chunk-JTDFOATG.js +11 -0
- package/dist/chunk-JTDFOATG.js.map +1 -0
- package/dist/chunk-JWTNHCVG.js +158 -0
- package/dist/chunk-JWTNHCVG.js.map +1 -0
- package/dist/chunk-K6G7X6PX.js +70 -0
- package/dist/chunk-K6G7X6PX.js.map +1 -0
- package/dist/chunk-LHDVZNW5.js +126 -0
- package/dist/chunk-LHDVZNW5.js.map +1 -0
- package/dist/{chunk-VXPVURGH.mjs → chunk-LN2BY2QF.mjs} +9 -9
- package/dist/chunk-LN2BY2QF.mjs.map +1 -0
- package/dist/{chunk-6X6I3HZU.js → chunk-LUKNP4HM.js} +28 -26
- package/dist/chunk-LUKNP4HM.js.map +1 -0
- package/dist/{chunk-GQLHSQGZ.js → chunk-MBTBE4P5.js} +9 -2
- package/dist/chunk-MBTBE4P5.js.map +1 -0
- package/dist/chunk-PCOIRDTO.js +18 -0
- package/dist/chunk-PCOIRDTO.js.map +1 -0
- package/dist/chunk-PNZGAAT4.mjs +273 -0
- package/dist/chunk-PNZGAAT4.mjs.map +1 -0
- package/dist/chunk-PRDECQM6.mjs +221 -0
- package/dist/chunk-PRDECQM6.mjs.map +1 -0
- package/dist/chunk-QE2F5AZL.mjs +158 -0
- package/dist/chunk-QE2F5AZL.mjs.map +1 -0
- package/dist/chunk-QHL6SQTC.mjs +112 -0
- package/dist/chunk-QHL6SQTC.mjs.map +1 -0
- package/dist/chunk-QILE6KIE.js +79 -0
- package/dist/chunk-QILE6KIE.js.map +1 -0
- package/dist/{chunk-CFST6GWE.js → chunk-T77FC4PB.js} +1 -1
- package/dist/chunk-T77FC4PB.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-UAXWZN5J.js +58 -0
- package/dist/chunk-UAXWZN5J.js.map +1 -0
- package/dist/{chunk-CZ7YK35S.mjs → chunk-UEZI2POO.mjs} +7 -5
- package/dist/{chunk-CZ7YK35S.mjs.map → chunk-UEZI2POO.mjs.map} +1 -1
- package/dist/{chunk-4NGEEDGV.mjs → chunk-UWRKMJBI.mjs} +9 -9
- package/dist/chunk-UWRKMJBI.mjs.map +1 -0
- package/dist/chunk-V46WVGWN.js +70 -0
- package/dist/{chunk-UMKBFFZ5.mjs → chunk-VTM5T7Y4.mjs} +13 -4
- package/dist/chunk-VTM5T7Y4.mjs.map +1 -0
- package/dist/chunk-VYE2DKST.js +102 -0
- package/dist/chunk-VYE2DKST.js.map +1 -0
- package/dist/chunk-W7JFFMEZ.mjs +98 -0
- package/dist/chunk-W7JFFMEZ.mjs.map +1 -0
- package/dist/chunk-WAS6V24H.js +221 -0
- package/dist/chunk-WAS6V24H.js.map +1 -0
- package/dist/{chunk-NRH6O4QZ.js → chunk-XUPRRLBI.js} +45 -14
- package/dist/chunk-XUPRRLBI.js.map +1 -0
- package/dist/{chunk-2FZSWVHT.mjs → chunk-YWA77VMP.mjs} +1 -1
- package/dist/chunk-YWA77VMP.mjs.map +1 -0
- package/dist/controllers/authentication/AuthenticationController.js +22 -0
- package/dist/controllers/authentication/AuthenticationController.mjs +22 -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 +27 -0
- package/dist/controllers/authentication/index.js.map +1 -0
- package/dist/controllers/authentication/index.mjs +27 -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 +35 -0
- package/dist/controllers/index.js.map +1 -0
- package/dist/controllers/index.mjs +35 -0
- package/dist/controllers/index.mjs.map +1 -0
- package/dist/controllers/user-storage/UserStorageController.js +27 -0
- package/dist/controllers/user-storage/UserStorageController.js.map +1 -0
- package/dist/controllers/user-storage/UserStorageController.mjs +27 -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 +37 -0
- package/dist/controllers/user-storage/index.js.map +1 -0
- package/dist/controllers/user-storage/index.mjs +37 -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 +32 -62
- package/dist/index.mjs +33 -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 +73 -0
- package/dist/types/controllers/authentication/AuthenticationController.d.ts.map +1 -0
- package/dist/types/controllers/authentication/__fixtures__/index.d.ts +3 -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 +84 -0
- package/dist/types/controllers/user-storage/UserStorageController.d.ts.map +1 -0
- package/dist/types/controllers/user-storage/__fixtures__/index.d.ts +4 -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 +8 -1
- 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 +8 -1
- 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/chunk-XUI43LEZ.mjs +0 -30
- package/dist/chunk-Z4BLTVTB.js +0 -30
- 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-MKJYSWME.mjs.map → chunk-26CCETCM.mjs.map} +0 -0
- /package/dist/{chunk-DEATIRII.js.map → chunk-V46WVGWN.js.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,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createSHA256Hash
|
|
3
|
+
} from "./chunk-QE2F5AZL.mjs";
|
|
4
|
+
|
|
5
|
+
// src/controllers/user-storage/schema.ts
|
|
6
|
+
var USER_STORAGE_ENTRIES = {
|
|
7
|
+
notificationSettings: {
|
|
8
|
+
path: "notifications",
|
|
9
|
+
entryName: "notificationSettings"
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
function createEntryPath(entryKey, storageKey) {
|
|
13
|
+
const entry = USER_STORAGE_ENTRIES[entryKey];
|
|
14
|
+
if (!entry) {
|
|
15
|
+
throw new Error(`user-storage - invalid entry provided: ${entryKey}`);
|
|
16
|
+
}
|
|
17
|
+
const hashedKey = createSHA256Hash(entry.entryName + storageKey);
|
|
18
|
+
return `/${entry.path}/${hashedKey}`;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export {
|
|
22
|
+
USER_STORAGE_ENTRIES,
|
|
23
|
+
createEntryPath
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=chunk-772MKTIO.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/controllers/user-storage/schema.ts"],"sourcesContent":["import { createSHA256Hash } from './encryption';\n\ntype UserStorageEntry = { path: string; entryName: string };\n\n/**\n * The User Storage Endpoint requires a path and an entry name.\n * Developers can provide additional paths by extending this variable below\n */\nexport const USER_STORAGE_ENTRIES = {\n notificationSettings: {\n path: 'notifications',\n entryName: 'notificationSettings',\n },\n} satisfies Record<string, UserStorageEntry>;\n\nexport type UserStorageEntryKeys = keyof typeof USER_STORAGE_ENTRIES;\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 entryKey - storage schema entry key\n * @param storageKey - users storage key\n * @returns path to store entry\n */\nexport function createEntryPath(\n entryKey: UserStorageEntryKeys,\n storageKey: string,\n): string {\n const entry = USER_STORAGE_ENTRIES[entryKey];\n if (!entry) {\n throw new Error(`user-storage - invalid entry provided: ${entryKey}`);\n }\n\n const hashedKey = createSHA256Hash(entry.entryName + storageKey);\n return `/${entry.path}/${hashedKey}`;\n}\n"],"mappings":";;;;;AAQO,IAAM,uBAAuB;AAAA,EAClC,sBAAsB;AAAA,IACpB,MAAM;AAAA,IACN,WAAW;AAAA,EACb;AACF;AAaO,SAAS,gBACd,UACA,YACQ;AACR,QAAM,QAAQ,qBAAqB,QAAQ;AAC3C,MAAI,CAAC,OAAO;AACV,UAAM,IAAI,MAAM,0CAA0C,QAAQ,EAAE;AAAA,EACtE;AAEA,QAAM,YAAY,iBAAiB,MAAM,YAAY,UAAU;AAC/D,SAAO,IAAI,MAAM,IAAI,IAAI,SAAS;AACpC;","names":[]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkJWTNHCVGjs = require('./chunk-JWTNHCVG.js');
|
|
4
|
+
|
|
5
|
+
// src/controllers/user-storage/schema.ts
|
|
6
|
+
var USER_STORAGE_ENTRIES = {
|
|
7
|
+
notificationSettings: {
|
|
8
|
+
path: "notifications",
|
|
9
|
+
entryName: "notificationSettings"
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
function createEntryPath(entryKey, storageKey) {
|
|
13
|
+
const entry = USER_STORAGE_ENTRIES[entryKey];
|
|
14
|
+
if (!entry) {
|
|
15
|
+
throw new Error(`user-storage - invalid entry provided: ${entryKey}`);
|
|
16
|
+
}
|
|
17
|
+
const hashedKey = _chunkJWTNHCVGjs.createSHA256Hash.call(void 0, entry.entryName + storageKey);
|
|
18
|
+
return `/${entry.path}/${hashedKey}`;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
exports.USER_STORAGE_ENTRIES = USER_STORAGE_ENTRIES; exports.createEntryPath = createEntryPath;
|
|
25
|
+
//# sourceMappingURL=chunk-7FCK4BY3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/controllers/user-storage/schema.ts"],"names":[],"mappings":";;;;;AAQO,IAAM,uBAAuB;AAAA,EAClC,sBAAsB;AAAA,IACpB,MAAM;AAAA,IACN,WAAW;AAAA,EACb;AACF;AAaO,SAAS,gBACd,UACA,YACQ;AACR,QAAM,QAAQ,qBAAqB,QAAQ;AAC3C,MAAI,CAAC,OAAO;AACV,UAAM,IAAI,MAAM,0CAA0C,QAAQ,EAAE;AAAA,EACtE;AAEA,QAAM,YAAY,iBAAiB,MAAM,YAAY,UAAU;AAC/D,SAAO,IAAI,MAAM,IAAI,IAAI,SAAS;AACpC","sourcesContent":["import { createSHA256Hash } from './encryption';\n\ntype UserStorageEntry = { path: string; entryName: string };\n\n/**\n * The User Storage Endpoint requires a path and an entry name.\n * Developers can provide additional paths by extending this variable below\n */\nexport const USER_STORAGE_ENTRIES = {\n notificationSettings: {\n path: 'notifications',\n entryName: 'notificationSettings',\n },\n} satisfies Record<string, UserStorageEntry>;\n\nexport type UserStorageEntryKeys = keyof typeof USER_STORAGE_ENTRIES;\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 entryKey - storage schema entry key\n * @param storageKey - users storage key\n * @returns path to store entry\n */\nexport function createEntryPath(\n entryKey: UserStorageEntryKeys,\n storageKey: string,\n): string {\n const entry = USER_STORAGE_ENTRIES[entryKey];\n if (!entry) {\n throw new Error(`user-storage - invalid entry provided: ${entryKey}`);\n }\n\n const hashedKey = createSHA256Hash(entry.entryName + storageKey);\n return `/${entry.path}/${hashedKey}`;\n}\n"]}
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getEnvUrls,
|
|
3
3
|
getOidcClientId
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-GLS4QZF6.mjs";
|
|
5
5
|
import {
|
|
6
6
|
NonceRetrievalError,
|
|
7
|
+
PairError,
|
|
7
8
|
SignInError,
|
|
8
9
|
ValidationError
|
|
9
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-TFFQFIJV.mjs";
|
|
10
11
|
|
|
11
12
|
// src/sdk/authentication-jwt-bearer/services.ts
|
|
12
13
|
var NONCE_URL = (env) => `${getEnvUrls(env).authApiUrl}/api/v2/nonce`;
|
|
14
|
+
var PAIR_IDENTIFIERS = (env) => `${getEnvUrls(env).authApiUrl}/api/v2/identifiers/pair`;
|
|
13
15
|
var OIDC_TOKEN_URL = (env) => `${getEnvUrls(env).oidcApiUrl}/oauth2/token`;
|
|
14
16
|
var SRP_LOGIN_URL = (env) => `${getEnvUrls(env).authApiUrl}/api/v2/srp/login`;
|
|
15
17
|
var SIWE_LOGIN_URL = (env) => `${getEnvUrls(env).authApiUrl}/api/v2/siwe/login`;
|
|
@@ -25,6 +27,31 @@ var getAuthenticationUrl = (authType, env) => {
|
|
|
25
27
|
);
|
|
26
28
|
}
|
|
27
29
|
};
|
|
30
|
+
async function pairIdentifiers(nonce, logins, accessToken, env) {
|
|
31
|
+
const pairUrl = new URL(PAIR_IDENTIFIERS(env));
|
|
32
|
+
try {
|
|
33
|
+
const response = await fetch(pairUrl, {
|
|
34
|
+
method: "POST",
|
|
35
|
+
headers: {
|
|
36
|
+
"Content-Type": "application/json",
|
|
37
|
+
Authorization: `Bearer ${accessToken}`
|
|
38
|
+
},
|
|
39
|
+
body: JSON.stringify({
|
|
40
|
+
nonce,
|
|
41
|
+
logins
|
|
42
|
+
})
|
|
43
|
+
});
|
|
44
|
+
if (!response.ok) {
|
|
45
|
+
const responseBody = await response.json();
|
|
46
|
+
throw new Error(
|
|
47
|
+
`HTTP error message: ${responseBody.message}, error: ${responseBody.error}`
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
} catch (e) {
|
|
51
|
+
const errorMessage = e instanceof Error ? e.message : JSON.stringify(e ?? "");
|
|
52
|
+
throw new PairError(`unable to pair identifiers: ${errorMessage}`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
28
55
|
async function getNonce(id, env) {
|
|
29
56
|
const nonceUrl = new URL(NONCE_URL(env));
|
|
30
57
|
nonceUrl.searchParams.set("identifier", id);
|
|
@@ -47,14 +74,14 @@ async function getNonce(id, env) {
|
|
|
47
74
|
throw new NonceRetrievalError(`failed to generate nonce: ${errorMessage}`);
|
|
48
75
|
}
|
|
49
76
|
}
|
|
50
|
-
async function authorizeOIDC(jwtToken, env) {
|
|
77
|
+
async function authorizeOIDC(jwtToken, env, platform) {
|
|
51
78
|
const grantType = "urn:ietf:params:oauth:grant-type:jwt-bearer";
|
|
52
79
|
const headers = new Headers({
|
|
53
80
|
"Content-Type": "application/x-www-form-urlencoded"
|
|
54
81
|
});
|
|
55
82
|
const urlEncodedBody = new URLSearchParams();
|
|
56
83
|
urlEncodedBody.append("grant_type", grantType);
|
|
57
|
-
urlEncodedBody.append("client_id", getOidcClientId(env));
|
|
84
|
+
urlEncodedBody.append("client_id", getOidcClientId(env, platform));
|
|
58
85
|
urlEncodedBody.append("assertion", jwtToken);
|
|
59
86
|
try {
|
|
60
87
|
const response = await fetch(OIDC_TOKEN_URL(env), {
|
|
@@ -89,6 +116,8 @@ async function authenticate(rawMessage, signature, authType, env) {
|
|
|
89
116
|
},
|
|
90
117
|
body: JSON.stringify({
|
|
91
118
|
signature,
|
|
119
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
120
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
92
121
|
raw_message: rawMessage
|
|
93
122
|
})
|
|
94
123
|
});
|
|
@@ -116,11 +145,13 @@ async function authenticate(rawMessage, signature, authType, env) {
|
|
|
116
145
|
|
|
117
146
|
export {
|
|
118
147
|
NONCE_URL,
|
|
148
|
+
PAIR_IDENTIFIERS,
|
|
119
149
|
OIDC_TOKEN_URL,
|
|
120
150
|
SRP_LOGIN_URL,
|
|
121
151
|
SIWE_LOGIN_URL,
|
|
152
|
+
pairIdentifiers,
|
|
122
153
|
getNonce,
|
|
123
154
|
authorizeOIDC,
|
|
124
155
|
authenticate
|
|
125
156
|
};
|
|
126
|
-
//# sourceMappingURL=chunk-
|
|
157
|
+
//# sourceMappingURL=chunk-7VMXBDXN.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/sdk/authentication-jwt-bearer/services.ts"],"sourcesContent":["import type { Env, Platform } from '../env';\nimport { getEnvUrls, getOidcClientId } from '../env';\nimport {\n NonceRetrievalError,\n PairError,\n SignInError,\n ValidationError,\n} from '../errors';\nimport type { AccessToken, ErrorMessage, UserProfile } from './types';\nimport { AuthType } from './types';\n\nexport const NONCE_URL = (env: Env) =>\n `${getEnvUrls(env).authApiUrl}/api/v2/nonce`;\n\nexport const PAIR_IDENTIFIERS = (env: Env) =>\n `${getEnvUrls(env).authApiUrl}/api/v2/identifiers/pair`;\n\nexport const OIDC_TOKEN_URL = (env: Env) =>\n `${getEnvUrls(env).oidcApiUrl}/oauth2/token`;\n\nexport const SRP_LOGIN_URL = (env: Env) =>\n `${getEnvUrls(env).authApiUrl}/api/v2/srp/login`;\n\nexport const SIWE_LOGIN_URL = (env: Env) =>\n `${getEnvUrls(env).authApiUrl}/api/v2/siwe/login`;\n\nconst getAuthenticationUrl = (authType: AuthType, env: Env): string => {\n switch (authType) {\n case AuthType.SRP:\n return SRP_LOGIN_URL(env);\n case AuthType.SiWE:\n return SIWE_LOGIN_URL(env);\n /* istanbul ignore next */\n default:\n throw new ValidationError(\n `Invalid AuthType: ${authType as number} - unable to create Auth URL`,\n );\n }\n};\n\ntype NonceResponse = {\n nonce: string;\n identifier: string;\n expiresIn: number;\n};\n\ntype PairRequest = {\n signature: string;\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n raw_message: string;\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n encrypted_storage_key: string;\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n identifier_type: 'SIWE' | 'SRP';\n};\n\n/**\n * Pair multiple identifiers under a single profile\n *\n * @param nonce - session nonce\n * @param logins - pairing request payload\n * @param accessToken - JWT access token used to access protected resources\n * @param env - server environment\n * @returns void.\n */\nexport async function pairIdentifiers(\n nonce: string,\n logins: PairRequest[],\n accessToken: string,\n env: Env,\n): Promise<void> {\n const pairUrl = new URL(PAIR_IDENTIFIERS(env));\n\n try {\n const response = await fetch(pairUrl, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${accessToken}`,\n },\n body: JSON.stringify({\n nonce,\n logins,\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 } catch (e) {\n /* istanbul ignore next */\n const errorMessage =\n e instanceof Error ? e.message : JSON.stringify(e ?? '');\n throw new PairError(`unable to pair identifiers: ${errorMessage}`);\n }\n}\n\n/**\n * Service to Get Nonce for JWT Bearer Flow\n *\n * @param id - identifier ID\n * @param env - server environment\n * @returns the nonce.\n */\nexport async function getNonce(id: string, env: Env): Promise<NonceResponse> {\n const nonceUrl = new URL(NONCE_URL(env));\n nonceUrl.searchParams.set('identifier', id);\n\n try {\n const nonceResponse = await fetch(nonceUrl.toString());\n if (!nonceResponse.ok) {\n const responseBody = (await nonceResponse.json()) as ErrorMessage;\n throw new Error(\n `HTTP error message: ${responseBody.message}, error: ${responseBody.error}`,\n );\n }\n\n const nonceJson = await nonceResponse.json();\n return {\n nonce: nonceJson.nonce,\n identifier: nonceJson.identifier,\n expiresIn: nonceJson.expires_in,\n };\n } catch (e) {\n /* istanbul ignore next */\n const errorMessage =\n e instanceof Error ? e.message : JSON.stringify(e ?? '');\n throw new NonceRetrievalError(`failed to generate nonce: ${errorMessage}`);\n }\n}\n\n/**\n * Service to Authorize And perform OIDC Flow to get the Access Token\n *\n * @param jwtToken - The original token received from Authentication. This is traded for the Access Token. (the authentication token is single-use)\n * @param env - server environment\n * @param platform - SDK platform\n * @returns Access Token from Authorization server\n */\nexport async function authorizeOIDC(\n jwtToken: string,\n env: Env,\n platform: Platform,\n): Promise<AccessToken> {\n const grantType = 'urn:ietf:params:oauth:grant-type:jwt-bearer';\n const headers = new Headers({\n 'Content-Type': 'application/x-www-form-urlencoded',\n });\n\n const urlEncodedBody = new URLSearchParams();\n urlEncodedBody.append('grant_type', grantType);\n urlEncodedBody.append('client_id', getOidcClientId(env, platform));\n urlEncodedBody.append('assertion', jwtToken);\n\n try {\n const response = await fetch(OIDC_TOKEN_URL(env), {\n method: 'POST',\n headers,\n body: urlEncodedBody.toString(),\n });\n\n if (!response.ok) {\n const responseBody = (await response.json()) as {\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 error_description: string;\n error: string;\n };\n throw new Error(\n `HTTP error: ${responseBody.error_description}, error code: ${responseBody.error}`,\n );\n }\n\n const accessTokenResponse = await response.json();\n return {\n accessToken: accessTokenResponse.access_token,\n expiresIn: accessTokenResponse.expires_in,\n obtainedAt: Date.now(),\n };\n } catch (e) {\n /* istanbul ignore next */\n const errorMessage =\n e instanceof Error ? e.message : JSON.stringify(e ?? '');\n throw new SignInError(`unable to get access token: ${errorMessage}`);\n }\n}\n\ntype Authentication = {\n token: string;\n expiresIn: number;\n profile: UserProfile;\n};\n/**\n * Service to Authenticate/Login a user via SIWE or SRP derived key.\n *\n * @param rawMessage - raw message for validation when authenticating\n * @param signature - signed raw message\n * @param authType - authentication type/flow used\n * @param env - server environment\n * @returns Authentication Token\n */\nexport async function authenticate(\n rawMessage: string,\n signature: string,\n authType: AuthType,\n env: Env,\n): Promise<Authentication> {\n const authenticationUrl = getAuthenticationUrl(authType, env);\n\n try {\n const response = await fetch(authenticationUrl, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n signature,\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n raw_message: rawMessage,\n }),\n });\n\n if (!response.ok) {\n const responseBody = (await response.json()) as ErrorMessage;\n throw new Error(\n `${authType} login HTTP error: ${responseBody.message}, error code: ${responseBody.error}`,\n );\n }\n\n const loginResponse = await response.json();\n return {\n token: loginResponse.token,\n expiresIn: loginResponse.expires_in,\n profile: {\n identifierId: loginResponse.profile.identifier_id,\n metaMetricsId: loginResponse.profile.metametrics_id,\n profileId: loginResponse.profile.profile_id,\n },\n };\n } catch (e) {\n /* istanbul ignore next */\n const errorMessage =\n e instanceof Error ? e.message : JSON.stringify(e ?? '');\n throw new SignInError(`unable to perform SRP login: ${errorMessage}`);\n }\n}\n"],"mappings":";;;;;;;;;;;;AAWO,IAAM,YAAY,CAAC,QACxB,GAAG,WAAW,GAAG,EAAE,UAAU;AAExB,IAAM,mBAAmB,CAAC,QAC/B,GAAG,WAAW,GAAG,EAAE,UAAU;AAExB,IAAM,iBAAiB,CAAC,QAC7B,GAAG,WAAW,GAAG,EAAE,UAAU;AAExB,IAAM,gBAAgB,CAAC,QAC5B,GAAG,WAAW,GAAG,EAAE,UAAU;AAExB,IAAM,iBAAiB,CAAC,QAC7B,GAAG,WAAW,GAAG,EAAE,UAAU;AAE/B,IAAM,uBAAuB,CAAC,UAAoB,QAAqB;AACrE,UAAQ,UA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,QACP,gBAAgB;AAAA,MAClB;AAAA,MACA,MAAM,KAAK,UAAU;AAAA,QACnB;AAAA;AAAA;AAAA,QAGA,aAAa;AAAA,MACf,CAAC;AAAA,IACH,CAAC;AAED,QAAI,CAAC,SAAS,IAAI;AAChB,YAAM,eAAgB,MAAM,SAAS,KAAK;AAC1C,YAAM,IAAI;AAAA,QACR,GAAG,QAAQ,sBAAsB,aAAa,OAAO,iBAAiB,aAAa,KAAK;AAAA,MAC1F;AAAA,IACF;AAEA,UAAM,gBAAgB,MAAM,SAAS,KAAK;AAC1C,WAAO;AAAA,MACL,OAAO,cAAc;AAAA,MACrB,WAAW,cAAc;AAAA,MACzB,SAAS;AAAA,QACP,cAAc,cAAc,QAAQ;AAAA,QACpC,eAAe,cAAc,QAAQ;AAAA,QACrC,WAAW,cAAc,QAAQ;AAAA,MACnC;AAAA,IACF;AAAA,EACF,SAAS,GAAG;AAEV,UAAM,eACJ,aAAa,QAAQ,EAAE,UAAU,KAAK,UAAU,KAAK,EAAE;AACzD,UAAM,IAAI,YAAY,gCAAgC,YAAY,EAAE;AAAA,EACtE;AACF;","names":[]}
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkIPSBQ3MSjs = require('./chunk-IPSBQ3MS.js');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
var _chunkK6G7X6PXjs = require('./chunk-K6G7X6PX.js');
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
var _chunkJWTNHCVGjs = require('./chunk-JWTNHCVG.js');
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
var _chunkV46WVGWNjs = require('./chunk-V46WVGWN.js');
|
|
16
|
+
|
|
17
|
+
// src/controllers/user-storage/UserStorageController.ts
|
|
18
|
+
var _basecontroller = require('@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.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
|
+
_chunkV46WVGWNjs.__privateAdd.call(void 0, this, _registerMessageHandlers);
|
|
48
|
+
_chunkV46WVGWNjs.__privateAdd.call(void 0, this, _assertProfileSyncingEnabled);
|
|
49
|
+
/**
|
|
50
|
+
* Utility to get the bearer token and storage key
|
|
51
|
+
*/
|
|
52
|
+
_chunkV46WVGWNjs.__privateAdd.call(void 0, 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
|
+
_chunkV46WVGWNjs.__privateAdd.call(void 0, 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
|
+
_chunkV46WVGWNjs.__privateAdd.call(void 0, this, _snapSignMessage);
|
|
66
|
+
_chunkV46WVGWNjs.__privateAdd.call(void 0, this, _setIsProfileSyncingUpdateLoading);
|
|
67
|
+
_chunkV46WVGWNjs.__privateAdd.call(void 0, 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
|
+
_chunkV46WVGWNjs.__privateAdd.call(void 0, 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
|
+
_chunkV46WVGWNjs.__privateMethod.call(void 0, this, _registerMessageHandlers, registerMessageHandlers_fn).call(this);
|
|
107
|
+
}
|
|
108
|
+
async enableProfileSyncing() {
|
|
109
|
+
try {
|
|
110
|
+
_chunkV46WVGWNjs.__privateMethod.call(void 0, this, _setIsProfileSyncingUpdateLoading, setIsProfileSyncingUpdateLoading_fn).call(this, true);
|
|
111
|
+
const authEnabled = _chunkV46WVGWNjs.__privateGet.call(void 0, this, _auth).isAuthEnabled();
|
|
112
|
+
if (!authEnabled) {
|
|
113
|
+
await _chunkV46WVGWNjs.__privateGet.call(void 0, this, _auth).signIn();
|
|
114
|
+
}
|
|
115
|
+
this.update((state) => {
|
|
116
|
+
state.isProfileSyncingEnabled = true;
|
|
117
|
+
});
|
|
118
|
+
_chunkV46WVGWNjs.__privateMethod.call(void 0, this, _setIsProfileSyncingUpdateLoading, setIsProfileSyncingUpdateLoading_fn).call(this, false);
|
|
119
|
+
} catch (e) {
|
|
120
|
+
_chunkV46WVGWNjs.__privateMethod.call(void 0, 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
|
+
_chunkV46WVGWNjs.__privateMethod.call(void 0, this, _setIsProfileSyncingUpdateLoading, setIsProfileSyncingUpdateLoading_fn).call(this, true);
|
|
139
|
+
const isNotificationServicesEnabled = await _chunkV46WVGWNjs.__privateGet.call(void 0, this, _notificationServices).selectIsNotificationServicesEnabled();
|
|
140
|
+
if (isNotificationServicesEnabled) {
|
|
141
|
+
await _chunkV46WVGWNjs.__privateGet.call(void 0, this, _notificationServices).disableNotificationServices();
|
|
142
|
+
}
|
|
143
|
+
const isMetaMetricsParticipation = this.getMetaMetricsState();
|
|
144
|
+
if (!isMetaMetricsParticipation) {
|
|
145
|
+
this.messagingSystem.call("AuthenticationController:performSignOut");
|
|
146
|
+
}
|
|
147
|
+
_chunkV46WVGWNjs.__privateMethod.call(void 0, this, _setIsProfileSyncingUpdateLoading, setIsProfileSyncingUpdateLoading_fn).call(this, false);
|
|
148
|
+
this.update((state) => {
|
|
149
|
+
state.isProfileSyncingEnabled = false;
|
|
150
|
+
});
|
|
151
|
+
} catch (e) {
|
|
152
|
+
_chunkV46WVGWNjs.__privateMethod.call(void 0, 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
|
+
_chunkV46WVGWNjs.__privateMethod.call(void 0, this, _assertProfileSyncingEnabled, assertProfileSyncingEnabled_fn).call(this);
|
|
168
|
+
const { bearerToken, storageKey } = await _chunkV46WVGWNjs.__privateMethod.call(void 0, this, _getStorageKeyAndBearerToken, getStorageKeyAndBearerToken_fn).call(this);
|
|
169
|
+
const result = await _chunkK6G7X6PXjs.getUserStorage.call(void 0, {
|
|
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
|
+
_chunkV46WVGWNjs.__privateMethod.call(void 0, this, _assertProfileSyncingEnabled, assertProfileSyncingEnabled_fn).call(this);
|
|
186
|
+
const { bearerToken, storageKey } = await _chunkV46WVGWNjs.__privateMethod.call(void 0, this, _getStorageKeyAndBearerToken, getStorageKeyAndBearerToken_fn).call(this);
|
|
187
|
+
await _chunkK6G7X6PXjs.upsertUserStorage.call(void 0, 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
|
+
_chunkV46WVGWNjs.__privateMethod.call(void 0, this, _assertProfileSyncingEnabled, assertProfileSyncingEnabled_fn).call(this);
|
|
200
|
+
const storageKey = await _chunkV46WVGWNjs.__privateMethod.call(void 0, 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 _chunkV46WVGWNjs.__privateGet.call(void 0, this, _auth).getBearerToken();
|
|
240
|
+
if (!bearerToken) {
|
|
241
|
+
throw new Error("UserStorageController - unable to get bearer token");
|
|
242
|
+
}
|
|
243
|
+
const storageKey = await _chunkV46WVGWNjs.__privateMethod.call(void 0, this, _createStorageKey, createStorageKey_fn).call(this);
|
|
244
|
+
return { bearerToken, storageKey };
|
|
245
|
+
};
|
|
246
|
+
_createStorageKey = new WeakSet();
|
|
247
|
+
createStorageKey_fn = async function() {
|
|
248
|
+
const id = await _chunkV46WVGWNjs.__privateGet.call(void 0, this, _auth).getProfileId();
|
|
249
|
+
if (!id) {
|
|
250
|
+
throw new Error("UserStorageController - unable to create storage key");
|
|
251
|
+
}
|
|
252
|
+
const storageKeySignature = await _chunkV46WVGWNjs.__privateMethod.call(void 0, this, _snapSignMessage, snapSignMessage_fn).call(this, `metamask:${id}`);
|
|
253
|
+
const storageKey = _chunkJWTNHCVGjs.createSHA256Hash.call(void 0, storageKeySignature);
|
|
254
|
+
return storageKey;
|
|
255
|
+
};
|
|
256
|
+
_snapSignMessage = new WeakSet();
|
|
257
|
+
snapSignMessage_fn = function(message) {
|
|
258
|
+
return this.messagingSystem.call(
|
|
259
|
+
"SnapController:handleRequest",
|
|
260
|
+
_chunkIPSBQ3MSjs.createSnapSignMessageRequest.call(void 0, message)
|
|
261
|
+
);
|
|
262
|
+
};
|
|
263
|
+
_setIsProfileSyncingUpdateLoading = new WeakSet();
|
|
264
|
+
setIsProfileSyncingUpdateLoading_fn = function(isProfileSyncingUpdateLoading) {
|
|
265
|
+
this.update((state) => {
|
|
266
|
+
state.isProfileSyncingUpdateLoading = isProfileSyncingUpdateLoading;
|
|
267
|
+
});
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
exports.UserStorageController = UserStorageController;
|
|
273
|
+
//# sourceMappingURL=chunk-ARWL2LBB.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/controllers/user-storage/UserStorageController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAIA,SAAS,sBAAsB;AA4B/B,IAAM,iBAAiB;AAcvB,IAAM,eAA2C;AAAA,EAC/C,yBAAyB;AAAA,EACzB,+BAA+B;AACjC;AAEA,IAAM,WAAsD;AAAA,E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cAAc;AAAA,IACnB;AAAA,EACF;AACF;AAKM;AAAA,iCAA4B,iBAG/B;AACD,QAAM,cAAc,MAAM,mBAAK,OAAM,eAAe;AACpD,MAAI,CAAC,aAAa;AAChB,UAAM,IAAI,MAAM,oDAAoD;AAAA,EACtE;AACA,QAAM,aAAa,MAAM,sBAAK,wCAAL;AAEzB,SAAO,EAAE,aAAa,WAAW;AACnC;AAOM;AAAA,sBAAiB,iBAAoB;AACzC,QAAM,KAAa,MAAM,mBAAK,OAAM,aAAa;AACjD,MAAI,CAAC,IAAI;AACP,UAAM,IAAI,MAAM,sDAAsD;AAAA,EACxE;AAEA,QAAM,sBAAsB,MAAM,sBAAK,sCAAL,WAAsB,YAAY,EAAE;AACtE,QAAM,aAAa,iBAAiB,mBAAmB;AACvD,SAAO;AACT;AAQA;AAAA,qBAAgB,SAAC,SAAgD;AAC/D,SAAO,KAAK,gBAAgB;AAAA,IAC1B;AAAA,IACA,6BAA6B,OAAO;AAAA,EACtC;AACF;AAEA;AAAA,sCAAiC,SAC/B,+BACM;AACN,OAAK,OAAO,CAAC,UAAU;AACrB,UAAM,gCAAgC;AAAA,EACxC,CAAC;AACH","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 { UserStorageEntryKeys } 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;\n /**\n * Loading state for the profile syncing update\n */\n isProfileSyncingUpdateLoading: boolean;\n};\n\nconst 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 entryKey - entry 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 entryKey: UserStorageEntryKeys,\n ): Promise<string | null> {\n this.#assertProfileSyncingEnabled();\n const { bearerToken, storageKey } =\n await this.#getStorageKeyAndBearerToken();\n const result = await getUserStorage({\n entryKey,\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 entryKey - entry 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 entryKey: UserStorageEntryKeys,\n value: string,\n ): Promise<void> {\n this.#assertProfileSyncingEnabled();\n const { bearerToken, storageKey } =\n await this.#getStorageKeyAndBearerToken();\n\n await upsertUserStorage(value, {\n entryKey,\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 /**\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 #snapSignMessage(message: `metamask:${string}`): Promise<string> {\n return this.messagingSystem.call(\n 'SnapController:handleRequest',\n createSnapSignMessageRequest(message),\n ) as Promise<string>;\n }\n\n #setIsProfileSyncingUpdateLoading(\n isProfileSyncingUpdateLoading: boolean,\n ): void {\n this.update((state) => {\n state.isProfileSyncingUpdateLoading = isProfileSyncingUpdateLoading;\n });\n }\n}\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import {
|
|
2
|
+
encryption_default
|
|
3
|
+
} from "./chunk-QE2F5AZL.mjs";
|
|
4
|
+
|
|
5
|
+
// src/controllers/user-storage/encryption/index.ts
|
|
6
|
+
var encryption_default2 = encryption_default;
|
|
7
|
+
|
|
8
|
+
export {
|
|
9
|
+
encryption_default2 as encryption_default
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=chunk-BFE6TB7Y.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/controllers/user-storage/encryption/index.ts"],"sourcesContent":["import Encryption from './encryption';\n\nexport { Encryption };\nexport * from './encryption';\nexport default Encryption;\n"],"mappings":";;;;;AAIA,IAAOA,sBAAQ;","names":["encryption_default"]}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkWAS6V24Hjs = require('./chunk-WAS6V24H.js');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
var _chunk2MVOZPBNjs = require('./chunk-2MVOZPBN.js');
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
var _chunkGJJT2CALjs = require('./chunk-GJJT2CAL.js');
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
var _chunkV46WVGWNjs = require('./chunk-V46WVGWN.js');
|
|
16
|
+
|
|
17
|
+
// src/controllers/authentication/index.ts
|
|
18
|
+
var authentication_exports = {};
|
|
19
|
+
_chunkV46WVGWNjs.__export.call(void 0, authentication_exports, {
|
|
20
|
+
Controller: () => _chunkWAS6V24Hjs.AuthenticationController,
|
|
21
|
+
Mocks: () => fixtures_exports
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
// src/controllers/authentication/__fixtures__/index.ts
|
|
25
|
+
var fixtures_exports = {};
|
|
26
|
+
_chunkV46WVGWNjs.__export.call(void 0, fixtures_exports, {
|
|
27
|
+
MOCK_ACCESS_TOKEN: () => MOCK_ACCESS_TOKEN,
|
|
28
|
+
MOCK_JWT: () => MOCK_JWT,
|
|
29
|
+
MOCK_LOGIN_RESPONSE: () => MOCK_LOGIN_RESPONSE,
|
|
30
|
+
MOCK_NONCE: () => MOCK_NONCE,
|
|
31
|
+
MOCK_NONCE_RESPONSE: () => MOCK_NONCE_RESPONSE,
|
|
32
|
+
MOCK_OATH_TOKEN_RESPONSE: () => MOCK_OATH_TOKEN_RESPONSE,
|
|
33
|
+
getMockAuthAccessTokenResponse: () => getMockAuthAccessTokenResponse,
|
|
34
|
+
getMockAuthLoginResponse: () => getMockAuthLoginResponse,
|
|
35
|
+
getMockAuthNonceResponse: () => getMockAuthNonceResponse,
|
|
36
|
+
mockEndpointAccessToken: () => mockEndpointAccessToken,
|
|
37
|
+
mockEndpointGetNonce: () => mockEndpointGetNonce,
|
|
38
|
+
mockEndpointLogin: () => mockEndpointLogin
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// src/controllers/authentication/__fixtures__/mockResponses.ts
|
|
42
|
+
var MOCK_NONCE = "4cbfqzoQpcNxVImGv";
|
|
43
|
+
var MOCK_NONCE_RESPONSE = {
|
|
44
|
+
nonce: MOCK_NONCE
|
|
45
|
+
};
|
|
46
|
+
var getMockAuthNonceResponse = () => {
|
|
47
|
+
return {
|
|
48
|
+
url: _chunk2MVOZPBNjs.AUTH_NONCE_ENDPOINT,
|
|
49
|
+
requestMethod: "GET",
|
|
50
|
+
response: MOCK_NONCE_RESPONSE
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
var MOCK_JWT = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c";
|
|
54
|
+
var MOCK_LOGIN_RESPONSE = {
|
|
55
|
+
token: MOCK_JWT,
|
|
56
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
57
|
+
expires_in: (/* @__PURE__ */ new Date()).toString(),
|
|
58
|
+
profile: {
|
|
59
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
60
|
+
identifier_id: "MOCK_IDENTIFIER",
|
|
61
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
62
|
+
profile_id: "MOCK_PROFILE_ID"
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
var getMockAuthLoginResponse = () => {
|
|
66
|
+
return {
|
|
67
|
+
url: _chunk2MVOZPBNjs.AUTH_LOGIN_ENDPOINT,
|
|
68
|
+
requestMethod: "POST",
|
|
69
|
+
response: MOCK_LOGIN_RESPONSE
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
var MOCK_ACCESS_TOKEN = `MOCK_ACCESS_TOKEN-${MOCK_JWT}`;
|
|
73
|
+
var MOCK_OATH_TOKEN_RESPONSE = {
|
|
74
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
75
|
+
access_token: MOCK_ACCESS_TOKEN,
|
|
76
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
77
|
+
expires_in: (/* @__PURE__ */ new Date()).getTime()
|
|
78
|
+
};
|
|
79
|
+
var getMockAuthAccessTokenResponse = () => {
|
|
80
|
+
return {
|
|
81
|
+
url: _chunk2MVOZPBNjs.OIDC_TOKENS_ENDPOINT,
|
|
82
|
+
requestMethod: "POST",
|
|
83
|
+
response: MOCK_OATH_TOKEN_RESPONSE
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
// src/controllers/authentication/__fixtures__/mockServices.ts
|
|
88
|
+
var import_nock = _chunkV46WVGWNjs.__toESM.call(void 0, _chunkGJJT2CALjs.require_nock.call(void 0, ));
|
|
89
|
+
var mockEndpointGetNonce = (mockReply) => {
|
|
90
|
+
const mockResponse = getMockAuthNonceResponse();
|
|
91
|
+
const reply = mockReply ?? { status: 200, body: mockResponse.response };
|
|
92
|
+
const mockNonceEndpoint = (0, import_nock.default)(mockResponse.url).get("").query(true).reply(reply.status, reply.body);
|
|
93
|
+
return mockNonceEndpoint;
|
|
94
|
+
};
|
|
95
|
+
var mockEndpointLogin = (mockReply) => {
|
|
96
|
+
const mockResponse = getMockAuthLoginResponse();
|
|
97
|
+
const reply = mockReply ?? { status: 200, body: mockResponse.response };
|
|
98
|
+
const mockLoginEndpoint = (0, import_nock.default)(mockResponse.url).post("").reply(reply.status, reply.body);
|
|
99
|
+
return mockLoginEndpoint;
|
|
100
|
+
};
|
|
101
|
+
var mockEndpointAccessToken = (mockReply) => {
|
|
102
|
+
const mockResponse = getMockAuthAccessTokenResponse();
|
|
103
|
+
const reply = mockReply ?? { status: 200, body: mockResponse.response };
|
|
104
|
+
const mockOidcTokensEndpoint = (0, import_nock.default)(mockResponse.url).post("").reply(reply.status, reply.body);
|
|
105
|
+
return mockOidcTokensEndpoint;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
exports.fixtures_exports = fixtures_exports; exports.authentication_exports = authentication_exports;
|
|
112
|
+
//# sourceMappingURL=chunk-BVM4HBM4.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","../src/controllers/authentication/__fixtures__/mockServices.ts"],"names":["nock"],"mappings":";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA;AAAA;AAAA;AAAA;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;;;AClEA,kBAAiB;AAaV,IAAM,uBAAuB,CAAC,cAA0B;AAC7D,QAAM,eAAe,yBAAyB;AAC9C,QAAM,QAAQ,aAAa,EAAE,QAAQ,KAAK,MAAM,aAAa,SAAS;AACtE,QAAM,wBAAoB,YAAAA,SAAK,aAAa,GAAG,EAC5C,IAAI,EAAE,EACN,MAAM,IAAI,EACV,MAAM,MAAM,QAAQ,MAAM,IAAI;AAEjC,SAAO;AACT;AAEO,IAAM,oBAAoB,CAAC,cAA0B;AAC1D,QAAM,eAAe,yBAAyB;AAC9C,QAAM,QAAQ,aAAa,EAAE,QAAQ,KAAK,MAAM,aAAa,SAAS;AACtE,QAAM,wBAAoB,YAAAA,SAAK,aAAa,GAAG,EAC5C,KAAK,EAAE,EACP,MAAM,MAAM,QAAQ,MAAM,IAAI;AAEjC,SAAO;AACT;AAEO,IAAM,0BAA0B,CAAC,cAA0B;AAChE,QAAM,eAAe,+BAA+B;AACpD,QAAM,QAAQ,aAAa,EAAE,QAAQ,KAAK,MAAM,aAAa,SAAS;AACtE,QAAM,6BAAyB,YAAAA,SAAK,aAAa,GAAG,EACjD,KAAK,EAAE,EACP,MAAM,MAAM,QAAQ,MAAM,IAAI;AAEjC,SAAO;AACT","sourcesContent":["import Controller from './AuthenticationController';\n\nexport { Controller };\nexport * from './AuthenticationController';\nexport * as Mocks from './__fixtures__';\n","export * from './mockResponses';\nexport * from './mockServices';\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","import nock from 'nock';\n\nimport {\n getMockAuthAccessTokenResponse,\n getMockAuthLoginResponse,\n getMockAuthNonceResponse,\n} from './mockResponses';\n\ntype MockReply = {\n status: nock.StatusCode;\n body?: nock.Body;\n};\n\nexport const mockEndpointGetNonce = (mockReply?: MockReply) => {\n const mockResponse = getMockAuthNonceResponse();\n const reply = mockReply ?? { status: 200, body: mockResponse.response };\n const mockNonceEndpoint = nock(mockResponse.url)\n .get('')\n .query(true)\n .reply(reply.status, reply.body);\n\n return mockNonceEndpoint;\n};\n\nexport const mockEndpointLogin = (mockReply?: MockReply) => {\n const mockResponse = getMockAuthLoginResponse();\n const reply = mockReply ?? { status: 200, body: mockResponse.response };\n const mockLoginEndpoint = nock(mockResponse.url)\n .post('')\n .reply(reply.status, reply.body);\n\n return mockLoginEndpoint;\n};\n\nexport const mockEndpointAccessToken = (mockReply?: MockReply) => {\n const mockResponse = getMockAuthAccessTokenResponse();\n const reply = mockReply ?? { status: 200, body: mockResponse.response };\n const mockOidcTokensEndpoint = nock(mockResponse.url)\n .post('')\n .reply(reply.status, reply.body);\n\n return mockOidcTokensEndpoint;\n};\n"]}
|