pub trait Signer {
// Required methods
fn try_pubkey(&self) -> Result<Address, SignerError>;
fn try_sign_message(&self, message: &[u8]) -> Result<Signature, SignerError>;
fn is_interactive(&self) -> bool;
// Provided methods
fn pubkey(&self) -> Address { ... }
fn sign_message(&self, message: &[u8]) -> Signature { ... }
}Expand description
The Signer trait declares operations that all digital signature providers
must support. It is the primary interface by which signers are specified in
Transaction signing interfaces
Required Methods§
Sourcefn try_pubkey(&self) -> Result<Address, SignerError>
fn try_pubkey(&self) -> Result<Address, SignerError>
Fallibly gets the implementor’s public key
Sourcefn try_sign_message(&self, message: &[u8]) -> Result<Signature, SignerError>
fn try_sign_message(&self, message: &[u8]) -> Result<Signature, SignerError>
Fallibly produces an Ed25519 signature over the provided message bytes.
Sourcefn is_interactive(&self) -> bool
fn is_interactive(&self) -> bool
Whether the implementation requires user interaction to sign
Provided Methods§
Sourcefn pubkey(&self) -> Address
fn pubkey(&self) -> Address
Infallibly gets the implementor’s public key. Returns the all-zeros
Pubkey if the implementor has none.
Examples found in repository?
examples/test_decrypt.rs (line 81)
7fn main() {
8 let args: Vec<String> = std::env::args().collect();
9 let password = if args.len() >= 2 {
10 args[1].clone()
11 } else {
12 eprintln!("Usage: cargo run -p sol-safekey --example test_decrypt <password>");
13 std::process::exit(1);
14 };
15
16 let keystore_path = if args.len() >= 3 {
17 args[2].clone()
18 } else {
19 "config/dev/keystore.json".to_string()
20 };
21
22 let content = std::fs::read_to_string(&keystore_path)
23 .unwrap_or_else(|e| {
24 eprintln!("Failed to read {}: {}", keystore_path, e);
25 std::process::exit(1);
26 });
27
28 let data: serde_json::Value = serde_json::from_str(&content).unwrap();
29 let encrypted = data["encrypted_private_key"].as_str().unwrap();
30 let pubkey = data["public_key"].as_str().unwrap();
31
32 eprintln!("Keystore: {}", keystore_path);
33 eprintln!("Public key: {}", pubkey);
34 eprintln!("Password len: {}", password.len());
35
36 let key = generate_encryption_key_simple(&password);
37 eprintln!("Encryption key: {:02x}{:02x}{:02x}{:02x}...", key[0], key[1], key[2], key[3]);
38
39 match decrypt_key_to_bytes(encrypted, &key) {
40 Ok(bytes) => {
41 let preview: Vec<String> = bytes.iter().take(16).map(|b| format!("{:02x}", b)).collect();
42 eprintln!("Decrypted {} bytes, first 16: {}", bytes.len(), preview.join(" "));
43 eprintln!("is_ascii: {}", bytes.iter().all(|b| b.is_ascii()));
44 eprintln!("is_utf8: {}", String::from_utf8(bytes.clone()).is_ok());
45
46 // Check if it looks like base58
47 let all_base58 = bytes.iter().all(|b| {
48 let c = *b as char;
49 c.is_ascii() && (
50 c >= '1' && c <= '9' ||
51 c >= 'A' && c <= 'H' ||
52 c >= 'J' && c <= 'N' ||
53 c >= 'P' && c <= 'Z' ||
54 c >= 'a' && c <= 'z'
55 )
56 });
57 eprintln!("all_base58_chars: {}", all_base58);
58 }
59 Err(e) => eprintln!("decrypt_key_to_bytes failed: {}", e),
60 }
61
62 // Also try with trimmed password
63 let trimmed = password.trim();
64 if trimmed != password {
65 eprintln!("\n--- Trying trimmed password (len={}) ---", trimmed.len());
66 let key2 = generate_encryption_key_simple(trimmed);
67 eprintln!("Encryption key: {:02x}{:02x}{:02x}{:02x}...", key2[0], key2[1], key2[2], key2[3]);
68
69 match decrypt_key_to_bytes(encrypted, &key2) {
70 Ok(bytes) => {
71 let preview: Vec<String> = bytes.iter().take(16).map(|b| format!("{:02x}", b)).collect();
72 eprintln!("Decrypted {} bytes, first 16: {}", bytes.len(), preview.join(" "));
73 eprintln!("is_ascii: {}", bytes.iter().all(|b| b.is_ascii()));
74 eprintln!("is_utf8: {}", String::from_utf8(bytes.clone()).is_ok());
75 }
76 Err(e) => eprintln!("decrypt failed: {}", e),
77 }
78
79 match KeyManager::keypair_from_encrypted_json(&content, trimmed) {
80 Ok(kp) => {
81 println!("SUCCESS with trimmed! keypair: {}", kp.pubkey());
82 if kp.pubkey().to_string() == pubkey {
83 println!("Public key MATCHES!");
84 }
85 }
86 Err(e) => eprintln!("keypair_from_encrypted_json (trimmed) failed: {}", e),
87 }
88 }
89
90 match KeyManager::keypair_from_encrypted_json(&content, &password) {
91 Ok(kp) => {
92 println!("SUCCESS! keypair: {}", kp.pubkey());
93 if kp.pubkey().to_string() == pubkey {
94 println!("Public key MATCHES!");
95 } else {
96 println!("WARNING: mismatch! expected {}", pubkey);
97 }
98 }
99 Err(e) => eprintln!("keypair_from_encrypted_json failed: {}", e),
100 }
101}Sourcefn sign_message(&self, message: &[u8]) -> Signature
fn sign_message(&self, message: &[u8]) -> Signature
Infallibly produces an Ed25519 signature over the provided message
bytes. Returns the all-zeros Signature if signing is not possible.
Trait Implementations§
impl Eq for dyn Signer
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".