@exodus/web3-ethereum-utils 1.2.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 +1 -0
- package/lib/index.js +1 -0
- package/lib/signatures.d.ts +1 -1
- package/lib/signatures.js +11 -4
- package/lib/transactions.d.ts +2 -0
- package/lib/transactions.js +8 -0
- package/lib/types.d.ts +1 -1
- package/package.json +2 -2
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
package/lib/signatures.d.ts
CHANGED
|
@@ -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):
|
|
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
|
|
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
|
-
|
|
16
|
-
return rawTransaction;
|
|
23
|
+
return signedTransaction.serialize();
|
|
17
24
|
}
|
|
@@ -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/lib/types.d.ts
CHANGED
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.
|
|
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": "
|
|
33
|
+
"gitHead": "e8db76660e5b1b230147c3391e843421a630d376"
|
|
34
34
|
}
|