@toruslabs/session-manager
Advanced tools
@@ -64,6 +64,23 @@ 'use strict'; | ||
| // session id must be a hex string | ||
| metadataHelpers.assert(metadataHelpers.isHexString(tokens.session_id), "Session id must be a hex string"); | ||
| this._sessionId = metadataHelpers.add0x(util.padHexString(tokens.session_id)); | ||
| this.accessToken = tokens.access_token; | ||
| await Promise.all([this.storage.sessionId.set(this.sessionIdKey, this._sessionId), this.storage.accessToken.set(this.accessTokenKey, tokens.access_token), this.storage.refreshToken.set(this.refreshTokenKey, tokens.refresh_token), this.storage.idToken.set(this.idTokenKey, tokens.id_token)]); | ||
| if (tokens.sessionId) { | ||
| metadataHelpers.assert(metadataHelpers.isHexString(tokens.sessionId), "Session id must be a hex string"); | ||
| this._sessionId = metadataHelpers.add0x(util.padHexString(tokens.sessionId)); | ||
| } | ||
| if (tokens.accessToken) { | ||
| this.accessToken = tokens.accessToken; | ||
| } | ||
| const promises = []; | ||
| if (tokens.sessionId) { | ||
| promises.push(this.storage.sessionId.set(this.sessionIdKey, this._sessionId)); | ||
| } | ||
| if (tokens.accessToken) { | ||
| promises.push(this.storage.accessToken.set(this.accessTokenKey, tokens.accessToken)); | ||
| } | ||
| if (tokens.refreshToken) { | ||
| promises.push(this.storage.refreshToken.set(this.refreshTokenKey, tokens.refreshToken)); | ||
| } | ||
| if (tokens.idToken) { | ||
| promises.push(this.storage.idToken.set(this.idTokenKey, tokens.idToken)); | ||
| } | ||
| await Promise.all(promises); | ||
| } | ||
@@ -70,0 +87,0 @@ async setAccessToken(token) { |
@@ -11,6 +11,6 @@ import { Hex } from "@toruslabs/metadata-helpers"; | ||
| export interface AuthTokens { | ||
| session_id: Hex; | ||
| access_token: string; | ||
| refresh_token: string; | ||
| id_token: string; | ||
| sessionId?: Hex; | ||
| accessToken?: string; | ||
| refreshToken?: string; | ||
| idToken?: string; | ||
| } | ||
@@ -17,0 +17,0 @@ /** |
@@ -62,6 +62,23 @@ import _defineProperty from '@babel/runtime/helpers/defineProperty'; | ||
| // session id must be a hex string | ||
| assert(isHexString(tokens.session_id), "Session id must be a hex string"); | ||
| this._sessionId = add0x(padHexString(tokens.session_id)); | ||
| this.accessToken = tokens.access_token; | ||
| await Promise.all([this.storage.sessionId.set(this.sessionIdKey, this._sessionId), this.storage.accessToken.set(this.accessTokenKey, tokens.access_token), this.storage.refreshToken.set(this.refreshTokenKey, tokens.refresh_token), this.storage.idToken.set(this.idTokenKey, tokens.id_token)]); | ||
| if (tokens.sessionId) { | ||
| assert(isHexString(tokens.sessionId), "Session id must be a hex string"); | ||
| this._sessionId = add0x(padHexString(tokens.sessionId)); | ||
| } | ||
| if (tokens.accessToken) { | ||
| this.accessToken = tokens.accessToken; | ||
| } | ||
| const promises = []; | ||
| if (tokens.sessionId) { | ||
| promises.push(this.storage.sessionId.set(this.sessionIdKey, this._sessionId)); | ||
| } | ||
| if (tokens.accessToken) { | ||
| promises.push(this.storage.accessToken.set(this.accessTokenKey, tokens.accessToken)); | ||
| } | ||
| if (tokens.refreshToken) { | ||
| promises.push(this.storage.refreshToken.set(this.refreshTokenKey, tokens.refreshToken)); | ||
| } | ||
| if (tokens.idToken) { | ||
| promises.push(this.storage.idToken.set(this.idTokenKey, tokens.idToken)); | ||
| } | ||
| await Promise.all(promises); | ||
| } | ||
@@ -68,0 +85,0 @@ async setAccessToken(token) { |
+5
-5
| { | ||
| "name": "@toruslabs/session-manager", | ||
| "version": "5.4.0", | ||
| "version": "5.5.0", | ||
| "description": "session manager web", | ||
@@ -31,3 +31,3 @@ "sideEffects": false, | ||
| "@babel/register": "^7.28.6", | ||
| "@babel/runtime": "^7.28.6", | ||
| "@babel/runtime": "^7.29.2", | ||
| "@toruslabs/config": "^4.0.0", | ||
@@ -38,11 +38,11 @@ "@toruslabs/eslint-config-typescript": "^5.0.1", | ||
| "@types/node": "^25", | ||
| "@vitest/coverage-istanbul": "^4.0.18", | ||
| "@vitest/coverage-istanbul": "^4.1.0", | ||
| "cross-env": "^10.1.0", | ||
| "eslint": "^9.39.2", | ||
| "husky": "^9.1.7", | ||
| "lint-staged": "^16.3.2", | ||
| "lint-staged": "^16.4.0", | ||
| "prettier": "^3.8.1", | ||
| "rimraf": "^6.1.3", | ||
| "typescript": "^5.9.3", | ||
| "vitest": "^4.0.18" | ||
| "vitest": "^4.1.0" | ||
| }, | ||
@@ -49,0 +49,0 @@ "optionalDependencies": { |
@@ -31,6 +31,6 @@ import { post } from "@toruslabs/http-helpers"; | ||
| const TEST_TOKENS: AuthTokens = { | ||
| session_id: "0x0000000000123456789012345678901234567890123456789012345678901234", | ||
| access_token: "test-access-token", | ||
| refresh_token: "test-refresh-token", | ||
| id_token: "test-id-token", | ||
| sessionId: "0x0000000000123456789012345678901234567890123456789012345678901234", | ||
| accessToken: "test-access-token", | ||
| refreshToken: "test-refresh-token", | ||
| idToken: "test-id-token", | ||
| }; | ||
@@ -69,3 +69,3 @@ | ||
| expect(await memStorage.get(`w3a:${STORAGE_KEYS.SESSION_ID}`)).toBe(TEST_TOKENS.session_id); | ||
| expect(await memStorage.get(`w3a:${STORAGE_KEYS.SESSION_ID}`)).toBe(TEST_TOKENS.sessionId); | ||
| expect(await memStorage.get(`w3a:${STORAGE_KEYS.ACCESS_TOKEN}`)).toBe("test-access-token"); | ||
@@ -84,3 +84,3 @@ expect(await memStorage.get(`w3a:${STORAGE_KEYS.REFRESH_TOKEN}`)).toBe("test-refresh-token"); | ||
| expect(await session.getIdToken()).toBe("test-id-token"); | ||
| expect(await session.getSessionId()).toBe(TEST_TOKENS.session_id); | ||
| expect(await session.getSessionId()).toBe(TEST_TOKENS.sessionId); | ||
| }); | ||
@@ -151,3 +151,3 @@ | ||
| expect(state.isAuthenticated).toBe(false); | ||
| expect(state.sessionId).toBe(TEST_TOKENS.session_id); | ||
| expect(state.sessionId).toBe(TEST_TOKENS.sessionId); | ||
| }); | ||
@@ -210,3 +210,3 @@ | ||
| expect(mockPost).toHaveBeenCalledTimes(1); | ||
| expect(mockDecryptData).toHaveBeenCalledWith(mockHexToBytes(TEST_TOKENS.session_id), "encrypted-session-data"); | ||
| expect(mockDecryptData).toHaveBeenCalledWith(mockHexToBytes(TEST_TOKENS.sessionId), "encrypted-session-data"); | ||
| expect(await apiSession.getAccessToken()).toBe("new-access-token"); | ||
@@ -222,3 +222,3 @@ }); | ||
| expect(mockDecryptData).toHaveBeenCalledWith(mockHexToBytes(TEST_TOKENS.session_id), "encrypted-session-data"); | ||
| expect(mockDecryptData).toHaveBeenCalledWith(mockHexToBytes(TEST_TOKENS.sessionId), "encrypted-session-data"); | ||
| }); | ||
@@ -225,0 +225,0 @@ |
@@ -18,6 +18,6 @@ import { get as httpGet, patch as httpPatch, post as httpPost, put as httpPut, remove as httpDelete } from "@toruslabs/http-helpers"; | ||
| const TEST_TOKENS: AuthTokens = { | ||
| session_id: "0x0000000000123456789012345678901234567890123456789012345678901234", | ||
| access_token: "test-access-token", | ||
| refresh_token: "test-refresh-token", | ||
| id_token: "test-id-token", | ||
| sessionId: "0x0000000000123456789012345678901234567890123456789012345678901234", | ||
| accessToken: "test-access-token", | ||
| refreshToken: "test-refresh-token", | ||
| idToken: "test-id-token", | ||
| }; | ||
@@ -24,0 +24,0 @@ |
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
149061
0.43%3461
0.93%