Migrate from ethereumjs-tx to @ethereumjs/tx

pull/445/head
Yannick Huard 4 years ago
parent 34f0f3f816
commit 02ea2da0da
  1. 9
      dist/es/sign-transaction.js
  2. 8
      dist/lib/sign-transaction.js
  3. 2
      package.json
  4. 9
      src/sign-transaction.js
  5. 6
      test/integration.test.js
  6. 6
      test/unit.test.js

@ -1,4 +1,5 @@
import { Transaction } from 'ethereumjs-tx';
import { Transaction } from '@ethereumjs/tx';
import publicKeyByPrivateKey from './public-key-by-private-key';
import { toAddress as addressByPublicKey } from './public-key';
@ -11,8 +12,8 @@ export default function signTransaction(rawTx, privateKey) {
var privateKeyBuffer = Buffer.from(privateKey.replace(/^.{2}/g, ''), 'hex');
var tx = new Transaction(rawTx);
tx.sign(privateKeyBuffer);
var serializedTx = tx.serialize().toString('hex');
var tx = Transaction.fromTxData(rawTx);
var signedTx = tx.sign(privateKeyBuffer);
var serializedTx = signedTx.serialize().toString('hex');
return serializedTx;
}

@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
});
exports['default'] = signTransaction;
var _ethereumjsTx = require('ethereumjs-tx');
var _tx = require('@ethereumjs/tx');
var _publicKeyByPrivateKey = require('./public-key-by-private-key');
@ -24,8 +24,8 @@ function signTransaction(rawTx, privateKey) {
var privateKeyBuffer = Buffer.from(privateKey.replace(/^.{2}/g, ''), 'hex');
var tx = new _ethereumjsTx.Transaction(rawTx);
tx.sign(privateKeyBuffer);
var serializedTx = tx.serialize().toString('hex');
var tx = _tx.Transaction.fromTxData(rawTx);
var signedTx = tx.sign(privateKeyBuffer);
var serializedTx = signedTx.serialize().toString('hex');
return serializedTx;
}

@ -108,11 +108,11 @@
"webpack-cli": "4.7.2"
},
"dependencies": {
"@ethereumjs/tx": "3.2.1",
"@types/bn.js": "5.1.0",
"babel-runtime": "6.26.0",
"eccrypto": "1.1.6",
"eth-lib": "0.2.8",
"ethereumjs-tx": "2.1.2",
"ethereumjs-util": "7.0.10",
"ethers": "5.3.1",
"secp256k1": "4.0.2"

@ -1,4 +1,5 @@
import { Transaction } from 'ethereumjs-tx';
import { Transaction } from '@ethereumjs/tx';
import publicKeyByPrivateKey from './public-key-by-private-key';
import {
toAddress as addressByPublicKey
@ -17,8 +18,8 @@ export default function signTransaction(
const privateKeyBuffer = Buffer.from(privateKey.replace(/^.{2}/g, ''), 'hex');
const tx = new Transaction(rawTx);
tx.sign(privateKeyBuffer);
const serializedTx = tx.serialize().toString('hex');
const tx = Transaction.fromTxData(rawTx);
const signedTx = tx.sign(privateKeyBuffer);
const serializedTx = signedTx.serialize().toString('hex');
return serializedTx;
}

@ -43,7 +43,7 @@ describe('integration.test.js', () => {
state.accounts.push(identity);
const twoStripped = identity.privateKey.replace(/^.{2}/g, '');
return {
secretKey: new Buffer(twoStripped, 'hex'),
secretKey: Buffer.from(twoStripped, 'hex'),
balance: state.web3.utils.toWei('100', 'ether')
};
});
@ -87,7 +87,7 @@ describe('integration.test.js', () => {
.fill(0)
.map(() => EthCrypto.createIdentity())
.map(identity => ({
secretKey: new Buffer(identity.privateKey.replace(/^.{2}/g, ''), 'hex'),
secretKey: Buffer.from(identity.privateKey.replace(/^.{2}/g, ''), 'hex'),
balance: web3.utils.toWei('100', 'ether')
}));
web3.setProvider(ganache.provider({
@ -101,7 +101,7 @@ describe('integration.test.js', () => {
web3.transactionConfirmationBlocks = WEB3_CONFIRMATION_BLOCKS;
web3.setProvider(ganache.provider({
accounts: [{
secretKey: new Buffer(identity.privateKey.replace(/^.{2}/g, ''), 'hex'),
secretKey: Buffer.from(identity.privateKey.replace(/^.{2}/g, ''), 'hex'),
balance: web3.utils.toWei('100', 'ether')
}]
}));

@ -284,21 +284,21 @@ describe('unit.test.js', () => {
const compressed = '03a34d6aef3eb42335fb3cacb59478c0b44c0bbeb8bb4ca427dbc7044157a5d24b';
const uncompressed = EthCrypto.publicKey.decompress(compressed);
assert.equal(typeof uncompressed, 'string');
const buf = new Buffer(uncompressed, 'hex');
const buf = Buffer.from(uncompressed, 'hex');
assert.equal(buf.length, 64);
});
it('should work when already uncompressed', () => {
const compressed = '04a34d6aef3eb42335fb3cacb59478c0b44c0bbeb8bb4ca427dbc7044157a5d24b4adf14868d8449c9b3e50d3d6338f3e5a2d3445abe679cddbe75cb893475806f';
const uncompressed = EthCrypto.publicKey.decompress(compressed);
assert.equal(typeof uncompressed, 'string');
const buf = new Buffer(uncompressed, 'hex');
const buf = Buffer.from(uncompressed, 'hex');
assert.equal(buf.length, 64);
});
it('should work when already uncompressed (no04)', () => {
const compressed = 'a34d6aef3eb42335fb3cacb59478c0b44c0bbeb8bb4ca427dbc7044157a5d24b4adf14868d8449c9b3e50d3d6338f3e5a2d3445abe679cddbe75cb893475806f';
const uncompressed = EthCrypto.publicKey.decompress(compressed);
assert.equal(typeof uncompressed, 'string');
const buf = new Buffer(uncompressed, 'hex');
const buf = Buffer.from(uncompressed, 'hex');
assert.equal(buf.length, 64);
});
});

Loading…
Cancel
Save