-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add NIP-06 test. * Separate out keys tests. Add taproot test to sanity-check wallet-generated addresses and descriptors. * Fix Nostr NIP-06 key derivation.
- Loading branch information
1 parent
4e2d831
commit 2c7f48e
Showing
3 changed files
with
93 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#![cfg(not(target_arch = "wasm32"))] | ||
|
||
use anyhow::Result; | ||
use bitmask_core::{ | ||
bitcoin::{get_wallet_data, save_mnemonic}, | ||
constants::switch_network, | ||
structs::SecretString, | ||
util::init_logging, | ||
}; | ||
|
||
#[tokio::test] | ||
pub async fn taproot() -> Result<()> { | ||
init_logging("nostr_tests=debug"); | ||
|
||
const MNEMONIC: &str = | ||
"empty faculty salute fortune select asthma attract question violin movie smile erupt half step lion deposit render stumble double mobile fossil height usual topple"; | ||
|
||
switch_network("bitcoin").await?; | ||
|
||
let decrypted_wallet = save_mnemonic( | ||
&SecretString(MNEMONIC.to_owned()), | ||
&SecretString("".to_owned()), | ||
) | ||
.await?; | ||
|
||
let wallet_data = get_wallet_data( | ||
&SecretString(decrypted_wallet.public.btc_descriptor_xpub.to_owned()), | ||
None, | ||
) | ||
.await?; | ||
|
||
// Compare to those generated by Sparrow Wallet | ||
assert_eq!( | ||
decrypted_wallet.public.btc_descriptor_xpub, | ||
"tr([496f1ccc/86'/0'/0']xpub6CBkARCPxmbRjaxzHxC38e9sKUVtMTRFqBYUFdXAHFBpeQzJz6mYSaQ1qSvCrNzYUNuvpD9FS6fmK9YowdCxaiCUSpjzNm5hvV2JxEodZ1q/0/*)", | ||
"correct taproot xpub descriptor is derived from mnemonic" | ||
); | ||
|
||
assert_eq!( | ||
wallet_data.address, "bc1pljwytlvv9n8ug5e7cxrjrfmhudd2w7r0nmdpt7j0387mc0zzpveq6jeqs6", | ||
"correct first address is derived" | ||
); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[tokio::test] | ||
pub async fn nip06() -> Result<()> { | ||
init_logging("nostr_tests=debug"); | ||
|
||
// Using this tool: | ||
// https://nip06.jaonoct.us | ||
|
||
const MNEMONIC: &str = | ||
"garment castle exhaust confirm wrong timber earth invest output comfort actress slot"; | ||
|
||
let wallet_data = save_mnemonic( | ||
&SecretString(MNEMONIC.to_owned()), | ||
&SecretString("".to_owned()), | ||
) | ||
.await?; | ||
|
||
assert_eq!( | ||
wallet_data.private.nostr_nsec, | ||
"nsec1t9s9xyu55mezxwkf98uws2m8h6smjvehgngme0346rwm456g3kfs8pt0qw", | ||
"correct nsec is generated" | ||
); | ||
assert_eq!( | ||
wallet_data.public.nostr_npub, | ||
"npub1v5zwxyd3dtmrvgnamxxlfxj92t52hwkg09dmwjhmkjujkq8kdzms77547c", | ||
"correct npub is generated" | ||
); | ||
|
||
Ok(()) | ||
} |