@@ -26,7 +26,7 @@ use crate::ckd::{
2626 derive_root_key_from_mpc, g1_to_near_format, generate_ephemeral_keypair, MpcConfig ,
2727} ;
2828use crate :: config:: { AuthApi , KmsConfig } ;
29- use crate :: near_kms_client:: { load_or_generate_near_signer, NearKmsClient } ;
29+ use crate :: near_kms_client:: { load_or_generate_near_signer, near_public_key_to_report_data , NearKmsClient } ;
3030use dcap_qvl:: collateral;
3131use near_api:: NetworkConfig ;
3232use ra_tls:: kdf;
@@ -446,6 +446,10 @@ async fn try_derive_keys_from_mpc(
446446 tracing:: info!( " Domain ID: {}" , mpc_domain_id) ;
447447 tracing:: info!( " Signer Account ID: {}" , signer. account_id) ;
448448
449+ // Get the NEAR account public key for report_data (clone before moving signer)
450+ // The signer's public_key field contains the NEAR account public key
451+ let near_account_public_key = signer. public_key . clone ( ) ;
452+
449453 let kms_client = NearKmsClient :: new (
450454 network_config,
451455 mpc_contract_id. clone ( ) ,
@@ -479,28 +483,20 @@ async fn try_derive_keys_from_mpc(
479483 // Get TDX attestation (quote, collateral, tcb_info) for KMS contract
480484 // The KMS contract's request_kms_root_key() requires attestation verification
481485 let ( quote_hex, collateral_json, tcb_info_json) = if quote_enabled {
482- // Generate a quote with the worker public key as report_data
483- let worker_pubkey_bytes = ephemeral_public_key. to_compressed ( ) ;
484- let mut report_data = vec ! [ 0u8 ; 64 ] ;
485- // Put worker public key in report_data (first 48 bytes for BLS12-381 G1)
486- if worker_pubkey_bytes. len ( ) <= 48 {
487- report_data[ ..worker_pubkey_bytes. len ( ) ] . copy_from_slice ( & worker_pubkey_bytes) ;
488- } else {
489- // Hash if too long
490- use sha2:: { Digest , Sha256 } ;
491- let hash = Sha256 :: digest ( & worker_pubkey_bytes) ;
492- report_data[ ..32 ] . copy_from_slice ( & hash) ;
493- }
486+ // Generate report_data from NEAR account public key using helper function
487+ let report_data = near_public_key_to_report_data ( & near_account_public_key)
488+ . context ( "Failed to convert NEAR public key to report_data format" ) ?;
494489
495- let attest_response = app_attest ( report_data)
490+ let attest_response = app_attest ( report_data. to_vec ( ) )
496491 . await
497492 . context ( "Failed to get TDX quote for MPC request" ) ?;
498493
499494 let attestation = VersionedAttestation :: from_scale ( & attest_response. attestation )
500495 . context ( "Failed to parse attestation" ) ?;
501496
502- // Get quote bytes
497+ // Get quote bytes - need to call into_inner() first to get Attestation
503498 let quote_bytes = attestation
499+ . into_inner ( )
504500 . tdx_quote ( )
505501 . and_then ( |q| Some ( q. quote . clone ( ) ) )
506502 . context ( "Failed to get TDX quote bytes" ) ?;
@@ -512,8 +508,11 @@ async fn try_derive_keys_from_mpc(
512508 . await
513509 . context ( "Failed to get collateral and verify quote" ) ?;
514510
515- let collateral_json = serde_json:: to_string ( & verified_report. collateral )
516- . context ( "Failed to serialize collateral" ) ?;
511+ // Extract collateral from verified_report
512+ // The verified_report contains the quote verification result
513+ // We need to serialize the entire verified_report or extract the needed fields
514+ let collateral_json = serde_json:: to_string ( & verified_report)
515+ . context ( "Failed to serialize verified report as collateral" ) ?;
517516
518517 // Get TCB info from verified report
519518 let td_report = verified_report
0 commit comments