@@ -2,6 +2,7 @@ import { type ProtocolAdapter, SOL } from '@protocols/shared';
22import { Summary } from '@/components/Summary' ;
33import { convertToMessage , looksLikeMessage , type MessageLike , type ParseSolTxResult , parseSolTx } from '@/parser' ;
44import type { DecodedInstruction } from '@/types' ;
5+ import { base64ToHex , isBase64 , isHex } from '@/utils' ;
56
67const computeSolanaHash = async ( rawTx : string ) : Promise < string > => {
78 try {
@@ -27,7 +28,12 @@ const computeSolanaHash = async (rawTx: string): Promise<string> => {
2728 } catch { }
2829 }
2930
30- const transactionUint8Array = new Uint8Array ( input . match ( / .{ 1 , 2 } / g) ?. map ( ( byte ) => parseInt ( byte , 16 ) ) || [ ] ) ;
31+ let hexInput = input ;
32+ if ( ! isHex ( input ) && isBase64 ( input ) ) {
33+ hexInput = base64ToHex ( input ) ;
34+ }
35+
36+ const transactionUint8Array = new Uint8Array ( hexInput . match ( / .{ 1 , 2 } / g) ?. map ( ( byte ) => parseInt ( byte , 16 ) ) || [ ] ) ;
3137 const hashBuffer = await crypto . subtle . digest ( 'SHA-256' , transactionUint8Array ) ;
3238 const hashArray = Array . from ( new Uint8Array ( hashBuffer ) ) ;
3339 return hashArray . map ( ( b ) => b . toString ( 16 ) . padStart ( 2 , '0' ) ) . join ( '' ) ;
@@ -40,16 +46,23 @@ const isValidSolanaInput = (rawTx: string): boolean => {
4046 const input = rawTx . trim ( ) ;
4147 if ( ! input ) return false ;
4248
49+ // JSON
4350 if ( input . startsWith ( '{' ) || input . startsWith ( '[' ) ) return true ;
4451
45- return / ^ [ 0 - 9 a - f A - F ] + $ / . test ( input ) && input . length % 2 === 0 ;
52+ // Hex
53+ if ( isHex ( input ) ) return true ;
54+
55+ // Base64
56+ if ( isBase64 ( input ) ) return true ;
57+
58+ return false ;
4659} ;
4760
4861export const solanaAdapter : ProtocolAdapter < ParseSolTxResult > = {
4962 protocol : SOL ,
5063 name : 'solana' ,
5164 displayName : 'Solana' ,
52- placeholder : 'Paste your transaction as hex or Fireblocks message JSON' ,
65+ placeholder : 'Paste your transaction as hex, base64, or Fireblocks message JSON' ,
5366
5467 validateInput : isValidSolanaInput ,
5568 parseTransaction : async ( rawTx ) => parseSolTx ( rawTx ) ,
0 commit comments