@@ -9,6 +9,7 @@ use crate::error::WasmSolanaError;
99use crate :: transaction:: { Transaction , TransactionExt } ;
1010use crate :: versioned:: { detect_transaction_version, TxVersion , VersionedTransactionExt } ;
1111use solana_message:: VersionedMessage ;
12+ use solana_sdk:: bs58;
1213use solana_transaction:: versioned:: VersionedTransaction ;
1314use wasm_bindgen:: prelude:: * ;
1415
@@ -56,6 +57,24 @@ impl WasmTransaction {
5657 self . inner . num_signatures ( )
5758 }
5859
60+ /// Get the transaction ID (first signature as base58).
61+ ///
62+ /// For Solana, the transaction ID is the first signature.
63+ /// Returns "UNSIGNED" if the first signature is all zeros (unsigned transaction).
64+ #[ wasm_bindgen( getter) ]
65+ pub fn id ( & self ) -> String {
66+ if let Some ( sig) = self . inner . signatures . first ( ) {
67+ let bytes: & [ u8 ] = sig. as_ref ( ) ;
68+ // Check if signature is all zeros (unsigned)
69+ if bytes. iter ( ) . all ( |& b| b == 0 ) {
70+ return "UNSIGNED" . to_string ( ) ;
71+ }
72+ bs58:: encode ( bytes) . into_string ( )
73+ } else {
74+ "UNSIGNED" . to_string ( )
75+ }
76+ }
77+
5978 /// Get the signable message payload (what gets signed).
6079 ///
6180 /// This is the serialized message that signers sign.
@@ -242,6 +261,24 @@ impl WasmVersionedTransaction {
242261 self . inner . num_signatures ( )
243262 }
244263
264+ /// Get the transaction ID (first signature as base58).
265+ ///
266+ /// For Solana, the transaction ID is the first signature.
267+ /// Returns "UNSIGNED" if the first signature is all zeros (unsigned transaction).
268+ #[ wasm_bindgen( getter) ]
269+ pub fn id ( & self ) -> String {
270+ if let Some ( sig) = self . inner . signatures . first ( ) {
271+ let bytes: & [ u8 ] = sig. as_ref ( ) ;
272+ // Check if signature is all zeros (unsigned)
273+ if bytes. iter ( ) . all ( |& b| b == 0 ) {
274+ return "UNSIGNED" . to_string ( ) ;
275+ }
276+ bs58:: encode ( bytes) . into_string ( )
277+ } else {
278+ "UNSIGNED" . to_string ( )
279+ }
280+ }
281+
245282 /// Get the signable message payload.
246283 #[ wasm_bindgen]
247284 pub fn signable_payload ( & self ) -> js_sys:: Uint8Array {
0 commit comments