Open-source Xbox-inspired desktop launcher for Xodus on Linux
TypeScript
fix(runtime): retain full release source graph and ancillary metadata
domsvobodada57efcde372
diff --git a/src/main/runtime-family-release.test.ts b/src/main/runtime-family-release.test.tsindex 02c8121..1266dba 100644--- a/src/main/runtime-family-release.test.ts+++ b/src/main/runtime-family-release.test.ts@@ -1,47 +1,192 @@-import {expect,it} from 'vitest';-import {parseManagedFamilyRelease,verifyManagedFamilyCandidate} from './runtime-family-release';+import { expect, it } from 'vitest';+import { parseManagedFamilyRelease, verifyManagedFamilyCandidate } from './runtime-family-release';// Sanitized public c070 release metadata, no download or native execution.-function fixture(family='nexus-cachyos') {- const commit='c0702eafb4ff4043c54e38bc5028ea77fa6a9487',repository='domsvoboda/'+(family==='nexus'?'nexus-runtime':'nexus-runtime-cachyos');- const prefix=family==='nexus'?'nexus-runtime':'nexus-runtime-cachyos',tag=(family==='nexus'?'runtime':'runtime-cachyos')+'-11.0-20261103-gc0702eaf',base=prefix+'-11.0-experimental-gc0702eaf';- const files=[{name:base+'-x86_64.tar.xz',sha256:'aaa55320834ce53e1b238badebbea339aaaf5ead4aeb2707e7dd17144cc493fb',size:401327524},{name:base+'-x86_64.sha512sum',sha256:'6ad003d38ce978fe7ede9fcdbf147c39b584cb4caa058022329667cead51701e',size:194},{name:base+'-source.tar.xz',sha256:'d75d7d496762dce28a1da596573398c238c6ea3403bd08cb1fdc7b55bcee2a6e',size:862538548},{name:base+'-source.sha512sum',sha256:'ac146584bdb7a5a15e15f58cbfba1e139d788a51b3de655f629fb3dcf6187284',size:194}];- const candidate:any={schema:1,kind:'runtime',repository,commit,ref:'refs/heads/main',runId:'41623159548',files,sourceGraph:{proton:commit,wine:'e449547994748ef9688a9b38ccb5dbb9dd4ba3ee',xgameruntime:'78780314332079f77052fbeb345b6f7e11e7a44d'},requiresBackendVersion:'0.2.13',requiresLauncherVersion:'0.4.1',validation:{nativeGateCount:12,treeSha256:'2cdce736bcd0234638fdcf9183c0a885bcf69eb2ec2159602025ec7fc9d0313d',resultsSha256:'45e2389a1fccec9613733bccafc89335eed48f31dafbaadf8132e4487c2c872f',realGameTest:false,stableApproved:false}};- const release:any={tag_name:tag,target_commitish:commit,draft:false,prerelease:true,published_at:'2026-11-03T12:43:55Z',assets:[]};- const policy:any={arch:'x64',allowCachyos:true,allowPrerelease:true,launcherVersion:'0.4.2',backendVersion:'0.2.14'};- const sync=()=>{const bytes=JSON.stringify(candidate);release.assets=[{name:'candidate.json',size:Buffer.byteLength(bytes)},...files.map(file=>({name:file.name,size:file.size}))].map(file=>({...file,browser_download_url:`https://github.com/${repository}/releases/download/${tag}/${file.name}`}));return bytes;};- const bytes=sync();return{family,release,policy,candidate,bytes,sync,parse:()=>parseManagedFamilyRelease(family,release,policy)};+function fixture(family = 'nexus-cachyos') {+ const commit = 'c0702eafb4ff4043c54e38bc5028ea77fa6a9487', repository = 'domsvoboda/' + (family === 'nexus' ? 'nexus-runtime' : 'nexus-runtime-cachyos');+ const prefix = family === 'nexus' ? 'nexus-runtime' : 'nexus-runtime-cachyos', tag = (family === 'nexus' ? 'runtime' : 'runtime-cachyos') + '-11.0-20261103-gc0702eaf', base = prefix + '-11.0-experimental-gc0702eaf';+ const files = [{+ name: base + '-x86_64.tar.xz', sha256: 'aaa55320834ce53e1b238badebbea339aaaf5ead4aeb2707e7dd17144cc493fb', size: 401327524+ }, {+ name: base + '-x86_64.sha512sum', sha256: '6ad003d38ce978fe7ede9fcdbf147c39b584cb4caa058022329667cead51701e', size: 194+ }, {+ name: base + '-source.tar.xz', sha256: 'd75d7d496762dce28a1da596573398c238c6ea3403bd08cb1fdc7b55bcee2a6e', size: 862538548+ }, {+ name: base + '-source.sha512sum', sha256: 'ac146584bdb7a5a15e15f58cbfba1e139d788a51b3de655f629fb3dcf6187284', size: 194+ }];+ const candidate: any = {+ schema: 1, kind: 'runtime', repository, commit, ref: 'refs/heads/main', runId: '41623159548', files, sourceGraph: {+ proton: commit, wine: 'e449547994748ef9688a9b38ccb5dbb9dd4ba3ee', xgameruntime: '78780314332079f77052fbeb345b6f7e11e7a44d'+ }, requiresBackendVersion: '0.2.13', requiresLauncherVersion: '0.4.1', validation: {+ nativeGateCount: 12, treeSha256: '2cdce736bcd0234638fdcf9183c0a885bcf69eb2ec2159602025ec7fc9d0313d', resultsSha256: '45e2389a1fccec9613733bccafc89335eed48f31dafbaadf8132e4487c2c872f', realGameTest: false, stableApproved: false+ }+ };+ const release: any = {+ tag_name: tag, target_commitish: commit, draft: false, prerelease: true, published_at: '2026-11-03T12:43:55Z', assets: []+ };+ const policy: any = {+ arch: 'x64', allowCachyos: true, allowPrerelease: true, launcherVersion: '0.4.2', backendVersion: '0.2.14'+ };+ const sync = () => {+ const bytes = JSON.stringify(candidate);+ release.assets = [{+ name: 'candidate.json', size: Buffer.byteLength(bytes)+ }, ...files.map(file => ({+ name: file.name, size: file.size+ }))].map(file => ({+ ...file, browser_download_url: `https://github.com/${repository}/releases/download/${tag}/${file.name}`+ }));+ return bytes;+ };+ const bytes = sync();+ return {+ family, release, policy, candidate, bytes, sync, parse: () => parseManagedFamilyRelease(family, release, policy)+ };}-it('accepts the actual c070 binary/source metadata contract offline without claiming native or stable approval',()=>{- const f=fixture(),selected=f.parse(),verified=verifyManagedFamilyCandidate(f.bytes,selected);expect(verified.commit).toBe(f.candidate.commit);expect(verified.files).toHaveLength(4);expect(verified.validation.nativeGateCount).toBe(12);expect(verified.validation.realGameTest).toBe(false);expect(verified.validation.stableApproved).toBe(false);expect(verified.candidateSha256).toMatch(/^[a-f0-9]{64}$/);expect(Object.isFrozen(verified)).toBe(true);expect(Object.isFrozen(verified.files[0])).toBe(true);-});-it('supports the standard fixed-repository contract as a synthetic future manifest release, without CachyOS opt-in',()=>{const f=fixture('nexus');f.policy.allowCachyos=false;expect(verifyManagedFamilyCandidate(f.bytes,f.parse()).family).toBe('nexus');});-it('requires distinct explicit CachyOS and prerelease permissions, and never accepts drafts',()=>{- for(const key of ['allowCachyos','allowPrerelease']){const f=fixture();f.policy[key]=false;expect(()=>f.parse()).toThrow('opt-in');}- const f=fixture();f.release.draft=true;expect(()=>f.parse()).toThrow('Draft');-});-it.each([undefined,null,[],true,1,'family'])('rejects non-object external release %s',value=>{const f=fixture();expect(()=>parseManagedFamilyRelease(f.family,value,f.policy)).toThrow();});-it.each(['draft','prerelease'])('requires a real boolean %s',key=>{for(const value of [undefined,'false',0,null]){const f=fixture();f.release[key]=value;expect(()=>f.parse()).toThrow();}});-it.each(['allowCachyos','allowPrerelease'])('rejects truthy or absent policy %s',key=>{for(const value of [undefined,'true',1,null]){const f=fixture();f.policy[key]=value;expect(()=>f.parse()).toThrow();}});-it.each(['arm64','x86_64','../nexus',undefined])('does not widen managed architecture %s',arch=>{const f=fixture();f.policy.arch=arch;expect(()=>f.parse()).toThrow('x64');});-it.each(['../runtime','runtime-../x-gc0702eaf','runtime-cachyos-11%2f-gc0702eaf','runtime-cachyos-11-gc0702eaf?x','runtime-cachyos-11-gdeadbeef'])('rejects unsafe or mismatched tag %s',tag=>{const f=fixture();f.release.tag_name=tag;expect(()=>f.parse()).toThrow();});-it.each(['https://evil.invalid/file','http://github.com/x','https://github.com/domsvoboda/nexus-runtime/releases/download/x/y','https://github.com:443/x','https://[email protected]/x'])('rejects arbitrary asset origin/path %s',url=>{const f=fixture();f.release.assets[1].browser_download_url=url;expect(()=>f.parse()).toThrow('URL');});-it('rejects duplicate assets, encoded traversal, query suffix and missing source pairs',()=>{- for(const mutate of [(f:ReturnType<typeof fixture>)=>f.release.assets.push(f.release.assets[0]),(f:ReturnType<typeof fixture>)=>f.release.assets[4]=f.release.assets[3],(f:ReturnType<typeof fixture>)=>f.release.assets[1].name='../escape',(f:ReturnType<typeof fixture>)=>f.release.assets[1].browser_download_url+='?download=1',(f:ReturnType<typeof fixture>)=>f.release.assets.pop()]){const f=fixture();mutate(f);expect(()=>f.parse()).toThrow();}-});-it.each([0,-1,1.5,NaN,Infinity,Number.MAX_SAFE_INTEGER+1,'194',33*1024**3])('rejects invalid release size %s',value=>{const f=fixture();f.release.assets[1].size=value;expect(()=>f.parse()).toThrow('size');});-it.each(['0.4','v0.4.2','0.4.2-beta','01.4.2','0.4.NaN','9999999.0.0',null])('validates installed version syntax %s before comparison',value=>{const f=fixture();f.policy.launcherVersion=value;expect(()=>f.parse()).toThrow('version');});-it('does not accept a caller-forged or copied release descriptor',()=>{const f=fixture(),selected=f.parse();expect(()=>verifyManagedFamilyCandidate(f.bytes,{...selected})).toThrow('locally verified');expect(()=>verifyManagedFamilyCandidate(f.bytes,null)).toThrow();});-it.each(['repository','commit','ref','kind','schema','runId'])('rejects candidate identity mismatch %s',key=>{const f=fixture();f.candidate[key]=key==='schema'?2:'invalid';const bytes=f.sync();expect(()=>verifyManagedFamilyCandidate(bytes,f.parse())).toThrow();});-it('requires candidate source graph to bind exact Proton/Wine/XGR commits',()=>{for(const key of ['proton','wine','xgameruntime']){const f=fixture();f.candidate.sourceGraph[key]='d'.repeat(key==='proton'?40:39);const bytes=f.sync();expect(()=>verifyManagedFamilyCandidate(bytes,f.parse())).toThrow();}});-it('rejects missing, duplicate, foreign and size/hash-mismatched candidate file records',()=>{- const changes=[(f:ReturnType<typeof fixture>)=>f.candidate.files.pop(),(f:ReturnType<typeof fixture>)=>f.candidate.files[3]=f.candidate.files[2],(f:ReturnType<typeof fixture>)=>f.candidate.files[0].name='foreign.tar.xz',(f:ReturnType<typeof fixture>)=>f.candidate.files[0].sha256='z'.repeat(64)];- for(const mutate of changes){const f=fixture();mutate(f);const bytes=JSON.stringify(f.candidate);f.release.assets[0].size=Buffer.byteLength(bytes);expect(()=>verifyManagedFamilyCandidate(bytes,f.parse())).toThrow();}- const f=fixture();f.candidate.files[0].size++;const bytes=JSON.stringify(f.candidate);f.release.assets[0].size=Buffer.byteLength(bytes);expect(()=>verifyManagedFamilyCandidate(bytes,f.parse())).toThrow('size');-});-it.each(['nativeGateCount','treeSha256','resultsSha256','realGameTest','stableApproved'])('requires validation evidence shape %s without interpreting it as approval',key=>{const f=fixture();f.candidate.validation[key]=key==='nativeGateCount'?11:key.endsWith('Sha256')?'bad':'false';const bytes=f.sync();expect(()=>verifyManagedFamilyCandidate(bytes,f.parse())).toThrow();});-it('rejects malformed requirements and incompatible installed components',()=>{- for(const [key,value] of [['requiresLauncherVersion','0.5.0'],['requiresBackendVersion','1.0.0'],['requiresBackendVersion','bad']] as const){const f=fixture();f.candidate[key]=value;const bytes=f.sync();expect(()=>verifyManagedFamilyCandidate(bytes,f.parse())).toThrow();}-});-it('rejects metadata size mismatch, malformed JSON and invalid UTF-8',()=>{const f=fixture(),selected=f.parse();expect(()=>verifyManagedFamilyCandidate(f.bytes+' ',selected)).toThrow('size');expect(()=>verifyManagedFamilyCandidate({},selected)).toThrow('bytes');const bad=Buffer.alloc(f.release.assets[0].size,0xff);expect(()=>verifyManagedFamilyCandidate(bad,selected)).toThrow('UTF-8');expect(()=>verifyManagedFamilyCandidate(' '.repeat(f.release.assets[0].size),selected)).toThrow();});--it('binds the full release target when available, not only the short display commit',()=>{const f=fixture();f.candidate.commit='c0702eaf'+'d'.repeat(32);f.candidate.sourceGraph.proton=f.candidate.commit;const bytes=f.sync();expect(()=>verifyManagedFamilyCandidate(bytes,f.parse())).toThrow('target commit');});+it('accepts the actual c070 binary/source metadata contract offline without claiming native or stable approval', () => {+ const f = fixture(), selected = f.parse(), verified = verifyManagedFamilyCandidate(f.bytes, selected);+ expect(verified.commit).toBe(f.candidate.commit);+ expect(verified.files).toHaveLength(4);+ expect(verified.validation.nativeGateCount).toBe(12);+ expect(verified.validation.realGameTest).toBe(false);+ expect(verified.validation.stableApproved).toBe(false);+ expect(verified.candidateSha256).toMatch(/^[a-f0-9]{64}$/);+ expect(Object.isFrozen(verified)).toBe(true);+ expect(Object.isFrozen(verified.files[0])).toBe(true);+});+it('supports the standard fixed-repository contract as a synthetic future manifest release, without CachyOS opt-in', () => {+ const f = fixture('nexus');+ f.policy.allowCachyos = false;+ expect(verifyManagedFamilyCandidate(f.bytes, f.parse()).family).toBe('nexus');+});+it('requires distinct explicit CachyOS and prerelease permissions, and never accepts drafts', () => {+ for (const key of ['allowCachyos', 'allowPrerelease']) {+ const f = fixture();+ f.policy[key] = false;+ expect(() => f.parse()).toThrow('opt-in');+ }+ const f = fixture();+ f.release.draft = true;+ expect(() => f.parse()).toThrow('Draft');+});+it.each([undefined, null, [], true, 1, 'family'])('rejects non-object external release %s', value => {+ const f = fixture();+ expect(() => parseManagedFamilyRelease(f.family, value, f.policy)).toThrow();+});+it.each(['draft', 'prerelease'])('requires a real boolean %s', key => {+ for (const value of [undefined, 'false', 0, null]) {+ const f = fixture();+ f.release[key] = value;+ expect(() => f.parse()).toThrow();+ }+});+it.each(['allowCachyos', 'allowPrerelease'])('rejects truthy or absent policy %s', key => {+ for (const value of [undefined, 'true', 1, null]) {+ const f = fixture();+ f.policy[key] = value;+ expect(() => f.parse()).toThrow();+ }+});+it.each(['arm64', 'x86_64', '../nexus', undefined])('does not widen managed architecture %s', arch => {+ const f = fixture();+ f.policy.arch = arch;+ expect(() => f.parse()).toThrow('x64');+});+it.each(['../runtime', 'runtime-../x-gc0702eaf', 'runtime-cachyos-11%2f-gc0702eaf', 'runtime-cachyos-11-gc0702eaf?x', 'runtime-cachyos-11-gdeadbeef'])('rejects unsafe or mismatched tag %s', tag => {+ const f = fixture();+ f.release.tag_name = tag;+ expect(() => f.parse()).toThrow();+});+it.each(['https://evil.invalid/file', 'http://github.com/x', 'https://github.com/domsvoboda/nexus-runtime/releases/download/x/y', 'https://github.com:443/x', 'https://[email protected]/x'])('rejects arbitrary asset origin/path %s', url => {+ const f = fixture();+ f.release.assets[1].browser_download_url = url;+ expect(() => f.parse()).toThrow('URL');+});+it('rejects duplicate assets, encoded traversal, query suffix and missing source pairs', () => {+ for (const mutate of [(f: ReturnType<typeof fixture>) => f.release.assets.push(f.release.assets[0]), (f: ReturnType<typeof fixture>) => f.release.assets[4] = f.release.assets[3], (f: ReturnType<typeof fixture>) => f.release.assets[1].name = '../escape', (f: ReturnType<typeof fixture>) => f.release.assets[1].browser_download_url += '?download=1', (f: ReturnType<typeof fixture>) => f.release.assets.pop()]) {+ const f = fixture();+ mutate(f);+ expect(() => f.parse()).toThrow();+ }+});+it.each([0, -1, 1.5, NaN, Infinity, Number.MAX_SAFE_INTEGER + 1, '194', 33 * 1024 ** 3])('rejects invalid release size %s', value => {+ const f = fixture();+ f.release.assets[1].size = value;+ expect(() => f.parse()).toThrow('size');+});+it.each(['0.4', 'v0.4.2', '0.4.2-beta', '01.4.2', '0.4.NaN', '9999999.0.0', null])('validates installed version syntax %s before comparison', value => {+ const f = fixture();+ f.policy.launcherVersion = value;+ expect(() => f.parse()).toThrow('version');+});+it('does not accept a caller-forged or copied release descriptor', () => {+ const f = fixture(), selected = f.parse();+ expect(() => verifyManagedFamilyCandidate(f.bytes, {+ ...selected+ })).toThrow('locally verified');+ expect(() => verifyManagedFamilyCandidate(f.bytes, null)).toThrow();+});+it.each(['repository', 'commit', 'ref', 'kind', 'schema', 'runId'])('rejects candidate identity mismatch %s', key => {+ const f = fixture();+ f.candidate[key] = key === 'schema' ? 2 : 'invalid';+ const bytes = f.sync();+ expect(() => verifyManagedFamilyCandidate(bytes, f.parse())).toThrow();+});+it('requires candidate source graph to bind exact Proton/Wine/XGR commits', () => {+ for (const key of ['proton', 'wine', 'xgameruntime']) {+ const f = fixture();+ f.candidate.sourceGraph[key] = 'd'.repeat(key === 'proton' ? 40 : 39);+ const bytes = f.sync();+ expect(() => verifyManagedFamilyCandidate(bytes, f.parse())).toThrow();+ }+});+it('rejects missing, duplicate, foreign and size/hash-mismatched candidate file records', () => {+ const changes = [(f: ReturnType<typeof fixture>) => f.candidate.files.pop(), (f: ReturnType<typeof fixture>) => f.candidate.files[3] = f.candidate.files[2], (f: ReturnType<typeof fixture>) => f.candidate.files[0].name = 'foreign.tar.xz', (f: ReturnType<typeof fixture>) => f.candidate.files[0].sha256 = 'z'.repeat(64)];+ for (const mutate of changes) {+ const f = fixture();+ mutate(f);+ const bytes = JSON.stringify(f.candidate);+ f.release.assets[0].size = Buffer.byteLength(bytes);+ expect(() => verifyManagedFamilyCandidate(bytes, f.parse())).toThrow();+ }+ const f = fixture();+ f.candidate.files[0].size++;+ const bytes = JSON.stringify(f.candidate);+ f.release.assets[0].size = Buffer.byteLength(bytes);+ expect(() => verifyManagedFamilyCandidate(bytes, f.parse())).toThrow('size');+});+it.each(['nativeGateCount', 'treeSha256', 'resultsSha256', 'realGameTest', 'stableApproved'])('requires validation evidence shape %s without interpreting it as approval', key => {+ const f = fixture();+ f.candidate.validation[key] = key === 'nativeGateCount' ? 11 : key.endsWith('Sha256') ? 'bad' : 'false';+ const bytes = f.sync();+ expect(() => verifyManagedFamilyCandidate(bytes, f.parse())).toThrow();+});+it('rejects malformed requirements and incompatible installed components', () => {+ for (const [key, value] of [['requiresLauncherVersion', '0.5.0'], ['requiresBackendVersion', '1.0.0'], ['requiresBackendVersion', 'bad']] as const) {+ const f = fixture();+ f.candidate[key] = value;+ const bytes = f.sync();+ expect(() => verifyManagedFamilyCandidate(bytes, f.parse())).toThrow();+ }+});+it('rejects metadata size mismatch, malformed JSON and invalid UTF-8', () => {+ const f = fixture(), selected = f.parse();+ expect(() => verifyManagedFamilyCandidate(f.bytes + ' ', selected)).toThrow('size');+ expect(() => verifyManagedFamilyCandidate({}, selected)).toThrow('bytes');+ const bad = Buffer.alloc(f.release.assets[0].size, 0xff);+ expect(() => verifyManagedFamilyCandidate(bad, selected)).toThrow('UTF-8');+ expect(() => verifyManagedFamilyCandidate(' '.repeat(f.release.assets[0].size), selected)).toThrow();+});+it('binds the full release target when available, not only the short display commit', () => {+ const f = fixture();+ f.candidate.commit = 'c0702eaf' + 'd'.repeat(32);+ f.candidate.sourceGraph.proton = f.candidate.commit;+ const bytes = f.sync();+ expect(() => verifyManagedFamilyCandidate(bytes, f.parse())).toThrow('target commit');+});+it('allows bounded ancillary release assets without weakening selected pair identity', () => {+ const f = fixture();+ f.release.assets.push({+ name: 'LICENSE', size: 100, browser_download_url: f.release.assets[0].browser_download_url.replace('candidate.json', 'LICENSE')+ });+ expect(verifyManagedFamilyCandidate(f.bytes, f.parse()).files).toHaveLength(4);+});diff --git a/src/main/runtime-family-release.ts b/src/main/runtime-family-release.tsindex 016cc33..e44c9a0 100644--- a/src/main/runtime-family-release.ts+++ b/src/main/runtime-family-release.ts@@ -1,111 +1,229 @@-import {createHash} from 'node:crypto';-import type {RuntimeFamily} from '../shared/runtime-selection.js';-const repositories={nexus:'domsvoboda/nexus-runtime','nexus-cachyos':'domsvoboda/nexus-runtime-cachyos'} as const;-const selectedReleases=new WeakSet<object>();-const maxMetadata=2*1024*1024,maxChecksum=64*1024;-interface Asset {readonly name:string;readonly url:string;readonly size:number;}+import { createHash } from 'node:crypto';+import type { RuntimeFamily } from '../shared/runtime-selection.js';+const repositories = {+ nexus: 'domsvoboda/nexus-runtime', 'nexus-cachyos': 'domsvoboda/nexus-runtime-cachyos'+} as const;+const selectedReleases = new WeakSet<object>();+const maxMetadata = 2 * 1024 * 1024, maxChecksum = 64 * 1024;+interface Asset {+ readonly name: string;+ readonly url: string;+ readonly size: number;+}export interface ManagedFamilyRelease {- readonly family:RuntimeFamily;readonly repository:string;readonly tag:string;readonly commitHint:string;- readonly targetCommitish:string;readonly arch:'x64';readonly prerelease:boolean;readonly publishedAt:string;- readonly assets:Readonly<{candidate:Asset;binary:Asset;checksum:Asset;source:Asset;sourceChecksum:Asset}>;- readonly installedVersions:Readonly<{launcher:string;backend:string}>;+ readonly family: RuntimeFamily;+ readonly repository: string;+ readonly tag: string;+ readonly commitHint: string;+ readonly targetCommitish: string;+ readonly arch: 'x64';+ readonly prerelease: boolean;+ readonly publishedAt: string;+ readonly assets: Readonly<{+ candidate: Asset;+ binary: Asset;+ checksum: Asset;+ source: Asset;+ sourceChecksum: Asset;+ }>;+ readonly installedVersions: Readonly<{+ launcher: string;+ backend: string;+ }>;}export interface VerifiedManagedFamilyRelease extends ManagedFamilyRelease {- readonly commit:string;readonly runId:string;readonly candidateSha256:string;- readonly files:readonly Readonly<{name:string;size:number;sha256:string}>[];- readonly requiresLauncherVersion:string;readonly requiresBackendVersion:string;- readonly sourceGraph:Readonly<{proton:string;wine:string;xgameruntime:string}>;- /** Publisher metadata only, not an independent native test or release approval. */- readonly validation:Readonly<{nativeGateCount:12;treeSha256:string;resultsSha256:string;realGameTest:boolean;stableApproved:boolean}>;+ readonly commit: string;+ readonly runId: string;+ readonly candidateSha256: string;+ readonly files: readonly Readonly<{+ name: string;+ size: number;+ sha256: string;+ }>[];+ readonly requiresLauncherVersion: string;+ readonly requiresBackendVersion: string;+ readonly sourceGraph: Readonly<Record<string, unknown>>;+ /** Publisher metadata only, not an independent native test or release approval. */+ readonly validation: Readonly<{+ nativeGateCount: 12;+ treeSha256: string;+ resultsSha256: string;+ realGameTest: boolean;+ stableApproved: boolean;+ }>;+}+function record(value: unknown, label: string): Record<string, unknown> {+ if (!value || typeof value !== 'object' || Array.isArray(value))+ throw Error('Invalid ' + label);+ return value as Record<string, unknown>;}-function record(value:unknown,label:string):Record<string,unknown> {- if(!value||typeof value!=='object'||Array.isArray(value))throw Error('Invalid '+label);return value as Record<string,unknown>;+function text(value: unknown, pattern: RegExp, label: string, max = 160): string {+ if (typeof value !== 'string' || value.length > max || !pattern.test(value))+ throw Error('Invalid ' + label);+ return value;}-function text(value:unknown,pattern:RegExp,label:string,max=160):string {- if(typeof value!=='string'||value.length>max||!pattern.test(value))throw Error('Invalid '+label);return value;+function flag(value: unknown, label: string): boolean {+ if (typeof value !== 'boolean')+ throw Error('Invalid ' + label);+ return value;}-function flag(value:unknown,label:string):boolean {if(typeof value!=='boolean')throw Error('Invalid '+label);return value;}-function size(value:unknown,max:number,label:string):number {- if(typeof value!=='number'||!Number.isSafeInteger(value)||value<=0||value>max)throw Error('Invalid '+label);return value;+function size(value: unknown, max: number, label: string): number {+ if (typeof value !== 'number' || !Number.isSafeInteger(value) || value <= 0 || value > max)+ throw Error('Invalid ' + label);+ return value;}-function version(value:unknown,label:string):string {- const result=text(value,/^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$/,label,48);- if(result.split('.').some(part=>!Number.isSafeInteger(Number(part))||Number(part)>999999))throw Error('Invalid '+label);return result;+function version(value: unknown, label: string): string {+ const result = text(value, /^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$/, label, 48);+ if (result.split('.').some(part => !Number.isSafeInteger(Number(part)) || Number(part) > 999999))+ throw Error('Invalid ' + label);+ return result;}-function sufficient(installed:string,required:string):boolean {- const a=installed.split('.').map(Number),b=required.split('.').map(Number);- for(let i=0;i<3;i++){if(a[i]!==b[i])return a[i]>b[i];}return true;+function sufficient(installed: string, required: string): boolean {+ const a = installed.split('.').map(Number), b = required.split('.').map(Number);+ for (let i = 0; i < 3; i++) {+ if (a[i] !== b[i])+ return a[i] > b[i];+ }+ return true;}-const sha=(value:unknown,label:string)=>text(value,/^[a-f0-9]{64}$/,label,64);+const sha = (value: unknown, label: string) => text(value, /^[a-f0-9]{64}$/, label, 64);/** Pure published-release selection. There is no network access, archive* extraction, installation or implicit CachyOS/prerelease opt-in here. */-export function parseManagedFamilyRelease(family:unknown,value:unknown,options:unknown):Readonly<ManagedFamilyRelease> {- if(family!=='nexus'&&family!=='nexus-cachyos')throw Error('Unknown managed runtime family');- const policy=record(options,'runtime release policy');- if(policy.arch!=='x64')throw Error('Managed family payload requires reviewed x64 architecture');- const allowCachyos=flag(policy.allowCachyos,'CachyOS opt-in'),allowPrerelease=flag(policy.allowPrerelease,'prerelease opt-in');- if(family==='nexus-cachyos'&&!allowCachyos)throw Error('Explicit CachyOS opt-in is required');- const launcher=version(policy.launcherVersion,'installed launcher version'),backend=version(policy.backendVersion,'installed backend version');- const release=record(value,'runtime release');- if(flag(release.draft,'draft flag'))throw Error('Draft runtime releases are not installable');- const prerelease=flag(release.prerelease,'prerelease flag');if(prerelease&&!allowPrerelease)throw Error('Explicit prerelease opt-in is required');- const prefix=family==='nexus'?'runtime-':'runtime-cachyos-';- const tag=text(release.tag_name,/^[A-Za-z0-9][A-Za-z0-9._-]*$/,'runtime release tag',128);- if(!tag.startsWith(prefix)||tag.includes('..'))throw Error('Unexpected runtime release tag');- const hint=tag.match(/-g([a-f0-9]{8,40})$/)?.[1];if(!hint)throw Error('Runtime release tag must bind a source commit');- const targetCommitish=text(release.target_commitish,/^(?:main|[a-f0-9]{40})$/,'release target commit',40);- const publishedAt=text(release.published_at,/^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(?:\.\d+)?Z$/,'publication date',40);- if(!Number.isFinite(Date.parse(publishedAt)))throw Error('Invalid publication date');- if(!Array.isArray(release.assets)||release.assets.length!==5)throw Error('Expected unique candidate, binary and corresponding-source assets');- const repository=repositories[family],assets=new Map<string,Asset>();- for(const input of release.assets){- const item=record(input,'release asset'),name=text(item.name,/^[A-Za-z0-9][A-Za-z0-9._-]*$/,'release asset name',200);- if(name.includes('..')||assets.has(name))throw Error('Duplicate or unsafe release asset');- const url=`https://github.com/${repository}/releases/download/${tag}/${name}`;- if(item.browser_download_url!==url)throw Error('Release asset URL must match its fixed repository, tag and name');- assets.set(name,Object.freeze({name,url,size:size(item.size,32*1024**3,'release asset size')}));- }- const assetPrefix=family==='nexus'?'nexus-runtime-':'nexus-runtime-cachyos-';- const binary=[...assets.values()].filter(item=>item.name.startsWith(assetPrefix)&&new RegExp('^'+assetPrefix+'[0-9][A-Za-z0-9._-]*-g([a-f0-9]{8,40})-x86_64\\.tar\\.xz$').test(item.name));- if(binary.length!==1)throw Error('Expected one exact family binary archive');- const name=binary[0].name,archiveHint=name.match(/-g([a-f0-9]{8,40})-x86_64\.tar\.xz$/)![1];- if(hint!==archiveHint)throw Error('Runtime archive and release tag source commits differ');- const base=name.slice(0,-'-x86_64.tar.xz'.length);- const get=(name:string,max:number)=>{const asset=assets.get(name);if(!asset)throw Error('Missing corresponding runtime asset: '+name);size(asset.size,max,'runtime asset size');return asset;};- const selected=Object.freeze({candidate:get('candidate.json',maxMetadata),binary:get(name,8*1024**3),checksum:get(base+'-x86_64.sha512sum',maxChecksum),source:get(base+'-source.tar.xz',32*1024**3),sourceChecksum:get(base+'-source.sha512sum',maxChecksum)});- const result=Object.freeze({family,repository,tag,commitHint:hint,arch:'x64' as const,targetCommitish,prerelease,publishedAt,assets:selected,installedVersions:Object.freeze({launcher,backend})});- selectedReleases.add(result);return result;+export function parseManagedFamilyRelease(family: unknown, value: unknown, options: unknown): Readonly<ManagedFamilyRelease> {+ if (family !== 'nexus' && family !== 'nexus-cachyos')+ throw Error('Unknown managed runtime family');+ const policy = record(options, 'runtime release policy');+ if (policy.arch !== 'x64')+ throw Error('Managed family payload requires reviewed x64 architecture');+ const allowCachyos = flag(policy.allowCachyos, 'CachyOS opt-in'), allowPrerelease = flag(policy.allowPrerelease, 'prerelease opt-in');+ if (family === 'nexus-cachyos' && !allowCachyos)+ throw Error('Explicit CachyOS opt-in is required');+ const launcher = version(policy.launcherVersion, 'installed launcher version'), backend = version(policy.backendVersion, 'installed backend version');+ const release = record(value, 'runtime release');+ if (flag(release.draft, 'draft flag'))+ throw Error('Draft runtime releases are not installable');+ const prerelease = flag(release.prerelease, 'prerelease flag');+ if (prerelease && !allowPrerelease)+ throw Error('Explicit prerelease opt-in is required');+ const prefix = family === 'nexus' ? 'runtime-' : 'runtime-cachyos-';+ const tag = text(release.tag_name, /^[A-Za-z0-9][A-Za-z0-9._-]*$/, 'runtime release tag', 128);+ if (!tag.startsWith(prefix) || tag.includes('..'))+ throw Error('Unexpected runtime release tag');+ const hint = tag.match(/-g([a-f0-9]{8,40})$/)?.[1];+ if (!hint)+ throw Error('Runtime release tag must bind a source commit');+ const targetCommitish = text(release.target_commitish, /^(?:main|[a-f0-9]{40})$/, 'release target commit', 40);+ const publishedAt = text(release.published_at, /^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(?:\.\d+)?Z$/, 'publication date', 40);+ if (!Number.isFinite(Date.parse(publishedAt)))+ throw Error('Invalid publication date');+ if (!Array.isArray(release.assets) || release.assets.length < 5 || release.assets.length > 64)+ throw Error('Expected unique candidate, binary and corresponding-source assets');+ const repository = repositories[family], assets = new Map<string, Asset>();+ for (const input of release.assets) {+ const item = record(input, 'release asset'), name = text(item.name, /^[A-Za-z0-9][A-Za-z0-9._-]*$/, 'release asset name', 200);+ if (name.includes('..') || assets.has(name))+ throw Error('Duplicate or unsafe release asset');+ const url = `https://github.com/${repository}/releases/download/${tag}/${name}`;+ if (item.browser_download_url !== url)+ throw Error('Release asset URL must match its fixed repository, tag and name');+ assets.set(name, Object.freeze({+ name, url, size: size(item.size, 32 * 1024 ** 3, 'release asset size')+ }));+ }+ const assetPrefix = family === 'nexus' ? 'nexus-runtime-' : 'nexus-runtime-cachyos-';+ const binary = [...assets.values()].filter(item => item.name.startsWith(assetPrefix) && new RegExp('^' + assetPrefix + '[0-9][A-Za-z0-9._-]*-g([a-f0-9]{8,40})-x86_64\\.tar\\.xz$').test(item.name));+ if (binary.length !== 1)+ throw Error('Expected one exact family binary archive');+ const name = binary[0].name, archiveHint = name.match(/-g([a-f0-9]{8,40})-x86_64\.tar\.xz$/)![1];+ if (hint !== archiveHint)+ throw Error('Runtime archive and release tag source commits differ');+ const base = name.slice(0, -'-x86_64.tar.xz'.length);+ const get = (name: string, max: number) => {+ const asset = assets.get(name);+ if (!asset)+ throw Error('Missing corresponding runtime asset: ' + name);+ size(asset.size, max, 'runtime asset size');+ return asset;+ };+ const selected = Object.freeze({+ candidate: get('candidate.json', maxMetadata), binary: get(name, 8 * 1024 ** 3), checksum: get(base + '-x86_64.sha512sum', maxChecksum), source: get(base + '-source.tar.xz', 32 * 1024 ** 3), sourceChecksum: get(base + '-source.sha512sum', maxChecksum)+ });+ const result = Object.freeze({+ family, repository, tag, commitHint: hint, arch: 'x64' as const, targetCommitish, prerelease, publishedAt, assets: selected, installedVersions: Object.freeze({+ launcher, backend+ })+ });+ selectedReleases.add(result);+ return result;}/** Bind candidate metadata to already selected fixed release assets. The family* manifest is authenticated later through the verified archive bytes and full* payload validation; candidate.json does not contain its standalone hash. */-export function verifyManagedFamilyCandidate(bytes:unknown,selected:unknown):Readonly<VerifiedManagedFamilyRelease> {- if(!selected||typeof selected!=='object'||!selectedReleases.has(selected))throw Error('Candidate requires a locally verified release descriptor');- const release=selected as Readonly<ManagedFamilyRelease>;- if(typeof bytes!=='string'&&!Buffer.isBuffer(bytes))throw Error('Candidate must be bounded UTF-8 JSON bytes');- const raw=Buffer.isBuffer(bytes)?bytes:Buffer.from(bytes,'utf8');- if(raw.length!==release.assets.candidate.size||raw.length>maxMetadata)throw Error('Candidate metadata size mismatch');- const json=raw.toString('utf8');if(!Buffer.from(json,'utf8').equals(raw))throw Error('Invalid candidate UTF-8');- const candidate=record(JSON.parse(json),'runtime candidate');- if(candidate.schema!==1||candidate.kind!=='runtime'||candidate.repository!==release.repository||candidate.ref!=='refs/heads/main')throw Error('Candidate must match the selected main runtime repository');- const commit=text(candidate.commit,/^[a-f0-9]{40}$/,'candidate source commit',40);- if(release.targetCommitish!=='main'&&release.targetCommitish!==commit)throw Error('Candidate differs from release target commit');- if(!commit.startsWith(release.commitHint))throw Error('Candidate commit differs from release tag and archive');- const runId=text(candidate.runId,/^[1-9][0-9]*$/,'candidate run ID',16);size(Number(runId),Number.MAX_SAFE_INTEGER,'candidate run ID');- const graph=record(candidate.sourceGraph,'candidate source graph');if(graph.proton!==commit)throw Error('Candidate Proton source graph mismatch');- const sourceGraph=Object.freeze({proton:commit,wine:text(graph.wine,/^[a-f0-9]{40}$/,'Wine source commit',40),xgameruntime:text(graph.xgameruntime,/^[a-f0-9]{40}$/,'XGameRuntime source commit',40)});- const requiresLauncherVersion=version(candidate.requiresLauncherVersion,'required launcher version'),requiresBackendVersion=version(candidate.requiresBackendVersion,'required backend version');- if(!sufficient(release.installedVersions.launcher,requiresLauncherVersion))throw Error('Update the launcher before installing this runtime');- if(!sufficient(release.installedVersions.backend,requiresBackendVersion))throw Error('Update the backend before installing this runtime');- const expected=new Map([release.assets.binary,release.assets.checksum,release.assets.source,release.assets.sourceChecksum].map(item=>[item.name,item]));- if(!Array.isArray(candidate.files)||candidate.files.length!==4)throw Error('Candidate must bind the exact binary and source asset pairs');- const files=candidate.files.map(input=>{const file=record(input,'candidate file'),name=file.name;- if(typeof name!=='string'||!expected.has(name))throw Error('Unexpected or duplicate candidate file');const asset=expected.get(name)!;expected.delete(name);- if(size(file.size,32*1024**3,'candidate file size')!==asset.size)throw Error('Candidate file size differs from release asset');- return Object.freeze({name,size:asset.size,sha256:sha(file.sha256,'candidate file SHA-256')});- });- const validation=record(candidate.validation,'candidate validation metadata');- if(validation.nativeGateCount!==12)throw Error('Expected twelve native validation gate records');- const evidence=Object.freeze({nativeGateCount:12 as const,treeSha256:sha(validation.treeSha256,'validation tree hash'),resultsSha256:sha(validation.resultsSha256,'validation results hash'),realGameTest:flag(validation.realGameTest,'real-game metadata flag'),stableApproved:flag(validation.stableApproved,'stable approval metadata flag')});- return Object.freeze({...release,commit,runId,candidateSha256:createHash('sha256').update(raw).digest('hex'),files:Object.freeze(files),requiresLauncherVersion,requiresBackendVersion,sourceGraph,validation:evidence});+export function verifyManagedFamilyCandidate(bytes: unknown, selected: unknown): Readonly<VerifiedManagedFamilyRelease> {+ if (!selected || typeof selected !== 'object' || !selectedReleases.has(selected))+ throw Error('Candidate requires a locally verified release descriptor');+ const release = selected as Readonly<ManagedFamilyRelease>;+ if (typeof bytes !== 'string' && !Buffer.isBuffer(bytes))+ throw Error('Candidate must be bounded UTF-8 JSON bytes');+ const raw = Buffer.isBuffer(bytes) ? bytes : Buffer.from(bytes, 'utf8');+ if (raw.length !== release.assets.candidate.size || raw.length > maxMetadata)+ throw Error('Candidate metadata size mismatch');+ const json = raw.toString('utf8');+ if (!Buffer.from(json, 'utf8').equals(raw))+ throw Error('Invalid candidate UTF-8');+ const candidate = record(JSON.parse(json), 'runtime candidate');+ if (candidate.schema !== 1 || candidate.kind !== 'runtime' || candidate.repository !== release.repository || candidate.ref !== 'refs/heads/main')+ throw Error('Candidate must match the selected main runtime repository');+ const commit = text(candidate.commit, /^[a-f0-9]{40}$/, 'candidate source commit', 40);+ if (release.targetCommitish !== 'main' && release.targetCommitish !== commit)+ throw Error('Candidate differs from release target commit');+ if (!commit.startsWith(release.commitHint))+ throw Error('Candidate commit differs from release tag and archive');+ const runId = text(candidate.runId, /^[1-9][0-9]*$/, 'candidate run ID', 16);+ size(Number(runId), Number.MAX_SAFE_INTEGER, 'candidate run ID');+ const graph = record(candidate.sourceGraph, 'candidate source graph');+ if (graph.proton !== commit)+ throw Error('Candidate Proton source graph mismatch');+ text(graph.wine, /^[a-f0-9]{40}$/, 'Wine source commit', 40);+ text(graph.xgameruntime, /^[a-f0-9]{40}$/, 'XGameRuntime source commit', 40);+ const freeze = (value: unknown, depth = 0): void => {+ if (depth > 32)+ throw Error('Candidate source graph is too deep');+ if (value && typeof value === 'object') {+ for (const child of Object.values(value))+ freeze(child, depth + 1);+ Object.freeze(value);+ }+ };+ freeze(graph);+ const sourceGraph = graph;+ const requiresLauncherVersion = version(candidate.requiresLauncherVersion, 'required launcher version'), requiresBackendVersion = version(candidate.requiresBackendVersion, 'required backend version');+ if (!sufficient(release.installedVersions.launcher, requiresLauncherVersion))+ throw Error('Update the launcher before installing this runtime');+ if (!sufficient(release.installedVersions.backend, requiresBackendVersion))+ throw Error('Update the backend before installing this runtime');+ const expected = new Map([release.assets.binary, release.assets.checksum, release.assets.source, release.assets.sourceChecksum].map(item => [item.name, item]));+ if (!Array.isArray(candidate.files) || candidate.files.length !== 4)+ throw Error('Candidate must bind the exact binary and source asset pairs');+ const files = candidate.files.map(input => {+ const file = record(input, 'candidate file'), name = file.name;+ if (typeof name !== 'string' || !expected.has(name))+ throw Error('Unexpected or duplicate candidate file');+ const asset = expected.get(name)!;+ expected.delete(name);+ if (size(file.size, 32 * 1024 ** 3, 'candidate file size') !== asset.size)+ throw Error('Candidate file size differs from release asset');+ return Object.freeze({+ name, size: asset.size, sha256: sha(file.sha256, 'candidate file SHA-256')+ });+ });+ const validation = record(candidate.validation, 'candidate validation metadata');+ if (validation.nativeGateCount !== 12)+ throw Error('Expected twelve native validation gate records');+ const evidence = Object.freeze({+ nativeGateCount: 12 as const, treeSha256: sha(validation.treeSha256, 'validation tree hash'), resultsSha256: sha(validation.resultsSha256, 'validation results hash'), realGameTest: flag(validation.realGameTest, 'real-game metadata flag'), stableApproved: flag(validation.stableApproved, 'stable approval metadata flag')+ });+ return Object.freeze({+ ...release, commit, runId, candidateSha256: createHash('sha256').update(raw).digest('hex'), files: Object.freeze(files), requiresLauncherVersion, requiresBackendVersion, sourceGraph, validation: evidence+ });}