@@ -99,7 +99,12 @@ import {
99
99
isTestRun ,
100
100
isValidArray ,
101
101
extractSolanaTransactionId ,
102
+ getSuiDigest ,
102
103
mergeRequiredAndOptionalNamespaces ,
104
+ getNearTransactionIdFromSignedTransaction ,
105
+ getAlgorandTransactionId ,
106
+ buildSignedExtrinsicHash ,
107
+ getSignDirectHash ,
103
108
} from "@walletconnect/utils" ;
104
109
import EventEmmiter from "events" ;
105
110
import {
@@ -651,7 +656,6 @@ export class Engine extends IEngine {
651
656
} ,
652
657
chainId,
653
658
} ;
654
- const shouldSetTVF = this . shouldSetTVF ( protocolMethod , protocolRequestParams ) ;
655
659
656
660
return await Promise . all ( [
657
661
new Promise < void > ( async ( resolve ) => {
@@ -663,9 +667,7 @@ export class Engine extends IEngine {
663
667
params : protocolRequestParams ,
664
668
expiry,
665
669
throwOnFailedPublish : true ,
666
- ...( shouldSetTVF && {
667
- tvf : this . getTVFParams ( clientRpcId , protocolRequestParams ) ,
668
- } ) ,
670
+ tvf : this . getTVFParams ( clientRpcId , protocolRequestParams ) ,
669
671
} ) . catch ( ( error ) => reject ( error ) ) ;
670
672
this . client . events . emit ( "session_request_sent" , {
671
673
topic,
@@ -1584,9 +1586,7 @@ export class Engine extends IEngine {
1584
1586
record = await this . client . core . history . get ( topic , id ) ;
1585
1587
const request = record . request ;
1586
1588
try {
1587
- if ( this . shouldSetTVF ( request . method as JsonRpcTypes . WcMethod , request . params ) ) {
1588
- tvf = this . getTVFParams ( id , request . params , result ) ;
1589
- }
1589
+ tvf = this . getTVFParams ( id , request . params , result ) ;
1590
1590
} catch ( error ) {
1591
1591
this . client . logger . warn ( `sendResult() -> getTVFParams() failed` , error ) ;
1592
1592
}
@@ -3111,39 +3111,26 @@ export class Engine extends IEngine {
3111
3111
}
3112
3112
} ;
3113
3113
3114
- private shouldSetTVF = (
3115
- protocolMethod : JsonRpcTypes . WcMethod ,
3116
- params : JsonRpcTypes . RequestParams [ "wc_sessionRequest" ] ,
3117
- ) => {
3118
- if ( ! params ) return false ;
3119
- if ( protocolMethod !== "wc_sessionRequest" ) return false ;
3120
- const { request } = params ;
3121
- return Object . keys ( TVF_METHODS ) . includes ( request . method ) ;
3122
- } ;
3123
-
3124
3114
private getTVFParams = (
3125
3115
id : number ,
3126
3116
params : JsonRpcTypes . RequestParams [ "wc_sessionRequest" ] ,
3127
3117
result ?: any ,
3128
3118
) => {
3119
+ const tvf : RelayerTypes . ITVF = {
3120
+ correlationId : id ,
3121
+ rpcMethods : [ params . request . method ] ,
3122
+ chainId : params . chainId ,
3123
+ } ;
3129
3124
try {
3130
- const requestMethod = params . request . method ;
3131
- const txHashes = this . extractTxHashesFromResult ( requestMethod , result ) ;
3132
- const tvf : RelayerTypes . ITVF = {
3133
- correlationId : id ,
3134
- rpcMethods : [ requestMethod ] ,
3135
- chainId : params . chainId ,
3136
- ...( this . isValidContractData ( params . request . params ) && {
3137
- // initially only get contractAddresses from EVM txs
3138
- contractAddresses : [ params . request . params ?. [ 0 ] ?. to ] ,
3139
- } ) ,
3140
- txHashes,
3141
- } ;
3142
- return tvf ;
3125
+ const txHashes = this . extractTxHashesFromResult ( params . request , result ) ;
3126
+ tvf . txHashes = txHashes ;
3127
+ tvf . contractAddresses = this . isValidContractData ( params . request . params )
3128
+ ? [ params . request . params ?. [ 0 ] ?. to ]
3129
+ : [ ] ;
3143
3130
} catch ( e ) {
3144
3131
this . client . logger . warn ( "Error getting TVF params" , e ) ;
3145
3132
}
3146
- return { } ;
3133
+ return tvf ;
3147
3134
} ;
3148
3135
3149
3136
private isValidContractData = ( params : any ) => {
@@ -3161,9 +3148,51 @@ export class Engine extends IEngine {
3161
3148
return false ;
3162
3149
} ;
3163
3150
3164
- private extractTxHashesFromResult = ( method : string , result : any ) : string [ ] => {
3151
+ private extractTxHashesFromResult = (
3152
+ request : JsonRpcTypes . RequestParams [ "wc_sessionRequest" ] [ "request" ] ,
3153
+ result : any ,
3154
+ ) : string [ ] => {
3165
3155
try {
3156
+ if ( ! result ) return [ ] ;
3157
+
3158
+ const method = request . method ;
3166
3159
const methodConfig = TVF_METHODS [ method as keyof typeof TVF_METHODS ] ;
3160
+
3161
+ if ( method === "sui_signTransaction" ) {
3162
+ return [ getSuiDigest ( result . transactionBytes ) ] ;
3163
+ }
3164
+
3165
+ if ( method === "near_signTransaction" ) {
3166
+ return [ getNearTransactionIdFromSignedTransaction ( result ) ] ;
3167
+ }
3168
+
3169
+ if ( method === "near_signTransactions" ) {
3170
+ return result . map ( ( tx : any ) => getNearTransactionIdFromSignedTransaction ( tx ) ) ;
3171
+ }
3172
+
3173
+ if ( method === "xrpl_signTransactionFor" || method === "xrpl_signTransaction" ) {
3174
+ return [ result . tx_json ?. hash ] ;
3175
+ }
3176
+
3177
+ if ( method === "polkadot_signTransaction" ) {
3178
+ return [
3179
+ buildSignedExtrinsicHash ( {
3180
+ transaction : request . params . transactionPayload ,
3181
+ signature : result . signature ,
3182
+ } ) ,
3183
+ ] ;
3184
+ }
3185
+
3186
+ if ( method === "algo_signTxn" ) {
3187
+ return isValidArray ( result )
3188
+ ? result . map ( ( tx : any ) => getAlgorandTransactionId ( tx ) )
3189
+ : [ getAlgorandTransactionId ( result ) ] ;
3190
+ }
3191
+
3192
+ if ( method === "cosmos_signDirect" ) {
3193
+ return [ getSignDirectHash ( result ) ] ;
3194
+ }
3195
+
3167
3196
// result = 0x...
3168
3197
if ( typeof result === "string" ) {
3169
3198
return [ result ] ;
0 commit comments