Socket
Socket
Sign inDemoInstall

ethereumjs-util

Package Overview
Dependencies
Maintainers
6
Versions
84
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ethereumjs-util - npm Package Compare versions

Comparing version 7.0.9 to 7.0.10

11

CHANGELOG.md

@@ -9,5 +9,10 @@ # Changelog

## [7.0.10] - 2021-03-31
- Added `Address.isPrecompileOrSystemAddress()` method which returns `true` if address is in the address range defined by [EIP-1352](https://eips.ethereum.org/EIPS/eip-1352), PR [#1170](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1170)
- Return `false` (instead of throwing) for non-hex-string values in account module `isValidAddress`, `isValidChecksumAddress`, `isZeroAddress` methods (it now gets enough to just handle the `false` case on function usage), PR [#1173](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1173)
## [7.0.9] - 2021-03-04
This release adds support for very high `chainId` numbers exceeding `MAX_SAFE_INTEGER` (an example is the chain ID `34180983699157880` used for the ephemeral Yolov3 testnet preparing for the `berlin` hardfork, but high chain IDs might be used for things like private test networks and the like as well).
This release adds support for very high `chainId` numbers exceeding `MAX_SAFE_INTEGER` (an example is the chain ID `34180983699157880` used for the ephemeral Yolov3 testnet preparing for the `berlin` hardfork, but high chain IDs might be used for things like private test networks and the like as well), see PR [#290](https://github.com/ethereumjs/ethereumjs-util/pull/290).

@@ -32,2 +37,4 @@ Function signatures for methods in `address` and `signature` are therefore expanded to allow for a `BNLike` input type (`BN | PrefixedHexString | number | Buffer`) for chain ID related parameters.

Along there is a new `toType()` helper function which can be used to easily convert to a `BNLike` output type.
[7.0.9]: https://github.com/ethereumjs/ethereumjs-util/compare/v7.0.8...v7.0.9

@@ -404,3 +411,3 @@

- Support for `EIP-155` replay protection by adding an optional `chainId` parameter
to `ecsign()`, `ecrecover()`, `toRpcSig()` and `isValidSignature()`, if present the
to `ecsign()`, `ecrecover()`, `toRpcSig()` and `isValidSignature()`, if present the
new signature format relying on the `chainId` is used, see PR [#143](https://github.com/ethereumjs/ethereumjs-util/pull/143)

@@ -407,0 +414,0 @@ - New `generateAddress2()` for `CREATE2` opcode (`EIP-1014`) address creation

28

dist/account.js

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

const rlp = __importStar(require("rlp"));
const secp256k1_1 = require("ethereum-cryptography/secp256k1");
const ethjs_util_1 = require("ethjs-util");

@@ -36,3 +37,2 @@ const constants_1 = require("./constants");

const types_1 = require("./types");
const { privateKeyVerify, publicKeyCreate, publicKeyVerify, publicKeyConvert } = require('ethereum-cryptography/secp256k1');
class Account {

@@ -111,3 +111,8 @@ /**

exports.isValidAddress = function (hexAddress) {
helpers_1.assertIsHexString(hexAddress);
try {
helpers_1.assertIsString(hexAddress);
}
catch (e) {
return false;
}
return /^0x[0-9a-fA-F]{40}$/.test(hexAddress);

@@ -189,3 +194,3 @@ };

exports.isValidPrivate = function (privateKey) {
return privateKeyVerify(privateKey);
return secp256k1_1.privateKeyVerify(privateKey);
};

@@ -202,3 +207,3 @@ /**

// Convert to SEC1 for secp256k1
return publicKeyVerify(Buffer.concat([Buffer.from([4]), publicKey]));
return secp256k1_1.publicKeyVerify(Buffer.concat([Buffer.from([4]), publicKey]));
}

@@ -208,3 +213,3 @@ if (!sanitize) {

}
return publicKeyVerify(publicKey);
return secp256k1_1.publicKeyVerify(publicKey);
};

@@ -220,3 +225,3 @@ /**

if (sanitize && pubKey.length !== 64) {
pubKey = Buffer.from(publicKeyConvert(pubKey, false).slice(1));
pubKey = Buffer.from(secp256k1_1.publicKeyConvert(pubKey, false).slice(1));
}

@@ -235,3 +240,3 @@ assert_1.default(pubKey.length === 64);

// skip the type flag and use the X, Y points
return Buffer.from(publicKeyCreate(privateKey, false)).slice(1);
return Buffer.from(secp256k1_1.publicKeyCreate(privateKey, false)).slice(1);
};

@@ -251,3 +256,3 @@ /**

if (publicKey.length !== 64) {
publicKey = Buffer.from(publicKeyConvert(publicKey, false).slice(1));
publicKey = Buffer.from(secp256k1_1.publicKeyConvert(publicKey, false).slice(1));
}

@@ -268,3 +273,8 @@ return publicKey;

exports.isZeroAddress = function (hexAddress) {
helpers_1.assertIsHexString(hexAddress);
try {
helpers_1.assertIsString(hexAddress);
}
catch (e) {
return false;
}
const zeroAddr = exports.zeroAddress();

@@ -271,0 +281,0 @@ return zeroAddr === hexAddress;

/// <reference types="node" />
import BN = require('bn.js');
import BN from 'bn.js';
export declare class Address {

@@ -47,2 +47,7 @@ readonly buf: Buffer;

/**
* True if address is in the address range defined
* by EIP-1352
*/
isPrecompileOrSystemAddress(): boolean;
/**
* Returns hex encoding of address.

@@ -49,0 +54,0 @@ */

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Address = void 0;
const assert = require('assert');
const BN = require("bn.js");
const assert_1 = __importDefault(require("assert"));
const bn_js_1 = __importDefault(require("bn.js"));
const bytes_1 = require("./bytes");

@@ -10,3 +13,3 @@ const account_1 = require("./account");

constructor(buf) {
assert(buf.length === 20, 'Invalid address length');
assert_1.default(buf.length === 20, 'Invalid address length');
this.buf = buf;

@@ -25,3 +28,3 @@ }

static fromString(str) {
assert(account_1.isValidAddress(str), 'Invalid address');
assert_1.default(account_1.isValidAddress(str), 'Invalid address');
return new Address(bytes_1.toBuffer(str));

@@ -34,3 +37,3 @@ }

static fromPublicKey(pubKey) {
assert(Buffer.isBuffer(pubKey), 'Public key should be Buffer');
assert_1.default(Buffer.isBuffer(pubKey), 'Public key should be Buffer');
const buf = account_1.pubToAddress(pubKey);

@@ -44,3 +47,3 @@ return new Address(buf);

static fromPrivateKey(privateKey) {
assert(Buffer.isBuffer(privateKey), 'Private key should be Buffer');
assert_1.default(Buffer.isBuffer(privateKey), 'Private key should be Buffer');
const buf = account_1.privateToAddress(privateKey);

@@ -55,3 +58,3 @@ return new Address(buf);

static generate(from, nonce) {
assert(BN.isBN(nonce));
assert_1.default(bn_js_1.default.isBN(nonce));
return new Address(account_1.generateAddress(from.buf, nonce.toArrayLike(Buffer)));

@@ -66,4 +69,4 @@ }

static generate2(from, salt, initCode) {
assert(Buffer.isBuffer(salt));
assert(Buffer.isBuffer(initCode));
assert_1.default(Buffer.isBuffer(salt));
assert_1.default(Buffer.isBuffer(initCode));
return new Address(account_1.generateAddress2(from.buf, salt, initCode));

@@ -84,2 +87,12 @@ }

/**
* True if address is in the address range defined
* by EIP-1352
*/
isPrecompileOrSystemAddress() {
const addressBN = new bn_js_1.default(this.buf);
const rangeMin = new bn_js_1.default(0);
const rangeMax = new bn_js_1.default('ffff', 'hex');
return addressBN.gte(rangeMin) && addressBN.lte(rangeMax);
}
/**
* Returns hex encoding of address.

@@ -86,0 +99,0 @@ */

@@ -46,3 +46,4 @@ /// <reference types="node" />

* Attempts to turn a value into a `Buffer`.
* Inputs supported: `Buffer`, `String`, `Number`, null/undefined, `BN` and other objects with a `toArray()` or `toBuffer()` method.
* Inputs supported: `Buffer`, `String` (hex-prefixed), `Number`, null/undefined, `BN` and other objects
* with a `toArray()` or `toBuffer()` method.
* @param v the value

@@ -49,0 +50,0 @@ */

@@ -107,3 +107,4 @@ "use strict";

* Attempts to turn a value into a `Buffer`.
* Inputs supported: `Buffer`, `String`, `Number`, null/undefined, `BN` and other objects with a `toArray()` or `toBuffer()` method.
* Inputs supported: `Buffer`, `String` (hex-prefixed), `Number`, null/undefined, `BN` and other objects
* with a `toArray()` or `toBuffer()` method.
* @param v the value

@@ -110,0 +111,0 @@ */

@@ -6,4 +6,4 @@ /**

*/
import BN = require('bn.js');
import rlp = require('rlp');
import BN from 'bn.js';
import * as rlp from 'rlp';
/**

@@ -10,0 +10,0 @@ * [`BN`](https://github.com/indutny/bn.js)

@@ -7,11 +7,30 @@ "use strict";

*/
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.rlp = exports.BN = void 0;
// TODO: This can be replaced with a normal ESM import once
// the new major version of the typescript config package
// is released and adopted here.
const BN = require("bn.js");
exports.BN = BN;
const rlp = require("rlp");
const bn_js_1 = __importDefault(require("bn.js"));
exports.BN = bn_js_1.default;
const rlp = __importStar(require("rlp"));
exports.rlp = rlp;
//# sourceMappingURL=externals.js.map

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

exports.rlphash = exports.ripemd160FromArray = exports.ripemd160FromString = exports.ripemd160 = exports.sha256FromArray = exports.sha256FromString = exports.sha256 = exports.keccakFromArray = exports.keccakFromHexString = exports.keccakFromString = exports.keccak256 = exports.keccak = void 0;
const { keccak224, keccak384, keccak256: k256, keccak512 } = require('ethereum-cryptography/keccak');
const keccak_1 = require("ethereum-cryptography/keccak");
const createHash = require('create-hash');

@@ -38,12 +38,12 @@ const rlp = __importStar(require("rlp"));

case 224: {
return keccak224(a);
return keccak_1.keccak224(a);
}
case 256: {
return k256(a);
return keccak_1.keccak256(a);
}
case 384: {
return keccak384(a);
return keccak_1.keccak384(a);
}
case 512: {
return keccak512(a);
return keccak_1.keccak512(a);
}

@@ -96,5 +96,3 @@ default: {

a = bytes_1.toBuffer(a);
return createHash('sha256')
.update(a)
.digest();
return createHash('sha256').update(a).digest();
};

@@ -132,5 +130,3 @@ /**

a = bytes_1.toBuffer(a);
const hash = createHash('rmd160')
.update(a)
.digest();
const hash = createHash('rmd160').update(a).digest();
if (padded === true) {

@@ -137,0 +133,0 @@ return bytes_1.setLengthLeft(hash, 32);

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

get: getter,
set: setter
set: setter,
});

@@ -93,3 +93,3 @@ if (field.default) {

set: setter,
get: getter
get: getter,
});

@@ -96,0 +96,0 @@ }

@@ -26,7 +26,3 @@ "use strict";

const chainIdBN = types_1.toType(chainId, types_1.TypeOutput.BN);
const v = chainIdBN
.muln(2)
.addn(35)
.addn(recovery)
.toArrayLike(Buffer);
const v = chainIdBN.muln(2).addn(35).addn(recovery).toArrayLike(Buffer);
return { r, s, v };

@@ -89,3 +85,3 @@ }

r: buf.slice(0, 32),
s: buf.slice(32, 64)
s: buf.slice(32, 64),
};

@@ -92,0 +88,0 @@ };

{
"name": "ethereumjs-util",
"version": "7.0.9",
"version": "7.0.10",
"description": "a collection of utility functions for Ethereum",

@@ -15,3 +15,5 @@ "main": "dist/index.js",

"build": "ethereumjs-config-ts-build",
"prepublishOnly": "npm run test && npm run build",
"prepublishOnly": "npm run clean && npm run build && npm run test",
"clean": "rm -Rf ./dist && rm -Rf ./dist.browser",
"coverage": "ethereumjs-config-coverage",
"docs:build": "npx typedoc --options typedoc.js",

@@ -22,10 +24,5 @@ "lint": "ethereumjs-config-lint",

"test:browser": "karma start karma.conf.js",
"test:node": "nyc --reporter=lcov mocha --require ts-node/register 'test/*.spec.ts'",
"test:node": "tape -r ts-node/register test/*.spec.ts",
"tsc": "ethereumjs-config-tsc"
},
"husky": {
"hooks": {
"pre-push": "npm run lint"
}
},
"repository": {

@@ -102,19 +99,21 @@ "type": "git",

"@types/assert": "^1.5.4",
"@types/mocha": "^8.2.0",
"@types/node": "^11.9.0",
"@types/node": "^11.13.4",
"@types/secp256k1": "^4.0.1",
"husky": "^2.1.0",
"karma": "^5.0.2",
"karma-chrome-launcher": "^2.0.0",
"karma-firefox-launcher": "^1.0.0",
"karma-mocha": "^2.0.0",
"karma-typescript": "^4.1.1",
"mocha": "^8.2.1",
"nyc": "^15.0.0",
"prettier": "^1.15.3",
"ts-node": "^8.6.2",
"@types/tape": "^4.13.0",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-implicit-dependencies": "^1.0.4",
"karma": "^5.2.1",
"karma-chrome-launcher": "^3.1.0",
"karma-firefox-launcher": "^1.3.0",
"karma-tap": "^4.2.0",
"karma-typescript": "^5.2.0",
"nyc": "^14.0.0",
"prettier": "^2.0.5",
"tape": "^4.10.1",
"ts-node": "^8.8.2",
"typedoc": "next",
"typedoc-plugin-markdown": "^2.2.16",
"typescript": "^3.8.3"
"typedoc-plugin-markdown": "^2.2.17",
"typescript": "^3.9.3"
}
}
# SYNOPSIS
[![NPM Status][npm-badge]][npm-link]
[![Actions Status][actions-badge]][actions-link]
[![Coverage Status][coverage-badge]][coverage-link]
[![NPM Package][util-npm-badge]][util-npm-link]
[![GitHub Issues][util-issues-badge]][util-issues-link]
[![Actions Status][util-actions-badge]][util-actions-link]
[![Code Coverage][util-coverage-badge]][util-coverage-link]
[![Discord][discord-badge]][discord-link]

@@ -97,9 +98,11 @@

[npm-badge]: https://img.shields.io/npm/v/ethereumjs-util.svg
[npm-link]: https://www.npmjs.org/package/ethereumjs-util
[actions-badge]: https://github.com/ethereumjs/ethereumjs-util/workflows/Build/badge.svg
[actions-link]: https://github.com/ethereumjs/ethereumjs-util/actions
[coverage-badge]: https://codecov.io/gh/ethereumjs/ethereumjs-util/branch/master/graph/badge.svg
[coverage-link]: https://codecov.io/gh/ethereumjs/ethereumjs-util
[util-npm-badge]: https://img.shields.io/npm/v/ethereumjs-util.svg
[util-npm-link]: https://www.npmjs.org/package/ethereumjs-util
[util-issues-badge]: https://img.shields.io/github/issues/ethereumjs/ethereumjs-monorepo/package:%20util?label=issues
[util-issues-link]: https://github.com/ethereumjs/ethereumjs-monorepo/issues?q=is%3Aopen+is%3Aissue+label%3A"package%3A+util"
[util-actions-badge]: https://github.com/ethereumjs/ethereumjs-monorepo/workflows/Util/badge.svg
[util-actions-link]: https://github.com/ethereumjs/ethereumjs-monorepo/actions?query=workflow%3A%22Util%22
[util-coverage-badge]: https://codecov.io/gh/ethereumjs/ethereumjs-monorepo/branch/master/graph/badge.svg?flag=util
[util-coverage-link]: https://codecov.io/gh/ethereumjs/ethereumjs-monorepo/tree/master/packages/util
[discord-badge]: https://img.shields.io/static/v1?logo=discord&label=discord&message=Join&color=blue
[discord-link]: https://discord.gg/TNwARpR

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