Skip to content

Commit 3ea9aa9

Browse files
authored
refactor: make TransactionAuthenticator return Arc for public key (#2304)
1 parent 9411b6a commit 3ea9aa9

3 files changed

Lines changed: 29 additions & 11 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
## 0.14.0 (TBD)
44

5+
### Features
6+
7+
### Changes
8+
9+
- [BREAKING] refactored `TransactionAuthenticator::get_public_key()` method to return `Arc<PublicKey> `instead of `&PublicKey` ([#2304](https://github.com/0xMiden/miden-base/pull/2304)).
10+
511
## 0.13.0 (2026-01-16)
612

713
### Features

crates/miden-testing/src/mock_chain/chain.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1094,7 +1094,12 @@ impl Serializable for AccountAuthenticator {
10941094
fn write_into<W: ByteWriter>(&self, target: &mut W) {
10951095
self.authenticator
10961096
.as_ref()
1097-
.map(|auth| auth.keys().values().collect::<Vec<_>>())
1097+
.map(|auth| {
1098+
auth.keys()
1099+
.values()
1100+
.map(|(secret_key, public_key)| (secret_key, public_key.as_ref().clone()))
1101+
.collect::<Vec<_>>()
1102+
})
10981103
.write_into(target);
10991104
}
11001105
}

crates/miden-tx/src/auth/tx_authenticator.rs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use alloc::boxed::Box;
22
use alloc::collections::BTreeMap;
33
use alloc::string::ToString;
4+
use alloc::sync::Arc;
45
use alloc::vec::Vec;
56

67
use 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)]
184185
pub 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

189190
impl 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

255259
impl 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)]
278285
mod test {
279286
use miden_protocol::account::auth::AuthSecretKey;

0 commit comments

Comments
 (0)