SHA256
Слить свежий main (8db2c7e7) в ветку личного чата
Конфликт был только в VERSION.properties: клиент 1.21.20 из ветки, сервер 1.17.11 из main. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
// Текст сервера недоверенный: никакого HTML, только текст и HTTPS-ссылки.
|
||||
export function appendAboutText(container, text) {
|
||||
const value = String(text);
|
||||
let offset = 0;
|
||||
for (const match of value.matchAll(/https:\/\/[^\s<>"']+/gu)) {
|
||||
container.append(document.createTextNode(value.slice(offset, match.index)));
|
||||
try {
|
||||
const url = new URL(match[0]);
|
||||
if (url.protocol !== 'https:' || url.username || url.password) throw new Error('Invalid URL');
|
||||
const link = document.createElement('a');
|
||||
link.href = url.href;
|
||||
link.textContent = match[0];
|
||||
link.target = '_blank';
|
||||
link.rel = 'noopener noreferrer';
|
||||
container.append(link);
|
||||
} catch {
|
||||
container.append(document.createTextNode(match[0]));
|
||||
}
|
||||
offset = match.index + match[0].length;
|
||||
}
|
||||
container.append(document.createTextNode(value.slice(offset)));
|
||||
}
|
||||
@@ -544,11 +544,11 @@ function extractContactsFromDialogs(dialogs) {
|
||||
return out;
|
||||
}
|
||||
|
||||
export const HEADER_VERSION = 3;
|
||||
export const HEADER_VERSION = 1;
|
||||
// Временное значение до утверждения лицензии проекта.
|
||||
export const HEADER_DEFAULT_LICENSE = '';
|
||||
|
||||
function makeHeaderBodyBytes({ login, initialBlockchainKey32, license = '', accountType = null, previousAccounts = [] }) {
|
||||
function makeHeaderBodyBytes({ login, initialBlockchainKey32, license = '', accountType = 1, previousAccounts = [] }) {
|
||||
const cleanLogin = String(login || '').trim();
|
||||
const loginBytes = utf8Bytes(cleanLogin);
|
||||
const licenseBytes = utf8Bytes(license);
|
||||
@@ -560,18 +560,15 @@ function makeHeaderBodyBytes({ login, initialBlockchainKey32, license = '', acco
|
||||
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);
|
||||
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(','));
|
||||
const identityBytes = accountType === 1 ? concatBytes(int8Byte(1), Uint8Array.of(csv.length >> 8, csv.length & 255), csv) : int8Byte(0);
|
||||
return concatBytes(
|
||||
utf8Bytes('SHiNE'),
|
||||
int8Byte(loginBytes.length),
|
||||
|
||||
@@ -124,33 +124,20 @@ function parseTechBody(subType, body, frame) {
|
||||
const magic = reader.text(5, 'HEADER magic');
|
||||
if (magic !== 'SHiNE') throw new Error('Неправильная сигнатура HEADER');
|
||||
const login = reader.textU8('HEADER login');
|
||||
let license = null;
|
||||
let accountType = null;
|
||||
const accountType = reader.u8('HEADER account type');
|
||||
if (accountType !== 0 && accountType !== 1) throw new Error('Invalid HEADER account type');
|
||||
let previousAccounts = [];
|
||||
if (frame.version === 3) {
|
||||
accountType = reader.u8('HEADER account type');
|
||||
if (accountType !== 0 && accountType !== 1) throw new Error('Invalid HEADER account type');
|
||||
if (accountType === 1) {
|
||||
const csv = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(reader.raw(reader.u16('HEADER previous accounts length'), 'HEADER previous accounts'));
|
||||
previousAccounts = csv ? csv.split(',') : [];
|
||||
const seen = new Set([login.toLowerCase()]);
|
||||
if (previousAccounts.length > 10) throw new Error('Too many previous accounts');
|
||||
for (const previous of previousAccounts) {
|
||||
if (!(/^[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 previous account');
|
||||
seen.add(previous.toLowerCase());
|
||||
}
|
||||
}
|
||||
license = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(reader.raw(reader.u8('HEADER license length'), 'HEADER license'));
|
||||
} else if (frame.version === 2) {
|
||||
const field = reader.raw(reader.remaining() - 32, 'HEADER license');
|
||||
const marker = 'license:CC0-1.0';
|
||||
if (field.length === marker.length && field.every((b, i) => b === marker.charCodeAt(i))) {
|
||||
license = 'CC0-1.0'; // исторический HEADER v2
|
||||
} else {
|
||||
if (!field.length || field[0] !== field.length - 1) throw new Error('Некорректная длина лицензии HEADER');
|
||||
license = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(field.slice(1));
|
||||
if (accountType === 1) {
|
||||
const csv = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(reader.raw(reader.u16('HEADER previous accounts length'), 'HEADER previous accounts'));
|
||||
previousAccounts = csv ? csv.split(',') : [];
|
||||
const seen = new Set([login.toLowerCase()]);
|
||||
if (previousAccounts.length > 10) throw new Error('Too many previous accounts');
|
||||
for (const previous of previousAccounts) {
|
||||
if (!(/^[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 previous account');
|
||||
seen.add(previous.toLowerCase());
|
||||
}
|
||||
}
|
||||
const license = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(reader.raw(reader.u8('HEADER license length'), 'HEADER license'));
|
||||
const initialBlockchainKey = bytesToBase64Url(reader.raw(32, 'initialBlockchainKey32'));
|
||||
if (reader.remaining() !== 0) throw new Error('Неожиданные данные после HEADER');
|
||||
return { kind: 'header', magic, login, license, accountType, previousAccounts, initialBlockchainKey };
|
||||
@@ -260,8 +247,7 @@ function parseStatusBody(subType, body) {
|
||||
}
|
||||
|
||||
function parseBody(type, subType, version, body, frame) {
|
||||
// Only TECH HEADER subtype 0 has a second version; all other records stay v1.
|
||||
if (version !== 1 && !(type === 0 && subType === 0 && (version === 2 || version === 3))) {
|
||||
if (version !== 1) {
|
||||
return { kind: 'unsupported_version', rawBodyLength: body.length };
|
||||
}
|
||||
if (type === 0) return parseTechBody(subType, body, frame);
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import { state } from '../state.js';
|
||||
import { getDevicePref, setDevicePref } from './device-prefs.js';
|
||||
|
||||
const PREFIX = 'showCallWarning:';
|
||||
|
||||
function key() {
|
||||
const login = String(state.session?.login || '').trim().toLowerCase();
|
||||
return login ? `${PREFIX}${login}` : null;
|
||||
}
|
||||
|
||||
export function getShowCallWarning() {
|
||||
const preference = key();
|
||||
return preference ? getDevicePref(preference, true) !== false : true;
|
||||
}
|
||||
|
||||
export function setShowCallWarning(show) {
|
||||
const preference = key();
|
||||
if (preference) setDevicePref(preference, Boolean(show));
|
||||
}
|
||||
@@ -80,7 +80,7 @@ export function coreTags(core) {
|
||||
function checkEventLine(content, core) {
|
||||
const { type, subType, version } = content;
|
||||
const header = type === 0 && subType === 0;
|
||||
if (version !== 1 && !(header && (version === 2 || version === 3))) throw new Error('Unsupported CONTENT version for creation');
|
||||
if (version !== 1) throw new Error('Unsupported CONTENT version for creation');
|
||||
if (header !== (core.blockNumber === 0)) throw new Error('HEADER must be CORE #0');
|
||||
const code = core.line?.lineCode;
|
||||
if (type === 0 && !header) { if (code !== SHINE_CORE_LINE_TECH) throw new Error('Wrong TECH line'); }
|
||||
|
||||
@@ -7,7 +7,7 @@ export const SHINE_CHANNEL_TAG_NAME = 'c';
|
||||
export const SHINE_TYPE_TAG_NAME = 't';
|
||||
|
||||
// Активная эпоха CORE/CONTENT.
|
||||
export const SHINE_CORE_NAMESPACE = 'test5595';
|
||||
export const SHINE_CORE_NAMESPACE = 'test5599';
|
||||
export const SHINE_CORE_NUMBER_TAG_NAME = 'n';
|
||||
export const SHINE_CORE_LINE_TAG_NAME = 'l';
|
||||
export const SHINE_CORE_LINE_PROFILE = 2147483645;
|
||||
|
||||
@@ -12,9 +12,7 @@ import { getNamespace, assertLoginInNamespace, normalizeFullLogin, userPdaSeed32
|
||||
|
||||
const MAGIC = 'SHiNE';
|
||||
const FORMAT_MAJOR = 1;
|
||||
const FORMAT_MINOR_LEGACY = 0;
|
||||
const FORMAT_MINOR_CURRENT = 3;
|
||||
const FORMAT_MINOR_PREVIOUS = 2;
|
||||
const FORMAT_MINOR_CURRENT = 0;
|
||||
const SHINE_PAYMENTS_INFLOW_VAULT_SEED = 'shine_payments_inflow_vault';
|
||||
const SHINE_USERS_USER_PDA_SEED_PREFIX = 'user_login=';
|
||||
const SHINE_USERS_PROMO_SELLER_PDA_SEED_PREFIX = 'promo_seller=';
|
||||
@@ -56,7 +54,7 @@ function normalizeAccessServers(values) {
|
||||
const login = normalizeLogin(value);
|
||||
if (!login || seen.has(login)) continue;
|
||||
if (result.length >= MAX_EFFECTIVE_ACCESS_SERVERS) {
|
||||
throw new Error('PDA 1.3 поддерживает максимум один сервер доступа');
|
||||
throw new Error('PDA 1.0 поддерживает максимум один сервер доступа');
|
||||
}
|
||||
seen.add(login);
|
||||
result.push(login);
|
||||
@@ -155,7 +153,7 @@ function buildEd25519IxData(sig64, pubkey32, messageBytes) {
|
||||
|
||||
function normalizeServerAddresses(values, fallback = null) {
|
||||
const src = Array.isArray(values) && values.length ? values : (fallback ? [fallback] : []);
|
||||
if (src.length > 1) throw new Error('PDA 1.3 поддерживает только один адрес сервера');
|
||||
if (src.length > 1) throw new Error('PDA 1.0 поддерживает только один адрес сервера');
|
||||
return src.map((item) => {
|
||||
const address = String(item?.address ?? item?.serverAddress ?? '').trim();
|
||||
const bytes = new TextEncoder().encode(address);
|
||||
@@ -223,7 +221,7 @@ function parseV12Pda(bytes, header) {
|
||||
if (payload.remaining !== 0) throw new Error('Повреждённый BlockchainRegistry');
|
||||
} else if (blockType === BLOCK_TYPE_SERVER_PROFILE) {
|
||||
const count = payload.readU8();
|
||||
if (count !== 1) throw new Error('PDA 1.3 допускает ровно один адрес в ServerProfileBlock');
|
||||
if (count !== 1) throw new Error('PDA 1.0 допускает ровно один адрес в ServerProfileBlock');
|
||||
serverAddresses = [];
|
||||
for (let j = 0; j < count; j += 1) {
|
||||
serverAddresses.push({
|
||||
@@ -235,7 +233,7 @@ function parseV12Pda(bytes, header) {
|
||||
if (payload.remaining !== 0) throw new Error('Повреждённый ServerProfileBlock');
|
||||
} else if (blockType === BLOCK_TYPE_ACCESS_SERVERS) {
|
||||
const count = payload.readU8();
|
||||
if (count > 1) throw new Error('PDA 1.3 допускает максимум один access server');
|
||||
if (count > 1) throw new Error('PDA 1.0 допускает максимум один access server');
|
||||
accessServers = [];
|
||||
for (let j = 0; j < count; j += 1) accessServers.push(payload.readStrU8());
|
||||
if (payload.remaining !== 0) throw new Error('Повреждённый AccessServersBlock');
|
||||
@@ -277,7 +275,7 @@ export function parseShineUserPda(dataBytes) {
|
||||
const formatMajor = reader.readU8();
|
||||
const formatMinor = reader.readU8();
|
||||
const recordLen = reader.readU16();
|
||||
if (formatMajor !== FORMAT_MAJOR || ![FORMAT_MINOR_PREVIOUS, FORMAT_MINOR_CURRENT].includes(formatMinor)) throw new Error(`Неподдерживаемый формат PDA ${formatMajor}.${formatMinor}`);
|
||||
if (formatMajor !== FORMAT_MAJOR || formatMinor !== FORMAT_MINOR_CURRENT) throw new Error(`Неподдерживаемый формат PDA ${formatMajor}.${formatMinor}`);
|
||||
if (recordLen < 9 + 64 || recordLen > bytes.length) throw new Error('Некорректный record_len');
|
||||
const createdAtMs = reader.readU64();
|
||||
const updatedAtMs = reader.readU64();
|
||||
@@ -311,13 +309,13 @@ function writeVariableBlock(out, blockType, writer) {
|
||||
out[lenPos + 1] = (len >>> 8) & 0xff;
|
||||
}
|
||||
|
||||
/** PDA 1.3 canonical signing message. Only the four limit bytes per fork are skipped.
|
||||
/** PDA 1.0 canonical signing message. Only the four limit bytes per fork are skipped.
|
||||
* All physical length fields remain unchanged, so changing a limit preserves signatures.
|
||||
*/
|
||||
export function canonicalPdaSigningBytes(unsignedBytes) {
|
||||
const bytes = toUint8Array(unsignedBytes);
|
||||
if (bytes.length < 64 || new TextDecoder().decode(bytes.slice(0, 5)) !== MAGIC || bytes[5] !== 1 || bytes[6] !== 3) {
|
||||
throw new Error('Ожидается unsigned PDA v1.3');
|
||||
if (bytes.length < 64 || new TextDecoder().decode(bytes.slice(0, 5)) !== MAGIC || bytes[5] !== FORMAT_MAJOR || bytes[6] !== FORMAT_MINOR_CURRENT) {
|
||||
throw new Error('Ожидается unsigned PDA v1.0');
|
||||
}
|
||||
const rd16 = (i) => bytes[i] | (bytes[i + 1] << 8);
|
||||
if (rd16(7) !== bytes.length + 64) throw new Error('Неверный record_len');
|
||||
@@ -696,36 +694,8 @@ export async function upgradeFreeUserOnSolana({ login, keyBundle, solanaEndpoint
|
||||
}
|
||||
|
||||
export async function registerServerOnSolana({ login, keyBundle, serverAddress, serverAddresses = null, addressFormatType = 1, addressFormatVersion = 0, accessServers = [], solanaEndpoint }) {
|
||||
// Серверная админка показывает баланс client/device-кошелька; именно он оплачивает создание PDA.
|
||||
return createShineUserPdaOnSolana({ login, keyBundle, solanaEndpoint, isServer: true, serverAddress, serverAddresses: serverAddresses || [], addressFormatType, addressFormatVersion, accessServers, feePayerPrivatePkcs8B64: keyBundle.clientPair.privatePkcs8B64 });
|
||||
}
|
||||
|
||||
export async function closeLegacyShineUserPdaOnSolana({ login, solanaEndpoint, callerPrivatePkcs8B64 }) {
|
||||
const cleanLogin = normalizeLogin(login);
|
||||
if (!cleanLogin || !callerPrivatePkcs8B64) throw new Error('Нужны login и private key вызывающего');
|
||||
const solana = await loadSolanaLib();
|
||||
const endpoint = String(solanaEndpoint || '').trim();
|
||||
const connection = new solana.Connection(endpoint, 'confirmed');
|
||||
const usersProgram = new solana.PublicKey(SHINE_USERS_PROGRAM_ID);
|
||||
const [userPda] = solana.PublicKey.findProgramAddressSync([new TextEncoder().encode(SHINE_USERS_USER_PDA_SEED_PREFIX), new TextEncoder().encode(cleanLogin)], usersProgram);
|
||||
const info = await connection.getAccountInfo(userPda, 'confirmed');
|
||||
if (!info) throw new Error('PDA не найдена');
|
||||
const raw = new Uint8Array(info.data);
|
||||
if (raw.length < 7 || new TextDecoder().decode(raw.slice(0, 5)) !== MAGIC || raw[5] !== FORMAT_MAJOR || raw[6] !== FORMAT_MINOR_LEGACY) {
|
||||
throw new Error('Закрывать этой инструкцией можно только legacy PDA 1.0');
|
||||
}
|
||||
const seed32 = extractSeed32FromPkcs8B64(callerPrivatePkcs8B64);
|
||||
const caller = solana.Keypair.fromSeed(seed32);
|
||||
const ix = new solana.TransactionInstruction({
|
||||
programId: usersProgram,
|
||||
keys: [
|
||||
{ pubkey: caller.publicKey, isSigner: true, isWritable: true },
|
||||
{ pubkey: userPda, isSigner: false, isWritable: true },
|
||||
],
|
||||
data: serializeCloseLegacyArgs(cleanLogin),
|
||||
});
|
||||
const signature = await sendAndConfirmSolanaHttp(connection, new solana.Transaction().add(ix), [caller]);
|
||||
return { signature, pdaAddress: userPda.toBase58() };
|
||||
// Единый payer регистрации — blockchain key, как и для обычного пользователя.
|
||||
return createShineUserPdaOnSolana({ login, keyBundle, solanaEndpoint, isServer: true, serverAddress, serverAddresses: serverAddresses || [], addressFormatType, addressFormatVersion, accessServers, feePayerPrivatePkcs8B64: keyBundle.blockchainPair.privatePkcs8B64 });
|
||||
}
|
||||
|
||||
export async function updateShineUserPdaOnSolana({
|
||||
@@ -760,7 +730,7 @@ export async function updateShineUserPdaOnSolana({
|
||||
if ((rootChanged || clientChanged) && !fullKeyRotation) {
|
||||
throw new Error('Root/client keys меняются только как полная ротация: новый root + новый client + новый blockchain fork');
|
||||
}
|
||||
const authMode = AUTH_MODE_ROOT; // Root is the sole user PDA authority in v1.3.
|
||||
const authMode = AUTH_MODE_ROOT; // Root is the sole user PDA authority in v1.0.
|
||||
if (authorityMode != null && authorityMode !== 'root' && authorityMode !== 'blockchain' && authorityMode !== AUTH_MODE_ROOT && authorityMode !== AUTH_MODE_BLOCKCHAIN) {
|
||||
throw new Error('Неподдерживаемый режим authority');
|
||||
}
|
||||
@@ -790,8 +760,7 @@ export async function updateShineUserPdaOnSolana({
|
||||
createdAtMs: current.createdAtMs,
|
||||
updatedAtMs,
|
||||
recordNumber: current.recordNumber + 1,
|
||||
prevRecordHash: await sha256Bytes(current.formatMinor === FORMAT_MINOR_CURRENT
|
||||
? canonicalPdaSigningBytes(current.unsignedBytes) : current.unsignedBytes),
|
||||
prevRecordHash: await sha256Bytes(canonicalPdaSigningBytes(current.unsignedBytes)),
|
||||
rootKey,
|
||||
clientKey,
|
||||
forks,
|
||||
|
||||
@@ -4,13 +4,10 @@ import { authService, state } from '../state.js';
|
||||
import { validateArweaveTxId } from './arweave-file-service.js';
|
||||
import { validatePublicPiecesRoot } from './public-pieces-root.js';
|
||||
import { buildAvatarReference, parseAvatarReference } from './avatar-reference.js';
|
||||
import { CITY_MAX_LENGTH, CITY_PARAM, CITY_SUGGESTIONS } from './cities.js';
|
||||
|
||||
export const profileFieldDefs = [
|
||||
{ key: 'first_name', readKeys: ['first_name'], get label() { return t('remaining.profile_fields.first_name'); }, get placeholder() { return t('remaining.profile_fields.enter_your_first_name'); } },
|
||||
{ key: 'last_name', readKeys: ['last_name'], get label() { return t('remaining.profile_fields.last_name'); }, get placeholder() { return t('remaining.profile_fields.enter_your_last_name'); } },
|
||||
// Город виден в профиле и собирает знакомых в раскладке «Города» на карте связей.
|
||||
{ key: CITY_PARAM, readKeys: [CITY_PARAM], get label() { return t('remaining.profile_fields.city'); }, get placeholder() { return t('remaining.profile_fields.for_example_london'); }, maxLength: CITY_MAX_LENGTH, suggestions: CITY_SUGGESTIONS },
|
||||
{ key: 'address', readKeys: ['address'], get label() { return t('remaining.profile_fields.address'); }, get placeholder() { return t('remaining.profile_fields.street_and_house_number'); } },
|
||||
{ key: 'web', readKeys: ['web'], get label() { return t('remaining.profile_fields.links'); }, get placeholder() { return t('remaining.profile_fields.website_profile_or_other_link'); } },
|
||||
{ key: 'phone', readKeys: ['phone'], get label() { return t('remaining.profile_fields.phone'); }, placeholder: '+7 ...' },
|
||||
|
||||
Reference in New Issue
Block a user