From 9b9ca91037d81e1d40c930d82c9dd785d998952b Mon Sep 17 00:00:00 2001 From: Darius Rainys Date: Wed, 6 Oct 2021 23:53:23 +0300 Subject: [PATCH] fix: crypto replaced by crypto-js --- package-lock.json | 8 ++++---- package.json | 2 +- src/serialize.ts | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0debe352ea..87f5cfd241 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1367,10 +1367,10 @@ "which": "^2.0.1" } }, - "crypto": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/crypto/-/crypto-1.0.1.tgz", - "integrity": "sha512-VxBKmeNcqQdiUQUW2Tzq0t377b54N2bMtXO/qiLa+6eRRmmC4qT3D4OnTGoT/U6O9aklQ/jTwbOtRMTTY8G0Ig==" + "crypto-js": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-4.1.1.tgz", + "integrity": "sha512-o2JlM7ydqd3Qk9CA0L4NL6mTzU2sdx96a+oOfPu8Mkl/PK51vSyoi8/rQ8NknZtk44vq15lmhAj9CIAGwgeWKw==" }, "cssom": { "version": "0.4.4", diff --git a/package.json b/package.json index 7836a686db..e964765314 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "dependencies": { "agentkeepalive": "^4.1.0", "axios": "^0.21.1", - "crypto": "^1.0.1", + "crypto-js": "4.1.1", "query-string": "^7.0.1", "retry-axios": "^2.2.1" }, diff --git a/src/serialize.ts b/src/serialize.ts index a2f7154914..714582e6a0 100644 --- a/src/serialize.ts +++ b/src/serialize.ts @@ -17,7 +17,7 @@ import { LatLng, LatLngBounds, LatLngLiteral } from "./common"; import { encodePath } from "./util"; -import { createHmac } from "crypto"; +import * as CryptoJS from "crypto-js"; import { stringify as qs } from "query-string"; import { URL } from "url"; @@ -161,9 +161,9 @@ export function createPremiumPlanSignature(unsignedUrl: string, clientSecret: st // Convert from 'web safe' base64 to true base64 const unsafeClientSecret = clientSecret.replace(/-/g, "+").replace(/_/g, "/"); // Base64 decode the secret - const decodedSecret = Buffer.from(unsafeClientSecret, "base64"); + const decodedSecret = CryptoJS.enc.Base64.parse(unsafeClientSecret) // Sign the url with the decoded secret - const unsafeSignature = createHmac("sha1", decodedSecret).update(pathAndQuery).digest("base64"); + const unsafeSignature = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA1, decodedSecret).update(pathAndQuery).finalize().toString(CryptoJS.enc.Base64) // Convert from true base64 to 'web safe' base64 return unsafeSignature.replace(/\+/g, "-").replace(/\//g, "_"); }