Trait sp_core::crypto::Derive

source ·
pub trait Derive: Sized {
    fn derive<Iter: Iterator<Item = DeriveJunction>>(
        &self,
        _path: Iter
    ) -> Option<Self> { ... } }
Expand description

Derivable key trait.

Provided Methods§

Derive a child key from a series of given junctions.

Will be None for public keys if there are any hard junctions in there.

Examples found in repository?
src/crypto.rs (line 434)
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
	fn from_string(s: &str) -> Result<Self, PublicError> {
		let cap = SS58_REGEX.captures(s).ok_or(PublicError::InvalidFormat)?;
		let s = cap.name("ss58").map(|r| r.as_str()).unwrap_or(DEV_ADDRESS);
		let addr = if let Some(stripped) = s.strip_prefix("0x") {
			let d = array_bytes::hex2bytes(stripped).map_err(|_| PublicError::InvalidFormat)?;
			Self::from_slice(&d).map_err(|()| PublicError::BadLength)?
		} else {
			Self::from_ss58check(s)?
		};
		if cap["path"].is_empty() {
			Ok(addr)
		} else {
			let path =
				JUNCTION_REGEX.captures_iter(&cap["path"]).map(|f| DeriveJunction::from(&f[1]));
			addr.derive(path).ok_or(PublicError::InvalidPath)
		}
	}

	fn from_string_with_version(s: &str) -> Result<(Self, Ss58AddressFormat), PublicError> {
		let cap = SS58_REGEX.captures(s).ok_or(PublicError::InvalidFormat)?;
		let (addr, v) = Self::from_ss58check_with_version(
			cap.name("ss58").map(|r| r.as_str()).unwrap_or(DEV_ADDRESS),
		)?;
		if cap["path"].is_empty() {
			Ok((addr, v))
		} else {
			let path =
				JUNCTION_REGEX.captures_iter(&cap["path"]).map(|f| DeriveJunction::from(&f[1]));
			addr.derive(path).ok_or(PublicError::InvalidPath).map(|a| (a, v))
		}
	}

Implementors§