Skip to content

Commit

Permalink
Merge branch 'keypath-seq'
Browse files Browse the repository at this point in the history
  • Loading branch information
benma committed Jun 3, 2024
2 parents fd02ba4 + 0acf2d6 commit 74758b9
Show file tree
Hide file tree
Showing 8 changed files with 292 additions and 248 deletions.
490 changes: 253 additions & 237 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ hidapi = { version = "2.3", optional = true }
js-sys = { version = "0.3.64", optional = true }
rlp = { version = "0.5", optional = true }
serde = { version = "1.0", features = ["derive"] }
serde-wasm-bindgen = { version = "0.5.0", optional = true }
serde-wasm-bindgen = { version = "0.6.5", optional = true }
tokio = { version = "1", optional = true, features = ["time"] }
wasm-bindgen = { version = "0.2.63", optional = true }
wasm-bindgen-futures = { version ="0.4.37", optional = true }
wasm-bindgen = { version = "0.2.92", optional = true }
wasm-bindgen-futures = { version ="0.4.42", optional = true }
web-sys = { version = "0.3.64", features = ["Storage", "Window"], optional = true }

[dev-dependencies]
wasm-bindgen-test = "0.3.13"
wasm-bindgen-test = "0.3.42"

[build-dependencies]
prost-build = { version = "0.11" }
Expand Down
2 changes: 1 addition & 1 deletion NPM_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.3.2
0.4.0
4 changes: 2 additions & 2 deletions ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ cargo fmt --check
for feature_set in "${features[@]}"; do
echo $feature_set
cargo test --locked --features="$feature_set" --all-targets
cargo clippy --locked --features="$feature_set" --all-targets -- -D warnings
cargo clippy --locked --features="$feature_set" --all-targets -- -D warnings -A clippy::empty-docs
done

for example in "${examples[@]}"; do
cargo test $example
cargo clippy $example -- -D warnings
cargo clippy $example -- -D warnings -A clippy::empty-docs
done
2 changes: 1 addition & 1 deletion sandbox/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/communication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ pub enum Product {
pub struct Info {
pub version: semver::Version,
pub product: Product,
#[allow(dead_code)]
pub unlocked: bool,
}

Expand Down
31 changes: 29 additions & 2 deletions src/keypath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,35 @@ impl<'de> serde::Deserialize<'de> for Keypath {
where
D: serde::Deserializer<'de>,
{
let s = String::deserialize(deserializer)?;
s.as_str().try_into().map_err(serde::de::Error::custom)
struct KeypathVisitor;

impl<'de> serde::de::Visitor<'de> for KeypathVisitor {
type Value = Keypath;

fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
formatter.write_str("a string or a number sequence")
}

fn visit_str<E>(self, value: &str) -> Result<Self::Value, E>
where
E: serde::de::Error,
{
value.try_into().map_err(serde::de::Error::custom)
}

fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
where
A: serde::de::SeqAccess<'de>,
{
let mut vec = Vec::<u32>::new();
while let Some(elem) = seq.next_element()? {
vec.push(elem);
}
Ok(Keypath(vec))
}
}

deserializer.deserialize_any(KeypathVisitor)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/wasm/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type Product = 'unknown' | 'bitbox02-multi' | 'bitbox02-btconly';
type BtcCoin = 'btc' | 'tbtc' | 'ltc' | 'tltc';
type BtcFormatUnit = 'default' | 'sat';
type XPubType = 'tpub' | 'xpub' | 'ypub' | 'zpub' | 'vpub' | 'upub' | 'Vpub' | 'Zpub' | 'Upub' | 'Ypub';
type Keypath = string;
type Keypath = string | number[];
type XPub = string;
type DeviceInfo = {
name: string;
Expand Down

0 comments on commit 74758b9

Please sign in to comment.