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 2.0.0 to 2.1.0

esm/aes.js

149

package.json
{
"name": "ethereum-cryptography",
"version": "2.0.0",
"version": "2.1.0",
"description": "All the cryptographic primitives used in Ethereum",

@@ -24,10 +24,143 @@ "contributors": [

"*.js",
"*.d.ts"
"*.d.ts",
"esm"
],
"dependencies": {
"@noble/curves": "1.0.0",
"@noble/hashes": "1.3.0",
"@scure/bip32": "1.3.0",
"@scure/bip39": "1.2.0"
"@noble/curves": "1.1.0",
"@noble/hashes": "1.3.1",
"@scure/bip32": "1.3.1",
"@scure/bip39": "1.2.1"
},
"exports": {
".": {
"types": "./index.d.ts",
"import": "./esm/index.js",
"default": "./index.js"
},
"./aes.js": {
"types": "./aes.d.ts",
"import": "./esm/aes.js",
"default": "./aes.js"
},
"./bip39.js": {
"types": "./bip39.d.ts",
"import": "./esm/bip39.js",
"default": "./bip39.js"
},
"./blake2b.js": {
"types": "./blake2b.d.ts",
"import": "./esm/blake2b.js",
"default": "./blake2b.js"
},
"./hdkey.js": {
"types": "./hdkey.d.ts",
"import": "./esm/hdkey.js",
"default": "./hdkey.js"
},
"./index.js": {
"types": "./index.d.ts",
"import": "./esm/index.js",
"default": "./index.js"
},
"./keccak.js": {
"types": "./keccak.d.ts",
"import": "./esm/keccak.js",
"default": "./keccak.js"
},
"./pbkdf2.js": {
"types": "./pbkdf2.d.ts",
"import": "./esm/pbkdf2.js",
"default": "./pbkdf2.js"
},
"./random.js": {
"types": "./random.d.ts",
"import": "./esm/random.js",
"default": "./random.js"
},
"./ripemd160.js": {
"types": "./ripemd160.d.ts",
"import": "./esm/ripemd160.js",
"default": "./ripemd160.js"
},
"./scrypt.js": {
"types": "./scrypt.d.ts",
"import": "./esm/scrypt.js",
"default": "./scrypt.js"
},
"./secp256k1-compat.js": {
"types": "./secp256k1-compat.d.ts",
"import": "./esm/secp256k1-compat.js",
"default": "./secp256k1-compat.js"
},
"./secp256k1.js": {
"types": "./secp256k1.d.ts",
"import": "./esm/secp256k1.js",
"default": "./secp256k1.js"
},
"./sha256.js": {
"types": "./sha256.d.ts",
"import": "./esm/sha256.js",
"default": "./sha256.js"
},
"./sha512.js": {
"types": "./sha512.d.ts",
"import": "./esm/sha512.js",
"default": "./sha512.js"
},
"./utils.js": {
"types": "./utils.d.ts",
"import": "./esm/utils.js",
"default": "./utils.js"
},
"./bip39/index.js": {
"types": "./bip39/index.d.ts",
"import": "./esm/bip39/index.js",
"default": "./bip39/index.js"
},
"./bip39/wordlists/czech.js": {
"types": "./bip39/wordlists/czech.d.ts",
"import": "./esm/bip39/wordlists/czech.js",
"default": "./bip39/wordlists/czech.js"
},
"./bip39/wordlists/english.js": {
"types": "./bip39/wordlists/english.d.ts",
"import": "./esm/bip39/wordlists/english.js",
"default": "./bip39/wordlists/english.js"
},
"./bip39/wordlists/french.js": {
"types": "./bip39/wordlists/french.d.ts",
"import": "./esm/bip39/wordlists/french.js",
"default": "./bip39/wordlists/french.js"
},
"./bip39/wordlists/italian.js": {
"types": "./bip39/wordlists/italian.d.ts",
"import": "./esm/bip39/wordlists/italian.js",
"default": "./bip39/wordlists/italian.js"
},
"./bip39/wordlists/japanese.js": {
"types": "./bip39/wordlists/japanese.d.ts",
"import": "./esm/bip39/wordlists/japanese.js",
"default": "./bip39/wordlists/japanese.js"
},
"./bip39/wordlists/korean.js": {
"types": "./bip39/wordlists/korean.d.ts",
"import": "./esm/bip39/wordlists/korean.js",
"default": "./bip39/wordlists/korean.js"
},
"./bip39/wordlists/simplified-chinese.js": {
"types": "./bip39/wordlists/simplified-chinese.d.ts",
"import": "./esm/bip39/wordlists/simplified-chinese.js",
"default": "./bip39/wordlists/simplified-chinese.js"
},
"./bip39/wordlists/spanish.js": {
"types": "./bip39/wordlists/spanish.d.ts",
"import": "./esm/bip39/wordlists/spanish.js",
"default": "./bip39/wordlists/spanish.js"
},
"./bip39/wordlists/traditional-chinese.js": {
"types": "./bip39/wordlists/traditional-chinese.d.ts",
"import": "./esm/bip39/wordlists/traditional-chinese.js",
"default": "./bip39/wordlists/traditional-chinese.js"
}
},
"browser": {

@@ -40,3 +173,3 @@ "crypto": false

"build": "npm-run-all build:tsc",
"build:tsc": "tsc --project tsconfig.prod.json",
"build:tsc": "tsc --project tsconfig.prod.json && tsc --project tsconfig.prod.esm.json",
"test": "npm-run-all test:node",

@@ -95,3 +228,3 @@ "test:node": "mocha",

"aes",
"advanced encryption standar",
"advanced encryption standard",
"secp256k1",

@@ -98,0 +231,0 @@ "ecdsa",

129

README.md
# ethereum-cryptography
[![npm version][1]][2] [![Travis CI][3]][4] [![license][5]][6] [![Types][7]][8]
[![npm version][1]][2] [![license][3]][4]
All pure-js cryptographic primitives normally used when
developing Javascript / TypeScript applications and tools for Ethereum.
[Audited](#security) pure JS library containing all Ethereum-related cryptographic primitives.
Included algorithms, implemented with just 5 [noble & scure](https://paulmillr.com/noble/) dependencies:
* [Hashes: SHA256, keccak-256, RIPEMD160, BLAKE2b](#hashes-sha256-keccak-256-ripemd160-blake2b)
* [KDFs: PBKDF2, Scrypt](#kdfs-pbkdf2-scrypt)
* [CSPRNG (Cryptographically Secure Pseudorandom Number Generator)](#csprng-cryptographically-strong-pseudorandom-number-generator)
* [secp256k1 elliptic curve](#secp256k1-curve)
* [BIP32 HD Keygen](#bip32-hd-keygen)
* [BIP39 Mnemonic phrases](#bip39-mnemonic-seed-phrase)
* [AES Encryption](#aes-encryption)
**April 2023 update:** v2.0 is out, switching

@@ -12,22 +21,12 @@ [noble-secp256k1](https://github.com/paulmillr/noble-secp256k1) to

which changes re-exported api of `secp256k1` submodule.
There have been no other changes. Check out [Upgrading](#upgrading).
There have been no other changes.
**January 2022 update:** We've released v1.0 of the package, a complete rewrite:
**January 2022 update:** v1.0 has been released. We've rewritten the library from
scratch and [audited](#security) it. It became **6x smaller:** ~5,000 lines of
code instead of ~24,000 (with all deps); 650KB instead of 10.2MB.
5 dependencies by 1 author are now used, instead of 38 by 5 authors.
- **6x smaller:** ~5,000 lines of code instead of ~24,000 (with all deps); 650KB instead of 10.2MB
- 5 dependencies by 1 author instead of 38 by 5 authors
- [Audited](#security) by an independent security firm
- Check out the article about it: [A safer, smaller, and faster Ethereum cryptography stack](https://medium.com/nomic-labs-blog/a-safer-smaller-and-faster-ethereum-cryptography-stack-5eeb47f62d79)
- Take a glance at the [Upgrading](#upgrading) section for breaking changes: there are almost none
Check out [Upgrading](#upgrading) section and an article about the library:
[A safer, smaller, and faster Ethereum cryptography stack](https://medium.com/nomic-labs-blog/a-safer-smaller-and-faster-ethereum-cryptography-stack-5eeb47f62d79).
The cryptographic primitives included are:
* [Hashes: SHA256, keccak-256, RIPEMD160, BLAKE2b](#hashes-sha256-keccak-256-ripemd160-blake2b)
* [KDFs: PBKDF2, Scrypt](#kdfs-pbkdf2-scrypt)
* [CSPRNG (Cryptographically strong pseudorandom number generator)](#csprng-cryptographically-strong-pseudorandom-number-generator)
* [secp256k1 curve](#secp256k1-curve)
* [BIP32 HD Keygen](#bip32-hd-keygen)
* [BIP39 Mnemonic phrases](#bip39-mnemonic-seed-phrase)
* [AES Encryption](#aes-encryption)
## Usage

@@ -59,27 +58,27 @@

// Hashes
const { sha256 } = require("ethereum-cryptography/sha256");
const { keccak256 } = require("ethereum-cryptography/keccak");
const { ripemd160 } = require("ethereum-cryptography/ripemd160");
const { blake2b } = require("ethereum-cryptography/blake2b");
import { sha256 } from "ethereum-cryptography/sha256.js";
import { keccak256 } from "ethereum-cryptography/keccak.js";
import { ripemd160 } from "ethereum-cryptography/ripemd160.js";
import { blake2b } from "ethereum-cryptography/blake2b.js";
// KDFs
const { pbkdf2Sync } = require("ethereum-cryptography/pbkdf2");
const { scryptSync } = require("ethereum-cryptography/scrypt");
import { pbkdf2Sync } from "ethereum-cryptography/pbkdf2.js";
import { scryptSync } from "ethereum-cryptography/scrypt.js";
// Random
const { getRandomBytesSync } = require("ethereum-cryptography/random");
import { getRandomBytesSync } from "ethereum-cryptography/random.js";
// AES encryption
const { encrypt } = require("ethereum-cryptography/aes");
import { encrypt } from "ethereum-cryptography/aes.js";
// secp256k1 elliptic curve operations
const { createPrivateKeySync, ecdsaSign } = require("ethereum-cryptography/secp256k1");
import { secp256k1 } from "ethereum-cryptography/secp256k1.js";
// BIP32 HD Keygen, BIP39 Mnemonic Phrases
const { HDKey } = require("ethereum-cryptography/hdkey");
const { generateMnemonic } = require("ethereum-cryptography/bip39");
const { wordlist } = require("ethereum-cryptography/bip39/wordlists/english");
import { HDKey } from "ethereum-cryptography/hdkey.js";
import { generateMnemonic } from "ethereum-cryptography/bip39/index.js";
import { wordlist } from "ethereum-cryptography/bip39/wordlists/english.js";
// utilities
const { hexToBytes, toHex, utf8ToBytes } = require("ethereum-cryptography/utils");
import { hexToBytes, toHex, utf8ToBytes } from "ethereum-cryptography/utils.js";
```

@@ -105,7 +104,7 @@

```js
const { sha256 } = require("ethereum-cryptography/sha256");
const { sha512 } = require("ethereum-cryptography/sha512");
const { keccak256, keccak224, keccak384, keccak512 } = require("ethereum-cryptography/keccak");
const { ripemd160 } = require("ethereum-cryptography/ripemd160");
const { blake2b } = require("ethereum-cryptography/blake2b");
import { sha256 } from "ethereum-cryptography/sha256.js";
import { sha512 } from "ethereum-cryptography/sha512.js";
import { keccak256, keccak224, keccak384, keccak512 } from "ethereum-cryptography/keccak.js";
import { ripemd160 } from "ethereum-cryptography/ripemd160.js";
import { blake2b } from "ethereum-cryptography/blake2b.js";

@@ -115,7 +114,7 @@ sha256(Uint8Array.from([1, 2, 3]))

// Can be used with strings
const { utf8ToBytes } = require("ethereum-cryptography/utils");
import { utf8ToBytes } from "ethereum-cryptography/utils.js";
sha256(utf8ToBytes("abc"))
// If you need hex
const { bytesToHex as toHex } = require("ethereum-cryptography/utils");
import { bytesToHex as toHex } from "ethereum-cryptography/utils.js";
toHex(sha256(utf8ToBytes("abc")))

@@ -148,4 +147,4 @@ ```

```js
const { pbkdf2 } = require("ethereum-cryptography/pbkdf2");
const { utf8ToBytes } = require("ethereum-cryptography/utils");
import { pbkdf2 } from "ethereum-cryptography/pbkdf2.js";
import { utf8ToBytes } from "ethereum-cryptography/utils.js";
// Pass Uint8Array, or convert strings to Uint8Array

@@ -156,4 +155,4 @@ console.log(await pbkdf2(utf8ToBytes("password"), utf8ToBytes("salt"), 131072, 32, "sha256"));

```js
const { scrypt } = require("ethereum-cryptography/scrypt");
const { utf8ToBytes } = require("ethereum-cryptography/utils");
import { scrypt } from "ethereum-cryptography/scrypt.js";
import { utf8ToBytes } from "ethereum-cryptography/utils.js";
console.log(await scrypt(utf8ToBytes("password"), utf8ToBytes("salt"), 262144, 8, 1, 32));

@@ -175,3 +174,3 @@ ```

```js
const { getRandomBytesSync } = require("ethereum-cryptography/random");
import { getRandomBytesSync } from "ethereum-cryptography/random.js";
console.log(getRandomBytesSync(32));

@@ -198,3 +197,3 @@ ```

```js
const {secp256k1} = require("ethereum-cryptography/secp256k1");
import { secp256k1 } from "ethereum-cryptography/secp256k1.js";
(async () => {

@@ -210,3 +209,5 @@ // You pass either a hex string, or Uint8Array

Note: if you've been using ethereum-cryptography v0.1, it had different API. We're providing a compatibility layer for users who want to upgrade without hassle. Check out [the legacy documentation](#legacy-secp256k1-compatibility-layer).
We're also providing a compatibility layer for users who want to upgrade
from `tiny-secp256k1` or `secp256k1` modules without hassle.
Check out [secp256k1 compatibility layer](#legacy-secp256k1-compatibility-layer).

@@ -221,3 +222,3 @@ ## BIP32 HD Keygen

```ts
const { HDKey } = require("ethereum-cryptography/hdkey");
import { HDKey } from "ethereum-cryptography/hdkey.js";
const hdkey1 = HDKey.fromMasterSeed(seed);

@@ -300,4 +301,4 @@ const hdkey2 = HDKey.fromExtendedKey(base58key);

```js
const { generateMnemonic } = require("ethereum-cryptography/bip39");
const { wordlist } = require("ethereum-cryptography/bip39/wordlists/english");
import { generateMnemonic } from "ethereum-cryptography/bip39/index.js";
import { wordlist } from "ethereum-cryptography/bip39/wordlists/english.js";
console.log(generateMnemonic(wordlist));

@@ -399,4 +400,4 @@ ```

```js
const { encrypt } = require("ethereum-cryptography/aes");
const { hexToBytes, utf8ToBytes } = require("ethereum-cryptography/utils");
import { encrypt } from "ethereum-cryptography/aes.js";
import { hexToBytes, utf8ToBytes } from "ethereum-cryptography/utils.js";

@@ -435,6 +436,4 @@ console.log(

**Note:** consider using `secp256k1` instead;
This module is only for users who upgraded
from ethereum-cryptography v0.1. It could be removed in the future,
but we're keeping it around for now, for backwards-compatibility.
**Warning:** use `secp256k1` instead. This module is only for users who upgraded
from ethereum-cryptography v0.1. It could be removed in the future.

@@ -444,3 +443,3 @@ The API of `secp256k1-compat` is the same as [secp256k1-node](https://github.com/cryptocoinjs/secp256k1-node):

```js
const { createPrivateKeySync, ecdsaSign } = require("ethereum-cryptography/secp256k1-compat");
import { createPrivateKeySync, ecdsaSign } from "ethereum-cryptography/secp256k1-compat";
const msgHash = Uint8Array.from(

@@ -477,3 +476,3 @@ "82ff40c0a986c6a5cfad4ddf4c3aa6996f1a7837f9c398e17e5de5cbd5a12b28",

b) `recoverPublicKey` got moved onto a `Signature` instance
2. node.js 14 and older support was dropped. Upgrade to node.js 16 or later.
2. node.js 14 and older support was dropped. Upgrade to node.js 16 or later.

@@ -489,4 +488,4 @@ Upgrading from 0.1 to 1.0: **Same functionality**, all old APIs remain the same except for the breaking changes:

```
const { sha256 } = require("ethereum-cryptography/sha256");
```js
import { sha256 } from "ethereum-cryptography/sha256.js";

@@ -497,3 +496,3 @@ // Old usage

// New usage
const { toHex } = require("ethereum-cryptography/utils");
import { toHex } from "ethereum-cryptography/utils.js";
const hashn = toHex(sha256("string"));

@@ -525,7 +524,3 @@

[2]: https://www.npmjs.com/package/ethereum-cryptography
[3]: https://img.shields.io/travis/ethereum/js-ethereum-cryptography/master.svg?label=Travis%20CI
[4]: https://travis-ci.org/ethereum/js-ethereum-cryptography
[5]: https://img.shields.io/npm/l/ethereum-cryptography
[6]: https://github.com/ethereum/js-ethereum-cryptography/blob/master/packages/ethereum-cryptography/LICENSE
[7]: https://img.shields.io/npm/types/ethereum-cryptography.svg
[8]: https://www.npmjs.com/package/ethereum-cryptography
[3]: https://img.shields.io/npm/l/ethereum-cryptography
[4]: https://github.com/ethereum/js-ethereum-cryptography/blob/master/packages/ethereum-cryptography/LICENSE

@@ -11,3 +11,3 @@ declare const assertBool: typeof import("@noble/hashes/_assert").bool;

node?: any;
web?: Crypto;
web?: any;
};

@@ -54,4 +54,5 @@ "use strict";

exports.wrapHash = wrapHash;
// TODO(v3): switch away from node crypto, remove this unnecessary variable.
exports.crypto = (() => {
const webCrypto = typeof self === "object" && "crypto" in self ? self.crypto : undefined;
const webCrypto = typeof globalThis === "object" && "crypto" in globalThis ? globalThis.crypto : undefined;
const nodeRequire = typeof module !== "undefined" &&

@@ -58,0 +59,0 @@ typeof module.require === "function" &&

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