Building on the wallet library
WalletCore is the Rust client: it holds keys, builds and signs transactions, proves private ones, scans for notes a user can decrypt, and submits. Every runner under examples/program_deployment/src/bin/ is a short client built on it, and so a worked example.
Source: lez/wallet/src/lib.rs, with account handling in lez/wallet/src/account_manager.rs.
The shape of a client
let mut wallet_core = WalletCore::from_env()?;
// accounts
let (account_id, _) = wallet_core.create_new_account_public(None); // or Some(chain_index)
let nonces = wallet_core.get_accounts_nonces(&[account_id]).await?;
wallet_core.store_persistent_data()?;
// reading
wallet_core.get_account(AccountIdWithPrivacy::Public(account_id)).await?;
wallet_core.get_account_public(account_id).await?; // or this, for a bare id
wallet_core.get_account_balance(account_id).await?;
wallet_core.get_account_view(Actor::new(account_id, program_account_id)).await?;
wallet_core.get_last_block_id().await?;
wallet_core.get_block(block_id).await?;
wallet_core.get_transaction(tx_hash).await?;
// the mailbox
wallet_core.get_publications(from_position, limit).await?;
wallet_core.owned_pending_messages().await?;
wallet_core.find_pending_message(..).await?;
// submitting
wallet_core.send_pub_tx(..).await?;
wallet_core.send_privacy_preserving_tx(mentions, root, message_bytes, &programs).await?;
store_persistent_data is not optional: keys created in memory and not stored are lost, which is why the examples’ deploy_program helper calls it after creating the header and segment accounts.
A native transfer
The facades in lez/wallet/src/program_facades/ build, sign or prove, and submit a builtin program’s call:
use wallet::{
AccountIdentity, WalletCore,
program_facades::{CreditDelivery, native_token_transfer::NativeTokenTransfer},
};
let mut wallet_core = WalletCore::from_env()?;
let (tx_hash, _) = NativeTokenTransfer(&wallet_core)
.transfer(AccountIdentity::Public(from), AccountIdentity::Public(to), amount, CreditDelivery::Automatic)
.await?;
from and to are AccountIds and amount a u128. Either side may be private, which makes it a private transaction proven in process; CreditDelivery::DeferredPrivate leaves a private recipient’s credit in the mailbox; a PrivateForeign recipient’s always waits there. transfer checks the sender’s balance first and returns InsufficientFundsError without sending. It returns the hash and, per private account, the shared secret (SharedSecretKey) its new note is encrypted under, not an outcome: wait for inclusion and read the receipt (It lags the sequencer). When a private account took part, call wallet_core.sync_to_latest_block().await? after inclusion so the wallet records the spent and new notes; it also stores. from_env reads LEE_WALLET_HOME_DIR and, for an encrypted store, LEE_WALLET_PASSWORD, prompting on the terminal when it is unset.
Depending on it from outside the repository
No crate is published. Depend on wallet (and lee, lee_core, common for their types) by path into a checkout matching the node you talk to, and copy that checkout’s [patch.crates-io] section, Cargo.lock and rust-toolchain.toml so the graph resolves as it does there. If your own core crate pins lee_core by git (A program crate), add a [patch."https://github.com/logos-blockchain/logos-execution-zone"] entry pointing lee_core at the same checkout, or the two do not unify. The guest binaries the wallet embeds are committed under artifacts/ and read by build scripts from the checkout, so a client build compiles no guest and needs neither Docker nor RISC0_SKIP_BUILD.
Naming an account
An account is named by an AccountIdentity, with nine variants:
| Variant | Use |
|---|---|
Public(id) | a public account this wallet owns and will sign for |
PublicNoSign(id) | a public account to touch without signing, even if owned |
PublicForeign { .. } | someone else’s public account, known by its initial key |
PublicPda { .. } | a public program-derived account |
PublicKeycard { .. } | a public account signed by a Keycard; refused in every build, because a Keycard key cannot rotate (lez/wallet/src/keycard_support.rs) |
PrivateOwned(id) | a private account whose keys and kind the wallet holds |
PrivateForeign { .. } | a private account known only by its public keys: a destination you can send async messages to but cannot witness |
PrivateShared { .. } | a shared regular private account with externally supplied keys, as from a group key |
PrivatePdaShared { .. } | a shared private PDA, likewise |
The distinction that catches people: PrivateForeign is send-only. You can address an async message to it but cannot produce a witness for it, because a witness needs the account’s nullifier secret key (or the authorization secret key it derives from), which only the holder has. That asymmetry is why the mailbox exists (Private accounts).
Select a program’s actor state on an identity before using it:
let account = AccountIdentity::PrivateOwned(account_id)
.select_program_actor_state(program_account_id);
Submitting a private transaction
wallet_core
.send_privacy_preserving_tx(vec![account], 0, Program::serialize_message(msg)?, &programs)
.await?;
The first argument lists the transaction’s account mentions: a mention is one account together with the program whose actor state it selects and whether it authorizes (AccountMention, a wallet type, not a protocol one). The second is the index in that list of the mention the root message goes to. Program::serialize_message(msg) is borsh::to_vec(&msg), returned as a MessageData (a Vec<u8>) inside a Result, the encoding a guest decodes, so Borsh bytes from anywhere work. A mention from select_program_actor_state authorizes; call .without_authorization() on it for an account the transaction touches but does not authorize, such as a recipient (PublicNoSign(id) is the public shorthand).
The programs argument must list every program the call graph may reach, each marked disclosed, undisclosed or shadow (Programs, deployment and identity). A disclosed or undisclosed program is keyed by its deployed account id; a shadow program, never deployed, by AccountId::for_shadow_program(&image_id), and a message reaching it in the public part fails with UnknownProgram. A program the execution dispatches to that was not supplied cannot be proven.
Proving happens in process (how long it takes). RISC0_DEV_MODE=1 skips real proving during development and must never be used against a real network.
A refused submission comes back with its cause; The sequencer’s own RPC lists the refusals and their codes. The library keeps the message and drops the code and data: a refusal is ExecutionFailureKind::SequencerClientError(message), so the size cap arrives as only Invalid params. The exception is -31901, PrivateFeeBelowHead, which a private send reprices and resends up to twice before returning.
Deployment from Rust
The examples’ helper is the shortest correct deployment and, unlike the CLI, creates the accounts.
pub async fn deploy_program<C: WalletSequencerClient>(
wallet_core: &mut WalletCore<C>,
bytecode: Vec<u8>,
payer: AccountId,
) -> anyhow::Result<AccountId>
WalletCore is generic over its sequencer client, so a function taking one needs that parameter and a struct holding one must name the client type. WalletCore::from_env() returns a WalletCore<SequencerClient>, the HTTP client. The helper decodes the ProgramBinary, computes the user ELF’s length divided by MAX_SEGMENT_DATA_LEN, rounded up, creates a header account and that many segment accounts, and calls ProgramLoader(wallet_core).deploy(header, &segments, bytecode, true, Some(payer)), hardcoding immutable. wallet program-loader deploy creates none of the accounts, so the CLI needs them to exist first.
payer must already exist and hold funds: the new header and segment accounts cannot pay for their own creation.
Source: examples/program_deployment/src/lib.rs.
The zone a signature is for
Every signature covers a zone id, a domain-separated SHA-256 of the channel id and genesis hash, so a transaction signed for one zone cannot be replayed on another. Each genesis gets its own zone from a salt, so a chain recreated on the same channel is normally a different zone and the old chain’s signatures stop verifying; Starting clean has the case where it is not.
A client that pins zone_id in its wallet configuration is safe against being pointed at a different chain; one that leaves it unset trusts whatever its sequencer reports from getZoneId. Pin it for anything holding value.
Where to start reading
Start with A native transfer. For a call to your own program, run_hello_world.rs is the minimal public client, and run_hello_world_private.rs the same thing privately. The public runner builds and signs its transaction by hand (fee, nonces, admission evidence); the private one builds an account mention from an AccountIdentity and passes it with a ProgramCatalog to send_privacy_preserving_tx.