self_test
Validate sample receipt and bundle to prove the verifier works offline.
Instructions
Verify the packaged sample receipt and sample bundle to prove the verifier works offline.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- server.js:167-191 (registration)Registration of the 'self_test' tool via server.tool() with name 'self_test', description, empty schema {}, and an async handler.
server.tool( 'self_test', 'Verify the packaged sample receipt and sample bundle to prove the verifier works offline.', {}, async () => { try { const { receipt, bundle, publicKeyHex } = loadSelfTestArtifacts(); const receiptResult = verifySingle(receipt, publicKeyHex); const bundleResult = verifyBundle(bundle); return textResult({ ok: receiptResult.valid && bundleResult.valid, receipt: receiptResult, bundle: { valid: bundleResult.valid, total: bundleResult.total, passed: bundleResult.passed, failed: bundleResult.failed, }, note: 'No ScopeBlind servers were contacted.', }); } catch (error) { return textResult({ ok: false, error: error.message }); } } ); - server.js:167-191 (handler)Handler function for 'self_test': loads sample artifacts, calls verifySingle() and verifyBundle(), and returns combined result.
server.tool( 'self_test', 'Verify the packaged sample receipt and sample bundle to prove the verifier works offline.', {}, async () => { try { const { receipt, bundle, publicKeyHex } = loadSelfTestArtifacts(); const receiptResult = verifySingle(receipt, publicKeyHex); const bundleResult = verifyBundle(bundle); return textResult({ ok: receiptResult.valid && bundleResult.valid, receipt: receiptResult, bundle: { valid: bundleResult.valid, total: bundleResult.total, passed: bundleResult.passed, failed: bundleResult.failed, }, note: 'No ScopeBlind servers were contacted.', }); } catch (error) { return textResult({ ok: false, error: error.message }); } } ); - server.js:149-155 (helper)Helper function loadSelfTestArtifacts() that loads sample-receipt.json and sample-bundle.json from the 'samples' directory plus a hardcoded public key hex.
function loadSelfTestArtifacts() { return { receipt: JSON.parse(readFileSync(join(__dirname, 'samples', 'sample-receipt.json'), 'utf-8')), bundle: JSON.parse(readFileSync(join(__dirname, 'samples', 'sample-bundle.json'), 'utf-8')), publicKeyHex: 'd75a980182b10ab7d54bfed3c964073a0ee172f3daa62325af021a68f707511a', }; } - server.js:75-103 (helper)Helper function verifySingle() used by the self_test handler to verify a single artifact with a public key.
function verifySingle(artifact, publicKeyHex) { const core = getArtifactCore(artifact); const key = publicKeyHex || deriveEmbeddedKey(artifact); if (!key) { return { valid: false, error: 'no_public_key', type: artifact?.type || core.artifact?.type || 'unknown', format: core.format, kid: core.kid, issuer: artifact?.issuer || null, hash: null, }; } const result = verifyArtifact(core.artifact, key); const unsigned = { ...core.artifact }; delete unsigned.signature; return { valid: !!result.valid, error: result.valid ? null : (result.error || 'invalid_signature'), type: artifact?.type || core.artifact?.type || 'unknown', format: core.format, kid: core.kid, issuer: artifact?.issuer || null, hash: canonicalHash(unsigned), }; } - server.js:105-130 (helper)Helper function verifyBundle() used by the self_test handler to verify all receipts in a bundle.
function verifyBundle(bundle) { if (!bundle?.receipts || !Array.isArray(bundle.receipts)) { throw new Error('Invalid bundle: missing receipts array'); } const keyMap = resolveBundleKeyMap(bundle); let passed = 0; const receipts = bundle.receipts.map((receipt, index) => { const key = receipt?.kid ? keyMap.get(receipt.kid) : deriveEmbeddedKey(receipt); const result = verifySingle(receipt, key || null); if (result.valid) passed += 1; return { index, type: result.type, kid: result.kid, valid: result.valid, error: result.error, }; }); return { valid: passed === bundle.receipts.length, total: bundle.receipts.length, passed, failed: bundle.receipts.length - passed, receipts, }; }