Skip to content

Commit 0cb9979

Browse files
authored
Merge pull request #165 from BitGo/BTC-3025-pr160-review-feedback
refactor: address PR #160 review feedback
2 parents 499c254 + fac868d commit 0cb9979

5 files changed

Lines changed: 20 additions & 32 deletions

File tree

packages/wasm-solana/js/keypair.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,6 @@ export class Keypair {
6161
return this._wasm.address();
6262
}
6363

64-
/**
65-
* Get the public key as a base58 string
66-
* @returns The public key as a base58 string
67-
*/
68-
toBase58(): string {
69-
return this._wasm.to_base58();
70-
}
71-
7264
/**
7365
* Sign a message with this keypair
7466
* @param message - The message bytes to sign

packages/wasm-solana/js/transaction.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { WasmTransaction } from "./wasm/wasm_solana.js";
2+
import { Keypair } from "./keypair.js";
23
import { Pubkey } from "./pubkey.js";
34

45
/**
@@ -225,15 +226,15 @@ export class Transaction {
225226
}
226227

227228
/**
228-
* Sign this transaction with a base58-encoded Ed25519 secret key.
229+
* Sign this transaction with a Keypair.
229230
*
230-
* Derives the public key from the secret, signs the transaction message,
231-
* and places the signature at the correct signer index.
231+
* Signs the transaction message and places the signature at the correct
232+
* signer index.
232233
*
233-
* @param secretKeyBase58 - The Ed25519 secret key (32-byte seed) as base58
234+
* @param keypair - A Keypair instance
234235
*/
235-
signWithSecretKey(secretKeyBase58: string): void {
236-
this._wasm.sign_with_secret_key(secretKeyBase58);
236+
signWithKeypair(keypair: Keypair): void {
237+
this._wasm.sign_with_keypair(keypair.wasm);
237238
}
238239

239240
/**

packages/wasm-solana/src/instructions/try_into_js_value.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use crate::intent::{AuthorizeType, KeypairPurpose, StakingType};
1515
// Enum → JS string conversions
1616
// =============================================================================
1717

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

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

41+
// camelCase: matches JS/TS field naming convention
3942
impl TryIntoJsValue for KeypairPurpose {
4043
fn try_to_js_value(&self) -> Result<JsValue, JsConversionError> {
4144
let s = match self {

packages/wasm-solana/src/wasm/keypair.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,6 @@ impl WasmKeypair {
5555
self.inner.address()
5656
}
5757

58-
/// Get the public key as a base58 string.
59-
#[wasm_bindgen]
60-
pub fn to_base58(&self) -> String {
61-
self.inner.address()
62-
}
63-
6458
/// Sign a message with this keypair and return the 64-byte Ed25519 signature.
6559
///
6660
/// @param message - The message bytes to sign

packages/wasm-solana/src/wasm/transaction.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use crate::error::WasmSolanaError;
99
use crate::transaction::{Transaction, TransactionExt};
1010
use crate::versioned::{detect_transaction_version, TxVersion, VersionedTransactionExt};
11+
use crate::wasm::keypair::WasmKeypair;
1112
use solana_message::VersionedMessage;
1213
use solana_sdk::bs58;
1314
use solana_transaction::versioned::VersionedTransaction;
@@ -135,24 +136,21 @@ impl WasmTransaction {
135136
self.inner.signer_index(pubkey)
136137
}
137138

138-
/// Sign this transaction with a base58-encoded Ed25519 secret key.
139+
/// Sign this transaction with a `WasmKeypair`.
139140
///
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.
142143
///
143-
/// @param secret_key_base58 - The Ed25519 secret key (32-byte seed) as base58
144+
/// @param keypair - A WasmKeypair instance
144145
#[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;
147148
use solana_signer::Signer;
148149

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();
153151
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();
156154
self.inner.add_signature(&address, signature.as_ref())
157155
}
158156

0 commit comments

Comments
 (0)