Socket
Socket
Sign inDemoInstall

web3-eth-accounts

Package Overview
Dependencies
Maintainers
4
Versions
437
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

web3-eth-accounts - npm Package Compare versions

Comparing version 4.1.4-dev.5f6deeb.0 to 4.1.4-dev.60fc197.0

7

lib/commonjs/account.d.ts

@@ -43,2 +43,9 @@ import { Address, Bytes, CipherOptions, HexString, KeyStore } from 'web3-types';

/**
* Takes a hash of a message and a private key, signs the message using the SECP256k1 elliptic curve algorithm, and returns the signature components.
* @param hash - The hash of the message to be signed, represented as a hexadecimal string.
* @param privateKey - The private key used to sign the message, represented as a byte array.
* @returns - The signature Object containing the message, messageHash, signature r, s, v
*/
export declare const signMessageWithPrivateKey: (hash: HexString, privateKey: Bytes) => SignResult;
/**
* Signs arbitrary data with a given private key.

@@ -45,0 +52,0 @@ * :::info

41

lib/commonjs/account.js

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.decrypt = exports.create = exports.privateKeyToAccount = exports.encrypt = exports.privateKeyToPublicKey = exports.privateKeyToAddress = exports.recover = exports.recoverTransaction = exports.signTransaction = exports.sign = exports.hashMessage = exports.parseAndValidatePrivateKey = void 0;
exports.decrypt = exports.create = exports.privateKeyToAccount = exports.encrypt = exports.privateKeyToPublicKey = exports.privateKeyToAddress = exports.recover = exports.recoverTransaction = exports.signTransaction = exports.sign = exports.signMessageWithPrivateKey = exports.hashMessage = exports.parseAndValidatePrivateKey = void 0;
/**

@@ -129,2 +129,24 @@ * The web3 accounts package contains functions to generate Ethereum accounts and sign transactions & data.

/**
* Takes a hash of a message and a private key, signs the message using the SECP256k1 elliptic curve algorithm, and returns the signature components.
* @param hash - The hash of the message to be signed, represented as a hexadecimal string.
* @param privateKey - The private key used to sign the message, represented as a byte array.
* @returns - The signature Object containing the message, messageHash, signature r, s, v
*/
const signMessageWithPrivateKey = (hash, privateKey) => {
const privateKeyUint8Array = (0, exports.parseAndValidatePrivateKey)(privateKey);
const signature = constants_js_1.secp256k1.sign(hash.substring(2), privateKeyUint8Array);
const signatureBytes = signature.toCompactRawBytes();
const r = signature.r.toString(16).padStart(64, '0');
const s = signature.s.toString(16).padStart(64, '0');
const v = signature.recovery + 27;
return {
messageHash: hash,
v: (0, web3_utils_1.numberToHex)(v),
r: `0x${r}`,
s: `0x${s}`,
signature: `${(0, web3_utils_1.bytesToHex)(signatureBytes)}${v.toString(16)}`,
};
};
exports.signMessageWithPrivateKey = signMessageWithPrivateKey;
/**
* Signs arbitrary data with a given private key.

@@ -152,16 +174,11 @@ * :::info

const sign = (data, privateKey) => {
const privateKeyUint8Array = (0, exports.parseAndValidatePrivateKey)(privateKey);
const hash = (0, exports.hashMessage)(data);
const signature = constants_js_1.secp256k1.sign(hash.substring(2), privateKeyUint8Array);
const signatureBytes = signature.toCompactRawBytes();
const r = signature.r.toString(16).padStart(64, '0');
const s = signature.s.toString(16).padStart(64, '0');
const v = signature.recovery + 27;
const { messageHash, v, r, s, signature } = (0, exports.signMessageWithPrivateKey)(hash, privateKey);
return {
message: data,
messageHash: hash,
v: (0, web3_utils_1.numberToHex)(v),
r: `0x${r}`,
s: `0x${s}`,
signature: `${(0, web3_utils_1.bytesToHex)(signatureBytes)}${v.toString(16)}`,
messageHash,
v,
r,
s,
signature,
};

@@ -168,0 +185,0 @@ };

@@ -25,3 +25,12 @@ "use strict";

const legacyTransaction_js_1 = require("./legacyTransaction.js");
const extraTxTypes = new Map();
let extraTxTypes;
// use the global object, to work fine even if web3-eth and web3-eth-accounts was on a different versions:
const typedGlobal = global;
if (!typedGlobal.extraTxTypes) {
extraTxTypes = new Map();
typedGlobal.extraTxTypes = extraTxTypes;
}
else {
extraTxTypes = typedGlobal.extraTxTypes;
}
// eslint-disable-next-line @typescript-eslint/no-extraneous-class

@@ -28,0 +37,0 @@ class TransactionFactory {

@@ -123,2 +123,23 @@ /*

/**
* Takes a hash of a message and a private key, signs the message using the SECP256k1 elliptic curve algorithm, and returns the signature components.
* @param hash - The hash of the message to be signed, represented as a hexadecimal string.
* @param privateKey - The private key used to sign the message, represented as a byte array.
* @returns - The signature Object containing the message, messageHash, signature r, s, v
*/
export const signMessageWithPrivateKey = (hash, privateKey) => {
const privateKeyUint8Array = parseAndValidatePrivateKey(privateKey);
const signature = secp256k1.sign(hash.substring(2), privateKeyUint8Array);
const signatureBytes = signature.toCompactRawBytes();
const r = signature.r.toString(16).padStart(64, '0');
const s = signature.s.toString(16).padStart(64, '0');
const v = signature.recovery + 27;
return {
messageHash: hash,
v: numberToHex(v),
r: `0x${r}`,
s: `0x${s}`,
signature: `${bytesToHex(signatureBytes)}${v.toString(16)}`,
};
};
/**
* Signs arbitrary data with a given private key.

@@ -146,16 +167,11 @@ * :::info

export const sign = (data, privateKey) => {
const privateKeyUint8Array = parseAndValidatePrivateKey(privateKey);
const hash = hashMessage(data);
const signature = secp256k1.sign(hash.substring(2), privateKeyUint8Array);
const signatureBytes = signature.toCompactRawBytes();
const r = signature.r.toString(16).padStart(64, '0');
const s = signature.s.toString(16).padStart(64, '0');
const v = signature.recovery + 27;
const { messageHash, v, r, s, signature } = signMessageWithPrivateKey(hash, privateKey);
return {
message: data,
messageHash: hash,
v: numberToHex(v),
r: `0x${r}`,
s: `0x${s}`,
signature: `${bytesToHex(signatureBytes)}${v.toString(16)}`,
messageHash,
v,
r,
s,
signature,
};

@@ -162,0 +178,0 @@ };

@@ -22,3 +22,12 @@ /*

import { Transaction } from './legacyTransaction.js';
const extraTxTypes = new Map();
let extraTxTypes;
// use the global object, to work fine even if web3-eth and web3-eth-accounts was on a different versions:
const typedGlobal = global;
if (!typedGlobal.extraTxTypes) {
extraTxTypes = new Map();
typedGlobal.extraTxTypes = extraTxTypes;
}
else {
extraTxTypes = typedGlobal.extraTxTypes;
}
// eslint-disable-next-line @typescript-eslint/no-extraneous-class

@@ -25,0 +34,0 @@ export class TransactionFactory {

@@ -43,2 +43,9 @@ import { Address, Bytes, CipherOptions, HexString, KeyStore } from 'web3-types';

/**
* Takes a hash of a message and a private key, signs the message using the SECP256k1 elliptic curve algorithm, and returns the signature components.
* @param hash - The hash of the message to be signed, represented as a hexadecimal string.
* @param privateKey - The private key used to sign the message, represented as a byte array.
* @returns - The signature Object containing the message, messageHash, signature r, s, v
*/
export declare const signMessageWithPrivateKey: (hash: HexString, privateKey: Bytes) => SignResult;
/**
* Signs arbitrary data with a given private key.

@@ -45,0 +52,0 @@ * :::info

{
"name": "web3-eth-accounts",
"version": "4.1.4-dev.5f6deeb.0+5f6deeb",
"version": "4.1.4-dev.60fc197.0+60fc197",
"description": "Package for managing Ethereum accounts and signing",

@@ -58,3 +58,3 @@ "main": "./lib/commonjs/index.js",

"typescript": "^4.7.4",
"web3-providers-ipc": "4.0.8-dev.5f6deeb.0+5f6deeb"
"web3-providers-ipc": "4.0.8-dev.60fc197.0+60fc197"
},

@@ -65,8 +65,8 @@ "dependencies": {

"ethereum-cryptography": "^2.0.0",
"web3-errors": "1.2.1-dev.5f6deeb.0+5f6deeb",
"web3-types": "1.7.1-dev.5f6deeb.0+5f6deeb",
"web3-utils": "4.3.2-dev.5f6deeb.0+5f6deeb",
"web3-validator": "2.0.7-dev.5f6deeb.0+5f6deeb"
"web3-errors": "1.2.2-dev.60fc197.0+60fc197",
"web3-types": "1.7.1-dev.60fc197.0+60fc197",
"web3-utils": "4.3.2-dev.60fc197.0+60fc197",
"web3-validator": "2.0.7-dev.60fc197.0+60fc197"
},
"gitHead": "5f6deebd2b27a6120e3102f4f03fb82b8c1b4674"
"gitHead": "60fc1979820fa7be3b6052ccca8397ee75032631"
}

@@ -174,2 +174,25 @@ /*

/**
* Takes a hash of a message and a private key, signs the message using the SECP256k1 elliptic curve algorithm, and returns the signature components.
* @param hash - The hash of the message to be signed, represented as a hexadecimal string.
* @param privateKey - The private key used to sign the message, represented as a byte array.
* @returns - The signature Object containing the message, messageHash, signature r, s, v
*/
export const signMessageWithPrivateKey = (hash: HexString, privateKey: Bytes): SignResult => {
const privateKeyUint8Array = parseAndValidatePrivateKey(privateKey);
const signature = secp256k1.sign(hash.substring(2), privateKeyUint8Array);
const signatureBytes = signature.toCompactRawBytes();
const r = signature.r.toString(16).padStart(64, '0');
const s = signature.s.toString(16).padStart(64, '0');
const v = signature.recovery! + 27;
return {
messageHash: hash,
v: numberToHex(v),
r: `0x${r}`,
s: `0x${s}`,
signature: `${bytesToHex(signatureBytes)}${v.toString(16)}`,
};
};
/**
* Signs arbitrary data with a given private key.

@@ -197,19 +220,13 @@ * :::info

export const sign = (data: string, privateKey: Bytes): SignResult => {
const privateKeyUint8Array = parseAndValidatePrivateKey(privateKey);
const hash = hashMessage(data);
const signature = secp256k1.sign(hash.substring(2), privateKeyUint8Array);
const signatureBytes = signature.toCompactRawBytes();
const r = signature.r.toString(16).padStart(64, '0');
const s = signature.s.toString(16).padStart(64, '0');
const v = signature.recovery! + 27;
const { messageHash, v, r, s, signature } = signMessageWithPrivateKey(hash, privateKey);
return {
message: data,
messageHash: hash,
v: numberToHex(v),
r: `0x${r}`,
s: `0x${s}`,
signature: `${bytesToHex(signatureBytes)}${v.toString(16)}`,
messageHash,
v,
r,
s,
signature,
};

@@ -216,0 +233,0 @@ };

@@ -34,3 +34,11 @@ /*

const extraTxTypes: Map<Numbers, typeof BaseTransaction<unknown>> = new Map();
let extraTxTypes: Map<Numbers, typeof BaseTransaction<unknown>>;
// use the global object, to work fine even if web3-eth and web3-eth-accounts was on a different versions:
const typedGlobal = global as unknown as {extraTxTypes: Map<Numbers, typeof BaseTransaction<unknown>>}
if (!typedGlobal.extraTxTypes) {
extraTxTypes = new Map();
typedGlobal.extraTxTypes = extraTxTypes;
} else {
extraTxTypes = typedGlobal.extraTxTypes;
}

@@ -37,0 +45,0 @@ // eslint-disable-next-line @typescript-eslint/no-extraneous-class

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

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