mx-core 0.1.0

Core utilities for MultiversX Rust services.
Documentation

mx-core

Core utilities shared across MultiversX Rust services.

Features

  • Wallet Derivation: BIP39 mnemonic to Ed25519 signing keys
  • Shard Computation: Matching mx-chain-go algorithm
  • Address Encoding: Bech32 encode/decode utilities
  • BigIntCaster Helpers: Go-compatible big integer encode/decode plus unsigned amount parsing
  • Topic System: P2P gossipsub topic generation and parsing
  • Protocol Constants: Centralized network constants

Usage

use mx_core::{
    // Wallet derivation
    derive_signing_key, derive_address,
    // Shard computation
    shard_of, shard_of_address_bytes, select_shard, shard_of_bytes,
    decode_embedded_receiver,
    // Address encoding
    decode_bech32, encode_bech32,
    // Big integer helpers
    parse_big_uint, encode_big_int_caster, decode_big_int_caster,
    // Topic system
    BaseTopic, TopicInfo, TopicRouting, TopicShard,
    broadcast_topic, transaction_topics_from_shards,
    // Constants
    META_SHARD_ID, METACHAIN_SHARD_ID, ALL_SHARD_ID,
    TX_OPTION_HASH_SIGN, TX_OPTION_GUARDED,
    // Encoding utilities
    decode_base64, decode_hex, decode_base64_or_hex,
};

// Derive wallet from mnemonic
let key = derive_signing_key(mnemonic, 0, 0)?;
let address = derive_address(mnemonic, 0, 0)?;

// Compute shard (multiple methods)
let shard = shard_of(&address, 3)?;
let shard = shard_of_address_bytes(&raw_bytes, 3);
let shard = select_shard(last_byte, 3);

// Parse topic (with caching for hot paths)
let info = TopicInfo::parse("transactions_0_1");
let info = TopicInfo::parse_cached("transactions_0_1"); // cached version

Modules

Module Description
wallet Ed25519 key derivation from BIP39 mnemonics
shard Shard computation matching mx-chain-go
bech32_utils Address encoding/decoding
bigint Go BigIntCaster helpers and unsigned amount parsing
topics P2P topic generation and parsing
constants Protocol constants
encoding Base64/hex utilities
mnemonic Mnemonic normalization

Performance

  • shard_of_address_bytes: ~30ns (pre-decoded)
  • shard_of: ~530ns (includes bech32 decode)
  • Topic parsing: Cached for hot paths