From 4a6253f16bf1c7bb1a0bbd68d331ab712165306f Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Mon, 6 Dec 2021 11:15:36 +0100 Subject: [PATCH] Replace ripemd160 dependencies with @noble/hashes --- .pnp.cjs | 30 +++++++++---------- ...hashes-npm-1.0.0-893cbd74b3-bdf1c28a4b.zip | 3 ++ ...emd160-npm-2.0.0-0e635eba3e-eb0eb2d380.zip | 3 -- packages/crypto/package.json | 3 +- packages/crypto/src/ripemd.ts | 8 ++--- yarn.lock | 19 +++++------- 6 files changed, 30 insertions(+), 36 deletions(-) create mode 100644 .yarn/cache/@noble-hashes-npm-1.0.0-893cbd74b3-bdf1c28a4b.zip delete mode 100644 .yarn/cache/@types-ripemd160-npm-2.0.0-0e635eba3e-eb0eb2d380.zip diff --git a/.pnp.cjs b/.pnp.cjs index a6ff4091..02242451 100755 --- a/.pnp.cjs +++ b/.pnp.cjs @@ -342,6 +342,10 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) { "@ledgerhq/logs", "npm:5.50.0" ], + [ + "@noble/hashes", + "npm:1.0.0" + ], [ "@nodelib/fs.scandir", "npm:2.1.4" @@ -582,10 +586,6 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) { "@types/range-parser", "npm:1.2.3" ], - [ - "@types/ripemd160", - "npm:2.0.0" - ], [ "@types/semver", "npm:7.3.6" @@ -3372,6 +3372,7 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) { ["@cosmjs/math", "workspace:packages/math"], ["@cosmjs/utils", "workspace:packages/utils"], ["@istanbuljs/nyc-config-typescript", "virtual:4f1584ad4aba8733a24be7c8aebbffafef25607f2d00f4b314cf96717145c692763628a31c2b85d4686fbb091ff21ebffa3cc337399c042c19a32b9bdb786464#npm:1.0.1"], + ["@noble/hashes", "npm:1.0.0"], ["@types/bn.js", "npm:5.1.0"], ["@types/elliptic", "npm:6.4.12"], ["@types/eslint-plugin-prettier", "npm:3.1.0"], @@ -3381,7 +3382,6 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) { ["@types/karma-jasmine-html-reporter", "npm:1.5.1"], ["@types/libsodium-wrappers", "npm:0.7.9"], ["@types/node", "npm:15.3.1"], - ["@types/ripemd160", "npm:2.0.0"], ["@types/sha.js", "npm:2.4.0"], ["@typescript-eslint/eslint-plugin", "virtual:4f1584ad4aba8733a24be7c8aebbffafef25607f2d00f4b314cf96717145c692763628a31c2b85d4686fbb091ff21ebffa3cc337399c042c19a32b9bdb786464#npm:4.28.4"], ["@typescript-eslint/parser", "virtual:4f1584ad4aba8733a24be7c8aebbffafef25607f2d00f4b314cf96717145c692763628a31c2b85d4686fbb091ff21ebffa3cc337399c042c19a32b9bdb786464#npm:4.28.4"], @@ -3409,7 +3409,6 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) { ["libsodium-wrappers", "npm:0.7.9"], ["nyc", "npm:15.1.0"], ["prettier", "npm:2.4.1"], - ["ripemd160", "npm:2.0.2"], ["ses", "npm:0.11.1"], ["sha.js", "npm:2.4.11"], ["source-map-support", "npm:0.5.19"], @@ -4224,6 +4223,15 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) { "linkType": "HARD", }] ]], + ["@noble/hashes", [ + ["npm:1.0.0", { + "packageLocation": "./.yarn/cache/@noble-hashes-npm-1.0.0-893cbd74b3-bdf1c28a4b.zip/node_modules/@noble/hashes/", + "packageDependencies": [ + ["@noble/hashes", "npm:1.0.0"] + ], + "linkType": "HARD", + }] + ]], ["@nodelib/fs.scandir", [ ["npm:2.1.4", { "packageLocation": "./.yarn/cache/@nodelib-fs.scandir-npm-2.1.4-6f6ddb2372-18c2150ab5.zip/node_modules/@nodelib/fs.scandir/", @@ -4847,16 +4855,6 @@ function $$SETUP_STATE(hydrateRuntimeState, basePath) { "linkType": "HARD", }] ]], - ["@types/ripemd160", [ - ["npm:2.0.0", { - "packageLocation": "./.yarn/cache/@types-ripemd160-npm-2.0.0-0e635eba3e-eb0eb2d380.zip/node_modules/@types/ripemd160/", - "packageDependencies": [ - ["@types/ripemd160", "npm:2.0.0"], - ["@types/node", "npm:15.3.1"] - ], - "linkType": "HARD", - }] - ]], ["@types/semver", [ ["npm:7.3.6", { "packageLocation": "./.yarn/cache/@types-semver-npm-7.3.6-4add0df8f9-933b115a59.zip/node_modules/@types/semver/", diff --git a/.yarn/cache/@noble-hashes-npm-1.0.0-893cbd74b3-bdf1c28a4b.zip b/.yarn/cache/@noble-hashes-npm-1.0.0-893cbd74b3-bdf1c28a4b.zip new file mode 100644 index 00000000..f19012b4 --- /dev/null +++ b/.yarn/cache/@noble-hashes-npm-1.0.0-893cbd74b3-bdf1c28a4b.zip @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:94104e20e08120f2dbf76552bc7b3d05bca55416c304990baeb335e3c9dfea81 +size 97291 diff --git a/.yarn/cache/@types-ripemd160-npm-2.0.0-0e635eba3e-eb0eb2d380.zip b/.yarn/cache/@types-ripemd160-npm-2.0.0-0e635eba3e-eb0eb2d380.zip deleted file mode 100644 index 8404bdd6..00000000 --- a/.yarn/cache/@types-ripemd160-npm-2.0.0-0e635eba3e-eb0eb2d380.zip +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:48fa2838edad2eae418762a057ea6c816e1f82a9976c1c93447d2fbe827a2dc3 -size 2531 diff --git a/packages/crypto/package.json b/packages/crypto/package.json index 72aee309..81aa7ddd 100644 --- a/packages/crypto/package.json +++ b/packages/crypto/package.json @@ -44,12 +44,12 @@ "@cosmjs/encoding": "workspace:packages/encoding", "@cosmjs/math": "workspace:packages/math", "@cosmjs/utils": "workspace:packages/utils", + "@noble/hashes": "^1", "bip39": "^3.0.2", "bn.js": "^5.2.0", "elliptic": "^6.5.3", "js-sha3": "^0.8.0", "libsodium-wrappers": "^0.7.6", - "ripemd160": "^2.0.2", "sha.js": "^2.4.11" }, "devDependencies": { @@ -63,7 +63,6 @@ "@types/karma-jasmine-html-reporter": "^1", "@types/libsodium-wrappers": "^0.7.7", "@types/node": "^15.0.1", - "@types/ripemd160": "^2.0.0", "@types/sha.js": "^2.4.0", "@typescript-eslint/eslint-plugin": "^4.28", "@typescript-eslint/parser": "^4.28", diff --git a/packages/crypto/src/ripemd.ts b/packages/crypto/src/ripemd.ts index 258a43e0..263e573c 100644 --- a/packages/crypto/src/ripemd.ts +++ b/packages/crypto/src/ripemd.ts @@ -1,11 +1,11 @@ -import RIPEMD160 from "ripemd160"; +import { ripemd160 as nobleRipemd160 } from "@noble/hashes/ripemd160"; import { HashFunction } from "./hash"; export class Ripemd160 implements HashFunction { public readonly blockSize = 512 / 8; - private readonly impl = new RIPEMD160(); + private readonly impl = nobleRipemd160.create(); public constructor(firstData?: Uint8Array) { if (firstData) { @@ -14,12 +14,12 @@ export class Ripemd160 implements HashFunction { } public update(data: Uint8Array): Ripemd160 { - this.impl.update(Buffer.from(data)); + this.impl.update(data); return this; } public digest(): Uint8Array { - return Uint8Array.from(this.impl.digest()); + return this.impl.digest(); } } diff --git a/yarn.lock b/yarn.lock index 38ffcfda..6e9dbf0e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -455,6 +455,7 @@ __metadata: "@cosmjs/math": "workspace:packages/math" "@cosmjs/utils": "workspace:packages/utils" "@istanbuljs/nyc-config-typescript": ^1.0.1 + "@noble/hashes": ^1 "@types/bn.js": ^5 "@types/elliptic": ^6.4.12 "@types/eslint-plugin-prettier": ^3 @@ -464,7 +465,6 @@ __metadata: "@types/karma-jasmine-html-reporter": ^1 "@types/libsodium-wrappers": ^0.7.7 "@types/node": ^15.0.1 - "@types/ripemd160": ^2.0.0 "@types/sha.js": ^2.4.0 "@typescript-eslint/eslint-plugin": ^4.28 "@typescript-eslint/parser": ^4.28 @@ -492,7 +492,6 @@ __metadata: libsodium-wrappers: ^0.7.6 nyc: ^15.1.0 prettier: ^2.4.1 - ripemd160: ^2.0.2 ses: ^0.11.0 sha.js: ^2.4.11 source-map-support: ^0.5.19 @@ -1248,6 +1247,13 @@ __metadata: languageName: node linkType: hard +"@noble/hashes@npm:^1": + version: 1.0.0 + resolution: "@noble/hashes@npm:1.0.0" + checksum: bdf1c28a4b587e72ec6b0c504903239c6f96680b2c15a6d90d367512f468eeca12f2ee7bd25967a9529be2bedbf3f8d0a50c33368937f8dfef2a973d0661c7b5 + languageName: node + linkType: hard + "@nodelib/fs.scandir@npm:2.1.4": version: 2.1.4 resolution: "@nodelib/fs.scandir@npm:2.1.4" @@ -1779,15 +1785,6 @@ __metadata: languageName: node linkType: hard -"@types/ripemd160@npm:^2.0.0": - version: 2.0.0 - resolution: "@types/ripemd160@npm:2.0.0" - dependencies: - "@types/node": "*" - checksum: eb0eb2d380734a957a1e584f22af874552fe2ce1b28bc079ea5e361dec4bfcee5285d34dc6acdbce31616ac93210343a6c92809a45e18e3b3fd7f462c65b5166 - languageName: node - linkType: hard - "@types/semver@npm:^7.3.4": version: 7.3.6 resolution: "@types/semver@npm:7.3.6"