From 9ce59b1239f8a71c0384ddf9fc50378ce9014dbd Mon Sep 17 00:00:00 2001 From: koushiro Date: Sun, 25 Oct 2026 15:34:33 +0800 Subject: [PATCH] chore(bip0039): update readme and use it as lib docs --- bip0039/README.md | 6 +- bip0039/benchmarks/README.md | 144 +++++++++++++++++------------------ bip0039/src/lib.rs | 52 +------------ 3 files changed, 74 insertions(+), 128 deletions(-) diff --git a/bip0039/README.md b/bip0039/README.md index f57ca8f..5008a01 100644 --- a/bip0039/README.md +++ b/bip0039/README.md @@ -49,10 +49,6 @@ assert_eq!(seed.len(), 64); println!("seed: {}", const_hex::encode(seed)); ``` -## Documentation - -See documentation and examples at https://docs.rs/bip0039. - ## Features - [x] Support all languages in the [BIP-0039 Word Lists](https://github.com/bitcoin/bips/blob/master/bip-0039/bip-0039-wordlists.md) @@ -80,4 +76,4 @@ See [benchmarks](https://github.com/koushiro/rust-bips/blob/main/bip0039/benchma ## License -This project is licensed under the Apache License, Version 2.0 - see the [LICENSE](../LICENSE) file for details. +Licensed under the Apache License, Version 2.0: diff --git a/bip0039/benchmarks/README.md b/bip0039/benchmarks/README.md index 975ebf8..98552fc 100644 --- a/bip0039/benchmarks/README.md +++ b/bip0039/benchmarks/README.md @@ -12,40 +12,40 @@ cargo bench --bench generate -- --quiet ```text generate/tiny-bip39 (12 words) - time: [523.59 ns 524.50 ns 525.71 ns] + time: [514.64 ns 522.07 ns 531.46 ns] generate/bip39 (12 words) - time: [1.5540 µs 1.5558 µs 1.5576 µs] + time: [1.6379 µs 1.7240 µs 1.8205 µs] generate/coins-bip39 (12 words) - time: [726.52 µs 728.22 µs 730.16 µs] + time: [719.23 µs 720.65 µs 722.02 µs] generate/bip0039 (12 words) - time: [341.26 ns 342.33 ns 343.60 ns] + time: [312.86 ns 316.63 ns 323.17 ns] generate/tiny-bip39 (15 words) - time: [604.25 ns 619.77 ns 648.99 ns] + time: [554.81 ns 559.83 ns 568.43 ns] generate/bip39 (15 words) - time: [1.6137 µs 1.6212 µs 1.6314 µs] + time: [1.6082 µs 1.6152 µs 1.6244 µs] generate/coins-bip39 (15 words) - time: [908.87 µs 912.40 µs 916.67 µs] + time: [900.94 µs 904.34 µs 909.27 µs] generate/bip0039 (15 words) - time: [410.52 ns 412.44 ns 414.31 ns] + time: [367.49 ns 368.81 ns 370.17 ns] generate/tiny-bip39 (18 words) - time: [663.81 ns 668.18 ns 674.12 ns] + time: [614.19 ns 616.14 ns 618.02 ns] generate/bip39 (18 words) - time: [1.6627 µs 1.6721 µs 1.6829 µs] + time: [1.6521 µs 1.6714 µs 1.7067 µs] generate/coins-bip39 (18 words) - time: [1.0872 ms 1.0902 ms 1.0934 ms] + time: [1.0806 ms 1.0824 ms 1.0845 ms] generate/bip0039 (18 words) - time: [461.72 ns 465.73 ns 471.93 ns] + time: [411.78 ns 418.61 ns 429.96 ns] generate/tiny-bip39 (24 words) - time: [812.13 ns 814.46 ns 817.03 ns] + time: [739.40 ns 741.77 ns 744.72 ns] generate/bip39 (24 words) - time: [1.8060 µs 1.8133 µs 1.8212 µs] + time: [1.8042 µs 1.8104 µs 1.8174 µs] generate/coins-bip39 (24 words) - time: [1.4543 ms 1.4585 ms 1.4634 ms] + time: [1.4402 ms 1.4438 ms 1.4475 ms] generate/bip0039 (24 words) - time: [591.94 ns 594.03 ns 596.34 ns] + time: [519.20 ns 520.55 ns 521.95 ns] ``` ## from_entropy @@ -57,40 +57,40 @@ cargo bench --bench from_entropy -- --quiet ```text from_entropy/tiny-bip39 (12 words) - time: [518.84 ns 520.80 ns 522.91 ns] + time: [488.11 ns 492.23 ns 497.50 ns] from_entropy/bip39 (12 words) - time: [614.78 ns 621.05 ns 631.25 ns] + time: [616.22 ns 619.91 ns 625.66 ns] from_entropy/coins-bip39 (12 words) - time: [724.39 µs 726.90 µs 730.19 µs] + time: [718.63 µs 719.91 µs 721.41 µs] from_entropy/bip0039 (12 words) - time: [340.42 ns 341.66 ns 343.00 ns] + time: [308.69 ns 314.00 ns 322.16 ns] from_entropy/tiny-bip39 (15 words) - time: [592.58 ns 594.24 ns 596.44 ns] + time: [546.63 ns 548.30 ns 550.06 ns] from_entropy/bip39 (15 words) - time: [663.83 ns 667.19 ns 671.91 ns] + time: [667.49 ns 670.29 ns 674.54 ns] from_entropy/coins-bip39 (15 words) - time: [904.16 µs 905.83 µs 907.69 µs] + time: [900.45 µs 908.99 µs 925.77 µs] from_entropy/bip0039 (15 words) - time: [404.65 ns 407.57 ns 412.63 ns] + time: [366.70 ns 368.05 ns 369.38 ns] from_entropy/tiny-bip39 (18 words) - time: [644.93 ns 646.83 ns 648.94 ns] + time: [598.79 ns 600.31 ns 602.10 ns] from_entropy/bip39 (18 words) - time: [707.15 ns 722.63 ns 752.99 ns] + time: [717.63 ns 720.09 ns 723.01 ns] from_entropy/coins-bip39 (18 words) - time: [1.0879 ms 1.0918 ms 1.0962 ms] + time: [1.0850 ms 1.0900 ms 1.0961 ms] from_entropy/bip0039 (18 words) - time: [456.64 ns 458.06 ns 459.59 ns] + time: [412.61 ns 417.85 ns 426.02 ns] from_entropy/tiny-bip39 (24 words) - time: [774.94 ns 780.52 ns 789.05 ns] + time: [726.80 ns 736.56 ns 752.37 ns] from_entropy/bip39 (24 words) - time: [872.75 ns 875.24 ns 877.97 ns] + time: [877.97 ns 880.68 ns 883.58 ns] from_entropy/coins-bip39 (24 words) - time: [1.4522 ms 1.4635 ms 1.4821 ms] + time: [1.4397 ms 1.4433 ms 1.4474 ms] from_entropy/bip0039 (24 words) - time: [567.81 ns 568.97 ns 570.33 ns] + time: [515.11 ns 520.96 ns 529.87 ns] ``` ## from_phrase @@ -102,60 +102,60 @@ cargo bench --bench from_phrase -- --quiet ```text from_phrase/tiny-bip39 (12 words) - time: [1.5675 µs 1.5737 µs 1.5817 µs] + time: [1.5478 µs 1.5531 µs 1.5586 µs] from_phrase/bip39 (12 words) - time: [2.0082 µs 2.0135 µs 2.0202 µs] + time: [2.0008 µs 2.0169 µs 2.0370 µs] from_phrase/coins-bip39 (12 words) - time: [1.6889 ms 1.6942 ms 1.7016 ms] + time: [1.6925 ms 1.7051 ms 1.7242 ms] from_phrase/bip0039 (12 words) - time: [777.33 ns 778.93 ns 780.74 ns] + time: [745.89 ns 749.98 ns 754.29 ns] from_phrase/tiny-bip39 (15 words) - time: [1.8220 µs 1.8404 µs 1.8654 µs] + time: [1.8002 µs 1.8141 µs 1.8356 µs] from_phrase/bip39 (15 words) - time: [2.4656 µs 2.4783 µs 2.4931 µs] + time: [2.4639 µs 2.4743 µs 2.4859 µs] from_phrase/coins-bip39 (15 words) - time: [2.1241 ms 2.1606 ms 2.2289 ms] + time: [2.1265 ms 2.1471 ms 2.1793 ms] from_phrase/bip0039 (15 words) - time: [952.73 ns 957.80 ns 966.29 ns] + time: [901.03 ns 903.92 ns 907.13 ns] from_phrase/tiny-bip39 (18 words) - time: [2.0556 µs 2.0662 µs 2.0826 µs] + time: [2.0624 µs 2.1266 µs 2.2174 µs] from_phrase/bip39 (18 words) - time: [2.9061 µs 2.9539 µs 3.0314 µs] + time: [2.9114 µs 2.9938 µs 3.1651 µs] from_phrase/coins-bip39 (18 words) - time: [2.5123 ms 2.5294 ms 2.5574 ms] + time: [2.5546 ms 2.5772 ms 2.6129 ms] from_phrase/bip0039 (18 words) - time: [1.0970 µs 1.1045 µs 1.1164 µs] + time: [1.0707 µs 1.0800 µs 1.0911 µs] from_phrase/tiny-bip39 (24 words) - time: [2.6467 µs 2.6578 µs 2.6689 µs] + time: [2.6592 µs 2.6922 µs 2.7427 µs] from_phrase/bip39 (24 words) - time: [3.6906 µs 3.7371 µs 3.8265 µs] + time: [3.7147 µs 3.7344 µs 3.7551 µs] from_phrase/coins-bip39 (24 words) - time: [3.3377 ms 3.3448 ms 3.3520 ms] + time: [3.4162 ms 3.4500 ms 3.4998 ms] from_phrase/bip0039 (24 words) - time: [1.4222 µs 1.4272 µs 1.4344 µs] + time: [1.3794 µs 1.3853 µs 1.3923 µs] from_normalized_phrase/bip39 (12 words) - time: [1.9007 µs 1.9402 µs 1.9990 µs] + time: [1.8928 µs 1.8989 µs 1.9055 µs] from_normalized_phrase/bip0039 (12 words) - time: [704.45 ns 706.89 ns 710.01 ns] + time: [686.03 ns 695.27 ns 707.47 ns] from_normalized_phrase/bip39 (15 words) - time: [2.2996 µs 2.3055 µs 2.3114 µs] + time: [2.3316 µs 2.3482 µs 2.3677 µs] from_normalized_phrase/bip0039 (15 words) - time: [884.84 ns 894.36 ns 907.62 ns] + time: [832.49 ns 836.58 ns 841.92 ns] from_normalized_phrase/bip39 (18 words) - time: [2.7791 µs 2.7876 µs 2.7982 µs] + time: [2.7424 µs 2.7544 µs 2.7674 µs] from_normalized_phrase/bip0039 (18 words) - time: [1.0290 µs 1.0312 µs 1.0341 µs] + time: [981.09 ns 992.49 ns 1.0110 µs] from_normalized_phrase/bip39 (24 words) - time: [3.6202 µs 3.6621 µs 3.7238 µs] + time: [3.6033 µs 3.6186 µs 3.6356 µs] from_normalized_phrase/bip0039 (24 words) - time: [1.3564 µs 1.3694 µs 1.3920 µs] + time: [1.2917 µs 1.3001 µs 1.3131 µs] ``` ## to_seed @@ -167,38 +167,38 @@ cargo bench --bench to_seed -- --quiet ```text to_seed/tiny-bip39 (12 words) - time: [977.20 µs 980.63 µs 985.20 µs] + time: [970.41 µs 972.44 µs 974.60 µs] to_seed/bip39 (12 words) - time: [1.0918 ms 1.0954 ms 1.0992 ms] + time: [1.0816 ms 1.0891 ms 1.1003 ms] to_seed/coins-bip39 (12 words) - time: [1.1631 ms 1.1666 ms 1.1705 ms] + time: [1.1490 ms 1.1596 ms 1.1795 ms] to_seed/bip0039 (12 words) - time: [463.57 µs 466.12 µs 469.75 µs] + time: [457.65 µs 458.97 µs 460.24 µs] to_seed/tiny-bip39 (15 words) - time: [975.90 µs 978.51 µs 982.07 µs] + time: [970.50 µs 972.52 µs 974.72 µs] to_seed/bip39 (15 words) - time: [1.0904 ms 1.0958 ms 1.1020 ms] + time: [1.0817 ms 1.0845 ms 1.0879 ms] to_seed/coins-bip39 (15 words) - time: [1.3396 ms 1.3451 ms 1.3518 ms] + time: [1.3227 ms 1.3276 ms 1.3335 ms] to_seed/bip0039 (15 words) - time: [464.11 µs 465.92 µs 467.89 µs] + time: [457.54 µs 458.40 µs 459.30 µs] to_seed/tiny-bip39 (18 words) - time: [980.42 µs 986.43 µs 993.44 µs] + time: [968.53 µs 970.61 µs 972.99 µs] to_seed/bip39 (18 words) - time: [1.0894 ms 1.0920 ms 1.0949 ms] + time: [1.0802 ms 1.0824 ms 1.0852 ms] to_seed/coins-bip39 (18 words) - time: [1.5161 ms 1.5211 ms 1.5269 ms] + time: [1.4935 ms 1.4986 ms 1.5048 ms] to_seed/bip0039 (18 words) - time: [464.60 µs 466.42 µs 468.69 µs] + time: [457.73 µs 458.76 µs 459.74 µs] to_seed/tiny-bip39 (24 words) - time: [978.29 µs 981.81 µs 985.51 µs] + time: [968.94 µs 970.94 µs 973.23 µs] to_seed/bip39 (24 words) - time: [1.0917 ms 1.0971 ms 1.1058 ms] + time: [1.0821 ms 1.0847 ms 1.0878 ms] to_seed/coins-bip39 (24 words) - time: [1.8658 ms 1.8931 ms 1.9396 ms] + time: [1.8365 ms 1.8393 ms 1.8424 ms] to_seed/bip0039 (24 words) - time: [463.52 µs 464.72 µs 465.96 µs] + time: [457.88 µs 462.89 µs 472.78 µs] ``` diff --git a/bip0039/src/lib.rs b/bip0039/src/lib.rs index 5ac4975..504a7c1 100644 --- a/bip0039/src/lib.rs +++ b/bip0039/src/lib.rs @@ -1,54 +1,4 @@ -//! # bip0039 -//! -//! [![](https://github.com/koushiro/rust-bips/actions/workflows/bip0039.yml/badge.svg)][actions] -//! [![](https://img.shields.io/docsrs/bip0039)][docs.rs] -//! [![](https://img.shields.io/crates/v/bip0039)][crates.io] -//! [![](https://img.shields.io/crates/l/bip0039)][crates.io] -//! [![](https://img.shields.io/crates/d/bip0039.svg)][crates.io] -//! [![](https://img.shields.io/badge/MSRV-1.85.0-green?logo=rust)][whatrustisit] -//! -//! [actions]: https://github.com/koushiro/rust-bips/actions -//! [docs.rs]: https://docs.rs/bip0039 -//! [crates.io]: https://crates.io/crates/bip0039 -//! [whatrustisit]: https://www.whatrustisit.com -//! -//! Another Rust implementation of [BIP-0039](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki) standard. -//! -//! ## Usage -//! -//! ### Compile-time language selection -//! -//! ```rust -//! use bip0039::{Count, English, Mnemonic}; -//! -//! // Generate an English mnemonic with 12 words randomly -//! let mnemonic = >::generate(Count::Words12); -//! // Or use the default generic type (English). -//! let mnemonic = ::generate(Count::Words12); -//! println!("phrase: {}", mnemonic.phrase()); -//! -//! // Generate the HD wallet seed from the mnemonic and the passphrase. -//! let seed = mnemonic.to_seed(""); -//! assert_eq!(seed.len(), 64); -//! println!("seed: {}", const_hex::encode(seed)); -//! ``` -//! -//! ### Runtime language selection -//! -//! ```rust -//! use bip0039::{AnyLanguage, AnyMnemonic, BuiltInLanguage, Count, English}; -//! -//! // Generate an English mnemonic with 12 words randomly -//! let mnemonic = AnyMnemonic::generate(BuiltInLanguage::English, Count::Words12); -//! assert_eq!(mnemonic.language(), AnyLanguage::of::()); -//! println!("phrase: {}", mnemonic.phrase()); -//! -//! // Generate the HD wallet seed from the mnemonic and the passphrase. -//! let seed = mnemonic.to_seed(""); -//! assert_eq!(seed.len(), 64); -//! println!("seed: {}", const_hex::encode(seed)); -//! ``` - +#![doc = include_str!("../README.md")] #![deny(unused_imports)] #![deny(missing_docs)] #![deny(unsafe_code)]