19 lines
877 B
TypeScript
19 lines
877 B
TypeScript
import { createHash } from 'node:crypto';
|
|
import { parseStrategyVersionPackage } from '@stock-bot/stock-config/strategy';
|
|
import type { StrategyVersionPackage } from '@stock-bot/types';
|
|
|
|
/** Validates bytes and metadata only; never imports, compiles or calls candidate code. */
|
|
export function verifyRetainedProgramPackage(input: unknown): StrategyVersionPackage {
|
|
const pkg = parseStrategyVersionPackage(input);
|
|
const hash = (content: string) => createHash('sha256').update(content, 'utf8').digest('hex');
|
|
if (
|
|
hash(pkg.artifact.content) !== pkg.artifact.sha256 ||
|
|
hash(pkg.dependencyLock.content) !== pkg.dependencyLock.sha256
|
|
) {
|
|
throw new Error('Retained strategy artifact or dependency lock hash mismatch');
|
|
}
|
|
if (pkg.program.apiVersion !== 'canonical-ts/v1') {
|
|
throw new Error('Unsupported retained strategy API version');
|
|
}
|
|
return pkg;
|
|
}
|