import { t } from '../i18n/index.js'; /** Разделённые шаги V2: независимая проверка логина, затем email. */ import { authService } from '../state.js'; import { normalizeFullLogin } from './shine-namespace-service.js'; async function call(op, payload = {}) { const response = await authService.ws.request(op, payload, op==='ConfirmFreeRegistration'?150000:18000); if (response.status !== 200 || response.ok === false) { const error=new Error(response.message || response.error || t('remaining.registration_api.server_error', { op })); error.code=response.error || 'REGISTRATION_REQUEST_FAILED'; throw error; } return response.payload || {}; } export const getRegistrationNamespaces = () => call('GetNamespaces'); export const checkRegistrationLogin = (fullLogin) => call('CheckRegistrationLogin', { fullLogin: normalizeFullLogin(fullLogin) }); export const checkRegistrationEmail = (email) => call('CheckRegistrationEmail', { email }); export const startFreeRegistration = ({ fullLogin, keyBundle, email }) => call('StartFreeRegistration', { fullLogin: normalizeFullLogin(fullLogin), email, rootPublicKeyB64: keyBundle.rootPair.publicKeyB64, blockchainPublicKeyB64: keyBundle.blockchainPair.publicKeyB64, clientPublicKeyB64: keyBundle.clientPair.publicKeyB64, }); export const confirmFreeRegistration = (challengeId, code) => call('ConfirmFreeRegistration',{challengeId,code}); export const getRegistrationStatus = (fullLogin) => call('GetRegistrationStatus',{fullLogin: normalizeFullLogin(fullLogin)});