188 Commits

Author SHA1 Message Date
Matt Hess dd36e9e03c version bump to r011 or v0.1.1 2026-02-26 04:20:16 +00:00
Matt Hess fc6213cd7d Add subaddress FFI exports: create, list, and label 2026-02-26 04:15:56 +00:00
Matt Hess 65d596a6ea Add sync cancellation via AtomicBool flag for FFI consumers
Allows Android/FFI callers to interrupt an in-progress wallet sync
  cleanly between batches. Adds salvium_wallet_stop_sync FFI export,
  WalletError::Cancelled, SyncEvent::Cancelled, and WalletHandle
  wrapper that pairs each wallet with its cancellation flag.
2026-02-26 02:23:12 +00:00
Matt Hess 0cec53f868 Populate transaction history during wallet sync, add transfer display to sync-bench
The sync engine already parsed every block and found owned/spent outputs, but never created TransactionRow records — so get_transfers() always returned empty. Now put_tx() is called at all 6 integration points (miner,
  protocol, regular TXs in both process_bin_block and process_block_data).
2026-02-25 23:38:48 +00:00
Matt Hess c076209f38 Fix critical wallet balance bug, add background mining to salvium-miner
Wallet: Fix per-output derivation in protocol TX key image override.
  Protocol TXs use additional_pubkeys (tag 0x04) for output derivation,
  but the two-step key image override always used the shared tx_pub_key.
  This caused the P_change recovery to fail silently, leaving ~9268 SAL1
  of spent stake-return outputs marked as unspent. Track the actual
  derivation pubkey through FoundOutput so the override uses the correct
  key. Also improve stake return matching to use origin TX linkage from
  salvium_txs instead of blind asset-type matching.

  Miner: Add background mining with system idle monitoring, AC power
  detection, and CPU throttling. Matches C++ background_worker_thread()
  behavior with zero overhead when unused.
2026-02-25 22:57:43 +00:00
Matt Hess 40a600f14e Add C++ input validation to salvium-multisig, bring to 100% compatibility 2026-02-25 20:04:28 +00:00
Matt Hess e3af07b1eb Add fmt + clippy CI checks to pre-commit hook
- Integrate cargo fmt --check and clippy -Dwarnings into .githooks/pre-commit
  - Matches CI's RUSTFLAGS="-Dwarnings" to catch issues before push
  - Runs before existing secret detection checks
2026-02-25 19:02:06 +00:00
Matt Hess d4723bc7e0 ● Fix CI formatting, add salvium-cli to CI, pre-commit hook
- cargo fmt fixes (transport.rs, wire_format.rs, miner main.rs)
  - Add salvium-cli compile check + salvium-wallet full test to CI
  - Pre-commit hook: fmt --check + clippy -Dwarnings matching CI
  - Update TODO.md: multisig ~98%, CI gaps all resolved
2026-02-25 18:59:37 +00:00
Matt Hess d8bc05b018 Add signed messages, binary wire format, and TCP transport to salvium-multisig
- Schnorr signatures (CryptoNote-style) for authenticating KEX messages
  - SignedKexMessage wrapper with ephemeral keypair matching C++ multisig_kex_msg
  - Binary wire format: magic + base58(Epee) for KEX, raw Epee for TX sets
  - TCP transport coordinator with star topology and length-delimited framing
  - 32 new tests across all four modules
2026-02-25 18:50:52 +00:00
Matt Hess a114998883 Update miner to use more xmrig style performance enhancements 2026-02-25 17:49:24 +00:00
Matt Hess 00d49fb6ea Finish multisig end-to-end gaps, add stratum pool mining, rewrite miner to pure Rust API
Multisig (7 gaps → 173 tests passing):
  - Remove dead partial_sig.rs module
  - Fix TCLSAG Y-nonce binding (Y aggregates in binding factor)
  - Split nonce exchange from signing (add_multisig_nonces + sign_multisig_tx)
  - Fix KEX state preservation (round_keys persisted, multisig_privkeys populated)
  - Add protocol amount parameter (commitment_diff for Schnorr proof)
  - Add signature injection (FinalizedTx::to_broadcast_blob)
  - Wire CARROT TX builder to use aggregate keys

  Miner:
  - Add CryptoNote stratum pool mining (salvium-miner, salvium-miner-v2)
  - Replace all C FFI with randomx-rs Rust API + Send/Sync newtypes
  - Fix light mode memory (256MB shared via Arc, not 256MB per thread)
  - Fix --benchmark (standalone, no daemon needed, exactly 20s)
2026-02-25 16:30:36 +00:00
Matt Hess 9550644b13 Add per-HF-era mainnet validation tests, extract shared test helpers
- New mainnet_validation.rs: 9 tests that sample blocks/TXs from every
    hard fork era (HF1–HF10) against public mainnet daemons, covering
    block parsing, header validation, tree hash, TX parsing, serialize
    roundtrip, CLSAG/TCLSAG signature verification, tamper detection,
    and BP+ structure checks.
  - Extract shared verification helpers (fetch_and_parse_tx, fetch_mix_ring,
    prepare_verification_data, etc.) into tests/common/mod.rs to avoid
    duplication between testnet and mainnet test files.
  - Refactor rct_verify_testnet.rs to use mod common.
  - All tests are #[ignore] — run with:
    cargo test -p salvium-tx --test mainnet_validation -- --ignored --nocapture
2026-02-25 12:29:34 +00:00
Matt Hess 61c58b5f18 Fixed release repo destination and allowed error bubble up 2026-02-25 12:27:21 +00:00
Matt Hess 9f00bb2c00 Update github runner for macos 13 -> 14 2026-02-25 11:45:16 +00:00
Matt Hess e98d2ea829 Fix multisig integration tests: add verification tests, update imports 2026-02-25 11:09:19 +00:00
Matt Hess fadf904328 Real CLSAG ring traversal for multisig, iOS cross-compilation fix
- Replace simplified challenge computation in partial_sign() with proper
    CLSAG ring traversal via new ClsagContext (mirrors C++ CLSAG_context_t)
  - Add MultisigTxBuilder for constructing PendingMultisigTx with signing
    contexts (pseudo-outputs, BP+ proof, signing message, fake responses)
  - Enhance PendingMultisigTx with per-input signing contexts and ring data
    so other signers can reconstruct ClsagContext for partial signing
  - Update wallet sign_multisig_tx() to use proper partial_sign() with ring
    traversal instead of dummy sc_mul_sub
  - Expose inv_eight() from salvium-crypto for commitment image computation
  - Fix iOS build: set CROSS_TOP/CROSS_SDK for openssl-src and per-target
    CC/CFLAGS/AR/RANLIB for cc crate (SQLCipher) cross-compilation
  - Fix cargo fmt across workspace
2026-02-25 11:01:26 +00:00
Matt Hess 04f3fc4da7 fixing openssl build 2026-02-25 05:10:40 +00:00
Matt Hess ae4a5de809 fixing openssl build 2026-02-25 05:08:28 +00:00
Matt Hess ed45c801f6 fixing openssl build 2026-02-25 05:00:06 +00:00
Matt Hess a0b6681a12 Add full CLI parity with C++ simplewallet (~30 commands) 2026-02-25 04:00:04 +00:00
Matt Hess 28fbd223c7 Fix iOS release build: replace bash associative arrays with indexed arrays
macOS GitHub Actions runners ship bash 3.2, which does not support
  declare -A (requires bash 4.0+). Rewrote build-ios.sh and
  build-android.sh to use parallel indexed arrays instead.
2026-02-25 03:59:29 +00:00
Matt Hess 43840ac0d2 Fix release builds: quote bash assoc-array keys, add NDK toolchain to PATH 2026-02-25 03:10:08 +00:00
Matt Hess 0d082f0893 Fix CI: rustfmt and clippy needless_range_loop in test 2026-02-25 02:30:48 +00:00
Matt Hess 1ab1bbb005 Fix pre-CARROT PROTOCOL return key images, implement difficulty_to_target()
Add salvium_txs table to track change output Kos from CONVERT/STAKE/AUDIT
  TXs. During sync, populate this map and use it to perform two-step key
  derivation for pre-CARROT PROTOCOL return outputs (C++ m_salvium_txs
  equivalent). This fixes scanning of blocks between HF6-HF10 where
  returned staked/audited/converted funds were invisible or had wrong key
  images.

  Replace difficulty_to_target() stub with bit-by-bit long division of
  (2^256-1)/difficulty. Add 5 unit tests including round-trip verification
  against check_hash().
2026-02-25 02:18:52 +00:00
Matt Hess e446324547 Merge release workflows into single build-release.yml
Consolidate the overlapping release.yml and build-release.yml into one
  workflow. Adds pre-release test gate (tests + clippy), miner binary
  builds, SHA-256 checksums, and creates releases as drafts.
2026-02-25 00:17:29 +00:00
Matt Hess 2a9063a390 Fix CI: resolve remaining clippy warnings in test targets 2026-02-25 00:09:10 +00:00
Matt Hess 72475633b6 Fix CI: resolve all clippy, rustdoc, and formatting warnings
This covers the 15 clippy fixes (redundant closures, unnecessary casts, identity map_err), 16 rustdoc fixes (unresolved bracket links, bare URLs), and formatting across 11 files in salvium-crypto, salvium-wallet,
  salvium-tx, salvium-ffi, and salvium-multisig.
2026-02-24 23:43:52 +00:00
Matt Hess e4c1e7088c WASM explorer support, FFI multisig bindings, wallet/test improvements
- Add 12 wasm_bindgen exports (address parsing, TX type names, mnemonics)
  - Feature-gate all wasm_bindgen with cfg_attr for dual-build support
  - New salvium-explorer crate with high-level WASM APIs and TypeScript types
  - Add FFI multisig bindings (prepare, make, exchange_keys, sign, status)
  - Improve full_testnet hardfork progression test coverage
  - Various wallet scanner, sync, and key derivation fixes
2026-02-24 21:50:44 +00:00
Matt Hess 40858cbc11 Fix CARROT multi-output ephemeral keys, add subaddress/integrated address management, FFI blob export
- TX builder: emit per-output ephemeral keys (tag 0x04) for CARROT TXs
    instead of single shared key (tag 0x01)
  - Wallet: add subaddress/account creation, labeling, integrated address
    encode/decode, and bump lookahead from 50 to 10,000
  - DB: add subaddresses table with upsert/query/label/mark-used methods
  - FFI: add wallet blob export/import/rekey (PQC-encrypted)
  - CI: add WASM build target to release workflow
2026-02-23 18:56:14 +00:00
Matt Hess f71176d1f6 v1.0.7-r001: Cross-platform builds, FFI expansion, license, and bug fixes
- Version all crates at 1.0.7-r001 (tracking Salvium C++ 1.0.7)
  - Source-available license: free for author/designees and non-commercial
    use; annual commercial license required for any revenue-generating use
  - Build scripts for Android/iOS/Linux/macOS/Windows producing both
    libsalvium_crypto and libsalvium_ffi
  - CI workflow publishes platform archives to salvium-rs-releases
  - 23 new FFI functions: storage ops, address book, tx notes, attributes,
    staked balance, key derivation, mnemonic
  - Fix stake detection: count owned outputs regardless of spent state
  - Auto-resume testnet integration tests from current chain height
2026-02-23 17:01:33 +00:00
Matt Hess 7757735ac6 Enhance full_testnet integration test with assertions and new coverage
Add 6 enhancements: sync parse-error tracking via SyncEvent channel,
   balance assertions after each fork phase, TX-ID stake return verification
   at HF6+, view-only wallet balance matching, sync idempotency check, and
   subaddress (0,1) receive test at HF10.
y
2026-02-23 01:04:37 +00:00
Matt Hess 3bc166ef7e Add FFI bindings, sync bench, TX-ID stake tracking, and fix unlock tests
- New salvium-ffi crate: C FFI bindings for wallet create/open/sync/transfer
  - New salvium-sync-bench crate: full-chain sync benchmark with balance verification
  - TX-ID-based stake return tracking via return_output_key (replaces height-only detection)
  - Fix is_unlocked tests: use Salvium relative unlock_time (60) not Monero absolute
  - Restructure CLI commands into per-domain modules
  - Add multisig signing module and PQC post-quantum module
  - Extend daemon RPC, portable storage, and CARROT scanning
2026-02-23 00:20:55 +00:00
Matt Hess e88e50629e Complete salvium-rpc API coverage, add wallet address book + tx notes
- salvium-rpc daemon: add 33 methods (get_version, get_connections,
    get_peer_list, get_public_nodes, transaction pool, mining control,
    log management, blockchain maintenance, etc.) with 20 response types
  - salvium-rpc wallet: add 56 methods (address/account management,
    address book, sweep variants, proofs, multisig, URI handling, output
    freeze/thaw, etc.) with 17 response types
  - salvium-crypto storage: add address_book table with CRUD operations,
    tx notes set/get methods
  - salvium-wallet: expose address book and transaction notes through
    Wallet struct (7 new methods)
2026-02-21 08:28:45 +00:00
Matt Hess 8a107b2bec Add stratum v1 pool mining + GhostRider miner crate
Implement stratum v1 protocol client for Bitcoin-style pool mining
  (mining.subscribe/authorize/notify/submit). Add salvium-miner-gr crate
  with GhostRider PoW (15 SPH-512 + 3 CryptoNight rounds), verified
  against XMRig test vectors. Extend MiningJob with optional nonce_offset
  and target fields for backward-compatible stratum support.
2026-02-20 23:36:11 +00:00
Matt Hess a6a2ddb950 Fix 4 consensus validation mismatches vs C++ reference
Audited all validation rules against blockchain.cpp and
   tx_verification_utils.cpp. Fixed every divergence found:

   - Asset type HF segregation: enforce SAL before HF6, SAL1 from HF6+
     (was ignoring hf_version parameter entirely)
   - Output key sorting: use <= (strictly increasing, no duplicates)
     to match C++ !(pubkey > last) comparison
   - Output sorting boundary: enforce at HF > CARROT || is_carrot
     (was HF >= CARROT for all TXs)
   - Ring size unmixable exception: allow < 16 for unmixable non-RCT
     outputs with ≤1 mixable input, gated behind HF >= 2
2026-02-20 02:37:08 +00:00
Matt Hess 6bc880f1ae Fix all clippy and rustc warnings for CI compliance
The CI workflow uses RUSTFLAGS="-Dwarnings" which promotes all warnings
  to errors. This resolves every warning across the workspace so both
  cargo build, cargo test, and cargo clippy pass cleanly.

  Clippy fixes (~100 warnings across 9 crates):
  - Replace manual assign ops with compound assignment (+=, *=) in
    bulletproofs_plus Scalar arithmetic
  - Use iterator patterns instead of index-based loops (enumerate, zip,
    iter_mut) in elligator2, bulletproofs_plus, miner, mnemonic
  - Replace manual div_ceil with .div_ceil() in consensus difficulty/fee
  - Replace map_or(true, ..) with is_none_or(..) in stake filtering
  - Replace inherent to_string() with Display impl in multisig types
  - Collapse nested if statements in validation.rs
  - Remove redundant closures (.map(hex::encode), .and_then(hex_to_32))
  - Remove unnecessary .to_vec(), borrows, and return statements
  - Use RangeInclusive::contains for range checks
  - Derive Default instead of manual impl for BlockExtendedInfo
  - Use unwrap_or_default/unwrap_or for simplified match expressions
  - Use std::ptr::slice_from_raw_parts_mut in FFI free function
  - Add #[allow(clippy::too_many_arguments)] where function signatures
    match the C++ reference implementation (crypto scan, TCLSAG, RCT
    verify, miner, RPC, stake lifecycle)
  - Add #[allow(clippy::type_complexity)] for complex tuple return types
  - Convert match-with-single-pattern to if-let in CLI commands
  - Rename AssetType::from_str to ::parse to avoid std trait confusion
  - Fix literal-in-format-string warnings in CLI table headers

  Rustc warning fixes (from prior session, included for completeness):
  - Remove unused constants, imports, and struct fields
  - Fix deprecated Nonce::from_slice calls in AES-256-GCM functions
  - Add missing protocol_tx_data field to all TxPrefix constructors
  - Prefix unused variables with underscore
2026-02-19 20:02:09 +00:00
Matt Hess 10ae3ee0d0 Implement legacy + CARROT TX construction, pass all 10 hardforks
- Implement legacy CryptoNote stealth address output construction (TaggedKey)
    for pre-HF10 transactions (rct_types 6-8, CLSAG signing)
  - Add CARROT output support at HF10 (rct_type 9, TCLSAG signing)
  - Add ProtocolTxData for v4 STAKE transactions (CARROT return enote)
  - Set secret_key_y = zero for legacy outputs spent with TCLSAG
  - Fix asset_type extraction from on-chain outputs (nested target sub-objects)
  - Fix STAKE TX: use amount_burnt, derive return_address/return_pubkey
  - Expose cn_scan helpers: ecdh_encode_amount, derive_view_tag
  - Full testnet test passes HF1-HF10: transfers, stake, burn, sweep
2026-02-19 17:07:22 +00:00
Matt Hess 2dc9c082fc Add full testnet hardfork progression test, silence miner warnings
Port test/legacy-js/full-testnet.js to Rust: a single #[ignore] integration
   test that mines from genesis through all 10 hard forks, testing transfers,
   stakes, burns, and sweeps at each era boundary. Suppress unused-code warnings
   in the miner crate (deserialized API fields, FFI stubs, stratum placeholder).
2026-02-18 16:32:45 +00:00
Matt Hess b5af339c77 Enhance RPC error reporting: context on all errors, retries with backoff
- Add method/url/endpoint context to every RpcError variant
  - Default retries 0→2 with exponential backoff (500ms initial)
  - HTTP status handling (401/4xx/5xx) with body capture
  - Transient error classification for retry decisions
  - Connection pooling (pool_max_idle_per_host=4)
  - All NoResult errors now identify the failing call
2026-02-18 05:31:03 +00:00
Matt Hess 4195250684 Fix flaky storage tests, use dedicated atomic counter for test DB paths 2026-02-18 04:45:07 +00:00
Matt Hess a6dfb90b9f Update README for salvium-rs: Rust workspace docs, crate overview, CLI usage 2026-02-18 02:01:44 +00:00
Matt Hess d00ff2e1d8 Update CI/CD: per-crate test matrix, clippy, WASM check, release gating
CI now runs fmt, clippy, compile (debug+release), WASM target check,
   per-crate test jobs (types+consensus, crypto, wallet+tx, miner+multisig+rpc),
   doc tests, and a final ci-pass gate. Release workflow gates on tests,
   fixes workspace target paths, and adds scaffolding for publishing
   binaries to an external releases repo.
2026-02-18 00:51:39 +00:00
Matt Hess 733ecd2681 Migrate all JS tests to Rust: 9-crate workspace, 703 tests, 0 JS remaining
Add root Cargo workspace with 9 crates: salvium-crypto (extended),
  salvium-types, salvium-consensus, salvium-wallet, salvium-tx,
  salvium-rpc, salvium-miner (extended), salvium-cli, salvium-multisig.

  New modules: chain_state, block_weight, alt_chain, validation,
  offline signing, stake lifecycle, wallet sync/query/encryption/utxo,
  randomx utilities, and full multisig crate with CARROT support.

  Delete 188 JS test/helper/debug files; archive integration test
  scripts to test/legacy-js/ for live testnet use. Testnet integration
  tests (transfer, stake, burn, convert, sweep) remain as #[ignore]-
  gated Rust tests runnable with --ignored against a live daemon.
2026-02-17 23:09:35 +00:00
Matt Hess e95ca67ec2 Optimize miner: large pages, pipelined hashing, blob reuse 2026-02-16 01:47:32 +00:00
Matt Hess ff15a54c30 Include staked balance in wallet total, add stake storage FFI + diagnostics
- Fix balance computation: staked amounts now included in total balance
     to match C++ wallet behavior (balance = unspent + staked, locked =
     immature + staked). Affects getBalance, getStorageBalance, and
     integration sync test reporting.
   - Add stake lifecycle methods to Rust storage (putStake, getStake,
     getStakes, getStakeByOutputKey, markStakeReturned, deleteStakesAbove)
     with FFI bindings and JS FfiStorage wrappers.
   - Fix BigInt serialization in FfiStorage.putStake (JSON.stringify crash).
   - Add balance diagnostic script (test/diagnose-balance.js) for verifying
     key image spent status against the blockchain.
   - Integration sync test: clear stale DB on fresh sync, add per-txType
     and per-format unspent breakdowns, show staked balance in report.
2026-02-15 22:26:24 +00:00
Matt Hess 2db263922b Fix BP+ R array parsing: read varint count instead of reusing L count
The Monero/Salvium binary format serializes both L and R vectors with
  their own varint length prefix, but the parser skipped R's varint and
  reused Lcount. This 1-byte offset shift corrupted all subsequent
  prunable data (TCLSAG sigs, pseudoOuts), causing RCT signature
  verification to fail on every daemon-fetched transaction.
2026-02-14 21:31:27 +00:00
Matt Hess c1c8cf4cb2 Remove stale ed25519.js import — ops route through crypto provider 2026-02-14 17:26:50 +00:00
Matt Hess ab01390bb6 Add bundle entry point, crypto shim, and wallet updates for Flutter integration 2026-02-14 17:17:25 +00:00
Matt Hess 7f01cafc62 Crypto layer consolidation: eliminate JS scalar ops, add cn_scan + RCT batch verify
Crypto Backend Refactoring
   ──────────────────────────
   - Delete src/ed25519.js — all scalar/point operations now route through
     the crypto provider (WASM/FFI/JSI backends only)
   - Remove duplicate JS BigInt implementations of scReduce32, scReduce64,
     scalarAdd, scalarMul from scanning.js, carrot.js, and carrot-scanning.js;
     delegate to Rust backend via crypto/index.js
   - Remove debug/test exports from index.js (randomPoint, testDouble,
     getBasePoint, isOnCurve, etc.) that were only used during development
   - Rebuild WASM binary (476KB → 487KB) with updated Rust crate

   Consolidated CryptoNote Scanner (cn_scan)
   ─────────────────────────────────────────
   - New Rust module crates/salvium-crypto/src/cn_scan.rs replaces 5-12
     individual FFI round-trips per output with a single native call:
     view tag check → derive subaddress pubkey → subaddress map lookup →
     amount decryption → commitment mask → key image generation
   - FFI wrapper salvium_cn_scan_output in ffi.rs + C header declaration
   - FFI backend scanCnOutput() with full subaddress map marshaling
     (32-byte key + u32 major/minor LE per entry) and JSON result parsing
   - JSI backend delegation via this.native.cnScanOutput()
   - wallet-sync.js _scanCNOutput() tries native path first when available
     (FFI/JSI), falls through to existing JS pipeline for WASM/JS backends
   - Change pub(crate) visibility on subaddress.rs cn_subaddress_secret_key
   - 8 Rust unit tests covering view tag, amount, commitment mask,
     subaddress matching, and key image generation
   - Verified identical results: WASM (JS fallback) and FFI (native cn_scan)
     produce same 964 outputs at same chain height; FFI is 3x faster sync
     (0.8s vs 2.5s) with 12x less heap (12MB vs 150MB)

   RCT Batch Signature Verification
   ─────────────────────────────────
   - New Rust module crates/salvium-crypto/src/rct_verify.rs — single-call
     verification of all ring signatures in a transaction (CLSAG + TCLSAG),
     avoiding N individual JS↔Rust boundary crossings
   - Computes pre-MLSAG message hash matching C++ get_pre_mlsag_hash
   - FFI export salvium_verify_rct_signatures with flat byte array interface
   - FFI backend verifyRctSignatures() method
   - JS backend stub returns null (validation.js handles JS fallback)
   - validation.js: 200+ lines of RCT verification logic including
     flattenKeyImages, packTclsagSigsFlat, packClsagSigsFlat helpers

   Transaction Expansion
   ─────────────────────
   - transaction.js: add expandTransaction() matching C++ expand_transaction_2
     (copies key images from prefix inputs into TCLSAG/CLSAG signature structs)
   - New test/expand-transaction.test.js (634 lines)
   - New test/rct-verify-testnet.test.js (430 lines)

   Mining Resilience
   ─────────────────
   - salvium-miner main.rs: retry get_info and get_block_template up to 5
     times with 2s delay for transient daemon errors
   - full-testnet.js mineTo(): retry miner up to 3 times with 3s delay,
     check for partial progress between attempts

   Testnet Tooling
   ───────────────
   - sync-only.js: CRYPTO_BACKEND env var for A/B testing (wasm vs ffi)
   - full-testnet.js: daemon URL update (node12.whiskymine.io)
   - Debug scripts for cn_scan development (debug-cn-scan/marshal/match/wasm)
   - Android .gitignore and build-bundle.sh for mobile builds
2026-02-14 17:02:35 +00:00
Matt Hess 2dd02da11c Tests for stake lifecycle tracking 2026-02-14 01:14:53 +00:00