Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@celo/utils

Package Overview
Dependencies
Maintainers
17
Versions
145
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@celo/utils - npm Package Compare versions

Comparing version 4.1.0 to 4.1.1-beta.1

lib/account.d.ts

2

lib/address.d.ts
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

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