Skip to content

Commit

Permalink
Use polyfill for WebCrypto
Browse files Browse the repository at this point in the history
  • Loading branch information
krasun committed Sep 27, 2023
1 parent a85c104 commit dc5e51f
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 5 deletions.
157 changes: 155 additions & 2 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "screenshotone-api-sdk",
"homepage": "https://screenshotone.com",
"version": "1.1.2",
"version": "1.1.3",
"description": "Use ScreenshotOne.com API to generate screenshots of any website.",
"repository": {
"type": "git",
Expand Down Expand Up @@ -38,6 +38,7 @@
"typescript": "^4.7.3"
},
"dependencies": {
"@peculiar/webcrypto": "^1.4.3",
"big.js": "^6.2.0",
"cross-fetch": "^4.0.0"
},
Expand Down
8 changes: 6 additions & 2 deletions src/signature.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import { Crypto } from "@peculiar/webcrypto";

const encoder = new TextEncoder();

export async function signQueryString(queryString: string, secretKey: string) {
const webCrypto = crypto ? crypto : new Crypto();

let algorithm = { name: "HMAC", hash: "SHA-256" };
let key = await crypto.subtle.importKey(
let key = await webCrypto.subtle.importKey(
"raw",
encoder.encode(secretKey),
algorithm,
false,
["sign", "verify"]
);
const digest = await crypto.subtle.sign(
const digest = await webCrypto.subtle.sign(
algorithm.name,
key,
encoder.encode(queryString)
Expand Down

0 comments on commit dc5e51f

Please sign in to comment.