Giter Club home page Giter Club logo

attest-auth's Introduction

attest-auth

Verify a keypair using a challenge

npm install attest-auth

Usage

const Authenticator = require('attest-auth')
const ed25519 = require('noise-curve-ed')
const secp256k1 = require('noise-curve-secp')

const keypair = ed25519.generateKeyPair()
const serverKeys = ed25519.generateKeyPair()

const server = new Authenticator(serverKeys, { curve: ed25519 })

let serverLogin = server.createServerLogin({
  timeout: 2 * 60 * 1000,
  description: 'Bitfinex'
})

serverLogin.on('verify', function () {
  console.log(serverLogin.publicKey.slice(0, 4).toString('hex'), 'logged in!')
})

const challengeInfo = serverLogin.getChallenge()

// User passes challenge somehow to auth device
const metadata = Buffer.from('put metadata here.')

const curve = [ed25519, secp256k1]
const trustedLogin = Authenticator.createClientLogin(keypair, serverKeys.pub, challengeInfo, { curve, metadata })

trustedLogin.on('verify', function (info) {
  console.log(info.publicKey.slice(0, 8), 'logged in!', info)
  console.log(Buffer.from(info.metadata, 'base64').toString()) // put metadata here.
})

// Verify the challenge using our local key pair
serverLogin = server.verify(trustedLogin.request, { metadata })

console.log(serverLogin.clientMetadata.toString()) // put metadata here.

// Pass the server response back so the trustedLogin knows it worked as well
trustedLogin.verify(serverLogin.response)

Curve Modules

Different curves may be used in the handshake. Handshakes expect curve modules that satisfy the noise-curve interface.

Existing modules:

API

const auth = new Authenticator(severKeyPair, [options])

Make a new authenticator.

serverLogin = auth.createServerLogin([options])

Make a server login instance.

options object takes the following parameters:

{
  curve  // specify curve to be used for dh, must be noise-handshake compliant
}

const challengeMessage = serverLogin.getChallenge()

Pass this challenge to the client to login

serverLogin.on('verify', () => ...)

Emitted when the client has proved the challenge using a key pair

serverLogin.on('error', () => ...)

Emitted when the login fails or times out.

serverLogin.publicKey

Populated after the client has verified the login.

trustedLogin = Authenticator.createClientLogin(clientKeyPair, serverPublicKey, challenge, [options])

Created a client login pointing to the server and the challenge.

options object takes the following parameters:

{
  curve,    // specify a curve/an array of curves to be used for dh, must be noise-handshake compliant
  metadata  // optional metadata to be passed as a buffer
}

trustedLogin.request

Send this request to the server to login.

serverLogin = auth.verify(loginRequest, [options])

Verified a login from the client. Returns the matched login instance, or throws otherwise.

If verified the serverLogin instance emits verify at this stage.

options object takes the following parameters:

{
  metadata  // optional metadata to be passed as a buffer
}

serverLogin.response

Contains the response buffer after a succesful login, send this back to the client.

response object has the form

{
  type,
  publicKey,   // hex encoded public key
  description,
  metadata     // base64 encoded metadata
}

trustedLogin.verify(loginResponse)

Verify that the server logged the user in, throws otherwise.

attest-auth's People

Contributors

chm-diederichs avatar mafintosh avatar nuhvi avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.