A time-based one-time password (TOTP) generator and authenticator for Gun DB

Overview

Entangler

A time-based one-time password (TOTP) generator and authenticator for Gun DB

Entangler generates a 6 digit passcode every 30 seconds. It generates an otpauth:// URI and QR codes (both console and image) that can be linked with popular authenticator apps like Microsoft Authenticator, Google Authenticator, LastPass--and many others. But it is not limited to big tech authenticator apps.

Entangler

About

How it works

Entangler generates a new token every 0 and 30 seconds of of every passing minute. When a peer passes in the correct token for that 30 second window, entangler will respond with the source instance's Gun SEA pair. The returned SEA pair may be used to sync Gun user accounts, reset passwords, or other purposes that might depend on passing SEA data over the network to another peer.

Entangler uses Bugoff (an extension built on Bugout) which also uses Gun's SEA suite to securely exchange ephemeral messages between peers without the need to store data in the Gun DB graph.

Usage

Install

> npm i entangler

Examples

Initiator Peer Instance

This is an example of creating and authenticating a Gun user, then creating an Entangler instance. The insance does not necessarily need to be an existing user. Engangler will accept any SEA pair, for example one created with Gun.SEA.pair()

const Gun = require('gun')
require('entangler')

let gun = new Gun()
let user = gun.user()

// Create new Gun user or authenticate existing one
let username = 'A secure username123' // A secure username
let password = 'A secure password123' // A secure password

user.create(username, password, cb => {
  user.auth(username, password)
})

gun.on('auth', async ack => {
  console.log('Authenticated')

  // Create an entangler instance with an SEA pair
  // The username and password here does not need, and probably shouldn't, match a Gun user's username and password!
  gun.entangler(ack.sea, {user: username, secret: password})

  // Return the OTP auth URI QR code image
  console.log(await gun.entangler.QR.image())

  // Print the OTP auth URI QR code to the terminal in ASCII
  console.log(await gun.entangler.QR.terminal())

  // Get the current token
  console.log(await gun.entangler.token())

  // Get tokens as they are generated
  gun.entangler.tokens(token => {
    console.log(token)
  })

})

Anonymous Peer

This is a peer that will be attempting to authenticate to the initiating peer's Entangler instance with the TOTP passcode.

const Gun = require('gun')
const prompt = require('readline-sync')
require('entangler')

let gun = new Gun()

// Look up user by alias
gun.entangler('~@A secure username123')

// Look up user by pub key (no prepending '~')
gun.entangler(pubkey)

// Prompt for a passcode
let passcode = prompt.question('Enter your pin + token: ')

// Verify the passed passcode 
gun.entangler.verify(passcode)

// If the passcode is accepted, the initiator's SEA is returned and can be used to log the user in
gun.entangler.once('authorized', (sea)=>{
  gun.user().auth(sea)
})

// The user has been logged in successfully
gun.on('auth', ack => {
  console.log('Authenticated!!')
})

// If the passcode is rejected, handle the error events
gun.entangler.on('error', err => {
  if(err) console.log(err)
  if(err.code === 401){
    let passcode = prompt.question('Pleae try again: ')
    gun.entangler.verify(passcode)
  }
})

API

Events

authorized

The peer successfully authenticated the TOTP passcode, so the initiating peer's SEA is passed as a callback to this event.

error

There was an error authenticating the TOTP passcode.

Error codes

  • Incorrect passcode: {code: 401, text: 'Incorrect passcode'}
  • Maximum number of attempts reached: {code: 403, text: 'Maximum number of attempts reached'}
  • Attempts timed out: {code: 408, text: 'Attempts timed out'}

Methods

gun.entangler((sea, [opts]) || (alias || pubkey))

For an Entangler initiator, creates an Entangler instance for the passed in Gun.SEA.pair and optional opts.

Example: gun.entangler(ack.sea, {user: username, secret: password})

For an Entangler peer, connects to an Engangler instance and attempts authorization with that instance and the TOTP passoce.

Example (by alias): gun.entangler(~@alias) Example (by pubkey): gun.entangler(pubkey)

The pubkey should not start with a preceding ~

gun.entangler.QR.image()

Return the OTP auth URI QR code image. This is an asynchronous call and must be used with await.

Example: console.log(await gun.entangler.QR.image())

gun.entangler.QR.terminal()

Print the OTP auth URI QR code to the console/terminal using ascii output. This is an asynchronous call and must be used with await.

Example: console.log(await gun.entangler.QR.terminal())

gun.entangler.token()

Return the current authenticator token. This may be called at any time and will return the token for the current time window. This is an asynchronous call and must be used with await.

Example: console.log(await gun.entangler.token())

gun.entangler.tokens(callback)

Return tokens as they are generated. This method will return a new token every 0 and 30 seconds of every minute.

Example:

  gun.entangler.tokens(token => {
    console.log(token)
  })

Optional parameters opts

Entangler's optional opts object can be tailored to aid in securing Entangler further.

opts.address = [string] default = Gun.SEA.pair().pub

opts.address is an optional string that may be passed in as an identifier for peers to swarm around and connect to each other. It is converted to a SHA256 hash and announced to the Webtorrent network via Bugoff, which further hashes that hash to SHA256. A SHA256 hash of a SHA256 hash!

opts.issuer = [string] default = 'Entangler Authenticator'

A TOTP issuer is used to describe the TOTP instance to authenticator apps.

opts.user = [string] default = randomly generated Base32 string

You may pass in your own string for opts.user. This is the TOTP user ID, which gets converted to a Base32 encoded SHA256 hash of the passed in string.

opts.secret = [string] default = randomly generated Base32 string

You may pass in your own string for opts.password. This is the TOTP secret, which gets converted to a Base32 encoded SHA256 hash of the passed in string.

opts.pin = [string || number] default = ''

You may supply a pin, which can be either a string or a number, as an optional additional security measure to protect the Entangler instance.

opts.timeout = [msec] default = 5 minutes (1000 * 60 * 5 msec )

The amount of time in milliseconds since this peer's first passcode entry attempt. Once this timeout has been met or exceeded, this peer can no longer make attempts.

Note: A peeer may try again by establishing a new connection.

opts.maxAttempts = [number] default = 10

The maximum attempts for a peer to enter incorrect passcodes.

You might also like...

Password Generator React App

Password Generator React App

Deployed App Link Password Generator React App Password Generator This Password Generator application is made using React JS. This application is used

Apr 1, 2022

A real time Web-App for one to one chatting.

A real time Web-App for one to one chatting.

We-Vibe A real time web-app for one to one chatting. The project is broadly divided into two parts - Server and Public (client). The Socket.io module

Dec 15, 2022

Generate a password based off user inputs with speed ⚡

speedy-speedy-password Generate a password based off user inputs with speed ⚡ Install NPM npm i speedy-speedy-password Yarn yarn add speedy-speedy-pa

Feb 2, 2022

Obsidian text generator Plugin Text generator using GPT-3 (OpenAI)

Obsidian text generator Plugin Text generator using GPT-3 (OpenAI)

is a handy plugin for Obsidian that helps you generate text content using the powerful language model GP

Dec 29, 2022

Types generator will help user to create TS types from JSON. Just paste your single object JSON the Types generator will auto-generate the interfaces for you. You can give a name for the root object

Types generator will help user to create TS types from JSON. Just paste your single object JSON the Types generator will auto-generate the interfaces for you. You can give a name for the root object

Types generator Types generator is a utility tool that will help User to create TS Interfaces from JSON. All you have to do is paste your single objec

Dec 6, 2022

Hadmean is an internal tool generator. It is language agnostic, schema driven, extremely customizable, featured packed, user-friendly and has just one installation step.

Hadmean is an internal tool generator. It is language agnostic, schema driven, extremely customizable, featured packed, user-friendly and has just one installation step.

Hadmean Report a Bug · Request a Feature · Ask a Question Table of Contents About Quick Demo Motivation Why you should try Hadmean Getting Started Pre

Dec 29, 2022

Check the strength of your password simply and quickly, and with optional UI indicators

Check the strength of your password simply and quickly, and with optional UI indicators. Lock Steel is lightweight, has no dependencies and is connected with the UI elements. Just pure CSS and VanillaJS.

Sep 15, 2022

Zenload - "Load couple loaders and apply transform one-by-one

Zenload Load couple loaders and apply transforms one-by-one. Install npm i zenload -g How to use? With env vairable ZENLOAD: NODE_OPTIONS='"--loader

Jan 25, 2022

A novel approach for security and user experience of Graphical Password Authentication.

A novel approach for security and user experience of Graphical Password Authentication.

Graphical Password Authentication Alohomora Harry Potter themed (not really) Graphical Password Authentication Flowchart and Architecture Solution Dem

Dec 15, 2022
Comments
  • Bump minimist from 1.2.5 to 1.2.6

    Bump minimist from 1.2.5 to 1.2.6

    Bumps minimist from 1.2.5 to 1.2.6.

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • Bump simple-get from 4.0.0 to 4.0.1

    Bump simple-get from 4.0.0 to 4.0.1

    Bumps simple-get from 4.0.0 to 4.0.1.

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
Owner
Daniel Raeder
Daniel Raeder
Self-hosted TOTP authenticator PWA with FIDO2 (WebAuthn)

pasu Self-hosted TOTP authenticator PWA with FIDO2 (WebAuthn) Features 2FA secrets stored in your own server instead of your own device Codes are gene

ソ瑠璃(soruly) 11 Nov 2, 2022
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
Telegram'da belirlediğiniz dakika, saat ve gün aralığında size istediğiniz para ve kripto para biriminin anlık fiyatını mesaj olarak gönderiyor.

Telegram Cryptocurrency Notification Bot Telegram'da belirlediğiniz dakika, saat ve gün aralığında size istediğiniz para ve kripto para biriminin anlı

İbrahim Can Mercan 18 Nov 23, 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
Open Source two factor authenticator. Built during #SupaLaunchWeek 5!

Archived This repository is archived, please go to https://github.com/otentikapp/clients for future development. Introduction Feeling bothered about h

Aris Ripandi 18 Dec 29, 2022
Download all Moodle files with one click. This is a Chrome extension built to save time and effort from downloading files manually one by one!

Moodle Downloader Extension Moodle downloader extension for Chrome. The extension is tested with both the TUM moodle and the official moodle demo. Not

Zhongpin Wang 8 Nov 15, 2022
Generate a secured base32 one time password to authenticate your user! 🔐

Django SOTP ?? Generate a secured base32 one time password to authenticate your user! Case Study ?? Before I mention why you should use django-sotp in

アブラム (Abram) 36 Dec 22, 2022
Password Generator - A fast, simple and powerful open-source utility tool for generating strong, unique and random passwords

A fast, simple and powerful open-source utility tool for generating strong, unique and random passwords. Password Generator is free to use as a secure password generator on any computer, phone, or tablet.

Sebastien Rousseau 11 Aug 3, 2022
Create your own password generator using jQuery, Vanilla JS, and SASS.

Password Generator Create your own password generator using jQuery, Vanilla JS, and SASS. I have been working with JS for my last few projects so I th

The Dev Drawer 1 Jul 12, 2021