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

ethereum-cryptography

Package Overview
Dependencies
Maintainers
2
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ethereum-cryptography - npm Package Compare versions

Comparing version 1.0.3 to 1.1.0

9

keccak.d.ts

@@ -0,4 +1,11 @@

import { Keccak } from "@noble/hashes/sha3";
import { Hash } from "@noble/hashes/utils";
interface K256 {
(data: Uint8Array): Uint8Array;
create(): Hash<Keccak>;
}
export declare const keccak224: (msg: Uint8Array) => Uint8Array;
export declare const keccak256: (msg: Uint8Array) => Uint8Array;
export declare const keccak256: K256;
export declare const keccak384: (msg: Uint8Array) => Uint8Array;
export declare const keccak512: (msg: Uint8Array) => Uint8Array;
export {};

33

keccak.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]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.keccak512 = exports.keccak384 = exports.keccak256 = exports.keccak224 = void 0;
const sha3 = __importStar(require("@noble/hashes/sha3"));
const sha3_1 = require("@noble/hashes/sha3");
const utils_1 = require("./utils");
exports.keccak224 = (0, utils_1.wrapHash)(sha3.keccak_224);
exports.keccak256 = (0, utils_1.wrapHash)(sha3.keccak_256);
exports.keccak384 = (0, utils_1.wrapHash)(sha3.keccak_384);
exports.keccak512 = (0, utils_1.wrapHash)(sha3.keccak_512);
exports.keccak224 = (0, utils_1.wrapHash)(sha3_1.keccak_224);
exports.keccak256 = (() => {
const k = (0, utils_1.wrapHash)(sha3_1.keccak_256);
k.create = sha3_1.keccak_256.create;
return k;
})();
exports.keccak384 = (0, utils_1.wrapHash)(sha3_1.keccak_384);
exports.keccak512 = (0, utils_1.wrapHash)(sha3_1.keccak_512);
{
"name": "ethereum-cryptography",
"version": "1.0.3",
"version": "1.1.0",
"description": "All the cryptographic primitives used in Ethereum",

@@ -27,6 +27,6 @@ "contributors": [

"dependencies": {
"@noble/hashes": "1.0.0",
"@noble/secp256k1": "1.5.5",
"@scure/bip32": "1.0.1",
"@scure/bip39": "1.0.0"
"@noble/hashes": "1.1.1",
"@noble/secp256k1": "1.6.0",
"@scure/bip32": "1.1.0",
"@scure/bip39": "1.1.0"
},

@@ -33,0 +33,0 @@ "browser": {

@@ -1,2 +0,2 @@

export declare function scrypt(password: Uint8Array, salt: Uint8Array, n: number, p: number, r: number, dklen: number): Promise<Uint8Array>;
export declare function scryptSync(password: Uint8Array, salt: Uint8Array, n: number, p: number, r: number, dklen: number): Uint8Array;
export declare function scrypt(password: Uint8Array, salt: Uint8Array, n: number, p: number, r: number, dkLen: number): Promise<Uint8Array>;
export declare function scryptSync(password: Uint8Array, salt: Uint8Array, n: number, p: number, r: number, dkLen: number): Uint8Array;

@@ -6,13 +6,13 @@ "use strict";

const utils_1 = require("./utils");
async function scrypt(password, salt, n, p, r, dklen) {
async function scrypt(password, salt, n, p, r, dkLen) {
(0, utils_1.assertBytes)(password);
(0, utils_1.assertBytes)(salt);
return (0, scrypt_1.scryptAsync)(password, salt, { N: n, r, p, dkLen: dklen });
return (0, scrypt_1.scryptAsync)(password, salt, { N: n, r, p, dkLen });
}
exports.scrypt = scrypt;
function scryptSync(password, salt, n, p, r, dklen) {
function scryptSync(password, salt, n, p, r, dkLen) {
(0, utils_1.assertBytes)(password);
(0, utils_1.assertBytes)(salt);
return (0, scrypt_1.scrypt)(password, salt, { N: n, r, p, dkLen: dklen });
return (0, scrypt_1.scrypt)(password, salt, { N: n, r, p, dkLen });
}
exports.scryptSync = scryptSync;

@@ -28,6 +28,2 @@ "use strict";

// This is a legacy compatibility layer for the npm package `secp256k1` via noble-secp256k1
// Copy-paste from secp256k1, maybe export it?
const bytesToNumber = (bytes) => hexToNumber((0, utils_1.toHex)(bytes));
const numberToHex = (num) => num.toString(16).padStart(64, "0");
const numberToBytes = (num) => (0, utils_1.hexToBytes)(numberToHex(num));
function hexToNumber(hex) {

@@ -39,7 +35,7 @@ if (typeof hex !== "string") {

}
// Calculates a modulo b
function mod(a, b = secp.CURVE.P) {
const result = a % b;
return result >= 0 ? result : b + result;
}
// Copy-paste from secp256k1, maybe export it?
const bytesToNumber = (bytes) => hexToNumber((0, utils_1.toHex)(bytes));
const numberToHex = (num) => num.toString(16).padStart(64, "0");
const numberToBytes = (num) => (0, utils_1.hexToBytes)(numberToHex(num));
const { mod } = secp.utils;
const ORDER = secp.CURVE.n;

@@ -148,17 +144,17 @@ function output(out = (len) => new Uint8Array(len), length, value) {

(0, utils_1.assertBytes)(tweak, 32);
let bn = bytesToNumber(tweak);
if (bn === 0n) {
let t = bytesToNumber(tweak);
if (t === 0n) {
throw new Error("Tweak must not be zero");
}
if (bn >= ORDER) {
if (t >= ORDER) {
throw new Error("Tweak bigger than curve order");
}
bn += bytesToNumber(privateKey);
if (bn >= ORDER) {
bn -= ORDER;
t += bytesToNumber(privateKey);
if (t >= ORDER) {
t -= ORDER;
}
if (bn === 0n) {
if (t === 0n) {
throw new Error("The tweak was out of range or the resulted private key is invalid");
}
privateKey.set((0, utils_1.hexToBytes)(numberToHex(bn)));
privateKey.set((0, utils_1.hexToBytes)(numberToHex(t)));
return privateKey;

@@ -165,0 +161,0 @@ }

@@ -1,3 +0,7 @@

export { assertBool, assertBytes, bytesToHex, bytesToHex as toHex, concatBytes, hexToBytes, createView, utf8ToBytes } from "@noble/hashes/utils";
declare const assertBool: typeof import("@noble/hashes/_assert").bool;
declare const assertBytes: typeof import("@noble/hashes/_assert").bytes;
export { assertBool, assertBytes };
export { bytesToHex, bytesToHex as toHex, concatBytes, createView, utf8ToBytes } from "@noble/hashes/utils";
export declare function bytesToUtf8(data: Uint8Array): string;
export declare function hexToBytes(data: string): Uint8Array;
export declare function equalsBytes(a: Uint8Array, b: Uint8Array): boolean;

@@ -4,0 +8,0 @@ export declare function wrapHash(hash: (msg: Uint8Array) => Uint8Array): (msg: Uint8Array) => Uint8Array;

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.crypto = exports.wrapHash = exports.equalsBytes = exports.bytesToUtf8 = exports.utf8ToBytes = exports.createView = exports.hexToBytes = exports.concatBytes = exports.toHex = exports.bytesToHex = exports.assertBytes = exports.assertBool = void 0;
exports.crypto = exports.wrapHash = exports.equalsBytes = exports.hexToBytes = exports.bytesToUtf8 = exports.utf8ToBytes = exports.createView = exports.concatBytes = exports.toHex = exports.bytesToHex = exports.assertBytes = exports.assertBool = void 0;
// buf.toString('hex') -> toHex(buf)
const _assert_1 = __importDefault(require("@noble/hashes/_assert"));
const utils_1 = require("@noble/hashes/utils");
const assertBool = _assert_1.default.bool;
exports.assertBool = assertBool;
const assertBytes = _assert_1.default.bytes;
exports.assertBytes = assertBytes;
var utils_2 = require("@noble/hashes/utils");
Object.defineProperty(exports, "assertBool", { enumerable: true, get: function () { return utils_2.assertBool; } });
Object.defineProperty(exports, "assertBytes", { enumerable: true, get: function () { return utils_2.assertBytes; } });
Object.defineProperty(exports, "bytesToHex", { enumerable: true, get: function () { return utils_2.bytesToHex; } });
Object.defineProperty(exports, "toHex", { enumerable: true, get: function () { return utils_2.bytesToHex; } });
Object.defineProperty(exports, "concatBytes", { enumerable: true, get: function () { return utils_2.concatBytes; } });
Object.defineProperty(exports, "hexToBytes", { enumerable: true, get: function () { return utils_2.hexToBytes; } });
Object.defineProperty(exports, "createView", { enumerable: true, get: function () { return utils_2.createView; } });

@@ -23,2 +28,7 @@ Object.defineProperty(exports, "utf8ToBytes", { enumerable: true, get: function () { return utils_2.utf8ToBytes; } });

exports.bytesToUtf8 = bytesToUtf8;
function hexToBytes(data) {
const sliced = data.startsWith("0x") ? data.substring(2) : data;
return (0, utils_1.hexToBytes)(sliced);
}
exports.hexToBytes = hexToBytes;
// buf.equals(buf2) -> equalsBytes(buf, buf2)

@@ -40,3 +50,3 @@ function equalsBytes(a, b) {

return (msg) => {
(0, utils_1.assertBytes)(msg);
_assert_1.default.bytes(msg);
return hash(msg);

@@ -43,0 +53,0 @@ };

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