@celo/utils
Advanced tools
Comparing version 4.1.0 to 4.1.1-beta.1
export { Address, bufferToHex, ensureLeading0x, eqAddress, findAddressIndex, getAddressChunks, hexToBuffer, isHexString, mapAddressListDataOnto, mapAddressListOnto, normalizeAddress, normalizeAddressWith0x, NULL_ADDRESS, trimLeading0x, } from '@celo/base/lib/address'; | ||
export { isValidChecksumAddress, toChecksumAddress } from 'ethereumjs-util'; | ||
export { isValidChecksumAddress, toChecksumAddress } from '@ethereumjs/util'; | ||
export declare const privateKeyToAddress: (privateKey: string) => string; | ||
@@ -4,0 +4,0 @@ export declare const privateKeyToPublicKey: (privateKey: string) => string; |
@@ -5,3 +5,3 @@ "use strict"; | ||
var address_1 = require("@celo/base/lib/address"); | ||
var ethereumjs_util_1 = require("ethereumjs-util"); | ||
var util_1 = require("@ethereumjs/util"); | ||
// Exports moved to @celo/base, forwarding them | ||
@@ -23,19 +23,19 @@ // here for backwards compatibility | ||
Object.defineProperty(exports, "trimLeading0x", { enumerable: true, get: function () { return address_2.trimLeading0x; } }); | ||
var ethereumjs_util_2 = require("ethereumjs-util"); | ||
Object.defineProperty(exports, "isValidChecksumAddress", { enumerable: true, get: function () { return ethereumjs_util_2.isValidChecksumAddress; } }); | ||
Object.defineProperty(exports, "toChecksumAddress", { enumerable: true, get: function () { return ethereumjs_util_2.toChecksumAddress; } }); | ||
var util_2 = require("@ethereumjs/util"); | ||
Object.defineProperty(exports, "isValidChecksumAddress", { enumerable: true, get: function () { return util_2.isValidChecksumAddress; } }); | ||
Object.defineProperty(exports, "toChecksumAddress", { enumerable: true, get: function () { return util_2.toChecksumAddress; } }); | ||
var privateKeyToAddress = function (privateKey) { | ||
return (0, ethereumjs_util_1.toChecksumAddress)((0, address_1.ensureLeading0x)((0, ethereumjs_util_1.privateToAddress)((0, address_1.hexToBuffer)(privateKey)).toString('hex'))); | ||
return (0, util_1.toChecksumAddress)((0, address_1.ensureLeading0x)((0, util_1.privateToAddress)((0, address_1.hexToBuffer)(privateKey)).toString('hex'))); | ||
}; | ||
exports.privateKeyToAddress = privateKeyToAddress; | ||
var privateKeyToPublicKey = function (privateKey) { | ||
return (0, ethereumjs_util_1.toChecksumAddress)((0, address_1.ensureLeading0x)((0, ethereumjs_util_1.privateToPublic)((0, address_1.hexToBuffer)(privateKey)).toString('hex'))); | ||
return (0, util_1.toChecksumAddress)((0, address_1.ensureLeading0x)((0, util_1.privateToPublic)((0, address_1.hexToBuffer)(privateKey)).toString('hex'))); | ||
}; | ||
exports.privateKeyToPublicKey = privateKeyToPublicKey; | ||
var publicKeyToAddress = function (publicKey) { | ||
return (0, ethereumjs_util_1.toChecksumAddress)((0, address_1.ensureLeading0x)((0, ethereumjs_util_1.pubToAddress)((0, ethereumjs_util_1.toBuffer)((0, address_1.ensureLeading0x)(publicKey)), true).toString('hex'))); | ||
return (0, util_1.toChecksumAddress)((0, address_1.ensureLeading0x)((0, util_1.pubToAddress)((0, util_1.toBuffer)((0, address_1.ensureLeading0x)(publicKey)), true).toString('hex'))); | ||
}; | ||
exports.publicKeyToAddress = publicKeyToAddress; | ||
var isValidPrivateKey = function (privateKey) { | ||
return privateKey.startsWith('0x') && (0, ethereumjs_util_1.isValidPrivate)((0, address_1.hexToBuffer)(privateKey)); | ||
return privateKey.startsWith('0x') && (0, util_1.isValidPrivate)((0, address_1.hexToBuffer)(privateKey)); | ||
}; | ||
@@ -53,3 +53,3 @@ exports.isValidPrivateKey = isValidPrivateKey; | ||
} | ||
if ((0, ethereumjs_util_1.toChecksumAddress)(input) === input) { | ||
if ((0, util_1.toChecksumAddress)(input) === input) { | ||
return true; | ||
@@ -56,0 +56,0 @@ } |
@@ -28,3 +28,3 @@ "use strict"; | ||
var io_1 = require("@celo/base/lib/io"); | ||
var ethereumjs_util_1 = require("ethereumjs-util"); | ||
var util_1 = require("@ethereumjs/util"); | ||
var Either_1 = require("fp-ts/lib/Either"); | ||
@@ -59,3 +59,3 @@ var t = __importStar(require("io-ts")); | ||
return (0, address_1.isValidAddress)(stringValue) | ||
? t.success((0, ethereumjs_util_1.toChecksumAddress)(stringValue)) | ||
? t.success((0, util_1.toChecksumAddress)(stringValue)) | ||
: t.failure(stringValue, context, 'is not a valid address'); | ||
@@ -66,4 +66,4 @@ }); | ||
return Either_1.either.chain(t.string.validate(input, context), function (stringValue) { | ||
return stringValue.startsWith('0x') && (0, ethereumjs_util_1.isValidPublic)(Buffer.from(stringValue.slice(2), 'hex'), true) | ||
? t.success((0, ethereumjs_util_1.toChecksumAddress)(stringValue)) | ||
return stringValue.startsWith('0x') && (0, util_1.isValidPublic)(Buffer.from(stringValue.slice(2), 'hex'), true) | ||
? t.success((0, util_1.toChecksumAddress)(stringValue)) | ||
: t.failure(stringValue, context, 'is not a valid public key'); | ||
@@ -70,0 +70,0 @@ }); |
@@ -30,4 +30,4 @@ "use strict"; | ||
exports.IstanbulUtils = exports.bitIsSet = exports.parseBlockExtraData = void 0; | ||
var util_1 = require("@ethereumjs/util"); | ||
var bignumber_js_1 = __importDefault(require("bignumber.js")); | ||
var ethereumjs_util_1 = require("ethereumjs-util"); | ||
var rlp = __importStar(require("rlp")); | ||
@@ -52,3 +52,3 @@ // This file contains utilities that help with istanbul-specific block information. | ||
return { | ||
addedValidators: decode[0].map(function (addr) { return (0, ethereumjs_util_1.toChecksumAddress)(addr.toString('hex')); }), | ||
addedValidators: decode[0].map(function (addr) { return (0, util_1.toChecksumAddress)((0, util_1.bufferToHex)(addr)); }), | ||
addedValidatorsPublicKeys: decode[1].map(function (key) { return '0x' + key.toString('hex'); }), | ||
@@ -55,0 +55,0 @@ removedValidators: bigNumberFromBuffer(decode[2]), |
@@ -78,4 +78,6 @@ "use strict"; | ||
var address_1 = require("@celo/base/lib/address"); | ||
var util_1 = require("@ethereumjs/util"); | ||
var bignumber_js_1 = require("bignumber.js"); | ||
var ethereumjs_util_1 = require("ethereumjs-util"); | ||
var keccak_1 = require("ethereum-cryptography/keccak"); | ||
var utils_1 = require("ethereum-cryptography/utils"); | ||
var t = __importStar(require("io-ts")); | ||
@@ -159,3 +161,3 @@ var web3_eth_abi_1 = __importDefault(require("web3-eth-abi")); | ||
function generateTypedDataHash(typedData) { | ||
return (0, ethereumjs_util_1.keccak)(Buffer.concat([ | ||
return (0, keccak_1.keccak256)(Buffer.concat([ | ||
Buffer.from('1901', 'hex'), | ||
@@ -238,3 +240,3 @@ structHash('EIP712Domain', typedData.domain, typedData.types), | ||
function typeHash(primaryType, types) { | ||
return (0, ethereumjs_util_1.keccak)(encodeType(primaryType, types)); | ||
return (0, keccak_1.keccak256)((0, utils_1.utf8ToBytes)(encodeType(primaryType, types))); | ||
} | ||
@@ -256,3 +258,3 @@ exports.typeHash = typeHash; | ||
// https://github.com/ethereumjs/ethereumjs-util/blob/7e3be1d97b4e11fbc4924836b8c444e644f643ac/index.js#L155-L183 | ||
return (0, ethereumjs_util_1.keccak)(Buffer.from(value, 'utf8')); | ||
return (0, keccak_1.keccak256)(Buffer.from(value, 'utf8')); | ||
} | ||
@@ -262,3 +264,3 @@ if (valueType === 'bytes') { | ||
// Note: keccak throws if the value cannot be converted into a Buffer, | ||
return (0, ethereumjs_util_1.keccak)(value); | ||
return (0, util_1.toBuffer)((0, keccak_1.keccak256)((0, utils_1.hexToBytes)((0, address_1.trimLeading0x)(value)))); | ||
} | ||
@@ -275,3 +277,3 @@ // Encode structs as its hashStruct (e.g. keccak(typeHash || encodeData(struct)) ). | ||
var memberType_1 = (_a = match === null || match === void 0 ? void 0 : match.groups) === null || _a === void 0 ? void 0 : _a.memberType; | ||
return (0, ethereumjs_util_1.keccak)(Buffer.concat(value.map(function (member) { return encodeValue(memberType_1, member, types); }))); | ||
return (0, keccak_1.keccak256)(Buffer.concat(value.map(function (member) { return encodeValue(memberType_1, member, types); }))); | ||
} | ||
@@ -296,3 +298,3 @@ throw new Error("Unrecognized or unsupported type in EIP-712 encoding: ".concat(valueType)); | ||
function structHash(primaryType, data, types) { | ||
return (0, ethereumjs_util_1.keccak)(Buffer.concat([typeHash(primaryType, types), encodeData(primaryType, data, types)])); | ||
return (0, keccak_1.keccak256)(Buffer.concat([typeHash(primaryType, types), encodeData(primaryType, data, types)])); | ||
} | ||
@@ -299,0 +301,0 @@ exports.structHash = structHash; |
@@ -10,10 +10,10 @@ import { NativeSigner, serializeSignature, Signer } from '@celo/base/lib/signatureUtils'; | ||
export declare function signMessage(message: string, privateKey: string, address: string): { | ||
v: any; | ||
r: any; | ||
s: any; | ||
v: number; | ||
r: string; | ||
s: string; | ||
}; | ||
export declare function signMessageWithoutPrefix(messageHash: string, privateKey: string, address: string): { | ||
v: any; | ||
r: any; | ||
s: any; | ||
v: number; | ||
r: string; | ||
s: string; | ||
}; | ||
@@ -20,0 +20,0 @@ export declare function verifySignature(message: string, signature: string, signer: string): boolean; |
@@ -52,2 +52,3 @@ "use strict"; | ||
var signatureUtils_1 = require("@celo/base/lib/signatureUtils"); | ||
var util_1 = require("@ethereumjs/util"); | ||
var web3_utils_1 = require("web3-utils"); | ||
@@ -62,3 +63,2 @@ var address_1 = require("./address"); | ||
Object.defineProperty(exports, "serializeSignature", { enumerable: true, get: function () { return signatureUtils_2.serializeSignature; } }); | ||
var ethjsutil = require('ethereumjs-util'); | ||
// If messages is a hex, the length of it should be the number of bytes | ||
@@ -93,6 +93,6 @@ function messageLength(message) { | ||
sig = _a.sent(); | ||
rawsig = ethjsutil.fromRpcSig(sig); | ||
rawsig = (0, util_1.fromRpcSig)(sig); | ||
prefixedMsg = hashMessageWithPrefix(data); | ||
pubKey = ethjsutil.ecrecover(Buffer.from(prefixedMsg.slice(2), 'hex'), rawsig.v, rawsig.r, rawsig.s); | ||
computedAddr = ethjsutil.pubToAddress(pubKey).toString('hex'); | ||
pubKey = (0, util_1.ecrecover)(Buffer.from(prefixedMsg.slice(2), 'hex'), rawsig.v, rawsig.r, rawsig.s); | ||
computedAddr = (0, util_1.pubToAddress)(pubKey).toString('hex'); | ||
if (!(0, address_1.eqAddress)(computedAddr, signer)) { | ||
@@ -119,3 +119,3 @@ throw new Error('computed address !== signer'); | ||
function signedMessageToPublicKey(message, v, r, s) { | ||
var pubKeyBuf = ethjsutil.ecrecover(Buffer.from(message.slice(2), 'hex'), v, Buffer.from(r.slice(2), 'hex'), Buffer.from(s.slice(2), 'hex')); | ||
var pubKeyBuf = (0, util_1.ecrecover)(Buffer.from(message.slice(2), 'hex'), BigInt(v), Buffer.from(r.slice(2), 'hex'), Buffer.from(s.slice(2), 'hex')); | ||
return '0x' + pubKeyBuf.toString('hex'); | ||
@@ -129,12 +129,12 @@ } | ||
function signMessageWithoutPrefix(messageHash, privateKey, address) { | ||
var publicKey = ethjsutil.privateToPublic(ethjsutil.toBuffer(privateKey)); | ||
var derivedAddress = ethjsutil.bufferToHex(ethjsutil.pubToAddress(publicKey)); | ||
var publicKey = (0, util_1.privateToPublic)((0, util_1.toBuffer)(privateKey)); | ||
var derivedAddress = (0, util_1.bufferToHex)((0, util_1.pubToAddress)(publicKey)); | ||
if (derivedAddress.toLowerCase() !== address.toLowerCase()) { | ||
throw new Error('Provided private key does not match address of intended signer'); | ||
} | ||
var _a = ethjsutil.ecsign(ethjsutil.toBuffer(messageHash), ethjsutil.toBuffer(privateKey)), r = _a.r, s = _a.s, v = _a.v; | ||
if (!isValidSignature(address, messageHash, v, ethjsutil.bufferToHex(r), ethjsutil.bufferToHex(s))) { | ||
var _a = (0, util_1.ecsign)((0, util_1.toBuffer)(messageHash), (0, util_1.toBuffer)(privateKey)), r = _a.r, s = _a.s, v = _a.v; | ||
if (!isValidSignature(address, messageHash, Number(v), (0, util_1.bufferToHex)(r), (0, util_1.bufferToHex)(s))) { | ||
throw new Error('Unable to validate signature'); | ||
} | ||
return { v: v, r: ethjsutil.bufferToHex(r), s: ethjsutil.bufferToHex(s) }; | ||
return { v: Number(v), r: (0, util_1.bufferToHex)(r), s: (0, util_1.bufferToHex)(s) }; | ||
} | ||
@@ -173,5 +173,5 @@ exports.signMessageWithoutPrefix = signMessageWithoutPrefix; | ||
var _a = parseFunction((0, address_1.trimLeading0x)(signature)), r = _a.r, s = _a.s, v = _a.v; | ||
var publicKey = ethjsutil.ecrecover(ethjsutil.toBuffer(dataBuff), v, ethjsutil.toBuffer(r), ethjsutil.toBuffer(s)); | ||
var publicKey = (0, util_1.ecrecover)((0, util_1.toBuffer)(dataBuff), BigInt(v), (0, util_1.toBuffer)(r), (0, util_1.toBuffer)(s)); | ||
// TODO test error handling on this | ||
return ethjsutil.bufferToHex(ethjsutil.pubToAddress(publicKey)); | ||
return (0, util_1.bufferToHex)((0, util_1.pubToAddress)(publicKey)); | ||
} | ||
@@ -232,4 +232,4 @@ /** | ||
var _a = parseSignatureAsRsv(signature.slice(2)), r = _a.r, s = _a.s, v = _a.v; | ||
var publicKey = ethjsutil.ecrecover(ethjsutil.toBuffer(messageHash), v, ethjsutil.toBuffer(r), ethjsutil.toBuffer(s)); | ||
return ethjsutil.bufferToHex(ethjsutil.pubToAddress(publicKey)); | ||
var publicKey = (0, util_1.ecrecover)((0, util_1.toBuffer)(messageHash), BigInt(v), (0, util_1.toBuffer)(r), (0, util_1.toBuffer)(s)); | ||
return (0, util_1.bufferToHex)((0, util_1.pubToAddress)(publicKey)); | ||
} | ||
@@ -257,4 +257,4 @@ exports.guessSigner = guessSigner; | ||
try { | ||
var publicKey = ethjsutil.ecrecover(ethjsutil.toBuffer(message), v, ethjsutil.toBuffer(r), ethjsutil.toBuffer(s)); | ||
var retrievedAddress = ethjsutil.bufferToHex(ethjsutil.pubToAddress(publicKey)); | ||
var publicKey = (0, util_1.ecrecover)((0, util_1.toBuffer)(message), BigInt(v), (0, util_1.toBuffer)(r), (0, util_1.toBuffer)(s)); | ||
var retrievedAddress = (0, util_1.bufferToHex)((0, util_1.pubToAddress)(publicKey)); | ||
return (0, address_1.eqAddress)(retrievedAddress, signer); | ||
@@ -261,0 +261,0 @@ } |
{ | ||
"name": "@celo/utils", | ||
"version": "4.1.0", | ||
"version": "4.1.1-beta.1", | ||
"description": "Celo common utils", | ||
@@ -25,19 +25,19 @@ "author": "Celo", | ||
"dependencies": { | ||
"@celo/base": "4.1.0", | ||
"@celo/base": "4.1.1-beta.1", | ||
"@ethereumjs/util": "8.0.5", | ||
"@types/bn.js": "^5.1.0", | ||
"@types/elliptic": "^6.4.9", | ||
"@types/ethereumjs-util": "^5.2.0", | ||
"@types/node": "^10.12.18", | ||
"bignumber.js": "^9.0.0", | ||
"elliptic": "^6.5.4", | ||
"ethereumjs-util": "^5.2.0", | ||
"ethereum-cryptography": "1.2.0", | ||
"io-ts": "2.0.1", | ||
"web3-eth-abi": "1.3.6", | ||
"web3-utils": "1.3.6" | ||
"web3-eth-abi": "1.10.0", | ||
"web3-utils": "1.10.0" | ||
}, | ||
"devDependencies": { | ||
"@celo/flake-tracker": "0.0.1-dev", | ||
"@celo/typescript": "0.0.1" | ||
}, | ||
"resolutions": { | ||
"@types/bn.js": "4.11.6", | ||
"bn.js": "4.11.9", | ||
@@ -44,0 +44,0 @@ "elliptic/bn.js": "bn.js@4.11.9", |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
487532
1
157
6472
2
1
+ Added@ethereumjs/util@8.0.5
+ Addedethereum-cryptography@1.2.0
+ Added@celo/base@4.1.1-beta.1(transitive)
+ Added@chainsafe/as-sha256@0.3.1(transitive)
+ Added@chainsafe/persistent-merkle-tree@0.4.2(transitive)
+ Added@chainsafe/ssz@0.9.4(transitive)
+ Added@ethereumjs/rlp@4.0.1(transitive)
+ Added@ethereumjs/util@8.0.5(transitive)
+ Added@ethersproject/abi@5.7.0(transitive)
+ Added@noble/hashes@1.2.0(transitive)
+ Added@noble/secp256k1@1.7.1(transitive)
+ Added@scure/base@1.1.9(transitive)
+ Added@scure/bip32@1.1.5(transitive)
+ Added@scure/bip39@1.1.1(transitive)
+ Addedcase@1.6.3(transitive)
+ Addedethereum-cryptography@1.2.0(transitive)
+ Addedethereumjs-util@7.1.5(transitive)
+ Addedweb3-eth-abi@1.10.0(transitive)
+ Addedweb3-utils@1.10.0(transitive)
- Removed@types/ethereumjs-util@^5.2.0
- Removedethereumjs-util@^5.2.0
- Removed@celo/base@4.1.0(transitive)
- Removed@ethersproject/abi@5.0.7(transitive)
- Removed@types/ethereumjs-util@5.2.0(transitive)
- Removedbuffer-to-arraybuffer@0.0.5(transitive)
- Removeddecode-uri-component@0.2.2(transitive)
- Removeddecompress-response@3.3.0(transitive)
- Removeddom-walk@0.1.2(transitive)
- Removedeth-lib@0.2.8(transitive)
- Removedethereumjs-util@5.2.1(transitive)
- Removedethjs-util@0.1.6(transitive)
- Removedglobal@4.4.0(transitive)
- Removedis-function@1.0.2(transitive)
- Removedmimic-response@1.0.1(transitive)
- Removedmin-document@2.19.0(transitive)
- Removedobject-assign@4.1.1(transitive)
- Removedonce@1.4.0(transitive)
- Removedparse-headers@2.0.5(transitive)
- Removedprocess@0.11.10(transitive)
- Removedquery-string@5.1.1(transitive)
- Removedsimple-concat@1.0.1(transitive)
- Removedsimple-get@2.8.2(transitive)
- Removedstrict-uri-encode@1.1.0(transitive)
- Removedtimed-out@4.0.1(transitive)
- Removedunderscore@1.12.1(transitive)
- Removedurl-set-query@1.0.0(transitive)
- Removedweb3-eth-abi@1.3.6(transitive)
- Removedweb3-utils@1.3.6(transitive)
- Removedwrappy@1.0.2(transitive)
- Removedxhr@2.6.0(transitive)
- Removedxhr-request@1.1.0(transitive)
- Removedxhr-request-promise@0.1.3(transitive)
- Removedxtend@4.0.2(transitive)
Updated@celo/base@4.1.1-beta.1
Updatedweb3-eth-abi@1.10.0
Updatedweb3-utils@1.10.0