Skip to content

Commit

Permalink
Merge branch 'x' into fix/native-check-btn
Browse files Browse the repository at this point in the history
  • Loading branch information
originalix authored Dec 26, 2024
2 parents 21439c7 + 3aac6c4 commit 520ca52
Show file tree
Hide file tree
Showing 7 changed files with 662 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
Loading

0 comments on commit 520ca52

Please sign in to comment.