Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ethereumjs/trie

Package Overview
Dependencies
Maintainers
0
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ethereumjs/trie - npm Package Compare versions

Comparing version 6.2.0 to 6.2.1

2

dist/cjs/db/checkpoint.js

@@ -34,3 +34,2 @@ "use strict";

if (this.cacheSize > 0) {
// @ts-ignore
this._cache = new lru_cache_1.LRUCache({

@@ -214,2 +213,3 @@ max: this.cacheSize,

};
this._stats.db.writes += 1;
if (op.type === 'put' && this.valueEncoding === util_1.ValueEncoding.String) {

@@ -216,0 +216,0 @@ convertedOp.value = (0, util_1.bytesToUnprefixedHex)(convertedOp.value);

@@ -5,2 +5,3 @@ // Some more secure presets when using e.g. JS `call`

exports.Trie = void 0;
const rlp_1 = require("@ethereumjs/rlp");
const util_1 = require("@ethereumjs/util");

@@ -402,4 +403,6 @@ const debug_1 = require("debug");

const deleteHashes = stack.map((e) => this.hash(e.serialize()));
ops = deleteHashes.map((e) => {
const key = this._opts.keyPrefix ? (0, util_1.concatBytes)(this._opts.keyPrefix, e) : e;
ops = deleteHashes.map((deletedHash) => {
const key = this._opts.keyPrefix
? (0, util_1.concatBytes)(this._opts.keyPrefix, deletedHash)
: deletedHash;
return {

@@ -442,4 +445,6 @@ type: 'del',

// So after deleting the node, one can safely delete these from the DB
ops = deleteHashes.map((e) => {
const key = this._opts.keyPrefix ? (0, util_1.concatBytes)(this._opts.keyPrefix, e) : e;
ops = deleteHashes.map((deletedHash) => {
const key = this._opts.keyPrefix
? (0, util_1.concatBytes)(this._opts.keyPrefix, deletedHash)
: deletedHash;
return {

@@ -828,5 +833,7 @@ type: 'del',

if (this._opts.useNodePruning) {
// If the branchNode has length < 32, it will be a RawNode (Uint8Array[]) instead of a Uint8Array
// In that case, we need to serialize and hash it into a Uint8Array, otherwise the operation will throw
opStack.push({
type: 'del',
key: branchNode,
key: (0, index_js_2.isRawNode)(branchNode) ? this.appliedKey(rlp_1.RLP.encode(branchNode)) : branchNode,
});

@@ -862,20 +869,18 @@ }

const node = stack.pop();
if (node instanceof index_js_2.LeafNode) {
key.splice(key.length - node.key().length);
if (node === undefined) {
throw new Error('saveStack: missing node');
}
else if (node instanceof index_js_2.ExtensionNode) {
if (node instanceof index_js_2.LeafNode || node instanceof index_js_2.ExtensionNode) {
key.splice(key.length - node.key().length);
if (lastRoot) {
node.value(lastRoot);
}
}
else if (node instanceof index_js_2.BranchNode) {
if (lastRoot) {
const branchKey = key.pop();
node.setBranch(branchKey, lastRoot);
}
if (node instanceof index_js_2.ExtensionNode && lastRoot !== undefined) {
node.value(lastRoot);
}
if (node instanceof index_js_2.BranchNode && lastRoot !== undefined) {
const branchKey = key.pop();
node.setBranch(branchKey, lastRoot);
}
lastRoot = this._formatNode(node, stack.length === 0, opStack);
}
if (lastRoot) {
if (lastRoot !== undefined) {
this.root(lastRoot);

@@ -965,3 +970,3 @@ }

try {
await this.walkTrie(this.root(), async function (nodeRef, node, key, controller) {
await this.walkTrie(this.root(), async function (_, node, key, controller) {
if (found) {

@@ -974,3 +979,4 @@ // Abort all other children checks

// If one of the branches matches the key, then it is found
if (item !== null && (0, util_1.bytesToUnprefixedHex)(item) === dbkey) {
if (item !== null &&
(0, util_1.bytesToUnprefixedHex)((0, index_js_2.isRawNode)(item) ? controller.trie.appliedKey(rlp_1.RLP.encode(item)) : item) === dbkey) {
found = true;

@@ -977,0 +983,0 @@ return;

@@ -159,3 +159,3 @@ "use strict";

const pathToHexKey = (path, extension, retType) => {
const b = (0, util_1.hexToBytes)('0x' + path);
const b = (0, util_1.hexToBytes)(`0x${path}`);
const n = (0, exports.byteTypeToNibbleType)(b);

@@ -162,0 +162,0 @@ if (retType === 'hex') {

@@ -14,3 +14,3 @@ "use strict";

for (const [key, value] of Object.entries(genesisState)) {
const address = (0, util_1.isHexPrefixed)(key) ? (0, util_1.toBytes)(key) : (0, util_1.unprefixedHexToBytes)(key);
const address = (0, util_1.isHexString)(key) ? (0, util_1.hexToBytes)(key) : (0, util_1.unprefixedHexToBytes)(key);
const account = new util_1.Account();

@@ -26,3 +26,3 @@ if (typeof value === 'string') {

if (code !== undefined) {
const codeBytes = (0, util_1.isHexPrefixed)(code) ? (0, util_1.toBytes)(code) : (0, util_1.unprefixedHexToBytes)(code);
const codeBytes = (0, util_1.isHexString)(code) ? (0, util_1.hexToBytes)(code) : (0, util_1.unprefixedHexToBytes)(code);
account.codeHash = (0, keccak_js_1.keccak256)(codeBytes);

@@ -33,4 +33,4 @@ }

for (const [k, val] of storage) {
const storageKey = (0, util_1.isHexPrefixed)(k) ? (0, util_1.toBytes)(k) : (0, util_1.unprefixedHexToBytes)(k);
const storageVal = rlp_1.RLP.encode((0, util_1.unpadBytes)((0, util_1.isHexPrefixed)(val) ? (0, util_1.toBytes)(val) : (0, util_1.unprefixedHexToBytes)(val)));
const storageKey = (0, util_1.isHexString)(k) ? (0, util_1.hexToBytes)(k) : (0, util_1.unprefixedHexToBytes)(k);
const storageVal = rlp_1.RLP.encode((0, util_1.unpadBytes)((0, util_1.isHexString)(val) ? (0, util_1.hexToBytes)(val) : (0, util_1.unprefixedHexToBytes)(val)));
await storageTrie.put(storageKey, storageVal);

@@ -37,0 +37,0 @@ }

@@ -31,3 +31,2 @@ import { KeyEncoding, ValueEncoding, bytesToUnprefixedHex, unprefixedHexToBytes, } from '@ethereumjs/util';

if (this.cacheSize > 0) {
// @ts-ignore
this._cache = new LRUCache({

@@ -211,2 +210,3 @@ max: this.cacheSize,

};
this._stats.db.writes += 1;
if (op.type === 'put' && this.valueEncoding === ValueEncoding.String) {

@@ -213,0 +213,0 @@ convertedOp.value = bytesToUnprefixedHex(convertedOp.value);

// Some more secure presets when using e.g. JS `call`
'use strict';
import { RLP } from '@ethereumjs/rlp';
import { KeyEncoding, Lock, MapDB, RLP_EMPTY_STRING, ValueEncoding, bytesToHex, bytesToUnprefixedHex, bytesToUtf8, concatBytes, equalsBytes, unprefixedHexToBytes, } from '@ethereumjs/util';

@@ -399,4 +400,6 @@ import debug from 'debug';

const deleteHashes = stack.map((e) => this.hash(e.serialize()));
ops = deleteHashes.map((e) => {
const key = this._opts.keyPrefix ? concatBytes(this._opts.keyPrefix, e) : e;
ops = deleteHashes.map((deletedHash) => {
const key = this._opts.keyPrefix
? concatBytes(this._opts.keyPrefix, deletedHash)
: deletedHash;
return {

@@ -439,4 +442,6 @@ type: 'del',

// So after deleting the node, one can safely delete these from the DB
ops = deleteHashes.map((e) => {
const key = this._opts.keyPrefix ? concatBytes(this._opts.keyPrefix, e) : e;
ops = deleteHashes.map((deletedHash) => {
const key = this._opts.keyPrefix
? concatBytes(this._opts.keyPrefix, deletedHash)
: deletedHash;
return {

@@ -825,5 +830,7 @@ type: 'del',

if (this._opts.useNodePruning) {
// If the branchNode has length < 32, it will be a RawNode (Uint8Array[]) instead of a Uint8Array
// In that case, we need to serialize and hash it into a Uint8Array, otherwise the operation will throw
opStack.push({
type: 'del',
key: branchNode,
key: isRawNode(branchNode) ? this.appliedKey(RLP.encode(branchNode)) : branchNode,
});

@@ -859,20 +866,18 @@ }

const node = stack.pop();
if (node instanceof LeafNode) {
key.splice(key.length - node.key().length);
if (node === undefined) {
throw new Error('saveStack: missing node');
}
else if (node instanceof ExtensionNode) {
if (node instanceof LeafNode || node instanceof ExtensionNode) {
key.splice(key.length - node.key().length);
if (lastRoot) {
node.value(lastRoot);
}
}
else if (node instanceof BranchNode) {
if (lastRoot) {
const branchKey = key.pop();
node.setBranch(branchKey, lastRoot);
}
if (node instanceof ExtensionNode && lastRoot !== undefined) {
node.value(lastRoot);
}
if (node instanceof BranchNode && lastRoot !== undefined) {
const branchKey = key.pop();
node.setBranch(branchKey, lastRoot);
}
lastRoot = this._formatNode(node, stack.length === 0, opStack);
}
if (lastRoot) {
if (lastRoot !== undefined) {
this.root(lastRoot);

@@ -962,3 +967,3 @@ }

try {
await this.walkTrie(this.root(), async function (nodeRef, node, key, controller) {
await this.walkTrie(this.root(), async function (_, node, key, controller) {
if (found) {

@@ -971,3 +976,4 @@ // Abort all other children checks

// If one of the branches matches the key, then it is found
if (item !== null && bytesToUnprefixedHex(item) === dbkey) {
if (item !== null &&
bytesToUnprefixedHex(isRawNode(item) ? controller.trie.appliedKey(RLP.encode(item)) : item) === dbkey) {
found = true;

@@ -974,0 +980,0 @@ return;

@@ -147,3 +147,3 @@ import { hexToBytes, toBytes, unprefixedHexToBytes } from '@ethereumjs/util';

export const pathToHexKey = (path, extension, retType) => {
const b = hexToBytes('0x' + path);
const b = hexToBytes(`0x${path}`);
const n = byteTypeToNibbleType(b);

@@ -150,0 +150,0 @@ if (retType === 'hex') {

import { RLP } from '@ethereumjs/rlp';
import { Account, isHexPrefixed, toBytes, unpadBytes, unprefixedHexToBytes } from '@ethereumjs/util';
import { Account, hexToBytes, isHexString, unpadBytes, unprefixedHexToBytes, } from '@ethereumjs/util';
import { keccak256 } from 'ethereum-cryptography/keccak.js';

@@ -11,3 +11,3 @@ import { Trie } from '../trie.js';

for (const [key, value] of Object.entries(genesisState)) {
const address = isHexPrefixed(key) ? toBytes(key) : unprefixedHexToBytes(key);
const address = isHexString(key) ? hexToBytes(key) : unprefixedHexToBytes(key);
const account = new Account();

@@ -23,3 +23,3 @@ if (typeof value === 'string') {

if (code !== undefined) {
const codeBytes = isHexPrefixed(code) ? toBytes(code) : unprefixedHexToBytes(code);
const codeBytes = isHexString(code) ? hexToBytes(code) : unprefixedHexToBytes(code);
account.codeHash = keccak256(codeBytes);

@@ -30,4 +30,4 @@ }

for (const [k, val] of storage) {
const storageKey = isHexPrefixed(k) ? toBytes(k) : unprefixedHexToBytes(k);
const storageVal = RLP.encode(unpadBytes(isHexPrefixed(val) ? toBytes(val) : unprefixedHexToBytes(val)));
const storageKey = isHexString(k) ? hexToBytes(k) : unprefixedHexToBytes(k);
const storageVal = RLP.encode(unpadBytes(isHexString(val) ? hexToBytes(val) : unprefixedHexToBytes(val)));
await storageTrie.put(storageKey, storageVal);

@@ -34,0 +34,0 @@ }

{
"name": "@ethereumjs/trie",
"version": "6.2.0",
"version": "6.2.1",
"description": "Implementation of the modified merkle patricia tree as specified in Ethereum's yellow paper.",

@@ -50,4 +50,4 @@ "keywords": [

"profiling": "tsc --target ES5 benchmarks/random.ts && 0x benchmarks/random.js",
"test": "npm run test:node && npm run test:browser",
"test:browser": "npx vitest run --config=./vitest.config.browser.ts --browser.name=chrome --browser.headless",
"test": "npm run test:node",
"test:browser": "npx vitest run --config=./vitest.config.browser.mts",
"test:node": "npx vitest run",

@@ -58,11 +58,11 @@ "tsc": "../../config/cli/ts-compile.sh"

"@ethereumjs/rlp": "^5.0.2",
"@ethereumjs/util": "^9.0.3",
"@ethereumjs/util": "^9.1.0",
"@types/readable-stream": "^2.3.13",
"debug": "^4.3.4",
"lru-cache": "10.1.0",
"ethereum-cryptography": "^2.1.3",
"ethereum-cryptography": "^2.2.1",
"readable-stream": "^3.6.0"
},
"devDependencies": {
"@ethereumjs/genesis": "^0.2.2",
"@ethereumjs/genesis": "^0.2.3",
"@types/benchmark": "^1.0.33",

@@ -69,0 +69,0 @@ "abstract-level": "^1.0.3",

@@ -58,3 +58,2 @@ import {

if (this.cacheSize > 0) {
// @ts-ignore
this._cache = new LRUCache({

@@ -253,2 +252,3 @@ max: this.cacheSize,

}
this._stats.db.writes += 1
if (op.type === 'put' && this.valueEncoding === ValueEncoding.String) {

@@ -255,0 +255,0 @@ convertedOp.value = bytesToUnprefixedHex(<Uint8Array>convertedOp.value)

// Some more secure presets when using e.g. JS `call`
'use strict'
import { RLP } from '@ethereumjs/rlp'
import {

@@ -530,4 +531,7 @@ KeyEncoding,

const deleteHashes = stack.map((e) => this.hash(e.serialize()))
ops = deleteHashes.map((e) => {
const key = this._opts.keyPrefix ? concatBytes(this._opts.keyPrefix, e) : e
ops = deleteHashes.map((deletedHash) => {
const key = this._opts.keyPrefix
? concatBytes(this._opts.keyPrefix, deletedHash)
: deletedHash
return {

@@ -572,4 +576,7 @@ type: 'del',

// So after deleting the node, one can safely delete these from the DB
ops = deleteHashes.map((e) => {
const key = this._opts.keyPrefix ? concatBytes(this._opts.keyPrefix, e) : e
ops = deleteHashes.map((deletedHash) => {
const key = this._opts.keyPrefix
? concatBytes(this._opts.keyPrefix, deletedHash)
: deletedHash
return {

@@ -1025,5 +1032,7 @@ type: 'del',

if (this._opts.useNodePruning) {
// If the branchNode has length < 32, it will be a RawNode (Uint8Array[]) instead of a Uint8Array
// In that case, we need to serialize and hash it into a Uint8Array, otherwise the operation will throw
opStack.push({
type: 'del',
key: branchNode as Uint8Array,
key: isRawNode(branchNode) ? this.appliedKey(RLP.encode(branchNode)) : branchNode,
})

@@ -1061,20 +1070,20 @@ }

while (stack.length) {
const node = stack.pop() as TrieNode
if (node instanceof LeafNode) {
const node = stack.pop()
if (node === undefined) {
throw new Error('saveStack: missing node')
}
if (node instanceof LeafNode || node instanceof ExtensionNode) {
key.splice(key.length - node.key().length)
} else if (node instanceof ExtensionNode) {
key.splice(key.length - node.key().length)
if (lastRoot) {
node.value(lastRoot)
}
} else if (node instanceof BranchNode) {
if (lastRoot) {
const branchKey = key.pop()
node.setBranch(branchKey!, lastRoot)
}
}
if (node instanceof ExtensionNode && lastRoot !== undefined) {
node.value(lastRoot)
}
if (node instanceof BranchNode && lastRoot !== undefined) {
const branchKey = key.pop()
node.setBranch(branchKey!, lastRoot)
}
lastRoot = this._formatNode(node, stack.length === 0, opStack) as Uint8Array
}
if (lastRoot) {
if (lastRoot !== undefined) {
this.root(lastRoot)

@@ -1176,3 +1185,3 @@ }

try {
await this.walkTrie(this.root(), async function (nodeRef, node, key, controller) {
await this.walkTrie(this.root(), async function (_, node, key, controller) {
if (found) {

@@ -1185,3 +1194,8 @@ // Abort all other children checks

// If one of the branches matches the key, then it is found
if (item !== null && bytesToUnprefixedHex(item as Uint8Array) === dbkey) {
if (
item !== null &&
bytesToUnprefixedHex(
isRawNode(item) ? controller.trie.appliedKey(RLP.encode(item)) : item
) === dbkey
) {
found = true

@@ -1188,0 +1202,0 @@ return

@@ -165,3 +165,3 @@ import { hexToBytes, toBytes, unprefixedHexToBytes } from '@ethereumjs/util'

export const pathToHexKey = (path: string, extension: Nibbles, retType: string): Uint8Array => {
const b = hexToBytes('0x' + path)
const b = hexToBytes(`0x${path}`)
const n = byteTypeToNibbleType(b)

@@ -168,0 +168,0 @@ if (retType === 'hex') {

import { RLP } from '@ethereumjs/rlp'
import { Account, isHexPrefixed, toBytes, unpadBytes, unprefixedHexToBytes } from '@ethereumjs/util'
import {
Account,
hexToBytes,
isHexString,
unpadBytes,
unprefixedHexToBytes,
} from '@ethereumjs/util'
import { keccak256 } from 'ethereum-cryptography/keccak.js'

@@ -15,3 +21,3 @@

for (const [key, value] of Object.entries(genesisState)) {
const address = isHexPrefixed(key) ? toBytes(key) : unprefixedHexToBytes(key)
const address = isHexString(key) ? hexToBytes(key) : unprefixedHexToBytes(key)
const account = new Account()

@@ -26,3 +32,3 @@ if (typeof value === 'string') {

if (code !== undefined) {
const codeBytes = isHexPrefixed(code) ? toBytes(code) : unprefixedHexToBytes(code)
const codeBytes = isHexString(code) ? hexToBytes(code) : unprefixedHexToBytes(code)
account.codeHash = keccak256(codeBytes)

@@ -33,5 +39,5 @@ }

for (const [k, val] of storage) {
const storageKey = isHexPrefixed(k) ? toBytes(k) : unprefixedHexToBytes(k)
const storageKey = isHexString(k) ? hexToBytes(k) : unprefixedHexToBytes(k)
const storageVal = RLP.encode(
unpadBytes(isHexPrefixed(val) ? toBytes(val) : unprefixedHexToBytes(val))
unpadBytes(isHexString(val) ? hexToBytes(val) : unprefixedHexToBytes(val))
)

@@ -38,0 +44,0 @@ await storageTrie.put(storageKey, storageVal)

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

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

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

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