fix: align deployment manifest schema

This commit is contained in:
golem
2026-08-21 02:55:41 -06:00
parent be8f01ea4e
commit c6bf8a683f
8 changed files with 389 additions and 139 deletions
+66 -25
View File
@@ -8,22 +8,20 @@ export const EDUCATIONAL_WARNING = "Educational demo — mock token — never us
const NETWORKS = {
anvil: {
name: "anvil", chainId: 31337, canonical: "anvil.json", recovery: "make reset-local", rpcUrl: "http://127.0.0.1:8545", explorerUrl: "",
name: "anvil", chainId: 31337, canonical: "anvil.json", recovery: "make reset-local", rpcUrl: "http://127.0.0.1:8545",
},
"base-sepolia": {
name: "base-sepolia", chainId: 84532, canonical: "base-sepolia.json", recovery: "make archive-base-manifest", rpcUrl: "https://sepolia.base.org", explorerUrl: "https://sepolia.basescan.org",
baseSepolia: {
name: "baseSepolia", chainId: 84532, canonical: "base-sepolia.json", recovery: "make archive-base-manifest",
},
};
const MANIFEST_FIELDS = [
"schemaVersion", "network", "chainId", "deploymentBlock", "rpcUrl", "explorerUrl", "token", "proxy", "implementation", "owner", "actorLabels", "actors",
];
const REQUIRED_MANIFEST_FIELDS = ["schemaVersion", "network", "chainId", "deploymentBlock", "token", "proxy", "implementation", "owner", "actors"];
const OPTIONAL_MANIFEST_FIELDS = ["rpcUrl", "explorerBaseUrl"];
const ANVIL_TEST_PHRASE = "test test test test test test test test test test test junk";
const PROHIBITED_STRING_VALUE = /(?:private[_ -]?key|mnemonic|secret|password|credential|api[_ -]?key)|0x[a-fA-F0-9]{64}/i;
export function networkSpec(network) {
const normalized = network === "baseSepolia" ? "base-sepolia" : network;
const spec = NETWORKS[normalized];
const spec = NETWORKS[network];
if (!spec) throw new Error(`unsupported deployment network: ${network}`);
return spec;
}
@@ -106,24 +104,26 @@ export function validateManifest(manifest, { pending = false } = {}) {
if (!Number.isSafeInteger(manifest.deploymentBlock) || manifest.deploymentBlock < (pending ? 0 : 1)) {
throw new Error(`manifest deploymentBlock must be ${pending ? "a nonnegative integer" : "at least 1"}`);
}
if (manifest.rpcUrl !== spec.rpcUrl || manifest.explorerUrl !== spec.explorerUrl) {
throw new Error(`manifest display URLs must use the public ${manifest.network} endpoints`);
}
assertManifestUrls(manifest, spec);
for (const field of ["token", "proxy", "implementation", "owner"]) assertAddress(manifest[field], field);
if (!Array.isArray(manifest.actorLabels) || !Array.isArray(manifest.actors) || manifest.actorLabels.length !== manifest.actors.length || manifest.actors.length === 0) {
throw new Error("manifest actors and actorLabels must be nonempty parallel arrays");
}
if (!Array.isArray(manifest.actors) || manifest.actors.length === 0) throw new Error("manifest actors must be a nonempty array");
const labels = new Set();
const actors = new Set();
for (let index = 0; index < manifest.actors.length; index += 1) {
const label = manifest.actorLabels[index];
for (const [index, actorRecord] of manifest.actors.entries()) {
if (!actorRecord || typeof actorRecord !== "object" || Array.isArray(actorRecord)) throw new Error(`actors[${index}] must be an object`);
const keys = Object.keys(actorRecord);
if (keys.length !== 2 || !Object.hasOwn(actorRecord, "label") || !Object.hasOwn(actorRecord, "address")) {
throw new Error(`actors[${index}] must contain exactly label and address`);
}
const { label, address } = actorRecord;
if (typeof label !== "string" || label.trim() === "" || labels.has(label)) throw new Error("manifest actor labels must be unique nonempty strings");
labels.add(label);
assertAddress(manifest.actors[index], `actors[${index}]`);
const actor = manifest.actors[index].toLowerCase();
assertAddress(address, `actors[${index}].address`);
const actor = address.toLowerCase();
if (actors.has(actor)) throw new Error("manifest actors must be unique");
actors.add(actor);
}
assertActorConfiguration(manifest);
}
export async function atomicWriteJson(path, value) {
@@ -149,14 +149,55 @@ function assertAddress(value, label) {
}
function assertExactSchema(manifest) {
for (const field of MANIFEST_FIELDS) {
for (const field of REQUIRED_MANIFEST_FIELDS) {
if (!Object.hasOwn(manifest, field)) throw new Error(`manifest is missing required field ${field}`);
}
for (const field of Object.keys(manifest)) {
if (!MANIFEST_FIELDS.includes(field)) throw new Error(`manifest contains unknown field ${field}`);
if (![...REQUIRED_MANIFEST_FIELDS, ...OPTIONAL_MANIFEST_FIELDS].includes(field)) throw new Error(`manifest contains unknown field ${field}`);
}
}
function assertManifestUrls(manifest, spec) {
if (manifest.network === "anvil") {
if (manifest.rpcUrl !== spec.rpcUrl) throw new Error("manifest anvil rpcUrl must use the local public endpoint");
if (Object.hasOwn(manifest, "explorerBaseUrl")) throw new Error("manifest anvil must omit explorerBaseUrl");
return;
}
for (const field of OPTIONAL_MANIFEST_FIELDS) {
if (Object.hasOwn(manifest, field)) assertPublicUrl(manifest[field], field);
}
}
function assertPublicUrl(value, field) {
if (typeof value !== "string") throw new Error(`manifest ${field} must be a URL string`);
let url;
try {
url = new URL(value);
} catch {
throw new Error(`manifest ${field} must be a public URL`);
}
if ((url.protocol !== "https:" && url.protocol !== "http:") || url.username || url.password) {
throw new Error(`manifest ${field} must be a public URL without credentials`);
}
}
function assertActorConfiguration(manifest) {
const { actors, network, owner } = manifest;
if (network === "anvil") {
const expected = [
["owner", "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"],
["Alice", "0x70997970C51812dc3A010C7d01b50e0d17dc79C8"],
["Bob", "0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC"],
];
if (actors.length !== expected.length || actors.some((actor, index) => actor.label !== expected[index][0] || actor.address.toLowerCase() !== expected[index][1].toLowerCase())) {
throw new Error("manifest anvil actors must match the documented local actor configuration");
}
} else if (actors.length !== 1 || actors[0].label !== "owner") {
throw new Error("manifest baseSepolia must contain only the owner actor");
}
if (actors[0].address.toLowerCase() !== owner.toLowerCase()) throw new Error("manifest owner must be actor zero");
}
function rejectProhibitedStringValues(value, path = "") {
if (typeof value === "string") {
if (value.includes(ANVIL_TEST_PHRASE) || PROHIBITED_STRING_VALUE.test(value)) {
@@ -171,6 +212,7 @@ function rejectProhibitedStringValues(value, path = "") {
if (!value || typeof value !== "object") return;
for (const [key, nested] of Object.entries(value)) {
const nestedPath = path ? `${path}.${key}` : key;
rejectProhibitedStringValues(key, nestedPath);
rejectProhibitedStringValues(nested, nestedPath);
}
}
@@ -181,14 +223,13 @@ function publicManifest(manifest, deploymentBlock) {
network: manifest.network,
chainId: manifest.chainId,
deploymentBlock,
rpcUrl: manifest.rpcUrl,
explorerUrl: manifest.explorerUrl,
...(Object.hasOwn(manifest, "rpcUrl") ? { rpcUrl: manifest.rpcUrl } : {}),
...(Object.hasOwn(manifest, "explorerBaseUrl") ? { explorerBaseUrl: manifest.explorerBaseUrl } : {}),
token: manifest.token,
proxy: manifest.proxy,
implementation: manifest.implementation,
owner: manifest.owner,
actorLabels: [...manifest.actorLabels],
actors: [...manifest.actors],
actors: manifest.actors.map(({ label, address }) => ({ label, address })),
};
}
@@ -240,7 +281,7 @@ export async function runFinalizeCli(argv, { root = process.cwd(), log = console
if (network !== "--rpc-url" || typeof rest[0] !== "string" || rest.length !== 1) throw new Error("usage: finalize-manifest.mjs deploy --rpc-url <url>");
return finalizeDeployment({ root, rpc: fetchRpc(rest[0]) });
}
throw new Error("usage: finalize-manifest.mjs preflight-deploy <anvil|base-sepolia> | deploy --rpc-url <url>");
throw new Error("usage: finalize-manifest.mjs preflight-deploy <anvil|baseSepolia> | deploy --rpc-url <url>");
}
if (process.argv[1] && pathToFileURL(resolve(process.argv[1])).href === import.meta.url) {