File size: 1,956 Bytes
d739b1b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | // 준비 철회는 기존 grant를 지우지 않고 마지막 checkpoint에 한 번만 추가한다.
// 설명 문서: docs/specs/batch-step-continuation.md (v0.4.0, R67 진행 중)
const {hash,hex}=require('../services/bong-browser-resolution'),{same}=require('./batch-recovery-record');
const fail=()=>require('./batch-checkpoint-record').fail();
function validate(record){
const map=record.revocations;if(map===undefined)return;
if(!map||typeof map!=='object'||Array.isArray(map)||Object.keys(map).length!==1)fail();
const [id,r]=Object.entries(map)[0],g=Object.values(record.recoveries||{}).at(-1),keys=['version','kind','runId','grantId','grantApprovalHash','checkpointHash','checkpointRevision','originalRun','usageHash','reviewedAt','reviewFingerprint','operator','reason','approvalHash'];
const {approvalHash,...body}=r||{};
if(r?.version!==1||r.kind!=='revoke'||r.grantId!==id||id!==g?.id||r.runId!==record.runId||r.grantApprovalHash!==g.approvalHash||r.reason!=='user_revoked_preparation'||r.operator!=='approved_owner'
||Object.keys(r).length!==keys.length||Object.keys(r).some(k=>!keys.includes(k))||!['grantApprovalHash','checkpointHash','usageHash','reviewFingerprint','approvalHash'].every(k=>hex(r[k]))||approvalHash!==hash(body)||!Number.isFinite(Date.parse(r.reviewedAt))
||!Number.isSafeInteger(r.checkpointRevision)||r.checkpointRevision!==g.checkpointRevision+1||record.revision!==r.checkpointRevision+1||!same(r.originalRun,{...g.originalRun,status:'paused',error_message:null,completed_at:null}))fail();
const before={...record,revision:r.checkpointRevision};delete before.revocations;if(hash(before)!==r.checkpointHash)fail();
}
function transition(next,previous,verify){
if(previous.revocations)fail();if(!next.revocations)return false;
const receipt=Object.values(next.revocations)[0];if(typeof verify!=='function'||verify(receipt,previous,next)!==true)fail();return true;
}
module.exports={validate,transition};
|