Обновление архитектуры ключей и кошельков

This commit is contained in:
AidarKC
2026-10-01 17:11:38 +03:00
parent f452ce1f1e
commit 8d22602761
51 changed files with 565 additions and 898 deletions
+18 -15
View File
@@ -1,6 +1,6 @@
import { loadEncryptedUserSecrets, updateEncryptedUserSecrets } from './key-vault.js';
import { extractClientKey32FromStoredValue } from './client-key-utils.js';
import { deriveArweaveWalletFromClientKey32 } from './sawd-v1.js';
import { extractEd25519Seed32FromStoredValue } from './client-key-utils.js';
import { deriveArweaveWalletFromBlockchainKey32 } from './sawd-v1.js';
const DEFAULT_ARWEAVE_GATEWAY = 'https://arweave.net';
const AR_TOPUP_URL = 'https://changenow.io/exchange?from=usd&to=ar&amount=10&fiatMode=true';
@@ -76,10 +76,11 @@ function pickCachedWallet(secrets) {
const cached = secrets?.arweaveWallet;
if (!cached || typeof cached !== 'object') return null;
const derivation = String(cached.derivation || '').trim();
const sourceKey = String(cached.sourceKey || '').trim();
const address = String(cached.address || '').trim();
const owner = String(cached.owner || '').trim();
const jwk = cached.jwk;
if (derivation !== 'SAWD-v1' || !address || !owner || !jwk || typeof jwk !== 'object') {
if (derivation !== 'SAWD-v1' || sourceKey !== 'blockchain' || !address || !owner || !jwk || typeof jwk !== 'object') {
return null;
}
if (!String(jwk.kty || '').trim() || !String(jwk.e || '').trim() || !String(jwk.n || '').trim() || !String(jwk.d || '').trim()) {
@@ -87,6 +88,7 @@ function pickCachedWallet(secrets) {
}
return {
derivation,
sourceKey,
address,
owner,
jwk,
@@ -150,13 +152,13 @@ function safeStatus(onStatus, text) {
}
export async function getArweaveWalletChoices({ login, storagePwd, onStatus } = {}) {
const derived = await getArweaveWalletFromStoredClientKey({ login, storagePwd, onStatus });
const derived = await getArweaveWalletFromStoredBlockchainKey({ login, storagePwd, onStatus });
const secrets = await loadEncryptedUserSecrets(String(login || '').trim(), String(storagePwd || '').trim());
const extras = normalizeExtraWallets(secrets);
return [
{
id: 'derived-client-key',
label: 'Стандартный из client key',
id: 'derived-blockchain-key',
label: 'Стандартный из ключа блокчейна',
address: derived.address,
owner: derived.owner,
jwk: derived.jwk,
@@ -206,11 +208,11 @@ export async function addArweaveWalletSecret({ login, storagePwd, secret, label
return wallet;
}
export async function getArweaveWalletFromStoredClientKey({ login, storagePwd, onStatus } = {}) {
export async function getArweaveWalletFromStoredBlockchainKey({ login, storagePwd, onStatus } = {}) {
const cleanLogin = String(login || '').trim();
const cleanPwd = String(storagePwd || '').trim();
if (!cleanLogin || !cleanPwd) {
throw new Error('Нет активной сессии для доступа к client.key');
throw new Error('Нет активной сессии для доступа к blockchain key');
}
const secrets = await loadEncryptedUserSecrets(cleanLogin, cleanPwd);
@@ -220,23 +222,24 @@ export async function getArweaveWalletFromStoredClientKey({ login, storagePwd, o
return cached;
}
safeStatus(onStatus, 'Сейчас мы впервые получаем Arweave-кошелёк из вашего client key. Это может занять немного времени.');
safeStatus(onStatus, 'Сейчас мы впервые получаем Arweave-кошелёк из вашего ключа блокчейна. Это может занять немного времени.');
const storedClientKey = String(secrets?.clientKey || '').trim();
if (!storedClientKey) {
throw new Error('На устройстве не найден client.key');
const storedBlockchainKey = String(secrets?.blockchainKey || '').trim();
if (!storedBlockchainKey) {
throw new Error('На устройстве не найден blockchain key');
}
const clientKey32 = extractClientKey32FromStoredValue(storedClientKey);
const blockchainKey32 = extractEd25519Seed32FromStoredValue(storedBlockchainKey);
let wallet;
try {
wallet = await deriveArweaveWalletFromClientKey32(clientKey32);
wallet = await deriveArweaveWalletFromBlockchainKey32(blockchainKey32);
} finally {
clientKey32.fill(0);
blockchainKey32.fill(0);
}
const cachedWallet = {
derivation: wallet.derivation,
sourceKey: 'blockchain',
address: wallet.address,
owner: wallet.owner,
jwk: wallet.jwk,