Skip to content

Commit 7b9adc2

Browse files
committed
release
1 parent ea7725a commit 7b9adc2

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ keywords = [ "crypto", "bitcoin" ]
1111
readme = "README.md"
1212

1313
[dependencies]
14-
bitcoin = { git= "https://github.com/tamasblummer/rust-bitcoin.git", branch = "patches", features=["serde"]}
14+
bitcoin = { version= "0.21.0", features=["serde"]}
1515
bitcoin_hashes={version="0.7", features=["serde"]}
1616
secp256k1 = "0.15"
1717
rand="0.7"
@@ -20,6 +20,6 @@ serde = "1"
2020
serde_derive = "1"
2121

2222
[dev-dependencies]
23-
bitcoin = { git= "https://github.com/tamasblummer/rust-bitcoin.git", branch = "patches", features=["serde", "bitcoinconsensus"]}
23+
bitcoin = { version= "0.21.0", features=["serde", "bitcoinconsensus"]}
2424
serde_json="1"
2525
hex = "0.3"

README.md

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,27 @@ It supports legacy P2PKH, transitional P2SHWPKH and native segwit P2WPKH for sin
1111
and native P2WSH for arbitrary sripts.
1212

1313
## Basic Accounts Use
14+
`MasterAccount` holds an encrypted seed that implies the BIP32 root key. Add any number of `Account` to it to derive
15+
hiararchies following BIP44. An Account will have addresses of a uniform type.
1416
```
1517
const PASSPHRASE: &str = "correct horse battery staple";
1618
1719
// create a new random master account. This holds the root BIP32 key
18-
let mut master = MasterAccount::new(MasterKeyEntropy::Low, Network::Bitcoin, PASSPHRASE, None).unwrap();
20+
// PASSPHRASE is used to encrypt the seed in memory and in storage
21+
let mut master = MasterAccount::new(MasterKeyEntropy::Low, Network::Bitcoin, PASSPHRASE).unwrap();
1922
2023
// or re-create a master from a known mnemonic
2124
let words = "announce damage viable ticket engage curious yellow ten clock finish burden orient faculty rigid smile host offer affair suffer slogan mercy another switch park";
2225
let mnemonic = Mnemonic::from_str(words).unwrap();
26+
// PASSPHRASE is used to encrypt the seed in memory and in storage
27+
// last argument is option password for plausible deniability
2328
let mut master = MasterAccount::from_mnemonic(&mnemonic, 0, Network::Bitcoin, PASSPHRASE, None).unwrap();
2429
25-
// or re-create a master from encrypted storage that holds AES encrypted mnemonic, master public key and the birth time point of the key (seconds in Unix epoch)
26-
let mut master = MasterAccount::from_encrypted(
27-
hex::decode("0e05ba48bb0fdc7285dc9498202aeee5e1777ac4f55072b30f15f6a8632ad0f3fde1c41d9e162dbe5d3153282eaebd081cf3b3312336fc56f5dd18a2df6ea48c1cdd11a1ed11281cd2e0f864f02e5bed5ab03326ed24e43b8a184acff9cb4e730db484e33f2b24295a97b2ca87871a69384eb64d4160ce8b3e8b4d90234040970e531d4333a8979dbe533c2b2668bf43b6607b2d24c5b42765ebfdd075fd173c").unwrap().as_slice(),
28-
ExtendedPubKey::from_str("tpubD6NzVbkrYhZ4XKz4vgwBmnnVmA7EgWhnXvimQ4krq94yUgcSSbroi4uC1xbZ3UGMxG9M2utmaPjdpMrWW2uKRY9Mj4DZWrrY8M4pry8shsK").unwrap(),
29-
1567260002);
30-
3130
// The master accounts only store public keys
32-
// Private keys are created on-demand with an Unlocker and forgotten as soon as possible
31+
// Private keys are created on-demand from encrypted seed with an Unlocker and forgotten as soon as possible
3332
3433
// create an unlocker that is able to decrypt the encrypted mnemonic and then calculate private keys
35-
let mut unlocker = Unlocker::new_for_master(&master, PASSPHRASE, None).unwrap();
34+
let mut unlocker = Unlocker::new_for_master(&master, PASSPHRASE).unwrap();
3635
3736
// The unlocker is needed to create accounts within the master account as
3837
// key derivation follows BIP 44, which requires private key derivation
@@ -164,4 +163,25 @@ coins.unwind_tip(block_hash);
164163
// choose inputs to spend
165164
let inputs = choose_inputs (minimum_amount_needed, current_block_height, |h| height_of_block(h));
166165
166+
```
167+
## Shamir's Secret Shares
168+
```
169+
// create an new random account
170+
let master = MasterAccount::new(MasterKeyEntropy::Low, Network::Bitcoin, PASSPHRASE).unwrap();
171+
172+
// extract seed
173+
let seed = master.seed(Network::Bitcoin, PASSPHRASE).unwrap();
174+
175+
// cut seed into 5 shares such that any 3 of them is sufficient to re-construct
176+
let shares = ShamirSecretSharing::generate(1, &[(3,5)], &seed, None, 1).unwrap();
177+
178+
// re-construct seed from the first 3
179+
let reconstructed_seed = ShamirSecretSharing::combine(&shares[..3], None).unwrap();
180+
181+
// re-construct master from seed
182+
let reconstructed_master = MasterAccount::from_seed(&reconstructed_seed, 0, Network::Bitcoin, PASSPHRASE).unwrap();
183+
184+
// prove that everything went fine
185+
assert_eq!(master.master_public(), reconstructed_master.master_public());
186+
assert_eq!(master.encrypted(), reconstructed_master.encrypted());
167187
```

0 commit comments

Comments
 (0)