Skip to content

Commit

Permalink
Fix/substrate path derivation (#82)
Browse files Browse the repository at this point in the history
* feat: evm custom network

* chore: bump version

* fix: susbtrate path derivation
  • Loading branch information
pedrxlz authored Jan 16, 2025
1 parent 30ee832 commit befcc82
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
13 changes: 13 additions & 0 deletions packages/kos/src/chains/substrate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,19 @@ mod test {
let addr = dot.get_address(pbk).unwrap();
assert_eq!(addr, "13KVd4f2a4S5pLp4gTTFezyXdPWx27vQ9vS6xBXJ9yWVd7xo");
}
#[test]
fn test_get_addr1() {
let dot = super::Substrate::new(62, 42, "AVAIL", "Avail");

let mnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about".to_string();
let path = dot.get_path(1, false);

let seed = dot.mnemonic_to_seed(mnemonic, String::from("")).unwrap();
let pvk = dot.derive(seed, path).unwrap();
let pbk = dot.get_pbk(pvk).unwrap();
let addr = dot.get_address(pbk).unwrap();
assert_eq!(addr, "5DJ8y4CAHnmjt4rdoZpR1wgXnQDnKDksskx7JTphZhMxthiG");
}

#[test]
fn test_sign_raw() {
Expand Down
8 changes: 4 additions & 4 deletions packages/kos/src/crypto/bip32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,10 @@ pub fn derive_sr25519(input_key: &[u8], mut path: String) -> Result<[u8; 64], Bi
.strip_prefix("//")
.ok_or(Bip32Err::PathError)?
.to_string();
path = path
.strip_suffix("///")
.ok_or(Bip32Err::PathError)?
.to_string();

if let Some(stripped) = path.strip_suffix("///") {
path = stripped.to_string();
}

let chaincode_value = u8::from_str(path.as_str()).map_err(|_| Bip32Err::PathError)?;

Expand Down

0 comments on commit befcc82

Please sign in to comment.