Socket
Socket
Sign inDemoInstall

@metamask/eth-sig-util

Package Overview
Dependencies
Maintainers
7
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@metamask/eth-sig-util - npm Package Compare versions

Comparing version 4.0.1 to 5.0.0

dist/ethereumjs-abi-utils.d.ts

10

CHANGELOG.md

@@ -9,2 +9,9 @@ # Changelog

## [5.0.0]
### Changed
- **BREAKING:** Removed support for Node v12 in favor of v14 ([#137](https://github.com/MetaMask/eth-json-rpc-middleware/pull/137))
- Replace heavy crypto packages for lighter noble implementations via upgrading `ethereumjs-util` to latest (now called `@ethereumjs/util`) ([#260](https://github.com/MetaMask/eth-sig-util/pull/260))
- Migrate to Yarn 3 ([#264](https://github.com/MetaMask/eth-sig-util/pull/264))
## [4.0.1]

@@ -91,3 +98,4 @@ ### Fixed

[Unreleased]: https://github.com/MetaMask/eth-sig-util/compare/v4.0.1...HEAD
[Unreleased]: https://github.com/MetaMask/eth-sig-util/compare/v5.0.0...HEAD
[5.0.0]: https://github.com/MetaMask/eth-sig-util/compare/v4.0.1...v5.0.0
[4.0.1]: https://github.com/MetaMask/eth-sig-util/compare/v4.0.0...v4.0.1

@@ -94,0 +102,0 @@ [4.0.0]: https://github.com/MetaMask/eth-sig-util/compare/v3.0.1...v4.0.0

26

dist/encryption.js
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -36,9 +40,9 @@ if (k2 === undefined) k2 = k;

function encrypt({ publicKey, data, version, }) {
if (utils_1.isNullish(publicKey)) {
if ((0, utils_1.isNullish)(publicKey)) {
throw new Error('Missing publicKey parameter');
}
else if (utils_1.isNullish(data)) {
else if ((0, utils_1.isNullish)(data)) {
throw new Error('Missing data parameter');
}
else if (utils_1.isNullish(version)) {
else if ((0, utils_1.isNullish)(version)) {
throw new Error('Missing version parameter');

@@ -93,9 +97,9 @@ }

function encryptSafely({ publicKey, data, version, }) {
if (utils_1.isNullish(publicKey)) {
if ((0, utils_1.isNullish)(publicKey)) {
throw new Error('Missing publicKey parameter');
}
else if (utils_1.isNullish(data)) {
else if ((0, utils_1.isNullish)(data)) {
throw new Error('Missing data parameter');
}
else if (utils_1.isNullish(version)) {
else if ((0, utils_1.isNullish)(version)) {
throw new Error('Missing version parameter');

@@ -137,6 +141,6 @@ }

function decrypt({ encryptedData, privateKey, }) {
if (utils_1.isNullish(encryptedData)) {
if ((0, utils_1.isNullish)(encryptedData)) {
throw new Error('Missing encryptedData parameter');
}
else if (utils_1.isNullish(privateKey)) {
else if ((0, utils_1.isNullish)(privateKey)) {
throw new Error('Missing privateKey parameter');

@@ -182,6 +186,6 @@ }

function decryptSafely({ encryptedData, privateKey, }) {
if (utils_1.isNullish(encryptedData)) {
if ((0, utils_1.isNullish)(encryptedData)) {
throw new Error('Missing encryptedData parameter');
}
else if (utils_1.isNullish(privateKey)) {
else if ((0, utils_1.isNullish)(privateKey)) {
throw new Error('Missing privateKey parameter');

@@ -188,0 +192,0 @@ }

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k;

/// <reference types="node" />
import { ToBufferInputTypes } from '@ethereumjs/util';
/**

@@ -15,3 +16,3 @@ * Create an Ethereum-specific signature for a message.

privateKey: Buffer;
data: unknown;
data: ToBufferInputTypes;
}): string;

@@ -28,3 +29,3 @@ /**

export declare function recoverPersonalSignature({ data, signature, }: {
data: unknown;
data: ToBufferInputTypes;
signature: string;

@@ -42,4 +43,4 @@ }): string;

export declare function extractPublicKey({ data, signature, }: {
data: unknown;
data: ToBufferInputTypes;
signature: string;
}): string;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.extractPublicKey = exports.recoverPersonalSignature = exports.personalSign = void 0;
const ethereumjs_util_1 = require("ethereumjs-util");
const util_1 = require("@ethereumjs/util");
const utils_1 = require("./utils");

@@ -18,12 +18,12 @@ /**

function personalSign({ privateKey, data, }) {
if (utils_1.isNullish(data)) {
if ((0, utils_1.isNullish)(data)) {
throw new Error('Missing data parameter');
}
else if (utils_1.isNullish(privateKey)) {
else if ((0, utils_1.isNullish)(privateKey)) {
throw new Error('Missing privateKey parameter');
}
const message = utils_1.legacyToBuffer(data);
const msgHash = ethereumjs_util_1.hashPersonalMessage(message);
const sig = ethereumjs_util_1.ecsign(msgHash, privateKey);
const serialized = utils_1.concatSig(ethereumjs_util_1.toBuffer(sig.v), sig.r, sig.s);
const message = (0, utils_1.legacyToBuffer)(data);
const msgHash = (0, util_1.hashPersonalMessage)(message);
const sig = (0, util_1.ecsign)(msgHash, privateKey);
const serialized = (0, utils_1.concatSig)((0, util_1.toBuffer)(sig.v), sig.r, sig.s);
return serialized;

@@ -42,11 +42,11 @@ }

function recoverPersonalSignature({ data, signature, }) {
if (utils_1.isNullish(data)) {
if ((0, utils_1.isNullish)(data)) {
throw new Error('Missing data parameter');
}
else if (utils_1.isNullish(signature)) {
else if ((0, utils_1.isNullish)(signature)) {
throw new Error('Missing signature parameter');
}
const publicKey = getPublicKeyFor(data, signature);
const sender = ethereumjs_util_1.publicToAddress(publicKey);
const senderHex = ethereumjs_util_1.bufferToHex(sender);
const sender = (0, util_1.publicToAddress)(publicKey);
const senderHex = (0, util_1.bufferToHex)(sender);
return senderHex;

@@ -65,6 +65,6 @@ }

function extractPublicKey({ data, signature, }) {
if (utils_1.isNullish(data)) {
if ((0, utils_1.isNullish)(data)) {
throw new Error('Missing data parameter');
}
else if (utils_1.isNullish(signature)) {
else if ((0, utils_1.isNullish)(signature)) {
throw new Error('Missing signature parameter');

@@ -84,5 +84,5 @@ }

function getPublicKeyFor(message, signature) {
const messageHash = ethereumjs_util_1.hashPersonalMessage(utils_1.legacyToBuffer(message));
return utils_1.recoverPublicKey(messageHash, signature);
const messageHash = (0, util_1.hashPersonalMessage)((0, utils_1.legacyToBuffer)(message));
return (0, utils_1.recoverPublicKey)(messageHash, signature);
}
//# sourceMappingURL=personal-sign.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.recoverTypedSignature = exports.signTypedData = exports.typedSignatureHash = exports.TypedDataUtils = exports.TYPED_MESSAGE_SCHEMA = exports.SignTypedDataVersion = void 0;
const ethereumjs_util_1 = require("ethereumjs-util");
const ethereumjs_abi_1 = require("ethereumjs-abi");
const ethjs_util_1 = require("ethjs-util");
const util_1 = require("@ethereumjs/util");
const keccak_1 = require("ethereum-cryptography/keccak");
const ethereumjs_abi_utils_1 = require("./ethereumjs-abi-utils");
const utils_1 = require("./utils");

@@ -79,3 +81,3 @@ /**

? '0x0000000000000000000000000000000000000000000000000000000000000000'
: ethereumjs_util_1.keccak(encodeData(type, value, types, version)),
: (0, util_1.arrToBufArr)((0, keccak_1.keccak256)(encodeData(type, value, types, version))),
];

@@ -87,10 +89,21 @@ }

if (type === 'bytes') {
return ['bytes32', ethereumjs_util_1.keccak(value)];
if (typeof value === 'number') {
value = (0, utils_1.numberToBuffer)(value);
}
else if ((0, ethjs_util_1.isHexString)(value)) {
value = (0, utils_1.numberToBuffer)(parseInt(value, 16));
}
else {
value = Buffer.from(value, 'utf8');
}
return ['bytes32', (0, util_1.arrToBufArr)((0, keccak_1.keccak256)(value))];
}
if (type === 'string') {
// convert string to buffer - prevents ethUtil from interpreting strings like '0xabcd' as hex
if (typeof value === 'string') {
value = Buffer.from(value, 'utf8');
if (typeof value === 'number') {
value = (0, utils_1.numberToBuffer)(value);
}
return ['bytes32', ethereumjs_util_1.keccak(value)];
else {
value = Buffer.from(value !== null && value !== void 0 ? value : '', 'utf8');
}
return ['bytes32', (0, util_1.arrToBufArr)((0, keccak_1.keccak256)(value))];
}

@@ -105,3 +118,3 @@ if (type.lastIndexOf(']') === type.length - 1) {

'bytes32',
ethereumjs_util_1.keccak(ethereumjs_abi_1.rawEncode(typeValuePairs.map(([t]) => t), typeValuePairs.map(([, v]) => v))),
(0, util_1.arrToBufArr)((0, keccak_1.keccak256)((0, ethereumjs_abi_utils_1.rawEncode)(typeValuePairs.map(([t]) => t), typeValuePairs.map(([, v]) => v)))),
];

@@ -132,3 +145,3 @@ }

}
return ethereumjs_abi_1.rawEncode(encodedTypes, encodedValues);
return (0, ethereumjs_abi_utils_1.rawEncode)(encodedTypes, encodedValues);
}

@@ -188,3 +201,3 @@ /**

validateVersion(version, [SignTypedDataVersion.V3, SignTypedDataVersion.V4]);
return ethereumjs_util_1.keccak(encodeData(primaryType, data, types, version));
return (0, util_1.arrToBufArr)((0, keccak_1.keccak256)(encodeData(primaryType, data, types, version)));
}

@@ -199,3 +212,4 @@ /**

function hashType(primaryType, types) {
return ethereumjs_util_1.keccak(encodeType(primaryType, types));
const encodedHashType = Buffer.from(encodeType(primaryType, types), 'utf-8');
return (0, util_1.arrToBufArr)((0, keccak_1.keccak256)(encodedHashType));
}

@@ -242,3 +256,3 @@ /**

}
return ethereumjs_util_1.keccak(Buffer.concat(parts));
return (0, util_1.arrToBufArr)((0, keccak_1.keccak256)(Buffer.concat(parts)));
}

@@ -268,3 +282,3 @@ /**

const hashBuffer = _typedSignatureHash(typedData);
return ethereumjs_util_1.bufferToHex(hashBuffer);
return (0, util_1.bufferToHex)(hashBuffer);
}

@@ -292,3 +306,3 @@ exports.typedSignatureHash = typedSignatureHash;

}
return utils_1.legacyToBuffer(e.value);
return (0, utils_1.legacyToBuffer)(e.value);
});

@@ -304,6 +318,6 @@ const types = typedData.map(function (e) {

});
return ethereumjs_abi_1.soliditySHA3(['bytes32', 'bytes32'], [
ethereumjs_abi_1.soliditySHA3(new Array(typedData.length).fill('string'), schema),
ethereumjs_abi_1.soliditySHA3(types, data),
]);
return (0, util_1.arrToBufArr)((0, keccak_1.keccak256)((0, ethereumjs_abi_utils_1.solidityPack)(['bytes32', 'bytes32'], [
(0, keccak_1.keccak256)((0, ethereumjs_abi_utils_1.solidityPack)(new Array(typedData.length).fill('string'), schema)),
(0, keccak_1.keccak256)((0, ethereumjs_abi_utils_1.solidityPack)(types, data)),
])));
}

@@ -331,6 +345,6 @@ /**

validateVersion(version);
if (utils_1.isNullish(data)) {
if ((0, utils_1.isNullish)(data)) {
throw new Error('Missing data parameter');
}
else if (utils_1.isNullish(privateKey)) {
else if ((0, utils_1.isNullish)(privateKey)) {
throw new Error('Missing private key parameter');

@@ -341,4 +355,4 @@ }

: exports.TypedDataUtils.eip712Hash(data, version);
const sig = ethereumjs_util_1.ecsign(messageHash, privateKey);
return utils_1.concatSig(ethereumjs_util_1.toBuffer(sig.v), sig.r, sig.s);
const sig = (0, util_1.ecsign)(messageHash, privateKey);
return (0, utils_1.concatSig)((0, util_1.toBuffer)(sig.v), sig.r, sig.s);
}

@@ -359,6 +373,6 @@ exports.signTypedData = signTypedData;

validateVersion(version);
if (utils_1.isNullish(data)) {
if ((0, utils_1.isNullish)(data)) {
throw new Error('Missing data parameter');
}
else if (utils_1.isNullish(signature)) {
else if ((0, utils_1.isNullish)(signature)) {
throw new Error('Missing signature parameter');

@@ -369,7 +383,7 @@ }

: exports.TypedDataUtils.eip712Hash(data, version);
const publicKey = utils_1.recoverPublicKey(messageHash, signature);
const sender = ethereumjs_util_1.publicToAddress(publicKey);
return ethereumjs_util_1.bufferToHex(sender);
const publicKey = (0, utils_1.recoverPublicKey)(messageHash, signature);
const sender = (0, util_1.publicToAddress)(publicKey);
return (0, util_1.bufferToHex)(sender);
}
exports.recoverTypedSignature = recoverTypedSignature;
//# sourceMappingURL=sign-typed-data.js.map
/// <reference types="node" />
import { ToBufferInputTypes } from '@ethereumjs/util';
/**

@@ -30,3 +31,3 @@ * Pads the front of the given hex string with zeroes until it reaches the

*/
export declare function legacyToBuffer(value: unknown): Buffer;
export declare function legacyToBuffer(value: ToBufferInputTypes): Buffer;
/**

@@ -56,1 +57,9 @@ * Concatenate an extended ECDSA signature into a single '0x'-prefixed hex string.

export declare function normalize(input: number | string): string;
/**
* Node's Buffer.from() method does not seem to buffer numbers correctly out of the box.
* This helper method formats the number correct for Buffer.from to return correct buffer.
*
* @param num - The number to convert to buffer.
* @returns The number in buffer form.
*/
export declare function numberToBuffer(num: number): Buffer;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.normalize = exports.recoverPublicKey = exports.concatSig = exports.legacyToBuffer = exports.isNullish = exports.padWithZeroes = void 0;
const ethereumjs_util_1 = require("ethereumjs-util");
exports.numberToBuffer = exports.normalize = exports.recoverPublicKey = exports.concatSig = exports.legacyToBuffer = exports.isNullish = exports.padWithZeroes = void 0;
const util_1 = require("@ethereumjs/util");
const ethjs_util_1 = require("ethjs-util");

@@ -47,5 +47,5 @@ /**

function legacyToBuffer(value) {
return typeof value === 'string' && !ethjs_util_1.isHexString(value)
return typeof value === 'string' && !(0, ethjs_util_1.isHexString)(value)
? Buffer.from(value)
: ethereumjs_util_1.toBuffer(value);
: (0, util_1.toBuffer)(value);
}

@@ -62,9 +62,9 @@ exports.legacyToBuffer = legacyToBuffer;

function concatSig(v, r, s) {
const rSig = ethereumjs_util_1.fromSigned(r);
const sSig = ethereumjs_util_1.fromSigned(s);
const vSig = ethereumjs_util_1.bufferToInt(v);
const rStr = padWithZeroes(ethereumjs_util_1.toUnsigned(rSig).toString('hex'), 64);
const sStr = padWithZeroes(ethereumjs_util_1.toUnsigned(sSig).toString('hex'), 64);
const vStr = ethjs_util_1.stripHexPrefix(ethjs_util_1.intToHex(vSig));
return ethereumjs_util_1.addHexPrefix(rStr.concat(sStr, vStr));
const rSig = (0, util_1.fromSigned)(r);
const sSig = (0, util_1.fromSigned)(s);
const vSig = (0, util_1.bufferToInt)(v);
const rStr = padWithZeroes((0, util_1.toUnsigned)(rSig).toString('hex'), 64);
const sStr = padWithZeroes((0, util_1.toUnsigned)(sSig).toString('hex'), 64);
const vStr = (0, ethjs_util_1.stripHexPrefix)((0, ethjs_util_1.intToHex)(vSig));
return (0, util_1.addHexPrefix)(rStr.concat(sStr, vStr));
}

@@ -80,4 +80,4 @@ exports.concatSig = concatSig;

function recoverPublicKey(messageHash, signature) {
const sigParams = ethereumjs_util_1.fromRpcSig(signature);
return ethereumjs_util_1.ecrecover(messageHash, sigParams.v, sigParams.r, sigParams.s);
const sigParams = (0, util_1.fromRpcSig)(signature);
return (0, util_1.ecrecover)(messageHash, sigParams.v, sigParams.r, sigParams.s);
}

@@ -96,4 +96,7 @@ exports.recoverPublicKey = recoverPublicKey;

if (typeof input === 'number') {
const buffer = ethereumjs_util_1.toBuffer(input);
input = ethereumjs_util_1.bufferToHex(buffer);
if (input < 0) {
return '0x';
}
const buffer = (0, util_1.toBuffer)(input);
input = (0, util_1.bufferToHex)(buffer);
}

@@ -105,5 +108,18 @@ if (typeof input !== 'string') {

}
return ethereumjs_util_1.addHexPrefix(input.toLowerCase());
return (0, util_1.addHexPrefix)(input.toLowerCase());
}
exports.normalize = normalize;
/**
* Node's Buffer.from() method does not seem to buffer numbers correctly out of the box.
* This helper method formats the number correct for Buffer.from to return correct buffer.
*
* @param num - The number to convert to buffer.
* @returns The number in buffer form.
*/
function numberToBuffer(num) {
const hexVal = num.toString(16);
const prepend = hexVal.length % 2 ? '0' : '';
return Buffer.from(prepend + hexVal, 'hex');
}
exports.numberToBuffer = numberToBuffer;
//# sourceMappingURL=utils.js.map
{
"name": "@metamask/eth-sig-util",
"version": "4.0.1",
"version": "5.0.0",
"description": "A few useful functions for signing ethereum data",

@@ -30,21 +30,19 @@ "keywords": [

"scripts": {
"setup": "yarn install && yarn allow-scripts",
"build": "tsc --project .",
"build:clean": "rimraf dist && yarn build",
"docs": "typedoc",
"docs:publish": "typedoc --cleanOutputDir false --gitRevision \"v$(jq -r .version < ./package.json)\"",
"lint": "yarn lint:eslint && yarn lint:misc --check",
"lint:eslint": "eslint . --cache --ext js,ts",
"lint:json": "prettier '**/*.json' --ignore-path .gitignore",
"lint": "yarn lint:eslint && yarn lint:json --check",
"lint:fix": "yarn lint:eslint --fix && yarn lint:json --write",
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write",
"lint:misc": "prettier '**/*.json' '**/*.md' '!CHANGELOG.md' '**/*.yml' '!.yarnrc.yml' --ignore-path .gitignore --no-error-on-unmatched-pattern",
"prepublishOnly": "yarn build:clean",
"setup": "yarn install",
"test": "jest",
"test:watch": "jest --watch",
"prepublishOnly": "yarn build:clean",
"docs": "typedoc",
"docs:publish": "typedoc --cleanOutputDir false --gitRevision \"v$(jq -r .version < ./package.json)\""
"test:watch": "jest --watch"
},
"resolutions": {
"airtap/engine.io-client/xmlhttprequest-ssl": "^1.6.2"
},
"dependencies": {
"ethereumjs-abi": "^0.6.8",
"ethereumjs-util": "^6.2.1",
"@ethereumjs/util": "^8.0.0",
"bn.js": "4.11.8",
"ethereum-cryptography": "^1.1.2",
"ethjs-util": "^0.1.6",

@@ -55,5 +53,4 @@ "tweetnacl": "^1.0.3",

"devDependencies": {
"@gudahtt/typedoc": "^0.23.0",
"@lavamoat/allow-scripts": "^1.0.6",
"@metamask/auto-changelog": "^2.4.0",
"@lavamoat/allow-scripts": "^2.0.3",
"@metamask/auto-changelog": "^2.6.1",
"@metamask/eslint-config": "^9.0.0",

@@ -72,3 +69,3 @@ "@metamask/eslint-config-jest": "^9.0.0",

"eslint-plugin-jest": "^24.3.6",
"eslint-plugin-jsdoc": "^36.1.0",
"eslint-plugin-jsdoc": "^39.2.0",
"eslint-plugin-node": "^11.1.0",

@@ -81,6 +78,8 @@ "eslint-plugin-prettier": "^3.4.0",

"ts-jest": "^27.0.3",
"typedoc": "^0.22.15",
"typescript": "^4.1.3"
},
"packageManager": "yarn@3.2.2",
"engines": {
"node": ">=12.0.0"
"node": ">=14.0.0"
},

@@ -94,6 +93,6 @@ "publishConfig": {

"@lavamoat/preinstall-always-fail": false,
"keccak": true,
"secp256k1": true
"ethereumjs-util>ethereum-cryptography>keccak": true,
"ethereumjs-util>ethereum-cryptography>secp256k1": true
}
}
}

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