@metamask-previews/profile-sync-controller 27.1.0-preview-378ea32e1 → 27.1.0-preview-1c2b324fd
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 +0 -9
- package/dist/controllers/authentication/AuthenticationController.cjs +27 -32
- package/dist/controllers/authentication/AuthenticationController.cjs.map +1 -1
- package/dist/controllers/authentication/AuthenticationController.d.cts +1 -1
- package/dist/controllers/authentication/AuthenticationController.d.cts.map +1 -1
- package/dist/controllers/authentication/AuthenticationController.d.mts +1 -1
- package/dist/controllers/authentication/AuthenticationController.d.mts.map +1 -1
- package/dist/controllers/authentication/AuthenticationController.mjs +27 -32
- package/dist/controllers/authentication/AuthenticationController.mjs.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/flow-siwe.cjs +1 -1
- package/dist/sdk/authentication-jwt-bearer/flow-siwe.cjs.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/flow-siwe.d.cts +1 -1
- package/dist/sdk/authentication-jwt-bearer/flow-siwe.d.cts.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/flow-siwe.d.mts +1 -1
- package/dist/sdk/authentication-jwt-bearer/flow-siwe.d.mts.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/flow-siwe.mjs +1 -1
- package/dist/sdk/authentication-jwt-bearer/flow-siwe.mjs.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/flow-srp.cjs +9 -6
- package/dist/sdk/authentication-jwt-bearer/flow-srp.cjs.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/flow-srp.d.cts +1 -1
- package/dist/sdk/authentication-jwt-bearer/flow-srp.d.cts.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/flow-srp.d.mts +1 -1
- package/dist/sdk/authentication-jwt-bearer/flow-srp.d.mts.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/flow-srp.mjs +9 -6
- package/dist/sdk/authentication-jwt-bearer/flow-srp.mjs.map +1 -1
- package/dist/sdk/authentication.cjs +2 -2
- package/dist/sdk/authentication.cjs.map +1 -1
- package/dist/sdk/authentication.d.cts +1 -1
- package/dist/sdk/authentication.d.cts.map +1 -1
- package/dist/sdk/authentication.d.mts +1 -1
- package/dist/sdk/authentication.d.mts.map +1 -1
- package/dist/sdk/authentication.mjs +2 -2
- package/dist/sdk/authentication.mjs.map +1 -1
- package/dist/sdk/mocks/auth.cjs +1 -1
- package/dist/sdk/mocks/auth.cjs.map +1 -1
- package/dist/sdk/mocks/auth.d.cts +1 -1
- package/dist/sdk/mocks/auth.d.cts.map +1 -1
- package/dist/sdk/mocks/auth.d.mts +1 -1
- package/dist/sdk/mocks/auth.d.mts.map +1 -1
- package/dist/sdk/mocks/auth.mjs +1 -1
- package/dist/sdk/mocks/auth.mjs.map +1 -1
- package/dist/sdk/utils/validate-login-response.cjs +3 -30
- package/dist/sdk/utils/validate-login-response.cjs.map +1 -1
- package/dist/sdk/utils/validate-login-response.d.cts +3 -7
- package/dist/sdk/utils/validate-login-response.d.cts.map +1 -1
- package/dist/sdk/utils/validate-login-response.d.mts +3 -7
- package/dist/sdk/utils/validate-login-response.d.mts.map +1 -1
- package/dist/sdk/utils/validate-login-response.mjs +3 -30
- package/dist/sdk/utils/validate-login-response.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -2,15 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.validateLoginResponse = void 0;
|
|
4
4
|
/**
|
|
5
|
-
* Validates
|
|
6
|
-
*
|
|
7
|
-
* Checks structural shape (token + profile objects exist) and verifies
|
|
8
|
-
* the JWT access token's `exp` claim is still in the future. This acts
|
|
9
|
-
* as a hard guard against stale cached tokens regardless of client-side
|
|
10
|
-
* TTL tracking (obtainedAt / expiresIn), which can be corrupted.
|
|
5
|
+
* Validates Shape is LoginResponse
|
|
6
|
+
* NOTE - validation is pretty loose, we can improve this by using external libs like Zod for improved/tighter validation
|
|
11
7
|
*
|
|
12
8
|
* @param input - unknown/untyped input
|
|
13
|
-
* @returns boolean if input is
|
|
9
|
+
* @returns boolean if input is LoginResponse
|
|
14
10
|
*/
|
|
15
11
|
function validateLoginResponse(input) {
|
|
16
12
|
const assumedInput = input;
|
|
@@ -20,30 +16,7 @@ function validateLoginResponse(input) {
|
|
|
20
16
|
if (!assumedInput?.token || !assumedInput?.profile) {
|
|
21
17
|
return false;
|
|
22
18
|
}
|
|
23
|
-
if (isJwtExpired(assumedInput.token.accessToken)) {
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
19
|
return true;
|
|
27
20
|
}
|
|
28
21
|
exports.validateLoginResponse = validateLoginResponse;
|
|
29
|
-
/**
|
|
30
|
-
* Checks whether a JWT has expired by decoding its `exp` claim.
|
|
31
|
-
*
|
|
32
|
-
* @param token - A JWT string.
|
|
33
|
-
* @returns true if the token is expired or cannot be decoded; false if still valid.
|
|
34
|
-
*/
|
|
35
|
-
function isJwtExpired(token) {
|
|
36
|
-
try {
|
|
37
|
-
const parts = token.split('.');
|
|
38
|
-
if (parts.length !== 3) {
|
|
39
|
-
return true;
|
|
40
|
-
}
|
|
41
|
-
const base64 = parts[1].replace(/-/gu, '+').replace(/_/gu, '/');
|
|
42
|
-
const { exp } = JSON.parse(atob(base64));
|
|
43
|
-
return typeof exp !== 'number' || exp * 1000 <= Date.now();
|
|
44
|
-
}
|
|
45
|
-
catch {
|
|
46
|
-
return true;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
22
|
//# sourceMappingURL=validate-login-response.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate-login-response.cjs","sourceRoot":"","sources":["../../../src/sdk/utils/validate-login-response.ts"],"names":[],"mappings":";;;AAEA
|
|
1
|
+
{"version":3,"file":"validate-login-response.cjs","sourceRoot":"","sources":["../../../src/sdk/utils/validate-login-response.ts"],"names":[],"mappings":";;;AAEA;;;;;;GAMG;AACH,SAAgB,qBAAqB,CAAC,KAAc;IAClD,MAAM,YAAY,GAAG,KAAsB,CAAC;IAE5C,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,CAAC,YAAY,EAAE,KAAK,IAAI,CAAC,YAAY,EAAE,OAAO,EAAE,CAAC;QACnD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAZD,sDAYC","sourcesContent":["import type { LoginResponse } from '../authentication';\n\n/**\n * Validates Shape is LoginResponse\n * NOTE - validation is pretty loose, we can improve this by using external libs like Zod for improved/tighter validation\n *\n * @param input - unknown/untyped input\n * @returns boolean if input is LoginResponse\n */\nexport function validateLoginResponse(input: unknown): input is LoginResponse {\n const assumedInput = input as LoginResponse;\n\n if (!assumedInput) {\n return false;\n }\n\n if (!assumedInput?.token || !assumedInput?.profile) {\n return false;\n }\n\n return true;\n}\n"]}
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import type { LoginResponse } from "../authentication.cjs";
|
|
2
2
|
/**
|
|
3
|
-
* Validates
|
|
4
|
-
*
|
|
5
|
-
* Checks structural shape (token + profile objects exist) and verifies
|
|
6
|
-
* the JWT access token's `exp` claim is still in the future. This acts
|
|
7
|
-
* as a hard guard against stale cached tokens regardless of client-side
|
|
8
|
-
* TTL tracking (obtainedAt / expiresIn), which can be corrupted.
|
|
3
|
+
* Validates Shape is LoginResponse
|
|
4
|
+
* NOTE - validation is pretty loose, we can improve this by using external libs like Zod for improved/tighter validation
|
|
9
5
|
*
|
|
10
6
|
* @param input - unknown/untyped input
|
|
11
|
-
* @returns boolean if input is
|
|
7
|
+
* @returns boolean if input is LoginResponse
|
|
12
8
|
*/
|
|
13
9
|
export declare function validateLoginResponse(input: unknown): input is LoginResponse;
|
|
14
10
|
//# sourceMappingURL=validate-login-response.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate-login-response.d.cts","sourceRoot":"","sources":["../../../src/sdk/utils/validate-login-response.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,8BAA0B;AAEvD
|
|
1
|
+
{"version":3,"file":"validate-login-response.d.cts","sourceRoot":"","sources":["../../../src/sdk/utils/validate-login-response.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,8BAA0B;AAEvD;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,aAAa,CAY5E"}
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import type { LoginResponse } from "../authentication.mjs";
|
|
2
2
|
/**
|
|
3
|
-
* Validates
|
|
4
|
-
*
|
|
5
|
-
* Checks structural shape (token + profile objects exist) and verifies
|
|
6
|
-
* the JWT access token's `exp` claim is still in the future. This acts
|
|
7
|
-
* as a hard guard against stale cached tokens regardless of client-side
|
|
8
|
-
* TTL tracking (obtainedAt / expiresIn), which can be corrupted.
|
|
3
|
+
* Validates Shape is LoginResponse
|
|
4
|
+
* NOTE - validation is pretty loose, we can improve this by using external libs like Zod for improved/tighter validation
|
|
9
5
|
*
|
|
10
6
|
* @param input - unknown/untyped input
|
|
11
|
-
* @returns boolean if input is
|
|
7
|
+
* @returns boolean if input is LoginResponse
|
|
12
8
|
*/
|
|
13
9
|
export declare function validateLoginResponse(input: unknown): input is LoginResponse;
|
|
14
10
|
//# sourceMappingURL=validate-login-response.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate-login-response.d.mts","sourceRoot":"","sources":["../../../src/sdk/utils/validate-login-response.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,8BAA0B;AAEvD
|
|
1
|
+
{"version":3,"file":"validate-login-response.d.mts","sourceRoot":"","sources":["../../../src/sdk/utils/validate-login-response.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,8BAA0B;AAEvD;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,aAAa,CAY5E"}
|
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Validates
|
|
3
|
-
*
|
|
4
|
-
* Checks structural shape (token + profile objects exist) and verifies
|
|
5
|
-
* the JWT access token's `exp` claim is still in the future. This acts
|
|
6
|
-
* as a hard guard against stale cached tokens regardless of client-side
|
|
7
|
-
* TTL tracking (obtainedAt / expiresIn), which can be corrupted.
|
|
2
|
+
* Validates Shape is LoginResponse
|
|
3
|
+
* NOTE - validation is pretty loose, we can improve this by using external libs like Zod for improved/tighter validation
|
|
8
4
|
*
|
|
9
5
|
* @param input - unknown/untyped input
|
|
10
|
-
* @returns boolean if input is
|
|
6
|
+
* @returns boolean if input is LoginResponse
|
|
11
7
|
*/
|
|
12
8
|
export function validateLoginResponse(input) {
|
|
13
9
|
const assumedInput = input;
|
|
@@ -17,29 +13,6 @@ export function validateLoginResponse(input) {
|
|
|
17
13
|
if (!assumedInput?.token || !assumedInput?.profile) {
|
|
18
14
|
return false;
|
|
19
15
|
}
|
|
20
|
-
if (isJwtExpired(assumedInput.token.accessToken)) {
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
16
|
return true;
|
|
24
17
|
}
|
|
25
|
-
/**
|
|
26
|
-
* Checks whether a JWT has expired by decoding its `exp` claim.
|
|
27
|
-
*
|
|
28
|
-
* @param token - A JWT string.
|
|
29
|
-
* @returns true if the token is expired or cannot be decoded; false if still valid.
|
|
30
|
-
*/
|
|
31
|
-
function isJwtExpired(token) {
|
|
32
|
-
try {
|
|
33
|
-
const parts = token.split('.');
|
|
34
|
-
if (parts.length !== 3) {
|
|
35
|
-
return true;
|
|
36
|
-
}
|
|
37
|
-
const base64 = parts[1].replace(/-/gu, '+').replace(/_/gu, '/');
|
|
38
|
-
const { exp } = JSON.parse(atob(base64));
|
|
39
|
-
return typeof exp !== 'number' || exp * 1000 <= Date.now();
|
|
40
|
-
}
|
|
41
|
-
catch {
|
|
42
|
-
return true;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
18
|
//# sourceMappingURL=validate-login-response.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate-login-response.mjs","sourceRoot":"","sources":["../../../src/sdk/utils/validate-login-response.ts"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"validate-login-response.mjs","sourceRoot":"","sources":["../../../src/sdk/utils/validate-login-response.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CAAC,KAAc;IAClD,MAAM,YAAY,GAAG,KAAsB,CAAC;IAE5C,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,CAAC,YAAY,EAAE,KAAK,IAAI,CAAC,YAAY,EAAE,OAAO,EAAE,CAAC;QACnD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import type { LoginResponse } from '../authentication';\n\n/**\n * Validates Shape is LoginResponse\n * NOTE - validation is pretty loose, we can improve this by using external libs like Zod for improved/tighter validation\n *\n * @param input - unknown/untyped input\n * @returns boolean if input is LoginResponse\n */\nexport function validateLoginResponse(input: unknown): input is LoginResponse {\n const assumedInput = input as LoginResponse;\n\n if (!assumedInput) {\n return false;\n }\n\n if (!assumedInput?.token || !assumedInput?.profile) {\n return false;\n }\n\n return true;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/profile-sync-controller",
|
|
3
|
-
"version": "27.1.0-preview-
|
|
3
|
+
"version": "27.1.0-preview-1c2b324fd",
|
|
4
4
|
"description": "The profile sync helps developers synchronize data across multiple clients and devices in a privacy-preserving way. All data saved in the user storage database is encrypted client-side to preserve privacy. The user storage provides a modular design, giving developers the flexibility to construct and manage their storage spaces in a way that best suits their needs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|