Skip to content

Commit 17e2bba

Browse files
committed
fix: validate eth_sendTransaction response is a tx hash not a signature
1 parent 678c9ef commit 17e2bba

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

packages/account-sdk/src/sign/base-account/Signer.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,9 +431,14 @@ describe('Signer', () => {
431431
params: [],
432432
};
433433

434+
// eth_sendTransaction requires a valid 32-byte tx hash response
435+
const mockValue = method === 'eth_sendTransaction'
436+
? '0x' + 'a'.repeat(64) // valid 32-byte tx hash
437+
: '0xSignature';
438+
434439
(decryptContent as Mock).mockResolvedValueOnce({
435440
result: {
436-
value: '0xSignature',
441+
value: mockValue,
437442
},
438443
});
439444

packages/account-sdk/src/sign/base-account/Signer.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,17 @@ export class Signer {
428428
this.callback?.('accountsChanged', this.accounts);
429429
break;
430430
}
431+
case 'eth_sendTransaction': {
432+
const txHash = result.value as string;
433+
// Validate that the response is a 32-byte tx hash (64 hex chars + 0x prefix = 66 chars)
434+
// If the popup returns a 65-byte ECDSA signature instead of a tx hash, throw an error
435+
if (typeof txHash === 'string' && txHash.startsWith('0x') && txHash.length !== 66) {
436+
throw standardErrors.rpc.internal(
437+
`eth_sendTransaction returned invalid response: expected 32-byte tx hash (66 chars) but got ${txHash.length} chars. The popup may have returned a signature instead of a transaction hash.`
438+
);
439+
}
440+
break;
441+
}
431442
default:
432443
break;
433444
}

0 commit comments

Comments
 (0)