forked from FOSWLY/vot-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1d55602
commit cf1b701
Showing
2 changed files
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import crypto from "crypto"; | ||
import { yandexHmacKey } from "../config/config.js"; | ||
|
||
export default async function getSignature(body) { | ||
// Create a key from the HMAC secret | ||
const utf8Encoder = new TextEncoder("utf-8"); | ||
const key = await crypto.subtle.importKey( | ||
"raw", | ||
utf8Encoder.encode(yandexHmacKey), | ||
{ name: "HMAC", hash: { name: "SHA-256" } }, | ||
false, | ||
["sign", "verify"], | ||
); | ||
// Sign the body with the key | ||
const signature = await crypto.subtle.sign("HMAC", key, body); | ||
// Convert the signature to a hex string | ||
return Array.from(new Uint8Array(signature), (x) => | ||
x.toString(16).padStart(2, "0"), | ||
).join(""); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import crypto from "crypto"; | ||
|
||
export default function getUUID(isLower) { | ||
const uuid = ([1e7] + 1e3 + 4e3 + 8e3 + 1e11).replace(/[018]/g, (c) => | ||
( | ||
c ^ | ||
(crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4))) | ||
).toString(16), | ||
); | ||
return isLower ? uuid : uuid.toUpperCase(); | ||
} |