← back to Newmor Onboard

scripts/asset-transition.mjs

13 lines

import assert from 'node:assert/strict';
import crypto from 'node:crypto';
export const hash=s=>crypto.createHash('sha256').update(s).digest('hex');
export async function transition({current,wanted,sourceHash,targetHash,apply,write,readback}) {
 assert.equal(hash(wanted),targetHash,'Planned target bytes changed');
 if(hash(current)===targetHash)return 'already-correct';
 assert.equal(hash(current),sourceHash,'Concurrent asset edit');
 if(!apply)return 'dry-run';
 await write(wanted);
 assert.equal(hash(await readback()),targetHash,'Persisted asset mismatch');
 return 'verified';
}