Skip to content

Commit

Permalink
keystore/ed25519: add some unit test fixtures
Browse files Browse the repository at this point in the history
Before updating the bip32-ed25519 dep to make sure there is no
breaking change.
  • Loading branch information
benma committed Nov 13, 2023
1 parent 6ee7f36 commit 1c2277b
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/rust/bitbox02-rust/src/keystore/ed25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,32 @@ mod tests {
assert_eq!(xpub.pubkey_bytes(), b"\xab\x58\xbd\x94\x7e\x2b\xf6\x64\xa7\xc0\x66\xde\x2e\xf0\x24\x0e\xfc\x24\xf3\x6e\xfd\x50\x2d\xf8\x83\x93\xe1\x96\xaf\x3c\x91\x8e");
assert_eq!(xpub.chain_code(), b"\xf2\x00\x13\x38\x58\x02\xa6\xf9\xc0\x5e\xe7\xb0\x36\x16\xad\xf6\x9f\x5f\x9e\xc4\x32\x53\xa5\xd0\x8b\xe9\x65\x79\x81\x90\x83\xbb");
}

#[test]
fn test_get_xprv() {
bitbox02::keystore::lock();
assert!(get_xprv(&[]).is_err());

mock_unlocked();
let xprv = get_xprv(&[]).unwrap();
assert_eq!(xprv.expanded_secret_key().as_slice(), b"\xf8\xcb\x28\x85\x37\x60\x2b\x90\xd1\x29\x75\x4b\xdd\x0e\x4b\xed\xf9\xe2\x92\x3a\x04\xb6\x86\x7e\xdb\xeb\xc7\x93\xa7\x17\x6f\x5d\xca\xc5\xc9\x5d\x5f\xd2\x3a\x8e\x01\x6c\x95\x57\x69\x0e\xad\x1f\x00\x2b\x0f\x35\xd7\x06\xff\x8e\x59\x84\x1c\x09\xe0\xb6\xbb\x23");

let xprv = get_xprv(&[10 + HARDENED_OFFSET, 10]).unwrap();
assert_eq!(xprv.expanded_secret_key().as_slice(), b"\x00\x28\x46\xb1\xeb\x06\x66\xff\x4e\xf1\x66\xde\x37\x80\xdf\xe1\x95\xed\x6f\xfd\xce\x41\x18\x09\x9d\x9d\x80\x85\xaa\x17\x6f\x5d\x1f\xcf\xf9\x55\x2e\xe4\xc0\xcb\x03\xaa\x42\x1a\xe8\x2f\x98\xa0\x0a\xfc\x65\xb6\x84\x66\x31\xaa\x41\x8e\x6d\x5a\x62\x6e\x75\xf4");
}

#[test]
fn test_sign() {
let msg = &[0u8; 32];
bitbox02::keystore::lock();
assert!(sign(&[10 + HARDENED_OFFSET, 10], msg).is_err());

mock_unlocked();
let sig = sign(&[10 + HARDENED_OFFSET, 10], msg).unwrap();
assert_eq!(sig.public_key.as_ref(), b"\xab\x58\xbd\x94\x7e\x2b\xf6\x64\xa7\xc0\x66\xde\x2e\xf0\x24\x0e\xfc\x24\xf3\x6e\xfd\x50\x2d\xf8\x83\x93\xe1\x96\xaf\x3c\x91\x8e");
assert_eq!(
sig.signature,
*b"\x6c\x9b\xc4\x0e\x34\xe2\xa9\xb7\x88\x5e\xec\x72\xc0\x60\xba\x76\x9f\xe3\xa7\x4c\x9b\x14\x4b\xbf\x63\xf4\xd5\x4e\xa6\x66\x04\x31\x34\x25\x0e\xb2\x7d\xd3\x42\x28\x47\x5d\x7c\x6b\x54\x32\xd7\x37\x42\xf4\xb5\xa0\x98\xf4\x65\xba\x10\x1e\x90\xd1\x00\x35\x68\x01"
);
}
}

0 comments on commit 1c2277b

Please sign in to comment.