Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions packages/wasm-solana/js/keypair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,6 @@ export class Keypair {
return this._wasm.address();
}

/**
* Get the public key as a base58 string
* @returns The public key as a base58 string
*/
toBase58(): string {
return this._wasm.to_base58();
}

/**
* Sign a message with this keypair
* @param message - The message bytes to sign
Expand Down
13 changes: 7 additions & 6 deletions packages/wasm-solana/js/transaction.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { WasmTransaction } from "./wasm/wasm_solana.js";
import { Keypair } from "./keypair.js";
import { Pubkey } from "./pubkey.js";

/**
Expand Down Expand Up @@ -225,15 +226,15 @@ export class Transaction {
}

/**
* Sign this transaction with a base58-encoded Ed25519 secret key.
* Sign this transaction with a Keypair.
*
* Derives the public key from the secret, signs the transaction message,
* and places the signature at the correct signer index.
* Signs the transaction message and places the signature at the correct
* signer index.
*
* @param secretKeyBase58 - The Ed25519 secret key (32-byte seed) as base58
* @param keypair - A Keypair instance
*/
signWithSecretKey(secretKeyBase58: string): void {
this._wasm.sign_with_secret_key(secretKeyBase58);
signWithKeypair(keypair: Keypair): void {
this._wasm.sign_with_keypair(keypair.wasm);
}

/**
Expand Down
3 changes: 3 additions & 0 deletions packages/wasm-solana/src/instructions/try_into_js_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use crate::intent::{AuthorizeType, KeypairPurpose, StakingType};
// Enum → JS string conversions
// =============================================================================

// UPPER_CASE: matches BitGo platform enum format
impl TryIntoJsValue for StakingType {
fn try_to_js_value(&self) -> Result<JsValue, JsConversionError> {
let s = match self {
Expand All @@ -26,6 +27,7 @@ impl TryIntoJsValue for StakingType {
}
}

// PascalCase: matches Solana SDK StakeAuthorize variant names
impl TryIntoJsValue for AuthorizeType {
fn try_to_js_value(&self) -> Result<JsValue, JsConversionError> {
let s = match self {
Expand All @@ -36,6 +38,7 @@ impl TryIntoJsValue for AuthorizeType {
}
}

// camelCase: matches JS/TS field naming convention
impl TryIntoJsValue for KeypairPurpose {
fn try_to_js_value(&self) -> Result<JsValue, JsConversionError> {
let s = match self {
Expand Down
6 changes: 0 additions & 6 deletions packages/wasm-solana/src/wasm/keypair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,6 @@ impl WasmKeypair {
self.inner.address()
}

/// Get the public key as a base58 string.
#[wasm_bindgen]
pub fn to_base58(&self) -> String {
self.inner.address()
}

/// Sign a message with this keypair and return the 64-byte Ed25519 signature.
///
/// @param message - The message bytes to sign
Expand Down
22 changes: 10 additions & 12 deletions packages/wasm-solana/src/wasm/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use crate::error::WasmSolanaError;
use crate::transaction::{Transaction, TransactionExt};
use crate::versioned::{detect_transaction_version, TxVersion, VersionedTransactionExt};
use crate::wasm::keypair::WasmKeypair;
use solana_message::VersionedMessage;
use solana_sdk::bs58;
use solana_transaction::versioned::VersionedTransaction;
Expand Down Expand Up @@ -135,24 +136,21 @@ impl WasmTransaction {
self.inner.signer_index(pubkey)
}

/// Sign this transaction with a base58-encoded Ed25519 secret key.
/// Sign this transaction with a `WasmKeypair`.
///
/// Derives the public key from the secret, signs the transaction message,
/// and places the signature at the correct signer index.
/// Signs the transaction message and places the signature at the correct
/// signer index.
///
/// @param secret_key_base58 - The Ed25519 secret key (32-byte seed) as base58
/// @param keypair - A WasmKeypair instance
#[wasm_bindgen]
pub fn sign_with_secret_key(&mut self, secret_key_base58: &str) -> Result<(), WasmSolanaError> {
use crate::keypair::{Keypair, KeypairExt};
pub fn sign_with_keypair(&mut self, keypair: &WasmKeypair) -> Result<(), WasmSolanaError> {
use crate::keypair::KeypairExt;
use solana_signer::Signer;

let secret_bytes: Vec<u8> = bs58::decode(secret_key_base58)
.into_vec()
.map_err(|e| WasmSolanaError::new(&format!("Failed to decode secret key: {}", e)))?;
let keypair = Keypair::from_secret_key_bytes(&secret_bytes)?;
let inner = keypair.inner();
let message_bytes = self.inner.message.serialize();
let signature = keypair.sign_message(&message_bytes);
let address = keypair.address();
let signature = inner.sign_message(&message_bytes);
let address = inner.address();
self.inner.add_signature(&address, signature.as_ref())
}

Expand Down