Skip to content

Commit

Permalink
Merge branch 'x' into fix/passcode
Browse files Browse the repository at this point in the history
  • Loading branch information
ezailWang authored Dec 25, 2024
2 parents 35dfd33 + 2bfc8fa commit fa6f0fa
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
13 changes: 13 additions & 0 deletions packages/kit-bg/src/services/ServiceSend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,19 @@ class ServiceSend extends ServiceBase {
...params,
customRpcInfo,
});

try {
const verified = await vault.verifyTxId({
txid: result.txid,
signedTx: result,
});
if (!verified) {
throw new Error('Invalid txid');
}
} catch (error) {
throw new Error('Invalid txid');
}

txid = result.txid;
}

Expand Down
7 changes: 7 additions & 0 deletions packages/kit-bg/src/vaults/base/VaultBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1419,4 +1419,11 @@ export abstract class VaultBase extends VaultBaseChainOnly {
): Promise<IEncodedTx> {
throw new NotImplemented();
}

async verifyTxId(params: {
txid: string;
signedTx: ISignedTxPro;
}): Promise<boolean> {
return Promise.resolve(true);
}
}
16 changes: 16 additions & 0 deletions packages/kit-bg/src/vaults/impls/evm/Vault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1232,13 +1232,29 @@ export default class Vault extends VaultBase {
}
const client = new ClientEvm(rpcUrl);
const txid = await client.broadcastTransaction(signedTx.rawTx);

return {
...signedTx,
txid,
encodedTx: signedTx.encodedTx,
};
}

override async verifyTxId(params: {
txid: string;
signedTx: ISignedTxPro;
}): Promise<boolean> {
const { signedTx, txid } = params;

if (typeof txid !== 'string') {
return false;
}

const recoveredTxid = ethers.utils.keccak256(signedTx.rawTx);

return recoveredTxid.toLowerCase() === txid.toLowerCase();
}

// RPC Client
async getRpcClient() {
const rpcInfo =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,26 +70,22 @@ function SendConfirmFromSwap() {
const isLastTx = i === len - 1;

const result: ISendTxOnSuccessData[] = await new Promise((resolve) => {
navigationToNext.current = true;
appNavigation.push(EModalSendRoutes.SendConfirm, {
...route.params,
popStack: false,
unsignedTxs: [unsignedTx],
onSuccess: (data: ISendTxOnSuccessData[]) => {
navigationToNext.current = false;
if (isLastTx) {
appNavigation.pop();
onSuccess?.(data);
}
resolve(data);
},
onFail: (error: Error) => {
navigationToNext.current = false;
appNavigation.pop();
onFail?.(error);
},
onCancel: () => {
navigationToNext.current = false;
appNavigation.pop();
onCancel?.();
},
Expand Down Expand Up @@ -127,6 +123,7 @@ function SendConfirmFromSwap() {
networkId,
encodedTxs: encodedTxList,
});
navigationToNext.current = true;
if (multiTxsFeeResult.txFees.length === unsignedTxs.length) {
await handleConfirmMultiTxsOnHwOrExternal(multiTxsFeeResult);
} else {
Expand All @@ -140,8 +137,9 @@ function SendConfirmFromSwap() {
}
}

navigationToNext.current = true;

if (!batchEstimateButSingleConfirm) {
navigationToNext.current = true;
action = StackActions.replace(EModalSendRoutes.SendConfirm, {
...route.params,
// @ts-ignore
Expand Down

0 comments on commit fa6f0fa

Please sign in to comment.