import {createHash} from 'node:crypto'; import {STAFF_OFFICE_ACCOUNT_ID} from './organisation-keys.mjs'; // Read facts from the same private campaign register used by the native bridge. // This producer never accepts browser counters or treats calendar proposals as // combat. Claims re-read the original capture and consumed conquest instrument. export async function warQuestEvidence(bank,central,{minecraftUuid,startsAt,endsAt,now}){ const totals=new Map(),proofIds=[];if(!bank)return {totals,proofIds}; const rows=await bank.query('SELECT snapshot_json FROM jarvis_war_campaigns WHERE starts_at>=? AND starts_at500)throw Error('Campaign evidence register requires a narrower view.'); for(const row of rows){ const c=JSON.parse(row.snapshot_json);if(c.cancelledAt!=null)continue; const team=c.teams.find(t=>t.roster.some(p=>p.uuid===minecraftUuid));if(!team)continue; totals.set('pol-war-deployment',(totals.get('pol-war-deployment')||0)+1);proofIds.push('war-deployment:'+c.id+':'+team.id); const captures=c.captures.filter(e=>e.playerUuid===minecraftUuid&&e.sideId===team.id&&e.capturedAt>=startsAt&&e.capturedAt'war-capture:'+e.eventId)); if(c.winnerSideId!==team.id||!c.provinces.length||!c.provinces.every(p=>p.ownerSideId===team.id))continue; const receipt=(await central.query("SELECT i.fields_json,i.manifest_json FROM jarvis_generated_instructions i JOIN organisation_keys k ON k.id=i.key_id WHERE i.action_id='war.conquest-settlement' AND i.state='applied' AND k.scope_id=? AND k.key_type='staff-parent-link' AND k.account_id=? AND k.used_at IS NOT NULL AND k.revoked_at IS NULL",['war-conquest:'+c.id,STAFF_OFFICE_ACCOUNT_ID]))[0]; if(!receipt)continue;const source=JSON.parse(receipt.fields_json),result=JSON.parse(receipt.manifest_json).receipt; if(source.campaignId!==c.id||source.winnerId!==team.id||source.sourceHash!==createHash('sha256').update(JSON.stringify(c)).digest('hex')||result?.winnerId!==team.id||result.sourceHash!==source.sourceHash||!Number.isSafeInteger(result.settledAt)||result.settledAt>now)continue; totals.set('pol-war-victory',(totals.get('pol-war-victory')||0)+1);proofIds.push('war-victory:'+c.id+':'+source.sourceHash); } return {totals,proofIds}; }