@@ -99,7 +99,7 @@ pub(crate) fn validate_txn_inputs_hash(
9999/// Validate the stake public key in the certificate with witness set in transaction.
100100#[ allow( clippy:: too_many_lines) ]
101101pub ( crate ) fn validate_stake_public_key (
102- cip509 : & Cip509 , txn : & MultiEraTx , txn_idx : usize , validation_report : & mut Vec < String > ,
102+ cip509 : & Cip509 , txn : & MultiEraTx , validation_report : & mut Vec < String > ,
103103) -> Option < bool > {
104104 let function_name = "Validate Stake Public Key" ;
105105 let mut pk_addrs = Vec :: new ( ) ;
@@ -158,6 +158,7 @@ pub(crate) fn validate_stake_public_key(
158158
159159 // Extract the CIP19 hash and push into
160160 // array
161+ println ! ( "{:?}" , & addr) ;
161162 if let Some ( h) =
162163 extract_cip19_hash ( & addr, Some ( "stake" ) )
163164 {
@@ -249,6 +250,7 @@ pub(crate) fn validate_stake_public_key(
249250 }
250251
251252 // Create TxWitness
253+ // Note that TxWitness designs to work with multiple transactions
252254 let witnesses = match TxWitness :: new ( & [ txn. clone ( ) ] ) {
253255 Ok ( witnesses) => witnesses,
254256 Err ( e) => {
@@ -257,17 +259,11 @@ pub(crate) fn validate_stake_public_key(
257259 } ,
258260 } ;
259261
260- let index = match u16:: try_from ( txn_idx) {
261- Ok ( value) => value,
262- Err ( e) => {
263- validation_report. push ( format ! (
264- "{function_name}, Failed to convert transaction index to usize: {e}"
265- ) ) ;
266- return None ;
267- } ,
268- } ;
269262 Some (
270- compare_key_hash ( & pk_addrs, & witnesses, index)
263+ // Set transaction index to 0 because the list of transaction is manually constructed
264+ // for TxWitness -> &[txn.clone()], so we can assume that the witness contains only the witness
265+ // within this transaction.
266+ compare_key_hash ( & pk_addrs, & witnesses, 0 )
271267 . map_err ( |e| {
272268 validation_report. push ( format ! (
273269 "{function_name}, Failed to compare public keys with witnesses: {e}"
@@ -276,6 +272,7 @@ pub(crate) fn validate_stake_public_key(
276272 . is_ok ( ) ,
277273 )
278274}
275+ // pk addrs [[224, 117, 190, 16, 236, 92, 87, 92, 175, 251, 104, 176, 140, 49, 71, 6, 102, 212, 254, 26, 238, 160, 124, 22, 214, 71, 57, 3]]
279276
280277// ------------------------ Validate Aux ------------------------
281278
@@ -562,8 +559,7 @@ mod tests {
562559
563560 let mut decoder = Decoder :: new ( aux_data. as_slice ( ) ) ;
564561 let cip509 = Cip509 :: decode ( & mut decoder, & mut ( ) ) . expect ( "Failed to decode Cip509" ) ;
565- validate_stake_public_key ( & cip509, tx, 0 , & mut validation_report) ;
566- assert ! ( validate_stake_public_key( & cip509, tx, 0 , & mut validation_report) . unwrap( ) ) ;
562+ assert ! ( validate_stake_public_key( & cip509, tx, & mut validation_report) . unwrap( ) ) ;
567563 }
568564
569565 #[ test]
@@ -587,15 +583,35 @@ mod tests {
587583 if let Some ( role_set) = & cip509. x509_chunks . 0 . role_set {
588584 for role in role_set {
589585 if role. role_number == 0 {
590- println ! (
591- "{:?}" ,
592- validate_payment_key( tx, 0 , role, & mut validation_report, )
593- ) ;
586+ assert ! ( validate_payment_key( tx, 0 , role, & mut validation_report, ) . unwrap( ) ) ;
594587 }
595588 }
596589 }
597590 }
598591
592+ #[ test]
593+ fn test_role_0_signing_key ( ) {
594+ let mut validation_report = Vec :: new ( ) ;
595+ let conway_block_data = conway_1 ( ) ;
596+ let multi_era_block = pallas:: ledger:: traverse:: MultiEraBlock :: decode ( & conway_block_data)
597+ . expect ( "Failed to decode MultiEraBlock" ) ;
598+
599+ let transactions = multi_era_block. txs ( ) ;
600+ // Second transaction of this test data contains the CIP509 auxiliary data
601+ let tx = transactions
602+ . get ( 1 )
603+ . expect ( "Failed to get transaction index" ) ;
604+
605+ let aux_data = cip_509_aux_data ( tx) ;
606+
607+ let mut decoder = Decoder :: new ( aux_data. as_slice ( ) ) ;
608+ let cip509 = Cip509 :: decode ( & mut decoder, & mut ( ) ) . expect ( "Failed to decode Cip509" ) ;
609+ assert ! ( validate_role_singing_key(
610+ & cip509. x509_chunks. 0 . role_set. as_ref( ) . unwrap( ) [ 0 ] ,
611+ & mut validation_report
612+ ) ) ;
613+ }
614+
599615 #[ test]
600616 fn test_validate_payment_key_success_positive_ref ( ) {
601617 let mut validation_report = Vec :: new ( ) ;
@@ -640,6 +656,6 @@ mod tests {
640656
641657 let mut decoder = Decoder :: new ( aux_data. as_slice ( ) ) ;
642658 let cip509 = Cip509 :: decode ( & mut decoder, & mut ( ) ) . expect ( "Failed to decode Cip509" ) ;
643- assert ! ( !validate_stake_public_key( & cip509, tx, 0 , & mut validation_report) . unwrap( ) ) ;
659+ assert ! ( !validate_stake_public_key( & cip509, tx, & mut validation_report) . unwrap( ) ) ;
644660 }
645661}
0 commit comments