Skip to main content

Module nonce

Module nonce 

Source
Expand description

Per-(wallet, subaccount) nonce manager for Derive self-custodial requests.

Nonce format (matching derive_action_signing/utils.py::get_action_nonce): int(str(utc_ms) || str(suffix)). The suffix is a non-negative integer whose decimal representation is concatenated to the millisecond timestamp.

Manager guarantees:

  1. Monotonically increasing per (wallet, subaccount). The venue rejects a nonce equal to or below the last accepted nonce for the signer, so the manager always issues max(now_ms_with_suffix0, last_issued + 1).
  2. Lock-free per key under contention. A DashMap shards the per-key state and a compare_exchange loop on a single AtomicU64 serialises concurrent allocators.

Cross-instance ordering (multiple processes signing for the same key) is the caller’s responsibility; the venue’s nextNonce-style endpoint should seed the manager via NonceManager::refresh at startup.

Structs§

NonceManager
Thread-safe sequential nonce allocator keyed by (wallet, subaccount_id).

Enums§

NonceError
Errors raised by NonceManager.