Skip to content

Commit 8f8da0f

Browse files
committed
fix: move verifyTransaction from ebe to mbe
Ticket: WP-4689
1 parent cd97ca3 commit 8f8da0f

File tree

2 files changed

+29
-23
lines changed

2 files changed

+29
-23
lines changed

src/api/enclaved/signMultisigTransaction.ts

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,13 @@ export async function signMultisigTransaction(
1414

1515
if (!source || !pub) {
1616
throw new Error('Source and public key are required for signing');
17-
} else if (!txPrebuild || !txPrebuild.wallet) {
17+
} else if (!txPrebuild) {
1818
throw new Error('Transaction prebuild is required for signing');
1919
}
2020

21-
const reqId = new RequestTracer();
2221
const bitgo = req.bitgo;
23-
const baseCoin = bitgo.coin(req.params.coin);
2422
const kms = new KmsClient();
2523

26-
// verify transaction prebuild
27-
try {
28-
await baseCoin.verifyTransaction({
29-
txParams: { ...txPrebuild.buildParams },
30-
txPrebuild,
31-
wallet: txPrebuild.wallet,
32-
verification: {},
33-
reqId: reqId,
34-
walletType: 'onchain',
35-
});
36-
} catch (e) {
37-
const err = e as Error;
38-
logger.error('transaction prebuild failed local validation:', err.message);
39-
logger.error('transaction prebuild:', JSON.stringify(txPrebuild, null, 2));
40-
logger.error(err);
41-
}
42-
4324
// Retrieve the private key from KMS
4425
let prv: string;
4526
try {

src/masterBitgoExpress/handleSendMany.ts

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,47 @@ export async function handleSendMany(req: MasterApiSpecRouteRequest<'v1.wallet.s
5252
throw new Error(`Signing keychain for ${params.source} not found`);
5353
}
5454

55+
logger.debug(`Signing keychain: ${JSON.stringify(signingKeychain, null, 2)}`);
56+
5557
try {
5658
const prebuildParams: PrebuildTransactionOptions = {
5759
...params,
5860
// Convert memo string to Memo object if present
5961
memo: params.memo ? ({ type: 'text', value: params.memo } as Memo) : undefined,
6062
};
6163

62-
// First build the transaction
63-
const txPrebuild = await wallet.prebuildTransaction({
64+
// First build the transaction with bitgo
65+
const txPrebuilt = await wallet.prebuildTransaction({
6466
...prebuildParams,
6567
reqId,
6668
});
6769

70+
// verify transaction prebuild
71+
try {
72+
const verified = await baseCoin.verifyTransaction({
73+
txParams: { ...prebuildParams },
74+
txPrebuild: txPrebuilt,
75+
wallet,
76+
verification: {},
77+
reqId: reqId,
78+
walletType: 'onchain',
79+
});
80+
if (!verified) {
81+
throw new Error('Transaction prebuild failed local validation');
82+
}
83+
logger.debug('Transaction prebuild verified');
84+
} catch (e) {
85+
const err = e as Error;
86+
logger.error('transaction prebuild failed local validation:', err.message);
87+
logger.error('transaction prebuild:', JSON.stringify(txPrebuilt, null, 2));
88+
logger.error(err);
89+
}
90+
91+
logger.debug('Tx prebuild: %s', JSON.stringify(txPrebuilt, null, 2));
92+
6893
// Then sign it using the enclaved express client
6994
const signedTx = await enclavedExpressClient.signMultisig({
70-
txPrebuild,
95+
txPrebuild: txPrebuilt,
7196
source: params.source,
7297
pub: signingKeychain.pub,
7398
});

0 commit comments

Comments
 (0)