-
Notifications
You must be signed in to change notification settings - Fork 140
P2pk receive wallet #1466
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
P2pk receive wallet #1466
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6d840d5
p2pk deterministic generation
lescuer97 8dfa437
fmt
lescuer97 4e2a515
PR fixes
lescuer97 709ab36
add wallet trait
lescuer97 d390d56
add functions to trait
lescuer97 e054296
change how P2PK generation works
lescuer97 95c6baa
remove the public nature of P2PK
lescuer97 cb9f89a
comment the purpose
lescuer97 2361f07
fix pr comments
lescuer97 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,44 @@ | ||
| use std::str::FromStr; | ||
|
|
||
| use anyhow::Result; | ||
| use cdk::mint_url::MintUrl; | ||
| use cdk::nuts::CurrencyUnit; | ||
| use cdk::wallet::WalletRepository; | ||
| use clap::Args; | ||
|
|
||
| use crate::utils::get_or_create_wallet; | ||
|
|
||
| #[derive(Args)] | ||
| pub struct GeneratePublicKeySubCommand { | ||
| /// Mint URL to select wallet context | ||
| #[arg(long)] | ||
| mint_url: Option<String>, | ||
| } | ||
|
|
||
| pub async fn generate_public_key( | ||
| wallet_repository: &WalletRepository, | ||
| sub_command_args: &GeneratePublicKeySubCommand, | ||
| unit: &CurrencyUnit, | ||
| ) -> Result<()> { | ||
| let mint_url = match &sub_command_args.mint_url { | ||
| Some(url) => MintUrl::from_str(url)?, | ||
| None => { | ||
| let wallets = wallet_repository.get_wallets().await; | ||
| wallets | ||
| .iter() | ||
| .find(|wallet| &wallet.unit == unit) | ||
| .map(|wallet| wallet.mint_url.clone()) | ||
| .ok_or_else(|| { | ||
| anyhow::anyhow!("No wallet found for unit {}. Use --mint-url.", unit) | ||
| })? | ||
| } | ||
| }; | ||
|
|
||
| let wallet = get_or_create_wallet(wallet_repository, &mint_url, unit).await?; | ||
| let public_key = wallet.generate_public_key().await?; | ||
|
|
||
| println!("\npublic key generated!\n"); | ||
| println!("public key: {}", public_key.to_hex()); | ||
|
|
||
| Ok(()) | ||
| } |
This file contains hidden or 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,70 @@ | ||
| use std::str::FromStr; | ||
|
|
||
| use anyhow::Result; | ||
| use cdk::mint_url::MintUrl; | ||
| use cdk::nuts::CurrencyUnit; | ||
| use cdk::wallet::WalletRepository; | ||
| use clap::Args; | ||
|
|
||
| use crate::utils::get_or_create_wallet; | ||
|
|
||
| #[derive(Args)] | ||
| pub struct GetPublicKeysSubCommand { | ||
| /// Show the latest public key | ||
| #[arg(long)] | ||
| pub latest: bool, | ||
| /// Mint URL to select wallet context | ||
| #[arg(long)] | ||
| mint_url: Option<String>, | ||
| } | ||
|
|
||
| pub async fn get_public_keys( | ||
| wallet_repository: &WalletRepository, | ||
| sub_command_args: &GetPublicKeysSubCommand, | ||
| unit: &CurrencyUnit, | ||
| ) -> Result<()> { | ||
| let mint_url = match &sub_command_args.mint_url { | ||
| Some(url) => MintUrl::from_str(url)?, | ||
| None => { | ||
| let wallets = wallet_repository.get_wallets().await; | ||
| wallets | ||
| .iter() | ||
| .find(|wallet| &wallet.unit == unit) | ||
| .map(|wallet| wallet.mint_url.clone()) | ||
| .ok_or_else(|| { | ||
| anyhow::anyhow!("No wallet found for unit {}. Use --mint-url.", unit) | ||
| })? | ||
| } | ||
| }; | ||
|
|
||
| let wallet = get_or_create_wallet(wallet_repository, &mint_url, unit).await?; | ||
|
|
||
| if sub_command_args.latest { | ||
| let latest_public_key = wallet.get_latest_public_key().await?; | ||
|
|
||
| match latest_public_key { | ||
| Some(key) => { | ||
| println!("\npublic key found!\n"); | ||
|
|
||
| println!("public key: {}", key.pubkey.to_hex()); | ||
| println!("derivation path: {}", key.derivation_path); | ||
| } | ||
| None => { | ||
| println!("\npublic key not found!\n"); | ||
| } | ||
| } | ||
|
|
||
| return Ok(()); | ||
| } | ||
|
|
||
| let list_public_keys = wallet.get_public_keys().await?; | ||
| if list_public_keys.is_empty() { | ||
| println!("\npublic not found!\n"); | ||
| } | ||
| println!("\npublic keys found:\n"); | ||
| for public_key in list_public_keys { | ||
|
lescuer97 marked this conversation as resolved.
|
||
| println!("public key: {}", public_key.pubkey.to_hex()); | ||
| println!("derivation path: {}", public_key.derivation_path); | ||
| } | ||
| Ok(()) | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.