Добавить диагностику server PDA и баланс device (не проверено)

This commit is contained in:
AidarKC
2026-06-03 16:12:40 +04:00
parent ee3721dfa4
commit eeb115584d
10 changed files with 218 additions and 8 deletions
+45
View File
@@ -7,6 +7,7 @@ import {
deriveMasterSecretFromPassword,
publicKeyB64FromPkcs8Ed25519,
} from '../../js/services/crypto-utils.js';
import { formatSol, getBalanceSol } from '../../js/services/solana-wallet-service.js';
const LOGIN_RE = /^[a-z0-9_]{1,20}$/;
const ED25519_PKCS8_PREFIX = new Uint8Array([
@@ -189,12 +190,56 @@ export function updateSolAddress(fieldMap) {
}
}
export function setText(idOrNode, value) {
const node = typeof idOrNode === 'string' ? $(idOrNode) : idOrNode;
if (node) node.textContent = String(value || '');
}
export function wireDeviceAddressPreview(fieldMap) {
const update = () => updateSolAddress(fieldMap);
$(fieldMap.devPub).addEventListener('input', update);
update();
}
export function publicKeyBytesToBase58(value) {
return bytesToBase58(value instanceof Uint8Array ? value : new Uint8Array(value || []));
}
export function compareExpectedPublicKeys(expected, actual) {
const exp = String(expected || '').trim();
const act = String(actual || '').trim();
return {
matches: Boolean(exp) && Boolean(act) && exp === act,
expected: exp,
actual: act,
};
}
export function summarizeKeyComparison(resultMap) {
const labels = {
root: 'root',
blockchain: 'blockchain',
device: 'device',
};
const mismatches = Object.entries(resultMap)
.filter(([, result]) => !result.matches)
.map(([key]) => labels[key] || key);
return {
allMatch: mismatches.length === 0,
mismatches,
};
}
export async function refreshDeviceBalance({ endpoint, deviceAddress, targetNode }) {
const cleanEndpoint = String(endpoint || '').trim();
const cleanAddress = String(deviceAddress || '').trim();
if (!cleanEndpoint) throw new Error('Укажите Solana endpoint');
if (!cleanAddress) throw new Error('Сначала укажите device-адрес');
const balance = await getBalanceSol({ endpoint: cleanEndpoint, address: cleanAddress });
setText(targetNode, `Баланс device: ${formatSol(balance.sol, 6)} SOL (${balance.lamports} lamports)`);
return balance;
}
export function buildDevnetTopupUrl(walletAddress) {
const cleanWallet = String(walletAddress || '').trim();
const url = new URL('../devnet-topup-view', window.location.href);