From f3f445f2a90ba0a4feedf0a733165604b30e2e88 Mon Sep 17 00:00:00 2001 From: abrichr Date: Tue, 24 Nov 2026 17:07:41 -0500 Subject: [PATCH] fix(seal-view): reject null and missing evidence_scope fields that Python rejects (follow-up #2643) The JS receipt verifier read a null evidence_scope, a null basis, read_back_at or recheck_window_s, and a null or missing wire.protocols_parsed as absent, so it could say VERIFIED where the Python verifier says malformed. Python refuses each because the payload is not the canonical form of its parsed statement: the canonical block leaves optional fields out and always lists wire.protocols_parsed. The JS now validates any field that is present, including null, and requires wire.protocols_parsed. Six shared record-run-v1 vectors, signed with the public this_computer test-vector key, pin the refusal for both verifiers. The bundled launcher viewer and its size snapshot are rebuilt. --- openadapt/seal_view/viewer.html | 2 +- packages/seal-view/CHANGELOG.md | 5 +++ packages/seal-view/src/lib/receiptRecord.mjs | 14 ++++--- packages/types/CHANGELOG.md | 9 ++++ .../tests/vectors/record-run-v1/README.md | 5 ++- .../evidence-scope-null-basis.json | 21 ++++++++++ .../evidence-scope-null-read-back-at.json | 21 ++++++++++ .../evidence-scope-null-recheck-window.json | 21 ++++++++++ .../record-run-v1/evidence-scope-null.json | 21 ++++++++++ .../evidence-scope-protocols-missing.json | 21 ++++++++++ .../evidence-scope-protocols-null.json | 21 ++++++++++ .../tests/vectors/record-run-v1/generate.py | 42 +++++++++++++++++++ tests/snapshots/seal_viewer_size.json | 4 +- 13 files changed, 197 insertions(+), 10 deletions(-) create mode 100644 packages/types/tests/vectors/record-run-v1/evidence-scope-null-basis.json create mode 100644 packages/types/tests/vectors/record-run-v1/evidence-scope-null-read-back-at.json create mode 100644 packages/types/tests/vectors/record-run-v1/evidence-scope-null-recheck-window.json create mode 100644 packages/types/tests/vectors/record-run-v1/evidence-scope-null.json create mode 100644 packages/types/tests/vectors/record-run-v1/evidence-scope-protocols-missing.json create mode 100644 packages/types/tests/vectors/record-run-v1/evidence-scope-protocols-null.json diff --git a/openadapt/seal_view/viewer.html b/openadapt/seal_view/viewer.html index 1e82798e71..c2a64b081f 100644 --- a/openadapt/seal_view/viewer.html +++ b/openadapt/seal_view/viewer.html @@ -24,7 +24,7 @@ `);if(n<0)return null;let o=e.slice(0,n),r=e.slice(n+2),a=o.split(` `);if(a.length<3||!/^\d+$/.test(a[1]))return null;let i;try{i=Tt(a[2])}catch{return null}let l=Zn(`${o} `),d=a[0].indexOf(" - "),c=d>=0?a[0].slice(0,d):a[0],g=d>=0?a[0].slice(d+3):null;if(g!==null&&!/^\d+$/.test(g))return null;let h=g===null?null:BigInt(g);for(let p of r.split(` -`)){if(!p.startsWith("— "))continue;let u=p.slice(2).split(" ");if(u.length<2)continue;let f=u.slice(0,-1).join(" "),v;try{v=Tt(u.at(-1))}catch{continue}let m=Ht(v.slice(0,4));for(let b of t)if(!(c!==b.origin||f!==b.origin)&&b.logId.slice(0,8)===m&&await _s(b,v.slice(4),l))return{origin:a[0],size:BigInt(a[1]),root:i,treeId:h}}return null}var gn=async e=>Ht(await Yn(Zn(Ge(e)))),Ec=(e,t)=>Zn(`${bs}\0${Ge({nonce:t,...e})}`);async function Nc(e){try{let t=ys(new TextDecoder().decode(e));return t.length!==44||Ht(t.slice(0,12))!==yc?null:t.slice(12)}catch{return null}}async function Xn(e,t,n,o){return or({seal_sha256:await gn(e)},t,n,o)}async function or(e,t,n,o){let r=[],a=(H,G,V={})=>({ok:H,reason:G,steps:r,...V});if(t==null)return a(!1,"anchor_missing");let i,l,d;try{if(t.schema!==bs)throw new Error("schema");if(i=String(t.nonce),l=t.entry,d=Object.fromEntries(Object.keys(e).map(H=>[H,t[H]])),!gs.test(i)||!l||!Object.values(d).every(H=>typeof H=="string"&&gs.test(H)))throw new Error("format")}catch{return r.push({id:"anchorEntry",result:"fail"}),a(!1,"anchor_malformed")}let c=Ht(new Uint8Array(await qn().digest("SHA-512",Ec(e,i))));if(Object.keys(e).some(H=>d[H]!==e[H])||t.statement_sha512!==c)return r.push({id:"anchorEntry",result:"fail"}),a(!1,"anchor_mismatch");let g,h,p,u,f,v,m,b,y,x,w,E;try{if(g=String(l.uuid),h=String(l.body),p=Tt(h),u=JSON.parse(new TextDecoder().decode(p)),f=l.integratedTime,v=String(l.logID),m=l.logIndex,!Number.isInteger(f)||!Number.isInteger(m))throw new Error("int");b=Tt(l.verification.signedEntryTimestamp),y=l.verification.inclusionProof,x=u.spec.data.hash,w=Tt(u.spec.signature.content),E=Tt(u.spec.signature.publicKey.content)}catch{return r.push({id:"anchorEntry",result:"fail"}),a(!1,"anchor_malformed")}let R={uuid:g,logIndex:m,integratedTime:f,logId:v},S=(H,G)=>(r.push({id:H,result:"fail"}),a(!1,G,R));if(u.kind!=="hashedrekord"||u.apiVersion!=="0.0.1")return S("anchorEntry","anchor_malformed");if(x?.algorithm!=="sha512"||x?.value!==c)return S("anchorEntry","anchor_mismatch");r.push({id:"anchorEntry",result:"pass"});let A=await Nc(E);if(!A||!nr(A,n))return S("anchorKey","anchor_key_mismatch");if(!await Xa(n,tr(c),w))return S("anchorKey","anchor_bad_signature");r.push({id:"anchorKey",result:"pass"});let L=o.find(H=>H.logId===v);if(!L)return S("anchorTime","anchor_unknown_log");let C=Zn(Ge({body:h,integratedTime:f,logID:v,logIndex:m}));if(!await _s(L,b,C))return S("anchorTime","anchor_bad_timestamp");r.push({id:"anchorTime",result:"pass"});let $=await kc(p);if(!g.endsWith(Ht($)))return S("anchorInclusion","anchor_bad_inclusion");let P,M,k;try{k=BigInt(y.treeSize),P=await wc(y.logIndex,y.treeSize,$,y.hashes.map(tr)),M=tr(y.rootHash)}catch{return S("anchorInclusion","anchor_malformed")}if(!P||!nr(P,M))return S("anchorInclusion","anchor_bad_inclusion");r.push({id:"anchorInclusion",result:"pass"});let B=await Sc(String(y.checkpoint),[L]);return!B||!nr(B.root,M)||B.size!==k||g.length===80&&B.treeId!==null&&g.slice(0,16)!==B.treeId.toString(16).padStart(16,"0")?S("anchorCheckpoint","anchor_bad_checkpoint"):(r.push({id:"anchorCheckpoint",result:"pass"}),a(!0,null,R))}var Tc=(e,t)=>!!(t&&e?.scope?.seal_key_ids?.includes(t.key_id));function xs(e){if(e==null||Xe(e)!==null)return null;try{return JSON.parse(e)}catch{return null}}async function ks(e,t,{requireAnchor:n=!1,requireAuthorization:o=!1,logKeys:r=null}={}){let a=await rs(e.sealText,e.report,t,"report.json"),i=[...a.steps],l=(y,x,w={})=>({...a,ok:y,reason:x,steps:i,sealOk:a.ok,...w});if(!a.ok)return l(!1,a.reason);let d=r||[await Jn(Vn)],c=y=>{let x=fn(t).filter(w=>w.key_id===y&&w.status==="active");return x.length===1?Ue(x[0].public_key):null},g=null,h=null,p=null;if(e.auth){let y=await ds(e.auth.statement,e.auth.sig);if(i=[...i,...y.steps],!y.ok)return l(!1,y.reason);let x=null;try{x=JSON.parse(new TextDecoder().decode(e.report))}catch{x=null}p=x?.started_at??null;let w=us(a.seal,x,y),E={auth_not_referenced:"authRef",auth_reference_mismatch:"authRef",auth_scope_mismatch:"authScope",auth_bundle_mismatch:"authBundle"};if(w){let R=E[w]||"authRef";for(let S of["authRef","authScope","authBundle"]){if(S===R)break;i=[...i,{id:S,result:"pass"}]}return i=[...i,{id:R,result:"fail"}],l(!1,w)}if(i=[...i,{id:"authRef",result:"pass"},{id:"authScope",result:"pass"},{id:"authBundle",result:"pass"}],g={login:y.login,fingerprint:y.fingerprint,sha256:y.sha256,publicKey:y.publicKey},e.auth.anchorText!=null){let R=xs(e.auth.anchorText),A=Tc(y.statement,R)?c(R.key_id):null,L=R?A?await or({run_authorization_sha256:y.sha256,signature_sha256:y.signatureSha256},R,A,d):{ok:!1,reason:"anchor_key_mismatch"}:{ok:!1,reason:"anchor_malformed"};if(i=[...i,{id:"authLogged",result:L.ok?"pass":"fail"}],!L.ok)return l(!1,`authorization_${L.reason}`,{authorizedBy:g});h=L.integratedTime}}else if(o)return i=[...i,{id:"authShape",result:"fail"}],l(!1,"auth_missing");if(e.anchorText==null){let y=er(h,p,null);return n?(i=[...i,{id:"anchorEntry",result:"fail"}],l(!1,"anchor_missing",{authorizedBy:g,timing:y})):l(!0,null,{authorizedBy:g,timing:y})}let u=xs(e.anchorText);if(!u)return i=[...i,{id:"anchorEntry",result:"fail"}],l(!1,"anchor_malformed",{authorizedBy:g});let f=c(a.seal.key_id),v=await Xn(a.seal,u,f,d);i=[...i,...v.steps];let m=er(h,p,v.ok?v.integratedTime:null),b=fs(h,v.ok?v.integratedTime:null);return l(v.ok,v.reason,{authorizedBy:g,timing:m,authAnchorTime:h,authorizationVsSeal:b,anchor:v.ok?{uuid:v.uuid,logIndex:v.logIndex,integratedTime:v.integratedTime,logId:v.logId}:null})}var $c="https://in-toto.io/Statement/v1",Ac="https://openadapt.ai/record/run/v1",ws="application/vnd.in-toto+json",Rc="openadapt.receipt-card/v1",Mc="openadapt.receipt-openings/v1",Ic="openadapt.receipt-keys/v1",As="openadapt.public-disclosure/v1",Cc="openadapt.receipt-commitment/v1",Ss=256,mn=2**53-1,Pc=65536,Oc=["this_computer","customer_key","openadapt_cloud","public_log","demo"],Es=["this_computer","customer_key","openadapt_cloud","public_log"],Lc={this_computer:"Signed by this computer",customer_key:"Signed by {org}'s key",openadapt_cloud:"Countersigned by OpenAdapt Cloud",public_log:"Logged publicly",demo:"Demo key: checks only in this demo"},zc={unknown_signer:"Not verified: unknown signer",unknown_role:"Not verified: unknown signer role",unknown_schema:"Not verified: unknown receipt format",unsigned:"Not verified: no signature",revoked_key:"Not verified: the signing key was revoked",bad_signature:"Not verified: the receipt was changed after it was signed",mixed_demo:"Not verified: a demo key signed alongside a real one",embedded_content:"Not verified: the receipt holds embedded content",opening_mismatch:"Not verified: a disclosed value doesn't match the receipt",disclosure_not_allowed:"Not verified: the card reveals a field it may not",inconsistent:"Not verified: the receipt contradicts itself",malformed:"Not verified: malformed receipt",verifier_unavailable:"Not verified: this browser can't check Ed25519 signatures"},Dc=e=>zc[e]||"Not verified",$t=/^[a-f0-9]{64}$/,Fc=/^[a-f0-9]{64}$/,Hc=/^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:00:00Z$/,Qn=/^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$/,jc=/^prog-[a-f0-9]{16}$/,Gc=/^[a-z][a-z0-9_]{0,47}$/,Uc=/^[A-Za-z0-9 ._-]{1,48}$/,rr=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,Rs={program_name:/^[A-Za-z0-9 ._-]{1,48}$/,flow_version:/^[0-9]{1,4}\.[0-9]{1,4}\.[0-9]{1,6}$/,github_login:/^[A-Za-z0-9-]{1,39}$/,run_id:/^[A-Za-z0-9._:-]{1,128}$/},Bc={[As]:["program_name","flow_version","github_login"]},Kc=["VERIFIED","STOPPED","UNKNOWN","FAILED"],Wc=["report.json","report.canonical","bundle","evidence","payload"],Vc=["application/json","application/cbor","text/plain","text/csv","application/pdf","application/octet-stream"],qc=["tx_receipt","write_receipt"],Zc=["ehr","payer_portal","bank","erp","crm","government_portal","email","other"],Yc=["portal_read_back","api","acknowledgment_message"],Ms=["portal_read_back","api"],Jc=["sent","acknowledged","recorded_as_intended","recorded_differently"],Xc=["read_back","acknowledgment","none"],Qc=["each_item","problems_only","not_gated"],ed=["person","agent","none"],td={sent:["rejected_by_counterparty","ambiguous_key","receiver_unreachable","not_found","no_answer_by_deadline"],acknowledged:["ambiguous_key","not_found","no_answer_by_deadline"],recorded_as_intended:["conflicting_report"],recorded_differently:["conflicting_report"]},nd=/^(?:counterparty|observed_at|reason|field\.[0-9]{1,2})$/,od=/^(?:principal|scope|approved_at)$/,rd=/^confirmations\.([0-9]{1,2})\.(counterparty|observed_at|reason|field\.[0-9]{1,2})$/,ad=/^approval\.(principal|scope|approved_at)$/,sd={counterparty:/^(?:ehr|payer_portal|bank|erp|crm|government_portal|email|other):cp-[a-f0-9]{16}$/,observed_at:Qn,reason:/^(?:rejected_by_counterparty|conflicting_report|ambiguous_key|receiver_unreachable|not_found|no_answer_by_deadline)$/,field:/^[a-z][a-z0-9_]{0,31}:[a-f0-9]{64}(?::differs)?$/,principal:/^(?:person|agent):pr-[a-f0-9]{16}$/,scope:$t,approved_at:Qn},id=["gui","api"],ld=["write","irreversible_write"],cd=["confirmed","refuted","not_checked"],dd=["read_back","same_screen","none"],pd=["effect_not_declared","approved_unverified","field_values","postconditions","uncertain"],ud="openadapt.evidence-scope/v1",fd=["unchecked","same_screen","reopened","separate_session","system_of_record","counterparty_confirmed"],hd=["VERIFIED","SHOWN","CONFIRMED","ATTESTED","RECORDED"],Ns={separate_session:"separate_session",system_api:"system_of_record",activity_log:"system_of_record",db_frame:"system_of_record",owned_connection:"system_of_record"},gd=["none","browser_network","http_proxy","api_client","db_connection"],md=["http","graphql","fhir","sql","websocket","grpc","smtp"],bd=["server_side_async_effects","outbound_effects","changes_after_read_back","fields_not_read","other_records","other_actors","read_back_time"],vd=["server_side_async_effects","outbound_effects"],yd=720*3600,_d={VERIFIED:["VERIFIED"],CONFIRMED:["VERIFIED"],SHOWN:["UNKNOWN","STOPPED","FAILED"],ATTESTED:["UNKNOWN","STOPPED","FAILED"],RECORDED:["UNKNOWN","STOPPED","FAILED"]},I=class extends Error{constructor(t,n=""){super(n||t),this.reason=t}},Ts=(e,t="")=>({ok:!1,reason:e,detail:t,signerLines:[Dc(e)],outcome:null,demo:!1,disclosed:{}}),xd=/data:[a-z]+\//i,kd=/[a-z][a-z0-9+.-]*:\/\//i,wd=/[A-Za-z0-9+/_-]{96,}={0,2}/,Sd=["iVBORw0KGgo","/9j/","R0lGOD","UklGR","PHN2Zy"];function ar(e){let t=e.toLowerCase();return[...e].length>256||xd.test(e)||kd.test(e)||wd.test(e)||Sd.some(n=>e.startsWith(n))||t.includes("e!==null&&typeof e=="object"&&!Array.isArray(e);function Oe(e,t,n=[],o=""){if(!Fe(e))throw new I("malformed",`${o} is an object`);for(let r of Object.keys(e))if(!t.includes(r)&&!n.includes(r))throw new I("malformed",`${o}.${r} is not a field`);for(let r of t)if(!(r in e))throw new I("malformed",`${o}.${r} is missing`)}function it(e,t,n,o){if(!Number.isInteger(e)||en)throw new I("malformed",`${o} is an integer from ${t} to ${n}`)}function oe(e,t,n){if(!(typeof e=="string"&&(Array.isArray(t)?t.includes(e):t.test(e))))throw new I("malformed",`${n} is not valid`)}function Ed(e,t){Oe(e,["required","confirmed"],[],t),it(e.required,0,mn,`${t}.required`),it(e.confirmed,0,mn,`${t}.confirmed`)}function Nd(e){if(Oe(e,["_type","subject","predicateType","predicate"],[],"$"),!Array.isArray(e.subject)||e.subject.length<1||e.subject.length>4)throw new I("malformed","subject has 1 to 4 entries");for(let[o,r]of e.subject.entries())Oe(r,["name","digest"],["media_type"],`subject[${o}]`),oe(r.name,Wc,`subject[${o}].name`),"media_type"in r&&oe(r.media_type,Vc,`subject[${o}].media_type`),Oe(r.digest,["sha256"],[],`subject[${o}].digest`),oe(r.digest.sha256,$t,`subject[${o}].digest.sha256`);let t=e.predicate;if(Oe(t,["program","started_hour","outcome","steps","lines","checks","model_calls","disclosure"],["reason_code","confirmations","approval","evidence_scope"],"predicate"),Oe(t.program,["id","version_sha256"],[],"predicate.program"),oe(t.program.id,jc,"predicate.program.id"),oe(t.program.version_sha256,$t,"predicate.program.version_sha256"),oe(t.started_hour,Hc,"predicate.started_hour"),oe(t.outcome,Kc,"predicate.outcome"),t.reason_code!=null&&oe(t.reason_code,Gc,"predicate.reason_code"),Oe(t.steps,["total","ok"],[],"predicate.steps"),it(t.steps.total,0,mn,"predicate.steps.total"),it(t.steps.ok,0,mn,"predicate.steps.ok"),!Array.isArray(t.lines)||t.lines.length>Ss)throw new I("malformed","predicate.lines");for(let[o,r]of t.lines.entries()){let a=`predicate.lines[${o}]`;if(Oe(r,["step","target_kind","operation","check","strength","not_checked"],["evidence"],a),"evidence"in r&&(Oe(r.evidence,["kind","sha256"],[],`${a}.evidence`),oe(r.evidence.kind,qc,`${a}.evidence.kind`),oe(r.evidence.sha256,$t,`${a}.evidence.sha256`)),it(r.step,0,1e4,`${a}.step`),oe(r.target_kind,id,`${a}.target_kind`),oe(r.operation,ld,`${a}.operation`),oe(r.check,cd,`${a}.check`),oe(r.strength,dd,`${a}.strength`),!Array.isArray(r.not_checked)||r.not_checked.length>5)throw new I("malformed",`${a}.not_checked`);r.not_checked.forEach((i,l)=>oe(i,pd,`${a}.not_checked[${l}]`))}let n=t.checks;Oe(n,["identity","postconditions","effects","authorization","lines_confirmed","lines_refuted","lines_not_checked"],[],"predicate.checks");for(let o of["identity","postconditions","effects","authorization"])Ed(n[o],`predicate.checks.${o}`);for(let o of["lines_confirmed","lines_refuted","lines_not_checked"])it(n[o],0,Ss,`predicate.checks.${o}`);if(it(t.model_calls,0,mn,"predicate.model_calls"),Oe(t.disclosure,["version","commitments"],[],"predicate.disclosure"),oe(t.disclosure.version,[As],"predicate.disclosure.version"),!Fe(t.disclosure.commitments)||Object.keys(t.disclosure.commitments).length>16)throw new I("malformed","predicate.disclosure.commitments");for(let o of Object.values(t.disclosure.commitments))if(typeof o!="string")throw new I("malformed","a commitment is a string");if("confirmations"in t){if(!Array.isArray(t.confirmations)||t.confirmations.length>64)throw new I("malformed","predicate.confirmations");for(let[o,r]of t.confirmations.entries()){let a=`predicate.confirmations[${o}]`;if(Oe(r,["kind","system_kind","read_method","state","strength","differing_count","commitments"],["for_step"],a),oe(r.kind,["counterparty_confirmation"],`${a}.kind`),r.for_step!=null&&it(r.for_step,0,1e4,`${a}.for_step`),oe(r.system_kind,Zc,`${a}.system_kind`),oe(r.read_method,Yc,`${a}.read_method`),oe(r.state,Jc,`${a}.state`),oe(r.strength,Xc,`${a}.strength`),it(r.differing_count,0,64,`${a}.differing_count`),!Fe(r.commitments)||Object.keys(r.commitments).length<2||Object.keys(r.commitments).length>34)throw new I("malformed",`${a}.commitments`)}}if("approval"in t&&(Oe(t.approval,["mode","approver_kind","commitments"],[],"predicate.approval"),oe(t.approval.mode,Qc,"predicate.approval.mode"),oe(t.approval.approver_kind,ed,"predicate.approval.approver_kind"),!Fe(t.approval.commitments)||Object.keys(t.approval.commitments).length>3))throw new I("malformed","predicate.approval.commitments");if("evidence_scope"in t&&t.evidence_scope!==null){let o=t.evidence_scope;Oe(o,["schema","check_level","word","wire","not_covered"],["basis","read_back_at","recheck_window_s"],"predicate.evidence_scope"),oe(o.schema,[ud],"predicate.evidence_scope.schema"),oe(o.check_level,fd,"predicate.evidence_scope.check_level"),oe(o.word,hd,"predicate.evidence_scope.word"),o.basis!=null&&oe(o.basis,Object.keys(Ns),"predicate.evidence_scope.basis"),Oe(o.wire,["channel"],["protocols_parsed"],"predicate.evidence_scope.wire"),oe(o.wire.channel,gd,"predicate.evidence_scope.wire.channel");let r=o.wire.protocols_parsed??[];if(!Array.isArray(r)||r.length>7)throw new I("malformed","predicate.evidence_scope.wire.protocols_parsed");if(r.forEach((a,i)=>oe(a,md,`predicate.evidence_scope.wire.protocols_parsed[${i}]`)),new Set(r).size!==r.length)throw new I("malformed","wire.protocols_parsed repeats a protocol");if(o.wire.channel==="none"&&r.length)throw new I("malformed","a run that watched no wire parsed no protocol");if(o.read_back_at!=null&&oe(o.read_back_at,Qn,"predicate.evidence_scope.read_back_at"),o.recheck_window_s!=null&&it(o.recheck_window_s,0,yd,"predicate.evidence_scope.recheck_window_s"),!Array.isArray(o.not_covered)||o.not_covered.length<2||o.not_covered.length>7)throw new I("malformed","predicate.evidence_scope.not_covered");if(o.not_covered.forEach((a,i)=>oe(a,bd,`predicate.evidence_scope.not_covered[${i}]`)),new Set(o.not_covered).size!==o.not_covered.length)throw new I("malformed","not_covered repeats a code");if(!vd.every(a=>o.not_covered.includes(a)))throw new I("malformed","not_covered must list server_side_async_effects and outbound_effects");if(o.basis!=null&&Ns[o.basis]!==o.check_level)throw new I("malformed",`basis ${o.basis} does not reach ${o.check_level}`);if(o.word==="VERIFIED"){if(!["separate_session","system_of_record"].includes(o.check_level)||o.basis==null)throw new I("malformed","VERIFIED needs level 3 or 4 and a basis");if(o.read_back_at==null&&!o.not_covered.includes("read_back_time"))throw new I("malformed","VERIFIED needs read_back_at, or says it has none")}if(o.word==="SHOWN"&&!["same_screen","reopened"].includes(o.check_level))throw new I("malformed","SHOWN is a level 1 or 2 re-read of the acting screen");if(o.word==="CONFIRMED"&&o.check_level!=="counterparty_confirmed")throw new I("malformed","CONFIRMED is level 5, the counterparty acknowledgment");if(o.read_back_at!=null&&o.not_covered.includes("read_back_time"))throw new I("malformed","a block with read_back_at covers the read-back time");if(o.recheck_window_s!=null&&o.read_back_at==null)throw new I("malformed","a recheck window needs read_back_at")}return{...e,predicate:{...t,reason_code:t.reason_code??null}}}function Td(e){let t=e.predicate,n=e.subject.map(a=>a.name);if(new Set(n).size!==n.length||!(n.includes("report.json")||n.includes("report.canonical")))return"subject names repeat, or the report is missing";for(let a of e.subject)if(a.name==="payload"!="media_type"in a)return"only the payload subject has a media type, and it always has one";if(t.approval){let a=t.approval;for(let[i,l]of Object.entries(a.commitments))if(!od.test(i)||!$t.test(l))return`approval commitment ${i} is not a known field`;if(a.mode==="not_gated"&&a.approver_kind!=="none")return"a not_gated run names no approver";if(a.approver_kind==="none"){if(Object.keys(a.commitments).length)return"an approval with no approver commits to nothing"}else if(!("principal"in a.commitments&&"scope"in a.commitments))return"an approval names its approver's principal and scope"}for(let[a,i]of Object.entries(t.disclosure.commitments))if(!Rs[a]||!$t.test(i))return`disclosure path ${a} is not a known field`;if(t.steps.ok>t.steps.total)return"steps.ok is more than steps.total";for(let a of["identity","postconditions","effects","authorization"])if(t.checks[a].confirmed>t.checks[a].required)return`checks.${a} confirms more than it requires`;let o={confirmed:0,refuted:0,not_checked:0};for(let a of t.lines){if(o[a.check]+=1,a.check==="confirmed"&&a.strength==="none")return"a confirmed line has no strength";if(new Set(a.not_checked).size!==a.not_checked.length)return"a line repeats a not_checked code"}if(t.checks.lines_confirmed!==o.confirmed||t.checks.lines_refuted!==o.refuted||t.checks.lines_not_checked!==o.not_checked)return"check counts disagree with the lines";if(t.outcome==="VERIFIED"&&o.refuted)return"a VERIFIED receipt has a refuted line";if(t.evidence_scope&&!_d[t.evidence_scope.word].includes(t.outcome))return"the evidence scope's word disagrees with the outcome";let r=t.lines.map(a=>a.step);for(let a=1;a0)return"differing_count disagrees with the state";if(!("counterparty"in a.commitments&&"observed_at"in a.commitments))return"a confirmation commits to its counterparty and observed_at";for(let[l,d]of Object.entries(a.commitments))if(!nd.test(l)||!$t.test(d))return`confirmation commitment ${l} is not a known field`;let i=Object.keys(a.commitments).filter(l=>l.startsWith("field.")).length;if(a.differing_count>i)return"more differing fields than observed fields"}return null}var jt=e=>new TextEncoder().encode(e);function Is(...e){let t=new Uint8Array(e.reduce((o,r)=>o+r.length,0)),n=0;for(let o of e)t.set(o,n),n+=o.length;return t}var $d=e=>Uint8Array.from(e.match(/../g),t=>parseInt(t,16));async function Ad(e,t,n){let o=new Uint8Array([0]);return Me(Is(jt(Cc),o,jt(e),o,$d(t),o,jt(Ge(n))))}function Rd(e,t){let n=rd.exec(e)||ad.exec(e);if(n){let r=(n[2]||n[1]).split(".")[0];return typeof t=="string"&&sd[r].test(t)?null:`${e} does not match its field's pattern`}let o=Rs[e];return o?typeof t!="string"?`${e} is not a string`:ar(t)?`${e} holds embedded content`:o.test(t)?null:`${e} does not match its field's pattern`:`${e} is not a disclosure field`}async function $s(e,t,n){if(!Fe(e))throw new I("malformed","openings are an object");let o=eo(e);if(o)throw new I("embedded_content",o);let r={};for(let[a,i]of Object.entries(e)){if(n&&!n.includes(a))throw new I("disclosure_not_allowed",a);if(!Fe(i)||Object.keys(i).length!==2||!("salt"in i)||!("value"in i))throw new I("malformed",`the opening for ${a}`);let l=Rd(a,i.value);if(l)throw new I("malformed",l);if(!(typeof i.salt=="string"&&Fc.test(i.salt)))throw new I("malformed",`the salt for ${a}`);if(t[a]!==await Ad(a,i.salt,i.value))throw new I("opening_mismatch",a);r[a]=i.value}return r}async function Md(e){if(!Fe(e)||e.schema!==Ic)throw new I("unknown_schema","not an openadapt.receipt-keys/v1 registry");if(!Array.isArray(e.keys))throw new I("malformed","a registry has a keys list");let t=[];for(let n of e.keys){if(!Fe(n))throw new I("malformed","a registry entry is an object");if(Object.keys(n).some(a=>!["key_id","public_key","role","status","revoked_at","org"].includes(a)))throw new I("malformed","a registry entry has an unknown field");if(!Oc.includes(n.role))throw new I("unknown_role",`unknown signer role ${n.role}`);if(typeof n.public_key!="string"||!rr.test(n.public_key))throw new I("malformed","a public key is base64");let o=Ue(n.public_key);if(o.length!==32||n.key_id!==`seal-ed25519-${(await Me(o)).slice(0,16)}`)throw new I("malformed","a key id doesn't match its public key");let r=n.status??"active";if(!["active","revoked"].includes(r)||r==="revoked"&&!(typeof n.revoked_at=="string"&&Qn.test(n.revoked_at)))throw new I("malformed","a key is active, or revoked with revoked_at");if(n.role==="customer_key"&&!(typeof n.org=="string"&&Uc.test(n.org)))throw new I("malformed","a customer key names its org");t.push({keyId:n.key_id,raw:o,role:n.role,status:r,revokedAt:r==="revoked"?n.revoked_at:null,org:n.role==="customer_key"?n.org:null})}if(new Set(t.map(n=>n.keyId)).size!==t.length)throw new I("malformed","a registry lists one key id twice");return t}function Id(e,t){let n=jt(e);return Is(jt(`DSSEv1 ${n.length} `),n,jt(` ${t.length} `),t)}var Cd=e=>Fe(e)&&e.schema===Rc;function Pd(e){if(Xe(e)!==null)throw new I("malformed","duplicate key");try{return JSON.parse(e)}catch{throw new I("malformed","the payload is not JSON")}}async function Od(e,t,n){let o;try{o=await globalThis.crypto.subtle.importKey("raw",e,{name:"Ed25519"},!1,["verify"])}catch{throw new I("verifier_unavailable")}return globalThis.crypto.subtle.verify({name:"Ed25519"},o,t,n)}async function Cs(e,t,{openings:n=null}={}){try{let o=await Md(t),r=null,a=null,i=e;if(Cd(e)){if(Object.keys(e).sort().join(",")!=="disclosure_version,envelope,openings,schema")throw new I("malformed","a card has exactly four fields");if(a=Bc[e.disclosure_version],!a)throw new I("unknown_schema","unknown public disclosure version");if(r=e.openings,!Fe(r))throw new I("malformed","a card's openings are an object");if(i=e.envelope,n!=null)throw new I("malformed","a card carries its own openings")}if(!Fe(i)||Object.keys(i).sort().join(",")!=="payload,payloadType,signatures")throw new I("malformed","a DSSE envelope has payloadType, payload, signatures");if(i.payloadType!==ws)throw new I("unknown_schema","the payload is not an in-toto statement");if(typeof i.payload!="string"||!rr.test(i.payload))throw new I("malformed","the payload is not base64");let l=Ue(i.payload);if(l.length>Pc)throw new I("malformed","the payload is too large");let d=i.signatures;if(!Array.isArray(d)||!d.length)throw new I("unsigned");let c=new Map(o.map($=>[$.keyId,$])),g=Id(ws,l),h=[],p=new Set;for(let $ of d){if(!Fe($)||Object.keys($).sort().join(",")!=="keyid,sig")throw new I("malformed","a signature has keyid and sig");let P=$.keyid;if(typeof P!="string"||p.has(P))throw new I("malformed","a signature's keyid is missing or repeated");p.add(P);let M=c.get(P);if(!M)throw new I("unknown_signer",`${P} is not in the pinned registry`);if(typeof $.sig!="string"||!rr.test($.sig))throw new I("bad_signature",`${P}'s signature`);if(!await Od(M.raw,Ue($.sig),g))throw new I("bad_signature",`${P}'s signature`);if(M.status==="revoked")throw new I("revoked_key",`${P} was revoked at ${M.revokedAt}`);h.push({keyId:P,role:M.role,line:Lc[M.role].replace("{org}",M.org||"the customer")})}let u=new Set(h.map($=>$.role)),f=u.has("demo");if(f&&u.size!==1)throw new I("mixed_demo");let v;try{v=new TextDecoder("utf-8",{fatal:!0}).decode(l)}catch{throw new I("malformed","the payload is not UTF-8")}let m=Pd(v);if(!Fe(m))throw new I("malformed","the payload is not an object");if(m._type!==$c||m.predicateType!==Ac)throw new I("unknown_schema","not a record/run/v1 statement");let b=Object.fromEntries(Object.entries(m).filter(([$])=>$!=="_type"&&$!=="predicateType")),y=eo(b);if(y)throw new I("embedded_content",y);let x=Nd(m);if(Ge(x)!==v)throw new I("malformed","the payload is not canonical JSON");let w=Td(x);if(w)throw new I("inconsistent",w);let E={...x.predicate.disclosure.commitments};for(let[$,P]of(x.predicate.confirmations||[]).entries())for(let[M,k]of Object.entries(P.commitments))E[`confirmations.${$}.${M}`]=k;if(x.predicate.approval)for(let[$,P]of Object.entries(x.predicate.approval.commitments))E[`approval.${$}`]=P;let R={},S=!1;if(r)R=await $s(r,E,a);else if(n!=null){if(!Fe(n)||Object.keys(n).sort().join(",")!=="openings,payload_sha256,schema")throw new I("malformed","a private openings file has three fields");if(n.schema!==Mc)throw new I("unknown_schema","not an openadapt.receipt-openings/v1 file");if(n.payload_sha256!==await Me(l))throw new I("opening_mismatch","the openings belong to another receipt");R=await $s(n.openings,E,null),S=!0;for(let[$,P]of(x.predicate.confirmations||[]).entries()){let M=R[`confirmations.${$}.reason`];if(M!=null&&!td[P.state].includes(M))throw new I("inconsistent",`a ${P.state} confirmation can't have reason ${M}`)}}let A=[...h].sort(($,P)=>Es.indexOf($.role)-Es.indexOf(P.role)),L=[...new Set(A.map($=>$.line))],C=x.predicate.confirmations||[];return{ok:!0,reason:null,detail:"",signerLines:L,confirmationLines:C.map(($,P)=>zd($,R[`confirmations.${P}.observed_at`])),independent:C.map($=>Ms.includes($.read_method)),approvalLine:Ld(x.predicate.approval),outcome:x.predicate.outcome,demo:f,disclosed:R,private:S,statement:x}}catch(o){return o instanceof I?Ts(o.reason,o.message):Ts("malformed",String(o?.message||o))}}function Ld(e){return e?e.mode==="not_gated"?"Not gated: no approval was required for these writes":e.approver_kind==="none"?`Approval required for ${e.mode==="each_item"?"each item":"items that fail a check"}; no item was approved`:`Approved by ${e.approver_kind==="person"?"a person":"an agent delegate"}: ${e.mode==="each_item"?"each item":"items that failed a check"}`:"No approval recorded"}function zd(e,t){let n=t?` at ${t}`:"";return e.state==="recorded_as_intended"?`Confirmed in the other party's system${n}`:e.state==="recorded_differently"?`Recorded differently in the other party's system${n}: ${e.differing_count} ${e.differing_count===1?"field differs":"fields differ"}`:e.state==="acknowledged"?`Acknowledged by the other party${n}`:`Sent to the other party${n}, not confirmed`}async function ft(e,t=!1){let n=await fetch(e,{cache:"no-store"});if(!n.ok)throw new Error(`${e}: ${n.status}`);return t?new Uint8Array(await n.arrayBuffer()):n.text()}async function Ps(e,t=null){let[n,o,r,a,i,l]=await Promise.all([ft(e.report,!0),ft(e.seal),e.anchor?ft(e.anchor):null,e.tsa?ft(e.tsa):null,e.tsr?ft(e.tsr,!0):null,t?Promise.all([ft(t.statement),ft(t.sig),ft(t.signers),t.anchor?ft(t.anchor):null]):null]);return{report:n,sealText:o,anchorText:r,tsaText:a,tsrBytes:i,auth:l?{statement:l[0],sig:l[1],signers:l[2],anchorText:l[3]}:null}}var Os={VERIFIED:"HALTED",HALTED:"VERIFIED"};function Ls(e,t){let n=t||e,o=Os[n]||"VERIFIED",r=Os[e]||"VERIFIED";return[{id:"report-outcome",target:"report",label:"Change the outcome in the report",field:"execution_outcome",from:n,to:o,text:[`"execution_outcome": "${n}"`,`"execution_outcome": "${o}"`]},{id:"report-model-calls",target:"report",label:"Add one AI model call to the report",field:"model_calls",from:"0",to:"1",text:['"model_calls": 0','"model_calls": 1']},{id:"seal-outcome",target:"seal",label:"Change the outcome in the receipt",field:"outcome",from:e,to:r}]}function zs(e,t){if(t.target==="seal"){let a=JSON.parse(e.sealText);if(a[t.field]!==t.from)throw new Error("The value to change is not in the receipt.");return{...e,sealText:JSON.stringify({...a,[t.field]:t.to},null,2),receiptText:e.receiptText?Dd(e.receiptText):e.receiptText}}let n=new TextDecoder().decode(e.report),[o,r]=t.text;if(!n.includes(o))throw new Error("The value to change is not in the report.");return{...e,report:new TextEncoder().encode(n.replace(o,r))}}function Dd(e){let t=JSON.parse(e),o=new TextDecoder().decode(Uint8Array.from(atob(t.payload),i=>i.charCodeAt(0))).replace(/"outcome":"(VERIFIED|STOPPED|UNKNOWN|FAILED)"/,(i,l)=>`"outcome":"${l==="VERIFIED"?"STOPPED":"VERIFIED"}"`),r=new TextEncoder().encode(o),a="";for(let i of r)a+=String.fromCharCode(i);return JSON.stringify({...t,payload:btoa(a)})}var Fd=`-----BEGIN CERTIFICATE----- +`)){if(!p.startsWith("— "))continue;let u=p.slice(2).split(" ");if(u.length<2)continue;let f=u.slice(0,-1).join(" "),v;try{v=Tt(u.at(-1))}catch{continue}let m=Ht(v.slice(0,4));for(let b of t)if(!(c!==b.origin||f!==b.origin)&&b.logId.slice(0,8)===m&&await _s(b,v.slice(4),l))return{origin:a[0],size:BigInt(a[1]),root:i,treeId:h}}return null}var gn=async e=>Ht(await Yn(Zn(Ge(e)))),Ec=(e,t)=>Zn(`${bs}\0${Ge({nonce:t,...e})}`);async function Nc(e){try{let t=ys(new TextDecoder().decode(e));return t.length!==44||Ht(t.slice(0,12))!==yc?null:t.slice(12)}catch{return null}}async function Xn(e,t,n,o){return or({seal_sha256:await gn(e)},t,n,o)}async function or(e,t,n,o){let r=[],a=(H,G,V={})=>({ok:H,reason:G,steps:r,...V});if(t==null)return a(!1,"anchor_missing");let i,l,d;try{if(t.schema!==bs)throw new Error("schema");if(i=String(t.nonce),l=t.entry,d=Object.fromEntries(Object.keys(e).map(H=>[H,t[H]])),!gs.test(i)||!l||!Object.values(d).every(H=>typeof H=="string"&&gs.test(H)))throw new Error("format")}catch{return r.push({id:"anchorEntry",result:"fail"}),a(!1,"anchor_malformed")}let c=Ht(new Uint8Array(await qn().digest("SHA-512",Ec(e,i))));if(Object.keys(e).some(H=>d[H]!==e[H])||t.statement_sha512!==c)return r.push({id:"anchorEntry",result:"fail"}),a(!1,"anchor_mismatch");let g,h,p,u,f,v,m,b,y,x,w,E;try{if(g=String(l.uuid),h=String(l.body),p=Tt(h),u=JSON.parse(new TextDecoder().decode(p)),f=l.integratedTime,v=String(l.logID),m=l.logIndex,!Number.isInteger(f)||!Number.isInteger(m))throw new Error("int");b=Tt(l.verification.signedEntryTimestamp),y=l.verification.inclusionProof,x=u.spec.data.hash,w=Tt(u.spec.signature.content),E=Tt(u.spec.signature.publicKey.content)}catch{return r.push({id:"anchorEntry",result:"fail"}),a(!1,"anchor_malformed")}let R={uuid:g,logIndex:m,integratedTime:f,logId:v},S=(H,G)=>(r.push({id:H,result:"fail"}),a(!1,G,R));if(u.kind!=="hashedrekord"||u.apiVersion!=="0.0.1")return S("anchorEntry","anchor_malformed");if(x?.algorithm!=="sha512"||x?.value!==c)return S("anchorEntry","anchor_mismatch");r.push({id:"anchorEntry",result:"pass"});let A=await Nc(E);if(!A||!nr(A,n))return S("anchorKey","anchor_key_mismatch");if(!await Xa(n,tr(c),w))return S("anchorKey","anchor_bad_signature");r.push({id:"anchorKey",result:"pass"});let L=o.find(H=>H.logId===v);if(!L)return S("anchorTime","anchor_unknown_log");let C=Zn(Ge({body:h,integratedTime:f,logID:v,logIndex:m}));if(!await _s(L,b,C))return S("anchorTime","anchor_bad_timestamp");r.push({id:"anchorTime",result:"pass"});let $=await kc(p);if(!g.endsWith(Ht($)))return S("anchorInclusion","anchor_bad_inclusion");let P,M,k;try{k=BigInt(y.treeSize),P=await wc(y.logIndex,y.treeSize,$,y.hashes.map(tr)),M=tr(y.rootHash)}catch{return S("anchorInclusion","anchor_malformed")}if(!P||!nr(P,M))return S("anchorInclusion","anchor_bad_inclusion");r.push({id:"anchorInclusion",result:"pass"});let B=await Sc(String(y.checkpoint),[L]);return!B||!nr(B.root,M)||B.size!==k||g.length===80&&B.treeId!==null&&g.slice(0,16)!==B.treeId.toString(16).padStart(16,"0")?S("anchorCheckpoint","anchor_bad_checkpoint"):(r.push({id:"anchorCheckpoint",result:"pass"}),a(!0,null,R))}var Tc=(e,t)=>!!(t&&e?.scope?.seal_key_ids?.includes(t.key_id));function xs(e){if(e==null||Xe(e)!==null)return null;try{return JSON.parse(e)}catch{return null}}async function ks(e,t,{requireAnchor:n=!1,requireAuthorization:o=!1,logKeys:r=null}={}){let a=await rs(e.sealText,e.report,t,"report.json"),i=[...a.steps],l=(y,x,w={})=>({...a,ok:y,reason:x,steps:i,sealOk:a.ok,...w});if(!a.ok)return l(!1,a.reason);let d=r||[await Jn(Vn)],c=y=>{let x=fn(t).filter(w=>w.key_id===y&&w.status==="active");return x.length===1?Ue(x[0].public_key):null},g=null,h=null,p=null;if(e.auth){let y=await ds(e.auth.statement,e.auth.sig);if(i=[...i,...y.steps],!y.ok)return l(!1,y.reason);let x=null;try{x=JSON.parse(new TextDecoder().decode(e.report))}catch{x=null}p=x?.started_at??null;let w=us(a.seal,x,y),E={auth_not_referenced:"authRef",auth_reference_mismatch:"authRef",auth_scope_mismatch:"authScope",auth_bundle_mismatch:"authBundle"};if(w){let R=E[w]||"authRef";for(let S of["authRef","authScope","authBundle"]){if(S===R)break;i=[...i,{id:S,result:"pass"}]}return i=[...i,{id:R,result:"fail"}],l(!1,w)}if(i=[...i,{id:"authRef",result:"pass"},{id:"authScope",result:"pass"},{id:"authBundle",result:"pass"}],g={login:y.login,fingerprint:y.fingerprint,sha256:y.sha256,publicKey:y.publicKey},e.auth.anchorText!=null){let R=xs(e.auth.anchorText),A=Tc(y.statement,R)?c(R.key_id):null,L=R?A?await or({run_authorization_sha256:y.sha256,signature_sha256:y.signatureSha256},R,A,d):{ok:!1,reason:"anchor_key_mismatch"}:{ok:!1,reason:"anchor_malformed"};if(i=[...i,{id:"authLogged",result:L.ok?"pass":"fail"}],!L.ok)return l(!1,`authorization_${L.reason}`,{authorizedBy:g});h=L.integratedTime}}else if(o)return i=[...i,{id:"authShape",result:"fail"}],l(!1,"auth_missing");if(e.anchorText==null){let y=er(h,p,null);return n?(i=[...i,{id:"anchorEntry",result:"fail"}],l(!1,"anchor_missing",{authorizedBy:g,timing:y})):l(!0,null,{authorizedBy:g,timing:y})}let u=xs(e.anchorText);if(!u)return i=[...i,{id:"anchorEntry",result:"fail"}],l(!1,"anchor_malformed",{authorizedBy:g});let f=c(a.seal.key_id),v=await Xn(a.seal,u,f,d);i=[...i,...v.steps];let m=er(h,p,v.ok?v.integratedTime:null),b=fs(h,v.ok?v.integratedTime:null);return l(v.ok,v.reason,{authorizedBy:g,timing:m,authAnchorTime:h,authorizationVsSeal:b,anchor:v.ok?{uuid:v.uuid,logIndex:v.logIndex,integratedTime:v.integratedTime,logId:v.logId}:null})}var $c="https://in-toto.io/Statement/v1",Ac="https://openadapt.ai/record/run/v1",ws="application/vnd.in-toto+json",Rc="openadapt.receipt-card/v1",Mc="openadapt.receipt-openings/v1",Ic="openadapt.receipt-keys/v1",As="openadapt.public-disclosure/v1",Cc="openadapt.receipt-commitment/v1",Ss=256,mn=2**53-1,Pc=65536,Oc=["this_computer","customer_key","openadapt_cloud","public_log","demo"],Es=["this_computer","customer_key","openadapt_cloud","public_log"],Lc={this_computer:"Signed by this computer",customer_key:"Signed by {org}'s key",openadapt_cloud:"Countersigned by OpenAdapt Cloud",public_log:"Logged publicly",demo:"Demo key: checks only in this demo"},zc={unknown_signer:"Not verified: unknown signer",unknown_role:"Not verified: unknown signer role",unknown_schema:"Not verified: unknown receipt format",unsigned:"Not verified: no signature",revoked_key:"Not verified: the signing key was revoked",bad_signature:"Not verified: the receipt was changed after it was signed",mixed_demo:"Not verified: a demo key signed alongside a real one",embedded_content:"Not verified: the receipt holds embedded content",opening_mismatch:"Not verified: a disclosed value doesn't match the receipt",disclosure_not_allowed:"Not verified: the card reveals a field it may not",inconsistent:"Not verified: the receipt contradicts itself",malformed:"Not verified: malformed receipt",verifier_unavailable:"Not verified: this browser can't check Ed25519 signatures"},Dc=e=>zc[e]||"Not verified",$t=/^[a-f0-9]{64}$/,Fc=/^[a-f0-9]{64}$/,Hc=/^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:00:00Z$/,Qn=/^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$/,jc=/^prog-[a-f0-9]{16}$/,Gc=/^[a-z][a-z0-9_]{0,47}$/,Uc=/^[A-Za-z0-9 ._-]{1,48}$/,rr=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,Rs={program_name:/^[A-Za-z0-9 ._-]{1,48}$/,flow_version:/^[0-9]{1,4}\.[0-9]{1,4}\.[0-9]{1,6}$/,github_login:/^[A-Za-z0-9-]{1,39}$/,run_id:/^[A-Za-z0-9._:-]{1,128}$/},Bc={[As]:["program_name","flow_version","github_login"]},Kc=["VERIFIED","STOPPED","UNKNOWN","FAILED"],Wc=["report.json","report.canonical","bundle","evidence","payload"],Vc=["application/json","application/cbor","text/plain","text/csv","application/pdf","application/octet-stream"],qc=["tx_receipt","write_receipt"],Zc=["ehr","payer_portal","bank","erp","crm","government_portal","email","other"],Yc=["portal_read_back","api","acknowledgment_message"],Ms=["portal_read_back","api"],Jc=["sent","acknowledged","recorded_as_intended","recorded_differently"],Xc=["read_back","acknowledgment","none"],Qc=["each_item","problems_only","not_gated"],ed=["person","agent","none"],td={sent:["rejected_by_counterparty","ambiguous_key","receiver_unreachable","not_found","no_answer_by_deadline"],acknowledged:["ambiguous_key","not_found","no_answer_by_deadline"],recorded_as_intended:["conflicting_report"],recorded_differently:["conflicting_report"]},nd=/^(?:counterparty|observed_at|reason|field\.[0-9]{1,2})$/,od=/^(?:principal|scope|approved_at)$/,rd=/^confirmations\.([0-9]{1,2})\.(counterparty|observed_at|reason|field\.[0-9]{1,2})$/,ad=/^approval\.(principal|scope|approved_at)$/,sd={counterparty:/^(?:ehr|payer_portal|bank|erp|crm|government_portal|email|other):cp-[a-f0-9]{16}$/,observed_at:Qn,reason:/^(?:rejected_by_counterparty|conflicting_report|ambiguous_key|receiver_unreachable|not_found|no_answer_by_deadline)$/,field:/^[a-z][a-z0-9_]{0,31}:[a-f0-9]{64}(?::differs)?$/,principal:/^(?:person|agent):pr-[a-f0-9]{16}$/,scope:$t,approved_at:Qn},id=["gui","api"],ld=["write","irreversible_write"],cd=["confirmed","refuted","not_checked"],dd=["read_back","same_screen","none"],pd=["effect_not_declared","approved_unverified","field_values","postconditions","uncertain"],ud="openadapt.evidence-scope/v1",fd=["unchecked","same_screen","reopened","separate_session","system_of_record","counterparty_confirmed"],hd=["VERIFIED","SHOWN","CONFIRMED","ATTESTED","RECORDED"],Ns={separate_session:"separate_session",system_api:"system_of_record",activity_log:"system_of_record",db_frame:"system_of_record",owned_connection:"system_of_record"},gd=["none","browser_network","http_proxy","api_client","db_connection"],md=["http","graphql","fhir","sql","websocket","grpc","smtp"],bd=["server_side_async_effects","outbound_effects","changes_after_read_back","fields_not_read","other_records","other_actors","read_back_time"],vd=["server_side_async_effects","outbound_effects"],yd=720*3600,_d={VERIFIED:["VERIFIED"],CONFIRMED:["VERIFIED"],SHOWN:["UNKNOWN","STOPPED","FAILED"],ATTESTED:["UNKNOWN","STOPPED","FAILED"],RECORDED:["UNKNOWN","STOPPED","FAILED"]},I=class extends Error{constructor(t,n=""){super(n||t),this.reason=t}},Ts=(e,t="")=>({ok:!1,reason:e,detail:t,signerLines:[Dc(e)],outcome:null,demo:!1,disclosed:{}}),xd=/data:[a-z]+\//i,kd=/[a-z][a-z0-9+.-]*:\/\//i,wd=/[A-Za-z0-9+/_-]{96,}={0,2}/,Sd=["iVBORw0KGgo","/9j/","R0lGOD","UklGR","PHN2Zy"];function ar(e){let t=e.toLowerCase();return[...e].length>256||xd.test(e)||kd.test(e)||wd.test(e)||Sd.some(n=>e.startsWith(n))||t.includes("e!==null&&typeof e=="object"&&!Array.isArray(e);function Oe(e,t,n=[],o=""){if(!Fe(e))throw new I("malformed",`${o} is an object`);for(let r of Object.keys(e))if(!t.includes(r)&&!n.includes(r))throw new I("malformed",`${o}.${r} is not a field`);for(let r of t)if(!(r in e))throw new I("malformed",`${o}.${r} is missing`)}function it(e,t,n,o){if(!Number.isInteger(e)||en)throw new I("malformed",`${o} is an integer from ${t} to ${n}`)}function oe(e,t,n){if(!(typeof e=="string"&&(Array.isArray(t)?t.includes(e):t.test(e))))throw new I("malformed",`${n} is not valid`)}function Ed(e,t){Oe(e,["required","confirmed"],[],t),it(e.required,0,mn,`${t}.required`),it(e.confirmed,0,mn,`${t}.confirmed`)}function Nd(e){if(Oe(e,["_type","subject","predicateType","predicate"],[],"$"),!Array.isArray(e.subject)||e.subject.length<1||e.subject.length>4)throw new I("malformed","subject has 1 to 4 entries");for(let[o,r]of e.subject.entries())Oe(r,["name","digest"],["media_type"],`subject[${o}]`),oe(r.name,Wc,`subject[${o}].name`),"media_type"in r&&oe(r.media_type,Vc,`subject[${o}].media_type`),Oe(r.digest,["sha256"],[],`subject[${o}].digest`),oe(r.digest.sha256,$t,`subject[${o}].digest.sha256`);let t=e.predicate;if(Oe(t,["program","started_hour","outcome","steps","lines","checks","model_calls","disclosure"],["reason_code","confirmations","approval","evidence_scope"],"predicate"),Oe(t.program,["id","version_sha256"],[],"predicate.program"),oe(t.program.id,jc,"predicate.program.id"),oe(t.program.version_sha256,$t,"predicate.program.version_sha256"),oe(t.started_hour,Hc,"predicate.started_hour"),oe(t.outcome,Kc,"predicate.outcome"),t.reason_code!=null&&oe(t.reason_code,Gc,"predicate.reason_code"),Oe(t.steps,["total","ok"],[],"predicate.steps"),it(t.steps.total,0,mn,"predicate.steps.total"),it(t.steps.ok,0,mn,"predicate.steps.ok"),!Array.isArray(t.lines)||t.lines.length>Ss)throw new I("malformed","predicate.lines");for(let[o,r]of t.lines.entries()){let a=`predicate.lines[${o}]`;if(Oe(r,["step","target_kind","operation","check","strength","not_checked"],["evidence"],a),"evidence"in r&&(Oe(r.evidence,["kind","sha256"],[],`${a}.evidence`),oe(r.evidence.kind,qc,`${a}.evidence.kind`),oe(r.evidence.sha256,$t,`${a}.evidence.sha256`)),it(r.step,0,1e4,`${a}.step`),oe(r.target_kind,id,`${a}.target_kind`),oe(r.operation,ld,`${a}.operation`),oe(r.check,cd,`${a}.check`),oe(r.strength,dd,`${a}.strength`),!Array.isArray(r.not_checked)||r.not_checked.length>5)throw new I("malformed",`${a}.not_checked`);r.not_checked.forEach((i,l)=>oe(i,pd,`${a}.not_checked[${l}]`))}let n=t.checks;Oe(n,["identity","postconditions","effects","authorization","lines_confirmed","lines_refuted","lines_not_checked"],[],"predicate.checks");for(let o of["identity","postconditions","effects","authorization"])Ed(n[o],`predicate.checks.${o}`);for(let o of["lines_confirmed","lines_refuted","lines_not_checked"])it(n[o],0,Ss,`predicate.checks.${o}`);if(it(t.model_calls,0,mn,"predicate.model_calls"),Oe(t.disclosure,["version","commitments"],[],"predicate.disclosure"),oe(t.disclosure.version,[As],"predicate.disclosure.version"),!Fe(t.disclosure.commitments)||Object.keys(t.disclosure.commitments).length>16)throw new I("malformed","predicate.disclosure.commitments");for(let o of Object.values(t.disclosure.commitments))if(typeof o!="string")throw new I("malformed","a commitment is a string");if("confirmations"in t){if(!Array.isArray(t.confirmations)||t.confirmations.length>64)throw new I("malformed","predicate.confirmations");for(let[o,r]of t.confirmations.entries()){let a=`predicate.confirmations[${o}]`;if(Oe(r,["kind","system_kind","read_method","state","strength","differing_count","commitments"],["for_step"],a),oe(r.kind,["counterparty_confirmation"],`${a}.kind`),r.for_step!=null&&it(r.for_step,0,1e4,`${a}.for_step`),oe(r.system_kind,Zc,`${a}.system_kind`),oe(r.read_method,Yc,`${a}.read_method`),oe(r.state,Jc,`${a}.state`),oe(r.strength,Xc,`${a}.strength`),it(r.differing_count,0,64,`${a}.differing_count`),!Fe(r.commitments)||Object.keys(r.commitments).length<2||Object.keys(r.commitments).length>34)throw new I("malformed",`${a}.commitments`)}}if("approval"in t&&(Oe(t.approval,["mode","approver_kind","commitments"],[],"predicate.approval"),oe(t.approval.mode,Qc,"predicate.approval.mode"),oe(t.approval.approver_kind,ed,"predicate.approval.approver_kind"),!Fe(t.approval.commitments)||Object.keys(t.approval.commitments).length>3))throw new I("malformed","predicate.approval.commitments");if("evidence_scope"in t){let o=t.evidence_scope;Oe(o,["schema","check_level","word","wire","not_covered"],["basis","read_back_at","recheck_window_s"],"predicate.evidence_scope"),oe(o.schema,[ud],"predicate.evidence_scope.schema"),oe(o.check_level,fd,"predicate.evidence_scope.check_level"),oe(o.word,hd,"predicate.evidence_scope.word"),"basis"in o&&oe(o.basis,Object.keys(Ns),"predicate.evidence_scope.basis"),Oe(o.wire,["channel","protocols_parsed"],[],"predicate.evidence_scope.wire"),oe(o.wire.channel,gd,"predicate.evidence_scope.wire.channel");let r=o.wire.protocols_parsed;if(!Array.isArray(r)||r.length>7)throw new I("malformed","predicate.evidence_scope.wire.protocols_parsed");if(r.forEach((a,i)=>oe(a,md,`predicate.evidence_scope.wire.protocols_parsed[${i}]`)),new Set(r).size!==r.length)throw new I("malformed","wire.protocols_parsed repeats a protocol");if(o.wire.channel==="none"&&r.length)throw new I("malformed","a run that watched no wire parsed no protocol");if("read_back_at"in o&&oe(o.read_back_at,Qn,"predicate.evidence_scope.read_back_at"),"recheck_window_s"in o&&it(o.recheck_window_s,0,yd,"predicate.evidence_scope.recheck_window_s"),!Array.isArray(o.not_covered)||o.not_covered.length<2||o.not_covered.length>7)throw new I("malformed","predicate.evidence_scope.not_covered");if(o.not_covered.forEach((a,i)=>oe(a,bd,`predicate.evidence_scope.not_covered[${i}]`)),new Set(o.not_covered).size!==o.not_covered.length)throw new I("malformed","not_covered repeats a code");if(!vd.every(a=>o.not_covered.includes(a)))throw new I("malformed","not_covered must list server_side_async_effects and outbound_effects");if(o.basis!=null&&Ns[o.basis]!==o.check_level)throw new I("malformed",`basis ${o.basis} does not reach ${o.check_level}`);if(o.word==="VERIFIED"){if(!["separate_session","system_of_record"].includes(o.check_level)||o.basis==null)throw new I("malformed","VERIFIED needs level 3 or 4 and a basis");if(o.read_back_at==null&&!o.not_covered.includes("read_back_time"))throw new I("malformed","VERIFIED needs read_back_at, or says it has none")}if(o.word==="SHOWN"&&!["same_screen","reopened"].includes(o.check_level))throw new I("malformed","SHOWN is a level 1 or 2 re-read of the acting screen");if(o.word==="CONFIRMED"&&o.check_level!=="counterparty_confirmed")throw new I("malformed","CONFIRMED is level 5, the counterparty acknowledgment");if(o.read_back_at!=null&&o.not_covered.includes("read_back_time"))throw new I("malformed","a block with read_back_at covers the read-back time");if(o.recheck_window_s!=null&&o.read_back_at==null)throw new I("malformed","a recheck window needs read_back_at")}return{...e,predicate:{...t,reason_code:t.reason_code??null}}}function Td(e){let t=e.predicate,n=e.subject.map(a=>a.name);if(new Set(n).size!==n.length||!(n.includes("report.json")||n.includes("report.canonical")))return"subject names repeat, or the report is missing";for(let a of e.subject)if(a.name==="payload"!="media_type"in a)return"only the payload subject has a media type, and it always has one";if(t.approval){let a=t.approval;for(let[i,l]of Object.entries(a.commitments))if(!od.test(i)||!$t.test(l))return`approval commitment ${i} is not a known field`;if(a.mode==="not_gated"&&a.approver_kind!=="none")return"a not_gated run names no approver";if(a.approver_kind==="none"){if(Object.keys(a.commitments).length)return"an approval with no approver commits to nothing"}else if(!("principal"in a.commitments&&"scope"in a.commitments))return"an approval names its approver's principal and scope"}for(let[a,i]of Object.entries(t.disclosure.commitments))if(!Rs[a]||!$t.test(i))return`disclosure path ${a} is not a known field`;if(t.steps.ok>t.steps.total)return"steps.ok is more than steps.total";for(let a of["identity","postconditions","effects","authorization"])if(t.checks[a].confirmed>t.checks[a].required)return`checks.${a} confirms more than it requires`;let o={confirmed:0,refuted:0,not_checked:0};for(let a of t.lines){if(o[a.check]+=1,a.check==="confirmed"&&a.strength==="none")return"a confirmed line has no strength";if(new Set(a.not_checked).size!==a.not_checked.length)return"a line repeats a not_checked code"}if(t.checks.lines_confirmed!==o.confirmed||t.checks.lines_refuted!==o.refuted||t.checks.lines_not_checked!==o.not_checked)return"check counts disagree with the lines";if(t.outcome==="VERIFIED"&&o.refuted)return"a VERIFIED receipt has a refuted line";if(t.evidence_scope&&!_d[t.evidence_scope.word].includes(t.outcome))return"the evidence scope's word disagrees with the outcome";let r=t.lines.map(a=>a.step);for(let a=1;a0)return"differing_count disagrees with the state";if(!("counterparty"in a.commitments&&"observed_at"in a.commitments))return"a confirmation commits to its counterparty and observed_at";for(let[l,d]of Object.entries(a.commitments))if(!nd.test(l)||!$t.test(d))return`confirmation commitment ${l} is not a known field`;let i=Object.keys(a.commitments).filter(l=>l.startsWith("field.")).length;if(a.differing_count>i)return"more differing fields than observed fields"}return null}var jt=e=>new TextEncoder().encode(e);function Is(...e){let t=new Uint8Array(e.reduce((o,r)=>o+r.length,0)),n=0;for(let o of e)t.set(o,n),n+=o.length;return t}var $d=e=>Uint8Array.from(e.match(/../g),t=>parseInt(t,16));async function Ad(e,t,n){let o=new Uint8Array([0]);return Me(Is(jt(Cc),o,jt(e),o,$d(t),o,jt(Ge(n))))}function Rd(e,t){let n=rd.exec(e)||ad.exec(e);if(n){let r=(n[2]||n[1]).split(".")[0];return typeof t=="string"&&sd[r].test(t)?null:`${e} does not match its field's pattern`}let o=Rs[e];return o?typeof t!="string"?`${e} is not a string`:ar(t)?`${e} holds embedded content`:o.test(t)?null:`${e} does not match its field's pattern`:`${e} is not a disclosure field`}async function $s(e,t,n){if(!Fe(e))throw new I("malformed","openings are an object");let o=eo(e);if(o)throw new I("embedded_content",o);let r={};for(let[a,i]of Object.entries(e)){if(n&&!n.includes(a))throw new I("disclosure_not_allowed",a);if(!Fe(i)||Object.keys(i).length!==2||!("salt"in i)||!("value"in i))throw new I("malformed",`the opening for ${a}`);let l=Rd(a,i.value);if(l)throw new I("malformed",l);if(!(typeof i.salt=="string"&&Fc.test(i.salt)))throw new I("malformed",`the salt for ${a}`);if(t[a]!==await Ad(a,i.salt,i.value))throw new I("opening_mismatch",a);r[a]=i.value}return r}async function Md(e){if(!Fe(e)||e.schema!==Ic)throw new I("unknown_schema","not an openadapt.receipt-keys/v1 registry");if(!Array.isArray(e.keys))throw new I("malformed","a registry has a keys list");let t=[];for(let n of e.keys){if(!Fe(n))throw new I("malformed","a registry entry is an object");if(Object.keys(n).some(a=>!["key_id","public_key","role","status","revoked_at","org"].includes(a)))throw new I("malformed","a registry entry has an unknown field");if(!Oc.includes(n.role))throw new I("unknown_role",`unknown signer role ${n.role}`);if(typeof n.public_key!="string"||!rr.test(n.public_key))throw new I("malformed","a public key is base64");let o=Ue(n.public_key);if(o.length!==32||n.key_id!==`seal-ed25519-${(await Me(o)).slice(0,16)}`)throw new I("malformed","a key id doesn't match its public key");let r=n.status??"active";if(!["active","revoked"].includes(r)||r==="revoked"&&!(typeof n.revoked_at=="string"&&Qn.test(n.revoked_at)))throw new I("malformed","a key is active, or revoked with revoked_at");if(n.role==="customer_key"&&!(typeof n.org=="string"&&Uc.test(n.org)))throw new I("malformed","a customer key names its org");t.push({keyId:n.key_id,raw:o,role:n.role,status:r,revokedAt:r==="revoked"?n.revoked_at:null,org:n.role==="customer_key"?n.org:null})}if(new Set(t.map(n=>n.keyId)).size!==t.length)throw new I("malformed","a registry lists one key id twice");return t}function Id(e,t){let n=jt(e);return Is(jt(`DSSEv1 ${n.length} `),n,jt(` ${t.length} `),t)}var Cd=e=>Fe(e)&&e.schema===Rc;function Pd(e){if(Xe(e)!==null)throw new I("malformed","duplicate key");try{return JSON.parse(e)}catch{throw new I("malformed","the payload is not JSON")}}async function Od(e,t,n){let o;try{o=await globalThis.crypto.subtle.importKey("raw",e,{name:"Ed25519"},!1,["verify"])}catch{throw new I("verifier_unavailable")}return globalThis.crypto.subtle.verify({name:"Ed25519"},o,t,n)}async function Cs(e,t,{openings:n=null}={}){try{let o=await Md(t),r=null,a=null,i=e;if(Cd(e)){if(Object.keys(e).sort().join(",")!=="disclosure_version,envelope,openings,schema")throw new I("malformed","a card has exactly four fields");if(a=Bc[e.disclosure_version],!a)throw new I("unknown_schema","unknown public disclosure version");if(r=e.openings,!Fe(r))throw new I("malformed","a card's openings are an object");if(i=e.envelope,n!=null)throw new I("malformed","a card carries its own openings")}if(!Fe(i)||Object.keys(i).sort().join(",")!=="payload,payloadType,signatures")throw new I("malformed","a DSSE envelope has payloadType, payload, signatures");if(i.payloadType!==ws)throw new I("unknown_schema","the payload is not an in-toto statement");if(typeof i.payload!="string"||!rr.test(i.payload))throw new I("malformed","the payload is not base64");let l=Ue(i.payload);if(l.length>Pc)throw new I("malformed","the payload is too large");let d=i.signatures;if(!Array.isArray(d)||!d.length)throw new I("unsigned");let c=new Map(o.map($=>[$.keyId,$])),g=Id(ws,l),h=[],p=new Set;for(let $ of d){if(!Fe($)||Object.keys($).sort().join(",")!=="keyid,sig")throw new I("malformed","a signature has keyid and sig");let P=$.keyid;if(typeof P!="string"||p.has(P))throw new I("malformed","a signature's keyid is missing or repeated");p.add(P);let M=c.get(P);if(!M)throw new I("unknown_signer",`${P} is not in the pinned registry`);if(typeof $.sig!="string"||!rr.test($.sig))throw new I("bad_signature",`${P}'s signature`);if(!await Od(M.raw,Ue($.sig),g))throw new I("bad_signature",`${P}'s signature`);if(M.status==="revoked")throw new I("revoked_key",`${P} was revoked at ${M.revokedAt}`);h.push({keyId:P,role:M.role,line:Lc[M.role].replace("{org}",M.org||"the customer")})}let u=new Set(h.map($=>$.role)),f=u.has("demo");if(f&&u.size!==1)throw new I("mixed_demo");let v;try{v=new TextDecoder("utf-8",{fatal:!0}).decode(l)}catch{throw new I("malformed","the payload is not UTF-8")}let m=Pd(v);if(!Fe(m))throw new I("malformed","the payload is not an object");if(m._type!==$c||m.predicateType!==Ac)throw new I("unknown_schema","not a record/run/v1 statement");let b=Object.fromEntries(Object.entries(m).filter(([$])=>$!=="_type"&&$!=="predicateType")),y=eo(b);if(y)throw new I("embedded_content",y);let x=Nd(m);if(Ge(x)!==v)throw new I("malformed","the payload is not canonical JSON");let w=Td(x);if(w)throw new I("inconsistent",w);let E={...x.predicate.disclosure.commitments};for(let[$,P]of(x.predicate.confirmations||[]).entries())for(let[M,k]of Object.entries(P.commitments))E[`confirmations.${$}.${M}`]=k;if(x.predicate.approval)for(let[$,P]of Object.entries(x.predicate.approval.commitments))E[`approval.${$}`]=P;let R={},S=!1;if(r)R=await $s(r,E,a);else if(n!=null){if(!Fe(n)||Object.keys(n).sort().join(",")!=="openings,payload_sha256,schema")throw new I("malformed","a private openings file has three fields");if(n.schema!==Mc)throw new I("unknown_schema","not an openadapt.receipt-openings/v1 file");if(n.payload_sha256!==await Me(l))throw new I("opening_mismatch","the openings belong to another receipt");R=await $s(n.openings,E,null),S=!0;for(let[$,P]of(x.predicate.confirmations||[]).entries()){let M=R[`confirmations.${$}.reason`];if(M!=null&&!td[P.state].includes(M))throw new I("inconsistent",`a ${P.state} confirmation can't have reason ${M}`)}}let A=[...h].sort(($,P)=>Es.indexOf($.role)-Es.indexOf(P.role)),L=[...new Set(A.map($=>$.line))],C=x.predicate.confirmations||[];return{ok:!0,reason:null,detail:"",signerLines:L,confirmationLines:C.map(($,P)=>zd($,R[`confirmations.${P}.observed_at`])),independent:C.map($=>Ms.includes($.read_method)),approvalLine:Ld(x.predicate.approval),outcome:x.predicate.outcome,demo:f,disclosed:R,private:S,statement:x}}catch(o){return o instanceof I?Ts(o.reason,o.message):Ts("malformed",String(o?.message||o))}}function Ld(e){return e?e.mode==="not_gated"?"Not gated: no approval was required for these writes":e.approver_kind==="none"?`Approval required for ${e.mode==="each_item"?"each item":"items that fail a check"}; no item was approved`:`Approved by ${e.approver_kind==="person"?"a person":"an agent delegate"}: ${e.mode==="each_item"?"each item":"items that failed a check"}`:"No approval recorded"}function zd(e,t){let n=t?` at ${t}`:"";return e.state==="recorded_as_intended"?`Confirmed in the other party's system${n}`:e.state==="recorded_differently"?`Recorded differently in the other party's system${n}: ${e.differing_count} ${e.differing_count===1?"field differs":"fields differ"}`:e.state==="acknowledged"?`Acknowledged by the other party${n}`:`Sent to the other party${n}, not confirmed`}async function ft(e,t=!1){let n=await fetch(e,{cache:"no-store"});if(!n.ok)throw new Error(`${e}: ${n.status}`);return t?new Uint8Array(await n.arrayBuffer()):n.text()}async function Ps(e,t=null){let[n,o,r,a,i,l]=await Promise.all([ft(e.report,!0),ft(e.seal),e.anchor?ft(e.anchor):null,e.tsa?ft(e.tsa):null,e.tsr?ft(e.tsr,!0):null,t?Promise.all([ft(t.statement),ft(t.sig),ft(t.signers),t.anchor?ft(t.anchor):null]):null]);return{report:n,sealText:o,anchorText:r,tsaText:a,tsrBytes:i,auth:l?{statement:l[0],sig:l[1],signers:l[2],anchorText:l[3]}:null}}var Os={VERIFIED:"HALTED",HALTED:"VERIFIED"};function Ls(e,t){let n=t||e,o=Os[n]||"VERIFIED",r=Os[e]||"VERIFIED";return[{id:"report-outcome",target:"report",label:"Change the outcome in the report",field:"execution_outcome",from:n,to:o,text:[`"execution_outcome": "${n}"`,`"execution_outcome": "${o}"`]},{id:"report-model-calls",target:"report",label:"Add one AI model call to the report",field:"model_calls",from:"0",to:"1",text:['"model_calls": 0','"model_calls": 1']},{id:"seal-outcome",target:"seal",label:"Change the outcome in the receipt",field:"outcome",from:e,to:r}]}function zs(e,t){if(t.target==="seal"){let a=JSON.parse(e.sealText);if(a[t.field]!==t.from)throw new Error("The value to change is not in the receipt.");return{...e,sealText:JSON.stringify({...a,[t.field]:t.to},null,2),receiptText:e.receiptText?Dd(e.receiptText):e.receiptText}}let n=new TextDecoder().decode(e.report),[o,r]=t.text;if(!n.includes(o))throw new Error("The value to change is not in the report.");return{...e,report:new TextEncoder().encode(n.replace(o,r))}}function Dd(e){let t=JSON.parse(e),o=new TextDecoder().decode(Uint8Array.from(atob(t.payload),i=>i.charCodeAt(0))).replace(/"outcome":"(VERIFIED|STOPPED|UNKNOWN|FAILED)"/,(i,l)=>`"outcome":"${l==="VERIFIED"?"STOPPED":"VERIFIED"}"`),r=new TextEncoder().encode(o),a="";for(let i of r)a+=String.fromCharCode(i);return JSON.stringify({...t,payload:btoa(a)})}var Fd=`-----BEGIN CERTIFICATE----- MIIB9zCCAXygAwIBAgIUV7f0GLDOoEzIh8LXSW80OJiUp14wCgYIKoZIzj0EAwMw OTEVMBMGA1UEChMMc2lnc3RvcmUuZGV2MSAwHgYDVQQDExdzaWdzdG9yZS10c2Et c2VsZnNpZ25lZDAeFw0yNTA0MDgwNjU5NDNaFw0zNTA0MDYwNjU5NDNaMDkxFTAT diff --git a/packages/seal-view/CHANGELOG.md b/packages/seal-view/CHANGELOG.md index 20847f188a..6f2d6c5123 100644 --- a/packages/seal-view/CHANGELOG.md +++ b/packages/seal-view/CHANGELOG.md @@ -2,6 +2,11 @@ ## v0.1.0 (unreleased) +- The receipt verifier refuses an `evidence_scope` the Python verifier + refuses: a `null` block, `basis`, `read_back_at` or `recheck_window_s` set + to `null`, and a `wire` without `protocols_parsed`. Before, it read those + as absent and could say VERIFIED where Python said malformed. Six shared + vectors in `packages/types` pin the answer. - Every string a reader sees says "receipt", not "Seal". The verdict card always shows a signer line ("Signed by this computer", "Demo key: checks only in this demo" with `host.signer: 'demo'`, or "Not verified: unknown diff --git a/packages/seal-view/src/lib/receiptRecord.mjs b/packages/seal-view/src/lib/receiptRecord.mjs index 83368134de..4b97319578 100644 --- a/packages/seal-view/src/lib/receiptRecord.mjs +++ b/packages/seal-view/src/lib/receiptRecord.mjs @@ -250,22 +250,24 @@ function validateStatement(s) { str(p.approval.approver_kind, APPROVER_KINDS, 'predicate.approval.approver_kind') if (!isObj(p.approval.commitments) || Object.keys(p.approval.commitments).length > 3) throw new Refusal('malformed', 'predicate.approval.commitments') } - if ('evidence_scope' in p && p.evidence_scope !== null) { + // Python's canonical round trip refuses a null block, a null optional field + // and a missing wire.protocols_parsed, so present means validated here too. + if ('evidence_scope' in p) { const es = p.evidence_scope closed(es, ['schema', 'check_level', 'word', 'wire', 'not_covered'], ['basis', 'read_back_at', 'recheck_window_s'], 'predicate.evidence_scope') str(es.schema, [EVIDENCE_SCOPE_SCHEMA], 'predicate.evidence_scope.schema') str(es.check_level, CHECK_LEVELS, 'predicate.evidence_scope.check_level') str(es.word, OUTCOME_WORDS, 'predicate.evidence_scope.word') - if (es.basis != null) str(es.basis, Object.keys(BASIS_LEVEL), 'predicate.evidence_scope.basis') - closed(es.wire, ['channel'], ['protocols_parsed'], 'predicate.evidence_scope.wire') + if ('basis' in es) str(es.basis, Object.keys(BASIS_LEVEL), 'predicate.evidence_scope.basis') + closed(es.wire, ['channel', 'protocols_parsed'], [], 'predicate.evidence_scope.wire') str(es.wire.channel, WIRE_CHANNELS, 'predicate.evidence_scope.wire.channel') - const protos = es.wire.protocols_parsed ?? [] + const protos = es.wire.protocols_parsed if (!Array.isArray(protos) || protos.length > 7) throw new Refusal('malformed', 'predicate.evidence_scope.wire.protocols_parsed') protos.forEach((pr, j) => str(pr, WIRE_PROTOCOLS, `predicate.evidence_scope.wire.protocols_parsed[${j}]`)) if (new Set(protos).size !== protos.length) throw new Refusal('malformed', 'wire.protocols_parsed repeats a protocol') if (es.wire.channel === 'none' && protos.length) throw new Refusal('malformed', 'a run that watched no wire parsed no protocol') - if (es.read_back_at != null) str(es.read_back_at, ISO_SECONDS, 'predicate.evidence_scope.read_back_at') - if (es.recheck_window_s != null) int(es.recheck_window_s, 0, MAX_RECHECK_S, 'predicate.evidence_scope.recheck_window_s') + if ('read_back_at' in es) str(es.read_back_at, ISO_SECONDS, 'predicate.evidence_scope.read_back_at') + if ('recheck_window_s' in es) int(es.recheck_window_s, 0, MAX_RECHECK_S, 'predicate.evidence_scope.recheck_window_s') if (!Array.isArray(es.not_covered) || es.not_covered.length < 2 || es.not_covered.length > 7) throw new Refusal('malformed', 'predicate.evidence_scope.not_covered') es.not_covered.forEach((nc, j) => str(nc, NOT_COVERED, `predicate.evidence_scope.not_covered[${j}]`)) if (new Set(es.not_covered).size !== es.not_covered.length) throw new Refusal('malformed', 'not_covered repeats a code') diff --git a/packages/types/CHANGELOG.md b/packages/types/CHANGELOG.md index 4a3b966aaf..b832b3076f 100644 --- a/packages/types/CHANGELOG.md +++ b/packages/types/CHANGELOG.md @@ -1,6 +1,15 @@ # CHANGELOG +## Unreleased + +- Test vectors only, no code change: six `record/run/v1` vectors + (`evidence-scope-null`, `evidence-scope-null-basis`, + `evidence-scope-null-read-back-at`, `evidence-scope-null-recheck-window`, + `evidence-scope-protocols-null`, `evidence-scope-protocols-missing`) sign + an `evidence_scope` with a `null` or missing field. Each payload is not + canonical, so every verifier must refuse it as `malformed`. + ## v0.24.2 (2026-11-23) 0.24.1 was stamped on main but never published. 0.24.2 is the first diff --git a/packages/types/tests/vectors/record-run-v1/README.md b/packages/types/tests/vectors/record-run-v1/README.md index d6aec22f75..c7b0edd94a 100644 --- a/packages/types/tests/vectors/record-run-v1/README.md +++ b/packages/types/tests/vectors/record-run-v1/README.md @@ -42,7 +42,10 @@ not secrets. receipt with a refuted line) are `inconsistent`. The predicate may carry an optional `evidence_scope` block (`openadapt.evidence-scope/v1`, closed; see `openadapt_types/evidence_scope.py`); a receipt without it still verifies. - With it, a `VERIFIED` outcome needs the word `VERIFIED` (level 3 or 4, with + The block is never `null`, an optional field in it (`basis`, + `read_back_at`, `recheck_window_s`) is left out rather than set to `null`, + and `wire.protocols_parsed` is always present (`[]` when none): those + payloads are not canonical, so `malformed`. With it, a `VERIFIED` outcome needs the word `VERIFIED` (level 3 or 4, with a basis) or `CONFIRMED`, and no other outcome may carry either; otherwise `inconsistent`. 4. **Commitments.** `sha256("openadapt.receipt-commitment/v1" 0x00 path 0x00 diff --git a/packages/types/tests/vectors/record-run-v1/evidence-scope-null-basis.json b/packages/types/tests/vectors/record-run-v1/evidence-scope-null-basis.json new file mode 100644 index 0000000000..6bed6b1f08 --- /dev/null +++ b/packages/types/tests/vectors/record-run-v1/evidence-scope-null-basis.json @@ -0,0 +1,21 @@ +{ + "description": "A SHOWN evidence scope with basis set to null: refused.", + "document": { + "payload": "eyJfdHlwZSI6Imh0dHBzOi8vaW4tdG90by5pby9TdGF0ZW1lbnQvdjEiLCJwcmVkaWNhdGUiOnsiY2hlY2tzIjp7ImF1dGhvcml6YXRpb24iOnsiY29uZmlybWVkIjowLCJyZXF1aXJlZCI6MH0sImVmZmVjdHMiOnsiY29uZmlybWVkIjoxLCJyZXF1aXJlZCI6Mn0sImlkZW50aXR5Ijp7ImNvbmZpcm1lZCI6NSwicmVxdWlyZWQiOjV9LCJsaW5lc19jb25maXJtZWQiOjEsImxpbmVzX25vdF9jaGVja2VkIjowLCJsaW5lc19yZWZ1dGVkIjoxLCJwb3N0Y29uZGl0aW9ucyI6eyJjb25maXJtZWQiOjMsInJlcXVpcmVkIjozfX0sImRpc2Nsb3N1cmUiOnsiY29tbWl0bWVudHMiOnt9LCJ2ZXJzaW9uIjoib3BlbmFkYXB0LnB1YmxpYy1kaXNjbG9zdXJlL3YxIn0sImV2aWRlbmNlX3Njb3BlIjp7ImJhc2lzIjpudWxsLCJjaGVja19sZXZlbCI6InNhbWVfc2NyZWVuIiwibm90X2NvdmVyZWQiOlsic2VydmVyX3NpZGVfYXN5bmNfZWZmZWN0cyIsIm91dGJvdW5kX2VmZmVjdHMiLCJjaGFuZ2VzX2FmdGVyX3JlYWRfYmFjayIsInJlYWRfYmFja190aW1lIl0sInNjaGVtYSI6Im9wZW5hZGFwdC5ldmlkZW5jZS1zY29wZS92MSIsIndpcmUiOnsiY2hhbm5lbCI6Im5vbmUiLCJwcm90b2NvbHNfcGFyc2VkIjpbXX0sIndvcmQiOiJTSE9XTiJ9LCJsaW5lcyI6W3siY2hlY2siOiJjb25maXJtZWQiLCJub3RfY2hlY2tlZCI6W10sIm9wZXJhdGlvbiI6IndyaXRlIiwic3RlcCI6Miwic3RyZW5ndGgiOiJyZWFkX2JhY2siLCJ0YXJnZXRfa2luZCI6Imd1aSJ9LHsiY2hlY2siOiJyZWZ1dGVkIiwibm90X2NoZWNrZWQiOlsiZmllbGRfdmFsdWVzIl0sIm9wZXJhdGlvbiI6ImlycmV2ZXJzaWJsZV93cml0ZSIsInN0ZXAiOjQsInN0cmVuZ3RoIjoicmVhZF9iYWNrIiwidGFyZ2V0X2tpbmQiOiJndWkifV0sIm1vZGVsX2NhbGxzIjowLCJvdXRjb21lIjoiU1RPUFBFRCIsInByb2dyYW0iOnsiaWQiOiJwcm9nLTViYjIxYWEwZjJlNmFjMzIiLCJ2ZXJzaW9uX3NoYTI1NiI6IjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIifSwicmVhc29uX2NvZGUiOiJoYWx0ZWQiLCJzdGFydGVkX2hvdXIiOiIyMDI2LTExLTIwVDIzOjAwOjAwWiIsInN0ZXBzIjp7Im9rIjo0LCJ0b3RhbCI6NX19LCJwcmVkaWNhdGVUeXBlIjoiaHR0cHM6Ly9vcGVuYWRhcHQuYWkvcmVjb3JkL3J1bi92MSIsInN1YmplY3QiOlt7ImRpZ2VzdCI6eyJzaGEyNTYiOiIxMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExIn0sIm5hbWUiOiJyZXBvcnQuanNvbiJ9LHsiZGlnZXN0Ijp7InNoYTI1NiI6IjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIifSwibmFtZSI6ImJ1bmRsZSJ9XX0=", + "payloadType": "application/vnd.in-toto+json", + "signatures": [ + { + "keyid": "seal-ed25519-b7a5ba90250d87f2", + "sig": "wVeAoQkb0pxyYLUn7AbOhsPJrrTLqFBdmV1im9nsLHERxFsUKZYLYRAJlJMurhjL078AAmDLKzv8HgH5TMgxBQ==" + } + ] + }, + "expected": { + "ok": false, + "reason": "malformed", + "signer_lines": [ + "Not verified: malformed receipt" + ] + }, + "registry": "registry.json" +} diff --git a/packages/types/tests/vectors/record-run-v1/evidence-scope-null-read-back-at.json b/packages/types/tests/vectors/record-run-v1/evidence-scope-null-read-back-at.json new file mode 100644 index 0000000000..8bcd523646 --- /dev/null +++ b/packages/types/tests/vectors/record-run-v1/evidence-scope-null-read-back-at.json @@ -0,0 +1,21 @@ +{ + "description": "A VERIFIED evidence scope with read_back_at set to null: refused.", + "document": { + "payload": "eyJfdHlwZSI6Imh0dHBzOi8vaW4tdG90by5pby9TdGF0ZW1lbnQvdjEiLCJwcmVkaWNhdGUiOnsiY2hlY2tzIjp7ImF1dGhvcml6YXRpb24iOnsiY29uZmlybWVkIjowLCJyZXF1aXJlZCI6MH0sImVmZmVjdHMiOnsiY29uZmlybWVkIjoyLCJyZXF1aXJlZCI6Mn0sImlkZW50aXR5Ijp7ImNvbmZpcm1lZCI6NSwicmVxdWlyZWQiOjV9LCJsaW5lc19jb25maXJtZWQiOjIsImxpbmVzX25vdF9jaGVja2VkIjowLCJsaW5lc19yZWZ1dGVkIjowLCJwb3N0Y29uZGl0aW9ucyI6eyJjb25maXJtZWQiOjMsInJlcXVpcmVkIjozfX0sImRpc2Nsb3N1cmUiOnsiY29tbWl0bWVudHMiOnt9LCJ2ZXJzaW9uIjoib3BlbmFkYXB0LnB1YmxpYy1kaXNjbG9zdXJlL3YxIn0sImV2aWRlbmNlX3Njb3BlIjp7ImJhc2lzIjoic2VwYXJhdGVfc2Vzc2lvbiIsImNoZWNrX2xldmVsIjoic2VwYXJhdGVfc2Vzc2lvbiIsIm5vdF9jb3ZlcmVkIjpbInNlcnZlcl9zaWRlX2FzeW5jX2VmZmVjdHMiLCJvdXRib3VuZF9lZmZlY3RzIiwiY2hhbmdlc19hZnRlcl9yZWFkX2JhY2siLCJyZWFkX2JhY2tfdGltZSJdLCJyZWFkX2JhY2tfYXQiOm51bGwsInNjaGVtYSI6Im9wZW5hZGFwdC5ldmlkZW5jZS1zY29wZS92MSIsIndpcmUiOnsiY2hhbm5lbCI6Im5vbmUiLCJwcm90b2NvbHNfcGFyc2VkIjpbXX0sIndvcmQiOiJWRVJJRklFRCJ9LCJsaW5lcyI6W3siY2hlY2siOiJjb25maXJtZWQiLCJub3RfY2hlY2tlZCI6W10sIm9wZXJhdGlvbiI6IndyaXRlIiwic3RlcCI6Miwic3RyZW5ndGgiOiJyZWFkX2JhY2siLCJ0YXJnZXRfa2luZCI6Imd1aSJ9LHsiY2hlY2siOiJjb25maXJtZWQiLCJub3RfY2hlY2tlZCI6WyJmaWVsZF92YWx1ZXMiXSwib3BlcmF0aW9uIjoiaXJyZXZlcnNpYmxlX3dyaXRlIiwic3RlcCI6NCwic3RyZW5ndGgiOiJyZWFkX2JhY2siLCJ0YXJnZXRfa2luZCI6Imd1aSJ9XSwibW9kZWxfY2FsbHMiOjAsIm91dGNvbWUiOiJWRVJJRklFRCIsInByb2dyYW0iOnsiaWQiOiJwcm9nLTViYjIxYWEwZjJlNmFjMzIiLCJ2ZXJzaW9uX3NoYTI1NiI6IjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIifSwicmVhc29uX2NvZGUiOiJ2ZXJpZmllZCIsInN0YXJ0ZWRfaG91ciI6IjIwMjYtMTEtMjBUMjM6MDA6MDBaIiwic3RlcHMiOnsib2siOjUsInRvdGFsIjo1fX0sInByZWRpY2F0ZVR5cGUiOiJodHRwczovL29wZW5hZGFwdC5haS9yZWNvcmQvcnVuL3YxIiwic3ViamVjdCI6W3siZGlnZXN0Ijp7InNoYTI1NiI6IjExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTEifSwibmFtZSI6InJlcG9ydC5qc29uIn0seyJkaWdlc3QiOnsic2hhMjU2IjoiMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMiJ9LCJuYW1lIjoiYnVuZGxlIn1dfQ==", + "payloadType": "application/vnd.in-toto+json", + "signatures": [ + { + "keyid": "seal-ed25519-b7a5ba90250d87f2", + "sig": "p0OwcO1P2jqJVII9fkPF3PNgqrrxCD8aY9Fl8MeWMLpl7dhowoIfCFAD9y8B6Cxa6D09ecwJbxRfpRH8pfT8Dw==" + } + ] + }, + "expected": { + "ok": false, + "reason": "malformed", + "signer_lines": [ + "Not verified: malformed receipt" + ] + }, + "registry": "registry.json" +} diff --git a/packages/types/tests/vectors/record-run-v1/evidence-scope-null-recheck-window.json b/packages/types/tests/vectors/record-run-v1/evidence-scope-null-recheck-window.json new file mode 100644 index 0000000000..9b903bd435 --- /dev/null +++ b/packages/types/tests/vectors/record-run-v1/evidence-scope-null-recheck-window.json @@ -0,0 +1,21 @@ +{ + "description": "A VERIFIED evidence scope with recheck_window_s set to null: refused.", + "document": { + "payload": "eyJfdHlwZSI6Imh0dHBzOi8vaW4tdG90by5pby9TdGF0ZW1lbnQvdjEiLCJwcmVkaWNhdGUiOnsiY2hlY2tzIjp7ImF1dGhvcml6YXRpb24iOnsiY29uZmlybWVkIjowLCJyZXF1aXJlZCI6MH0sImVmZmVjdHMiOnsiY29uZmlybWVkIjoyLCJyZXF1aXJlZCI6Mn0sImlkZW50aXR5Ijp7ImNvbmZpcm1lZCI6NSwicmVxdWlyZWQiOjV9LCJsaW5lc19jb25maXJtZWQiOjIsImxpbmVzX25vdF9jaGVja2VkIjowLCJsaW5lc19yZWZ1dGVkIjowLCJwb3N0Y29uZGl0aW9ucyI6eyJjb25maXJtZWQiOjMsInJlcXVpcmVkIjozfX0sImRpc2Nsb3N1cmUiOnsiY29tbWl0bWVudHMiOnt9LCJ2ZXJzaW9uIjoib3BlbmFkYXB0LnB1YmxpYy1kaXNjbG9zdXJlL3YxIn0sImV2aWRlbmNlX3Njb3BlIjp7ImJhc2lzIjoic2VwYXJhdGVfc2Vzc2lvbiIsImNoZWNrX2xldmVsIjoic2VwYXJhdGVfc2Vzc2lvbiIsIm5vdF9jb3ZlcmVkIjpbInNlcnZlcl9zaWRlX2FzeW5jX2VmZmVjdHMiLCJvdXRib3VuZF9lZmZlY3RzIiwiY2hhbmdlc19hZnRlcl9yZWFkX2JhY2siLCJyZWFkX2JhY2tfdGltZSJdLCJyZWNoZWNrX3dpbmRvd19zIjpudWxsLCJzY2hlbWEiOiJvcGVuYWRhcHQuZXZpZGVuY2Utc2NvcGUvdjEiLCJ3aXJlIjp7ImNoYW5uZWwiOiJub25lIiwicHJvdG9jb2xzX3BhcnNlZCI6W119LCJ3b3JkIjoiVkVSSUZJRUQifSwibGluZXMiOlt7ImNoZWNrIjoiY29uZmlybWVkIiwibm90X2NoZWNrZWQiOltdLCJvcGVyYXRpb24iOiJ3cml0ZSIsInN0ZXAiOjIsInN0cmVuZ3RoIjoicmVhZF9iYWNrIiwidGFyZ2V0X2tpbmQiOiJndWkifSx7ImNoZWNrIjoiY29uZmlybWVkIiwibm90X2NoZWNrZWQiOlsiZmllbGRfdmFsdWVzIl0sIm9wZXJhdGlvbiI6ImlycmV2ZXJzaWJsZV93cml0ZSIsInN0ZXAiOjQsInN0cmVuZ3RoIjoicmVhZF9iYWNrIiwidGFyZ2V0X2tpbmQiOiJndWkifV0sIm1vZGVsX2NhbGxzIjowLCJvdXRjb21lIjoiVkVSSUZJRUQiLCJwcm9ncmFtIjp7ImlkIjoicHJvZy01YmIyMWFhMGYyZTZhYzMyIiwidmVyc2lvbl9zaGEyNTYiOiIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyIn0sInJlYXNvbl9jb2RlIjoidmVyaWZpZWQiLCJzdGFydGVkX2hvdXIiOiIyMDI2LTExLTIwVDIzOjAwOjAwWiIsInN0ZXBzIjp7Im9rIjo1LCJ0b3RhbCI6NX19LCJwcmVkaWNhdGVUeXBlIjoiaHR0cHM6Ly9vcGVuYWRhcHQuYWkvcmVjb3JkL3J1bi92MSIsInN1YmplY3QiOlt7ImRpZ2VzdCI6eyJzaGEyNTYiOiIxMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExIn0sIm5hbWUiOiJyZXBvcnQuanNvbiJ9LHsiZGlnZXN0Ijp7InNoYTI1NiI6IjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIifSwibmFtZSI6ImJ1bmRsZSJ9XX0=", + "payloadType": "application/vnd.in-toto+json", + "signatures": [ + { + "keyid": "seal-ed25519-b7a5ba90250d87f2", + "sig": "ZIfKTQb12W/VUyhWJsaes1Y90+AJDs/REqb4X6e8x6j1UOKMirPa4xqzZNiCAL1m9ulDCMBn6UTEXKoIWEmfBw==" + } + ] + }, + "expected": { + "ok": false, + "reason": "malformed", + "signer_lines": [ + "Not verified: malformed receipt" + ] + }, + "registry": "registry.json" +} diff --git a/packages/types/tests/vectors/record-run-v1/evidence-scope-null.json b/packages/types/tests/vectors/record-run-v1/evidence-scope-null.json new file mode 100644 index 0000000000..0909cfb07c --- /dev/null +++ b/packages/types/tests/vectors/record-run-v1/evidence-scope-null.json @@ -0,0 +1,21 @@ +{ + "description": "An evidence_scope of null: refused, never read as absent.", + "document": { + "payload": "eyJfdHlwZSI6Imh0dHBzOi8vaW4tdG90by5pby9TdGF0ZW1lbnQvdjEiLCJwcmVkaWNhdGUiOnsiY2hlY2tzIjp7ImF1dGhvcml6YXRpb24iOnsiY29uZmlybWVkIjowLCJyZXF1aXJlZCI6MH0sImVmZmVjdHMiOnsiY29uZmlybWVkIjoyLCJyZXF1aXJlZCI6Mn0sImlkZW50aXR5Ijp7ImNvbmZpcm1lZCI6NSwicmVxdWlyZWQiOjV9LCJsaW5lc19jb25maXJtZWQiOjIsImxpbmVzX25vdF9jaGVja2VkIjowLCJsaW5lc19yZWZ1dGVkIjowLCJwb3N0Y29uZGl0aW9ucyI6eyJjb25maXJtZWQiOjMsInJlcXVpcmVkIjozfX0sImRpc2Nsb3N1cmUiOnsiY29tbWl0bWVudHMiOnt9LCJ2ZXJzaW9uIjoib3BlbmFkYXB0LnB1YmxpYy1kaXNjbG9zdXJlL3YxIn0sImV2aWRlbmNlX3Njb3BlIjpudWxsLCJsaW5lcyI6W3siY2hlY2siOiJjb25maXJtZWQiLCJub3RfY2hlY2tlZCI6W10sIm9wZXJhdGlvbiI6IndyaXRlIiwic3RlcCI6Miwic3RyZW5ndGgiOiJyZWFkX2JhY2siLCJ0YXJnZXRfa2luZCI6Imd1aSJ9LHsiY2hlY2siOiJjb25maXJtZWQiLCJub3RfY2hlY2tlZCI6WyJmaWVsZF92YWx1ZXMiXSwib3BlcmF0aW9uIjoiaXJyZXZlcnNpYmxlX3dyaXRlIiwic3RlcCI6NCwic3RyZW5ndGgiOiJyZWFkX2JhY2siLCJ0YXJnZXRfa2luZCI6Imd1aSJ9XSwibW9kZWxfY2FsbHMiOjAsIm91dGNvbWUiOiJWRVJJRklFRCIsInByb2dyYW0iOnsiaWQiOiJwcm9nLTViYjIxYWEwZjJlNmFjMzIiLCJ2ZXJzaW9uX3NoYTI1NiI6IjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIifSwicmVhc29uX2NvZGUiOiJ2ZXJpZmllZCIsInN0YXJ0ZWRfaG91ciI6IjIwMjYtMTEtMjBUMjM6MDA6MDBaIiwic3RlcHMiOnsib2siOjUsInRvdGFsIjo1fX0sInByZWRpY2F0ZVR5cGUiOiJodHRwczovL29wZW5hZGFwdC5haS9yZWNvcmQvcnVuL3YxIiwic3ViamVjdCI6W3siZGlnZXN0Ijp7InNoYTI1NiI6IjExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTEifSwibmFtZSI6InJlcG9ydC5qc29uIn0seyJkaWdlc3QiOnsic2hhMjU2IjoiMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMiJ9LCJuYW1lIjoiYnVuZGxlIn1dfQ==", + "payloadType": "application/vnd.in-toto+json", + "signatures": [ + { + "keyid": "seal-ed25519-b7a5ba90250d87f2", + "sig": "19I+1GdW5nWxW4r8oolCuUJ9eKcuHhlMM7PMRCs/d7ugvBfyqE1Jl8kha3MM0J5SLnOHjFcBN23RO/7GADCjAg==" + } + ] + }, + "expected": { + "ok": false, + "reason": "malformed", + "signer_lines": [ + "Not verified: malformed receipt" + ] + }, + "registry": "registry.json" +} diff --git a/packages/types/tests/vectors/record-run-v1/evidence-scope-protocols-missing.json b/packages/types/tests/vectors/record-run-v1/evidence-scope-protocols-missing.json new file mode 100644 index 0000000000..d4993994e3 --- /dev/null +++ b/packages/types/tests/vectors/record-run-v1/evidence-scope-protocols-missing.json @@ -0,0 +1,21 @@ +{ + "description": "An evidence scope whose wire leaves out protocols_parsed: refused.", + "document": { + "payload": "eyJfdHlwZSI6Imh0dHBzOi8vaW4tdG90by5pby9TdGF0ZW1lbnQvdjEiLCJwcmVkaWNhdGUiOnsiY2hlY2tzIjp7ImF1dGhvcml6YXRpb24iOnsiY29uZmlybWVkIjowLCJyZXF1aXJlZCI6MH0sImVmZmVjdHMiOnsiY29uZmlybWVkIjoyLCJyZXF1aXJlZCI6Mn0sImlkZW50aXR5Ijp7ImNvbmZpcm1lZCI6NSwicmVxdWlyZWQiOjV9LCJsaW5lc19jb25maXJtZWQiOjIsImxpbmVzX25vdF9jaGVja2VkIjowLCJsaW5lc19yZWZ1dGVkIjowLCJwb3N0Y29uZGl0aW9ucyI6eyJjb25maXJtZWQiOjMsInJlcXVpcmVkIjozfX0sImRpc2Nsb3N1cmUiOnsiY29tbWl0bWVudHMiOnt9LCJ2ZXJzaW9uIjoib3BlbmFkYXB0LnB1YmxpYy1kaXNjbG9zdXJlL3YxIn0sImV2aWRlbmNlX3Njb3BlIjp7ImJhc2lzIjoic2VwYXJhdGVfc2Vzc2lvbiIsImNoZWNrX2xldmVsIjoic2VwYXJhdGVfc2Vzc2lvbiIsIm5vdF9jb3ZlcmVkIjpbInNlcnZlcl9zaWRlX2FzeW5jX2VmZmVjdHMiLCJvdXRib3VuZF9lZmZlY3RzIiwiY2hhbmdlc19hZnRlcl9yZWFkX2JhY2siLCJyZWFkX2JhY2tfdGltZSJdLCJzY2hlbWEiOiJvcGVuYWRhcHQuZXZpZGVuY2Utc2NvcGUvdjEiLCJ3aXJlIjp7ImNoYW5uZWwiOiJub25lIn0sIndvcmQiOiJWRVJJRklFRCJ9LCJsaW5lcyI6W3siY2hlY2siOiJjb25maXJtZWQiLCJub3RfY2hlY2tlZCI6W10sIm9wZXJhdGlvbiI6IndyaXRlIiwic3RlcCI6Miwic3RyZW5ndGgiOiJyZWFkX2JhY2siLCJ0YXJnZXRfa2luZCI6Imd1aSJ9LHsiY2hlY2siOiJjb25maXJtZWQiLCJub3RfY2hlY2tlZCI6WyJmaWVsZF92YWx1ZXMiXSwib3BlcmF0aW9uIjoiaXJyZXZlcnNpYmxlX3dyaXRlIiwic3RlcCI6NCwic3RyZW5ndGgiOiJyZWFkX2JhY2siLCJ0YXJnZXRfa2luZCI6Imd1aSJ9XSwibW9kZWxfY2FsbHMiOjAsIm91dGNvbWUiOiJWRVJJRklFRCIsInByb2dyYW0iOnsiaWQiOiJwcm9nLTViYjIxYWEwZjJlNmFjMzIiLCJ2ZXJzaW9uX3NoYTI1NiI6IjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIifSwicmVhc29uX2NvZGUiOiJ2ZXJpZmllZCIsInN0YXJ0ZWRfaG91ciI6IjIwMjYtMTEtMjBUMjM6MDA6MDBaIiwic3RlcHMiOnsib2siOjUsInRvdGFsIjo1fX0sInByZWRpY2F0ZVR5cGUiOiJodHRwczovL29wZW5hZGFwdC5haS9yZWNvcmQvcnVuL3YxIiwic3ViamVjdCI6W3siZGlnZXN0Ijp7InNoYTI1NiI6IjExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTEifSwibmFtZSI6InJlcG9ydC5qc29uIn0seyJkaWdlc3QiOnsic2hhMjU2IjoiMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMiJ9LCJuYW1lIjoiYnVuZGxlIn1dfQ==", + "payloadType": "application/vnd.in-toto+json", + "signatures": [ + { + "keyid": "seal-ed25519-b7a5ba90250d87f2", + "sig": "YG+uBVzQDTumQjkySMdooM8lsrUrU9cD7R3R4v8GAPJWrhfFsZ+6sWASjFQLwZAWu81kTPsG17XrWWyc4KoJDw==" + } + ] + }, + "expected": { + "ok": false, + "reason": "malformed", + "signer_lines": [ + "Not verified: malformed receipt" + ] + }, + "registry": "registry.json" +} diff --git a/packages/types/tests/vectors/record-run-v1/evidence-scope-protocols-null.json b/packages/types/tests/vectors/record-run-v1/evidence-scope-protocols-null.json new file mode 100644 index 0000000000..24ab26391b --- /dev/null +++ b/packages/types/tests/vectors/record-run-v1/evidence-scope-protocols-null.json @@ -0,0 +1,21 @@ +{ + "description": "An evidence scope with wire.protocols_parsed set to null: refused.", + "document": { + "payload": "eyJfdHlwZSI6Imh0dHBzOi8vaW4tdG90by5pby9TdGF0ZW1lbnQvdjEiLCJwcmVkaWNhdGUiOnsiY2hlY2tzIjp7ImF1dGhvcml6YXRpb24iOnsiY29uZmlybWVkIjowLCJyZXF1aXJlZCI6MH0sImVmZmVjdHMiOnsiY29uZmlybWVkIjoyLCJyZXF1aXJlZCI6Mn0sImlkZW50aXR5Ijp7ImNvbmZpcm1lZCI6NSwicmVxdWlyZWQiOjV9LCJsaW5lc19jb25maXJtZWQiOjIsImxpbmVzX25vdF9jaGVja2VkIjowLCJsaW5lc19yZWZ1dGVkIjowLCJwb3N0Y29uZGl0aW9ucyI6eyJjb25maXJtZWQiOjMsInJlcXVpcmVkIjozfX0sImRpc2Nsb3N1cmUiOnsiY29tbWl0bWVudHMiOnt9LCJ2ZXJzaW9uIjoib3BlbmFkYXB0LnB1YmxpYy1kaXNjbG9zdXJlL3YxIn0sImV2aWRlbmNlX3Njb3BlIjp7ImJhc2lzIjoic2VwYXJhdGVfc2Vzc2lvbiIsImNoZWNrX2xldmVsIjoic2VwYXJhdGVfc2Vzc2lvbiIsIm5vdF9jb3ZlcmVkIjpbInNlcnZlcl9zaWRlX2FzeW5jX2VmZmVjdHMiLCJvdXRib3VuZF9lZmZlY3RzIiwiY2hhbmdlc19hZnRlcl9yZWFkX2JhY2siLCJyZWFkX2JhY2tfdGltZSJdLCJzY2hlbWEiOiJvcGVuYWRhcHQuZXZpZGVuY2Utc2NvcGUvdjEiLCJ3aXJlIjp7ImNoYW5uZWwiOiJub25lIiwicHJvdG9jb2xzX3BhcnNlZCI6bnVsbH0sIndvcmQiOiJWRVJJRklFRCJ9LCJsaW5lcyI6W3siY2hlY2siOiJjb25maXJtZWQiLCJub3RfY2hlY2tlZCI6W10sIm9wZXJhdGlvbiI6IndyaXRlIiwic3RlcCI6Miwic3RyZW5ndGgiOiJyZWFkX2JhY2siLCJ0YXJnZXRfa2luZCI6Imd1aSJ9LHsiY2hlY2siOiJjb25maXJtZWQiLCJub3RfY2hlY2tlZCI6WyJmaWVsZF92YWx1ZXMiXSwib3BlcmF0aW9uIjoiaXJyZXZlcnNpYmxlX3dyaXRlIiwic3RlcCI6NCwic3RyZW5ndGgiOiJyZWFkX2JhY2siLCJ0YXJnZXRfa2luZCI6Imd1aSJ9XSwibW9kZWxfY2FsbHMiOjAsIm91dGNvbWUiOiJWRVJJRklFRCIsInByb2dyYW0iOnsiaWQiOiJwcm9nLTViYjIxYWEwZjJlNmFjMzIiLCJ2ZXJzaW9uX3NoYTI1NiI6IjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIifSwicmVhc29uX2NvZGUiOiJ2ZXJpZmllZCIsInN0YXJ0ZWRfaG91ciI6IjIwMjYtMTEtMjBUMjM6MDA6MDBaIiwic3RlcHMiOnsib2siOjUsInRvdGFsIjo1fX0sInByZWRpY2F0ZVR5cGUiOiJodHRwczovL29wZW5hZGFwdC5haS9yZWNvcmQvcnVuL3YxIiwic3ViamVjdCI6W3siZGlnZXN0Ijp7InNoYTI1NiI6IjExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTEifSwibmFtZSI6InJlcG9ydC5qc29uIn0seyJkaWdlc3QiOnsic2hhMjU2IjoiMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMiJ9LCJuYW1lIjoiYnVuZGxlIn1dfQ==", + "payloadType": "application/vnd.in-toto+json", + "signatures": [ + { + "keyid": "seal-ed25519-b7a5ba90250d87f2", + "sig": "tM1PYCIT3UgoRHhyJm+holJe26rrzYSX3E2i7s5SGSI2th5rhbSFBB0t2EX7X1qy4gtFniFxcSsol7OQHWPnAg==" + } + ] + }, + "expected": { + "ok": false, + "reason": "malformed", + "signer_lines": [ + "Not verified: malformed receipt" + ] + }, + "registry": "registry.json" +} diff --git a/packages/types/tests/vectors/record-run-v1/generate.py b/packages/types/tests/vectors/record-run-v1/generate.py index 6a2e05c44c..ca63943c75 100644 --- a/packages/types/tests/vectors/record-run-v1/generate.py +++ b/packages/types/tests/vectors/record-run-v1/generate.py @@ -267,9 +267,51 @@ def add(name, description, document, expected, openings=None): _handoff_vectors(vectors) _canonical_vectors(vectors) _chain_vectors(vectors) + _evidence_scope_shape_vectors(add, scoped) return vectors +def _signed_raw(statement_: dict) -> dict: + """An envelope signed by this computer's test key, bypassing the builder.""" + payload = r.canonical_json(statement_).encode() + sig = KEYS["this_computer"].sign(r.pae(r.PAYLOAD_TYPE, payload)) + return {"payloadType": r.PAYLOAD_TYPE, "payload": base64.b64encode(payload).decode(), + "signatures": [{"keyid": IDS["this_computer"], "sig": base64.b64encode(sig).decode()}]} + + +def _evidence_scope_shape_vectors(add, scoped: dict) -> None: + """An evidence scope with a null or missing field, signed anyway: malformed. + + The Python verifier refuses each because its payload is not the canonical + form (the canonical block leaves optional fields out and always lists + wire.protocols_parsed); a verifier without a round trip must refuse them too. + """ + + refused = {"ok": False, "reason": "malformed", "signer_lines": [r.refusal_line("malformed")]} + + def variant(edit, outcome_scope=None): + s = copy.deepcopy(outcome_scope or scoped) + edit(s["predicate"]) + return _signed_raw(s) + + add("evidence-scope-null", "An evidence_scope of null: refused, never read as absent.", + variant(lambda p: p.update(evidence_scope=None)), refused) + add("evidence-scope-null-read-back-at", "A VERIFIED evidence scope with read_back_at set to null: refused.", + variant(lambda p: p["evidence_scope"].update(read_back_at=None)), refused) + add("evidence-scope-null-recheck-window", "A VERIFIED evidence scope with recheck_window_s set to null: refused.", + variant(lambda p: p["evidence_scope"].update(recheck_window_s=None)), refused) + shown = statement("STOPPED") + shown["predicate"]["evidence_scope"] = copy.deepcopy(scoped["predicate"]["evidence_scope"]) + shown["predicate"]["evidence_scope"].update(check_level="same_screen", word="SHOWN") + del shown["predicate"]["evidence_scope"]["basis"] + add("evidence-scope-null-basis", "A SHOWN evidence scope with basis set to null: refused.", + variant(lambda p: p["evidence_scope"].update(basis=None), shown), refused) + add("evidence-scope-protocols-null", "An evidence scope with wire.protocols_parsed set to null: refused.", + variant(lambda p: p["evidence_scope"]["wire"].update(protocols_parsed=None)), refused) + add("evidence-scope-protocols-missing", "An evidence scope whose wire leaves out protocols_parsed: refused.", + variant(lambda p: p["evidence_scope"]["wire"].pop("protocols_parsed")), refused) + + def _chain_vectors(vectors) -> None: """Follow-up chains: an original receipt sent, then acknowledged, then recorded.""" sent, sent_openings = _confirmed("sent") diff --git a/tests/snapshots/seal_viewer_size.json b/tests/snapshots/seal_viewer_size.json index 793f0fe64a..92d25b7b68 100644 --- a/tests/snapshots/seal_viewer_size.json +++ b/tests/snapshots/seal_viewer_size.json @@ -1,5 +1,5 @@ { - "bytes": 257738, - "gzip_bytes": 82102, + "bytes": 257704, + "gzip_bytes": 82107, "budget_bytes": 262144 }