import { ConfigurationError, record, text } from "./validation.ts"; export interface BridgeKey { readonly keyId: string; readonly publicKey: string; } export interface DeploymentRelease { readonly version: string; readonly artifactDigest: string; readonly operationId: string; } export function parseBridgeKey(value: unknown): BridgeKey { const v = record(value, ["keyId", "publicKey"], "bridge"); const keyId = text(v.keyId, "bridge.keyId"); const publicKey = text(v.publicKey, "bridge.publicKey"); if ( !/^[a-zA-Z0-9_-]{1,64}$/.test(keyId) || !/^[A-Za-z0-9_-]{43}$/.test(publicKey) ) throw new ConfigurationError( "bridge", "expected an Ed25519 public key and key ID", ); return Object.freeze({ keyId, publicKey }); } export function parseDeploymentRelease(value: unknown): DeploymentRelease { const v = record( value, ["version", "artifactDigest", "operationId"], "release", ); const version = text(v.version, "release.version"); const artifactDigest = text(v.artifactDigest, "release.artifactDigest"); const operationId = text(v.operationId, "release.operationId"); if ( version.length > 128 || !/^[a-f0-9]{64}$/.test(artifactDigest) || !/^[a-f0-9]{32}$/.test(operationId) ) throw new ConfigurationError("release", "invalid deployment identity"); return Object.freeze({ version, artifactDigest, operationId }); }