pub struct Credentials {
pub user: Address,
pub signer: Address,
/* private fields */
}Expand description
SDK credentials — holds wallet addresses and EIP-712 signing key. No Debug derive — private key must NEVER be logged.
Fields§
§user: Address§signer: AddressImplementations§
Source§impl Credentials
impl Credentials
Sourcepub fn new(
user: &str,
signer: &str,
private_key_hex: &str,
chain_id: u64,
) -> Result<Self, AsterDexError>
pub fn new( user: &str, signer: &str, private_key_hex: &str, chain_id: u64, ) -> Result<Self, AsterDexError>
Create from explicit string values
Sourcepub fn from_env() -> Result<Self, AsterDexError>
pub fn from_env() -> Result<Self, AsterDexError>
Create from environment variables
Sourcepub fn new_nonce(&self) -> u64
pub fn new_nonce(&self) -> u64
Generate a strictly monotonically increasing nonce.
Format follows BR-001 / FORMULA-001: unix_seconds * 1_000_000 + sub_second_index.
Implementation notes:
- Lock-free via
AtomicU64::compare_exchange→ never blocks other async tasks. - If the wall clock jumps backwards (NTP rollback, VM pause/restore), we still
return
prev + 1to preserve strict monotonicity. - If more than 1_000_000 nonces are requested within one wall-clock second, nonces simply continue counting into the next “virtual second” — still strictly monotonic, still uniquely identifying the request.
- Never panics (vs. previous
.expect("time before epoch")).
Sourcepub fn sign_query(
&self,
params: &[(&str, &str)],
) -> Result<String, AsterDexError>
pub fn sign_query( &self, params: &[(&str, &str)], ) -> Result<String, AsterDexError>
URL-encode params, add auth fields, sign with EIP-712.
Returns the complete signed query string with &signature=<hex> appended.
Optimisations vs. the previous implementation:
- Address strings pre-computed at construction — no per-call format allocation.
- Param string built in a single
Stringwithpush_str— no intermediateVec<String>. - EIP-712 domain cached at construction — no per-call struct rebuild.
- Nonce / user / signer values are all ASCII-unreserved — URL-encoding skipped.
Auto Trait Implementations§
impl !Freeze for Credentials
impl RefUnwindSafe for Credentials
impl Send for Credentials
impl Sync for Credentials
impl Unpin for Credentials
impl UnsafeUnpin for Credentials
impl UnwindSafe for Credentials
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more