discord-verify
Advanced tools
Comparing version 0.0.2-beta.20 to 0.0.2-beta.21
{ | ||
"name": "discord-verify", | ||
"version": "0.0.2-beta.20", | ||
"version": "0.0.2-beta.21", | ||
"author": "Ian Mitchell", | ||
@@ -5,0 +5,0 @@ "description": "A library for verifying the authenticity of requests coming from the Discord Interactions API", |
@@ -75,3 +75,10 @@ import type { | ||
Node18: "Ed25519", | ||
Node16: { | ||
/** | ||
* Version 16.17.0+ | ||
*/ | ||
Node16: "Ed25519", | ||
/** | ||
* Versions older than 16.17.0 | ||
*/ | ||
Node16_Old: { | ||
name: "NODE-ED25519", | ||
@@ -78,0 +85,0 @@ namedCurve: "NODE-ED25519", |
@@ -18,2 +18,12 @@ // eslint-disable-next-line @typescript-eslint/ban-ts-comment, @typescript-eslint/prefer-ts-expect-error | ||
// v16.17.0+ use standardized naming: | ||
// https://github.com/nodejs/node/blob/main/doc/changelogs/CHANGELOG_V16.md#2022-08-16-version-16170-gallium-lts-targos | ||
function getAlgo(major: number, minor: number) { | ||
if (major > 16 || (major === 16 && minor >= 17)) { | ||
return PlatformAlgorithm.Node18; | ||
} | ||
return PlatformAlgorithm.Node16; | ||
} | ||
/** | ||
@@ -31,5 +41,7 @@ * Validates a request from Discord | ||
) { | ||
const [majorVersion] = process.versions.node.split("."); | ||
const algo = | ||
majorVersion >= 18 ? PlatformAlgorithm.Node18 : PlatformAlgorithm.Node16; | ||
const [major, minor] = process.versions.node.split("."); | ||
const majorVersion = Number(major); | ||
const minorVersion = Number(minor); | ||
const algo = algorithm ?? getAlgo(majorVersion, minorVersion); | ||
const subtleCrypto = | ||
@@ -40,3 +52,3 @@ majorVersion >= 18 | ||
return verifyRequest(request, publicKey, subtleCrypto, algorithm ?? algo); | ||
return verifyRequest(request, publicKey, subtleCrypto, algo); | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
66953
1095