@exodus/web3-ethereum-utils 1.3.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './addresses.js';
2
2
  export * from './signatures.js';
3
+ export * from './transactions.js';
3
4
  export * from './types.js';
package/lib/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './addresses.js';
2
2
  export * from './signatures.js';
3
+ export * from './transactions.js';
3
4
  export * from './types.js';
@@ -3,4 +3,4 @@ import { MessageTypes, SignTypedDataVersion, TypedDataV1, TypedMessage } from '@
3
3
  import { EthTransactionParams } from './types.js';
4
4
  export declare function signMessage(message: string, privateKey: Buffer): string;
5
5
  export declare function signTypedData(typedData: TypedDataV1 | TypedMessage<MessageTypes>, privateKey: Buffer, version?: SignTypedDataVersion): string;
6
- export declare function signTransaction(transactionParams: EthTransactionParams, privateKey: Buffer): string;
6
+ export declare function signTransaction(transactionParams: EthTransactionParams, privateKey: Buffer): Buffer;
package/lib/signatures.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import Common, { Hardfork } from '@exodus/ethereumjs-common';
2
- import { FeeMarketEIP1559Transaction } from '@exodus/ethereumjs-tx';
2
+ import { FeeMarketEIP1559Transaction, Transaction as LegacyTransaction, } from '@exodus/ethereumjs-tx';
3
3
  import { SignTypedDataVersion, personalSign, signTypedData as ethSigUtilSignTypedData, } from '@metamask/eth-sig-util';
4
4
  export function signMessage(message, privateKey) {
5
5
  return personalSign({ privateKey, data: message });
@@ -10,8 +10,15 @@ export function signTypedData(typedData, privateKey, version = SignTypedDataVers
10
10
  export function signTransaction(transactionParams, privateKey) {
11
11
  const { chainId: hexChainId, gas, ...rest } = transactionParams;
12
12
  const chainId = Number.parseInt(hexChainId, 16);
13
- const transaction = FeeMarketEIP1559Transaction.fromTxData({ ...rest, gasLimit: gas }, { common: Common.custom({ chainId }, { hardfork: Hardfork.London }) });
13
+ const transactionData = { ...rest, gasLimit: gas };
14
+ const isEIP1559Enabled = !!transactionParams.maxFeePerGas;
15
+ const transaction = isEIP1559Enabled
16
+ ? FeeMarketEIP1559Transaction.fromTxData(transactionData, {
17
+ common: Common.custom({ chainId }, { hardfork: Hardfork.London }),
18
+ })
19
+ : LegacyTransaction.fromTxData(transactionData, {
20
+ common: Common.custom({ chainId }),
21
+ });
14
22
  const signedTransaction = transaction.sign(privateKey);
15
- const rawTransaction = `0x${signedTransaction.serialize().toString('hex')}`;
16
- return rawTransaction;
23
+ return signedTransaction.serialize();
17
24
  }
@@ -0,0 +1,2 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ export declare function getTransactionId(serializedTransaction: Buffer, isEIP1559Transaction: boolean): string;
@@ -0,0 +1,8 @@
1
+ import { FeeMarketEIP1559Transaction, Transaction as LegacyTransaction, } from '@exodus/ethereumjs-tx';
2
+ export function getTransactionId(serializedTransaction, isEIP1559Transaction) {
3
+ const TransactionClass = isEIP1559Transaction
4
+ ? FeeMarketEIP1559Transaction
5
+ : LegacyTransaction;
6
+ const transaction = TransactionClass.fromSerializedTx(serializedTransaction);
7
+ return `0x${transaction.hash().toString('hex')}`;
8
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@exodus/web3-ethereum-utils",
3
3
  "description": "Web3 Ethereum utils.",
4
- "version": "1.3.0",
4
+ "version": "1.4.0",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "module": "lib/index.js",
@@ -30,5 +30,5 @@
30
30
  "@exodus/ethereumjs-tx": "^3.3.0-exodus.6",
31
31
  "@metamask/eth-sig-util": "^4.0.1"
32
32
  },
33
- "gitHead": "7f7584e3b44d7099c9ee848ec08c522e1eece630"
33
+ "gitHead": "e8db76660e5b1b230147c3391e843421a630d376"
34
34
  }