Skip to content

Commit 06b37c5

Browse files
authored
Merge pull request #81 from ethereum/esm
Add hybrid common.js - ESM support. Bump deps. Closes #79, #80, #14
2 parents a2fffce + 8e2e571 commit 06b37c5

File tree

8 files changed

+168
-8
lines changed

8 files changed

+168
-8
lines changed

.github/workflows/nodejs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
runs-on: ${{ matrix.os }}
1010
strategy:
1111
matrix:
12-
node: [16, 18, 19]
12+
node: [18, 20]
1313
os: [ubuntu-latest]
1414
steps:
1515
- uses: actions/checkout@v3

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
/test-builds
77
/node_modules
88
/.parcel-cache
9+
/esm

.vscode/settings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"files.exclude": {
3+
"*.{js,d.ts,js.map,d.ts.map}": true,
4+
"esm/*.{js,d.ts,js.map,d.ts.map}": true
5+
}
6+
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

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

7-
Included algorithms, implemented with 5 @noble & @scure packages:
7+
Included algorithms, implemented with just 5 [noble & scure](https://paulmillr.com/noble/) dependencies:
88

99
* [Hashes: SHA256, keccak-256, RIPEMD160, BLAKE2b](#hashes-sha256-keccak-256-ripemd160-blake2b)
1010
* [KDFs: PBKDF2, Scrypt](#kdfs-pbkdf2-scrypt)

esm/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"type": "module"
3+
}

package.json

Lines changed: 139 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ethereum-cryptography",
3-
"version": "2.0.0",
3+
"version": "2.1.0",
44
"description": "All the cryptographic primitives used in Ethereum",
55
"contributors": [
66
{
@@ -21,13 +21,146 @@
2121
"bip39/wordlists/*.js",
2222
"bip39/wordlists/*.d.ts",
2323
"*.js",
24-
"*.d.ts"
24+
"*.d.ts",
25+
"esm"
2526
],
2627
"dependencies": {
27-
"@noble/curves": "1.0.0",
28-
"@noble/hashes": "1.3.0",
28+
"@noble/curves": "1.1.0",
29+
"@noble/hashes": "1.3.1",
2930
"@scure/bip32": "1.3.0",
30-
"@scure/bip39": "1.2.0"
31+
"@scure/bip39": "1.2.1"
32+
},
33+
"exports": {
34+
".": {
35+
"types": "./index.d.ts",
36+
"import": "./esm/index.js",
37+
"default": "./index.js"
38+
},
39+
"./aes.js": {
40+
"types": "./aes.d.ts",
41+
"import": "./esm/aes.js",
42+
"default": "./aes.js"
43+
},
44+
"./bip39.js": {
45+
"types": "./bip39.d.ts",
46+
"import": "./esm/bip39.js",
47+
"default": "./bip39.js"
48+
},
49+
"./blake2b.js": {
50+
"types": "./blake2b.d.ts",
51+
"import": "./esm/blake2b.js",
52+
"default": "./blake2b.js"
53+
},
54+
"./hdkey.js": {
55+
"types": "./hdkey.d.ts",
56+
"import": "./esm/hdkey.js",
57+
"default": "./hdkey.js"
58+
},
59+
"./index.js": {
60+
"types": "./index.d.ts",
61+
"import": "./esm/index.js",
62+
"default": "./index.js"
63+
},
64+
"./keccak.js": {
65+
"types": "./keccak.d.ts",
66+
"import": "./esm/keccak.js",
67+
"default": "./keccak.js"
68+
},
69+
"./pbkdf2.js": {
70+
"types": "./pbkdf2.d.ts",
71+
"import": "./esm/pbkdf2.js",
72+
"default": "./pbkdf2.js"
73+
},
74+
"./random.js": {
75+
"types": "./random.d.ts",
76+
"import": "./esm/random.js",
77+
"default": "./random.js"
78+
},
79+
"./ripemd160.js": {
80+
"types": "./ripemd160.d.ts",
81+
"import": "./esm/ripemd160.js",
82+
"default": "./ripemd160.js"
83+
},
84+
"./scrypt.js": {
85+
"types": "./scrypt.d.ts",
86+
"import": "./esm/scrypt.js",
87+
"default": "./scrypt.js"
88+
},
89+
"./secp256k1-compat.js": {
90+
"types": "./secp256k1-compat.d.ts",
91+
"import": "./esm/secp256k1-compat.js",
92+
"default": "./secp256k1-compat.js"
93+
},
94+
"./secp256k1.js": {
95+
"types": "./secp256k1.d.ts",
96+
"import": "./esm/secp256k1.js",
97+
"default": "./secp256k1.js"
98+
},
99+
"./sha256.js": {
100+
"types": "./sha256.d.ts",
101+
"import": "./esm/sha256.js",
102+
"default": "./sha256.js"
103+
},
104+
"./sha512.js": {
105+
"types": "./sha512.d.ts",
106+
"import": "./esm/sha512.js",
107+
"default": "./sha512.js"
108+
},
109+
"./utils.js": {
110+
"types": "./utils.d.ts",
111+
"import": "./esm/utils.js",
112+
"default": "./utils.js"
113+
},
114+
"./bip39/index.js": {
115+
"types": "./bip39/index.d.ts",
116+
"import": "./esm/bip39/index.js",
117+
"default": "./bip39/index.js"
118+
},
119+
"./bip39/wordlists/czech.js": {
120+
"types": "./bip39/wordlists/czech.d.ts",
121+
"import": "./esm/bip39/wordlists/czech.js",
122+
"default": "./bip39/wordlists/czech.js"
123+
},
124+
"./bip39/wordlists/english.js": {
125+
"types": "./bip39/wordlists/english.d.ts",
126+
"import": "./esm/bip39/wordlists/english.js",
127+
"default": "./bip39/wordlists/english.js"
128+
},
129+
"./bip39/wordlists/french.js": {
130+
"types": "./bip39/wordlists/french.d.ts",
131+
"import": "./esm/bip39/wordlists/french.js",
132+
"default": "./bip39/wordlists/french.js"
133+
},
134+
"./bip39/wordlists/italian.js": {
135+
"types": "./bip39/wordlists/italian.d.ts",
136+
"import": "./esm/bip39/wordlists/italian.js",
137+
"default": "./bip39/wordlists/italian.js"
138+
},
139+
"./bip39/wordlists/japanese.js": {
140+
"types": "./bip39/wordlists/japanese.d.ts",
141+
"import": "./esm/bip39/wordlists/japanese.js",
142+
"default": "./bip39/wordlists/japanese.js"
143+
},
144+
"./bip39/wordlists/korean.js": {
145+
"types": "./bip39/wordlists/korean.d.ts",
146+
"import": "./esm/bip39/wordlists/korean.js",
147+
"default": "./bip39/wordlists/korean.js"
148+
},
149+
"./bip39/wordlists/simplified-chinese.js": {
150+
"types": "./bip39/wordlists/simplified-chinese.d.ts",
151+
"import": "./esm/bip39/wordlists/simplified-chinese.js",
152+
"default": "./bip39/wordlists/simplified-chinese.js"
153+
},
154+
"./bip39/wordlists/spanish.js": {
155+
"types": "./bip39/wordlists/spanish.d.ts",
156+
"import": "./esm/bip39/wordlists/spanish.js",
157+
"default": "./bip39/wordlists/spanish.js"
158+
},
159+
"./bip39/wordlists/traditional-chinese.js": {
160+
"types": "./bip39/wordlists/traditional-chinese.d.ts",
161+
"import": "./esm/bip39/wordlists/traditional-chinese.js",
162+
"default": "./bip39/wordlists/traditional-chinese.js"
163+
}
31164
},
32165
"browser": {
33166
"crypto": false
@@ -36,7 +169,7 @@
36169
"scripts": {
37170
"prepare": "npm run build",
38171
"build": "npm-run-all build:tsc",
39-
"build:tsc": "tsc --project tsconfig.prod.json",
172+
"build:tsc": "tsc --project tsconfig.prod.json && tsc --project tsconfig.prod.esm.json",
40173
"test": "npm-run-all test:node",
41174
"test:node": "mocha",
42175
"clean": "rimraf test-builds bip39 '*.js' '*.js.map' '*.d.ts' '*.d.ts.map' 'src/**/*.js'",

src/utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ export function wrapHash(hash: (msg: Uint8Array) => Uint8Array) {
5151
};
5252
}
5353

54+
declare const globalThis: Record<string, any> | undefined;
55+
5456
// TODO(v3): switch away from node crypto, remove this unnecessary variable.
5557
export const crypto: { node?: any; web?: any } = (() => {
5658
const webCrypto =

tsconfig.prod.esm.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es2020",
4+
"lib": ["es2020", "dom"],
5+
"module": "es6",
6+
"moduleResolution": "node",
7+
"strict": true,
8+
"rootDir": "src",
9+
"outDir": "esm"
10+
},
11+
"include": [
12+
"src/**/*.ts"
13+
],
14+
"exclude": []
15+
}

0 commit comments

Comments
 (0)