Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
use crate::*;
use bs58;
/// define cesium subcommands
#[derive(Clone, Default, Debug, clap::Parser)]
pub enum Subcommand {
// Nothing
#[default]
#[clap(hide = true)]
Nothing,
/// Generate key pair with old style unsafe scrypt
Pubkey { id: String, pass: String },
/// Prompt
Prompt,
}
/// handle blockchain commands
pub async fn handle_command(_data: Data, command: Subcommand) -> Result<(), GcliError> {
match command {
Subcommand::Nothing => {}
Subcommand::Pubkey { id, pass } => {
let keypair = pair_from_cesium(id, pass);
println!(
"Pubkey: {}",
bs58::encode(keypair.pkey).into_string()
);
}
Subcommand::Prompt => {
let keypair = prompt_secret_cesium();
println!(
"Pubkey: {}",
bs58::encode(keypair.pkey).into_string()
);
}
}
Ok(())
}
pub struct CesiumSigner<T: subxt::Config> {
account_id: T::AccountId,
keypair: nacl::sign::Keypair,
}
impl<T> CesiumSigner<T>
where
T: subxt::Config,
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 {
self.account_id.clone().into()
}
fn sign(&self, payload: &[u8]) -> T::Signature {
sp_core::ed25519::Signature(
nacl::sign::signature(payload, &self.keypair.skey)
.unwrap()
.try_into()
.expect("could not read signature"),
)
.into()
}
}