@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,70 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createEntryPath
|
|
3
|
+
} from "./chunk-772MKTIO.mjs";
|
|
4
|
+
import {
|
|
5
|
+
encryption_default
|
|
6
|
+
} from "./chunk-BFE6TB7Y.mjs";
|
|
7
|
+
import {
|
|
8
|
+
getEnvUrls
|
|
9
|
+
} from "./chunk-GLS4QZF6.mjs";
|
|
10
|
+
|
|
11
|
+
// src/controllers/user-storage/services.ts
|
|
12
|
+
import log from "loglevel";
|
|
13
|
+
var ENV_URLS = getEnvUrls("prd" /* PRD */);
|
|
14
|
+
var USER_STORAGE_API = ENV_URLS.userStorageApiUrl;
|
|
15
|
+
var USER_STORAGE_ENDPOINT = `${USER_STORAGE_API}/api/v1/userstorage`;
|
|
16
|
+
async function getUserStorage(opts) {
|
|
17
|
+
try {
|
|
18
|
+
const path = createEntryPath(opts.entryKey, opts.storageKey);
|
|
19
|
+
const url = new URL(`${USER_STORAGE_ENDPOINT}${path}`);
|
|
20
|
+
const userStorageResponse = await fetch(url.toString(), {
|
|
21
|
+
headers: {
|
|
22
|
+
"Content-Type": "application/json",
|
|
23
|
+
Authorization: `Bearer ${opts.bearerToken}`
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
if (userStorageResponse.status === 404) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
if (userStorageResponse.status !== 200) {
|
|
30
|
+
throw new Error("Unable to get User Storage");
|
|
31
|
+
}
|
|
32
|
+
const userStorage = await userStorageResponse.json();
|
|
33
|
+
const encryptedData = userStorage?.Data ?? null;
|
|
34
|
+
if (!encryptedData) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
const decryptedData = encryption_default.decryptString(
|
|
38
|
+
encryptedData,
|
|
39
|
+
opts.storageKey
|
|
40
|
+
);
|
|
41
|
+
return decryptedData;
|
|
42
|
+
} catch (e) {
|
|
43
|
+
log.error("Failed to get user storage", e);
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
async function upsertUserStorage(data, opts) {
|
|
48
|
+
const encryptedData = encryption_default.encryptString(data, opts.storageKey);
|
|
49
|
+
const path = createEntryPath(opts.entryKey, opts.storageKey);
|
|
50
|
+
const url = new URL(`${USER_STORAGE_ENDPOINT}${path}`);
|
|
51
|
+
const res = await fetch(url.toString(), {
|
|
52
|
+
method: "PUT",
|
|
53
|
+
headers: {
|
|
54
|
+
"Content-Type": "application/json",
|
|
55
|
+
Authorization: `Bearer ${opts.bearerToken}`
|
|
56
|
+
},
|
|
57
|
+
body: JSON.stringify({ data: encryptedData })
|
|
58
|
+
});
|
|
59
|
+
if (!res.ok) {
|
|
60
|
+
throw new Error("user-storage - unable to upsert data");
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export {
|
|
65
|
+
USER_STORAGE_API,
|
|
66
|
+
USER_STORAGE_ENDPOINT,
|
|
67
|
+
getUserStorage,
|
|
68
|
+
upsertUserStorage
|
|
69
|
+
};
|
|
70
|
+
//# sourceMappingURL=chunk-DHHBHLVN.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/controllers/user-storage/services.ts"],"sourcesContent":["import log from 'loglevel';\n\nimport { Env, getEnvUrls } from '../../sdk';\nimport encryption from './encryption';\nimport type { UserStorageEntryKeys } from './schema';\nimport { createEntryPath } from './schema';\n\nconst ENV_URLS = getEnvUrls(Env.PRD);\n\nexport const USER_STORAGE_API: string = ENV_URLS.userStorageApiUrl;\nexport const USER_STORAGE_ENDPOINT = `${USER_STORAGE_API}/api/v1/userstorage`;\n\n/**\n * This is the Server Response shape\n */\nexport type GetUserStorageResponse = {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n HashedKey: string;\n // eslint-disable-next-line @typescript-eslint/naming-convention\n Data: string;\n};\n\nexport type UserStorageOptions = {\n bearerToken: string;\n entryKey: UserStorageEntryKeys;\n storageKey: string;\n};\n\n/**\n * User Storage Service - Get Storage Entry.\n *\n * @param opts - User Storage Options\n * @returns The storage entry, or null if fails to find entry\n */\nexport async function getUserStorage(\n opts: UserStorageOptions,\n): Promise<string | null> {\n try {\n const path = createEntryPath(opts.entryKey, opts.storageKey);\n const url = new URL(`${USER_STORAGE_ENDPOINT}${path}`);\n\n const userStorageResponse = await fetch(url.toString(), {\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${opts.bearerToken}`,\n },\n });\n\n // Acceptable error - since indicates entry does not exist.\n if (userStorageResponse.status === 404) {\n return null;\n }\n\n if (userStorageResponse.status !== 200) {\n throw new Error('Unable to get User Storage');\n }\n\n const userStorage: GetUserStorageResponse | null =\n await userStorageResponse.json();\n const encryptedData = userStorage?.Data ?? null;\n\n if (!encryptedData) {\n return null;\n }\n\n const decryptedData = encryption.decryptString(\n encryptedData,\n opts.storageKey,\n );\n\n return decryptedData;\n } catch (e) {\n log.error('Failed to get user storage', e);\n return null;\n }\n}\n\n/**\n * User Storage Service - Set Storage Entry.\n *\n * @param data - data to store\n * @param opts - storage options\n */\nexport async function upsertUserStorage(\n data: string,\n opts: UserStorageOptions,\n): Promise<void> {\n const encryptedData = encryption.encryptString(data, opts.storageKey);\n const path = createEntryPath(opts.entryKey, opts.storageKey);\n const url = new URL(`${USER_STORAGE_ENDPOINT}${path}`);\n\n const res = await fetch(url.toString(), {\n method: 'PUT',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${opts.bearerToken}`,\n },\n body: JSON.stringify({ data: encryptedData }),\n });\n\n if (!res.ok) {\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3C;AAAA,IACA,MAAM,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAAA,EAC9C,CAAC;AAED,MAAI,CAAC,IAAI,IAAI;AACX,UAAM,IAAI,MAAM,sCAAsC;AAAA,EACxD;AACF;","names":[]}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkLHDVZNW5js = require('./chunk-LHDVZNW5.js');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunk6TK7544Ljs = require('./chunk-6TK7544L.js');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
var _chunkXUPRRLBIjs = require('./chunk-XUPRRLBI.js');
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
var _chunkMBTBE4P5js = require('./chunk-MBTBE4P5.js');
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
var _chunkV46WVGWNjs = require('./chunk-V46WVGWN.js');
|
|
21
|
+
|
|
22
|
+
// src/sdk/authentication.ts
|
|
23
|
+
var _type, _env, _sdk, _assertSIWE, assertSIWE_fn;
|
|
24
|
+
var JwtBearerAuth = class {
|
|
25
|
+
constructor(...args) {
|
|
26
|
+
_chunkV46WVGWNjs.__privateAdd.call(void 0, this, _assertSIWE);
|
|
27
|
+
_chunkV46WVGWNjs.__privateAdd.call(void 0, this, _type, void 0);
|
|
28
|
+
_chunkV46WVGWNjs.__privateAdd.call(void 0, this, _env, void 0);
|
|
29
|
+
_chunkV46WVGWNjs.__privateAdd.call(void 0, this, _sdk, void 0);
|
|
30
|
+
_chunkV46WVGWNjs.__privateSet.call(void 0, this, _type, args[0].type);
|
|
31
|
+
_chunkV46WVGWNjs.__privateSet.call(void 0, this, _env, args[0].env);
|
|
32
|
+
if (args[0].type === "SRP" /* SRP */) {
|
|
33
|
+
_chunkV46WVGWNjs.__privateSet.call(void 0, this, _sdk, new (0, _chunk6TK7544Ljs.SRPJwtBearerAuth)(args[0], args[1]));
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (args[0].type === "SiWE" /* SiWE */) {
|
|
37
|
+
_chunkV46WVGWNjs.__privateSet.call(void 0, this, _sdk, new (0, _chunkLHDVZNW5js.SIWEJwtBearerAuth)(args[0], args[1]));
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
throw new (0, _chunkMBTBE4P5js.UnsupportedAuthTypeError)("unsupported auth type");
|
|
41
|
+
}
|
|
42
|
+
async getAccessToken() {
|
|
43
|
+
return await _chunkV46WVGWNjs.__privateGet.call(void 0, this, _sdk).getAccessToken();
|
|
44
|
+
}
|
|
45
|
+
async getUserProfile() {
|
|
46
|
+
return await _chunkV46WVGWNjs.__privateGet.call(void 0, this, _sdk).getUserProfile();
|
|
47
|
+
}
|
|
48
|
+
async getIdentifier() {
|
|
49
|
+
return await _chunkV46WVGWNjs.__privateGet.call(void 0, this, _sdk).getIdentifier();
|
|
50
|
+
}
|
|
51
|
+
async signMessage(message) {
|
|
52
|
+
return await _chunkV46WVGWNjs.__privateGet.call(void 0, this, _sdk).signMessage(message);
|
|
53
|
+
}
|
|
54
|
+
async pairIdentifiers(pairing) {
|
|
55
|
+
const profile = await this.getUserProfile();
|
|
56
|
+
const n = await _chunkXUPRRLBIjs.getNonce.call(void 0, profile.profileId, _chunkV46WVGWNjs.__privateGet.call(void 0, this, _env));
|
|
57
|
+
const logins = await Promise.all(
|
|
58
|
+
pairing.map(async (p) => {
|
|
59
|
+
try {
|
|
60
|
+
const raw = `metamask:${n.nonce}:${p.identifier}`;
|
|
61
|
+
const sig = await p.signMessage(raw);
|
|
62
|
+
return {
|
|
63
|
+
signature: sig,
|
|
64
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
65
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
66
|
+
raw_message: raw,
|
|
67
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
68
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
69
|
+
encrypted_storage_key: p.encryptedStorageKey,
|
|
70
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
71
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
72
|
+
identifier_type: p.identifierType
|
|
73
|
+
};
|
|
74
|
+
} catch (e) {
|
|
75
|
+
const errorMessage = e instanceof Error ? e.message : JSON.stringify(e ?? "");
|
|
76
|
+
throw new (0, _chunkMBTBE4P5js.PairError)(
|
|
77
|
+
`failed to sign pairing message: ${errorMessage}`
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
})
|
|
81
|
+
);
|
|
82
|
+
const accessToken = await this.getAccessToken();
|
|
83
|
+
await _chunkXUPRRLBIjs.pairIdentifiers.call(void 0, n.nonce, logins, accessToken, _chunkV46WVGWNjs.__privateGet.call(void 0, this, _env));
|
|
84
|
+
}
|
|
85
|
+
prepare(signer) {
|
|
86
|
+
_chunkV46WVGWNjs.__privateMethod.call(void 0, this, _assertSIWE, assertSIWE_fn).call(this, _chunkV46WVGWNjs.__privateGet.call(void 0, this, _type), _chunkV46WVGWNjs.__privateGet.call(void 0, this, _sdk));
|
|
87
|
+
_chunkV46WVGWNjs.__privateGet.call(void 0, this, _sdk).prepare(signer);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
_type = new WeakMap();
|
|
91
|
+
_env = new WeakMap();
|
|
92
|
+
_sdk = new WeakMap();
|
|
93
|
+
_assertSIWE = new WeakSet();
|
|
94
|
+
assertSIWE_fn = function(type, sdk) {
|
|
95
|
+
if (type === "SiWE" /* SiWE */) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
throw new (0, _chunkMBTBE4P5js.UnsupportedAuthTypeError)(
|
|
99
|
+
"This method is only available via SIWE auth type"
|
|
100
|
+
);
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
|
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AAC/C,gBAAM,MAAM,MAAM,EAAE,YAAY,GAAG;AACnC,iBAAO;AAAA,YACL,WAAW;AAAA;AAAA;AAAA,YAGX,aAAa;AAAA;AAAA;AAAA,YAGb,uBAAuB,EAAE;AAAA;AAAA;AAAA,YAGzB,iBAAiB,EAAE;AAAA,UACrB;AAAA,QACF,SAAS,GAAG;AAEV,gBAAM,eACJ,aAAa,QAAQ,EAAE,UAAU,KAAK,UAAU,KAAK,EAAE;AACzD,gBAAM,IAAI;AAAA,YACR,mCAAmC,YAAY;AAAA,UACjD;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAEA,UAAM,cAAc,MAAM,KAAK,eAAe;AAC9C,UAAM,gBAAgB,EAAE,OAAO,QAAQ,aAAa,mBAAK,KAAI;AAAA,EAC/D;AAAA,EAEA,QAAQ,QAKC;AACP,0BAAK,4BAAL,WAAiB,mBAAK,QAAO,mBAAK;AAClC,uBAAK,MAAK,QAAQ,MAAM;AAAA,EAC1B;AAcF;AAjGE;AAEA;AAEA;AAiFA;AAAA,gBAAW,SACT,MACA,KACkC;AAClC,MAAI,4BAAwB;AAC1B;AAAA,EACF;AAEA,QAAM,IAAI;AAAA,IACR;AAAA,EACF;AACF","sourcesContent":["import { SIWEJwtBearerAuth } from './authentication-jwt-bearer/flow-siwe';\nimport { SRPJwtBearerAuth } from './authentication-jwt-bearer/flow-srp';\nimport {\n getNonce,\n pairIdentifiers,\n} from './authentication-jwt-bearer/services';\nimport type { UserProfile, Pair } from './authentication-jwt-bearer/types';\nimport { AuthType } from './authentication-jwt-bearer/types';\nimport type { Env } from './env';\nimport { PairError, UnsupportedAuthTypeError } from './errors';\n\n// Computing the Classes, so we only get back the public methods for the interface.\n// TODO: Either fix this lint violation or explain why it's necessary to ignore.\n// eslint-disable-next-line @typescript-eslint/naming-convention\ntype Compute<T> = T extends infer U ? { [K in keyof U]: U[K] } : never;\ntype SIWEInterface = Compute<SIWEJwtBearerAuth>;\ntype SRPInterface = Compute<SRPJwtBearerAuth>;\n\ntype SiweParams = ConstructorParameters<typeof SIWEJwtBearerAuth>;\ntype SRPParams = ConstructorParameters<typeof SRPJwtBearerAuth>;\ntype JwtBearerAuthParams = SiweParams | SRPParams;\n\nexport class JwtBearerAuth implements SIWEInterface, SRPInterface {\n #type: AuthType;\n\n #env: Env;\n\n #sdk: SIWEJwtBearerAuth | SRPJwtBearerAuth;\n\n constructor(...args: JwtBearerAuthParams) {\n this.#type = args[0].type;\n this.#env = args[0].env;\n\n if (args[0].type === AuthType.SRP) {\n this.#sdk = new SRPJwtBearerAuth(args[0], args[1]);\n return;\n }\n\n if (args[0].type === AuthType.SiWE) {\n this.#sdk = new SIWEJwtBearerAuth(args[0], args[1]);\n return;\n }\n\n throw new UnsupportedAuthTypeError('unsupported auth type');\n }\n\n async getAccessToken(): Promise<string> {\n return await this.#sdk.getAccessToken();\n }\n\n async getUserProfile(): Promise<UserProfile> {\n return await this.#sdk.getUserProfile();\n }\n\n async getIdentifier(): Promise<string> {\n return await this.#sdk.getIdentifier();\n }\n\n async signMessage(message: string): Promise<string> {\n return await this.#sdk.signMessage(message);\n }\n\n async pairIdentifiers(pairing: Pair[]): Promise<void> {\n const profile = await this.getUserProfile();\n const n = await getNonce(profile.profileId, this.#env);\n\n const logins = await Promise.all(\n pairing.map(async (p) => {\n try {\n const raw = `metamask:${n.nonce}:${p.identifier}`;\n const sig = await p.signMessage(raw);\n return {\n signature: sig,\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n raw_message: raw,\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n encrypted_storage_key: p.encryptedStorageKey,\n // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n identifier_type: p.identifierType,\n };\n } catch (e) {\n /* istanbul ignore next */\n const errorMessage =\n e instanceof Error ? e.message : JSON.stringify(e ?? '');\n throw new PairError(\n `failed to sign pairing message: ${errorMessage}`,\n );\n }\n }),\n );\n\n const accessToken = await this.getAccessToken();\n await pairIdentifiers(n.nonce, logins, accessToken, this.#env);\n }\n\n prepare(signer: {\n address: string;\n chainId: number;\n signMessage: (message: string) => Promise<string>;\n domain: string;\n }): void {\n this.#assertSIWE(this.#type, this.#sdk);\n this.#sdk.prepare(signer);\n }\n\n #assertSIWE(\n type: AuthType,\n sdk: SIWEJwtBearerAuth | SRPJwtBearerAuth,\n ): asserts sdk is SIWEJwtBearerAuth {\n if (type === AuthType.SiWE) {\n return;\n }\n\n throw new UnsupportedAuthTypeError(\n 'This method is only available via SIWE auth type',\n );\n }\n}\n\nexport { SIWEJwtBearerAuth } from './authentication-jwt-bearer/flow-siwe';\nexport { SRPJwtBearerAuth } from './authentication-jwt-bearer/flow-srp';\nexport * from './authentication-jwt-bearer/types';\n"]}
|