SHA256
Разделить среды и закрепить лицензии в HEADER 1.0
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { dmPreviewLockName } from './dm-preview-settings.js';
|
||||
import { buildAvatarReference } from './avatar-reference.js';
|
||||
import { WsJsonClient } from './ws-client.js';
|
||||
import { parseServerEnvironment } from './server-environment.js';
|
||||
import { invalidateConnectionsGraphCache } from './connections-graph-cache.js';
|
||||
import {
|
||||
base64ToBytes,
|
||||
@@ -544,10 +545,10 @@ function extractContactsFromDialogs(dialogs) {
|
||||
return out;
|
||||
}
|
||||
|
||||
export const HEADER_VERSION = 2;
|
||||
export const HEADER_DEFAULT_LICENSE = 'CC0-1.0';
|
||||
export const HEADER_VERSION = 1;
|
||||
export const HEADER_DEFAULT_LICENSE = 'licenses:CC-BY-NC-4.0/sha256:41003d4a74749c0220e33dd415042164b5a1093ed401f36277234f772d22d3d0/arweave:Xtym3vUAyt7OgFBINBh1ene-5360Ah76c6D-O9ywxVE;SCDL-1.0/sha256:696454cb26c7ecb9e8b66812996b37733dc532307a3584718edd442b291870af/arweave:NPckIo-nQUP2-ZM6PIoDYnx-6wwLeErH39jXCddOxPE';
|
||||
|
||||
function makeHeaderBodyBytes({ login, initialBlockchainKey32, license = 'CC0-1.0', accountType = 1, previousAccounts = [] }) {
|
||||
function makeHeaderBodyBytes({ login, initialBlockchainKey32, license = HEADER_DEFAULT_LICENSE, accountType = 1, previousAccounts = [] }) {
|
||||
const cleanLogin = String(login || '').trim();
|
||||
const loginBytes = utf8Bytes(cleanLogin);
|
||||
const licenseBytes = utf8Bytes(license);
|
||||
@@ -961,10 +962,35 @@ export class AuthService {
|
||||
});
|
||||
}
|
||||
|
||||
async getServerEnvironment() {
|
||||
const ws = this.ws;
|
||||
let generation;
|
||||
let environment;
|
||||
try {
|
||||
await ws.open();
|
||||
generation = ws.connectionGeneration;
|
||||
const response = await ws.request('GetServerInfo', {}, 9000);
|
||||
if (this.ws !== ws || ws.connectionGeneration !== generation || !ws.ws) throw new Error('Server connection changed');
|
||||
environment = parseServerEnvironment(response);
|
||||
} catch (error) {
|
||||
if (this.ws === ws && (generation == null || ws.connectionGeneration === generation)) {
|
||||
this.serverEnvironment = null; this.environmentGeneration = null; this.onEnvironmentChange?.(null);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
this.serverEnvironment = environment;
|
||||
this.environmentGeneration = generation;
|
||||
this.onEnvironmentChange?.(environment);
|
||||
return environment;
|
||||
}
|
||||
|
||||
resetConnection(serverUrl = this.serverUrl, { clearSessionContext = true } = {}) {
|
||||
const normalized = normalizeServerUrl(serverUrl);
|
||||
const requestGuard = this.ws?.requestGuard;
|
||||
try { this.ws?.close(); } catch {}
|
||||
try { if (this.ws) this.ws.retired = true; this.ws?.close(); } catch {}
|
||||
this.serverEnvironment = null;
|
||||
this.environmentGeneration = null;
|
||||
this.onEnvironmentChange?.(null);
|
||||
this.serverUrl = normalized;
|
||||
this.ws = new WsJsonClient(this.serverUrl);
|
||||
this.ws.setRequestGuard(requestGuard);
|
||||
@@ -1667,14 +1693,18 @@ export class AuthService {
|
||||
}
|
||||
|
||||
async submitPreparedAddBlock({ login, storagePwd, blockchainName, blockNumber, prevBlockHash, event }) {
|
||||
const ws = this.ws;
|
||||
const { arweaveAppTag } = await this.getServerEnvironment();
|
||||
const generation = ws.connectionGeneration;
|
||||
const savedKeys = await loadEncryptedUserSecrets(login, storagePwd);
|
||||
const pkcs8 = String(savedKeys?.blockchainKey || '').trim();
|
||||
if (!pkcs8) throw new Error('Blockchain key unavailable for local signing');
|
||||
const privateKey = await importPkcs8Ed25519(pkcs8);
|
||||
const owner32 = base64ToBytes(await publicKeyB64FromPkcs8Ed25519(pkcs8));
|
||||
const signed = await signEventContainer({ ...event, owner32, privateKey, blockNumber,
|
||||
const signed = await signEventContainer({ ...event, owner32, privateKey, blockNumber, arweaveAppTag,
|
||||
prevBlockHash, timestamp: Math.floor(Date.now() / 1000) });
|
||||
return submitSignedEvent(this.ws, { blockchainName, blockNumber, prevBlockHash }, signed);
|
||||
if (this.ws !== ws || ws.connectionGeneration !== generation || !ws.ws) throw new Error('Server connection changed');
|
||||
return submitSignedEvent(ws, { blockchainName, blockNumber, prevBlockHash }, signed);
|
||||
}
|
||||
|
||||
async submitRemoteAddBlockBody({ login, storagePwd, blockchainName, blockBodyBytes }) {
|
||||
|
||||
Reference in New Issue
Block a user