-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(common): add a route /info for operator public key
- Loading branch information
Showing
3 changed files
with
26 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright 2023-, GraphOps and Semiotic Labs. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use ethers::signers::{ | ||
coins_bip39::English, LocalWallet, MnemonicBuilder, Signer, Wallet, WalletError, | ||
}; | ||
use ethers_core::k256::ecdsa::SigningKey; | ||
|
||
/// Build Wallet from Private key or Mnemonic | ||
pub fn build_wallet(value: &str) -> Result<Wallet<SigningKey>, WalletError> { | ||
value | ||
.parse::<LocalWallet>() | ||
.or(MnemonicBuilder::<English>::default().phrase(value).build()) | ||
} | ||
|
||
// Format public key to a String | ||
pub fn public_key(value: &str) -> Result<String, WalletError> { | ||
let wallet = build_wallet(value)?; | ||
let addr = format!("{:?}", wallet.address()); | ||
Ok(addr) | ||
} |
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