SHA256
HEADER v3, primary аккаунты и подтверждения
This commit is contained in:
@@ -41,6 +41,7 @@ import {
|
||||
} from './key-vault.js';
|
||||
import { signEventContainer, submitSignedEvent, readStoredLineMeta } from './core-content.js';
|
||||
import { defaultServerWs } from '../deploy-config.js';
|
||||
import { readPendingHeaderIdentity, clearPendingHeaderIdentity } from './pending-header-identity.js';
|
||||
|
||||
const BCH_SUFFIX = '001';
|
||||
const ZERO64 = '0'.repeat(64);
|
||||
@@ -540,11 +541,15 @@ function extractContactsFromDialogs(dialogs) {
|
||||
return out;
|
||||
}
|
||||
|
||||
export const HEADER_VERSION = 1;
|
||||
export const HEADER_VERSION = 3;
|
||||
// Временное значение до утверждения лицензии проекта.
|
||||
export const HEADER_DEFAULT_LICENSE = '';
|
||||
|
||||
function makeHeaderBodyBytes({ login, initialBlockchainKey32 }) {
|
||||
function makeHeaderBodyBytes({ login, initialBlockchainKey32, license = '', accountType = null, previousAccounts = [] }) {
|
||||
const cleanLogin = String(login || '').trim();
|
||||
const loginBytes = utf8Bytes(cleanLogin);
|
||||
const licenseBytes = utf8Bytes(license);
|
||||
if (licenseBytes.length > 255) throw new Error('HEADER license must be 0..255 UTF-8 bytes');
|
||||
const keyBytes = initialBlockchainKey32 instanceof Uint8Array
|
||||
? initialBlockchainKey32
|
||||
: new Uint8Array(initialBlockchainKey32 || []);
|
||||
@@ -552,10 +557,25 @@ function makeHeaderBodyBytes({ login, initialBlockchainKey32 }) {
|
||||
if (keyBytes.length !== 32 || keyBytes.every((value) => value === 0)) {
|
||||
throw new Error('HEADER initialBlockchainKey32 must be a non-zero 32-byte key');
|
||||
}
|
||||
let identityBytes = new Uint8Array(0);
|
||||
if (accountType !== null) {
|
||||
if (accountType !== 0 && accountType !== 1) throw new Error('Invalid HEADER account type');
|
||||
if (!Array.isArray(previousAccounts) || previousAccounts.length > 10 || (accountType === 0 && previousAccounts.length)) throw new Error('Invalid HEADER previous accounts');
|
||||
const seen = new Set([cleanLogin.toLowerCase()]);
|
||||
for (const previous of previousAccounts) {
|
||||
if (typeof previous !== 'string' || !(/^[A-Za-z0-9_]{1,255}$/.test(previous) || (previous.length <= 30 && /^[A-Za-z0-9_]+@[a-z0-9_]+$/.test(previous))) || seen.has(previous.toLowerCase())) throw new Error('Invalid or duplicate previous account');
|
||||
seen.add(previous.toLowerCase());
|
||||
}
|
||||
const csv = utf8Bytes(previousAccounts.join(','));
|
||||
identityBytes = accountType === 1 ? concatBytes(int8Byte(1), Uint8Array.of(csv.length >> 8, csv.length & 255), csv) : int8Byte(0);
|
||||
}
|
||||
return concatBytes(
|
||||
utf8Bytes('SHiNE'),
|
||||
int8Byte(loginBytes.length),
|
||||
loginBytes,
|
||||
identityBytes,
|
||||
int8Byte(licenseBytes.length),
|
||||
licenseBytes,
|
||||
keyBytes,
|
||||
);
|
||||
}
|
||||
@@ -1270,6 +1290,7 @@ export class AuthService {
|
||||
...currentSecrets,
|
||||
clientKey: keyBundle.clientPair.privatePkcs8B64,
|
||||
};
|
||||
if (saveOptions.headerIdentity) secrets.headerIdentity = saveOptions.headerIdentity;
|
||||
if (saveOptions.saveRoot) secrets.rootKey = keyBundle.rootPair.privatePkcs8B64;
|
||||
if (saveOptions.saveBlockchain) secrets.blockchainKey = keyBundle.blockchainPair.privatePkcs8B64;
|
||||
await saveEncryptedUserSecrets(login, storagePwd, secrets);
|
||||
@@ -1774,6 +1795,9 @@ export class AuthService {
|
||||
}
|
||||
|
||||
const registeredLogin = await this.requireRegisteredDisplayLogin(cleanLogin);
|
||||
// Never invent an account type after a lost registration draft.
|
||||
const identity = keyBundle?.headerIdentity || readPendingHeaderIdentity(registeredLogin, publicKeyB64);
|
||||
if (!identity || ![0, 1].includes(identity.accountType)) throw new Error('HEADER identity declaration is missing; resume registration on the original device');
|
||||
await this.addBlockSigned({
|
||||
login: cleanLogin,
|
||||
storagePwd,
|
||||
@@ -1782,9 +1806,10 @@ export class AuthService {
|
||||
msgVersion: HEADER_VERSION,
|
||||
// HEADER хранит исходный регистр неизменяемого имени из Solana/Arweave.
|
||||
// Нормализация нужна только для уникальности и имени самой цепочки.
|
||||
bodyBytes: makeHeaderBodyBytes({ login: registeredLogin, initialBlockchainKey32 }),
|
||||
bodyBytes: makeHeaderBodyBytes({ login: registeredLogin, initialBlockchainKey32, license: HEADER_DEFAULT_LICENSE, accountType: identity.accountType, previousAccounts: identity.previousAccounts }),
|
||||
_skipHeaderEnsure: true,
|
||||
});
|
||||
clearPendingHeaderIdentity(registeredLogin, publicKeyB64);
|
||||
|
||||
return this.getUser(cleanLogin);
|
||||
}
|
||||
@@ -3268,6 +3293,7 @@ export class AuthService {
|
||||
const cleanParam = (param || '').trim();
|
||||
const cleanValue = String(value ?? '').trim();
|
||||
if (!cleanLogin || !cleanParam) throw new Error('Не переданы login/param.');
|
||||
if (['account_role', 'official'].includes(cleanParam.toLowerCase())) throw new Error('account_type_immutable');
|
||||
if (!cleanValue) throw new Error('Значение параметра не может быть пустым.');
|
||||
if (!storagePwd) throw new Error('Не передан storagePwd для подписи AddBlock.');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user