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.10 to 7.1.0

dist.browser/@types/ethjs-util/index.d.ts

24

CHANGELOG.md

@@ -9,4 +9,26 @@ # Changelog

## [7.0.10] - 2021-03-31
## 7.1.0 - 2021-07-08
### Distribution Changes
#### Dual ES5 and ES2017 Builds
We significantly updated our internal tool and CI setup along the work on PR [#913](https://github.com/ethereumjs/ethereumjs-monorepo/pull/913) with an update to `ESLint` from `TSLint` for code linting and formatting and the introduction of a new build setup.
Packages now target `ES2017` for Node.js builds (the `main` entrypoint from `package.json`) and introduce a separate `ES5` build distributed along using the `browser` directive as an entrypoint, see PR [#921](https://github.com/ethereumjs/ethereumjs-monorepo/pull/921). This will result in performance benefits for Node.js consumers, see [here](https://github.com/ethereumjs/merkle-patricia-tree/pull/117) for a releated discussion.
#### Included Source Files
Source files from the `src` folder are now included in the distribution build, see PR [#1301](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1301). This allows for a better debugging experience in debug tools like Chrome DevTools by having working source map references to the original sources available for inspection.
### EIP-2098 Support (Compact 64-byte Signatures)
The `signature` module comes with a new helper function `toCompactSig(v: BNLike, r: Buffer, s: Buffer, chainId?: BNLike): string` which allows to convert signature parameters into the format of Compact Signature Representation as defined in [EIP-2098](https://eips.ethereum.org/EIPS/eip-2098).
### Other Changes
- Renamed `bnToRlp()`helper function to `bnToUnpaddedBuffer()`, PR [#1293](https://github.com/ethereumjs/ethereumjs-monorepo/pull/1293)
## 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)

@@ -13,0 +35,0 @@ - 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)

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

raw() {
return [types_1.bnToRlp(this.nonce), types_1.bnToRlp(this.balance), this.stateRoot, this.codeHash];
return [
types_1.bnToUnpaddedBuffer(this.nonce),
types_1.bnToUnpaddedBuffer(this.balance),
this.stateRoot,
this.codeHash,
];
}

@@ -84,0 +89,0 @@ /**

@@ -30,2 +30,7 @@ /// <reference types="node" />

/**
* Convert signature parameters into the format of Compact Signature Representation (EIP-2098).
* @returns Signature
*/
export declare const toCompactSig: (v: BNLike, r: Buffer, s: Buffer, chainId?: string | number | Buffer | BN | undefined) => string;
/**
* Convert signature format of the `eth_sign` RPC method to signature parameters

@@ -32,0 +37,0 @@ * NOTE: all because of a bug in geth: https://github.com/ethereum/go-ethereum/issues/2053

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.hashPersonalMessage = exports.isValidSignature = exports.fromRpcSig = exports.toRpcSig = exports.ecrecover = exports.ecsign = void 0;
exports.hashPersonalMessage = exports.isValidSignature = exports.fromRpcSig = exports.toCompactSig = exports.toRpcSig = exports.ecrecover = exports.ecsign = void 0;
const secp256k1_1 = require("ethereum-cryptography/secp256k1");

@@ -69,2 +69,19 @@ const bn_js_1 = __importDefault(require("bn.js"));

/**
* Convert signature parameters into the format of Compact Signature Representation (EIP-2098).
* @returns Signature
*/
exports.toCompactSig = function (v, r, s, chainId) {
const recovery = calculateSigRecovery(v, chainId);
if (!isValidSigRecovery(recovery)) {
throw new Error('Invalid signature v value');
}
const vn = types_1.toType(v, types_1.TypeOutput.Number);
let ss = s;
if ((vn > 28 && vn % 2 === 1) || vn === 1 || vn === 28) {
ss = Buffer.from(s);
ss[0] |= 0x80;
}
return bytes_1.bufferToHex(Buffer.concat([bytes_1.setLengthLeft(r, 32), bytes_1.setLengthLeft(ss, 32)]));
};
/**
* Convert signature format of the `eth_sign` RPC method to signature parameters

@@ -75,6 +92,20 @@ * NOTE: all because of a bug in geth: https://github.com/ethereum/go-ethereum/issues/2053

const buf = bytes_1.toBuffer(sig);
if (buf.length < 65) {
let r;
let s;
let v;
if (buf.length >= 65) {
r = buf.slice(0, 32);
s = buf.slice(32, 64);
v = bytes_1.bufferToInt(buf.slice(64));
}
else if (buf.length === 64) {
// Compact Signature Representation (https://eips.ethereum.org/EIPS/eip-2098)
r = buf.slice(0, 32);
s = buf.slice(32, 64);
v = bytes_1.bufferToInt(buf.slice(32, 33)) >> 7;
s[0] &= 0x7f;
}
else {
throw new Error('Invalid signature length');
}
let v = bytes_1.bufferToInt(buf.slice(64));
// support both versions of `eth_sign` responses

@@ -85,5 +116,5 @@ if (v < 27) {

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

@@ -90,0 +121,0 @@ };

@@ -26,5 +26,11 @@ /// <reference types="node" />

/**
* Convert value from BN to RLP (unpadded buffer)
* Convert value from BN to an unpadded Buffer
* (useful for RLP transport)
* @param value value to convert
*/
export declare function bnToUnpaddedBuffer(value: BN): Buffer;
/**
* Deprecated alias for {@link bnToUnpaddedBuffer}
* @deprecated
*/
export declare function bnToRlp(value: BN): Buffer;

@@ -31,0 +37,0 @@ /**

15

dist/types.js

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.toType = exports.TypeOutput = exports.bnToRlp = exports.bnToHex = void 0;
exports.toType = exports.TypeOutput = exports.bnToRlp = exports.bnToUnpaddedBuffer = exports.bnToHex = void 0;
const bn_js_1 = __importDefault(require("bn.js"));

@@ -19,6 +19,7 @@ const ethjs_util_1 = require("ethjs-util");

/**
* Convert value from BN to RLP (unpadded buffer)
* Convert value from BN to an unpadded Buffer
* (useful for RLP transport)
* @param value value to convert
*/
function bnToRlp(value) {
function bnToUnpaddedBuffer(value) {
// Using `bn.toArrayLike(Buffer)` instead of `bn.toBuffer()`

@@ -28,2 +29,10 @@ // for compatibility with browserify and similar tools

}
exports.bnToUnpaddedBuffer = bnToUnpaddedBuffer;
/**
* Deprecated alias for {@link bnToUnpaddedBuffer}
* @deprecated
*/
function bnToRlp(value) {
return bnToUnpaddedBuffer(value);
}
exports.bnToRlp = bnToRlp;

@@ -30,0 +39,0 @@ /**

{
"name": "ethereumjs-util",
"version": "7.0.10",
"description": "a collection of utility functions for Ethereum",
"main": "dist/index.js",
"types": "./dist/index.d.ts",
"version": "7.1.0",
"description": "A collection of utility functions for Ethereum",
"license": "MPL-2.0",
"author": "mjbecze <mjbecze@gmail.com>",
"keywords": [
"ethereum",
"utilties"
],
"engines": {

@@ -11,26 +15,56 @@ "node": ">=10.0.0"

"files": [
"dist"
"dist",
"dist.browser",
"src"
],
"main": "dist/index.js",
"types": "dist/index.d.ts",
"browser": "dist.browser/index.js",
"scripts": {
"build": "ethereumjs-config-ts-build",
"build": "../../config/cli/ts-build.sh",
"prepublishOnly": "npm run clean && npm run build && npm run test",
"clean": "rm -Rf ./dist && rm -Rf ./dist.browser",
"coverage": "ethereumjs-config-coverage",
"coverage": "../../config/cli/coverage.sh",
"docs:build": "npx typedoc --options typedoc.js",
"lint": "ethereumjs-config-lint",
"lint:fix": "ethereumjs-config-lint-fix",
"lint": "../../config/cli/lint.sh",
"lint:fix": "../../config/cli/lint-fix.sh",
"test": "npm run test:node && npm run test:browser",
"test:browser": "karma start karma.conf.js",
"test:node": "tape -r ts-node/register test/*.spec.ts",
"tsc": "ethereumjs-config-tsc"
"tsc": "../../config/cli/ts-compile.sh"
},
"dependencies": {
"@types/bn.js": "^5.1.0",
"bn.js": "^5.1.2",
"create-hash": "^1.1.2",
"ethereum-cryptography": "^0.1.3",
"ethjs-util": "0.1.6",
"rlp": "^2.2.4"
},
"devDependencies": {
"@types/assert": "^1.5.4",
"@types/node": "^11.13.4",
"@types/secp256k1": "^4.0.1",
"@types/tape": "^4.13.0",
"eslint": "^6.8.0",
"karma": "^6.3.2",
"karma-chrome-launcher": "^3.1.0",
"karma-firefox-launcher": "^2.1.0",
"karma-tap": "^4.2.0",
"karma-typescript": "^5.5.1",
"nyc": "^14.0.0",
"prettier": "^2.0.5",
"tape": "^4.10.1",
"ts-node": "^8.8.2",
"typedoc": "^0.20.34",
"typescript": "^3.9.3"
},
"repository": {
"type": "git",
"url": "https://github.com/ethereumjs/ethereumjs-util.git"
"url": "https://github.com/ethereumjs/ethereumjs-monorepo.git"
},
"keywords": [
"ethereum",
"utilties"
],
"author": "mjbecze <mjbecze@gmail.com>",
"homepage": "https://github.com/ethereumjs/ethereumjs-monorepo/tree/master/packages/util#readme",
"bugs": {
"url": "https://github.com/ethereumjs/ethereumjs-monorepo/issues?q=is%3Aissue+label%3A%22package%3A+util%22"
},
"contributors": [

@@ -79,40 +113,3 @@ {

}
],
"license": "MPL-2.0",
"bugs": {
"url": "https://github.com/ethereumjs/ethereumjs-util/issues"
},
"homepage": "https://github.com/ethereumjs/ethereumjs-util",
"dependencies": {
"@types/bn.js": "^5.1.0",
"bn.js": "^5.1.2",
"create-hash": "^1.1.2",
"ethereum-cryptography": "^0.1.3",
"ethjs-util": "0.1.6",
"rlp": "^2.2.4"
},
"devDependencies": {
"@ethereumjs/config-coverage": "^2.0.0",
"@ethereumjs/config-typescript": "^2.0.0",
"@ethereumjs/eslint-config-defaults": "^2.0.0",
"@types/assert": "^1.5.4",
"@types/node": "^11.13.4",
"@types/secp256k1": "^4.0.1",
"@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.17",
"typescript": "^3.9.3"
}
]
}

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