Skip to content

Commit ed5be68

Browse files
authored
Merge pull request #87 from ethereum/fix-imports
Rewrite imports: add .js extension, gh-86
2 parents 263279a + 7c33ac2 commit ed5be68

31 files changed

+105
-59
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
/node_modules
88
/.parcel-cache
99
/esm
10+
/test/node_modules

Diff for: package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ethereum-cryptography",
3-
"version": "2.1.0",
3+
"version": "2.1.1",
44
"description": "All the cryptographic primitives used in Ethereum",
55
"contributors": [
66
{
@@ -296,8 +296,8 @@
296296
"build": "npm-run-all build:tsc",
297297
"build:tsc": "tsc --project tsconfig.prod.json && tsc --project tsconfig.prod.esm.json",
298298
"test": "npm-run-all test:node",
299-
"test:node": "mocha",
300-
"clean": "rimraf test-builds bip39 '*.js' '*.js.map' '*.d.ts' '*.d.ts.map' 'src/**/*.js'",
299+
"test:node": "cd test && npm install && cd .. && mocha",
300+
"clean": "rimraf test/test-builds bip39 '*.js' '*.js.map' '*.d.ts' '*.d.ts.map' 'src/**/*.js'",
301301
"lint": "eslint",
302302
"lint:fix": "eslint --fix",
303303
"browser-tests": "npm-run-all browser-tests:build browser-tests:test",
@@ -361,4 +361,4 @@
361361
"context": "browser"
362362
}
363363
}
364-
}
364+
}

Diff for: scripts/build-browser-tests.sh

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
set -e
22

3+
cd ./test/
4+
echo "Install package to tests"
5+
# Cleanup old module build
6+
rm -rf ./node_modules
7+
npm install
8+
39
echo "Building tests with TypeScript"
4-
npx tsc --project tsconfig.json
10+
npx tsc --project ./tsconfig.json
511

612
echo "Building tests with Parcel"
7-
npx parcel build --no-cache --no-optimize test-builds/tsc/test/test-vectors/*.js --dist-dir test-builds/parcel --target parcel_tests
13+
npx parcel build --no-cache --no-optimize ./test-builds/tsc/test/test-vectors/*.js --dist-dir ./test-builds/parcel --target parcel_tests
814

915
echo "Building tests with Browserify"
10-
npx browserify test-builds/tsc/test/test-vectors/*.js > test-builds/browserify-build.js
16+
npx browserify ./test-builds/tsc/test/test-vectors/*.js > ./test-builds/browserify-build.js
1117

1218
echo "Building tests with webpack"
1319
npx webpack --mode development ./test-builds/tsc/test/test-vectors/*.js --output-path ./test-builds
1420

1521
echo "Building tests with Rollup"
16-
rollup -c test/rollup.config.js
22+
rollup -c ./rollup.config.js

Diff for: src/aes.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { crypto as cr } from "@noble/hashes/crypto";
2-
import { concatBytes, equalsBytes } from "./utils";
2+
import { concatBytes, equalsBytes } from "./utils.js";
33

44
const crypto: any = { web: cr };
55

Diff for: src/blake2b.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { blake2b as _blake2b } from "@noble/hashes/blake2b";
2-
import { assertBytes } from "./utils";
2+
import { assertBytes } from "./utils.js";
33

44
export const blake2b = (msg: Uint8Array, outputLength = 64): Uint8Array => {
55
assertBytes(msg);

Diff for: src/keccak.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
keccak_512
77
} from "@noble/hashes/sha3";
88
import { Hash } from "@noble/hashes/utils";
9-
import { wrapHash } from "./utils";
9+
import { wrapHash } from "./utils.js";
1010

1111
// Expose create only for keccak256
1212
interface K256 {

Diff for: src/pbkdf2.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
} from "@noble/hashes/pbkdf2";
55
import { sha256 } from "@noble/hashes/sha256";
66
import { sha512 } from "@noble/hashes/sha512";
7-
import { assertBytes } from "./utils";
7+
import { assertBytes } from "./utils.js";
88

99
export async function pbkdf2(
1010
password: Uint8Array,

Diff for: src/ripemd160.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import { ripemd160 as _ripemd160 } from "@noble/hashes/ripemd160";
2-
import { wrapHash } from "./utils";
2+
import { wrapHash } from "./utils.js";
33

44
export const ripemd160 = wrapHash(_ripemd160);

Diff for: src/scrypt.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { scrypt as _sync, scryptAsync as _async } from "@noble/hashes/scrypt";
2-
import { assertBytes } from "./utils";
2+
import { assertBytes } from "./utils.js";
33

44
type OnProgressCallback = (progress: number) => void;
55

Diff for: src/secp256k1-compat.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { sha256 } from "@noble/hashes/sha256";
22
import { mod } from "@noble/curves/abstract/modular";
3-
import { secp256k1 } from "./secp256k1";
4-
import { assertBool, assertBytes, hexToBytes, toHex } from "./utils";
3+
import { secp256k1 } from "./secp256k1.js";
4+
import { assertBool, assertBytes, hexToBytes, toHex } from "./utils.js";
55

66
// Use `secp256k1` module directly.
77
// This is a legacy compatibility layer for the npm package `secp256k1` via noble-secp256k1

Diff for: src/sha256.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import { sha256 as _sha256 } from "@noble/hashes/sha256";
2-
import { wrapHash } from "./utils";
2+
import { wrapHash } from "./utils.js";
33

44
export const sha256 = wrapHash(_sha256);

Diff for: src/sha512.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import { sha512 as _sha512 } from "@noble/hashes/sha512";
2-
import { wrapHash } from "./utils";
2+
import { wrapHash } from "./utils.js";
33

44
export const sha512 = wrapHash(_sha512);

Diff for: src/utils.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// buf.toString('hex') -> toHex(buf)
21
import assert from "@noble/hashes/_assert";
32
import { hexToBytes as _hexToBytes } from "@noble/hashes/utils";
43
const assertBool = assert.bool;
@@ -12,6 +11,8 @@ export {
1211
utf8ToBytes
1312
} from "@noble/hashes/utils";
1413

14+
// buf.toString('hex') -> toHex(buf)
15+
1516
// Global symbols in both browsers and Node.js since v11
1617
// See https://github.com/microsoft/TypeScript/issues/31535
1718
declare const TextEncoder: any;

Diff for: test/karma.browserify.conf.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
module.exports = function(config) {
1+
module.exports = function (config) {
22
config.set({
33
frameworks: ["mocha"],
4-
files: ["../test-builds/browserify-build.js"],
4+
files: ["./test-builds/browserify-build.js"],
55
colors: true,
66
logLevel: config.LOG_INFO,
77
browsers: ["ChromeHeadless"],
@@ -12,7 +12,7 @@ module.exports = function(config) {
1212
concurrency: Infinity,
1313
reporters: ["mocha"],
1414
client: {
15-
captureConsole: true
16-
}
15+
captureConsole: true,
16+
},
1717
});
1818
};

Diff for: test/karma.parcel.conf.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
module.exports = function(config) {
1+
module.exports = function (config) {
22
config.set({
33
frameworks: ["mocha"],
4-
files: ["../test-builds/parcel/*.js"],
4+
files: ["./test-builds/parcel/*.js"],
55
colors: true,
66
logLevel: config.LOG_INFO,
77
browsers: ["ChromeHeadless"],
@@ -12,7 +12,7 @@ module.exports = function(config) {
1212
concurrency: Infinity,
1313
reporters: ["mocha"],
1414
client: {
15-
captureConsole: true
16-
}
15+
captureConsole: true,
16+
},
1717
});
1818
};

Diff for: test/karma.rollup.conf.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
module.exports = function(config) {
1+
module.exports = function (config) {
22
config.set({
33
frameworks: ["mocha"],
4-
files: ["../test-builds/rollup/*.js"],
4+
files: ["./test-builds/rollup/*.js"],
55
colors: true,
66
logLevel: config.LOG_INFO,
77
browsers: ["ChromeHeadless"],
@@ -12,7 +12,7 @@ module.exports = function(config) {
1212
concurrency: Infinity,
1313
reporters: ["mocha"],
1414
client: {
15-
captureConsole: true
16-
}
15+
captureConsole: true,
16+
},
1717
});
1818
};

Diff for: test/karma.webpack.conf.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
module.exports = function(config) {
1+
module.exports = function (config) {
22
config.set({
33
frameworks: ["mocha"],
4-
files: ["../test-builds/main.js"],
4+
files: ["./test-builds/main.js"],
55
colors: true,
66
logLevel: config.LOG_INFO,
77
browsers: ["ChromeHeadless"],
@@ -12,7 +12,7 @@ module.exports = function(config) {
1212
concurrency: Infinity,
1313
reporters: ["mocha"],
1414
client: {
15-
captureConsole: true
16-
}
15+
captureConsole: true,
16+
},
1717
});
1818
};

Diff for: test/package.json

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "test",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "karma.browserify.conf.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"keywords": [],
10+
"author": "",
11+
"license": "ISC",
12+
"dependencies": {
13+
"ethereum-cryptography": "file:..",
14+
"@types/mocha": "9.1.1"
15+
},
16+
"targets": {
17+
"parcel_tests": {
18+
"context": "browser"
19+
}
20+
}
21+
}

Diff for: test/test-vectors/aes.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { decrypt, encrypt } from "../../src/aes";
2-
import { hexToBytes, toHex } from "../../src/utils";
1+
import { decrypt, encrypt } from "ethereum-cryptography/aes";
2+
import { hexToBytes, toHex } from "ethereum-cryptography/utils";
33
import { deepStrictEqual, rejects } from "./assert";
44
// Test vectors taken from https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38a.pdf
55
const TEST_VECTORS = [

Diff for: test/test-vectors/blake2b.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { blake2b } from "../../src/blake2b";
2-
import { hexToBytes, toHex } from "../../src/utils";
1+
import { blake2b } from "ethereum-cryptography/blake2b";
2+
import { hexToBytes, toHex } from "ethereum-cryptography/utils";
33
import { deepStrictEqual, throws } from "./assert";
44
// Vectors extracted from https://github.com/emilbayes/blake2b/blob/f0a7c7b550133eca5f5fc3b751ccfd2335ce736f/test-vectors.json
55
const TEST_VECTORS = [

Diff for: test/test-vectors/hdkey.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { secp256k1 as secp } from "@noble/curves/secp256k1";
2-
import { HARDENED_OFFSET, HDKey } from "../../src/hdkey";
3-
import { hexToBytes, toHex } from "../../src/utils";
2+
import { HARDENED_OFFSET, HDKey } from "ethereum-cryptography/hdkey";
3+
import { hexToBytes, toHex } from "ethereum-cryptography/utils";
44
import { deepStrictEqual, throws } from "./assert";
55
// https://github.com/cryptocoinjs/hdkey/blob/42637e381bdef0c8f785b14f5b66a80dad969514/test/fixtures/hdkey.json
66
const fixtures = [

Diff for: test/test-vectors/keccak.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { keccak224, keccak256, keccak384, keccak512 } from "../../src/keccak";
2-
import { hexToBytes, toHex, utf8ToBytes } from "../../src/utils";
1+
import { keccak224, keccak256, keccak384, keccak512 } from "ethereum-cryptography/keccak";
2+
import { hexToBytes, toHex, utf8ToBytes } from "ethereum-cryptography/utils";
33
import { deepStrictEqual } from "./assert";
44

55
export const keccak224Vectors = [

Diff for: test/test-vectors/pbkdf2.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { pbkdf2 as pbkdf2Async, pbkdf2Sync } from "../../src/pbkdf2";
2-
import { toHex, utf8ToBytes } from "../../src/utils";
1+
import { pbkdf2 as pbkdf2Async, pbkdf2Sync } from "ethereum-cryptography/pbkdf2";
2+
import { toHex, utf8ToBytes } from "ethereum-cryptography/utils";
33
import { deepStrictEqual } from "./assert";
44

55
const TEST_VECTORS = [

Diff for: test/test-vectors/random.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { getRandomBytes, getRandomBytesSync } from "../../src/random";
2-
import { equalsBytes } from "../../src/utils";
1+
import { getRandomBytes, getRandomBytesSync } from "ethereum-cryptography/random";
2+
import { equalsBytes } from "ethereum-cryptography/utils";
33
import { deepStrictEqual } from "./assert";
44

55
describe("Random number generation", () => {

Diff for: test/test-vectors/ripemd160.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { ripemd160 } from "../../src/ripemd160";
2-
import { toHex, utf8ToBytes } from "../../src/utils";
1+
import { ripemd160 } from "ethereum-cryptography/ripemd160";
2+
import { toHex, utf8ToBytes } from "ethereum-cryptography/utils";
33
import { deepStrictEqual } from "./assert";
44

55
const TEST_VECTORS = [

Diff for: test/test-vectors/scrypt.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { scrypt as scryptAsync, scryptSync } from "../../src/scrypt";
2-
import { hexToBytes, toHex } from "../../src/utils";
1+
import { scrypt as scryptAsync, scryptSync } from "ethereum-cryptography/scrypt";
2+
import { hexToBytes, toHex } from "ethereum-cryptography/utils";
33
import { deepStrictEqual } from "./assert";
44

55
const TEST_VECTORS = [

Diff for: test/test-vectors/secp256k1-compat.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import * as secp from "../../src/secp256k1-compat";
2-
import { sha256 } from "../../src/sha256";
3-
import { concatBytes, hexToBytes, toHex } from "../../src/utils";
1+
import * as secp from "ethereum-cryptography/secp256k1-compat";
2+
import { sha256 } from "ethereum-cryptography/sha256";
3+
import { concatBytes, hexToBytes, toHex } from "ethereum-cryptography/utils";
44
import { deepStrictEqual, throws } from "./assert";
55
import { VECTORS } from "./secp256k1_lib_vectors";
66

Diff for: test/test-vectors/secp256k1.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { secp256k1 } from "../../src/secp256k1";
1+
import { secp256k1 } from "ethereum-cryptography/secp256k1";
22
import { deepStrictEqual } from "./assert";
33

44
describe("secp256k1", () => {

Diff for: test/test-vectors/sha256.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { sha256 } from "../../src/sha256";
2-
import { toHex, utf8ToBytes } from "../../src/utils";
1+
import { sha256 } from "ethereum-cryptography/sha256";
2+
import { toHex, utf8ToBytes } from "ethereum-cryptography/utils";
33
import { deepStrictEqual } from "./assert";
44

55
const TEST_VECTORS = [

Diff for: test/test-vectors/sha512.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { sha512 } from "../../src/sha512";
2-
import { toHex, utf8ToBytes } from "../../src/utils";
1+
import { sha512 } from "ethereum-cryptography/sha512";
2+
import { toHex, utf8ToBytes } from "ethereum-cryptography/utils";
33
import { deepStrictEqual } from "./assert";
44

55
const TEST_VECTORS = [

Diff for: test/tsconfig.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es2020",
4+
"module": "commonjs",
5+
"strict": true,
6+
"downlevelIteration": true,
7+
"rootDirs": [
8+
"./"
9+
],
10+
"outDir": "./test-builds/tsc",
11+
"noUnusedLocals": true,
12+
"declaration": true
13+
},
14+
"include": [
15+
"./**/*.ts",
16+
]
17+
}

0 commit comments

Comments
 (0)