Skip to content

Commit 7c4dd46

Browse files
authored
Merge pull request #11 from commandlayer/codex/fix-boot-logic-and-key-matching-in-server.mjs
[runtime] Fix DEV_AUTO_KEYS signer boot state and tighten public key env parsing
2 parents 4cef871 + 3be4d7b commit 7c4dd46

File tree

1 file changed

+12
-37
lines changed

1 file changed

+12
-37
lines changed

server.mjs

Lines changed: 12 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ function getPublicPemFromRaw32B64(b64) {
294294
function getPublicPemFromEnv() {
295295
const src = runtimeConfig.publicKeySource;
296296
if (!src) return null;
297-
if (src.name.endsWith("_PUBLIC_KEY_B64")) {
297+
if (src.name.endsWith("_PUBLIC_KEY_B64") || src.name.endsWith("_RAW32_B64")) {
298298
const raw = decodeB64Strict(src.value);
299299
if (!raw || raw.length !== 32) return null;
300300
runtimeConfig.publicKeyRaw32 = Buffer.from(raw);
@@ -325,6 +325,8 @@ function getPublicPemFromEnv() {
325325
}
326326

327327
function assertBootConfigOrThrow() {
328+
if (DEV_AUTO_KEYS) return;
329+
328330
const missing = [];
329331
if (!runtimeConfig.signerId) missing.push("CL_RECEIPT_SIGNER_ID|RECEIPT_SIGNER_ID");
330332
if (!runtimeConfig.privateKeySource) missing.push("receipt signing private key env var");
@@ -452,6 +454,10 @@ function initializeSignerConfigOrThrow() {
452454
maybeEnableDevAutoKeys();
453455
}
454456

457+
if (activeSigner.privateKeyPem && activeSigner.publicKeyPem && activeSigner.source === "dev_auto_keys") {
458+
signerBootState.errors = [];
459+
}
460+
455461
if (!activeSigner.privateKeyPem || !activeSigner.publicKeyPem) {
456462
signerBootState.errors.push(
457463
"Invalid signer config: provide RECEIPT_SIGNING_PRIVATE_KEY_PEM_B64 and RECEIPT_SIGNING_PUBLIC_KEY_B64 (or supported CL_/legacy aliases)"
@@ -469,6 +475,10 @@ function initializeSignerConfigOrThrow() {
469475
}
470476
}
471477

478+
console.log(
479+
`[boot] signer_ok=${signerBootState.ok} signer_source=${activeSigner.source} kid=${runtimeConfig.kid} fp=${activeSigner.publicKeyFingerprint || "n/a"}`
480+
);
481+
472482
printEnsTxtValues({
473483
pubRaw32B64: activeSigner.publicKeyRaw32B64,
474484
kid: runtimeConfig.kid,
@@ -1328,13 +1338,7 @@ async function handleVerb(verb, req, res) {
13281338
return res.json(receipt);
13291339
} catch (signErr) {
13301340
return respondSigningError(res, signErr);
1331-
1332-
1333-
const receipt = makeReceipt({ x402, trace, result, status: "success", actor });
1334-
1335-
1336-
return res.json(receipt);
1337-
eed1802 (Runtime: signer env standardization + ENS verify smoke)
1341+
}
13381342
} catch (e) {
13391343
const x402 = req.body?.x402 || { verb, version: "1.0.0", entry: `x402://${verb}agent.eth/${verb}/v1.0.0` };
13401344

@@ -1351,41 +1355,12 @@ return res.json(receipt);
13511355
details: { verb },
13521356
};
13531357

1354-
<<<<<<< HEAD
13551358
try {
13561359
const receipt = makeReceipt({ x402, trace, status: "error", error: err, actor });
13571360
return res.status(500).json(receipt);
13581361
} catch (signErr) {
13591362
return respondSigningError(res, signErr);
13601363
}
1361-
=======
1362-
let receipt;
1363-
try {
1364-
receipt = makeReceipt({ x402, trace, status: "error", error: err, actor });
1365-
} catch (e2) {
1366-
receipt = {
1367-
status: "error",
1368-
x402,
1369-
trace,
1370-
error: err,
1371-
metadata: {
1372-
proof: {
1373-
alg: "ed25519-sha256",
1374-
canonical: CANONICAL_ID_SORTED_KEYS_V1,
1375-
signer_id: SIGNER_ID,
1376-
kid: SIGNER_KID,
1377-
hash_sha256: null,
1378-
signature_b64: null,
1379-
note: "unsigned_error_receipt",
1380-
},
1381-
receipt_id: "",
1382-
...(actor ? { actor } : {}),
1383-
},
1384-
};
1385-
}
1386-
1387-
return res.status(500).json(receipt);
1388-
>>>>>>> eed1802 (Runtime: signer env standardization + ENS verify smoke)
13891364
}
13901365
}
13911366

0 commit comments

Comments
 (0)