Skip to content

Commit

Permalink
Rewrite imports: add .js extension, gh-86
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmillr committed Jul 11, 2023
1 parent 263279a commit aadd3f4
Show file tree
Hide file tree
Showing 25 changed files with 53 additions and 36 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
/node_modules
/.parcel-cache
/esm
/test/node_modules
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ethereum-cryptography",
"version": "2.1.0",
"version": "2.1.1",
"description": "All the cryptographic primitives used in Ethereum",
"contributors": [
{
Expand Down
2 changes: 1 addition & 1 deletion src/aes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { crypto as cr } from "@noble/hashes/crypto";
import { concatBytes, equalsBytes } from "./utils";
import { concatBytes, equalsBytes } from "./utils.js";

const crypto: any = { web: cr };

Expand Down
2 changes: 1 addition & 1 deletion src/blake2b.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { blake2b as _blake2b } from "@noble/hashes/blake2b";
import { assertBytes } from "./utils";
import { assertBytes } from "./utils.js";

export const blake2b = (msg: Uint8Array, outputLength = 64): Uint8Array => {
assertBytes(msg);
Expand Down
2 changes: 1 addition & 1 deletion src/keccak.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
keccak_512
} from "@noble/hashes/sha3";
import { Hash } from "@noble/hashes/utils";
import { wrapHash } from "./utils";
import { wrapHash } from "./utils.js";

// Expose create only for keccak256
interface K256 {
Expand Down
2 changes: 1 addition & 1 deletion src/pbkdf2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
} from "@noble/hashes/pbkdf2";
import { sha256 } from "@noble/hashes/sha256";
import { sha512 } from "@noble/hashes/sha512";
import { assertBytes } from "./utils";
import { assertBytes } from "./utils.js";

export async function pbkdf2(
password: Uint8Array,
Expand Down
2 changes: 1 addition & 1 deletion src/ripemd160.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ripemd160 as _ripemd160 } from "@noble/hashes/ripemd160";
import { wrapHash } from "./utils";
import { wrapHash } from "./utils.js";

export const ripemd160 = wrapHash(_ripemd160);
2 changes: 1 addition & 1 deletion src/scrypt.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { scrypt as _sync, scryptAsync as _async } from "@noble/hashes/scrypt";
import { assertBytes } from "./utils";
import { assertBytes } from "./utils.js";

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

Expand Down
4 changes: 2 additions & 2 deletions src/secp256k1-compat.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { sha256 } from "@noble/hashes/sha256";
import { mod } from "@noble/curves/abstract/modular";
import { secp256k1 } from "./secp256k1";
import { assertBool, assertBytes, hexToBytes, toHex } from "./utils";
import { secp256k1 } from "./secp256k1.js";
import { assertBool, assertBytes, hexToBytes, toHex } from "./utils.js";

// Use `secp256k1` module directly.
// This is a legacy compatibility layer for the npm package `secp256k1` via noble-secp256k1
Expand Down
2 changes: 1 addition & 1 deletion src/sha256.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { sha256 as _sha256 } from "@noble/hashes/sha256";
import { wrapHash } from "./utils";
import { wrapHash } from "./utils.js";

export const sha256 = wrapHash(_sha256);
2 changes: 1 addition & 1 deletion src/sha512.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { sha512 as _sha512 } from "@noble/hashes/sha512";
import { wrapHash } from "./utils";
import { wrapHash } from "./utils.js";

export const sha512 = wrapHash(_sha512);
3 changes: 2 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// buf.toString('hex') -> toHex(buf)
import assert from "@noble/hashes/_assert";
import { hexToBytes as _hexToBytes } from "@noble/hashes/utils";
const assertBool = assert.bool;
Expand All @@ -12,6 +11,8 @@ export {
utf8ToBytes
} from "@noble/hashes/utils";

// buf.toString('hex') -> toHex(buf)

// Global symbols in both browsers and Node.js since v11
// See https://github.com/microsoft/TypeScript/issues/31535
declare const TextEncoder: any;
Expand Down
15 changes: 15 additions & 0 deletions test/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "karma.browserify.conf.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"ethereum-cryptography": "file:.."
}
}
4 changes: 2 additions & 2 deletions test/test-vectors/aes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { decrypt, encrypt } from "../../src/aes";
import { hexToBytes, toHex } from "../../src/utils";
import { decrypt, encrypt } from "ethereum-cryptography/aes";
import { hexToBytes, toHex } from "ethereum-cryptography/utils";
import { deepStrictEqual, rejects } from "./assert";
// Test vectors taken from https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38a.pdf
const TEST_VECTORS = [
Expand Down
4 changes: 2 additions & 2 deletions test/test-vectors/blake2b.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { blake2b } from "../../src/blake2b";
import { hexToBytes, toHex } from "../../src/utils";
import { blake2b } from "ethereum-cryptography/blake2b";
import { hexToBytes, toHex } from "ethereum-cryptography/utils";
import { deepStrictEqual, throws } from "./assert";
// Vectors extracted from https://github.com/emilbayes/blake2b/blob/f0a7c7b550133eca5f5fc3b751ccfd2335ce736f/test-vectors.json
const TEST_VECTORS = [
Expand Down
4 changes: 2 additions & 2 deletions test/test-vectors/hdkey.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { secp256k1 as secp } from "@noble/curves/secp256k1";
import { HARDENED_OFFSET, HDKey } from "../../src/hdkey";
import { hexToBytes, toHex } from "../../src/utils";
import { HARDENED_OFFSET, HDKey } from "ethereum-cryptography/hdkey";
import { hexToBytes, toHex } from "ethereum-cryptography/utils";
import { deepStrictEqual, throws } from "./assert";
// https://github.com/cryptocoinjs/hdkey/blob/42637e381bdef0c8f785b14f5b66a80dad969514/test/fixtures/hdkey.json
const fixtures = [
Expand Down
4 changes: 2 additions & 2 deletions test/test-vectors/keccak.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { keccak224, keccak256, keccak384, keccak512 } from "../../src/keccak";
import { hexToBytes, toHex, utf8ToBytes } from "../../src/utils";
import { keccak224, keccak256, keccak384, keccak512 } from "ethereum-cryptography/keccak";
import { hexToBytes, toHex, utf8ToBytes } from "ethereum-cryptography/utils";
import { deepStrictEqual } from "./assert";

export const keccak224Vectors = [
Expand Down
4 changes: 2 additions & 2 deletions test/test-vectors/pbkdf2.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { pbkdf2 as pbkdf2Async, pbkdf2Sync } from "../../src/pbkdf2";
import { toHex, utf8ToBytes } from "../../src/utils";
import { pbkdf2 as pbkdf2Async, pbkdf2Sync } from "ethereum-cryptography/pbkdf2";
import { toHex, utf8ToBytes } from "ethereum-cryptography/utils";
import { deepStrictEqual } from "./assert";

const TEST_VECTORS = [
Expand Down
4 changes: 2 additions & 2 deletions test/test-vectors/random.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getRandomBytes, getRandomBytesSync } from "../../src/random";
import { equalsBytes } from "../../src/utils";
import { getRandomBytes, getRandomBytesSync } from "ethereum-cryptography/random";
import { equalsBytes } from "ethereum-cryptography/utils";
import { deepStrictEqual } from "./assert";

describe("Random number generation", () => {
Expand Down
4 changes: 2 additions & 2 deletions test/test-vectors/ripemd160.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ripemd160 } from "../../src/ripemd160";
import { toHex, utf8ToBytes } from "../../src/utils";
import { ripemd160 } from "ethereum-cryptography/ripemd160";
import { toHex, utf8ToBytes } from "ethereum-cryptography/utils";
import { deepStrictEqual } from "./assert";

const TEST_VECTORS = [
Expand Down
4 changes: 2 additions & 2 deletions test/test-vectors/scrypt.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { scrypt as scryptAsync, scryptSync } from "../../src/scrypt";
import { hexToBytes, toHex } from "../../src/utils";
import { scrypt as scryptAsync, scryptSync } from "ethereum-cryptography/scrypt";
import { hexToBytes, toHex } from "ethereum-cryptography/utils";
import { deepStrictEqual } from "./assert";

const TEST_VECTORS = [
Expand Down
6 changes: 3 additions & 3 deletions test/test-vectors/secp256k1-compat.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as secp from "../../src/secp256k1-compat";
import { sha256 } from "../../src/sha256";
import { concatBytes, hexToBytes, toHex } from "../../src/utils";
import * as secp from "ethereum-cryptography/secp256k1-compat";
import { sha256 } from "ethereum-cryptography/sha256";
import { concatBytes, hexToBytes, toHex } from "ethereum-cryptography/utils";
import { deepStrictEqual, throws } from "./assert";
import { VECTORS } from "./secp256k1_lib_vectors";

Expand Down
2 changes: 1 addition & 1 deletion test/test-vectors/secp256k1.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { secp256k1 } from "../../src/secp256k1";
import { secp256k1 } from "ethereum-cryptography/secp256k1";
import { deepStrictEqual } from "./assert";

describe("secp256k1", () => {
Expand Down
4 changes: 2 additions & 2 deletions test/test-vectors/sha256.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { sha256 } from "../../src/sha256";
import { toHex, utf8ToBytes } from "../../src/utils";
import { sha256 } from "ethereum-cryptography/sha256";
import { toHex, utf8ToBytes } from "ethereum-cryptography/utils";
import { deepStrictEqual } from "./assert";

const TEST_VECTORS = [
Expand Down
4 changes: 2 additions & 2 deletions test/test-vectors/sha512.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { sha512 } from "../../src/sha512";
import { toHex, utf8ToBytes } from "../../src/utils";
import { sha512 } from "ethereum-cryptography/sha512";
import { toHex, utf8ToBytes } from "ethereum-cryptography/utils";
import { deepStrictEqual } from "./assert";

const TEST_VECTORS = [
Expand Down

0 comments on commit aadd3f4

Please sign in to comment.