Skip to content

Commit

Permalink
Use Sha2 from @noble/hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
webmaster128 committed Jan 26, 2022
1 parent 218c341 commit 3c7d886
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 43 deletions.
16 changes: 0 additions & 16 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions .yarn/cache/@types-sha.js-npm-2.4.0-844623a8de-0e1bd1a98d.zip

This file was deleted.

4 changes: 1 addition & 3 deletions packages/crypto/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@
"bip39": "^3.0.2",
"bn.js": "^5.2.0",
"elliptic": "^6.5.3",
"libsodium-wrappers": "^0.7.6",
"sha.js": "^2.4.11"
"libsodium-wrappers": "^0.7.6"
},
"devDependencies": {
"@istanbuljs/nyc-config-typescript": "^1.0.1",
Expand All @@ -62,7 +61,6 @@
"@types/karma-jasmine-html-reporter": "^1",
"@types/libsodium-wrappers": "^0.7.7",
"@types/node": "^15.0.1",
"@types/sha.js": "^2.4.0",
"@typescript-eslint/eslint-plugin": "^4.28",
"@typescript-eslint/parser": "^4.28",
"buffer": "^6.0.3",
Expand Down
16 changes: 6 additions & 10 deletions packages/crypto/src/sha.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { Hash } from "crypto";
import shajs from "sha.js";
import { sha256 as nobleSha256 } from "@noble/hashes/sha256";
import { sha512 as nobleSha512 } from "@noble/hashes/sha512";

import { HashFunction } from "./hash";

export class Sha256 implements HashFunction {
public readonly blockSize = 512 / 8;

private readonly impl: Hash;
private readonly impl = nobleSha256.create();

public constructor(firstData?: Uint8Array) {
this.impl = shajs("sha256");

if (firstData) {
this.update(firstData);
}
Expand All @@ -22,7 +20,7 @@ export class Sha256 implements HashFunction {
}

public digest(): Uint8Array {
return new Uint8Array(this.impl.digest());
return this.impl.digest();
}
}

Expand All @@ -34,11 +32,9 @@ export function sha256(data: Uint8Array): Uint8Array {
export class Sha512 implements HashFunction {
public readonly blockSize = 1024 / 8;

private readonly impl: Hash;
private readonly impl = nobleSha512.create();

public constructor(firstData?: Uint8Array) {
this.impl = shajs("sha512");

if (firstData) {
this.update(firstData);
}
Expand All @@ -50,7 +46,7 @@ export class Sha512 implements HashFunction {
}

public digest(): Uint8Array {
return new Uint8Array(this.impl.digest());
return this.impl.digest();
}
}

Expand Down
11 changes: 0 additions & 11 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,6 @@ __metadata:
"@types/karma-jasmine-html-reporter": ^1
"@types/libsodium-wrappers": ^0.7.7
"@types/node": ^15.0.1
"@types/sha.js": ^2.4.0
"@typescript-eslint/eslint-plugin": ^4.28
"@typescript-eslint/parser": ^4.28
bip39: ^3.0.2
Expand All @@ -492,7 +491,6 @@ __metadata:
nyc: ^15.1.0
prettier: ^2.4.1
ses: ^0.11.0
sha.js: ^2.4.11
source-map-support: ^0.5.19
stream-browserify: ^3.0.0
ts-node: ^8
Expand Down Expand Up @@ -1801,15 +1799,6 @@ __metadata:
languageName: node
linkType: hard

"@types/sha.js@npm:^2.4.0":
version: 2.4.0
resolution: "@types/sha.js@npm:2.4.0"
dependencies:
"@types/node": "*"
checksum: 0e1bd1a98d88dbbf87180b8ef81ab2bf8c2bd066a99858c76299fb599fd912df807072a55a6f484077498dd972a1b55eaa03aae6ea2654027a4dd0331db7e201
languageName: node
linkType: hard

"@types/ws@npm:^6.0.1":
version: 6.0.4
resolution: "@types/ws@npm:6.0.4"
Expand Down

0 comments on commit 3c7d886

Please sign in to comment.