Skip to content

Commit

Permalink
Merge pull request #22 from getsafle/test
Browse files Browse the repository at this point in the history
Updated sign transaction to use ethereumjs-tx module
  • Loading branch information
sshubhamagg authored Feb 15, 2024
2 parents e3cb43b + c3b3a5b commit c5419ad
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 196 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@
##### Updated 'main' path and Updated signTransaction Method.

- Updated 'main' path to "src/index.js" .
- Removed signTransaction() dependency from getFees().
- Removed signTransaction() dependency from getFees().

### 1.0.1 (2024-02-15)

- Updated sign transaction to use ethereumjs-tx module.
- Removed unused dependencies.
214 changes: 32 additions & 182 deletions package-lock.json

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

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@getsafle/vault-polygon-zkevm-controller",
"version": "1.0.0",
"version": "1.0.1",
"description": "Polygon zkEVM controller for Safle Vault",
"main": "src/index.js",
"scripts": {
Expand Down Expand Up @@ -45,15 +45,14 @@
"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.2.0",
"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
15 changes: 5 additions & 10 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ const { normalize: normalizeAddress } = require('eth-sig-util')
const SimpleKeyring = require('eth-simple-keyring')
const HdKeyring = require('eth-hd-keyring')

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

const axios = require('axios')
Expand Down Expand Up @@ -264,17 +263,13 @@ class KeyringController extends EventEmitter {

async signTransaction(rawTx, privateKey) {

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

const chainId = rawTx.chainId;

const common = Common.custom({ chainId: chainId }, { hardfork: Hardfork.Istanbul })
const tx = new Tx(rawTx);

const tx = LegacyTransaction.fromTxData(rawTx, { common })
const pkey = Buffer.from(privateKey, 'hex');

const signedTransaction = tx.sign(pkey);
tx.sign(pkey);

const signedTx = bufferToHex(signedTransaction.serialize());
const signedTx = `0x${tx.serialize().toString('hex')}`;

return signedTx
}
Expand Down

0 comments on commit c5419ad

Please sign in to comment.