|
8 | 8 | use crate::error::WasmSolanaError; |
9 | 9 | use crate::transaction::{Transaction, TransactionExt}; |
10 | 10 | use crate::versioned::{detect_transaction_version, TxVersion, VersionedTransactionExt}; |
| 11 | +use crate::wasm::keypair::WasmKeypair; |
11 | 12 | use solana_message::VersionedMessage; |
12 | 13 | use solana_sdk::bs58; |
13 | 14 | use solana_transaction::versioned::VersionedTransaction; |
@@ -135,24 +136,21 @@ impl WasmTransaction { |
135 | 136 | self.inner.signer_index(pubkey) |
136 | 137 | } |
137 | 138 |
|
138 | | - /// Sign this transaction with a base58-encoded Ed25519 secret key. |
| 139 | + /// Sign this transaction with a `WasmKeypair`. |
139 | 140 | /// |
140 | | - /// Derives the public key from the secret, signs the transaction message, |
141 | | - /// and places the signature at the correct signer index. |
| 141 | + /// Signs the transaction message and places the signature at the correct |
| 142 | + /// signer index. |
142 | 143 | /// |
143 | | - /// @param secret_key_base58 - The Ed25519 secret key (32-byte seed) as base58 |
| 144 | + /// @param keypair - A WasmKeypair instance |
144 | 145 | #[wasm_bindgen] |
145 | | - pub fn sign_with_secret_key(&mut self, secret_key_base58: &str) -> Result<(), WasmSolanaError> { |
146 | | - use crate::keypair::{Keypair, KeypairExt}; |
| 146 | + pub fn sign_with_keypair(&mut self, keypair: &WasmKeypair) -> Result<(), WasmSolanaError> { |
| 147 | + use crate::keypair::KeypairExt; |
147 | 148 | use solana_signer::Signer; |
148 | 149 |
|
149 | | - let secret_bytes: Vec<u8> = bs58::decode(secret_key_base58) |
150 | | - .into_vec() |
151 | | - .map_err(|e| WasmSolanaError::new(&format!("Failed to decode secret key: {}", e)))?; |
152 | | - let keypair = Keypair::from_secret_key_bytes(&secret_bytes)?; |
| 150 | + let inner = keypair.inner(); |
153 | 151 | let message_bytes = self.inner.message.serialize(); |
154 | | - let signature = keypair.sign_message(&message_bytes); |
155 | | - let address = keypair.address(); |
| 152 | + let signature = inner.sign_message(&message_bytes); |
| 153 | + let address = inner.address(); |
156 | 154 | self.inner.add_signature(&address, signature.as_ref()) |
157 | 155 | } |
158 | 156 |
|
|
0 commit comments