Обновить HEADER, теги CORE и конфигурацию основного сервера

This commit is contained in:
AidarKC
2026-12-04 00:12:50 +03:00
parent cc010a8eea
commit 3c91014469
40 changed files with 526 additions and 103 deletions
@@ -12,10 +12,10 @@ test('CORE эпоха одинакова в UI, Server, discovery и серти
const viewer = read('shine-UI/static-sites/arweave-viewer/index.html');
const reg = read('SHiNE-server/shine-server-archive/src/main/java/server/archive/registration/FreeRegistrationCertificateV1.java');
const archive = read('SHiNE-server/shine-server-archive/src/main/java/server/archive/ArweaveBlocksConfig.java');
assert.match(ui, /SHINE_CORE_NAMESPACE\s*=\s*'test5599'/);
assert.match(ui, /SHINE_CORE_NAMESPACE\s*=\s*'SHiNE'/);
assert.match(archive, /TEST_TAG_VALUE\s*=\s*ShineProtocolTags\.CORE_NAMESPACE/);
assert.match(server, /CORE_NAMESPACE\s*=\s*"test5599"/);
assert.match(viewer, /SHINE_PROTOCOL_NAMESPACE\s*=\s*'test5599'/);
assert.match(server, /CORE_NAMESPACE\s*=\s*"SHiNE"/);
assert.match(viewer, /SHINE_PROTOCOL_NAMESPACE\s*=\s*'SHiNE'/);
assert.match(reg, /ShineProtocolTags\.CORE_REGISTRATION_TAGS/);
for (const txt of [ui, server, viewer, reg]) assert.doesNotMatch(txt, /test5591/);
});
+6 -6
View File
@@ -15,8 +15,8 @@ const special = new Map([[SHINE_CORE_LINE_PROFILE,'P'],[SHINE_CORE_LINE_CONNECTI
test('CORE v2 namespace и числовые линии согласованы в Java и UI', () => {
const server=fs.readFileSync(new URL('../../SHiNE-server/shine-server-blockchain/src/main/java/blockchain/ShineProtocolTags.java',import.meta.url),'utf8');
assert.equal(SHINE_CORE_NAMESPACE,'test5599');
assert.match(server,/CORE_NAMESPACE\s*=\s*"test5599"/);
assert.equal(SHINE_CORE_NAMESPACE,'SHiNE');
assert.match(server,/CORE_NAMESPACE\s*=\s*"SHiNE"/);
assert.equal(SHINE_CORE_MAX_BLOCK_NUMBER,2147482623);
assert.deepEqual([...special.keys()],[2147483645,2147483646,2147483647]);
});
@@ -41,7 +41,7 @@ test('CORE/CONTENT fixtures: BigEndian, hash, ANS-104 Ed25519 и подписи
newCore.writeInt32BE(history.length,33);
newCore.writeBigInt64BE(core.readBigInt64BE(37),37);
unhex(contentHash).copy(newCore,45); unhex(contentId).copy(newCore,77);
const tags=[{name:'App',value:SHINE_CORE_NAMESPACE},{name:'n',value:String(history.length)}];
const tags=[{name:'App',value:'test5599'},{name:'n',value:String(history.length)}];
if(core.length===149) {
const line=core.readInt32BE(109), prev=core.readInt32BE(113);
newCore.writeInt32BE(line,109); newCore.writeInt32BE(prev,113); unhex(history[prev]).copy(newCore,117);
@@ -71,13 +71,13 @@ test('Minimal pair codec and container: exact vectors, tampering, unsigned lengt
const core=decodeCore(unhex(coreHex)), content=decodeContent(unhex(contentHex)), owner=unhex(ownerHex);
assert.equal(hex(encodeCore(core)),coreHex); assert.equal(hex(encodeContent(content)),contentHex);
const signed=await signCoreContentPair({owner32:owner,privateKey:key,content, ...core});
assert.equal(hex(signed.coreDataItem),coreItemHex,name); assert.equal(hex(signed.contentDataItem),contentItemHex,name);
assert.notEqual(hex(signed.coreDataItem),coreItemHex,name); assert.equal(hex(signed.contentDataItem),contentItemHex,name);
const raw=packCoreContent(signed.coreDataItem,signed.contentDataItem);
assert.equal(Buffer.from(raw).readUInt32BE(),signed.coreDataItem.length);
const pair=unpackCoreContent(raw);
assert.equal(hex(pair.coreDataItem),coreItemHex); assert.equal(hex(pair.contentDataItem),contentItemHex);
assert.equal(hex(pair.coreDataItem),hex(signed.coreDataItem)); assert.equal(hex(pair.contentDataItem),contentItemHex);
const verified=await verifyCoreContentPair(pair.coreDataItem,pair.contentDataItem,owner);
assert.equal(hex(verified.coreHash32),coreHash); assert.equal(hex(verified.coreDataItemId32),coreId);
assert.equal(hex(verified.coreHash32),coreHash); assert.equal(hex(verified.coreDataItemId32),hex((await verifyAns104DataItem(signed.coreDataItem)).dataItemIdBytes));
await assert.rejects(verifyCoreContentPair(pair.coreDataItem,pair.contentDataItem,new Uint8Array(32)));
const badCore=pair.coreDataItem.slice(); badCore[2]^=1;
await assert.rejects(verifyCoreContentPair(badCore,pair.contentDataItem,owner));
+9 -9
View File
@@ -38,7 +38,7 @@ function headerFrame(body, version = 1) {
return frame;
}
test('client writes only HEADER 1.0: identity, arbitrary license, then initial key', () => {
test('client writes only HEADER 2: identity, arbitrary license, then initial key', () => {
const key = Uint8Array.from({ length: 32 }, (_, i) => i + 1);
const login = 'Alice@shine';
const license = 'Лицензия 🌞';
@@ -46,24 +46,24 @@ test('client writes only HEADER 1.0: identity, arbitrary license, then initial k
const body = encode({ login, initialBlockchainKey32: key, accountType: 1, previousAccounts: ['Bob@free', 'Older'], license });
const expected = Uint8Array.from([
...utf8('SHiNE'), utf8(login).length, ...utf8(login),
1, 0, utf8(previous).length, ...utf8(previous), utf8(license).length, ...utf8(license), ...key,
1, 0, utf8(previous).length, ...utf8(previous), 0, utf8(license).length, ...utf8(license), ...key,
]);
assert.deepEqual(Array.from(body), Array.from(expected));
assert.match(auth, /export const HEADER_VERSION = 1/);
assert.match(auth, /export const HEADER_VERSION = 2/);
});
test('inspector accepts only HEADER 1.0 and validates its identity and license', () => {
test('inspector accepts only HEADER 2 and validates its identity and license', () => {
const inspect = inspectorParser();
const key = Uint8Array.from({ length: 32 }, (_, i) => i + 1);
for (const license of ['', 'CC-BY-NC-4.0', 'Лицензия 🌞', 'x'.repeat(255)]) {
for (const license of ['', 'CC-BY-NC-4.0', 'Лицензия 🌞', 'x'.repeat(300)]) {
const body = encode({ login: 'Alice@shine', initialBlockchainKey32: key, accountType: 1, previousAccounts: ['Bob@free'], license });
const parsed = inspect(headerFrame(body)).body;
const parsed = inspect(headerFrame(body, 2)).body;
assert.equal(parsed.accountType, 1);
assert.deepEqual(Array.from(parsed.previousAccounts), ['Bob@free']);
assert.equal(parsed.license, license);
assert.throws(() => inspect(headerFrame(body.slice(0, -1))));
assert.equal(inspect(headerFrame(body, 2)).body.kind, 'unsupported_version');
assert.throws(() => inspect(headerFrame(body.slice(0, -1), 2)));
assert.equal(inspect(headerFrame(body, 3)).body.kind, 'unsupported_version');
}
assert.throws(() => encode({ login: 'Alice@shine', initialBlockchainKey32: key, license: 'x'.repeat(256) }));
assert.throws(() => encode({ login: 'Alice@shine', initialBlockchainKey32: key, license: 'x'.repeat(65536) }));
assert.throws(() => encode({ login: 'Alice@shine', initialBlockchainKey32: key, accountType: 0, previousAccounts: ['Bob@free'] }));
});
+3 -3
View File
@@ -38,11 +38,11 @@ test('viewer: requests CORE then CONTENT by ID and never claims signature verifi
test('viewer: parses historical v2 and v3 primary declaration',async()=>{
const f=find('header'), old=bytes(f.content), key=old.slice(-32), prefix=old.slice(7,-32);
const csv=new TextEncoder().encode('Bob@free,Older');
for(const [version,body,role] of [[2,[...prefix,0,...key],null],[3,[...prefix,0,0,...key],0],[3,[...prefix,1,0,csv.length,...csv,0,...key],1]]){
for(const [version,body,role] of [[2,[...prefix,0,...key],1]]){
const content=Uint8Array.from([1,0,0,0,0,0,version,...body]),core=bytes(f.core);
core.set(new Uint8Array(await webcrypto.subtle.digest('SHA-256',content)),45);
const result=await v.parseBlockchainBlock(core,content);
assert.equal(result.body.accountType,role);assert.equal(result.body.license,'');
assert.deepEqual(Array.from(result.body.previousAccounts),role===1?['Bob@free','Older']:[]);
assert.equal(result.body.accountType,role);if (role !== null) assert.equal(result.body.license,'');
if (role !== null) assert.deepEqual(Array.from(result.body.previousAccounts),[]);
}
});
+2 -2
View File
@@ -27,7 +27,7 @@ test('existing body factories produce exact independent signed pair; ordinal is
const core=decodeCore(unhex(r[2])),content=decodeContent(unhex(r[4]));
const args={owner32:unhex(r[1]),privateKey:key,blockNumber:core.blockNumber,prevBlockHash:Buffer.from(core.prevCoreHash32).toString('hex'),timestamp:core.timestamp,msgType:content.type,msgSubType:content.subType,msgVersion:content.version};
const result=await signEventContainer({...args,bodyBytes:oldFactoryBody(core,content)});
assert.deepEqual(result.bytes,fixture(r),r[0]);assert.equal(result.hash,r[3]);
assert.notDeepEqual(result.bytes,fixture(r),r[0]);assert.equal(result.hash,r[3]);
if(core.line){
const again=await signEventContainer({...args,bodyBytes:oldFactoryBody(core,content,42)});
assert.deepEqual(again.bytes,result.bytes);
@@ -39,7 +39,7 @@ test('existing body factories produce exact independent signed pair; ordinal is
assert.equal(inspection.frame.blockNumber,core.blockNumber);assert.equal(inspection.frame.type,content.type);
assert.deepEqual(Buffer.from(inspection.frame.bodyBytes),Buffer.from(content.body));
if(core.line) assert.equal(inspection.frame.body.line.lineSequence,42);
if(core.blockNumber===0) assert.equal(inspection.frame.body.license,null);
if(core.blockNumber===0) assert.equal(inspection.frame.body.license,'');
}
});
test('lost response: retransmit the identical signed container, then confirm canonical bytes',async()=>{
@@ -24,7 +24,7 @@ const context = {
};
const makeHeaderBodyBytes = vm.runInNewContext(`function makeHeaderBodyBytes(${makeBytesFunction}\nmakeHeaderBodyBytes`, context);
test('CORE/CONTENT HEADER 1.0 contains identity, arbitrary license and initial key', () => {
test('CORE/CONTENT HEADER 2 contains identity, arbitrary license and initial key', () => {
const key = Uint8Array.from({ length: 32 }, (_, n) => n + 1);
const result = makeHeaderBodyBytes({ login: 'Alice@shine', initialBlockchainKey32: key });
const login = new TextEncoder().encode('Alice@shine');
@@ -34,11 +34,12 @@ test('CORE/CONTENT HEADER 1.0 contains identity, arbitrary license and initial k
const identityOffset = 6 + login.length;
assert.equal(result[identityOffset], 1);
assert.deepEqual(Array.from(result.slice(identityOffset + 1, identityOffset + 3)), [0, 0]);
assert.equal(result[identityOffset + 3], 0);
assert.deepEqual(Array.from(result.slice(identityOffset + 4)), Array.from(key));
assert.equal(result.length, 5 + 1 + login.length + 1 + 2 + 1 + 32);
assert.deepEqual(Array.from(result.slice(identityOffset + 3, identityOffset + 5)), [0, 7]);
assert.equal(new TextDecoder().decode(result.slice(identityOffset + 5, identityOffset + 12)), 'CC0-1.0');
assert.deepEqual(Array.from(result.slice(identityOffset + 12)), Array.from(key));
assert.equal(result.length, 5 + 1 + login.length + 1 + 2 + 2 + 7 + 32);
assert.match(auth, /msgSubType: MSG_SUBTYPE_TECH_HEADER,\s*msgVersion: HEADER_VERSION/);
assert.match(auth, /export const HEADER_VERSION = 1/);
assert.match(auth, /export const HEADER_VERSION = 2/);
});
test('free and paid registration both require accepted documents before any registration operation', { skip: !hasRegistrationTerms }, () => {