Naivete Precedes Misrepresentation

    authrite-js

    0.2.9 • Public • Published

    authrite-js

    JavaScript client for Authrite

    The code is available on GitHub and the package is published on NPM.

    Overview

    Authrite is a system for mutual authentication over a communications channel where both parties come to know the identity of the counterparty. authrite-js provides an API for making authenticated HTTP requests from a client to a server that uses the authrite-express middleware.

    During setup, the client asks for some basic information from the server and provides their identity key. The server sends back a reply, proving custody over the identity key they send back. Then, every message sent between the two parties is signed and verified, enabling everyone to have confidence in message integrity. Messages are not encrypted by Authrite, but encryption is provided by HTTPS.

    Installation

    npm i authrite-js
    

    Example Usage

    This example demonstrates sending a simple request sent with authrite-js

    const { Authrite } = require('authrite-js')
    
    // Authrite required parameters
    const EXAMPLE_CLIENT_PRIVATE_KEY = 
    '0d7889a0e56684ba795e9b1e28eb906df43454f8172ff3f6807b8cf9464994df'
    
    const init = async () => {
        // Create a new instance of the Authrite class
        // Provide the server baseUrl, and your private identity key
        const authrite = new Authrite({
            clientPrivateKey: TEST_CLIENT_PRIVATE_KEY
        })
        // Construct a payload to send as the body of your request
        const body = {
            user: 'Bob',
            message: 'message from client'
        }
        // Create a new request to the server
        const response = await authrite.request('http://localhost:5000/sendSomeData', {
            body,
            method: 'POST',
            headers: {
            'Content-Type': 'application/json'
            }
        })
        // Retrieve the response from the server
        const responseData = JSON.parse(Buffer.from(response.body).toString('utf8'))
    }
    
    init()

    API

    Table of Contents

    constructor

    Client-side API for establishing authenticated server communication

    Parameters

    • authrite object All parameters are given in an object. (optional, default {})

      • authrite.clientPrivateKey String The client's private key used for derivations
      • authrite.initialRequestPath String Initial request path for establishing a connection (optional, default '/authrite/initialRequest')
      • authrite.certificates Array Provided certificates from the client (optional, default [])
      • authrite.signingStrategy (optional, default 'Babbage')

    request

    Parameters

    • requestUrl String The URL to request on an Authrite-enabled server
    • fetchConfig object Config object passed to the Fetch API. The current version of Authrite only supports JSON structures for the fetch body. However, you can include a Buffer as part of the json object. (optional, default {})

    Returns object The response object. Fields are 'status', 'headers' and 'body' (containing an ArrayBuffer of the HTTP response body)

    License

    The license for the code in this repository is the Open BSV License.

    Keywords

    none

    Install

    npm i authrite-js

    DownloadsWeekly Downloads

    41

    Version

    0.2.9

    License

    Open BSV License

    Unpacked Size

    33.5 kB

    Total Files

    4

    Last publish

    Collaborators

    • tyeverett