Socket
Socket
Sign inDemoInstall

@nomicfoundation/ethereumjs-util

Package Overview
Dependencies
Maintainers
2
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nomicfoundation/ethereumjs-util - npm Package Compare versions

Comparing version 8.0.0-rc.3 to 8.0.0

5

dist/account.d.ts

@@ -9,2 +9,3 @@ /// <reference types="node" />

}
export declare type AccountBodyBuffer = [Buffer, Buffer, Buffer | Uint8Array, Buffer | Uint8Array];
export declare class Account {

@@ -120,6 +121,8 @@ nonce: bigint;

export declare const isZeroAddress: (hexAddress: string) => boolean;
export declare function accountBodyFromSlim(body: AccountBodyBuffer): (Uint8Array | Buffer)[];
export declare function accountBodyToSlim(body: AccountBodyBuffer): (Uint8Array | Buffer)[];
/**
* Converts a slim account RLP to a normal account RLP
*/
export declare function convertSlimAccount(body: any): Buffer;
export declare function accountBodyToRLP(body: AccountBodyBuffer, couldBeSlim?: boolean): Buffer;
//# sourceMappingURL=account.d.ts.map

44

dist/account.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.convertSlimAccount = exports.isZeroAddress = exports.zeroAddress = exports.importPublic = exports.privateToAddress = exports.privateToPublic = exports.publicToAddress = exports.pubToAddress = exports.isValidPublic = exports.isValidPrivate = exports.generateAddress2 = exports.generateAddress = exports.isValidChecksumAddress = exports.toChecksumAddress = exports.isValidAddress = exports.Account = void 0;
exports.accountBodyToRLP = exports.accountBodyToSlim = exports.accountBodyFromSlim = exports.isZeroAddress = exports.zeroAddress = exports.importPublic = exports.privateToAddress = exports.privateToPublic = exports.publicToAddress = exports.pubToAddress = exports.isValidPublic = exports.isValidPrivate = exports.generateAddress2 = exports.generateAddress = exports.isValidChecksumAddress = exports.toChecksumAddress = exports.isValidAddress = exports.Account = void 0;
const ethereumjs_rlp_1 = require("@nomicfoundation/ethereumjs-rlp");

@@ -11,3 +11,2 @@ const keccak_1 = require("ethereum-cryptography/keccak");

const internal_1 = require("./internal");
const types_1 = require("./types");
const _0n = BigInt(0);

@@ -28,3 +27,3 @@ class Account {

const { nonce, balance, storageRoot, codeHash } = accountData;
return new Account((0, types_1.isTruthy)(nonce) ? (0, bytes_1.bufferToBigInt)((0, bytes_1.toBuffer)(nonce)) : undefined, (0, types_1.isTruthy)(balance) ? (0, bytes_1.bufferToBigInt)((0, bytes_1.toBuffer)(balance)) : undefined, (0, types_1.isTruthy)(storageRoot) ? (0, bytes_1.toBuffer)(storageRoot) : undefined, (0, types_1.isTruthy)(codeHash) ? (0, bytes_1.toBuffer)(codeHash) : undefined);
return new Account(nonce !== undefined ? (0, bytes_1.bufferToBigInt)((0, bytes_1.toBuffer)(nonce)) : undefined, balance !== undefined ? (0, bytes_1.bufferToBigInt)((0, bytes_1.toBuffer)(balance)) : undefined, storageRoot !== undefined ? (0, bytes_1.toBuffer)(storageRoot) : undefined, codeHash !== undefined ? (0, bytes_1.toBuffer)(codeHash) : undefined);
}

@@ -118,3 +117,3 @@ static fromRlpSerializedAccount(serialized) {

let prefix = '';
if ((0, types_1.isTruthy)(eip1191ChainId)) {
if (eip1191ChainId !== undefined) {
const chainId = (0, bytes_1.bufferToBigInt)((0, bytes_1.toBuffer)(eip1191ChainId));

@@ -279,18 +278,31 @@ prefix = chainId.toString() + '0x';

exports.isZeroAddress = isZeroAddress;
function accountBodyFromSlim(body) {
const [nonce, balance, storageRoot, codeHash] = body;
return [
nonce,
balance,
(0, bytes_1.arrToBufArr)(storageRoot).length === 0 ? constants_1.KECCAK256_RLP : storageRoot,
(0, bytes_1.arrToBufArr)(codeHash).length === 0 ? constants_1.KECCAK256_NULL : codeHash,
];
}
exports.accountBodyFromSlim = accountBodyFromSlim;
const emptyUint8Arr = new Uint8Array(0);
function accountBodyToSlim(body) {
const [nonce, balance, storageRoot, codeHash] = body;
return [
nonce,
balance,
(0, bytes_1.arrToBufArr)(storageRoot).equals(constants_1.KECCAK256_RLP) ? emptyUint8Arr : storageRoot,
(0, bytes_1.arrToBufArr)(codeHash).equals(constants_1.KECCAK256_NULL) ? emptyUint8Arr : codeHash,
];
}
exports.accountBodyToSlim = accountBodyToSlim;
/**
* Converts a slim account RLP to a normal account RLP
*/
function convertSlimAccount(body) {
const cpy = [body[0], body[1], body[2], body[3]];
if ((0, bytes_1.arrToBufArr)(body[2]).length === 0) {
// StorageRoot
cpy[2] = constants_1.KECCAK256_RLP;
}
if ((0, bytes_1.arrToBufArr)(body[3]).length === 0) {
// CodeHash
cpy[3] = constants_1.KECCAK256_NULL;
}
return (0, bytes_1.arrToBufArr)(ethereumjs_rlp_1.RLP.encode(cpy));
function accountBodyToRLP(body, couldBeSlim = true) {
const accountBody = couldBeSlim ? accountBodyFromSlim(body) : body;
return (0, bytes_1.arrToBufArr)(ethereumjs_rlp_1.RLP.encode(accountBody));
}
exports.convertSlimAccount = convertSlimAccount;
exports.accountBodyToRLP = accountBodyToRLP;
//# sourceMappingURL=account.js.map

@@ -45,20 +45,2 @@ /// <reference types="node" />

export declare function toType<T extends TypeOutput>(input: ToBufferInputTypes, outputType: T): TypeOutputReturnType[T];
declare type Falsy = false | '' | 0 | null | undefined | 0n;
/**
* Returns true if a value is falsy
*
* @param value - Value to check for falseness
*
* @deprecated This helper function should only be used temporarily until the monorepo types are explicit enough
*/
export declare function isFalsy(value: unknown): value is Falsy;
/**
* Returns true if a value is truthy
*
* @param value - Value to check for truthiness
*
* @deprecated This helper function should only be used temporarily until the monorepo types are explicit enough
*/
export declare function isTruthy<T>(value: T | Falsy): value is T;
export {};
//# sourceMappingURL=types.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isTruthy = exports.isFalsy = exports.toType = exports.TypeOutput = void 0;
exports.toType = exports.TypeOutput = void 0;
const bytes_1 = require("./bytes");

@@ -49,30 +49,2 @@ const internal_1 = require("./internal");

exports.toType = toType;
/**
* Returns true if a value is falsy
*
* @param value - Value to check for falseness
*
* @deprecated This helper function should only be used temporarily until the monorepo types are explicit enough
*/
function isFalsy(value) {
return !!(value === false ||
value === '' ||
value === 0 ||
Number.isNaN(value) ||
value === null ||
typeof value === 'undefined' ||
value === BigInt(0));
}
exports.isFalsy = isFalsy;
/**
* Returns true if a value is truthy
*
* @param value - Value to check for truthiness
*
* @deprecated This helper function should only be used temporarily until the monorepo types are explicit enough
*/
function isTruthy(value) {
return !isFalsy(value);
}
exports.isTruthy = isTruthy;
//# sourceMappingURL=types.js.map
{
"name": "@nomicfoundation/ethereumjs-util",
"version": "8.0.0-rc.3",
"version": "8.0.0",
"description": "A collection of utility functions for Ethereum",

@@ -5,0 +5,0 @@ "keywords": [

@@ -22,3 +22,2 @@ import { RLP } from '@nomicfoundation/ethereumjs-rlp'

import { stripHexPrefix } from './internal'
import { isTruthy } from './types'

@@ -36,2 +35,4 @@ import type { BigIntLike, BufferLike } from './types'

export type AccountBodyBuffer = [Buffer, Buffer, Buffer | Uint8Array, Buffer | Uint8Array]
export class Account {

@@ -47,6 +48,6 @@ nonce: bigint

return new Account(
isTruthy(nonce) ? bufferToBigInt(toBuffer(nonce)) : undefined,
isTruthy(balance) ? bufferToBigInt(toBuffer(balance)) : undefined,
isTruthy(storageRoot) ? toBuffer(storageRoot) : undefined,
isTruthy(codeHash) ? toBuffer(codeHash) : undefined
nonce !== undefined ? bufferToBigInt(toBuffer(nonce)) : undefined,
balance !== undefined ? bufferToBigInt(toBuffer(balance)) : undefined,
storageRoot !== undefined ? toBuffer(storageRoot) : undefined,
codeHash !== undefined ? toBuffer(codeHash) : undefined
)

@@ -168,3 +169,3 @@ }

let prefix = ''
if (isTruthy(eip1191ChainId)) {
if (eip1191ChainId !== undefined) {
const chainId = bufferToBigInt(toBuffer(eip1191ChainId))

@@ -345,16 +346,29 @@ prefix = chainId.toString() + '0x'

export function accountBodyFromSlim(body: AccountBodyBuffer) {
const [nonce, balance, storageRoot, codeHash] = body
return [
nonce,
balance,
arrToBufArr(storageRoot).length === 0 ? KECCAK256_RLP : storageRoot,
arrToBufArr(codeHash).length === 0 ? KECCAK256_NULL : codeHash,
]
}
const emptyUint8Arr = new Uint8Array(0)
export function accountBodyToSlim(body: AccountBodyBuffer) {
const [nonce, balance, storageRoot, codeHash] = body
return [
nonce,
balance,
arrToBufArr(storageRoot).equals(KECCAK256_RLP) ? emptyUint8Arr : storageRoot,
arrToBufArr(codeHash).equals(KECCAK256_NULL) ? emptyUint8Arr : codeHash,
]
}
/**
* Converts a slim account RLP to a normal account RLP
*/
export function convertSlimAccount(body: any) {
const cpy = [body[0], body[1], body[2], body[3]]
if (arrToBufArr(body[2]).length === 0) {
// StorageRoot
cpy[2] = KECCAK256_RLP
}
if (arrToBufArr(body[3]).length === 0) {
// CodeHash
cpy[3] = KECCAK256_NULL
}
return arrToBufArr(RLP.encode(cpy))
export function accountBodyToRLP(body: AccountBodyBuffer, couldBeSlim = true) {
const accountBody = couldBeSlim ? accountBodyFromSlim(body) : body
return arrToBufArr(RLP.encode(accountBody))
}

@@ -123,33 +123,1 @@ import { bufferToBigInt, bufferToHex, toBuffer } from './bytes'

}
type Falsy = false | '' | 0 | null | undefined | 0n
/**
* Returns true if a value is falsy
*
* @param value - Value to check for falseness
*
* @deprecated This helper function should only be used temporarily until the monorepo types are explicit enough
*/
export function isFalsy(value: unknown): value is Falsy {
return !!(
value === false ||
value === '' ||
value === 0 ||
Number.isNaN(value) ||
value === null ||
typeof value === 'undefined' ||
value === BigInt(0)
)
}
/**
* Returns true if a value is truthy
*
* @param value - Value to check for truthiness
*
* @deprecated This helper function should only be used temporarily until the monorepo types are explicit enough
*/
export function isTruthy<T>(value: T | Falsy): value is T {
return !isFalsy(value)
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc