Сделал адекватное отображение ключей / и при регистрации ключи спрашивают какие сохранять

(что то работает что то сложно)
This commit is contained in:
AidarKC
2026-03-30 03:11:09 +03:00
parent 089146a137
commit eb5593c7be
35 changed files with 396 additions and 247 deletions
+110 -68
View File
@@ -1,8 +1,15 @@
import { chatMessages, wallet } from './mock-data.js?v=20260327192619';
import { AuthService } from './services/auth-service.js?v=20260327192619';
import { chatMessages, wallet } from './mock-data.js?v=20260330001044';
import { AuthService } from './services/auth-service.js?v=20260330001044';
import { clearClientAuthData } from './services/key-vault.js?v=20260330001044';
const clone = (value) => JSON.parse(JSON.stringify(value));
const SESSION_STORAGE_KEY = 'shine-ui-current-session-v1';
const INVALID_SESSION_CODES = new Set([
'NOT_AUTHENTICATED',
'SESSION_NOT_FOUND',
'SESSION_KEY_NOT_ACTUAL',
'SESSION_OF_ANOTHER_USER',
]);
function loadStoredSession() {
try {
@@ -30,68 +37,73 @@ function clearStoredSession() {
}
}
const storedSession = loadStoredSession();
export const state = {
chats: clone(chatMessages),
notificationsTab: 'replies',
pageLabelCollapsed: false,
session: {
isAuthorized: false,
login: storedSession?.login || '',
sessionId: storedSession?.sessionId || '',
storagePwdInMemory: '',
},
startHint: '',
entrySettings: {
language: 'ru',
solanaServer: 'https://api.mainnet-beta.solana.com',
shineServer: 'wss://shineup.me/ws',
arweaveServer: 'https://arweave.net',
statuses: {
solanaServer: 'idle',
shineServer: 'idle',
arweaveServer: 'idle',
function createInitialState({ withStoredSession = true } = {}) {
const storedSession = withStoredSession ? loadStoredSession() : null;
return {
chats: clone(chatMessages),
notificationsTab: 'replies',
pageLabelCollapsed: false,
session: {
isAuthorized: false,
login: storedSession?.login || '',
sessionId: storedSession?.sessionId || '',
storagePwdInMemory: '',
},
},
registrationDraft: {
login: '',
password: '',
sessionId: '',
storagePwd: '',
pendingKeyBundle: null,
pendingSessionMaterial: null,
},
loginDraft: {
login: storedSession?.login || '',
password: '',
},
registrationPayment: {
walletAddress: wallet.publicAddress,
balanceSOL: '0.0068',
},
keyStorage: {
rootKey: 'Ключ root хранится в зашифрованном виде',
blockchainKey: 'Ключ blockchain хранится в зашифрованном виде',
deviceKey: 'Ключ device хранится в зашифрованном виде',
saveRoot: true,
saveBlockchain: true,
saveDevice: true,
},
deviceConnect: {
root: true,
blockchain: true,
device: true,
},
authUi: {
busy: false,
error: '',
info: '',
},
sessions: [],
};
startHint: '',
entrySettings: {
language: 'ru',
solanaServer: 'https://api.mainnet-beta.solana.com',
shineServer: 'wss://shineup.me/ws',
arweaveServer: 'https://arweave.net',
statuses: {
solanaServer: 'idle',
shineServer: 'idle',
arweaveServer: 'idle',
},
},
registrationDraft: {
flowType: '',
login: '',
password: '',
sessionId: '',
storagePwd: '',
pendingKeyBundle: null,
pendingSessionMaterial: null,
},
loginDraft: {
login: storedSession?.login || '',
password: '',
},
registrationPayment: {
walletAddress: wallet.publicAddress,
balanceSOL: '0.0068',
},
keyStorage: {
rootKey: 'Ключ root хранится в зашифрованном виде',
blockchainKey: 'Ключ blockchain хранится в зашифрованном виде',
deviceKey: 'Ключ device хранится в зашифрованном виде',
saveRoot: false,
saveBlockchain: true,
saveDevice: true,
},
deviceConnect: {
root: true,
blockchain: true,
device: true,
},
authUi: {
busy: false,
error: '',
info: '',
},
sessions: [],
};
}
export const state = createInitialState();
export const authService = new AuthService(state.entrySettings.shineServer);
let onSessionReset = null;
export function getChatMessages(chatId) {
if (!state.chats[chatId]) {
@@ -170,19 +182,49 @@ export function authorizeSession({ login, sessionId, storagePwd }) {
state.startHint = '';
}
export function setSessionResetHandler(handler) {
onSessionReset = typeof handler === 'function' ? handler : null;
}
export function isSessionInvalidError(error) {
return INVALID_SESSION_CODES.has(error?.code);
}
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 = [];
function resetStateForSignedOut() {
const next = createInitialState({ withStoredSession: false });
state.chats = next.chats;
state.notificationsTab = next.notificationsTab;
state.session = next.session;
state.startHint = next.startHint;
state.registrationDraft = next.registrationDraft;
state.loginDraft = next.loginDraft;
state.registrationPayment = next.registrationPayment;
state.keyStorage = next.keyStorage;
state.deviceConnect = next.deviceConnect;
state.authUi = next.authUi;
state.sessions = next.sessions;
}
export async function terminateCurrentSession({ infoMessage = '' } = {}) {
clearStoredSession();
state.startHint = '';
resetStateForSignedOut();
authService.close();
try {
await clearClientAuthData();
} catch {
// ignore cleanup errors in prototype mode
}
if (infoMessage) {
state.startHint = infoMessage;
}
if (onSessionReset) {
onSessionReset();
}
}
export function refreshRegistrationBalance() {