Обновить shine-users и синхронизацию пользователей

This commit is contained in:
AidarKC
2026-11-18 15:28:07 +03:00
parent 780ca53931
commit 76bbc9d023
24 changed files with 503 additions and 278 deletions
+8 -1
View File
@@ -482,10 +482,12 @@ export function render({navigate, chrome}) {
saved = null;
}
const savedRoot = String(saved?.rootKey || '').trim();
const savedBlockchain = String(saved?.blockchainKey || '').trim();
const savedClient = String(saved?.clientKey || '').trim();
if (savedBlockchain && savedClient) {
if (savedRoot && savedBlockchain && savedClient) {
return {
rootPrivatePkcs8B64: savedRoot,
blockchainPrivatePkcs8B64: savedBlockchain,
clientPrivatePkcs8B64: savedClient,
payerAddress: await clientAddressFromPrivatePkcs8(savedBlockchain),
@@ -513,10 +515,14 @@ export function render({navigate, chrome}) {
if (!equalBytes(derivedClientPublic, currentPda.clientKey)) {
throw new Error(t('screens.access_servers_view.text_013'));
}
if (!equalBytes(base64ToBytes(keyBundle.rootPair.publicKeyB64), currentPda.rootKey)) {
throw new Error('Root Key не соответствует PDA');
}
await authService.persistSelectedKeys(sessionLogin, storagePwd, keyBundle);
return {
rootPrivatePkcs8B64: keyBundle.rootPair.privatePkcs8B64,
blockchainPrivatePkcs8B64: keyBundle.blockchainPair.privatePkcs8B64,
clientPrivatePkcs8B64: keyBundle.clientPair.privatePkcs8B64,
payerAddress: clientAddressFromPublicB64(keyBundle.blockchainPair.publicKeyB64),
@@ -546,6 +552,7 @@ export function render({navigate, chrome}) {
const tx = await updateShineUserPdaOnSolana({
login: sessionLogin,
solanaEndpoint,
rootPrivatePkcs8B64: signingMaterial.rootPrivatePkcs8B64,
blockchainPrivatePkcs8B64: signingMaterial.blockchainPrivatePkcs8B64,
clientPrivatePkcs8B64: signingMaterial.clientPrivatePkcs8B64,
accessServers: normalizedList,
+7 -42
View File
@@ -21,10 +21,7 @@ import { getUsdtBalance, getUsdtAsset } from '../services/solana-usdt-service.js
import { openArweaveAttachmentManager } from '../components/arweave-attachment-manager.js';
import { buildArweaveDataUrl, sha256HexFromArrayBuffer } from '../services/arweave-file-service.js';
import {
calcLimitTopupPriceLamports,
getLimitStepBytes,
getShineBlockchainUsage,
getShineUsersEconomyConfig,
updateShineUserPdaOnSolana,
} from '../services/shine-blockchain-wallet-service.js?v=202605300007';
import {
@@ -71,16 +68,6 @@ function lamportsToSolText(lamportsBigInt) {
return formatNumber(value, { minimumFractionDigits: 0, maximumFractionDigits: 9 });
}
function formatLimitTopupError(error) {
const message = String(error?.message || '').trim();
const logs = Array.isArray(error?.logs) ? error.logs.join(' | ') : '';
const haystack = `${message} ${logs}`.toLowerCase();
if (haystack.includes('insufficient funds for rent')) {
return t('screens.wallet_view.text_106');
}
return t('screens.wallet_view.text_153', { value1: message || 'unknown' });
}
function createModeBackButton(renderWalletChoice) {
const backBtn = document.createElement('button');
backBtn.className = 'text-btn';
@@ -537,32 +524,14 @@ export function render({navigate, chrome}) {
async function resolveWalletSigningMaterial() {
const { login, storagePwd } = sessionArgsOrThrow();
let saved = null;
try {
saved = await loadEncryptedUserSecrets(login, storagePwd);
} catch {
saved = null;
}
const blockchainKey = String(saved?.blockchainKey || '').trim();
const clientKey = String(saved?.clientKey || '').trim();
if (blockchainKey && clientKey) {
return {
rootPrivatePkcs8B64: '',
blockchainPrivatePkcs8B64: blockchainKey,
clientPrivatePkcs8B64: clientKey,
};
}
const password = window.prompt(
t('dialogs.pages.wallet_view.prompt_001'),
'',
);
// Root key is intentionally not kept in IndexedDB or encrypted key vault.
// Solana PDA updates are rare, so require a fresh password on every update.
const password = window.prompt(t('dialogs.pages.wallet_view.prompt_001'), '');
if (password == null) throw new Error(t('screens.wallet_view.text_138'));
const keyBundle = await authService.derivePasswordKeyBundle(login, password);
await authService.persistSelectedKeys(login, storagePwd, keyBundle);
return {
rootPrivatePkcs8B64: '',
rootPrivatePkcs8B64: keyBundle.rootPair.privatePkcs8B64,
blockchainPrivatePkcs8B64: keyBundle.blockchainPair.privatePkcs8B64,
clientPrivatePkcs8B64: keyBundle.clientPair.privatePkcs8B64,
};
@@ -1419,14 +1388,11 @@ export function render({navigate, chrome}) {
actions.className = 'stack';
actions.innerHTML = `
<button class="ghost-btn" id="refresh-shine-bch" style="width:100%;">${th('screens.wallet_view.text_266')}</button>
<button class="primary-btn" id="topup-shine-limit" style="width:100%;">${th('screens.wallet_view.text_267')}</button>
`;
const refreshBtn = actions.querySelector('#refresh-shine-bch');
const topupBtn = actions.querySelector('#topup-shine-limit');
const setButtonsDisabled = (disabled) => {
refreshBtn.disabled = disabled;
topupBtn.disabled = disabled;
};
const refreshUsage = async () => {
@@ -1440,11 +1406,11 @@ export function render({navigate, chrome}) {
fetchServerBlockchainState(),
]);
if (modeToken !== activeModeToken) return;
limitValue.textContent = formatKbFromBytes(usage.paidLimitBytes);
limitValue.textContent = usage.paidLimitBytes === 0n ? t('screens.wallet_view.unlimited') : formatKbFromBytes(usage.paidLimitBytes);
const usedServerBytes = BigInt(Math.max(0, Number(serverState.sizeBytes || 0)));
const leftServerBytes = usage.paidLimitBytes > usedServerBytes ? (usage.paidLimitBytes - usedServerBytes) : 0n;
usedValue.textContent = formatKbFromBytes(usedServerBytes);
leftValue.textContent = formatKbFromBytes(leftServerBytes);
leftValue.textContent = usage.paidLimitBytes === 0n ? t('screens.wallet_view.unlimited') : formatKbFromBytes(leftServerBytes);
pdaLabel.textContent = `PDA: ${usage.userPda}`;
endpointLabel.textContent = `RPC: ${usage.endpoint}`;
updatedLabel.textContent = t('screens.wallet_view.text_162', { value1: nowRu() });
@@ -1623,7 +1589,7 @@ export function render({navigate, chrome}) {
pdaLastEl.textContent = t('screens.wallet_view.text_167', { value1: usage.lastBlockNumber });
pdaHashEl.textContent = `Hash: ${usage.lastBlockHashHex || '–'}`;
pdaUsedEl.textContent = t('screens.wallet_view.text_168', { value1: formatBytesRu(usage.usedBytes) });
pdaLimitEl.textContent = t('screens.wallet_view.text_169', { value1: formatBytesRu(usage.paidLimitBytes) });
pdaLimitEl.textContent = t('screens.wallet_view.text_169', { value1: usage.paidLimitBytes === 0n ? t('screens.wallet_view.unlimited') : formatBytesRu(usage.paidLimitBytes) });
pdaArweaveEl.textContent = `Arweave tx: ${usage.arweaveTxId || '–'}`;
if (usage.arweaveTxId) {
pdaArweaveLinkEl.href = buildArweaveDataUrl({ gateway: state.entrySettings.arweaveServer, txId: usage.arweaveTxId });
@@ -1778,7 +1744,6 @@ export function render({navigate, chrome}) {
rootPrivatePkcs8B64: signing.rootPrivatePkcs8B64,
blockchainPrivatePkcs8B64: signing.blockchainPrivatePkcs8B64,
clientPrivatePkcs8B64: signing.clientPrivatePkcs8B64,
additionalLimitBytes: 0n,
nextUsedBytes: BigInt(Math.max(0, serverState.sizeBytes)),
nextLastBlockNumber: serverState.lastNumber,
nextLastBlockHashHex: serverState.lastHash,