@@ -38,10 +38,6 @@ const ecashSign = async (
3838 return { error : getCustomError ( 'ecash-sign: missing required parameters' ) } ;
3939 }
4040
41- if ( ! isValidECashAddress ( params . toAddress ) ) {
42- return { error : getCustomError ( 'ecash-sign: invalid destination address' ) } ;
43- }
44-
4541 if ( keyring . isLocked ( ) ) {
4642 return { error : getCustomError ( 'ecash-sign: keyring is locked' ) } ;
4743 }
@@ -66,9 +62,14 @@ const ecashSign = async (
6662 return { error : getCustomError ( 'ecash-sign: unknown network' ) } ;
6763 }
6864
69- privateKeyBuffer = await keyring . getPrivateKeyForECash (
70- params . account ,
71- ) ;
65+ const cashAddrPrefix = ( network as any ) . cashAddrPrefix ?? 'ecash' ;
66+ if ( ! isValidECashAddress ( params . toAddress , cashAddrPrefix ) ) {
67+ return {
68+ error : getCustomError ( 'ecash-sign: invalid destination address' ) ,
69+ } ;
70+ }
71+
72+ privateKeyBuffer = await keyring . getPrivateKeyForECash ( params . account ) ;
7273 pkBytes = new Uint8Array ( privateKeyBuffer ) ;
7374 const chronik = new ChronikClient ( [ network . node ] ) ;
7475 const wallet = Wallet . fromSk ( pkBytes , chronik ) ;
@@ -97,8 +98,10 @@ const ecashSign = async (
9798 result . errors ?. length ? result . errors . join ( ', ' ) : 'Broadcast failed' ,
9899 ) ;
99100 }
100-
101- const txid = result . broadcasted [ 0 ] || '' ;
101+ const txid = result . broadcasted [ 0 ] ;
102+ if ( ! txid ) {
103+ throw new Error ( 'Broadcast succeeded but no txid returned' ) ;
104+ }
102105 return { result : JSON . stringify ( { txid } ) } ;
103106 } catch ( e : any ) {
104107 console . error ( '[ecash-sign] Error:' , e ) ;
0 commit comments