on fe1e348 help sign in
bridge/src/lib/WalletConnect.ts
27 lines 754 B history raw
1import { ITxData } from '@walletconnect/types';
2import { Transaction } from '@ethereumjs/tx';
3import { stripHexPrefix } from './utils/address';
5type SignWalletConnectTransactionArgs = {
6 from: string;
7 txn: Transaction;
8 txnSigner: (args: ITxData) => Promise<string>;
9};
11const walletConnectSignTransaction = async ({
12 from,
13 txn,
14 txnSigner,
15}: SignWalletConnectTransactionArgs) => {
16 let wcFormattedTx = txn.toJSON();
17 wcFormattedTx.from = from;
18 wcFormattedTx.gas = wcFormattedTx.gasLimit;
20 const signature = await txnSigner(wcFormattedTx);
21 const serializedTx = Buffer.from(stripHexPrefix(signature), 'hex');
22 const signedTx = Transaction.fromSerializedTx(serializedTx);
24 return signedTx;
25};
27export { walletConnectSignTransaction };