Subkey can construct and sign transfer txs (#2109)

* First effort

* Fix for encoding

* !fixed subkey xfer creation (still brittle because of double-hardcoded genesis_hash (#2221)

* CLI genesis hash

* Add test

* Slightly nicer text

* Fix Elm hash

* Update lock file
This commit is contained in:
Gavin Wood
2019-04-24 12:23:59 +02:00
committed by GitHub
parent bf9d7957d8
commit babe638be7
5 changed files with 123 additions and 7 deletions
+16 -6
View File
@@ -215,7 +215,9 @@ pub trait Derive: Sized {
/// Derive a child key from a series of given junctions.
///
/// Will be `None` for public keys if there are any hard junctions in there.
fn derive<Iter: Iterator<Item=DeriveJunction>>(&self, _path: Iter) -> Option<Self> { None }
fn derive<Iter: Iterator<Item=DeriveJunction>>(&self, _path: Iter) -> Option<Self> {
None
}
}
#[cfg(feature = "std")]
@@ -266,11 +268,19 @@ impl<T: AsMut<[u8]> + AsRef<[u8]> + Default + Derive> Ss58Codec for T {
let cap = re.captures(s).ok_or(PublicError::InvalidFormat)?;
let re_junction = Regex::new(r"/(/?[^/]+)")
.expect("constructed from known-good static value; qed");
let path = re_junction.captures_iter(&cap["path"])
.map(|f| DeriveJunction::from(&f[1]));
Self::from_ss58check(cap.name("ss58").map(|r| r.as_str()).unwrap_or(DEV_ADDRESS))?
.derive(path)
.ok_or(PublicError::InvalidPath)
let addr = Self::from_ss58check(
cap.name("ss58")
.map(|r| r.as_str())
.unwrap_or(DEV_ADDRESS)
)?;
if cap["path"].is_empty() {
Ok(addr)
} else {
let path = re_junction.captures_iter(&cap["path"])
.map(|f| DeriveJunction::from(&f[1]));
addr.derive(path)
.ok_or(PublicError::InvalidPath)
}
}
}