Skip to content

Commit 2ddc694

Browse files
authored
feat: dynamic signer interactivity (#648)
1 parent f31e426 commit 2ddc694

File tree

17 files changed

+102
-52
lines changed

17 files changed

+102
-52
lines changed

examples/mint_tokens.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use starknet::{
2-
accounts::{Account, Call, ExecutionEncoding, SingleOwnerAccount},
2+
accounts::{Account, ExecutionEncoding, SingleOwnerAccount},
33
core::{
44
chain_id,
5-
types::{BlockId, BlockTag, Felt},
5+
types::{BlockId, BlockTag, Call, Felt},
66
utils::get_selector_from_name,
77
},
88
providers::{

examples/transfer_with_ledger.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use starknet::{
2-
accounts::{Account, Call, ExecutionEncoding, SingleOwnerAccount},
2+
accounts::{Account, ExecutionEncoding, SingleOwnerAccount},
33
core::{
44
chain_id,
5-
types::{BlockId, BlockTag, Felt},
5+
types::{BlockId, BlockTag, Call, Felt},
66
utils::get_selector_from_name,
77
},
88
macros::felt,

starknet-accounts/src/account/declaration.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use starknet_core::{
1717
};
1818
use starknet_crypto::PoseidonHasher;
1919
use starknet_providers::Provider;
20+
use starknet_signers::SignerInteractivityContext;
2021
use std::sync::Arc;
2122

2223
/// Cairo string for "declare"
@@ -209,7 +210,9 @@ where
209210
&self,
210211
nonce: Felt,
211212
) -> Result<FeeEstimate, AccountError<A::SignError>> {
212-
let skip_signature = self.account.is_signer_interactive();
213+
let skip_signature = self
214+
.account
215+
.is_signer_interactive(SignerInteractivityContext::Other);
213216

214217
let prepared = PreparedDeclarationV2 {
215218
account: self.account,
@@ -245,7 +248,10 @@ where
245248
skip_validate: bool,
246249
skip_fee_charge: bool,
247250
) -> Result<SimulatedTransaction, AccountError<A::SignError>> {
248-
let skip_signature = if self.account.is_signer_interactive() {
251+
let skip_signature = if self
252+
.account
253+
.is_signer_interactive(SignerInteractivityContext::Other)
254+
{
249255
// If signer is interactive, we would try to minimize signing requests. However, if the
250256
// caller has decided to not skip validation, it's best we still request a real
251257
// signature, as otherwise the simulation would most likely fail.
@@ -519,7 +525,9 @@ where
519525
&self,
520526
nonce: Felt,
521527
) -> Result<FeeEstimate, AccountError<A::SignError>> {
522-
let skip_signature = self.account.is_signer_interactive();
528+
let skip_signature = self
529+
.account
530+
.is_signer_interactive(SignerInteractivityContext::Other);
523531

524532
let prepared = PreparedDeclarationV3 {
525533
account: self.account,
@@ -556,7 +564,10 @@ where
556564
skip_validate: bool,
557565
skip_fee_charge: bool,
558566
) -> Result<SimulatedTransaction, AccountError<A::SignError>> {
559-
let skip_signature = if self.account.is_signer_interactive() {
567+
let skip_signature = if self
568+
.account
569+
.is_signer_interactive(SignerInteractivityContext::Other)
570+
{
560571
// If signer is interactive, we would try to minimize signing requests. However, if the
561572
// caller has decided to not skip validation, it's best we still request a real
562573
// signature, as otherwise the simulation would most likely fail.
@@ -753,7 +764,9 @@ where
753764
&self,
754765
nonce: Felt,
755766
) -> Result<FeeEstimate, AccountError<A::SignError>> {
756-
let skip_signature = self.account.is_signer_interactive();
767+
let skip_signature = self
768+
.account
769+
.is_signer_interactive(SignerInteractivityContext::Other);
757770

758771
let prepared = PreparedLegacyDeclaration {
759772
account: self.account,
@@ -788,7 +801,10 @@ where
788801
skip_validate: bool,
789802
skip_fee_charge: bool,
790803
) -> Result<SimulatedTransaction, AccountError<A::SignError>> {
791-
let skip_signature = if self.account.is_signer_interactive() {
804+
let skip_signature = if self
805+
.account
806+
.is_signer_interactive(SignerInteractivityContext::Other)
807+
{
792808
// If signer is interactive, we would try to minimize signing requests. However, if the
793809
// caller has decided to not skip validation, it's best we still request a real
794810
// signature, as otherwise the simulation would most likely fail.

starknet-accounts/src/account/execution.rs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@ use super::{
22
super::NotPreparedError, Account, AccountError, ConnectedAccount, ExecutionV1, ExecutionV3,
33
PreparedExecutionV1, PreparedExecutionV3, RawExecutionV1, RawExecutionV3,
44
};
5-
use crate::{Call, ExecutionEncoder};
5+
use crate::ExecutionEncoder;
66

77
use starknet_core::{
88
crypto::compute_hash_on_elements,
99
types::{
1010
BroadcastedInvokeTransaction, BroadcastedInvokeTransactionV1,
11-
BroadcastedInvokeTransactionV3, BroadcastedTransaction, DataAvailabilityMode, FeeEstimate,
12-
Felt, InvokeTransactionResult, ResourceBounds, ResourceBoundsMapping, SimulatedTransaction,
13-
SimulationFlag, SimulationFlagForEstimateFee,
11+
BroadcastedInvokeTransactionV3, BroadcastedTransaction, Call, DataAvailabilityMode,
12+
FeeEstimate, Felt, InvokeTransactionResult, ResourceBounds, ResourceBoundsMapping,
13+
SimulatedTransaction, SimulationFlag, SimulationFlagForEstimateFee,
1414
},
1515
};
1616
use starknet_crypto::PoseidonHasher;
1717
use starknet_providers::Provider;
18+
use starknet_signers::SignerInteractivityContext;
1819

1920
/// Cairo string for "invoke"
2021
const PREFIX_INVOKE: Felt = Felt::from_raw([
@@ -271,7 +272,9 @@ where
271272
&self,
272273
nonce: Felt,
273274
) -> Result<FeeEstimate, AccountError<A::SignError>> {
274-
let skip_signature = self.account.is_signer_interactive();
275+
let skip_signature = self
276+
.account
277+
.is_signer_interactive(SignerInteractivityContext::Execution { calls: &self.calls });
275278

276279
let prepared = PreparedExecutionV1 {
277280
account: self.account,
@@ -309,7 +312,10 @@ where
309312
skip_validate: bool,
310313
skip_fee_charge: bool,
311314
) -> Result<SimulatedTransaction, AccountError<A::SignError>> {
312-
let skip_signature = if self.account.is_signer_interactive() {
315+
let skip_signature = if self
316+
.account
317+
.is_signer_interactive(SignerInteractivityContext::Execution { calls: &self.calls })
318+
{
313319
// If signer is interactive, we would try to minimize signing requests. However, if the
314320
// caller has decided to not skip validation, it's best we still request a real
315321
// signature, as otherwise the simulation would most likely fail.
@@ -498,7 +504,9 @@ where
498504
&self,
499505
nonce: Felt,
500506
) -> Result<FeeEstimate, AccountError<A::SignError>> {
501-
let skip_signature = self.account.is_signer_interactive();
507+
let skip_signature = self
508+
.account
509+
.is_signer_interactive(SignerInteractivityContext::Execution { calls: &self.calls });
502510

503511
let prepared = PreparedExecutionV3 {
504512
account: self.account,
@@ -537,7 +545,10 @@ where
537545
skip_validate: bool,
538546
skip_fee_charge: bool,
539547
) -> Result<SimulatedTransaction, AccountError<A::SignError>> {
540-
let skip_signature = if self.account.is_signer_interactive() {
548+
let skip_signature = if self
549+
.account
550+
.is_signer_interactive(SignerInteractivityContext::Execution { calls: &self.calls })
551+
{
541552
// If signer is interactive, we would try to minimize signing requests. However, if the
542553
// caller has decided to not skip validation, it's best we still request a real
543554
// signature, as otherwise the simulation would most likely fail.

starknet-accounts/src/account/mod.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
use crate::Call;
2-
31
use async_trait::async_trait;
42
use auto_impl::auto_impl;
53
use starknet_core::types::{
64
contract::{legacy::LegacyContractClass, CompressProgramError, ComputeClassHashError},
7-
BlockId, BlockTag, Felt, FlattenedSierraClass,
5+
BlockId, BlockTag, Call, Felt, FlattenedSierraClass,
86
};
97
use starknet_providers::{Provider, ProviderError};
8+
use starknet_signers::SignerInteractivityContext;
109
use std::{error::Error, sync::Arc};
1110

1211
mod declaration;
@@ -89,7 +88,7 @@ pub trait Account: ExecutionEncoder + Sized {
8988
///
9089
/// This affects how an account makes decision on whether to request a real signature for
9190
/// estimation/simulation purposes.
92-
fn is_signer_interactive(&self) -> bool;
91+
fn is_signer_interactive(&self, context: SignerInteractivityContext<'_>) -> bool;
9392

9493
/// Generates an instance of [`ExecutionV1`] for sending `INVOKE` v1 transactions. Pays
9594
/// transaction fees in `ETH`.
@@ -465,8 +464,8 @@ where
465464
.await
466465
}
467466

468-
fn is_signer_interactive(&self) -> bool {
469-
(*self).is_signer_interactive()
467+
fn is_signer_interactive(&self, context: SignerInteractivityContext<'_>) -> bool {
468+
(*self).is_signer_interactive(context)
470469
}
471470
}
472471

@@ -532,8 +531,8 @@ where
532531
.await
533532
}
534533

535-
fn is_signer_interactive(&self) -> bool {
536-
self.as_ref().is_signer_interactive()
534+
fn is_signer_interactive(&self, context: SignerInteractivityContext<'_>) -> bool {
535+
self.as_ref().is_signer_interactive(context)
537536
}
538537
}
539538

@@ -599,8 +598,8 @@ where
599598
.await
600599
}
601600

602-
fn is_signer_interactive(&self) -> bool {
603-
self.as_ref().is_signer_interactive()
601+
fn is_signer_interactive(&self, context: SignerInteractivityContext<'_>) -> bool {
602+
self.as_ref().is_signer_interactive(context)
604603
}
605604
}
606605

starknet-accounts/src/factory/argent.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::{
66
use async_trait::async_trait;
77
use starknet_core::types::{BlockId, BlockTag, Felt};
88
use starknet_providers::Provider;
9-
use starknet_signers::Signer;
9+
use starknet_signers::{Signer, SignerInteractivityContext};
1010

1111
/// [`AccountFactory`] implementation for deploying `Argent X` account contracts.
1212
#[derive(Debug)]
@@ -78,7 +78,8 @@ where
7878
}
7979

8080
fn is_signer_interactive(&self) -> bool {
81-
self.signer.is_interactive()
81+
self.signer
82+
.is_interactive(SignerInteractivityContext::Other)
8283
}
8384

8485
fn block_id(&self) -> BlockId {

starknet-accounts/src/factory/open_zeppelin.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::{
66
use async_trait::async_trait;
77
use starknet_core::types::{BlockId, BlockTag, Felt};
88
use starknet_providers::Provider;
9-
use starknet_signers::Signer;
9+
use starknet_signers::{Signer, SignerInteractivityContext};
1010

1111
/// [`AccountFactory`] implementation for deploying `OpenZeppelin` account contracts.
1212
#[derive(Debug)]
@@ -75,7 +75,8 @@ where
7575
}
7676

7777
fn is_signer_interactive(&self) -> bool {
78-
self.signer.is_interactive()
78+
self.signer
79+
.is_interactive(SignerInteractivityContext::Other)
7980
}
8081

8182
fn block_id(&self) -> BlockId {

starknet-accounts/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ pub use account::{
1010
RawDeclarationV3, RawExecutionV1, RawExecutionV3, RawLegacyDeclaration,
1111
};
1212

13-
mod call;
14-
pub use call::Call;
15-
1613
mod factory;
1714
pub use factory::{
1815
argent::ArgentAccountFactory, open_zeppelin::OpenZeppelinAccountFactory, AccountDeploymentV1,

starknet-accounts/src/single_owner.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use crate::{
2-
Account, Call, ConnectedAccount, ExecutionEncoder, RawDeclarationV2, RawDeclarationV3,
2+
Account, ConnectedAccount, ExecutionEncoder, RawDeclarationV2, RawDeclarationV3,
33
RawExecutionV1, RawExecutionV3, RawLegacyDeclaration,
44
};
55

66
use async_trait::async_trait;
7-
use starknet_core::types::{contract::ComputeClassHashError, BlockId, BlockTag, Felt};
7+
use starknet_core::types::{contract::ComputeClassHashError, BlockId, BlockTag, Call, Felt};
88
use starknet_providers::Provider;
9-
use starknet_signers::Signer;
9+
use starknet_signers::{Signer, SignerInteractivityContext};
1010

1111
/// A generic [`Account`] implementation for controlling account contracts that only have one signer
1212
/// using ECDSA the STARK curve.
@@ -177,8 +177,8 @@ where
177177
Ok(vec![signature.r, signature.s])
178178
}
179179

180-
fn is_signer_interactive(&self) -> bool {
181-
self.signer.is_interactive()
180+
fn is_signer_interactive(&self, context: SignerInteractivityContext<'_>) -> bool {
181+
self.signer.is_interactive(context)
182182
}
183183
}
184184

starknet-accounts/tests/single_owner_account.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use starknet_accounts::{
2-
Account, AccountError, Call, ConnectedAccount, ExecutionEncoding, SingleOwnerAccount,
2+
Account, AccountError, ConnectedAccount, ExecutionEncoding, SingleOwnerAccount,
33
};
44
use starknet_core::{
55
types::{
66
contract::{
77
legacy::{LegacyContractClass, RawLegacyAbiEntry, RawLegacyFunction},
88
SierraClass,
99
},
10-
BlockId, BlockTag, Felt, StarknetError,
10+
BlockId, BlockTag, Call, Felt, StarknetError,
1111
},
1212
utils::get_selector_from_name,
1313
};

0 commit comments

Comments
 (0)