SHA256
Обновление архитектуры ключей и кошельков
This commit is contained in:
@@ -674,7 +674,7 @@ function targetLoginBytes(value) {
|
||||
|
||||
function normalizeTargetForkNumber(value, actionName = 'target') {
|
||||
const n = Number(value);
|
||||
if (!Number.isInteger(n) || n < 0 || n > 999) throw new Error(`Invalid toForkNumber for ${actionName}`);
|
||||
if (!Number.isInteger(n) || n < 1 || n > 999) throw new Error(`Invalid toForkNumber for ${actionName}`);
|
||||
return n;
|
||||
}
|
||||
|
||||
@@ -1142,8 +1142,10 @@ export class AuthService {
|
||||
async createSessionFromImportedSecrets(login, secrets) {
|
||||
const cleanLogin = (login || '').trim();
|
||||
if (!cleanLogin) throw new Error('В QR-коде нет логина');
|
||||
const clientKey = String(secrets?.clientKey || secrets?.clientKey || '').trim();
|
||||
if (!clientKey) throw new Error('В QR-коде нет client key для входа');
|
||||
const clientKey = String(secrets?.clientKey || '').trim();
|
||||
const blockchainKey = String(secrets?.blockchainKey || '').trim();
|
||||
if (!clientKey) throw new Error('В QR-коде нет ключа доступа для входа');
|
||||
if (!blockchainKey) throw new Error('В QR-коде нет ключа блокчейна');
|
||||
|
||||
const privateKey = await importPkcs8Ed25519(clientKey);
|
||||
const publicKeyB64 = await publicKeyB64FromPkcs8Ed25519(clientKey);
|
||||
@@ -1219,7 +1221,7 @@ export class AuthService {
|
||||
}
|
||||
}
|
||||
|
||||
async persistSelectedKeys(login, storagePwd, keyBundle, saveOptions = { saveRoot: true, saveBlockchain: true }) {
|
||||
async persistSelectedKeys(login, storagePwd, keyBundle) {
|
||||
let currentSecrets = {};
|
||||
try {
|
||||
const loaded = await loadEncryptedUserSecrets(login, storagePwd);
|
||||
@@ -1230,12 +1232,23 @@ export class AuthService {
|
||||
// Если контейнера ещё нет или пароль новый для этого логина — создадим новый ниже.
|
||||
}
|
||||
|
||||
const clientKey = String(keyBundle?.clientPair?.privatePkcs8B64 || '').trim();
|
||||
const blockchainKey = String(keyBundle?.blockchainPair?.privatePkcs8B64 || '').trim();
|
||||
if (!clientKey || !blockchainKey) {
|
||||
throw new Error('Для входа нужно сохранить client key и blockchain key');
|
||||
}
|
||||
|
||||
const secrets = {
|
||||
...currentSecrets,
|
||||
clientKey: keyBundle.clientPair.privatePkcs8B64,
|
||||
clientKey,
|
||||
blockchainKey,
|
||||
};
|
||||
if (saveOptions.saveRoot) secrets.rootKey = keyBundle.rootPair.privatePkcs8B64;
|
||||
if (saveOptions.saveBlockchain) secrets.blockchainKey = keyBundle.blockchainPair.privatePkcs8B64;
|
||||
// SAWD-v1 wallet зависит от blockchain key. При смене ключа старый кэш
|
||||
// нельзя переносить в новую identity: он будет лениво выведен заново.
|
||||
if (String(currentSecrets?.blockchainKey || '').trim() !== blockchainKey) {
|
||||
delete secrets.arweaveWallet;
|
||||
}
|
||||
delete secrets.rootKey;
|
||||
await saveEncryptedUserSecrets(login, storagePwd, secrets);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user