hdwallet-fc

Crates.iohdwallet-fc
lib.rshdwallet-fc
version0.2.8
sourcesrc
created_at2024-01-09 08:06:50.144112
updated_at2024-03-13 03:12:08.889954
descriptionHierarchical deterministic wallet
homepage
repositoryhttps://github.com/fcihpy001/hdwallet-fc
max_upload_size
id1093585
size20,188
fcihpy (fcihpy001)

documentation

README

功能介绍

  • 根据助记词生成btc各种钱包地址
  • 根据助记词生成eth私钥
  • 使用方法

根据助记词生成p2pk2类型的钱包地址

fn test_p2p2kh_addr() {
    let mn = "pulp gun crisp mechanic hub ahead blouse hurry life boss option evolve";
    let addr = btc_addr_p2pkh(mn);
    assert_eq!(addr, "1NDScYSjEqrYAMGRr7DwLhwFRACqo1BCU1")
}

根据助记词生成以太系私钥

fn test_eth_private() {
    let mn = "pulp gun crisp mechanic hub ahead blouse hurry life boss option evolve";
    let addr = eth_private(mn);
    assert_eq!(addr, "ff4d431538ee621168a8063e640653b2413ff4dbb519f954748d5eef669a6347")
}

根据助记词和派生路径生成对应的扩展私钥

 fn test_get_private_key() {
    let test_mnemonic_phrase: &str =
     "pulp gun crisp mechanic hub ahead blouse hurry life boss option evolve";
    let test_seed = self::get_mnemonic(test_mnemonic_phrase)
      .unwrap()
     .to_seed("");
    println!("bip39种子(seed): {:?}", hex::encode(test_seed));

    // 获取扩展私钥
    let private_key = get_private_key(test_seed,44,0);
    println!("扩展密钥 {}", private_key.to_string());
    println!("子私钥 {}", private_key.private_key.to_string());

    assert_eq!(
       private_key.private_key.to_string(),
     "L3sQh1LbgjxxsGW9hgSskg87MaMJWGcp4Pf8acAjbbeFSNBrPVC4"
    )
}

根据助记词和派生路径生成对应公钥

fn test_get_public_key() {
    let test_mnemonic_phrase: &str =
        "pulp gun crisp mechanic hub ahead blouse hurry life boss option evolve";
    let test_seed = get_mnemonic(test_mnemonic_phrase)
        .unwrap()
        .to_seed("");

    let private_key = get_private_key(test_seed, 44,0);

    let public_key = get_public_key(private_key);
    assert_eq!(
        "032352a1c4465934cdff949e4f0bb9a050676a9f6162ecca238612b08519bdcded",
     public_key.public_key.to_string()
     );
}   
Commit count: 0

cargo fmt