Skip to content

Commit

Permalink
chore: bump @ethereumjs/tx from 4.1.2 to 5.2.1 (#1293)
Browse files Browse the repository at this point in the history
* chore: bump @ethereumjs/tx from 4.1.2 to 5.0.0

Bumps [@ethereumjs/tx](https://github.com/ethereumjs/ethereumjs-monorepo) from 4.1.2 to 5.0.0.
- [Release notes](https://github.com/ethereumjs/ethereumjs-monorepo/releases)
- [Commits](https://github.com/ethereumjs/ethereumjs-monorepo/compare/@ethereumjs/[email protected]...@ethereumjs/[email protected])

---
updated-dependencies:
- dependency-name: "@ethereumjs/tx"
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>

* update codebase to ethereumjs update

* rename buffer

* fix: use correct package

* chore: revert type conversion

* chore: rename buffer -> array

* chore: move packages to shared folder

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Mark Nardi <[email protected]>
Co-authored-by: Tuditi <[email protected]>
Co-authored-by: Tuditi <[email protected]>
  • Loading branch information
4 people authored Feb 15, 2024
1 parent fdadc57 commit 20f3755
Show file tree
Hide file tree
Showing 14 changed files with 1,661 additions and 1,353 deletions.
3 changes: 0 additions & 3 deletions packages/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
},
"dependencies": {
"@amplitude/analytics-node": "1.3.5",
"@ethereumjs/rlp": "4.0.1",
"@ethereumjs/tx": "4.1.2",
"@ethereumjs/util": "9.0.1",
"@ledgerhq/hw-app-eth": "6.34.8",
"@ledgerhq/hw-transport-node-hid": "6.28.3",
"@ledgerhq/logs": "6.10.1",
Expand Down
3 changes: 3 additions & 0 deletions packages/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
"license": "Apache-2.0",
"dependencies": {
"@bloomwalletio/ui": "0.20.1",
"@ethereumjs/rlp": "4.0.1",
"@ethereumjs/tx": "5.2.1",
"@ethereumjs/util": "9.0.2",
"@iota/bundle": "1.0.0-beta.30",
"@iota/converter": "1.0.0-beta.30",
"@iota/crypto.js": "1.8.6",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import type { TxData } from '@ethereumjs/tx'
import type { TypedTxData } from '@ethereumjs/tx'

export type EvmTransactionData = TxData & { estimatedGas?: number; timestamp?: number }
export type EvmTransactionData = TypedTxData & { estimatedGas?: number; timestamp?: number }
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TxData } from '@ethereumjs/tx'
import { TypedTxData } from '@ethereumjs/tx'
import { isTrackedNftAddress, isTrackedTokenAddress } from '@core/wallet/actions'
import { ISC_MAGIC_CONTRACT_ADDRESS, WEI_PER_GLOW } from '../constants'
import { ERC20_ABI, ERC721_ABI, ISC_SANDBOX_ABI } from '../abis'
Expand All @@ -24,7 +24,7 @@ type TransferInfo =
| { type: ActivityType.Nft; nftId: string; additionalBaseTokenAmount?: bigint; recipientAddress: string }
| { type: ActivityType.SmartContract }

export function getTransferInfoFromTransactionData(transaction: TxData, chain: IChain): TransferInfo | undefined {
export function getTransferInfoFromTransactionData(transaction: TypedTxData, chain: IChain): TransferInfo | undefined {
const networkId = chain.getConfiguration().id

const recipientAddress = transaction.to?.toString()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { EvmChainId, getEvmTransactionOptions } from '@core/network'
import { HEX_PREFIX } from '@core/utils'
import { RLP } from '@ethereumjs/rlp'
import { Transaction } from '@ethereumjs/tx'
import { bufArrToArr } from '@ethereumjs/util'
import { TransactionFactory } from '@ethereumjs/tx'
import { IEvmSignature } from '../interfaces'
import { EvmTransactionData } from '../types'

Expand All @@ -14,8 +13,9 @@ export function prepareEvmTransaction(
const { r, v, s } = transactionSignature ?? {}
const isSigned = r && v && s
const preparedTransactionData = isSigned ? { ...transactionData, r, v, s } : transactionData
const transaction = Transaction.fromTxData(preparedTransactionData, getEvmTransactionOptions(chainId))
const transactionBuffer = isSigned ? transaction.raw() : transaction.getMessageToSign(false)
const transactionHex = Buffer.from(RLP.encode(bufArrToArr(transactionBuffer))).toString('hex')
const transaction = TransactionFactory.fromTxData(preparedTransactionData, getEvmTransactionOptions(chainId))

const rawMessage = isSigned ? transaction.raw() : transaction.getMessageToSign()
const transactionHex = Buffer.from(RLP.encode(rawMessage)).toString('hex')
return isSigned ? HEX_PREFIX + transactionHex : transactionHex
}
4 changes: 2 additions & 2 deletions packages/shared/src/lib/core/ledger/classes/ledger.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
prepareEvmTransaction,
} from '@core/layer-2/utils'
import { Converter, MILLISECONDS_PER_SECOND, sleep } from '@core/utils'
import { TxData } from '@ethereumjs/tx'
import { TypedTxData } from '@ethereumjs/tx'
import type { Bip44 } from '@iota/sdk/out/types'
import { PopupId, closePopup, openPopup } from '../../../../../../desktop/lib/auxiliary/popup'
import { DEFAULT_LEDGER_API_REQUEST_OPTIONS } from '../constants'
Expand Down Expand Up @@ -65,7 +65,7 @@ export class Ledger {
}

static async signEvmTransaction(
transactionData: TxData,
transactionData: TypedTxData,
chainId: EvmChainId,
bip44: Bip44
): Promise<string | undefined> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,45 +1,44 @@
import { TxData } from '@ethereumjs/tx'
import { LegacyTransaction, TransactionFactory, TypedTxData } from '@ethereumjs/tx'
import { prepareEvmTransaction } from '@core/layer-2/utils'
import { EvmChainId, getEvmTransactionOptions } from '@core/network'
import { removeLeadingZeros } from '@core/utils/buffer'
import { Transaction } from '@ethereumjs/tx'
import { removeLeadingZeros } from '@core/utils/array'
import { ECDSASignature } from '@ethereumjs/util'
import type { Bip44 } from '@iota/sdk/out/types'
import { getSignatureForStringWithStronghold } from './getSignatureForStringWithStronghold'
import { HEX_PREFIX } from '@core/utils'

export async function signEvmTransactionWithStronghold(
txData: TxData,
txData: TypedTxData,
chainId: EvmChainId,
bip44Path: Bip44
): Promise<string> {
const unsignedTransactionMessageHex = HEX_PREFIX + prepareEvmTransaction(txData, chainId)
const transaction = Transaction.fromTxData(txData, getEvmTransactionOptions(chainId))
const transaction = TransactionFactory.fromTxData(txData, getEvmTransactionOptions(chainId)) as LegacyTransaction

const signature = await getSignatureForStringWithStronghold(unsignedTransactionMessageHex, bip44Path, chainId)
const signedTransaction = createSignedTransaction(transaction, signature, chainId)
return getHexEncodedTransaction(signedTransaction)
}

function createSignedTransaction(
transaction: Transaction,
transaction: LegacyTransaction,
signature: ECDSASignature,
chainId: EvmChainId
): Transaction {
): LegacyTransaction {
const rawTx = transaction.raw()

const vHex = padHexString(signature.v.toString(16))
rawTx[6] = Buffer.from(vHex, 'hex')
rawTx[7] = removeLeadingZeros(signature.r)
rawTx[8] = removeLeadingZeros(signature.s)
const signedTransaction = Transaction.fromValuesArray(rawTx, getEvmTransactionOptions(chainId))
const signedTransaction = LegacyTransaction.fromValuesArray(rawTx, getEvmTransactionOptions(chainId))

return signedTransaction
}

function getHexEncodedTransaction(transaction: Transaction): string {
function getHexEncodedTransaction(transaction: LegacyTransaction): string {
const serializedTransaction = transaction.serialize()
const hexEncodedTransaction = HEX_PREFIX + serializedTransaction.toString('hex')
const hexEncodedTransaction = HEX_PREFIX + Buffer.from(serializedTransaction).toString('hex')
return hexEncodedTransaction
}

Expand Down
11 changes: 11 additions & 0 deletions packages/shared/src/lib/core/utils/array.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export function removeLeadingZeros(array: Uint8Array): Uint8Array {
let indexToSliceFrom = 0
for (let i = 0; i < array.length; i++) {
if (array[i] === 0) {
indexToSliceFrom = i + 1
} else {
break
}
}
return array.subarray(indexToSliceFrom)
}
11 changes: 0 additions & 11 deletions packages/shared/src/lib/core/utils/buffer.ts

This file was deleted.

7 changes: 3 additions & 4 deletions packages/shared/src/lib/core/utils/convert.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable no-bitwise */
import { BigIntLike, bufferToBigInt } from '@ethereumjs/util'
import { BigIntLike, bytesToBigInt } from '@ethereumjs/util'

import { HEX_PREFIX, MILLISECONDS_PER_SECOND } from './constants'
import { isValidDate } from './date'
Expand Down Expand Up @@ -306,8 +305,8 @@ export class Converter {
* @returns The bytes.
*/
public static bigIntLikeToBigInt(number: BigIntLike | undefined): bigint {
if (Buffer.isBuffer(number)) {
return bufferToBigInt(number)
if (ArrayBuffer.isView(number)) {
return bytesToBigInt(number)
} else {
return BigInt(String(number ?? '0'))
}
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/lib/core/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export * from './abiDecoder'
export * from './api'
export * from './buffer'
export * from './array'
export * from './constants'
export * from './crypto'
export * from './enums'
Expand Down
24 changes: 24 additions & 0 deletions packages/shared/src/lib/core/utils/tests/array.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { removeLeadingZeros } from '../array'

describe('array', () => {
test('Removes leading zeros', () => {
const array = Uint8Array.from([0, 0, 1])
expect(removeLeadingZeros(array)).toEqual(Uint8Array.from([1]))
})

test('Uint8Array contains non-zero elements only', () => {
const array1 = Uint8Array.from([1, 2, 3])
expect(removeLeadingZeros(array1)).toEqual(array1)

const array2 = Uint8Array.from([1])
expect(removeLeadingZeros(array2)).toEqual(array2)

const array3 = Uint8Array.from([1, 0, 0])
expect(removeLeadingZeros(array3)).toEqual(array3)
})

test('Keeps non-leading zeros untouched', () => {
const array = Uint8Array.from([1, 0, 0, 1])
expect(removeLeadingZeros(array)).toEqual(array)
})
})
24 changes: 0 additions & 24 deletions packages/shared/src/lib/core/utils/tests/buffer.test.ts

This file was deleted.

Loading

0 comments on commit 20f3755

Please sign in to comment.