@ethereumjs/util
Advanced tools
Comparing version 8.0.5 to 8.0.6
@@ -184,3 +184,3 @@ "use strict"; | ||
const isValidPrivate = function (privateKey) { | ||
return secp256k1_1.utils.isValidPrivateKey(privateKey); | ||
return secp256k1_1.secp256k1.utils.isValidPrivateKey(privateKey); | ||
}; | ||
@@ -200,3 +200,3 @@ exports.isValidPrivate = isValidPrivate; | ||
try { | ||
secp256k1_1.Point.fromHex(Buffer.concat([Buffer.from([4]), publicKey])); | ||
secp256k1_1.secp256k1.ProjectivePoint.fromHex(Buffer.concat([Buffer.from([4]), publicKey])); | ||
return true; | ||
@@ -212,3 +212,3 @@ } | ||
try { | ||
secp256k1_1.Point.fromHex(publicKey); | ||
secp256k1_1.secp256k1.ProjectivePoint.fromHex(publicKey); | ||
return true; | ||
@@ -230,3 +230,3 @@ } | ||
if (sanitize && pubKey.length !== 64) { | ||
pubKey = Buffer.from(secp256k1_1.Point.fromHex(pubKey).toRawBytes(false).slice(1)); | ||
pubKey = Buffer.from(secp256k1_1.secp256k1.ProjectivePoint.fromHex(pubKey).toRawBytes(false).slice(1)); | ||
} | ||
@@ -248,3 +248,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(secp256k1_1.secp256k1.ProjectivePoint.fromPrivateKey(privateKey).toRawBytes(false).slice(1)); | ||
}; | ||
@@ -266,3 +266,3 @@ exports.privateToPublic = privateToPublic; | ||
if (publicKey.length !== 64) { | ||
publicKey = Buffer.from(secp256k1_1.Point.fromHex(publicKey).toRawBytes(false).slice(1)); | ||
publicKey = Buffer.from(secp256k1_1.secp256k1.ProjectivePoint.fromHex(publicKey).toRawBytes(false).slice(1)); | ||
} | ||
@@ -269,0 +269,0 @@ return publicKey; |
@@ -20,4 +20,4 @@ "use strict"; | ||
exports.MAX_INTEGER_BIGINT = BigInt('115792089237316195423570985008687907853269984665640564039457584007913129639935'); | ||
exports.SECP256K1_ORDER = secp256k1_1.CURVE.n; | ||
exports.SECP256K1_ORDER_DIV_2 = secp256k1_1.CURVE.n / BigInt(2); | ||
exports.SECP256K1_ORDER = secp256k1_1.secp256k1.CURVE.n; | ||
exports.SECP256K1_ORDER_DIV_2 = secp256k1_1.secp256k1.CURVE.n / BigInt(2); | ||
/** | ||
@@ -24,0 +24,0 @@ * 2^256 |
@@ -38,2 +38,6 @@ /** | ||
/** | ||
* Helper function for working with compact encoding | ||
*/ | ||
export * from './encoding'; | ||
/** | ||
* Export ethjs-util methods | ||
@@ -44,2 +48,3 @@ */ | ||
export * from './lock'; | ||
export * from './provider'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -55,2 +55,6 @@ "use strict"; | ||
/** | ||
* Helper function for working with compact encoding | ||
*/ | ||
__exportStar(require("./encoding"), exports); | ||
/** | ||
* Export ethjs-util methods | ||
@@ -71,2 +75,3 @@ */ | ||
__exportStar(require("./lock"), exports); | ||
__exportStar(require("./provider"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -16,8 +16,9 @@ "use strict"; | ||
function ecsign(msgHash, privateKey, chainId) { | ||
const [signature, recovery] = (0, secp256k1_1.signSync)(msgHash, privateKey, { recovered: true, der: false }); | ||
const r = Buffer.from(signature.slice(0, 32)); | ||
const s = Buffer.from(signature.slice(32, 64)); | ||
const sig = secp256k1_1.secp256k1.sign(msgHash, privateKey); | ||
const buf = sig.toCompactRawBytes(); | ||
const r = Buffer.from(buf.slice(0, 32)); | ||
const s = Buffer.from(buf.slice(32, 64)); | ||
const v = chainId === undefined | ||
? BigInt(recovery + 27) | ||
: BigInt(recovery + 35) + BigInt(chainId) * BigInt(2); | ||
? BigInt(sig.recovery + 27) | ||
: BigInt(sig.recovery + 35) + BigInt(chainId) * BigInt(2); | ||
return { r, s, v }; | ||
@@ -48,4 +49,5 @@ } | ||
} | ||
const senderPubKey = (0, secp256k1_1.recoverPublicKey)(msgHash, signature, Number(recovery)); | ||
return Buffer.from(senderPubKey.slice(1)); | ||
const sig = secp256k1_1.secp256k1.Signature.fromCompact(signature).addRecoveryBit(Number(recovery)); | ||
const senderPubKey = sig.recoverPublicKey(msgHash); | ||
return Buffer.from(senderPubKey.toRawBytes(false).slice(1)); | ||
}; | ||
@@ -52,0 +54,0 @@ exports.ecrecover = ecrecover; |
{ | ||
"name": "@ethereumjs/util", | ||
"version": "8.0.5", | ||
"version": "8.0.6", | ||
"description": "A collection of utility functions for Ethereum", | ||
@@ -86,5 +86,6 @@ "keywords": [ | ||
"dependencies": { | ||
"@chainsafe/ssz": "0.9.4", | ||
"@chainsafe/ssz": "^0.11.1", | ||
"@ethereumjs/rlp": "^4.0.1", | ||
"ethereum-cryptography": "^1.1.2" | ||
"ethereum-cryptography": "^2.0.0", | ||
"micro-ftch": "^0.3.1" | ||
}, | ||
@@ -91,0 +92,0 @@ "devDependencies": { |
import { RLP } from '@ethereumjs/rlp' | ||
import { keccak256 } from 'ethereum-cryptography/keccak' | ||
import { Point, utils } from 'ethereum-cryptography/secp256k1' | ||
import { secp256k1 } from 'ethereum-cryptography/secp256k1' | ||
import { bytesToHex } from 'ethereum-cryptography/utils' | ||
@@ -242,3 +242,3 @@ | ||
export const isValidPrivate = function (privateKey: Buffer): boolean { | ||
return utils.isValidPrivateKey(privateKey) | ||
return secp256k1.utils.isValidPrivateKey(privateKey) | ||
} | ||
@@ -258,3 +258,3 @@ | ||
try { | ||
Point.fromHex(Buffer.concat([Buffer.from([4]), publicKey])) | ||
secp256k1.ProjectivePoint.fromHex(Buffer.concat([Buffer.from([4]), publicKey])) | ||
return true | ||
@@ -271,3 +271,3 @@ } catch (e) { | ||
try { | ||
Point.fromHex(publicKey) | ||
secp256k1.ProjectivePoint.fromHex(publicKey) | ||
return true | ||
@@ -288,3 +288,3 @@ } catch (e) { | ||
if (sanitize && pubKey.length !== 64) { | ||
pubKey = Buffer.from(Point.fromHex(pubKey).toRawBytes(false).slice(1)) | ||
pubKey = Buffer.from(secp256k1.ProjectivePoint.fromHex(pubKey).toRawBytes(false).slice(1)) | ||
} | ||
@@ -306,3 +306,5 @@ 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( | ||
secp256k1.ProjectivePoint.fromPrivateKey(privateKey).toRawBytes(false).slice(1) | ||
) | ||
} | ||
@@ -324,3 +326,3 @@ | ||
if (publicKey.length !== 64) { | ||
publicKey = Buffer.from(Point.fromHex(publicKey).toRawBytes(false).slice(1)) | ||
publicKey = Buffer.from(secp256k1.ProjectivePoint.fromHex(publicKey).toRawBytes(false).slice(1)) | ||
} | ||
@@ -327,0 +329,0 @@ return publicKey |
import { Buffer } from 'buffer' | ||
import { CURVE } from 'ethereum-cryptography/secp256k1' | ||
import { secp256k1 } from 'ethereum-cryptography/secp256k1' | ||
@@ -25,4 +25,4 @@ /** | ||
export const SECP256K1_ORDER = CURVE.n | ||
export const SECP256K1_ORDER_DIV_2 = CURVE.n / BigInt(2) | ||
export const SECP256K1_ORDER = secp256k1.CURVE.n | ||
export const SECP256K1_ORDER_DIV_2 = secp256k1.CURVE.n / BigInt(2) | ||
@@ -29,0 +29,0 @@ /** |
@@ -47,2 +47,7 @@ /** | ||
/** | ||
* Helper function for working with compact encoding | ||
*/ | ||
export * from './encoding' | ||
/** | ||
* Export ethjs-util methods | ||
@@ -64,1 +69,2 @@ */ | ||
export * from './lock' | ||
export * from './provider' |
import { keccak256 } from 'ethereum-cryptography/keccak' | ||
import { recoverPublicKey, signSync } from 'ethereum-cryptography/secp256k1' | ||
import { secp256k1 } from 'ethereum-cryptography/secp256k1' | ||
@@ -21,11 +21,11 @@ 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 sig = secp256k1.sign(msgHash, privateKey) | ||
const buf = sig.toCompactRawBytes() | ||
const r = Buffer.from(buf.slice(0, 32)) | ||
const s = Buffer.from(buf.slice(32, 64)) | ||
const r = Buffer.from(signature.slice(0, 32)) | ||
const s = Buffer.from(signature.slice(32, 64)) | ||
const v = | ||
chainId === undefined | ||
? BigInt(recovery + 27) | ||
: BigInt(recovery + 35) + BigInt(chainId) * BigInt(2) | ||
? BigInt(sig.recovery! + 27) | ||
: BigInt(sig.recovery! + 35) + BigInt(chainId) * BigInt(2) | ||
@@ -66,4 +66,5 @@ return { r, s, v } | ||
const senderPubKey = recoverPublicKey(msgHash, signature, Number(recovery)) | ||
return Buffer.from(senderPubKey.slice(1)) | ||
const sig = secp256k1.Signature.fromCompact(signature).addRecoveryBit(Number(recovery)) | ||
const senderPubKey = sig.recoverPublicKey(msgHash) | ||
return Buffer.from(senderPubKey.toRawBytes(false).slice(1)) | ||
} | ||
@@ -70,0 +71,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
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
238482
83
4469
4
+ Addedmicro-ftch@^0.3.1
+ Added@chainsafe/as-sha256@0.4.2(transitive)
+ Added@chainsafe/persistent-merkle-tree@0.6.1(transitive)
+ Added@chainsafe/ssz@0.11.1(transitive)
+ Added@noble/curves@1.4.2(transitive)
+ Added@noble/hashes@1.4.01.5.0(transitive)
+ Added@scure/bip32@1.4.0(transitive)
+ Added@scure/bip39@1.3.0(transitive)
+ Addedethereum-cryptography@2.2.1(transitive)
+ Addedmicro-ftch@0.3.1(transitive)
- Removed@chainsafe/as-sha256@0.3.1(transitive)
- Removed@chainsafe/persistent-merkle-tree@0.4.2(transitive)
- Removed@chainsafe/ssz@0.9.4(transitive)
- Removed@noble/hashes@1.2.0(transitive)
- Removed@noble/secp256k1@1.7.1(transitive)
- Removed@scure/bip32@1.1.5(transitive)
- Removed@scure/bip39@1.1.1(transitive)
- Removedcase@1.6.3(transitive)
- Removedethereum-cryptography@1.2.0(transitive)
Updated@chainsafe/ssz@^0.11.1
Updatedethereum-cryptography@^2.0.0