Skip to content

Commit 05576f9

Browse files
committed
Remove every mention to -native
1 parent 240cc25 commit 05576f9

File tree

10 files changed

+51
-94
lines changed

10 files changed

+51
-94
lines changed

package.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,9 @@
4949
"pure/**/*.d.ts.map"
5050
],
5151
"browser": {
52-
"./ripemd160.js": "./pure/ripemd160.js",
53-
"./sha256.js": "./pure/sha256.js",
5452
"./hdkey.js": "./pure/hdkey.js",
55-
"./blake2b.js": "./pure/blake2b.js",
56-
"./bip39/index.js": "./pure/bip39/index.js"
53+
"./ripemd160.js": "./pure/ripemd160.js",
54+
"./sha256.js": "./pure/sha256.js"
5755
},
5856
"sideEffects": false,
5957
"scripts": {
@@ -75,7 +73,7 @@
7573
"hdkey-without-crypto:build": "bash -x scripts/build-hdkey-without-crypto.sh",
7674
"hdkey-without-crypto:copy": "mkdir -p vendor pure/vendor && cp src/vendor/hdkey-without-crypto.js ./vendor && cp src/pure/vendor/hdkey-without-crypto.js ./pure/vendor",
7775
"bip39-without-wordlists:build": "bash -x scripts/build-bip39-without-wordlists.sh",
78-
"bip39-without-wordlists:copy": "mkdir -p pure/vendor && cp src/pure/vendor/bip39-without-wordlists.js ./pure/vendor"
76+
"bip39-without-wordlists:copy": "mkdir -p vendor && cp src/vendor/bip39-without-wordlists.js ./vendor"
7977
},
8078
"devDependencies": {
8179
"@types/chai": "^4.2.1",

scripts/build-bip39-without-wordlists.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ echo "Bundling bip39 with Rollup"
44
npx rollup -c bip39-without-wordlists-config/rollup.config.js
55

66
echo "Copying output"
7-
cp bip39-without-wordlists-build/bip39-without-wordlists.js ./src/pure/vendor
7+
cp bip39-without-wordlists-build/bip39-without-wordlists.js ./src/vendor

scripts/build-browser-tests.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ cp src/pure/vendor/hdkey-without-crypto.js test-builds/tsc/src/pure/vendor
1111

1212
echo "Building bip39-without-wordlists"
1313
npm run bip39-without-wordlists:build
14-
mkdir -p test-builds/tsc/src/pure/vendor
15-
cp src/pure/vendor/bip39-without-wordlists.js test-builds/tsc/src/pure/vendor
14+
mkdir -p test-builds/tsc/src/vendor
15+
cp src/vendor/bip39-without-wordlists.js test-builds/tsc/src/vendor
1616

1717
echo "Building tests with Parcel"
1818
npx parcel build --no-cache --no-minify test-builds/tsc/src/pure/*.js test-builds/tsc/test/pure/*.js -d test-builds/parcel

src/bip39/index.ts

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,40 @@
1-
import * as bip39Pure from "../pure/bip39";
1+
const bip39 = require("../vendor/bip39-without-wordlists");
22

3-
let bip39Module: typeof bip39Pure;
3+
export function generateMnemonic(
4+
wordlist: string[],
5+
strength: number = 128
6+
): string {
7+
return bip39.generateMnemonic(strength, undefined, wordlist);
8+
}
9+
10+
export function mnemonicToEntropy(
11+
mnemonic: string,
12+
wordlist: string[]
13+
): Buffer {
14+
return bip39.mnemonicToEntropy(mnemonic, wordlist);
15+
}
16+
17+
export function entropyToMnemonic(entropy: Buffer, wordlist: string[]): string {
18+
return bip39.entropyToMnemonic(entropy, wordlist);
19+
}
20+
21+
export function validateMnemonic(
22+
mnemonic: string,
23+
wordlist: string[]
24+
): boolean {
25+
return bip39.validateMnemonic(mnemonic, wordlist);
26+
}
427

5-
try {
6-
// tslint:disable-next-line no-implicit-dependencies
7-
bip39Module = require("ethereum-cryptography-native/bip39");
8-
} catch {
9-
bip39Module = require("../pure/bip39");
28+
export async function mnemonicToSeed(
29+
mnemonic: string,
30+
passphrase: string = ""
31+
): Promise<Buffer> {
32+
return bip39.mnemonicToSeed(mnemonic, passphrase);
1033
}
1134

12-
export const generateMnemonic = bip39Module.generateMnemonic;
13-
export const mnemonicToEntropy = bip39Module.mnemonicToEntropy;
14-
export const entropyToMnemonic = bip39Module.entropyToMnemonic;
15-
export const validateMnemonic = bip39Module.validateMnemonic;
16-
export const mnemonicToSeed = bip39Module.mnemonicToSeed;
17-
export const mnemonicToSeedSync = bip39Module.mnemonicToSeedSync;
35+
export function mnemonicToSeedSync(
36+
mnemonic: string,
37+
passphrase: string = ""
38+
): Buffer {
39+
return bip39.mnemonicToSeedSync(mnemonic, passphrase);
40+
}

src/blake2b.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
import * as blake2bPure from "./pure/blake2b";
1+
const blake2bJs = require("blakejs");
22

3-
let blake2bModule: typeof blake2bPure;
3+
export function blake2b(input: Buffer, outputLength = 64): Buffer {
4+
if (outputLength <= 0 || outputLength > 64) {
5+
throw Error("Invalid outputLength");
6+
}
47

5-
try {
6-
// tslint:disable-next-line no-implicit-dependencies
7-
blake2bModule = require("ethereum-cryptography-native/blake2b");
8-
} catch {
9-
blake2bModule = require("./pure/blake2b");
8+
return Buffer.from(blake2bJs.blake2b(input, undefined, outputLength));
109
}
11-
12-
export const blake2b = blake2bModule.blake2b;

src/hdkey.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
11
import * as hdkeyPure from "./pure/hdkey";
22

3-
let hdkey: typeof hdkeyPure.HDKey;
4-
5-
try {
6-
// tslint:disable-next-line no-implicit-dependencies
7-
hdkey = require("ethereum-cryptography-native/hdkey").HDKey;
8-
} catch {
9-
// This module is slightly more complicated, as we don't want to use the
10-
// 100% pure version of hdkey if the native one isn't installed.
11-
12-
// We require this local version of hdkey-without-crypto because it uses
13-
// the built-in crypto module
14-
hdkey = require("./vendor/hdkey-without-crypto");
15-
}
3+
const hdkey: typeof hdkeyPure.HDKey = require("./vendor/hdkey-without-crypto");
164

175
export const HDKey = hdkey;

src/pure/bip39/index.ts

Lines changed: 0 additions & 40 deletions
This file was deleted.

src/pure/blake2b.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

test/pure/bip39.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import * as bip39 from "../../src/bip39";
12
import { wordlist as englishWordlist } from "../../src/bip39/wordlists/english";
23
import { wordlist as spanishWordlist } from "../../src/bip39/wordlists/spanish";
3-
import * as bip39 from "../../src/pure/bip39";
44
import { createTests } from "../test-vectors/bip39";
55

66
createTests(

test/pure/blake2b.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { blake2b } from "../../src/pure/blake2b";
1+
import { blake2b } from "../../src/blake2b";
22
import { createTests } from "../test-vectors/blake2b";
33

44
createTests(blake2b);

0 commit comments

Comments
 (0)