@@ -36,28 +36,15 @@ fn stamp_to_buf_for_nonce(
3636 pk : & PK ,
3737 nonce : u32 ,
3838 id : usize ,
39- ) -> Result < Vec < u8 > , ( ) > {
40- let Ok ( memo) = stamp_to_buf_for_nonce_memo ( address, count, pk, id) else {
41- return Err ( ( ) ) ;
42- } ;
39+ ) -> Vec < u8 > {
40+ let memo = stamp_to_buf_for_nonce_memo ( address, count, pk, id) ;
4341 let nonce_buf = nonce. to_be_bytes ( ) ;
44- Ok ( [ memo, nonce_buf. to_vec ( ) ] . concat ( ) )
42+ [ memo, nonce_buf. to_vec ( ) ] . concat ( )
4543}
46- fn stamp_to_buf_for_nonce_memo (
47- address : & Address ,
48- count : u32 ,
49- pk : & PK ,
50- id : usize ,
51- ) -> Result < Vec < u8 > , ( ) > {
52- let Ok ( address_buf) = address. key ( ) . public_key_to_der ( ) else {
53- return Err ( ( ) ) ;
54- } ;
55- let count_buf = count. to_be_bytes ( ) ;
56- let Ok ( pk_buf) = pk. key ( ) . public_key_to_der ( ) else {
57- return Err ( ( ) ) ;
58- } ;
59- let id_buf = id. to_be_bytes ( ) ;
60- Ok ( [ address_buf, count_buf. to_vec ( ) , pk_buf, id_buf. to_vec ( ) ] . concat ( ) )
44+ fn stamp_to_buf_for_nonce_memo ( address : & Address , count : u32 , pk : & PK , id : usize ) -> Vec < u8 > {
45+ format ! ( "{:?} {:?} {:?} {:?}" , address. der, count, pk. der, id)
46+ . as_bytes ( )
47+ . to_vec ( )
6148}
6249
6350pub fn create_sign_to_stamp (
@@ -88,11 +75,10 @@ pub fn verify_nonce(
8875 nonce : u32 ,
8976 id : usize ,
9077) -> bool {
91- stamp_to_buf_for_nonce ( address, count, pk, nonce, id)
92- . map ( |buf| {
93- hex:: encode ( sha2:: Sha256 :: digest ( buf) ) . starts_with ( & nonce_start_with_str ( difficulty) )
94- } )
95- . is_ok ( )
78+ hex:: encode ( sha2:: Sha256 :: digest ( stamp_to_buf_for_nonce (
79+ address, count, pk, nonce, id,
80+ ) ) )
81+ . starts_with ( & nonce_start_with_str ( difficulty) )
9682}
9783pub fn verify_nonce_for_calc ( memo : & [ u8 ] , nonce : u32 , starts_with : & str ) -> bool {
9884 hex:: encode ( sha2:: Sha256 :: digest ( [ memo, & nonce. to_be_bytes ( ) ] . concat ( ) ) )
@@ -101,7 +87,7 @@ pub fn verify_nonce_for_calc(memo: &[u8], nonce: u32, starts_with: &str) -> bool
10187
10288pub fn calc_nonce ( difficulty : usize , address : & Address , count : u32 , pk : & PK , id : usize ) -> u32 {
10389 let start_with = & nonce_start_with_str ( difficulty) ;
104- let memo = stamp_to_buf_for_nonce_memo ( address, count, pk, id) . unwrap ( ) ;
90+ let memo = stamp_to_buf_for_nonce_memo ( address, count, pk, id) ;
10591 let mut nonce = 0 ;
10692 while !verify_nonce_for_calc ( & memo, nonce, start_with) {
10793 nonce += 1
0 commit comments