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

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
@@ -73,15 +73,15 @@ function normalizeKeys(keys = {}) {
return {
clientKey: String(keys?.clientKey || '').trim(),
blockchainKey: String(keys?.blockchainKey || '').trim(),
rootKey: String(keys?.rootKey || '').trim(),
};
}
export function detectPairingPayloadType(keys = {}) {
const normalized = normalizeKeys(keys);
if (normalized.rootKey) return 3;
if (normalized.blockchainKey) return 2;
return 1;
if (!normalized.clientKey || !normalized.blockchainKey) {
throw new Error('Для подключения устройства нужны ключ доступа и ключ блокчейна');
}
return 2;
}
export async function deriveEspPairingPasswordHash(login, password) {
@@ -159,13 +159,14 @@ export async function decryptPairingPayloadFromEnvelope(encryptedPayload, reques
}
export function buildSecretsPayload({ login, keys, mode }) {
const normalizedKeys = normalizeKeys(keys);
return {
v: 1,
type: 'shine-esp-pairing-transfer',
login: String(login || '').trim(),
mode: String(mode || 'device-only').trim() || 'device-only',
keys: normalizeKeys(keys),
payloadType: detectPairingPayloadType(keys),
mode: String(mode || 'full-device').trim() || 'full-device',
keys: normalizedKeys,
payloadType: detectPairingPayloadType(normalizedKeys),
createdAtMs: Date.now(),
};
}