Skip to content

Commit

Permalink
refactor: archive unmaintained packages
Browse files Browse the repository at this point in the history
major: remove error from mnemonic interface
  • Loading branch information
prestwich committed Jan 12, 2023
1 parent db28df1 commit d0bafb5
Show file tree
Hide file tree
Showing 70 changed files with 58 additions and 48 deletions.
10 changes: 0 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,5 @@ members = [
"core",
"bip32",
"bip39",
"bitcoins",
"litecoins",
"handshakes",
"ledger",
"ledger-btc",
"provider",
]

exclude = [
"ledger", # Excluded until we can figure out how to build hidapi on travis
"ledger-btc", # Excluded until we can figure out how to build hidapi on travis
]
File renamed without changes.
5 changes: 5 additions & 0 deletions archive/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## Archived coins packages

These packages are deprecated and are not maintained going forward.

If you would like to take over these packages, please DM me on twitter.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ mod test {
}
}

#[allow(unused_must_use)]
#[test]
#[allow(unused_must_use)]
fn it_converts_between_bitcoin_script_types() {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
59 changes: 51 additions & 8 deletions bip39/src/mnemonic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,57 @@ use thiserror::Error;
const PBKDF2_ROUNDS: u32 = 2048;
const PBKDF2_BYTES: usize = 64;

pub struct Words12;
pub struct Words15;
pub struct Words18;
pub struct Words21;
pub struct Words24;

pub trait WordCount {
const COUNT: usize;
const ENTROPY_BYTES: usize;
}

impl WordCount for Words12 {
const COUNT: usize = 12;
const ENTROPY_BYTES: usize = 128;
}

impl WordCount for Words15 {
const COUNT: usize = 15;
const ENTROPY_BYTES: usize = 160;
}

impl WordCount for Words18 {
const COUNT: usize = 18;
const ENTROPY_BYTES: usize = 192;
}

impl WordCount for Words21 {
const COUNT: usize = 21;
const ENTROPY_BYTES: usize = 224;
}

impl WordCount for Words24 {
const COUNT: usize = 24;
const ENTROPY_BYTES: usize = 256;
}

/// Mnemonic represents entropy that can be represented as a phrase. A mnemonic can be used to
/// deterministically generate an extended private key or derive its child keys.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Mnemonic<W: Wordlist> {
pub struct Mnemonic<W, /*C*/>
where
W: Wordlist,
// C: WordCount,
{
/// Entropy used to generate mnemonic.
entropy: Vec<u8>,
// entropy: [u8; C::ENTROPY_BYTES],
/// Wordlist used to produce phrases from entropy.
_wordlist: PhantomData<W>,
// /// Number of words in the mnemonic
// _word_count: PhantomData<C>,
}

#[derive(Debug, Error)]
Expand Down Expand Up @@ -99,15 +142,15 @@ impl<W: Wordlist> Mnemonic<W> {
};

// Ensures the checksum word matches the checksum word in the given phrase.
match phrase == mnemonic.to_phrase()? {
match phrase == mnemonic.to_phrase() {
true => Ok(mnemonic),
false => Err(MnemonicError::InvalidPhrase(phrase.into())),
}
}

/// Converts the mnemonic into phrase.
pub fn to_phrase(&self) -> Result<String, MnemonicError> {
let length = self.word_count()?;
pub fn to_phrase(&self) -> String {
let length = self.word_count().expect("always valid in memory");

// Compute checksum. Checksum is the most significant (ENTROPY_BYTES/4) bits. That is also
// equivalent to (WORD_COUNT/3).
Expand Down Expand Up @@ -137,7 +180,7 @@ impl<W: Wordlist> Mnemonic<W> {
})
.collect::<Vec<&str>>();

Ok(phrase.join(" "))
phrase.join(" ")
}

fn word_count(&self) -> Result<usize, MnemonicError> {
Expand Down Expand Up @@ -174,7 +217,7 @@ impl<W: Wordlist> Mnemonic<W> {
let mut seed = vec![0u8; PBKDF2_BYTES];
let salt = format!("mnemonic{}", password.unwrap_or(""));
pbkdf2::<Hmac<Sha512>>(
self.to_phrase()?.as_bytes(),
self.to_phrase().as_bytes(),
salt.as_bytes(),
PBKDF2_ROUNDS,
&mut seed,
Expand Down Expand Up @@ -382,7 +425,7 @@ mod tests {
let expected_entropy: Vec<u8> = hex::decode(entropy_str).unwrap();
let mnemonic = Mnemonic::<W>::new_from_phrase(phrase).unwrap();
assert_eq!(mnemonic.entropy, expected_entropy);
assert_eq!(mnemonic.to_phrase().unwrap(), phrase.to_string());
assert_eq!(mnemonic.to_phrase(), phrase.to_string());
})
}

Expand All @@ -397,7 +440,7 @@ mod tests {
_wordlist: PhantomData,
};
assert_eq!(mnemonic.entropy, entropy);
assert_eq!(mnemonic.to_phrase().unwrap(), expected_phrase.to_string())
assert_eq!(mnemonic.to_phrase(), expected_phrase.to_string())
})
}

Expand Down
25 changes: 0 additions & 25 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,8 @@ cargo --verbose build
cargo --verbose build --no-default-features
cargo --verbose build --target wasm32-unknown-unknown

### Bitcoins ###
cd ../bitcoins
cargo --verbose build --target wasm32-unknown-unknown

# default features covered by workspace-level tests
cargo test --verbose

### Provider ###
cd ../provider
cargo --verbose build
cargo --verbose build --no-default-features --features="mainnet"
cargo build --target wasm32-unknown-unknown

### Ledger ###
cd ../ledger
# # broken on travis
# cargo build --verbose
cargo build --verbose --target wasm32-unknown-unknown --no-default-features --features="browser"

### Ledger bitcoins ###
cd ../ledger-btc
# # broken on travis
# cargo build --verbose
cargo build --verbose --target wasm32-unknown-unknown --no-default-features --features="browser"

### HANDSHAKE ###
cd ../handshakes
cargo build --verbose
cargo test --verbose --lib
cargo --verbose build --target wasm32-unknown-unknown
2 changes: 1 addition & 1 deletion ledger/src/transports/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ extern "C" {

// `transport.exchange(apdu: Buffer): Promise<Buffer>`
//
// Seed [here](https://github.com/LedgerHQ/ledgerjs#an-unified-transport-interface)
// See [here](https://github.com/LedgerHQ/ledgerjs#an-unified-transport-interface)
#[wasm_bindgen(method)]
fn exchange(t: &Transport, buf: &[u8]) -> js_sys::Promise;
}
Expand Down
4 changes: 0 additions & 4 deletions release.toml

This file was deleted.

0 comments on commit d0bafb5

Please sign in to comment.