Skip to content

Add hybrid common.js - ESM support. Bump deps. Closes #79, #80, #14 #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node: [16, 18, 19]
node: [18, 20]
os: [ubuntu-latest]
steps:
- uses: actions/checkout@v3
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
/test-builds
/node_modules
/.parcel-cache
/esm
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"files.exclude": {
"*.{js,d.ts,js.map,d.ts.map}": true,
"esm/*.{js,d.ts,js.map,d.ts.map}": true
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

[Audited](#security) pure JS library containing all Ethereum-related cryptographic primitives.

Included algorithms, implemented with 5 @noble & @scure packages:
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)
Expand Down
3 changes: 3 additions & 0 deletions esm/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
145 changes: 139 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ethereum-cryptography",
"version": "2.0.0",
"version": "2.1.0",
"description": "All the cryptographic primitives used in Ethereum",
"contributors": [
{
Expand All @@ -21,13 +21,146 @@
"bip39/wordlists/*.js",
"bip39/wordlists/*.d.ts",
"*.js",
"*.d.ts"
"*.d.ts",
"esm"
],
"dependencies": {
"@noble/curves": "1.0.0",
"@noble/hashes": "1.3.0",
"@noble/curves": "1.1.0",
"@noble/hashes": "1.3.1",
"@scure/bip32": "1.3.0",
"@scure/bip39": "1.2.0"
"@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": {
"crypto": false
Expand All @@ -36,7 +169,7 @@
"scripts": {
"prepare": "npm run build",
"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",
"test:node": "mocha",
"clean": "rimraf test-builds bip39 '*.js' '*.js.map' '*.d.ts' '*.d.ts.map' 'src/**/*.js'",
Expand Down
2 changes: 2 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ export function wrapHash(hash: (msg: Uint8Array) => Uint8Array) {
};
}

declare const globalThis: Record<string, any> | undefined;

// TODO(v3): switch away from node crypto, remove this unnecessary variable.
export const crypto: { node?: any; web?: any } = (() => {
const webCrypto =
Expand Down
15 changes: 15 additions & 0 deletions tsconfig.prod.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"compilerOptions": {
"target": "es2020",
"lib": ["es2020", "dom"],
"module": "es6",
"moduleResolution": "node",
"strict": true,
"rootDir": "src",
"outDir": "esm"
},
"include": [
"src/**/*.ts"
],
"exclude": []
}