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.1 to 8.0.0-rc.2

32

dist/account.js

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

const secp256k1_1 = require("ethereum-cryptography/secp256k1");
const utils_1 = require("ethereum-cryptography/utils");
const bytes_1 = require("./bytes");

@@ -123,3 +122,3 @@ const constants_1 = require("./constants");

const buf = Buffer.from(prefix + address, 'utf8');
const hash = (0, utils_1.bytesToHex)((0, keccak_1.keccak256)(buf));
const hash = (0, keccak_1.keccak256)(buf).toString('hex');
let ret = '0x';

@@ -157,6 +156,6 @@ for (let i = 0; i < address.length; i++) {

// read the RLP documentation for an answer if you dare
return Buffer.from((0, keccak_1.keccak256)(ethereumjs_rlp_1.RLP.encode((0, bytes_1.bufArrToArr)([from, null])))).slice(-20);
return (0, bytes_1.toBuffer)((0, keccak_1.keccak256)((0, bytes_1.arrToBufArr)(ethereumjs_rlp_1.RLP.encode([from, null])))).slice(-20);
}
// Only take the lower 160bits of the hash
return Buffer.from((0, keccak_1.keccak256)(ethereumjs_rlp_1.RLP.encode((0, bytes_1.bufArrToArr)([from, nonce])))).slice(-20);
return Buffer.from((0, keccak_1.keccak256)((0, bytes_1.arrToBufArr)(ethereumjs_rlp_1.RLP.encode((0, bytes_1.bufArrToArr)([from, nonce]))))).slice(-20);
};

@@ -188,3 +187,3 @@ exports.generateAddress = generateAddress;

const isValidPrivate = function (privateKey) {
return secp256k1_1.utils.isValidPrivateKey(privateKey);
return (0, secp256k1_1.privateKeyVerify)(privateKey);
};

@@ -202,10 +201,3 @@ exports.isValidPrivate = isValidPrivate;

// Convert to SEC1 for secp256k1
// Automatically checks whether point is on curve
try {
secp256k1_1.Point.fromHex(Buffer.concat([Buffer.from([4]), publicKey]));
return true;
}
catch (e) {
return false;
}
return (0, secp256k1_1.publicKeyVerify)(Buffer.concat([Buffer.from([4]), publicKey]));
}

@@ -215,9 +207,3 @@ if (!sanitize) {

}
try {
secp256k1_1.Point.fromHex(publicKey);
return true;
}
catch (e) {
return false;
}
return (0, secp256k1_1.publicKeyVerify)(publicKey);
};

@@ -234,3 +220,3 @@ exports.isValidPublic = isValidPublic;

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

@@ -252,3 +238,3 @@ if (pubKey.length !== 64) {

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

@@ -270,3 +256,3 @@ exports.privateToPublic = privateToPublic;

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

@@ -273,0 +259,0 @@ return publicKey;

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

const buffer_1 = require("buffer");
const secp256k1_1 = require("ethereum-cryptography/secp256k1");
/**

@@ -19,4 +18,4 @@ * 2^64-1

exports.MAX_INTEGER_BIGINT = BigInt(2) ** BigInt(256) - BigInt(1);
exports.SECP256K1_ORDER = secp256k1_1.CURVE.n;
exports.SECP256K1_ORDER_DIV_2 = secp256k1_1.CURVE.n / BigInt(2);
exports.SECP256K1_ORDER = BigInt('0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141');
exports.SECP256K1_ORDER_DIV_2 = exports.SECP256K1_ORDER / BigInt(2);
/**

@@ -23,0 +22,0 @@ * 2^256

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

const keccak_1 = require("ethereum-cryptography/keccak");
const secp256k1_1 = require("ethereum-cryptography/secp256k1");
const secp256k1_1 = require("secp256k1");
const bytes_1 = require("./bytes");

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

function ecsign(msgHash, privateKey, chainId) {
const [signature, recovery] = (0, secp256k1_1.signSync)(msgHash, privateKey, { recovered: true, der: false });
const { signature, recid: recovery } = (0, secp256k1_1.ecdsaSign)(msgHash, privateKey);
const r = Buffer.from(signature.slice(0, 32));

@@ -49,4 +49,4 @@ const s = Buffer.from(signature.slice(32, 64));

}
const senderPubKey = (0, secp256k1_1.recoverPublicKey)(msgHash, signature, Number(recovery));
return Buffer.from(senderPubKey.slice(1));
const senderPubKey = (0, secp256k1_1.ecdsaRecover)(signature, Number(recovery), msgHash);
return Buffer.from((0, secp256k1_1.publicKeyConvert)(senderPubKey, false).slice(1));
};

@@ -53,0 +53,0 @@ exports.ecrecover = ecrecover;

{
"name": "@nomicfoundation/ethereumjs-util",
"version": "8.0.0-rc.1",
"version": "8.0.0-rc.2",
"description": "A collection of utility functions for Ethereum",

@@ -86,3 +86,3 @@ "keywords": [

"@nomicfoundation/ethereumjs-rlp": "^4.0.0-beta.2",
"ethereum-cryptography": "^1.1.2"
"ethereum-cryptography": "0.1.3"
},

@@ -89,0 +89,0 @@ "devDependencies": {

import { RLP } from '@nomicfoundation/ethereumjs-rlp'
import { keccak256 } from 'ethereum-cryptography/keccak'
import { Point, utils } from 'ethereum-cryptography/secp256k1'
import { bytesToHex } from 'ethereum-cryptography/utils'
import {
privateKeyVerify,
publicKeyConvert,
publicKeyCreate,
publicKeyVerify,
} from 'ethereum-cryptography/secp256k1'

@@ -167,3 +171,3 @@ import {

const buf = Buffer.from(prefix + address, 'utf8')
const hash = bytesToHex(keccak256(buf))
const hash = keccak256(buf).toString('hex')
let ret = '0x'

@@ -206,7 +210,7 @@

// read the RLP documentation for an answer if you dare
return Buffer.from(keccak256(RLP.encode(bufArrToArr([from, null] as any)))).slice(-20)
return toBuffer(keccak256(arrToBufArr(RLP.encode([from, null])))).slice(-20)
}
// Only take the lower 160bits of the hash
return Buffer.from(keccak256(RLP.encode(bufArrToArr([from, nonce])))).slice(-20)
return Buffer.from(keccak256(arrToBufArr(RLP.encode(bufArrToArr([from, nonce]))))).slice(-20)
}

@@ -243,3 +247,3 @@

export const isValidPrivate = function (privateKey: Buffer): boolean {
return utils.isValidPrivateKey(privateKey)
return privateKeyVerify(privateKey)
}

@@ -257,9 +261,3 @@

// Convert to SEC1 for secp256k1
// Automatically checks whether point is on curve
try {
Point.fromHex(Buffer.concat([Buffer.from([4]), publicKey]))
return true
} catch (e) {
return false
}
return publicKeyVerify(Buffer.concat([Buffer.from([4]), publicKey]))
}

@@ -271,8 +269,3 @@

try {
Point.fromHex(publicKey)
return true
} catch (e) {
return false
}
return publicKeyVerify(publicKey)
}

@@ -289,3 +282,3 @@

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

@@ -307,3 +300,3 @@ if (pubKey.length !== 64) {

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

@@ -325,3 +318,3 @@

if (publicKey.length !== 64) {
publicKey = Buffer.from(Point.fromHex(publicKey).toRawBytes(false).slice(1))
publicKey = Buffer.from(publicKeyConvert(publicKey, false).slice(1))
}

@@ -328,0 +321,0 @@ return publicKey

import { Buffer } from 'buffer'
import { CURVE } from 'ethereum-cryptography/secp256k1'

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

export const SECP256K1_ORDER = CURVE.n
export const SECP256K1_ORDER_DIV_2 = CURVE.n / BigInt(2)
export const SECP256K1_ORDER = BigInt(
'0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141'
)
export const SECP256K1_ORDER_DIV_2 = SECP256K1_ORDER / BigInt(2)

@@ -25,0 +26,0 @@ /**

import { keccak256 } from 'ethereum-cryptography/keccak'
import { recoverPublicKey, signSync } from 'ethereum-cryptography/secp256k1'
import { ecdsaRecover, ecdsaSign, publicKeyConvert } from 'secp256k1'

@@ -21,3 +21,3 @@ import { bufferToBigInt, bufferToHex, bufferToInt, setLengthLeft, toBuffer } from './bytes'

export function ecsign(msgHash: Buffer, privateKey: Buffer, chainId?: bigint): ECDSASignature {
const [signature, recovery] = signSync(msgHash, privateKey, { recovered: true, der: false })
const { signature, recid: recovery } = ecdsaSign(msgHash, privateKey)

@@ -66,4 +66,4 @@ const r = Buffer.from(signature.slice(0, 32))

const senderPubKey = recoverPublicKey(msgHash, signature, Number(recovery))
return Buffer.from(senderPubKey.slice(1))
const senderPubKey = ecdsaRecover(signature, Number(recovery), msgHash)
return Buffer.from(publicKeyConvert(senderPubKey, false).slice(1))
}

@@ -70,0 +70,0 @@

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