diff --git a/packages/sdk/utils/package.json b/packages/sdk/utils/package.json index f3429dc9d..8881b81cc 100644 --- a/packages/sdk/utils/package.json +++ b/packages/sdk/utils/package.json @@ -23,6 +23,7 @@ ], "dependencies": { "@celo/base": "^6.0.0", + "@ethereumjs/rlp": "^5.0.2", "@ethereumjs/util": "8.0.5", "@noble/ciphers": "0.4.1", "@noble/curves": "1.3.0", @@ -32,7 +33,6 @@ "bignumber.js": "^9.0.0", "fp-ts": "2.1.1", "io-ts": "2.0.1", - "rlp": "^2.2.4", "web3-eth-abi": "1.10.0", "web3-utils": "1.10.0" }, diff --git a/packages/sdk/utils/src/istanbul.ts b/packages/sdk/utils/src/istanbul.ts index 4ee6bcb08..5ab7f9be9 100644 --- a/packages/sdk/utils/src/istanbul.ts +++ b/packages/sdk/utils/src/istanbul.ts @@ -1,6 +1,7 @@ import { bufferToHex, toChecksumAddress } from '@ethereumjs/util' import BigNumber from 'bignumber.js' -import * as rlp from 'rlp' +// import * as rlp from 'rlp' +import * as rlp from '@ethereumjs/rlp' import { Address } from './address' // This file contains utilities that help with istanbul-specific block information. @@ -42,14 +43,19 @@ function sealFromBuffers(data: Buffer[]): Seal { // Parse RLP encoded block extra data into an IstanbulExtra object. export function parseBlockExtraData(data: string): IstanbulExtra { const buffer = Buffer.from(data.replace(/^0x/, ''), 'hex') - const decode: any = rlp.decode('0x' + buffer.slice(ISTANBUL_EXTRA_VANITY_BYTES).toString('hex')) + const decode = rlp.decode('0x' + buffer.subarray(ISTANBUL_EXTRA_VANITY_BYTES).toString('hex')) + return { - addedValidators: decode[0].map((addr: Buffer) => toChecksumAddress(bufferToHex(addr))), - addedValidatorsPublicKeys: decode[1].map((key: Buffer) => '0x' + key.toString('hex')), - removedValidators: bigNumberFromBuffer(decode[2]), - seal: '0x' + decode[3].toString('hex'), - aggregatedSeal: sealFromBuffers(decode[4]), - parentAggregatedSeal: sealFromBuffers(decode[5]), + addedValidators: (decode.at(0) as Uint8Array[]).map((addr) => + toChecksumAddress(bufferToHex(Buffer.from(addr))) + ), + addedValidatorsPublicKeys: (decode.at(1) as Uint8Array[]).map( + (key) => '0x' + Buffer.from(key).toString('hex') + ), + removedValidators: bigNumberFromBuffer(Buffer.from(decode.at(2) as Uint8Array)), + seal: '0x' + Buffer.from(decode.at(3) as Uint8Array).toString('hex'), + aggregatedSeal: sealFromBuffers((decode.at(4) as Uint8Array[]).map(Buffer.from)), + parentAggregatedSeal: sealFromBuffers((decode.at(5) as Uint8Array[]).map(Buffer.from)), } }