Skip to content

Commit

Permalink
added support for type-2 tx signing
Browse files Browse the repository at this point in the history
  • Loading branch information
CaptainLEVI-XXX committed Dec 12, 2023
1 parent a2db78e commit 8372b1f
Show file tree
Hide file tree
Showing 5 changed files with 271 additions and 80 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,5 @@

### 1.0.9 (2023-12-12)

- Added gas estimation for EIP-1559 transaction on arbitrum.
- Added gas estimation for EIP-1559 transaction on arbitrum.
- Added support for Type-2 transactions signing.
237 changes: 192 additions & 45 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,15 @@
"nyc": "^15.0.0"
},
"dependencies": {
"@ethereumjs/common": "^4.1.0",
"@ethereumjs/tx": "^5.1.0",
"axios": "^1.6.2",
"bip39": "^3.0.4",
"browser-passworder": "^2.0.3",
"crypto-js": "^4.1.1",
"eth-hd-keyring": "^3.6.0",
"eth-sig-util": "^3.0.1",
"eth-simple-keyring": "^4.2.0",
"ethereumjs-tx": "^1.3.7",
"ethereumjs-util": "^7.1.0",
"hdkey": "^2.0.1",
"loglevel": "^1.7.1",
Expand Down
39 changes: 22 additions & 17 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
const { EventEmitter } = require('events')
const log = require('loglevel')
const ethUtil = require('ethereumjs-util')
const Tx = require('ethereumjs-tx');

const bip39 = require('bip39')
const ObservableStore = require('obs-store')
const encryptor = require('browser-passworder')
const { normalize: normalizeAddress } = require('eth-sig-util')

const { Common, Hardfork } =require('@ethereumjs/common')
const { FeeMarketEIP1559Transaction } = require('@ethereumjs/tx');
const { bufferToHex } = require('ethereumjs-util')

const SimpleKeyring = require('eth-simple-keyring')
const HdKeyring = require('eth-hd-keyring')

Expand Down Expand Up @@ -254,27 +257,29 @@ class KeyringController extends EventEmitter {
// SIGNING METHODS
//

/**
* Sign Arbitrum Transaction
*
* Signs an Arbitrum transaction object.
*
* @param {Object} arbitrumTx - The transaction to sign.
* @param {Object} web3 - web3 object.
* @returns {string} The signed transaction raw string.
*/
/**
* Sign arbitrum Transaction
*
* Signs an arbitrum transaction object.
*
* @param {Object} rawTx - The transaction to sign.
* @returns {string} The signed transaction raw string.
*/

async signTransaction(arbitrumTx, privateKey) {
const tx = new Tx(arbitrumTx);
async signTransaction(rawTx, privateKey) {

const pkey = Buffer.from(privateKey, 'hex');
const pkey = Buffer.from(privateKey, 'hex');

tx.sign(pkey);
const common = Common.custom({ chainId: chainId }, { hardfork: Hardfork.London })

const signedTx = `0x${tx.serialize().toString('hex')}`;
const tx = FeeMarketEIP1559Transaction.fromTxData(rawTx, { common });

return signedTx;
}
const signedTransaction = tx.sign(pkey);

const signedTx = bufferToHex(signedTransaction.serialize());

return signedTx
}

/**
* Sign Transaction or Message to get v,r,s
Expand Down
Loading

0 comments on commit 8372b1f

Please sign in to comment.