New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

discord-verify

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

discord-verify - npm Package Compare versions

Comparing version 0.0.2-beta.25 to 0.0.2-beta.26

45

dist/node.js

@@ -38,3 +38,2 @@ "use strict";

var import_node_crypto = __toESM(require("crypto"));
var import_node_process = __toESM(require("process"));

@@ -119,32 +118,22 @@ // src/lib/verify.ts

// src/node.ts
function getAlgo(major, minor) {
switch (major) {
case 18: {
if (minor < 4) {
return PlatformAlgorithm.OldNode;
}
return PlatformAlgorithm.NewNode;
async function isValidRequest2(request, publicKey, algorithm) {
try {
return await isValidRequest(
request,
publicKey,
import_node_crypto.default.webcrypto.subtle,
algorithm ?? PlatformAlgorithm.NewNode
);
} catch (error) {
if (error instanceof Error && error.constructor.name === "DOMException") {
return isValidRequest(
request,
publicKey,
import_node_crypto.default.webcrypto.subtle,
algorithm ?? PlatformAlgorithm.OldNode
);
}
case 17: {
return PlatformAlgorithm.OldNode;
}
case 16: {
if (minor >= 17) {
return PlatformAlgorithm.NewNode;
}
return PlatformAlgorithm.OldNode;
}
default: {
return PlatformAlgorithm.NewNode;
}
throw error;
}
}
async function isValidRequest2(request, publicKey, algorithm) {
const [major, minor] = import_node_process.default.versions.node.split(".");
const majorVersion = Number(major);
const minorVersion = Number(minor);
const algo = algorithm ?? getAlgo(majorVersion, minorVersion);
const subtleCrypto = majorVersion >= 18 ? import_node_crypto.default.subtle : import_node_crypto.default.webcrypto.subtle;
return isValidRequest(request, publicKey, subtleCrypto, algo);
}
// Annotate the CommonJS export names for ESM import in node:

@@ -151,0 +140,0 @@ 0 && (module.exports = {

{
"name": "discord-verify",
"version": "0.0.2-beta.25",
"version": "0.0.2-beta.26",
"author": "Ian Mitchell",

@@ -5,0 +5,0 @@ "description": "A library for verifying the authenticity of requests coming from the Discord Interactions API",

@@ -6,3 +6,2 @@ // eslint-disable-next-line @typescript-eslint/ban-ts-comment, @typescript-eslint/prefer-ts-expect-error

// @ts-ignore-error Node Process
import process from "node:process";
import {

@@ -12,39 +11,5 @@ isValidRequest as verifyRequest,

} from "./lib/verify";
import type {
Request,
SubtleCrypto,
SubtleCryptoImportKeyAlgorithm,
} from "./types";
import type { Request, SubtleCryptoImportKeyAlgorithm } from "./types";
export { hexStringToBinary, PlatformAlgorithm, verify } from "./lib/verify";
// 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) {
switch (major) {
case 18: {
if (minor < 4) {
return PlatformAlgorithm.OldNode;
}
return PlatformAlgorithm.NewNode;
}
case 17: {
return PlatformAlgorithm.OldNode;
}
case 16: {
if (minor >= 17) {
return PlatformAlgorithm.NewNode;
}
return PlatformAlgorithm.OldNode;
}
default: {
return PlatformAlgorithm.NewNode;
}
}
}
/**

@@ -62,13 +27,21 @@ * Validates a request from Discord

) {
const [major, minor] = process.versions.node.split(".");
const majorVersion = Number(major);
const minorVersion = Number(minor);
try {
return await verifyRequest(
request,
publicKey,
crypto.webcrypto.subtle,
algorithm ?? PlatformAlgorithm.NewNode
);
} catch (error: unknown) {
if (error instanceof Error && error.constructor.name === "DOMException") {
return verifyRequest(
request,
publicKey,
crypto.webcrypto.subtle,
algorithm ?? PlatformAlgorithm.OldNode
);
}
const algo = algorithm ?? getAlgo(majorVersion, minorVersion);
const subtleCrypto =
majorVersion >= 18
? (crypto.subtle as SubtleCrypto)
: (crypto.webcrypto.subtle as SubtleCrypto);
return verifyRequest(request, publicKey, subtleCrypto, algo);
throw error;
}
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc