Huge News!Announcing our $40M Series B led by Abstract Ventures.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.4 to 0.0.2-beta.5

dist/types/crypto.d.ts

28

dist/lib/verify.d.ts

@@ -1,3 +0,11 @@

/// <reference types="@cloudflare/workers-types" />
import type { Request, SubtleCrypto, SubtleCryptoImportKeyAlgorithm } from "../types";
/**
* Helper method that takes in a hex string and converts it to its binary representation.
* @param hex Hex string to convert to binary
* @returns The binary form of a hex string
*/
export declare function hexToBinary(hex: string | null): Uint8Array;
/**
* Helper values for popular platforms
*/
export declare const PlatformAlgorithm: {

@@ -13,3 +21,21 @@ Cloudflare: {

};
/**
* Validates a request from Discord
* @param request Request to verify
* @param publicKey The application's public key
* @param subtleCrypto The crypto engine to use
* @param algorithm The name of the crypto algorithm to use
* @returns Whether the request is valid or not
*/
export declare function isValidRequest(request: Request, publicKey: string, subtleCrypto: SubtleCrypto, algorithm?: SubtleCryptoImportKeyAlgorithm | string): Promise<boolean>;
/**
* Determines if a request is valid or not based on provided values
* @param rawBody The raw body of the request
* @param signature The signature header of the request
* @param timestamp The timestamp header of the request
* @param publicKey The application's public key
* @param subtleCrypto The crypto engine to use
* @param algorithm The name of the crypto algorithm to use
* @returns Whether the request is valid or not
*/
export declare function validate(rawBody: string | null | undefined, signature: string | null | undefined, timestamp: string | null | undefined, publicKey: string, subtleCrypto: SubtleCrypto, algorithm?: SubtleCryptoImportKeyAlgorithm | string): Promise<boolean>;
const encoder = new TextEncoder();
/**
* Helper method that takes in a hex string and converts it to its binary representation.
* @param hex Hex string to convert to binary
* @returns The binary form of a hex string
*/
export function hexToBinary(hex) {

@@ -16,2 +21,5 @@ if (hex == null) {

}
/**
* Helper values for popular platforms
*/
export const PlatformAlgorithm = {

@@ -27,2 +35,10 @@ Cloudflare: {

};
/**
* Validates a request from Discord
* @param request Request to verify
* @param publicKey The application's public key
* @param subtleCrypto The crypto engine to use
* @param algorithm The name of the crypto algorithm to use
* @returns Whether the request is valid or not
*/
export async function isValidRequest(request, publicKey, subtleCrypto, algorithm = "Ed25519") {

@@ -35,2 +51,12 @@ const clone = request.clone();

}
/**
* Determines if a request is valid or not based on provided values
* @param rawBody The raw body of the request
* @param signature The signature header of the request
* @param timestamp The timestamp header of the request
* @param publicKey The application's public key
* @param subtleCrypto The crypto engine to use
* @param algorithm The name of the crypto algorithm to use
* @returns Whether the request is valid or not
*/
export async function validate(rawBody, signature, timestamp, publicKey, subtleCrypto, algorithm = "Ed25519") {

@@ -37,0 +63,0 @@ if (timestamp == null || signature == null || rawBody == null) {

@@ -1,3 +0,10 @@

/// <reference types="@cloudflare/workers-types" />
import type { Request, SubtleCryptoImportKeyAlgorithm } from "./types";
export { hexToBinary, validate } from "./lib/verify";
/**
* Validates a request from Discord
* @param request Request to verify
* @param publicKey The application's public key
* @param algorithm The name of the crypto algorithm to use
* @returns Whether the request is valid or not
*/
export declare function isValidRequest(request: Request, publicKey: string, algorithm?: SubtleCryptoImportKeyAlgorithm | string): Promise<boolean>;

@@ -5,2 +5,9 @@ // @ts-expect-error Crypto types are not defined yet

export { hexToBinary, validate } from "./lib/verify";
/**
* Validates a request from Discord
* @param request Request to verify
* @param publicKey The application's public key
* @param algorithm The name of the crypto algorithm to use
* @returns Whether the request is valid or not
*/
export async function isValidRequest(request, publicKey, algorithm = "Ed25519") {

@@ -7,0 +14,0 @@ return verifyRequest(request, publicKey, crypto.subtle, algorithm);

@@ -1,3 +0,10 @@

/// <reference types="@cloudflare/workers-types" />
import type { Request, SubtleCryptoImportKeyAlgorithm } from "./types";
export { hexToBinary, PlatformAlgorithm, validate } from "./lib/verify";
/**
* Validates a request from Discord
* @param request Request to verify
* @param publicKey The application's public key
* @param algorithm The name of the crypto algorithm to use
* @returns Whether the request is valid or not
*/
export declare function isValidRequest(request: Request, publicKey: string, algorithm?: SubtleCryptoImportKeyAlgorithm | string): Promise<boolean>;
import { isValidRequest as verifyRequest } from "./lib/verify";
export { hexToBinary, PlatformAlgorithm, validate } from "./lib/verify";
/**
* Validates a request from Discord
* @param request Request to verify
* @param publicKey The application's public key
* @param algorithm The name of the crypto algorithm to use
* @returns Whether the request is valid or not
*/
export async function isValidRequest(request, publicKey, algorithm = "Ed25519") {

@@ -4,0 +11,0 @@ return verifyRequest(request, publicKey, crypto.subtle, algorithm);

2

package.json
{
"name": "discord-verify",
"version": "0.0.2-beta.4",
"version": "0.0.2-beta.5",
"author": "Ian Mitchell",

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

@@ -0,3 +1,14 @@

import type {
Request,
SubtleCrypto,
SubtleCryptoImportKeyAlgorithm,
} from "../types";
const encoder = new TextEncoder();
/**
* Helper method that takes in a hex string and converts it to its binary representation.
* @param hex Hex string to convert to binary
* @returns The binary form of a hex string
*/
export function hexToBinary(hex: string | null) {

@@ -32,2 +43,5 @@ if (hex == null) {

/**
* Helper values for popular platforms
*/
export const PlatformAlgorithm = {

@@ -44,2 +58,10 @@ Cloudflare: {

/**
* Validates a request from Discord
* @param request Request to verify
* @param publicKey The application's public key
* @param subtleCrypto The crypto engine to use
* @param algorithm The name of the crypto algorithm to use
* @returns Whether the request is valid or not
*/
export async function isValidRequest(

@@ -66,2 +88,12 @@ request: Request,

/**
* Determines if a request is valid or not based on provided values
* @param rawBody The raw body of the request
* @param signature The signature header of the request
* @param timestamp The timestamp header of the request
* @param publicKey The application's public key
* @param subtleCrypto The crypto engine to use
* @param algorithm The name of the crypto algorithm to use
* @returns Whether the request is valid or not
*/
export async function validate(

@@ -68,0 +100,0 @@ rawBody: string | null | undefined,

// @ts-expect-error Crypto types are not defined yet
import crypto from "node:crypto";
import { isValidRequest as verifyRequest } from "./lib/verify";
import type { Request, SubtleCryptoImportKeyAlgorithm } from "./types";
export { hexToBinary, validate } from "./lib/verify";
/**
* Validates a request from Discord
* @param request Request to verify
* @param publicKey The application's public key
* @param algorithm The name of the crypto algorithm to use
* @returns Whether the request is valid or not
*/
export async function isValidRequest(

@@ -7,0 +15,0 @@ request: Request,

import { isValidRequest as verifyRequest } from "./lib/verify";
import type {
Request,
SubtleCrypto,
SubtleCryptoImportKeyAlgorithm,
} from "./types";
export { hexToBinary, PlatformAlgorithm, validate } from "./lib/verify";
declare const crypto: {
subtle: SubtleCrypto;
};
/**
* Validates a request from Discord
* @param request Request to verify
* @param publicKey The application's public key
* @param algorithm The name of the crypto algorithm to use
* @returns Whether the request is valid or not
*/
export async function isValidRequest(

@@ -5,0 +21,0 @@ request: Request,

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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