@@ -1643,7 +1643,7 @@ export function JsonRpcContextProvider({
16431643 const tronWeb = getTronWeb ( chainId ) ;
16441644
16451645 if ( ! tronWeb ) {
1646- throw new Error ( "Tron web not found for chainId: " + chainId ) ;
1646+ throw new Error ( "TronWeb not found for chainId: " + chainId ) ;
16471647 }
16481648
16491649 // Take USDT as an example:
@@ -1653,7 +1653,7 @@ export function JsonRpcContextProvider({
16531653 const testContract = isTestnet
16541654 ? "TXYZopYRdj2D9XRtbG411XZZ3kM5VkAeBf"
16551655 : "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t" ;
1656- const testTransaction =
1656+ const { transaction } =
16571657 await tronWeb . transactionBuilder . triggerSmartContract (
16581658 testContract ,
16591659 "approve(address,uint256)" ,
@@ -1665,17 +1665,26 @@ export function JsonRpcContextProvider({
16651665 address
16661666 ) ;
16671667
1668- const result = await client ! . request < { signature : any } > ( {
1668+ const sessionProperties = session ! . sessionProperties ;
1669+ const isV1Method = sessionProperties ?. tron_method_version === "v1" ;
1670+
1671+ const result = await client ! . request < {
1672+ signature : any ;
1673+ result ?: { signature : any } ;
1674+ } > ( {
16691675 chainId,
16701676 topic : session ! . topic ,
16711677 request : {
16721678 method : DEFAULT_TRON_METHODS . TRON_SIGN_TRANSACTION ,
1673- params : {
1674- address,
1675- transaction : {
1676- ...testTransaction ,
1677- } ,
1678- } ,
1679+ params : isV1Method
1680+ ? {
1681+ address,
1682+ transaction,
1683+ }
1684+ : {
1685+ address,
1686+ transaction : { transaction } ,
1687+ } ,
16791688 } ,
16801689 } ) ;
16811690 console . log ( "tron sign transaction result" , result ) ;
@@ -1684,7 +1693,7 @@ export function JsonRpcContextProvider({
16841693 method : DEFAULT_TRON_METHODS . TRON_SIGN_TRANSACTION ,
16851694 address,
16861695 valid : true ,
1687- result : result . signature ,
1696+ result : result . result ?. signature ?? result . signature ,
16881697 } ;
16891698 }
16901699 ) ,
@@ -1697,7 +1706,7 @@ export function JsonRpcContextProvider({
16971706
16981707 const tronWeb = getTronWeb ( chainId ) ;
16991708 if ( ! tronWeb ) {
1700- throw new Error ( "Tron web not found for chainId: " + chainId ) ;
1709+ throw new Error ( "TronWeb not found for chainId: " + chainId ) ;
17011710 }
17021711
17031712 const result = await client ! . request < { signature : string } > ( {
@@ -1711,14 +1720,17 @@ export function JsonRpcContextProvider({
17111720 } ,
17121721 } ,
17131722 } ) ;
1714- const valid = await tronWeb . trx . verifyMessage (
1715- result . signature ,
1716- message
1723+ const valid = await tronWeb . trx . verifyMessageV2 (
1724+ message ,
1725+ result . signature
17171726 ) ;
1727+
1728+ console . log ( "tron sign message valid" , { valid, address } ) ;
1729+ console . log ( "tron sign message result" , result ) ;
17181730 return {
17191731 method : DEFAULT_TRON_METHODS . TRON_SIGN_MESSAGE ,
17201732 address,
1721- valid : valid ,
1733+ valid : valid === address ,
17221734 result : result . signature ,
17231735 } ;
17241736 }
0 commit comments