Skip to content

Commit 2bf68f6

Browse files
authored
Merge pull request #6678 from WalletConnect/feat/sui-tvf
feat: extending tvf
2 parents 8929378 + e3f297a commit 2bf68f6

File tree

10 files changed

+2126
-48
lines changed

10 files changed

+2126
-48
lines changed

.changeset/modern-plums-do.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
"@walletconnect/sign-client": patch
3+
"@walletconnect/utils": patch
4+
"@walletconnect/core": patch
5+
"@walletconnect/react-native-compat": patch
6+
"@walletconnect/types": patch
7+
"@walletconnect/ethereum-provider": patch
8+
"@walletconnect/signer-connection": patch
9+
"@walletconnect/universal-provider": patch
10+
---
11+
12+
Extended TVF to cover more chains

package-lock.json

Lines changed: 12 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/sign-client/src/constants/engine.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ export const ENGINE_QUEUE_STATES: { idle: "IDLE"; active: "ACTIVE" } = {
146146
};
147147

148148
export const TVF_METHODS = {
149+
// evm
149150
eth_sendTransaction: {
150151
key: "",
151152
},
@@ -156,6 +157,7 @@ export const TVF_METHODS = {
156157
key: "",
157158
},
158159

160+
// solana
159161
solana_signTransaction: {
160162
key: "signature",
161163
},
@@ -165,4 +167,67 @@ export const TVF_METHODS = {
165167
solana_signAndSendTransaction: {
166168
key: "signature",
167169
},
170+
171+
// sui
172+
sui_signAndExecuteTransaction: {
173+
key: "digest",
174+
},
175+
sui_signTransaction: {
176+
key: "",
177+
},
178+
179+
// hedera
180+
hedera_signAndExecuteTransaction: {
181+
key: "transactionId",
182+
},
183+
hedera_executeTransaction: {
184+
key: "transactionId",
185+
},
186+
187+
// near
188+
near_signTransaction: {
189+
key: "",
190+
},
191+
near_signTransactions: {
192+
key: "",
193+
},
194+
195+
// tron
196+
tron_signTransaction: {
197+
key: "txID",
198+
},
199+
200+
// xrpl
201+
xrpl_signTransaction: {
202+
key: "",
203+
},
204+
205+
xrpl_signTransactionFor: {
206+
key: "",
207+
},
208+
209+
// algorand
210+
algo_signTxn: {
211+
key: "",
212+
},
213+
214+
// bitcoin
215+
sendTransfer: {
216+
key: "txid",
217+
},
218+
219+
// stacks
220+
stacks_stxTransfer: {
221+
key: "txId",
222+
},
223+
224+
// polkadot
225+
polkadot_signTransaction: {
226+
key: "",
227+
},
228+
229+
// cosmos
230+
cosmos_signDirect: {
231+
key: "",
232+
},
168233
};

packages/sign-client/src/controllers/engine.ts

Lines changed: 61 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,12 @@ import {
9999
isTestRun,
100100
isValidArray,
101101
extractSolanaTransactionId,
102+
getSuiDigest,
102103
mergeRequiredAndOptionalNamespaces,
104+
getNearTransactionIdFromSignedTransaction,
105+
getAlgorandTransactionId,
106+
buildSignedExtrinsicHash,
107+
getSignDirectHash,
103108
} from "@walletconnect/utils";
104109
import EventEmmiter from "events";
105110
import {
@@ -651,7 +656,6 @@ export class Engine extends IEngine {
651656
},
652657
chainId,
653658
};
654-
const shouldSetTVF = this.shouldSetTVF(protocolMethod, protocolRequestParams);
655659

656660
return await Promise.all([
657661
new Promise<void>(async (resolve) => {
@@ -663,9 +667,7 @@ export class Engine extends IEngine {
663667
params: protocolRequestParams,
664668
expiry,
665669
throwOnFailedPublish: true,
666-
...(shouldSetTVF && {
667-
tvf: this.getTVFParams(clientRpcId, protocolRequestParams),
668-
}),
670+
tvf: this.getTVFParams(clientRpcId, protocolRequestParams),
669671
}).catch((error) => reject(error));
670672
this.client.events.emit("session_request_sent", {
671673
topic,
@@ -1584,9 +1586,7 @@ export class Engine extends IEngine {
15841586
record = await this.client.core.history.get(topic, id);
15851587
const request = record.request;
15861588
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);
15901590
} catch (error) {
15911591
this.client.logger.warn(`sendResult() -> getTVFParams() failed`, error);
15921592
}
@@ -3111,39 +3111,26 @@ export class Engine extends IEngine {
31113111
}
31123112
};
31133113

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-
31243114
private getTVFParams = (
31253115
id: number,
31263116
params: JsonRpcTypes.RequestParams["wc_sessionRequest"],
31273117
result?: any,
31283118
) => {
3119+
const tvf: RelayerTypes.ITVF = {
3120+
correlationId: id,
3121+
rpcMethods: [params.request.method],
3122+
chainId: params.chainId,
3123+
};
31293124
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+
: [];
31433130
} catch (e) {
31443131
this.client.logger.warn("Error getting TVF params", e);
31453132
}
3146-
return {};
3133+
return tvf;
31473134
};
31483135

31493136
private isValidContractData = (params: any) => {
@@ -3161,9 +3148,51 @@ export class Engine extends IEngine {
31613148
return false;
31623149
};
31633150

3164-
private extractTxHashesFromResult = (method: string, result: any): string[] => {
3151+
private extractTxHashesFromResult = (
3152+
request: JsonRpcTypes.RequestParams["wc_sessionRequest"]["request"],
3153+
result: any,
3154+
): string[] => {
31653155
try {
3156+
if (!result) return [];
3157+
3158+
const method = request.method;
31663159
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+
31673196
// result = 0x...
31683197
if (typeof result === "string") {
31693198
return [result];

0 commit comments

Comments
 (0)