@@ -872,12 +872,10 @@ function startWarmWorker() {
872872// -----------------------
873873// receipts (runtime-core: single source of truth)
874874// -----------------------
875- function makeReceipt ( { x402, trace , result, status = "success" , error = null , delegation_result = null , actor = null } ) {
875+ function makeReceipt ( { x402, result, status = "success" , error = null } ) {
876876 let receipt = {
877877 status,
878878 x402,
879- trace,
880- ...( delegation_result ? { delegation_result } : { } ) ,
881879 ...( error ? { error } : { } ) ,
882880 ...( status === "success" ? { result } : { } ) ,
883881 metadata : {
@@ -893,8 +891,6 @@ function makeReceipt({ x402, trace, result, status = "success", error = null, de
893891 } ,
894892 } ;
895893
896- if ( actor ) receipt . metadata . actor = actor ;
897-
898894 const privPem = getActivePrivatePem ( ) ;
899895 if ( ! privPem ) throw new Error ( "Missing/invalid private key" ) ;
900896
@@ -914,8 +910,28 @@ function makeReceipt({ x402, trace, result, status = "success", error = null, de
914910 return receipt ;
915911}
916912
917- function normalizeReceiptForRuntimeCoreVerify ( receipt ) {
918- const cloned = JSON . parse ( JSON . stringify ( receipt || { } ) ) ;
913+ function wrapReceiptResponse ( receipt , { trace = null , actor = null , delegation_result = null } = { } ) {
914+ const runtime_metadata = {
915+ ...( trace ? { trace } : { } ) ,
916+ ...( actor ? { actor } : { } ) ,
917+ ...( delegation_result ? { delegation_result } : { } ) ,
918+ } ;
919+
920+ return {
921+ receipt,
922+ ...( Object . keys ( runtime_metadata ) . length ? { runtime_metadata } : { } ) ,
923+ } ;
924+ }
925+
926+ function extractReceiptPayload ( payload ) {
927+ if ( payload && typeof payload === "object" && payload . receipt && typeof payload . receipt === "object" ) {
928+ return payload . receipt ;
929+ }
930+ return payload ;
931+ }
932+
933+ function normalizeReceiptForRuntimeCoreVerify ( payload ) {
934+ const cloned = JSON . parse ( JSON . stringify ( extractReceiptPayload ( payload ) || { } ) ) ;
919935 if ( cloned ?. metadata ?. proof && typeof cloned . metadata . proof === "object" ) {
920936 const proof = cloned . metadata . proof ;
921937 if ( ! proof . canonical && proof . canonical_id ) proof . canonical = proof . canonical_id ;
@@ -1351,18 +1367,12 @@ async function handleVerb(verb, req, res) {
13511367
13521368
13531369 try {
1354- const receipt = makeReceipt ( { x402, trace , result, status : "success" , actor } ) ;
1355- return res . json ( receipt ) ;
1370+ const receipt = makeReceipt ( { x402, result, status : "success" } ) ;
1371+ return res . json ( wrapReceiptResponse ( receipt , { trace , actor } ) ) ;
13561372 } catch ( signErr ) {
13571373 return respondSigningError ( res , signErr ) ;
13581374 }
13591375
1360-
1361- const receipt = makeReceipt ( { x402, trace, result, status : "success" , actor } ) ;
1362-
1363-
1364- return res . json ( receipt ) ;
1365-
13661376 } catch ( e ) {
13671377 const x402 = req . body ?. x402 || { verb, version : "1.0.0" , entry : `x402://${ verb } agent.eth/${ verb } /v1.0.0` } ;
13681378
@@ -1382,40 +1392,12 @@ return res.json(receipt);
13821392
13831393
13841394 try {
1385- const receipt = makeReceipt ( { x402, trace , status : "error" , error : err , actor } ) ;
1386- return res . status ( 500 ) . json ( receipt ) ;
1395+ const receipt = makeReceipt ( { x402, status : "error" , error : err } ) ;
1396+ return res . status ( 500 ) . json ( wrapReceiptResponse ( receipt , { trace , actor } ) ) ;
13871397 } catch ( signErr ) {
13881398 return respondSigningError ( res , signErr ) ;
13891399 }
13901400
1391-
1392- let receipt ;
1393- try {
1394- receipt = makeReceipt ( { x402, trace, status : "error" , error : err , actor } ) ;
1395- } catch ( e2 ) {
1396- receipt = {
1397- status : "error" ,
1398- x402,
1399- trace,
1400- error : err ,
1401- metadata : {
1402- proof : {
1403- alg : "ed25519-sha256" ,
1404- canonical : CANONICAL_ID_SORTED_KEYS_V1 ,
1405- signer_id : SIGNER_ID ,
1406- kid : SIGNER_KID ,
1407- hash_sha256 : null ,
1408- signature_b64 : null ,
1409- note : "unsigned_error_receipt" ,
1410- } ,
1411- receipt_id : "" ,
1412- ...( actor ? { actor } : { } ) ,
1413- } ,
1414- } ;
1415- }
1416-
1417- return res . status ( 500 ) . json ( receipt ) ;
1418-
14191401 }
14201402}
14211403
@@ -1601,7 +1583,8 @@ app.post("/debug/prewarm", requireDebug, (req, res) => {
16011583// verify endpoint (signature/hash + optional schema + optional ENS binding)
16021584// -----------------------
16031585app . post ( "/verify" , async ( req , res ) => {
1604- const receipt = req . body ;
1586+ const verifyInput = req . body ;
1587+ const receipt = extractReceiptPayload ( verifyInput ) ;
16051588
16061589 const wantEns = String ( req . query . ens || "0" ) === "1" ;
16071590 const strictKid = String ( req . query . strict_kid || "0" ) === "1" ;
@@ -1775,7 +1758,7 @@ app.post("/verify", async (req, res) => {
17751758 schemaOk = false ;
17761759 schemaErrors = [ { message : "validator_missing" } ] ;
17771760 } else {
1778- const ok = validate ( receipt ) ;
1761+ const ok = validate ( runtimeCoreReceipt ) ;
17791762 schemaOk = ! ! ok ;
17801763 if ( ! ok ) schemaErrors = ajvErrorsToSimple ( validate . errors ) || [ { message : "schema validation failed" } ] ;
17811764 }
0 commit comments