Skip to content

Commit

Permalink
fix: crypto replaced by crypto-js (#676)
Browse files Browse the repository at this point in the history
  • Loading branch information
Smile4192 committed Oct 7, 2021
1 parent 2ef4915 commit 4ce1069
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
6 changes: 3 additions & 3 deletions src/serialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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, "_");
}

0 comments on commit 4ce1069

Please sign in to comment.