@@ -20,6 +20,7 @@ import {
2020} from '@peac/mappings-a2a' ;
2121import { issue , verifyLocal } from '@peac/protocol' ;
2222import { computeReceiptRef } from '@peac/schema' ;
23+ import { A2AGrpcCarrierAdapter , GrpcMetadataKeys } from '@peac/transport-grpc' ;
2324
2425import agentCard from './agent-card.json' with { type : 'json' } ;
2526
@@ -109,7 +110,41 @@ if (!extracted) {
109110 }
110111}
111112
113+ // --- 5. gRPC metadata-carrier transport: same receipt, different carrier ---
114+ // This demonstrates metadata-carrier usage, not a full gRPC server/client.
115+ // The same receipt attached via A2A metadata or gRPC metadata produces
116+ // identical receipt_ref, proving transport-independent verification.
117+
118+ console . log ( '\n=== gRPC Metadata-Carrier Parity ===\n' ) ;
119+
120+ const grpcAdapter = new A2AGrpcCarrierAdapter ( ) ;
121+ const lastCarrier = allCarriers [ allCarriers . length - 1 ] ;
122+
123+ // Attach the last receipt to gRPC metadata (metadata-carrier transport)
124+ const grpcMetadata : Record < string , string | string [ ] | undefined > = { } ;
125+ grpcAdapter . attach ( grpcMetadata , [ lastCarrier ] ) ;
126+ console . log ( 'gRPC metadata key:' , GrpcMetadataKeys . RECEIPT ) ;
127+ console . log ( 'gRPC receipt type:' , grpcMetadata [ GrpcMetadataKeys . RECEIPT_TYPE ] ) ;
128+
129+ // Extract from gRPC and verify identical receipt_ref
130+ const grpcExtracted = grpcAdapter . extract ( grpcMetadata ) ;
131+ if ( grpcExtracted ) {
132+ console . log ( `gRPC receipt_ref: ${ grpcExtracted . receipts [ 0 ] . receipt_ref . slice ( 0 , 30 ) } ...` ) ;
133+ console . log ( `A2A receipt_ref: ${ lastCarrier . receipt_ref . slice ( 0 , 30 ) } ...` ) ;
134+ console . log (
135+ 'Cross-transport parity:' ,
136+ grpcExtracted . receipts [ 0 ] . receipt_ref === lastCarrier . receipt_ref ? 'PASS' : 'FAIL'
137+ ) ;
138+
139+ // Verify the gRPC-extracted receipt
140+ const grpcResult = await verifyLocal ( grpcExtracted . receipts [ 0 ] . receipt_jws ! , publicKey ) ;
141+ console . log ( 'gRPC-extracted receipt valid:' , grpcResult . valid ) ;
142+ }
143+
112144console . log ( '\n=== Summary ===\n' ) ;
113145console . log ( 'The gateway pattern issues one receipt per state transition.' ) ;
114146console . log ( 'Each receipt is attached to A2A TaskStatus metadata via the carrier contract.' ) ;
147+ console . log (
148+ 'The same receipt produces identical receipt_ref through both A2A and gRPC transports.'
149+ ) ;
115150console . log ( 'Consumers extract and verify the full chain for end-to-end traceability.' ) ;
0 commit comments