Skip to content

Commit 3cfa551

Browse files
committed
Replace scryptsy with scrypt-js
1 parent 9a097ac commit 3cfa551

File tree

10 files changed

+30
-107
lines changed

10 files changed

+30
-107
lines changed

packages/ethereum-cryptography/package.json

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
"pure/**/*.d.ts.map"
5050
],
5151
"browser": {
52-
"./scrypt.js": "./pure/scrypt.js",
5352
"./ripemd160.js": "./pure/ripemd160.js",
5453
"./sha256.js": "./pure/sha256.js",
5554
"./hdkey.js": "./pure/hdkey.js",
@@ -59,11 +58,11 @@
5958
"sideEffects": false,
6059
"scripts": {
6160
"prepare": "npm run build",
62-
"build": "npm-run-all build:tsc scryptsy-without-crypto:build scryptsy-without-crypto:copy hdkey-without-crypto:build hdkey-without-crypto:copy bip39-without-wordlists:build bip39-without-wordlists:copy",
61+
"build": "npm-run-all build:tsc hdkey-without-crypto:build hdkey-without-crypto:copy bip39-without-wordlists:build bip39-without-wordlists:copy",
6362
"build:tsc": "tsc --project tsconfig.prod.json",
64-
"test": "npm-run-all scryptsy-without-crypto:build hdkey-without-crypto:build bip39-without-wordlists:build test:node",
63+
"test": "npm-run-all hdkey-without-crypto:build bip39-without-wordlists:build test:node",
6564
"test:node": "mocha",
66-
"clean": "rimraf vendor test-builds pure shims scryptsy-without-crypto-build hdkey-without-crypto-build bip39-without-wordlists-build '*.js' '*.js.map' '*.d.ts' '*.d.ts.map' 'src/**/*.js'",
65+
"clean": "rimraf vendor test-builds pure shims hdkey-without-crypto-build bip39-without-wordlists-build '*.js' '*.js.map' '*.d.ts' '*.d.ts.map' 'src/**/*.js'",
6766
"lint": "tslint --project tsconfig.json",
6867
"lint:fix": "tslint --fix --project tsconfig.json",
6968
"browser-tests": "npm-run-all browser-tests:build browser-tests:test",
@@ -73,8 +72,6 @@
7372
"browser-tests:test-browserify": "karma start --single-run --browsers ChromeHeadless test/karma.browserify.conf.js",
7473
"browser-tests:test-webpack": "karma start --single-run --browsers ChromeHeadless test/karma.webpack.conf.js",
7574
"browser-tests:test-rollup": "karma start --single-run --browsers ChromeHeadless test/karma.rollup.conf.js",
76-
"scryptsy-without-crypto:build": "bash -x scripts/build-scryptsy-without-crypto.sh",
77-
"scryptsy-without-crypto:copy": "mkdir -p vendor && cp src/vendor/scryptsy-without-crypto.js ./vendor",
7875
"hdkey-without-crypto:build": "bash -x scripts/build-hdkey-without-crypto.sh",
7976
"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",
8077
"bip39-without-wordlists:build": "bash -x scripts/build-bip39-without-wordlists.sh",
@@ -115,16 +112,17 @@
115112
"dependencies": {
116113
"@types/pbkdf2": "^3.0.0",
117114
"@types/secp256k1": "^4.0.1",
115+
"blakejs": "^1.1.0",
116+
"browserify-aes": "^1.2.0",
118117
"bs58check": "^2.1.2",
119-
"safe-buffer": "^5.1.2",
120118
"create-hash": "^1.2.0",
121-
"pbkdf2": "^3.0.17",
122119
"create-hmac": "^1.1.7",
123-
"blakejs": "^1.1.0",
124-
"browserify-aes": "^1.2.0",
125120
"hash.js": "^1.1.7",
126121
"keccak": "^3.0.0",
122+
"pbkdf2": "^3.0.17",
127123
"randombytes": "^2.1.0",
124+
"safe-buffer": "^5.1.2",
125+
"scrypt-js": "^3.0.0",
128126
"secp256k1": "^4.0.1",
129127
"setimmediate": "^1.0.5"
130128
}

packages/ethereum-cryptography/scripts/build-browser-tests.sh

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@ set -e
33
echo "Building tests with TypeScript"
44
npx tsc --project tsconfig.json
55

6-
echo "Building scryptsy-without-crypto"
7-
npm run scryptsy-without-crypto:build
8-
mkdir -p test-builds/tsc/src/vendor
9-
cp src/vendor/scryptsy-without-crypto.js test-builds/tsc/src/vendor
10-
116
echo "Building hdkey-without-crypto"
127
npm run hdkey-without-crypto:build
138
mkdir -p test-builds/tsc/src/vendor test-builds/tsc/src/pure/vendor

packages/ethereum-cryptography/scripts/build-scryptsy-without-crypto.sh

Lines changed: 0 additions & 10 deletions
This file was deleted.
Submodule scryptsy deleted from 395c3b0

packages/ethereum-cryptography/scryptsy-without-crypto-config/README.md

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

packages/ethereum-cryptography/scryptsy-without-crypto-config/crypto-shim.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/ethereum-cryptography/scryptsy-without-crypto-config/rollup.config.js

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

packages/ethereum-cryptography/src/pure/scrypt.ts

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
1-
import * as scryptPure from "./pure/scrypt";
1+
import "scrypt-js/thirdparty/setImmediate";
2+
const scryptJs = require("scrypt-js");
23

3-
let scryptModule: typeof scryptPure;
4-
5-
try {
6-
// tslint:disable-next-line no-implicit-dependencies
7-
scryptModule = require("ethereum-cryptography-native/scrypt");
8-
} catch {
9-
scryptModule = scryptPure;
4+
export async function scrypt(
5+
password: Buffer,
6+
salt: Buffer,
7+
n: number,
8+
p: number,
9+
r: number,
10+
dklen: number
11+
): Promise<Buffer> {
12+
return Buffer.from(await scryptJs.scrypt(password, salt, n, r, p, dklen));
1013
}
1114

12-
export const scrypt = scryptModule.scrypt;
13-
export const scryptSync = scryptModule.scryptSync;
15+
export function scryptSync(
16+
password: Buffer,
17+
salt: Buffer,
18+
n: number,
19+
p: number,
20+
r: number,
21+
dklen: number
22+
): Buffer {
23+
return Buffer.from(scryptJs.syncScrypt(password, salt, n, r, p, dklen));
24+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { scrypt, scryptSync } from "../../src/pure/scrypt";
1+
import { scrypt, scryptSync } from "../../src/scrypt";
22
import { createTests } from "../test-vectors/scrypt";
33

44
createTests(scryptSync, scrypt);

0 commit comments

Comments
 (0)