Discord Like Tokens for Authentication for Everyone. Uses HMAC with SHA-256

Overview

DC Tokens

npm version npm downloads


About

DCTokens are the discord like tokens that can be used for authentiction in your website, api, or anything you want (you can even trick people to think its an actual discord token 😉 ).

It Uses HMAC with SHA-256 to sign the tokens.

Features

  • Sign Custom Tokens (with your own private key) 📝
  • Verify Tokens
  • Zero-Depencency 💪

Install

Via NPM:

npm install dc-tokens

Via Yarn:

yarn add dc-tokens

Via PNPM

pnpm install dc-tokens

Usage

NOTE: For Node.js only (not supported in browsers)

DCT.sign(payload, privateKey, [options, callback])

If a callback is supplied, the callback is called with the err and the Token.

Else returns the DCToken as string

payload should be string.

privateKey is a string or buffer.

options is an object with the following properties:

  • timestamp (in milliseconds) - defaults to Date.now()
  • epoch (in milliseconds) - defaults to Milliseconds since Discord Epoch: 1420070400000

callback is a function that is called with the err and the Token as string respectively.

Synchronous Sign:

const DCT = require('dc-tokens');
let token = DCT.sign("Cute little cats", "secret");

Sign asynchronously

const DCT = require('dc-tokens');

DCT.sign("Cute little cats", "secret", { }, (err, token) => {
  if (err) {
    console.error(err);
  } else {
    console.log(token);
  }
});

DCT.verify(token, privateKey, [options, callback])

If a callback is supplied, the callback is called with the err and the TokenObject.

Else returns the TokenObject as string

The TokenObject is an object with the following structure

{
  payload: string;
  timestamp: Date;
  signature: string;
}

privateKey is a string or buffer. it should be the same key that was used to generate the token.

options is an object with the following properties:

  • epoch (in milliseconds) - defaults to Milliseconds since Discord Epoch: 1420070400000

callback is a function that is called with the err and the TokenObject respectively.

Verify Asynchronously

const DCT = require('dc-tokens');

DCT.verify(token, privateKey, options, (err, decoded) =>{
    console.log(decoded);
});

Verify Synchronously

const DCT = require('dc-tokens');

let decoded = DCT.verify(token, privateKey, options);

Handiling Errors

const DCT = require('dc-tokens');

// Handling Erros - Asynchronously
DCT.verify(token, privateKey, options, (err, decoded) =>{
  if (err) {
    console.error(err);
  } else {
    console.log(decoded);
  }
});

// Handling Erros - Synchronously
try{
  let decoded = DCT.verify(token, privateKey, options);
} catch (err) {
  console.error(err);
}

Error Codes

the error that is passed as the first paramater in the callback function in either sign or verify has a specific structure when running asynchronously.

{
  code: DCTError;
  message: string;
  stack?: string;
}

DCTError can have the following values:

  • INVALID_TOKEN - token is invalid
  • TOKEN_MALFORMED - token is malformed
  • SIGNATURE_REQUIRED - signature is required
  • INVALID_SIGNATURE - invalid signature
  • UNCAUGHT_ERROR - uncaught error (any other error)
  • TIMESTAMP_MALFORMED - malformed timestamp

If used synchronously, the error is thrown.

Report an Issue

If you have found a bug or if you have a feature request, please report them at this repository issues section.

Author

arnav-kr

License

The project is licensed under the MIT license.

You might also like...

Anonymous Polls for everyone!

Anonymous Polls for everyone!

Anonpoll Anonpoll allows you to ask and share your opinions anonymously, without being cancelled. Built with Angular and Firebase. See hosted version

Mar 24, 2022

⛺️ Tipi is a homeserver for everyone! One command setup, one click installs for your favorites self-hosted apps. ✨

⛺️ Tipi is a homeserver for everyone! One command setup, one click installs for your favorites self-hosted apps. ✨

⛺️ Tipi — A personal homeserver for everyone ⚠️ Tipi is still at an early stage of development and issues are to be expected. Feel free to open an iss

Jan 4, 2023

The wallet for everyone, built on Sui blockchain

The wallet for everyone, built on Sui blockchain

Suiet, the wallet designed for everyone If you want to know how to install/use suiet, please visit our offical website suiet.app or docs Warning Suiet

Dec 28, 2022

🚀 The web-based text editor for everyone built with Electron & React.

 🚀 The web-based text editor for everyone built with Electron & React.

🚀 The web-based text editor for everyone built with Electron & React. Next release | Current release | Documentation (soon) ⬇️ Download: Windows (x64

Sep 16, 2022

🔐 A Privacy-first Diff tool for everyone. ✅ Your data never hits our servers.

🔐 A Privacy-first Diff tool for everyone. ✅ Your data never hits our servers.

Features 🔐 Privacy-first developer tool. 💻 Run on your Web Browser, Your data is sent nowhere. 🔎 Find a Difference between two text input for Side

Dec 5, 2022

Everyone is welcomed here to contribute different web projects. Do follow the Contributors Guidelines

Everyone is welcomed here to contribute different web projects. Do follow the Contributors Guidelines

WebMine Add your Web Development Projects Here This is the repository were you can contribute all your Web Projects. Duplicate projects will not be me

Oct 30, 2022

A work-in-progress HTML sanitizer that strives for: performance like window.Sanitizer, readiness like DOMPurify, and ability to run in a WebWorker like neither of those.

Amuchina A work-in-progress HTML sanitizer that strives for: performance like window.Sanitizer, readiness like DOMPurify, and ability to run in a WebW

Sep 17, 2022

Pull sensitive data from users on windows including discord tokens and chrome data.

Pull sensitive data from users on windows including discord tokens and chrome data.

⭐ For a 🍪 Pegasus Pull sensitive data from users on windows including discord tokens and chrome data. Features 🟩 Discord tokens 🟩 Geolocation data

Dec 24, 2022

Loops through a list of Discord tokens in a file to check if they are valid/invalid

Loops through a list of Discord tokens in a file to check if they are valid/invalid

Discord Token Checker Loops through a list of Discord tokens in a file to check if they are valid/invalid. Click here to report bugs. Usage Download Z

Dec 31, 2022
Comments
  • Bug: Unknown message digest Error in lower versions of Node.js

    Bug: Unknown message digest Error in lower versions of Node.js

    Is there an existing issue for this?

    • [X] I have searched the existing issues

    Describe the bug

    The Code Throws and error showing Unknown message digest when running with lower versions of nodejs.

    Expected Behavior

    Should do the general functioning of signing tokens and verifying them

    Steps To Reproduce

    No response

    System Info

    - OS: Linux
    

    Additional context?

    No response

    bug hacktoberfest 
    opened by arnav-kr 0
Owner
Arnav Kumar
A Full Stack Web Developer, CEO at @Curious-Coders-Official
Arnav Kumar
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
A boilerplate project to build proof of concept paywalls with lightning service authentication tokens (LSATs)

lsat-workshop-boilerplate A boilerplate project to build proof of concept paywalls with lightning service authentication tokens (LSATs) Install Setup

Buck Perley 2 Oct 13, 2022
We are creating a Library that would ensure developers do not reinvent the wheel anymore as far as Authentication is concerned. Developers can easily register and download authentication codes that suits their need at any point.

#AuthWiki Resource Product Documentation Figma Database Schema First Presentation Live Link API Documentation Individual Contributions User Activity U

Zuri Training 17 Dec 2, 2022
Chrome extension that uses vulnerabilities CVE-2021-33044 and CVE-2021-33045 to log in to Dahua cameras without authentication.

DahuaLoginBypass Chrome extension that uses vulnerability CVE-2021-33044 to log in to Dahua IP cameras and VTH/VTO (video intercom) devices without au

null 71 Nov 26, 2022
A full stack application that uses an authentication system to allow FAA Inspectors, Airliners, and Aircraft Technicians to update progress on their work all while keeping a log of records on projects completed.

A full stack application that uses an authentication system to allow FAA Inspectors, Airliners, and Aircraft Technicians to update progress on their work all while keeping a log of records on projects completed.

BinaryBitBytes 3 Jun 13, 2022
Making participation to open source easy for everyone

Torii ⛩️ Your Gateway to open source ⛩️ View Demo · Report Bug · Request Feature Introducing Torii ⛩️ Your gateway to Open Souce Contributing to open

Gaurav Tewari 45 Oct 27, 2022
A name generato for everyone (Programmers, Gamers etc)

HACKZILLA A name generator for Programmers, Gamers and etc. Used Languages HTML5 CSS3 Javascript ?? ?? Link: https://rededge967.github.io/HACKZILLA/ R

Chandula Janith 3 May 14, 2022
Social media platform that hosts community-driven challenges where everyone can play and compete

Komo A social media platform that hosts community-driven challenges where everyone can play and compete. How To Install Komo TBA Preview Home Screen A

null 2 Jun 13, 2022