Skip to main content

kobe_casper/
lib.rs

1//! Casper Network wallet utilities for Kobe.
2//!
3//! Offline HD derivation for **CSPR** (SLIP-44 coin type `506`) with dual
4//! signature algorithms:
5//!
6//! | Algorithm | Default path | Curve | Kobe primitive |
7//! | --- | --- | --- | --- |
8//! | [`KeyAlgo::Secp256k1`] (default) | `m/44'/506'/0'/0/{i}` | secp256k1 | BIP-32 |
9//! | [`KeyAlgo::Ed25519`] | `m/44'/506'/0'/0'/{i}'` | Ed25519 | SLIP-10 |
10//!
11//! # Address encoding
12//!
13//! The primary [`DerivedAccount::address`] is the Casper **`AccountHash`**
14//! display form `account-hash-` + 64 lowercase hex digits.
15//!
16//! Per [`casper-types`](https://github.com/casper-network/casper-node)
17//! `AccountHash::from_public_key`, the `BLAKE2b`-256 preimage is **not** the
18//! tag-prefixed public-key serialization. It is:
19//!
20//! ```text
21//! algorithm_name_ascii || 0x00 || raw_public_key_bytes
22//! ```
23//!
24//! where `algorithm_name` is the lowercase ASCII string `"secp256k1"` or
25//! `"ed25519"`, and `raw_public_key_bytes` is the 33-byte compressed `SEC1`
26//! secp256k1 key or the 32-byte Ed25519 key (no algorithm tag byte).
27//!
28//! The algorithm-tagged public-key hex used in Casper serialization /
29//! CEP-57 contexts (`0x01 ‖ ed25519` or `0x02 ‖ secp compressed`) is
30//! exposed separately on [`CasperAccount::tagged_public_key_hex`].
31//!
32//! # Example
33//!
34//! ```no_run
35//! use kobe_casper::{Deriver, KeyAlgo};
36//! use kobe_primitives::{Derive, Wallet};
37//!
38//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
39//! let wallet = Wallet::from_mnemonic(
40//!     "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about",
41//!     None,
42//! )?;
43//! let account = Deriver::new(&wallet).derive(0)?;
44//! assert!(account.address().starts_with("account-hash-"));
45//! assert_eq!(account.algo(), KeyAlgo::Secp256k1);
46//! # Ok(())
47//! # }
48//! ```
49
50#![cfg_attr(not(feature = "std"), no_std)]
51
52#[cfg(feature = "alloc")]
53extern crate alloc;
54
55#[cfg(feature = "alloc")]
56mod address;
57#[cfg(feature = "alloc")]
58mod deriver;
59#[cfg(feature = "alloc")]
60mod key_algo;
61
62#[cfg(feature = "alloc")]
63pub use address::{
64    ACCOUNT_HASH_PREFIX, ED25519_TAG, SECP256K1_TAG, account_hash_ed25519, account_hash_secp256k1,
65    format_account_hash, tagged_public_key_hex,
66};
67#[cfg(feature = "alloc")]
68pub use deriver::{CasperAccount, Deriver};
69#[cfg(feature = "alloc")]
70pub use key_algo::KeyAlgo;
71pub use kobe_primitives::{
72    DeriveError, DerivedAccount, DerivedPublicKey, ParseDerivationStyleError,
73};