Skip to content
Snippets Groups Projects

Adding db persistence for all SecretFormat of vault keys as well as supporting derivations

Merged Nicolas80 requested to merge vault-db-persistence-and-derivation-support into master
Compare and
18 files
+ 3217
258
Compare changes
  • Side-by-side
  • Inline
Files
18
+ 19
39
use crate::*;
use crate::*;
use bs58;
use bs58;
 
use sp_core::ed25519::Pair as Ed25519Pair;
/// define cesium subcommands
/// define cesium subcommands
#[derive(Clone, Default, Debug, clap::Parser)]
#[derive(Clone, Default, Debug, clap::Parser)]
@@ -33,52 +34,31 @@ pub async fn handle_command(_data: Data, command: Subcommand) -> Result<(), Gcli
@@ -33,52 +34,31 @@ pub async fn handle_command(_data: Data, command: Subcommand) -> Result<(), Gcli
println!("Address (SS58): {}", address);
println!("Address (SS58): {}", address);
}
}
Subcommand::Prompt => {
Subcommand::Prompt => {
let keypair = prompt_secret_cesium();
let pair = prompt_secret_cesium();
println!("Pubkey: {}", bs58::encode(keypair.pkey).into_string());
println!(
let address: AccountId = keypair.pkey.into();
"Pubkey: {}",
 
compute_g1v1_public_key_from_ed25519_pair(&pair)?
 
);
 
let address: AccountId = pair.public().into();
println!("Address: {}", address);
println!("Address: {}", address);
}
}
}
}
Ok(())
Ok(())
}
}
pub struct CesiumSigner<T: subxt::Config> {
/// Computes G1v1 public key from a KeyPair of type sp_core::ed25519::Pair - fails otherwise
account_id: T::AccountId,
pub fn compute_g1v1_public_key(key_pair: &KeyPair) -> Result<String, GcliError> {
keypair: nacl::sign::Keypair,
match key_pair {
}
KeyPair::Sr25519(_) => Err(GcliError::Logic(
impl<T> CesiumSigner<T>
"key pair is not of type ed25519".to_string(),
where
)),
T: subxt::Config,
KeyPair::Ed25519(key_pair) => Ok(compute_g1v1_public_key_from_ed25519_pair(key_pair)?),
T::AccountId: From<[u8; 32]>,
{
pub fn new(keypair: nacl::sign::Keypair) -> Self {
Self {
account_id: T::AccountId::from(keypair.pkey),
keypair,
}
}
}
}
}
impl<T> subxt::tx::Signer<T> for CesiumSigner<T>
where
T: subxt::Config,
T::Address: From<T::AccountId>,
T::Signature: From<sp_core::ed25519::Signature>,
{
fn account_id(&self) -> T::AccountId {
self.account_id.clone()
}
fn address(&self) -> T::Address {
/// Computes G1v1 public key from an ed25519 Pair
self.account_id.clone().into()
pub fn compute_g1v1_public_key_from_ed25519_pair(
}
ed25519_key_pair: &Ed25519Pair,
) -> Result<String, GcliError> {
fn sign(&self, payload: &[u8]) -> T::Signature {
Ok(bs58::encode(ed25519_key_pair.public()).into_string())
sp_core::ed25519::Signature::from_raw(
nacl::sign::signature(payload, &self.keypair.skey)
.unwrap()
.try_into()
.expect("could not read signature"),
)
.into()
}
}
}
Loading