11use alloc:: boxed:: Box ;
22use alloc:: collections:: BTreeMap ;
33use alloc:: string:: ToString ;
4+ use alloc:: sync:: Arc ;
45use alloc:: vec:: Vec ;
56
67use miden_processor:: FutureMaybeSend ;
@@ -145,7 +146,7 @@ pub trait TransactionAuthenticator {
145146 fn get_public_key (
146147 & self ,
147148 pub_key_commitment : PublicKeyCommitment ,
148- ) -> impl FutureMaybeSend < Option < & PublicKey > > ;
149+ ) -> impl FutureMaybeSend < Option < Arc < PublicKey > > > ;
149150}
150151
151152/// A placeholder type for the generic trait bound of `TransactionAuthenticator<'_,'_,_,T>`
@@ -171,7 +172,7 @@ impl TransactionAuthenticator for UnreachableAuth {
171172 fn get_public_key (
172173 & self ,
173174 _pub_key_commitment : PublicKeyCommitment ,
174- ) -> impl FutureMaybeSend < Option < & PublicKey > > {
175+ ) -> impl FutureMaybeSend < Option < Arc < PublicKey > > > {
175176 async { unreachable ! ( "Type `UnreachableAuth` must not be instantiated" ) }
176177 }
177178}
@@ -183,15 +184,15 @@ impl TransactionAuthenticator for UnreachableAuth {
183184#[ derive( Clone , Debug ) ]
184185pub struct BasicAuthenticator {
185186 /// pub_key |-> (secret_key, public_key) mapping
186- keys : BTreeMap < PublicKeyCommitment , ( AuthSecretKey , PublicKey ) > ,
187+ keys : BTreeMap < PublicKeyCommitment , ( AuthSecretKey , Arc < PublicKey > ) > ,
187188}
188189
189190impl BasicAuthenticator {
190191 pub fn new ( keys : & [ AuthSecretKey ] ) -> Self {
191192 let mut key_map = BTreeMap :: new ( ) ;
192193 for secret_key in keys {
193194 let pub_key = secret_key. public_key ( ) ;
194- key_map. insert ( pub_key. to_commitment ( ) , ( secret_key. clone ( ) , pub_key) ) ;
195+ key_map. insert ( pub_key. to_commitment ( ) , ( secret_key. clone ( ) , pub_key. into ( ) ) ) ;
195196 }
196197
197198 BasicAuthenticator { keys : key_map }
@@ -200,7 +201,10 @@ impl BasicAuthenticator {
200201 pub fn from_key_pairs ( keys : & [ ( AuthSecretKey , PublicKey ) ] ) -> Self {
201202 let mut key_map = BTreeMap :: new ( ) ;
202203 for ( secret_key, public_key) in keys {
203- key_map. insert ( public_key. to_commitment ( ) , ( secret_key. clone ( ) , public_key. clone ( ) ) ) ;
204+ key_map. insert (
205+ public_key. to_commitment ( ) ,
206+ ( secret_key. clone ( ) , public_key. clone ( ) . into ( ) ) ,
207+ ) ;
204208 }
205209
206210 BasicAuthenticator { keys : key_map }
@@ -210,7 +214,7 @@ impl BasicAuthenticator {
210214 ///
211215 /// Map keys represent the public key commitments, and values represent the (secret_key,
212216 /// public_key) pair that the authenticator would use to sign messages.
213- pub fn keys ( & self ) -> & BTreeMap < PublicKeyCommitment , ( AuthSecretKey , PublicKey ) > {
217+ pub fn keys ( & self ) -> & BTreeMap < PublicKeyCommitment , ( AuthSecretKey , Arc < PublicKey > ) > {
214218 & self . keys
215219 }
216220}
@@ -244,12 +248,12 @@ impl TransactionAuthenticator for BasicAuthenticator {
244248 fn get_public_key (
245249 & self ,
246250 pub_key_commitment : PublicKeyCommitment ,
247- ) -> impl FutureMaybeSend < Option < & PublicKey > > {
248- async move { self . keys . get ( & pub_key_commitment) . map ( |( _, pub_key) | pub_key) }
251+ ) -> impl FutureMaybeSend < Option < Arc < PublicKey > > > {
252+ async move { self . keys . get ( & pub_key_commitment) . map ( |( _, pub_key) | pub_key. clone ( ) ) }
249253 }
250254}
251255
252- // HELPER FUNCTIONS
256+ // EMPTY AUTHENTICATOR
253257// ================================================================================================
254258
255259impl TransactionAuthenticator for ( ) {
@@ -269,11 +273,14 @@ impl TransactionAuthenticator for () {
269273 fn get_public_key (
270274 & self ,
271275 _pub_key_commitment : PublicKeyCommitment ,
272- ) -> impl FutureMaybeSend < Option < & PublicKey > > {
276+ ) -> impl FutureMaybeSend < Option < Arc < PublicKey > > > {
273277 async { None }
274278 }
275279}
276280
281+ // TESTS
282+ // ================================================================================================
283+
277284#[ cfg( test) ]
278285mod test {
279286 use miden_protocol:: account:: auth:: AuthSecretKey ;
0 commit comments