SHA256
Derive root/device/blockchain keys from password SHA-256
This commit is contained in:
+88
-9
@@ -1,19 +1,52 @@
|
||||
import { chatMessages, wallet } from './mock-data.js?v=20260327192619';
|
||||
import { AuthService } from './services/auth-service.js?v=20260327192619';
|
||||
|
||||
const clone = (value) => JSON.parse(JSON.stringify(value));
|
||||
const SESSION_STORAGE_KEY = 'shine-ui-current-session-v1';
|
||||
|
||||
function loadStoredSession() {
|
||||
try {
|
||||
const raw = localStorage.getItem(SESSION_STORAGE_KEY);
|
||||
if (!raw) return null;
|
||||
return JSON.parse(raw);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function persistSession(session) {
|
||||
try {
|
||||
localStorage.setItem(SESSION_STORAGE_KEY, JSON.stringify(session));
|
||||
} catch {
|
||||
// ignore quota/storage errors for prototype
|
||||
}
|
||||
}
|
||||
|
||||
function clearStoredSession() {
|
||||
try {
|
||||
localStorage.removeItem(SESSION_STORAGE_KEY);
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
const storedSession = loadStoredSession();
|
||||
|
||||
export const state = {
|
||||
chats: clone(chatMessages),
|
||||
notificationsTab: 'replies',
|
||||
pageLabelCollapsed: false,
|
||||
session: {
|
||||
isAuthorized: false,
|
||||
isAuthorized: Boolean(storedSession?.isAuthorized),
|
||||
login: storedSession?.login || '',
|
||||
sessionId: storedSession?.sessionId || '',
|
||||
storagePwdInMemory: '',
|
||||
},
|
||||
startHint: '',
|
||||
entrySettings: {
|
||||
language: 'ru',
|
||||
solanaServer: 'https://api.mainnet-beta.solana.com',
|
||||
shineServer: 'https://demo.shine.local',
|
||||
shineServer: 'wss://shineup.me/ws',
|
||||
arweaveServer: 'https://arweave.net',
|
||||
statuses: {
|
||||
solanaServer: 'idle',
|
||||
@@ -24,6 +57,8 @@ export const state = {
|
||||
registrationDraft: {
|
||||
login: '',
|
||||
password: '',
|
||||
sessionId: '',
|
||||
storagePwd: '',
|
||||
},
|
||||
loginDraft: {
|
||||
login: '',
|
||||
@@ -34,10 +69,10 @@ export const state = {
|
||||
balanceSOL: '0.0068',
|
||||
},
|
||||
keyStorage: {
|
||||
rootKey: 'RK-4Q8N-1SZP-71LM-AUTH-ROOT',
|
||||
blockchainKey: 'BK-SOL-19F2-CHAIN-ACCESS',
|
||||
deviceKey: 'DK-LOCAL-82XA-DEVICE-SIGN',
|
||||
saveRoot: false,
|
||||
rootKey: 'Ключ root хранится в зашифрованном виде',
|
||||
blockchainKey: 'Ключ blockchain хранится в зашифрованном виде',
|
||||
deviceKey: 'Ключ device хранится в зашифрованном виде',
|
||||
saveRoot: true,
|
||||
saveBlockchain: true,
|
||||
saveDevice: true,
|
||||
},
|
||||
@@ -46,8 +81,16 @@ export const state = {
|
||||
blockchain: true,
|
||||
device: true,
|
||||
},
|
||||
authUi: {
|
||||
busy: false,
|
||||
error: '',
|
||||
info: '',
|
||||
},
|
||||
sessions: [],
|
||||
};
|
||||
|
||||
export const authService = new AuthService(state.entrySettings.shineServer);
|
||||
|
||||
export function getChatMessages(chatId) {
|
||||
if (!state.chats[chatId]) {
|
||||
state.chats[chatId] = [];
|
||||
@@ -73,12 +116,12 @@ export function checkServerAvailability(address) {
|
||||
const normalized = address.trim().toLowerCase();
|
||||
if (!normalized) return 'unavailable';
|
||||
|
||||
const looksLikeUrl = /^https?:\/\/[a-z0-9.-]+/i.test(normalized);
|
||||
const looksLikeUrl = /^(https?:\/\/|wss?:\/\/)[a-z0-9.-]+/i.test(normalized);
|
||||
const blockedWord = /(offline|down|fail|bad|broken|invalid)/i.test(normalized);
|
||||
return looksLikeUrl && !blockedWord ? 'available' : 'unavailable';
|
||||
}
|
||||
|
||||
export function saveEntrySettings(nextSettings) {
|
||||
export async function saveEntrySettings(nextSettings) {
|
||||
state.entrySettings = {
|
||||
...state.entrySettings,
|
||||
...nextSettings,
|
||||
@@ -87,6 +130,7 @@ export function saveEntrySettings(nextSettings) {
|
||||
...(nextSettings.statuses || {}),
|
||||
},
|
||||
};
|
||||
await authService.reconnect(state.entrySettings.shineServer);
|
||||
state.startHint = 'Настройки входа сохранены, адреса серверов обновлены.';
|
||||
}
|
||||
|
||||
@@ -94,13 +138,48 @@ export function clearStartHint() {
|
||||
state.startHint = '';
|
||||
}
|
||||
|
||||
export function authorizeSession() {
|
||||
export function setAuthBusy(flag) {
|
||||
state.authUi.busy = flag;
|
||||
}
|
||||
|
||||
export function setAuthError(message) {
|
||||
state.authUi.error = message || '';
|
||||
}
|
||||
|
||||
export function setAuthInfo(message) {
|
||||
state.authUi.info = message || '';
|
||||
}
|
||||
|
||||
export function clearAuthMessages() {
|
||||
state.authUi.error = '';
|
||||
state.authUi.info = '';
|
||||
}
|
||||
|
||||
export function authorizeSession({ login, sessionId, storagePwd }) {
|
||||
state.session.isAuthorized = true;
|
||||
state.session.login = login;
|
||||
state.session.sessionId = sessionId;
|
||||
state.session.storagePwdInMemory = storagePwd;
|
||||
persistSession({
|
||||
isAuthorized: true,
|
||||
login,
|
||||
sessionId,
|
||||
});
|
||||
state.startHint = '';
|
||||
}
|
||||
|
||||
export async function refreshSessions() {
|
||||
state.sessions = await authService.listSessions();
|
||||
return state.sessions;
|
||||
}
|
||||
|
||||
export function terminateCurrentSession() {
|
||||
state.session.isAuthorized = false;
|
||||
state.session.login = '';
|
||||
state.session.sessionId = '';
|
||||
state.session.storagePwdInMemory = '';
|
||||
state.sessions = [];
|
||||
clearStoredSession();
|
||||
state.startHint = '';
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user