// Offline bundle verification against explicit World trust anchors. No network or persistent TUF state. import { certificateOf, digest, publicKeyOf } from './signing.ts'; /** Verify simulated keyless attestations using the World's certificate and transparency roots. * World certificate authorities do not run CT; signing time must still be authenticated by a log witness. */ export async function verifyAttestationBundle(bundle: unknown, trust: { certificates: readonly string[]; logKeys: readonly string[] }): Promise { if (!trust.certificates.length || !trust.logKeys.length) throw new Error('Attestation trust anchors are required'); // B1: protocol libraries are supplied by the pack and load only when the wire is used. const [{ bundleFromJSON }, { TrustedRoot }, { toSignedEntity, toTrustMaterial, Verifier }] = await Promise.all([import('@sigstore/bundle'), import('@sigstore/protobuf-specs'), import('@sigstore/verify')]); const root = TrustedRoot.fromJSON({ mediaType: 'application/vnd.dev.sigstore.trustedroot+json;version=0.1', certificateAuthorities: trust.certificates.map((pem) => { const cert = certificateOf(pem); if (!cert) throw new Error('Invalid attestation certificate root'); return { certChain: { certificates: [{ rawBytes: Buffer.from(cert.der).toString('base64') }] }, validFor: { start: cert.notBefore, end: cert.notAfter } }; }), tlogs: trust.logKeys.map((pem) => { const key = publicKeyOf(pem); return { hashAlgorithm: 'SHA2_256', logId: { keyId: Buffer.from(digest('sha256', key.der), 'hex').toString('base64') }, publicKey: { rawBytes: Buffer.from(key.der).toString('base64'), keyDetails: 'PUBLIC_KEY_DETAILS_UNSPECIFIED' }, }; }), ctlogs: [], timestampAuthorities: [], }); const entity = toSignedEntity(bundleFromJSON(bundle)); new Verifier(toTrustMaterial(root), { tlogThreshold: 1, ctlogThreshold: 0 }).verify(entity); }